V3 [PATCH] Add a C wrapper for prctl [BZ #25896]
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Thu Nov 10 11:49:24 GMT 2022
On 10/11/22 05:33, Florian Weimer via Libc-alpha wrote:
> * H. J. Lu via Libc-alpha:
>
>> From ee8672af3ef5f3db438c0abb39b2673944181292 Mon Sep 17 00:00:00 2001
>> From: "H.J. Lu" <hjl.tools@gmail.com>
>> Date: Wed, 29 Apr 2020 07:38:49 -0700
>> Subject: [PATCH] Add a C wrapper for prctl [BZ #25896]
>>
>> Add a C wrapper to pass arguments in
>>
>> /* Control process execution. */
>> extern int prctl (int __option, ...) __THROW;
>>
>> to prctl syscall:
>>
>> extern int prctl (int, unsigned long int, unsigned long int,
>> unsigned long int, unsigned long int);
>>
>> On Linux/x86, since the prctl syscall interface:
>>
>> extern int prctl (int, unsigned long int, unsigned long int,
>> unsigned long int, unsigned long int);
>>
>> and the glibc prctl interface:
>>
>> extern int prctl (int option, ...);
>>
>> pass the arguments identically, the assembly verion:
>>
>> PSEUDO (__prctl, prctl, 5)
>> ret
>> PSEUDO_END (__prctl)
>>
>> is used.
>
> This broke ABI on powerpc64le-linux-gnu because the calling convention
> is not identical. The manual page specifies the second prototype.
>
> I filed a GCC RFE so that we can deal with this in a more elegant
> manner:
>
> rs6000: Option not to use parameter save area in variadic function
> implementations
> <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107606>
>
> I don't know whether we should restrict the C prctl wrapper to x86 x32,
> or if we should add an assembler wrapper on powerpc64le-linux-gnu.
>
> Thanks,
> Florian
>
The previous syscalls.list entry marked the function as 5 argument one
instead of variadic, so I think it would be better to add a way each
ABI to use this instead of the variadic one. Something like:
#if PRCTL_VARIADIC_OK
int
__prctl (int option, ...)
{
va_list arg;
va_start (arg, option);
unsigned long int arg2 = va_arg (arg, unsigned long int);
unsigned long int arg3 = va_arg (arg, unsigned long int);
unsigned long int arg4 = va_arg (arg, unsigned long int);
unsigned long int arg5 = va_arg (arg, unsigned long int);
va_end (arg);
return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5);
}
#else
int
__prctl (int option, int arg1, int arg2, int arg3, int arg4, int arg5)
{
return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5);
}
#endif
Or if powerpc64le is the only affected add a specific C implementation for
it. I think we should really move away from assembler wrappers.
More information about the Libc-alpha
mailing list