2 * Check decoding of return values injected into a syscall that "never fails".
4 * Copyright (c) 2018 The strace developers.
7 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include <asm/unistd.h>
17 #include "raw_syscall.h"
20 /* alpha has no getpid */
21 # define SC_NR __NR_getpgrp
22 # define SC_NAME "getpgrp"
23 # define getpid getpgrp
25 # define SC_NR __NR_getpid
26 # define SC_NAME "getpid"
30 # define INVOKE_SC(err) raw_syscall_0(SC_NR, &err)
32 /* No raw_syscall_0, let's use getpid() and hope for the best. */
33 # define INVOKE_SC(err) getpid()
37 * This prototype is intentionally different
38 * from the prototype provided by <unistd.h>.
40 extern kernel_ulong_t getpid(void);
43 main(int ac, char **av)
45 assert(ac == 1 || ac == 2);
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);
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);
59 printf("%s() = %llu (INJECTED)\n",
60 SC_NAME, (unsigned long long) rc);
62 puts("+++ exited with 0 +++");