mirror of
https://github.com/AmbiML/sparrow-kata-full.git
synced 2025-08-30 11:11:57 +00:00
Rename the cate and functions to better identify things as application-specific. Change-Id: Ie4c888f6b0c0b66c2d4cfb6e0fb3b5b1e0b82c48 GitOrigin-RevId: 5ea9e1204023f717bbb63dcc0cf0579c1359e2da
76 lines
2.5 KiB
Rust
76 lines
2.5 KiB
Rust
/*
|
|
* Copyright 2021, Google LLC
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
#![no_std]
|
|
#![no_main]
|
|
|
|
extern crate alloc;
|
|
extern crate libkata;
|
|
use alloc::format;
|
|
use alloc::string::String;
|
|
use kata_os_common::allocator;
|
|
use kata_os_common::logger::KataLogger;
|
|
use kata_os_common::sel4_sys;
|
|
use sdk_interface::*;
|
|
use SDKRuntimeError::*;
|
|
|
|
// Message output is sent through the kata-os-logger which calls logger_log
|
|
// to deliver data to the console. We use seL4_DebugPutChar to write to the
|
|
// console which only works if DEBUG_PRINTING is enabled in the kernel.
|
|
#[no_mangle]
|
|
#[allow(unused_variables)]
|
|
pub fn logger_log(_level: u8, msg: *const cstr_core::c_char) {
|
|
#[cfg(feature = "CONFIG_PRINTING")]
|
|
unsafe {
|
|
for c in cstr_core::CStr::from_ptr(msg).to_bytes() {
|
|
let _ = sel4_sys::seL4_DebugPutChar(*c);
|
|
}
|
|
let _ = sel4_sys::seL4_DebugPutChar(b'\n');
|
|
}
|
|
}
|
|
|
|
#[no_mangle]
|
|
// XXX need SDK specification of main, use hack for now
|
|
pub fn main(_a0: u32, _a1: u32, _a2: u32, _a3: u32) {
|
|
// Setup logger; (XXX maybe belongs in the SDKRuntime)
|
|
static KATA_LOGGER: KataLogger = KataLogger;
|
|
log::set_logger(&KATA_LOGGER).unwrap();
|
|
log::set_max_level(log::LevelFilter::Trace);
|
|
|
|
static mut HEAP: [u8; 4096] = [0; 4096];
|
|
unsafe {
|
|
allocator::ALLOCATOR.init(HEAP.as_mut_ptr() as _, HEAP.len());
|
|
}
|
|
|
|
const KEY: &str = "foo";
|
|
let mut keyval: KeyValueData = [0u8; KEY_VALUE_DATA_SIZE];
|
|
let _ = match sdk_read_key(KEY, &mut keyval) {
|
|
Err(SDKReadKeyFailed) => sdk_log("read(foo) failed as expected"),
|
|
Err(e) => sdk_log(&format!("read error {:?}", e)),
|
|
Ok(kv) => sdk_log(&format!("read returned {:?}", kv)),
|
|
};
|
|
keyval
|
|
.split_at_mut(3)
|
|
.0
|
|
.copy_from_slice(String::from("123").as_bytes());
|
|
let _ = match sdk_write_key(KEY, &keyval) {
|
|
Ok(_) => sdk_log("write ok"),
|
|
Err(e) => sdk_log(&format!("write error {:?}", e)),
|
|
};
|
|
let _ = match sdk_read_key(KEY, &mut keyval) {
|
|
Err(SDKReadKeyFailed) => sdk_log("read(foo) failed as expected"),
|
|
Err(e) => sdk_log(&format!("read failed: {:?}", e)),
|
|
Ok(kv) => sdk_log(&format!("read returned {:?}", kv)),
|
|
};
|
|
let _ = match sdk_delete_key(KEY) {
|
|
Ok(_) => sdk_log("delete ok"),
|
|
Err(e) => sdk_log(&format!("delete error {:?}", e)),
|
|
};
|
|
let _ = match sdk_delete_key(KEY) {
|
|
Ok(_) => sdk_log("delete ok (for missing key)"),
|
|
Err(e) => sdk_log(&format!("delete error {:?}", e)),
|
|
};
|
|
}
|