From patchwork Wed Feb 5 00:56:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 37682 Received: (qmail 91771 invoked by alias); 5 Feb 2020 01:03:01 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 91744 invoked by uid 89); 5 Feb 2020 01:03:00 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=UD:buf, __typeof__, HContent-Transfer-Encoding:8bit X-HELO: esa3.hgst.iphmx.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1580864579; x=1612400579; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=OujJi+dlnQTkmMvDJFLgoPF+DMAKTjZZRTHyzLwxEYI=; b=RBiOtc4OZx/x9+pipwFk1Dzp528+HURMO8srDvelQWwRMriocpoIUZFo eGHsM07GA1wOD+e+ZbHBZGrmpWs5pTqePjY9tl6IGhrZzag1RFWpl2qaa SNg+I1OMeHKA7E9fG+A0wv8xlEQJfa0gLq5SXRzFGq64Ev3Aw5q6RcYtQ 1j3EEKV2QdjR1ddknDJzD9RspMaYPcfhtzGudali3X5180NjI7J63Lqsx 2q8kDx1o2JgEPb9btpGtCsosRWUOqpK2hii/0SuagMCYJYhm4mxyczmN8 yxgba3OUpSzsn2h0NucvrV2GAXVJJNxouixXiJkhoFJiXZFtHaepZZubn Q==; IronPort-SDR: ArFwlfVDxhBxpSsx5lH9i6Gje1DQdHHIGfupEevSlfWPQ4cEP8c7bArS3tTafQdCiIejr89QSv RB1lz3LYkPJdvRfce31xWWCGRiW4JIbOU/QTQIaykds8BRJ3BTzBUyVLiNQXcAH5lEKXQoGNzR 8b2OgNHYrjjC+I6CDOl2XDVRq/vja52TZPD1VHnCZpVxm+FrI/890kOT2cUb5cQdrSVX5r//4g LoZqBz7CNwJJ8cQObqc8U+yDDQOyihjtxjutQcRMN/zGWwaN193deVSt1mbW9JUCC7cwjMoH3l iIA= IronPort-SDR: 45SHTYJBNnjtKGveCrn5o/PCR20PkQksdMIO4eRouvvpPTn0JX8ah0mBSjhVGNfbUAJ8EllLDN xfzgtNd6yEUcJe1yPVnnS5VquhZIxPmIX4Tqe7xu6GhM9lUbeR9LSGitwY0VWNkTQgZvV0t0Xl BOceMvKZavshhAv3gnw/EKDhL9Fp5MEQmn1cthGNC0Zqs8ZEbxp3Pq46i3nPtE/7jznwst/csx J17jdxueVLhXkUMj/7+UbQsK6iF8apCBOjWpIDWLpvq3DUAnbmUy+b98vJw1c8dzibZR1KFll8 8Qzmgc9ZcyNSFzU8xWFtf51S IronPort-SDR: m+x/eHI2Hq9khAuGTqI6YxGD5wECJb6Ja1WqQTCHq5A2ECrayVDCh+AtMYm/QZy9pr5HS4mChS by9yRaR2LdP696WLR2495YjVYQntHi0kPs15bezC666FVaL2JkGMioJJgXn2YDSp3HxHOvK40y H39UDR69IMLYnpweYU2X/qWE4Jqs2NtJ2O9E5QEcvqGvxc3DWlsRJP9svMCmtjfuDPudcJXSyg +1IqDWwU9lVgfDuLyLC2q/8SF2FSxanlVzgHiyW8a/4MttR6knplosRW5JLlNif6ikSNk55WZw Y0U= WDCIronportException: Internal From: Alistair Francis To: libc-alpha@sourceware.org Cc: alistair23@gmail.com, Alistair Francis Subject: [PATCH v2] sysv: linux: Pass 64-bit version of semctl syscall Date: Tue, 4 Feb 2020 16:56:10 -0800 Message-Id: <20200205005610.31739-1-alistair.francis@wdc.com> MIME-Version: 1.0 The semctl_syscall() function passes a union semun to the kernel. The union includes struct semid_ds as a member. On 32-bit architectures the Linux kernel provides a *_high version of the 32-bit sem_otime and sem_ctime values. These can be combined to get a 64-bit version of the time. This patch adjusts the union semun to include a struct __semid_ds32 which supports the *_high versions of sem_otime and sem_ctime. For 32-bit systems with a 64-bit time_t this can be used to get a 64-bit time from the two 32-bit values. --- v2: - Fix the HPPA error - Simplfy the code changes include/sys/sem.h | 35 +++++++++++++++++++ sysdeps/unix/sysv/linux/bits/sem-pad.h | 1 + sysdeps/unix/sysv/linux/hppa/bits/sem-pad.h | 2 ++ sysdeps/unix/sysv/linux/mips/bits/sem-pad.h | 2 ++ .../unix/sysv/linux/powerpc/bits/sem-pad.h | 2 ++ sysdeps/unix/sysv/linux/semctl.c | 23 +++++++++--- sysdeps/unix/sysv/linux/sparc/bits/sem-pad.h | 2 ++ sysdeps/unix/sysv/linux/x86/bits/sem-pad.h | 1 + 8 files changed, 64 insertions(+), 4 deletions(-) diff --git a/include/sys/sem.h b/include/sys/sem.h index 69fdf1f752..70b83127cb 100644 --- a/include/sys/sem.h +++ b/include/sys/sem.h @@ -5,5 +5,40 @@ __typeof__ (semtimedop) __semtimedop attribute_hidden; +# endif + +# ifdef __SEMID_DS_HIGH +# if defined (__SEMID_DS_HIGH_END) +struct __semid_ds32 { + struct ipc_perm sem_perm; /* permissions .. see ipc.h */ + __syscall_ulong_t sem_otime; /* last semop time */ + __syscall_ulong_t sem_ctime; /* last change time */ + __syscall_ulong_t sem_nsems; /* no. of semaphores in array */ + __syscall_ulong_t sem_otime_high; + __syscall_ulong_t sem_ctime_high; +}; +# elif defined (__SEMID_DS_HIGH_SWAP) +struct __semid_ds32 { + struct ipc_perm sem_perm; /* operation permission struct */ + __syscall_ulong_t sem_otime_high; /* last semop() time high */ + __syscall_ulong_t sem_otime; /* last semop() time */ + __syscall_ulong_t sem_ctime_high; /* last time changed by semctl() high */ + __syscall_ulong_t sem_ctime; /* last time changed by semctl() */ + __syscall_ulong_t sem_nsems; /* number of semaphores in set */ + __syscall_ulong_t __glibc_reserved3; + __syscall_ulong_t __glibc_reserved4; +}; +# else +struct __semid_ds32 { + struct ipc_perm sem_perm; /* operation permission struct */ + __syscall_ulong_t sem_otime; /* last semop() time */ + __syscall_ulong_t sem_otime_high; /* last semop() time high */ + __syscall_ulong_t sem_ctime; /* last time changed by semctl() */ + __syscall_ulong_t sem_ctime_high; /* last time changed by semctl() high */ + __syscall_ulong_t sem_nsems; /* number of semaphores in set */ + __syscall_ulong_t __glibc_reserved3; + __syscall_ulong_t __glibc_reserved4; +}; +# endif # endif #endif diff --git a/sysdeps/unix/sysv/linux/bits/sem-pad.h b/sysdeps/unix/sysv/linux/bits/sem-pad.h index 566ce039cc..18235e56df 100644 --- a/sysdeps/unix/sysv/linux/bits/sem-pad.h +++ b/sysdeps/unix/sysv/linux/bits/sem-pad.h @@ -31,3 +31,4 @@ #define __SEM_PAD_AFTER_TIME (__TIMESIZE == 32) #define __SEM_PAD_BEFORE_TIME 0 +#define __SEMID_DS_HIGH (__WORDSIZE == 32) diff --git a/sysdeps/unix/sysv/linux/hppa/bits/sem-pad.h b/sysdeps/unix/sysv/linux/hppa/bits/sem-pad.h index ee0332325b..62580792b3 100644 --- a/sysdeps/unix/sysv/linux/hppa/bits/sem-pad.h +++ b/sysdeps/unix/sysv/linux/hppa/bits/sem-pad.h @@ -24,3 +24,5 @@ #define __SEM_PAD_AFTER_TIME 0 #define __SEM_PAD_BEFORE_TIME (__TIMESIZE == 32) +#define __SEMID_DS_HIGH (__WORDSIZE == 32) +#define __SEMID_DS_HIGH_SWAP (__WORDSIZE == 32) diff --git a/sysdeps/unix/sysv/linux/mips/bits/sem-pad.h b/sysdeps/unix/sysv/linux/mips/bits/sem-pad.h index 4c581f7694..12f2bd9c62 100644 --- a/sysdeps/unix/sysv/linux/mips/bits/sem-pad.h +++ b/sysdeps/unix/sysv/linux/mips/bits/sem-pad.h @@ -22,3 +22,5 @@ #define __SEM_PAD_AFTER_TIME 0 #define __SEM_PAD_BEFORE_TIME 0 +#define __SEMID_DS_HIGH (__WORDSIZE == 32) +#define __SEMID_DS_HIGH_END (__WORDSIZE == 32) diff --git a/sysdeps/unix/sysv/linux/powerpc/bits/sem-pad.h b/sysdeps/unix/sysv/linux/powerpc/bits/sem-pad.h index 42d8827906..a13ca5f6bd 100644 --- a/sysdeps/unix/sysv/linux/powerpc/bits/sem-pad.h +++ b/sysdeps/unix/sysv/linux/powerpc/bits/sem-pad.h @@ -24,3 +24,5 @@ #define __SEM_PAD_AFTER_TIME 0 #define __SEM_PAD_BEFORE_TIME (__TIMESIZE == 32) +#define __SEMID_DS_HIGH (__WORDSIZE == 32) +#define __SEMID_DS_HIGH_SWAP (__WORDSIZE == 32) diff --git a/sysdeps/unix/sysv/linux/semctl.c b/sysdeps/unix/sysv/linux/semctl.c index 0c3eb0932f..8dcb012b0b 100644 --- a/sysdeps/unix/sysv/linux/semctl.c +++ b/sysdeps/unix/sysv/linux/semctl.c @@ -28,6 +28,9 @@ union semun { int val; /* value for SETVAL */ struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ +#ifdef __SEMID_DS_HIGH + struct __semid_ds32 *buf32; /* buffer for IPC_STAT & IPC_SET on 32-bit systems */ +#endif unsigned short int *array; /* array for GETALL & SETALL */ struct seminfo *__buf; /* buffer for IPC_INFO */ }; @@ -43,13 +46,25 @@ union semun static int semctl_syscall (int semid, int semnum, int cmd, union semun arg) { + int ret; #ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS - return INLINE_SYSCALL_CALL (semctl, semid, semnum, cmd | __IPC_64, - arg.array); + ret = INLINE_SYSCALL_CALL (semctl, semid, semnum, cmd | __IPC_64, + arg.array); #else - return INLINE_SYSCALL_CALL (ipc, IPCOP_semctl, semid, semnum, cmd | __IPC_64, - SEMCTL_ARG_ADDRESS (arg)); + ret = INLINE_SYSCALL_CALL (ipc, IPCOP_semctl, semid, semnum, cmd | __IPC_64, + SEMCTL_ARG_ADDRESS (arg)); #endif +#ifdef __SEMID_DS_HIGH +/* If we aren't going to overflow the time_t sem_ctime/sem_otime set it */ +# if __TIMESIZE == 64 && __WORDSIZE == 32 + if (ret == 0) + { + arg.buf->sem_ctime = arg.buf32->sem_ctime | ((time_t) arg.buf32->sem_ctime_high << 32); + arg.buf->sem_otime = arg.buf32->sem_otime | ((time_t) arg.buf32->sem_otime_high << 32); + } +# endif +#endif + return ret; } int diff --git a/sysdeps/unix/sysv/linux/sparc/bits/sem-pad.h b/sysdeps/unix/sysv/linux/sparc/bits/sem-pad.h index 5f4e214d12..79655b8149 100644 --- a/sysdeps/unix/sysv/linux/sparc/bits/sem-pad.h +++ b/sysdeps/unix/sysv/linux/sparc/bits/sem-pad.h @@ -24,3 +24,5 @@ #define __SEM_PAD_AFTER_TIME 0 #define __SEM_PAD_BEFORE_TIME (__TIMESIZE == 32) +#define __SEMID_DS_HIGH (__WORDSIZE == 32) +#define __SEMID_DS_HIGH_SWAP (__WORDSIZE == 32) diff --git a/sysdeps/unix/sysv/linux/x86/bits/sem-pad.h b/sysdeps/unix/sysv/linux/x86/bits/sem-pad.h index 102e226997..db397857e7 100644 --- a/sysdeps/unix/sysv/linux/x86/bits/sem-pad.h +++ b/sysdeps/unix/sysv/linux/x86/bits/sem-pad.h @@ -22,3 +22,4 @@ #define __SEM_PAD_AFTER_TIME 1 #define __SEM_PAD_BEFORE_TIME 0 +#define __SEMID_DS_HIGH 1