From: Julian Seward Date: Fri, 25 Feb 2005 02:45:39 +0000 (+0000) Subject: On AMD64 it's valid to access up to 128 bytes below %rsp. Or to be X-Git-Tag: svn/VALGRIND_3_0_0~1066 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2cfb6bc855b07248db0d6c9763d27b95314be81e;p=thirdparty%2Fvalgrind.git On AMD64 it's valid to access up to 128 bytes below %rsp. Or to be more accurate, on the amd64-linux ABI that is allowable. Anyway, parameterise the signal handler so it isn't confused by such accesses. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3252 --- diff --git a/coregrind/amd64/core_arch.h b/coregrind/amd64/core_arch.h index c7084497e6..16aaf37a4c 100644 --- a/coregrind/amd64/core_arch.h +++ b/coregrind/amd64/core_arch.h @@ -77,6 +77,10 @@ asm("movq %%rbp, %0" : "=r" (lval)); \ } while (0) +// On AMD64, it's ok to access up to 128 bytes below %rsp. +// The signal handler needs to know this. +#define ARCH_STACK_REDZONE_SIZE 128 + /* --------------------------------------------------------------------- Architecture-specific part of a ThreadState ------------------------------------------------------------------ */ diff --git a/coregrind/vg_signals.c b/coregrind/vg_signals.c index a46cdd3ef7..bebdaa5d6a 100644 --- a/coregrind/vg_signals.c +++ b/coregrind/vg_signals.c @@ -1781,17 +1781,17 @@ void vg_sync_signalhandler ( Int sigNo, vki_siginfo_t *info, struct vki_ucontext VG_(shadow_base), VG_(shadow_end)); } - if (info->si_code == 1 && /* SEGV_MAPERR */ - seg != NULL && - fault >= esp && - fault < seg->addr && + if (info->si_code == 1 && /* SEGV_MAPERR */ + seg != NULL && + fault >= (esp - ARCH_STACK_REDZONE_SIZE) && + fault < seg->addr && (seg->flags & SF_GROWDOWN)) { /* If the fault address is above esp but below the current known stack segment base, and it was a fault because there was nothing mapped there (as opposed to a permissions fault), then extend the stack segment. */ - Addr base = PGROUNDDN(esp); + Addr base = PGROUNDDN(esp - ARCH_STACK_REDZONE_SIZE); if (seg->len + (seg->addr - base) <= VG_(threads)[tid].stack_size && (void*)-1 != VG_(mmap)((Char *)base, seg->addr - base, VKI_PROT_READ|VKI_PROT_WRITE|VKI_PROT_EXEC, diff --git a/coregrind/x86/core_arch.h b/coregrind/x86/core_arch.h index 471f15f750..9feb3a544d 100644 --- a/coregrind/x86/core_arch.h +++ b/coregrind/x86/core_arch.h @@ -77,6 +77,10 @@ asm("movl %%ebp, %0" : "=r" (ebp)); \ } while (0) +// On X86, any access below %esp is illegal. +// The signal handler needs to know this. +#define ARCH_STACK_REDZONE_SIZE 0 + /* --------------------------------------------------------------------- Architecture-specific part of a ThreadState ------------------------------------------------------------------ */