home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / vms / 20483 < prev    next >
Encoding:
Internet Message Format  |  1993-01-06  |  13.3 KB

  1. Path: sparky!uunet!portal!cup.portal.com!Chris_F_Chiesa
  2. From: Chris_F_Chiesa@cup.portal.com
  3. Newsgroups: comp.os.vms
  4. Subject: Long-awaited $IMGACT example program: part 2 of 2
  5. Message-ID: <73056@cup.portal.com>
  6. Date: Wed,  6 Jan 93 18:54:45 PST
  7. Organization: The Portal System (TM)
  8. Distribution: world
  9. References: <9301041627.AA20066@uu3.psi.com> <72934@cup.portal.com>
  10. Lines: 373
  11.  
  12. -+-+-+-+-+-+-+-+ START OF PART 2 -+-+-+-+-+-+-+-+
  13. X`09IAC$V_WRITABLE`09If set, the image is writeable
  14. X`09IAC$V_SHAREABLE`09If set, the specified image is a shareable image`20
  15. X`09`09`09that is being activated as a piece of an executable
  16. X`09`09`09image. This flag can only be used in a recursive call
  17. X`09`09`09to the image activator
  18. X`09IAC$V_PRIVILEGE`09If set, the executable image has amplified privileges.
  19. X`09`09`09If this flag is set, the shareable image being
  20. X`09`09`09activated must be installed as a known file. The flag
  21. X`09`09`09IAC$V_SHAREABLE must also be set.
  22. X`09IAC$V_MERGE`09If set, the image activator is directed to merge one
  23. X`09`09`09executable image into the address space of another.
  24. X`09`09`09When this flag is set, the user stack, the image I/O
  25. X`09`09`09segment, and the privilege amplification flag are
  26. X`09`09`09to be ignored. This flag must be set if the image
  27. X`09`09`09activator is called from user mode.
  28. X`09IAC$V_EXPRG`09If set, the _inadr_ argument does not give an actual
  29. X`09`09`09address range, but merely indicates the address space
  30. X`09`09`09(P0 space or P1 space) into which the image is to be
  31. X`09`09`09mapped. This flag is only used during a merged image
  32. X`09`09`09activation.
  33. Xinadr`09Address of a two-longword array containing the virtual address range
  34. X`09into which the image is to be mapped. This argument is usually omitted,
  35. X`09in which case the address ranges designated by the image section
  36. X`09descriptors in the image header are used.
  37. Xretadr`09Address of a two-longword array to receive the starting and ending
  38. X`09addresses into which the image was actually mapped.
  39. Xident`09Address of a quadword containing the version number and matching
  40. X`09criteria for a shareable image.
  41. XThe last 3 arguments are similiar to the input argumetns for various other
  42. Xmemory management system services that are described in Chapter 16.
  43. X--- End VVI quote ---
  44. X
  45. X----- INCLUDED TEXT ENDS -----
  46. $ CALL UNPACK README.TXT;7 606893441
  47. $ create 'f'
  48. X;+
  49. X; TRYIT.MAR - Christopher F. Chiesa, 9-NOV-1992 (commented 17-DEC-1992)
  50. X;
  51. X;    Accept DCL command line, nibble off TRYIT verb and replace with`20
  52. X;    COPY, and call the VMS COPY utility as a subroutine.  Based on`20
  53. X;    Internet posting from Garry Wiegand (garry@oak.cadif.cornell.edu)
  54. X;    on March 28, 1988 in comp.os.vms newsgroup.
  55. X;
  56. X;-
  57. X;===========================================================================
  58. X; MACRO LIBRARIES`20
  59. X;===========================================================================
  60. X;
  61. X`09.LIBRARY`09\SYS$LIBRARY:LIB\
  62. X;
  63. X;===========================================================================
  64. X; LOCAL MACROS
  65. X;===========================================================================
  66. X;+
  67. X;   CHKSTS dest
  68. X;     Branch to "dest" if R0 contains a non-success severity condition`20
  69. X;     value
  70. X;-
  71. X`09.MACRO`09CHKSTS,DEST,?LABEL`09; W.Dick
  72. X`09BLBS`09R0,LABEL
  73. X`09.IF`09NOT_BLANK,<DEST>
  74. X`09BRW`09DEST
  75. X`09.IF_FALSE
  76. X`09RET
  77. X`09.ENDC
  78. XLABEL:
  79. X`09.ENDM`09CHKSTS
  80. X;+
  81. X;   GEN_ASCID size
  82. X;    Declare an "empty" descriptor of "size" characters
  83. X;-
  84. X`09.MACRO`09GEN_ASCID`09SIZE`09; C.Chiesa after R. & L. Utter
  85. X`09x = .
  86. X`09.ASCID`09\ \
  87. X`09.BLKB`09<SIZE-1>
  88. X`09y = .
  89. X`09. = x
  90. X`09.WORD`09<SIZE>
  91. X`09. = y
  92. X`09.ENDM`09GEN_ASCID
  93. X;===========================================================================
  94. X; SYMBOLIC CONSTANTS
  95. X;===========================================================================
  96. X`09cr = 13`09`09`09`09; Carriage Return character
  97. X`09lf = 10`09`09`09`09; Line Feed character
  98. X`09$SSDEF`09`09`09`09; Completion status values
  99. X`09$UAIDEF`09`09`09`09; $GETUAI item codes
  100. X`09$IACDEF`09`09`09`09; Image Activator symbols
  101. X`09$IHDDEF`09`09`09`09; Image Header symbols
  102. X;===========================================================================
  103. X; WRITEABLE DATA
  104. X;===========================================================================
  105. X`09.PSECT`09DATA`09WRT,NOEXE
  106. X;+
  107. X; Item List (item_list_3) for $GETJPI
  108. X;-
  109. Xjpi_items:
  110. X`09.word`0912`09`09`09; buffer length
  111. X`09.word`09JPI$_USERNAME`09`09; $GETJPI item code
  112. X`09.address username_data`09`09; buffer address
  113. X`09.address username_desc`09`09; return length address
  114. X`09.long`090
  115. X;+
  116. X; Item List (item_list_3) for $GETUAI
  117. X;-
  118. Xuai_items:
  119. X`09.word`0932`09`09`09; buffer length
  120. X`09.word`09UAI$_CLITABLES`09`09; $GETJPI item code`20
  121. X`09.address cli_table_filename`09; buffer address
  122. X`09.address cli_table_desc`09`09; return length address
  123. X`09.long`090
  124. X;+
  125. X; Descriptor for username - LENGTH field receives $GETJPI buffer-length retu
  126. Vrn
  127. X;-
  128. Xusername_desc:
  129. X`09.long`0912`09`09`09; Username has 12 characters max
  130. X`09.address username_data`09`09; Pointer to data buffer
  131. Xusername_data:
  132. X`09.blkb`0912`09`09`09; Data buffer
  133. X;+
  134. X; Descriptor for CLI table file name - LENGTH field receives $GETUAI`20
  135. X; buffer-length return
  136. X;-
  137. Xcli_table_desc:
  138. X`09.blkl
  139. X`09.address`09cli_table_filename
  140. Xcli_table_filename:
  141. X`09.blkb`0932
  142. X;+
  143. X; Descriptor for COPY command constructed from TRYIT command that got us
  144. X; into this program
  145. X;-
  146. Xcopy_command:`09`09`09`09; Receives entire command
  147. X`09gen_ascid`09255
  148. Xcopy:`09.ascid`09\COPY \`09`09`09; Actual COPY verb for DCL parse`09
  149. X;+
  150. X; Pointers to address range SYS$SYSTEM:COPY.EXE "wants" to reside in, i.e.
  151. X; where it would find itself if invoked normally by DCL.  Note that this
  152. X; is the same range where TRYIT.EXE would reside if linked without the`20
  153. X; BASE=%XA000 statement in TRYIT.OPT; that statement and file exist solely
  154. X; to "move TRYIT up out of the way" so that COPY can reside where it be-
  155. X; longs. This is necessary because $IMGACT/$IMGFIX don't resolve address
  156. X; references COMPILED INTO static descriptors...
  157. X;-
  158. Xcopy_home_range:`09`09`09; Address range COPY.EXE "wants"`20
  159. X`09.address `5Ex00000200`09`09; to inhabit
  160. X`09.address `5Ex00009DFF
  161. X;+
  162. X; Receives "actual" address range into which COPY.EXE gets mapped at run`20
  163. X; time
  164. X;+
  165. Xvm_actual:
  166. X`09.blka
  167. X`09.blka
  168. X;+
  169. X; Receives address of DCL command table
  170. X;-
  171. Xcli_table_ptr:
  172. X`09.blka
  173. X;+
  174. X; Buffer to contain header of COPY.EXE when $IMGACT'ed into memory
  175. X;-
  176. Ximg_header_buf:
  177. X`09.blkb`09512
  178. X;+
  179. X; Messages - output BEFORE and AFTER calling COPY.EXE, to prove that TRYIT
  180. X; is in control throughout!
  181. X;-
  182. Xafter_msg:`09.ascid`09<CR><LF>\* After calling COPY *\<CR><LF>
  183. Xbefore_msg:`09.ascid`09<CR><LF>\* Before calling COPY *\<CR><LF>
  184. X;+
  185. X; Universal Symbol pointing to start of DCL Command Table in a DCL Command`2
  186. V0
  187. X; Table image file such as DCLTABLES.EXE:
  188. X;-
  189. Xcli_table_symbol:
  190. X`09`09.ascid`09\DCL$AL_TAB_VEC\
  191. X;+
  192. X; CLI$ parameter name that gets us the "entire command line" from DCL:
  193. X;-
  194. Xline_parm:`09.ascid`09\$LINE\
  195. X;+
  196. X; Buffer to contain actual command line from DCL...
  197. X;-
  198. Xcommand_line:`09gen_ascid 255
  199. X;+
  200. X; Name of image file we're going to activate... the VMS Copy Utility!
  201. X;-
  202. Xcopy_image_name:
  203. X`09`09.ascid`09\SYS$SYSTEM:COPY.EXE\
  204. X;===========================================================================
  205. X; EXECUTABLE CODE
  206. X;===========================================================================
  207. X`09.PSECT`09CODE`09NOWRT,EXE
  208. X`09.DISABLE`09LOCAL_BLOCK
  209. X`09.ENTRY`09TRYIT,`5EM<>
  210. X;+
  211. X; Issue "before" message
  212. X;-
  213. X`09pushaq`09before_msg
  214. X`09calls`09#1,g`5ELIB$PUT_OUTPUT
  215. X`09chksts`09try_fail
  216. X;+
  217. X; Get TRYIT command line...
  218. X;-
  219. X`09pushaw `09command_line
  220. X`09pushaq`09command_line
  221. X`09pushaq`09line_parm
  222. X`09calls`09#3,g`5ECLI$GET_VALUE
  223. X`09chksts`09try_fail
  224. X`09subw2`09#1,command_line
  225. X;+
  226. X; "... nibble off the command verb..." (in this case, "TRYIT") ...
  227. X;-
  228. X`09.ENABLE`09LOCAL_BLOCK
  229. X`09movl`09#SS$_BADPARAM,r0`09`09; Assume failure to nibble verb
  230. X`09movaq`09command_line,r6`09`09`09; R6 <- line descr base
  231. X`09locc`09#`5Ea\ \,DSC$W_LENGTH(r6),-`09; Find first blank if any
  232. X`09`09@DSC$A_POINTER(r6)
  233. X`09bneq`0910$
  234. X`09brw`09try_fail
  235. X10$:
  236. X`09addl3`09#1,r1,DSC$A_POINTER(r6)
  237. X`09bgtr`0920$
  238. X`09brw`09try_fail
  239. X20$:
  240. X;+
  241. X; Replace former TRYIT verb with COPY:
  242. X;-
  243. X`09addw3`09<command_line+DSC$W_LENGTH>,-
  244. X`09`09<copy+DSC$W_LENGTH>,-
  245. X`09`09<copy_command+DSC$W_LENGTH>
  246. X`09pushaq`09command_line`09`09`09; ... tail of TRYIT command...
  247. X`09pushaq`09copy`09`09`09`09; "COPY"
  248. X`09pushaq`09copy_command`09`09`09; Receives concatenated string
  249. X`09calls`09#3,g`5ESTR$CONCAT
  250. X`09chksts`09try_fail
  251. X;+
  252. X; Look up username currently running this program
  253. X;-
  254. X`09$GETJPI_S -`09`09`09`09; username_desc gets filled in
  255. X`09`09itmlst=jpi_items`09`09; with current username string
  256. X`09chksts`09try_fail
  257. X;+
  258. X; Look up DCL command table file name for the username currently running thi
  259. Vs
  260. X; program; $GETUAI looks up this information in the system UAF (User Authori
  261. V-
  262. X; zation File):
  263. X;-
  264. X`09$GETUAI_S -`09`09`09`09; cli_table_desc gets filled in
  265. X`09`09usrnam=username_desc,-`09`09; with command-table-filename
  266. X`09`09itmlst=uai_items`09`09; string, with prefixed LENGTH
  267. X`09`09`09`09`09`09; byte!
  268. X`09chksts`09try_fail
  269. X`09movzbw`09cli_table_filename,-`09`09; Copy filename length byte from
  270. X`09`09cli_table_desc`09`09`09; string to descriptor
  271. X`09movab`09<cli_table_filename+1>,-`09; Adjust valid filename string
  272. X`09`09<cli_table_desc+DSC$A_POINTER>`09; data start address
  273. X;+
  274. X; Find the Universal Symbol "DCL$AL_TAB_VEC" in the named DCL command table
  275. X; file, and merge that command table into process memory space and obtain`20
  276. X; the address where the table is merged...
  277. X;-
  278. X`09pushal`09cli_table_ptr`09`09`09; Receives address of table
  279. X`09pushaq`09cli_table_symbol`09`09; "DCL$AL_TAB_VEC"
  280. X`09pushaq`09cli_table_desc`09`09`09; DCL command table filespec
  281. X`09calls`09#3,g`5ELIB$FIND_IMAGE_SYMBOL
  282. X`09chksts`09try_fail
  283. X;+
  284. X; Activate COPY using $IMGACT -- *THIS IS TOTALLY UNSUPPORTED BY DIGITAL!*
  285. X;-
  286. X`09$IMGACT_S -
  287. X`09`09NAME=copy_image_name,-
  288. X`09`09HDRBUF=img_header_buf,-
  289. X`09`09IMGCTL=#<IAC$M_MERGE>,-
  290. X`09`09INADR=copy_home_range,-
  291. X`09`09RETADR=vm_actual
  292. X`09chksts`09try_fail
  293. X;+
  294. X; Perform address fixups?  It's not clear what this does, but it seems to
  295. X; be necessary.
  296. X;-
  297. X`09$IMGFIX_S
  298. X;+
  299. X; $IMGACT places COPY.EXE's Image Header in img_header_buf, and maps the`20
  300. X; executable etc. portion(s) of the image at their "natural" addresses.
  301. X; We have to traverse through the Image Header to find the address of the
  302. X; entry mask of the entry point of COPY.EXE.  This is in one of the three
  303. X; Transfer Vector fields, probably the first or second, but I tried to be
  304. X; thorough and check for Debugger startup (SYS$IMGSTA), missing (0), and
  305. X; other "wrong" Transfer Vector field contents...
  306. X;-
  307. X`09moval`09img_header_buf,r2`09`09; R2 => header buffer base
  308. X`09movl`09(r2),r2`09`09`09`09; R2 => Image Header base
  309. X;+
  310. X; Look up offset, and compute actual address, of Transfer Vector array:
  311. X;-
  312. X`09movzwl`09IHD$W_ACTIVOFF(r2),r3`09`09; R3 <-- xfer array offset
  313. X`09movab`09(r2)`5Br3`5D,r3`09`09`09; R3 <-- xfer array address
  314. X;+
  315. X; Look for first non-zero, non-SYS$IMGSTA transfer address, which we'll
  316. X; assume is the proper start address for COPY.EXE:
  317. X;-
  318. X`09movl`09#0,r4`09`09`09`09; R4 <-- array index
  319. Xloop:
  320. X`09movab`09(r3)`5Br4`5D,r5`09`09`09; R5 <-- xfer address address
  321. X`09movl`09(r5),r6`09`09`09`09; R6 <-- xfer address itself
  322. X`09tstl`09r6`09`09`09`09; Is xfer address 0?
  323. X`09beql`09next_entry`09`09`09;   YES: try next entry if any
  324. X`09cmpl`09r6,#SYS$IMGSTA`09`09`09;    NO: is it $IMGSTA ?
  325. X`09bneq`09go_for_it`09`09`09;       NO: try running image!
  326. X;+
  327. X; Repeat checks for all three entries in Transfer Vector array; if no usable
  328. X; Transfer Address is found, indicate generic error (R0 = 0) and exit!
  329. X;-
  330. Xnext_entry:
  331. X`09addl2`09#4,r4
  332. X`09cmpl`09r4,#12`09`09`09`09; Past end of entries?
  333. X`09blss`09loop`09`09`09`09;   NO: try again
  334. X`09movl`09#0,r0`09`09`09`09;  YES: fail
  335. X`09brw`09try_fail
  336. X;+
  337. X; Now that we know where COPY.EXE's entry point is, we can parse the COPY
  338. X; command we constructed from the TRYIT command line, to make COPY.EXE`20
  339. X; think IT is running directly from the command line!
  340. X;-
  341. Xgo_for_it:
  342. X;+
  343. X; Parse fake, "constructed" COPY command
  344. X;-
  345. X`09pushl`09cli_table_ptr
  346. X`09pushaq`09copy_command
  347. X`09calls`09#2,g`5ECLI$DCL_PARSE
  348. X`09chksts`09try_fail
  349. X;+
  350. X; Call COPY.EXE as a subroutine!
  351. X;-
  352. X`09calls`09#0,(r6)`09`09`09`09; call COPY!
  353. X`09movl`09r0,r5`09`09`09`09; R5 <- saved status from COPY
  354. X;+
  355. X; Show the world that TRYIT is still in control
  356. X;-
  357. X`09pushaq`09after_msg
  358. X`09calls`09#1,g`5ELIB$PUT_OUTPUT`09`09; Generates its own status in
  359. X`09`09`09`09`09`09; R0, which we ignore
  360. X`09movl`09r5,r0`09`09`09`09; Restore saved COPY status
  361. X;+
  362. X; At this point, I am not aware that I need do anything special in order`20
  363. X; to "unwind" anything I've done: there's no '$IMGDAC' (Image De-Activate)
  364. X; operation, for example.  Everything gets unmapped, I presume, by the defau
  365. Vlt
  366. X; image rundown procedure(s).  As the original 1988 posting says, "trapping
  367. X; possible $EXIT_S calls..." from COPY.EXE "... is left as an exercise for
  368. X; the reader."
  369. X;-
  370. Xtry_fail:
  371. X`09ret`09`09`09`09`09; Return to DCL with status
  372. X`09.end`09tryit
  373. $ CALL UNPACK TRYIT.MAR;22 863771829
  374. $ create 'f'
  375. XBASE=%XA000
  376. $ CALL UNPACK TRYIT.OPT;1 67855631
  377. $ create 'f'
  378. Xdefine verb tryit
  379. X  image testdir:tryit
  380. X  parameter p1
  381. X`09value(type=$rest_of_line)
  382. $ CALL UNPACK TRYIT.CLD;7 1175010657
  383. $ v=f$verify(v)
  384. $ EXIT
  385.