Acceptable Seg Faults?

php.internals

Ralph Schindler

19 years ago
The following script produces a seg fault: <? $class = new MyClass(); class MyClass { public function __construct() { $this->_start(); } public function _start() { $this->_myCall(); } public function _myCall() { $this->_start(); } } I assume this is b/c its recursively diving into Class function/method calls and we are filling memory.. Is this detectable? Should I file a bug report or is this known? Ideally it would be nice to see a fatal error thrown, if this is indeed detectable. PHP 5.1.6 / Linux 2.6 / Apache 2 [notice] child pid 6688 exit signal Segmentation fault (11) -Ralph

Johannes Schlueter

19 years ago
Yes, this is expected. Ralph Schindler wrote:

Stanislav Malyshev

19 years ago
> > I assume this is b/c its recursively diving into Class function/method > calls and we are filling memory.. Is this detectable? Should I file a > bug report or is this known? Ideally it would be nice to see a fatal > error thrown, if this is indeed detectable.
So far nobody had proposed a solution for endless loop problem that would satisfy these conditions: 1. No false positives (i.e. good code always works) 2. No slowdown for execution 3. Works with any stack size Thus, this problem remains unsloved.
-- Stanislav Malyshev, Zend Products Engineer stas@zend.com http://www.zend.com/

Unknown W. Brackets

19 years ago
Is it at all possible to determine in a cross-platform way: 1. The current stack position (e.g. SP, except on all architectures.) 2. The maximum stack size. I realize this is a naive question, but given the above - worst-case, an option (like memory_limit) could be added which tracks recursion depth or stack usage and triggers an error within an acceptable limit. Example: if you know each recursive PHP function call uses approximately X bytes of stack with its local variable table etc., and you know you have 2 megabytes of stack in your thread/process, you know you can only use a recursion depth of 2097152 / X, and you also know you won't have all of that. Thus you could prevent segfaults even on shared servers. Still, the solution is to have correct code. The above would either have false negatives and/or introduce a performance loss (check or at least inc per user-space function call) when compiled on. -[Unknown] -------- Original Message --------