netbsd32_compat_12.c revision 1.2 1 /* $NetBSD: netbsd32_compat_12.c,v 1.2 1998/08/29 17:01:16 mrg Exp $ */
2
3 /*
4 * Copyright (c) 1998 Matthew R. Green
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/mount.h>
34 #include <sys/mman.h>
35 #include <sys/proc.h>
36 #include <sys/stat.h>
37 #include <sys/swap.h>
38 #include <sys/syscallargs.h>
39
40 #include <compat/sparc32/sparc32.h>
41 #include <compat/sparc32/sparc32_syscallargs.h>
42
43
44 /* for use with {,fl}stat() */
45 static void
46 compat_sparc32_stat12_to_sparc32(sp12, sp32)
47 struct stat12 *sp12;
48 struct sparc32_stat12 *sp32;
49 {
50
51 sp32->st_dev = sp12->st_dev;
52 sp32->st_ino = sp12->st_ino;
53 sp32->st_mode = sp12->st_mode;
54 sp32->st_nlink = sp12->st_nlink;
55 sp32->st_uid = sp12->st_uid;
56 sp32->st_gid = sp12->st_gid;
57 sp32->st_rdev = sp12->st_rdev;
58 if (sp12->st_size < (quad_t)1 << 32)
59 sp32->st_size = sp12->st_size;
60 else
61 sp32->st_size = -2;
62 sp32->st_atimespec.tv_sec = sp12->st_atimespec.tv_sec;
63 sp32->st_atimespec.tv_nsec = sp12->st_atimespec.tv_nsec;
64 sp32->st_mtimespec.tv_sec = sp12->st_mtimespec.tv_sec;
65 sp32->st_mtimespec.tv_nsec = sp12->st_mtimespec.tv_nsec;
66 sp32->st_ctimespec.tv_sec = sp12->st_ctimespec.tv_sec;
67 sp32->st_ctimespec.tv_nsec = sp12->st_ctimespec.tv_nsec;
68 sp32->st_blocks = sp12->st_blocks;
69 sp32->st_blksize = sp12->st_blksize;
70 sp32->st_flags = sp12->st_flags;
71 sp32->st_gen = sp12->st_gen;
72 }
73
74 int
75 compat_12_compat_sparc32_msync(p, v, retval)
76 struct proc *p;
77 void *v;
78 register_t *retval;
79 {
80 struct compat_12_compat_sparc32_msync_args /* {
81 syscallarg(sparc32_caddr_t) addr;
82 syscallarg(sparc32_size_t) len;
83 } */ *uap = v;
84 struct sys___msync13_args ua;
85
86 SPARC32TOX64_UAP(addr, caddr_t);
87 SPARC32TOX_UAP(len, size_t);
88 SCARG(&ua, flags) = MS_SYNC | MS_INVALIDATE;
89 return (sys___msync13(p, &ua, retval));
90 }
91
92 int
93 compat_12_compat_sparc32_oswapon(p, v, retval)
94 struct proc *p;
95 void *v;
96 register_t *retval;
97 {
98 struct compat_12_compat_sparc32_oswapon_args /* {
99 syscallarg(const sparc32_charp) name;
100 } */ *uap = v;
101 struct sys_swapctl_args ua;
102
103 SCARG(&ua, cmd) = SWAP_ON;
104 SCARG(&ua, arg) = (void *)(u_long)SCARG(uap, name);
105 SCARG(&ua, misc) = 0; /* priority */
106 return (sys_swapctl(p, &ua, retval));
107 }
108
109 int
110 compat_12_compat_sparc32_stat12(p, v, retval)
111 struct proc *p;
112 void *v;
113 register_t *retval;
114 {
115 struct compat_12_compat_sparc32_stat12_args /* {
116 syscallarg(const sparc32_charp) path;
117 syscallarg(sparc32_stat12p_t) ub;
118 } */ *uap = v;
119 struct sparc32_stat12 *sp32;
120 struct stat12 sb12;
121 struct stat12 *sp12 = &sb12;
122 struct compat_12_sys_stat_args ua;
123 caddr_t sg;
124 int rv;
125
126 SPARC32TOP_UAP(path, const char);
127 SCARG(&ua, ub) = &sb12;
128 sg = stackgap_init(p->p_emul);
129 SPARC32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
130
131 rv = compat_12_sys_stat(p, &ua, retval);
132
133 sp32 = (struct sparc32_stat12 *)(u_long)SCARG(uap, ub);
134 compat_sparc32_stat12_to_sparc32(sp12, sp32);
135
136 return (rv);
137 }
138
139 int
140 compat_12_compat_sparc32_fstat12(p, v, retval)
141 struct proc *p;
142 void *v;
143 register_t *retval;
144 {
145 struct compat_12_compat_sparc32_fstat12_args /* {
146 syscallarg(int) fd;
147 syscallarg(sparc32_stat12p_t) sb;
148 } */ *uap = v;
149 struct sparc32_stat12 *sp32;
150 struct stat12 sb12;
151 struct stat12 *sp12 = &sb12;
152 struct compat_12_sys_fstat_args ua;
153 int rv;
154
155 SPARC32TO64_UAP(fd);
156 SCARG(&ua, sb) = &sb12;
157 rv = compat_12_sys_fstat(p, &ua, retval);
158
159 sp32 = (struct sparc32_stat12 *)(u_long)SCARG(uap, sb);
160 compat_sparc32_stat12_to_sparc32(sp12, sp32);
161
162 return (rv);
163 }
164
165 int
166 compat_12_compat_sparc32_lstat12(p, v, retval)
167 struct proc *p;
168 void *v;
169 register_t *retval;
170 {
171 struct compat_12_compat_sparc32_lstat12_args /* {
172 syscallarg(const sparc32_charp) path;
173 syscallarg(sparc32_stat12p_t) ub;
174 } */ *uap = v;
175 struct sparc32_stat12 *sp32;
176 struct stat12 sb12;
177 struct stat12 *sp12 = &sb12;
178 struct compat_12_sys_lstat_args ua;
179 caddr_t sg;
180 int rv;
181
182 SPARC32TOP_UAP(path, const char);
183 SCARG(&ua, ub) = &sb12;
184 sg = stackgap_init(p->p_emul);
185 SPARC32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
186
187 rv = compat_12_sys_lstat(p, &ua, retval);
188
189 sp32 = (struct sparc32_stat12 *)(u_long)SCARG(uap, ub);
190 compat_sparc32_stat12_to_sparc32(sp12, sp32);
191
192 return (rv);
193 }
194
195 int
196 compat_12_compat_sparc32_getdirentries(p, v, retval)
197 struct proc *p;
198 void *v;
199 register_t *retval;
200 {
201 struct compat_12_compat_sparc32_getdirentries_args /* {
202 syscallarg(int) fd;
203 syscallarg(sparc32_charp) buf;
204 syscallarg(u_int) count;
205 syscallarg(sparc32_longp) basep;
206 } */ *uap = v;
207 struct compat_12_sys_getdirentries_args ua;
208
209 SPARC32TO64_UAP(fd);
210 SPARC32TOP_UAP(buf, char);
211 SPARC32TO64_UAP(count);
212 SPARC32TOP_UAP(basep, long);
213
214 return (compat_12_sys_getdirentries(p, &ua, retval));
215 }
216