[x86/Linux] Fix generic context(hidden arg) position (#8848)
authorSaeHie Park <saehie.park@gmail.com>
Tue, 10 Jan 2017 23:43:23 +0000 (08:43 +0900)
committerJan Vorlicek <janvorli@microsoft.com>
Tue, 10 Jan 2017 23:43:23 +0000 (00:43 +0100)
This fixes how to handle generic context position in x86 by num of arguments

src/vm/prestub.cpp

index e0d4096..9fd7c52 100644 (file)
@@ -829,15 +829,24 @@ Stub * CreateInstantiatingILStub(MethodDesc* pTargetMD, void* pHiddenArg)
     CreateInstantiatingILStubTargetSig(pTargetMD, typeContext, &stubSigBuilder);
     
     // 2. Emit the method body
+    unsigned int numArgs = msig.NumFixedArgs();
     if (msig.HasThis())
     {
         // 2.1 Push the thisptr
         pCode->EmitLoadThis();
+        numArgs++;
     }
 
-    // 2.2 Push the hidden context param 
-    // InstantiatingStub
-    pCode->EmitLDC((TADDR)pHiddenArg);
+#if defined(_TARGET_X86_)
+    if (numArgs < NUM_ARGUMENT_REGISTERS)
+    {
+#endif // _TARGET_X86_
+        // 2.2 Push the hidden context param
+        // InstantiatingStub
+        pCode->EmitLDC((TADDR)pHiddenArg);
+#if defined(_TARGET_X86_)
+    }
+#endif // _TARGET_X86_
 
     // 2.3 Push the rest of the arguments
     for (unsigned i = 0; i < msig.NumFixedArgs();i++)
@@ -845,10 +854,19 @@ Stub * CreateInstantiatingILStub(MethodDesc* pTargetMD, void* pHiddenArg)
         pCode->EmitLDARG(i);
     }
 
-    // 2.4 Push the target address
+#if defined(_TARGET_X86_)
+    if (numArgs >= NUM_ARGUMENT_REGISTERS)
+    {
+        // 2.4 Push the hidden context param
+        // InstantiatingStub
+        pCode->EmitLDC((TADDR)pHiddenArg);
+    }
+#endif // _TARGET_X86_
+
+    // 2.5 Push the target address
     pCode->EmitLDC((TADDR)pTargetMD->GetMultiCallableAddrOfCode(CORINFO_ACCESS_ANY));
 
-    // 2.5 Do the calli
+    // 2.6 Do the calli
     pCode->EmitCALLI(TOKEN_ILSTUB_TARGET_SIG, msig.NumFixedArgs() + 1, msig.IsReturnTypeVoid() ? 0 : 1);
     pCode->EmitRET();