clock = (modelclock_t *)snapshot_calloc(num_threads, sizeof(int));
if (parent)
- std::memcpy(clock, parent->clock, parent->num_threads * sizeof(modelclock_t));
+ real_memcpy(clock, parent->clock, parent->num_threads * sizeof(modelclock_t));
if (act != NULL)
clock[id_to_int(act->get_tid())] = act->get_seq_number();
int newCapacity = copytoindex * 2;
thread_id_t *newthread = (thread_id_t *)snapshot_malloc(sizeof(thread_id_t) * newCapacity);
modelclock_t *newreadClock = (modelclock_t *)snapshot_malloc(sizeof(modelclock_t) * newCapacity);
- std::memcpy(newthread, record->thread, copytoindex * sizeof(thread_id_t));
- std::memcpy(newreadClock, record->readClock, copytoindex * sizeof(modelclock_t));
+ real_memcpy(newthread, record->thread, copytoindex * sizeof(thread_id_t));
+ real_memcpy(newreadClock, record->readClock, copytoindex * sizeof(modelclock_t));
snapshot_free(record->readClock);
snapshot_free(record->thread);
record->readClock = newreadClock;
}
argc++; //first parameter is executable name
char optcpy[index + 1];
- memcpy(optcpy, options, index+1);
+ real_memcpy(optcpy, options, index+1);
char * argv[argc + 1];
argv[0] = NULL;
argv[1] = optcpy;
#include "plugins.h"
ModelChecker *model = NULL;
+int inside_model = 0;
void placeholder(void *) {
ASSERT(0);
"Copyright (c) 2013 and 2019 Regents of the University of California. All rights reserved.\n"
"Distributed under the GPLv2\n"
"Written by Weiyu Luo, Brian Norris, and Brian Demsky\n\n");
+ init_memory_ops();
memset(&stats,0,sizeof(struct execution_stats));
init_thread = new Thread(execution->get_next_id(), (thrd_t *) model_malloc(sizeof(thrd_t)), &placeholder, NULL, NULL);
#ifdef TLS
Thread *thr = getNextThread(old);
if (thr != nullptr) {
scheduler->set_current_thread(thr);
-
+ inside_model = 0;
if (Thread::swap(old, thr) < 0) {
perror("swap threads");
exit(EXIT_FAILURE);
delete act;
return 0;
}
+ inside_model = 1;
+
DBG();
Thread *old = thread_current();
old->set_state(THREAD_READY);
void print_stats() const;
};
+extern int inside_model;
extern ModelChecker *model;
void parse_options(struct model_params *params);
void install_trace_analyses(ModelExecution *execution);
{
snapshot_free(ptr);
}
+
+void * (*volatile real_memcpy)(void * dst, const void *src, size_t n) = NULL;
+void * (*volatile real_memmove)(void * dst, const void *src, size_t len) = NULL;
+void (*volatile real_bzero)(void * dst, size_t len) = NULL;
+void * (*volatile real_memset)(void * dst, int c, size_t len) = NULL;
+
+void init_memory_ops()
+{
+ if (!real_memcpy) {
+ real_memcpy = (void * (*)(void * dst, const void *src, size_t n)) 1;
+ real_memcpy = (void * (*)(void * dst, const void *src, size_t n))dlsym(RTLD_NEXT, "memcpy");
+ }
+ if (!real_memmove) {
+ real_memmove = (void * (*)(void * dst, const void *src, size_t n)) 1;
+ real_memmove = (void * (*)(void * dst, const void *src, size_t n))dlsym(RTLD_NEXT, "memmove");
+ }
+ if (!real_memset) {
+ real_memset = (void * (*)(void * dst, int c, size_t n)) 1;
+ real_memset = (void * (*)(void * dst, int c, size_t n))dlsym(RTLD_NEXT, "memset");
+ }
+ if (!real_bzero) {
+ real_bzero = (void (*)(void * dst, size_t len)) 1;
+ real_bzero = (void (*)(void * dst, size_t len))dlsym(RTLD_NEXT, "bzero");
+ }
+}
+
+void * memcpy(void * dst, const void * src, size_t n) {
+ if (false && model && !inside_model) {
+ thread_id_t tid = thread_current_id();
+ if (((uintptr_t)src&7) == 0 && ((uintptr_t)dst&7) == 0 && (n&7) == 0) {
+ for (uint i = 0; i < (n>>3); i++) {
+ raceCheckRead64(tid, (void *)(((char *)src) + i));
+ ((volatile uint64_t *)dst)[i] = ((uint64_t *)src)[i];
+ raceCheckWrite64(tid, (void *)(((char *)src) + i));
+ }
+ } else if (((uintptr_t)src&3) == 0 && ((uintptr_t)dst&3) == 0 && (n&3) == 0) {
+ for (uint i = 0; i < (n>>2); i++) {
+ raceCheckRead32(tid, (void *)(((char *)src) + i));
+ ((volatile uint32_t *)dst)[i] = ((uint32_t *)src)[i];
+ raceCheckWrite32(tid, (void *)(((char *)src) + i));
+ }
+ } else if (((uintptr_t)src&1) == 0 && ((uintptr_t)dst&1) == 0 && (n&1) == 0) {
+ for (uint i = 0; i < (n>>1); i++) {
+ raceCheckRead16(tid, (void *)(((char *)src) + i));
+ ((volatile uint16_t *)dst)[i] = ((uint16_t *)src)[i];
+ raceCheckWrite16(tid, (void *)(((char *)src) + i));
+ }
+ } else {
+ for(uint i=0;i<n;i++) {
+ raceCheckRead8(tid, (void *)(((char *)src) + i));
+ ((volatile char *)dst)[i] = ((char *)src)[i];
+ raceCheckWrite8(tid, (void *)(((char *)src) + i));
+ }
+ }
+ } else {
+ if (((uintptr_t)real_memcpy) < 2) {
+ for(uint i=0;i<n;i++) {
+ ((volatile char *)dst)[i] = ((char *)src)[i];
+ }
+ return dst;
+ }
+
+ return real_memcpy(dst, src, n);
+ }
+ return dst;
+}
void * Thread_malloc(size_t size);
void Thread_free(void *ptr);
+void init_memory_ops();
+
/** @brief Provides a non-snapshotting allocator for use in STL classes.
*
* The code was adapted from a code example from the book The C++
extern mspace model_snapshot_space;
+extern void * (*volatile real_memcpy)(void * dst, const void *src, size_t n);
+extern void * (*volatile real_memmove)(void * dst, const void *src, size_t len);
+extern void (*volatile real_bzero)(void * dst, size_t len);
+extern void * (*volatile real_memset)(void * dst, int c, size_t len);
+
#ifdef __cplusplus
}; /* end of extern "C" */
#endif
enabled_type_t *new_enabled = (enabled_type_t *)snapshot_malloc(sizeof(enabled_type_t) * (threadid + 1));
memset(&new_enabled[enabled_len], 0, (threadid + 1 - enabled_len) * sizeof(enabled_type_t));
if (enabled != NULL) {
- memcpy(new_enabled, enabled, enabled_len * sizeof(enabled_type_t));
+ real_memcpy(new_enabled, enabled, enabled_len * sizeof(enabled_type_t));
snapshot_free(enabled);
}
enabled = new_enabled;
_size(_capacity),
capacity(_capacity),
array((type *) model_malloc(sizeof(type) * _capacity)) {
- memcpy(array, _array, capacity * sizeof(type));
+ real_memcpy(array, _array, capacity * sizeof(type));
}
void pop_back() {
_size--;
_size(_capacity),
capacity(_capacity),
array((type *) snapshot_malloc(sizeof(type) * _capacity)) {
- memcpy(array, _array, capacity * sizeof(type));
+ real_memcpy(array, _array, capacity * sizeof(type));
}
void pop_back() {
_size--;