Skip to content

Commit 970fec9

Browse files
committed
Add dl_iterate_phdr to Android
1 parent 4d0cd9a commit 970fec9

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

libc-test/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,11 +1384,13 @@ fn test_android(target: &str) {
13841384
"ctype.h",
13851385
"dirent.h",
13861386
"dlfcn.h",
1387+
"elf.h",
13871388
"errno.h",
13881389
"fcntl.h",
13891390
"grp.h",
13901391
"ifaddrs.h",
13911392
"limits.h",
1393+
"link.h",
13921394
"locale.h",
13931395
"malloc.h",
13941396
"net/ethernet.h",
@@ -1507,7 +1509,7 @@ fn test_android(target: &str) {
15071509
cfg.type_name(move |ty, is_struct, is_union| {
15081510
match ty {
15091511
// Just pass all these through, no need for a "struct" prefix
1510-
"FILE" | "fd_set" | "Dl_info" => ty.to_string(),
1512+
"FILE" | "fd_set" | "Dl_info" | "Elf32_Phdr" | "Elf64_Phdr" => ty.to_string(),
15111513

15121514
t if is_union => format!("union {}", t),
15131515

src/unix/linux_like/android/mod.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,36 @@ pub type loff_t = ::c_longlong;
2626
pub type __kernel_loff_t = ::c_longlong;
2727
pub type __kernel_pid_t = ::c_int;
2828

29+
// elf.h
30+
31+
pub type Elf32_Addr = u32;
32+
pub type Elf32_Half = u16;
33+
pub type Elf32_Lword = u64;
34+
pub type Elf32_Off = u32;
35+
pub type Elf32_Sword = i32;
36+
pub type Elf32_Word = u32;
37+
38+
pub type Elf64_Addr = u64;
39+
pub type Elf64_Half = u16;
40+
pub type Elf64_Lword = u64;
41+
pub type Elf64_Off = u64;
42+
pub type Elf64_Sword = i32;
43+
pub type Elf64_Sxword = i64;
44+
pub type Elf64_Word = u32;
45+
pub type Elf64_Xword = u64;
46+
47+
cfg_if! {
48+
if #[cfg(target_pointer_width = "64")] {
49+
type Elf_Addr = Elf64_Addr;
50+
type Elf_Half = Elf64_Half;
51+
type Elf_Phdr = Elf64_Phdr;
52+
} else if #[cfg(target_pointer_width = "32")] {
53+
type Elf_Addr = Elf32_Addr;
54+
type Elf_Half = Elf32_Half;
55+
type Elf_Phdr = Elf32_Phdr;
56+
}
57+
}
58+
2959
s! {
3060
pub struct stack_t {
3161
pub ss_sp: *mut ::c_void,
@@ -244,6 +274,43 @@ s! {
244274
pub svm_cid: ::c_uint,
245275
pub svm_zero: [u8; 4]
246276
}
277+
278+
// elf.h
279+
280+
pub struct Elf32_Phdr {
281+
pub p_type: Elf32_Word,
282+
pub p_offset: Elf32_Off,
283+
pub p_vaddr: Elf32_Addr,
284+
pub p_paddr: Elf32_Addr,
285+
pub p_filesz: Elf32_Word,
286+
pub p_memsz: Elf32_Word,
287+
pub p_flags: Elf32_Word,
288+
pub p_align: Elf32_Word,
289+
}
290+
291+
pub struct Elf64_Phdr {
292+
pub p_type: Elf64_Word,
293+
pub p_flags: Elf64_Word,
294+
pub p_offset: Elf64_Off,
295+
pub p_vaddr: Elf64_Addr,
296+
pub p_paddr: Elf64_Addr,
297+
pub p_filesz: Elf64_Xword,
298+
pub p_memsz: Elf64_Xword,
299+
pub p_align: Elf64_Xword,
300+
}
301+
302+
// link.h
303+
304+
pub struct dl_phdr_info {
305+
pub dlpi_addr: Elf_Addr,
306+
pub dlpi_name: *const ::c_char,
307+
pub dlpi_phdr: *const Elf_Phdr,
308+
pub dlpi_phnum: Elf_Half,
309+
pub dlpi_adds: ::c_ulonglong,
310+
pub dlpi_subs: ::c_ulonglong,
311+
pub dlpi_tls_modid: usize,
312+
pub dlpi_tls_data: *mut ::c_void,
313+
}
247314
}
248315

249316
s_no_extra_traits! {
@@ -2715,6 +2782,19 @@ extern "C" {
27152782

27162783
pub fn __system_property_set(__name: *const ::c_char, __value: *const ::c_char) -> ::c_int;
27172784
pub fn __system_property_get(__name: *const ::c_char, __value: *mut ::c_char) -> ::c_int;
2785+
2786+
// #include <link.h>
2787+
/// Only available in API Version 21+
2788+
pub fn dl_iterate_phdr(
2789+
callback: ::Option<
2790+
unsafe extern "C" fn(
2791+
info: *mut dl_phdr_info,
2792+
size: usize,
2793+
data: *mut ::c_void,
2794+
) -> ::c_int,
2795+
>,
2796+
data: *mut ::c_void,
2797+
) -> ::c_int;
27182798
}
27192799

27202800
cfg_if! {

0 commit comments

Comments
 (0)