Beispiel #1
0
static int Sys_Main(int argc, char **argv)
{
    // fix current directory to point to the basedir
    if (!fix_current_directory()) {
        return 1;
    }

#if (_MSC_VER >= 1400)
    // work around strftime given invalid format string
    // killing the whole f*****g process :((
    _set_invalid_parameter_handler(msvcrt_sucks);
#endif

    Qcommon_Init(argc, argv);

    // main program loop
    while (1) {
        Qcommon_Frame();
        if (shouldExit) {
#if USE_WINSVC
            if (shouldExit == SE_FULL)
#endif
                Com_Quit(NULL, ERR_DISCONNECT);
            break;
        }
    }

    // may get here when our service stops
    return 0;
}
Beispiel #2
0
static void uv_init(void) {
  /* Tell Windows that we will handle critical errors. */
  SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX |
               SEM_NOOPENFILEERRORBOX);

  /* Tell the CRT to not exit the application when an invalid parameter is */
  /* passed. The main issue is that invalid FDs will trigger this behavior. */
#ifdef _WRITE_ABORT_MSG
  _set_invalid_parameter_handler(uv__crt_invalid_parameter_handler);
#endif

  /* Fetch winapi function pointers. This must be done first because other */
  /* intialization code might need these function pointers to be loaded. */
  uv_winapi_init();

  /* Initialize winsock */
  uv_winsock_init();

  /* Initialize FS */
  uv_fs_init();

  /* Initialize signal stuff */
  uv_signals_init();

  /* Initialize console */
  uv_console_init();

  /* Initialize utilities */
  uv__util_init();
}
void CCrashHandler::SetProcessExceptionHandlers()
{
	// Install top-level SEH handler
	SetUnhandledExceptionFilter(SehHandler);    

	// Catch pure virtual function calls.
	// Because there is one _purecall_handler for the whole process, 
	// calling this function immediately impacts all threads. The last 
	// caller on any thread sets the handler. 
	// http://msdn.microsoft.com/en-us/library/t296ys27.aspx
	_set_purecall_handler(PureCallHandler);    

	// Catch new operator memory allocation exceptions
	_set_new_handler(NewHandler);

	// Catch invalid parameter exceptions.
	_set_invalid_parameter_handler(InvalidParameterHandler); 

	// Set up C++ signal handlers

	//_set_abort_behavior(_CALL_REPORTFAULT,_CALL_REPORTFAULT);
 	_set_abort_behavior(_WRITE_ABORT_MSG|_CALL_REPORTFAULT, _WRITE_ABORT_MSG|_CALL_REPORTFAULT);
 	_set_abort_behavior(0, _WRITE_ABORT_MSG);

	// Catch an abnormal program termination
	signal(SIGABRT, SigabrtHandler);  

	// Catch illegal instruction handler
	signal(SIGINT, SigintHandler);     

	// Catch a termination request
	signal(SIGTERM, SigtermHandler);          

}
Beispiel #4
0
static void my_win_init(void)
{
  DBUG_ENTER("my_win_init");

#if defined(_MSC_VER)
#if _MSC_VER < 1300
  /*
    Clear the OS system variable TZ and avoid the 100% CPU usage
    Only for old versions of Visual C++
  */
  _putenv("TZ=");
#endif
#if _MSC_VER >= 1400
  /* this is required to make crt functions return -1 appropriately */
  _set_invalid_parameter_handler(my_parameter_handler);
#endif
#endif

#ifdef __MSVC_RUNTIME_CHECKS
  /*
    Install handler to send RTC (Runtime Error Check) warnings
    to log file
  */
  _RTC_SetErrorFunc(handle_rtc_failure);
#endif

  _tzset();

  win_init_registry();

  DBUG_VOID_RETURN;
}
Beispiel #5
0
void Sys_Quit (qbool restart)
{
	if (restart)
	{
#ifndef __MINGW32__
		int maxfd = 131072; // well, should be enough for everyone...

		_set_invalid_parameter_handler(myInvalidParameterHandler); // so close() does not crash our program on invalid handle...

		// close all file descriptors even stdin stdout and stderr, seems that not hurt...
		for (; maxfd > -1; maxfd--)
		{
			close(maxfd);
			closesocket(maxfd); // yeah, windows separate sockets and files, so you can't close socket with close() like on *nix.
		}

		if (execv(argv[0], com_argv) == -1)
#endif
		{
#ifdef _CONSOLE
			if (!((int)sys_nostdout.value || isdaemon))
				printf("Restart failed: (%i): %s\n", qerrno, strerror(qerrno));
#else
			if (!(COM_CheckParm("-noerrormsgbox") || isdaemon))
				MessageBox(NULL, strerror(qerrno), "Restart failed", 0 /* MB_OK */ );
#endif
			Sys_Exit(1);
		}
	}
	Sys_Exit(0);
}
ArchHooks_Win32::ArchHooks_Win32()
{
	HOOKS = this;

	/* Disable critical errors, and handle them internally.  We never want the
	 * "drive not ready", etc. dialogs to pop up. */
	SetErrorMode( SetErrorMode(0) | SEM_FAILCRITICALERRORS );

	CrashHandler::CrashHandlerHandleArgs( g_argc, g_argv );
	SetUnhandledExceptionFilter( CrashHandler::ExceptionHandler );

#if _MSC_VER >= 1400 // VC8
	_set_invalid_parameter_handler( InvalidParameterHandler );
#endif

	/* Windows boosts priority on keyboard input, among other things.  Disable that for
	 * the main thread. */
	SetThreadPriorityBoost( GetCurrentThread(), TRUE );

	g_hInstanceMutex = CreateMutex( NULL, TRUE, PRODUCT_ID );

	g_bIsMultipleInstance = false;
	if( GetLastError() == ERROR_ALREADY_EXISTS )
		g_bIsMultipleInstance = true;
}
Beispiel #7
0
	void CDumpCatch::UnSetInvalidHandle()
	{
#if _MSC_VER >= 1400  // MSVC 2005/8
		_set_invalid_parameter_handler(m_preIph);
#endif  // _MSC_VER >= 1400
		_set_purecall_handler(m_prePch); //At application this can stop show the error message box.
	}
Beispiel #8
0
int initialiseWindows(const TRI_win_initialise_e initialiseWhat, const char* data) {


  // ............................................................................
  // The data is used to transport information from the calling function to here
  // it may be NULL (and will be in most cases)
  // ............................................................................

  switch (initialiseWhat) {

    case TRI_WIN_INITIAL_SET_DEBUG_FLAG: {
      _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF)|_CRTDBG_CHECK_ALWAYS_DF);    
      return 0;
    }

    // ...........................................................................
    // Assign a handler for invalid handles 
    // ...........................................................................

    case TRI_WIN_INITIAL_SET_INVALID_HANLE_HANDLER: { 
      newInvalidHandleHandler = InvalidParameterHandler;
      oldInvalidHandleHandler = _set_invalid_parameter_handler(newInvalidHandleHandler);
      return 0;
    }

    case TRI_WIN_INITIAL_SET_MAX_STD_IO: {
      int* newMax = (int*)(data);
      int result = _setmaxstdio(*newMax);
      if (result != *newMax) {
        return -1;
      }
      return 0;  
    }

    case TRI_WIN_INITIAL_WSASTARTUP_FUNCTION_CALL: {
      int errorCode;
      WSADATA wsaData;
      WORD wVersionRequested = MAKEWORD(2,2);
      errorCode = WSAStartup(wVersionRequested, &wsaData);
      if (errorCode != 0) {
        LOG_ERROR("Could not find a usuable Winsock DLL. WSAStartup returned an error.");
        return -1;
      }
      if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
        LOG_ERROR("Could not find a usuable Winsock DLL. WSAStartup did not return version 2.2.");
        WSACleanup();
        return -1;
      }   
      return 0;
    }

    default: {
      LOG_ERROR("Invalid windows initialisation called");
      return -1;
    }
  }

  return -1;

}
void setupSynchronousSignalHandlers() {
    std::set_terminate(myTerminate);
    std::set_new_handler(reportOutOfMemoryErrorAndExit);

    // SIGABRT is the only signal we want handled by signal handlers on both windows and posix.
    invariant(signal(SIGABRT, abruptQuit) != SIG_ERR);

#if defined(_WIN32)
    _set_purecall_handler(myPureCallHandler);
    _set_invalid_parameter_handler(myInvalidParameterHandler);
    setWindowsUnhandledExceptionFilter();
#else
    invariant(signal(SIGHUP, SIG_IGN) != SIG_ERR);
    invariant(signal(SIGUSR2, SIG_IGN) != SIG_ERR);
    invariant(signal(SIGPIPE, SIG_IGN) != SIG_ERR);

    struct sigaction addrSignals;
    memset(&addrSignals, 0, sizeof(struct sigaction));
    addrSignals.sa_sigaction = abruptQuitWithAddrSignal;
    sigemptyset(&addrSignals.sa_mask);
    addrSignals.sa_flags = SA_SIGINFO;

    // ^\ is the stronger ^C. Log and quit hard without waiting for cleanup.
    invariant(signal(SIGQUIT, abruptQuit) != SIG_ERR);

    invariant(sigaction(SIGSEGV, &addrSignals, 0) == 0);
    invariant(sigaction(SIGBUS, &addrSignals, 0) == 0);
    invariant(sigaction(SIGILL, &addrSignals, 0) == 0);
    invariant(sigaction(SIGFPE, &addrSignals, 0) == 0);

    setupSIGTRAPforGDB();
#endif
}
Beispiel #10
0
	void CDumpCatch::SetInvalidHandle()
	{
#if _MSC_VER >= 1400  // MSVC 2005/8
		m_preIph = _set_invalid_parameter_handler(MyInvalidParameterHandler);
#endif  // _MSC_VER >= 1400
		m_prePch = _set_purecall_handler(MyPureCallHandler);   //At application, this call can stop show the error message box.
	}
Beispiel #11
0
// for debug
void CUtils::Log(LPCTSTR fmt, ...)
{
	va_list ap;
	va_start(ap, fmt);
	TCHAR log[1024];
	_set_invalid_parameter_handler(invalid_parameter_handler);
	if (_vstprintf_s(log, fmt, ap) < 0)
		_tcscpy_s(log, _T("invalid format"));

	static int n = 0;
	TCHAR path[MAX_PATH];
	if (GetTempPath(MAX_PATH, path)) {
#ifndef _WIN64
		_tmakepath_s(path, NULL, path, _T("xkeylog"), _T("txt"));
#else
		_tmakepath_s(path, NULL, path, _T("xkeylog64"), _T("txt"));
#endif
	} else
		_tcscpy_s(path, _T("c:\\xkeylog.txt"));

	FILE *fp;
	_tfopen_s(&fp, path, _T("a"));
	_ftprintf(fp, _T("%8d: %s\t%s\n"), n++, AppName::GetAppName(), log);
	fclose(fp);
}
Beispiel #12
0
void DLLCALL js_PrepareToExecute(JSContext *cx, JSObject *obj, const char *filename, const char* startup_dir)
{
	JSString*	str;
	jsval		val;

	if(JS_GetProperty(cx, obj, "js", &val) && JSVAL_IS_OBJECT(val)) {
		JSObject* js = JSVAL_TO_OBJECT(val);
		char	dir[MAX_PATH+1];

		if(filename!=NULL) {
			char* p;

			if((str=JS_NewStringCopyZ(cx, filename)) != NULL)
				JS_DefineProperty(cx, js, "exec_path", STRING_TO_JSVAL(str)
					,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY);
			if((str=JS_NewStringCopyZ(cx, getfname(filename))) != NULL)
				JS_DefineProperty(cx, js, "exec_file", STRING_TO_JSVAL(str)
					,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY);
			SAFECOPY(dir,filename);
			p=getfname(dir);
			*p=0;
			if((str=JS_NewStringCopyZ(cx, dir)) != NULL)
				JS_DefineProperty(cx, js, "exec_dir", STRING_TO_JSVAL(str)
					,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY);
		}
		if(startup_dir==NULL)
			startup_dir="";
		if((str=JS_NewStringCopyZ(cx, startup_dir)) != NULL)
			JS_DefineProperty(cx, js, "startup_dir", STRING_TO_JSVAL(str)
				,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY);
	}
#if defined(_MSC_VER)
	_set_invalid_parameter_handler(msvc_invalid_parameter_handler);
#endif
}
void exception_catcher::set_process_exception_handlers()
{
    // Install top-level SEH handler
    SetUnhandledExceptionFilter(catched_seh_handler);

    // Catch pure virtual function calls.
    // Because there is one _purecall_handler for the whole process,
    // calling this function immediately impacts all threads. The last
    // caller on any thread sets the handler.
    // http://msdn.microsoft.com/en-us/library/t296ys27.aspx
    _set_purecall_handler(catched_pure_call_handler);

    // Catch new operator memory allocation exceptions
    _set_new_handler(catched_new_handler);

    // Catch invalid parameter exceptions.
    _set_invalid_parameter_handler(catched_invalid_parameter_handler);

    // Set up C++ signal handlers

    _set_abort_behavior(_CALL_REPORTFAULT, _CALL_REPORTFAULT);

    // Catch an abnormal program termination
    signal(SIGABRT, catched_sigabrt_handler);

    // Catch illegal instruction handler
    signal(SIGINT, catched_sigint_handler);

    // Catch a termination request
    signal(SIGTERM, catched_sigterm_handler);
}
int _tmain(int argc, _TCHAR* argv[])
{
	_set_invalid_parameter_handler(ReportInvaidParamentFun);
	_set_se_translator(ReportESHFun);
	CSplitInfo::GetInst()->Init(argc, argv);
	CDif2Lua::GetInst()->StartProcess();
	return 0;
}
///////////////////////////////////////////////////////////////
//
// CCrashDumpWriter::SetHandlers
//
// Static function. Initialize handlers for crash situations
//
///////////////////////////////////////////////////////////////
void CCrashDumpWriter::SetHandlers( void )
{
#ifndef MTA_DEBUG
    _set_invalid_parameter_handler( CCrashDumpWriter::HandleInvalidParameter );
    SetCrashHandlerFilter ( CCrashDumpWriter::HandleExceptionGlobal );
    CCrashDumpWriter::ReserveMemoryKBForCrashDumpProcessing( 500 );
#endif
}
Beispiel #16
0
void
gl_msvc_inval_ensure_handler (void)
{
  if (gl_msvc_inval_initialized == 0)
    {
      _set_invalid_parameter_handler (gl_msvc_invalid_parameter_handler);
      gl_msvc_inval_initialized = 1;
    }
}
Beispiel #17
0
/*
** Converts given time to string.
** This function is a wrapper function for wcsftime.
**
*/
void CMeasureTime::TimeToString(WCHAR* buf, size_t bufLen, const WCHAR* format, const struct tm* time)
{
	if (bufLen > 0)
	{
		_invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(RmNullCRTInvalidParameterHandler);
		_CrtSetReportMode(_CRT_ASSERT, 0);

		errno = 0;
		wcsftime(buf, bufLen, format, time);
		if (errno == EINVAL)
		{
			LogWithArgs(LOG_ERROR, L"Time: \"Format=%s\" invalid in [%s]", format, m_Name.c_str());
			buf[0] = 0;
		}

		_set_invalid_parameter_handler(oldHandler);
	}
}
Beispiel #18
0
/*
** Converts given time to string.
** This function is a wrapper function for wcsftime.
**
*/
void MeasureTime::TimeToString(WCHAR* buf, size_t bufLen, const WCHAR* format, const struct tm* time)
{
	if (bufLen > 0)
	{
		_invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(RmNullCRTInvalidParameterHandler);
		_CrtSetReportMode(_CRT_ASSERT, 0);

		errno = 0;
		wcsftime(buf, bufLen, format, time);
		if (errno == EINVAL)
		{
			LogErrorF(this, L"Time: \"Format=%s\" invalid", format);
			buf[0] = 0;
		}

		_set_invalid_parameter_handler(oldHandler);
	}
}
int _tmain(int argc, _TCHAR* argv[])
{
	_set_invalid_parameter_handler(ReportInvaidParamentFun);
	_set_se_translator(ReportESHFun);
	CSplitInfo::GetInst()->Init(argc, argv);
	if(!CSplitInfo::GetInst()->GetBeInternational())
		return 0;
	CUpgradeFinallyTxt::GetInst()->StartProcess();
	return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
	setlocale(LC_CTYPE,"");
	_set_invalid_parameter_handler(ReportInvaidParamentFun);
	_set_se_translator(ReportESHFun);
	CSplitInfo::GetInst()->Init(argc, argv);
	CDeleteCfg::GetInst()->StartProcess();
	system("pause");
	return 0;
}
void Logger::LogVF(Level level, const WCHAR* source, const WCHAR* format, va_list args)
{
	WCHAR* buffer = new WCHAR[1024];

	_invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(RmNullCRTInvalidParameterHandler);
	_CrtSetReportMode(_CRT_ASSERT, 0);

	errno = 0;
	_vsnwprintf_s(buffer, 1024, _TRUNCATE, format, args);
	if (errno != 0)
	{
		level = Level::Error;
		_snwprintf_s(buffer, 1024, _TRUNCATE, L"Internal error: %s", format);
	}

	_set_invalid_parameter_handler(oldHandler);

	Log(level, source, buffer);
	delete [] buffer;
}
Beispiel #22
0
PLUGIN_EXPORT LPCWSTR GetString(void* data)
{
	static WCHAR buffer[128];
	MeasureData* measure = (MeasureData*)data;

	if (measure->type == POWER_LIFETIME)
	{
		SYSTEM_POWER_STATUS sps;
		if (GetSystemPowerStatus(&sps))
		{
			// Change it to time string
			if (sps.BatteryLifeTime == -1)
			{
				return L"Unknown";
			}
			else
			{
				tm time = {0};
				time.tm_sec = sps.BatteryLifeTime % 60;
				time.tm_min = (sps.BatteryLifeTime / 60) % 60;
				time.tm_hour = sps.BatteryLifeTime / 60 / 60;

				_invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(NullCRTInvalidParameterHandler);
				_CrtSetReportMode(_CRT_ASSERT, 0);

				errno = 0;
				wcsftime(buffer, 128, measure->format.c_str(), &time);
				if (errno == EINVAL)
				{
					buffer[0] = L'\0';
				}

				_set_invalid_parameter_handler(oldHandler);

				return buffer;
			}
		}
	}

	return nullptr;
}
Beispiel #23
0
/**
 * Setup the common debug settings 
 */
void SetupWindowsEnvironment( void )
{
	// all crt validation should trigger the callback
	_set_invalid_parameter_handler(InvalidParameterHandler);

#if UE_BUILD_DEBUG
	// Disable the message box for assertions and just write to debugout instead
	_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_DEBUG );
	// don't fill buffers with 0xfd as we make assumptions for FNames st we only use a fraction of the entire buffer
	_CrtSetDebugFillThreshold( 0 );
#endif
}
Beispiel #24
0
extern "C" void cbStartup()
{
	cbLock = CreateMutex( NULL, FALSE, NULL );
	cbReportData = NULL;

	swprintf_s( cbShareName, 256, L"CrashBack_%x", GetCurrentProcessId() );

	GetModuleFileName( NULL, cbReportExePath, MAX_PATH );
	wcscpy_s( cbReportExeDir, MAX_PATH, cbReportExePath );
	wchar_t *p = wcsrchr( cbReportExeDir, '\\' );
	if ( p )
		*p = 0;

	wcscpy_s( cbReportExePath, MAX_PATH, cbReportExeDir );
	wcscat_s( cbReportExePath, MAX_PATH, L"\\" );
	wcscat_s( cbReportExePath, MAX_PATH, L"crashreport.exe" );

	// Check that crashreport.exe exists in the app's directory.
	if ( GetFileAttributes( cbReportExePath ) == INVALID_FILE_ATTRIBUTES )
		return;

	swprintf_s( cbReportCmdLine, 1024, L"\"%s\" 0x%x", cbReportExePath, GetCurrentProcessId() );

	cbGetProgramName();
	cbGetCmdLine();

	// Set up shared memory to communicate with the report handler EXE.
	HANDLE hShared = CreateFileMapping(
		INVALID_HANDLE_VALUE,    // use paging file
		NULL,                    // default security
		PAGE_READWRITE,          // read/write access
		0,                       // max. object size
		sizeof(CbReport),        // buffer size
		cbShareName );           // name of mapping object
	if ( !hShared )
		return;

	cbReportData = (CbReport *)MapViewOfFile( hShared, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(CbReport) );
	if ( !cbReportData )
	{
		CloseHandle( hShared );
		return;
	}

	// Register the handlers.
	SetUnhandledExceptionFilter( &cbExceptionHandler );
	_set_error_mode( _OUT_TO_STDERR );
	_set_purecall_handler( cbPureCallHandler );
	_set_new_mode( 1 ); // malloc calls the new handler on failure
	_set_new_handler( cbNewHandler );
	_set_invalid_parameter_handler( cbInvalidParameterHandler );
	_set_abort_behavior( _CALL_REPORTFAULT, _CALL_REPORTFAULT );
}
Beispiel #25
0
rt_shared void initstk(void)
{
	/* Initialize both the local stack and the hector stack. Those two stacks
	 * may have their context saved and restored in an Eiffel routine, so they
	 * need to be correctly initialized.
	 * In workbench mode, the debugger stack is also created here.
	 */

	EIF_GET_CONTEXT
#ifdef ISE_GC
	char **top;
#endif


#ifdef EIF_ASSERTIONS
#if defined(EIF_WINDOWS) && defined(_DEBUG)

	int tmpDbgFlag = 0;
	_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
	_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT);
	_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
	_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDOUT);
	_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
	_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT);

	tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
	tmpDbgFlag |= _CRTDBG_DELAY_FREE_MEM_DF;
	tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF;
	tmpDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF;
	_CrtSetDbgFlag(tmpDbgFlag);
#endif
#endif

#if defined(EIF_WINDOWS) && defined(_MSC_VER)
		/* This is to catch CRT raised exception when passing incorrect arguments to CRT routines. */
	_set_invalid_parameter_handler(eif_invalid_paramter_handler);
#endif

#ifdef ISE_GC
	top = st_alloc(&loc_set, eif_stack_chunk);
	if (top != (char **) 0)
		top = st_alloc(&hec_stack, eif_stack_chunk);

	if (top == (char **) 0)
		eif_panic(MTC "can't create runtime stacks");
#endif

#ifdef WORKBENCH
	initdb();				/* Initialize debugger stack */
#endif
}
int _tmain(int argc, _TCHAR* argv[])
{
	_set_invalid_parameter_handler(ReportInvaidParamentFun);
	_set_se_translator(ReportESHFun);
	CSplitInfo::GetInst()->Init(argc, argv);
	if(!CSplitInfo::GetInst()->GetBeInternational())
		return 0;
	BeginToPrint("MakeGermanReferTxt");
	CConsoleInfo::GetInst()->PrintFunction("德语任务索引关系表生成");
	FileTreeWalk( gbk_to_utf16(CSplitInfo::GetInst()->GetReferPath()).c_str(), CGermanRefer::CreateRefer, NULL );
	CGermanRefer::GetInst()->WriteToGermanRefer();
	EndToPrint();
	return 0;
}
Beispiel #27
0
void LogWithArgs(int nLevel, const WCHAR* format, ...)
{
	WCHAR* buffer = new WCHAR[4096];
	va_list args;
	va_start( args, format );

	_invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(RmNullCRTInvalidParameterHandler);
	_CrtSetReportMode(_CRT_ASSERT, 0);

	errno = 0;
	_vsnwprintf_s(buffer, 4096, _TRUNCATE, format, args);
	if (errno != 0)
	{
		nLevel = LOG_ERROR;
		_snwprintf_s(buffer, 4096, _TRUNCATE, L"LogWithArgs internal error: %s", format);
	}

	_set_invalid_parameter_handler(oldHandler);

	Log(nLevel, buffer);
	va_end(args);

	delete [] buffer;
}
Beispiel #28
0
main (int ac, string *av)
#endif
{
#  ifdef __EMX__
    _wildcard(&ac, &av);
    _response(&ac, &av);
#  endif

#  ifdef WIN32
#    ifdef _MSC_VER
    _set_invalid_parameter_handler(myInvalidParameterHandler);
#    endif
    av[0] = kpse_program_basename (av[0]);
    _setmaxstdio(2048);
/*
    We choose to crash for fatal errors:

    SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
*/
    setmode(fileno(stdin), _O_BINARY);
#  endif

    lua_initialize(ac, av);

#  ifdef WIN32
    if (ac > 1) {
        char *pp;
        if ((strlen(av[ac-1]) > 2) && isalpha(av[ac-1][0]) && (av[ac-1][1] == ':') && (av[ac-1][2] == '\\')) {
            for (pp=av[ac-1]+2; *pp; pp++) {
            if (IS_KANJI(pp)) {
                pp++;
                continue;
            }
            if (*pp == '\\')
                *pp = '/';
            }
        }
    }
#  endif

    /*
        Call the real main program.
    */
    main_body();

    return EXIT_SUCCESS;
}
Beispiel #29
0
static void uv_init(void) {
  /* Tell Windows that we will handle critical errors. */
  SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX |
               SEM_NOOPENFILEERRORBOX);

  /* Tell the CRT to not exit the application when an invalid parameter is
   * passed. The main issue is that invalid FDs will trigger this behavior.
   */
#if !defined(__MINGW32__) || __MSVCRT_VERSION__ >= 0x800
  _set_invalid_parameter_handler(uv__crt_invalid_parameter_handler);
#endif

  /* We also need to setup our debug report handler because some CRT
   * functions (eg _get_osfhandle) raise an assert when called with invalid
   * FDs even though they return the proper error code in the release build.
   */
#if defined(_DEBUG) && (defined(_MSC_VER) || defined(__MINGW64_VERSION_MAJOR))
  _CrtSetReportHook(uv__crt_dbg_report_handler);
#endif

  /* Initialize tracking of all uv loops */
  uv__loops_init();

  /* Fetch winapi function pointers. This must be done first because other
   * initialization code might need these function pointers to be loaded.
   */
  uv_winapi_init();

  /* Initialize winsock */
  uv_winsock_init();

  /* Initialize FS */
  uv_fs_init();

  /* Initialize signal stuff */
  uv_signals_init();

  /* Initialize console */
  uv_console_init();

  /* Initialize utilities */
  uv__util_init();

  /* Initialize system wakeup detection */
  uv__init_detect_system_wakeup();
}
void CrashHandlerWindows::unregisterCrashHandlers() {
    unregisterThreadCrashHandlers();

    SetUnhandledExceptionFilter(m_pPreviousCrashHandlers->m_SEHHandler);
    _set_purecall_handler(m_pPreviousCrashHandlers->m_pureCallHandler);
    _set_new_handler(m_pPreviousCrashHandlers->m_newHandler);
    _set_invalid_parameter_handler(m_pPreviousCrashHandlers->m_invalidParameterHandler);
    signal(SIGABRT, m_pPreviousCrashHandlers->m_SIGABRTHandler);
    signal(SIGINT, m_pPreviousCrashHandlers->m_SIGINTHandler);
    signal(SIGTERM, m_pPreviousCrashHandlers->m_SIGTERMHandler);

    if(!m_pPreviousCrashHandlers->m_threadExceptionHandlers.empty())
        LogWarning << "Some threads crash handlers are still registered.";

    delete m_pPreviousCrashHandlers;
    m_pPreviousCrashHandlers = 0;
}