V2 [PATCH 2/2] Add C wrappers for prctl/process_vm_readv/process_vm_writev [BZ #25810]

Florian Weimer fweimer@redhat.com
Wed Apr 29 15:41:55 GMT 2020


* 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



More information about the Libc-alpha mailing list