1 /*
2 * Check decoding of sysctl syscall.
3 *
4 * Copyright (c) 2022 Dmitry V. Levin <ldv@strace.io>
5 * All rights reserved.
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10 #include "tests.h"
11 #include "scno.h"
12
13 #ifdef __NR__sysctl
14
15 # include <stdio.h>
16 # include <string.h>
17 # include <unistd.h>
18 # include <linux/sysctl.h>
19
20 static const char *errstr;
21
22 static long
23 k_sysctl(const void *const args)
24 {
25 const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
26 const long rc = syscall(__NR__sysctl, (uintptr_t) args,
27 bad, bad, bad, bad, bad);
28 errstr = sprintrc(rc);
29 return rc;
30 }
31
32 int
33 main(void)
34 {
35 TAIL_ALLOC_OBJECT_CONST_PTR(struct __sysctl_args, args);
36 void *const efault = args + 1;
37
38 k_sysctl(efault);
39 printf("_sysctl(%p) = %s\n", efault, errstr);
40
41 memset(args, 0, sizeof(*args));
42 k_sysctl(args);
43 printf("_sysctl({name=NULL, nlen=0, oldval=NULL, oldlenp=NULL"
44 ", newval=NULL, newlen=0}) = %s\n", errstr);
45
46 fill_memory_ex(args, sizeof(*args), 'a', 'z' - 'a' + 1);
47 args->name = efault;
48
49 k_sysctl(args);
50 printf("_sysctl({name=%p, nlen=%d, oldval=%p, oldlenp=%p"
51 ", newval=%p, newlen=%llu}) = %s\n",
52 args->name, args->nlen, args->oldval, args->oldlenp,
53 args->newval, (unsigned long long) args->newlen, errstr);
54
55 puts("+++ exited with 0 +++");
56 return 0;
57 }
58
59 #else
60
61 SKIP_MAIN_UNDEFINED("__NR__sysctl")
62
63 #endif