Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[browser][MT] log proxied functions and FS #100861

Closed
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 src/mono/browser/runtime/es6/dotnet.es6.lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ function setup(emscriptenBuildOptions) {
isPThread: ENVIRONMENT_IS_PTHREAD,
quit_, ExitStatus,
updateMemoryViews,
#if USE_PTHREADS
getProxiedFunctionTable:() => { return proxiedFunctionTable; },
#endif
getMemory: () => { return wasmMemory; },
getWasmIndirectFunctionTable: () => { return wasmTable; },
}, emscriptenBuildOptions);
Expand Down
1 change: 1 addition & 0 deletions src/mono/browser/runtime/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function passEmscriptenInternals (internals: EmscriptenInternals, emscrip
runtimeHelpers.getMemory = internals.getMemory;
runtimeHelpers.getWasmIndirectFunctionTable = internals.getWasmIndirectFunctionTable;
runtimeHelpers.updateMemoryViews = internals.updateMemoryViews;
Module.getProxiedFunctionTable = internals.getProxiedFunctionTable;
}

// NOTE: this is called AFTER the config is loaded
Expand Down
41 changes: 41 additions & 0 deletions src/mono/browser/runtime/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ function preInit (userPreInit: (() => void)[]) {
Module.addRunDependency("mono_pre_init");
const mark = startMeasure();
try {
spyEmscriptenFS(Module.FS);
mono_wasm_pre_init_essential(false);
mono_log_debug("preInit");
runtimeHelpers.beforePreInit.promise_control.resolve();
Expand Down Expand Up @@ -278,6 +279,7 @@ async function onRuntimeInitializedAsync (userOnRuntimeInitialized: () => void)
}, 3000);

if (WasmEnableThreads) {
spyEmscriptenProxied(Module.getProxiedFunctionTable());
await threadsReady;

// this will create thread and call start_runtime() on it
Expand Down Expand Up @@ -676,3 +678,42 @@ export async function configureWorkerStartup (module: DotnetModuleInternal): Pro
module.instantiateWasm = instantiateWasmWorker;
await runtimeHelpers.afterPreInit.promise;
}

function simpleArguments (args:any[]) {
let text = "";
for (const arg of args) {
if (typeof arg === "number" || typeof arg === "boolean" || arg === null || arg === undefined) {
text += arg + ",";
} else if ( typeof arg === "string") {
text += "'" + arg + "',";
} else {
text += "<complex>,";
}
}
return text;
}

function spyEmscriptenProxied (proxiedFunctionTable:any[]) {
for (let index = 0; index < proxiedFunctionTable.length; index++) {
const fn = proxiedFunctionTable[index];
if (typeof fn === "function") {
proxiedFunctionTable[index] = function (...args: any[]) {
mono_log_warn(`${fn.name} (${simpleArguments(args)})`);
return fn(...args);
};
}
}
}

function spyEmscriptenFS (FS:any) {
const keys = Object.keys(FS);
for (const k of keys) {
const fn = FS[k];
if (typeof fn === "function" && fn.name[0].toUpperCase() !== fn.name[0]) {
FS[k] = function (...args: any[]) {
mono_log_warn(`FS.${k} (${simpleArguments(args)})`);
return fn(...args);
};
}
}
}
2 changes: 2 additions & 0 deletions src/mono/browser/runtime/types/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ export type EmscriptenInternals = {
getMemory(): WebAssembly.Memory,
getWasmIndirectFunctionTable(): WebAssembly.Table,
updateMemoryViews: () => void,
getProxiedFunctionTable: () => any[],
};
export type GlobalObjects = {
mono: any,
Expand Down Expand Up @@ -435,6 +436,7 @@ export declare interface EmscriptenModuleInternal {
printErr(message: string): void;
abort(reason: any): void;
_emscripten_force_exit(exit_code: number): void;
getProxiedFunctionTable(): any[],
}

/// A PromiseController encapsulates a Promise together with easy access to its resolve and reject functions.
Expand Down
Loading