x86: sigaltstack problems
Kostik Belousov
kostikbel at gmail.com
Fri Feb 15 16:23:59 UTC 2008
On Fri, Feb 15, 2008 at 09:40:09AM +0200, Sergei Trofimovich wrote:
> On Thu, 14 Feb 2008 11:40:21 -0700
> Bert JW Regeer <xistence at 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;
> }
I do not see a problem on RELENG_7.
The tail of the truss output is below:
sigaltstack(0xbfbfe638,0x0,0x1,0x0,0x0,0x1) = 0 (0x0)
sigaction(SIGALRM,{ 0x8048550 SA_ONSTACK ss_t },0x0) = 0 (0x0)
setitimer(0,{0.000000, 1.000000},{0.000000, 0.000000}) = 0 (0x0)
SIGNAL 14 (SIGALRM)
sigreturn(0x28209500,0xe,0x0,0x28209500,0x0,0x8048550) = 0 (0x0)
fstat(1,{mode=crw------- ,inode=137,size=0,blksize=4096}) = 0 (0x0)
ioctl(1,TIOCGETA,0xbfbfe4e8) = 0 (0x0)
caught alarm signal
write(1,"caught alarm signal\n",20) = 20 (0x14)
process exit, rval = 0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20080215/6db30677/attachment.pgp
More information about the freebsd-hackers
mailing list