mirror of
https://github.com/AmbiML/sparrow-kata-full.git
synced 2025-09-10 09:48:48 +00:00
StorageManager: clippy findings
Change-Id: If4b16efb9c333f82631f9b1a13be3890d1560e39 GitOrigin-RevId: c4eba8d744f0cf29e0cac6ce697e49ee3e29a577
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
// Code here binds the camkes component to the rust code.
|
||||
#![no_std]
|
||||
#![allow(clippy::missing_safety_doc)]
|
||||
|
||||
extern crate alloc;
|
||||
use core::slice;
|
||||
@@ -15,7 +16,7 @@ use kata_storage_manager::KATA_STORAGE;
|
||||
use log::trace;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn pre_init() {
|
||||
pub unsafe extern "C" fn pre_init() {
|
||||
static KATA_LOGGER: KataLogger = KataLogger;
|
||||
log::set_logger(&KATA_LOGGER).unwrap();
|
||||
// NB: set to max; the LoggerInterface will filter
|
||||
@@ -23,7 +24,6 @@ pub extern "C" fn pre_init() {
|
||||
|
||||
// TODO(sleffler): temp until we integrate with seL4
|
||||
static mut HEAP_MEMORY: [u8; 8 * 1024] = [0; 8 * 1024];
|
||||
unsafe {
|
||||
allocator::ALLOCATOR.init(HEAP_MEMORY.as_mut_ptr() as usize, HEAP_MEMORY.len());
|
||||
trace!(
|
||||
"setup heap: start_addr {:p} size {}",
|
||||
@@ -31,15 +31,13 @@ pub extern "C" fn pre_init() {
|
||||
HEAP_MEMORY.len()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// StorageInterface glue stubs.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn storage_read(
|
||||
pub unsafe extern "C" fn storage_read(
|
||||
c_key: *const cstr_core::c_char,
|
||||
c_raw_value: *mut KeyValueData,
|
||||
) -> StorageManagerError {
|
||||
unsafe {
|
||||
match CStr::from_ptr(c_key).to_str() {
|
||||
Ok(key) => {
|
||||
// TODO(sleffler): de-badge reply cap to get bundle_id
|
||||
@@ -55,24 +53,21 @@ pub extern "C" fn storage_read(
|
||||
Err(_) => StorageManagerError::SmeKeyInvalid,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn storage_write(
|
||||
pub unsafe extern "C" fn storage_write(
|
||||
c_key: *const cstr_core::c_char,
|
||||
c_raw_value_len: usize,
|
||||
c_raw_value: *const u8,
|
||||
) -> StorageManagerError {
|
||||
match unsafe { CStr::from_ptr(c_key).to_str() } {
|
||||
match CStr::from_ptr(c_key).to_str() {
|
||||
Ok(key) => {
|
||||
// TODO(sleffler): de-badge reply cap to get bundle_id
|
||||
unsafe {
|
||||
KATA_STORAGE.write(
|
||||
"fubar",
|
||||
key,
|
||||
slice::from_raw_parts(c_raw_value, c_raw_value_len),
|
||||
)
|
||||
}
|
||||
.into()
|
||||
}
|
||||
Err(_) => StorageManagerError::SmeKeyInvalid,
|
||||
@@ -80,11 +75,13 @@ pub extern "C" fn storage_write(
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn storage_delete(c_key: *const cstr_core::c_char) -> StorageManagerError {
|
||||
match unsafe { CStr::from_ptr(c_key).to_str() } {
|
||||
pub unsafe extern "C" fn storage_delete(
|
||||
c_key: *const cstr_core::c_char
|
||||
) -> StorageManagerError {
|
||||
match CStr::from_ptr(c_key).to_str() {
|
||||
Ok(key) => {
|
||||
// TODO(sleffler): de-badge reply cap to get bundle_id
|
||||
unsafe { KATA_STORAGE.delete("fubar", key) }.into()
|
||||
KATA_STORAGE.delete("fubar", key).into()
|
||||
}
|
||||
Err(_) => StorageManagerError::SmeKeyInvalid,
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@
|
||||
|
||||
use core::str;
|
||||
use cstr_core::CString;
|
||||
use postcard;
|
||||
|
||||
// TODO(sleffler): temp constraint on value part of key-value pairs
|
||||
pub const KEY_VALUE_DATA_SIZE: usize = 100;
|
||||
@@ -77,8 +76,8 @@ impl From<StorageError> for StorageManagerError {
|
||||
impl From<Result<(), StorageError>> for StorageManagerError {
|
||||
fn from(result: Result<(), StorageError>) -> StorageManagerError {
|
||||
result.map_or_else(
|
||||
|e| StorageManagerError::from(e),
|
||||
|_v| StorageManagerError::SmeSuccess,
|
||||
StorageManagerError::from,
|
||||
|_| StorageManagerError::SmeSuccess,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user