diff --git a/src/backend_x64/block_of_code.cpp b/src/backend_x64/block_of_code.cpp index 928244d3..738c47cf 100644 --- a/src/backend_x64/block_of_code.cpp +++ b/src/backend_x64/block_of_code.cpp @@ -4,6 +4,7 @@ * General Public License version 2 or any later version. */ +#include #include #include @@ -227,6 +228,17 @@ void BlockOfCode::nop(size_t size) { } } +void* BlockOfCode::alloc(size_t alloc_size) { + if (size_ + alloc_size >= maxSize_) { + throw Xbyak::Error(Xbyak::ERR_CODE_IS_TOO_BIG); + } + + void* ret = getCurr(); + size_ += alloc_size; + memset(ret, 0, alloc_size); + return ret; +} + void BlockOfCode::SetCodePtr(CodePtr code_ptr) { // The "size" defines where top_, the insertion point, is. size_t required_size = reinterpret_cast(code_ptr) - getCode(); diff --git a/src/backend_x64/block_of_code.h b/src/backend_x64/block_of_code.h index d25aaa93..1db798d5 100644 --- a/src/backend_x64/block_of_code.h +++ b/src/backend_x64/block_of_code.h @@ -127,6 +127,7 @@ public: void int3() { db(0xCC); } void nop(size_t size = 1); + void* alloc(size_t size); void SetCodePtr(CodePtr code_ptr); void EnsurePatchLocationSize(CodePtr begin, size_t size);