Ver código fonte

src: minor style and comments edit

Quentin Monnet 8 anos atrás
pai
commit
115c4a362b
2 arquivos alterados com 9 adições e 4 exclusões
  1. 9 3
      src/ebpf.rs
  2. 0 1
      src/helpers.rs

+ 9 - 3
src/ebpf.rs

@@ -244,13 +244,19 @@ pub struct Insn {
 /// assert_eq!(insn.opc, 0x95);
 /// assert_eq!(insn.opc, 0x95);
 /// ```
 /// ```
 pub fn get_insn(prog: &std::vec::Vec<u8>, idx: usize) -> Insn {
 pub fn get_insn(prog: &std::vec::Vec<u8>, idx: usize) -> Insn {
-    // TODO panic if size problem? Should be checked by verifier, though
+    // TODO panic if size problem? Should have been checked by verifier, though.
+    // Update: this function is publicly available and user can call it with any idx, so we should
+    // definitely add a guard here.
     let insn = Insn {
     let insn = Insn {
         opc:  prog[INSN_SIZE * idx],
         opc:  prog[INSN_SIZE * idx],
         dst:  prog[INSN_SIZE * idx + 1] & 0x0f,
         dst:  prog[INSN_SIZE * idx + 1] & 0x0f,
         src: (prog[INSN_SIZE * idx + 1] & 0xf0) >> 4,
         src: (prog[INSN_SIZE * idx + 1] & 0xf0) >> 4,
-        off: unsafe { let x = prog.as_ptr().offset((INSN_SIZE * idx + 2) as isize) as *const i16; *x },
-        imm: unsafe { let x = prog.as_ptr().offset((INSN_SIZE * idx + 4) as isize) as *const i32; *x },
+        off: unsafe {
+            let x = prog.as_ptr().offset((INSN_SIZE * idx + 2) as isize) as *const i16; *x
+        },
+        imm: unsafe {
+            let x = prog.as_ptr().offset((INSN_SIZE * idx + 4) as isize) as *const i32; *x
+        },
     };
     };
     insn
     insn
 }
 }

+ 0 - 1
src/helpers.rs

@@ -120,7 +120,6 @@ pub fn memfrob (ptr: u64, len: u64, unused3: u64, unused4: u64, unused5: u64) ->
     0
     0
 }
 }
 
 
-
 // TODO: Try again when asm!() is available in stable Rust.
 // TODO: Try again when asm!() is available in stable Rust.
 // #![feature(asm)]
 // #![feature(asm)]
 // #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
 // #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]