mimalloc: avoid having to link to `bcrypt` just for mimalloc

Instead, load the `BCryptGenRandom()` function dynamically. When
needed. If needed.

This is necessary because the start-up cost of Git processes spent on
loading dynamic libraries is non-negligible.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin 2022-08-12 13:49:22 +02:00
Родитель 905d51293e
Коммит 0ec60aa323
1 изменённых файлов: 8 добавлений и 2 удалений

Просмотреть файл

@ -185,9 +185,15 @@ static bool os_random_buf(void* buf, size_t buf_len) {
return (RtlGenRandom(buf, (ULONG)buf_len) != 0);
}
#else
#pragma comment (lib,"bcrypt.lib")
#include <bcrypt.h>
#include "compat/win32/lazyload.h"
#ifndef BCRYPT_USE_SYSTEM_PREFERRED_RNG
#define BCRYPT_USE_SYSTEM_PREFERRED_RNG 0x00000002
#endif
static bool os_random_buf(void* buf, size_t buf_len) {
DECLARE_PROC_ADDR(bcrypt, LONG, NTAPI, BCryptGenRandom, HANDLE, PUCHAR, ULONG, ULONG);
if (!INIT_PROC_ADDR(BCryptGenRandom))
return 0;
return (BCryptGenRandom(NULL, (PUCHAR)buf, (ULONG)buf_len, BCRYPT_USE_SYSTEM_PREFERRED_RNG) >= 0);
}
#endif