Skip to main content

Crate cosmo_compat

Crate cosmo_compat 

Source
Expand description

Shims for places where cosmopolitan’s libc and Rust’s std disagree.

Link this into any cosmo target and the fixes apply themselves – each is a #[no_mangle] definition that the linker prefers over the one in libcosmo.a, because an archive member is only pulled in to satisfy a symbol that is still undefined.

Modules§

shim
The libc-boundary wrappers. cosmo-ld links every program with --wrap=NAME for each name in ../wrap.txt, so a call to open from std (or from anything else in the link) lands in __wrap_open here, which translates the Linux-numbered arguments to the host’s numbering, calls __cosmo_real_open (cosmo’s), and translates errno / results back.
xlate
Constant translation between Linux numbering (what std was compiled with) and the running host’s numbering (what cosmopolitan resolved at load time).

Functions§

__xpg_strerror_r⚠
POSIX XSI strerror_r, which is what Rust’s std actually calls.
waitid⚠
waitid, which cosmopolitan does not provide but std’s Process::wait references unconditionally (its pidfd path, P_PIDFD, is compiled in for every linux target). Linking is the requirement; the semantics only matter if the function is ever reached, and on cosmo std never creates a pidfd, so it is not. Implemented over waitpid for the P_PID/P_ALL shapes anyway: siginfo_t.si_status receives the raw wait status and si_pid the pid, at the Linux offsets std reads (si_pid at byte 16, si_status at 24).