shared-platform: Remove dependency on shared-utils' bh_memory_remap_slow (#3153)
As an original design rule, the code in `core/shared/platform` should not rely on the code in `core/share/utils`. In the current implementation, platform layer calls function `bh_memory_remap_slow` in utils layer. This PR adds inline function `os_mremap_slow` in platform_api_vmcore.h, and lets os_remap call it if mremap fails. And remove bh_memutils.h/c as as they are unused. And resolve the compilation warning in wamrc: ```bash core/shared/platform/common/posix/posix_memmap.c:255:16: warning: implicit declaration of function ‘bh_memory_remap_slow’ 255 | return bh_memory_remap_slow(old_addr, old_size, new_size); ```
This commit is contained in:
@ -142,6 +142,24 @@ os_munmap(void *addr, size_t size);
|
||||
int
|
||||
os_mprotect(void *addr, size_t size, int prot);
|
||||
|
||||
static inline void *
|
||||
os_mremap_slow(void *old_addr, size_t old_size, size_t new_size)
|
||||
{
|
||||
void *new_memory = os_mmap(NULL, new_size, MMAP_PROT_WRITE | MMAP_PROT_READ,
|
||||
0, os_get_invalid_handle());
|
||||
if (!new_memory) {
|
||||
return NULL;
|
||||
}
|
||||
/*
|
||||
* bh_memcpy_s can't be used as it doesn't support values bigger than
|
||||
* UINT32_MAX
|
||||
*/
|
||||
memcpy(new_memory, old_addr, new_size < old_size ? new_size : old_size);
|
||||
os_munmap(old_addr, old_size);
|
||||
|
||||
return new_memory;
|
||||
}
|
||||
|
||||
/* Doesn't guarantee that protection flags will be preserved.
|
||||
os_mprotect() must be called after remapping. */
|
||||
void *
|
||||
|
||||
Reference in New Issue
Block a user