mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
FunctionPointerVariableHook: use VirtualAlloc instead of HeapAlloc
This commit is contained in:
parent
8781183eaa
commit
325b3d551d
2 changed files with 8 additions and 8 deletions
|
|
@ -58,7 +58,14 @@ internal class FunctionPointerVariableHook<T> : Hook<T>
|
|||
|
||||
unsafe
|
||||
{
|
||||
var pfnThunkBytes = (byte*)NativeFunctions.HeapAlloc(HookManager.NoFreeExecutableHeap, 0, 12);
|
||||
// Note: WINE seemingly tries to clean up all heap allocations on process exit.
|
||||
// We want our allocation to be kept there forever, until no running thread remains.
|
||||
// Therefore we're using VirtualAlloc instead of HeapCreate/HeapAlloc.
|
||||
var pfnThunkBytes = (byte*)NativeFunctions.VirtualAlloc(
|
||||
0,
|
||||
12,
|
||||
NativeFunctions.AllocationType.Reserve | NativeFunctions.AllocationType.Commit,
|
||||
MemoryProtection.ExecuteReadWrite);
|
||||
if (pfnThunkBytes == null)
|
||||
{
|
||||
throw new OutOfMemoryException("Failed to allocate memory for import hooks.");
|
||||
|
|
|
|||
|
|
@ -16,13 +16,6 @@ namespace Dalamud.Hooking.Internal;
|
|||
[ServiceManager.EarlyLoadedService]
|
||||
internal class HookManager : IDisposable, IServiceType
|
||||
{
|
||||
/// <summary>
|
||||
/// Handle to an executable heap that we shall never free anything unless we can be absolutely sure that nothing is
|
||||
/// referencing to it anymore.
|
||||
/// </summary>
|
||||
internal static readonly nint NoFreeExecutableHeap =
|
||||
NativeFunctions.HeapCreate(NativeFunctions.HeapOptions.CreateEnableExecute, 0, 0);
|
||||
|
||||
private static readonly ModuleLog Log = new("HM");
|
||||
|
||||
[ServiceManager.ServiceConstructor]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue