home *** CD-ROM | disk | FTP | other *** search
/ Shareware 1 2 the Maxx / sw_1.zip / sw_1 / PROGRAM / SPAWNO40.ZIP / SPAWNO.DOC < prev    next >
Text File  |  1991-11-17  |  20KB  |  434 lines

  1. SPAWNO v4.00    11/17/91    disk/EMS/XMS/INT15 swapping replacement for spawn()
  2. (c) Copyright 1990,1991 Ralf Brown.  All Rights Reserved.
  3.  
  4.  
  5. -----------------
  6. LICENSE
  7.  
  8. This document and the associated header file, libraries, and source and
  9. object modules may be freely copied provided that:
  10.      1) all of the files are copied as a group (such as in a single
  11.     archive).  See below for a list of files.
  12.      2) the files are not modified in any way (including removal or
  13.     alteration of copyright notices or this license)
  14.      3) no charge beyond a cost-recovery fee not to exceed $5, or a
  15.     general telecommunications connection fee, is made
  16.  
  17. The source and/or object code comprising the public SPAWNO distribution
  18. may be incorporated at no charge into programs which are distributed or
  19. sold to others provided that:
  20.      1) credit is given in the documentation.  A mention such as
  21.        "This product uses the SPAWNO routines by Ralf Brown
  22.         to minimize memory use while shelling to DOS and
  23.         running other programs."
  24.     is sufficient.
  25.      2) you drop me a line telling me that you are using SPAWNO and
  26.     in which product(s) you are using it (see addresses at the
  27.     end of this file).  I'm interested in finding out how wide-
  28.     spread the use of SPAWNO becomes.
  29.  
  30.  
  31. -----------------
  32. DISCLAIMER
  33.  
  34. Although both I and others have tested the code which comprises SPAWNO,
  35. it is entirely possible that SPAWNO may malfunction in environments or
  36. under circumstances in which it has not been tested.  This code is
  37. provided AS IS, and the author disclaims any and all responsibility for
  38. damages (both consequential and incidental) resulting from the use or
  39. misuse of SPAWNO.  Sole responsibility for determining the suitability
  40. of the code rests with the user.
  41.  
  42.  
  43. -----------------
  44. FILES
  45.  
  46. The disk or archive you received should contain the following files:
  47.  
  48.     SPAWNO.DOC    this file
  49.     SPAWNO.H    the header file providing prototypes for the functions
  50.     SPAWNx.LIB    versions of the library for each of [T]iny, [S]mall,
  51.             [C]ompact, [M]edium, [L]arge, and [H]uge memory
  52.             models.
  53.     SPAWNTP.OBJ    Turbo Pascal version of SPAWNO
  54.     SPAWNO.PAS    Turbo Pascal unit encapsulating SPAWNO
  55.     SPAWN_MS.ZIP    Microsoft C versions of compiler-specific functions
  56.     MSC.BAT        replace Turbo C specific functions in libraries with
  57.             Microsoft C versions.
  58.     NOREPLAC.BAT    remove replacements for the standard spawn..()
  59.             functions from the libraries.
  60.     SWAPTEST.C    example program for testing
  61.     TEST.PAS    example program for testing
  62.     SPWNOSRC.ZIP    archive containing partial source code for SPAWNO
  63.         _SPAWNO.H        header file for recompiling library
  64.         *.C            source for the spawn..() and spawn...o() functions
  65.         RULES.ASI        shortened and modified Turbo C macro file
  66.         SPAWNO.INC        include file for various important constants
  67.         SPAWNPTH.ASM    source for the path search
  68.         CHECKEXT.ASM    check for 'file', 'file.EXE', and 'file.COM'
  69.         SWAP_EMS.ASM    support routines for swapping to EMS
  70.         SWAPLIST.ASM    specify which swap types will be linked in
  71.         SPAWNENV.ASM    make an environment block from an array of strings     
  72.         SPAWNERR.ASM    set _doserrno and errno
  73.         MAKEFILE
  74.  
  75. -----------------
  76. INSTALLATION
  77.  
  78. If you are using Turbo C, Turbo C++, or Borland C++, simply dearchive
  79. the libraries and header file and place them where your compiler can
  80. find them.  If you are using Microsoft C, dearchive SPAWN_MS.ZIP and
  81. then run the MSC batch file to replace the compiler-specific functions
  82. in the libraries with Microsoft C versions.  Please do not run this
  83. batch file on your original copy of the libraries.
  84.  
  85. If you are using Turbo Pascal, unarchive SPAWNTP.OBJ and SPAWNO.PAS.
  86. Compile SPAWNO.PAS and then add a USES SPAWNO; line to your program.
  87. After that you can call the function SPAWN() as desired.  The
  88. distribution does not contain a pre-compiled version because .TPU
  89. files are not compatible between different versions of Turbo Pascal.
  90.  
  91.  
  92. -----------------
  93. INSTRUCTIONS
  94.  
  95. As distributed, SPAWNO contains replacements for the standard spawn..()
  96. functions.  You can use SPAWNO with absolutely no changes to your
  97. existing source code; however, you will probably want to call
  98. init_SPAWNO() from main(), and include SPAWNO.H for that source file.
  99. The initialization function takes two arguments: the first is a string
  100. containing a list of directories (separated by semicolons) in which to
  101. attempt to store the swap file when swapping to disk. The second
  102. specifies which swap devices to attempt to use; it may be either
  103. SWAP_ANY or the ORing or addition of any combination of SWAP_DISK,
  104. SWAP_EMS, SWAP_EXT, and SWAP_XMS (such as SWAP_DISK|SWAP_XMS).    If you
  105. do not call init_SPAWNO(), the defaults are to attempt all swap devices
  106. and to store the swap file in the current directory when swapping to
  107. disk.  init_SPAWNO() will set the swap file directory list to the first
  108. of the following to have a non-NULL, non-empty value: the environment
  109. variable SWAPDIR, the passed parameter, the environment variable TEMP,
  110. and the environment variable TMP.
  111.  
  112. After making the above change, recompile your existing code, but include
  113. the SPAWNO library in the link step.  Note that SPAWNO does not support
  114. the P_OVERLAY spawn type--any calls using that argument should be
  115. replaced with the corresponding exec..() function.  If a SPAWNO function
  116. is called with P_OVERLAY, it simply returns an error.
  117.  
  118. For backwards compatibility with previous versions of SPAWNO, and for
  119. those who (for whatever reason) require the use of both the swapping and
  120. standard spawn..() functions, there is a second set of functions which
  121. take an explicit swap directory argument.  To use them, include the
  122. header file SPAWNO.H.  Then use the functions provided in this
  123. archive--spawnvo(), spawnlo(), spawnvpo(), etc--as you would the
  124. corresponding spawnv(), spawnl(), etc, except replace the first argument
  125. by a string containing the path where the swap file is to be stored.
  126. Note that the swap file path is required even when swapping to XMS, EMS,
  127. or plain extended memory, as SPAWNO will swap to disk anyway if there is
  128. not enough memory available.
  129.  
  130. If you require the use of both the swapping and standard spawn..()
  131. functions, you will need to run the NOREPLAC.BAT batch file to remove
  132. the modules containing the replacements for the standard functions or
  133. arrange the linker command line such that SPAWNx.LIB is listed after the
  134. standard runtime library (for Turbo/Borland C users, the latter requires
  135. a separate TLINK command, as TCC/BCC places any libraries specified on
  136. the command line prior to the runtime library).     Please do not run
  137. NOREPLAC on your original copy of the libraries, as the process is
  138. destructive and cannot be reversed.
  139.  
  140. The spawn?p??() functions search for both .COM and .EXE files in the
  141. current directory and then in the pathed directories if no extension is
  142. given, but use the specified extension if present.  If a full pathname
  143. is given to those functions, only the specified directory is searched.
  144. If both a path and an extension are given, only that specific file will
  145. be loaded.  The other spawn..() functions check the current directory
  146. only; if the specified filename does not contain an extension, .COM and
  147. .EXE will be tried if the extension-less file does not exist.
  148.  
  149. When linking, you must include SPAWNx.LIB.  A sample TCC line would be
  150.  
  151.     tcc -mc <other-flags> sample spawnc.lib library.lib
  152.  
  153. This results in 208 to 288 bytes remaining in memory (depending on swap
  154. type) while the spawned program executes.  However, if you want to keep
  155. an interrupt hooked which might be invoked while spawned, you must set
  156. __spawn_resident large enough that *all* code and data which could be
  157. invoked by that interrupt is kept resident[1].    SPAWNO automatically
  158. deactivates INT 23h and INT 24h and restores them before returning to
  159. the caller unless __spawn_keepints is set to 1, so no extra work is
  160. required if those two are the only interrupts hooked by the program.
  161.  
  162. ----
  163. [1] Due to the segment layout used by C compilers, this option is probably
  164.     useful only when calling SPAWNO from assembly-language code (which can
  165.     localize such code and data near the start of the executable) or a
  166.     small program which uses a large amount of space in the far heap.
  167.  
  168.  
  169. -----------------
  170. ERROR MESSAGES
  171.  
  172. SPAWNO: stack too small, retrying
  173.     SPAWNO did not correctly determine the stack requirements for
  174.     the system on which it is running, but was able to determine
  175.     that the specified minimum size is insufficient.  On the retry,
  176.     the stack size is increased by one paragraph.  Since SPAWNO
  177.     cannot always detect the problem, which would result in
  178.     memory chain corruption, you should increase the value of
  179.     __spawn_res_stack to prevent a recurrence of this error
  180.     message.  For most systems, the default value of 4 paragraphs
  181.     will be sufficient.
  182.  
  183. SWAP ERR
  184.     The resident stub detected an error while trying to reload the
  185.     main portion of the program and aborted.  This may be due to
  186.     loading a TSR while swapped out or deleting the swap file.
  187.  
  188. SPAWNO: error reloading program, aborting
  189.     The main portion of SPAWNO detected an error while attempting
  190.     to restore the remainder of the program to memory.
  191.  
  192.  
  193. -----------------
  194. LIMITATIONS
  195.  
  196. After freeing all memory owned by the program except the initial (PSP)
  197. memory block and the environment, at least 384 bytes of conventional
  198. memory must be available.  SPAWNO uses this for its temporary stack.
  199. This is of particular importance for the Turbo Pascal variant, because
  200. setting the maximum heap size to the available memory or greater will
  201. use up all RAM and prevent SPAWNO from allocating its temporary stack
  202. unless memory is fragmented or there is DOS 5 high memory available.
  203.  
  204. SPAWNO may report insufficient memory even though the program to be
  205. executed would fit with up to 600 bytes to spare, due to the fact that
  206. part of the stack and all of the data used by DOS to start the program
  207. may be overwritten after the child program starts executing.
  208.  
  209. Functions which pass an explicit environment attempt to allocate enough
  210. memory to build the environment block which is passed to the DOS EXEC
  211. function.  If neither malloc() nor a DOS memory allocation request are
  212. successful, SPAWNO passes the original environment rather than the
  213. specified environment.
  214.  
  215. As distributed, SPAWNO functions which do not take an explicit
  216. environment pointer pass the calling program's original environment to
  217. the child, rather than the current environment as modified by putenv().
  218. You may recompile SPAWNO to pass the current environment (see
  219. _SPAWNO.H); if you do so, the caveat discussed in the previous paragraph
  220. will apply to all of the spawn..() functions.
  221.  
  222.  
  223. -----------------
  224. SUPPORT
  225.  
  226. Since I am not getting any money, I can't promise any support.    Those
  227. who have purchased the complete source code will receive priority over
  228. those who haven't, but even they will only receive support to the
  229. extent that I have spare time....
  230.  
  231.  
  232. -----------------
  233. ACKNOWLEDGEMENTS
  234.  
  235. Thanks to Gene McManus for testing the Microsoft versions of SPAWNO 3.0
  236. and 4.0.
  237.  
  238.  
  239. -----------------
  240. FUTURE PLANS
  241.  
  242. The next release will drop support for DOS 2.x (which is now over
  243. seven years old) to reduce the code size and further reduce the size
  244. of the resident stub.
  245.  
  246.  
  247. -----------------
  248. SPAWNO versus THE COMPETITION
  249.  
  250. Product:        SPAWNO        XSPAWN        SWAP
  251. Version:         4.00         1.34         1.0
  252. Author:             Ralf Brown      Whitney Software  Marty Del Vecchio
  253. Memory models:        tsmclh        tsmclh         tsm
  254. Supported DOS vers:    2.0-5.0           2.1-5.0          3.0-5.0
  255. Code size [1]:           4.2-5.6K           4.4-9K         1.5K
  256. Resident stub (bytes): 208-288          1277+2*env     1.8K+env [2]
  257. Direct replacement for
  258.     spawn..():         yes         yes          no
  259. Use in existing code
  260.     without changes:     yes          no          no
  261. Swap to disk:         yes         yes         yes
  262. Swap to EMS:         yes         yes         yes
  263. Swap to XMS:         yes          no          no
  264. Swap to INT 15h ext:     yes          no          no
  265. Multiple swap dirs:     yes         yes          no
  266. Automatic unique swap
  267.     file naming:     yes         yes          no
  268. May leave interrupts
  269.     hooked [3]:         yes          no         yes
  270. Swaps DOS5 high memory:     yes           ?           ?
  271. Free for any use:     yes         yes         yes
  272. Source included:       partial [4]     yes         yes
  273.  
  274. Notes:
  275. [1] For both SPAWNO and XSPAWN, the amount added to the executable's
  276.     size depends on which functions of the library are called and which
  277.     of the additional C runtime library function that are called by
  278.     SPAWNO/XSPAWN would have been included anyway.  SPAWNO's size may
  279.     be reduced by removing one or more swap types; the savings are
  280.     about 400 bytes per swap type (without EMS and non-XMS (INT 15h)
  281.     swapping, SPAWNO would add as little as 3.4K to the executable).
  282.  
  283. [2] SWAP's resident size depends on the location of the object code
  284.     within the executable.  The size reported here is the resident
  285.     size when SWAP immediately follows the Turbo C 2.0 startup code.
  286.  
  287. [3] For SPAWNO, enough of the program must be left in memory to keep all
  288.     interrupt handlers resident.  XSPAWN has no provision for keeping
  289.     an interrupt handler resident unless swapping is disabled; it does
  290.     however permit selection whether a given interrupt handler will
  291.     automatically be restored to its original value or pointed at an
  292.     IRET instruction while swapped out.     For SWAP, the swapper module
  293.     must be linked in after all code and data which might be accessed
  294.     by the interrupt handler(s).
  295.  
  296. [4] Full SPAWNO source code is available for purchase.    See ORDER.FRM for
  297.     details.
  298.  
  299.  
  300. -----------------
  301. Functions:
  302.     void init_SPAWNO(const char *swap_directories, int swap_types) ;
  303.  
  304.     /* replacements for the standard functions */
  305.     int spawnv(int type, const char *name, const char **args) ;
  306.     int spawnvp(int type, const char *name, const char **args) ;
  307.     int spawnve(int type, const char *name, const char **args,
  308.             const char **env) ;
  309.     int spawnvpe(int type, const char *name, const char **args,
  310.              const char **env) ;
  311.     int spawnl(int type, const char *name, const char *argv0, ...) ;
  312.     int spawnlp(int type, const char *name, const char *argv0, ...) ;
  313.     int spawnle(int type, const char *name, const char *argv0, ...) ;
  314.     int spawnlpe(int type, const char *name, const char *argv0, ...) ;
  315.     int system(const char *command) ;
  316.     /* Note: the above functions return -1 (error) if 'type' is not */
  317.     /*     P_WAIT     */
  318.  
  319.     /* SPAWNO-specific functions */
  320.     int spawnvo(const char *overlay_path, const char *name,
  321.             const char **args) ;
  322.     int spawnvpo(const char *overlay_path, const char *name,
  323.              const char **args) ;
  324.     int spawnveo(const char *overlay_path, const char *name,
  325.              const char **args,const char **env) ;
  326.     int spawnvpeo(const char *overlay_path, const char *name,
  327.              const char **args,const char **env) ;
  328.     int spawnlo(const char *overlay_path, const char *name, ...) ;
  329.     int spawnlpo(const char *overlay_path, const char *name, ...) ;
  330.     int spawnleo(const char *overlay_path, const char *name, ...) ;
  331.     int spawnlpeo(const char *overlay_path, const char *name, ...) ;
  332.     int systemo(const char *overlay_path, const char *command) ;
  333.  
  334. Global variables:
  335.        char __spawn_xms ;
  336.         Specify whether to use XMS memory for swapping (if available).
  337.         0 = no, 1 = yes, default = 1
  338.         This variable is set by init_SPAWNO().
  339.        char __spawn_ems ;
  340.         Specify whether to use EMS memory for swapping (if available).
  341.         0 = no, 1 = yes, default = 1
  342.         This variable is set by init_SPAWNO().
  343.        char __spawn_ext ;  /* 0 = don't use non-XMS extended memory for swap */
  344.         Specify whether to use non-XMS extended memory (via INT 15h) for
  345.         swapping (if available).  0 = no, 1 = yes, default = 1
  346.         This variable is set by init_SPAWNO().
  347.         Note: SPAWNO should not be allowed to swap to extended memory if
  348.         running under a multitasker or task switcher, as other programs
  349.         would be able to grab the same memory used by SPAWNO to store the
  350.         swapped-out program.  For this reason, SPAWNO automatically
  351.         disables swapping to non-XMS extended memory if it detects that
  352.         TopView, DESQview, or any other TopView API-compatible multi-
  353.         tasker is active, or the DOS 5 task switcher is loaded, or
  354.         MS Windows 3 is running in real or standard mode (enhanced mode
  355.         is not readily detectable from a program, unfortunately).
  356.        const char *pascal ___spawn_swap_dirs ;
  357.         Specify the list of directories in which to attempt to store
  358.         the swap file when swapping to disk.  The directories are
  359.         separated by semicolons just as they would be in the PATH
  360.         environment variable.  Default = "." (current directory)
  361.         This variable is set by init_SPAWNO().
  362.         Note: SPAWNO will not swap to disk if this variable is set to an
  363.         empty string; if it is set to NULL, SPAWNO will use the default
  364.         of ".".
  365.        char __spawn_keepints ;
  366.         Specify whether to deactivate INT 23h and INT 24h handlers by
  367.         temporarily restoring the vectors stored in the PSP.
  368.         0 = no, nonzero = yes, default = 0
  369.        char __spawn_swap_UMA ;
  370.         Specify whether to swap out memory blocks in the upper memory
  371.         area (640K-1M).  0 = no, 1 = yes, default = 1
  372.         Note: This option only has an effect under MSDOS 5.0 with the
  373.         line DOS=UMB or DOS=HIGH,UMB in CONFIG.SYS.
  374.        unsigned __spawn_resident ;
  375.         Specify the minimum number of paragraphs in the memory block
  376.         containing the PSP to keep resident while in the child program.
  377.         This value will be increased if necessary to be large enough to
  378.         hold the swapping code; it may also be increased slightly if it
  379.         causes the end of the shrunken PSP block to fall within a
  380.         specific section of SPAWNO's code.  You may force the entire
  381.         main block to stay in memory by setting this variable to 0xFFFF;
  382.         however, the environment and any additional memory blocks
  383.         allocated by the program will still be swapped out.  default = 0
  384.         Note: in addition to the PSP memory block, a small second block
  385.         is used for the stack needed by the swapping code (see below).
  386.        unsigned __spawn_res_stack ;
  387.         Specify the minimum number of paragraphs of the stack to keep
  388.         resident while in the child program.  Default = 4, minimum = 2
  389.         (two paragraphs is only sufficient for bare DOS; TSRs which
  390.         hook INT 21h will increase the stack requirements, but four is
  391.         sufficient for most systems).  SPAWNO attempts to compute the
  392.         necessary stack size, but this variable allows the computed
  393.         value to be overridden if necessary.
  394.  
  395. External functions called by SPAWNO:
  396.     malloc()   \ only when passing an array of environment strings
  397.     free()       /
  398.  
  399. External variables referenced by SPAWNO:
  400.     int errno ;
  401.     int _doserrno ;
  402.     unsigned int _psp ;
  403.     char **environ ;  (only when passing an array of environment strings)
  404.  
  405. Other:
  406.     This version of SPAWNO overwrites the PSP, so the commandline
  407.     will be lost unless it was copied before the first spawn().
  408.  
  409.  
  410. -----------------
  411. Functions (Turbo Pascal):
  412.     init_SPAWNO(swap_dirs : string ; swap_types : integer ;
  413.             min_resident : integer ; resident_stack : integer) ;
  414.     spawn(program_name : string ; arguments : string ;
  415.           envseg : integer) : integer ;
  416.  
  417. Global Variables (Turbo Pascal):
  418.     spawno_error : integer ;   (error code when spawn() returns -1)
  419.  
  420.  
  421. -----------------
  422. Send comments, bug reports, etc. to
  423.  
  424.      Internet: ralf+@cs.cmu.edu
  425.      Fidonet:  Ralf Brown 1:129/26.1 (or post a message to me on DR_DEBUG--I
  426.                      have to route netmail outside Zone 1
  427.                      via Internet -> Fidonet gateways, which
  428.                      is not always reliable)
  429. or
  430.      Ralf Brown
  431.      Suite #26
  432.      813 Copeland Way
  433.      Pittsburgh, PA 15232
  434.