-/*
- * unwind.c: Stack Unwinding Interface
+/**
+ * \file
+ * Stack Unwinding Interface
*
* Authors:
* Zoltan Varga (vargaz@gmail.com)
#define DWARF_PC_REG (mono_hw_reg_to_dwarf_reg (X86_NREG))
#elif defined (TARGET_POWERPC)
// http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.html
-static int map_hw_reg_to_dwarf_reg [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8,
+static int map_hw_reg_to_dwarf_reg [ppc_lr + 1] = { 0, 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31 };
-#define NUM_DWARF_REGS 110
#define DWARF_DATA_ALIGN (-(gint32)sizeof (mgreg_t))
+#if _CALL_ELF == 2
+#define DWARF_PC_REG 65
+#else
#define DWARF_PC_REG 108
+#endif
+#define NUM_DWARF_REGS (DWARF_PC_REG + 1)
#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_DWARF_REGS 16
#define NUM_HW_REGS (sizeof (map_hw_reg_to_dwarf_reg) / sizeof (int))
#ifndef IS_DOUBLE_REG
-#define IS_DOUBLE_REG(dwarf_reg) 0
+#define IS_DOUBLE_REG(dwarf_reg) (dwarf_reg ? 0 : 0)
#endif
static gboolean dwarf_reg_to_hw_reg_inited;
+static gboolean hw_reg_to_dwarf_reg_inited;
static int map_dwarf_reg_to_hw_reg [NUM_DWARF_REGS];
+static void
+init_hw_reg_map (void)
+{
+#ifdef TARGET_POWERPC
+ map_hw_reg_to_dwarf_reg [ppc_lr] = DWARF_PC_REG;
+#endif
+ mono_memory_barrier ();
+ hw_reg_to_dwarf_reg_inited = TRUE;
+}
+
/*
* mono_hw_reg_to_dwarf_reg:
*
int
mono_hw_reg_to_dwarf_reg (int reg)
{
-#ifdef TARGET_POWERPC
- if (reg == ppc_lr)
- return 108;
- else
- g_assert (reg < NUM_HW_REGS);
-#endif
+ if (!hw_reg_to_dwarf_reg_inited)
+ init_hw_reg_map ();
if (NUM_HW_REGS == 0) {
g_assert_not_reached ();
}
static void
-init_reg_map (void)
+init_dwarf_reg_map (void)
{
int i;
map_dwarf_reg_to_hw_reg [mono_hw_reg_to_dwarf_reg (i)] = i;
}
-#ifdef TARGET_POWERPC
- map_dwarf_reg_to_hw_reg [DWARF_PC_REG] = ppc_lr;
-#endif
-
mono_memory_barrier ();
dwarf_reg_to_hw_reg_inited = TRUE;
}
mono_dwarf_reg_to_hw_reg (int reg)
{
if (!dwarf_reg_to_hw_reg_inited)
- init_reg_map ();
+ init_dwarf_reg_map ();
return map_dwarf_reg_to_hw_reg [reg];
}
/* Emit an advance_loc if neccesary */
while (op->when > loc) {
- if (op->when - loc > 65536) {
+ if (op->when - loc >= 65536) {
*p ++ = DW_CFA_advance_loc4;
guint32 v = (guint32)(op->when - loc);
memcpy (p, &v, 4);
g_assert (read32 (p) == (guint32)(op->when - loc));
p += 4;
loc = op->when;
- } else if (op->when - loc > 256) {
+ } else if (op->when - loc >= 256) {
*p ++ = DW_CFA_advance_loc2;
guint16 v = (guint16)(op->when - loc);
memcpy (p, &v, 2);
g_assert (op->val == 0);
*p ++ = op->op;
break;
+#if defined(TARGET_WIN32) && defined(TARGET_AMD64)
+ case DW_CFA_mono_sp_alloc_info_win64:
+ case DW_CFA_mono_fp_alloc_info_win64:
+ // Drop Windows specific unwind op's. These op's are currently
+ // only used when registering unwind info with Windows OS unwinder.
+ break;
+#endif
default:
g_assert_not_reached ();
break;
* decode_lsda:
*
* Decode the Mono specific Language Specific Data Area generated by LLVM.
+ * This function is async safe.
*/
static void
-decode_lsda (guint8 *lsda, guint8 *code, MonoJitExceptionInfo **ex_info, guint32 *ex_info_len, gpointer **type_info, int *this_reg, int *this_offset)
+decode_lsda (guint8 *lsda, guint8 *code, MonoJitExceptionInfo *ex_info, gpointer *type_info, guint32 *ex_info_len, int *this_reg, int *this_offset)
{
guint8 *p;
int i, ncall_sites, this_encoding;
ncall_sites = decode_uleb128 (p, &p);
p = (guint8*)ALIGN_TO ((mgreg_t)p, 4);
- if (ex_info) {
- *ex_info = (MonoJitExceptionInfo *)g_malloc0 (ncall_sites * sizeof (MonoJitExceptionInfo));
+ if (ex_info_len)
*ex_info_len = ncall_sites;
- }
- if (type_info)
- *type_info = (gpointer *)g_malloc0 (ncall_sites * sizeof (gpointer));
for (i = 0; i < ncall_sites; ++i) {
int block_start_offset, block_size, landing_pad;
//printf ("X: %p %d\n", landing_pad, *(int*)tinfo);
if (ex_info) {
- if (*type_info)
- (*type_info) [i] = tinfo;
- (*ex_info)[i].try_start = code + block_start_offset;
- (*ex_info)[i].try_end = code + block_start_offset + block_size;
- (*ex_info)[i].handler_start = code + landing_pad;
+ if (type_info)
+ type_info [i] = tinfo;
+ ex_info[i].try_start = code + block_start_offset;
+ ex_info[i].try_end = code + block_start_offset + block_size;
+ ex_info[i].handler_start = code + landing_pad;
}
}
}
if (lsda_offset != 0) {
lsda = fde_aug + lsda_offset;
- decode_lsda (lsda, code, ex_info, ex_info_len, type_info, this_reg, this_offset);
+ /* Get the lengths first */
+ guint32 len;
+ decode_lsda (lsda, code, NULL, NULL, &len, this_reg, this_offset);
+
+ if (ex_info)
+ *ex_info = (MonoJitExceptionInfo *)g_malloc0 (len * sizeof (MonoJitExceptionInfo));
+ if (type_info)
+ *type_info = (gpointer *)g_malloc0 (len * sizeof (gpointer));
+
+ decode_lsda (lsda, code, ex_info ? *ex_info : NULL, type_info ? *type_info : NULL, ex_info_len, this_reg, this_offset);
}
}
* mono_unwind_decode_mono_fde:
*
* Decode an FDE entry in the LLVM emitted mono EH frame.
- * info->ex_info is set to a malloc-ed array of MonoJitExceptionInfo structures,
- * only try_start, try_end and handler_start is set.
- * info->type_info is set to a malloc-ed array containing the ttype table from the
- * LSDA.
+ * If EI/TYPE_INFO/UNW_INFO are NULL, compute only the value of the scalar fields in INFO.
+ * Otherwise:
+ * - Fill out EX_INFO with try_start, try_end and handler_start.
+ * - Fill out TYPE_INFO with the ttype table from the LSDA.
+ * - Fill out UNW_INFO with the unwind info.
+ * This function is async safe.
*/
void
-mono_unwind_decode_llvm_mono_fde (guint8 *fde, int fde_len, guint8 *cie, guint8 *code, MonoLLVMFDEInfo *res)
+mono_unwind_decode_llvm_mono_fde (guint8 *fde, int fde_len, guint8 *cie, guint8 *code, MonoLLVMFDEInfo *res, MonoJitExceptionInfo *ex_info, gpointer *type_info, guint8 *unw_info)
{
guint8 *p, *fde_aug, *cie_cfi, *fde_cfi, *buf;
int has_aug, aug_len, cie_cfi_len, fde_cfi_len;
/* 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);
+ /* Get the lengths first */
+ decode_lsda (lsda, code, NULL, NULL, &res->ex_info_len, &res->this_reg, &res->this_offset);
+
+ decode_lsda (lsda, code, ex_info, type_info, NULL, &res->this_reg, &res->this_offset);
}
/* Decode CIE */
cie_cfi_len = p - cie_cfi;
fde_cfi_len = (fde + fde_len - fde_cfi);
- buf = (guint8 *)g_malloc0 (cie_cfi_len + fde_cfi_len);
- memcpy (buf, cie_cfi, cie_cfi_len);
- memcpy (buf + cie_cfi_len, fde_cfi, fde_cfi_len);
+ buf = unw_info;
+ if (buf) {
+ memcpy (buf, cie_cfi, cie_cfi_len);
+ memcpy (buf + cie_cfi_len, fde_cfi, fde_cfi_len);
+ }
res->unw_info_len = cie_cfi_len + fde_cfi_len;
- res->unw_info = buf;
}
/*