It's a joy to see LibMain
and TRY()
greatly simplifying the main function of SerenityOS components like in 6b862d5. One thing that stands out though is the barebones C-syscall wrapping of Core::System::pledge()
and Core::System::unveil()
.
Given the Core::System
namespace you'd expect these functions to offer a typed C++ interface to the underlying system calls. Such a 'proper' C++ interface would allow for compile-time checking, finding exact argument usage and automated code indexing and refactoring.
Maybe someone's already on this, but here's a few ideas that cross my mind.
pledge()
symbolsMake the Core::System
namespace define specific enum
s or macros for each possible pledge
promise. Advantages:
stdio
pledge in the codebase)This would make code look something like:
// enumeration style
TRY(Core::System::pledge(kPromise_STDIO | kPromise_EXEC));
// macro style
TRY(Core::System::pledge(PROMISE_STDIO | PROMISE_EXEC));
// struct style
TRY(Core::System::pledge({ .stdio = true, .exec = true }));
unveil()
symbolsMake the Core::System
namespace define specific enum
s or macros for each possible unveil
permission. Advantages:
c
permission uses in the codebase)This would make code look something like:
// enumeration style
TRY(Core::System::unveil("/tmp/tmpfile", kUnveil_Read | kUnveil_Write));
// macro style
TRY(Core::System::unveil("/tmp/tmpfile", UNVEIL_READ | UNVEIL_WRITE));
// struct style
TRY(Core::System::unveil("/tmp/tmpfile", { .read = true, .write = true }));
unveil()
auto-commitInstead of forcing unveil(nullptr, nullptr)
into every program, serenity_main
could commit permissions automatically if any Core::System::unveil()
call was made in serenity_main
. Programs that want to unveil()
at a later moment can then still unveil later.
unveil_commit()
functionIn a similar vein, forcing programmers to unveil(nullptr, nullptr)
at all seems silly. Why not introduce a Core::System::unveilCommit()
function that commits unveil
permissions without having to pass nullptr
s.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too