<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
   <channel>
      <title>Nat!&apos;s Web Journal</title>
      <link>http://www.mulle-kybernetik.com/weblog/</link>
      <description></description>
      <language>en</language>
      <copyright>Copyright 2010</copyright>
      <lastBuildDate>Sun, 21 Feb 2010 23:19:36 +0100</lastBuildDate>
      <generator>http://www.sixapart.com/movabletype/</generator>
      <docs>http://blogs.law.harvard.edu/tech/rss</docs> 

      
      <item>
         <title>How I bricked my iTunes Server</title>
         <description><![CDATA[for a while...
<p>
As soon as it was available in Germany I bought a Sheeva Plug Computer (ca. EUR 100) and a 1 TB Imation external USB disk (ca. EUR 100).  My plan was to use this a fileserver, mainly as a DAAP iTunes Music server.
<p>
The Imation disk is great. It's covered with an absorber material, and I only hear it when I put my ear on it. It's also supposed to use very little energy.<br>The Sheeva Plug is not so great. The USB connections have too little friction, so it is extremely easy to lose the connection. I already had to format the USB disk twice, because it became unusable, when the USB cabled didn't connect properly any more... Also I think, it could be a little smaller. It's quite a beefy plug.
<p>
There are a lot of guides out there, that cover what to do with the Sheeva, once you get it. For a fileserver like mine, you only need three packages: <b>avahi-daemon</b> for Zeroconf, <b>mt-daapd</b> for Daap/iTunes and <b>samba</b> for filesharing. I also wanted <b>netatalk</b> for completeness sake.
<p>
I just want to write down a few notes, that I didn't see covered elsewhere on the web. There are a lot of good guides out there.
<p>
<ul>
<li><b>netatalk</b> - gave me some weird address family errors, but when I turned off the ATALKD daemon and just use AFPD daemon (see <tt>/etc/defult/netatalk/</tt>. It worked OK. I don't really use AFP now, I use samba, it seems so much faster.
<li><b>hostname</b> - append a .local to the name you come up with. Zeroconf will then be able to properly resolve it.
<li><b>fstab</b> - try to replace as much as possible of the <tt>/var</tt> hierarchy with <b>tmpfs</b> mounts. You will lose persistent logs, but that should reduce writes to the flash memory of the plug.
</ul>
As a final buff, I wanted to mount the root file system as read only. Truely an idiotic maneuvre in planning in execution, but here's what I did, no kidding...
<ol>
<li>Edited <tt>/etc/fstab</tt> to read <tt>rootfs / rootfs <b>ro</b> 00</tt> instead of <tt>rootfs / rootfs rw 0 0</tt>, hoping that this would just work
<li>Rebooted
<li>Checked with <b>mount</b> that it worked, it didn't (<tt>rootfs on / type rootfs (rw)</tt>)
<li>Decided to revert <tt>/etc/fstab</tt> to avoid confusion later in life
<li>Noticed  about three times in a row that saving the changed file didn't work.
<li>Examined <b>fstab</b> file permissions and my user <b>id</b> (root)
<li>Failed to see any reason, why it shouldn't work.
<li>Abandoned this problem and tried to figure out some other aesthetic problem in the boot process
<li>Figured out that I needed <b>strings</b> for that
<li>Tried <tt>apt-get install strings</tt>, knowing that it wouldn't work, which it didn't. Dimly rememberd something about "bin-utils"...
<li>Gave up on this, but noticed a warning that <b>apt-get</b> gave about not being able to use a read-only <tt>/var/lib/dpkg/lock</tt>.
<li>Figured, that probably <tt>/var/lib/dpkg</tt> was missing and needed creation
<li>Noticed, that this wasn't the case.
<li>Experienced a rare moment, that I wouldn't call lucid, but nevertheless had a somewhat dim-but-brighter-than-pitch-black quality. The root filesystem was indeed mounted read only, and <tt>mount</tt> had lied to me!
<li>Moaned as I realized, that to install anything on the root file system I had to edit <b>fstab</b> and reboot. But everything on the root file system is read only now.
<li>Dealt with the pain, by writing this blog entry
<li>Rememberd the remount option <tt>mount -o remount,rw /</tt> ;)
</ol>
]]></description>
         <link>http://www.mulle-kybernetik.com/weblog/2010/02/how_i_bricked_my_itunes_server.html</link>
         <guid>http://www.mulle-kybernetik.com/weblog/2010/02/how_i_bricked_my_itunes_server.html</guid>
        
        
         <pubDate>Sun, 21 Feb 2010 23:19:36 +0100</pubDate>
      </item>
      
      <item>
         <title>A mysterious and largely unknown gcc builtin function</title>
         <description><![CDATA[<pre>#include &lt;stdio.h&gt;

main()
{
   int  x;

   // \\\\\\\\\\\  ///////////// 
   // ||    POWERFUL MAGIC    ||
   // //////////   \\\\\\\\\\\\\
   x = __powerful_magic__( 1848);
   printf( "%d\n", x);

   return( 0);
}</pre>]]></description>
         <link>http://www.mulle-kybernetik.com/weblog/2010/01/a_mysterious_and_largely_unkno.html</link>
         <guid>http://www.mulle-kybernetik.com/weblog/2010/01/a_mysterious_and_largely_unkno.html</guid>
        
        
         <pubDate>Tue, 12 Jan 2010 12:11:25 +0100</pubDate>
      </item>
      
      <item>
         <title>deprecation, deprecation, deprecation - Part 2</title>
         <description><![CDATA[So out of curiosity I figured I'd like to check the deprecation statistics.
<p>
Here's the unix command I used to get the statistics. I am collecting recursive all the header files inside an SDK directory, unique them by filename (which is a bug, but better than not doing it) and check for the AVAILABLE...BUT..DEPRECATED string. Then I massage the output a little, so I can easily put it in a table:
<p>
<tt>( for i in `find /Developer/SDKs/MacOSX10.4u.sdk/ -name "*.h" -print` ; do    file=`basename $i`;    echo "$file" "$i"; done | awk '{  files[ $1] = $2 } END { for ( x in files) print files[ x] }' | xargs egrep -H "AVAILABLE_MAC_OS_X_VERSION_10_._AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_." ) | egrep -v "#define|#ifdef|#ifndef|\ \*\ .*AVA" | sed 's/.*\(AVAILABLE_.*_10_.\).*/\1/' | sort | uniq -c | sed 's/AVAILABLE_MAC_OS_X_VERSION_10_\(.*\)_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_\(.*\)/\1 \2/'</tt>
<p>
which exposes that the <tt>JavaVM.framework</tt> is apparently broken in the 10.6 SDK, but who uses Java anyway ;)<br>
<tt>egrep: /Developer/SDKs/MacOSX10.6.sdk//System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/jvmdi.h: No such file or directory<br>
egrep: /Developer/SDKs/MacOSX10.6.sdk//System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/jvmpi.h: No such file or directory<br>
</tt>
<p>
Anway here are the results:
<p>
<img src="http://www.mulle-kybernetik.com/weblog/pix/deprecated-chart.png" height="274" width="405" align="" border="0" hspace="0" vspace="0" alt="Mac OS X Deprecation Chart" title="" longdesc="" />
<p>
How to read this chart. On the left side is the released version. The bars show the number of symbols deprecated of previous OS X versions. So for example the top entry 10.1, shows that it deprecates less than 10 function from <font color=blue>10.0</font>. Then 10.3 deprecates a few symbols from <font color=blue>10.0</font> and  <font color="gold">10.2</font> and so on. Further interpretation of the data is left to the reader.
<p>
What is kind of interesting is to compare the raw numbers for the various SDKs. I checked 10.4.u.sdk, 10.5.sdk and 10.6.sdk. The horizontal axis has the version that <b>deprecates</b>, the vertical axis has the version that <b>suffers</b> deprecation:

<table>
<tr><td>
<table bgcolor="black" cellspacing=1>
<tr bgcolor="white"><th bgcolor="lightgray">10.4u.sdk</th><th bgcolor="lightgray">10.1</th><th bgcolor="lightgray">10.2</th><th bgcolor="lightgray">10.3</th><th bgcolor="lightgray">10.4</th><th bgcolor="lightgray">10.5</th><th bgcolor="lightgray">10.6</th></tr>
<tr bgcolor="white"><th bgcolor="lightgray">10.0</td><td>2</td><td>5</td><td>31</td><td>1119</td><td>82</td><td></td></tr>
<tr bgcolor="white"><th bgcolor="lightgray">10.1</td><td></td><td>1</td><td>3</td><td>24</td><td></td><td></td></tr>
<tr bgcolor="white"><th bgcolor="lightgray">10.2</td><td></td><td></td><td></td><td>20</td><td></td><td></td></tr>
<tr bgcolor="white"><th bgcolor="lightgray">10.3</td><td></td><td></td><td></td><td>12</td><td></td><td></td></tr>
<tr bgcolor="white"><th bgcolor="lightgray">10.4</td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr bgcolor="white"><th bgcolor="lightgray">10.5</td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
</table>
</td><td>
<table bgcolor="black" cellspacing=1>
<tr bgcolor="white"><th bgcolor="lightgray">10.5.sdk</th><th bgcolor="lightgray">10.1</th><th bgcolor="lightgray">10.2</th><th bgcolor="lightgray">10.3</th><th bgcolor="lightgray">10.4</th><th bgcolor="lightgray">10.5</th><th bgcolor="lightgray">10.6</th></tr>
<tr bgcolor="white"><th bgcolor="lightgray">10.0</td><td>2</td><td>6</td><td>38</td><td>1107</td><td>682</td><td></td></tr>
<tr bgcolor="white"><th bgcolor="lightgray">10.1</td><td></td><td></td><td>1</td><td>37</td><td>37</td><td></td></tr>
<tr bgcolor="white"><th bgcolor="lightgray">10.2</td><td></td><td></td><td>9</td><td>22</td><td>19</td><td></td></tr>
<tr bgcolor="white"><th bgcolor="lightgray">10.3</td><td></td><td></td><td></td><td>14</td><td>32</td><td></td></tr>
<tr bgcolor="white"><th bgcolor="lightgray">10.4</td><td></td><td></td><td></td><td></td><td>7</td><td></td></tr>
<tr bgcolor="white"><th bgcolor="lightgray">10.5</td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
</table>
</td></tr><tr><td>
<table bgcolor="black" cellspacing=1>
<tr bgcolor="#FEFEFE"><th bgcolor="lightgray">10.6.sdk</th><th bgcolor="lightgray">10.1</th><th bgcolor="lightgray">10.2</th><th bgcolor="lightgray">10.3</th><th bgcolor="lightgray">10.4</th><th bgcolor="lightgray">10.5</th><th bgcolor="lightgray">10.6</th></tr>
<tr bgcolor="white"><th bgcolor="lightgray">10.0</td><td>2</td><td>5</td><td>37</td><td>1082</td><td>640</td><td>97</td></tr>
<tr bgcolor="white"><th bgcolor="lightgray">10.1</td><td></td><td></td><td>1</td><td>18</td><td>3</td><td>2</td></tr>
<tr bgcolor="white"><th bgcolor="lightgray">10.2</td><td></td><td></td><td>9</td><td>21</td><td>12</td><td>3</td></tr>
<tr bgcolor="white"><th bgcolor="lightgray">10.3</td><td></td><td></td><td></td><td>18</td><td>19</td><td>106</td></tr>
<tr bgcolor="white"><th bgcolor="lightgray">10.4</td><td></td><td></td><td></td><td></td><td>7</td><td>13</td></tr>
<tr bgcolor="white"><th bgcolor="lightgray">10.5</td><td></td><td></td><td></td><td></td><td></td><td>8</td></tr>
</table>
</td></tr></table>

Some quick observations:
<ul>
<li>10.4u.sdk seems to be broken, as it has deprecations from 10.5 already
<li>since deprecations seem to disappear over time, this could mean, that either symbols were really removed, or that some symbols were wrongly deprecated
</li>
</ul>
<p><i>The methodology used here isn't perfect, because I am not checking all headers. But I hate scrapping the whole entry ;)</i><p>]]></description>
         <link>http://www.mulle-kybernetik.com/weblog/2010/01/deprecation_deprecation_deprec_1.html</link>
         <guid>http://www.mulle-kybernetik.com/weblog/2010/01/deprecation_deprecation_deprec_1.html</guid>
        
        
         <pubDate>Wed, 06 Jan 2010 18:39:51 +0100</pubDate>
      </item>
      
      <item>
         <title>deprecation, deprecation, deprecation - Part 1</title>
         <description><![CDATA[The initial grievance for this posting is this warning:
<pre>foo.m:17: warning: 'NSLookupSymbolInImage' is deprecated 
(declared at /Developer/SDKs/MacOSX10.5.sdk/usr/include/mach-o/dyld.h:182)</pre>

When I look into the header I find this:
<pre>/*
 * The following dyld API's are deprecated as of Mac OS X 10.5.  They are either  
 * no longer necessary or are superceeded by dlopen and friends in <dlfcn.h>.
 * dlopen/dlsym/dlclose have been available since Mac OS X 10.3 and work with 
 * dylibs and bundles.  
 *
 *    NSAddImage                           -&gt; dlopen
 *    NSLookupSymbolInImage                -&gt; dlsym
 *    NSCreateObjectFileImageFromFile      -&gt; dlopen
 *    NSDestroyObjectFileImage             -&gt; dlclose
 *    NSLinkModule                         -&gt; not needed when dlopen used
 *    NSUnLinkModule                       -&gt; not needed when dlclose used
 *    NSLookupSymbolInModule               -&gt; dlsym
 *    _dyld_image_containing_address       -&gt; dladdr
 *    NSLinkEditError                      -&gt; dlerror
 *
 */
</pre>

and 
<pre>extern NSSymbol NSLookupSymbolInModule(NSModule module, const char* symbolName)
AVAILABLE_MAC_OS_X_VERSION_10_1_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5;</pre>

So it appeared in 10.1 and it's plug gets pulled in 10.5. Short lived API, I would say.<p>
What bothers me, that one of the ideas behind <b><tt>Foundation</tt></b> is, that it should isolate me from the OS layer and abstract to a common denominator, that remains stable. Yet here, the <tt>Foundation</tt> functions are deprecated and I am suposed to use <tt>dyld</tt> directly, although <tt>Foundation</tt> still could (and probably does) do the work using <tt>dyld</tt>.
<p>
I don't get this.
]]></description>
         <link>http://www.mulle-kybernetik.com/weblog/2010/01/deprecation_deprecation_deprec.html</link>
         <guid>http://www.mulle-kybernetik.com/weblog/2010/01/deprecation_deprecation_deprec.html</guid>
        
        
         <pubDate>Wed, 06 Jan 2010 18:11:47 +0100</pubDate>
      </item>
      
      <item>
         <title>Nat! vs. evil code elves: Final fishings before christmas</title>
         <description><![CDATA[Moving the framework to different start addresses:

<table><tr><th>Start Address</th><th>Result</th></tr>
<tr><td>0x34200000</td><td>no crash</td></tr>
<tr><td>0x00f50000</td><td>no crash</td></tr>
<tr><td>0x35210000</td><td>no crash</td></tr>
<tr><td>0x35200000</td><td><b>crash</b></td></tr>
<tr><td>0x75200000</td><td>no crash</td></tr>
</table>

So it it crashes with <b> 0x35200000</b>, well that I already did know.

<H3>Isolating the bug</H3>

I was able to isolate the bug eventually into a much much smaller project. Strangely enough, if I put the code into a <tt>.dylib</tt> then there is no problem, but if I use a <tt>.framework</tt> it crashes or fails. If I had tried a framework two days ago instead of a dylib, it would have saved me quite a bit of headache. Also I know now, that AppKit doesn't need to be present. A Foundation tool shows the same problem.
<p>
<b>The same code does not crash on another computer.</b>
<p>
Hilarious! After three days I know now much more about the bug, still, it seems to make no sense whatsoever. On a hunch I would say this has something to do with virtualization on the CPU in some way. It will be interesting to figure out, how to debug that.
<p>
As this is the last entry before christmas. Happy Christmas and New Years. More to come next year, if I don't die of old age in the mean time.
]]></description>
         <link>http://www.mulle-kybernetik.com/weblog/2009/12/nat_vs_evil_code_elves_final_f.html</link>
         <guid>http://www.mulle-kybernetik.com/weblog/2009/12/nat_vs_evil_code_elves_final_f.html</guid>
        
        
         <pubDate>Wed, 23 Dec 2009 00:41:10 +0100</pubDate>
      </item>
      
      <item>
         <title>The plot thickens in the fight vs. the bug elves</title>
         <description><![CDATA[
The VPN is up again and I rearranged the code a little, and now I get a <b><tt>EXC_BAD_ACCESS</tt></b> in a completely different place: 
<pre>0x35204e9f  &lt;+0042&gt;  mov    (%eax),%eax
0x35204ea1  &lt;+0044&gt;  mov    %eax,0x4(%esp)
0x35204ea5  &lt;+0048&gt;  mov    %edx,(%esp)
0x35204ea8  &lt;+0051&gt;  call   0x35236170 &lt;dyld_stub_objc_msgSendSuper&gt;
0x35204ead  &lt;+0056&gt;  lea    0x2c2a1(%ebx),%eax
<b>0x35204eb3  &lt;+0062&gt;  mov    (%eax),%eax</b>
0x35204eb5  &lt;+0064&gt;  cmp    %eax,0x14(%ebp)
</pre>
<p>
compared to the original troublesome code
<p>
<pre>0x35204ea6  &lt;+0000>  push   %ebp
0x35204ea7  &lt;+0001>  mov    %esp,%ebp
0x35204ea9  &lt;+0003>  sub    $0x8,%esp
0x35204eac  &lt;+0006>  mov    0x8(%ebp),%eax
<b>0x35204eaf  &lt;+0009>  mov    0x8(%eax),%eax</b>
0x35204eb2  &lt;+0012>  leave  
0x35204eb3  &lt;+0013>  ret    
</pre>

Is it really a different place ? Actually in terms of adresses it's almost but not quite identical. Yes that still makes no sense whatsoever to me.
<p>
<h3>More fishing around</h3>

Dump of the shared library binary at the appropriate place. (I have put in four nops <b>0x90</b>, so I can easily identify it. (It stlll EXC_BAD_ACCESS crashes with the four nops)
<pre>00004ea0: 0489 1424 e8c7 1203 00<b>90 9090 90</b>8d 83a5  ...$............
00004eb0: c202 008b 0039 4514 7411 8d83 a1c2 0200  .....9E.t.......
00004ec0: 8b00 3945 140f 85ff 0000 0083 7d18 000f  ..9E........}...
</pre>
<i>It's interesting to note, that the offset into the linker file, is the same as the offset into a virtual memory page.</i> 
And here's the same memory seen by <tt>gdb</tt> post <tt>EXC_BAD_ACCESS</tt> crash:
<pre>0x35204ea0: 0x8904 0x2414 0xc7e8 0x0312 <b>0x90</b>00 <b>0x9090</b> 0x8d<b>90</b> 0xa583
0x35204eb0: 0x02c2 0x8b00 0x3900 0x1445 0x1174 0x838d 0xc2a1 0x0002
0x35204ec0: 0x008b 0x4539 0x0f14 0xff85 0x0000 0x8300 0x187d 0x0f00
</pre>
One  dump was made by <tt>emacs</tt> and the other with <tt>gdb</tt> and the endianness is different, but the instructions are identical.
<p>
<h3>One more nop and the crash is gone</h3>

So this is currently the code that gives the <tt> EXC_BAD_ACCESS</tt> at <b> 0x35204eb3</b> 
<pre>0x35204ea9  &lt;+0056&gt;  nop    
0x35204eaa  &lt;+0057&gt;  nop    
0x35204eab  &lt;+0058&gt;  nop    
0x35204eac  &lt;+0059&gt;  nop    
0x35204ead  &lt;+0060&gt;  lea    0x2c2a5(%ebx),%eax
0x35204eb3  &lt;+0066&gt;  mov    (%eax),%eax
0x35204eb5  &lt;+0068&gt;  cmp    %eax,0x14(%ebp)
</pre>

but if I put another <tt>nop</tt> there the crash is gone. Unfortunately as you can see, there is also a subtle shift of the code involved, which is due to the linker, which is out of my control (see: <a href="http://www.mulle-kybernetik.com/weblog/2009/12/some_more_fishing_around_the_e.html">previous entry</a>).

<pre>0x35204ea5  &lt;+0056&gt;  nop    
0x35204ea6  &lt;+0057&gt;  nop    
0x35204ea7  &lt;+0058&gt;  nop    
0x35204ea8  &lt;+0059&gt;  nop    
0x35204ea9  &lt;+0060&gt;  nop    
0x35204eaa  &lt;+0061&gt;  lea    0x2c2a9(%ebx),%eax
0x35204eb0  &lt;+0067&gt;  mov    (%eax),%eax
0x35204eb2  &lt;+0069&gt;  cmp    %eax,0x14(%ebp)
</pre>
]]></description>
         <link>http://www.mulle-kybernetik.com/weblog/2009/12/the_plot_thickens_in_the_fight.html</link>
         <guid>http://www.mulle-kybernetik.com/weblog/2009/12/the_plot_thickens_in_the_fight.html</guid>
        
        
         <pubDate>Tue, 22 Dec 2009 21:46:58 +0100</pubDate>
      </item>
      
      <item>
         <title>The idiocy of too strong typing</title>
         <description><![CDATA[While perusing the <a href="http://lists.apple.com/archives/Xcode-users">Xcode Users mailing list</a> archives I found <a href="http://lists.apple.com/archives/Xcode-users/2009/Dec/msg00279.html">this beauty</a>:<p>

<table  bgcolor="#F8F8F8"><tr bgcolor="white"><td bgcolor="#FEFEEF">
<i>I'd like to write a quick function template to change a function pointer from type " return_type (*)(void) " to "return_type (*)(...)". &nbsp;I thought this would work:</i>

<pre><i>template &lt;typename RetT&gt;
RetT (*convert_ptr(...)) ( RetT (*src)(void) ) { 
&nbsp;&nbsp; typedef RetT (*rt)(...); 
&nbsp;&nbsp;return reinterpret_cast<rt>(src); 
  //ERROR: "src" was not declared in this scope.
}</i>
</pre>
</td></tr></table>
<p>

The whole code functionally is a big bag of nothing. It's all syntax.  Spending time programming this stuff is about as worthwhile as reformatting <a href="http://en.wikipedia.org/wiki/TPS_report">TPS reports</a>.

<p>
The C-solution is (or should be, if it hasn't been broken by some committee by now) <tt>convert_ptr = (void *) src </tt>, which means: I know what I am doing, don't bother me even with warnings, I have better things to do.
 
]]></description>
         <link>http://www.mulle-kybernetik.com/weblog/2009/12/the_idiocy_of_too_strong_typin.html</link>
         <guid>http://www.mulle-kybernetik.com/weblog/2009/12/the_idiocy_of_too_strong_typin.html</guid>
        
        
         <pubDate>Tue, 22 Dec 2009 18:15:19 +0100</pubDate>
      </item>
      
      <item>
         <title>Some more fishing around the evil elves conspiracy</title>
         <description><![CDATA[I wrote another shorter program, that just did the same piece of code at the same place. To write this was harder than expected (see this <a href="http://lists.apple.com/archives/Darwin-dev/2009/Dec/msg00050.html">cry for help</a>) for some more details or check out the gruesome project <a href="http://www.mulle-kybernetik.com/weblog/files/SimpleBestBugVerify.zip">SimpleBestBugVerify</a>.
<p>
In any case, as was sort of expected, the bug doesn't manifest itself there at all.
<p>
Unfortunately I can't reproduce the bug in the original code currently, because as fate has it, the certificate for the VPN that carries the database connection just expired and now it's christmas and the guy responsible for it (Hey Oli! ;)) might not be able to fix it so quickly.
<p>
It's like evil elves are conspiring against me, but I am used to that.
]]></description>
         <link>http://www.mulle-kybernetik.com/weblog/2009/12/some_more_fishing_around_the_e.html</link>
         <guid>http://www.mulle-kybernetik.com/weblog/2009/12/some_more_fishing_around_the_e.html</guid>
        
        
         <pubDate>Sun, 20 Dec 2009 22:02:39 +0100</pubDate>
      </item>
      
      <item>
         <title>Fishing for clues for &quot;my best bug ever&quot;</title>
         <description><![CDATA[<pre>(gdb) x/128x 0x30de800
0x30de800: 0x508152eb 0x50899500 0x50899b14 0x508152de
0x30de810: 0x50898e84 0x50899b14 0x508152d1 0x5089caa9
0x30de820: 0x508986b8 0x50815269 0x508983f2 0x508986b8
0x30de830: 0x5081520b 0x55105c35 0x50899b14 0x508151fe
0x30de840: 0x508a46aa 0x508986b8 0x5081510f 0x00095555
0x30de850: 0x00d0dff0 0x010011c0 0x00000009 0x00000000
0x30de860: 0x00000004 0x00020000 0xa0912ba4 0x00000000
0x30de870: 0x00000000 0x00000000 0x00000000 0x00000000
0x30de880: 0x00d0dff0 0x01001180 0x00000009 0x00000000
0x30de890: 0x00000004 0x00030000 0xa0912ba4 0x00000000
0x30de8a0: 0x00000000 0x00000000 0x00000000 0x00000000
0x30de8b0: 0x00d609f0 0x00000009 0x03078710 0x15627a70
0x30de8c0: 0x00000001 0x030dfc30 0x00000000 0x00000000
0x30de8d0: 0x04a24dc0 0x00000002 0x00000014 0x00000019
0x30de8e0: 0x030decf0 0x00000000 0x00000000 0x00000000
0x30de8f0: 0x04a24a20 0x00000000 0x00000000 0x03240960
0x30de900: 0x030dea70 0x00000000 0x00000000 0x00000000
0x30de910: 0x00000000 0x00000000 0x00000000 0x00000000
0x30de920: 0x00d0a590 0x01001384 0x00000083 0x00000083
0x30de930: 0x00000000 0x030de940 0x00000000 0x00000000
0x30de940: 0x454c4553 0x75205443 0x45422e30 0x5a54554e
0x30de950: 0x535f5245 0x4b454c45 0x4e4f4954 0x3075202c
0x30de960: 0x4d414e2e 0x75202c45 0x44492e30 0x53555a5f
0x30de970: 0x444e4154 0x3075202c 0x5f44492e 0x5453414d
0x30de980: 0x535f5245 0x4b454c45 0x4e4f4954 0x3075202c
0x30de990: 0x414c4b2e 0x2c455353 0x2e307520 0x5245554b
0x30de9a0: 0x2c4c455a 0x2e307520 0x4d4d554e 0x46205245
0x30de9b0: 0x204d4f52 0x5f544448 0x45424154 <font color="red"><strong>0x20454c4c</strong></font>
0x30de9c0: 0x00003075 0x00000000 0x00000000 0x00000000
0x30de9d0: 0x00d01af0 0x352f00d8 0x500afa60 0x00000000
0x30de9e0: 0x00000000 0x00000000 0x00000000 0x00000000
0x30de9f0: <strong>0x35231f20 0x925c93a8 0x04a053c0 0x00d7dfa0</strong>
</pre>

and

<pre>(gdb) set $eax = 0x30de9f4
(gdb) set $eip = 0x35204eaf
(gdb) stepi
(gdb) p/x $eax
$22 = 0x3075
(gdb) set $eax = 0x30de9ec
(gdb) set $eip = 0x35204eaf
(gdb) stepi
(gdb) p/x $eax
$23 = 0x45424154
(gdb) 
</pre>

hmm significant, I would say. It should be noted, that the address of the executable code and the memory address is somewhere in the middle of what I would expect a VM page to be, since these are supposed to be divisible by 4K as far as I know.

<pre>(gdb) x/64x 0x10000
0x10000: 0xffffff4c 0x8bb0148b 0xffff108d 0x18858bff
0x10010: 0xe8ffffff 0x00076f07 0x2785c646 0x01ffffff
0x10020: 0x858b0ceb 0xffffff10 0x0a74c085 0xb539f631
0x10030: 0xffffff50 0x858bc87f 0xffffff4c 0xe8240489
0x10040: 0x0011c3b6 0xff1c958b 0x9589ffff 0xffffff30
0x10050: 0xff2885c7 0x0000ffff 0x85c60000 0xffffff2f
0x10060: 0x1f8b8d00 0x890012c7 0xffff0c8d 0x7d838dff
0x10070: 0x8900120e 0xffff0885 0x83938dff 0x8900120e
0x10080: 0xffff0495 0x898b8dff 0x8900120e 0xffff008d
0x10090: 0x60858dff 0x89ffffff 0xfffefc85 0x8f938dff
0x100a0: 0x8900120e 0xfffef895 0x5c8d8dff 0x89ffffff
0x100b0: 0xfffef48d 0x0288e9ff 0x858b0000 <b>0xffffff30</b>
0x100c0: 0x00587880 0x0268840f 0xc0830000 0x20858948
0x100d0: 0xb9ffffff 0x00000007 0x0cb58bfc 0x89ffffff
0x100e0: 0xb8a6f3c7 0x00000000 0xb60f0a74 0xb60fff46
0x100f0: 0xc829ff4f 0x1d75c085 0x850c458b <b>0x2f840fc0</b>
(gdb) set $eax = 0x100f0
(gdb) set $eip = 0x35204eaf
(gdb) stepi
(gdb) p/x $eax
$26 = 0xffffff30
(gdb) set $eax = 0x100f0
(gdb) set $eip = 0x35204c93
(gdb) stepi
(gdb) p/x $eax
$27 = 0x2f840fc0
(gdb) x/i 0x35204c93
0x35204c93 &lt;-[xxx value]+9&gt;:	mov    0xc(%eax),%eax
(gdb) x/i 0x35204eaf
0x35204eaf &lt;-[xxx key]+9&gt;:	mov    0x8(%eax),%eax
(gdb)
</pre>

Just checking stuff with a different memory address and double checking the assembly code.
<p>
Try a different class in a different project with the same layout:
<pre>0x00001f0f  &lt;+0006&gt;  push   %ebp
0x00001f10  &lt;+0007&gt;  mov    %esp,%ebp
0x00001f12  &lt;+0009&gt;  sub    $0x8,%esp
0x00001f15  &lt;+0012&gt;  mov    0x8(%ebp),%eax
0x00001f18  &lt;+0015&gt;  mov    0x8(%eax),%eax
0x00001f1b  &lt;+0018&gt;  leave  
0x00001f1c  &lt;+0019&gt;  ret 
(gdb) stepi
(gdb) p/x $eax
$2 = 0x403f20
(gdb) x/4x $eax
0x403f20: 0x00003030 0x924e24f8 0x00002024 0x00002034
(gdb) stepi
(gdb) p/x $eax
$4 = 0x2024
(gdb) 
</pre>

]]></description>
         <link>http://www.mulle-kybernetik.com/weblog/2009/12/fishing_for_clues_for_my_best.html</link>
         <guid>http://www.mulle-kybernetik.com/weblog/2009/12/fishing_for_clues_for_my_best.html</guid>
        
        
         <pubDate>Thu, 17 Dec 2009 21:51:44 +0100</pubDate>
      </item>
      
      <item>
         <title>My best bug ever</title>
         <description><![CDATA[This is obscure, but who said programming is always easy. Maybe more on this later, if I know whats going on.  

This is the disassembled code for <b>-value</b>:
<pre>0x35204c8a  &lt;+0000>  push   %ebp
0x35204c8b  &lt;+0001>  mov    %esp,%ebp
0x35204c8d  &lt;+0003>  sub    $0x8,%esp
0x35204c90  &lt;+0006>  mov    0x8(%ebp),%eax
0x35204c93  &lt;+0009>  mov    <b>0xc</b>(%eax),%eax
0x35204c96  &lt;+0012>  leave  
0x35204c97  &lt;+0013>  ret 
</pre>
and this is <b>-key</b>:
<pre>0x35204ea6  &lt;+0000>  push   %ebp
0x35204ea7  &lt;+0001>  mov    %esp,%ebp
0x35204ea9  &lt;+0003>  sub    $0x8,%esp
0x35204eac  &lt;+0006>  mov    0x8(%ebp),%eax
0x35204eaf  &lt;+0009>  mov    <b>0x8</b>(%eax),%eax
0x35204eb2  &lt;+0012>  leave  
0x35204eb3  &lt;+0013>  ret    
</pre>
I hightlighted the only difference in the assembly code between the two functions. 
<br>
<h3>Stepping through the code, with the same object</h3>
There are breakpoints on <tt> 0x35204c90</tt> and <tt> 0x35204eac</tt>

<b>-value</b> works as expected but <b>-key</b> doesn't

<pre>(gdb) stepi
(gdb) p/x $eax
$16 = 0x30de9f0
(gdb) x/4 $eax
0x30de9f0: 0x35231f20 0x925c93a8 0x04a053c0 0x00d7dfa0
(gdb) x/x $eip
0x35204c93 &lt;-[xxx value]+9&gt;:	0xc90c408b
(gdb) stepi
(gdb) p/x $eax
$17 = 0xd7dfa0
(gdb) c
Continuing.
(gdb) stepi
(gdb) p/x $eax
$18 = 0x30de9f0
(gdb) x/4x 0x30de9f0
0x30de9f0: 0x35231f20 0x925c93a8 0x04a053c0 0x00d7dfa0
(gdb) x/x $eip
0x35204eaf &lt;-[xxx key]+9&gt;:	0xc908408b
(gdb) stepi
(gdb) p/x $eax
$19 = 0x20454c4c
(gdb) set $eip = 0x35204eaf
(gdb) set $eax = 0x30de9f0
(gdb) stepi
(gdb) p/x $eax
$20 = 0x20454c4c
(gdb) set $eip = 0x35204c93
(gdb) set $eax = 0x30de9f0
(gdb) stepi
(gdb) p/x $eax
$21 = 0xd7dfa0
(gdb) 
(gdb) x/4x 0x30de9f0
0x30de9f0: 0x35231f20 0x925c93a8 0x04a053c0 0x00d7dfa0
</pre>

There is nothing ommitted, there is no other thread of mine running. <b> 0xc908408b</b> in Visual Studio is also <tt>mov eax,dword ptr [eax+8]</tt>.]]></description>
         <link>http://www.mulle-kybernetik.com/weblog/2009/12/my_best_bug_ever.html</link>
         <guid>http://www.mulle-kybernetik.com/weblog/2009/12/my_best_bug_ever.html</guid>
        
        
         <pubDate>Thu, 17 Dec 2009 17:38:22 +0100</pubDate>
      </item>
      
      <item>
         <title>How to move an Impulse account to another machine without knowing your password or email address</title>
         <description><![CDATA[What if you lost your password to Impulse and what if you gave Impulse a fake email address during registration. Who could be so stupid ? But hypothetically... what could you do, if you wanted to migrate to another machine ?
<p>
Use <tt>regedit.exe</tt>, locate <tt>\HKEY_CURRENT_USER\Software\Stardock</tt> and export this folder onto a USB stick or some such.
<p>
On the new machine just doubleclick on the created registry export file and ignore the warnings.
<p>
It worked for me.]]></description>
         <link>http://www.mulle-kybernetik.com/weblog/2009/12/how_to_move_an_impulse_account.html</link>
         <guid>http://www.mulle-kybernetik.com/weblog/2009/12/how_to_move_an_impulse_account.html</guid>
        
        
         <pubDate>Fri, 11 Dec 2009 18:09:17 +0100</pubDate>
      </item>
      
      <item>
         <title>SSD Fight: Samsung PM 800 256 GB vs Intel X-25M Postville</title>
         <description><![CDATA[I am using the first version of the Intel X-25M in my MacBook and I am very happy with it. So now its time to upgrade the desktops. Since some time has passed since I bought my first SSD there are now actually alternatives to the X-25M on the market. The Samsung PM 800 seems to have the X-25M beat in every benchmark I have seen, except one, and that was random 4K block read/writes. In that benchmark the IBM was about 10 times faster than the Samsung.
<p>
<img src="http://www.mulle-kybernetik.com/weblog/files/ibm.jpg" height="157" width="200" align="" border="0" hspace="0" vspace="0" alt="IBM SSD" title="" longdesc="" />
<p>
My suspicion was, that this particular benchmark would be of great importance, to my foremost interest, when it comes to disk speed, which is compiling. Unfortunately this aspect is rarely benchmarked. So here goes. So I ordered both and tried them in my MacBook. 
<p>


<table border=0 cellpadding=1 bgcolor="#AAAAAA">
<tr bgcolor="#FFFFFF">
<th width="25%"></th><th width="25%">Samsung</th><th width="25%">Intel X-25M Postville</th><th width="25%">Intel X-25M (Generation 1)</th></tr>
<tr bgcolor="#FFFFFF"><th>GB/&euro;</th><td>0,50</td><td>0,42</td><td>-</td></tr>
<tr bgcolor="#FFFFFF"><th>SL Installation time (min)</th><td>27</td><td>31</td><td>-</td></tr>
<tr bgcolor="#FFFFFF"><th>Xcode Installation time (m:s)</th><td>6:21</td><td>6:21</td><td>-</td></tr>
<tr bgcolor="#FFFFFF"><th>Build time (m:s)</th><td>2:40</td><td>2:42</td><td>2:41</td></tr>
</table>
<p>
What I did was I put each SSD into my MacBook, partioned it to one partition and installed Snow Leopard 10.6 from DVD on it. I measured how many minutes that took. Than I installed Xcode and checked the installer log for the time elapsed. Finally I used <tt>xcodebuild</tt> to built a decently sized software package. The I did a <b>clean</b> and then I measured it with <tt>time xcodebuild</tt>.
<p>
<img src="http://www.mulle-kybernetik.com/weblog/files/samsung.jpg" height="200" width="166" align="" border="0" hspace="0" vspace="0" alt="Samsung SSD" title="" longdesc="" />
<p>
Conclusion: In my tests on the white MacBook there is no big difference between both SSDs, but the Samsung seems to be the all around better pick on first look. The Intel is going into my Windows system and the Samsung will go into my G5.
<p>
<i>An advantage the IBM package has, it comes with a 2.5" to 3.5" adaptor.</i>

]]></description>
         <link>http://www.mulle-kybernetik.com/weblog/2009/12/ssd_fight_samsung_pm_800_256_g.html</link>
         <guid>http://www.mulle-kybernetik.com/weblog/2009/12/ssd_fight_samsung_pm_800_256_g.html</guid>
        
        
         <pubDate>Thu, 10 Dec 2009 20:44:44 +0100</pubDate>
      </item>
      
      <item>
         <title>A small x86_64 optimization brainteaser [with complete solution]</title>
         <description><![CDATA[Can you make this code - method <b>abc</b> - run faster with x86_64 ?

<pre>#import &lt;Foundation/Foundation.h&gt;

@interface Foo : NSObject 
{
   long  a;
   long  b;
   long  c;
}

- (long) abc;

@end

@implementation Foo

- (long) abc
{
   return( self->a + self->b + self->c);
}

@end
</pre>

<font color="white">Hint: Think about reorganization or restructuring.</font><br>
Reference toolchain is stock Xcode 3.2 with default gcc 4.2 and Release setting. 
<p>
<i>The solution is in the full text.</i>

]]></description>
         <link>http://www.mulle-kybernetik.com/weblog/2009/11/a_small_x68_64_optimization_br.html</link>
         <guid>http://www.mulle-kybernetik.com/weblog/2009/11/a_small_x68_64_optimization_br.html</guid>
        
        
         <pubDate>Thu, 19 Nov 2009 12:54:16 +0100</pubDate>
      </item>
      
      <item>
         <title>va_list is now an array of some (opaque ?) struct... gee thanks</title>
         <description><![CDATA[A little trap in the new 64 bit ABI.

<pre>void   bar( va_list args)
{
   va_list   x;  
   
   x = args;
   return( va_arg( x, int));
}
</pre>

does not work anymore. It gives the error
<p><tt>error: array type 'va_list' (aka 'struct __va_list_tag [1]') is not assignable</tt><br>
<p>
I was curious if there was any "obvious" change in functionality. Here is the part of a function calling <tt>bar</tt> disassembled for three different architectures. The disassembly shows, that it's the same internally, two pointers are pushed unto the stack (put into parameter registers).
<pre>x86_64
	movq	%rbx, %rsi
	movl	%r12d, %edi
	call	_bar

i386:
	movl	-12(%ebp), %eax
	movl	%eax, 4(%esp)
	movl	8(%ebp), %eax
	movl	%eax, (%esp)
	call	_bar

ppc:
	lwz r4,76(r1)
	mr r3,r29
	bl _bar
</pre>

What does work in the old and the new world is
<pre>void   bar( va_list args)
{
   va_list   *x;  
   
   x = &args;
   return( va_arg( *x, int));
}
</pre>

where I incur one pointer indirection due to syntax. I am still forming an opinion on that...

]]></description>
         <link>http://www.mulle-kybernetik.com/weblog/2009/11/va_list_is_now_an_array_of_som.html</link>
         <guid>http://www.mulle-kybernetik.com/weblog/2009/11/va_list_is_now_an_array_of_som.html</guid>
        
        
         <pubDate>Sun, 15 Nov 2009 00:46:10 +0100</pubDate>
      </item>
      
      <item>
         <title>The beginning of a bigger change ?</title>
         <description><![CDATA[So I try to compile some older code (10.5) on SnowLeopard and I get:
<pre>
error: @defs is not supported in new abi
</pre>
<p>
The offending code looks something like this
<pre>
@interface Foo
{
   void   *table1_;
}
@endif

static inline BOOL   Foo_IsASpecialObject( Foo *self, id p)
{
   return( NSHashGet( ((struct { @defs( Foo) } *) self)->table1_, p) != nil);
}
</pre>

<i>If you find this a little obscure, I once wrote an <a href="http://www.mulle-kybernetik.com/artikel/Optimization/opti-3.html">article</a> about it (look for <b>Using inline functions instead of method calls</b>)</i>

<p>
These are all the solutions to this particular problem I came up with:

<ol>
<li>don't use the new ABI / abandon platform
<li>pester ABI maintainer to support <tt>@defs</tt>
<li>pester ABI maintainer to support <tt>static inline</tt> between <tt>@interface</tt> and <tt>@end</tt>
<li>painstakingly create a shadow <tt>struct</tt>, that mimics the <tt>Foo</tt> class
<li>unprotect inline accessed instance variables in <tt>Foo</tt> with <tt>@public</tt>
</ol>

Just ignoring the ABI and sticking to 32 bit is a dead end on Mac OS X, so it's not an option. Option #2 and #3, well call me negative but I am also not buying lottery tickets because of the bad odds. Option #4 is extremely fragile, I don't want that. So for now I will have to make the instance variables <tt>@public</tt>. SIGH!





]]></description>
         <link>http://www.mulle-kybernetik.com/weblog/2009/11/the_beginning_of_a_bigger_chan.html</link>
         <guid>http://www.mulle-kybernetik.com/weblog/2009/11/the_beginning_of_a_bigger_chan.html</guid>
        
        
         <pubDate>Fri, 13 Nov 2009 21:12:13 +0100</pubDate>
      </item>
      
   </channel>
</rss>
