Subject: Re: SA_SIGINFO patch
To: Christos Zoulas <christos@zoulas.com>
From: Jason Thorpe <thorpej@wasabisystems.com>
List: tech-kern
Date: 09/02/2003 17:45:49
On Tuesday, September 2, 2003, at 01:24  AM, Christos Zoulas wrote:

> Index: __sigaction14_sigtramp.c
> ===================================================================
> RCS file: 
> /cvsroot/src/lib/libc/arch/i386/sys/__sigaction14_sigtramp.c,v
> retrieving revision 1.2
> diff -u -u -r1.2 __sigaction14_sigtramp.c
> --- __sigaction14_sigtramp.c	2003/01/18 11:08:12	1.2
> +++ __sigaction14_sigtramp.c	2003/09/01 23:29:46
> @@ -48,7 +48,7 @@
>  int
>  __libc_sigaction14(int sig, const struct sigaction *act, struct 
> sigaction *oact)
>  {
> -	extern int __sigtramp_sigcontext_1[];
> +	extern int __sigtramp_sigcontext_2[];

For non-siginfo signals, you should continue to use 
__sigtramp_sigcontext_1.  For siginfo signals, you should use 
__sigtramp_siginfo_1 (i.e. rename your __sigtramp_sigcontext_2 to 
__sigtramp_siginfo_1).

I intended the ABI version to be within the domain of the trampoline 
type.  So, "sigcontext"-type handlers have one ABI domain, and 
"siginfo"-type handlers have another ABI domain.

Note that this also means that your kernel "osigframe" is really 
"sigframe_sigcontext" and your new "sigframe" is really 
"sigframe_siginfo".

>
>  	/*
>  	 * Right here we should select the SA_SIGINFO trampoline
> @@ -56,5 +56,5 @@
>  	 */
>
>  	return (__sigaction_sigtramp(sig, act, oact,
> -				     __sigtramp_sigcontext_1, 1));
> +				     __sigtramp_sigcontext_2, 2));

If the handler does not have SA_SIGINFO set, then use 
__sigtramp_sigcontext_1, else use __sigtramp_siginfo_1.

It is important to name the signinfo trampoline 
"__sigtramp_siginfo_...", since GDB will use the "siginfo" part of the 
name to decide how to decode the arguments passed to the handler.  Oh, 
guess what, you get to update GDB for this, too :-)  (GDB 5.3 and later 
have support for our userland signal trampolines.)

>  }
> --- /dev/null	2003-09-01 14:55:16.000000000 -0400
> +++ __sigtramp2.S	2003-09-01 14:41:36.000000000 -0400

...and adjust this file as necessary.  (Perhaps move its contents to 
__sigtramp1.S, since it is the "version 1 siginfo trampoline".)

> @@ -0,0 +1,59 @@
> +/*	$NetBSD: __sigtramp1.S,v 1.1 2002/07/09 23:32:36 thorpej Exp $	*/
> +
> +/*-
> + * Copyright (c) 2002 The NetBSD Foundation, Inc.
> + * All rights reserved.
> + *
> + * This code is derived from software contributed to The NetBSD 
> Foundation
> + * by Jason R. Thorpe.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above 
> copyright
> + *    notice, this list of conditions and the following disclaimer in 
> the
> + *    documentation and/or other materials provided with the 
> distribution.
> + * 3. All advertising materials mentioning features or use of this 
> software
> + *    must display the following acknowledgement:
> + *	This product includes software developed by the NetBSD
> + *	Foundation, Inc. and its contributors.
> + * 4. Neither the name of The NetBSD Foundation nor the names of its
> + *    contributors may be used to endorse or promote products derived
> + *    from this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 
> CONTRIBUTORS
> + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 
> NOT LIMITED
> + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
> PARTICULAR
> + * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR 
> CONTRIBUTORS
> + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
> EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
> OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
> BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
> WHETHER IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
> OTHERWISE)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
> ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#include "SYS.h"
> +
> +/*
> + * The i386 signal trampoline is invoked only to return from
> + * the signal; the kernel calls the signal handler directly.
> + *
> + * On entry, stack looks like:
> + *
> + *		ucontext structure			[12+sizeof(siginfo_t)]
> + *		siginfo structure			[12]
> + *		pointer to ucontext structure		[8]
> + *		pointer to siginfo structure		[4]
> + *	sp->	signal number				[0]
> + */
> +NENTRY(__sigtramp_sigcontext_2)
> +	movl	8(%esp),%eax	/* get pointer to ucontext */
> +	movl	%eax,4(%esp)	/* put it in the argument slot */
> +				/* fake return address already there */
> +	SYSTRAP(setcontext)	/* do setcontext */
> +	movl	%eax,4(%esp)	/* error code */
> +	SYSTRAP(exit)		/* exit */
>
         -- Jason R. Thorpe <thorpej@wasabisystems.com>