1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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);
}
|