ns-3 Direct Code Execution
Home
Tutorials ▼
Docs ▼
Wiki
Manual
Develop ▼
API
Bugs
API
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
process.h
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2008 INRIA
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
*/
20
#ifndef PROCESS_H
21
#define PROCESS_H
22
23
#include <signal.h>
24
#include <map>
25
#include <vector>
26
#include <list>
27
#include <set>
28
#include <stdio.h>
29
#include <dirent.h>
30
#include "ns3/callback.h"
31
#include "ns3/event-id.h"
32
#include "ns3/nstime.h"
33
#include "
unix-fd.h
"
34
#include "ns3/random-variable.h"
35
36
class
KingsleyAlloc
;
37
38
extern
"C"
{
39
struct
SimTask;
40
}
41
42
43
namespace
ns3 {
44
45
struct
Process;
46
struct
Thread;
47
class
DceManager;
48
class
UnixFd;
49
class
Loader;
50
class
Task;
51
class
FileUsage;
52
class
PollTable;
53
54
struct
Mutex
55
{
56
uint32_t
mid
;
// mutex id
57
enum
58
{
59
NORMAL
,
60
RECURSIVE
61
}
type
;
62
uint32_t
count
;
63
std::list<Thread *>
waiting
;
64
Thread
*
current
;
65
};
66
struct
Semaphore
67
{
68
uint32_t
sid
;
// semaphore id
69
uint32_t
count
;
70
std::list<Thread *>
waiting
;
71
};
72
struct
Condition
73
{
74
uint32_t
cid
;
// condition var id
75
std::list<Thread *>
waiting
;
76
};
77
struct
SignalHandler
78
{
79
int
signal
;
80
int
flags
;
81
sigset_t
mask
;
82
void (*
handler
)(int);
83
void (*
sigaction
)(int, siginfo_t *,
void
*);
84
};
85
enum
ThreadState_e
86
{
87
// the thread is executing
88
THREAD_RUNNING
,
89
// the thread is in the run queue, not executing yet
90
THREAD_ACTIVE
,
91
// the thread is blocked, is not in the run queue, is not executing
92
THREAD_BLOCKED
,
93
// the thread is dead: it will never move back to any other state
94
// and will be deleted soon.
95
THREAD_DEAD
96
};
97
98
struct
AtExitHandler
99
{
100
enum
101
{
102
NORMAL
,
103
CXA
104
}
type
;
105
union
106
{
107
void (*
normal
)(void);
108
struct
109
{
110
void (*
fn
)(
void
*);
111
void
*
arg
;
112
void
*
d
;
113
}
cxa
;
114
}
value
;
115
};
116
117
struct
ProcessActivity
118
{
119
int64_t
ns3Start
;
120
time_t
realStart
;
121
int64_t
ns3End
;
122
time_t
realEnd
;
123
int
exitValue
;
124
std::string
cmdLine
;
125
};
126
127
struct
Process
128
{
129
uid_t
euid
;
130
uid_t
ruid
;
131
uid_t
suid
;
132
gid_t
egid
;
133
gid_t
rgid
;
134
gid_t
sgid
;
135
uint16_t
ppid
;
136
uint16_t
pid
;
137
uint16_t
pgid
;
138
std::string
name
;
139
std::string
stdinFilename
;
140
// Key is the fd
141
std::map<int,FileUsage *>
openFiles
;
142
std::vector<FILE *>
openStreams
;
143
std::vector<DIR *>
openDirs
;
144
std::vector<SignalHandler>
signalHandlers
;
145
std::vector<Thread *>
threads
;
146
std::vector<Mutex *>
mutexes
;
147
std::vector<Semaphore *>
semaphores
;
148
std::vector<Condition *>
conditions
;
149
std::vector<struct AtExitHandler>
atExitHandlers
;
150
std::set<uint16_t>
children
;
151
sigset_t
pendingSignals
;
152
Time
itimerInterval
;
153
EventId
itimer
;
154
uint32_t
nextMid
;
155
uint32_t
nextSid
;
156
uint32_t
nextCid
;
157
pthread_key_t
nextThreadKey
;
158
DceManager
*
manager
;
159
Loader
*
loader
;
160
void
*
mainHandle
;
161
std::string
cwd
;
162
KingsleyAlloc
*
alloc
;
163
Callback<void,uint16_t,int>
finished
;
164
// the values specified by the user
165
char
**
originalEnvp
;
166
char
**
originalArgv
;
167
int
originalArgc
;
168
char
*
originalProgname
;
// some programs use it instead argv[0]
169
170
// pointers to the global variables present in the libc loader
171
// in the corresponding process.
172
FILE **
pstdin
;
173
FILE **
pstdout
;
174
FILE **
pstderr
;
175
char
***
penvp
;
176
char
**
poptarg
;
177
int
*
poptind
;
178
int
*
popterr
;
179
int
*
poptopt
;
180
FILE *
syslog
;
// instead of real syslog, everything is written to a file /var/log/<pid>/syslog
181
struct
tm
struct_tm
;
182
char
asctime_result
[ 3 + 1 + 3 + 1 + 20 + 1 + 20 + 1 + 20 + 1 + 20 + 1 + 20 + 1 + 1];
// definition is stolen from glibc
183
uint32_t
nodeId
;
// NS3 NODE ID
184
uint8_t
minimizeFiles
;
// If true close stderr and stdout between writes .
185
// an array of memory buffers which must be freed upon process
186
// termination to avoid memory leaks. We stick in there a bunch
187
// of buffers we allocate but for which we cannot control the
188
// lifetime due to weirdness in the posix API.
189
std::vector<void *>
allocated
;
190
//random variable for rand and random implementation
191
RandomVariable
rndVarible
;
192
// srand48 seed
193
struct
drand48_data
seed48Current
;
194
// Current umask
195
mode_t
uMask
;
196
struct
ProcessActivity
timing
;
197
};
198
199
struct
ThreadKeyValue
200
{
201
pthread_key_t
key
;
202
void (*
destructor
)(
void
*);
203
void
*
value
;
204
};
205
206
struct
Thread
207
{
208
/* true: this thread has been detached with pthread_detach. */
209
bool
isDetached
;
210
/* true: exitValue field is valid */
211
bool
hasExitValue
;
212
/* value passed to pthread_exit or returned from thread function */
213
void
*
exitValue
;
214
/* errno of the thread. */
215
int
err
;
216
/* thread id. */
217
uint16_t
tid
;
218
Task
*
task
;
219
Thread
*
joinWaiter
;
220
Process
*
process
;
221
std::list<struct ThreadKeyValue>
keyValues
;
222
sigset_t
signalMask
;
223
sigset_t
pendingSignals
;
224
Time
lastTime
;
// Last time of a possible infinite loop checkpoint.
225
Waiter
*
childWaiter
;
// Not zero if thread waiting for a child in wait or waitall ...
226
PollTable
*
pollTable
;
// No 0 if a poll is running on this thread
227
std::pair <UnixFd*, WaitQueueEntry*>
ioWait
;
// Filled if the current thread is currently waiting for IO
228
};
229
230
}
// namespace ns3
231
232
#endif
/* PROCESS_H */
model
process.h
Generated on Fri Aug 30 2013 13:57:56 for ns-3-dce by
1.8.1.2