From: <ed_heinrich@npd.novell.com>
Newsgroups: vmsnet.internals
Subject: Re: Help getting image dumps?
Date: Tue, 7 Apr 92 9:14:55 MDT
Organization: Macro32<==>Vmsnet.Internals Gateway
X-Gateway-Source-Info: Mailing List

<Jamie Hanarahan writes:>
>
> Hi, folks,
>
> Do any of you have some good experience with SET PROCESS/DUMP ?
>
> I am trying to get this to work reliably so that I can have people send me
> dumps when the extended-packet version of uucico accvio's... since, naturally,
> I can't duplicate the problem here.
>
> However, I can't get it to work reliably on my copies of uucico.  Works fine
> on simple test images.
>
> What conditions will inhibit an image dump?  I know that it won't do an image
> dump if the image is installed with privileges that aren't in the process's
> current privilege mask (as read by JPI$_PROCPRIV), (and either CMKRNL or
> SETPRV in _PROCPRIV overrides this check), but that isn't the problem here.
> What else could it be?
>
>         --- Jamie Hanrahan, Kernel Mode Consulting, San Diego CA
> uucp 'g' protool guru, VMSnet (DECUS uucp) Working Group, and
> Chair, VMS Programming and Internals Working Group, U.S. DECUS VAX Systems SIG
> Internet:  jeh@cmkrnl.com, hanrahan@eisner.decus.org, or jeh@crash.cts.com
> Uucp:  ...{crash,eisner,uunet}!cmkrnl!jeh
>
> "There's no security... where's the challenge?!?"  -- Bruce Ellis on Unix
>



        Years ago I worked for a company with sites throughout the world and
we had the requirement to have a dump file to examine back in the development
office.  The following are the extracted relevant pieces that I used in an
exception handler to cause an image dump file.  It also has the feature of
purging the dump file to prevent exhausting the customers disk space.


        It has been a while since I looked into the conditions that allow/
disallow RUN/DUMP from creating a dump file but I got around those checks
by calling the image dump merge routine directly.  This approach allows a
dump to be generated no matter what RUN command is used.


        After the exception handler had written out messages to a disk file
and the system console, it would set the PHD$M_IMGDMP bit in the PHD and then
call the EXE$IMGDMP_MERGE code to merge in the image dump facility and
execute it.  This assumes that the code thread is executing in user mode and
that the process has CMKRNL privileges.  (Actually the real version called a
user-written service to set the PHD bit so that the process did not need
CMKRNL privs).  This approach gets around the requirement that a process be
RUN/DUMP.  It worked very well for us.


                                        - Ed -



        .Title  EXCEPTION       Exception Handler
        .Ident  /V2.8-00/       ; 17-Nov-1987   EAH908
        .Sbttl  HEADING         Program Description
;++
;
; PROJECT:
;       VAX/VMS Error handling
;
; PROGRAM:
;       EXCEPTION.MAR
;
; AUTHOR:                               CREATION DATE:
;       Edward A. Heinrich                      03-Jul-1984
;
; FUNCTION:
;       Exception Handler - Abort an image gracefully
;
; ENTRY POINTS:
;       EXCEPTION (by VMS)
;
; CALL FORMAT:
;       By VMS as a result of an exception condition
;
; ABSTRACT:
;       EXCEPTION is invoked by VMS as a result of an exception condition or by
;       a program directly to output an error message and unwind the call
;       frames to the point where the condition handler was established.
;       job is interactive, the same information will be displayed on the
;       terminal.  EXCEPTION then sets the PHD$V_DUMP bit in the process
;       header and merges in the VMS image dump code to produce a binary dump
;       disk file of the contents of memory at the time of the exception.
;
;
;
;--

        .Page
        .Sbttl  MODIFICATIONS   Detailed Modification History
;
; MODIFICATIONS HISTORY:
; ---------------------
;
;       V2.8-00 EAH908  Edward A. Heinrich      17-Nov-1987     15:30
;               Purge .DMP files to avoid eating a disk.
;
;       V2.7-00 EAH664  Edward A. Heinrich      28-Aug-1986     15:20
;               Allow images executing in EXEC mode to create dumps.
;
;       V2.6-01 EAH513  Edward A. Heinrich      18-Mar-1986     08:35
;               Add code to force image dumps.  Fix display of SP address.
;

        .Page
        .Sbttl  MACROS          Macro Definitions
;
;       VMS macro definitions
;
        $CHFDEF                         ; Define condition handler offsets
        $JPIDEF                         ; Define JPI offsets
        $PSLDEF                         ; Processor status word definitions


        .Page
        .Sbttl  IMPURE          Data Declarations

        .Psect  RTLRWC  EXE, PIC, NOSHR, WRT, QUAD



JPI_IMAGE:      .Long     0             ; Length of image name
                .Address JPI_IMAGE_NAME ; Make us a descriptor for FAO
JPI_IMAGE_NAME: .Blkb    128            ; For small image names


DUMP_DESC:      .Long   256             ; Descriptor for dump file name
                .Address DUMPSPEC       ;
DUMPSPEC:       .Blkb   256             ; Buffer for dump file name


        .Page
        .Sbttl  PURE            Storage Declarations

        .Psect  RTLROD  EXE, PIC, SHR, NOWRT, LONG, REL

JPI_ITEMS:                              ; Begin JPI item list
        .Word    128                    ; Size of image name buffer
        .Word    JPI$_IMAGNAME          ; Request current image name
        .Address JPI_IMAGE_NAME         ; Address to return image name to
        .Address JPI_IMAGE              ; Address to return image name length
        .Long    0                      ; Indicate end of list


        .Page
        .Sbttl  EXCEPTION               Code

        .Psect  RTLCOD  PIC,SHR,EXE,NOWRT,USR,RD,LONG

;+
;       EXCEPTION Entry Point - Entered as a condition handler by VMS
;
;       Argument list set up by VMS.
;-
        .Align  Long

        .Entry  EXCEPTION, ^M<R2,R3,R4,R5,R6,R7,R8>
                                        ; A place to begin at

        .
        .
        .

        $GETJPIW_S -                    ; Get Job/Process Information
                EFN     = #1,         - ; Specify an event flag
                ITMLST  = JPI_ITEMS     ; Address of item list

;
;       We are going to create a .DMP file.  Before we do so we want to purge
;       down previous versions of the .DMP file to aviod eating all the free
;       disk space.
;
  700$: PUSHAB  DUMP_DESC               ; Current directory buffer        EAH908
        PUSHAB  DUMP_DESC               ; Buffer to receive length        EAH908
        PUSHL   #0                      ; No new directory                EAH908
        CALLS   #3, G^SYS$SETDDIR       ; Call RMS routine                EAH908
        BLBC    R0, 900$                ; Branch if any problems          EAH908
;
;       Now build dump file name
;
        LOCC    #^A/]/, JPI_IMAGE, JPI_IMAGE_NAME                       ; EAH908
        BEQL    900$                    ; Branch if not found             EAH908
        MOVAB   1(R1), R2               ; Save address + 1                EAH908
        MOVL    R0, JPI_IMAGE           ; Copy remaining length           EAH908
        LOCC    #^A/./, JPI_IMAGE, (R2) ; Search for period               EAH908
        BEQL    900$                    ; Branch if not found             EAH908
        SUBL3   R2, R1, R0              ; Compute length of image name    EAH908
        INCL    R0                      ; Account for period we found     EAH908
        MOVAB   DUMPSPEC, R3            ; Start of filename buffer        EAH908
        ADDL2   DUMP_DESC, R3           ; Offset into buffer              EAH908
        ADDL    R0, DUMP_DESC           ; Update descriptor length        EAH908
        MOVC3   R0, (R2), (R3)          ; Copy filename to dumpname bufferEAH908
        ADDL2   #6, DUMP_DESC           ; Add in next 6 bytes             EAH908
        MOVL    #^A/DMP;/, (R3)+        ; Tack on the extension           EAH908
        MOVW    #^A/-3/, (R3)+          ; And wildcard version            EAH908

  800$: PUSHAB  DUMP_DESC               ; Address of file to delete       EAH908
        CALLS   #1, G^LIB$DELETE_FILE   ; Let VMS delete the file for us  EAH908
        BLBS    R0, 800$                ; If success try again            EAH908
;
;       Force image to dump - First call IMAGE_DUMP to set the dump bit in the
;       PHD then call EXE$IMGDMP_MERGE, if in USER mode, to merge in the dump
;       code.  If in EXEC mode then call EXE$IMGDMP_EXEC.
;
  900$: $CMKRNL_S       -               ; Go to kernel mode to
                routin  = DUMP_IMAGE    ; ... set PHD bit to force dump of image
        MOVPSL  R0                      ; Get PSL in R0
        EXTZV   #PSL$V_CURMOD, #PSL$S_CURMOD, R0, R0
                                        ; Get current mode from PSL
        CMPL    #PSL$C_EXEC, R0         ; Are we in EXEC mode?
        BNEQ    1000$                   ; Nope do USER mode dump entry
        JSB     G^EXE$IMGDMP_EXEC       ; Do dump with EXEC mode entry
        BRB     2000$                   ; And join common code

        .Align  Long
 1000$: JSB     G^EXE$IMGDMP_MERGE      ; Merge in dump code
;
;       Final cleanup - unwind call stack
;
 2000$: MOVL    CHF$L_MCHARGLST(AP),R2  ; Point R2 to mechanism array
        $UNWIND_S -                     ; Unwind the call stack
                depadr  = CHF$L_MCH_DEPTH(R2)
                                        ; Make sure you get the right number

        RET                             ; Exit back to INIT



        .Sbttl  DUMP_IMAGE      Set PHD$M_IMGDMP bit
;+
;
; FUNCTIONAL DESCRIPTION:
;       Kernel mode routine to set the image dump requested bits in the PHD.
;
; INPUTS:
;       None.
;
; OUTPUTS:
;       R0      SS$_NORMAL
;
;-
        .Align  Long
        .Entry  DUMP_IMAGE, 0           ; KERNEL routine entry address

        MOVL    G^CTL$GL_PHD, R0        ; Get current process PHD address
        BISW    #PHD$M_IMGDMP, PHD$W_FLAGS(R0)
                                        ; Indicate a desire to dump
        MOVZBL  #SS$_NORMAL, R0         ; Always return success
        RET                             ; And be gone




        .End                            ; That's all folks



-------------------------------------------------------------------------------
Ed Heinrich, Novell, Inc.       Sandy, Utah
ed_heinrich@npd.Novell.COM
-------------------------------------------------------------------------------