In the next big refactor (next PR), all of the platform functionality
used by both relibc and ld.so will be moved into a `platform`/`sysdeps`
crate and then ld.so would be moved out of relibc and not link with it.
I think doing it in a seperate PR would make it more managable, as when
I did half of it, the diff was pretty huge and that way it would be
easier to review too :)
Signed-off-by: Anhad Singh <andypython@protonmail.com>
Closes: #200
The spec doesn't define which error code to set if `len` is too large.
`ENOMEM` is the closest defined condition that fits:
>> [...] the range [addr,addr+len) exceeds that allowed for the address
space of a process [...]
Logically, `len` would lead to `addr` exceeding the address space of a
process if rounding it up to the next page size causes an overflow.
The bug is described for `x86_64` and Linux but is the same for other architectures and on Redox.
`Tcb::current()` is used to retrieve the current TCB, which is done by by reading `fs:[0x10]`. The TCB layout describes that at offset `0x10`, there is `tcb_ptr: *mut GenericTcb<...>`, which is nothing more but a pointer to itself.
This is fine as otherwise a system call would be required to get the TCB (`arch_prctl(ARCH_GET_FS)` on Linux).
However, this is problematic as the function may be called when the FS base is not set, and in that case the expected output of the function should be [`None`], but we don't currently handle that.
To fix this, any code paths that maybe call this function on an uninitialized TCB are be switched to call `current_slow()`. Which just uses `arch_prctl(ARCH_GET_FS)` to get the FS base and check if it's non-zero.
Signed-off-by: Anhad Singh <andypython@protonmail.com>
`_Exit`, `exit`, and related functions should return `!` because they
don't return. This also signals to cbindgen that it should emit
`[[noreturn]]` for those functions.
As we know, vectors amortize the cost of adding new elements by reserving
space for multiple elements when full. This is useful but may lead to
allocating more memory than necessary.
`relibc` generally avoids over allocations by reserving the exact amount
of space when possible. I fixed a few areas that still over allocated or
reallocated unnecessarily by leveraging iterators that are more likely
to know sizes.