David T. Lewis uploaded a new version of VMMaker to project VM Maker Inbox: http://source.squeak.org/VMMakerInbox/VMMaker-dtl.407.mcz ==================== Summary ==================== Name: VMMaker-dtl.407 Author: dtl Time: 30 November 2019, 3:09:22.384 pm UUID: 190f79b2-f9f4-4585-9010-4db1afe51481 Ancestors: VMMaker-dtl.406 VMMaker 4.17.1 Implement ContextInterpreter>>primitiveResumeFromSnapshot. This primitive discards the current object memory and resumes interpreter execution in the provided snapshot. Use primitiveMemorySnapshotBytesWithHeader or primitiveMemorySnapshotWithHeader to obtain a snapshot object within a running image, and primitveResumeFromSnapshot to resume into a snapshot object from a sacrificial donor image. For supporting code see www.squeaksource.com/ImageSnapshot and package ImageFormat in the source.squeak.org/VMMaker repository. =============== Diff against VMMaker-dtl.406 =============== Item was added: + ----- Method: ContextInterpreter>>primitiveResumeFromSnapshot (in category 'snapshot utility primitives') ----- + primitiveResumeFromSnapshot + "Discard the current object memory and resume interpreter execution + in the provided snapshot." + + <export: true> + | expectedArraySize snapshotValues size newMemoryBytesOrBitmap bigEndian snapshotImageFormat snapshotStartOfMemory snapshotSpecialObjectsOop snapshotLastHash screenSizePoint headerSize imageBytes imageHeaderFlags snapshotExtraVMMemory swapBytes snapshotFullScreen defaultHeapSize desiredHeapSize | + expectedArraySize := 11. "ImageSnapshot new asValues size => 11" + argumentCount == 1 + ifFalse: [ ^self primitiveFailFor: PrimErrBadNumArgs]. + snapshotValues := self stackObjectValue: 0. + self assertClassOf: snapshotValues is: (objectMemory splObj: ClassArray). + self successful + ifFalse: [ ^self primitiveFailFor: PrimErrBadArgument]. + size := objectMemory numSlotsOf: snapshotValues. + size < expectedArraySize ifTrue: [ ^self primitiveFailFor: PrimErrBadArgument]. + newMemoryBytesOrBitmap := objectMemory fetchPointer: 0 ofObject: snapshotValues. + bigEndian := (objectMemory fetchPointer: 1 ofObject: snapshotValues) = objectMemory trueObject. + snapshotImageFormat := objectMemory integerValueOf: (objectMemory fetchPointer: 2 ofObject: snapshotValues).. + headerSize := objectMemory integerValueOf: (objectMemory fetchPointer: 3 ofObject: snapshotValues).. + imageBytes := self positive32BitValueOf: (objectMemory fetchPointer: 4 ofObject: snapshotValues).. "good for up to 2GB image" + snapshotStartOfMemory := objectMemory integerValueOf: (objectMemory fetchPointer: 5 ofObject: snapshotValues).. + snapshotSpecialObjectsOop := objectMemory integerValueOf: (objectMemory fetchPointer: 6 ofObject: snapshotValues).. + snapshotLastHash := objectMemory integerValueOf: (objectMemory fetchPointer: 7 ofObject: snapshotValues).. + screenSizePoint := objectMemory fetchPointer: 8 ofObject: snapshotValues.. + self assertClassOf: screenSizePoint is: (objectMemory splObj: ClassPoint). + self successful + ifFalse: [ ^self primitiveFailFor: PrimErrBadArgument]. + imageHeaderFlags := objectMemory integerValueOf: (objectMemory fetchPointer: 9 ofObject: snapshotValues).. + snapshotExtraVMMemory := objectMemory integerValueOf: (objectMemory fetchPointer: 10 ofObject: snapshotValues).. + + swapBytes := bigEndian ~= self isBigEnder. + snapshotFullScreen := false. "FIXME" + + "From sqUnixMain.c + #define DefaultHeapSize 20 + megabytes BEYOND actual image size" + defaultHeapSize := 20 * 1000 * 1000. + desiredHeapSize := defaultHeapSize + imageBytes. + + self + snapshotResume: newMemoryBytesOrBitmap + heapSize: desiredHeapSize + swapBytes: swapBytes + oldBaseAddr: snapshotStartOfMemory + specialObjectsOop: snapshotSpecialObjectsOop + lastHash: snapshotLastHash + savedWindowSize: screenSizePoint + fullScreenFlag: snapshotFullScreen + extraVMMemory: snapshotExtraVMMemory. + + self pop: 1 thenPush: newMemoryBytesOrBitmap. + + ! Item was added: + ----- Method: ContextInterpreter>>snapshotResume:heapSize:swapBytes:oldBaseAddr:specialObjectsOop:lastHash:savedWindowSize:fullScreenFlag:extraVMMemory: (in category 'snapshot utility primitives') ----- + snapshotResume: byteArrayOrBitmap heapSize: desiredHeapSize swapBytes: swapBytes oldBaseAddr: oldBaseAddr specialObjectsOop: specialObjects lastHash: hashValue savedWindowSize: windowSize fullScreenFlag: fullScreen extraVMMemory: extraMemory + "Arrange for the interpreter to resume execution from a snapshot of saved + memory and interpreter state. The current object memory and interpreter state + will be discarded, and the interpreter will resume execution at the point of the + supplied image snapshot. Answer the address of the previous object memory + or nil if this is the first evaluation." + + | dataSize sourceBytes mem | + <returnTypeC: 'usqInt'> + <var: #desiredHeapSize type: 'usqInt'> + <var: #dataSize type: 'size_t '> + <var: #sourceBytes type: 'char *'> + <var: #mem type: 'char *'> + + "Notes - The parameters windowSize, fullScreen and extraMemory are currently + not used when resuming the VM in a new image. The display size and fullscreen + mode are probably best set from the image by calling primitiveSetDisplayMode + prior to primitiveResumeFromSnapshot. The extraMemory parameter is ignored + here because we are simply copying the new object memory over a previously + allocated heap space." + + dataSize := objectMemory byteSizeOf: byteArrayOrBitmap. + sourceBytes := objectMemory firstIndexableField: byteArrayOrBitmap. + objectMemory setSpecialObjectsOop: specialObjects. + objectMemory setLastHash: hashValue. + + "Copy object memory into allocated space" + objectMemory setMemoryLimits: dataSize heapSize: desiredHeapSize. + mem := objectMemory pointerForOop: objectMemory getMemory. + self mem: mem + cp: sourceBytes + y: dataSize. + + self swapBytesAndPrepareToInterpret: swapBytes oldBaseAddr: oldBaseAddr. + self interpret. "Resume interpreter execution in the snapshot." + ! Item was added: + ----- Method: ObjectMemory>>setMemoryLimits:heapSize: (in category 'image save/restore') ----- + setMemoryLimits: dataSize heapSize: heapSize + "Set memory limits, assuming that previously allocated heap space is sufficient. + Use this instead of allocateMemory: dataSize heapSize: desiredHeapSize when + resuming the interpreter in a new inage snapshot using previously allocated + heap memory." + + | minimumMemory | + <var: #heapSize type: 'usqInt'> + <var: #dataSize type: 'size_t '> + + minimumMemory := dataSize + 100000. "need at least 100K of breathing room" + "compare memory requirements with availability". + heapSize < minimumMemory ifTrue: [ "try to make more space" + self growObjectMemory: minimumMemory - heapSize. + heapSize < minimumMemory ifTrue: [ + interpreter insufficientMemorySpecifiedError]]. + self setEndOfMemory: memory + dataSize. + ! Item was changed: ----- Method: VMMaker class>>versionString (in category 'version testing') ----- versionString "VMMaker versionString" + ^'4.17.1'! - ^'4.16.9'! |
I put this in the VMMaker inbox because it is tested only on Linux, and because it presumably could open some rather interesting security holes in the system. Dave On Sun, Dec 01, 2019 at 03:35:04PM +0000, [hidden email] wrote: > > David T. Lewis uploaded a new version of VMMaker to project VM Maker Inbox: > http://source.squeak.org/VMMakerInbox/VMMaker-dtl.407.mcz > > ==================== Summary ==================== > > Name: VMMaker-dtl.407 > Author: dtl > Time: 30 November 2019, 3:09:22.384 pm > UUID: 190f79b2-f9f4-4585-9010-4db1afe51481 > Ancestors: VMMaker-dtl.406 > > VMMaker 4.17.1 > Implement ContextInterpreter>>primitiveResumeFromSnapshot. This primitive discards the current object memory and resumes interpreter execution in the provided snapshot. > > Use primitiveMemorySnapshotBytesWithHeader or primitiveMemorySnapshotWithHeader to obtain a snapshot object within a running image, and primitveResumeFromSnapshot to resume into a snapshot object from a sacrificial donor image. > > For supporting code see www.squeaksource.com/ImageSnapshot and package ImageFormat in the source.squeak.org/VMMaker repository. > > =============== Diff against VMMaker-dtl.406 =============== > > Item was added: > + ----- Method: ContextInterpreter>>primitiveResumeFromSnapshot (in category 'snapshot utility primitives') ----- > + primitiveResumeFromSnapshot > + "Discard the current object memory and resume interpreter execution > + in the provided snapshot." > + > + <export: true> > + | expectedArraySize snapshotValues size newMemoryBytesOrBitmap bigEndian snapshotImageFormat snapshotStartOfMemory snapshotSpecialObjectsOop snapshotLastHash screenSizePoint headerSize imageBytes imageHeaderFlags snapshotExtraVMMemory swapBytes snapshotFullScreen defaultHeapSize desiredHeapSize | > + expectedArraySize := 11. "ImageSnapshot new asValues size => 11" > + argumentCount == 1 > + ifFalse: [ ^self primitiveFailFor: PrimErrBadNumArgs]. > + snapshotValues := self stackObjectValue: 0. > + self assertClassOf: snapshotValues is: (objectMemory splObj: ClassArray). > + self successful > + ifFalse: [ ^self primitiveFailFor: PrimErrBadArgument]. > + size := objectMemory numSlotsOf: snapshotValues. > + size < expectedArraySize ifTrue: [ ^self primitiveFailFor: PrimErrBadArgument]. > + newMemoryBytesOrBitmap := objectMemory fetchPointer: 0 ofObject: snapshotValues. > + bigEndian := (objectMemory fetchPointer: 1 ofObject: snapshotValues) = objectMemory trueObject. > + snapshotImageFormat := objectMemory integerValueOf: (objectMemory fetchPointer: 2 ofObject: snapshotValues).. > + headerSize := objectMemory integerValueOf: (objectMemory fetchPointer: 3 ofObject: snapshotValues).. > + imageBytes := self positive32BitValueOf: (objectMemory fetchPointer: 4 ofObject: snapshotValues).. "good for up to 2GB image" > + snapshotStartOfMemory := objectMemory integerValueOf: (objectMemory fetchPointer: 5 ofObject: snapshotValues).. > + snapshotSpecialObjectsOop := objectMemory integerValueOf: (objectMemory fetchPointer: 6 ofObject: snapshotValues).. > + snapshotLastHash := objectMemory integerValueOf: (objectMemory fetchPointer: 7 ofObject: snapshotValues).. > + screenSizePoint := objectMemory fetchPointer: 8 ofObject: snapshotValues.. > + self assertClassOf: screenSizePoint is: (objectMemory splObj: ClassPoint). > + self successful > + ifFalse: [ ^self primitiveFailFor: PrimErrBadArgument]. > + imageHeaderFlags := objectMemory integerValueOf: (objectMemory fetchPointer: 9 ofObject: snapshotValues).. > + snapshotExtraVMMemory := objectMemory integerValueOf: (objectMemory fetchPointer: 10 ofObject: snapshotValues).. > + > + swapBytes := bigEndian ~= self isBigEnder. > + snapshotFullScreen := false. "FIXME" > + > + "From sqUnixMain.c > + #define DefaultHeapSize 20 > + megabytes BEYOND actual image size" > + defaultHeapSize := 20 * 1000 * 1000. > + desiredHeapSize := defaultHeapSize + imageBytes. > + > + self > + snapshotResume: newMemoryBytesOrBitmap > + heapSize: desiredHeapSize > + swapBytes: swapBytes > + oldBaseAddr: snapshotStartOfMemory > + specialObjectsOop: snapshotSpecialObjectsOop > + lastHash: snapshotLastHash > + savedWindowSize: screenSizePoint > + fullScreenFlag: snapshotFullScreen > + extraVMMemory: snapshotExtraVMMemory. > + > + self pop: 1 thenPush: newMemoryBytesOrBitmap. > + > + ! > > Item was added: > + ----- Method: ContextInterpreter>>snapshotResume:heapSize:swapBytes:oldBaseAddr:specialObjectsOop:lastHash:savedWindowSize:fullScreenFlag:extraVMMemory: (in category 'snapshot utility primitives') ----- > + snapshotResume: byteArrayOrBitmap heapSize: desiredHeapSize swapBytes: swapBytes oldBaseAddr: oldBaseAddr specialObjectsOop: specialObjects lastHash: hashValue savedWindowSize: windowSize fullScreenFlag: fullScreen extraVMMemory: extraMemory > + "Arrange for the interpreter to resume execution from a snapshot of saved > + memory and interpreter state. The current object memory and interpreter state > + will be discarded, and the interpreter will resume execution at the point of the > + supplied image snapshot. Answer the address of the previous object memory > + or nil if this is the first evaluation." > + > + | dataSize sourceBytes mem | > + <returnTypeC: 'usqInt'> > + <var: #desiredHeapSize type: 'usqInt'> > + <var: #dataSize type: 'size_t '> > + <var: #sourceBytes type: 'char *'> > + <var: #mem type: 'char *'> > + > + "Notes - The parameters windowSize, fullScreen and extraMemory are currently > + not used when resuming the VM in a new image. The display size and fullscreen > + mode are probably best set from the image by calling primitiveSetDisplayMode > + prior to primitiveResumeFromSnapshot. The extraMemory parameter is ignored > + here because we are simply copying the new object memory over a previously > + allocated heap space." > + > + dataSize := objectMemory byteSizeOf: byteArrayOrBitmap. > + sourceBytes := objectMemory firstIndexableField: byteArrayOrBitmap. > + objectMemory setSpecialObjectsOop: specialObjects. > + objectMemory setLastHash: hashValue. > + > + "Copy object memory into allocated space" > + objectMemory setMemoryLimits: dataSize heapSize: desiredHeapSize. > + mem := objectMemory pointerForOop: objectMemory getMemory. > + self mem: mem > + cp: sourceBytes > + y: dataSize. > + > + self swapBytesAndPrepareToInterpret: swapBytes oldBaseAddr: oldBaseAddr. > + self interpret. "Resume interpreter execution in the snapshot." > + ! > > Item was added: > + ----- Method: ObjectMemory>>setMemoryLimits:heapSize: (in category 'image save/restore') ----- > + setMemoryLimits: dataSize heapSize: heapSize > + "Set memory limits, assuming that previously allocated heap space is sufficient. > + Use this instead of allocateMemory: dataSize heapSize: desiredHeapSize when > + resuming the interpreter in a new inage snapshot using previously allocated > + heap memory." > + > + | minimumMemory | > + <var: #heapSize type: 'usqInt'> > + <var: #dataSize type: 'size_t '> > + > + minimumMemory := dataSize + 100000. "need at least 100K of breathing room" > + "compare memory requirements with availability". > + heapSize < minimumMemory ifTrue: [ "try to make more space" > + self growObjectMemory: minimumMemory - heapSize. > + heapSize < minimumMemory ifTrue: [ > + interpreter insufficientMemorySpecifiedError]]. > + self setEndOfMemory: memory + dataSize. > + ! > > Item was changed: > ----- Method: VMMaker class>>versionString (in category 'version testing') ----- > versionString > > "VMMaker versionString" > > + ^'4.17.1'! > - ^'4.16.9'! > |
Free forum by Nabble | Edit this page |