Ver Fonte

src/lib.rs: minor cleanup in documentation

Following the addition of customized verifier support, bring minor
modifications to the documentation of the library. In particular, remove
comments about set_verifier() that would panic (it does not, it returns
an error on verification failure).

Also remove spurious blank lines at the end of a test file (I was just
asking for an end-of-line char at the end of the last line ;) ).
Quentin Monnet há 6 anos atrás
pai
commit
bc41ec47d9
2 ficheiros alterados com 23 adições e 32 exclusões
  1. 23 30
      src/lib.rs
  2. 0 2
      tests/misc.rs

+ 23 - 30
src/lib.rs

@@ -40,13 +40,14 @@ mod asm_parser;
 mod jit;
 mod verifier;
 
-/// eBPF verification function that panics if the program does not meet its requirements.
+/// eBPF verification function that returns an error if the program does not meet its requirements.
 ///
-/// Some examples of things the verifier may panic for:
-///   - program does not terminate
-///   - unknown instructions
-///   - bad formed instruction
-///   - unknown eBPF helper index
+/// Some examples of things the verifier may reject the program for:
+///
+///   - Program does not terminate.
+///   - Unknown instructions.
+///   - Bad formed instruction.
+///   - Unknown eBPF helper index.
 pub type Verifier = fn(prog: &[u8]) -> Result<(), Error>;
 
 // A metadata buffer with two offset indications. It can be used in one kind of eBPF VM to simulate
@@ -158,11 +159,9 @@ impl<'a> EbpfVmMbuff<'a> {
         Ok(())
     }
 
-    /// Set a new verifier function.
-    ///
-    /// # Panics
-    ///
-    /// The simple verifier may panic if it finds errors in the eBPF program at load time.
+    /// Set a new verifier function. The function should return an `Error` if the program should be
+    /// rejected by the virtual machine. If a program has been loaded to the VM already, the
+    /// verifier is immediately run.
     ///
     /// # Examples
     ///
@@ -170,7 +169,7 @@ impl<'a> EbpfVmMbuff<'a> {
     /// use std::io::{Error, ErrorKind};
     /// use rbpf::ebpf;
     ///
-    /// // simple verifier.
+    /// // Define a simple verifier function.
     /// fn verifier(prog: &[u8]) -> Result<(), Error> {
     ///     let last_insn = ebpf::get_insn(prog, (prog.len() / ebpf::INSN_SIZE) - 1);
     ///     if last_insn.opc != ebpf::EXIT {
@@ -858,11 +857,9 @@ impl<'a> EbpfVmFixedMbuff<'a> {
         Ok(())
     }
 
-    /// Set a new verifier function.
-    ///
-    /// # Panics
-    ///
-    /// The simple verifier may panic if it finds errors in the eBPF program at load time.
+    /// Set a new verifier function. The function should return an `Error` if the program should be
+    /// rejected by the virtual machine. If a program has been loaded to the VM already, the
+    /// verifier is immediately run.
     ///
     /// # Examples
     ///
@@ -870,7 +867,7 @@ impl<'a> EbpfVmFixedMbuff<'a> {
     /// use std::io::{Error, ErrorKind};
     /// use rbpf::ebpf;
     ///
-    /// // simple verifier.
+    /// // Define a simple verifier function.
     /// fn verifier(prog: &[u8]) -> Result<(), Error> {
     ///     let last_insn = ebpf::get_insn(prog, (prog.len() / ebpf::INSN_SIZE) - 1);
     ///     if last_insn.opc != ebpf::EXIT {
@@ -1174,11 +1171,9 @@ impl<'a> EbpfVmRaw<'a> {
         Ok(())
     }
 
-    /// Set a new verifier function.
-    ///
-    /// # Panics
-    ///
-    /// The simple verifier may panic if it finds errors in the eBPF program at load time.
+    /// Set a new verifier function. The function should return an `Error` if the program should be
+    /// rejected by the virtual machine. If a program has been loaded to the VM already, the
+    /// verifier is immediately run.
     ///
     /// # Examples
     ///
@@ -1186,7 +1181,7 @@ impl<'a> EbpfVmRaw<'a> {
     /// use std::io::{Error, ErrorKind};
     /// use rbpf::ebpf;
     ///
-    /// // simple verifier.
+    /// // Define a simple verifier function.
     /// fn verifier(prog: &[u8]) -> Result<(), Error> {
     ///     let last_insn = ebpf::get_insn(prog, (prog.len() / ebpf::INSN_SIZE) - 1);
     ///     if last_insn.opc != ebpf::EXIT {
@@ -1457,11 +1452,9 @@ impl<'a> EbpfVmNoData<'a> {
         Ok(())
     }
 
-    /// Set a new verifier function.
-    ///
-    /// # Panics
-    ///
-    /// The simple verifier may panic if it finds errors in the eBPF program at load time.
+    /// Set a new verifier function. The function should return an `Error` if the program should be
+    /// rejected by the virtual machine. If a program has been loaded to the VM already, the
+    /// verifier is immediately run.
     ///
     /// # Examples
     ///
@@ -1469,7 +1462,7 @@ impl<'a> EbpfVmNoData<'a> {
     /// use std::io::{Error, ErrorKind};
     /// use rbpf::ebpf;
     ///
-    /// // simple verifier.
+    /// // Define a simple verifier function.
     /// fn verifier(prog: &[u8]) -> Result<(), Error> {
     ///     let last_insn = ebpf::get_insn(prog, (prog.len() / ebpf::INSN_SIZE) - 1);
     ///     if last_insn.opc != ebpf::EXIT {

+ 0 - 2
tests/misc.rs

@@ -607,5 +607,3 @@ fn test_verifier_fail() {
     vm.set_prog(&prog).unwrap();
     assert_eq!(vm.prog_exec(), 0xBEE);
 }
-
-