richard@calvin.spp.cornell.edu (Richard Brittain) (04/08/90)
Hi, I'm wondering if anyone has tried to "roll their own" spawn() with TC. I am trying to minimise the resident code after running a child program, and spawn() links in a bunch of stuff I don't need, and adds over 2k - mostly dealing with setting up the FCB structures on the offchance that some archaic program still needs them. I have a working version, setting up the parameter blocks, pointing the registers in the right places and calling function 4Bh, but it seems to be very flaky. A rather high percentage of the programs I try to run this way cause a crash (4B returns error code 8 - not enough memory and the MCB structure is wrecked so that any future attempt to allocate or deallocate memory locks up the machine). When I have one that works, it at least works consistently. There is never really not enough memory. So, does anyone have any experience of "gotchas" using this function, which presumable the spawn() library code works around? I already figured out that the command line has to begin with a space or DOS is very unhappy, and it seems to like a trailing space also. I am sticking null pointers in for the address of the FCB's which DOS puts in the PSP of the child, since I know they will not be used. It seems to behave just the same if I actually stick empty FCB's in though. thanks Richard Brittain, School of Elect. Eng., Upson Hall Cornell University, Ithaca, NY 14853 ARPA: richard@calvin.spp.cornell.edu UUCP: {uunet,uw-beaver,rochester,cmcl2}!cornell!calvin!richard
fredex@cg-atla.agfa.com (Fred Smith) (04/09/90)
In article <1990Apr8.073952.5936@calvin.spp.cornell.edu> richard@calvin.spp.cornell.edu.UUCP (Richard Brittain) writes: >Hi, > I'm wondering if anyone has tried to "roll their own" spawn() with >TC. >So, does anyone have any experience of "gotchas" using this function, which >that the command line has to begin with a space or DOS is very unhappy, and >Richard Brittain, School of Elect. Eng., Upson Hall > Cornell University, Ithaca, NY 14853 Well, on some versions of DOS function 4B is not very polite, and when it returns from the child, it leaves ALL the registers except CS/IP in a condition known in the trade as "trashed". This means that you cannot reliably call DOS function 4B from within a piece of C code. Rather you need to have a short assembler interlude which contains enough space in the CODE segment for you to save the CS/IP immediately before the INT 21h, and the very next thing you need to do is restore the stack. I am assuming, of course, that you previously saved everything you care about (like the registers, for example) on the stack, so that you can pop them off once you have restored the SP after returning from the DOS call. I once wrote a system() in assembler for use with Small-C, and discovered all this the hard way. Later someone pointed me to the discussion in Ray Duncan's Advanced MS-DOS, which explains it all nicely, along with an example, even. have fun! Fred
cs4g6ag@maccs.dcss.mcmaster.ca (Stephen M. Dunn) (04/11/90)
Are you keeping in mind that the only registers that are preserved across the MS-DOS EXEC call are CS:IP? I've never rolled my own spawn() for C, but I did it a couple of times for Turbo Pascal 3 (but I've lost the code ... I just checked) and never had any problems with it. -- More half-baked ideas from the oven of: **************************************************************************** Stephen M. Dunn cs4g6ag@maccs.dcss.mcmaster.ca <std_disclaimer.h> = "\nI'm only an undergraduate ... for now!\n";