News for hackers. Stuff that matters.
Re:C stdlib isn't threadsafe and even safe Rust didn't save us by ModernMech on Wednesday January 22, 2025 @05:14PM (#42798078)
> The environment is provided by the OS at startup.

That's part of the design of the OS. How the OS implements this is primitive, and so it leaves it up to every language to handle. The blog mentions the issue is with getenv, setenv, and realloc, all system calls. To me, that sounds like bad OS design is causing issues downstream with languages, leaving it up to individual programmers to deal with the fallout.

Re:C stdlib isn't threadsafe and even safe Rust didn't save us by eqvinox on Wednesday January 22, 2025 @05:23PM (#42798153)
> getenv, setenv, and realloc, all system calls

None of these 3 functions is a system call. open(), mmap(), sbrk(), poll(), etc. are system calls. What you're referring to is C library API, which as Go has shown (both to its benefit and its detriment) is optional on almost all operating systems (a major exception being OpenBSD.)

If you really want to lose some sanity I would recommend reading the man page for getauxval(), and then look up how that works on the machine level when the process is started. Especially on some of the older architectures. (No liability accepted for any grey hair induced by this.)

ed.: https://lwn.net/Articles/631631/

Re:C stdlib isn't threadsafe and even safe Rust didn't save us by Joker_vD on Wednesday January 22, 2025 @05:21PM (#42798134)
Neither getenv, setenv nor realloc are system calls, they all are functions from C stdandard library, some parts of which for historical reasons are required to be almost impossible to use safely/reliably.