From 289294220f278a291452332da8f45cf756f57fe5 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 8 Jan 2014 16:12:47 -0500 Subject: fix type of semctl variadic argument per POSIX, the variadic argument has type union semun, which may contain a pointer or int; the type read depends on the command being issued. this allows the userspace part of the implementation to be type-correct without requiring special-casing for different commands. the kernel always expects to receive the argument interpreted as unsigned long (or equivalently, a pointer), and does its own handling of extracting the int portion from the representation, as needed. this change fixes two possible issues: most immediately, reading the argument as a (signed) long and passing it to the syscall would perform incorrect sign-extension of pointers on the upcoming x32 target. the other possible issue is that some archs may use different (user-space) argument-passing convention for unions, preventing va_arg from correctly obtaining the argument when the type long (or even unsigned long or void *) is passed to it. --- src/ipc/semctl.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/ipc') diff --git a/src/ipc/semctl.c b/src/ipc/semctl.c index 274e2cf..49927e2 100644 --- a/src/ipc/semctl.c +++ b/src/ipc/semctl.c @@ -3,16 +3,22 @@ #include "syscall.h" #include "ipc.h" +struct semun { + int val; + struct semid_ds *buf; + unsigned short *array; +}; + int semctl(int id, int num, int cmd, ...) { - long arg; + struct semun arg; va_list ap; va_start(ap, cmd); - arg = va_arg(ap, long); + arg = va_arg(ap, struct semun); va_end(ap); #ifdef SYS_semctl - return syscall(SYS_semctl, id, num, cmd | IPC_64, arg); + return syscall(SYS_semctl, id, num, cmd | IPC_64, arg.buf); #else - return syscall(SYS_ipc, IPCOP_semctl, id, num, cmd | IPC_64, &arg); + return syscall(SYS_ipc, IPCOP_semctl, id, num, cmd | IPC_64, &arg.buf); #endif } -- cgit v1.1