Call BoringSSL.load() in more places

This commit is contained in:
Jarred Sumner
2023-02-25 15:15:10 -08:00
parent eb94e5b990
commit f58728ccc7
3 changed files with 16 additions and 8 deletions

View File

@@ -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();

View File

@@ -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);

View File

@@ -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,