better logics in sigstack allocation on native platforms

This commit is contained in:
gbeauche
2005-03-28 09:50:58 +00:00
parent 88b493bf38
commit f9e3fd28a1

View File

@@ -264,22 +264,22 @@ static void build_sigregs(sigregs *srp, machine_regs *mrp)
static struct sigaltstack sig_stacks[SIG_STACK_COUNT]; // Stacks for signal handlers static struct sigaltstack sig_stacks[SIG_STACK_COUNT]; // Stacks for signal handlers
static int sig_stack_id = 0; // Stack slot currently used static int sig_stack_id = 0; // Stack slot currently used
static inline void sig_stack_acquire(void) static inline int sig_stack_acquire(void)
{ {
if (++sig_stack_id == SIG_STACK_COUNT) { if (sig_stack_id >= SIG_STACK_COUNT) {
printf("FATAL: signal stack overflow\n"); printf("FATAL: signal stack overflow\n");
return; return -1;
} }
sigaltstack(&sig_stacks[sig_stack_id], NULL); return sigaltstack(&sig_stacks[sig_stack_id++], NULL);
} }
static inline void sig_stack_release(void) static inline int sig_stack_release(void)
{ {
if (--sig_stack_id < 0) { if (sig_stack_id <= 0) {
printf("FATAL: signal stack underflow\n"); printf("FATAL: signal stack underflow\n");
return; return -1;
} }
sigaltstack(&sig_stacks[sig_stack_id], NULL); return sigaltstack(&sig_stacks[--sig_stack_id], NULL);
} }
#endif #endif
@@ -576,8 +576,7 @@ int main(int argc, char **argv)
sig_stacks[i].ss_flags = 0; sig_stacks[i].ss_flags = 0;
sig_stacks[i].ss_size = SIG_STACK_SIZE; sig_stacks[i].ss_size = SIG_STACK_SIZE;
} }
sig_stack_id = 0; if (sig_stack_acquire() < 0) {
if (sigaltstack(&sig_stacks[0], NULL) < 0) {
sprintf(str, GetString(STR_SIGALTSTACK_ERR), strerror(errno)); sprintf(str, GetString(STR_SIGALTSTACK_ERR), strerror(errno));
ErrorAlert(str); ErrorAlert(str);
goto quit; goto quit;