mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
LibWasm: Follow the updated spec on instantiation
The spec now permits access to all globals for all segment initializers, as well as previously-defined globals for the global initializers.
This commit is contained in:
parent
ddb35dcb5f
commit
8138c2f48b
|
|
@ -255,6 +255,7 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<Ex
|
|||
if (result.is_trap())
|
||||
return InstantiationError { "Global instantiation trapped", move(result.trap()) };
|
||||
global_values.append(result.values().first());
|
||||
auxiliary_instance.globals().append(m_store.allocate(entry.type(), result.values().first()).release_value());
|
||||
}
|
||||
|
||||
if (auto result = allocate_all_initial_phase(module, main_module_instance, externs, global_values, module_functions); result.has_value())
|
||||
|
|
@ -267,7 +268,7 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<Ex
|
|||
if (m_should_limit_instruction_count)
|
||||
config.enable_instruction_count_limit();
|
||||
config.set_frame(Frame {
|
||||
auxiliary_instance,
|
||||
main_module_instance,
|
||||
Vector<Value> {},
|
||||
entry,
|
||||
entry.instructions().size() - 1,
|
||||
|
|
@ -302,7 +303,7 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<Ex
|
|||
if (m_should_limit_instruction_count)
|
||||
config.enable_instruction_count_limit();
|
||||
config.set_frame(Frame {
|
||||
auxiliary_instance,
|
||||
main_module_instance,
|
||||
Vector<Value> {},
|
||||
active_ptr->expression,
|
||||
1,
|
||||
|
|
@ -337,7 +338,7 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<Ex
|
|||
if (m_should_limit_instruction_count)
|
||||
config.enable_instruction_count_limit();
|
||||
config.set_frame(Frame {
|
||||
auxiliary_instance,
|
||||
main_module_instance,
|
||||
Vector<Value> {},
|
||||
data.offset,
|
||||
1,
|
||||
|
|
|
|||
|
|
@ -79,8 +79,6 @@ ErrorOr<void, ValidationError> Validator::validate(Module& module)
|
|||
for (auto& memory : module.memory_section().memories())
|
||||
m_context.memories.append(memory.type());
|
||||
|
||||
auto imported_globals = m_context.globals;
|
||||
|
||||
m_context.globals.ensure_capacity(m_context.globals.size() + module.global_section().entries().size());
|
||||
for (auto& global : module.global_section().entries())
|
||||
m_context.globals.append(global.type());
|
||||
|
|
@ -119,23 +117,11 @@ ErrorOr<void, ValidationError> Validator::validate(Module& module)
|
|||
TRY(validate(module.import_section()));
|
||||
TRY(validate(module.export_section()));
|
||||
TRY(validate(module.start_section()));
|
||||
{
|
||||
// Let C′ be the same context as C, except that C′.globals is just the sequence globals(it∗).
|
||||
|
||||
// Under the context C′:
|
||||
// For each table_i in module.tables, the definition table_i must be val_i with a table type tt_i.
|
||||
// For each mem_i in module.mems, the definition mem_i must be val_i with a memory type mt_i.
|
||||
// For each global_i in module.globals, the definition global_i must be val_i with a global type gt_i.
|
||||
// For each elem_i in module.elems, the segment elem_i must be val_i with reference type rt_i.
|
||||
// For each data_i in module.datas, the segment data_i must be val_i.
|
||||
|
||||
TemporaryChange omit_internal_globals { m_context.globals, imported_globals };
|
||||
TRY(validate(module.data_section()));
|
||||
TRY(validate(module.element_section()));
|
||||
TRY(validate(module.global_section()));
|
||||
TRY(validate(module.memory_section()));
|
||||
TRY(validate(module.table_section()));
|
||||
}
|
||||
TRY(validate(module.data_section()));
|
||||
TRY(validate(module.element_section()));
|
||||
TRY(validate(module.global_section()));
|
||||
TRY(validate(module.memory_section()));
|
||||
TRY(validate(module.table_section()));
|
||||
TRY(validate(module.code_section()));
|
||||
|
||||
module.set_validation_status(Module::ValidationStatus::Valid, {});
|
||||
|
|
@ -226,8 +212,6 @@ ErrorOr<void, ValidationError> Validator::validate(ElementSection const& section
|
|||
|
||||
ErrorOr<void, ValidationError> Validator::validate(GlobalSection const& section)
|
||||
{
|
||||
TemporaryChange omit_internal_globals { m_context.globals, m_globals_without_internal_globals };
|
||||
|
||||
for (auto& entry : section.entries()) {
|
||||
auto& type = entry.type();
|
||||
TRY(validate(type));
|
||||
|
|
|
|||
|
|
@ -314,7 +314,13 @@ private:
|
|||
}
|
||||
|
||||
struct Errors {
|
||||
static ValidationError invalid(StringView name) { return ByteString::formatted("Invalid {}", name); }
|
||||
static ValidationError invalid(StringView name, SourceLocation location = SourceLocation::current())
|
||||
{
|
||||
if constexpr (WASM_VALIDATOR_DEBUG)
|
||||
return ByteString::formatted("Invalid {} in {}", name, find_instruction_name(location));
|
||||
else
|
||||
return ByteString::formatted("Invalid {}", name);
|
||||
}
|
||||
|
||||
template<typename Expected, typename Given>
|
||||
static ValidationError invalid(StringView name, Expected expected, Given given, SourceLocation location = SourceLocation::current())
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user