Merge branch 'refactor/fix-compiler-warnings' into 'master'
lib: fix compiler warnings See merge request redox-os/relibc!704
This commit is contained in:
@@ -9,7 +9,7 @@ fn get_target() -> String {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
|
||||
let _crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
|
||||
let target = get_target();
|
||||
|
||||
println!("cargo:rerun-if-changed=src/c");
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#![no_std]
|
||||
#![feature(core_intrinsics)]
|
||||
|
||||
use core::{
|
||||
arch::asm,
|
||||
@@ -92,10 +91,8 @@ impl<Os> GenericTcb<Os> {
|
||||
Some(&mut *Self::current_ptr()?)
|
||||
}
|
||||
}
|
||||
pub fn panic_notls(_msg: impl core::fmt::Display) -> ! {
|
||||
//eprintln!("panicked in ld.so: {}", msg);
|
||||
|
||||
core::intrinsics::abort();
|
||||
pub fn panic_notls(msg: impl core::fmt::Display) -> ! {
|
||||
panic!("panicked in ld.so: {msg}");
|
||||
}
|
||||
|
||||
pub trait ExpectTlsFree {
|
||||
@@ -110,8 +107,7 @@ impl<T, E: core::fmt::Debug> ExpectTlsFree for Result<T, E> {
|
||||
match self {
|
||||
Ok(t) => t,
|
||||
Err(err) => panic_notls(format_args!(
|
||||
"{}: expect failed for Result with err: {:?}",
|
||||
msg, err
|
||||
"{msg}: expect failed for Result with err: {err:?}",
|
||||
)),
|
||||
}
|
||||
}
|
||||
@@ -122,7 +118,7 @@ impl<T> ExpectTlsFree for Option<T> {
|
||||
fn expect_notls(self, msg: &str) -> T {
|
||||
match self {
|
||||
Some(t) => t,
|
||||
None => panic_notls(format_args!("{}: expect failed for Option", msg)),
|
||||
None => panic_notls(format_args!("{msg}: expect failed for Option")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
name = "ld_so"
|
||||
version = "0.1.0"
|
||||
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "ld_so"
|
||||
|
||||
+10
-17
@@ -1,16 +1,9 @@
|
||||
#![no_std]
|
||||
#![feature(
|
||||
asm_const,
|
||||
core_intrinsics,
|
||||
int_roundings,
|
||||
let_chains,
|
||||
slice_ptr_get,
|
||||
sync_unsafe_cell
|
||||
)]
|
||||
#![feature(int_roundings, let_chains, slice_ptr_get, sync_unsafe_cell)]
|
||||
#![forbid(unreachable_patterns)]
|
||||
|
||||
use core::{
|
||||
cell::{SyncUnsafeCell, UnsafeCell},
|
||||
cell::UnsafeCell,
|
||||
mem::{size_of, MaybeUninit},
|
||||
};
|
||||
|
||||
@@ -232,14 +225,14 @@ pub(crate) struct StaticProcInfo {
|
||||
proc_fd: MaybeUninit<FdGuard>,
|
||||
has_proc_fd: bool,
|
||||
}
|
||||
struct DynamicProcInfo {
|
||||
pgid: u32,
|
||||
euid: u32,
|
||||
suid: u32,
|
||||
ruid: u32,
|
||||
egid: u32,
|
||||
rgid: u32,
|
||||
sgid: u32,
|
||||
pub struct DynamicProcInfo {
|
||||
pub pgid: u32,
|
||||
pub euid: u32,
|
||||
pub suid: u32,
|
||||
pub ruid: u32,
|
||||
pub egid: u32,
|
||||
pub rgid: u32,
|
||||
pub sgid: u32,
|
||||
}
|
||||
|
||||
static DYNAMIC_PROC_INFO: Mutex<DynamicProcInfo> = Mutex::new(DynamicProcInfo {
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{
|
||||
arch::*,
|
||||
auxv_defs::*,
|
||||
protocol::{ProcCall, ThreadCall},
|
||||
read_proc_meta, static_proc_info,
|
||||
read_proc_meta,
|
||||
sys::{proc_call, thread_call},
|
||||
RtTcb, StaticProcInfo, DYNAMIC_PROC_INFO,
|
||||
};
|
||||
@@ -30,8 +30,8 @@ use goblin::elf64::{
|
||||
use syscall::{
|
||||
error::*,
|
||||
flag::{MapFlags, SEEK_SET},
|
||||
CallFlags, GrantDesc, GrantFlags, Map, ProcSchemeAttrs, SetSighandlerData, MAP_FIXED_NOREPLACE,
|
||||
MAP_SHARED, O_CLOEXEC, PAGE_SIZE, PROT_EXEC, PROT_READ, PROT_WRITE,
|
||||
CallFlags, GrantDesc, GrantFlags, Map, SetSighandlerData, MAP_FIXED_NOREPLACE, MAP_SHARED,
|
||||
PAGE_SIZE, PROT_EXEC, PROT_READ, PROT_WRITE,
|
||||
};
|
||||
|
||||
pub enum FexecResult {
|
||||
@@ -902,7 +902,7 @@ pub fn fork_inner(initial_rsp: *mut usize, args: &ForkArgs) -> Result<usize> {
|
||||
Ok(new_pid)
|
||||
}
|
||||
|
||||
struct NewChildProc {
|
||||
pub struct NewChildProc {
|
||||
proc_fd: Option<FdGuard>,
|
||||
|
||||
thr_fd: FdGuard,
|
||||
|
||||
@@ -152,7 +152,8 @@ unsafe fn inner(stack: &mut SigStack) {
|
||||
flags: SigactionFlags::empty(),
|
||||
}),
|
||||
None,
|
||||
);
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
action
|
||||
};
|
||||
@@ -171,7 +172,7 @@ unsafe fn inner(stack: &mut SigStack) {
|
||||
CallFlags::empty(),
|
||||
&[ProcCall::Exit as u64, u64::from(sig) << 8],
|
||||
);
|
||||
core::intrinsics::abort()
|
||||
panic!()
|
||||
}
|
||||
SigactionKind::Handled { handler } => handler,
|
||||
};
|
||||
@@ -546,7 +547,7 @@ bitflags::bitflags! {
|
||||
|
||||
const STORED_FLAGS: u32 = 0xfe00_0000;
|
||||
|
||||
fn default_handler(sig: c_int) {
|
||||
fn default_handler(_sig: c_int) {
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
@@ -569,10 +570,6 @@ pub(crate) static PROC_CONTROL_STRUCT: SigProcControl = SigProcControl {
|
||||
sender_infos: [const { AtomicU64::new(0) }; 32],
|
||||
};
|
||||
|
||||
fn combine_allowset([lo, hi]: [u64; 2]) -> u64 {
|
||||
(lo >> 32) | ((hi >> 32) << 32)
|
||||
}
|
||||
|
||||
const fn sig_bit(sig: u32) -> u64 {
|
||||
//assert_ne!(sig, 32);
|
||||
//assert_ne!(sig, 0);
|
||||
@@ -631,7 +628,7 @@ pub fn setup_sighandler(tcb: &RtTcb, first_thread: bool) {
|
||||
.expect("failed to sync signal tctl");
|
||||
|
||||
// TODO: Inherited set of ignored signals
|
||||
set_sigmask(Some(0), None);
|
||||
set_sigmask(Some(0), None).ok();
|
||||
}
|
||||
pub type RtSigarea = RtTcb; // TODO
|
||||
pub fn current_setsighandler_struct() -> SetSighandlerData {
|
||||
|
||||
+16
-6
@@ -11,14 +11,17 @@ pub struct Mutex<T> {
|
||||
pub inner: UnsafeCell<T>,
|
||||
}
|
||||
|
||||
const UNLOCKED: u32 = 0;
|
||||
const LOCKED: u32 = 1;
|
||||
const WAITING: u32 = 2;
|
||||
|
||||
unsafe impl<T: Send> Send for Mutex<T> {}
|
||||
unsafe impl<T: Send> Sync for Mutex<T> {}
|
||||
|
||||
impl<T> Mutex<T> {
|
||||
/// Represents an unlocked [Mutex].
|
||||
pub const UNLOCKED: u32 = 0;
|
||||
/// Represents a locked [Mutex].
|
||||
pub const LOCKED: u32 = 1;
|
||||
/// Represents a waiting [Mutex].
|
||||
pub const WAITING: u32 = 2;
|
||||
|
||||
pub const fn new(t: T) -> Self {
|
||||
Self {
|
||||
lockword: AtomicU32::new(0),
|
||||
@@ -28,7 +31,12 @@ impl<T> Mutex<T> {
|
||||
pub fn lock(&self) -> MutexGuard<'_, T> {
|
||||
while self
|
||||
.lockword
|
||||
.compare_exchange(UNLOCKED, LOCKED, Ordering::Acquire, Ordering::Relaxed)
|
||||
.compare_exchange(
|
||||
Self::UNLOCKED,
|
||||
Self::LOCKED,
|
||||
Ordering::Acquire,
|
||||
Ordering::Relaxed,
|
||||
)
|
||||
.is_err()
|
||||
{
|
||||
core::hint::spin_loop();
|
||||
@@ -53,6 +61,8 @@ impl<T> DerefMut for MutexGuard<'_, T> {
|
||||
}
|
||||
impl<T> Drop for MutexGuard<'_, T> {
|
||||
fn drop(&mut self) {
|
||||
self.lock.lockword.store(UNLOCKED, Ordering::Release);
|
||||
self.lock
|
||||
.lockword
|
||||
.store(Mutex::<T>::UNLOCKED, Ordering::Release);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -324,7 +324,7 @@ pub fn posix_exit(status: i32) -> ! {
|
||||
)
|
||||
.expect("failed to call proc mgr with Exit");
|
||||
let _ = syscall::write(1, b"redox-rt: ProcCall::Exit FAILED, abort()ing!\n");
|
||||
core::intrinsics::abort();
|
||||
panic!();
|
||||
}
|
||||
pub fn setrens(rns: usize, ens: usize) -> Result<()> {
|
||||
this_proc_call(
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
name = "crt0"
|
||||
version = "0.1.0"
|
||||
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "crt0"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
name = "crti"
|
||||
version = "0.1.0"
|
||||
authors = ["jD91mZM2 <me@krake.one>"]
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "crti"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
name = "crtn"
|
||||
version = "0.1.0"
|
||||
authors = ["jD91mZM2 <me@krake.one>"]
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "crtn"
|
||||
|
||||
+1
-5
@@ -1,5 +1,3 @@
|
||||
#[cfg(target_os = "redox")]
|
||||
use crate::header::unistd::{F_OK, R_OK, W_OK, X_OK};
|
||||
use crate::{
|
||||
c_str::{CStr, CString},
|
||||
error::Errno,
|
||||
@@ -7,8 +5,6 @@ use crate::{
|
||||
};
|
||||
|
||||
pub fn accessible(path: &str, mode: c_int) -> Result<(), Errno> {
|
||||
let path_c = CString::new(path.as_bytes()).unwrap(); /*.map_err(|err| {
|
||||
Error::Malformed(format!("invalid path '{}': {}", path, err))
|
||||
})?;*/
|
||||
let path_c = CString::new(path.as_bytes()).unwrap();
|
||||
unsafe { Sys::access(CStr::from_ptr(path_c.as_ptr()), mode) }
|
||||
}
|
||||
|
||||
+10
-1
@@ -63,6 +63,15 @@ impl RTLDDebug {
|
||||
}
|
||||
}
|
||||
|
||||
/// SAFETY: safe as long as caller wraps the instance in a mutex,
|
||||
/// or similar structure that guarantees exclusive mutable access.
|
||||
/// Separate instances must not contain pointers to the same LinkMap instance.
|
||||
unsafe impl Send for RTLDDebug {}
|
||||
/// SAFETY: safe as long as caller wraps the instance in a mutex,
|
||||
/// or similar structure that guarantees exclusive mutable access.
|
||||
/// Separate instances must not contain pointers to the same LinkMap instance.
|
||||
unsafe impl Sync for RTLDDebug {}
|
||||
|
||||
#[repr(C)]
|
||||
struct LinkMap {
|
||||
/* These members are part of the protocol with the debugger.
|
||||
@@ -126,4 +135,4 @@ impl LinkMap {
|
||||
pub extern "C" fn _dl_debug_state() {}
|
||||
|
||||
#[no_mangle]
|
||||
pub static mut _r_debug: RTLDDebug = RTLDDebug::NEW;
|
||||
pub static _r_debug: spin::Mutex<RTLDDebug> = spin::Mutex::new(RTLDDebug::NEW);
|
||||
|
||||
+7
-3
@@ -505,7 +505,9 @@ impl DSO {
|
||||
} else {
|
||||
bounds.1 - bounds.0
|
||||
};
|
||||
_r_debug.insert_first(addr, path, addr + l_ld as usize);
|
||||
_r_debug
|
||||
.lock()
|
||||
.insert_first(addr, path, addr + l_ld as usize);
|
||||
slice::from_raw_parts_mut(addr as *mut u8, size)
|
||||
} else {
|
||||
let (start, end) = bounds;
|
||||
@@ -535,7 +537,9 @@ impl DSO {
|
||||
}
|
||||
trace!(" = {:p}", ptr);
|
||||
ptr::write_bytes(ptr as *mut u8, 0, size);
|
||||
_r_debug.insert(ptr as usize, path, ptr as usize + l_ld as usize);
|
||||
_r_debug
|
||||
.lock()
|
||||
.insert(ptr as usize, path, ptr as usize + l_ld as usize);
|
||||
slice::from_raw_parts_mut(ptr as *mut u8, size)
|
||||
}
|
||||
};
|
||||
@@ -618,7 +622,7 @@ impl DSO {
|
||||
let (ph, _) = dynamic.unwrap();
|
||||
let vaddr = ph.p_vaddr(endian) as usize;
|
||||
let bytes: [u8; size_of::<Dyn>() / 2] =
|
||||
unsafe { core::mem::transmute((&_r_debug) as *const RTLDDebug as usize) };
|
||||
((&raw const _r_debug).cast::<*const RTLDDebug>() as usize).to_ne_bytes();
|
||||
let start = if is_pie_enabled(elf) {
|
||||
vaddr + i * size_of::<Dyn>() + size_of::<Dyn>() / 2
|
||||
} else {
|
||||
|
||||
+2
-2
@@ -593,7 +593,7 @@ impl Linker {
|
||||
Resolve::Now
|
||||
};
|
||||
|
||||
unsafe { _r_debug.state = RTLDState::RT_ADD };
|
||||
_r_debug.lock().state = RTLDState::RT_ADD;
|
||||
_dl_debug_state();
|
||||
|
||||
let mut new_objects = Vec::new();
|
||||
@@ -724,7 +724,7 @@ impl Linker {
|
||||
self.register_object(obj);
|
||||
}
|
||||
|
||||
unsafe { _r_debug.state = RTLDState::RT_CONSISTENT };
|
||||
_r_debug.lock().state = RTLDState::RT_CONSISTENT;
|
||||
_dl_debug_state();
|
||||
|
||||
Ok(loaded_dso)
|
||||
|
||||
+1
-3
@@ -208,9 +208,7 @@ pub unsafe extern "C" fn relibc_ld_so_start(sp: &'static mut Stack, ld_entry: us
|
||||
};
|
||||
|
||||
// we might need global lock for this kind of stuff
|
||||
unsafe {
|
||||
_r_debug.r_ldbase = ld_entry;
|
||||
}
|
||||
_r_debug.lock().r_ldbase = ld_entry;
|
||||
|
||||
// TODO: Fix memory leak, although minimal.
|
||||
unsafe {
|
||||
|
||||
Reference in New Issue
Block a user