You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.8 KiB

  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. #ifndef __LIBCONTEXT_H
  17. #define __LIBCONTEXT_H
  18. #include <stdint.h>
  19. #include <stdio.h>
  20. #include <stddef.h>
  21. #if defined(__GNUC__) || defined(__APPLE__) || defined(__FreeBSD__)
  22. #define LIBCONTEXT_COMPILER_gcc
  23. #if defined(__linux__) || defined(__FreeBSD__)
  24. #if defined(__x86_64__) || defined(__amd64__)
  25. #define LIBCONTEXT_PLATFORM_linux_x86_64
  26. #define LIBCONTEXT_CALL_CONVENTION
  27. #elif __i386__
  28. #define LIBCONTEXT_PLATFORM_linux_i386
  29. #define LIBCONTEXT_CALL_CONVENTION
  30. #elif __arm__
  31. #define LIBCONTEXT_PLATFORM_linux_arm32
  32. #define LIBCONTEXT_CALL_CONVENTION
  33. #elif __aarch64__
  34. #define LIBCONTEXT_PLATFORM_linux_arm64
  35. #define LIBCONTEXT_CALL_CONVENTION
  36. #elif (__mips__ && _MIPS_SIM == _ABI64)
  37. #define LIBCONTEXT_PLATFORM_linux_mips_n64
  38. #define LIBCONTEXT_CALL_CONVENTION
  39. #elif __powerpc__
  40. #ifdef _ARCH_PPC64
  41. #define LIBCONTEXT_PLATFORM_linux_ppc64
  42. #define LIBCONTEXT_CALL_CONVENTION
  43. #elif defined _ARCH_PPC
  44. #define LIBCONTEXT_PLATFORM_linux_ppc32
  45. #define LIBCONTEXT_CALL_CONVENTION
  46. #endif
  47. #endif
  48. #elif defined(__MINGW32__) || defined(__MINGW64__)
  49. #if defined(__x86_64__)
  50. #define LIBCONTEXT_COMPILER_gcc
  51. #define LIBCONTEXT_PLATFORM_windows_x86_64
  52. #define LIBCONTEXT_CALL_CONVENTION
  53. #endif
  54. #if defined(__i386__)
  55. #define LIBCONTEXT_COMPILER_gcc
  56. #define LIBCONTEXT_PLATFORM_windows_i386
  57. #define LIBCONTEXT_CALL_CONVENTION __cdecl
  58. #endif
  59. #elif defined(__APPLE__) && defined(__MACH__)
  60. #if defined(__i386__)
  61. #define LIBCONTEXT_PLATFORM_apple_i386
  62. #define LIBCONTEXT_CALL_CONVENTION
  63. #elif defined(__x86_64__)
  64. #define LIBCONTEXT_PLATFORM_apple_x86_64
  65. #define LIBCONTEXT_CALL_CONVENTION
  66. #endif
  67. #endif
  68. #endif
  69. #ifdef __cplusplus
  70. namespace libcontext {
  71. #endif
  72. #if defined(_WIN32_WCE)
  73. typedef int intptr_t;
  74. #endif
  75. typedef void* fcontext_t;
  76. #ifdef __cplusplus
  77. extern "C" {
  78. #endif
  79. intptr_t LIBCONTEXT_CALL_CONVENTION jump_fcontext( fcontext_t* ofc, fcontext_t nfc,
  80. intptr_t vp, bool preserve_fpu = true );
  81. fcontext_t LIBCONTEXT_CALL_CONVENTION make_fcontext( void* sp, size_t size,
  82. void (* fn)( intptr_t ) );
  83. #ifdef __cplusplus
  84. } // namespace
  85. #endif
  86. #ifdef __cplusplus
  87. } // extern "C"
  88. #endif
  89. #endif