[Experiment] Registering syscalls with a proc macro #22
hardliner66
started this conversation in
Show and tell
Replies: 1 comment
-
|
That's actually kinda cool, I like this! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Yesterday I thought it might be nice to define syscalls with a proc macro using linkme, which makes it possible to register syscall handlers, even in different crates, which could be useful if we want to move the implementation for each arch into its own crate.
This approach has a drawback, namely there is no central place anymore to check if a syscall is implemented or not.
On the other hand, it allows to dynamically access the registered syscalls, which makes it possible to dynamically generate a list of implemented syscalls and print them. In theory, depending on how everything is structured, it should even be possible to generate this list without having to run the kernel, but I didn't want to invest too much time into that yet.
If you want to check it out, I created a branch for my fork called syscall_macro so I could play around with the idea a bit.
Here is a syscall I have re-written to use the macro instead:
Here is the modified syscall handler, that first checks the registry and if it doesn't find anything, uses the old match expression:
I also added some code to the kernel so it prints all the implemented syscalls (simplest way to print the data without major restructuring):
I also wanted to play around with proc macros and explore how to collect information about items marked with the proc macros in order to auto generate docs. I had to resort to a bit of a workaround to get the data out, but I think there is the potential to write the implementations for different CPUs/Architectures as separate crates. This could make it possible for users to provide their own syscalls and probably some other cool shenanigans.
Note
This is not intended as a proposal to use this, but rather an experiment I wanted to share.
Beta Was this translation helpful? Give feedback.
All reactions