home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / sun / volume3 / strace / part01 / mem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-02  |  3.2 KB  |  198 lines

  1. /*
  2.  * @(#)mem.c    2.5 92/01/21
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <sys/types.h>
  8. #include <sys/ptrace.h>
  9. #include <sys/file.h>
  10. #include <sys/stat.h>
  11. #include <sys/time.h>
  12. #include <sys/mman.h>
  13.  
  14. #include "defs.h"
  15.  
  16. int
  17. sys_brk(tcp)
  18. struct tcb *tcp;
  19. {
  20.     if (entering(tcp)) {
  21.         tprintf("%#x", tcp->u_args[0]);
  22.     }
  23.     return 0;
  24. }
  25.  
  26. int
  27. sys_sbrk(tcp)
  28. struct tcb *tcp;
  29. {
  30.     if (entering(tcp)) {
  31.         tprintf("%u", tcp->u_args[0]);
  32.     }
  33.     return RVAL_HEX;
  34. }
  35.  
  36. static Xlat mmap_prot[] = {
  37.     PROT_READ,    "READ",
  38.     PROT_WRITE,    "WRITE",
  39.     PROT_EXEC,    "EXEC",
  40.     PROT_NONE,    "NONE",
  41.     0,        NULL,
  42. };
  43. static Xlat mmap_flags[] = {
  44.     MAP_SHARED,     "SHARED",
  45.     MAP_PRIVATE,     "PRIVATE",
  46.     MAP_FIXED,     "FIXED",
  47. #ifdef    MAP_RENAME
  48.     MAP_RENAME,     "RENAME",
  49. #endif
  50. #ifdef    MAP_NORESERVE
  51.     MAP_NORESERVE,     "NORESERVE",
  52. #endif
  53.     0,        NULL,
  54. };
  55.  
  56. int
  57. sys_smmap(tcp)
  58. struct tcb *tcp;
  59. {
  60.     if (entering(tcp)) {
  61.         /* addr */
  62.         tprintf("%#x, ", tcp->u_args[0]);
  63.         /* len */
  64.         tprintf("%u, ", tcp->u_args[1]);
  65.         /* prot */
  66.         if (!printflags(mmap_prot, tcp->u_args[2]))
  67.             tprintf("PROT_???");
  68.         tprintf(", ");
  69.         /* flags */
  70.         printxval(mmap_flags, tcp->u_args[3] & MAP_TYPE, "MAP_???");
  71.         (void)addflags(mmap_flags,
  72.                 tcp->u_args[3] & (~_MAP_NEW & ~MAP_TYPE));
  73.         /* fd */
  74.         tprintf(", %u, ", tcp->u_args[4]);
  75.         /* offset */
  76.         tprintf("%#x", tcp->u_args[5]);
  77.     }
  78.     return RVAL_HEX;
  79. }
  80.  
  81. int
  82. sys_munmap(tcp)
  83. struct tcb *tcp;
  84. {
  85.     if (entering(tcp)) {
  86.         tprintf("%#x, %u", tcp->u_args[0], tcp->u_args[1]);
  87.     }
  88.     return 0;
  89. }
  90.  
  91. int
  92. sys_mprotect(tcp)
  93. struct tcb *tcp;
  94. {
  95.     if (entering(tcp)) {
  96.         /* addr */
  97.         tprintf("%#x", tcp->u_args[0]);
  98.         /* len */
  99.         tprintf(", %u, ", tcp->u_args[1]);
  100.         /* prot */
  101.         if (!printflags(mmap_prot, tcp->u_args[2]))
  102.             tprintf("PROT_???");
  103.     }
  104.     return 0;
  105. }
  106.  
  107. static Xlat mctl_funcs[] = {
  108.     MC_LOCK,    "LOCK",
  109.     MC_LOCKAS,    "LOCKAS",
  110.     MC_SYNC,    "SYNC",
  111.     MC_UNLOCK,    "UNLOCK",
  112.     MC_UNLOCKAS,    "UNLOCKAS",
  113.     0,        NULL,
  114. };
  115. static Xlat mctl_lockas[] = {
  116.     MCL_CURRENT,    "CURRENT",
  117.     MCL_FUTURE,    "FUTURE",
  118.     0,        NULL,
  119. };
  120. static Xlat mctl_sync[] = {
  121.     MS_ASYNC,    "ASYNC",
  122.     MS_INVALIDATE,    "INVALIDATE",
  123.     0,        NULL,
  124. };
  125.  
  126. int
  127. sys_mctl(tcp)
  128. struct tcb *tcp;
  129. {
  130.     int arg, function;
  131.  
  132.     if (entering(tcp)) {
  133.         /* addr */
  134.         tprintf("%#x", tcp->u_args[0]);
  135.         /* len */
  136.         tprintf(", %u, ", tcp->u_args[1]);
  137.         /* function */
  138.         function = tcp->u_args[2];
  139.         if (!printflags(mctl_funcs, function))
  140.             tprintf("MC_???");
  141.         /* arg */
  142.         arg = tcp->u_args[3];
  143.         tprintf(", ");
  144.         switch (function) {
  145.         case MC_SYNC:
  146.             if (!printflags(mctl_sync, arg))
  147.                 tprintf("MS_???");
  148.             break;
  149.         case MC_LOCKAS:
  150.             if (!printflags(mctl_lockas, arg))
  151.                 tprintf("MCL_???");
  152.             break;
  153.         default:
  154.             tprintf("%#x", arg);
  155.             break;
  156.         }
  157.     }
  158.     return 0;
  159. }
  160.  
  161. int
  162. sys_mincore(tcp)
  163. struct tcb *tcp;
  164. {
  165.     int i, len;
  166.     char *vec = (char *)0;
  167.  
  168.     if (entering(tcp)) {
  169.         tprintf("%#x, %u, ", tcp->u_args[0], tcp->u_args[1]);
  170.     } else {
  171.         len = tcp->u_args[1];
  172.         if (syserror(tcp) || tcp->u_args[2] == 0 ||
  173.             (vec = malloc((u_int)len)) == NULL ||
  174.             umove(tcp->pid, tcp->u_args[2], len, vec) < 0)
  175.             tprintf("%#x", tcp->u_args[2]);
  176.         else
  177.             for (i = 0; i < len; i++) {
  178.                 if (!verbose && i >= max_str_len) {
  179.                     tprintf("..");
  180.                     break;
  181.                 }
  182.                 tprintf((vec[i]&1)?"1":"0");
  183.             }
  184.  
  185.         if (vec) free(vec);
  186.     }
  187.     return 0;
  188. }
  189.  
  190. int
  191. sys_getpagesize(tcp)
  192. struct tcb *tcp;
  193. {
  194.     if (exiting(tcp))
  195.         return RVAL_HEX;
  196.     return 0;
  197. }
  198.