Re: alternatives to null-terminated byte arrays in syscalls in the future?
From: Denys Vlasenko
Date: Fri Apr 08 2016 - 17:11:22 EST
On Fri, Apr 8, 2016 at 11:04 PM, Andrew Kelley <superjoe30@xxxxxxxxx> wrote:
> The open syscall looks like this:
>
> SYSCALL_DEFINE3(open, const char __user *, filename, int, flags, umode_t, mode)
>
> filename is a null terminated byte array. Null termination is one way
> to handle lengths of byte arrays, but arguably a better way is to keep
> track of the length in a separate field. Many programming languages
> use pointer + length instead of null termination for various reasons.
>
> When it's time to make a syscall such as open, software which does not
> have a null character at the end of byte arrays are forced to allocate
> memory, do a memcpy, insert a null byte, perform the open syscall,
> then deallocate the memory.
In many cases, it's possible to just add the NUL byte instead.
> What are the chances that in the future, Linux will have alternate
> syscalls which accept byte array parameters where one can pass the
> length of the byte array explicitly instead of using a null byte?
0% chances. Amount of PITA to make that happen far outweighs
possible benefits.