home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / FS191 / XSPAWN33 / MANUAL.DOC < prev    next >
Text File  |  1991-05-04  |  18KB  |  396 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.                                        XSPAWN
  16.  
  17.                                     Version 1.33
  18.  
  19.  
  20.         (C) Copyright 1990 Whitney Software, Inc.
  21.         All Rights Reserved
  22.  
  23.         Microsoft and MS-DOS are registered trademarks of Microsoft
  24.         Corporation.
  25.  
  26.         Turbo C is a registered trademark and VROOMM is a trademark of
  27.         Borland International.
  28.  
  29.         Lattice is a registered trademark of Lattice, Incorporated.
  30.  
  31.  
  32.         XSPAWN                                                              1
  33.         _____________________________________________________________________
  34.  
  35.  
  36.         Overview
  37.  
  38.         The XSPAWN functions allow you to run a large program on top of
  39.         another program by swapping the underlying program to EMS memory or
  40.         to disk.  This frees most of the DOS memory occupied by the
  41.         underlying program (both code and data segments) and returns it to
  42.         DOS for use by other programs or a DOS shell.  The "parent" program
  43.         is automatically restored upon completion of the "child" program and
  44.         execution resumes where the parent program left off.  The XSPAWN
  45.         functions can be called over and over again from one program to
  46.         another.
  47.  
  48.  
  49.         System Requirements
  50.  
  51.         XSPAWN supports DOS versions 2.1 and later.  Programs using the
  52.         XSPAWN functions instead of the standard C run-time library spawn
  53.         functions (fork functions in Lattice C) require up to 9K additional
  54.         DOS memory (4K on average).  XSPAWN requires sufficient EMS (3.2+)
  55.         memory or sufficient disk space to perform a swap.
  56.  
  57.  
  58.         XSPAWN Kernel
  59.  
  60.         The XSPAWN code that remains in memory while the child program is
  61.         executing is called the "XSPAWN kernel."  The XSPAWN kernel is 1021
  62.         bytes in size.  In addition to the XSPAWN kernel, the parent
  63.         program's environment, the parent program's PSP (program segment
  64.         prefix), and the environment to be passed to the child program remain
  65.         in memory while the child program is executing.  The program segment
  66.         prefix is 256 bytes in size.
  67.  
  68.  
  69.         Compilers and Memory Models Supported
  70.  
  71.         XSPAWN supports all standard memory models for Microsoft C (4.0, 5.0,
  72.         5.1, and 6.0), Turbo C++ (1.0), Turbo C (2.0), and Lattice C (6.0).
  73.         XSPAWN supports Turbo C++'s VROOMM overlay manager (as long as XSPAWN
  74.         is in the overlaid application's base).
  75.  
  76.  
  77.         XSPAWN                                                              2
  78.         _____________________________________________________________________
  79.  
  80.  
  81.         Using the XSPAWN Functions
  82.  
  83.         To use the XSPAWN functions you must include the XSPAWN.H header file
  84.         in your program, call the XSPAWN function that is equivalent to the
  85.         standard C run-time library spawn function (fork function in Lattice
  86.         C) you wish to use, and link with the appropriate XSPAWN library.
  87.         The XSPAWN functions have the same name as their standard C
  88.         counterparts (for Lattice C change fork to spawn) with the letter x
  89.         prefixed.  The XSPAWN functions expect the same arguments as their
  90.         standard C counterparts (the modeflag argument does not exist in
  91.         Lattice C fork functions).
  92.  
  93.         The XSPAWN family consists of the following functions:
  94.  
  95.         int xspawnl( modeflag, path, arg0, arg1..., argn, NULL );
  96.  
  97.         int xspawnle( modeflag, path, arg0, arg1..., argn, NULL, envp );
  98.  
  99.         int xspawnlp( modeflag, path, arg0, arg1..., argn, NULL );
  100.  
  101.         int xspawnlpe( modeflag, path, arg0, arg1..., argn, NULL, envp );
  102.  
  103.         int xspawnv( modeflag, path, argv );
  104.  
  105.         int xspawnve( modeflag, path, argv, envp );
  106.  
  107.         int xspawnvp( modeflag, path, argv );
  108.  
  109.         int xspawnvpe( modeflag, path, argv, envp );
  110.  
  111.         int modeflag;                 Execution mode for parent process
  112.         char *path;                   File to be executed
  113.         char *arg0, *arg1..., *argn;  List of pointers to arguments
  114.         char *argv[];                 Array of pointers to arguments
  115.         char *envp[];                 Array of pointers to environment
  116.                                       strings
  117.  
  118.         int xsystem( command );
  119.         char *command;                Command to be passed to COMMAND.COM
  120.  
  121.         The modeflag argument must be P_WAIT.  The modeflag argument exists
  122.         only for compatibility with the standard C spawn functions.  (The
  123.         modeflag argument does not exist in Lattice C fork functions.)  The
  124.         parent process will be suspended while the child process is
  125.         executing.
  126.  
  127.  
  128.         XSPAWN                                                              3
  129.         _____________________________________________________________________
  130.  
  131.  
  132.         The path argument specifies the file to be executed.  The path can be
  133.         just a file name or it can be a full or partial path (from the
  134.         current working directory).  If path does not have a filename
  135.         extension or end with a period, XSPAWN will try the extension .COM
  136.         and then, if necessary, the extension .EXE.  The xspawnlp, xspawnlpe,
  137.         xspawnvp, and xspawnvpe functions search for path in the directories
  138.         specified by the PATH environment variable.
  139.  
  140.         Arguments are passed to the child process by giving one or more
  141.         pointers to character strings as arguments in the XSPAWN call.  The
  142.         combined length of the strings (not including the first string, but
  143.         including space characters inserted automatically for separation) may
  144.         not exceed 124 bytes.  The strings can be passed as separate
  145.         arguments (xspawnl, xspawnle, xspawnlp, and xspawnlpe) or as an array
  146.         of pointers (xspawnv, xspawnve, xspawnvp, and xspawnvpe).  At least
  147.         one argument must be passed to the child process.  The first argument
  148.         is, by convention, a copy of the path argument.  (Using a different
  149.         value won't produce an error.)  The end of the argument list must be
  150.         marked with a null pointer.
  151.  
  152.         Files that are open in the parent process remain open in the child
  153.         process.  With the xspawnl, xspawnlp, xspawnv, and xspawnvp
  154.         functions, the child process inherits the parent's environment.  With
  155.         the xspawnle, xspawnlpe, xspawnve, and xspawnvpe functions, the child
  156.         process acquires the environment passed through the envp argument.
  157.         The envp argument is an array of pointers to character strings where
  158.         each string defines an environment variable.  Each string is of the
  159.         form
  160.  
  161.         variable=value
  162.  
  163.         where variable is an environment variable and value is its string
  164.         value.  The final element of the array must be NULL.  When envp is
  165.         NULL, the child process inherits the parent's environment.
  166.  
  167.         The xsystem function passes command to the file COMMAND.COM for
  168.         execution.  The COMSPEC and if necessary PATH environment variables
  169.         are used to locate the file COMMAND.COM.  If command is NULL and if
  170.         the function locates COMMAND.COM, it returns 1.  If it does not
  171.         locate COMMAND.COM, it returns 0 and sets errno to ENOENT.
  172.  
  173.         If the child process is started, the return value is the exit status
  174.         of the child process.  The return value will be 0 unless either the
  175.         child process called the exit function with a nonzero argument or the
  176.         child process exited abnormally with an abort call or an interrupt.
  177.  
  178.  
  179.         XSPAWN                                                              4
  180.         _____________________________________________________________________
  181.  
  182.  
  183.         If the child process is not started, the XSPAWN functions return -1
  184.         and set errno to one of the following values:
  185.  
  186.         Value         Meaning
  187.         ---------------------------------------------------------------------
  188.         E2BIG         The argument list exceeds 124 bytes or the environment
  189.                       is not less than 32K.
  190.  
  191.         EACCES        Access to the swap file was denied, no handle was
  192.                       available for the swap file, the file handle table size
  193.                       did not equal FHTSZ in the file XSPAWN.ASM, attempt to
  194.                       map EMS memory failed, or attempt to restore EMS memory
  195.                       page-mapping state failed.  There may be insufficient
  196.                       EMS (3.2+) memory and disk space on the specified
  197.                       paths.
  198.  
  199.         EINVAL        The modeflag argument is not P_WAIT.
  200.  
  201.         ENOENT        The specified file was not found.
  202.  
  203.         ENOEXEC       The specified file is not executable.
  204.  
  205.         ENOMEM        Not enough memory is available to execute the child
  206.                       process or the memory control blocks are corrupted.
  207.  
  208.  
  209.         Controlling the Swap Operation
  210.  
  211.         There are four global variables defined in XSPAWN.H which allow you
  212.         to control the swap operation of all of the XSPAWN functions.  The
  213.         XSPAWN global variables and their actions are as follows:
  214.  
  215.         _swap
  216.  
  217.         If _swap is 0 (the default), XSPAWN will attempt to swap out the
  218.         parent process before executing the child process.  Any other value,
  219.         and XSPAWN will execute the child process without swapping out the
  220.         parent process.  In other words, if _swap is not 0, XSPAWN will
  221.         behave like the standard C run-time library spawn functions (fork
  222.         functions in Lattice C).
  223.  
  224.  
  225.         XSPAWN                                                              5
  226.         _____________________________________________________________________
  227.  
  228.  
  229.         _swappath
  230.  
  231.         If _swappath is a null pointer (the default), XSPAWN will attempt to
  232.         write the swap file (if EMS memory is not used) to the current
  233.         directory on the current drive.
  234.  
  235.         You can specify one or more alternate paths for the swap file by
  236.         assigning a string to _swappath as follows:
  237.  
  238.         _swappath = "D:\\;C:\\SCRATCH";
  239.  
  240.         Each separate path specifier in the _swappath string (separated by a
  241.         ;) can contain a drive, a directory, or both.  If you do not specify
  242.         a drive, XSPAWN will use the current drive.  If the directory is not
  243.         specified, XSPAWN will use the directory that is current on the
  244.         target drive.
  245.  
  246.         You may be wondering why you would ever want to specify multiple
  247.         paths.  To illustrate one use of this feature, let us say your system
  248.         has a ramdrive called D: and a hard drive called C:.  Since writing
  249.         to a ramdrive is many times faster than writing to a hard drive, you
  250.         would naturally prefer to write the swap file to the ramdrive.  The
  251.         problem is that there may not be enough space on the ramdrive to hold
  252.         the swap file.  The _swappath string shown above would cause XSPAWN
  253.         to try the ramdrive first and if there is insufficient space, to try
  254.         the C: drive next.
  255.  
  256.         If a path does not exist, XSPAWN will skip it.  If XSPAWN can't store
  257.         the swap file on any of the specified paths, it will return -1 and
  258.         set errno to EACCES.
  259.  
  260.  
  261.         _useems
  262.  
  263.         If _useems is 0 (the default), XSPAWN will check for the existence of
  264.         EMS (3.2+) memory and if there is enough EMS memory, will swap the
  265.         parent process there instead of to disk.  You can disable the use of
  266.         EMS memory by assigning a nonzero value to _useems.
  267.  
  268.  
  269.         _required
  270.  
  271.         If you know the amount of memory required by the child process, you
  272.         can assign the amount in kilobytes to _required.  Regardless of the
  273.         value of the _swap variable, if _required is less than or equal to
  274.         the amount of memory that is already free (without swapping out the
  275.         parent process), XSPAWN will execute the child process without
  276.         swapping out the parent process.  If _required is 0 (the default) and
  277.         _swap is 0, XSPAWN will attempt to swap out the parent process.
  278.  
  279.  
  280.         XSPAWN                                                              6
  281.         _____________________________________________________________________
  282.  
  283.  
  284.         Linking XSPAWN Into Your Program
  285.  
  286.         The XSPAWN functions can be linked into your program by including the
  287.         XSPAWN library appropriate for your compiler and memory model on your
  288.         linker command line.
  289.  
  290.  
  291.         Interrupt Handlers
  292.  
  293.         Something must be done with captured interrupt vectors that point to
  294.         interrupt handlers in your program.  This is true for two reasons.
  295.         First, if XSPAWN swaps out your program, the interrupt handlers in
  296.         your program will no longer be in memory.  Second, even if XSPAWN
  297.         doesn't swap out your program, it is probably undesirable to have
  298.         interrupt handlers in your program invoked in response to interrupts
  299.         that occur while the child process is executing.  If you capture
  300.         interrupts, you should read the following to understand how XSPAWN
  301.         handles interrupts.
  302.  
  303.         Before executing the child process, XSPAWN saves the current content
  304.         of the vectors listed in a XSPAWN table called the "vector table" and
  305.         replaces the content of these vectors with addresses stored in the
  306.         table.  After executing the child process, XSPAWN restores the
  307.         vectors that were saved.
  308.  
  309.         By default, the vector table contains the interrupts: 0, 1, 2, 3,
  310.         1BH, and 23H.  Associated with the default interrupts is the address
  311.         of an interrupt handler in the XSPAWN kernel (the XSPAWN code that
  312.         remains in memory while the child process is executing) that consists
  313.         of only an IRET (INTERRUPT RETURN) instruction.  By default, the
  314.         default interrupts will do nothing if invoked while the child process
  315.         is executing.
  316.  
  317.         You can add or change entries in the vector table by using the
  318.         addvect function.
  319.  
  320.         int addvect( number, opcode );
  321.         int number;                   Interrupt number
  322.         int opcode;                   Operation code
  323.  
  324.         The number argument must be an integer from 0 to FFH.
  325.  
  326.         The opcode argument can be either IRET or CURRENT.  If the value is
  327.         IRET, the interrupt will point (while the child process is executing)
  328.         to the interrupt handler in the XSPAWN kernel that consists of only
  329.         an IRET instruction, unless the child process captures the interrupt.
  330.         If the value is CURRENT, the interrupt will point to the interrupt
  331.         handler that is in effect when the addvect function is called.
  332.  
  333.  
  334.         XSPAWN                                                              7
  335.         _____________________________________________________________________
  336.  
  337.  
  338.         If the addvect function fails, it returns -1 and sets errno to one of
  339.         the following values:
  340.  
  341.         Value         Meaning
  342.         ---------------------------------------------------------------------
  343.         EINVAL        The opcode argument must be IRET or CURRENT.
  344.  
  345.         ENOMEM        The vector table is full.  The vector table has space
  346.                       for 20 entries (6 are used by default).  If more
  347.                       entries are desired, you will have to modify and
  348.                       compile the file XSPAWNVE.C.  Add free records to the
  349.                       vectab1 array.  No other changes are necessary.
  350.  
  351.         It is typical to call addvect with an opcode of CURRENT before you
  352.         capture an interrupt.  This will cause XSPAWN to set the interrupt to
  353.         its original value while the child process is executing.
  354.  
  355.         To find out what interrupt vectors are captured by your program, use
  356.         an XSPAWN function other than xsystem (with the _swap variable set to
  357.         a nonzero value) to run MP.COM from your program.  Remember by
  358.         default, XSPAWN captures the interrupts: 0, 1, 2, 3, 1BH, and 23H.
  359.         Interrupt 22H will point to your program because DOS uses it to store
  360.         the return address from the child process.
  361.  
  362.  
  363.         File Handle Table Size
  364.  
  365.         If you have increased the file handle table size so that more than 20
  366.         files may be open in the parent process, you will have to modify and
  367.         assemble the file XSPAWN.ASM.  Change the line
  368.  
  369.         FHTSZ           EQU     20
  370.  
  371.         so that FHTSZ is set to the new size.
  372.  
  373.         To increase the file handle table size for Microsoft C versions 5.0,
  374.         5.1, or 6.0, see the description of the necessary modifications to
  375.         the startup code in the README file accompanying the compiler.
  376.  
  377.  
  378.         XSPAWN                                                              8
  379.         _____________________________________________________________________
  380.  
  381.  
  382.         Fatal Errors
  383.  
  384.         If XSPAWN is unable to restore the parent process upon completion of
  385.         the child process, it will display the message "XSPAWN error" and
  386.         exit to DOS with an exit status of 1.  This can occur for several
  387.         reasons:
  388.  
  389.         1. The child process may have made itself permanently resident.
  390.  
  391.         2. The swap file may have been erased or corrupted.
  392.  
  393.         3. There may have occurred a disk read error.
  394.  
  395.         4. There may have occurred an EMS memory management error.
  396.