home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 1.ddi / WINLBSRC.ZIP / H_CHKSTK.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-06-10  |  1.9 KB  |  69 lines

  1. ;[]-----------------------------------------------------------------[]
  2. ;|      H_CHKSTK.ASM -- Windows stack check function                 |
  3. ;[]-----------------------------------------------------------------[]
  4.  
  5. ;
  6. ;       C/C++ Run Time Library - Version 5.0
  7. ;       Copyright (c) 1987, 1992 by Borland International
  8. ;       All Rights Reserved.
  9.  
  10.         INCLUDE RULES.ASI
  11.  
  12. ; calls to these routines are generated by the compiler to allocate
  13. ; stack space if available.  Aborts with message on failure.
  14.  
  15. MARGIN    equ   1024
  16. pStackTop equ   0Ah
  17.  
  18. extrn   __errorExitBox:DIST
  19.  
  20. _DATA   segment
  21.         _stkovrmsg db "Runtime Error: Stack Overflow", 0
  22.         ends
  23.  
  24. _TEXT   segment
  25.         assume cs:_TEXT
  26. ;
  27. ;       F_CHKSTK@ - Allocates local space.
  28. ;
  29. ;       ax      number of bytes for local space
  30.  
  31.         public  N_CHKSTK@
  32.         public  F_CHKSTK@
  33.         public  __aNchkstk
  34.         public  __aFchkstk
  35.  
  36. __aNchkstk:
  37. N_CHKSTK@:      pop     bx
  38.                 push    cs
  39.                 push    bx
  40. __aFchkstk:
  41. F_CHKSTK@:
  42.                 pop     bx              ; get return address
  43.                 pop     dx
  44.                 sub     ax, sp
  45.                 jae     overflow
  46.                 neg     ax
  47.                 mov     cx, ss:pStackTop
  48.                 add     cx, MARGIN
  49.                 cmp     ax, cx          ;StackMax + MARGIN
  50.                 jbe     overflow
  51.                 mov     sp, ax
  52.                 push    dx              ; Note: may use up to four bytes
  53.                 push    bx              ; of the reserved stack buffer
  54.                 retf
  55. overflow:
  56.                 mov    ax, 3
  57.                 push   ax
  58. IF LDATA
  59.                 push   ds
  60. ENDIF
  61.                 lea    ax, _stkovrmsg
  62.                 push   ax
  63.                 call   __errorExitBox   ; doesn't return!
  64.                 ends
  65.                 END
  66.  
  67.