|
@@ -56,7 +56,7 @@ pub mod ebpf;
|
|
pub mod helpers;
|
|
pub mod helpers;
|
|
pub mod insn_builder;
|
|
pub mod insn_builder;
|
|
mod interpreter;
|
|
mod interpreter;
|
|
-#[cfg(not(windows))]
|
|
|
|
|
|
+#[cfg(all(not(windows), feature = "std"))]
|
|
mod jit;
|
|
mod jit;
|
|
mod verifier;
|
|
mod verifier;
|
|
|
|
|
|
@@ -118,7 +118,7 @@ struct MetaBuff {
|
|
pub struct EbpfVmMbuff<'a> {
|
|
pub struct EbpfVmMbuff<'a> {
|
|
prog: Option<&'a [u8]>,
|
|
prog: Option<&'a [u8]>,
|
|
verifier: Verifier,
|
|
verifier: Verifier,
|
|
- #[cfg(not(windows))]
|
|
|
|
|
|
+ #[cfg(all(not(windows), feature = "std"))]
|
|
jit: Option<jit::JitMemory<'a>>,
|
|
jit: Option<jit::JitMemory<'a>>,
|
|
#[cfg(feature = "cranelift")]
|
|
#[cfg(feature = "cranelift")]
|
|
cranelift_prog: Option<cranelift::CraneliftProgram>,
|
|
cranelift_prog: Option<cranelift::CraneliftProgram>,
|
|
@@ -149,7 +149,7 @@ impl<'a> EbpfVmMbuff<'a> {
|
|
Ok(EbpfVmMbuff {
|
|
Ok(EbpfVmMbuff {
|
|
prog,
|
|
prog,
|
|
verifier: verifier::check,
|
|
verifier: verifier::check,
|
|
- #[cfg(not(windows))]
|
|
|
|
|
|
+ #[cfg(all(not(windows), feature = "std"))]
|
|
jit: None,
|
|
jit: None,
|
|
#[cfg(feature = "cranelift")]
|
|
#[cfg(feature = "cranelift")]
|
|
cranelift_prog: None,
|
|
cranelift_prog: None,
|
|
@@ -319,7 +319,7 @@ impl<'a> EbpfVmMbuff<'a> {
|
|
///
|
|
///
|
|
/// vm.jit_compile();
|
|
/// vm.jit_compile();
|
|
/// ```
|
|
/// ```
|
|
- #[cfg(not(windows))]
|
|
|
|
|
|
+ #[cfg(all(not(windows), feature = "std"))]
|
|
pub fn jit_compile(&mut self) -> Result<(), Error> {
|
|
pub fn jit_compile(&mut self) -> Result<(), Error> {
|
|
let prog = match self.prog {
|
|
let prog = match self.prog {
|
|
Some(prog) => prog,
|
|
Some(prog) => prog,
|
|
@@ -374,17 +374,17 @@ impl<'a> EbpfVmMbuff<'a> {
|
|
/// // Instantiate a VM.
|
|
/// // Instantiate a VM.
|
|
/// let mut vm = rbpf::EbpfVmMbuff::new(Some(prog)).unwrap();
|
|
/// let mut vm = rbpf::EbpfVmMbuff::new(Some(prog)).unwrap();
|
|
///
|
|
///
|
|
- /// # #[cfg(not(windows))]
|
|
|
|
|
|
+ /// # #[cfg(all(not(windows), feature = "std"))]
|
|
/// vm.jit_compile();
|
|
/// vm.jit_compile();
|
|
///
|
|
///
|
|
/// // Provide both a reference to the packet data, and to the metadata buffer.
|
|
/// // Provide both a reference to the packet data, and to the metadata buffer.
|
|
- /// # #[cfg(not(windows))]
|
|
|
|
|
|
+ /// # #[cfg(all(not(windows), feature = "std"))]
|
|
/// unsafe {
|
|
/// unsafe {
|
|
/// let res = vm.execute_program_jit(mem, &mut mbuff).unwrap();
|
|
/// let res = vm.execute_program_jit(mem, &mut mbuff).unwrap();
|
|
/// assert_eq!(res, 0x2211);
|
|
/// assert_eq!(res, 0x2211);
|
|
/// }
|
|
/// }
|
|
/// ```
|
|
/// ```
|
|
- #[cfg(not(windows))]
|
|
|
|
|
|
+ #[cfg(all(not(windows), feature = "std"))]
|
|
pub unsafe fn execute_program_jit(
|
|
pub unsafe fn execute_program_jit(
|
|
&self,
|
|
&self,
|
|
mem: &mut [u8],
|
|
mem: &mut [u8],
|
|
@@ -835,7 +835,7 @@ impl<'a> EbpfVmFixedMbuff<'a> {
|
|
///
|
|
///
|
|
/// vm.jit_compile();
|
|
/// vm.jit_compile();
|
|
/// ```
|
|
/// ```
|
|
- #[cfg(not(windows))]
|
|
|
|
|
|
+ #[cfg(all(not(windows), feature = "std"))]
|
|
pub fn jit_compile(&mut self) -> Result<(), Error> {
|
|
pub fn jit_compile(&mut self) -> Result<(), Error> {
|
|
let prog = match self.parent.prog {
|
|
let prog = match self.parent.prog {
|
|
Some(prog) => prog,
|
|
Some(prog) => prog,
|
|
@@ -884,11 +884,11 @@ impl<'a> EbpfVmFixedMbuff<'a> {
|
|
/// // Instantiate a VM. Note that we provide the start and end offsets for mem pointers.
|
|
/// // Instantiate a VM. Note that we provide the start and end offsets for mem pointers.
|
|
/// let mut vm = rbpf::EbpfVmFixedMbuff::new(Some(prog), 0x40, 0x50).unwrap();
|
|
/// let mut vm = rbpf::EbpfVmFixedMbuff::new(Some(prog), 0x40, 0x50).unwrap();
|
|
///
|
|
///
|
|
- /// # #[cfg(not(windows))]
|
|
|
|
|
|
+ /// # #[cfg(all(not(windows), feature = "std"))]
|
|
/// vm.jit_compile();
|
|
/// vm.jit_compile();
|
|
///
|
|
///
|
|
/// // Provide only a reference to the packet data. We do not manage the metadata buffer.
|
|
/// // Provide only a reference to the packet data. We do not manage the metadata buffer.
|
|
- /// # #[cfg(not(windows))]
|
|
|
|
|
|
+ /// # #[cfg(all(not(windows), feature = "std"))]
|
|
/// unsafe {
|
|
/// unsafe {
|
|
/// let res = vm.execute_program_jit(mem).unwrap();
|
|
/// let res = vm.execute_program_jit(mem).unwrap();
|
|
/// assert_eq!(res, 0xdd);
|
|
/// assert_eq!(res, 0xdd);
|
|
@@ -896,7 +896,7 @@ impl<'a> EbpfVmFixedMbuff<'a> {
|
|
/// ```
|
|
/// ```
|
|
// This struct redefines the `execute_program_jit()` function, in order to pass the offsets
|
|
// This struct redefines the `execute_program_jit()` function, in order to pass the offsets
|
|
// associated with the fixed mbuff.
|
|
// associated with the fixed mbuff.
|
|
- #[cfg(not(windows))]
|
|
|
|
|
|
+ #[cfg(all(not(windows), feature = "std"))]
|
|
pub unsafe fn execute_program_jit(&mut self, mem: &'a mut [u8]) -> Result<u64, Error> {
|
|
pub unsafe fn execute_program_jit(&mut self, mem: &'a mut [u8]) -> Result<u64, Error> {
|
|
// If packet data is empty, do not send the address of an empty slice; send a null pointer
|
|
// If packet data is empty, do not send the address of an empty slice; send a null pointer
|
|
// as first argument instead, as this is uBPF's behavior (empty packet should not happen
|
|
// as first argument instead, as this is uBPF's behavior (empty packet should not happen
|
|
@@ -1240,7 +1240,7 @@ impl<'a> EbpfVmRaw<'a> {
|
|
///
|
|
///
|
|
/// vm.jit_compile();
|
|
/// vm.jit_compile();
|
|
/// ```
|
|
/// ```
|
|
- #[cfg(not(windows))]
|
|
|
|
|
|
+ #[cfg(all(not(windows), feature = "std"))]
|
|
pub fn jit_compile(&mut self) -> Result<(), Error> {
|
|
pub fn jit_compile(&mut self) -> Result<(), Error> {
|
|
let prog = match self.parent.prog {
|
|
let prog = match self.parent.prog {
|
|
Some(prog) => prog,
|
|
Some(prog) => prog,
|
|
@@ -1286,16 +1286,16 @@ impl<'a> EbpfVmRaw<'a> {
|
|
///
|
|
///
|
|
/// let mut vm = rbpf::EbpfVmRaw::new(Some(prog)).unwrap();
|
|
/// let mut vm = rbpf::EbpfVmRaw::new(Some(prog)).unwrap();
|
|
///
|
|
///
|
|
- /// # #[cfg(not(windows))]
|
|
|
|
|
|
+ /// # #[cfg(all(not(windows), feature = "std"))]
|
|
/// vm.jit_compile();
|
|
/// vm.jit_compile();
|
|
///
|
|
///
|
|
- /// # #[cfg(not(windows))]
|
|
|
|
|
|
+ /// # #[cfg(all(not(windows), feature = "std"))]
|
|
/// unsafe {
|
|
/// unsafe {
|
|
/// let res = vm.execute_program_jit(mem).unwrap();
|
|
/// let res = vm.execute_program_jit(mem).unwrap();
|
|
/// assert_eq!(res, 0x22cc);
|
|
/// assert_eq!(res, 0x22cc);
|
|
/// }
|
|
/// }
|
|
/// ```
|
|
/// ```
|
|
- #[cfg(not(windows))]
|
|
|
|
|
|
+ #[cfg(all(not(windows), feature = "std"))]
|
|
pub unsafe fn execute_program_jit(&self, mem: &'a mut [u8]) -> Result<u64, Error> {
|
|
pub unsafe fn execute_program_jit(&self, mem: &'a mut [u8]) -> Result<u64, Error> {
|
|
let mut mbuff = vec![];
|
|
let mut mbuff = vec![];
|
|
self.parent.execute_program_jit(mem, &mut mbuff)
|
|
self.parent.execute_program_jit(mem, &mut mbuff)
|
|
@@ -1555,7 +1555,7 @@ impl<'a> EbpfVmNoData<'a> {
|
|
///
|
|
///
|
|
/// vm.jit_compile();
|
|
/// vm.jit_compile();
|
|
/// ```
|
|
/// ```
|
|
- #[cfg(not(windows))]
|
|
|
|
|
|
+ #[cfg(all(not(windows), feature = "std"))]
|
|
pub fn jit_compile(&mut self) -> Result<(), Error> {
|
|
pub fn jit_compile(&mut self) -> Result<(), Error> {
|
|
self.parent.jit_compile()
|
|
self.parent.jit_compile()
|
|
}
|
|
}
|
|
@@ -1604,16 +1604,16 @@ impl<'a> EbpfVmNoData<'a> {
|
|
///
|
|
///
|
|
/// let mut vm = rbpf::EbpfVmNoData::new(Some(prog)).unwrap();
|
|
/// let mut vm = rbpf::EbpfVmNoData::new(Some(prog)).unwrap();
|
|
///
|
|
///
|
|
- /// # #[cfg(not(windows))]
|
|
|
|
|
|
+ /// # #[cfg(all(not(windows), feature = "std"))]
|
|
/// vm.jit_compile();
|
|
/// vm.jit_compile();
|
|
///
|
|
///
|
|
- /// # #[cfg(not(windows))]
|
|
|
|
|
|
+ /// # #[cfg(all(not(windows), feature = "std"))]
|
|
/// unsafe {
|
|
/// unsafe {
|
|
/// let res = vm.execute_program_jit().unwrap();
|
|
/// let res = vm.execute_program_jit().unwrap();
|
|
/// assert_eq!(res, 0x1122);
|
|
/// assert_eq!(res, 0x1122);
|
|
/// }
|
|
/// }
|
|
/// ```
|
|
/// ```
|
|
- #[cfg(not(windows))]
|
|
|
|
|
|
+ #[cfg(all(not(windows), feature = "std"))]
|
|
pub unsafe fn execute_program_jit(&self) -> Result<u64, Error> {
|
|
pub unsafe fn execute_program_jit(&self) -> Result<u64, Error> {
|
|
self.parent.execute_program_jit(&mut [])
|
|
self.parent.execute_program_jit(&mut [])
|
|
}
|
|
}
|