From fe5cffdbd16698d2508cdb472212189ab12bde4f Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Mon, 12 Nov 2012 16:42:41 -0800 Subject: [PATCH] race: where possible, use "const void *" for addresses This allows more flexible use for read-only objects. --- datarace.cc | 8 ++++---- datarace.h | 4 ++-- include/librace.h | 8 ++++---- librace.cc | 30 +++++++++++++++--------------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/datarace.cc b/datarace.cc index 270e5231..e6bbe05c 100644 --- a/datarace.cc +++ b/datarace.cc @@ -16,7 +16,7 @@ void initRaceDetector() { /** This function looks up the entry in the shadow table corresponding to a * given address.*/ -static uint64_t * lookupAddressEntry(void * address) { +static uint64_t * lookupAddressEntry(const void * address) { struct ShadowTable *currtable=root; #if BIT48 currtable=(struct ShadowTable *) currtable->array[(((uintptr_t)address)>>32)&MASK16BIT]; @@ -75,7 +75,7 @@ static void expandRecord(uint64_t * shadow) { } /** This function is called when we detect a data race.*/ -static void reportDataRace(thread_id_t oldthread, modelclock_t oldclock, bool isoldwrite, ModelAction *newaction, bool isnewwrite, void *address) { +static void reportDataRace(thread_id_t oldthread, modelclock_t oldclock, bool isoldwrite, ModelAction *newaction, bool isnewwrite, const void *address) { struct DataRace *race = (struct DataRace *)snapshot_malloc(sizeof(struct DataRace)); race->oldthread=oldthread; race->oldclock=oldclock; @@ -210,7 +210,7 @@ void raceCheckWrite(thread_id_t thread, void *location, ClockVector *currClock) } /** This function does race detection on a read for an expanded record. */ -void fullRaceCheckRead(thread_id_t thread, void *location, uint64_t * shadow, ClockVector *currClock) { +void fullRaceCheckRead(thread_id_t thread, const void *location, uint64_t * shadow, ClockVector *currClock) { struct RaceRecord * record=(struct RaceRecord *) (*shadow); /* Check for datarace against last write. */ @@ -268,7 +268,7 @@ void fullRaceCheckRead(thread_id_t thread, void *location, uint64_t * shadow, Cl } /** This function does race detection on a read. */ -void raceCheckRead(thread_id_t thread, void *location, ClockVector *currClock) { +void raceCheckRead(thread_id_t thread, const void *location, ClockVector *currClock) { uint64_t * shadow=lookupAddressEntry(location); uint64_t shadowval=*shadow; diff --git a/datarace.h b/datarace.h index 627b8cc8..2fb1a7f9 100644 --- a/datarace.h +++ b/datarace.h @@ -36,14 +36,14 @@ struct DataRace { bool isnewwrite; /* Address of data race. */ - void *address; + const void *address; }; #define MASK16BIT 0xffff void initRaceDetector(); void raceCheckWrite(thread_id_t thread, void *location, ClockVector *currClock); -void raceCheckRead(thread_id_t thread, void *location, ClockVector *currClock); +void raceCheckRead(thread_id_t thread, const void *location, ClockVector *currClock); bool checkDataRaces(); void printRace(struct DataRace *race); diff --git a/include/librace.h b/include/librace.h index 591b2925..cabf0661 100644 --- a/include/librace.h +++ b/include/librace.h @@ -16,10 +16,10 @@ extern "C" { void store_32(void *addr, uint32_t val); void store_64(void *addr, uint64_t val); - uint8_t load_8(void *addr); - uint16_t load_16(void *addr); - uint32_t load_32(void *addr); - uint64_t load_64(void *addr); + uint8_t load_8(const void *addr); + uint16_t load_16(const void *addr); + uint32_t load_32(const void *addr); + uint64_t load_64(const void *addr); #ifdef __cplusplus } diff --git a/librace.cc b/librace.cc index 3c56d969..95b97aa9 100644 --- a/librace.cc +++ b/librace.cc @@ -54,7 +54,7 @@ void store_64(void *addr, uint64_t val) (*(uint64_t *)addr) = val; } -uint8_t load_8(void *addr) +uint8_t load_8(const void *addr) { DEBUG("addr = %p\n", addr); thread_id_t tid=thread_current()->get_id(); @@ -63,40 +63,40 @@ uint8_t load_8(void *addr) return *((uint8_t *)addr); } -uint16_t load_16(void *addr) +uint16_t load_16(const void *addr) { DEBUG("addr = %p\n", addr); thread_id_t tid=thread_current()->get_id(); ClockVector * cv=model->get_cv(tid); raceCheckRead(tid, addr, cv); - raceCheckRead(tid, (void *)(((uintptr_t)addr)+1), cv); + raceCheckRead(tid, (const void *)(((uintptr_t)addr)+1), cv); return *((uint16_t *)addr); } -uint32_t load_32(void *addr) +uint32_t load_32(const void *addr) { DEBUG("addr = %p\n", addr); thread_id_t tid=thread_current()->get_id(); ClockVector * cv=model->get_cv(tid); raceCheckRead(tid, addr, cv); - raceCheckRead(tid, (void *)(((uintptr_t)addr)+1), cv); - raceCheckRead(tid, (void *)(((uintptr_t)addr)+2), cv); - raceCheckRead(tid, (void *)(((uintptr_t)addr)+3), cv); + raceCheckRead(tid, (const void *)(((uintptr_t)addr)+1), cv); + raceCheckRead(tid, (const void *)(((uintptr_t)addr)+2), cv); + raceCheckRead(tid, (const void *)(((uintptr_t)addr)+3), cv); return *((uint32_t *)addr); } -uint64_t load_64(void *addr) +uint64_t load_64(const void *addr) { DEBUG("addr = %p\n", addr); thread_id_t tid=thread_current()->get_id(); ClockVector * cv=model->get_cv(tid); raceCheckRead(tid, addr, cv); - raceCheckRead(tid, (void *)(((uintptr_t)addr)+1), cv); - raceCheckRead(tid, (void *)(((uintptr_t)addr)+2), cv); - raceCheckRead(tid, (void *)(((uintptr_t)addr)+3), cv); - raceCheckRead(tid, (void *)(((uintptr_t)addr)+4), cv); - raceCheckRead(tid, (void *)(((uintptr_t)addr)+5), cv); - raceCheckRead(tid, (void *)(((uintptr_t)addr)+6), cv); - raceCheckRead(tid, (void *)(((uintptr_t)addr)+7), cv); + raceCheckRead(tid, (const void *)(((uintptr_t)addr)+1), cv); + raceCheckRead(tid, (const void *)(((uintptr_t)addr)+2), cv); + raceCheckRead(tid, (const void *)(((uintptr_t)addr)+3), cv); + raceCheckRead(tid, (const void *)(((uintptr_t)addr)+4), cv); + raceCheckRead(tid, (const void *)(((uintptr_t)addr)+5), cv); + raceCheckRead(tid, (const void *)(((uintptr_t)addr)+6), cv); + raceCheckRead(tid, (const void *)(((uintptr_t)addr)+7), cv); return *((uint64_t *)addr); } -- 2.34.1