fix: remove unnecessary unsafe

pull/21/head
EKTehtris 4 years ago
parent 907256be98
commit e26b3e4306

@ -1,4 +1,5 @@
use core::ffi::c_void;
use crate::{bindings::pt_regs, BpfContext};
pub struct ProbeContext {
@ -50,7 +51,7 @@ impl Regs {
#[doc(alias = "PT_REGS_PARM1")]
/// Utility to get the First Parameter
pub unsafe fn parm1(&self) -> *const c_void {
pub fn parm1(&self) -> *const c_void {
// assert!(self.regs.is_null(),"You should ensure that the registers are not null");
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
return unsafe { &*(self.regs) }.rdi as *const c_void;
@ -61,7 +62,7 @@ impl Regs {
#[doc(alias = "PT_REGS_PARM2")]
/// Utility to get the Second Parameter
pub unsafe fn parm2(&self) -> *const c_void {
pub fn parm2(&self) -> *const c_void {
// assert!(self.regs.is_null(),"You should ensure that the registers are not null");
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
return unsafe { &*(self.regs) }.rsi as *const c_void;
@ -72,7 +73,7 @@ impl Regs {
#[doc(alias = "PT_REGS_PARM3")]
/// Utility to get the Third Parameter
pub unsafe fn parm3(&self) -> *const c_void {
pub fn parm3(&self) -> *const c_void {
// assert!(self.regs.is_null(),"You should ensure that the registers are not null");
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
return unsafe { &*(self.regs) }.rdx as *const c_void;
@ -83,7 +84,7 @@ impl Regs {
#[doc(alias = "PT_REGS_PARM4")]
/// Utility to get the Fourth Parameter
pub unsafe fn parm4(&self) -> *const c_void {
pub fn parm4(&self) -> *const c_void {
// assert!(self.regs.is_null(),"You should ensure that the registers are not null");
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
return unsafe { &*(self.regs) }.rcx as *const c_void;
@ -94,7 +95,7 @@ impl Regs {
#[doc(alias = "PT_REGS_PARM5")]
/// Utility to get the Fifth Parameter
pub unsafe fn parm5(&self) -> *const c_void {
pub fn parm5(&self) -> *const c_void {
// assert!(self.regs.is_null(),"You should ensure that the registers are not null");
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
return unsafe { &*(self.regs) }.r8 as *const c_void;
@ -105,7 +106,7 @@ impl Regs {
#[doc(alias = "PT_REGS_PARM6")]
/// Utility to get the Sixth Parameter (not available for s390x)
pub unsafe fn parm6(&self) -> *const c_void {
pub fn parm6(&self) -> *const c_void {
// assert!(self.regs.is_null(),"You should ensure that the registers are not null");
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
return unsafe { &*(self.regs) }.r9 as *const c_void;
@ -119,7 +120,7 @@ impl Regs {
#[doc(alias = "PT_REGS_RET")]
/// Utility to get the Stack Pointer
pub unsafe fn ret(&self) -> *const c_void {
pub fn ret(&self) -> *const c_void {
// assert!(self.regs.is_null(),"You should ensure that the registers are not null");
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
return unsafe { &*(self.regs) }.rsp as *const c_void;
@ -131,7 +132,7 @@ impl Regs {
#[doc(alias = "PT_REGS_FP")]
/// Utility to get the Frame Pointer
/// Only available with CONFIG_FRAME_POINTER enabled on kernel.
pub unsafe fn fp(&self) -> *const c_void {
pub fn fp(&self) -> *const c_void {
// assert!(self.regs.is_null(),"You should ensure that the registers are not null");
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
return unsafe { &*(self.regs) }.rbp as *const c_void;
@ -154,7 +155,7 @@ impl Regs {
#[doc(alias = "PT_REGS_IP")]
/// Utility to get the Instruction Pointer register
pub unsafe fn ip(&self) -> *const c_void {
pub fn ip(&self) -> *const c_void {
// assert!(self.regs.is_null(),"You should ensure that the registers are not null");
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
return unsafe { &*(self.regs) }.rip as *const c_void;
@ -165,7 +166,7 @@ impl Regs {
#[doc(alias = "PT_REGS_SP")]
/// Utility to get the Stack Pointer
pub unsafe fn sp(&self) -> *const c_void {
pub fn sp(&self) -> *const c_void {
// assert!(self.regs.is_null(),"You should ensure that the registers are not null");
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
return unsafe { &*(self.regs) }.rsp as *const c_void;

Loading…
Cancel
Save