Skip to main content

relibc/ld_so/
callbacks.rs

1use super::linker::{Linker, ObjectHandle, Resolve, Result, ScopeKind};
2use crate::platform::types::c_void;
3use alloc::boxed::Box;
4
5pub struct LinkerCallbacks {
6    pub unload: Box<dyn Fn(&mut Linker, ObjectHandle)>,
7    pub load_library:
8        Box<dyn Fn(&mut Linker, Option<&str>, Resolve, ScopeKind, bool) -> Result<ObjectHandle>>,
9    pub get_sym: Box<dyn Fn(&Linker, Option<ObjectHandle>, &str) -> Option<*mut c_void>>,
10}
11
12impl LinkerCallbacks {
13    #[allow(clippy::new_without_default)]
14    pub fn new() -> LinkerCallbacks {
15        LinkerCallbacks {
16            unload: Box::new(unload),
17            load_library: Box::new(load_library),
18            get_sym: Box::new(get_sym),
19        }
20    }
21}
22
23fn unload(linker: &mut Linker, handle: ObjectHandle) {
24    linker.unload(handle)
25}
26
27fn load_library(
28    linker: &mut Linker,
29    name: Option<&str>,
30    resolve: Resolve,
31    scope: ScopeKind,
32    noload: bool,
33) -> Result<ObjectHandle> {
34    linker.load_library(name, resolve, scope, noload)
35}
36
37fn get_sym(linker: &Linker, handle: Option<ObjectHandle>, name: &str) -> Option<*mut c_void> {
38    linker.get_sym(handle, name)
39}