Skip to content

Commit 2b56228

Browse files
committed
Make PEImage Size/UncompressedSize getters more explicit
1 parent c248c07 commit 2b56228

File tree

6 files changed

+32
-19
lines changed

6 files changed

+32
-19
lines changed

src/coreclr/inc/bundle.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ struct BundleFileLocation
1919
{
2020
INT64 Size;
2121
INT64 Offset;
22-
INT64 UncompresedSize;
22+
INT64 UncompressedSize;
2323

2424
BundleFileLocation()
2525
{
2626
LIMITED_METHOD_CONTRACT;
2727

2828
Size = 0;
2929
Offset = 0;
30-
UncompresedSize = 0;
30+
UncompressedSize = 0;
3131
}
3232

3333
static BundleFileLocation Invalid() { LIMITED_METHOD_CONTRACT; return BundleFileLocation(); }

src/coreclr/vm/bundle.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ BundleFileLocation Bundle::Probe(const SString& path, bool pathIsBundleRelative)
8888
if (compressedSize)
8989
{
9090
loc.Size = compressedSize;
91-
loc.UncompresedSize = fileSize;
91+
loc.UncompressedSize = fileSize;
9292
}
9393
else
9494
{
9595
loc.Size = fileSize;
96-
loc.UncompresedSize = 0;
96+
loc.UncompressedSize = 0;
9797
}
9898

9999
return loc;

src/coreclr/vm/hostinformation.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ bool HostInformation::ExternalAssemblyProbe(_In_ const SString& path, _Out_ void
5454
StackSString utf8Path;
5555
utf8Path.SetAndConvertToUTF8(path.GetUnicode());
5656
return s_hostContract->external_assembly_probe(utf8Path.GetUTF8(), data, size);
57-
}
57+
}

src/coreclr/vm/peimage.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class PEImage final
142142
void* GetExternalData(INT64* size);
143143
INT64 GetOffset() const;
144144
INT64 GetSize() const;
145-
INT64 GetUncompressedSize() const;
145+
BOOL IsCompressed(INT64* uncompressedSize = NULL) const;
146146

147147
HANDLE GetFileHandle();
148148
HRESULT TryOpenFile(bool takeLock = false);

src/coreclr/vm/peimage.inl

+19-7
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ inline void* PEImage::GetExternalData(INT64* size)
4444
LIMITED_METHOD_CONTRACT;
4545

4646
_ASSERTE(size != nullptr);
47-
if (m_probeExtensionResult.Type != ProbeExtensionResult::Type::External)
47+
if (!IsExternalData())
4848
{
4949
*size = 0;
5050
return nullptr;
@@ -58,7 +58,7 @@ inline INT64 PEImage::GetOffset() const
5858
{
5959
LIMITED_METHOD_CONTRACT;
6060

61-
return m_probeExtensionResult.BundleLocation.Offset;
61+
return IsInBundle() ? m_probeExtensionResult.BundleLocation.Offset : 0;
6262
}
6363

6464
inline BOOL PEImage::IsInBundle() const
@@ -77,14 +77,26 @@ inline BOOL PEImage::IsExternalData() const
7777

7878
inline INT64 PEImage::GetSize() const
7979
{
80-
LIMITED_METHOD_CONTRACT;
81-
return m_probeExtensionResult.BundleLocation.Size;
80+
if (!m_probeExtensionResult.IsValid())
81+
82+
if (IsInBundle())
83+
return m_probeExtensionResult.BundleLocation.Size;
84+
85+
if (IsExternalData())
86+
return m_probeExtensionResult.ExternalData.Size;
87+
88+
// Size is not specified
89+
return 0;
8290
}
8391

84-
inline INT64 PEImage::GetUncompressedSize() const
92+
inline BOOL PEImage::IsCompressed(INT64* uncompressedSize) const
8593
{
8694
LIMITED_METHOD_CONTRACT;
87-
return m_probeExtensionResult.BundleLocation.UncompresedSize;
95+
96+
if (uncompressedSize != NULL)
97+
*uncompressedSize = IsInBundle() ? m_probeExtensionResult.BundleLocation.UncompressedSize : 0;
98+
99+
return IsInBundle() && m_probeExtensionResult.BundleLocation.UncompressedSize != 0;
88100
}
89101

90102
inline void PEImage::SetModuleFileNameHintForDAC()
@@ -120,7 +132,7 @@ inline const SString &PEImage::GetModuleFileNameHintForDAC()
120132
inline BOOL PEImage::IsFile()
121133
{
122134
WRAPPER_NO_CONTRACT;
123-
return m_probeExtensionResult.Type != ProbeExtensionResult::Type::External && !GetPathToLoad().IsEmpty();
135+
return !IsExternalData() && !GetPathToLoad().IsEmpty();
124136
}
125137

126138
//

src/coreclr/vm/peimagelayout.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ PEImageLayout* PEImageLayout::Load(PEImage* pOwner, HRESULT* loadFailure)
124124
{
125125
if (!pOwner->IsInBundle()
126126
#if defined(TARGET_UNIX)
127-
|| (pOwner->GetUncompressedSize() == 0)
127+
|| !pOwner->IsCompressed()
128128
#endif
129129
)
130130
{
@@ -537,7 +537,7 @@ LoadedImageLayout::LoadedImageLayout(PEImage* pOwner, HRESULT* loadFailure)
537537
CONTRACTL_END;
538538

539539
m_pOwner = pOwner;
540-
_ASSERTE(pOwner->GetUncompressedSize() == 0);
540+
_ASSERTE(!pOwner->IsCompressed());
541541

542542
#ifndef TARGET_UNIX
543543
_ASSERTE(!pOwner->IsInBundle());
@@ -670,12 +670,13 @@ FlatImageLayout::FlatImageLayout(PEImage* pOwner)
670670
// It's okay if resource files are length zero
671671
if (size > 0)
672672
{
673-
INT64 uncompressedSize = pOwner->GetUncompressedSize();
673+
INT64 uncompressedSize;
674+
BOOL isCompressed = pOwner->IsCompressed(&uncompressedSize);
674675

675676
DWORD mapAccess = PAGE_READONLY;
676677
#if !defined(TARGET_UNIX)
677678
// to map sections into executable views on Windows the mapping must have EXECUTE permissions
678-
if (uncompressedSize == 0)
679+
if (!isCompressed)
679680
{
680681
mapAccess = PAGE_EXECUTE_READ;
681682
}
@@ -701,7 +702,7 @@ FlatImageLayout::FlatImageLayout(PEImage* pOwner)
701702
m_FileView.Assign(view);
702703
addr = (LPVOID)((size_t)view + offset - mapBegin);
703704

704-
if (uncompressedSize > 0)
705+
if (isCompressed)
705706
{
706707
#if defined(CORECLR_EMBEDDED)
707708
// The mapping we have just created refers to the region in the bundle that contains compressed data.
@@ -1031,7 +1032,7 @@ void* FlatImageLayout::LoadImageByMappingParts(SIZE_T* m_imageParts) const
10311032
}
10321033
CONTRACTL_END;
10331034

1034-
if (!HavePlaceholderAPI() || m_pOwner->GetUncompressedSize() != 0)
1035+
if (!HavePlaceholderAPI() || m_pOwner->IsCompressed())
10351036
{
10361037
return NULL;
10371038
}

0 commit comments

Comments
 (0)