5 #if defined(__x86_64__)
9 using context_frame = context_frame_x86_64;
10 using context = context_x86_64;
13 #elif defined(__aarch64__)
17 using context_frame = context_frame_aarch64;
18 using context = context_aarch64;
22 #error "This architecture is not supported"
27 ITYR_TEST_CASE(
"[ityr::ito::context] save_context_with_call()") {
30 void* random_addr = (
void*)0x123456;
32 auto fn = [](context_frame* cf,
void* xp,
void* yp) {
35 ITYR_CHECK(cf->parent_frame == (
void*)0x123456);
38 context::save_context_with_call((context_frame*)random_addr, fn, &x, &y);
41 ITYR_TEST_CASE(
"[ityr::ito::context] save_context_with_call() and resume()") {
44 context::save_context_with_call(
nullptr, [](context_frame* cf1,
void* ok_,
void*) {
47 context::save_context_with_call(cf1, [](context_frame* cf2,
void* cf1_,
void*) {
48 context_frame* cf1 = (context_frame*)cf1_;
52 context::save_context_with_call(cf2, [](context_frame* cf3,
void* cf1_,
void* cf2_) {
53 context_frame* cf1 = (context_frame*)cf1_;
54 context_frame* cf2 = (context_frame*)cf2_;
63 }, (
void*)cf1, (
void*)cf2);
67 }, (
void*)cf1,
nullptr);
76 ITYR_TEST_CASE(
"[ityr::ito::context] call_on_stack()") {
80 size_t stack_size = 128 * 1024;
83 context::call_on_stack(stack_buf, stack_size,
84 [](
void* xp,
void* yp,
void* stack_buf,
void* stack_size_p) {
87 size_t stack_size = *((
size_t*)stack_size_p);
92 ITYR_CHECK((uintptr_t)stack_buf <= (uintptr_t)&a);
93 ITYR_CHECK((uintptr_t)&a < (uintptr_t)stack_buf + stack_size);
94 }, &x, &y, stack_buf, &stack_size);
99 ITYR_TEST_CASE(
"[ityr::ito::context] jump_to_stack()") {
100 size_t stack_size = 128 * 1024;
103 context::save_context_with_call(
nullptr, [](context_frame* cf,
void* stack_buf,
void* stack_size_p) {
104 size_t stack_size = *((
size_t*)stack_size_p);
108 *((uint8_t*)stack_buf + stack_size - 1) = canary;
111 context::jump_to_stack((uint8_t*)stack_buf + stack_size - 2,
112 [](
void* cf_,
void* stack_buf,
void* stack_size_p,
void* canary_p) {
113 context_frame* cf = (context_frame*)cf_;
114 size_t stack_size = *((
size_t*)stack_size_p);
115 uint8_t canary = *((
size_t*)canary_p);
120 ITYR_CHECK((uintptr_t)stack_buf <= (uintptr_t)&a);
121 ITYR_CHECK((uintptr_t)&a < (uintptr_t)stack_buf + stack_size);
124 ITYR_CHECK(*((uint8_t*)stack_buf + stack_size - 1) == canary);
127 ITYR_CHECK((uintptr_t)stack_buf <= (uintptr_t)&a);
128 ITYR_CHECK((uintptr_t)&a < (uintptr_t)stack_buf + stack_size);
132 }, cf, stack_buf, &stack_size, &canary);
136 }, stack_buf, &stack_size);
#define ITYR_CHECK(cond)
Definition: util.hpp:48
Definition: aarch64.hpp:5
void free(global_ptr< T > ptr, std::size_t count)
Definition: ori.hpp:75
global_ptr< T > malloc(std::size_t count)
Definition: ori.hpp:65