No empty .Rs/.Re
[netbsd-mini2440.git] / sys / compat / osf1 / osf1_generic.c
blobc3be0bd8c2ce63c7610902538c9c12f6f32270d3
1 /* $NetBSD: osf1_generic.c,v 1.15 2009/04/01 03:06:06 dogcow Exp $ */
3 /*
4 * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Christopher G. Demetriou
17 * for the NetBSD Project.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1994, 1995 Carnegie-Mellon University.
35 * All rights reserved.
37 * Author: Chris G. Demetriou
39 * Permission to use, copy, modify and distribute this software and
40 * its documentation is hereby granted, provided that both the copyright
41 * notice and this permission notice appear in all copies of the
42 * software, derivative works or modified versions, and any portions
43 * thereof, and that both notices appear in supporting documentation.
45 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
46 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
47 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
49 * Carnegie Mellon requests users of this software to return to
51 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
52 * School of Computer Science
53 * Carnegie Mellon University
54 * Pittsburgh PA 15213-3890
56 * any improvements or extensions that they make and grant Carnegie the
57 * rights to redistribute these changes.
60 #include <sys/cdefs.h>
61 __KERNEL_RCSID(0, "$NetBSD: osf1_generic.c,v 1.15 2009/04/01 03:06:06 dogcow Exp $");
63 #include <sys/param.h>
64 #include <sys/systm.h>
65 #include <sys/namei.h>
66 #include <sys/proc.h>
67 #include <sys/file.h>
68 #include <sys/stat.h>
69 #include <sys/malloc.h>
70 #include <sys/mman.h>
71 #include <sys/mount.h>
72 #include <sys/select.h>
73 #include <sys/syscallargs.h>
74 #include <sys/exec.h>
76 #include <compat/osf1/osf1.h>
77 #include <compat/osf1/osf1_syscallargs.h>
78 #include <compat/osf1/osf1_cvt.h>
81 * The structures end up being the same... but we can't be sure that
82 * the other word of our iov_len is zero!
85 #if __GNUC_PREREQ__(3, 0)
86 __attribute ((noinline))
87 #endif
88 static int
89 osf1_get_iov(struct osf1_iovec *uiov, unsigned int iovcnt, struct iovec **iovp)
91 struct iovec *iov = *iovp;
92 struct osf1_iovec osf1_iov[UIO_SMALLIOV];
93 int i, j, n, error;
95 if (iovcnt > IOV_MAX)
96 return EINVAL;
98 if (iovcnt > UIO_SMALLIOV) {
99 iov = malloc(iovcnt * sizeof *iov, M_IOV, M_WAITOK);
100 *iovp = iov;
101 /* Caller must free - even if we return an error */
104 for (i = 0; i < iovcnt; uiov += UIO_SMALLIOV, i += UIO_SMALLIOV) {
105 n = iovcnt - i;
106 if (n > UIO_SMALLIOV)
107 n = UIO_SMALLIOV;
108 error = copyin(uiov, osf1_iov, n * sizeof osf1_iov[0]);
109 if (error != 0)
110 return error;
112 for (j = 0; j < n; iov++, j++) {
113 iov->iov_base = osf1_iov[j].iov_base;
114 iov->iov_len = osf1_iov[j].iov_len;
118 return 0;
122 osf1_sys_readv(struct lwp *l, const struct osf1_sys_readv_args *uap, register_t *retval)
124 struct iovec aiov[UIO_SMALLIOV], *niov = aiov;
125 int error;
127 error = osf1_get_iov(SCARG(uap, iovp), SCARG(uap, iovcnt), &niov);
129 if (error == 0) {
130 error = do_filereadv(SCARG(uap, fd), niov,
131 SCARG(uap, iovcnt), NULL,
132 FOF_UPDATE_OFFSET | FOF_IOV_SYSSPACE, retval);
135 if (niov != aiov)
136 free(niov, M_IOV);
138 return error;
142 osf1_sys_writev(struct lwp *l, const struct osf1_sys_writev_args *uap, register_t *retval)
144 struct iovec aiov[UIO_SMALLIOV], *niov = aiov;
145 int error;
147 error = osf1_get_iov(SCARG(uap, iovp), SCARG(uap, iovcnt), &niov);
149 if (error == 0) {
150 error = do_filewritev(SCARG(uap, fd), niov,
151 SCARG(uap, iovcnt), NULL,
152 FOF_UPDATE_OFFSET | FOF_IOV_SYSSPACE, retval);
155 if (niov != aiov)
156 free(niov, M_IOV);
158 return error;
162 osf1_sys_select(struct lwp *l, const struct osf1_sys_select_args *uap,
163 register_t *retval)
165 struct osf1_timeval otv;
166 struct timespec ats, *ts = NULL;
167 int error;
169 if (SCARG(uap, tv)) {
170 /* get the OSF/1 timeval argument */
171 error = copyin(SCARG(uap, tv), &otv, sizeof otv);
172 if (error != 0)
173 return error;
175 ats.tv_sec = otv.tv_sec;
176 ats.tv_nsec = otv.tv_usec * 1000;
177 ts = &ats;
180 return selcommon(retval, SCARG(uap, nd), SCARG(uap, in),
181 SCARG(uap, ou), SCARG(uap, ex), ts, NULL);