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
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
|
2017-07-28 12:19:47 +00:00
|
|
|
#if defined(__GNUC__) || defined(__APPLE__) || defined(__FreeBSD__)
|
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
|
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
|
|
|
|
#endif
|
|
|
|
#ifdef _ARCH_PPC
|
|
|
|
#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
|
|
|
|
#endif
|
2017-03-07 13:30:15 +00:00
|
|
|
#endif
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
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
|