github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/runtime/gc_stack_raw.go (about)

     1  //go:build (gc.conservative || gc.precise) && !tinygo.wasm
     2  
     3  package runtime
     4  
     5  import "internal/task"
     6  
     7  // markStack marks all root pointers found on the stack.
     8  //
     9  // This implementation is conservative and relies on the stack top (provided by
    10  // the linker) and getting the current stack pointer from a register. Also, it
    11  // assumes a descending stack. Thus, it is not very portable.
    12  func markStack() {
    13  	// Scan the current stack, and all current registers.
    14  	scanCurrentStack()
    15  
    16  	if !task.OnSystemStack() {
    17  		// Mark system stack.
    18  		markRoots(getSystemStackPointer(), stackTop)
    19  	}
    20  }
    21  
    22  //go:export tinygo_scanCurrentStack
    23  func scanCurrentStack()
    24  
    25  //go:export tinygo_scanstack
    26  func scanstack(sp uintptr) {
    27  	// Mark current stack.
    28  	// This function is called by scanCurrentStack, after pushing all registers onto the stack.
    29  	// Callee-saved registers have been pushed onto stack by tinygo_localscan, so this will scan them too.
    30  	if task.OnSystemStack() {
    31  		// This is the system stack.
    32  		// Scan all words on the stack.
    33  		markRoots(sp, stackTop)
    34  	} else {
    35  		// This is a goroutine stack.
    36  		// It is an allocation, so scan it as if it were a value in a global.
    37  		markRoot(0, sp)
    38  	}
    39  }