Skip to content

Commit 7bcb5a8

Browse files
authored
[browser][MT] try to fix "Invalid atomic access index" - more (#98640)
1 parent 3296dae commit 7bcb5a8

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

src/mono/browser/runtime/marshal-to-cs.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
set_arg_element_type, ManagedObject, JavaScriptMarshalerArgSize, proxy_debug_symbol, get_arg_gc_handle, get_arg_type
1919
} from "./marshal";
2020
import { get_marshaler_to_js_by_type } from "./marshal-to-js";
21-
import { _zero_region, localHeapViewF64, localHeapViewI32, localHeapViewU8 } from "./memory";
21+
import { _zero_region, forceThreadMemoryViewRefresh, localHeapViewF64, localHeapViewI32, localHeapViewU8 } from "./memory";
2222
import { stringToMonoStringRoot, stringToUTF16 } from "./strings";
2323
import { JSMarshalerArgument, JSMarshalerArguments, JSMarshalerType, MarshalerToCs, MarshalerToJs, BoundMarshalerToCs, MarshalerType } from "./types/internal";
2424
import { TypedArray } from "./types/emscripten";
@@ -359,6 +359,7 @@ function _marshal_task_to_cs(arg: JSMarshalerArgument, value: Promise<any>, _?:
359359
mono_assert(!holder.isCanceled, "This promise already canceled.");
360360
holder.isResolved = true;
361361
if (WasmEnableThreads) {
362+
forceThreadMemoryViewRefresh();
362363
settleUnsettledPromise();
363364
}
364365
// we can unregister the GC handle just on JS side
@@ -387,6 +388,7 @@ function _marshal_task_to_cs(arg: JSMarshalerArgument, value: Promise<any>, _?:
387388
mono_assert(!holder.isResolved, "This promise already resolved.");
388389
holder.isResolved = true;
389390
if (WasmEnableThreads) {
391+
forceThreadMemoryViewRefresh();
390392
settleUnsettledPromise();
391393
}
392394
// we can unregister the GC handle just on JS side

src/mono/browser/runtime/marshal.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import WasmEnableThreads from "consts:wasmEnableThreads";
55

66
import { js_owned_gc_handle_symbol, teardown_managed_proxy } from "./gc-handles";
77
import { Module, loaderHelpers, mono_assert, runtimeHelpers } from "./globals";
8-
import { getF32, getF64, getI16, getI32, getI64Big, getU16, getU32, getU8, setF32, setF64, setI16, setI32, setI64Big, setU16, setU32, setU8, localHeapViewF64, localHeapViewI32, localHeapViewU8, _zero_region, getB32, setB32 } from "./memory";
8+
import { getF32, getF64, getI16, getI32, getI64Big, getU16, getU32, getU8, setF32, setF64, setI16, setI32, setI64Big, setU16, setU32, setU8, localHeapViewF64, localHeapViewI32, localHeapViewU8, _zero_region, getB32, setB32, forceThreadMemoryViewRefresh } from "./memory";
99
import { mono_wasm_new_external_root } from "./roots";
1010
import { GCHandle, JSHandle, MonoObject, MonoString, GCHandleNull, JSMarshalerArguments, JSFunctionSignature, JSMarshalerType, JSMarshalerArgument, MarshalerToJs, MarshalerToCs, WasmRoot, MarshalerType } from "./types/internal";
1111
import { TypedArray, VoidPtr } from "./types/emscripten";
@@ -24,6 +24,9 @@ export const JSMarshalerTypeSize = 32;
2424
export const JSMarshalerSignatureHeaderSize = 4 * 8; // without Exception and Result
2525

2626
export function alloc_stack_frame(size: number): JSMarshalerArguments {
27+
if (WasmEnableThreads) {
28+
forceThreadMemoryViewRefresh();
29+
}
2730
const bytes = JavaScriptMarshalerArgSize * size;
2831
const args = Module.stackAlloc(bytes) as any;
2932
_zero_region(args, bytes);

src/mono/browser/runtime/scheduling.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ function prevent_timer_throttling_tick() {
3434
if (!loaderHelpers.is_runtime_running()) {
3535
return;
3636
}
37+
if (WasmEnableThreads) {
38+
forceThreadMemoryViewRefresh();
39+
}
3740
cwraps.mono_wasm_execute_timer();
3841
pump_count++;
3942
mono_background_exec_until_done();

src/mono/browser/runtime/web-socket.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import WasmEnableThreads from "consts:wasmEnableThreads";
66
import { prevent_timer_throttling } from "./scheduling";
77
import { Queue } from "./queue";
88
import { ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_SHELL, createPromiseController, loaderHelpers, mono_assert } from "./globals";
9-
import { setI32, localHeapViewU8 } from "./memory";
9+
import { setI32, localHeapViewU8, forceThreadMemoryViewRefresh } from "./memory";
1010
import { VoidPtr } from "./types/emscripten";
1111
import { PromiseController } from "./types/internal";
1212
import { mono_log_warn } from "./logging";
@@ -69,6 +69,9 @@ export function ws_wasm_create(uri: string, sub_protocols: string[] | null, rece
6969
try {
7070
if (ws[wasm_ws_is_aborted]) return;
7171
if (!loaderHelpers.is_runtime_running()) return;
72+
if (WasmEnableThreads) {
73+
forceThreadMemoryViewRefresh();
74+
}
7275
open_promise_control.resolve(ws);
7376
prevent_timer_throttling();
7477
} catch (error: any) {
@@ -79,6 +82,9 @@ export function ws_wasm_create(uri: string, sub_protocols: string[] | null, rece
7982
try {
8083
if (ws[wasm_ws_is_aborted]) return;
8184
if (!loaderHelpers.is_runtime_running()) return;
85+
if (WasmEnableThreads) {
86+
forceThreadMemoryViewRefresh();
87+
}
8288
web_socket_on_message(ws, ev);
8389
prevent_timer_throttling();
8490
} catch (error: any) {
@@ -90,6 +96,9 @@ export function ws_wasm_create(uri: string, sub_protocols: string[] | null, rece
9096
ws.removeEventListener("message", local_on_message);
9197
if (ws[wasm_ws_is_aborted]) return;
9298
if (!loaderHelpers.is_runtime_running()) return;
99+
if (WasmEnableThreads) {
100+
forceThreadMemoryViewRefresh();
101+
}
93102

94103
ws[wasm_ws_close_received] = true;
95104
ws["close_status"] = ev.code;
@@ -119,6 +128,9 @@ export function ws_wasm_create(uri: string, sub_protocols: string[] | null, rece
119128
try {
120129
if (ws[wasm_ws_is_aborted]) return;
121130
if (!loaderHelpers.is_runtime_running()) return;
131+
if (WasmEnableThreads) {
132+
forceThreadMemoryViewRefresh();
133+
}
122134
ws.removeEventListener("message", local_on_message);
123135
const message = ev.message
124136
? "WebSocket error: " + ev.message

0 commit comments

Comments
 (0)