This commit is contained in:
Huo Yaoyuan 2025-07-30 07:06:08 -07:00 committed by GitHub
commit e64041b491
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
26 changed files with 488 additions and 852 deletions

View File

@ -4,6 +4,7 @@
#include "blobfetcher.h"
#include "pedecoder.h"
#include <dn-stdio.h>
#ifdef _DEBUG
#define LOGGING
@ -547,7 +548,7 @@ HRESULT PEWriter::Init(PESectionMan *pFrom, DWORD createFlags)
headers = NULL;
headersEnd = NULL;
m_file = INVALID_HANDLE_VALUE;
m_file = NULL;
return S_OK;
}
@ -626,21 +627,15 @@ HRESULT PEWriter::setDirectoryEntry(PEWriterSection *section, ULONG entry, ULONG
return S_OK;
}
//-----------------------------------------------------------------------------
// These 2 write functions must be implemented here so that they're in the same
// .obj file as whoever creates the FILE struct. We can't pass a FILE struct
// across a dll boundary and use it.
//-----------------------------------------------------------------------------
HRESULT PEWriterSection::write(HANDLE file)
HRESULT PEWriterSection::write(FILE* file)
{
return m_blobFetcher.Write(file);
}
//-----------------------------------------------------------------------------
// Write out the section to the stream
// Write out the section to the file
//-----------------------------------------------------------------------------
HRESULT CBlobFetcher::Write(HANDLE file)
HRESULT CBlobFetcher::Write(FILE* file)
{
// Must write out each pillar (including idx = m_nIndexUsed), one after the other
unsigned idx;
@ -648,10 +643,10 @@ HRESULT CBlobFetcher::Write(HANDLE file)
if (m_pIndex[idx].GetDataLen() > 0)
{
ULONG length = m_pIndex[idx].GetDataLen();
DWORD dwWritten = 0;
if (!WriteFile(file, m_pIndex[idx].GetRawDataStart(), length, &dwWritten, NULL))
size_t dwWritten = 0;
if ((dwWritten = fwrite(m_pIndex[idx].GetRawDataStart(), 1, length, file)) <= 0)
{
return HRESULT_FROM_GetLastError();
return HRESULT_FROM_LAST_STDIO();
}
_ASSERTE(dwWritten == length);
}
@ -1336,37 +1331,32 @@ HRESULT PEWriter::fixup(CeeGenTokenMapper *pMapper)
HRESULT PEWriter::Open(_In_ LPCWSTR fileName)
{
_ASSERTE(m_file == INVALID_HANDLE_VALUE);
_ASSERTE(m_file == NULL);
HRESULT hr = NOERROR;
m_file = WszCreateFile(fileName,
GENERIC_WRITE,
0, // No sharing. Was: FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL );
if (m_file == INVALID_HANDLE_VALUE)
hr = HRESULT_FROM_GetLastErrorNA();
int err = fopen_lp(&m_file, fileName, W("wb"));
if (err != 0)
hr = HRESULT_FROM_LAST_STDIO();
return hr;
}
HRESULT PEWriter::Seek(int offset)
{
_ASSERTE(m_file != INVALID_HANDLE_VALUE);
if (SetFilePointer(m_file, offset, 0, FILE_BEGIN))
_ASSERTE(m_file != NULL);
if (fseek(m_file, offset, SEEK_SET) == 0)
return S_OK;
else
return HRESULT_FROM_GetLastError();
return HRESULT_FROM_LAST_STDIO();
}
HRESULT PEWriter::Write(const void *data, int size)
{
_ASSERTE(m_file != INVALID_HANDLE_VALUE);
_ASSERTE(m_file != NULL);
HRESULT hr = S_OK;
DWORD dwWritten = 0;
size_t dwWritten = 0;
if (size)
{
CQuickBytes zero;
@ -1379,13 +1369,13 @@ HRESULT PEWriter::Write(const void *data, int size)
data = zero.Ptr();
}
}
if (WriteFile(m_file, data, size, &dwWritten, NULL))
_ASSERTE(data != NULL);
if ((dwWritten = fwrite(data, 1, size, m_file)) >= 0)
{
_ASSERTE(dwWritten == (DWORD)size);
_ASSERTE(dwWritten == (size_t)size);
}
else
hr = HRESULT_FROM_GetLastError();
hr = HRESULT_FROM_LAST_STDIO();
}
return hr;
@ -1393,7 +1383,7 @@ HRESULT PEWriter::Write(const void *data, int size)
HRESULT PEWriter::Pad(int align)
{
DWORD offset = SetFilePointer(m_file, 0, NULL, FILE_CURRENT);
DWORD offset = (DWORD)ftell(m_file);
int pad = padLen(offset, align);
if (pad > 0)
return Write(NULL, pad);
@ -1403,16 +1393,17 @@ HRESULT PEWriter::Pad(int align)
HRESULT PEWriter::Close()
{
if (m_file == INVALID_HANDLE_VALUE)
if (m_file == NULL)
return S_OK;
int err = fclose(m_file);
HRESULT hr;
if (CloseHandle(m_file))
if (err == 0)
hr = S_OK;
else
hr = HRESULT_FROM_GetLastError();
hr = HRESULT_FROM_LAST_STDIO();
m_file = INVALID_HANDLE_VALUE;
m_file = NULL;
return hr;
}

View File

@ -111,7 +111,7 @@ private:
ULONG m_codeRvaBase;
DWORD m_peFileTimeStamp;
HANDLE m_file;
FILE* m_file;
PEWriterSection **getSectStart() {
return (PEWriterSection**)sectStart;
@ -203,7 +203,7 @@ public:
DWORD dataRvaBase,
DWORD textRvaBase);
virtual HRESULT write (HANDLE file);
virtual HRESULT write (FILE* file);
virtual unsigned writeMem (void ** pMem);
};

View File

@ -10,6 +10,7 @@
#include "assembler.h"
#include "strongnameinternal.h"
#include <limits.h>
#include <dn-stdio.h>
extern WCHAR* pwzInputFiles[];
@ -404,28 +405,23 @@ void AsmMan::EndAssembly()
else
{
// Read public key or key pair from file.
HANDLE hFile = WszCreateFile(((Assembler*)m_pAssembler)->m_wzKeySourceName,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
NULL);
if(hFile == INVALID_HANDLE_VALUE)
FILE* fp;
int err = fopen_lp(&fp, ((Assembler*)m_pAssembler)->m_wzKeySourceName, W("rb"));
if (err != 0)
{
hr = GetLastError();
MAKE_UTF8PTR_FROMWIDE(keySourceNameUtf8, ((Assembler*)m_pAssembler)->m_wzKeySourceName);
report->error("Failed to open key file '%s': 0x%08X\n",keySourceNameUtf8,hr);
report->error("Failed to open key file '%s': 0x%08X\n",keySourceNameUtf8,err);
m_pCurAsmRef = NULL;
return;
}
// Determine file size and allocate an appropriate buffer.
m_sStrongName.m_cbPublicKey = SafeGetFileSize(hFile, NULL);
if (m_sStrongName.m_cbPublicKey == 0xffffffff) {
int64_t fSize = fgetsize(fp);
m_sStrongName.m_cbPublicKey = (DWORD)fSize;
if (fSize > UINT32_MAX) {
report->error("File size too large\n");
m_pCurAsmRef = NULL;
CloseHandle(hFile);
fclose(fp);
return;
}
@ -433,23 +429,23 @@ void AsmMan::EndAssembly()
if (m_sStrongName.m_pbPublicKey == NULL) {
report->error("Failed to allocate key buffer\n");
m_pCurAsmRef = NULL;
CloseHandle(hFile);
fclose(fp);
return;
}
m_sStrongName.m_dwPublicKeyAllocated = AsmManStrongName::AllocatedByNew;
// Read the file into the buffer.
DWORD dwBytesRead;
if (!ReadFile(hFile, m_sStrongName.m_pbPublicKey, m_sStrongName.m_cbPublicKey, &dwBytesRead, NULL)) {
hr = GetLastError();
size_t dwBytesRead;
if ((dwBytesRead = fread(m_sStrongName.m_pbPublicKey, 1, m_sStrongName.m_cbPublicKey, fp)) <= m_sStrongName.m_cbPublicKey) {
MAKE_UTF8PTR_FROMWIDE(keySourceNameUtf8, ((Assembler*)m_pAssembler)->m_wzKeySourceName);
report->error("Failed to read key file '%s': 0x%08X\n",keySourceNameUtf8,hr);
report->error("Failed to read key file '%s': 0x%08X\n",keySourceNameUtf8,HRESULT_FROM_LAST_STDIO());
m_pCurAsmRef = NULL;
CloseHandle(hFile);
fclose(fp);
return;
}
CloseHandle(hFile);
fclose(fp);
// Guess whether we're full or delay signing based on
// whether the blob passed to us looks like a public

View File

@ -80,9 +80,6 @@ BOOL g_fShowCA = TRUE;
BOOL g_fCAVerbal = FALSE;
BOOL g_fShowRefs = FALSE;
BOOL g_fDumpToPerfWriter = FALSE;
HANDLE g_PerfDataFilePtr = NULL;
BOOL g_fDumpClassList = FALSE;
BOOL g_fDumpTypeList = FALSE;
BOOL g_fDumpSummary = FALSE;
@ -5791,65 +5788,6 @@ void DumpHeaderDetails(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
printLine(GUICookie,"");
}
void WritePerfData(const char *KeyDesc, const char *KeyName, const char *UnitDesc, const char *UnitName, void* Value, BOOL IsInt)
{
DWORD BytesWritten;
if(!g_fDumpToPerfWriter) return;
if (!g_PerfDataFilePtr)
{
if((g_PerfDataFilePtr = WszCreateFile(W("c:\\temp\\perfdata.dat"), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL) ) == INVALID_HANDLE_VALUE)
{
printLine(NULL,"PefTimer::LogStoppedTime(): Unable to open the FullPath file. No performance data will be generated");
g_fDumpToPerfWriter = FALSE;
return;
}
WriteFile(g_PerfDataFilePtr,"ExecTime=0\r\n",13,&BytesWritten,NULL);
WriteFile(g_PerfDataFilePtr,"ExecUnit=bytes\r\n",17,&BytesWritten,NULL);
WriteFile(g_PerfDataFilePtr,"ExecUnitDescr=File Size\r\n",26,&BytesWritten,NULL);
WriteFile(g_PerfDataFilePtr,"ExeciDirection=False\r\n",23,&BytesWritten,NULL);
}
char ValueStr[10];
char TmpStr[201];
if (IsInt)
{
sprintf_s(ValueStr,10,"%d",(int)*(int*)Value);
}
else
{
sprintf_s(ValueStr,10,"%5.2f",(float)*(float*)Value);
}
sprintf_s(TmpStr, 201, "%s=%s\r\n", KeyName, ValueStr);
WriteFile(g_PerfDataFilePtr, TmpStr, (DWORD)strlen(TmpStr), &BytesWritten, NULL);
sprintf_s(TmpStr, 201, "%s Descr=%s\r\n", KeyName, KeyDesc);
WriteFile(g_PerfDataFilePtr, TmpStr, (DWORD)strlen(TmpStr), &BytesWritten, NULL);
sprintf_s(TmpStr, 201, "%s Unit=%s\r\n", KeyName, UnitName);
WriteFile(g_PerfDataFilePtr, TmpStr, (DWORD)strlen(TmpStr), &BytesWritten, NULL);
sprintf_s(TmpStr, 201, "%s Unit Descr=%s\r\n", KeyName, UnitDesc);
WriteFile(g_PerfDataFilePtr, TmpStr, (DWORD)strlen(TmpStr), &BytesWritten, NULL);
sprintf_s(TmpStr, 201, "%s IDirection=%s\r\n", KeyName, "False");
WriteFile(g_PerfDataFilePtr, TmpStr, (DWORD)strlen(TmpStr), &BytesWritten, NULL);
}
void WritePerfDataInt(const char *KeyDesc, const char *KeyName, const char *UnitDesc, const char *UnitName, int Value)
{
WritePerfData(KeyDesc,KeyName,UnitDesc,UnitName, (void*)&Value, TRUE);
}
void WritePerfDataFloat(const char *KeyDesc, const char *KeyName, const char *UnitDesc, const char *UnitName, float Value)
{
WritePerfData(KeyDesc,KeyName,UnitDesc,UnitName, (void*)&Value, FALSE);
}
IMetaDataTables *pITables = NULL;
//ULONG sizeRec, count;
//int size, size2;
@ -5877,8 +5815,6 @@ void DumpTable(unsigned long Table, const char *TableName, void* GUICookie)
if(count > 0)
{
metaSize += size = count * sizeRec;
WritePerfDataInt(TableName,TableName,"count","count",count);
WritePerfDataInt(TableName,TableName,"bytes","bytes",size);
sprintf_s(szString,SZSTRING_SIZE,"// %-14s- %4d (%d bytes)", TableName, count, size);
printLine(GUICookie,szStr);
}
@ -5902,8 +5838,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
sprintf_s(szString,SZSTRING_SIZE,"// File size : %d", fileSize = SafeGetFileSize(g_pPELoader->getHFile(), NULL));
printLine(GUICookie,szStr);
WritePerfDataInt("FileSize","FileSize","standard byte","bytes",fileSize);
if (g_pPELoader->IsPE32())
{
size = VAL32(((IMAGE_DOS_HEADER*) g_pPELoader->getHModule())->e_lfanew) +
@ -5926,10 +5860,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
if (g_pPELoader->IsPE32())
{
sizeOfHeaders = VAL32(g_pPELoader->ntHeaders32()->OptionalHeader.SizeOfHeaders);
WritePerfDataInt("PE header size", "PE header size", "standard byte", "bytes", sizeOfHeaders);
WritePerfDataInt("PE header size used", "PE header size used", "standard byte", "bytes", size);
WritePerfDataFloat("PE header size", "PE header size", "percentage", "percentage", (float)((sizeOfHeaders * 100) / fileSize));
sprintf_s(szString,SZSTRING_SIZE,"// PE header size : %d (%d used) (%5.2f%%)",
sizeOfHeaders, size, (double) (sizeOfHeaders * 100) / fileSize);
@ -5945,11 +5875,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
else
{
sizeOfHeaders = VAL32(g_pPELoader->ntHeaders64()->OptionalHeader.SizeOfHeaders);
WritePerfDataInt("PE+ header size", "PE header size", "standard byte", "bytes", sizeOfHeaders);
WritePerfDataInt("PE+ header size used", "PE header size used", "standard byte", "bytes", size);
WritePerfDataFloat("PE+ header size", "PE header size", "percentage", "percentage", (float)((sizeOfHeaders * 100) / fileSize));
sprintf_s(szString,SZSTRING_SIZE,"// PE header size : %d (%d used) (%5.2f%%)",
sizeOfHeaders, size, (double) (sizeOfHeaders * 100) / fileSize);
@ -5963,9 +5888,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
}
}
WritePerfDataInt("PE additional info", "PE additional info", "standard byte", "bytes",miscPESize);
WritePerfDataFloat("PE additional info", "PE additional info", "percentage", "percent", (float) ((miscPESize * 100) / fileSize));
sprintf_s(buf, MAX_MEMBER_LENGTH, "PE additional info : %d", miscPESize);
sprintf_s(szString,SZSTRING_SIZE,"// %-40s (%5.2f%%)", buf, (double) (miscPESize * 100) / fileSize);
printLine(GUICookie,szStr);
@ -5980,21 +5902,15 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
numberOfSections = VAL16(g_pPELoader->ntHeaders64()->FileHeader.NumberOfSections);
}
WritePerfDataInt("Num.of PE sections", "Num.of PE sections", "Nbr of sections", "sections",numberOfSections);
sprintf_s(szString,SZSTRING_SIZE,"// Num.of PE sections : %d", numberOfSections);
printLine(GUICookie,szStr);
WritePerfDataInt("CLR header size", "CLR header size", "byte", "bytes",VAL32(CORHeader->cb));
WritePerfDataFloat("CLR header size", "CLR header size", "percentage", "percent",(float) ((VAL32(CORHeader->cb) * 100) / fileSize));
sprintf_s(buf, MAX_MEMBER_LENGTH, "CLR header size : %d", VAL32(CORHeader->cb));
sprintf_s(szString,SZSTRING_SIZE,"// %-40s (%5.2f%%)", buf, (double) (VAL32(CORHeader->cb) * 100) / fileSize);
printLine(GUICookie,szStr);
DWORD dwMetaSize = g_cbMetaData;
WritePerfDataInt("CLR meta-data size", "CLR meta-data size", "bytes", "bytes",dwMetaSize);
WritePerfDataFloat("CLR meta-data size", "CLR meta-data size", "percentage", "percent",(float) ((dwMetaSize * 100) / fileSize));
sprintf_s(buf, MAX_MEMBER_LENGTH, "CLR meta-data size : %d", dwMetaSize);
sprintf_s(szString,SZSTRING_SIZE,"// %-40s (%5.2f%%)", buf, (double) (dwMetaSize * 100) / fileSize);
@ -6009,9 +5925,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
pFirst++;
}
WritePerfDataInt("CLR Additional info", "CLR Additional info", "bytes", "bytes",miscCOMPlusSize);
WritePerfDataFloat("CLR Additional info", "CLR Additional info", "percentage", "percent",(float) ((miscCOMPlusSize * 100) / fileSize));
sprintf_s(buf, MAX_MEMBER_LENGTH, "CLR additional info : %d", miscCOMPlusSize);
sprintf_s(szString,SZSTRING_SIZE,"// %-40s (%5.2f%%)", buf, (double) (miscCOMPlusSize * 100) / fileSize);
printLine(GUICookie,szStr);
@ -6081,17 +5994,10 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
}
}
WritePerfDataInt("CLR method headers", "CLR method headers", "bytes", "bytes",methodHeaderSize);
WritePerfDataFloat("CLR method headers", "CLR method headers", "percentage", "percent",(float) ((methodHeaderSize * 100) / fileSize));
sprintf_s(buf, MAX_MEMBER_LENGTH, "CLR method headers : %d", methodHeaderSize);
sprintf_s(szString,SZSTRING_SIZE,"// %-40s (%5.2f%%)", buf, (double) (methodHeaderSize * 100) / fileSize);
printLine(GUICookie,szStr);
WritePerfDataInt("Managed code", "Managed code", "bytes", "bytes",methodBodySize);
WritePerfDataFloat("Managed code", "Managed code", "percentage", "percent",(float) ((methodBodySize * 100) / fileSize));
sprintf_s(buf, MAX_MEMBER_LENGTH, "Managed code : %d", methodBodySize);
sprintf_s(szString,SZSTRING_SIZE,"// %-40s (%5.2f%%)", buf, (double) (methodBodySize * 100) / fileSize);
printLine(GUICookie,szStr);
@ -6100,9 +6006,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
{
DWORD sizeOfInitializedData = VAL32(g_pPELoader->ntHeaders32()->OptionalHeader.SizeOfInitializedData);
WritePerfDataInt("Data", "Data", "bytes", "bytes",sizeOfInitializedData);
WritePerfDataFloat("Data", "Data", "percentage", "percent",(float) ((sizeOfInitializedData * 100) / fileSize));
sprintf_s(buf, MAX_MEMBER_LENGTH, "Data : %d", sizeOfInitializedData);
sprintf_s(szString,SZSTRING_SIZE,"// %-40s (%5.2f%%)", buf, (double) (sizeOfInitializedData * 100) / fileSize);
printLine(GUICookie,szStr);
@ -6116,9 +6019,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
{
DWORD sizeOfInitializedData = VAL32(g_pPELoader->ntHeaders64()->OptionalHeader.SizeOfInitializedData);
WritePerfDataInt("Data", "Data", "bytes", "bytes",sizeOfInitializedData);
WritePerfDataFloat("Data", "Data", "percentage", "percent",(float) ((sizeOfInitializedData * 100) / fileSize));
sprintf_s(buf, MAX_MEMBER_LENGTH, "Data : %d", sizeOfInitializedData);
sprintf_s(szString,SZSTRING_SIZE,"// %-40s (%5.2f%%)", buf, (double) (sizeOfInitializedData * 100) / fileSize);
printLine(GUICookie,szStr);
@ -6129,9 +6029,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
methodHeaderSize - methodBodySize;
}
WritePerfDataInt("Unaccounted", "Unaccounted", "bytes", "bytes",size);
WritePerfDataFloat("Unaccounted", "Unaccounted", "percentage", "percent",(float) ((size * 100) / fileSize));
sprintf_s(buf, MAX_MEMBER_LENGTH, "Unaccounted : %d", size);
sprintf_s(szString,SZSTRING_SIZE,"// %-40s (%5.2f%%)", buf, (double) (size * 100) / fileSize);
printLine(GUICookie,szStr);
@ -6142,7 +6039,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
{
numberOfSections = VAL16(g_pPELoader->ntHeaders32()->FileHeader.NumberOfSections);
WritePerfDataInt("Num.of PE sections", "Num.of PE sections", "bytes", "bytes",numberOfSections);
printLine(GUICookie,"");
sprintf_s(szString,SZSTRING_SIZE,"// Num.of PE sections : %d", numberOfSections);
printLine(GUICookie,szStr);
@ -6151,7 +6047,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
for (i=0; i < numberOfSections; ++i)
{
WritePerfDataInt((char*)pSecHdr->Name,(char*)pSecHdr->Name, "bytes", "bytes",VAL32(pSecHdr->SizeOfRawData));
sprintf_s(szString,SZSTRING_SIZE,"// %-8s - %d", pSecHdr->Name, VAL32(pSecHdr->SizeOfRawData));
printLine(GUICookie,szStr);
++pSecHdr;
@ -6161,7 +6056,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
{
numberOfSections = VAL16(g_pPELoader->ntHeaders64()->FileHeader.NumberOfSections);
WritePerfDataInt("Num.of PE sections", "Num.of PE sections", "bytes", "bytes",numberOfSections);
printLine(GUICookie,"");
sprintf_s(szString,SZSTRING_SIZE,"// Num.of PE sections : %d", numberOfSections);
printLine(GUICookie,szStr);
@ -6170,7 +6064,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
for (i=0; i < numberOfSections; ++i)
{
WritePerfDataInt((char*)pSecHdr->Name,(char*)pSecHdr->Name, "bytes", "bytes",pSecHdr->SizeOfRawData);
sprintf_s(szString,SZSTRING_SIZE,"// %-8s - %d", pSecHdr->Name, pSecHdr->SizeOfRawData);
printLine(GUICookie,szStr);
++pSecHdr;
@ -6192,7 +6085,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
else
{
DWORD Size = g_cbMetaData;
WritePerfDataInt("CLR meta-data size", "CLR meta-data size", "bytes", "bytes",Size);
printLine(GUICookie,"");
sprintf_s(szString,SZSTRING_SIZE,"// CLR meta-data size : %d", Size);
printLine(GUICookie,szStr);
@ -6201,8 +6093,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
pITables->GetTableInfo(TBL_Module, &sizeRec, &count, NULL, NULL, NULL);
TableSeen(TBL_Module);
metaSize += size = count * sizeRec; \
WritePerfDataInt("Module (count)", "Module (count)", "count", "count",count);
WritePerfDataInt("Module (bytes)", "Module (bytes)", "bytes", "bytes",size);
sprintf_s(szString,SZSTRING_SIZE,"// %-14s- %4d (%d bytes)", "Module", count, size); \
printLine(GUICookie,szStr);
@ -6223,11 +6113,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
TableSeen(TBL_TypeDef);
metaSize += size = count * sizeRec;
WritePerfDataInt("TypeDef (count)", "TypeDef (count)", "count", "count", count);
WritePerfDataInt("TypeDef (bytes)", "TypeDef (bytes)", "bytes", "bytes", size);
WritePerfDataInt("interfaces", "interfaces", "count", "count", interfaces);
WritePerfDataInt("explicitLayout", "explicitLayout", "count", "count", explicitLayout);
sprintf_s(buf, MAX_MEMBER_LENGTH, " TypeDef - %4d (%d bytes)", count, size);
sprintf_s(szString,SZSTRING_SIZE,"// %-38s %d interfaces, %d explicit layout", buf, interfaces, explicitLayout);
printLine(GUICookie,szStr);
@ -6239,8 +6124,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
if (count > 0)
{
metaSize += size = count * sizeRec; \
WritePerfDataInt("TypeRef (count)", "TypeRef (count)", "count", "count", count);
WritePerfDataInt("TypeRef (bytes)", "TypeRef (bytes)", "bytes", "bytes", size);
sprintf_s(szString,SZSTRING_SIZE,"// %-14s- %4d (%d bytes)", "TypeRef", count, size); \
printLine(GUICookie,szStr);
}
@ -6264,12 +6147,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
{
metaSize += size = count * sizeRec;
WritePerfDataInt("MethodDef (count)", "MethodDef (count)", "count", "count", count);
WritePerfDataInt("MethodDef (bytes)", "MethodDef (bytes)", "bytes", "bytes", size);
WritePerfDataInt("abstract", "abstract", "count", "count", abstract);
WritePerfDataInt("native", "native", "count", "count", native);
WritePerfDataInt("methodBodies", "methodBodies", "count", "count", methodBodies);
sprintf_s(buf, MAX_MEMBER_LENGTH, " MethodDef - %4d (%d bytes)", count, size);
sprintf_s(szString,SZSTRING_SIZE,"// %-38s %d abstract, %d native, %d bodies", buf, abstract, native, methodBodies);
printLine(GUICookie,szStr);
@ -6293,10 +6170,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
pITables->GetTableInfo(TBL_Field, &sizeRec, NULL, NULL, NULL, NULL);
metaSize += size = count * sizeRec;
WritePerfDataInt("FieldDef (count)", "FieldDef (count)", "count", "count", count);
WritePerfDataInt("FieldDef (bytes)", "FieldDef (bytes)", "bytes", "bytes", size);
WritePerfDataInt("constant", "constant", "count", "count", constants);
sprintf_s(buf, MAX_MEMBER_LENGTH, " FieldDef - %4d (%d bytes)", count, size);
sprintf_s(szString,SZSTRING_SIZE,"// %-38s %d constant", buf, constants);
printLine(GUICookie,szStr);
@ -6343,7 +6216,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
if (sizeRec > 0)
{
metaSize += sizeRec;
WritePerfDataInt("Strings", "Strings", "bytes", "bytes",sizeRec);
sprintf_s(szString,SZSTRING_SIZE,"// Strings - %5d bytes", sizeRec);
printLine(GUICookie,szStr);
}
@ -6352,7 +6224,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
if (sizeRec > 0)
{
metaSize += sizeRec;
WritePerfDataInt("Blobs", "Blobs", "bytes", "bytes",sizeRec);
sprintf_s(szString,SZSTRING_SIZE,"// Blobs - %5d bytes", sizeRec);
printLine(GUICookie,szStr);
}
@ -6361,7 +6232,6 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
if (sizeRec > 0)
{
metaSize += sizeRec;
WritePerfDataInt("UserStrings", "UserStrings", "bytes", "bytes",sizeRec);
sprintf_s(szString,SZSTRING_SIZE,"// UserStrings - %5d bytes", sizeRec);
printLine(GUICookie,szStr);
}
@ -6370,92 +6240,74 @@ void DumpStatistics(IMAGE_COR20_HEADER *CORHeader, void* GUICookie)
if (sizeRec > 0)
{
metaSize += sizeRec;
WritePerfDataInt("Guids", "Guids", "bytes", "bytes", sizeRec);
sprintf_s(szString,SZSTRING_SIZE,"// Guids - %5d bytes", sizeRec);
printLine(GUICookie,szStr);
}
if (g_cbMetaData - metaSize > 0)
{
WritePerfDataInt("Uncategorized", "Uncategorized", "bytes", "bytes",g_cbMetaData - metaSize);
sprintf_s(szString,SZSTRING_SIZE,"// Uncategorized - %5d bytes", g_cbMetaData - metaSize);
printLine(GUICookie,szStr);
}
if (miscCOMPlusSize != 0)
{
WritePerfDataInt("CLR additional info", "CLR additional info", "bytes", "bytes", miscCOMPlusSize);
sprintf_s(szString,SZSTRING_SIZE,"// CLR additional info : %d", miscCOMPlusSize);
printLine(GUICookie,"");
printLine(GUICookie,szStr);
if (CORHeader->CodeManagerTable.Size != 0)
{
WritePerfDataInt("CodeManagerTable", "CodeManagerTable", "bytes", "bytes", VAL32(CORHeader->CodeManagerTable.Size));
sprintf_s(szString,SZSTRING_SIZE,"// CodeManagerTable - %d", VAL32(CORHeader->CodeManagerTable.Size));
printLine(GUICookie,szStr);
}
if (CORHeader->VTableFixups.Size != 0)
{
WritePerfDataInt("VTableFixups", "VTableFixups", "bytes", "bytes", VAL32(CORHeader->VTableFixups.Size));
sprintf_s(szString,SZSTRING_SIZE,"// VTableFixups - %d", VAL32(CORHeader->VTableFixups.Size));
printLine(GUICookie,szStr);
}
if (CORHeader->Resources.Size != 0)
{
WritePerfDataInt("Resources", "Resources", "bytes", "bytes", VAL32(CORHeader->Resources.Size));
sprintf_s(szString,SZSTRING_SIZE,"// Resources - %d", VAL32(CORHeader->Resources.Size));
printLine(GUICookie,szStr);
}
}
WritePerfDataInt("CLR method headers", "CLR method headers", "count", "count", methodHeaderSize);
sprintf_s(szString,SZSTRING_SIZE,"// CLR method headers : %d", methodHeaderSize);
printLine(GUICookie,"");
printLine(GUICookie,szStr);
WritePerfDataInt("Num.of method bodies", "Num.of method bodies", "count", "count",methodBodies);
sprintf_s(szString,SZSTRING_SIZE,"// Num.of method bodies - %d", methodBodies);
printLine(GUICookie,szStr);
WritePerfDataInt("Num.of fat headers", "Num.of fat headers", "count", "count", fatHeaders);
sprintf_s(szString,SZSTRING_SIZE,"// Num.of fat headers - %d", fatHeaders);
printLine(GUICookie,szStr);
WritePerfDataInt("Num.of tiny headers", "Num.of tiny headers", "count", "count", tinyHeaders);
sprintf_s(szString,SZSTRING_SIZE,"// Num.of tiny headers - %d", tinyHeaders);
printLine(GUICookie,szStr);
if (deprecatedHeaders > 0) {
WritePerfDataInt("Num.of old headers", "Num.of old headers", "count", "count", deprecatedHeaders);
sprintf_s(szString,SZSTRING_SIZE,"// Num.of old headers - %d", deprecatedHeaders);
printLine(GUICookie,szStr);
}
if (fatSections != 0 || smallSections != 0) {
WritePerfDataInt("Num.of fat sections", "Num.of fat sections", "count", "count", fatSections);
sprintf_s(szString,SZSTRING_SIZE,"// Num.of fat sections - %d", fatSections);
printLine(GUICookie,szStr);
WritePerfDataInt("Num.of small section", "Num.of small section", "count", "count", smallSections);
sprintf_s(szString,SZSTRING_SIZE,"// Num.of small sections - %d", smallSections);
printLine(GUICookie,szStr);
}
WritePerfDataInt("Managed code", "Managed code", "bytes", "bytes", methodBodySize);
sprintf_s(szString,SZSTRING_SIZE,"// Managed code : %d", methodBodySize);
printLine(GUICookie,"");
printLine(GUICookie,szStr);
if (methodBodies != 0) {
WritePerfDataInt("Ave method size", "Ave method size", "bytes", "bytes", methodBodySize / methodBodies);
sprintf_s(szString,SZSTRING_SIZE,"// Ave method size - %d", methodBodySize / methodBodies);
printLine(GUICookie,szStr);
}
if (pITables)
pITables->Release();
if(g_fDumpToPerfWriter)
CloseHandle((char*) g_PerfDataFilePtr);
}
void DumpHexbytes(__inout __nullterminated char* szptr,BYTE *pb, DWORD fromPtr, DWORD toPtr, DWORD limPtr)

View File

@ -38,8 +38,6 @@ extern BOOL g_fDumpSummary;
extern BOOL g_fDecompile; // still in progress
extern BOOL g_fShowRefs;
extern BOOL g_fDumpToPerfWriter;
extern BOOL g_fShowBytes;
extern BOOL g_fShowSource;
extern BOOL g_fInsertSourceLines;
@ -230,10 +228,6 @@ int ProcessOneArg(_In_ __nullterminated char* szArg, _Out_ char** ppszObjFileNam
{
g_fDumpSummary = TRUE;
}
else if (_stricmp(szOpt, "per") == 0)
{
g_fDumpToPerfWriter = TRUE;
}
else if (_stricmp(szOpt, "for") == 0)
{
g_fForwardDecl = TRUE;

View File

@ -17,6 +17,7 @@
#define __BLOB_FETCHER_H_
#include <windef.h>
#include <stdio.h>
class CBlobFetcher
@ -84,7 +85,7 @@ public:
unsigned ComputeOffset(_In_ char *ptr) const;
// Write out the section to the stream
HRESULT Write(HANDLE file);
HRESULT Write(FILE* file);
// Write out the section to memory
HRESULT WriteMem(void ** pMem);

View File

@ -1,49 +0,0 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#ifndef __FSTREAM_H_INCLUDED__
#define __FSTREAM_H_INCLUDED__
#include <objidl.h>
class CFileStream : public IStream
{
public:
CFileStream();
virtual ~CFileStream();
HRESULT OpenForRead(LPCWSTR wzFilePath);
HRESULT OpenForWrite(LPCWSTR wzFilePath);
// IUnknown methods:
STDMETHODIMP_(ULONG) AddRef();
STDMETHODIMP_(ULONG) Release();
STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObj);
// ISequentialStream methods:
STDMETHODIMP Read(void *pv, ULONG cb, ULONG *pcbRead);
STDMETHODIMP Write(void const *pv, ULONG cb, ULONG *pcbWritten);
// IStream methods:
STDMETHODIMP Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition);
STDMETHODIMP SetSize(ULARGE_INTEGER libNewSize);
STDMETHODIMP CopyTo(IStream *pstm, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten);
STDMETHODIMP Commit(DWORD grfCommitFlags);
STDMETHODIMP Revert();
STDMETHODIMP LockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
STDMETHODIMP UnlockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
STDMETHODIMP Stat(STATSTG *pstatstg, DWORD grfStatFlag);
STDMETHODIMP Clone(IStream **ppIStream);
private:
BOOL Close();
private:
LONG _cRef;
HANDLE _hFile;
};
#endif

View File

@ -25,6 +25,8 @@ CreateFileWrapper(
_In_opt_ HANDLE hTemplateFile
);
int fopen_u16_wrapper(FILE** stream, const WCHAR* filename, const WCHAR* mode);
BOOL
CopyFileExWrapper(
_In_ LPCWSTR lpExistingFileName,

View File

@ -42,9 +42,11 @@
#ifdef HOST_WINDOWS
#define WszLoadLibrary LoadLibraryExWrapper
#define WszCreateFile CreateFileWrapper
#define fopen_lp fopen_u16_wrapper
#else // HOST_WINDOWS
#define WszLoadLibrary LoadLibraryExW
#define WszCreateFile CreateFileW
#define fopen_lp fopen_u16
#endif // HOST_WINDOWS
//APIS which have a buffer as an out parameter

View File

@ -1,6 +1,7 @@
set(SOURCES
doublemapping.cpp
dn-u16.cpp
dn-stdio.cpp
)
add_library(coreclrminipal_objects

View File

@ -0,0 +1,149 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#include <stdint.h>
typedef char16_t WCHAR;
typedef uint32_t HRESULT;
#include <stdio.h>
#include <errno.h>
#include <dn-stdio.h>
#include <dn-u16.h>
#include <minipal/utf8.h>
int fopen_u16(FILE** stream, const WCHAR* path, const WCHAR* mode)
{
size_t pathLen = u16_strlen(path);
size_t pathU8Len = minipal_get_length_utf16_to_utf8((CHAR16_T*)path, pathLen, 0);
char* pathU8 = new char[pathU8Len + 1];
size_t ret = minipal_convert_utf16_to_utf8((CHAR16_T*)path, pathLen, pathU8, pathU8Len, 0);
pathU8[ret] = '\0';
size_t modeLen = u16_strlen(mode);
size_t modeU8Len = minipal_get_length_utf16_to_utf8((CHAR16_T*)mode, modeLen, 0);
char* modeU8 = new char[modeU8Len + 1];
ret = minipal_convert_utf16_to_utf8((CHAR16_T*)mode, modeLen, modeU8, modeU8Len, 0);
modeU8[ret] = '\0';
FILE* result = fopen(pathU8, modeU8);
int err = errno;
delete[] pathU8;
delete[] modeU8;
if (result)
{
*stream = result;
return 0;
}
else
{
*stream = NULL;
return err;
}
}
int64_t fgetsize(FILE* stream)
{
fpos_t current;
fgetpos(stream, &current);
fseek(stream, 0, SEEK_END);
int64_t length = ftell(stream);
fsetpos(stream, &current);
return length;
}
int64_t ftell_64(FILE* stream)
{
return ftell(stream);
}
int fsetpos_64(FILE* stream, int64_t pos)
{
return fseek(stream, pos, SEEK_SET);
}
#define FACILITY_WIN32 7
#define HRESULT_FROM_WIN32(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (FACILITY_WIN32 << 16) | 0x80000000)))
#define ERROR_SUCCESS 0L
#define ERROR_FILE_NOT_FOUND 2L
#define ERROR_PATH_NOT_FOUND 3L
#define ERROR_TOO_MANY_OPEN_FILES 4L
#define ERROR_ACCESS_DENIED 5L
#define ERROR_INVALID_HANDLE 6L
#define ERROR_NOT_ENOUGH_MEMORY 8L
#define ERROR_WRITE_FAULT 29L
#define ERROR_GEN_FAILURE 31L
#define ERROR_DISK_FULL 112L
#define ERROR_DIR_NOT_EMPTY 145L
#define ERROR_BAD_PATHNAME 161L
#define ERROR_BUSY 170L
#define ERROR_ALREADY_EXISTS 183L
#define ERROR_FILENAME_EXCED_RANGE 206L
HRESULT HRESULT_FROM_LAST_STDIO()
{
// maps the common I/O errors
// based on FILEGetLastErrorFromErrno
uint32_t win32Err;
switch(errno)
{
case 0:
win32Err = ERROR_SUCCESS;
break;
case ENAMETOOLONG:
win32Err = ERROR_FILENAME_EXCED_RANGE;
break;
case ENOTDIR:
win32Err = ERROR_PATH_NOT_FOUND;
break;
case ENOENT:
win32Err = ERROR_FILE_NOT_FOUND;
break;
case EACCES:
case EPERM:
case EROFS:
case EISDIR:
win32Err = ERROR_ACCESS_DENIED;
break;
case EEXIST:
win32Err = ERROR_ALREADY_EXISTS;
break;
case ENOTEMPTY:
win32Err = ERROR_DIR_NOT_EMPTY;
break;
case EBADF:
win32Err = ERROR_INVALID_HANDLE;
break;
case ENOMEM:
win32Err = ERROR_NOT_ENOUGH_MEMORY;
break;
case EBUSY:
win32Err = ERROR_BUSY;
break;
case ENOSPC:
case EDQUOT:
win32Err = ERROR_DISK_FULL;
break;
case ELOOP:
win32Err = ERROR_BAD_PATHNAME;
break;
case EIO:
win32Err = ERROR_WRITE_FAULT;
break;
case EMFILE:
win32Err = ERROR_TOO_MANY_OPEN_FILES;
break;
case ERANGE:
win32Err = ERROR_BAD_PATHNAME;
break;
default:
win32Err = ERROR_GEN_FAILURE;
}
return HRESULT_FROM_WIN32(win32Err);
}

View File

@ -1,6 +1,7 @@
set(SOURCES
doublemapping.cpp
dn-u16.cpp
dn-stdio.cpp
)
add_library(coreclrminipal
STATIC

View File

@ -0,0 +1,38 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#include <Windows.h>
#include <dn-stdio.h>
int fopen_u16(FILE** stream, const WCHAR* path, const WCHAR* mode)
{
return _wfopen_s(stream, path, mode);
}
int64_t fgetsize(FILE* stream)
{
fpos_t current;
fgetpos(stream, &current);
fseek(stream, 0, SEEK_END);
int64_t length = _ftelli64(stream);
fsetpos(stream, &current);
return length;
}
int64_t ftell_64(FILE* stream)
{
fpos_t pos;
fgetpos(stream, &pos);
return pos;
}
int fsetpos_64(FILE* stream, int64_t pos)
{
fpos_t fpos = pos;
return fsetpos(stream, &fpos);
}
HRESULT HRESULT_FROM_LAST_STDIO()
{
return HRESULT_FROM_WIN32(::GetLastError());
}

View File

@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#include <stdio.h>
#include <stdint.h>
//
// Wrappers for stdio with UTF-16 path.
//
int fopen_u16(FILE** stream, const WCHAR* path, const WCHAR* mode);
int64_t fgetsize(FILE* stream);
int64_t ftell_64(FILE* stream);
int fsetpos_64(FILE* stream, int64_t pos);
HRESULT HRESULT_FROM_LAST_STDIO();

View File

@ -14,7 +14,6 @@ set(UTILCODE_COMMON_SOURCES
configuration.cpp
collections.cpp
posterror.cpp
fstream.cpp
clrhelpers.cpp
stgpool.cpp
stgpooli.cpp

View File

@ -1,253 +0,0 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#include "stdafx.h" // Precompiled header key.
#include "fstream.h"
CFileStream::CFileStream()
: _cRef(1)
, _hFile(INVALID_HANDLE_VALUE)
{
}
CFileStream::~CFileStream()
{
Close();
}
HRESULT CFileStream::OpenForRead(LPCWSTR wzFilePath)
{
HRESULT hr = S_OK;
DWORD dwShareMode = FILE_SHARE_READ;
dwShareMode |= FILE_SHARE_DELETE;
_ASSERTE(_hFile == INVALID_HANDLE_VALUE && wzFilePath);
if (_hFile != INVALID_HANDLE_VALUE || !wzFilePath) {
hr = E_INVALIDARG;
goto Exit;
}
_hFile = WszCreateFile(wzFilePath, GENERIC_READ,
dwShareMode, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (_hFile == INVALID_HANDLE_VALUE) {
hr = HRESULT_FROM_WIN32(GetLastError());
goto Exit;
}
Exit:
return hr;
}
HRESULT CFileStream::OpenForWrite(LPCWSTR wzFilePath)
{
HRESULT hr = S_OK;
_ASSERTE(_hFile == INVALID_HANDLE_VALUE && wzFilePath);
if (_hFile != INVALID_HANDLE_VALUE || !wzFilePath) {
hr = E_INVALIDARG;
goto Exit;
}
_hFile = WszCreateFile(wzFilePath, GENERIC_WRITE,
FILE_SHARE_READ, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (_hFile == INVALID_HANDLE_VALUE)
{
hr = HRESULT_FROM_WIN32(GetLastError());
goto Exit;
}
Exit:
return hr;
}
HRESULT CFileStream::QueryInterface(REFIID riid, void **ppv)
{
HRESULT hr = S_OK;
if (!ppv)
return E_POINTER;
*ppv = NULL;
if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IStream)) {
*ppv = static_cast<IStream *>(this);
}
else {
hr = E_NOINTERFACE;
}
if (*ppv) {
AddRef();
}
return hr;
}
STDMETHODIMP_(ULONG) CFileStream::AddRef()
{
return InterlockedIncrement(&_cRef);
}
STDMETHODIMP_(ULONG) CFileStream::Release()
{
ULONG ulRef = InterlockedDecrement(&_cRef);
if (!ulRef) {
delete this;
}
return ulRef;
}
HRESULT CFileStream::Read(void *pv, ULONG cb, ULONG *pcbRead)
{
HRESULT hr = S_OK;
ULONG cbRead = 0;
if (pcbRead != NULL) {
*pcbRead = 0;
}
_ASSERTE(_hFile != INVALID_HANDLE_VALUE);
if (_hFile == INVALID_HANDLE_VALUE) {
hr = E_UNEXPECTED;
goto Exit;
}
if (!::ReadFile(_hFile, pv, cb, &cbRead, NULL)) {
hr = HRESULT_FROM_WIN32(::GetLastError());
goto Exit;
}
if (cbRead == 0) {
hr = S_FALSE;
}
else {
hr = NOERROR;
}
if (pcbRead != NULL) {
*pcbRead = cbRead;
}
Exit:
return hr;
}
HRESULT CFileStream::Write(void const *pv, ULONG cb, ULONG *pcbWritten)
{
HRESULT hr = S_OK;
ULONG cbWritten = 0;
if (pcbWritten != NULL) {
*pcbWritten = 0;
}
_ASSERTE(_hFile != INVALID_HANDLE_VALUE);
if (_hFile == INVALID_HANDLE_VALUE) {
hr = E_UNEXPECTED;
goto Exit;
}
if (!::WriteFile(_hFile, pv, cb, &cbWritten, NULL)) {
hr = HRESULT_FROM_WIN32(::GetLastError());
goto Exit;
}
if (cbWritten == 0) {
hr = S_FALSE;
}
else {
hr = S_OK;
}
if (pcbWritten != NULL) {
*pcbWritten = cbWritten;
}
Exit:
return hr;
}
HRESULT CFileStream::Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
{
return E_NOTIMPL;
}
HRESULT CFileStream::SetSize(ULARGE_INTEGER libNewSize)
{
return E_NOTIMPL;
}
HRESULT CFileStream::CopyTo(IStream *pstm, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
{
return E_NOTIMPL;
}
HRESULT CFileStream::Commit(DWORD grfCommitFlags)
{
HRESULT hr = S_OK;
if (grfCommitFlags != 0) {
hr = E_INVALIDARG;
goto Exit;
}
if (!Close()) {
hr = HRESULT_FROM_WIN32(GetLastError());
}
Exit:
return hr;
}
HRESULT CFileStream::Revert()
{
return E_NOTIMPL;
}
HRESULT CFileStream::LockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
{
return E_NOTIMPL;
}
HRESULT CFileStream::UnlockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
{
return E_NOTIMPL;
}
HRESULT CFileStream::Stat(STATSTG *pstatstg, DWORD grfStatFlag)
{
return E_NOTIMPL;
}
HRESULT CFileStream::Clone(IStream **ppIStream)
{
return E_NOTIMPL;
}
BOOL CFileStream::Close()
{
BOOL fSuccess = FALSE;
if (_hFile != INVALID_HANDLE_VALUE) {
if (!::CloseHandle(_hFile)) {
_hFile = INVALID_HANDLE_VALUE;
goto Exit;
}
_hFile = INVALID_HANDLE_VALUE;
}
fSuccess = TRUE;
Exit:
return fSuccess;
}

View File

@ -17,6 +17,7 @@
#include "log.h"
#include "utilcode.h"
#include <dn-stdio.h>
#ifdef LOGGING
@ -32,7 +33,7 @@
static DWORD LogFlags = 0;
static CQuickWSTR szLogFileName;
static HANDLE LogFileHandle = INVALID_HANDLE_VALUE;
static FILE* LogFileHandle = NULL;
static minipal_mutex* volatile LogFileMutex = nullptr;
static DWORD LogFacilityMask = LF_ALL;
static DWORD LogFacilityMask2 = 0;
@ -85,20 +86,13 @@ VOID InitLogging()
if ((LogFlags & LOG_ENABLE) &&
(LogFlags & LOG_ENABLE_FILE_LOGGING) &&
(szLogFileName.Size() > 0) &&
(LogFileHandle == INVALID_HANDLE_VALUE))
(LogFileHandle == NULL))
{
DWORD fdwCreate = (LogFlags & LOG_ENABLE_APPEND_FILE) ? OPEN_ALWAYS : CREATE_ALWAYS;
LogFileHandle = WszCreateFile(
szLogFileName.Ptr(),
GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
fdwCreate,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | ((LogFlags & LOG_ENABLE_FLUSH_FILE) ? FILE_FLAG_WRITE_THROUGH : 0),
NULL);
const WCHAR* mode = (LogFlags & LOG_ENABLE_APPEND_FILE) ? W("ab+") : W("wb+");
int err = fopen_lp(&LogFileHandle, szLogFileName.Ptr(), mode);
// Some other logging may be going on, try again with another file name
if (LogFileHandle == INVALID_HANDLE_VALUE && u16_strlen(szLogFileName.Ptr()) + 3 <= szLogFileName.Size())
if ((err != 0) && u16_strlen(szLogFileName.Ptr()) + 3 <= szLogFileName.Size())
{
WCHAR* ptr = szLogFileName.Ptr() + u16_strlen(szLogFileName.Ptr()) + 1;
ptr[-1] = W('.');
@ -107,41 +101,19 @@ VOID InitLogging()
for(int i = 0; i < 10; i++)
{
LogFileHandle = WszCreateFile(
szLogFileName.Ptr(),
GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
fdwCreate,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | ((LogFlags & LOG_ENABLE_FLUSH_FILE) ? FILE_FLAG_WRITE_THROUGH : 0),
NULL);
if (LogFileHandle != INVALID_HANDLE_VALUE)
err = fopen_lp(&LogFileHandle, szLogFileName.Ptr(), mode);
if (err == 0)
break;
*ptr = *ptr + 1;
}
if (LogFileHandle == INVALID_HANDLE_VALUE) {
int ret = WideCharToMultiByte(CP_ACP, 0, szLogFileName.Ptr(), -1, NULL, 0, NULL, NULL);
const char *msg = "Could not open log file, logging to ";
DWORD msgLen = (DWORD)strlen(msg);
CQuickSTR buff;
if (SUCCEEDED(buff.ReSizeNoThrow(ret + msgLen)))
{
strcpy_s(buff.Ptr(), buff.Size(), msg);
WideCharToMultiByte(CP_ACP, 0, szLogFileName.Ptr(), -1, buff.Ptr() + msgLen, ret, NULL, NULL);
msg = buff.Ptr();
}
else
{
msg = "Could not open log file";
}
DWORD written;
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msg, (DWORD)strlen(msg), &written, 0);
if (err != 0) {
MAKE_UTF8PTR_FROMWIDE_NOTHROW(u8LogFileName, szLogFileName.Ptr());
printf("Could not open log file, logging to %s\n", u8LogFileName);
}
}
if (LogFileHandle != INVALID_HANDLE_VALUE)
if (LogFileHandle != NULL)
{
if (LogFlags & LOG_ENABLE_APPEND_FILE)
SetFilePointer(LogFileHandle, 0, NULL, FILE_END);
LogSpew( LF_ALWAYS, FATALERROR, "************************ New Output *****************\n" );
}
}
@ -203,12 +175,12 @@ VOID InitializeLogging()
VOID FlushLogging() {
STATIC_CONTRACT_NOTHROW;
if (LogFileHandle != INVALID_HANDLE_VALUE)
if (LogFileHandle != NULL)
{
// We must take the lock, as an OS deadlock can occur between
// FlushFileBuffers and WriteFile.
// fflush and fwrite.
EnterLogLock();
FlushFileBuffers( LogFileHandle );
fflush( LogFileHandle );
LeaveLogLock();
}
}
@ -217,11 +189,11 @@ VOID ShutdownLogging()
{
STATIC_CONTRACT_NOTHROW;
if (LogFileHandle != INVALID_HANDLE_VALUE) {
if (LogFileHandle != NULL) {
LogSpew( LF_ALWAYS, FATALERROR, "Logging shutting down\n");
CloseHandle( LogFileHandle );
fclose( LogFileHandle );
}
LogFileHandle = INVALID_HANDLE_VALUE;
LogFileHandle = NULL;
bLoggingInitialized = false;
}
@ -314,7 +286,6 @@ VOID LogSpewAlwaysValist(const char *fmt, va_list args)
char * pBuffer = &rgchBuffer[0];
DWORD buflen = 0;
DWORD written;
static bool needsPrefix = true;
@ -358,11 +329,11 @@ VOID LogSpewAlwaysValist(const char *fmt, va_list args)
pBuffer = pBuffer2;
#endif // TARGET_UNIX
if (LogFlags & LOG_ENABLE_FILE_LOGGING && LogFileHandle != INVALID_HANDLE_VALUE)
if (LogFlags & LOG_ENABLE_FILE_LOGGING && LogFileHandle != NULL)
{
WriteFile(LogFileHandle, pBuffer, buflen, &written, NULL);
fwrite(pBuffer, 1, buflen, LogFileHandle);
if (LogFlags & LOG_ENABLE_FLUSH_FILE) {
FlushFileBuffers( LogFileHandle );
fflush(LogFileHandle);
}
}

View File

@ -6,6 +6,7 @@
#include "longfilepathwrappers.h"
#include "sstring.h"
#include "ex.h"
#include <dn-stdio.h>
#ifdef HOST_WINDOWS
class LongFile
@ -342,6 +343,18 @@ CreateFileWrapper(
return ret;
}
int fopen_u16_wrapper(FILE** stream, const WCHAR* filename, const WCHAR* mode)
{
LongPathString path(LongPathString::Literal, filename);
if (SUCCEEDED(LongFile::NormalizePath(path)))
{
return fopen_u16(stream, path.GetUnicode(), mode);
}
return -1;
}
BOOL
CopyFileExWrapper(
_In_ LPCWSTR lpExistingFileName,

View File

@ -13,10 +13,18 @@
#include <eventpipe/ep-provider.h>
#include <eventpipe/ep-session-provider.h>
#include <eventpipe/ep-string.h>
#include "fstream.h"
#include "typestring.h"
#include "clrversion.h"
#include "hostinformation.h"
#ifdef HOST_WINDOWS
#include <windows.h>
#else
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
#include <minipal/guid.h>
#include <minipal/strings.h>
#include <minipal/time.h>
@ -1074,17 +1082,25 @@ ep_rt_file_open_write (const ep_char8_t *path)
{
STATIC_CONTRACT_NOTHROW;
ep_char16_t *path_utf16 = ep_rt_utf8_to_utf16le_string (path);
ep_return_null_if_nok (path_utf16 != NULL);
if (!path)
return INVALID_HANDLE_VALUE;
CFileStream *file_stream = new (nothrow) CFileStream ();
if (file_stream && FAILED (file_stream->OpenForWrite (reinterpret_cast<LPWSTR>(path_utf16)))) {
delete file_stream;
file_stream = NULL;
}
#ifdef TARGET_WINDOWS
ep_char16_t *path_utf16 = ep_rt_utf8_to_utf16le_string (path);
if (!path_utf16)
return INVALID_HANDLE_VALUE;
ep_rt_utf16_string_free (path_utf16);
return static_cast<ep_rt_file_handle_t>(file_stream);
HANDLE res = ::CreateFileW (reinterpret_cast<LPCWSTR>(path_utf16), GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
ep_rt_utf16_string_free (path_utf16);
return static_cast<ep_rt_file_handle_t>(res);
#else
mode_t perms = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
int fd = creat (path, perms);
if (fd == -1)
return INVALID_HANDLE_VALUE;
return (ep_rt_file_handle_t)(ptrdiff_t)fd;
#endif
}
static
@ -1094,10 +1110,13 @@ ep_rt_file_close (ep_rt_file_handle_t file_handle)
{
STATIC_CONTRACT_NOTHROW;
// Closed in destructor.
if (file_handle)
delete file_handle;
return true;
#ifdef TARGET_WINDOWS
return ::CloseHandle (file_handle) != FALSE;
#else
int fd = (int)(ptrdiff_t)file_handle;
close (fd);
return true;
#endif
}
static
@ -1114,10 +1133,28 @@ ep_rt_file_write (
ep_return_false_if_nok (file_handle != NULL);
ULONG out_count;
HRESULT result = reinterpret_cast<CFileStream *>(file_handle)->Write (buffer, bytes_to_write, &out_count);
*bytes_written = static_cast<uint32_t>(out_count);
return result == S_OK;
#ifdef TARGET_WINDOWS
return ::WriteFile (file_handle, buffer, bytes_to_write, reinterpret_cast<LPDWORD>(bytes_written), NULL) != FALSE;
#else
int fd = (int)(ptrdiff_t)file_handle;
int ret;
do {
ret = write (fd, buffer, bytes_to_write);
} while (ret == -1 && errno == EINTR);
if (ret == -1) {
if (bytes_written != NULL) {
*bytes_written = 0;
}
return false;
}
if (bytes_written != NULL)
*bytes_written = ret;
return true;
#endif
}
static

View File

@ -56,7 +56,7 @@ typedef class MethodDesc ep_rt_method_desc_t;
*/
#undef ep_rt_file_handle_t
typedef class CFileStream * ep_rt_file_handle_t;
typedef void * ep_rt_file_handle_t;
#undef ep_rt_wait_event_handle_t
typedef struct _rt_coreclr_event_internal_t ep_rt_wait_event_handle_t;

View File

@ -18,7 +18,6 @@
#include "stubgen.h"
#include "eventtrace.h"
#include "array.h"
#include "fstream.h"
#include "hash.h"
#include "minipal/time.h"
@ -28,6 +27,7 @@
#include "eventtracebase.h"
#include "multicorejit.h"
#include "multicorejitimpl.h"
#include <dn-stdio.h>
void MulticoreJitFireEtw(const WCHAR * pAction, const WCHAR * pTarget, int p1, int p2, int p3)
{
@ -154,11 +154,12 @@ HRESULT MulticoreJitRecorder::WriteOutput()
EX_TRY
{
CFileStream fileStream;
FILE* fp;
if (SUCCEEDED(hr = fileStream.OpenForWrite(m_fullFileName.GetUnicode())))
if (fopen_lp(&fp, m_fullFileName.GetUnicode(), W("wb")) == 0)
{
hr = WriteOutput(& fileStream);
hr = WriteOutput(fp);
fclose(fp);
}
}
EX_CATCH
@ -169,7 +170,7 @@ HRESULT MulticoreJitRecorder::WriteOutput()
}
HRESULT WriteData(IStream * pStream, const void * pData, unsigned len)
HRESULT WriteData(FILE * fp, const void * pData, unsigned len)
{
CONTRACTL
{
@ -179,20 +180,20 @@ HRESULT WriteData(IStream * pStream, const void * pData, unsigned len)
}
CONTRACTL_END
ULONG cbWritten;
size_t cbWritten = fwrite(pData, 1, len, fp);
HRESULT hr = pStream->Write(pData, len, & cbWritten);
HRESULT hr = S_OK;
if (SUCCEEDED(hr) && (cbWritten != len))
if (cbWritten != len)
{
hr = E_FAIL;
hr = HRESULT_FROM_LAST_STDIO();
}
return hr;
}
// Write string, round to DWORD alignment
HRESULT WriteString(const void * pString, unsigned len, IStream * pStream)
HRESULT WriteString(const void * pString, unsigned len, FILE * fp)
{
CONTRACTL
{
@ -202,25 +203,23 @@ HRESULT WriteString(const void * pString, unsigned len, IStream * pStream)
}
CONTRACTL_END;
ULONG cbWritten = 0;
size_t cbWritten = fwrite(pString, 1, len, fp);
HRESULT hr;
hr = pStream->Write(pString, len, & cbWritten);
if (SUCCEEDED(hr))
if (cbWritten == (size_t)len)
{
len = RoundUp(len) - len;
if (len != 0)
{
cbWritten = 0;
uint32_t temp = 0;
cbWritten = fwrite(&temp, 1, len, fp);
hr = pStream->Write(& cbWritten, len, & cbWritten);
if (cbWritten == (size_t)len)
return S_OK;
}
}
return hr;
return HRESULT_FROM_LAST_STDIO();
}
@ -329,7 +328,7 @@ bool RecorderModuleInfo::SetModule(Module * pMod)
//
/////////////////////////////////////////////////////
HRESULT MulticoreJitRecorder::WriteModuleRecord(IStream * pStream, const RecorderModuleInfo & module)
HRESULT MulticoreJitRecorder::WriteModuleRecord(FILE * fp, const RecorderModuleInfo & module)
{
CONTRACTL
{
@ -355,15 +354,15 @@ HRESULT MulticoreJitRecorder::WriteModuleRecord(IStream * pStream, const Recorde
mod.wLoadLevel = (unsigned short) module.loadLevel;
mod.flags = module.flags;
hr = WriteData(pStream, & mod, sizeof(mod));
hr = WriteData(fp, & mod, sizeof(mod));
if (SUCCEEDED(hr))
{
hr = WriteString(pModuleName, lenModuleName, pStream);
hr = WriteString(pModuleName, lenModuleName, fp);
if (SUCCEEDED(hr))
{
hr = WriteString(pAssemblyName, lenAssemblyName, pStream);
hr = WriteString(pAssemblyName, lenAssemblyName, fp);
}
}
@ -371,7 +370,7 @@ HRESULT MulticoreJitRecorder::WriteModuleRecord(IStream * pStream, const Recorde
}
HRESULT MulticoreJitRecorder::WriteOutput(IStream * pStream)
HRESULT MulticoreJitRecorder::WriteOutput(FILE * fp)
{
CONTRACTL
{
@ -486,14 +485,14 @@ HRESULT MulticoreJitRecorder::WriteOutput(IStream * pStream)
_ASSERTE((sizeof(header) % sizeof(unsigned)) == 0);
hr = WriteData(pStream, & header, sizeof(header));
hr = WriteData(fp, & header, sizeof(header));
}
DWORD dwData = 0;
for (unsigned i = 0; SUCCEEDED(hr) && (i < m_ModuleCount); i ++)
{
hr = WriteModuleRecord(pStream, m_ModuleList[i]);
hr = WriteModuleRecord(fp, m_ModuleList[i]);
}
for (LONG i = 0 ; i < m_JitInfoCount && SUCCEEDED(hr); i++)
@ -504,7 +503,7 @@ HRESULT MulticoreJitRecorder::WriteOutput(IStream * pStream)
_ASSERTE(m_JitInfoArray[i].IsFullyInitialized());
DWORD data1 = m_JitInfoArray[i].GetRawModuleData();
hr = WriteData(pStream, &data1, sizeof(data1));
hr = WriteData(fp, &data1, sizeof(data1));
}
else if (m_JitInfoArray[i].IsGenericMethodInfo())
{
@ -522,19 +521,19 @@ HRESULT MulticoreJitRecorder::WriteOutput(IStream * pStream)
DWORD sigSize = m_JitInfoArray[i].GetMethodSignatureSize();
DWORD paddingSize = m_JitInfoArray[i].GetMethodRecordPaddingSize();
hr = WriteData(pStream, &data1, sizeof(data1));
hr = WriteData(fp, &data1, sizeof(data1));
if (SUCCEEDED(hr))
{
hr = WriteData(pStream, &data2, sizeof(data2));
hr = WriteData(fp, &data2, sizeof(data2));
}
if (SUCCEEDED(hr))
{
hr = WriteData(pStream, pSignature, sigSize);
hr = WriteData(fp, pSignature, sigSize);
}
if (SUCCEEDED(hr) && paddingSize > 0)
{
DWORD tmp = 0;
hr = WriteData(pStream, &tmp, paddingSize);
hr = WriteData(fp, &tmp, paddingSize);
}
}
else
@ -545,10 +544,10 @@ HRESULT MulticoreJitRecorder::WriteOutput(IStream * pStream)
DWORD data1 = m_JitInfoArray[i].GetRawMethodData1();
unsigned data2 = m_JitInfoArray[i].GetRawMethodData2NonGeneric();
hr = WriteData(pStream, &data1, sizeof(data1));
hr = WriteData(fp, &data1, sizeof(data1));
if (SUCCEEDED(hr))
{
hr = WriteData(pStream, &data2, sizeof(data2));
hr = WriteData(fp, &data2, sizeof(data2));
}
}
}

View File

@ -626,13 +626,13 @@ private:
unsigned FindModule(Module * pModule);
unsigned GetOrAddModuleIndex(Module * pModule);
HRESULT WriteModuleRecord(IStream * pStream, const RecorderModuleInfo & module);
HRESULT WriteModuleRecord(FILE * fp, const RecorderModuleInfo & module);
void RecordMethodInfo(unsigned moduleIndex, MethodDesc * pMethod, bool application);
unsigned RecordModuleInfo(Module * pModule);
void RecordOrUpdateModuleInfo(FileLoadLevel needLevel, unsigned moduleIndex);
HRESULT WriteOutput(IStream * pStream);
HRESULT WriteOutput(FILE * fp);
HRESULT WriteOutput();

View File

@ -18,10 +18,10 @@
#include "stubgen.h"
#include "eventtrace.h"
#include "array.h"
#include "fstream.h"
#include "hash.h"
#include "clrex.h"
#include "minipal/time.h"
#include <dn-stdio.h>
#include "appdomain.hpp"
@ -1029,22 +1029,17 @@ HRESULT MulticoreJitProfilePlayer::ReadCheckFile(const WCHAR * pFileName)
HRESULT hr = S_OK;
{
HANDLE hFile = WszCreateFile(pFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
FILE* fp;
if (fopen_lp(&fp, pFileName, W("rb")) != 0)
{
return COR_E_FILENOTFOUND;
}
HeaderRecord header;
DWORD cbRead = 0;
size_t cbRead = fread(&header, sizeof(header), 1, fp);
if (! ::ReadFile(hFile, & header, sizeof(header), &cbRead, NULL))
{
hr = COR_E_BADIMAGEFORMAT;
}
else if (cbRead != sizeof(header))
if (cbRead != sizeof(header))
{
hr = COR_E_BADIMAGEFORMAT;
}
@ -1072,7 +1067,7 @@ HRESULT MulticoreJitProfilePlayer::ReadCheckFile(const WCHAR * pFileName)
if (SUCCEEDED(hr))
{
m_nFileSize = SafeGetFileSize(hFile, 0);
m_nFileSize = (unsigned int)fgetsize(fp);
if (m_nFileSize > sizeof(header))
{
@ -1084,7 +1079,7 @@ HRESULT MulticoreJitProfilePlayer::ReadCheckFile(const WCHAR * pFileName)
{
hr = E_OUTOFMEMORY;
}
else if (::ReadFile(hFile, m_pFileBuffer, m_nFileSize, & cbRead, NULL))
else if ((cbRead = fread(m_pFileBuffer, 1, m_nFileSize, fp)) > 0)
{
if (cbRead != m_nFileSize)
{
@ -1102,7 +1097,7 @@ HRESULT MulticoreJitProfilePlayer::ReadCheckFile(const WCHAR * pFileName)
}
}
CloseHandle(hFile);
fclose(fp);
_FireEtwMulticoreJit(W("PLAYER"), W("Header"), hr, m_headerModuleCount, header.methodCount);
}

View File

@ -10,6 +10,7 @@
#include <clrconfignocache.h>
#include "perfmap.h"
#include "pal.h"
#include <dn-stdio.h>
// The code addresses are actually native image offsets during crossgen. Print
@ -221,8 +222,8 @@ PerfMap::~PerfMap()
{
LIMITED_METHOD_CONTRACT;
delete m_FileStream;
m_FileStream = nullptr;
fclose(m_fp);
m_fp = nullptr;
}
void PerfMap::OpenFileForPid(int pid, const char* basePath)
@ -240,17 +241,8 @@ void PerfMap::OpenFile(SString& path)
STANDARD_VM_CONTRACT;
// Open the file stream.
m_FileStream = new (nothrow) CFileStream();
if(m_FileStream != nullptr)
{
HRESULT hr = m_FileStream->OpenForWrite(path.GetUnicode());
if(FAILED(hr))
{
delete m_FileStream;
m_FileStream = nullptr;
fopen_lp(&m_fp, path.GetUnicode(), W("w"));
}
}
}
// Write a line to the map file.
void PerfMap::WriteLine(SString& line)
@ -260,7 +252,7 @@ void PerfMap::WriteLine(SString& line)
_ASSERTE(s_csPerfMap.OwnedByCurrentThread());
#endif
if (m_FileStream == nullptr || m_ErrorEncountered)
if (m_fp == nullptr || m_ErrorEncountered)
{
return;
}
@ -268,13 +260,8 @@ void PerfMap::WriteLine(SString& line)
EX_TRY
{
// Write the line.
// The PAL already takes a lock when writing, so we don't need to do so here.
const char * strLine = line.GetUTF8();
ULONG inCount = line.GetCount();
ULONG outCount;
m_FileStream->Write(strLine, inCount, &outCount);
if (inCount != outCount)
if (fprintf(m_fp, "%s", line.GetUTF8()) != 0)
{
// This will cause us to stop writing to the file.
// The file will still remain open until shutdown so that we don't have to take a lock at this level when we touch the file stream.

View File

@ -7,8 +7,8 @@
#define PERFPID_H
#include "sstring.h"
#include "fstream.h"
#include "volatile.h"
#include <stdio.h>
// Generates a perfmap file.
@ -40,7 +40,7 @@ private:
static CrstStatic s_csPerfMap;
// The file stream to write the map to.
CFileStream * m_FileStream;
FILE * m_fp;
// Set to true if an error is encountered when writing to the file.
bool m_ErrorEncountered;

View File

@ -8,6 +8,7 @@
#include "CachedInterfaceDispatchPal.h"
#include "CachedInterfaceDispatch.h"
#include "comdelegate.h"
#include <dn-stdio.h>
#ifdef FEATURE_PERFMAP
#include "perfmap.h"
@ -148,7 +149,7 @@ UINT32 g_dumpLogIncr;
#endif // STUB_LOGGING
//@TODO: use the existing logging mechanisms. for now we write to a file.
HANDLE g_hStubLogFile;
FILE* g_hStubLogFile;
void VirtualCallStubManager::StartupLogging()
{
@ -167,22 +168,12 @@ void VirtualCallStubManager::StartupLogging()
FAULT_NOT_FATAL(); // We handle filecreation problems locally
SString str;
str.Printf("StubLog_%d.log", GetCurrentProcessId());
g_hStubLogFile = WszCreateFile (str.GetUnicode(),
GENERIC_WRITE,
0,
0,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
0);
fopen_lp(&g_hStubLogFile, str.GetUnicode(), W("wb"));
}
EX_CATCH
{
}
EX_END_CATCH
if (g_hStubLogFile == INVALID_HANDLE_VALUE) {
g_hStubLogFile = NULL;
}
}
#define OUTPUT_FORMAT_INT "\t%-30s %d\r\n"
@ -212,226 +203,155 @@ void VirtualCallStubManager::LoggingDump()
g_resolveCache->LogStats();
#endif // FEATURE_VIRTUAL_STUB_DISPATCH
// Temp space to use for formatting the output.
static const int FMT_STR_SIZE = 160;
char szPrintStr[FMT_STR_SIZE];
DWORD dwWriteByte;
if(g_hStubLogFile)
{
#ifdef STUB_LOGGING
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\nstub tuning parameters\r\n");
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, "\r\nstub tuning parameters\r\n");
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\t%-30s %3d (0x%02x)\r\n", "STUB_MISS_COUNT_VALUE",
fprintf(g_hStubLogFile, "\t%-30s %3d (0x%02x)\r\n", "STUB_MISS_COUNT_VALUE",
STUB_MISS_COUNT_VALUE, STUB_MISS_COUNT_VALUE);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\t%-30s %3d%% (0x%02x)\r\n", "STUB_COLLIDE_WRITE_PCT",
fprintf(g_hStubLogFile, "\t%-30s %3d%% (0x%02x)\r\n", "STUB_COLLIDE_WRITE_PCT",
STUB_COLLIDE_WRITE_PCT, STUB_COLLIDE_WRITE_PCT);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\t%-30s %3d%% (0x%02x)\r\n", "STUB_COLLIDE_MONO_PCT",
fprintf(g_hStubLogFile, "\t%-30s %3d%% (0x%02x)\r\n", "STUB_COLLIDE_MONO_PCT",
STUB_COLLIDE_MONO_PCT, STUB_COLLIDE_MONO_PCT);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\t%-30s %3d%% (0x%02x)\r\n", "DumpLogCounter",
fprintf(g_hStubLogFile, "\t%-30s %3d%% (0x%02x)\r\n", "DumpLogCounter",
g_dumpLogCounter, g_dumpLogCounter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\t%-30s %3d%% (0x%02x)\r\n", "DumpLogIncr",
fprintf(g_hStubLogFile, "\t%-30s %3d%% (0x%02x)\r\n", "DumpLogIncr",
g_dumpLogCounter, g_dumpLogIncr);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\t%-30s %3d%% (0x%02x)\r\n", "ResetCacheCounter",
fprintf(g_hStubLogFile, "\t%-30s %3d%% (0x%02x)\r\n", "ResetCacheCounter",
g_resetCacheCounter, g_resetCacheCounter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\t%-30s %3d%% (0x%02x)\r\n", "ResetCacheIncr",
fprintf(g_hStubLogFile, "\t%-30s %3d%% (0x%02x)\r\n", "ResetCacheIncr",
g_resetCacheCounter, g_resetCacheIncr);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
#endif // STUB_LOGGING
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\nsite data\r\n");
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, "\r\nsite data\r\n");
//output counters
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "site_counter", g_site_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "site_write", g_site_write);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "site_write_mono", g_site_write_mono);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "site_write_poly", g_site_write_poly);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "site_counter", g_site_counter);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "site_write", g_site_write);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "site_write_mono", g_site_write_mono);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "site_write_poly", g_site_write_poly);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\n%-30s %d\r\n", "reclaim_counter", g_reclaim_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, "\r\n%-30s %d\r\n", "reclaim_counter", g_reclaim_counter);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\nstub data\r\n");
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, "\r\nstub data\r\n");
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "stub_lookup_counter", g_stub_lookup_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "stub_mono_counter", g_stub_mono_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "stub_poly_counter", g_stub_poly_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "stub_vtable_counter", g_stub_vtable_counter);
WriteFile(g_hStubLogFile, szPrintStr, (DWORD)strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "stub_space", g_stub_space);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "stub_lookup_counter", g_stub_lookup_counter);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "stub_mono_counter", g_stub_mono_counter);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "stub_poly_counter", g_stub_poly_counter);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "stub_vtable_counter", g_stub_vtable_counter);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "stub_space", g_stub_space);
#ifdef STUB_LOGGING
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\nlookup stub data\r\n");
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, "\r\nlookup stub data\r\n");
UINT32 total_calls = g_mono_call_counter + g_poly_call_counter;
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "lookup_call_counter", g_call_lookup_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "lookup_call_counter", g_call_lookup_counter);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\n%-30s %d\r\n", "total stub dispatch calls", total_calls);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, "\r\n%-30s %d\r\n", "total stub dispatch calls", total_calls);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\n%-30s %#5.2f%%\r\n", "mono stub data",
fprintf(g_hStubLogFile, "\r\n%-30s %#5.2f%%\r\n", "mono stub data",
100.0 * double(g_mono_call_counter)/double(total_calls));
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "mono_call_counter", g_mono_call_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "mono_miss_counter", g_mono_miss_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_PCT, "miss percent",
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "mono_call_counter", g_mono_call_counter);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "mono_miss_counter", g_mono_miss_counter);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_PCT, "miss percent",
100.0 * double(g_mono_miss_counter)/double(g_mono_call_counter));
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\n%-30s %#5.2f%%\r\n", "poly stub data",
fprintf(g_hStubLogFile, "\r\n%-30s %#5.2f%%\r\n", "poly stub data",
100.0 * double(g_poly_call_counter)/double(total_calls));
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "poly_call_counter", g_poly_call_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "poly_miss_counter", g_poly_miss_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_PCT, "miss percent",
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "poly_call_counter", g_poly_call_counter);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "poly_miss_counter", g_poly_miss_counter);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_PCT, "miss percent",
100.0 * double(g_poly_miss_counter)/double(g_poly_call_counter));
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
#endif // STUB_LOGGING
#ifdef CHAIN_LOOKUP
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\nchain lookup data\r\n");
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, "\r\nchain lookup data\r\n");
#ifdef STUB_LOGGING
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "chained_lookup_call_counter", g_chained_lookup_call_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "chained_lookup_miss_counter", g_chained_lookup_miss_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_PCT, "miss percent",
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "chained_lookup_call_counter", g_chained_lookup_call_counter);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "chained_lookup_miss_counter", g_chained_lookup_miss_counter);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_PCT, "miss percent",
100.0 * double(g_chained_lookup_miss_counter)/double(g_chained_lookup_call_counter));
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "chained_lookup_external_call_counter", g_chained_lookup_external_call_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "chained_lookup_external_miss_counter", g_chained_lookup_external_miss_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_PCT, "miss percent",
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "chained_lookup_external_call_counter", g_chained_lookup_external_call_counter);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "chained_lookup_external_miss_counter", g_chained_lookup_external_miss_counter);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_PCT, "miss percent",
100.0 * double(g_chained_lookup_external_miss_counter)/double(g_chained_lookup_external_call_counter));
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
#endif // STUB_LOGGING
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "chained_entry_promoted", g_chained_entry_promoted);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "chained_entry_promoted", g_chained_entry_promoted);
#endif // CHAIN_LOOKUP
#ifdef STUB_LOGGING
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\n%-30s %#5.2f%%\r\n", "worker (slow resolver) data",
fprintf(g_hStubLogFile, "\r\n%-30s %#5.2f%%\r\n", "worker (slow resolver) data",
100.0 * double(g_worker_call)/double(total_calls));
#else // !STUB_LOGGING
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\nworker (slow resolver) data\r\n");
fprintf(g_hStubLogFile, "\r\nworker (slow resolver) data\r\n");
#endif // !STUB_LOGGING
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "worker_call", g_worker_call);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "worker_call_no_patch", g_worker_call_no_patch);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "external_call", g_external_call);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "external_call_no_patch", g_external_call_no_patch);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "worker_collide_to_mono", g_worker_collide_to_mono);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "worker_call", g_worker_call);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "worker_call_no_patch", g_worker_call_no_patch);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "external_call", g_external_call);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "external_call_no_patch", g_external_call_no_patch);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "worker_collide_to_mono", g_worker_collide_to_mono);
UINT32 total_inserts = g_insert_cache_external
+ g_insert_cache_shared
+ g_insert_cache_dispatch
+ g_insert_cache_resolve;
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\n%-30s %d\r\n", "insert cache data", total_inserts);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, "\r\n%-30s %d\r\n", "insert cache data", total_inserts);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT_PCT, "insert_cache_external", g_insert_cache_external,
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT_PCT, "insert_cache_external", g_insert_cache_external,
100.0 * double(g_insert_cache_external)/double(total_inserts));
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT_PCT, "insert_cache_shared", g_insert_cache_shared,
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT_PCT, "insert_cache_shared", g_insert_cache_shared,
100.0 * double(g_insert_cache_shared)/double(total_inserts));
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT_PCT, "insert_cache_dispatch", g_insert_cache_dispatch,
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT_PCT, "insert_cache_dispatch", g_insert_cache_dispatch,
100.0 * double(g_insert_cache_dispatch)/double(total_inserts));
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT_PCT, "insert_cache_resolve", g_insert_cache_resolve,
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT_PCT, "insert_cache_resolve", g_insert_cache_resolve,
100.0 * double(g_insert_cache_resolve)/double(total_inserts));
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT_PCT, "insert_cache_hit", g_insert_cache_hit,
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT_PCT, "insert_cache_hit", g_insert_cache_hit,
100.0 * double(g_insert_cache_hit)/double(total_inserts));
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT_PCT, "insert_cache_miss", g_insert_cache_miss,
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT_PCT, "insert_cache_miss", g_insert_cache_miss,
100.0 * double(g_insert_cache_miss)/double(total_inserts));
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT_PCT, "insert_cache_collide", g_insert_cache_collide,
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT_PCT, "insert_cache_collide", g_insert_cache_collide,
100.0 * double(g_insert_cache_collide)/double(total_inserts));
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT_PCT, "insert_cache_write", g_insert_cache_write,
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT_PCT, "insert_cache_write", g_insert_cache_write,
100.0 * double(g_insert_cache_write)/double(total_inserts));
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\ncache data\r\n");
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, "\r\ncache data\r\n");
#ifdef FEATURE_VIRTUAL_STUB_DISPATCH
size_t total, used;
g_resolveCache->GetLoadFactor(&total, &used);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_SIZE, "cache_entry_used", used);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "cache_entry_counter", g_cache_entry_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "cache_entry_space", g_cache_entry_space);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_SIZE, "cache_entry_used", used);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "cache_entry_counter", g_cache_entry_counter);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "cache_entry_space", g_cache_entry_space);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\nstub hash table data\r\n");
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, "\r\nstub hash table data\r\n");
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "bucket_space", g_bucket_space);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "bucket_space_dead", g_bucket_space_dead);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "bucket_space", g_bucket_space);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "bucket_space_dead", g_bucket_space_dead);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\ncache_load:\t%zu used, %zu total, utilization %#5.2f%%\r\n",
fprintf(g_hStubLogFile, "\r\ncache_load:\t%zu used, %zu total, utilization %#5.2f%%\r\n",
used, total, 100.0 * double(used) / double(total));
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
#ifdef STUB_LOGGING
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\ncache entry write counts\r\n");
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, "\r\ncache entry write counts\r\n");
DispatchCache::CacheEntryData *rgCacheData = g_resolveCache->cacheData;
for (UINT16 i = 0; i < CALL_STUB_CACHE_SIZE; i++)
{
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), " %4d", rgCacheData[i]);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, " %4d", rgCacheData[i]);
if (i % 16 == 15)
{
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\n");
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, "\r\n");
}
}
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\n");
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, "\r\n");
#endif // STUB_LOGGING
#endif // FEATURE_VIRTUAL_STUB_DISPATCH
@ -440,28 +360,21 @@ void VirtualCallStubManager::LoggingDump()
{
if (ContractImplMap::deltasDescs[i] != 0)
{
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "deltasDescs[%d]\t%d\r\n", i, ContractImplMap::deltasDescs[i]);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, "deltasDescs[%d]\t%d\r\n", i, ContractImplMap::deltasDescs[i]);
}
}
for (unsigned i = 0; i < ContractImplMap::max_delta_count; i++)
{
if (ContractImplMap::deltasSlots[i] != 0)
{
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "deltasSlots[%d]\t%d\r\n", i, ContractImplMap::deltasSlots[i]);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, "deltasSlots[%d]\t%d\r\n", i, ContractImplMap::deltasSlots[i]);
}
}
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "cout of maps:\t%d\r\n", ContractImplMap::countMaps);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "count of interfaces:\t%d\r\n", ContractImplMap::countInterfaces);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "count of deltas:\t%d\r\n", ContractImplMap::countDelta);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "total delta for descs:\t%d\r\n", ContractImplMap::totalDeltaDescs);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "total delta for slots:\t%d\r\n", ContractImplMap::totalDeltaSlots);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, "cout of maps:\t%d\r\n", ContractImplMap::countMaps);
fprintf(g_hStubLogFile, "count of interfaces:\t%d\r\n", ContractImplMap::countInterfaces);
fprintf(g_hStubLogFile, "count of deltas:\t%d\r\n", ContractImplMap::countDelta);
fprintf(g_hStubLogFile, "total delta for descs:\t%d\r\n", ContractImplMap::totalDeltaDescs);
fprintf(g_hStubLogFile, "total delta for slots:\t%d\r\n", ContractImplMap::totalDeltaSlots);
#endif // 0
}
@ -473,7 +386,7 @@ void VirtualCallStubManager::FinishLogging()
if(g_hStubLogFile)
{
CloseHandle(g_hStubLogFile);
fclose(g_hStubLogFile);
}
g_hStubLogFile = NULL;
}
@ -3173,50 +3086,32 @@ void VirtualCallStubManager::LogStats()
return;
}
// Temp space to use for formatting the output.
static const int FMT_STR_SIZE = 160;
char szPrintStr[FMT_STR_SIZE];
DWORD dwWriteByte;
if (g_hStubLogFile && (stats.site_write != 0))
{
//output counters
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "site_counter", stats.site_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "site_write", stats.site_write);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "site_write_mono", stats.site_write_mono);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "site_write_poly", stats.site_write_poly);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "site_counter", stats.site_counter);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "site_write", stats.site_write);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "site_write_mono", stats.site_write_mono);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "site_write_poly", stats.site_write_poly);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\nstub data\r\n");
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, "\r\nstub data\r\n");
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "stub_lookup_counter", stats.stub_lookup_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "stub_mono_counter", stats.stub_mono_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "stub_poly_counter", stats.stub_poly_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "stub_space", stats.stub_space);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "stub_lookup_counter", stats.stub_lookup_counter);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "stub_mono_counter", stats.stub_mono_counter);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "stub_poly_counter", stats.stub_poly_counter);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "stub_space", stats.stub_space);
#ifdef FEATURE_VIRTUAL_STUB_DISPATCH
size_t total, used;
g_resolveCache->GetLoadFactor(&total, &used);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_SIZE, "cache_entry_used", used);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "cache_entry_counter", stats.cache_entry_counter);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), OUTPUT_FORMAT_INT, "cache_entry_space", stats.cache_entry_space);
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_SIZE, "cache_entry_used", used);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "cache_entry_counter", stats.cache_entry_counter);
fprintf(g_hStubLogFile, OUTPUT_FORMAT_INT, "cache_entry_space", stats.cache_entry_space);
sprintf_s(szPrintStr, ARRAY_SIZE(szPrintStr), "\r\ncache_load:\t%zu used, %zu total, utilization %#5.2f%%\r\n",
fprintf(g_hStubLogFile, "\r\ncache_load:\t%zu used, %zu total, utilization %#5.2f%%\r\n",
used, total, 100.0 * double(used) / double(total));
#endif // FEATURE_VIRTUAL_STUB_DISPATCH
WriteFile (g_hStubLogFile, szPrintStr, (DWORD) strlen(szPrintStr), &dwWriteByte, NULL);
}
#ifdef FEATURE_VIRTUAL_STUB_DISPATCH