home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
EFFO
/
forum16.lzh
/
SOFTWARE
/
ASSEMBLER
/
EXIT_HANDLER
/
uacct.doc
< prev
Wrap
Text File
|
1991-01-09
|
6KB
|
174 lines
********** UPDATE FOR SECOND RELEASE - DOUG KEMP 1990-Nov-06 *****************
UACCT (Exit handler) module as installed by the system at boot:
It must be included in the Extens module list in systype.d.
In order to install it after the boot the TypLang must be changed
to 'Prgrm' (instead of 'System') and the rts line must be replaced by
an 'OS9 F$Exit': then you can load it in memory and execute it.
************** END OF UPDATE FOR SECOND RELEASE *****************************
OS-9 PROGRAMMABLE PROCESS EXIT HANDLER
-------------------------------------
P. Mato
A. Miotto
INTRODUCTION
------------
Many software packages need to do some internal clean-up when the Process
terminates. In normal situations a package user terminates his program with
a call to a routine of the package implemented for that purpose. The problem
arises when the user is a "bad user" and doesn't call the termination routine
or his program has a crash and ends abnormally. Because these situations can
occur the package writer has to provide a method to cope with them. There are
several solutions:
- Using a dummy device driver. OS-9 takes care of closing all the open paths
before the user process ends. In that way the package is informed that
user program has exited.
- Doing a consistency check time to time or in certain conditions. The package
can keep a list of active users and their fork time. The fork time in the
list and in the process descriptor must be equal, otherwise something is
wrong. This technique works but the cpu time consumed can be large if the
check is done often.
- Implementing an Exit Handler. What writers want is a way of indicating to
the operating system that a certain routine must be called when the process
exits. Because a user process may use more than one package there must be
the possibility of declaring more than one routine to be executed on
exit. This utility does not exist in OS-9.
This note explains how an OS-9 exit Handler has been implemented and how
the package writers may make use of it.
IMPLEMENTATION
--------------
The OS-9 system call F$UAcct is foreseen for implementing User Accounting.
This system service is called each time a process is forked and exited. By
default this system call is a dummy routine. This is called each time a process
exits, so we can use it as a hook for our exit handler. Moreover in the process
descriptor there is some space reserved to be used by the User Accounting
module. Two longwords of this reserved space can be used to store pointers
to a double linked list containing the entry point and other parameters for
each declared routine. Programs that do not use any of the packages using the
Exit handler facility will have these pointers to zero and no routine will be
executed.
Two more system services have been implemented to link and unlink elements
to the exit handler list. These have the names F$ExhLnk and F$ExhUlk and are
described as follows:
F$ExhLnk equ I$Last
F$ExhUlk equ I$Last+1
F$ExhLnk Link routine to the Exit Handler list
Assembler call: os9 F$ExhLnk
Input: (a1) = 6 longword structure pointer
offset 0: reserved for the pointer to the next entry
4: reserved for the pointer to the previous entry
8: entry point to the exit routine
12: a6 to be passed to the exit routine
16: d0 to be passed to the exit routine (optional)
20: d1 to be passed to the exit routine (optional)
Output: none
Error: cc = carry bit set
d1.w = error code if error
F$ExhUlk Unlink routine from the Exit Handler list
Assembler call: os9 F$ExhUlk
Input: (a1) = 6 longword structure pointer
Output: none
Error: cc = carry bit set
d1.w = error code if error
CAVEATS
-------
The exit routine is executed in supervisor mode. The user has to be careful
to link to exit routines sensibly. There is no check in F$ExhLnk if the
the entry point supplied has real meaning. The system service F$ExhUlk
checks before doing the unlink if really the list element was linked. Otherwise
returns an error.
The module "uacct" must be resident in memory all the time. Unpredictable
errors (often a crash) can happen if is unlinked.
INSTALLATION
____________
In order to install these new system services the following commands need
to be executed at startup.
$ load <path>/uacct ! this contains the system services
$ <path>/install uacct ! This command is needed to install the new service
EXAMPLE
-------
This is an example of how can be use the exit handler in a routine package.
Let's take the ALEPH OS-9 Buffer Manager as example.
extern int bm_uclean();
bm_include( .... )
{
. . . /* many other things */
icode = bm_exh_link(bm_uclean,user_id);
if(icode == -1)
{
bm_uclean(user_id);
return(errno);
}
return(0);
}
bm_exclude()
{
. . . /* other things */
icode = bm_exh_unlink();
if (icode == -1) return(errno);
bm_uclean(user_id);
}
-------- assembler code ---------
F$ExhLnk equ I$Last
F$ExhUlk equ I$Last+1
vsect
next dc.l 0
prev dc.l 0
r_pc dc.l 0
r_a6 dc.l 0
r_d0 dc.l 0
ends
bm_exh_link: equ * bm_exh_link(routine,arg1);
move.l a1,-(a7)
move.l d0,r_pc(a6)
move.l a6,r_a6(a6)
move.l d1,r_d0(a6)
lea.l next(a6),a1
os9 F$ExhLnk
bcc Exh_ok
move.l #-1,d0
move.l d1,errno(a6)
Exh_ok move.l (a7)+,a1
rts
bm_exh_unlink: equ * bm_exh_unlink();
move.l a1,-(a7)
moveq.l #0,d0
lea.l next(a6),a1
os9 F$ExhUlk
bcc Exhu_ok
move.l #-1,d0
move.l d1,errno(a6)
Exhu_ok move.l (a7)+,a1
rts