+ /*
+ * CAVEAT: We have to check carefully that this is a real 64-bit syscall.
+ * We test whether the process runs in 64-bit mode, but surprisingly this
+ * is not enough: a 64-bit process can still issue the INT 0x80 instruction
+ * which performs a 32-bit syscall. Currently, the only known way how to
+ * detect this situation is to inspect the instruction code (the kernel
+ * keeps a syscall type flag internally, but it is not accessible from
+ * user space). Hopefully, there is no instruction whose suffix is the
+ * code of the SYSCALL instruction. Sometimes, one would wish the
+ * instruction codes to be unique even when read backwards :)
+ */
+
+ if (is_exit)
+ return;
+
+ switch (a->user.regs.cs)
+ {
+ case 0x23:
+ err("FO: Forbidden 32-bit mode syscall");
+ case 0x33:
+ break;
+ default:
+ err("XX: Unknown code segment %04jx", (intmax_t) a->user.regs.cs);
+ }
+
+ uint16_t instr;
+ if (read_user_mem(a->user.regs.rip-2, (char *) &instr, 2) != 2)
+ err("FO: Cannot read syscall instruction");
+ switch (instr)
+ {
+ case 0x050f:
+ break;
+ case 0x80cd:
+ err("FO: Forbidden 32-bit syscall in 64-bit mode");
+ default:
+ err("FO: Unknown syscall instruction %04x", instr);
+ }