From 0e68241138aa754fc05a4396e573946e55c4fa5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 15 Aug 2020 18:54:18 +0200 Subject: [PATCH 1/3] missing_syscall: add forgotten check for __NR_get_mempolicy nonnegativity We do it in other cases, we should here too. Fixup for b070c7c0e13. --- src/basic/missing_syscall.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index 41164ea7d0..227c2121fa 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -515,7 +515,7 @@ static inline long missing_get_mempolicy(int *mode, unsigned long *nodemask, unsigned long maxnode, void *addr, unsigned long flags) { long i; -# ifdef __NR_get_mempolicy +# if defined __NR_get_mempolicy && __NR_get_mempolicy >= 0 i = syscall(__NR_get_mempolicy, mode, nodemask, maxnode, addr, flags); # else errno = ENOSYS; From 23654cee136862996d92e7f1e9887786ddb3dfe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 15 Aug 2020 19:01:23 +0200 Subject: [PATCH 2/3] missing_syscall: fix pidfd_{send_signal,open} numbers for alpha Also order the syscalls by syscall number for easier comparisons with the kernel headers. Fixup for 5f152f43d04e5aad6a3f98f45f020a66e3aac717. --- src/basic/missing_syscall.h | 54 ++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index 227c2121fa..2d6e08dbe9 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -527,39 +527,49 @@ static inline long missing_get_mempolicy(int *mode, unsigned long *nodemask, #define get_mempolicy missing_get_mempolicy #endif -#if !HAVE_PIDFD_OPEN -/* may be (invalid) negative number due to libseccomp, see PR 13319 */ -# if ! (defined __NR_pidfd_open && __NR_pidfd_open >= 0) -# if defined __NR_pidfd_open -# undef __NR_pidfd_open -# endif -# define __NR_pidfd_open 434 -#endif -static inline int pidfd_open(pid_t pid, unsigned flags) { -#ifdef __NR_pidfd_open - return syscall(__NR_pidfd_open, pid, flags); -#else - errno = ENOSYS; - return -1; -#endif -} -#endif - #if !HAVE_PIDFD_SEND_SIGNAL /* may be (invalid) negative number due to libseccomp, see PR 13319 */ # if ! (defined __NR_pidfd_send_signal && __NR_pidfd_send_signal >= 0) # if defined __NR_pidfd_send_signal # undef __NR_pidfd_send_signal # endif -# define __NR_pidfd_send_signal 424 -#endif +/* should be always defined, see kernel 39036cd2727395c3369b1051005da74059a85317 */ +# if defined(__alpha__) +# define __NR_pidfd_send_signal 534 +# else +# define __NR_pidfd_send_signal 424 +# endif +# endif static inline int pidfd_send_signal(int fd, int sig, siginfo_t *info, unsigned flags) { -#ifdef __NR_pidfd_open +# ifdef __NR_pidfd_open return syscall(__NR_pidfd_send_signal, fd, sig, info, flags); -#else +# else errno = ENOSYS; return -1; +# endif +} #endif + +#if !HAVE_PIDFD_OPEN +/* may be (invalid) negative number due to libseccomp, see PR 13319 */ +# if ! (defined __NR_pidfd_open && __NR_pidfd_open >= 0) +# if defined __NR_pidfd_open +# undef __NR_pidfd_open +# endif +/* should be always defined, see kernel 7615d9e1780e26e0178c93c55b73309a5dc093d7 */ +# if defined(__alpha__) +# define __NR_pidfd_open 544 +# else +# define __NR_pidfd_open 434 +# endif +# endif +static inline int pidfd_open(pid_t pid, unsigned flags) { +# ifdef __NR_pidfd_open + return syscall(__NR_pidfd_open, pid, flags); +# else + errno = ENOSYS; + return -1; +# endif } #endif From faeae444ea452139519718ceb681e8b5831b6890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 16 Aug 2020 16:19:29 +0200 Subject: [PATCH 3/3] missing_syscall: do not use function name that may conflict with glibc This was done for all replacements back in 5187dd2c403caf92d09f3491e41f1ceb3f10491f, but some newer stuff didn't do this. --- src/basic/missing_syscall.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index 2d6e08dbe9..501c4d811c 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -524,7 +524,7 @@ static inline long missing_get_mempolicy(int *mode, unsigned long *nodemask, return i; } -#define get_mempolicy missing_get_mempolicy +# define get_mempolicy missing_get_mempolicy #endif #if !HAVE_PIDFD_SEND_SIGNAL @@ -540,7 +540,7 @@ static inline long missing_get_mempolicy(int *mode, unsigned long *nodemask, # define __NR_pidfd_send_signal 424 # endif # endif -static inline int pidfd_send_signal(int fd, int sig, siginfo_t *info, unsigned flags) { +static inline int missing_pidfd_send_signal(int fd, int sig, siginfo_t *info, unsigned flags) { # ifdef __NR_pidfd_open return syscall(__NR_pidfd_send_signal, fd, sig, info, flags); # else @@ -548,6 +548,8 @@ static inline int pidfd_send_signal(int fd, int sig, siginfo_t *info, unsigned f return -1; # endif } + +# define pidfd_send_signal missing_pidfd_send_signal #endif #if !HAVE_PIDFD_OPEN @@ -563,7 +565,7 @@ static inline int pidfd_send_signal(int fd, int sig, siginfo_t *info, unsigned f # define __NR_pidfd_open 434 # endif # endif -static inline int pidfd_open(pid_t pid, unsigned flags) { +static inline int missing_pidfd_open(pid_t pid, unsigned flags) { # ifdef __NR_pidfd_open return syscall(__NR_pidfd_open, pid, flags); # else @@ -571,10 +573,14 @@ static inline int pidfd_open(pid_t pid, unsigned flags) { return -1; # endif } + +# define pidfd_open missing_pidfd_open #endif #if !HAVE_RT_SIGQUEUEINFO -static inline int rt_sigqueueinfo(pid_t tgid, int sig, siginfo_t *info) { +static inline int missing_rt_sigqueueinfo(pid_t tgid, int sig, siginfo_t *info) { return syscall(__NR_rt_sigqueueinfo, tgid, sig, info); } + +# define rt_sigqueueinfo missing_rt_sigqueueinfo #endif