X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fkernel%2Fao_task.c;h=048f5e67c6e39b58c4c0d5c633a9d77028297c10;hb=2dd10fcc43369129b1d5067f10365574a12943eb;hp=dd278bde064740f3ed0ac1a6ef11d90ccb85ab7c;hpb=7b1f4177d42e5e951a7db4289c847d355a785c2a;p=fw%2Faltos diff --git a/src/kernel/ao_task.c b/src/kernel/ao_task.c index dd278bde..048f5e67 100644 --- a/src/kernel/ao_task.c +++ b/src/kernel/ao_task.c @@ -57,7 +57,17 @@ static inline void ao_check_stack(void) { #endif #ifndef SLEEP_HASH_SIZE +#ifdef __ARM_FEATURE_IDIV__ #define SLEEP_HASH_SIZE 17 +#else +#define SLEEP_HASH_SIZE 16 +#endif +#endif + +#if SLEEP_HASH_SIZE & (SLEEP_HASH_SIZE - 1) +#define SLEEP_HASH_SHIFT 0 +#else +#define SLEEP_HASH_SHIFT 2 #endif static struct ao_list run_queue; @@ -75,7 +85,7 @@ _ao_task_to_run_queue(struct ao_task *task) static struct ao_list * ao_task_sleep_queue(void *wchan) { - return &ao_sleep_queue[(uintptr_t) wchan % SLEEP_HASH_SIZE]; + return &ao_sleep_queue[(((uintptr_t) wchan) >> SLEEP_HASH_SHIFT) % SLEEP_HASH_SIZE]; } static void @@ -297,6 +307,8 @@ ao_stack_top(struct ao_task *task) #endif } +#define AO_STACK_CANARY_VALUE 0xbaadf00dU + void ao_add_task(struct ao_task * task, void (*task_func)(void), const char *name) { @@ -314,6 +326,10 @@ ao_add_task(struct ao_task * task, void (*task_func)(void), const char *name) task->task_id = task_id; task->name = name; task->wchan = NULL; +#ifdef AO_STACK_CANARY + task->bottom_canary = AO_STACK_CANARY_VALUE; + task->top_canary = AO_STACK_CANARY_VALUE; +#endif /* * Construct a stack frame so that it will 'return' * to the start of the task @@ -331,6 +347,19 @@ ao_add_task(struct ao_task * task, void (*task_func)(void), const char *name) ); } +#ifdef AO_STACK_CANARY +static void +ao_check_stack_canary(void) +{ + if (ao_cur_task->bottom_canary != AO_STACK_CANARY_VALUE) + ao_panic(AO_PANIC_STACK); + if (ao_cur_task->top_canary != AO_STACK_CANARY_VALUE) + ao_panic(AO_PANIC_STACK); +} +#else +#define ao_check_stack_canary() +#endif + uint8_t ao_task_minimize_latency; /* Task switching function. */ @@ -346,6 +375,7 @@ ao_yield(void) ao_cur_task->max_run = run; ++ao_cur_task->yields; #endif + ao_check_stack_canary(); ao_arch_save_regs(); ao_arch_save_stack(); } @@ -388,6 +418,7 @@ ao_yield(void) #if USE_TLS _set_tls(ao_stack_top(ao_cur_task)); #endif + ao_check_stack_canary(); ao_arch_restore_stack(); }