Skip to content
Closed
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
3 changes: 3 additions & 0 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const {
overrideStackTrace,
} = require('internal/errors');
const { signals } = internalBinding('constants').os;
const { getEmbeddedData } = internalBinding('sea');

const {
isArrayBufferDetached: _isArrayBufferDetached,
guessHandleType: _guessHandleType,
Expand Down Expand Up @@ -874,6 +876,7 @@ class WeakReference {
}

module.exports = {
getEmbeddedData,
getLazy,
assertCrypto,
cachedResult,
Expand Down
2 changes: 2 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const {
promisify,
toUSVString,
defineLazyProperties,
getEmbeddedData,
} = require('internal/util');

let abortController;
Expand Down Expand Up @@ -384,6 +385,7 @@ module.exports = {
formatWithOptions,
getSystemErrorMap,
getSystemErrorName,
getEmbeddedData,
inherits,
inspect,
isArray: ArrayIsArray,
Expand Down
38 changes: 38 additions & 0 deletions src/node_sea.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,42 @@ void GetCodeCache(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(data_view);
}

#define POSTJECT_SENTINEL_EMBED "NODE_EMBED_fce680ab2cc467b6e072b8b5df1996b2"
static inline bool hasEmbeddedData() {
static const volatile char* sentinel = POSTJECT_SENTINEL_EMBED ":0";
return sentinel[sizeof(POSTJECT_SENTINEL_EMBED)] == '1';
}
#undef POSTJECT_SENTINEL_EMBED
void GetEmbeddedData(const FunctionCallbackInfo<Value>& args) {
if (!hasEmbeddedData()) {
return;
}

Isolate* isolate = args.GetIsolate();
size_t size = 0;
#ifdef __APPLE__
postject_options options;
postject_options_init(&options);
options.macho_segment_name = "NODE_SEA";
const void* data =
postject_find_resource("NODE_EMBEDDED_DATA", &size, &options);
#else
const void* data =
postject_find_resource("NODE_EMBEDDED_DATA", &size, nullptr);
#endif

std::shared_ptr<BackingStore> backing_store = ArrayBuffer::NewBackingStore(
const_cast<void*>(static_cast<const void*>(data)),
size,
[](void* /* data */, size_t /* length */, void* /* deleter_data */) {
// The code cache data blob is not freed here because it is a static
// blob which is not allocated by the BackingStore allocator.
},
nullptr);
Local<ArrayBuffer> array_buffer = ArrayBuffer::New(isolate, backing_store);
args.GetReturnValue().Set(array_buffer);
}

void GetCodePath(const FunctionCallbackInfo<Value>& args) {
DCHECK(IsSingleExecutable());

Expand Down Expand Up @@ -558,13 +594,15 @@ void Initialize(Local<Object> target,
IsExperimentalSeaWarningNeeded);
SetMethod(context, target, "getCodePath", GetCodePath);
SetMethod(context, target, "getCodeCache", GetCodeCache);
SetMethod(context, target, "getEmbeddedData", GetEmbeddedData);
}

void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(IsSea);
registry->Register(IsExperimentalSeaWarningNeeded);
registry->Register(GetCodePath);
registry->Register(GetCodeCache);
registry->Register(GetEmbeddedData);
}

} // namespace sea
Expand Down