1232950Stheraven/*
2232950Stheraven * Copyright 2010-2011 PathScale, Inc. All rights reserved.
3232950Stheraven *
4232950Stheraven * Redistribution and use in source and binary forms, with or without
5232950Stheraven * modification, are permitted provided that the following conditions are met:
6232950Stheraven *
7232950Stheraven * 1. Redistributions of source code must retain the above copyright notice,
8232950Stheraven *    this list of conditions and the following disclaimer.
9232950Stheraven *
10232950Stheraven * 2. Redistributions in binary form must reproduce the above copyright notice,
11232950Stheraven *    this list of conditions and the following disclaimer in the documentation
12232950Stheraven *    and/or other materials provided with the distribution.
13232950Stheraven *
14232950Stheraven * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
15232950Stheraven * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16232950Stheraven * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17232950Stheraven * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18232950Stheraven * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19232950Stheraven * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20232950Stheraven * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21232950Stheraven * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22232950Stheraven * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23232950Stheraven * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24232950Stheraven * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25232950Stheraven */
26227825Stheraven/**
27227825Stheraven * dwarf_eh.h - Defines some helper functions for parsing DWARF exception
28227825Stheraven * handling tables.
29227825Stheraven *
30227825Stheraven * This file contains various helper functions that are independent of the
31227825Stheraven * language-specific code.  It can be used in any personality function for the
32227825Stheraven * Itanium ABI.
33227825Stheraven */
34227825Stheraven#include <assert.h>
35227825Stheraven
36227825Stheraven// TODO: Factor out Itanium / ARM differences.  We probably want an itanium.h
37227825Stheraven// and arm.h that can be included by this file depending on the target ABI.
38227825Stheraven
39227825Stheraven// _GNU_SOURCE must be defined for unwind.h to expose some of the functions
40227825Stheraven// that we want.  If it isn't, then we define it and undefine it to make sure
41227825Stheraven// that it doesn't impact the rest of the program.
42227825Stheraven#ifndef _GNU_SOURCE
43227825Stheraven#	define _GNU_SOURCE 1
44227972Stheraven#	include "unwind.h"
45227825Stheraven#	undef _GNU_SOURCE
46227825Stheraven#else
47227972Stheraven#	include "unwind.h"
48227825Stheraven#endif
49227825Stheraven
50227825Stheraven#include <stdint.h>
51227825Stheraven
52227825Stheraven/// Type used for pointers into DWARF data
53227825Stheraventypedef unsigned char *dw_eh_ptr_t;
54227825Stheraven
55227825Stheraven// Flag indicating a signed quantity
56227825Stheraven#define DW_EH_PE_signed 0x08
57227825Stheraven/// DWARF data encoding types.
58227825Stheravenenum dwarf_data_encoding
59227825Stheraven{
60253159Stheraven	/// Absolute pointer value
61253159Stheraven	DW_EH_PE_absptr   = 0x00,
62227825Stheraven	/// Unsigned, little-endian, base 128-encoded (variable length).
63227825Stheraven	DW_EH_PE_uleb128 = 0x01,
64227825Stheraven	/// Unsigned 16-bit integer.
65227825Stheraven	DW_EH_PE_udata2  = 0x02,
66227825Stheraven	/// Unsigned 32-bit integer.
67227825Stheraven	DW_EH_PE_udata4  = 0x03,
68227825Stheraven	/// Unsigned 64-bit integer.
69227825Stheraven	DW_EH_PE_udata8  = 0x04,
70227825Stheraven	/// Signed, little-endian, base 128-encoded (variable length)
71227825Stheraven	DW_EH_PE_sleb128 = DW_EH_PE_uleb128 | DW_EH_PE_signed,
72227825Stheraven	/// Signed 16-bit integer.
73227825Stheraven	DW_EH_PE_sdata2  = DW_EH_PE_udata2 | DW_EH_PE_signed,
74227825Stheraven	/// Signed 32-bit integer.
75227825Stheraven	DW_EH_PE_sdata4  = DW_EH_PE_udata4 | DW_EH_PE_signed,
76227825Stheraven	/// Signed 32-bit integer.
77227825Stheraven	DW_EH_PE_sdata8  = DW_EH_PE_udata8 | DW_EH_PE_signed
78227825Stheraven};
79227825Stheraven
80227825Stheraven/**
81227825Stheraven * Returns the encoding for a DWARF EH table entry.  The encoding is stored in
82227825Stheraven * the low four of an octet.  The high four bits store the addressing mode.
83227825Stheraven */
84227825Stheravenstatic inline enum dwarf_data_encoding get_encoding(unsigned char x)
85227825Stheraven{
86278724Sdim	return static_cast<enum dwarf_data_encoding>(x & 0xf);
87227825Stheraven}
88227825Stheraven
89227825Stheraven/**
90227825Stheraven * DWARF addressing mode constants.  When reading a pointer value from a DWARF
91227825Stheraven * exception table, you must know how it is stored and what the addressing mode
92227825Stheraven * is.  The low four bits tell you the encoding, allowing you to decode a
93227825Stheraven * number.  The high four bits tell you the addressing mode, allowing you to
94227825Stheraven * turn that number into an address in memory.
95227825Stheraven */
96227825Stheravenenum dwarf_data_relative
97227825Stheraven{
98227825Stheraven	/// Value is omitted
99227825Stheraven	DW_EH_PE_omit     = 0xff,
100227825Stheraven	/// Value relative to program counter
101227825Stheraven	DW_EH_PE_pcrel    = 0x10,
102227825Stheraven	/// Value relative to the text segment
103227825Stheraven	DW_EH_PE_textrel  = 0x20,
104227825Stheraven	/// Value relative to the data segment
105227825Stheraven	DW_EH_PE_datarel  = 0x30,
106227825Stheraven	/// Value relative to the start of the function
107227825Stheraven	DW_EH_PE_funcrel  = 0x40,
108227825Stheraven	/// Aligned pointer (Not supported yet - are they actually used?)
109227825Stheraven	DW_EH_PE_aligned  = 0x50,
110227825Stheraven	/// Pointer points to address of real value
111227825Stheraven	DW_EH_PE_indirect = 0x80
112227825Stheraven};
113227825Stheraven/**
114227825Stheraven * Returns the addressing mode component of this encoding.
115227825Stheraven */
116227825Stheravenstatic inline enum dwarf_data_relative get_base(unsigned char x)
117227825Stheraven{
118278724Sdim	return static_cast<enum dwarf_data_relative>(x & 0x70);
119227825Stheraven}
120227825Stheraven/**
121227825Stheraven * Returns whether an encoding represents an indirect address.
122227825Stheraven */
123227825Stheravenstatic int is_indirect(unsigned char x)
124227825Stheraven{
125227825Stheraven	return ((x & DW_EH_PE_indirect) == DW_EH_PE_indirect);
126227825Stheraven}
127227825Stheraven
128227825Stheraven/**
129227825Stheraven * Returns the size of a fixed-size encoding.  This function will abort if
130227825Stheraven * called with a value that is not a fixed-size encoding.
131227825Stheraven */
132227825Stheravenstatic inline int dwarf_size_of_fixed_size_field(unsigned char type)
133227825Stheraven{
134227825Stheraven	switch (get_encoding(type))
135227825Stheraven	{
136227825Stheraven		default: abort();
137227825Stheraven		case DW_EH_PE_sdata2:
138227825Stheraven		case DW_EH_PE_udata2: return 2;
139227825Stheraven		case DW_EH_PE_sdata4:
140227825Stheraven		case DW_EH_PE_udata4: return 4;
141227825Stheraven		case DW_EH_PE_sdata8:
142227825Stheraven		case DW_EH_PE_udata8: return 8;
143227825Stheraven		case DW_EH_PE_absptr: return sizeof(void*);
144227825Stheraven	}
145227825Stheraven}
146227825Stheraven
147227825Stheraven/**
148227825Stheraven * Read an unsigned, little-endian, base-128, DWARF value.  Updates *data to
149227825Stheraven * point to the end of the value.  Stores the number of bits read in the value
150227825Stheraven * pointed to by b, allowing you to determine the value of the highest bit, and
151227825Stheraven * therefore the sign of a signed value.
152227825Stheraven *
153227825Stheraven * This function is not intended to be called directly.  Use read_sleb128() or
154227825Stheraven * read_uleb128() for reading signed and unsigned versions, respectively.
155227825Stheraven */
156227825Stheravenstatic uint64_t read_leb128(dw_eh_ptr_t *data, int *b)
157227825Stheraven{
158227825Stheraven	uint64_t uleb = 0;
159227825Stheraven	unsigned int bit = 0;
160227825Stheraven	unsigned char digit = 0;
161227825Stheraven	// We have to read at least one octet, and keep reading until we get to one
162227825Stheraven	// with the high bit unset
163227825Stheraven	do
164227825Stheraven	{
165227825Stheraven		// This check is a bit too strict - we should also check the highest
166227825Stheraven		// bit of the digit.
167227825Stheraven		assert(bit < sizeof(uint64_t) * 8);
168227825Stheraven		// Get the base 128 digit
169227825Stheraven		digit = (**data) & 0x7f;
170227825Stheraven		// Add it to the current value
171227825Stheraven		uleb += digit << bit;
172227825Stheraven		// Increase the shift value
173227825Stheraven		bit += 7;
174227825Stheraven		// Proceed to the next octet
175227825Stheraven		(*data)++;
176227825Stheraven		// Terminate when we reach a value that does not have the high bit set
177227825Stheraven		// (i.e. which was not modified when we mask it with 0x7f)
178227825Stheraven	} while ((*(*data - 1)) != digit);
179227825Stheraven	*b = bit;
180227825Stheraven
181227825Stheraven	return uleb;
182227825Stheraven}
183227825Stheraven
184227825Stheraven/**
185227825Stheraven * Reads an unsigned little-endian base-128 value starting at the address
186227825Stheraven * pointed to by *data.  Updates *data to point to the next byte after the end
187227825Stheraven * of the variable-length value.
188227825Stheraven */
189227825Stheravenstatic int64_t read_uleb128(dw_eh_ptr_t *data)
190227825Stheraven{
191227825Stheraven	int b;
192227825Stheraven	return read_leb128(data, &b);
193227825Stheraven}
194227825Stheraven
195227825Stheraven/**
196227825Stheraven * Reads a signed little-endian base-128 value starting at the address pointed
197227825Stheraven * to by *data.  Updates *data to point to the next byte after the end of the
198227825Stheraven * variable-length value.
199227825Stheraven */
200227825Stheravenstatic int64_t read_sleb128(dw_eh_ptr_t *data)
201227825Stheraven{
202227825Stheraven	int bits;
203227825Stheraven	// Read as if it's signed
204227825Stheraven	uint64_t uleb = read_leb128(data, &bits);
205227825Stheraven	// If the most significant bit read is 1, then we need to sign extend it
206227825Stheraven	if ((uleb >> (bits-1)) == 1)
207227825Stheraven	{
208227825Stheraven		// Sign extend by setting all bits in front of it to 1
209278724Sdim		uleb |= static_cast<int64_t>(-1) << bits;
210227825Stheraven	}
211278724Sdim	return static_cast<int64_t>(uleb);
212227825Stheraven}
213227825Stheraven/**
214227825Stheraven * Reads a value using the specified encoding from the address pointed to by
215227825Stheraven * *data.  Updates the value of *data to point to the next byte after the end
216227825Stheraven * of the data.
217227825Stheraven */
218227825Stheravenstatic uint64_t read_value(char encoding, dw_eh_ptr_t *data)
219227825Stheraven{
220227825Stheraven	enum dwarf_data_encoding type = get_encoding(encoding);
221227825Stheraven	switch (type)
222227825Stheraven	{
223227825Stheraven		// Read fixed-length types
224227825Stheraven#define READ(dwarf, type) \
225227825Stheraven		case dwarf:\
226279456Sdim		{\
227279456Sdim			type t;\
228279456Sdim			memcpy(&t, *data, sizeof t);\
229279456Sdim			*data += sizeof t;\
230279456Sdim			return static_cast<uint64_t>(t);\
231279456Sdim		}
232227825Stheraven		READ(DW_EH_PE_udata2, uint16_t)
233227825Stheraven		READ(DW_EH_PE_udata4, uint32_t)
234227825Stheraven		READ(DW_EH_PE_udata8, uint64_t)
235227825Stheraven		READ(DW_EH_PE_sdata2, int16_t)
236227825Stheraven		READ(DW_EH_PE_sdata4, int32_t)
237227825Stheraven		READ(DW_EH_PE_sdata8, int64_t)
238227825Stheraven		READ(DW_EH_PE_absptr, intptr_t)
239227825Stheraven#undef READ
240227825Stheraven		// Read variable-length types
241227825Stheraven		case DW_EH_PE_sleb128:
242279456Sdim			return read_sleb128(data);
243227825Stheraven		case DW_EH_PE_uleb128:
244279456Sdim			return read_uleb128(data);
245227825Stheraven		default: abort();
246227825Stheraven	}
247227825Stheraven}
248227825Stheraven
249227825Stheraven/**
250227825Stheraven * Resolves an indirect value.  This expects an unwind context, an encoding, a
251227825Stheraven * decoded value, and the start of the region as arguments.  The returned value
252227825Stheraven * is a pointer to the address identified by the encoded value.
253227825Stheraven *
254227825Stheraven * If the encoding does not specify an indirect value, then this returns v.
255227825Stheraven */
256227825Stheravenstatic uint64_t resolve_indirect_value(_Unwind_Context *c,
257227825Stheraven                                       unsigned char encoding,
258227825Stheraven                                       int64_t v,
259227825Stheraven                                       dw_eh_ptr_t start)
260227825Stheraven{
261227825Stheraven	switch (get_base(encoding))
262227825Stheraven	{
263227825Stheraven		case DW_EH_PE_pcrel:
264278724Sdim			v += reinterpret_cast<uint64_t>(start);
265227825Stheraven			break;
266227825Stheraven		case DW_EH_PE_textrel:
267278724Sdim			v += static_cast<uint64_t>(static_cast<uintptr_t>(_Unwind_GetTextRelBase(c)));
268227825Stheraven			break;
269227825Stheraven		case DW_EH_PE_datarel:
270278724Sdim			v += static_cast<uint64_t>(static_cast<uintptr_t>(_Unwind_GetDataRelBase(c)));
271227825Stheraven			break;
272227825Stheraven		case DW_EH_PE_funcrel:
273278724Sdim			v += static_cast<uint64_t>(static_cast<uintptr_t>(_Unwind_GetRegionStart(c)));
274227825Stheraven		default:
275227825Stheraven			break;
276227825Stheraven	}
277227825Stheraven	// If this is an indirect value, then it is really the address of the real
278227825Stheraven	// value
279227825Stheraven	// TODO: Check whether this should really always be a pointer - it seems to
280227825Stheraven	// be a GCC extensions, so not properly documented...
281227825Stheraven	if (is_indirect(encoding))
282227825Stheraven	{
283278724Sdim		v = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(*reinterpret_cast<void**>(v)));
284227825Stheraven	}
285227825Stheraven	return v;
286227825Stheraven}
287227825Stheraven
288227825Stheraven
289227825Stheraven/**
290227825Stheraven * Reads an encoding and a value, updating *data to point to the next byte.
291227825Stheraven */
292227825Stheravenstatic inline void read_value_with_encoding(_Unwind_Context *context,
293227825Stheraven                                            dw_eh_ptr_t *data,
294227825Stheraven                                            uint64_t *out)
295227825Stheraven{
296227825Stheraven	dw_eh_ptr_t start = *data;
297227825Stheraven	unsigned char encoding = *((*data)++);
298227825Stheraven	// If this value is omitted, skip it and don't touch the output value
299227825Stheraven	if (encoding == DW_EH_PE_omit) { return; }
300227825Stheraven
301227825Stheraven	*out = read_value(encoding, data);
302227825Stheraven	*out = resolve_indirect_value(context, encoding, *out, start);
303227825Stheraven}
304227825Stheraven
305227825Stheraven/**
306227825Stheraven * Structure storing a decoded language-specific data area.  Use parse_lsda()
307227825Stheraven * to generate an instance of this structure from the address returned by the
308227825Stheraven * generic unwind library.
309227825Stheraven *
310227825Stheraven * You should not need to inspect the fields of this structure directly if you
311227825Stheraven * are just using this header.  The structure stores the locations of the
312227825Stheraven * various tables used for unwinding exceptions and is used by the functions
313227825Stheraven * for reading values from these tables.
314227825Stheraven */
315227825Stheravenstruct dwarf_eh_lsda
316227825Stheraven{
317227825Stheraven	/// The start of the region.  This is a cache of the value returned by
318227825Stheraven	/// _Unwind_GetRegionStart().
319227825Stheraven	dw_eh_ptr_t region_start;
320227825Stheraven	/// The start of the landing pads table.
321227825Stheraven	dw_eh_ptr_t landing_pads;
322227825Stheraven	/// The start of the type table.
323227825Stheraven	dw_eh_ptr_t type_table;
324227825Stheraven	/// The encoding used for entries in the type tables.
325227825Stheraven	unsigned char type_table_encoding;
326227825Stheraven	/// The location of the call-site table.
327227825Stheraven	dw_eh_ptr_t call_site_table;
328227825Stheraven	/// The location of the action table.
329227825Stheraven	dw_eh_ptr_t action_table;
330227825Stheraven	/// The encoding used for entries in the call-site table.
331227825Stheraven	unsigned char callsite_encoding;
332227825Stheraven};
333227825Stheraven
334227825Stheraven/**
335227825Stheraven * Parse the header on the language-specific data area and return a structure
336227825Stheraven * containing the addresses and encodings of the various tables.
337227825Stheraven */
338227825Stheravenstatic inline struct dwarf_eh_lsda parse_lsda(_Unwind_Context *context,
339227825Stheraven                                              unsigned char *data)
340227825Stheraven{
341227825Stheraven	struct dwarf_eh_lsda lsda;
342227825Stheraven
343278724Sdim	lsda.region_start = reinterpret_cast<dw_eh_ptr_t>(_Unwind_GetRegionStart(context));
344227825Stheraven
345227825Stheraven	// If the landing pads are relative to anything other than the start of
346227825Stheraven	// this region, find out where.  This is @LPStart in the spec, although the
347227825Stheraven	// encoding that GCC uses does not quite match the spec.
348278724Sdim	uint64_t v = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(lsda.region_start));
349227825Stheraven	read_value_with_encoding(context, &data, &v);
350278724Sdim	lsda.landing_pads = reinterpret_cast<dw_eh_ptr_t>(static_cast<uintptr_t>(v));
351227825Stheraven
352227825Stheraven	// If there is a type table, find out where it is.  This is @TTBase in the
353227825Stheraven	// spec.  Note: we find whether there is a type table pointer by checking
354227825Stheraven	// whether the leading byte is DW_EH_PE_omit (0xff), which is not what the
355227825Stheraven	// spec says, but does seem to be how G++ indicates this.
356227825Stheraven	lsda.type_table = 0;
357227825Stheraven	lsda.type_table_encoding = *data++;
358227825Stheraven	if (lsda.type_table_encoding != DW_EH_PE_omit)
359227825Stheraven	{
360227825Stheraven		v = read_uleb128(&data);
361227825Stheraven		dw_eh_ptr_t type_table = data;
362227825Stheraven		type_table += v;
363227825Stheraven		lsda.type_table = type_table;
364227825Stheraven		//lsda.type_table = (uintptr_t*)(data + v);
365227825Stheraven	}
366278724Sdim#if defined(__arm__) && !defined(__ARM_DWARF_EH__)
367227972Stheraven	lsda.type_table_encoding = (DW_EH_PE_pcrel | DW_EH_PE_indirect);
368227972Stheraven#endif
369227825Stheraven
370278724Sdim	lsda.callsite_encoding = static_cast<enum dwarf_data_encoding>(*(data++));
371227825Stheraven
372227825Stheraven	// Action table is immediately after the call site table
373227825Stheraven	lsda.action_table = data;
374278724Sdim	uintptr_t callsite_size = static_cast<uintptr_t>(read_uleb128(&data));
375227825Stheraven	lsda.action_table = data + callsite_size;
376227825Stheraven	// Call site table is immediately after the header
377278724Sdim	lsda.call_site_table = static_cast<dw_eh_ptr_t>(data);
378227825Stheraven
379227825Stheraven
380227825Stheraven	return lsda;
381227825Stheraven}
382227825Stheraven
383227825Stheraven/**
384227825Stheraven * Structure representing an action to be performed while unwinding.  This
385227825Stheraven * contains the address that should be unwound to and the action record that
386227825Stheraven * provoked this action.
387227825Stheraven */
388227825Stheravenstruct dwarf_eh_action
389227825Stheraven{
390227825Stheraven	/**
391227825Stheraven	 * The address that this action directs should be the new program counter
392227825Stheraven	 * value after unwinding.
393227825Stheraven	 */
394227825Stheraven	dw_eh_ptr_t landing_pad;
395227825Stheraven	/// The address of the action record.
396227825Stheraven	dw_eh_ptr_t action_record;
397227825Stheraven};
398227825Stheraven
399227825Stheraven/**
400227825Stheraven * Look up the landing pad that corresponds to the current invoke.
401227825Stheraven * Returns true if record exists.  The context is provided by the generic
402227825Stheraven * unwind library and the lsda should be the result of a call to parse_lsda().
403227825Stheraven *
404227825Stheraven * The action record is returned via the result parameter.
405227825Stheraven */
406227825Stheravenstatic bool dwarf_eh_find_callsite(struct _Unwind_Context *context,
407227825Stheraven                                   struct dwarf_eh_lsda *lsda,
408227825Stheraven                                   struct dwarf_eh_action *result)
409227825Stheraven{
410227825Stheraven	result->action_record = 0;
411227825Stheraven	result->landing_pad = 0;
412227825Stheraven	// The current instruction pointer offset within the region
413227825Stheraven	uint64_t ip = _Unwind_GetIP(context) - _Unwind_GetRegionStart(context);
414278724Sdim	unsigned char *callsite_table = static_cast<unsigned char*>(lsda->call_site_table);
415227825Stheraven
416227825Stheraven	while (callsite_table <= lsda->action_table)
417227825Stheraven	{
418227825Stheraven		// Once again, the layout deviates from the spec.
419227825Stheraven		uint64_t call_site_start, call_site_size, landing_pad, action;
420227825Stheraven		call_site_start = read_value(lsda->callsite_encoding, &callsite_table);
421227825Stheraven		call_site_size = read_value(lsda->callsite_encoding, &callsite_table);
422227825Stheraven
423227825Stheraven		// Call site entries are sorted, so if we find a call site that's after
424227825Stheraven		// the current instruction pointer then there is no action associated
425227825Stheraven		// with this call and we should unwind straight through this frame
426227825Stheraven		// without doing anything.
427227825Stheraven		if (call_site_start > ip) { break; }
428227825Stheraven
429227825Stheraven		// Read the address of the landing pad and the action from the call
430227825Stheraven		// site table.
431227825Stheraven		landing_pad = read_value(lsda->callsite_encoding, &callsite_table);
432227825Stheraven		action = read_uleb128(&callsite_table);
433227825Stheraven
434227825Stheraven		// We should not include the call_site_start (beginning of the region)
435227825Stheraven		// address in the ip range. For each call site:
436227825Stheraven		//
437227825Stheraven		// address1: call proc
438227825Stheraven		// address2: next instruction
439227825Stheraven		//
440227825Stheraven		// The call stack contains address2 and not address1, address1 can be
441227825Stheraven		// at the end of another EH region.
442227825Stheraven		if (call_site_start < ip && ip <= call_site_start + call_site_size)
443227825Stheraven		{
444227825Stheraven			if (action)
445227825Stheraven			{
446227825Stheraven				// Action records are 1-biased so both no-record and zeroth
447227825Stheraven				// record can be stored.
448227825Stheraven				result->action_record = lsda->action_table + action - 1;
449227825Stheraven			}
450227825Stheraven			// No landing pad means keep unwinding.
451227825Stheraven			if (landing_pad)
452227825Stheraven			{
453227825Stheraven				// Landing pad is the offset from the value in the header
454227825Stheraven				result->landing_pad = lsda->landing_pads + landing_pad;
455227825Stheraven			}
456227825Stheraven			return true;
457227825Stheraven		}
458227825Stheraven	}
459227825Stheraven	return false;
460227825Stheraven}
461227825Stheraven
462227825Stheraven/// Defines an exception class from 8 bytes (endian independent)
463227825Stheraven#define EXCEPTION_CLASS(a,b,c,d,e,f,g,h) \
464278724Sdim	((static_cast<uint64_t>(a) << 56) +\
465278724Sdim	 (static_cast<uint64_t>(b) << 48) +\
466278724Sdim	 (static_cast<uint64_t>(c) << 40) +\
467278724Sdim	 (static_cast<uint64_t>(d) << 32) +\
468278724Sdim	 (static_cast<uint64_t>(e) << 24) +\
469278724Sdim	 (static_cast<uint64_t>(f) << 16) +\
470278724Sdim	 (static_cast<uint64_t>(g) << 8) +\
471278724Sdim	 (static_cast<uint64_t>(h)))
472227825Stheraven
473227825Stheraven#define GENERIC_EXCEPTION_CLASS(e,f,g,h) \
474278724Sdim	 (static_cast<uint32_t>(e) << 24) +\
475278724Sdim	 (static_cast<uint32_t>(f) << 16) +\
476278724Sdim	 (static_cast<uint32_t>(g) << 8) +\
477278724Sdim	 (static_cast<uint32_t>(h))
478