github.com/ebiten/purego@v0.0.0-20220525025155-0f6873f42222/dl_darwin.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // SPDX-FileCopyrightText: 2022 The Ebiten Authors
     3  
     4  package purego
     5  
     6  import (
     7  	"runtime"
     8  	"strings"
     9  	"unsafe"
    10  )
    11  
    12  const RTLD_GLOBAL = 0x8
    13  
    14  const RTLD_DEFAULT = ^uintptr(1)
    15  
    16  func cString(name string) *byte {
    17  	if strings.HasSuffix(name, "\x00") {
    18  		return &[]byte(name)[0]
    19  	}
    20  	var b = make([]byte, len(name)+1)
    21  	copy(b, name)
    22  	return &b[0]
    23  }
    24  
    25  func Dlopen(name string, mode int) uintptr {
    26  	bs := cString(name)
    27  	ret, _, _ := SyscallN(dlopenABI0, uintptr(unsafe.Pointer(bs)), uintptr(mode), 0)
    28  	runtime.KeepAlive(bs)
    29  	return ret
    30  }
    31  
    32  func Dlsym(handle uintptr, name string) uintptr {
    33  	bs := cString(name)
    34  	ret, _, _ := SyscallN(dlsymABI0, handle, uintptr(unsafe.Pointer(bs)), 0)
    35  	runtime.KeepAlive(bs)
    36  	return ret
    37  }
    38  
    39  //go:cgo_import_dynamic _dlopen dlopen "/usr/lib/libSystem.B.dylib"
    40  //go:cgo_import_dynamic _dlsym dlsym "/usr/lib/libSystem.B.dylib"
    41  
    42  var dlopenABI0 uintptr
    43  
    44  func dlopen() // implemented in assembly
    45  
    46  var dlsymABI0 uintptr
    47  
    48  func dlsym() // implemented in assembly