github.com/code-reading/golang@v0.0.0-20220303082512-ba5bc0e589a3/go/src/internal/abi/abi.go (about)

     1  // Copyright 2020 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  package abi
     6  
     7  import "unsafe"
     8  
     9  // RegArgs is a struct that has space for each argument
    10  // and return value register on the current architecture.
    11  //
    12  // Assembly code knows the layout of the first two fields
    13  // of RegArgs.
    14  //
    15  // RegArgs also contains additional space to hold pointers
    16  // when it may not be safe to keep them only in the integer
    17  // register space otherwise.
    18  type RegArgs struct {
    19  	Ints   [IntArgRegs]uintptr  // untyped integer registers
    20  	Floats [FloatArgRegs]uint64 // untyped float registers
    21  
    22  	// Fields above this point are known to assembly.
    23  
    24  	// Ptrs is a space that duplicates Ints but with pointer type,
    25  	// used to make pointers passed or returned  in registers
    26  	// visible to the GC by making the type unsafe.Pointer.
    27  	Ptrs [IntArgRegs]unsafe.Pointer
    28  
    29  	// ReturnIsPtr is a bitmap that indicates which registers
    30  	// contain or will contain pointers on the return path from
    31  	// a reflectcall. The i'th bit indicates whether the i'th
    32  	// register contains or will contain a valid Go pointer.
    33  	ReturnIsPtr IntArgRegBitmap
    34  }
    35  
    36  func (r *RegArgs) Dump() {
    37  	print("Ints:")
    38  	for _, x := range r.Ints {
    39  		print(" ", x)
    40  	}
    41  	println()
    42  	print("Floats:")
    43  	for _, x := range r.Floats {
    44  		print(" ", x)
    45  	}
    46  	println()
    47  	print("Ptrs:")
    48  	for _, x := range r.Ptrs {
    49  		print(" ", x)
    50  	}
    51  	println()
    52  }
    53  
    54  // IntArgRegBitmap is a bitmap large enough to hold one bit per
    55  // integer argument/return register.
    56  type IntArgRegBitmap [(IntArgRegs + 7) / 8]uint8
    57  
    58  // Set sets the i'th bit of the bitmap to 1.
    59  func (b *IntArgRegBitmap) Set(i int) {
    60  	b[i/8] |= uint8(1) << (i % 8)
    61  }
    62  
    63  // Get returns whether the i'th bit of the bitmap is set.
    64  //
    65  // nosplit because it's called in extremely sensitive contexts, like
    66  // on the reflectcall return path.
    67  //
    68  //go:nosplit
    69  func (b *IntArgRegBitmap) Get(i int) bool {
    70  	return b[i/8]&(uint8(1)<<(i%8)) != 0
    71  }
    72  
    73  // FuncPC* intrinsics.
    74  //
    75  // CAREFUL: In programs with plugins, FuncPC* can return different values
    76  // for the same function (because there are actually multiple copies of
    77  // the same function in the address space). To be safe, don't use the
    78  // results of this function in any == expression. It is only safe to
    79  // use the result as an address at which to start executing code.
    80  
    81  // FuncPCABI0 returns the entry PC of the function f, which must be a
    82  // direct reference of a function defined as ABI0. Otherwise it is a
    83  // compile-time error.
    84  //
    85  // Implemented as a compile intrinsic.
    86  func FuncPCABI0(f interface{}) uintptr
    87  
    88  // FuncPCABIInternal returns the entry PC of the function f. If f is a
    89  // direct reference of a function, it must be defined as ABIInternal.
    90  // Otherwise it is a compile-time error. If f is not a direct reference
    91  // of a defined function, it assumes that f is a func value. Otherwise
    92  // the behavior is undefined.
    93  //
    94  // Implemented as a compile intrinsic.
    95  func FuncPCABIInternal(f interface{}) uintptr