Figure 1: MACRO-32 routine rewritten in DEC C ---------------------------------------------------------------------- MACRO-32 routine used in early versions of VMS to get the process name ---------------------------------------------------------------------- .library "sys$library:lib.mlb" $pcbdef $ssdef .page .sbttl extract_prcnam -- copy process name to descriptor ;++ ; Abstract: ; Kernel mode procedure to copy the process name of the current ; process into a use supplied descriptor. ; ; Inputs: ; 4(ap) -- address of string descriptor to receive process name. ; ; Outputs: ; Current process's name is written to supplied string descriptor. ; ; Return Value: ; - SS$_NORMAL ; - SS$_ACCVIO ; - SS$_BUFFEROVF ;-- .psect code exe, shr, pic, novec, quad extract_prcnam: .word ^m moval g^lib$sig_to_ret, (fp) ; ret exception status to caller movzwl #ss$_accvio, r0 ; assume access violation ifnord #8, (ap), 10$ ; br arguments not accessible movl 4(ap), r1 ; load address of descriptor ifnowrt #8, (r1), 10$ ; br descriptor not writable movq (r1), r2 ; load descriptor into r2, r3 ifnowrt r2, (r3), 10$ ; br descriptor not writable movl g^sch$gl_curpcb, r4 ; load pcb into r4 movzbl pcb$t_lname(r4), r0 ; get length of process name movw r0, (r1) ; write length into descriptor movc5 r0, pcb$t_lname+1(r4), #0, r2, (r3) ; copy name into descriptor tstl r0 ; test buffer overflow bneq 20$ ; branch if yes movl #ss$_normal, r0 ; load normal return status 10$: ret 20$: movl g^sch$gl_curpcb, r4 ; restore r4 movzbl pcb$t_lname(r4), r1 ; get length of process name subl2 r0, r1 ; get length of string copied movw r1, @4(ap) ; write length into descriptor movzwl #ss$_bufferovf, r0 ; load buffer two small status ret .page .sbttl getprcnam -- procedure to hid cmkrnl system service ;++ ; Abstract: ; getprcnam hides the cmkrnl system service form the calling program. ; ; Inputs: ; ap -- argument list pointer passed to getprcnam ; ; Return Value ; any status returned from getprcnam ; ; Special Notes: ; Requires cmkrnl privilege ;-- .align quad .entry getprcnam, ^m<> $cmkrnl_s b^extract_prcnam, (ap) ret .end --------------------------------------------------------------- High level language routine to replace obsolute MACRO32 routine --------------------------------------------------------------- /* * Abstract: * Procedure to get the current process name using the SYS$GETJPIW * System Service. * * Inputs: * None * * Outputs: * Process name of current process is written into supplied character * string descriptor. * * Return Value: * Program status * */ #include #include #include unsigned long int getprcnam( struct dsc$descriptor_s *prcnam ) { struct { unsigned short buflen; unsigned short item_code; char *bufadr; unsigned short *retlen; } itmlst[2]; itmlst[0].buflen = prcnam->dsc$w_length; itmlst[0].item_code = JPI$_PRCNAM; itmlst[0].bufadr = prcnam->dsc$a_pointer; itmlst[0].retlen = &prcnam->dsc$w_length; itmlst[1].buflen = 0; itmlst[1].item_code = 0; return ( SYS$GETJPIW( 0, NULL, NULL, itmlst, NULL, NULL, 0 ) ); }