1 /* 2 * Test GDB syscall catchpoints. 3 * 4 * SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 #define _GNU_SOURCE 7 #include <stdlib.h> 8 #include <unistd.h> 9 10 const char *catch_syscalls_state = "start"; 11 end_of_main(void)12void end_of_main(void) 13 { 14 } 15 main(void)16int main(void) 17 { 18 int ret = EXIT_FAILURE; 19 char c0 = 'A', c1; 20 int fd[2]; 21 22 catch_syscalls_state = "pipe2"; 23 if (pipe2(fd, 0)) { 24 goto out; 25 } 26 27 catch_syscalls_state = "write"; 28 if (write(fd[1], &c0, sizeof(c0)) != sizeof(c0)) { 29 goto out_close; 30 } 31 32 catch_syscalls_state = "read"; 33 if (read(fd[0], &c1, sizeof(c1)) != sizeof(c1)) { 34 goto out_close; 35 } 36 37 catch_syscalls_state = "check"; 38 if (c0 == c1) { 39 ret = EXIT_SUCCESS; 40 } 41 42 out_close: 43 catch_syscalls_state = "close"; 44 close(fd[0]); 45 close(fd[1]); 46 47 out: 48 catch_syscalls_state = "end"; 49 end_of_main(); 50 return ret; 51 } 52