diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..ebf3274 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,58 @@ +use std::cell::RefCell; +use libc::malloc; + +pub mod error; +pub mod parse; + +#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] +pub struct PissAmount { + to_piss: u128 +} + +#[derive(Copy, Clone, Debug)] +pub enum Toliet { + Rust, + Lazy, + Unsafe +} + +fn leak_rust(amount: usize) { + Vec::<u8>::with_capacity(amount).leak(); +} + +thread_local!(static TOLIET: RefCell<Vec<Vec<u8>>> = RefCell::new(Vec::new())); + +fn leak_lazy(amount: usize) { + TOLIET.with(|t| { + t.borrow_mut().push(Vec::<u8>::with_capacity(amount)); + }) +} + +fn leak_unsafe(amount: usize) { + unsafe { + malloc(amount); + } +} + +fn leak_match(amount: usize, method: Toliet) { + match method { + Toliet::Rust => leak_rust(amount), + Toliet::Lazy => leak_lazy(amount), + Toliet::Unsafe => leak_unsafe(amount), + } +} + +pub fn leak<T: Into<PissAmount>>(amount: T, method: Toliet) { + let num: u128 = amount.into().to_piss; + let count = num / usize::MAX as u128; + + for _ in 0..count { + leak_match(usize::MAX, method); + } + + leak_match((num % usize::MAX as u128) as usize, method); +} + +pub async fn leak_async<T: Into<PissAmount>>(amount: T, method: Toliet) { + leak(amount, method); +} |