diff --git a/src/mono/browser/browser.proj b/src/mono/browser/browser.proj index f7429193002a60..7646be944b156c 100644 --- a/src/mono/browser/browser.proj +++ b/src/mono/browser/browser.proj @@ -369,8 +369,7 @@ -g -Os -s -DDEBUG=1 -DENABLE_AOT_PROFILER=1 -DENABLE_BROWSER_PROFILER=1 -Oz -DENABLE_BROWSER_PROFILER=1 - $(CMakeConfigurationEmccFlags) -s ASSERTIONS=1 - -O2 + $(CMakeConfigurationEmccFlags) -s ASSERTIONS=1 $(CMakeConfigurationLinkFlags) -s EXPORT_ES6=1 -lexports.js diff --git a/src/mono/browser/build/BrowserWasmApp.targets b/src/mono/browser/build/BrowserWasmApp.targets index aa231c45d8b7cc..0c793e8a66d8e9 100644 --- a/src/mono/browser/build/BrowserWasmApp.targets +++ b/src/mono/browser/build/BrowserWasmApp.targets @@ -432,7 +432,7 @@ <_EmccLDSFlags Include="-s STACK_SIZE=$(EmccStackSize)" /> <_EmccLDSFlags Include="-s WASM_BIGINT=1" /> <_EmccLDSFlags Condition="'$(EmccEnvironment)' != ''" Include="-s ENVIRONMENT="$(EmccEnvironment)"" /> - <_EmccLDSFlags Condition="'$(EmccEnableAssertions)' == 'true'" Include="-s ASSERTIONS=1" /> + <_EmccLDSFlags Include="-s ASSERTIONS=1" /> <_WasmNativeFileForLinking Include="%(_BitcodeFile.ObjectFile)" /> <_WasmNativeFileForLinking Include="%(_WasmSourceFileToCompile.ObjectFile)" /> diff --git a/src/mono/browser/runtime/invoke-js.ts b/src/mono/browser/runtime/invoke-js.ts index c5d385a17e4e44..1be08285613427 100644 --- a/src/mono/browser/runtime/invoke-js.ts +++ b/src/mono/browser/runtime/invoke-js.ts @@ -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[] = [null];// 0th slot is dummy, main thread we free them on shutdown. On web worker thread we free them when worker is detached. @@ -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); @@ -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(); } diff --git a/src/mono/browser/runtime/pthreads/deputy-thread.ts b/src/mono/browser/runtime/pthreads/deputy-thread.ts index 4b514b28a4aed3..ddb38d1f666ebb 100644 --- a/src/mono/browser/runtime/pthreads/deputy-thread.ts +++ b/src/mono/browser/runtime/pthreads/deputy-thread.ts @@ -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; @@ -27,7 +28,7 @@ export function mono_wasm_start_deputy_thread_async () { info: monoThreadInfo, }); Module.runtimeKeepalivePush(); - Module.safeSetTimeout(async () => { + monoSafeSetTimeout(async () => { try { forceThreadMemoryViewRefresh(); diff --git a/src/mono/browser/runtime/pthreads/shared.ts b/src/mono/browser/runtime/pthreads/shared.ts index 69137957eeeebe..290233b29ae956 100644 --- a/src/mono/browser/runtime/pthreads/shared.ts +++ b/src/mono/browser/runtime/pthreads/shared.ts @@ -11,6 +11,7 @@ import { set_thread_prefix } from "../logging"; import { monoMessageSymbol, 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 = " - "; @@ -86,7 +87,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 { diff --git a/src/mono/browser/runtime/scheduling.ts b/src/mono/browser/runtime/scheduling.ts index 0be8cb19a72336..5639707696e69a 100644 --- a/src/mono/browser/runtime/scheduling.ts +++ b/src/mono/browser/runtime/scheduling.ts @@ -63,7 +63,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; @@ -73,7 +73,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 () { @@ -93,3 +93,21 @@ function mono_wasm_schedule_timer_tick () { loaderHelpers.mono_exit(1, ex); } } + + +export function monoSafeSetTimeout (userCallback: (() => void), timeout: number): number { + Module.runtimeKeepalivePush(); + return setTimeout(() => { + try { + if (!loaderHelpers.is_runtime_running()) { + return; + } + Module.maybeExit(); + Module.runtimeKeepalivePop(); + userCallback(); + Module.maybeExit(); + } catch (e) { + loaderHelpers.mono_exit(1, e); + } + }, timeout); +} diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 8b57badb1a2e38..89cd40be9f6111 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -413,7 +413,7 @@ <_MonoMinimal Condition="'$(Configuration)' == 'Release'">,debugger_agent,log_dest - <_MonoMinimal Condition="'$(Configuration)' == 'Release' and '$(MonoEnableAssertMessages)' != 'true'">$(_MonoMinimal),assert_messages + <_MonoMinimal Condition="'$(Configuration)' == 'Release'">$(_MonoMinimal),assert_messages <_MonoMinimal Condition="'$(WasmEnableThreads)' != 'true'">$(_MonoMinimal),threads diff --git a/src/native/libs/System.Native/pal_time.c b/src/native/libs/System.Native/pal_time.c index a249fe653be1c0..bd33d7d49a45a8 100644 --- a/src/native/libs/System.Native/pal_time.c +++ b/src/native/libs/System.Native/pal_time.c @@ -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;