Skip to content

Commit

Permalink
* Backported crash dumping system for Win32 - see 1.2 log for a full …
Browse files Browse the repository at this point in the history
…description

* Fixed new m_ident compile under Win32

git-svn-id: http://svn.inspircd.org/repository/branches/1_1_stable@8016 e03df62e-2008-0410-955e-edbf42e46eb7
  • Loading branch information
burlex committed Sep 4, 2007
1 parent 827a3a3 commit b00836d
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 3 deletions.
19 changes: 18 additions & 1 deletion src/inspircd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,14 +1170,31 @@ int InspIRCd::Run()
* An ircd in four lines! bwahahaha. ahahahahaha. ahahah *cough*.
*/

int main(int argc, char** argv)
int ircd(int argc, char** argv)
{
SI = new InspIRCd(argc, argv);
SI->Run();
delete SI;
return 0;
}

#ifdef WINDOWS

int main(int argc, char ** argv)
{
__try {
ircd(argc,argv);
} __except(__exceptionHandler(GetExceptionInformation())) {}
return 0;
}

#else
int main(int argc, char** argv)
{
return ircd(argc,argv);
}
#endif

/* this returns true when all modules are satisfied that the user should be allowed onto the irc server
* (until this returns true, a user will block in the waiting state, waiting to connect up to the
* registration timeout maximum seconds)
Expand Down
2 changes: 1 addition & 1 deletion src/modules/m_ident.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class ModuleIdent : public Module
std::string IdentBindIP;
public:
ModuleIdent(InspIRCd *Me)
: Module::Module(Me)
: Module(Me)
{
OnRehash(NULL, "");
}
Expand Down
2 changes: 1 addition & 1 deletion win/inspircdVC71.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib mswsock.lib"
AdditionalDependencies="ws2_32.lib mswsock.lib dbghelp.lib"
ShowProgress="0"
OutputFile="$(OutDir)/inspircd.exe"
LinkIncremental="1"
Expand Down
65 changes: 65 additions & 0 deletions win/inspircd_win32wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,3 +525,68 @@ int gettimeofday(struct timeval * tv, void * tz)
return 0;
}

#ifdef ENABLE_CRASHDUMPS
int __exceptionHandler(PEXCEPTION_POINTERS pExceptPtrs)
{
SYSTEMTIME _time;
HANDLE hDump;
char mod[MAX_PATH*2];
char * pMod = mod;
char dump_filename[MAX_PATH];
MINIDUMP_EXCEPTION_INFORMATION dumpInfo;
DWORD code;

if(pExceptPtrs == NULL) {
__try {
RaiseException(EXCEPTION_BREAKPOINT, 0, 0, NULL);
} __except(__exceptionHandler(GetExceptionInformation()), EXCEPTION_CONTINUE_EXECUTION) {}
}

printf("Exception caught at 0x%.8X! Attempting to write crash dump file.\n", (unsigned long)pExceptPtrs->ExceptionRecord->ExceptionAddress);

if(GetModuleFileName(0, mod, MAX_PATH*2) > 0)
{
if( (pMod = strrchr(mod, '\\')) != NULL )
++pMod;
else
strcpy(mod, "unk");
}
else
strcpy(mod, "unk");

GetSystemTime(&_time);
snprintf(dump_filename, MAX_PATH, "dump-%s-%u-%u-%u-%u-%u-%u.dmp",
pMod, _time.wYear, _time.wMonth, _time.wDay, _time.wHour, _time.wMinute, _time.wSecond);

hDump = CreateFile(dump_filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, 0);
if(hDump != INVALID_HANDLE_VALUE)
{
dumpInfo.ClientPointers = FALSE;
dumpInfo.ExceptionPointers = pExceptPtrs;
dumpInfo.ThreadId = GetCurrentThreadId();

/* let's write a full memory dump. insp shouldn't be using much memory anyway, and it will help a lot with debugging. */
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDump, MiniDumpWithFullMemory, &dumpInfo, NULL, NULL);
FlushFileBuffers(hDump);
CloseHandle(hDump);
}

/* check for a debugger */
__asm {
pushad
pushfd
mov eax, fs:[18h]
mov eax, dword ptr [eax+30h]
mov ebx, dword ptr [eax]
mov code, ebx
popfd
popad
}

/* break into debugger if we have one */
if(code & 0x10000)
return EXCEPTION_CONTINUE_SEARCH;
else /* otherwise exit abnormally */
return EXCEPTION_CONTINUE_EXECUTION;
}
#endif
10 changes: 10 additions & 0 deletions win/inspircd_win32wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/* Define the WINDOWS macro. This means we're building on windows to the rest of the server.
I think this is more reasonable than using WIN32, especially if we're gonna be doing 64-bit compiles */
#define WINDOWS 1
#define ENABLE_CRASHDUMPS 1

/* Make builds smaller, leaner and faster */
#define VC_EXTRALEAN
Expand Down Expand Up @@ -66,6 +67,10 @@
#include <stdio.h>
#include <algorithm>

#ifdef ENABLE_CRASHDUMPS
#include <DbgHelp.h>
#endif

/* strcasecmp is not defined on windows by default */
#define strcasecmp _stricmp

Expand Down Expand Up @@ -188,5 +193,10 @@ CoreExport void ClearConsole();
/* Windows does not have gettimeofday() */
CoreExport int gettimeofday(struct timeval * tv, void * tz);

#ifdef ENABLE_CRASHDUMPS
typedef struct _EXCEPTION_POINTERS EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
int __cdecl __exceptionHandler(PEXCEPTION_POINTERS pExceptPtrs);
#endif

#endif

0 comments on commit b00836d

Please sign in to comment.