Source-Changes-HG archive

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

[src/trunk]: src/sys/compat/netbsd32 fix the glaring errors in emulations for...



details:   https://anonhg.NetBSD.org/src/rev/c863a92d7134
branches:  trunk
changeset: 503388:c863a92d7134
user:      mrg <mrg%NetBSD.org@localhost>
date:      Mon Feb 05 06:32:55 2001 +0000

description:
fix the glaring errors in emulations for osendmsg, orecvmsg, osigvec and osigstack.

diffstat:

 sys/compat/netbsd32/netbsd32_compat_43.c |  260 +++++++++++++++++++++++-------
 1 files changed, 194 insertions(+), 66 deletions(-)

diffs (truncated from 334 to 300 lines):

diff -r efc22123e0d8 -r c863a92d7134 sys/compat/netbsd32/netbsd32_compat_43.c
--- a/sys/compat/netbsd32/netbsd32_compat_43.c  Mon Feb 05 06:28:55 2001 +0000
+++ b/sys/compat/netbsd32/netbsd32_compat_43.c  Mon Feb 05 06:32:55 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_compat_43.c,v 1.15 2001/02/02 13:06:48 mrg Exp $      */
+/*     $NetBSD: netbsd32_compat_43.c,v 1.16 2001/02/05 06:32:55 mrg Exp $      */
 
 /*
  * Copyright (c) 1998 Matthew R. Green
@@ -508,33 +508,86 @@
                syscallarg(int) flags;
        } */ *uap = v;
        struct compat_43_sys_recvmsg_args ua;
-       struct omsghdr omh;
-       struct omsghdr *omhp = &omh;
-       struct netbsd32_omsghdr *omhp32;
-       struct iovec *iovec43p;
-       struct netbsd32_iovec *iovec32p;
-       int i;
+       struct omsghdr omh, *sgsbp;
+       struct netbsd32_omsghdr omh32;
+       struct iovec iov, *sgsbp2;
+       struct netbsd32_iovec iov32, *iovec32p;
+       caddr_t sg = stackgap_init(p->p_emul);
+       int i, error, rv;
 
        NETBSD32TO64_UAP(s);
        NETBSD32TO64_UAP(flags);
 
-       SCARG(&ua, msg) = omhp;
-       omhp32 = (struct netbsd32_omsghdr *)(u_long)SCARG(uap, msg);
-       omhp->msg_name = (caddr_t)(u_long)omhp32->msg_name;
-       omhp->msg_namelen = omhp32->msg_namelen;
-       omhp->msg_iovlen = (size_t)omhp32->msg_iovlen;
-       MALLOC(omhp->msg_iov, struct iovec *, sizeof(struct iovec) * omhp->msg_iovlen, M_TEMP, M_WAITOK);
-       iovec43p = omhp->msg_iov;
-       iovec32p = (struct netbsd32_iovec *)(u_long)omhp32->msg_iov;
-       for (i = 0; i < omhp->msg_iovlen; i++, iovec43p++, iovec32p++) {
-               iovec43p->iov_base = (struct iovec *)(u_long)iovec32p->iov_base;
-               iovec43p->iov_len = (size_t)iovec32p->iov_len;
+       /*
+        * this is annoying:
+        *      - copyin the msghdr32 struct
+        *      - stackgap_alloc a msghdr struct
+        *      - convert msghdr32 to msghdr:
+        *              - stackgap_alloc enough space for iovec's
+        *              - copy in each iov32, and convert to iov
+        *              - copyout converted iov
+        *      - copyout converted msghdr
+        *      - do real syscall
+        *      - copyin the msghdr struct
+        *      - convert msghdr to msghdr32
+        *              - copyin each iov and convert to iov32
+        *              - copyout converted iov32
+        *      - copyout converted msghdr32
+        */
+       error = copyin((caddr_t)(u_long)SCARG(uap, msg), &omh32, sizeof(omh32));
+       if (error)
+               return (error);
+
+       SCARG(&ua, msg) = sgsbp = stackgap_alloc(&sg, sizeof(omh));
+       omh.msg_name = (caddr_t)(u_long)omh32.msg_name;
+       omh.msg_namelen = omh32.msg_namelen;
+       omh.msg_iovlen = (size_t)omh32.msg_iovlen;
+       omh.msg_iov = sgsbp2 = stackgap_alloc(&sg, sizeof(struct iovec) * omh.msg_iovlen);
+       iovec32p = (struct netbsd32_iovec *)(u_long)omh32.msg_iov;
+       for (i = 0; i < omh.msg_iovlen; i++, sgsbp2++, iovec32p++) {
+               error = copyin(iovec32p, &iov32, sizeof(iov32));
+               if (error)
+                       return (error);
+               iov.iov_base = (struct iovec *)(u_long)iovec32p->iov_base;
+               iov.iov_len = (size_t)iovec32p->iov_len;
+               error = copyout(&iov, sgsbp2, sizeof(iov));
+               if (error)
+                       return (error);
        }
+       omh.msg_accrights = (caddr_t)(u_long)omh32.msg_accrights;
+       omh.msg_accrightslen = omh32.msg_accrightslen;
+       error = copyout(&omh, sgsbp, sizeof(omh));
+       if (error)
+               return (error);
 
-       omhp->msg_accrights = (caddr_t)(u_long)omhp32->msg_accrights;
-       omhp->msg_accrightslen = omhp32->msg_accrightslen;
+       rv = compat_43_sys_recvmsg(p, &ua, retval);
 
-       return (compat_43_sys_recvmsg(p, &ua, retval));
+       error = copyin(sgsbp, &omh, sizeof(omh));
+       if (error)
+               return error;
+       omh32.msg_name = (netbsd32_caddr_t)(u_long)omh.msg_name;
+       omh32.msg_namelen = omh.msg_namelen;
+       omh32.msg_iovlen = (netbsd32_size_t)omh.msg_iovlen;
+       iovec32p = (struct netbsd32_iovec *)(u_long)omh32.msg_iov;
+       sgsbp2 = omh.msg_iov;
+       for (i = 0; i < omh.msg_iovlen; i++, sgsbp2++, iovec32p++) {
+               error = copyin(sgsbp2, &iov, sizeof(iov));
+               if (error)
+                       return (error);
+               iov32.iov_base = (netbsd32_iovecp_t)(u_long)iov.iov_base;
+               iov32.iov_len = (netbsd32_size_t)iov.iov_len;
+               error = copyout(&iov32, iovec32p, sizeof(iov32));
+               if (error)
+                       return (error);
+       }
+       omh32.msg_accrights = (netbsd32_caddr_t)(u_long)omh.msg_accrights;
+       omh32.msg_accrightslen = omh.msg_accrightslen;
+
+       error = copyout(&omh32, (char *)(u_long)SCARG(uap, msg), sizeof(omh32));
+       if (error)
+               return error;
+
+       return (rv);
 }
 
 int
@@ -548,34 +601,87 @@
                syscallarg(netbsd32_caddr_t) msg;
                syscallarg(int) flags;
        } */ *uap = v;
-       struct compat_43_sys_sendmsg_args ua;
-       struct omsghdr omh;
-       struct omsghdr *omhp = &omh;
-       struct netbsd32_omsghdr *omhp32;
-       struct iovec *iovec43p;
-       struct netbsd32_iovec *iovec32p;
-       int i;
+       struct compat_43_sys_recvmsg_args ua;
+       struct omsghdr omh, *sgsbp;
+       struct netbsd32_omsghdr omh32;
+       struct iovec iov, *sgsbp2;
+       struct netbsd32_iovec iov32, *iovec32p;
+       caddr_t sg = stackgap_init(p->p_emul);
+       int i, error, rv;
 
        NETBSD32TO64_UAP(s);
        NETBSD32TO64_UAP(flags);
 
-       SCARG(&ua, msg) = (caddr_t)(u_long)omhp;
-       omhp32 = (struct netbsd32_omsghdr *)(u_long)SCARG(uap, msg);
-       omhp->msg_name = (caddr_t)(u_long)omhp32->msg_name;
-       omhp->msg_namelen = omhp32->msg_namelen;
-       omhp->msg_iovlen = (size_t)omhp32->msg_iovlen;
-       MALLOC(omhp->msg_iov, struct iovec *, sizeof(struct iovec) * omhp->msg_iovlen, M_TEMP, M_WAITOK);
-       iovec43p = omhp->msg_iov;
-       iovec32p = (struct netbsd32_iovec *)(u_long)omhp32->msg_iov;
-       for (i = 0; i < omhp->msg_iovlen; i++, iovec43p++, iovec32p++) {
-               iovec43p->iov_base = (void *)(u_long)iovec32p->iov_base;
-               iovec43p->iov_len = (size_t)iovec32p->iov_len;
+       /*
+        * this is annoying:
+        *      - copyin the msghdr32 struct
+        *      - stackgap_alloc a msghdr struct
+        *      - convert msghdr32 to msghdr:
+        *              - stackgap_alloc enough space for iovec's
+        *              - copy in each iov32, and convert to iov
+        *              - copyout converted iov
+        *      - copyout converted msghdr
+        *      - do real syscall
+        *      - copyin the msghdr struct
+        *      - convert msghdr to msghdr32
+        *              - copyin each iov and convert to iov32
+        *              - copyout converted iov32
+        *      - copyout converted msghdr32
+        */
+       error = copyin((caddr_t)(u_long)SCARG(uap, msg), &omh32, sizeof(omh32));
+       if (error)
+               return (error);
+
+       SCARG(&ua, msg) = sgsbp = stackgap_alloc(&sg, sizeof(omh));
+       omh.msg_name = (caddr_t)(u_long)omh32.msg_name;
+       omh.msg_namelen = omh32.msg_namelen;
+       omh.msg_iovlen = (size_t)omh32.msg_iovlen;
+       omh.msg_iov = sgsbp2 = stackgap_alloc(&sg, sizeof(struct iovec) * omh.msg_iovlen);
+       iovec32p = (struct netbsd32_iovec *)(u_long)omh32.msg_iov;
+       for (i = 0; i < omh.msg_iovlen; i++, sgsbp2++, iovec32p++) {
+               error = copyin(iovec32p, &iov32, sizeof(iov32));
+               if (error)
+                       return (error);
+               iov.iov_base = (struct iovec *)(u_long)iovec32p->iov_base;
+               iov.iov_len = (size_t)iovec32p->iov_len;
+               error = copyout(&iov, sgsbp2, sizeof(iov));
+               if (error)
+                       return (error);
        }
+       omh.msg_accrights = (caddr_t)(u_long)omh32.msg_accrights;
+       omh.msg_accrightslen = omh32.msg_accrightslen;
+       error = copyout(&omh, sgsbp, sizeof(omh));
+       if (error)
+               return (error);
 
-       omhp->msg_accrights = (caddr_t)(u_long)omhp32->msg_accrights;
-       omhp->msg_accrightslen = omhp32->msg_accrightslen;
+       rv = compat_43_sys_sendmsg(p, &ua, retval);
 
-       return (compat_43_sys_sendmsg(p, &ua, retval));
+       error = copyin(sgsbp, &omh, sizeof(omh));
+       if (error)
+               return error;
+       omh32.msg_name = (netbsd32_caddr_t)(u_long)omh.msg_name;
+       omh32.msg_namelen = omh.msg_namelen;
+       omh32.msg_iovlen = (netbsd32_size_t)omh.msg_iovlen;
+       iovec32p = (struct netbsd32_iovec *)(u_long)omh32.msg_iov;
+       sgsbp2 = omh.msg_iov;
+       for (i = 0; i < omh.msg_iovlen; i++, sgsbp2++, iovec32p++) {
+               error = copyin(sgsbp2, &iov, sizeof(iov));
+               if (error)
+                       return (error);
+               iov32.iov_base = (netbsd32_iovecp_t)(u_long)iov.iov_base;
+               iov32.iov_len = (netbsd32_size_t)iov.iov_len;
+               error = copyout(&iov32, iovec32p, sizeof(iov32));
+               if (error)
+                       return (error);
+       }
+       omh32.msg_accrights = (netbsd32_caddr_t)(u_long)omh.msg_accrights;
+       omh32.msg_accrightslen = omh.msg_accrightslen;
+
+       error = copyout(&omh32, (char *)(u_long)SCARG(uap, msg), sizeof(omh32));
+       if (error)
+               return error;
+
+       return (rv);
 }
 
 int
@@ -654,21 +760,27 @@
                syscallarg(netbsd32_sigvecp_t) osv;
        } */ *uap = v;
        struct compat_43_sys_sigvec_args ua;
-       struct netbsd32_sigvec *sv32p;
-       struct sigvec nsv, osv;
-       int rv;
+       struct netbsd32_sigvec sv32;
+       struct sigvec sv, *sgnsvp, *sgosvp;
+       caddr_t sg = stackgap_init(p->p_emul);
+       int rv, error;
 
        NETBSD32TO64_UAP(signum);
        if (SCARG(uap, osv))
-               SCARG(&ua, osv) = &osv;
+               SCARG(&ua, osv) = sgosvp = stackgap_alloc(&sg, sizeof(sv));
        else
                SCARG(&ua, osv) = NULL;
        if (SCARG(uap, nsv)) {
-               SCARG(&ua, nsv) = &nsv;
-               sv32p = (struct netbsd32_sigvec *)(u_long)SCARG(uap, nsv);
-               nsv.sv_handler = (void *)(u_long)sv32p->sv_handler;
-               nsv.sv_mask = sv32p->sv_mask;
-               nsv.sv_flags = sv32p->sv_flags;
+               SCARG(&ua, nsv) = sgnsvp = stackgap_alloc(&sg, sizeof(sv));
+               error = copyin((caddr_t)(u_long)SCARG(uap, nsv), &sv32, sizeof(sv32));
+               if (error)
+                       return (error);
+               sv.sv_handler = (void *)(u_long)sv32.sv_handler;
+               sv.sv_mask = sv32.sv_mask;
+               sv.sv_flags = sv32.sv_flags;
+               error = copyout(&sv, sgnsvp, sizeof(sv));
+               if (error)
+                       return (error);
        } else
                SCARG(&ua, nsv) = NULL;
        rv = compat_43_sys_sigvec(p, &ua, retval);
@@ -676,10 +788,15 @@
                return (rv);
 
        if (SCARG(uap, osv)) {
-               sv32p = (struct netbsd32_sigvec *)(u_long)SCARG(uap, osv);
-               sv32p->sv_handler = (netbsd32_sigvecp_t)(u_long)osv.sv_handler;
-               sv32p->sv_mask = osv.sv_mask;
-               sv32p->sv_flags = osv.sv_flags;
+               error = copyin(sgosvp, &sv, sizeof(sv));
+               if (error)
+                       return (error);
+               sv32.sv_handler = (netbsd32_sigvecp_t)(u_long)sv.sv_handler;
+               sv32.sv_mask = sv.sv_mask;
+               sv32.sv_flags = sv.sv_flags;
+               error = copyout(&sv32, (caddr_t)(u_long)SCARG(uap, osv), sizeof(sv32));
+               if (error)
+                       return (error);
        }
 
        return (0);
@@ -726,19 +843,25 @@
                syscallarg(netbsd32_sigstackp_t) oss;
        } */ *uap = v;
        struct compat_43_sys_sigstack_args ua;
-       struct netbsd32_sigstack *ss32p;
-       struct sigstack nss, oss;
-       int rv;
+       struct netbsd32_sigstack ss32;
+       struct sigstack ss, *sgossp, *sgnssp;
+       caddr_t sg = stackgap_init(p->p_emul);
+       int error, rv;
 
        if (SCARG(uap, oss))
-               SCARG(&ua, oss) = &oss;
+               SCARG(&ua, oss) = sgossp = stackgap_alloc(&sg, sizeof(ss));
        else
                SCARG(&ua, oss) = NULL;
        if (SCARG(uap, nss)) {



Home | Main Index | Thread Index | Old Index