Skip to content

Commit 2b28981

Browse files
committed
core/shared/platform: Zero memory returned by os_mmap in some platforms
1 parent cdd95bf commit 2b28981

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

core/shared/platform/alios/alios_platform.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,15 @@ os_dumps_proc_mem_info(char *out, unsigned int size)
4949
void *
5050
os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
5151
{
52-
if ((uint64)size >= UINT32_MAX)
52+
void *addr;
53+
54+
if (size >= UINT32_MAX)
5355
return NULL;
54-
return BH_MALLOC((uint32)size);
56+
57+
if ((addr = BH_MALLOC((uint32)size)))
58+
memset(addr, 0, (uint32)size);
59+
60+
return addr;
5561
}
5662

5763
void

core/shared/platform/esp-idf/espidf_memmap.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
4343
uintptr_t *addr_field = buf_fixed - sizeof(uintptr_t);
4444
*addr_field = (uintptr_t)buf_origin;
4545
#if (WASM_MEM_DUAL_BUS_MIRROR != 0)
46+
memset(buf_fixed + MEM_DUAL_BUS_OFFSET, 0, size);
4647
return buf_fixed + MEM_DUAL_BUS_OFFSET;
4748
#else
49+
memset(buf_fixed, 0, size);
4850
return buf_fixed;
4951
#endif
5052
}
@@ -71,6 +73,7 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
7173
uintptr_t *addr_field = buf_fixed - sizeof(uintptr_t);
7274
*addr_field = (uintptr_t)buf_origin;
7375

76+
memset(buf_fixed, 0, size);
7477
return buf_fixed;
7578
}
7679
}

core/shared/platform/riot/riot_platform.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,15 @@ os_dumps_proc_mem_info(char *out, unsigned int size)
5252
void *
5353
os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
5454
{
55-
if (size > ((unsigned)~0))
55+
void *addr;
56+
57+
if (size >= UINT32_MAX)
5658
return NULL;
57-
return BH_MALLOC((unsigned)size);
59+
60+
if ((addr = BH_MALLOC((uint32)size)))
61+
memset(addr, 0, (uint32)size);
62+
63+
return addr;
5864
}
5965

6066
void *
@@ -88,4 +94,4 @@ os_dcache_flush(void)
8894

8995
void
9096
os_icache_flush(void *start, size_t len)
91-
{}
97+
{}

core/shared/platform/rt-thread/rtt_platform.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,12 @@ os_cond_wait(korp_cond *cond, korp_mutex *mutex)
200200
void *
201201
os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
202202
{
203-
return rt_malloc(size);
203+
void *addr;
204+
205+
if ((addr = rt_malloc(size)))
206+
memset(addr, 0, size);
207+
208+
return addr;
204209
}
205210

206211
void
@@ -221,4 +226,4 @@ os_dcache_flush(void)
221226

222227
void
223228
os_icache_flush(void *start, size_t len)
224-
{}
229+
{}

core/shared/platform/zephyr/zephyr_platform.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,19 @@ strcspn(const char *s, const char *reject)
179179
void *
180180
os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
181181
{
182+
void *addr;
183+
182184
if ((uint64)size >= UINT32_MAX)
183185
return NULL;
186+
184187
if (exec_mem_alloc_func)
185-
return exec_mem_alloc_func((uint32)size);
188+
addr = exec_mem_alloc_func((uint32)size);
186189
else
187-
return BH_MALLOC(size);
190+
addr = BH_MALLOC(size);
191+
192+
if (addr)
193+
memset(addr, 0, size);
194+
return addr;
188195
}
189196

190197
void *

0 commit comments

Comments
 (0)