diff --git a/mps/code/prmcxc.c b/mps/code/prmcxc.c index d521dcb96ca..315f1d31c9f 100644 --- a/mps/code/prmcxc.c +++ b/mps/code/prmcxc.c @@ -24,19 +24,39 @@ SRCID(prmcxc, "$Id$"); Bool MutatorContextCheck(MutatorContext context) { CHECKS(MutatorContext, context); + CHECKL(sizeof *context->threadState == sizeof(THREAD_STATE_S)); + CHECKL(NONNEGATIVE(context->var)); + CHECKL(context->var < MutatorContextLIMIT); + CHECKL((context->var == MutatorContextTHREAD) == (context->address == NULL)); CHECKL(context->threadState != NULL); return TRUE; } -void MutatorContextInit(MutatorContext context, Addr address, - THREAD_STATE_S *threadState) +void MutatorContextInitFault(MutatorContext context, Addr address, + THREAD_STATE_S *threadState) +{ + AVER(context != NULL); + AVER(address != NULL); + AVER(threadState != NULL); + + context->var = MutatorContextFAULT; + context->address = address; + context->threadState = threadState; + context->sig = MutatorContextSig; + + AVERT(MutatorContext, context); +} + + +void MutatorContextInitThread(MutatorContext context, + THREAD_STATE_S *threadState) { AVER(context != NULL); AVER(threadState != NULL); - context->address = address; - AVER(sizeof *context->threadState == sizeof(THREAD_STATE_S)); + context->var = MutatorContextTHREAD; + context->address = NULL; context->threadState = threadState; context->sig = MutatorContextSig; @@ -50,7 +70,9 @@ Res MutatorContextScan(ScanState ss, MutatorContext context, THREAD_STATE_S *mc; Res res; + AVERT(ScanState, ss); AVERT(MutatorContext, context); + AVER(context->var == MutatorContextTHREAD); /* This scans the root registers (.context.regroots). It also unnecessarily scans the rest of the context. The optimisation diff --git a/mps/code/prmcxc.h b/mps/code/prmcxc.h index 832b0c4015a..896fa87313c 100644 --- a/mps/code/prmcxc.h +++ b/mps/code/prmcxc.h @@ -16,13 +16,16 @@ typedef struct MutatorContextStruct { Sig sig; /* */ - Addr address; + MutatorContextVar var; /* Discriminator. */ + Addr address; /* Fault address, if stopped by protection + * fault; NULL if stopped by thread manager. */ THREAD_STATE_S *threadState; /* FIXME: Might need to get the floats in case the compiler stashes intermediate values in them. */ } MutatorContextStruct; -extern void MutatorContextInit(MutatorContext context, Addr address, THREAD_STATE_S *threadState); +extern void MutatorContextInitFault(MutatorContext context, Addr address, THREAD_STATE_S *threadState); +extern void MutatorContextInitThread(MutatorContext context, THREAD_STATE_S *threadState); #endif /* prmcxc_h */ diff --git a/mps/code/prmcxci3.c b/mps/code/prmcxci3.c index 1e51dec7aae..853b28a70f1 100644 --- a/mps/code/prmcxci3.c +++ b/mps/code/prmcxci3.c @@ -74,6 +74,7 @@ void Prmci3DecodeFaultContext(MRef *faultmemReturn, AVER(faultmemReturn != NULL); AVER(insvecReturn != NULL); AVERT(MutatorContext, context); + AVER(context->var == MutatorContextFAULT); *faultmemReturn = (MRef)context->address; *insvecReturn = (Byte*)context->threadState->__eip; diff --git a/mps/code/prmcxci6.c b/mps/code/prmcxci6.c index 1c7d6ac5f91..f16967b0f85 100644 --- a/mps/code/prmcxci6.c +++ b/mps/code/prmcxci6.c @@ -79,6 +79,7 @@ void Prmci6DecodeFaultContext(MRef *faultmemReturn, AVER(faultmemReturn != NULL); AVER(insvecReturn != NULL); AVERT(MutatorContext, context); + AVER(context->var == MutatorContextFAULT); *faultmemReturn = (MRef)context->address; *insvecReturn = (Byte*)context->threadState->__rip; diff --git a/mps/code/protxc.c b/mps/code/protxc.c index 2674fd0610e..3edbfd8ddb4 100644 --- a/mps/code/protxc.c +++ b/mps/code/protxc.c @@ -238,8 +238,8 @@ static void protCatchOne(void) /* The cast via Word suppresses "cast to pointer from integer of different size" warnings in GCC, for the XCI3GC build. */ - MutatorContextInit(&context, (Addr)(Word)request.code[1], - (void *)request.old_state); + MutatorContextInitFault(&context, (Addr)(Word)request.code[1], + (void *)request.old_state); if (ArenaAccess(context.address, AccessREAD | AccessWRITE, diff --git a/mps/code/thxc.c b/mps/code/thxc.c index 0952c75fa08..3ef92e63aa6 100644 --- a/mps/code/thxc.c +++ b/mps/code/thxc.c @@ -236,7 +236,7 @@ Res ThreadScan(ScanState ss, Thread thread, Word *stackCold, order to assert that the thread is suspended, but it's probably unnecessary and is a lot of work to check a static condition. */ - MutatorContextInit(&context, NULL, &threadState); + MutatorContextInitThread(&context, &threadState); count = THREAD_STATE_COUNT; AVER(sizeof(*context.threadState) == count * sizeof(natural_t));