summaryrefslogtreecommitdiff
path: root/sys/arch/amd64/amd64/machdep.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/arch/amd64/amd64/machdep.c')
-rw-r--r--sys/arch/amd64/amd64/machdep.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c
index 19dcf44..9ff96e1 100644
--- a/sys/arch/amd64/amd64/machdep.c
+++ b/sys/arch/amd64/amd64/machdep.c
@@ -47,6 +47,13 @@
#include <dev/cons/cons.h>
#include <string.h>
+/*
+ * This defines the max number of frames
+ * we will pass while walking the callstack
+ * in md_backtrace()
+ */
+#define MAX_FRAME_DEPTH 16
+
#define pr_trace(fmt, ...) kprintf("cpu: " fmt, ##__VA_ARGS__)
#define pr_error(...) pr_trace(__VA_ARGS__)
#define pr_trace_bsp(...) \
@@ -259,24 +266,43 @@ void
md_backtrace(void)
{
uintptr_t *rbp;
- uintptr_t rip;
+ uintptr_t rip, tmp;
off_t off;
const char *name;
char line[256];
+ uint8_t n = 0;
__ASMV("mov %%rbp, %0" : "=r" (rbp) :: "memory");
while (1) {
+ if (n >= MAX_FRAME_DEPTH) {
+ break;
+ }
+
rip = rbp[1];
rbp = (uintptr_t *)rbp[0];
- name = backtrace_addr_to_name(rip, &off);
- if (rbp == NULL)
+ /*
+ * RBP should be aligned on an 8-byte
+ * boundary... Don't trust this state
+ * anymore if it is not.
+ */
+ tmp = (uintptr_t)rbp;
+ if ((tmp & (8 - 1)) != 0) {
+ break;
+ }
+
+ /*
+ * This is not a valid value, get out
+ * of this loop!!
+ */
+ if (rbp == NULL || rip == 0) {
break;
- if (name == NULL)
- name = "???";
+ }
+ name = backtrace_addr_to_name(rip, &off);
snprintf(line, sizeof(line), "%p @ <%s+0x%x>\n", rip, name, off);
cons_putstr(&g_root_scr, line, strlen(line));
+ ++n;
}
}