| 1 | #include <lwp.h> |
| 2 | #include <stddef.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <unistd.h> |
| 5 | #include <signal.h> |
| 6 | |
| 7 | volatile int sem = 0; |
| 8 | |
| 9 | static void bar() { |
| 10 | char F = 'b'; |
| 11 | sem = 1; |
| 12 | while (1) continue; // Frame bar |
| 13 | } |
| 14 | |
| 15 | static void foo(void (*boomer)()) { |
| 16 | char F = 'f'; |
| 17 | boomer(); // Frame foo |
| 18 | } |
| 19 | |
| 20 | static void lwp_main(void *unused) { |
| 21 | char F = 'l'; |
| 22 | foo(boomer: bar); // Frame lwp_main |
| 23 | } |
| 24 | |
| 25 | int main(int argc, char **argv) { |
| 26 | ucontext_t uc; |
| 27 | lwpid_t lid; |
| 28 | static const size_t ssize = 16 * 1024; |
| 29 | void *stack; |
| 30 | |
| 31 | stack = malloc(size: ssize); |
| 32 | _lwp_makecontext(&uc, lwp_main, NULL, NULL, stack, ssize); |
| 33 | _lwp_create(&uc, 0, &lid); |
| 34 | while (sem != 1) continue; |
| 35 | kill(pid: getpid(), SIGSEGV); |
| 36 | _lwp_wait(lid, NULL); |
| 37 | } |
| 38 | |