2 * Check decoding of utimensat 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.
37 #include <asm/unistd.h>
39 #if defined __NR_utimensat && defined UTIME_NOW && defined UTIME_OMIT
42 print_ts(const struct timespec *ts)
44 printf("{tv_sec=%lld, tv_nsec=%llu}", (long long) ts->tv_sec,
45 zero_extend_signed_to_ull(ts->tv_nsec));
46 print_time_t_nsec(ts->tv_sec,
47 zero_extend_signed_to_ull(ts->tv_nsec), 1);
50 static const char *errstr;
53 k_utimensat(const kernel_ulong_t dirfd,
54 const kernel_ulong_t pathname,
55 const kernel_ulong_t times,
56 const kernel_ulong_t flags)
58 long rc = syscall(__NR_utimensat, dirfd, pathname, times, flags);
59 errstr = sprintrc(rc);
66 static const kernel_ulong_t bogus_fd =
67 (kernel_ulong_t) 0xbadc0deddeadbeef;
68 static const kernel_ulong_t kfdcwd =
69 (kernel_ulong_t) 0xdefaced00000000 | -100U;
70 static const char proto_fname[] = "utimensat\nfilename";
71 static const char qname[] = "\"utimensat\\nfilename\"";
73 char *const fname = tail_memdup(proto_fname, sizeof(proto_fname));
74 const kernel_ulong_t kfname = (uintptr_t) fname;
75 struct timespec *const ts = tail_alloc(sizeof(*ts) * 2);
80 k_utimensat(0, kfname, 0, 0);
81 printf("utimensat(0, %s, NULL, 0) = %s\n", qname, errstr);
83 k_utimensat(bogus_fd, kfname, 0, 0);
84 printf("utimensat(%d, %s, NULL, 0) = %s\n",
85 (int) bogus_fd, qname, errstr);
87 k_utimensat(-100U, kfname, 0, 0);
88 printf("utimensat(AT_FDCWD, %s, NULL, 0) = %s\n", qname, errstr);
90 k_utimensat(kfdcwd, kfname, 0, 0);
91 printf("utimensat(AT_FDCWD, %s, NULL, 0) = %s\n", qname, errstr);
94 k_utimensat(kfdcwd, 0, 0, 0);
95 printf("utimensat(AT_FDCWD, NULL, NULL, 0) = %s\n", errstr);
97 k_utimensat(kfdcwd, kfname + sizeof(proto_fname) - 1, 0, 0);
98 printf("utimensat(AT_FDCWD, \"\", NULL, 0) = %s\n", errstr);
100 fname[sizeof(proto_fname) - 1] = '+';
101 k_utimensat(kfdcwd, kfname, 0, 0);
102 fname[sizeof(proto_fname) - 1] = '\0';
103 printf("utimensat(AT_FDCWD, %p, NULL, 0) = %s\n", fname, errstr);
105 if (F8ILL_KULONG_SUPPORTED) {
106 k_utimensat(kfdcwd, f8ill_ptr_to_kulong(fname), 0, 0);
107 printf("utimensat(AT_FDCWD, %#jx, NULL, 0) = %s\n",
108 (uintmax_t) f8ill_ptr_to_kulong(fname), errstr);
112 k_utimensat(kfdcwd, kfname, (uintptr_t) (ts + 1), 0);
113 printf("utimensat(AT_FDCWD, %s, %p, 0) = %s\n",
114 qname, ts + 1, errstr);
116 k_utimensat(kfdcwd, kfname, (uintptr_t) (ts + 2), 0);
117 printf("utimensat(AT_FDCWD, %s, %p, 0)"
118 " = %s\n", qname, ts + 2, errstr);
120 ts[0].tv_sec = 1492358706;
121 ts[0].tv_nsec = 123456789;
122 ts[1].tv_sec = 1492357068;
123 ts[1].tv_nsec = 234567890;
125 k_utimensat(kfdcwd, kfname, (uintptr_t) ts, 0x100);
126 printf("utimensat(AT_FDCWD, %s, [", qname);
130 printf("], AT_SYMLINK_NOFOLLOW) = %s\n", errstr);
133 ts[0].tv_nsec = 2000000000;
134 ts[1].tv_sec = (time_t) -0x100000001LL;
135 ts[1].tv_nsec = 2345678900U;
137 k_utimensat(kfdcwd, kfname, (uintptr_t) ts, 0x100);
138 printf("utimensat(AT_FDCWD, %s, [", qname);
142 printf("], AT_SYMLINK_NOFOLLOW) = %s\n", errstr);
146 ts[1].tv_sec = (time_t) 0xcafef00ddeadbeefLL;
149 k_utimensat(kfdcwd, kfname, (uintptr_t) ts, 0x100);
150 printf("utimensat(AT_FDCWD, %s, [", qname);
154 printf("], AT_SYMLINK_NOFOLLOW) = %s\n", errstr);
156 ts[0].tv_sec = 0xdeadbeefU;
157 ts[0].tv_nsec = 0xfacefeedU;
158 ts[1].tv_sec = (time_t) 0xcafef00ddeadbeefLL;
159 ts[1].tv_nsec = (long) 0xbadc0dedfacefeedLL;
161 k_utimensat(kfdcwd, kfname, (uintptr_t) ts, 0x100);
162 printf("utimensat(AT_FDCWD, %s, [", qname);
166 printf("], AT_SYMLINK_NOFOLLOW) = %s\n", errstr);
168 ts[0].tv_nsec = UTIME_NOW;
169 ts[1].tv_nsec = UTIME_OMIT;
170 k_utimensat(kfdcwd, kfname, (uintptr_t) ts, 0x100);
171 printf("utimensat(AT_FDCWD, %s, [UTIME_NOW, UTIME_OMIT]"
172 ", AT_SYMLINK_NOFOLLOW) = %s\n", qname, errstr);
174 if (F8ILL_KULONG_SUPPORTED) {
175 k_utimensat(kfdcwd, kfname, f8ill_ptr_to_kulong(ts), 0);
176 printf("utimensat(AT_FDCWD, %s, %#jx, 0) = %s\n",
177 qname, (uintmax_t) f8ill_ptr_to_kulong(ts), errstr);
181 k_utimensat(kfdcwd, kfname, (uintptr_t) ts,
182 (kernel_ulong_t) 0xdefaced00000200);
183 printf("utimensat(AT_FDCWD, %s, [UTIME_NOW, UTIME_OMIT]"
184 ", AT_REMOVEDIR) = %s\n",
187 k_utimensat(kfdcwd, kfname, (uintptr_t) ts,
188 (kernel_ulong_t) 0xdefaced00000600);
189 printf("utimensat(AT_FDCWD, %s, [UTIME_NOW, UTIME_OMIT]"
190 ", AT_REMOVEDIR|AT_SYMLINK_FOLLOW) = %s\n",
193 k_utimensat(kfdcwd, kfname, (uintptr_t) ts, (kernel_ulong_t) -1ULL);
194 printf("utimensat(AT_FDCWD, %s, [UTIME_NOW, UTIME_OMIT]"
195 ", AT_SYMLINK_NOFOLLOW|AT_REMOVEDIR|AT_SYMLINK_FOLLOW"
196 "|AT_NO_AUTOMOUNT|AT_EMPTY_PATH|0xffffe0ff) = %s\n",
199 puts("+++ exited with 0 +++");
205 SKIP_MAIN_UNDEFINED("__NR_utimensat && UTIME_NOW && UTIME_OMIT")