Skip to content

Commit

Permalink
Fix syscalls
Browse files Browse the repository at this point in the history
  • Loading branch information
roblabla committed Mar 30, 2018
1 parent adc3e9a commit 33d2b2f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions shim/src/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ pub unsafe fn brk(ptr: *const u8) -> *const u8 {
let mut base = 0;

// TODO: Cache this information
if ::megaton_hammer::kernel::svc::get_info(&mut base, 4, ::megaton_hammer::kernel::svc::CURRENT_PROCESS, 0) != 0 {
let (res, base) = ::megaton_hammer::kernel::svc::get_info(4, ::megaton_hammer::kernel::svc::CURRENT_PROCESS, 0);

if res != 0 {
return ptr::null();
}

Expand All @@ -88,13 +90,13 @@ pub unsafe fn brk(ptr: *const u8) -> *const u8 {
return (base + HEAP_POS.load(Ordering::Relaxed) as u64) as *mut u8;
}

let mut new_addr = ptr::null_mut();

let mut new_size = (ptr as u64 - base) as u32;

// Align size to 2MB.
let new_size_aligned = if new_size & (0x200000 - 1) == 0 { new_size } else { (new_size + 0x200000) & !(0x200000 - 1) };
if ::megaton_hammer::kernel::svc::set_heap_size(&mut new_addr, new_size_aligned) != 0 {
let (res, new_addr) = ::megaton_hammer::kernel::svc::set_heap_size(new_size_aligned);
if res != 0 {
// Error out. Maybe log something here?
return (base + HEAP_POS.load(Ordering::Relaxed) as u64) as *mut u8;
}
HEAP_POS.store(new_size as usize, Ordering::Relaxed);
Expand Down

0 comments on commit 33d2b2f

Please sign in to comment.