Re: [PATCH v1 1/2] fork: add clone3
From: Arnd Bergmann
Date: Fri May 31 2019 - 04:18:38 EST
On Thu, May 30, 2019 at 3:20 PM Szabolcs Nagy <nsz@xxxxxxxxxx> wrote:
> * Christian Brauner <christian@xxxxxxxxxx> [2019-05-29 17:22:36 +0200]:
> > /* uapi */
> > struct clone_args {
> > __aligned_u64 flags;
> > __aligned_u64 pidfd;
> > __aligned_u64 parent_tidptr;
> > __aligned_u64 child_tidptr;
> > __aligned_u64 stack;
> > __aligned_u64 stack_size;
> > __aligned_u64 tls;
> > };
>
> is this new linux syscall api style to pass pointers as u64?
This is common for ioctls passing structures now. I don't think
we've had many system calls with structures containing pointers,
but the idea is the same, i.e. we want structures to be identical
on 32-bit and 64-bit architectures.
> i think it will look a bit ugly in userspace where cast
> to u64 would signextend pointers on most 32bit targets, so
> user code would have to do something like
>
> arg.ptr = (uint64_t)(uintptr_t)ptr;
>
> such ugliness can be hidden by the libc with a different
> struct definition, but it will require bigendian and alignment
> hackery (or translation in libc, but that does not really work
> when user calls raw syscall).
Right. Note also that user space should do zero-extension
of the variables in order for the kernel to not care about
what called it. Just leaving padding fields in the structure
is not enough here.
User space that calls the raw syscall certainly has to
go through the uintptr_t cast, but I would also expect that
applications don't normally do that, and instead call a
library function that has regular C calling conventions
with individual arguments instead of a structure.
Arnd