task_stack_wasm.mx raw
1 //go:build scheduler.tasks && wasm
2
3 package task
4
5 import "unsafe"
6
7 var systemStack uintptr
8
9 // calleeSavedRegs on WASM is empty — WASM manages its own value stack.
10 // Task switching is done via the asyncify transform or cooperative yields.
11 type calleeSavedRegs struct{}
12
13 // archInit stores the function and args for the task. On WASM, there are no
14 // hardware registers to initialize — the runtime uses cooperative scheduling.
15 func (s *state) archInit(r *calleeSavedRegs, fn uintptr, args unsafe.Pointer) {
16 s.sp = uintptr(unsafe.Pointer(r))
17 }
18
19 func (s *state) resume() {
20 swapTask(s.sp, &systemStack)
21 }
22
23 func (s *state) pause() {
24 newStack := systemStack
25 systemStack = 0
26 swapTask(newStack, &s.sp)
27 }
28
29 func SystemStack() uintptr {
30 return systemStack
31 }
32