Open danielschemmel opened 1 month ago
Generally speaking, any no_std
Rust code that wants to exit in a similar fashion to std::process::exit
(rather than returning through main
), for example when having to write a panic handler.
For the specific use-case, we are writing a no_std
rust library that needs to be as unintrusive as possible, when linked into the target process. Critically, calling libc
is problematic (we are currently doing a very hacky dance of a statically linked and symbol-renamed musl, and would really like to get rid of it completely).
The point of this library is to serve as a runtime for testing via symbolic execution, which means we really want to run below the "user-facing libc". I am currently trying to move away from this multiple-but-different libc approach and make our runtime (which is mostly written in Rust) be pure Rust, ideally using the x86_64-unknown-linux-none target.
The OS APIs that we are currently using are mostly covered by Rustix, but sometimes we need to immediately exit without going through user code (the code under test is after all by definition untrustworthy).
Turns out that I was not quite thorough enough, and that rustix::runtime::exit_group
was exactly what I was looking for, I just could not find it without your comments.
I still think that a more discoverable function (probably in rustix::process
) would be good for more general no_std
libraries, what do you think?
This PR adds
rustix::process::exit
to exit the current process. This is useful forno_std
code, which cannot callstd::process::exit
.The kernel backend uses the
exit_group
syscall, which is equivalent to the_exit
/_Exit
POSIX/C functions. For consistency, I also used the_exit
function for the C backend.There are two main ways in which this could be changed:
rustix::process::_exit
instead, which would differ from the usual Rust naming scheme.exit
in the C backend instead, which would callat_exit
functions only when the C backend is enabled.This PR is additive and should not require a semver bump.