2017-03-07 13:30:15 +00:00
|
|
|
/*
|
2017-03-14 09:01:17 +00:00
|
|
|
*
|
|
|
|
* libcontext - a slightly more portable version of boost::context
|
|
|
|
*
|
|
|
|
* Copyright Martin Husemann 2013.
|
|
|
|
* Copyright Oliver Kowalke 2009.
|
|
|
|
* Copyright Sergue E. Leontiev 2013.
|
|
|
|
* Copyright Thomas Sailer 2013.
|
|
|
|
* Minor modifications by Tomasz Wlostowski 2016.
|
|
|
|
*
|
|
|
|
* Distributed under the Boost Software License, Version 1.0.
|
|
|
|
* (See accompanying file LICENSE_1_0.txt or copy at
|
|
|
|
* http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
*
|
|
|
|
*/
|
2017-03-07 13:30:15 +00:00
|
|
|
|
|
|
|
#ifndef __LIBCONTEXT_H
|
|
|
|
#define __LIBCONTEXT_H
|
|
|
|
|
2019-12-05 14:03:15 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cstdio>
|
2017-03-07 13:30:15 +00:00
|
|
|
|
|
|
|
|
2017-07-28 12:19:47 +00:00
|
|
|
#if defined(__GNUC__) || defined(__APPLE__) || defined(__FreeBSD__)
|
2017-03-07 13:30:15 +00:00
|
|
|
|
2019-03-06 15:19:44 +00:00
|
|
|
#undef LIBCONTEXT_HAS_OWN_STACK
|
|
|
|
|
2017-03-07 13:30:15 +00:00
|
|
|
#define LIBCONTEXT_COMPILER_gcc
|
|
|
|
|
2017-07-28 12:19:47 +00:00
|
|
|
#if defined(__linux__) || defined(__FreeBSD__)
|
|
|
|
#if defined(__x86_64__) || defined(__amd64__)
|
2017-03-14 09:01:17 +00:00
|
|
|
#define LIBCONTEXT_PLATFORM_linux_x86_64
|
|
|
|
#define LIBCONTEXT_CALL_CONVENTION
|
|
|
|
#elif __i386__
|
|
|
|
#define LIBCONTEXT_PLATFORM_linux_i386
|
|
|
|
#define LIBCONTEXT_CALL_CONVENTION
|
|
|
|
#elif __arm__
|
|
|
|
#define LIBCONTEXT_PLATFORM_linux_arm32
|
|
|
|
#define LIBCONTEXT_CALL_CONVENTION
|
|
|
|
#elif __aarch64__
|
|
|
|
#define LIBCONTEXT_PLATFORM_linux_arm64
|
|
|
|
#define LIBCONTEXT_CALL_CONVENTION
|
2021-10-15 13:24:12 +00:00
|
|
|
#elif (__loongarch__ && _LOONGARCH_SIM == _ABILP64)
|
|
|
|
#define LIBCONTEXT_PLATFORM_linux_loong64
|
|
|
|
#define LIBCONTEXT_CALL_CONVENTION
|
2018-12-26 01:28:09 +00:00
|
|
|
#elif (__mips__ && _MIPS_SIM == _ABI64)
|
|
|
|
#define LIBCONTEXT_PLATFORM_linux_mips_n64
|
|
|
|
#define LIBCONTEXT_CALL_CONVENTION
|
2019-02-11 15:33:28 +00:00
|
|
|
#elif __powerpc__
|
|
|
|
#ifdef _ARCH_PPC64
|
|
|
|
#define LIBCONTEXT_PLATFORM_linux_ppc64
|
|
|
|
#define LIBCONTEXT_CALL_CONVENTION
|
2019-08-24 19:13:46 +00:00
|
|
|
#elif defined _ARCH_PPC
|
2019-02-11 15:33:28 +00:00
|
|
|
#define LIBCONTEXT_PLATFORM_linux_ppc32
|
|
|
|
#define LIBCONTEXT_CALL_CONVENTION
|
|
|
|
#endif
|
2017-03-14 09:01:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#elif defined(__MINGW32__) || defined(__MINGW64__)
|
|
|
|
#if defined(__x86_64__)
|
|
|
|
#define LIBCONTEXT_COMPILER_gcc
|
|
|
|
#define LIBCONTEXT_PLATFORM_windows_x86_64
|
|
|
|
#define LIBCONTEXT_CALL_CONVENTION
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__i386__)
|
|
|
|
#define LIBCONTEXT_COMPILER_gcc
|
|
|
|
#define LIBCONTEXT_PLATFORM_windows_i386
|
|
|
|
#define LIBCONTEXT_CALL_CONVENTION __cdecl
|
|
|
|
#endif
|
2017-03-07 13:30:15 +00:00
|
|
|
#elif defined(__APPLE__) && defined(__MACH__)
|
2017-03-14 09:01:17 +00:00
|
|
|
#if defined(__i386__)
|
|
|
|
#define LIBCONTEXT_PLATFORM_apple_i386
|
|
|
|
#define LIBCONTEXT_CALL_CONVENTION
|
|
|
|
#elif defined(__x86_64__)
|
|
|
|
#define LIBCONTEXT_PLATFORM_apple_x86_64
|
|
|
|
#define LIBCONTEXT_CALL_CONVENTION
|
2021-01-04 11:17:17 +00:00
|
|
|
#elif __aarch64__
|
|
|
|
#define LIBCONTEXT_PLATFORM_apple_arm64
|
|
|
|
#define LIBCONTEXT_CALL_CONVENTION
|
2017-03-14 09:01:17 +00:00
|
|
|
#endif
|
2017-03-07 13:30:15 +00:00
|
|
|
#endif
|
2021-03-04 01:27:37 +00:00
|
|
|
#elif defined (_MSC_VER )
|
2019-03-06 15:19:44 +00:00
|
|
|
|
2021-03-04 01:27:37 +00:00
|
|
|
#if defined( LIBCONTEXT_USE_WINFIBER )
|
2019-03-06 15:19:44 +00:00
|
|
|
#define LIBCONTEXT_HAS_OWN_STACK
|
2021-03-04 01:27:37 +00:00
|
|
|
#endif
|
2019-03-06 15:19:44 +00:00
|
|
|
|
|
|
|
#define LIBCONTEXT_CALL_CONVENTION __cdecl
|
|
|
|
|
|
|
|
#if defined(_WIN64)
|
|
|
|
#define LIBCONTEXT_PLATFORM_msvc_x86_64
|
|
|
|
#elif defined(_WIN32)
|
|
|
|
#define LIBCONTEXT_PLATFORM_msvc_i386
|
|
|
|
#endif
|
2017-03-07 13:30:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
namespace libcontext {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_WIN32_WCE)
|
|
|
|
typedef int intptr_t;
|
|
|
|
#endif
|
|
|
|
|
2017-03-14 09:01:17 +00:00
|
|
|
typedef void* fcontext_t;
|
2017-03-07 13:30:15 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2017-03-14 09:01:17 +00:00
|
|
|
extern "C" {
|
2017-03-07 13:30:15 +00:00
|
|
|
#endif
|
|
|
|
|
2020-07-22 13:39:04 +00:00
|
|
|
void LIBCONTEXT_CALL_CONVENTION release_fcontext( fcontext_t ctx );
|
2017-03-07 13:30:15 +00:00
|
|
|
|
2017-03-14 09:01:17 +00:00
|
|
|
intptr_t LIBCONTEXT_CALL_CONVENTION jump_fcontext( fcontext_t* ofc, fcontext_t nfc,
|
2017-04-23 22:01:52 +00:00
|
|
|
intptr_t vp, bool preserve_fpu = true );
|
2017-03-14 09:01:17 +00:00
|
|
|
fcontext_t LIBCONTEXT_CALL_CONVENTION make_fcontext( void* sp, size_t size,
|
|
|
|
void (* fn)( intptr_t ) );
|
2017-03-07 13:30:15 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2017-11-02 20:41:29 +00:00
|
|
|
} // namespace
|
2017-03-07 13:30:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2017-11-02 20:41:29 +00:00
|
|
|
} // extern "C"
|
2017-03-07 13:30:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|