                  <<< DOCD$:[NOTES$LIBRARY]SCT-RAVEN.NOTE;1 >>>
                         -< The SCT Raven conference >-
================================================================================
Note 694.0              RAVEN_FT1: reimplement perthread              No replies
EVMS::FYFE "{VDE SCT}"                              603 lines  29-MAY-1997 16:20
--------------------------------------------------------------------------------
$!
$!	Project:		Per-Thread Security
$!	Project Leader:		Douglas Fyfe
$!	Development Stream:	Raven FT1
$!	Checkin Type:		New Functionality
$!
$!	Problem Symptom:	Slow RMS performance after Perthread Implemetation
$!				
$!	Diagnosis:		Excessive overhead of perthread system services.
$!				
$!
$!	Description of Changes: Make use of RMS supplied flag to determine if an when
$!				to ensure perthread security. Move persona operations
$!				from the start of an RMS request to the stall/restart
$!				portion of RMS processing. These two changes are designed
$!				to avoid unnecessary persona system service requests.
$!
$!	Platforms affected:     Alpha only (not on VAX)
$!
$!	Modules affected:
$!
$!		[RMS]
$!			RM0THDMGR.B32
$!
$!	Images affected:
$!
$!		[SYS$LDR]
$!			RMS.EXE
$!
$!	Impact/Risks:		None
$!
$!	How was change Tested:	New listings were generated and inspected.
$!				New image created and maps inspected.
$!				New image installed and excercised by QVT.
$!
$!      Associated		
$!	QARs,CLDs,SPRs:
$!
$!	Special Build		None
$!	Instructions:		
$!
Diffs:

************
File WORK7:[FYFE]RM0THDMGR.B32;3
    2   MODULE RM0THDMGR (IDENT = 'X-46') =
    3   %ELSE
    4   MODULE RM0THDMGR (IDENT = 'D-46') =
    5   %FI
******
File WORK7:[FYFE]RM0THDMGR.B32;2
    2   MODULE RM0THDMGR (IDENT = 'X-45') =
    3   %ELSE
    4   MODULE RM0THDMGR (IDENT = 'D-45') =
    5   %FI
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
   14   ! * All Rights Reserved.                                                  *
******
File WORK7:[FYFE]RM0THDMGR.B32;2
   14   ! *                                                                       *
   15   ! * All Rights Reserved.                                                  *
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
   82   !	X-46			Douglas Fyfe		07-May-1997
   83   !		Move X-43 and X44 changes to occur only at stall/restart
   84   !		operation point. Avoid persona action if operation is deemed
   85   !		security profile safe when ASB$V_STALL_WITH_PERSONA bit is clear. 
   86   !		Remove old RESTORE_PRIVS macros and routines.		
   87   !
   88   !	X-45	AJM61509	Andrew J. Moskal	 5-May-1997
******
File WORK7:[FYFE]RM0THDMGR.B32;2
   83   !	X-45	AJM61509	Andrew J. Moskal	 5-May-1997
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
   93   !
   94   !	X-44	AJM61307	Andrew J. Moskal	28-Mar-1997
******
File WORK7:[FYFE]RM0THDMGR.B32;2
   88   !	X-44	AJM61307	Andrew J. Moskal	28-Mar-1997
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
  118   !	X-42	TGS049		Tom Speer		30-Apr-1996
******
File WORK7:[FYFE]RM0THDMGR.B32;2
  112   !
  113   !	X-42	TGS049		Tom Speer		30-Apr-1996
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
  366   
  367   ! Literals
******
File WORK7:[FYFE]RM0THDMGR.B32;2
  361   ! Literals
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
  457   !	 3) Store the current privilege mask within the ASB structure. 
  458   !	 4) Start execution of the thread via a call to RM$INIT_THREAD which will
  459   !	    return when the thread either terminates or stalls.
  460   !	 5) If the thread has terminated then the ASB structure is deallocated.
  461   !
******
File WORK7:[FYFE]RM0THDMGR.B32;2
  451   !	 3) Clone the caller's security profile, to isolate RMS's manipulation
  452   !	    of such (priv's) from other execution contexts, and make it active.
  453   !	 4) Start execution of the thread via a call to RM$INIT_THREAD which will
  454   !	    return when the thread either terminates or stalls.
  455   !	 5) Restore the caller's original security profile.
  456   !	 6) If the thread has terminated then the thread specific security
  457   !	    profile and ASB structure are deallocated.
  458   !
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
  562       ! We now have an ASB.  The next thing to do is to initialize it and start execution on the
******
File WORK7:[FYFE]RM0THDMGR.B32;2
  559   !    !
  560   !    ! Clone the caller's security profile, to isolate RMS's manipulation of
  561   !    ! such (priv's) from other execution contexts, and make it active.
  562   !    !
  563   !    IF ( STATUS = $PERSONA_CLONE (
  564   !			PERSONA  = ASB [ASB$L_PERSONA_ID]
  565   !				 ) )
  566   !    THEN
  567   !	STATUS = $PERSONA_ASSUME (
  568   !			PERSONA  = ASB [ASB$L_PERSONA_ID],
  569   !			PREVIOUS = ASB [ASB$L_SAVED_PERSONA_ID],
  570   !			FLAGS	 = %IF %VARIANT EQL 0
  571   !				   %THEN
  572   !					ISS$M_ASSUME_NODEREF_OLD
  573   !				   %ELSE
  574   !					0
  575   !				   %FI
  576   !				 );
  577   !
  578   !    !
  579   !    ! If the CLONE or ASSUME operation failed, something is seriously wrong.
  580   !    ;
  581   !    IF NOT .STATUS
  582   !    THEN
  583   !	RMSBUG (INVSECSTATE);
  584   
  585       ! We now have an ASB.  The next thing to do is to initialize it and start execution on the
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
  568       ! If thread is not stalled then release the ASB.
******
File WORK7:[FYFE]RM0THDMGR.B32;2
  591   !    !
  592   !    ! Restore the caller's identity.
  593   !    !
  594   !    IF NOT $PERSONA_ASSUME (
  595   !		PERSONA  = ASB [ASB$L_SAVED_PERSONA_ID],
  596   !		FLAGS	 = %IF %VARIANT EQL 0
  597   !			   %THEN
  598   !				ISS$M_ASSUME_NOREF_NEW
  599   !			   %ELSE
  600   !				0
  601   !			   %FI
  602   !			   )
  603   !    THEN
  604   !	RMSBUG (INVSECSTATE);
  605   
  606       ! If thread is not stalled then release the ASB.
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
  573              IF NOT (STATUS = RM$DELETE_THREAD (.ASB))
******
File WORK7:[FYFE]RM0THDMGR.B32;2
  611   !	    !
  612   !	    ! Release the thread specific security profile.
  613   !	    !
  614   !	    IF NOT $PERSONA_DELETE (
  615   !			PERSONA = ASB [ASB$L_PERSONA_ID]
  616   !				   )
  617   !	    THEN
  618   !		RMSBUG (INVSECSTATE);
  619   
  620              IF NOT (STATUS = RM$DELETE_THREAD (.ASB))
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
  599   !	 3) Store the current privilege mask within the ASB structure. 
  600   !	 4) Start execution of the thread via a call to RM$INIT_THREAD which will
  601   !	    return when the thread either terminates or stalls.
  602   !	 5) If the thread has terminated then the ASB structure is deallocated.
  603   !	 6) If this in not a recursive call then the RMS mutex is released. 
  604   !
******
File WORK7:[FYFE]RM0THDMGR.B32;2
  646   !	 3) If this is not a recursive call, then clone the caller's security
  647   !	    profile, to isolate RMS's manipulation of such (priv's) from other
  648   !	    execution contexts, and make it active.  For a recursive call, set
  649   !	    the thread specific and active profiles
  650   !	 4) Start execution of the thread via a call to RM$INIT_THREAD which will
  651   !	    return when the thread either terminates or stalls.
  652   !	 5) If this is not a recursive call, then restore the caller's
  653   !	    original security profile, and if the thread has terminated, then
  654   !	    delete the thread specific security profile.
  655   !	 6) If the thread has terminated then the ASB structure is deallocated.
  656   !	 7) If this in not a recursive call then the RMS mutex is released. 
  657   !
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
  722       ! return, we can restore it before restarting the parent thread
  723       !
  724       IF TESTBITSC (PIO$GW_STATUS [PIO$V_RECURSIVE]) THEN
  725   	BEGIN
  726   	ASB [ASB$V_RECURSIVE] = TRUE;
  727       	ASB [ASB$PS_SAVED_ASB] = .PIO$GL_CUR_ASB;
  728   	END;
  729      
******
File WORK7:[FYFE]RM0THDMGR.B32;2
  775       ! return, we can restore it before restarting the parent thread.
  776       !
  777       IF TESTBITSC (PIO$GW_STATUS [PIO$V_RECURSIVE]) THEN
  778   	BEGIN
  779   
  780   	BIND
  781   	    PARENT_ASB	    = PIO$GL_CUR_ASB : REF $BBLOCK;
  782   
  783   	ASB [ASB$V_RECURSIVE] = TRUE;
  784       	ASB [ASB$PS_SAVED_ASB] = .PARENT_ASB;
  785   
  786   	!
  787   	! For a recursive call, set the thread specific and active profiles
  788   	! for this context to reflect the currently active profile - which
  789   	! is the thread specific profile of the parent.
  790   	!
  791   	ASB [ASB$L_SAVED_PERSONA_ID] =
  792   		ASB [ASB$L_PERSONA_ID] = .PARENT_ASB [ASB$L_PERSONA_ID]
  793   
  794   	END;
  795   !	END
  796   !    ELSE
  797   !	BEGIN
  798   !
  799   !	!
  800   !	! For a non-recursive call, clone the caller's security profile, to
  801   !	! isolate RMS's manipulation of such (priv's) from other execution
  802   !	! contexts, and make it active.
  803   !	!
  804   !	IF ( STATUS = $PERSONA_CLONE (
  805   !			PERSONA  = ASB [ASB$L_PERSONA_ID]
  806   !				     ) )
  807   !	THEN
  808   !	    STATUS = $PERSONA_ASSUME (
  809   !			PERSONA  = ASB [ASB$L_PERSONA_ID],
  810   !			PREVIOUS = ASB [ASB$L_SAVED_PERSONA_ID],
  811   !			FLAGS	 = %IF %VARIANT EQL 0
  812   !				   %THEN
  813   !					ISS$M_ASSUME_NODEREF_OLD
  814   !				   %ELSE
  815   !					0
  816   !				   %FI
  817   !				     );
  818   !	!
  819   !	! If the CLONE or ASSUME operation failed, something is seriously wrong.
  820   !	;
  821   !	IF NOT .STATUS
  822   !	THEN
  823   !	    RMSBUG (INVSECSTATE);
  824   !
  825   !	END;
  826      
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
  751       IF .ASB [ASB$V_STALLED] THEN	
******
File WORK7:[FYFE]RM0THDMGR.B32;2
  848   !    !
  849   !    ! If a non-recursive call, restore the caller's original identity.
  850   !    !
  851   !    IF NOT .RECURSIVE
  852   !    THEN
  853   !	IF NOT $PERSONA_ASSUME (
  854   !		    PERSONA  = ASB [ASB$L_SAVED_PERSONA_ID],
  855   !		    FLAGS    = %IF %VARIANT EQL 0
  856   !			       %THEN
  857   !				    ISS$M_ASSUME_NOREF_NEW
  858   !			       %ELSE
  859   !				    0
  860   !			       %FI
  861   !			       )
  862   !	THEN
  863   !	    RMSBUG (INVSECSTATE);
  864   
  865       IF .ASB [ASB$V_STALLED] THEN	
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
  774           !
******
File WORK7:[FYFE]RM0THDMGR.B32;2
  888   
  889   !	!
  890   !	! If not recursive, release the thread specific security profile.
  891   !	!
  892   !	IF NOT .RECURSIVE
  893   !	THEN
  894   !	    IF NOT $PERSONA_DELETE (
  895   !			PERSONA = ASB [ASB$L_PERSONA_ID]
  896   !				   )
  897   !	    THEN
  898   !		RMSBUG (INVSECSTATE);
  899   
  900           !
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
  850   
  851       ! First check to see if this operation envoked a security clone
  852       ! and clean it up if it did.
  853      
  854       IF .ASB [ASB$V_STALL_WITH_PERSONA] 
  855       THEN
  856   
  857   	!
  858   	! Restore the caller's security profile first.
  859   	! NOTE: if any of the PERSONA_ID fields are invalid
  860   	! we will bugcheck here.
  861   	!
  862   
  863   	IF .ASB [ASB$L_SAVED_PERSONA_ID] NEQ 0   ! If we assumed a clone PSB
  864   	THEN
  865   	BEGIN
  866   	   IF NOT $PERSONA_ASSUME (
  867                   PERSONA  = ASB [ASB$L_SAVED_PERSONA_ID],
  868                   FLAGS    = 0)
  869   	   THEN
  870   		RMSBUG (INVSECSTATE);
  871   
  872   	   ! Release the thread specific security profile.
  873   
  874   	   IF NOT $PERSONA_DELETE ( PERSONA = ASB [ASB$L_PERSONA_ID] )
  875              THEN
  876   		 RMSBUG (INVSECSTATE);
  877           END ;
  878   
  879       ! Deallocate an RMS thread structure.
******
File WORK7:[FYFE]RM0THDMGR.B32;2
  976       ! Deallocate an RMS thread structure.
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
 1226   !	1) It checks for ASTs inhibited, and if so disables ASTs, redeclares the
 1227   !	   current AST, sets the flag to cause ASTs to be re-enabled on exit.
******
File WORK7:[FYFE]RM0THDMGR.B32;2
 1323   !	1) It checks for ASTS inhibited, and if so disables ASTs, redeclares the
 1324   !	   current AST, sets the flag to cause ASTs to be re-enabled on exit.
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
 1286   
******
File WORK7:[FYFE]RM0THDMGR.B32;2
 1383   
 1384   
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
 1520   ! completion or for access to the shared file database (or part thereof)
 1521   !
******
File WORK7:[FYFE]RM0THDMGR.B32;2
 1618   ! completion or for access to the shared file databse (or part thereof)
 1619   !
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
 1526   ! The current process privilege is saved in the stalling threads ASB and the
 1527   ! saved privilege is replaced.  
 1528   !
 1529   ! The threads are then switched.
******
File WORK7:[FYFE]RM0THDMGR.B32;2
 1624   ! The threads are then switched.
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
 1539   !	R8	STRUCTURE ADDRESS
 1540   !
******
File WORK7:[FYFE]RM0THDMGR.B32;2
 1634   !	R8	STARUCTURE ADDRESS
 1635   !
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
 1615   
 1616   	!
 1617   	! The first time through we need to clone the existing security profile.
 1618   	! Every time after that we need to restore the profile saved during threadgo
 1619   	! before stalling out to user mode.
 1620   	! 
 1621   	   IF .ASB [ASB$V_STALL_WITH_PERSONA] THEN
 1622   	      IF .ASB [ASB$L_PERSONA_ID] EQL 0 
 1623   	      THEN
 1624   	         BEGIN
 1625   	            IF NOT $PERSONA_CLONE (PERSONA  = ASB [ASB$L_PERSONA_ID] )
 1626   		       THEN
 1627   		          RMSBUG (INVSECSTATE);
 1628   	         END
 1629   	      ELSE
 1630   	         BEGIN
 1631   	            ! if we have a clone, and we previously assumed it, we must
 1632   	            ! restore the callers profile before we stall.
 1633   
 1634   	            IF NOT (STATUS    = $PERSONA_ASSUME (
 1635   		            PERSONA   = ASB [ASB$L_SAVED_PERSONA_ID],
 1636   		            FLAGS     = 0))
 1637   		    THEN
 1638   		       RMSBUG (INVSECSTATE);
 1639   
 1640   		    !
 1641   		    ! Clear the saved ID to insure consitency in persona handling
 1642   		    ! across stall/threadgo. The result will be a bugcheck during
 1643   		    ! an assume if taken out of order. 
 1644   		    !
 1645   
 1646   		    ASB [ASB$L_SAVED_PERSONA_ID] = 0 ; 
 1647   
 1648   	         END;
 1649   
 1650   
 1651              $ASSUME ($BITPOSITION(IFB$V_RMS_STALL), EQL, $BITPOSITION(IRB$V_RMS_STALL));
******
File WORK7:[FYFE]RM0THDMGR.B32;2
 1710              $ASSUME ($BITPOSITION(IFB$V_RMS_STALL), EQL, $BITPOSITION(IRB$V_RMS_STALL));
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
 1807   ! the stall thread from R9.
 1808   !
******
File WORK7:[FYFE]RM0THDMGR.B32;2
 1866   ! the stall thread form R9.
 1867   !
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
 1886   ! the stall thread form R9.
 1887   !
 1888   ! The routine checks for ASTs inhibited, and if so disabled ASTS, redeclares the current 
 1889   ! AST, sets the flag to cause ASTS to be renabled and exits.
 1890   !
 1891   ! The thread context to resume is retrieved from the IFAB/IRAB and the ASB address is
 1892   ! saved as the current thread in execution.
******
File WORK7:[FYFE]RM0THDMGR.B32;2
 1945   ! the satll thread form R9.
 1946   !
 1947   ! The routine checks for ASTs inhibited, and if so disabled ASTS, redeclares the current 
 1948   ! AST, sets the flag to cause ASTS to be renabled and exits.
 1949   !
 1950   ! The thread context to resume is retrieved form the IFAB/IRAB and the ASB address is
 1951   ! saved as the current thread in execution.
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
 1932       ! Check for ASTs inhibited, and if so disabled ASTs, redeclares the current AST,
 1933       ! sets the flag to cause ASTs to be re-enabled and exit.
 1934       !
******
File WORK7:[FYFE]RM0THDMGR.B32;2
 1991       ! Check for ASTS inhibited, and if so disabled ASTS, redeclares the current AST,
 1992       ! sets the flag to cause ASTS to be re-enabled and exit.
 1993       !
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
 2014       ! Find ASB from stall structure and BUGCHECK if zero,  reset stall bit
 2015       ! in ASB and mark as current thread in execution.
******
File WORK7:[FYFE]RM0THDMGR.B32;2
 2073       ! Find ASB form stall structure and BUGCHECK if zero,  reset stall bit
 2074       ! in ASB and mark as current thread in execution.
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
 2043   !   Restore security profile of the thread if it has been previously stalled
 2044   !
 2045   
 2046   	    IF .ASB [ASB$V_STALL_WITH_PERSONA]
 2047   	    THEN
 2048   	      IF NOT (STATUS = $PERSONA_ASSUME (
 2049   			PERSONA  = ASB [ASB$L_PERSONA_ID],
 2050   			PREVIOUS = ASB [ASB$L_SAVED_PERSONA_ID],
 2051   			FLAGS	 = 0 ))
 2052   		THEN
 2053   		    RMSBUG (INVSECSTATE);
 2054   
******
File WORK7:[FYFE]RM0THDMGR.B32;2
 2102   
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
 2145       ! Once we have found the thread to resume, the current stack context is stored
******
File WORK7:[FYFE]RM0THDMGR.B32;2
 2193   !    !
 2194   !    ! Assume the security profile applicable to the execution context.
 2195   !    !
 2196   !    IF NOT $PERSONA_ASSUME (
 2197   !		PERSONA  = ASB [ASB$L_PERSONA_ID],
 2198   !		PREVIOUS = ASB [ASB$L_SAVED_PERSONA_ID],
 2199   !		FLAGS	 = %IF %VARIANT EQL 0
 2200   !			   %THEN
 2201   !				ISS$M_ASSUME_NODEREF_OLD
 2202   !			   %ELSE
 2203   !				0
 2204   !			   %FI
 2205   !			   )
 2206   !    THEN
 2207   !	RMSBUG (INVSECSTATE);
 2208   
 2209       ! Once we have found the thread to resume, the current stack context is stored
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
 2150       IF NOT .ASB [ASB$V_STALLED] THEN	
******
File WORK7:[FYFE]RM0THDMGR.B32;2
 2214   !    !
 2215   !    ! Restore the caller's identity.
 2216   !    !
 2217   !    IF NOT $PERSONA_ASSUME (
 2218   !		PERSONA  = ASB [ASB$L_SAVED_PERSONA_ID],
 2219   !		FLAGS    = %IF %VARIANT EQL 0
 2220   !			   %THEN
 2221   !				ISS$M_ASSUME_NOREF_NEW
 2222   !			   %ELSE
 2223   !				0
 2224   !			   %FI
 2225   !			   )
 2226   !    THEN
 2227   !	RMSBUG (INVSECSTATE);
 2228   
 2229       IF NOT .ASB [ASB$V_STALLED] THEN	
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
 2158           !
******
File WORK7:[FYFE]RM0THDMGR.B32;2
 2237   
 2238   !	!
 2239   !	! If not recursive, release the thread specific security profile.
 2240   !	!
 2241   !	IF NOT .ASB [ASB$V_RECURSIVE]
 2242   !	THEN
 2243   !	    IF NOT $PERSONA_DELETE (
 2244   !			PERSONA = ASB [ASB$L_PERSONA_ID]
 2245   !			       )
 2246   !	    THEN
 2247   !		RMSBUG (INVSECSTATE);
 2248   
 2249           !
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
 2362           ASB [ASB$L_SAVED_PERSONA_ID] = 0;
 2363   	ASB_ADDR = .ASB;
******
File WORK7:[FYFE]RM0THDMGR.B32;2
 2453   	ASB [ASB$L_SAVED_PERSONA_ID] = 0;
 2454   	ASB_ADDR = .ASB;
************
************
File WORK7:[FYFE]RM0THDMGR.B32;3
 2403       ASB [ASB$L_PERSONA_ID] = 0;
 2404       ASB [ASB$L_SAVED_PERSONA_ID] = 0;
 2405   
******
File WORK7:[FYFE]RM0THDMGR.B32;2
 2494       ASB [ASB$L_PERSONA_ID]	= 0;
 2495       ASB [ASB$L_SAVED_PERSONA_ID]
 2496   				= 0;
 2497   
************

Number of difference sections found: 31
Number of difference records found: 301

DIFFERENCES /IGNORE=()/MATCH=5/MERGED=1/OUTPUT=WORK7:[FYFE]X.X;431-
    WORK7:[FYFE]RM0THDMGR.B32;3-
    WORK7:[FYFE]RM0THDMGR.B32;2
