[Vm-dev] what about image reading?

David T. Lewis lewis at mail.msen.com
Thu Jan 13 16:52:49 UTC 2011


On Thu, Jan 13, 2011 at 05:26:34PM +0100, Tobias Pape wrote:
> 
> Dear all,
> 
> I'm just getting grips on the squeak image format and
> I am trying to make sense of the "512 bytes padding" possibility.
>   In a previous discussion, the method
> Interpreter>>readImageFromFile: f HeapSize: desiredHeapSize StartingAt: imageOffset
> was mentioned that can read the image format using the given offset.
> However, neither in the Smalltalk code nor in the generated C code I was able
> to find any uses of this. 
> 
> SqueakVMMaker/src ??? grep -iR readImageFromFileHeapSizeStartingAt *
> vm/interp.c:sqInt readImageFromFileHeapSizeStartingAt(sqImageFile  f, usqInt desiredHeapSize, squeakFileOffsetType  imageOffset);
> vm/interp.c:sqInt readImageFromFileHeapSizeStartingAt(sqImageFile  f, usqInt desiredHeapSize, squeakFileOffsetType  imageOffset) {
> 
> Is this by design? Did I miss something?
> 
> So Long,
> 	-Tobias

The purpose of this feature is to support "shebang" processing:
  http://en.wikipedia.org/wiki/Shebang_(Unix)

The idea is to offset the start of the image by 512 bytes into
the image file, and put the hash-bang line at the beginning
of the file. The hash-bang line invokes the VM, and the VM
reads the file containing the image at offset 512. The VM
first tries to read the image starting at offset 0, which
fails because it sees the hash-bang instead of the image
format word. It then skips ahead 512 bytes, tries again, and
presto the image starts up.

The end result is that an image file can be turned into an
executable file that runs itself.

Dave



More information about the Vm-dev mailing list