1 /* Test that all instructions that make syscalls are handled correctly.
2 Note that it isn't possible to run this program natively. */
3
4 #include <stdio.h>
5 #include <sys/syscall.h>
6 #include <sys/trap.h>
7
8 #define SYSCALL(instr, scnum, out) \
9 do { \
10 __asm__ __volatile__( \
11 "movl %1,%%eax\n" \
12 "leal 0f,%%edx\n" /* Set return address for SYSENTER. */ \
13 instr "\n" \
14 "0:\n" \
15 "movl %%eax,%0\n" \
16 : "=m" (out) \
17 : "i" (scnum) \
18 : "eax", "edx", "cc", "memory"); \
19 } while (0)
20
check_pid(int pid,int pid2,const char * instr)21 static void check_pid(int pid, int pid2, const char *instr)
22 {
23 if (pid == pid2)
24 return;
25
26 fprintf(stderr, "Pid values differ, instruction: %s\n", instr);
27 }
28
main(void)29 int main(void)
30 {
31 int pid, pid2, dummy;
32
33 /* Normal Solaris/x86 syscall instructions. */
34 SYSCALL("int $0x91", SYS_getpid, pid);
35
36 /* AMD's syscall instruction. */
37 SYSCALL("syscall", SYS_getpid, pid2);
38 check_pid(pid, pid2, "syscall");
39
40 /* Intel's sysenter instruction. */
41 SYSCALL("sysenter", SYS_getpid, pid2);
42 check_pid(pid, pid2, "sysenter");
43
44 /* Linux syscall instructions that are handled as "int $0x91". */
45 SYSCALL("int $0x80", SYS_getpid, pid2);
46 check_pid(pid, pid2, "int $0x80");
47
48 SYSCALL("int $0x81", SYS_getpid, pid2);
49 check_pid(pid, pid2, "int $0x81");
50
51 SYSCALL("int $0x82", SYS_getpid, pid2);
52 check_pid(pid, pid2, "int $0x82");
53
54 /* Fasttraps. */
55 SYSCALL("int $0xd2", T_GETHRTIME, dummy);
56
57 return 0;
58 }
59
60