为什么堆栈必须页面对齐? [英] Why does the stack have to be page aligned?

查看:210
本文介绍了为什么堆栈必须页面对齐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux中,我试图(只是为了好玩)在process.c中创建内核源代码.c创建一个具有更多熵的堆栈地址,即特别是以下行:

In Linux, I've tried (just for fun) to modify the kernel source in process.c create a stack address that has more entropy, i.e. in particular the line:

sp -= get_random_int() % 8192;

当我对此进行过多更改时,内核停止运行,或者出现一些看似未定义的行为.我猜测这会导致PAGE_ALIGN()以某种方式失败?我对为什么PAGE_ALIGN()尤其是失败,或者内核中的哪段代码失败(虽然也很高兴知道)并不感兴趣;我对为什么堆栈必须完全驻留在特定区域中更感兴趣.这背后的架构原因和动机是什么?这与GDT/LDT在保护模式下的工作方式有关吗?

When I change this too much, the kernel halts or I get some seemingly undefined behavior. I'm guessing that this causes PAGE_ALIGN() to fail in some way? I'm not that interested in why PAGE_ALIGN() in particular fails, or exactly what piece of code in the kernel that fails (although that too would be nice to know); I'm more interested in why the stack must reside in a particular region at all. What is the architectural reason and motivation behind this? Does this have something to do with how GDT/LDT works in protected mode?

只是要弄清楚我在问什么:

Just to make clear what I'm asking:

为什么堆栈必须具有0xbfXXXXXX的格式(在32位上)?为什么不能像0xaaXXXXXX还是其他任何值?

Why does the stack have to have the form 0xbfXXXXXX (on 32-bit)? Why cannot the stack be e.g. 0xaaXXXXXX, or any other value?

推荐答案

do_page_fault()中存在一个限制,即在将vma认为是错误的访问权限之前,堆栈vma可以走多远,也许是您遇到了麻烦?

There is a limit in do_page_fault() as to how far outside the stack vma you can be before it considers it a bad access, perhaps you're hitting that?

这篇关于为什么堆栈必须页面对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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