mymemory: enforce that user allocations come from user context
authorBrian Norris <banorris@uci.edu>
Sat, 9 Mar 2013 20:54:58 +0000 (12:54 -0800)
committerBrian Norris <banorris@uci.edu>
Sat, 9 Mar 2013 20:54:58 +0000 (12:54 -0800)
model.cc
mymemory.cc
schedule.cc

index 0cc2079..2aa94cf 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -3021,6 +3021,7 @@ uint64_t ModelChecker::switch_to_master(ModelAction *act)
 {
        DBG();
        Thread *old = thread_current();
+       scheduler->set_current_thread(NULL);
        ASSERT(!old->get_pending());
        old->set_pending(act);
        if (Thread::swap(old, &system_context) < 0) {
index ea8670d..c79ad9a 100644 (file)
@@ -8,6 +8,8 @@
 #include "mymemory.h"
 #include "snapshot.h"
 #include "common.h"
+#include "threads-model.h"
+#include "model.h"
 
 #define REQUESTS_BEFORE_ALLOC 1024
 
@@ -176,9 +178,11 @@ static void * user_malloc(size_t size)
  */
 void *malloc(size_t size)
 {
-       if (user_snapshot_space)
+       if (user_snapshot_space) {
+               /* Only perform user allocations from user context */
+               ASSERT(!model || thread_current());
                return user_malloc(size);
-       else
+       else
                return HandleEarlyAllocationRequest(size);
 }
 
index 1eb57d7..62ba8fb 100644 (file)
@@ -250,7 +250,7 @@ void Scheduler::set_scheduler_thread(thread_id_t tid) {
  */
 void Scheduler::set_current_thread(Thread *t)
 {
-       ASSERT(t && !t->is_model_thread());
+       ASSERT(!t || !t->is_model_thread());
 
        current = t;
        if (DBG_ENABLED())