|
||||
File indexing completed on 2025-01-18 10:04:36
0001 // Copyright (c) 1992-1999 Matra Datavision 0002 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0003 // 0004 // This file is part of Open CASCADE Technology software library. 0005 // 0006 // This library is free software; you can redistribute it and/or modify it under 0007 // the terms of the GNU Lesser General Public License version 2.1 as published 0008 // by the Free Software Foundation, with special exception defined in the file 0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0010 // distribution for complete text of the license and disclaimer of any warranty. 0011 // 0012 // Alternatively, this file may be used under the terms of Open CASCADE 0013 // commercial license or contractual agreement. 0014 0015 #ifndef _OSD_HeaderFile 0016 #define _OSD_HeaderFile 0017 0018 #include <Standard.hxx> 0019 #include <Standard_PCharacter.hxx> 0020 #include <OSD_SignalMode.hxx> 0021 0022 //! Set of Operating System Dependent (OSD) tools. 0023 class OSD 0024 { 0025 public: 0026 0027 DEFINE_STANDARD_ALLOC 0028 0029 //! Sets or removes signal and FPE (floating-point exception) handlers. 0030 //! OCCT signal handlers translate signals raised by C subsystem to C++ 0031 //! exceptions inheriting Standard_Failure. 0032 //! 0033 //! ### Windows-specific notes 0034 //! 0035 //! Compiled with MS VC++ sets 3 main handlers: 0036 //! @li Signal handlers (via ::signal() functions) that translate system signals 0037 //! (SIGSEGV, SIGFPE, SIGILL) into C++ exceptions (classes inheriting 0038 //! Standard_Failure). They only be called if function ::raise() is called 0039 //! with one of supported signal type set. 0040 //! @li Exception handler OSD::WntHandler() (via ::SetUnhandledExceptionFilter()) 0041 //! that will be used when user's code is compiled with /EHs option. 0042 //! @li Structured exception (SE) translator (via _set_se_translator()) that 0043 //! translates SE exceptions (aka asynchronous exceptions) into the 0044 //! C++ exceptions inheriting Standard_Failure. This translator will be 0045 //! used when user's code is compiled with /EHa option. 0046 //! 0047 //! This approach ensures that regardless of the option the user chooses to 0048 //! compile his code with (/EHs or /EHa), signals (or SE exceptions) will be 0049 //! translated into Open CASCADE C++ exceptions. 0050 //! 0051 //! MinGW should use SEH exception mode for signal handling to work. 0052 //! 0053 //! ### Linux-specific notes 0054 //! 0055 //! OSD::SetSignal() sets handlers (via ::sigaction()) for multiple signals 0056 //! (SIGFPE, SIGSEGV, etc). 0057 //! 0058 //! ### Common notes 0059 //! 0060 //! If @a theFloatingSignal is TRUE then floating point exceptions will 0061 //! generate SIGFPE in accordance with the mask 0062 //! - Windows: _EM_INVALID | _EM_DENORMAL | _EM_ZERODIVIDE | _EM_OVERFLOW, 0063 //! see _controlfp() system function. 0064 //! - Linux: FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW, 0065 //! see feenableexcept() system function. 0066 //! 0067 //! If @a theFloatingSignal is FALSE then floating point calculations will gracefully 0068 //! complete regardless of occurred exceptions (e.g. division by zero). 0069 //! Otherwise the (thread-specific) FPE flags are set to raise signal if one of 0070 //! floating-point exceptions (division by zero, overflow, or invalid operation) occurs. 0071 //! 0072 //! The recommended approach is to call OSD::SetSignal() in the beginning of the 0073 //! execution of the program, in function main() or its equivalent. 0074 //! In multithreaded programs it is advisable to call OSD::SetSignal() or 0075 //! OSD::SetThreadLocalSignal() with the same parameters in other threads where 0076 //! OCCT is used, to ensure consistency of behavior. 0077 //! 0078 //! Note that in order to handle signals as C++ exceptions on Linux and under 0079 //! MinGW on Windows it is necessary to compile both OCCT and application with 0080 //! OCC_CONVERT_SIGNALS macro, and use macro OCC_CATCH_SIGNALS within each try{} 0081 //! block that has to catch this kind of exceptions. 0082 //! 0083 //! Refer to documentation of Standard_ErrorHandler.hxx for details. 0084 Standard_EXPORT static void SetSignal (OSD_SignalMode theSignalMode, 0085 Standard_Boolean theFloatingSignal); 0086 0087 //! Sets signal and FPE handlers. 0088 //! Short-cut for OSD::SetSignal (OSD_SignalMode_Set, theFloatingSignal). 0089 static void SetSignal (const Standard_Boolean theFloatingSignal = Standard_True) 0090 { 0091 SetSignal (OSD_SignalMode_Set, theFloatingSignal); 0092 } 0093 0094 //! Initializes thread-local signal handlers. 0095 //! This includes _set_se_translator() on Windows platform, and SetFloatingSignal(). 0096 //! The main purpose of this method is initializing handlers for newly created threads 0097 //! without overriding global handlers (set by application or by OSD::SetSignal()). 0098 Standard_EXPORT static void SetThreadLocalSignal (OSD_SignalMode theSignalMode, 0099 Standard_Boolean theFloatingSignal); 0100 0101 //! Enables / disables generation of C signal on floating point exceptions (FPE). 0102 //! This call does NOT register a handler for signal raised in case of FPE - 0103 //! SetSignal() should be called beforehand for complete setup. 0104 //! Note that FPE setting is thread-local, new threads inherit it from parent. 0105 Standard_EXPORT static void SetFloatingSignal (Standard_Boolean theFloatingSignal); 0106 0107 //! Returns signal mode set by the last call to SetSignal(). 0108 //! By default, returns OSD_SignalMode_AsIs. 0109 Standard_EXPORT static OSD_SignalMode SignalMode(); 0110 0111 //! Returns true if floating point exceptions will raise C signal 0112 //! according to current (platform-dependent) settings in this thread. 0113 Standard_EXPORT static Standard_Boolean ToCatchFloatingSignals(); 0114 0115 //! Commands the process to sleep for a number of seconds. 0116 Standard_EXPORT static void SecSleep (const Standard_Integer theSeconds); 0117 0118 //! Commands the process to sleep for a number of milliseconds 0119 Standard_EXPORT static void MilliSecSleep (const Standard_Integer theMilliseconds); 0120 0121 //! Converts aReal into aCstring in exponential format with a period as decimal point, 0122 //! no thousand separator and no grouping of digits. 0123 //! The conversion is independent from the current locale 0124 Standard_EXPORT static Standard_Boolean RealToCString (const Standard_Real aReal, Standard_PCharacter& aString); 0125 0126 //! Converts aCstring representing a real with a period as decimal point, 0127 //! no thousand separator and no grouping of digits into aReal. 0128 //! 0129 //! The conversion is independent from the current locale. 0130 Standard_EXPORT static Standard_Boolean CStringToReal (const Standard_CString aString, Standard_Real& aReal); 0131 0132 //! since Windows NT does not support 'SIGINT' signal like UNIX, 0133 //! then this method checks whether Ctrl-Break keystroke was or 0134 //! not. If yes then raises Exception_CTRL_BREAK. 0135 Standard_EXPORT static void ControlBreak(); 0136 0137 //! Returns a length of stack trace to be put into exception redirected from signal; 0138 //! 0 by default meaning no stack trace. 0139 //! @sa Standard_Failure::GetStackString() 0140 Standard_EXPORT static Standard_Integer SignalStackTraceLength(); 0141 0142 //! Sets a length of stack trace to be put into exception redirected from signal. 0143 Standard_EXPORT static void SetSignalStackTraceLength (Standard_Integer theLength); 0144 0145 }; 0146 0147 #endif // _OSD_HeaderFile
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |