PDataManager.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #include "Backend.h"
  6. // Conditionally-compiled on x64 and arm
  7. #if PDATA_ENABLED
  8. void PDataManager::RegisterPdata(RUNTIME_FUNCTION* pdataStart, _In_ const ULONG_PTR functionStart, _In_ const ULONG_PTR functionEnd, _Out_ PVOID* pdataTable, ULONG entryCount, ULONG maxEntryCount)
  9. {
  10. BOOLEAN success = FALSE;
  11. if (AutoSystemInfo::Data.IsWin8OrLater())
  12. {
  13. Assert(pdataTable != NULL);
  14. // Since we do not expect many thunk functions to be created, we are using 1 table/function
  15. // for now. This can be optimized further if needed.
  16. DWORD status = NtdllLibrary::Instance->AddGrowableFunctionTable(pdataTable,
  17. pdataStart,
  18. entryCount,
  19. maxEntryCount,
  20. /*RangeBase*/ functionStart,
  21. /*RangeEnd*/ functionEnd);
  22. success = NT_SUCCESS(status);
  23. if (success)
  24. {
  25. Assert(pdataTable);
  26. }
  27. }
  28. else
  29. {
  30. *pdataTable = pdataStart;
  31. success = RtlAddFunctionTable(pdataStart, entryCount, functionStart);
  32. }
  33. Js::Throw::CheckAndThrowOutOfMemory(success);
  34. }
  35. void PDataManager::UnregisterPdata(RUNTIME_FUNCTION* pdata)
  36. {
  37. if (AutoSystemInfo::Data.IsWin8OrLater())
  38. {
  39. NtdllLibrary::Instance->DeleteGrowableFunctionTable(pdata);
  40. }
  41. else
  42. {
  43. BOOLEAN success = RtlDeleteFunctionTable(pdata);
  44. Assert(success);
  45. }
  46. }
  47. #endif