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

[Minios-devel] [UNIKRAFT PATCH v2 8/9] lib/syscall_shim: introduce uk_syscallp



The macro layer is efficient, but the exact syscall must be known at
the compilation stage. If a syscall number is kept in a variable macro
layer will not be able to resolve it to the syscall function.

For this case another file is generated - syscall_entry.c. Where
syscalls are resolved at run-time into a destination functions.

Signed-off-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>
---
 lib/syscall_shim/Makefile.uk          | 10 ++++++-
 lib/syscall_shim/entry.c.in_end       | 15 ++++++++++
 lib/syscall_shim/gen_entry.awk        | 40 +++++++++++++++++++++++++++
 lib/syscall_shim/include/uk/syscall.h |  2 ++
 4 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 lib/syscall_shim/entry.c.in_end
 create mode 100644 lib/syscall_shim/gen_entry.awk

diff --git a/lib/syscall_shim/Makefile.uk b/lib/syscall_shim/Makefile.uk
index 50ee28ca..4dcb3d69 100644
--- a/lib/syscall_shim/Makefile.uk
+++ b/lib/syscall_shim/Makefile.uk
@@ -7,7 +7,8 @@ LIBSYSCALL_SHIM_PHONY_SRC := $(addprefix 
$(LIBSYSCALL_SHIM_INCLUDES_PATH)/, $(LI
 LIBSYSCALL_SHIM_PHONY_SRC += $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.h.in
 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_INCLUDES_PATH)/provided_syscalls.h \
+               $(LIBSYSCALL_SHIM_BUILD)/syscall_entry.c
 
 UK_PREPARE-$(CONFIG_LIBSYSCALL_SHIM) += $(LIBSYSCALL_SHIM_PHONY_SRC) 
$(LIBSYSCALL_SHIM_GEN_SRC)
 
@@ -37,6 +38,11 @@ $(LIBSYSCALL_SHIM_INCLUDES_PATH)/provided_syscalls.h: 
$(LIBSYSCALL_SHIM_BUILD)/p
                $(AWK) -F '-' -f  $(LIBSYSCALL_SHIM_BASE)/gen_provided.awk \
                $^ > $@)
 
+$(LIBSYSCALL_SHIM_BUILD)/syscall_entry.c: 
$(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.h.in 
$(LIBSYSCALL_SHIM_BASE)/gen_entry.awk
+       $(call build_cmd,GEN,SYSCALL_SHIM,$(notdir $@), \
+               $(AWK) -F '-' -f $(LIBSYSCALL_SHIM_BASE)/gen_entry.awk $< > $@ 
&& \
+               cat $(LIBSYSCALL_SHIM_BASE)/entry.c.in_end >> $@)
+
 $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.h.in.new:
        $(call build_cmd,GEN,SYSCALL_SHIM,$(notdir $@), \
                echo $(UK_PROVIDED_SYSCALLS-y) | tr ' ' '\n' > $@)
@@ -51,4 +57,6 @@ CXXINCLUDES-$(CONFIG_LIBSYSCALL_SHIM) += 
-I$(LIBSYSCALL_SHIM_BUILD)/include
 CINCLUDES-y   += -I$(LIBSYSCALL_SHIM_BASE)/include
 CXXINCLUDES-y += -I$(LIBSYSCALL_SHIM_BASE)/include
 
+LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BUILD)/syscall_entry.c
+
 LIBSYSCALL_SHIM_CLEAN = $(LIBSYSCALL_SHIM_PHONY_SRC) 
$(LIBSYSCALL_SHIM_PHONY_SRC_NEW) $(LIBSYSCALL_SHIM_GEN_SRC) 
$(LIBSYSCALL_SHIM_GEN_SRC)
diff --git a/lib/syscall_shim/entry.c.in_end b/lib/syscall_shim/entry.c.in_end
new file mode 100644
index 00000000..dd809e7b
--- /dev/null
+++ b/lib/syscall_shim/entry.c.in_end
@@ -0,0 +1,15 @@
+
+long uk_syscall(long n, ...)
+{
+       va_list ap;
+       syscall_arg_t a,b,c,d,e,f;
+       va_start(ap, n);
+       a=va_arg(ap, long);
+       b=va_arg(ap, long);
+       c=va_arg(ap, long);
+       d=va_arg(ap, long);
+       e=va_arg(ap, long);
+       f=va_arg(ap, long);
+       va_end(ap);
+       return __syscall_dynamic(n,a,b,c,d,e,f);
+}
diff --git a/lib/syscall_shim/gen_entry.awk b/lib/syscall_shim/gen_entry.awk
new file mode 100644
index 00000000..92457089
--- /dev/null
+++ b/lib/syscall_shim/gen_entry.awk
@@ -0,0 +1,40 @@
+BEGIN {
+       max_args = 6
+       print "/* Auto generated file. DO NOT EDIT */\n\n"
+
+       print "#include <uk/syscall.h>"
+       print "#include <uk/print.h>\n"
+
+       printf "static inline long __syscall_dynamic(long nr, "
+       for (i = 1; i < max_args; i++)
+               printf "long arg%d, ",i
+       printf "long arg%d)\n{\n", max_args
+
+       for (i = 1; i <= max_args; i++)
+               printf "\t(void) arg%d;\n", i
+
+       print "\n\tswitch (nr) {"
+}
+
+
+/[a-zA-Z0-9]+-[0-9]+/{
+       name = $1
+       sys_name = "SYS_" name
+       uk_name = "uk_syscall_" name
+       args_nr = $2 + 0
+       printf "\tcase %s:\n", sys_name;
+       printf "\t\treturn %s(", uk_name;
+       for (i = 1; i < args_nr; i++)
+               printf("arg%d, ", i)
+       if (args_nr > 0)
+               printf("arg%d", args_nr)
+       printf(");\n")
+}
+
+END {
+       printf "\tdefault:\n"
+       printf "\t\tuk_pr_debug(\"syscall nr %%ld is not implemented\", nr);\n"
+       printf "\t\terrno = -ENOSYS;\n"
+       printf "\t\treturn -1;\n"
+       printf "\t}\n}\n"
+}
diff --git a/lib/syscall_shim/include/uk/syscall.h 
b/lib/syscall_shim/include/uk/syscall.h
index 96811918..ebefa403 100644
--- a/lib/syscall_shim/include/uk/syscall.h
+++ b/lib/syscall_shim/include/uk/syscall.h
@@ -143,6 +143,8 @@ typedef long syscall_arg_t;
 #include <uk/bits/provided_syscalls.h>
 #include <uk/bits/syscall_stubs.h>
 
+long uk_syscall(long n, ...);
+
 #define syscall(...)                                                   \
        UK_CONCAT(__uk_syscall, __SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__)
 #endif
-- 
2.19.2


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

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