Skip to content

Commit 18876d2

Browse files
committed
Add wrapper for mremap
1 parent 7e46b95 commit 18876d2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/sys/mman.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,27 @@ pub unsafe fn mmap(addr: *mut c_void, length: size_t, prot: ProtFlags, flags: Ma
315315
}
316316
}
317317

318+
/// Expands (or shrinks) an existing memory mapping, potentially moving it at the same time.
319+
///
320+
/// # Safety
321+
///
322+
/// See the `mremap(2)` man page for detailed requirements.
323+
pub unsafe fn mremap(
324+
addr: *mut c_void,
325+
old_size: size_t,
326+
new_size: size_t,
327+
flags: MapFlags,
328+
new_address: size_t,
329+
) -> Result<*mut c_void> {
330+
let ret = libc::mremap(addr, old_size, new_size, flags.bits(), new_address);
331+
332+
if ret == libc::MAP_FAILED {
333+
Err(Error::Sys(Errno::last()))
334+
} else {
335+
Ok(ret)
336+
}
337+
}
338+
318339
/// remove a mapping
319340
///
320341
/// # Safety

0 commit comments

Comments
 (0)