/* LoadLib * load a dynamic library * * "lib" [ OUT ] - return parameter for loaded library * * "path" [ IN ] - NUL terminated string in directory-native * character set denoting target library */ static rc_t KDyldLoad ( KDyld *self, KDylib *lib, const wchar_t *path ) { DWORD err; #if WE_WERE_BUILDING_FOR_WINDOWS_7_ALONE UINT errMode = GetErrorMode(); #endif if ( path == NULL ) { if ( GetModuleHandleExW( 0, NULL, &( lib -> handle ) ) ) return 0; return RC ( rcFS, rcDylib, rcLoading, rcNoObj, rcUnknown ); } SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); /* suppress the message box in case of an error */ lib -> handle = LoadLibraryW ( path ); #if WE_WERE_BUILDING_FOR_WINDOWS_7_ALONE SetErrorMode(errMode); #endif if ( lib -> handle != NULL ) return KDylibSetLogging ( lib ); err = GetLastError (); switch ( err ) { case ERROR_MOD_NOT_FOUND : return RC ( rcFS, rcDylib, rcLoading, rcPath, rcNotFound ); case ERROR_BAD_EXE_FORMAT : return RC ( rcFS, rcDylib, rcLoading, rcFormat, rcInvalid ); } return RC ( rcFS, rcDylib, rcLoading, rcNoObj, rcUnknown ); }
/* * ut_sigaction -- a sigaction that cannot return < 0 */ int ut_sigaction(const char *file, int line, const char *func, int signum, struct sigaction *act, struct sigaction *oldact) { #ifndef _WIN32 int retval = sigaction(signum, act, oldact); if (retval != 0) ut_fatal(file, line, func, "!sigaction: %s", strsignal(signum)); return retval; #else if (signum == SIGABRT) { DWORD dwMode = GetErrorMode(); SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS); _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); } if (signum == SIGSEGV) { Sa_handler = act->sa_handler; Signum = signum; AddVectoredExceptionHandler(0, exception_handler); } _crt_signal_t retval = signal(signum, act->sa_handler); if (retval == SIG_ERR) ut_fatal(file, line, func, "!signal: %d", signum); if (oldact != NULL) { oldact->sa_handler = retval; } return 0; #endif }
Io_Manager Io_Manager__init() { // Initialize an event manager, and allocate an I/O completion port. Coroutine__set_signals(); Io_Manager ret = Boot_calloc(sizeof(struct Io_Manager)); #ifdef WINDOWS WORD version = MAKEWORD(2, 2); WSADATA data; // Disable error dialog boxes SetErrorMode(GetErrorMode()|SEM_NOGPFAULTERRORBOX); if (WSAStartup(version, &data) != 0) { Boot_abort(); } #endif ret->_vtable = Io_Manager__vtable; ret->_refcount = 1; ret->scheduled = Queue__init(0); ret->waiting = 0; #if defined(WINDOWS) ret->handle = (Int)CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0, 0); #elif defined(DARWIN) ret->handle = (Int)kqueue(); #elif defined(LINUX) ret->handle = (Int)epoll_create(1); #endif return ret; }
void ut_suppress_errmsg() { ErrMode = GetErrorMode(); SetErrorMode(ErrMode | SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS); AbortBehave = _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); Suppressed = TRUE; }
/* * util_suppress_errmsg -- suppresses "abort" window on Windows if env variable * is set, useful for automatic tests */ void util_suppress_errmsg(void) { if (os_getenv("PMDK_NO_ABORT_MSG") != NULL) { DWORD err = GetErrorMode(); SetErrorMode(err | SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS); _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); } }
int WebEmberLinker::link(const char* prefix) { assert(!mModuleHandle); std::string libdir(prefix); #ifdef _WIN32 if(!libdir.empty()) { #if defined(_DEBUG) && defined(SEPARATE_BUILDS) //In msvc I prefer to separate release/debug builds to prevent mixing the runtime. //Set SEPARATE_BUILDS to enable this feature. libdir += "\\bin_d"; #else libdir += "\\bin"; #endif SetDllDirectoryA(libdir.c_str()); SetCurrentDirectoryA(libdir.c_str()); libdir += "\\"; } //normally the browsers are disabling verbose popup messages from the OS on errors, //but to get more info on what is the missing DLL when linking recursively, we need to enable this. UINT browserErrorMode = GetErrorMode(); SetErrorMode(0); #else if (!libdir.empty()) { libdir += "/lib/"; } #endif std::string libfile(libdir + sLibName); FBLOG_INFO("WebEmberLinker::runEmber", "Loading library: " << libfile); //Loads the specified module into the address space of the calling process. mModuleHandle = LoadLib(libfile.c_str()); if (mModuleHandle == NULL) { #ifndef _WIN32 FBLOG_ERROR("WebEmberLinker::runEmber", "dlerror: " << dlerror()); #endif FBLOG_ERROR("WebEmberLinker::runEmber", "Unable to load " << libfile); return 1; } //Retrieves the address of an exported function or variable from the specified DLL. pStartWebEmber = (funcTypeStart)GetFunction(mModuleHandle, sFuncNameStart); if (pStartWebEmber == NULL) { #ifndef _WIN32 FBLOG_ERROR("WebEmberLinker::runEmber", "dlerror: " << dlerror()); #endif FBLOG_ERROR("WebEmberLinker::runEmber", "Unable to load function " << sFuncNameStart << " in " << libfile); UnloadLib(mModuleHandle); return 2; } //same as above pQuitWebEmber = (funcTypeQuit)GetFunction(mModuleHandle, sFuncNameQuit); if (pQuitWebEmber == NULL) { #ifndef _WIN32 FBLOG_ERROR("WebEmberLinker::runEmber", "dlerror: " << dlerror()); #endif FBLOG_ERROR("WebEmberLinker::runEmber", "Unable to load function " << sFuncNameQuit << " in " << libfile); UnloadLib(mModuleHandle); return 3; } #ifdef _WIN32 //SetErrorMode of the process back to the original. SetErrorMode(browserErrorMode); #endif return 0; }