eh_frame_parser.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  1. /*
  2. * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file DWARF Exception Frames parser
  8. *
  9. * This file performs parsing and execution of DWARF except frames described in
  10. * section `.eh_frame` and `.eh_frame_hdr`. This is currently used on RISC-V
  11. * boards to implement a complete backtracing when a panic occurs.
  12. *
  13. * More information about the sections structure and DWARF instructions can be
  14. * found in the official documentation:
  15. * http://dwarfstd.org/Download.php
  16. */
  17. #include "sdkconfig.h"
  18. #include <string.h>
  19. #if CONFIG_ESP_SYSTEM_USE_EH_FRAME
  20. #include "libunwind.h"
  21. #include "esp_private/panic_internal.h"
  22. #include "esp_private/eh_frame_parser.h"
  23. #if UNW_UNKNOWN_TARGET
  24. #error "Unsupported architecture for unwinding"
  25. #endif
  26. /**
  27. * @brief Dimension of an array (number of elements)
  28. */
  29. #ifndef DIM
  30. #define DIM(array) (sizeof(array)/sizeof(*array))
  31. #endif
  32. /**
  33. * @brief DWARF Exception Header Encoding
  34. * This is used to know how the data in .eh_frame and .eh_frame_hdr sections
  35. * are encoded.
  36. */
  37. /* DWARF Exception Exception Header value format. */
  38. #define DW_EH_PE_omit 0xff /*!< No value is present */
  39. #define DW_EH_PE_uleb128 0x01 /*!< Unsigned value encoded in LEB128 (Little Endian Base 128). */
  40. #define DW_EH_PE_udata2 0x02 /*!< Unsigned 16-bit value. */
  41. #define DW_EH_PE_udata4 0x03 /*!< Unsigned 32-bit value. */
  42. #define DW_EH_PE_udata8 0x04 /*!< Unsigned 64-bit value. */
  43. #define DW_EH_PE_sleb128 0x09 /*!< Signed value encoded in LEB128 (Little Endian Base 128). */
  44. #define DW_EH_PE_sdata2 0x0A /*!< Signed 16-bit value. */
  45. #define DW_EH_PE_sdata4 0x0B /*!< Signed 32-bit value. */
  46. #define DW_EH_PE_sdata8 0x0C /*!< Signed 64-bit value. */
  47. /* DWARF Exception Exception Header value application.
  48. * These values are in fact represented in the high nibble of a given data.
  49. * For example:
  50. * 0x3A describes the values as signed 16-bit offsets relative to .eh_frame_hdr section.
  51. * 0x11 describes the values as unsigned value encoded in LEB128, relative to their location ion memory. */
  52. #define DW_EH_PE_absptr 0x00 /*!< The value itself is a pointer, it is not an offset. */
  53. #define DW_EH_PE_pcrel 0x01 /*!< The value is an offset, relative to its location in memory. */
  54. #define DW_EH_PE_datarel 0x03 /*!< The value is an offset, relative to .eh_frame_hdr section. */
  55. /* Macros simplifying testing relative offset data encoding. */
  56. #define ESP_ENCODING_PC_REL(ENCODING) (((ENCODING >> 4) & 0xf) == DW_EH_PE_pcrel)
  57. #define ESP_ENCODING_FRAME_HDR_REL(ENCODING) (((ENCODING >> 4) & 0xf) == DW_EH_PE_datarel)
  58. /**
  59. * @brief Call Frame Information (CIE) fields information.
  60. * As the size of CIE is variable, the simplest way to described it is to
  61. * have a pointer at the beginning of CIE structure and access the fields
  62. * thanks to the index macros defined here.
  63. */
  64. #define ESP_CIE_VARIABLE_FIELDS_IDX (9) /*!< Offset, in bytes, where variable length fields start. */
  65. /**
  66. * @brief Frame Description Entry (FDE) fields index.
  67. * For the same reasons as above, we prefer defining these macros rather than
  68. * having a structure.
  69. */
  70. #define ESP_FDE_LENGTH_IDX (0) /*!< Length, in bytes, of the FDE excluding this field. 4 bytes field. */
  71. #define ESP_FDE_CIE_IDX (1) /*!< Nearest preceding Common Information Entry (CIE) offset. 4 bytes field. */
  72. #define ESP_FDE_INITLOC_IDX (2) /*!< Initial location (of the function) the FDE describes. Variable size (encoding in CIE). */
  73. #define ESP_FDE_RANGELEN_IDX (3) /*!< Size, in bytes, of the function described by this FDE location the FDE describes. Variable size (encoding in CIE). */
  74. #define ESP_FDE_AUGMENTATION_IDX (4) /*!< Augmentation data length. Unsigned LEB128. */
  75. /**
  76. * @brief Pointers to both .eh_frame_hdr and .eh_frame sections.
  77. */
  78. #define EH_FRAME_HDR_ADDR (&__eh_frame_hdr)
  79. #define EH_FRAME_ADDR (&__eh_frame)
  80. /**
  81. * @brief Structure of .eh_frame_hdr section header.
  82. */
  83. typedef struct {
  84. uint8_t version; /*!< Structure version, must be 1.*/
  85. uint8_t eh_frame_ptr_enc; /*!< eh_frame_ptr entry encoding. */
  86. uint8_t fde_count_enc; /*!< fde_count entry encoding. */
  87. uint8_t table_enc; /*!< table entries encoding. */
  88. /* The rest of the structure has variable length. Thus, we cannot define
  89. * them here. Here are their names:
  90. * - eh_frame_ptr : encoded pointer to the .eh_frame section.
  91. * - fde_Count : number of entries in the array of table_entry.
  92. * - table_entry array : sorted array of table_entry. */
  93. } __attribute__((packed)) fde_header;
  94. /**
  95. * @brief .eh_frame_hdr table's entry format.
  96. * Each entry of the table contains 2 32-bit encoded addresses.
  97. * Encoding is defined in the previous structure. Check table_enc field.
  98. */
  99. typedef struct {
  100. uint32_t fun_addr; /*!< Address of the function described. */
  101. uint32_t fde_addr; /*!< Address of the FDE for the function.*/
  102. } table_entry;
  103. /**
  104. * @brief DWARF state constant macros.
  105. */
  106. #define ESP_EH_FRAME_STACK_SIZE (2) /*!< DWARF virtual machine can save the push the current on a virtual
  107. stack. we mimic the stack with an array. While testing, a stack
  108. size of 2 was enough. */
  109. /**
  110. * @brief
  111. * Structure representing the state of the DWARF virtual machine.
  112. */
  113. typedef struct {
  114. /* Stack for DWARF state registers.
  115. * For caller saved registers, save their CFA address (value in previous call frame).
  116. * As these registers will be used to define offset in the CFA, they will always be
  117. * multiple of CPU word (4-bytes in our case). Thus, it will save the offset in word-size, not
  118. * in bytes. Plus, the highest bit will be used to mark that this register is NOY
  119. * ESP_EH_FRAME_REG_SAME. (0x80000000 is a valid value then, meaning that the register value
  120. * is CFA + 0 offset) */
  121. uint32_t regs_offset[ESP_EH_FRAME_STACK_SIZE][EXECUTION_FRAME_MAX_REGS];
  122. /* reg_offset represents the state of registers when PC reaches the following location. */
  123. uint32_t location;
  124. /* Index of the registers offset to use (1 for saved offset, 0 else). */
  125. uint8_t offset_idx;
  126. } dwarf_regs;
  127. /**
  128. * @brief DWARF's register state.
  129. * When a DWARF register is set to ESP_EH_FRAME_REG_SAME, the CPU register corresponding to this
  130. * virtual register will be unchanged after executing DWARF instructions.
  131. * Please see esp_eh_frame_restore_caller_state() for more details.
  132. */
  133. #define ESP_EH_FRAME_REG_SAME (0)
  134. /**
  135. * @brief Set a register's offset (relative to CFA).
  136. * The highest bit is set to 1 to mark that this register needs to be retrived because it has been
  137. * altered.
  138. */
  139. #define ESP_EH_FRAME_SET_REG_OFFSET(offset) (0x80000000 | offset)
  140. /**
  141. * @brief Get a register's offset (relative to CFA).
  142. */
  143. #define ESP_EH_FRAME_GET_REG_OFFSET(offset) (0x7fffffff & offset)
  144. /**
  145. * @brief Get a register's CFA offset.
  146. */
  147. #define ESP_EH_FRAME_IS_CFA_RELATIVE(reg) ((reg >> 31) == 1)
  148. /**
  149. * @brief Test whether an offset is small enough to be stored
  150. * in our 32-bit register.
  151. * Note: the highest bit is used.
  152. */
  153. #define ESP_EH_FRAME_CFA_OFFSET_VALID(offset) (offset < 0x80000000)
  154. /**
  155. * @brief Index of Call Frame Address (CFA) in DWARF registers array.
  156. */
  157. #define ESP_ESH_FRAME_CFA_IDX (EXECUTION_FRAME_SP_REG)
  158. /**
  159. * @brief Macros to get and set CFA's relative register and offset.
  160. * Indeed, CFA is defined by two values: register and offset. CFA is then
  161. * calculated by adding the offset to the register value.
  162. * `register` will be stored in the lowest 8 bits.
  163. * `offset` will be stored in the highest 24 bits.
  164. *
  165. * NOTE: with this implementation, CFA will be affected by
  166. * DW_CFA_REMEMBER_STATE and DW_CFA_RESTORE_STATE instructions.
  167. */
  168. #if EXECUTION_FRAME_MAX_REGS > 255
  169. #error "Too many registers defined for the target ExecutionFrame"
  170. #endif
  171. #define ESP_EH_FRAME_CFA_REG_VALID(reg) (reg < EXECUTION_FRAME_MAX_REGS)
  172. #define ESP_EH_FRAME_CFA_OFF_VALID(off) (((off) >> 24) == 0)
  173. #define ESP_EH_FRAME_CFA(state) ((state)->regs_offset[(state)->offset_idx][ESP_ESH_FRAME_CFA_IDX])
  174. #define ESP_EH_FRAME_NEW_CFA(reg, off) (((off) << 8) | ((reg) & 0xff))
  175. #define ESP_EH_FRAME_SET_CFA_REG(value, reg) (((value) & ~0xff) | ((reg) & 0xff))
  176. #define ESP_EH_FRAME_SET_CFA_OFF(value, off) (((value) & 0xff) | ((off) << 8))
  177. #define ESP_EH_FRAME_GET_CFA_REG(value) ((value) & 0xff)
  178. #define ESP_EH_FRAME_GET_CFA_OFF(value) ((value) >> 8)
  179. /**
  180. * @brief Unsupported opcode value to return when exeucting 0-opcode type instructions.
  181. */
  182. #define ESP_EH_FRAME_UNSUPPORTED_OPCODE ((uint32_t) -1)
  183. /**
  184. * @brief Macros defining the DWARF instructions code.
  185. */
  186. #define DW_GET_OPCODE(OP) ((OP) >> 6)
  187. #define DW_GET_PARAM(OP) ((OP) & 0b111111)
  188. #define DW_CFA_ADVANCE_LOC (1)
  189. #define DW_CFA_OFFSET (2)
  190. #define DW_CFA_RESTORE (3)
  191. /**
  192. * @brief Constant for DWARF instructions code when high 2 bits are 0.
  193. */
  194. #define DW_CFA_0_OPCODE (0)
  195. #define DW_CFA_NOP (0x0)
  196. #define DW_CFA_SET_LOC (0x1)
  197. #define DW_CFA_ADVANCE_LOC1 (0x2)
  198. #define DW_CFA_ADVANCE_LOC2 (0x3)
  199. #define DW_CFA_ADVANCE_LOC4 (0x4)
  200. #define DW_CFA_OFFSET_EXTENDED (0x5)
  201. #define DW_CFA_RESTORE_EXTENDED (0x6)
  202. #define DW_CFA_UNDEFINED (0x7)
  203. #define DW_CFA_SAME_VALUE (0x8)
  204. #define DW_CFA_REGISTER (0x9)
  205. #define DW_CFA_REMEMBER_STATE (0xA)
  206. #define DW_CFA_RESTORE_STATE (0xB)
  207. #define DW_CFA_DEF_CFA (0xC)
  208. #define DW_CFA_DEF_CFA_REGISTER (0xD)
  209. #define DW_CFA_DEF_CFA_OFFSET (0xE)
  210. #define DW_CFA_DEF_CFA_EXPRESSION (0xF)
  211. #define DW_CFA_EXPRESSION (0x10)
  212. #define DW_CFA_OFFSET_EXTENDED_SF (0x11)
  213. #define DW_CFA_DEF_CFA_SF (0x12)
  214. #define DW_CFA_DEF_CFA_OFFSET_SF (0x13)
  215. #define DW_CFA_VAL_OFFSET (0x14)
  216. #define DW_CFA_VAL_OFFSET_SF (0x15)
  217. #define DW_CFA_VAL_EXPRESSION (0x16)
  218. #define DW_CFA_LO_USER (0x1C)
  219. /**
  220. * @brief Constants used for decoding (U)LEB128 integers.
  221. */
  222. #define DW_LEB128_HIGHEST_BIT(byte) (((byte) >> 7) & 1)
  223. #define DW_LEB128_SIGN_BIT(byte) (((byte) >> 6) & 1)
  224. #define DW_LEB128_MAX_SHIFT (31)
  225. /**
  226. * @brief Symbols defined by the linker.
  227. * Retrieve the addresses of both .eh_frame_hdr and .eh_frame sections.
  228. */
  229. extern void *__eh_frame_hdr;
  230. extern void *__eh_frame;
  231. /**
  232. * @brief Decode multiple bytes encoded in LEB128.
  233. *
  234. * @param bytes bytes encoded in LEB128. They will not be modified.
  235. * @param is_signed true if bytes represent a signed value, false else.
  236. * @param size Size in bytes of the encoded value.
  237. *
  238. * @return Decoded bytes.
  239. */
  240. static uint32_t decode_leb128(const uint8_t* bytes, bool is_signed, uint32_t* lebsize)
  241. {
  242. uint32_t res = 0;
  243. uint32_t shf = 0;
  244. uint32_t size = 0;
  245. uint8_t byte = 0;
  246. while(1) {
  247. byte = bytes[size++];
  248. res |= (byte & 0x7f) << shf;
  249. shf += 7;
  250. if (DW_LEB128_HIGHEST_BIT(byte) == 0)
  251. break;
  252. }
  253. if (is_signed && shf <= DW_LEB128_MAX_SHIFT && DW_LEB128_SIGN_BIT(byte)) {
  254. res |= ((uint32_t) ~0 << shf);
  255. }
  256. if (lebsize) {
  257. *lebsize = size;
  258. }
  259. return res;
  260. }
  261. /**
  262. * @brief Get the value of data encoded.
  263. *
  264. * @param data Pointer to the encoded data.
  265. * @param encoding Encoding for the data to read.
  266. * @param psize Reference to be filled with data size, in bytes.
  267. *
  268. * @return Decoded data read from the pointer.
  269. */
  270. static uint32_t esp_eh_frame_get_encoded(void* data, uint8_t encoding, uint32_t* psize)
  271. {
  272. int32_t svalue = 0;
  273. uint32_t uvalue = 0;
  274. uint32_t fvalue = 0;
  275. uint32_t size = 0;
  276. const uint32_t high = encoding >> 4;
  277. const uint32_t low = encoding & 0xf;
  278. assert(psize != NULL);
  279. if (encoding == DW_EH_PE_omit) {
  280. *psize = size;
  281. return uvalue;
  282. }
  283. switch (low) {
  284. case DW_EH_PE_udata2:
  285. size = 2;
  286. uvalue = *((uint16_t*) data);
  287. break;
  288. case DW_EH_PE_udata4:
  289. size = 4;
  290. uvalue = *((uint32_t*) data);
  291. break;
  292. case DW_EH_PE_sdata2:
  293. size = 2;
  294. svalue = *((int16_t*) data);
  295. break;
  296. case DW_EH_PE_sdata4:
  297. size = 4;
  298. svalue = *((int32_t*) data);
  299. break;
  300. default:
  301. /* Unsupported yet. */
  302. assert(false);
  303. break;
  304. }
  305. switch (high) {
  306. case DW_EH_PE_absptr:
  307. /* Do not change the values, as one of them will be 0, fvalue will
  308. * contain the data no matter whether it is signed or unsigned. */
  309. fvalue = svalue + uvalue;
  310. break;
  311. case DW_EH_PE_pcrel:
  312. /* Relative to the address of the data.
  313. * svalue has been casted to an 32-bit value, so even if it was a
  314. * 2-byte signed value, fvalue will be calculated correctly here. */
  315. fvalue = (uint32_t) data + svalue + uvalue;
  316. break;
  317. case DW_EH_PE_datarel:
  318. fvalue = (uint32_t) EH_FRAME_HDR_ADDR + svalue + uvalue;
  319. break;
  320. }
  321. *psize = size;
  322. return fvalue;
  323. }
  324. /**
  325. * @brief Find entry in the table for the given return_address.
  326. *
  327. * @param sorted_table Pointer to the sorted table of entries.
  328. * @param length Number of entries in the table.
  329. * @param encoding Encoding for the addresses in the table
  330. * (Check DWARF documentation for more info about encoding).
  331. * @param return_address The address to find in the table. This address can be
  332. * part of one in the function listed.
  333. *
  334. * @note The table is structured like this (after decoding the addresses):
  335. * Function address FDE address Index
  336. * +-------------------------------+
  337. * |0x403805a4 0x4038d014| 0
  338. * +-------------------------------+
  339. * |0x403805be 0x4038d034| 1
  340. * +-------------------------------+
  341. * |0x403805d8 0x4038d070| 2
  342. * +-------------------------------+
  343. * |.......... ..........| ...
  344. * +-------------------------------+
  345. * |0x42020c48 0x4038ddb4| length-3
  346. * +-------------------------------+
  347. * |0x42020dca 0x4038dde4| length-2
  348. *+-------------------------------+
  349. * |0x42020f92 0x4038debc| length-1
  350. * +-------------------------------+
  351. *
  352. * For example, if return_address passed is 0x403805b4, this function will
  353. * return a pointer to the entry (0x403805a4, 0x4038d014).
  354. *
  355. * @return Pointer to the entry found, NULL if not found.
  356. */
  357. static const table_entry* esp_eh_frame_find_entry(const table_entry* sorted_table,
  358. const uint32_t length,
  359. const uint32_t encoding,
  360. const uint32_t return_address)
  361. {
  362. int32_t ra = 0;
  363. /* Used for decoding addresses in the table. */
  364. uint32_t is_signed = (encoding & 0xf) >= 0x9;
  365. uint32_t pc_relative = true;
  366. /* The following local variables are used for dichotomic search. */
  367. uint32_t found = false;
  368. uint32_t begin = 0;
  369. uint32_t end = length;
  370. uint32_t middle = (end + begin) / 2;
  371. /* If the addresses in the table are offsets relative to the eh_frame section,
  372. * instead of decoding each of them, we can simply encode the return_address
  373. * we have to find. If addresses are offsets relative to the programe counter,
  374. * then we have no other choice than decoding each of them to compare them
  375. * with return_address. */
  376. if (ESP_ENCODING_FRAME_HDR_REL(encoding)) {
  377. ra = return_address - (uint32_t) EH_FRAME_HDR_ADDR;
  378. pc_relative = false;
  379. }
  380. /* Perform dichotomic search. */
  381. while (end != 0 && middle != (length - 1) && !found) {
  382. const uint32_t fun_addr = sorted_table[middle].fun_addr;
  383. const uint32_t nxt_addr = sorted_table[middle + 1].fun_addr;
  384. if (pc_relative) {
  385. ra = return_address - (uint32_t) (sorted_table + middle);
  386. }
  387. if (is_signed) {
  388. /* Signed comparisons. */
  389. const int32_t sfun_addr = (int32_t) fun_addr;
  390. const int32_t snxt_addr = (int32_t) nxt_addr;
  391. if (sfun_addr <= ra && snxt_addr > ra)
  392. found = true;
  393. else if (snxt_addr <= ra)
  394. begin = middle + 1;
  395. else
  396. end = middle;
  397. } else {
  398. /* Unsigned comparisons. */
  399. const uint32_t ura = (uint32_t) ra;
  400. if (fun_addr <= ura && nxt_addr > ura)
  401. found = true;
  402. else if (nxt_addr <= ura)
  403. begin = middle + 1;
  404. else
  405. end = middle;
  406. }
  407. middle = (end + begin) / 2;
  408. }
  409. /* If 'end' reached the beginning of the array, it means the return_address
  410. * passed was below the first address of the array, thus, it was wrong.
  411. * Else, return the address found. */
  412. return (end == 0) ? 0 : sorted_table + middle;
  413. }
  414. /**
  415. * @brief Decode an address according to the encoding passed.
  416. *
  417. * @param addr Pointer to the address to decode.
  418. * This pointer's value MUST be an address in .eh_frame_hdr section.
  419. * @param encoding DWARF encoding byte.
  420. *
  421. * @return address dedoded (e.g. absolute address)
  422. */
  423. static inline uint32_t* esp_eh_frame_decode_address(const uint32_t* addr,
  424. const uint32_t encoding)
  425. {
  426. uint32_t* decoded = 0;
  427. if (ESP_ENCODING_FRAME_HDR_REL(encoding))
  428. decoded = (uint32_t*) (*addr + (uint32_t) EH_FRAME_HDR_ADDR);
  429. else if (ESP_ENCODING_PC_REL(encoding))
  430. decoded = (uint32_t*) (*addr + (uint32_t) addr);
  431. else
  432. decoded = (uint32_t*) (*addr);
  433. return decoded;
  434. }
  435. /**
  436. * @brief Execute the DWARF instruction which high 2 bits are 0.
  437. *
  438. * @param opcode low 6 bits of the instruction code.
  439. * @param operands pointer to the possible operands.
  440. * @param state state of the DWARF machine. Its registers may be modified.
  441. *
  442. * @return Number of operands used for executing the instruction.
  443. */
  444. static inline uint32_t esp_eh_frame_execute_opcode_0(const uint32_t opcode, const uint8_t* operands,
  445. dwarf_regs* state)
  446. {
  447. uint32_t operand1 = 0;
  448. uint32_t used_operands = 0;
  449. uint32_t operand2 = 0;
  450. uint32_t used_operands2 = 0;
  451. switch(opcode) {
  452. case DW_CFA_NOP:
  453. break;
  454. case DW_CFA_ADVANCE_LOC1:
  455. /* Advance location with a 1-byte delta. */
  456. used_operands = 1;
  457. state->location += *operands;
  458. break;
  459. case DW_CFA_ADVANCE_LOC2:
  460. /* Advance location with a 2-byte delta. */
  461. used_operands = 2;
  462. state->location += *((const uint16_t*) operands);
  463. break;
  464. case DW_CFA_ADVANCE_LOC4:
  465. /* Advance location with a 4-byte delta. */
  466. used_operands = 4;
  467. state->location += *((const uint32_t*) operands);
  468. break;
  469. case DW_CFA_REMEMBER_STATE:
  470. assert(state->offset_idx == 0);
  471. memcpy(state->regs_offset[1], state->regs_offset[0],
  472. EXECUTION_FRAME_MAX_REGS * sizeof(uint32_t));
  473. state->offset_idx++;
  474. break;
  475. case DW_CFA_RESTORE_STATE:
  476. assert(state->offset_idx == 1);
  477. /* Drop the saved state. */
  478. state->offset_idx--;
  479. break;
  480. case DW_CFA_DEF_CFA:
  481. /* CFA changes according to a register and an offset.
  482. * This instruction appears when the assembly code saves the
  483. * SP in the middle of a routine, before modifying it.
  484. * For example (on RISC-V):
  485. * addi s0, sp, 80
  486. * addi sp, sp, -10
  487. * ... */
  488. /* Operand1 is the register containing the CFA value. */
  489. operand1 = decode_leb128(operands, false, &used_operands);
  490. /* Offset for the register's value. */
  491. operand2 = decode_leb128(operands + used_operands, false, &used_operands2);
  492. /* Calculate the number of bytes */
  493. used_operands += used_operands2;
  494. /* Assert that the register and the offset are valid. */
  495. assert(ESP_EH_FRAME_CFA_REG_VALID(operand1));
  496. assert(ESP_EH_FRAME_CFA_OFF_VALID(operand2));
  497. ESP_EH_FRAME_CFA(state) = ESP_EH_FRAME_NEW_CFA(operand1, operand2);
  498. break;
  499. case DW_CFA_DEF_CFA_REGISTER:
  500. /* Define the register of the current frame address (CFA).
  501. * Its operand is in the next bytes, its type is ULEB128. */
  502. operand1 = decode_leb128(operands, false, &used_operands);
  503. /* Check whether the value is valid or not. */
  504. assert(ESP_EH_FRAME_CFA_OFF_VALID(operand1));
  505. /* Offset will be unchanged, only register changes. */
  506. ESP_EH_FRAME_CFA(state) = ESP_EH_FRAME_SET_CFA_REG(ESP_EH_FRAME_CFA(state), operand1);
  507. break;
  508. case DW_CFA_DEF_CFA_OFFSET:
  509. /* Same as above but for the offset. The register of CFA remains unchanged. */
  510. operand1 = decode_leb128(operands, false, &used_operands);
  511. assert(ESP_EH_FRAME_CFA_OFF_VALID(operand1));
  512. ESP_EH_FRAME_CFA(state) = ESP_EH_FRAME_SET_CFA_OFF(ESP_EH_FRAME_CFA(state), operand1);
  513. break;
  514. default:
  515. panic_print_str("\r\nUnsupported DWARF opcode 0: 0x");
  516. panic_print_hex(opcode);
  517. panic_print_str("\r\n");
  518. used_operands = ESP_EH_FRAME_UNSUPPORTED_OPCODE;
  519. break;
  520. }
  521. return used_operands;
  522. }
  523. /**
  524. * @brief Execute DWARF instructions.
  525. *
  526. * @param instructions Array of instructions to execute.
  527. * @param instructions_length Length of the array of instructions.
  528. * @param frame Execution frame of the crashed task. This will only be used to
  529. * get the PC where the task crashed.
  530. * @param state DWARF machine state. The registers contained in the state will
  531. * modified accordingly to the instructions.
  532. *
  533. * @return true if the execution went fine, false if an unsupported instruction was met.
  534. */
  535. static bool esp_eh_frame_execute(const uint8_t* instructions, const uint32_t instructions_length,
  536. const ExecutionFrame* frame, dwarf_regs* state)
  537. {
  538. for (uint32_t i = 0; i < instructions_length; i++) {
  539. const uint8_t instr = instructions[i];
  540. const uint8_t param = DW_GET_PARAM(instr);
  541. uint32_t operand1 = 0;
  542. uint32_t size = 0;
  543. uint32_t used_operands = 0;
  544. /* Decode the instructions. According to DWARF documentation, there are three
  545. * types of Call Frame Instructions. The upper 2 bits defines the type. */
  546. switch (DW_GET_OPCODE(instr)) {
  547. case DW_CFA_0_OPCODE:
  548. used_operands = esp_eh_frame_execute_opcode_0(param, &instructions[i + 1], state);
  549. /* Exit the function if an unsupported opcode was met. */
  550. if (used_operands == ESP_EH_FRAME_UNSUPPORTED_OPCODE) {
  551. return false;
  552. }
  553. i += used_operands;
  554. break;
  555. case DW_CFA_ADVANCE_LOC:
  556. /* Move the location forward. This instruction will mark when to stop:
  557. * once we reach the instruction where the PC left, we can break out of the loop
  558. * The delta is part of the lowest 6 bits.
  559. */
  560. state->location += param;
  561. break;
  562. case DW_CFA_OFFSET:
  563. operand1 = decode_leb128(&instructions[i + 1], false, &size);
  564. assert(ESP_EH_FRAME_CFA_OFFSET_VALID(operand1));
  565. state->regs_offset[state->offset_idx][param] = ESP_EH_FRAME_SET_REG_OFFSET(operand1);
  566. i += size;
  567. break;
  568. case DW_CFA_RESTORE:
  569. state->regs_offset[state->offset_idx][param] = ESP_EH_FRAME_REG_SAME;
  570. break;
  571. default:
  572. /* Illegal opcode */
  573. assert(false);
  574. break;
  575. }
  576. /* As the state->location can also be modified by 0-opcode instructions (in the function)
  577. * and also because we need to break the loop (and not only the switch), let's put this
  578. * check here, after the execution of the instruction, outside of the switch block. */
  579. if (state->location >= EXECUTION_FRAME_PC(*frame))
  580. break;
  581. }
  582. /* Everything went fine, no unsupported opcode was met, return true. */
  583. return true;
  584. }
  585. /**
  586. * @brief Initialize the DWARF registers state by parsing and executing CIE instructions.
  587. *
  588. * @param cie Pointer to the CIE data.
  589. * @param frame Pointer to the execution frame.
  590. * @param state DWARF machine state (DWARF registers).
  591. *
  592. * @return index of the DWARF register containing the return address.
  593. */
  594. static uint32_t esp_eh_frame_initialize_state(const uint8_t* cie, ExecutionFrame* frame, dwarf_regs* state)
  595. {
  596. char c = 0;
  597. uint32_t size = 0;
  598. /* The first word in the CIE structure is the length of the structure,
  599. * excluding this field itself. */
  600. const uint32_t length = ((uint32_t*) cie)[0];
  601. /* ID of the CIE, should be 0 for .eh_frame (which is our case) */
  602. const uint32_t id = ((uint32_t*) cie)[1];
  603. assert(id == 0);
  604. /* Ignore CIE version (1 byte). */
  605. /* The following data in the structure have variable length as they are
  606. * encoded in (U)LEB128. Thus, let's use a byte pointer to parse them. */
  607. uint8_t* cie_data = (uint8_t*) cie + ESP_CIE_VARIABLE_FIELDS_IDX;
  608. /* Next field is a null-terminated UTF-8 string. Ignore it, look for the end. */
  609. while((c = *cie_data++) != 0);
  610. /* Field alignment factor shall be 1. It is encoded in ULEB128. */
  611. const uint32_t code_align = decode_leb128(cie_data, false, &size);
  612. assert(code_align == 1);
  613. /* Jump to the next field */
  614. cie_data += size;
  615. /* Same goes for data alignment factor. Shall be equal to -4. */
  616. const int32_t data_align = decode_leb128(cie_data, true, &size);
  617. cie_data += size;
  618. assert(data_align == -4);
  619. /* Field describing the index of the DWARF register which will contain
  620. * the return address. */
  621. const uint32_t ra_reg = decode_leb128(cie_data, false, &size);
  622. cie_data += size;
  623. /* Augmentation data length is encoded in ULEB128. It represents the,
  624. * length of the augmentation data. Jump after it to retrieve the
  625. * instructions to execute. */
  626. const uint32_t augmentation_len = decode_leb128(cie_data, false, &size);
  627. cie_data += size + augmentation_len;
  628. /* Calculate the instructions length in order to prevent any out of bounds
  629. * bug. Subtract the offset of this field (minus sizeof(uint32_t) because
  630. * `length` field is not part of the structure length) to the total length
  631. * of the structure. */
  632. const uint32_t instructions_length = length - (cie_data - sizeof(uint32_t) - cie);
  633. /* Execute the instructions contained in CIE structure. Their goal is to
  634. * initialize the DWARF registers. Usually it binds the CFA (virtual stack
  635. * pointer), to its hardware equivalent. It will also bind a hardware
  636. * register to the virtual return address register. For example, x86
  637. * doesn't have a return address register, the address to return to
  638. * it stored on the stack when `call` instruction is used. DWARF will
  639. * use `eip` (instruction pointer, a.k.a. program counter) as a
  640. * register containing the return address register. */
  641. esp_eh_frame_execute(cie_data, instructions_length, frame, state);
  642. return ra_reg;
  643. }
  644. /**
  645. * @brief Modify the execution frame and DWARF VM state for restoring caller's context.
  646. *
  647. * @param fde Pointer to the Frame Description Entry for the current program counter (defined by frame's MEPC register)
  648. * @param frame Snapshot of the CPU registers when the CPU stopped its normal execution.
  649. * @param state DWARF VM registers.
  650. *
  651. * @return Return Address of the current context. Frame has been restored to the previous context
  652. * (before calling the function program counter is currently going throught).
  653. */
  654. static uint32_t esp_eh_frame_restore_caller_state(const uint32_t* fde,
  655. ExecutionFrame* frame,
  656. dwarf_regs* state)
  657. {
  658. /* Length of the whole Frame Description Entry (FDE), excluding this field. */
  659. const uint32_t length = fde[ESP_FDE_LENGTH_IDX];
  660. /* The addresses in FDE are relative to the location of each field.
  661. * Thus, to get the absolute address of the function it is pointing to,
  662. * we have to compute:
  663. * fun_addr = &fde[IDX] +/- fde[IDX]
  664. */
  665. const uint8_t* cie = (uint8_t*) ((uint32_t) &fde[ESP_FDE_CIE_IDX] - fde[ESP_FDE_CIE_IDX]);
  666. const uint32_t initial_location = ((uint32_t) &fde[ESP_FDE_INITLOC_IDX] + fde[ESP_FDE_INITLOC_IDX]);
  667. const uint32_t range_length = fde[ESP_FDE_RANGELEN_IDX];
  668. const uint8_t augmentation = *((uint8_t*) (fde + ESP_FDE_AUGMENTATION_IDX));
  669. /* The length, in byte, of the instructions is the size of the FDE header minus
  670. * the above fields' length. */
  671. const uint32_t instructions_length = length - 3 * sizeof(uint32_t) - sizeof(uint8_t);
  672. const uint8_t* instructions = ((uint8_t*) (fde + ESP_FDE_AUGMENTATION_IDX)) + 1;
  673. /* Make sure this FDE is the correct one for the PC given. */
  674. assert(initial_location <= EXECUTION_FRAME_PC(*frame) &&
  675. EXECUTION_FRAME_PC(*frame) < initial_location + range_length);
  676. /* Augmentation not supported. */
  677. assert(augmentation == 0);
  678. /* Initialize the DWARF state by executing the CIE's instructions. */
  679. const uint32_t ra_reg = esp_eh_frame_initialize_state(cie, frame, state);
  680. state->location = initial_location;
  681. /**
  682. * Execute the DWARf instructions is order to create rules that will be executed later to retrieve
  683. * the registers former value.
  684. */
  685. bool success = esp_eh_frame_execute(instructions, instructions_length, frame, state);
  686. if (!success) {
  687. /* An error occured (unsupported opcode), return PC as the return address.
  688. * This will be tested by the caller, and the backtrace will be finished. */
  689. return EXECUTION_FRAME_PC(*frame);
  690. }
  691. /* Execute the rules calculated previously. Start with the CFA. */
  692. const uint32_t cfa_val = ESP_EH_FRAME_CFA(state);
  693. const uint32_t cfa_reg = ESP_EH_FRAME_GET_CFA_REG(cfa_val);
  694. const uint32_t cfa_off = ESP_EH_FRAME_GET_CFA_OFF(cfa_val);
  695. const uint32_t cfa_addr = EXECUTION_FRAME_REG(frame, cfa_reg) + cfa_off;
  696. /* Restore the registers that need to be restored. */
  697. for (uint32_t i = 0; i < DIM(state->regs_offset[0]); i++) {
  698. uint32_t value_addr = state->regs_offset[state->offset_idx][i];
  699. /* Check that the value changed and that we are not treating the CFA register (if it is part of the array). */
  700. if (i != ESP_ESH_FRAME_CFA_IDX && value_addr != ESP_EH_FRAME_REG_SAME) {
  701. /* value_addr contains a description of how to find its address:
  702. * it has an offset relative to the CFA, which will point to the actual former value.
  703. * In fact, the register's previous value (in the context of the caller) is on the stack,
  704. * this is what value_addr will point to. */
  705. value_addr = cfa_addr - ESP_EH_FRAME_GET_REG_OFFSET(value_addr) * sizeof(uint32_t);
  706. EXECUTION_FRAME_REG(frame, i) = *((uint32_t*) value_addr);
  707. }
  708. }
  709. /* Restore the stack pointer according to DWARF CFA register. */
  710. EXECUTION_FRAME_SP(*frame) = cfa_addr;
  711. /* If the frame was not available, it would be possible to retrieve the return address
  712. * register thanks to CIE structure.
  713. * The return address points to the address the PC needs to jump to. It
  714. * does NOT point to the instruction where the routine call occured.
  715. * This can cause problems with functions without epilogue (i.e. function
  716. * which last instruction is a function call). This happens when compiler
  717. * optimization are ON or when a function is marked as "noreturn".
  718. *
  719. * Thus, in order to point to the call/jal instruction, we need to
  720. * subtract at least 1 byte but not more than an instruction size.
  721. */
  722. return EXECUTION_FRAME_REG(frame, ra_reg) - 2;
  723. }
  724. /**
  725. * @brief Test whether the DWARF information for the given PC are missing or not.
  726. *
  727. * @param fde FDE associated to this PC. This FDE is the one found thanks to
  728. * `esp_eh_frame_find_entry()`.
  729. * @param pc PC to get information from.
  730. *
  731. * @return true is DWARF information are missing, false else.
  732. */
  733. static bool esp_eh_frame_missing_info(const uint32_t* fde, uint32_t pc) {
  734. if (fde == NULL) {
  735. return true;
  736. }
  737. /* Get the range of this FDE entry. It is possible that there are some
  738. * gaps between DWARF entries, in that case, the FDE entry found has
  739. * indeed an initial_location very close to PC but doesn't reach it.
  740. * For example, if FDE initial_location is 0x40300000 and its length is
  741. * 0x100, but PC value is 0x40300200, then some DWARF information
  742. * are missing as there is a gap.
  743. * End the backtrace. */
  744. const uint32_t initial_location = ((uint32_t) &fde[ESP_FDE_INITLOC_IDX] + fde[ESP_FDE_INITLOC_IDX]);
  745. const uint32_t range_length = fde[ESP_FDE_RANGELEN_IDX];
  746. return (initial_location + range_length) <= pc;
  747. }
  748. /**
  749. * @brief When one step of the backtrace is generated, output it to the serial.
  750. * This function can be overriden as it is defined as weak.
  751. *
  752. * @param pc Program counter of the backtrace step.
  753. * @param sp Stack pointer of the backtrace step.
  754. */
  755. void __attribute__((weak)) esp_eh_frame_generated_step(uint32_t pc, uint32_t sp)
  756. {
  757. panic_print_str(" 0x");
  758. panic_print_hex(pc);
  759. panic_print_str(":0x");
  760. panic_print_hex(sp);
  761. }
  762. /**
  763. * @brief Print backtrace for the given execution frame.
  764. *
  765. * @param frame_or Snapshot of the CPU registers when the CPU stopped its normal execution.
  766. */
  767. void esp_eh_frame_print_backtrace(const void *frame_or)
  768. {
  769. assert(frame_or != NULL);
  770. static dwarf_regs state = { 0 };
  771. ExecutionFrame frame = *((ExecutionFrame*) frame_or);
  772. uint32_t size = 0;
  773. uint8_t* enc_values = NULL;
  774. bool end_of_backtrace = false;
  775. /* Start parsing the .eh_frame_hdr section. */
  776. fde_header* header = (fde_header*) EH_FRAME_HDR_ADDR;
  777. assert(header->version == 1);
  778. /* Make enc_values point to the end of the structure, where the encoded
  779. * values start. */
  780. enc_values = (uint8_t*) (header + 1);
  781. /* Retrieve the encoded value eh_frame_ptr. Get the size of the data also. */
  782. const uint32_t eh_frame_ptr = esp_eh_frame_get_encoded(enc_values, header->eh_frame_ptr_enc, &size);
  783. assert(eh_frame_ptr == (uint32_t) EH_FRAME_ADDR);
  784. enc_values += size;
  785. /* Same for the number of entries in the sorted table. */
  786. const uint32_t fde_count = esp_eh_frame_get_encoded(enc_values, header->fde_count_enc, &size);
  787. enc_values += size;
  788. /* enc_values points now at the beginning of the sorted table. */
  789. /* Only support 4-byte entries. */
  790. const uint32_t table_enc = header->table_enc;
  791. assert(((table_enc >> 4) == 0x3) || ((table_enc >> 4) == 0xB));
  792. const table_entry* sorted_table = (const table_entry*) enc_values;
  793. panic_print_str("Backtrace:");
  794. while (!end_of_backtrace) {
  795. /* Output one step of the backtrace. */
  796. esp_eh_frame_generated_step(EXECUTION_FRAME_PC(frame), EXECUTION_FRAME_SP(frame));
  797. const table_entry* from_fun = esp_eh_frame_find_entry(sorted_table, fde_count,
  798. table_enc, EXECUTION_FRAME_PC(frame));
  799. /* Get absolute address of FDE entry describing the function where PC left of. */
  800. uint32_t* fde = NULL;
  801. if (from_fun != NULL) {
  802. fde = esp_eh_frame_decode_address(&from_fun->fde_addr, table_enc);
  803. }
  804. if (esp_eh_frame_missing_info(fde, EXECUTION_FRAME_PC(frame))) {
  805. /* Address was not found in the list. */
  806. panic_print_str("\r\nBacktrace ended abruptly: cannot find DWARF information for"
  807. " instruction at address 0x");
  808. panic_print_hex(EXECUTION_FRAME_PC(frame));
  809. panic_print_str("\r\n");
  810. break;
  811. }
  812. /* Clean and set the DWARF register structure. */
  813. memset(&state, 0, sizeof(dwarf_regs));
  814. const uint32_t prev_sp = EXECUTION_FRAME_SP(frame);
  815. /* Retrieve the return address of the frame. The frame's registers will be modified.
  816. * The frame we get then is the caller's one. */
  817. uint32_t ra = esp_eh_frame_restore_caller_state(fde, &frame, &state);
  818. /* End of backtrace is reached if the stack and the PC don't change anymore. */
  819. end_of_backtrace = (EXECUTION_FRAME_SP(frame) == prev_sp) && (EXECUTION_FRAME_PC(frame) == ra);
  820. /* Go back to the caller: update stack pointer and program counter. */
  821. EXECUTION_FRAME_PC(frame) = ra;
  822. }
  823. panic_print_str("\r\n");
  824. }
  825. /**
  826. * The following functions are the implementation of libunwind API
  827. * Check the header libunwind.h for more information
  828. */
  829. int unw_init_local(unw_cursor_t* c, unw_context_t* ctxt) {
  830. /* In our implementation, a context and a cursor is the same, so we simply need
  831. * to copy a structure inside another one */
  832. _Static_assert(sizeof(unw_cursor_t) >= sizeof(unw_context_t), "unw_cursor_t size must be greater or equal to unw_context_t's");
  833. int ret = -UNW_EUNSPEC;
  834. if (c != NULL && ctxt != NULL) {
  835. memcpy(c, ctxt, sizeof(unw_context_t));
  836. ret = UNW_ESUCCESS;
  837. }
  838. return ret;
  839. }
  840. int unw_step(unw_cursor_t* cp) {
  841. static dwarf_regs state = { 0 };
  842. ExecutionFrame* frame = (ExecutionFrame*) cp;
  843. uint32_t size = 0;
  844. uint8_t* enc_values = NULL;
  845. /* Start parsing the .eh_frame_hdr section. */
  846. fde_header* header = (fde_header*) EH_FRAME_HDR_ADDR;
  847. if (header->version != 1) {
  848. goto badversion;
  849. }
  850. /* Make enc_values point to the end of the structure, where the encoded
  851. * values start. */
  852. enc_values = (uint8_t*) (header + 1);
  853. /* Retrieve the encoded value eh_frame_ptr. Get the size of the data also. */
  854. const uint32_t eh_frame_ptr = esp_eh_frame_get_encoded(enc_values, header->eh_frame_ptr_enc, &size);
  855. assert(eh_frame_ptr == (uint32_t) EH_FRAME_ADDR);
  856. enc_values += size;
  857. /* Same for the number of entries in the sorted table. */
  858. const uint32_t fde_count = esp_eh_frame_get_encoded(enc_values, header->fde_count_enc, &size);
  859. enc_values += size;
  860. /* enc_values points now at the beginning of the sorted table. */
  861. /* Only support 4-byte entries. */
  862. const uint32_t table_enc = header->table_enc;
  863. if ( ((table_enc >> 4) != 0x3) && ((table_enc >> 4) != 0xB) ) {
  864. goto badversion;
  865. }
  866. const table_entry* sorted_table = (const table_entry*) enc_values;
  867. const table_entry* from_fun = esp_eh_frame_find_entry(sorted_table, fde_count,
  868. table_enc, EXECUTION_FRAME_PC(*frame));
  869. /* Get absolute address of FDE entry describing the function where PC left of. */
  870. uint32_t* fde = NULL;
  871. if (from_fun != NULL) {
  872. fde = esp_eh_frame_decode_address(&from_fun->fde_addr, table_enc);
  873. }
  874. if (esp_eh_frame_missing_info(fde, EXECUTION_FRAME_PC(*frame))) {
  875. goto missinginfo;
  876. }
  877. const uint32_t prev_sp = EXECUTION_FRAME_SP(*frame);
  878. /* Retrieve the return address of the frame. The frame's registers will be modified.
  879. * The frame we get then is the caller's one. */
  880. uint32_t ra = esp_eh_frame_restore_caller_state(fde, frame, &state);
  881. /* End of backtrace is reached if the stack and the PC don't change anymore. */
  882. if ((EXECUTION_FRAME_SP(*frame) == prev_sp) && (EXECUTION_FRAME_PC(*frame) == ra)) {
  883. goto stopunwind;
  884. }
  885. /* Go back to the caller: update stack pointer and program counter. */
  886. EXECUTION_FRAME_PC(*frame) = ra;
  887. return 1;
  888. badversion:
  889. return -UNW_EBADVERSION;
  890. missinginfo:
  891. return -UNW_ENOINFO;
  892. stopunwind:
  893. return 0;
  894. }
  895. int unw_get_reg(unw_cursor_t* cp, unw_regnum_t reg, unw_word_t* valp) {
  896. if (cp == NULL || valp == NULL) {
  897. goto invalid;
  898. }
  899. if (reg >= EXECUTION_FRAME_MAX_REGS) {
  900. goto badreg;
  901. }
  902. *valp = EXECUTION_FRAME_REG(cp, reg);
  903. return UNW_ESUCCESS;
  904. invalid:
  905. return -UNW_EUNSPEC;
  906. badreg:
  907. return -UNW_EBADREG;
  908. }
  909. int unw_set_reg(unw_cursor_t* cp, unw_regnum_t reg, unw_word_t val) {
  910. if (cp == NULL) {
  911. goto invalid;
  912. }
  913. if (reg >= EXECUTION_FRAME_MAX_REGS) {
  914. goto badreg;
  915. }
  916. EXECUTION_FRAME_REG(cp, reg) = val;
  917. return UNW_ESUCCESS;
  918. invalid:
  919. return -UNW_EUNSPEC;
  920. badreg:
  921. return -UNW_EBADREG;
  922. }
  923. #endif //ESP_SYSTEM_USE_EH_FRAME