Add dl_iterate_phdr for openbsd

This commit is contained in:
Lzu Tao 2020-10-23 20:20:05 +07:00
parent 6711eefc8c
commit 42dce281b2
1 changed files with 73 additions and 0 deletions

View File

@ -16,6 +16,36 @@ pub type pthread_rwlock_t = *mut ::c_void;
pub type pthread_rwlockattr_t = *mut ::c_void;
pub type caddr_t = *mut ::c_char;
// elf.h
pub type Elf32_Addr = u32;
pub type Elf32_Half = u16;
pub type Elf32_Lword = u64;
pub type Elf32_Off = u32;
pub type Elf32_Sword = i32;
pub type Elf32_Word = u32;
pub type Elf64_Addr = u64;
pub type Elf64_Half = u16;
pub type Elf64_Lword = u64;
pub type Elf64_Off = u64;
pub type Elf64_Sword = i32;
pub type Elf64_Sxword = i64;
pub type Elf64_Word = u32;
pub type Elf64_Xword = u64;
cfg_if! {
if #[cfg(target_pointer_width = "64")] {
type Elf_Addr = Elf64_Addr;
type Elf_Half = Elf64_Half;
type Elf_Phdr = Elf64_Phdr;
} else if #[cfg(target_pointer_width = "32")] {
type Elf_Addr = Elf32_Addr;
type Elf_Half = Elf32_Half;
type Elf_Phdr = Elf32_Phdr;
}
}
s! {
pub struct glob_t {
pub gl_pathc: ::size_t,
@ -321,6 +351,38 @@ s! {
__shm_ctimensec: c_long,
pub shm_internal: *mut ::c_void,
}
// elf.h
pub struct Elf32_Phdr {
pub p_type: Elf32_Word,
pub p_offset: Elf32_Off,
pub p_vaddr: Elf32_Addr,
pub p_paddr: Elf32_Addr,
pub p_filesz: Elf32_Word,
pub p_memsz: Elf32_Word,
pub p_flags: Elf32_Word,
pub p_align: Elf32_Word,
}
pub struct Elf64_Phdr {
pub p_type: Elf64_Word,
pub p_flags: Elf64_Word,
pub p_offset: Elf64_Off,
pub p_vaddr: Elf64_Addr,
pub p_paddr: Elf64_Addr,
pub p_filesz: Elf64_Xword,
pub p_memsz: Elf64_Xword,
pub p_align: Elf64_Xword,
}
// link.h
pub struct dl_phdr_info {
pub dlpi_addr: Elf_Addr,
pub dlpi_name: *const ::c_char,
pub dlpi_phdr: *const Elf_Phdr,
pub dlpi_phnum: Elf_Half,
}
}
impl siginfo_t {
@ -1482,6 +1544,17 @@ extern "C" {
needle: *const ::c_void,
needlelen: ::size_t,
) -> *mut ::c_void;
// #include <link.h>
pub fn dl_iterate_phdr(
callback: ::Option<
unsafe extern "C" fn(
info: *mut dl_phdr_info,
size: usize,
data: *mut ::c_void,
) -> ::c_int,
>,
data: *mut ::c_void,
) -> ::c_int;
}
cfg_if! {