Trying (not) to crash with libpthread (6.3-RELEASE)
Oliver Fromme
olli at lurza.secnetix.de
Fri May 16 19:14:17 UTC 2008
Mike <deathjestr at gmail.com> wrote:
> Jille Timmermans wrote:
> > void
> > sigcatcher(int sig) {
> > printf("[%p] signal %d\n", pthread_self(), sig);
> > printf("Test (probably) succeeded\n");
> > fflush(NULL);
> > success=1;
> > exit(0);
> > }
>
> Take a look at the man page for sigaction(2). Here's an excerpt:
>
> "All functions not in the above lists are considered to be unsafe with
> respect to signals. That is to say, the behaviour of such functions when
> called from a signal handler is undefined. In general though, signal
> handlers should do little more than set a flag; most other actions are
> not safe."
Additionally, the "success" variable should be
declared as "volatile sig_atomic_t".
By the way, this code ...
> > char *x=malloc(1);
> > [...]
> > x[666]=0;
.. does not necessarily cause a SIGSEGV. It may do so,
but it is not guaranteed. It may as well write into a
random memory area that happens to belong to your process,
too. The result is undefined, i.e. it could be anything.
If you need to send a SIGSEGV to yourself reliably, the
best way is to kill(getpid(), SIGSEGV).
Best regards
Oliver
--
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart
FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd
"File names are infinite in length, where infinity is set to 255 characters."
-- Peter Collinson, "The Unix File System"
More information about the freebsd-hackers
mailing list