space-data-module-sdk 0.8.24 → 0.8.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,12 +35,31 @@ ENV PATH="/opt/wasmedge/bin:${PATH}" \
35
35
  LD_LIBRARY_PATH="/opt/wasmedge/lib64:/opt/wasmedge/lib"
36
36
 
37
37
  COPY native/wasmedge_wasi_threads_runner.c /tmp/sdm-wasi-threads-runner.c
38
- COPY native/wasmedge-0.16.4-atomic-wait.patch /tmp/atomic-wait.patch
39
- # The ordinary CLI keeps its release library. Only the SDK thread runner uses
40
- # the isolated 0.16.4 atomic-wait correction, matching the native build.
38
+ # The SDN WasmEdge 0.16.4 patch series, byte-identical to SDN's testdata/
39
+ # (sdn-server/internal/wasmrt/SUBSTRATE.md): 01-atomic-wait, 02-stop-token,
40
+ # 03-fault-jmp, 04-atomic-memarg-offset. Order matters (02 and 04 both touch
41
+ # lib/llvm/compiler.cpp) and matches SDN's build-static-wasmedge.sh.
42
+ # The ordinary CLI (above) keeps its release library. Only the SDK thread
43
+ # runner links this patched build, matching the native (non-Docker) build in
44
+ # buildWasmEdgeRunner.js. Configured -DWASMEDGE_USE_LLVM=OFF, which in 0.16.4
45
+ # also gates WASMEDGE_BUILD_AOT_RUNTIME: this library can neither compile nor
46
+ # load AOT code. Patches 02-04 therefore patch code this runner never
47
+ # executes (Interruptible-AOT stop-token traffic, the AOT fault path, and the
48
+ # LLVM AOT compiler); only 01 changes this image's observable behaviour
49
+ # today. They stay applied so this image's WasmEdge checkout never drifts
50
+ # from SDN's patched baseline. This is also why no memarg-offset (04)
51
+ # regression test runs against this image: there is no AOT lane here to run
52
+ # SDN's substrate probe against.
53
+ COPY native/wasmedge-0.16.4-atomic-wait.patch /tmp/01-atomic-wait.patch
54
+ COPY native/wasmedge-0.16.4-stop-token.patch /tmp/02-stop-token.patch
55
+ COPY native/wasmedge-0.16.4-fault-jmp.patch /tmp/03-fault-jmp.patch
56
+ COPY native/wasmedge-0.16.4-atomic-memarg-offset.patch /tmp/04-atomic-memarg-offset.patch
41
57
  RUN git clone --depth 1 --branch 0.16.4 https://github.com/WasmEdge/WasmEdge.git /tmp/wasmedge-source \
42
58
  && test "$(git -C /tmp/wasmedge-source rev-parse HEAD)" = be85c2fbba68318f103b4a766728f6946e65abf8 \
43
- && git -C /tmp/wasmedge-source apply /tmp/atomic-wait.patch \
59
+ && git -C /tmp/wasmedge-source apply /tmp/01-atomic-wait.patch \
60
+ && git -C /tmp/wasmedge-source apply /tmp/02-stop-token.patch \
61
+ && git -C /tmp/wasmedge-source apply /tmp/03-fault-jmp.patch \
62
+ && git -C /tmp/wasmedge-source apply /tmp/04-atomic-memarg-offset.patch \
44
63
  && cmake -S /tmp/wasmedge-source -B /tmp/wasmedge-build -G Ninja \
45
64
  -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/sdm-wasmedge \
46
65
  "-DCMAKE_CXX_FLAGS=-Wno-error=maybe-uninitialized -Wno-error=array-bounds" \
@@ -48,7 +67,8 @@ RUN git clone --depth 1 --branch 0.16.4 https://github.com/WasmEdge/WasmEdge.git
48
67
  -DWASMEDGE_BUILD_TOOLS=OFF -DWASMEDGE_FORCE_DISABLE_LTO=ON \
49
68
  && cmake --build /tmp/wasmedge-build -j 4 \
50
69
  && cmake --install /tmp/wasmedge-build \
51
- && rm -rf /tmp/wasmedge-source /tmp/wasmedge-build /tmp/atomic-wait.patch
70
+ && rm -rf /tmp/wasmedge-source /tmp/wasmedge-build \
71
+ /tmp/01-atomic-wait.patch /tmp/02-stop-token.patch /tmp/03-fault-jmp.patch /tmp/04-atomic-memarg-offset.patch
52
72
  RUN cc /tmp/sdm-wasi-threads-runner.c -std=c11 -O2 -pthread -Wall -Wextra -Werror \
53
73
  -I/opt/sdm-wasmedge/include -L/opt/sdm-wasmedge/lib64 -L/opt/sdm-wasmedge/lib -lwasmedge \
54
74
  -Wl,--disable-new-dtags,-rpath,/opt/sdm-wasmedge/lib64,-rpath,/opt/sdm-wasmedge/lib \
@@ -459,6 +459,8 @@ export function createBrowserModuleHarness(options?: {
459
459
  initialMemoryBytes?: number;
460
460
  maximumMemoryBytes?: number;
461
461
  maxThreads?: number;
462
+ wasiThreadSpawnWaitMs?: number;
463
+ wasiThreadPoolSize?: number;
462
464
  threadHostcallChannel?: {
463
465
  channelName: string;
464
466
  token: string;
@@ -0,0 +1,46 @@
1
+ diff --git a/lib/llvm/compiler.cpp b/lib/llvm/compiler.cpp
2
+ index f765db6..5b1bfc3 100644
3
+ --- a/lib/llvm/compiler.cpp
4
+ +++ b/lib/llvm/compiler.cpp
5
+ @@ -3952,6 +3952,21 @@ public:
6
+ Builder.positionAtEnd(OkBB);
7
+ }
8
+
9
+ + // memory.atomic.notify / wait32 / wait64 call the runtime with the
10
+ + // effective address: the operand plus the memarg offset (as the interpreter
11
+ + // does, threadInstr.cpp). Passing the bare operand notified and waited on
12
+ + // the wrong word whenever the offset was not 0 (a global such as wasi-libc's
13
+ + // __thread_list_lock at `i32.const 0; memory.atomic.notify offset=N`): lost
14
+ + // wakeups. An address past 4 GiB is out of bounds.
15
+ + LLVM::Value compileAtomicEffectiveAddress(LLVM::Value Addr) noexcept {
16
+ + auto OkBB = LLVM::BasicBlock::create(LLContext, F.Fn, "address_in_bounds");
17
+ + auto InBounds = Builder.createLikely(
18
+ + Builder.createICmpULE(Addr, LLContext.getInt64(UINT32_MAX)));
19
+ + Builder.createCondBr(InBounds, OkBB,
20
+ + getTrapBB(ErrCode::Value::MemoryOutOfBounds));
21
+ + Builder.positionAtEnd(OkBB);
22
+ + return Builder.createTrunc(Addr, Context.Int32Ty);
23
+ + }
24
+ void compileMemoryFence() noexcept {
25
+ Builder.createFence(LLVMAtomicOrderingSequentiallyConsistent);
26
+ }
27
+ @@ -3963,7 +3978,8 @@ public:
28
+ Addr = Builder.createAdd(Addr, LLContext.getInt64(MemoryOffset));
29
+ }
30
+ compileAtomicCheckOffsetAlignment(Addr, Context.Int32Ty);
31
+ - auto Offset = stackPop();
32
+ + stackPop();
33
+ + auto Offset = compileAtomicEffectiveAddress(Addr);
34
+
35
+ stackPush(Builder.createCall(
36
+ Context.getIntrinsic(
37
+ @@ -3982,7 +3998,8 @@ public:
38
+ Addr = Builder.createAdd(Addr, LLContext.getInt64(MemoryOffset));
39
+ }
40
+ compileAtomicCheckOffsetAlignment(Addr, TargetType);
41
+ - auto Offset = stackPop();
42
+ + stackPop();
43
+ + auto Offset = compileAtomicEffectiveAddress(Addr);
44
+
45
+ stackPush(Builder.createCall(
46
+ Context.getIntrinsic(
@@ -0,0 +1,35 @@
1
+ diff --git a/include/system/fault.h b/include/system/fault.h
2
+ index 1f57d78..71dd6ea 100644
3
+ --- a/include/system/fault.h
4
+ +++ b/include/system/fault.h
5
+ @@ -43,4 +43,14 @@ private:
6
+
7
+ } // namespace WasmEdge
8
+
9
+ +// _setjmp/_longjmp carry no signal state. darwin's longjmp resets or sets the
10
+ +// thread's alternate-signal-stack flag from a jmp_buf word setjmp never
11
+ +// writes, so a trap could leave a thread marked as running on its signal stack
12
+ +// and the embedder's next signal (Go's preemption) lands on the wrong stack.
13
+ +// The fault handler unblocks its own signal before it jumps, so nothing needs
14
+ +// restoring.
15
+ +#if defined(_WIN32)
16
+ #define PREPARE_FAULT(f) (static_cast<uint32_t>(setjmp((f).buffer())))
17
+ +#else
18
+ +#define PREPARE_FAULT(f) (static_cast<uint32_t>(_setjmp((f).buffer())))
19
+ +#endif
20
+ diff --git a/lib/system/fault.cpp b/lib/system/fault.cpp
21
+ index e435d4e..c49f5ae 100644
22
+ --- a/lib/system/fault.cpp
23
+ +++ b/lib/system/fault.cpp
24
+ @@ -118,7 +118,11 @@ Fault::~Fault() noexcept {
25
+ assuming(localHandler != nullptr);
26
+ auto Buffer = stackTrace(localHandler->StackTraceBuffer);
27
+ localHandler->StackTraceSize = Buffer.size();
28
+ +#if defined(_WIN32)
29
+ longjmp(localHandler->Buffer, static_cast<int>(Error.operator uint32_t()));
30
+ +#else
31
+ + _longjmp(localHandler->Buffer, static_cast<int>(Error.operator uint32_t()));
32
+ +#endif
33
+ }
34
+
35
+ } // namespace WasmEdge
@@ -0,0 +1,111 @@
1
+ diff --git a/include/executor/executor.h b/include/executor/executor.h
2
+ index 6683ee9..6bdccea 100644
3
+ --- a/include/executor/executor.h
4
+ +++ b/include/executor/executor.h
5
+ @@ -201,9 +201,15 @@ public:
6
+ asyncInvoke(const Runtime::Instance::FunctionInstance *FuncInst,
7
+ Span<const ValVariant> Params, Span<const ValType> ParamTypes);
8
+
9
+ - /// Stop execution
10
+ + /// Stop execution.
11
+ + ///
12
+ + /// SDN patch (stop-token): a stop is STICKY for every invocation running on
13
+ + /// this executor. Upstream consumed the token with exchange(0), so one stop
14
+ + /// interrupted exactly one thread and every other wasi-thread on the same
15
+ + /// executor kept running. The token is cleared only when the next
16
+ + /// invocation starts on an idle executor (see invoke()).
17
+ void stop() noexcept {
18
+ - StopToken.store(1, std::memory_order_relaxed);
19
+ + StopToken.store(1, std::memory_order_seq_cst);
20
+ atomicNotifyAll();
21
+ }
22
+
23
+ @@ -1120,6 +1126,8 @@ private:
24
+ Statistics::Statistics *Stat;
25
+ /// Stop Execution
26
+ std::atomic_uint32_t StopToken = 0;
27
+ + /// Invocations currently running on this executor (SDN stop-token patch).
28
+ + std::atomic_uint32_t ActiveInvocations = 0;
29
+ /// Executor Host Function Handler
30
+ HostFuncHandler HostFuncHelper = {};
31
+ };
32
+ diff --git a/lib/executor/engine/controlInstr.cpp b/lib/executor/engine/controlInstr.cpp
33
+ index 935992a..55e08d7 100644
34
+ --- a/lib/executor/engine/controlInstr.cpp
35
+ +++ b/lib/executor/engine/controlInstr.cpp
36
+ @@ -134,7 +134,7 @@ Expect<void> Executor::runBrOnCastOp(Runtime::StackManager &StackMgr,
37
+ Expect<void> Executor::runReturnOp(Runtime::StackManager &StackMgr,
38
+ AST::InstrView::iterator &PC) noexcept {
39
+ // Check stop token
40
+ - if (unlikely(StopToken.exchange(0, std::memory_order_relaxed))) {
41
+ + if (unlikely(StopToken.load(std::memory_order_relaxed))) {
42
+ spdlog::error(ErrCode::Value::Interrupted);
43
+ return Unexpect(ErrCode::Value::Interrupted);
44
+ }
45
+ diff --git a/lib/executor/executor.cpp b/lib/executor/executor.cpp
46
+ index 137131b..68ef4fe 100644
47
+ --- a/lib/executor/executor.cpp
48
+ +++ b/lib/executor/executor.cpp
49
+ @@ -140,6 +140,16 @@ Executor::invoke(const Runtime::Instance::FunctionInstance *FuncInst,
50
+ }
51
+ }
52
+
53
+ + // SDN patch (stop-token): a stop issued while invocations run stays set
54
+ + // until all of them have returned; the first invocation on an idle executor
55
+ + // clears a token left over from an earlier stop.
56
+ + if (ActiveInvocations.fetch_add(1, std::memory_order_acq_rel) == 0) {
57
+ + StopToken.store(0, std::memory_order_seq_cst);
58
+ + }
59
+ + cxx20::scope_exit ActiveInvocationGuard([this]() noexcept {
60
+ + ActiveInvocations.fetch_sub(1, std::memory_order_acq_rel);
61
+ + });
62
+ +
63
+ Runtime::StackManager StackMgr;
64
+
65
+ // Call runFunction.
66
+ diff --git a/lib/executor/helper.cpp b/lib/executor/helper.cpp
67
+ index 96205cc..2ace419 100644
68
+ --- a/lib/executor/helper.cpp
69
+ +++ b/lib/executor/helper.cpp
70
+ @@ -51,7 +51,7 @@ Executor::enterFunction(Runtime::StackManager &StackMgr,
71
+ // RetIt: the return position when the entered function returns.
72
+
73
+ // Check if the interruption occurs.
74
+ - if (unlikely(StopToken.exchange(0, std::memory_order_relaxed))) {
75
+ + if (unlikely(StopToken.load(std::memory_order_relaxed))) {
76
+ spdlog::error(ErrCode::Value::Interrupted);
77
+ return Unexpect(ErrCode::Value::Interrupted);
78
+ }
79
+ @@ -251,7 +251,7 @@ Executor::branchToLabel(Runtime::StackManager &StackMgr,
80
+ const AST::Instruction::JumpDescriptor &JumpDesc,
81
+ AST::InstrView::iterator &PC) noexcept {
82
+ // Check the stop token.
83
+ - if (unlikely(StopToken.exchange(0, std::memory_order_relaxed))) {
84
+ + if (unlikely(StopToken.load(std::memory_order_relaxed))) {
85
+ spdlog::error(ErrCode::Value::Interrupted);
86
+ return Unexpect(ErrCode::Value::Interrupted);
87
+ }
88
+ diff --git a/lib/llvm/compiler.cpp b/lib/llvm/compiler.cpp
89
+ index 8db12e3..f765db6 100644
90
+ --- a/lib/llvm/compiler.cpp
91
+ +++ b/lib/llvm/compiler.cpp
92
+ @@ -5670,12 +5670,13 @@ private:
93
+ return;
94
+ }
95
+ auto NotStopBB = LLVM::BasicBlock::create(LLContext, F.Fn, "NotStop");
96
+ - auto StopToken = Builder.createAtomicRMW(
97
+ - LLVMAtomicRMWBinOpXchg, Context.getStopToken(Builder, ExecCtx),
98
+ - LLContext.getInt32(0), LLVMAtomicOrderingMonotonic);
99
+ -#if LLVM_VERSION_MAJOR >= 13
100
+ - StopToken.setAlignment(32);
101
+ -#endif
102
+ + // SDN patch (stop-token): read the token, never consume it. An exchange
103
+ + // let one thread swallow a stop meant for all of them, and it made every
104
+ + // block of every thread an RMW on one shared cache line.
105
+ + auto StopToken = Builder.createLoad(
106
+ + LLContext.getInt32Ty(), Context.getStopToken(Builder, ExecCtx), true);
107
+ + StopToken.setOrdering(LLVMAtomicOrderingMonotonic);
108
+ + StopToken.setAlignment(4);
109
+ auto NotStop = Builder.createLikely(
110
+ Builder.createICmpEQ(StopToken, LLContext.getInt32(0)));
111
+ Builder.createCondBr(NotStop, NotStopBB,
@@ -71,9 +71,16 @@ export function loadWasmEdgePin() {
71
71
  if (!repository) {
72
72
  throw new Error("wasmedgePin.json dockerImageRepository is required.");
73
73
  }
74
+ // The SDN WasmEdge 0.16.4 patch series (01-atomic-wait, 02-stop-token,
75
+ // 03-fault-jmp, 04-atomic-memarg-offset; sdn-server/internal/wasmrt/SUBSTRATE.md).
76
+ // Any change to the runner source, any patch, or the Dockerfile itself must
77
+ // bump this identity so a stale-patched image is never reused.
74
78
  const runnerIdentity = createHash("sha256")
75
79
  .update(readFileSync(path.join(__dirname, "native/wasmedge_wasi_threads_runner.c")))
76
80
  .update(readFileSync(path.join(__dirname, "native/wasmedge-0.16.4-atomic-wait.patch")))
81
+ .update(readFileSync(path.join(__dirname, "native/wasmedge-0.16.4-stop-token.patch")))
82
+ .update(readFileSync(path.join(__dirname, "native/wasmedge-0.16.4-fault-jmp.patch")))
83
+ .update(readFileSync(path.join(__dirname, "native/wasmedge-0.16.4-atomic-memarg-offset.patch")))
77
84
  .update(readFileSync(path.join(__dirname, String(pin.dockerfile))))
78
85
  .digest("hex").slice(0, 16);
79
86
  return Object.freeze({