@@ -72,7 +72,6 @@ class EnCFieldDesc;
72
72
class FieldDesc ;
73
73
class NativeFieldDescriptor ;
74
74
class EEClassNativeLayoutInfo ;
75
- struct LayoutRawFieldInfo ;
76
75
class MetaSig ;
77
76
class MethodDesc ;
78
77
class MethodDescChunk ;
@@ -126,7 +125,7 @@ class ExplicitFieldTrust
126
125
};
127
126
128
127
// ----------------------------------------------------------------------------------------------
129
- // This class is a helper for HandleExplicitLayout . To make it harder to introduce security holes
128
+ // This class is a helper for ValidateExplicitLayout . To make it harder to introduce security holes
130
129
// into this function, we will manage all updates to the class's trust level through the ExplicitClassTrust
131
130
// class. This abstraction enforces the rule that the overall class is only as trustworthy as
132
131
// the least trustworthy field.
@@ -175,7 +174,7 @@ class ExplicitClassTrust : private ExplicitFieldTrust
175
174
};
176
175
177
176
// ----------------------------------------------------------------------------------------------
178
- // This class is a helper for HandleExplicitLayout . To make it harder to introduce security holes
177
+ // This class is a helper for ValidateExplicitLayout . To make it harder to introduce security holes
179
178
// into this function, this class will collect trust information about individual fields to be later
180
179
// aggregated into the overall class level.
181
180
//
@@ -334,39 +333,22 @@ class SparseVTableMap
334
333
// =======================================================================
335
334
class EEClassLayoutInfo
336
335
{
337
- static VOID CollectLayoutFieldMetadataThrowing (
338
- mdTypeDef cl, // cl of the NStruct being loaded
339
- BYTE packingSize, // packing size (from @dll.struct)
340
- BYTE nlType, // nltype (from @dll.struct)
341
- BOOL fExplicitOffsets , // explicit offsets?
342
- MethodTable *pParentMT, // the loaded superclass
343
- ULONG cTotalFields, // total number of fields (instance and static)
344
- HENUMInternal *phEnumField, // enumerator for fields
345
- Module* pModule, // Module that defines the scope, loader and heap (for allocate FieldMarshalers)
346
- const SigTypeContext *pTypeContext, // Type parameters for NStruct being loaded
347
- EEClassLayoutInfo *pEEClassLayoutInfoOut, // caller-allocated structure to fill in.
348
- LayoutRawFieldInfo *pInfoArrayOut, // caller-allocated array to fill in. Needs room for cTotalFields+1 elements
349
- LoaderAllocator * pAllocator,
350
- AllocMemTracker *pamTracker
351
- );
352
-
353
- friend class ClassLoader ;
354
- friend class EEClass ;
355
- friend class MethodTableBuilder ;
356
- UINT32 m_cbManagedSize;
357
-
358
336
public:
359
- BYTE m_ManagedLargestAlignmentRequirementOfAllMembers;
360
-
337
+ enum class LayoutType : BYTE
338
+ {
339
+ Auto = 0 , // Make sure Auto is the default value as the default-constructed value represents the "auto layout" case
340
+ Sequential,
341
+ Explicit
342
+ };
361
343
private:
362
344
enum {
363
345
// TRUE if the GC layout of the class is bit-for-bit identical
364
346
// to its unmanaged counterpart with the runtime marshalling system
365
347
// (i.e. no internal reference fields, no ansi-unicode char conversions required, etc.)
366
348
// Used to optimize marshaling.
367
349
e_BLITTABLE = 0x01 ,
368
- // Is this type also sequential in managed memory?
369
- e_MANAGED_SEQUENTIAL = 0x02 ,
350
+ // unused = 0x02,
351
+
370
352
// When a sequential/explicit type has no fields, it is conceptually
371
353
// zero-sized, but actually is 1 byte in length. This holds onto this
372
354
// fact and allows us to revert the 1 byte of padding when another
@@ -380,28 +362,27 @@ class EEClassLayoutInfo
380
362
e_IS_OR_HAS_INT128_FIELD = 0x20 ,
381
363
};
382
364
383
- BYTE m_bFlags;
365
+ LayoutType m_LayoutType;
366
+
367
+ BYTE m_ManagedLargestAlignmentRequirementOfAllMembers;
368
+
369
+ BYTE m_bFlags;
384
370
385
371
// Packing size in bytes (1, 2, 4, 8 etc.)
386
- BYTE m_cbPackingSize;
372
+ BYTE m_cbPackingSize;
387
373
388
374
public:
389
- UINT32 GetManagedSize () const
390
- {
391
- LIMITED_METHOD_CONTRACT;
392
- return m_cbManagedSize;
393
- }
394
375
395
376
BOOL IsBlittable () const
396
377
{
397
378
LIMITED_METHOD_CONTRACT;
398
379
return (m_bFlags & e_BLITTABLE) == e_BLITTABLE;
399
380
}
400
381
401
- BOOL IsManagedSequential () const
382
+ LayoutType GetLayoutType () const
402
383
{
403
384
LIMITED_METHOD_CONTRACT;
404
- return (m_bFlags & e_MANAGED_SEQUENTIAL) == e_MANAGED_SEQUENTIAL ;
385
+ return m_LayoutType ;
405
386
}
406
387
407
388
// If true, this says that the type was originally zero-sized
@@ -433,54 +414,112 @@ class EEClassLayoutInfo
433
414
return (m_bFlags & e_IS_OR_HAS_INT128_FIELD) == e_IS_OR_HAS_INT128_FIELD;
434
415
}
435
416
417
+ BYTE GetAlignmentRequirement () const
418
+ {
419
+ LIMITED_METHOD_CONTRACT;
420
+ return m_ManagedLargestAlignmentRequirementOfAllMembers;
421
+ }
422
+
436
423
BYTE GetPackingSize () const
437
424
{
438
425
LIMITED_METHOD_CONTRACT;
439
426
return m_cbPackingSize;
440
427
}
441
428
442
- private:
443
429
void SetIsBlittable (BOOL isBlittable)
444
430
{
445
431
LIMITED_METHOD_CONTRACT;
446
432
m_bFlags = isBlittable ? (m_bFlags | e_BLITTABLE)
447
433
: (m_bFlags & ~e_BLITTABLE);
448
434
}
449
435
450
- void SetIsManagedSequential (BOOL isManagedSequential )
436
+ void SetHasAutoLayoutField (BOOL hasAutoLayoutField )
451
437
{
452
438
LIMITED_METHOD_CONTRACT;
453
- m_bFlags = isManagedSequential ? (m_bFlags | e_MANAGED_SEQUENTIAL )
454
- : (m_bFlags & ~e_MANAGED_SEQUENTIAL );
439
+ m_bFlags = hasAutoLayoutField ? (m_bFlags | e_HAS_AUTO_LAYOUT_FIELD_IN_LAYOUT )
440
+ : (m_bFlags & ~e_HAS_AUTO_LAYOUT_FIELD_IN_LAYOUT );
455
441
}
456
442
457
- void SetIsZeroSized (BOOL isZeroSized )
443
+ void SetIsInt128OrHasInt128Fields (BOOL hasInt128Field )
458
444
{
459
445
LIMITED_METHOD_CONTRACT;
460
- m_bFlags = isZeroSized ? (m_bFlags | e_ZERO_SIZED )
461
- : (m_bFlags & ~e_ZERO_SIZED );
446
+ m_bFlags = hasInt128Field ? (m_bFlags | e_IS_OR_HAS_INT128_FIELD )
447
+ : (m_bFlags & ~e_IS_OR_HAS_INT128_FIELD );
462
448
}
463
449
464
450
void SetHasExplicitSize (BOOL hasExplicitSize)
465
451
{
466
452
LIMITED_METHOD_CONTRACT;
467
453
m_bFlags = hasExplicitSize ? (m_bFlags | e_HAS_EXPLICIT_SIZE)
468
- : (m_bFlags & ~e_HAS_EXPLICIT_SIZE);
454
+ : (m_bFlags & ~e_HAS_EXPLICIT_SIZE);
469
455
}
470
456
471
- void SetHasAutoLayoutField (BOOL hasAutoLayoutField )
457
+ void SetAlignmentRequirement (BYTE alignment )
472
458
{
473
459
LIMITED_METHOD_CONTRACT;
474
- m_bFlags = hasAutoLayoutField ? (m_bFlags | e_HAS_AUTO_LAYOUT_FIELD_IN_LAYOUT)
475
- : (m_bFlags & ~e_HAS_AUTO_LAYOUT_FIELD_IN_LAYOUT);
460
+ m_ManagedLargestAlignmentRequirementOfAllMembers = alignment;
476
461
}
477
462
478
- void SetIsInt128OrHasInt128Fields (BOOL hasInt128Field)
463
+ ULONG InitializeSequentialFieldLayout (
464
+ FieldDesc* pFields,
465
+ MethodTable** pByValueClassCache,
466
+ ULONG cFields,
467
+ BYTE packingSize,
468
+ ULONG classSizeInMetadata,
469
+ MethodTable* pParentMT
470
+ );
471
+
472
+ ULONG InitializeExplicitFieldLayout (
473
+ FieldDesc* pFields,
474
+ MethodTable** pByValueClassCache,
475
+ ULONG cFields,
476
+ BYTE packingSize,
477
+ ULONG classSizeInMetadata,
478
+ MethodTable* pParentMT,
479
+ Module* pModule,
480
+ mdTypeDef cl
481
+ );
482
+
483
+ private:
484
+ void SetIsZeroSized (BOOL isZeroSized)
479
485
{
480
486
LIMITED_METHOD_CONTRACT;
481
- m_bFlags = hasInt128Field ? (m_bFlags | e_IS_OR_HAS_INT128_FIELD)
482
- : (m_bFlags & ~e_IS_OR_HAS_INT128_FIELD);
487
+ m_bFlags = isZeroSized ? (m_bFlags | e_ZERO_SIZED)
488
+ : (m_bFlags & ~e_ZERO_SIZED);
489
+ }
490
+
491
+ void SetPackingSize (BYTE cbPackingSize)
492
+ {
493
+ LIMITED_METHOD_CONTRACT;
494
+ m_cbPackingSize = cbPackingSize;
483
495
}
496
+
497
+ UINT32 SetInstanceBytesSize (UINT32 size)
498
+ {
499
+ LIMITED_METHOD_CONTRACT;
500
+ // Bump the managed size of the structure up to 1.
501
+ SetIsZeroSized (size == 0 ? TRUE : FALSE );
502
+ return size == 0 ? 1 : size;
503
+ }
504
+
505
+ void SetLayoutType (LayoutType layoutType)
506
+ {
507
+ LIMITED_METHOD_CONTRACT;
508
+ m_LayoutType = layoutType;
509
+ }
510
+ public:
511
+ enum class NestedFieldFlags
512
+ {
513
+ support_use_as_flags = -1 ,
514
+ None = 0x0 ,
515
+ NonBlittable = 0x1 ,
516
+ GCPointer = 0x2 ,
517
+ Align8 = 0x4 ,
518
+ AutoLayout = 0x8 ,
519
+ Int128 = 0x10 ,
520
+ };
521
+
522
+ static NestedFieldFlags GetNestedFieldFlags (Module* pModule, FieldDesc *pFD, ULONG cFields, CorNativeLinkType nlType, MethodTable** pByValueClassCache);
484
523
};
485
524
486
525
//
@@ -1964,7 +2003,7 @@ inline BOOL EEClass::IsBlittable()
1964
2003
inline BOOL EEClass::IsManagedSequential ()
1965
2004
{
1966
2005
LIMITED_METHOD_CONTRACT;
1967
- return HasLayout () && GetLayoutInfo ()->IsManagedSequential () ;
2006
+ return HasLayout () && GetLayoutInfo ()->GetLayoutType () == EEClassLayoutInfo::LayoutType::Sequential ;
1968
2007
}
1969
2008
1970
2009
inline BOOL EEClass::HasExplicitSize ()
0 commit comments