github.com/primecitizens/pcz/std@v0.2.1/core/sys/auxv_uintptr.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  
     4  //go:build !noos && (linux || freebsd || netbsd || solaris || dragonfly)
     5  
     6  package sys
     7  
     8  var (
     9  	auxvs []uintptr
    10  )
    11  
    12  func init() {
    13  	base := unsafe.SliceData(_args)
    14  	if base == nil { // no args
    15  		return
    16  	}
    17  
    18  	// base is the envv
    19  	base := stdptr.Add(unsafe.SliceData(_args), arch.PtrSize*uintptr(len(_args)+1 /* NULL sep */))
    20  	n := 0
    21  	for p := base; *p != nil; p = stdptr.Add(p, arch.PtrSize) {
    22  		n++
    23  	}
    24  	envs = unsafe.Slice(base, n)
    25  
    26  	// auxvv
    27  	base = stdptr.Add(base, arch.PtrSize*uintptr(n+1 /* NULL sep */))
    28  	n = 0
    29  	for p := base; *p != nil; p = stdptr.Add(p, arch.PtrSize) {
    30  		n++
    31  	}
    32  	auxvs = unsafe.Slice((*uintptr)(unsafe.Pointer(base)), n)
    33  }
    34  
    35  type Auxv uintptr
    36  
    37  func nthauxv(i int) Auxv {
    38  	return auxvs[i]
    39  }