Black Lives Matter. Support the Equal Justice Initiative.

Source file src/internal/abi/abi.go

Documentation: internal/abi

     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  // IntArgRegBitmap is a bitmap large enough to hold one bit per
    37  // integer argument/return register.
    38  type IntArgRegBitmap [(IntArgRegs + 7) / 8]uint8
    39  
    40  // Set sets the i'th bit of the bitmap to 1.
    41  func (b *IntArgRegBitmap) Set(i int) {
    42  	b[i/8] |= uint8(1) << (i % 8)
    43  }
    44  
    45  // Get returns whether the i'th bit of the bitmap is set.
    46  //
    47  // nosplit because it's called in extremely sensitive contexts, like
    48  // on the reflectcall return path.
    49  //
    50  //go:nosplit
    51  func (b *IntArgRegBitmap) Get(i int) bool {
    52  	return b[i/8]&(uint8(1)<<(i%8)) != 0
    53  }
    54  
    55  // FuncPC* intrinsics.
    56  //
    57  // CAREFUL: In programs with plugins, FuncPC* can return different values
    58  // for the same function (because there are actually multiple copies of
    59  // the same function in the address space). To be safe, don't use the
    60  // results of this function in any == expression. It is only safe to
    61  // use the result as an address at which to start executing code.
    62  
    63  // FuncPCABI0 returns the entry PC of the function f, which must be a
    64  // direct reference of a function defined as ABI0. Otherwise it is a
    65  // compile-time error.
    66  //
    67  // Implemented as a compile intrinsic.
    68  func FuncPCABI0(f interface{}) uintptr
    69  
    70  // FuncPCABIInternal returns the entry PC of the function f. If f is a
    71  // direct reference of a function, it must be defined as ABIInternal.
    72  // Otherwise it is a compile-time error. If f is not a direct reference
    73  // of a defined function, it assumes that f is a func value. Otherwise
    74  // the behavior is undefined.
    75  //
    76  // Implemented as a compile intrinsic.
    77  func FuncPCABIInternal(f interface{}) uintptr
    78  

View as plain text