add linux_emul base, reorganize docs
[openbsd_emul.git] / linux_emul_base / dat.h
1 typedef struct Ref Ref;
2 typedef struct Urestart Urestart;
3 typedef struct Uproc Uproc;
4 typedef struct Uproctab Uproctab;
5 typedef struct Uwaitq Uwaitq;
6 typedef struct Uwait Uwait;
7
8 typedef struct Udev Udev;
9 typedef struct Ufile Ufile;
10 typedef struct Ustat Ustat;
11 typedef struct Udirent Udirent;
12
13 typedef struct Ureg Ureg;
14 typedef struct Usiginfo Usiginfo;
15
16 enum {
17 HZ = 100,
18 PAGESIZE = 0x1000,
19
20 MAXPROC = 128,
21 MAXFD = 256,
22
23 USTACK = 8*1024*1024,
24 KSTACK = 8*1024,
25 };
26
27 struct Ref
28 {
29 long ref;
30 };
31
32 struct Urestart
33 {
34 Urestart *link;
35 char *syscall;
36
37 union {
38 struct {
39 vlong timeout;
40 } nanosleep;
41 struct {
42 vlong timeout;
43 } poll;
44 struct {
45 vlong timeout;
46 } select;
47 struct {
48 vlong timeout;
49 } futex;
50 };
51 };
52
53 struct Uproc
54 {
55 QLock;
56
57 int tid;
58 int pid;
59 int ppid;
60 int pgid;
61 int psid;
62 int uid;
63 int gid;
64 int umask;
65 int tlsmask;
66
67 int kpid;
68 int notefd;
69 int argsfd;
70
71 int wstate;
72 int wevent;
73 int exitcode;
74 int exitsignal;
75
76 int *cleartidptr;
77
78 vlong timeout;
79
80 vlong alarm;
81 Uproc *alarmq;
82
83 char *state;
84 char *xstate;
85 int innote;
86 int notified;
87 Ureg *ureg;
88 char *syscall;
89 void (*sysret)(int errno);
90 Urestart *restart;
91 Urestart restart0;
92 Uwait *freewait;
93
94 void (*traceproc)(void *arg);
95 void *tracearg;
96
97 int linkloop;
98 char *root;
99 char *cwd;
100 char *kcwd;
101
102 void *fdtab;
103 void *mem;
104 void *trace;
105 void *signal;
106
107 char *comm;
108 int ncomm;
109 ulong codestart;
110 ulong codeend;
111 ulong stackstart;
112 vlong starttime;
113 };
114
115 struct Uproctab
116 {
117 QLock;
118 int nextpid;
119 int alloc;
120 Uproc proc[MAXPROC];
121 };
122
123 struct Uwaitq
124 {
125 QLock;
126 Uwait *w;
127 };
128
129 struct Uwait
130 {
131 Uwait *next;
132 Uwaitq *q;
133 Uwait *nextq;
134 Uproc *proc;
135 Ufile *file;
136 };
137
138 enum {
139 ROOTDEV,
140 SOCKDEV,
141 PIPEDEV,
142 CONSDEV,
143 MISCDEV,
144 DSPDEV,
145 PTYDEV,
146 PROCDEV,
147 MAXDEV,
148 };
149
150 /* device */
151 struct Udev
152 {
153 int (*open)(char *path, int mode, int perm, Ufile **pf);
154 int (*access)(char *path, int perm);
155 int (*stat)(char *path, int link, Ustat *ps);
156
157 int (*link)(char *old, char *new, int sym);
158 int (*unlink)(char *path, int rmdir);
159 int (*readlink)(char *path, char *buf, int len);
160 int (*rename)(char *old, char *new);
161 int (*mkdir)(char *path, int mode);
162 int (*utime)(char *path, long atime, long mtime);
163 int (*chmod)(char *path, int mode);
164 int (*chown)(char *path, int uid, int gid, int link);
165 int (*truncate)(char *path, vlong size);
166
167 int (*read)(Ufile *file, void *buf, int len, vlong off);
168 int (*write)(Ufile *file, void *buf, int len, vlong off);
169
170 vlong (*size)(Ufile *file);
171 int (*poll)(Ufile *file, void *tab);
172 int (*ioctl)(Ufile *file, int cmd, void *arg);
173 int (*close)(Ufile *file);
174
175 int (*fstat)(Ufile *file, Ustat *ps);
176 int (*readdir)(Ufile *file, Udirent **pd);
177
178 int (*fchmod)(Ufile *file, int mode);
179 int (*fchown)(Ufile *file, int uid, int gid);
180 int (*ftruncate)(Ufile *file, vlong size);
181 };
182
183 struct Ufile
184 {
185 Ref;
186
187 int mode;
188 int dev;
189 char *path;
190 int fd;
191 vlong off;
192
193 Udirent *rdaux; /* aux pointer to hold Udirent* chains */
194 };
195
196 struct Ustat
197 {
198 int mode;
199 int uid;
200 int gid;
201 int dev;
202 int rdev;
203 vlong size;
204 ulong atime;
205 ulong mtime;
206 ulong ctime;
207 uvlong ino;
208 };
209
210 struct Udirent
211 {
212 Udirent *next;
213
214 uvlong ino;
215 int mode;
216 char name[];
217 };
218
219 struct Usiginfo
220 {
221 int signo;
222 int errno;
223 int code;
224
225 union {
226 /* kill() */
227 struct {
228 int pid; /* sender's pid */
229 int uid; /* sender's uid */
230 } kill;
231
232 /* POSIX.1b timers */
233 struct {
234 int tid; /* timer id */
235 int overrun; /* overrun count */
236 int val; /* same as below */
237 int sys_private; /* not to be passed to user */
238 } timer;
239
240 /* POSIX.1b signals */
241 struct {
242 int pid; /* sender's pid */
243 int uid; /* sender's uid */
244 int val;
245 } rt;
246
247 /* SIGCHLD */
248 struct {
249 int pid; /* which child */
250 int uid; /* sender's uid */
251 int status; /* exit code */
252 long utime;
253 long stime;
254 } chld;
255
256 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
257 struct {
258 void *addr; /* faulting insn/memory ref. */
259 int trapno; /* TRAP # which caused the signal */
260 } fault;
261
262 /* SIGPOLL */
263 struct {
264 long band; /* POLL_IN, POLL_OUT, POLL_MSG */
265 int fd;
266 } poll;
267 };
268
269 int topid;
270 int group;
271 };
272
273 int debug;
274 long *kstack;
275 long *exitjmp;
276 Uproc **pcurrent;
277 #define current (*pcurrent)
278 vlong boottime;
279
280 Udev *devtab[MAXDEV];
281 Uproctab proctab;