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

  1. /*
  2.  * @(#)io.c    2.3 92/01/10
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <sys/types.h>
  8. #include <fcntl.h>
  9. #include <stropts.h>
  10. #include <poll.h>
  11. #include <sys/ptrace.h>
  12. #include <sys/uio.h>
  13.  
  14. #include "defs.h"
  15.  
  16. int
  17. sys_read(tcp)
  18. struct tcb *tcp;
  19. {
  20.     if (entering(tcp)) {
  21.         tprintf("%u, ", tcp->u_args[0]);
  22.     } else {
  23.         if (syserror(tcp))
  24.             tprintf("%#x", tcp->u_args[1]);
  25.         else
  26.             (void)printstr(tcp->pid, tcp->u_args[1], tcp->u_rval);
  27.         tprintf(", %u", tcp->u_args[2]);
  28.     }
  29.     return 0;
  30. }
  31.  
  32. int
  33. sys_write(tcp)
  34. struct tcb *tcp;
  35. {
  36.     if (entering(tcp)) {
  37.         tprintf("%u, ", tcp->u_args[0]);
  38.         (void)printstr(tcp->pid, tcp->u_args[1], tcp->u_args[2]);
  39.         tprintf(", %u", tcp->u_args[2]);
  40.     }
  41.     return 0;
  42. }
  43.  
  44. int
  45. sys_readv(tcp)
  46. struct tcb *tcp;
  47. {
  48.     struct iovec *iov;
  49.     int i, len;
  50.  
  51.     if (entering(tcp)) {
  52.         tprintf("%u, ", tcp->u_args[0]);
  53.     } else {
  54.         if (syserror(tcp)) {
  55.             tprintf("%#x, %u",
  56.                     tcp->u_args[1], tcp->u_args[2]);
  57.             return 0;
  58.         }
  59.         len = tcp->u_args[2];
  60.         if ((iov = (struct iovec *)malloc((u_int)len * sizeof *iov)) == NULL) {
  61.             (void)fprintf(stderr, "No memory");
  62.             return 0;
  63.         }
  64.         if (umove(tcp->pid, tcp->u_args[1],
  65.                 len * sizeof *iov, (char *)iov) < 0) {
  66.             tprintf("%#x", tcp->u_args[1]);
  67.         } else {
  68.             for (i = 0; i < len; i++) {
  69.                 (void)printstr(tcp->pid, (int)iov[i].iov_base,
  70.                             iov[i].iov_len);
  71.             }
  72.         }
  73.         free((char *)iov);
  74.         tprintf(", %u", tcp->u_args[2]);
  75.     }
  76.     return 0;
  77. }
  78.  
  79. int
  80. sys_writev(tcp)
  81. struct tcb *tcp;
  82. {
  83.     struct iovec *iov;
  84.     int i, len;
  85.  
  86.     if (entering(tcp)) {
  87.         tprintf("%u, ", tcp->u_args[0]);
  88.         len = tcp->u_args[2];
  89.         if ((iov = (struct iovec *)malloc((u_int)len * sizeof *iov)) == NULL) {
  90.             (void)fprintf(stderr, "No memory");
  91.             return 0;
  92.         }
  93.         if (umove(tcp->pid, tcp->u_args[1],
  94.                 len * sizeof *iov, (char *)iov) < 0) {
  95.             tprintf("%#x", tcp->u_args[1]);
  96.         } else {
  97.             for (i = 0; i < len; i++) {
  98.                 (void)printstr(tcp->pid, (int)iov[i].iov_base,
  99.                             iov[i].iov_len);
  100.             }
  101.         }
  102.         free((char *)iov);
  103.         tprintf(", %u", tcp->u_args[2]);
  104.     }
  105.     return 0;
  106. }
  107.  
  108. int
  109. sys_ioctl(tcp)
  110. struct tcb *tcp;
  111. {
  112.     char *symbol, *ioctl_lookup();
  113.     int ioctl_decode();
  114.  
  115.     if (entering(tcp)) {
  116.         tprintf("%u, ", tcp->u_args[0]);
  117.         symbol = ioctl_lookup(tcp->u_args[1]);
  118.         if (symbol)
  119.             tprintf("%s, ", symbol);
  120.         else
  121.             tprintf("%#x, ", tcp->u_args[1]);
  122.  
  123.         if (ioctl_decode(tcp->pid, (u_int)tcp->u_args[1],
  124.                         (u_int)tcp->u_args[2]) == 0)
  125.             tprintf("%#x", tcp->u_args[2]);
  126.     }
  127.     return 0;
  128. }
  129.  
  130. static Xlat msgflags[] = {
  131.     RS_HIPRI,    "RS_HIPRI",
  132.     0,         NULL,
  133. };
  134.  
  135. int
  136. sys_putmsg(tcp)
  137. struct tcb *tcp;
  138. {
  139.     struct strbuf buf;
  140.     int i;
  141.  
  142.     if (entering(tcp)) {
  143.         tprintf("%u, ", tcp->u_args[0]);
  144.         for (i = 0; i < 2; i++) {
  145.             if (umove(tcp->pid, tcp->u_args[i],
  146.                     sizeof buf, (char *)&buf) < 0) {
  147.                 tprintf("(struct strbuf *)%#x",
  148.                                 tcp->u_args[i]);
  149.             } else {
  150.                 (void)printstr(tcp->pid, (int)buf.buf, buf.len);
  151.             }
  152.             tprintf(", ");
  153.         }
  154.         printxval(msgflags, tcp->u_args[3], "RS_???");
  155.     }
  156.     return 0;
  157. }
  158.  
  159. int
  160. sys_getmsg(tcp)
  161. struct tcb *tcp;
  162. {
  163.     struct strbuf buf;
  164.     int i, flags;
  165.  
  166.     if (entering(tcp)) {
  167.         tprintf("%u, ", tcp->u_args[0]);
  168.     } else {
  169.         if (syserror(tcp)) {
  170.             tprintf("(struct strbuf *)%#x, (struct strbuf *)%#x, (int *)%#x",
  171.             tcp->u_args[1], tcp->u_args[2], tcp->u_args[3]);
  172.             return 0;
  173.         }
  174.         for (i = 0; i < 2; i++) {
  175.             if (umove(tcp->pid, tcp->u_args[i],
  176.                     sizeof buf, (char *)&buf) < 0) {
  177.                 tprintf("(struct strbuf *)%#x",
  178.                                 tcp->u_args[i]);
  179.             } else {
  180.                 (void)printstr(tcp->pid, (int)buf.buf, buf.len);
  181.             }
  182.             tprintf(", ");
  183.         }
  184.         if (tcp->u_args[3] == 0 || umove(tcp->pid, tcp->u_args[3],
  185.                         sizeof flags, (char *)&flags) < 0)
  186.             tprintf("(int *)%#x", tcp->u_args[3]);
  187.         else
  188.             printxval(msgflags, flags, "RS_???");
  189.     }
  190.     return 0;
  191. }
  192.  
  193. static Xlat pollflags[] = {
  194.     POLLIN,        "POLLIN",    /* fd is readable */
  195.     POLLPRI,    "POLLPRI",    /* priority info at fd */
  196.     POLLOUT,    "POLLOUT",    /* fd is writeable (won't block) */
  197.     POLLERR,    "POLLERR",    /* fd has error condition */
  198.     POLLHUP,    "POLLHUP",    /* fd has been hung up on */
  199.     POLLNVAL,    "POLLNVAL",    /* invalid pollfd entry */
  200.     0,        NULL,
  201. };
  202.  
  203. int
  204. sys_poll(tcp)
  205. struct tcb *tcp;
  206. {
  207.     struct pollfd *pollp;
  208.  
  209.     if (entering(tcp)) {
  210.         unsigned long i, nfds = tcp->u_args[1];
  211.  
  212.         if ((pollp = (struct pollfd *)malloc((u_int)nfds)) == NULL) {
  213.             (void)fprintf(stderr, "sys_poll: no memory\n");
  214.             tprintf("%#x, %u, %u",
  215.                     tcp->u_args[0], nfds, tcp->u_args[2]);
  216.             return 0;
  217.         }
  218.         if (umove(tcp->pid, tcp->u_args[0],
  219.             (int)(nfds * sizeof *pollp), (char *)pollp) < 0) {
  220.             tprintf("%#x", tcp->u_args[0]);
  221.         } else {
  222.             for (i = 0; i < nfds; i++) {
  223.                 tprintf("{fd:%d, events:", pollp[i].fd);
  224.                 if (printflags(pollflags, pollp[i].events) == 0)
  225.                     tprintf("0");
  226.                 tprintf("}");
  227.             }
  228.         }
  229.         tprintf(", %u, %u", nfds, tcp->u_args[2]);
  230.         free((char *)pollp);
  231.     }
  232.     return 0;
  233. }
  234.