init/main.c

 941         set_task_stack_end_magic(&init_task);


kernel/fork.c

 951 void set_task_stack_end_magic(struct task_struct *tsk)
 952 {
 953         unsigned long *stackend;
 954
 955         stackend = end_of_stack(tsk);
 956         *stackend = STACK_END_MAGIC;    /* for overflow detection */

stack 끝에 STACK_END_MAGIC 코드 넣어서 stack 넘침 여부 확인


 957 }


init/init_task.c

 60 /*
 61  * Set up the first task table, touch at your own risk!. Base=0,
 62  * limit=0x1fffff (=2MB)
 63  */
 64 struct task_struct init_task
 65 #ifdef CONFIG_ARCH_TASK_STRUCT_ON_STACK
 66         __init_task_data

__init_task_data : CONFIG_ARCH_TASK_STRUCT_ON_STACK 활성화된 경우

                             init_task의 위치를 ".data..init_task" section 으로

 

 67 #endif
 68         __aligned(L1_CACHE_BYTES)
 69 = {
 70 #ifdef CONFIG_THREAD_INFO_IN_TASK
 71         .thread_info    = INIT_THREAD_INFO(init_task),
 72         .stack_refcount = REFCOUNT_INIT(1),
 73 #endif
 74         .__state        = 0,
 75         .stack          = init_stack,
 76         .usage          = REFCOUNT_INIT(2),
 77         .flags          = PF_KTHREAD,
 78         .prio           = MAX_PRIO - 20,
 79         .static_prio    = MAX_PRIO - 20,
 80         .normal_prio    = MAX_PRIO - 20,
 81         .policy         = SCHED_NORMAL,
 82         .cpus_ptr       = &init_task.cpus_mask,
 83         .user_cpus_ptr  = NULL,
 84         .cpus_mask      = CPU_MASK_ALL,
 85         .nr_cpus_allowed= NR_CPUS,
 86         .mm             = NULL,
 87         .active_mm      = &init_mm,
 88         .restart_block  = {
 89                 .fn = do_no_restart_syscall,
 90         },
 91         .se             = {
 92                 .group_node     = LIST_HEAD_INIT(init_task.se.group_node),
 93         },
 94         .rt             = {
 95                 .run_list       = LIST_HEAD_INIT(init_task.rt.run_list),
 96                 .time_slice     = RR_TIMESLICE,
 97         },
 98         .tasks          = LIST_HEAD_INIT(init_task.tasks),

...

213 };
214 EXPORT_SYMBOL(init_task);

 


 26 static inline unsigned long *end_of_stack(const struct task_struct *task)
 27 {
 28 #ifdef CONFIG_STACK_GROWSUP
 29     return (unsigned long *)((unsigned long)task->stack + THREAD_SIZE) - 1;

stack 포인터가 아래에서 위로 증가 하는 경우 최상위 주소 반환


 30 #else
 31     return task->stack;
 32 #endif
 33 }

 


420 SYM_FUNC_START_LOCAL(__primary_switched)
421         adr_l   x4, init_task
422         init_cpu_task x4, x5, x6

 

397         .macro  init_cpu_task tsk, tmp1, tmp2
398         msr     sp_el0, \tsk

399
400         ldr     \tmp1, [\tsk, #TSK_STACK]
401         add     sp, \tmp1, #THREAD_SIZE
402         sub     sp, sp, #PT_REGS_SIZE

 

 

'linux' 카테고리의 다른 글

6.1/Head.S  (0) 2023.11.16
6.1/kaslr_requires_kpti(void)  (0) 2023.11.10
6.1/smp_setup_processor_id()  (0) 2023.02.23
Linux Kernel 6.1/start_kernel(void)  (0) 2023.02.09
Linux kernel 5.0 ARM64 Compile  (0) 2019.03.12

+ Recent posts