Debian Codegraph @

Source/Core/Common/MemoryUtil.h

raw symbols SCIP
1 // Copyright 2008 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <cstddef>
7 #include <string>
8
9 namespace Common
10 {
11 void* AllocateExecutableMemory(size_t size);
12
13 // These two functions control the executable/writable state of the W^X memory
14 // allocations. More detailed documentation about them is in the .cpp file.
15 // In general where applicable the ScopedJITPageWriteAndNoExecute wrapper
16 // should be used to prevent bugs from not pairing up the calls properly.
17
18 // Allows a thread to write to executable memory, but not execute the data.
19 void JITPageWriteEnableExecuteDisable();
20 // Allows a thread to execute memory allocated for execution, but not write to it.
21 void JITPageWriteDisableExecuteEnable();
22 // RAII Wrapper around JITPageWrite*Execute*(). When this is in scope the thread can
23 // write to executable memory but not execute it.
24 struct ScopedJITPageWriteAndNoExecute
25 {
26 ScopedJITPageWriteAndNoExecute() { JITPageWriteEnableExecuteDisable(); }
27 ~ScopedJITPageWriteAndNoExecute() { JITPageWriteDisableExecuteEnable(); }
28 };
29 void* AllocateMemoryPages(size_t size);
30 bool FreeMemoryPages(void* ptr, size_t size);
31 void* AllocateAlignedMemory(size_t size, size_t alignment);
32 void FreeAlignedMemory(void* ptr);
33 bool ReadProtectMemory(void* ptr, size_t size);
34 bool WriteProtectMemory(void* ptr, size_t size, bool executable = false);
35 bool UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute = false);
36 size_t MemPhysical();
37
38 } // namespace Common