<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Doing better &#187; Off-topic</title>
	<atom:link href="http://www.longacre-scm.com/blog/index.php/category/off-topic/feed" rel="self" type="application/rss+xml" />
	<link>http://www.longacre-scm.com/blog</link>
	<description>Opinions on CM, software development, and process automation from Longacre.</description>
	<lastBuildDate>Sat, 28 Aug 2010 21:23:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using Doxygen&#8217;s \test command with C++</title>
		<link>http://www.longacre-scm.com/blog/index.php/2010/08/using-doxygens-test-command-with-c</link>
		<comments>http://www.longacre-scm.com/blog/index.php/2010/08/using-doxygens-test-command-with-c#comments</comments>
		<pubDate>Sat, 28 Aug 2010 21:19:39 +0000</pubDate>
		<dc:creator>Austin Hastings</dc:creator>
				<category><![CDATA[Off-topic]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.longacre-scm.com/blog/?p=95</guid>
		<description><![CDATA[I&#8217;m working on some C++ code that is documented using Doxygen. Nothing earth-shattering there.
But I&#8217;m doing unit testing, and writing unit tests. In this case, I&#8217;m using the boost C++ libraries. That means my tests don&#8217;t look like classes, the way they might look if I was using CppUnit or CxxUnit. Instead, they look like [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on some C++ code that is documented using <a href="http://www.doxygen.org">Doxygen.</a> Nothing earth-shattering there.</p>
<p>But I&#8217;m doing unit testing, and writing unit tests. In this case, I&#8217;m using the <a href="http://www.boost.org">boost C++ libraries.</a> That means my tests don&#8217;t look like classes, the way they might look if I was using CppUnit or CxxUnit. Instead, they look like macros:<br />
<code><br />
BOOST_AUTO_TEST_CASE( null_ctor ) {</p>
<p>	Arena &#038; sut = Simple::Arena();<br />
	BOOST_CHECK( sut.capacity() != 0 );<br />
}<br />
</code></p>
<p>The macro expansion is really quite clever, in a Lovecraftian &#8220;there are secrets man was not meant to know&#8221; fashion. And reading them has certainly improved my knowledge of C++. (But it also permanently lowered my SAN by a few points, I think.)</p>
<p>Anyway, Doxygen offers this command called <b>\test</b> that seems tailor-made for testing.</p>
<p>Well, it&#8217;s not. The command description is very &#8220;vague,&#8221; in that you use it to add entries (paragraphs) to the &#8220;test list.&#8221; </p>
<p>Some experimentation will show that the apparent use is to document something (a class, a function) and add a bunch of these \test entries, just like adding \param commands. And the entity you are documenting will then have a <b>Test:</b> section in its documentation.</p>
<p>This is totally not what I want. And I&#8217;m pretty sure it&#8217;s not what anybody doing TDD wants. What I want is to somehow tie my tests, which are in a separate location (different file, different class, different namespace, etc.), back to the class or function that I&#8217;m testing.</p>
<p>The best way I&#8217;ve found so far to accomplish this is to <em>lie</em> to Doxygen about what is being documented. Here&#8217;s my current scheme:<br />
<code><br />
#define BOOST_TEST_DYN_LINK<br />
#include &lt;boost/test/unit_test.hpp&gt;</p>
<p>#include &lt;Bronze/Memory/Simple/Arena.h&gt;</p>
<p>using namespace Bronze::Memory;</p>
<p>BOOST_AUTO_TEST_SUITE( Memory_SimpleArena )</p>
<p>/// \class Bronze::Memory::Simple::Arena<br />
/// \test \b null_ctor Confims that a SimpleArena no-args construction will<br />
/// use the default size, whatever that is. (1m)</p>
<p>BOOST_AUTO_TEST_CASE( null_ctor ) {</p>
<p>	Arena &#038; sut = Simple::Arena();<br />
	BOOST_CHECK( sut.capacity() != 0 );<br />
}<br />
</code></p>
<p>Adding the <tt>\class</tt> command tells Doxygen to re-open the documentation of the target class. The <tt>\test</tt> command is then associated with the &#8220;right&#8221; class, and I include the testcase name in bold as part of the test description. </p>
<p>This still doesn&#8217;t generate a link to the right source file (containing the test), and it doesn&#8217;t really know anything about the test case. So it&#8217;s not a perfect solution. But it does enable me to put my testcase documentation with my testcases, while having the documentation actually show up attached to the right class.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.longacre-scm.com/blog/index.php/2010/08/using-doxygens-test-command-with-c/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Which &#8216;which&#8217; is which?</title>
		<link>http://www.longacre-scm.com/blog/index.php/2010/08/which-which-is-which</link>
		<comments>http://www.longacre-scm.com/blog/index.php/2010/08/which-which-is-which#comments</comments>
		<pubDate>Tue, 10 Aug 2010 22:13:27 +0000</pubDate>
		<dc:creator>Austin Hastings</dc:creator>
				<category><![CDATA[Off-topic]]></category>
		<category><![CDATA[Practice]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.longacre-scm.com/blog/?p=91</guid>
		<description><![CDATA[The &#8216;which&#8217; utility is one of those really useful commands that never seems to cross the bridge from Unix to Windows. The CMD.EXE special %$PATH:f syntax seems to promise some relief, but of course it&#8217;s never that simple &#8211; I at least want to type &#8220;which foo&#8221; rather than &#8220;which foo.exe&#8221;.
So here&#8217;s which.cmd &#8211; a [...]]]></description>
			<content:encoded><![CDATA[<p>The &#8216;which&#8217; utility is one of those really useful commands that never seems to cross the bridge from Unix to Windows. The CMD.EXE special %$PATH:f syntax seems to promise some relief, but of course it&#8217;s never that simple &#8211; <strong>I</strong> at least want to type &#8220;which foo&#8221; rather than &#8220;which foo.exe&#8221;.</p>
<p>So here&#8217;s <code>which.cmd</code> &#8211; a script that tries to DWIW. </p>
<p>Note that this script is wrong in one key detail: it searches inside-out. That is, any &#8220;foo.COM&#8221; will take precedence over any &#8220;foo.EXE&#8221; even if the .exe version occurs earlier in the PATH.</p>
<pre>
@echo off
REM Copyright (c) 2010, Austin Hastings.
REM This file may be used for any purpose without restriction.

REM NOTE: This script does not handle multiple entries with different
REM extensions correctly. It returns the first matching EXTENSION, rather
REM than returning the first DIRECTORY with any EXTENSION.

REM Analogous to unix 'which' command, look for a matching runnable
REM in %PATH% and print the location.

SETLOCAL ENABLEDELAYEDEXPANSION

set check_extensions= ;%PATHEXT%

:ext_loop
if "%check_extensions%" == "" goto done

for /F "tokens=1* delims=;" %%E in ( "%check_extensions%" ) do (
	set check_extensions=%%F
	set target=%1%%E
	for %%W in (  !target! ) do set answer=%%~f$PATH:W
)

if "%answer%" == "" goto ext_loop

:done
if "%answer%" == "" goto not_found

@echo %answer%
goto exit

:not_found
@echo No runnable matching '%1' was found.

:exit
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.longacre-scm.com/blog/index.php/2010/08/which-which-is-which/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some bash goodness</title>
		<link>http://www.longacre-scm.com/blog/index.php/2009/10/some-bash-goodness</link>
		<comments>http://www.longacre-scm.com/blog/index.php/2009/10/some-bash-goodness#comments</comments>
		<pubDate>Wed, 28 Oct 2009 15:09:48 +0000</pubDate>
		<dc:creator>Austin Hastings</dc:creator>
				<category><![CDATA[Off-topic]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.longacre-scm.com/blog/index.php/2009/10/some-bash-goodness</guid>
		<description><![CDATA[Here&#8217;s some bash goodness (well, not really) to make &#8216;less&#8217; a little bit more useful.
&#160;
less() {
 &#160; &#160; &#160; &#160;local -a args
&#160;
 &#160; &#160; &#160; &#160;for arg
 &#160; &#160; &#160; &#160;do
 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;case &#8220;$arg&#8221; in
 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;*:[[:digit:]]* )
 &#160; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<div>Here&#8217;s some bash goodness (well, not really) to make &#8216;less&#8217; a little bit more useful.</div>
<div>&#160;</div>
<div>less() {</div>
<div> &#160; &#160; &#160; &#160;local -a args</div>
<div>&#160;</div>
<div> &#160; &#160; &#160; &#160;for arg</div>
<div> &#160; &#160; &#160; &#160;do</div>
<div> &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;case &#8220;$arg&#8221; in</div>
<div> &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;*:[[:digit:]]* )</div>
<div> &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;line=${arg/#+(?):/}</div>
<div> &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;args[${#args[*]}]=&#8221;+$line&#8221;</div>
<div> &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;arg=${arg/%:+(?)/}</div>
<div> &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;;;</div>
<div> &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;esac</div>
<div>&#160;</div>
<div> &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;args[${#args[*]}]=$arg</div>
<div> &#160; &#160; &#160; &#160;done</div>
<div>&#160;</div>
<div> &#160; &#160; &#160; &#160;$( which less ) &#8220;${args[@]}&#8221;</div>
<div>}</div>
<div>&#160;</div>
<div>Basically, this shell function loads when you tell it to (in your .profile, likely), and it replaces the &#8216;less&#8217; command. When you type &#8216;less &#8230;&#8217; on the command line, the function runs.</div>
<div>&#160;</div>
<div>It scans through the args, looking for one like filename.c:24, and if it finds that kind of arg, it replaces it with +24 filename.c &#8212; translating the syntax used by a *lot* of compilers into the syntax used by less for opening a file and jumping directly to the line number.</div>
<div>&#160;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.longacre-scm.com/blog/index.php/2009/10/some-bash-goodness/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why not 2 stacks?</title>
		<link>http://www.longacre-scm.com/blog/index.php/2009/06/why-not-2-stacks</link>
		<comments>http://www.longacre-scm.com/blog/index.php/2009/06/why-not-2-stacks#comments</comments>
		<pubDate>Wed, 01 Jul 2009 00:05:13 +0000</pubDate>
		<dc:creator>Austin Hastings</dc:creator>
				<category><![CDATA[Off-topic]]></category>

		<guid isPermaLink="false">http://www.longacre-scm.com/blog/?p=76</guid>
		<description><![CDATA[I was googling around the other day for compiler wisdom when I stumbled on a computer security &#8220;research&#8221; paper. Some one or ones were postulating some theoretical result about vulnerability to buffer overflow attacks in blah, blah, blah special case. I didn&#8217;t read it, because that&#8217;s not what I was after.
But it made me think: [...]]]></description>
			<content:encoded><![CDATA[<p>I was googling around the other day for compiler wisdom when I stumbled on a computer security &#8220;research&#8221; paper. Some one or ones were postulating some theoretical result about vulnerability to buffer overflow attacks in <i>blah, blah, blah</i> special case. I didn&#8217;t read it, because that&#8217;s not what I was after.</p>
<p>But it made me think: how come Microsoft hasn&#8217;t just solved this problem already? Two &#8220;stacks&#8221; would wipe out the overflow attack problem at minimal cost.<br />
<span id="more-76"></span></p>
<h3>Back Story</h3>
<p>If you don&#8217;t know, here&#8217;s a very (!) short summary of the problem.</p>
<p>Computer software uses &#8220;subroutines&#8221; to do everything. In fact, even the &#8220;main&#8221; program is a subroutine. Because subroutines can call other subroutines, they can &#8220;stack up&#8221;. That is, &#8220;main&#8221; can call &#8220;sell ticket&#8221; which can call &#8220;print schedule&#8221; which can call &#8220;draw table&#8221;, etc.</p>
<h4>What&#8217;s a stack?</h4>
<p>In modern systems, there is no really good way to keep track of how many routines will get stacked up, a general-purpose data structure called a &#8220;stack&#8221; is used. This is so important that CPU&#8217;s explicitly support a single &#8220;call stack&#8221; with special CPU instructions like push and pop, special registers to access the stack, and all kinds of <i>incredibly expensive</i> stuff. </p>
<p>A stack works by &#8220;stacking&#8221; data, in much the same way they stack plates at a buffet restaurant (or cafeteria). The only data item you can get to is the one at the &#8220;top&#8221; of the stack. (The only plate you can take is the one on the top of the stack. See?) If you want to put on more data, it goes on the top of the stack, and the stack grows. If you want to take off data, you take it off the top of the stack, and the stack shrinks.</p>
<p>In this case, though, there are two ways to think about what &#8220;data&#8221; means. One way is to think of data as being individual units. One number goes on the stack, then another number goes on top of it, etc. But another way is to think of data &#8220;sets&#8221; going on the stack. If you think about the back button on your web browser, it acts like a stack. You click on a link, and a page gets <strong>pushed</strong> on to the &#8220;history&#8221; in the browser. You click &#8220;Back&#8221; and a page gets <strong>popped</strong> off the stack, leaving a different page visible in the browser. But these pages aren&#8217;t just a single number. There&#8217;s a URL, the page contents, maybe some form data, etc.</p>
<p>In terms of computer subroutines, each subroutine may have some &#8220;local data&#8221; that it needs to store. The URL of a web page, or the name of the current user, for example. And this data is expected to be used within the subroutine, maybe passed down into any sub-subroutines that get called, and then it will disappear when the subroutine finishes. </p>
<p>So a subroutine may have a bunch of local data, much like a web page in your browers. That can also be managed as part of a stack, using what is called a <em>stack frame</em>. A stack frame is a collection of data that all gets jammed onto the stack at one time, so the subroutine can use it. Again,&#8221;modern CPUs&#8221; (pretty much all of them built since the 1970&#8217;s) support this directly.</p>
<h4>How important is the stack?</h4>
<p>The de facto standard computer in the world today is the Intel x86 CPU of some kind: Pentium, Opteron, whatever you want to call it. Back when dinosaurs roamed the earth and nobody thought a 16-bit computer was worth the extra money over a 8-bit computer, the x86 family had about 30,000 transistors on board. Now, when people are arguing the relative merits of 32 versus 64 bit computing, the transistor count is about a billion.</p>
<p>The x86 family of computers work using &#8220;registers.&#8221; A register is a place in the center of the CPU where a number can be held while other stuff gets done to it. If you want to add two numbers, you use a register. If you want to store the result, you probably use another register. They are absolutely crucial to the design of the x86, and most other widespread CPUs. (There are alternative architectures: stack based and accumulator based CPUs. But nobody buys them except for special applications.)</p>
<p>The x86 registers back in the time of the 8088 and 8086 computer were called:</p>
<ul>
<li><tt>AX</tt> The <em>accumulator</em> register, best for math.</li>
<li><tt>BX</tt> The <em>base address</em> register, best for pointer references.</li>
<li><tt>CX</tt> The <em>counter</em> register, best for loop counts.</li>
<li><tt>DX</tt> The <em>data</em> register, used for multiply/divide operations, I/O operations, and indirect addressing.</li>
<li><tt>SI</tt> The <em>source index</em> register, for memory-to-memory block operations, like copying data.</li>
<li><tt>DI</tt> The <em>destination index</em> register, used for memory block operations, like SI.</li>
<li><tt>BP</tt> The <em>base pointer</em> register, used to point to the base of the stack frame.</li>
<li><tt>SP</tt> The <em>stack pointer</em> register, used to point to the current &#8220;top&#8221; of the stack.</li>
</ul>
<p>There were some additional registers, like IP, flags, CS, DS, ES, and SS. But they weren&#8217;t (and still aren&#8217;t) general purpose registers, can&#8217;t participate in computations, and generally don&#8217;t get modified much by programs. Because the registers listed above are <em>general purpose</em> registers, they can be used for things not listed above. For example, if you need to store a temporary intermediate result while you are computing some other value, you can always jam it into the DI register. (or SI, or DX, or whatever you like). But not BP or SP.</p>
<p>So back in the day, when we had to carve our own computers out of rocks using nothing buy a bronze chisel and a wooden mallet, BP and SP were given over to the stack frame. That&#8217;s two registers <em>out of eight</em> &#8212; 25%, for you liberal arts majors &#8212; assigned to do the job of keeping track of the stack.</p>
<h4>And now?</h4>
<p>When the 80&#215;86 family went 32-bit, the registers changed. The 32-bit registers were called &#8220;extended&#8221; registers, and so the names became: <tt>eax, ebx, ecx, edx, edi, esi, ebp, esp</tt>. </p>
<p>Now, with the advent of the 64-bit x86 family, the names have changed again: <tt>rax, rbx, rcx, rdx, rsi, rdi, rbp, rsp.</tt> But in addition, AMD added 8 new registers to the x64 architecture, and Intel followed suit.</p>
<p>This means that if you&#8217;re using a 32-bit CPU, or a 64-bit CPU in compatibility mode, you&#8217;re using 8 registers, still, and 2 of them are dedicated to the stack, still. (25%, still, for you liberal arts majors.) If you&#8217;re using a 64-bit CPU in 64-bit mode, then you&#8217;ve got 16 registers (that&#8217;s 12.5% for all you Art History grads).</p>
<p>So the stack frame, and the stack pointer, and this whole stack &#8220;thang&#8221; are pretty important.</p>
<h3>What&#8217;s a buffer overflow attack?</h3>
<p>So there&#8217;s a stack, and your subroutines use it. The most obvious way they can use it is to store a &#8220;return address&#8221; on it. If you have a subroutine called sub_1, it might have the stack set up like this:</p>
<pre>
    :
  ????
  ????
  1234 < -- SP
</pre>
<p>Where the SP (stack pointer) points to 1234. What's 1234? Well, it's the return address -- an address is a location in computer memory -- where it will send program control when it finishes doing whatever it is doing.</p>
<p>And if the sub_1 routine calls a sub_2 routine, the stack will look like:
</pre>
<pre>
    :
  ????
  ????
  1234
  1299 < -- SP
</pre>
<p>When the CPU executes a <tt>call</tt> instruction, it pushes the return address (of the instruction right after the call) onto the stack automatically. (And yes, on Intel platforms the stack always goes down instead of up. Don't ask why, it doesn't matter.)</p>
<p>When the sub_2 routine returns control to sub_1, it pops the stack and uses the address that it gets to branch back.
</pre>
<pre>
    :
  ????
  ????
  1234 < -- SP
  1299
</pre>
<p>Of course the 1299 is still down there -- it doesn't get erased. Instead, the SP adds 4 (4 is the size of a return address on a 32-bit [4 byte] CPU) and we go on. Very efficient, very fast, and very automatic with all the special instruction support.</p>
<h4>Stack Frames, redux</h4>
<p>When the program has local data it needs to store, the situation gets a little more complex. The caller pushes a return address, then the callee (the local subroutine) moves the stack pointer a little bit more, to make room. If sub_2 needs 12 bytes of storage, the <em>preamble</em> of the subroutine looks like this:
</pre>
<pre>
   push(ebp)
   ebp = esp
   esp = esp - 12
</pre>
<p>A preamble is a standard set of code that gets executed at the top of every function. It is generated automatically by the compiler &#8212; programmers don&#8217;t have to think about inserting it.</p>
<p>When it comes time to clean up and leave the subroutine, the corresponding code is the <em>postamble</em> and it does something like:</p>
<pre>
   esp = esp + 12
   pop ebp
   return
</pre>
<p>(In fact, this is wrong. But the effect is the same and it&#8217;s easier for you to understand.)</p>
<p>Before the subroutine is called, the stack looks like:</p>
<pre>
    :
  ????
  ????
  1234   < -- SP
</pre>
<p>Then when the call happens, the stack looks like:
</pre>
<pre>
    :
  ????
  ????
  1234
  1299  < -- SP
</pre>
<p>Then when the preamble runs, we get:
</pre>
<pre>
    :
  ????
  ????
  1234
  1299
   BP'  < -- BP
   ?
   ?
   ?     <-- SP (12 bytes = 3 x 32bit words of "stack frame" storage)
</pre>
<p>Note that the new BP is pointing to the place on the stack where the previous BP was stored.</p>
<h4>So?</h4>
<p>So there's a stack frame, and it's a little complex, and it's sitting there on the stack. And in the middle of that stack is the "local data" the subroutine needs.</p>
<p>Sometimes the "local data" includes what is called a "buffer." A buffer is just a space to store a bunch of characters in a row. For example, if the program is going to ask me for my name and address, it needs a place to store however-many characters go into a name and address.</p>
<p>If the buffer is 12 bytes long, I could enter my name as "Austin" and there would be not problem. But if I entered "Austin Hastings" (14 letters, with the space) the buffer would not be long enough to store the name. The problem is that if I am allowed to just enter any old thing, I might deliberately do something destructive. Suppose we are using our previous example:
</pre>
<pre>
    :
  ????
  ????
  1234
  1299
   BP'  < -- BP
   ?
   ?
   ?     <-- SP (12 bytes = 3 x 32bit words of "stack frame" storage)
</pre>
<p>If I type my name as "Austin Hastings", the buffer overflows, like this:
</pre>
<pre>
    :
  ????
  ????
  1234
  1299
  ngs   < -- BP
  asti
  in H
  Aust  <-- SP
</pre>
<p>The old value of BP gets wiped out, and so the calling subroutine will have a bunch of bogus data (because it accesses all the local variables relative to where BP is pointing).</p>
<p>But if I type my name as "Austin Hastings.1215" look what happens to the return address that is supposed to point to the subroutine that called us:
</pre>
<pre>
    :
  ????
  ????
  1234
  1215    -- look here!
  ngs.   < -- BP
  asti
  in H
  Aust  <-- SP
</pre>
<p>See? The return address got changed by me typing in a special, too-long name. This is called a "buffer overflow attack", and if done right it can cause the subroutine to return control to a new program, written by the attacker.</p>
<h3>Why can Microsoft solve the problem?</h3>
<p>First, Microsoft writes Windows, the most attacked system in the world. And it writes the Microsoft C/C++ compiler, which is the tool of choice for compiling on Windows. Since anything Microsoft does will get copied by the Linux and Apple guys, this is a no-brainer. If Microsoft solves the problem, everyone will copy them and solve the problem for their own sites.</p>
<h3>Okay, <em>how</em> can Microsoft solve the problem?</h3>
<p>The solution to the "attack" part of the problem is to use two stacks. There are two registers already, and one of them rarely gets used (SP). So split them into two different stacks, and you eliminate the ability of an attacker to overwrite the return address (by separating the stack frame data from the "just-a-stack" data).</p>
<h4>Details</h4>
<p>Here's what the previous example would look like with two stacks.
</pre>
<pre>
  "Frames":          "Stack":
      :                1234
    ????               EBP(1)  < -- SP(2)
    ????  <-- BP(2)    1299
    ....               EBP(2)  <-- SP(3)
    ....
    ....  <-- BP(3)
</pre>
<p>Notice that I've drawn the buffer as dots, and whatever was in the caller's local data as question marks. Notice also that the important data -- the frame pointers and return addresses -- are in a totally different place from the stack frame data. This means that no buffer overflow attack can reach them. </p>
<h4>That's it?</h4>
<p>Yep. That's it.</p>
<p>Mind you, it's an expensive it. But not a horribly expensive one. Microsoft, and the GCC folks, and Intel, and anybody else that writes a compiler, would have to come up with a transition plan to take us from one system to another. It would probably easier for Microsoft, since they can deliver their system (Windows) all at once. This recompile would have to happen for almost every problem, so it might take a while for total coverage. But the "most attacked" programs are things like email servers, web servers, the PHP interpreter, etc. There is a pretty short list of those, and getting them secured might take an hour and a half, if everyone would work together.</p>
<h4>Any problems with this idea?</h4>
<p>First, it doesn't just magically make everything work. Some solutions, like W(+)E, try to do that. If you can just "solve it in hardware" then the problem goes away without messing around with that 23-year-old program that the boss uses but nobody has the source for.</p>
<p>Second, this approach doesn't require anybody to buy a new computer. (But keep reading!) So unless Microsoft forces an upgrade with Windows 7 or 8 or whatever (and when have they ever forced an upgrade?) there's no money in it for the CPU vendors.</p>
<p>Also, don't forget that this only protects against buffer overrun attacks that try to force code execution. It won't protect you from corruption of <em>data</em> that is in a stack frame buffer or local variable. Someone might try to rewrite their account balance, or change your password, or whatever. </p>
<h4>Checksum the Stack Frame</h4>
<p>There's a solution for that, too. And it could involve new hardware. Just create a "checksum" value for the stack frame, and put it right at the end of each subroutine's frame. That way, if an attacker overruns a buffer it will destroy the checksum. </p>
<p>Obviously I don't mean a real checksum. What I mean is something unpredictable, unlikely to occur at random, and easily checked. Most of the registers wouldn't work, since their values are generally predictable. It would make sense to create a dedicated register for this on the CPU -- which would also allow Intel to make some new hardware -- and push the "random" value on both the frame stack and the SP stack (for checking).</p>
<h3>If you're so damn smart, why aren't you rich?</h3>
<p>I used to do a lot of assembly programming. So I've always kind of wondered why this wasn't obvious to everybody else. And it may well be that there's some critical flaw in the logic. Probably having to do with interrupt-proofing the two-stack transition. </p>
<p>But maybe there's not. Maybe it's just obvious to me. In which case, I hereby demand that anyone who implements this must call it "Austin's Device". And if you implement the checksum idea, that shall be "Austin's Other Device." </p>
<p>But there's an old joke about an Economics professor and one of his grad students walking across the quad. And the grad student says, "Look, professor! There's a $100 bill lying on the ground."</p>
<p>To which the professor replies, "Don't be absurd. If there were really a $100 bill lying on the ground, someone would pick it up."</p>
<p>Maybe you know what's wrong with my clever device? If so, please let me know.</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.longacre-scm.com/blog/index.php/2009/06/why-not-2-stacks/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Things left unsaid&#8230;</title>
		<link>http://www.longacre-scm.com/blog/index.php/2009/06/things-left-unsaid</link>
		<comments>http://www.longacre-scm.com/blog/index.php/2009/06/things-left-unsaid#comments</comments>
		<pubDate>Sat, 27 Jun 2009 23:15:18 +0000</pubDate>
		<dc:creator>Austin Hastings</dc:creator>
				<category><![CDATA[Off-topic]]></category>

		<guid isPermaLink="false">http://www.longacre-scm.com/blog/?p=69</guid>
		<description><![CDATA[In my copious spare time I&#8217;m working on a programming language called &#8220;Close.&#8221; It&#8217;s a C-like systems programming language targeted at the Parrot VM.
Now, I&#8217;m not a compiler guy. But I don&#8217;t have to be. Because Parrot comes with the Parrot Compiler Toolkit (PCT), a set of code that can render an Abstract Syntax Tree [...]]]></description>
			<content:encoded><![CDATA[<p>In my copious spare time I&#8217;m working on a programming language called &#8220;Close.&#8221; It&#8217;s a C-like systems programming language targeted at the <a href="http://www.parrot.org">Parrot VM.</a></p>
<p>Now, I&#8217;m not a compiler guy. But I don&#8217;t have to be. Because Parrot comes with the Parrot Compiler Toolkit (PCT), a set of code that can render an Abstract Syntax Tree (AST) into executable code. The result is that I built a grammar using Perl6, then wrote some action methods hooked to the grammar that built the AST. Then I stood back and let PCT do it&#8217;s voodoo. The time between starting the project and now has been about 3 weeks, and I was busy with other stuff for 30 percent or so of that.</p>
<p>Okay, that&#8217;s cool. Parrot+PCT rocks, as Allison Randal <a href="http://www.linux-mag.com/cache/7373/1.html">points out</a>. But it&#8217;s not my point. The reason I wrote Close was because people were still coding in PIR &#8212; Parrot&#8217;s version of assembly language &#8212; years after starting the project. D&#8217;oh! Everybody knows that the first thing you do with a new architecture is develop a C compiler.</p>
<p>Well, somebody had to do it. So I stepped up. I talked a little bit about it at the Parrot Virtual Machine Workshop last week in Pittsburgh, and some other people acted interested. As a result, it&#8217;s up on Google code at http://close.googlecode.com. But the key for me was a conversation I had with Uri Guttman in a hallway at <a href="http://yapc10.org/yn2009/">YAPC10</a> (the conference to which the PVMW was attached).</p>
<p>I showed Uri this code:</p>
<pre>
void test_foreach()
{
	pmc the_list = new ResizableStringArray;
	push the_list, "alpha", "beta", "gamma", "delta", "omega";

	pmc new_list = new ResizableStringArray;
	int count = 0;

	foreach (str i: the_list) {
		push new_list, i;
		++count;
	}

	ok(count, 5, "f/e Iterate over each element");

	count = 0;
	int pass = 1;

	foreach (i : new_list) {
		if (i != the_list[count++]) {
			pass = 0;
		}
	}

	ok(pass, "f/e Same items, same order");
}
</pre>
<p>And Uri read through it, figured out what I was doing, and said, &#8220;Well, I don&#8217;t like your coding style. And I really don&#8217;t like single letter variable names, even inside a loop.&#8221;</p>
<p>And my first reaction was &#8220;Up yours, bud!&#8221; But I swallowed that, and then it hit me: I won!</p>
<p>The whole point of implementing Close was to stop writing code that looks like this:</p>
<pre>
.sub 'uniquereg' :method
    .param string rtype
    unless rtype goto err_nortype
    if rtype == 'v' goto reg_void
    .local string reg
    reg = 'P'
    $I0 = index 'Ss~Nn+Ii', rtype
    if $I0 < 0 goto reg_psin
    reg = substr 'SSSNNNII', $I0, 1
  reg_psin:
    reg = concat '$', reg
    .tailcall self.'unique'(reg)
  reg_void:
    .return ('')
  err_nortype:
    self.'panic'('rtype not set')
.end
</pre>
<p>And so what occurred to me was that I showed Uri some code that <em>didn't</em> look like that. It looked like C. And so naturally he read it. And he commented on something that was relevant to him. Not "Gee, I can read your code!" but "Of course I can read your code -- it's C. But I don't like your curly braces."</p>
<p>Win. Win. Win. </p>
<p>Hearing what Uri did <strong>not</strong> say was the key.</p>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.longacre-scm.com/blog/index.php/2009/06/things-left-unsaid/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Three</title>
		<link>http://www.longacre-scm.com/blog/index.php/2009/01/three</link>
		<comments>http://www.longacre-scm.com/blog/index.php/2009/01/three#comments</comments>
		<pubDate>Thu, 22 Jan 2009 11:52:13 +0000</pubDate>
		<dc:creator>Austin Hastings</dc:creator>
				<category><![CDATA[Off-topic]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[monitors]]></category>

		<guid isPermaLink="false">http://www.longacre-scm.com/blog/?p=49</guid>
		<description><![CDATA[
As you can probably tell, my three LCD monitors are all present and accounted for. And yeah, before you ask, it ROCKS!
One very interesting &#8220;problem&#8221; is that none of the monitors I received shipped with a DVI cable. I have no idea why that is &#8212; all of the smaller LCD monitors I saw last [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.longacre-scm.com/blog/wp-content/uploads/2009/01/img4-2.jpg"><img src="http://www.longacre-scm.com/blog/wp-content/uploads/2009/01/img4-2-300x169.jpg" alt="" title="img4-2" width="300" height="169" class="alignnone size-fullsize wp-image-50" /></a></p>
<p>As you can probably tell, my three LCD monitors are all present and accounted for. And yeah, before you ask, it ROCKS!</p>
<p>One very interesting &#8220;problem&#8221; is that none of the monitors I received shipped with a DVI cable. I have no idea why that is &#8212; all of the smaller LCD monitors I saw last summer came out of the box with both VGA and DVI cables, but these bigger, high-dollar products came with just VGA.</p>
<p>But that&#8217;s not a problem, because while the first monitor was a nice <a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16824254035">Hanns-G</a>, which I plugged in to the VGA output from my laptop docking station, the other two are even nicer &#8212; they&#8217;re <a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16824236038">ASUS VW223-B</a> monitors with &#8220;EzLink&#8221; (ASUS&#8217;s feature name for <a href="http://www.displaylink.com">DisplayLink&#8217;s</a> technology).</p>
<p>I found the two monitors on clearance from NewEgg.com. They were $159 plus NJ sales tax, call it $175 each. Apparently part of the clearance was getting rid of the products entirely, since the products are now shown as &#8220;Deactivated Item&#8221; on NewEgg&#8217;s site. </p>
<p>The DisplayLink/EzLink technology is an on-the-fly compression mechanism that sends video requests (probably just re-encoding Direct-X requests, but it might be something different) over USB. I wondered how well that technology would perform, but I was planning on buying a USB/VGA adapter device and finding out. Well, no need. </p>
<p>Both of the ASUS monitors are plugged in to USB, since they didn&#8217;t include a DVI adapter and since my Hanns-G is already taking up the VGA output port. And they work swimmingly. Not only is the display nice, but you can watch videos and other streaming media over the USB connection. I will admit that my limited experiment, watching three (different) videos on three different monitors at the same time, seemed to show some &#8220;snow&#8221; in the video images of the ASUS (USB linked) monitors. I&#8217;m guessing that this is a compression artifact, with the drivers sacrificing video in factor of speed. If that&#8217;s true, they&#8217;re doing it exactly right. The result was kind of like watching a slightly imperfect broadcast (over-the-air) television signal: a little fuzz, and some salt/pepper, but the underlying picture was clear.</p>
<p>The DisplayLink drivers installed smoothly, and once installed the driver had no problem picking up when I plugged in the third monitor. That little Windows &#8220;de-dum&#8221; sound for a new USB device, and I could instantly extend the desktop one more time. The monitors can be controlled from the taskbar, including specifically a rotation option. Also, the monitors appear in the standard Windows Display control panel, so you can specify location and resolution.</p>
<p><a href="http://www.longacre-scm.com/blog/wp-content/uploads/2009/01/display-properties.jpg"><img src="http://www.longacre-scm.com/blog/wp-content/uploads/2009/01/display-properties-150x150.jpg" alt="Snapshot of Display Properties dialog showing locations, orientation" title="display-properties" width="150" height="150" class="alignnone size-thumbnail wp-image-52" /></a></p>
<p>As you can see in the above image, setting the rotation causes the correct data to be reflected back to windows. And you&#8217;ll have to take my word for it, but you can get a LOT of lines of code onto a 22&#8243; monitor in portrait mode. Here&#8217;s the bottom of a <a href="http://www.scintilla.org/SciTE.html">Scite</a> window, where the top of the window is showing top-of-file:</p>
<p><a href="http://www.longacre-scm.com/blog/wp-content/uploads/2009/01/scite-cpp-bottom.jpg"><img src="http://www.longacre-scm.com/blog/wp-content/uploads/2009/01/scite-cpp-bottom-150x150.jpg" alt="" title="scite-cpp-bottom" width="150" height="150" class="alignnone size-thumbnail wp-image-53" /></a></p>
<p>Yes, that&#8217;s 104 lines of source code on a single screen. Given that subroutines and methods are supposed to fit &#8220;on a single page,&#8221; I may have discovered the ultimate solution to <em>all</em> refactoring problems.</p>
<p>This is so cool!</p>
<p>One thing worth pointing out is that the monitors themselves do not support rotation. They come with the kind of cheap plastic stand that you would expect. Instead, I bought a third-party monitor stand from the <a href="http://www.ergotechgroup.com/products/heavy-duty-17-30-36/triple-lcd-desk-stand-62/">Ergotech Group.</a> They don&#8217;t have an on-line store, but rely on other vendors for retail sales. I found a bunch of places where I could choose to pay about a million dollars for that stand, and then I found <a href="http://www.pcconnection.com/IPA/Shop/Product/Detail.htm?sku=9018451">PC Connection,</a> where $250 seemed like a bargain. </p>
<p>All told, the monitors ($522) and the stand ($267) cost me $790. Sitting here, beginning to develop retinal cancer from the massive volume of monitor-light being blasted at my eyes, it was totally worth it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.longacre-scm.com/blog/index.php/2009/01/three/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting L A R G E R</title>
		<link>http://www.longacre-scm.com/blog/index.php/2009/01/getting-l-a-r-g-e-r</link>
		<comments>http://www.longacre-scm.com/blog/index.php/2009/01/getting-l-a-r-g-e-r#comments</comments>
		<pubDate>Fri, 16 Jan 2009 08:22:53 +0000</pubDate>
		<dc:creator>Austin Hastings</dc:creator>
				<category><![CDATA[Off-topic]]></category>

		<guid isPermaLink="false">http://www.longacre-scm.com/blog/?p=44</guid>
		<description><![CDATA[I just spent a bunch of time out west (which, since I live on the east coast, isn&#8217;t saying much) working with a client trying to do agile development. I have a kind of gentlemen&#8217;s agreement with the client that I won&#8217;t write anything that makes them look too bad. Presumably, they&#8217;ll be kind enough [...]]]></description>
			<content:encoded><![CDATA[<p>I just spent a bunch of time out west (which, since I live on the east coast, isn&#8217;t saying much) working with a client trying to do agile development. I have a kind of gentlemen&#8217;s agreement with the client that I won&#8217;t write anything that makes them look too bad. Presumably, they&#8217;ll be kind enough to do the same thing for me <img src='http://www.longacre-scm.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>That said, I want to talk about something that I absolutely cannot stand about the development environment out there:  They have really big monitors, usually two per pairing station. And I don&#8217;t.</p>
<p>It&#8217;s a little bit surprising how easy it was to get used to working with multiple monitors. In fact, towards the end of the engagement I got moved in to a cubicle that had three monitors in it &#8211; one for the old user&#8217;s laptop, one for a desktop that was sitting there, and one small one unused. Since I was bringing two monitors with me, that took me up to five monitors. Sadly, I couldn&#8217;t talk the IT guys into buying the Lenovo advanced docking station that supported a plug-in video controller, or I&#8217;m sure I could have driven all five monitors off my laptop.</p>
<p>Now, you might be asking &#8220;what on earth could you do with five monitors?&#8221; And, you know, I&#8217;m not entirely sure myself. But I would surely have loved to find out. In the meantime, I got away with using <a href="http://synergy2.sourceforge.net/">Synergy</a> to share my laptop&#8217;s keyboard and mouse with another computer, and then drove three monitors from my laptop with a USB video adapter. </p>
<p>What can I do with four monitors? One of them was my designated remote desktop box, for connecting to the Windows servers the team was using. The other three? Well, whatever I wanted. </p>
<p>I almost always had Firefox open in one monitor, maximized. Because I was almost always working on something that required frequent reference to online forums or documentation. CM consultants never spend much time in the &#8220;well documented, easy to configure&#8221; part of the system. Go figure.</p>
<p>Sometimes I had email open in another monitor, but more often I had a text editor maximized. And then I stuck a couple of shell windows (MSYS, Powershell, Cygwin, rxvt, whatever it takes) in the other monitor. And then I silently wished that I could have gotten that fifth monitor up, because sometimes you need to RDP into two different remote servers, in order to test a deployment script. </p>
<p>So, yeah. I&#8217;m addicted to having multiple monitors. LOTS of them. And my addiction is growing. Two monitors, which I&#8217;m using now, just isn&#8217;t enough anymore. So I&#8217;ve taken steps. I&#8217;m ordering more monitors. And a monitor stand to hang them from, because that was one thing that I didn&#8217;t have out west. And this time, they&#8217;re going to be BIG. </p>
<p>Apparently, Alienware hasn&#8217;t released their <a href="http://www.youtube.com/watch?v=2yT6OuGXmGo&#038;feature=channel">promised</a> 3&#8242;-wide ubermonitor, but Panasonic <em>has</em> got a 103&#8243; screen in production. Sadly, I can&#8217;t afford one. So I&#8217;m going to settle for 22&#8243; LCD monitors. </p>
<p>Now, you&#8217;re probably saying &#8220;Wait, why not get two 24 or 30 inch monitors?&#8221; And there are three answers. One, I like having a &#8220;main&#8221; screen in front of me. Two monitors would put the main screen at an angle (bad) or put the main screen in front and require twisting my neck in one direction half the time (bad). So three is the right number. Second, the native resolutions for the big displays is too large for my laptop to drive, and is also too large for a USB video adapter to drive, and is also too large for a Matrox TripleHead2Go adapter to drive. So 1650&#215;1050 or 1650&#215;1200 is the right size. And third, they don&#8217;t make three-across monitor mounting brackets quite that big yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.longacre-scm.com/blog/index.php/2009/01/getting-l-a-r-g-e-r/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Delays</title>
		<link>http://www.longacre-scm.com/blog/index.php/2006/01/delays</link>
		<comments>http://www.longacre-scm.com/blog/index.php/2006/01/delays#comments</comments>
		<pubDate>Mon, 30 Jan 2006 22:43:19 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Off-topic]]></category>

		<guid isPermaLink="false">http://www.longacre-inc.com/blog/index.php/2006/01/delays</guid>
		<description><![CDATA[Brad Appleton, is a smart guy, published author, and all around good egg. He&#8217;s been posting quite a bit in the last few months while I&#8217;ve been procrastinating converting Longacre-inc to use WordPress so that I could respond to his posts in a persistent, expository fashion. (Important considering some of Blogspot&#8217;s policies on comments.)
Well, it [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://bradapp.blogspot.com/">Brad Appleton</a>, is a smart guy, published author, and all around good egg. He&#8217;s been posting quite a bit in the last few months while I&#8217;ve been procrastinating converting Longacre-inc to use WordPress so that I could respond to his posts in a persistent, expository fashion. (Important considering some of Blogspot&#8217;s policies on comments.)</p>
<p>Well, it may not be done, but it&#8217;s working now. I regret not being able to do this much earlier.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.longacre-scm.com/blog/index.php/2006/01/delays/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Doing better</title>
		<link>http://www.longacre-scm.com/blog/index.php/2005/11/doing-better</link>
		<comments>http://www.longacre-scm.com/blog/index.php/2005/11/doing-better#comments</comments>
		<pubDate>Tue, 22 Nov 2005 22:12:18 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Off-topic]]></category>

		<guid isPermaLink="false">http://www.longacre-inc.com/blog/index.php/2005/11/doing-better</guid>
		<description><![CDATA[Longacre has a blog! 
Doing better, obviously named for the Longacre motto, is about Software CM. It will cover the tools, the practice, and the industry itself. 
]]></description>
			<content:encoded><![CDATA[<p>Longacre has a blog! </p>
<p>Doing better, obviously named for the Longacre motto, is about Software CM. It will cover the tools, the practice, and the industry itself. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.longacre-scm.com/blog/index.php/2005/11/doing-better/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
