From: Nicholas Nethercote Date: Wed, 13 Oct 2004 14:42:57 +0000 (+0000) Subject: Arch-abstraction: X-Git-Tag: svn/VALGRIND_3_0_0~1542 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d1ad5601fb06faec99073f5af54815d4606e7688;p=thirdparty%2Fvalgrind.git Arch-abstraction: - factor out differences in ucontext types across different archs. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2751 --- diff --git a/coregrind/core.h b/coregrind/core.h index 0180808095..197fe887d4 100644 --- a/coregrind/core.h +++ b/coregrind/core.h @@ -1361,7 +1361,7 @@ void VG_(sanity_check_proxy)(void); back into the proxy's main loop, so it doesn't return. */ __attribute__ ((__noreturn__)) extern void VG_(proxy_handlesig)( const vki_ksiginfo_t *siginfo, - const struct vki_sigcontext *sigcontext ); + Addr ip, Int sysnum ); /* --------------------------------------------------------------------- Exports of vg_syscalls.c diff --git a/coregrind/vg_proxylwp.c b/coregrind/vg_proxylwp.c index 8c57639c55..8856444116 100644 --- a/coregrind/vg_proxylwp.c +++ b/coregrind/vg_proxylwp.c @@ -402,13 +402,10 @@ void VG_(proxy_shutdown)(void) handler is being run with all signals blocked; the longjmp is there to make sure they stay masked until the application thread is ready to run its signal handler. */ -void VG_(proxy_handlesig)(const vki_ksiginfo_t *siginfo, - const struct vki_sigcontext *sigcontext) +void VG_(proxy_handlesig)(const vki_ksiginfo_t *siginfo, Addr ip, Int sysnum) { UChar local; ProxyLWP *px = LWP_TSD(&local); - Addr eip = sigcontext->eip; - Int eax = sigcontext->eax; vg_assert(siginfo->si_signo != 0); if (px->siginfo.si_signo != 0) { @@ -423,7 +420,7 @@ void VG_(proxy_handlesig)(const vki_ksiginfo_t *siginfo, /* First look to see if the EIP is within our interesting ranges near a syscall to work out what should happen. */ - if (sys_before <= eip && eip <= sys_restarted) { + if (sys_before <= ip && ip <= sys_restarted) { /* We are before the syscall actually ran, or it did run and wants to be restarted. Either way, set the return code to indicate a restart. This is not really any different from @@ -431,15 +428,15 @@ void VG_(proxy_handlesig)(const vki_ksiginfo_t *siginfo, the proxy and machine state here. */ vg_assert(px->state == PXS_RunSyscall); vg_assert(PLATFORM_SYSCALL_RET(px->tst->arch) == -VKI_ERESTARTSYS); - } else if (sys_after <= eip && eip <= sys_done) { + } else if (sys_after <= ip && ip <= sys_done) { /* We're after the syscall. Either it was interrupted by the signal, or the syscall completed normally. In either case - eax contains the correct syscall return value, and the new - state is effectively PXS_SysDone. */ + the usual register contains the correct syscall return value, and + the new state is effectively PXS_SysDone. */ vg_assert(px->state == PXS_RunSyscall || px->state == PXS_SysDone); px->state = PXS_SysDone; - PLATFORM_SYSCALL_RET(px->tst->arch) = eax; + PLATFORM_SYSCALL_RET(px->tst->arch) = sysnum; } px_printf(" signalled in state %s\n", pxs_name(px->state)); diff --git a/coregrind/vg_signals.c b/coregrind/vg_signals.c index 9bd8406fee..80cc82a158 100644 --- a/coregrind/vg_signals.c +++ b/coregrind/vg_signals.c @@ -1652,7 +1652,8 @@ void vg_async_signalhandler ( Int sigNo, vki_ksiginfo_t *info, struct vki_uconte vg_assert(VG_(gettid)() != VG_(main_pid)); - VG_(proxy_handlesig)(info, &uc->uc_mcontext); + VG_(proxy_handlesig)(info, UCONTEXT_INSTR_PTR(uc), + UCONTEXT_SYSCALL_NUM(uc)); } /* @@ -1679,7 +1680,8 @@ void vg_sync_signalhandler ( Int sigNo, vki_ksiginfo_t *info, struct vki_ucontex proxy LWP code has a bug) */ vg_assert(info->si_code <= VKI_SI_USER); - VG_(proxy_handlesig)(info, &uc->uc_mcontext); + VG_(proxy_handlesig)(info, UCONTEXT_INSTR_PTR(uc), + UCONTEXT_SYSCALL_NUM(uc)); return; } @@ -1852,9 +1854,9 @@ void vg_sync_signalhandler ( Int sigNo, vki_ksiginfo_t *info, struct vki_ucontex if (0) VG_(kill_self)(sigNo); /* generate a core dump */ VG_(core_panic_at)("Killed by fatal signal", - VG_(get_ExeContext2)(uc->uc_mcontext.eip, - uc->uc_mcontext.ebp, - uc->uc_mcontext.esp, + VG_(get_ExeContext2)(UCONTEXT_INSTR_PTR(uc), + UCONTEXT_FRAME_PTR(uc), + UCONTEXT_STACK_PTR(uc), VG_(valgrind_last))); } } @@ -1876,7 +1878,8 @@ static void proxy_sigvg_handler(int signo, vki_ksiginfo_t *si, struct vki_uconte vg_assert(si->si_code == VKI_SI_TKILL); vg_assert(si->_sifields._kill._pid == VG_(main_pid)); - VG_(proxy_handlesig)(si, &uc->uc_mcontext); + VG_(proxy_handlesig)(si, UCONTEXT_INSTR_PTR(uc), + UCONTEXT_SYSCALL_NUM(uc)); } } diff --git a/coregrind/x86-linux/core_platform.h b/coregrind/x86-linux/core_platform.h index 6ffe040c6b..d599811d61 100644 --- a/coregrind/x86-linux/core_platform.h +++ b/coregrind/x86-linux/core_platform.h @@ -84,7 +84,14 @@ extern Int VG_(sys_get_thread_area) ( ThreadId tid, address, return a linear address, and do limit checks too. */ extern Addr VG_(do_useseg) ( UInt seg_selector, Addr virtual_addr ); +/* --------------------------------------------------------------------- + ucontext stuff + ------------------------------------------------------------------ */ +#define UCONTEXT_INSTR_PTR(uc) ((uc)->uc_mcontext.eip) +#define UCONTEXT_STACK_PTR(uc) ((uc)->uc_mcontext.esp) +#define UCONTEXT_FRAME_PTR(uc) ((uc)->uc_mcontext.ebp) +#define UCONTEXT_SYSCALL_NUM(uc) ((uc)->uc_mcontext.eax) /*--------------------------------------------------------------------*/ /*--- end ---*/