From f0eea47175c71330c59bef68ffa1f70aeaa8bc4c Mon Sep 17 00:00:00 2001 From: pdliyan Date: Tue, 4 Jul 2023 21:16:59 +0800 Subject: [PATCH] impl from_stack_argument. --- bpf/aya-bpf/src/args.rs | 51 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/bpf/aya-bpf/src/args.rs b/bpf/aya-bpf/src/args.rs index deb9aaa7..0775bf16 100644 --- a/bpf/aya-bpf/src/args.rs +++ b/bpf/aya-bpf/src/args.rs @@ -120,7 +120,11 @@ impl FromPtRegs for *const T { fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option { let addr: __u64 = &ctx.rsp + 8 * (n + 1) as __u64; - unsafe { bpf_probe_read(addr as *const c_int).map(|v| v as *const _).ok() } + unsafe { + bpf_probe_read(addr as *const c_int) + .map(|v| v as *const _) + .ok() + } } fn from_retval(ctx: &pt_regs) -> Option { @@ -140,7 +144,11 @@ impl FromPtRegs for *const T { fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option { let addr: __u64 = &ctx.uregs[13] + 8 * (n + 1) as __u64; - unsafe { bpf_probe_read(addr as *const c_int).map(|v| v as *const _).ok() } + unsafe { + bpf_probe_read(addr as *const c_int) + .map(|v| v as *const _) + .ok() + } } fn from_retval(ctx: &pt_regs) -> Option { @@ -160,7 +168,11 @@ impl FromPtRegs for *const T { fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option { let addr: __u64 = &ctx.sp + 8 * (n + 1) as __u64; - unsafe { bpf_probe_read(addr as *const c_int).map(|v| v as *const _).ok() } + unsafe { + bpf_probe_read(addr as *const c_int) + .map(|v| v as *const _) + .ok() + } } fn from_retval(ctx: &pt_regs) -> Option { @@ -184,7 +196,11 @@ impl FromPtRegs for *mut T { fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option { let addr: __u64 = &ctx.rsp + 8 * (n + 1) as __u64; - unsafe { bpf_probe_read(addr as *const c_int).map(|v| v as *mut _).ok() } + unsafe { + bpf_probe_read(addr as *const c_int) + .map(|v| v as *mut _) + .ok() + } } fn from_retval(ctx: &pt_regs) -> Option { @@ -204,7 +220,11 @@ impl FromPtRegs for *mut T { fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option { let addr: __u64 = &ctx.uregs[13] + 8 * (n + 1) as __u64; - unsafe { bpf_probe_read(addr as *const c_int).map(|v| v as *mut _).ok() } + unsafe { + bpf_probe_read(addr as *const c_int) + .map(|v| v as *mut _) + .ok() + } } fn from_retval(ctx: &pt_regs) -> Option { @@ -224,7 +244,11 @@ impl FromPtRegs for *mut T { fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option { let addr: __u64 = &ctx.sp + 8 * (n + 1) as __u64; - unsafe { bpf_probe_read(addr as *const c_int).map(|v| v as *mut _).ok() } + unsafe { + bpf_probe_read(addr as *const c_int) + .map(|v| v as *mut _) + .ok() + } } fn from_retval(ctx: &pt_regs) -> Option { @@ -249,6 +273,11 @@ macro_rules! impl_from_pt_regs { } } + fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option { + let addr = ctx.rsp + 8 * (n + 1) as __u64; + Some(addr as *const $type as _) + } + fn from_retval(ctx: &pt_regs) -> Option { Some(ctx.rax as *const $type as _) } @@ -264,6 +293,11 @@ macro_rules! impl_from_pt_regs { } } + fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option { + let addr = ctx.uregs[13] + 8 * (n + 1) as __u64; + Some(addr as *const $type as _) + } + fn from_retval(ctx: &pt_regs) -> Option { Some(ctx.uregs[0] as *const $type as _) } @@ -279,6 +313,11 @@ macro_rules! impl_from_pt_regs { } } + fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option { + let addr = ctx.sp + 8 * (n + 1) as __u64; + Some(addr as *const $type as _) + } + fn from_retval(ctx: &pt_regs) -> Option { Some(ctx.regs[0] as *const $type as _) }