sewardj | 4eee476 | 2006-10-14 15:51:32 +0000 | [diff] [blame] | 1 | #include "../../../include/vki/vki-scnums-x86-linux.h" |
nethercote | e365ff5 | 2004-11-12 17:12:04 +0000 | [diff] [blame] | 2 | |
nethercote | 75a8c98 | 2004-11-11 19:03:34 +0000 | [diff] [blame] | 3 | #include <assert.h> |
nethercote | 92b2fd5 | 2004-11-16 16:15:41 +0000 | [diff] [blame] | 4 | #include <errno.h> |
nethercote | 75a8c98 | 2004-11-11 19:03:34 +0000 | [diff] [blame] | 5 | #include <fcntl.h> |
| 6 | #include <stdio.h> |
| 7 | #include <stdlib.h> |
nethercote | 75a8c98 | 2004-11-11 19:03:34 +0000 | [diff] [blame] | 8 | #include <sys/syscall.h> |
nethercote | 9a3beb9 | 2004-11-12 17:07:26 +0000 | [diff] [blame] | 9 | #include <sys/stat.h> |
| 10 | #include <sys/ptrace.h> |
nethercote | 75a8c98 | 2004-11-11 19:03:34 +0000 | [diff] [blame] | 11 | #include <sys/types.h> |
| 12 | |
nethercote | e365ff5 | 2004-11-12 17:12:04 +0000 | [diff] [blame] | 13 | // Since we use vki_unistd.h, we can't include <unistd.h>. So we have to |
| 14 | // declare this ourselves. |
| 15 | extern long int syscall (long int __sysno, ...) __THROW; |
| 16 | |
nethercote | 75a8c98 | 2004-11-11 19:03:34 +0000 | [diff] [blame] | 17 | // Thorough syscall scalar arg checking. Also serves as thorough checking |
| 18 | // for (very) basic syscall use. Generally not trying to do anything |
| 19 | // meaningful with the syscalls. |
| 20 | |
| 21 | #define GO(__NR_xxx, s) \ |
| 22 | fprintf(stderr, "-----------------------------------------------------\n" \ |
| 23 | "%3d:%20s %s\n" \ |
| 24 | "-----------------------------------------------------\n", \ |
| 25 | __NR_xxx, #__NR_xxx, s); |
| 26 | |
nethercote | 92b2fd5 | 2004-11-16 16:15:41 +0000 | [diff] [blame] | 27 | #define SY res = syscall |
nethercote | 75a8c98 | 2004-11-11 19:03:34 +0000 | [diff] [blame] | 28 | |
nethercote | 92b2fd5 | 2004-11-16 16:15:41 +0000 | [diff] [blame] | 29 | #define FAIL assert(-1 == res); |
| 30 | #define SUCC assert(-1 != res); |
| 31 | #define SUCC_OR_FAIL /* no test */ |
| 32 | |
| 33 | #define FAILx(E) \ |
| 34 | do { \ |
| 35 | int myerrno = errno; \ |
| 36 | if (-1 == res) { \ |
| 37 | if (E == myerrno) { \ |
| 38 | /* as expected */ \ |
| 39 | } else { \ |
| 40 | fprintf(stderr, "Expected error %s (%d), got %d\n", #E, E, myerrno); \ |
| 41 | exit(1); \ |
| 42 | } \ |
| 43 | } else { \ |
| 44 | fprintf(stderr, "Expected error %s (%d), got success\n", #E, E); \ |
| 45 | exit(1); \ |
| 46 | } \ |
| 47 | } while (0); |
nethercote | 75a8c98 | 2004-11-11 19:03:34 +0000 | [diff] [blame] | 48 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 49 | #define SUCC_OR_FAILx(E) \ |
| 50 | do { \ |
| 51 | int myerrno = errno; \ |
| 52 | if (-1 == res) { \ |
| 53 | if (E == myerrno) { \ |
| 54 | /* as expected */ \ |
| 55 | } else { \ |
| 56 | fprintf(stderr, "Expected error %s (%d), got %d\n", #E, E, myerrno); \ |
| 57 | exit(1); \ |
| 58 | } \ |
| 59 | } \ |
| 60 | } while (0); |