Decouple <cstdint>

This commit is contained in:
Martin Natano
2023-04-21 22:13:41 +02:00
parent bcea05dd67
commit aa87f85eef
167 changed files with 1533 additions and 1307 deletions
+3 -2
View File
@@ -4,6 +4,7 @@
//#include <stdio.h>
#include <cstddef>
#include <cstdint>
#include <windows.h>
#include "global.h"
@@ -580,7 +581,7 @@ static void debug_crash()
/* Get a stack trace of the current thread and the specified thread.
* If iID == GetInvalidThreadId(), then output a stack trace for every thread. */
void CrashHandler::ForceDeadlock( RString reason, uint64_t iID )
void CrashHandler::ForceDeadlock( RString reason, std::uint64_t iID )
{
strncpy( g_CrashInfo.m_CrashReason, reason, sizeof(g_CrashInfo.m_CrashReason) );
g_CrashInfo.m_CrashReason[ sizeof(g_CrashInfo.m_CrashReason)-1 ] = 0;
@@ -607,7 +608,7 @@ void CrashHandler::ForceDeadlock( RString reason, uint64_t iID )
context.ContextFlags = CONTEXT_FULL;
if( !GetThreadContext( hThread, &context ) )
wsprintf( g_CrashInfo.m_CrashReason + strlen(g_CrashInfo.m_CrashReason),
"; GetThreadContext(%Ix) failed", reinterpret_cast<uintptr_t>(hThread) );
"; GetThreadContext(%Ix) failed", reinterpret_cast<std::uintptr_t>(hThread) );
else
{
static const void *BacktracePointers[BACKTRACE_MAX_SIZE];
+2 -1
View File
@@ -2,6 +2,7 @@
#define CRASH_H
#include <cstddef>
#include <cstdint>
#include <windows.h>
/** @brief Win32 crash handling. */
@@ -12,7 +13,7 @@ namespace CrashHandler
void do_backtrace( const void **buf, std::size_t size, HANDLE hProcess, HANDLE hThread, const CONTEXT *pContext );
void SymLookup( const void *ptr, char *buf );
void ForceCrash( const char *reason );
void ForceDeadlock( RString reason, uint64_t iID );
void ForceDeadlock( RString reason, std::uint64_t iID );
/* Inform the crash handler of a foreground window that may be fullscreen.
* If set, the crash handler will attempt to hide the window or reset the
+24 -22
View File
@@ -1,9 +1,11 @@
#include "global.h"
#include "CrashHandlerInternal.h"
#include "Crash.h"
#include <errno.h>
#include <cerrno>
#include <cstddef>
#include <cstdint>
#include <windows.h>
#include <commctrl.h>
#include "archutils/Win32/ddk/dbghelp.h"
@@ -53,10 +55,10 @@ namespace VDDebugInfo
int nBuildNumber;
const unsigned char *pRVAHeap;
uintptr_t nFirstRVA;
std::uintptr_t nFirstRVA;
const char *pFuncNameHeap;
const uintptr_t (*pSegments)[2];
const std::uintptr_t (*pSegments)[2];
int nSegments;
char sFilename[1024];
RString sError;
@@ -110,10 +112,10 @@ namespace VDDebugInfo
src += 2 * (sizeof(int) + sizeof(std::size_t));
pctx->nBuildNumber = *pVer;
pctx->pRVAHeap = reinterpret_cast<const unsigned char*>(src + sizeof(uintptr_t));
pctx->nFirstRVA = *reinterpret_cast<const uintptr_t*>(src);
pctx->pRVAHeap = reinterpret_cast<const unsigned char*>(src + sizeof(std::uintptr_t));
pctx->nFirstRVA = *reinterpret_cast<const std::uintptr_t*>(src);
pctx->pFuncNameHeap = reinterpret_cast<const char*>(src + *pRVASize);
pctx->pSegments = reinterpret_cast<const uintptr_t(*)[2]>(src + *pRVASize + *pFNamSize);
pctx->pSegments = reinterpret_cast<const std::uintptr_t(*)[2]>(src + *pRVASize + *pFNamSize);
pctx->nSegments = *pSegCnt;
return true;
@@ -167,7 +169,7 @@ namespace VDDebugInfo
return false;
}
static bool PointerIsInAnySegment( const Context *pctx, uintptr_t rva )
static bool PointerIsInAnySegment( const Context *pctx, std::uintptr_t rva )
{
for( int i=0; i<pctx->nSegments; ++i )
{
@@ -186,7 +188,7 @@ namespace VDDebugInfo
return heap;
}
intptr_t VDDebugInfoLookupRVA( const Context *pctx, uintptr_t rva, char *buf, int buflen )
std::intptr_t VDDebugInfoLookupRVA( const Context *pctx, std::uintptr_t rva, char *buf, int buflen )
{
if( !PointerIsInAnySegment(pctx, rva) )
return -1;
@@ -198,13 +200,13 @@ namespace VDDebugInfo
// Linearly unpack RVA deltas and find lower_bound
rva -= pctx->nFirstRVA;
if( static_cast<intptr_t>(rva) < 0 )
if( static_cast<std::intptr_t>(rva) < 0 )
return -1;
while( pr < pr_limit )
{
unsigned char c;
uintptr_t diff = 0;
std::uintptr_t diff = 0;
do
{
@@ -215,7 +217,7 @@ namespace VDDebugInfo
rva -= diff;
if (static_cast<intptr_t>(rva) < 0) {
if (static_cast<std::intptr_t>(rva) < 0) {
rva += diff;
break;
}
@@ -234,7 +236,7 @@ namespace VDDebugInfo
strncpy( buf, fn_name, buflen );
buf[buflen-1] = 0;
return static_cast<intptr_t>(rva);
return static_cast<std::intptr_t>(rva);
}
}
@@ -287,7 +289,7 @@ namespace SymbolLookup
return true;
}
SYMBOL_INFO *GetSym( uintptr_t ptr, DWORD64 &disp )
SYMBOL_INFO *GetSym( std::uintptr_t ptr, DWORD64 &disp )
{
InitDbghelp();
@@ -367,12 +369,12 @@ namespace SymbolLookup
VirtualQueryEx( g_hParent, ptr, &meminfo, sizeof meminfo );
char tmp[512];
intptr_t iAddress = VDDebugInfo::VDDebugInfoLookupRVA(pctx, reinterpret_cast<uintptr_t>(ptr), tmp, sizeof(tmp));
std::intptr_t iAddress = VDDebugInfo::VDDebugInfoLookupRVA(pctx, reinterpret_cast<std::uintptr_t>(ptr), tmp, sizeof(tmp));
if( iAddress >= 0 )
{
wsprintf( buf, "%" ADDRESS_ZEROS "Ix: %s [%" ADDRESS_ZEROS "Ix+%Ix+%Ix]", reinterpret_cast<uintptr_t>(ptr), Demangle(tmp),
wsprintf( buf, "%" ADDRESS_ZEROS "Ix: %s [%" ADDRESS_ZEROS "Ix+%Ix+%Ix]", reinterpret_cast<std::uintptr_t>(ptr), Demangle(tmp),
pctx->nFirstRVA,
reinterpret_cast<uintptr_t>(ptr) - pctx->nFirstRVA - iAddress,
reinterpret_cast<std::uintptr_t>(ptr) - pctx->nFirstRVA - iAddress,
iAddress );
return;
}
@@ -380,21 +382,21 @@ namespace SymbolLookup
RString sName = CrashChildGetModuleBaseName( (HMODULE)meminfo.AllocationBase );
DWORD64 disp;
SYMBOL_INFO *pSymbol = GetSym( reinterpret_cast<uintptr_t>(ptr), disp );
SYMBOL_INFO *pSymbol = GetSym( reinterpret_cast<std::uintptr_t>(ptr), disp );
if( pSymbol )
{
wsprintf( buf, "%" ADDRESS_ZEROS "Ix: %s!%s [%" ADDRESS_ZEROS "Ix+%Ix+%Ix]",
reinterpret_cast<uintptr_t>(ptr), sName.c_str(), pSymbol->Name,
reinterpret_cast<uintptr_t>(meminfo.AllocationBase),
static_cast<uintptr_t>(pSymbol->Address) - reinterpret_cast<uintptr_t>(meminfo.AllocationBase),
reinterpret_cast<std::uintptr_t>(ptr), sName.c_str(), pSymbol->Name,
reinterpret_cast<std::uintptr_t>(meminfo.AllocationBase),
static_cast<std::uintptr_t>(pSymbol->Address) - reinterpret_cast<std::uintptr_t>(meminfo.AllocationBase),
static_cast<ULONG_PTR>(disp));
return;
}
wsprintf( buf, "%" ADDRESS_ZEROS "Ix: %s!%" ADDRESS_ZEROS "Ix",
reinterpret_cast<uintptr_t>(ptr), sName.c_str(),
reinterpret_cast<uintptr_t>(meminfo.AllocationBase) );
reinterpret_cast<std::uintptr_t>(ptr), sName.c_str(),
reinterpret_cast<std::uintptr_t>(meminfo.AllocationBase) );
}
}
@@ -7,6 +7,7 @@
#include "RageUtil.h"
#include <cstddef>
#include <cstdint>
#if defined(WINDOWS)
#include <windows.h>
@@ -396,7 +397,7 @@ void NetworkStream_Win32::Open( const RString &sHost, int iPort, ConnectionType
sockaddr_in addr;
addr.sin_addr.s_addr = *(DWORD *)pHost->h_addr_list[0];
addr.sin_family = PF_INET;
addr.sin_port = htons( (uint16_t) iPort );
addr.sin_port = htons( (std::uint16_t) iPort );
m_Mutex.Lock();
m_Socket = socket( PF_INET, SOCK_STREAM, IPPROTO_TCP );
+5 -3
View File
@@ -3,6 +3,8 @@
#include "RageUtil.h"
#include "archutils/Win32/ErrorStrings.h"
#include <cstdint>
#include <sys/stat.h>
#include <windows.h>
#include <tlhelp32.h>
@@ -87,7 +89,7 @@ RString FindSystemFile( RString sFile )
/* Get the full path of the process running in iProcessID. On error, false is
* returned and an error message is placed in sName. */
bool GetProcessFileName( uint32_t iProcessID, RString &sName )
bool GetProcessFileName( std::uint32_t iProcessID, RString &sName )
{
/* This method works in everything except for NT4, and only uses
* kernel32.lib functions. */
@@ -173,7 +175,7 @@ bool GetProcessFileName( uint32_t iProcessID, RString &sName )
/*
* (c) 2004 Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -183,7 +185,7 @@ bool GetProcessFileName( uint32_t iProcessID, RString &sName )
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+5 -3
View File
@@ -3,16 +3,18 @@
#ifndef GET_FILE_INFORMATION_H
#define GET_FILE_INFORMATION_H
#include <cstdint>
bool GetFileVersion( RString fsFile, RString &sOut );
RString FindSystemFile( RString sFile );
bool GetProcessFileName( uint32_t iProcessID, RString &sName );
bool GetProcessFileName( std::uint32_t iProcessID, RString &sName );
#endif
/*
* (c) 2004 Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -22,7 +24,7 @@ bool GetProcessFileName( uint32_t iProcessID, RString &sName );
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+4 -1
View File
@@ -1,5 +1,8 @@
#include "global.h"
#include "GotoURL.h"
#include <cstdint>
#include <windows.h>
#include <shellapi.h>
@@ -25,7 +28,7 @@ static LONG GetRegKey( HKEY key, RString subkey, LPTSTR retdata )
bool GotoURL( RString sUrl )
{
// First try ShellExecute()
intptr_t iRet = reinterpret_cast<intptr_t>(ShellExecute( nullptr, "open", sUrl, nullptr, nullptr, SW_SHOWDEFAULT ));
std::intptr_t iRet = reinterpret_cast<std::intptr_t>(ShellExecute( nullptr, "open", sUrl, nullptr, nullptr, SW_SHOWDEFAULT ));
// If it failed, get the .htm regkey and lookup the program
if( iRet > 32 )
+8 -6
View File
@@ -7,6 +7,8 @@
#include "RageSurface_Load.h"
#include "archutils/Win32/ErrorStrings.h"
#include <cstdint>
#include <wingdi.h>
HICON IconFromSurface( const RageSurface *pSrcImg )
@@ -45,8 +47,8 @@ HICON IconFromSurface( const RageSurface *pSrcImg )
pBitmap->biCompression = BI_RGB;
pBitmap->biSizeImage = pImg->h * pImg->pitch;
uint8_t *pImage = ((uint8_t *) pBitmap) + iSize;
uint8_t *pMask = pImage + pImg->h * pImg->pitch;
std::uint8_t *pImage = ((std::uint8_t *) pBitmap) + iSize;
std::uint8_t *pMask = pImage + pImg->h * pImg->pitch;
memcpy( pImage, pImg->pixels, pImg->h * pImg->pitch );
@@ -54,8 +56,8 @@ HICON IconFromSurface( const RageSurface *pSrcImg )
for( int y = 0; y < pImg->h; ++y )
{
int bit = 0x80;
uint32_t *pRow = (uint32_t *) (pImage + y*pImg->pitch);
uint8_t *pMaskRow = pMask + y*iMaskPitch;
std::uint32_t *pRow = (std::uint32_t *) (pImage + y*pImg->pitch);
std::uint8_t *pMaskRow = pMask + y*iMaskPitch;
for( int x = 0; x < pImg->w; ++x )
{
if( !(pRow[x] & pImg->fmt.Mask[3]) )
@@ -107,7 +109,7 @@ HICON IconFromFile( const RString &sIconFile )
/*
* (c) 2004 Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -117,7 +119,7 @@ HICON IconFromFile( const RString &sIconFile )
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
-13
View File
@@ -72,19 +72,6 @@ struct tm *my_gmtime_r( const time_t *timep, struct tm *result );
void my_usleep( unsigned long usec );
#define usleep my_usleep
// Missing stdint types:
typedef signed char int8_t;
typedef signed short int16_t;
typedef int int32_t;
typedef __int64 int64_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef int int32_t;
typedef unsigned int uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#undef min
#undef max
#define NOMINMAX // make sure Windows doesn't try to define this
+23 -23
View File
@@ -16,7 +16,7 @@
#define MAX_GROUPS (64)
struct RVAEnt {
uintptr_t rva;
std::uintptr_t rva;
char *line;
};
@@ -25,10 +25,10 @@ std::vector<RVAEnt> rvabuf;
char fnambuf[MAX_FNAMBUF];
char *fnamptr = fnambuf;
uintptr_t segbuf[MAX_SEGMENTS][2];
std::uintptr_t segbuf[MAX_SEGMENTS][2];
int segcnt = 0;
uint16_t seggrp[MAX_SEGMENTS];
uintptr_t grpstart[MAX_GROUPS];
std::uint16_t seggrp[MAX_SEGMENTS];
std::uintptr_t grpstart[MAX_GROUPS];
char line[8192];
long codeseg_flags = 0;
@@ -94,7 +94,7 @@ void RemoveAnonymousNamespaces( char *p )
}
void parsename(uintptr_t rva, char *func_name) {
void parsename(std::uintptr_t rva, char *func_name) {
RemoveAnonymousNamespaces( func_name );
fnamptr = strtack(fnamptr, func_name, fnambuf+MAX_FNAMBUF);
@@ -140,9 +140,9 @@ int main(int argc, char **argv) {
// printf("Reading in segment list.\n");
while (readline()) {
uint16_t grp;
uint32_t start;
uint32_t len;
std::uint16_t grp;
std::uint32_t start;
std::uint32_t len;
if (sscanf(line, "%" SCNx16 ":%" SCNx32 " %" SCNx32, &grp, &start, &len) != 3)
break;
@@ -152,8 +152,8 @@ int main(int argc, char **argv) {
codeseg_flags |= 1 << grp;
segbuf[segcnt][0] = static_cast<uintptr_t>(start);
segbuf[segcnt][1] = static_cast<uintptr_t>(len);
segbuf[segcnt][0] = static_cast<std::uintptr_t>(start);
segbuf[segcnt][1] = static_cast<std::uintptr_t>(len);
seggrp[segcnt] = grp;
++segcnt;
}
@@ -169,9 +169,9 @@ int main(int argc, char **argv) {
// printf("Found public symbol list.\n");
while (readline()) {
uint16_t grp;
uint32_t start;
uintptr_t rva;
std::uint16_t grp;
std::uint32_t start;
std::uintptr_t rva;
char symname[2048];
if (sscanf(line, "%" SCNx16 ":%" SCNx32 " %s %" SCNxPTR, &grp, &start, symname, &rva) != 4)
@@ -199,9 +199,9 @@ int main(int argc, char **argv) {
readline();
while (readline()) {
uint16_t grp;
uint32_t start;
uintptr_t rva;
std::uint16_t grp;
std::uint32_t start;
std::uintptr_t rva;
char symname[4096];
if (sscanf(line, "%" SCNx16 ":%" SCNx32 " %s %" SCNxPTR, &grp, &start, symname, &rva) != 4)
@@ -225,15 +225,15 @@ int main(int argc, char **argv) {
// printf("Processing RVA entries...\n");
for (std::size_t i = 0; i < rvabuf.size(); ++i) {
uint16_t grp;
uint32_t start;
uintptr_t rva;
std::uint16_t grp;
std::uint32_t start;
std::uintptr_t rva;
char symname[4096];
if (sscanf(rvabuf[i].line, "%" SCNx16 ":%" SCNx32 " %s %" SCNxPTR, &grp, &start, symname, &rva) != 4)
break;
grpstart[grp] = rva - static_cast<uintptr_t>(start);
grpstart[grp] = rva - static_cast<std::uintptr_t>(start);
parsename(rva, symname);
}
@@ -253,8 +253,8 @@ int main(int argc, char **argv) {
*/
std::vector<RVAEnt>::iterator itRVA = rvabuf.begin(), itRVAEnd = rvabuf.end();
std::vector<char> rvaout;
uintptr_t firstrva = (*itRVA++).rva;
uintptr_t lastrva = firstrva;
std::uintptr_t firstrva = (*itRVA++).rva;
std::uintptr_t lastrva = firstrva;
for(; itRVA != itRVAEnd; ++itRVA) {
std::ptrdiff_t rvadiff = (*itRVA).rva - lastrva;
@@ -303,7 +303,7 @@ int main(int argc, char **argv) {
fwrite(&firstrva, sizeof firstrva, 1, fo);
fwrite(&rvaout[0], rvaout.size(), 1, fo);
fwrite(fnambuf, fnamptr - fnambuf, 1, fo);
fwrite(segbuf, segcnt * 2 * sizeof(uintptr_t), 1, fo);
fwrite(segbuf, segcnt * 2 * sizeof(std::uintptr_t), 1, fo);
// really all done