Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordotnet-bot <dotnet-bot@microsoft.com>2015-10-01 00:47:24 +0300
committerScott Mosier <smosier@microsoft.com>2015-10-01 00:47:24 +0300
commitad0323ab91a7b1469b42ca5457ddd631b94294fe (patch)
tree88fae57e1ec3aae90288463dc07e58f7aebc1de8 /src/Native/Runtime/eetype.cpp
parent6763d16387778f126ec510c0421783952602f8f7 (diff)
Initial population of CoreRT Runtime files.
Diffstat (limited to 'src/Native/Runtime/eetype.cpp')
-rw-r--r--src/Native/Runtime/eetype.cpp149
1 files changed, 149 insertions, 0 deletions
diff --git a/src/Native/Runtime/eetype.cpp b/src/Native/Runtime/eetype.cpp
new file mode 100644
index 000000000..6259a7518
--- /dev/null
+++ b/src/Native/Runtime/eetype.cpp
@@ -0,0 +1,149 @@
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+#include "common.h"
+#ifdef DACCESS_COMPILE
+#include "gcrhenv.h"
+#endif // DACCESS_COMPILE
+
+#ifndef DACCESS_COMPILE
+#include "commontypes.h"
+#include "daccess.h"
+#include "commonmacros.h"
+#include "assert.h"
+#include "rhbinder.h"
+#include "eetype.h"
+#include "palredhawkcommon.h"
+#include "palredhawk.h"
+#endif
+
+#pragma warning(disable:4127) // C4127: conditional expression is constant
+
+// Validate an EEType extracted from an object.
+bool EEType::Validate(bool assertOnFail /* default: true */)
+{
+#define REPORT_FAILURE() do { if (assertOnFail) { ASSERT_UNCONDITIONALLY("EEType::Validate check failed"); } return false; } while (false)
+
+ // Deal with the most common case of a bad pointer without an exception.
+ if (this == NULL)
+ REPORT_FAILURE();
+
+ // EEType structures should be at least pointer aligned.
+ if (dac_cast<TADDR>(this) & (sizeof(TADDR)-1))
+ REPORT_FAILURE();
+
+ // Verify object size is bigger than min_obj_size
+ size_t minObjSize = get_BaseSize();
+ if (get_ComponentSize() != 0)
+ {
+ // If it is an array, we will align the size to the nearest pointer alignment, even if there are
+ // zero elements. Our strings take advantage of this.
+ minObjSize = (size_t)ALIGN_UP(minObjSize, sizeof(TADDR));
+ }
+ if (minObjSize < (3 * sizeof(TADDR)))
+ REPORT_FAILURE();
+
+ switch (get_Kind())
+ {
+ case CanonicalEEType:
+ {
+ // If the parent type is NULL this had better look like Object.
+ if (m_RelatedType.m_pBaseType == NULL)
+ {
+ if (IsRelatedTypeViaIAT() ||
+ get_IsValueType() ||
+ HasFinalizer() ||
+ HasReferenceFields() ||
+ IsRuntimeAllocated() ||
+ HasGenericVariance())
+ {
+ REPORT_FAILURE();
+ }
+ }
+ break;
+ }
+
+ case ClonedEEType:
+ {
+ // Cloned types must have a related type.
+ if (m_RelatedType.m_ppCanonicalTypeViaIAT == NULL)
+ REPORT_FAILURE();
+
+ // Either we're dealing with a clone of String or a generic type. We can tell the difference based
+ // on the component size.
+ switch (get_ComponentSize())
+ {
+ case 0:
+ {
+ // Cloned generic type.
+ if (!IsRelatedTypeViaIAT() ||
+ IsRuntimeAllocated())
+ {
+ REPORT_FAILURE();
+ }
+ break;
+ }
+
+ case 2:
+ {
+ // Cloned string.
+ if (!IsRelatedTypeViaIAT() ||
+ get_IsValueType() ||
+ HasFinalizer() ||
+ HasReferenceFields() ||
+ IsRuntimeAllocated() ||
+ HasGenericVariance())
+ {
+ REPORT_FAILURE();
+ }
+
+ break;
+ }
+
+ default:
+ // Apart from cloned strings we don't expected cloned types to have a component size.
+ REPORT_FAILURE();
+ }
+ break;
+ }
+
+ case ParameterizedEEType:
+ {
+ // The only parameter EETypes that can exist on the heap are arrays
+
+ // Array types must have a related type.
+ if (m_RelatedType.m_pRelatedParameterType == NULL)
+ REPORT_FAILURE();
+
+ // Component size cannot be zero in this case.
+ if (get_ComponentSize() == 0)
+ REPORT_FAILURE();
+
+ if (get_IsValueType() ||
+ HasFinalizer() ||
+ IsRuntimeAllocated() ||
+ HasGenericVariance())
+ {
+ REPORT_FAILURE();
+ }
+
+ break;
+ }
+
+ case GenericTypeDefEEType:
+ {
+ // We should never see uninstantiated generic type definitions here
+ // since we should never construct an object instance around them.
+ REPORT_FAILURE();
+ }
+
+ default:
+ // Should be unreachable.
+ REPORT_FAILURE();
+ }
+
+#undef REPORT_FAILURE
+
+ return true;
+}