home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / msysjour / vol05 / 05 / swap / exec.doc < prev    next >
Text File  |  1990-09-01  |  8KB  |  204 lines

  1.  
  2.               An EXEC function with memory swap
  3.               =================================
  4.  
  5.         Thomas Wagner
  6.         Ferrari electronic GmbH
  7.         Beusselstrasse 27
  8.         D-1000 Berlin 21
  9.         West Germany
  10.  
  11. Version 2.2, released 90-08-16.
  12.  
  13. This archive contains the sources for an 'EXEC' function that
  14. optionally swaps out the memory image of the calling program to a
  15. temporary file or to EMS, and shrinks down to a minimal core before
  16. executing the program.
  17.  
  18. This allows chaining or spawning to memory-hungry programs, and it
  19. eases building of DOS menu-systems. The memory used when swapping is
  20. less than 1k, plus the memory needed for a copy of the environment. If
  21. you pass a new environment to the spawned program, space for two
  22. copies of the environment are needed.
  23.  
  24. EMS (LIM 3.0 or above) is used automatically if there is enough space
  25. left, otherwise a temporary file is created. If the "TEMP=" or "TMP="
  26. environment variable is present, the temporary file is created in the
  27. directory specified by this variable, otherwise it is created in the
  28. current directory.
  29.  
  30.  
  31.                         CHANGES
  32.                         =======
  33.  
  34. Changes from version 1.0 to 2.0:
  35.  
  36. 1) Problem fixes
  37.  
  38. - Problems with EMS drivers that return handles above 255 have been
  39.   fixed.
  40.  
  41. - Bug that prevented deletion of temporary file has been fixed.
  42.  
  43. - The Division by Zero interrupt vector is patched to an IRET and
  44.   restored when swapping back in.
  45.  
  46.  
  47. 2) Enhancements
  48.  
  49. - The TMP/TEMP environment string is checked for validity, and
  50.   is ignored if it points to a non-existent directory.
  51.  
  52. - For DOS versions 3.0 and above, the temporary file is created using
  53.   the special DOS function. This eliminates the extra overhead for
  54.   generating a unique filename.
  55.  
  56. - Now compatible with Microsoft C 5.x.
  57.  
  58. - Non-contiguous memory blocks can be swapped.
  59.  
  60. - The 'spwn' parameter to the do_exec function has been changed to
  61.   allow EMS usage to be controlled. It can now have the values -1, 0,
  62.   and 1. The internal assembler routine takes an additional method
  63.   parameter, it no longer uses the first byte of the swap-filename
  64.   to determine swapping method.
  65.  
  66.  
  67. Changes from version 2.0 to 2.2:
  68.  
  69.   Several bugs in spawn.asm were fixed, no other changes.
  70.  
  71.  
  72.                         INTERFACE
  73.                         =========
  74.  
  75.         extern int do_exec (char *xfn, char *pars, int spwn,
  76.                             unsigned needed, char **envp);
  77.  
  78.  
  79. Parameters:
  80.             xfn         is a string containing the name of the file
  81.                         to be executed. If the string is empty,
  82.                         the COMSPEC environment variable is used to
  83.                         load a copy of COMMAND.COM or its equivalent.
  84.                         If the filename does not include a path, the
  85.                         current PATH is searched after the default.
  86.                         If the filename does not include an extension,
  87.                         the path is scanned for a COM or EXE file in
  88.                         that order.
  89.  
  90.             pars        The program parameters.
  91.  
  92.             spwn        If 1, the function will return, if necessary
  93.                         after swapping the memory image.
  94.                         If -1, EMS will not be used when swapping.
  95.                         If 0, the function will terminate after the
  96.                         EXECed program returns.
  97.                         NOTE: If the program file is not found,
  98.                         the function will always return
  99.                         with the appropriate error code, even if
  100.                         'spwn' is 0.
  101.  
  102.             needed      The memory needed for the program in
  103.                         paragraphs. If not enough memory is free, the
  104.                         program will be swapped out. Use 0 to never
  105.                         swap, $ffff to always swap. If 'spwn' is false,
  106.                         this parameter is irrelevant.
  107.  
  108.             envp        The environment to be passed to the spawned
  109.                         program. If this parameter is NULL, a copy
  110.                         of the parent's environment is used (i.e.
  111.                         'putenv' calls have no effect). If non-NULL,
  112.                         envp must point to an array of pointers to
  113.                         strings, terminated by a NULL pointer (the
  114.                         standard variable 'environ' may be used).
  115.  
  116.  
  117. Return value:
  118.  
  119.             0000..00FF: The EXECed Program's return code
  120.             (0..255 decimal)
  121.             0100:       Error writing swap file
  122.             (256 decimal)
  123.             0200:       Program file not found
  124.             (512 decimal)
  125.             03xx:       DOS-error-code xx calling EXEC
  126.             (768..1023 decimal)
  127.             0400:       Error allocating environment buffer
  128.             (1024 decimal)
  129.  
  130.  
  131.  
  132.                         RESTRICTIONS
  133.                         ============
  134.  
  135. The calling program may not have interrupt handlers installed when
  136. calling the do_exec function. This includes handlers for Control C
  137. and critical errors.
  138.  
  139. All open files will stay open during the EXEC call. This reduces the
  140. number of handles available to the child process. The "C_FILE_INFO"
  141. environment variable created by the standard C spawn is not supported.
  142.  
  143. BAT-files and internal commands are not automatically processed. You
  144. can execute those by calling the do_exec function twice, for example:
  145.  
  146.      retcode = do_exec ("dir", "*.*", 1, 0xffff, environ);
  147.      if (retcode == 0x200)
  148.         retcode = do_exec ("", "/c dir *.*", 1, 0xffff, environ);
  149.  
  150.  
  151.                         CAUTIONS
  152.                         ========
  153.  
  154. The functions should be compatible with DOS versions down to DOS
  155. 2.21, but they have been tested under DOS 3.3 and DOS 4.0 only.
  156.  
  157. Spawning a command that exits and stays resident (TSR), like PRINT or
  158. Sidekick, will fragment memory and prevent a return to the calling
  159. program. This should, however, not crash the system. Allocated EMS
  160. pages are released, but a swap file is not deleted.
  161.  
  162. The memory image of the calling program should be contiguous. This
  163. is always guaranteed if you use the standard Turbo C allocation
  164. routines only. The swapper is able to swap non-contiguous blocks such
  165. as those created by the Microsoft far allocation routines. However,
  166. to do this, the swapper has to use undocumented fields in the memory
  167. control blocks, and modify DOS memory control blocks directly. This
  168. may lead to incompatibilities in later versions of DOS, or in DOS
  169. substitutes or emulators.
  170.  
  171. When debugging the assembler module, take care not to set breakpoints
  172. in the code while it is being swapped out. Those breakpoints (INT 3
  173. instructions) will be swapped back in later without the debugger
  174. knowing about it, and cause quite strange results when you run through
  175. the code for the second time.
  176.  
  177.                         CONTENTS
  178.                         ========
  179.  
  180. This archive contains the following files:
  181.  
  182.     SPAWN.ASM       The main swap/exec function
  183.  
  184.         It can be assembled with TASM (specify
  185.         /JMASM51 on the command line) or MASM 5.1.
  186.  
  187.         To assemble:
  188.             ?asm spawn;                     For C (default small model)
  189.             ?asm /DMODL=xxx spawn;          For C (model 'xxx')
  190.  
  191.     EXEC.C          Interface routines for Turbo C(1.x/2.x) / MS-C(5.x)
  192.     COMPAT.H        MS-C/TC Compatibility definitions for C
  193.  
  194.         These files prepare the parameters for the main spawn
  195.         function, and handle the file search and environment
  196.         processing.
  197.  
  198.                            ACKNOWLEDGEMENTS
  199.                            ================
  200.  
  201. Thanks to H. Qualls, H. Gubler, J. Clinton, and M. Adler for pointing
  202. out bugs and suggesting enhancements.
  203.  
  204.