Guest User

Untitled

a guest
May 27th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #ifndef RBX_STACK_JUMPER_HPP
  2. #define RBX_STACK_JUMPER_HPP
  3.  
  4. #include "detection.hpp"
  5.  
  6. /** API to hide stack jump mechanism. */
  7.  
  8. #define RBX_SUBTEND_BY_UCONTEXT 1
  9.  
  10. #ifdef RBX_SUBTEND_BY_UCONTEXT
  11.  
  12. #include "subtend/PortableUContext.h"
  13.  
  14. #define HAS_UCONTEXT 1
  15.  
  16. /*
  17. * OS X 10.5's ucontext implementation is broken and requires
  18. * that we manually set up the additional mcontext fields so
  19. * that the ucontext_t's are sized up correctly. Otherwise they
  20. * get written over :/
  21. */
  22. #ifdef OS_X_10_5
  23. #define DECLARE_POINT_VARIABLE(name) ucontext_t name; \
  24. _STRUCT_MCONTEXT __ ## name ## _mc
  25. #else
  26. #define DECLARE_POINT_VARIABLE(name) ucontext_t name
  27. #endif
  28.  
  29. /** Externally used type name for the execution point. */
  30. typedef ucontext_t* ExecutionPoint;
  31.  
  32. /* Some alterable labels to create an API. Sadly #defines are a must here. */
  33. #define store_current_execution_point_in(uctx) getcontext((uctx))
  34.  
  35. #define jump_to_execution_point_in(uctx) setcontext((uctx))
  36.  
  37. #define create_execution_point_with_stack(uctx, stack, size) do { \
  38. getcontext((uctx)); \
  39. #ifndef OS_X_10_4
  40. (uctx)->uc_link = NULL; \
  41. (uctx)->uc_stack.ss_flags = 0; \
  42. #endif
  43. (uctx)->uc_stack.ss_sp = (char *)(stack); \
  44. (uctx)->uc_stack.ss_size = (size); } while (0)
  45.  
  46. #define set_function_to_run_in(uctx, func) makecontext((uctx), &(func), 0)
  47.  
  48. #endif /* RBX_SUBTEND_BY_UCONTEXT */
  49.  
  50.  
  51. #endif
Add Comment
Please, Sign In to add comment