From: Brian Norris <banorris@uci.edu>
Date: Thu, 14 Jun 2012 22:31:44 +0000 (-0700)
Subject: snapshot: refactor the fork-based stack initialization
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=8b76d39eff3f6e27d416123292641ae36f88ca06;p=c11tester.git

snapshot: refactor the fork-based stack initialization

This complicated code block uses a getcontext()/setcontext() pair with an
'alreadySwapped' boolean (int) to perform basically the same functionality as
'swapcontext()'. Refactor this code to make it simpler.
---

diff --git a/snapshot.cc b/snapshot.cc
index d8eda7f5..a50835d1 100644
--- a/snapshot.cc
+++ b/snapshot.cc
@@ -178,18 +178,13 @@ void initSnapShotLibrary(unsigned int numbackingpages,
 	createSharedLibrary();
 
 	//step 2 setup the stack context.
-
-	int alreadySwapped = 0;
-	getcontext( &savedSnapshotContext );
-	if( !alreadySwapped ){
-		alreadySwapped = 1;
-		ucontext_t swappedContext, newContext;
-		getcontext( &newContext );
-		newContext.uc_stack.ss_sp = sTheRecord->mStackBase;
-		newContext.uc_stack.ss_size = STACK_SIZE_DEFAULT;
-		makecontext( &newContext, entryPoint, 0 );
-		swapcontext( &swappedContext, &newContext );
-	}
+	ucontext_t newContext;
+	getcontext( &newContext );
+	newContext.uc_stack.ss_sp = sTheRecord->mStackBase;
+	newContext.uc_stack.ss_size = STACK_SIZE_DEFAULT;
+	makecontext( &newContext, entryPoint, 0 );
+	/* switch to a new entryPoint context, on a new stack */
+	swapcontext(&savedSnapshotContext, &newContext);
 
 	//add the code to take a snapshot here...
 	//to return to user process, do a second swapcontext...