home *** CD-ROM | disk | FTP | other *** search
- /*
- * @(#)io.c 2.3 92/01/10
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <fcntl.h>
- #include <stropts.h>
- #include <poll.h>
- #include <sys/ptrace.h>
- #include <sys/uio.h>
-
- #include "defs.h"
-
- int
- sys_read(tcp)
- struct tcb *tcp;
- {
- if (entering(tcp)) {
- tprintf("%u, ", tcp->u_args[0]);
- } else {
- if (syserror(tcp))
- tprintf("%#x", tcp->u_args[1]);
- else
- (void)printstr(tcp->pid, tcp->u_args[1], tcp->u_rval);
- tprintf(", %u", tcp->u_args[2]);
- }
- return 0;
- }
-
- int
- sys_write(tcp)
- struct tcb *tcp;
- {
- if (entering(tcp)) {
- tprintf("%u, ", tcp->u_args[0]);
- (void)printstr(tcp->pid, tcp->u_args[1], tcp->u_args[2]);
- tprintf(", %u", tcp->u_args[2]);
- }
- return 0;
- }
-
- int
- sys_readv(tcp)
- struct tcb *tcp;
- {
- struct iovec *iov;
- int i, len;
-
- if (entering(tcp)) {
- tprintf("%u, ", tcp->u_args[0]);
- } else {
- if (syserror(tcp)) {
- tprintf("%#x, %u",
- tcp->u_args[1], tcp->u_args[2]);
- return 0;
- }
- len = tcp->u_args[2];
- if ((iov = (struct iovec *)malloc((u_int)len * sizeof *iov)) == NULL) {
- (void)fprintf(stderr, "No memory");
- return 0;
- }
- if (umove(tcp->pid, tcp->u_args[1],
- len * sizeof *iov, (char *)iov) < 0) {
- tprintf("%#x", tcp->u_args[1]);
- } else {
- for (i = 0; i < len; i++) {
- (void)printstr(tcp->pid, (int)iov[i].iov_base,
- iov[i].iov_len);
- }
- }
- free((char *)iov);
- tprintf(", %u", tcp->u_args[2]);
- }
- return 0;
- }
-
- int
- sys_writev(tcp)
- struct tcb *tcp;
- {
- struct iovec *iov;
- int i, len;
-
- if (entering(tcp)) {
- tprintf("%u, ", tcp->u_args[0]);
- len = tcp->u_args[2];
- if ((iov = (struct iovec *)malloc((u_int)len * sizeof *iov)) == NULL) {
- (void)fprintf(stderr, "No memory");
- return 0;
- }
- if (umove(tcp->pid, tcp->u_args[1],
- len * sizeof *iov, (char *)iov) < 0) {
- tprintf("%#x", tcp->u_args[1]);
- } else {
- for (i = 0; i < len; i++) {
- (void)printstr(tcp->pid, (int)iov[i].iov_base,
- iov[i].iov_len);
- }
- }
- free((char *)iov);
- tprintf(", %u", tcp->u_args[2]);
- }
- return 0;
- }
-
- int
- sys_ioctl(tcp)
- struct tcb *tcp;
- {
- char *symbol, *ioctl_lookup();
- int ioctl_decode();
-
- if (entering(tcp)) {
- tprintf("%u, ", tcp->u_args[0]);
- symbol = ioctl_lookup(tcp->u_args[1]);
- if (symbol)
- tprintf("%s, ", symbol);
- else
- tprintf("%#x, ", tcp->u_args[1]);
-
- if (ioctl_decode(tcp->pid, (u_int)tcp->u_args[1],
- (u_int)tcp->u_args[2]) == 0)
- tprintf("%#x", tcp->u_args[2]);
- }
- return 0;
- }
-
- static Xlat msgflags[] = {
- RS_HIPRI, "RS_HIPRI",
- 0, NULL,
- };
-
- int
- sys_putmsg(tcp)
- struct tcb *tcp;
- {
- struct strbuf buf;
- int i;
-
- if (entering(tcp)) {
- tprintf("%u, ", tcp->u_args[0]);
- for (i = 0; i < 2; i++) {
- if (umove(tcp->pid, tcp->u_args[i],
- sizeof buf, (char *)&buf) < 0) {
- tprintf("(struct strbuf *)%#x",
- tcp->u_args[i]);
- } else {
- (void)printstr(tcp->pid, (int)buf.buf, buf.len);
- }
- tprintf(", ");
- }
- printxval(msgflags, tcp->u_args[3], "RS_???");
- }
- return 0;
- }
-
- int
- sys_getmsg(tcp)
- struct tcb *tcp;
- {
- struct strbuf buf;
- int i, flags;
-
- if (entering(tcp)) {
- tprintf("%u, ", tcp->u_args[0]);
- } else {
- if (syserror(tcp)) {
- tprintf("(struct strbuf *)%#x, (struct strbuf *)%#x, (int *)%#x",
- tcp->u_args[1], tcp->u_args[2], tcp->u_args[3]);
- return 0;
- }
- for (i = 0; i < 2; i++) {
- if (umove(tcp->pid, tcp->u_args[i],
- sizeof buf, (char *)&buf) < 0) {
- tprintf("(struct strbuf *)%#x",
- tcp->u_args[i]);
- } else {
- (void)printstr(tcp->pid, (int)buf.buf, buf.len);
- }
- tprintf(", ");
- }
- if (tcp->u_args[3] == 0 || umove(tcp->pid, tcp->u_args[3],
- sizeof flags, (char *)&flags) < 0)
- tprintf("(int *)%#x", tcp->u_args[3]);
- else
- printxval(msgflags, flags, "RS_???");
- }
- return 0;
- }
-
- static Xlat pollflags[] = {
- POLLIN, "POLLIN", /* fd is readable */
- POLLPRI, "POLLPRI", /* priority info at fd */
- POLLOUT, "POLLOUT", /* fd is writeable (won't block) */
- POLLERR, "POLLERR", /* fd has error condition */
- POLLHUP, "POLLHUP", /* fd has been hung up on */
- POLLNVAL, "POLLNVAL", /* invalid pollfd entry */
- 0, NULL,
- };
-
- int
- sys_poll(tcp)
- struct tcb *tcp;
- {
- struct pollfd *pollp;
-
- if (entering(tcp)) {
- unsigned long i, nfds = tcp->u_args[1];
-
- if ((pollp = (struct pollfd *)malloc((u_int)nfds)) == NULL) {
- (void)fprintf(stderr, "sys_poll: no memory\n");
- tprintf("%#x, %u, %u",
- tcp->u_args[0], nfds, tcp->u_args[2]);
- return 0;
- }
- if (umove(tcp->pid, tcp->u_args[0],
- (int)(nfds * sizeof *pollp), (char *)pollp) < 0) {
- tprintf("%#x", tcp->u_args[0]);
- } else {
- for (i = 0; i < nfds; i++) {
- tprintf("{fd:%d, events:", pollp[i].fd);
- if (printflags(pollflags, pollp[i].events) == 0)
- tprintf("0");
- tprintf("}");
- }
- }
- tprintf(", %u, %u", nfds, tcp->u_args[2]);
- free((char *)pollp);
- }
- return 0;
- }
-