Lines Matching +full:msb +full:- +full:-

1 /* SPDX-License-Identifier: GPL-2.0 */
3 * syscall_numbering.c - test calling the x86-64 kernel with various
33 /* x64-only system call numbers */
37 /* x32-only system call numbers (without X32_BIT) */
44 static int nullfd = -1; /* File descriptor for /dev/null */
64 [PTP_INTNUM] = "sign-extending the syscall number",
80 unsigned int level = sh ? sh->indent : 0; in offset()
85 #define msg(lvl, fmt, ...) printf("%-*s" fmt, offset(), "[" #lvl "]", \
95 sh->nerr++; \
100 sh->indent = 0; \
106 /* Sentinel for ptrace-modified return value */
107 #define MODIFIED_BY_PTRACE -9999
115 static long long probe_syscall(int msb, int lsb) in probe_syscall() argument
123 long long nr = ((long long)msb << 32) | (unsigned int)lsb; in probe_syscall()
133 sh->probing_syscall = true; in probe_syscall()
140 sh->probing_syscall = false; in probe_syscall()
145 static const char *syscall_str(int msb, int start, int end) in syscall_str() argument
153 * toward zero so we don't display -1 as -1073741825. in syscall_str()
162 type, msb, lsb); in syscall_str()
165 type, msb, lsb, lsb + (end-start)); in syscall_str()
170 static unsigned int _check_for(int msb, int start, int end, long long expect, in _check_for() argument
175 sh->indent++; in _check_for()
177 sh->indent++; in _check_for()
180 long long ret = probe_syscall(msb, nr); in _check_for()
184 syscall_str(msb, nr, nr), in _check_for()
191 sh->indent--; in _check_for()
196 syscall_str(msb, start, end), in _check_for()
200 syscall_str(msb, start, end), expect_str); in _check_for()
203 sh->indent--; in _check_for()
208 #define check_for(msb,start,end,expect) \ argument
209 _check_for(msb,start,end,expect,#expect)
211 static bool check_zero(int msb, int nr) in check_zero() argument
213 return check_for(msb, nr, nr, 0); in check_zero()
216 static bool check_enosys(int msb, int nr) in check_enosys() argument
218 return check_for(msb, nr, nr, -ENOSYS); in check_enosys()
234 sh->indent++; in test_x32()
238 } else if (ret == -ENOSYS) { in test_x32()
242 …fail("x32 getpid() returned %lld, but it should have returned either %lld or -ENOSYS\n", ret, (lon… in test_x32()
245 sh->indent--; in test_x32()
249 static void test_syscalls_common(int msb) in test_syscalls_common() argument
251 enum ptrace_pass pass = sh->ptrace_pass; in test_syscalls_common()
254 check_zero(msb, SYS_READ); in test_syscalls_common()
255 check_zero(msb, SYS_WRITE); in test_syscalls_common()
257 run("Checking some 64-bit only syscalls as 64 bit\n"); in test_syscalls_common()
258 check_zero(msb, X64_READV); in test_syscalls_common()
259 check_zero(msb, X64_WRITEV); in test_syscalls_common()
262 check_for(msb, -64, -2, -ENOSYS); in test_syscalls_common()
264 check_for(msb, -1, -1, MODIFIED_BY_PTRACE); in test_syscalls_common()
266 check_for(msb, -1, -1, -ENOSYS); in test_syscalls_common()
267 check_for(msb, X32_BIT-64, X32_BIT-1, -ENOSYS); in test_syscalls_common()
268 check_for(msb, -64-X32_BIT, -1-X32_BIT, -ENOSYS); in test_syscalls_common()
269 check_for(msb, INT_MAX-64, INT_MAX-1, -ENOSYS); in test_syscalls_common()
272 static void test_syscalls_with_x32(int msb) in test_syscalls_with_x32() argument
275 * Syscalls 512-547 are "x32" syscalls. They are in test_syscalls_with_x32()
281 check_for(msb, 512, 547, -ENOSYS); in test_syscalls_with_x32()
284 check_zero(msb, SYS_READ | X32_BIT); in test_syscalls_with_x32()
285 check_zero(msb, SYS_WRITE | X32_BIT); in test_syscalls_with_x32()
288 check_zero(msb, X32_READV | X32_BIT); in test_syscalls_with_x32()
289 check_zero(msb, X32_WRITEV | X32_BIT); in test_syscalls_with_x32()
291 run("Checking some 64-bit syscalls as x32\n"); in test_syscalls_with_x32()
292 check_enosys(msb, X64_IOCTL | X32_BIT); in test_syscalls_with_x32()
293 check_enosys(msb, X64_READV | X32_BIT); in test_syscalls_with_x32()
294 check_enosys(msb, X64_WRITEV | X32_BIT); in test_syscalls_with_x32()
297 static void test_syscalls_without_x32(int msb) in test_syscalls_without_x32() argument
300 check_for(msb, 0 | X32_BIT, 999 | X32_BIT, -ENOSYS); in test_syscalls_without_x32()
306 0, 1, -1, X32_BIT-1, X32_BIT, X32_BIT-1, -X32_BIT, INT_MAX, in test_syscall_numbering()
310 sh->indent++; in test_syscall_numbering()
313 * The MSB is supposed to be ignored, so we loop over a few in test_syscall_numbering()
317 int msb = msbs[i]; in test_syscall_numbering() local
318 run("Checking system calls with msb = %d (0x%x)\n", in test_syscall_numbering()
319 msb, msb); in test_syscall_numbering()
321 sh->indent++; in test_syscall_numbering()
323 test_syscalls_common(msb); in test_syscall_numbering()
325 test_syscalls_with_x32(msb); in test_syscall_numbering()
327 test_syscalls_without_x32(msb); in test_syscall_numbering()
329 sh->indent--; in test_syscall_numbering()
332 sh->indent--; in test_syscall_numbering()
345 for (sh->ptrace_pass = pass = PTP_NOTHING; pass < PTP_DONE; in syscall_numbering_tracee()
346 sh->ptrace_pass = ++pass) { in syscall_numbering_tracee()
356 sh->probing_syscall = false; /* Do this on entry only */ in mess_with_syscall()
409 if (sh->probing_syscall && WSTOPSIG(wstatus) == SIGTRAP) in syscall_numbering_tracer()
410 mess_with_syscall(testpid, sh->ptrace_pass); in syscall_numbering_tracer()
411 } while (sh->ptrace_pass != PTP_DONE && in syscall_numbering_tracer()
473 nerr = sh->nerr; in main()