<?xml version="1.0"?>
<!-- name="generator" content="blosxom/2.0" -->
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Landon Fuller   </title>
		<link>http://landonf.bikemonkey.org</link>
		<description>Technical Minutiae</description>
		<language>en</language>
		<!-- <atom:link href="http://landonf.bikemonkey.org/index.rss" rel="self" type="application/rss+xml" /> -->
		<copyright>Copyright (c) 2008 Landon Fuller. All Rights Reserved.</copyright>
<item>
	<title>Work with Plausible Labs</title>
	<link>http://landonf.bikemonkey.org/2010/02/18#Work_with_Plausible_Labs.20100218</link>
	<guid>http://landonf.bikemonkey.org/2010/02/18#Work_with_Plausible_Labs.20100218</guid>
	<pubDate>Thu, 18 Feb 2010 10:26 PST</pubDate>
	<description>&lt;p class=&quot;story&quot;&gt;When I started &lt;a href=&quot;http://www.plausiblelabs.com/about/&quot;&gt;Plausible Labs&lt;/a&gt; in
2008, we were working out of our homes, paying our rent out of savings while we figured
out how to bootstrap worker-owned &lt;a href=&quot;http://www.plausiblelabs.com/about/&quot;&gt;software
cooperative&lt;/a&gt; without external funding.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;A year or so later, I'm part of a three member team. We are all still working out of a home, but now
it's a loft in the Mission with proper office space, Ikea desks, and even a few Aeron chairs.
We've got the issue of self-sufficiency figured out, and now we're looking to the future -- how
we'd like to grow our organization, what sort of software projects we'd like to tackle (both in-house
and on contract), and how the co-operative experiment will scale past a few members.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;We're ready to take on more (and larger) projects, and we’d like to find the right engineer for a
contract-to-hire role to help us out. We’re particularly keen in finding someone genuinely
interested in joining the co-operative, and open to working with us on either a part-time or
full-time basis.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;If you'd be interested in working with us, you can find the job posting
&lt;a href=&quot;http://www.plausiblelabs.com/blog/?p=23&quot;&gt;here.&lt;/a&gt;&lt;/p&gt;

</description>
</item>
<item>
	<title>OpenJDK 7 on Leopard PPC</title>
	<link>http://landonf.bikemonkey.org/2009/12/16#OpenJDK_7_PPC.20091205</link>
	<guid>http://landonf.bikemonkey.org/2009/12/16#OpenJDK_7_PPC.20091205</guid>
	<pubDate>Wed, 16 Dec 2009 17:29 PST</pubDate>
	<description>&lt;h3 class=&quot;story&quot; &gt; Introduction&lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;Thanks to the &lt;a href=&quot;http://gbenson.net/?p=166&quot;&gt;work of Gary Benson&lt;/a&gt; on implementing
and merging the &lt;a href=&quot;http://openjdk.java.net/projects/zero/&quot;&gt;Zero-Assembler Project&lt;/a&gt;,
and Greg Lewis' work bringing it to &lt;a href=&quot;http://openjdk.java.net/projects/zero/&quot;&gt;OpenJDK BSD Port&lt;/a&gt;,
it's now possible to bootstrap OpenJDK 7 on Mac OS X 10.5/PPC.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;Gary Benson's Zero Assembler provides a portable implementation of the JVM intepreter that -- unlike
the existing JVM implementations -- relies on very little assembler to provide an acceptably performing but
highly portable VM, opening the door to supporting Mac OS X PPC with very little additional work.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;I've committed the few small fixes to get OpenJDK running on Mac OS X 10.5/PPC, and have bootstrapped an initial OpenJDK 7
binary using Havard Eidnes's &lt;a href=&quot;http://freebsd.monkey.org/freebsd-java/200802/msg00002.html&quot;&gt;bootstrap scripts&lt;/a&gt;.  
Bootstrapping the initial VM running is sufficiently involved that I would recommend using my
binaries (&lt;a href=&quot;http://hg.bikemonkey.org/archive/openjdk7_darwin/openjdk7-macppc-2009-12-16-b4.tar.bz2&quot;&gt;openjdk7-macppc-2009-12-16-b4.tar.bz2&lt;/a&gt;).&lt;/p&gt;

&lt;h3 class=&quot;story&quot; &gt; Source Access &lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;OpenJDK uses &lt;a href=&quot;http://www.selenic.com/mercurial/wiki/&quot;&gt;Mercurial&lt;/a&gt; with the Forest extension.
Before checking out the BSD sources, you will need to install and configure Mercurial. See the
&lt;a href=&quot;http://openjdk.java.net/guide/repositories.html#installConfig&quot;&gt;OpenJDK Developer's Guide&lt;/a&gt; for more
information.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;To check out the BSD-Port forest:&lt;/p&gt;

&lt;pre class=&quot;story&quot; &gt;hg fclone http://hg.openjdk.java.net/bsd-port/bsd-port&lt;/pre&gt;

&lt;h3 class=&quot;story&quot; &gt; Building on Leopard/PPC&lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;Building OpenJDK requires Java 6 or OpenJDK 7 -- on PPC, you will need to download or build
an OpenJDK 7 bootstrap VM (&lt;a href=&quot;http://hg.bikemonkey.org/archive/openjdk7_darwin/openjdk7-macppc-2009-12-16-b4.tar.bz2&quot;&gt;openjdk7-macppc-2009-12-16-b4.tar.bz2&lt;/a&gt;).&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;To build the JDK in build/bsd-ppc/j2sdk-image:&lt;/p&gt;

&lt;pre class=&quot;story&quot; &gt;make \
CC=gcc-4.0 \
CXX=g++-4.0 \
ALT_BOOTDIR=/usr/local/openjdk7-macppc-2009-12-16-b4
ANT_HOME=/usr/share/ant \
ALT_FREETYPE_HEADERS_PATH=/usr/X11/include \
ALT_FREETYPE_LIB_PATH=/usr/X11/lib \
ALT_CUPS_HEADERS_PATH=/usr/include \
ALT_CACERTS_FILE=/System/Library/Frameworks/JavaVM.framework/Home/lib/security/cacerts \
LIBFFI_CFLAGS=&quot;-I/usr/include/ffi&quot; \
NO_DOCS=true \
ZERO_BUILD=true \
ZERO_ENDIANNESS=big \
ZERO_LIBARCH=ppc \
ZERO_ARCHDEF=PPC \
ZERO_ARCHFLAG=-m32&lt;/pre&gt;

&lt;p class=&quot;story&quot;&gt;Be sure to set ALT_BOOTDIR to the path of your installed openjdk7-macppc-2009-12-16-b4 bootstrap JDK.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;Once built, you should now have a JDK in build/bsd-ppc/j2sdk-image:&lt;/p&gt;

&lt;pre class=&quot;story&quot; &gt;landonf@onefish:~/openjdk-ppc/bsd-port&gt; ./build/bsd-ppc/j2sdk-image/bin/java -version
openjdk version &quot;1.7.0-internal&quot;
OpenJDK Runtime Environment (build 1.7.0-internal-landonf_2009_12_16_12_54-b00)
OpenJDK Zero VM (build 17.0-b05, interpreted mode)&lt;/pre&gt;

&lt;p class=&quot;story&quot;&gt;For more information or assistance, please refer to the OpenJDK BSD-Port &lt;a href=&quot;http://wikis.sun.com/display/OpenJDK/BSDPort&quot;&gt;wiki&lt;/a&gt; and
&lt;a href=&quot;http://mail.openjdk.java.net/mailman/listinfo/bsd-port-dev&quot;&gt;mailing list&lt;/a&gt;. My testing has been very limited -- if you run into issues, please report
them on the development mailing list.&lt;/p&gt;

</description>
</item>
<item>
	<title>Using Blocks: Understanding the Memory Management Rules</title>
	<link>http://landonf.bikemonkey.org/2009/07/11#Using_Blocks_2.20090710</link>
	<guid>http://landonf.bikemonkey.org/2009/07/11#Using_Blocks_2.20090710</guid>
	<pubDate>Sat, 11 Jul 2009 18:09 PDT</pubDate>
	<description>&lt;h3 class=&quot;story&quot; &gt; Introduction&lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;I just finished uploading &lt;a href=&quot;http://code.google.com/p/plblocks/&quot;&gt;PLBlocks&lt;/a&gt; 1.0-beta2, which
adds support for iPhoneOS 2.2, iPhone 3GS armv7-optimized binaries, and host support for PPC systems
(&lt;a href=&quot;http://www.plausiblelabs.com/blog/?p=11&quot;&gt;release announcement&lt;/a&gt;). This seems like a good time a good time to continue with my ad-hoc
series on developing with Blocks (&lt;a href=&quot;http://landonf.bikemonkey.org/code/iphone/Using_Blocks_1.20090704.html&quot;&gt;previous post&lt;/a&gt;).&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;I've fielded a number of questions regarding the memory management rules surrounding blocks; This article
should help you understand the basic rules necessary to use blocks successfully.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;I won't delve too deep into the describing the actual block implementation,
as that's a topic well-covered by Clang's &lt;a href=&quot;http://clang.llvm.org/docs/BlockImplementation.txt&quot;&gt;Block Implementation Specification&lt;/a&gt;
Even if you don't have time to read the implementation specification, it's important to note that blocks are really just a few
functions and structures implemented for you by the compiler, coupled with a runtime to help with managing setup and tear down.
You could implement the same thing yourself in pure C -- but it would be so verbose as to not be useful.&lt;/p&gt;

&lt;h3 class=&quot;story&quot; &gt; The Memory Management Rules&lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;Apple provides a set of straight-forward &lt;a href=&quot;http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html&quot;&gt;memory management rules&lt;/a&gt;
for Objective-C. I've endeavoured to provide an equivalent set of rules for blocks in C and Objective-C.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;This is the single fundamental memory management rule:&lt;/p&gt;

&lt;ul class=&quot;story&quot;&gt;
&lt;li&gt;To take ownership of a block, you must copy that block via -copy or Block_copy(). You
are responsible for relinquishing ownership of blocks you own using -release or Block_release().&lt;/li&gt;
&lt;/ul&gt;

&lt;p class=&quot;story&quot;&gt;The following rules derive from the fundamental rule, or cope with edge cases:&lt;/p&gt;

&lt;ul class=&quot;story&quot;&gt;
&lt;li&gt;Block_copy() must be paired with Block_release(); likewise, the Objective-C -copy message must be paired with an Objective-C -release message.&lt;/li&gt;
&lt;li&gt;By default, variables captured by a block are copied, and global variables are referenced directly. If a captured variable is marked with the __block storage specifier, the variable will be indirectly referenced and thus may be modified from within a block.&lt;/li&gt;
&lt;li&gt;
    When a block is copied (or released):
    &lt;ul class=&quot;story&quot;&gt;
        &lt;li&gt;Any referenced (captured) Objective-C objects will be retained (or released).&lt;/li&gt;
        &lt;li&gt;Any captured blocks will be copied (or released).&lt;/li&gt;
    &lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 class=&quot;story&quot; &gt; Block Ownership: Copy vs. Retain&lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;All blocks have a valid class pointer, and appear to be Objective-C objects. According to the standard Objective-C
memory management, to assume ownership of an object you must simply retain it. However, blocks
differ from the standard Objective-C objects in at least one fundamental and very important way:
blocks defined within a function are allocated on the stack, and will persist only until your
function returns.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;This is why it is necessary to copy a block, rather than retain it: If the block is stack allocated, it must
be copied to a heap allocation to persist beyond the lifetime of the current stack frame. Once copied,
the block will be heap allocated and persist like any other standard Objective-C object.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;Thus, to ensure that you do not attempt to maintain ownership of a stack allocated block, you must &lt;em&gt;always&lt;/em&gt;
copy a block if you wish to reference it past the lifetime of your current function. As an optimization, if
a block has already been copied to the heap copying will simply increment the block's reference count.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;It should also be noted that there is one very real benefit to stack allocation of blocks: they are very cheap,
and unless copied, require no allocations or cleanup.&lt;/p&gt;

&lt;h3 class=&quot;story&quot; &gt; Captured Variables: Copy vs. Reference&lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;By default, local variables (variables of the &quot;auto&quot; storage class) are captured by your block
as const copies, while global variables are accessed directly. The runtime automatically handles
reference counting of captured blocks and Objective-C objects.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;To allow you modify a local variable (rather than its copy), Apple has added the __block storage specifier. Any __block variables are
accessed by referenced from within a block. This is best explained by example:&lt;/p&gt;

&lt;pre class=&quot;story&quot; &gt;__block int i = 0;
int j = 0;
executeBlock(^{
    // Increments the stack allocated 'i' variable by 1.
    i++;&lt;/pre&gt;

&lt;blockquote class=&quot;story&quot;&gt;&lt;p class=&quot;story&quot;&gt;// 'j' is a const copy, and can not be modified from within the block
    / j++
});&lt;/p&gt;&lt;/blockquote&gt;

&lt;p class=&quot;story&quot;&gt;If you copy a block, any captured __block variables will also be copied to the heap.&lt;/p&gt;

&lt;h3 class=&quot;story&quot; &gt; Further Reading&lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;I hope these brief explanations have provided a reasonable introduction to memory management with blocks. For additional details, you may
wish to review Jim Dovey's post on the &lt;a href=&quot;http://alanquatermain.net/post/138827791/blocks-episode-2-life-cycles&quot;&gt;life-cycle of blocks&lt;/a&gt;,
and join the &lt;a href=&quot;http://groups.google.com/group/plblocks-devel&quot;&gt;PLBlocks Mailing List&lt;/a&gt; for further discussion.&lt;/p&gt;

</description>
</item>
<item>
	<title>Blocks Examples: NSOperationQueue and UIActionSheet  </title>
	<link>http://landonf.bikemonkey.org/2009/07/04#Using_Blocks_1.20090704</link>
	<guid>http://landonf.bikemonkey.org/2009/07/04#Using_Blocks_1.20090704</guid>
	<pubDate>Sat, 04 Jul 2009 18:25 PDT</pubDate>
	<description>&lt;h3 class=&quot;story&quot; &gt; Introduction&lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;On Friday, &lt;a href=&quot;http://www.plausiblelabs.com&quot;&gt;Plausible Labs&lt;/a&gt; released &lt;a href=&quot;http://code.google.com/p/plblocks/&quot;&gt;PLBlocks&lt;/a&gt;, an
SDK that allows you to immediately begin experimenting with blocks (also known as closures) on
Mac OS X 10.5 and iPhone OS 3.0.  While the &lt;a href=&quot;http://www.plausiblelabs.com/blog/?p=8&quot;&gt;original announcement&lt;/a&gt; included a very brief
introduction to blocks, I thought it might be worthwhile to provide some concrete examples of using blocks in your own code.&lt;/p&gt;

&lt;h3 class=&quot;story&quot; &gt; Example Code&lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;All the sample code and implementation classes for this article are available
via my &lt;a href=&quot;http://github.com/landonf/block_samples/tree/master&quot;&gt;block_samples&lt;/a&gt; github repository.
You may download the repository as an archive (no git required) by pressing the &quot;download&quot; button next
to the repository name.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;To get started with the PLBlocks SDK, check out the download and installation instructions on the
&lt;a href=&quot;http://code.google.com/p/plblocks/#Download&quot;&gt;project page&lt;/a&gt;. Please note
that PLBlocks is still in beta.&lt;/p&gt;

&lt;h3 class=&quot;story&quot; &gt; NSOperationQueue&lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;On Mac OS X and iPhoneOS, there are a variety of ways to schedule operations on a background thread.
One method that's often used is calling -[NSObject performSelectorInBackground:withObject:] to execute
a method in the background, and then -[NSObject performSelectorOnMainThread:withObject:waitUntilDone:]
to provide the results to the primary thread.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;This works, but it's not as convenient as it could be:&lt;/p&gt;

&lt;ul class=&quot;story&quot;&gt;
&lt;li&gt;Every background task requires at least one new method definition.&lt;/li&gt;
&lt;li&gt;Methods can only accept one (or two) arguments.&lt;/li&gt;
&lt;li&gt;There's no easy way to provide the background method with additional state.&lt;/li&gt;
&lt;/ul&gt;

&lt;p class=&quot;story&quot;&gt;Using blocks -- and a few small extensions to NSOperationQueue and NSThread -- we can
instead encapsulate this full exchange in one method, using a block to run
the background operation, and a nested block to handle the response directly on the main
thread:&lt;/p&gt;

&lt;pre class=&quot;story&quot; &gt;- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Allocated here for succinctness.
    NSOperationQueue *q = [[NSOperationQueue alloc] init];
 
    /* Data to process */
    NSData *data = [@&quot;Hello, I'm a Block!&quot; dataUsingEncoding: NSUTF8StringEncoding];
 
    /* Push an expensive computation to the operation queue, and then
     * display the response to the user on the main thread. */
    [q addOperationWithBlock: ^{
        /* Perform expensive processing with data on our background thread */
        NSString *string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
         
        /* This is the &quot;expensive&quot; part =) */
        sleep(5);
         
        /* Inform the user of the result on the main thread, where it's safe to play with the UI. */
        [[NSThread mainThread] performBlock: ^{
            NSAlert *alert = [[[NSAlert alloc] init] autorelease];
             
            [alert addButtonWithTitle: @&quot;OK&quot;];
            [alert setMessageText: [NSString stringWithFormat: @&quot;Processing completed: %@&quot;, string]];
            [alert runModal];
        }];
 
        /* We don't need to hold a string reference anymore */
        [string release];
    }];
}&lt;/pre&gt;

&lt;p class=&quot;story&quot;&gt;The first block is scheduled to run on the NSOperationQueue, and inside contains an additional nested block. When the operation has
completed, it schedules its nested block to run on the main thread, where the result can be presented to the user,
or passed on for further processing.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;You can find the full NSOperationQueue and NSThread extensions -- including example usage -- 
&lt;a href=&quot;http://github.com/landonf/block_samples/tree/master/NSOperationBlocks&quot;&gt;here.&lt;/a&gt;&lt;/p&gt;

&lt;h3 class=&quot;story&quot; &gt; UIActionSheet&lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;If you've done any iPhone development, you'll know that using
&lt;a href=&quot;http://developer.apple.com/IPhone/library/documentation/UIKit/Reference/UIActionSheet_Class/Reference/Reference.html&quot;&gt;UIActionSheet&lt;/a&gt;
is a bit complicated -- more so if you want to share an action sheet implementation across view controllers,
or display multiple UIActionSheets from a single view controller.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;If you've used UIActionSheet in the past, you've had to do the following:&lt;/p&gt;

&lt;ul class=&quot;story&quot;&gt;
&lt;li&gt;Create a UIActionSheet instance in your view controller.&lt;/li&gt;
&lt;li&gt;Add the UIActionSheetDelegate protocol to your view controller.&lt;/li&gt;
&lt;li&gt;Add the -[UIActionSheetDelegate actionSheet:clickedButtonAtIndex:] delegate method.&lt;/li&gt;
&lt;li&gt;Match the button index and source action sheet to your intended action, fetch any state you need, and execute.&lt;/li&gt;
&lt;/ul&gt;

&lt;p class=&quot;story&quot;&gt;Using blocks, we can significant reduce the effort required to define and use a UIActionSheet. Instead of defining a delegate, and matching
index values to your button actions, we can simply pass a block that implements the button's action directly:&lt;/p&gt;

&lt;pre class=&quot;story&quot; &gt;- (void) displaySheet {
    PLActionSheet *sheet = [[PLActionSheet alloc] initWithTitle: @&quot;Destination&quot;];
    
    /* A re-usable block that simply displays an alert message */
    void (^alert)(NSString *) = ^(NSString *message) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @&quot;Destination Selected&quot;
                                                        message: message
                                                       delegate: nil
                                              cancelButtonTitle: @&quot;OK&quot;
                                              otherButtonTitles: nil];
        
        [alert show];
        [alert release];
    };
    
    [sheet addButtonWithTitle: @&quot;Work&quot; block: ^{
        alert(@&quot;Work selected&quot;);
    }];
    
    [sheet addButtonWithTitle: @&quot;Home&quot; block: ^{
        alert(@&quot;Home selected&quot;);
    }];
    
    [sheet addButtonWithTitle: @&quot;School&quot; block: ^{
        alert(@&quot;School selected&quot;);
    }];
    
    [sheet setCancelButtonWithTitle: @&quot;Cancel&quot; block: ^{}];
 
    [sheet showInView: self.window];
    [sheet release];
}&lt;/pre&gt;

&lt;p class=&quot;story&quot;&gt;That's it -- there is nothing else. The blocks used for each button automatically have access to the enclosing
method's variables, and we even use another block (&lt;em&gt;alert&lt;/em&gt;) to avoid retyping the UIAlertView boilerplate
or cluttering our class with an alert method.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;You can find the full UIActionSheet wrapper -- including example usage -- 
&lt;a href=&quot;http://github.com/landonf/block_samples/tree/master/UIActionSheetBlocks&quot;&gt;here.&lt;/a&gt;&lt;/p&gt;

&lt;h3 class=&quot;story&quot; &gt; Conclusion&lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;I hope you'll find these examples useful in experimenting with and incorporating blocks into your own software. There are quite a few
other ways that blocks can be leveraged to decrease code size and complexity, and I'll plan on writing future articles on the subject.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;If you'd like to discuss blocks, the PLBlocks implementation, or having any other
questions, feel free to join the &lt;a href=&quot;http://groups.google.com/group/plblocks-devel&quot;&gt;PLBlocks mailing list.&lt;/a&gt;&lt;/p&gt;

</description>
</item>
<item>
	<title>PLBlocks: Blocks for iPhoneOS 3.0 and Mac OS X 10.5</title>
	<link>http://landonf.bikemonkey.org/2009/07/02#Blocks_For_iPhone.20090703</link>
	<guid>http://landonf.bikemonkey.org/2009/07/02#Blocks_For_iPhone.20090703</guid>
	<pubDate>Thu, 02 Jul 2009 21:50 PDT</pubDate>
	<description>&lt;p class=&quot;story&quot;&gt;Over the weekend (and for some of the week) I've been working on
back-porting block support from the &lt;a href=&quot;http://www.apple.com/macosx/&quot;&gt;Snow Leopard&lt;/a&gt;
toolchain, with the goal of leveraging blocks for our iPhone and Mac OS X 10.5
development at Plausible Labs.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;If you're unfamiliar with blocks, they're an implementation of closures for C,
Objective-C, and provisionally C++. The full &lt;a href=&quot;http://clang.llvm.org/docs/BlockLanguageSpec.txt&quot;&gt;language specification&lt;/a&gt;
and &lt;a href=&quot;http://clang.llvm.org/docs/BlockImplementation.txt&quot;&gt;ABI specification&lt;/a&gt; are available from the LLVM/Clang project.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;I've now published an initial beta release with support for iPhone OS 3.0 (armv6),
and Mac OS X 10.5 (i386, x86-64, ppc) -- you can find the full announcement -- including
download and usage instructions -- &lt;a href=&quot;http://www.plausiblelabs.com/blog/?p=8&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
</item>
<item>
	<title>New Plausible Labs Website</title>
	<link>http://landonf.bikemonkey.org/2009/05/20#Plausible_New_Website.20090521</link>
	<guid>http://landonf.bikemonkey.org/2009/05/20#Plausible_New_Website.20090521</guid>
	<pubDate>Wed, 20 May 2009 17:55 PDT</pubDate>
	<description>&lt;p class=&quot;story&quot;&gt;We just released a new design for the &lt;a href=&quot;http://www.plausiblelabs.com&quot;&gt;Plausible Labs&lt;/a&gt; website, home
of the fine worker-owned cooperative that keeps me gainfully employed so that I can
spend my free time (such as it exists) working on open source software.&lt;/p&gt;

</description>
</item>
<item>
	<title>Critical Mac OS X Java Vulnerabilities</title>
	<link>http://landonf.bikemonkey.org/2009/05/19#CVE-2008-5353.20090519</link>
	<guid>http://landonf.bikemonkey.org/2009/05/19#CVE-2008-5353.20090519</guid>
	<pubDate>Tue, 19 May 2009 14:42 PDT</pubDate>
	<description>&lt;h3 class=&quot;story&quot; &gt; Introduction&lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;Five months ago, &lt;a href=&quot;http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5353&quot;&gt;CVE-2008-5353&lt;/a&gt; and
&lt;a href=&quot;http://java.sun.com/javase/6/webnotes/6u11.html&quot;&gt;other vulnerabilities&lt;/a&gt; were publicly disclosed, and fixed by Sun.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;CVE-2008-5353 allows malicious code to escape the Java sandbox and run arbitrary
commands with the permissions of the executing user. This may result in untrusted Java applets
executing arbitrary code merely by visiting a web page hosting the applet. The issue
is trivially exploitable.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;Unfortunately, these vulnerabilities remain in Apple's shipping JVMs, as well as Soylatte 1.0.3. As
Soylatte does not provide browser plugins, the impact of the vulnerability is reduced. The recent
release of OpenJDK6/Mac OS X is not affected by CVE-2008-5353.&lt;/p&gt;

&lt;h3 class=&quot;story&quot; &gt; Work-Arounds&lt;/h3&gt;

&lt;ul class=&quot;story&quot;&gt;
&lt;li&gt;Mac OS X users should disable Java applets in their browsers and disable 'Open &quot;safe&quot; files after downloading' in Safari.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://landonf.bikemonkey.org/static/soylatte&quot;&gt;Soylatte&lt;/a&gt; users running untrusted code should upgrade to an OpenJDK6-based release, where possible. No future releases of the JRL-based Soylatte branch are planned at this time. If this is an issue for you, please feel free to &lt;a href=&quot;mailto:landonf@macports.org&quot;&gt;contact me&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 class=&quot;story&quot; &gt; Patch&lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;&lt;strong&gt;Update 06-15-2009:&lt;/strong&gt; Apple has released Java for Mac OS X 10.5 Update 4, which
contains a fix for this issue.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;To update your system, run &quot;Software Update&quot; from the Apple menu.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;&lt;strong&gt;Note&lt;/strong&gt;: Safari users should leave 'Open &quot;safe&quot; files after download' permanently disabled. Similarly critical vulnerabilities unrelated to Java remain in Safari's handling of &quot;Safe&quot; files.&lt;/p&gt;

&lt;h3 class=&quot;story&quot; &gt; Proof of Concept&lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;Unfortunately, it seems that many Mac OS X security issues are ignored if the severity of the issue
is not adequately demonstrated. Due to the fact that an exploit for this issue is available in the wild,
and the vulnerability has been public knowledge for six months, I have decided to release a my own
proof of concept to demonstrate the issue.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;If you visit the following page, &quot;/usr/bin/say&quot; will be executed on your system by a Java applet,
with your current user permissions. &lt;a href=&quot;http://landonf.bikemonkey.org/static/moab-tests/CVE-2008-5353/hello.html&quot;&gt;This link
will execute code on your system with your current user permissions.&lt;/a&gt; The proof of concept runs
on fully-patched PowerPC and Intel Mac OS X systems.&lt;/p&gt;

&lt;h3 class=&quot;story&quot; &gt; Credit&lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;Thanks to Jeffrey Czerniak for bringing this issue to my attention.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;&lt;strong&gt;Update:&lt;/strong&gt; Julien Tinnes e-mailed with a link to his in-depth discussion regarding the vulnerability &lt;a href=&quot;http://blog.cr0.org/2009/05/write-once-own-everyone.html&quot;&gt;available here.&lt;/a&gt;&lt;/p&gt;

</description>
</item>
<item>
	<title>OpenJDK 6 for Mac OS X</title>
	<link>http://landonf.bikemonkey.org/2009/05/17#OpenJDK6_MacPorts.20090516</link>
	<guid>http://landonf.bikemonkey.org/2009/05/17#OpenJDK6_MacPorts.20090516</guid>
	<pubDate>Sun, 17 May 2009 15:19 PDT</pubDate>
	<description>&lt;p class=&quot;story&quot;&gt;As part of the OpenJDK project, various organizations have been working on &lt;a href=&quot;http://openjdk.java.net/projects/jdk6/&quot;&gt;OpenJDK 6&lt;/a&gt;, a freely distributable
Java 6 implementation based on the open source OpenJDK 7 code base. Most Linux distributions are now shipping OpenJDK 6 binaries.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;&lt;a href=&quot;http://landonf.bikemonkey.org/static/soylatte&quot;&gt;Soylatte&lt;/a&gt; (Java 6 Port for Mac OS X) was originally based on the BSD port of
the &lt;a href=&quot;http://www.java.net/jrl.csp&quot;&gt;JRL&lt;/a&gt; licensed Java 6 code base, which significantly constrains end-user usage
and distribution rights. With Sun's approved re-licensing of the BSD changes for use in OpenJDK 7, a backport to OpenJDK 6 was made possible.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;I've added support for OpenJDK 6 on Mac OS X, based on Brian Gardner's &lt;a href=&quot;http://lists.freebsd.org/pipermail/freebsd-java/2009-February/007887.html&quot;&gt;work&lt;/a&gt; backporting the OpenJDK 7 BSD changes to
OpenJDK6/FreeBSD. Unlike the legacy Soylatte builds, OpenJDK 6 is:&lt;/p&gt;

&lt;ul class=&quot;story&quot;&gt;
&lt;li&gt;Open source and freely redistributable under the &lt;a href=&quot;http://www.openjdk.org/legal/gplv2+ce.html&quot;&gt;GPLv2 w/ ClassPath Exception license&lt;/a&gt; -- you may bundle the JDK/JRE with commerical products.&lt;/li&gt;
&lt;li&gt;More up-to-date -- the current build of OpenJDK6/Mac OS X should be runtime equivalent to Java 6 Update 11 (Sun JRL source releases are sporadic).&lt;/li&gt;
&lt;li&gt;Available as a binary package as well as installable via MacPorts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p class=&quot;story&quot;&gt;The initial beta release is available for testing via the &lt;a href=&quot;http://www.macports.org&quot;&gt;MacPorts&lt;/a&gt; openjdk6 port (Leopard only),
or as a binary from the &lt;a href=&quot;http://landonf.bikemonkey.org/static/soylatte&quot;&gt;Soylatte&lt;/a&gt; web page (Leopard/Tiger, untested on Tiger).
My ability to provide 10.4 support is constrained without access to a 10.4 machine, and any testing/development assistance is most welcome.&lt;/p&gt;

</description>
</item>
<item>
	<title>iPhone: Preventing Piracy</title>
	<link>http://landonf.bikemonkey.org/2009/02/13#iPhone_Preventing_Piracy.20090213</link>
	<guid>http://landonf.bikemonkey.org/2009/02/13#iPhone_Preventing_Piracy.20090213</guid>
	<pubDate>Fri, 13 Feb 2009 12:39 PST</pubDate>
	<description>&lt;p class=&quot;story&quot;&gt;There's a lot of talk lately about preventing application piracy on the iPhone. Automated tools have been
released to strip Apple's DRM, and a new anti-piracy product (which charges royalty fees on your sales) has
&lt;a href=&quot;http://www.tuaw.com/2009/02/11/ripdev-launches-anti-piracy-service-for-iphone-developers/&quot;&gt;been released&lt;/a&gt;.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;As an iPhone developer, you have no access to the purchasing process. You can't issue (or revoke) serial numbers,
implement an activation scheme, or provide any other fully independent copy protection. The only way to differentiate
between a purchased copy of your application and a pirated one is to implement your own code to introspect the DRM
that Apple has applied to your application.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;On the phone, purchased applications are shipped to the user with a variety of meta-data that is readable
by the application. The information potentially useful for implementing additional copy protection includes:&lt;/p&gt;

&lt;ul class=&quot;story&quot;&gt;
&lt;li&gt;iTunesMetadata.plist - Media &amp;amp; Purchase Information (incl user's name, Apple ID, and purchase date)&lt;/li&gt;
&lt;li&gt;SC_Info - FairPlay DRM Metadata&lt;/li&gt;
&lt;li&gt;Code Signing - Binaries and resources are encrypted and signed by Apple&lt;/li&gt;
&lt;/ul&gt;

&lt;p class=&quot;story&quot;&gt;Using this information, it is possible to implement additional copy protection. The signature can be checked,
the application encryption can be verified, etc. However, there's a problem -- none of this is documented
by Apple. While most of the APIs and file formats are public, the actual distribution format is not. Apple
could change the signature format, the meta-data plist, or any other distribution component at any time, at
which point your copy protection may raise a false positive, and your paying customers will be wondering
why you're wasting their time.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;Given the risks, I've decided against implementing any further copy protection in my applications -- I believe it's
Apple's problem to solve, and don't think it's worth risking false positives and annoyed customers. That said, if
you'd like to take the plunge, here is some example code to get you started. For further reading, I suggest starting with
Apple's &lt;a href=&quot;http://developer.apple.com/technotes/tn2007/tn2206.html&quot;&gt;Mac OS X Code Signing In Depth&lt;/a&gt; and Amit Singh's
&lt;a href=&quot;http://www.osxbook.com/book/bonus/chapter7/binaryprotection/&quot;&gt;Understanding Apple's Binary Protection in Mac OS X&lt;/a&gt;.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;The current process of cracking an application relies on stripping the application of encryption by attaching a
debugger to the application on a jailbroken phone, dumping the text section containing the program code, and
reinserting it into the original binary. The below code checks for the existence of LC_ENCRYPTION_INFO, and
verifies that encryption is still enabled. There are, of course, a number of ways to defeat this check, but
that's the nature of copy protection:&lt;/p&gt;

&lt;pre class=&quot;story&quot; &gt;#import &amp;lt;dlfcn.h&amp;gt;
#import &amp;lt;mach-o/dyld.h&amp;gt;
#import &amp;lt;TargetConditionals.h&amp;gt;
 
/* The encryption info struct and constants are missing from the iPhoneSimulator SDK, but not from the iPhoneOS or
 * Mac OS X SDKs. Since one doesn't ever ship a Simulator binary, we'll just provide the definitions here. */
#if TARGET_IPHONE_SIMULATOR &amp;&amp; !defined(LC_ENCRYPTION_INFO)
#define LC_ENCRYPTION_INFO 0x21
struct encryption_info_command {
    uint32_t cmd;
    uint32_t cmdsize;
    uint32_t cryptoff;
    uint32_t cryptsize;
    uint32_t cryptid;
};
#endif
  
int main (int argc, char *argv[]);
  
static BOOL is_encrypted () {
    const struct mach_header *header;
    Dl_info dlinfo;
      
    /* Fetch the dlinfo for main() */
    if (dladdr(main, &amp;dlinfo) == 0 || dlinfo.dli_fbase == NULL) {
        NSLog(@&quot;Could not find main() symbol (very odd)&quot;);
        return NO;
    }
    header = dlinfo.dli_fbase;
 
    /* Compute the image size and search for a UUID */
    struct load_command *cmd = (struct load_command *) (header+1);
     
    for (uint32_t i = 0; cmd != NULL &amp;&amp; i &amp;lt; header-&amp;gt;ncmds; i++) {
        /* Encryption info segment */
        if (cmd-&amp;gt;cmd == LC_ENCRYPTION_INFO) {
            struct encryption_info_command *crypt_cmd = (struct encryption_info_command *) cmd;
            /* Check if binary encryption is enabled */
            if (crypt_cmd-&amp;gt;cryptid &amp;lt; 1) {
                /* Disabled, probably pirated */
                return NO;
            }
             
            /* Probably not pirated? */
            return YES;
        }
         
        cmd = (struct load_command *) ((uint8_t *) cmd + cmd-&amp;gt;cmdsize);
    }
     
    /* Encryption info not found */
    return NO;
}&lt;/pre&gt;

</description>
</item>
<item>
	<title>Open Source Crash Reporter for iPhone (and Mac OS X)</title>
	<link>http://landonf.bikemonkey.org/2009/01/29#Crash_Reporter.20090129</link>
	<guid>http://landonf.bikemonkey.org/2009/01/29#Crash_Reporter.20090129</guid>
	<pubDate>Thu, 29 Jan 2009 16:41 PST</pubDate>
	<description>&lt;h3 class=&quot;story&quot; &gt; Introduction&lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;Despite my best efforts to the contrary, I ship software with bugs.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;After unit testing and integration testing, the bugs that tend to slip through are tricky ones -- race
conditions, crashes triggered by bugs in platform vendor's implementation, and issues that only appear
in specific configurations, such as a user synchronizing their iPhone's Address Book with Microsoft Outlook.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;These are the types of issues that you hope to catch in beta testing. If you don't, however, these bugs leak
into the wild.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;On the iPhone, Apple generates crash logs for every third-party application crash. These plain text logs include backtraces,
thread state, and other information to help you debug your crashes. Unfortunately, these crash logs are not actually
readable by third party applications. As a software developer, you're reliant on users to report the bug
(rather than, say, simply delete your application), and then at your behest, synchronize their iPhone, locate the
(correct!) crash log on disk, and send it to you.&lt;/p&gt;

&lt;h3 class=&quot;story&quot; &gt; Plausible Crash Reporter&lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;To solve this problem, I decided to implement our own Crash Reporter. It sports the following features:&lt;/p&gt;

&lt;ul class=&quot;story&quot;&gt;
&lt;li&gt;Implemented as a in-process signal handler&lt;/li&gt;
&lt;li&gt;Does not interfere with debugging in gdb&lt;/li&gt;
&lt;li&gt;Handles both uncaught Objective-C exceptions and fatal signals (SIGSEGV, SIGBUS, etc)&lt;/li&gt;
&lt;li&gt;Full thread state for all active threads (backtraces, register dumps) is provided&lt;/li&gt;
&lt;/ul&gt;

&lt;p class=&quot;story&quot;&gt;If your application crashes, a crash report will be written. When the application is next run, you may check for a
pending crash report, submit the report to your own HTTP server, send an e-mail, or even introspect the
report locally. Additionally, I hope to add support for services like &lt;a href=&quot;http://www.getexceptional.com&quot;&gt;getexceptional&lt;/a&gt; to
automatically handle uploading, notification, and tracking of crashing issues.&lt;/p&gt;

&lt;h3 class=&quot;story&quot; &gt; Crash Report Format&lt;/h3&gt;

&lt;p class=&quot;story&quot;&gt;Crash logs are encoded using &lt;a href=&quot;http://code.google.com/p/protobuf/&quot;&gt;google protobuf&lt;/a&gt;, and may be decoded
using the PLCrashReport API. Additionally, the included plcrashutil handles conversion of binary crash reports to the 
symbolicate-compatible iPhone text format.&lt;/p&gt;

&lt;h3 class=&quot;story&quot; &gt; Example iPhone Usage&lt;/h3&gt;

&lt;pre class=&quot;story&quot; &gt;/**
 * Called to handle a pending crash report.
 */
- (void) handleCrashReport {
    PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];
    NSData *crashData;
    NSError *error;
  
    /* Try loading the crash report */
    crashData = [crashReporter loadPendingCrashReportDataAndReturnError: &amp;error];
    if (crashData == nil) {
        NSLog(@&quot;Could not load crash report: %@&quot;, error);
        goto finish;
    }
  
    /* We could send the report from here, but we'll just print out
     * some debugging info instead */
    PLCrashReport *report = [[[PLCrashReport alloc] initWithData: crashData error: &amp;error] autorelease];
    if (report == nil) {
        NSLog(@&quot;Could not parse crash report&quot;);
        goto finish;
    }
  
    NSLog(@&quot;Crashed on %@&quot;, report.systemInfo.timestamp);
    NSLog(@&quot;Crashed with signal %@ (code %@, address=0x%&quot; PRIx64 &quot;)&quot;, report.signalInfo.name,
          report.signalInfo.code, report.signalInfo.address);
 
    /* Purge the report */
finish:
    [crashReporter purgePendingCrashReport];
    return;
}
 
// from UIApplicationDelegate protocol
- (void) applicationDidFinishLaunching: (UIApplication *) application {
    PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];
    NSError *error;
 
    /* Check if we previously crashed */
    if ([crashReporter hasPendingCrashReport])
        [self handleCrashReport];
 
    /* Enable the Crash Reporter */
    if (![crashReporter enableCrashReporterAndReturnError: &amp;error])
        NSLog(@&quot;Warning: Could not enable crash reporter: %@&quot;, error);
 
    ...
}&lt;/pre&gt;

&lt;p class=&quot;story&quot;&gt;The first beta release is now available as open source (MIT licensed) from the &lt;a href=&quot;http://code.google.com/p/plcrashreporter/&quot;&gt;PLCrashReporter Project Page&lt;/a&gt;. This
is intended for developer testing, and your feedback is most appreciated.&lt;/p&gt;

&lt;p class=&quot;story&quot;&gt;If you're interested in additional functionality, integration support, or other development services, feel free to &lt;a href=&quot;mailto:landonf@plausiblelabs.com&quot;&gt;drop me a line&lt;/a&gt;.
We also gladly accept donations to support our open source development efforts: &lt;a href=&quot;https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=2866045&quot;&gt;Donate via Paypal&lt;/a&gt;&lt;/p&gt;

</description>
</item>
</channel>
</rss>
