[comp.sys.amiga.tech] 1.4 enhancement / replacement for Setfunction?

john13@garfield.MUN.EDU (John Russell) (11/13/88)

On a couple of recent occasions I have been tempted to use Setfunction() to
make things safer when doing not-entirely-safe things, just by adding a
test "does this call relate to me? If not pass it, else shut down then call
the function over again to let it go through".

However it seems that unless your new function is the big enchilada in terms
of replacement functions this approach may be unsafe as well, as in the
case where different people Setfunction a vector and then don't exit in 
exactly the same order, leading to the vector pointing to a defunct routine.

Since we already have very expandable ways to add chains of input handlers,
devices, interrupt servers, etc. why not make Setfunction (or a new
similar function) just as good?

Here is the first scenario that comes to my mind:

Application: SafeSetfunction(library, offset, newvec);

System: Adds a list node (somewhere) containing the new vector and pointing
	to another list node containing the old vector. Returns pointer to the
	node containing _my vector_.

Application: Intercepts a library call. Performs the desired extra processing,
	then if it wants to let the old function finish up it determines the
	function to call by 
	func = (func_descriptor *)(return_ptr->node.ln_succ)->oldfunc.

Several more applications SafeSetfunction the same vector. Each one determines
the proper old function to call by following the pointer to the next node
_each time_ it needs to call the old function.

Application (the original one): SafeUnsetfunction(library, offset, my_vec).
	The third parameter might instead be the pointer to the func
	descriptor returned by the original SafeSetfunction call. In any
	case that func descriptor is removed from its point in the middle
	of the list; if any other SafeSetfunctions are still in effect,
	they will now work correctly so long as they scan one place down
	the list to retrieve the old vector. This old vector may be
	a replacement vector from another program or the original system
	one, but it's guaranteed to be one that's current and valid.

I think with a bit of planning this could be made to work without any changes
to the library structure at all. I doubt the function call overhead would
be raised by a non-trivial amount, since instead of jumping through a
vector you were returned, you'd only need to do one pointer reference,
one move, and then the jump. 

As for breaking programs that already use Setfunction, I think Setfunction's
internal workings could be massaged well enough so that programs which used
it would only break in the same cases as they do know, ie multiple
Setfunctions on the same vector with bad restoration order. Over a period
of time Setfunctioning programs could be upgraded, since only a few lines
of code would need to be added and they would be standard for all such cases.

John
-- 
"Families of Murder Victims bring Human Face to Court Proceedings"
		-- Gets my vote as most poorly-worded headline of the year

bart@amiga.UUCP (Barry A. Whitebook) (11/15/88)

In article <4995@garfield.MUN.EDU> john13@garfield.MUN.EDU (John Russell) 
writes:
)
)On a couple of recent occasions I have been tempted to use Setfunction() to
)make things safer when doing not-entirely-safe things, just by adding a
)test "does this call relate to me? If not pass it, else shut down then call
)the function over again to let it go through".
)
)However it seems that unless your new function is the big enchilada in terms
)of replacement functions this approach may be unsafe as well, as in the
)case where different people Setfunction a vector and then don't exit in 
)exactly the same order, leading to the vector pointing to a defunct routine.
)
)Since we already have very expandable ways to add chains of input handlers,
)devices, interrupt servers, etc. why not make Setfunction (or a new
)similar function) just as good?
)

prior to the april dencon3 in washington d.c. i invested some real work in
creating the framework for this exact SetFunction() replacement.  the name
of these nodes was (perhaps unfortunately) system "Wedge"s.  System Wedges
are as safe as one can reasonably get in terms of multitasking and avoiding
potential race conditions.

while there has currently been no hard decision to include a safer setfunction()
in V1.4, i would like very much to be able to use the Wedge code as the basis
for such a SafeSetFunction().  details on the proposed procedures are included
as part of the 1.3 devcon notes, under the heading "Creating your own Libraries
and Leveraging off existing ones" including discussion of the more subtle 
multitasking considerations.  

source code examples can be found on the devcon3 code disk. 
your comments on this code are welcomed.