home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / callmon / src / example_getvm.c < prev    next >
C/C++ Source or Header  |  1996-08-06  |  3KB  |  106 lines

  1. /*  CALLMON Examples
  2.  *
  3.  *  File:     EXAMPLE_GETVM.C
  4.  *  Author:   Thierry Lelegard
  5.  *  Version:  1.0
  6.  *  Date:     24-JUL-1996
  7.  *
  8.  *  Abstract: Simple interception example program.
  9.  *            Intercept LIB$GET_VM and LIB$FREE_VM and trace the calls.
  10.  */
  11.  
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <builtins.h>
  17. #include <psldef.h>
  18. #include <ssdef.h>
  19. #include <stsdef.h>
  20. #include <starlet.h>
  21. #include <lib$routines.h>
  22. #include "callmon.h"
  23.  
  24.  
  25. /*
  26.  *  General pre- and post-processing routine for CALLMON.
  27.  */
  28.  
  29. static void interceptor (
  30.     callmon$arguments_t* arguments,
  31.     uint32               caller_invo_handle,
  32.     char*                routine_name,
  33.     uint64               (*intercepted_routine)(),
  34.     uint64               (*jacket_routine)())
  35. {
  36.     int arg;
  37.     uint64* ref;
  38.  
  39.     printf ("%s calling %s at %08X, jacket at %08X\n",
  40.         arguments->post_processing ? "AFTER" : "BEFORE",
  41.         routine_name,
  42.         intercepted_routine,
  43.         jacket_routine);
  44.  
  45.     /* Print the argument list, try to derefence pointers */
  46.  
  47.     printf ("    arg count = %d\n", arguments->arg_count);
  48.     for (arg = 0; arg < arguments->arg_count; arg++) {
  49.         printf ("    arg%-2d = %016LX", arg + 1, arguments->arg_list [arg]);
  50.         ref = (uint64*) arguments->arg_list [arg];
  51.         if (__PAL_PROBER (ref, sizeof (uint64), PSL$C_USER))
  52.             printf (" -> %016LX", *ref);
  53.         printf ("\n");
  54.     }
  55.  
  56.     /* In the post-processing phase, display the results */
  57.  
  58.     if (arguments->post_processing) {
  59.         printf ("    Result R0 = %016LX\n", arguments->result_r0);
  60.         printf ("    Result R1 = %016LX\n", arguments->result_r1);
  61.         printf ("    Result F0 = %016LX\n", arguments->result_f0);
  62.         printf ("    Result F1 = %016LX\n", arguments->result_f1);
  63.     }
  64. }
  65.  
  66.  
  67. /*
  68.  *  Test program entry point.
  69.  */
  70.  
  71. main ()
  72. {
  73.     uint32 status;
  74.     uint32 size;
  75.     char* ptr;
  76.  
  77.     printf ("Before intercepting LIB$GET_VM = %08X, LIB$FREE_VM = %08X\n",
  78.         lib$get_vm, lib$free_vm);
  79.  
  80.     status = callmon$intercept ("LIB$GET_VM", interceptor, interceptor);
  81.  
  82.     if (!$VMS_STATUS_SUCCESS (status))
  83.         sys$exit (status);
  84.  
  85.     status = callmon$intercept ("LIB$FREE_VM", interceptor, interceptor);
  86.  
  87.     if (!$VMS_STATUS_SUCCESS (status))
  88.         sys$exit (status);
  89.  
  90.     printf ("After intercepting LIB$GET_VM = %08X, LIB$FREE_VM = %08X\n",
  91.         lib$get_vm, lib$free_vm);
  92.  
  93.     printf ("\n");
  94.     callmon$dump_routine_tree (CALLMON$C_INTERCEPTED_ONLY);
  95.     printf ("\n");
  96.  
  97.     size = 100;
  98.     printf ("Calling LIB$GET_VM (100), &size = %08X, &ptr = %08X\n",
  99.         &size, &ptr);
  100.     status = lib$get_vm (&size, &ptr);
  101.     printf ("Result of LIB$GET_VM (100) = %08X, status = %08X\n", ptr, status);
  102.  
  103.     status = lib$free_vm (&size, &ptr);
  104.     printf ("Result of LIB$FREE_VM (100) = %08X, status = %08X\n", ptr, status);
  105. }
  106.