[Vm-dev] what about image reading?

David T. Lewis lewis at mail.msen.com
Thu Jan 13 18:46:41 UTC 2011


On Thu, Jan 13, 2011 at 06:20:28PM +0100, Tobias Pape wrote:
> 
> Am 2011-01-13 um 17:52 schrieb David T. Lewis:
> > 
> > On Thu, Jan 13, 2011 at 05:26:34PM +0100, Tobias Pape wrote:
> >> [?]
> >> 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?
> >> [?]
> > 
> > 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.
> 
> 
> The _purpose_ of the 512byte skip was clear to me.
> I was just puzzled that there is no reference to the indicated method whatsoever.
> Can you give me a hint, where that is used?

I'm away from Squeak at the moment, but look in class Interpreter
in package VMMaker. I think the method is #readImageFromFile:HeapSize:StartingAt:
or similar. The colons get removed from the method/function name as
part of the translation to C.

Dave



More information about the Vm-dev mailing list