mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-10 01:09:31 +03:00
test with dynamic override
This commit is contained in:
parent
36cf82dc71
commit
a7bb572176
3 changed files with 48 additions and 9 deletions
|
@ -115,6 +115,8 @@
|
||||||
<ExceptionHandling>Sync</ExceptionHandling>
|
<ExceptionHandling>Sync</ExceptionHandling>
|
||||||
<CompileAs>Default</CompileAs>
|
<CompileAs>Default</CompileAs>
|
||||||
<SupportJustMyCode>false</SupportJustMyCode>
|
<SupportJustMyCode>false</SupportJustMyCode>
|
||||||
|
<PreprocessorDefinitions>
|
||||||
|
</PreprocessorDefinitions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
|
|
|
@ -167,7 +167,7 @@ If we cannot get good randomness, we fall back to weak randomness based on a tim
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
|
||||||
#if !defined(MI_USE_RTLGENRANDOM)
|
#if defined(MI_USE_BCRYPTGENRANDOM)
|
||||||
// We prefer BCryptGenRandom over RtlGenRandom
|
// We prefer BCryptGenRandom over RtlGenRandom
|
||||||
#pragma comment (lib,"bcrypt.lib")
|
#pragma comment (lib,"bcrypt.lib")
|
||||||
#include <bcrypt.h>
|
#include <bcrypt.h>
|
||||||
|
|
|
@ -37,6 +37,7 @@ static void fail_aslr(); // issue #372
|
||||||
static void tsan_numa_test(); // issue #414
|
static void tsan_numa_test(); // issue #414
|
||||||
static void strdup_test(); // issue #445
|
static void strdup_test(); // issue #445
|
||||||
static void bench_alloc_large(void); // issue #xxx
|
static void bench_alloc_large(void); // issue #xxx
|
||||||
|
static void corrupt_free();
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
mi_stats_reset(); // ignore earlier allocations
|
mi_stats_reset(); // ignore earlier allocations
|
||||||
|
@ -49,6 +50,7 @@ int main() {
|
||||||
large_alloc();
|
large_alloc();
|
||||||
tsan_numa_test();
|
tsan_numa_test();
|
||||||
strdup_test();
|
strdup_test();
|
||||||
|
// corrupt_free();
|
||||||
|
|
||||||
//test_mt_shutdown();
|
//test_mt_shutdown();
|
||||||
//fail_aslr();
|
//fail_aslr();
|
||||||
|
@ -257,6 +259,41 @@ static void tsan_numa_test() {
|
||||||
t1.join();
|
t1.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Try to corrupt the heap through buffer overflow
|
||||||
|
#define N 256
|
||||||
|
#define SZ 64
|
||||||
|
#define OVF_SZ 32
|
||||||
|
|
||||||
|
static void corrupt_free() {
|
||||||
|
void* p[N];
|
||||||
|
// allocate
|
||||||
|
for (int i = 0; i < N; i++) {
|
||||||
|
p[i] = malloc(SZ);
|
||||||
|
}
|
||||||
|
// free some
|
||||||
|
for (int i = 0; i < N; i += (N/10)) {
|
||||||
|
free(p[i]);
|
||||||
|
p[i] = NULL;
|
||||||
|
}
|
||||||
|
// try to corrupt the free list
|
||||||
|
for (int i = 0; i < N; i++) {
|
||||||
|
if (p[i] != NULL) {
|
||||||
|
memset(p[i], 0, SZ+OVF_SZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// allocate more.. trying to trigger an allocation from a corrupted entry
|
||||||
|
// this may need many allocations to get there (if at all)
|
||||||
|
for (int i = 0; i < 4096; i++) {
|
||||||
|
malloc(SZ);
|
||||||
|
}
|
||||||
|
// free the rest
|
||||||
|
for (int i = 0; i < N; i++) {
|
||||||
|
free(p[i]);
|
||||||
|
p[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// issue #?
|
// issue #?
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
Loading…
Add table
Reference in a new issue