|
|
1.1 root 1: TITLE chkstk - C stack checking routine
2: ;***
3: ;chkstk.asm - C stack checking routine
4: ;
5: ; Copyright (c) 1985-1987 Microsoft Corporation, All Rights Reserved
6: ;
7: ;Purpose:
8: ; Provides support for automatic stack checking in C procedures
9: ; when stack checking is enabled.
10: ;
11: ;*******************************************************************************
12:
13: include version.inc
14: .xlist
15:
16: include cmacros.inc
17: include msdos.inc
18: .list
19:
20: sBegin data
21: assumes ds,data
22:
23: extrn _end:word ; stack bottom
24:
25: if sizeC
26: globalCP _aaltstkovr,-1 ; alternate stack overflow
27: endif
28:
29: public STKHQQ ; used by parasitic heap
30: STKHQQ dw dataoffset _end+STACKSLOP ; initial value
31:
32:
33:
34: sEnd data
35:
36:
37: sBegin code
38: assumes ds,data
39: assumes cs,code
40:
41: externNP _amsg_exit ; write error and die
42:
43: page
44: ;***
45: ;_chkstk - check stack upon procedure entry
46: ;
47: ;Purpose:
48: ; Provide stack checking on procedure entry.
49: ;
50: ;Entry:
51: ; AX = size of local frame
52: ;
53: ;Exit:
54: ; SP = new stackframe if successful
55: ;
56: ;Uses:
57: ; BX, CX, DX
58: ;
59: ;Exceptions:
60: ; Gives out of memory error and aborts if there is not enough
61: ; stack space for the routine.
62: ;*******************************************************************************
63:
64: labelP <PUBLIC,_chkstk>
65:
66: if sizeC
67: pop cx ; get return offset
68: pop dx ; get return segment
69: else
70: pop cx ; get return offset
71: endif
72:
73: mov bx,sp
74: sub bx,ax ; new position
75: jc OMerr ; error - out of memory
76: cmp bx,[STKHQQ] ; SP - AX : STKHQQ (for heap/stack)
77: jb OMerr ; error - out of memory
78:
79: mov sp,bx ; set new stack pointer
80:
81: if sizeC
82: push dx ; push segment
83: push cx ; push offset
84: chkproc proc far
85: ret ; far return to dx:cx
86: chkproc endp
87: else
88: jmp cx ; return to cx
89: endif
90:
91: OMerr:
92: if sizeC
93: mov ax,word ptr [_aaltstkovr]
94: inc ax
95: jnz altstkovr
96: endif
97:
98:
99: xor ax,ax
100: jmp _amsg_exit ; give stack overflow and die
101:
102: if sizeC
103: altstkovr:
104: push dx ; user segment
105: push cx ; user offset
106: jmp [_aaltstkovr] ; Pascal/FORTRAN stack overflow
107: endif
108:
109: sEnd code
110:
111: end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.