[comp.os.vms] User mode AST and user stack

LEICHTER@VENUS.YCC.YALE.EDU ("Jerry Leichter ", LEICHTER-JERRY@CS.YALE.EDU) (07/05/88)

	The Compiler Construction Laboratory here at EPFL is in the process of
	implementing a multi tasking environment for a language on the VAX.
	They have faced the classical problem of sharing of the stack between
	several tasks. Obviously, the better solution is to allocate a stack
	for each task. The problem is how to dimension it. The compiler can of
	course compute the requirements for a task, but it cannot know the
	requirements for VMS. For the system services calls, they have found a
	solution. But it remains the user mode AST.

	As far I as know VMS, a user mode AST execute on the user mode stack.

Basically true.

	But as each task has a different stack dimensionned for it's own use,
	if an unexpected AST (as are most of them) occurs, a stack overflow
	will surely happen.

Why?  On the stack, an AST basically looks like a normal procedure call frame.
Besides the documented AST information, there are a couple of extra longwords
for a frame that points back into a system routine that will really dismiss
the AST.  The number of such longwords is small, fixed, and easily determin-
able - though of course as undocumented as the amount of stack space a system
call might use.  If you calculate the amount of stack needed for the code,
then add enough for one AST, plus whatever the AST routine itself might need,
you will be quite safe.  Note that AST's cannot nest at any one access level -
you don't have to worry about two AST's on the user stack at the same time!

	My questions are:

	- Is there a way to filter the AST's (the scheduler in the
	  multi-tasking kernel is implemented with an AST !)

I have no idea what this means.

	- Is there a way to trap an AST, i.e. to execute a piece of code of
	  the multi-tasking kernel which will take the necessary precautions?

The AST routine is exactly this trap.

If your concern is that you can't predict what other routines the AST routine
might call, leave enough extra space for one AST frame, and then have the
AST routine immediately switch over to some other stack.

	This problem has already been solved, I'm sure (in VAX Ada, for
	example).  Please respond to me directly, I'll summarize for the net.

Well, more or less.  In Ada, it's up to you to allocate a large enough stack,
where "large enough" must included room for any AST's.  There's really no way
for an Ada compiler to figure out just how deeply calls might nest.  In fact,
I'm rather puzzled by your claim that your compiler can figure this out -
sounds uncomputable, for any universal language.  (A compiler COULD add
prologue code at the beginning of each routine to check if enough space to
execute that routine was available.  Adding a bit extra for the AST frame
would work just fine.)
							-- Jerry