Document the runtime environment assumptions of std
#133604
Labels
A-docs
Area: Documentation for any part of the project, including the compiler, standard library, and tools
A-runtime
Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows
C-tracking-issue
Category: An issue tracking the progress of sth. like the implementation of an RFC
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
std
makes a number of assumptions about the runtime environment that go beyond what is guaranteed by the ABI. They should be documented somewhere. I'm filing this issue to both collect these assumptions and have a discussion about what the best place is to put them.Assumptions
std
makes:std
is not used when the C platform functions are not available. E.g. usingclone
on Linux and then calling intostd
is definitely not sound. (This one is very obvious)std
is not called from an asynchronous signal handler or afterfork
.std
makes no attempt at being async-signal-safe (except forpanic!
afteralways_abort
has been called).pthread_exit
orpthread_cancel
).This is because cancellation does not result in proper unwinding meaning destructors aren't called, but the thread's stack is reused – this is incompatible with
pin!
and probably a bunch of library code.STDIN_FILENO
,STDOUT_FILENO
,STDERR_FILENO
) are assumed to be usable as standard input/output/error.sigaltstack
is not used by code that does not also install it's own handlers forSIGSEGV
andSIGBUS
(only applicable whensigaltstack
is used in threads not spawned bystd
).std
uses TLS variables to store the address of the stack guard page. While TLS accesses are not documented to be async-signal-safe, they mostly are – except for the first access to a variable.std
makes sure to always access the relevant variables before setting up asigaltstack
, thereby ensuring that the TLS accesses are safe when the signal handler is successfully called. User code has no access to these variables and therefore cannot initialize them, so it must ensure thatstd
's signal handler is not called when they could be uninitialized._tlv_atexit
.There was a platform bug that resulted in crashes when
_tlv_atexit
is recursively called. It has since been fixed, but our minimum supported version is not high enough to include the fix.The text was updated successfully, but these errors were encountered: