sh: unwinder: Fix up usage of unaligned accessors.
[linux-2.6/kvm.git] / arch / sh / kernel / dwarf.c
blobd1d8536e5ba3377b5126c1ad0aa71ace6e2f8a6b
1 /*
2 * Copyright (C) 2009 Matt Fleming <matt@console-pimps.org>
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
8 * This is an implementation of a DWARF unwinder. Its main purpose is
9 * for generating stacktrace information. Based on the DWARF 3
10 * specification from http://www.dwarfstd.org.
12 * TODO:
13 * - DWARF64 doesn't work.
16 /* #define DEBUG */
17 #include <linux/kernel.h>
18 #include <linux/io.h>
19 #include <linux/list.h>
20 #include <linux/mm.h>
21 #include <asm/dwarf.h>
22 #include <asm/unwinder.h>
23 #include <asm/sections.h>
24 #include <asm/unaligned.h>
25 #include <asm/dwarf.h>
26 #include <asm/stacktrace.h>
28 static LIST_HEAD(dwarf_cie_list);
29 DEFINE_SPINLOCK(dwarf_cie_lock);
31 static LIST_HEAD(dwarf_fde_list);
32 DEFINE_SPINLOCK(dwarf_fde_lock);
34 static struct dwarf_cie *cached_cie;
37 * Figure out whether we need to allocate some dwarf registers. If dwarf
38 * registers have already been allocated then we may need to realloc
39 * them. "reg" is a register number that we need to be able to access
40 * after this call.
42 * Register numbers start at zero, therefore we need to allocate space
43 * for "reg" + 1 registers.
45 static void dwarf_frame_alloc_regs(struct dwarf_frame *frame,
46 unsigned int reg)
48 struct dwarf_reg *regs;
49 unsigned int num_regs = reg + 1;
50 size_t new_size;
51 size_t old_size;
53 new_size = num_regs * sizeof(*regs);
54 old_size = frame->num_regs * sizeof(*regs);
56 /* Fast path: don't allocate any regs if we've already got enough. */
57 if (frame->num_regs >= num_regs)
58 return;
60 regs = kzalloc(new_size, GFP_KERNEL);
61 if (!regs) {
62 printk(KERN_WARNING "Unable to allocate DWARF registers\n");
64 * Let's just bomb hard here, we have no way to
65 * gracefully recover.
67 BUG();
70 if (frame->regs) {
71 memcpy(regs, frame->regs, old_size);
72 kfree(frame->regs);
75 frame->regs = regs;
76 frame->num_regs = num_regs;
79 /**
80 * dwarf_read_addr - read dwarf data
81 * @src: source address of data
82 * @dst: destination address to store the data to
84 * Read 'n' bytes from @src, where 'n' is the size of an address on
85 * the native machine. We return the number of bytes read, which
86 * should always be 'n'. We also have to be careful when reading
87 * from @src and writing to @dst, because they can be arbitrarily
88 * aligned. Return 'n' - the number of bytes read.
90 static inline int dwarf_read_addr(unsigned long *src, unsigned long *dst)
92 *dst = get_unaligned(src);
93 return sizeof(unsigned long *);
96 /**
97 * dwarf_read_uleb128 - read unsigned LEB128 data
98 * @addr: the address where the ULEB128 data is stored
99 * @ret: address to store the result
101 * Decode an unsigned LEB128 encoded datum. The algorithm is taken
102 * from Appendix C of the DWARF 3 spec. For information on the
103 * encodings refer to section "7.6 - Variable Length Data". Return
104 * the number of bytes read.
106 static inline unsigned long dwarf_read_uleb128(char *addr, unsigned int *ret)
108 unsigned int result;
109 unsigned char byte;
110 int shift, count;
112 result = 0;
113 shift = 0;
114 count = 0;
116 while (1) {
117 byte = __raw_readb(addr);
118 addr++;
119 count++;
121 result |= (byte & 0x7f) << shift;
122 shift += 7;
124 if (!(byte & 0x80))
125 break;
128 *ret = result;
130 return count;
134 * dwarf_read_leb128 - read signed LEB128 data
135 * @addr: the address of the LEB128 encoded data
136 * @ret: address to store the result
138 * Decode signed LEB128 data. The algorithm is taken from Appendix
139 * C of the DWARF 3 spec. Return the number of bytes read.
141 static inline unsigned long dwarf_read_leb128(char *addr, int *ret)
143 unsigned char byte;
144 int result, shift;
145 int num_bits;
146 int count;
148 result = 0;
149 shift = 0;
150 count = 0;
152 while (1) {
153 byte = __raw_readb(addr);
154 addr++;
155 result |= (byte & 0x7f) << shift;
156 shift += 7;
157 count++;
159 if (!(byte & 0x80))
160 break;
163 /* The number of bits in a signed integer. */
164 num_bits = 8 * sizeof(result);
166 if ((shift < num_bits) && (byte & 0x40))
167 result |= (-1 << shift);
169 *ret = result;
171 return count;
175 * dwarf_read_encoded_value - return the decoded value at @addr
176 * @addr: the address of the encoded value
177 * @val: where to write the decoded value
178 * @encoding: the encoding with which we can decode @addr
180 * GCC emits encoded address in the .eh_frame FDE entries. Decode
181 * the value at @addr using @encoding. The decoded value is written
182 * to @val and the number of bytes read is returned.
184 static int dwarf_read_encoded_value(char *addr, unsigned long *val,
185 char encoding)
187 unsigned long decoded_addr = 0;
188 int count = 0;
190 switch (encoding & 0x70) {
191 case DW_EH_PE_absptr:
192 break;
193 case DW_EH_PE_pcrel:
194 decoded_addr = (unsigned long)addr;
195 break;
196 default:
197 pr_debug("encoding=0x%x\n", (encoding & 0x70));
198 BUG();
201 if ((encoding & 0x07) == 0x00)
202 encoding |= DW_EH_PE_udata4;
204 switch (encoding & 0x0f) {
205 case DW_EH_PE_sdata4:
206 case DW_EH_PE_udata4:
207 count += 4;
208 decoded_addr += get_unaligned((u32 *)addr);
209 __raw_writel(decoded_addr, val);
210 break;
211 default:
212 pr_debug("encoding=0x%x\n", encoding);
213 BUG();
216 return count;
220 * dwarf_entry_len - return the length of an FDE or CIE
221 * @addr: the address of the entry
222 * @len: the length of the entry
224 * Read the initial_length field of the entry and store the size of
225 * the entry in @len. We return the number of bytes read. Return a
226 * count of 0 on error.
228 static inline int dwarf_entry_len(char *addr, unsigned long *len)
230 u32 initial_len;
231 int count;
233 initial_len = get_unaligned((u32 *)addr);
234 count = 4;
237 * An initial length field value in the range DW_LEN_EXT_LO -
238 * DW_LEN_EXT_HI indicates an extension, and should not be
239 * interpreted as a length. The only extension that we currently
240 * understand is the use of DWARF64 addresses.
242 if (initial_len >= DW_EXT_LO && initial_len <= DW_EXT_HI) {
244 * The 64-bit length field immediately follows the
245 * compulsory 32-bit length field.
247 if (initial_len == DW_EXT_DWARF64) {
248 *len = get_unaligned((u64 *)addr + 4);
249 count = 12;
250 } else {
251 printk(KERN_WARNING "Unknown DWARF extension\n");
252 count = 0;
254 } else
255 *len = initial_len;
257 return count;
261 * dwarf_lookup_cie - locate the cie
262 * @cie_ptr: pointer to help with lookup
264 static struct dwarf_cie *dwarf_lookup_cie(unsigned long cie_ptr)
266 struct dwarf_cie *cie, *n;
267 unsigned long flags;
269 spin_lock_irqsave(&dwarf_cie_lock, flags);
272 * We've cached the last CIE we looked up because chances are
273 * that the FDE wants this CIE.
275 if (cached_cie && cached_cie->cie_pointer == cie_ptr) {
276 cie = cached_cie;
277 goto out;
280 list_for_each_entry_safe(cie, n, &dwarf_cie_list, link) {
281 if (cie->cie_pointer == cie_ptr) {
282 cached_cie = cie;
283 break;
287 /* Couldn't find the entry in the list. */
288 if (&cie->link == &dwarf_cie_list)
289 cie = NULL;
290 out:
291 spin_unlock_irqrestore(&dwarf_cie_lock, flags);
292 return cie;
296 * dwarf_lookup_fde - locate the FDE that covers pc
297 * @pc: the program counter
299 struct dwarf_fde *dwarf_lookup_fde(unsigned long pc)
301 unsigned long flags;
302 struct dwarf_fde *fde, *n;
304 spin_lock_irqsave(&dwarf_fde_lock, flags);
305 list_for_each_entry_safe(fde, n, &dwarf_fde_list, link) {
306 unsigned long start, end;
308 start = fde->initial_location;
309 end = fde->initial_location + fde->address_range;
311 if (pc >= start && pc < end)
312 break;
315 /* Couldn't find the entry in the list. */
316 if (&fde->link == &dwarf_fde_list)
317 fde = NULL;
319 spin_unlock_irqrestore(&dwarf_fde_lock, flags);
321 return fde;
325 * dwarf_cfa_execute_insns - execute instructions to calculate a CFA
326 * @insn_start: address of the first instruction
327 * @insn_end: address of the last instruction
328 * @cie: the CIE for this function
329 * @fde: the FDE for this function
330 * @frame: the instructions calculate the CFA for this frame
331 * @pc: the program counter of the address we're interested in
333 * Execute the Call Frame instruction sequence starting at
334 * @insn_start and ending at @insn_end. The instructions describe
335 * how to calculate the Canonical Frame Address of a stackframe.
336 * Store the results in @frame.
338 static int dwarf_cfa_execute_insns(unsigned char *insn_start,
339 unsigned char *insn_end,
340 struct dwarf_cie *cie,
341 struct dwarf_fde *fde,
342 struct dwarf_frame *frame,
343 unsigned long pc)
345 unsigned char insn;
346 unsigned char *current_insn;
347 unsigned int count, delta, reg, expr_len, offset;
349 current_insn = insn_start;
351 while (current_insn < insn_end && frame->pc <= pc) {
352 insn = __raw_readb(current_insn++);
355 * Firstly, handle the opcodes that embed their operands
356 * in the instructions.
358 switch (DW_CFA_opcode(insn)) {
359 case DW_CFA_advance_loc:
360 delta = DW_CFA_operand(insn);
361 delta *= cie->code_alignment_factor;
362 frame->pc += delta;
363 continue;
364 /* NOTREACHED */
365 case DW_CFA_offset:
366 reg = DW_CFA_operand(insn);
367 count = dwarf_read_uleb128(current_insn, &offset);
368 current_insn += count;
369 offset *= cie->data_alignment_factor;
370 dwarf_frame_alloc_regs(frame, reg);
371 frame->regs[reg].addr = offset;
372 frame->regs[reg].flags |= DWARF_REG_OFFSET;
373 continue;
374 /* NOTREACHED */
375 case DW_CFA_restore:
376 reg = DW_CFA_operand(insn);
377 continue;
378 /* NOTREACHED */
382 * Secondly, handle the opcodes that don't embed their
383 * operands in the instruction.
385 switch (insn) {
386 case DW_CFA_nop:
387 continue;
388 case DW_CFA_advance_loc1:
389 delta = *current_insn++;
390 frame->pc += delta * cie->code_alignment_factor;
391 break;
392 case DW_CFA_advance_loc2:
393 delta = get_unaligned((u16 *)current_insn);
394 current_insn += 2;
395 frame->pc += delta * cie->code_alignment_factor;
396 break;
397 case DW_CFA_advance_loc4:
398 delta = get_unaligned((u32 *)current_insn);
399 current_insn += 4;
400 frame->pc += delta * cie->code_alignment_factor;
401 break;
402 case DW_CFA_offset_extended:
403 count = dwarf_read_uleb128(current_insn, &reg);
404 current_insn += count;
405 count = dwarf_read_uleb128(current_insn, &offset);
406 current_insn += count;
407 offset *= cie->data_alignment_factor;
408 break;
409 case DW_CFA_restore_extended:
410 count = dwarf_read_uleb128(current_insn, &reg);
411 current_insn += count;
412 break;
413 case DW_CFA_undefined:
414 count = dwarf_read_uleb128(current_insn, &reg);
415 current_insn += count;
416 break;
417 case DW_CFA_def_cfa:
418 count = dwarf_read_uleb128(current_insn,
419 &frame->cfa_register);
420 current_insn += count;
421 count = dwarf_read_uleb128(current_insn,
422 &frame->cfa_offset);
423 current_insn += count;
425 frame->flags |= DWARF_FRAME_CFA_REG_OFFSET;
426 break;
427 case DW_CFA_def_cfa_register:
428 count = dwarf_read_uleb128(current_insn,
429 &frame->cfa_register);
430 current_insn += count;
431 frame->flags |= DWARF_FRAME_CFA_REG_OFFSET;
432 break;
433 case DW_CFA_def_cfa_offset:
434 count = dwarf_read_uleb128(current_insn, &offset);
435 current_insn += count;
436 frame->cfa_offset = offset;
437 break;
438 case DW_CFA_def_cfa_expression:
439 count = dwarf_read_uleb128(current_insn, &expr_len);
440 current_insn += count;
442 frame->cfa_expr = current_insn;
443 frame->cfa_expr_len = expr_len;
444 current_insn += expr_len;
446 frame->flags |= DWARF_FRAME_CFA_REG_EXP;
447 break;
448 case DW_CFA_offset_extended_sf:
449 count = dwarf_read_uleb128(current_insn, &reg);
450 current_insn += count;
451 count = dwarf_read_leb128(current_insn, &offset);
452 current_insn += count;
453 offset *= cie->data_alignment_factor;
454 dwarf_frame_alloc_regs(frame, reg);
455 frame->regs[reg].flags |= DWARF_REG_OFFSET;
456 frame->regs[reg].addr = offset;
457 break;
458 case DW_CFA_val_offset:
459 count = dwarf_read_uleb128(current_insn, &reg);
460 current_insn += count;
461 count = dwarf_read_leb128(current_insn, &offset);
462 offset *= cie->data_alignment_factor;
463 frame->regs[reg].flags |= DWARF_REG_OFFSET;
464 frame->regs[reg].addr = offset;
465 break;
466 default:
467 pr_debug("unhandled DWARF instruction 0x%x\n", insn);
468 break;
472 return 0;
476 * dwarf_unwind_stack - recursively unwind the stack
477 * @pc: address of the function to unwind
478 * @prev: struct dwarf_frame of the previous stackframe on the callstack
480 * Return a struct dwarf_frame representing the most recent frame
481 * on the callstack. Each of the lower (older) stack frames are
482 * linked via the "prev" member.
484 struct dwarf_frame *dwarf_unwind_stack(unsigned long pc,
485 struct dwarf_frame *prev)
487 struct dwarf_frame *frame;
488 struct dwarf_cie *cie;
489 struct dwarf_fde *fde;
490 unsigned long addr;
491 int i, offset;
494 * If this is the first invocation of this recursive function we
495 * need get the contents of a physical register to get the CFA
496 * in order to begin the virtual unwinding of the stack.
498 * The constant DWARF_ARCH_UNWIND_OFFSET is added to the address of
499 * this function because the return address register
500 * (DWARF_ARCH_RA_REG) will probably not be initialised until a
501 * few instructions into the prologue.
503 if (!pc && !prev) {
504 pc = (unsigned long)&dwarf_unwind_stack;
505 pc += DWARF_ARCH_UNWIND_OFFSET;
508 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
509 if (!frame)
510 return NULL;
512 frame->prev = prev;
514 fde = dwarf_lookup_fde(pc);
515 if (!fde) {
517 * This is our normal exit path - the one that stops the
518 * recursion. There's two reasons why we might exit
519 * here,
521 * a) pc has no asscociated DWARF frame info and so
522 * we don't know how to unwind this frame. This is
523 * usually the case when we're trying to unwind a
524 * frame that was called from some assembly code
525 * that has no DWARF info, e.g. syscalls.
527 * b) the DEBUG info for pc is bogus. There's
528 * really no way to distinguish this case from the
529 * case above, which sucks because we could print a
530 * warning here.
532 return NULL;
535 cie = dwarf_lookup_cie(fde->cie_pointer);
537 frame->pc = fde->initial_location;
539 /* CIE initial instructions */
540 dwarf_cfa_execute_insns(cie->initial_instructions,
541 cie->instructions_end, cie, fde, frame, pc);
543 /* FDE instructions */
544 dwarf_cfa_execute_insns(fde->instructions, fde->end, cie,
545 fde, frame, pc);
547 /* Calculate the CFA */
548 switch (frame->flags) {
549 case DWARF_FRAME_CFA_REG_OFFSET:
550 if (prev) {
551 BUG_ON(!prev->regs[frame->cfa_register].flags);
553 addr = prev->cfa;
554 addr += prev->regs[frame->cfa_register].addr;
555 frame->cfa = __raw_readl(addr);
557 } else {
559 * Again, this is the first invocation of this
560 * recurisve function. We need to physically
561 * read the contents of a register in order to
562 * get the Canonical Frame Address for this
563 * function.
565 frame->cfa = dwarf_read_arch_reg(frame->cfa_register);
568 frame->cfa += frame->cfa_offset;
569 break;
570 default:
571 BUG();
574 /* If we haven't seen the return address reg, we're screwed. */
575 BUG_ON(!frame->regs[DWARF_ARCH_RA_REG].flags);
577 for (i = 0; i <= frame->num_regs; i++) {
578 struct dwarf_reg *reg = &frame->regs[i];
580 if (!reg->flags)
581 continue;
583 offset = reg->addr;
584 offset += frame->cfa;
587 addr = frame->cfa + frame->regs[DWARF_ARCH_RA_REG].addr;
588 frame->return_addr = __raw_readl(addr);
590 frame->next = dwarf_unwind_stack(frame->return_addr, frame);
591 return frame;
594 static int dwarf_parse_cie(void *entry, void *p, unsigned long len,
595 unsigned char *end)
597 struct dwarf_cie *cie;
598 unsigned long flags;
599 int count;
601 cie = kzalloc(sizeof(*cie), GFP_KERNEL);
602 if (!cie)
603 return -ENOMEM;
605 cie->length = len;
608 * Record the offset into the .eh_frame section
609 * for this CIE. It allows this CIE to be
610 * quickly and easily looked up from the
611 * corresponding FDE.
613 cie->cie_pointer = (unsigned long)entry;
615 cie->version = *(char *)p++;
616 BUG_ON(cie->version != 1);
618 cie->augmentation = p;
619 p += strlen(cie->augmentation) + 1;
621 count = dwarf_read_uleb128(p, &cie->code_alignment_factor);
622 p += count;
624 count = dwarf_read_leb128(p, &cie->data_alignment_factor);
625 p += count;
628 * Which column in the rule table contains the
629 * return address?
631 if (cie->version == 1) {
632 cie->return_address_reg = __raw_readb(p);
633 p++;
634 } else {
635 count = dwarf_read_uleb128(p, &cie->return_address_reg);
636 p += count;
639 if (cie->augmentation[0] == 'z') {
640 unsigned int length, count;
641 cie->flags |= DWARF_CIE_Z_AUGMENTATION;
643 count = dwarf_read_uleb128(p, &length);
644 p += count;
646 BUG_ON((unsigned char *)p > end);
648 cie->initial_instructions = p + length;
649 cie->augmentation++;
652 while (*cie->augmentation) {
654 * "L" indicates a byte showing how the
655 * LSDA pointer is encoded. Skip it.
657 if (*cie->augmentation == 'L') {
658 p++;
659 cie->augmentation++;
660 } else if (*cie->augmentation == 'R') {
662 * "R" indicates a byte showing
663 * how FDE addresses are
664 * encoded.
666 cie->encoding = *(char *)p++;
667 cie->augmentation++;
668 } else if (*cie->augmentation == 'P') {
670 * "R" indicates a personality
671 * routine in the CIE
672 * augmentation.
674 BUG();
675 } else if (*cie->augmentation == 'S') {
676 BUG();
677 } else {
679 * Unknown augmentation. Assume
680 * 'z' augmentation.
682 p = cie->initial_instructions;
683 BUG_ON(!p);
684 break;
688 cie->initial_instructions = p;
689 cie->instructions_end = end;
691 /* Add to list */
692 spin_lock_irqsave(&dwarf_cie_lock, flags);
693 list_add_tail(&cie->link, &dwarf_cie_list);
694 spin_unlock_irqrestore(&dwarf_cie_lock, flags);
696 return 0;
699 static int dwarf_parse_fde(void *entry, u32 entry_type,
700 void *start, unsigned long len)
702 struct dwarf_fde *fde;
703 struct dwarf_cie *cie;
704 unsigned long flags;
705 int count;
706 void *p = start;
708 fde = kzalloc(sizeof(*fde), GFP_KERNEL);
709 if (!fde)
710 return -ENOMEM;
712 fde->length = len;
715 * In a .eh_frame section the CIE pointer is the
716 * delta between the address within the FDE
718 fde->cie_pointer = (unsigned long)(p - entry_type - 4);
720 cie = dwarf_lookup_cie(fde->cie_pointer);
721 fde->cie = cie;
723 if (cie->encoding)
724 count = dwarf_read_encoded_value(p, &fde->initial_location,
725 cie->encoding);
726 else
727 count = dwarf_read_addr(p, &fde->initial_location);
729 p += count;
731 if (cie->encoding)
732 count = dwarf_read_encoded_value(p, &fde->address_range,
733 cie->encoding & 0x0f);
734 else
735 count = dwarf_read_addr(p, &fde->address_range);
737 p += count;
739 if (fde->cie->flags & DWARF_CIE_Z_AUGMENTATION) {
740 unsigned int length;
741 count = dwarf_read_uleb128(p, &length);
742 p += count + length;
745 /* Call frame instructions. */
746 fde->instructions = p;
747 fde->end = start + len;
749 /* Add to list. */
750 spin_lock_irqsave(&dwarf_fde_lock, flags);
751 list_add_tail(&fde->link, &dwarf_fde_list);
752 spin_unlock_irqrestore(&dwarf_fde_lock, flags);
754 return 0;
757 static void dwarf_unwinder_dump(struct task_struct *task, struct pt_regs *regs,
758 unsigned long *sp,
759 const struct stacktrace_ops *ops, void *data)
761 struct dwarf_frame *frame;
763 frame = dwarf_unwind_stack(0, NULL);
765 while (frame && frame->return_addr) {
766 ops->address(data, frame->return_addr, 1);
767 frame = frame->next;
771 static struct unwinder dwarf_unwinder = {
772 .name = "dwarf-unwinder",
773 .dump = dwarf_unwinder_dump,
774 .rating = 150,
777 static void dwarf_unwinder_cleanup(void)
779 struct dwarf_cie *cie, *m;
780 struct dwarf_fde *fde, *n;
781 unsigned long flags;
784 * Deallocate all the memory allocated for the DWARF unwinder.
785 * Traverse all the FDE/CIE lists and remove and free all the
786 * memory associated with those data structures.
788 spin_lock_irqsave(&dwarf_cie_lock, flags);
789 list_for_each_entry_safe(cie, m, &dwarf_cie_list, link)
790 kfree(cie);
791 spin_unlock_irqrestore(&dwarf_cie_lock, flags);
793 spin_lock_irqsave(&dwarf_fde_lock, flags);
794 list_for_each_entry_safe(fde, n, &dwarf_fde_list, link)
795 kfree(fde);
796 spin_unlock_irqrestore(&dwarf_fde_lock, flags);
800 * dwarf_unwinder_init - initialise the dwarf unwinder
802 * Build the data structures describing the .dwarf_frame section to
803 * make it easier to lookup CIE and FDE entries. Because the
804 * .eh_frame section is packed as tightly as possible it is not
805 * easy to lookup the FDE for a given PC, so we build a list of FDE
806 * and CIE entries that make it easier.
808 void dwarf_unwinder_init(void)
810 u32 entry_type;
811 void *p, *entry;
812 int count, err;
813 unsigned long len;
814 unsigned int c_entries, f_entries;
815 unsigned char *end;
816 INIT_LIST_HEAD(&dwarf_cie_list);
817 INIT_LIST_HEAD(&dwarf_fde_list);
819 c_entries = 0;
820 f_entries = 0;
821 entry = &__start_eh_frame;
823 while ((char *)entry < __stop_eh_frame) {
824 p = entry;
826 count = dwarf_entry_len(p, &len);
827 if (count == 0) {
829 * We read a bogus length field value. There is
830 * nothing we can do here apart from disabling
831 * the DWARF unwinder. We can't even skip this
832 * entry and move to the next one because 'len'
833 * tells us where our next entry is.
835 goto out;
836 } else
837 p += count;
839 /* initial length does not include itself */
840 end = p + len;
842 entry_type = get_unaligned((u32 *)p);
843 p += 4;
845 if (entry_type == DW_EH_FRAME_CIE) {
846 err = dwarf_parse_cie(entry, p, len, end);
847 if (err < 0)
848 goto out;
849 else
850 c_entries++;
851 } else {
852 err = dwarf_parse_fde(entry, entry_type, p, len);
853 if (err < 0)
854 goto out;
855 else
856 f_entries++;
859 entry = (char *)entry + len + 4;
862 printk(KERN_INFO "DWARF unwinder initialised: read %u CIEs, %u FDEs\n",
863 c_entries, f_entries);
865 err = unwinder_register(&dwarf_unwinder);
866 if (err)
867 goto out;
869 return;
871 out:
872 printk(KERN_ERR "Failed to initialise DWARF unwinder: %d\n", err);
873 dwarf_unwinder_cleanup();