Skip to content

Commit 0ba8ce6

Browse files
committed
shared-platform: Remove dependency on shared-utils' bh_memory_remap_slow
1 parent 7cac053 commit 0ba8ce6

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

core/shared/platform/common/memory/mremap.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44
*/
55

6-
#include "bh_memutils.h"
6+
#include "platform_api_vmcore.h"
77

88
void *
99
os_mremap(void *old_addr, size_t old_size, size_t new_size)
1010
{
11-
return bh_memory_remap_slow(old_addr, old_size, new_size);
11+
return os_mremap_slow(old_addr, old_size, new_size);
1212
}

core/shared/platform/common/posix/platform_api_posix.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ list (REMOVE_AT CMAKE_REQUIRED_DEFINITIONS 0)
2525

2626
if(MREMAP_EXISTS)
2727
add_definitions (-DWASM_HAVE_MREMAP=1)
28+
add_definitions (-D_GNU_SOURCE)
2829
else()
2930
add_definitions (-DWASM_HAVE_MREMAP=0)
3031
include (${CMAKE_CURRENT_LIST_DIR}/../memory/platform_api_memory.cmake)

core/shared/platform/common/posix/posix_memmap.c

+1-7
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44
*/
55

6-
#if !defined(_GNU_SOURCE) && WASM_HAVE_MREMAP != 0
7-
/* Enable mremap */
8-
#define _GNU_SOURCE
9-
#include "bh_memutils.h"
10-
#endif
11-
126
#include "platform_api_vmcore.h"
137

148
#if defined(__APPLE__) || defined(__MACH__)
@@ -252,7 +246,7 @@ os_mremap(void *old_addr, size_t old_size, size_t new_size)
252246
#if BH_ENABLE_TRACE_MMAP != 0
253247
os_printf("mremap failed: %d\n", errno);
254248
#endif
255-
return bh_memory_remap_slow(old_addr, old_size, new_size);
249+
return os_mremap_slow(old_addr, old_size, new_size);
256250
}
257251

258252
return ptr;

core/shared/platform/include/platform_api_vmcore.h

+18
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,24 @@ os_munmap(void *addr, size_t size);
142142
int
143143
os_mprotect(void *addr, size_t size, int prot);
144144

145+
static inline void *
146+
os_mremap_slow(void *old_addr, size_t old_size, size_t new_size)
147+
{
148+
void *new_memory =
149+
os_mmap(NULL, new_size, MMAP_PROT_WRITE | MMAP_PROT_READ, 0, -1);
150+
if (!new_memory) {
151+
return NULL;
152+
}
153+
/*
154+
* bh_memcpy_s can't be used as it doesn't support values bigger than
155+
* UINT32_MAX
156+
*/
157+
memcpy(new_memory, old_addr, new_size < old_size ? new_size : old_size);
158+
os_munmap(old_addr, old_size);
159+
160+
return new_memory;
161+
}
162+
145163
/* Doesn't guarantee that protection flags will be preserved.
146164
os_mprotect() must be called after remapping. */
147165
void *

core/shared/utils/bh_memutils.c

+1-13
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,5 @@
88
void *
99
bh_memory_remap_slow(void *old_addr, size_t old_size, size_t new_size)
1010
{
11-
void *new_memory =
12-
os_mmap(NULL, new_size, MMAP_PROT_WRITE | MMAP_PROT_READ, 0, -1);
13-
if (!new_memory) {
14-
return NULL;
15-
}
16-
/*
17-
* bh_memcpy_s can't be used as it doesn't support values bigger than
18-
* UINT32_MAX
19-
*/
20-
memcpy(new_memory, old_addr, new_size < old_size ? new_size : old_size);
21-
os_munmap(old_addr, old_size);
22-
23-
return new_memory;
11+
return os_mremap_slow(old_addr, old_size, new_size);
2412
}

0 commit comments

Comments
 (0)