1234567891011121314151617181920212223242526272829303132 |
- extern crate ralloc;
- use ralloc::sys::{inc_brk, segment_end};
- use std::ptr;
- fn main() {
- let alloc_before = Box::new("hello from the outside.");
- let ptr = unsafe { (segment_end().unwrap() as *const u8).offset(-1) };
- let byte_end = unsafe { ptr::read(ptr) };
- let abc = "abc";
- let mem = *inc_brk(8).unwrap() as *mut u64;
- unsafe {
- *mem = 90823;
- *mem = 2897309273;
- *mem = 293872;
- *mem = 0xDEADBEAFDEADBEAF;
- *mem = 99999;
- assert_eq!(*mem, 99999);
- }
- // Do some heap allocations.
- let bx = Box::new("yo mamma is so nice.");
- assert_eq!(*bx, "yo mamma is so nice.");
- assert_eq!(*alloc_before, "hello from the outside.");
- // Check that the stack frame is unaltered.
- assert_eq!(abc, "abc");
- assert_eq!(byte_end, unsafe { ptr::read(ptr) });
- }
|