Skip to content

Commit f66ec4c

Browse files
aykevldeadprogram
authored andcommitted
wasm: refactor/modify stub signal handling
This commit changes signal handling in a few ways: * It stubs signals for all wasm targets (not just wasi) and baremetal, since none of those have traditional POSIX signals. And moves the code for that into a single file, instead of duplicating it. * It removes the stub for signal_ignored since the value `false` might be wrong in some cases and it doesn't usually seem to be called (it is not called in tsgo). Should be trivial to re-add if it is shown to be needed. * It adds a stub for `os/signal.signalWaitUntilIdle` which _is_ called by tsgo.
1 parent 60ccc9e commit f66ec4c

File tree

3 files changed

+21
-34
lines changed

3 files changed

+21
-34
lines changed

src/runtime/runtime_wasip1.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,3 @@ type (
149149
}
150150
}
151151
)
152-
153-
// Need to stub these for `os/signal`, but wasi doesn't support signals.
154-
155-
//go:linkname signal_disable os/signal.signal_disable
156-
func signal_disable(uint32) {}
157-
158-
//go:linkname signal_enable os/signal.signal_enable
159-
func signal_enable(uint32) {}
160-
161-
//go:linkname signal_ignore os/signal.signal_ignore
162-
func signal_ignore(uint32) {}
163-
164-
//go:linkname signal_ignored os/signal.signal_ignored
165-
func signal_ignored(uint32) bool { return false }
166-
167-
//go:linkname signal_recv os/signal.signal_recv
168-
func signal_recv() uint32 { return ^uint32(0) }

src/runtime/runtime_wasip2.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,3 @@ func sleepTicks(d timeUnit) {
5050
func ticks() timeUnit {
5151
return timeUnit(monotonicclock.Now())
5252
}
53-
54-
// Need to stub these for `os/signal`, but wasi doesn't support signals.
55-
56-
//go:linkname signal_disable os/signal.signal_disable
57-
func signal_disable(uint32) {}
58-
59-
//go:linkname signal_enable os/signal.signal_enable
60-
func signal_enable(uint32) {}
61-
62-
//go:linkname signal_ignore os/signal.signal_ignore
63-
func signal_ignore(uint32) {}
64-
65-
//go:linkname signal_ignored os/signal.signal_ignored
66-
func signal_ignored(uint32) bool { return false }
67-
68-
//go:linkname signal_recv os/signal.signal_recv
69-
func signal_recv() uint32 { return ^uint32(0) }

src/runtime/signalstub.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//go:build tinygo.wasm || baremetal
2+
3+
package runtime
4+
5+
// Some platforms don't support Unix signals (and never will), so we need to
6+
// stub the signal functions.
7+
8+
//go:linkname signal_disable os/signal.signal_disable
9+
func signal_disable(uint32) {}
10+
11+
//go:linkname signal_enable os/signal.signal_enable
12+
func signal_enable(uint32) {}
13+
14+
//go:linkname signal_ignore os/signal.signal_ignore
15+
func signal_ignore(uint32) {}
16+
17+
//go:linkname signal_waitUntilIdle os/signal.signalWaitUntilIdle
18+
func signal_waitUntilIdle() {}
19+
20+
//go:linkname signal_recv os/signal.signal_recv
21+
func signal_recv() uint32 { return ^uint32(0) }

0 commit comments

Comments
 (0)