1 /*
2  * Copyright (C) 2016 YunOS Project. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <k_api.h>
18 #include <k_config.h>
19 
20 #if (RHINO_CONFIG_STACK_OVF_CHECK_HW != 0)
cpu_intrpt_stack_protect(void)21 void cpu_intrpt_stack_protect(void)
22 {
23 }
24 
task_stack_crash_warning(void)25 void task_stack_crash_warning(void)
26 {
27     printf("****The task stack base has been broken !!!****\n");
28 }
29 
cpu_task_stack_protect(cpu_stack_t * base,size_t size)30 void cpu_task_stack_protect(cpu_stack_t *base, size_t size)
31 {
32     uint32_t base_addr = (uint32_t)base;
33 
34     int num_return = wp_register(base_addr, AWATCH, task_stack_crash_warning);
35     if (num_return == 1) {
36         wp_enable(1);
37     } else if (num_return == 2 || num_return == -1) {
38           wp_unregister(1);
39           int number_tmp = wp_register(base_addr, AWATCH, task_stack_crash_warning);
40           if (number_tmp == 1){
41               wp_enable(1);
42           }
43       }
44 }
45 #endif
46