#![allow(unsafe_code)]
use super::super::c;
use super::super::elf::*;
use super::super::process::exe_phdrs_slice;
use core::ptr::null;
#[cfg(target_arch = "x86")]
pub type UserDesc = linux_raw_sys::general::user_desc;
pub(crate) fn startup_tls_info() -> StartupTlsInfo {
let mut base = null();
let mut tls_phdr = null();
let mut stack_size = 0;
unsafe {
let phdrs = exe_phdrs_slice();
for phdr in phdrs {
match (*phdr).p_type {
PT_PHDR => {
base = phdrs
.as_ptr()
.cast::<u8>()
.offset(-((*phdr).p_vaddr as isize))
}
PT_TLS => tls_phdr = phdr,
PT_GNU_STACK => stack_size = (*phdr).p_memsz,
_ => {}
}
}
StartupTlsInfo {
addr: base.cast::<u8>().add((*tls_phdr).p_vaddr).cast(),
mem_size: (*tls_phdr).p_memsz,
file_size: (*tls_phdr).p_filesz,
align: (*tls_phdr).p_align,
stack_size,
}
}
}
pub struct StartupTlsInfo {
pub addr: *const c::c_void,
pub mem_size: usize,
pub file_size: usize,
pub align: usize,
pub stack_size: usize,
}