Re: [RFC][v5][PATCH 8/8]: Define clone_with_pids() syscall

Arnd Bergmann
2009-09-09T12:21:41Z

On Tuesday 08 September 2009, Nathan Lynch wrote:

> This doesn't work on a 64-bit kernel when the process is 32-bit and uses
> the definition of struct pid_set provided in types.h:
>
> +struct pid_set {
> + int num_pids;
> + pid_t *pids;
> +};
>
> Shouldn't the pids field be u64 or some other type of fixed size?

This is a complex problem. The structure above would need a conversion
for the pointer size that you can avoid by using a u64, but that introduces
another problem:

struct pid_set {
int num_pids;
u64 pidp;
};

Has implicit padding between the two members on all 64 bit architectures,
but not on i386, so you would still need a conversion (not for s390, power,
mips, sparc or parisc though, only for x86).

I can see two solutions for this:

1. use separate system call arguments for num_pids and pidp.
This avoids the data structure and saves one copy_from_user call,
at the cost of adding another argument to the syscall. syscalls with
more than 6 arguments are somewhat problematic as well.

2. use a single pointer, with variable length data structures:

struct pid_set {
int num_pids;
pid_t pids[0];
};

Since pid_t is always an int, you have no problem with padding or
incompatible types, but rely on a data structure definition that
is not in C89 (not sure about C99).