mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Call BoringSSL.load() in more places
This commit is contained in:
@@ -15,9 +15,12 @@ pub fn load() void {
|
||||
boring.OpenSSL_add_all_algorithms();
|
||||
|
||||
if (!builtin.is_test) {
|
||||
std.mem.doNotOptimizeAway(&OPENSSL_memory_alloc);
|
||||
comptime {
|
||||
@export(bun.Mimalloc.mi_malloc, .{ .name = "OPENSSL_memory_alloc", .linkage = .Strong });
|
||||
@export(bun.Mimalloc.mi_usable_size, .{ .name = "OPENSSL_memory_get_size", .linkage = .Strong });
|
||||
}
|
||||
|
||||
std.mem.doNotOptimizeAway(&OPENSSL_memory_free);
|
||||
std.mem.doNotOptimizeAway(&OPENSSL_memory_get_size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,9 +62,9 @@ pub fn initClient() *boring.SSL {
|
||||
// into the process, including pthreads locks. Failing to meet these constraints
|
||||
// may result in deadlocks, crashes, or memory corruption.
|
||||
|
||||
export fn OPENSSL_memory_alloc(size: usize) ?*anyopaque {
|
||||
return bun.Mimalloc.mi_malloc(size);
|
||||
}
|
||||
// export fn OPENSSL_memory_alloc(size: usize) ?*anyopaque {
|
||||
// return
|
||||
// }
|
||||
|
||||
// BoringSSL always expects memory to be zero'd
|
||||
export fn OPENSSL_memory_free(ptr: *anyopaque) void {
|
||||
@@ -69,9 +72,9 @@ export fn OPENSSL_memory_free(ptr: *anyopaque) void {
|
||||
bun.Mimalloc.mi_free(ptr);
|
||||
}
|
||||
|
||||
export fn OPENSSL_memory_get_size(ptr: ?*const anyopaque) usize {
|
||||
return bun.Mimalloc.mi_usable_size(ptr);
|
||||
}
|
||||
// export fn OPENSSL_memory_get_size(ptr: ?*const anyopaque) usize {
|
||||
// return bun.Mimalloc.mi_usable_size(ptr);
|
||||
// }
|
||||
|
||||
test "load" {
|
||||
load();
|
||||
|
||||
@@ -1497,6 +1497,8 @@ pub const Crypto = struct {
|
||||
pub const Digest = [BoringSSL.EVP_MAX_MD_SIZE]u8;
|
||||
|
||||
pub fn init(algorithm: Algorithm, md: *const BoringSSL.EVP_MD, engine: *BoringSSL.ENGINE) EVP {
|
||||
BoringSSL.load();
|
||||
|
||||
var ctx: BoringSSL.EVP_MD_CTX = undefined;
|
||||
BoringSSL.EVP_MD_CTX_init(&ctx);
|
||||
_ = BoringSSL.EVP_DigestInit_ex(&ctx, md, engine);
|
||||
|
||||
@@ -9,6 +9,7 @@ fn NewHasher(comptime digest_size: comptime_int, comptime ContextType: type, com
|
||||
pub const digest: comptime_int = digest_size;
|
||||
|
||||
pub fn init() @This() {
|
||||
BoringSSL.load();
|
||||
var this: @This() = .{
|
||||
.hasher = undefined,
|
||||
};
|
||||
@@ -45,6 +46,8 @@ fn NewEVP(
|
||||
pub const digest: comptime_int = digest_size;
|
||||
|
||||
pub fn init() @This() {
|
||||
BoringSSL.load();
|
||||
|
||||
const md = @call(.auto, @field(BoringSSL, MDName), .{});
|
||||
var this: @This() = .{
|
||||
.ctx = undefined,
|
||||
|
||||
Reference in New Issue
Block a user