1#include "../../memcheck.h"
2#include "scalar.h"
3#include <unistd.h>
4#include <sched.h>
5#include <signal.h>
6#include <sys/shm.h>
7
8// See memcheck/tests/x86-linux/scalar.c for an explanation of what this test
9// is doing.
10
11int main(void)
12{
13   // uninitialised, but we know px[0] is 0x0
14   long* px  = malloc(sizeof(long));
15   long  x0  = px[0];
16   long  res;
17
18   VALGRIND_MAKE_MEM_NOACCESS(0, 0x1000);
19
20   // __NR_syscall 0
21   // XXX
22
23   GO(__NR_exit, 1, "below");
24   // (see below)
25
26   GO(__NR_fork, 2, "other");
27   // (sse scalar_fork.c)
28
29   // Nb: here we are also getting an error from the syscall arg itself.
30   GO(__NR_read, 3, "1+3s 1m");
31   SY(__NR_read+(int)x0, x0, x0, x0+1); FAILx(EFAULT);
32
33   GO(__NR_write, 4, "3s 1m");
34   SY(__NR_write, x0, x0, x0+1); FAIL;
35   //res = write(x0, x0, x0+1); FAIL;
36
37   GO(__NR_open, 5, "(2-args) 2s 1m");
38   SY(__NR_open, x0, x0); FAIL;
39   // Only 1s 0m errors -- the other 2s 1m have been checked in the previous
40   // open test, and if we test them they may be commoned up but they also
41   // may not.
42   GO(__NR_open, 5, "(3-args) 1s 0m");
43   SY(__NR_open, "scalar.c", O_CREAT|O_EXCL, x0); FAIL;
44
45   GO(__NR_close, 6, "1s 0m");
46   SY(__NR_close, x0-1); FAIL;
47
48   GO(__NR_wait4, 7, "4s 2m");
49   SY(__NR_wait4, x0, x0+1, x0, x0+1); FAIL;
50
51   GO_UNIMP(8, "old creat");
52
53   GO(__NR_link, 9, "2s 2m");
54   SY(__NR_link, x0, x0); FAIL;
55
56   GO(__NR_unlink, 10, "1s 1m");
57   SY(__NR_unlink, x0); FAIL;
58
59   GO_UNIMP(11, "old execv");
60
61   GO(__NR_chdir, 12, "1s 1m");
62   SY(__NR_chdir, x0); FAIL;
63
64   GO(__NR_fchdir, 13, "1s 0m");
65   SY(__NR_fchdir, x0-1); FAIL;
66
67   GO(__NR_mknod, 14, "3s 1m");
68   SY(__NR_mknod, x0, x0, x0); FAIL;
69
70   GO(__NR_chmod, 15, "2s 1m");
71   SY(__NR_chmod, x0, x0); FAIL;
72
73   GO(__NR_chown, 16, "3s 1m");
74   SY(__NR_chown, x0, x0, x0); FAIL;
75
76   GO_UNIMP(17, "old break");
77
78   GO(__NR_getfsstat, 18, "3s 1m");
79   SY(__NR_getfsstat, x0+1, x0+1, x0); SUCC; // This should fail...
80
81   GO_UNIMP(19, "old lseek");
82
83   // __NR_getpid 20
84
85   GO_UNIMP(21, "old mount");
86
87   GO_UNIMP(22, "old umount");
88
89   // __NR_setuid 23
90   // __NR_getuid 24
91   // __NR_geteuid 25
92   // __NR_ptrace 26
93   // __NR_recvmsg 27
94   // __NR_sendmsg 28
95   // __NR_recvfrom 29
96   // __NR_accept 30
97   // __NR_getpeername 31
98   // __NR_getsockname 32
99   // __NR_access 33
100   // __NR_chflags 34
101   // __NR_fchflags 35
102   // __NR_sync 36
103   // __NR_kill 37
104
105   GO_UNIMP(38, "old stat");
106
107   // __NR_getppid 39
108
109   GO_UNIMP(40, "old lstat");
110
111   // __NR_dup 41
112   // __NR_pipe           VG_DARWIN_SYSCALL_CONSTRUCT_UX64(42
113   // __NR_getegid 43
114   // __NR_profil 44
115
116   GO_UNIMP(45, "old ktrace");
117
118   // __NR_sigaction 46
119   // __NR_getgid 47
120   // __NR_sigprocmask 48
121   // __NR_getlogin 49
122   // __NR_setlogin 50
123   // __NR_acct 51
124   // __NR_sigpending 52
125   // __NR_sigaltstack 53
126   // __NR_ioctl 54
127   // __NR_reboot 55
128   // __NR_revoke 56
129   // __NR_symlink 57
130   // __NR_readlink 58
131   // __NR_execve 59
132   // __NR_umask 60
133   // __NR_chroot 61
134
135   GO_UNIMP(62, "old fstat");
136
137   GO_UNIMP(63, "used internally, reserved");
138
139   GO_UNIMP(64, "old getpagesize");
140
141   // __NR_msync 65
142   // __NR_vfork 66
143
144   GO_UNIMP(67, "old vread");
145
146   GO_UNIMP(68, "old vwrite");
147
148   GO_UNIMP(69, "old sbrk");
149
150   GO_UNIMP(70, "old sstk");
151
152   GO_UNIMP(71, "old mmap");
153
154   GO_UNIMP(72, "old vadvise");
155
156   // __NR_munmap 73
157   // __NR_mprotect 74
158   // __NR_madvise 75
159
160   GO_UNIMP(76, "old vhangup");
161
162   GO_UNIMP(77, "old vlimit");
163
164   GO(__NR_mincore, 78, "3s 1m");
165   SY(__NR_mincore, x0, x0+40960, x0); FAIL;
166
167   // __NR_getgroups 79
168   // __NR_setgroups 80
169   // __NR_getpgrp 81
170
171   GO(__NR_setpgid, 82, "2s 0m");
172   SY(__NR_setpgid, x0-1, x0-1); FAIL;
173
174   // __NR_setitimer 83
175
176   GO_UNIMP(78, "old wait");
177
178   // __NR_swapon 85
179   // __NR_getitimer 86
180
181   GO_UNIMP(87, "old gethostname");
182
183   GO_UNIMP(88, "old sethostname");
184
185   // __NR_getdtablesize 89
186   // __NR_dup2 90
187
188   GO_UNIMP(91, "old getdopt");
189
190   // __NR_fcntl 92
191   // __NR_select 93
192
193   GO_UNIMP(94, "old setdopt");
194
195   // __NR_fsync 95
196   // __NR_setpriority 96
197   // __NR_socket 97
198   // __NR_connect 98
199
200   GO_UNIMP(99, "old accept");
201
202   // __NR_getpriority 100
203
204   GO_UNIMP(101, "old send");
205
206   GO_UNIMP(102, "old recv");
207
208   GO_UNIMP(103, "old sigreturn");
209
210   // __NR_bind 104
211
212   GO(__NR_setsockopt, 105, "5s 1m");
213   SY(__NR_setsockopt, x0, x0, x0, x0+1, x0+1); FAIL;
214
215   // __NR_listen 106
216
217   GO_UNIMP(107, "old vtimes");
218
219   GO_UNIMP(108, "old sigvec");
220
221   GO_UNIMP(109, "old sigblock");
222
223   GO_UNIMP(110, "old sigsetmask");
224
225   GO(__NR_sigsuspend, 111, "ignore");
226   // (I don't know how to test this...)
227
228   GO_UNIMP(112, "old sigstack");
229
230   GO_UNIMP(113, "old recvmsg");
231
232   GO_UNIMP(114, "old sendmsg");
233
234   GO_UNIMP(115, "old vtrace");
235
236   // __NR_gettimeofday 116
237   // __NR_getrusage 117
238
239   // Nb: there's no "getsockopt(optlen) points to unaddressable byte(s)";
240   // difficult to get with arg4 being checked with buf_and_len_pre_check.
241   GO(__NR_getsockopt, 118, "5s 1m");
242   SY(__NR_getsockopt, x0, x0, x0, x0+1, x0+&px[1]); FAIL;
243
244   GO_UNIMP(119, "old resuba");
245
246   // __NR_readv 120
247   // __NR_writev 121
248   // __NR_settimeofday 122
249   // __NR_fchown 123
250   // __NR_fchmod 124
251
252   GO_UNIMP(125, "old recvfrom");
253
254   // __NR_setreuid 126
255   // __NR_setregid 127
256   // __NR_rename 128
257
258   GO_UNIMP(129, "old truncate");
259
260   GO_UNIMP(130, "old ftruncate");
261
262   // __NR_flock 131
263
264   GO(__NR_mkfifo, 132, "2s 1m");
265   SY(__NR_mkfifo, x0, x0); FAIL;
266
267   // __NR_sendto 133
268   // __NR_shutdown 134
269   // __NR_socketpair 135
270   // __NR_mkdir 136
271   // __NR_rmdir 137
272   // __NR_utimes 138
273   // __NR_futimes 139
274   // __NR_adjtime 140
275
276   GO_UNIMP(141, "old getpeername");
277
278   // __NR_gethostuuid 142
279
280   GO_UNIMP(143, "old sethostid");
281
282   GO_UNIMP(144, "old getrlimit");
283
284   GO_UNIMP(145, "old setrlimit");
285
286   GO_UNIMP(146, "old killpg");
287
288   // __NR_setsid 147
289
290   GO_UNIMP(148, "old setquota");
291
292   GO_UNIMP(149, "old qquota");
293
294   GO_UNIMP(150, "old getsockname");
295
296   // __NR_getpgid 151
297   // __NR_setprivexec 152
298   // __NR_pread 153
299   // __NR_pwrite 154
300   // __NR_nfssvc 155
301
302   GO_UNIMP(156, "old getdirentries");
303
304   // __NR_statfs 157
305   // __NR_fstatfs 158
306   // __NR_unmount 159
307
308   GO_UNIMP(160, "old async_daemon");
309
310   // __NR_getfh 161
311
312   GO_UNIMP(162, "old getdomainname");
313
314   GO_UNIMP(163, "old setdomainname");
315
316   // /* 164 */
317
318   // __NR_quotactl 165
319
320   GO_UNIMP(166, "old exportfs");
321
322   GO(__NR_mount, 167, "4s 2m");
323   SY(__NR_mount, x0, x0, x0, x0); FAIL;
324
325   GO_UNIMP(168, "old ustat");
326
327   GO(__NR_csops, 169, "4s 1m");
328   SY(__NR_csops, x0, x0, x0+1, x0+1); FAILx(EFAULT);
329
330   GO_UNIMP(170, "old table");
331
332   GO_UNIMP(171, "old wait3");
333
334   GO_UNIMP(172, "old rpause");
335
336   // __NR_waitid 173
337
338   GO_UNIMP(174, "old getdents");
339
340   GO_UNIMP(175, "old gc_control");
341
342   // __NR_add_profil 176
343
344   GO_UNIMP(177-179, "unused");
345
346   // __NR_kdebug_trace 180
347   // __NR_setgid 181
348   // __NR_setegid 182
349   // __NR_seteuid 183
350   // __NR_sigreturn 184
351   // __NR_chud 185
352
353   GO_UNIMP(186-187, "unused");
354
355   // __NR_stat 188
356   // __NR_fstat 189
357   // __NR_lstat 190
358   // __NR_pathconf 191
359   // __NR_fpathconf 192
360
361   GO_UNIMP(193, "unused");
362
363   // __NR_getrlimit 194
364   // __NR_setrlimit 195
365   // __NR_getdirentries 196
366   // __NR_mmap 197
367
368   // /* 198  __syscall */
369
370   // __NR_lseek          VG_DARWIN_SYSCALL_CONSTRUCT_UX64(199
371   // __NR_truncate 200
372   // __NR_ftruncate 201
373   // __NR___sysctl 202
374   // __NR_mlock 203
375   // __NR_munlock 204
376   // __NR_undelete 205
377   // __NR_ATsocket 206
378   // __NR_ATgetmsg 207
379   // __NR_ATputmsg 208
380   // __NR_ATPsndreq 209
381   // __NR_ATPsndrsp 210
382   // __NR_ATPgetreq 211
383   // __NR_ATPgetrsp 212
384
385   GO_UNIMP(213, "reserved for AppleTalk");
386
387   // __NR_kqueue_from_portset_np 214
388   // __NR_kqueue_portset_np 215
389   // __NR_mkcomplex 216
390   // __NR_statv 217
391   // __NR_lstatv 218
392   // __NR_fstatv 219
393   // __NR_getattrlist 220
394   // __NR_setattrlist 221
395   // __NR_getdirentriesattr 222
396
397   GO(__NR_exchangedata, 223, "3s 2m");
398   SY(__NR_exchangedata, x0, x0, x0); FAIL;
399
400   // /* 224  checkuseraccess */
401
402   // __NR_searchfs 225
403   // __NR_delete 226
404   // __NR_copyfile 227
405
406   GO_UNIMP(228-229, "unused");
407
408   // __NR_poll 230
409   // __NR_watchevent 231
410   // __NR_waitevent 232
411   // __NR_modwatch 233
412   // __NR_getxattr 234
413   // __NR_fgetxattr 235
414   // __NR_setxattr 236
415   // __NR_fsetxattr 237
416   // __NR_removexattr 238
417   // __NR_fremovexattr 239
418   // __NR_listxattr 240
419   // __NR_flistxattr 241
420   // __NR_fsctl 242
421   // __NR_initgroups 243
422   // __NR_posix_spawn 244
423
424   GO_UNIMP(245-246, "unused");
425
426   // __NR_nfsclnt 247
427   // __NR_fhopen 248
428
429   GO_UNIMP(249, "unused");
430
431   // __NR_minherit 250
432   // __NR_semsys 251
433   // __NR_msgsys 252
434   // __NR_shmsys 253
435   // __NR_semctl 254
436   // __NR_semget 255
437   // __NR_semop 256
438
439   GO_UNIMP(257, "unused");
440
441   // __NR_msgctl 258
442   // __NR_msgget 259
443   // __NR_msgsnd 260
444   // __NR_msgrcv 261
445
446   GO(__NR_shmat, 262, "3s 0m");
447   SY(__NR_shmat, x0, x0, x0); FAIL;
448
449   GO(__NR_shmctl, 263, "3s 1m");
450   SY(__NR_shmctl, x0, x0+IPC_STAT, x0+1); FAIL;
451
452   GO(__NR_shmdt, 264, "1s 0m");
453   SY(__NR_shmdt, x0); FAIL;
454
455   GO(__NR_shmget, 265, "3s 0m");
456   SY(__NR_shmget, x0, x0, x0); FAIL;
457
458   // __NR_shm_open 266
459   // __NR_shm_unlink 267
460
461   GO(__NR_sem_open, 268, "2s 1m");
462   SY(__NR_sem_open, x0, x0); FAIL;
463
464   GO(__NR_sem_open, 268, "(4-args) 2s 0m");
465   SY(__NR_sem_open, "my_sem", O_CREAT|O_EXCL, x0, x0); SUCC_OR_FAIL;
466
467   // Nb: we add 0x12345 to make sure it's not a valid semaphore descriptor.
468   GO(__NR_sem_close, 269, "1s 0m");
469   SY(__NR_sem_close, x0+0x12345); FAIL;
470
471   GO(__NR_sem_unlink, 270, "1s 1m");
472   SY(__NR_sem_unlink, x0); FAIL;
473
474   GO(__NR_sem_wait, 271, "1s 0m");
475   SY(__NR_sem_wait, x0); FAIL;
476
477   GO(__NR_sem_trywait, 272, "1s 0m");
478   SY(__NR_sem_trywait, x0); FAIL;
479
480   GO(__NR_sem_post, 273, "1s 0m");
481   SY(__NR_sem_post, x0); FAIL;
482
483   // __NR_sem_getvalue 274
484
485   GO(__NR_sem_init, 275, "3s 1m");
486   SY(__NR_sem_init, x0+1, x0, x0); FAILx(ENOSYS);
487
488   GO(__NR_sem_destroy, 276, "1s 1m");
489   SY(__NR_sem_destroy, x0+1); FAILx(ENOSYS);
490
491   // __NR_open_extended 277
492   // __NR_umask_extended 278
493
494   {
495      size_t one = 1;
496      GO(__NR_stat_extended, 279, "4s 4m");
497      SY(__NR_stat_extended, x0, x0, x0, x0); FAIL;
498      // Go again to get a complaint about where the 3rd arg points;  it
499      // requires the 4th arg to point to a valid value.
500      SY(__NR_stat_extended, 0, 0, 0, &one); FAIL;
501
502      GO(__NR_lstat_extended, 280, "4s 4m");
503      SY(__NR_lstat_extended, x0, x0, x0, x0); FAIL;
504      // Go again to get a complaint about where the 3rd arg points;  it
505      // requires the 4th arg to point to a valid value.
506      SY(__NR_lstat_extended, 0, 0, 0, &one); FAIL;
507
508      GO(__NR_fstat_extended, 280, "4s 3m");
509      SY(__NR_fstat_extended, x0, x0, x0, x0); FAIL;
510      // Go again to get a complaint about where the 3rd arg points;  it
511      // requires the 4th arg to point to a valid value.
512      SY(__NR_fstat_extended, 0, 0, 0, &one); FAIL;
513   }
514
515   // __NR_chmod_extended 282
516   // __NR_fchmod_extended 283
517
518   // XXX: we don't check the 'results' (too hard, see the wrapper code).  If
519   // we did, it would be 2m.
520   GO(__NR_access_extended, 284, "4s 1m");
521   SY(__NR_access_extended, x0, x0+1, x0, x0); FAIL;
522
523   // __NR_settid 285
524   // __NR_gettid 286
525   // __NR_setsgroups 287
526   // __NR_getsgroups 288
527   // __NR_setwgroups 289
528   // __NR_getwgroups 290
529   // __NR_mkfifo_extended 291
530   // __NR_mkdir_extended 292
531   // __NR_identitysvc 293
532   // __NR_shared_region_check_np 294
533   // __NR_shared_region_map_np 295
534
535   GO_UNIMP(296, "old load_shared_file");
536
537   GO_UNIMP(297, "old reset_shared_file");
538
539   GO_UNIMP(298, "old new_system_shared_regions");
540
541   GO_UNIMP(299, "old shared_region_map_file_np");
542
543   GO_UNIMP(300, "old shared_region_make_private_np");
544
545   // __NR___pthread_mutex_destroy 301
546   // __NR___pthread_mutex_init 302
547   // __NR___pthread_mutex_lock 303
548   // __NR___pthread_mutex_trylock 304
549   // __NR___pthread_mutex_unlock 305
550   // __NR___pthread_cond_init 306
551   // __NR___pthread_cond_destroy 307
552   // __NR___pthread_cond_broadcast 308
553   // __NR___pthread_cond_signal 309
554   // __NR_getsid 310
555   // __NR_settid_with_pid 311
556   // __NR___pthread_cond_timedwait 312
557   // __NR_aio_fsync 313
558
559   GO(__NR_aio_return, 314, "1s 0m");
560   SY(__NR_aio_return, x0); FAIL;
561
562   GO(__NR_aio_suspend, 315, "1s 0m");
563   SY(__NR_aio_suspend, x0, x0+1, x0); FAIL;
564
565   // __NR_aio_cancel 316
566
567   GO(__NR_aio_error, 317, "1s 0m");
568   SY(__NR_aio_error, x0); FAIL;
569
570   GO(__NR_aio_read, 318, "1s 1m");
571   SY(__NR_aio_read, x0); FAIL;
572
573   GO(__NR_aio_write, 319, "1s 1m");
574   SY(__NR_aio_write, x0); FAIL;
575
576   // __NR_lio_listio 320
577   // __NR___pthread_cond_wait 321
578   // __NR_iopolicysys 322
579
580   GO_UNIMP(323, "unused");
581
582   // __NR_mlockall 324
583   // __NR_munlockall 325
584
585   GO_UNIMP(326, "unused");
586
587   // __NR_issetugid 327
588
589   GO(__NR___pthread_kill, 328, "2s 0m");
590   SY(__NR___pthread_kill, x0, x0); FAIL;
591
592   GO(__NR___pthread_sigmask, 329, "3s 0m");
593   SY(__NR___pthread_sigmask, x0, x0, x0); SUCC;
594
595   // __NR___sigwait 330
596   // __NR_sigwait 330) // GrP fixme hack
597   // __NR___disable_threadsignal 331
598   // __NR___pthread_markcancel 332
599   // __NR___pthread_canceled 333
600   // __NR___semwait_signal 334
601
602   GO_UNIMP(335, "old utrace");
603
604   // __NR_proc_info 336
605   // __NR_sendfile 337
606   // __NR_stat64 338
607   // __NR_fstat64 339
608   // __NR_lstat64 340
609
610   {
611      size_t one = 1;
612      GO(__NR_stat64_extended, 341, "4s 4m");
613      SY(__NR_stat64_extended, x0, x0, x0, x0); FAIL;
614      // Go again to get a complaint about where the 3rd arg points;  it
615      // requires the 4th arg to point to a valid value.
616      SY(__NR_stat64_extended, 0, 0, 0, &one); FAIL;
617
618      GO(__NR_lstat64_extended, 342, "4s 4m");
619      SY(__NR_lstat64_extended, x0, x0, x0, x0); FAIL;
620      // Go again to get a complaint about where the 3rd arg points;  it
621      // requires the 4th arg to point to a valid value.
622      SY(__NR_lstat64_extended, 0, 0, 0, &one); FAIL;
623
624      GO(__NR_fstat64_extended, 342, "4s 3m");
625      SY(__NR_fstat64_extended, x0, x0, x0, x0); FAIL;
626      // Go again to get a complaint about where the 3rd arg points;  it
627      // requires the 4th arg to point to a valid value.
628      SY(__NR_fstat64_extended, 0, 0, 0, &one); FAIL;
629   }
630
631   // __NR_fstat64_extended 343
632   // __NR_getdirentries64 344
633   // __NR_statfs64 345
634   // __NR_fstatfs64 346
635
636   GO(__NR_getfsstat64, 347, "3s 1m");
637   SY(__NR_getfsstat64, x0+1, x0+1, x0); SUCC; // This should fail...
638
639   // __NR___pthread_chdir 348
640   // __NR___pthread_fchdir 349
641   // __NR_audit 350
642   // __NR_auditon 351
643
644   // /* 352 */
645
646   // __NR_getauid 353
647   // __NR_setauid 354
648   // __NR_getaudit 355
649   // __NR_setaudit 356
650   // __NR_getaudit_addr 357
651   // __NR_setaudit_addr 358
652   // __NR_auditctl 359
653   // __NR_bsdthread_create 360
654   // __NR_bsdthread_terminate 361
655   // __NR_kqueue 362
656   // __NR_kevent 363
657   // __NR_lchown 364
658   // __NR_stack_snapshot 365
659   // __NR_bsdthread_register 366
660   // __NR_workq_open 367
661   // __NR_workq_ops 368
662
663   GO_UNIMP(369-379, "unused");
664
665   // __NR___mac_execve 380
666   // __NR___mac_syscall 381
667   // __NR___mac_get_file 382
668   // __NR___mac_set_file 383
669   // __NR___mac_get_link 384
670   // __NR___mac_set_link 385
671   // __NR___mac_get_proc 386
672   // __NR___mac_set_proc 387
673   // __NR___mac_get_fd 388
674   // __NR___mac_set_fd 389
675   // __NR___mac_get_pid 390
676   // __NR___mac_get_lcid 391
677   // __NR___mac_get_lctx 392
678   // __NR___mac_set_lctx 393
679   // __NR_setlcid 394
680   // __NR_getlcid 395
681
682   // The nocancel syscalls (396--423) are tested in scalar_nocancel.c.
683
684   // __NR___mac_mount 424
685   // __NR___mac_get_mount 425
686   // __NR___mac_getfsstat 426
687   // __NR_MAXSYSCALL 427
688
689#if 0
690   // XXX: all these are copied from x86-linux/scalar.c.
691
692   // __NR_creat 8
693   GO(__NR_creat, "2s 1m");
694   SY(__NR_creat, x0, x0); FAIL;
695
696   // __NR_execve 11
697   // Nb: could have 3 memory errors if we pass x0+1 as the 2nd and 3rd
698   // args, except for bug #93174.
699   GO(__NR_execve, "3s 1m");
700   SY(__NR_execve, x0, x0, x0); FAIL;
701
702   // __NR_time 13
703   GO(__NR_time, "1s 1m");
704   SY(__NR_time, x0+1); FAIL;
705
706   // __NR_lchown 16
707   GO(__NR_lchown, "n/a");
708 //SY(__NR_lchown); // (Not yet handled by Valgrind) FAIL;
709
710   // __NR_break 17
711   GO(__NR_break, "ni");
712   SY(__NR_break); FAIL;
713
714   // __NR_oldstat 18
715   GO(__NR_oldstat, "n/a");
716   // (obsolete, not handled by Valgrind)
717
718   // __NR_lseek 19
719   GO(__NR_lseek, "3s 0m");
720   SY(__NR_lseek, x0-1, x0, x0); FAILx(EBADF);
721
722   // __NR_getpid 20
723   GO(__NR_getpid, "0s 0m");
724   SY(__NR_getpid); SUCC;
725
726   // __NR_mount 21
727   GO(__NR_mount, "5s 3m");
728   SY(__NR_mount, x0, x0, x0, x0, x0); FAIL;
729
730   // __NR_umount 22
731   GO(__NR_umount, "1s 1m");
732   SY(__NR_umount, x0); FAIL;
733
734   // __NR_setuid 23
735   GO(__NR_setuid, "1s 0m");
736   SY(__NR_setuid, x0); FAIL;
737
738   // __NR_getuid 24
739   GO(__NR_getuid, "0s 0m");
740   SY(__NR_getuid); SUCC;
741
742   // __NR_stime 25
743   GO(__NR_stime, "n/a");
744 //SY(__NR_stime); // (Not yet handled by Valgrind) FAIL;
745
746   // __NR_ptrace 26
747   // XXX: memory pointed to by arg3 goes unchecked... otherwise would be 2m
748   GO(__NR_ptrace, "4s 1m");
749   SY(__NR_ptrace, x0+PTRACE_GETREGS, x0, x0, x0); FAIL;
750
751   // __NR_alarm 27
752   GO(__NR_alarm, "1s 0m");
753   SY(__NR_alarm, x0); SUCC;
754
755   // __NR_oldfstat 28
756   GO(__NR_oldfstat, "n/a");
757   // (obsolete, not handled by Valgrind)
758
759   // __NR_pause 29
760   GO(__NR_pause, "ignore");
761   // (hard to test, and no args so not much to be gained -- don't bother)
762
763   // __NR_utime 30
764   GO(__NR_utime, "2s 2m");
765   SY(__NR_utime, x0, x0+1); FAIL;
766
767   // __NR_stty 31
768   GO(__NR_stty, "ni");
769   SY(__NR_stty); FAIL;
770
771   // __NR_gtty 32
772   GO(__NR_gtty, "ni");
773   SY(__NR_gtty); FAIL;
774
775   // __NR_access 33
776   GO(__NR_access, "2s 1m");
777   SY(__NR_access, x0, x0); FAIL;
778
779   // __NR_nice 34
780   GO(__NR_nice, "1s 0m");
781   SY(__NR_nice, x0); SUCC;
782
783   // __NR_ftime 35
784   GO(__NR_ftime, "ni");
785   SY(__NR_ftime); FAIL;
786
787   // __NR_sync 36
788   GO(__NR_sync, "0s 0m");
789   SY(__NR_sync); SUCC;
790
791   // __NR_kill 37
792   GO(__NR_kill, "2s 0m");
793   SY(__NR_kill, x0, x0); SUCC;
794
795   // __NR_rename 38
796   GO(__NR_rename, "2s 2m");
797   SY(__NR_rename, x0, x0); FAIL;
798
799   // __NR_mkdir 39
800   GO(__NR_mkdir, "2s 1m");
801   SY(__NR_mkdir, x0, x0); FAIL;
802
803   // __NR_rmdir 40
804   GO(__NR_rmdir, "1s 1m");
805   SY(__NR_rmdir, x0); FAIL;
806
807   // __NR_dup 41
808   GO(__NR_dup, "1s 0m");
809   SY(__NR_dup, x0-1); FAIL;
810
811   // __NR_pipe 42
812   GO(__NR_pipe, "1s 1m");
813   SY(__NR_pipe, x0); FAIL;
814
815   // __NR_times 43
816   GO(__NR_times, "1s 1m");
817   SY(__NR_times, x0+1); FAIL;
818
819   // __NR_prof 44
820   GO(__NR_prof, "ni");
821   SY(__NR_prof); FAIL;
822
823   // __NR_brk 45
824   GO(__NR_brk, "1s 0m");
825   SY(__NR_brk, x0); SUCC;
826
827   // __NR_setgid 46
828   GO(__NR_setgid, "1s 0m");
829   SY(__NR_setgid, x0); FAIL;
830
831   // __NR_getgid 47
832   GO(__NR_getgid, "0s 0m");
833   SY(__NR_getgid); SUCC;
834
835   // __NR_signal 48
836   GO(__NR_signal, "n/a");
837 //SY(__NR_signal); // (Not yet handled by Valgrind) FAIL;
838
839   // __NR_geteuid 49
840   GO(__NR_geteuid, "0s 0m");
841   SY(__NR_geteuid); SUCC;
842
843   // __NR_getegid 50
844   GO(__NR_getegid, "0s 0m");
845   SY(__NR_getegid); SUCC;
846
847   // __NR_acct 51
848   GO(__NR_acct, "1s 1m");
849   SY(__NR_acct, x0); FAIL;
850
851   // __NR_umount2 52
852   GO(__NR_umount2, "2s 1m");
853   SY(__NR_umount2, x0, x0); FAIL;
854
855   // __NR_lock 53
856   GO(__NR_lock, "ni");
857   SY(__NR_lock); FAIL;
858
859   // __NR_ioctl 54
860   #include <asm/ioctls.h>
861   GO(__NR_ioctl, "3s 1m");
862   SY(__NR_ioctl, x0, x0+TCSETS, x0); FAIL;
863
864   // __NR_fcntl 55
865   // As with sys_open(), the 'fd' error is suppressed for the later ones.
866   // For F_GETFD the 3rd arg is ignored
867   GO(__NR_fcntl, "(GETFD) 2s 0m");
868   SY(__NR_fcntl, x0-1, x0+F_GETFD, x0); FAILx(EBADF);
869
870   // For F_DUPFD the 3rd arg is 'arg'.  We don't check the 1st two args
871   // because any errors may or may not be commoned up with the ones from
872   // the previous fcntl call.
873   GO(__NR_fcntl, "(DUPFD) 1s 0m");
874   SY(__NR_fcntl, -1, F_DUPFD, x0); FAILx(EBADF);
875
876   // For F_GETLK the 3rd arg is 'lock'.  On x86, this fails w/EBADF.  But
877   // on amd64 in 32-bit mode it fails w/EFAULT.  We don't check the 1st two
878   // args for the reason given above.
879   GO(__NR_fcntl, "(GETLK) 1s 0m");
880   SY(__NR_fcntl, -1, F_GETLK, x0); FAIL; //FAILx(EBADF);
881
882   // __NR_mpx 56
883   GO(__NR_mpx, "ni");
884   SY(__NR_mpx); FAIL;
885
886   // __NR_setpgid 57
887   GO(__NR_setpgid, "2s 0m");
888   SY(__NR_setpgid, x0, x0-1); FAIL;
889
890   // __NR_ulimit 58
891   GO(__NR_ulimit, "ni");
892   SY(__NR_ulimit); FAIL;
893
894   // __NR_oldolduname 59
895   GO(__NR_oldolduname, "n/a");
896   // (obsolete, not handled by Valgrind)
897
898   // __NR_umask 60
899   GO(__NR_umask, "1s 0m");
900   SY(__NR_umask, x0+022); SUCC;
901
902   // __NR_chroot 61
903   GO(__NR_chroot, "1s 1m");
904   SY(__NR_chroot, x0); FAIL;
905
906   // __NR_ustat 62
907   GO(__NR_ustat, "n/a");
908   // (deprecated, not handled by Valgrind)
909
910   // __NR_dup2 63
911   GO(__NR_dup2, "2s 0m");
912   SY(__NR_dup2, x0-1, x0); FAIL;
913
914   // __NR_getppid 64
915   GO(__NR_getppid, "0s 0m");
916   SY(__NR_getppid); SUCC;
917
918   // __NR_getpgrp 65
919   GO(__NR_getpgrp, "0s 0m");
920   SY(__NR_getpgrp); SUCC;
921
922   // __NR_setsid 66
923   GO(__NR_setsid, "0s 0m");
924   SY(__NR_setsid); SUCC_OR_FAIL;
925
926   // __NR_sigaction 67
927   GO(__NR_sigaction, "3s 4m");
928   SY(__NR_sigaction, x0, x0+&px[1], x0+&px[1]); FAIL;
929
930   // __NR_sgetmask 68 sys_sgetmask()
931   GO(__NR_sgetmask, "n/a");
932 //SY(__NR_sgetmask); // (Not yet handled by Valgrind) FAIL;
933
934   // __NR_ssetmask 69
935   GO(__NR_ssetmask, "n/a");
936 //SY(__NR_ssetmask); // (Not yet handled by Valgrind) FAIL;
937
938   // __NR_setreuid 70
939   GO(__NR_setreuid, "2s 0m");
940   SY(__NR_setreuid, x0, x0); FAIL;
941
942   // __NR_setregid 71
943   GO(__NR_setregid, "2s 0m");
944   SY(__NR_setregid, x0, x0); FAIL;
945
946   // __NR_sigsuspend 72
947   // XXX: how do you use this function?
948   GO(__NR_sigsuspend, "ignore");
949   // (I don't know how to test this...)
950
951   // __NR_sigpending 73
952   GO(__NR_sigpending, "1s 1m");
953   SY(__NR_sigpending, x0); FAIL;
954
955   // __NR_sethostname 74
956   GO(__NR_sethostname, "n/a");
957 //SY(__NR_sethostname); // (Not yet handled by Valgrind) FAIL;
958
959   // __NR_setrlimit 75
960   GO(__NR_setrlimit, "2s 1m");
961   SY(__NR_setrlimit, x0, x0); FAIL;
962
963   // __NR_getrlimit 76
964   GO(__NR_getrlimit, "2s 1m");
965   SY(__NR_getrlimit, x0, x0); FAIL;
966
967   // __NR_getrusage 77
968   GO(__NR_getrusage, "2s 1m");
969   SY(__NR_getrusage, x0, x0); FAIL;
970
971   // __NR_gettimeofday 78
972   GO(__NR_gettimeofday, "2s 2m");
973   SY(__NR_gettimeofday, x0, x0+1); FAIL;
974
975   // __NR_settimeofday 79
976   GO(__NR_settimeofday, "2s 2m");
977   SY(__NR_settimeofday, x0, x0+1); FAIL;
978
979   // __NR_getgroups 80
980   GO(__NR_getgroups, "2s 1m");
981   SY(__NR_getgroups, x0+1, x0+1); FAIL;
982
983   // __NR_setgroups 81
984   GO(__NR_setgroups, "2s 1m");
985   SY(__NR_setgroups, x0+1, x0+1); FAIL;
986
987   // __NR_select 82
988   {
989      long args[5] = { x0+8, x0+0xffffffee, x0+1, x0+1, x0+1 };
990      GO(__NR_select, "1s 5m");
991      SY(__NR_select, args+x0); FAIL;
992   }
993
994   // __NR_symlink 83
995   GO(__NR_symlink, "2s 2m");
996   SY(__NR_symlink, x0, x0); FAIL;
997
998   // __NR_oldlstat 84
999   GO(__NR_oldlstat, "n/a");
1000   // (obsolete, not handled by Valgrind)
1001
1002   // __NR_readlink 85
1003   GO(__NR_readlink, "3s 2m");
1004   SY(__NR_readlink, x0+1, x0+1, x0+1); FAIL;
1005
1006   // __NR_uselib 86
1007   GO(__NR_uselib, "n/a");
1008 //SY(__NR_uselib); // (Not yet handled by Valgrind) FAIL;
1009
1010   // __NR_swapon 87
1011   GO(__NR_swapon, "n/a");
1012 //SY(__NR_swapon); // (Not yet handled by Valgrind) FAIL;
1013
1014   // __NR_reboot 88
1015   GO(__NR_reboot, "n/a");
1016 //SY(__NR_reboot); // (Not yet handled by Valgrind) FAIL;
1017
1018   // __NR_readdir 89
1019   GO(__NR_readdir, "n/a");
1020   // (superseded, not handled by Valgrind)
1021
1022   // __NR_mmap 90
1023   {
1024      long args[6] = { x0, x0, x0, x0, x0-1, x0 };
1025      GO(__NR_mmap, "1s 1m");
1026      SY(__NR_mmap, args+x0); FAIL;
1027   }
1028
1029   // __NR_munmap 91
1030   GO(__NR_munmap, "2s 0m");
1031   SY(__NR_munmap, x0, x0); FAIL;
1032
1033   // __NR_truncate 92
1034   GO(__NR_truncate, "2s 1m");
1035   SY(__NR_truncate, x0, x0); FAIL;
1036
1037   // __NR_ftruncate 93
1038   GO(__NR_ftruncate, "2s 0m");
1039   SY(__NR_ftruncate, x0, x0); FAIL;
1040
1041   // __NR_fchmod 94
1042   GO(__NR_fchmod, "2s 0m");
1043   SY(__NR_fchmod, x0-1, x0); FAIL;
1044
1045   // __NR_fchown 95
1046   GO(__NR_fchown, "3s 0m");
1047   SY(__NR_fchown, x0, x0, x0); FAIL;
1048
1049   // __NR_getpriority 96
1050   GO(__NR_getpriority, "2s 0m");
1051   SY(__NR_getpriority, x0-1, x0); FAIL;
1052
1053   // __NR_setpriority 97
1054   GO(__NR_setpriority, "3s 0m");
1055   SY(__NR_setpriority, x0-1, x0, x0); FAIL;
1056
1057   // __NR_profil 98
1058   GO(__NR_profil, "ni");
1059   SY(__NR_profil); FAIL;
1060
1061   // __NR_statfs 99
1062   GO(__NR_statfs, "2s 2m");
1063   SY(__NR_statfs, x0, x0); FAIL;
1064
1065   // __NR_fstatfs 100
1066   GO(__NR_fstatfs, "2s 1m");
1067   SY(__NR_fstatfs, x0, x0); FAIL;
1068
1069   // __NR_ioperm 101
1070   GO(__NR_ioperm, "3s 0m");
1071   SY(__NR_ioperm, x0, x0, x0); FAIL;
1072
1073   // __NR_socketcall 102
1074   GO(__NR_socketcall, "XXX");
1075   // (XXX: need to do all sub-cases properly)
1076
1077   // __NR_syslog 103
1078   GO(__NR_syslog, "3s 1m");
1079   SY(__NR_syslog, x0+2, x0, x0+1); FAIL;
1080
1081   // __NR_setitimer 104
1082   GO(__NR_setitimer, "3s 2m");
1083   SY(__NR_setitimer, x0, x0+1, x0+1); FAIL;
1084
1085   // __NR_getitimer 105
1086   GO(__NR_getitimer, "2s 1m");
1087   SY(__NR_getitimer, x0, x0, x0); FAIL;
1088
1089   // __NR_stat 106
1090   GO(__NR_stat, "2s 2m");
1091   SY(__NR_stat, x0, x0); FAIL;
1092
1093   // __NR_lstat 107
1094   GO(__NR_lstat, "2s 2m");
1095   SY(__NR_lstat, x0, x0); FAIL;
1096
1097   // __NR_fstat 108
1098   GO(__NR_fstat, "2s 1m");
1099   SY(__NR_fstat, x0, x0); FAIL;
1100
1101   // __NR_olduname 109
1102   GO(__NR_olduname, "n/a");
1103   // (obsolete, not handled by Valgrind)
1104
1105   // __NR_iopl 110
1106   GO(__NR_iopl, "1s 0m");
1107   SY(__NR_iopl, x0+100); FAIL;
1108
1109   // __NR_vhangup 111
1110   GO(__NR_vhangup, "0s 0m");
1111   SY(__NR_vhangup); SUCC_OR_FAIL;  // Will succeed for superuser
1112
1113   // __NR_idle 112
1114   GO(__NR_idle, "ni");
1115   SY(__NR_idle); FAIL;
1116
1117   // __NR_vm86old 113
1118   GO(__NR_vm86old, "n/a");
1119   // (will probably never be handled by Valgrind)
1120
1121   // __NR_swapoff 115
1122   GO(__NR_swapoff, "n/a");
1123 //SY(__NR_swapoff); // (Not yet handled by Valgrind) FAIL;
1124
1125   // __NR_sysinfo 116
1126   GO(__NR_sysinfo, "1s 1m");
1127   SY(__NR_sysinfo, x0); FAIL;
1128
1129   // __NR_ipc 117
1130   // XXX: This is simplistic -- need to do all the sub-cases properly.
1131   // XXX: Also, should be 6 scalar errors, except glibc's syscall() doesn't
1132   //      use the 6th one!
1133   GO(__NR_ipc, "5s 0m");
1134   SY(__NR_ipc, x0+4, x0, x0, x0, x0, x0); FAIL;
1135
1136   // __NR_fsync 118
1137   GO(__NR_fsync, "1s 0m");
1138   SY(__NR_fsync, x0-1); FAIL;
1139
1140   // __NR_sigreturn 119
1141   GO(__NR_sigreturn, "n/a");
1142 //SY(__NR_sigreturn); // (Not yet handled by Valgrind) FAIL;
1143
1144   // __NR_clone 120
1145#ifndef CLONE_PARENT_SETTID
1146#define CLONE_PARENT_SETTID   0x00100000
1147#endif
1148   // XXX: should really be "4s 2m"?  Not sure... (see PRE(sys_clone))
1149   GO(__NR_clone, "4s 0m");
1150   SY(__NR_clone, x0|CLONE_PARENT_SETTID|SIGCHLD, x0, x0, x0); FAIL;
1151   if (0 == res) {
1152      SY(__NR_exit, 0); FAIL;
1153   }
1154
1155   // __NR_setdomainname 121
1156   GO(__NR_setdomainname, "n/a");
1157 //SY(__NR_setdomainname); // (Not yet handled by Valgrind) FAIL;
1158
1159   // __NR_uname 122
1160   GO(__NR_uname, "1s 1m");
1161   SY(__NR_uname, x0); FAIL;
1162
1163   // __NR_modify_ldt 123
1164   GO(__NR_modify_ldt, "3s 1m");
1165   SY(__NR_modify_ldt, x0+1, x0, x0+1); FAILx(EINVAL);
1166
1167   // __NR_adjtimex 124
1168   // XXX: need to do properly, but deref'ing NULL causing Valgrind to crash...
1169     GO(__NR_adjtimex, "XXX");
1170//   SY(__NR_adjtimex, x0); FAIL;
1171
1172   // __NR_mprotect 125
1173   GO(__NR_mprotect, "3s 0m");
1174   SY(__NR_mprotect, x0+1, x0, x0); FAILx(EINVAL);
1175
1176   // __NR_sigprocmask 126
1177   GO(__NR_sigprocmask, "3s 2m");
1178   SY(__NR_sigprocmask, x0, x0+&px[1], x0+&px[1]); SUCC;
1179
1180   // __NR_create_module 127
1181   GO(__NR_create_module, "ni");
1182   SY(__NR_create_module); FAIL;
1183
1184   // __NR_init_module 128
1185   GO(__NR_init_module, "3s 2m");
1186   SY(__NR_init_module, x0, x0+1, x0); FAIL;
1187
1188   // __NR_delete_module 129
1189   GO(__NR_delete_module, "n/a");
1190 //SY(__NR_delete_module); // (Not yet handled by Valgrind) FAIL;
1191
1192   // __NR_get_kernel_syms 130
1193   GO(__NR_get_kernel_syms, "ni");
1194   SY(__NR_get_kernel_syms); FAIL;
1195
1196   // __NR_quotactl 131
1197   GO(__NR_quotactl, "4s 1m");
1198   SY(__NR_quotactl, x0, x0, x0, x0); FAIL;
1199
1200   // __NR_getpgid 132
1201   GO(__NR_getpgid, "1s 0m");
1202   SY(__NR_getpgid, x0-1); FAIL;
1203
1204   // __NR_bdflush 134
1205   GO(__NR_bdflush, "n/a");
1206 //SY(__NR_bdflush); // (Not yet handled by Valgrind) FAIL;
1207
1208   // __NR_sysfs 135
1209   GO(__NR_sysfs, "n/a");
1210 //SY(__NR_sysfs); // (Not yet handled by Valgrind) FAIL;
1211
1212   // __NR_personality 136
1213   GO(__NR_personality, "1s 0m");
1214   SY(__NR_personality, x0+0xffffffff); SUCC;
1215
1216   // __NR_afs_syscall 137
1217   GO(__NR_afs_syscall, "ni");
1218   SY(__NR_afs_syscall); FAIL;
1219
1220   // __NR_setfsuid 138
1221   GO(__NR_setfsuid, "1s 0m");
1222   SY(__NR_setfsuid, x0); SUCC;  // This syscall has a stupid return value
1223
1224   // __NR_setfsgid 139
1225   GO(__NR_setfsgid, "1s 0m");
1226   SY(__NR_setfsgid, x0); SUCC;  // This syscall has a stupid return value
1227
1228   // __NR__llseek 140
1229   GO(__NR__llseek, "5s 1m");
1230   SY(__NR__llseek, x0, x0, x0, x0, x0); FAIL;
1231
1232   // __NR_getdents 141
1233   GO(__NR_getdents, "3s 1m");
1234   SY(__NR_getdents, x0, x0, x0+1); FAIL;
1235
1236   // __NR__newselect 142
1237   GO(__NR__newselect, "5s 4m");
1238   SY(__NR__newselect, x0+8, x0+0xffffffff, x0+1, x0+1, x0+1); FAIL;
1239
1240   // __NR_flock 143
1241   GO(__NR_flock, "2s 0m");
1242   SY(__NR_flock, x0, x0); FAIL;
1243
1244   // __NR_msync 144
1245   GO(__NR_msync, "3s 1m");
1246   SY(__NR_msync, x0, x0+1, x0); FAIL;
1247
1248   // __NR_readv 145
1249   GO(__NR_readv, "3s 1m");
1250   SY(__NR_readv, x0, x0, x0+1); FAIL;
1251
1252   // __NR_writev 146
1253   GO(__NR_writev, "3s 1m");
1254   SY(__NR_writev, x0, x0, x0+1); FAIL;
1255
1256   // __NR_getsid 147
1257   GO(__NR_getsid, "1s 0m");
1258   SY(__NR_getsid, x0-1); FAIL;
1259
1260   // __NR_fdatasync 148
1261   GO(__NR_fdatasync, "1s 0m");
1262   SY(__NR_fdatasync, x0-1); FAIL;
1263
1264   // __NR__sysctl 149
1265   GO(__NR__sysctl, "1s 1m");
1266   SY(__NR__sysctl, x0); FAIL;
1267
1268   // __NR_mlock 150
1269   GO(__NR_mlock, "2s 0m");
1270   SY(__NR_mlock, x0, x0+1); FAIL;
1271
1272   // __NR_munlock 151
1273   GO(__NR_munlock, "2s 0m");
1274   SY(__NR_munlock, x0, x0+1); FAIL;
1275
1276   // __NR_mlockall 152
1277   GO(__NR_mlockall, "1s 0m");
1278   SY(__NR_mlockall, x0-1); FAIL;
1279
1280   // __NR_munlockall 153
1281   GO(__NR_munlockall, "0s 0m");
1282   SY(__NR_munlockall); SUCC_OR_FAILx(EPERM);
1283
1284   // __NR_sched_setparam 154
1285   GO(__NR_sched_setparam, "2s 1m");
1286   SY(__NR_sched_setparam, x0, x0); FAIL;
1287
1288   // __NR_sched_getparam 155
1289   GO(__NR_sched_getparam, "2s 1m");
1290   SY(__NR_sched_getparam, x0, x0); FAIL;
1291
1292   // __NR_sched_setscheduler 156
1293   GO(__NR_sched_setscheduler, "3s 1m");
1294   SY(__NR_sched_setscheduler, x0-1, x0, x0+1); FAIL;
1295
1296   // __NR_sched_getscheduler 157
1297   GO(__NR_sched_getscheduler, "1s 0m");
1298   SY(__NR_sched_getscheduler, x0-1); FAIL;
1299
1300   // __NR_sched_yield 158
1301   GO(__NR_sched_yield, "0s 0m");
1302   SY(__NR_sched_yield); SUCC;
1303
1304   // __NR_sched_get_priority_max 159
1305   GO(__NR_sched_get_priority_max, "1s 0m");
1306   SY(__NR_sched_get_priority_max, x0-1); FAIL;
1307
1308   // __NR_sched_get_priority_min 160
1309   GO(__NR_sched_get_priority_min, "1s 0m");
1310   SY(__NR_sched_get_priority_min, x0-1); FAIL;
1311
1312   // __NR_sched_rr_get_interval 161
1313   GO(__NR_sched_rr_get_interval, "n/a");
1314 //SY(__NR_sched_rr_get_interval); // (Not yet handled by Valgrind) FAIL;
1315
1316   // __NR_nanosleep 162
1317   GO(__NR_nanosleep, "2s 2m");
1318   SY(__NR_nanosleep, x0, x0+1); FAIL;
1319
1320   // __NR_mremap 163
1321   GO(__NR_mremap, "5s 0m");
1322   SY(__NR_mremap, x0+1, x0, x0, x0+MREMAP_FIXED, x0); FAILx(EINVAL);
1323
1324   // __NR_setresuid 164
1325   GO(__NR_setresuid, "3s 0m");
1326   SY(__NR_setresuid, x0, x0, x0); FAIL;
1327
1328   // __NR_getresuid 165
1329   GO(__NR_getresuid, "3s 3m");
1330   SY(__NR_getresuid, x0, x0, x0); FAIL;
1331
1332   // __NR_vm86 166
1333   GO(__NR_vm86, "n/a");
1334   // (will probably never be handled by Valgrind)
1335
1336   // __NR_query_module 167
1337   GO(__NR_query_module, "ni");
1338   SY(__NR_query_module); FAIL;
1339
1340   // __NR_poll 168
1341   GO(__NR_poll, "3s 1m");
1342   SY(__NR_poll, x0, x0+1, x0); FAIL;
1343
1344   // __NR_nfsservctl 169
1345   GO(__NR_nfsservctl, "n/a");
1346 //SY(__NR_nfsservctl); // (Not yet handled by Valgrind) FAIL;
1347
1348   // __NR_setresgid 170
1349   GO(__NR_setresgid, "3s 0m");
1350   SY(__NR_setresgid, x0, x0, x0); FAIL;
1351
1352   // __NR_getresgid 171
1353   GO(__NR_getresgid, "3s 3m");
1354   SY(__NR_getresgid, x0, x0, x0); FAIL;
1355
1356   // __NR_prctl 172
1357   GO(__NR_prctl, "5s 0m");
1358   SY(__NR_prctl, x0, x0, x0, x0, x0); FAIL;
1359
1360   // __NR_rt_sigreturn 173
1361   GO(__NR_rt_sigreturn, "n/a");
1362 //SY(__NR_rt_sigreturn); // (Not yet handled by Valgrind) FAIL;
1363
1364   // __NR_rt_sigaction 174
1365   GO(__NR_rt_sigaction, "4s 4m");
1366   SY(__NR_rt_sigaction, x0, x0+&px[2], x0+&px[2], x0); FAIL;
1367
1368   // __NR_rt_sigprocmask 175
1369   GO(__NR_rt_sigprocmask, "4s 2m");
1370   SY(__NR_rt_sigprocmask, x0, x0+1, x0+1, x0); FAIL;
1371
1372   // __NR_rt_sigpending 176
1373   GO(__NR_rt_sigpending, "2s 1m");
1374   SY(__NR_rt_sigpending, x0, x0+1); FAIL;
1375
1376   // __NR_rt_sigtimedwait 177
1377   GO(__NR_rt_sigtimedwait, "4s 3m");
1378   SY(__NR_rt_sigtimedwait, x0+1, x0+1, x0+1, x0); FAIL;
1379
1380   // __NR_rt_sigqueueinfo 178
1381   GO(__NR_rt_sigqueueinfo, "3s 1m");
1382   SY(__NR_rt_sigqueueinfo, x0, x0+1, x0); FAIL;
1383
1384   // __NR_rt_sigsuspend 179
1385   GO(__NR_rt_sigsuspend, "ignore");
1386   // (I don't know how to test this...)
1387
1388   // __NR_pread64 180
1389   GO(__NR_pread64, "5s 1m");
1390   SY(__NR_pread64, x0, x0, x0+1, x0, x0); FAIL;
1391
1392   // __NR_pwrite64 181
1393   GO(__NR_pwrite64, "5s 1m");
1394   SY(__NR_pwrite64, x0, x0, x0+1, x0, x0); FAIL;
1395
1396   // __NR_getcwd 183
1397   GO(__NR_getcwd, "2s 1m");
1398   SY(__NR_getcwd, x0, x0+1); FAIL;
1399
1400   // __NR_capget 184
1401   GO(__NR_capget, "2s 2m");
1402   SY(__NR_capget, x0, x0); FAIL;
1403
1404   // __NR_capset 185
1405   GO(__NR_capset, "2s 2m");
1406   SY(__NR_capset, x0, x0); FAIL;
1407
1408   // __NR_sigaltstack 186
1409   {
1410      struct our_sigaltstack {
1411              void *ss_sp;
1412              int ss_flags;
1413              size_t ss_size;
1414      } ss;
1415      ss.ss_sp     = NULL;
1416      ss.ss_flags  = 0;
1417      ss.ss_size   = 0;
1418      VALGRIND_MAKE_MEM_NOACCESS(& ss, sizeof(struct our_sigaltstack));
1419      GO(__NR_sigaltstack, "2s 2m");
1420      SY(__NR_sigaltstack, x0+&ss, x0+&ss); SUCC;
1421   }
1422
1423   // __NR_sendfile 187
1424   GO(__NR_sendfile, "4s 1m");
1425   SY(__NR_sendfile, x0, x0, x0+1, x0); FAIL;
1426
1427   // __NR_getpmsg 188
1428   // Could do 5s 4m with more effort, but I can't be bothered for this
1429   // crappy non-standard syscall.
1430   GO(__NR_getpmsg, "5s 0m");
1431   SY(__NR_getpmsg, x0, x0, x0, x0); FAIL;
1432
1433   // __NR_putpmsg 189
1434   // Could do 5s 2m with more effort, but I can't be bothered for this
1435   // crappy non-standard syscall.
1436   GO(__NR_putpmsg, "5s 0m");
1437   SY(__NR_putpmsg, x0, x0, x0, x0, x0); FAIL;
1438
1439   // __NR_vfork 190
1440   GO(__NR_vfork, "other");
1441   // (sse scalar_vfork.c)
1442
1443   // __NR_ugetrlimit 191
1444   GO(__NR_ugetrlimit, "2s 1m");
1445   SY(__NR_ugetrlimit, x0, x0); FAIL;
1446
1447   // __NR_mmap2 192
1448   GO(__NR_mmap2, "6s 0m");
1449   SY(__NR_mmap2, x0, x0, x0, x0, x0-1, x0); FAIL;
1450
1451   // __NR_truncate64 193
1452   GO(__NR_truncate64, "3s 1m");
1453   SY(__NR_truncate64, x0, x0, x0); FAIL;
1454
1455   // __NR_ftruncate64 194
1456   GO(__NR_ftruncate64, "3s 0m");
1457   SY(__NR_ftruncate64, x0, x0, x0); FAIL;
1458
1459   // __NR_stat64 195
1460   GO(__NR_stat64, "2s 2m");
1461   SY(__NR_stat64, x0, x0); FAIL;
1462
1463   // __NR_lstat64 196
1464   GO(__NR_lstat64, "2s 2m");
1465   SY(__NR_lstat64, x0, x0); FAIL;
1466
1467   // __NR_fstat64 197
1468   GO(__NR_fstat64, "2s 1m");
1469   SY(__NR_fstat64, x0, x0); FAIL;
1470
1471   // __NR_lchown32 198
1472   GO(__NR_lchown32, "3s 1m");
1473   SY(__NR_lchown32, x0, x0, x0); FAIL;
1474
1475   // __NR_getuid32 199
1476   GO(__NR_getuid32, "0s 0m");
1477   SY(__NR_getuid32); SUCC;
1478
1479   // __NR_getgid32 200
1480   GO(__NR_getgid32, "0s 0m");
1481   SY(__NR_getgid32); SUCC;
1482
1483   // __NR_geteuid32 201
1484   GO(__NR_geteuid32, "0s 0m");
1485   SY(__NR_geteuid32); SUCC;
1486
1487   // __NR_getegid32 202
1488   GO(__NR_getegid32, "0s 0m");
1489   SY(__NR_getegid32); SUCC;
1490
1491   // __NR_setreuid32 203
1492   GO(__NR_setreuid32, "2s 0m");
1493   SY(__NR_setreuid32, x0, x0); FAIL;
1494
1495   // __NR_setregid32 204
1496   GO(__NR_setregid32, "2s 0m");
1497   SY(__NR_setregid32, x0, x0); FAIL;
1498
1499   // __NR_getgroups32 205
1500   GO(__NR_getgroups32, "2s 1m");
1501   SY(__NR_getgroups32, x0+1, x0+1); FAIL;
1502
1503   // __NR_setgroups32 206
1504   GO(__NR_setgroups32, "2s 1m");
1505   SY(__NR_setgroups32, x0+1, x0+1); FAIL;
1506
1507   // __NR_fchown32 207
1508   GO(__NR_fchown32, "3s 0m");
1509   SY(__NR_fchown32, x0, x0, x0); FAIL;
1510
1511   // __NR_setresuid32 208
1512   GO(__NR_setresuid32, "3s 0m");
1513   SY(__NR_setresuid32, x0, x0, x0); FAIL;
1514
1515   // __NR_getresuid32 209
1516   GO(__NR_getresuid32, "3s 3m");
1517   SY(__NR_getresuid32, x0, x0, x0); FAIL;
1518
1519   // __NR_setresgid32 210
1520   GO(__NR_setresgid32, "3s 0m");
1521   SY(__NR_setresgid32, x0, x0, x0); FAIL;
1522
1523   // __NR_getresgid32 211
1524   GO(__NR_getresgid32, "3s 3m");
1525   SY(__NR_getresgid32, x0, x0, x0); FAIL;
1526
1527   // __NR_chown32 212
1528   GO(__NR_chown32, "3s 1m");
1529   SY(__NR_chown32, x0, x0, x0); FAIL;
1530
1531   // __NR_setuid32 213
1532   GO(__NR_setuid32, "1s 0m");
1533   SY(__NR_setuid32, x0); FAIL;
1534
1535   // __NR_setgid32 214
1536   GO(__NR_setgid32, "1s 0m");
1537   SY(__NR_setgid32, x0); FAIL;
1538
1539   // __NR_setfsuid32 215
1540   GO(__NR_setfsuid32, "1s 0m");
1541   SY(__NR_setfsuid32, x0); SUCC;  // This syscall has a stupid return value
1542
1543   // __NR_setfsgid32 216
1544   GO(__NR_setfsgid32, "1s 0m");
1545   SY(__NR_setfsgid32, x0); SUCC;  // This syscall has a stupid return value
1546
1547   // __NR_pivot_root 217
1548   GO(__NR_pivot_root, "n/a");
1549 //SY(__NR_pivot_root); // (Not yet handled by Valgrind) FAIL;
1550
1551   // __NR_mincore 218
1552   GO(__NR_mincore, "3s 1m");
1553   SY(__NR_mincore, x0, x0+40960, x0); FAIL;
1554
1555   // __NR_madvise 219
1556   GO(__NR_madvise, "3s 0m");
1557   SY(__NR_madvise, x0, x0+1, x0); FAILx(ENOMEM);
1558
1559   // __NR_getdents64 220
1560   GO(__NR_getdents64, "3s 1m");
1561   SY(__NR_getdents64, x0, x0, x0+1); FAIL;
1562
1563   // __NR_fcntl64 221
1564   // As with sys_open(), we don't trigger errors for the 1st two args for
1565   // the later ones.
1566   // For F_GETFD the 3rd arg is ignored.
1567   GO(__NR_fcntl64, "(GETFD) 2s 0m");
1568   SY(__NR_fcntl64, x0-1, x0+F_GETFD, x0); FAILx(EBADF);
1569
1570   // For F_DUPFD the 3rd arg is 'arg'
1571   GO(__NR_fcntl64, "(DUPFD) 1s 0m");
1572   SY(__NR_fcntl64, -1, F_DUPFD, x0); FAILx(EBADF);
1573
1574   // For F_GETLK the 3rd arg is 'lock'.
1575   // On x86, this fails w/EBADF.  But on amd64 in 32-bit mode it fails
1576   // w/EFAULT.
1577   GO(__NR_fcntl64, "(GETLK) 1s 0m");
1578   SY(__NR_fcntl64, -1, +F_GETLK, x0); FAIL; //FAILx(EBADF);
1579
1580   // 222
1581   GO(222, "ni");
1582   SY(222); FAIL;
1583
1584   // 223
1585   GO(223, "ni");
1586   SY(223); FAIL;
1587
1588   // __NR_gettid 224
1589   GO(__NR_gettid, "n/a");
1590 //SY(__NR_gettid); // (Not yet handled by Valgrind) FAIL;
1591
1592   // __NR_readahead 225
1593   GO(__NR_readahead, "n/a");
1594 //SY(__NR_readahead); // (Not yet handled by Valgrind) FAIL;
1595
1596   // __NR_setxattr 226
1597   GO(__NR_setxattr, "5s 3m");
1598   SY(__NR_setxattr, x0, x0, x0, x0+1, x0); FAIL;
1599
1600   // __NR_lsetxattr 227
1601   GO(__NR_lsetxattr, "5s 3m");
1602   SY(__NR_lsetxattr, x0, x0, x0, x0+1, x0); FAIL;
1603
1604   // __NR_fsetxattr 228
1605   GO(__NR_fsetxattr, "5s 2m");
1606   SY(__NR_fsetxattr, x0, x0, x0, x0+1, x0); FAIL;
1607
1608   // __NR_getxattr 229
1609   GO(__NR_getxattr, "4s 3m");
1610   SY(__NR_getxattr, x0, x0, x0, x0+1); FAIL;
1611
1612   // __NR_lgetxattr 230
1613   GO(__NR_lgetxattr, "4s 3m");
1614   SY(__NR_lgetxattr, x0, x0, x0, x0+1); FAIL;
1615
1616   // __NR_fgetxattr 231
1617   GO(__NR_fgetxattr, "4s 2m");
1618   SY(__NR_fgetxattr, x0, x0, x0, x0+1); FAIL;
1619
1620   // __NR_listxattr 232
1621   GO(__NR_listxattr, "3s 2m");
1622   SY(__NR_listxattr, x0, x0, x0+1); FAIL;
1623
1624   // __NR_llistxattr 233
1625   GO(__NR_llistxattr, "3s 2m");
1626   SY(__NR_llistxattr, x0, x0, x0+1); FAIL;
1627
1628   // __NR_flistxattr 234
1629   GO(__NR_flistxattr, "3s 1m");
1630   SY(__NR_flistxattr, x0-1, x0, x0+1); FAIL; /* kernel returns EBADF, but both seem correct */
1631
1632   // __NR_removexattr 235
1633   GO(__NR_removexattr, "2s 2m");
1634   SY(__NR_removexattr, x0, x0); FAIL;
1635
1636   // __NR_lremovexattr 236
1637   GO(__NR_lremovexattr, "2s 2m");
1638   SY(__NR_lremovexattr, x0, x0); FAIL;
1639
1640   // __NR_fremovexattr 237
1641   GO(__NR_fremovexattr, "2s 1m");
1642   SY(__NR_fremovexattr, x0, x0); FAIL;
1643
1644   // __NR_tkill 238
1645   GO(__NR_tkill, "n/a");
1646 //SY(__NR_tkill); // (Not yet handled by Valgrind) FAIL;
1647
1648   // __NR_sendfile64 239
1649   GO(__NR_sendfile64, "4s 1m");
1650   SY(__NR_sendfile64, x0, x0, x0+1, x0); FAIL;
1651
1652   // __NR_futex 240
1653   #ifndef FUTEX_WAIT
1654   #define FUTEX_WAIT   0
1655   #endif
1656   // XXX: again, glibc not doing 6th arg means we have only 5s errors
1657   GO(__NR_futex, "4s 2m");
1658   SY(__NR_futex, x0+FUTEX_WAIT, x0, x0, x0+1); FAIL;
1659
1660   // __NR_sched_setaffinity 241
1661   GO(__NR_sched_setaffinity, "3s 1m");
1662   SY(__NR_sched_setaffinity, x0, x0+1, x0); FAIL;
1663
1664   // __NR_sched_getaffinity 242
1665   GO(__NR_sched_getaffinity, "3s 1m");
1666   SY(__NR_sched_getaffinity, x0, x0+1, x0); FAIL;
1667
1668   // __NR_set_thread_area 243
1669   GO(__NR_set_thread_area, "1s 1m");
1670   SY(__NR_set_thread_area, x0); FAILx(EFAULT);
1671
1672   // __NR_get_thread_area 244
1673   GO(__NR_get_thread_area, "1s 1m");
1674   SY(__NR_get_thread_area, x0); FAILx(EFAULT);
1675
1676   // __NR_io_setup 245
1677   GO(__NR_io_setup, "2s 1m");
1678   SY(__NR_io_setup, x0, x0); FAIL;
1679
1680   // __NR_io_destroy 246
1681   {
1682      // jump through hoops to prevent the PRE(io_destroy) wrapper crashing.
1683      struct fake_aio_ring {
1684        unsigned        id;     /* kernel internal index number */
1685        unsigned        nr;     /* number of io_events */
1686        // There are more fields in the real aio_ring, but the 'nr' field is
1687        // the only one used by the PRE() wrapper.
1688      } ring = { 0, 0 };
1689      struct fake_aio_ring* ringptr = &ring;
1690      GO(__NR_io_destroy, "1s 0m");
1691      SY(__NR_io_destroy, x0+&ringptr); FAIL;
1692   }
1693
1694   // __NR_io_getevents 247
1695   GO(__NR_io_getevents, "5s 2m");
1696   SY(__NR_io_getevents, x0, x0, x0+1, x0, x0+1); FAIL;
1697
1698   // __NR_io_submit 248
1699   GO(__NR_io_submit, "3s 1m");
1700   SY(__NR_io_submit, x0, x0+1, x0); FAIL;
1701
1702   // __NR_io_cancel 249
1703   GO(__NR_io_cancel, "3s 2m");
1704   SY(__NR_io_cancel, x0, x0, x0); FAIL;
1705
1706   // __NR_fadvise64 250
1707   GO(__NR_fadvise64, "n/a");
1708 //SY(__NR_fadvise64); // (Not yet handled by Valgrind) FAIL;
1709
1710   // 251
1711   GO(251, "ni");
1712   SY(251); FAIL;
1713
1714   // __NR_exit_group 252
1715   GO(__NR_exit_group, "other");
1716   // (see scalar_exit_group.c)
1717
1718   // __NR_lookup_dcookie 253
1719   GO(__NR_lookup_dcookie, "4s 1m");
1720   SY(__NR_lookup_dcookie, x0, x0, x0, x0+1); FAIL;
1721
1722   // __NR_epoll_create 254
1723   GO(__NR_epoll_create, "1s 0m");
1724   SY(__NR_epoll_create, x0); SUCC_OR_FAIL;
1725
1726   // __NR_epoll_ctl 255
1727   GO(__NR_epoll_ctl, "4s 1m");
1728   SY(__NR_epoll_ctl, x0, x0, x0, x0); FAIL;
1729
1730   // __NR_epoll_wait 256
1731   GO(__NR_epoll_wait, "4s 1m");
1732   SY(__NR_epoll_wait, x0, x0, x0+1, x0); FAIL;
1733
1734   // __NR_remap_file_pages 257
1735   GO(__NR_remap_file_pages, "n/a");
1736 //SY(__NR_remap_file_pages); // (Not yet handled by Valgrind) FAIL;
1737
1738   // __NR_set_tid_address 258
1739   GO(__NR_set_tid_address, "1s 0m");
1740   SY(__NR_set_tid_address, x0); SUCC_OR_FAILx(ENOSYS);
1741
1742   // __NR_timer_create 259
1743   GO(__NR_timer_create, "3s 2m");
1744   SY(__NR_timer_create, x0, x0+1, x0); FAIL;
1745
1746   // __NR_timer_settime (__NR_timer_create+1)
1747   GO(__NR_timer_settime, "4s 2m");
1748   SY(__NR_timer_settime, x0, x0, x0, x0+1); FAIL;
1749
1750   // __NR_timer_gettime (__NR_timer_create+2)
1751   GO(__NR_timer_gettime, "2s 1m");
1752   SY(__NR_timer_gettime, x0, x0); FAIL;
1753
1754   // __NR_timer_getoverrun (__NR_timer_create+3)
1755   GO(__NR_timer_getoverrun, "1s 0m");
1756   SY(__NR_timer_getoverrun, x0); FAIL;
1757
1758   // __NR_timer_delete (__NR_timer_create+4)
1759   GO(__NR_timer_delete, "1s 0m");
1760   SY(__NR_timer_delete, x0); FAIL;
1761
1762   // __NR_clock_settime (__NR_timer_create+5)
1763   GO(__NR_clock_settime, "2s 1m");
1764   SY(__NR_clock_settime, x0, x0);  FAIL; FAIL;
1765
1766   // __NR_clock_gettime (__NR_timer_create+6)
1767   GO(__NR_clock_gettime, "2s 1m");
1768   SY(__NR_clock_gettime, x0, x0); FAIL;
1769
1770   // __NR_clock_getres (__NR_timer_create+7)
1771   GO(__NR_clock_getres, "2s 1m");
1772   SY(__NR_clock_getres, x0+1, x0+1); FAIL; FAIL;
1773
1774   // __NR_clock_nanosleep (__NR_timer_create+8)
1775   GO(__NR_clock_nanosleep, "n/a");
1776 //SY(__NR_clock_nanosleep); // (Not yet handled by Valgrind) FAIL;
1777
1778   // __NR_statfs64 268
1779   GO(__NR_statfs64, "3s 2m");
1780   SY(__NR_statfs64, x0, x0+1, x0); FAIL;
1781
1782   // __NR_fstatfs64 269
1783   GO(__NR_fstatfs64, "3s 1m");
1784   SY(__NR_fstatfs64, x0, x0+1, x0); FAIL;
1785
1786   // __NR_tgkill 270
1787   GO(__NR_tgkill, "n/a");
1788 //SY(__NR_tgkill); // (Not yet handled by Valgrind) FAIL;
1789
1790   // __NR_utimes 271
1791   GO(__NR_utimes, "2s 2m");
1792   SY(__NR_utimes, x0, x0+1); FAIL;
1793
1794   // __NR_fadvise64_64 272
1795   GO(__NR_fadvise64_64, "n/a");
1796 //SY(__NR_fadvise64_64); // (Not yet handled by Valgrind) FAIL;
1797
1798   // __NR_vserver 273
1799   GO(__NR_vserver, "ni");
1800   SY(__NR_vserver); FAIL;
1801
1802   // __NR_mbind 274
1803   GO(__NR_mbind, "n/a");
1804 //SY(__NR_mbind); // (Not yet handled by Valgrind) FAIL;
1805
1806   // __NR_get_mempolicy 275
1807   GO(__NR_get_mempolicy, "n/a");
1808 //SY(__NR_get_mempolicy); // (Not yet handled by Valgrind) FAIL;
1809
1810   // __NR_set_mempolicy 276
1811   GO(__NR_set_mempolicy, "n/a");
1812 //SY(__NR_set_mempolicy); // (Not yet handled by Valgrind) FAIL;
1813
1814   // __NR_mq_open 277
1815   GO(__NR_mq_open, "4s 3m");
1816   SY(__NR_mq_open, x0, x0+O_CREAT, x0, x0+1); FAIL;
1817
1818   // __NR_mq_unlink (__NR_mq_open+1)
1819   GO(__NR_mq_unlink, "1s 1m");
1820   SY(__NR_mq_unlink, x0); FAIL;
1821
1822   // __NR_mq_timedsend (__NR_mq_open+2)
1823   GO(__NR_mq_timedsend, "5s 2m");
1824   SY(__NR_mq_timedsend, x0, x0, x0+1, x0, x0+1); FAIL;
1825
1826   // __NR_mq_timedreceive (__NR_mq_open+3)
1827   GO(__NR_mq_timedreceive, "5s 3m");
1828   SY(__NR_mq_timedreceive, x0, x0, x0+1, x0+1, x0+1); FAIL;
1829
1830   // __NR_mq_notify (__NR_mq_open+4)
1831   GO(__NR_mq_notify, "2s 1m");
1832   SY(__NR_mq_notify, x0, x0+1); FAIL;
1833
1834   // __NR_mq_getsetattr (__NR_mq_open+5)
1835   GO(__NR_mq_getsetattr, "3s 2m");
1836   SY(__NR_mq_getsetattr, x0, x0+1, x0+1); FAIL;
1837
1838   // __NR_sys_kexec_load 283
1839   GO(__NR_sys_kexec_load, "ni");
1840   SY(__NR_sys_kexec_load); FAIL;
1841#endif
1842
1843   // no such syscall...
1844   GO(9999, 9999, "1e");
1845   SY(9999); FAIL;
1846
1847   // __NR_exit 1
1848   GO(__NR_exit, 1, "1s 0m");
1849   SY(__NR_exit, x0); FAIL;
1850
1851   assert(0);
1852}
1853
1854