Implement mono_arch_context_set_int_reg () for arm.
[mono.git] / mono / mini / unwind.c
index 2f1302065a8a0edddf60fa060d83f752318c7808..07233221381f56ea1dc2005a12e05cecef2faba3 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <mono/utils/mono-counters.h>
 #include <mono/utils/freebsd-dwarf.h>
+#include <mono/utils/hazard-pointer.h>
 #include <mono/metadata/threads-types.h>
 #include <mono/metadata/mono-endian.h>
 
@@ -66,6 +67,11 @@ static int map_hw_reg_to_dwarf_reg [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8,
 #define NUM_REGS 110
 #define DWARF_DATA_ALIGN (-(gint32)sizeof (mgreg_t))
 #define DWARF_PC_REG 108
+#elif defined (TARGET_S390X)
+static int map_hw_reg_to_dwarf_reg [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
+#define NUM_REGS 16
+#define DWARF_DATA_ALIGN (-8)
+#define DWARF_PC_REG (mono_hw_reg_to_dwarf_reg (14))
 #else
 static int map_hw_reg_to_dwarf_reg [16];
 #define NUM_REGS 16
@@ -319,12 +325,16 @@ print_dwarf_state (int cfa_reg, int cfa_offset, int ip, int nregs, Loc *location
  * Given the state of the current frame as stored in REGS, execute the unwind 
  * operations in unwind_info until the location counter reaches POS. The result is 
  * stored back into REGS. OUT_CFA will receive the value of the CFA.
+ * If SAVE_LOCATIONS is non-NULL, it should point to an array of size SAVE_LOCATIONS_LEN.
+ * On return, the nth entry will point to the address of the stack slot where register
+ * N was saved, or NULL, if it was not saved by this frame.
  * This function is signal safe.
  */
 void
 mono_unwind_frame (guint8 *unwind_info, guint32 unwind_info_len, 
-                                  guint8 *start_ip, guint8 *end_ip, guint8 *ip, mgreg_t *regs, 
-                                  int nregs, guint8 **out_cfa)
+                                  guint8 *start_ip, guint8 *end_ip, guint8 *ip, mgreg_t *regs, int nregs,
+                                  mgreg_t **save_locations, int save_locations_len,
+                                  guint8 **out_cfa)
 {
        Loc locations [NUM_REGS];
        int i, pos, reg, cfa_reg, cfa_offset;
@@ -386,12 +396,17 @@ mono_unwind_frame (guint8 *unwind_info, guint32 unwind_info_len,
                }
        }
 
+       if (save_locations)
+               memset (save_locations, 0, save_locations_len * sizeof (mgreg_t*));
+
        cfa_val = (guint8*)regs [mono_dwarf_reg_to_hw_reg (cfa_reg)] + cfa_offset;
        for (i = 0; i < NUM_REGS; ++i) {
                if (locations [i].loc_type == LOC_OFFSET) {
                        int hreg = mono_dwarf_reg_to_hw_reg (i);
                        g_assert (hreg < nregs);
                        regs [hreg] = *(mgreg_t*)(cfa_val + locations [i].offset);
+                       if (save_locations && hreg < save_locations_len)
+                               save_locations [hreg] = (mgreg_t*)(cfa_val + locations [i].offset);
                }
        }
 
@@ -495,32 +510,6 @@ mono_cache_unwind_info (guint8 *unwind_info, guint32 unwind_info_len)
        return i;
 }
 
-static gpointer
-get_hazardous_pointer (gpointer volatile *pp, MonoThreadHazardPointers *hp, int hazard_index)
-{
-       gpointer p;
-
-       for (;;) {
-               /* Get the pointer */
-               p = *pp;
-               /* If we don't have hazard pointers just return the
-                  pointer. */
-               if (!hp)
-                       return p;
-               /* Make it hazardous */
-               mono_hazard_pointer_set (hp, hazard_index, p);
-               /* Check that it's still the same.  If not, try
-                  again. */
-               if (*pp != p) {
-                       mono_hazard_pointer_clear (hp, hazard_index);
-                       continue;
-               }
-               break;
-       }
-
-       return p;
-}
-
 /*
  * This function is signal safe.
  */
@@ -774,6 +763,10 @@ decode_lsda (guint8 *lsda, guint8 *code, MonoJitExceptionInfo **ex_info, guint32
                                guint8 *ttype_entry = (ttype - (type_offset * 4));
                                gint32 offset = *(gint32*)ttype_entry;
                                tinfo = ttype_entry + offset;
+                       } else if (ttype_encoding == DW_EH_PE_udata4) {
+                               /* Embedded directly */
+                               guint8 *ttype_entry = (ttype - (type_offset * 4));
+                               tinfo = ttype_entry;
                        } else {
                                g_assert_not_reached ();
                        }
@@ -976,7 +969,7 @@ void
 mono_unwind_decode_llvm_mono_fde (guint8 *fde, int fde_len, guint8 *cie, guint8 *code, MonoLLVMFDEInfo *res)
 {
        guint8 *p, *fde_aug, *cie_cfi, *fde_cfi, *buf;
-       int aug_len, cie_cfi_len, fde_cfi_len;
+       int has_aug, aug_len, cie_cfi_len, fde_cfi_len;
        gint32 code_align, data_align, return_reg, pers_encoding;
 
        memset (res, 0, sizeof (*res));
@@ -985,30 +978,25 @@ mono_unwind_decode_llvm_mono_fde (guint8 *fde, int fde_len, guint8 *cie, guint8
 
        /* fde points to data emitted by LLVM in DwarfException::EmitMonoEHFrame () */
        p = fde;
-       aug_len = *p;
+       has_aug = *p;
        p ++;
+       if (has_aug) {
+               aug_len = read32 (p);
+               p += 4;
+       } else {
+               aug_len = 0;
+       }
        fde_aug = p;
        p += aug_len;
        fde_cfi = p;
 
-       if (aug_len) {
-               gint32 lsda_offset;
+       if (has_aug) {
                guint8 *lsda;
 
-               /* LSDA pointer */
-
-               /* sdata|pcrel encoding */
-               if (aug_len == 4)
-                       lsda_offset = read32 (fde_aug);
-               else if (aug_len == 8)
-                       lsda_offset = *(gint64*)fde_aug;
-               else
-                       g_assert_not_reached ();
-               if (lsda_offset != 0) {
-                       lsda = fde_aug + lsda_offset;
+               /* The LSDA is embedded directly into the FDE */
+               lsda = fde_aug;
 
-                       decode_lsda (lsda, code, &res->ex_info, &res->ex_info_len, &res->type_info, &res->this_reg, &res->this_offset);
-               }
+               decode_lsda (lsda, code, &res->ex_info, &res->ex_info_len, &res->type_info, &res->this_reg, &res->this_offset);
        }
 
        /* Decode CIE */