summaryrefslogtreecommitdiff
path: root/src/vm/compatibilityswitch.cpp
blob: 0c825eea2dafb3d476695c117e94206ba6fc4004 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//


#include "common.h"
#include "clrconfig.h"
#include "compatibilityswitch.h"

FCIMPL2(FC_BOOL_RET, CompatibilitySwitch::IsEnabled, StringObject* switchNameUNSAFE, CLR_BOOL onlyDB)
{
    FCALL_CONTRACT;

    if (!switchNameUNSAFE)
        FCThrowRes(kArgumentNullException, W("Arg_InvalidSwitchName"));

    BOOL result = TRUE;

    STRINGREF name = (STRINGREF) switchNameUNSAFE;
    VALIDATEOBJECTREF(name);

    HELPER_METHOD_FRAME_BEGIN_RET_1(name);

    CLRConfig::ConfigDWORDInfo info;
    info.name = name->GetBuffer();
    if(onlyDB)
    {
        // for public managed apis we ignore checking in registry/config/env
        // only check in windows appcompat DB
        info.options = CLRConfig::IgnoreEnv | 
                       CLRConfig::IgnoreHKLM |
                       CLRConfig::IgnoreHKCU |
                       CLRConfig::IgnoreConfigFiles; 
    }
    else
    {
        // for mscorlib (i.e. which use internal apis) also check in 
        // registry/config/env in addition to windows appcompat DB
        info.options = CLRConfig::EEConfig_default;
    }

    // default value is disabled
    info.defaultValue = 0;
    result = CLRConfig::IsConfigEnabled(info);
    HELPER_METHOD_FRAME_END();
   
    FC_RETURN_BOOL(result);
}
FCIMPLEND


FCIMPL2(StringObject*, CompatibilitySwitch::GetValue, StringObject* switchNameUNSAFE, CLR_BOOL onlyDB) {
    CONTRACTL {
        FCALL_CHECK;
    }
    CONTRACTL_END;
        
    if (!switchNameUNSAFE)
        FCThrowRes(kArgumentNullException, W("Arg_InvalidSwitchName"));

    STRINGREF name = (STRINGREF) switchNameUNSAFE;
    VALIDATEOBJECTREF(name);
        
    STRINGREF refName = NULL;

    HELPER_METHOD_FRAME_BEGIN_RET_1(name);
    CLRConfig::ConfigStringInfo info;
    info.name = name->GetBuffer();
    if(onlyDB)
    {
        // for public managed apis we ignore checking in registry/config/env
        // only check in windows appcompat DB
        info.options = CLRConfig::IgnoreEnv | 
                       CLRConfig::IgnoreHKLM |
                       CLRConfig::IgnoreHKCU |
                       CLRConfig::IgnoreConfigFiles; 
    }
    else
    {
        // for mscorlib (i.e. which use internal apis) also check in 
        // registry/config/env in addition to windows appcompat DB
        info.options = CLRConfig::EEConfig_default;
    }
    LPWSTR strVal = CLRConfig::GetConfigValue(info);
    refName = StringObject::NewString(strVal);
    HELPER_METHOD_FRAME_END();            
    
    return (StringObject*)OBJECTREFToObject(refName);
}
FCIMPLEND

FCIMPL0(StringObject*, CompatibilitySwitch::GetAppContextOverrides) {
    CONTRACTL{
        FCALL_CHECK;
    }
    CONTRACTL_END;

    STRINGREF refName = NULL;

    HELPER_METHOD_FRAME_BEGIN_RET_0();
    LPWSTR strVal = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_AppContextSwitchOverrides);
    refName = StringObject::NewString(strVal);
    HELPER_METHOD_FRAME_END();

    return (StringObject*)OBJECTREFToObject(refName);
}
FCIMPLEND