Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1 | From 0e054339c1422168a7f4a9dcf090268053a33b1f Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Thu, 20 Jul 2017 21:05:37 -0700 |
| 4 | Subject: [PATCH 2/5] wvtask: Dont use ucontext on non-glibc systems |
| 5 | |
| 6 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 7 | --- |
| 8 | utils/wvtask.cc | 24 ++++++++++++++++++++++++ |
| 9 | 1 file changed, 24 insertions(+) |
| 10 | |
| 11 | diff --git a/utils/wvtask.cc b/utils/wvtask.cc |
| 12 | index cdcd544..c0bff7d 100644 |
| 13 | --- a/utils/wvtask.cc |
| 14 | +++ b/utils/wvtask.cc |
| 15 | @@ -199,7 +199,9 @@ WvTaskMan::WvTaskMan() |
| 16 | stacktop = (char *)alloca(0); |
| 17 | |
| 18 | context_return = 0; |
| 19 | +#ifdef __GLIBC__ |
| 20 | assert(getcontext(&get_stack_return) == 0); |
| 21 | +#endif |
| 22 | if (context_return == 0) |
| 23 | { |
| 24 | // initial setup - start the stackmaster() task (never returns!) |
| 25 | @@ -265,13 +267,17 @@ int WvTaskMan::run(WvTask &task, int val) |
| 26 | state = &old_task->mystate; |
| 27 | |
| 28 | context_return = 0; |
| 29 | +#ifdef __GLIBC__ |
| 30 | assert(getcontext(state) == 0); |
| 31 | +#endif |
| 32 | int newval = context_return; |
| 33 | if (newval == 0) |
| 34 | { |
| 35 | // saved the state, now run the task. |
| 36 | context_return = val; |
| 37 | +#ifdef __GLIBC__ |
| 38 | setcontext(&task.mystate); |
| 39 | +#endif |
| 40 | return -1; |
| 41 | } |
| 42 | else |
| 43 | @@ -319,13 +325,17 @@ int WvTaskMan::yield(int val) |
| 44 | #endif |
| 45 | |
| 46 | context_return = 0; |
| 47 | +#ifdef __GLIBC__ |
| 48 | assert(getcontext(¤t_task->mystate) == 0); |
| 49 | +#endif |
| 50 | int newval = context_return; |
| 51 | if (newval == 0) |
| 52 | { |
| 53 | // saved the task state; now yield to the toplevel. |
| 54 | context_return = val; |
| 55 | +#ifdef __GLIBC__ |
| 56 | setcontext(&toplevel); |
| 57 | +#endif |
| 58 | return -1; |
| 59 | } |
| 60 | else |
| 61 | @@ -341,7 +351,9 @@ int WvTaskMan::yield(int val) |
| 62 | void WvTaskMan::get_stack(WvTask &task, size_t size) |
| 63 | { |
| 64 | context_return = 0; |
| 65 | +#ifdef __GLIBC__ |
| 66 | assert(getcontext(&get_stack_return) == 0); |
| 67 | +#endif |
| 68 | if (context_return == 0) |
| 69 | { |
| 70 | assert(magic_number == -WVTASK_MAGIC); |
| 71 | @@ -371,7 +383,9 @@ void WvTaskMan::get_stack(WvTask &task, size_t size) |
| 72 | // initial setup |
| 73 | stack_target = &task; |
| 74 | context_return = size/1024 + (size%1024 > 0); |
| 75 | +#ifdef __GLIBC__ |
| 76 | setcontext(&stackmaster_task); |
| 77 | +#endif |
| 78 | } |
| 79 | else |
| 80 | { |
| 81 | @@ -409,7 +423,9 @@ void WvTaskMan::_stackmaster() |
| 82 | assert(magic_number == -WVTASK_MAGIC); |
| 83 | |
| 84 | context_return = 0; |
| 85 | +#ifdef __GLIBC__ |
| 86 | assert(getcontext(&stackmaster_task) == 0); |
| 87 | +#endif |
| 88 | val = context_return; |
| 89 | if (val == 0) |
| 90 | { |
| 91 | @@ -419,7 +435,9 @@ void WvTaskMan::_stackmaster() |
| 92 | // all current stack allocations) and go back to get_stack |
| 93 | // (or the constructor, if that's what called us) |
| 94 | context_return = 1; |
| 95 | +#ifdef __GLIBC__ |
| 96 | setcontext(&get_stack_return); |
| 97 | +#endif |
| 98 | } |
| 99 | else |
| 100 | { |
| 101 | @@ -474,7 +492,9 @@ void WvTaskMan::do_task() |
| 102 | |
| 103 | // back here from longjmp; someone wants stack space. |
| 104 | context_return = 0; |
| 105 | +#ifdef __GLIBC__ |
| 106 | assert(getcontext(&task->mystate) == 0); |
| 107 | +#endif |
| 108 | if (context_return == 0) |
| 109 | { |
| 110 | // done the setjmp; that means the target task now has |
| 111 | @@ -510,7 +530,9 @@ void WvTaskMan::do_task() |
| 112 | } |
| 113 | else |
| 114 | { |
| 115 | +#ifdef __GLIBC__ |
| 116 | assert(getcontext(&task->func_call) == 0); |
| 117 | +#endif |
| 118 | task->func_call.uc_stack.ss_size = task->stacksize; |
| 119 | task->func_call.uc_stack.ss_sp = task->stack; |
| 120 | task->func_call.uc_stack.ss_flags = 0; |
| 121 | @@ -521,9 +543,11 @@ void WvTaskMan::do_task() |
| 122 | (void (*)(void))call_func, 1, task); |
| 123 | |
| 124 | context_return = 0; |
| 125 | +#ifdef __GLIBC__ |
| 126 | assert(getcontext(&task->func_return) == 0); |
| 127 | if (context_return == 0) |
| 128 | setcontext(&task->func_call); |
| 129 | +#endif |
| 130 | } |
| 131 | |
| 132 | // the task's function terminated. |
| 133 | -- |
| 134 | 2.13.3 |
| 135 | |