1 /* 2 * 3 * libcontext - a slightly more portable version of boost::context 4 * 5 * Copyright Martin Husemann 2013. 6 * Copyright Oliver Kowalke 2009. 7 * Copyright Sergue E. Leontiev 2013. 8 * Copyright Thomas Sailer 2013. 9 * Minor modifications by Tomasz Wlostowski 2016. 10 * 11 * Distributed under the Boost Software License, Version 1.0. 12 * (See accompanying file LICENSE_1_0.txt or copy at 13 * http://www.boost.org/LICENSE_1_0.txt) 14 * 15 */ 16 17 #ifndef __LIBCONTEXT_H 18 #define __LIBCONTEXT_H 19 20 #include <cstddef> 21 #include <cstdint> 22 #include <cstdio> 23 24 25 #if defined(__GNUC__) || defined(__APPLE__) || defined(__DragonFly__) 26 27 #undef LIBCONTEXT_HAS_OWN_STACK 28 29 #define LIBCONTEXT_COMPILER_gcc 30 31 #if defined(__linux__) || defined(__DragonFly__) 32 #if defined(__x86_64__) || defined(__amd64__) 33 #define LIBCONTEXT_PLATFORM_linux_x86_64 34 #define LIBCONTEXT_CALL_CONVENTION 35 #elif __i386__ 36 #define LIBCONTEXT_PLATFORM_linux_i386 37 #define LIBCONTEXT_CALL_CONVENTION 38 #elif __arm__ 39 #define LIBCONTEXT_PLATFORM_linux_arm32 40 #define LIBCONTEXT_CALL_CONVENTION 41 #elif __aarch64__ 42 #define LIBCONTEXT_PLATFORM_linux_arm64 43 #define LIBCONTEXT_CALL_CONVENTION 44 #elif (__loongarch__ && _LOONGARCH_SIM == _ABILP64) 45 #define LIBCONTEXT_PLATFORM_linux_loong64 46 #define LIBCONTEXT_CALL_CONVENTION 47 #elif (__mips__ && _MIPS_SIM == _ABI64) 48 #define LIBCONTEXT_PLATFORM_linux_mips_n64 49 #define LIBCONTEXT_CALL_CONVENTION 50 #elif __powerpc__ 51 #ifdef _ARCH_PPC64 52 #define LIBCONTEXT_PLATFORM_linux_ppc64 53 #define LIBCONTEXT_CALL_CONVENTION 54 #elif defined _ARCH_PPC 55 #define LIBCONTEXT_PLATFORM_linux_ppc32 56 #define LIBCONTEXT_CALL_CONVENTION 57 #endif 58 #endif 59 60 #elif defined(__MINGW32__) || defined(__MINGW64__) 61 #if defined(__x86_64__) 62 #define LIBCONTEXT_COMPILER_gcc 63 #define LIBCONTEXT_PLATFORM_windows_x86_64 64 #define LIBCONTEXT_CALL_CONVENTION 65 #endif 66 67 #if defined(__i386__) 68 #define LIBCONTEXT_COMPILER_gcc 69 #define LIBCONTEXT_PLATFORM_windows_i386 70 #define LIBCONTEXT_CALL_CONVENTION __cdecl 71 #endif 72 #elif defined(__APPLE__) && defined(__MACH__) 73 #if defined(__i386__) 74 #define LIBCONTEXT_PLATFORM_apple_i386 75 #define LIBCONTEXT_CALL_CONVENTION 76 #elif defined(__x86_64__) 77 #define LIBCONTEXT_PLATFORM_apple_x86_64 78 #define LIBCONTEXT_CALL_CONVENTION 79 #elif __aarch64__ 80 #define LIBCONTEXT_PLATFORM_apple_arm64 81 #define LIBCONTEXT_CALL_CONVENTION 82 #endif 83 #endif 84 #elif defined (_MSC_VER ) 85 86 #if defined( LIBCONTEXT_USE_WINFIBER ) 87 #define LIBCONTEXT_HAS_OWN_STACK 88 #endif 89 90 #define LIBCONTEXT_CALL_CONVENTION __cdecl 91 92 #if defined(_WIN64) 93 #define LIBCONTEXT_PLATFORM_msvc_x86_64 94 #elif defined(_WIN32) 95 #define LIBCONTEXT_PLATFORM_msvc_i386 96 #endif 97 #endif 98 99 #ifdef __cplusplus 100 namespace libcontext { 101 #endif 102 103 #if defined(_WIN32_WCE) 104 typedef int intptr_t; 105 #endif 106 107 typedef void* fcontext_t; 108 109 #ifdef __cplusplus 110 extern "C" { 111 #endif 112 113 void LIBCONTEXT_CALL_CONVENTION release_fcontext( fcontext_t ctx ); 114 115 intptr_t LIBCONTEXT_CALL_CONVENTION jump_fcontext( fcontext_t* ofc, fcontext_t nfc, 116 intptr_t vp, bool preserve_fpu = true ); 117 fcontext_t LIBCONTEXT_CALL_CONVENTION make_fcontext( void* sp, size_t size, 118 void (* fn)( intptr_t ) ); 119 120 #ifdef __cplusplus 121 } // namespace 122 #endif 123 124 #ifdef __cplusplus 125 } // extern "C" 126 #endif 127 128 #endif 129