Message ID | 20200429152017.GA3811691@gmail.com |
---|---|
State | New |
Headers | show |
Series | V2 [PATCH 2/2] Add C wrappers for prctl/process_vm_readv/process_vm_writev [BZ #25810] | expand |
* H. J. Lu: >> > +{ >> > + return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5); >> > +} >> > + >> > +hidden_def (__prctl) >> > +weak_alias (__prctl, prctl) >> > +hidden_weak (prctl) >> >> Can't you use libc_hidden_proto in include/sys/prctl.h and >> libc_hidden_proto here? >> > > Since include/sys/prctl.h has > > extern int __prctl (int __option, ...); > > it can't be used. I still don't get it. What happens if you use libc_hidden_proto and libc_hidden_def? > Since the the U marker can only be applied to 2 unsigned long arguments, > add a C wrapper for prctl, process_vm_readv and process_vm_writev syscals > which have more than 2 unsigned long arguments. Please add that syscalls.list reference. Thanks. Florian
On Wed, Apr 29, 2020 at 8:22 AM Florian Weimer <fweimer@redhat.com> wrote: > > * H. J. Lu: > > >> > +{ > >> > + return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5); > >> > +} > >> > + > >> > +hidden_def (__prctl) > >> > +weak_alias (__prctl, prctl) > >> > +hidden_weak (prctl) > >> > >> Can't you use libc_hidden_proto in include/sys/prctl.h and > >> libc_hidden_proto here? > >> > > > > Since include/sys/prctl.h has > > > > extern int __prctl (int __option, ...); > > > > it can't be used. > > I still don't get it. What happens if you use libc_hidden_proto and > libc_hidden_def? With extern int __prctl (int __option, ...); libc_hidden_proto (__prctl) libc_hidden_proto (prctl) and #include <unistd.h> #include <sysdep.h> #include <errno.h> #include <sys/prctl.h> int __prctl (int option, unsigned long int arg2, unsigned long int arg3, unsigned long int arg4, unsigned long int arg5) { return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5); } libc_hidden_def (__prctl) weak_alias (__prctl, prctl) hidden_weak (prctl) I got ../sysdeps/unix/sysv/linux/prctl.c:25:1: error: conflicting types for ‘__prctl’ 25 | __prctl (int option, unsigned long int arg2, unsigned long int arg3, | ^~~~~~~ In file included from <command-line>: ../include/sys/prctl.h:7:20: note: previous declaration of ‘__prctl’ was here 7 | libc_hidden_proto (__prctl) | ^~~~~~~ ./../include/libc-symbols.h:541:33: note: in definition of macro ‘__hidden_proto’ 541 | extern thread __typeof (name) name __asm__ (__hidden_asmname (#internal)) \ | ^~~~ ./../include/libc-symbols.h:624:44: note: in expansion of macro ‘hidden_proto’ 624 | # define libc_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) | ^~~~~~~~~~~~ ../include/sys/prctl.h:7:1: note: in expansion of macro ‘libc_hidden_proto’ 7 | libc_hidden_proto (__prctl) | ^~~~~~~~~~~~~~~~~ ../sysdeps/unix/sysv/linux/prctl.c:32:22: error: conflicting types for ‘prctl’ 32 | weak_alias (__prctl, prctl) | ^~~~~ ./../include/libc-symbols.h:152:26: note: in definition of macro ‘_weak_alias’ 152 | extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))) \ | ^~~~~~~~~ ../sysdeps/unix/sysv/linux/prctl.c:32:1: note: in expansion of macro ‘weak_alias’ 32 | weak_alias (__prctl, prctl) | ^~~~~~~~~~ ../include/sys/prctl.h:8:20: note: previous declaration of ‘prctl’ was here 8 | libc_hidden_proto (prctl) | ^~~~~ ./../include/libc-symbols.h:541:33: note: in definition of macro ‘__hidden_proto’ 541 | extern thread __typeof (name) name __asm__ (__hidden_asmname (#internal)) \ | ^~~~ ./../include/libc-symbols.h:624:44: note: in expansion of macro ‘hidden_proto’ 624 | # define libc_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) | ^~~~~~~~~~~~ ../include/sys/prctl.h:8:1: note: in expansion of macro ‘libc_hidden_proto’ 8 | libc_hidden_proto (prctl) | ^~~~~~~~~~~~~~~~~ ./../include/libc-symbols.h:552:33: error: ‘__EI___prctl’ aliased to undefined symbol ‘__GI___prctl’ 552 | extern thread __typeof (name) __EI_##name \ | ^~~~~ ./../include/libc-symbols.h:548:3: note: in expansion of macro ‘__hidden_ver2’ 548 | __hidden_ver2 (, local, internal, name) | ^~~~~~~~~~~~~ ./../include/libc-symbols.h:557:29: note: in expansion of macro ‘__hidden_ver1’ 557 | # define hidden_def(name) __hidden_ver1(__GI_##name, name, name); | ^~~~~~~~~~~~~ ./../include/libc-symbols.h:626:32: note: in expansion of macro ‘hidden_def’ 626 | # define libc_hidden_def(name) hidden_def (name) | ^~~~~~~~~~ ../sysdeps/unix/sysv/linux/prctl.c:31:1: note: in expansion of macro ‘libc_hidden_def’ 31 | libc_hidden_def (__prctl) | ^~~~~~~~~~~~~~~ ./../include/libc-symbols.h:552:33: error: ‘__EI_prctl’ aliased to undefined symbol ‘__GI_prctl’ 552 | extern thread __typeof (name) __EI_##name \ | ^~~~~ ./../include/libc-symbols.h:548:3: note: in expansion of macro ‘__hidden_ver2’ 548 | __hidden_ver2 (, local, internal, name) | ^~~~~~~~~~~~~ ./../include/libc-symbols.h:562:2: note: in expansion of macro ‘__hidden_ver1’ 562 | __hidden_ver1(__GI_##name, name, name) __attribute__((weak)); | ^~~~~~~~~~~~~ ../sysdeps/unix/sysv/linux/prctl.c:33:1: note: in expansion of macro ‘hidden_weak’ 33 | hidden_weak (prctl) | ^~~~~~~~~~~ > > Since the the U marker can only be applied to 2 unsigned long arguments, > > add a C wrapper for prctl, process_vm_readv and process_vm_writev syscals > > which have more than 2 unsigned long arguments. > > Please add that syscalls.list reference. Thanks. > I have --- Since the the U marker can only be applied to 2 unsigned long arguments in syscalls.list files, add a C wrapper for prctl, process_vm_readv and process_vm_writev syscals which have more than 2 unsigned long arguments. ---
On Apr 29 2020, H.J. Lu via Libc-alpha wrote: >> > +int >> > +__prctl (int option, unsigned long arg2, unsigned long arg3, >> > + unsigned long arg4, unsigned long arg5) >> >> unsigned long int everywhere. > > Fixed. > >> >> > +{ >> > + return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5); >> > +} >> > + >> > +hidden_def (__prctl) >> > +weak_alias (__prctl, prctl) >> > +hidden_weak (prctl) >> >> Can't you use libc_hidden_proto in include/sys/prctl.h and >> libc_hidden_proto here? >> > > Since include/sys/prctl.h has > > extern int __prctl (int __option, ...); > > it can't be used. You cannot implement a function declared as varargs with a non-varargs definition. Andreas.
* H. J. Lu: > With > > extern int __prctl (int __option, ...); > libc_hidden_proto (__prctl) > libc_hidden_proto (prctl) > > and > > #include <unistd.h> > #include <sysdep.h> > #include <errno.h> > #include <sys/prctl.h> > > int > __prctl (int option, unsigned long int arg2, unsigned long int arg3, > unsigned long int arg4, unsigned long int arg5) > { > return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5); > } > > libc_hidden_def (__prctl) > weak_alias (__prctl, prctl) > hidden_weak (prctl) Please try: extern int __prctl (int __option, ...); libc_hidden_proto (__prctl) And: int __prctl (int option, unsigned long int arg2, unsigned long int arg3, unsigned long int arg4, unsigned long int arg5) { return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5); } libc_hidden_def (__prctl) strong_alias (__prctl, prctl) Internal users should always use __prctl to avoid linknamespace failures, so there are no callers of prctl and we don't need a hidden alias for it. >> > Since the the U marker can only be applied to 2 unsigned long arguments, >> > add a C wrapper for prctl, process_vm_readv and process_vm_writev syscals >> > which have more than 2 unsigned long arguments. >> >> Please add that syscalls.list reference. Thanks. >> > > I have > > --- > Since the the U marker can only be applied to 2 unsigned long arguments > in syscalls.list files, add a C wrapper for prctl, process_vm_readv and > process_vm_writev syscals which have more than 2 unsigned long arguments. > --- Nice. Thanks, Florian
On Wed, Apr 29, 2020 at 8:32 AM Andreas Schwab <schwab@linux-m68k.org> wrote: > > On Apr 29 2020, H.J. Lu via Libc-alpha wrote: > > >> > +int > >> > +__prctl (int option, unsigned long arg2, unsigned long arg3, > >> > + unsigned long arg4, unsigned long arg5) > >> > >> unsigned long int everywhere. > > > > Fixed. > > > >> > >> > +{ > >> > + return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5); > >> > +} > >> > + > >> > +hidden_def (__prctl) > >> > +weak_alias (__prctl, prctl) > >> > +hidden_weak (prctl) > >> > >> Can't you use libc_hidden_proto in include/sys/prctl.h and > >> libc_hidden_proto here? > >> > > > > Since include/sys/prctl.h has > > > > extern int __prctl (int __option, ...); > > > > it can't be used. > > You cannot implement a function declared as varargs with a non-varargs > definition. True. There is a separate bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25896
* Florian Weimer: >> extern int __prctl (int __option, ...); >> libc_hidden_proto (__prctl) >> libc_hidden_proto (prctl) >> >> and >> >> #include <unistd.h> >> #include <sysdep.h> >> #include <errno.h> >> #include <sys/prctl.h> >> >> int >> __prctl (int option, unsigned long int arg2, unsigned long int arg3, >> unsigned long int arg4, unsigned long int arg5) >> { >> return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5); >> } >> >> libc_hidden_def (__prctl) >> weak_alias (__prctl, prctl) >> hidden_weak (prctl) > > Please try: > > extern int __prctl (int __option, ...); > libc_hidden_proto (__prctl) > > And: > > int > __prctl (int option, unsigned long int arg2, unsigned long int arg3, > unsigned long int arg4, unsigned long int arg5) > { > return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5); > } > libc_hidden_def (__prctl) > strong_alias (__prctl, prctl) > > Internal users should always use __prctl to avoid linknamespace > failures, so there are no callers of prctl and we don't need a hidden > alias for it. My bad. I see it know. It's the variadic/non-variadic mismatch. For the open family of functions, we actually use <stdarg.h> and try to match the actual argument list. This has caused bugs, so I don't recommend it. For fcntl, we unconditionally access the optional arguments, also with <stdarg.h>. This avoids the bug. Likewise for ptrace. I think it's safe for the ABIs we support to implement a variadic function with a non-variadic one. It's needed for implicit function declaration support. (The converse is definitely unsafe and causes stack corruption on some targets.) So perhaps use <stdarg.h> for prctl as well? Thanks, Florian
* H. J. Lu: > On Wed, Apr 29, 2020 at 8:32 AM Andreas Schwab <schwab@linux-m68k.org> wrote: >> >> On Apr 29 2020, H.J. Lu via Libc-alpha wrote: >> >> >> > +int >> >> > +__prctl (int option, unsigned long arg2, unsigned long arg3, >> >> > + unsigned long arg4, unsigned long arg5) >> >> >> >> unsigned long int everywhere. >> > >> > Fixed. >> > >> >> >> >> > +{ >> >> > + return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5); >> >> > +} >> >> > + >> >> > +hidden_def (__prctl) >> >> > +weak_alias (__prctl, prctl) >> >> > +hidden_weak (prctl) >> >> >> >> Can't you use libc_hidden_proto in include/sys/prctl.h and >> >> libc_hidden_proto here? >> >> >> > >> > Since include/sys/prctl.h has >> > >> > extern int __prctl (int __option, ...); >> > >> > it can't be used. >> >> You cannot implement a function declared as varargs with a non-varargs >> definition. > > True. There is a separate bug: > > https://sourceware.org/bugzilla/show_bug.cgi?id=25896 I suggest to drop prctl from process_vm_*v fix and commit only the latter now. Thanks, Florian
On Wed, Apr 29, 2020 at 8:43 AM Florian Weimer <fweimer@redhat.com> wrote: > > * H. J. Lu: > > > On Wed, Apr 29, 2020 at 8:32 AM Andreas Schwab <schwab@linux-m68k.org> wrote: > >> > >> On Apr 29 2020, H.J. Lu via Libc-alpha wrote: > >> > >> >> > +int > >> >> > +__prctl (int option, unsigned long arg2, unsigned long arg3, > >> >> > + unsigned long arg4, unsigned long arg5) > >> >> > >> >> unsigned long int everywhere. > >> > > >> > Fixed. > >> > > >> >> > >> >> > +{ > >> >> > + return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5); > >> >> > +} > >> >> > + > >> >> > +hidden_def (__prctl) > >> >> > +weak_alias (__prctl, prctl) > >> >> > +hidden_weak (prctl) > >> >> > >> >> Can't you use libc_hidden_proto in include/sys/prctl.h and > >> >> libc_hidden_proto here? > >> >> > >> > > >> > Since include/sys/prctl.h has > >> > > >> > extern int __prctl (int __option, ...); > >> > > >> > it can't be used. > >> > >> You cannot implement a function declared as varargs with a non-varargs > >> definition. > > > > True. There is a separate bug: > > > > https://sourceware.org/bugzilla/show_bug.cgi?id=25896 > > I suggest to drop prctl from process_vm_*v fix and commit only the > latter now. > > Thanks, > Florian > Sounds good. I will submit a separate patch for prctl later. This is I am going to check in. Thanks.
* H. J. Lu: > Sounds good. I will submit a separate patch for prctl later. > > This is I am going to check in. Yes, looks good, thanks. Florian
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 089a4899d5..1d9a8d3cdb 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -59,7 +59,8 @@ sysdep_routines += adjtimex clone umount umount2 readahead sysctl \ eventfd eventfd_read eventfd_write prlimit \ personality epoll_wait tee vmsplice splice \ open_by_handle_at mlock2 pkey_mprotect pkey_set pkey_get \ - timerfd_gettime timerfd_settime + timerfd_gettime timerfd_settime prctl \ + process_vm_readv process_vm_writev CFLAGS-gethostid.c = -fexceptions CFLAGS-tee.c = -fexceptions -fasynchronous-unwind-tables diff --git a/sysdeps/unix/sysv/linux/prctl.c b/sysdeps/unix/sysv/linux/prctl.c new file mode 100644 index 0000000000..6a9c1a8fbf --- /dev/null +++ b/sysdeps/unix/sysv/linux/prctl.c @@ -0,0 +1,39 @@ +/* prctl - Linux specific syscall. + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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 + <https://www.gnu.org/licenses/>. */ + +#include <unistd.h> +#include <sysdep.h> +#include <errno.h> + +extern int prctl (int, unsigned long int, unsigned long int, + unsigned long int, unsigned long int); +hidden_proto (prctl) +extern int __prctl (int, unsigned long int, unsigned long int, + unsigned long int, unsigned long int); +hidden_proto (__prctl) + +int +__prctl (int option, unsigned long int arg2, unsigned long int arg3, + unsigned long int arg4, unsigned long int arg5) +{ + return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5); +} + +hidden_def (__prctl) +weak_alias (__prctl, prctl) +hidden_weak (prctl) diff --git a/sysdeps/unix/sysv/linux/process_vm_readv.c b/sysdeps/unix/sysv/linux/process_vm_readv.c new file mode 100644 index 0000000000..dca826b679 --- /dev/null +++ b/sysdeps/unix/sysv/linux/process_vm_readv.c @@ -0,0 +1,33 @@ +/* process_vm_readv - Linux specific syscall. + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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 + <https://www.gnu.org/licenses/>. */ + +#include <unistd.h> +#include <sysdep.h> +#include <errno.h> +#include <sys/uio.h> + +ssize_t +process_vm_readv (pid_t pid, const struct iovec *local_iov, + unsigned long int liovcnt, + const struct iovec *remote_iov, + unsigned long int riovcnt, unsigned long int flags) +{ + return INLINE_SYSCALL_CALL (process_vm_readv, pid, local_iov, + liovcnt, remote_iov, riovcnt, flags); +} + diff --git a/sysdeps/unix/sysv/linux/process_vm_writev.c b/sysdeps/unix/sysv/linux/process_vm_writev.c new file mode 100644 index 0000000000..15748451aa --- /dev/null +++ b/sysdeps/unix/sysv/linux/process_vm_writev.c @@ -0,0 +1,33 @@ +/* process_vm_writev - Linux specific syscall. + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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 + <https://www.gnu.org/licenses/>. */ + +#include <unistd.h> +#include <sysdep.h> +#include <errno.h> +#include <sys/uio.h> + +ssize_t +process_vm_writev (pid_t pid, const struct iovec *local_iov, + unsigned long int liovcnt, + const struct iovec *remote_iov, + unsigned long int riovcnt, unsigned long int flags) +{ + return INLINE_SYSCALL_CALL (process_vm_writev, pid, local_iov, + liovcnt, remote_iov, riovcnt, flags); +} + diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list index 5b4e205934..1d8893d1b8 100644 --- a/sysdeps/unix/sysv/linux/syscalls.list +++ b/sysdeps/unix/sysv/linux/syscalls.list @@ -43,7 +43,6 @@ nfsservctl EXTRA nfsservctl i:ipp __compat_nfsservctl nfsservctl@GLIBC_2.0:GLIBC pipe - pipe i:f __pipe pipe pipe2 - pipe2 i:fi __pipe2 pipe2 pivot_root EXTRA pivot_root i:ss pivot_root -prctl EXTRA prctl i:iiiii __prctl prctl query_module EXTRA query_module i:sipip __compat_query_module query_module@GLIBC_2.0:GLIBC_2.23 quotactl EXTRA quotactl i:isip quotactl remap_file_pages - remap_file_pages i:pUiUi __remap_file_pages remap_file_pages @@ -98,8 +97,6 @@ name_to_handle_at EXTRA name_to_handle_at i:isppi name_to_handle_at setns EXTRA setns i:ii setns -process_vm_readv EXTRA process_vm_readv i:ipipii process_vm_readv -process_vm_writev EXTRA process_vm_writev i:ipipii process_vm_writev memfd_create EXTRA memfd_create i:si memfd_create pkey_alloc EXTRA pkey_alloc i:ii pkey_alloc pkey_free EXTRA pkey_free i:i pkey_free