diff options
Diffstat (limited to 'linux/signals.mk')
-rw-r--r-- | linux/signals.mk | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/linux/signals.mk b/linux/signals.mk new file mode 100644 index 0000000..f7a8a45 --- /dev/null +++ b/linux/signals.mk @@ -0,0 +1,138 @@ +libsyscalls_get_signals.o: generated/linux-signals.h linux/signals.c +libsyscalls_get_signals.lo: generated/linux-signals.h linux/signals.c + +generated/linux-signals.tbl: $(LINUX_SOURCE) linux/signals.mk + mkdir -p -- generated + set -e; ( \ + get_gcc_or_clang () { \ + ( \ + ( \ + IFS=:; \ + for dir in $$PATH; do \ + if test ! -d "$$dir"; then continue; fi; \ + for file in "$$dir"/*; do \ + if test ! -x "$$file"; then continue; fi; \ + printf '%s\n' "$$file"; \ + done \ + done \ + ) | grep '/\(gcc\|clang\)\(-[0-9.]\+\)\?$$'; \ + printf '%s\n' gcc; \ + ) | sed 1q; \ + }; \ + if test -n "$(CC_DEF_EXTRACT)"; then \ + c="$(CC_DEF_EXTRACT)"; \ + else \ + c="$(CC)"; \ + fi; \ + c="$$($$c --version 2>&1 | sed 1q | sed 's/^.*(\(.*\)).*$$/\1/' | tr '[A-Z]' '[a-z]' | cut -d ' ' -f 1)"; \ + if test ! "$$c" = gcc && test ! "$$c" = clang; then \ + c="$$(get_gcc_or_clang)"; \ + fi; \ + extract="$$c -E -dM -D__KERNEL__"; \ + srcdir="linux-src/linux-$(LINUX_VERSION)"; \ + mkdir -p -- "$$srcdir/tools/include/generated/"; \ + touch -- "$$srcdir/tools/include/generated/bounds.h"; \ + touch -- "$$srcdir/tools/include/generated/timeconst.h"; \ + process_arch () \ + { \ + set -e; \ + signals="$$( \ + $$extract "-I$$srcdir/tools/include" $$fixes "$$2" \ + | sed -n 's/^\s*\x23\s*define\s\+\(SIG[^\s]\+\)\s\+\([0-9]\+\)\s*\(\/.*\)\?$$/'"$$1"' \2 \1/p' \ + | grep -v ' SIG_' \ + | grep -v ' SIGSTKSZ' \ + | sort -k 2 -nu; \ + )"; \ + if test "$$1" = arm; then \ + signals="$$(printf "%s\n" "$$signals" | sed 's/\bSIGSWI\b/SIGRTMIN/')"; \ + fi; \ + printf "%s\n" "$$signals"; \ + sigrtmin="$$(printf "%s\n" "$$signals" | sed -n 's/^.* \([0-9]\+\) SIGRTMIN$$/\1/p')"; \ + maxnamed="$$(printf "%s\n" "$$signals" | sed -n '$$s/^.* \([0-9]\+\) .*$$/\1/p')"; \ + test "$$sigrtmin" = "$$maxnamed"; \ + maxsig=_NSIG; \ + depth=0; \ + while test -n "$$maxsig" && test -n "$$(printf '%s\n' "$$maxsig" | tr -d '[0-9]')" ; do \ + printf '%s: looking for %s\n' "$$1" "$$maxsig" >&2; \ + def="$$maxsig"; \ + maxsig="$$($$extract "-I$$srcdir/tools/include" $$fixes "$$2" \ + | sed -n 's/^\s*\x23\s*define\s\+'"$$def"'\s\+\([A-Z0-9_]\+\)\s*\(\/.*\)\?$$/\1/p')"; \ + if test -z "$$maxsig"; then \ + maxsig="$$($$extract "-I$$srcdir/tools/include" \ + "-I$$srcdir/arch/$$1/include" \ + "-I$$srcdir/include" \ + "-I$$srcdir" \ + $$fixes \ + "$$(printf '%s\n' "$$2" | sed 's:/uapi/:/:')" \ + | sed -n 's/^\s*\x23\s*define\s\+'"$$def"'\s\+\([A-Z0-9_]\+\)\s*\(\/.*\)\?$$/\1/p')"; \ + fi; \ + printf '%s: found %s\n' "$$1" "$$maxsig" >&2; \ + : $$(( depth++ )); \ + test $$(( depth )) -lt 1000; \ + done; \ + test -n "$$maxsig"; \ + i=1; \ + while (( sigrtmin + i <= maxsig )); do \ + printf '%s %d SIGRTMIN+%d\n' "$$1" $$(( sigrtmin + i )) $$i; \ + : $$(( i++ )); \ + done; \ + }; \ + getsigs () { \ + process_arch "$$@" | sed 's/\bSIGRTMIN\b/_&/'; \ + }; \ + for arch in $$(printf '%s\n' "$$srcdir/arch"/*/ | sed 's:^.*/\([^/]*\)/$$:\1:'); do \ + if test ! "$$arch" = s390 && test -f "$$srcdir/arch/$$arch/include/uapi/asm/signal.h"; then \ + getsigs "$$arch" "$$srcdir/arch/$$arch/include/uapi/asm/signal.h"; \ + fi; \ + done; \ + getsigs generic "$$srcdir/include/uapi/asm-generic/signal.h"; \ + ) > $@ + @printf '\033[1;32m%s\033[m\n' \ + 'Compiler warnings above are not of interest, they were generated during' \ + 'extraction of the Linux source code and are not part of this library' + @grep '^generic.*SIGRTMIN+.*' >/dev/null 2>/dev/null < $@ + grep '^generic ' < $@ | cut -d ' ' -f 2 > generated/linux-signals.generic.tbl + @# For most architectures the signal numbers are the same, + @# yet they have their own signal.h listing them, so to remove + @# duplication in the library, we removing duplicates after + @# validating that they have not diverged + grep '^arm ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl - + sed '/^arm /d' < $@ > $@.tmp && mv -- $@.tmp $@ + grep '^arm64 ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl - + sed '/^arm64 /d' < $@ > $@.tmp && mv -- $@.tmp $@ + grep '^hexagon ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl - + sed '/^hexagon /d' < $@ > $@.tmp && mv -- $@.tmp $@ + grep '^loongarch ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl - + sed '/^loongarch /d' < $@ > $@.tmp && mv -- $@.tmp $@ + grep '^arc ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl - + sed '/^arc /d' < $@ > $@.tmp && mv -- $@.tmp $@ + grep '^nios2 ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl - + sed '/^nios2 /d' < $@ > $@.tmp && mv -- $@.tmp $@ + grep '^ia64 ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl - + sed '/^ia64 /d' < $@ > $@.tmp && mv -- $@.tmp $@ + grep '^m68k ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl - + sed '/^m68k /d' < $@ > $@.tmp && mv -- $@.tmp $@ + grep '^powerpc ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl - + sed '/^powerpc /d' < $@ > $@.tmp && mv -- $@.tmp $@ + grep '^sh ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl - + sed '/^sh /d' < $@ > $@.tmp && mv -- $@.tmp $@ + grep '^x86 ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl - + sed '/^x86 /d' < $@ > $@.tmp && mv -- $@.tmp $@ + grep '^xtensa ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl - + sed '/^xtensa /d' < $@ > $@.tmp && mv -- $@.tmp $@ + rm -f -- generated/linux-signals.*.tbl + +generated/linux-signals.h: generated/linux-signals.tbl linux/signals.mk + set -e; \ + for arch in $$(cut -d ' ' -f 1 < generated/linux-signals.tbl | uniq); do \ + ARCH="$$(printf '%s\n' "$$arch" | tr '[a-z]' '[A-Z]')"; \ + printf '#define LIST_LINUX_SIGNALS_FOR_%s(X, D)\\\n' "$$ARCH"; \ + sed -n 's/^'"$$arch"' \([0-9]\+\) \(.*\)$$/\tX(\1, "\2") D\\/p' \ + < generated/linux-signals.tbl \ + | sed '$$s/ D\\//'; \ + printf 'static struct libsyscalls_named_number linux_signals_for_%s[] = {\n' "$$arch"; \ + printf '#define X(NR, NAME) {.number.s = NR, .name = NAME}\n'; \ + printf '\tLIST_LINUX_SIGNALS_FOR_%s(X, COMMA)\n' "$$ARCH"; \ + printf '#undef X\n'; \ + printf '};\n'; \ + done > $@ |