This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: What can a signal handler do with SIGSTKSZ?
- From: Florian Weimer <fweimer at redhat dot com>
- To: Carlos O'Donell <carlos at redhat dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Fri, 11 Jan 2019 20:40:29 +0100
- Subject: Re: What can a signal handler do with SIGSTKSZ?
- References: <e4215c6e-e8a4-a9b6-d88f-3c54e262711a@redhat.com>
* Carlos O'Donell:
> In the continuing series of "What can X do with Y?" [1]
>
> I would like to get consensus on what a signal handler can do with
> SIGSTKSZ amount of space.
>
> I propose the following:
> ~~~
> The implementation only guarantees that a signal handler can
> manipulate a reasonable amount of local variables (no more than
> 2 KiB worth), and can read and write to memory, carry out atomic
> operations, and call simple C library functions that do similar
> memory and simple string operations e.g. memcpy, memset, strcmp,
> strcpy. The amount of signal stack allocated for SIGSTKSZ is not
> sufficient to call complex signal-safe functions e.g. fork, _exit,
> abort, nor any that can be canceled (requires enough stack for
> cancellation). Any other operations or function calls in the
> signal handler should be evaluated for runtime stack usage and
> additional stack beyond SIGSTKSZ should be allocated.
> ~~~
>
> Thoughts?
I have posted some numbers here:
[PATCH] nptl: New test nptl/tst-stack-usage
<https://sourceware.org/ml/libc-alpha/2018-12/msg00271.html>
x86_64: MINSIGSTKSZ too small for AVX-512F support
<https://sourceware.org/bugzilla/show_bug.cgi?id=20305>
I did not measure dynamic linker overhead. On x86-64, due to the use of
XSAVE, I expect it to be comparable to signal delivery, perhaps slightly
worse. That means that the default SIGSTKSZ (8192 bytes I think) is
really tight with your 2 KiB rule and lazy binding.
It's also non-obvious that vfprintf needs more than 8192 bytes of stack
with some streams (which includes the fake stream in dprintf, I think).
Furthermore, you'd also have to use sigaction with a proper sa_mask
value for correctness, which I believe is rare.
Thanks,
Florian