opnsense-src/sys/tools/syscalls/scripts
Brooks Davis 42d075f4b7 makesyscalls: Restore support for cpp in input
Allow patterns like this in syscalls.master:

	#if 0
	91	AUE_NULL	RESERVED
	#else
	91	AUE_NULL	STD|CAPENABLED {
			int newsyscall(void);
		}
	#endif

makesyscalls.lua and it's predecessor makesyscalls.sh (really an awk
script with a tiny shell prolog) used a single pass parsing model where
lines beginning with `#` were emitted into most generated files as they
were read.  I belive this was initially there to allow includes to be
listed in syscalls.master, but Hyrum's Law[0] applies and people are using
it for things like architecture-specific syscall definitions.

This use of CPP macro is unsound and there are a number of sharp edges
in both the new and old implementations.  The macros are unsound because
not all the files were generate are run through CPP (or if they are not
in the same context) and this will increasingly be true as we generate
more things.  Sharp edges include the fact that anything before the
first syscall would be printed at a different scope (e.g., before an
array is declared).

In this patch I collect each non-#include CPP directive and attach them
to the syscall table or individual entries.  All entries before the
first syscall and after the last are attached to the prolog and epilog
members.  Within the syscall table all entries are attached to the next
system calls's prolog member.  In generators, each prolog entry is
printed regardless of the system call's visibiilty which replicates the
naive single pass model's behavior (including lots of empty blocks
of #if/#else/#endif in the output).  Unlike makesyscalls.lua, I discard
none #define entries at the top of the file and print a warning as their
usefulness appears limited.

[0] https://www.hyrumslaw.com

Reported by:	kevans
Reviewed by:	kevans
Sponsored by:	DARPA, AFRL
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1575
2025-02-18 22:03:13 +00:00
..
init_sysent.lua makesyscalls: Restore support for cpp in input 2025-02-18 22:03:13 +00:00
libsys_h.lua sysent: add a NOLIB modifer to prevent stub generation 2024-11-01 15:44:47 +00:00
syscall_h.lua
syscall_mk.lua makesyscalls: reduce redundency in syscall.mk code 2025-02-18 22:03:06 +00:00
syscalls.lua makesyscalls: Restore support for cpp in input 2025-02-18 22:03:13 +00:00
syscalls_map.lua sysent: add a NOLIB modifer to prevent stub generation 2024-11-01 15:44:47 +00:00
sysproto_h.lua makesyscalls: Restore support for cpp in input 2025-02-18 22:03:13 +00:00
systrace_args.lua makesyscalls: Restore support for cpp in input 2025-02-18 22:03:13 +00:00