fix: replaced custom type defintions with proper libc types

pull/23/head
Simone Margaritelli 4 years ago
parent 75c2fe14b0
commit 03a891011f

@ -65,11 +65,6 @@ pub use sock::{SockHash, SockMap};
pub use stack::Stack; pub use stack::Stack;
pub use stack_trace::StackTraceMap; pub use stack_trace::StackTraceMap;
#[cfg(target_pointer_width = "32")]
type CodeType = i32;
#[cfg(target_pointer_width = "64")]
type CodeType = i64;
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum MapError { pub enum MapError {
#[error("map `{name}` not found ")] #[error("map `{name}` not found ")]
@ -90,7 +85,7 @@ pub enum MapError {
#[error("failed to create map `{name}`: {code}")] #[error("failed to create map `{name}`: {code}")]
CreateError { CreateError {
name: String, name: String,
code: CodeType, code: libc::c_long,
io_error: io::Error, io_error: io::Error,
}, },
@ -115,7 +110,7 @@ pub enum MapError {
#[error("the `{call}` syscall failed with code {code} io_error {io_error}")] #[error("the `{call}` syscall failed with code {code} io_error {io_error}")]
SyscallError { SyscallError {
call: String, call: String,
code: CodeType, code: libc::c_long,
io_error: io::Error, io_error: io::Error,
}, },

@ -273,11 +273,6 @@ impl Drop for PerfBuffer {
} }
} }
#[cfg(target_pointer_width = "32")]
type OffsetType = i32;
#[cfg(target_pointer_width = "64")]
type OffsetType = i64;
#[cfg_attr(test, allow(unused_variables))] #[cfg_attr(test, allow(unused_variables))]
unsafe fn mmap( unsafe fn mmap(
addr: *mut c_void, addr: *mut c_void,
@ -285,7 +280,7 @@ unsafe fn mmap(
prot: c_int, prot: c_int,
flags: c_int, flags: c_int,
fd: i32, fd: i32,
offset: OffsetType, offset: libc::off_t,
) -> *mut c_void { ) -> *mut c_void {
#[cfg(not(test))] #[cfg(not(test))]
return libc::mmap(addr, len, prot, flags, fd, offset); return libc::mmap(addr, len, prot, flags, fd, offset);

@ -49,11 +49,6 @@ fn syscall(call: Syscall) -> SysResult {
return TEST_SYSCALL.with(|test_impl| unsafe { test_impl.borrow()(call) }); return TEST_SYSCALL.with(|test_impl| unsafe { test_impl.borrow()(call) });
} }
#[cfg(target_pointer_width = "32")]
type RetType = i32;
#[cfg(target_pointer_width = "64")]
type RetType = i64;
#[cfg(not(test))] #[cfg(not(test))]
unsafe fn syscall_impl(call: Syscall) -> SysResult { unsafe fn syscall_impl(call: Syscall) -> SysResult {
use libc::{SYS_bpf, SYS_perf_event_open}; use libc::{SYS_bpf, SYS_perf_event_open};
@ -69,7 +64,7 @@ unsafe fn syscall_impl(call: Syscall) -> SysResult {
flags, flags,
} => libc::syscall(SYS_perf_event_open, &attr, pid, cpu, group, flags), } => libc::syscall(SYS_perf_event_open, &attr, pid, cpu, group, flags),
PerfEventIoctl { fd, request, arg } => { PerfEventIoctl { fd, request, arg } => {
libc::ioctl(fd, request.try_into().unwrap(), arg) as RetType libc::ioctl(fd, request.try_into().unwrap(), arg) as libc::c_long
} }
}; };

Loading…
Cancel
Save