VM Maker: VMMaker-dtl.402.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

VM Maker: VMMaker-dtl.402.mcz

commits-2
 
David T. Lewis uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker-dtl.402.mcz

==================== Summary ====================

Name: VMMaker-dtl.402
Author: dtl
Time: 26 September 2019, 7:37:15.375 pm
UUID: ac8bd24c-b252-4e8f-a6c6-f8884f0cdf6f
Ancestors: VMMaker-dtl.401

VMMaker 4.16.7
Fix an ancient slip, do not set Mac file type twice when saving the image. The second call happens after the image file has been closed, which fails on newer OS X systems. Eliminate the duplicate call and ensure that setting Mac file type happens before closing the file stream. The original slip appears to have been introduced in VMMaker-tpr.15 in April 2005.

=============== Diff against VMMaker-dtl.401 ===============

Item was changed:
  ----- Method: ContextInterpreter>>snapshot: (in category 'image save/restore') -----
  snapshot: embedded
 
+ | dataSize rcvr |
- | dataSize rcvr setMacType |
  dataSize := self prepareForSnapshot.
  self successful
  ifTrue: [rcvr := self popStack.
  "pop rcvr"
  self push: objectMemory getTrueObj.
+ self writeImageFileIO: dataSize embedded: embedded.
- self writeImageFile: dataSize.
- embedded
- ifFalse: ["set Mac file type and creator; this is a noop on other platforms"
- setMacType := self ioLoadFunction: 'setMacFileTypeAndCreator' From: 'FilePlugin'.
- setMacType = 0
- ifFalse: [self cCode: '((sqInt (*)(char *, char *, char *))setMacType)(imageName, "STim", "FAST")']].
  self pop: 1].
 
  "activeContext was unmarked in #snapshotCleanUp, mark it old "
  objectMemory beRootIfOld: activeContext.
  self successful
  ifTrue: [self push: objectMemory getFalseObj]
  ifFalse: [self push: rcvr].
  compilerInitialized
  ifTrue: [self compilerPostSnapshot]!

Item was removed:
- ----- Method: ContextInterpreter>>writeImageFile: (in category 'image save/restore') -----
- writeImageFile: imageBytes
-
- | fn |
- <var: #fn type: 'void *'>
- self writeImageFileIO: imageBytes.
- "set Mac file type and creator; this is a noop on other platforms"
- fn := self ioLoadFunction: 'setMacFileTypeAndCreator' From: 'FilePlugin'.
- fn = 0 ifFalse:[
- self cCode:'((sqInt (*)(char*, char*, char*))fn)(imageName, "STim", "FAST")'.
- ].
- !

Item was added:
+ ----- Method: ContextInterpreter>>writeImageFileIO:embedded: (in category 'image save/restore') -----
+ writeImageFileIO: imageBytes embedded: embedded
+
+ | headerStart headerSize f bytesWritten sCWIfn okToWrite |
+ <var: #f type: 'sqImageFile'>
+ <var: #headerStart type: 'squeakFileOffsetType '>
+ <var: #sCWIfn type: 'void *'>
+
+ "If the security plugin can be loaded, use it to check for write permission.
+ If not, assume it's ok"
+ sCWIfn := self ioLoadFunction: 'secCanWriteImage' From: 'SecurityPlugin'.
+ sCWIfn ~= 0 ifTrue:[okToWrite := self cCode: '((sqInt (*)(void))sCWIfn)()'.
+ okToWrite ifFalse:[^self primitiveFail]].
+
+ "local constants"
+ headerStart := 0.  
+ headerSize := 16 * objectMemory bytesPerWord.  "header size in bytes; do not change!!"
+
+ f := self cCode: 'sqImageFileOpen(imageName, "wb")'.
+ f = nil ifTrue: [
+ "could not open the image file for writing"
+ self success: false.
+ ^ nil].
+
+ headerStart := self cCode: 'sqImageFileStartLocation(f,imageName,headerSize+imageBytes)'.
+ self cCode: '/* Note: on Unix systems one could put an exec command here, padded to 512 bytes */'.
+ "position file to start of header"
+ self sqImageFile: f Seek: headerStart.
+
+ self putLong: (self imageFormatVersion) toFile: f.
+ self putLong: headerSize toFile: f.
+ self putLong: imageBytes toFile: f.
+ self putLong: (objectMemory startOfMemory) toFile: f.
+ self putLong: objectMemory getSpecialObjectsOop toFile: f.
+ self putLong: objectMemory getLastHash toFile: f.
+ self putLong: (self ioScreenSize) toFile: f.
+ self putLong: fullScreenFlag toFile: f.
+ self putLong: extraVMMemory toFile: f.
+ 1 to: 7 do: [:i | self putLong: 0 toFile: f].  "fill remaining header words with zeros"
+ self successful ifFalse: [
+ "file write or seek failure"
+ self cCode: 'sqImageFileClose(f)'.
+ ^ nil].
+
+ "position file after the header"
+ self sqImageFile: f Seek: headerStart + headerSize.
+
+ "write the image data"
+ bytesWritten := self
+ sqImage: (objectMemory pointerForOop: objectMemory getMemory)
+ write: f
+ size: (self cCode: 'sizeof(unsigned char)')
+ length: imageBytes.
+ self success: bytesWritten = imageBytes.
+ embedded ifFalse: [self setMacFileTypeForImageFile].
+ self cCode: 'sqImageFileClose(f)'.
+
+ !

Item was added:
+ ----- Method: Interpreter>>setMacFileTypeForImageFile (in category 'image save/restore') -----
+ setMacFileTypeForImageFile
+ "Set Mac file type and creator; this is a noop on other platforms"
+ | setMacType |
+ <var: #setMacType type: 'void *'>
+ setMacType := self ioLoadFunction: 'setMacFileTypeAndCreator' From: 'FilePlugin'.
+ setMacType = 0 ifFalse:
+ [self cCode: '((sqInt (*)(char *, char *, char *))setMacType)(imageName, "STim", "FAST")'].
+ !

Item was added:
+ ----- Method: InterpreterSimulator>>writeImageFileIO:embedded: (in category 'image save/restore') -----
+ writeImageFileIO: numberOfBytesToWrite embedded: embedded
+ ^self writeImageFileIO: numberOfBytesToWrite
+ !

Item was changed:
  ----- Method: StackInterpreter>>snapshot: (in category 'image save/restore') -----
  snapshot: embedded
  "update state of active context"
+ | activeContext activeProc dataSize rcvr stackIndex |
- | activeContext activeProc dataSize rcvr setMacType stackIndex |
  <var: #setMacType type: 'void *'>
 
  "Need to convert all frames into contexts since the snapshot file only holds objects."
  self push: instructionPointer.
  activeContext := self voidVMStateForSnapshot.
  objectMemory pushRemappableOop: activeContext.
 
  "update state of active process"
  activeProc := self activeProcess.
  objectMemory
  storePointer: SuspendedContextIndex
  ofObject: activeProc
  withValue: activeContext.
 
  "compact memory and compute the size of the memory actually in use"
  objectMemory incrementalGC.
 
  "maximimize space for forwarding table"
  objectMemory fullGC.
  self snapshotCleanUp.
 
  "Nothing moves from here on so it is safe to grab the activeContext again."
  activeContext := objectMemory popRemappableOop.
 
  dataSize := objectMemory freeStart - objectMemory startOfMemory. "Assume all objects are below the start of the free block"
  self successful ifTrue:
  ["Without contexts or stacks simulate
  rcvr := self popStack.
  ''pop rcvr''
  self push: trueObj.
   to arrange that the snapshot resumes with true.  N.B. stackIndex is one-relative."
  stackIndex := self quickFetchInteger: StackPointerIndex ofObject: activeContext.
  rcvr := objectMemory fetchPointer: stackIndex + CtxtTempFrameStart - 1 ofObject: activeContext.
  objectMemory storePointerUnchecked: stackIndex + CtxtTempFrameStart - 1
  ofObject: activeContext
  withValue: objectMemory trueObject.
  "now attempt to write the snapshot file"
+ self writeImageFileIO: dataSize embedded: embedded.
- self writeImageFile: dataSize.
- embedded ifFalse:
- ["set Mac file type and creator; this is a noop on other platforms"
- setMacType := self ioLoadFunction: 'setMacFileTypeAndCreator' From: 'FilePlugin'.
- setMacType = 0 ifFalse:
- [self cCode: '((sqInt (*)(char *, char *, char *))setMacType)(imageName, "STim", "FAST")']].
  "Without contexts or stacks simulate
  self pop: 1"
  objectMemory storePointerUnchecked: StackPointerIndex
  ofObject: activeContext
  withValue: (objectMemory integerObjectOf: stackIndex - 1)].
 
  self marryContextInNewStackPageAndInitializeInterpreterRegisters: activeContext.
  self successful
  ifTrue: [self push: objectMemory falseObject]
  ifFalse: [self push: rcvr]!

Item was removed:
- ----- Method: StackInterpreter>>writeImageFile: (in category 'image save/restore') -----
- writeImageFile: imageBytes
-
- | fn |
- <var: #fn type: 'void *'>
- self writeImageFileIO: imageBytes.
- "set Mac file type and creator; this is a noop on other platforms"
- fn := self ioLoadFunction: 'setMacFileTypeAndCreator' From: 'FilePlugin'.
- fn = 0 ifFalse:[
- self cCode:'((sqInt (*)(char*, char*, char*))fn)(imageName, "STim", "FAST")'.
- ].
- !

Item was added:
+ ----- Method: StackInterpreter>>writeImageFileIO:embedded: (in category 'image save/restore') -----
+ writeImageFileIO: imageBytes embedded: embedded
+
+ | headerStart headerSize f bytesWritten sCWIfn okToWrite memStart |
+ <var: #f type: 'sqImageFile'>
+ <var: #headerStart type: 'squeakFileOffsetType '>
+ <var: #sCWIfn type: 'void *'>
+
+ "If the security plugin can be loaded, use it to check for write permission.
+ If not, assume it's ok"
+ sCWIfn := self ioLoadFunction: 'secCanWriteImage' From: 'SecurityPlugin'.
+ sCWIfn ~= 0 ifTrue:
+ [okToWrite := self cCode: '((sqInt (*)(void))sCWIfn)()'.
+ okToWrite ifFalse:[^self primitiveFail]].
+
+ "local constants"
+ headerStart := 0.  
+ headerSize := 64.  "header size in bytes; do not change!!"
+
+ f := self cCode: 'sqImageFileOpen(imageName, "wb")'.
+ f = nil ifTrue: "could not open the image file for writing"
+ [^self primitiveFail].
+
+ headerStart := self cCode: 'sqImageFileStartLocation(f,imageName,headerSize+imageBytes)'.
+ self cCode: '/* Note: on Unix systems one could put an exec command here, padded to 512 bytes */'.
+ "position file to start of header"
+ self sqImageFile: f Seek: headerStart.
+
+ self putLong: self imageFormatVersion toFile: f.
+ self putLong: headerSize toFile: f.
+ self putLong: imageBytes toFile: f.
+ self putLong: objectMemory startOfMemory toFile: f.
+ self putLong: objectMemory getSpecialObjectsOop toFile: f.
+ self putLong: objectMemory newObjectHash toFile: f.
+ self putLong: self ioScreenSize toFile: f.
+ self putLong: self getImageHeaderFlags toFile: f.
+ self putLong: extraVMMemory toFile: f.
+ self putShort: desiredNumStackPages toFile: f.
+ self putShort: self unknownShortOrCodeSizeInKs toFile: f.
+ self putLong: desiredEdenBytes toFile: f.
+ self putShort: (maxExtSemTabSizeSet ifTrue: [self ioGetMaxExtSemTableSize] ifFalse: [0]) toFile: f.
+ self putShort: 0 toFile: f.
+ 1 to: 4 do: [:i | self putLong: 0 toFile: f].  "fill remaining header words with zeros"
+ self successful ifFalse: [
+ "file write or seek failure"
+ self cCode: 'sqImageFileClose(f)'.
+ ^ nil].
+
+ "position file after the header"
+ self sqImageFile: f Seek: headerStart + headerSize.
+
+ "write the image data"
+ memStart := objectMemory startOfMemory.
+ bytesWritten := self cCode: 'sqImageFileWrite(pointerForOop(memStart), sizeof(unsigned char), imageBytes, f)'.
+ self success: bytesWritten = imageBytes.
+ self touch: memStart.
+ embedded ifFalse: [self setMacFileTypeForImageFile].
+ self cCode: 'sqImageFileClose(f)'
+ !

Item was added:
+ ----- Method: StackInterpreterSimulator>>writeImageFileIO:embedded: (in category 'image save/restore') -----
+ writeImageFileIO: numberOfBytesToWrite embedded: embedded
+ ^self writeImageFileIO: numberOfBytesToWrite
+ !

Item was changed:
  ----- Method: VMMaker class>>versionString (in category 'version testing') -----
  versionString
 
  "VMMaker versionString"
 
+ ^'4.16.7'!
- ^'4.16.6'!