Thus, you can access the thread_info structure by simply reading the stack pointer and masking the THREAD_SIZE bits (otherwise SP will initially be in the next THREAD_SIZE block).
static inline struct thread_info *current_thread_info(void) { register unsigned long sp asm ("sp"); return (struct thread_info *)(sp & ~(THREAD_SIZE - 1)); }
Eight bytes come from the ARM calling convention, which the SP should be aligned to 8 bytes.
Update: AAPCS 5.2.1.1 status:
A process can only access (read or write) the closed interval of the entire stack, limited by [SP, stack-base-1] (where SP is the value of register r13).
Since the stack is full downward
THREAD_START_SP (THREAD_SIZE - 8)
will apply this requirement, probably through illegal access to the next page (segmentation error).
auselen
source share