Переглянути джерело

[LibOS/regression] Add test for syscall instruction redirection

Add LibOS regression test which contains a raw syscall instruction to test
SIGILL handler hook logic (if SIGILL'ed instruction is a syscall, it is
redirected inside LibOS as if syscalldb() was called).
Isaku Yamahata 5 роки тому
батько
коміт
bdb8b9c36b

+ 20 - 0
LibOS/shim/test/regression/30_syscall-redirect.py

@@ -0,0 +1,20 @@
+import os, sys, mmap
+from regression import Regression
+
+loader = sys.argv[1]
+sgx = os.environ.get('SGX_RUN') == '1'
+
+# This test is only meaningful on SGX PAL because only SGX catches raw syscalls
+# and redirects to Graphene's LibOS. If we will add seccomp to Linux PAL, then
+# we should allow this test on Linux PAL as well.
+if not sgx:
+    sys.exit(0)
+
+# Running Syscall Instruction Example
+regression = Regression(loader, "syscall")
+
+regression.add_check(name="Syscall Instruction Redirection",
+    check=lambda res: "Hello world" in res[0].out)
+
+rv = regression.run_checks()
+if rv: sys.exit(rv)

+ 3 - 0
LibOS/shim/test/regression/Makefile

@@ -41,6 +41,9 @@ shared_object: %: %.c
 	@echo [ $@ ]
 	@$(CC) $(CFLAGS) -o $@ -fPIC -pie $< \
 	$(shell echo $@ | sed 's/^[^\.]*//g' | sed 's/\./ -l/g')
+
+syscall: CFLAGS += -I$(PALDIR)/../include -I$(PALDIR)/host/$(PAL_HOST)
+
 else
 .IGNORE: $(special_executables) $(c_executables) $(cxx_executables)
 $(special_executables) $(c_executables) $(cxx_executables):

+ 8 - 0
LibOS/shim/test/regression/syscall.c

@@ -0,0 +1,8 @@
+#include <sys/syscall.h>
+#include <sysdep-x86_64.h>
+
+int main(int argc, char** argv) {
+    const char buf[] = "Hello world\n";
+    INLINE_SYSCALL(write, 3, 1, buf, sizeof(buf) - 1);
+    return 0;
+}