summaryrefslogtreecommitdiff
path: root/packaging/0004-LoaderHeap-remove-LHF_ZEROINIT-option.patch
blob: f104f98e8b5fa3424fad7dbb70787cac57ce4563 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
From 81116227de9850ea4ef4a3aefa911bdea6127d07 Mon Sep 17 00:00:00 2001
From: Konstantin Baladurin <k.baladurin@partner.samsung.com>
Date: Fri, 12 Jan 2018 19:11:05 +0300
Subject: [PATCH 04/47] LoaderHeap: remove LHF_ZEROINIT option.

This option was used for UMEntryThunkCode::Poison. Now we use own free list
to store freed thunks and don't return allocated memory to the LoaderHeap.
So reused thunks are always uninitialized.
---
 src/inc/loaderheap.h         | 17 +++++------------
 src/utilcode/loaderheap.cpp  | 19 ++++---------------
 src/vm/dllimportcallback.cpp |  1 -
 src/vm/loaderallocator.cpp   |  3 +--
 4 files changed, 10 insertions(+), 30 deletions(-)

diff --git a/src/inc/loaderheap.h b/src/inc/loaderheap.h
index 4333505..5bdbe8c 100644
--- a/src/inc/loaderheap.h
+++ b/src/inc/loaderheap.h
@@ -288,8 +288,7 @@ protected:
                        SIZE_T dwReservedRegionSize,
                        size_t *pPrivatePerfCounter_LoaderBytes = NULL,
                        RangeList *pRangeList = NULL,
-                       BOOL fMakeExecutable = FALSE,
-                       BOOL fZeroInit = TRUE);
+                       BOOL fMakeExecutable = FALSE);
 
     ~UnlockedLoaderHeap();
 #endif
@@ -400,8 +399,6 @@ public:
     }
 
     BOOL IsExecutable();
-    BOOL IsZeroInit();
-
 
 public:
 #ifdef _DEBUG
@@ -446,16 +443,14 @@ public:
                DWORD dwCommitBlockSize,
                size_t *pPrivatePerfCounter_LoaderBytes = NULL,
                RangeList *pRangeList = NULL,
-               BOOL fMakeExecutable = FALSE,
-               BOOL fZeroInit = TRUE
+               BOOL fMakeExecutable = FALSE
                )
       : UnlockedLoaderHeap(dwReserveBlockSize,
                            dwCommitBlockSize,
                            NULL, 0,
                            pPrivatePerfCounter_LoaderBytes,
                            pRangeList,
-                           fMakeExecutable,
-                           fZeroInit)
+                           fMakeExecutable)
     {
         WRAPPER_NO_CONTRACT;
         m_CriticalSection = NULL;
@@ -470,8 +465,7 @@ public:
                SIZE_T dwReservedRegionSize,
                size_t *pPrivatePerfCounter_LoaderBytes = NULL,
                RangeList *pRangeList = NULL,
-               BOOL fMakeExecutable = FALSE,
-               BOOL fZeroInit = TRUE
+               BOOL fMakeExecutable = FALSE
                )
       : UnlockedLoaderHeap(dwReserveBlockSize,
                            dwCommitBlockSize,
@@ -479,8 +473,7 @@ public:
                            dwReservedRegionSize,
                            pPrivatePerfCounter_LoaderBytes,
                            pRangeList,
-                           fMakeExecutable,
-                           fZeroInit)
+                           fMakeExecutable)
     {
         WRAPPER_NO_CONTRACT;
         m_CriticalSection = NULL;
diff --git a/src/utilcode/loaderheap.cpp b/src/utilcode/loaderheap.cpp
index 21aa150..4033c86 100644
--- a/src/utilcode/loaderheap.cpp
+++ b/src/utilcode/loaderheap.cpp
@@ -11,7 +11,6 @@
 #include "eventtracebase.h"
 
 #define LHF_EXECUTABLE  0x1
-#define LHF_ZEROINIT    0x2
 
 #ifndef DACCESS_COMPILE
 
@@ -906,8 +905,7 @@ UnlockedLoaderHeap::UnlockedLoaderHeap(DWORD dwReserveBlockSize,
                                        SIZE_T dwReservedRegionSize, 
                                        size_t *pPrivatePerfCounter_LoaderBytes,
                                        RangeList *pRangeList,
-                                       BOOL fMakeExecutable,
-                                       BOOL fZeroInit)
+                                       BOOL fMakeExecutable)
 {
     CONTRACTL
     {
@@ -946,9 +944,6 @@ UnlockedLoaderHeap::UnlockedLoaderHeap(DWORD dwReserveBlockSize,
     m_Options                    = 0;
     if (fMakeExecutable)
         m_Options                |= LHF_EXECUTABLE;
-    if (fZeroInit)
-        m_Options                |= LHF_ZEROINIT;
-
     m_pFirstFreeBlock            = NULL;
 
     if (dwReservedRegionAddress != NULL && dwReservedRegionSize > 0)
@@ -1356,7 +1351,7 @@ again:
             // Don't fill the memory we allocated - it is assumed to be zeroed - fill the memory after it
             memset(pAllocatedBytes + dwRequestedSize, 0xEE, LOADER_HEAP_DEBUG_BOUNDARY);
 #endif
-            if ((dwRequestedSize > 0) && (m_Options & LHF_ZEROINIT))
+            if (dwRequestedSize > 0)
             {
                 _ASSERTE_MSG(pAllocatedBytes[0] == 0 && memcmp(pAllocatedBytes, pAllocatedBytes + 1, dwRequestedSize - 1) == 0,
                     "LoaderHeap must return zero-initialized memory");
@@ -1534,8 +1529,7 @@ void UnlockedLoaderHeap::UnlockedBackoutMem(void *pMem,
     {
         // Cool. This was the last block allocated. We can just undo the allocation instead
         // of going to the freelist.
-        if (m_Options & LHF_ZEROINIT)
-            memset(pMem, 0x00, dwSize); // Fill freed region with 0
+        memset(pMem, 0x00, dwSize); // Fill freed region with 0
         m_pAllocPtr = (BYTE*)pMem;
     }
     else
@@ -1653,7 +1647,7 @@ void *UnlockedLoaderHeap::UnlockedAllocAlignedMem_NoThrow(size_t  dwRequestedSiz
     memset(pAllocatedBytes + dwRequestedSize, 0xee, LOADER_HEAP_DEBUG_BOUNDARY);
 #endif
 
-    if ((dwRequestedSize != 0) && (m_Options & LHF_ZEROINIT))
+    if (dwRequestedSize != 0)
     {
         _ASSERTE_MSG(pAllocatedBytes[0] == 0 && memcmp(pAllocatedBytes, pAllocatedBytes + 1, dwRequestedSize - 1) == 0,
             "LoaderHeap must return zero-initialized memory");
@@ -1778,11 +1772,6 @@ BOOL UnlockedLoaderHeap::IsExecutable()
     return (m_Options & LHF_EXECUTABLE);
 }
 
-BOOL UnlockedLoaderHeap::IsZeroInit()
-{
-    return (m_Options & LHF_ZEROINIT);
-}
-
 #ifdef DACCESS_COMPILE
 
 void UnlockedLoaderHeap::EnumMemoryRegions(CLRDataEnumMemoryFlags flags)
diff --git a/src/vm/dllimportcallback.cpp b/src/vm/dllimportcallback.cpp
index 8623d46..2becba5 100644
--- a/src/vm/dllimportcallback.cpp
+++ b/src/vm/dllimportcallback.cpp
@@ -1153,7 +1153,6 @@ void UMEntryThunk::Terminate()
     }
     CONTRACTL_END;
 
-    _ASSERTE(!SystemDomain::GetGlobalLoaderAllocator()->GetExecutableHeap()->IsZeroInit());
     m_code.Poison();
 
     s_thunkFreeList.AddToList(this);
diff --git a/src/vm/loaderallocator.cpp b/src/vm/loaderallocator.cpp
index 5a3f8f5..2264dc1 100644
--- a/src/vm/loaderallocator.cpp
+++ b/src/vm/loaderallocator.cpp
@@ -1005,8 +1005,7 @@ void LoaderAllocator::Init(BaseDomain *pDomain, BYTE *pExecutableHeapMemory)
                                                                       dwExecutableHeapReserveSize,
                                                                       LOADERHEAP_PROFILE_COUNTER,
                                                                       NULL,
-                                                                      TRUE /* Make heap executable */,
-                                                                      FALSE /* Disable zero-initialization (needed by UMEntryThunkCode::Poison) */
+                                                                      TRUE /* Make heap executable */
                                                                       );
         initReservedMem += dwExecutableHeapReserveSize;
     }
-- 
2.7.4