Pascal strings in syscalls
Created by: mahkoh
Redox currently follows the unix convention of passing strings as C strings---that is, sequences of bytes terminated by a zero byte. This means that languages using Pascal strings---that is, a pointer plus a length field---will have to perform copies every time they do a syscall. For example, the open syscall looks like this:
pub unsafe fn do_sys_open(path: *const u8, flags: usize) -> usize {
// ...
current.canonicalize(str::from_utf8_unchecked(c_string_to_slice(path)));
Instead, it could look like this:
#[repr(C)]
pub struct iovec {
base: *mut u8,
size: usize
}
pub unsafe fn do_sys_open(path: *const iovec, flags: usize) -> usize {
(Note that, while the base
pointer is mut
, open
would guarantee in its documentation not to modify it.)
This means that the libc will have to do a little bit more work to translate the C string to a Pascal string (by calling strlen), but, on the other hand, the kernel no longer has to calculate the length. It's still a bit more expensive for C programs because the kernel has to do some sanity checks anyway, but it's much cheaper for Rust programs.