sbpf_runtime/syscalls/
log.rs1use {
2 crate::{config::ExecutionCost, runtime::LogCollector},
3 sbpf_vm::{compute::ComputeMeter, errors::SbpfVmResult, memory::Memory},
4};
5
6pub fn sol_log(
7 registers: [u64; 5],
8 memory: &Memory,
9 compute: &ComputeMeter,
10 costs: &ExecutionCost,
11 log_collector: &LogCollector,
12) -> SbpfVmResult<u64> {
13 let msg_ptr = registers[0];
14 let msg_len = registers[1];
15
16 compute.consume(costs.syscall_base_cost.max(msg_len))?;
17
18 let msg_bytes = memory.read_bytes(msg_ptr, msg_len as usize)?;
19 let msg = String::from_utf8_lossy(msg_bytes);
20 log_collector
21 .borrow_mut()
22 .push(format!("Program log: {}", msg));
23 Ok(0)
24}
25
26pub fn sol_log_64(
27 registers: [u64; 5],
28 compute: &ComputeMeter,
29 costs: &ExecutionCost,
30 log_collector: &LogCollector,
31) -> SbpfVmResult<u64> {
32 compute.consume(costs.log_64_units)?;
33 log_collector.borrow_mut().push(format!(
34 "Program log: {:#x}, {:#x}, {:#x}, {:#x}, {:#x}",
35 registers[0], registers[1], registers[2], registers[3], registers[4]
36 ));
37 Ok(0)
38}
39
40pub fn sol_log_pubkey(
41 registers: [u64; 5],
42 memory: &Memory,
43 compute: &ComputeMeter,
44 costs: &ExecutionCost,
45 log_collector: &LogCollector,
46) -> SbpfVmResult<u64> {
47 compute.consume(costs.log_pubkey_units)?;
48
49 let pubkey_bytes = memory.read_bytes(registers[0], 32)?;
50 let pubkey_base58 = bs58::encode(pubkey_bytes).into_string();
51 log_collector
52 .borrow_mut()
53 .push(format!("Program log: {}", pubkey_base58));
54 Ok(0)
55}
56
57pub fn sol_log_compute_units(
58 compute: &ComputeMeter,
59 costs: &ExecutionCost,
60 log_collector: &LogCollector,
61) -> SbpfVmResult<u64> {
62 compute.consume(costs.syscall_base_cost)?;
63 log_collector.borrow_mut().push(format!(
64 "Program consumption: {} units remaining",
65 compute.get_remaining()
66 ));
67 Ok(0)
68}
69
70pub fn sol_remaining_compute_units(
71 compute: &ComputeMeter,
72 costs: &ExecutionCost,
73) -> SbpfVmResult<u64> {
74 compute.consume(costs.syscall_base_cost)?;
75 Ok(compute.get_remaining())
76}