MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / _mi_os_random_weak

Function _mi_os_random_weak

3rd/mimalloc-2.0.9/src/random.c:299–321  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

297#endif
298
299uintptr_t _mi_os_random_weak(uintptr_t extra_seed) {
300 uintptr_t x = (uintptr_t)&_mi_os_random_weak ^ extra_seed; // ASLR makes the address random
301
302 #if defined(_WIN32)
303 LARGE_INTEGER pcount;
304 QueryPerformanceCounter(&pcount);
305 x ^= (uintptr_t)(pcount.QuadPart);
306 #elif defined(__APPLE__)
307 x ^= (uintptr_t)mach_absolute_time();
308 #else
309 struct timespec time;
310 clock_gettime(CLOCK_MONOTONIC, &time);
311 x ^= (uintptr_t)time.tv_sec;
312 x ^= (uintptr_t)time.tv_nsec;
313 #endif
314 // and do a few randomization steps
315 uintptr_t max = ((x ^ (x >> 17)) & 0x0F) + 1;
316 for (uintptr_t i = 0; i < max; i++) {
317 x = _mi_random_shuffle(x);
318 }
319 mi_assert_internal(x != 0);
320 return x;
321}
322
323static void mi_random_init_ex(mi_random_ctx_t* ctx, bool use_weak) {
324 uint8_t key[32];

Callers 1

mi_random_init_exFunction · 0.85

Calls 1

_mi_random_shuffleFunction · 0.85

Tested by

no test coverage detected