2 * Check decoding of futimesat syscall.
4 * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <asm/unistd.h>
37 # include <sys/time.h>
41 print_tv(const struct timeval *tv)
43 printf("{tv_sec=%lld, tv_usec=%llu}",
44 (long long) tv->tv_sec,
45 zero_extend_signed_to_ull(tv->tv_usec));
46 print_time_t_usec(tv->tv_sec,
47 zero_extend_signed_to_ull(tv->tv_usec), 1);
50 static const char *errstr;
53 k_futimesat(const kernel_ulong_t dirfd,
54 const kernel_ulong_t pathname,
55 const kernel_ulong_t times)
57 long rc = syscall(__NR_futimesat, dirfd, pathname, times);
58 errstr = sprintrc(rc);
65 static const kernel_ulong_t bogus_fd =
66 (kernel_ulong_t) 0xbadfaceddeadbeaf;
67 static const kernel_ulong_t kfdcwd =
68 (kernel_ulong_t) 0xdefaced00000000 | -100U;
69 static const char proto_fname[] = "futimesat_sample";
70 static const char qname[] = "\"futimesat_sample\"";
72 char *const fname = tail_memdup(proto_fname, sizeof(proto_fname));
73 const kernel_ulong_t kfname = (uintptr_t) fname;
74 struct timeval *const tv = tail_alloc(sizeof(*tv) * 2);
79 k_futimesat(0, kfname, 0);
80 printf("futimesat(0, %s, NULL) = %s\n", qname, errstr);
82 k_futimesat(bogus_fd, kfname, 0);
83 printf("futimesat(%d, %s, NULL) = %s\n", (int) bogus_fd, qname, errstr);
85 k_futimesat(-100U, kfname, 0);
86 printf("futimesat(AT_FDCWD, %s, NULL) = %s\n", qname, errstr);
88 k_futimesat(kfdcwd, kfname, 0);
89 printf("futimesat(AT_FDCWD, %s, NULL) = %s\n", qname, errstr);
92 k_futimesat(kfdcwd, 0, 0);
93 printf("futimesat(AT_FDCWD, NULL, NULL) = %s\n", errstr);
95 k_futimesat(kfdcwd, kfname + sizeof(proto_fname) - 1, 0);
96 printf("futimesat(AT_FDCWD, \"\", NULL) = %s\n", errstr);
98 fname[sizeof(proto_fname) - 1] = '+';
99 k_futimesat(kfdcwd, kfname, 0);
100 fname[sizeof(proto_fname) - 1] = '\0';
101 printf("futimesat(AT_FDCWD, %p, NULL) = %s\n", fname, errstr);
103 if (F8ILL_KULONG_SUPPORTED) {
104 k_futimesat(kfdcwd, f8ill_ptr_to_kulong(fname), 0);
105 printf("futimesat(AT_FDCWD, %#jx, NULL) = %s\n",
106 (uintmax_t) f8ill_ptr_to_kulong(fname), errstr);
110 k_futimesat(kfdcwd, kfname, (uintptr_t) (tv + 1));
111 printf("futimesat(AT_FDCWD, %s, %p) = %s\n",
112 qname, tv + 1, errstr);
114 k_futimesat(kfdcwd, kfname, (uintptr_t) (tv + 2));
115 printf("futimesat(AT_FDCWD, %s, %p) = %s\n",
116 qname, tv + 2, errstr);
118 tv[0].tv_sec = 0xdeadbeefU;
119 tv[0].tv_usec = 0xfacefeedU;
120 tv[1].tv_sec = (time_t) 0xcafef00ddeadbeefLL;
121 tv[1].tv_usec = (long) 0xbadc0dedfacefeedLL;
123 k_futimesat(kfdcwd, kfname, (uintptr_t) tv);
124 printf("futimesat(AT_FDCWD, %s, [", qname);
128 printf("]) = %s\n", errstr);
130 tv[0].tv_sec = 1492356708;
131 tv[0].tv_usec = 567891234;
132 tv[1].tv_sec = 1492357086;
133 tv[1].tv_usec = 678902345;
135 k_futimesat(kfdcwd, kfname, (uintptr_t) tv);
136 printf("futimesat(AT_FDCWD, %s, [", qname);
140 printf("]) = %s\n", errstr);
142 tv[0].tv_usec = 567891;
143 tv[1].tv_usec = 678902;
145 k_futimesat(kfdcwd, kfname, (uintptr_t) tv);
146 printf("futimesat(AT_FDCWD, %s, [", qname);
150 printf("]) = %s\n", errstr);
152 if (F8ILL_KULONG_SUPPORTED) {
153 k_futimesat(kfdcwd, kfname, f8ill_ptr_to_kulong(tv));
154 printf("futimesat(AT_FDCWD, %s, %#jx) = %s\n",
155 qname, (uintmax_t) f8ill_ptr_to_kulong(tv), errstr);
158 puts("+++ exited with 0 +++");
164 SKIP_MAIN_UNDEFINED("__NR_futimesat")