unwind.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313
  1. /*
  2. * Copyright (C) 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  3. * Copyright (C) 2002-2006 Novell, Inc.
  4. * Jan Beulich <jbeulich@novell.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * A simple API for unwinding kernel stacks. This is used for
  11. * debugging and error reporting purposes. The kernel doesn't need
  12. * full-blown stack unwinding with all the bells and whistles, so there
  13. * is not much point in implementing the full Dwarf2 unwind API.
  14. */
  15. #include <linux/sched.h>
  16. #include <linux/module.h>
  17. #include <linux/bootmem.h>
  18. #include <linux/sort.h>
  19. #include <linux/slab.h>
  20. #include <linux/stop_machine.h>
  21. #include <linux/uaccess.h>
  22. #include <linux/ptrace.h>
  23. #include <asm/sections.h>
  24. #include <asm/unaligned.h>
  25. #include <asm/unwind.h>
  26. extern char __start_unwind[], __end_unwind[];
  27. /* extern const u8 __start_unwind_hdr[], __end_unwind_hdr[];*/
  28. /* #define UNWIND_DEBUG */
  29. #ifdef UNWIND_DEBUG
  30. int dbg_unw;
  31. #define unw_debug(fmt, ...) \
  32. do { \
  33. if (dbg_unw) \
  34. pr_info(fmt, ##__VA_ARGS__); \
  35. } while (0);
  36. #else
  37. #define unw_debug(fmt, ...)
  38. #endif
  39. #define MAX_STACK_DEPTH 8
  40. #define EXTRA_INFO(f) { \
  41. BUILD_BUG_ON_ZERO(offsetof(struct unwind_frame_info, f) \
  42. % FIELD_SIZEOF(struct unwind_frame_info, f)) \
  43. + offsetof(struct unwind_frame_info, f) \
  44. / FIELD_SIZEOF(struct unwind_frame_info, f), \
  45. FIELD_SIZEOF(struct unwind_frame_info, f) \
  46. }
  47. #define PTREGS_INFO(f) EXTRA_INFO(regs.f)
  48. static const struct {
  49. unsigned offs:BITS_PER_LONG / 2;
  50. unsigned width:BITS_PER_LONG / 2;
  51. } reg_info[] = {
  52. UNW_REGISTER_INFO};
  53. #undef PTREGS_INFO
  54. #undef EXTRA_INFO
  55. #ifndef REG_INVALID
  56. #define REG_INVALID(r) (reg_info[r].width == 0)
  57. #endif
  58. #define DW_CFA_nop 0x00
  59. #define DW_CFA_set_loc 0x01
  60. #define DW_CFA_advance_loc1 0x02
  61. #define DW_CFA_advance_loc2 0x03
  62. #define DW_CFA_advance_loc4 0x04
  63. #define DW_CFA_offset_extended 0x05
  64. #define DW_CFA_restore_extended 0x06
  65. #define DW_CFA_undefined 0x07
  66. #define DW_CFA_same_value 0x08
  67. #define DW_CFA_register 0x09
  68. #define DW_CFA_remember_state 0x0a
  69. #define DW_CFA_restore_state 0x0b
  70. #define DW_CFA_def_cfa 0x0c
  71. #define DW_CFA_def_cfa_register 0x0d
  72. #define DW_CFA_def_cfa_offset 0x0e
  73. #define DW_CFA_def_cfa_expression 0x0f
  74. #define DW_CFA_expression 0x10
  75. #define DW_CFA_offset_extended_sf 0x11
  76. #define DW_CFA_def_cfa_sf 0x12
  77. #define DW_CFA_def_cfa_offset_sf 0x13
  78. #define DW_CFA_val_offset 0x14
  79. #define DW_CFA_val_offset_sf 0x15
  80. #define DW_CFA_val_expression 0x16
  81. #define DW_CFA_lo_user 0x1c
  82. #define DW_CFA_GNU_window_save 0x2d
  83. #define DW_CFA_GNU_args_size 0x2e
  84. #define DW_CFA_GNU_negative_offset_extended 0x2f
  85. #define DW_CFA_hi_user 0x3f
  86. #define DW_EH_PE_FORM 0x07
  87. #define DW_EH_PE_native 0x00
  88. #define DW_EH_PE_leb128 0x01
  89. #define DW_EH_PE_data2 0x02
  90. #define DW_EH_PE_data4 0x03
  91. #define DW_EH_PE_data8 0x04
  92. #define DW_EH_PE_signed 0x08
  93. #define DW_EH_PE_ADJUST 0x70
  94. #define DW_EH_PE_abs 0x00
  95. #define DW_EH_PE_pcrel 0x10
  96. #define DW_EH_PE_textrel 0x20
  97. #define DW_EH_PE_datarel 0x30
  98. #define DW_EH_PE_funcrel 0x40
  99. #define DW_EH_PE_aligned 0x50
  100. #define DW_EH_PE_indirect 0x80
  101. #define DW_EH_PE_omit 0xff
  102. typedef unsigned long uleb128_t;
  103. typedef signed long sleb128_t;
  104. static struct unwind_table {
  105. struct {
  106. unsigned long pc;
  107. unsigned long range;
  108. } core, init;
  109. const void *address;
  110. unsigned long size;
  111. const unsigned char *header;
  112. unsigned long hdrsz;
  113. struct unwind_table *link;
  114. const char *name;
  115. } root_table;
  116. struct unwind_item {
  117. enum item_location {
  118. Nowhere,
  119. Memory,
  120. Register,
  121. Value
  122. } where;
  123. uleb128_t value;
  124. };
  125. struct unwind_state {
  126. uleb128_t loc, org;
  127. const u8 *cieStart, *cieEnd;
  128. uleb128_t codeAlign;
  129. sleb128_t dataAlign;
  130. struct cfa {
  131. uleb128_t reg, offs;
  132. } cfa;
  133. struct unwind_item regs[ARRAY_SIZE(reg_info)];
  134. unsigned stackDepth:8;
  135. unsigned version:8;
  136. const u8 *label;
  137. const u8 *stack[MAX_STACK_DEPTH];
  138. };
  139. static const struct cfa badCFA = { ARRAY_SIZE(reg_info), 1 };
  140. static struct unwind_table *find_table(unsigned long pc)
  141. {
  142. struct unwind_table *table;
  143. for (table = &root_table; table; table = table->link)
  144. if ((pc >= table->core.pc
  145. && pc < table->core.pc + table->core.range)
  146. || (pc >= table->init.pc
  147. && pc < table->init.pc + table->init.range))
  148. break;
  149. return table;
  150. }
  151. static unsigned long read_pointer(const u8 **pLoc,
  152. const void *end, signed ptrType);
  153. static void init_unwind_hdr(struct unwind_table *table,
  154. void *(*alloc) (unsigned long));
  155. /*
  156. * wrappers for header alloc (vs. calling one vs. other at call site)
  157. * to elide section mismatches warnings
  158. */
  159. static void *__init unw_hdr_alloc_early(unsigned long sz)
  160. {
  161. return __alloc_bootmem_nopanic(sz, sizeof(unsigned int),
  162. MAX_DMA_ADDRESS);
  163. }
  164. static void *unw_hdr_alloc(unsigned long sz)
  165. {
  166. return kmalloc(sz, GFP_KERNEL);
  167. }
  168. static void init_unwind_table(struct unwind_table *table, const char *name,
  169. const void *core_start, unsigned long core_size,
  170. const void *init_start, unsigned long init_size,
  171. const void *table_start, unsigned long table_size,
  172. const u8 *header_start, unsigned long header_size)
  173. {
  174. const u8 *ptr = header_start + 4;
  175. const u8 *end = header_start + header_size;
  176. table->core.pc = (unsigned long)core_start;
  177. table->core.range = core_size;
  178. table->init.pc = (unsigned long)init_start;
  179. table->init.range = init_size;
  180. table->address = table_start;
  181. table->size = table_size;
  182. /* See if the linker provided table looks valid. */
  183. if (header_size <= 4
  184. || header_start[0] != 1
  185. || (void *)read_pointer(&ptr, end, header_start[1]) != table_start
  186. || header_start[2] == DW_EH_PE_omit
  187. || read_pointer(&ptr, end, header_start[2]) <= 0
  188. || header_start[3] == DW_EH_PE_omit)
  189. header_start = NULL;
  190. table->hdrsz = header_size;
  191. smp_wmb();
  192. table->header = header_start;
  193. table->link = NULL;
  194. table->name = name;
  195. }
  196. void __init arc_unwind_init(void)
  197. {
  198. init_unwind_table(&root_table, "kernel", _text, _end - _text, NULL, 0,
  199. __start_unwind, __end_unwind - __start_unwind,
  200. NULL, 0);
  201. /*__start_unwind_hdr, __end_unwind_hdr - __start_unwind_hdr);*/
  202. init_unwind_hdr(&root_table, unw_hdr_alloc_early);
  203. }
  204. static const u32 bad_cie, not_fde;
  205. static const u32 *cie_for_fde(const u32 *fde, const struct unwind_table *);
  206. static signed fde_pointer_type(const u32 *cie);
  207. struct eh_frame_hdr_table_entry {
  208. unsigned long start, fde;
  209. };
  210. static int cmp_eh_frame_hdr_table_entries(const void *p1, const void *p2)
  211. {
  212. const struct eh_frame_hdr_table_entry *e1 = p1;
  213. const struct eh_frame_hdr_table_entry *e2 = p2;
  214. return (e1->start > e2->start) - (e1->start < e2->start);
  215. }
  216. static void swap_eh_frame_hdr_table_entries(void *p1, void *p2, int size)
  217. {
  218. struct eh_frame_hdr_table_entry *e1 = p1;
  219. struct eh_frame_hdr_table_entry *e2 = p2;
  220. unsigned long v;
  221. v = e1->start;
  222. e1->start = e2->start;
  223. e2->start = v;
  224. v = e1->fde;
  225. e1->fde = e2->fde;
  226. e2->fde = v;
  227. }
  228. static void init_unwind_hdr(struct unwind_table *table,
  229. void *(*alloc) (unsigned long))
  230. {
  231. const u8 *ptr;
  232. unsigned long tableSize = table->size, hdrSize;
  233. unsigned n;
  234. const u32 *fde;
  235. struct {
  236. u8 version;
  237. u8 eh_frame_ptr_enc;
  238. u8 fde_count_enc;
  239. u8 table_enc;
  240. unsigned long eh_frame_ptr;
  241. unsigned int fde_count;
  242. struct eh_frame_hdr_table_entry table[];
  243. } __attribute__ ((__packed__)) *header;
  244. if (table->header)
  245. return;
  246. if (table->hdrsz)
  247. pr_warn(".eh_frame_hdr for '%s' present but unusable\n",
  248. table->name);
  249. if (tableSize & (sizeof(*fde) - 1))
  250. return;
  251. for (fde = table->address, n = 0;
  252. tableSize > sizeof(*fde) && tableSize - sizeof(*fde) >= *fde;
  253. tableSize -= sizeof(*fde) + *fde, fde += 1 + *fde / sizeof(*fde)) {
  254. const u32 *cie = cie_for_fde(fde, table);
  255. signed ptrType;
  256. if (cie == &not_fde)
  257. continue;
  258. if (cie == NULL || cie == &bad_cie)
  259. goto ret_err;
  260. ptrType = fde_pointer_type(cie);
  261. if (ptrType < 0)
  262. goto ret_err;
  263. ptr = (const u8 *)(fde + 2);
  264. if (!read_pointer(&ptr, (const u8 *)(fde + 1) + *fde,
  265. ptrType)) {
  266. /* FIXME_Rajesh We have 4 instances of null addresses
  267. * instead of the initial loc addr
  268. * return;
  269. */
  270. WARN(1, "unwinder: FDE->initial_location NULL %p\n",
  271. (const u8 *)(fde + 1) + *fde);
  272. }
  273. ++n;
  274. }
  275. if (tableSize || !n)
  276. goto ret_err;
  277. hdrSize = 4 + sizeof(unsigned long) + sizeof(unsigned int)
  278. + 2 * n * sizeof(unsigned long);
  279. header = alloc(hdrSize);
  280. if (!header)
  281. goto ret_err;
  282. header->version = 1;
  283. header->eh_frame_ptr_enc = DW_EH_PE_abs | DW_EH_PE_native;
  284. header->fde_count_enc = DW_EH_PE_abs | DW_EH_PE_data4;
  285. header->table_enc = DW_EH_PE_abs | DW_EH_PE_native;
  286. put_unaligned((unsigned long)table->address, &header->eh_frame_ptr);
  287. BUILD_BUG_ON(offsetof(typeof(*header), fde_count)
  288. % __alignof(typeof(header->fde_count)));
  289. header->fde_count = n;
  290. BUILD_BUG_ON(offsetof(typeof(*header), table)
  291. % __alignof(typeof(*header->table)));
  292. for (fde = table->address, tableSize = table->size, n = 0;
  293. tableSize;
  294. tableSize -= sizeof(*fde) + *fde, fde += 1 + *fde / sizeof(*fde)) {
  295. /* const u32 *cie = fde + 1 - fde[1] / sizeof(*fde); */
  296. const u32 *cie = (const u32 *)(fde[1]);
  297. if (fde[1] == 0xffffffff)
  298. continue; /* this is a CIE */
  299. ptr = (const u8 *)(fde + 2);
  300. header->table[n].start = read_pointer(&ptr,
  301. (const u8 *)(fde + 1) +
  302. *fde,
  303. fde_pointer_type(cie));
  304. header->table[n].fde = (unsigned long)fde;
  305. ++n;
  306. }
  307. WARN_ON(n != header->fde_count);
  308. sort(header->table,
  309. n,
  310. sizeof(*header->table),
  311. cmp_eh_frame_hdr_table_entries, swap_eh_frame_hdr_table_entries);
  312. table->hdrsz = hdrSize;
  313. smp_wmb();
  314. table->header = (const void *)header;
  315. return;
  316. ret_err:
  317. panic("Attention !!! Dwarf FDE parsing errors\n");;
  318. }
  319. #ifdef CONFIG_MODULES
  320. static struct unwind_table *last_table;
  321. /* Must be called with module_mutex held. */
  322. void *unwind_add_table(struct module *module, const void *table_start,
  323. unsigned long table_size)
  324. {
  325. struct unwind_table *table;
  326. if (table_size <= 0)
  327. return NULL;
  328. table = kmalloc(sizeof(*table), GFP_KERNEL);
  329. if (!table)
  330. return NULL;
  331. init_unwind_table(table, module->name,
  332. module->module_core, module->core_size,
  333. module->module_init, module->init_size,
  334. table_start, table_size,
  335. NULL, 0);
  336. init_unwind_hdr(table, unw_hdr_alloc);
  337. #ifdef UNWIND_DEBUG
  338. unw_debug("Table added for [%s] %lx %lx\n",
  339. module->name, table->core.pc, table->core.range);
  340. #endif
  341. if (last_table)
  342. last_table->link = table;
  343. else
  344. root_table.link = table;
  345. last_table = table;
  346. return table;
  347. }
  348. struct unlink_table_info {
  349. struct unwind_table *table;
  350. int init_only;
  351. };
  352. static int unlink_table(void *arg)
  353. {
  354. struct unlink_table_info *info = arg;
  355. struct unwind_table *table = info->table, *prev;
  356. for (prev = &root_table; prev->link && prev->link != table;
  357. prev = prev->link)
  358. ;
  359. if (prev->link) {
  360. if (info->init_only) {
  361. table->init.pc = 0;
  362. table->init.range = 0;
  363. info->table = NULL;
  364. } else {
  365. prev->link = table->link;
  366. if (!prev->link)
  367. last_table = prev;
  368. }
  369. } else
  370. info->table = NULL;
  371. return 0;
  372. }
  373. /* Must be called with module_mutex held. */
  374. void unwind_remove_table(void *handle, int init_only)
  375. {
  376. struct unwind_table *table = handle;
  377. struct unlink_table_info info;
  378. if (!table || table == &root_table)
  379. return;
  380. if (init_only && table == last_table) {
  381. table->init.pc = 0;
  382. table->init.range = 0;
  383. return;
  384. }
  385. info.table = table;
  386. info.init_only = init_only;
  387. unlink_table(&info); /* XXX: SMP */
  388. kfree(table->header);
  389. kfree(table);
  390. }
  391. #endif /* CONFIG_MODULES */
  392. static uleb128_t get_uleb128(const u8 **pcur, const u8 *end)
  393. {
  394. const u8 *cur = *pcur;
  395. uleb128_t value;
  396. unsigned shift;
  397. for (shift = 0, value = 0; cur < end; shift += 7) {
  398. if (shift + 7 > 8 * sizeof(value)
  399. && (*cur & 0x7fU) >= (1U << (8 * sizeof(value) - shift))) {
  400. cur = end + 1;
  401. break;
  402. }
  403. value |= (uleb128_t) (*cur & 0x7f) << shift;
  404. if (!(*cur++ & 0x80))
  405. break;
  406. }
  407. *pcur = cur;
  408. return value;
  409. }
  410. static sleb128_t get_sleb128(const u8 **pcur, const u8 *end)
  411. {
  412. const u8 *cur = *pcur;
  413. sleb128_t value;
  414. unsigned shift;
  415. for (shift = 0, value = 0; cur < end; shift += 7) {
  416. if (shift + 7 > 8 * sizeof(value)
  417. && (*cur & 0x7fU) >= (1U << (8 * sizeof(value) - shift))) {
  418. cur = end + 1;
  419. break;
  420. }
  421. value |= (sleb128_t) (*cur & 0x7f) << shift;
  422. if (!(*cur & 0x80)) {
  423. value |= -(*cur++ & 0x40) << shift;
  424. break;
  425. }
  426. }
  427. *pcur = cur;
  428. return value;
  429. }
  430. static const u32 *cie_for_fde(const u32 *fde, const struct unwind_table *table)
  431. {
  432. const u32 *cie;
  433. if (!*fde || (*fde & (sizeof(*fde) - 1)))
  434. return &bad_cie;
  435. if (fde[1] == 0xffffffff)
  436. return &not_fde; /* this is a CIE */
  437. if ((fde[1] & (sizeof(*fde) - 1)))
  438. /* || fde[1] > (unsigned long)(fde + 1) - (unsigned long)table->address) */
  439. return NULL; /* this is not a valid FDE */
  440. /* cie = fde + 1 - fde[1] / sizeof(*fde); */
  441. cie = (u32 *) fde[1];
  442. if (*cie <= sizeof(*cie) + 4 || *cie >= fde[1] - sizeof(*fde)
  443. || (*cie & (sizeof(*cie) - 1))
  444. || (cie[1] != 0xffffffff))
  445. return NULL; /* this is not a (valid) CIE */
  446. return cie;
  447. }
  448. static unsigned long read_pointer(const u8 **pLoc, const void *end,
  449. signed ptrType)
  450. {
  451. unsigned long value = 0;
  452. union {
  453. const u8 *p8;
  454. const u16 *p16u;
  455. const s16 *p16s;
  456. const u32 *p32u;
  457. const s32 *p32s;
  458. const unsigned long *pul;
  459. } ptr;
  460. if (ptrType < 0 || ptrType == DW_EH_PE_omit)
  461. return 0;
  462. ptr.p8 = *pLoc;
  463. switch (ptrType & DW_EH_PE_FORM) {
  464. case DW_EH_PE_data2:
  465. if (end < (const void *)(ptr.p16u + 1))
  466. return 0;
  467. if (ptrType & DW_EH_PE_signed)
  468. value = get_unaligned((u16 *) ptr.p16s++);
  469. else
  470. value = get_unaligned((u16 *) ptr.p16u++);
  471. break;
  472. case DW_EH_PE_data4:
  473. #ifdef CONFIG_64BIT
  474. if (end < (const void *)(ptr.p32u + 1))
  475. return 0;
  476. if (ptrType & DW_EH_PE_signed)
  477. value = get_unaligned(ptr.p32s++);
  478. else
  479. value = get_unaligned(ptr.p32u++);
  480. break;
  481. case DW_EH_PE_data8:
  482. BUILD_BUG_ON(sizeof(u64) != sizeof(value));
  483. #else
  484. BUILD_BUG_ON(sizeof(u32) != sizeof(value));
  485. #endif
  486. case DW_EH_PE_native:
  487. if (end < (const void *)(ptr.pul + 1))
  488. return 0;
  489. value = get_unaligned((unsigned long *)ptr.pul++);
  490. break;
  491. case DW_EH_PE_leb128:
  492. BUILD_BUG_ON(sizeof(uleb128_t) > sizeof(value));
  493. value = ptrType & DW_EH_PE_signed ? get_sleb128(&ptr.p8, end)
  494. : get_uleb128(&ptr.p8, end);
  495. if ((const void *)ptr.p8 > end)
  496. return 0;
  497. break;
  498. default:
  499. return 0;
  500. }
  501. switch (ptrType & DW_EH_PE_ADJUST) {
  502. case DW_EH_PE_abs:
  503. break;
  504. case DW_EH_PE_pcrel:
  505. value += (unsigned long)*pLoc;
  506. break;
  507. default:
  508. return 0;
  509. }
  510. if ((ptrType & DW_EH_PE_indirect)
  511. && __get_user(value, (unsigned long __user *)value))
  512. return 0;
  513. *pLoc = ptr.p8;
  514. return value;
  515. }
  516. static signed fde_pointer_type(const u32 *cie)
  517. {
  518. const u8 *ptr = (const u8 *)(cie + 2);
  519. unsigned version = *ptr;
  520. if (*++ptr) {
  521. const char *aug;
  522. const u8 *end = (const u8 *)(cie + 1) + *cie;
  523. uleb128_t len;
  524. /* check if augmentation size is first (and thus present) */
  525. if (*ptr != 'z')
  526. return -1;
  527. /* check if augmentation string is nul-terminated */
  528. aug = (const void *)ptr;
  529. ptr = memchr(aug, 0, end - ptr);
  530. if (ptr == NULL)
  531. return -1;
  532. ++ptr; /* skip terminator */
  533. get_uleb128(&ptr, end); /* skip code alignment */
  534. get_sleb128(&ptr, end); /* skip data alignment */
  535. /* skip return address column */
  536. version <= 1 ? (void) ++ptr : (void)get_uleb128(&ptr, end);
  537. len = get_uleb128(&ptr, end); /* augmentation length */
  538. if (ptr + len < ptr || ptr + len > end)
  539. return -1;
  540. end = ptr + len;
  541. while (*++aug) {
  542. if (ptr >= end)
  543. return -1;
  544. switch (*aug) {
  545. case 'L':
  546. ++ptr;
  547. break;
  548. case 'P':{
  549. signed ptrType = *ptr++;
  550. if (!read_pointer(&ptr, end, ptrType)
  551. || ptr > end)
  552. return -1;
  553. }
  554. break;
  555. case 'R':
  556. return *ptr;
  557. default:
  558. return -1;
  559. }
  560. }
  561. }
  562. return DW_EH_PE_native | DW_EH_PE_abs;
  563. }
  564. static int advance_loc(unsigned long delta, struct unwind_state *state)
  565. {
  566. state->loc += delta * state->codeAlign;
  567. /* FIXME_Rajesh: Probably we are defining for the initial range as well;
  568. return delta > 0;
  569. */
  570. unw_debug("delta %3lu => loc 0x%lx: ", delta, state->loc);
  571. return 1;
  572. }
  573. static void set_rule(uleb128_t reg, enum item_location where, uleb128_t value,
  574. struct unwind_state *state)
  575. {
  576. if (reg < ARRAY_SIZE(state->regs)) {
  577. state->regs[reg].where = where;
  578. state->regs[reg].value = value;
  579. #ifdef UNWIND_DEBUG
  580. unw_debug("r%lu: ", reg);
  581. switch (where) {
  582. case Nowhere:
  583. unw_debug("s ");
  584. break;
  585. case Memory:
  586. unw_debug("c(%lu) ", value);
  587. break;
  588. case Register:
  589. unw_debug("r(%lu) ", value);
  590. break;
  591. case Value:
  592. unw_debug("v(%lu) ", value);
  593. break;
  594. default:
  595. break;
  596. }
  597. #endif
  598. }
  599. }
  600. static int processCFI(const u8 *start, const u8 *end, unsigned long targetLoc,
  601. signed ptrType, struct unwind_state *state)
  602. {
  603. union {
  604. const u8 *p8;
  605. const u16 *p16;
  606. const u32 *p32;
  607. } ptr;
  608. int result = 1;
  609. u8 opcode;
  610. if (start != state->cieStart) {
  611. state->loc = state->org;
  612. result =
  613. processCFI(state->cieStart, state->cieEnd, 0, ptrType,
  614. state);
  615. if (targetLoc == 0 && state->label == NULL)
  616. return result;
  617. }
  618. for (ptr.p8 = start; result && ptr.p8 < end;) {
  619. switch (*ptr.p8 >> 6) {
  620. uleb128_t value;
  621. case 0:
  622. opcode = *ptr.p8++;
  623. switch (opcode) {
  624. case DW_CFA_nop:
  625. unw_debug("cfa nop ");
  626. break;
  627. case DW_CFA_set_loc:
  628. state->loc = read_pointer(&ptr.p8, end,
  629. ptrType);
  630. if (state->loc == 0)
  631. result = 0;
  632. unw_debug("cfa_set_loc: 0x%lx ", state->loc);
  633. break;
  634. case DW_CFA_advance_loc1:
  635. unw_debug("\ncfa advance loc1:");
  636. result = ptr.p8 < end
  637. && advance_loc(*ptr.p8++, state);
  638. break;
  639. case DW_CFA_advance_loc2:
  640. value = *ptr.p8++;
  641. value += *ptr.p8++ << 8;
  642. unw_debug("\ncfa advance loc2:");
  643. result = ptr.p8 <= end + 2
  644. /* && advance_loc(*ptr.p16++, state); */
  645. && advance_loc(value, state);
  646. break;
  647. case DW_CFA_advance_loc4:
  648. unw_debug("\ncfa advance loc4:");
  649. result = ptr.p8 <= end + 4
  650. && advance_loc(*ptr.p32++, state);
  651. break;
  652. case DW_CFA_offset_extended:
  653. value = get_uleb128(&ptr.p8, end);
  654. unw_debug("cfa_offset_extended: ");
  655. set_rule(value, Memory,
  656. get_uleb128(&ptr.p8, end), state);
  657. break;
  658. case DW_CFA_val_offset:
  659. value = get_uleb128(&ptr.p8, end);
  660. set_rule(value, Value,
  661. get_uleb128(&ptr.p8, end), state);
  662. break;
  663. case DW_CFA_offset_extended_sf:
  664. value = get_uleb128(&ptr.p8, end);
  665. set_rule(value, Memory,
  666. get_sleb128(&ptr.p8, end), state);
  667. break;
  668. case DW_CFA_val_offset_sf:
  669. value = get_uleb128(&ptr.p8, end);
  670. set_rule(value, Value,
  671. get_sleb128(&ptr.p8, end), state);
  672. break;
  673. case DW_CFA_restore_extended:
  674. unw_debug("cfa_restore_extended: ");
  675. case DW_CFA_undefined:
  676. unw_debug("cfa_undefined: ");
  677. case DW_CFA_same_value:
  678. unw_debug("cfa_same_value: ");
  679. set_rule(get_uleb128(&ptr.p8, end), Nowhere, 0,
  680. state);
  681. break;
  682. case DW_CFA_register:
  683. unw_debug("cfa_register: ");
  684. value = get_uleb128(&ptr.p8, end);
  685. set_rule(value,
  686. Register,
  687. get_uleb128(&ptr.p8, end), state);
  688. break;
  689. case DW_CFA_remember_state:
  690. unw_debug("cfa_remember_state: ");
  691. if (ptr.p8 == state->label) {
  692. state->label = NULL;
  693. return 1;
  694. }
  695. if (state->stackDepth >= MAX_STACK_DEPTH)
  696. return 0;
  697. state->stack[state->stackDepth++] = ptr.p8;
  698. break;
  699. case DW_CFA_restore_state:
  700. unw_debug("cfa_restore_state: ");
  701. if (state->stackDepth) {
  702. const uleb128_t loc = state->loc;
  703. const u8 *label = state->label;
  704. state->label =
  705. state->stack[state->stackDepth - 1];
  706. memcpy(&state->cfa, &badCFA,
  707. sizeof(state->cfa));
  708. memset(state->regs, 0,
  709. sizeof(state->regs));
  710. state->stackDepth = 0;
  711. result =
  712. processCFI(start, end, 0, ptrType,
  713. state);
  714. state->loc = loc;
  715. state->label = label;
  716. } else
  717. return 0;
  718. break;
  719. case DW_CFA_def_cfa:
  720. state->cfa.reg = get_uleb128(&ptr.p8, end);
  721. unw_debug("cfa_def_cfa: r%lu ", state->cfa.reg);
  722. /*nobreak*/
  723. case DW_CFA_def_cfa_offset:
  724. state->cfa.offs = get_uleb128(&ptr.p8, end);
  725. unw_debug("cfa_def_cfa_offset: 0x%lx ",
  726. state->cfa.offs);
  727. break;
  728. case DW_CFA_def_cfa_sf:
  729. state->cfa.reg = get_uleb128(&ptr.p8, end);
  730. /*nobreak */
  731. case DW_CFA_def_cfa_offset_sf:
  732. state->cfa.offs = get_sleb128(&ptr.p8, end)
  733. * state->dataAlign;
  734. break;
  735. case DW_CFA_def_cfa_register:
  736. unw_debug("cfa_def_cfa_regsiter: ");
  737. state->cfa.reg = get_uleb128(&ptr.p8, end);
  738. break;
  739. /*todo case DW_CFA_def_cfa_expression: */
  740. /*todo case DW_CFA_expression: */
  741. /*todo case DW_CFA_val_expression: */
  742. case DW_CFA_GNU_args_size:
  743. get_uleb128(&ptr.p8, end);
  744. break;
  745. case DW_CFA_GNU_negative_offset_extended:
  746. value = get_uleb128(&ptr.p8, end);
  747. set_rule(value,
  748. Memory,
  749. (uleb128_t) 0 - get_uleb128(&ptr.p8,
  750. end),
  751. state);
  752. break;
  753. case DW_CFA_GNU_window_save:
  754. default:
  755. unw_debug("UNKNOWN OPCODE 0x%x\n", opcode);
  756. result = 0;
  757. break;
  758. }
  759. break;
  760. case 1:
  761. unw_debug("\ncfa_adv_loc: ");
  762. result = advance_loc(*ptr.p8++ & 0x3f, state);
  763. break;
  764. case 2:
  765. unw_debug("cfa_offset: ");
  766. value = *ptr.p8++ & 0x3f;
  767. set_rule(value, Memory, get_uleb128(&ptr.p8, end),
  768. state);
  769. break;
  770. case 3:
  771. unw_debug("cfa_restore: ");
  772. set_rule(*ptr.p8++ & 0x3f, Nowhere, 0, state);
  773. break;
  774. }
  775. if (ptr.p8 > end)
  776. result = 0;
  777. if (result && targetLoc != 0 && targetLoc < state->loc)
  778. return 1;
  779. }
  780. return result && ptr.p8 == end && (targetLoc == 0 || (
  781. /*todo While in theory this should apply, gcc in practice omits
  782. everything past the function prolog, and hence the location
  783. never reaches the end of the function.
  784. targetLoc < state->loc && */ state->label == NULL));
  785. }
  786. /* Unwind to previous to frame. Returns 0 if successful, negative
  787. * number in case of an error. */
  788. int arc_unwind(struct unwind_frame_info *frame)
  789. {
  790. #define FRAME_REG(r, t) (((t *)frame)[reg_info[r].offs])
  791. const u32 *fde = NULL, *cie = NULL;
  792. const u8 *ptr = NULL, *end = NULL;
  793. unsigned long pc = UNW_PC(frame) - frame->call_frame;
  794. unsigned long startLoc = 0, endLoc = 0, cfa;
  795. unsigned i;
  796. signed ptrType = -1;
  797. uleb128_t retAddrReg = 0;
  798. const struct unwind_table *table;
  799. struct unwind_state state;
  800. unsigned long *fptr;
  801. unsigned long addr;
  802. unw_debug("\n\nUNWIND FRAME:\n");
  803. unw_debug("PC: 0x%lx BLINK: 0x%lx, SP: 0x%lx, FP: 0x%x\n",
  804. UNW_PC(frame), UNW_BLINK(frame), UNW_SP(frame),
  805. UNW_FP(frame));
  806. if (UNW_PC(frame) == 0)
  807. return -EINVAL;
  808. #ifdef UNWIND_DEBUG
  809. {
  810. unsigned long *sptr = (unsigned long *)UNW_SP(frame);
  811. unw_debug("\nStack Dump:\n");
  812. for (i = 0; i < 20; i++, sptr++)
  813. unw_debug("0x%p: 0x%lx\n", sptr, *sptr);
  814. unw_debug("\n");
  815. }
  816. #endif
  817. table = find_table(pc);
  818. if (table != NULL
  819. && !(table->size & (sizeof(*fde) - 1))) {
  820. const u8 *hdr = table->header;
  821. unsigned long tableSize;
  822. smp_rmb();
  823. if (hdr && hdr[0] == 1) {
  824. switch (hdr[3] & DW_EH_PE_FORM) {
  825. case DW_EH_PE_native:
  826. tableSize = sizeof(unsigned long);
  827. break;
  828. case DW_EH_PE_data2:
  829. tableSize = 2;
  830. break;
  831. case DW_EH_PE_data4:
  832. tableSize = 4;
  833. break;
  834. case DW_EH_PE_data8:
  835. tableSize = 8;
  836. break;
  837. default:
  838. tableSize = 0;
  839. break;
  840. }
  841. ptr = hdr + 4;
  842. end = hdr + table->hdrsz;
  843. if (tableSize && read_pointer(&ptr, end, hdr[1])
  844. == (unsigned long)table->address
  845. && (i = read_pointer(&ptr, end, hdr[2])) > 0
  846. && i == (end - ptr) / (2 * tableSize)
  847. && !((end - ptr) % (2 * tableSize))) {
  848. do {
  849. const u8 *cur =
  850. ptr + (i / 2) * (2 * tableSize);
  851. startLoc = read_pointer(&cur,
  852. cur + tableSize,
  853. hdr[3]);
  854. if (pc < startLoc)
  855. i /= 2;
  856. else {
  857. ptr = cur - tableSize;
  858. i = (i + 1) / 2;
  859. }
  860. } while (startLoc && i > 1);
  861. if (i == 1
  862. && (startLoc = read_pointer(&ptr,
  863. ptr + tableSize,
  864. hdr[3])) != 0
  865. && pc >= startLoc)
  866. fde = (void *)read_pointer(&ptr,
  867. ptr +
  868. tableSize,
  869. hdr[3]);
  870. }
  871. }
  872. if (fde != NULL) {
  873. cie = cie_for_fde(fde, table);
  874. ptr = (const u8 *)(fde + 2);
  875. if (cie != NULL
  876. && cie != &bad_cie
  877. && cie != &not_fde
  878. && (ptrType = fde_pointer_type(cie)) >= 0
  879. && read_pointer(&ptr,
  880. (const u8 *)(fde + 1) + *fde,
  881. ptrType) == startLoc) {
  882. if (!(ptrType & DW_EH_PE_indirect))
  883. ptrType &=
  884. DW_EH_PE_FORM | DW_EH_PE_signed;
  885. endLoc =
  886. startLoc + read_pointer(&ptr,
  887. (const u8 *)(fde +
  888. 1) +
  889. *fde, ptrType);
  890. if (pc >= endLoc) {
  891. fde = NULL;
  892. cie = NULL;
  893. }
  894. } else {
  895. fde = NULL;
  896. cie = NULL;
  897. }
  898. }
  899. }
  900. if (cie != NULL) {
  901. memset(&state, 0, sizeof(state));
  902. state.cieEnd = ptr; /* keep here temporarily */
  903. ptr = (const u8 *)(cie + 2);
  904. end = (const u8 *)(cie + 1) + *cie;
  905. frame->call_frame = 1;
  906. if (*++ptr) {
  907. /* check if augmentation size is first (thus present) */
  908. if (*ptr == 'z') {
  909. while (++ptr < end && *ptr) {
  910. switch (*ptr) {
  911. /* chk for ignorable or already handled
  912. * nul-terminated augmentation string */
  913. case 'L':
  914. case 'P':
  915. case 'R':
  916. continue;
  917. case 'S':
  918. frame->call_frame = 0;
  919. continue;
  920. default:
  921. break;
  922. }
  923. break;
  924. }
  925. }
  926. if (ptr >= end || *ptr)
  927. cie = NULL;
  928. }
  929. ++ptr;
  930. }
  931. if (cie != NULL) {
  932. /* get code aligment factor */
  933. state.codeAlign = get_uleb128(&ptr, end);
  934. /* get data aligment factor */
  935. state.dataAlign = get_sleb128(&ptr, end);
  936. if (state.codeAlign == 0 || state.dataAlign == 0 || ptr >= end)
  937. cie = NULL;
  938. else {
  939. retAddrReg =
  940. state.version <= 1 ? *ptr++ : get_uleb128(&ptr,
  941. end);
  942. unw_debug("CIE Frame Info:\n");
  943. unw_debug("return Address register 0x%lx\n",
  944. retAddrReg);
  945. unw_debug("data Align: %ld\n", state.dataAlign);
  946. unw_debug("code Align: %lu\n", state.codeAlign);
  947. /* skip augmentation */
  948. if (((const char *)(cie + 2))[1] == 'z') {
  949. uleb128_t augSize = get_uleb128(&ptr, end);
  950. ptr += augSize;
  951. }
  952. if (ptr > end || retAddrReg >= ARRAY_SIZE(reg_info)
  953. || REG_INVALID(retAddrReg)
  954. || reg_info[retAddrReg].width !=
  955. sizeof(unsigned long))
  956. cie = NULL;
  957. }
  958. }
  959. if (cie != NULL) {
  960. state.cieStart = ptr;
  961. ptr = state.cieEnd;
  962. state.cieEnd = end;
  963. end = (const u8 *)(fde + 1) + *fde;
  964. /* skip augmentation */
  965. if (((const char *)(cie + 2))[1] == 'z') {
  966. uleb128_t augSize = get_uleb128(&ptr, end);
  967. if ((ptr += augSize) > end)
  968. fde = NULL;
  969. }
  970. }
  971. if (cie == NULL || fde == NULL) {
  972. #ifdef CONFIG_FRAME_POINTER
  973. unsigned long top, bottom;
  974. top = STACK_TOP_UNW(frame->task);
  975. bottom = STACK_BOTTOM_UNW(frame->task);
  976. #if FRAME_RETADDR_OFFSET < 0
  977. if (UNW_SP(frame) < top && UNW_FP(frame) <= UNW_SP(frame)
  978. && bottom < UNW_FP(frame)
  979. #else
  980. if (UNW_SP(frame) > top && UNW_FP(frame) >= UNW_SP(frame)
  981. && bottom > UNW_FP(frame)
  982. #endif
  983. && !((UNW_SP(frame) | UNW_FP(frame))
  984. & (sizeof(unsigned long) - 1))) {
  985. unsigned long link;
  986. if (!__get_user(link, (unsigned long *)
  987. (UNW_FP(frame) + FRAME_LINK_OFFSET))
  988. #if FRAME_RETADDR_OFFSET < 0
  989. && link > bottom && link < UNW_FP(frame)
  990. #else
  991. && link > UNW_FP(frame) && link < bottom
  992. #endif
  993. && !(link & (sizeof(link) - 1))
  994. && !__get_user(UNW_PC(frame),
  995. (unsigned long *)(UNW_FP(frame)
  996. + FRAME_RETADDR_OFFSET)))
  997. {
  998. UNW_SP(frame) =
  999. UNW_FP(frame) + FRAME_RETADDR_OFFSET
  1000. #if FRAME_RETADDR_OFFSET < 0
  1001. -
  1002. #else
  1003. +
  1004. #endif
  1005. sizeof(UNW_PC(frame));
  1006. UNW_FP(frame) = link;
  1007. return 0;
  1008. }
  1009. }
  1010. #endif
  1011. return -ENXIO;
  1012. }
  1013. state.org = startLoc;
  1014. memcpy(&state.cfa, &badCFA, sizeof(state.cfa));
  1015. unw_debug("\nProcess instructions\n");
  1016. /* process instructions
  1017. * For ARC, we optimize by having blink(retAddrReg) with
  1018. * the sameValue in the leaf function, so we should not check
  1019. * state.regs[retAddrReg].where == Nowhere
  1020. */
  1021. if (!processCFI(ptr, end, pc, ptrType, &state)
  1022. || state.loc > endLoc
  1023. /* || state.regs[retAddrReg].where == Nowhere */
  1024. || state.cfa.reg >= ARRAY_SIZE(reg_info)
  1025. || reg_info[state.cfa.reg].width != sizeof(unsigned long)
  1026. || state.cfa.offs % sizeof(unsigned long))
  1027. return -EIO;
  1028. #ifdef UNWIND_DEBUG
  1029. unw_debug("\n");
  1030. unw_debug("\nRegister State Based on the rules parsed from FDE:\n");
  1031. for (i = 0; i < ARRAY_SIZE(state.regs); ++i) {
  1032. if (REG_INVALID(i))
  1033. continue;
  1034. switch (state.regs[i].where) {
  1035. case Nowhere:
  1036. break;
  1037. case Memory:
  1038. unw_debug(" r%d: c(%lu),", i, state.regs[i].value);
  1039. break;
  1040. case Register:
  1041. unw_debug(" r%d: r(%lu),", i, state.regs[i].value);
  1042. break;
  1043. case Value:
  1044. unw_debug(" r%d: v(%lu),", i, state.regs[i].value);
  1045. break;
  1046. }
  1047. }
  1048. unw_debug("\n");
  1049. #endif
  1050. /* update frame */
  1051. #ifndef CONFIG_AS_CFI_SIGNAL_FRAME
  1052. if (frame->call_frame
  1053. && !UNW_DEFAULT_RA(state.regs[retAddrReg], state.dataAlign))
  1054. frame->call_frame = 0;
  1055. #endif
  1056. cfa = FRAME_REG(state.cfa.reg, unsigned long) + state.cfa.offs;
  1057. startLoc = min_t(unsigned long, UNW_SP(frame), cfa);
  1058. endLoc = max_t(unsigned long, UNW_SP(frame), cfa);
  1059. if (STACK_LIMIT(startLoc) != STACK_LIMIT(endLoc)) {
  1060. startLoc = min(STACK_LIMIT(cfa), cfa);
  1061. endLoc = max(STACK_LIMIT(cfa), cfa);
  1062. }
  1063. unw_debug("\nCFA reg: 0x%lx, offset: 0x%lx => 0x%lx\n",
  1064. state.cfa.reg, state.cfa.offs, cfa);
  1065. for (i = 0; i < ARRAY_SIZE(state.regs); ++i) {
  1066. if (REG_INVALID(i)) {
  1067. if (state.regs[i].where == Nowhere)
  1068. continue;
  1069. return -EIO;
  1070. }
  1071. switch (state.regs[i].where) {
  1072. default:
  1073. break;
  1074. case Register:
  1075. if (state.regs[i].value >= ARRAY_SIZE(reg_info)
  1076. || REG_INVALID(state.regs[i].value)
  1077. || reg_info[i].width >
  1078. reg_info[state.regs[i].value].width)
  1079. return -EIO;
  1080. switch (reg_info[state.regs[i].value].width) {
  1081. case sizeof(u8):
  1082. state.regs[i].value =
  1083. FRAME_REG(state.regs[i].value, const u8);
  1084. break;
  1085. case sizeof(u16):
  1086. state.regs[i].value =
  1087. FRAME_REG(state.regs[i].value, const u16);
  1088. break;
  1089. case sizeof(u32):
  1090. state.regs[i].value =
  1091. FRAME_REG(state.regs[i].value, const u32);
  1092. break;
  1093. #ifdef CONFIG_64BIT
  1094. case sizeof(u64):
  1095. state.regs[i].value =
  1096. FRAME_REG(state.regs[i].value, const u64);
  1097. break;
  1098. #endif
  1099. default:
  1100. return -EIO;
  1101. }
  1102. break;
  1103. }
  1104. }
  1105. unw_debug("\nRegister state after evaluation with realtime Stack:\n");
  1106. fptr = (unsigned long *)(&frame->regs);
  1107. for (i = 0; i < ARRAY_SIZE(state.regs); ++i, fptr++) {
  1108. if (REG_INVALID(i))
  1109. continue;
  1110. switch (state.regs[i].where) {
  1111. case Nowhere:
  1112. if (reg_info[i].width != sizeof(UNW_SP(frame))
  1113. || &FRAME_REG(i, __typeof__(UNW_SP(frame)))
  1114. != &UNW_SP(frame))
  1115. continue;
  1116. UNW_SP(frame) = cfa;
  1117. break;
  1118. case Register:
  1119. switch (reg_info[i].width) {
  1120. case sizeof(u8):
  1121. FRAME_REG(i, u8) = state.regs[i].value;
  1122. break;
  1123. case sizeof(u16):
  1124. FRAME_REG(i, u16) = state.regs[i].value;
  1125. break;
  1126. case sizeof(u32):
  1127. FRAME_REG(i, u32) = state.regs[i].value;
  1128. break;
  1129. #ifdef CONFIG_64BIT
  1130. case sizeof(u64):
  1131. FRAME_REG(i, u64) = state.regs[i].value;
  1132. break;
  1133. #endif
  1134. default:
  1135. return -EIO;
  1136. }
  1137. break;
  1138. case Value:
  1139. if (reg_info[i].width != sizeof(unsigned long))
  1140. return -EIO;
  1141. FRAME_REG(i, unsigned long) = cfa + state.regs[i].value
  1142. * state.dataAlign;
  1143. break;
  1144. case Memory:
  1145. addr = cfa + state.regs[i].value * state.dataAlign;
  1146. if ((state.regs[i].value * state.dataAlign)
  1147. % sizeof(unsigned long)
  1148. || addr < startLoc
  1149. || addr + sizeof(unsigned long) < addr
  1150. || addr + sizeof(unsigned long) > endLoc)
  1151. return -EIO;
  1152. switch (reg_info[i].width) {
  1153. case sizeof(u8):
  1154. __get_user(FRAME_REG(i, u8),
  1155. (u8 __user *)addr);
  1156. break;
  1157. case sizeof(u16):
  1158. __get_user(FRAME_REG(i, u16),
  1159. (u16 __user *)addr);
  1160. break;
  1161. case sizeof(u32):
  1162. __get_user(FRAME_REG(i, u32),
  1163. (u32 __user *)addr);
  1164. break;
  1165. #ifdef CONFIG_64BIT
  1166. case sizeof(u64):
  1167. __get_user(FRAME_REG(i, u64),
  1168. (u64 __user *)addr);
  1169. break;
  1170. #endif
  1171. default:
  1172. return -EIO;
  1173. }
  1174. break;
  1175. }
  1176. unw_debug("r%d: 0x%lx ", i, *fptr);
  1177. }
  1178. return 0;
  1179. #undef FRAME_REG
  1180. }
  1181. EXPORT_SYMBOL(arc_unwind);