;       SCCSID = @(#)smrstpse.asm	6.3 92/02/21
;       SCCSID @(#)smrstpse.asm	6.3 92/02/21
PAGE 60,132    ;
; ****************************************************************************
; *                                                                          *
; *                       IBM/Microsoft Confidential                         *
; *                                                                          *
; *                 Copyright (c) IBM Corporation  1987, 1990                *
; *                 Copyright (c) Microsoft Corp.  1987, 1990                *
; *                           All Rights Reserved                            *
; *                                                                          *
; ****************************************************************************

;************************************************************************
;
; Source File Name:     SMRSTPSE.ASM
;
; Subroutine Name:      DOSSTOPSESSION
;
; Descriptive Name:     Terminate a child session.
;
; Function:     Allow an application to terminate a session started with
;               DOSSTARTSESSION
;
; 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
;       CJ47 12/06/91  PTR B730582  Co-req for PM20 SM05650.
;
; Entry Point:
;       Linkage:  EXTRN DOSSTOPSESSION:FAR
;                       PUSH    WORD   StopOption ; Stop session options
;                       PUSH    WORD   SessionID  ; Session Number
;                       PUSH    DWORD  Reserved   ; Reserved
;                       CALL    DOSSTOPSESSION
; Inputs:
;       WORD    StopOption Value=0, Stop specified child session
;                          Value=1, Stop all children
;
;       WORD    SessionID  Session Number
;
;       DWORD   Reserved   Double word of zeros reserved for
;                          future use
;
; Exit Normal:
;       AX      ReturnCode Value = 0, Session terminate successful
;
; Exit Errors:
;       AX      ReturnCode error_smg_bad_reserve
;                          error_smg_invalid_call
;                          error_smg_invalid_session_id
;                          error_smg_invalid_stop_option
;                          error_smg_process_not_parent
;                          error_smg_retry_sub_alloc
;
;                          REQUESTBLOCKALOC errors
;                          APPSENDREQUEST   errors
;
; Effects:      All other registers preserved.
;
; Internal References:
;          Data:        QDATA - Common data segment
;                               reqblock (SMRREQB.INC)
;          Routines:    REQUESTBLOCKALOC
;                       APPSENDREQUEST
;
; External References:
;          Routines:
;
;************************************************************************
ifdef I1
;
;   IF (Reserved words are valid)
;      Get session id from stack
;      Get stop option from stack
;      IF (stop option be max_stop_option)
;         IF (Stop option e term_all) OR
;         IF (Session id ne current session id) AND
;         IF (Session id ne 0)
;            Get addressability to queue data segment
;            REQUESTBLOCKALOC (Alloc req block and init header)
;            IF (No_Error)
;               Move stop option into request block
;               IF (Stop option e term_all)
;                  Get request session id from request block
;               ELSE
;                  Get session id from stack
;               ENDIF
;               APPSENDREQUEST (Write stop request into queue)
;            ENDIF
;         ELSE
;            RC = Error_SMG_Invalid_Session_ID
;         ENDIF
;      ELSE
;         RC = Error_SMG_Invalid_Stop_Option
;   ELSE
;      RC = Error_SMG_Bad_Reserve
;   ENDIF
;
;************************************************************************
else

.386C
    EXTRN LocalSelector    : WORD       ; @ of Local Selector

    EXTRN APPSENDREQUEST   : NEAR       ; Send Shell application request
    EXTRN REQUESTBLOCKALOC : NEAR       ; Allocate app request block
.xlist
    INCLUDE SMRREQB.INC
    INCLUDE SMRSTPSE.INC                ; Stop session input structures
.xcref
    INCLUDE ERROR2.INC
    INCLUDE INFOSEG.INC                 ; Information segment definitions
    INCLUDE SMMMPHA.INC                 ; Performance hook macros       ;MHW
    INCLUDE SMRRDATA.INC
    INCLUDE STRUC.INC
.cref
.list

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

    PUBLIC DOSSTOPSESSION
    PUBLIC DOSSTOPSESSION_POSTDT        ; Dynamic Trace Label
DOSSTOPSESSION PROC FAR

    Local_Bytes  EQU  0

    ENTER Local_Bytes,0
    PUSH BX                             ; Save registers
    PUSH DI
    PUSH SI

    PUSH DS
    PUSH ES
    PUSH FS
    PUSH GS

    MMPHPreDOSStopSession               ; Performance Hook (800Fh)      ;MHW

;   ******************************
;   *  Validate input parameters *
;   ******************************

;   **************************************************************      ;CJ47
;   *  WinTerminateApp is a special value that indicates we've   *      ;CJ47
;   *  been called by OS2SM WinTerminateApp.  This is a private  *      ;CJ47
;   *  interface added for Workplace so they can stop unrelated  *      ;CJ47
;   *  sessions.                                                 *      ;CJ47
;   **************************************************************      ;CJ47
    .IF  < <DWORD PTR SS:[BP].StpReserved[0]> eq 0 > OR NEAR ; Check reserved ;CJ10;CJ47
    .IF  < <DWORD PTR SS:[BP].StpReserved[0]> eq WinTerminateApp>             ;CJ47
      MOV  AX, RDATA                    ; Get addressability to
      MOV  DS, AX                       ; localSelector  to get selector
      MOV  ES, DS:LocalSelector         ; of local info seg.
      MOV  AX, SS:[BP].StpSessionID     ; Child to terminate
      MOV  BX, SS:[BP].StpSeOption      ; Stop Option - All or One
      XOR  AH, AH                       ; ES:LIS_CurScrnGrp is only in AL ;CJ10,VR12

      .IF  < BX be Max_Stop_Option > NEAR ; Stop option ok
        .IF  < BX eq Term_All > OR   NEAR ; Term all, session id not used
        .IF  < AX ne ES:LIS_CurScrnGrp > AND NEAR ; same ses. id as current
        .IF  < nonzero AX > NEAR          ; don't allow a 0.            ;CJ10

;         **************************************************************
;         * Sub-allocate the request block in the queue request seg.   *
;         * Inputs:                                                    *
;         *       AX - Start Related Child Request Flag = 0.           *
;         *       BX - Reqbsize   Size of request block to allocate    *
;         * Exit:                                                      *
;         *       AX - ReturnCode Value = 0, Request block allocated   *
;         *       GS - LocalSel   Local information selector           *
;         *       FS - INSTANCE   Instance Data segment                *
;         *       ES:DI - Pointer to ReqBlock                          *
;         **************************************************************
          XOR  AX, AX                   ; Specify this is not a start related
          MOV  BX, StopReqBSize         ; # of bytes to sub-allocate
          CALL REQUESTBLOCKALOC         ; DS:DI --> New Request Block
                                        ; ES    --> LDT
          .IF  < zero AX >                                              ;CJ10
;           ***************************************************
;           *  Fill in request block with user supplied data  *
;           ***************************************************
            MOV  BX, SS:[BP].StpSeOption
            MOV  ES:[DI].RqTrmOptions, BX ; Kill one or all children

;           *************************************************************
;           *  If this is a terminate all request, then put the parent  *
;           *  SID in the request block, otherwise, make sure it's NOT  *
;           *  the parent SID or 0.                                     *
;           *************************************************************
            .IF  < BX eq Term_All >         ; Terminate all children ?
              MOV  AX, ES:[DI].ReqSessionID ; Get requesting SID from Req Blk
            .ELSE                           ; Specify which child
              MOV  EAX, DWORD PTR SS:[BP].StpReserved[0]  ; Get reserved, could CJ47
              MOV  ES:[DI].RqTrmReserved, EAX             ; be WinTerminateApp  CJ47
              MOV  AX, SS:[BP].StpSessionID ; Child to terminate
            .ENDIF

            MOV  BX, StopReqBSize           ; # of bytes in request
            MOV  ES:[DI].RqTrmSessionID, AX ; Session to kill
            MOV  ES:[DI].RqTrmLength, StopReqBSize - rb_head_len_equ
            MOV  ES:[DI].ReqType, App_Stop  ; Specify Stop   Session
            CALL APPSENDREQUEST

          .ENDIF                        ; End error check from REQUESTBLOCKALOC

        .ELSE                           ; Invlid session id
          MOV  AX, Error_SMG_Invalid_Session_ID
        .ENDIF
      .ELSE                             ; Bad stop option
        MOV  AX, Error_SMG_Invalid_Stop_Option
      .ENDIF                            ; End input parameter checking
    .ELSE                               ; Bad reserved DWORD
      MOV  AX, Error_SMG_Bad_Reserve
    .ENDIF

    POP  GS
    POP  FS
    POP  ES
    POP  DS

    POP  SI                             ; Restore Registers
    POP  DI
    POP  BX

    MMPHPostDOSStopSession              ; Performance Hook (808Fh)      ;MHW

    LEAVE
    DOSSTOPSESSION_POSTDT LABEL FAR     ; Dynamic Trace Label
    RET  stpseslen

DOSSTOPSESSION ENDP

CODE ENDS
endif
    END
