...

Source file src/runtime/testdata/testprog/framepointer.go

Documentation: runtime/testdata/testprog

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build amd64 || arm64
     6  
     7  package main
     8  
     9  import "unsafe"
    10  
    11  func init() {
    12  	register("FramePointerAdjust", FramePointerAdjust)
    13  }
    14  
    15  func FramePointerAdjust() { framePointerAdjust1(0) }
    16  
    17  //go:noinline
    18  func framePointerAdjust1(x int) {
    19  	argp := uintptr(unsafe.Pointer(&x))
    20  	fp := *getFP()
    21  	if !(argp-0x100 <= fp && fp <= argp+0x100) {
    22  		print("saved FP=", fp, " &x=", argp, "\n")
    23  		panic("FAIL")
    24  	}
    25  
    26  	// grow the stack
    27  	grow(10000)
    28  
    29  	// check again
    30  	argp = uintptr(unsafe.Pointer(&x))
    31  	fp = *getFP()
    32  	if !(argp-0x100 <= fp && fp <= argp+0x100) {
    33  		print("saved FP=", fp, " &x=", argp, "\n")
    34  		panic("FAIL")
    35  	}
    36  }
    37  
    38  func grow(n int) {
    39  	if n > 0 {
    40  		grow(n - 1)
    41  	}
    42  }
    43  
    44  func getFP() *uintptr
    45  

View as plain text