ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

abort.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:   See COPYING in the top level directory
00003  * PROJECT:     ReactOS system libraries
00004  * FILE:        lib/crt/stdlib/abort.c
00005  * PURPOSE:     Abnormal termination message
00006  * PROGRAMER:   Jon Griffiths
00007  *              Samuel Serapión
00008  */
00009 
00010 /* based on wine exit.c */
00011 
00012 #include <precomp.h>
00013 #include <signal.h>
00014 #include <internal/wine/msvcrt.h>
00015 
00016 extern int msvcrt_error_mode;
00017 extern int __app_type;
00018 unsigned int msvcrt_abort_behavior =  MSVCRT__WRITE_ABORT_MSG | MSVCRT__CALL_REPORTFAULT;
00019 
00020 /* avoid linking to user32 */
00021 typedef HWND (WINAPI *GetActiveWindowPtr)(void);
00022 static GetActiveWindowPtr pGetActiveWindow = NULL;
00023 typedef int (WINAPI *MessageBoxIndirectWPtr)(const MSGBOXPARAMSW*);
00024 static MessageBoxIndirectWPtr pMessageBoxIndirectW = NULL;
00025 
00026 static void DoMessageBoxW(const wchar_t *lead, const wchar_t *message)
00027 {
00028   const char szMsgBoxTitle[] = "ReactOS C++ Runtime Library";
00029   const wchar_t message_format[] = {'%','s','\n','\n','P','r','o','g','r','a','m',':',' ','%','s','\n',
00030     '%','s','\n','\n','P','r','e','s','s',' ','O','K',' ','t','o',' ','e','x','i','t',' ','t','h','e',' ',
00031     'p','r','o','g','r','a','m',',',' ','o','r',' ','C','a','n','c','e','l',' ','t','o',' ','s','t','a','r','t',' ',
00032     't','h','e',' ','d','e','b','b','u','g','e','r','.','\n',0};
00033 
00034   MSGBOXPARAMSW msgbox;
00035   wchar_t text[2048];
00036   INT ret;
00037 
00038   _snwprintf(text,sizeof(text),message_format, lead, _wpgmptr, message);
00039 
00040   msgbox.cbSize = sizeof(msgbox);
00041   msgbox.hwndOwner = pGetActiveWindow();
00042   msgbox.hInstance = 0;
00043   msgbox.lpszText = (LPCWSTR)text;
00044   msgbox.lpszCaption = (LPCWSTR)szMsgBoxTitle;
00045   msgbox.dwStyle = MB_OKCANCEL|MB_ICONERROR;
00046   msgbox.lpszIcon = NULL;
00047   msgbox.dwContextHelpId = 0;
00048   msgbox.lpfnMsgBoxCallback = NULL;
00049   msgbox.dwLanguageId = LANG_NEUTRAL;
00050 
00051   ret = pMessageBoxIndirectW(&msgbox);
00052   if (ret == IDCANCEL)
00053     DebugBreak();
00054 }
00055 
00056 static void DoMessageBox(const char *lead, const char *message)
00057 {
00058   wchar_t leadW[1024], messageW[1024];
00059   HMODULE huser32 = LoadLibrary("user32.dll");
00060 
00061   if(huser32) {
00062       pGetActiveWindow = (GetActiveWindowPtr)GetProcAddress(huser32, "GetActiveWindow");
00063       pMessageBoxIndirectW = (MessageBoxIndirectWPtr)GetProcAddress(huser32, "MessageBoxIndirectW");
00064 
00065       if(!pGetActiveWindow || !pMessageBoxIndirectW) {
00066           FreeLibrary(huser32);
00067           ERR("GetProcAddress failed!\n");
00068           return;
00069       }
00070   }
00071   else
00072   {
00073       ERR("Loading user32 failed!\n");
00074       return;
00075   }
00076 
00077   mbstowcs(leadW, lead, 1024);
00078   mbstowcs(messageW, message, 1024);
00079 
00080   DoMessageBoxW(leadW, messageW);
00081   FreeLibrary(huser32); 
00082 }
00083 
00084 /*
00085  * @implemented
00086  */
00087 void abort()
00088 {
00089   if (msvcrt_abort_behavior & MSVCRT__WRITE_ABORT_MSG)
00090   {
00091     if ((msvcrt_error_mode == MSVCRT__OUT_TO_MSGBOX) ||
00092        ((msvcrt_error_mode == MSVCRT__OUT_TO_DEFAULT) && (__app_type == 2)))
00093     {
00094       DoMessageBox("Runtime error!", "abnormal program termination");
00095     }
00096     else
00097       _cputs("\nabnormal program termination\n");
00098   }
00099   raise(SIGABRT);
00100   /* in case raise() returns */
00101   _exit(3);
00102 }
00103 
00104 unsigned int CDECL _set_abort_behavior(unsigned int flags, unsigned int mask)
00105 {
00106   unsigned int old = msvcrt_abort_behavior;
00107 
00108   TRACE("%x, %x\n", flags, mask);
00109   if (mask & MSVCRT__CALL_REPORTFAULT)
00110     FIXME("_WRITE_CALL_REPORTFAULT unhandled\n");
00111 
00112   msvcrt_abort_behavior = (msvcrt_abort_behavior & ~mask) | (flags & mask);
00113   return old;
00114 }

Generated on Sun May 27 2012 04:36:37 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.