baremetal: provide os_mmap/os_mremap for wamr aot_load_from_aot_file
This commit is contained in:
@ -92,16 +92,67 @@ bh_log_proc_mem(const char *function, uint32 line)
|
||||
* mman
|
||||
****************************************************/
|
||||
|
||||
// NOTE: We need os_mmap for aot_load_from_aot_file
|
||||
//
|
||||
// Stacktrace:
|
||||
// #5 0x0805e5c1 in os_mmap
|
||||
// #6 0x080524d3 in loader_mmap
|
||||
// #7 0x08059294 in create_sections
|
||||
// #8 0x08059553 in load
|
||||
// #9 0x0805966b in aot_load_from_aot_file
|
||||
// #10 0x08048c34 in wasm_runtime_load_ex
|
||||
// #11 0x08048cff in wasm_runtime_load
|
||||
// #12 0x08048112 in main
|
||||
|
||||
#define MMAP_SPACE_SIZE (2 * 1024 * 1024)
|
||||
static uint8_t mmap_space[MMAP_SPACE_SIZE];
|
||||
static size_t mmap_offset = 0; // Free space begins here
|
||||
|
||||
static size_t
|
||||
align_up(size_t x, size_t a)
|
||||
{
|
||||
// a is a power of two, e.g., 8:
|
||||
// x+a-1: Shift value upwards to the next alignment "bucket"
|
||||
// a-1: 00000111, ~(a-1): 11111000 - Clears the lower bits/alignment
|
||||
// remainder
|
||||
return (x + a - 1) & ~(a - 1);
|
||||
}
|
||||
|
||||
void *
|
||||
os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
|
||||
{
|
||||
return NULL;
|
||||
// Free space begins here (aligned)
|
||||
size_t start = align_up(mmap_offset, PAGE_SIZE);
|
||||
|
||||
// How much we're mapping
|
||||
size_T end = start + align_up(size, PAGE_SIZE);
|
||||
|
||||
if (end > MMAP_SPACE_SIZE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *ptr = &mmap_space[start];
|
||||
mmap_offset = end;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *
|
||||
os_mremap(void *old_addr, size_t old_size, size_t new_size)
|
||||
{
|
||||
return NULL;
|
||||
// Map the new size
|
||||
void *new_addr = os_mmap(NULL, new_size, 0, 0, -1);
|
||||
if (!new_addr) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Copy the old memory to the new mapped address
|
||||
if (old_addr) {
|
||||
size_t copy_size = old_size < new_size ? old_size : new_size;
|
||||
memcpy(new_addr, old_addr, copy_size);
|
||||
}
|
||||
|
||||
return new_addr;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@ -74,11 +74,12 @@ os_get_invalid_handle(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
static inline int
|
||||
os_getpagesize()
|
||||
{
|
||||
// TODO: What pagesize? 65536?
|
||||
return 4096;
|
||||
return PAGE_SIZE;
|
||||
}
|
||||
|
||||
// void *
|
||||
|
||||
Reference in New Issue
Block a user