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
34 /* x64-only system call numbers */
38 /* x32-only system call numbers (without X32_BIT) */
45 static int nullfd = -1; /* File descriptor for /dev/null */
65 [PTP_INTNUM] = "sign-extending the syscall number",
81 unsigned int level = sh ? sh->indent : 0; in offset()
86 #define msg(lvl, fmt, ...) printf("%-*s" fmt, offset(), "[" #lvl "]", \
96 sh->nerr++; \
101 sh->indent = 0; \
107 /* Sentinel for ptrace-modified return value */
108 #define MODIFIED_BY_PTRACE -9999
116 static long long probe_syscall(int msb, int lsb) in probe_syscall() argument
124 long long nr = ((long long)msb << 32) | (unsigned int)lsb; in probe_syscall()
134 sh->probing_syscall = true; in probe_syscall()
141 sh->probing_syscall = false; in probe_syscall()
146 static const char *syscall_str(int msb, int start, int end) in syscall_str() argument
154 * toward zero so we don't display -1 as -1073741825. in syscall_str()
163 type, msb, lsb); in syscall_str()
166 type, msb, lsb, lsb + (end-start)); in syscall_str()
171 static unsigned int _check_for(int msb, int start, int end, long long expect, in _check_for() argument
176 sh->indent++; in _check_for()
178 sh->indent++; in _check_for()
181 long long ret = probe_syscall(msb, nr); in _check_for()
185 syscall_str(msb, nr, nr), in _check_for()
192 sh->indent--; in _check_for()
197 syscall_str(msb, start, end), in _check_for()
201 syscall_str(msb, start, end), expect_str); in _check_for()
204 sh->indent--; in _check_for()
209 #define check_for(msb,start,end,expect) \ argument
210 _check_for(msb,start,end,expect,#expect)
212 static bool check_zero(int msb, int nr) in check_zero() argument
214 return check_for(msb, nr, nr, 0); in check_zero()
217 static bool check_enosys(int msb, int nr) in check_enosys() argument
219 return check_for(msb, nr, nr, -ENOSYS); in check_enosys()
235 sh->indent++; in test_x32()
239 } else if (ret == -ENOSYS) { in test_x32()
243 …fail("x32 getpid() returned %lld, but it should have returned either %lld or -ENOSYS\n", ret, (lon… in test_x32()
246 sh->indent--; in test_x32()
250 static void test_syscalls_common(int msb) in test_syscalls_common() argument
252 enum ptrace_pass pass = sh->ptrace_pass; in test_syscalls_common()
255 check_zero(msb, SYS_READ); in test_syscalls_common()
256 check_zero(msb, SYS_WRITE); in test_syscalls_common()
258 run("Checking some 64-bit only syscalls as 64 bit\n"); in test_syscalls_common()
259 check_zero(msb, X64_READV); in test_syscalls_common()
260 check_zero(msb, X64_WRITEV); in test_syscalls_common()
263 check_for(msb, -64, -2, -ENOSYS); in test_syscalls_common()
265 check_for(msb, -1, -1, MODIFIED_BY_PTRACE); in test_syscalls_common()
267 check_for(msb, -1, -1, -ENOSYS); in test_syscalls_common()
268 check_for(msb, X32_BIT-64, X32_BIT-1, -ENOSYS); in test_syscalls_common()
269 check_for(msb, -64-X32_BIT, -1-X32_BIT, -ENOSYS); in test_syscalls_common()
270 check_for(msb, INT_MAX-64, INT_MAX-1, -ENOSYS); in test_syscalls_common()
273 static void test_syscalls_with_x32(int msb) in test_syscalls_with_x32() argument
276 * Syscalls 512-547 are "x32" syscalls. They are in test_syscalls_with_x32()
282 check_for(msb, 512, 547, -ENOSYS); in test_syscalls_with_x32()
285 check_zero(msb, SYS_READ | X32_BIT); in test_syscalls_with_x32()
286 check_zero(msb, SYS_WRITE | X32_BIT); in test_syscalls_with_x32()
289 check_zero(msb, X32_READV | X32_BIT); in test_syscalls_with_x32()
290 check_zero(msb, X32_WRITEV | X32_BIT); in test_syscalls_with_x32()
292 run("Checking some 64-bit syscalls as x32\n"); in test_syscalls_with_x32()
293 check_enosys(msb, X64_IOCTL | X32_BIT); in test_syscalls_with_x32()
294 check_enosys(msb, X64_READV | X32_BIT); in test_syscalls_with_x32()
295 check_enosys(msb, X64_WRITEV | X32_BIT); in test_syscalls_with_x32()
298 static void test_syscalls_without_x32(int msb) in test_syscalls_without_x32() argument
301 check_for(msb, 0 | X32_BIT, 999 | X32_BIT, -ENOSYS); in test_syscalls_without_x32()
307 0, 1, -1, X32_BIT-1, X32_BIT, X32_BIT-1, -X32_BIT, INT_MAX, in test_syscall_numbering()
311 sh->indent++; in test_syscall_numbering()
314 * The MSB is supposed to be ignored, so we loop over a few in test_syscall_numbering()
318 int msb = msbs[i]; in test_syscall_numbering() local
319 run("Checking system calls with msb = %d (0x%x)\n", in test_syscall_numbering()
320 msb, msb); in test_syscall_numbering()
322 sh->indent++; in test_syscall_numbering()
324 test_syscalls_common(msb); in test_syscall_numbering()
326 test_syscalls_with_x32(msb); in test_syscall_numbering()
328 test_syscalls_without_x32(msb); in test_syscall_numbering()
330 sh->indent--; in test_syscall_numbering()
333 sh->indent--; in test_syscall_numbering()
346 for (sh->ptrace_pass = pass = PTP_NOTHING; pass < PTP_DONE; in syscall_numbering_tracee()
347 sh->ptrace_pass = ++pass) { in syscall_numbering_tracee()
357 sh->probing_syscall = false; /* Do this on entry only */ in mess_with_syscall()
410 if (sh->probing_syscall && WSTOPSIG(wstatus) == SIGTRAP) in syscall_numbering_tracer()
411 mess_with_syscall(testpid, sh->ptrace_pass); in syscall_numbering_tracer()
412 } while (sh->ptrace_pass != PTP_DONE && in syscall_numbering_tracer()
474 nerr = sh->nerr; in main()