From d2498bb635db8616071aea4391aa480399fcaafc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marius=20D=C3=B6rbandt?= Date: Mon, 20 Nov 2023 15:17:58 +0100 Subject: [PATCH] Fix stack pointer before running C code --- .../nodes/primitives/PrimitiveNodeFactory.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/PrimitiveNodeFactory.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/PrimitiveNodeFactory.java index 92fdb2cf1..64c342133 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/PrimitiveNodeFactory.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/PrimitiveNodeFactory.java @@ -7,6 +7,7 @@ package de.hpi.swa.trufflesqueak.nodes.primitives; import com.oracle.truffle.api.dsl.NodeFactory; +import com.oracle.truffle.api.frame.Frame; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.interop.InteropLibrary; import de.hpi.swa.trufflesqueak.exceptions.PrimitiveFailed; @@ -52,6 +53,7 @@ import de.hpi.swa.trufflesqueak.nodes.primitives.impl.IOPrimitives; import de.hpi.swa.trufflesqueak.nodes.primitives.impl.MiscellaneousPrimitives; import de.hpi.swa.trufflesqueak.nodes.primitives.impl.StoragePrimitives; +import de.hpi.swa.trufflesqueak.util.FrameAccess; import de.hpi.swa.trufflesqueak.util.NFIUtils; import de.hpi.swa.trufflesqueak.util.OS; import org.graalvm.collections.EconomicMap; @@ -236,6 +238,10 @@ public Object execute(VirtualFrame frame) { final InteropLibrary uuidPluginLibrary = NFIUtils.getInteropLibrary(uuidPlugin); InterpreterProxy interpreterProxy = null; try { + // A send (AbstractSendNode.executeVoid) will decrement the stack pointer by the number of arguments + // before transferring control. We need the stack pointer to point at the last argument, + // since the C code expects that. Therefore, we undo the decrement operation here. + FrameAccess.setStackPointer(frame, FrameAccess.getStackPointer(frame) + numReceiverAndArguments - 1); interpreterProxy = InterpreterProxy.instanceFor(getContext(), frame, numReceiverAndArguments); //uuidPluginLibrary.invokeMember(uuidPlugin, "initialiseModule");