From 312297ac38eb67dd06802590b31ef0eb25f66708 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 7 Jun 2021 15:24:33 +0200 Subject: [PATCH] LibJS: Add placeholder bytecode block sealing mechanism After compiling bytecode, we should mark the memory read-only. This currently does not work because it breaks instruction destruction. I'm adding this anyway with a FIXME so we don't forget about it. :^) --- Userland/Libraries/LibJS/Bytecode/Block.cpp | 7 +++++++ Userland/Libraries/LibJS/Bytecode/Block.h | 1 + Userland/Libraries/LibJS/Bytecode/Generator.cpp | 1 + 3 files changed, 9 insertions(+) diff --git a/Userland/Libraries/LibJS/Bytecode/Block.cpp b/Userland/Libraries/LibJS/Bytecode/Block.cpp index cc28e7cb44..ba22762228 100644 --- a/Userland/Libraries/LibJS/Bytecode/Block.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Block.cpp @@ -36,6 +36,13 @@ Block::~Block() } } +void Block::seal() +{ + // FIXME: mprotect the instruction stream as PROT_READ + // This is currently not possible because instructions can have destructors (that clean up strings) + // Instructions should instead be destructor-less and refer to strings in a string table on the Bytecode::Block. +} + void Block::dump() const { Bytecode::InstructionStreamIterator it(instruction_stream()); diff --git a/Userland/Libraries/LibJS/Bytecode/Block.h b/Userland/Libraries/LibJS/Bytecode/Block.h index 27349a46f1..9a13175e24 100644 --- a/Userland/Libraries/LibJS/Bytecode/Block.h +++ b/Userland/Libraries/LibJS/Bytecode/Block.h @@ -42,6 +42,7 @@ public: static NonnullOwnPtr create(); ~Block(); + void seal(); void dump() const; ReadonlyBytes instruction_stream() const { return ReadonlyBytes { m_buffer, m_buffer_size }; } diff --git a/Userland/Libraries/LibJS/Bytecode/Generator.cpp b/Userland/Libraries/LibJS/Bytecode/Generator.cpp index c60716fc93..6b43bf3002 100644 --- a/Userland/Libraries/LibJS/Bytecode/Generator.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Generator.cpp @@ -28,6 +28,7 @@ OwnPtr Generator::generate(ASTNode const& node) Generator generator; [[maybe_unused]] auto dummy = node.generate_bytecode(generator); generator.m_block->set_register_count({}, generator.m_next_register); + generator.m_block->seal(); return move(generator.m_block); }