8000 Do not allocate the buffer for the code on the stack · randomstuff/unjit@fd900c5 · GitHub
[go: up one dir, main page]

Skip to content

Commit fd900c5

Browse files
author
Gabriel Corona
committed
Do not allocate the buffer for the code on the stack
Use the heap instead.
1 parent 49567f3 commit fd900c5

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/Disassembler.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ void Disassembler::disassemble(std::ostream& stream, std::uint64_t start, std::u
9898

9999
void Disassembler::disassemble(std::ostream& stream, Symbol const& symbol)
100100
{
101-
uint8_t buffer[symbol.size];
101+
if (this->buffer_.size() < symbol.size)
102+
this->buffer_.resize(symbol.size);
103+
102104
struct iovec local, remote;
103105

104-
local.iov_base = buffer;
106+
local.iov_base = this->buffer_.data();
105107
local.iov_len = symbol.size;
106108

107109
remote.iov_base = (void*) symbol.value;
@@ -114,7 +116,7 @@ void Disassembler::disassemble(std::ostream& stream, Symbol const& symbol)
114116
}
115117

116118
stream << std::hex << symbol.value << '<' << symbol.name << ">\n";
117-
this->disassemble(stream, buffer, symbol.size, symbol.value);
119+
this->disassemble(stream, this->buffer_.data(), symbol.size, symbol.value);
118120
stream << '\n';
119121
}
120122

src/unjit.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class Disassembler {
160160
private:
161161
Process* process_;
162162
LLVMDisasmContextRef disassembler_;
163+
std::vector<std::uint8_t> buffer_;
163164
public:
164165
Disassembler(Process& process);
165166
~Disassembler();

0 commit comments

Comments
 (0)
0