Skip to content

Commit accd94c

Browse files
committed
build: update unsafe blocks to new 2024 requirements
1 parent 2941655 commit accd94c

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

src/elf/dynamic.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -540,30 +540,30 @@ macro_rules! elf_dyn_std_impl {
540540
}
541541

542542
/// Given a bias and a memory address (typically for a _correctly_ mmap'd binary in memory), returns the `_DYNAMIC` array as a slice of that memory
543-
pub unsafe fn from_raw<'a>(bias: usize, vaddr: usize) -> &'a [Dyn] {
543+
pub unsafe fn from_raw<'a>(bias: usize, vaddr: usize) -> &'a [Dyn] { unsafe {
544544
let dynp = vaddr.wrapping_add(bias) as *const Dyn;
545545
let mut idx = 0;
546546
while u64::from((*dynp.offset(idx)).d_tag) != DT_NULL {
547547
idx += 1;
548548
}
549549
slice::from_raw_parts(dynp, idx as usize)
550-
}
550+
}}
551551

552552
// TODO: these bare functions have always seemed awkward, but not sure where they should go...
553553
/// Maybe gets and returns the dynamic array with the same lifetime as the `phdrs`, using the provided bias with wrapping addition.
554554
/// If the bias is wrong, it will either segfault or give you incorrect values, beware
555-
pub unsafe fn from_phdrs(bias: usize, phdrs: &[$phdr]) -> Option<&[Dyn]> {
555+
pub unsafe fn from_phdrs(bias: usize, phdrs: &[$phdr]) -> Option<&[Dyn]> { unsafe {
556556
for phdr in phdrs {
557557
// FIXME: change to casting to u64 similar to DT_*?
558558
if phdr.p_type as u32 == PT_DYNAMIC {
559559
return Some(from_raw(bias, phdr.p_vaddr as usize));
560560
}
561561
}
562562
None
563-
}
563+
}}
564564

565565
/// Gets the needed libraries from the `_DYNAMIC` array, with the str slices lifetime tied to the dynamic array/strtab's lifetime(s)
566-
pub unsafe fn get_needed<'a>(dyns: &[Dyn], strtab: *const Strtab<'a>, count: usize) -> Vec<&'a str> {
566+
pub unsafe fn get_needed<'a>(dyns: &[Dyn], strtab: *const Strtab<'a>, count: usize) -> Vec<&'a str> { unsafe {
567567
let mut needed = Vec::with_capacity(count.min(dyns.len()));
568568
for dynamic in dyns {
569569
if u64::from(dynamic.d_tag) == DT_NEEDED {
@@ -572,7 +572,7 @@ macro_rules! elf_dyn_std_impl {
572572
}
573573
}
574574
needed
575-
}
575+
}}
576576
}
577577
};
578578
}

src/elf/gnu_hash.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ macro_rules! elf_gnu_hash_impl {
9797
pub unsafe fn from_raw_table(
9898
hashtab: &'a [u8],
9999
dynsyms: &'a [Sym],
100-
) -> Result<Self, &'static str> {
100+
) -> Result<Self, &'static str> { unsafe {
101101
if hashtab.as_ptr() as usize % INT_SIZE != 0 {
102102
return Err("hashtab is not aligned with 64-bit");
103103
}
@@ -151,7 +151,7 @@ macro_rules! elf_gnu_hash_impl {
151151
chains,
152152
dynsyms,
153153
})
154-
}
154+
}}
155155

156156
/// Locate the hash chain, and corresponding hash value element.
157157
#[cold]

src/elf/program_header.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,9 @@ macro_rules! elf_program_header_std_impl {
341341
pub unsafe fn from_raw_parts<'a>(
342342
phdrp: *const ProgramHeader,
343343
phnum: usize,
344-
) -> &'a [ProgramHeader] {
344+
) -> &'a [ProgramHeader] { unsafe {
345345
slice::from_raw_parts(phdrp, phnum)
346-
}
346+
}}
347347

348348
#[cfg(feature = "std")]
349349
pub fn from_fd(fd: &mut File, offset: u64, count: usize) -> Result<Vec<ProgramHeader>> {

src/elf/reloc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,19 @@ macro_rules! elf_rela_std_impl {
188188
/// 1. `ptr` points to memory received from the kernel (i.e., it loaded the executable), _or_
189189
/// 2. The binary has already been mmapped (i.e., it's a `SharedObject`), and hence it's safe to return a slice of that memory.
190190
/// 3. Or if you obtained the pointer in some other lawful manner
191-
pub unsafe fn from_raw_rela<'a>(ptr: *const Rela, size: usize) -> &'a [Rela] {
191+
pub unsafe fn from_raw_rela<'a>(ptr: *const Rela, size: usize) -> &'a [Rela] { unsafe {
192192
slice::from_raw_parts(ptr, size / SIZEOF_RELA)
193-
}
193+
}}
194194

195195
/// Gets the rel entries given a rel pointer and the _size_ of the rel section in the binary,
196196
/// in bytes.
197197
/// Assumes the pointer is valid and can safely return a slice of memory pointing to the rels because:
198198
/// 1. `ptr` points to memory received from the kernel (i.e., it loaded the executable), _or_
199199
/// 2. The binary has already been mmapped (i.e., it's a `SharedObject`), and hence it's safe to return a slice of that memory.
200200
/// 3. Or if you obtained the pointer in some other lawful manner
201-
pub unsafe fn from_raw_rel<'a>(ptr: *const Rel, size: usize) -> &'a [Rel] {
201+
pub unsafe fn from_raw_rel<'a>(ptr: *const Rel, size: usize) -> &'a [Rel] { unsafe {
202202
slice::from_raw_parts(ptr, size / SIZEOF_REL)
203-
}
203+
}}
204204

205205
#[cfg(feature = "std")]
206206
pub fn from_fd(fd: &mut File, offset: usize, size: usize) -> Result<Vec<Rela>> {

src/elf/sym.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,9 @@ macro_rules! elf_sym_std_impl {
239239
///
240240
/// This function creates a `Sym` slice directly from a raw pointer
241241
#[inline]
242-
pub unsafe fn from_raw<'a>(symp: *const Sym, count: usize) -> &'a [Sym] {
242+
pub unsafe fn from_raw<'a>(symp: *const Sym, count: usize) -> &'a [Sym] { unsafe {
243243
slice::from_raw_parts(symp, count)
244-
}
244+
}}
245245

246246
if_std! {
247247
use crate::error::Result;

src/strtab.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ impl<'a> Strtab<'a> {
154154
///
155155
/// # Safety
156156
/// This function creates a `Strtab` directly from a raw pointer and size
157-
pub unsafe fn from_raw(ptr: *const u8, len: usize, delim: u8) -> Strtab<'a> {
157+
pub unsafe fn from_raw(ptr: *const u8, len: usize, delim: u8) -> Strtab<'a> { unsafe {
158158
Self::from_slice_unparsed(core::slice::from_raw_parts(ptr, len), 0, len, delim)
159-
}
159+
}}
160160
#[deprecated(since = "0.4.2", note = "Bad performance, use get_at() instead")]
161161
#[cfg(feature = "alloc")]
162162
/// Parses a str reference from the parsed table starting at byte `offset`.

0 commit comments

Comments
 (0)