runtime: refactor obtaining the system stack

The system stack is only needed when we're not on it. So we can directly
call task.SystemStack() without problems.

This also saves a tiny bit of binary size.
This commit is contained in:
Ayke van Laethem
2025-06-11 10:26:52 +02:00
committed by Ron Evans
parent 3a2188fc7b
commit 0c7c2926f9
5 changed files with 10 additions and 27 deletions
+3 -3
View File
@@ -42,9 +42,9 @@ func TestBinarySize(t *testing.T) {
// This is a small number of very diverse targets that we want to test.
tests := []sizeTest{
// microcontrollers
{"hifive1b", "examples/echo", 4560, 280, 0, 2268},
{"microbit", "examples/serial", 2924, 388, 8, 2272},
{"wioterminal", "examples/pininterrupt", 7383, 1489, 116, 6912},
{"hifive1b", "examples/echo", 4556, 280, 0, 2268},
{"microbit", "examples/serial", 2920, 388, 8, 2272},
{"wioterminal", "examples/pininterrupt", 7379, 1489, 116, 6912},
// TODO: also check wasm. Right now this is difficult, because
// wasm binaries are run through wasm-opt and therefore the
+6
View File
@@ -36,3 +36,9 @@ func OnSystemStack() bool {
// This scheduler does not do any stack switching.
return true
}
func SystemStack() uintptr {
// System stack is the current stack, so this shouldn't be called.
runtimePanic("scheduler is disabled")
return 0 // unreachable
}
+1 -1
View File
@@ -20,7 +20,7 @@ func markStack() {
if !task.OnSystemStack() {
// Mark system stack.
markRoots(getSystemStackPointer(), stackTop)
markRoots(task.SystemStack(), stackTop)
}
}
-6
View File
@@ -73,9 +73,3 @@ func scheduler(returnAtDeadlock bool) {
// this code should be unreachable.
runtimePanic("unreachable: scheduler must not be called with the 'none' scheduler")
}
// getSystemStackPointer returns the current stack pointer of the system stack.
// This is always the current stack pointer.
func getSystemStackPointer() uintptr {
return getCurrentStackPointer()
}
-17
View File
@@ -1,17 +0,0 @@
//go:build scheduler.tasks
package runtime
import "internal/task"
// getSystemStackPointer returns the current stack pointer of the system stack.
// This is not necessarily the same as the current stack pointer.
func getSystemStackPointer() uintptr {
// TODO: this always returns the correct stack on Cortex-M, so don't bother
// comparing against 0.
sp := task.SystemStack()
if sp == 0 {
sp = getCurrentStackPointer()
}
return sp
}