Subject: Re: SA_SIGINFO for mips
To: Christos Zoulas <christos@zoulas.com>
From: Christopher SEKIYA <wileyc@rezrov.net>
List: port-mips
Date: 10/12/2003 14:03:47
On Sun, Oct 12, 2003 at 04:25:28AM +0000, Christos Zoulas wrote:
> It is probably better to use matt's powerpc one. I've switched the i386
> to do that.
Ah, okay. Attached (this time with __sigtramp2.S).
I'm not sure that I'm doing the right thing in __sigtramp_siginfo_2 --
the +128 was gleaned from the alpha implementation, which was the closest
in structure to mips. Could someone please sanity-check it?
-- Chris
GPG key FEB9DE7F (91AF 4534 4529 4BCC 31A5 938E 023E EEFB FEB9 DE7F)
diff -urN stable/lib/libc/arch/mips/Makefile.inc ip32/lib/libc/arch/mips/Makefile.inc
--- stable/lib/libc/arch/mips/Makefile.inc 2002-07-10 13:29:07.000000000 +0900
+++ ip32/lib/libc/arch/mips/Makefile.inc 2003-10-12 13:47:40.000000000 +0900
@@ -3,4 +3,4 @@
KMINCLUDES=
KMSRCS=
-SRCS+= __sigaction14_sigtramp.c __sigtramp1.S
+SRCS+= __sigaction14_sigtramp.c __sigtramp1.S __sigtramp2.S
diff -urN stable/lib/libc/arch/mips/sys/__sigaction14_sigtramp.c ip32/lib/libc/arch/mips/sys/__sigaction14_sigtramp.c
--- stable/lib/libc/arch/mips/sys/__sigaction14_sigtramp.c 2003-01-18 20:10:45.000000000 +0900
+++ ip32/lib/libc/arch/mips/sys/__sigaction14_sigtramp.c 2003-10-12 13:51:53.000000000 +0900
@@ -36,10 +36,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#define __LIBC12_SOURCE__
-
#include <sys/types.h>
+#include <stddef.h>
#include <signal.h>
+#include <errno.h>
#include "extern.h"
@@ -48,13 +48,31 @@
int
__libc_sigaction14(int sig, const struct sigaction *act, struct sigaction *oact)
{
- extern int __sigtramp_sigcontext_1[];
+ extern const int __sigtramp_sigcontext_1[];
+ extern const int __sigtramp_siginfo_2[];
+ int rv;
+
+ /*
+ * If no sigaction, use the "default" trampoline since it won't
+ * be used.
+ */
+ if (act == NULL)
+ return __sigaction_sigtramp(sig, act, oact, NULL, 0);
/*
- * Right here we should select the SA_SIGINFO trampoline
- * if SA_SIGINFO is set in the sigaction.
+ * We select the non-SA_SIGINFO trampoline if SA_SIGINFO is not
+ * set in the sigaction.
*/
+ if ((act->sa_flags & SA_SIGINFO) == 0) {
+ rv = __sigaction_sigtramp(sig, act, oact,
+ __sigtramp_sigcontext_1, 1);
+ if (rv >= 0 || errno != EINVAL)
+ return rv;
+ }
- return (__sigaction_sigtramp(sig, act, oact,
- __sigtramp_sigcontext_1, 1));
+ /*
+ * If SA_SIGINFO was specificed or the compatibility trampolines
+ * can't be used, use the siginfo trampoline.
+ */
+ return __sigaction_sigtramp(sig, act, oact, __sigtramp_siginfo_2, 2);
}
diff -urN stable/lib/libc/arch/mips/sys/__sigtramp2.S ip32/lib/libc/arch/mips/sys/__sigtramp2.S
--- stable/lib/libc/arch/mips/sys/__sigtramp2.S 1970-01-01 09:00:00.000000000 +0900
+++ ip32/lib/libc/arch/mips/sys/__sigtramp2.S 2003-10-12 13:54:13.000000000 +0900
@@ -0,0 +1,56 @@
+/* $NetBSD: __sigtramp1.S,v 1.1 2002/07/09 23:32:37 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 MIPS signal trampoline is invoked only to return from
+ * the signal; the kernel calls the signal handler directly.
+ *
+ * On entry, stack looks like:
+ *
+ * ucontext structure [128] == sp + sizeof(siginfo_t)]
+ * sp-> siginfo structure
+ */
+LEAF_NOPROFILE(__sigtramp_siginfo_2)
+ move a0, sp
+ addu a0, 128 /* get pointer to ucontext */
+ SYSTRAP(setcontext) /* and call setcontext() with it */
+ move a0, v0 /* if that failed, get error code */
+ SYSTRAP(exit) /* and call exit() with it */
+END(__sigtramp_siginfo_2)
--- stable/sys/arch/mips/include/signal.h 2003-08-08 01:28:29.000000000 +0900
+++ ip32/sys/arch/mips/include/signal.h 2003-10-12 12:01:30.000000000 +0900
@@ -41,6 +41,13 @@
#include <machine/cdefs.h> /* for API selection */
+#define __HAVE_SIGINFO
+#ifdef COMPAT_16
+#define SIGTRAMP_VALID(vers) ((unsigned)(vers) <= 2)
+#else
+#define SIGTRAMP_VALID(vers) ((vers) == 2)
+#endif
+
#if !defined(__ASSEMBLER__)
/*