diff mbox

[v2,02/16] Consolidate Linux msgctl implementation

Message ID 1478114813-3526-3-git-send-email-adhemerval.zanella@linaro.org
State New
Headers show

Commit Message

Adhemerval Zanella Netto Nov. 2, 2016, 7:26 p.m. UTC
Changes from previous version:

  - Use __ASSUME_SYSVIPC_SYSCALL instead of __NR_syscall to issue the
    wired syscall or the ipc one.

--

This patch consolidates the msgctl Linux implementation in only
one default file, sysdeps/unix/sysv/linux/msgctl.c.  If tries to use
the direct syscall if it is supported, otherwise will use the old ipc
multiplex mechanism.

The patch also simplify header inclusion and reorganize internal
compat symbol to be built only if old ipc is defined.

Checked on x86_64, i686, powerpc64le, aarch64, and armhf.

	* sysdeps/unix/sysv/linux/alpha/msgctl.c: Remove file.
	* sysdeps/unix/sysv/linux/arm/msgctl.c: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/msgctl.c: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/msgctl.c: Use default
	implementation.
	* sysdeps/unix/sysv/linux/msgctl.c (__new_msgctl): Use msgctl syscall
	if defined.
---
 ChangeLog                                    |  8 ++++++
 sysdeps/unix/sysv/linux/alpha/msgctl.c       |  1 -
 sysdeps/unix/sysv/linux/arm/msgctl.c         | 33 ----------------------
 sysdeps/unix/sysv/linux/microblaze/msgctl.c  |  1 -
 sysdeps/unix/sysv/linux/mips/mips64/msgctl.c | 17 ++---------
 sysdeps/unix/sysv/linux/msgctl.c             | 42 +++++++++++++---------------
 6 files changed, 30 insertions(+), 72 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/alpha/msgctl.c
 delete mode 100644 sysdeps/unix/sysv/linux/arm/msgctl.c
 delete mode 100644 sysdeps/unix/sysv/linux/microblaze/msgctl.c

-- 
2.7.4

Comments

Adhemerval Zanella Netto Nov. 4, 2016, 5:03 p.m. UTC | #1
On 04/11/2016 13:33, Yury Norov wrote:
> On Wed, Nov 02, 2016 at 05:26:39PM -0200, Adhemerval Zanella wrote:

>> Changes from previous version:

>>

>>   - Use __ASSUME_SYSVIPC_SYSCALL instead of __NR_syscall to issue the

>>     wired syscall or the ipc one.

>>

>> --

>>

>> This patch consolidates the msgctl Linux implementation in only

>> one default file, sysdeps/unix/sysv/linux/msgctl.c.  If tries to use

>> the direct syscall if it is supported, otherwise will use the old ipc

>> multiplex mechanism.

>>

>> The patch also simplify header inclusion and reorganize internal

>> compat symbol to be built only if old ipc is defined.

>>

>> Checked on x86_64, i686, powerpc64le, aarch64, and armhf.

>>

>> 	* sysdeps/unix/sysv/linux/alpha/msgctl.c: Remove file.

>> 	* sysdeps/unix/sysv/linux/arm/msgctl.c: Likewise.

>> 	* sysdeps/unix/sysv/linux/microblaze/msgctl.c: Likewise.

>> 	* sysdeps/unix/sysv/linux/mips/mips64/msgctl.c: Use default

>> 	implementation.

>> 	* sysdeps/unix/sysv/linux/msgctl.c (__new_msgctl): Use msgctl syscall

>> 	if defined.

>> ---

>>  ChangeLog                                    |  8 ++++++

>>  sysdeps/unix/sysv/linux/alpha/msgctl.c       |  1 -

>>  sysdeps/unix/sysv/linux/arm/msgctl.c         | 33 ----------------------

>>  sysdeps/unix/sysv/linux/microblaze/msgctl.c  |  1 -

>>  sysdeps/unix/sysv/linux/mips/mips64/msgctl.c | 17 ++---------

>>  sysdeps/unix/sysv/linux/msgctl.c             | 42 +++++++++++++---------------

>>  6 files changed, 30 insertions(+), 72 deletions(-)

>>  delete mode 100644 sysdeps/unix/sysv/linux/alpha/msgctl.c

>>  delete mode 100644 sysdeps/unix/sysv/linux/arm/msgctl.c

>>  delete mode 100644 sysdeps/unix/sysv/linux/microblaze/msgctl.c

> 

> Hi Adhemerval, 

> 

> I'm testing your series with aarch64/ilp32 + LTP, and see regressions:

> msgctl01                       FAIL       1

> msgctl06                       FAIL       1

> msgsnd01                       FAIL       1

> semctl01                       FAIL       1

> semctl07                       FAIL       1

> semget01                       FAIL       1

> shmat01                        FAIL       1

> shmctl01                       FAIL       1

> shmget01                       FAIL       1

> 

> Regarding msgctl. objdump for libc.so shows that syscall is generated

> from stub in sysdeps/unix/sysv/linux/generic/syscalls.list.

> 000d0e80 <msgctl>:

> #else

> 

> /* This is a "normal" system call stub: if there is an error,

>    it returns -1 and sets errno.  */

> 

> T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)

>   d0e80:       d2801768        mov     x8, #0xbb

>   // #187

>   d0e84:       d4000001        svc     #0x0

>   d0e88:       b13ffc1f        cmn     x0, #0xfff

>   d0e8c:       54000042        b.cs    d0e94

> <msgctl+0x14>

>         ret

>   d0e90:       d65f03c0        ret

> T_PSEUDO_END (SYSCALL_SYMBOL)

>   d0e94:       17fd194b        b

>   173c0 <__GI___syscall_error>

>   d0e98:       d503201f        nop

>   d0e9c:       d503201f        nop

> 

> For aarch64/ilp32 to drop custom implementation, we need 

> to force __IPC_64, and so remove stubs for msgctl, semctl and shmctl

> to let glibc find proper implementation under sysv/linux.

> 

> The minimal fix for my regression is below. Though, I'm not sure that it's

> complete, and that it will not affect other ports. BTW, grepping for

> msgctl in syscalls.list files shows that they has outdated comment

> which should be fixed in this series too - in arm, microblaze and mips64 ports.

> 

> # Semaphore and shm system calls.  msgctl, shmctl, and semctl have C

> # wrappers (to set __IPC_64).

> 

> Yury.

> 

> diff --git a/sysdeps/unix/sysv/linux/generic/syscalls.list b/sysdeps/unix/sysv/linux/generic/syscalls.list

> index 5993ab4..459892d 100644

> --- a/sysdeps/unix/sysv/linux/generic/syscalls.list

> +++ b/sysdeps/unix/sysv/linux/generic/syscalls.list

> @@ -2,15 +2,12 @@

>  

>  # SysV APIs

>  msgget		-	msgget		i:ii	__msgget	msgget

> -msgctl		-	msgctl		i:iip	__msgctl	msgctl

>  msgrcv		-	msgrcv		Ci:ibnii __msgrcv	msgrcv

>  msgsnd		-	msgsnd		Ci:ibni	__msgsnd	msgsnd

>  semget		-	semget		i:iii	__semget	semget

> -semctl		-	semctl		i:iiii	__semctl	semctl

>  semtimedop	-	semtimedop	i:ipip	semtimedop

>  semop		-	semop		i:ipi	__semop		semop

>  shmget		-	shmget		i:iii	__shmget	shmget

> -shmctl		-	shmctl		i:iip	__shmctl	shmctl

>  shmat		-	shmat		i:ipi	__shmat		shmat

>  shmdt		-	shmdt		i:s	__shmdt		shmdt


Yes, auto-generation syscall won't add the __IPC_64 required for
some architectures.  And that's why I have added in default 
implementation, since kernel will just ignore for architecture
that do not require it.

And I think by removing them from generic syscalls.list seems
reasonable, since for some architecture. I will change my
local branch accordingly.
diff mbox

Patch

diff --git a/sysdeps/unix/sysv/linux/alpha/msgctl.c b/sysdeps/unix/sysv/linux/alpha/msgctl.c
deleted file mode 100644
index d65a5b9..0000000
--- a/sysdeps/unix/sysv/linux/alpha/msgctl.c
+++ /dev/null
@@ -1 +0,0 @@ 
-#include <sysdeps/unix/sysv/linux/arm/msgctl.c>
diff --git a/sysdeps/unix/sysv/linux/arm/msgctl.c b/sysdeps/unix/sysv/linux/arm/msgctl.c
deleted file mode 100644
index 83c6744..0000000
--- a/sysdeps/unix/sysv/linux/arm/msgctl.c
+++ /dev/null
@@ -1,33 +0,0 @@ 
-/* Copyright (C) 1995-2016 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library.  If not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <sys/msg.h>
-#include <ipc_priv.h>
-#include <sysdep.h>
-#include <sys/syscall.h>
-
-
-int
-__new_msgctl (int msqid, int cmd, struct msqid_ds *buf)
-{
-  return INLINE_SYSCALL (msgctl, 3, msqid, cmd | __IPC_64, buf);
-}
-
-#include <shlib-compat.h>
-versioned_symbol (libc, __new_msgctl, msgctl, GLIBC_2_2);
diff --git a/sysdeps/unix/sysv/linux/microblaze/msgctl.c b/sysdeps/unix/sysv/linux/microblaze/msgctl.c
deleted file mode 100644
index d65a5b9..0000000
--- a/sysdeps/unix/sysv/linux/microblaze/msgctl.c
+++ /dev/null
@@ -1 +0,0 @@ 
-#include <sysdeps/unix/sysv/linux/arm/msgctl.c>
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/msgctl.c b/sysdeps/unix/sysv/linux/mips/mips64/msgctl.c
index c4dc7ff..f43479f 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/msgctl.c
+++ b/sysdeps/unix/sysv/linux/mips/mips64/msgctl.c
@@ -15,18 +15,5 @@ 
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <sys/msg.h>
-#include <ipc_priv.h>
-#include <sysdep.h>
-
-int __msgctl (int msqid, int cmd, struct msqid_ds *buf);
-
-int
-__msgctl (int msqid, int cmd, struct msqid_ds *buf)
-{
-  return INLINE_SYSCALL (msgctl, 3, msqid, cmd | __IPC_64, buf);
-}
-
-#include <shlib-compat.h>
-versioned_symbol (libc, __msgctl, msgctl, GLIBC_2_0);
+#define DEFAULT_VERSION GLIBC_2_0
+#include <sysdeps/unix/sysv/linux/msgctl.c>
diff --git a/sysdeps/unix/sysv/linux/msgctl.c b/sysdeps/unix/sysv/linux/msgctl.c
index e48fbb3..3316670 100644
--- a/sysdeps/unix/sysv/linux/msgctl.c
+++ b/sysdeps/unix/sysv/linux/msgctl.c
@@ -16,17 +16,31 @@ 
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
 #include <sys/msg.h>
 #include <ipc_priv.h>
-
 #include <sysdep.h>
-#include <string.h>
-#include <sys/syscall.h>
 #include <shlib-compat.h>
+#include <errno.h>
+
+#ifndef DEFAULT_VERSION
+# define DEFAULT_VERSION GLIBC_2_2
+#endif
 
-#include <kernel-features.h>
+int
+__new_msgctl (int msqid, int cmd, struct msqid_ds *buf)
+{
+#ifdef __ASSUME_SYSVIPC_SYSCALL
+  return INLINE_SYSCALL_CALL (msgctl, msqid, cmd | __IPC_64, buf);
+#else
+  return INLINE_SYSCALL_CALL (ipc, IPCOP_msgctl, msqid, cmd | __IPC_64, 0,
+			      buf);
+#endif
+}
+versioned_symbol (libc, __new_msgctl, msgctl, DEFAULT_VERSION);
 
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2) \
+    && defined (__NR_ipc)
 struct __old_msqid_ds
 {
   struct __old_ipc_perm msg_perm;	/* structure describing operation permission */
@@ -44,27 +58,11 @@  struct __old_msqid_ds
   __ipc_pid_t msg_lrpid;		/* pid of last msgrcv() */
 };
 
-/* Allows to control internal state and destruction of message queue
-   objects.  */
-#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
-int __old_msgctl (int, int, struct __old_msqid_ds *);
-#endif
-int __new_msgctl (int, int, struct msqid_ds *);
-
-#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
 int
 attribute_compat_text_section
 __old_msgctl (int msqid, int cmd, struct __old_msqid_ds *buf)
 {
-  return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl, msqid, cmd, 0, buf);
+  return INLINE_SYSCALL_CALL (ipc, IPCOP_msgctl, msqid, cmd, 0, buf);
 }
 compat_symbol (libc, __old_msgctl, msgctl, GLIBC_2_0);
 #endif
-
-int
-__new_msgctl (int msqid, int cmd, struct msqid_ds *buf)
-{
-  return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl, msqid, cmd | __IPC_64, 0, buf);
-}
-
-versioned_symbol (libc, __new_msgctl, msgctl, GLIBC_2_2);