1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:07:34 +00:00

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. :^)
This commit is contained in:
Andreas Kling 2021-06-07 15:24:33 +02:00
parent 4ba2eb8fe5
commit 312297ac38
3 changed files with 9 additions and 0 deletions

View file

@ -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());

View file

@ -42,6 +42,7 @@ public:
static NonnullOwnPtr<Block> create();
~Block();
void seal();
void dump() const;
ReadonlyBytes instruction_stream() const { return ReadonlyBytes { m_buffer, m_buffer_size }; }

View file

@ -28,6 +28,7 @@ OwnPtr<Block> 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);
}