mirror of
https://github.com/AmbiML/sparrow-kata-full.git
synced 2025-07-10 12:43:22 +00:00
Merge "SDKRuntime: Introduce skeleton implementation"
GitOrigin-RevId: 4c147d204f782881662e3d30b36f848906ae51d3
This commit is contained in:
parent
02e6caec95
commit
c0c03fe731
@ -1,14 +1,16 @@
|
|||||||
|
# Copyright 2022 Google LLC
|
||||||
#
|
#
|
||||||
# Copyright 2018, Data61
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# Commonwealth Scientific and Industrial Research Organisation (CSIRO)
|
# you may not use this file except in compliance with the License.
|
||||||
# ABN 41 687 119 230.
|
# You may obtain a copy of the License at
|
||||||
#
|
#
|
||||||
# This software may be distributed and modified according to the terms of
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
# the BSD 2-Clause license. Note that NO WARRANTY is provided.
|
|
||||||
# See "LICENSE_BSD2.txt" for details.
|
|
||||||
#
|
|
||||||
# @TAG(DATA61_BSD)
|
|
||||||
#
|
#
|
||||||
|
# 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)
|
cmake_minimum_required(VERSION 3.7.2)
|
||||||
|
|
||||||
@ -71,6 +73,18 @@ DeclareCAmkESComponent(ProcessManager
|
|||||||
$ENV{OUT}/kata/components
|
$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(
|
RustAddLibrary(
|
||||||
kata_security_coordinator
|
kata_security_coordinator
|
||||||
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/components/SecurityCoordinator
|
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/components/SecurityCoordinator
|
||||||
|
@ -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 <LoggerInterface.camkes>;
|
import <LoggerInterface.camkes>;
|
||||||
import <ProcessControlInterface.camkes>;
|
import <ProcessControlInterface.camkes>;
|
||||||
import <PackageManagementInterface.camkes>;
|
import <PackageManagementInterface.camkes>;
|
||||||
@ -6,6 +20,7 @@ import <MemoryInterface.camkes>;
|
|||||||
import <SecurityCoordinatorInterface.camkes>;
|
import <SecurityCoordinatorInterface.camkes>;
|
||||||
import <StorageInterface.camkes>;
|
import <StorageInterface.camkes>;
|
||||||
import <TimerServiceInterface.camkes>;
|
import <TimerServiceInterface.camkes>;
|
||||||
|
import <SDKRuntimeInterface.camkes>;
|
||||||
|
|
||||||
component DebugConsole {
|
component DebugConsole {
|
||||||
control;
|
control;
|
||||||
@ -27,6 +42,7 @@ component DebugConsole {
|
|||||||
uses SecurityCoordinatorInterface security;
|
uses SecurityCoordinatorInterface security;
|
||||||
// TODO(b/200707300): for debugging
|
// TODO(b/200707300): for debugging
|
||||||
uses StorageInterface storage;
|
uses StorageInterface storage;
|
||||||
|
uses SDKRuntimeInterface sdk_runtime;
|
||||||
|
|
||||||
uses Timer timer;
|
uses Timer timer;
|
||||||
|
|
||||||
|
@ -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]
|
[package]
|
||||||
name = "kata-shell"
|
name = "kata-shell"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -15,6 +29,7 @@ default = [
|
|||||||
"TEST_MEMORY_MANAGER",
|
"TEST_MEMORY_MANAGER",
|
||||||
"TEST_ML_COORDINATOR",
|
"TEST_ML_COORDINATOR",
|
||||||
"TEST_PANIC",
|
"TEST_PANIC",
|
||||||
|
"TEST_SDK_RUNTIME",
|
||||||
"TEST_SECURITY_COORDINATOR",
|
"TEST_SECURITY_COORDINATOR",
|
||||||
"TEST_TIMER_SERVICE",
|
"TEST_TIMER_SERVICE",
|
||||||
]
|
]
|
||||||
@ -29,6 +44,7 @@ TEST_MAILBOX = []
|
|||||||
TEST_MEMORY_MANAGER = []
|
TEST_MEMORY_MANAGER = []
|
||||||
TEST_ML_COORDINATOR = []
|
TEST_ML_COORDINATOR = []
|
||||||
TEST_PANIC = []
|
TEST_PANIC = []
|
||||||
|
TEST_SDK_RUNTIME = []
|
||||||
TEST_SECURITY_COORDINATOR = []
|
TEST_SECURITY_COORDINATOR = []
|
||||||
TEST_TIMER_SERVICE = []
|
TEST_TIMER_SERVICE = []
|
||||||
TEST_UART = []
|
TEST_UART = []
|
||||||
@ -47,5 +63,6 @@ kata-os-common = { path = "../../kata-os-common" }
|
|||||||
kata-security-interface = { path = "../../SecurityCoordinator/kata-security-interface" }
|
kata-security-interface = { path = "../../SecurityCoordinator/kata-security-interface" }
|
||||||
kata-storage-interface = { path = "../../StorageManager/kata-storage-interface" }
|
kata-storage-interface = { path = "../../StorageManager/kata-storage-interface" }
|
||||||
kata-timer-interface = { path = "../../TimerService/kata-timer-interface" }
|
kata-timer-interface = { path = "../../TimerService/kata-timer-interface" }
|
||||||
|
kata-sdk-interface = { path = "../../SDKRuntime/kata-sdk-interface" }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
zmodem = { path = "../zmodem" }
|
zmodem = { path = "../zmodem" }
|
||||||
|
@ -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]
|
#![no_std]
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
@ -40,6 +54,8 @@ mod test_memory_manager;
|
|||||||
mod test_ml_coordinator;
|
mod test_ml_coordinator;
|
||||||
#[cfg(feature = "TEST_PANIC")]
|
#[cfg(feature = "TEST_PANIC")]
|
||||||
mod test_panic;
|
mod test_panic;
|
||||||
|
#[cfg(feature = "TEST_SDK_RUNTIME")]
|
||||||
|
mod test_sdk_runtime;
|
||||||
#[cfg(feature = "TEST_SECURITY_COORDINATOR")]
|
#[cfg(feature = "TEST_SECURITY_COORDINATOR")]
|
||||||
mod test_security_coordinator;
|
mod test_security_coordinator;
|
||||||
#[cfg(feature = "TEST_TIMER_SERVICE")]
|
#[cfg(feature = "TEST_TIMER_SERVICE")]
|
||||||
@ -129,6 +145,8 @@ pub fn repl<T: io::BufRead>(output: &mut dyn io::Write, input: &mut T, builtin_c
|
|||||||
test_ml_coordinator::add_cmds(&mut cmds);
|
test_ml_coordinator::add_cmds(&mut cmds);
|
||||||
#[cfg(feature = "TEST_PANIC")]
|
#[cfg(feature = "TEST_PANIC")]
|
||||||
test_panic::add_cmds(&mut cmds);
|
test_panic::add_cmds(&mut cmds);
|
||||||
|
#[cfg(feature = "TEST_SDK_RUNTIME")]
|
||||||
|
test_sdk_runtime::add_cmds(&mut cmds);
|
||||||
#[cfg(feature = "TEST_SECURITY_COORDINATOR")]
|
#[cfg(feature = "TEST_SECURITY_COORDINATOR")]
|
||||||
test_security_coordinator::add_cmds(&mut cmds);
|
test_security_coordinator::add_cmds(&mut cmds);
|
||||||
#[cfg(feature = "TEST_TIMER_SERVICE")]
|
#[cfg(feature = "TEST_TIMER_SERVICE")]
|
||||||
|
@ -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<Item = &str>,
|
||||||
|
_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(())
|
||||||
|
}
|
39
apps/system/components/SDKRuntime/Cargo.toml
Normal file
39
apps/system/components/SDKRuntime/Cargo.toml
Normal 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.
|
||||||
|
|
||||||
|
[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
|
27
apps/system/components/SDKRuntime/SDKRuntime.camkes
Normal file
27
apps/system/components/SDKRuntime/SDKRuntime.camkes
Normal file
@ -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 <LoggerInterface.camkes>;
|
||||||
|
import <SDKRuntimeInterface.camkes>;
|
||||||
|
|
||||||
|
component SDKRuntime {
|
||||||
|
provides SDKRuntimeInterface sdk_runtime;
|
||||||
|
|
||||||
|
uses LoggerInterface logger;
|
||||||
|
|
||||||
|
// Enable KataOS CAmkES support.
|
||||||
|
attribute int kataos = true;
|
||||||
|
}
|
@ -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"]
|
@ -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() }
|
@ -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 }
|
@ -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 $@
|
@ -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",
|
||||||
|
]
|
@ -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<postcard::Error> 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<SDKError> 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<Result<(), SDKError>> 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<SDKRuntimeError> for Result<(), SDKError> {
|
||||||
|
fn from(err: SDKRuntimeError) -> Result<(), SDKError> {
|
||||||
|
match err {
|
||||||
|
SDKRuntimeError::SDKSuccess => Ok(()),
|
||||||
|
SDKRuntimeError::SDKSerializeFailed => Err(SDKError::SerializeFailed),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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() }
|
||||||
|
}
|
@ -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"
|
@ -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(())
|
||||||
|
}
|
||||||
|
}
|
19
apps/system/interfaces/SDKRuntimeInterface.camkes
Normal file
19
apps/system/interfaces/SDKRuntimeInterface.camkes
Normal file
@ -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 <SDKRuntimeInterfaceBindings.h>;
|
||||||
|
|
||||||
|
SDKRuntimeError sdk_ping();
|
||||||
|
};
|
@ -1,14 +1,16 @@
|
|||||||
/*
|
// Copyright 2022 Google LLC
|
||||||
* Copyright 2017, Data61
|
//
|
||||||
* Commonwealth Scientific and Industrial Research Organisation (CSIRO)
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* ABN 41 687 119 230.
|
// 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.
|
// https://www.apache.org/licenses/LICENSE-2.0
|
||||||
* See "LICENSE_BSD2.txt" for details.
|
//
|
||||||
*
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
* @TAG(DATA61_BSD)
|
// 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 <std_connector.camkes>;
|
import <std_connector.camkes>;
|
||||||
import <global-connectors.camkes>;
|
import <global-connectors.camkes>;
|
||||||
@ -22,6 +24,7 @@ import "components/StorageManager/StorageManager.camkes";
|
|||||||
import "components/SecurityCoordinator/SecurityCoordinator.camkes";
|
import "components/SecurityCoordinator/SecurityCoordinator.camkes";
|
||||||
import "components/TimerService/TimerService.camkes";
|
import "components/TimerService/TimerService.camkes";
|
||||||
import "components/MailboxDriver/MailboxDriver.camkes";
|
import "components/MailboxDriver/MailboxDriver.camkes";
|
||||||
|
import "components/SDKRuntime/SDKRuntime.camkes";
|
||||||
|
|
||||||
component OpenTitanUART {
|
component OpenTitanUART {
|
||||||
hardware;
|
hardware;
|
||||||
@ -81,6 +84,8 @@ assembly {
|
|||||||
component StorageManager storage_manager;
|
component StorageManager storage_manager;
|
||||||
component TimerService timer_service;
|
component TimerService timer_service;
|
||||||
|
|
||||||
|
component SDKRuntime sdk_runtime;
|
||||||
|
|
||||||
// Built-in CPIO archive is visible only to DebugConsole.
|
// Built-in CPIO archive is visible only to DebugConsole.
|
||||||
connection seL4HardwareMMIO cpio_archive(from debug_console.cpio_archive,
|
connection seL4HardwareMMIO cpio_archive(from debug_console.cpio_archive,
|
||||||
to cpio.cpio);
|
to cpio.cpio);
|
||||||
@ -140,6 +145,10 @@ assembly {
|
|||||||
connection seL4RPCCall shell_storage(from debug_console.storage,
|
connection seL4RPCCall shell_storage(from debug_console.storage,
|
||||||
to storage_manager.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
|
// Note this allocates a 4KB shared memory region for pkg install
|
||||||
// to pass an ObjDescArray
|
// to pass an ObjDescArray
|
||||||
connection seL4RPCOverMultiSharedData shell_package(
|
connection seL4RPCOverMultiSharedData shell_package(
|
||||||
@ -187,6 +196,7 @@ assembly {
|
|||||||
from storage_manager.logger,
|
from storage_manager.logger,
|
||||||
from timer_service.logger,
|
from timer_service.logger,
|
||||||
from mailbox_driver.logger,
|
from mailbox_driver.logger,
|
||||||
|
from sdk_runtime.logger,
|
||||||
to debug_console.logger);
|
to debug_console.logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user