Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Feb 2008 18:04:35 +0200
From:      Kostik Belousov <kostikbel@gmail.com>
To:        Sergei Trofimovich <st@anti-virus.by>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: x86: sigaltstack problems
Message-ID:  <20080215160435.GG57756@deviant.kiev.zoral.com.ua>
In-Reply-To: <20080215094009.07079ef0@st.vba.com.by>
References:  <20080214174645.5bdb2879@st.vba.com.by> <49BA5EE4-D845-4F74-A61D-3CD2AAB41E53@0x58.com> <20080215094009.07079ef0@st.vba.com.by>

next in thread | previous in thread | raw e-mail | index | archive | help

--pccYjlC/mV5H7SoF
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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@0x58.com> wrote:
>=20
> > On Feb 14, 2008, at 08:46 , Sergei Trofimovich wrote:
> >=20
> > > Attached file causes segfaults on freebsd 4,5,6
> > > but keeps alive in linux.
> > >
> > > IANIAML, so please CC me explicitly.
> > >
> > > Thanks!
> >=20
> > You did not attach any files.
> >=20
> > Bert JW Regeer
>=20
> Sorry, something stripped it out.
>=20
> (copy of file is here -  http://rafb.net/p/OYjAUQ55.html)
>=20
> The question is:
> Is it okay the program segfaults?
>=20
> I thought sigaltstack is the way not to mess our (possible invalid) stack.
> IANIAML, so please CC me explicitly.
>=20
> //////////////////////////////////////////////////////
> //main.c:
> //////////////////////////////////////////////////////
>=20
> #include <stdio.h>
> #include <stdlib.h>
> #include <assert.h>
> #include <string.h>
>=20
> #include <sys/time.h>
> #include <signal.h>
> #include <unistd.h>
>=20
> volatile int alarmed =3D 0;
> void alarm_handler(int signo)
> {
>     alarmed =3D 1;
> }
>=20
> #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 */);
>=20
> int main ()
> {
>     /* alternate stack not to segfault on signal arrival */
>     stack_t ss;
>     ss.ss_sp =3D malloc(SIGSTKSZ);
>     if (ss.ss_sp =3D=3D NULL) exit (1);
>     ss.ss_size =3D SIGSTKSZ;
>     ss.ss_flags =3D 0;
>     if (sigaltstack(&ss, NULL) =3D=3D -1) exit (2);
>=20
>=20
>     struct sigaction sa;
>     memset(&sa, 0, sizeof(sa));
>     sigfillset(&sa.sa_mask);
>     sa.sa_handler =3D alarm_handler;
>     // we DO alternate stack on signal arrival
>     sa.sa_flags   =3D SA_ONSTACK;
>     sigaction(SIGALRM, &sa, NULL);
>=20
>     alarm (1);
>=20
>     // loop on volatile var
>     EMIT_ASM_CALL(alarmed);
>=20
>     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)      =3D 0 (0x0)
sigaction(SIGALRM,{ 0x8048550 SA_ONSTACK ss_t },0x0) =3D 0 (0x0)
setitimer(0,{0.000000, 1.000000},{0.000000, 0.000000}) =3D 0 (0x0)
SIGNAL 14 (SIGALRM)
sigreturn(0x28209500,0xe,0x0,0x28209500,0x0,0x8048550) =3D 0 (0x0)
fstat(1,{mode=3Dcrw------- ,inode=3D137,size=3D0,blksize=3D4096}) =3D 0 (0x=
0)
ioctl(1,TIOCGETA,0xbfbfe4e8)                     =3D 0 (0x0)
caught alarm signal
write(1,"caught alarm signal\n",20)              =3D 20 (0x14)
process exit, rval =3D 0

--pccYjlC/mV5H7SoF
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (FreeBSD)

iEYEARECAAYFAke1uBIACgkQC3+MBN1Mb4g2eACfaeeOta1MaRAEdYatsuNs1uPD
ko8AoMrzhjCvF5H/teVVC5g9LjGiRzD/
=TCv9
-----END PGP SIGNATURE-----

--pccYjlC/mV5H7SoF--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080215160435.GG57756>