+#if __i386__
+#define i386_RETURN_OFFSET 4
+
+static unsigned int
+i386_validate_stackptr(vm_offset_t stackptr)
+{
+ /* Existence and alignment check
+ */
+ if (!stackptr || (stackptr & 0x3))
+ return 0;
+
+ /* Is a virtual->physical translation present?
+ */
+ if (!kvtophys(stackptr))
+ return 0;
+
+ /* Check if the return address lies on the same page;
+ * If not, verify that a translation exists.
+ */
+ if (((PAGE_SIZE - (stackptr & PAGE_MASK)) < i386_RETURN_OFFSET) &&
+ !kvtophys(stackptr + i386_RETURN_OFFSET))
+ return 0;
+ return 1;
+}
+
+static unsigned int
+i386_validate_raddr(vm_offset_t raddr)
+{
+ return ((raddr > VM_MIN_KERNEL_AND_KEXT_ADDRESS) &&
+ (raddr < VM_MAX_KERNEL_ADDRESS));
+}
+#endif
+
+#if __x86_64__
+#define x86_64_RETURN_OFFSET 8
+static unsigned int
+x86_64_validate_raddr(vm_offset_t raddr)
+{
+ return ((raddr > VM_MIN_KERNEL_AND_KEXT_ADDRESS) &&
+ (raddr < VM_MAX_KERNEL_ADDRESS));
+}
+static unsigned int
+x86_64_validate_stackptr(vm_offset_t stackptr)
+{
+ /* Existence and alignment check
+ */
+ if (!stackptr || (stackptr & 0x7) || !x86_64_validate_raddr(stackptr))
+ return 0;
+
+ /* Is a virtual->physical translation present?
+ */
+ if (!kvtophys(stackptr))
+ return 0;
+
+ /* Check if the return address lies on the same page;
+ * If not, verify that a translation exists.
+ */
+ if (((PAGE_SIZE - (stackptr & PAGE_MASK)) < x86_64_RETURN_OFFSET) &&
+ !kvtophys(stackptr + x86_64_RETURN_OFFSET))
+ return 0;
+ return 1;
+}
+#endif
+
+void
+OSPrintBacktrace(void)
+{
+ void * btbuf[20];
+ int tmp = OSBacktrace(btbuf, 20);
+ int i;
+ for(i=0;i<tmp;i++)
+ {
+ kprintf("bt[%.2d] = %p\n", i, btbuf[i]);
+ }
+}
+