46 Commits

Author SHA1 Message Date
daanx d5ed0cc71e various improvements 2024-12-09 14:31:43 -08:00
Daan Leijen f58357548c restructure header files 2023-03-20 10:37:39 -07:00
Daan Leijen 973268bf1e move random initialization to primitives 2023-03-15 12:40:18 -07:00
Daan Leijen 9b110090b2 move threadid and mi_get_default_heap to primitives 2023-03-14 20:35:00 -07:00
Daan Leijen 505a14bbd8 cleanup on-demand loading of psapi and bcrypt on windows 2022-12-19 16:50:13 -08:00
Johannes Schindelin edb181c377 Lazy-link to bcrypt
Let's not make `bcrypt.dl` a link-time bound library. Instead, load the
`BCryptGenRandom()` function dynamically. When needed. If needed.

This helps reduce the start-up cost of any mimalloc user because the
time spent on loading dynamic libraries is non-negligible.

Note: In contrast to how `os.c` loads libraries and obtains function
addresses, we cannot call `FreeLibrary(hDll)` here because that would
unload the `bcrypt` library before we want to use it.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2022-12-03 01:13:00 +01:00
Johannes Schindelin 745a34f475 Fix whitespace
This mostly deletes trailing spaces.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2022-12-03 00:24:20 +01:00
daan 3e1d800e9b potential fix for windows static linking with thread creation in dll's 2022-11-07 14:47:53 -08:00
daan 3bf299cd2b add comment on crash on Windows server 2019 2022-11-02 10:56:13 -07:00
Daan Leijen adc8b3187c fix Windows C++ compilation in combination with dynamic overriding by preferring RtlGenRandom 2022-04-09 13:48:16 -07:00
David CARLIER 40e0507a59 fix build on older macOs releases, aligned_alloc only from catalina.
closes #549
2022-02-22 22:01:26 +00:00
Daan 9c583eb910 fix return code check on syscall (issue #524) 2022-01-16 12:10:33 -08:00
Daan 0e851de2ba shorten comments for pr #390 2021-12-15 17:06:09 -08:00
Daan 2a4ad02d27 Merge branch 'dev' into random-context-macos 2021-12-15 16:57:25 -08:00
daan 6503ad7a76 check if using bcryptgenrandom fixes windows pipeline 2021-12-14 18:45:44 -08:00
Daan Leijen 36edfbc70a use rtlgenrandom by default on windows 2021-12-09 16:18:17 -08:00
Christian Heimes 13de1920ae Rename _os_random_weak to _mi_os_random_weak
The ``_os_random_weak`` function is the only non-static function
besides ``_ZSt15get_new_handlerv`` that is not prefixed with ``mi`` or
``_mi``.

The discrepancy was discovered by CPython's smelly script. The checker
looks for exported symbols that don't have well-defined prefixes.

Signed-off-by: Christian Heimes <christian@python.org>
2021-10-21 21:40:45 +02:00
Daan 2adf69859b Merge pull request #418 from devnexen/haiku_build_fix
haiku biuld fix proposal, warning suppression.
2021-10-19 12:19:44 -07:00
Daan ea46430016 Merge pull request #468 from tiran/default_source
Define _DEFAULT_SOURCE for syscall and realpath
2021-10-19 09:40:21 -07:00
Christian Heimes afbcf20f24 Define _DEFAULT_SOURCE for syscall and realpath
Define ``_DEFAULT_SOURCE`` in ``random.c`` and ``alloc.c``. The macro
is required for ``syscall()`` and ``realpath()``. Other files like
``os.c`` already define the macro.

Signed-off-by: Christian Heimes <christian@python.org>
2021-10-19 15:07:54 +02:00
Daan Leijen 679aad0659 update wasm support with emscripten compilation; now using sbrk instead of wasm_memory_grow 2021-10-01 15:05:01 -07:00
Jim Huang c4947c8879 Use secure random generator on macOS
The implementation of arc4random_buf differs from its documentation. It
is documented as "always successful, and no return value is reserved to
indicate an error" for the sake of FreeBSD compatibility [1]. However,
the actual implementation on macOS invokes function "ccrng_generate" [2]
without validating the error cases. It might fail silently[3], which leads
to unexpected source of entropy.

The original arc4random used the RC4 a.k.a. ARC4 algorithm, and ChaCha20
based implementation was introduced in FreeBSD 12.0. Since macOS 10.12,
it was replaced with the NIST-approved AES cipher, and it may be replaced
again in the future as cryptographic techniques advance. Therefore, we
should not assume that arc4random never fails.

On the contrary, CCRandomGenerateBytes(), part of Cryptographic Services [4],
returns cryptographically strong random bits with explicit status code.
This patch properly calls CCRandomGenerateBytes() and checks the status.

[1] https://www.freebsd.org/cgi/man.cgi?query=arc4random_buf
[2] https://opensource.apple.com/source/CommonCrypto/CommonCrypto-60178.40.2/lib/CommonRandom.c.auto.html
[3] https://opensource.apple.com/source/Libc/Libc-1439.40.11/gen/FreeBSD/arc4random.c.auto.html
[4] https://developer.apple.com/documentation/security
2021-06-25 12:37:00 +08:00
David Carlier a35a7d4f19 haiku biuld fix proposal, warning suppression. 2021-06-19 09:14:43 +00:00
Daan Leijen 4ba32c3160 Revert "make all includes relative"
This reverts commit 1feb6123d9.
2021-06-07 16:47:57 -07:00
Daan Leijen 1feb6123d9 make all includes relative 2021-06-06 20:31:36 -07:00