github.com/HXSecurity/DongTai-agent-go@v0.4.2/core/base/runtimeMapassign_faststr/replacement.go (about)

     1  package runtimeMapassign_faststr
     2  
     3  import (
     4  	"fmt"
     5  	"unsafe"
     6  	_ "unsafe"
     7  )
     8  
     9  const tmpStringBufSize = 32
    10  
    11  type tflag uint8
    12  type nameOff int32
    13  type typeOff int32
    14  
    15  type _type struct {
    16  	size       uintptr
    17  	ptrdata    uintptr // size of memory prefix holding all pointers
    18  	hash       uint32
    19  	tflag      tflag
    20  	align      uint8
    21  	fieldAlign uint8
    22  	kind       uint8
    23  	// function for comparing objects of this type
    24  	// (ptr to object A, ptr to object B) -> ==?
    25  	equal func(unsafe.Pointer, unsafe.Pointer) bool
    26  	// gcdata stores the GC type data for the garbage collector.
    27  	// If the KindGCProg bit is set in kind, gcdata is a GC program.
    28  	// Otherwise it is a ptrmask bitmap. See mbitmap.go for details.
    29  	gcdata    *byte
    30  	str       nameOff
    31  	ptrToThis typeOff
    32  }
    33  
    34  type maptype struct {
    35  	typ    _type
    36  	key    *_type
    37  	elem   *_type
    38  	bucket *_type // internal type representing a hash bucket
    39  	// function for hashing keys (ptr to key, seed) -> hash
    40  	hasher     func(unsafe.Pointer, uintptr) uintptr
    41  	keysize    uint8  // size of key slot
    42  	elemsize   uint8  // size of elem slot
    43  	bucketsize uint16 // size of bucket
    44  	flags      uint32
    45  }
    46  
    47  // A header for a Go map.
    48  type hmap struct {
    49  	// Note: the format of the hmap is also encoded in cmd/compile/internal/reflectdata/reflect.go.
    50  	// Make sure this stays in sync with the compiler's definition.
    51  	count     int // # live cells == size of map.  Must be first (used by len() builtin)
    52  	flags     uint8
    53  	B         uint8  // log_2 of # of buckets (can hold up to loadFactor * 2^B items)
    54  	noverflow uint16 // approximate number of overflow buckets; see incrnoverflow for details
    55  	hash0     uint32 // hash seed
    56  
    57  	buckets    unsafe.Pointer // array of 2^B Buckets. may be nil if count==0.
    58  	oldbuckets unsafe.Pointer // previous bucket array of half the size, non-nil only when growing
    59  	nevacuate  uintptr        // progress counter for evacuation (buckets less than this have been evacuated)
    60  
    61  	extra *mapextra // optional fields
    62  }
    63  
    64  const (
    65  	// Maximum number of key/elem pairs a bucket can hold.
    66  	bucketCntBits = 3
    67  	bucketCnt     = 1 << bucketCntBits
    68  )
    69  
    70  // A bucket for a Go map.
    71  type bmap struct {
    72  	// tophash generally contains the top byte of the hash value
    73  	// for each key in this bucket. If tophash[0] < minTopHash,
    74  	// tophash[0] is a bucket evacuation state instead.
    75  	tophash [bucketCnt]uint8
    76  	// Followed by bucketCnt keys and then bucketCnt elems.
    77  	// NOTE: packing all the keys together and then all the elems together makes the
    78  	// code a bit more complicated than alternating key/elem/key/elem/... but it allows
    79  	// us to eliminate padding which would be needed for, e.g., map[int64]int8.
    80  	// Followed by an overflow pointer.
    81  }
    82  
    83  // mapextra holds fields that are not present on all maps.
    84  type mapextra struct {
    85  	// If both key and elem do not contain pointers and are inline, then we mark bucket
    86  	// type as containing no pointers. This avoids scanning such maps.
    87  	// However, bmap.overflow is a pointer. In order to keep overflow buckets
    88  	// alive, we store pointers to all overflow buckets in hmap.extra.overflow and hmap.extra.oldoverflow.
    89  	// overflow and oldoverflow are only used if key and elem do not contain pointers.
    90  	// overflow contains overflow buckets for hmap.buckets.
    91  	// oldoverflow contains overflow buckets for hmap.oldbuckets.
    92  	// The indirection allows to store a pointer to the slice in hiter.
    93  	overflow    *[]*bmap
    94  	oldoverflow *[]*bmap
    95  
    96  	// nextOverflow holds a pointer to a free overflow bucket.
    97  	nextOverflow *bmap
    98  }
    99  
   100  //go:linkname concatstrings runtime.mapassign_faststr
   101  func mapassign_faststr(t *maptype, h *hmap, s string) unsafe.Pointer
   102  
   103  func mapassign_faststrR(t *maptype, h *hmap, s string) unsafe.Pointer {
   104  	fmt.Println("Hook到了mapassign_faststrR方法")
   105  	fmt.Println("入参为", t, h, s)
   106  	e := mapassign_faststrT(t, h, s)
   107  	fmt.Println("返回值", e)
   108  	return e
   109  }
   110  
   111  func mapassign_faststrT(t *maptype, h *hmap, s string) unsafe.Pointer {
   112  	return *new(unsafe.Pointer)
   113  }