mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
commit
ebc8fd90f3
1 changed files with 6 additions and 1 deletions
|
|
@ -148,6 +148,10 @@ pub unsafe extern "C" fn realloc(
|
||||||
ptr: *mut c_void,
|
ptr: *mut c_void,
|
||||||
size: c_uint
|
size: c_uint
|
||||||
) -> *mut c_void {
|
) -> *mut c_void {
|
||||||
|
if ptr.is_null() {
|
||||||
|
// if ptr is null, realloc() is identical to malloc()
|
||||||
|
return malloc(size);
|
||||||
|
}
|
||||||
let mut region_index: Option<usize> = None;
|
let mut region_index: Option<usize> = None;
|
||||||
for (index, region) in C_HEAP.iter().enumerate() {
|
for (index, region) in C_HEAP.iter().enumerate() {
|
||||||
if region.as_ptr() as usize == ptr as usize {
|
if region.as_ptr() as usize == ptr as usize {
|
||||||
|
|
@ -158,7 +162,7 @@ pub unsafe extern "C" fn realloc(
|
||||||
match region_index {
|
match region_index {
|
||||||
Some(index) => {
|
Some(index) => {
|
||||||
log::info!("realloc/free success: {:x}", ptr as usize);
|
log::info!("realloc/free success: {:x}", ptr as usize);
|
||||||
let mut old = C_HEAP.remove(index);
|
let mut old = C_HEAP.swap_remove(index);
|
||||||
let checked_size = if size == 0 {
|
let checked_size = if size == 0 {
|
||||||
1 // at least 1 element so we have a pointer we can pass back
|
1 // at least 1 element so we have a pointer we can pass back
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -170,6 +174,7 @@ pub unsafe extern "C" fn realloc(
|
||||||
alloc.push(src);
|
alloc.push(src);
|
||||||
}
|
}
|
||||||
old.clear();
|
old.clear();
|
||||||
|
alloc.set_len(checked_size as usize);
|
||||||
C_HEAP.push(alloc);
|
C_HEAP.push(alloc);
|
||||||
log::info!("realloc/allocated: {:x}", ret_ptr as usize);
|
log::info!("realloc/allocated: {:x}", ret_ptr as usize);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue