BytecodeInterpreter.cpp 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  1. /*
  2. * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Debug.h>
  7. #include <LibWasm/AbstractMachine/AbstractMachine.h>
  8. #include <LibWasm/AbstractMachine/BytecodeInterpreter.h>
  9. #include <LibWasm/AbstractMachine/Configuration.h>
  10. #include <LibWasm/AbstractMachine/Operators.h>
  11. #include <LibWasm/Opcode.h>
  12. #include <LibWasm/Printer/Printer.h>
  13. namespace Wasm {
  14. #define TRAP_IF_NOT(x) \
  15. do { \
  16. if (trap_if_not(x, #x##sv)) { \
  17. dbgln_if(WASM_TRACE_DEBUG, "Trapped because {} failed, at line {}", #x, __LINE__); \
  18. return; \
  19. } \
  20. } while (false)
  21. #define TRAP_IF_NOT_NORETURN(x) \
  22. do { \
  23. if (trap_if_not(x, #x##sv)) { \
  24. dbgln_if(WASM_TRACE_DEBUG, "Trapped because {} failed, at line {}", #x, __LINE__); \
  25. } \
  26. } while (false)
  27. void BytecodeInterpreter::interpret(Configuration& configuration)
  28. {
  29. m_trap.clear();
  30. auto& instructions = configuration.frame().expression().instructions();
  31. auto max_ip_value = InstructionPointer { instructions.size() };
  32. auto& current_ip_value = configuration.ip();
  33. auto const should_limit_instruction_count = configuration.should_limit_instruction_count();
  34. u64 executed_instructions = 0;
  35. while (current_ip_value < max_ip_value) {
  36. if (should_limit_instruction_count) {
  37. if (executed_instructions++ >= Constants::max_allowed_executed_instructions_per_call) [[unlikely]] {
  38. m_trap = Trap { "Exceeded maximum allowed number of instructions" };
  39. return;
  40. }
  41. }
  42. auto& instruction = instructions[current_ip_value.value()];
  43. auto old_ip = current_ip_value;
  44. interpret(configuration, current_ip_value, instruction);
  45. if (m_trap.has_value())
  46. return;
  47. if (current_ip_value == old_ip) // If no jump occurred
  48. ++current_ip_value;
  49. }
  50. }
  51. void BytecodeInterpreter::branch_to_label(Configuration& configuration, LabelIndex index)
  52. {
  53. dbgln_if(WASM_TRACE_DEBUG, "Branch to label with index {}...", index.value());
  54. auto label = configuration.nth_label(index.value());
  55. dbgln_if(WASM_TRACE_DEBUG, "...which is actually IP {}, and has {} result(s)", label->continuation().value(), label->arity());
  56. auto results = pop_values(configuration, label->arity());
  57. size_t drop_count = index.value() + 1;
  58. for (; !configuration.stack().is_empty();) {
  59. auto& entry = configuration.stack().peek();
  60. if (entry.has<Label>()) {
  61. if (--drop_count == 0)
  62. break;
  63. }
  64. configuration.stack().pop();
  65. }
  66. for (auto& result : results)
  67. configuration.stack().push(move(result));
  68. configuration.ip() = label->continuation();
  69. }
  70. template<typename ReadType, typename PushType>
  71. void BytecodeInterpreter::load_and_push(Configuration& configuration, Instruction const& instruction)
  72. {
  73. auto& address = configuration.frame().module().memories().first();
  74. auto memory = configuration.store().get(address);
  75. if (!memory) {
  76. m_trap = Trap { "Nonexistent memory" };
  77. return;
  78. }
  79. auto& arg = instruction.arguments().get<Instruction::MemoryArgument>();
  80. auto& entry = configuration.stack().peek();
  81. auto base = entry.get<Value>().to<i32>();
  82. if (!base.has_value()) {
  83. m_trap = Trap { "Memory access out of bounds" };
  84. return;
  85. }
  86. u64 instance_address = static_cast<u64>(bit_cast<u32>(base.value())) + arg.offset;
  87. Checked addition { instance_address };
  88. addition += sizeof(ReadType);
  89. if (addition.has_overflow() || addition.value() > memory->size()) {
  90. m_trap = Trap { "Memory access out of bounds" };
  91. dbgln("LibWasm: Memory access out of bounds (expected {} to be less than or equal to {})", instance_address + sizeof(ReadType), memory->size());
  92. return;
  93. }
  94. dbgln_if(WASM_TRACE_DEBUG, "load({} : {}) -> stack", instance_address, sizeof(ReadType));
  95. auto slice = memory->data().bytes().slice(instance_address, sizeof(ReadType));
  96. configuration.stack().peek() = Value(static_cast<PushType>(read_value<ReadType>(slice)));
  97. }
  98. void BytecodeInterpreter::call_address(Configuration& configuration, FunctionAddress address)
  99. {
  100. TRAP_IF_NOT(m_stack_info.size_free() >= Constants::minimum_stack_space_to_keep_free);
  101. auto instance = configuration.store().get(address);
  102. FunctionType const* type { nullptr };
  103. instance->visit([&](auto const& function) { type = &function.type(); });
  104. TRAP_IF_NOT(configuration.stack().entries().size() > type->parameters().size());
  105. Vector<Value> args;
  106. args.ensure_capacity(type->parameters().size());
  107. auto span = configuration.stack().entries().span().slice_from_end(type->parameters().size());
  108. for (auto& entry : span) {
  109. auto* call_argument = entry.get_pointer<Value>();
  110. TRAP_IF_NOT(call_argument);
  111. args.unchecked_append(move(*call_argument));
  112. }
  113. configuration.stack().entries().remove(configuration.stack().size() - span.size(), span.size());
  114. Result result { Trap { ""sv } };
  115. {
  116. CallFrameHandle handle { *this, configuration };
  117. result = configuration.call(*this, address, move(args));
  118. }
  119. if (result.is_trap()) {
  120. m_trap = move(result.trap());
  121. return;
  122. }
  123. configuration.stack().entries().ensure_capacity(configuration.stack().size() + result.values().size());
  124. for (auto& entry : result.values())
  125. configuration.stack().entries().unchecked_append(move(entry));
  126. }
  127. template<typename PopType, typename PushType, typename Operator>
  128. void BytecodeInterpreter::binary_numeric_operation(Configuration& configuration)
  129. {
  130. auto rhs_entry = configuration.stack().pop();
  131. auto& lhs_entry = configuration.stack().peek();
  132. auto rhs_ptr = rhs_entry.get_pointer<Value>();
  133. auto lhs_ptr = lhs_entry.get_pointer<Value>();
  134. auto rhs = rhs_ptr->to<PopType>();
  135. auto lhs = lhs_ptr->to<PopType>();
  136. PushType result;
  137. auto call_result = Operator {}(lhs.value(), rhs.value());
  138. if constexpr (IsSpecializationOf<decltype(call_result), AK::Result>) {
  139. if (call_result.is_error()) {
  140. trap_if_not(false, call_result.error());
  141. return;
  142. }
  143. result = call_result.release_value();
  144. } else {
  145. result = call_result;
  146. }
  147. dbgln_if(WASM_TRACE_DEBUG, "{} {} {} = {}", lhs.value(), Operator::name(), rhs.value(), result);
  148. lhs_entry = Value(result);
  149. }
  150. template<typename PopType, typename PushType, typename Operator>
  151. void BytecodeInterpreter::unary_operation(Configuration& configuration)
  152. {
  153. auto& entry = configuration.stack().peek();
  154. auto entry_ptr = entry.get_pointer<Value>();
  155. auto value = entry_ptr->to<PopType>();
  156. auto call_result = Operator {}(*value);
  157. PushType result;
  158. if constexpr (IsSpecializationOf<decltype(call_result), AK::Result>) {
  159. if (call_result.is_error()) {
  160. trap_if_not(false, call_result.error());
  161. return;
  162. }
  163. result = call_result.release_value();
  164. } else {
  165. result = call_result;
  166. }
  167. dbgln_if(WASM_TRACE_DEBUG, "map({}) {} = {}", Operator::name(), *value, result);
  168. entry = Value(result);
  169. }
  170. template<typename T>
  171. struct ConvertToRaw {
  172. T operator()(T value)
  173. {
  174. return LittleEndian<T>(value);
  175. }
  176. };
  177. template<>
  178. struct ConvertToRaw<float> {
  179. u32 operator()(float value)
  180. {
  181. LittleEndian<u32> res;
  182. ReadonlyBytes bytes { &value, sizeof(float) };
  183. InputMemoryStream stream { bytes };
  184. stream >> res;
  185. VERIFY(!stream.has_any_error());
  186. return static_cast<u32>(res);
  187. }
  188. };
  189. template<>
  190. struct ConvertToRaw<double> {
  191. u64 operator()(double value)
  192. {
  193. LittleEndian<u64> res;
  194. ReadonlyBytes bytes { &value, sizeof(double) };
  195. InputMemoryStream stream { bytes };
  196. stream >> res;
  197. VERIFY(!stream.has_any_error());
  198. return static_cast<u64>(res);
  199. }
  200. };
  201. template<typename PopT, typename StoreT>
  202. void BytecodeInterpreter::pop_and_store(Configuration& configuration, Instruction const& instruction)
  203. {
  204. auto entry = configuration.stack().pop();
  205. auto value = ConvertToRaw<StoreT> {}(*entry.get<Value>().to<PopT>());
  206. dbgln_if(WASM_TRACE_DEBUG, "stack({}) -> temporary({}b)", value, sizeof(StoreT));
  207. auto base_entry = configuration.stack().pop();
  208. auto base = base_entry.get<Value>().to<i32>();
  209. store_to_memory(configuration, instruction, { &value, sizeof(StoreT) }, *base);
  210. }
  211. void BytecodeInterpreter::store_to_memory(Configuration& configuration, Instruction const& instruction, ReadonlyBytes data, i32 base)
  212. {
  213. auto& address = configuration.frame().module().memories().first();
  214. auto memory = configuration.store().get(address);
  215. auto& arg = instruction.arguments().get<Instruction::MemoryArgument>();
  216. u64 instance_address = static_cast<u64>(bit_cast<u32>(base)) + arg.offset;
  217. Checked addition { instance_address };
  218. addition += data.size();
  219. if (addition.has_overflow() || addition.value() > memory->size()) {
  220. m_trap = Trap { "Memory access out of bounds" };
  221. dbgln("LibWasm: Memory access out of bounds (expected 0 <= {} and {} <= {})", instance_address, instance_address + data.size(), memory->size());
  222. return;
  223. }
  224. dbgln_if(WASM_TRACE_DEBUG, "tempoaray({}b) -> store({})", data.size(), instance_address);
  225. data.copy_to(memory->data().bytes().slice(instance_address, data.size()));
  226. }
  227. template<typename T>
  228. T BytecodeInterpreter::read_value(ReadonlyBytes data)
  229. {
  230. LittleEndian<T> value;
  231. InputMemoryStream stream { data };
  232. stream >> value;
  233. if (stream.handle_any_error()) {
  234. dbgln("Read from {} failed", data.data());
  235. m_trap = Trap { "Read from memory failed" };
  236. }
  237. return value;
  238. }
  239. template<>
  240. float BytecodeInterpreter::read_value<float>(ReadonlyBytes data)
  241. {
  242. InputMemoryStream stream { data };
  243. LittleEndian<u32> raw_value;
  244. stream >> raw_value;
  245. if (stream.handle_any_error())
  246. m_trap = Trap { "Read from memory failed" };
  247. return bit_cast<float>(static_cast<u32>(raw_value));
  248. }
  249. template<>
  250. double BytecodeInterpreter::read_value<double>(ReadonlyBytes data)
  251. {
  252. InputMemoryStream stream { data };
  253. LittleEndian<u64> raw_value;
  254. stream >> raw_value;
  255. if (stream.handle_any_error())
  256. m_trap = Trap { "Read from memory failed" };
  257. return bit_cast<double>(static_cast<u64>(raw_value));
  258. }
  259. template<typename V, typename T>
  260. MakeSigned<T> BytecodeInterpreter::checked_signed_truncate(V value)
  261. {
  262. if (isnan(value) || isinf(value)) { // "undefined", let's just trap.
  263. m_trap = Trap { "Signed truncation undefined behavior" };
  264. return 0;
  265. }
  266. double truncated;
  267. if constexpr (IsSame<float, V>)
  268. truncated = truncf(value);
  269. else
  270. truncated = trunc(value);
  271. using SignedT = MakeSigned<T>;
  272. if (NumericLimits<SignedT>::min() <= truncated && static_cast<double>(NumericLimits<SignedT>::max()) >= truncated)
  273. return static_cast<SignedT>(truncated);
  274. dbgln_if(WASM_TRACE_DEBUG, "Truncate out of range error");
  275. m_trap = Trap { "Signed truncation out of range" };
  276. return true;
  277. }
  278. template<typename V, typename T>
  279. MakeUnsigned<T> BytecodeInterpreter::checked_unsigned_truncate(V value)
  280. {
  281. if (isnan(value) || isinf(value)) { // "undefined", let's just trap.
  282. m_trap = Trap { "Unsigned truncation undefined behavior" };
  283. return 0;
  284. }
  285. double truncated;
  286. if constexpr (IsSame<float, V>)
  287. truncated = truncf(value);
  288. else
  289. truncated = trunc(value);
  290. using UnsignedT = MakeUnsigned<T>;
  291. if (NumericLimits<UnsignedT>::min() <= truncated && static_cast<double>(NumericLimits<UnsignedT>::max()) >= truncated)
  292. return static_cast<UnsignedT>(truncated);
  293. dbgln_if(WASM_TRACE_DEBUG, "Truncate out of range error");
  294. m_trap = Trap { "Unsigned truncation out of range" };
  295. return true;
  296. }
  297. Vector<Value> BytecodeInterpreter::pop_values(Configuration& configuration, size_t count)
  298. {
  299. Vector<Value> results;
  300. results.resize(count);
  301. for (size_t i = 0; i < count; ++i) {
  302. auto top_of_stack = configuration.stack().pop();
  303. if (auto value = top_of_stack.get_pointer<Value>())
  304. results[i] = move(*value);
  305. else
  306. TRAP_IF_NOT_NORETURN(value);
  307. }
  308. return results;
  309. }
  310. void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPointer& ip, Instruction const& instruction)
  311. {
  312. dbgln_if(WASM_TRACE_DEBUG, "Executing instruction {} at ip {}", instruction_name(instruction.opcode()), ip.value());
  313. switch (instruction.opcode().value()) {
  314. case Instructions::unreachable.value():
  315. m_trap = Trap { "Unreachable" };
  316. return;
  317. case Instructions::nop.value():
  318. return;
  319. case Instructions::local_get.value():
  320. configuration.stack().push(Value(configuration.frame().locals()[instruction.arguments().get<LocalIndex>().value()]));
  321. return;
  322. case Instructions::local_set.value(): {
  323. auto entry = configuration.stack().pop();
  324. configuration.frame().locals()[instruction.arguments().get<LocalIndex>().value()] = move(entry.get<Value>());
  325. return;
  326. }
  327. case Instructions::i32_const.value():
  328. configuration.stack().push(Value(ValueType { ValueType::I32 }, static_cast<i64>(instruction.arguments().get<i32>())));
  329. return;
  330. case Instructions::i64_const.value():
  331. configuration.stack().push(Value(ValueType { ValueType::I64 }, instruction.arguments().get<i64>()));
  332. return;
  333. case Instructions::f32_const.value():
  334. configuration.stack().push(Value(ValueType { ValueType::F32 }, static_cast<double>(instruction.arguments().get<float>())));
  335. return;
  336. case Instructions::f64_const.value():
  337. configuration.stack().push(Value(ValueType { ValueType::F64 }, instruction.arguments().get<double>()));
  338. return;
  339. case Instructions::block.value(): {
  340. size_t arity = 0;
  341. auto& args = instruction.arguments().get<Instruction::StructuredInstructionArgs>();
  342. if (args.block_type.kind() != BlockType::Empty)
  343. arity = 1;
  344. configuration.stack().push(Label(arity, args.end_ip));
  345. return;
  346. }
  347. case Instructions::loop.value(): {
  348. size_t arity = 0;
  349. auto& args = instruction.arguments().get<Instruction::StructuredInstructionArgs>();
  350. if (args.block_type.kind() != BlockType::Empty)
  351. arity = 1;
  352. configuration.stack().push(Label(arity, ip.value() + 1));
  353. return;
  354. }
  355. case Instructions::if_.value(): {
  356. size_t arity = 0;
  357. auto& args = instruction.arguments().get<Instruction::StructuredInstructionArgs>();
  358. if (args.block_type.kind() != BlockType::Empty)
  359. arity = 1;
  360. auto entry = configuration.stack().pop();
  361. auto value = entry.get<Value>().to<i32>();
  362. auto end_label = Label(arity, args.end_ip.value());
  363. if (value.value() == 0) {
  364. if (args.else_ip.has_value()) {
  365. configuration.ip() = args.else_ip.value();
  366. configuration.stack().push(move(end_label));
  367. } else {
  368. configuration.ip() = args.end_ip.value() + 1;
  369. }
  370. } else {
  371. configuration.stack().push(move(end_label));
  372. }
  373. return;
  374. }
  375. case Instructions::structured_end.value():
  376. case Instructions::structured_else.value(): {
  377. auto index = configuration.nth_label_index(0);
  378. auto label = configuration.stack().entries()[*index].get<Label>();
  379. configuration.stack().entries().remove(*index, 1);
  380. if (instruction.opcode() == Instructions::structured_end)
  381. return;
  382. // Jump to the end label
  383. configuration.ip() = label.continuation();
  384. return;
  385. }
  386. case Instructions::return_.value(): {
  387. auto& frame = configuration.frame();
  388. size_t end = configuration.stack().size() - frame.arity();
  389. size_t start = end;
  390. for (; start + 1 > 0 && start < configuration.stack().size(); --start) {
  391. auto& entry = configuration.stack().entries()[start];
  392. if (entry.has<Frame>()) {
  393. // Leave the frame, _and_ its label.
  394. start += 2;
  395. break;
  396. }
  397. }
  398. configuration.stack().entries().remove(start, end - start);
  399. // Jump past the call/indirect instruction
  400. configuration.ip() = configuration.frame().expression().instructions().size();
  401. return;
  402. }
  403. case Instructions::br.value():
  404. return branch_to_label(configuration, instruction.arguments().get<LabelIndex>());
  405. case Instructions::br_if.value(): {
  406. auto entry = configuration.stack().pop();
  407. if (entry.get<Value>().to<i32>().value_or(0) == 0)
  408. return;
  409. return branch_to_label(configuration, instruction.arguments().get<LabelIndex>());
  410. }
  411. case Instructions::br_table.value(): {
  412. auto& arguments = instruction.arguments().get<Instruction::TableBranchArgs>();
  413. auto entry = configuration.stack().pop();
  414. auto maybe_i = entry.get<Value>().to<i32>();
  415. if (0 <= *maybe_i) {
  416. size_t i = *maybe_i;
  417. if (i < arguments.labels.size())
  418. return branch_to_label(configuration, arguments.labels[i]);
  419. }
  420. return branch_to_label(configuration, arguments.default_);
  421. }
  422. case Instructions::call.value(): {
  423. auto index = instruction.arguments().get<FunctionIndex>();
  424. auto address = configuration.frame().module().functions()[index.value()];
  425. dbgln_if(WASM_TRACE_DEBUG, "call({})", address.value());
  426. call_address(configuration, address);
  427. return;
  428. }
  429. case Instructions::call_indirect.value(): {
  430. auto& args = instruction.arguments().get<Instruction::IndirectCallArgs>();
  431. auto table_address = configuration.frame().module().tables()[args.table.value()];
  432. auto table_instance = configuration.store().get(table_address);
  433. auto entry = configuration.stack().pop();
  434. auto index = entry.get<Value>().to<i32>();
  435. TRAP_IF_NOT(index.value() >= 0);
  436. TRAP_IF_NOT(static_cast<size_t>(index.value()) < table_instance->elements().size());
  437. auto element = table_instance->elements()[index.value()];
  438. TRAP_IF_NOT(element.has_value());
  439. TRAP_IF_NOT(element->ref().has<Reference::Func>());
  440. auto address = element->ref().get<Reference::Func>().address;
  441. dbgln_if(WASM_TRACE_DEBUG, "call_indirect({} -> {})", index.value(), address.value());
  442. call_address(configuration, address);
  443. return;
  444. }
  445. case Instructions::i32_load.value():
  446. return load_and_push<i32, i32>(configuration, instruction);
  447. case Instructions::i64_load.value():
  448. return load_and_push<i64, i64>(configuration, instruction);
  449. case Instructions::f32_load.value():
  450. return load_and_push<float, float>(configuration, instruction);
  451. case Instructions::f64_load.value():
  452. return load_and_push<double, double>(configuration, instruction);
  453. case Instructions::i32_load8_s.value():
  454. return load_and_push<i8, i32>(configuration, instruction);
  455. case Instructions::i32_load8_u.value():
  456. return load_and_push<u8, i32>(configuration, instruction);
  457. case Instructions::i32_load16_s.value():
  458. return load_and_push<i16, i32>(configuration, instruction);
  459. case Instructions::i32_load16_u.value():
  460. return load_and_push<u16, i32>(configuration, instruction);
  461. case Instructions::i64_load8_s.value():
  462. return load_and_push<i8, i64>(configuration, instruction);
  463. case Instructions::i64_load8_u.value():
  464. return load_and_push<u8, i64>(configuration, instruction);
  465. case Instructions::i64_load16_s.value():
  466. return load_and_push<i16, i64>(configuration, instruction);
  467. case Instructions::i64_load16_u.value():
  468. return load_and_push<u16, i64>(configuration, instruction);
  469. case Instructions::i64_load32_s.value():
  470. return load_and_push<i32, i64>(configuration, instruction);
  471. case Instructions::i64_load32_u.value():
  472. return load_and_push<u32, i64>(configuration, instruction);
  473. case Instructions::i32_store.value():
  474. return pop_and_store<i32, i32>(configuration, instruction);
  475. case Instructions::i64_store.value():
  476. return pop_and_store<i64, i64>(configuration, instruction);
  477. case Instructions::f32_store.value():
  478. return pop_and_store<float, float>(configuration, instruction);
  479. case Instructions::f64_store.value():
  480. return pop_and_store<double, double>(configuration, instruction);
  481. case Instructions::i32_store8.value():
  482. return pop_and_store<i32, i8>(configuration, instruction);
  483. case Instructions::i32_store16.value():
  484. return pop_and_store<i32, i16>(configuration, instruction);
  485. case Instructions::i64_store8.value():
  486. return pop_and_store<i64, i8>(configuration, instruction);
  487. case Instructions::i64_store16.value():
  488. return pop_and_store<i64, i16>(configuration, instruction);
  489. case Instructions::i64_store32.value():
  490. return pop_and_store<i64, i32>(configuration, instruction);
  491. case Instructions::local_tee.value(): {
  492. auto& entry = configuration.stack().peek();
  493. auto value = entry.get<Value>();
  494. auto local_index = instruction.arguments().get<LocalIndex>();
  495. dbgln_if(WASM_TRACE_DEBUG, "stack:peek -> locals({})", local_index.value());
  496. configuration.frame().locals()[local_index.value()] = move(value);
  497. return;
  498. }
  499. case Instructions::global_get.value(): {
  500. auto global_index = instruction.arguments().get<GlobalIndex>();
  501. auto address = configuration.frame().module().globals()[global_index.value()];
  502. dbgln_if(WASM_TRACE_DEBUG, "global({}) -> stack", address.value());
  503. auto global = configuration.store().get(address);
  504. configuration.stack().push(Value(global->value()));
  505. return;
  506. }
  507. case Instructions::global_set.value(): {
  508. auto global_index = instruction.arguments().get<GlobalIndex>();
  509. auto address = configuration.frame().module().globals()[global_index.value()];
  510. auto entry = configuration.stack().pop();
  511. auto value = entry.get<Value>();
  512. dbgln_if(WASM_TRACE_DEBUG, "stack -> global({})", address.value());
  513. auto global = configuration.store().get(address);
  514. global->set_value(move(value));
  515. return;
  516. }
  517. case Instructions::memory_size.value(): {
  518. auto address = configuration.frame().module().memories()[0];
  519. auto instance = configuration.store().get(address);
  520. auto pages = instance->size() / Constants::page_size;
  521. dbgln_if(WASM_TRACE_DEBUG, "memory.size -> stack({})", pages);
  522. configuration.stack().push(Value((i32)pages));
  523. return;
  524. }
  525. case Instructions::memory_grow.value(): {
  526. auto address = configuration.frame().module().memories()[0];
  527. auto instance = configuration.store().get(address);
  528. i32 old_pages = instance->size() / Constants::page_size;
  529. auto& entry = configuration.stack().peek();
  530. auto new_pages = entry.get<Value>().to<i32>();
  531. dbgln_if(WASM_TRACE_DEBUG, "memory.grow({}), previously {} pages...", *new_pages, old_pages);
  532. if (instance->grow(new_pages.value() * Constants::page_size))
  533. configuration.stack().peek() = Value((i32)old_pages);
  534. else
  535. configuration.stack().peek() = Value((i32)-1);
  536. return;
  537. }
  538. case Instructions::table_get.value():
  539. case Instructions::table_set.value():
  540. goto unimplemented;
  541. case Instructions::ref_null.value(): {
  542. auto type = instruction.arguments().get<ValueType>();
  543. configuration.stack().push(Value(Reference(Reference::Null { type })));
  544. return;
  545. };
  546. case Instructions::ref_func.value(): {
  547. auto index = instruction.arguments().get<FunctionIndex>().value();
  548. auto& functions = configuration.frame().module().functions();
  549. auto address = functions[index];
  550. configuration.stack().push(Value(ValueType(ValueType::FunctionReference), address.value()));
  551. return;
  552. }
  553. case Instructions::ref_is_null.value(): {
  554. auto top = configuration.stack().peek().get_pointer<Value>();
  555. TRAP_IF_NOT(top->type().is_reference());
  556. auto is_null = top->to<Reference::Null>().has_value();
  557. configuration.stack().peek() = Value(ValueType(ValueType::I32), static_cast<u64>(is_null ? 1 : 0));
  558. return;
  559. }
  560. case Instructions::drop.value():
  561. configuration.stack().pop();
  562. return;
  563. case Instructions::select.value():
  564. case Instructions::select_typed.value(): {
  565. // Note: The type seems to only be used for validation.
  566. auto entry = configuration.stack().pop();
  567. auto value = entry.get<Value>().to<i32>();
  568. dbgln_if(WASM_TRACE_DEBUG, "select({})", value.value());
  569. auto rhs_entry = configuration.stack().pop();
  570. auto& lhs_entry = configuration.stack().peek();
  571. auto rhs = move(rhs_entry.get<Value>());
  572. auto lhs = move(lhs_entry.get<Value>());
  573. configuration.stack().peek() = value.value() != 0 ? move(lhs) : move(rhs);
  574. return;
  575. }
  576. case Instructions::i32_eqz.value():
  577. return unary_operation<i32, i32, Operators::EqualsZero>(configuration);
  578. case Instructions::i32_eq.value():
  579. return binary_numeric_operation<i32, i32, Operators::Equals>(configuration);
  580. case Instructions::i32_ne.value():
  581. return binary_numeric_operation<i32, i32, Operators::NotEquals>(configuration);
  582. case Instructions::i32_lts.value():
  583. return binary_numeric_operation<i32, i32, Operators::LessThan>(configuration);
  584. case Instructions::i32_ltu.value():
  585. return binary_numeric_operation<u32, i32, Operators::LessThan>(configuration);
  586. case Instructions::i32_gts.value():
  587. return binary_numeric_operation<i32, i32, Operators::GreaterThan>(configuration);
  588. case Instructions::i32_gtu.value():
  589. return binary_numeric_operation<u32, i32, Operators::GreaterThan>(configuration);
  590. case Instructions::i32_les.value():
  591. return binary_numeric_operation<i32, i32, Operators::LessThanOrEquals>(configuration);
  592. case Instructions::i32_leu.value():
  593. return binary_numeric_operation<u32, i32, Operators::LessThanOrEquals>(configuration);
  594. case Instructions::i32_ges.value():
  595. return binary_numeric_operation<i32, i32, Operators::GreaterThanOrEquals>(configuration);
  596. case Instructions::i32_geu.value():
  597. return binary_numeric_operation<u32, i32, Operators::GreaterThanOrEquals>(configuration);
  598. case Instructions::i64_eqz.value():
  599. return unary_operation<i64, i32, Operators::EqualsZero>(configuration);
  600. case Instructions::i64_eq.value():
  601. return binary_numeric_operation<i64, i32, Operators::Equals>(configuration);
  602. case Instructions::i64_ne.value():
  603. return binary_numeric_operation<i64, i32, Operators::NotEquals>(configuration);
  604. case Instructions::i64_lts.value():
  605. return binary_numeric_operation<i64, i32, Operators::LessThan>(configuration);
  606. case Instructions::i64_ltu.value():
  607. return binary_numeric_operation<u64, i32, Operators::LessThan>(configuration);
  608. case Instructions::i64_gts.value():
  609. return binary_numeric_operation<i64, i32, Operators::GreaterThan>(configuration);
  610. case Instructions::i64_gtu.value():
  611. return binary_numeric_operation<u64, i32, Operators::GreaterThan>(configuration);
  612. case Instructions::i64_les.value():
  613. return binary_numeric_operation<i64, i32, Operators::LessThanOrEquals>(configuration);
  614. case Instructions::i64_leu.value():
  615. return binary_numeric_operation<u64, i32, Operators::LessThanOrEquals>(configuration);
  616. case Instructions::i64_ges.value():
  617. return binary_numeric_operation<i64, i32, Operators::GreaterThanOrEquals>(configuration);
  618. case Instructions::i64_geu.value():
  619. return binary_numeric_operation<u64, i32, Operators::GreaterThanOrEquals>(configuration);
  620. case Instructions::f32_eq.value():
  621. return binary_numeric_operation<float, i32, Operators::Equals>(configuration);
  622. case Instructions::f32_ne.value():
  623. return binary_numeric_operation<float, i32, Operators::NotEquals>(configuration);
  624. case Instructions::f32_lt.value():
  625. return binary_numeric_operation<float, i32, Operators::LessThan>(configuration);
  626. case Instructions::f32_gt.value():
  627. return binary_numeric_operation<float, i32, Operators::GreaterThan>(configuration);
  628. case Instructions::f32_le.value():
  629. return binary_numeric_operation<float, i32, Operators::LessThanOrEquals>(configuration);
  630. case Instructions::f32_ge.value():
  631. return binary_numeric_operation<float, i32, Operators::GreaterThanOrEquals>(configuration);
  632. case Instructions::f64_eq.value():
  633. return binary_numeric_operation<double, i32, Operators::Equals>(configuration);
  634. case Instructions::f64_ne.value():
  635. return binary_numeric_operation<double, i32, Operators::NotEquals>(configuration);
  636. case Instructions::f64_lt.value():
  637. return binary_numeric_operation<double, i32, Operators::LessThan>(configuration);
  638. case Instructions::f64_gt.value():
  639. return binary_numeric_operation<double, i32, Operators::GreaterThan>(configuration);
  640. case Instructions::f64_le.value():
  641. return binary_numeric_operation<double, i32, Operators::LessThanOrEquals>(configuration);
  642. case Instructions::f64_ge.value():
  643. return binary_numeric_operation<double, i32, Operators::GreaterThanOrEquals>(configuration);
  644. case Instructions::i32_clz.value():
  645. return unary_operation<i32, i32, Operators::CountLeadingZeros>(configuration);
  646. case Instructions::i32_ctz.value():
  647. return unary_operation<i32, i32, Operators::CountTrailingZeros>(configuration);
  648. case Instructions::i32_popcnt.value():
  649. return unary_operation<i32, i32, Operators::PopCount>(configuration);
  650. case Instructions::i32_add.value():
  651. return binary_numeric_operation<u32, i32, Operators::Add>(configuration);
  652. case Instructions::i32_sub.value():
  653. return binary_numeric_operation<u32, i32, Operators::Subtract>(configuration);
  654. case Instructions::i32_mul.value():
  655. return binary_numeric_operation<u32, i32, Operators::Multiply>(configuration);
  656. case Instructions::i32_divs.value():
  657. return binary_numeric_operation<i32, i32, Operators::Divide>(configuration);
  658. case Instructions::i32_divu.value():
  659. return binary_numeric_operation<u32, i32, Operators::Divide>(configuration);
  660. case Instructions::i32_rems.value():
  661. return binary_numeric_operation<i32, i32, Operators::Modulo>(configuration);
  662. case Instructions::i32_remu.value():
  663. return binary_numeric_operation<u32, i32, Operators::Modulo>(configuration);
  664. case Instructions::i32_and.value():
  665. return binary_numeric_operation<i32, i32, Operators::BitAnd>(configuration);
  666. case Instructions::i32_or.value():
  667. return binary_numeric_operation<i32, i32, Operators::BitOr>(configuration);
  668. case Instructions::i32_xor.value():
  669. return binary_numeric_operation<i32, i32, Operators::BitXor>(configuration);
  670. case Instructions::i32_shl.value():
  671. return binary_numeric_operation<u32, i32, Operators::BitShiftLeft>(configuration);
  672. case Instructions::i32_shrs.value():
  673. return binary_numeric_operation<i32, i32, Operators::BitShiftRight>(configuration);
  674. case Instructions::i32_shru.value():
  675. return binary_numeric_operation<u32, i32, Operators::BitShiftRight>(configuration);
  676. case Instructions::i32_rotl.value():
  677. return binary_numeric_operation<u32, i32, Operators::BitRotateLeft>(configuration);
  678. case Instructions::i32_rotr.value():
  679. return binary_numeric_operation<u32, i32, Operators::BitRotateRight>(configuration);
  680. case Instructions::i64_clz.value():
  681. return unary_operation<i64, i64, Operators::CountLeadingZeros>(configuration);
  682. case Instructions::i64_ctz.value():
  683. return unary_operation<i64, i64, Operators::CountTrailingZeros>(configuration);
  684. case Instructions::i64_popcnt.value():
  685. return unary_operation<i64, i64, Operators::PopCount>(configuration);
  686. case Instructions::i64_add.value():
  687. return binary_numeric_operation<u64, i64, Operators::Add>(configuration);
  688. case Instructions::i64_sub.value():
  689. return binary_numeric_operation<u64, i64, Operators::Subtract>(configuration);
  690. case Instructions::i64_mul.value():
  691. return binary_numeric_operation<u64, i64, Operators::Multiply>(configuration);
  692. case Instructions::i64_divs.value():
  693. return binary_numeric_operation<i64, i64, Operators::Divide>(configuration);
  694. case Instructions::i64_divu.value():
  695. return binary_numeric_operation<u64, i64, Operators::Divide>(configuration);
  696. case Instructions::i64_rems.value():
  697. return binary_numeric_operation<i64, i64, Operators::Modulo>(configuration);
  698. case Instructions::i64_remu.value():
  699. return binary_numeric_operation<u64, i64, Operators::Modulo>(configuration);
  700. case Instructions::i64_and.value():
  701. return binary_numeric_operation<i64, i64, Operators::BitAnd>(configuration);
  702. case Instructions::i64_or.value():
  703. return binary_numeric_operation<i64, i64, Operators::BitOr>(configuration);
  704. case Instructions::i64_xor.value():
  705. return binary_numeric_operation<i64, i64, Operators::BitXor>(configuration);
  706. case Instructions::i64_shl.value():
  707. return binary_numeric_operation<u64, i64, Operators::BitShiftLeft>(configuration);
  708. case Instructions::i64_shrs.value():
  709. return binary_numeric_operation<i64, i64, Operators::BitShiftRight>(configuration);
  710. case Instructions::i64_shru.value():
  711. return binary_numeric_operation<u64, i64, Operators::BitShiftRight>(configuration);
  712. case Instructions::i64_rotl.value():
  713. return binary_numeric_operation<u64, i64, Operators::BitRotateLeft>(configuration);
  714. case Instructions::i64_rotr.value():
  715. return binary_numeric_operation<u64, i64, Operators::BitRotateRight>(configuration);
  716. case Instructions::f32_abs.value():
  717. return unary_operation<float, float, Operators::Absolute>(configuration);
  718. case Instructions::f32_neg.value():
  719. return unary_operation<float, float, Operators::Negate>(configuration);
  720. case Instructions::f32_ceil.value():
  721. return unary_operation<float, float, Operators::Ceil>(configuration);
  722. case Instructions::f32_floor.value():
  723. return unary_operation<float, float, Operators::Floor>(configuration);
  724. case Instructions::f32_trunc.value():
  725. return unary_operation<float, float, Operators::Truncate>(configuration);
  726. case Instructions::f32_nearest.value():
  727. return unary_operation<float, float, Operators::NearbyIntegral>(configuration);
  728. case Instructions::f32_sqrt.value():
  729. return unary_operation<float, float, Operators::SquareRoot>(configuration);
  730. case Instructions::f32_add.value():
  731. return binary_numeric_operation<float, float, Operators::Add>(configuration);
  732. case Instructions::f32_sub.value():
  733. return binary_numeric_operation<float, float, Operators::Subtract>(configuration);
  734. case Instructions::f32_mul.value():
  735. return binary_numeric_operation<float, float, Operators::Multiply>(configuration);
  736. case Instructions::f32_div.value():
  737. return binary_numeric_operation<float, float, Operators::Divide>(configuration);
  738. case Instructions::f32_min.value():
  739. return binary_numeric_operation<float, float, Operators::Minimum>(configuration);
  740. case Instructions::f32_max.value():
  741. return binary_numeric_operation<float, float, Operators::Maximum>(configuration);
  742. case Instructions::f32_copysign.value():
  743. return binary_numeric_operation<float, float, Operators::CopySign>(configuration);
  744. case Instructions::f64_abs.value():
  745. return unary_operation<double, double, Operators::Absolute>(configuration);
  746. case Instructions::f64_neg.value():
  747. return unary_operation<double, double, Operators::Negate>(configuration);
  748. case Instructions::f64_ceil.value():
  749. return unary_operation<double, double, Operators::Ceil>(configuration);
  750. case Instructions::f64_floor.value():
  751. return unary_operation<double, double, Operators::Floor>(configuration);
  752. case Instructions::f64_trunc.value():
  753. return unary_operation<double, double, Operators::Truncate>(configuration);
  754. case Instructions::f64_nearest.value():
  755. return unary_operation<double, double, Operators::NearbyIntegral>(configuration);
  756. case Instructions::f64_sqrt.value():
  757. return unary_operation<double, double, Operators::SquareRoot>(configuration);
  758. case Instructions::f64_add.value():
  759. return binary_numeric_operation<double, double, Operators::Add>(configuration);
  760. case Instructions::f64_sub.value():
  761. return binary_numeric_operation<double, double, Operators::Subtract>(configuration);
  762. case Instructions::f64_mul.value():
  763. return binary_numeric_operation<double, double, Operators::Multiply>(configuration);
  764. case Instructions::f64_div.value():
  765. return binary_numeric_operation<double, double, Operators::Divide>(configuration);
  766. case Instructions::f64_min.value():
  767. return binary_numeric_operation<double, double, Operators::Minimum>(configuration);
  768. case Instructions::f64_max.value():
  769. return binary_numeric_operation<double, double, Operators::Maximum>(configuration);
  770. case Instructions::f64_copysign.value():
  771. return binary_numeric_operation<double, double, Operators::CopySign>(configuration);
  772. case Instructions::i32_wrap_i64.value():
  773. return unary_operation<i64, i32, Operators::Wrap<i32>>(configuration);
  774. case Instructions::i32_trunc_sf32.value():
  775. return unary_operation<float, i32, Operators::CheckedTruncate<i32>>(configuration);
  776. case Instructions::i32_trunc_uf32.value():
  777. return unary_operation<float, i32, Operators::CheckedTruncate<u32>>(configuration);
  778. case Instructions::i32_trunc_sf64.value():
  779. return unary_operation<double, i32, Operators::CheckedTruncate<i32>>(configuration);
  780. case Instructions::i32_trunc_uf64.value():
  781. return unary_operation<double, i32, Operators::CheckedTruncate<u32>>(configuration);
  782. case Instructions::i64_trunc_sf32.value():
  783. return unary_operation<float, i64, Operators::CheckedTruncate<i64>>(configuration);
  784. case Instructions::i64_trunc_uf32.value():
  785. return unary_operation<float, i64, Operators::CheckedTruncate<u64>>(configuration);
  786. case Instructions::i64_trunc_sf64.value():
  787. return unary_operation<double, i64, Operators::CheckedTruncate<i64>>(configuration);
  788. case Instructions::i64_trunc_uf64.value():
  789. return unary_operation<double, i64, Operators::CheckedTruncate<u64>>(configuration);
  790. case Instructions::i64_extend_si32.value():
  791. return unary_operation<i32, i64, Operators::Extend<i64>>(configuration);
  792. case Instructions::i64_extend_ui32.value():
  793. return unary_operation<u32, i64, Operators::Extend<i64>>(configuration);
  794. case Instructions::f32_convert_si32.value():
  795. return unary_operation<i32, float, Operators::Convert<float>>(configuration);
  796. case Instructions::f32_convert_ui32.value():
  797. return unary_operation<u32, float, Operators::Convert<float>>(configuration);
  798. case Instructions::f32_convert_si64.value():
  799. return unary_operation<i64, float, Operators::Convert<float>>(configuration);
  800. case Instructions::f32_convert_ui64.value():
  801. return unary_operation<u64, float, Operators::Convert<float>>(configuration);
  802. case Instructions::f32_demote_f64.value():
  803. return unary_operation<double, float, Operators::Demote>(configuration);
  804. case Instructions::f64_convert_si32.value():
  805. return unary_operation<i32, double, Operators::Convert<double>>(configuration);
  806. case Instructions::f64_convert_ui32.value():
  807. return unary_operation<u32, double, Operators::Convert<double>>(configuration);
  808. case Instructions::f64_convert_si64.value():
  809. return unary_operation<i64, double, Operators::Convert<double>>(configuration);
  810. case Instructions::f64_convert_ui64.value():
  811. return unary_operation<u64, double, Operators::Convert<double>>(configuration);
  812. case Instructions::f64_promote_f32.value():
  813. return unary_operation<float, double, Operators::Promote>(configuration);
  814. case Instructions::i32_reinterpret_f32.value():
  815. return unary_operation<float, i32, Operators::Reinterpret<i32>>(configuration);
  816. case Instructions::i64_reinterpret_f64.value():
  817. return unary_operation<double, i64, Operators::Reinterpret<i64>>(configuration);
  818. case Instructions::f32_reinterpret_i32.value():
  819. return unary_operation<i32, float, Operators::Reinterpret<float>>(configuration);
  820. case Instructions::f64_reinterpret_i64.value():
  821. return unary_operation<i64, double, Operators::Reinterpret<double>>(configuration);
  822. case Instructions::i32_extend8_s.value():
  823. return unary_operation<i32, i32, Operators::SignExtend<i8>>(configuration);
  824. case Instructions::i32_extend16_s.value():
  825. return unary_operation<i32, i32, Operators::SignExtend<i16>>(configuration);
  826. case Instructions::i64_extend8_s.value():
  827. return unary_operation<i64, i64, Operators::SignExtend<i8>>(configuration);
  828. case Instructions::i64_extend16_s.value():
  829. return unary_operation<i64, i64, Operators::SignExtend<i16>>(configuration);
  830. case Instructions::i64_extend32_s.value():
  831. return unary_operation<i64, i64, Operators::SignExtend<i32>>(configuration);
  832. case Instructions::i32_trunc_sat_f32_s.value():
  833. return unary_operation<float, i32, Operators::SaturatingTruncate<i32>>(configuration);
  834. case Instructions::i32_trunc_sat_f32_u.value():
  835. return unary_operation<float, i32, Operators::SaturatingTruncate<u32>>(configuration);
  836. case Instructions::i32_trunc_sat_f64_s.value():
  837. return unary_operation<double, i32, Operators::SaturatingTruncate<i32>>(configuration);
  838. case Instructions::i32_trunc_sat_f64_u.value():
  839. return unary_operation<double, i32, Operators::SaturatingTruncate<u32>>(configuration);
  840. case Instructions::i64_trunc_sat_f32_s.value():
  841. return unary_operation<float, i64, Operators::SaturatingTruncate<i64>>(configuration);
  842. case Instructions::i64_trunc_sat_f32_u.value():
  843. return unary_operation<float, i64, Operators::SaturatingTruncate<u64>>(configuration);
  844. case Instructions::i64_trunc_sat_f64_s.value():
  845. return unary_operation<double, i64, Operators::SaturatingTruncate<i64>>(configuration);
  846. case Instructions::i64_trunc_sat_f64_u.value():
  847. return unary_operation<double, i64, Operators::SaturatingTruncate<u64>>(configuration);
  848. case Instructions::memory_init.value(): {
  849. auto data_index = instruction.arguments().get<DataIndex>();
  850. auto& data_address = configuration.frame().module().datas()[data_index.value()];
  851. auto& data = *configuration.store().get(data_address);
  852. auto count = *configuration.stack().pop().get<Value>().to<i32>();
  853. auto source_offset = *configuration.stack().pop().get<Value>().to<i32>();
  854. auto destination_offset = *configuration.stack().pop().get<Value>().to<i32>();
  855. TRAP_IF_NOT(count > 0);
  856. TRAP_IF_NOT(source_offset + count > 0);
  857. TRAP_IF_NOT(static_cast<size_t>(source_offset + count) <= data.size());
  858. Instruction synthetic_store_instruction {
  859. Instructions::i32_store8,
  860. Instruction::MemoryArgument { 0, 0 }
  861. };
  862. for (size_t i = 0; i < (size_t)count; ++i) {
  863. auto value = data.data()[source_offset + i];
  864. store_to_memory(configuration, synthetic_store_instruction, { &value, sizeof(value) }, destination_offset + i);
  865. }
  866. return;
  867. }
  868. case Instructions::data_drop.value():
  869. case Instructions::memory_copy.value():
  870. case Instructions::memory_fill.value():
  871. case Instructions::table_init.value():
  872. case Instructions::elem_drop.value():
  873. case Instructions::table_copy.value():
  874. case Instructions::table_grow.value():
  875. case Instructions::table_size.value():
  876. case Instructions::table_fill.value():
  877. default:
  878. unimplemented:;
  879. dbgln("Instruction '{}' not implemented", instruction_name(instruction.opcode()));
  880. m_trap = Trap { String::formatted("Unimplemented instruction {}", instruction_name(instruction.opcode())) };
  881. return;
  882. }
  883. }
  884. void DebuggerBytecodeInterpreter::interpret(Configuration& configuration, InstructionPointer& ip, Instruction const& instruction)
  885. {
  886. if (pre_interpret_hook) {
  887. auto result = pre_interpret_hook(configuration, ip, instruction);
  888. if (!result) {
  889. m_trap = Trap { "Trapped by user request" };
  890. return;
  891. }
  892. }
  893. BytecodeInterpreter::interpret(configuration, ip, instruction);
  894. if (post_interpret_hook) {
  895. auto result = post_interpret_hook(configuration, ip, instruction, *this);
  896. if (!result) {
  897. m_trap = Trap { "Trapped by user request" };
  898. return;
  899. }
  900. }
  901. }
  902. }