Repository navigation
boringssl: route OPENSSL_malloc to mimalloc on macOS and Windows #34847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+89
−12
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| --- a/crypto/mem.cc | ||
| +++ b/crypto/mem.cc | ||
| @@ -100,9 +100,20 @@ | ||
| // primitives used must tolerate every other synchronization primitive linked | ||
| // into the process, including pthreads locks. Failing to meet these constraints | ||
| // may result in deadlocks, crashes, or memory corruption. | ||
| +#if defined(BORINGSSL_REQUIRE_MEMORY_HOOKS) | ||
| +// Bun: the embedder guarantees these three are always defined. WEAK_SYMBOL_FUNC | ||
| +// is gated on __ELF__, so on Mach-O and COFF it would expand to a static null | ||
| +// pointer and the hook path would be folded away at compile time. | ||
| +extern "C" { | ||
| +void *OPENSSL_memory_alloc(size_t size); | ||
| +void OPENSSL_memory_free(void *ptr); | ||
| +size_t OPENSSL_memory_get_size(void *ptr); | ||
| +} | ||
| +#else | ||
| WEAK_SYMBOL_FUNC(void *, OPENSSL_memory_alloc, (size_t size)) | ||
| WEAK_SYMBOL_FUNC(void, OPENSSL_memory_free, (void *ptr)) | ||
| WEAK_SYMBOL_FUNC(size_t, OPENSSL_memory_get_size, (void *ptr)) | ||
| +#endif | ||
|
|
||
| #if defined(BORINGSSL_MALLOC_FAILURE_TESTING) | ||
| static StaticMutex malloc_failure_lock; | ||
| @@ -186,6 +197,15 @@ | ||
| goto err; | ||
| } | ||
|
|
||
| +#if defined(BORINGSSL_REQUIRE_MEMORY_HOOKS) | ||
| + { | ||
| + void *ptr2 = OPENSSL_memory_alloc(size); | ||
| + if (ptr2 == nullptr && size != 0) { | ||
| + goto err; | ||
| + } | ||
| + return ptr2; | ||
| + } | ||
| +#else | ||
| if (OPENSSL_memory_alloc != nullptr) { | ||
| assert(OPENSSL_memory_free != nullptr); | ||
| assert(OPENSSL_memory_get_size != nullptr); | ||
| @@ -195,6 +215,7 @@ | ||
| } | ||
| return ptr2; | ||
| } | ||
| +#endif | ||
|
|
||
| if (size + OPENSSL_MALLOC_PREFIX < size) { | ||
| goto err; | ||
| @@ -238,10 +259,15 @@ | ||
| return; | ||
| } | ||
|
|
||
| +#if defined(BORINGSSL_REQUIRE_MEMORY_HOOKS) | ||
| + OPENSSL_memory_free(orig_ptr); | ||
| + return; | ||
| +#else | ||
| if (OPENSSL_memory_free != nullptr) { | ||
| OPENSSL_memory_free(orig_ptr); | ||
| return; | ||
| } | ||
| +#endif | ||
|
|
||
| void *ptr = ((uint8_t *)orig_ptr) - OPENSSL_MALLOC_PREFIX; | ||
| __asan_unpoison_memory_region(ptr, OPENSSL_MALLOC_PREFIX); | ||
| @@ -268,6 +294,9 @@ | ||
| } | ||
|
|
||
| size_t old_size; | ||
| +#if defined(BORINGSSL_REQUIRE_MEMORY_HOOKS) | ||
| + old_size = OPENSSL_memory_get_size(orig_ptr); | ||
| +#else | ||
| if (OPENSSL_memory_get_size != nullptr) { | ||
| old_size = OPENSSL_memory_get_size(orig_ptr); | ||
| } else { | ||
| @@ -276,6 +305,7 @@ | ||
| old_size = *(size_t *)ptr; | ||
| __asan_poison_memory_region(ptr, OPENSSL_MALLOC_PREFIX); | ||
| } | ||
| +#endif | ||
|
|
||
| void *ret = OPENSSL_malloc(new_size); | ||
| if (ret == nullptr) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.