home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / SOURCE / STARTUP / WIN / WEP.AS_ / WEP.AS
Encoding:
Text File  |  1993-02-08  |  3.9 KB  |  214 lines

  1.     page    ,132
  2.     title    wep - Windows DLL Exit Processing
  3. ;***
  4. ;wep.asm - Windows DLL Exit Processing
  5. ;
  6. ;    Copyright (c) 1990-1992, Microsoft Corporation.  All rights reserved.
  7. ;
  8. ;Purpose:
  9. ;    This is the WEP() procedure that gets control when a Windows DLL
  10. ;    terminates.
  11. ;
  12. ;    NOTE:  There are a whole PILE of restrictions and problems with
  13. ;    WIN DLLs (especially under Win 3.0).  Here's a short list.
  14. ;
  15. ;    (1) WEP code should be RESIDENT and FIXED.
  16. ;
  17. ;    (2) WEP can possibly be called with DS!=DGROUP.
  18. ;
  19. ;    (3) WEP can possibly be called before the DLL init code is done.
  20. ;
  21. ;    (4) We might be on a small kernel stack (4k, I think) so avoid
  22. ;    going too deep (and minimize OS requests).
  23. ;
  24. ;*******************************************************************************
  25.  
  26. ?DF=    1            ; this is special for c startup
  27.  
  28. .xlist
  29. include version.inc
  30. ?PLM = 1
  31. ?WIN = 1
  32. include cmacros.inc
  33. include defsegs.inc
  34. .list
  35.  
  36. .286
  37.  
  38. ;
  39. ; Define segments
  40. ;
  41.  
  42. CrtDefSegs <wepcode,code>
  43.  
  44. WEPCODE_SEG  equ   <wepcode>
  45. CS_ASSUMEWEP equ   <WEP_TEXT>       ; assumes macro won't handle wepcode
  46.  
  47. CrtDefSegs <null,data,cdata,const,bss>
  48.  
  49. ;
  50. ; WEP fSystemExit flag values
  51. ;
  52.     WEP_SYSTEM_EXIT equ 1        ; System shutdown
  53.     WEP_FREE_DLL    equ 0        ; DLL termination
  54.  
  55. ;
  56. ; Segment present access bit
  57. ;
  58.  
  59.     _SEG_PRESENT    equ 8000H    ; hi bit, hi byte
  60.  
  61. ;
  62. ; External routines
  63. ;
  64.     extern    pascal __STUBWEP:far    ; Alternate _WEP() routine
  65.     extern    pascal _WEP(__STUBWEP):far ; User's DLL Term Routine
  66.  
  67.     externP <__cexit>        ; callable C termination code
  68. ;
  69. ; External data
  70. ;
  71.  
  72. sBegin data
  73.  
  74.     externB <__dllinit>        ; Win DLL init flag
  75.  
  76. sEnd
  77.  
  78.  
  79. %sBegin  WEPCODE_SEG
  80. %assumes cs,CS_ASSUMEWEP
  81.  
  82. page
  83. ;***
  84. ;WEP - Windows DLL Exit Processing
  85. ;
  86. ;Purpose:
  87. ;
  88. ;    This is the WEP() procedure that gets control when a Windows DLL
  89. ;    terminates.  Perform the following actions:
  90. ;
  91. ;    (1) Call the a user's termination routine (via weak extern)
  92. ;
  93. ;    (2) Call _cexit()
  94. ;
  95. ;    (3) Return to OS
  96. ;
  97. ;Entry:
  98. ;    int fSystemExit = WEP_SYSTEM_EXIT = System Shutdown
  99. ;            = WEP_FREE_DLL = DLL Termination
  100. ;
  101. ;Exit:
  102. ;    ax = 1 = successful WEP processing
  103. ;
  104. ;Uses:
  105. ;
  106. ;Exceptions:
  107. ;
  108. ;*******************************************************************************
  109.  
  110. ;int _far pascal WEP (int bSystemExit)
  111.  
  112. cProc    WEP,<PUBLIC,PASCAL,FAR>,<>
  113.  
  114.     parmW    exitflags
  115.  
  116. cBegin    <nolocals>
  117.  
  118. ;
  119. ; See if the DLL init code had a chance to run
  120. ;
  121.  
  122.     assumes ds,nothing
  123.     mov    cx,ds
  124.     lar    ax,cx        ; get ds access rights
  125.     jnz    return1     ; oops, ds not ours
  126.  
  127.     and    ax,_SEG_PRESENT ; is segment present?
  128.     jz    return1     ; nope, get out
  129.  
  130.     assumes ds,data     ; DS=DGROUP
  131.     mov    al,[__dllinit]    ; get dll initialization flag
  132.     or    al,al        ; is it 0 ??
  133.     jz    return1     ; yup, initialization not completed
  134.  
  135. ;
  136. ; Call user's DLL term routine
  137. ;
  138.  
  139.     cCall _WEP <exitflags>
  140.  
  141. ;
  142. ; Perform C exit processing
  143. ; ax = return code from _WEP (1 = success)
  144. ;
  145.  
  146.     push    ax        ; save return code around _cexit()
  147. if sizeC
  148.     call    __cexit     ; C termination processing
  149. else
  150.     call    __fcexit    ; C termination processing (far version)
  151. endif
  152.     pop    ax        ; ax = exit code
  153.     jmp    short done    ; use ax for return code
  154.  
  155. ;
  156. ; Return
  157. ; ax = exit code (1 = success)
  158. ;
  159.  
  160. return1:
  161.     mov    ax,1
  162. done:
  163.  
  164. cEnd    <nolocals>
  165.  
  166. % sEnd    WEPCODE_SEG
  167.  
  168.  
  169. ife sizeC
  170.  
  171. sBegin    code
  172. assumes cs,code
  173.  
  174. page
  175. ;***
  176. ; _fcexit - Shell that calls _cexit (always FAR)
  177. ;
  178. ;Purpose:
  179. ;    This routine is simply a shell that allows WEP to call
  180. ;    _fcexit.  Since WEP is always in it's own segment, we
  181. ;    need a wrapper that is always called far in the _TEXT
  182. ;    segment.
  183. ;
  184. ;    This stub in only needed in small code model; large
  185. ;    code model can call directly to __cexit.
  186. ;
  187. ;Entry:
  188. ;    void
  189. ;
  190. ;Exit:
  191. ;    void
  192. ;
  193. ;Uses:
  194. ;
  195. ;Exceptions:
  196. ;
  197. ;*******************************************************************************
  198.  
  199. ; void __fcexit (void)
  200.  
  201. cProc    __fcexit,<LOCAL,FAR>,<>
  202.  
  203. cBegin    <nolocals>
  204.  
  205.     call    __cexit
  206.  
  207. cEnd    <nolocals>
  208.  
  209. sEnd  code
  210.  
  211. endif ;!sizeC
  212.  
  213.     end
  214.