struct model_snapshot_members;
struct bug_message;
typedef SnapList<ModelAction *> action_list_t;
+
+extern volatile int forklock;
#endif
#include "printf.h"
extern int model_out;
-extern int switch_alloc;
#define model_print(fmt, ...) do { \
- switch_alloc = 1; \
char mprintbuf[256]; \
int printbuflen=snprintf_(mprintbuf, 256, fmt, ## __VA_ARGS__); \
int lenleft = printbuflen < 256 ? printbuflen : 256; \
lenleft-=byteswritten; \
totalwritten+=byteswritten; \
} \
- switch_alloc = 0; \
} while (0)
#ifdef CONFIG_DEBUG
/** Enable debugging assertions (via ASSERT()) */
#define CONFIG_ASSERT
+/** Enable mitigations against fork handlers that call into locks... */
+#define FORK_HANDLER_HACK
+
#endif
*/
uint64_t ModelChecker::switch_to_master(ModelAction *act)
{
- DBG();
+ if (forklock) {
+ static bool fork_message_printed = false;
+
+ if (!fork_message_printed) {
+ model_print("Fork handler trying to call into model checker...\n");
+ fork_message_printed = true;
+ }
+ delete act;
+ return 0;
+ }
+ DBG();
Thread *old = thread_current();
scheduler->set_current_thread(NULL);
ASSERT(!old->get_pending());
size_t allocatedReqs[REQUESTS_BEFORE_ALLOC] = { 0 };
int nextRequest = 0;
int howManyFreed = 0;
-int switch_alloc = 0;
#if !USE_MPROTECT_SNAPSHOT
static mspace sStaticSpace = NULL;
#endif
void *malloc(size_t size)
{
if (user_snapshot_space) {
- if (switch_alloc) {
- return model_malloc(size);
- }
/* Only perform user allocations from user context */
ASSERT(!model || thread_current());
return user_malloc(size);
void free(void * ptr)
{
if (!DontFree(ptr)) {
- if (switch_alloc) {
- return model_free(ptr);
- }
mspace_free(user_snapshot_space, ptr);
}
}
model_snapshot_space = create_mspace(numheappages * PAGESIZE, 1);
}
+volatile int forklock = 0;
+
static void fork_loop() {
/* switch back here when takesnapshot is called */
snapshotid = fork_snap->currSnapShotID;
while (true) {
pid_t forkedID;
fork_snap->currSnapShotID = snapshotid + 1;
+
+ forklock = 1;
forkedID = fork();
+ forklock = 0;
if (0 == forkedID) {
setcontext(&fork_snap->shared_ctxt);