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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
|
// 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.
// --------------------------------------------------------------------------------
// PEImage.inl
//
// --------------------------------------------------------------------------------
#ifndef PEIMAGE_INL_
#define PEIMAGE_INL_
#include "peimage.h"
#include "../dlls/mscorrc/resource.h"
inline ULONG PEImage::AddRef()
{
CONTRACT(ULONG)
{
PRECONDITION(m_refCount>0 && m_refCount < COUNT_T_MAX);
NOTHROW;
GC_NOTRIGGER;
}
CONTRACT_END;
RETURN (static_cast<ULONG>(FastInterlockIncrement(&m_refCount)));
}
inline const SString &PEImage::GetPath()
{
LIMITED_METHOD_DAC_CONTRACT;
STATIC_CONTRACT_SO_TOLERANT;
return m_path;
}
inline void PEImage::SetModuleFileNameHintForDAC()
{
LIMITED_METHOD_DAC_CONTRACT;
STATIC_CONTRACT_SO_INTOLERANT;
// Grab module name only for triage dumps where full paths are excluded
// because may contain PII data.
// m_sModuleFileNameHintUsedByDac will just point to module name starting character.
const WCHAR* pStartPath = m_path.GetUnicode();
COUNT_T nChars = m_path.GetCount();
if (pStartPath != NULL && nChars > 0 && nChars <= MAX_PATH)
{
const WCHAR* pChar = pStartPath + nChars;
nChars = 0;
while ((pChar >= pStartPath) && (*pChar != L'\\'))
{
pChar--;
nChars++;
}
pChar++;
m_sModuleFileNameHintUsedByDac.SetPreallocated(pChar, nChars);
}
}
#ifdef DACCESS_COMPILE
inline const SString &PEImage::GetModuleFileNameHintForDAC()
{
LIMITED_METHOD_CONTRACT;
return m_sModuleFileNameHintUsedByDac;
}
#endif
inline BOOL PEImage::IsFile()
{
WRAPPER_NO_CONTRACT;
return !m_path.IsEmpty();
}
#ifndef DACCESS_COMPILE
inline void PEImage::SetLayout(DWORD dwLayout, PEImageLayout* pLayout)
{
LIMITED_METHOD_CONTRACT;
_ASSERTE(dwLayout<IMAGE_COUNT);
_ASSERTE(m_pLayouts[dwLayout]==NULL);
FastInterlockExchangePointer((m_pLayouts+dwLayout),pLayout);
}
#endif // DACCESS_COMPILE
inline PTR_PEImageLayout PEImage::GetLoadedLayout()
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
_ASSERTE(m_pLayouts[IMAGE_LOADED]!=NULL);
return m_pLayouts[IMAGE_LOADED]; //no addref
}
inline PTR_PEImageLayout PEImage::GetLoadedIntrospectionLayout()
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
_ASSERTE(m_pLayouts[IMAGE_LOADED_FOR_INTROSPECTION]!=NULL);
return m_pLayouts[IMAGE_LOADED_FOR_INTROSPECTION]; //no addref
}
//
// GetExistingLayout - get an layout corresponding to the specified mask, or null if none.
// Does not take any locks or call AddRef.
//
// Arguments:
// imageLayoutMask - bits from PEImageLayout specifying which layouts the caller would be
// interested in getting
//
// Return value:
// a PEImageLayout of a type matching one of the bits specified in the mask, or NULL if
// none exists yet. Does not call AddRef on the returned value.
//
inline PTR_PEImageLayout PEImage::GetExistingLayoutInternal(DWORD imageLayoutMask)
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
PTR_PEImageLayout pRetVal = NULL;
if (imageLayoutMask&PEImageLayout::LAYOUT_LOADED)
pRetVal=m_pLayouts[IMAGE_LOADED];
if (pRetVal==NULL && (imageLayoutMask & PEImageLayout::LAYOUT_LOADED_FOR_INTROSPECTION))
pRetVal=m_pLayouts[IMAGE_LOADED_FOR_INTROSPECTION];
if (pRetVal==NULL && (imageLayoutMask & PEImageLayout::LAYOUT_MAPPED))
pRetVal=m_pLayouts[IMAGE_MAPPED];
if (pRetVal==NULL && (imageLayoutMask & PEImageLayout::LAYOUT_FLAT))
pRetVal=m_pLayouts[IMAGE_FLAT];
return pRetVal;
}
inline BOOL PEImage::HasLoadedLayout()
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
return m_pLayouts[IMAGE_LOADED]!=NULL;
}
inline BOOL PEImage::IsOpened()
{
LIMITED_METHOD_CONTRACT;
return m_pLayouts[IMAGE_LOADED]!=NULL ||m_pLayouts[IMAGE_MAPPED]!=NULL || m_pLayouts[IMAGE_FLAT] !=NULL || m_pLayouts[IMAGE_LOADED_FOR_INTROSPECTION]!=NULL;
}
inline BOOL PEImage::HasLoadedIntrospectionLayout() //introspection only!!!
{
LIMITED_METHOD_DAC_CONTRACT;
return m_pLayouts[IMAGE_LOADED_FOR_INTROSPECTION]!=NULL;
}
#ifdef FEATURE_PREJIT
inline CHECK PEImage::CheckNativeFormat()
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
CHECK(GetLoadedLayout()->CheckNativeFormat());
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
CHECK(pLayout->CheckNativeFormat());
}
CHECK_OK;
};
#endif // FEATURE_PREJIT
inline BOOL PEImage::IsReferenceAssembly()
{
CONTRACTL
{
PRECONDITION(HasCorHeader());
}
CONTRACTL_END;
IMDInternalImport* mdImport = this->GetMDImport();
HRESULT hr = mdImport->GetCustomAttributeByName(TokenFromRid(1, mdtAssembly),
g_ReferenceAssemblyAttribute,
NULL,
NULL);
IfFailThrow(hr);
if (hr == S_OK) {
return TRUE;
}
_ASSERTE(hr == S_FALSE);
return FALSE;
}
inline const BOOL PEImage::HasNTHeaders()
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
return GetLoadedLayout()->HasNTHeaders();
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return pLayout->HasNTHeaders();
}
}
inline const BOOL PEImage::HasCorHeader()
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
return GetLoadedLayout()->HasCorHeader();
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return pLayout->HasCorHeader();
}
}
inline const BOOL PEImage::HasReadyToRunHeader()
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
return GetLoadedLayout()->HasReadyToRunHeader();
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return pLayout->HasReadyToRunHeader();
}
}
inline void PEImage::SetPassiveDomainOnly()
{
LIMITED_METHOD_CONTRACT;
m_bPassiveDomainOnly=TRUE;
}
inline BOOL PEImage::PassiveDomainOnly()
{
LIMITED_METHOD_CONTRACT;
return m_bPassiveDomainOnly;
}
#ifdef FEATURE_PREJIT
inline const BOOL PEImage::GetNativeILHasSecurityDirectory()
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
return GetLoadedLayout()->GetNativeILHasSecurityDirectory();
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return pLayout->GetNativeILHasSecurityDirectory();
}
}
#endif
inline const BOOL PEImage::HasDirectoryEntry(int entry)
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
return GetLoadedLayout()->HasDirectoryEntry(entry);
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return pLayout->HasDirectoryEntry(entry);
}
}
inline const mdToken PEImage::GetEntryPointToken()
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
{
PTR_PEImageLayout pLayout = GetLoadedLayout();
if (!pLayout->HasManagedEntryPoint())
return mdTokenNil;
return pLayout->GetEntryPointToken();
}
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
if (!pLayout->HasManagedEntryPoint())
return mdTokenNil;
return pLayout->GetEntryPointToken();
}
}
inline const DWORD PEImage::GetCorHeaderFlags()
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
{
PTR_PEImageLayout pLayout = GetLoadedLayout();
return VAL32(pLayout->GetCorHeader()->Flags);
}
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return VAL32(pLayout->GetCorHeader()->Flags);
}
}
inline BOOL PEImage::MDImportLoaded()
{
return m_pMDImport != NULL;
}
inline const BOOL PEImage::HasV1Metadata()
{
WRAPPER_NO_CONTRACT;
return GetMDImport()->GetMetadataStreamVersion()==MD_STREAM_VER_1X;
}
inline const BOOL PEImage::IsILOnly()
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
return GetLoadedLayout()->IsILOnly();
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return pLayout->IsILOnly();
}
}
inline const WORD PEImage::GetSubsystem()
{
WRAPPER_NO_CONTRACT;
SUPPORTS_DAC;
if (HasLoadedLayout())
return GetLoadedLayout()->GetSubsystem();
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return pLayout->GetSubsystem();
}
}
#ifdef FEATURE_PREJIT
inline const BOOL PEImage::IsNativeILILOnly()
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
return GetLoadedLayout()->IsNativeILILOnly();
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return pLayout->IsNativeILILOnly();
}
}
inline void PEImage::GetNativeILPEKindAndMachine(DWORD* pdwKind, DWORD* pdwMachine)
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
GetLoadedLayout()->GetNativeILPEKindAndMachine(pdwKind, pdwMachine);
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
pLayout->GetNativeILPEKindAndMachine(pdwKind, pdwMachine);
}
}
inline const BOOL PEImage::IsNativeILDll()
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
return GetLoadedLayout()->IsNativeILDll();
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return pLayout->IsNativeILDll();
}
}
#endif // FEATURE_PREJIT
inline const BOOL PEImage::IsDll()
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
return GetLoadedLayout()->IsDll();
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return pLayout->IsDll();
}
}
inline const BOOL PEImage::HasStrongNameSignature()
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
return GetLoadedLayout()->HasStrongNameSignature();
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return pLayout->HasStrongNameSignature();
}
}
#ifndef DACCESS_COMPILE
#endif // !DACCESS_COMPILE
inline BOOL PEImage::IsStrongNameSigned()
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
return GetLoadedLayout()->IsStrongNameSigned();
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return pLayout->IsStrongNameSigned();
}
}
inline BOOL PEImage::IsIbcOptimized()
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
return GetLoadedLayout()->GetNativeILIsIbcOptimized();
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return pLayout->GetNativeILIsIbcOptimized();
}
}
#ifndef DACCESS_COMPILE
inline void PEImage::GetImageBits(DWORD layout, SBuffer &result)
{
WRAPPER_NO_CONTRACT;
PEImageLayoutHolder pLayout(GetLayout(layout,LAYOUT_CREATEIFNEEDED));
BYTE* buffer=result.OpenRawBuffer(pLayout->GetSize());
PREFIX_ASSUME(buffer != NULL);
memcpyNoGCRefs(buffer,pLayout->GetBase(),pLayout->GetSize());
result.CloseRawBuffer(pLayout->GetSize());
}
#endif
#ifdef FEATURE_PREJIT
inline PTR_CVOID PEImage::GetNativeManifestMetadata(COUNT_T *pSize)
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
return GetLoadedLayout()->GetNativeManifestMetadata(pSize);
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return pLayout->GetNativeManifestMetadata(pSize);
}
}
#endif
inline PTR_CVOID PEImage::GetMetadata(COUNT_T *pSize)
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
return GetLoadedLayout()->GetMetadata(pSize);
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return pLayout->GetMetadata(pSize);
}
}
inline BOOL PEImage::HasNativeHeader()
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
return GetLoadedLayout()->HasNativeHeader();
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return pLayout->HasNativeHeader();
}
}
inline BOOL PEImage::HasContents()
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
return GetLoadedLayout()->HasContents();
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return pLayout->HasContents();
}
}
inline CHECK PEImage::CheckFormat()
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
CHECK(GetLoadedLayout()->CheckFormat());
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
CHECK(pLayout->CheckFormat());
}
CHECK_OK;
}
inline PTR_CVOID PEImage::GetStrongNameSignature(COUNT_T *pSize)
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
return GetLoadedLayout()->GetStrongNameSignature(pSize);
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return pLayout->GetStrongNameSignature(pSize);
}
}
inline void PEImage::Init(LPCWSTR pPath)
{
CONTRACTL
{
THROWS;
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;
m_path = pPath;
m_path.Normalize();
SetModuleFileNameHintForDAC();
}
#ifndef DACCESS_COMPILE
/*static*/
inline PTR_PEImage PEImage::FindByPath(LPCWSTR pPath)
{
CONTRACTL
{
THROWS;
GC_TRIGGERS;
MODE_ANY;
PRECONDITION(s_hashLock.OwnedByCurrentThread());
}
CONTRACTL_END;
int CaseHashHelper(const WCHAR *buffer, COUNT_T count, LocaleID lcid);
PEImageLocator locator(pPath);
#ifdef FEATURE_CASE_SENSITIVE_FILESYSTEM
DWORD dwHash=path.Hash();
#else
DWORD dwHash = CaseHashHelper(pPath, (COUNT_T) wcslen(pPath), PEImage::GetFileSystemLocale());
#endif
return (PEImage *) s_Images->LookupValue(dwHash, &locator);
}
/* static */
inline PTR_PEImage PEImage::OpenImage(LPCWSTR pPath, MDInternalImportFlags flags /* = MDInternalImport_Default */)
{
BOOL fUseCache = !((flags & MDInternalImport_NoCache) == MDInternalImport_NoCache);
if (!fUseCache)
{
PEImageHolder pImage(new PEImage);
pImage->Init(pPath);
return dac_cast<PTR_PEImage>(pImage.Extract());
}
CrstHolder holder(&s_hashLock);
PEImage* found = FindByPath(pPath);
if (found == (PEImage*) INVALIDENTRY)
{
// We did not find the entry in the Cache, and we've been asked to only use the cache.
if ((flags & MDInternalImport_OnlyLookInCache) == MDInternalImport_OnlyLookInCache)
{
return NULL;
}
PEImageHolder pImage(new PEImage);
#ifdef FEATURE_PREJIT
if (flags & MDInternalImport_TrustedNativeImage)
pImage->SetIsTrustedNativeImage();
if (flags & MDInternalImport_NativeImageInstall)
pImage->SetIsNativeImageInstall();
#endif
pImage->Init(pPath);
pImage->AddToHashMap();
return dac_cast<PTR_PEImage>(pImage.Extract());
}
found->AddRef();
return dac_cast<PTR_PEImage>(found);
}
#endif
inline BOOL PEImage::IsFileLocked()
{
WRAPPER_NO_CONTRACT;
return (m_pLayouts[IMAGE_FLAT])!=NULL || (m_pLayouts[IMAGE_MAPPED])!=NULL ;
}
#ifndef DACCESS_COMPILE
inline void PEImage::AddToHashMap()
{
CONTRACTL
{
THROWS;
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;
_ASSERTE(s_hashLock.OwnedByCurrentThread());
s_Images->InsertValue(GetIDHash(),this);
m_bInHashMap=TRUE;
}
#endif
inline BOOL PEImage::Has32BitNTHeaders()
{
WRAPPER_NO_CONTRACT;
if (HasLoadedLayout())
return GetLoadedLayout()->Has32BitNTHeaders();
else
{
PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
return pLayout->Has32BitNTHeaders();
}
}
inline BOOL PEImage::HasID()
{
LIMITED_METHOD_CONTRACT;
return !GetPath().IsEmpty();
}
inline ULONG PEImage::GetIDHash()
{
CONTRACT(ULONG)
{
PRECONDITION(HasID());
MODE_ANY;
GC_NOTRIGGER;
THROWS;
}
CONTRACT_END;
#ifdef FEATURE_CASE_SENSITIVE_FILESYSTEM
RETURN m_path.Hash();
#else
RETURN m_path.HashCaseInsensitive(PEImage::GetFileSystemLocale());
#endif
}
inline void PEImage::CachePEKindAndMachine()
{
CONTRACTL
{
THROWS;
GC_TRIGGERS;
MODE_ANY;
}
CONTRACTL_END;
// Do nothing if we have cached the information already
if(m_fCachedKindAndMachine)
return;
PEImageLayoutHolder pLayout;
if (HasLoadedLayout())
{
pLayout.Assign(GetLoadedLayout(), false);
}
else
{
pLayout.Assign(GetLayout(PEImageLayout::LAYOUT_MAPPED|PEImageLayout::LAYOUT_FLAT,
PEImage::LAYOUT_CREATEIFNEEDED));
}
// Compute result into a local variables first
DWORD dwPEKind, dwMachine;
pLayout->GetPEKindAndMachine(&dwPEKind, &dwMachine);
// Write the final result into the lock-free cache.
m_dwPEKind = dwPEKind;
m_dwMachine = dwMachine;
MemoryBarrier();
m_fCachedKindAndMachine = TRUE;
}
inline void PEImage::GetPEKindAndMachine(DWORD* pdwKind, DWORD* pdwMachine)
{
WRAPPER_NO_CONTRACT;
CachePEKindAndMachine();
if (pdwKind)
*pdwKind = m_dwPEKind;
if (pdwMachine)
*pdwMachine = m_dwMachine;
}
#ifndef DACCESS_COMPILE
inline void PEImage::AllocateLazyCOWPages()
{
STANDARD_VM_CONTRACT;
#ifdef FEATURE_LAZY_COW_PAGES
if (!m_bAllocatedLazyCOWPages && CLRConfig::GetConfigValue(CLRConfig::INTERNAL_ZapLazyCOWPagesEnabled))
{
::AllocateLazyCOWPages(GetLoadedLayout());
m_bAllocatedLazyCOWPages = TRUE;
}
#endif
}
#endif
#endif // PEIMAGE_INL_
|