walk_stack respects the max stack depth provided
@@ -20,8 +20,18 @@ walk_stack:
mov ecx, [esp + 20] ; Maximum array size in ECX.
.walk:
; Walk backwards through EBP linked list, storing return addresses in EDI array.
+ ; Did we reach the "root" base pointer?
+ ; (The root base pointer is set up by the kernel bootstrap, and is
+ ; valid only for kernel stack frames, not user-mode stack frames)
test ebx, ebx
jz .done
+
+ ; Did we hit the maximum stack frame length?
+ test ecx, ecx
+ jz .done
+ ; Record that we walked one more frame
+ dec ecx
+
mov edx, [ebx + 4] ; EDX = previous stack frame's IP.
mov ebx, [ebx + 0] ; EBX = previous stack frame's BP.
mov [edi], edx ; Copy IP.
