1 /*
2 * Check decoding of lookup_dcookie syscall.
3 *
4 * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
5 * Copyright (c) 2016-2021 The strace developers.
6 * All rights reserved.
7 *
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11 #include "tests.h"
12 #include "scno.h"
13
14 #include <inttypes.h>
15 #include <limits.h>
16 #include <stdio.h>
17 #include <unistd.h>
18
19 static void
20 do_lookup_cookie(uint64_t cookie, char *buf, kernel_ulong_t len)
21 {
22 long rc;
23 const char *errstr;
24
25 #if (LONG_MAX > INT_MAX) \
26 || (defined __x86_64__ && defined __ILP32__) \
27 || defined LINUX_MIPSN32
28 rc = syscall(__NR_lookup_dcookie, cookie, buf, len);
29 #else
30 rc = syscall(__NR_lookup_dcookie, LL_VAL_TO_PAIR(cookie), buf, len);
31 #endif
32
33 errstr = sprintrc(rc);
34 printf("lookup_dcookie(%" PRIu64 ", ", cookie);
35
36 /* Here, we trust successful return code */
37 if ((rc >= 0) && (rc < (long) INT_MAX)) {
38 printf("%.*s, ", (int) rc, buf);
39 } else {
40 if (buf != NULL)
41 printf("%p, ", buf);
42 else
43 printf("NULL, ");
44 }
45
46 printf("%" PRIu64 ") = %s\n", (uint64_t) len, errstr);
47 }
48
49 int
50 main(void)
51 {
52 enum { BUF_SIZE = 4096 };
53
54 static const uint64_t bogus_cookie =
55 (uint64_t) 0xf157feeddeadfaceULL;
56 static const kernel_ulong_t bogus_len =
57 (kernel_ulong_t) 0xbadc0dedda7a1057ULL;
58
59 char *buf = tail_alloc(BUF_SIZE);
60
61 do_lookup_cookie(0, NULL, 0);
62 do_lookup_cookie(bogus_cookie, buf + BUF_SIZE, bogus_len);
63 do_lookup_cookie(bogus_cookie, buf, BUF_SIZE);
64
65 puts("+++ exited with 0 +++");
66
67 return 0;
68 }