1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
/*
* Check decoding of fspick syscall.
*
* Copyright (c) 2019-2021 Dmitry V. Levin <ldv@strace.io>
* All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "tests.h"
#include "scno.h"
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
static const char *errstr;
static long
k_fspick(const unsigned int dfd,
const void *fname,
const unsigned int flags)
{
const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
const kernel_ulong_t arg1 = fill | dfd;
const kernel_ulong_t arg2 = (uintptr_t) fname;
const kernel_ulong_t arg3 = fill | flags;
const long rc = syscall(__NR_fspick, arg1, arg2, arg3, bad, bad, bad);
errstr = sprintrc(rc);
return rc;
}
int
main(void)
{
skip_if_unavailable("/proc/self/fd/");
#ifndef PATH_TRACING
char *cwd = get_fd_path(get_dir_fd("."));
#endif
static const char path_full[] = "/dev/full";
const char *const path = tail_memdup(path_full, sizeof(path_full));
char *const fname = tail_alloc(PATH_MAX);
const void *const efault = fname + PATH_MAX;
const char *const empty = efault - 1;
fill_memory_ex(fname, PATH_MAX, '0', 10);
int dfd = open(path, O_WRONLY);
if (dfd < 0)
perror_msg_and_fail("open: %s", path);
k_fspick(-1, 0, 1);
#ifndef PATH_TRACING
printf("fspick(-1, NULL, %s) = %s\n", "FSPICK_CLOEXEC", errstr);
#endif
k_fspick(-100, fname, 0);
#ifndef PATH_TRACING
printf("fspick(AT_FDCWD<%s>, \"%.*s\"..., 0) = %s\n",
cwd, (int) PATH_MAX - 1, fname, errstr);
#endif
fname[PATH_MAX - 1] = '\0';
k_fspick(dfd, fname, 0xfffffff0);
printf("fspick(%d<%s>, \"%s\", %s) = %s\n",
dfd, path, fname, "0xfffffff0 /* FSPICK_??? */", errstr);
k_fspick(-1, efault, 0xf);
#ifndef PATH_TRACING
printf("fspick(-1, %p, %s) = %s\n",
efault,
"FSPICK_CLOEXEC|FSPICK_SYMLINK_NOFOLLOW"
"|FSPICK_NO_AUTOMOUNT|FSPICK_EMPTY_PATH",
errstr);
#endif
k_fspick(-1, empty, -1);
#ifndef PATH_TRACING
printf("fspick(-1, \"\", %s|0xfffffff0) = %s\n",
"FSPICK_CLOEXEC|FSPICK_SYMLINK_NOFOLLOW"
"|FSPICK_NO_AUTOMOUNT|FSPICK_EMPTY_PATH",
errstr);
#endif
if (k_fspick(-1, path, 0) < 0)
printf("fspick(-1, \"%s\", 0) = %s\n",
path, errstr);
else
printf("fspick(-1, \"%s\", 0) = %s<%s>\n",
path, errstr, path);
if (k_fspick(dfd, empty, 8) < 0)
printf("fspick(%d<%s>, \"\", %s) = %s\n",
dfd, path, "FSPICK_EMPTY_PATH", errstr);
else
printf("fspick(%d<%s>, \"\", %s) = %s<%s>\n",
dfd, path, "FSPICK_EMPTY_PATH", errstr, path);
puts("+++ exited with 0 +++");
return 0;
}
|