From b5d3ce04e8bb1049b6f0d14def0ac7ca16c35091 Mon Sep 17 00:00:00 2001 From: "Kate J. Temkin" Date: Fri, 20 Apr 2018 19:12:06 -0600 Subject: [PATCH] fusee: fix missing volatiles in memory utils --- fusee/fusee-primary/src/utils.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/fusee/fusee-primary/src/utils.h b/fusee/fusee-primary/src/utils.h index 5a288717d..43f2634ba 100644 --- a/fusee/fusee-primary/src/utils.h +++ b/fusee/fusee-primary/src/utils.h @@ -29,9 +29,8 @@ static inline uintptr_t get_physical_address(const void *addr) { static inline uint32_t read32le(const volatile void *dword, size_t offset) { uintptr_t addr = (uintptr_t)dword + offset; - uint32_t dst; - memcpy(&dst, (void *)addr, 4); - return dst; + volatile uint32_t *target = (uint32_t *)addr; + return *target; } static inline uint32_t read32be(const volatile void *dword, size_t offset) { @@ -40,9 +39,8 @@ static inline uint32_t read32be(const volatile void *dword, size_t offset) { static inline uint64_t read64le(const volatile void *qword, size_t offset) { uintptr_t addr = (uintptr_t)qword + offset; - uint64_t dst; - memcpy(&dst, (void *)addr, 8); - return dst; + volatile uint64_t *target = (uint64_t *)addr; + return *target; } static inline uint64_t read64be(const volatile void *qword, size_t offset) { @@ -50,7 +48,9 @@ static inline uint64_t read64be(const volatile void *qword, size_t offset) { } static inline void write32le(volatile void *dword, size_t offset, uint32_t value) { - memcpy((void *)((uintptr_t)dword + offset), &value, 4); + uintptr_t addr = (uintptr_t)dword + offset; + volatile uint32_t *target = (uint32_t *)addr; + *target = value; } static inline void write32be(volatile void *dword, size_t offset, uint32_t value) { @@ -58,7 +58,9 @@ static inline void write32be(volatile void *dword, size_t offset, uint32_t value } static inline void write64le(volatile void *qword, size_t offset, uint64_t value) { - memcpy((void *)((uintptr_t)qword + offset), &value, 8); + uintptr_t addr = (uintptr_t)qword + offset; + volatile uint64_t *target = (uint64_t *)addr; + *target = value; } static inline void write64be(volatile void *qword, size_t offset, uint64_t value) {