[klibc] [PATCH 2/2] ia64: Fix sigaction struct layout and function implementation

Ben Hutchings ben at decadent.org.uk
Sat Feb 2 06:48:48 PST 2019


On Sat, 2019-02-02 at 01:35 +0000, James Clarke wrote:
[...]
> --- a/usr/klibc/sigaction.c
> +++ b/usr/klibc/sigaction.c
> @@ -19,13 +19,30 @@ __extern int __rt_sigaction(int, const struct sigaction *, struct sigaction *,
>  			    size_t);
>  #endif
>  
> +#ifdef __ia64__
> +/* We use -mno-pic so our function pointers are straight to the function entry
> +   point, but the kernel always expects a descriptor. Thus we create a fake
> +   descriptor for each possible signal, update it, and pass that to the kernel
> +   instead (the descriptor must remain valid after returning from sigaction
> +   until it is replaced). */
> +struct {
> +	uintptr_t entry;
> +	uintptr_t gp;
> +} signal_descriptors[_NSIG];
> +#endif

This should be declared static.

[...]
> +#ifdef __ia64__
> +	if (sig < 0 || sig >= _NSIG) {
> +		errno = EINVAL;
> +		return -1;
> +	}
> +
> +	if (oact) {
> +		old_entry = signal_descriptors[sig].entry;
> +	}
> +
> +	if (act && act->sa_handler != SIG_IGN && act->sa_handler != SIG_DFL) {
> +		sa = *act;
> +		act = &sa;
> +
> +		signal_descriptors[sig].entry = (uintptr_t)sa.sa_handler;

What if sigaction() races with delivery of the signal, so it arrives
between here and the system call?  At the very least this assignment
needs to be made atomic.

Also, what if the system call fails?  In that case the signal handler
must never be called, so we can't do the assignment until after the
call returns.  It seems like we would have to block the signal
temporarily.

Are you sure it's worth the trouble to avoid using function
descriptors?

Ben.

> +		sa.sa_handler = (__sighandler_t)(uintptr_t)&signal_descriptors[sig];
> +	}
> +#endif
> +
>  #if _KLIBC_USE_RT_SIG
>  # ifdef __sparc__
>  	{
> @@ -61,5 +98,11 @@ int sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
>  	}
>  #endif
>  
> +#ifdef __ia64__
> +	if (oact && oact->sa_handler != SIG_IGN && oact->sa_handler != SIG_DFL) {
> +		oact->sa_handler = (__sighandler_t)old_entry;
> +	}
> +#endif
> +
>  	return rv;
>  }
-- 
Ben Hutchings
Knowledge is power.  France is bacon.





More information about the klibc mailing list