Revert "native,platform: use malloc/free for temporary memory"

This reverts commit 9249c3fb60.

* defining __NATIVE_USE_KLIB__ will link malloc() to the klib version,
  which may cause errors
This commit is contained in:
Zihao Yu 2020-02-06 23:16:10 +08:00
parent b5db2daab5
commit e670d1f2ca
1 changed files with 5 additions and 3 deletions

View File

@ -54,8 +54,8 @@ static void init_platform() {
uintptr_t pad = (uintptr_t)vaddr & 0xfff;
void *vaddr_align = vaddr - pad;
uintptr_t size = phdr[i].p_memsz + pad;
void *temp_mem = malloc(size);
assert(temp_mem != NULL);
void *temp_mem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
assert(temp_mem != (void *)-1);
// save data and bss sections
memcpy(temp_mem, vaddr_align, size);
@ -77,7 +77,9 @@ static void init_platform() {
// restore the data in the sections
memcpy_libc(vaddr_align, temp_mem, size);
free(temp_mem);
// unmap the temporary memory
ret2 = munmap(temp_mem, size);
assert(ret2 == 0);
}
}