<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Jaromir,<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jan 22, 2022 at 3:57 AM Jaromir Matas <<a href="mailto:mail@jaromir.net">mail@jaromir.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"> 





<div lang="EN-US" style="word-wrap:break-word">
<div class="gmail-m_8064685681750289554WordSection1">
<p class="MsoNormal">Hi Eliot,</p>
<p class="MsoNormal">I’d like to test it but the build failed for Windows and Mac; not sure what it means…</p>
<p class="MsoNormal">Sorry to hear the current “incorrect” suspend behavior has been exploited more than expected in the existing code. </p></div></div></blockquote><div><br></div><div class="gmail_default" style="font-size:small">It's not the incorrect suspend behaviour that's being exploited, it's the return value of suspend.  Existing code appears to depend on the semaphore/mutex a process is blocked on being answered by suspend.</div><div class="gmail_default" style="font-size:small"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div lang="EN-US" style="word-wrap:break-word"><div class="gmail-m_8064685681750289554WordSection1"><p class="MsoNormal">What would you think about having primitiveSuspendV2 return self instead of any list at all – to make all state changing
 methods answer consistently (like e.g. VW do)… if the answer expected by the “affected” code base has to be provided by primitiveSuspend anyways.</p></div></div></blockquote><div><br></div><div class="gmail_default" style="font-size:small">I don't see this is at all useful.  If one isn't interested in the semaphore/mutex return value one does not have to examine it.  But there is no way of getting the list once the process has been removed from it other than by having the suspend primitive answer it.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">So if one isn't interested in the return value simply write something of the form</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">    aProcess suspend; yourself</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">But if one *is* interested in the result then the primitive better answer it, nbo?</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div lang="EN-US" style="word-wrap:break-word"><div class="gmail-m_8064685681750289554WordSection1"><p class="MsoNormal"><u></u><u></u></p>
<p class="MsoNormal">Best,<u></u><u></u></p>
<p class="MsoNormal">Jaromir</p>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border-style:solid none none;border-top-width:1pt;border-top-color:rgb(225,225,225);padding:3pt 0in 0in">
<p class="MsoNormal" style="border:none;padding:0in"><b>From: </b><a href="mailto:commits@source.squeak.org" target="_blank">commits@source.squeak.org</a><br>
<b>Sent: </b>Saturday, January 22, 2022 2:11<br>
<b>To: </b><a href="mailto:vm-dev@lists.squeakfoundation.org" target="_blank">vm-dev@lists.squeakfoundation.org</a><br>
<b>Subject: </b>[Vm-dev] VM Maker: VMMaker.oscog-eem.3142.mcz</p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal" style="margin-bottom:12pt"><br>
Eliot Miranda uploaded a new version of VMMaker to project VM Maker:<br>
<a href="http://source.squeak.org/VMMaker/VMMaker.oscog-eem.3142.mcz" target="_blank">http://source.squeak.org/VMMaker/VMMaker.oscog-eem.3142.mcz</a><br>
<br>
==================== Summary ====================<br>
<br>
Name: VMMaker.oscog-eem.3142<br>
Author: eem<br>
Time: 21 January 2022, 5:10:43.282744 pm<br>
UUID: ecaa84c0-26c9-440b-bc13-59a6e56c5e7c<br>
Ancestors: VMMaker.oscog-eem.3141<br>
<br>
Change the revised primitiveSuspend to behave clkoser to the original, always answeriong the list the receiver was on if bnlocked.  make the newer variant available as a named prim itive (primitiveSuspendV2).  AFAICT using primitiveSuspendV2 breaks lots of
 things (SqueakSSL tests hang, Virtend login hangs).  So while the idea is right, in practice answering nil if the receiver is suspended while waiting on a condition variable breaks more things than it fixes.<br>
<br>
=============== Diff against VMMaker.oscog-eem.3141 ===============<br>
<br>
Item was changed:<br>
  ----- Method: CoInterpreterPrimitives>>primitiveSuspend (in category 'process primitives') -----<br>
  primitiveSuspend<br>
         "Primitive. Suspend the receiver, aProcess, such that it can be executed again<br>
          by sending #resume. If the given process is not the active process, take it off<br>
          its corresponding list. If the list was not its run queue assume it was on some<br>
          condition variable (Semaphore, Mutex) and back up its pc to the send that<br>
          invoked the wait state the process entered.  Hence when the process resumes<br>
+         it will reenter the wait state. Answer the list the receiver was previously on,<br>
+         unless it was the activ eProcess, in which case answer nil."<br>
-         it will reenter the wait state. Answer the list the receiver was previously on iff<br>
-         it was not active and not blocked, otherwise answer nil."<br>
         | process myList myContext ok |<br>
         process := self stackTop.<br>
         process = self activeProcess ifTrue:<br>
                 [| inInterpreter |<br>
                 "We're going to switch process, either to an interpreted frame or a machine<br>
                  code frame. To know whether to return or enter machine code we have to<br>
                  know from whence we came.  We could have come from the interpreter,<br>
                  either directly or via a machine code primitive.  We could have come from<br>
                  machine code.  The instructionPointer tells us where from:"<br>
                 self pop: 1 thenPush: objectMemory nilObject.<br>
                 inInterpreter := instructionPointer >= objectMemory startOfMemory.<br>
                 self transferTo: self wakeHighestPriority from: CSSuspend.<br>
                 ^self forProcessPrimitiveReturnToExecutivePostContextSwitch: inInterpreter].<br>
         myList := objectMemory fetchPointer: MyListIndex ofObject: process.<br>
         myContext := objectMemory fetchPointer: SuspendedContextIndex ofObject: process.<br>
         ((objectMemory isPointers: myList)<br>
          and: [(objectMemory numSlotsOf: myList) > LastLinkIndex<br>
          and: [(objectMemory isContext: myContext)<br>
          and: [self isResumableContext: myContext]]]) ifFalse:<br>
                 [^self primitiveFailFor: PrimErrBadReceiver].<br>
         ok := self removeProcess: process fromList: myList.<br>
         ok ifFalse:<br>
                 [^self primitiveFailFor: PrimErrOperationFailed].<br>
         objectMemory storePointerUnchecked: MyListIndex ofObject: process withValue: objectMemory nilObject.<br>
         self assert: RevisedSuspend.<br>
         (RevisedSuspend<br>
+         and: [(objectMemory fetchClassTagOfNonImm: myList) ~= classLinkedListClassTag]) ifTrue:<br>
+                [self backupContext: myContext toBlockingSendTo: myList].<br>
+        self pop: 1 thenPush: myList!<br>
-         and: [(objectMemory fetchClassTagOfNonImm: myList) ~= classLinkedListClassTag])<br>
-                ifTrue:<br>
-                        [self backupContext: myContext toBlockingSendTo: myList.<br>
-                         self pop: 1 thenPush: objectMemory nilObject]<br>
-                ifFalse:<br>
-                        [self pop: 1 thenPush: myList]!<br>
<br>
Item was added:<br>
+ ----- Method: CoInterpreterPrimitives>>primitiveSuspendV2 (in category 'process primitives') -----<br>
+ primitiveSuspendV2<br>
+        "Primitive. Suspend the receiver, aProcess, such that it can be executed again<br>
+         by sending #resume. If the given process is not the active process, take it off<br>
+         its corresponding list. If the list was not its run queue assume it was on some<br>
+         condition variable (Semaphore, Mutex) and back up its pc to the send that<br>
+         invoked the wait state the process entered.  Hence when the process resumes<br>
+         it will reenter the wait state. Answer the list the receiver was previously on iff<br>
+         it was not active and not blocked, otherwise answer nil.<br>
+         c.f. primitiveSuspend, which always answers the list the process was on, if blocked."<br>
+        <export: true><br>
+        | process myList myContext ok |<br>
+        process := self stackTop.<br>
+        process = self activeProcess ifTrue:<br>
+                [| inInterpreter |<br>
+                "We're going to switch process, either to an interpreted frame or a machine<br>
+                 code frame. To know whether to return or enter machine code we have to<br>
+                 know from whence we came.  We could have come from the interpreter,<br>
+                 either directly or via a machine code primitive.  We could have come from<br>
+                 machine code.  The instructionPointer tells us where from:"<br>
+                self pop: 1 thenPush: objectMemory nilObject.<br>
+                inInterpreter := instructionPointer >= objectMemory startOfMemory.<br>
+                self transferTo: self wakeHighestPriority from: CSSuspend.<br>
+                ^self forProcessPrimitiveReturnToExecutivePostContextSwitch: inInterpreter].<br>
+        myList := objectMemory fetchPointer: MyListIndex ofObject: process.<br>
+        myContext := objectMemory fetchPointer: SuspendedContextIndex ofObject: process.<br>
+        ((objectMemory isPointers: myList)<br>
+         and: [(objectMemory numSlotsOf: myList) > LastLinkIndex<br>
+         and: [(objectMemory isContext: myContext)<br>
+         and: [self isResumableContext: myContext]]]) ifFalse:<br>
+                [^self primitiveFailFor: PrimErrBadReceiver].<br>
+        ok := self removeProcess: process fromList: myList.<br>
+        ok ifFalse:<br>
+                [^self primitiveFailFor: PrimErrOperationFailed].<br>
+        objectMemory storePointerUnchecked: MyListIndex ofObject: process withValue: objectMemory nilObject.<br>
+        self assert: RevisedSuspend.<br>
+        (RevisedSuspend<br>
+         and: [(objectMemory fetchClassTagOfNonImm: myList) ~= classLinkedListClassTag])<br>
+                ifTrue:<br>
+                        [self backupContext: myContext toBlockingSendTo: myList.<br>
+                         self pop: 1 thenPush: objectMemory nilObject]<br>
+                ifFalse:<br>
+                        [self pop: 1 thenPush: myList]!<br>
<br>
Item was changed:<br>
  ----- Method: CogVMSimulator class>>initialize (in category 'class initialization') -----<br>
  initialize<br>
         "These are primitives that alter the state of the stack.  They are here simply for assert checking.<br>
          After invocation the Cogit should not check for the expected stack delta when these primitives<br>
          succeed, because the stack will usually have been modified."<br>
         StackAlteringPrimitives := #(   primitiveClosureValue primitiveClosureValueWithArgs primitiveClosureValueNoContextSwitch<br>
                                                                         primitiveClone primitiveInstVarAt primitiveSlotAt "because these can cause code compactions..."<br>
                                                                         primitiveEnterCriticalSection primitiveExitCriticalSection<br>
                                                                         primitiveFullClosureValue primitiveFullClosureValueWithArgs primitiveFullClosureValueNoContextSwitch<br>
+                                                                        primitiveSignal primitiveWait primitiveResume primitiveSuspend primitiveSuspendV2 primitiveYield<br>
-                                                                        primitiveSignal primitiveWait primitiveResume primitiveSuspend primitiveYield<br>
                                                                         primitiveExecuteMethodArgsArray primitiveExecuteMethod<br>
                                                                         primitivePerform primitivePerformWithArgs primitivePerformInSuperclass<br>
                                                                         primitiveTerminateTo primitiveStoreStackp primitiveDoPrimitiveWithArgs) asIdentitySet!<br>
<br>
Item was changed:<br>
  ----- Method: StackInterpreterPrimitives>>primitiveSuspend (in category 'process primitives') -----<br>
  primitiveSuspend<br>
         "Primitive. Suspend the receiver, aProcess, such that it can be executed again<br>
          by sending #resume. If the given process is not the active process, take it off<br>
          its corresponding list. If the list was not its run queue assume it was on some<br>
          condition variable (Semaphore, Mutex) and back up its pc to the send that<br>
          invoked the wait state the process entered.  Hence when the process resumes<br>
+         it will reenter the wait state. Answer the list the receiver was previously on,<br>
+         unless it was the activ eProcess, in which case answer nil."<br>
-         it will reenter the wait state. Answer the list the receiver was previously on iff<br>
-         it was not active and not blocked, otherwise answer nil."<br>
         | process myList myContext ok |<br>
         process := self stackTop.<br>
         process = self activeProcess ifTrue:<br>
                 [self pop: 1 thenPush: objectMemory nilObject.<br>
                  ^self transferTo: self wakeHighestPriority].<br>
         myList := objectMemory fetchPointer: MyListIndex ofObject: process.<br>
         myContext := objectMemory fetchPointer: SuspendedContextIndex ofObject: process.<br>
         ((objectMemory isPointers: myList)<br>
          and: [(objectMemory numSlotsOf: myList) > LastLinkIndex<br>
          and: [(objectMemory isContext: myContext)<br>
          and: [self isResumableContext: myContext]]]) ifFalse:<br>
                 [^self primitiveFailFor: PrimErrBadReceiver].<br>
         ok := self removeProcess: process fromList: myList.<br>
         ok ifFalse:<br>
                 [^self primitiveFailFor: PrimErrOperationFailed].<br>
         objectMemory storePointerUnchecked: MyListIndex ofObject: process withValue: objectMemory nilObject.<br>
         self assert: RevisedSuspend.<br>
         (RevisedSuspend<br>
+         and: [(objectMemory fetchClassTagOfNonImm: myList) ~= classLinkedListClassTag]) ifTrue:<br>
+                [self backupContext: myContext toBlockingSendTo: myList].<br>
+        self pop: 1 thenPush: myList!<br>
-         and: [(objectMemory fetchClassTagOfNonImm: myList) ~= classLinkedListClassTag])<br>
-                ifTrue:<br>
-                        [self backupContext: myContext toBlockingSendTo: myList.<br>
-                         self pop: 1 thenPush: objectMemory nilObject]<br>
-                ifFalse:<br>
-                        [self pop: 1 thenPush: myList]!<br>
<br>
Item was added:<br>
+ ----- Method: StackInterpreterPrimitives>>primitiveSuspendV2 (in category 'process primitives') -----<br>
+ primitiveSuspendV2<br>
+        "Primitive. Suspend the receiver, aProcess, such that it can be executed again<br>
+         by sending #resume. If the given process is not the active process, take it off<br>
+         its corresponding list. If the list was not its run queue assume it was on some<br>
+         condition variable (Semaphore, Mutex) and back up its pc to the send that<br>
+         invoked the wait state the process entered.  Hence when the process resumes<br>
+         it will reenter the wait state. Answer the list the receiver was previously on iff<br>
+         it was not active and not blocked, otherwise answer nil.<br>
+         c.f. primitiveSuspend, which always answers the list the process was on, if blocked."<br>
+        <export: true><br>
+        | process myList myContext ok |<br>
+        process := self stackTop.<br>
+        process = self activeProcess ifTrue:<br>
+                [self pop: 1 thenPush: objectMemory nilObject.<br>
+                 ^self transferTo: self wakeHighestPriority].<br>
+        myList := objectMemory fetchPointer: MyListIndex ofObject: process.<br>
+        myContext := objectMemory fetchPointer: SuspendedContextIndex ofObject: process.<br>
+        ((objectMemory isPointers: myList)<br>
+         and: [(objectMemory numSlotsOf: myList) > LastLinkIndex<br>
+         and: [(objectMemory isContext: myContext)<br>
+         and: [self isResumableContext: myContext]]]) ifFalse:<br>
+                [^self primitiveFailFor: PrimErrBadReceiver].<br>
+        ok := self removeProcess: process fromList: myList.<br>
+        ok ifFalse:<br>
+                [^self primitiveFailFor: PrimErrOperationFailed].<br>
+        objectMemory storePointerUnchecked: MyListIndex ofObject: process withValue: objectMemory nilObject.<br>
+        self assert: RevisedSuspend.<br>
+        (RevisedSuspend<br>
+         and: [(objectMemory fetchClassTagOfNonImm: myList) ~= classLinkedListClassTag])<br>
+                ifTrue:<br>
+                        [self backupContext: myContext toBlockingSendTo: myList.<br>
+                         self pop: 1 thenPush: objectMemory nilObject]<br>
+                ifFalse:<br>
+                        [self pop: 1 thenPush: myList]!<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>

</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div></div>