You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
The POSIX spec defines the concept of "error numbers" (aka "error codes"), which are integers with platform-specific values used to signal error conditions from low-level OS routines. Authors of libraries that interact directly with the OS (for example, via Linux kernel syscalls) need to know the values of each error number. These values can vary between OSes and architectures, and not all error numbers defined by POSIX are necessarily defined for a given (os, arch) target tuple.
Rust currently has limited support for error numbers via auto-generated bindings to the platform's libc, but these are awkward to use in no_std contexts because a common reason to build no_std binaries is specifically to avoid depending on libc:
The runtime environment may have resource constraints (ram, storage) that are too small to fit a libc.
The platform vendor might not provide a libc at all, or if it does, it might not be sufficiently standards-compliant to be supported by the libc crate's build system.
There may be external requirements such as "must not depend on libc", and it is much easier to produce evidence of compliance if the build does not have the libc crate in its transitive dependency graph.
Desired project outcome
Ideally there would be an ErrorCode or ErrorNumber type defined in std, which is re-exported from a sub-crate (similar to alloc defining containers) so that it can be used in no_std mode. Ports of rustc to a target platform would define error codes for that platform as associated constants of ErrorCode, with values appropriate to the target.
Error codes are part of a platform ABI and therefore don't change once defined[0], so the ongoing maintenance overhead of this new type should be low. The primary maintenance burden will land on people adding new target platforms to rustc, and I expect that specifying error codes will not be a material increase in work considering how much is involved in porting the rest of the compiler.
[0] excepting platforms that intentionally do not provide an ABI -- it might not be possible to define the associated constants on such platforms.
The text was updated successfully, but these errors were encountered:
Looking into this, it seems to be about posix function error codes and not process exit codes (which I'm more interested in).
Some quick thoughts from my dealing with process exit codes that might carry over here
This is done through a lot of platform conditionals. I find that information tends to get communicated across platforms and ideally we expose the platform specific information in a way that any platform can access.
This specifically uses NonZeroU16. In process exit codes, you need to expose the 0 case as well since you can't or shouldn't always immediately map a u16 -> Result<(), NonZeroU16>
Related discussion:
std::os::unix
std::os::unix
Prototype code: https://github.com/jmillikin/rust-posix-error-numbers (rustdoc)
General background
The POSIX spec defines the concept of "error numbers" (aka "error codes"), which are integers with platform-specific values used to signal error conditions from low-level OS routines. Authors of libraries that interact directly with the OS (for example, via Linux kernel syscalls) need to know the values of each error number. These values can vary between OSes and architectures, and not all error numbers defined by POSIX are necessarily defined for a given (os, arch) target tuple.
Rust currently has limited support for error numbers via auto-generated bindings to the platform's libc, but these are awkward to use in
no_std
contexts because a common reason to buildno_std
binaries is specifically to avoid depending on libc:libc
crate's build system.libc
crate in its transitive dependency graph.Desired project outcome
Ideally there would be an
ErrorCode
orErrorNumber
type defined instd
, which is re-exported from a sub-crate (similar toalloc
defining containers) so that it can be used inno_std
mode. Ports of rustc to a target platform would define error codes for that platform as associated constants ofErrorCode
, with values appropriate to the target.Error codes are part of a platform ABI and therefore don't change once defined[0], so the ongoing maintenance overhead of this new type should be low. The primary maintenance burden will land on people adding new target platforms to rustc, and I expect that specifying error codes will not be a material increase in work considering how much is involved in porting the rest of the compiler.
[0] excepting platforms that intentionally do not provide an ABI -- it might not be possible to define the associated constants on such platforms.
The text was updated successfully, but these errors were encountered: