Skip to content

Commit

Permalink
Restore validation. Fix offset validation directly in the backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
guillep committed Jul 18, 2023
1 parent 7a6becf commit 4d9460d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
5 changes: 2 additions & 3 deletions smalltalksrc/VMMaker/CogAbstractInstruction.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1228,9 +1228,8 @@ CogAbstractInstruction >> isPCDependent [

{ #category : #testing }
CogAbstractInstruction >> isWithinMwOffsetRange: anAddress [
"Answer if an address can be accessed using the offset in a MoveMw:r:R: or similar instruction.
We assume this is true for 32-bit processors and expect 64-bit processors to answer false
for values in the interpreter or the object memory."
"Answer if an immediate value can be used as offset in a MoveMw:r:R: or similar instruction.
By default, the backend will handle it"

^true
]
Expand Down
13 changes: 5 additions & 8 deletions smalltalksrc/VMMaker/CogX64Compiler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4345,14 +4345,11 @@ CogX64Compiler >> isQuick: operand [
]

{ #category : #testing }
CogX64Compiler >> isWithinMwOffsetRange: anAddress [
"Answer if an address can be accessed using the offset in a MoveMw:r:R: or similar instruction.
We assume this is true for 32-bit processors and expect 64-bit processors to answer false
for values in the interpreter or the object memory. Restrict our use of offsets to reference
addresses within the method zone, rather than checking for a 32-bit offset, si as to keep the
simulator and real VM in sync."

^cogit addressIsInCodeZone: anAddress
CogX64Compiler >> isWithinMwOffsetRange: anImmediate [
"Answer if an immediate value can be used as offset in a MoveMw:r:R: or similar instruction.
The X64 backend only encodes 32bit signed immediates for now"

^ self is32BitSignedImmediate: anImmediate
]

{ #category : #accessing }
Expand Down
11 changes: 9 additions & 2 deletions smalltalksrc/VMMaker/Integer.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,15 @@ Integer >> asSmallIntegerObj [

{ #category : #'*VMMaker-interpreter simulator' }
Integer >> asUnsignedInteger [

^ self
"Since the simulator deals with positive integers most of the time we assert that the receiver is greater than zero.
But one major exception is stack pointers in the StackInterpreterSimulator, which are negative. So don't fail
if the sender is a StackInterpreter and the receiver could be a stack pointer."
self >= 0 ifFalse:
[self assert: (((thisContext sender methodClass includesBehavior: CoInterpreter)
and: [self between: Cogit maxNegativeErrorCode and: -1])
or: [(thisContext sender methodClass includesBehavior: StackInterpreter)
and: [thisContext sender receiver stackPages couldBeFramePointer: self]])].
^self
]

{ #category : #'*VMMaker-interpreter simulator' }
Expand Down

0 comments on commit 4d9460d

Please sign in to comment.