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