[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[UNIKRAFT PATCH 1/3] lib/syscall_shim: Provide `uk_syscall_r_fn()`



`uk_syscall_r_fn()` returns a the raw system call handler as function
pointer for a given system call.

Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
---
 lib/syscall_shim/Makefile.uk             |  7 +++++++
 lib/syscall_shim/gen_uk_syscall_r_fn.awk | 24 ++++++++++++++++++++++++
 lib/syscall_shim/include/uk/syscall.h    | 12 ++++++++++++
 3 files changed, 43 insertions(+)
 create mode 100644 lib/syscall_shim/gen_uk_syscall_r_fn.awk

diff --git a/lib/syscall_shim/Makefile.uk b/lib/syscall_shim/Makefile.uk
index d3bfe4f8..ad4c8188 100644
--- a/lib/syscall_shim/Makefile.uk
+++ b/lib/syscall_shim/Makefile.uk
@@ -10,6 +10,7 @@ LIBSYSCALL_SHIM_PHONY_SRC_NEW := $(addsuffix .new, 
$(LIBSYSCALL_SHIM_PHONY_SRC))
 LIBSYSCALL_SHIM_GEN_SRC := $(LIBSYSCALL_SHIM_INCLUDES_PATH)/provided_syscalls.h
 LIBSYSCALL_SHIM_GEN_SRC += $(LIBSYSCALL_SHIM_BUILD)/uk_syscall.c
 LIBSYSCALL_SHIM_GEN_SRC += $(LIBSYSCALL_SHIM_BUILD)/uk_syscall_r.c
+LIBSYSCALL_SHIM_GEN_SRC += $(LIBSYSCALL_SHIM_BUILD)/uk_syscall_r_fn.c
 LIBSYSCALL_SHIM_GEN_SRC += $(LIBSYSCALL_SHIM_BUILD)/uk_syscall_name.c
 LIBSYSCALL_SHIM_GEN_SRC += $(LIBSYSCALL_SHIM_BUILD)/uk_syscall_name_p.c
 LIBSYSCALL_SHIM_GEN_SRC += $(LIBSYSCALL_SHIM_BUILD)/libc_stubs.c
@@ -57,6 +58,10 @@ $(LIBSYSCALL_SHIM_BUILD)/uk_syscall_r.c: 
$(LIBSYSCALL_SHIM_BUILD)/provided_sysca
                $(AWK) -F '-' -f $(LIBSYSCALL_SHIM_BASE)/gen_uk_syscall_r.awk 
$< > $@ && \
                cat $(LIBSYSCALL_SHIM_BASE)/uk_syscall_r.c.in_end >> $@)
 
+$(LIBSYSCALL_SHIM_BUILD)/uk_syscall_r_fn.c: 
$(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.h.in 
$(LIBSYSCALL_SHIM_BASE)/gen_uk_syscall_r_fn.awk
+       $(call build_cmd,GEN,libsyscall_shim,$(notdir $@), \
+               $(AWK) -F '-' -f 
$(LIBSYSCALL_SHIM_BASE)/gen_uk_syscall_r_fn.awk $< > $@)
+
 $(LIBSYSCALL_SHIM_BUILD)/uk_syscall_name.c: 
$(LIBSYSCALL_SHIM_BASE)/gen_uk_syscall_name.awk $(LIBSYSCALL_SHIM_TEMPL)
        $(call build_cmd,GEN,libsyscall_shim,$(notdir $@), \
                $(AWK) -f $(LIBSYSCALL_SHIM_BASE)/gen_uk_syscall_name.awk \
@@ -89,6 +94,8 @@ LIBSYSCALL_SHIM_CINCLUDES += -I$(LIBSYSCALL_SHIM_BASE)
 
 LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BUILD)/uk_syscall.c
 LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BUILD)/uk_syscall_r.c
+LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BUILD)/uk_syscall_r_fn.c
+LIBSYSCALL_SHIM_UK_SYSCALL_R_FN_FLAGS+=-Wno-cast-function-type
 LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BUILD)/uk_syscall_name.c
 LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BUILD)/uk_syscall_name_p.c
 LIBSYSCALL_SHIM_SRCS-$(CONFIG_LIBSYSCALL_SHIM_LIBCSTUBS) += 
$(LIBSYSCALL_SHIM_BUILD)/libc_stubs.c
diff --git a/lib/syscall_shim/gen_uk_syscall_r_fn.awk 
b/lib/syscall_shim/gen_uk_syscall_r_fn.awk
new file mode 100644
index 00000000..767b902d
--- /dev/null
+++ b/lib/syscall_shim/gen_uk_syscall_r_fn.awk
@@ -0,0 +1,24 @@
+BEGIN {
+       print "/* Auto generated file. DO NOT EDIT */\n"
+
+       print "#include <uk/syscall.h>"
+       print "#include <uk/print.h>"
+       print "#include <stdlib.h>\n"
+
+       print "long (*uk_syscall_r_fn(long nr))(void)\n{"
+       print "\tswitch (nr) {"
+}
+
+/[a-zA-Z0-9]+-[0-9]+/{
+       name = $1
+       sys_name = "SYS_" name
+       uk_syscall_r = "uk_syscall_r_" name
+       printf "\tcase %s:\n", sys_name;
+       printf "\t\treturn (long (*)(void)) %s;\n", uk_syscall_r;
+}
+
+END {
+       print "\tdefault:"
+       print "\t\treturn NULL;"
+       print "\t}\n}"
+}
diff --git a/lib/syscall_shim/include/uk/syscall.h 
b/lib/syscall_shim/include/uk/syscall.h
index dc7bc7ef..078129e5 100644
--- a/lib/syscall_shim/include/uk/syscall.h
+++ b/lib/syscall_shim/include/uk/syscall.h
@@ -337,6 +337,18 @@ const char *uk_syscall_name(long nr);
  */
 const char *uk_syscall_name_p(long nr);
 
+/**
+ * Returns the according raw system call handler as function pointer for the
+ * given system call number. If the system call handler is not available,
+ * NULL is returned.
+ * @param nr
+ *  System call number of current architecture
+ * @return
+ *  - Function pointer to raw system call handler
+ *  - (NULL): if system call handler is not provided
+ */
+long (*uk_syscall_r_fn(long nr))(void);
+
 #endif /* CONFIG_LIBSYSCALL_SHIM */
 
 #endif /* __UK_SYSCALL_H__ */
-- 
2.20.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.