2 * Check decoding of lookup_dcookie syscall.
4 * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
7 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include <asm/unistd.h>
14 #ifdef __NR_lookup_dcookie
16 # include <inttypes.h>
22 do_lookup_cookie(uint64_t cookie, char *buf, kernel_ulong_t len)
27 # if (LONG_MAX > INT_MAX) \
28 || (defined __x86_64__ && defined __ILP32__) \
29 || defined LINUX_MIPSN32
30 rc = syscall(__NR_lookup_dcookie, cookie, buf, len);
32 rc = syscall(__NR_lookup_dcookie, LL_VAL_TO_PAIR(cookie), buf, len);
35 errstr = sprintrc(rc);
36 printf("lookup_dcookie(%" PRIu64 ", ", cookie);
38 /* Here, we trust successful return code */
39 if ((rc >= 0) && (rc < (long) INT_MAX)) {
40 printf("%.*s, ", (int) rc, buf);
48 printf("%" PRIu64 ") = %s\n", (uint64_t) len, errstr);
54 enum { BUF_SIZE = 4096 };
56 static const uint64_t bogus_cookie =
57 (uint64_t) 0xf157feeddeadfaceULL;
58 static const kernel_ulong_t bogus_len =
59 (kernel_ulong_t) 0xbadc0dedda7a1057ULL;
61 char *buf = tail_alloc(BUF_SIZE);
63 do_lookup_cookie(0, NULL, 0);
64 do_lookup_cookie(bogus_cookie, buf + BUF_SIZE, bogus_len);
65 do_lookup_cookie(bogus_cookie, buf, BUF_SIZE);
67 puts("+++ exited with 0 +++");
74 SKIP_MAIN_UNDEFINED("__NR_lookup_dcookie");