From fae20dcd6824c220066c92a728904febb8561251 Mon Sep 17 00:00:00 2001 From: Sam Leffler Date: Mon, 19 Sep 2022 18:12:20 +0000 Subject: [PATCH] apps/rust: add panic test app to test panic! Change-Id: I4615cdc48996c2d8739a00a4c585d09faf03b63b GitOrigin-RevId: 9a0041d37df0d9526e29171f4c17d339579a44ef --- apps/rust/Cargo.toml | 1 + apps/rust/panic/Cargo.toml | 39 ++++++++++++++++++++++++++++++++++++++ apps/rust/panic/Makefile | 18 ++++++++++++++++++ apps/rust/panic/build.rs | 34 +++++++++++++++++++++++++++++++++ apps/rust/panic/panic.rs | 37 ++++++++++++++++++++++++++++++++++++ 5 files changed, 129 insertions(+) create mode 100644 apps/rust/panic/Cargo.toml create mode 100644 apps/rust/panic/Makefile create mode 100644 apps/rust/panic/build.rs create mode 100644 apps/rust/panic/panic.rs diff --git a/apps/rust/Cargo.toml b/apps/rust/Cargo.toml index d11212b..5dd7f74 100644 --- a/apps/rust/Cargo.toml +++ b/apps/rust/Cargo.toml @@ -19,6 +19,7 @@ members = [ "hello", "fibonacci", + "panic", ] resolver = "2" diff --git a/apps/rust/panic/Cargo.toml b/apps/rust/panic/Cargo.toml new file mode 100644 index 0000000..362dc4c --- /dev/null +++ b/apps/rust/panic/Cargo.toml @@ -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" diff --git a/apps/rust/panic/Makefile b/apps/rust/panic/Makefile new file mode 100644 index 0000000..d1a0faf --- /dev/null +++ b/apps/rust/panic/Makefile @@ -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 diff --git a/apps/rust/panic/build.rs b/apps/rust/panic/build.rs new file mode 100644 index 0000000..69753b1 --- /dev/null +++ b/apps/rust/panic/build.rs @@ -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); + } +} diff --git a/apps/rust/panic/panic.rs b/apps/rust/panic/panic.rs new file mode 100644 index 0000000..debea0c --- /dev/null +++ b/apps/rust/panic/panic.rs @@ -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"); +}