2 * Check decoding of futimesat syscall.
4 * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
7 * SPDX-License-Identifier: GPL-2.0-or-later
11 #include <asm/unistd.h>
17 # include <sys/time.h>
21 print_tv(const struct timeval *tv)
23 printf("{tv_sec=%lld, tv_usec=%llu}",
24 (long long) tv->tv_sec,
25 zero_extend_signed_to_ull(tv->tv_usec));
26 print_time_t_usec(tv->tv_sec,
27 zero_extend_signed_to_ull(tv->tv_usec), 1);
30 static const char *errstr;
33 k_futimesat(const kernel_ulong_t dirfd,
34 const kernel_ulong_t pathname,
35 const kernel_ulong_t times)
37 long rc = syscall(__NR_futimesat, dirfd, pathname, times);
38 errstr = sprintrc(rc);
45 static const kernel_ulong_t bogus_fd =
46 (kernel_ulong_t) 0xbadfaceddeadbeaf;
47 static const kernel_ulong_t kfdcwd =
48 (kernel_ulong_t) 0xdefaced00000000 | -100U;
49 static const char proto_fname[] = "futimesat_sample";
50 static const char qname[] = "\"futimesat_sample\"";
52 char *const fname = tail_memdup(proto_fname, sizeof(proto_fname));
53 const kernel_ulong_t kfname = (uintptr_t) fname;
54 struct timeval *const tv = tail_alloc(sizeof(*tv) * 2);
59 k_futimesat(0, kfname, 0);
60 printf("futimesat(0, %s, NULL) = %s\n", qname, errstr);
62 k_futimesat(bogus_fd, kfname, 0);
63 printf("futimesat(%d, %s, NULL) = %s\n", (int) bogus_fd, qname, errstr);
65 k_futimesat(-100U, kfname, 0);
66 printf("futimesat(AT_FDCWD, %s, NULL) = %s\n", qname, errstr);
68 k_futimesat(kfdcwd, kfname, 0);
69 printf("futimesat(AT_FDCWD, %s, NULL) = %s\n", qname, errstr);
72 k_futimesat(kfdcwd, 0, 0);
73 printf("futimesat(AT_FDCWD, NULL, NULL) = %s\n", errstr);
75 k_futimesat(kfdcwd, kfname + sizeof(proto_fname) - 1, 0);
76 printf("futimesat(AT_FDCWD, \"\", NULL) = %s\n", errstr);
78 fname[sizeof(proto_fname) - 1] = '+';
79 k_futimesat(kfdcwd, kfname, 0);
80 fname[sizeof(proto_fname) - 1] = '\0';
81 printf("futimesat(AT_FDCWD, %p, NULL) = %s\n", fname, errstr);
83 if (F8ILL_KULONG_SUPPORTED) {
84 k_futimesat(kfdcwd, f8ill_ptr_to_kulong(fname), 0);
85 printf("futimesat(AT_FDCWD, %#jx, NULL) = %s\n",
86 (uintmax_t) f8ill_ptr_to_kulong(fname), errstr);
90 k_futimesat(kfdcwd, kfname, (uintptr_t) (tv + 1));
91 printf("futimesat(AT_FDCWD, %s, %p) = %s\n",
92 qname, tv + 1, errstr);
94 k_futimesat(kfdcwd, kfname, (uintptr_t) (tv + 2));
95 printf("futimesat(AT_FDCWD, %s, %p) = %s\n",
96 qname, tv + 2, errstr);
98 tv[0].tv_sec = 0xdeadbeefU;
99 tv[0].tv_usec = 0xfacefeedU;
100 tv[1].tv_sec = (time_t) 0xcafef00ddeadbeefLL;
101 tv[1].tv_usec = (suseconds_t) 0xbadc0dedfacefeedLL;
103 k_futimesat(kfdcwd, kfname, (uintptr_t) tv);
104 printf("futimesat(AT_FDCWD, %s, [", qname);
108 printf("]) = %s\n", errstr);
110 tv[0].tv_sec = 1492356708;
111 tv[0].tv_usec = 567891234;
112 tv[1].tv_sec = 1492357086;
113 tv[1].tv_usec = 678902345;
115 k_futimesat(kfdcwd, kfname, (uintptr_t) tv);
116 printf("futimesat(AT_FDCWD, %s, [", qname);
120 printf("]) = %s\n", errstr);
122 tv[0].tv_usec = 567891;
123 tv[1].tv_usec = 678902;
125 k_futimesat(kfdcwd, kfname, (uintptr_t) tv);
126 printf("futimesat(AT_FDCWD, %s, [", qname);
130 printf("]) = %s\n", errstr);
132 if (F8ILL_KULONG_SUPPORTED) {
133 k_futimesat(kfdcwd, kfname, f8ill_ptr_to_kulong(tv));
134 printf("futimesat(AT_FDCWD, %s, %#jx) = %s\n",
135 qname, (uintmax_t) f8ill_ptr_to_kulong(tv), errstr);
138 puts("+++ exited with 0 +++");
144 SKIP_MAIN_UNDEFINED("__NR_futimesat")