2 * Check decoding of socketcall syscall.
4 * Copyright (c) 2016-2018 Dmitry V. Levin <ldv@altlinux.org>
7 * SPDX-License-Identifier: GPL-2.0-or-later
11 #include <asm/unistd.h>
13 #ifdef __NR_socketcall
20 # include "xlat/socketcalls.h"
23 xlookup_uint(const struct xlat *xlat, const unsigned int val)
25 for (; xlat->str != NULL; xlat++)
31 static const int sc_min = 1, sc_max = 20;
35 test_socketcall(const int i, const void *const addr)
37 const unsigned long call =
38 (unsigned long) 0xfacefeed00000000ULL | (unsigned int) i;
40 long rc = syscall(__NR_socketcall, call, addr);
42 if (i < sc_min || i > sc_max) {
43 printf("socketcall(%d, %p) = %ld %s (%m)\n",
44 (int) call, addr, rc, errno2name());
45 } else if (addr == efault) {
46 const char *const str = xlookup_uint(socketcalls, i);
48 printf("socketcall(%s, %p) = %ld %s (%m)\n",
49 str, addr, rc, errno2name());
55 assert((unsigned) sc_min == socketcalls[0].val);
56 assert((unsigned) sc_max == socketcalls[ARRAY_SIZE(socketcalls) - 2].val);
58 const unsigned long *const args = tail_alloc(sizeof(*args) * 6);
59 efault = tail_alloc(1) + 1;
62 for (i = sc_min - 3; i <= sc_max + 3; ++i) {
63 test_socketcall(i, efault);
64 test_socketcall(i, args);
67 puts("+++ exited with 0 +++");
73 SKIP_MAIN_UNDEFINED("__NR_socketcall")