Subversion Repositories Kolibri OS

Rev

Rev 548 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
548 serge 1
;*****************************************************************************
2
;*
3
;*                            Open Watcom Project
4
;*
5
;*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
6
;*
7
;*  ========================================================================
8
;*
9
;*    This file contains Original Code and/or Modifications of Original
10
;*    Code as defined in and that are subject to the Sybase Open Watcom
11
;*    Public License version 1.0 (the 'License'). You may not use this file
12
;*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
13
;*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
14
;*    provided with the Original Code and Modifications, and is also
15
;*    available at www.sybase.com/developer/opensource.
16
;*
17
;*    The Original Code and all software distributed under the License are
18
;*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
19
;*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
20
;*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
21
;*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
22
;*    NON-INFRINGEMENT. Please see the License for the specific language
23
;*    governing rights and limitations under the License.
24
;*
25
;*  ========================================================================
26
;*
27
;* Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
28
;*               DESCRIBE IT HERE!
29
;*
30
;*****************************************************************************
31
 
32
 
33
include mdef.inc
34
include struct.inc
35
include xinit.inc
36
include exitwmsg.inc
37
 
38
        modstart        stk
39
 
40
        datasegment
41
        extrn   "C",_STACKLOW : dword
42
msg     db      "Stack Overflow!", 0dh, 0ah, 0
43
        enddata
44
 
45
        xinit   _init_stk,DEF_PRIORITY
46
 
47
        assume  ds:DGROUP
48
 
49
 
50
        defp    _init_stk
51
        ret                             ; return
52
        endproc _init_stk
53
 
54
 
55
        xdefp   __CHK
56
        defpe   __CHK                   ; new style stack check
57
        xchg    eax,4[esp]              ; get parm in eax
58
        call    __STK                   ; call stack checker
59
        mov     eax,4[esp]              ; restore eax
60
        ret     4
61
        endproc __CHK
62
 
63
        xdefp   __STK
64
        defpe   __STK
65
        push    eax                     ; save parm for __GRO routine
66
        _guess                          ; guess: no overflow
67
          cmp   eax,esp                 ; - quit if user asking for too much
68
          _quif ae                      ; - ...
69
          sub   eax,esp                 ; - calculate new low point
70
          neg   eax                     ; - calc what new SP would be
705 serge 71
          cmp   eax,[_STACKLOW]         ; - quit if too much
548 serge 72
          _quif   be                    ; - ...
73
          call  __GRO                   ; - return
74
          ret
75
        _endguess                       ; endguess
76
 
77
__STKOVERFLOW:
78
        xdefp   "C",__STKOVERFLOW
79
        pop     eax                     ; pop the stack
80
ifdef __STACK__
81
        push    1                       ; ...
82
        push    offset msg              ; print the error message
83
else
84
        mov     eax,offset msg          ; print the error message
85
        mov     edx,1                   ; ...
86
endif
87
        call    __fatal_runtime_error   ; ...
88
        endproc __STK
89
 
90
        xdefp   __GRO
91
        defpe   __GRO                   ; dummy function to resolve symbol
92
        push    eax                     ; save regs
93
        push    ebx                     ; ...
94
        mov     eax,12[esp]             ; get size to grow by
95
        mov     ebx,-4                  ; initialiaze index
96
lup:                                    ; do {
97
        mov     [esp+ebx],ebx           ; - touch that stack page
98
        sub     ebx,1000H               ; - decrement by 4k
99
        sub     eax,1000H               ; - decrement by 4k
100
        jg      lup                     ; } while stack left to go
101
        pop     ebx                     ; restore regs
102
        pop     eax                     ; ...
103
        ret     4                       ; return to caller
104
        endproc __GRO
105
 
106
        xdefp   __alloca_probe
107
        ; on entry eax is size of stack to grow
108
        ; on exit esp has been advanced to new size
109
        defpe   __alloca_probe          ; ms compatible function
110
        push    eax                     ; size parm to __GRO
111
        call    __GRO
112
        push    eax                     ; save size
113
        lea     eax,8[esp]              ; get esp value to adjust
114
        sub     eax,[esp]               ; carve off piece of stack
115
        xchg    eax,esp                 ; set new esp
116
        mov     eax,4[eax]              ; snag return address
117
        jmp     eax                     ; return to caller
118
        endproc __alloca_probe
119
        endmod
120
        end