From 66539255beeb3686e1aa4d20cc419900f5b1e5d2 Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Thu, 17 Feb 2011 11:28:43 +0000 Subject: [PATCH] ddk: missing chkstk.S git-svn-id: svn://kolibrios.org@1873 a494cfbc-eb01-0410-851d-a64ba20cac60 --- drivers/ddk/debug/chkstk.S | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 drivers/ddk/debug/chkstk.S diff --git a/drivers/ddk/debug/chkstk.S b/drivers/ddk/debug/chkstk.S new file mode 100644 index 0000000000..cf0a8d0d94 --- /dev/null +++ b/drivers/ddk/debug/chkstk.S @@ -0,0 +1,31 @@ + +.global ___chkstk +.global __alloca + +.section .text + +.align 4 +___chkstk: +__alloca: + pushl %ecx /* save temp */ + leal 8(%esp), %ecx /* point past return addr */ + subl %eax, %ecx + call *__imp__GetStackBase + cmpl %eax, %ecx # check low stack limit + jb 1f + + movl %esp, %eax /* save old stack pointer */ + movl %ecx, %esp /* decrement stack */ + movl (%eax), %ecx /* recover saved temp */ + movl 4(%eax), %eax /* recover return address */ + + /* Push the return value back. Doing this instead of just + jumping to %eax preserves the cached call-return stack + used by most modern processors. */ + pushl %eax + ret +1: + int3 #trap to debugger. + #Oh wait... there is no kernel debugger + .ascii "Stack overflow" +