1 /* libunwind - a platform-independent unwind library
2    Copyright (c) 2003 Hewlett-Packard Development Company, L.P.
3         Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4 
5 This file is part of libunwind.
6 
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
14 
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
25 
26 #ifndef dwarf_eh_h
27 #define dwarf_eh_h
28 
29 #include "dwarf.h"
30 #include "libunwind_i.h"
31 
32 /* This header file defines the format of a DWARF exception-header
33    section (.eh_frame_hdr, pointed to by program-header
34    PT_GNU_EH_FRAME).  The exception-header is self-describing in the
35    sense that the format of the addresses contained in it is expressed
36    as a one-byte type-descriptor called a "pointer-encoding" (PE).
37 
38    The exception header encodes the address of the .eh_frame section
39    and optionally contains a binary search table for the
40    Frame Descriptor Entries (FDEs) in the .eh_frame.  The contents of
41    .eh_frame has the format described by the DWARF v3 standard
42    (http://www.eagercon.com/dwarf/dwarf3std.htm), except that code
43    addresses may be encoded in different ways.  Also, .eh_frame has
44    augmentations that allow encoding a language-specific data-area
45    (LSDA) pointer and a pointer to a personality-routine.
46 
47    Details:
48 
49     The Common Information Entry (CIE) associated with an FDE may
50     contain an augmentation string.  Each character in this string has
51     a specific meaning and either one or two associated operands.  The
52     operands are stored in an augmentation body which appears right
53     after the "return_address_register" member and before the
54     "initial_instructions" member.  The operands appear in the order
55     in which the characters appear in the string.  For example, if the
56     augmentation string is "zL", the operand for 'z' would be first in
57     the augmentation body and the operand for 'L' would be second.
58     The following characters are supported for the CIE augmentation
59     string:
60 
61      'z': The operand for this character is a uleb128 value that gives the
62           length of the CIE augmentation body, not counting the length
63           of the uleb128 operand itself.  If present, this code must
64           appear as the first character in the augmentation body.
65 
66      'L': Indicates that the FDE's augmentation body contains an LSDA
67           pointer.  The operand for this character is a single byte
68           that specifies the pointer-encoding (PE) that is used for
69           the LSDA pointer.
70 
71      'R': Indicates that the code-pointers (FDE members
72           "initial_location" and "address_range" and the operand for
73           DW_CFA_set_loc) in the FDE have a non-default encoding.  The
74           operand for this character is a single byte that specifies
75           the pointer-encoding (PE) that is used for the
76           code-pointers.  Note: the "address_range" member is always
77           encoded as an absolute value.  Apart from that, the specified
78           FDE pointer-encoding applies.
79 
80      'P': Indicates the presence of a personality routine (handler).
81           The first operand for this character specifies the
82           pointer-encoding (PE) that is used for the second operand,
83           which specifies the address of the personality routine.
84 
85     If the augmentation string contains any other characters, the
86     remainder of the augmentation string should be ignored.
87     Furthermore, if the size of the augmentation body is unknown
88     (i.e., 'z' is not the first character of the augmentation string),
89     then the entire CIE as well all associated FDEs must be ignored.
90 
91     A Frame Descriptor Entries (FDE) may contain an augmentation body
92     which, if present, appears right after the "address_range" member
93     and before the "instructions" member.  The contents of this body
94     is implicitly defined by the augmentation string of the associated
95     CIE.  The meaning of the characters in the CIE's augmentation
96     string as far as FDEs are concerned is as follows:
97 
98      'z': The first operand in the FDE's augmentation body specifies
99           the total length of the augmentation body as a uleb128 (not
100           counting the length of the uleb128 operand itself).
101 
102      'L': The operand for this character is an LSDA pointer, encoded
103           in the format specified by the corresponding operand in the
104           CIE's augmentation body.
105 
106 */
107 
108 #define DW_EH_VERSION           1       /* The version we're implementing */
109 
110 struct __attribute__((packed)) dwarf_eh_frame_hdr
111   {
112     unsigned char version;
113     unsigned char eh_frame_ptr_enc;
114     unsigned char fde_count_enc;
115     unsigned char table_enc;
116     Elf_W (Addr) eh_frame;
117     /* The rest of the header is variable-length and consists of the
118        following members:
119 
120         encoded_t fde_count;
121         struct
122           {
123             encoded_t start_ip; // first address covered by this FDE
124             encoded_t fde_addr; // address of the FDE
125           }
126         binary_search_table[fde_count];  */
127   };
128 
129 #endif /* dwarf_eh_h */
130