<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Feb 18, 2014 at 7:30 AM, Stefan Marr <span dir="ltr">&lt;<a href="mailto:smalltalk@stefan-marr.de" target="_blank">smalltalk@stefan-marr.de</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Hi:<br>
<div><div class="h5"><br>
On 18 Feb 2014, at 15:58, Sven Van Caekenberghe &lt;<a href="mailto:sven@stfx.eu">sven@stfx.eu</a>&gt; wrote:<br>
<br>
&gt; The VM could sure use stack overflow protection, it would/could help catch numerous &#39;hangs&#39; due to infinite loops.<br></div></div></blockquote><div><br></div><div>But Smalltalk, having a spaghetti stack composed of contexts needs a different approach. &nbsp; The stack guard page won&#39;t work. &nbsp;The original approach of waiting for space to run out and signalling the low space semaphore doesn&#39;t scale, and hasn&#39;t been well-maintained, often resulting in systems that lock-up before they open a debugger on an offending process when space is low (it can be difficult to pick the right process also). &nbsp;Counting the stack depth periodically is sloooow, but something the VM can optimize unsafely (e.g. imagine an inst var in Process that records a per-process stack depth, and imagine that is updated by the VM on process switch and that the VM can efficiently compute the stack depth of the part of the process&#39;s context chain that is mapped to stack pages in the stack zone; this is fine provided nothing edits the process&#39;s stack chain explicitly, as does e.g. Seaside). &nbsp;So this is not a trivial problem to solve satisfactorily.</div>
<div><br></div><div>To understand how we should implement this one really should understand the architecture of context-to-stack mapping in the Cog and Stack VMs. &nbsp;You can read my blog for that.</div><div><br></div><div>Here&#39;s a hack off the top of my head: &nbsp;Process contains an inst var which records the number of contexts it creates. &nbsp;This count is not accurate. &nbsp;In Cog and the Stack VM it records only contexts created when the VM evacuates a page of contexts. &nbsp;In the classic Interpreter VM we count context allocations). &nbsp;Whenever a process&#39;s context count exceeds a given threshold, its actual depth is counted (accurately) and if this exceeds a second threshold, the process is interrupted. &nbsp;These thresholds need to be known to the VM and hence be vm parameters.</div>
<div><br></div><div><br></div><div>Thoughts? &nbsp;Other ideas?</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
&gt;<br>
&gt; On 18 Feb 2014, at 13:08, Sebastian Sastre &lt;<a href="mailto:sebastian@flowingconcept.com">sebastian@flowingconcept.com</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; Hi there,<br>
&gt;&gt;<br>
&gt;&gt; Toyota shoot its foot and learnt how not to anymore.<br>
&gt;&gt;<br>
&gt;&gt; This is a nice read on the things our software do when the stack overflows.<br>
&gt;&gt; Are We Shooting Ourselves in the Foot with Stack Overflow?<br>
&gt;&gt; <a href="http://embeddedgurus.com/state-space/2014/02/are-we-shooting-ourselves-in-the-foot-with-stack-overflow/" target="_blank">http://embeddedgurus.com/state-space/2014/02/are-we-shooting-ourselves-in-the-foot-with-stack-overflow/</a><br>

&gt;&gt;<br>
&gt;&gt; The question on the table is<br>
&gt;&gt;<br>
&gt;&gt; are we following time proven safety rules when the same thing happen to our VM?<br>
<br>
</div></div>From the top of my head, I would expect operating systems for non-embedded devises to allocate a protected page at the end of the stack to detect stack overflows.<br>
And, most of the standard OSes should use Address Space Layout Randomization, which you need to turn off explicitly if you actually want to make sure that your stack is at a predefined position.<br>
<br>
I think, this article is really targeted towards embedded systems, where you might not even got a MMU.<br>
<br>
And, if you are interested in those things, it might be best to follow Eliot&rsquo;s suggestion and discuss it on the VM list.<br>
<br>
Best regards<br>
<span class="HOEnZb"><font color="#888888">Stefan<br>
<br>
--<br>
Stefan Marr<br>
INRIA Lille - Nord Europe<br>
<a href="http://stefan-marr.de/research/" target="_blank">http://stefan-marr.de/research/</a><br>
<br>
<br>
<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div>
</div></div>