Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

fix permissive C++ code (MSVC /permissive-) #8337

Merged
merged 3 commits into from
Dec 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/ToolBox/SOS/Strike/strike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
64 changes: 33 additions & 31 deletions src/ToolBox/SOS/Strike/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<WCHAR> 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<WCHAR> 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);
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/debug/ee/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2824,6 +2824,8 @@ DPOSS_ACTION DebuggerController::DispatchPatchOrSingleStep(Thread *thread, CONTE

CrstHolderWithState lockController(&g_criticalSection);

TADDR originalAddress = 0;

#ifdef EnC_SUPPORTED
DebuggerControllerPatch *dcpEnCOriginal = NULL;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 12 additions & 5 deletions src/dlls/mscorpe/ceefilegenwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<unsigned>(cbTotalSizeOfRawData.Value()), 8);
data = rsrcSection->getBlock(static_cast<unsigned>(cbTotalSizeOfRawData.Value()), 8);
if(data == NULL)
{
pParam->hr = E_OUTOFMEMORY;
Expand All @@ -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
Expand Down
120 changes: 62 additions & 58 deletions src/jit/codegenlegacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 */
Expand Down
24 changes: 13 additions & 11 deletions src/md/ceefilegen/cceegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading