Attached testcase open-codes old sigaction syscall.
(Current libc usually uses rt_sigaction).
Before patch, output is:
sigaction(SIGTRAP, {0x804825b, [], SA_RESTORER, 0x8048253}, NULL, 0x8048253) = 0
getpid() = 5842
kill(5842, SIGTRAP) = 0
--- {si_signo=SIGTRAP, si_code=SI_USER, si_pid=5842, si_uid=0,
si_value={int=134513920, ptr=0x8048500}} (Trace/breakpoint trap) ---
write(1, "Got sig:5\n", 10) = 10
sigreturn() (mask []) = 0
rt_sigprocmask(SIG_BLOCK, [TRAP], NULL, 8) = 0
getpid() = 5842
kill(5842, SIGTRAP) = 0
rt_sigprocmask(SIG_UNBLOCK, [TRAP], NULL, 8) = 0
--- {si_signo=SIGTRAP, si_code=SI_USER, si_pid=5842, si_uid=0,
si_value={int=134513920, ptr=0x8048500}} (Trace/breakpoint trap) ---
write(1, "Got sig:5\n", 10) = 10
sigreturn() (mask []) = 0
sigaction(SIGTRAP, {SIG_IGN, , NULL, 0x8048253) = 0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
getpid() = 5842
kill(5842, SIGTRAP) = 0
--- {si_signo=SIGTRAP, si_code=SI_USER, si_pid=5842, si_uid=0,
si_value={int=134513920, ptr=0x8048500}} (Trace/breakpoint trap) ---
sigaction(SIGTRAP, {0x804825b, [], SA_RESTORER, 0x8048253}, NULL, 0x8048253) = 0
getpid() = 5842
kill(5842, SIGTRAP) = 0
--- {si_signo=SIGTRAP, si_code=SI_USER, si_pid=5842, si_uid=0,
si_value={int=134513920, ptr=0x8048500}} (Trace/breakpoint trap) ---
write(1, "Got sig:5\n", 10) = 10
sigreturn() (mask []) = 0
_exit(0) = ?
+++ exited with 0 +++
Note messed-up line.
Patch makes it display as:
sigaction(SIGTRAP, {SIG_IGN, [], SA_RESTORER, 0x8048253}, NULL, 0x8048253) = 0
* signal (sys_sigaction): Fix display of sigaction with
SIG_DFL/SIG_IGN handlers.
--
vda
diff -d -urpN strace.6/signal.c strace.7/signal.c
--- strace.6/signal.c 2012-01-18 13:47:01.883493605 +0100
+++ strace.7/signal.c 2012-01-18 15:19:26.334601560 +0100
@@ -1022,20 +1022,20 @@ sys_sigaction(struct tcb *tcp)
}
#endif /* !USE_PROCFS */
tprintf("{%#lx, ", (long) sa.SA_HANDLER);
+ }
#ifndef LINUX
- printsigmask(&sa.sa_mask, 0);
+ printsigmask(&sa.sa_mask, 0);
#else
- long_to_sigset(sa.sa_mask, &sigset);
- printsigmask(&sigset, 0);
+ long_to_sigset(sa.sa_mask, &sigset);
+ printsigmask(&sigset, 0);
#endif
- tprints(", ");
- printflags(sigact_flags, sa.sa_flags, "SA_???");
+ tprints(", ");
+ printflags(sigact_flags, sa.sa_flags, "SA_???");
#ifdef SA_RESTORER
- if (sa.sa_flags & SA_RESTORER)
- tprintf(", %p", sa.sa_restorer);
+ if (sa.sa_flags & SA_RESTORER)
+ tprintf(", %p", sa.sa_restorer);
#endif
- tprints("}");
- }
+ tprints("}");
}
if (entering(tcp))
tprints(", ");
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <netdb.h>
#include <setjmp.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include <string.h>
#include <syscall.h>
#include <sys/poll.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <termios.h>
#include <time.h>
#include <sys/param.h>
/* This is the sigaction structure from the Linux 2.1.20 kernel. */
struct old_kernel_sigaction {
__sighandler_t k_sa_handler;
unsigned long sa_mask;
unsigned long sa_flags;
void (*sa_restorer)(void);
};
#define SA_RESTORER 0x04000000
extern void restoreZ(void) __asm__ ("__restoreZ");
int sigactionZ(int sig, const struct sigaction *act, struct sigaction *oact)
{
int result;
struct old_kernel_sigaction kact, koact;
if (act) {
kact.k_sa_handler = act->sa_handler;
kact.sa_mask = act->sa_mask.__val[0];
kact.sa_flags = act->sa_flags | SA_RESTORER;
kact.sa_restorer = &restoreZ;
}
__asm__ __volatile__ (
" pushl %%ebx\n"
" movl %3, %%ebx\n"
" int $0x80\n"
" popl %%ebx\n"
: "=a" (result), "=m" (koact)
: "0" (__NR_sigaction), "r" (sig), "m" (kact),
"c" (act ? &kact : NULL),
"d" (oact ? &koact : NULL));
if (result < 0) {
__set_errno(-result);
return -1;
}
if (oact) {
oact->sa_handler = koact.k_sa_handler;
oact->sa_mask.__val[0] = koact.sa_mask;
oact->sa_flags = koact.sa_flags;
oact->sa_restorer = koact.sa_restorer;
}
return result;
}
#define RESTORE(name, syscall) RESTORE2(name, syscall)
#define RESTORE2(name, syscall) \
__asm__ ( \
".text\n" \
"__" #name ":\n" \
" popl %eax\n" \
" movl $" #syscall ", %eax\n" \
" int $0x80\n" \
);
RESTORE(restoreZ, __NR_sigreturn)
static void handler(int sig)
{
printf("Got sig:%d\n", sig);
}
int main(int argc, char **argv)
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = handler;
///signal(SIGTRAP, handler);
sigactionZ(SIGTRAP, &sa, NULL);
raise(SIGTRAP); // 1
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGTRAP);
sigprocmask(SIG_BLOCK, &set, NULL);
raise(SIGTRAP);
// trap should not happen
sigprocmask(SIG_UNBLOCK, &set, NULL);
// 2 trap should happen here
///signal(SIGTRAP, SIG_IGN);
sa.sa_handler = SIG_IGN;
sigactionZ(SIGTRAP, &sa, NULL);
raise(SIGTRAP);
// trap should not happen
///signal(SIGTRAP, handler);
sa.sa_handler = handler;
sigactionZ(SIGTRAP, &sa, NULL);
raise(SIGTRAP); // 3
return 0;
}
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Strace-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/strace-devel