RFC: C++-style sysdeps without weak symbols #1546
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR provides a small proof of concept for reworking the sysdep interfaces.
Previously, sysdeps were either made required for absolutely basic functionality (like
sys_read), and the rest was made optional by way of having them be weak symbols. This lead to a few problems:My proposal is derived from @marv7000's godbolt example that shoved the sysdep interface in a C++ class.
This proposal aims to extend on that, so as to provide mechanisms for required sysdeps, optional sysdeps, a transition plan so that changes can be made incrementally.
The core of the PoC is the
struct Sysdepsthat each sysdep defines. It contains functions that can be called by implementations.Required sysdeps are enforced by a concept (
concept RequiredSysdeps). Thestruct Sysdepsis globally instantiated as aconstinitvariable with a requires clause onRequiredSysdeps, which means that missing or having a sysdep wrongly typed results in a short error message at compile-time.The
struct Sysdepsshould derive interface classes likeAnsiSysdepsfor optional sysdeps for each supported option. These base classes provide an implementation for each optional sysdep that amounts to returningENOSYS, but allow for the sysdep to provide a proper implementation.As a compatability thing for transitioning, I provided a
AnsiCompatSysdepsclass that adapts the old weak-symbol interface to thestruct Sysdeps. This allows for gradual replacement of the weak symbol implementations by class functions.The PR currently implements ANSI sysdeps for Linux and managarm as an example using the compat interface as a basis. Some functions are rewritten to use the new interface, and some call sites have been changed to the new style.
Due to the
AnsiSysdepsclass providing aENOSYSimplementation, we can avoid using theauto sysdep = MLIBC_CHECK_OR_ENOSYS(mlibc::sys_whatever, -1);line and just directly callsysdeps.whatever()instead.