diff options
author | Jose Fonseca <jfonseca@vmware.com> | 2016-05-11 01:07:10 +0100 |
---|---|---|
committer | Jose Fonseca <jfonseca@vmware.com> | 2016-05-11 01:08:55 +0100 |
commit | f1977beca436a1f8902052bee8ec81d3eccb22fb (patch) | |
tree | 9762eec9465a47a0505eedde71fb5bc4ae616bac /wrappers | |
parent | ef45b1fff4ca3102ee5c2e795f6297e18d25cdb8 (diff) |
memtrace: Align blocks to 64 bytes.
WARP doesn't align memory mapping to pages, causing tests to fail, as
blocks get different offsets.
Diffstat (limited to 'wrappers')
-rw-r--r-- | wrappers/memtrace.cpp | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/wrappers/memtrace.cpp b/wrappers/memtrace.cpp index fc89a8db..feb2019e 100644 --- a/wrappers/memtrace.cpp +++ b/wrappers/memtrace.cpp @@ -60,6 +60,7 @@ #endif +#define BLOCK_ALIGN 64 #define BLOCK_SIZE 512 @@ -120,7 +121,7 @@ mm_crc32_u32(uint32_t crc, uint32_t current) uint32_t hashBlock(const void *p) { - assert((intptr_t)p % BLOCK_SIZE == 0); + assert(lAlignPtr(p, BLOCK_ALIGN) == p); uint32_t crc; @@ -186,29 +187,33 @@ void MemoryShadow::cover(void *_ptr, size_t _size, bool _discard) { assert(_ptr); + const uint8_t *ptr = static_cast<const uint8_t *>(_ptr); + const uint8_t *basePtr = lAlignPtr(ptr, BLOCK_ALIGN); + if (_size != size) { - nBlocks = ((intptr_t)_ptr + _size + BLOCK_SIZE - 1)/BLOCK_SIZE - (intptr_t)_ptr/BLOCK_SIZE; + static_assert(BLOCK_SIZE % BLOCK_ALIGN == 0, "inconsistent block align/size"); + nBlocks = (ptr + _size - basePtr + BLOCK_SIZE - 1)/BLOCK_SIZE; hashPtr = (uint32_t *)realloc(hashPtr, nBlocks * sizeof *hashPtr); size = _size; } - realPtr = (const uint8_t *)_ptr; + realPtr = ptr; if (_discard) { zero(_ptr, size); } - const uint8_t *p = lAlignPtr((const uint8_t *)_ptr, BLOCK_SIZE); + const uint8_t *blockPtr = basePtr; if (_discard) { - hashPtr[0] = hashBlock(p); + hashPtr[0] = hashBlock(blockPtr); for (size_t i = 1; i < nBlocks; ++i) { hashPtr[i] = hashPtr[0]; } } else { for (size_t i = 0; i < nBlocks; ++i) { - hashPtr[i] = hashBlock(p); - p += BLOCK_SIZE; + hashPtr[i] = hashBlock(blockPtr); + blockPtr += BLOCK_SIZE; } } } @@ -219,14 +224,14 @@ void MemoryShadow::update(Callback callback) const const uint8_t *realStart = realPtr + size; const uint8_t *realStop = realPtr; - const uint8_t *p = lAlignPtr(realPtr, BLOCK_SIZE); + const uint8_t *blockPtr = lAlignPtr(realPtr, BLOCK_ALIGN); for (size_t i = 0; i < nBlocks; ++i) { - uint32_t crc = hashBlock(p); + uint32_t crc = hashBlock(blockPtr); if (crc != hashPtr[i]) { - realStart = std::min(realStart, p); - realStop = std::max(realStop, p + BLOCK_SIZE); + realStart = std::min(realStart, blockPtr); + realStop = std::max(realStop, blockPtr + BLOCK_SIZE); } - p += BLOCK_SIZE; + blockPtr += BLOCK_SIZE; } realStart = std::max(realStart, realPtr); |