Skip to content

Commit

Permalink
chore: [IC-272] add method to save log messages when calling ic0.debu…
Browse files Browse the repository at this point in the history
…g_print
  • Loading branch information
maksymar committed Feb 14, 2024
1 parent 7bb428f commit 1059c10
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
4 changes: 4 additions & 0 deletions rs/config/src/embedders.rs
Expand Up @@ -78,6 +78,9 @@ pub struct FeatureFlags {
/// Track dirty pages with a write barrier instead of the signal handler.
pub write_barrier: FlagStatus,
pub wasm_native_stable_memory: FlagStatus,
// TODO(IC-272): remove this flag once the feature is enabled by default.
/// Indicates whether canister logging feature is enabled or not.
pub canister_logging: FlagStatus,
}

impl FeatureFlags {
Expand All @@ -86,6 +89,7 @@ impl FeatureFlags {
rate_limiting_of_debug_prints: FlagStatus::Enabled,
write_barrier: FlagStatus::Disabled,
wasm_native_stable_memory: FlagStatus::Enabled,
canister_logging: FlagStatus::Disabled,
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions rs/embedders/fuzz/fuzz_targets/execute_with_wasm_executor.rs
Expand Up @@ -63,9 +63,8 @@ fuzz_target!(|module: ConfiguredModule<ICWasmConfig>| {
let log = no_op_logger();
let embedder_config = Config {
feature_flags: FeatureFlags {
rate_limiting_of_debug_prints: FlagStatus::Enabled,
wasm_native_stable_memory: FlagStatus::Enabled,
write_barrier: FlagStatus::Enabled,
..Default::default()
},
..Default::default()
};
Expand Down
28 changes: 15 additions & 13 deletions rs/embedders/src/wasmtime_embedder/system_api.rs
Expand Up @@ -582,21 +582,23 @@ pub(crate) fn syscalls(
overhead!(DEBUG_PRINT, metering_type),
length as u64,
)?;
match (
caller.data().system_api.as_ref().unwrap().subnet_type(),
feature_flags.rate_limiting_of_debug_prints,
) {
// Debug print is a no-op on non-system subnets with rate limiting.
(SubnetType::Application, FlagStatus::Enabled) => Ok(()),
(SubnetType::VerifiedApplication, FlagStatus::Enabled) => Ok(()),
// If rate limiting is disabled or the subnet is a system subnet, then
// debug print produces output.
(_, FlagStatus::Disabled) | (SubnetType::System, FlagStatus::Enabled) => {
with_memory_and_system_api(&mut caller, |system_api, memory| {
with_memory_and_system_api(&mut caller, |system_api, memory| {
if feature_flags.canister_logging == FlagStatus::Enabled {
system_api.save_log_message(offset, length, memory);
}
match (
feature_flags.rate_limiting_of_debug_prints,
system_api.subnet_type(),
) {
// Debug print is a no-op if rate limiting is enabled on non-system subnets.
(FlagStatus::Enabled, SubnetType::Application) => Ok(()),
(FlagStatus::Enabled, SubnetType::VerifiedApplication) => Ok(()),
// Debug print produces output if either rate limiting is disabled or it's a system subnet.
(FlagStatus::Disabled, _) | (_, SubnetType::System) => {
system_api.ic0_debug_print(offset, length, memory)
})
}
}
}
})
}
})
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions rs/execution_environment/src/hypervisor.rs
Expand Up @@ -234,6 +234,7 @@ impl Hypervisor {
let mut embedder_config = config.embedders_config.clone();
embedder_config.subnet_type = own_subnet_type;
embedder_config.dirty_page_overhead = dirty_page_overhead;
embedder_config.feature_flags.canister_logging = config.fetch_canister_logs;

let wasm_executor: Arc<dyn WasmExecutor> = match config.canister_sandboxing_flag {
FlagStatus::Enabled => {
Expand Down
3 changes: 3 additions & 0 deletions rs/interfaces/src/execution_environment.rs
Expand Up @@ -690,6 +690,9 @@ pub trait SystemApi {
heap: &mut [u8],
) -> HypervisorResult<()>;

/// Logs the specified bytes on the heap as a string.
fn save_log_message(&self, src: u32, size: u32, heap: &[u8]);

/// Outputs the specified bytes on the heap as a string on STDOUT.
fn ic0_debug_print(&self, src: u32, size: u32, heap: &[u8]) -> HypervisorResult<()>;

Expand Down
4 changes: 4 additions & 0 deletions rs/system_api/src/lib.rs
Expand Up @@ -2826,6 +2826,10 @@ impl SystemApi for SystemApiImpl {
result
}

fn save_log_message(&self, _src: u32, _size: u32, _heap: &[u8]) {
// TODO(IC-272): implement storing log message.
}

fn ic0_debug_print(&self, src: u32, size: u32, heap: &[u8]) -> HypervisorResult<()> {
const MAX_DEBUG_MESSAGE_SIZE: u32 = 32 * 1024;
let size = size.min(MAX_DEBUG_MESSAGE_SIZE);
Expand Down

0 comments on commit 1059c10

Please sign in to comment.