xref: /reactos/sdk/lib/crt/except/i386/chkstk_ms.s (revision c2c66aff)
1*c2c66affSColin Finck/*
2*c2c66affSColin Finck * COPYRIGHT:         See COPYING in the top level directory
3*c2c66affSColin Finck * PROJECT:           ReactOS kernel
4*c2c66affSColin Finck * PURPOSE:           Stack checker
5*c2c66affSColin Finck * PROGRAMERS:        KJK::Hyperion <noog@libero.it>
6*c2c66affSColin Finck *                    Richard Henderson <rth@redhat.com>
7*c2c66affSColin Finck *                    Kai Tietz <kai.tietz@onevision.com>
8*c2c66affSColin Finck *                    Timo Kreuzer <timo.kreuzer@reactos.org>
9*c2c66affSColin Finck */
10*c2c66affSColin Finck
11*c2c66affSColin Finck#include <asm.inc>
12*c2c66affSColin Finck#include <ks386.inc>
13*c2c66affSColin Finck
14*c2c66affSColin Finck#define PAGE_SIZE 4096
15*c2c66affSColin Finck
16*c2c66affSColin FinckPUBLIC ___chkstk_ms
17*c2c66affSColin Finck.code
18*c2c66affSColin Finck
19*c2c66affSColin Finck/* Special version, that does only probe and not allocate */
20*c2c66affSColin Finck___chkstk_ms:
21*c2c66affSColin Finck
22*c2c66affSColin Finck    /* EAX = size to be allocated */
23*c2c66affSColin Finck    /* save the ECX and EAX register */
24*c2c66affSColin Finck    push ecx
25*c2c66affSColin Finck    push eax
26*c2c66affSColin Finck
27*c2c66affSColin Finck    /* ECX = top of the previous stack frame */
28*c2c66affSColin Finck    lea ecx, [esp + 12]
29*c2c66affSColin Finck
30*c2c66affSColin Finck    /* probe the desired memory, page by page */
31*c2c66affSColin Finck    cmp eax, PAGE_SIZE
32*c2c66affSColin Finck    jl .l_LessThanAPage
33*c2c66affSColin Finck
34*c2c66affSColin Finck.l_MoreThanAPage:
35*c2c66affSColin Finck
36*c2c66affSColin Finck    /* raise the top of the stack by a page and probe */
37*c2c66affSColin Finck    sub ecx, PAGE_SIZE
38*c2c66affSColin Finck    test [ecx], eax
39*c2c66affSColin Finck
40*c2c66affSColin Finck    /* loop if still more than a page must be probed */
41*c2c66affSColin Finck    sub eax, PAGE_SIZE
42*c2c66affSColin Finck    cmp eax, PAGE_SIZE
43*c2c66affSColin Finck    jge .l_MoreThanAPage
44*c2c66affSColin Finck
45*c2c66affSColin Finck.l_LessThanAPage:
46*c2c66affSColin Finck
47*c2c66affSColin Finck    /* raise the top of the stack by EAX bytes (size % 4096) and probe */
48*c2c66affSColin Finck    sub ecx, eax
49*c2c66affSColin Finck    test [ecx], eax
50*c2c66affSColin Finck
51*c2c66affSColin Finck    /* restore ECX and EAX */
52*c2c66affSColin Finck    pop eax
53*c2c66affSColin Finck    pop ecx
54*c2c66affSColin Finck
55*c2c66affSColin Finck    /* return */
56*c2c66affSColin Finck    ret
57*c2c66affSColin Finck
58*c2c66affSColin Finck/* EOF */
59*c2c66affSColin FinckEND
60