www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/07/27/08:28:00

Message-Id: <m0z0mMW-000S4WC@inti.gov.ar>
Comments: Authenticated sender is <salvador AT natacha DOT inti DOT gov DOT ar>
From: "Salvador Eduardo Tropea (SET)" <salvador AT inti DOT gov DOT ar>
Organization: INTI
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>, djgpp-workers AT delorie DOT com
Date: Mon, 27 Jul 1998 09:36:27 +0000
MIME-Version: 1.0
Subject: Pipes

Hi All:

*Note: this technique needs some changes and works only with modified
       programs but looks like there is no way to do it without
       modifications. Not at least in DOS where we must make the task switch
       stuff.*

  I was trying to implement the following approach:

1) There are a program that acts like a shell. This program is the one that
starts the djgpp programs.
2) The shell have a table of running programs, each entry in the table
indicate if stdout, stderr and/or stdin are redirected to another program
and the index of this program in the table.
3) Each entrie have all the needed information to longjmp to this program at
right point.
4) Each program have a "handle", this information is passed to the program
as parameters (the handle and the information to longjmp to the shell).
That's just to experiment, it can be replaced by a better method. For
example: using a pmode interrupt hook. So the programs check if the shell is
running and gets this information at startup.
5) I'm not using pmode interrupts because the libc manual clearly says:

*Warning!* Because of the way DPMI works, you may *not* `longjmp' out
of an interrupt handler or perform any system calls (such as `printf')
from within an interrupt handler.

Now what I was able to do:
I was able to tell to the shell to start a program A and this program asked
to the shell to start a program B. Then B just exit, A gets the return value
of B, exits and the shell exits. All the sequence without hanging ;-)
So it works but my main problem is how to call the programs. Currently I'm
using it:

Each entry in the table have a 128Kb stack (less doesn't work) so the shell
uses this stack to spawn this program. Why? because spawn returns only when
the program exit and in the middle time other threads of the shell will be
running so I can use the same stack or spawn will hang when the program ends.
It partially work, looks like something have re-entrancy problems in spawn.

I don't like this technique because:
1) I need huge stacks.
2) We must change spawn to be fully re-entrant.
3) There are a potential problem: if A finishes before B the DPMI host could
get confused and release the resources of B (Charles says all works like an
stack). I don't know how dangerous could it be.

So I preffer an approach using v2loadimage but:
 How can I get the CPU when a program ends? I mean: I load a program with
v2loadimage and then longjmp to it, but when the program ends it calls DOS
and the shell ends.
I know I can hook the int 31 and look for int 21 calls but that isn't good
because in this case we are inside an interrupt routine and we can't longjmp
out of it.
The only way I think could work is allowing the program to choose between
ending with an int 21 or longjmp'ing somewhere. That's a very complex stuff,
can somebody explain the djgpp exit sequence?

Lamentably looks like we must do a lot of things in the hard way because the
DPMI servers aren't designed to handle such a things so RMCBs or pmode
interrupts can't be used.

Perhaps another solution to the v2loadimage could be:
The programs hooks the exit sequence while it still in pmode and before
releasing all the resources. I think at _exit level and before __exit and
gives the control to the shell passing all the information needed to make the
clean up from the shell side so the shell releases the memory of the program
and other stuff. But the point must be very well selected.

SET


------------------------------------ 0 --------------------------------
Visit my home page: http://set-soft.home.ml.org/
or
http://www.geocities.com/SiliconValley/Vista/6552/
Salvador Eduardo Tropea (SET). (Electronics Engineer)
Alternative e-mail: set-soft AT usa DOT net set AT computer DOT org
ICQ: 2951574
Address: Curapaligue 2124, Caseros, 3 de Febrero
Buenos Aires, (1678), ARGENTINA
TE: +(541) 759 0013

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019