;       SCCSID = @(#)smrsmtrm.asm	6.2 91/08/28
PAGE 60,132    ;
; ****************************************************************************
; *                                                                          *
; *                       IBM/Microsoft Confidential                         *
; *                                                                          *
; *                 Copyright (c) IBM Corporation  1987, 1990                *
; *                 Copyright (c) Microsoft Corp.  1987, 1990                *
; *                           All Rights Reserved                            *
; *                                                                          *
; ****************************************************************************

;************************************************************************
;
; Source File Name:     SMRSMTRM.ASM
;
; Subroutine Name:      DOSSMTERMINATE
;
; Descriptive Name:     Session Terminate
;
; Function:     Synchronize Shell session terminate with application
;               session calls and call the Session Manager to terminate
;               the specified session.
;
; Notes:
;       Dependencies:   None
;
;       Restrictions:   Only the Shell can call this procedure.
;
;       Change History:
;       @TL6 - 03/01/90 - DCR 704 - Merge SMG/SSW instance data into OS2CHAR
;       @GDW   08/26/91   PTR B725436 Fix to allow semaphore loop on INTERUPT
;
; Entry Point:
;       Linkage:  EXTRN DOSSMTERMINATE:FAR
;                       PUSH    WORD   SessionID  ; Session Number
;                       PUSH    DWORD  Reserved   ; Reserved
;                       CALL    DOSSMTERMINATE
; Inputs:
;       WORD    SessionID  Session Number
;       DWORD   Reserved   Reserved double word of zeros
;
; Exit Normal:
;       AX      ReturnCode Value = 0, Session terminate successful
;
; Exit Errors:
;       AX      ReturnCode error_smg_bad_reserve
;                          error_smg_not_baseshell
;                          error_smg_session_not_found
;
;                          DOSSEMREQUEST    errors
;                          DOSSMSGTERMINATE errors
;                          DOSKILLPROCESS   errors
;
; Effects:      All other registers preserved.
;
; Internal References:
;          Data:        RDATA - Common data segment
;                               smroutsem - Shell/Application synchronization
;          Routines:
;
; External References:
;          Routines:    DOSSEMREQUEST
;                       DOSSMSGTERMINATE
;                       DOSSEMCLEAR
;
;************************************************************************
ifdef I1
;
;   DOSSEMREQUEST (Wait for SMG router semaphore)
;   IF (No_Error)
;      DOSKILLPROCESS
;   ENDIF
;   DOSSEMCLEAR (Release SMG router semaphore)
;
;************************************************************************
else

.386C
    EXTRN SMRoutSem        : BYTE       ; Shell/application synchronization sem

    EXTRN DOSFSRAMSEMCLEAR    : FAR     ; Release semaphore ownership
    EXTRN DOSFSRAMSEMREQUEST  : FAR     ; Synchronize Shell/App. calls
    EXTRN DOSKILLPROCESS      : FAR
.xlist
    INCLUDE SMRSMTRM.INC
.xcref
    INCLUDE SMRRDATA.INC
    INCLUDE STRUC.INC
    INCLUDE ERROR2.INC
.cref
.list

CODE    SEGMENT WORD PUBLIC 'CODE' USE16                                ;@TL6
    ASSUME CS:CODE,DS:NOTHING,SS:NOTHING,ES:NOTHING                     ;@TL6

    PUBLIC DOSSMTERMINATE
DOSSMTERMINATE PROC FAR

    ENTER 0,0

;   ************************************************************
;   *  Sychronize Shell/Application Session Manager API calls  *
;   ************************************************************
    .repeat                                                             ;@GDW
      PUSH RDATA                        ; SMG router RAM semaphore
      PUSH OFFSET SmRoutSem
      PUSH DWORD PTR -1                                                 ;CJ10
;     PUSH -1                                                           ;CJ10
      CALL DOSFSRAMSEMREQUEST
    .until  <ax ne ERROR_INTERRUPT>                                     ;@GDW

;   ************************************
;   *  Call Session Manager Terminate  *
;   ************************************
    .IF  <zero AX>                                                      ;@TL6
      PUSH AX                          ; Kill process and descendants   ;@TL6
      CALL DOSKILLPROCESS
    .ENDIF

;   ************************************************************************
;   *  Preserve terminate return code and clear synchronization semaphore  *
;   ************************************************************************
    PUSH AX                             ; Save return code
    PUSH RDATA                          ; Clear synchronization semaphore
    PUSH OFFSET SmRoutSem
    CALL DOSFSRAMSEMCLEAR

    POP  AX                             ; Restore Session Manager return code

    LEAVE
    RET  6

DOSSMTERMINATE ENDP

CODE    ENDS                                                            ;@TL6
endif
    END
