summaryrefslogtreecommitdiff
path: root/src/ToolBox/superpmi/superpmi/coreclrcallbacks.cpp
blob: 7a66d20940f1e5df83106f91ffadb0df78748ec1 (plain)
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
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

#include "standardpch.h"
#include "spmiutil.h"
#include "coreclrcallbacks.h"
#include "iexecutionengine.h"

IExecutionEngine* STDMETHODCALLTYPE IEE_t()
{
    MyIEE *iee = InitIExecutionEngine();
    return iee;
}

/*#pragma warning( suppress :4996 ) //deprecated
HRESULT STDMETHODCALLTYPE GetCORSystemDirectory(LPWSTR pbuffer, DWORD cchBuffer, DWORD* pdwlength)
{
    DebugBreakorAV(131);
    return 0;
}
*/

HANDLE ourHeap = nullptr;

LPVOID STDMETHODCALLTYPE EEHeapAllocInProcessHeap (DWORD dwFlags, SIZE_T dwBytes)
{
   if(ourHeap==nullptr)
       ourHeap = HeapCreate(0, 4096 ,0);
   if(ourHeap==nullptr)
   {
       LogError("HeapCreate Failed");
       __debugbreak();
       return nullptr;
   }
   LPVOID result = HeapAlloc(ourHeap, dwFlags, dwBytes);
//   LogDebug("EEHeapAllocInProcessHeap %p %u %u", result, dwFlags, dwBytes);
   return result;
}

BOOL STDMETHODCALLTYPE EEHeapFreeInProcessHeap (DWORD dwFlags, LPVOID lpMem)
{
//  return true;
    return HeapFree(ourHeap, dwFlags, lpMem);
}

void* STDMETHODCALLTYPE GetCLRFunction(LPCSTR functionName)
{
    if(strcmp(functionName, "EEHeapAllocInProcessHeap")==0)
        return (void*)EEHeapAllocInProcessHeap;
    if(strcmp(functionName, "EEHeapFreeInProcessHeap")==0)
        return (void*)EEHeapFreeInProcessHeap;
    DebugBreakorAV(132);
    return nullptr;
}

CoreClrCallbacks *InitCoreClrCallbacks()
{
    CoreClrCallbacks *temp = new CoreClrCallbacks();
    ::ZeroMemory(temp, sizeof(CoreClrCallbacks));

    temp->m_hmodCoreCLR = (HINSTANCE)(size_t)0xbadbad01; // any non-null value seems okay...
    temp->m_pfnIEE = IEE_t;
    temp->m_pfnGetCORSystemDirectory = nullptr;//GetCORSystemDirectory;
    temp->m_pfnGetCLRFunction = GetCLRFunction;

    return temp;
}