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