2 /* This test tests whether registers are correctly restored after a
3 * signal handler is executed. The assembly file (test57loop.S) puts
4 * 'random' values in the registers, and the C code checks whether
5 * these values are the same, before and after the signal handler.
8 #define _POSIX_SOURCE 1
16 #include <sys/types.h>
19 #define SIGNAL SIGUSR1
21 volatile int remaining_invocations
= 2, handler_level
= 0;
23 void check_context_loop(void);
25 #define REGS 8 /* how many registers pusha and popa save. */
27 #define ESP 3 /* where is esp saved? */
29 unsigned long newstate
[REGS
], origstate
[REGS
];
31 static void handler(int signal
)
36 remaining_invocations
--;
37 if(remaining_invocations
< 1)
40 sigaddset(&set
, SIGNAL
);
41 sigprocmask(SIG_UNBLOCK
, &set
, &oset
);
46 int main(int argc
, char *argv
[])
52 if(signal(SIGNAL
, handler
) == SIG_ERR
)
57 if((child_pid
=fork()) < 0)
63 /* Keep signaling the parent until
66 while((ppid
= getppid()) > 1) {
67 if(kill(ppid
, SIGNAL
) < 0)
79 /* correct 2nd esp for 'pusha' difference. */
80 newstate
[ESP
] += REGS
*4;
82 for(i
= 0; i
< REGS
; i
++) {
84 printf("%d %08lx %08lx diff ",
85 i
, newstate
[i
], origstate
[i
]);
87 if(newstate
[i
] != origstate
[i
]) {
88 fprintf(stderr
, "reg %d changed; "
89 "found 0x%lx, expected 0x%lx\n",
90 i
, newstate
[i
], origstate
[i
]);
95 if(!err
) printf("ok\n");