shop audit
This commit is contained in:
@@ -480,6 +480,31 @@ JSValue cell_rt_native_module_load(JSContext *ctx, void *dl_handle) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Load a native module from a dylib handle, trying a named symbol first.
|
||||
Falls back to cell_main if the named symbol is not found. */
|
||||
JSValue cell_rt_native_module_load_named(JSContext *ctx, void *dl_handle, const char *sym_name) {
|
||||
cell_compiled_fn fn = NULL;
|
||||
if (sym_name)
|
||||
fn = (cell_compiled_fn)dlsym(dl_handle, sym_name);
|
||||
if (!fn)
|
||||
fn = (cell_compiled_fn)dlsym(dl_handle, "cell_main");
|
||||
if (!fn)
|
||||
return JS_ThrowTypeError(ctx, "symbol not found in native module dylib");
|
||||
|
||||
void *prev_handle = g_current_dl_handle;
|
||||
g_current_dl_handle = dl_handle;
|
||||
|
||||
JSValue *frame = calloc(512, sizeof(JSValue));
|
||||
if (!frame) {
|
||||
g_current_dl_handle = prev_handle;
|
||||
return JS_ThrowTypeError(ctx, "frame allocation failed");
|
||||
}
|
||||
|
||||
JSValue result = fn(ctx, frame);
|
||||
g_current_dl_handle = prev_handle;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Backward-compat: uses RTLD_DEFAULT (works when dylib opened with RTLD_GLOBAL) */
|
||||
JSValue cell_rt_module_entry(JSContext *ctx) {
|
||||
void *handle = dlopen(NULL, RTLD_LAZY);
|
||||
|
||||
Reference in New Issue
Block a user