#ifndef _XOPEN_SOURCE #define _XOPEN_SOURCE 800 #endif #include #include #include #include #include #include static atomic_uintptr_t stack_base; static atomic_size_t stack_size; static atomic_int stack_flags; static void handler(int signo, siginfo_t *restrict info, void *context) { // context = ((ucontext_t *)context)->uc_link; if(!context) { return; } const stack_t stack = ((ucontext_t *)context)->uc_stack; stack_base = (uintptr_t)stack.ss_sp; stack_size = stack.ss_size; stack_flags = stack.ss_flags; } int main(void) { (void)setlocale(LC_ALL, ""); if(!atomic_is_lock_free(&stack_base) || !atomic_is_lock_free(&stack_size) || !atomic_is_lock_free(&stack_flags)) { fputs("Atomic type is not lock-free\n", stderr); exit(EXIT_FAILURE); } struct sigaction act = { .sa_sigaction = handler, .sa_flags = SA_SIGINFO }; if(sigemptyset(&act.sa_mask) == -1 || sigprocmask(SIG_SETMASK, &act.sa_mask, NULL) == -1 || sigaction(SIGUSR1, &act, NULL) == -1 || raise(SIGUSR1) || printf("%p\t%zu\t%#x\n", (void *)stack_base, (size_t)stack_size, (unsigned int)stack_flags) < 0) { perror(NULL); exit(EXIT_FAILURE); } }