@@ -23,6 +23,17 @@ pub type __s16 = ::c_short;
23
23
pub type __u32 = :: c_uint ;
24
24
pub type __s32 = :: c_int ;
25
25
26
+ pub type Elf32_Half = u16 ;
27
+ pub type Elf32_Word = u32 ;
28
+ pub type Elf32_Off = u32 ;
29
+ pub type Elf32_Addr = u32 ;
30
+
31
+ pub type Elf64_Half = u16 ;
32
+ pub type Elf64_Word = u32 ;
33
+ pub type Elf64_Off = u64 ;
34
+ pub type Elf64_Addr = u64 ;
35
+ pub type Elf64_Xword = u64 ;
36
+
26
37
pub enum fpos64_t { } // TODO: fill this out with a struct
27
38
28
39
s ! {
@@ -391,6 +402,52 @@ s! {
391
402
#[ cfg( target_pointer_width = "32" ) ]
392
403
pub u: [ u32 ; 7 ] ,
393
404
}
405
+
406
+ pub struct dl_phdr_info {
407
+ #[ cfg( target_pointer_width = "64" ) ]
408
+ pub dlpi_addr: Elf64_Addr ,
409
+ #[ cfg( target_pointer_width = "32" ) ]
410
+ pub dlpi_addr: Elf32_Addr ,
411
+
412
+ pub dlpi_name: * const :: c_char,
413
+
414
+ #[ cfg( target_pointer_width = "64" ) ]
415
+ pub dlpi_phdr: * const Elf64_Phdr ,
416
+ #[ cfg( target_pointer_width = "32" ) ]
417
+ pub dlpi_phdr: * const Elf32_Phdr ,
418
+
419
+ #[ cfg( target_pointer_width = "64" ) ]
420
+ pub dlpi_phnum: Elf64_Half ,
421
+ #[ cfg( target_pointer_width = "32" ) ]
422
+ pub dlpi_phnum: Elf32_Half ,
423
+
424
+ pub dlpi_adds: :: c_ulonglong,
425
+ pub dlpi_subs: :: c_ulonglong,
426
+ pub dlpi_tls_modid: :: size_t,
427
+ pub dlpi_tls_data: * mut :: c_void,
428
+ }
429
+
430
+ pub struct Elf32_Phdr {
431
+ pub p_type: Elf32_Word ,
432
+ pub p_offset: Elf32_Off ,
433
+ pub p_vaddr: Elf32_Addr ,
434
+ pub p_paddr: Elf32_Addr ,
435
+ pub p_filesz: Elf32_Word ,
436
+ pub p_memsz: Elf32_Word ,
437
+ pub p_flags: Elf32_Word ,
438
+ pub p_align: Elf32_Word ,
439
+ }
440
+
441
+ pub struct Elf64_Phdr {
442
+ pub p_type: Elf64_Word ,
443
+ pub p_flags: Elf64_Word ,
444
+ pub p_offset: Elf64_Off ,
445
+ pub p_vaddr: Elf64_Addr ,
446
+ pub p_paddr: Elf64_Addr ,
447
+ pub p_filesz: Elf64_Xword ,
448
+ pub p_memsz: Elf64_Xword ,
449
+ pub p_align: Elf64_Xword ,
450
+ }
394
451
}
395
452
396
453
pub const ABDAY_1 : :: nl_item = 0x20000 ;
@@ -1031,6 +1088,23 @@ pub const CMSPAR: ::tcflag_t = 0o10000000000;
1031
1088
pub const MFD_CLOEXEC : :: c_uint = 0x0001 ;
1032
1089
pub const MFD_ALLOW_SEALING : :: c_uint = 0x0002 ;
1033
1090
1091
+ // these are used in the p_type field of Elf32_Phdr and Elf64_Phdr, which has
1092
+ // the type Elf32Word and Elf64Word respectively. Luckily, both of those are u32
1093
+ // so we can use that type here to avoid having to cast.
1094
+ pub const PT_NULL : u32 = 0 ;
1095
+ pub const PT_LOAD : u32 = 1 ;
1096
+ pub const PT_DYNAMIC : u32 = 2 ;
1097
+ pub const PT_INTERP : u32 = 3 ;
1098
+ pub const PT_NOTE : u32 = 4 ;
1099
+ pub const PT_SHLIB : u32 = 5 ;
1100
+ pub const PT_PHDR : u32 = 6 ;
1101
+ pub const PT_TLS : u32 = 7 ;
1102
+ pub const PT_NUM : u32 = 8 ;
1103
+ pub const PT_LOOS : u32 = 0x60000000 ;
1104
+ pub const PT_GNU_EH_FRAME : u32 = 0x6474e550 ;
1105
+ pub const PT_GNU_STACK : u32 = 0x6474e551 ;
1106
+ pub const PT_GNU_RELRO : u32 = 0x6474e552 ;
1107
+
1034
1108
f ! {
1035
1109
pub fn CPU_ZERO ( cpuset: & mut cpu_set_t) -> ( ) {
1036
1110
for slot in cpuset. bits. iter_mut( ) {
@@ -1488,6 +1562,14 @@ extern {
1488
1562
attr : * const :: pthread_attr_t ,
1489
1563
f : extern fn ( * mut :: c_void ) -> * mut :: c_void ,
1490
1564
value : * mut :: c_void ) -> :: c_int ;
1565
+ pub fn dl_iterate_phdr (
1566
+ callback : Option < unsafe extern fn (
1567
+ info : * mut :: dl_phdr_info ,
1568
+ size : :: size_t ,
1569
+ data : * mut :: c_void
1570
+ ) -> :: c_int > ,
1571
+ data : * mut :: c_void
1572
+ ) -> :: c_int ;
1491
1573
}
1492
1574
1493
1575
cfg_if ! {
0 commit comments