Enhance XIP and add XIP document (#863)
Auto detect whether file is XIP file before loading module in posix like and linux-sgx platforms, and if yes, mmap executable memory automatically to run the XIP file. Add document about XIP feature. Enable test spec cases with XIP feature.
This commit is contained in:
@ -2190,6 +2190,8 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
|
||||
|| !strcmp(group->section_name, ".text")
|
||||
#endif
|
||||
) {
|
||||
#if !defined(BH_PLATFORM_LINUX) && !defined(BH_PLATFORM_LINUX_SGX) \
|
||||
&& !defined(BH_PLATFORM_DARWIN)
|
||||
if (module->native_symbol_count > 0) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"cannot apply relocation to text section "
|
||||
@ -2197,6 +2199,7 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
|
||||
"\"--enable-indirect-mode\" flag");
|
||||
goto fail;
|
||||
}
|
||||
#endif
|
||||
if (!do_text_relocation(module, group, error_buf, error_buf_size))
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -294,6 +294,64 @@ get_package_type(const uint8 *buf, uint32 size)
|
||||
return Package_Type_Unknown;
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_AOT != 0
|
||||
static uint8 *
|
||||
align_ptr(const uint8 *p, uint32 b)
|
||||
{
|
||||
uintptr_t v = (uintptr_t)p;
|
||||
uintptr_t m = b - 1;
|
||||
return (uint8 *)((v + m) & ~m);
|
||||
}
|
||||
|
||||
#define CHECK_BUF(buf, buf_end, length) \
|
||||
do { \
|
||||
if (buf + length < buf || buf + length > buf_end) \
|
||||
return false; \
|
||||
} while (0)
|
||||
|
||||
#define read_uint32(p, p_end, res) \
|
||||
do { \
|
||||
p = (uint8 *)align_ptr(p, sizeof(uint32)); \
|
||||
CHECK_BUF(p, p_end, sizeof(uint32)); \
|
||||
res = *(uint32 *)p; \
|
||||
p += sizeof(uint32); \
|
||||
} while (0)
|
||||
|
||||
bool
|
||||
wasm_runtime_is_xip_file(const uint8 *buf, uint32 size)
|
||||
{
|
||||
const uint8 *p = buf, *p_end = buf + size;
|
||||
uint32 section_type, sub_section_type, section_size;
|
||||
|
||||
if (get_package_type(buf, size) != Wasm_Module_AoT)
|
||||
return false;
|
||||
|
||||
CHECK_BUF(p, p_end, 8);
|
||||
p += 8;
|
||||
while (p < p_end) {
|
||||
read_uint32(p, p_end, section_type);
|
||||
read_uint32(p, p_end, section_size);
|
||||
CHECK_BUF(p, p_end, section_size);
|
||||
|
||||
if (section_type == AOT_SECTION_TYPE_CUSTOM) {
|
||||
read_uint32(p, p_end, sub_section_type);
|
||||
if (sub_section_type == AOT_CUSTOM_SECTION_NATIVE_SYMBOL) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
p -= sizeof(uint32);
|
||||
}
|
||||
}
|
||||
else if (section_type >= AOT_SECTION_TYPE_SIGANATURE) {
|
||||
return false;
|
||||
}
|
||||
p += section_size;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif /* end of WASM_ENABLE_AOT */
|
||||
|
||||
#if (WASM_ENABLE_THREAD_MGR != 0) && (WASM_ENABLE_DEBUG_INTERP != 0)
|
||||
uint32
|
||||
wasm_runtime_start_debug_instance(WASMExecEnv *exec_env)
|
||||
|
||||
@ -406,6 +406,10 @@ wasm_runtime_destroy(void);
|
||||
WASM_RUNTIME_API_EXTERN PackageType
|
||||
get_package_type(const uint8 *buf, uint32 size);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN bool
|
||||
wasm_runtime_is_xip_file(const uint8 *buf, uint32 size);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN WASMModuleCommon *
|
||||
wasm_runtime_load(const uint8 *buf, uint32 size, char *error_buf,
|
||||
|
||||
@ -235,6 +235,17 @@ wasm_runtime_free(void *ptr);
|
||||
WASM_RUNTIME_API_EXTERN package_type_t
|
||||
get_package_type(const uint8_t *buf, uint32_t size);
|
||||
|
||||
/**
|
||||
* Check whether a file is an AOT XIP (Execution In Place) file
|
||||
*
|
||||
* @param buf the package buffer
|
||||
* @param size the package buffer size
|
||||
*
|
||||
* @return true if success, false otherwise
|
||||
*/
|
||||
WASM_RUNTIME_API_EXTERN bool
|
||||
wasm_runtime_is_xip_file(const uint8_t *buf, uint32_t size);
|
||||
|
||||
/**
|
||||
* It is a callback for WAMR providing by embedding to load a module file
|
||||
* into a buffer
|
||||
|
||||
Reference in New Issue
Block a user