/* $Id: test05.c,v 2.1 2000/05/29 13:10:46 cibrario Rel $ Chf test program. Condition & Handler stacks oveflow checks - single and multithreaded $Log: test05.c,v $ Revision 2.1 2000/05/29 13:10:46 cibrario *** empty log message *** */ #include #include #include #include #ifdef _REENTRANT #include #endif #define CHF_MODULE_ID 255 #define CHF_EXTENDED_INFO #include "Chf.h" #define H_STACK_SIZE 10 #define C_STACK_SIZE 30 /* Dummy handler; pushed only to verify that the handler stack overflow checks are correct. */ ChfAction h1( const ChfDescriptor *c, const ChfState s, ChfPointer p ) { return CHF_RESIGNAL; } /* Overflow check handler; it unwinds if the CHF_F_HDLR_STACK_FULL condition is signalled exactly after H_STACK_SIZE-2 invocations of ChfPushHandler(), it resignals a modified condition if the condition is signalled too early */ ChfAction h2( const ChfDescriptor *c, const ChfState s, ChfPointer p ) { int push_count = *((int *)p); ChfAction action; if(s == CHF_SIGNALING) { if(ChfGetModuleId(c) == CHF_SET && ChfGetConditionCode(c) == CHF_F_HDLR_STACK_FULL) { /* Handler stack is full; check correctness of the descriptor */ if(push_count == H_STACK_SIZE-2 && ChfGetNextDescriptor(c) == NULL && ChfGetSeverity(c) == CHF_FATAL) action = CHF_UNWIND; else { ChfCondition 11, CHF_FATAL, push_count, H_STACK_SIZE-2 ChfEnd; action = CHF_RESIGNAL; } } } else action = CHF_RESIGNAL; return action; } /* Overflow check handler; it unwinds if the CHF_F_COND_STACK_FULL condition is signalled exactly after C_STACK_SIZE invocations of ChfCondition, it resignals a modified condition if the condition is signalled too early */ ChfAction h3( const ChfDescriptor *c, const ChfState s, ChfPointer p ) { int push_count = *((int *)p); ChfAction action; if(s == CHF_SIGNALING) { if(ChfGetModuleId(c) == CHF_SET && ChfGetConditionCode(c) == CHF_F_COND_STACK_FULL) { /* Handler stack is full; check correctness of the descriptor */ if(push_count == C_STACK_SIZE && ChfGetNextDescriptor(c) == NULL && ChfGetSeverity(c) == CHF_FATAL) action = CHF_UNWIND; else { ChfCondition 12, CHF_FATAL, push_count, C_STACK_SIZE ChfEnd; action = CHF_RESIGNAL; } } } else action = CHF_RESIGNAL; return action; } void *task(void *arg) { int push_count = 0; sigjmp_buf jb; /* The sleep() is here to increase contention between threads */ sleep(1); printf("\tThread %d\n", (int)arg); /* Check handler stack overflow checks */ if(sigsetjmp(jb, 1) == 0) { int i; /* Push the handler */ ChfPushHandler(h2, jb, (ChfPointer)(&push_count)); /* The sleep() is here to increase contention between threads */ sleep(1); /* Push dummy handlers until an error should occur */ for(; push_count