API to handle custom sections. Fix #284

pull/296/head
Vova 3 years ago
parent 5deaf9306f
commit 4916bc2065

@ -27,7 +27,7 @@ M3Result m3_LinkWASI (IM3Module io_module);
#if defined(d_m3HasUVWASI)
M3Result m3_LinkWASIWithOptions (IM3Module io_module, uvwasi_options_t uvwasiOptions);
M3Result m3_LinkWASIWithOptions (IM3Module io_module, uvwasi_options_t uvwasiOptions);
#endif

@ -80,6 +80,12 @@ void m3_FreeEnvironment (IM3Environment i_environment)
}
void m3_SetCustomSectionHandler (IM3Environment i_environment, M3SectionHandler i_handler)
{
if (i_environment) i_environment->customSectionHandler = i_handler;
}
// returns the same io_funcType or replaces it with an equivalent that's already in the type linked list
void Environment_AddFuncType (IM3Environment i_environment, IM3FuncType * io_funcType)
{
@ -747,7 +753,7 @@ M3Result checkStartFunction(IM3Module i_module)
{
result = m3_RunStart (i_module);
}
return result;
}

@ -138,6 +138,8 @@ typedef struct M3Environment
IM3FuncType retFuncTypes [c_m3Type_unknown]; // these 'point' to elements in the linked list above.
// the number of elements must match the basic types as per M3ValueType
M3CodePage * pagesReleased;
M3SectionHandler customSectionHandler;
}
M3Environment;

@ -476,17 +476,11 @@ _ (Parse_InitExpr (io_module, & i_bytes, i_end));
}
M3Result ParseSection_Custom (M3Module * io_module, bytes_t i_bytes, cbytes_t i_end)
M3Result ParseSection_Name (M3Module * io_module, bytes_t i_bytes, cbytes_t i_end)
{
M3Result result;
cstr_t name;
_ (Read_utf8 (& name, & i_bytes, i_end));
m3log (parse, "** Custom: '%s'", name);
if (strcmp (name, "name") != 0)
i_bytes = i_end;
m3_Free (name);
while (i_bytes < i_end)
{
@ -533,6 +527,25 @@ _ (Read_utf8 (& name, & i_bytes, i_end));
}
M3Result ParseSection_Custom (M3Module * io_module, bytes_t i_bytes, cbytes_t i_end)
{
M3Result result;
cstr_t name;
_ (Read_utf8 (& name, & i_bytes, i_end));
m3log (parse, "** Custom: '%s'", name);
if (strcmp (name, "name") == 0) {
_ (ParseSection_Name(io_module, i_bytes, i_end));
} else if (io_module->environment->customSectionHandler) {
_ (io_module->environment->customSectionHandler(io_module, name, i_bytes, i_end));
}
m3_Free (name);
_catch: return result;
}
M3Result ParseModuleSection (M3Module * o_module, u8 i_sectionType, bytes_t i_bytes, u32 i_numBytes)
{
M3Result result = m3Err_none;

@ -190,6 +190,11 @@ d_m3ErrorConst (trapStackOverflow, "[trap] stack overflow")
void m3_FreeEnvironment (IM3Environment i_environment);
typedef M3Result (* M3SectionHandler) (IM3Module i_module, const char* name, const uint8_t * start, const uint8_t * end);
void m3_SetCustomSectionHandler (IM3Environment i_environment, M3SectionHandler i_handler);
//-------------------------------------------------------------------------------------------------------------------------------
// execution context
//-------------------------------------------------------------------------------------------------------------------------------

Loading…
Cancel
Save