diff --git a/apps/system/CMakeLists.txt b/apps/system/CMakeLists.txt index 17a8211..a8f98fc 100644 --- a/apps/system/CMakeLists.txt +++ b/apps/system/CMakeLists.txt @@ -1,14 +1,16 @@ +# Copyright 2022 Google LLC # -# Copyright 2018, Data61 -# Commonwealth Scientific and Industrial Research Organisation (CSIRO) -# ABN 41 687 119 230. +# 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 # -# This software may be distributed and modified according to the terms of -# the BSD 2-Clause license. Note that NO WARRANTY is provided. -# See "LICENSE_BSD2.txt" for details. -# -# @TAG(DATA61_BSD) +# 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. cmake_minimum_required(VERSION 3.7.2) @@ -71,6 +73,18 @@ DeclareCAmkESComponent(ProcessManager $ENV{OUT}/kata/components ) +RustAddLibrary( + kata_sdk_runtime + SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/components/SDKRuntime + LIB_FILENAME libkata_sdk_runtime.a +) + +DeclareCAmkESComponent(SDKRuntime + LIBS kata_sdk_runtime + INCLUDES interfaces + $ENV{OUT}/kata/components +) + RustAddLibrary( kata_security_coordinator SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/components/SecurityCoordinator diff --git a/apps/system/components/DebugConsole/DebugConsole.camkes b/apps/system/components/DebugConsole/DebugConsole.camkes index bea826c..72edbf0 100644 --- a/apps/system/components/DebugConsole/DebugConsole.camkes +++ b/apps/system/components/DebugConsole/DebugConsole.camkes @@ -1,3 +1,17 @@ +// 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. + import ; import ; import ; @@ -6,6 +20,7 @@ import ; import ; import ; import ; +import ; component DebugConsole { control; @@ -27,6 +42,7 @@ component DebugConsole { uses SecurityCoordinatorInterface security; // TODO(b/200707300): for debugging uses StorageInterface storage; + uses SDKRuntimeInterface sdk_runtime; uses Timer timer; diff --git a/apps/system/components/DebugConsole/kata-shell/Cargo.toml b/apps/system/components/DebugConsole/kata-shell/Cargo.toml index a56b218..cad01fc 100644 --- a/apps/system/components/DebugConsole/kata-shell/Cargo.toml +++ b/apps/system/components/DebugConsole/kata-shell/Cargo.toml @@ -1,3 +1,17 @@ +# 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 = "kata-shell" version = "0.1.0" @@ -15,6 +29,7 @@ default = [ "TEST_MEMORY_MANAGER", "TEST_ML_COORDINATOR", "TEST_PANIC", + "TEST_SDK_RUNTIME", "TEST_SECURITY_COORDINATOR", "TEST_TIMER_SERVICE", ] @@ -29,6 +44,7 @@ TEST_MAILBOX = [] TEST_MEMORY_MANAGER = [] TEST_ML_COORDINATOR = [] TEST_PANIC = [] +TEST_SDK_RUNTIME = [] TEST_SECURITY_COORDINATOR = [] TEST_TIMER_SERVICE = [] TEST_UART = [] @@ -47,5 +63,6 @@ kata-os-common = { path = "../../kata-os-common" } kata-security-interface = { path = "../../SecurityCoordinator/kata-security-interface" } kata-storage-interface = { path = "../../StorageManager/kata-storage-interface" } kata-timer-interface = { path = "../../TimerService/kata-timer-interface" } +kata-sdk-interface = { path = "../../SDKRuntime/kata-sdk-interface" } log = "0.4" zmodem = { path = "../zmodem" } diff --git a/apps/system/components/DebugConsole/kata-shell/src/lib.rs b/apps/system/components/DebugConsole/kata-shell/src/lib.rs index eb697c3..3712cd6 100644 --- a/apps/system/components/DebugConsole/kata-shell/src/lib.rs +++ b/apps/system/components/DebugConsole/kata-shell/src/lib.rs @@ -1,3 +1,17 @@ +// 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. + #![no_std] extern crate alloc; @@ -40,6 +54,8 @@ mod test_memory_manager; mod test_ml_coordinator; #[cfg(feature = "TEST_PANIC")] mod test_panic; +#[cfg(feature = "TEST_SDK_RUNTIME")] +mod test_sdk_runtime; #[cfg(feature = "TEST_SECURITY_COORDINATOR")] mod test_security_coordinator; #[cfg(feature = "TEST_TIMER_SERVICE")] @@ -129,6 +145,8 @@ pub fn repl(output: &mut dyn io::Write, input: &mut T, builtin_c test_ml_coordinator::add_cmds(&mut cmds); #[cfg(feature = "TEST_PANIC")] test_panic::add_cmds(&mut cmds); + #[cfg(feature = "TEST_SDK_RUNTIME")] + test_sdk_runtime::add_cmds(&mut cmds); #[cfg(feature = "TEST_SECURITY_COORDINATOR")] test_security_coordinator::add_cmds(&mut cmds); #[cfg(feature = "TEST_TIMER_SERVICE")] diff --git a/apps/system/components/DebugConsole/kata-shell/src/test_sdk_runtime.rs b/apps/system/components/DebugConsole/kata-shell/src/test_sdk_runtime.rs new file mode 100644 index 0000000..cf771d6 --- /dev/null +++ b/apps/system/components/DebugConsole/kata-shell/src/test_sdk_runtime.rs @@ -0,0 +1,45 @@ +// 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. + +//! SDK Runtime shell test commands + +use crate::CmdFn; +use crate::CommandError; +use crate::HashMap; +use core::fmt::Write; + +use kata_io as io; + +use kata_sdk_interface::kata_sdk_ping; + +pub fn add_cmds(cmds: &mut HashMap<&str, CmdFn>) { + cmds.extend([("test_sdkping", sdk_ping_command as CmdFn)]); +} + +fn sdk_ping_command( + _args: &mut dyn Iterator, + _input: &mut dyn io::BufRead, + output: &mut dyn io::Write, + _builtin_cpio: &[u8], +) -> Result<(), CommandError> { + match kata_sdk_ping() { + Ok(()) => { + writeln!(output, "pong received")?; + } + Err(sdkerror) => { + writeln!(output, "ping failed: {:?}", sdkerror)?; + } + } + Ok(()) +} diff --git a/apps/system/components/SDKRuntime/Cargo.toml b/apps/system/components/SDKRuntime/Cargo.toml new file mode 100644 index 0000000..5a35672 --- /dev/null +++ b/apps/system/components/SDKRuntime/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. + +[workspace] + +members = [ + "kata-sdk-component", + "kata-sdk-interface", + "kata-sdk-runtime", +] +resolver = "2" + +[profile.dev] +opt-level = 0 +debug = true +# TODO(b/223253186): workaround gdb DIE errors +lto = false +codegen-units = 1 + +[profile.release] +opt-level = "z" +lto = "fat" +codegen-units = 1 +split-debuginfo = "unpacked" + +[profile.release.build-override] +opt-level = "z" +codegen-units = 1 diff --git a/apps/system/components/SDKRuntime/SDKRuntime.camkes b/apps/system/components/SDKRuntime/SDKRuntime.camkes new file mode 100644 index 0000000..b84eee7 --- /dev/null +++ b/apps/system/components/SDKRuntime/SDKRuntime.camkes @@ -0,0 +1,27 @@ +// 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. + +// KataOS SDKRuntime services. + +import ; +import ; + +component SDKRuntime { + provides SDKRuntimeInterface sdk_runtime; + + uses LoggerInterface logger; + + // Enable KataOS CAmkES support. + attribute int kataos = true; +} diff --git a/apps/system/components/SDKRuntime/kata-sdk-component/Cargo.toml b/apps/system/components/SDKRuntime/kata-sdk-component/Cargo.toml new file mode 100644 index 0000000..f1b38ee --- /dev/null +++ b/apps/system/components/SDKRuntime/kata-sdk-component/Cargo.toml @@ -0,0 +1,31 @@ +# 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 = "kata-sdk-component" +version = "0.1.0" +edition = "2021" + +[dependencies] +cstr_core = { version = "0.2.3", default-features = false } +kata-os-common = { path = "../../kata-os-common" } +kata-sdk-interface = { path = "../kata-sdk-interface" } +kata-sdk-runtime = { path = "../kata-sdk-runtime" } +log = "0.4" +postcard = { version = "0.7", features = ["alloc"], default-features = false } + +[lib] +name = "kata_sdk_runtime" +path = "src/run.rs" +crate-type = ["staticlib"] diff --git a/apps/system/components/SDKRuntime/kata-sdk-component/src/run.rs b/apps/system/components/SDKRuntime/kata-sdk-component/src/run.rs new file mode 100644 index 0000000..210d94c --- /dev/null +++ b/apps/system/components/SDKRuntime/kata-sdk-component/src/run.rs @@ -0,0 +1,51 @@ +// 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. + +/*! + * KataOS SDK Manager CAmkES component support routines. + * + * Functions defined here are entrypoints defined by the CAmkES component + * definition in SDKRuntime.camkes, and bind the C entry points to Rust by + * calling Rust methods in the SDKRuntimeInterface impl, KATA_SDK. + * + * This is the lowest level entry point from C to Rust in CAmkES. + */ + +#![no_std] +#![allow(clippy::missing_safety_doc)] + +extern crate alloc; +use kata_os_common::camkes::Camkes; +use kata_sdk_interface::SDKRuntimeError; +use kata_sdk_interface::SDKRuntimeInterface; +use kata_sdk_runtime::KATA_SDK; + +static mut CAMKES: Camkes = Camkes::new("SDKRuntime"); + +/// CAmkES component pre-init method. +/// +/// We use this to initialize our Rust heap, logger, etc. +#[no_mangle] +pub unsafe extern "C" fn pre_init() { + static mut HEAP_MEMORY: [u8; 8 * 1024] = [0; 8 * 1024]; + CAMKES.pre_init(log::LevelFilter::Trace, &mut HEAP_MEMORY); +} + +/// CAmkES sdk_ping method. +/// +/// See also the component interface definition called +/// `SDKRuntimeInterface.camkes` outside of this crate. Since this is a C +/// function, we must use the C enum for error codes. +#[no_mangle] +pub unsafe extern "C" fn sdk_runtime_sdk_ping() -> SDKRuntimeError { KATA_SDK.ping().into() } diff --git a/apps/system/components/SDKRuntime/kata-sdk-interface/Cargo.toml b/apps/system/components/SDKRuntime/kata-sdk-interface/Cargo.toml new file mode 100644 index 0000000..ea7ee27 --- /dev/null +++ b/apps/system/components/SDKRuntime/kata-sdk-interface/Cargo.toml @@ -0,0 +1,22 @@ +# 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 = "kata-sdk-interface" +version = "0.1.0" +edition = "2021" + +[dependencies] +cstr_core = "0.2.3" +postcard = { version = "0.7", features = ["alloc"], default-features = false } diff --git a/apps/system/components/SDKRuntime/kata-sdk-interface/Makefile b/apps/system/components/SDKRuntime/kata-sdk-interface/Makefile new file mode 100644 index 0000000..0b9d3bc --- /dev/null +++ b/apps/system/components/SDKRuntime/kata-sdk-interface/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. + +INTERFACES=${OUT}/kata/components + +${INTERFACES}/SDKRuntimeInterfaceBindings.h: src/lib.rs cbindgen.toml + cbindgen -c cbindgen.toml src/lib.rs -o $@ diff --git a/apps/system/components/SDKRuntime/kata-sdk-interface/cbindgen.toml b/apps/system/components/SDKRuntime/kata-sdk-interface/cbindgen.toml new file mode 100644 index 0000000..310945f --- /dev/null +++ b/apps/system/components/SDKRuntime/kata-sdk-interface/cbindgen.toml @@ -0,0 +1,24 @@ +# 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. + +language = "C" +include_guard = "__SDK_MANAGER_BINDINGS_H__" +autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually.\n */" +no_includes = true +includes = ["CamkesBindings.h"] + +[export] +include = [ + "SDKRuntimeError", +] diff --git a/apps/system/components/SDKRuntime/kata-sdk-interface/src/error.rs b/apps/system/components/SDKRuntime/kata-sdk-interface/src/error.rs new file mode 100644 index 0000000..b77e522 --- /dev/null +++ b/apps/system/components/SDKRuntime/kata-sdk-interface/src/error.rs @@ -0,0 +1,58 @@ +// 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. + +/// Rust Error enum used for representing an SDK error with postcard. This is +/// what most rust components will actually use as their error handling enum. +#[derive(Debug, Eq, PartialEq)] +pub enum SDKError { + SerializeFailed, +} + +impl From for SDKError { + fn from(_err: postcard::Error) -> SDKError { SDKError::SerializeFailed } +} + +/// C-version of SDKError presented over the CAmkES rpc interface. +#[repr(C)] +#[derive(Debug, Eq, PartialEq)] +pub enum SDKRuntimeError { + SDKSuccess = 0, + SDKSerializeFailed, +} + +/// Mapping function from Rust -> C. +impl From for SDKRuntimeError { + fn from(err: SDKError) -> SDKRuntimeError { + match err { + SDKError::SerializeFailed => SDKRuntimeError::SDKSerializeFailed, + } + } +} + +/// Helper to map from a Result and SDKError to C enum mapping. +impl From> for SDKRuntimeError { + fn from(result: Result<(), SDKError>) -> SDKRuntimeError { + result.map_or_else(SDKRuntimeError::from, |_| SDKRuntimeError::SDKSuccess) + } +} + +/// Inverse mapping function from C -> Rust Result. +impl From for Result<(), SDKError> { + fn from(err: SDKRuntimeError) -> Result<(), SDKError> { + match err { + SDKRuntimeError::SDKSuccess => Ok(()), + SDKRuntimeError::SDKSerializeFailed => Err(SDKError::SerializeFailed), + } + } +} diff --git a/apps/system/components/SDKRuntime/kata-sdk-interface/src/lib.rs b/apps/system/components/SDKRuntime/kata-sdk-interface/src/lib.rs new file mode 100644 index 0000000..e0fffa1 --- /dev/null +++ b/apps/system/components/SDKRuntime/kata-sdk-interface/src/lib.rs @@ -0,0 +1,50 @@ +// 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. + +//! KataOS SDK runtime interfaces + +#![cfg_attr(not(test), no_std)] + +pub mod error; + +pub use error::SDKError; +pub use error::SDKRuntimeError; + +/// Rust interface for the SDKRuntime. +/// +/// This trait defines all of the same verbs we expect to support in the component +/// interface, for both client and server, since CAmkES does not (yet) know how +/// to generate Rust bindings. +/// +/// On the server side, the impl of this trait is instantiated in the component +/// as a global mutable object where the incoming calls from the CAmkES C side +/// are wrapped. +/// +/// On the client side, this trait is implemented using top-level functions, +/// wrapping their CAmkES C stubs. +pub trait SDKRuntimeInterface { + /// Pings the SDK runtime, going from client to server and back via CAmkES IPC. + fn ping(&self) -> Result<(), SDKError>; +} + +/// Rust client-side wrapper for the autogenerated CAmkES ping method. +#[inline] +#[allow(dead_code)] +pub fn kata_sdk_ping() -> Result<(), SDKError> { + extern "C" { + fn sdk_runtime_sdk_ping() -> SDKRuntimeError; + } + + unsafe { sdk_runtime_sdk_ping().into() } +} diff --git a/apps/system/components/SDKRuntime/kata-sdk-runtime/Cargo.toml b/apps/system/components/SDKRuntime/kata-sdk-runtime/Cargo.toml new file mode 100644 index 0000000..32f1ee2 --- /dev/null +++ b/apps/system/components/SDKRuntime/kata-sdk-runtime/Cargo.toml @@ -0,0 +1,22 @@ +# 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 = "kata-sdk-runtime" +version = "0.1.0" +edition = "2021" + +[dependencies] +kata-sdk-interface = { path = "../kata-sdk-interface" } +log = "0.4" diff --git a/apps/system/components/SDKRuntime/kata-sdk-runtime/src/lib.rs b/apps/system/components/SDKRuntime/kata-sdk-runtime/src/lib.rs new file mode 100644 index 0000000..77d6f2f --- /dev/null +++ b/apps/system/components/SDKRuntime/kata-sdk-runtime/src/lib.rs @@ -0,0 +1,35 @@ +// 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. + +#![cfg_attr(not(test), no_std)] + +use kata_sdk_interface::error::SDKError; +use kata_sdk_interface::SDKRuntimeInterface; +use log::trace; + +#[cfg(not(test))] +pub static mut KATA_SDK: KataSDKRuntime = KataSDKRuntime {}; + +/// Kata OS SDK support for third-party applications, Rust core. +/// +/// This is the actual Rust implementation of the SDK runtime component. Here's +/// where we can encapsulate all of our Rust fanciness, away from the C +/// bindings. This is the server-side implementation. +pub struct KataSDKRuntime; +impl SDKRuntimeInterface for KataSDKRuntime { + fn ping(&self) -> Result<(), SDKError> { + trace!("ping!"); + Ok(()) + } +} diff --git a/apps/system/interfaces/SDKRuntimeInterface.camkes b/apps/system/interfaces/SDKRuntimeInterface.camkes new file mode 100644 index 0000000..3ee6902 --- /dev/null +++ b/apps/system/interfaces/SDKRuntimeInterface.camkes @@ -0,0 +1,19 @@ +// 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. + +procedure SDKRuntimeInterface { + include ; + + SDKRuntimeError sdk_ping(); +}; diff --git a/apps/system/system.camkes b/apps/system/system.camkes index 3151e31..58bda50 100644 --- a/apps/system/system.camkes +++ b/apps/system/system.camkes @@ -1,14 +1,16 @@ -/* - * Copyright 2017, Data61 - * Commonwealth Scientific and Industrial Research Organisation (CSIRO) - * ABN 41 687 119 230. - * - * This software may be distributed and modified according to the terms of - * the BSD 2-Clause license. Note that NO WARRANTY is provided. - * See "LICENSE_BSD2.txt" for details. - * - * @TAG(DATA61_BSD) - */ +// 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. import ; import ; @@ -22,6 +24,7 @@ import "components/StorageManager/StorageManager.camkes"; import "components/SecurityCoordinator/SecurityCoordinator.camkes"; import "components/TimerService/TimerService.camkes"; import "components/MailboxDriver/MailboxDriver.camkes"; +import "components/SDKRuntime/SDKRuntime.camkes"; component OpenTitanUART { hardware; @@ -81,6 +84,8 @@ assembly { component StorageManager storage_manager; component TimerService timer_service; + component SDKRuntime sdk_runtime; + // Built-in CPIO archive is visible only to DebugConsole. connection seL4HardwareMMIO cpio_archive(from debug_console.cpio_archive, to cpio.cpio); @@ -140,6 +145,10 @@ assembly { connection seL4RPCCall shell_storage(from debug_console.storage, to storage_manager.storage); + // Hookup SDKRuntime to DebugConsole for shell commands. + connection seL4RPCCall sdk_ping(from debug_console.sdk_runtime, + to sdk_runtime.sdk_runtime); + // Note this allocates a 4KB shared memory region for pkg install // to pass an ObjDescArray connection seL4RPCOverMultiSharedData shell_package( @@ -187,6 +196,7 @@ assembly { from storage_manager.logger, from timer_service.logger, from mailbox_driver.logger, + from sdk_runtime.logger, to debug_console.logger); }