home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK7 / SOURCE / STARTUP / WIN / WCHKSTK.AS$ / WCHKSTK
Encoding:
Text File  |  1991-11-06  |  2.8 KB  |  152 lines

  1.     page    ,132
  2.     title    wchkstk.asm - Stack checking for windows
  3. ;***
  4. ;wchkstk.asm - Stack checking for windows
  5. ;
  6. ;    Copyright (c) 1988-1992, Microsoft Corporation. All rights reserved.
  7. ;
  8. ;Purpose:
  9. ;    Windows versions of the C lib stack checking routines.
  10. ;
  11. ;*******************************************************************************
  12.  
  13. .xlist
  14. include version.inc
  15. ?PLM = 1
  16. include cmacros.inc
  17. include rterr.inc
  18. .list
  19.  
  20.     externW pStackTop    ; Windows stack values
  21.     externW pStackMin
  22.     externW pStackBot
  23.  
  24.     externNP __amsg_exit    ; fatal error handler
  25.  
  26. ifdef    SS_NEQ_DGROUP
  27. externP    <__GetDGROUP>    ; Function to recover DGROUP
  28. endif
  29.  
  30. sBegin    data
  31.     assumes ds,data
  32.  
  33. globalCP    __aaltstkovr,-1    ; Holds alternate overflow handler
  34.  
  35. sEnd    data
  36.  
  37.  
  38. sBegin    code
  39.     assumes cs,code
  40.  
  41. page
  42. ;***
  43. ; _aNchkstk - Near check stack routine (windows version)
  44. ;
  45. ;Purpose:
  46. ;
  47. ;Entry:
  48. ;    AX = size of local frame
  49. ;
  50. ;Exit:
  51. ;    SP = new stackframe if successful
  52. ;
  53. ;Uses:
  54. ;
  55. ;Exceptions:
  56. ;    Gives out of stack overflow error and aborts if there is not enough
  57. ;    stack space for the routine.
  58. ;
  59. ;*******************************************************************************
  60.  
  61. ife sizeC
  62. labelP    <PUBLIC,__chkstk>
  63. endif
  64.  
  65. labelP    <PUBLIC, __aNchkstk>
  66.     pop    bx            ; get return address
  67.     inc    ax
  68.     and    al,0FEh         ; round up to nearest even
  69.     sub    ax,sp
  70.     jae    astkovr
  71.     neg    ax
  72.     cmp    ss:[pStackTop],ax
  73.     ja    astkovr
  74.     cmp    ss:[pStackMin],ax
  75.     jbe    nchkstk1
  76.     mov    ss:[pStackMin],ax
  77. nchkstk1:
  78.     mov    sp,ax
  79.     jmp    bx            ; jump to return address
  80.  
  81.  
  82. page
  83. ;***
  84. ; _aFchkstk - Far check stack routine (windows version)
  85. ;
  86. ;Purpose:
  87. ;
  88. ;Entry:
  89. ;    AX = size of local frame
  90. ;
  91. ;Exit:
  92. ;    SP = new stackframe if successful
  93. ;
  94. ;Uses:
  95. ;
  96. ;Exceptions:
  97. ;    Gives out of stack overflow error and aborts if there is not enough
  98. ;    stack space for the routine.
  99. ;
  100. ;*******************************************************************************
  101.  
  102.  
  103. if  sizeC
  104. labelP    <PUBLIC,__chkstk>
  105. endif
  106.  
  107. labelP    <PUBLIC, __aFchkstk>
  108.         pop     bx
  109.     pop    dx            ; get far return address
  110.     inc    ax
  111.     and    al,0FEh         ; round up to nearest even
  112.         sub     ax,sp
  113.         jae     stkerr
  114.         neg     ax
  115.         cmp     ss:[pStackTop],ax
  116.         ja      stkerr
  117.         cmp     ss:[pStackMin],ax
  118.     jbe    fchkstk1
  119.         mov     ss:[pStackMin],ax
  120. fchkstk1:
  121.         mov     sp,ax
  122.         push    dx
  123.         push    bx
  124. ccc     proc    far
  125.         ret
  126. ccc     endp
  127.  
  128. ;
  129. ; Stack fault has occurred
  130. ; (common to both near and far check stack routines)
  131. ;
  132.  
  133. stkerr:
  134.  
  135. ifdef SS_NEQ_DGROUP
  136.     call    __GetDGROUP
  137.     mov    ds,ax            ;set DS = DGROUP
  138. endif
  139.     mov    dx,word ptr [__aaltstkovr]
  140.     inc    dx
  141.     jz    astkovr
  142.     jmp    [__aaltstkovr]    ; alternate stack handler
  143.  
  144. astkovr:
  145.     mov    ax,_RT_STACK    ; stack overflow error
  146.     jmp    __amsg_exit    ; fatal error handler
  147.  
  148.  
  149. sEnd    code
  150.  
  151.     end
  152.