Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/jsc/bindings/node/crypto/JSCipher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ const JSC::ClassInfo JSCipher::s_info = { "Cipher"_s, &Base::s_info, nullptr, nu
void JSCipher::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
{
Base::finishCreation(vm);

if (m_ctx) {
m_sizeForGC = sizeof(EVP_CIPHER_CTX);
vm.heap.reportExtraMemoryAllocated(this, m_sizeForGC);
}
}

template<typename Visitor>
Expand All @@ -29,6 +34,8 @@ void JSCipher::visitChildrenImpl(JSCell* cell, Visitor& visitor)
JSCipher* thisObject = uncheckedDowncast<JSCipher>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);

visitor.reportExtraMemoryVisited(thisObject->m_sizeForGC);
}

DEFINE_VISIT_CHILDREN(JSCipher);
Expand Down
1 change: 1 addition & 0 deletions src/jsc/bindings/node/crypto/JSCipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class JSCipher final : public JSC::JSDestructibleObject {
char m_authTag[EVP_GCM_TLS_TAG_LEN];
bool m_pendingAuthFailed;
int32_t m_maxMessageSize;
size_t m_sizeForGC { 0 };

private:
JSCipher(JSC::VM& vm, JSC::Structure* structure, CipherKind kind, ncrypto::CipherCtxPointer&& ctx, std::optional<uint32_t> authTagLen, int32_t maxMessageSize)
Expand Down
1 change: 1 addition & 0 deletions src/jsc/bindings/node/crypto/JSCipherPrototype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ JSC_DEFINE_HOST_FUNCTION(jsCipherFinal, (JSC::JSGlobalObject * lexicalGlobalObje
}

cipher->m_ctx.reset();
cipher->m_sizeForGC = 0;

if (!ok) {
throwCryptoErrorWithAuth(lexicalGlobalObject, scope);
Expand Down
5 changes: 5 additions & 0 deletions src/jsc/bindings/node/crypto/JSECDH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const JSC::ClassInfo JSECDH::s_info = { "ECDH"_s, &Base::s_info, nullptr, nullpt
void JSECDH::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
{
Base::finishCreation(vm);

m_sizeForGC = (EC_GROUP_get_degree(m_group) + 7) / 8;
vm.heap.reportExtraMemoryAllocated(this, m_sizeForGC);
}

template<typename Visitor>
Expand All @@ -27,6 +30,8 @@ void JSECDH::visitChildrenImpl(JSCell* cell, Visitor& visitor)
JSECDH* thisObject = uncheckedDowncast<JSECDH>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);

visitor.reportExtraMemoryVisited(thisObject->m_sizeForGC);
}

point_conversion_form_t JSECDH::getFormat(JSC::JSGlobalObject* globalObject, JSC::ThrowScope& scope, JSC::JSValue formatValue)
Expand Down
1 change: 1 addition & 0 deletions src/jsc/bindings/node/crypto/JSECDH.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class JSECDH final : public JSC::JSDestructibleObject {

ncrypto::ECKeyPointer m_key;
const EC_GROUP* m_group;
size_t m_sizeForGC { 0 };

JSC::EncodedJSValue getPublicKey(JSC::JSGlobalObject*, JSC::ThrowScope&, JSC::JSValue encodingValue, JSC::JSValue formatValue);

Expand Down
18 changes: 18 additions & 0 deletions src/jsc/bindings/node/crypto/JSHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ void JSHash::finishCreation(JSC::VM& vm)
Base::finishCreation(vm);
}

template<typename Visitor>
void JSHash::visitChildrenImpl(JSCell* cell, Visitor& visitor)
{
JSHash* thisObject = uncheckedDowncast<JSHash>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);

visitor.reportExtraMemoryVisited(thisObject->m_sizeForGC);
}

DEFINE_VISIT_CHILDREN(JSHash);

template<typename, JSC::SubspaceAccess mode>
JSC::GCClient::IsoSubspace* JSHash::subspaceFor(JSC::VM& vm)
{
Expand Down Expand Up @@ -94,6 +106,9 @@ bool JSHash::init(JSC::JSGlobalObject* globalObject, ThrowScope& scope, const EV
m_mdLen = xofLen.value();
}

m_sizeForGC = sizeof(EVP_MD_CTX) + m_mdLen;
globalObject->vm().heap.reportExtraMemoryAllocated(this, m_sizeForGC);

return true;
}

Expand All @@ -114,6 +129,9 @@ bool JSHash::initZig(JSGlobalObject* globalObject, ThrowScope& scope, ExternZigH
m_mdLen = xofLen.value();
}

m_sizeForGC = m_mdLen;
globalObject->vm().heap.reportExtraMemoryAllocated(this, m_sizeForGC);
Comment thread
coderabbitai[bot] marked this conversation as resolved.

return true;
}

Expand Down
2 changes: 2 additions & 0 deletions src/jsc/bindings/node/crypto/JSHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class JSHash final : public JSC::JSDestructibleObject {
static JSHash* create(JSC::VM& vm, JSC::Structure* structure);

DECLARE_INFO;
DECLARE_VISIT_CHILDREN;

template<typename, JSC::SubspaceAccess mode>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm);
Expand Down Expand Up @@ -52,6 +53,7 @@ class JSHash final : public JSC::JSDestructibleObject {
Vector<uint8_t, EVP_MAX_MD_SIZE> m_digestBuffer;

ExternZigHash::Hasher* m_zigHasher { nullptr };
size_t m_sizeForGC { 0 };
};

class JSHashPrototype final : public JSC::JSNonFinalObject {
Expand Down
17 changes: 17 additions & 0 deletions src/jsc/bindings/node/crypto/JSHmac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ void JSHmac::finishCreation(JSC::VM& vm)
Base::finishCreation(vm);
}

template<typename Visitor>
void JSHmac::visitChildrenImpl(JSCell* cell, Visitor& visitor)
{
JSHmac* thisObject = uncheckedDowncast<JSHmac>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);

visitor.reportExtraMemoryVisited(thisObject->m_sizeForGC);
}

DEFINE_VISIT_CHILDREN(JSHmac);

template<typename, JSC::SubspaceAccess mode>
JSC::GCClient::IsoSubspace* JSHmac::subspaceFor(JSC::VM& vm)
{
Expand Down Expand Up @@ -88,6 +100,9 @@ void JSHmac::init(JSC::JSGlobalObject* globalObject, ThrowScope& scope, const St
throwCryptoError(globalObject, scope, ERR_get_error(), "Failed to initialize HMAC context"_s);
return;
}

m_sizeForGC = sizeof(HMAC_CTX);
globalObject->vm().heap.reportExtraMemoryAllocated(this, m_sizeForGC);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

bool JSHmac::update(std::span<const uint8_t> input)
Expand Down Expand Up @@ -219,10 +234,12 @@ JSC_DEFINE_HOST_FUNCTION(jsHmacProtoFuncDigest, (JSC::JSGlobalObject * lexicalGl
if (hmac->m_ctx) {
if (!hmac->m_ctx.digestInto(&mdBuffer)) {
hmac->m_ctx.reset();
hmac->m_sizeForGC = 0;
throwCryptoError(lexicalGlobalObject, scope, ERR_get_error(), "Failed to digest HMAC"_s);
return {};
}
hmac->m_ctx.reset();
hmac->m_sizeForGC = 0;
}

// We shouldn't set finalized if coming from _flush, but this
Expand Down
2 changes: 2 additions & 0 deletions src/jsc/bindings/node/crypto/JSHmac.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class JSHmac final : public JSC::JSDestructibleObject {
static void destroy(JSC::JSCell* cell);

DECLARE_INFO;
DECLARE_VISIT_CHILDREN;

template<typename, JSC::SubspaceAccess mode>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm);
Expand All @@ -44,6 +45,7 @@ class JSHmac final : public JSC::JSDestructibleObject {

ncrypto::HMACCtxPointer m_ctx;
bool m_finalized { false };
size_t m_sizeForGC { 0 };
};

class JSHmacPrototype final : public JSC::JSNonFinalObject {
Expand Down
7 changes: 7 additions & 0 deletions src/jsc/bindings/node/crypto/JSKeyObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const JSC::ClassInfo JSKeyObject::s_info = { "KeyObject"_s, &Base::s_info, nullp
void JSKeyObject::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
{
Base::finishCreation(vm);

if (auto data = m_handle.data()) {
m_sizeForGC = sizeof(KeyObjectData) + data->symmetricKey.sizeInBytes() + data->asymmetricKey.size();
vm.heap.reportExtraMemoryAllocated(this, m_sizeForGC);
}
}

template<typename Visitor>
Expand All @@ -25,6 +30,8 @@ void JSKeyObject::visitChildrenImpl(JSCell* cell, Visitor& visitor)
JSKeyObject* thisObject = uncheckedDowncast<JSKeyObject>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);

visitor.reportExtraMemoryVisited(thisObject->m_sizeForGC);
}

DEFINE_VISIT_CHILDREN(JSKeyObject);
Expand Down
1 change: 1 addition & 0 deletions src/jsc/bindings/node/crypto/JSKeyObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class JSKeyObject : public JSC::JSDestructibleObject {
static void destroy(JSC::JSCell* cell) { static_cast<JSKeyObject*>(cell)->~JSKeyObject(); }

KeyObject m_handle;
size_t m_sizeForGC { 0 };

DECLARE_INFO;
DECLARE_VISIT_CHILDREN;
Expand Down
18 changes: 18 additions & 0 deletions src/jsc/bindings/node/crypto/JSSign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ void JSSign::finishCreation(JSC::VM& vm)
Base::finishCreation(vm);
}

template<typename Visitor>
void JSSign::visitChildrenImpl(JSCell* cell, Visitor& visitor)
{
JSSign* thisObject = uncheckedDowncast<JSSign>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);

visitor.reportExtraMemoryVisited(thisObject->m_sizeForGC);
}

DEFINE_VISIT_CHILDREN(JSSign);

JSSign* JSSign::create(JSC::VM& vm, JSC::Structure* structure)
{
JSSign* sign = new (NotNull, JSC::allocateCell<JSSign>(vm)) JSSign(vm, structure);
Expand Down Expand Up @@ -196,6 +208,11 @@ JSC_DEFINE_HOST_FUNCTION(jsSignProtoFuncInit, (JSC::JSGlobalObject * globalObjec
// Store the initialized context in the JSSign object
thisObject->m_mdCtx = WTF::move(mdCtx);

if (!thisObject->m_sizeForGC) {
thisObject->m_sizeForGC = sizeof(EVP_MD_CTX);
vm.heap.reportExtraMemoryAllocated(thisObject, thisObject->m_sizeForGC);
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

return JSC::JSValue::encode(JSC::jsUndefined());
}

Expand Down Expand Up @@ -304,6 +321,7 @@ JSUint8Array* signWithKey(JSC::JSGlobalObject* lexicalGlobalObject, JSSign* this

// Move mdCtx out of JSSign object
ncrypto::EVPMDCtxPointer mdCtx = WTF::move(thisObject->m_mdCtx);
thisObject->m_sizeForGC = 0;

// Validate DSA parameters
if (!pkey.validateDsaParameters()) {
Expand Down
2 changes: 2 additions & 0 deletions src/jsc/bindings/node/crypto/JSSign.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ class JSSign final : public JSC::JSDestructibleObject {
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm);

DECLARE_INFO;
DECLARE_VISIT_CHILDREN;

ncrypto::EVPMDCtxPointer m_mdCtx;
size_t m_sizeForGC { 0 };

private:
JSSign(JSC::VM& vm, JSC::Structure* structure);
Expand Down
18 changes: 18 additions & 0 deletions src/jsc/bindings/node/crypto/JSVerify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ void JSVerify::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
Base::finishCreation(vm);
}

template<typename Visitor>
void JSVerify::visitChildrenImpl(JSCell* cell, Visitor& visitor)
{
JSVerify* thisObject = uncheckedDowncast<JSVerify>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);

visitor.reportExtraMemoryVisited(thisObject->m_sizeForGC);
}

DEFINE_VISIT_CHILDREN(JSVerify);

JSVerify* JSVerify::create(JSC::VM& vm, JSC::Structure* structure, JSC::JSGlobalObject* globalObject)
{
JSVerify* verify = new (NotNull, JSC::allocateCell<JSVerify>(vm)) JSVerify(vm, structure);
Expand Down Expand Up @@ -202,6 +214,11 @@ JSC_DEFINE_HOST_FUNCTION(jsVerifyProtoFuncInit, (JSGlobalObject * globalObject,
// Store the initialized context in the JSVerify object
thisObject->m_mdCtx = WTF::move(mdCtx);

if (!thisObject->m_sizeForGC) {
thisObject->m_sizeForGC = sizeof(EVP_MD_CTX);
vm.heap.reportExtraMemoryAllocated(thisObject, thisObject->m_sizeForGC);
}

return JSC::JSValue::encode(JSC::jsUndefined());
}

Expand Down Expand Up @@ -368,6 +385,7 @@ JSC_DEFINE_HOST_FUNCTION(jsVerifyProtoFuncVerify, (JSGlobalObject * globalObject

// Move mdCtx out of JSVerify object to finalize it
ncrypto::EVPMDCtxPointer mdCtx = WTF::move(thisObject->m_mdCtx);
thisObject->m_sizeForGC = 0;

// Validate DSA parameters
if (!keyPtr.validateDsaParameters()) {
Expand Down
2 changes: 2 additions & 0 deletions src/jsc/bindings/node/crypto/JSVerify.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ class JSVerify final : public JSC::JSDestructibleObject {
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm);

DECLARE_INFO;
DECLARE_VISIT_CHILDREN;

ncrypto::EVPMDCtxPointer m_mdCtx;
size_t m_sizeForGC { 0 };

private:
JSVerify(JSC::VM& vm, JSC::Structure* structure);
Expand Down
Loading
Loading