Source

python-ptrace / ptrace / syscall / prototypes.py

Full commit
  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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
# From Linux kernel source code
#    include/linux/syscalls.h
#    arch/i386/kernel/syscall_table.S
#    arch/um/include/sysdep-i386/syscalls.h
#    arch/um/sys-i386/sys_call_table.S

ALIASES = {
    "mmap": ("mmap2",),
    "break": ("brk",),
    "exit": ("exit_group",),
    "fcntl": ("fcntl64",),
}

# Name of arguments containing a filename or a path
FILENAME_ARGUMENTS = set(("filename", "pathname"))

SYSCALL_PROTOTYPES = {
    "read": ("ssize_t", (
            ("unsigned int", "fd"),
            ("char*", "buf"),
            ("size_t", "count"),
        )),
    "write": ("ssize_t", (
            ("int", "fd"),
            ("const char*", "buf"),
            ("size_t", "count"),
        )),
    "open": ("long", (
            ("const char*", "filename"),
            ("int", "mode"),
        )),
    "readlink": ("long", (
            ("const char*", "pathname"),
            ("char*", "buf"),
            ("int", "bufsize"),
        )),
    "close": ("long", (
            ("unsigned int", "fd"),
        )),
    "set_tid_address": ("long", (
            ("int*", "tidptr"),
        )),
    "set_robust_list": ("long", (
            ("struct robust_list_head*", "head"),
            ("size_t", "len_ptr"),
        )),
    "fcntl": ("long", (
            ("unsigned int", "fd"),
            ("unsigned int", "cmd"),
            ("unsigned int", "arg"),
        )),
    "stat": ("long", (
            ("const char*", "filename"),
            ("struct oldstat*", "statbuf"),
        )),
    "stat64": ("long", (
            ("const char*", "filename"),
            ("struct stat64*", "statbuf"),
        )),
    "lstat": ("long", (
            ("const char*", "filename"),
            ("struct oldstat*", "statbuf"),
        )),
    "lstat64": ("long", (
            ("const char*", "filename"),
            ("struct stat64*", "statbuf"),
        )),
    "fstat": ("long", (
            ("unsigned int", "fd"),
            ("struct oldstat*", "statbuf"),
        )),
    "fstat64": ("long", (
            ("unsigned long", "fd"),
            ("struct stat64*", "buf"),
        )),
    "fstatat64": ("long", (
            ("unsigned long", "dirfd"),
            ("const char*", "filename"),
            ("struct stat64*", "statbuf"),
            ("int", "flags"),
        )),
    "statfs": ("long", (
            ("const char*", "pathname"),
            ("struct statfs*", "buf"),
        )),
    "fstatfs": ("long", (
            ("int", "fs"),
            ("struct statfs*", "buf"),
        )),
    "access": ("long", (
            ("char*", "filename"),
            ("int", "mode"),
        )),
    "lseek": ("long", (
            ("unsigned int", "fd"),
            ("unsigned long", "offset"),
            ("loff_t*", "result"),
            ("unsigned int", "origin"),
        )),
    "llseek": ("long", (
            ("unsigned int", "fd"),
            ("unsigned long", "offset_high"),
            ("unsigned long", "offset_low"),
            ("loff_t*", "result"),
            ("unsigned int", "origin"),
        )),
    "break": ("void*", (
            ("void*", "brk"),
        )),
    "sigprocmask": ("int", (
            ("int", "how"),
            ("const old_sigset_t*", "set"),
            ("old_sigset_t*", "ofset"),
        )),
    "rt_sigprocmask": ("int", (
            ("int", "how"),
            ("const sigset_t*", "set"),
            ("sigset_t*", "ofset"),
            ("size_t", "sigsetsize"),
        )),
    "sigaction": ("long", (
            ("int", "signum"),
            ("const struct oldsigaction*", "act"),
            ("struct oldsigaction*", "oldact"),
        )),
    "rt_sigaction": ("long", (
            # FIXME: Check parameters!
            ("int", "signum"),
            ("const struct sigaction*", "act"),
            ("struct sigaction*", "oldact"),
            ("int", "sigsetsize"),
        )),
    "select": ("long", (
            ("int", "n"),
            ("fd_set*", "inp"),
            ("fd_set*", "outp"),
            ("fd_set*", "exp"),
            ("struct timeval*", "timeout"),
        )),
    "poll": ("long", (
            ("struct pollfd*", "ufds"),
            ("int", "nfds"),
            ("long", "timeout"),
        )),
    "gettimeofday": ("long", (
            ("struct timeval*", "tv"),
            ("struct timezone*", "tz"),
        )),
    "settimeofday": ("long", (
            ("struct timeval*", "tv"),
            ("struct timezone*", "tz"),
        )),
    "socketcall": ("long", (
            ("int", "call"),
            ("unsigned long*", "args"),
        )),
    "clock_gettime": ("long", (
            ("clockid_t", "which_clock"),
            ("struct timespec*", "tp"),
        )),
    "clock_getres": ("long", (
            ("clockid_t", "which_clock"),
            ("struct timespec*", "tp"),
        )),
    "time": ("time_t", (
            ("time_t*", "tloc"),
        )),
    "stime": ("long", (
            ("time_t*", "tptr"),
        )),
    "munmap": ("long", (
            ("void*", "addr"),
            ("size_t", "length"),
        )),
    "mmap": ("void*", (
            ("void*", "start"),
            ("unsigned long", "length"),
            ("unsigned long", "prot"),
            ("long", "flags"),
            ("long", "fd"),
            ("unsigned long", "offset"),
        )),
    "madvise": ("long", (
            ("unsigned long", "start"),
            ("size_t", "length"),
            ("int", "behaviour"),
        )),
    "exit": ("void", (
            ("int", "error_code"),
        )),
    "futex": ("long", (
            ("u32*", "uaddr"),
            ("int", "op"),
            ("u32", "val"),
            ("struct timespec*", "utime"),
            ("u32*", "uaddr2"),
            ("u32", "val3"),
        )),
    "ioctl": ("long", (
            ("unsigned int", "fd"),
            ("unsigend int", "cmd"),
            ("void*", "arg"),
        )),
    "getrusage": ("long", (
            ("int", "who"),
            ("struct rusage*", "usage"),
        )),
    "times": ("clock_t", (
            ("struct tms*", "tbuf"),
        )),
    "mprotect": ("long", (
            ("void*", "start"),
            ("size_t", "len"),
            ("unsigned long", "prot"),
        )),
    "getrlimit": ("int", (
            ("unsigned int", "resource"),
            ("struct rlimit*", "rlim"),
        )),
    "setrlimit": ("int", (
            ("unsigned int", "resource"),
            ("struct rlimit*", "rlim"),
        )),

    "getuid": ("uid_t", tuple()),
    "geteuid": ("uid_t", tuple()),
    "getuid16": ("uid16_t", tuple()),
    "geteuid16": ("uid16_t", tuple()),
    "issetugid": ("long", tuple()),

    "getgid": ("gid_t", tuple()),
    "getegid": ("gid_t", tuple()),
    "getgid16": ("gid16_t", tuple()),
    "getegid16": ("gid16_t", tuple()),

    "getpid": ("pid_t", tuple()),
    "getppid": ("pid_t", tuple()),

    "setuid": ("long", (("uid_t", "uid"),)),
    "setreuid": ("long", (("uid_t", "uid"),)),
    "setfsuid": ("long", (("uid_t", "uid"),)),

    "setgid": ("long", (("gid_t", "gid"),)),
    "setregid": ("long", (("gid_t", "gid"),)),
    "setfsgid": ("long", (("gid_t", "gid"),)),

    "getsid": ("long", (("pid_t", "pid"),)),
    "setsid": ("long", tuple()),

    "pipe": ("int", (
            ("int[2]", "filedes"),
        )),
    "wait4": ("pid_t", (
            ("pid_t", "pid"),
            ("int*", "status"),
            ("int", "options"),
            ("struct rusage*", "rusage"),
        )),
    "waitpid": ("pid_t", (
            ("pid_t", "pid"),
            ("int*", "status"),
            ("int", "options"),
        )),
    "set_thread_area": ("long", (
            ("struct user_desc*", "u_info"),
        )),
    "oldolduname": ("long", (
            ("struct oldold_utsname*", "name"),
        )),
    "olduname": ("long", (
            ("struct old_utsname*", "name"),
        )),
    "uname": ("long", (
            ("struct new_utsname*", "name"),
        )),
    "clone": ("long", (
            ("int", "flags"),
            ("void*", "child_stack"),
            ("void*", "parent_tidptr"),
            ("struct user_desc*", "newtls"),
            ("void*", "child_tidptr"),
        )),
    "__getcwd": ("long", (
            ("char*", "pathname"),
            ("size_t", "size"),
        )),
    "dup2": ("long", (
            ("int", "fd"),
            ("int", "fd2"),
        )),
    "fork": ("uid_t", tuple()),
    "execve": ("long", (
            ("const char*", "filename"),
            ("const char**", "argv"),
            ("const char**", "envp"),
        )),
    "readv": ("ssize_t", (
            ("int", "fd"),
            ("const iovec*", "vector"),
            ("int", "count"),
        )),
    "writev": ("ssize_t", (
            ("int", "fd"),
            ("const iovec*", "vector"),
            ("int", "count"),
        )),
    "openat": ("long", (
            ("int", "dirfd"),
            ("const char*", "pathname"),
            ("int", "flags"),
            ("int", "mode"),
        )),
    "getdents": ("long", (
            ("int", "fd"),
            ("struct dirent*", "dirp"),
            ("unsigned int", "count"),
        )),
    "getdents64": ("long", (
            ("int", "fd"),
            ("struct dirent64*", "dirp"),
            ("unsigned int", "count"),
        )),
    "dup": ("long", (
            ("int", "fd"),
        )),
    "dup2": ("long", (
            ("int", "oldfd"),
            ("int", "newfd"),
        )),
    "fchdir": ("long", (
            ("int", "fd"),
        )),
    "getdirentries": ("long", (
            ("int", "fd"),
            ("void*", "buf"),
            ("int", "nbytes"),
            ("long*", "basep"),
        )),
    "unlink": ("long", (
            ("const char*", "pathname"),
        )),
    "kill" : ("long", (
            ("int", "pid"),
            ("int", "signum"),
        )),
    "modify_ldt" : ("long", (
            ("int", "func"),
            ("void*", "ptr"),
            ("unsigned long", "bytecount"),
        )),
    "ipc" : ("long", (
            ("unsigned int", "call"),
            ("int", "first"),
            ("unsigned long", "second"),
            ("long", "third"),
            ("void*", "ptr"),
            ("long", "fifth"),
        )),
    "nanosleep" : ("long", (
            ("struct timespec*", "rqtp"),
            ("struct timespec*", "rmtp"),
        )),
    "restart_syscall" : ("long", tuple()),
    "getsockname" : ("long", (
            ("int", "fd"),
            ("struct sockaddr*", "name"),
            ("socklen_t*", "namelen"),
        )),
    "getpeername" : ("long", (
            ("int", "fd"),
            ("struct sockaddr*", "name"),
            ("socklen_t*", "namelen"),
        )),
    "getsockopt" : ("long", (
            ("int", "fd"),
            ("int", "level"),
            ("int", "optname"),
            ("void*", "optval"),
            ("socklen_t*", "optlen"),
        )),
    "setsockopt" : ("long", (
            ("int", "fd"),
            ("int", "level"),
            ("int", "optname"),
            ("void*", "optval"),
            ("socklen_t*", "optlen"),
        )),
    "bind" : ("long", (
            ("int", "fd"),
            ("const struct sockaddr*", "addr"),
            ("socklen_t", "addrlen"),
        )),
    "connect" : ("long", (
            ("int", "fd"),
            ("const struct sockaddr*", "addr"),
            ("socklen_t", "addrlen"),
        )),
    "socket" : ("long", (
            ("int", "domain"),
            ("int", "type"),
            ("int", "protocol"),
        )),
    "alarm" : ("long", (
            ("unsigned int", "seconds"),
        )),
    "recv": ("ssize_t", (
            ("int", "sockfd"),
            ("void*", "buf"),
            ("size_t", "len"),
            ("int", "flags"),
        )),
    "recvfrom": ("ssize_t", (
            ("int", "sockfd"),
            ("void*", "buf"),
            ("size_t", "len"),
            ("int", "flags"),
            ("struct sockaddr*", "src_addr"),
            ("socklen_t", "addrlen"),
        )),
    "recvmsg": ("ssize_t", (
            ("int", "sockfd"),
            ("struct msghdr*", "msg"),
            ("int", "flags"),
        )),
    "send": ("ssize_t", (
            ("int", "sockfd"),
            ("const void*", "buf"),
            ("size_t", "len"),
            ("int", "flags"),
        )),
    "sendto": ("ssize_t", (
            ("int", "sockfd"),
            ("const void*", "buf"),
            ("size_t", "len"),
            ("int", "flags"),
            ("const struct sockaddr*", "dest_addr"),
            ("socklen_t", "addrlen"),
        )),
    "sendmsg": ("ssize_t", (
            ("int", "sockfd"),
            ("const struct msghdr*", "buf"),
            ("int", "flags"),
        )),
    "listen": ("int", (
            ("int", "fd"),
            ("int", "backlog"),
        )),
    "accept": ("int", (
            ("int", "fd"),
            ("struct sockaddr*", "addr"),
            ("socklen_t*", "addrlen"),
        )),
    "socketpair": ("int", (
            ("int", "domain"),
            ("int", "type"),
            ("int", "protocol"),
            ("int*", "sockvec"),
        )),
    "shutdown": ("int", (
            ("int", "fd"),
            ("int", "how"),
        )),
}

for orig, copies in ALIASES.iteritems():
    orig = SYSCALL_PROTOTYPES[orig]
    for copy in copies:
        SYSCALL_PROTOTYPES[copy] = orig