     1                                  ;	SCCSID = @(#)abort.asm	1.4 85/10/02
     2                                  ;TITLE   DOS_ABORT - Internal SFT close all files for proc call for MSDOS
     3                                  ;NAME    DOS_ABORT
     4                                  
     5                                  ; Internal Abort call closes all handles and FCBs associated with a process.
     6                                  ;  If process has NET resources a close all is sent out over the net.
     7                                  ;
     8                                  ;   DOS_ABORT
     9                                  ;
    10                                  ;   Modification history:
    11                                  ;
    12                                  ;       Created: ARR 30 March 1983
    13                                  ;
    14                                  
    15                                  ;
    16                                  ; get the appropriate segment definitions
    17                                  ;
    18                                  
    19                                  %include "dosseg.nas"
     1                              <1> ;	SCCSID = @(#)dosseg.asm	1.1 85/04/10
     2                              <1> ;	SCCSID = @(#)dosseg.asm	1.1 85/04/10
     3                              <1> ;
     4                              <1> ; segment ordering for MSDOS
     5                              <1> ;
     6                              <1> 
     7                              <1> %include "ddataseg.nas"
     1                              <2> 
     2                              <2> %include "lmacros3.mac"
     1                              <3> [list -]
     1          ******************  <3>  warning: redefining multi-line macro `struc' [-w+pp-macro-redef-multi]
    14                              <4> [list -]
    14                              <3> [list -]
     3                              <2> 
     4                              <2> addsection DOSSTART, align=16 PUBLIC class=DOSSTART
     5                              <2> ; (no prior section) ; DOSSTART		ENDS
     6                              <2> 
     7                              <2> addsection DOSSTARTJUMP, align=1 PUBLIC class=START
     8                              <2> ; (no prior section) ; DOSSTARTJUMP		ENDS
     9                              <2> 
    10                              <2> addsection CONSTANTS, align=2 PUBLIC class=CONST
    11                              <2> ; (no prior section) ; CONSTANTS	ENDS
    12                              <2> 
    13                              <2> addsection DATA, align=2 PUBLIC class=DATA
    14                              <2> ; (no prior section) ; DATA		ENDS
    15                              <2> 
    16                              <2> addsection TABLE, align=2 PUBLIC class=TABLE
    17                              <2> ; (no prior section) ; TABLE		ENDS
    18                              <2> 
    19                              <2> addsection DOSDATATABLE, align=2 PUBLIC class=DOSDATACODE
    20                              <2> ; (no prior section) ; DOSDATATABLE		ENDS
    21                              <2> 
    22                              <2> addsection DOSDATACODE, align=1 PUBLIC class=DOSDATACODE
    23                              <2> ; (no prior section) ; DOSDATACODE		ENDS
    24                              <2> 
    25                              <2> addsection DOSBIODATA, align=2 PUBLIC class=DOSBIODATA
    26                              <2> 
    27                              <2> addsection LAST, align=16 PUBLIC class=LAST
    28                              <2> ; (no prior section) ; LAST		ENDS
    29                              <2> 
    30                              <2> group DOSGROUP DOSSTART DOSSTARTJUMP CONSTANTS DATA TABLE DOSDATATABLE DOSDATACODE DOSBIODATA LAST
     8                              <1> 
     9                              <1> %include "dcodeseg.nas"
     1                              <2> 
     2                              <2> %ifndef DCODESEGNAS
     3                              <2> %assign DCODESEGNAS 1
     4                              <2> 
     5                              <2> section DOSCODETABLE align=2 PUBLIC class=DOSCODE
     6                              <2> ; (no prior section) ; DOSCODETABLE		ENDS
     7                              <2> section DOSCODECODE align=1 PUBLIC class=DOSCODE
     8                              <2> ; (no prior section) ; DOSCODECODE		ENDS
     9                              <2> section DOSBIOCODE align=2 PUBLIC class=DOSCODE
    10                              <2> section BIOCODE	align=2 PUBLIC class=DOSCODE
    11                              <2> 
    12                              <2> %ifnidni DOSENTRYGROUP, DOSCODEGROUP
    13                              <2>  group DOSCODEGROUP DOSCODETABLE DOSCODECODE DOSBIOCODE BIOCODE
    14                              <2> %endif
    15                              <2> 
    16                              <2> %endif
    10                              <1> 
    11                              <1> section LAST
    12                              <1> ; (no prior section) ; LAST		ENDS
    20                                  
    21                                  section DOSCODECODE
    22                                  
    23                                  [list -]
    23          ******************       warning: out: ... for DOS Version 4.00 ... [-w+user]
    23          ******************       warning: out: BPB.INC... [-w+user]
    23          ******************       warning: out: ... CLONE version build switch on ... [-w+user]
    23          ******************       warning: out: DEVSYM.INC... [-w+user]
    29                                  
    30                                  %iassign Installed TRUE
    31                                  
    32                                  	I_Need  PROC_ID,WORD            ; current process ID
    33                                  	I_Need  USER_ID,WORD            ; current user ID
    34                                  	i_need  CurrentPDB,WORD
    35                                  	i_need  sft_addr,DWORD
    36                                  	i_need  THISSFT,DWORD
    37                                  	i_need  JSHARE,DWORD
    38                                  	I_need  sftFCB,DWORD            ; pointer to SFTs for FCB cache
    39                                  
    40                                  Break   <DOS_ABORT -- CLOSE all files for process>
    41                                  
    42                                  ; Inputs:
    43                                  ;       [CurrentPDB] set to PID of process aborting
    44                                  ; Function:
    45                                  ;       Close all files and free all SFTs for this PID
    46                                  ; Returns:
    47                                  ;       None
    48                                  ; All destroyed except stack
    49                                  
    50                                  	Procedure   DOS_ABORT,NEAR
    50          ******************       warning: proc DOS_ABORT... [-w+user]
    51                                   assume ds:nothing, es:nothing, ss:DOSGROUP
    52                                  
    53 00000000 368E06[0000]            	MOV     ES,[ss:CurrentPDB]
    54                                   assume es:PSP
    55 00000005 268B0E3200              	MOV     CX,[ES:PDB_JFN_Length]  ; Number of JFNs
    56                                  reset_free_jfn:
    57 0000000A 89CB                    	MOV     BX,CX
    58 0000000C 51                      	PUSH    CX
    59 0000000D 4B                      	DEC     BX                      ; get jfn (start with last one)
    60                                  
    61 0000000E E8(0000)                	invoke  D_close
    62 00000011 59                      	POP     CX
    63 00000012 E2F6                    	LOOP    reset_free_jfn          ; and do 'em all
    64                                  ;
    65                                  ; Note:  We do need to explicitly close FCBs.  Reasons are as follows:  If we
    66                                  ; are running in the no-sharing no-network environment, we are simulating the
    67                                  ; 2.0 world and thus if the user doesn't close the file, that is his problem
    68                                  ; BUT...  the cache remains in a state with garbage that may be reused by the
    69                                  ; next process.  We scan the set and blast the ref counts of the FCBs we own.
    70                                  ;
    71                                  ; If sharing is loaded, then the following call to close process will
    72                                  ; correctly close all FCBs.  We will then need to walk the list AFTER here.
    73                                  ;
    74                                  ; Finally, the following call to NET_Abort will cause an EOP to be sent to all
    75                                  ; known network resources.  These resources are then responsible for cleaning
    76                                  ; up after this process.
    77                                  ;
    78                                  ; Sleazy, eh?
    79                                  ;
    80 00000014 161F                    	context DS
    81                                  multNet equ MultNET	; NASM port equate
    82 00000016 B81D11CD2F              	CallInstall Net_Abort, multNet, 29
    83                                  %if installed
    84                                  JShare equ JSHARE	; NASM port label
    85 0000001B FF1E[1000]              	call    far [JShare + 4 * 4]
    86                                  %else
    87                                  	call    mftCloseP
    88                                  %endif
    89                                   assume ds:nothing
    90                                  ;
    91                                  ; Scan the FCB cache for guys that belong to this process and zap their ref
    92                                  ; counts.
    93                                  ;
    94 0000001F 36C43E[0000]            	les     di,[ss:sftFCB]               ; grab the pointer to the table
    95                                   assume es:nothing
    96                                  sfCount equ SFCount	; NASM port equate
    97 00000024 268B4D04                	mov     cx,[es:di + sfCount]
    98 00000028 E317                    	jcxz    FCBScanDone
    99                                  sfTable equ SFTable	; NASM port equate
   100 0000002A 8D7D06                  	LEA     DI,[DI + sfTable]         ; point at table
   101                                  proc_id equ PROC_ID	; NASM port label
   102 0000002D 36A1[0000]              	mov     ax,[ss:proc_id]
   103                                  FCBTest:
   104 00000031 26394531                	cmp     [es:di + sf_PID],ax       ; is this one of ours
   105 00000035 7505                    	jnz     FCBNext                 ; no, skip it
   106 00000037 26C7050000              	mov     word [es:di + sf_ref_count],0  ; yes, blast ref count
   107                                  FCBNext:
   108                                  sf_Entry_struc_size equ sf_entry_struc_size	; NASM port equate
   109 0000003C 83C73B                  	add     di,sf_Entry_struc_size
   110 0000003F E2F0                    	loop    FCBTest
   111                                  FCBScanDone:
   112                                  
   113                                  ;
   114                                  ; Walk the SFT to eliminate all busy SFT's for this process.
   115                                  ;
   116 00000041 31DB                    	XOR     BX,BX
   117                                  Scan:
   118 00000043 53                      	push    bx
   119 00000044 E8(0000)                	invoke  SFFromSFN
   120                                   assume es:nothing
   121 00000047 5B                      	pop     bx
   122 00000048 7301C3                  	retc
   123                                  		; lDOS note: For MS-DOS v5 the following comparison
   124                                  		;  only has us operate on entries with a reference
   125                                  		;  count equal to 0FFFFh, signifying a temporarily
   126                                  		;  busy SFT entry. This difference had us interfere
   127                                  		;  with the initial PSP relocation in sysinit1.nas,
   128                                  		;  but the difference is relevant for others too.
   129                                  		; Need to study when MS-DOS v5 leaves this special
   130                                  		;  value in the reference count field.
   131                                  		; 2026-03: Change to mimic MS-DOS v5, previously
   132                                  		;  operated on any nonzero count here.
   133 0000004B 26833DFF                	cmp word [es:di + sf_ref_count], 0FFFFh
   134 0000004F 7519                    	jne next
   135                                  ;
   136                                  ; we have a SFT that is not free.  See if it is for the current process
   137                                  ;
   138 00000051 36A1[0000]              	mov     ax,[ss:proc_id]
   139                                  sf_pid equ sf_PID	; NASM port equate
   140 00000055 26394531                	cmp     [es:di + sf_pid],ax
   141 00000059 750F                    	jnz     next
   142                                  user_id equ USER_ID	; NASM port label
   143 0000005B 36A1[0000]              	mov     ax,[ss:user_id]
   144                                  sf_uid equ sf_UID	; NASM port equate
   145 0000005F 2639452F                	cmp     [es:di + sf_uid],ax
   146 00000063 7505                    	jnz     next
   147                                  ;
   148                                  ; This SFT is labelled as ours.
   149                                  ;
   150 00000065 26C7050000              	mov     word [es:di + sf_ref_count],0
   151                                  next:
   152 0000006A 43                      	inc     bx
   153                                  scan equ Scan	; NASM port label
   154 0000006B EBD6                    	jmp     scan
   155                                  
   156                                  EndProc DOS_Abort
   157                                  
   158                                      END
