Once openat is supported on Redox, consider using dirfds for `/` and for the cwd
Once openat is supported, I think there should be a statically allocated fd number used for cwd. This means getcwd <=> realpath(__get_cwd_fd), chdir(path) <=> dup2(__get_cwd_fd, tmp := open(path)) then close(tmp), fchdir(fd) <=> dup2(__get_cwd_fd, fd). Since chdir is async-signal-safe, it currently needs to do two sigprocmasks for every open(), but using dup2 to replace the file description the fd points to, is already fully atomic.
If openat eventually replaces regular open, relibc might also store a statically allocated fd for /, making chroot trivial. The only problem is that fpath probably needs to continue to exist, but openat could take a "dirfd is root" flag so fpath returns a path relative to that root.