Date: Fri, 15 Feb 2008 09:40:09 +0200 From: Sergei Trofimovich <st@anti-virus.by> To: freebsd-hackers@freebsd.org Subject: Re: x86: sigaltstack problems Message-ID: <20080215094009.07079ef0@st.vba.com.by> In-Reply-To: <49BA5EE4-D845-4F74-A61D-3CD2AAB41E53@0x58.com> References: <20080214174645.5bdb2879@st.vba.com.by> <49BA5EE4-D845-4F74-A61D-3CD2AAB41E53@0x58.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 14 Feb 2008 11:40:21 -0700 Bert JW Regeer <xistence@0x58.com> wrote: > On Feb 14, 2008, at 08:46 , Sergei Trofimovich wrote: > > > Attached file causes segfaults on freebsd 4,5,6 > > but keeps alive in linux. > > > > IANIAML, so please CC me explicitly. > > > > Thanks! > > You did not attach any files. > > Bert JW Regeer Sorry, something stripped it out. (copy of file is here - http://rafb.net/p/OYjAUQ55.html) The question is: Is it okay the program segfaults? I thought sigaltstack is the way not to mess our (possible invalid) stack. IANIAML, so please CC me explicitly. ////////////////////////////////////////////////////// //main.c: ////////////////////////////////////////////////////// #include <stdio.h> #include <stdlib.h> #include <assert.h> #include <string.h> #include <sys/time.h> #include <signal.h> #include <unistd.h> volatile int alarmed = 0; void alarm_handler(int signo) { alarmed = 1; } #define EMIT_ASM_CALL(aflag) \ asm volatile( \ "nop \t\n" \ /* backup and mess esp */ \ "movl %%esp, %%ebp \t\n" \ "xorl %%eax, %%eax \t\n" \ "movl %%eax, %%esp \t\n" \ \ "while_not_alarmed: \t\n" \ "movl %0, %%eax \t\n" \ "test %%eax, %%eax \t\n" \ \ /* loop on volatile var */ \ "jz while_not_alarmed \t\n" \ \ /* restore esp */ \ "movl %%ebp, %%esp \t\n" \ "nop \t\n" \ : \ : "m"(aflag) \ : "%eax", "%ebp", "%esp","cc" /* we mess up EFLAGS */); int main () { /* alternate stack not to segfault on signal arrival */ stack_t ss; ss.ss_sp = malloc(SIGSTKSZ); if (ss.ss_sp == NULL) exit (1); ss.ss_size = SIGSTKSZ; ss.ss_flags = 0; if (sigaltstack(&ss, NULL) == -1) exit (2); struct sigaction sa; memset(&sa, 0, sizeof(sa)); sigfillset(&sa.sa_mask); sa.sa_handler = alarm_handler; // we DO alternate stack on signal arrival sa.sa_flags = SA_ONSTACK; sigaction(SIGALRM, &sa, NULL); alarm (1); // loop on volatile var EMIT_ASM_CALL(alarmed); printf ("caught alarm signal\n"); return 0; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080215094009.07079ef0>