1#![warn(missing_docs)]
14#![allow(clippy::literal_string_with_formatting_args)]
15#![deny(clippy::arithmetic_side_effects)]
16#![deny(clippy::ptr_as_ptr)]
17
18extern crate byteorder;
19extern crate combine;
20extern crate hash32;
21extern crate log;
22extern crate rand;
23extern crate thiserror;
24
25pub mod aligned_memory;
26mod asm_parser;
27pub mod assembler;
28#[cfg(feature = "debugger")]
29pub mod debugger;
30pub mod disassembler;
31pub mod ebpf;
32pub mod elf;
33pub mod elf_parser;
34pub mod error;
35pub mod insn_builder;
36pub mod interpreter;
37#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
38pub mod jit;
39#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
40mod memory_management;
41pub mod memory_region;
42pub mod program;
43pub mod static_analysis;
44pub mod verifier;
45pub mod vm;
46#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
47mod x86;
48
49trait ErrCheckedArithmetic: Sized {
50 fn err_checked_add(self, other: Self) -> Result<Self, ArithmeticOverflow>;
51 fn err_checked_sub(self, other: Self) -> Result<Self, ArithmeticOverflow>;
52 fn err_checked_mul(self, other: Self) -> Result<Self, ArithmeticOverflow>;
53 #[allow(dead_code)]
54 fn err_checked_div(self, other: Self) -> Result<Self, ArithmeticOverflow>;
55}
56struct ArithmeticOverflow;
57
58macro_rules! impl_err_checked_arithmetic {
59 ($($ty:ty),*) => {
60 $(
61 impl ErrCheckedArithmetic for $ty {
62 fn err_checked_add(self, other: $ty) -> Result<Self, ArithmeticOverflow> {
63 self.checked_add(other).ok_or(ArithmeticOverflow)
64 }
65
66 fn err_checked_sub(self, other: $ty) -> Result<Self, ArithmeticOverflow> {
67 self.checked_sub(other).ok_or(ArithmeticOverflow)
68 }
69
70 fn err_checked_mul(self, other: $ty) -> Result<Self, ArithmeticOverflow> {
71 self.checked_mul(other).ok_or(ArithmeticOverflow)
72 }
73
74 fn err_checked_div(self, other: $ty) -> Result<Self, ArithmeticOverflow> {
75 self.checked_div(other).ok_or(ArithmeticOverflow)
76 }
77 }
78 )*
79 }
80}
81
82impl_err_checked_arithmetic!(i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize);