mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-07-12 15:33:16 +00:00
Compare commits
3 Commits
ad83b04316
...
b763451c99
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b763451c99 | ||
![]() |
1c9d5a523f | ||
![]() |
5757905698 |
|
@ -883,6 +883,12 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
|
|||
}
|
||||
#endif /* end of WASM_MEM_ALLOC_WITH_USAGE */
|
||||
|
||||
/*
|
||||
* AOT compiler assumes at least 8 byte alignment.
|
||||
* see aot_check_memory_overflow.
|
||||
*/
|
||||
bh_assert(((uintptr_t)memory->memory_data & 0x7) == 0);
|
||||
|
||||
memory->num_bytes_per_page = num_bytes_per_page;
|
||||
memory->cur_page_count = total_page_count;
|
||||
memory->max_page_count = max_page_count;
|
||||
|
@ -1032,5 +1038,11 @@ wasm_allocate_linear_memory(uint8 **data, bool is_shared_memory,
|
|||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* AOT compiler assumes at least 8 byte alignment.
|
||||
* see aot_check_memory_overflow.
|
||||
*/
|
||||
bh_assert(((uintptr_t)*data & 0x7) == 0);
|
||||
|
||||
return BHT_OK;
|
||||
}
|
||||
|
|
|
@ -181,6 +181,26 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|||
comp_ctx->comp_data->memories[0].init_page_count;
|
||||
uint64 mem_data_size = (uint64)num_bytes_per_page * init_page_count;
|
||||
|
||||
if (alignp != NULL) {
|
||||
/*
|
||||
* A note about max_align below:
|
||||
* the assumption here is the base address of a linear memory
|
||||
* has the natural alignment. for platforms using mmap, it can
|
||||
* be even larger. for now, use a conservative value.
|
||||
*/
|
||||
const int max_align = 8;
|
||||
int shift = ffs((int)(unsigned int)mem_offset);
|
||||
if (shift == 0) {
|
||||
*alignp = max_align;
|
||||
}
|
||||
else {
|
||||
unsigned int align = 1 << (shift - 1);
|
||||
if (align > max_align) {
|
||||
align = max_align;
|
||||
}
|
||||
*alignp = align;
|
||||
}
|
||||
}
|
||||
if (mem_offset + bytes <= mem_data_size) {
|
||||
/* inside memory space */
|
||||
if (comp_ctx->pointer_size == sizeof(uint64))
|
||||
|
@ -203,30 +223,10 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|||
goto fail;
|
||||
}
|
||||
}
|
||||
if (alignp != NULL) {
|
||||
/*
|
||||
* A note about max_align below:
|
||||
* the assumption here is the base address of a linear memory
|
||||
* has the natural alignment. for platforms using mmap, it can
|
||||
* be even larger. for now, use a conservative value.
|
||||
*/
|
||||
const int max_align = 4;
|
||||
int shift = ffs((int)(unsigned int)mem_offset);
|
||||
if (shift == 0) {
|
||||
*alignp = max_align;
|
||||
}
|
||||
else {
|
||||
unsigned int align = 1 << (shift - 1);
|
||||
if (align > max_align) {
|
||||
align = max_align;
|
||||
}
|
||||
*alignp = align;
|
||||
}
|
||||
}
|
||||
return maddr;
|
||||
}
|
||||
}
|
||||
if (alignp != NULL) {
|
||||
else if (alignp != NULL) {
|
||||
*alignp = 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user