apps/rust: add panic test app to test panic!

Change-Id: I4615cdc48996c2d8739a00a4c585d09faf03b63b
GitOrigin-RevId: 9a0041d37df0d9526e29171f4c17d339579a44ef
This commit is contained in:
Sam Leffler 2022-09-19 18:12:20 +00:00
parent 95f8965986
commit fae20dcd68
5 changed files with 129 additions and 0 deletions

View File

@ -19,6 +19,7 @@ members = [
"hello",
"fibonacci",
"panic",
]
resolver = "2"

View File

@ -0,0 +1,39 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
[package]
name = "panic_app"
version = "0.1.0"
edition = "2021"
build = "build.rs"
[build-dependencies]
# build.rs depends on SEL4_OUT_DIR = "${ROOTDIR}/out/kata/kernel"
sel4-config = { path = "../../system/components/kata-os-common/src/sel4-config" }
[features]
default = []
# Used by sel4-config to extract kernel config
CONFIG_PRINTING = []
[lib]
name = "panic"
path = "panic.rs"
crate-type = ["staticlib"]
[dependencies]
cstr_core = { version = "0.2.3", default-features = false }
kata-os-common = { path = "../../system/components/kata-os-common", default-features = false }
libkata = { path = "../libkata" }
log = "0.4"

18
apps/rust/panic/Makefile Normal file
View File

@ -0,0 +1,18 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
APPNAME := panic
LIBKATA ?= ../libkata
include ${LIBKATA}/make/app.mk

34
apps/rust/panic/build.rs Normal file
View File

@ -0,0 +1,34 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
extern crate sel4_config;
use std::env;
fn main() {
// If SEL4_OUT_DIR is not set we expect the kernel build at a fixed
// location relative to the ROOTDIR env variable.
println!("SEL4_OUT_DIR {:?}", env::var("SEL4_OUT_DIR"));
let sel4_out_dir = env::var("SEL4_OUT_DIR")
.unwrap_or_else(|_| format!("{}/out/kata/kernel", env::var("ROOTDIR").unwrap()));
println!("sel4_out_dir {}", sel4_out_dir);
// Dredge seL4 kernel config for settings we need as features to generate
// correct code: e.g. CONFIG_KERNEL_MCS enables MCS support which changes
// the system call numbering.
let features = sel4_config::get_sel4_features(&sel4_out_dir);
println!("features={:?}", features);
for feature in features {
println!("cargo:rustc-cfg=feature=\"{}\"", feature);
}
}

37
apps/rust/panic/panic.rs Normal file
View File

@ -0,0 +1,37 @@
/*
* Copyright 2021, Google LLC
*
* SPDX-License-Identifier: Apache-2.0
*/
#![no_std]
#![no_main]
// This file is a minimal test application to check panic's WAI.
extern crate libkata;
use kata_os_common::logger::KataLogger;
use kata_os_common::sel4_sys;
// 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]
pub fn main() {
static KATA_LOGGER: KataLogger = KataLogger;
log::set_logger(&KATA_LOGGER).unwrap();
log::set_max_level(log::LevelFilter::Trace);
panic!("Goodbye, cruel world");
}