v0.10.0-alpha.2 73cecc9

dlfcn.go RawHistoryFolder

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
3
4//go:build (darwin || freebsd || linux || netbsd) && !android && !faketime
5
6package purego
7
8import (
9	"unsafe"
10)
11
12// Unix Specification for dlfcn.h: https://pubs.opengroup.org/onlinepubs/7908799/xsh/dlfcn.h.html
13
14var (
15	fnDlopen  func(path string, mode int) uintptr
16	fnDlsym   func(handle uintptr, name string) uintptr
17	fnDlerror func() string
18	fnDlclose func(handle uintptr) bool
19)
20
21func init() {
22	RegisterFunc(&fnDlopen, dlopenABI0)
23	RegisterFunc(&fnDlsym, dlsymABI0)
24	RegisterFunc(&fnDlerror, dlerrorABI0)
25	RegisterFunc(&fnDlclose, dlcloseABI0)
26}
27
28// Dlopen examines the dynamic library or bundle file specified by path. If the file is compatible
29// with the current process and has not already been loaded into the
30// current process, it is loaded and linked. After being linked, if it contains
31// any initializer functions, they are called, before Dlopen
32// returns. It returns a handle that can be used with Dlsym and Dlclose.
33// A second call to Dlopen with the same path will return the same handle, but the internal
34// reference count for the handle will be incremented. Therefore, all
35// Dlopen calls should be balanced with a Dlclose call.
36//
37// This function is not available on Windows.
38// Use [golang.org/x/sys/windows.LoadLibrary], [golang.org/x/sys/windows.LoadLibraryEx],
39// [golang.org/x/sys/windows.NewLazyDLL], or [golang.org/x/sys/windows.NewLazySystemDLL] for Windows instead.
40func Dlopen(path string, mode int) (uintptr, error) {
41	u := fnDlopen(path, mode)
42	if u == 0 {
43		return 0, Dlerror{fnDlerror()}
44	}
45	return u, nil
46}
47
48// Dlsym takes a "handle" of a dynamic library returned by Dlopen and the symbol name.
49// It returns the address where that symbol is loaded into memory. If the symbol is not found,
50// in the specified library or any of the libraries that were automatically loaded by Dlopen
51// when that library was loaded, Dlsym returns zero.
52//
53// This function is not available on Windows.
54// Use [golang.org/x/sys/windows.GetProcAddress] for Windows instead.
55func Dlsym(handle uintptr, name string) (uintptr, error) {
56	u := fnDlsym(handle, name)
57	if u == 0 {
58		return 0, Dlerror{fnDlerror()}
59	}
60	return u, nil
61}
62
63// Dlclose decrements the reference count on the dynamic library handle.
64// If the reference count drops to zero and no other loaded libraries
65// use symbols in it, then the dynamic library is unloaded.
66//
67// This function is not available on Windows.
68// Use [golang.org/x/sys/windows.FreeLibrary] for Windows instead.
69func Dlclose(handle uintptr) error {
70	if fnDlclose(handle) {
71		return Dlerror{fnDlerror()}
72	}
73	return nil
74}
75
76func loadSymbol(handle uintptr, name string) (uintptr, error) {
77	return Dlsym(handle, name)
78}
79
80// these functions exist in dlfcn_stubs.s and are calling C functions linked to in dlfcn_GOOS.go
81// the indirection is necessary because a function is actually a pointer to the pointer to the code.
82// sadly, I do not know of anyway to remove the assembly stubs entirely because //go:linkname doesn't
83// appear to work if you link directly to the C function on darwin arm64.
84
85//go:linkname dlopen dlopen
86var dlopen uint8
87var dlopenABI0 = uintptr(unsafe.Pointer(&dlopen))
88
89//go:linkname dlsym dlsym
90var dlsym uint8
91var dlsymABI0 = uintptr(unsafe.Pointer(&dlsym))
92
93//go:linkname dlclose dlclose
94var dlclose uint8
95var dlcloseABI0 = uintptr(unsafe.Pointer(&dlclose))
96
97//go:linkname dlerror dlerror
98var dlerror uint8
99var dlerrorABI0 = uintptr(unsafe.Pointer(&dlerror))

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close