1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-16 04:29:08 +00:00

fixup! WIP - extend trezorhal translations interface

This commit is contained in:
matejcik 2024-01-18 10:26:12 +01:00
parent 30aae199fa
commit 959d2f235c

View File

@ -1,8 +1,8 @@
use super::ffi; use super::ffi;
// SAFETY: Returned slice is valid and immutable until a call to `erase()` and/or `set_blob()`. // SAFETY: Returned slice is valid and immutable until a call to `erase()`
// Caller is responsible for disposing of all references to the slice before touching // and/or `set_blob()`. Caller is responsible for disposing of all references to
// the flash contents. // the slice before touching the flash contents.
pub unsafe fn get_blob<'a>() -> &'a [u8] { pub unsafe fn get_blob<'a>() -> &'a [u8] {
let mut len: u32 = 0; let mut len: u32 = 0;
let ptr = unsafe { ffi::translations_read(&mut len, 0) }; let ptr = unsafe { ffi::translations_read(&mut len, 0) };
@ -13,7 +13,8 @@ pub unsafe fn get_blob<'a>() -> &'a [u8] {
unsafe { core::slice::from_raw_parts(ptr, len as usize) } unsafe { core::slice::from_raw_parts(ptr, len as usize) }
} }
// SAFETY: This call invalidates the reference to the blob returned by `get_blob()`. // SAFETY: This call invalidates the reference to the blob returned by
// `get_blob()`.
pub unsafe fn erase() { pub unsafe fn erase() {
unsafe { ffi::translations_erase() }; unsafe { ffi::translations_erase() };
} }
@ -23,7 +24,8 @@ pub fn area_bytesize() -> usize {
unsafe { ffi::translations_area_bytesize() as usize } unsafe { ffi::translations_area_bytesize() as usize }
} }
// SAFETY: This call may invalidate the reference to the blob returned by `get_blob()`. // SAFETY: This call may invalidate the reference to the blob returned by
// `get_blob()`.
pub unsafe fn write(data: &[u8], offset: usize) { pub unsafe fn write(data: &[u8], offset: usize) {
unsafe { ffi::translations_write(data.as_ptr(), offset as u32, data.len() as u32) }; unsafe { ffi::translations_write(data.as_ptr(), offset as u32, data.len() as u32) };
} }