diff options
| author | 2018-04-06 14:26:03 +0000 | |
|---|---|---|
| committer | 2018-04-06 14:26:03 +0000 | |
| commit | bdabc2f19ffb9e20600dad6e8a300842a7bda50e (patch) | |
| tree | c50e7b2e5449b074651bb82a58517a8ebc4a8cf7 /gnu/llvm/lib/Support/Windows/Memory.inc | |
| parent | Print a 'p' flag for file descriptors that were opened after pledge(2). (diff) | |
| download | wireguard-openbsd-bdabc2f19ffb9e20600dad6e8a300842a7bda50e.tar.xz wireguard-openbsd-bdabc2f19ffb9e20600dad6e8a300842a7bda50e.zip | |
Import LLVM 6.0.1 release including clang, lld and lldb.
"where is the kaboom?" deraadt@
Diffstat (limited to 'gnu/llvm/lib/Support/Windows/Memory.inc')
| -rw-r--r-- | gnu/llvm/lib/Support/Windows/Memory.inc | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/gnu/llvm/lib/Support/Windows/Memory.inc b/gnu/llvm/lib/Support/Windows/Memory.inc index 7eab9ff3afd..318e65aaa9e 100644 --- a/gnu/llvm/lib/Support/Windows/Memory.inc +++ b/gnu/llvm/lib/Support/Windows/Memory.inc @@ -160,85 +160,5 @@ void Memory::InvalidateInstructionCache( FlushInstructionCache(GetCurrentProcess(), Addr, Len); } - -MemoryBlock Memory::AllocateRWX(size_t NumBytes, - const MemoryBlock *NearBlock, - std::string *ErrMsg) { - MemoryBlock MB; - std::error_code EC; - MB = allocateMappedMemory(NumBytes, NearBlock, - MF_READ|MF_WRITE|MF_EXEC, EC); - if (EC != std::error_code() && ErrMsg) { - MakeErrMsg(ErrMsg, EC.message()); - } - return MB; -} - -bool Memory::ReleaseRWX(MemoryBlock &M, std::string *ErrMsg) { - std::error_code EC = releaseMappedMemory(M); - if (EC == std::error_code()) - return false; - MakeErrMsg(ErrMsg, EC.message()); - return true; -} - -static DWORD getProtection(const void *addr) { - MEMORY_BASIC_INFORMATION info; - if (sizeof(info) == ::VirtualQuery(addr, &info, sizeof(info))) { - return info.Protect; - } - return 0; -} - -bool Memory::setWritable(MemoryBlock &M, std::string *ErrMsg) { - if (!setRangeWritable(M.Address, M.Size)) { - return MakeErrMsg(ErrMsg, "Cannot set memory to writeable"); - } - return true; -} - -bool Memory::setExecutable(MemoryBlock &M, std::string *ErrMsg) { - if (!setRangeExecutable(M.Address, M.Size)) { - return MakeErrMsg(ErrMsg, "Cannot set memory to executable"); - } - return true; -} - -bool Memory::setRangeWritable(const void *Addr, size_t Size) { - DWORD prot = getProtection(Addr); - if (!prot) - return false; - - if (prot == PAGE_EXECUTE || prot == PAGE_EXECUTE_READ) { - prot = PAGE_EXECUTE_READWRITE; - } else if (prot == PAGE_NOACCESS || prot == PAGE_READONLY) { - prot = PAGE_READWRITE; - } - - DWORD oldProt; - Memory::InvalidateInstructionCache(Addr, Size); - return ::VirtualProtect(const_cast<LPVOID>(Addr), Size, prot, &oldProt) - == TRUE; -} - -bool Memory::setRangeExecutable(const void *Addr, size_t Size) { - DWORD prot = getProtection(Addr); - if (!prot) - return false; - - if (prot == PAGE_NOACCESS) { - prot = PAGE_EXECUTE; - } else if (prot == PAGE_READONLY) { - prot = PAGE_EXECUTE_READ; - } else if (prot == PAGE_READWRITE) { - prot = PAGE_EXECUTE_READWRITE; - } - - DWORD oldProt; - Memory::InvalidateInstructionCache(Addr, Size); - return ::VirtualProtect(const_cast<LPVOID>(Addr), Size, prot, &oldProt) - == TRUE; -} - } // namespace sys } // namespace llvm |
