This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH] pthread_sighandler


On Fri, Feb 23, 2001 at 02:25:48PM -0800, Ulrich Drepper wrote:
> Jakub Jelinek <jakub@redhat.com> writes:
> 
> > What do you think?
> 
> Not much.  This is simply undocumented are fragile.  Nobody should
> depend on it.  I won't spend my time thinking about this.  If you come
> up with a patch and it doesn't add much overhead to the general case
> (since 99% of the users are not insane and don't use it) then maybe.

What about this?
I've done the i386 case only so far, I could try to do alpha later on.
I don't think it adds much overhead. I wanted to make sure 16 byte alignment
is ensured for the signal handler in case it would use SSE, that's why it
looks uglier than it could.
This is the testcase I was testing it on:
#include <signal.h>
#include <stdlib.h>

void segv (int signo, struct sigcontext ctx)
{
  ctx.eip += 2;
}

int main(void)
{
  struct sigaction s;

  sigemptyset (&s.sa_mask);
  s.sa_handler = (void *)segv;
  s.sa_flags = SA_ONESHOT;
  sigaction (SIGSEGV, &s, NULL);
  asm volatile ("movl %0, (%0)" : : "r" (0));
  return 0;
}
(i386 specific, works without -lpthread in all glibcs and with -lpthread
with this patch in).

2001-02-26  Jakub Jelinek  <jakub@redhat.com>

	* signals.c (pthread_sighandler): Use CALL_SIGHANDLER.

	* sysdeps/generic/sigcontextinfo.h (CALL_SIGHANDLER): Define.
	* sysdeps/mach/hurd/i386/sigcontextinfo.h: Likewise.
	* sysdeps/unix/sysv/linux/alpha/sigcontextinfo.h: Likewise.
	* sysdeps/unix/sysv/linux/arm/sigcontextinfo.h: Likewise.
	* sysdeps/unix/sysv/linux/i386/sigcontextinfo.h: Likewise.
	* sysdeps/unix/sysv/linux/m68k/sigcontextinfo.h: Likewise.
	* sysdeps/unix/sysv/linux/mips/sigcontextinfo.h: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/sigcontextinfo.h: Likewise.
	* sysdeps/unix/sysv/linux/s390/sigcontextinfo.h: Likewise.
	* sysdeps/unix/sysv/linux/sh/sigcontextinfo.h: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/sigcontextinfo.h: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/sigcontextinfo.h: Likewise.

--- libc/linuxthreads/signals.c.jj	Fri Feb 23 16:03:33 2001
+++ libc/linuxthreads/signals.c	Mon Feb 26 17:25:50 2001
@@ -94,7 +94,7 @@ static void pthread_sighandler(int signo
   in_sighandler = THREAD_GETMEM(self, p_in_sighandler);
   if (in_sighandler == NULL)
     THREAD_SETMEM(self, p_in_sighandler, CURRENT_STACK_FRAME);
-  sighandler[signo].old(signo, SIGCONTEXT_EXTRA_ARGS ctx);
+  CALL_SIGHANDLER(sighandler[signo].old, signo, ctx);
   if (in_sighandler == NULL)
     THREAD_SETMEM(self, p_in_sighandler, NULL);
 }
--- libc/sysdeps/generic/sigcontextinfo.h.jj	Mon Aug 23 19:41:16 1999
+++ libc/sysdeps/generic/sigcontextinfo.h	Mon Feb 26 17:28:13 2001
@@ -23,3 +23,5 @@
 #define GET_PC(ctx)	((void *) 0)
 #define GET_FRAME(ctx)	((void *) 0)
 #define GET_STACK(ctx)	((void *) 0)
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+  (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
--- libc/sysdeps/mach/hurd/i386/sigcontextinfo.h.jj	Mon Aug 23 19:41:41 1999
+++ libc/sysdeps/mach/hurd/i386/sigcontextinfo.h	Mon Feb 26 17:28:18 2001
@@ -21,3 +21,5 @@
 #define GET_PC(ctx)	((void *) (ctx).sc_eip)
 #define GET_FRAME(ctx)	((void *) (ctx).sc_ebp)
 #define GET_STACK(ctx)	((void *) (ctx).sc_uesp)
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+  (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
--- libc/sysdeps/unix/sysv/linux/alpha/sigcontextinfo.h.jj	Mon Aug 23 19:42:07 1999
+++ libc/sysdeps/unix/sysv/linux/alpha/sigcontextinfo.h	Mon Feb 26 17:28:23 2001
@@ -21,3 +21,5 @@
 #define GET_PC(ctx)	((void *) (ctx).sc_pc)
 #define GET_FRAME(ctx)	((void *) (ctx).sc_regs[15])
 #define GET_STACK(ctx)	((void *) (ctx).sc_regs[30])
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+  (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
--- libc/sysdeps/unix/sysv/linux/sh/sigcontextinfo.h.jj	Mon Jun 12 22:43:23 2000
+++ libc/sysdeps/unix/sysv/linux/sh/sigcontextinfo.h	Mon Feb 26 17:28:34 2001
@@ -23,3 +23,5 @@
 #define GET_PC(ctx)	((void *) ctx.sc_pc)
 #define GET_FRAME(ctx)	((void *) ctx.sc_regs[14])
 #define GET_STACK(ctx)	((void *) ctx.sc_regs[15])
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+  (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
--- libc/sysdeps/unix/sysv/linux/s390/sigcontextinfo.h.jj	Wed Aug  2 17:14:21 2000
+++ libc/sysdeps/unix/sysv/linux/s390/sigcontextinfo.h	Mon Feb 26 17:28:39 2001
@@ -24,3 +24,5 @@
 #define GET_PC(ctx)	((void *)((ctx)->sregs->regs.psw.addr))
 #define GET_FRAME(ctx)	(*(void **)((ctx)->sregs->regs.gprs[11]))
 #define GET_STACK(ctx)	((void *)((ctx)->sregs->regs.gprs[15]))
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+  (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
--- libc/sysdeps/unix/sysv/linux/arm/sigcontextinfo.h.jj	Thu Jan 13 10:47:56 2000
+++ libc/sysdeps/unix/sysv/linux/arm/sigcontextinfo.h	Mon Feb 26 17:28:47 2001
@@ -31,3 +31,5 @@
 			 ctx.v20.reg.ARM_sp : ctx.v21.arm_sp))
 #define ADVANCE_STACK_FRAME(frm)	\
 			((struct layout *)frm - 1)
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+  (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
--- libc/sysdeps/unix/sysv/linux/i386/sigcontextinfo.h.jj	Mon Aug 23 19:42:51 1999
+++ libc/sysdeps/unix/sysv/linux/i386/sigcontextinfo.h	Mon Feb 26 17:17:38 2001
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
 
@@ -22,3 +22,30 @@
 #define GET_PC(ctx)	((void *) ctx.eip)
 #define GET_FRAME(ctx)	((void *) ctx.ebp)
 #define GET_STACK(ctx)	((void *) ctx.esp_at_signal)
+#define CALL_SIGHANDLER(handler, signo, ctx)				\
+do {									\
+  int __tmp1, __tmp2, __tmp3, __tmp4;					\
+  __asm __volatile ("movl\t%%esp, %%edi\n\t"				\
+		    "andl\t$-16, %%esp\n\t"				\
+		    "subl\t%8, %%esp\n\t"				\
+		    "movl\t%%edi, %c8-4(%%esp)\n\t"			\
+		    "movl\t%1, 0(%%esp)\n\t"				\
+		    "leal\t4(%%esp), %%edi\n\t"				\
+		    "cld\n\t"						\
+		    "rep\tmovsl\n\t"					\
+		    "call\t*%0\n\t"					\
+		    "cld\n\t"						\
+		    "movl\t%9, %%ecx\n\t"				\
+		    "subl\t%%edi, %%esi\n\t"				\
+		    "leal\t4(%%esp,%%esi,1), %%edi\n\t"			\
+		    "leal\t4(%%esp), %%esi\n\t"				\
+		    "rep\tmovsl\n\t"					\
+		    "movl\t%c8-4(%%esp), %%esp\n\t"			\
+		    : "=a" (__tmp1), "=d" (__tmp2), "=S" (__tmp3),	\
+		      "=c" (__tmp4)					\
+		    : "0" (handler), "1" (signo), "2" (&ctx),		\
+		      "3" (sizeof (struct sigcontext) / 4),		\
+		      "n" ((sizeof (struct sigcontext) + 19) & ~15),	\
+		      "i" (sizeof (struct sigcontext) / 4)		\
+		    : "cc", "edi");					\
+} while (0)
--- libc/sysdeps/unix/sysv/linux/m68k/sigcontextinfo.h.jj	Mon Aug 23 19:43:28 1999
+++ libc/sysdeps/unix/sysv/linux/m68k/sigcontextinfo.h	Mon Feb 26 17:28:51 2001
@@ -22,3 +22,5 @@
 #define GET_PC(ctx)	((void *) (ctx)->sc_pc)
 #define GET_FRAME(ctx)	((void *) __builtin_frame_address (1))
 #define GET_STACK(ctx)	((void *) (ctx)->sc_usp)
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+  (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
--- libc/sysdeps/unix/sysv/linux/mips/sigcontextinfo.h.jj	Wed Jan 31 16:35:23 2001
+++ libc/sysdeps/unix/sysv/linux/mips/sigcontextinfo.h	Mon Feb 26 17:28:54 2001
@@ -23,3 +23,5 @@
 #define GET_PC(ctx)	((void *) ctx->sc_pc)
 #define GET_FRAME(ctx)	((void *) ctx->sc_regs[30])
 #define GET_STACK(ctx)	((void *) ctx->sc_regs[29])
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+  (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
--- libc/sysdeps/unix/sysv/linux/powerpc/sigcontextinfo.h.jj	Mon Aug 23 19:43:48 1999
+++ libc/sysdeps/unix/sysv/linux/powerpc/sigcontextinfo.h	Mon Feb 26 17:28:58 2001
@@ -23,3 +23,5 @@
 #define GET_PC(ctx)	((void *)((ctx)->regs->nip))
 #define GET_FRAME(ctx)	(*(void **)((ctx)->regs->gpr[1]))
 #define GET_STACK(ctx)	((void *)((ctx)->regs->gpr[1]))
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+  (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
--- libc/sysdeps/unix/sysv/linux/sparc/sparc32/sigcontextinfo.h.jj	Wed Mar 29 16:07:30 2000
+++ libc/sysdeps/unix/sysv/linux/sparc/sparc32/sigcontextinfo.h	Mon Feb 26 17:29:02 2001
@@ -25,3 +25,5 @@
 
 #define GET_STACK(__ctx)	((void *) (__ctx)->si_regs.u_regs[14])
 #define GET_FRAME(__ctx)	ADVANCE_STACK_FRAME (GET_STACK(__ctx))
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+  (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
--- libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigcontextinfo.h.jj	Fri Dec 10 15:15:34 1999
+++ libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigcontextinfo.h	Mon Feb 26 17:29:06 2001
@@ -28,3 +28,5 @@
 					   + STACK_BIAS))+14))
 #define GET_STACK(__ctx)	((void *) ((__ctx)->sigc_regs.u_regs[14]))
 #define GET_FRAME(__ctx)	ADVANCE_STACK_FRAME (GET_STACK (__ctx))
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+  (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))


	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]