mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:17:35 +00:00
LibJS: Seal Bytecode Blocks and munmap them (#7919)
This commit is contained in:
parent
064ed8279e
commit
c6ce7c9326
2 changed files with 19 additions and 5 deletions
|
@ -28,19 +28,31 @@ Block::Block()
|
||||||
|
|
||||||
Block::~Block()
|
Block::~Block()
|
||||||
{
|
{
|
||||||
|
unseal();
|
||||||
Bytecode::InstructionStreamIterator it(instruction_stream());
|
Bytecode::InstructionStreamIterator it(instruction_stream());
|
||||||
while (!it.at_end()) {
|
while (!it.at_end()) {
|
||||||
auto& to_destroy = (*it);
|
auto& to_destroy = (*it);
|
||||||
++it;
|
++it;
|
||||||
Instruction::destroy(const_cast<Instruction&>(to_destroy));
|
Instruction::destroy(const_cast<Instruction&>(to_destroy));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
munmap(m_buffer, m_buffer_capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Block::seal()
|
void Block::seal() const
|
||||||
{
|
{
|
||||||
// FIXME: mprotect the instruction stream as PROT_READ
|
if (mprotect(m_buffer, m_buffer_capacity, PROT_READ) < 0) {
|
||||||
// This is currently not possible because instructions can have destructors (that clean up strings)
|
perror("ByteCode::Block::seal: mprotect");
|
||||||
// Instructions should instead be destructor-less and refer to strings in a string table on the Bytecode::Block.
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Block::unseal()
|
||||||
|
{
|
||||||
|
if (mprotect(m_buffer, m_buffer_capacity, PROT_READ | PROT_WRITE) < 0) {
|
||||||
|
perror("ByteCode::Block::unseal: mprotect");
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Block::dump() const
|
void Block::dump() const
|
||||||
|
|
|
@ -42,7 +42,9 @@ public:
|
||||||
static NonnullOwnPtr<Block> create();
|
static NonnullOwnPtr<Block> create();
|
||||||
~Block();
|
~Block();
|
||||||
|
|
||||||
void seal();
|
void seal() const;
|
||||||
|
void unseal();
|
||||||
|
|
||||||
void dump() const;
|
void dump() const;
|
||||||
ReadonlyBytes instruction_stream() const { return ReadonlyBytes { m_buffer, m_buffer_size }; }
|
ReadonlyBytes instruction_stream() const { return ReadonlyBytes { m_buffer, m_buffer_size }; }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue