Skip to content

Commit d21d7f7

Browse files
CopilotjkotasCopilot
authored
Move stgpool to md subsystem, extract memory streams, eliminate VM dependencies on MD internals (#122723)
Fixes #35624 - Moved `stgpool.h`, `stgpooli.h` from `src/coreclr/inc/` to `src/coreclr/md/inc/` - Moved `stgpool.cpp`, `stgpooli.cpp`, `stgpoolreadonly.cpp` from `src/coreclr/utilcode/` to `src/coreclr/md/runtime/` - Moved `CPackedLen` struct from `stgpooli.h` to `src/coreclr/inc/mdfileformat.h` - Moved `CInMemoryStream` and `CGrowableStream` from `stgpool.*` to `memorystreams.*` - Replaced CDescPool with standalone implementation --------- Co-authored-by: Jan Kotas <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 5274662 commit d21d7f7

26 files changed

+1146
-1382
lines changed

src/coreclr/debug/di/module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "corsym.h"
1616

1717
#include "pedecoder.h"
18-
#include "stgpool.h"
18+
#include "memorystreams.h"
1919

2020
//---------------------------------------------------------------------------------------
2121
// Initialize a new CordbModule around a Module in the target.

src/coreclr/ilasm/ilasmpch.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <stdarg.h> // for vararg macros
2424

2525
#include "mdfileformat.h"
26-
#include "stgpooli.h"
2726
#include "minipal/time.h"
2827

2928
#ifdef _EXPORT

src/coreclr/inc/caparser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#ifndef __CAPARSER_H__
1414
#define __CAPARSER_H__
1515

16-
#include "stgpooli.h"
16+
#include "mdfileformat.h"
1717

1818
class CustomAttributeParser {
1919
public:

src/coreclr/inc/formattype.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -734,10 +734,6 @@ PCCOR_SIGNATURE PrettyPrintType(
734734
str = " modreq(";
735735
ADDCLASSTOCMOD:
736736
typePtr += CorSigUncompressToken(typePtr, &tk);
737-
if (IsNilToken(tk))
738-
{
739-
Debug_ReportError("Nil token in custom modifier");
740-
}
741737
tmp.Shrink(0);
742738
appendStr(&tmp, KEYWORD((char*)str));
743739
PrettyPrintClass(&tmp, tk, pIMDI);

src/coreclr/inc/mdfileformat.h

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,88 @@ class MDFormat
261261

262262
};
263263

264+
//*****************************************************************************
265+
// Helper class to pack and unpack lengths.
266+
//*****************************************************************************
267+
struct CPackedLen
268+
{
269+
enum {MAX_LEN = 0x1fffffff};
270+
static int Size(ULONG len)
271+
{
272+
LIMITED_METHOD_CONTRACT;
273+
// Smallest.
274+
if (len <= 0x7F)
275+
return 1;
276+
// Medium.
277+
if (len <= 0x3FFF)
278+
return 2;
279+
// Large (too large?).
280+
_ASSERTE(len <= MAX_LEN);
281+
return 4;
282+
}
283+
284+
// Get a pointer to the data, and store the length.
285+
static void const *GetData(void const *pData, ULONG *pLength);
286+
287+
// Get the length value encoded at *pData. Update ppData to point past data.
288+
static ULONG GetLength(void const *pData, void const **ppData=0);
289+
290+
// Get the length value encoded at *pData, and the size of that encoded value.
291+
static ULONG GetLength(void const *pData, int *pSizeOfLength);
292+
293+
// Pack a length at *pData; return a pointer to the next byte.
294+
static void* PutLength(void *pData, ULONG len);
295+
296+
// This is used for just getting an encoded length, and verifies that
297+
// there is no buffer or integer overflow.
298+
static HRESULT SafeGetLength( // S_OK, or error
299+
void const *pDataSource, // First byte of length.
300+
void const *pDataSourceEnd, // End of valid source data memory
301+
ULONG *pLength, // Encoded value
302+
void const **ppDataNext); // Pointer immediately following encoded length
303+
304+
static HRESULT SafeGetLength( // S_OK, or error
305+
BYTE const *pDataSource, // First byte of length.
306+
BYTE const *pDataSourceEnd, // End of valid source data memory
307+
ULONG *pLength, // Encoded value
308+
BYTE const **ppDataNext) // Pointer immediately following encoded length
309+
{
310+
return SafeGetLength(
311+
reinterpret_cast<void const *>(pDataSource),
312+
reinterpret_cast<void const *>(pDataSourceEnd),
313+
pLength,
314+
reinterpret_cast<void const **>(ppDataNext));
315+
}
316+
317+
// This performs the same tasks as GetLength above in addition to checking
318+
// that the value in *pcbData does not extend *ppData beyond pDataSourceEnd
319+
// and does not cause an integer overflow.
320+
static HRESULT SafeGetData(
321+
void const *pDataSource, // First byte of length.
322+
void const *pDataSourceEnd, // End of valid source data memory
323+
ULONG *pcbData, // Length of data
324+
void const **ppData); // Start of data
325+
326+
static HRESULT SafeGetData(
327+
BYTE const *pDataSource, // First byte of length.
328+
BYTE const *pDataSourceEnd, // End of valid source data memory
329+
ULONG *pcbData, // Length of data
330+
BYTE const **ppData) // Start of data
331+
{
332+
return SafeGetData(
333+
reinterpret_cast<void const *>(pDataSource),
334+
reinterpret_cast<void const *>(pDataSourceEnd),
335+
pcbData,
336+
reinterpret_cast<void const **>(ppData));
337+
}
338+
339+
// This is the same as GetData above except it takes a byte count instead
340+
// of pointer to determine the source data length.
341+
static HRESULT SafeGetData( // S_OK, or error
342+
void const *pDataSource, // First byte of data
343+
ULONG cbDataSource, // Count of valid bytes in data source
344+
ULONG *pcbData, // Length of data
345+
void const **ppData); // Start of data
346+
};
347+
264348
#endif // __MDFileFormat_h__

src/coreclr/inc/memoryrange.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define _memory_range_h
1111

1212
#include "daccess.h"
13+
#include "contract.h"
1314

1415
// MemoryRange is a descriptor of a memory range. This groups (pointer + size).
1516
//
@@ -49,8 +50,6 @@ class MemoryRange
4950

5051
// Note: use compiler-default copy ctor and assignment operator
5152

52-
53-
5453
// Check whether a pointer is in the memory range represented by this instance.
5554
BOOL IsInRange(PTR_VOID pAddress) const
5655
{
@@ -94,4 +93,3 @@ class MemoryRange
9493
typedef ArrayDPTR(MemoryRange) ARRAY_PTR_MemoryRange;
9594

9695
#endif // _memory_range_h
97-

0 commit comments

Comments
 (0)