Skip to content

Commit

Permalink
Add discriminator to MutatorContextStruct and implement MutatorContex…
Browse files Browse the repository at this point in the history
…tInitFault and MutatorContextInitThread on POSIX/Linux.

Copied from Perforce
 Change: 192577
 ServerID: perforce.ravenbrook.com
  • Loading branch information
gareth-rees committed Oct 14, 2016
1 parent 9edf039 commit 5e70f08
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 11 deletions.
12 changes: 8 additions & 4 deletions code/prmcan.c
Expand Up @@ -3,10 +3,6 @@
* $Id$
* Copyright (c) 2001-2016 Ravenbrook Limited. See end of file for license.
*
* .design: See <design/prot/> for the generic design of the interface
* which is implemented in this module including the contracts for the
* functions.
*
* .purpose: Implement the mutator context module. See <design/prmc/>.
* In this ANSI version none of the functions have a useful
* implementation.
Expand All @@ -17,6 +13,14 @@
SRCID(prmcan, "$Id$");


Bool MutatorContextCheck(MutatorContext context)
{
UNUSED(context);

return TRUE;
}


Bool MutatorContextCanStepInstruction(MutatorContext context)
{
UNUSED(context);
Expand Down
25 changes: 22 additions & 3 deletions code/prmcix.c
Expand Up @@ -24,17 +24,22 @@ SRCID(prmcix, "$Id$");
Bool MutatorContextCheck(MutatorContext context)
{
CHECKS(MutatorContext, context);
CHECKL(NONNEGATIVE(context->var));
CHECKL(context->var < MutatorContextLIMIT);
CHECKL((context->var == MutatorContextTHREAD) == (context->info == NULL));
CHECKL(context->ucontext != NULL);
return TRUE;
}


void MutatorContextInit(MutatorContext context, siginfo_t *info,
ucontext_t *ucontext)
void MutatorContextInitFault(MutatorContext context, siginfo_t *info,
ucontext_t *ucontext)
{
AVER(context != NULL);
AVER(info != NULL);
AVER(ucontext != NULL);

context->var = MutatorContextFAULT;
context->info = info;
context->ucontext = ucontext;
context->sig = MutatorContextSig;
Expand All @@ -43,6 +48,20 @@ void MutatorContextInit(MutatorContext context, siginfo_t *info,
}


void MutatorContextInitThread(MutatorContext context, ucontext_t *ucontext)
{
AVER(context != NULL);
AVER(ucontext != NULL);

context->var = MutatorContextTHREAD;
context->info = NULL;
context->ucontext = ucontext;
context->sig = MutatorContextSig;

AVERT(MutatorContext, context);
}


Res MutatorContextScan(ScanState ss, MutatorContext context,
mps_area_scan_t scan_area, void *closure)
{
Expand All @@ -63,7 +82,7 @@ Res MutatorContextScan(ScanState ss, MutatorContext context,

/* C. COPYRIGHT AND LICENSE
*
* Copyright (C) 2001-2015 Ravenbrook Limited <http://www.ravenbrook.com/>.
* Copyright (C) 2001-2016 Ravenbrook Limited <http://www.ravenbrook.com/>.
* All rights reserved. This is an open source license. Contact
* Ravenbrook for commercial licensing options.
*
Expand Down
7 changes: 5 additions & 2 deletions code/prmcix.h
Expand Up @@ -16,11 +16,14 @@

typedef struct MutatorContextStruct {
Sig sig; /* <design/sig/> */
siginfo_t *info;
MutatorContextVar var; /* Discriminator. */
siginfo_t *info; /* Signal info, if stopped by protection
* fault; NULL if stopped by thread manager. */
ucontext_t *ucontext;
} MutatorContextStruct;

extern void MutatorContextInit(MutatorContext context, siginfo_t *info, ucontext_t *ucontext);
extern void MutatorContextInitFault(MutatorContext context, siginfo_t *info, ucontext_t *ucontext);
extern void MutatorContextInitThread(MutatorContext context, ucontext_t *ucontext);

#endif /* prmcix_h */

Expand Down
1 change: 1 addition & 0 deletions code/prmclii3.c
Expand Up @@ -79,6 +79,7 @@ void Prmci3DecodeFaultContext(MRef *faultmemReturn,
AVER(faultmemReturn != NULL);
AVER(insvecReturn != NULL);
AVERT(MutatorContext, context);
AVER(context->var == MutatorContextFAULT);

/* .source.linux.kernel (linux/arch/i386/mm/fault.c). */
*faultmemReturn = (MRef)context->info->si_addr;
Expand Down
1 change: 1 addition & 0 deletions code/prmclii6.c
Expand Up @@ -83,6 +83,7 @@ void Prmci6DecodeFaultContext(MRef *faultmemReturn,
AVER(faultmemReturn != NULL);
AVER(insvecReturn != NULL);
AVERT(MutatorContext, context);
AVER(context->var == MutatorContextFAULT);

/* .source.linux.kernel (linux/arch/x86/mm/fault.c). */
*faultmemReturn = (MRef)context->info->si_addr;
Expand Down
2 changes: 1 addition & 1 deletion code/protsgix.c
Expand Up @@ -83,7 +83,7 @@ static void sigHandle(int sig, siginfo_t *info, void *uap) /* .sigh.args */
Addr base;
MutatorContextStruct context;

MutatorContextInit(&context, info, (ucontext_t *)uap);
MutatorContextInitFault(&context, info, (ucontext_t *)uap);

mode = AccessREAD | AccessWRITE; /* .sigh.mode */

Expand Down
2 changes: 1 addition & 1 deletion code/pthrdext.c
Expand Up @@ -80,7 +80,7 @@ static void suspendSignalHandler(int sig,
/* copy the ucontext structure so we definitely have it on our stack,
* not (e.g.) shared with other threads. */
ucontext = *(ucontext_t *)uap;
MutatorContextInit(&context, NULL, &ucontext);
MutatorContextInitThread(&context, &ucontext);
suspendingVictim->context = &context;
/* Block all signals except PTHREADEXT_SIGRESUME while suspended. */
sigfillset(&signal_set);
Expand Down

0 comments on commit 5e70f08

Please sign in to comment.