xref: /openbmc/linux/arch/parisc/kernel/unwind.c (revision e036306aa1832963cd147849b282259a32f5ac08)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Kernel unwinding support
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * (c) 2002-2004 Randolph Chung <tausq@debian.org>
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  * Derived partially from the IA64 implementation. The PA-RISC
71da177e4SLinus Torvalds  * Runtime Architecture Document is also a useful reference to
81da177e4SLinus Torvalds  * understand what is happening here
91da177e4SLinus Torvalds  */
101da177e4SLinus Torvalds 
111da177e4SLinus Torvalds #include <linux/kernel.h>
121da177e4SLinus Torvalds #include <linux/init.h>
13e6fc0449SMatthew Wilcox #include <linux/sched.h>
141da177e4SLinus Torvalds #include <linux/slab.h>
151da177e4SLinus Torvalds #include <linux/kallsyms.h>
161da177e4SLinus Torvalds 
171da177e4SLinus Torvalds #include <asm/uaccess.h>
181da177e4SLinus Torvalds #include <asm/assembly.h>
191da177e4SLinus Torvalds 
201da177e4SLinus Torvalds #include <asm/unwind.h>
211da177e4SLinus Torvalds 
221da177e4SLinus Torvalds /* #define DEBUG 1 */
231da177e4SLinus Torvalds #ifdef DEBUG
241da177e4SLinus Torvalds #define dbg(x...) printk(x)
251da177e4SLinus Torvalds #else
261da177e4SLinus Torvalds #define dbg(x...)
271da177e4SLinus Torvalds #endif
281da177e4SLinus Torvalds 
29*e036306aSRandolph Chung #define KERNEL_START (KERNEL_BINARY_TEXT_START - 0x1000)
30*e036306aSRandolph Chung 
311da177e4SLinus Torvalds extern struct unwind_table_entry __start___unwind[];
321da177e4SLinus Torvalds extern struct unwind_table_entry __stop___unwind[];
331da177e4SLinus Torvalds 
341da177e4SLinus Torvalds static spinlock_t unwind_lock;
351da177e4SLinus Torvalds /*
361da177e4SLinus Torvalds  * the kernel unwind block is not dynamically allocated so that
371da177e4SLinus Torvalds  * we can call unwind_init as early in the bootup process as
381da177e4SLinus Torvalds  * possible (before the slab allocator is initialized)
391da177e4SLinus Torvalds  */
408039de10SHelge Deller static struct unwind_table kernel_unwind_table __read_mostly;
411da177e4SLinus Torvalds static LIST_HEAD(unwind_tables);
421da177e4SLinus Torvalds 
431da177e4SLinus Torvalds static inline const struct unwind_table_entry *
441da177e4SLinus Torvalds find_unwind_entry_in_table(const struct unwind_table *table, unsigned long addr)
451da177e4SLinus Torvalds {
461da177e4SLinus Torvalds 	const struct unwind_table_entry *e = NULL;
471da177e4SLinus Torvalds 	unsigned long lo, hi, mid;
481da177e4SLinus Torvalds 
491da177e4SLinus Torvalds 	lo = 0;
501da177e4SLinus Torvalds 	hi = table->length - 1;
511da177e4SLinus Torvalds 
521da177e4SLinus Torvalds 	while (lo <= hi) {
531da177e4SLinus Torvalds 		mid = (hi - lo) / 2 + lo;
541da177e4SLinus Torvalds 		e = &table->table[mid];
551da177e4SLinus Torvalds 		if (addr < e->region_start)
561da177e4SLinus Torvalds 			hi = mid - 1;
571da177e4SLinus Torvalds 		else if (addr > e->region_end)
581da177e4SLinus Torvalds 			lo = mid + 1;
591da177e4SLinus Torvalds 		else
601da177e4SLinus Torvalds 			return e;
611da177e4SLinus Torvalds 	}
621da177e4SLinus Torvalds 
631da177e4SLinus Torvalds 	return NULL;
641da177e4SLinus Torvalds }
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds static const struct unwind_table_entry *
671da177e4SLinus Torvalds find_unwind_entry(unsigned long addr)
681da177e4SLinus Torvalds {
691da177e4SLinus Torvalds 	struct unwind_table *table;
701da177e4SLinus Torvalds 	const struct unwind_table_entry *e = NULL;
711da177e4SLinus Torvalds 
721da177e4SLinus Torvalds 	if (addr >= kernel_unwind_table.start &&
731da177e4SLinus Torvalds 	    addr <= kernel_unwind_table.end)
741da177e4SLinus Torvalds 		e = find_unwind_entry_in_table(&kernel_unwind_table, addr);
751da177e4SLinus Torvalds 	else
761da177e4SLinus Torvalds 		list_for_each_entry(table, &unwind_tables, list) {
771da177e4SLinus Torvalds 			if (addr >= table->start &&
781da177e4SLinus Torvalds 			    addr <= table->end)
791da177e4SLinus Torvalds 				e = find_unwind_entry_in_table(table, addr);
801da177e4SLinus Torvalds 			if (e)
811da177e4SLinus Torvalds 				break;
821da177e4SLinus Torvalds 		}
831da177e4SLinus Torvalds 
841da177e4SLinus Torvalds 	return e;
851da177e4SLinus Torvalds }
861da177e4SLinus Torvalds 
871da177e4SLinus Torvalds static void
881da177e4SLinus Torvalds unwind_table_init(struct unwind_table *table, const char *name,
891da177e4SLinus Torvalds 		  unsigned long base_addr, unsigned long gp,
901da177e4SLinus Torvalds 		  void *table_start, void *table_end)
911da177e4SLinus Torvalds {
921da177e4SLinus Torvalds 	struct unwind_table_entry *start = table_start;
931da177e4SLinus Torvalds 	struct unwind_table_entry *end =
941da177e4SLinus Torvalds 		(struct unwind_table_entry *)table_end - 1;
951da177e4SLinus Torvalds 
961da177e4SLinus Torvalds 	table->name = name;
971da177e4SLinus Torvalds 	table->base_addr = base_addr;
981da177e4SLinus Torvalds 	table->gp = gp;
991da177e4SLinus Torvalds 	table->start = base_addr + start->region_start;
1001da177e4SLinus Torvalds 	table->end = base_addr + end->region_end;
1011da177e4SLinus Torvalds 	table->table = (struct unwind_table_entry *)table_start;
1021da177e4SLinus Torvalds 	table->length = end - start + 1;
1031da177e4SLinus Torvalds 	INIT_LIST_HEAD(&table->list);
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds 	for (; start <= end; start++) {
1061da177e4SLinus Torvalds 		if (start < end &&
1071da177e4SLinus Torvalds 		    start->region_end > (start+1)->region_start) {
1081da177e4SLinus Torvalds 			printk("WARNING: Out of order unwind entry! %p and %p\n", start, start+1);
1091da177e4SLinus Torvalds 		}
1101da177e4SLinus Torvalds 
1111da177e4SLinus Torvalds 		start->region_start += base_addr;
1121da177e4SLinus Torvalds 		start->region_end += base_addr;
1131da177e4SLinus Torvalds 	}
1141da177e4SLinus Torvalds }
1151da177e4SLinus Torvalds 
1161da177e4SLinus Torvalds static void
1171da177e4SLinus Torvalds unwind_table_sort(struct unwind_table_entry *start,
1181da177e4SLinus Torvalds 		  struct unwind_table_entry *finish)
1191da177e4SLinus Torvalds {
1201da177e4SLinus Torvalds 	struct unwind_table_entry el, *p, *q;
1211da177e4SLinus Torvalds 
1221da177e4SLinus Torvalds 	for (p = start + 1; p < finish; ++p) {
1231da177e4SLinus Torvalds 		if (p[0].region_start < p[-1].region_start) {
1241da177e4SLinus Torvalds 			el = *p;
1251da177e4SLinus Torvalds 			q = p;
1261da177e4SLinus Torvalds 			do {
1271da177e4SLinus Torvalds 				q[0] = q[-1];
1281da177e4SLinus Torvalds 				--q;
1291da177e4SLinus Torvalds 			} while (q > start &&
1301da177e4SLinus Torvalds 				 el.region_start < q[-1].region_start);
1311da177e4SLinus Torvalds 			*q = el;
1321da177e4SLinus Torvalds 		}
1331da177e4SLinus Torvalds 	}
1341da177e4SLinus Torvalds }
1351da177e4SLinus Torvalds 
1361da177e4SLinus Torvalds struct unwind_table *
1371da177e4SLinus Torvalds unwind_table_add(const char *name, unsigned long base_addr,
1381da177e4SLinus Torvalds 		 unsigned long gp,
1391da177e4SLinus Torvalds                  void *start, void *end)
1401da177e4SLinus Torvalds {
1411da177e4SLinus Torvalds 	struct unwind_table *table;
1421da177e4SLinus Torvalds 	unsigned long flags;
1431da177e4SLinus Torvalds 	struct unwind_table_entry *s = (struct unwind_table_entry *)start;
1441da177e4SLinus Torvalds 	struct unwind_table_entry *e = (struct unwind_table_entry *)end;
1451da177e4SLinus Torvalds 
1461da177e4SLinus Torvalds 	unwind_table_sort(s, e);
1471da177e4SLinus Torvalds 
1481da177e4SLinus Torvalds 	table = kmalloc(sizeof(struct unwind_table), GFP_USER);
1491da177e4SLinus Torvalds 	if (table == NULL)
1501da177e4SLinus Torvalds 		return NULL;
1511da177e4SLinus Torvalds 	unwind_table_init(table, name, base_addr, gp, start, end);
1521da177e4SLinus Torvalds 	spin_lock_irqsave(&unwind_lock, flags);
1531da177e4SLinus Torvalds 	list_add_tail(&table->list, &unwind_tables);
1541da177e4SLinus Torvalds 	spin_unlock_irqrestore(&unwind_lock, flags);
1551da177e4SLinus Torvalds 
1561da177e4SLinus Torvalds 	return table;
1571da177e4SLinus Torvalds }
1581da177e4SLinus Torvalds 
1591da177e4SLinus Torvalds void unwind_table_remove(struct unwind_table *table)
1601da177e4SLinus Torvalds {
1611da177e4SLinus Torvalds 	unsigned long flags;
1621da177e4SLinus Torvalds 
1631da177e4SLinus Torvalds 	spin_lock_irqsave(&unwind_lock, flags);
1641da177e4SLinus Torvalds 	list_del(&table->list);
1651da177e4SLinus Torvalds 	spin_unlock_irqrestore(&unwind_lock, flags);
1661da177e4SLinus Torvalds 
1671da177e4SLinus Torvalds 	kfree(table);
1681da177e4SLinus Torvalds }
1691da177e4SLinus Torvalds 
1701da177e4SLinus Torvalds /* Called from setup_arch to import the kernel unwind info */
1711da177e4SLinus Torvalds static int unwind_init(void)
1721da177e4SLinus Torvalds {
1731da177e4SLinus Torvalds 	long start, stop;
1741da177e4SLinus Torvalds 	register unsigned long gp __asm__ ("r27");
1751da177e4SLinus Torvalds 
1761da177e4SLinus Torvalds 	start = (long)&__start___unwind[0];
1771da177e4SLinus Torvalds 	stop = (long)&__stop___unwind[0];
1781da177e4SLinus Torvalds 
1791da177e4SLinus Torvalds 	spin_lock_init(&unwind_lock);
1801da177e4SLinus Torvalds 
1811da177e4SLinus Torvalds 	printk("unwind_init: start = 0x%lx, end = 0x%lx, entries = %lu\n",
1821da177e4SLinus Torvalds 	    start, stop,
1831da177e4SLinus Torvalds 	    (stop - start) / sizeof(struct unwind_table_entry));
1841da177e4SLinus Torvalds 
1851da177e4SLinus Torvalds 	unwind_table_init(&kernel_unwind_table, "kernel", KERNEL_START,
1861da177e4SLinus Torvalds 			  gp,
1871da177e4SLinus Torvalds 			  &__start___unwind[0], &__stop___unwind[0]);
1881da177e4SLinus Torvalds #if 0
1891da177e4SLinus Torvalds 	{
1901da177e4SLinus Torvalds 		int i;
1911da177e4SLinus Torvalds 		for (i = 0; i < 10; i++)
1921da177e4SLinus Torvalds 		{
1931da177e4SLinus Torvalds 			printk("region 0x%x-0x%x\n",
1941da177e4SLinus Torvalds 				__start___unwind[i].region_start,
1951da177e4SLinus Torvalds 				__start___unwind[i].region_end);
1961da177e4SLinus Torvalds 		}
1971da177e4SLinus Torvalds 	}
1981da177e4SLinus Torvalds #endif
1991da177e4SLinus Torvalds 	return 0;
2001da177e4SLinus Torvalds }
2011da177e4SLinus Torvalds 
2021da177e4SLinus Torvalds static void unwind_frame_regs(struct unwind_frame_info *info)
2031da177e4SLinus Torvalds {
2041da177e4SLinus Torvalds 	const struct unwind_table_entry *e;
2051da177e4SLinus Torvalds 	unsigned long npc;
2061da177e4SLinus Torvalds 	unsigned int insn;
2071da177e4SLinus Torvalds 	long frame_size = 0;
2081da177e4SLinus Torvalds 	int looking_for_rp, rpoffset = 0;
2091da177e4SLinus Torvalds 
2101da177e4SLinus Torvalds 	e = find_unwind_entry(info->ip);
2111da177e4SLinus Torvalds 	if (e == NULL) {
2121da177e4SLinus Torvalds 		unsigned long sp;
2131da177e4SLinus Torvalds 		extern char _stext[], _etext[];
2141da177e4SLinus Torvalds 
2151da177e4SLinus Torvalds 		dbg("Cannot find unwind entry for 0x%lx; forced unwinding\n", info->ip);
2161da177e4SLinus Torvalds 
2171da177e4SLinus Torvalds #ifdef CONFIG_KALLSYMS
2181da177e4SLinus Torvalds 		/* Handle some frequent special cases.... */
2191da177e4SLinus Torvalds 		{
2201da177e4SLinus Torvalds 			char symname[KSYM_NAME_LEN+1];
221cb957795SKyle McMartin 			char *modname;
2221da177e4SLinus Torvalds 
223cb957795SKyle McMartin 			kallsyms_lookup(info->ip, NULL, NULL, &modname,
224cb957795SKyle McMartin 				symname);
2251da177e4SLinus Torvalds 
2261da177e4SLinus Torvalds 			dbg("info->ip = 0x%lx, name = %s\n", info->ip, symname);
2271da177e4SLinus Torvalds 
2281da177e4SLinus Torvalds 			if (strcmp(symname, "_switch_to_ret") == 0) {
2291da177e4SLinus Torvalds 				info->prev_sp = info->sp - CALLEE_SAVE_FRAME_SIZE;
2301da177e4SLinus Torvalds 				info->prev_ip = *(unsigned long *)(info->prev_sp - RP_OFFSET);
2311da177e4SLinus Torvalds 				dbg("_switch_to_ret @ %lx - setting "
2321da177e4SLinus Torvalds 				    "prev_sp=%lx prev_ip=%lx\n",
2331da177e4SLinus Torvalds 				    info->ip, info->prev_sp,
2341da177e4SLinus Torvalds 				    info->prev_ip);
2351da177e4SLinus Torvalds 				return;
2361da177e4SLinus Torvalds 			} else if (strcmp(symname, "ret_from_kernel_thread") == 0 ||
2371da177e4SLinus Torvalds 				   strcmp(symname, "syscall_exit") == 0) {
2381da177e4SLinus Torvalds 				info->prev_ip = info->prev_sp = 0;
2391da177e4SLinus Torvalds 				return;
2401da177e4SLinus Torvalds 			}
2411da177e4SLinus Torvalds 		}
2421da177e4SLinus Torvalds #endif
2431da177e4SLinus Torvalds 
2441da177e4SLinus Torvalds 		/* Since we are doing the unwinding blind, we don't know if
2451da177e4SLinus Torvalds 		   we are adjusting the stack correctly or extracting the rp
2461da177e4SLinus Torvalds 		   correctly. The rp is checked to see if it belongs to the
2471da177e4SLinus Torvalds 		   kernel text section, if not we assume we don't have a
2481da177e4SLinus Torvalds 		   correct stack frame and we continue to unwind the stack.
2491da177e4SLinus Torvalds 		   This is not quite correct, and will fail for loadable
2501da177e4SLinus Torvalds 		   modules. */
2511da177e4SLinus Torvalds 		sp = info->sp & ~63;
2521da177e4SLinus Torvalds 		do {
2531da177e4SLinus Torvalds 			unsigned long tmp;
2541da177e4SLinus Torvalds 
2551da177e4SLinus Torvalds 			info->prev_sp = sp - 64;
2561da177e4SLinus Torvalds 			info->prev_ip = 0;
2571da177e4SLinus Torvalds 			if (get_user(tmp, (unsigned long *)(info->prev_sp - RP_OFFSET)))
2581da177e4SLinus Torvalds 				break;
2591da177e4SLinus Torvalds 			info->prev_ip = tmp;
2601da177e4SLinus Torvalds 			sp = info->prev_sp;
2611da177e4SLinus Torvalds 		} while (info->prev_ip < (unsigned long)_stext ||
2621da177e4SLinus Torvalds 			 info->prev_ip > (unsigned long)_etext);
2631da177e4SLinus Torvalds 
2641da177e4SLinus Torvalds 		info->rp = 0;
2651da177e4SLinus Torvalds 
2661da177e4SLinus Torvalds 		dbg("analyzing func @ %lx with no unwind info, setting "
2671da177e4SLinus Torvalds 		    "prev_sp=%lx prev_ip=%lx\n", info->ip,
2681da177e4SLinus Torvalds 		    info->prev_sp, info->prev_ip);
2691da177e4SLinus Torvalds 	} else {
2701da177e4SLinus Torvalds 		dbg("e->start = 0x%x, e->end = 0x%x, Save_SP = %d, "
2711da177e4SLinus Torvalds 		    "Save_RP = %d, Millicode = %d size = %u\n",
2721da177e4SLinus Torvalds 		    e->region_start, e->region_end, e->Save_SP, e->Save_RP,
2731da177e4SLinus Torvalds 		    e->Millicode, e->Total_frame_size);
2741da177e4SLinus Torvalds 
2751da177e4SLinus Torvalds 		looking_for_rp = e->Save_RP;
2761da177e4SLinus Torvalds 
2771da177e4SLinus Torvalds 		for (npc = e->region_start;
2781da177e4SLinus Torvalds 		     (frame_size < (e->Total_frame_size << 3) ||
2791da177e4SLinus Torvalds 		      looking_for_rp) &&
2801da177e4SLinus Torvalds 		     npc < info->ip;
2811da177e4SLinus Torvalds 		     npc += 4) {
2821da177e4SLinus Torvalds 
2831da177e4SLinus Torvalds 			insn = *(unsigned int *)npc;
2841da177e4SLinus Torvalds 
2851da177e4SLinus Torvalds 			if ((insn & 0xffffc000) == 0x37de0000 ||
2861da177e4SLinus Torvalds 			    (insn & 0xffe00000) == 0x6fc00000) {
2871da177e4SLinus Torvalds 				/* ldo X(sp), sp, or stwm X,D(sp) */
2881da177e4SLinus Torvalds 				frame_size += (insn & 0x1 ? -1 << 13 : 0) |
2891da177e4SLinus Torvalds 					((insn & 0x3fff) >> 1);
2901da177e4SLinus Torvalds 				dbg("analyzing func @ %lx, insn=%08x @ "
2911da177e4SLinus Torvalds 				    "%lx, frame_size = %ld\n", info->ip,
2921da177e4SLinus Torvalds 				    insn, npc, frame_size);
2931da177e4SLinus Torvalds 			} else if ((insn & 0xffe00008) == 0x73c00008) {
2941da177e4SLinus Torvalds 				/* std,ma X,D(sp) */
2951da177e4SLinus Torvalds 				frame_size += (insn & 0x1 ? -1 << 13 : 0) |
2961da177e4SLinus Torvalds 					(((insn >> 4) & 0x3ff) << 3);
2971da177e4SLinus Torvalds 				dbg("analyzing func @ %lx, insn=%08x @ "
2981da177e4SLinus Torvalds 				    "%lx, frame_size = %ld\n", info->ip,
2991da177e4SLinus Torvalds 				    insn, npc, frame_size);
3001da177e4SLinus Torvalds 			} else if (insn == 0x6bc23fd9) {
3011da177e4SLinus Torvalds 				/* stw rp,-20(sp) */
3021da177e4SLinus Torvalds 				rpoffset = 20;
3031da177e4SLinus Torvalds 				looking_for_rp = 0;
3041da177e4SLinus Torvalds 				dbg("analyzing func @ %lx, insn=stw rp,"
3051da177e4SLinus Torvalds 				    "-20(sp) @ %lx\n", info->ip, npc);
3061da177e4SLinus Torvalds 			} else if (insn == 0x0fc212c1) {
3071da177e4SLinus Torvalds 				/* std rp,-16(sr0,sp) */
3081da177e4SLinus Torvalds 				rpoffset = 16;
3091da177e4SLinus Torvalds 				looking_for_rp = 0;
3101da177e4SLinus Torvalds 				dbg("analyzing func @ %lx, insn=std rp,"
3111da177e4SLinus Torvalds 				    "-16(sp) @ %lx\n", info->ip, npc);
3121da177e4SLinus Torvalds 			}
3131da177e4SLinus Torvalds 		}
3141da177e4SLinus Torvalds 
3151da177e4SLinus Torvalds 		info->prev_sp = info->sp - frame_size;
3161da177e4SLinus Torvalds 		if (e->Millicode)
3171da177e4SLinus Torvalds 			info->rp = info->r31;
3181da177e4SLinus Torvalds 		else if (rpoffset)
3191da177e4SLinus Torvalds 			info->rp = *(unsigned long *)(info->prev_sp - rpoffset);
3201da177e4SLinus Torvalds 		info->prev_ip = info->rp;
3211da177e4SLinus Torvalds 		info->rp = 0;
3221da177e4SLinus Torvalds 
3231da177e4SLinus Torvalds 		dbg("analyzing func @ %lx, setting prev_sp=%lx "
3241da177e4SLinus Torvalds 		    "prev_ip=%lx npc=%lx\n", info->ip, info->prev_sp,
3251da177e4SLinus Torvalds 		    info->prev_ip, npc);
3261da177e4SLinus Torvalds 	}
3271da177e4SLinus Torvalds }
3281da177e4SLinus Torvalds 
3291da177e4SLinus Torvalds void unwind_frame_init(struct unwind_frame_info *info, struct task_struct *t,
3301da177e4SLinus Torvalds 		       struct pt_regs *regs)
3311da177e4SLinus Torvalds {
3321da177e4SLinus Torvalds 	memset(info, 0, sizeof(struct unwind_frame_info));
3331da177e4SLinus Torvalds 	info->t = t;
3341da177e4SLinus Torvalds 	info->sp = regs->gr[30];
3351da177e4SLinus Torvalds 	info->ip = regs->iaoq[0];
3361da177e4SLinus Torvalds 	info->rp = regs->gr[2];
3371da177e4SLinus Torvalds 	info->r31 = regs->gr[31];
3381da177e4SLinus Torvalds 
3391da177e4SLinus Torvalds 	dbg("(%d) Start unwind from sp=%08lx ip=%08lx\n",
3401da177e4SLinus Torvalds 	    t ? (int)t->pid : -1, info->sp, info->ip);
3411da177e4SLinus Torvalds }
3421da177e4SLinus Torvalds 
3431da177e4SLinus Torvalds void unwind_frame_init_from_blocked_task(struct unwind_frame_info *info, struct task_struct *t)
3441da177e4SLinus Torvalds {
3451da177e4SLinus Torvalds 	struct pt_regs *r = &t->thread.regs;
3461da177e4SLinus Torvalds 	struct pt_regs *r2;
3471da177e4SLinus Torvalds 
3485cbded58SRobert P. J. Day 	r2 = kmalloc(sizeof(struct pt_regs), GFP_KERNEL);
3491da177e4SLinus Torvalds 	if (!r2)
3501da177e4SLinus Torvalds 		return;
3511da177e4SLinus Torvalds 	*r2 = *r;
3521da177e4SLinus Torvalds 	r2->gr[30] = r->ksp;
3531da177e4SLinus Torvalds 	r2->iaoq[0] = r->kpc;
3541da177e4SLinus Torvalds 	unwind_frame_init(info, t, r2);
3551da177e4SLinus Torvalds 	kfree(r2);
3561da177e4SLinus Torvalds }
3571da177e4SLinus Torvalds 
3581da177e4SLinus Torvalds void unwind_frame_init_running(struct unwind_frame_info *info, struct pt_regs *regs)
3591da177e4SLinus Torvalds {
3601da177e4SLinus Torvalds 	unwind_frame_init(info, current, regs);
3611da177e4SLinus Torvalds }
3621da177e4SLinus Torvalds 
3631da177e4SLinus Torvalds int unwind_once(struct unwind_frame_info *next_frame)
3641da177e4SLinus Torvalds {
3651da177e4SLinus Torvalds 	unwind_frame_regs(next_frame);
3661da177e4SLinus Torvalds 
3671da177e4SLinus Torvalds 	if (next_frame->prev_sp == 0 ||
3681da177e4SLinus Torvalds 	    next_frame->prev_ip == 0)
3691da177e4SLinus Torvalds 		return -1;
3701da177e4SLinus Torvalds 
3711da177e4SLinus Torvalds 	next_frame->sp = next_frame->prev_sp;
3721da177e4SLinus Torvalds 	next_frame->ip = next_frame->prev_ip;
3731da177e4SLinus Torvalds 	next_frame->prev_sp = 0;
3741da177e4SLinus Torvalds 	next_frame->prev_ip = 0;
3751da177e4SLinus Torvalds 
3761da177e4SLinus Torvalds 	dbg("(%d) Continue unwind to sp=%08lx ip=%08lx\n",
3771da177e4SLinus Torvalds 	    next_frame->t ? (int)next_frame->t->pid : -1,
3781da177e4SLinus Torvalds 	    next_frame->sp, next_frame->ip);
3791da177e4SLinus Torvalds 
3801da177e4SLinus Torvalds 	return 0;
3811da177e4SLinus Torvalds }
3821da177e4SLinus Torvalds 
3831da177e4SLinus Torvalds int unwind_to_user(struct unwind_frame_info *info)
3841da177e4SLinus Torvalds {
3851da177e4SLinus Torvalds 	int ret;
3861da177e4SLinus Torvalds 
3871da177e4SLinus Torvalds 	do {
3881da177e4SLinus Torvalds 		ret = unwind_once(info);
3891da177e4SLinus Torvalds 	} while (!ret && !(info->ip & 3));
3901da177e4SLinus Torvalds 
3911da177e4SLinus Torvalds 	return ret;
3921da177e4SLinus Torvalds }
3931da177e4SLinus Torvalds 
3941da177e4SLinus Torvalds module_init(unwind_init);
395