1 /*
2 * Check decoding of fsopen syscall.
3 *
4 * Copyright (c) 2019-2021 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 #include <stdio.h>
14 #include <stdint.h>
15 #include <unistd.h>
16
17 static const char *errstr;
18
19 static long
20 k_fsopen(const void *name, const unsigned int flags)
21 {
22 const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
23 const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
24 const kernel_ulong_t arg1 = (uintptr_t) name;
25 const kernel_ulong_t arg2 = fill | flags;
26 const long rc = syscall(__NR_fsopen, arg1, arg2, bad, bad, bad, bad);
27 errstr = sprintrc(rc);
28 return rc;
29 }
30
31 int
32 main(void)
33 {
34 char *const name1 = tail_alloc(DEFAULT_STRLEN + 2);
35 char *const name = name1 + 1;
36 const void *const efault = name + DEFAULT_STRLEN + 1;
37 const char *const empty = efault - 1;
38 fill_memory_ex(name1, DEFAULT_STRLEN + 1, '0', 10);
39 name1[DEFAULT_STRLEN + 1] = '\0';
40
41 k_fsopen(name, 0);
42 printf("fsopen(\"%s\", 0) = %s\n", name, errstr);
43
44 k_fsopen(name1, 1);
45 printf("fsopen(\"%.*s\"..., FSOPEN_CLOEXEC) = %s\n",
46 DEFAULT_STRLEN, name1, errstr);
47
48 k_fsopen(0, 2);
49 printf("fsopen(NULL, 0x2 /* FSOPEN_??? */) = %s\n", errstr);
50
51 k_fsopen(efault, 0xfffffffe);
52 printf("fsopen(%p, 0xfffffffe /* FSOPEN_??? */) = %s\n", efault, errstr);
53
54 k_fsopen(empty, -1);
55 printf("fsopen(\"\", FSOPEN_CLOEXEC|0xfffffffe) = %s\n", errstr);
56
57 puts("+++ exited with 0 +++");
58 return 0;
59 }