Refactor log macro for readability

This happens to fix the miscompilation that occurs when bpf-linker is
moved to LLVM's new pass manager. A later commit will avoid the
miscompilation more convincingly.
pull/683/head
Tamir Duberstein 1 year ago
parent ec5ff01e41
commit b3db9161eb
No known key found for this signature in database

@ -144,34 +144,27 @@ pub(crate) fn log(args: LogArgs, level: Option<TokenStream>) -> Result<TokenStre
let values_iter = values.iter(); let values_iter = values.iter();
Ok(quote! { Ok(quote! {
{ match unsafe { &mut ::aya_log_ebpf::AYA_LOG_BUF }.get_ptr_mut(0).and_then(|ptr| unsafe { ptr.as_mut() }) {
if let Some(buf_ptr) = unsafe { ::aya_log_ebpf::AYA_LOG_BUF.get_ptr_mut(0) } { None => {},
let buf = unsafe { &mut *buf_ptr }; Some(::aya_log_ebpf::LogBuf { buf }) => {
if let Ok(header_len) = ::aya_log_ebpf::write_record_header( let _: Result<(), ()> = (|| {
&mut buf.buf, let mut len = ::aya_log_ebpf::write_record_header(
buf,
#target, #target,
#lvl, #lvl,
module_path!(), module_path!(),
file!(), file!(),
line!(), line!(),
#num_args, #num_args,
) { )?;
let record_len = header_len; #(
let slice = buf.get_mut(len..).ok_or(())?;
if let Ok(record_len) = { len += ::aya_log_ebpf::WriteToBuf::write(#values_iter, slice)?;
Ok::<_, ()>(record_len) #( .and_then(|record_len| { )*
if record_len >= buf.buf.len() { let record = buf.get(..len).ok_or(())?;
return Err(()); unsafe { &mut ::aya_log_ebpf::AYA_LOGS }.output(#ctx, record, 0);
} Ok(())
aya_log_ebpf::WriteToBuf::write({ #values_iter }, &mut buf.buf[record_len..]).map(|len| record_len + len) })();
}) )*
} {
unsafe { ::aya_log_ebpf::AYA_LOGS.output(
#ctx,
&buf.buf[..record_len], 0
)}
}
}
} }
} }
}) })

Loading…
Cancel
Save