2 * unwind.c: Stack Unwinding Interface
5 * Zoltan Varga (vargaz@gmail.com)
7 * (C) 2008 Novell, Inc.
11 #include "mini-unwind.h"
13 #include <mono/utils/mono-counters.h>
14 #include <mono/utils/freebsd-dwarf.h>
15 #include <mono/utils/hazard-pointer.h>
16 #include <mono/metadata/threads-types.h>
17 #include <mono/metadata/mono-endian.h>
31 guint8 info [MONO_ZERO_LEN_ARRAY];
34 static CRITICAL_SECTION unwind_mutex;
36 static MonoUnwindInfo **cached_info;
37 static int cached_info_next, cached_info_size;
38 static GSList *cached_info_list;
40 static int unwind_info_size;
42 #define unwind_lock() EnterCriticalSection (&unwind_mutex)
43 #define unwind_unlock() LeaveCriticalSection (&unwind_mutex)
46 static int map_hw_reg_to_dwarf_reg [] = { 0, 2, 1, 3, 7, 6, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
47 #define NUM_REGS AMD64_NREG
48 #define DWARF_DATA_ALIGN (-8)
49 #define DWARF_PC_REG (mono_hw_reg_to_dwarf_reg (AMD64_RIP))
50 #elif defined(TARGET_ARM)
51 // http://infocenter.arm.com/help/topic/com.arm.doc.ihi0040a/IHI0040A_aadwarf.pdf
52 static int map_hw_reg_to_dwarf_reg [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
54 #define DWARF_DATA_ALIGN (-4)
55 #define DWARF_PC_REG (mono_hw_reg_to_dwarf_reg (ARMREG_LR))
56 #elif defined (TARGET_X86)
57 static int map_hw_reg_to_dwarf_reg [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
59 #define NUM_REGS X86_NREG + 1
60 #define DWARF_DATA_ALIGN (-4)
61 #define DWARF_PC_REG (mono_hw_reg_to_dwarf_reg (X86_NREG))
62 #elif defined (TARGET_POWERPC)
63 // http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.html
64 static int map_hw_reg_to_dwarf_reg [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8,
65 9, 10, 11, 12, 13, 14, 15, 16,
66 17, 18, 19, 20, 21, 22, 23, 24,
67 25, 26, 27, 28, 29, 30, 31 };
69 #define DWARF_DATA_ALIGN (-(gint32)sizeof (mgreg_t))
70 #define DWARF_PC_REG 108
71 #elif defined (TARGET_S390X)
72 static int map_hw_reg_to_dwarf_reg [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
74 #define DWARF_DATA_ALIGN (-8)
75 #define DWARF_PC_REG (mono_hw_reg_to_dwarf_reg (14))
76 #elif defined (TARGET_MIPS)
78 static int map_hw_reg_to_dwarf_reg [32] = {
79 0, 1, 2, 3, 4, 5, 6, 7,
80 8, 9, 10, 11, 12, 13, 14, 15,
81 16, 17, 18, 19, 20, 21, 22, 23,
82 24, 25, 26, 27, 28, 29, 30, 31
85 #define DWARF_DATA_ALIGN (-(gint32)sizeof (mgreg_t))
86 #define DWARF_PC_REG (mono_hw_reg_to_dwarf_reg (mips_ra))
88 static int map_hw_reg_to_dwarf_reg [16];
90 #define DWARF_DATA_ALIGN 0
91 #define DWARF_PC_REG -1
94 static gboolean dwarf_reg_to_hw_reg_inited;
96 static int map_dwarf_reg_to_hw_reg [NUM_REGS];
99 * mono_hw_reg_to_dwarf_reg:
101 * Map the hardware register number REG to the register number used by DWARF.
104 mono_hw_reg_to_dwarf_reg (int reg)
106 #ifdef TARGET_POWERPC
110 g_assert (reg < NUM_REGS);
114 g_assert_not_reached ();
117 return map_hw_reg_to_dwarf_reg [reg];
126 g_assert (NUM_REGS > 0);
127 for (i = 0; i < sizeof (map_hw_reg_to_dwarf_reg) / sizeof (int); ++i) {
128 map_dwarf_reg_to_hw_reg [mono_hw_reg_to_dwarf_reg (i)] = i;
131 #ifdef TARGET_POWERPC
132 map_dwarf_reg_to_hw_reg [DWARF_PC_REG] = ppc_lr;
135 mono_memory_barrier ();
136 dwarf_reg_to_hw_reg_inited = TRUE;
140 mono_dwarf_reg_to_hw_reg (int reg)
142 if (!dwarf_reg_to_hw_reg_inited)
145 return map_dwarf_reg_to_hw_reg [reg];
148 static G_GNUC_UNUSED void
149 encode_uleb128 (guint32 value, guint8 *buf, guint8 **endbuf)
154 guint8 b = value & 0x7f;
156 if (value != 0) /* more bytes to come */
164 static G_GNUC_UNUSED void
165 encode_sleb128 (gint32 value, guint8 *buf, guint8 **endbuf)
168 gboolean negative = (value < 0);
176 /* the following is unnecessary if the
177 * implementation of >>= uses an arithmetic rather
178 * than logical shift for a signed left operand
182 value |= - (1 <<(size - 7));
183 /* sign bit of byte is second high order bit (0x40) */
184 if ((value == 0 && !(byte & 0x40)) ||
185 (value == -1 && (byte & 0x40)))
195 static inline guint32
196 decode_uleb128 (guint8 *buf, guint8 **endbuf)
206 res = res | (((int)(b & 0x7f)) << shift);
218 decode_sleb128 (guint8 *buf, guint8 **endbuf)
228 res = res | (((int)(b & 0x7f)) << shift);
231 if (shift < 32 && (b & 0x40))
232 res |= - (1 << shift);
243 * mono_unwind_ops_encode:
245 * Encode the unwind ops in UNWIND_OPS into the compact DWARF encoding.
246 * Return a pointer to malloc'ed memory.
249 mono_unwind_ops_encode (GSList *unwind_ops, guint32 *out_len)
254 guint8 *buf, *p, *res;
256 p = buf = g_malloc0 (4096);
260 for (; l; l = l->next) {
265 /* Convert the register from the hw encoding to the dwarf encoding */
266 reg = mono_hw_reg_to_dwarf_reg (op->reg);
268 /* Emit an advance_loc if neccesary */
269 while (op->when > loc) {
270 if (op->when - loc < 32) {
271 *p ++ = DW_CFA_advance_loc | (op->when - loc);
274 *p ++ = DW_CFA_advance_loc | (30);
282 encode_uleb128 (reg, p, &p);
283 encode_uleb128 (op->val, p, &p);
285 case DW_CFA_def_cfa_offset:
287 encode_uleb128 (op->val, p, &p);
289 case DW_CFA_def_cfa_register:
291 encode_uleb128 (reg, p, &p);
295 *p ++ = DW_CFA_offset_extended_sf;
296 encode_uleb128 (reg, p, &p);
297 encode_sleb128 (op->val / DWARF_DATA_ALIGN, p, &p);
299 *p ++ = DW_CFA_offset | reg;
300 encode_uleb128 (op->val / DWARF_DATA_ALIGN, p, &p);
304 g_assert_not_reached ();
309 g_assert (p - buf < 4096);
311 res = g_malloc (p - buf);
312 memcpy (res, buf, p - buf);
318 #define UNW_DEBUG(stmt) do { stmt; } while (0)
320 #define UNW_DEBUG(stmt) do { } while (0)
323 static G_GNUC_UNUSED void
324 print_dwarf_state (int cfa_reg, int cfa_offset, int ip, int nregs, Loc *locations)
328 printf ("\t%x: cfa=r%d+%d ", ip, cfa_reg, cfa_offset);
330 for (i = 0; i < nregs; ++i)
331 if (locations [i].loc_type == LOC_OFFSET)
332 printf ("r%d@%d(cfa) ", i, locations [i].offset);
337 * Given the state of the current frame as stored in REGS, execute the unwind
338 * operations in unwind_info until the location counter reaches POS. The result is
339 * stored back into REGS. OUT_CFA will receive the value of the CFA.
340 * If SAVE_LOCATIONS is non-NULL, it should point to an array of size SAVE_LOCATIONS_LEN.
341 * On return, the nth entry will point to the address of the stack slot where register
342 * N was saved, or NULL, if it was not saved by this frame.
343 * This function is signal safe.
346 mono_unwind_frame (guint8 *unwind_info, guint32 unwind_info_len,
347 guint8 *start_ip, guint8 *end_ip, guint8 *ip, mgreg_t *regs, int nregs,
348 mgreg_t **save_locations, int save_locations_len,
351 Loc locations [NUM_REGS];
352 int i, pos, reg, cfa_reg, cfa_offset;
356 for (i = 0; i < NUM_REGS; ++i)
357 locations [i].loc_type = LOC_SAME;
363 while (pos <= ip - start_ip && p < unwind_info + unwind_info_len) {
367 case DW_CFA_advance_loc:
368 UNW_DEBUG (print_dwarf_state (cfa_reg, cfa_offset, pos, nregs, locations));
375 locations [reg].loc_type = LOC_OFFSET;
376 locations [reg].offset = decode_uleb128 (p, &p) * DWARF_DATA_ALIGN;
383 cfa_reg = decode_uleb128 (p, &p);
384 cfa_offset = decode_uleb128 (p, &p);
386 case DW_CFA_def_cfa_offset:
387 cfa_offset = decode_uleb128 (p, &p);
389 case DW_CFA_def_cfa_register:
390 cfa_reg = decode_uleb128 (p, &p);
392 case DW_CFA_offset_extended_sf:
393 reg = decode_uleb128 (p, &p);
394 locations [reg].loc_type = LOC_OFFSET;
395 locations [reg].offset = decode_sleb128 (p, &p) * DWARF_DATA_ALIGN;
397 case DW_CFA_advance_loc4:
402 g_assert_not_reached ();
407 g_assert_not_reached ();
412 memset (save_locations, 0, save_locations_len * sizeof (mgreg_t*));
414 cfa_val = (guint8*)regs [mono_dwarf_reg_to_hw_reg (cfa_reg)] + cfa_offset;
415 for (i = 0; i < NUM_REGS; ++i) {
416 if (locations [i].loc_type == LOC_OFFSET) {
417 int hreg = mono_dwarf_reg_to_hw_reg (i);
418 g_assert (hreg < nregs);
419 regs [hreg] = *(mgreg_t*)(cfa_val + locations [i].offset);
420 if (save_locations && hreg < save_locations_len)
421 save_locations [hreg] = (mgreg_t*)(cfa_val + locations [i].offset);
429 mono_unwind_init (void)
431 InitializeCriticalSection (&unwind_mutex);
433 mono_counters_register ("Unwind info size", MONO_COUNTER_JIT | MONO_COUNTER_INT, &unwind_info_size);
437 mono_unwind_cleanup (void)
441 DeleteCriticalSection (&unwind_mutex);
446 for (i = 0; i < cached_info_next; ++i) {
447 MonoUnwindInfo *cached = cached_info [i];
452 g_free (cached_info);
456 * mono_cache_unwind_info
458 * Save UNWIND_INFO in the unwind info cache and return an id which can be passed
459 * to mono_get_cached_unwind_info to get a cached copy of the info.
460 * A copy is made of the unwind info.
461 * This function is useful for two reasons:
462 * - many methods have the same unwind info
463 * - MonoJitInfo->used_regs is an int so it can't store the pointer to the unwind info
466 mono_cache_unwind_info (guint8 *unwind_info, guint32 unwind_info_len)
469 MonoUnwindInfo *info;
473 if (cached_info == NULL) {
474 cached_info_size = 16;
475 cached_info = g_new0 (MonoUnwindInfo*, cached_info_size);
478 for (i = 0; i < cached_info_next; ++i) {
479 MonoUnwindInfo *cached = cached_info [i];
481 if (cached->len == unwind_info_len && memcmp (cached->info, unwind_info, unwind_info_len) == 0) {
487 info = g_malloc (sizeof (MonoUnwindInfo) + unwind_info_len);
488 info->len = unwind_info_len;
489 memcpy (&info->info, unwind_info, unwind_info_len);
491 i = cached_info_next;
493 if (cached_info_next >= cached_info_size) {
494 MonoUnwindInfo **old_table, **new_table;
497 * Avoid freeing the old table so mono_get_cached_unwind_info ()
498 * doesn't need locks/hazard pointers.
501 old_table = cached_info;
502 new_table = g_new0 (MonoUnwindInfo*, cached_info_size * 2);
504 memcpy (new_table, cached_info, cached_info_size * sizeof (MonoUnwindInfo*));
506 mono_memory_barrier ();
508 cached_info = new_table;
510 cached_info_list = g_slist_prepend (cached_info_list, cached_info);
512 cached_info_size *= 2;
515 cached_info [cached_info_next ++] = info;
517 unwind_info_size += sizeof (MonoUnwindInfo) + unwind_info_len;
524 * This function is signal safe.
527 mono_get_cached_unwind_info (guint32 index, guint32 *unwind_info_len)
529 MonoUnwindInfo **table;
530 MonoUnwindInfo *info;
534 * This doesn't need any locks/hazard pointers,
535 * since new tables are copies of the old ones.
539 info = table [index];
541 *unwind_info_len = info->len;
548 * mono_unwind_get_dwarf_data_align:
550 * Return the data alignment used by the encoded unwind information.
553 mono_unwind_get_dwarf_data_align (void)
555 return DWARF_DATA_ALIGN;
559 * mono_unwind_get_dwarf_pc_reg:
561 * Return the dwarf register number of the register holding the ip of the
565 mono_unwind_get_dwarf_pc_reg (void)
571 decode_cie_op (guint8 *p, guint8 **endp)
576 case DW_CFA_advance_loc:
581 decode_uleb128 (p, &p);
588 decode_uleb128 (p, &p);
589 decode_uleb128 (p, &p);
591 case DW_CFA_def_cfa_offset:
592 decode_uleb128 (p, &p);
594 case DW_CFA_def_cfa_register:
595 decode_uleb128 (p, &p);
597 case DW_CFA_advance_loc4:
600 case DW_CFA_offset_extended_sf:
601 decode_uleb128 (p, &p);
602 decode_uleb128 (p, &p);
605 g_assert_not_reached ();
610 g_assert_not_reached ();
617 read_encoded_val (guint32 encoding, guint8 *p, guint8 **endp)
621 switch (encoding & 0xf) {
622 case DW_EH_PE_sdata8:
626 case DW_EH_PE_sdata4:
631 g_assert_not_reached ();
641 * Decode the Language Specific Data Area generated by LLVM.
644 decode_lsda (guint8 *lsda, guint8 *code, MonoJitExceptionInfo **ex_info, guint32 *ex_info_len, gpointer **type_info, int *this_reg, int *this_offset)
646 gint32 ttype_offset, call_site_length;
647 gint32 ttype_encoding, call_site_encoding;
648 guint8 *ttype, *action_table, *call_site, *p;
652 * LLVM generates a c++ style LSDA, which can be decoded by looking at
653 * eh_personality.cc in gcc.
657 if (*p == DW_EH_PE_udata4) {
658 /* This is the modified LSDA generated by the LLVM mono branch */
659 guint32 mono_magic, version;
660 gint32 op, reg, offset;
663 mono_magic = decode_uleb128 (p, &p);
664 g_assert (mono_magic == 0x4d4fef4f);
665 version = decode_uleb128 (p, &p);
666 g_assert (version == 1);
668 /* 'this' location */
670 g_assert (op == DW_OP_bregx);
672 reg = decode_uleb128 (p, &p);
673 offset = decode_sleb128 (p, &p);
675 *this_reg = mono_dwarf_reg_to_hw_reg (reg);
676 *this_offset = offset;
679 g_assert (*p == DW_EH_PE_omit);
689 ttype_offset = decode_uleb128 (p, &p);
690 ttype = p + ttype_offset;
692 /* Read call-site table */
693 call_site_encoding = *p;
694 g_assert (call_site_encoding == DW_EH_PE_udata4);
696 call_site_length = decode_uleb128 (p, &p);
698 p += call_site_length;
701 /* Calculate the size of our table */
704 while (p < action_table) {
705 int block_start_offset, block_size, landing_pad, action_offset;
707 block_start_offset = read32 (p);
708 p += sizeof (gint32);
709 block_size = read32 (p);
710 p += sizeof (gint32);
711 landing_pad = read32 (p);
712 p += sizeof (gint32);
713 action_offset = decode_uleb128 (p, &p);
715 /* landing_pad == 0 means the region has no landing pad */
721 *ex_info = g_malloc0 (ncall_sites * sizeof (MonoJitExceptionInfo));
722 *ex_info_len = ncall_sites;
726 *type_info = g_malloc0 (ncall_sites * sizeof (gpointer));
730 while (p < action_table) {
731 int block_start_offset, block_size, landing_pad, action_offset, type_offset;
732 guint8 *action, *tinfo;
734 block_start_offset = read32 (p);
735 p += sizeof (gint32);
736 block_size = read32 (p);
737 p += sizeof (gint32);
738 landing_pad = read32 (p);
739 p += sizeof (gint32);
740 action_offset = decode_uleb128 (p, &p);
745 action = action_table + action_offset - 1;
747 type_offset = decode_sleb128 (action, &action);
750 //printf ("BLOCK: %p-%p %p, %d\n", code + block_start_offset, code + block_start_offset + block_size, code + landing_pad, action_offset);
752 g_assert (ttype_offset);
754 if (ttype_encoding == DW_EH_PE_absptr) {
755 guint8 *ttype_entry = (ttype - (type_offset * sizeof (gpointer)));
756 tinfo = *(gpointer*)ttype_entry;
757 } else if (ttype_encoding == (DW_EH_PE_indirect | DW_EH_PE_pcrel | DW_EH_PE_sdata4)) {
758 guint8 *ttype_entry = (ttype - (type_offset * 4));
759 gint32 offset = *(gint32*)ttype_entry;
760 guint8 *stub = ttype_entry + offset;
761 tinfo = *(gpointer*)stub;
762 } else if (ttype_encoding == (DW_EH_PE_pcrel | DW_EH_PE_sdata4)) {
763 guint8 *ttype_entry = (ttype - (type_offset * 4));
764 gint32 offset = *(gint32*)ttype_entry;
765 tinfo = ttype_entry + offset;
766 } else if (ttype_encoding == DW_EH_PE_udata4) {
767 /* Embedded directly */
768 guint8 *ttype_entry = (ttype - (type_offset * 4));
771 g_assert_not_reached ();
776 (*type_info) [i] = tinfo;
777 (*ex_info)[i].try_start = code + block_start_offset;
778 (*ex_info)[i].try_end = code + block_start_offset + block_size;
779 (*ex_info)[i].handler_start = code + landing_pad;
788 * mono_unwind_decode_fde:
790 * Decode a DWARF FDE entry, returning the unwind opcodes.
791 * If not NULL, EX_INFO is set to a malloc-ed array of MonoJitExceptionInfo structures,
792 * only try_start, try_end and handler_start is set.
793 * If not NULL, TYPE_INFO is set to a malloc-ed array containing the ttype table from the
797 mono_unwind_decode_fde (guint8 *fde, guint32 *out_len, guint32 *code_len, MonoJitExceptionInfo **ex_info, guint32 *ex_info_len, gpointer **type_info, int *this_reg, int *this_offset)
799 guint8 *p, *cie, *fde_current, *fde_aug = NULL, *code, *fde_cfi, *cie_cfi;
800 gint32 fde_len, cie_offset, pc_begin, pc_range, aug_len, fde_data_len;
801 gint32 cie_len, cie_id, cie_version, code_align, data_align, return_reg;
802 gint32 i, cie_aug_len, buf_len;
805 gboolean has_fde_augmentation = FALSE;
808 * http://refspecs.freestandards.org/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html
818 // FIXME: Endianess ?
819 fde_len = *(guint32*)p;
820 g_assert (fde_len != 0xffffffff && fde_len != 0);
822 cie_offset = *(guint32*)p;
823 cie = p - cie_offset;
829 cie_len = *(guint32*)p;
831 cie_id = *(guint32*)p;
832 g_assert (cie_id == 0);
835 g_assert (cie_version == 1);
837 cie_aug_str = (char*)p;
838 p += strlen (cie_aug_str) + 1;
839 code_align = decode_uleb128 (p, &p);
840 data_align = decode_sleb128 (p, &p);
841 return_reg = decode_uleb128 (p, &p);
842 if (strstr (cie_aug_str, "z")) {
846 cie_aug_len = decode_uleb128 (p, &p);
848 has_fde_augmentation = TRUE;
851 for (i = 0; cie_aug_str [i] != '\0'; ++i) {
852 switch (cie_aug_str [i]) {
858 read_encoded_val (p_encoding, p, &p);
861 g_assert ((*p == (DW_EH_PE_sdata4|DW_EH_PE_pcrel)) || (*p == (DW_EH_PE_sdata8|DW_EH_PE_pcrel)));
865 g_assert (*p == (DW_EH_PE_sdata4|DW_EH_PE_pcrel));
869 g_assert_not_reached ();
879 /* Continue decoding FDE */
881 /* DW_EH_PE_sdata4|DW_EH_PE_pcrel encoding */
882 pc_begin = *(gint32*)p;
885 pc_range = *(guint32*)p;
887 if (has_fde_augmentation) {
888 aug_len = decode_uleb128 (p, &p);
895 fde_data_len = fde + 4 + fde_len - p;
898 *code_len = pc_range;
905 /* Decode FDE augmention */
910 /* sdata|pcrel encoding */
912 lsda_offset = read32 (fde_aug);
913 else if (aug_len == 8)
914 lsda_offset = *(gint64*)fde_aug;
916 g_assert_not_reached ();
917 if (lsda_offset != 0) {
918 lsda = fde_aug + lsda_offset;
920 decode_lsda (lsda, code, ex_info, ex_info_len, type_info, this_reg, this_offset);
924 /* Make sure the FDE uses the same constants as we do */
925 g_assert (code_align == 1);
926 g_assert (data_align == DWARF_DATA_ALIGN);
927 g_assert (return_reg == DWARF_PC_REG);
929 buf_len = (cie + cie_len + 4 - cie_cfi) + (fde + fde_len + 4 - fde_cfi);
930 buf = g_malloc0 (buf_len);
934 while (p < cie + cie_len + 4) {
935 if (*p == DW_CFA_nop)
938 decode_cie_op (p, &p);
940 memcpy (buf + i, cie_cfi, p - cie_cfi);
944 while (p < fde + fde_len + 4) {
945 if (*p == DW_CFA_nop)
948 decode_cie_op (p, &p);
950 memcpy (buf + i, fde_cfi, p - fde_cfi);
952 g_assert (i <= buf_len);
956 return g_realloc (buf, i);
960 * mono_unwind_decode_mono_fde:
962 * Decode an FDE entry in the LLVM emitted mono EH frame.
963 * info->ex_info is set to a malloc-ed array of MonoJitExceptionInfo structures,
964 * only try_start, try_end and handler_start is set.
965 * info->type_info is set to a malloc-ed array containing the ttype table from the
969 mono_unwind_decode_llvm_mono_fde (guint8 *fde, int fde_len, guint8 *cie, guint8 *code, MonoLLVMFDEInfo *res)
971 guint8 *p, *fde_aug, *cie_cfi, *fde_cfi, *buf;
972 int has_aug, aug_len, cie_cfi_len, fde_cfi_len;
973 gint32 code_align, data_align, return_reg, pers_encoding;
975 memset (res, 0, sizeof (*res));
977 res->this_offset = -1;
979 /* fde points to data emitted by LLVM in DwarfException::EmitMonoEHFrame () */
984 aug_len = read32 (p);
996 /* The LSDA is embedded directly into the FDE */
999 decode_lsda (lsda, code, &res->ex_info, &res->ex_info_len, &res->type_info, &res->this_reg, &res->this_offset);
1004 code_align = decode_uleb128 (p, &p);
1005 data_align = decode_sleb128 (p, &p);
1006 return_reg = decode_uleb128 (p, &p);
1009 if (pers_encoding != DW_EH_PE_omit)
1010 read_encoded_val (pers_encoding, p, &p);
1014 /* Make sure the FDE uses the same constants as we do */
1015 g_assert (code_align == 1);
1016 g_assert (data_align == DWARF_DATA_ALIGN);
1017 g_assert (return_reg == DWARF_PC_REG);
1019 /* Compute size of CIE unwind info it is DW_CFA_nop terminated */
1022 if (*p == DW_CFA_nop)
1025 decode_cie_op (p, &p);
1027 cie_cfi_len = p - cie_cfi;
1028 fde_cfi_len = (fde + fde_len - fde_cfi);
1030 buf = g_malloc0 (cie_cfi_len + fde_cfi_len);
1031 memcpy (buf, cie_cfi, cie_cfi_len);
1032 memcpy (buf + cie_cfi_len, fde_cfi, fde_cfi_len);
1034 res->unw_info_len = cie_cfi_len + fde_cfi_len;
1035 res->unw_info = buf;
1039 * mono_unwind_get_cie_program:
1041 * Get the unwind bytecode for the DWARF CIE.
1044 mono_unwind_get_cie_program (void)
1046 #if defined(TARGET_AMD64) || defined(TARGET_X86) || defined(TARGET_POWERPC)
1047 return mono_arch_get_cie_program ();