Merge pull request #4110 from BrzVlad/fix-sgen-win32
[mono.git] / mono / mini / tramp-s390x.c
index e70f5c55c08a1142f9c4bef9ec9e30dacc25e675..408997daace8d426c6ba6ffaf4a81c9b8eea032c 100644 (file)
@@ -13,7 +13,7 @@
 /*              Dietmar Maurer (dietmar@ximian.com)                */
 /*                                                                 */
 /* Copyright   - 2001 Ximian, Inc.                                 */
-/*                                                                 */
+/* Licensed under the MIT license. See LICENSE file in the project root for full license information.*/
 /*------------------------------------------------------------------*/
 
 /*------------------------------------------------------------------*/
@@ -39,7 +39,7 @@
 
 #include <mono/metadata/abi-details.h>
 #include <mono/metadata/appdomain.h>
-#include <mono/metadata/gc-internal.h>
+#include <mono/metadata/gc-internals.h>
 #include <mono/metadata/marshal.h>
 #include <mono/metadata/profiler-private.h>
 #include <mono/metadata/tabledefs.h>
@@ -48,6 +48,7 @@
 #include "mini.h"
 #include "mini-s390x.h"
 #include "support-s390x.h"
+#include "jit-icalls.h"
 
 /*========================= End of Includes ========================*/
 
@@ -57,6 +58,7 @@
 
 typedef struct {
        guint8  stk[S390_MINIMAL_STACK_SIZE];   /* Standard s390x stack */
+       guint64 saveFn;                         /* Call address         */
        struct MonoLMF  LMF;                    /* LMF                  */
 } trampStack_t;
 
@@ -96,6 +98,7 @@ mono_arch_get_unbox_trampoline (MonoMethod *method, gpointer addr)
        guint8 *code, *start;
        int this_pos = s390_r2;
        MonoDomain *domain = mono_domain_get ();
+       char trampName[128];
 
        start = code = mono_domain_code_reserve (domain, 28);
 
@@ -108,7 +111,9 @@ mono_arch_get_unbox_trampoline (MonoMethod *method, gpointer addr)
        mono_arch_flush_icache (start, code - start);
        mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_UNBOX_TRAMPOLINE, method);
 
-       mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, NULL), domain);
+       snprintf(trampName, sizeof(trampName), "%s_unbox_trampoline", method->name);
+
+       mono_tramp_info_register (mono_tramp_info_create (trampName, start, code - start, NULL, NULL), domain);
 
        return start;
 }
@@ -305,15 +310,22 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf
        S390_SET  (buf, s390_r1, tramp);
        s390_basr (buf, s390_r14, s390_r1);
                
-       /* OK, code address is now on r2. Move it to r1, so that we
-          can restore r2 and use it from r1 later */
-       s390_lgr  (buf, s390_r1, s390_r2);
+       /* OK, code address is now on r2. Save it, so that we
+          can restore r2 and use it later */
+       s390_stg  (buf, s390_r2, 0, STK_BASE, G_STRUCT_OFFSET(trampStack_t, saveFn));
+
+       /* Check for thread interruption */
+       S390_SET  (buf, s390_r1, (guint8 *)mono_interruption_checkpoint_from_trampoline);
+       s390_basr (buf, s390_r14, s390_r1);
 
        /*----------------------------------------------------------
          STEP 3: Restore the LMF
          ----------------------------------------------------------*/
        restoreLMF(buf, STK_BASE, sizeof(trampStack_t));
        
+       /* Reload result */
+       s390_lg   (buf, s390_r1, 0, STK_BASE, G_STRUCT_OFFSET(trampStack_t, saveFn));
+
        /*----------------------------------------------------------
          STEP 4: call the compiled method
          ----------------------------------------------------------*/
@@ -555,6 +567,7 @@ mono_arch_get_static_rgctx_trampoline (MonoMethod *m,
        guint8 *code, *start;
        gint32 displace;
        int buf_len;
+       char trampName[128];
 
        MonoDomain *domain = mono_domain_get ();
 
@@ -570,7 +583,9 @@ mono_arch_get_static_rgctx_trampoline (MonoMethod *m,
        mono_arch_flush_icache (start, code - start);
        mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_HELPER, NULL);
 
-       mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, NULL), domain);
+       snprintf(trampName, sizeof(trampName), "%s_rgctx_trampoline", m->name);
+
+       mono_tramp_info_register (mono_tramp_info_create (trampName, start, code - start, NULL, NULL), domain);
 
        return(start);
 }