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] with emscripten ASSERTIONS #100767

Closed
wants to merge 1 commit into from
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: 1 addition & 2 deletions src/mono/browser/browser.proj
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,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
9 changes: 5 additions & 4 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 @@ -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 @@ -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 = " - ";
Expand Down Expand Up @@ -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 {
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 @@ -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;
Expand All @@ -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 () {
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion src/mono/mono.proj
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@
<!-- WASM specific options -->
<PropertyGroup Condition="'$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true'">
<_MonoMinimal Condition="'$(Configuration)' == 'Release'">,debugger_agent,log_dest</_MonoMinimal>
<_MonoMinimal Condition="'$(Configuration)' == 'Release' and '$(MonoEnableAssertMessages)' != 'true'">$(_MonoMinimal),assert_messages</_MonoMinimal>
<_MonoMinimal Condition="'$(Configuration)' == 'Release'">$(_MonoMinimal),assert_messages</_MonoMinimal>
<_MonoMinimal Condition="'$(WasmEnableThreads)' != 'true'">$(_MonoMinimal),threads</_MonoMinimal>
</PropertyGroup>
<ItemGroup Condition="'$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true'">
Expand Down
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
Loading