[22/30] Linux: Assume and consolidate getsockname wire-up syscall

Message ID 20221019221433.1082017-23-adhemerval.zanella@linaro.org
State Superseded
Headers
Series Remove Linux generic sysdep |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Adhemerval Zanella Netto Oct. 19, 2022, 10:14 p.m. UTC
  And disable if kernel does not support it.

Checked on x86_64-linux-gnu and i686-linux-gnu.
---
 sysdeps/unix/sysv/linux/generic/syscalls.list        | 1 -
 sysdeps/unix/sysv/linux/getsockname.c                | 7 +------
 sysdeps/unix/sysv/linux/i386/kernel-features.h       | 2 +-
 sysdeps/unix/sysv/linux/kernel-features.h            | 1 +
 sysdeps/unix/sysv/linux/m68k/kernel-features.h       | 2 +-
 sysdeps/unix/sysv/linux/microblaze/kernel-features.h | 1 -
 sysdeps/unix/sysv/linux/powerpc/kernel-features.h    | 1 -
 sysdeps/unix/sysv/linux/s390/kernel-features.h       | 2 +-
 sysdeps/unix/sysv/linux/sh/kernel-features.h         | 1 -
 9 files changed, 5 insertions(+), 13 deletions(-)
  

Comments

Joseph Myers Oct. 20, 2022, 12:01 a.m. UTC | #1
On Wed, 19 Oct 2022, Adhemerval Zanella via Libc-alpha wrote:

> And disable if kernel does not support it.

How did you determine what #undefs to add?  I'd have expected a #undef for 
32-bit SPARC at least (where getpeername and getsockname were only added 
to the compat syscall table for SPARC in 4.20 (Linux commit 
1f2b5b8e2df4591fbca430aff9c5a072dcc0f408)).
  
Adhemerval Zanella Netto Oct. 20, 2022, 6:12 p.m. UTC | #2
On 19/10/22 21:01, Joseph Myers wrote:
> On Wed, 19 Oct 2022, Adhemerval Zanella via Libc-alpha wrote:
> 
>> And disable if kernel does not support it.
> 
> How did you determine what #undefs to add?  I'd have expected a #undef for 
> 32-bit SPARC at least (where getpeername and getsockname were only added 
> to the compat syscall table for SPARC in 4.20 (Linux commit 
> 1f2b5b8e2df4591fbca430aff9c5a072dcc0f408)).
> 

I wrongly assumed the comments on sparc kernel-features.h for socket support
was up to date, which does not seems the case. I check the kernel history and
fix it.
  
Carlos O'Donell Dec. 6, 2022, 4:18 p.m. UTC | #3
On 10/19/22 18:14, Adhemerval Zanella via Libc-alpha wrote:
> And disable if kernel does not support it.
> 
> Checked on x86_64-linux-gnu and i686-linux-gnu.

LGTM.

No regressions on x86_64 and i686.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>

> ---
>  sysdeps/unix/sysv/linux/generic/syscalls.list        | 1 -
>  sysdeps/unix/sysv/linux/getsockname.c                | 7 +------
>  sysdeps/unix/sysv/linux/i386/kernel-features.h       | 2 +-
>  sysdeps/unix/sysv/linux/kernel-features.h            | 1 +
>  sysdeps/unix/sysv/linux/m68k/kernel-features.h       | 2 +-
>  sysdeps/unix/sysv/linux/microblaze/kernel-features.h | 1 -
>  sysdeps/unix/sysv/linux/powerpc/kernel-features.h    | 1 -
>  sysdeps/unix/sysv/linux/s390/kernel-features.h       | 2 +-
>  sysdeps/unix/sysv/linux/sh/kernel-features.h         | 1 -
>  9 files changed, 5 insertions(+), 13 deletions(-)
> 
> diff --git a/sysdeps/unix/sysv/linux/generic/syscalls.list b/sysdeps/unix/sysv/linux/generic/syscalls.list
> index 706893f245..a5bb00a3e4 100644
> --- a/sysdeps/unix/sysv/linux/generic/syscalls.list
> +++ b/sysdeps/unix/sysv/linux/generic/syscalls.list
> @@ -1,6 +1,5 @@
>  # File name	Caller	Syscall name	# args	Strong name	Weak names
>  
>  # Socket APIs
> -getsockname	-	getsockname	i:ipp	__getsockname	getsockname

OK. Remove wrapper.

>  getpeername	-	getpeername	i:ipp	__getpeername	getpeername
>  shutdown	-	shutdown	i:ii	__shutdown	shutdown
> diff --git a/sysdeps/unix/sysv/linux/getsockname.c b/sysdeps/unix/sysv/linux/getsockname.c
> index d0718c2aaf..8350b800fe 100644
> --- a/sysdeps/unix/sysv/linux/getsockname.c
> +++ b/sysdeps/unix/sysv/linux/getsockname.c
> @@ -15,19 +15,14 @@
>     License along with the GNU C Library; if not, see
>     <https://www.gnu.org/licenses/>.  */
>  
> -#include <errno.h>
> -#include <signal.h>
>  #include <sys/socket.h>
> -
>  #include <socketcall.h>
> -#include <kernel-features.h>
> -#include <sys/syscall.h>
>  
>  int
>  __getsockname (int fd, __SOCKADDR_ARG addr, socklen_t *len)
>  {
>  #ifdef __ASSUME_GETSOCKNAME_SYSCALL
> -  return INLINE_SYSCALL (getsockname, 3, fd, addr.__sockaddr__, len);
> +  return INLINE_SYSCALL_CALL (getsockname, fd, addr.__sockaddr__, len);

OK.

>  #else
>    return SOCKETCALL (getsockname, fd, addr.__sockaddr__, len);
>  #endif
> diff --git a/sysdeps/unix/sysv/linux/i386/kernel-features.h b/sysdeps/unix/sysv/linux/i386/kernel-features.h
> index a79ec679cc..f294380215 100644
> --- a/sysdeps/unix/sysv/linux/i386/kernel-features.h
> +++ b/sysdeps/unix/sysv/linux/i386/kernel-features.h
> @@ -19,7 +19,6 @@
>  
>  /* Direct socketcalls available with kernel 4.3.  */
>  #if __LINUX_KERNEL_VERSION >= 0x040300
> -# define __ASSUME_GETSOCKNAME_SYSCALL        1
>  # define __ASSUME_GETPEERNAME_SYSCALL        1
>  # define __ASSUME_SHUTDOWN_SYSCALL           1
>  #endif
> @@ -41,6 +40,7 @@
>  # undef __ASSUME_SOCKET_SYSCALL
>  # undef __ASSUME_SOCKETPAIR_SYSCALL
>  # undef __ASSUME_LISTEN_SYSCALL
> +# undef __ASSUME_GETSOCKNAME_SYSCALL
>  #endif
>  
>  /* i686 only supports ipc syscall before 5.1.  */
> diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
> index d1769b2d99..6fb99f5c35 100644
> --- a/sysdeps/unix/sysv/linux/kernel-features.h
> +++ b/sysdeps/unix/sysv/linux/kernel-features.h
> @@ -83,6 +83,7 @@
>  #define __ASSUME_SOCKET_SYSCALL		1
>  #define __ASSUME_SOCKETPAIR_SYSCALL	1
>  #define __ASSUME_LISTEN_SYSCALL		1
> +#define __ASSUME_GETSOCKNAME_SYSCALL	1
>  
>  /* Support for SysV IPC through wired syscalls.  All supported architectures
>     either support ipc syscall and/or all the ipc correspondent syscalls.  */
> diff --git a/sysdeps/unix/sysv/linux/m68k/kernel-features.h b/sysdeps/unix/sysv/linux/m68k/kernel-features.h
> index a65fa63c5e..898c24ba62 100644
> --- a/sysdeps/unix/sysv/linux/m68k/kernel-features.h
> +++ b/sysdeps/unix/sysv/linux/m68k/kernel-features.h
> @@ -19,7 +19,6 @@
>  
>  /* Direct socketcalls available with kernel 4.3.  */
>  #if __LINUX_KERNEL_VERSION >= 0x040300
> -# define __ASSUME_GETSOCKNAME_SYSCALL        1
>  # define __ASSUME_GETPEERNAME_SYSCALL        1
>  # define __ASSUME_SHUTDOWN_SYSCALL           1
>  #endif
> @@ -43,6 +42,7 @@
>  # undef __ASSUME_SOCKET_SYSCALL
>  # undef __ASSUME_SOCKETPAIR_SYSCALL
>  # undef __ASSUME_LISTEN_SYSCALL
> +# undef __ASSUME_GETSOCKNAME_SYSCALL
>  #endif
>  
>  /* No support for PI futexes or robust mutexes before 3.10 for m68k.  */
> diff --git a/sysdeps/unix/sysv/linux/microblaze/kernel-features.h b/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
> index e19e6bb6ba..7e2b15859e 100644
> --- a/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
> +++ b/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
> @@ -19,7 +19,6 @@
>  
>  /* All supported kernel versions for MicroBlaze have these syscalls.  */
>  #define __ASSUME_CONNECT_SYSCALL	1
> -#define __ASSUME_GETSOCKNAME_SYSCALL	1
>  #define __ASSUME_GETPEERNAME_SYSCALL	1
>  #define __ASSUME_SEND_SYSCALL		1
>  #define __ASSUME_RECV_SYSCALL		1
> diff --git a/sysdeps/unix/sysv/linux/powerpc/kernel-features.h b/sysdeps/unix/sysv/linux/powerpc/kernel-features.h
> index eb73a91a5d..8953cb019f 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/kernel-features.h
> +++ b/sysdeps/unix/sysv/linux/powerpc/kernel-features.h
> @@ -19,7 +19,6 @@
>  
>  /* New syscalls added for PowerPC in 2.6.37.  */
>  #define __ASSUME_CONNECT_SYSCALL	1
> -#define __ASSUME_GETSOCKNAME_SYSCALL	1
>  #define __ASSUME_GETPEERNAME_SYSCALL	1
>  #define __ASSUME_SEND_SYSCALL		1
>  #define __ASSUME_RECV_SYSCALL		1
> diff --git a/sysdeps/unix/sysv/linux/s390/kernel-features.h b/sysdeps/unix/sysv/linux/s390/kernel-features.h
> index 3daee3f132..1422ee620c 100644
> --- a/sysdeps/unix/sysv/linux/s390/kernel-features.h
> +++ b/sysdeps/unix/sysv/linux/s390/kernel-features.h
> @@ -19,7 +19,6 @@
>  
>  /* Direct socketcalls available with kernel 4.3.  */
>  #if __LINUX_KERNEL_VERSION >= 0x040300
> -# define __ASSUME_GETSOCKNAME_SYSCALL        1
>  # define __ASSUME_GETPEERNAME_SYSCALL        1
>  # define __ASSUME_SHUTDOWN_SYSCALL           1
>  #endif
> @@ -43,6 +42,7 @@
>  # undef __ASSUME_SOCKET_SYSCALL
>  # undef __ASSUME_SOCKETPAIR_SYSCALL
>  # undef __ASSUME_LISTEN_SYSCALL
> +# undef __ASSUME_GETSOCKNAME_SYSCALL
>  #endif
>  
>  /* s390 only supports ipc syscall before 5.1.  */
> diff --git a/sysdeps/unix/sysv/linux/sh/kernel-features.h b/sysdeps/unix/sysv/linux/sh/kernel-features.h
> index 23eadf84e0..91dc28f33f 100644
> --- a/sysdeps/unix/sysv/linux/sh/kernel-features.h
> +++ b/sysdeps/unix/sysv/linux/sh/kernel-features.h
> @@ -24,7 +24,6 @@
>  
>  /* These syscalls were added for SH in 2.6.37.  */
>  #define __ASSUME_CONNECT_SYSCALL	1
> -#define __ASSUME_GETSOCKNAME_SYSCALL	1
>  #define __ASSUME_GETPEERNAME_SYSCALL	1
>  #define __ASSUME_SEND_SYSCALL		1
>  #define __ASSUME_RECV_SYSCALL		1
  

Patch

diff --git a/sysdeps/unix/sysv/linux/generic/syscalls.list b/sysdeps/unix/sysv/linux/generic/syscalls.list
index 706893f245..a5bb00a3e4 100644
--- a/sysdeps/unix/sysv/linux/generic/syscalls.list
+++ b/sysdeps/unix/sysv/linux/generic/syscalls.list
@@ -1,6 +1,5 @@ 
 # File name	Caller	Syscall name	# args	Strong name	Weak names
 
 # Socket APIs
-getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
diff --git a/sysdeps/unix/sysv/linux/getsockname.c b/sysdeps/unix/sysv/linux/getsockname.c
index d0718c2aaf..8350b800fe 100644
--- a/sysdeps/unix/sysv/linux/getsockname.c
+++ b/sysdeps/unix/sysv/linux/getsockname.c
@@ -15,19 +15,14 @@ 
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <signal.h>
 #include <sys/socket.h>
-
 #include <socketcall.h>
-#include <kernel-features.h>
-#include <sys/syscall.h>
 
 int
 __getsockname (int fd, __SOCKADDR_ARG addr, socklen_t *len)
 {
 #ifdef __ASSUME_GETSOCKNAME_SYSCALL
-  return INLINE_SYSCALL (getsockname, 3, fd, addr.__sockaddr__, len);
+  return INLINE_SYSCALL_CALL (getsockname, fd, addr.__sockaddr__, len);
 #else
   return SOCKETCALL (getsockname, fd, addr.__sockaddr__, len);
 #endif
diff --git a/sysdeps/unix/sysv/linux/i386/kernel-features.h b/sysdeps/unix/sysv/linux/i386/kernel-features.h
index a79ec679cc..f294380215 100644
--- a/sysdeps/unix/sysv/linux/i386/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/i386/kernel-features.h
@@ -19,7 +19,6 @@ 
 
 /* Direct socketcalls available with kernel 4.3.  */
 #if __LINUX_KERNEL_VERSION >= 0x040300
-# define __ASSUME_GETSOCKNAME_SYSCALL        1
 # define __ASSUME_GETPEERNAME_SYSCALL        1
 # define __ASSUME_SHUTDOWN_SYSCALL           1
 #endif
@@ -41,6 +40,7 @@ 
 # undef __ASSUME_SOCKET_SYSCALL
 # undef __ASSUME_SOCKETPAIR_SYSCALL
 # undef __ASSUME_LISTEN_SYSCALL
+# undef __ASSUME_GETSOCKNAME_SYSCALL
 #endif
 
 /* i686 only supports ipc syscall before 5.1.  */
diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index d1769b2d99..6fb99f5c35 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -83,6 +83,7 @@ 
 #define __ASSUME_SOCKET_SYSCALL		1
 #define __ASSUME_SOCKETPAIR_SYSCALL	1
 #define __ASSUME_LISTEN_SYSCALL		1
+#define __ASSUME_GETSOCKNAME_SYSCALL	1
 
 /* Support for SysV IPC through wired syscalls.  All supported architectures
    either support ipc syscall and/or all the ipc correspondent syscalls.  */
diff --git a/sysdeps/unix/sysv/linux/m68k/kernel-features.h b/sysdeps/unix/sysv/linux/m68k/kernel-features.h
index a65fa63c5e..898c24ba62 100644
--- a/sysdeps/unix/sysv/linux/m68k/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/m68k/kernel-features.h
@@ -19,7 +19,6 @@ 
 
 /* Direct socketcalls available with kernel 4.3.  */
 #if __LINUX_KERNEL_VERSION >= 0x040300
-# define __ASSUME_GETSOCKNAME_SYSCALL        1
 # define __ASSUME_GETPEERNAME_SYSCALL        1
 # define __ASSUME_SHUTDOWN_SYSCALL           1
 #endif
@@ -43,6 +42,7 @@ 
 # undef __ASSUME_SOCKET_SYSCALL
 # undef __ASSUME_SOCKETPAIR_SYSCALL
 # undef __ASSUME_LISTEN_SYSCALL
+# undef __ASSUME_GETSOCKNAME_SYSCALL
 #endif
 
 /* No support for PI futexes or robust mutexes before 3.10 for m68k.  */
diff --git a/sysdeps/unix/sysv/linux/microblaze/kernel-features.h b/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
index e19e6bb6ba..7e2b15859e 100644
--- a/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
@@ -19,7 +19,6 @@ 
 
 /* All supported kernel versions for MicroBlaze have these syscalls.  */
 #define __ASSUME_CONNECT_SYSCALL	1
-#define __ASSUME_GETSOCKNAME_SYSCALL	1
 #define __ASSUME_GETPEERNAME_SYSCALL	1
 #define __ASSUME_SEND_SYSCALL		1
 #define __ASSUME_RECV_SYSCALL		1
diff --git a/sysdeps/unix/sysv/linux/powerpc/kernel-features.h b/sysdeps/unix/sysv/linux/powerpc/kernel-features.h
index eb73a91a5d..8953cb019f 100644
--- a/sysdeps/unix/sysv/linux/powerpc/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/powerpc/kernel-features.h
@@ -19,7 +19,6 @@ 
 
 /* New syscalls added for PowerPC in 2.6.37.  */
 #define __ASSUME_CONNECT_SYSCALL	1
-#define __ASSUME_GETSOCKNAME_SYSCALL	1
 #define __ASSUME_GETPEERNAME_SYSCALL	1
 #define __ASSUME_SEND_SYSCALL		1
 #define __ASSUME_RECV_SYSCALL		1
diff --git a/sysdeps/unix/sysv/linux/s390/kernel-features.h b/sysdeps/unix/sysv/linux/s390/kernel-features.h
index 3daee3f132..1422ee620c 100644
--- a/sysdeps/unix/sysv/linux/s390/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/s390/kernel-features.h
@@ -19,7 +19,6 @@ 
 
 /* Direct socketcalls available with kernel 4.3.  */
 #if __LINUX_KERNEL_VERSION >= 0x040300
-# define __ASSUME_GETSOCKNAME_SYSCALL        1
 # define __ASSUME_GETPEERNAME_SYSCALL        1
 # define __ASSUME_SHUTDOWN_SYSCALL           1
 #endif
@@ -43,6 +42,7 @@ 
 # undef __ASSUME_SOCKET_SYSCALL
 # undef __ASSUME_SOCKETPAIR_SYSCALL
 # undef __ASSUME_LISTEN_SYSCALL
+# undef __ASSUME_GETSOCKNAME_SYSCALL
 #endif
 
 /* s390 only supports ipc syscall before 5.1.  */
diff --git a/sysdeps/unix/sysv/linux/sh/kernel-features.h b/sysdeps/unix/sysv/linux/sh/kernel-features.h
index 23eadf84e0..91dc28f33f 100644
--- a/sysdeps/unix/sysv/linux/sh/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/sh/kernel-features.h
@@ -24,7 +24,6 @@ 
 
 /* These syscalls were added for SH in 2.6.37.  */
 #define __ASSUME_CONNECT_SYSCALL	1
-#define __ASSUME_GETSOCKNAME_SYSCALL	1
 #define __ASSUME_GETPEERNAME_SYSCALL	1
 #define __ASSUME_SEND_SYSCALL		1
 #define __ASSUME_RECV_SYSCALL		1