• R/O
  • HTTP
  • SSH
  • HTTPS

PeerCastIM: Commit


Commit MetaInfo

Revisãod740be2282b31ac3a3cd0de3872a812f17baadfa (tree)
Hora2008-09-09 16:58:32
Autoreru <eru01@user...>
Commitereru

Mensagem de Log

CoreのスレッドにSEHを設置

Mudança Sumário

Diff

--- a/PeerCast.root/PeerCast/core/common/channel.cpp
+++ b/PeerCast.root/PeerCast/core/common/channel.cpp
@@ -50,6 +50,8 @@
5050 #define new DEBUG_NEW
5151 #endif
5252
53+#include "win32/seh.h"
54+
5355 // -----------------------------------
5456 char *Channel::srcTypes[]=
5557 {
@@ -423,7 +425,7 @@ void Channel::checkReadDelay(unsigned int len)
423425
424426
425427 // -----------------------------------
426-THREAD_PROC Channel::stream(ThreadInfo *thread)
428+THREAD_PROC Channel::streamMain(ThreadInfo *thread)
427429 {
428430 // thread->lock();
429431
@@ -483,10 +485,16 @@ THREAD_PROC Channel::stream(ThreadInfo *thread)
483485 ch->endThread(true);
484486 }
485487 return 0;
488+}
489+
490+// -----------------------------------
491+THREAD_PROC Channel::stream(ThreadInfo *thread)
492+{
493+ SEH_THREAD(streamMain, Channel::stream);
486494 }
487495
488496 // -----------------------------------
489-THREAD_PROC Channel::waitFinish(ThreadInfo *thread)
497+THREAD_PROC Channel::waitFinishMain(ThreadInfo *thread)
490498 {
491499 Channel *ch = (Channel*)thread->data;
492500 LOG_DEBUG("Wait channel finish");
@@ -507,6 +515,13 @@ THREAD_PROC Channel::waitFinish(ThreadInfo *thread)
507515 }
508516
509517 // -----------------------------------
518+THREAD_PROC Channel::waitFinish(ThreadInfo *thread)
519+{
520+ SEH_THREAD(waitFinishMain, Channel::waitFinish);
521+}
522+
523+
524+// -----------------------------------
510525 bool Channel::acceptGIV(ClientSocket *givSock)
511526 {
512527 if (!pushSock)
@@ -3041,7 +3056,7 @@ public:
30413056 bool keep;
30423057 };
30433058 // -----------------------------------
3044-THREAD_PROC findAndPlayChannelProc(ThreadInfo *th)
3059+THREAD_PROC findAndPlayChannelProcMain(ThreadInfo *th)
30453060 {
30463061 ChanFindInfo *cfi = (ChanFindInfo *)th;
30473062
@@ -3069,6 +3084,13 @@ THREAD_PROC findAndPlayChannelProc(ThreadInfo *th)
30693084 delete cfi;
30703085 return 0;
30713086 }
3087+
3088+// -----------------------------------
3089+THREAD_PROC findAndPlayChannelProc(ThreadInfo *thread)
3090+{
3091+ SEH_THREAD(findAndPlayChannelProcMain, findAndPlayChannel);
3092+}
3093+
30723094 // -----------------------------------
30733095 void ChanMgr::findAndPlayChannel(ChanInfo &info, bool keep)
30743096 {
--- a/PeerCast.root/PeerCast/core/common/channel.h
+++ b/PeerCast.root/PeerCast/core/common/channel.h
@@ -443,8 +443,10 @@ public:
443443 bool isIdle() {return isActive() && (status==S_IDLE);}
444444
445445 static THREAD_PROC stream(ThreadInfo *);
446+ static THREAD_PROC streamMain(ThreadInfo *);
446447
447448 static THREAD_PROC waitFinish(ThreadInfo *);
449+ static THREAD_PROC waitFinishMain(ThreadInfo *);
448450
449451 void setStatus(STATUS s);
450452 const char *getSrcTypeStr() {return srcTypes[srcType];}
--- a/PeerCast.root/PeerCast/core/common/servent.cpp
+++ b/PeerCast.root/PeerCast/core/common/servent.cpp
@@ -40,6 +40,8 @@
4040 #define new DEBUG_NEW
4141 #endif
4242
43+#include "win32/seh.h"
44+
4345
4446 const int DIRECT_WRITE_TIMEOUT = 60;
4547
@@ -1668,7 +1670,7 @@ void Servent::processRoot()
16681670 }
16691671
16701672 // -----------------------------------
1671-int Servent::givProc(ThreadInfo *thread)
1673+int Servent::givProcMain(ThreadInfo *thread)
16721674 {
16731675 // thread->lock();
16741676 Servent *sv = (Servent*)thread->data;
@@ -1688,6 +1690,12 @@ int Servent::givProc(ThreadInfo *thread)
16881690 }
16891691
16901692 // -----------------------------------
1693+int Servent::givProc(ThreadInfo *thread)
1694+{
1695+ SEH_THREAD(givProcMain, Servent::givProc);
1696+}
1697+
1698+// -----------------------------------
16911699 void Servent::handshakeOutgoingPCP(AtomStream &atom, Host &rhost, GnuID &rid, String &agent, bool isTrusted)
16921700 {
16931701
@@ -2128,7 +2136,7 @@ void Servent::processIncomingPCP(bool suggestOthers)
21282136 }
21292137
21302138 // -----------------------------------
2131-int Servent::outgoingProc(ThreadInfo *thread)
2139+int Servent::outgoingProcMain(ThreadInfo *thread)
21322140 {
21332141 // thread->lock();
21342142 LOG_DEBUG("COUT started");
@@ -2309,7 +2317,12 @@ int Servent::outgoingProc(ThreadInfo *thread)
23092317 return 0;
23102318 }
23112319 // -----------------------------------
2312-int Servent::incomingProc(ThreadInfo *thread)
2320+int Servent::outgoingProc(ThreadInfo *thread)
2321+{
2322+ SEH_THREAD(outgoingProcMain, Servent::outgoingProc);
2323+}
2324+// -----------------------------------
2325+int Servent::incomingProcMain(ThreadInfo *thread)
23132326 {
23142327 // thread->lock();
23152328
@@ -2342,6 +2355,11 @@ int Servent::incomingProc(ThreadInfo *thread)
23422355 return 0;
23432356 }
23442357 // -----------------------------------
2358+int Servent::incomingProc(ThreadInfo *thread)
2359+{
2360+ SEH_THREAD(incomingProcMain, Servent::incomingProc);
2361+}
2362+// -----------------------------------
23452363 void Servent::processServent()
23462364 {
23472365 setStatus(S_HANDSHAKE);
@@ -2986,7 +3004,7 @@ void Servent::sendPCPChannel()
29863004 }
29873005
29883006 // -----------------------------------
2989-int Servent::serverProc(ThreadInfo *thread)
3007+int Servent::serverProcMain(ThreadInfo *thread)
29903008 {
29913009 // thread->lock();
29923010
@@ -3053,6 +3071,12 @@ int Servent::serverProc(ThreadInfo *thread)
30533071 sys->endThread(thread);
30543072 return 0;
30553073 }
3074+
3075+// -----------------------------------
3076+int Servent::serverProc(ThreadInfo *thread)
3077+{
3078+ SEH_THREAD(serverProcMain, Servent::serverProc);
3079+}
30563080
30573081 // -----------------------------------
30583082 bool Servent::writeVariable(Stream &s, const String &var)
--- a/PeerCast.root/PeerCast/core/common/servent.h
+++ b/PeerCast.root/PeerCast/core/common/servent.h
@@ -144,9 +144,13 @@ public:
144144
145145 // static funcs that do the actual work in the servent thread
146146 static THREAD_PROC serverProc(ThreadInfo *);
147+ static THREAD_PROC serverProcMain(ThreadInfo *);
147148 static THREAD_PROC outgoingProc(ThreadInfo *);
149+ static THREAD_PROC outgoingProcMain(ThreadInfo *);
148150 static THREAD_PROC incomingProc(ThreadInfo *);
151+ static THREAD_PROC incomingProcMain(ThreadInfo *);
149152 static THREAD_PROC givProc(ThreadInfo *);
153+ static THREAD_PROC givProcMain(ThreadInfo *);
150154 static THREAD_PROC pcpProc(ThreadInfo *);
151155 static THREAD_PROC fetchProc(ThreadInfo *);
152156
--- a/PeerCast.root/PeerCast/core/common/version2.h
+++ b/PeerCast.root/PeerCast/core/common/version2.h
@@ -44,9 +44,9 @@ extern int version_ex; // PP
4444 #if 1 /* for VP extend version */
4545 //#define VERSION_EX 1
4646 static const char *PCP_CLIENT_VERSION_EX_PREFIX = "IM"; // 2bytes only
47-static const int PCP_CLIENT_VERSION_EX_NUMBER = 28;
48-static const char *PCX_AGENTEX = "PeerCast/0.1218(IM0028-3)";
49-static const char *PCX_VERSTRING_EX = "v0.1218(IM0028-3)";
47+static const int PCP_CLIENT_VERSION_EX_NUMBER = 29;
48+static const char *PCX_AGENTEX = "PeerCast/0.1218(IM0029)";
49+static const char *PCX_VERSTRING_EX = "v0.1218(IM0029)";
5050 #endif
5151
5252 // ------------------------------------------------
--- a/PeerCast.root/PeerCast/core/win32/lib/corelib.vcproj
+++ b/PeerCast.root/PeerCast/core/win32/lib/corelib.vcproj
@@ -212,6 +212,7 @@
212212 ProgramDataBaseFileName=".\Release/"
213213 WarningLevel="3"
214214 SuppressStartupBanner="true"
215+ DebugInformationFormat="3"
215216 />
216217 <Tool
217218 Name="VCManagedResourceCompilerTool"
@@ -1374,6 +1375,10 @@
13741375 Name="Win32 Source"
13751376 >
13761377 <File
1378+ RelativePath="..\seh.cpp"
1379+ >
1380+ </File>
1381+ <File
13771382 RelativePath="..\wsocket.cpp"
13781383 >
13791384 <FileConfiguration
@@ -1458,6 +1463,10 @@
14581463 Name="Win32 Includes"
14591464 >
14601465 <File
1466+ RelativePath="..\seh.h"
1467+ >
1468+ </File>
1469+ <File
14611470 RelativePath="..\wsocket.h"
14621471 >
14631472 </File>
--- /dev/null
+++ b/PeerCast.root/PeerCast/core/win32/seh.cpp
@@ -0,0 +1,41 @@
1+#include "win32/seh.h"
2+
3+void SEHdump(_EXCEPTION_POINTERS *lpExcept)
4+{
5+ // crash dump
6+ MINIDUMP_EXCEPTION_INFORMATION minidumpInfo;
7+ HANDLE hFile;
8+ BOOL dump = FALSE;
9+
10+ minidumpInfo.ThreadId = GetCurrentThreadId();
11+ minidumpInfo.ExceptionPointers = lpExcept;
12+ minidumpInfo.ClientPointers = FALSE;
13+
14+ hFile = CreateFile(".\\dump.dmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
15+ if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE))
16+ {
17+ dump = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile,
18+ (MINIDUMP_TYPE)(MiniDumpWithIndirectlyReferencedMemory|MiniDumpScanMemory),
19+ &minidumpInfo, NULL, NULL);
20+ CloseHandle(hFile);
21+ }
22+
23+
24+ // dump peercast's log
25+ fs.openWriteReplace(".\\dump.html");
26+ sys->logBuf->dumpHTML(fs);
27+ fs.close();
28+ if (dump)
29+ {
30+ MessageBox(NULL, "一般保護違反の為、プログラムは強制終了されます。\n"
31+ "問題解決のためダンプデータ(dump.html, dump.dmp)を提供してください。", "SEH",
32+ MB_OK|MB_ICONWARNING);
33+ } else
34+ {
35+ MessageBox(NULL, "一般保護違反の為、プログラムは強制終了されます。\n"
36+ "問題解決のためにダンプデータ(dump.html)を提供してください。", "SEH",
37+ MB_OK|MB_ICONWARNING);
38+ }
39+
40+ ::exit(lpExcept->ExceptionRecord->ExceptionCode);
41+}
--- /dev/null
+++ b/PeerCast.root/PeerCast/core/win32/seh.h
@@ -0,0 +1,24 @@
1+#ifndef _SEH_H_
2+#define _SEH_H_
3+
4+#include "stream.h"
5+#include <dbghelp.h>
6+
7+#pragma once
8+#pragma comment(lib, "dbghelp.lib")
9+
10+extern FileStream fs;
11+
12+#define SEH_THREAD(func, name) \
13+{ \
14+ __try \
15+ { \
16+ return func(thread); \
17+ } __except(SEHdump(GetExceptionInformation()), EXCEPTION_EXECUTE_HANDLER) \
18+ { \
19+ } \
20+} \
21+
22+void SEHdump(_EXCEPTION_POINTERS *);
23+
24+#endif
--- a/PeerCast.root/PeerCast/ui/win32/simple/Simple.cpp
+++ b/PeerCast.root/PeerCast/ui/win32/simple/Simple.cpp
@@ -408,225 +408,55 @@ int APIENTRY WinMain(HINSTANCE hInstance,
408408 int nCmdShow)
409409 {
410410 // SEH handling
411+ _EXCEPTION_POINTERS *lpExcept;
411412 __try
412413 {
413-#if 0
414-#ifdef _DEBUG
415- // memory leak check
416- ::_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
417-#endif
418-
419- char tmpURL[8192];
420- tmpURL[0]=0;
421- char *chanURL=NULL;
422-
423- hInst = hInstance;
424-
425- version_ex = 1; // PP版拡張機能を無効に←大嘘。バージョン表記をEXに
426-
427- iniFileName.set(".\\peercast.ini");
428-
429- WIN32_FIND_DATA fd; //JP-EX
430- HANDLE hFind; //JP-EX
431-
432- OSVERSIONINFO osInfo; //JP-EX
433- osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); //JP-EX
434- GetVersionEx(&osInfo);
435- if (osInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
436- winDistinctionNT = true;
437- else
438- winDistinctionNT = false;
439-
440- // off by default now
441- showGUI = false;
442-
443- if (strlen(lpCmdLine) > 0)
444- {
445- char *p;
446- if ((p = strstr(lpCmdLine,"-inifile"))!=NULL)
447- iniFileName.setFromString(p+8);
448-
449- if (strstr(lpCmdLine,"-zen"))
450- showGUI = false;
451-
452- if (strstr(lpCmdLine,"-multi"))
453- allowMulti = true;
454-
455- if (strstr(lpCmdLine,"-kill"))
456- killMe = true;
457-
458- if ((p = strstr(lpCmdLine,"-url"))!=NULL)
459- {
460- p+=4;
461- while (*p)
462- {
463- if (*p=='"')
464- {
465- p++;
466- break;
467- }
468- if (*p != ' ')
469- break;
470- p++;
471- }
472- if (*p)
473- strncpy(tmpURL,p,sizeof(tmpURL)-1);
474- }
475- }
476-
477- // get current path
478- {
479- exePath = iniFileName;
480- char *s = exePath.cstr();
481- char *end = NULL;
482- while (*s)
483- {
484- if (*s++ == '\\')
485- end = s;
486- }
487- if (end)
488- *end = 0;
489- }
490-
491-
492- if (strnicmp(tmpURL,"peercast://",11)==0)
493- {
494- if (strnicmp(tmpURL+11,"pls/",4)==0)
495- chanURL = tmpURL+11+4;
496- else
497- chanURL = tmpURL+11;
498- showGUI = false;
499- }
500-
501-
502- MSG msg;
503- HACCEL hAccelTable;
504-
505- // Initialize global strings
506- //LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
507- //LoadString(hInstance, IDC_APP_TITLE, szWindowClass, MAX_LOADSTRING);
414+ WinMainDummy(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
508415
509- strcpy(szTitle,"PeerCast");
510- strcpy(szWindowClass,"PeerCast");
511- strcpy(szWindowClass2,"Main");
416+ } __except(lpExcept = GetExceptionInformation(), EXCEPTION_EXECUTE_HANDLER)
417+ {
418+ DWORD nParams;
512419
513- if (!allowMulti)
420+ fs.openWriteReplace(".\\dump.txt");
421+ fs.writeLine("Exception Point: WinMain");
422+ fs.write("Exception: ", 11);
423+ switch (lpExcept->ExceptionRecord->ExceptionCode)
514424 {
515- HANDLE mutex = CreateMutex(NULL,TRUE,szWindowClass);
516-
517- if (GetLastError() == ERROR_ALREADY_EXISTS)
518- {
519- HWND oldWin = FindWindow(szWindowClass,NULL);
520- if (oldWin)
521- {
522- //SendMessage(oldWin,WM_SHOWGUI,0,0);
523- if (killMe)
524- {
525- SendMessage(oldWin,WM_DESTROY,0,0);
526- return 0;
527- }
528-
529- if (chanURL)
530- {
531- COPYDATASTRUCT copy;
532- copy.dwData = WM_PLAYCHANNEL;
533- copy.cbData = strlen(chanURL)+1; // plus null term
534- copy.lpData = chanURL;
535- SendMessage(oldWin,WM_COPYDATA,NULL,(LPARAM)&copy);
536- }else{
537- if (showGUI)
538- SendMessage(oldWin,WM_SHOWGUI,0,0);
539- }
540- }
541- return 0;
542- }
543- }
544-
545- if (killMe)
546- return 0;
547-
548- MyRegisterClass(hInstance);
549- MyRegisterClass2(hInstance);
550-
551- // Perform application initialization:
552- if (!InitInstance (hInstance, nCmdShow))
553- return FALSE;
554-
555- peercastInst = new MyPeercastInst();
556- peercastApp = new MyPeercastApp();
557-
558- peercastInst->init();
559-
560- LOG_DEBUG("Set OS Type: %s",winDistinctionNT?"WinNT":"Win9x");
425+ case EXCEPTION_ACCESS_VIOLATION:
426+ fs.writeLine("Access violation");
427+ break;
561428
562- if (peercastApp->clearTemp()) //JP-EX
563- {
564- DeleteFile("play.pls");
565- hFind = FindFirstFile("*.asx",&fd);
566- if (hFind != INVALID_HANDLE_VALUE)
567- {
568- do
569- {
570- DeleteFile((char *)&fd.cFileName);
571- }
572- while (FindNextFile(hFind,&fd));
429+ case EXCEPTION_FLT_DIVIDE_BY_ZERO:
430+ case EXCEPTION_INT_DIVIDE_BY_ZERO:
431+ fs.writeLine("Divide by zero");
432+ break;
573433
574- FindClose(hFind);
575- }
576- }
434+ case EXCEPTION_STACK_OVERFLOW:
435+ fs.writeLine("Stack overflow");
436+ break;
577437
578- if (chanURL)
579- {
580- ChanInfo info;
581- servMgr->procConnectArgs(chanURL,info);
582- chanMgr->findAndPlayChannel(info,false);
438+ default:
439+ fs.writeLong(lpExcept->ExceptionRecord->ExceptionCode);
440+ fs.writeLine("");
583441 }
584442
585- hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SIMPLE);
586-
587- // setup menu notifes
588- int mask = peercastInst->getNotifyMask();
589- if (mask & ServMgr::NT_PEERCAST)
590- CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_PEERCAST,MF_CHECKED|MF_BYCOMMAND);
591- if (mask & ServMgr::NT_BROADCASTERS)
592- CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_BROADCASTERS,MF_CHECKED|MF_BYCOMMAND);
593- if (mask & ServMgr::NT_TRACKINFO)
594- CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_TRACKINFO,MF_CHECKED|MF_BYCOMMAND);
443+ fs.writeLineF("Address: %p", lpExcept->ExceptionRecord->ExceptionAddress);
595444
596- if (servMgr->startWithGui)
445+ fs.writeLine("Additional information:");
446+ nParams = lpExcept->ExceptionRecord->NumberParameters;
447+ for (unsigned i=0; i<nParams; ++i)
597448 {
598- createGUI((HWND)0);
449+ fs.writeLineF("%d: %lu", i, lpExcept->ExceptionRecord->ExceptionInformation[i]);
599450 }
451+ fs.close();
600452
601- // Main message loop:
602- while (GetMessage(&msg, NULL, 0, 0))
603- {
604- if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
605- {
606- TranslateMessage(&msg);
607- DispatchMessage(&msg);
608- }
609- }
610-
611- Shell_NotifyIcon(NIM_DELETE, (NOTIFYICONDATA*)&trayIcon);
612-
613- peercastInst->saveSettings();
614- peercastInst->quit();
615-
616- Gdiplus::GdiplusShutdown(gdiplusToken);
617453
618- return msg.wParam;
619-#endif
620- WinMainDummy(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
621-
622- } __except(EXCEPTION_EXECUTE_HANDLER)
623- {
624454 fs.openWriteReplace(".\\dump.html");
625455 sys->logBuf->dumpHTML(fs);
626456 fs.close();
627457
628458 MessageBox(NULL, "一般保護違反の為、プログラムは強制終了されます。\n"
629- "問題解決のためにダンプデータ(dump.html)を提供してください。", "SEH",
459+ "問題解決のためにダンプデータ(dump.html, dump.txt)を提供してください。", "SEH",
630460 MB_OK|MB_ICONWARNING);
631461
632462 return GetExceptionCode();
--- a/PeerCast.root/PeerCast/ui/win32/simple/Simple.vcproj
+++ b/PeerCast.root/PeerCast/ui/win32/simple/Simple.vcproj
@@ -168,6 +168,7 @@
168168 BrowseInformation="1"
169169 WarningLevel="3"
170170 SuppressStartupBanner="true"
171+ DebugInformationFormat="3"
171172 />
172173 <Tool
173174 Name="VCManagedResourceCompilerTool"
@@ -187,7 +188,9 @@
187188 LinkIncremental="1"
188189 SuppressStartupBanner="true"
189190 AdditionalLibraryDirectories="&quot;C:\Visual Studio Projects\PeCa-IMAS7651\core\win32\lib\Release&quot;"
191+ GenerateDebugInformation="true"
190192 ProgramDatabaseFile=".\Release/PeerCast.pdb"
193+ GenerateMapFile="true"
191194 SubSystem="2"
192195 RandomizedBaseAddress="1"
193196 DataExecutionPrevention="0"
--- a/c:/Git/PeerCast.root/PeerCast/core/common/channel.cpp
+++ b/c:/Git/PeerCast.root/PeerCast/core/common/channel.cpp
@@ -50,6 +50,8 @@
5050 #define new DEBUG_NEW
5151 #endif
5252
53+#include "win32/seh.h"
54+
5355 // -----------------------------------
5456 char *Channel::srcTypes[]=
5557 {
@@ -423,7 +425,7 @@ void Channel::checkReadDelay(unsigned int len)
423425
424426
425427 // -----------------------------------
426-THREAD_PROC Channel::stream(ThreadInfo *thread)
428+THREAD_PROC Channel::streamMain(ThreadInfo *thread)
427429 {
428430 // thread->lock();
429431
@@ -483,10 +485,16 @@ THREAD_PROC Channel::stream(ThreadInfo *thread)
483485 ch->endThread(true);
484486 }
485487 return 0;
488+}
489+
490+// -----------------------------------
491+THREAD_PROC Channel::stream(ThreadInfo *thread)
492+{
493+ SEH_THREAD(streamMain, Channel::stream);
486494 }
487495
488496 // -----------------------------------
489-THREAD_PROC Channel::waitFinish(ThreadInfo *thread)
497+THREAD_PROC Channel::waitFinishMain(ThreadInfo *thread)
490498 {
491499 Channel *ch = (Channel*)thread->data;
492500 LOG_DEBUG("Wait channel finish");
@@ -507,6 +515,13 @@ THREAD_PROC Channel::waitFinish(ThreadInfo *thread)
507515 }
508516
509517 // -----------------------------------
518+THREAD_PROC Channel::waitFinish(ThreadInfo *thread)
519+{
520+ SEH_THREAD(waitFinishMain, Channel::waitFinish);
521+}
522+
523+
524+// -----------------------------------
510525 bool Channel::acceptGIV(ClientSocket *givSock)
511526 {
512527 if (!pushSock)
@@ -3041,7 +3056,7 @@ public:
30413056 bool keep;
30423057 };
30433058 // -----------------------------------
3044-THREAD_PROC findAndPlayChannelProc(ThreadInfo *th)
3059+THREAD_PROC findAndPlayChannelProcMain(ThreadInfo *th)
30453060 {
30463061 ChanFindInfo *cfi = (ChanFindInfo *)th;
30473062
@@ -3069,6 +3084,13 @@ THREAD_PROC findAndPlayChannelProc(ThreadInfo *th)
30693084 delete cfi;
30703085 return 0;
30713086 }
3087+
3088+// -----------------------------------
3089+THREAD_PROC findAndPlayChannelProc(ThreadInfo *thread)
3090+{
3091+ SEH_THREAD(findAndPlayChannelProcMain, findAndPlayChannel);
3092+}
3093+
30723094 // -----------------------------------
30733095 void ChanMgr::findAndPlayChannel(ChanInfo &info, bool keep)
30743096 {
--- a/c:/Git/PeerCast.root/PeerCast/core/common/channel.h
+++ b/c:/Git/PeerCast.root/PeerCast/core/common/channel.h
@@ -443,8 +443,10 @@ public:
443443 bool isIdle() {return isActive() && (status==S_IDLE);}
444444
445445 static THREAD_PROC stream(ThreadInfo *);
446+ static THREAD_PROC streamMain(ThreadInfo *);
446447
447448 static THREAD_PROC waitFinish(ThreadInfo *);
449+ static THREAD_PROC waitFinishMain(ThreadInfo *);
448450
449451 void setStatus(STATUS s);
450452 const char *getSrcTypeStr() {return srcTypes[srcType];}
--- a/c:/Git/PeerCast.root/PeerCast/core/common/servent.cpp
+++ b/c:/Git/PeerCast.root/PeerCast/core/common/servent.cpp
@@ -40,6 +40,8 @@
4040 #define new DEBUG_NEW
4141 #endif
4242
43+#include "win32/seh.h"
44+
4345
4446 const int DIRECT_WRITE_TIMEOUT = 60;
4547
@@ -1668,7 +1670,7 @@ void Servent::processRoot()
16681670 }
16691671
16701672 // -----------------------------------
1671-int Servent::givProc(ThreadInfo *thread)
1673+int Servent::givProcMain(ThreadInfo *thread)
16721674 {
16731675 // thread->lock();
16741676 Servent *sv = (Servent*)thread->data;
@@ -1688,6 +1690,12 @@ int Servent::givProc(ThreadInfo *thread)
16881690 }
16891691
16901692 // -----------------------------------
1693+int Servent::givProc(ThreadInfo *thread)
1694+{
1695+ SEH_THREAD(givProcMain, Servent::givProc);
1696+}
1697+
1698+// -----------------------------------
16911699 void Servent::handshakeOutgoingPCP(AtomStream &atom, Host &rhost, GnuID &rid, String &agent, bool isTrusted)
16921700 {
16931701
@@ -2128,7 +2136,7 @@ void Servent::processIncomingPCP(bool suggestOthers)
21282136 }
21292137
21302138 // -----------------------------------
2131-int Servent::outgoingProc(ThreadInfo *thread)
2139+int Servent::outgoingProcMain(ThreadInfo *thread)
21322140 {
21332141 // thread->lock();
21342142 LOG_DEBUG("COUT started");
@@ -2309,7 +2317,12 @@ int Servent::outgoingProc(ThreadInfo *thread)
23092317 return 0;
23102318 }
23112319 // -----------------------------------
2312-int Servent::incomingProc(ThreadInfo *thread)
2320+int Servent::outgoingProc(ThreadInfo *thread)
2321+{
2322+ SEH_THREAD(outgoingProcMain, Servent::outgoingProc);
2323+}
2324+// -----------------------------------
2325+int Servent::incomingProcMain(ThreadInfo *thread)
23132326 {
23142327 // thread->lock();
23152328
@@ -2342,6 +2355,11 @@ int Servent::incomingProc(ThreadInfo *thread)
23422355 return 0;
23432356 }
23442357 // -----------------------------------
2358+int Servent::incomingProc(ThreadInfo *thread)
2359+{
2360+ SEH_THREAD(incomingProcMain, Servent::incomingProc);
2361+}
2362+// -----------------------------------
23452363 void Servent::processServent()
23462364 {
23472365 setStatus(S_HANDSHAKE);
@@ -2986,7 +3004,7 @@ void Servent::sendPCPChannel()
29863004 }
29873005
29883006 // -----------------------------------
2989-int Servent::serverProc(ThreadInfo *thread)
3007+int Servent::serverProcMain(ThreadInfo *thread)
29903008 {
29913009 // thread->lock();
29923010
@@ -3053,6 +3071,12 @@ int Servent::serverProc(ThreadInfo *thread)
30533071 sys->endThread(thread);
30543072 return 0;
30553073 }
3074+
3075+// -----------------------------------
3076+int Servent::serverProc(ThreadInfo *thread)
3077+{
3078+ SEH_THREAD(serverProcMain, Servent::serverProc);
3079+}
30563080
30573081 // -----------------------------------
30583082 bool Servent::writeVariable(Stream &s, const String &var)
--- a/c:/Git/PeerCast.root/PeerCast/core/common/servent.h
+++ b/c:/Git/PeerCast.root/PeerCast/core/common/servent.h
@@ -144,9 +144,13 @@ public:
144144
145145 // static funcs that do the actual work in the servent thread
146146 static THREAD_PROC serverProc(ThreadInfo *);
147+ static THREAD_PROC serverProcMain(ThreadInfo *);
147148 static THREAD_PROC outgoingProc(ThreadInfo *);
149+ static THREAD_PROC outgoingProcMain(ThreadInfo *);
148150 static THREAD_PROC incomingProc(ThreadInfo *);
151+ static THREAD_PROC incomingProcMain(ThreadInfo *);
149152 static THREAD_PROC givProc(ThreadInfo *);
153+ static THREAD_PROC givProcMain(ThreadInfo *);
150154 static THREAD_PROC pcpProc(ThreadInfo *);
151155 static THREAD_PROC fetchProc(ThreadInfo *);
152156
--- a/c:/Git/PeerCast.root/PeerCast/core/common/version2.h
+++ b/c:/Git/PeerCast.root/PeerCast/core/common/version2.h
@@ -44,9 +44,9 @@ extern int version_ex; // PP
4444 #if 1 /* for VP extend version */
4545 //#define VERSION_EX 1
4646 static const char *PCP_CLIENT_VERSION_EX_PREFIX = "IM"; // 2bytes only
47-static const int PCP_CLIENT_VERSION_EX_NUMBER = 28;
48-static const char *PCX_AGENTEX = "PeerCast/0.1218(IM0028-3)";
49-static const char *PCX_VERSTRING_EX = "v0.1218(IM0028-3)";
47+static const int PCP_CLIENT_VERSION_EX_NUMBER = 29;
48+static const char *PCX_AGENTEX = "PeerCast/0.1218(IM0029)";
49+static const char *PCX_VERSTRING_EX = "v0.1218(IM0029)";
5050 #endif
5151
5252 // ------------------------------------------------
--- a/c:/Git/PeerCast.root/PeerCast/core/win32/lib/corelib.vcproj
+++ b/c:/Git/PeerCast.root/PeerCast/core/win32/lib/corelib.vcproj
@@ -212,6 +212,7 @@
212212 ProgramDataBaseFileName=".\Release/"
213213 WarningLevel="3"
214214 SuppressStartupBanner="true"
215+ DebugInformationFormat="3"
215216 />
216217 <Tool
217218 Name="VCManagedResourceCompilerTool"
@@ -1374,6 +1375,10 @@
13741375 Name="Win32 Source"
13751376 >
13761377 <File
1378+ RelativePath="..\seh.cpp"
1379+ >
1380+ </File>
1381+ <File
13771382 RelativePath="..\wsocket.cpp"
13781383 >
13791384 <FileConfiguration
@@ -1458,6 +1463,10 @@
14581463 Name="Win32 Includes"
14591464 >
14601465 <File
1466+ RelativePath="..\seh.h"
1467+ >
1468+ </File>
1469+ <File
14611470 RelativePath="..\wsocket.h"
14621471 >
14631472 </File>
--- /dev/null
+++ b/c:/Git/PeerCast.root/PeerCast/core/win32/seh.cpp
@@ -0,0 +1,41 @@
1+#include "win32/seh.h"
2+
3+void SEHdump(_EXCEPTION_POINTERS *lpExcept)
4+{
5+ // crash dump
6+ MINIDUMP_EXCEPTION_INFORMATION minidumpInfo;
7+ HANDLE hFile;
8+ BOOL dump = FALSE;
9+
10+ minidumpInfo.ThreadId = GetCurrentThreadId();
11+ minidumpInfo.ExceptionPointers = lpExcept;
12+ minidumpInfo.ClientPointers = FALSE;
13+
14+ hFile = CreateFile(".\\dump.dmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
15+ if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE))
16+ {
17+ dump = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile,
18+ (MINIDUMP_TYPE)(MiniDumpWithIndirectlyReferencedMemory|MiniDumpScanMemory),
19+ &minidumpInfo, NULL, NULL);
20+ CloseHandle(hFile);
21+ }
22+
23+
24+ // dump peercast's log
25+ fs.openWriteReplace(".\\dump.html");
26+ sys->logBuf->dumpHTML(fs);
27+ fs.close();
28+ if (dump)
29+ {
30+ MessageBox(NULL, "一般保護違反の為、プログラムは強制終了されます。\n"
31+ "問題解決のためダンプデータ(dump.html, dump.dmp)を提供してください。", "SEH",
32+ MB_OK|MB_ICONWARNING);
33+ } else
34+ {
35+ MessageBox(NULL, "一般保護違反の為、プログラムは強制終了されます。\n"
36+ "問題解決のためにダンプデータ(dump.html)を提供してください。", "SEH",
37+ MB_OK|MB_ICONWARNING);
38+ }
39+
40+ ::exit(lpExcept->ExceptionRecord->ExceptionCode);
41+}
--- /dev/null
+++ b/c:/Git/PeerCast.root/PeerCast/core/win32/seh.h
@@ -0,0 +1,24 @@
1+#ifndef _SEH_H_
2+#define _SEH_H_
3+
4+#include "stream.h"
5+#include <dbghelp.h>
6+
7+#pragma once
8+#pragma comment(lib, "dbghelp.lib")
9+
10+extern FileStream fs;
11+
12+#define SEH_THREAD(func, name) \
13+{ \
14+ __try \
15+ { \
16+ return func(thread); \
17+ } __except(SEHdump(GetExceptionInformation()), EXCEPTION_EXECUTE_HANDLER) \
18+ { \
19+ } \
20+} \
21+
22+void SEHdump(_EXCEPTION_POINTERS *);
23+
24+#endif
--- a/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.cpp
+++ b/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.cpp
@@ -408,225 +408,55 @@ int APIENTRY WinMain(HINSTANCE hInstance,
408408 int nCmdShow)
409409 {
410410 // SEH handling
411+ _EXCEPTION_POINTERS *lpExcept;
411412 __try
412413 {
413-#if 0
414-#ifdef _DEBUG
415- // memory leak check
416- ::_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
417-#endif
418-
419- char tmpURL[8192];
420- tmpURL[0]=0;
421- char *chanURL=NULL;
422-
423- hInst = hInstance;
424-
425- version_ex = 1; // PP版拡張機能を無効に←大嘘。バージョン表記をEXに
426-
427- iniFileName.set(".\\peercast.ini");
428-
429- WIN32_FIND_DATA fd; //JP-EX
430- HANDLE hFind; //JP-EX
431-
432- OSVERSIONINFO osInfo; //JP-EX
433- osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); //JP-EX
434- GetVersionEx(&osInfo);
435- if (osInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
436- winDistinctionNT = true;
437- else
438- winDistinctionNT = false;
439-
440- // off by default now
441- showGUI = false;
442-
443- if (strlen(lpCmdLine) > 0)
444- {
445- char *p;
446- if ((p = strstr(lpCmdLine,"-inifile"))!=NULL)
447- iniFileName.setFromString(p+8);
448-
449- if (strstr(lpCmdLine,"-zen"))
450- showGUI = false;
451-
452- if (strstr(lpCmdLine,"-multi"))
453- allowMulti = true;
454-
455- if (strstr(lpCmdLine,"-kill"))
456- killMe = true;
457-
458- if ((p = strstr(lpCmdLine,"-url"))!=NULL)
459- {
460- p+=4;
461- while (*p)
462- {
463- if (*p=='"')
464- {
465- p++;
466- break;
467- }
468- if (*p != ' ')
469- break;
470- p++;
471- }
472- if (*p)
473- strncpy(tmpURL,p,sizeof(tmpURL)-1);
474- }
475- }
476-
477- // get current path
478- {
479- exePath = iniFileName;
480- char *s = exePath.cstr();
481- char *end = NULL;
482- while (*s)
483- {
484- if (*s++ == '\\')
485- end = s;
486- }
487- if (end)
488- *end = 0;
489- }
490-
491-
492- if (strnicmp(tmpURL,"peercast://",11)==0)
493- {
494- if (strnicmp(tmpURL+11,"pls/",4)==0)
495- chanURL = tmpURL+11+4;
496- else
497- chanURL = tmpURL+11;
498- showGUI = false;
499- }
500-
501-
502- MSG msg;
503- HACCEL hAccelTable;
504-
505- // Initialize global strings
506- //LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
507- //LoadString(hInstance, IDC_APP_TITLE, szWindowClass, MAX_LOADSTRING);
414+ WinMainDummy(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
508415
509- strcpy(szTitle,"PeerCast");
510- strcpy(szWindowClass,"PeerCast");
511- strcpy(szWindowClass2,"Main");
416+ } __except(lpExcept = GetExceptionInformation(), EXCEPTION_EXECUTE_HANDLER)
417+ {
418+ DWORD nParams;
512419
513- if (!allowMulti)
420+ fs.openWriteReplace(".\\dump.txt");
421+ fs.writeLine("Exception Point: WinMain");
422+ fs.write("Exception: ", 11);
423+ switch (lpExcept->ExceptionRecord->ExceptionCode)
514424 {
515- HANDLE mutex = CreateMutex(NULL,TRUE,szWindowClass);
516-
517- if (GetLastError() == ERROR_ALREADY_EXISTS)
518- {
519- HWND oldWin = FindWindow(szWindowClass,NULL);
520- if (oldWin)
521- {
522- //SendMessage(oldWin,WM_SHOWGUI,0,0);
523- if (killMe)
524- {
525- SendMessage(oldWin,WM_DESTROY,0,0);
526- return 0;
527- }
528-
529- if (chanURL)
530- {
531- COPYDATASTRUCT copy;
532- copy.dwData = WM_PLAYCHANNEL;
533- copy.cbData = strlen(chanURL)+1; // plus null term
534- copy.lpData = chanURL;
535- SendMessage(oldWin,WM_COPYDATA,NULL,(LPARAM)&copy);
536- }else{
537- if (showGUI)
538- SendMessage(oldWin,WM_SHOWGUI,0,0);
539- }
540- }
541- return 0;
542- }
543- }
544-
545- if (killMe)
546- return 0;
547-
548- MyRegisterClass(hInstance);
549- MyRegisterClass2(hInstance);
550-
551- // Perform application initialization:
552- if (!InitInstance (hInstance, nCmdShow))
553- return FALSE;
554-
555- peercastInst = new MyPeercastInst();
556- peercastApp = new MyPeercastApp();
557-
558- peercastInst->init();
559-
560- LOG_DEBUG("Set OS Type: %s",winDistinctionNT?"WinNT":"Win9x");
425+ case EXCEPTION_ACCESS_VIOLATION:
426+ fs.writeLine("Access violation");
427+ break;
561428
562- if (peercastApp->clearTemp()) //JP-EX
563- {
564- DeleteFile("play.pls");
565- hFind = FindFirstFile("*.asx",&fd);
566- if (hFind != INVALID_HANDLE_VALUE)
567- {
568- do
569- {
570- DeleteFile((char *)&fd.cFileName);
571- }
572- while (FindNextFile(hFind,&fd));
429+ case EXCEPTION_FLT_DIVIDE_BY_ZERO:
430+ case EXCEPTION_INT_DIVIDE_BY_ZERO:
431+ fs.writeLine("Divide by zero");
432+ break;
573433
574- FindClose(hFind);
575- }
576- }
434+ case EXCEPTION_STACK_OVERFLOW:
435+ fs.writeLine("Stack overflow");
436+ break;
577437
578- if (chanURL)
579- {
580- ChanInfo info;
581- servMgr->procConnectArgs(chanURL,info);
582- chanMgr->findAndPlayChannel(info,false);
438+ default:
439+ fs.writeLong(lpExcept->ExceptionRecord->ExceptionCode);
440+ fs.writeLine("");
583441 }
584442
585- hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SIMPLE);
586-
587- // setup menu notifes
588- int mask = peercastInst->getNotifyMask();
589- if (mask & ServMgr::NT_PEERCAST)
590- CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_PEERCAST,MF_CHECKED|MF_BYCOMMAND);
591- if (mask & ServMgr::NT_BROADCASTERS)
592- CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_BROADCASTERS,MF_CHECKED|MF_BYCOMMAND);
593- if (mask & ServMgr::NT_TRACKINFO)
594- CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_TRACKINFO,MF_CHECKED|MF_BYCOMMAND);
443+ fs.writeLineF("Address: %p", lpExcept->ExceptionRecord->ExceptionAddress);
595444
596- if (servMgr->startWithGui)
445+ fs.writeLine("Additional information:");
446+ nParams = lpExcept->ExceptionRecord->NumberParameters;
447+ for (unsigned i=0; i<nParams; ++i)
597448 {
598- createGUI((HWND)0);
449+ fs.writeLineF("%d: %lu", i, lpExcept->ExceptionRecord->ExceptionInformation[i]);
599450 }
451+ fs.close();
600452
601- // Main message loop:
602- while (GetMessage(&msg, NULL, 0, 0))
603- {
604- if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
605- {
606- TranslateMessage(&msg);
607- DispatchMessage(&msg);
608- }
609- }
610-
611- Shell_NotifyIcon(NIM_DELETE, (NOTIFYICONDATA*)&trayIcon);
612-
613- peercastInst->saveSettings();
614- peercastInst->quit();
615-
616- Gdiplus::GdiplusShutdown(gdiplusToken);
617453
618- return msg.wParam;
619-#endif
620- WinMainDummy(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
621-
622- } __except(EXCEPTION_EXECUTE_HANDLER)
623- {
624454 fs.openWriteReplace(".\\dump.html");
625455 sys->logBuf->dumpHTML(fs);
626456 fs.close();
627457
628458 MessageBox(NULL, "一般保護違反の為、プログラムは強制終了されます。\n"
629- "問題解決のためにダンプデータ(dump.html)を提供してください。", "SEH",
459+ "問題解決のためにダンプデータ(dump.html, dump.txt)を提供してください。", "SEH",
630460 MB_OK|MB_ICONWARNING);
631461
632462 return GetExceptionCode();
--- a/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.vcproj
+++ b/c:/Git/PeerCast.root/PeerCast/ui/win32/simple/Simple.vcproj
@@ -168,6 +168,7 @@
168168 BrowseInformation="1"
169169 WarningLevel="3"
170170 SuppressStartupBanner="true"
171+ DebugInformationFormat="3"
171172 />
172173 <Tool
173174 Name="VCManagedResourceCompilerTool"
@@ -187,7 +188,9 @@
187188 LinkIncremental="1"
188189 SuppressStartupBanner="true"
189190 AdditionalLibraryDirectories="&quot;C:\Visual Studio Projects\PeCa-IMAS7651\core\win32\lib\Release&quot;"
191+ GenerateDebugInformation="true"
190192 ProgramDatabaseFile=".\Release/PeerCast.pdb"
193+ GenerateMapFile="true"
191194 SubSystem="2"
192195 RandomizedBaseAddress="1"
193196 DataExecutionPrevention="0"
Show on old repository browser