From: Simon Kuenzer Date: Thu, 30 Mar 2023 16:32:03 +0000 (+0200) Subject: lib/syscall_shim: Utilize `SUBBUILD` feature within `Makefile.uk` X-Git-Tag: RELEASE-0.14.0~198 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=23fe2fb999a59ffb8596e1a42bd0ecd65773ff1e;p=unikraft%2Funikraft.git lib/syscall_shim: Utilize `SUBBUILD` feature within `Makefile.uk` This commit utilizes the recently added `SUBBUILD` feature of the build system to natively generate all dynamic headers of the library. This has several reasons: 1) The `Makefile.uk` of `syscall_shim` becomes more readable 2) No custom rule for creating the subdirectory structure is needed 3) No custom `awk`-rules are needed for generating the headers 4) The build system can take care of handling build order dependencies Signed-off-by: Simon Kuenzer Reviewed-by: Michalis Pappas Reviewed-by: Robert Kuban Approved-by: Razvan Deaconescu Tested-by: Unikraft CI GitHub-Closes: #938 --- diff --git a/lib/syscall_shim/Makefile.uk b/lib/syscall_shim/Makefile.uk index a93fae5dc..9df6cb2cf 100644 --- a/lib/syscall_shim/Makefile.uk +++ b/lib/syscall_shim/Makefile.uk @@ -1,106 +1,88 @@ $(eval $(call addlib_s,libsyscall_shim,$(CONFIG_LIBSYSCALL_SHIM))) -LIBSYSCALL_SHIM_CFLAGS-$(CONFIG_LIBSYSCALL_SHIM_DEBUG) += -DUK_DEBUG +CINCLUDES-$(CONFIG_LIBSYSCALL_SHIM) += -I$(LIBSYSCALL_SHIM_BUILD)/include +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_INCLUDES_PATH := $(LIBSYSCALL_SHIM_BUILD)/include/uk/bits - -LIBSYSCALL_SHIM_PHONY_SRC := syscall_map.h syscall_stubs.h syscall_nrs.h syscall_nrs2.h -LIBSYSCALL_SHIM_PHONY_SRC := $(addprefix $(LIBSYSCALL_SHIM_INCLUDES_PATH)/, $(LIBSYSCALL_SHIM_PHONY_SRC)) -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)/syscall_static.h -LIBSYSCALL_SHIM_GEN_SRC += $(LIBSYSCALL_SHIM_INCLUDES_PATH)/syscall_r_static.h - -UK_PREPARE-$(CONFIG_LIBSYSCALL_SHIM) += $(LIBSYSCALL_SHIM_PHONY_SRC) $(LIBSYSCALL_SHIM_GEN_SRC) - -LIBSYSCALL_SHIM_TEMPL := $(LIBSYSCALL_SHIM_BASE)/arch/$(CONFIG_UK_ARCH)/syscall.h.in - -$(if $(shell mkdir -p $(LIBSYSCALL_SHIM_INCLUDES_PATH) && \ - cd $(LIBSYSCALL_SHIM_INCLUDES_PATH) >/dev/null && pwd),,\ - $(error could not create directory $1)) - -.PHONY: $(LIBSYSCALL_SHIM_PHONY_SRC_NEW) - -$(LIBSYSCALL_SHIM_PHONY_SRC): %: %.new - @cmp -s $^ $@; if [ $$? -ne 0 ]; then cp $^ $@; fi - -$(LIBSYSCALL_SHIM_INCLUDES_PATH)/syscall_nrs.h.new: $(LIBSYSCALL_SHIM_BASE)/gen_syscall_nrs.awk $(LIBSYSCALL_SHIM_TEMPL) - $(call build_cmd,GEN,libsyscall_shim,$(notdir $@), \ - $(AWK) -f $(LIBSYSCALL_SHIM_BASE)/gen_syscall_nrs.awk \ - $(LIBSYSCALL_SHIM_TEMPL) > $@) - -$(LIBSYSCALL_SHIM_INCLUDES_PATH)/syscall_nrs2.h.new: $(LIBSYSCALL_SHIM_BASE)/gen_syscall_nrs2.awk $(LIBSYSCALL_SHIM_TEMPL) - $(call build_cmd,GEN,libsyscall_shim,$(notdir $@), \ - $(AWK) -f $(LIBSYSCALL_SHIM_BASE)/gen_syscall_nrs2.awk \ - $(LIBSYSCALL_SHIM_TEMPL) > $@) - -$(LIBSYSCALL_SHIM_INCLUDES_PATH)/syscall_map.h.new: $(LIBSYSCALL_SHIM_BASE)/gen_syscall_map.awk $(LIBSYSCALL_SHIM_TEMPL) - $(call build_cmd,GEN,libsyscall_shim,$(notdir $@), \ - $(AWK) -f $(LIBSYSCALL_SHIM_BASE)/gen_syscall_map.awk \ - $(LIBSYSCALL_SHIM_TEMPL) > $@) - -$(LIBSYSCALL_SHIM_INCLUDES_PATH)/provided_syscalls.h: $(LIBSYSCALL_SHIM_BASE)/gen_provided.awk $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.h.in - $(call build_cmd,GEN,libsyscall_shim,$(notdir $@), \ - $(AWK) -F '-' -f $(LIBSYSCALL_SHIM_BASE)/gen_provided.awk \ - $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.h.in > $@) +LIBSYSCALL_SHIM_CINCLUDES += -I$(LIBSYSCALL_SHIM_BASE) +LIBSYSCALL_SHIM_COMPFLAGS-$(CONFIG_LIBSYSCALL_SHIM_DEBUG) += -DUK_DEBUG -$(LIBSYSCALL_SHIM_INCLUDES_PATH)/syscall_static.h: $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.h.in $(LIBSYSCALL_SHIM_BASE)/gen_syscall_static.awk - $(call build_cmd,GEN,libsyscall_shim,$(notdir $@), \ - $(AWK) -F '-' -f $(LIBSYSCALL_SHIM_BASE)/gen_syscall_static.awk $< > $@) +LIBSYSCALL_SHIM_INCLUDES_SUBBUILD := include/uk/bits +LIBSYSCALL_SHIM_ARCH_TEMPLATE := $(LIBSYSCALL_SHIM_BASE)/arch/$(CONFIG_UK_ARCH)/syscall.h.in -$(LIBSYSCALL_SHIM_INCLUDES_PATH)/syscall_r_static.h: $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.h.in $(LIBSYSCALL_SHIM_BASE)/gen_syscall_r_static.awk - $(call build_cmd,GEN,libsyscall_shim,$(notdir $@), \ - $(AWK) -F '-' -f $(LIBSYSCALL_SHIM_BASE)/gen_syscall_r_static.awk $< > $@) +################################################################################ +# Generate provided_syscalls.in from `UK_PROVIDED_SYSCALLS` variable +################################################################################ -$(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.h.in.new: +$(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.in.new: $(call build_cmd,GEN,libsyscall_shim,$(notdir $@), \ echo $(UK_PROVIDED_SYSCALLS-y) $(UK_PROVIDED_SYSCALLS) | tr ' ' '\n' > $@) -$(LIBSYSCALL_SHIM_INCLUDES_PATH)/syscall_stubs.h.new: $(LIBSYSCALL_SHIM_BASE)/gen_stubs.awk $(LIBSYSCALL_SHIM_TEMPL) - $(call build_cmd,GEN,libsyscall_shim,$(notdir $@), \ - $(AWK) -f $(LIBSYSCALL_SHIM_BASE)/gen_stubs.awk \ - $(LIBSYSCALL_SHIM_TEMPL) > $@) - -CINCLUDES-$(CONFIG_LIBSYSCALL_SHIM) += -I$(LIBSYSCALL_SHIM_BUILD)/include -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_CINCLUDES += -I$(LIBSYSCALL_SHIM_BASE) -LIBSYSCALL_SHIM_COMPFLAGS-$(CONFIG_LIBSYSCALL_SHIM_DEBUG) += -DUK_DEBUG +# Enforce re-creation of provided_syscalls.in.new +.PHONY: $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.in.new + +# Update only if we have changes in provided_syscalls.in.new +$(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.in: $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.in.new + $(call build_cmd,CP,libsyscall_shim,$(notdir $@), \ + cmp -s $^ $@; if [ $$? -ne 0 ]; then cp $^ $@; fi) + +LIBSYSCALL_SHIM_CLEAN += $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.in.new +LIBSYSCALL_SHIM_CLEAN += $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.in +################################################################################ + +LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BASE)/syscall_provided.awk>.h +LIBSYSCALL_SHIM_SYSCALL_PROVIDED_SUBBUILD = $(LIBSYSCALL_SHIM_INCLUDES_SUBBUILD) +LIBSYSCALL_SHIM_SYSCALL_PROVIDED_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.in +LIBSYSCALL_SHIM_SYSCALL_PROVIDED_AWKFLAGS-y += -F '-' +LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BASE)/syscall_static.awk>.h +LIBSYSCALL_SHIM_SYSCALL_STATIC_SUBBUILD = $(LIBSYSCALL_SHIM_INCLUDES_SUBBUILD) +LIBSYSCALL_SHIM_SYSCALL_STATIC_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.in +LIBSYSCALL_SHIM_SYSCALL_STATIC_AWKFLAGS-y += -F '-' +LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BASE)/syscall_r_static.awk>.h +LIBSYSCALL_SHIM_SYSCALL_R_STATIC_SUBBUILD = $(LIBSYSCALL_SHIM_INCLUDES_SUBBUILD) +LIBSYSCALL_SHIM_SYSCALL_R_STATIC_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.in +LIBSYSCALL_SHIM_SYSCALL_R_STATIC_AWKFLAGS-y += -F '-' + +LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BASE)/syscall_nrs.awk>.h +LIBSYSCALL_SHIM_SYSCALL_NRS_SUBBUILD = $(LIBSYSCALL_SHIM_INCLUDES_SUBBUILD) +LIBSYSCALL_SHIM_SYSCALL_NRS_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_ARCH_TEMPLATE) +LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BASE)/syscall_nrs2.awk>.h +LIBSYSCALL_SHIM_SYSCALL_NRS2_SUBBUILD = $(LIBSYSCALL_SHIM_INCLUDES_SUBBUILD) +LIBSYSCALL_SHIM_SYSCALL_NRS2_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_ARCH_TEMPLATE) +LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BASE)/syscall_map.awk>.h +LIBSYSCALL_SHIM_SYSCALL_MAP_SUBBUILD = $(LIBSYSCALL_SHIM_INCLUDES_SUBBUILD) +LIBSYSCALL_SHIM_SYSCALL_MAP_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_ARCH_TEMPLATE) +LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BASE)/syscall_stubs.awk>.h +LIBSYSCALL_SHIM_SYSCALL_STUBS_SUBBUILD = $(LIBSYSCALL_SHIM_INCLUDES_SUBBUILD) +LIBSYSCALL_SHIM_SYSCALL_STUBS_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_ARCH_TEMPLATE) LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BASE)/uk_syscall.awk>.c -LIBSYSCALL_SHIM_UK_SYSCALL_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.h.in +LIBSYSCALL_SHIM_UK_SYSCALL_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.in LIBSYSCALL_SHIM_UK_SYSCALL_AWKFLAGS-y += -F '-' LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BASE)/uk_syscall_r.awk>.c -LIBSYSCALL_SHIM_UK_SYSCALL_R_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.h.in +LIBSYSCALL_SHIM_UK_SYSCALL_R_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.in LIBSYSCALL_SHIM_UK_SYSCALL_R_AWKFLAGS-y += -F '-' - LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BASE)/uk_syscall6.awk>.c -LIBSYSCALL_SHIM_UK_SYSCALL6_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.h.in +LIBSYSCALL_SHIM_UK_SYSCALL6_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.in LIBSYSCALL_SHIM_UK_SYSCALL6_AWKFLAGS-y += -F '-' LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BASE)/uk_syscall6_r.awk>.c -LIBSYSCALL_SHIM_UK_SYSCALL6_R_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.h.in +LIBSYSCALL_SHIM_UK_SYSCALL6_R_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.in LIBSYSCALL_SHIM_UK_SYSCALL6_R_AWKFLAGS-y += -F '-' - LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BASE)/uk_syscall_r_fn.awk>.c -LIBSYSCALL_SHIM_UK_SYSCALL_R_FN_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.h.in +LIBSYSCALL_SHIM_UK_SYSCALL_R_FN_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.in LIBSYSCALL_SHIM_UK_SYSCALL_R_FN_AWKFLAGS-y += -F '-' -LIBSYSCALL_SHIM_UK_SYSCALL_R_FN_FLAGS-$(call gcc_version_ge,8,0) = -Wno-cast-function-type +LIBSYSCALL_SHIM_UK_SYSCALL_R_FN_FLAGS-$(call gcc_version_ge,8,0) += -Wno-cast-function-type LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BASE)/uk_syscall_name.awk>.c -LIBSYSCALL_SHIM_UK_SYSCALL_NAME_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_TEMPL) +LIBSYSCALL_SHIM_UK_SYSCALL_NAME_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_ARCH_TEMPLATE) LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BASE)/uk_syscall_name_p.awk>.c -LIBSYSCALL_SHIM_UK_SYSCALL_NAME_P_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_TEMPL) - +LIBSYSCALL_SHIM_UK_SYSCALL_NAME_P_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_ARCH_TEMPLATE) LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BASE)/libc_stubs.awk>.c -LIBSYSCALL_SHIM_LIBC_STUBS_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_TEMPL) +LIBSYSCALL_SHIM_LIBC_STUBS_AWKINCLUDES-y += $(LIBSYSCALL_SHIM_ARCH_TEMPLATE) LIBSYSCALL_SHIM_LIBC_STUBS_FLAGS += -fno-builtin LIBSYSCALL_SHIM_LIBC_STUBS_FLAGS-$(call have_gcc) += -Wno-builtin-declaration-mismatch LIBSYSCALL_SHIM_SRCS-$(CONFIG_LIBSYSCALL_SHIM_HANDLER) += $(LIBSYSCALL_SHIM_BASE)/uk_syscall_binary.c|isr + LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BASE)/uk_prsyscall.c LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BASE)/vars.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/gen_provided.awk b/lib/syscall_shim/gen_provided.awk deleted file mode 100644 index d10342467..000000000 --- a/lib/syscall_shim/gen_provided.awk +++ /dev/null @@ -1,31 +0,0 @@ -BEGIN { - print "/* Automatically generated file; DO NOT EDIT */" - print "#ifndef __LIBSYSCALL_SHIM_PROVIDED_SYSCALLS_H__" - print "#define __LIBSYSCALL_SHIM_PROVIDED_SYSCALLS_H__" - print "\n#include " -} - -/[a-zA-Z0-9]+-[0-9]+/{ - # check if the syscall is not defined - printf "\n#ifndef SYS_%s\n", $1; - # if a LEGACY_ symbol is defined, the syscall is not required - # and we can continue the build process - printf "#ifdef LEGACY_SYS_%s\n", $1; - printf "#ifdef CONFIG_LIBSYSCALL_SHIM_LEGACY_VERBOSE\n" - printf "#warning Ignoring legacy system call '%s': No system call number available\n", $1 - printf "#endif /* LIBSYSCALL_SHIM_LEGACY_VERBOSE */\n" - # if the LEGACY symbol is not defined for this syscall, it means that the - # syscall is required and we can't continue without a definition - printf "#else\n"; - printf "#error Failed to map system call '%s': No system call number available\n", $1 - printf "#endif /* LEGACY_SYS_%s */\n", $1 - printf "#else\n"; - printf "#define HAVE_uk_syscall_%s t\n", $1; - printf "UK_SYSCALL_E_PROTO(%s, %s);\n", $2, $1; - printf "UK_SYSCALL_R_PROTO(%s, %s);\n", $2, $1; - printf "#endif /* !SYS_%s */\n", $1; -} - -END { - print "\n#endif /* __LIBSYSCALL_SHIM_PROVIDED_SYSCALLS_H__ */" -} diff --git a/lib/syscall_shim/gen_stubs.awk b/lib/syscall_shim/gen_stubs.awk deleted file mode 100644 index a93712656..000000000 --- a/lib/syscall_shim/gen_stubs.awk +++ /dev/null @@ -1,8 +0,0 @@ -BEGIN { print "/* Auto generated file. Do not edit */" } -/#define __NR_/ { - name = substr($2,6); - printf "\n#ifndef HAVE_uk_syscall_%s", name; - printf "\n#define uk_syscall_e_%s(...) uk_syscall_e_stub(\"%s\")", name, name; - printf "\n#define uk_syscall_r_%s(...) uk_syscall_r_stub(\"%s\")", name, name; - printf "\n#endif /* !HAVE_uk_syscall_%s */\n", name; -} diff --git a/lib/syscall_shim/gen_syscall_map.awk b/lib/syscall_shim/gen_syscall_map.awk deleted file mode 100644 index 5d2c3a0f1..000000000 --- a/lib/syscall_shim/gen_syscall_map.awk +++ /dev/null @@ -1,78 +0,0 @@ -BEGIN { - max_args = 6 - print "/* Automatically generated file; DO NOT EDIT */\n" - print "#include \n" - print "#define _uk_syscall_e_enosys() \\" - print "\t({ errno = ENOSYS; (-1); })" - print "#define _uk_syscall_r_enosys() \\" - print "\t({ (-ENOSYS); })" -} -/#define __NR_/{ - printf "\n" - printf "#ifdef HAVE_uk_syscall_%s\n", substr($2,6); - printf "#define uk_syscall_fn%d(...) \\\n\tuk_syscall_e_%s(__VA_ARGS__)\n", $3, substr($2,6) - for (i = 0; i <= max_args; i++) - { - printf "#define uk_syscall%d_fn%d(", i, $3 - for (j = 1; j <= i; j++) - { - if (j > 1) - printf ", "; - printf "arg%d", j; - } - printf ") \\\n\tuk_syscall_e%d_%s(", i, substr($2,6) - for (j = 1; j <= i; j++) - { - if (j > 1) - printf ", "; - printf "arg%d", j; - } - printf ")\n"; - } - printf "#define uk_syscall_r_fn%d(...) \\\n\tuk_syscall_r_%s(__VA_ARGS__)\n", $3, substr($2,6) - for (i = 0; i <= max_args; i++) - { - printf "#define uk_syscall_r%d_fn%d(", i, $3 - for (j = 1; j <= i; j++) - { - if (j > 1) - printf ", "; - printf "arg%d", j; - } - printf ") \\\n\tuk_syscall_r%d_%s(", i, substr($2,6) - for (j = 1; j <= i; j++) - { - if (j > 1) - printf ", "; - printf "arg%d", j; - } - printf ")\n"; - } - printf "#else /* !HAVE_uk_syscall_%s */\n", substr($2,6); - - printf "#define uk_syscall_fn%d(...) _uk_syscall_e_enosys()\n", $3 - for (i = 0; i <= max_args; i++) - { - printf "#define uk_syscall%d_fn%d(", i, $3 - for (j = 1; j <= i; j++) - { - if (j > 1) - printf ", "; - printf "arg%d", j; - } - printf ") _uk_syscall_e_enosys()\n"; - } - printf "#define uk_syscall_r_fn%d(...) _uk_syscall_r_enosys()\n", $3 - for (i = 0; i <= max_args; i++) - { - printf "#define uk_syscall_r%d_fn%d(", i, $3 - for (j = 1; j <= i; j++) - { - if (j > 1) - printf ", "; - printf "arg%d", j; - } - printf ") _uk_syscall_r_enosys()\n"; - } - printf "#endif /* !HAVE_uk_syscall_%s */\n", substr($2,6); -} diff --git a/lib/syscall_shim/gen_syscall_nrs.awk b/lib/syscall_shim/gen_syscall_nrs.awk deleted file mode 100644 index 46a78053b..000000000 --- a/lib/syscall_shim/gen_syscall_nrs.awk +++ /dev/null @@ -1,13 +0,0 @@ -BEGIN { - print "/* Automatically generated file; DO NOT EDIT */" - print "#ifndef __LIBSYSCALL_SHIM_SYSCALL_NRS_H__" - print "#define __LIBSYSCALL_SHIM_SYSCALL_NRS_H__" -} - -/#define __NR_/{ - printf "\n#define SYS_%s\t\t%s", substr($2,6),$3 -} - -END { - print "\n\n#endif /* __LIBSYSCALL_SHIM_SYSCALL_NRS_H__ */" -} diff --git a/lib/syscall_shim/gen_syscall_nrs2.awk b/lib/syscall_shim/gen_syscall_nrs2.awk deleted file mode 100644 index a70897a8d..000000000 --- a/lib/syscall_shim/gen_syscall_nrs2.awk +++ /dev/null @@ -1,13 +0,0 @@ -BEGIN { - print "/* Automatically generated file; DO NOT EDIT */" - print "#ifndef __LIBSYSCALL_SHIM_SYSCALLS_NRS2_H__" - print "#define __LIBSYSCALL_SHIM_SYSCALLS_NRS2_H__" -} - -/#define __NR_/{ - printf "\n#define __NR_%s\t\t%s", substr($2,6),$3 -} - -END { - print "\n\n#endif /* __LIBSYSCALL_SHIM_SYSCALLS_NRS2_H__ */" -} diff --git a/lib/syscall_shim/gen_syscall_r_static.awk b/lib/syscall_shim/gen_syscall_r_static.awk deleted file mode 100644 index 9de510609..000000000 --- a/lib/syscall_shim/gen_syscall_r_static.awk +++ /dev/null @@ -1,41 +0,0 @@ -BEGIN { - max_args = 6 - print "/* Auto generated file. DO NOT EDIT */\n\n" -} - -/[a-zA-Z0-9]+-[0-9]+/ { - name = $1 - args_nr = $2 + 0 - - printf "\n/* SYS_%s: %d argument(s) */\n", name, args_nr; - for (i = 0; i <= max_args; i++) - { - printf "#define uk_syscall_r%d_%s(", i, name; - for (j = 1; j <= i; j++) - { - if (j > 1) - printf ", " - printf "arg%d", j; - } - printf ") \\\n"; - - printf "\tuk_syscall_r_%s(", name; - - # hand-over given arguments - for (j = 1; j <= i && j <= args_nr; j++) - { - if (j > 1) - printf ", " - printf "__uk_scc(arg%d)", j; - } - - # fill-up missing arguments - for (j = i + 1; j <= args_nr; j++) - { - if (j > 1) - printf ", " - printf "__uk_scc(0)"; - } - printf ")\n"; - } -} diff --git a/lib/syscall_shim/gen_syscall_static.awk b/lib/syscall_shim/gen_syscall_static.awk deleted file mode 100644 index eeb4ce3b3..000000000 --- a/lib/syscall_shim/gen_syscall_static.awk +++ /dev/null @@ -1,41 +0,0 @@ -BEGIN { - max_args = 6 - print "/* Auto generated file. DO NOT EDIT */\n\n" -} - -/[a-zA-Z0-9]+-[0-9]+/ { - name = $1 - args_nr = $2 + 0 - - printf "\n/* SYS_%s: %d argument(s) */\n", name, args_nr; - for (i = 0; i <= max_args; i++) - { - printf "#define uk_syscall_e%d_%s(", i, name; - for (j = 1; j <= i; j++) - { - if (j > 1) - printf ", " - printf "arg%d", j; - } - printf ") \\\n"; - - printf "\tuk_syscall_e_%s(", name; - - # hand-over given arguments - for (j = 1; j <= i && j <= args_nr; j++) - { - if (j > 1) - printf ", " - printf "__uk_scc(arg%d)", j; - } - - # fill-up missing arguments - for (j = i + 1; j <= args_nr; j++) - { - if (j > 1) - printf ", " - printf "__uk_scc(0)"; - } - printf ")\n"; - } -} diff --git a/lib/syscall_shim/include/uk/syscall.h b/lib/syscall_shim/include/uk/syscall.h index b5e300b1c..279c31ffd 100644 --- a/lib/syscall_shim/include/uk/syscall.h +++ b/lib/syscall_shim/include/uk/syscall.h @@ -424,7 +424,7 @@ typedef long uk_syscall_arg_t; #ifdef CONFIG_LIBSYSCALL_SHIM #include #include -#include +#include #include #include #include diff --git a/lib/syscall_shim/syscall_map.awk b/lib/syscall_shim/syscall_map.awk new file mode 100644 index 000000000..828c5657e --- /dev/null +++ b/lib/syscall_shim/syscall_map.awk @@ -0,0 +1,78 @@ +BEGIN { + max_args = 6 + print "/* Automatically generated file; DO NOT EDIT */\n" + print "#include \n" + print "#define _uk_syscall_e_enosys() \\" + print "\t({ errno = ENOSYS; (-1); })" + print "#define _uk_syscall_r_enosys() \\" + print "\t({ (-ENOSYS); })" +} +/#define __NR_/{ + printf "\n" + printf "#ifdef HAVE_uk_syscall_%s\n", substr($2,6); + printf "#define uk_syscall_fn%d(...) \\\n\tuk_syscall_e_%s(__VA_ARGS__)\n", $3, substr($2,6) + for (i = 0; i <= max_args; i++) + { + printf "#define uk_syscall%d_fn%d(", i, $3 + for (j = 1; j <= i; j++) + { + if (j > 1) + printf ", "; + printf "arg%d", j; + } + printf ") \\\n\tuk_syscall_e%d_%s(", i, substr($2,6) + for (j = 1; j <= i; j++) + { + if (j > 1) + printf ", "; + printf "arg%d", j; + } + printf ")\n"; + } + printf "#define uk_syscall_r_fn%d(...) \\\n\tuk_syscall_r_%s(__VA_ARGS__)\n", $3, substr($2,6) + for (i = 0; i <= max_args; i++) + { + printf "#define uk_syscall_r%d_fn%d(", i, $3 + for (j = 1; j <= i; j++) + { + if (j > 1) + printf ", "; + printf "arg%d", j; + } + printf ") \\\n\tuk_syscall_r%d_%s(", i, substr($2,6) + for (j = 1; j <= i; j++) + { + if (j > 1) + printf ", "; + printf "arg%d", j; + } + printf ")\n"; + } + printf "#else /* !HAVE_uk_syscall_%s */\n", substr($2,6); + + printf "#define uk_syscall_fn%d(...) _uk_syscall_e_enosys()\n", $3 + for (i = 0; i <= max_args; i++) + { + printf "#define uk_syscall%d_fn%d(", i, $3 + for (j = 1; j <= i; j++) + { + if (j > 1) + printf ", "; + printf "arg%d", j; + } + printf ") _uk_syscall_e_enosys()\n"; + } + printf "#define uk_syscall_r_fn%d(...) _uk_syscall_r_enosys()\n", $3 + for (i = 0; i <= max_args; i++) + { + printf "#define uk_syscall_r%d_fn%d(", i, $3 + for (j = 1; j <= i; j++) + { + if (j > 1) + printf ", "; + printf "arg%d", j; + } + printf ") _uk_syscall_r_enosys()\n"; + } + printf "#endif /* !HAVE_uk_syscall_%s */\n", substr($2,6); +} diff --git a/lib/syscall_shim/syscall_nrs.awk b/lib/syscall_shim/syscall_nrs.awk new file mode 100644 index 000000000..46a78053b --- /dev/null +++ b/lib/syscall_shim/syscall_nrs.awk @@ -0,0 +1,13 @@ +BEGIN { + print "/* Automatically generated file; DO NOT EDIT */" + print "#ifndef __LIBSYSCALL_SHIM_SYSCALL_NRS_H__" + print "#define __LIBSYSCALL_SHIM_SYSCALL_NRS_H__" +} + +/#define __NR_/{ + printf "\n#define SYS_%s\t\t%s", substr($2,6),$3 +} + +END { + print "\n\n#endif /* __LIBSYSCALL_SHIM_SYSCALL_NRS_H__ */" +} diff --git a/lib/syscall_shim/syscall_nrs2.awk b/lib/syscall_shim/syscall_nrs2.awk new file mode 100644 index 000000000..a70897a8d --- /dev/null +++ b/lib/syscall_shim/syscall_nrs2.awk @@ -0,0 +1,13 @@ +BEGIN { + print "/* Automatically generated file; DO NOT EDIT */" + print "#ifndef __LIBSYSCALL_SHIM_SYSCALLS_NRS2_H__" + print "#define __LIBSYSCALL_SHIM_SYSCALLS_NRS2_H__" +} + +/#define __NR_/{ + printf "\n#define __NR_%s\t\t%s", substr($2,6),$3 +} + +END { + print "\n\n#endif /* __LIBSYSCALL_SHIM_SYSCALLS_NRS2_H__ */" +} diff --git a/lib/syscall_shim/syscall_provided.awk b/lib/syscall_shim/syscall_provided.awk new file mode 100644 index 000000000..d10342467 --- /dev/null +++ b/lib/syscall_shim/syscall_provided.awk @@ -0,0 +1,31 @@ +BEGIN { + print "/* Automatically generated file; DO NOT EDIT */" + print "#ifndef __LIBSYSCALL_SHIM_PROVIDED_SYSCALLS_H__" + print "#define __LIBSYSCALL_SHIM_PROVIDED_SYSCALLS_H__" + print "\n#include " +} + +/[a-zA-Z0-9]+-[0-9]+/{ + # check if the syscall is not defined + printf "\n#ifndef SYS_%s\n", $1; + # if a LEGACY_ symbol is defined, the syscall is not required + # and we can continue the build process + printf "#ifdef LEGACY_SYS_%s\n", $1; + printf "#ifdef CONFIG_LIBSYSCALL_SHIM_LEGACY_VERBOSE\n" + printf "#warning Ignoring legacy system call '%s': No system call number available\n", $1 + printf "#endif /* LIBSYSCALL_SHIM_LEGACY_VERBOSE */\n" + # if the LEGACY symbol is not defined for this syscall, it means that the + # syscall is required and we can't continue without a definition + printf "#else\n"; + printf "#error Failed to map system call '%s': No system call number available\n", $1 + printf "#endif /* LEGACY_SYS_%s */\n", $1 + printf "#else\n"; + printf "#define HAVE_uk_syscall_%s t\n", $1; + printf "UK_SYSCALL_E_PROTO(%s, %s);\n", $2, $1; + printf "UK_SYSCALL_R_PROTO(%s, %s);\n", $2, $1; + printf "#endif /* !SYS_%s */\n", $1; +} + +END { + print "\n#endif /* __LIBSYSCALL_SHIM_PROVIDED_SYSCALLS_H__ */" +} diff --git a/lib/syscall_shim/syscall_r_static.awk b/lib/syscall_shim/syscall_r_static.awk new file mode 100644 index 000000000..9de510609 --- /dev/null +++ b/lib/syscall_shim/syscall_r_static.awk @@ -0,0 +1,41 @@ +BEGIN { + max_args = 6 + print "/* Auto generated file. DO NOT EDIT */\n\n" +} + +/[a-zA-Z0-9]+-[0-9]+/ { + name = $1 + args_nr = $2 + 0 + + printf "\n/* SYS_%s: %d argument(s) */\n", name, args_nr; + for (i = 0; i <= max_args; i++) + { + printf "#define uk_syscall_r%d_%s(", i, name; + for (j = 1; j <= i; j++) + { + if (j > 1) + printf ", " + printf "arg%d", j; + } + printf ") \\\n"; + + printf "\tuk_syscall_r_%s(", name; + + # hand-over given arguments + for (j = 1; j <= i && j <= args_nr; j++) + { + if (j > 1) + printf ", " + printf "__uk_scc(arg%d)", j; + } + + # fill-up missing arguments + for (j = i + 1; j <= args_nr; j++) + { + if (j > 1) + printf ", " + printf "__uk_scc(0)"; + } + printf ")\n"; + } +} diff --git a/lib/syscall_shim/syscall_static.awk b/lib/syscall_shim/syscall_static.awk new file mode 100644 index 000000000..eeb4ce3b3 --- /dev/null +++ b/lib/syscall_shim/syscall_static.awk @@ -0,0 +1,41 @@ +BEGIN { + max_args = 6 + print "/* Auto generated file. DO NOT EDIT */\n\n" +} + +/[a-zA-Z0-9]+-[0-9]+/ { + name = $1 + args_nr = $2 + 0 + + printf "\n/* SYS_%s: %d argument(s) */\n", name, args_nr; + for (i = 0; i <= max_args; i++) + { + printf "#define uk_syscall_e%d_%s(", i, name; + for (j = 1; j <= i; j++) + { + if (j > 1) + printf ", " + printf "arg%d", j; + } + printf ") \\\n"; + + printf "\tuk_syscall_e_%s(", name; + + # hand-over given arguments + for (j = 1; j <= i && j <= args_nr; j++) + { + if (j > 1) + printf ", " + printf "__uk_scc(arg%d)", j; + } + + # fill-up missing arguments + for (j = i + 1; j <= args_nr; j++) + { + if (j > 1) + printf ", " + printf "__uk_scc(0)"; + } + printf ")\n"; + } +} diff --git a/lib/syscall_shim/syscall_stubs.awk b/lib/syscall_shim/syscall_stubs.awk new file mode 100644 index 000000000..a93712656 --- /dev/null +++ b/lib/syscall_shim/syscall_stubs.awk @@ -0,0 +1,8 @@ +BEGIN { print "/* Auto generated file. Do not edit */" } +/#define __NR_/ { + name = substr($2,6); + printf "\n#ifndef HAVE_uk_syscall_%s", name; + printf "\n#define uk_syscall_e_%s(...) uk_syscall_e_stub(\"%s\")", name, name; + printf "\n#define uk_syscall_r_%s(...) uk_syscall_r_stub(\"%s\")", name, name; + printf "\n#endif /* !HAVE_uk_syscall_%s */\n", name; +}