Commit | Line | Data |
---|---|---|
fbbe92c5 SDJ |
1 | /* This file is used to test the 'catch syscall' feature on GDB. |
2 | ||
3 | Please, if you are going to edit this file DO NOT change the syscalls | |
4 | being called (nor the order of them). If you really must do this, then | |
5 | take a look at catch-syscall.exp and modify there too. | |
6 | ||
7 | Written by Sergio Durigan Junior <sergiodj@linux.vnet.ibm.com> | |
8 | September, 2008 */ | |
9 | ||
10 | #include <unistd.h> | |
2e0d821f | 11 | #include <sys/syscall.h> |
fbbe92c5 SDJ |
12 | #include <fcntl.h> |
13 | #include <sys/stat.h> | |
bfd09d20 | 14 | #include <sched.h> |
fbbe92c5 | 15 | |
2e0d821f SDJ |
16 | /* These are the syscalls numbers used by the test. */ |
17 | ||
2abc3f8d DB |
18 | int close_syscall = SYS_close; |
19 | int chroot_syscall = SYS_chroot; | |
4924df79 GKB |
20 | /* GDB had a bug where it couldn't catch syscall number 0 (PR 16297). |
21 | In most GNU/Linux architectures, syscall number 0 is | |
22 | restart_syscall, which can't be called from userspace. However, | |
23 | the "read" syscall is zero on x86_64. */ | |
2abc3f8d | 24 | int read_syscall = SYS_read; |
f68f11b7 | 25 | #ifdef SYS_pipe |
2abc3f8d | 26 | int pipe_syscall = SYS_pipe; |
f68f11b7 YQ |
27 | #else |
28 | int pipe2_syscall = SYS_pipe2; | |
29 | #endif | |
2abc3f8d | 30 | int write_syscall = SYS_write; |
28244707 YQ |
31 | #if defined(__arm__) |
32 | /* Although 123456789 is an illegal syscall umber on arm linux, kernel | |
33 | sends SIGILL rather than returns -ENOSYS. However, arm linux kernel | |
34 | returns -ENOSYS if syscall number is within 0xf0001..0xf07ff, so we | |
35 | can use 0xf07ff for unknown_syscall in test. */ | |
36 | int unknown_syscall = 0x0f07ff; | |
37 | #else | |
bfd09d20 | 38 | int unknown_syscall = 123456789; |
28244707 | 39 | #endif |
2abc3f8d | 40 | int exit_group_syscall = SYS_exit_group; |
2e0d821f | 41 | |
82075af2 JS |
42 | /* Set by the test when it wants execve. */ |
43 | int do_execve = 0; | |
44 | ||
fbbe92c5 | 45 | int |
82075af2 | 46 | main (int argc, char *const argv[]) |
fbbe92c5 | 47 | { |
4924df79 GKB |
48 | int fd[2]; |
49 | char buf1[2] = "a"; | |
50 | char buf2[2]; | |
51 | ||
82075af2 JS |
52 | /* Test a simple self-exec, but only on request. */ |
53 | if (do_execve) | |
54 | execv (*argv, argv); | |
55 | ||
fbbe92c5 SDJ |
56 | /* A close() with a wrong argument. We are only |
57 | interested in the syscall. */ | |
58 | close (-1); | |
59 | ||
60 | chroot ("."); | |
61 | ||
4924df79 GKB |
62 | pipe (fd); |
63 | ||
64 | write (fd[1], buf1, sizeof (buf1)); | |
65 | read (fd[0], buf2, sizeof (buf2)); | |
66 | ||
bfd09d20 JS |
67 | /* Test vfork-event interactions. Child exits immediately. |
68 | (Plain fork won't work on no-mmu kernel configurations.) */ | |
69 | if (vfork () == 0) | |
70 | _exit (0); | |
71 | ||
72 | /* Trigger an intentional ENOSYS. */ | |
73 | syscall (unknown_syscall); | |
74 | ||
fbbe92c5 SDJ |
75 | /* The last syscall. Do not change this. */ |
76 | _exit (0); | |
77 | } |