bpf: fix PerfMap::output() API when appending context data

map.output(&ctx, &data, nr_bytes) can be used to append nr_bytes from
the current context to the &data event.
pull/1/head
Alessandro Decina 3 years ago
parent 73c48a5029
commit 67d35cc1d3

@ -32,8 +32,8 @@ impl<T> PerfMap<T> {
} }
} }
pub fn output<C: BpfContext>(&mut self, ctx: &C, data: &T) { pub fn output<C: BpfContext>(&mut self, ctx: &C, data: &T, flags: u32) {
self.output_at_index(ctx, None, data, 0) self.output_at_index(ctx, None, data, flags)
} }
pub fn output_at_index<C: BpfContext>( pub fn output_at_index<C: BpfContext>(
@ -43,10 +43,8 @@ impl<T> PerfMap<T> {
data: &T, data: &T,
flags: u32, flags: u32,
) { ) {
let index = index let index = index.unwrap_or(BPF_F_CURRENT_CPU.into()) as u64;
.map(|i| (i as u64) << 32) let flags = (flags as u64) << 32 | index;
.unwrap_or(BPF_F_CURRENT_CPU.into());
let flags = index | flags as u64;
unsafe { unsafe {
bpf_perf_event_output( bpf_perf_event_output(
ctx.as_ptr(), ctx.as_ptr(),

Loading…
Cancel
Save