detached 05ec841

purego: add documentation for dlfcn functions (#17)

commit
05ec841cf131ee33d1ad4794807ddf2a53f253e3
author
TotallyGamerJet · · 2022-08-12 02:49 UTC
committer
GitHub · · 2022-08-12 02:49 UTC
parent
ab59a38
signature
GPG Unverified4AEE18F83AFDEB23 The key is unknown
1 file · +20 -0
M dlfcn.go +20 -0
@@ -18,6 +18,14 @@ const RTLD_GLOBAL = 0x8
1818
1919 const RTLD_DEFAULT = ^uintptr(1)
2020
21+// Dlopen examines the dynamic library or bundle file specified by path. If the file is compatible
22+// with the current process and has not already been loaded into the
23+// current process, it is loaded and linked. After being linked, if it contains
24+// any initializer functions, they are called, before Dlopen
25+// returns. It returns a handle that can be used with Dlsym and Dlclose.
26+// A second call to Dlopen with the same path will return the same handle, but the internal
27+// reference count for the handle will be incremented. Therefore, all
28+// Dlopen calls should be balanced with a Dlclose call.
2129 func Dlopen(path string, mode int) uintptr {
2230 bs := strings.CString(path)
2331 ret, _, _ := SyscallN(dlopenABI0, uintptr(unsafe.Pointer(bs)), uintptr(mode), 0)
@@ -25,6 +33,10 @@ func Dlopen(path string, mode int) uintptr {
2533 return ret
2634 }
2735
36+// Dlsym takes a "handle" of a dynamic library returned by Dlopen and the symbol name.
37+// It returns the address where that symbol is loaded into memory. If the symbol is not found,
38+// in the specified library or any of the libraries that were automatically loaded by Dlopen
39+// when that library was loaded, Dlsym returns zero.
2840 func Dlsym(handle uintptr, name string) uintptr {
2941 bs := strings.CString(name)
3042 ret, _, _ := SyscallN(dlsymABI0, handle, uintptr(unsafe.Pointer(bs)), 0)
@@ -32,6 +44,10 @@ func Dlsym(handle uintptr, name string) uintptr {
3244 return ret
3345 }
3446
47+// Dlerror returns a human-readable string describing the most recent error that
48+// occurred from Dlopen, Dlsym or Dlclose since the last call to Dlerror. It
49+// returns an empty string if no errors have occurred since initialization or
50+// since it was last called.
3551 func Dlerror() string {
3652 // msg is only valid until the next call to Dlerror
3753 // which is why it gets copied into a Go string
@@ -53,6 +69,10 @@ func Dlerror() string {
5369 return string(s)
5470 }
5571
72+// Dlclose decrements the reference count on the dynamic library handle.
73+// If the reference count drops to zero and no other loaded libraries
74+// use symbols in it, then the dynamic library is unloaded.
75+// Dlclose returns false on success, and true on error.
5676 func Dlclose(handle uintptr) bool {
5777 ret, _, _ := SyscallN(dlcloseABI0, handle)
5878 return ret != 0
@@ -18,6 +18,14 @@ const RTLD_GLOBAL = 0x8
18 18
19 const RTLD_DEFAULT = ^uintptr(1)19 const RTLD_DEFAULT = ^uintptr(1)
20 20
21+// Dlopen examines the dynamic library or bundle file specified by path. If the file is compatible
22+// with the current process and has not already been loaded into the
23+// current process, it is loaded and linked. After being linked, if it contains
24+// any initializer functions, they are called, before Dlopen
25+// returns. It returns a handle that can be used with Dlsym and Dlclose.
26+// A second call to Dlopen with the same path will return the same handle, but the internal
27+// reference count for the handle will be incremented. Therefore, all
28+// Dlopen calls should be balanced with a Dlclose call.
21 func Dlopen(path string, mode int) uintptr {29 func Dlopen(path string, mode int) uintptr {
22 bs := strings.CString(path)30 bs := strings.CString(path)
23 ret, _, _ := SyscallN(dlopenABI0, uintptr(unsafe.Pointer(bs)), uintptr(mode), 0)31 ret, _, _ := SyscallN(dlopenABI0, uintptr(unsafe.Pointer(bs)), uintptr(mode), 0)
@@ -25,6 +33,10 @@ func Dlopen(path string, mode int) uintptr {
25 return ret33 return ret
26 }34 }
27 35
36+// Dlsym takes a "handle" of a dynamic library returned by Dlopen and the symbol name.
37+// It returns the address where that symbol is loaded into memory. If the symbol is not found,
38+// in the specified library or any of the libraries that were automatically loaded by Dlopen
39+// when that library was loaded, Dlsym returns zero.
28 func Dlsym(handle uintptr, name string) uintptr {40 func Dlsym(handle uintptr, name string) uintptr {
29 bs := strings.CString(name)41 bs := strings.CString(name)
30 ret, _, _ := SyscallN(dlsymABI0, handle, uintptr(unsafe.Pointer(bs)), 0)42 ret, _, _ := SyscallN(dlsymABI0, handle, uintptr(unsafe.Pointer(bs)), 0)
@@ -32,6 +44,10 @@ func Dlsym(handle uintptr, name string) uintptr {
32 return ret44 return ret
33 }45 }
34 46
47+// Dlerror returns a human-readable string describing the most recent error that
48+// occurred from Dlopen, Dlsym or Dlclose since the last call to Dlerror. It
49+// returns an empty string if no errors have occurred since initialization or
50+// since it was last called.
35 func Dlerror() string {51 func Dlerror() string {
36 // msg is only valid until the next call to Dlerror52 // msg is only valid until the next call to Dlerror
37 // which is why it gets copied into a Go string53 // which is why it gets copied into a Go string
@@ -53,6 +69,10 @@ func Dlerror() string {
53 return string(s)69 return string(s)
54 }70 }
55 71
72+// Dlclose decrements the reference count on the dynamic library handle.
73+// If the reference count drops to zero and no other loaded libraries
74+// use symbols in it, then the dynamic library is unloaded.
75+// Dlclose returns false on success, and true on error.
56 func Dlclose(handle uintptr) bool {76 func Dlclose(handle uintptr) bool {
57 ret, _, _ := SyscallN(dlcloseABI0, handle)77 ret, _, _ := SyscallN(dlcloseABI0, handle)
58 return ret != 078 return ret != 0

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