Skip to content

Commit

Permalink
Differentiate orcherstrator logs (project-oak#4953)
Browse files Browse the repository at this point in the history
Now orchestrator logs will be prefixed, just as stage0 and kernel logs are
  • Loading branch information
jul-sh authored Mar 25, 2024
1 parent 7300e14 commit 29174fb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
58 changes: 55 additions & 3 deletions enclave_apps/oak_orchestrator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,66 @@

extern crate alloc;

use core::fmt::Write;

use oak_dice::evidence::Stage0DiceData;
use oak_restricted_kernel_interface::{syscall, DERIVED_KEY_FD, DICE_DATA_FD};
use oak_restricted_kernel_orchestrator::AttestedApp;
use oak_restricted_kernel_sdk::{channel::FileDescriptorChannel, entrypoint};
use oak_restricted_kernel_sdk::channel::FileDescriptorChannel;
use zerocopy::{AsBytes, FromZeroes};
use zeroize::Zeroize;

struct OrchestratorLogger {}

impl log::Log for OrchestratorLogger {
fn enabled(&self, _metadata: &log::Metadata) -> bool {
true
}

fn log(&self, record: &log::Record) {
writeln!(
oak_restricted_kernel_sdk::utils::Stderr {},
"orchestrator {}: {}",
record.level(),
record.args()
)
.unwrap();
}

fn flush(&self) {
oak_restricted_kernel_sdk::utils::Stderr::flush();
}
}

#[global_allocator]
static ALLOCATOR: oak_restricted_kernel_sdk::utils::heap::LockedGrowableHeap =
oak_restricted_kernel_sdk::utils::heap::LockedGrowableHeap::empty();

static LOGGER: OrchestratorLogger = OrchestratorLogger {};

// The orchestrator uses a custom logging implementation, hence the
// #[oak_restricted_kernel_sdk::entrypoint] is not used. The allocator,
// handlers, etc are declared explicitly.
#[no_mangle]
fn _start() -> ! {
oak_restricted_kernel_sdk::utils::log::set_logger(&LOGGER).expect("failed to set logger");
oak_restricted_kernel_sdk::utils::log::set_max_level(
oak_restricted_kernel_sdk::utils::log::LevelFilter::Debug,
);
entrypoint()
}

#[alloc_error_handler]
fn out_of_memory(layout: ::core::alloc::Layout) -> ! {
panic!("error allocating memory in orchestrator: {:#?}", layout);
}

#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
log::error!("orchestrator PANIC: {}", info);
oak_restricted_kernel_interface::syscall::exit(-1);
}

fn read_stage0_dice_data() -> Stage0DiceData {
let mut result = Stage0DiceData::new_zeroed();
let buffer = result.as_bytes_mut();
Expand All @@ -35,8 +88,7 @@ fn read_stage0_dice_data() -> Stage0DiceData {
result
}

#[entrypoint]
fn start() -> ! {
fn entrypoint() -> ! {
let mut attested_app = {
let stage0_dice_data = read_stage0_dice_data();
let channel = FileDescriptorChannel::default();
Expand Down
4 changes: 2 additions & 2 deletions oak_restricted_kernel_sdk/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ pub use oak_core::*;
pub use oak_enclave_runtime_support::heap;
use oak_restricted_kernel_interface::syscall::{fsync, write};

struct Stderr {}
pub struct Stderr {}

impl Stderr {
const STDERR_FD: i32 = 2;

fn flush() {
pub fn flush() {
fsync(Self::STDERR_FD).unwrap();
}
}
Expand Down

0 comments on commit 29174fb

Please sign in to comment.