Index: include/vki-linux.h
===================================================================
--- include/vki-linux.h	(revision 5643)
+++ include/vki-linux.h	(working copy)
@@ -436,6 +436,32 @@
 #define VKI_TRAP_TRACE      (__VKI_SI_FAULT|2)  /* process trace trap */
 
 /*
+ * SIGTRAP si_codes
+ */
+#define VKI_TRAP_BRKPT  (__VKI_SI_FAULT|1)      /* Process breakpoint.  */
+#define VKI_TRAP_TRACE  (__VKI_SI_FAULT|2)      /* single step trap */
+
+/*
+ * SIGCHLD si_codes
+ */
+#define VKI_CLD_EXITED  (__VKI_SI_FAULT|1)      /* Child has exited.  */
+#define VKI_CLD_KILLED  (__VKI_SI_FAULT|2)      /* Child was killed.  */
+#define VKI_CLD_DUMPED  (__VKI_SI_FAULT|3)      /* Child terminated abnormally.  */
+#define VKI_CLD_TRAPPED (__VKI_SI_FAULT|4)      /* Traced child has trapped.  */
+#define VKI_CLD_STOPPED (__VKI_SI_FAULT|5)      /* Child has stopped.  */
+#define VKI_CLD_CONTINUED (__VKI_SI_FAULT|6)    /* Stopped child has continued.  */
+
+/*
+ * SIGPOLL si_codes
+ */
+#define VKI_POLL_IN     (__VKI_SI_FAULT|1)      /* Data input available.  */
+#define VKI_POLL_OUT    (__VKI_SI_FAULT|2)      /* Output buffers available.  */
+#define VKI_POLL_MSG    (__VKI_SI_FAULT|3)      /* Input message available.   */
+#define VKI_POLL_ERR    (__VKI_SI_FAULT|4)      /* I/O error.  */
+#define VKI_POLL_PRI    (__VKI_SI_FAULT|5)      /* High priority input available.  */
+#define VKI_POLL_HUP    (__VKI_SI_FAULT|6)      /* Device disconnected.  */
+
+/*
  * This works because the alignment is ok on all current architectures
  * but we leave open this being overridden in the future
  */
Index: coregrind/m_sigframe/sigframe-x86-linux.c
===================================================================
--- coregrind/m_sigframe/sigframe-x86-linux.c	(revision 5643)
+++ coregrind/m_sigframe/sigframe-x86-linux.c	(working copy)
@@ -338,6 +339,61 @@
 /*--- Creating signal frames                               ---*/
 /*------------------------------------------------------------*/
 
+static void fetch_trapno(const vki_siginfo_t *si, struct vki_sigcontext *sc)
+{
+    int i;
+    static struct {int sig, code, trap;} sig_pair[] = {
+        {VKI_SIGILL,  VKI_ILL_ILLOPC,   6},
+/*      {VKI_SIGILL,  VKI_ILL_ILLOPN,  -1}, */
+/*      {VKI_SIGILL,  VKI_ILL_ILLADR,  -1}, */
+/*      {VKI_SIGILL,  VKI_ILL_ILLTRP,  -1}, */
+/*      {VKI_SIGILL,  VKI_ILL_PRVOPC,  -1}, */
+/*      {VKI_SIGILL,  VKI_ILL_PRVREG,  -1}, */
+/*      {VKI_SIGILL,  VKI_ILL_COPROC,  -1}, */
+        {VKI_SIGILL,  VKI_ILL_BADSTK,  12},
+
+        {VKI_SIGFPE,  VKI_FPE_INTDIV,   0},
+        {VKI_SIGFPE,  VKI_FPE_INTOVF,   4},
+/*      {VKI_SIGFPE,  VKI_FPE_FLTDIV,  16}, */
+/*      {VKI_SIGFPE,  VKI_FPE_FLTOVF,  16}, */
+/*      {VKI_SIGFPE,  VKI_FPE_FLTUND,  16}, */
+/*      {VKI_SIGFPE,  VKI_FPE_FLTRES,  16}, */
+/*      {VKI_SIGFPE,  VKI_FPE_FLTINV,  16}, */
+/*      {VKI_SIGFPE,  VKI_FPE_FLTSUB,  16}, */
+
+        {VKI_SIGSEGV, VKI_SEGV_MAPERR, 14},
+        {VKI_SIGSEGV, VKI_SEGV_ACCERR, 13},
+
+        {VKI_SIGBUS,  VKI_BUS_ADRALN,  17},
+/*      {VKI_SIGBUS,  VKI_BUS_ADRERR,  -1}, */
+/*      {VKI_SIGBUS,  VKI_BUS_OBJERR,  -1}, */
+       
+        {VKI_SIGTRAP, VKI_TRAP_TRACE,   1},
+        {VKI_SIGTRAP, VKI_TRAP_BRKPT,   3},
+    };
+
+    switch (si->si_signo)
+    {
+    case VKI_SIGILL:
+    case VKI_SIGFPE:
+    case VKI_SIGSEGV:
+    case VKI_SIGBUS:
+    case VKI_SIGTRAP:
+        for (i = 0; i < sizeof(sig_pair) / sizeof(sig_pair[0]); i++) {
+            if (sig_pair[i].sig == si->si_signo && sig_pair[i].code == si->si_code) {
+                if (sig_pair[i].code != -1) {
+                    sc->trapno = sig_pair[i].trap;
+                }
+                return;
+            }
+        }
+        VG_(message)(Vg_UserMsg,
+                     "Cannot map signal %d, code %d to a valid trap number",
+                     si->si_signo, si->si_code);
+        break;
+    }
+}
+
 /* Create a plausible-looking sigcontext from the thread's
    Vex guest state.  NOTE: does not fill in the FP or SSE
    bits of sigcontext at the moment.
@@ -380,8 +436,8 @@
    sc->eflags = LibVEX_GuestX86_get_eflags(&tst->arch.vex);
    SC2(ss,SS);
    /* XXX esp_at_signal */
-   /* XXX trapno */
    /* XXX err */
+   fetch_trapno(si, sc);
 #  undef SC2
 
    sc->cr2 = (UInt)si->_sifields._sigfault._addr;
