]> granicus.if.org Git - strace/blob - tests/inject-nf.c
Update copyright headers
[strace] / tests / inject-nf.c
1 /*
2  * Check decoding of return values injected into a syscall that "never fails".
3  *
4  * Copyright (c) 2018 The strace developers.
5  * All rights reserved.
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9
10 #include "tests.h"
11
12 #include <assert.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <asm/unistd.h>
16
17 #include "raw_syscall.h"
18
19 #ifdef __alpha__
20 /* alpha has no getpid */
21 # define SC_NR __NR_getpgrp
22 # define SC_NAME "getpgrp"
23 # define getpid getpgrp
24 #else
25 # define SC_NR __NR_getpid
26 # define SC_NAME "getpid"
27 #endif
28
29 #ifdef raw_syscall_0
30 # define INVOKE_SC(err) raw_syscall_0(SC_NR, &err)
31 #else
32 /* No raw_syscall_0, let's use getpid() and hope for the best.  */
33 # define INVOKE_SC(err) getpid()
34 #endif
35
36 /*
37  * This prototype is intentionally different
38  * from the prototype provided by <unistd.h>.
39  */
40 extern kernel_ulong_t getpid(void);
41
42 int
43 main(int ac, char **av)
44 {
45         assert(ac == 1 || ac == 2);
46
47         kernel_ulong_t expected =
48                 (ac == 1) ? getpid() : strtoull(av[1], NULL, 0);
49         kernel_ulong_t err = 0;
50         kernel_ulong_t rc = INVOKE_SC(err);
51
52         if (err || rc != expected)
53                 error_msg_and_fail("expected %#llx, got rval=%#llx err=%#llx",
54                                    (unsigned long long) expected,
55                                    (unsigned long long) rc,
56                                    (unsigned long long) err);
57
58         if (ac == 2) {
59                 printf("%s() = %llu (INJECTED)\n",
60                        SC_NAME, (unsigned long long) rc);
61
62                 puts("+++ exited with 0 +++");
63         }
64
65         return 0;
66 }