Skip to content

Commit c64b16c

Browse files
Merge tock#128
128: Remove unstable offset_from feature r=torfmaster a=torfmaster # Summary In this PR I remove the unstable `offset_from` feature which is used to calculate the number of bytes of a slice of bytes in a given range of addresses (the flash region). Clearly, the feature provides a safe and concise way of computing this. However, I find that using a minimal number of unstable/experimental features here has a higher value. Co-authored-by: torfmaster <[email protected]>
2 parents a8af2c3 + 3ac708c commit c64b16c

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(asm, alloc_error_handler, lang_items, naked_functions, ptr_offset_from)]
1+
#![feature(asm, alloc_error_handler, lang_items, naked_functions)]
22
#![cfg_attr(any(target_arch = "arm", target_arch = "riscv32"), no_std)]
33

44
mod callback;

src/memop.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ pub fn get_flash_region_end(i: usize) -> Option<*const u8> {
7171
/// flash regions during the application's lifetime.
7272
pub fn get_flash_region(i: usize) -> Option<&'static [u8]> {
7373
if i < get_flash_regions_count() {
74-
let start = unsafe { syscalls::raw::memop(8, i) as *const u8 };
75-
let end = unsafe { syscalls::raw::memop(9, i) as *const u8 };
74+
let start_addr = unsafe { syscalls::raw::memop(8, i) } as usize;
75+
let start_ptr = start_addr as *const u8;
76+
let end_addr = unsafe { syscalls::raw::memop(9, i) } as usize;
7677
// This assumes that the kernel sends consistent results, i.e. start <= end.
77-
let len = unsafe { end.offset_from(start) } as usize;
78-
Some(unsafe { slice::from_raw_parts(start, len) })
78+
let len = end_addr - start_addr;
79+
Some(unsafe { slice::from_raw_parts(start_ptr, len) })
7980
} else {
8081
None
8182
}

0 commit comments

Comments
 (0)