master
c 42 lines 1.46 KB
Raw
1 /*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 *
4 * This test attempts to execute a magic syscall. The syscall test plugin
5 * should intercept this and return an expected value.
6 */
7
8 #include <stdint.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12
13 int main(int argc, char *argv[])
14 {
15 #ifdef SKIP
16 return EXIT_SUCCESS;
17 #endif
18 /*
19 * We cannot use a very large magic syscall number, because on some ISAs,
20 * QEMU will treat it as an illegal instruction and trigger a critical
21 * exception. For instance, on arm32, the syscall number cannot exceed
22 * ARM_NR_BASE (0xf0000), as can be seen in
23 * "linux-user/arm/cpu_loop.c:cpu_loop".
24 * As well, some arch expect a minimum, like 4000 for mips 32 bits.
25 *
26 * Therefore, we pick 4096, which sits between those bounds. It is not
27 * unused everywhere though: mips 32 bits numbers from 4000, so 4096 is its
28 * getpriority. This test is unaffected because the filter also requires
29 * the first argument to be 0x66CCFF, so a real syscall carrying this
30 * number falls through untouched. This is just a test case, so replace
31 * this number as needed in the future.
32 *
33 * The corresponding syscall filter is implemented in
34 * "tests/tcg/plugins/syscall.c".
35 */
36 long ret = syscall(4096, 0x66CCFF);
37 if (ret != 0xFFCC66) {
38 fprintf(stderr, "Error: unexpected syscall return value %ld\n", ret);
39 return EXIT_FAILURE;
40 }
41 return EXIT_SUCCESS;
42 }