(root)/
strace-6.5/
tests-m32/
futimesat.c
       1  /*
       2   * Check decoding of futimesat syscall.
       3   *
       4   * Copyright (c) 2015-2018 Dmitry V. Levin <ldv@strace.io>
       5   * Copyright (c) 2016-2023 The strace developers.
       6   * All rights reserved.
       7   *
       8   * SPDX-License-Identifier: GPL-2.0-or-later
       9   */
      10  
      11  #include "tests.h"
      12  #include "scno.h"
      13  #include "kernel_timeval.h"
      14  
      15  #ifdef __NR_futimesat
      16  
      17  # include <stdint.h>
      18  # include <stdio.h>
      19  # include <sys/time.h>
      20  # include <unistd.h>
      21  
      22  static void
      23  print_tv(const kernel_old_timeval_t *tv)
      24  {
      25  	printf("{tv_sec=%lld, tv_usec=%llu}",
      26  	       (long long) tv->tv_sec,
      27  	       zero_extend_signed_to_ull(tv->tv_usec));
      28  	print_time_t_usec(tv->tv_sec,
      29  			  zero_extend_signed_to_ull(tv->tv_usec), 1);
      30  }
      31  
      32  static const char *errstr;
      33  
      34  static long
      35  k_futimesat(const kernel_ulong_t dirfd,
      36  	    const kernel_ulong_t pathname,
      37  	    const kernel_ulong_t times)
      38  {
      39  	long rc = syscall(__NR_futimesat, dirfd, pathname, times);
      40  	errstr = sprintrc(rc);
      41  	return rc;
      42  }
      43  
      44  int
      45  main(void)
      46  {
      47  	static const kernel_ulong_t bogus_fd =
      48  		(kernel_ulong_t) 0xbadfaceddeadbeaf;
      49  	static const kernel_ulong_t kfdcwd =
      50  		(kernel_ulong_t) 0xdefaced00000000 | -100U;
      51  	static const char proto_fname[] = "futimesat_sample";
      52  	static const char qname[] = "\"futimesat_sample\"";
      53  
      54  	char *const fname = tail_memdup(proto_fname, sizeof(proto_fname));
      55  	const kernel_ulong_t kfname = (uintptr_t) fname;
      56  	kernel_old_timeval_t *const tv = tail_alloc(sizeof(*tv) * 2);
      57  
      58  	(void) close(0);
      59  
      60  	/* dirfd */
      61  	k_futimesat(0, kfname, 0);
      62  	printf("futimesat(0, %s, NULL) = %s\n", qname, errstr);
      63  
      64  	k_futimesat(bogus_fd, kfname, 0);
      65  	printf("futimesat(%d, %s, NULL) = %s\n", (int) bogus_fd, qname, errstr);
      66  
      67  	k_futimesat(-100U, kfname, 0);
      68  	printf("futimesat(AT_FDCWD, %s, NULL) = %s\n", qname, errstr);
      69  
      70  	k_futimesat(kfdcwd, kfname, 0);
      71  	printf("futimesat(AT_FDCWD, %s, NULL) = %s\n", qname, errstr);
      72  
      73  	/* pathname */
      74  	k_futimesat(kfdcwd, 0, 0);
      75  	printf("futimesat(AT_FDCWD, NULL, NULL) = %s\n", errstr);
      76  
      77  	k_futimesat(kfdcwd, kfname + sizeof(proto_fname) - 1, 0);
      78  	printf("futimesat(AT_FDCWD, \"\", NULL) = %s\n", errstr);
      79  
      80  	fname[sizeof(proto_fname) - 1] = '+';
      81  	k_futimesat(kfdcwd, kfname, 0);
      82  	fname[sizeof(proto_fname) - 1] = '\0';
      83  	printf("futimesat(AT_FDCWD, %p, NULL) = %s\n", fname, errstr);
      84  
      85  	if (F8ILL_KULONG_SUPPORTED) {
      86  		k_futimesat(kfdcwd, f8ill_ptr_to_kulong(fname), 0);
      87  		printf("futimesat(AT_FDCWD, %#jx, NULL) = %s\n",
      88  		       (uintmax_t) f8ill_ptr_to_kulong(fname), errstr);
      89  	}
      90  
      91  	/* times */
      92  	k_futimesat(kfdcwd, kfname, (uintptr_t) (tv + 1));
      93  	printf("futimesat(AT_FDCWD, %s, %p) = %s\n",
      94  	       qname, tv + 1, errstr);
      95  
      96  	k_futimesat(kfdcwd, kfname, (uintptr_t) (tv + 2));
      97  	printf("futimesat(AT_FDCWD, %s, %p) = %s\n",
      98  	       qname, tv + 2, errstr);
      99  
     100  	tv[0].tv_sec = 0xdeadbeefU;
     101  	tv[0].tv_usec = 0xfacefeedU;
     102  	tv[1].tv_sec = (typeof(tv[1].tv_sec)) 0xcafef00ddeadbeefLL;
     103  	tv[1].tv_usec = (suseconds_t) 0xbadc0dedfacefeedLL;
     104  
     105  	k_futimesat(kfdcwd, kfname, (uintptr_t) tv);
     106  	printf("futimesat(AT_FDCWD, %s, [", qname);
     107  	print_tv(&tv[0]);
     108  	printf(", ");
     109  	print_tv(&tv[1]);
     110  	printf("]) = %s\n", errstr);
     111  
     112  	tv[0].tv_sec = 1492356708;
     113  	tv[0].tv_usec = 567891234;
     114  	tv[1].tv_sec = 1492357086;
     115  	tv[1].tv_usec = 678902345;
     116  
     117  	k_futimesat(kfdcwd, kfname, (uintptr_t) tv);
     118  	printf("futimesat(AT_FDCWD, %s, [", qname);
     119  	print_tv(&tv[0]);
     120  	printf(", ");
     121  	print_tv(&tv[1]);
     122  	printf("]) = %s\n", errstr);
     123  
     124  	tv[0].tv_usec = 567891;
     125  	tv[1].tv_usec = 678902;
     126  
     127  	k_futimesat(kfdcwd, kfname, (uintptr_t) tv);
     128  	printf("futimesat(AT_FDCWD, %s, [", qname);
     129  	print_tv(&tv[0]);
     130  	printf(", ");
     131  	print_tv(&tv[1]);
     132  	printf("]) = %s\n", errstr);
     133  
     134  	if (F8ILL_KULONG_SUPPORTED) {
     135  		k_futimesat(kfdcwd, kfname, f8ill_ptr_to_kulong(tv));
     136  		printf("futimesat(AT_FDCWD, %s, %#jx) = %s\n",
     137  		       qname, (uintmax_t) f8ill_ptr_to_kulong(tv), errstr);
     138  	}
     139  
     140  	puts("+++ exited with 0 +++");
     141  	return 0;
     142  }
     143  
     144  #else
     145  
     146  SKIP_MAIN_UNDEFINED("__NR_futimesat")
     147  
     148  #endif