Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/sys/compat/netbsd32 pull up 1.7. approved by thorpej:



details:   https://anonhg.NetBSD.org/src/rev/056450cdf048
branches:  netbsd-1-5
changeset: 489268:056450cdf048
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sat Aug 26 01:08:57 2000 +0000

description:
pull up 1.7.  approved by thorpej:
>Fix netbsd32_ioctls.

diffstat:

 sys/compat/netbsd32/netbsd32_ioctl.c |  466 ++++++++++++++++++++--------------
 1 files changed, 271 insertions(+), 195 deletions(-)

diffs (truncated from 630 to 300 lines):

diff -r f99cbb5ba1d6 -r 056450cdf048 sys/compat/netbsd32/netbsd32_ioctl.c
--- a/sys/compat/netbsd32/netbsd32_ioctl.c      Sat Aug 26 01:07:05 2000 +0000
+++ b/sys/compat/netbsd32/netbsd32_ioctl.c      Sat Aug 26 01:08:57 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_ioctl.c,v 1.5 1999/12/30 15:40:45 eeh Exp $   */
+/*     $NetBSD: netbsd32_ioctl.c,v 1.5.4.1 2000/08/26 01:08:57 mrg Exp $       */
 
 /*
  * Copyright (c) 1998 Matthew R. Green
@@ -34,6 +34,11 @@
 
 #include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/filedesc.h>
+#include <sys/ioctl.h>
+#include <sys/file.h>
+#include <sys/proc.h>
+#include <sys/socketvar.h>
 #include <sys/audioio.h>
 #include <sys/disklabel.h>
 #include <sys/dkio.h>
@@ -61,10 +66,12 @@
 #include <compat/netbsd32/netbsd32_ioctl.h>
 #include <compat/netbsd32/netbsd32_syscallargs.h>
 
+
 void
-netbsd32_to_fbcmap(s32p, p)
+netbsd32_to_fbcmap(s32p, p, cmd)
        struct netbsd32_fbcmap *s32p;
        struct fbcmap *p;
+       u_long cmd;
 {
 
        p->index = s32p->index;
@@ -75,25 +82,27 @@
 }
 
 void
-netbsd32_to_fbcursor(s32p, p)
+netbsd32_to_fbcursor(s32p, p, cmd)
        struct netbsd32_fbcursor *s32p;
        struct fbcursor *p;
+       u_long cmd;
 {
 
        p->set = s32p->set;
        p->enable = s32p->enable;
        p->pos = s32p->pos;
        p->hot = s32p->hot;
-       netbsd32_to_fbcmap(&s32p->cmap, &p->cmap);
+       netbsd32_to_fbcmap(&s32p->cmap, &p->cmap, cmd);
        p->size = s32p->size;
        p->image = (char *)(u_long)s32p->image;
        p->mask = (char *)(u_long)s32p->mask;
 }
 
 void
-netbsd32_to_opiocdesc(s32p, p)
+netbsd32_to_opiocdesc(s32p, p, cmd)
        struct netbsd32_opiocdesc *s32p;
        struct opiocdesc *p;
+       u_long cmd;
 {
 
        p->op_nodeid = s32p->op_nodeid;
@@ -104,9 +113,10 @@
 }
 
 void
-netbsd32_to_partinfo(s32p, p)
+netbsd32_to_partinfo(s32p, p, cmd)
        struct netbsd32_partinfo *s32p;
        struct partinfo *p;
+       u_long cmd;
 {
 
        p->disklab = (struct disklabel *)(u_long)s32p->disklab;
@@ -114,9 +124,10 @@
 }
 
 void
-netbsd32_to_format_op(s32p, p)
+netbsd32_to_format_op(s32p, p, cmd)
        struct netbsd32_format_op *s32p;
        struct format_op *p;
+       u_long cmd;
 {
 
        p->df_buf = (char *)(u_long)s32p->df_buf;
@@ -144,9 +155,10 @@
 #endif
 
 void
-netbsd32_to_ifconf(s32p, p)
+netbsd32_to_ifconf(s32p, p, cmd)
        struct netbsd32_ifconf *s32p;
        struct ifconf *p;
+       u_long cmd;
 {
 
        p->ifc_len = s32p->ifc_len;
@@ -155,9 +167,10 @@
 }
 
 void
-netbsd32_to_ifmediareq(s32p, p)
+netbsd32_to_ifmediareq(s32p, p, cmd)
        struct netbsd32_ifmediareq *s32p;
        struct ifmediareq *p;
+       u_long cmd;
 {
 
        memcpy(p, s32p, sizeof *s32p);
@@ -165,9 +178,10 @@
 }
 
 void
-netbsd32_to_ifdrv(s32p, p)
+netbsd32_to_ifdrv(s32p, p, cmd)
        struct netbsd32_ifdrv *s32p;
        struct ifdrv *p;
+       u_long cmd;
 {
 
        memcpy(p, s32p, sizeof *s32p);
@@ -175,9 +189,10 @@
 }
 
 void
-netbsd32_to_sioc_vif_req(s32p, p)
+netbsd32_to_sioc_vif_req(s32p, p, cmd)
        struct netbsd32_sioc_vif_req *s32p;
        struct sioc_vif_req *p;
+       u_long cmd;
 {
 
        p->vifi = s32p->vifi;
@@ -188,9 +203,10 @@
 }
 
 void
-netbsd32_to_sioc_sg_req(s32p, p)
+netbsd32_to_sioc_sg_req(s32p, p, cmd)
        struct netbsd32_sioc_sg_req *s32p;
        struct sioc_sg_req *p;
+       u_long cmd;
 {
 
        p->src = s32p->src;
@@ -253,6 +269,16 @@
 }
 
 void
+netbsd32_from_partinfo(p, s32p)
+       struct partinfo *p;
+       struct netbsd32_partinfo *s32p;
+{
+
+       s32p->disklab = (netbsd32_disklabel_tp_t)(u_long)p->disklab;
+       s32p->part = s32p->part;
+}
+
+void
 netbsd32_from_format_op(p, s32p)
        struct format_op *p;
        struct netbsd32_format_op *s32p;
@@ -366,9 +392,17 @@
                syscallarg(netbsd32_u_long) com;
                syscallarg(netbsd32_voidp) data;
        } */ *uap = v;
-       struct sys_ioctl_args ua;
-       void *data = NULL;
-       int rv;
+       struct file *fp;
+       struct filedesc *fdp;
+       u_long com;
+       int error = 0;
+       u_int size, size32;
+       caddr_t data, memp = NULL;
+       caddr_t data32, memp32 = NULL;
+       int tmp;
+#define STK_PARAMS     128
+       u_long stkbuf[STK_PARAMS/sizeof(u_long)];
+       u_long stkbuf32[STK_PARAMS/sizeof(u_long)];
 
        /*
         * we need to translate some commands (_IOW) before calling sys_ioctl,
@@ -387,219 +421,261 @@
        }
 #endif
 
-/* we define some handy macros here... */
-#define IOCTL_STRUCT_CONV_TO(type)     \
-       data = malloc(sizeof(struct type), M_TEMP, M_WAITOK); \
-       __CONCAT(netbsd32_to_, type)((struct __CONCAT(netbsd32_, type) *) \
-           (u_long)SCARG(uap, data), data)
+       fdp = p->p_fd;
+       if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
+           (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL ||
+           (fp->f_iflags & FIF_WANTCLOSE) != 0)
+               return (EBADF);
+
+       FILE_USE(fp);
+
+       if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
+               error = EBADF;
+               goto out;
+       }
+
+       switch (com = SCARG(uap, com)) {
+       case FIONCLEX:
+               fdp->fd_ofileflags[SCARG(uap, fd)] &= ~UF_EXCLOSE;
+               goto out;
+
+       case FIOCLEX:
+               fdp->fd_ofileflags[SCARG(uap, fd)] |= UF_EXCLOSE;
+               goto out;
+       }
 
-#define IOCTL_STRUCT_CONV_CMD_TO(type, cmd)    \
-       data = malloc(sizeof(struct type), M_TEMP, M_WAITOK); \
-       __CONCAT(netbsd32_to_, type)((struct __CONCAT(netbsd32_, type) *) \
-           (u_long)SCARG(uap, data), data, cmd)
+       /*
+        * Interpret high order word to find amount of data to be
+        * copied to/from the user's address space.
+        */
+       size32 = IOCPARM_LEN(com);
+       if (size32 > IOCPARM_MAX) {
+               error = ENOTTY;
+               goto out;
+       }
+       memp = NULL;
+       if (size32 > sizeof(stkbuf)) {
+               memp32 = (caddr_t)malloc((u_long)size32, M_IOCTLOPS, M_WAITOK);
+               data32 = memp32;
+       } else
+               data32 = (caddr_t)stkbuf32;
+       if (com&IOC_IN) {
+               if (size32) {
+                       error = copyin((caddr_t)(u_long)SCARG(uap, data), 
+                                      data32, size32);
+                       if (error) {
+                               if (memp32)
+                                       free(memp32, M_IOCTLOPS);
+                               goto out;
+                       }
+               } else
+                       *(caddr_t *)data32 = (caddr_t)(u_long)SCARG(uap, data);
+       } else if ((com&IOC_OUT) && size32)
+               /*
+                * Zero the buffer so the user always
+                * gets back something deterministic.
+                */
+               memset(data32, 0, size32);
+       else if (com&IOC_VOID)
+               *(caddr_t *)data = (caddr_t)(u_long)SCARG(uap, data);
 
-#define IOCTL_STRUCT_CONV_FROM(type)   \
-       __CONCAT(netbsd32_from_, type)(data, \
-           (struct __CONCAT(netbsd32_, type) *) (u_long)SCARG(uap, data))
-
-#define IOCTL_STRUCT_CONV_CMD_FROM(type, cmd)  \
-       __CONCAT(netbsd32_from_, type)(data, \
-           (struct __CONCAT(netbsd32_, type) *) (u_long)SCARG(uap, data), cmd)
+/* we define some handy macros here... */
+#define IOCTL_STRUCT_CONV_TO(cmd, type)        \
+               com = cmd; \
+               size = IOCPARM_LEN(com); \
+               if (size > sizeof(stkbuf)) \
+                       data = memp = malloc(size, M_IOCTLOPS, M_WAITOK); \
+               else \
+                       data = (caddr_t)stkbuf; \
+               __CONCAT(netbsd32_to_, type)((struct __CONCAT(netbsd32_, type) *) \
+                       data32, (struct type *)data, com); \
+               error = (*fp->f_ops->fo_ioctl)(fp, com, data, p); \
+               __CONCAT(netbsd32_from_, type)((struct type *)data, \
+                       (struct __CONCAT(netbsd32_, type) *)data32); \
+               break
 
        /*
         * convert various structures, pointers, and other objects that
         * change size from 32 bit -> 64 bit, for all ioctl commands.
         */
        switch (SCARG(uap, com)) {
-       case FBIOPUTCMAP:
-       case FBIOGETCMAP:
-               IOCTL_STRUCT_CONV_TO(fbcmap);
+       case FIONBIO:
+               if ((tmp = *(int *)data) != 0)
+                       fp->f_flag |= FNONBLOCK;
+               else
+                       fp->f_flag &= ~FNONBLOCK;
+               error = (*fp->f_ops->fo_ioctl)(fp, FIONBIO, (caddr_t)&tmp, p);
+               break;
+
+       case FIOASYNC:
+               if ((tmp = *(int *)data) != 0)
+                       fp->f_flag |= FASYNC;



Home | Main Index | Thread Index | Old Index