github.com/undoio/delve@v1.9.0/pkg/proc/linutil/auxv.go (about)

     1  package linutil
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/binary"
     6  )
     7  
     8  const (
     9  	_AT_NULL  = 0
    10  	_AT_ENTRY = 9
    11  )
    12  
    13  // EntryPointFromAuxv searches the elf auxiliary vector for the entry point
    14  // address.
    15  // For a description of the auxiliary vector (auxv) format see:
    16  // System V Application Binary Interface, AMD64 Architecture Processor
    17  // Supplement, section 3.4.3.
    18  // System V Application Binary Interface, Intel386 Architecture Processor
    19  // Supplement (fourth edition), section 3-28.
    20  func EntryPointFromAuxv(auxv []byte, ptrSize int) uint64 {
    21  	rd := bytes.NewBuffer(auxv)
    22  
    23  	for {
    24  		tag, err := readUintRaw(rd, binary.LittleEndian, ptrSize)
    25  		if err != nil {
    26  			return 0
    27  		}
    28  		val, err := readUintRaw(rd, binary.LittleEndian, ptrSize)
    29  		if err != nil {
    30  			return 0
    31  		}
    32  
    33  		switch tag {
    34  		case _AT_NULL:
    35  			return 0
    36  		case _AT_ENTRY:
    37  			return val
    38  		}
    39  	}
    40  }