From patchwork Wed May 13 15:22:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 39235 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E34EC393EC31; Wed, 13 May 2020 15:31:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E34EC393EC31 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1589383877; bh=4NOGTnnvUMinEPa+kDWOBG2SUmTWit1UbFdmqTBBvE0=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=JbU0DvfCMyUJr0BD4915sALm6KSI9ETFqzijwQbLUpJl4/Y+l1HPcImcwo6qbE6sb 5D/lKskw+iscVdTwgQyVyh46xYPYtxlFKBcpbvheadB3Bie29NZGhntjlZ7lF80WCu SkURJaqqR3QU5FcVLIAX1pgH4YkrMDnL1by8Bd8Y= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by sourceware.org (Postfix) with ESMTPS id 90373393EC31 for ; Wed, 13 May 2020 15:31:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 90373393EC31 IronPort-SDR: mktb+E+HX85IMRbMMxiztGilGg0nfP1fVGQ/hvR0gmWOyhuFChg33EVRM6gfu8M5vfhXgW/NrH /AUUD+8XljdX/psG2fxQvYAFY4Xz77tCw1euDUVGCW2OCmkLmZ/fKWf+daGwmOKodkTQj1jBNm OrH4H6pB51poY67ktdg9d/gssNfOzH/DmQlSc4YR1mfU5WeVRrGa//f072mMVCbFl3aEPbNJUi wn9hOSEcTXexF04/pX0C3Np64DeVjDiRJpVQR9CS/YciZXa9O31YERLK+BHASbueSkwk1M1yHV yYQ= X-IronPort-AV: E=Sophos;i="5.73,388,1583164800"; d="scan'208";a="139022187" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 13 May 2020 23:31:11 +0800 IronPort-SDR: PiWoEqbYJds0DakRd/SdSl5XtA6idWUCtINP5mnrQWulNV/P82M8hp2C9DNPxgvueCfJPku5Nx 4fq/Xbe++3wguklugc3Yhyj9xbBJgbQzM= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2020 08:21:25 -0700 IronPort-SDR: LvKGMGzDeQldPdQAKjOVAMYzTA/ExajYCSZe/t2MXjwaroiBPMl/XAIrePlrcxMaeCAPdhlxUI rqKANegVM7Jg== WDCIronportException: Internal Received: from usa002611.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.57.103]) by uls-op-cesaip02.wdc.com with ESMTP; 13 May 2020 08:31:10 -0700 To: libc-alpha@sourceware.org Subject: [PATCH v8 2/2] sysv: linux: Pass 64-bit version of semctl syscall Date: Wed, 13 May 2020 08:22:49 -0700 Message-Id: <20200513152249.5103-3-alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513152249.5103-1-alistair.francis@wdc.com> References: <20200513152249.5103-1-alistair.francis@wdc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-16.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alistair Francis via Libc-alpha From: Alistair Francis Reply-To: Alistair Francis Cc: stepan@golosunov.pp.ru, Alistair Francis Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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 struct semid_ds to support 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. Due to alignment differences between 64-bit and 32-bit variables we also need to set nsems to ensure it's correct. --- sysdeps/unix/sysv/linux/ipc_priv.h | 4 +++ sysdeps/unix/sysv/linux/semctl.c | 50 +++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/sysdeps/unix/sysv/linux/ipc_priv.h b/sysdeps/unix/sysv/linux/ipc_priv.h index 15a6e683a4..a1a7cacd17 100644 --- a/sysdeps/unix/sysv/linux/ipc_priv.h +++ b/sysdeps/unix/sysv/linux/ipc_priv.h @@ -43,6 +43,10 @@ struct __old_ipc_perm unsigned short int __seq; /* Sequence number. */ }; +#define __IPC_TIME64 \ + (__WORDSIZE == 32 && __TIMESIZE == 64 \ + && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32)) + #define SEMCTL_ARG_ADDRESS(__arg) &__arg.array #define MSGRCV_ARGS(__msgp, __msgtyp) \ diff --git a/sysdeps/unix/sysv/linux/semctl.c b/sysdeps/unix/sysv/linux/semctl.c index 30571af49f..3ed2af89d1 100644 --- a/sysdeps/unix/sysv/linux/semctl.c +++ b/sysdeps/unix/sysv/linux/semctl.c @@ -22,6 +22,7 @@ #include #include #include +#include #include /* For __kernel_mode_t. */ /* Define a `union semun' suitable for Linux here. */ @@ -44,13 +45,54 @@ union semun static int semctl_syscall (int semid, int semnum, int cmd, union semun arg) { + int ret; +#if __IPC_TIME64 + /* A temporary buffer is used to avoid both an issue where the export + semid_ds might not follow the kernel's expected layout (due +   to {o,c}time{_high} alignment in 64-bit time case) and the issue where +    some kernel versions might not clear the high bits when returning +    then {o,c}time{_high} information. */ + struct __semid_ds32 tmp; + struct semid_ds *orig; + bool restore = false; + if (cmd == IPC_STAT || cmd == SEM_STAT || cmd == SEM_STAT_ANY) + { + tmp = (struct __semid_ds32) { + .sem_perm = arg.buf->sem_perm, + .sem_otime = arg.buf->sem_otime, + .sem_otime_high = arg.buf->sem_otime >> 32, + .sem_ctime = arg.buf->sem_ctime, + .sem_ctime_high = arg.buf->sem_ctime >> 32, + .sem_nsems = arg.buf->sem_nsems, + }; + orig = arg.buf; + arg.buf = (struct semid_ds*) &tmp; + restore = true; + } +#endif + #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 + +#if __IPC_TIME64 + if (ret >= 0 && restore) + { + arg.buf = orig; + arg.buf->sem_perm = tmp.sem_perm; + arg.buf->sem_otime = tmp.sem_otime + | ((__time64_t) tmp.sem_otime_high << 32); + arg.buf->sem_ctime = tmp.sem_ctime + | ((__time64_t) tmp.sem_ctime_high << 32); + arg.buf->sem_nsems = tmp.sem_nsems; + } +#endif + + return ret; } int