Minor tweaks to make the verifier's job easier

pull/350/head
Alessandro Decina 3 years ago committed by Dave Tucker
parent b14d4bab2f
commit 2ac433449c

@ -11,7 +11,8 @@ use aya_bpf::{
maps::{PerCpuArray, PerfEventByteArray},
};
pub use aya_log_common::Level;
use aya_log_common::{RecordField, LOG_BUF_CAPACITY};
use aya_log_common::RecordField;
pub use aya_log_common::LOG_BUF_CAPACITY;
#[doc(hidden)]
#[repr(C)]
@ -59,12 +60,18 @@ impl<'a> ufmt::uWrite for LogBufWriter<'a> {
fn write_str(&mut self, s: &str) -> Result<(), Self::Error> {
let bytes = s.as_bytes();
let len = bytes.len();
// this is to make sure the verifier knows about the upper bound
if len > LOG_BUF_CAPACITY {
return Err(());
}
let available = self.data.len() - self.pos;
if available < len {
return Err(());
}
self.data[self.pos..self.pos + len].copy_from_slice(bytes);
self.data[self.pos..self.pos + len].copy_from_slice(&bytes[..len]);
self.pos += len;
Ok(())
}

@ -183,7 +183,10 @@ macro_rules! log {
if let Some(buf) = unsafe { $crate::AYA_LOG_BUF.get_mut(0) } {
if let Ok(header_len) = $crate::write_record_header(&mut buf.buf, module_path!(), $lvl, module_path!(), file!(), line!()) {
if let Ok(message_len) = $crate::write_record_message!(&mut buf.buf[header_len..], $($arg)+) {
let record_len = header_len + message_len;
if record_len <= $crate::LOG_BUF_CAPACITY {
let _ = unsafe { $crate::AYA_LOGS.output($ctx, &buf.buf[..header_len + message_len], 0) };
}
};
}
}

Loading…
Cancel
Save