From 8f5a17b54265ce2ad2cbec158292b1bf559ddfd3 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Sat, 6 Feb 2021 19:13:47 +0000 Subject: [PATCH] Rename the syscalls module to sys --- src/bpf.rs | 2 +- src/lib.rs | 2 +- src/maps/hash_map.rs | 4 ++-- src/maps/mod.rs | 4 ++-- src/maps/perf_map.rs | 6 +++--- src/maps/program_array.rs | 2 +- src/programs/mod.rs | 2 +- src/programs/perf_attach.rs | 2 +- src/programs/probe.rs | 2 +- src/programs/trace_point.rs | 4 +--- src/programs/xdp.rs | 2 +- src/{syscalls => sys}/bpf.rs | 2 +- src/{syscalls => sys}/fake.rs | 1 + src/{syscalls => sys}/mod.rs | 0 src/{syscalls => sys}/perf_event.rs | 2 +- 15 files changed, 18 insertions(+), 19 deletions(-) rename src/{syscalls => sys}/bpf.rs (99%) rename src/{syscalls => sys}/fake.rs (97%) rename src/{syscalls => sys}/mod.rs (100%) rename src/{syscalls => sys}/perf_event.rs (95%) diff --git a/src/bpf.rs b/src/bpf.rs index 74444749..bc29b2eb 100644 --- a/src/bpf.rs +++ b/src/bpf.rs @@ -12,7 +12,7 @@ use crate::{ maps::{Map, MapError}, obj::{btf::BtfError, Object, ParseError}, programs::{KProbe, Program, ProgramData, ProgramError, SocketFilter, TracePoint, UProbe, Xdp}, - syscalls::bpf_map_update_elem_ptr, + sys::bpf_map_update_elem_ptr, }; pub(crate) const BPF_OBJ_NAME_LEN: usize = 16; diff --git a/src/lib.rs b/src/lib.rs index bceaa6da..14a3e8d7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,6 @@ mod generated; pub mod maps; mod obj; pub mod programs; -mod syscalls; +mod sys; pub use bpf::*; diff --git a/src/maps/hash_map.rs b/src/maps/hash_map.rs index 3607b8fd..5a7ea257 100644 --- a/src/maps/hash_map.rs +++ b/src/maps/hash_map.rs @@ -9,7 +9,7 @@ use std::{ use crate::{ generated::bpf_map_type::BPF_MAP_TYPE_HASH, maps::{IterableMap, Map, MapError, MapIter, MapKeys}, - syscalls::{ + sys::{ bpf_map_delete_elem, bpf_map_lookup_and_delete_elem, bpf_map_lookup_elem, bpf_map_update_elem, }, @@ -142,7 +142,7 @@ mod tests { bpf_map_type::{BPF_MAP_TYPE_HASH, BPF_MAP_TYPE_PERF_EVENT_ARRAY}, }, obj, - syscalls::{override_syscall, SysResult, Syscall}, + sys::{override_syscall, SysResult, Syscall}, }; use super::*; diff --git a/src/maps/mod.rs b/src/maps/mod.rs index 1972cb0e..a64b6957 100644 --- a/src/maps/mod.rs +++ b/src/maps/mod.rs @@ -3,7 +3,7 @@ use thiserror::Error; use crate::{ obj, - syscalls::{bpf_create_map, bpf_map_get_next_key}, + sys::{bpf_create_map, bpf_map_get_next_key}, Pod, RawFd, }; @@ -196,7 +196,7 @@ mod tests { use crate::{ bpf_map_def, generated::{bpf_cmd, bpf_map_type::BPF_MAP_TYPE_HASH}, - syscalls::{override_syscall, Syscall}, + sys::{override_syscall, Syscall}, }; use super::*; diff --git a/src/maps/perf_map.rs b/src/maps/perf_map.rs index 48a3f60f..d822f8dc 100644 --- a/src/maps/perf_map.rs +++ b/src/maps/perf_map.rs @@ -21,7 +21,7 @@ use crate::{ perf_event_type::*, }, maps::{Map, MapError}, - syscalls::{bpf_map_update_elem, perf_event_ioctl, perf_event_open}, + sys::{bpf_map_update_elem, perf_event_ioctl, perf_event_open}, RawFd, PERF_EVENT_IOC_DISABLE, PERF_EVENT_IOC_ENABLE, }; @@ -397,7 +397,7 @@ unsafe fn mmap( return libc::mmap(addr, len, prot, flags, fd, offset); #[cfg(test)] - use crate::syscalls::TEST_MMAP_RET; + use crate::sys::TEST_MMAP_RET; #[cfg(test)] TEST_MMAP_RET.with(|ret| *ret.borrow()) @@ -423,7 +423,7 @@ mod tests { use super::*; use crate::{ generated::perf_event_mmap_page, - syscalls::{override_syscall, Syscall, TEST_MMAP_RET}, + sys::{override_syscall, Syscall, TEST_MMAP_RET}, }; use std::{convert::TryInto, fmt::Debug, iter::FromIterator, mem}; diff --git a/src/maps/program_array.rs b/src/maps/program_array.rs index 70bbb9f4..a3998f00 100644 --- a/src/maps/program_array.rs +++ b/src/maps/program_array.rs @@ -10,7 +10,7 @@ use crate::{ generated::bpf_map_type::BPF_MAP_TYPE_PROG_ARRAY, maps::{IterableMap, Map, MapError, MapIter, MapKeys}, programs::ProgramFd, - syscalls::{ + sys::{ bpf_map_delete_elem, bpf_map_lookup_and_delete_elem, bpf_map_lookup_elem, bpf_map_update_elem, }, diff --git a/src/programs/mod.rs b/src/programs/mod.rs index 9b8c1601..7be70c9f 100644 --- a/src/programs/mod.rs +++ b/src/programs/mod.rs @@ -23,7 +23,7 @@ pub use socket_filter::*; pub use trace_point::*; pub use xdp::*; -use crate::{obj, syscalls::bpf_load_program, RawFd}; +use crate::{obj, sys::bpf_load_program, RawFd}; #[derive(Debug, Error)] pub enum ProgramError { #[error("the program {program} is already loaded")] diff --git a/src/programs/perf_attach.rs b/src/programs/perf_attach.rs index 2faaee3e..8eaa2989 100644 --- a/src/programs/perf_attach.rs +++ b/src/programs/perf_attach.rs @@ -3,7 +3,7 @@ use std::{cell::RefCell, rc::Rc}; use libc::close; use crate::{ - syscalls::perf_event_ioctl, RawFd, PERF_EVENT_IOC_DISABLE, PERF_EVENT_IOC_ENABLE, + sys::perf_event_ioctl, RawFd, PERF_EVENT_IOC_DISABLE, PERF_EVENT_IOC_ENABLE, PERF_EVENT_IOC_SET_BPF, }; diff --git a/src/programs/probe.rs b/src/programs/probe.rs index 6b9a29d4..8da150d6 100644 --- a/src/programs/probe.rs +++ b/src/programs/probe.rs @@ -13,7 +13,7 @@ use thiserror::Error; use crate::{ generated::bpf_prog_type::BPF_PROG_TYPE_KPROBE, programs::{load_program, perf_attach, Link, ProgramData, ProgramError}, - syscalls::perf_event_open_probe, + sys::perf_event_open_probe, }; lazy_static! { diff --git a/src/programs/trace_point.rs b/src/programs/trace_point.rs index d7f2fe60..7f210d39 100644 --- a/src/programs/trace_point.rs +++ b/src/programs/trace_point.rs @@ -1,8 +1,6 @@ use std::fs; -use crate::{ - generated::bpf_prog_type::BPF_PROG_TYPE_TRACEPOINT, syscalls::perf_event_open_trace_point, -}; +use crate::{generated::bpf_prog_type::BPF_PROG_TYPE_TRACEPOINT, sys::perf_event_open_trace_point}; use super::{load_program, perf_attach, Link, ProgramData, ProgramError}; diff --git a/src/programs/xdp.rs b/src/programs/xdp.rs index 12cd83cf..e3c8162f 100644 --- a/src/programs/xdp.rs +++ b/src/programs/xdp.rs @@ -6,7 +6,7 @@ use crate::RawFd; use crate::{ generated::{bpf_attach_type::BPF_XDP, bpf_prog_type::BPF_PROG_TYPE_XDP}, programs::{load_program, FdLink, Link, LinkRef, ProgramData, ProgramError}, - syscalls::bpf_link_create, + sys::bpf_link_create, }; #[derive(Debug)] diff --git a/src/syscalls/bpf.rs b/src/sys/bpf.rs similarity index 99% rename from src/syscalls/bpf.rs rename to src/sys/bpf.rs index af3e8f81..fc0a4fb3 100644 --- a/src/syscalls/bpf.rs +++ b/src/sys/bpf.rs @@ -12,7 +12,7 @@ use crate::{ bpf_map_def, generated::{bpf_attach_type, bpf_attr, bpf_cmd, bpf_insn}, programs::VerifierLog, - syscalls::SysResult, + sys::SysResult, Pod, RawFd, BPF_OBJ_NAME_LEN, }; diff --git a/src/syscalls/fake.rs b/src/sys/fake.rs similarity index 97% rename from src/syscalls/fake.rs rename to src/sys/fake.rs index 0be0e6a9..a72027b9 100644 --- a/src/syscalls/fake.rs +++ b/src/sys/fake.rs @@ -17,6 +17,7 @@ unsafe fn test_syscall(_call: Syscall) -> SysResult { return Err((-1, io::Error::from_raw_os_error(libc::EINVAL))); } +#[cfg(test)] pub(crate) fn override_syscall(call: unsafe fn(Syscall) -> SysResult) { TEST_SYSCALL.with(|test_impl| *test_impl.borrow_mut() = call); } diff --git a/src/syscalls/mod.rs b/src/sys/mod.rs similarity index 100% rename from src/syscalls/mod.rs rename to src/sys/mod.rs diff --git a/src/syscalls/perf_event.rs b/src/sys/perf_event.rs similarity index 95% rename from src/syscalls/perf_event.rs rename to src/sys/perf_event.rs index 62db76c7..72ea6cd9 100644 --- a/src/syscalls/perf_event.rs +++ b/src/sys/perf_event.rs @@ -85,5 +85,5 @@ pub(crate) fn perf_event_ioctl(fd: c_int, request: c_ulong, arg: c_int) -> SysRe return syscall(call); #[cfg(test)] - return crate::syscalls::TEST_SYSCALL.with(|test_impl| unsafe { test_impl.borrow()(call) }); + return crate::sys::TEST_SYSCALL.with(|test_impl| unsafe { test_impl.borrow()(call) }); }