25 DWORD getWindowsProtectionFlags(
unsigned Flags) {
33 return PAGE_READWRITE;
35 return PAGE_READWRITE;
37 return PAGE_EXECUTE_READ;
41 return PAGE_EXECUTE_READWRITE;
51 size_t getAllocationGranularity() {
53 ::GetSystemInfo(&Info);
54 if (Info.dwPageSize > Info.dwAllocationGranularity)
55 return Info.dwPageSize;
57 return Info.dwAllocationGranularity;
71 const MemoryBlock *
const NearBlock,
73 std::error_code &EC) {
74 EC = std::error_code();
83 static volatile size_t GranularityCached;
84 size_t Granularity = GranularityCached;
85 if (Granularity == 0) {
86 Granularity = getAllocationGranularity();
87 GranularityCached = Granularity;
90 const size_t NumBlocks = (NumBytes+Granularity-1)/Granularity;
92 uintptr_t Start = NearBlock ?
reinterpret_cast<uintptr_t
>(NearBlock->base()) +
98 if (Start && Start % Granularity != 0)
99 Start += Granularity - Start % Granularity;
101 DWORD Protect = getWindowsProtectionFlags(Flags);
103 void *PA = ::VirtualAlloc(reinterpret_cast<void*>(Start),
104 NumBlocks*Granularity,
105 MEM_RESERVE | MEM_COMMIT, Protect);
112 return MemoryBlock();
117 Result.Size = NumBlocks*Granularity;
126 if (M.Address == 0 || M.Size == 0)
127 return std::error_code();
129 if (!VirtualFree(M.Address, 0, MEM_RELEASE))
135 return std::error_code();
140 if (M.Address == 0 || M.Size == 0)
141 return std::error_code();
143 DWORD Protect = getWindowsProtectionFlags(Flags);
146 if (!VirtualProtect(M.Address, M.Size, Protect, &OldFlags))
152 return std::error_code();
159 const void *Addr,
size_t Len) {
160 FlushInstructionCache(GetCurrentProcess(), Addr, Len);
This class represents lattice values for constants.
static std::error_code releaseMappedMemory(MemoryBlock &Block)
This method releases a block of memory that was allocated with the allocateMappedMemory method...
static MemoryBlock allocateMappedMemory(size_t NumBytes, const MemoryBlock *const NearBlock, unsigned Flags, std::error_code &EC)
This method allocates a block of memory that is suitable for loading dynamically generated code (e...
static void InvalidateInstructionCache(const void *Addr, size_t Len)
InvalidateInstructionCache - Before the JIT can run a block of code that has been emitted it must inv...
Analysis containing CSE Info
std::error_code mapWindowsError(unsigned EV)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Provides a library for accessing information about this process and other processes on the operating ...
static std::error_code protectMappedMemory(const MemoryBlock &Block, unsigned Flags)
This method sets the protection flags for a block of memory to the state specified by /p Flags...