;       SCCSID = @(#)smgsgtrm.asm	6.1 90/11/18
;	SCCSID @(#)smgsgtrm.asm	6.8 90/09/12
PAGE 60,132				;
; ****************************************************************************
; *									     *
; *			  IBM/Microsoft Confidential			     *
; *									     *
; *		    Copyright (c) IBM Corporation  1987, 1990		     *
; *		    Copyright (c) Microsoft Corp.  1987, 1990		     *
; *			      All Rights Reserved			     *
; *									     *
; ****************************************************************************

;**************************************************************************
;
; Source File Name:	SMGSGTRM.ASM
;
; Subroutine Name:	DOSSMSGTERMINATE
;
; Descriptive Name:	Terminate a screen group
;
; Function:	Kill the parent process and its descendants in a
;		specified screen group.
;
;		Wakes up the termination monitoring thread. The
;		termination monitoring thread will free the screen
;		group associated with  the process terminated.
;
; Notes:
;	Dependencies:	None
;
;	Restrictions:	None
;
;     Change History:
;	@TL7 - 04/05/90 - PTR B712376 - Enable for MMIO
;	@MHW - 09/13/90 - PTR B715818 - In-line performance (MMIO) hooks
;
; Entry Point:
;	Linkage:  EXTRN DOSSMSGTERMINATE:FAR
;			PUSH	DWORD	SGCB	   ; Screen Group Control Block
;			CALL	DOSSMSGTERMINATE
;
; Inputs:
;	DWORD	SGCB	   Screen Group Control Block of SG to terminate
;	DS	RDATA
;
; Exit Normal:
;	AX	ReturnCode Value = 0, screen group terminated
;
; Exit Errors:
;	AX	ReturnCode error_smg_bad_reserve
;			   error_smg_not_baseshell
;			   error_smg_session_not_found
;
;			   DOSKILLPROCESS  errors
;			   DOSSMBASESHELL  errors
;
; Effects:	All other registers preserved.
;
; Internal References:
;
;	   Routines:	DOSSMBASESHELL
;
; External References:
;	   Routines:	DOSSEMREQUEST
;			DOSKILLPROCESS
;			DOSSEMCLEAR
;
;**************************************************************************
ifndef I1

.386C
    EXTRN LocalSelector	   : WORD	; Local	 info segment sel.
    EXTRN ShellPID	   : WORD	; Base Shell PID save in INIT.
    EXTRN SGCB_QueueRamSem : DWORD

    EXTRN DOSKILLPROCESS  : FAR		; Kill process and descendants
    EXTRN DOSSEMREQUEST	  : FAR		; Request semaphore ownership
    EXTRN DOSSEMCLEAR	  : FAR		; Clear semaphore ownership
    EXTRN DOSSMBASESHELL  : NEAR
.xlist
    INCLUDE SMRSGCB.INC
    INCLUDE SMRRDATA.INC
    INCLUDE SMGSGTRM.INC
.xcref
    INCLUDE ERROR2.INC
    INCLUDE INFOSEG.INC
    INCLUDE SMMMPHA.INC			; Performance hook macros	;MHW
    INCLUDE STRUC.INC
.cref
.list

CODE SEGMENT WORD PUBLIC 'CODE' USE16
    ASSUME CS:CODE,DS:RDATA,SS:NOTHING,ES:NOTHING

    PUBLIC DOSSMSGTERMINATE
    PUBLIC DOSSMSGTERMINATE_POSTDT
DOSSMSGTERMINATE PROC FAR

    Local_Bytes	 EQU  0

    ENTER Local_Bytes,0
    PUSH SI				; Save registers

    MMPHPreDOSSMSGTerminate		; Performance Hook (8004h)	;MHW

;   *********************************
;   *  Verify caller is Base Shell  *
;   *********************************
    CALL DOSSMBASESHELL
    .IF	 < zero AX >							;CJ10

;     *****************************************
;     *	 Block other Session Manager threads  *
;     *	 from accessing the queue segment     *
;     *****************************************
;CJ10 PUSH DS				; Queue access semaphore
;CJ10 PUSH OFFSET SGCB_QueueRamSem
;CJ10 PUSH -1				; Wait until queue available
;CJ10 PUSH -1
;CJ10 CALL DOSSEMREQUEST

;     **********************************************
;     *	 Kill the application and its descendants  *
;     **********************************************
      LFS  SI, SS:[BP].SGTrmSGCB
      PUSH AX				; Kill process and descendants	;CJ10
      PUSH FS:[SI].SGCB_ID		; Proc ID/command subtree ID
      CALL DOSKILLPROCESS

;     *************************************************************
;     *	 Free the queue semaphore to allow other Session Manager  *
;     *	 threads to access the active screen group queue.	  *
;     *************************************************************
;CJ10 PUSH AX
;CJ10 PUSH DS				; Queue access semaphore
;CJ10 PUSH OFFSET SGCB_QueueRamSem
;CJ10 CALL DOSSEMCLEAR
;CJ10 POP  AX
    .ENDIF

    MMPHPostDOSSMSGTerminate		; Performance Hook (8084h)	;MHW

    POP	 SI

    LEAVE
    DOSSMSGTERMINATE_POSTDT LABEL FAR
    RET	 SGTrmFrmLen			; Return to caller

DOSSMSGTERMINATE ENDP


CODE ENDS
endif
    END
