Skip to content

Commit bf2584b

Browse files
committed
fix(*): fix some clippy warnings
1 parent e372c85 commit bf2584b

3 files changed

Lines changed: 30 additions & 28 deletions

File tree

src/dynld.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,17 @@ pub fn dynamically_link(
6161
loaded_dylibs.push(lib_name);
6262
}
6363

64-
fixup_all_chained_fixups(
65-
vm.as_ptr() as *mut u8,
66-
PAGE_ZERO_SIZE,
67-
&parsed.fixups,
68-
&parsed.symbols,
69-
&loaded_dylibs,
70-
Some(dyld_shared_cache),
71-
false,
72-
)?;
64+
unsafe {
65+
fixup_all_chained_fixups(
66+
vm.as_ptr() as *mut u8,
67+
PAGE_ZERO_SIZE,
68+
&parsed.fixups,
69+
&parsed.symbols,
70+
&loaded_dylibs,
71+
Some(dyld_shared_cache),
72+
false,
73+
)?
74+
};
7375

7476
apply_segment_protections(vm, &parsed.segments)?;
7577
run_initializers(vm, &parsed.init_functions);

src/fixups.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'bytes> Image<'bytes> {
110110
next_load_command_offset += cmdsize as usize;
111111
}
112112

113-
return if contains_fixups_header {
113+
if contains_fixups_header {
114114
// a LC_DYLD_CHAINED_FIXUPS is a linkedit_data_command. We need to extract `dataoff` from
115115
// it. This will tell us where the `dyld_chained_fixups_header` is located at
116116
let linkedit_data_command { dataoff, .. } = self
@@ -126,7 +126,7 @@ impl<'bytes> Image<'bytes> {
126126
)))
127127
} else {
128128
Ok(None)
129-
};
129+
}
130130
}
131131

132132
/// Applies all fixups to the image
@@ -474,7 +474,7 @@ impl<'bytes> Image<'bytes> {
474474
}
475475
}
476476

477-
pub fn fixup_all_chained_fixups(
477+
pub unsafe fn fixup_all_chained_fixups(
478478
dst_ptr: *mut u8,
479479
page_zero_size: usize,
480480
fixups: &Vec<Fixup>,
@@ -522,7 +522,7 @@ pub fn fixup_all_chained_fixups(
522522
let symbol = symbols
523523
.iter()
524524
.find(|sym| sym.array_string_cmp(symbol_name))
525-
.ok_or_else(|| "could not find a matching symbol while fixing up a BIND_SPECIAL_DYLIB_WEAK_LOOKUP")?;
525+
.ok_or("could not find a matching symbol while fixing up a BIND_SPECIAL_DYLIB_WEAK_LOOKUP")?;
526526

527527
*dst_addr = (dst_ptr.add(symbol.impl_offset).addr()) as u64;
528528
},

src/main.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![no_std]
22
#![no_main]
3-
#![deny(unsafe_op_in_unsafe_fn)]
4-
//#![deny(clippy::undocumented_unsafe_blocks)]
53

64
use crate::{
75
allocator::{Allocator, VM},
@@ -133,19 +131,21 @@ fn rebase_self_and_extract_bind_fixups(self_header: *mut u8, self_size: usize) -
133131
if !fixups.is_empty() {
134132
// unwrap if this does not work, we might want to return
135133
// a proper error instead though
136-
fixup_all_chained_fixups(
137-
self_header,
138-
0,
139-
&fixups,
140-
&Vec::new(),
141-
&ArrayVec::new_array(),
142-
None,
143-
true,
144-
)
145-
.map_err(|_| {
146-
let _ = libc::write(STDERR_FILENO, b"self rebase error, exiting ...\n");
147-
exit_error()
148-
});
134+
unsafe {
135+
fixup_all_chained_fixups(
136+
self_header,
137+
0,
138+
&fixups,
139+
&Vec::new(),
140+
&ArrayVec::new_array(),
141+
None,
142+
true,
143+
)
144+
.map_err(|_| {
145+
let _ = libc::write(STDERR_FILENO, b"self rebase error, exiting ...\n");
146+
exit_error()
147+
})
148+
};
149149
};
150150
// we return the bind fixups, as we cannot handle them right now. We first need to load
151151
// the shared cache first

0 commit comments

Comments
 (0)