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