From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 16-FEB-1991 06:31:43.60
To:	ARISIA::EVERHART
CC:	
Subj:	Re: Program names and link dates

From:	RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP@CRDGW2
To:	Everhart@Arisia@MRGATE

Received:  by crdgw1.ge.com (5.57/GE 1.83)
	 id AA13978; Sat, 16 Feb 91 06:17:36 EST
Received: From UCBVAX.BERKELEY.EDU by CRVAX.SRI.COM with TCP; Sat, 16 FEB 91 03:03:22 PST
Received: by ucbvax.Berkeley.EDU (5.63/1.42)
	id AA28659; Sat, 16 Feb 91 03:00:44 -0800
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 16 Feb 91 04:01:01 GMT
From: swrinde!elroy.jpl.nasa.gov!zardoz.cpd.com!dpdvax!potter@ucsd.edu
Organization: Data Processing Design,  Anaheim CA
Subject: Re: Program names and link dates
Message-Id: <284.27bba96b@dpdvax.uucp>
References: <1991Feb6.200812.25355@astro.as.utexas.edu>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

In article <1991Feb6.200812.25355@astro.as.utexas.edu>, michael@astro.as.utexas.edu (Michael Lemke) writes:
> I would like to access from within a FORTRAN subroutine the actual
> program name as defined in the PROGRAM statement as well as the link date. This
> is a similar kind of information as you can get with ANALYZE/IMAGE; so the
> information must be somewhere in the image. Does anyone know how to do this? I
> do not want something like LIB$GETJPI(,,,,"IMAGENAME") (don't count the commas),
> which would give you the file name and not what you declared in the program
> statement.
> 
> Many thanks,
> Michael Lemke
> 
> UT Astronomy Department
> University of Texas at Austin

We were looking to do a similar thing from a C program.  The part we
especially needed was the version number specified in the linker
IDENTIFICATION string.  It turns out this information is available.  We
wrote a macro routine to return it for us.

Here is the source for our routine.  It is called GET_IMAGE_IDENT.  Be aware
that this routine is optimized for use with a C program -- it uses
null-terminated strings instead of descriptors.  to build it, just type

	MACRO GET_IMAGE_IDENT

I hope this helps.
-- 
  David Potter                Voice: (714) 970-1515
  Data Processing Design      UUCP: {lawnet,zardoz,dhw68k}!dpdvax!potter
  Anaheim, CA                 Internet: potter@dpdvax.uucp

;------------------------------------------------------------------------------
; CUT HERE
;------------------------------------------------------------------------------
	.TITLE	GET_IMAGE_IDENT Get Image Identification Information

;------------------------------------------------------------------------------
;
;   File:		Get_Image_Ident.Mar
;   Author:		David R. Potter
;   Creation Date:	11-Jan-1991
;
;------------------------------------------------------------------------------
;
;   Description:
;
;	This function will extract the image identification from the image
;	header contained in the process' P1 space and return it to the caller.
;	It also returns the fully qualified file specification of the currently
;	executing image.
;
;   Inputs/Outputs:
;	4(ap)		<pszImageSpec>	The address of a null-terminated string
;					  in which to return the fully qualified
;					  image file specification.
;	8(ap)		<lImageSpecLen>	The size of pszImageSpec (including space
;					  for the terminating null).
;	12(ap)		<pszImageName>	The address of a null-terminated string
;					  in which to return the image name from
;					  the image header.
;	16(ap)		<lImageNameLen>	The size of pszImageName (including space
;					  for the terminating null).
;	20(ap)		<pszImageIdent>	The address of a null-terminated string
;					  in which to return the image version
;					  number.
;	24(ap)		<lImageIdentLen> The size of pszImageIdent (including
;					  space for the terminating null).
;	28(ap)		<pqLinkTime>	The address of a quadword in which to
;					  return the link time.
;
;   Return:
;	SS$_NORMAL			Normal successful completion.
;	SS$_ACCVIO			Could not write to output buffer.
;	SS$_BUFFEROVF			String was too long for output buffer.
;	LIB$_WRONUMARG			Wrong number of arguments.
;
;------------------------------------------------------------------------------

	.LIBRARY	"SYS$LIBRARY:lib.mlb"
	.LINK		"SYS$SYSTEM:sys.stb" /Selective_Search

$IFDDEF							; Image File Descriptions.
$IHDDEF							; Image Header Definitions.
$IHIDEF							; Image Identification Offsets.
$SSDEF							; System Service Completion Codes.

;------------------------------------------------------------------------------
;
;   GET_IMAGE_IDENT	Get Image Identification Information.
;
;------------------------------------------------------------------------------

	.PSECT	_GET_IMAGE_IDENT, PIC, CON, REL, GBL, SHR, EXE, RD, NOWRT, LONG
	.ENTRY	GET_IMAGE_IDENT, ^m<r2, r3, r4, r5, r6, r7>

; Parameters:
pszImageSpec	= 4
lImageSpecLen	= 8
pszImageName	= 12
lImageNameLen	= 16
pszImageIdent	= 20
lImageIdentLen	= 24
pqLinkTime	= 28

	movl		#SS$_NORMAL, r7			; Set the return status.

; Make sure we can write to the output buffers.

	cmpl	#2, (ap)			; Are these params specified?
	bleq	5$				; Branch if so.
	jmp	GII_DONE			; Jump if not.
5$:
	tstl	pszImageSpec(ap)		; Does caller want this param?
	beql	10$				; Branch if not.
	tstl	lImageSpecLen(ap)		; Any space in output string?
	beql	RET_BUFFEROVF			; Branch if not.

	IFNOWRT	lImageSpecLen(ap), pszImageSpec(ap), RET_ACCVIO
10$:
	cmpl	#4, (ap)			; Are these params specified?
	bleq	15$				; Branch if so.
	jmp	PROBE_DONE			; Jump if not.
15$:
	tstl	pszImageName(ap)		; Does caller want this param?
	beql	20$				; Branch if not.
	tstl	lImageNameLen(ap)		; Any space in output string?
	beql	RET_BUFFEROVF			; Branch if not.

	IFNOWRT	lImageNameLen(ap), pszImageName(ap), RET_ACCVIO
20$:
	cmpl	#6, (ap)			; Are these params specified?
	bleq	25$				; Branch if so.
	jmp	PROBE_DONE			; Jump if not.
25$:
	tstl	pszImageIdent(ap)		; Does caller want this param?
	beql	30$				; Branch if not.
	tstl	lImageIdentLen(ap)		; Any space in output string?
	beql	RET_BUFFEROVF			; Branch if not.

	IFNOWRT	lImageIdentLen(ap), pszImageIdent(ap), RET_ACCVIO
30$:
	cmpl	#7, (ap)			; Is this parameter specified?
	bleq	35$				; Branch if so.
	jmp	PROBE_DONE			; Jump if not.
35$:
	tstl	pqLinkTime(ap)			; Does caller want this param?
	beql	PROBE_DONE			; Branch if not.

	IFWRT	#8, pqLinkTime(ap), PROBE_DONE
RET_ACCVIO:
	movzbl	#SS$_ACCVIO, r0			; Report an access violation.
	ret					; Return to the caller.
RET_BUFFEROVF:
	movzwl	#SS$_BUFFEROVF, r0		; Report a buffer overflow.
	ret					; Return to the caller.
PROBE_DONE:

	movl	g^CTL$GL_IMGHDRBF, r6		; Get image activator's image
						;   header buffer address.

; Return the fully qualified image file specification.

	cmpl	#2, (ap)			; Are these params specified?
	bgtr	110$				; Branch if not.
	movl	pszImageSpec(ap), r4		; Get caller's buffer address.
	beql	110$				; Branch if not specified.
	movl	lImageSpecLen(ap), r5		; Get caller's buffer length.
	beql	110$				; Branch if empty.
	decl	r5				; Subtract one for ending null.

	movl	4(r6), r2			; R2=addr of image file descr.
	movq	IFD$Q_CURPROG(r2), r2		; Get image name descr to R2/R3.
	movzwl	r2, r2				; Get size as a word.
	cmpl	r5, r2				; Caller's buffer big enough?
	bgeq	100$				; Branch if so.
	movl	r5, r2				; No - use caller's length.
	movzwl	#SS$_BUFFEROVF, r7		; Set return status.
100$:
	movc3	r2, (r3), (r4)			; Copy the specification to
						;   the caller's buffer.
	clrb	(r3)				; Null-terminate the string.
110$:

; Get the IHD address.

	movl	(r6), r2			; Point to Image HeaDer (IHD).
	movzwl	IHD$W_IMGIDOFF(r2), r0		; IMaGe IDent OFFset in IHD.
	movab	(r2)[r0], r6			; Get image identification addr.

; Return the image name as specified by the link command.

	cmpl	#4, (ap)			; Are these params specified?
	bgtr	210$				; Branch if not.
	movl	pszImageName(ap), r4		; Get caller's buffer address.
	beql	210$				; Branch if not specified.
	movl	lImageNameLen(ap), r5		; Get caller's buffer length.
	beql	210$				; Branch if empty.
	decl	r5				; Subtract one for ending null.

	movzbl	IHI$T_IMGNAM(r6), r1		; Get length of the image name.
	cmpw	r5, r1				; Caller's buffer big enough?
	bgeq	200$				; Branch if so.
	movl	r5, r1				; No - use caller's buffer len.
	movzwl	#SS$_BUFFEROVF, r7		; Set return status.
200$:
	movab	<IHI$T_IMGNAM+1>(r6), r0	; Get image name address.
	movc3	r1, (r0), (r4)			; Copy the specification to the
						;   caller's buffer.
	clrb	(r3)				; Null-terminate the string.
210$:

; Return the image identification (version).

	cmpl	#6, (ap)			; Are these params specified?
	bgtr	310$				; Branch if not.
	movl	pszImageIdent(ap), r4		; Get caller's buffer address.
	beql	310$				; Branch if not specified.
	movl	lImageIdentLen(ap), r5		; Get caller's buffer length.
	beql	310$				; Branch if empty.
	decl	r5				; Subtract one for ending null.

	movzbl	IHI$T_IMGID(r6), r1		; Get length of the IMAge ID.
	cmpw	r5, r1				; Caller's buffer big enough?
	bgeq	300$				; Branch if so.
	movl	r5, r1				; No - use caller's buffer len.
	movzwl	#SS$_BUFFEROVF, r7		; Set return status.
300$:
	movab	<IHI$T_IMGID+1>(r6), r0		; Get image name address.
	movc3	r1, (r0), (r4)			; Copy the specification to the
						;   caller's buffer.
	clrb	(r3)				; Null-terminate the string.
310$:

; Return the link date/time.

	cmpl	#7, (ap)			; Is this parameter specified?
	bgtr	410$				; Branch if not.
	movl	pqLinkTime(ap), r4		; Get caller's buffer address.
	beql	410$				; Branch if not specified.

	movq	IHI$Q_LINKTIME(r6), (r4)	; Copy image link time to
						;   caller's buffer.
410$:
GII_DONE:
	movl	r7, r0				; Set return status in R0.
	ret					; Return to the caller.

;------------------------------------------------------------------------------

	.END
;------------------------------------------------------------------------------
; CUT HERE
;------------------------------------------------------------------------------

