Procházet zdrojové kódy

src: add some additional style fixes thanks to rust-clippy

Quentin Monnet před 8 roky
rodič
revize
20bf842baf
5 změnil soubory, kde provedl 19 přidání a 16 odebrání
  1. 8 7
      examples/uptime.rs
  2. 3 0
      src/ebpf.rs
  3. 2 2
      src/jit.rs
  4. 1 1
      src/lib.rs
  5. 5 6
      src/verifier.rs

+ 8 - 7
examples/uptime.rs

@@ -55,13 +55,14 @@ fn main() {
     vm.register_helper(helpers::BPF_KTIME_GETNS_IDX, helpers::bpf_time_getns);
 
     vm.jit_compile();
-    let t = unsafe { vm.prog_exec_jit() };
+    let time = unsafe { vm.prog_exec_jit() };
 
-    let d =  t / 10u64.pow(9)  / 60   / 60  / 24;
-    let h = (t / 10u64.pow(9)  / 60   / 60) % 24;
-    let m = (t / 10u64.pow(9)  / 60 ) % 60;
-    let s = (t / 10u64.pow(9)) % 60;
-    let ns = t % 10u64.pow(9);
+    let days    =  time / 10u64.pow(9)  / 60   / 60  / 24;
+    let hours   = (time / 10u64.pow(9)  / 60   / 60) % 24;
+    let minutes = (time / 10u64.pow(9)  / 60 ) % 60;
+    let seconds = (time / 10u64.pow(9)) % 60;
+    let nanosec =  time % 10u64.pow(9);
 
-    println!("Uptime: {:#x} ns == {} days {:02}:{:02}:{:02}, {} ns", t, d, h, m, s, ns);
+    println!("Uptime: {:#x} ns == {} days {:02}:{:02}:{:02}, {} ns",
+             time, days, hours, minutes, seconds, nanosec);
 }

+ 3 - 0
src/ebpf.rs

@@ -354,6 +354,9 @@ pub const BPF_CLS_MASK    : u8 = 0x07;
 /// Mask to extract the arithmetic operation code from an instruction operation code.
 pub const BPF_ALU_OP_MASK : u8 = 0xf0;
 
+/// Prototype of an eBPF helper function.
+pub type Helper = fn (u64, u64, u64, u64, u64) -> u64;
+
 /// An eBPF instruction.
 ///
 /// See <https://www.kernel.org/doc/Documentation/networking/filter.txt> for the Linux kernel

+ 2 - 2
src/jit.rs

@@ -452,7 +452,7 @@ impl<'a> JitMemory<'a> {
     }
 
     fn jit_compile(&mut self, prog: &[u8], use_mbuff: bool, update_data_ptr: bool,
-                   helpers: &HashMap<u32, fn (u64, u64, u64, u64, u64) -> u64>) {
+                   helpers: &HashMap<u32, ebpf::Helper>) {
         emit_push(self, RBP);
         emit_push(self, RBX);
         emit_push(self, R13);
@@ -833,7 +833,7 @@ impl<'a> std::fmt::Debug for JitMemory<'a> {
 
 // In the end, this is the only thing we export
 pub fn compile(prog: &[u8],
-               helpers: &HashMap<u32, fn (u64, u64, u64, u64, u64) -> u64>,
+               helpers: &HashMap<u32, ebpf::Helper>,
                use_mbuff: bool, update_data_ptr: bool)
     -> (unsafe fn(*mut u8, usize, *mut u8, usize, usize, usize) -> u64) {
 

+ 1 - 1
src/lib.rs

@@ -71,7 +71,7 @@ struct MetaBuff {
 pub struct EbpfVmMbuff<'a> {
     prog:    &'a [u8],
     jit:     (unsafe fn (*mut u8, usize, *mut u8, usize, usize, usize) -> u64),
-    helpers: HashMap<u32, fn (u64, u64, u64, u64, u64) -> u64>,
+    helpers: HashMap<u32, ebpf::Helper>,
 }
 
 impl<'a> EbpfVmMbuff<'a> {

+ 5 - 6
src/verifier.rs

@@ -92,12 +92,11 @@ fn check_registers(insn: &ebpf::Insn, store: bool, insn_ptr: usize) {
     }
 
     match (insn.dst, store) {
-        (0 ... 9, _) => {},
-        (10, true)   => {},
-        (10, false)  => panic!("[Verifier] Error: cannot write into register r10 (insn #{:?})",
-                               insn_ptr),
-        (_, _)       => panic!("[Verifier] Error: invalid destination register (insn #{:?})",
-                               insn_ptr)
+        (0 ... 9, _) | (10, true) => {},
+        (10, false) => panic!("[Verifier] Error: cannot write into register r10 (insn #{:?})",
+                              insn_ptr),
+        (_, _)      => panic!("[Verifier] Error: invalid destination register (insn #{:?})",
+                              insn_ptr)
     }
 }