From 798cd0a3327980faccb444485468a9f5c0af3e38 Mon Sep 17 00:00:00 2001 From: cgd Date: Mon, 10 May 1999 05:58:44 +0000 Subject: [PATCH] start at (new) sendmsg and recvmsg. right now, the former doesn't handle control messages and the latter is just a stub. --- sys/compat/osf1/osf1_cvt.c | 34 ++++++++++++- sys/compat/osf1/osf1_cvt.h | 4 +- sys/compat/osf1/osf1_socket.c | 90 ++++++++++++++++++++++++++++++++- sys/compat/osf1/syscalls.master | 8 +-- 4 files changed, 130 insertions(+), 6 deletions(-) diff --git a/sys/compat/osf1/osf1_cvt.c b/sys/compat/osf1/osf1_cvt.c index 14b4cc2da31d..af9cab9541b8 100644 --- a/sys/compat/osf1/osf1_cvt.c +++ b/sys/compat/osf1/osf1_cvt.c @@ -1,4 +1,4 @@ -/* $NetBSD: osf1_cvt.c,v 1.5 1999/05/05 00:57:43 cgd Exp $ */ +/* $NetBSD: osf1_cvt.c,v 1.6 1999/05/10 05:58:44 cgd Exp $ */ /* * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved. @@ -307,6 +307,38 @@ const struct emul_flags_xtab osf1_wait_options_xtab[] = { { 0 } }; +int +osf1_cvt_msghdr_xopen_to_native(omh, bmh) + const struct osf1_msghdr_xopen *omh; + struct msghdr *bmh; +{ + unsigned long leftovers; + + memset(bmh, 0, sizeof bmh); + bmh->msg_name = omh->msg_name; /* XXX sockaddr translation */ + bmh->msg_namelen = omh->msg_namelen; + bmh->msg_iov = NULL; /* iovec xlation separate */ + bmh->msg_iovlen = omh->msg_iovlen; + + /* XXX we don't translate control messages (yet) */ + if (bmh->msg_control != NULL || bmh->msg_controllen != 0) +{ +printf("osf1_cvt_msghdr_xopen_to_native: control\n"); + return (EINVAL); +} + + /* translate flags */ + bmh->msg_flags = emul_flags_translate(osf1_sendrecv_msg_flags_xtab, + omh->msg_flags, &leftovers); + if (leftovers != 0) +{ +printf("osf1_cvt_msghdr_xopen_to_native: leftovers 0x%lx\n", leftovers); + return (EINVAL); +} + + return (0); +} + int osf1_cvt_pathconf_name_to_native(oname, bnamep) int oname, *bnamep; diff --git a/sys/compat/osf1/osf1_cvt.h b/sys/compat/osf1/osf1_cvt.h index 69b63e57e84b..8b581810b167 100644 --- a/sys/compat/osf1/osf1_cvt.h +++ b/sys/compat/osf1/osf1_cvt.h @@ -1,4 +1,4 @@ -/* $NetBSD: osf1_cvt.h,v 1.4 1999/05/04 02:12:15 cgd Exp $ */ +/* $NetBSD: osf1_cvt.h,v 1.5 1999/05/10 05:58:44 cgd Exp $ */ /* * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved. @@ -47,6 +47,8 @@ #define osf1_cvt_dev_to_native(dev) \ makedev(osf1_major(dev), osf1_minor(dev)) +int osf1_cvt_msghdr_xopen_to_native(const struct osf1_msghdr_xopen *omh, + struct msghdr *nmh); int osf1_cvt_pathconf_name_to_native(int oname, int *bnamep); void osf1_cvt_rusage_from_native(const struct rusage *nru, struct osf1_rusage *oru); diff --git a/sys/compat/osf1/osf1_socket.c b/sys/compat/osf1/osf1_socket.c index 11904bdea419..e4222dd801ee 100644 --- a/sys/compat/osf1/osf1_socket.c +++ b/sys/compat/osf1/osf1_socket.c @@ -1,4 +1,4 @@ -/* $NetBSD: osf1_socket.c,v 1.4 1999/05/10 01:58:37 cgd Exp $ */ +/* $NetBSD: osf1_socket.c,v 1.5 1999/05/10 05:58:44 cgd Exp $ */ /* * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved. @@ -65,12 +65,100 @@ #include #include #include +#include #include #include #include #include +int +osf1_sys_recvmsg_xopen(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + + /* XXX */ + return (EINVAL); +} + +int +osf1_sys_sendmsg_xopen(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct osf1_sys_sendmsg_xopen_args *uap = v; + struct sys_sendmsg_args a; + struct osf1_msghdr_xopen osf_msghdr; + struct osf1_iovec_xopen osf_iovec, *osf_iovec_ptr; + struct msghdr bsd_msghdr; + struct iovec bsd_iovec, *bsd_iovec_ptr; + unsigned long leftovers; + caddr_t sg; + unsigned int i; + int error; + + sg = stackgap_init(p->p_emul); + + SCARG(&a, s) = SCARG(uap, s); + + /* + * translate msghdr structure + */ + if ((error = copyin(SCARG(uap, msg), &osf_msghdr, + sizeof osf_msghdr)) != 0) + return (error); + + error = osf1_cvt_msghdr_xopen_to_native(&osf_msghdr, &bsd_msghdr); + if (error != 0) + return (error); + + if (STACKGAPLEN < (bsd_msghdr.msg_iovlen * sizeof (struct iovec) + + sizeof (struct msghdr))) +{ +printf("sendmsg space\n"); + return (EINVAL); +} + + SCARG(&a, msg) = stackgap_alloc(&sg, sizeof bsd_msghdr); + bsd_msghdr.msg_iov = stackgap_alloc(&sg, + bsd_msghdr.msg_iovlen * sizeof (struct iovec)); + + if ((error = copyout(&bsd_msghdr, (caddr_t)SCARG(&a, msg), + sizeof bsd_msghdr)) != 0) + return (error); + + osf_iovec_ptr = osf_msghdr.msg_iov; + bsd_iovec_ptr = bsd_msghdr.msg_iov; + for (i = 0; i < bsd_msghdr.msg_iovlen; i++) { + if ((error = copyin(&osf_iovec_ptr[i], &osf_iovec, + sizeof osf_iovec)) != 0) + return (error); + + bsd_iovec.iov_base = osf_iovec.iov_base; + bsd_iovec.iov_len = osf_iovec.iov_len; + + if ((error = copyout(&bsd_iovec, &bsd_iovec_ptr[i], + sizeof bsd_iovec)) != 0) + return (error); + } + + /* + * translate flags + */ + SCARG(&a, flags) = emul_flags_translate(osf1_sendrecv_msg_flags_xtab, + SCARG(uap, flags), &leftovers); + if (leftovers != 0) +{ +printf("sendmsg flags leftover: 0x%lx\n", leftovers); + return (EINVAL); +} + + return sys_sendmsg(p, &a, retval); +} + int osf1_sys_sendto(p, v, retval) struct proc *p; diff --git a/sys/compat/osf1/syscalls.master b/sys/compat/osf1/syscalls.master index adca832f5f30..f5083a1fdc75 100644 --- a/sys/compat/osf1/syscalls.master +++ b/sys/compat/osf1/syscalls.master @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.29 1999/05/10 03:33:04 cgd Exp $ + $NetBSD: syscalls.master,v 1.30 1999/05/10 05:58:44 cgd Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -77,8 +77,10 @@ 24 NOARGS { uid_t sys_getuid(void); } 25 UNIMPL exec_with_loader 26 UNIMPL ptrace -27 UNIMPL recvmsg -28 UNIMPL sendmsg +27 STD { int osf1_sys_recvmsg_xopen(int s, \ + struct osf1_msghdr_xopen *msg, int flags); } +28 STD { int osf1_sys_sendmsg_xopen(int s, \ + const struct osf1_msghdr_xopen *msg, int flags); } 29 UNIMPL recvfrom 30 UNIMPL accept 31 UNIMPL getpeername