mirror of
https://github.com/ioacademy-jikim/debugging
synced 2025-06-08 08:26:14 +00:00
49 lines
917 B
C
49 lines
917 B
C
/* Test of correct simulation for uc->uc_link in a signal handler. */
|
|
|
|
#include <assert.h>
|
|
#include <signal.h>
|
|
#include <stdio.h>
|
|
#include <ucontext.h>
|
|
|
|
static void sighandler(int sig, siginfo_t *sip, ucontext_t *ucp)
|
|
{
|
|
ucontext_t uc2;
|
|
|
|
/* Current uc_link value has to be equal to ucp. */
|
|
getcontext(&uc2);
|
|
assert(uc2.uc_link == ucp);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
ucontext_t uc;
|
|
struct sigaction sa;
|
|
|
|
/* Current uc_link value has to be NULL. */
|
|
if (getcontext(&uc)) {
|
|
perror("getcontext");
|
|
return 1;
|
|
}
|
|
assert(!uc.uc_link);
|
|
|
|
sa.sa_handler = sighandler;
|
|
sa.sa_flags = SA_SIGINFO;
|
|
if (sigfillset(&sa.sa_mask)) {
|
|
perror("sigfillset");
|
|
return 1;
|
|
}
|
|
if (sigaction(SIGUSR1, &sa, NULL)) {
|
|
perror("sigaction");
|
|
return 1;
|
|
}
|
|
|
|
raise(SIGUSR1);
|
|
|
|
/* Current uc_link value has to be NULL. */
|
|
getcontext(&uc);
|
|
assert(!uc.uc_link);
|
|
|
|
return 0;
|
|
}
|
|
|