Skip to content

Commit

Permalink
rebase + v8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelsavara committed Apr 9, 2024
1 parent 22d1288 commit 132e2b2
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/mono/browser/browser.proj
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,7 @@
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Debug'">-g -Os -s -DDEBUG=1 -DENABLE_AOT_PROFILER=1 -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>

<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Debug'" >$(CMakeConfigurationEmccFlags) -s ASSERTIONS=1 </CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Release'">-O2</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags >$(CMakeConfigurationEmccFlags) -s ASSERTIONS=1 </CMakeConfigurationLinkFlags>

<!-- -lexports.js has the magical property of disabling minification of export names -->
<CMakeConfigurationLinkFlags>$(CMakeConfigurationLinkFlags) -s EXPORT_ES6=1 -lexports.js</CMakeConfigurationLinkFlags>
Expand Down
2 changes: 1 addition & 1 deletion src/mono/browser/build/BrowserWasmApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@
<_EmccLDSFlags Include="-s STACK_SIZE=$(EmccStackSize)" />
<_EmccLDSFlags Include="-s WASM_BIGINT=1" />
<_EmccLDSFlags Condition="'$(EmccEnvironment)' != ''" Include="-s ENVIRONMENT=&quot;$(EmccEnvironment)&quot;" />
<_EmccLDSFlags Condition="'$(EmccEnableAssertions)' == 'true'" Include="-s ASSERTIONS=1" />
<_EmccLDSFlags Include="-s ASSERTIONS=1" />

<_WasmNativeFileForLinking Include="%(_BitcodeFile.ObjectFile)" />
<_WasmNativeFileForLinking Include="%(_WasmSourceFileToCompile.ObjectFile)" />
Expand Down
11 changes: 6 additions & 5 deletions src/mono/browser/runtime/invoke-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { wrap_as_cancelable_promise } from "./cancelable-promise";
import { threads_c_functions as tcwraps } from "./cwraps";
import { monoThreadInfo } from "./pthreads";
import { stringToUTF16Ptr } from "./strings";
import { monoSafeSetTimeout } from "./scheduling";

export const js_import_wrapper_by_fn_handle: Function[] = <any>[null];// 0th slot is dummy, main thread we free them on shutdown. On web worker thread we free them when worker is detached.

Expand Down Expand Up @@ -60,7 +61,7 @@ export function mono_wasm_invoke_jsimport_MT (signature: JSFunctionSignature, ar
}
return;
} catch (ex2: any) {
runtimeHelpers.nativeExit(ex2);
runtimeHelpers.nativeAbort(ex2);
return;
}
}
Expand Down Expand Up @@ -501,9 +502,9 @@ export function assert_c_interop (): void {
// make sure we are not blocking em_task_queue_execute up the call stack
// so that when we call back to managed, the FS calls could still be processed by the UI thread
// see also emscripten_yield which can process the FS calls inside the spin wait
export function invoke_later_when_on_ui_thread_sync (fn: Function, args: JSMarshalerArguments) {
export function invoke_later_when_on_ui_thread_sync (fn: (() => void), args: JSMarshalerArguments) {
if (WasmEnableThreads && monoThreadInfo.isUI) {
Module.safeSetTimeout(() => {
monoSafeSetTimeout(() => {
fn();
// see also mono_threads_wasm_sync_run_in_target_thread_vii_cb
const done_semaphore = get_sync_done_semaphore_ptr(args);
Expand All @@ -516,9 +517,9 @@ export function invoke_later_when_on_ui_thread_sync (fn: Function, args: JSMarsh

// make sure we are not blocking em_task_queue_execute up the call stack
// so that when we call back to managed, the FS calls could still be processed by the UI thread
export function invoke_later_when_on_ui_thread_async (fn: Function) {
export function invoke_later_when_on_ui_thread_async (fn: (() => void)) {
if (WasmEnableThreads && monoThreadInfo.isUI) {
Module.safeSetTimeout(fn, 0);
monoSafeSetTimeout(fn, 0);
} else {
fn();
}
Expand Down
3 changes: 2 additions & 1 deletion src/mono/browser/runtime/pthreads/deputy-thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Module, loaderHelpers, runtimeHelpers } from "../globals";
import { start_runtime } from "../startup";
import { WorkerToMainMessageType } from "../types/internal";
import { forceThreadMemoryViewRefresh } from "../memory";
import { monoSafeSetTimeout } from "../scheduling";

export function mono_wasm_start_deputy_thread_async () {
if (!WasmEnableThreads) return;
Expand All @@ -27,7 +28,7 @@ export function mono_wasm_start_deputy_thread_async () {
info: monoThreadInfo,
});
Module.runtimeKeepalivePush();
Module.safeSetTimeout(async () => {
monoSafeSetTimeout(async () => {
try {
forceThreadMemoryViewRefresh();

Expand Down
3 changes: 2 additions & 1 deletion src/mono/browser/runtime/pthreads/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { forceDisposeProxies } from "../gc-handles";
import { monoMessageSymbol, GCHandleNull, PThreadPtrNull, WorkerToMainMessageType } from "../types/internal";
import { threads_c_functions as tcwraps } from "../cwraps";
import { forceThreadMemoryViewRefresh } from "../memory";
import { monoSafeSetTimeout } from "../scheduling";

// A duplicate in loader/assets.ts
export const worker_empty_prefix = " - ";
Expand Down Expand Up @@ -117,7 +118,7 @@ export function exec_synchronization_context_pump (): void {

export function mono_wasm_schedule_synchronization_context (): void {
if (!WasmEnableThreads) return;
Module.safeSetTimeout(exec_synchronization_context_pump, 0);
monoSafeSetTimeout(exec_synchronization_context_pump, 0);
}

export function mono_wasm_pthread_ptr (): PThreadPtr {
Expand Down
22 changes: 20 additions & 2 deletions src/mono/browser/runtime/scheduling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import WasmEnableThreads from "consts:wasmEnableThreads";
import cwraps from "./cwraps";
import { Module, loaderHelpers } from "./globals";
import { forceThreadMemoryViewRefresh } from "./memory";
import { mono_exit } from "./loader/exit";

let spread_timers_maximum = 0;
let pump_count = 0;
Expand Down Expand Up @@ -55,7 +56,7 @@ function mono_background_exec_until_done () {
export function schedule_background_exec (): void {
if (WasmEnableThreads) return;
++pump_count;
Module.safeSetTimeout(mono_background_exec_until_done, 0);
monoSafeSetTimeout(mono_background_exec_until_done, 0);
}

let lastScheduledTimeoutId: any = undefined;
Expand All @@ -65,7 +66,7 @@ export function mono_wasm_schedule_timer (shortestDueTimeMs: number): void {
globalThis.clearTimeout(lastScheduledTimeoutId);
lastScheduledTimeoutId = undefined;
}
lastScheduledTimeoutId = Module.safeSetTimeout(mono_wasm_schedule_timer_tick, shortestDueTimeMs);
lastScheduledTimeoutId = monoSafeSetTimeout(mono_wasm_schedule_timer_tick, shortestDueTimeMs);
}

function mono_wasm_schedule_timer_tick () {
Expand All @@ -80,3 +81,20 @@ function mono_wasm_schedule_timer_tick () {
lastScheduledTimeoutId = undefined;
cwraps.mono_wasm_execute_timer();
}


export function monoSafeSetTimeout (userCallback: (() => void), timeout: number): number {
Module.runtimeKeepalivePush();
return setTimeout(function () {
try {
if (!loaderHelpers.is_runtime_running()) {
return;
}
Module.runtimeKeepalivePop();
userCallback();
Module.maybeExit();
} catch (e) {
mono_exit(1, e);
}
}, timeout);
}
4 changes: 4 additions & 0 deletions src/native/libs/System.Native/pal_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ int32_t SystemNative_UTimensat(const char* path, TimeSpec* times)

updatedTimes[1].tv_sec = (time_t)times[1].tv_sec;
updatedTimes[1].tv_nsec = (long)times[1].tv_nsec;
#if defined(TARGET_BROWSER)
while (CheckInterrupted(result = utimensat(AT_FDCWD, path, updatedTimes, 0)));
#else
while (CheckInterrupted(result = utimensat(AT_FDCWD, path, updatedTimes, AT_SYMLINK_NOFOLLOW)));
#endif
#else
struct timeval updatedTimes[2];
updatedTimes[0].tv_sec = (long)times[0].tv_sec;
Expand Down

0 comments on commit 132e2b2

Please sign in to comment.