home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / MAGS / ICTARI05.ARJ / ictari.05 / MISC / PEXEC / PEXEC.TXT < prev   
Text File  |  1993-06-21  |  6KB  |  147 lines

  1. PEXEC INFO
  2. ==========
  3. Note:
  4.     Child processes inherit default drive, default paths in each drive
  5. and default devices on handles 0-5.
  6. Counters on these structures are incremented when loaded, not when run,
  7. and decremented when terminated. Thereforem repeated running may cause
  8. problems as the counters on internal structures go negative.
  9. This statement is valid on all versions of GEMDOS up to 0.19
  10. Preferable to use mode 5, mode 6 to run multiple times.
  11.  
  12. Pexec() will fail if the parent has not Mshrink'ed itself to give the child
  13. room to run. Remember to move the stack into the program memory before you
  14. Mshrink it, otherwise your stack is not in your own memory!
  15.  
  16. MODES AVAILABLE
  17. ===============
  18. 0] LOAD AND GO
  19.    Execute like a subroutine - returns a word from child or long GEMDOS error.
  20.    Error=Pexec(0,Filename_ptr,cmdline_ptr,environment_ptr)
  21. 3] LOAD
  22.    Load and return pointer to Basepage
  23.    Basepage_ptr=Pexec(3,Filename_ptr,cmdline_ptr,environment_ptr)
  24. 4] GO
  25.    Execute and return word from child or Long GEMDOS error.
  26.    Keep in memory when run.
  27.    Error=Pexec(4,0L,Basepage_ptr,0L)
  28.    Mfree(Basepage_ptr->P_env)
  29.    Mfree(Basepage_ptr)
  30. 5] MAKE BASEPAGE
  31.    Allocate Environment and create Basepage with TPA of largest free block of
  32.    memory. Return pointer to memory block (Basepage).
  33.    Basepage_ptr=Pexec(5,0L,cmdline_ptr,environment_ptr)
  34.    Load child into tpa after basepage
  35.    Setup basepage text,data,bss start_addresses and lengths
  36. 6] GO then FREE
  37.    Execute already loaded process, free it when finished - return as mode 0
  38.    Only available on Gemdos v0.15 or higher.
  39.    Error=Pexec(6,0L,Basepage_ptr,0L)
  40. 7] MAKE BASEPAGE WITH PRGFLAGS
  41.    Same as Mode 5 but uses PRGFLAGS passed as parameter 2
  42.    Basepage_ptr=Pexec(7,PRGFLAGS,cmdline_ptr,environment_ptr)
  43.    
  44. Filename=Null terminated string of full path\filename.ext
  45. Cmdline=length_byte+string (less than 125 bytes)+Null
  46. Environment=Null terminated strings of the form "VAR=value"
  47.             terminated with double Null.
  48.             If just Null, parent's environment string is used.
  49.  
  50. Mode 0 - Load & Go
  51. ------------------
  52. 1] Make sure File exists
  53. 2] Set up Environment,TPA and Basepage:
  54.     Allocate Environment and Copy from Parent
  55.     Allocate Largest Free block of memory to child process
  56.     Set up Basepage - Lowtpa, Hitpa, Dta and Env pointers
  57.     Copy file handles and default directory from parent
  58.     Copy Command line into memory Block
  59. 3] Give ownership of Environment and Memory Block to child process
  60. 4] Load Child process Executable File and fill in rest of Basepage
  61. 5] Start Program:
  62.     Set Parent Pointer in Memory Block to child process
  63.     Set initial User Stack and put values in it
  64.     Set child process as Global to Memory Block
  65.     Run Child Process
  66.  
  67. Mode 3 - Load, don't go
  68. -----------------------
  69. Does steps 1, 2 and 4:
  70.     Parent Process still owns all memory of child process
  71.  
  72. Mode 4 - Don't load, just go
  73. ----------------------------
  74. Does step 5 only:
  75.     Parent Process still owns memory of child process
  76.     Environment and TPA are not freed when finished
  77.     Memory Malloc'd by child IS freed
  78.  
  79. Mode 5 - Create Basepage
  80. ------------------------
  81. Does Step 2 only
  82.  
  83. Mode 6 - Don't load, Just Go:
  84. -----------------------------
  85. Does Step 3 then Step 5:
  86.     All Memory of child belongs to child
  87.  
  88. Mode 7 - Create Basepage
  89. ------------------------
  90. Does Step 2 only:
  91.     Accepts PRGFLAGS passed as second argument
  92.  
  93. NOTE:
  94.     MODE 6 REQUIRES GEMDOS >=0.15
  95.     MODE 7 REQUIRES GEMDOS >=0.19
  96.  
  97. RUNNING PEXEC(mode 0)
  98. =====================
  99. 1] Put full file path and name into a string, ending with a NULL (0)
  100.    e.g. "C:\TEST\FILE.EXT",0
  101. 2] Put command line into string_address+1
  102. 3] Put length of string into byte at string_address
  103. 4] Put all environment strings following each other,ending in a NULL
  104.    e.g. "Path=c:\;c:\rsc",0,"Lib=c:\libs",0,0
  105. 5] Call Pexec(mode0,filename,cmdline,environment);
  106.  
  107. If Environment is 0.L, the parent's environment will be passed instead.
  108.  
  109. RETURN CODES
  110. ============
  111.     When the child process exits, its return code is passed back to the parent
  112. as a WORD. If pexec fails it will return a negative LONG.
  113. Programs should only return negative values as indications of system failures 
  114. (e.g. not enough memory) and positive codes for their own messages.
  115. Therefore, Exit all programs with Pterm(value) rather than Pterm0.
  116.  
  117. OTHER MODES
  118. ===========
  119. Mode 3 followed by Mode 6 is the same as just mode 0
  120.  
  121. Mode 3 followed by Mode 4 is for load once, run many times
  122.     This will only work if the child process either doesn't mshrink itself (not
  123. recommended) or puts its new top of stack address into the basepage->hitpa.
  124. Also, remember that text and data values will keep the values they had when 
  125. they were last run. Also the BSS does not get cleared (unless you do it!)
  126. Also, if the parent changes current directory, it may not be passed so all file
  127. operations should use full paths, not just filenames.
  128.  
  129. Mode 3 followed by Mode 5 followed by Mode 6
  130.     Use Mode 3 to Load child Process
  131.     Mshrink its TPA to Basepage+text+data+BSS
  132.     For each Run:
  133.     Use mode 5 to create Basepage,then fill it with fields of old one
  134.     Execute this new basepage with mode 6
  135. Mode 4 could be used with this method,but the tpa and environment must be 
  136. freed after execution.
  137. Note that some programs may not like the idea that their basepage is not before
  138. the text segment and that the program's memory is not after the BSS segment
  139.  
  140. Mode 5 (or 7) followed by mode 6
  141.     Use mode 5 to create a basepage
  142.     Fill its tpa with a RAM copy of the child process
  143.     relocate it
  144.     run it with mode 6
  145. The best way to do it but needs mode 6 and uses more memory
  146.  
  147.