@@ -29,16 +29,6 @@ type stackChainObject struct {
2929// - The system stack (aka startup stack) is not heap allocated, so even
3030// though it may be referenced it will not be scanned by default.
3131//
32- // Therefore, we only need to scan the system stack.
33- // It is relatively easy to scan the system stack while we're on it: we can
34- // simply read __stack_pointer and __global_base and scan the area in between.
35- // Unfortunately, it's hard to get the system stack pointer while we're on a
36- // goroutine stack. But when we're on a goroutine stack, the system stack is in
37- // the scheduler which means there shouldn't be anything on the system stack
38- // anyway.
39- // ...I hope this assumption holds, otherwise we will need to store the system
40- // stack in a global or something.
41- //
4232// The compiler also inserts code to store all globals in a chain via
4333// stackChainStart. Luckily we don't need to scan these, as these globals are
4434// stored on the goroutine stack and are therefore already getting scanned.
@@ -50,9 +40,18 @@ func markStack() {
5040 // live.
5141 volatile .LoadUint32 ((* uint32 )(unsafe .Pointer (& stackChainStart )))
5242
43+ // Scan the system stack.
44+ var sysSP uintptr
5345 if task .OnSystemStack () {
54- markRoots (getCurrentStackPointer (), stackTop )
46+ // We are on the system stack.
47+ // Use the current stack pointer.
48+ sysSP = getCurrentStackPointer ()
49+ } else {
50+ // We are in a goroutine.
51+ // Use the saved stack pointer.
52+ sysSP = savedStackPointer
5553 }
54+ markRoots (sysSP , stackTop )
5655}
5756
5857// trackPointer is a stub function call inserted by the compiler during IR
0 commit comments