Merge branch 'dev' into dev-slice
This commit is contained in:
commit
725fe2ac7d
@ -50,7 +50,7 @@ void _mi_random_init(mi_random_ctx_t* ctx);
|
|||||||
void _mi_random_split(mi_random_ctx_t* ctx, mi_random_ctx_t* new_ctx);
|
void _mi_random_split(mi_random_ctx_t* ctx, mi_random_ctx_t* new_ctx);
|
||||||
uintptr_t _mi_random_next(mi_random_ctx_t* ctx);
|
uintptr_t _mi_random_next(mi_random_ctx_t* ctx);
|
||||||
uintptr_t _mi_heap_random_next(mi_heap_t* heap);
|
uintptr_t _mi_heap_random_next(mi_heap_t* heap);
|
||||||
uintptr_t _os_random_weak(uintptr_t extra_seed);
|
uintptr_t _mi_os_random_weak(uintptr_t extra_seed);
|
||||||
static inline uintptr_t _mi_random_shuffle(uintptr_t x);
|
static inline uintptr_t _mi_random_shuffle(uintptr_t x);
|
||||||
|
|
||||||
// init.c
|
// init.c
|
||||||
|
@ -165,7 +165,7 @@ mi_stats_t _mi_stats_main = { MI_STATS_NULL };
|
|||||||
static void mi_heap_main_init(void) {
|
static void mi_heap_main_init(void) {
|
||||||
if (_mi_heap_main.cookie == 0) {
|
if (_mi_heap_main.cookie == 0) {
|
||||||
_mi_heap_main.thread_id = _mi_thread_id();
|
_mi_heap_main.thread_id = _mi_thread_id();
|
||||||
_mi_heap_main.cookie = _os_random_weak((uintptr_t)&mi_heap_main_init);
|
_mi_heap_main.cookie = _mi_os_random_weak((uintptr_t)&mi_heap_main_init);
|
||||||
_mi_random_init(&_mi_heap_main.random);
|
_mi_random_init(&_mi_heap_main.random);
|
||||||
_mi_heap_main.keys[0] = _mi_heap_random_next(&_mi_heap_main);
|
_mi_heap_main.keys[0] = _mi_heap_random_next(&_mi_heap_main);
|
||||||
_mi_heap_main.keys[1] = _mi_heap_random_next(&_mi_heap_main);
|
_mi_heap_main.keys[1] = _mi_heap_random_next(&_mi_heap_main);
|
||||||
@ -599,7 +599,7 @@ static void mi_process_done(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
typedef int(*_crt_cb)(void);
|
typedef int(*_crt_cb)(void);
|
||||||
#ifdef _M_X64
|
#if defined(_M_X64) || defined(_M_ARM64)
|
||||||
__pragma(comment(linker, "/include:" "_mi_msvc_initu"))
|
__pragma(comment(linker, "/include:" "_mi_msvc_initu"))
|
||||||
#pragma section(".CRT$XIU", long, read)
|
#pragma section(".CRT$XIU", long, read)
|
||||||
#else
|
#else
|
||||||
|
4
src/os.c
4
src/os.c
@ -51,10 +51,6 @@ terms of the MIT license. A copy of the license can be found in the file
|
|||||||
#include <mach/vm_statistics.h>
|
#include <mach/vm_statistics.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#if defined(__HAIKU__)
|
|
||||||
#define madvise posix_madvise
|
|
||||||
#define MADV_DONTNEED POSIX_MADV_DONTNEED
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* -----------------------------------------------------------
|
/* -----------------------------------------------------------
|
||||||
|
@ -257,8 +257,8 @@ static bool os_random_buf(void* buf, size_t buf_len) {
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uintptr_t _os_random_weak(uintptr_t extra_seed) {
|
uintptr_t _mi_os_random_weak(uintptr_t extra_seed) {
|
||||||
uintptr_t x = (uintptr_t)&_os_random_weak ^ extra_seed; // ASLR makes the address random
|
uintptr_t x = (uintptr_t)&_mi_os_random_weak ^ extra_seed; // ASLR makes the address random
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
LARGE_INTEGER pcount;
|
LARGE_INTEGER pcount;
|
||||||
@ -289,7 +289,7 @@ void _mi_random_init(mi_random_ctx_t* ctx) {
|
|||||||
#if !defined(__wasi__)
|
#if !defined(__wasi__)
|
||||||
_mi_warning_message("unable to use secure randomness\n");
|
_mi_warning_message("unable to use secure randomness\n");
|
||||||
#endif
|
#endif
|
||||||
uintptr_t x = _os_random_weak(0);
|
uintptr_t x = _mi_os_random_weak(0);
|
||||||
for (size_t i = 0; i < 8; i++) { // key is eight 32-bit words.
|
for (size_t i = 0; i < 8; i++) { // key is eight 32-bit words.
|
||||||
x = _mi_random_shuffle(x);
|
x = _mi_random_shuffle(x);
|
||||||
((uint32_t*)key)[i] = (uint32_t)x;
|
((uint32_t*)key)[i] = (uint32_t)x;
|
||||||
|
Loading…
Reference in New Issue
Block a user