在ARM Linux的,什么是在&QUOT保留的几个字节的目的;底部"为每个线程的内核栈 [英] In ARM Linux, what is the purpose of the few bytes reserved at the "bottom" of kernel stack for each thread

查看:219
本文介绍了在ARM Linux的,什么是在&QUOT保留的几个字节的目的;底部"为每个线程的内核栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在创建时的内核栈的底部保留​​的8个字节?

背景

我们知道,结构pt_regs 的thread_info 共享相同的2个连续的页(8192字节),与 pt_reg 位于下端高端和的thread_info
然而,我注意到,8个字节这些2页的最高地址保留:

在arch / ARM /有/ ASM / threadinfo.h

 的#define THREAD_START_SP(THREAD_SIZE  -  8)


解决方案

  

为什么在创建时的内核栈的底部保留​​的8个字节?



  1. 如果我们在栈上保留任何东西,它必须是8的倍数。

  2. 如果我们偷看栈上面,我们希望确保它被映射。

堆栈和用户寄存器需要被对准以8个字节。这只是使事情变得更加有效,因为许多臂具有64位总线和操作内核堆栈(如 LDRD STRD )可以具有这些要求。你可以看到<一个href=\"https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/arch/arm/kernel/entry-armv.S#n307\"相对=nofollow>在 usr_entry 宏的保护。具体来说,

 #如果定义(CONFIG_AEABI)及和放大器; (__LINUX_ARM_ARCH__&GT; = 5)及与放大器; (S_FRAME_SIZE和7)
#ERROR的sizeof(结构pt_regs)必须是8的倍数
#万一

的ARMv5(架构版本5)增加了 LDRD STRD 的说明。它也是在内核(相对于OABI)的EABI版本的要求。因此,如果我们在栈上保留任何东西,它必须是8的倍数。

偷看堆栈

对于非常顶部​​框架,我们可能想在previous数据的偷看。为了不经常检查堆栈在8K范围内的额外条目保留。具体来说,我认为信号需要在堆栈偷看。

Question:

Why are 8 bytes reserved at the "bottom" of kernel stack when it is created?

Background:

We know that struct pt_regs and thread_info share the same 2 consecutive pages(8192 bytes), with pt_reg located at the higher end and thread_info at the lower end. However, I noticed that 8 bytes are reserved at the highest address of these 2 pages:

in arch/arm/include/asm/threadinfo.h

#define THREAD_START_SP     (THREAD_SIZE - 8)

解决方案

Why are 8 bytes reserved at the "bottom" of kernel stack when it is created?

  1. If we reserve anything on the stack, it must be a multiple of eight.
  2. If we peek above the stack, we like to make sure it is mapped.

Multiple of eight

The stack and user register needs to be aligned to 8 bytes. This just makes things more efficient as many ARMs have a 64bit bus and operations on the kernel stack (such as ldrd and strd) may have these requirements. You can see the protection in usr_entry macro. Specifically,

#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (S_FRAME_SIZE & 7)
#error "sizeof(struct pt_regs) must be a multiple of 8"
#endif

ARMv5 (architecture version 5) adds the ldrd and strd instructions. It is also a requirement of the EABI version of the kernel (versus OABI). So if we reserve anything on the stack, it must be a multiple of 8.

Peeking on stack

For the very top frame, we may want to take a peek at previous data. In order not to constantly check that the stack is in the 8K range an extra entry is reserved. Specifically, I think that signals need to peek at the stack.

这篇关于在ARM Linux的,什么是在&QUOT保留的几个字节的目的;底部&QUOT;为每个线程的内核栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆