Linux是否在较低的堆栈末端下方提供了保证的不可访问的内存区域? [英] Does linux provide a guaranteed inaccessible memory area below the lower stack end?

查看:71
本文介绍了Linux是否在较低的堆栈末端下方提供了保证的不可访问的内存区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Linux是否在堆栈下端下方提供了无法访问的内存区域,该区域具有保证的最小大小?如果存在这样保证的最小尺寸,那是什么?

Does Linux provide an inaccessible memory area below the lower stack end that has a guaranteed minimum size? And if such a guaranteed minimum size exists, what is it?

或者换句话说,我什么时候应该开始担心alloca()或将指针提供给有效的非堆栈内存?

Or in other words, when should I start to worry about alloca() or so giving me pointers into valid, non-stack memory?

推荐答案

作为

如果不能扩展堆栈帧,则没有错误指示. (但是,分配失败后,该程序很可能会收到 如果尝试访问未分配的空间,则为SIGSEGV信号.)

There is no error indication if the stack frame cannot be extended. (However, after a failed allocation, the program is likely to receive a SIGSEGV signal if it attempts to access the unallocated space.)

所以根本没有任何指示,它还说:

So there is no indication at all and it also says:

如果分配导致堆栈溢出,则程序行为未定义.

If the allocation causes stack overflow, program behavior is undefined.

堆栈溢出问题是递归的一个普遍问题,并不是alloca的真正问题,或者说可变长度数组.通常,您要么需要找到一种方法来限制递归的深度,要么将其重构为迭代解决方案,要么使用自己的动态堆栈(可能不适用于这种情况).

The stack overflow problem is a general issue with recursion and not really particular to alloca or let's say variable length arrays. Typically you either need to find a way to limit the depth of the recursion, refactor to an iterative solution or use your own dynamic stack(probably does not apply to this case).

更新

OP发现 Linux确实会通过生成用于解决问题第一部分的SIGBUS信号,在堆栈溢出后使用保护页来提供事后指示.

As the OP discovered Linux does provide an after the fact indication using a guard page after the stack of stack overflow by generating a SIGBUS signal, which addresses the first part of the question.

这篇关于Linux是否在较低的堆栈末端下方提供了保证的不可访问的内存区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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