From 78d9afe8606a242caa0df9927763c7608c592782 Mon Sep 17 00:00:00 2001 From: Phil Christensen Date: Thu, 1 Dec 2016 03:53:23 -0800 Subject: [PATCH] fix permissive C++ code (MSVC /permissive-) (dotnet/coreclr#8337) * fix permissive C++ code (MSVC /permissive-) These were found by the C++ compiler group when doing "Real world code" build tests using /permissive-. We are sharing these with you to help you clean up your code before the new version of the compiler comes out. For more information on /permissive- see https://blogs.msdn.microsoft.com/vcblog/2016/11/16/permissive-switch/. ---------------------------- Under /permissive-, skipping the initialization of a variable is not allowed. As an extension the compiler allowed this when there was no destructor for the type. void func(bool b) { if(b) goto END; int value = 0; //error C2362: initialization of 'value' is skipped by 'goto END' int array[10]; //Okay, not initialized. //... value used here END: return; } Fix 1) Limit the scope of value: { int value = 0; //... value used here } END: Fix 2) Initialize/declare value before the 'goto' int value = 0; if(b) goto END; //... value used here END: Fix 3) Don't initialize value in the variable declaration. int value; value = 0 //... value used here END: ------------------- Alternative token representations. The following are reserved as alternative representations for operators: and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq //Can't use reserved names for variables: static int and = 0; // Change name (possibly to 'and_') void func() { _asm { xor edx,edx // xor is reserved, change to uppercase XOR or eax,eax // or is reserved, change to uppercase OR } } * Apply formatting patch. * fixes from code review. I addressed @janvorli requests from the pull request code review. Commit migrated from https://github.com/dotnet/coreclr/commit/20275aa647c5733bc5b1929cba3fd1094c67fb1d --- src/coreclr/src/ToolBox/SOS/Strike/strike.cpp | 6 +- src/coreclr/src/ToolBox/SOS/Strike/util.cpp | 64 ++++++------ src/coreclr/src/debug/ee/controller.cpp | 6 +- src/coreclr/src/dlls/mscorpe/ceefilegenwriter.cpp | 17 ++- src/coreclr/src/jit/codegenlegacy.cpp | 120 +++++++++++----------- src/coreclr/src/md/ceefilegen/cceegen.cpp | 24 +++-- src/coreclr/src/md/winmd/adapter.cpp | 28 +++-- src/coreclr/src/md/winmd/winmdimport.cpp | 30 +++--- src/coreclr/src/utilcode/regutil.cpp | 3 +- src/coreclr/src/utilcode/securitywrapper.cpp | 35 ++++--- src/coreclr/src/vm/ceemain.cpp | 16 +-- src/coreclr/src/vm/clrprivbinderwinrt.cpp | 11 +- src/coreclr/src/vm/encee.cpp | 15 +-- src/coreclr/src/vm/excep.cpp | 55 +++++----- src/coreclr/src/vm/i386/cgenx86.cpp | 3 +- src/coreclr/src/vm/mlinfo.cpp | 4 +- src/coreclr/src/vm/util.cpp | 25 ++--- src/coreclr/src/vm/win32threadpool.cpp | 4 +- 18 files changed, 257 insertions(+), 209 deletions(-) diff --git a/src/coreclr/src/ToolBox/SOS/Strike/strike.cpp b/src/coreclr/src/ToolBox/SOS/Strike/strike.cpp index 71db902..3bb3f50 100644 --- a/src/coreclr/src/ToolBox/SOS/Strike/strike.cpp +++ b/src/coreclr/src/ToolBox/SOS/Strike/strike.cpp @@ -4361,8 +4361,10 @@ DECLARE_API(VerifyObj) ExtOut("Unable to build snapshot of the garbage collector state\n"); goto Exit; } - DacpGcHeapDetails *pheapDetails = g_snapshot.GetHeap(taddrObj); - bValid = VerifyObject(*pheapDetails, taddrObj, taddrMT, objSize, TRUE); + { + DacpGcHeapDetails *pheapDetails = g_snapshot.GetHeap(taddrObj); + bValid = VerifyObject(*pheapDetails, taddrObj, taddrMT, objSize, TRUE); + } Exit: if (bValid) diff --git a/src/coreclr/src/ToolBox/SOS/Strike/util.cpp b/src/coreclr/src/ToolBox/SOS/Strike/util.cpp index 9eec76e..b2c96fe 100644 --- a/src/coreclr/src/ToolBox/SOS/Strike/util.cpp +++ b/src/coreclr/src/ToolBox/SOS/Strike/util.cpp @@ -254,47 +254,49 @@ HRESULT CreateInstanceCustomImpl( typedef HRESULT (__stdcall IDebugSymbols3::*GetPathFunc)(LPWSTR , ULONG, ULONG*); - // Handle both the image path and the symbol path - GetPathFunc rgGetPathFuncs[] = - { &IDebugSymbols3::GetImagePathWide, &IDebugSymbols3::GetSymbolPathWide }; - - for (int i = 0; i < _countof(rgGetPathFuncs); ++i) { - ULONG pathSize = 0; + // Handle both the image path and the symbol path + GetPathFunc rgGetPathFuncs[] = + { &IDebugSymbols3::GetImagePathWide, &IDebugSymbols3::GetSymbolPathWide }; - // get the path buffer size - if ((spSym3.GetPtr()->*rgGetPathFuncs[i])(NULL, 0, &pathSize) != S_OK) + for (int i = 0; i < _countof(rgGetPathFuncs); ++i) { - continue; - } + ULONG pathSize = 0; - ArrayHolder imgPath = new WCHAR[pathSize+MAX_LONGPATH+1]; - if (imgPath == NULL) - { - continue; - } + // get the path buffer size + if ((spSym3.GetPtr()->*rgGetPathFuncs[i])(NULL, 0, &pathSize) != S_OK) + { + continue; + } - // actually get the path - if ((spSym3.GetPtr()->*rgGetPathFuncs[i])(imgPath, pathSize, NULL) != S_OK) - { - continue; - } + ArrayHolder imgPath = new WCHAR[pathSize+MAX_LONGPATH+1]; + if (imgPath == NULL) + { + continue; + } - LPWSTR ctx; - LPCWSTR pathElem = wcstok_s(imgPath, W(";"), &ctx); - while (pathElem != NULL) - { - WCHAR fullName[MAX_LONGPATH]; - wcscpy_s(fullName, _countof(fullName), pathElem); - if (wcscat_s(fullName, W("\\")) == 0 && wcscat_s(fullName, dllName) == 0) + // actually get the path + if ((spSym3.GetPtr()->*rgGetPathFuncs[i])(imgPath, pathSize, NULL) != S_OK) + { + continue; + } + + LPWSTR ctx; + LPCWSTR pathElem = wcstok_s(imgPath, W(";"), &ctx); + while (pathElem != NULL) { - if (SUCCEEDED(CreateInstanceFromPath(clsid, iid, fullName, ppItf))) + WCHAR fullName[MAX_LONGPATH]; + wcscpy_s(fullName, _countof(fullName), pathElem); + if (wcscat_s(fullName, W("\\")) == 0 && wcscat_s(fullName, dllName) == 0) { - return S_OK; + if (SUCCEEDED(CreateInstanceFromPath(clsid, iid, fullName, ppItf))) + { + return S_OK; + } } - } - pathElem = wcstok_s(NULL, W(";"), &ctx); + pathElem = wcstok_s(NULL, W(";"), &ctx); + } } } diff --git a/src/coreclr/src/debug/ee/controller.cpp b/src/coreclr/src/debug/ee/controller.cpp index 7f4d445..3a87fdf 100644 --- a/src/coreclr/src/debug/ee/controller.cpp +++ b/src/coreclr/src/debug/ee/controller.cpp @@ -2824,6 +2824,8 @@ DPOSS_ACTION DebuggerController::DispatchPatchOrSingleStep(Thread *thread, CONTE CrstHolderWithState lockController(&g_criticalSection); + TADDR originalAddress = 0; + #ifdef EnC_SUPPORTED DebuggerControllerPatch *dcpEnCOriginal = NULL; @@ -2878,7 +2880,7 @@ DPOSS_ACTION DebuggerController::DispatchPatchOrSingleStep(Thread *thread, CONTE // If we setip, then that will change the address in the context. // Remeber the old address so that we can compare it to the context's ip and see if it changed. // If it did change, then don't dispatch our current event. - TADDR originalAddress = (TADDR) address; + originalAddress = (TADDR) address; #ifdef _DEBUG // If we do a SetIP after this point, the value of address will be garbage. Set it to a distictive pattern now, so @@ -4486,7 +4488,7 @@ void DebuggerPatchSkip::DebuggerDetachClean() // THIS FIX IS INCOMPLETE!It attempts to update the IP in the cases we can easily detect.However, // if a thread is in pre - emptive mode, and its filter context has been propagated to a VEH // context, then the filter context we get will be NULL and this fix will not work.Our belief is - // that this scenario is rare enough that it doesn’t justify the cost and risk associated with a + // that this scenario is rare enough that it doesnt justify the cost and risk associated with a // complete fix, in which we would have to either : // 1. Change the reference counting for DebuggerController and then change the exception handling // logic in the debuggee so that we can handle the debugger event after detach. diff --git a/src/coreclr/src/dlls/mscorpe/ceefilegenwriter.cpp b/src/coreclr/src/dlls/mscorpe/ceefilegenwriter.cpp index da853c3..04bacd7 100644 --- a/src/coreclr/src/dlls/mscorpe/ceefilegenwriter.cpp +++ b/src/coreclr/src/dlls/mscorpe/ceefilegenwriter.cpp @@ -1167,6 +1167,13 @@ HRESULT CeeFileGenWriter::emitResourceSection() const BYTE *pbStartOfMappedMem; IMAGE_SECTION_HEADER *rsrc[2] = { NULL, NULL }; S_SIZE_T cbTotalSizeOfRawData; + + char *data = NULL; + SIZE_T cReloc = 0; + IMAGE_RELOCATION *pReloc = NULL; + SIZE_T cSymbol = 0; + IMAGE_SYMBOL *pSymbolTable = NULL; + // create a mapped view of the .res file pParam->hFile = WszCreateFile(pParam->szResFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (pParam->hFile == INVALID_HANDLE_VALUE) @@ -1308,7 +1315,7 @@ HRESULT CeeFileGenWriter::emitResourceSection() if (FAILED(pParam->hr)) goto lDone; rsrcSection->directoryEntry(IMAGE_DIRECTORY_ENTRY_RESOURCE); - char *data = rsrcSection->getBlock(static_cast(cbTotalSizeOfRawData.Value()), 8); + data = rsrcSection->getBlock(static_cast(cbTotalSizeOfRawData.Value()), 8); if(data == NULL) { pParam->hr = E_OUTOFMEMORY; @@ -1319,11 +1326,11 @@ HRESULT CeeFileGenWriter::emitResourceSection() memcpy(data, (char *)pParam->hMod + VAL32(rsrc[0]->PointerToRawData), VAL32(rsrc[0]->SizeOfRawData)); // Map all the relocs in .rsrc$01 using the reloc and symbol tables in the COFF object., - SIZE_T cReloc = 0; // Total number of relocs - IMAGE_RELOCATION *pReloc = NULL; // Reloc table start + cReloc = 0; // Total number of relocs + pReloc = NULL; // Reloc table start - SIZE_T cSymbol = 0; // Total number of symbols - IMAGE_SYMBOL *pSymbolTable = NULL; // Symbol table start + cSymbol = 0; // Total number of symbols + pSymbolTable = NULL; // Symbol table start { // Check that the relocations and symbols lie within the resource diff --git a/src/coreclr/src/jit/codegenlegacy.cpp b/src/coreclr/src/jit/codegenlegacy.cpp index 6ae47f5..667b9d4 100644 --- a/src/coreclr/src/jit/codegenlegacy.cpp +++ b/src/coreclr/src/jit/codegenlegacy.cpp @@ -485,9 +485,10 @@ void CodeGen::genIncRegBy(regNumber reg, ssize_t ival, GenTreePtr tree, var_type } } #endif - - insFlags flags = setFlags ? INS_FLAGS_SET : INS_FLAGS_DONT_CARE; - inst_RV_IV(INS_add, reg, ival, emitActualTypeSize(dstType), flags); + { + insFlags flags = setFlags ? INS_FLAGS_SET : INS_FLAGS_DONT_CARE; + inst_RV_IV(INS_add, reg, ival, emitActualTypeSize(dstType), flags); + } #ifdef _TARGET_XARCH_ UPDATE_LIVENESS: @@ -7071,84 +7072,87 @@ void CodeGen::genCodeForTreeSmpBinArithLogOp(GenTreePtr tree, regMaskTP destReg, regTracker.rsTrackRegTrash(reg); - bool op2Released = false; + { + bool op2Released = false; - // For overflow instructions, tree->gtType is the accurate type, - // and gives us the size for the operands. + // For overflow instructions, tree->gtType is the accurate type, + // and gives us the size for the operands. - emitAttr opSize = emitTypeSize(treeType); + emitAttr opSize = emitTypeSize(treeType); - /* Compute the new value */ + /* Compute the new value */ - if (isArith && !op2->InReg() && (op2->OperKind() & GTK_CONST) + if (isArith && !op2->InReg() && (op2->OperKind() & GTK_CONST) #if !CPU_HAS_FP_SUPPORT - && (treeType == TYP_INT || treeType == TYP_I_IMPL) + && (treeType == TYP_INT || treeType == TYP_I_IMPL) #endif - ) - { - ssize_t ival = op2->gtIntCon.gtIconVal; - - if (oper == GT_ADD) - { - genIncRegBy(reg, ival, tree, treeType, ovfl); - } - else if (oper == GT_SUB) - { - if (ovfl && ((tree->gtFlags & GTF_UNSIGNED) || - (ival == ((treeType == TYP_INT) ? INT32_MIN : SSIZE_T_MIN))) // -0x80000000 == 0x80000000. - // Therefore we can't use -ival. ) - { - /* For unsigned overflow, we have to use INS_sub to set - the flags correctly */ + { + ssize_t ival = op2->gtIntCon.gtIconVal; - genDecRegBy(reg, ival, tree); + if (oper == GT_ADD) + { + genIncRegBy(reg, ival, tree, treeType, ovfl); } - else + else if (oper == GT_SUB) { - /* Else, we simply add the negative of the value */ + if (ovfl && ((tree->gtFlags & GTF_UNSIGNED) || + (ival == ((treeType == TYP_INT) ? INT32_MIN : SSIZE_T_MIN))) // -0x80000000 == 0x80000000. + // Therefore we can't use -ival. + ) + { + /* For unsigned overflow, we have to use INS_sub to set + the flags correctly */ - genIncRegBy(reg, -ival, tree, treeType, ovfl); + genDecRegBy(reg, ival, tree); + } + else + { + /* Else, we simply add the negative of the value */ + + genIncRegBy(reg, -ival, tree, treeType, ovfl); + } + } + else if (oper == GT_MUL) + { + genMulRegBy(reg, ival, tree, treeType, ovfl); } } - else if (oper == GT_MUL) - { - genMulRegBy(reg, ival, tree, treeType, ovfl); - } - } - else - { - // op2 could be a GT_COMMA (i.e. an assignment for a CSE def) - op2 = op2->gtEffectiveVal(); - if (varTypeIsByte(treeType) && op2->InReg()) + else { - noway_assert(genRegMask(reg) & RBM_BYTE_REGS); + // op2 could be a GT_COMMA (i.e. an assignment for a CSE def) + op2 = op2->gtEffectiveVal(); + if (varTypeIsByte(treeType) && op2->InReg()) + { + noway_assert(genRegMask(reg) & RBM_BYTE_REGS); - regNumber op2reg = op2->gtRegNum; - regMaskTP op2regMask = genRegMask(op2reg); + regNumber op2reg = op2->gtRegNum; + regMaskTP op2regMask = genRegMask(op2reg); - if (!(op2regMask & RBM_BYTE_REGS)) - { - regNumber byteReg = regSet.rsGrabReg(RBM_BYTE_REGS); + if (!(op2regMask & RBM_BYTE_REGS)) + { + regNumber byteReg = regSet.rsGrabReg(RBM_BYTE_REGS); - inst_RV_RV(INS_mov, byteReg, op2reg); - regTracker.rsTrackRegTrash(byteReg); + inst_RV_RV(INS_mov, byteReg, op2reg); + regTracker.rsTrackRegTrash(byteReg); - genDoneAddressable(op2, addrReg, RegSet::KEEP_REG); - op2Released = true; + genDoneAddressable(op2, addrReg, RegSet::KEEP_REG); + op2Released = true; - op2->gtRegNum = byteReg; + op2->gtRegNum = byteReg; + } } - } - - inst_RV_TT(ins, reg, op2, 0, opSize, flags); - } - /* Free up anything that was tied up by the operand */ + inst_RV_TT(ins, reg, op2, 0, opSize, flags); + } - if (!op2Released) - genDoneAddressable(op2, addrReg, RegSet::KEEP_REG); + /* Free up anything that was tied up by the operand */ + if (!op2Released) + { + genDoneAddressable(op2, addrReg, RegSet::KEEP_REG); + } + } /* The result will be where the first operand is sitting */ /* We must use RegSet::KEEP_REG since op1 can have a GC pointer here */ diff --git a/src/coreclr/src/md/ceefilegen/cceegen.cpp b/src/coreclr/src/md/ceefilegen/cceegen.cpp index 268093c..0cf0780 100644 --- a/src/coreclr/src/md/ceefilegen/cceegen.cpp +++ b/src/coreclr/src/md/ceefilegen/cceegen.cpp @@ -572,18 +572,20 @@ HRESULT CCeeGen::emitMetaData(IMetaDataEmit *emitter, CeeSection* section, DWORD _ASSERTE(metaDataLen <= buffLen); #ifdef ENC_DELTA_HACK - extern int __cdecl fclose(FILE *); - WCHAR szFileName[256]; - DWORD len = GetEnvironmentVariable(W("COMP_ENC_EMIT"), szFileName, ARRAYSIZE(szFileName)); - _ASSERTE(len < (ARRAYSIZE(szFileName) + 6)); // +6 for the .dmeta - if (len > 0 && len < (ARRAYSIZE(szFileName) + 6)) { - wcscat_s(szFileName, ARRAYSIZE(szFileName), W(".dmeta")); - FILE *pDelta; - int ec = _wfopen_s(&pDelta, szFileName, W("wb")); - if (FAILED(ec)) { return HRESULT_FROM_WIN32(ERROR_OPEN_FAILED); } - fwrite(buffer, 1, metaDataLen, pDelta); - fclose(pDelta); + extern int __cdecl fclose(FILE *); + WCHAR szFileName[256]; + DWORD len = GetEnvironmentVariable(W("COMP_ENC_EMIT"), szFileName, ARRAYSIZE(szFileName)); + _ASSERTE(len < (ARRAYSIZE(szFileName) + 6)); // +6 for the .dmeta + if (len > 0 && len < (ARRAYSIZE(szFileName) + 6)) + { + wcscat_s(szFileName, ARRAYSIZE(szFileName), W(".dmeta")); + FILE *pDelta; + int ec = _wfopen_s(&pDelta, szFileName, W("wb")); + if (FAILED(ec)) { return HRESULT_FROM_WIN32(ERROR_OPEN_FAILED); } + fwrite(buffer, 1, metaDataLen, pDelta); + fclose(pDelta); + } } #endif diff --git a/src/coreclr/src/md/winmd/adapter.cpp b/src/coreclr/src/md/winmd/adapter.cpp index 5b4d95c..2c9dd1b 100644 --- a/src/coreclr/src/md/winmd/adapter.cpp +++ b/src/coreclr/src/md/winmd/adapter.cpp @@ -88,6 +88,8 @@ HRESULT CheckIfWinMDAdapterNeeded(IMDCommon *pRawMDCommon) HRESULT hr; LPWSTR wszCorVersion = NULL; WinMDAdapter* pNewAdapter = NULL; + ULONG numAssemblyRefs = 0; + const char *szClrPortion = NULL; *ppAdapter = NULL; @@ -102,7 +104,7 @@ HRESULT CheckIfWinMDAdapterNeeded(IMDCommon *pRawMDCommon) //------------------------------------------------------------------------------------------------ LPCSTR szVersion; IfFailGo(pRawMDCommon->GetVersionString(&szVersion)); - const char *szClrPortion = strchr(szVersion, ';'); + szClrPortion = strchr(szVersion, ';'); if (szClrPortion) { pNewAdapter->m_scenario = kWinMDExp; @@ -148,7 +150,7 @@ HRESULT CheckIfWinMDAdapterNeeded(IMDCommon *pRawMDCommon) //------------------------------------------------------------------------------------------------ // Find an assemblyRef to mscorlib (required to exist in .winmd files precisely to make the adapter's job easier. //------------------------------------------------------------------------------------------------ - ULONG numAssemblyRefs = pNewAdapter->m_pRawMetaModelCommonRO->CommonGetRowCount(mdtAssemblyRef); + numAssemblyRefs = pNewAdapter->m_pRawMetaModelCommonRO->CommonGetRowCount(mdtAssemblyRef); pNewAdapter->m_assemblyRefMscorlib = 0; pNewAdapter->m_fReferencesMscorlibV4 = FALSE; for (ULONG rid = 1; rid <= numAssemblyRefs; rid++) @@ -860,10 +862,11 @@ WinMDAdapter::GetTypeRefProps( HRESULT hr; ULONG treatment; + ULONG treatmentClass; IfFailGo(GetTypeRefTreatment(tkTypeRef, &treatment)); _ASSERTE(treatment != kTrNotYetInitialized); - ULONG treatmentClass = treatment & kTrClassMask; + treatmentClass = treatment & kTrClassMask; if (treatmentClass == kTrClassWellKnownRedirected) { ULONG nRewritePairIndex = treatment & ~kTrClassMask; @@ -998,9 +1001,10 @@ WinMDAdapter::GetTypeRefRedirectedInfo( HRESULT hr; ULONG treatment; + ULONG treatmentClass; IfFailGo(GetTypeRefTreatment(tkTypeRef, &treatment)); - ULONG treatmentClass = treatment & kTrClassMask; + treatmentClass = treatment & kTrClassMask; if (treatmentClass == kTrClassWellKnownRedirected) { *pIndex = (RedirectedTypeIndex)(treatment & ~kTrClassMask); @@ -1278,11 +1282,14 @@ HRESULT WinMDAdapter::ModifyMethodProps(mdMethodDef tkMethodDef, /*[in, out]*/ D _ASSERTE(TypeFromToken(tkMethodDef) == mdtMethodDef); ULONG mdTreatment; + DWORD dwAttr; + DWORD dwImplFlags; + ULONG ulRVA; IfFailGo(GetMethodDefTreatment(tkMethodDef, &mdTreatment)); - DWORD dwAttr = pdwAttr ? *pdwAttr: 0; - DWORD dwImplFlags = pdwImplFlags ? *pdwImplFlags : 0; - ULONG ulRVA = pulRVA ? *pulRVA : 0; + dwAttr = pdwAttr ? *pdwAttr: 0; + dwImplFlags = pdwImplFlags ? *pdwImplFlags : 0; + ulRVA = pulRVA ? *pulRVA : 0; switch (mdTreatment & kMdTreatmentMask) { @@ -2400,9 +2407,12 @@ HRESULT WinMDAdapter::TranslateWinMDAttributeUsageAttribute(mdTypeDef tkTypeDefO { IfFailGo(COR_E_BADIMAGEFORMAT); } - DWORD wfTargetValue = *(DWORD*)(pbWFUsageBlob + 2); - *pClrTargetValue = ConvertToClrAttributeTarget(wfTargetValue); + { + DWORD wfTargetValue = *(DWORD*)(pbWFUsageBlob + 2); + *pClrTargetValue = ConvertToClrAttributeTarget(wfTargetValue); + } + // add AttributeTargets.Method, AttributeTargets.Constructor , AttributeTargets.Property, and AttributeTargets.Event if this is the VersionAttribute LPCSTR szNamespace; LPCSTR szName; diff --git a/src/coreclr/src/md/winmd/winmdimport.cpp b/src/coreclr/src/md/winmd/winmdimport.cpp index fe80bf0..cc983d2 100644 --- a/src/coreclr/src/md/winmd/winmdimport.cpp +++ b/src/coreclr/src/md/winmd/winmdimport.cpp @@ -588,13 +588,15 @@ class WinMDImport : public IMetaDataImport2 *pmb = mdMethodDefNil; - // check to see if this is a vararg signature - PCCOR_SIGNATURE pvSigTemp = pvSigBlob; - if (isCallConv(CorSigUncompressCallingConv(pvSigTemp), IMAGE_CEE_CS_CALLCONV_VARARG)) { - // Get the fixed part of VARARG signature - IfFailGo(_GetFixedSigOfVarArg(pvSigBlob, cbSigBlob, &qbSig, &cbSigBlob)); - pvSigBlob = (PCCOR_SIGNATURE) qbSig.Ptr(); + // check to see if this is a vararg signature + PCCOR_SIGNATURE pvSigTemp = pvSigBlob; + if (isCallConv(CorSigUncompressCallingConv(pvSigTemp), IMAGE_CEE_CS_CALLCONV_VARARG)) + { + // Get the fixed part of VARARG signature + IfFailGo(_GetFixedSigOfVarArg(pvSigBlob, cbSigBlob, &qbSig, &cbSigBlob)); + pvSigBlob = (PCCOR_SIGNATURE) qbSig.Ptr(); + } } // now iterate all methods in td and compare name and signature @@ -1654,15 +1656,17 @@ class WinMDImport : public IMetaDataImport2 // Step 1: Call EnumAssemblyRefs with an empty buffer to create the HENUMInternal IfFailGo(m_pRawAssemblyImport->EnumAssemblyRefs(phEnum, NULL, 0, NULL)); - // Step 2: Increment the cound to include the extra assembly refs - HENUMInternal *phInternalEnum = static_cast(*phEnum); + { + // Step 2: Increment the count to include the extra assembly refs + HENUMInternal *phInternalEnum = static_cast(*phEnum); - _ASSERTE(phInternalEnum->m_EnumType == MDSimpleEnum); + _ASSERTE(phInternalEnum->m_EnumType == MDSimpleEnum); - _ASSERTE( phInternalEnum->m_ulCount == m_pWinMDAdapter->GetRawAssemblyRefCount()); - int n = m_pWinMDAdapter->GetExtraAssemblyRefCount(); - phInternalEnum->m_ulCount += n; - phInternalEnum->u.m_ulEnd += n; + _ASSERTE( phInternalEnum->m_ulCount == m_pWinMDAdapter->GetRawAssemblyRefCount()); + int n = m_pWinMDAdapter->GetExtraAssemblyRefCount(); + phInternalEnum->m_ulCount += n; + phInternalEnum->u.m_ulEnd += n; + } // Step 3: Call EnumAssemblyRefs again and pass in the modifed HENUMInternal and the real buffer IfFailGo(m_pRawAssemblyImport->EnumAssemblyRefs(phEnum, rAssemblyRefs, cMax, pcTokens)); diff --git a/src/coreclr/src/utilcode/regutil.cpp b/src/coreclr/src/utilcode/regutil.cpp index fbc5570..d611ef9 100644 --- a/src/coreclr/src/utilcode/regutil.cpp +++ b/src/coreclr/src/utilcode/regutil.cpp @@ -1439,8 +1439,7 @@ void REGUTIL::InitOptionalConfigCache() s_fUseRegCache = TRUE; // Now create a cache of environment variables - WCHAR * wszStrings = WszGetEnvironmentStrings(); - if (wszStrings) + if (WCHAR * wszStrings = WszGetEnvironmentStrings()) { // GetEnvironmentStrings returns pointer to a null terminated block containing // null terminated strings diff --git a/src/coreclr/src/utilcode/securitywrapper.cpp b/src/coreclr/src/utilcode/securitywrapper.cpp index f949b26..0f146ab 100644 --- a/src/coreclr/src/utilcode/securitywrapper.cpp +++ b/src/coreclr/src/utilcode/securitywrapper.cpp @@ -412,6 +412,7 @@ HRESULT SidBuffer::InitFromProcessAppContainerSidNoThrow(DWORD pid) { HRESULT hr = S_OK; HANDLE hToken = NULL; + BOOL fIsLowBox = FALSE; HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid); if (hProcess == NULL) @@ -438,7 +439,6 @@ HRESULT SidBuffer::InitFromProcessAppContainerSidNoThrow(DWORD pid) } TOKEN_APPCONTAINER_INFORMATION, *PTOKEN_APPCONTAINER_INFORMATION; DWORD size; - BOOL fIsLowBox = FALSE; if (!GetTokenInformation(hToken, (TOKEN_INFORMATION_CLASS)TokenIsAppContainer, &fIsLowBox, sizeof(fIsLowBox), &size)) { DWORD gle = GetLastError(); @@ -466,24 +466,26 @@ HRESULT SidBuffer::InitFromProcessAppContainerSidNoThrow(DWORD pid) goto exit; } - PTOKEN_APPCONTAINER_INFORMATION pTokPack = (PTOKEN_APPCONTAINER_INFORMATION)&PackSid; - PSID pLowBoxPackage = pTokPack->TokenPackage; - DWORD dwSidLen = GetLengthSid(pLowBoxPackage); - m_pBuffer = new (nothrow) BYTE[dwSidLen]; - if (m_pBuffer == NULL) - { - hr = E_OUTOFMEMORY; - goto exit; - } - else { - if (!CopySid(dwSidLen, m_pBuffer, pLowBoxPackage)) + PTOKEN_APPCONTAINER_INFORMATION pTokPack = (PTOKEN_APPCONTAINER_INFORMATION)&PackSid; + PSID pLowBoxPackage = pTokPack->TokenPackage; + DWORD dwSidLen = GetLengthSid(pLowBoxPackage); + m_pBuffer = new (nothrow) BYTE[dwSidLen]; + if (m_pBuffer == NULL) { - hr = HRESULT_FROM_GetLastError(); - delete m_pBuffer; - m_pBuffer = NULL; + hr = E_OUTOFMEMORY; goto exit; } + else + { + if (!CopySid(dwSidLen, m_pBuffer, pLowBoxPackage)) + { + hr = HRESULT_FROM_GetLastError(); + delete m_pBuffer; + m_pBuffer = NULL; + goto exit; + } + } } exit: @@ -790,6 +792,7 @@ bool IsHandleSpoofed(HANDLE handle, DWORD pid) SidBuffer sbPidOther; SidBuffer sbPidThis; + DWORD pidThis; // Is the object owner the "other" pid? sbPidOther.InitFromProcess(pid); @@ -805,7 +808,7 @@ bool IsHandleSpoofed(HANDLE handle, DWORD pid) // This can happen if the other process impersonates us. The most common case would // be if we're an admin and the other process (say some service) is impersonating Admin // when it spins up the CLR. - DWORD pidThis = GetCurrentProcessId(); + pidThis = GetCurrentProcessId(); if (pidThis != pid) { sbPidThis.InitFromProcess(pidThis); diff --git a/src/coreclr/src/vm/ceemain.cpp b/src/coreclr/src/vm/ceemain.cpp index 67fa33c..b16d797 100644 --- a/src/coreclr/src/vm/ceemain.cpp +++ b/src/coreclr/src/vm/ceemain.cpp @@ -1933,15 +1933,17 @@ void STDMETHODCALLTYPE EEShutDownHelper(BOOL fIsDllUnloading) #endif #ifdef FEATURE_PREJIT - // If we're doing basic block profiling, we need to write the log files to disk. - - static BOOL fIBCLoggingDone = FALSE; - if (!fIBCLoggingDone) { - if (g_IBCLogger.InstrEnabled()) - Module::WriteAllModuleProfileData(true); + // If we're doing basic block profiling, we need to write the log files to disk. + + static BOOL fIBCLoggingDone = FALSE; + if (!fIBCLoggingDone) + { + if (g_IBCLogger.InstrEnabled()) + Module::WriteAllModuleProfileData(true); - fIBCLoggingDone = TRUE; + fIBCLoggingDone = TRUE; + } } #endif // FEATURE_PREJIT diff --git a/src/coreclr/src/vm/clrprivbinderwinrt.cpp b/src/coreclr/src/vm/clrprivbinderwinrt.cpp index b82d46c..b4fb45c 100644 --- a/src/coreclr/src/vm/clrprivbinderwinrt.cpp +++ b/src/coreclr/src/vm/clrprivbinderwinrt.cpp @@ -287,7 +287,8 @@ HRESULT CLRPrivBinderWinRT::BindWinRTAssemblyByName( { STANDARD_VM_CONTRACT; HRESULT hr = S_OK; - ReleaseHolder pAssembly; + ReleaseHolder pAssembly; + LPWSTR wszFullTypeName = nullptr; #ifndef FEATURE_CORECLR NewArrayHolder wszAssemblySimpleName; #endif @@ -319,11 +320,13 @@ HRESULT CLRPrivBinderWinRT::BindWinRTAssemblyByName( IfFailGo(fusion::util::GetProperty(pAssemblyName, ASM_NAME_NAME, &wszAssemblySimpleName)); #else WCHAR wszAssemblySimpleName[_MAX_PATH]; - DWORD cchAssemblySimpleName = _MAX_PATH; - IfFailGo(pAssemblyName->GetName(&cchAssemblySimpleName, wszAssemblySimpleName)); + { + DWORD cchAssemblySimpleName = _MAX_PATH; + IfFailGo(pAssemblyName->GetName(&cchAssemblySimpleName, wszAssemblySimpleName)); + } #endif - LPWSTR wszFullTypeName = wcschr(wszAssemblySimpleName, W('!')); + wszFullTypeName = wcschr(wszAssemblySimpleName, W('!')); if (wszFullTypeName != nullptr) { diff --git a/src/coreclr/src/vm/encee.cpp b/src/coreclr/src/vm/encee.cpp index ca4e7fe..7f12643 100644 --- a/src/coreclr/src/vm/encee.cpp +++ b/src/coreclr/src/vm/encee.cpp @@ -149,7 +149,11 @@ HRESULT EditAndContinueModule::ApplyEditAndContinue( HRESULT hr = S_OK; HENUMInternal enumENC; - + + BYTE *pLocalILMemory = NULL; + IMDInternalImport *pMDImport = NULL; + IMDInternalImport *pNewMDImport = NULL; + CONTRACT_VIOLATION(GCViolation); // SafeComHolder goes to preemptive mode, which will trigger a GC SafeComHolder pIMDInternalImportENC; SafeComHolder pEmitter; @@ -175,8 +179,7 @@ HRESULT EditAndContinueModule::ApplyEditAndContinue( IfFailGo(hr); // Grab the current importer. - IMDInternalImport *pMDImport = GetMDImport(); - IMDInternalImport *pNewMDImport; + pMDImport = GetMDImport(); // Apply the EnC delta to this module's metadata. IfFailGo(pMDImport->ApplyEditAndContinue(pDeltaMD, cbDeltaMD, &pNewMDImport)); @@ -195,7 +198,7 @@ HRESULT EditAndContinueModule::ApplyEditAndContinue( IfFailGo(GetMetaDataPublicInterfaceFromInternal(pMDImport, IID_IMetaDataEmit, (void **)&pEmitter)); // Copy the deltaIL into our RVAable IL memory - BYTE *pLocalILMemory = new BYTE[cbDeltaIL]; + pLocalILMemory = new BYTE[cbDeltaIL]; memcpy(pLocalILMemory, pDeltaIL, cbDeltaIL); // Enumerate all of the EnC delta tokens @@ -203,7 +206,6 @@ HRESULT EditAndContinueModule::ApplyEditAndContinue( IfFailGo(pIMDInternalImportENC->EnumDeltaTokensInit(&enumENC)); mdToken token; - FieldDesc * pField = NULL; while (pIMDInternalImportENC->EnumNext(&enumENC, &token)) { STRESS_LOG3(LF_ENC, LL_INFO100, "EACM::AEAC: updated token 0x%x; type 0x%x; rid 0x%x\n", token, TypeFromToken(token), RidFromToken(token)); @@ -248,8 +250,7 @@ HRESULT EditAndContinueModule::ApplyEditAndContinue( // FieldDef token - add a new field LOG((LF_ENC, LL_INFO10000, "EACM::AEAC: Found field 0x%x\n", token)); - pField = LookupFieldDef(token); - if (pField) + if (LookupFieldDef(token)) { // Field already exists - just ignore for now continue; diff --git a/src/coreclr/src/vm/excep.cpp b/src/coreclr/src/vm/excep.cpp index c161c47..b7c55d3 100644 --- a/src/coreclr/src/vm/excep.cpp +++ b/src/coreclr/src/vm/excep.cpp @@ -9916,47 +9916,48 @@ PTR_EHWatsonBucketTracker GetWatsonBucketTrackerForPreallocatedException(OBJECTR goto doValidation; } - // Find the reference to the exception tracker corresponding to the preallocated exception, - // starting the search from the current exception tracker (2nd arg of NULL specifies that). -#if defined(WIN64EXCEPTIONS) - PTR_ExceptionTracker pEHTracker = NULL; - PTR_ExceptionTracker pPreviousEHTracker = NULL; + { + // Find the reference to the exception tracker corresponding to the preallocated exception, + // starting the search from the current exception tracker (2nd arg of NULL specifies that). + #if defined(WIN64EXCEPTIONS) + PTR_ExceptionTracker pEHTracker = NULL; + PTR_ExceptionTracker pPreviousEHTracker = NULL; #elif _TARGET_X86_ - PTR_ExInfo pEHTracker = NULL; - PTR_ExInfo pPreviousEHTracker = NULL; + PTR_ExInfo pEHTracker = NULL; + PTR_ExInfo pPreviousEHTracker = NULL; #else // !(_WIN64 || _TARGET_X86_) #error Unsupported platform #endif // _WIN64 - if (fStartSearchFromPreviousTracker) - { - // Get the exception tracker previous to the current one - pPreviousEHTracker = GetThread()->GetExceptionState()->GetCurrentExceptionTracker()->GetPreviousExceptionTracker(); + if (fStartSearchFromPreviousTracker) + { + // Get the exception tracker previous to the current one + pPreviousEHTracker = GetThread()->GetExceptionState()->GetCurrentExceptionTracker()->GetPreviousExceptionTracker(); + + // If there is no previous tracker to start from, then simply abort the search attempt. + // If we couldnt find the exception tracker, then buckets are not available + if (pPreviousEHTracker == NULL) + { + LOG((LF_EH, LL_INFO100, "GetWatsonBucketTrackerForPreallocatedException - Couldnt find the previous EHTracker to start the search from.\n")); + pWBTracker = NULL; + goto done; + } + } + + pEHTracker = GetEHTrackerForPreallocatedException(gc.oPreAllocThrowable, pPreviousEHTracker); - // If there is no previous tracker to start from, then simply abort the search attempt. // If we couldnt find the exception tracker, then buckets are not available - if (pPreviousEHTracker == NULL) + if (pEHTracker == NULL) { - LOG((LF_EH, LL_INFO100, "GetWatsonBucketTrackerForPreallocatedException - Couldnt find the previous EHTracker to start the search from.\n")); + LOG((LF_EH, LL_INFO100, "GetWatsonBucketTrackerForPreallocatedException - Couldnt find EHTracker for preallocated exception object.\n")); pWBTracker = NULL; goto done; } - } - pEHTracker = GetEHTrackerForPreallocatedException(gc.oPreAllocThrowable, pPreviousEHTracker); - - // If we couldnt find the exception tracker, then buckets are not available - if (pEHTracker == NULL) - { - LOG((LF_EH, LL_INFO100, "GetWatsonBucketTrackerForPreallocatedException - Couldnt find EHTracker for preallocated exception object.\n")); - pWBTracker = NULL; - goto done; + // Get the Watson Bucket Tracker from the exception tracker + pWBTracker = pEHTracker->GetWatsonBucketTracker(); } - - // Get the Watson Bucket Tracker from the exception tracker - pWBTracker = pEHTracker->GetWatsonBucketTracker(); - doValidation: _ASSERTE(pWBTracker != NULL); diff --git a/src/coreclr/src/vm/i386/cgenx86.cpp b/src/coreclr/src/vm/i386/cgenx86.cpp index cefeeef..8864b02 100644 --- a/src/coreclr/src/vm/i386/cgenx86.cpp +++ b/src/coreclr/src/vm/i386/cgenx86.cpp @@ -1784,13 +1784,14 @@ DWORD GetLogicalCpuCount() PAL_TRY(Param *, pParam, ¶m) { unsigned char buffer[16]; + DWORD* dwBuffer = NULL; DWORD maxCpuId = getcpuid(0, buffer); if (maxCpuId < 1) goto lDone; - DWORD* dwBuffer = (DWORD*)buffer; + dwBuffer = (DWORD*)buffer; if (dwBuffer[1] == 'uneG') { if (dwBuffer[3] == 'Ieni') { diff --git a/src/coreclr/src/vm/mlinfo.cpp b/src/coreclr/src/vm/mlinfo.cpp index ab25452..74bd536 100644 --- a/src/coreclr/src/vm/mlinfo.cpp +++ b/src/coreclr/src/vm/mlinfo.cpp @@ -4865,6 +4865,8 @@ void ArrayMarshalInfo::InitForHiddenLengthArray(TypeHandle thElement) { STANDARD_VM_CONTRACT; + MethodTable *pMT = NULL; + // WinRT supports arrays of any WinRT-legal types if (thElement.IsArray()) { @@ -4877,7 +4879,7 @@ void ArrayMarshalInfo::InitForHiddenLengthArray(TypeHandle thElement) m_thElement = thElement; - MethodTable *pMT = thElement.GetMethodTable(); + pMT = thElement.GetMethodTable(); if (pMT->IsString()) { m_vtElement = VTHACK_HSTRING; diff --git a/src/coreclr/src/vm/util.cpp b/src/coreclr/src/vm/util.cpp index a7c264f..a96a56c 100644 --- a/src/coreclr/src/vm/util.cpp +++ b/src/coreclr/src/vm/util.cpp @@ -1950,17 +1950,18 @@ size_t GetLogicalProcessorCacheSizeFromOS() // Crack the information. Iterate through all the SLPI array entries for all processors in system. // Will return the greatest of all the processor cache sizes or zero - - size_t last_cache_size = 0; - - for (DWORD i=0; i < nEntries; i++) { - if (pslpi[i].Relationship == RelationCache) + size_t last_cache_size = 0; + + for (DWORD i=0; i < nEntries; i++) { - last_cache_size = max(last_cache_size, pslpi[i].Cache.Size); - } - } - cache_size = last_cache_size; + if (pslpi[i].Relationship == RelationCache) + { + last_cache_size = max(last_cache_size, pslpi[i].Cache.Size); + } + } + cache_size = last_cache_size; + } Exit: if(pslpi) @@ -1991,6 +1992,9 @@ DWORD GetLogicalCpuCountFromOS() DWORD nEntries = 0; + DWORD prevcount = 0; + DWORD count = 1; + // Try to use GetLogicalProcessorInformation API and get a valid pointer to the SLPI array if successful. Returns NULL // if API not present or on failure. SYSTEM_LOGICAL_PROCESSOR_INFORMATION *pslpi = IsGLPISupported(&nEntries) ; @@ -2001,9 +2005,6 @@ DWORD GetLogicalCpuCountFromOS() goto lDone; } - DWORD prevcount = 0; - DWORD count = 1; - for (DWORD j = 0; j < nEntries; j++) { if (pslpi[j].Relationship == RelationProcessorCore) diff --git a/src/coreclr/src/vm/win32threadpool.cpp b/src/coreclr/src/vm/win32threadpool.cpp index 98c7d3e..e8a05c3 100644 --- a/src/coreclr/src/vm/win32threadpool.cpp +++ b/src/coreclr/src/vm/win32threadpool.cpp @@ -3679,6 +3679,8 @@ DWORD __stdcall ThreadpoolMgr::CompletionPortThreadStart(LPVOID lpArgs) BOOL fThreadInit = FALSE; Thread *pThread = NULL; + DWORD cpThreadWait = 0; + if (g_fEEStarted) { pThread = SetupThreadNoThrow(); if (pThread == NULL) { @@ -3713,7 +3715,7 @@ DWORD __stdcall ThreadpoolMgr::CompletionPortThreadStart(LPVOID lpArgs) ThreadCounter::Counts oldCounts; ThreadCounter::Counts newCounts; - DWORD cpThreadWait = CP_THREAD_WAIT; + cpThreadWait = CP_THREAD_WAIT; for (;; ) { Top: -- 2.7.4