Skip to content

Commit

Permalink
Implement runtime::brk.
Browse files Browse the repository at this point in the history
`brk` is used by some `malloc` implementations.
  • Loading branch information
sunfishcode committed Oct 22, 2023
1 parent 414309a commit a80d62d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/backend/linux_raw/runtime/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,9 @@ unsafe fn sigtimedwait_old(
pub(crate) fn exit_group(code: c::c_int) -> ! {
unsafe { syscall_noreturn!(__NR_exit_group, c_int(code)) }
}

#[inline]
pub(crate) unsafe fn brk(addr: *mut c::c_void) -> io::Result<()> {
// Don't mark this `readonly`, so that loads don't get reordered past it.
ret(syscall!(__NR_brk, addr))
}
11 changes: 11 additions & 0 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,14 @@ pub unsafe fn sigtimedwait(set: &Sigset, timeout: Option<Timespec>) -> io::Resul
pub fn linux_secure() -> bool {
backend::param::auxv::linux_secure()
}

/// `brk(addr)`—Change the location of the “program break”.
///
/// # Safety
///
/// Be a good sport and don't break the allocator.
#[cfg(linux_raw)]
#[inline]
pub unsafe fn brk(addr: *mut c_void) -> io::Result<()> {
backend::runtime::syscalls::brk(addr)
}

0 comments on commit a80d62d

Please sign in to comment.