src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

auxv.go (1020B)


      1 // Copyright 2025 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 //go:build go1.21 && (aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos)
      6 
      7 package unix
      8 
      9 import (
     10 	"syscall"
     11 	"unsafe"
     12 )
     13 
     14 //go:linkname runtime_getAuxv runtime.getAuxv
     15 func runtime_getAuxv() []uintptr
     16 
     17 // Auxv returns the ELF auxiliary vector as a sequence of key/value pairs.
     18 // The returned slice is always a fresh copy, owned by the caller.
     19 // It returns an error on non-ELF platforms, or if the auxiliary vector cannot be accessed,
     20 // which happens in some locked-down environments and build modes.
     21 func Auxv() ([][2]uintptr, error) {
     22 	vec := runtime_getAuxv()
     23 	vecLen := len(vec)
     24 
     25 	if vecLen == 0 {
     26 		return nil, syscall.ENOENT
     27 	}
     28 
     29 	if vecLen%2 != 0 {
     30 		return nil, syscall.EINVAL
     31 	}
     32 
     33 	result := make([]uintptr, vecLen)
     34 	copy(result, vec)
     35 	return unsafe.Slice((*[2]uintptr)(unsafe.Pointer(&result[0])), vecLen/2), nil
     36 }