1 /*========================== begin_copyright_notice ============================ 2 3 Copyright (C) 2019-2021 Intel Corporation 4 5 SPDX-License-Identifier: MIT 6 7 ============================= end_copyright_notice ===========================*/ 8 9 #ifndef UFO_FAKE_SEH_H 10 #define UFO_FAKE_SEH_H 11 12 /** 13 * This file provides trivial mapping of Microsoft specific structured exception handling mechanism: 14 * __try 15 * __leave 16 * __finally 17 * __except(e) 18 * NOTE: This mapping will just enable compilation of your code. SEH will *NOT* work as on MSVC! 19 */ 20 21 #if !defined(_MSC_VER) 22 23 // __try may be defined as internal macro in GNU C++ library 24 #if defined(__cplusplus) 25 // NOTE: Any C++ standard header must be included _before_ any attempt of keyword 26 // redefinition (i.e. try/catch) in other case a fatal error is generated according 27 // to C++11 standard. 28 #include <exception> 29 #endif 30 31 #ifndef __try 32 #define __try { if(1) 33 #define __leave goto _end_of_guarded_block 34 #define __finally __leave; } _end_of_guarded_block: if(1) 35 #define __except(e) __leave; } _end_of_guarded_block: if(0) 36 #elif defined(__catch) 37 // __try is likely defined as "try" or "if(true)" 38 // and __catch is likely defined as "catch" or "if(false)" 39 #define __leave goto _end_of_guarded_block 40 #define __finally __catch(...) { __leave; } _end_of_guarded_block: if(true) 41 #define __except(e) __catch(...) { __leave; } _end_of_guarded_block: if(false) 42 #else 43 #pragma message "FIXME unknown config (found __try without __catch)" 44 #error "FIXME unknown config (found __try without __catch)" 45 #endif 46 47 #endif 48 49 #endif // UFO_FAKE_SEH_H 50