summaryrefslogtreecommitdiff
path: root/src/utilcode/jithost.cpp
blob: 3174aa6188037e28c52b52ef2d618431072a883e (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
70
71
72
73
74
75
76
77
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#include "stdafx.h"

#include "utilcode.h"
#include "corjit.h"
#include "jithost.h"

void* JitHost::allocateMemory(size_t size, bool usePageAllocator)
{
    WRAPPER_NO_CONTRACT;

    if (usePageAllocator)
    {
        return GetEEMemoryManager()->ClrVirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE);
    }
    else
    {
        return ClrAllocInProcessHeap(0, S_SIZE_T(size));
    }
}

void JitHost::freeMemory(void* block, bool usePageAllocator)
{
    WRAPPER_NO_CONTRACT;

    if (usePageAllocator)
    {
        GetEEMemoryManager()->ClrVirtualFree(block, 0, MEM_RELEASE);
    }
    else
    {
        ClrFreeInProcessHeap(0, block);
    }
}

int JitHost::getIntConfigValue(const wchar_t* name, int defaultValue)
{
    WRAPPER_NO_CONTRACT;

    // Translate JIT call into runtime configuration query
    CLRConfig::ConfigDWORDInfo info{ name, defaultValue, CLRConfig::EEConfig_default };

    // Perform a CLRConfig look up on behalf of the JIT.
    return CLRConfig::GetConfigValue(info);
}

const wchar_t* JitHost::getStringConfigValue(const wchar_t* name)
{
    WRAPPER_NO_CONTRACT;

    // Translate JIT call into runtime configuration query
    CLRConfig::ConfigStringInfo info{ name, CLRConfig::EEConfig_default };

    // Perform a CLRConfig look up on behalf of the JIT.
    return CLRConfig::GetConfigValue(info);
}

void JitHost::freeStringConfigValue(const wchar_t* value)
{
    WRAPPER_NO_CONTRACT;

    CLRConfig::FreeConfigString(const_cast<wchar_t*>(value));
}

JitHost JitHost::theJitHost;
ICorJitHost* JitHost::getJitHost()
{
    STATIC_CONTRACT_SO_TOLERANT;
    STATIC_CONTRACT_GC_NOTRIGGER;
    STATIC_CONTRACT_NOTHROW;
    STATIC_CONTRACT_CANNOT_TAKE_LOCK;

    return &theJitHost;
}