...
This recommendation is related to SIG32-C. Do not call longjmp() from inside a signal handler and ENV32-C. All atexit handlers must return normally.
Implementation Details
glibc v2.11.1 defines the jmp_buf
type as follows:
Platform | | Registers Saved |
---|---|---|
i386 | 24 | |
x86_64 | 64 | |
No other state information is saved.
Noncompliant Code Example
...
Code Block | ||
---|---|---|
| ||
jmp_buf buf; unsigned char b[] = {0xe5, 0x06, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00}; int main(void) { setup(); do_stuff(); return 0; } void setup(void) { f(); } void f(void) { g(); } void g(void) { if (setjmp(buf) == 0) { printf("setjmp() invoked\n"); } else { printf("longjmp() invoked\n"); } } void do_stuff(void) { char a[8]; memcpy(a, b, 8); /* ... stuff ... */ longjmp(buf, 1); } void bad(void) { printf("Should not be called!\n"); exit(1); } |
Implementation Details
When compiled for x86-64 using GCC v4.1.2, the above example outputs the following when run:
...