summaryrefslogtreecommitdiff
path: root/src/utilcode/format1.cpp
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2016-11-23 19:09:09 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2016-11-23 19:09:09 +0900
commit4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (patch)
tree98110734c91668dfdbb126fcc0e15ddbd93738ca /src/utilcode/format1.cpp
parentfa45f57ed55137c75ac870356a1b8f76c84b229c (diff)
downloadcoreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.gz
coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.bz2
coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.zip
Imported Upstream version 1.1.0upstream/1.1.0
Diffstat (limited to 'src/utilcode/format1.cpp')
-rw-r--r--src/utilcode/format1.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/utilcode/format1.cpp b/src/utilcode/format1.cpp
new file mode 100644
index 0000000000..97cb95598b
--- /dev/null
+++ b/src/utilcode/format1.cpp
@@ -0,0 +1,120 @@
+// 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.
+
+/***************************************************************************/
+/* routines for parsing file format stuff ... */
+/* this is split off from format.cpp because this uses meta-data APIs that
+ are not present in many builds. Thus if someone needs things in the format.cpp
+ file but does not have the meta-data APIs, I want it to link */
+
+#include "stdafx.h"
+#include "cor.h"
+#include "corpriv.h"
+
+//---------------------------------------------------------------------------------------
+//
+static LONG FilterAllExceptions(PEXCEPTION_POINTERS pExceptionPointers, LPVOID lpvParam)
+{
+ if ((pExceptionPointers->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) ||
+ (pExceptionPointers->ExceptionRecord->ExceptionCode == EXCEPTION_ARRAY_BOUNDS_EXCEEDED) ||
+ (pExceptionPointers->ExceptionRecord->ExceptionCode == EXCEPTION_IN_PAGE_ERROR))
+ return EXCEPTION_EXECUTE_HANDLER;
+
+ return EXCEPTION_CONTINUE_SEARCH;
+}
+
+//---------------------------------------------------------------------------------------
+//
+COR_ILMETHOD_DECODER::COR_ILMETHOD_DECODER(
+ COR_ILMETHOD * header,
+ void * pInternalImport,
+ DecoderStatus * wbStatus)
+{
+ STATIC_CONTRACT_NOTHROW;
+ STATIC_CONTRACT_FORBID_FAULT;
+
+ // Can't put contract because of SEH
+ // CONTRACTL
+ // {
+ // NOTHROW;
+ // GC_NOTRIGGER;
+ // FORBID_FAULT;
+ // }
+ // CONTRACTL_END
+
+ bool fErrorInInit = false;
+ struct Param
+ {
+ COR_ILMETHOD_DECODER * pThis;
+ COR_ILMETHOD * header;
+ } param;
+ param.pThis = this;
+ param.header = header;
+
+ PAL_TRY(Param *, pParam, &param)
+ {
+ // Decode the COR header into a more convenient form
+ DecoderInit(pParam->pThis, pParam->header);
+ }
+ PAL_EXCEPT_FILTER(FilterAllExceptions)
+ {
+ fErrorInInit = true;
+ Code = 0;
+ SetLocalVarSigTok(0);
+ if (wbStatus != NULL)
+ {
+ *wbStatus = FORMAT_ERROR;
+ }
+ }
+ PAL_ENDTRY
+
+ if (fErrorInInit)
+ {
+ return;
+ }
+
+ // If there is a local variable sig, fetch it into 'LocalVarSig'
+ if ((GetLocalVarSigTok() != 0) && (pInternalImport != NULL))
+ {
+ IMDInternalImport * pMDI = reinterpret_cast<IMDInternalImport *>(pInternalImport);
+
+ if (wbStatus != NULL)
+ {
+ if ((!pMDI->IsValidToken(GetLocalVarSigTok())) ||
+ (TypeFromToken(GetLocalVarSigTok()) != mdtSignature) ||
+ (RidFromToken(GetLocalVarSigTok()) == 0))
+ {
+ *wbStatus = FORMAT_ERROR; // failure bad local variable signature token
+ return;
+ }
+ }
+
+ if (FAILED(pMDI->GetSigFromToken(GetLocalVarSigTok(), &cbLocalVarSig, &LocalVarSig)))
+ {
+ // Failure bad local variable signature token
+ if (wbStatus != NULL)
+ {
+ *wbStatus = FORMAT_ERROR;
+ }
+ LocalVarSig = NULL;
+ cbLocalVarSig = 0;
+ return;
+ }
+
+ if (wbStatus != NULL)
+ {
+ if (FAILED(validateTokenSig(GetLocalVarSigTok(), LocalVarSig, cbLocalVarSig, 0, pMDI)) ||
+ (*LocalVarSig != IMAGE_CEE_CS_CALLCONV_LOCAL_SIG))
+ {
+ *wbStatus = VERIFICATION_ERROR; // failure validating local variable signature
+ return;
+ }
+ }
+ }
+
+ if (wbStatus != NULL)
+ {
+ *wbStatus = SUCCESS;
+ }
+} // COR_ILMETHOD_DECODER::COR_ILMETHOD_DECODER