sigaction_SIGSEGV(): +PROT_EXEC sanity check caching for better performance.
authorshort <>
Tue, 28 Oct 2003 18:57:53 +0000 (18:57 +0000)
committershort <>
Tue, 28 Oct 2003 18:57:53 +0000 (18:57 +0000)
src/libcaptive/ps/signal.c

index 1e78c4c..68a08b3 100644 (file)
@@ -188,6 +188,7 @@ static void sigaction_SIGSEGV(int signo,siginfo_t *siginfo,struct ucontext *ucon
 {
 guint8 *reg_eip;
 const void *reg_eip_aligned;
+static const void *reg_eip_aligned_last_valid=NULL;    /* performance cache */
 
        g_return_if_fail(signo==SIGSEGV);
        g_return_if_fail(siginfo->si_signo==SIGSEGV);
@@ -200,7 +201,14 @@ const void *reg_eip_aligned;
         */
        reg_eip_aligned=(const void *)(((char *)reg_eip)-(GPOINTER_TO_UINT(reg_eip)&(PAGE_SIZE-1)));
        g_assert(reg_eip_aligned!=NULL);
-       g_return_if_fail(!(captive_mmap_map_get(reg_eip_aligned)&PROT_EXEC));
+
+       /* We do not expect any pages can get un-PROT_EXEC-ed
+        * and therefore we never invalidate our cache 'reg_eip_aligned_last_valid'.
+        */
+       if (reg_eip_aligned_last_valid!=reg_eip_aligned) {
+               g_return_if_fail(!(captive_mmap_map_get(reg_eip_aligned)&PROT_EXEC));
+               reg_eip_aligned_last_valid=reg_eip_aligned;
+               }
        
        /* all instruction notation comments are written in AT&T 'instr src,dest' syntax! */
        if (*reg_eip==0x64) {   /* prefix '%fs:' */