1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
|
/* from hellkit by stealth
*/
#ifndef INT80_H
#define INT80_H
#include "unistd.h"
#ifndef _I386_FCNTL_H
#define O_RDONLY 00
#define O_WRONLY 01
#define O_RDWR 02
#define O_CREAT 0100
#define O_TRUNC 01000
#define O_APPEND 02000
#define F_DUPFD 0 /* Duplicate file descriptor. */
#define F_GETFD 1 /* Get file descriptor flags. */
#define F_SETFD 2 /* Set file descriptor flags. */
#define F_GETFL 3 /* Get file status flags. */
#define F_SETFL 4 /* Set file status flags. */
#endif
/* from bits/termios.h */
#define TCGETS 0x5401
#define TCSETS 0x5402
#define TCSETSW 0x5403
#define TCSETSF 0x5404
#define ISIG 0000001
#define ECHO 0000010
typedef unsigned char cc_t;
typedef unsigned int speed_t;
typedef unsigned int tcflag_t;
#define NCCS 32
typedef struct {
tcflag_t c_iflag; /* input mode flags */
tcflag_t c_oflag; /* output mode flags */
tcflag_t c_cflag; /* control mode flags */
tcflag_t c_lflag; /* local mode flags */
cc_t c_line; /* line discipline */
cc_t c_cc[NCCS]; /* control characters */
speed_t c_ispeed; /* input speed */
speed_t c_ospeed; /* output speed */
} termios;
/* from bits/utsname.h and sys/utsname.h */
#define _UTSNAME_LENGTH 65
#define _UTSNAME_DOMAIN_LENGTH _UTSNAME_LENGTH
#define _UTSNAME_NODENAME_LENGTH _UTSNAME_LENGTH
struct utsname {
char sysname[_UTSNAME_LENGTH];
char nodename[_UTSNAME_NODENAME_LENGTH];
char release[_UTSNAME_LENGTH];
char version[_UTSNAME_LENGTH];
char machine[_UTSNAME_LENGTH];
char domainname[_UTSNAME_DOMAIN_LENGTH];
};
/* from bits/mman.h */
#define PROT_READ 0x1
#define PROT_WRITE 0x2
#define PROT_EXEC 0x4
#define PROT_NONE 0x0
#define MAP_SHARED 0x01
#define MAP_PRIVATE 0x02
#define MAP_TYPE 0x0f
#define MAP_FIXED 0x10
#define MAP_ANONYMOUS 0x20
/* from unistd.h */
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
extern int errno;
#if 0
/* XXX: one would have to make a wrap-around cpp script to avoid defining
* the functions in their code as it happens now :/ that is the reason
* why we include every function un-macro'd
*/
_syscall3(int,lseek,int,fd,long,offset,int,whence);
#endif
static int mmap (void *start, long length, int prot, int flags,
int fd, long offset)
{
long ret;
__asm__ __volatile__ ( "int $0x80"
: "=a" (ret)
: "a" (__NR_mmap), "b" (&start));
return (ret);
}
static inline int munmap (char *start, int length)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_munmap), "S" ((long)start),
"c" ((int)length): "bx");
return ret;
}
static inline int ioctl (int d, int request, int argp)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_ioctl), "S" ((long)d),
"c" ((long)request), "d" ((long)argp): "bx");
return ret;
}
static inline int fcntl (int fd, int cmd, long arg)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_fcntl), "S" ((long)fd),
"c" ((long)cmd), "d" ((long)arg): "bx");
return ret;
}
static inline int lseek (int fd, unsigned long int offset, int whence)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_lseek), "S" ((long)fd),
"c" ((long)offset), "d" ((long)whence): "bx");
return ret;
}
static inline int mprotect(void *addr, long len, int prot)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_mprotect), "S" ((long)addr),
"c" ((long)len), "d" ((long)prot): "bx");
return ret;
}
static inline int read(int fd, void *buf, long count)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_read), "S" ((long)fd),
"c" ((long)buf), "d" ((long)count): "bx");
return ret;
}
static inline int write(int fd, void *buf, long count)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_write), "S" ((int)fd),
"c" ((long)buf), "d" ((long)count): "bx");
return ret;
}
static inline int execve(char *s, char **argv, char **envp)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_execve), "S" ((long)s),
"c" ((long)argv), "d" ((long)envp): "bx");
return ret;
}
static inline int setreuid(int reuid, int euid)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_setreuid), "S" ((long)reuid),
"c" ((long)euid): "bx");
return ret;
}
static inline int uname(struct utsname *un)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_uname), "S" ((long)un): "bx");
return ret;
}
static inline int unlink(char *pathname)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_unlink), "S" ((long)pathname): "bx");
return ret;
}
static inline int chroot(char *path)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_chroot), "S" ((long)path): "bx");
return ret;
}
static inline int brk(void *addr)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_brk), "S" (addr): "bx");
return (ret);
}
static inline int _exit(int level)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_exit), "S" (level): "bx");
return (ret);
}
static inline int dup(int fd)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_dup), "S" (fd): "bx");
return ret;
}
static inline int dup2(int ofd, int nfd)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_dup2), "S" (ofd), "c" (nfd): "bx");
return ret;
}
static inline int open(char *path, int mode, int flags)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_open), "S" ((long)path),
"c" ((int)mode), "d" ((int)flags): "bx");
return ret;
}
static inline int chdir(char *path)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_chdir), "S" ((long)path): "bx");
return ret;
}
static inline int close(int fd)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_close), "S" ((int)fd): "bx");
return ret;
}
static inline int chown(char *path, int uid, int gid)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_chown), "S" ((long)path),
"c" ((int)uid), "d" ((int)gid): "bx");
return ret;
}
static inline int rename(char *oldpath, char *newpath)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_rename), "S" ((long)oldpath),
"c" ((int)newpath): "bx");
return ret;
}
static inline int chmod(char *path, int mode)
{
long ret;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi, %%ebx\n\t"
"int $0x80"
:"=a" (ret)
:"0" (__NR_chmod), "S" ((long)path),
"c" ((int)mode): "bx");
return ret;
}
static inline int sync(void)
{
long ret;
__asm__ __volatile__ ("int $0x80"
:"=a" (ret)
:"0" (__NR_sync));
return (ret);
}
static inline int fork(void)
{
long ret;
__asm__ __volatile__ ("int $0x80"
:"=a" (ret)
:"0" (__NR_fork));
return (ret);
}
static inline int antistrace(void)
{
long ret;
__asm__ __volatile__ ("int $0x03\n\t"
:"=a" (ret)
: );
return (ret);
}
#define SIGTRAP 5
static inline int signal(int signum, void *handler)
{
long ret;
__asm__ __volatile__ ("int $0x80"
:"=a" (ret)
:"0" (__NR_signal), "b" ((long)signum),
"c" ((int)handler));
return ret;
}
#endif
|