mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-08 00:09:31 +03:00
Merge branch 'dev' into dev-slice
This commit is contained in:
commit
4f7bc7d98e
3 changed files with 15 additions and 13 deletions
|
@ -190,7 +190,7 @@ endif()
|
||||||
|
|
||||||
# extra needed libraries
|
# extra needed libraries
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
list(APPEND mi_libraries psapi shell32 user32 bcrypt)
|
list(APPEND mi_libraries psapi shell32 user32 advapi32 bcrypt)
|
||||||
else()
|
else()
|
||||||
if(NOT ${CMAKE_C_COMPILER} MATCHES "android")
|
if(NOT ${CMAKE_C_COMPILER} MATCHES "android")
|
||||||
list(APPEND mi_libraries pthread)
|
list(APPEND mi_libraries pthread)
|
||||||
|
|
|
@ -37,10 +37,10 @@ jobs:
|
||||||
inputs:
|
inputs:
|
||||||
solution: $(BuildType)/libmimalloc.sln
|
solution: $(BuildType)/libmimalloc.sln
|
||||||
configuration: '$(MSBuildConfiguration)'
|
configuration: '$(MSBuildConfiguration)'
|
||||||
#- script: |
|
- script: |
|
||||||
# cd $(BuildType)
|
cd $(BuildType)
|
||||||
# ctest --verbose --timeout 120
|
ctest --verbose --timeout 120
|
||||||
# displayName: CTest
|
displayName: CTest
|
||||||
#- script: $(BuildType)\$(BuildType)\mimalloc-test-stress
|
#- script: $(BuildType)\$(BuildType)\mimalloc-test-stress
|
||||||
# displayName: TestStress
|
# displayName: TestStress
|
||||||
#- upload: $(Build.SourcesDirectory)/$(BuildType)
|
#- upload: $(Build.SourcesDirectory)/$(BuildType)
|
||||||
|
|
18
src/random.c
18
src/random.c
|
@ -155,21 +155,24 @@ uintptr_t _mi_random_next(mi_random_ctx_t* ctx) {
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
To initialize a fresh random context we rely on the OS:
|
To initialize a fresh random context we rely on the OS:
|
||||||
- Windows : RtlGenRandom
|
- Windows : BCryptGenRandom (or RtlGenRandom)
|
||||||
- osX,bsd,wasi: arc4random_buf
|
- osX,bsd,wasi: arc4random_buf
|
||||||
- Linux : getrandom,/dev/urandom
|
- Linux : getrandom,/dev/urandom
|
||||||
If we cannot get good randomness, we fall back to weak randomness based on a timer and ASLR.
|
If we cannot get good randomness, we fall back to weak randomness based on a timer and ASLR.
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
/*
|
|
||||||
// We prefer BCryptGenRandom over RtlGenRandom but it leads to a crash a when using dynamic override combined with the C++ runtime :-(
|
#if !defined(MI_USE_RTLGENRANDOM)
|
||||||
|
// We prefer BCryptGenRandom over RtlGenRandom
|
||||||
#pragma comment (lib,"bcrypt.lib")
|
#pragma comment (lib,"bcrypt.lib")
|
||||||
#include <bcrypt.h>
|
#include <bcrypt.h>
|
||||||
static bool os_random_buf(void* buf, size_t buf_len) {
|
static bool os_random_buf(void* buf, size_t buf_len) {
|
||||||
return (BCryptGenRandom(NULL, (PUCHAR)buf, (ULONG)buf_len, BCRYPT_USE_SYSTEM_PREFERRED_RNG) >= 0);
|
return (BCryptGenRandom(NULL, (PUCHAR)buf, (ULONG)buf_len, BCRYPT_USE_SYSTEM_PREFERRED_RNG) >= 0);
|
||||||
}
|
}
|
||||||
*/
|
#else
|
||||||
|
// Use (unofficial) RtlGenRandom
|
||||||
|
#pragma comment (lib,"advapi32.lib")
|
||||||
#define RtlGenRandom SystemFunction036
|
#define RtlGenRandom SystemFunction036
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -179,11 +182,9 @@ BOOLEAN NTAPI RtlGenRandom(PVOID RandomBuffer, ULONG RandomBufferLength);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
static bool os_random_buf(void* buf, size_t buf_len) {
|
static bool os_random_buf(void* buf, size_t buf_len) {
|
||||||
mi_assert_internal(buf_len >= sizeof(uintptr_t));
|
return (RtlGenRandom(buf, (ULONG)buf_len) != 0);
|
||||||
memset(buf, 0, buf_len);
|
|
||||||
RtlGenRandom(buf, (ULONG)buf_len);
|
|
||||||
return (((uintptr_t*)buf)[0] != 0); // sanity check (but RtlGenRandom should never fail)
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#elif defined(ANDROID) || defined(XP_DARWIN) || defined(__APPLE__) || defined(__DragonFly__) || \
|
#elif defined(ANDROID) || defined(XP_DARWIN) || defined(__APPLE__) || defined(__DragonFly__) || \
|
||||||
defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
|
defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
|
||||||
|
@ -252,6 +253,7 @@ static bool os_random_buf(void* buf, size_t buf_len) {
|
||||||
|
|
||||||
uintptr_t _os_random_weak(uintptr_t extra_seed) {
|
uintptr_t _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)&_os_random_weak ^ extra_seed; // ASLR makes the address random
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
LARGE_INTEGER pcount;
|
LARGE_INTEGER pcount;
|
||||||
QueryPerformanceCounter(&pcount);
|
QueryPerformanceCounter(&pcount);
|
||||||
|
|
Loading…
Add table
Reference in a new issue