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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: issue with SIGPROF signal handler on ARM


On Wed, Oct 10, 2007 at 06:05:53PM +0530, Arvind Ayyangar wrote:
> I changed the prototype of profil_counter from
>  profil_counter (int signo, int _a2, int _a3, int _a4, union
> k_sigcontext sc) to
>  profil_counter (int signo, siginfo_t *sig_info, struct sigcontext
> *scp) and passed the pc value stored in ((struct ucontext *)
> scp)->uc_mcontext.arm_pc.  Here, the PC value passed to the signal
> handler seems to be as expected.

I assume you also had to change the signal handler to set SA_SIGINFO;
if you didn't I'm not sure why it worked.  Here's what I checked
in to fix this.

-- 
Daniel Jacobowitz
CodeSourcery

2007-12-21  Daniel Jacobowitz  <dan@codesourcery.com>

	* sysdeps/unix/sysv/linux/arm/profil-counter.h: Use the i386 version.
	* sysdeps/unix/sysv/linux/arm/register-dump.h (register_dump): Update
	to use ucontext.
	(REGISTER_DUMP): Likewise.
	* sysdeps/unix/sysv/linux/arm/sigcontextinfo.h (SIGCONTEXT,
	SIGCONTEXT_EXTRA_ARGS, GET_PC, GET_FRAME, GET_STACK): Likewise.
	(sigaction, __sigaction): Define.
	* sysdeps/unix/sysv/linux/arm/bits/armsigctx.h: Delete.

Index: sysdeps/unix/sysv/linux/arm/profil-counter.h
===================================================================
RCS file: /cvs/glibc/ports/sysdeps/unix/sysv/linux/arm/profil-counter.h,v
retrieving revision 1.8
diff -u -p -r1.8 profil-counter.h
--- sysdeps/unix/sysv/linux/arm/profil-counter.h	14 Oct 2002 17:26:14 -0000	1.8
+++ sysdeps/unix/sysv/linux/arm/profil-counter.h	21 Dec 2007 16:29:19 -0000
@@ -1,37 +1,2 @@
-/* Low-level statistical profiling support function.  Linux/ARM version.
-   Copyright (C) 1996, 1997, 1998, 2002 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
-
-#include <signal.h>
-#include <bits/armsigctx.h>
-
-void
-profil_counter (int signo, int _a2, int _a3, int _a4, union k_sigcontext sc)
-{
-  void *pc;
-  if (sc.v20.magic == SIGCONTEXT_2_0_MAGIC)
-    pc = (void *) sc.v20.reg.ARM_pc;
-  else
-    pc = (void *) sc.v21.arm_pc;
-  profil_count (pc);
-
-  /* This is a hack to prevent the compiler from implementing the
-     above function call as a sibcall.  The sibcall would overwrite
-     the signal context.  */
-  asm volatile ("");
-}
+/* We can use the ix86 version.  */
+#include <sysdeps/unix/sysv/linux/i386/profil-counter.h>
Index: sysdeps/unix/sysv/linux/arm/register-dump.h
===================================================================
RCS file: /cvs/glibc/ports/sysdeps/unix/sysv/linux/arm/register-dump.h,v
retrieving revision 1.5
diff -u -p -r1.5 register-dump.h
--- sysdeps/unix/sysv/linux/arm/register-dump.h	6 Jul 2001 04:56:13 -0000	1.5
+++ sysdeps/unix/sysv/linux/arm/register-dump.h	21 Dec 2007 16:29:19 -0000
@@ -20,7 +20,7 @@
 
 #include <sys/uio.h>
 #include <stdio-common/_itoa.h>
-#include <bits/armsigctx.h>
+#include <sys/ucontext.h>
 
 /* We will print the register dump in this format:
 
@@ -45,7 +45,7 @@ hexvalue (unsigned long int value, char 
 }
 
 static void
-register_dump (int fd, union k_sigcontext *ctx)
+register_dump (int fd, const struct ucontext *ctx)
 {
   char regs[21][8];
   struct iovec iov[97];
@@ -61,53 +61,27 @@ register_dump (int fd, union k_sigcontex
   ++nr
 
   /* Generate strings of register contents.  */
-  if (ctx->v20.magic == SIGCONTEXT_2_0_MAGIC)
-    {
-      hexvalue (ctx->v20.reg.ARM_r0, regs[0], 8);
-      hexvalue (ctx->v20.reg.ARM_r1, regs[1], 8);
-      hexvalue (ctx->v20.reg.ARM_r2, regs[2], 8);
-      hexvalue (ctx->v20.reg.ARM_r3, regs[3], 8);
-      hexvalue (ctx->v20.reg.ARM_r4, regs[4], 8);
-      hexvalue (ctx->v20.reg.ARM_r5, regs[5], 8);
-      hexvalue (ctx->v20.reg.ARM_r6, regs[6], 8);
-      hexvalue (ctx->v20.reg.ARM_r7, regs[7], 8);
-      hexvalue (ctx->v20.reg.ARM_r8, regs[8], 8);
-      hexvalue (ctx->v20.reg.ARM_r9, regs[9], 8);
-      hexvalue (ctx->v20.reg.ARM_r10, regs[10], 8);
-      hexvalue (ctx->v20.reg.ARM_fp, regs[11], 8);
-      hexvalue (ctx->v20.reg.ARM_ip, regs[12], 8);
-      hexvalue (ctx->v20.reg.ARM_sp, regs[13], 8);
-      hexvalue (ctx->v20.reg.ARM_lr, regs[14], 8);
-      hexvalue (ctx->v20.reg.ARM_pc, regs[15], 8);
-      hexvalue (ctx->v20.reg.ARM_cpsr, regs[16], 8);
-      hexvalue (ctx->v20.trap_no, regs[17], 8);
-      hexvalue (ctx->v20.error_code, regs[18], 8);
-      hexvalue (ctx->v20.oldmask, regs[19], 8);
-    }
-  else
-    {
-      hexvalue (ctx->v21.arm_r0, regs[0], 8);
-      hexvalue (ctx->v21.arm_r1, regs[1], 8);
-      hexvalue (ctx->v21.arm_r2, regs[2], 8);
-      hexvalue (ctx->v21.arm_r3, regs[3], 8);
-      hexvalue (ctx->v21.arm_r4, regs[4], 8);
-      hexvalue (ctx->v21.arm_r5, regs[5], 8);
-      hexvalue (ctx->v21.arm_r6, regs[6], 8);
-      hexvalue (ctx->v21.arm_r7, regs[7], 8);
-      hexvalue (ctx->v21.arm_r8, regs[8], 8);
-      hexvalue (ctx->v21.arm_r9, regs[9], 8);
-      hexvalue (ctx->v21.arm_r10, regs[10], 8);
-      hexvalue (ctx->v21.arm_fp, regs[11], 8);
-      hexvalue (ctx->v21.arm_ip, regs[12], 8);
-      hexvalue (ctx->v21.arm_sp, regs[13], 8);
-      hexvalue (ctx->v21.arm_lr, regs[14], 8);
-      hexvalue (ctx->v21.arm_pc, regs[15], 8);
-      hexvalue (ctx->v21.arm_cpsr, regs[16], 8);
-      hexvalue (ctx->v21.trap_no, regs[17], 8);
-      hexvalue (ctx->v21.error_code, regs[18], 8);
-      hexvalue (ctx->v21.oldmask, regs[19], 8);
-      hexvalue (ctx->v21.fault_address, regs[20], 8);
-    }
+  hexvalue (ctx->uc_mcontext.arm_r0, regs[0], 8);
+  hexvalue (ctx->uc_mcontext.arm_r1, regs[1], 8);
+  hexvalue (ctx->uc_mcontext.arm_r2, regs[2], 8);
+  hexvalue (ctx->uc_mcontext.arm_r3, regs[3], 8);
+  hexvalue (ctx->uc_mcontext.arm_r4, regs[4], 8);
+  hexvalue (ctx->uc_mcontext.arm_r5, regs[5], 8);
+  hexvalue (ctx->uc_mcontext.arm_r6, regs[6], 8);
+  hexvalue (ctx->uc_mcontext.arm_r7, regs[7], 8);
+  hexvalue (ctx->uc_mcontext.arm_r8, regs[8], 8);
+  hexvalue (ctx->uc_mcontext.arm_r9, regs[9], 8);
+  hexvalue (ctx->uc_mcontext.arm_r10, regs[10], 8);
+  hexvalue (ctx->uc_mcontext.arm_fp, regs[11], 8);
+  hexvalue (ctx->uc_mcontext.arm_ip, regs[12], 8);
+  hexvalue (ctx->uc_mcontext.arm_sp, regs[13], 8);
+  hexvalue (ctx->uc_mcontext.arm_lr, regs[14], 8);
+  hexvalue (ctx->uc_mcontext.arm_pc, regs[15], 8);
+  hexvalue (ctx->uc_mcontext.arm_cpsr, regs[16], 8);
+  hexvalue (ctx->uc_mcontext.trap_no, regs[17], 8);
+  hexvalue (ctx->uc_mcontext.error_code, regs[18], 8);
+  hexvalue (ctx->uc_mcontext.oldmask, regs[19], 8);
+  hexvalue (ctx->uc_mcontext.fault_address, regs[20], 8);
 
   /* Generate the output.  */
   ADD_STRING ("Register dump:\n\n R0: ");
@@ -150,11 +124,8 @@ register_dump (int fd, union k_sigcontex
   ADD_MEM (regs[18], 8);
   ADD_STRING ("   OldMask: ");
   ADD_MEM (regs[19], 8);
-  if (ctx->v20.magic != SIGCONTEXT_2_0_MAGIC)
-    {
-      ADD_STRING ("\n Addr: ");
-      ADD_MEM (regs[20], 8);
-    }
+  ADD_STRING ("\n Addr: ");
+  ADD_MEM (regs[20], 8);
 
   ADD_STRING ("\n");
 
@@ -163,4 +134,4 @@ register_dump (int fd, union k_sigcontex
 }
 
 
-#define REGISTER_DUMP register_dump (fd, &ctx)
+#define REGISTER_DUMP register_dump (fd, ctx)
Index: sysdeps/unix/sysv/linux/arm/sigcontextinfo.h
===================================================================
RCS file: /cvs/glibc/ports/sysdeps/unix/sysv/linux/arm/sigcontextinfo.h,v
retrieving revision 1.8
diff -u -p -r1.8 sigcontextinfo.h
--- sysdeps/unix/sysv/linux/arm/sigcontextinfo.h	21 Dec 2002 18:37:16 -0000	1.8
+++ sysdeps/unix/sysv/linux/arm/sigcontextinfo.h	21 Dec 2007 16:29:19 -0000
@@ -17,35 +17,34 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
-#include <bits/armsigctx.h>
+#include <sys/ucontext.h>
 #include "kernel-features.h"
 
-#define SIGCONTEXT int _a2, int _a3, int _a4, union k_sigcontext
-#define SIGCONTEXT_EXTRA_ARGS _a2, _a3, _a4,
+#define SIGCONTEXT siginfo_t *_si, struct ucontext *
+#define SIGCONTEXT_EXTRA_ARGS _si,
 
 /* The sigcontext structure changed between 2.0 and 2.1 kernels.  On any
    modern system we should be able to assume that the "new" format will be
    in use.  */
-#if __LINUX_KERNEL_VERSION > 131328
 
-#define GET_PC(ctx)	((void *) ctx.v21.arm_pc)
-#define GET_FRAME(ctx)	ADVANCE_STACK_FRAME ((void *) ctx.v21.arm_fp)
-#define GET_STACK(ctx)	((void *) ctx.v21.arm_sp)
-
-#else
-
-#define GET_PC(ctx)	((void *)((ctx.v20.magic == SIGCONTEXT_2_0_MAGIC) ? \
-			 ctx.v20.reg.ARM_pc : ctx.v21.arm_pc))
-#define GET_FRAME(ctx)	\
-	ADVANCE_STACK_FRAME((void *)((ctx.v20.magic == SIGCONTEXT_2_0_MAGIC) ? \
-			 ctx.v20.reg.ARM_fp : ctx.v21.arm_fp))
-#define GET_STACK(ctx)	((void *)((ctx.v20.magic == SIGCONTEXT_2_0_MAGIC) ? \
-			 ctx.v20.reg.ARM_sp : ctx.v21.arm_sp))
-
-#endif
+#define GET_PC(ctx)	((void *) (ctx)->uc_mcontext.arm_pc)
+#define GET_FRAME(ctx)	ADVANCE_STACK_FRAME ((void *) ctx->uc_mcontext.arm_fp)
+#define GET_STACK(ctx)	((void *) (ctx)->uc_mcontext.arm_sp)
 
 #define ADVANCE_STACK_FRAME(frm)	\
 			((struct layout *)frm - 1)
 
 #define CALL_SIGHANDLER(handler, signo, ctx) \
   (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
+
+/* There is no reliable way to get the sigcontext unless we use a
+   three-argument signal handler.  */
+#define __sigaction(sig, act, oact) ({ \
+  (act)->sa_flags |= SA_SIGINFO; \
+  (__sigaction) (sig, act, oact); \
+})
+
+#define sigaction(sig, act, oact) ({ \
+  (act)->sa_flags |= SA_SIGINFO; \
+  (sigaction) (sig, act, oact); \
+})
Index: sysdeps/unix/sysv/linux/arm/bits/armsigctx.h
===================================================================
RCS file: sysdeps/unix/sysv/linux/arm/bits/armsigctx.h
diff -N sysdeps/unix/sysv/linux/arm/bits/armsigctx.h
--- sysdeps/unix/sysv/linux/arm/bits/armsigctx.h	6 Jul 2001 04:56:13 -0000	1.5
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,73 +0,0 @@
-/* Definition of `struct sigcontext' for Linux/ARM
-   Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
-
-/* The format of struct sigcontext changed between 2.0 and 2.1 kernels.
-   Fortunately 2.0 puts a magic number in the first word and this is not
-   a legal value for `trap_no', so we can tell them apart.  */
-
-/* Early 2.2 and 2.3 kernels do not have the `fault_address' member in
-   the sigcontext structure.  Unfortunately there is no reliable way
-   to test for its presence and this word will contain garbage for too-old
-   kernels.  Versions 2.2.14 and 2.3.35 (plus later versions) are known to
-   include this element.  */
-
-#ifndef __ARMSIGCTX_H
-#define __ARMSIGCTX_H	1
-
-#include <asm/ptrace.h>
-
-union k_sigcontext
-  {
-    struct
-      {
-	unsigned long int trap_no;
-	unsigned long int error_code;
-	unsigned long int oldmask;
-	unsigned long int arm_r0;
-	unsigned long int arm_r1;
-	unsigned long int arm_r2;
-	unsigned long int arm_r3;
-	unsigned long int arm_r4;
-	unsigned long int arm_r5;
-	unsigned long int arm_r6;
-	unsigned long int arm_r7;
-	unsigned long int arm_r8;
-	unsigned long int arm_r9;
-	unsigned long int arm_r10;
-	unsigned long int arm_fp;
-	unsigned long int arm_ip;
-	unsigned long int arm_sp;
-	unsigned long int arm_lr;
-	unsigned long int arm_pc;
-	unsigned long int arm_cpsr;
-	unsigned long fault_address;
-      } v21;
-    struct
-      {
-	unsigned long int magic;
-	struct pt_regs reg;
-	unsigned long int trap_no;
-	unsigned long int error_code;
-	unsigned long int oldmask;
-      } v20;
-};
-
-#define SIGCONTEXT_2_0_MAGIC	0x4B534154
-
-#endif	/* bits/armsigctx.h */


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