Skip to content

Commit

Permalink
Use minipal in more places (#3019)
Browse files Browse the repository at this point in the history
* Port minipal/getexepath.h from runtime repo

* Use ARRAY_SIZE from minipal in more places

* Fix C4996 warning on windows

* Introspect sys/auxv.h in SOS configuration

* Fix include
  • Loading branch information
am11 authored Apr 18, 2022
1 parent 570ef70 commit 9578eda
Show file tree
Hide file tree
Showing 30 changed files with 322 additions and 333 deletions.
8 changes: 4 additions & 4 deletions src/SOS/Strike/ExpressionNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2153,23 +2153,23 @@ HRESULT ExpressionNode::IsTokenValueTypeOrEnum(mdToken token, IMetaDataImport* p
{
ULONG chTypeDef;
pMetadata->GetTypeRefProps(token, NULL, NULL, 0, &chTypeDef);
if(chTypeDef > _countof(nameBuffer))
if(chTypeDef > ARRAY_SIZE(nameBuffer))
{
*pResult = FALSE;
return Status;
}
IfFailRet(pMetadata->GetTypeRefProps(token, NULL, nameBuffer, _countof(nameBuffer), &chTypeDef));
IfFailRet(pMetadata->GetTypeRefProps(token, NULL, nameBuffer, ARRAY_SIZE(nameBuffer), &chTypeDef));
}
else if(type == mdtTypeDef)
{
ULONG chTypeDef;
pMetadata->GetTypeDefProps(token, NULL, 0, &chTypeDef, NULL, NULL);
if(chTypeDef > _countof(nameBuffer))
if(chTypeDef > ARRAY_SIZE(nameBuffer))
{
*pResult = FALSE;
return Status;
}
IfFailRet(pMetadata->GetTypeDefProps(token, nameBuffer, _countof(nameBuffer), &chTypeDef, NULL, NULL));
IfFailRet(pMetadata->GetTypeDefProps(token, nameBuffer, ARRAY_SIZE(nameBuffer), &chTypeDef, NULL, NULL));
}

if(_wcscmp(nameBuffer, L"System.ValueType") == 0 ||
Expand Down
6 changes: 3 additions & 3 deletions src/SOS/Strike/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ char* PrintOneLine (__in_z char *begin, __in_z char *limit)
if (n > 127) {
n = 127;
}
strncpy_s (line,_countof(line), begin, n);
strncpy_s (line,ARRAY_SIZE(line), begin, n);
line[n] = '\0';
ExtOut ("%s", line);
begin += n;
Expand Down Expand Up @@ -839,7 +839,7 @@ void PrintNativeStack(DWORD_PTR ip, BOOL bSuppressLines)
char symbol[1024];
ULONG64 displacement;

HRESULT hr = g_ExtSymbols->GetNameByOffset(TO_CDADDR(ip), symbol, _countof(symbol), NULL, &displacement);
HRESULT hr = g_ExtSymbols->GetNameByOffset(TO_CDADDR(ip), symbol, ARRAY_SIZE(symbol), NULL, &displacement);
if (SUCCEEDED(hr) && symbol[0] != '\0')
{
ExtOut("%s", symbol);
Expand All @@ -852,7 +852,7 @@ void PrintNativeStack(DWORD_PTR ip, BOOL bSuppressLines)
if (!bSuppressLines)
{
ULONG line;
hr = g_ExtSymbols->GetLineByOffset(TO_CDADDR(ip), &line, filename, _countof(filename), NULL, NULL);
hr = g_ExtSymbols->GetLineByOffset(TO_CDADDR(ip), &line, filename, ARRAY_SIZE(filename), NULL, NULL);
if (SUCCEEDED(hr))
{
ExtOut(" [%s:%d]", filename, line);
Expand Down
8 changes: 4 additions & 4 deletions src/SOS/Strike/disasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class X86Machine : public IMachine
virtual LPCSTR GetDumpStackObjectsHeading() const { return s_DSOHeading; }
virtual LPCSTR GetSPName() const { return s_SPName; }
virtual void GetGCRegisters(LPCSTR** regNames, unsigned int* cntRegs) const
{ _ASSERTE(cntRegs != NULL); *regNames = s_GCRegs; *cntRegs = _countof(s_GCRegs); }
{ _ASSERTE(cntRegs != NULL); *regNames = s_GCRegs; *cntRegs = ARRAY_SIZE(s_GCRegs); }

virtual void DumpGCInfo(GCInfoToken gcInfoToken, unsigned methodSize, printfFtn gcPrintf, bool encBytes, bool bPrintHeader) const;

Expand Down Expand Up @@ -247,7 +247,7 @@ class ARMMachine : public IMachine
virtual LPCSTR GetDumpStackObjectsHeading() const { return s_DSOHeading; }
virtual LPCSTR GetSPName() const { return s_SPName; }
virtual void GetGCRegisters(LPCSTR** regNames, unsigned int* cntRegs) const
{ _ASSERTE(cntRegs != NULL); *regNames = s_GCRegs; *cntRegs = _countof(s_GCRegs); }
{ _ASSERTE(cntRegs != NULL); *regNames = s_GCRegs; *cntRegs = ARRAY_SIZE(s_GCRegs); }

virtual void DumpGCInfo(GCInfoToken gcInfoToken, unsigned methodSize, printfFtn gcPrintf, bool encBytes, bool bPrintHeader) const;

Expand Down Expand Up @@ -320,7 +320,7 @@ class AMD64Machine : public IMachine
virtual LPCSTR GetDumpStackObjectsHeading() const { return s_DSOHeading; }
virtual LPCSTR GetSPName() const { return s_SPName; }
virtual void GetGCRegisters(LPCSTR** regNames, unsigned int* cntRegs) const
{ _ASSERTE(cntRegs != NULL); *regNames = s_GCRegs; *cntRegs = _countof(s_GCRegs); }
{ _ASSERTE(cntRegs != NULL); *regNames = s_GCRegs; *cntRegs = ARRAY_SIZE(s_GCRegs); }

virtual void DumpGCInfo(GCInfoToken gcInfoToken, unsigned methodSize, printfFtn gcPrintf, bool encBytes, bool bPrintHeader) const;

Expand Down Expand Up @@ -390,7 +390,7 @@ class ARM64Machine : public IMachine
virtual LPCSTR GetDumpStackObjectsHeading() const { return s_DSOHeading; }
virtual LPCSTR GetSPName() const { return s_SPName; }
virtual void GetGCRegisters(LPCSTR** regNames, unsigned int* cntRegs) const
{ _ASSERTE(cntRegs != NULL); *regNames = s_GCRegs; *cntRegs = _countof(s_GCRegs);}
{ _ASSERTE(cntRegs != NULL); *regNames = s_GCRegs; *cntRegs = ARRAY_SIZE(s_GCRegs);}

virtual void DumpGCInfo(GCInfoToken gcInfoToken, unsigned methodSize, printfFtn gcPrintf, bool encBytes, bool bPrintHeader) const;

Expand Down
4 changes: 2 additions & 2 deletions src/SOS/Strike/disasmARM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ void ARMMachine::Unassembly (
}

ULONG_PTR prevPC = PC;
DisasmAndClean (PC, line, _countof(line));
DisasmAndClean (PC, line, ARRAY_SIZE(line));

// look at the disassembled bytes
ptr = line;
Expand Down Expand Up @@ -451,7 +451,7 @@ void ARMMachine::Unassembly (
ULONG_PTR OrigInstrAddr = GCStressCodeCopy + (InstrAddr - PCBegin);
ULONG_PTR OrigPC = OrigInstrAddr;

DisasmAndClean(OrigPC, line, _countof(line));
DisasmAndClean(OrigPC, line, ARRAY_SIZE(line));

//
// Increment the real PC based on the size of the unmodifed
Expand Down
4 changes: 2 additions & 2 deletions src/SOS/Strike/disasmARM64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void ARM64Machine::Unassembly (
while(PC < PCEnd)
{
ULONG_PTR currentPC = PC;
DisasmAndClean (PC, line, _countof(line));
DisasmAndClean (PC, line, ARRAY_SIZE(line));

// This is the closing of the previous run.
// Check the next instruction. if it's not a the last movk, handle the accumulated value
Expand Down Expand Up @@ -265,7 +265,7 @@ void ARM64Machine::Unassembly (
ULONG_PTR OrigInstrAddr = GCStressCodeCopy + (InstrAddr - PCBegin);
ULONG_PTR OrigPC = OrigInstrAddr;

DisasmAndClean(OrigPC, line, _countof(line));
DisasmAndClean(OrigPC, line, ARRAY_SIZE(line));

//
// Increment the real PC based on the size of the unmodifed
Expand Down
6 changes: 3 additions & 3 deletions src/SOS/Strike/disasmX86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ inline RegIndex FindReg (___in __in_z char *ptr, __out_opt int *plen = NULL, __o

};

for (size_t i = 0; i < sizeof(rgRegNames)/sizeof(rgRegNames[0]); i++)
for (size_t i = 0; i < ARRAY_SIZE(rgRegNames); i++)
{
if (!strncmp(ptr, rgRegNames[i].pszName, rgRegNames[i].cchName))
{
Expand Down Expand Up @@ -577,7 +577,7 @@ void

ULONG_PTR InstrAddr = IP;

DisasmAndClean (IP, line, _countof(line));
DisasmAndClean (IP, line, ARRAY_SIZE(line));

// look at key word
ptr = line;
Expand Down Expand Up @@ -605,7 +605,7 @@ void
ULONG_PTR OrigInstrAddr = GCStressCodeCopy + (InstrAddr - IPBegin);
ULONG_PTR OrigIP = OrigInstrAddr;

DisasmAndClean(OrigIP, line, _countof(line));
DisasmAndClean(OrigIP, line, ARRAY_SIZE(line));

//
// Increment the real IP based on the size of the unmodifed
Expand Down
4 changes: 2 additions & 2 deletions src/SOS/Strike/eeheap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,7 @@ BOOL GCHeapSnapshot::AddSegments(const GCHeapDetails& details)
// this loop will get information for all the heap segments in this heap. The outer loop iterates once
// for the "normal" generation segments and once for the large object heap. The inner loop follows the chain
// of segments rooted at AddrSegs[i]
for (unsigned int i = 0; i < sizeof(AddrSegs)/sizeof(AddrSegs[0]); ++i)
for (unsigned int i = 0; i < ARRAY_SIZE(AddrSegs); ++i)
{
if (AddrSegs[i] == NULL)
{
Expand Down Expand Up @@ -2370,4 +2370,4 @@ DWORD_PTR PrintModuleHeapInfo(__out_ecount(count) DWORD_PTR *moduleList, int cou
*outWasted += wasted;

return toReturn;
}
}
6 changes: 3 additions & 3 deletions src/SOS/Strike/gchist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ DECLARE_API(HistRoot)
{&rootstr.data, COSTRING},
};

if (!GetCMDOption(args, NULL, 0, arg, _countof(arg), &nArg))
if (!GetCMDOption(args, NULL, 0, arg, ARRAY_SIZE(arg), &nArg))
return Status;

if (nArg != 1)
Expand Down Expand Up @@ -463,7 +463,7 @@ DECLARE_API(HistObjFind)
{&objstr.data, COSTRING},
};

if (!GetCMDOption(args, NULL, 0, arg, _countof(arg), &nArg))
if (!GetCMDOption(args, NULL, 0, arg, ARRAY_SIZE(arg), &nArg))
return Status;

if (nArg != 1)
Expand Down Expand Up @@ -542,7 +542,7 @@ DECLARE_API(HistObj)
{&objstr.data, COSTRING},
};

if (!GetCMDOption(args, NULL, 0, arg, _countof(arg), &nArg))
if (!GetCMDOption(args, NULL, 0, arg, ARRAY_SIZE(arg), &nArg))
return Status;

if (nArg != 1)
Expand Down
16 changes: 8 additions & 8 deletions src/SOS/Strike/gcroot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void GCRootImpl::GetDependentHandleMap(std::unordered_map<TADDR, std::list<TADDR

do
{
hr = handles->Next(_countof(data), data, &fetched);
hr = handles->Next(ARRAY_SIZE(data), data, &fetched);

if (FAILED(hr))
{
Expand All @@ -240,7 +240,7 @@ void GCRootImpl::GetDependentHandleMap(std::unordered_map<TADDR, std::list<TADDR
map[obj].push_back(target);
}
}
} while (fetched == _countof(data));
} while (fetched == ARRAY_SIZE(data));
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -791,7 +791,7 @@ int GCRootImpl::PrintRootsOnHandleTable(int gen)
do
{
// Fetch more handles
hr = pEnum->Next(_countof(handles), handles, &fetched);
hr = pEnum->Next(ARRAY_SIZE(handles), handles, &fetched);
if (FAILED(hr))
{
ExtOut("Failed to request more handles.\n");
Expand Down Expand Up @@ -833,7 +833,7 @@ int GCRootImpl::PrintRootsOnHandleTable(int gen)
}
}
}
while (_countof(handles) == fetched);
while (ARRAY_SIZE(handles) == fetched);

return total;
}
Expand Down Expand Up @@ -1244,7 +1244,7 @@ UINT FindAllPinnedAndStrong(DWORD_PTR handlearray[], UINT arraySize)

do
{
hr = handles->Next(_countof(data), data, &fetched);
hr = handles->Next(ARRAY_SIZE(data), data, &fetched);

if (FAILED(hr))
{
Expand All @@ -1265,7 +1265,7 @@ UINT FindAllPinnedAndStrong(DWORD_PTR handlearray[], UINT arraySize)
handlearray[pos++] = (DWORD_PTR)data[i].Handle;
}
}
} while (fetched == _countof(data));
} while (fetched == ARRAY_SIZE(data));

return pos;
}
Expand Down Expand Up @@ -2190,14 +2190,14 @@ void HeapTraverser::TraceHandles()

do
{
hr = handles->Next(_countof(data), data, &fetched);
hr = handles->Next(ARRAY_SIZE(data), data, &fetched);

if (FAILED(hr))
break;

for (unsigned int i = 0; i < fetched; ++i)
PrintRoot(W("handle"), (size_t)data[i].Handle);
} while (fetched == _countof(data));
} while (fetched == ARRAY_SIZE(data));
}

/* static */ void HeapTraverser::GatherTypes(DWORD_PTR objAddr,size_t Size,
Expand Down
8 changes: 4 additions & 4 deletions src/SOS/Strike/metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ void MDInfo::GetMethodName(mdTypeDef token, CQuickBytes *fullName)
WCHAR szFunctionName[1024];

hr = m_pImport->GetMethodProps(token, &memTypeDef,
szFunctionName, _countof(szFunctionName), &nameLen,
szFunctionName, ARRAY_SIZE(szFunctionName), &nameLen,
&flags, &pbSigBlob, &ulSigBlob, &ulCodeRVA, &ulImplFlags);
if (FAILED (hr))
{
Expand All @@ -393,12 +393,12 @@ void MDInfo::GetMethodName(mdTypeDef token, CQuickBytes *fullName)
m_szName[0] = L'\0';
if (memTypeDef != mdTypeDefNil)
{
hr = NameForTypeDef_s (memTypeDef, m_pImport, m_szName, _countof(m_szName));
hr = NameForTypeDef_s (memTypeDef, m_pImport, m_szName, ARRAY_SIZE(m_szName));
if (SUCCEEDED (hr)) {
wcscat_s (m_szName, _countof(m_szName), W("."));
wcscat_s (m_szName, ARRAY_SIZE(m_szName), W("."));
}
}
wcscat_s (m_szName, _countof(m_szName), szFunctionName);
wcscat_s (m_szName, ARRAY_SIZE(m_szName), szFunctionName);

LONG lSigBlobRemaining;
hr = GetFullNameForMD(pbSigBlob, ulSigBlob, &lSigBlobRemaining);
Expand Down
2 changes: 1 addition & 1 deletion src/SOS/Strike/platform/targetimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ LPCSTR Target::GetTempDirectory()
pid = ::GetCurrentProcessId();
}
char pidstr[128];
sprintf_s(pidstr, _countof(pidstr), "sos%d", pid);
sprintf_s(pidstr, ARRAY_SIZE(pidstr), "sos%d", pid);
strcat_s(tmpPath, MAX_LONGPATH, pidstr);
strcat_s(tmpPath, MAX_LONGPATH, DIRECTORY_SEPARATOR_STR_A);

Expand Down
Loading

0 comments on commit 9578eda

Please sign in to comment.