-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathPDataManager.cpp
83 lines (73 loc) · 2.73 KB
/
PDataManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "Backend.h"
// Conditionally-compiled on x64 and arm/arm64
#if PDATA_ENABLED
#ifdef _WIN32
// ----------------------------------------------------------------------------
// _WIN32 x64 unwind uses PDATA
// ----------------------------------------------------------------------------
void PDataManager::RegisterPdata(RUNTIME_FUNCTION* pdataStart, _In_ const ULONG_PTR functionStart, _In_ const ULONG_PTR functionEnd, _Out_ PVOID* pdataTable, ULONG entryCount, ULONG maxEntryCount)
{
BOOLEAN success = FALSE;
HRESULT hr = S_OK;
if (AutoSystemInfo::Data.IsWin8OrLater())
{
Assert(pdataTable != NULL);
// Since we do not expect many thunk functions to be created, we are using 1 table/function
// for now. This can be optimized further if needed.
NTSTATUS status = NtdllLibrary::Instance->AddGrowableFunctionTable(pdataTable,
pdataStart,
entryCount,
maxEntryCount,
/*RangeBase*/ functionStart,
/*RangeEnd*/ functionEnd);
success = NT_SUCCESS(status);
Assert(!success || pdataTable);
hr = status;
}
else
{
*pdataTable = pdataStart;
success = RtlAddFunctionTable(pdataStart, entryCount, functionStart);
if (!success)
{
hr = E_OUTOFMEMORY; // only OOM error can happen for RtlAddFunctionTable
}
}
if (!success)
{
Js::Throw::XDataRegistrationError(hr, functionStart);
}
}
void PDataManager::UnregisterPdata(RUNTIME_FUNCTION* pdata)
{
if (AutoSystemInfo::Data.IsWin8OrLater())
{
NtdllLibrary::Instance->DeleteGrowableFunctionTable(pdata);
}
else
{
BOOLEAN success = RtlDeleteFunctionTable(pdata);
Assert(success);
}
}
#else // !_WIN32
// ----------------------------------------------------------------------------
// !_WIN32 x64 unwind uses .eh_frame
// ----------------------------------------------------------------------------
void PDataManager::RegisterPdata(RUNTIME_FUNCTION* pdataStart,
_In_ const ULONG_PTR functionStart, _In_ const ULONG_PTR functionEnd,
_Out_ PVOID* pdataTable, ULONG entryCount, ULONG maxEntryCount)
{
__REGISTER_FRAME(pdataStart);
*pdataTable = pdataStart;
}
void PDataManager::UnregisterPdata(RUNTIME_FUNCTION* pdata)
{
__DEREGISTER_FRAME(pdata);
}
#endif // !_WIN32
#endif // PDATA_ENABLED