-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfasmcpp.win32.cpp
57 lines (50 loc) · 1.08 KB
/
fasmcpp.win32.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "fasmcpp.win32.h"
#include "fasmcpp.h"
#include <Windows.h>
fasmcpp::Assembler::Assembler()
{
_assemblerMemory = nullptr;
_assemblerMemorySize = 0;
}
fasmcpp::Assembler::Assembler(size_t memory, size_t)
{
try
{
_assemblerMemory = new char[memory];
_assemblerMemorySize = static_cast<uint32_t>(memory);
}
catch (const std::bad_alloc&)
{
throw std::runtime_error("Fatal error: failed to allocate memory for Flat Assembler.");
}
}
fasmcpp::Assembler::~Assembler()
{
if (_assemblerMemory)
{
delete[] _assemblerMemory;
_assemblerMemory = nullptr;
_assemblerMemorySize = 0;
}
}
void fasmcpp::Assembly::allocateExecutableMemory(size_t size)
{
void* memory = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if (memory)
{
_executableMemory = memory;
_executableMemorySize = size;
}
else
{
throw std::runtime_error("Fatal error: failed to allocate executable memory.");
}
}
void fasmcpp::Assembly::freeExecutableMemory()
{
if (_executableMemory)
{
VirtualFree(_executableMemory, 0, MEM_RELEASE);
_executableMemory = nullptr;
}
}