Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makesyscalls: restore support for cpp in input #1575

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

brooksdavis
Copy link
Contributor

Implement functionality largely identical to that in makesyscalls.lua on 14-STABLE. I've excluded prolog and epilogue support as it's not obviously very useful. Could restore the original function if someone is using conditional includes or the like.

Deprecate this functionality (no plan to remove it without replacement, but putting a line in the sand.)

@brooksdavis
Copy link
Contributor Author

CC @agge3

@brooksdavis
Copy link
Contributor Author

I suspect we also need ifdefs in syscalls.map, but I wanted to start with replicating what's in the old version.

kevans91 and others added 5 commits January 21, 2025 18:50
This exercises some subset of the preprocessor that would be nice to
still support.
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
Sponsored by:	DARPA, AFRL
Warn that C preprocessor directives in the config file are deprecated.
They are unsound and support has a number of potential pitfalls.  They
should be replaced by compile-time generation of files plus an overlay
framework to allow things like per-arch variation.

Sponsored by:	DARPA, AFRL
If there are per-platform differences in which syscalls are supported,
we should only try to export implemented ones in libc.  Fortunately,
syscall maps are run though cpp.  (This is arguably incomplete as
syscall.mk isn't--and can't practically be--supported.)

Sponsored by:	DARPA, AFRL
The two outer blocks had identical contents and the two inner blocks
differed in a single location.

Sponsored by:	DARPA, AFRL
@brooksdavis
Copy link
Contributor Author

Pulled in @kevans91's test script and updated for main (I should probably MFC the diff reduction changes.)

Fixed the way the epilogue is handled.

Added syscalls.map cpp support and added an unrelated minor improvement to the syscall.mk code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants