memtag_test: fix sporadic failures of overflow/underflow tests
parent
f793a3edf6
commit
88b3c1acf9
|
@ -10,6 +10,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
@ -181,9 +182,26 @@ void tag_distinctness() {
|
||||||
}
|
}
|
||||||
|
|
||||||
u8* alloc_default() {
|
u8* alloc_default() {
|
||||||
|
const size_t full_alloc_size = DEFAULT_ALLOC_SIZE + CANARY_SIZE;
|
||||||
|
set<uptr> addrs;
|
||||||
|
|
||||||
|
// make sure allocation has both left and right neighbors, otherwise overflow/underflow tests
|
||||||
|
// will fail when allocation is at the end/beginning of slab
|
||||||
|
for (;;) {
|
||||||
u8 *p = (u8 *) malloc(DEFAULT_ALLOC_SIZE);
|
u8 *p = (u8 *) malloc(DEFAULT_ALLOC_SIZE);
|
||||||
assert(p);
|
assert(p);
|
||||||
|
|
||||||
|
uptr addr = (uptr) untag_pointer(p);
|
||||||
|
uptr left = addr - full_alloc_size;
|
||||||
|
if (addrs.find(left) != addrs.end()) {
|
||||||
|
uptr right = addr + full_alloc_size;
|
||||||
|
if (addrs.find(right) != addrs.end()) {
|
||||||
return p;
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addrs.emplace(addr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
volatile u8 u8_var;
|
volatile u8 u8_var;
|
||||||
|
|
Loading…
Reference in New Issue