std.os: spring-cleanup and specify organization
- Alphabetically sort things, where reasonable.
- Document, that only non-portable posix things belong into posix.zig
- If there is a portable abstraction, do not offer one in posix.zig
- Reason: Prevent useless abstractions and needless strong coupling.
- Move posix-only functions into posix.zig, which have either incompatible
or more extensive execution semantics than their counterparts and can be
grouped into
- File permission system
- Process management
- Memory management
- IPC
- Signaling
Work on #6600.
TODOs
- [x] rebase
- [x] sort the symbols in os.zig
- [x] draft specficiation for os organization
- [x] ~~openW is Windows only, where should this go?~~
- [x] skip moving too much stuff around
- [x] move the posix things
- [x] double check moved functions on semantical compatibility
- [x] make os organization specification + semantics more dense + get reviews
Self-Notification: Semantics + organization should be probably clarified within the lower layers.
Open question
- [x] ~~reboot is Linux only, not posix. see https://unix.stackexchange.com/questions/507259/is-there-a-posix-way-to-shutdown-a-unix-machine, So far linux.zig does not error handling and is merely the Linux shim. How should the shim be called to distinguish wrapper from error handling? => call it linux/bindings.zig for now.~~
- [x] same question for plan9.zig
- [x] same question for wasi.zig
- [x] Where should the usable without libc things go? If they would stay, then we should specify os means "platform-portable, but possibly requiring libc". => should stay
others:
- reboot: Linux, Mac
- epoll_create1, epoll_ctl, epoll_wait, : linux
- inotify_init1, inotify_add_watch, inotify_add_watchZ, inotify_rm_watch: linux
- event, eventfd: linux, wasi
- kqueue: bsd abstraction?
- [x] mmap is missing a pile of errors: https://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html
- dl_iterate_phdr: linux
- sched_getaffinity: linux
- [x] sigaltstack, sigaction, sigprocmask, futimens, uname: posix
- [x] copy_file_range: no proper target check ("assume linux")
- [x] getrusage, tcgetattr, tcsetattr(posix ones), ioctl_SIOCGIFINDEX (non-posix),
- signalfd: linux
- syncfs: linux only
- [x] prctl: linux, getrlimit, setrlimit (both posix),
- [x] madvise: posix? much less capable PrefetchVirtualMemory
- perf_event_open: linux only,
- timerfd_create, timerfd_gettime, timerfd_gettime: linux-only because posix ones are broken.
- [x] maybeIgnoreSigpipe: belongs into start.zig and NOT into os.zig (moved around + added explanation)
- ...
Future work: cleanup linux.zig: move non-error handling functions with error set into linux.api.zig
Derived TODOs:
- 1.~~change uname + add getVersion https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getversion + what other OSes use (BYOS), possible name
os.kernelVersion+ used viasystem.kernelVersion~~ already finished -
- ~~maybeIgnoreSigpipe belongs into start.zig and not into os.zig~~
-
- ~~mmap is missing a pile of errors: https://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html~~
-
- unify nanosleep with Windows NtDelayExecution => posix one for signaling, std.os non-signaling
-
- test link, linkat on Windows without libc + with libc for
@compileError
- test link, linkat on Windows without libc + with libc for
Ref: #14795
Future TODOs
Where should linux only error abstractions go? linux.zig and move the non-error abstractions into linux/api.zig?
-
epoll_create1, epoll_ctl, epoll_wait
-
inotify_init1, inotify_add_watch, inotify_add_watchZ, inotify_rm_watch: linux
-
dl_iterate_phdr
-
sched_getaffinity
-
signalfd
-
syncfs
-
perf_event_open etc
-
timerfd_create, timerfd_gettime, timerfd_gettime (posix ones are broken)
-
maybeIgnoreSigpipe: belongs into start.zig
This pull request is extremely chaotic and does a lot of things that are difficult to review, and likely to break. Let us chat about big changes to std.os ahead of time and be intentional and precise about what exactly the goal is.