Skip to content

Commit d62543c

Browse files
authored
Enlarge max pool size and fix bh_memcpy_s dest max size check (#1151)
Enlarge max pool size and fix bh_memcpy_s dest max size check to support large linear memory, e.g. with initial page count 65535.
1 parent a7f4c3c commit d62543c

5 files changed

Lines changed: 10 additions & 19 deletions

File tree

core/iwasm/common/wasm_memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ wasm_runtime_memory_pool_size()
8686
if (memory_mode == MEMORY_MODE_POOL)
8787
return global_pool_size;
8888
else
89-
return 1 * BH_GB;
89+
return UINT32_MAX;
9090
}
9191

9292
static inline void *

core/iwasm/common/wasm_memory.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ wasm_runtime_memory_init(mem_alloc_type_t mem_alloc_type,
2020
void
2121
wasm_runtime_memory_destroy();
2222

23+
unsigned
24+
wasm_runtime_memory_pool_size();
25+
2326
#ifdef __cplusplus
2427
}
2528
#endif

core/iwasm/interpreter/wasm_loader.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "wasm_opcode.h"
1111
#include "wasm_runtime.h"
1212
#include "../common/wasm_native.h"
13+
#include "../common/wasm_memory.h"
1314
#if WASM_ENABLE_DEBUG_INTERP != 0
1415
#include "../libraries/debug-engine/debug_engine.h"
1516
#endif
@@ -1229,9 +1230,6 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end,
12291230
return false;
12301231
}
12311232

1232-
unsigned
1233-
wasm_runtime_memory_pool_size();
1234-
12351233
static bool
12361234
check_memory_init_size(uint32 init_size, char *error_buf, uint32 error_buf_size)
12371235
{

core/iwasm/interpreter/wasm_mini_loader.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "wasm_opcode.h"
1111
#include "wasm_runtime.h"
1212
#include "../common/wasm_native.h"
13+
#include "../common/wasm_memory.h"
1314

1415
/* Read a value of given type from the address pointed to by the given
1516
pointer and increase the pointer to the position just after the
@@ -497,9 +498,6 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end,
497498
return true;
498499
}
499500

500-
unsigned
501-
wasm_runtime_memory_pool_size();
502-
503501
static bool
504502
load_memory_import(const uint8 **p_buf, const uint8 *buf_end,
505503
WASMModule *parent_module, const char *sub_module_name,

core/shared/utils/bh_common.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55

66
#include "bh_common.h"
77

8-
#ifdef RSIZE_MAX
9-
#undef RSIZE_MAX
10-
#endif
11-
12-
#define RSIZE_MAX 0x7FFFFFFF
13-
148
int
159
b_memcpy_s(void *s1, unsigned int s1max, const void *s2, unsigned int n)
1610
{
@@ -20,7 +14,7 @@ b_memcpy_s(void *s1, unsigned int s1max, const void *s2, unsigned int n)
2014
return 0;
2115
}
2216

23-
if (s1 == NULL || s1max > RSIZE_MAX) {
17+
if (s1 == NULL) {
2418
return -1;
2519
}
2620
if (s2 == NULL || n > s1max) {
@@ -40,7 +34,7 @@ b_memmove_s(void *s1, unsigned int s1max, const void *s2, unsigned int n)
4034
return 0;
4135
}
4236

43-
if (s1 == NULL || s1max > RSIZE_MAX) {
37+
if (s1 == NULL) {
4438
return -1;
4539
}
4640
if (s2 == NULL || n > s1max) {
@@ -54,8 +48,7 @@ b_memmove_s(void *s1, unsigned int s1max, const void *s2, unsigned int n)
5448
int
5549
b_strcat_s(char *s1, unsigned int s1max, const char *s2)
5650
{
57-
if (NULL == s1 || NULL == s2 || s1max < (strlen(s1) + strlen(s2) + 1)
58-
|| s1max > RSIZE_MAX) {
51+
if (NULL == s1 || NULL == s2 || s1max < (strlen(s1) + strlen(s2) + 1)) {
5952
return -1;
6053
}
6154

@@ -66,8 +59,7 @@ b_strcat_s(char *s1, unsigned int s1max, const char *s2)
6659
int
6760
b_strcpy_s(char *s1, unsigned int s1max, const char *s2)
6861
{
69-
if (NULL == s1 || NULL == s2 || s1max < (strlen(s2) + 1)
70-
|| s1max > RSIZE_MAX) {
62+
if (NULL == s1 || NULL == s2 || s1max < (strlen(s2) + 1)) {
7163
return -1;
7264
}
7365

0 commit comments

Comments
 (0)