Skip to content

Commit

Permalink
Rename (qmonnet#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmay authored Oct 24, 2018
1 parent 206d6eb commit f4bda94
Show file tree
Hide file tree
Showing 9 changed files with 321 additions and 321 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,15 @@ do not need those offsets.

```rust,ignore
// for struct EbpfVmMbuff, struct EbpfVmRaw and struct EbpfVmRawData
pub fn set_prog(&mut self, prog: &'a [u8]) -> Result<(), Error>
pub fn set_program(&mut self, prog: &'a [u8]) -> Result<(), Error>
// for struct EbpfVmFixedMbuff
pub fn set_prog(&mut self, prog: &'a [u8],
pub fn set_program(&mut self, prog: &'a [u8],
data_offset: usize,
data_end_offset: usize) -> Result<(), Error>
```

You can use for example `my_vm.set_prog(my_program);` to change the loaded
You can use for example `my_vm.set_program(my_program);` to change the loaded
program after the VM instance creation. This program is checked with the
verifier attached to the VM. The verifying function of the VM can be changed at
any moment.
Expand Down Expand Up @@ -205,16 +205,16 @@ therefore must use specific helper numbers.

```rust,ignore
// for struct EbpfVmMbuff
pub fn prog_exec(&self,
pub fn execute_program(&self,
mem: &'a mut [u8],
mbuff: &'a mut [u8]) -> Result<(u64), Error>
// for struct EbpfVmFixedMbuff and struct EbpfVmRaw
pub fn prog_exec(&self,
pub fn execute_program(&self,
mem: &'a mut [u8]) -> Result<(u64), Error>
// for struct EbpfVmNoData
pub fn prog_exec(&self) -> Result<(u64), Error>
pub fn execute_program(&self) -> Result<(u64), Error>
```

Interprets the loaded program. The function takes a reference to the packet
Expand All @@ -232,18 +232,18 @@ is called. The generated assembly function is internally stored in the VM.

```rust,ignore
// for struct EbpfVmMbuff
pub unsafe fn prog_exec_jit(&self, mem: &'a mut [u8],
pub unsafe fn execute_program_jit(&self, mem: &'a mut [u8],
mbuff: &'a mut [u8]) -> Result<(u64), Error>
// for struct EbpfVmFixedMbuff and struct EbpfVmRaw
pub unsafe fn prog_exec_jit(&self, mem: &'a mut [u8]) -> Result<(u64), Error>
pub unsafe fn execute_program_jit(&self, mem: &'a mut [u8]) -> Result<(u64), Error>
// for struct EbpfVmNoData
pub unsafe fn prog_exec_jit(&self) -> Result<(u64), Error>
pub unsafe fn execute_program_jit(&self) -> Result<(u64), Error>
```

Calls the JIT-compiled program. The arguments to provide are the same as for
`prog_exec()`, again depending on the kind of VM that is used. The result of
`execute_program()`, again depending on the kind of VM that is used. The result of
the JIT-compiled program should be the same as with the interpreter, but it
should run faster. Note that if errors occur during the program execution, the
JIT-compiled version does not handle it as well as the interpreter, and the
Expand Down Expand Up @@ -275,7 +275,7 @@ fn main() {
let vm = rbpf::EbpfVmNoData::new(prog).unwrap();

// Execute (interpret) the program. No argument required for this VM.
assert_eq!(vm.prog_exec().unwrap(), 0x3);
assert_eq!(vm.execute_program().unwrap(), 0x3);
}
```

Expand Down Expand Up @@ -306,7 +306,7 @@ fn main() {

// Then we execute it. For this kind of VM, a reference to the packet data
// must be passed to the function that executes the program.
unsafe { assert_eq!(vm.prog_exec_jit(mem).unwrap(), 0x11); }
unsafe { assert_eq!(vm.execute_program_jit(mem).unwrap(), 0x11); }
}
```
### Using a metadata buffer
Expand Down Expand Up @@ -347,7 +347,7 @@ fn main() {

// Here we must provide both a reference to the packet data, and to the
// metadata buffer we use.
unsafe { assert_eq!(vm.prog_exec_jit(mem, mbuff).unwrap(), 0x2211); }
unsafe { assert_eq!(vm.execute_program_jit(mem, mbuff).unwrap(), 0x2211); }
}
```

Expand Down Expand Up @@ -437,7 +437,7 @@ fn main() {
// This kind of VM takes a reference to the packet data, but does not need
// any reference to the metadata buffer: a fixed buffer is handled
// internally by the VM.
let res = vm.prog_exec(packet).unwrap();
let res = vm.execute_program(packet).unwrap();
println!("Program returned: {:?} ({:#x})", res, res);
}
```
Expand Down
6 changes: 3 additions & 3 deletions examples/load_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,22 @@ fn main() {
let mut vm = rbpf::EbpfVmFixedMbuff::new(Some(prog), 0x40, 0x50).unwrap();
vm.register_helper(helpers::BPF_TRACE_PRINTK_IDX, helpers::bpf_trace_printf).unwrap();

let res = vm.prog_exec(packet1).unwrap();
let res = vm.execute_program(packet1).unwrap();
println!("Packet #1, program returned: {:?} ({:#x})", res, res);
assert_eq!(res, 0xffffffff);

#[cfg(not(windows))]
{
vm.jit_compile().unwrap();

let res = unsafe { vm.prog_exec_jit(packet2).unwrap() };
let res = unsafe { vm.execute_program_jit(packet2).unwrap() };
println!("Packet #2, program returned: {:?} ({:#x})", res, res);
assert_eq!(res, 0);
}

#[cfg(windows)]
{
let res = vm.prog_exec(packet2).unwrap();
let res = vm.execute_program(packet2).unwrap();
println!("Packet #2, program returned: {:?} ({:#x})", res, res);
assert_eq!(res, 0);
}
Expand Down
8 changes: 4 additions & 4 deletions examples/uptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn main() {
// Create a VM: this one takes no data. Load prog1 in it.
let mut vm = rbpf::EbpfVmNoData::new(Some(prog1)).unwrap();
// Execute prog1.
assert_eq!(vm.prog_exec().unwrap(), 0x3);
assert_eq!(vm.execute_program().unwrap(), 0x3);

// As struct EbpfVmNoData does not takes any memory area, its return value is mostly
// deterministic. So we know prog1 will always return 3. There is an exception: when it uses
Expand All @@ -51,7 +51,7 @@ fn main() {
// In the following example we use a helper to get the elapsed time since boot time: we
// reimplement uptime in eBPF, in Rust. Because why not.

vm.set_prog(prog2).unwrap();
vm.set_program(prog2).unwrap();
vm.register_helper(helpers::BPF_KTIME_GETNS_IDX, helpers::bpf_time_getns).unwrap();

let time;
Expand All @@ -60,12 +60,12 @@ fn main() {
{
vm.jit_compile().unwrap();

time = unsafe { vm.prog_exec_jit().unwrap() };
time = unsafe { vm.execute_program_jit().unwrap() };
}

#[cfg(windows)]
{
time = vm.prog_exec().unwrap();
time = vm.execute_program().unwrap();
}

let days = time / 10u64.pow(9) / 60 / 60 / 24;
Expand Down
Loading

0 comments on commit f4bda94

Please sign in to comment.