netbsd32_conv.h revision 1.47 1 1.47 rin /* $NetBSD: netbsd32_conv.h,v 1.47 2023/07/29 12:38:25 rin Exp $ */
2 1.1 mrg
3 1.1 mrg /*
4 1.1 mrg * Copyright (c) 1998, 2001 Matthew R. Green
5 1.1 mrg * All rights reserved.
6 1.1 mrg *
7 1.1 mrg * Redistribution and use in source and binary forms, with or without
8 1.1 mrg * modification, are permitted provided that the following conditions
9 1.1 mrg * are met:
10 1.1 mrg * 1. Redistributions of source code must retain the above copyright
11 1.1 mrg * notice, this list of conditions and the following disclaimer.
12 1.1 mrg * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 mrg * notice, this list of conditions and the following disclaimer in the
14 1.1 mrg * documentation and/or other materials provided with the distribution.
15 1.1 mrg *
16 1.1 mrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 mrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 mrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 mrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 mrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 mrg * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 mrg * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 mrg * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 mrg * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 mrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 mrg * SUCH DAMAGE.
27 1.1 mrg */
28 1.1 mrg
29 1.1 mrg #ifndef _COMPAT_NETBSD32_NETBSD32_CONV_H_
30 1.1 mrg #define _COMPAT_NETBSD32_NETBSD32_CONV_H_
31 1.1 mrg
32 1.1 mrg #include <sys/param.h>
33 1.1 mrg #include <sys/systm.h>
34 1.1 mrg #include <sys/kernel.h>
35 1.30 mrg #include <sys/dirent.h>
36 1.1 mrg #include <sys/ipc.h>
37 1.1 mrg #include <sys/msg.h>
38 1.1 mrg #define msg __msg /* Don't ask me! */
39 1.1 mrg #include <sys/sem.h>
40 1.1 mrg #include <sys/shm.h>
41 1.1 mrg #include <sys/socket.h>
42 1.1 mrg #include <sys/stat.h>
43 1.1 mrg #include <sys/time.h>
44 1.1 mrg #include <sys/timex.h>
45 1.11 cube #include <sys/event.h>
46 1.1 mrg
47 1.10 christos #include <compat/sys/dirent.h>
48 1.10 christos
49 1.26 bouyer #include <prop/plistref.h>
50 1.26 bouyer
51 1.36 mlelstv #include <nv.h>
52 1.36 mlelstv
53 1.1 mrg #include <compat/netbsd32/netbsd32.h>
54 1.1 mrg
55 1.1 mrg /* converters for structures that we need */
56 1.14 perry static __inline void
57 1.21 christos netbsd32_from_timeval50(const struct timeval *tv,
58 1.21 christos struct netbsd32_timeval50 *tv32)
59 1.1 mrg {
60 1.1 mrg
61 1.46 riastrad memset(tv32, 0, sizeof(*tv32));
62 1.42 rin tv32->tv_sec = (netbsd32_time50_t)tv->tv_sec;
63 1.1 mrg tv32->tv_usec = (netbsd32_long)tv->tv_usec;
64 1.1 mrg }
65 1.1 mrg
66 1.14 perry static __inline void
67 1.21 christos netbsd32_from_timeval(const struct timeval *tv,
68 1.21 christos struct netbsd32_timeval *tv32)
69 1.1 mrg {
70 1.1 mrg
71 1.46 riastrad memset(tv32, 0, sizeof(*tv32));
72 1.31 rin tv32->tv_sec = (netbsd32_time_t)tv->tv_sec;
73 1.31 rin tv32->tv_usec = tv->tv_usec;
74 1.21 christos }
75 1.21 christos
76 1.21 christos static __inline void
77 1.21 christos netbsd32_to_timeval50(const struct netbsd32_timeval50 *tv32,
78 1.21 christos struct timeval *tv)
79 1.21 christos {
80 1.21 christos
81 1.46 riastrad memset(tv, 0, sizeof(*tv));
82 1.21 christos tv->tv_sec = (time_t)tv32->tv_sec;
83 1.31 rin tv->tv_usec = tv32->tv_usec;
84 1.21 christos }
85 1.21 christos
86 1.21 christos static __inline void
87 1.21 christos netbsd32_to_timeval(const struct netbsd32_timeval *tv32,
88 1.21 christos struct timeval *tv)
89 1.21 christos {
90 1.21 christos
91 1.46 riastrad memset(tv, 0, sizeof(*tv));
92 1.21 christos tv->tv_sec = (time_t)tv32->tv_sec;
93 1.31 rin tv->tv_usec = tv32->tv_usec;
94 1.21 christos }
95 1.21 christos
96 1.21 christos static __inline void
97 1.21 christos netbsd32_from_itimerval50(const struct itimerval *itv,
98 1.21 christos struct netbsd32_itimerval50 *itv32)
99 1.21 christos {
100 1.21 christos
101 1.46 riastrad memset(itv32, 0, sizeof(*itv32));
102 1.21 christos netbsd32_from_timeval50(&itv->it_interval,
103 1.21 christos &itv32->it_interval);
104 1.21 christos netbsd32_from_timeval50(&itv->it_value,
105 1.21 christos &itv32->it_value);
106 1.1 mrg }
107 1.1 mrg
108 1.14 perry static __inline void
109 1.21 christos netbsd32_from_itimerval(const struct itimerval *itv,
110 1.21 christos struct netbsd32_itimerval *itv32)
111 1.1 mrg {
112 1.1 mrg
113 1.46 riastrad memset(itv32, 0, sizeof(*itv32));
114 1.5 perry netbsd32_from_timeval(&itv->it_interval,
115 1.1 mrg &itv32->it_interval);
116 1.5 perry netbsd32_from_timeval(&itv->it_value,
117 1.1 mrg &itv32->it_value);
118 1.1 mrg }
119 1.1 mrg
120 1.14 perry static __inline void
121 1.21 christos netbsd32_to_itimerval50(const struct netbsd32_itimerval50 *itv32,
122 1.21 christos struct itimerval *itv)
123 1.21 christos {
124 1.21 christos
125 1.46 riastrad memset(itv, 0, sizeof(*itv));
126 1.21 christos netbsd32_to_timeval50(&itv32->it_interval, &itv->it_interval);
127 1.21 christos netbsd32_to_timeval50(&itv32->it_value, &itv->it_value);
128 1.21 christos }
129 1.21 christos
130 1.21 christos static __inline void
131 1.21 christos netbsd32_to_itimerval(const struct netbsd32_itimerval *itv32,
132 1.21 christos struct itimerval *itv)
133 1.1 mrg {
134 1.1 mrg
135 1.46 riastrad memset(itv, 0, sizeof(*itv));
136 1.1 mrg netbsd32_to_timeval(&itv32->it_interval, &itv->it_interval);
137 1.1 mrg netbsd32_to_timeval(&itv32->it_value, &itv->it_value);
138 1.1 mrg }
139 1.1 mrg
140 1.14 perry static __inline void
141 1.21 christos netbsd32_to_timespec50(const struct netbsd32_timespec50 *s32p,
142 1.21 christos struct timespec *p)
143 1.1 mrg {
144 1.1 mrg
145 1.46 riastrad memset(p, 0, sizeof(*p));
146 1.1 mrg p->tv_sec = (time_t)s32p->tv_sec;
147 1.1 mrg p->tv_nsec = (long)s32p->tv_nsec;
148 1.1 mrg }
149 1.1 mrg
150 1.14 perry static __inline void
151 1.21 christos netbsd32_to_timespec(const struct netbsd32_timespec *s32p,
152 1.21 christos struct timespec *p)
153 1.21 christos {
154 1.21 christos
155 1.46 riastrad memset(p, 0, sizeof(*p));
156 1.21 christos p->tv_sec = (time_t)s32p->tv_sec;
157 1.21 christos p->tv_nsec = (long)s32p->tv_nsec;
158 1.21 christos }
159 1.21 christos
160 1.21 christos static __inline void
161 1.21 christos netbsd32_from_timespec50(const struct timespec *p,
162 1.21 christos struct netbsd32_timespec50 *s32p)
163 1.21 christos {
164 1.21 christos
165 1.46 riastrad memset(s32p, 0, sizeof(*s32p));
166 1.42 rin s32p->tv_sec = (netbsd32_time50_t)p->tv_sec;
167 1.21 christos s32p->tv_nsec = (netbsd32_long)p->tv_nsec;
168 1.21 christos }
169 1.21 christos
170 1.21 christos static __inline void
171 1.21 christos netbsd32_from_timespec(const struct timespec *p,
172 1.21 christos struct netbsd32_timespec *s32p)
173 1.1 mrg {
174 1.1 mrg
175 1.46 riastrad memset(s32p, 0, sizeof(*s32p));
176 1.31 rin s32p->tv_sec = (netbsd32_time_t)p->tv_sec;
177 1.1 mrg s32p->tv_nsec = (netbsd32_long)p->tv_nsec;
178 1.1 mrg }
179 1.1 mrg
180 1.14 perry static __inline void
181 1.21 christos netbsd32_from_rusage(const struct rusage *rup,
182 1.21 christos struct netbsd32_rusage *ru32p)
183 1.1 mrg {
184 1.1 mrg
185 1.46 riastrad memset(ru32p, 0, sizeof(*ru32p));
186 1.1 mrg netbsd32_from_timeval(&rup->ru_utime, &ru32p->ru_utime);
187 1.1 mrg netbsd32_from_timeval(&rup->ru_stime, &ru32p->ru_stime);
188 1.1 mrg #define C(var) ru32p->var = (netbsd32_long)rup->var
189 1.1 mrg C(ru_maxrss);
190 1.1 mrg C(ru_ixrss);
191 1.1 mrg C(ru_idrss);
192 1.1 mrg C(ru_isrss);
193 1.1 mrg C(ru_minflt);
194 1.1 mrg C(ru_majflt);
195 1.1 mrg C(ru_nswap);
196 1.1 mrg C(ru_inblock);
197 1.1 mrg C(ru_oublock);
198 1.1 mrg C(ru_msgsnd);
199 1.1 mrg C(ru_msgrcv);
200 1.1 mrg C(ru_nsignals);
201 1.1 mrg C(ru_nvcsw);
202 1.1 mrg C(ru_nivcsw);
203 1.1 mrg #undef C
204 1.1 mrg }
205 1.1 mrg
206 1.14 perry static __inline void
207 1.21 christos netbsd32_to_rusage(const struct netbsd32_rusage *ru32p,
208 1.21 christos struct rusage *rup)
209 1.1 mrg {
210 1.1 mrg
211 1.46 riastrad memset(rup, 0, sizeof(*rup));
212 1.1 mrg netbsd32_to_timeval(&ru32p->ru_utime, &rup->ru_utime);
213 1.1 mrg netbsd32_to_timeval(&ru32p->ru_stime, &rup->ru_stime);
214 1.1 mrg #define C(var) rup->var = (long)ru32p->var
215 1.1 mrg C(ru_maxrss);
216 1.1 mrg C(ru_ixrss);
217 1.1 mrg C(ru_idrss);
218 1.1 mrg C(ru_isrss);
219 1.1 mrg C(ru_minflt);
220 1.1 mrg C(ru_majflt);
221 1.1 mrg C(ru_nswap);
222 1.1 mrg C(ru_inblock);
223 1.1 mrg C(ru_oublock);
224 1.1 mrg C(ru_msgsnd);
225 1.1 mrg C(ru_msgrcv);
226 1.1 mrg C(ru_nsignals);
227 1.1 mrg C(ru_nvcsw);
228 1.1 mrg C(ru_nivcsw);
229 1.1 mrg #undef C
230 1.1 mrg }
231 1.1 mrg
232 1.21 christos static __inline void
233 1.21 christos netbsd32_from_rusage50(const struct rusage *rup,
234 1.21 christos struct netbsd32_rusage50 *ru32p)
235 1.21 christos {
236 1.21 christos
237 1.46 riastrad memset(ru32p, 0, sizeof(*ru32p));
238 1.21 christos netbsd32_from_timeval50(&rup->ru_utime, &ru32p->ru_utime);
239 1.21 christos netbsd32_from_timeval50(&rup->ru_stime, &ru32p->ru_stime);
240 1.21 christos #define C(var) ru32p->var = (netbsd32_long)rup->var
241 1.21 christos C(ru_maxrss);
242 1.21 christos C(ru_ixrss);
243 1.21 christos C(ru_idrss);
244 1.21 christos C(ru_isrss);
245 1.21 christos C(ru_minflt);
246 1.21 christos C(ru_majflt);
247 1.21 christos C(ru_nswap);
248 1.21 christos C(ru_inblock);
249 1.21 christos C(ru_oublock);
250 1.21 christos C(ru_msgsnd);
251 1.21 christos C(ru_msgrcv);
252 1.21 christos C(ru_nsignals);
253 1.21 christos C(ru_nvcsw);
254 1.21 christos C(ru_nivcsw);
255 1.21 christos #undef C
256 1.21 christos }
257 1.21 christos
258 1.14 perry static __inline int
259 1.21 christos netbsd32_to_iovecin(const struct netbsd32_iovec *iov32p, struct iovec *iovp,
260 1.21 christos int len)
261 1.1 mrg {
262 1.1 mrg int i, error=0;
263 1.43 simonb uint32_t iov_base;
264 1.45 simonb uint32_t iov_len, total_iov_len;
265 1.45 simonb
266 1.5 perry /*
267 1.1 mrg * We could allocate an iov32p, do a copyin, and translate
268 1.1 mrg * each field and then free it all up, or we could copyin
269 1.1 mrg * each field separately. I'm doing the latter to reduce
270 1.1 mrg * the number of MALLOC()s.
271 1.1 mrg */
272 1.46 riastrad memset(iovp, 0, sizeof(*iovp));
273 1.45 simonb total_iov_len = 0;
274 1.1 mrg for (i = 0; i < len; i++, iovp++, iov32p++) {
275 1.7 cube if ((error = copyin(&iov32p->iov_base, &iov_base, sizeof(iov_base))))
276 1.44 simonb return error;
277 1.7 cube if ((error = copyin(&iov32p->iov_len, &iov_len, sizeof(iov_len))))
278 1.44 simonb return error;
279 1.1 mrg iovp->iov_base = (void *)(u_long)iov_base;
280 1.1 mrg iovp->iov_len = (size_t)iov_len;
281 1.45 simonb
282 1.45 simonb /*
283 1.45 simonb * System calls return ssize_t because -1 is returned
284 1.45 simonb * on error. Therefore we must restrict the length to
285 1.45 simonb * SSIZE_MAX (NETBSD32_SSIZE_MAX with compat32) to
286 1.45 simonb * avoid garbage return values.
287 1.45 simonb */
288 1.45 simonb total_iov_len += iov_len;
289 1.45 simonb if (iov_len > NETBSD32_SSIZE_MAX ||
290 1.45 simonb total_iov_len > NETBSD32_SSIZE_MAX) {
291 1.45 simonb return EINVAL;
292 1.45 simonb break;
293 1.45 simonb }
294 1.1 mrg }
295 1.1 mrg return error;
296 1.1 mrg }
297 1.1 mrg
298 1.1 mrg /* msg_iov must be done separately */
299 1.14 perry static __inline void
300 1.21 christos netbsd32_to_msghdr(const struct netbsd32_msghdr *mhp32, struct msghdr *mhp)
301 1.1 mrg {
302 1.1 mrg
303 1.46 riastrad memset(mhp, 0, sizeof(*mhp));
304 1.16 dsl mhp->msg_name = NETBSD32PTR64(mhp32->msg_name);
305 1.1 mrg mhp->msg_namelen = mhp32->msg_namelen;
306 1.1 mrg mhp->msg_iovlen = (size_t)mhp32->msg_iovlen;
307 1.16 dsl mhp->msg_control = NETBSD32PTR64(mhp32->msg_control);
308 1.1 mrg mhp->msg_controllen = mhp32->msg_controllen;
309 1.1 mrg mhp->msg_flags = mhp32->msg_flags;
310 1.1 mrg }
311 1.1 mrg
312 1.1 mrg /* msg_iov must be done separately */
313 1.14 perry static __inline void
314 1.21 christos netbsd32_from_msghdr(struct netbsd32_msghdr *mhp32, const struct msghdr *mhp)
315 1.1 mrg {
316 1.1 mrg
317 1.46 riastrad memset(mhp32, 0, sizeof(*mhp32));
318 1.33 martin NETBSD32PTR32(mhp32->msg_name, mhp->msg_name);
319 1.33 martin mhp32->msg_namelen = mhp->msg_namelen;
320 1.33 martin mhp32->msg_iovlen = mhp->msg_iovlen;
321 1.33 martin NETBSD32PTR32(mhp32->msg_control, mhp->msg_control);
322 1.1 mrg mhp32->msg_controllen = mhp->msg_controllen;
323 1.1 mrg mhp32->msg_flags = mhp->msg_flags;
324 1.1 mrg }
325 1.1 mrg
326 1.14 perry static __inline void
327 1.35 christos netbsd32_to_mmsghdr(const struct netbsd32_mmsghdr *mmsg32,
328 1.35 christos struct mmsghdr *mmsg)
329 1.35 christos {
330 1.46 riastrad
331 1.46 riastrad memset(mmsg, 0, sizeof(*mmsg));
332 1.46 riastrad netbsd32_to_msghdr(&mmsg32->msg_hdr, &mmsg->msg_hdr);
333 1.46 riastrad mmsg->msg_len = mmsg32->msg_len;
334 1.35 christos }
335 1.35 christos
336 1.35 christos static __inline void
337 1.35 christos netbsd32_from_mmsghdr(struct netbsd32_mmsghdr *mmsg32,
338 1.35 christos const struct mmsghdr *mmsg)
339 1.35 christos {
340 1.46 riastrad
341 1.46 riastrad memset(mmsg32, 0, sizeof(*mmsg32));
342 1.46 riastrad netbsd32_from_msghdr(&mmsg32->msg_hdr, &mmsg->msg_hdr);
343 1.46 riastrad mmsg32->msg_len = mmsg->msg_len;
344 1.35 christos }
345 1.35 christos
346 1.35 christos static __inline void
347 1.39 christos netbsd32_from_statvfs90(const struct statvfs *sbp, struct netbsd32_statvfs90 *sb32p)
348 1.39 christos {
349 1.46 riastrad
350 1.46 riastrad memset(sb32p, 0, sizeof(*sb32p));
351 1.39 christos sb32p->f_flag = sbp->f_flag;
352 1.39 christos sb32p->f_bsize = (netbsd32_u_long)sbp->f_bsize;
353 1.39 christos sb32p->f_frsize = (netbsd32_u_long)sbp->f_frsize;
354 1.39 christos sb32p->f_iosize = (netbsd32_u_long)sbp->f_iosize;
355 1.39 christos sb32p->f_blocks = sbp->f_blocks;
356 1.39 christos sb32p->f_bfree = sbp->f_bfree;
357 1.39 christos sb32p->f_bavail = sbp->f_bavail;
358 1.39 christos sb32p->f_bresvd = sbp->f_bresvd;
359 1.39 christos sb32p->f_files = sbp->f_files;
360 1.39 christos sb32p->f_ffree = sbp->f_ffree;
361 1.39 christos sb32p->f_favail = sbp->f_favail;
362 1.39 christos sb32p->f_fresvd = sbp->f_fresvd;
363 1.39 christos sb32p->f_syncreads = sbp->f_syncreads;
364 1.39 christos sb32p->f_syncwrites = sbp->f_syncwrites;
365 1.39 christos sb32p->f_asyncreads = sbp->f_asyncreads;
366 1.39 christos sb32p->f_asyncwrites = sbp->f_asyncwrites;
367 1.39 christos sb32p->f_fsidx = sbp->f_fsidx;
368 1.39 christos sb32p->f_fsid = (netbsd32_u_long)sbp->f_fsid;
369 1.39 christos sb32p->f_namemax = (netbsd32_u_long)sbp->f_namemax;
370 1.39 christos sb32p->f_owner = sbp->f_owner;
371 1.39 christos sb32p->f_spare[0] = 0;
372 1.39 christos sb32p->f_spare[1] = 0;
373 1.39 christos sb32p->f_spare[2] = 0;
374 1.39 christos sb32p->f_spare[3] = 0;
375 1.39 christos #if 1
376 1.39 christos /* May as well do the whole batch in one go */
377 1.39 christos memcpy(sb32p->f_fstypename, sbp->f_fstypename,
378 1.39 christos sizeof(sb32p->f_fstypename) + sizeof(sb32p->f_mntonname) +
379 1.39 christos sizeof(sb32p->f_mntfromname));
380 1.39 christos #else
381 1.39 christos /* If we want to be careful */
382 1.39 christos memcpy(sb32p->f_fstypename, sbp->f_fstypename, sizeof(sb32p->f_fstypename));
383 1.39 christos memcpy(sb32p->f_mntonname, sbp->f_mntonname, sizeof(sb32p->f_mntonname));
384 1.39 christos memcpy(sb32p->f_mntfromname, sbp->f_mntfromname, sizeof(sb32p->f_mntfromname));
385 1.39 christos #endif
386 1.39 christos }
387 1.39 christos
388 1.39 christos static __inline void
389 1.21 christos netbsd32_from_statvfs(const struct statvfs *sbp, struct netbsd32_statvfs *sb32p)
390 1.1 mrg {
391 1.46 riastrad
392 1.46 riastrad memset(sb32p, 0, sizeof(*sb32p));
393 1.4 cube sb32p->f_flag = sbp->f_flag;
394 1.4 cube sb32p->f_bsize = (netbsd32_u_long)sbp->f_bsize;
395 1.4 cube sb32p->f_frsize = (netbsd32_u_long)sbp->f_frsize;
396 1.4 cube sb32p->f_iosize = (netbsd32_u_long)sbp->f_iosize;
397 1.4 cube sb32p->f_blocks = sbp->f_blocks;
398 1.4 cube sb32p->f_bfree = sbp->f_bfree;
399 1.4 cube sb32p->f_bavail = sbp->f_bavail;
400 1.4 cube sb32p->f_bresvd = sbp->f_bresvd;
401 1.4 cube sb32p->f_files = sbp->f_files;
402 1.4 cube sb32p->f_ffree = sbp->f_ffree;
403 1.4 cube sb32p->f_favail = sbp->f_favail;
404 1.4 cube sb32p->f_fresvd = sbp->f_fresvd;
405 1.4 cube sb32p->f_syncreads = sbp->f_syncreads;
406 1.4 cube sb32p->f_syncwrites = sbp->f_syncwrites;
407 1.4 cube sb32p->f_asyncreads = sbp->f_asyncreads;
408 1.4 cube sb32p->f_asyncwrites = sbp->f_asyncwrites;
409 1.4 cube sb32p->f_fsidx = sbp->f_fsidx;
410 1.4 cube sb32p->f_fsid = (netbsd32_u_long)sbp->f_fsid;
411 1.4 cube sb32p->f_namemax = (netbsd32_u_long)sbp->f_namemax;
412 1.1 mrg sb32p->f_owner = sbp->f_owner;
413 1.1 mrg sb32p->f_spare[0] = 0;
414 1.1 mrg sb32p->f_spare[1] = 0;
415 1.1 mrg sb32p->f_spare[2] = 0;
416 1.1 mrg sb32p->f_spare[3] = 0;
417 1.1 mrg #if 1
418 1.1 mrg /* May as well do the whole batch in one go */
419 1.4 cube memcpy(sb32p->f_fstypename, sbp->f_fstypename,
420 1.4 cube sizeof(sb32p->f_fstypename) + sizeof(sb32p->f_mntonname) +
421 1.39 christos sizeof(sb32p->f_mntfromname) + sizeof(sb32p->f_mntfromlabel));
422 1.1 mrg #else
423 1.1 mrg /* If we want to be careful */
424 1.4 cube memcpy(sb32p->f_fstypename, sbp->f_fstypename, sizeof(sb32p->f_fstypename));
425 1.4 cube memcpy(sb32p->f_mntonname, sbp->f_mntonname, sizeof(sb32p->f_mntonname));
426 1.4 cube memcpy(sb32p->f_mntfromname, sbp->f_mntfromname, sizeof(sb32p->f_mntfromname));
427 1.39 christos memcpy(sb32p->f_mntfromlabel, sbp->f_mntfromlabel, sizeof(sb32p->f_mntfromlabel));
428 1.1 mrg #endif
429 1.1 mrg }
430 1.1 mrg
431 1.14 perry static __inline void
432 1.21 christos netbsd32_from_timex(const struct timex *txp, struct netbsd32_timex *tx32p)
433 1.1 mrg {
434 1.1 mrg
435 1.46 riastrad memset(tx32p, 0, sizeof(*tx32p));
436 1.1 mrg tx32p->modes = txp->modes;
437 1.1 mrg tx32p->offset = (netbsd32_long)txp->offset;
438 1.1 mrg tx32p->freq = (netbsd32_long)txp->freq;
439 1.1 mrg tx32p->maxerror = (netbsd32_long)txp->maxerror;
440 1.1 mrg tx32p->esterror = (netbsd32_long)txp->esterror;
441 1.1 mrg tx32p->status = txp->status;
442 1.1 mrg tx32p->constant = (netbsd32_long)txp->constant;
443 1.1 mrg tx32p->precision = (netbsd32_long)txp->precision;
444 1.1 mrg tx32p->tolerance = (netbsd32_long)txp->tolerance;
445 1.1 mrg tx32p->ppsfreq = (netbsd32_long)txp->ppsfreq;
446 1.1 mrg tx32p->jitter = (netbsd32_long)txp->jitter;
447 1.1 mrg tx32p->shift = txp->shift;
448 1.1 mrg tx32p->stabil = (netbsd32_long)txp->stabil;
449 1.1 mrg tx32p->jitcnt = (netbsd32_long)txp->jitcnt;
450 1.1 mrg tx32p->calcnt = (netbsd32_long)txp->calcnt;
451 1.1 mrg tx32p->errcnt = (netbsd32_long)txp->errcnt;
452 1.1 mrg tx32p->stbcnt = (netbsd32_long)txp->stbcnt;
453 1.1 mrg }
454 1.1 mrg
455 1.14 perry static __inline void
456 1.21 christos netbsd32_to_timex(const struct netbsd32_timex *tx32p, struct timex *txp)
457 1.1 mrg {
458 1.1 mrg
459 1.46 riastrad memset(txp, 0, sizeof(*txp));
460 1.1 mrg txp->modes = tx32p->modes;
461 1.1 mrg txp->offset = (long)tx32p->offset;
462 1.1 mrg txp->freq = (long)tx32p->freq;
463 1.1 mrg txp->maxerror = (long)tx32p->maxerror;
464 1.1 mrg txp->esterror = (long)tx32p->esterror;
465 1.1 mrg txp->status = tx32p->status;
466 1.1 mrg txp->constant = (long)tx32p->constant;
467 1.1 mrg txp->precision = (long)tx32p->precision;
468 1.1 mrg txp->tolerance = (long)tx32p->tolerance;
469 1.1 mrg txp->ppsfreq = (long)tx32p->ppsfreq;
470 1.1 mrg txp->jitter = (long)tx32p->jitter;
471 1.1 mrg txp->shift = tx32p->shift;
472 1.1 mrg txp->stabil = (long)tx32p->stabil;
473 1.1 mrg txp->jitcnt = (long)tx32p->jitcnt;
474 1.1 mrg txp->calcnt = (long)tx32p->calcnt;
475 1.1 mrg txp->errcnt = (long)tx32p->errcnt;
476 1.1 mrg txp->stbcnt = (long)tx32p->stbcnt;
477 1.1 mrg }
478 1.1 mrg
479 1.14 perry static __inline void
480 1.21 christos netbsd32_from___stat13(const struct stat *sbp, struct netbsd32_stat13 *sb32p)
481 1.8 christos {
482 1.46 riastrad
483 1.38 mrg memset(sb32p, 0, sizeof *sb32p);
484 1.21 christos sb32p->st_dev = (uint32_t)sbp->st_dev;
485 1.8 christos sb32p->st_ino = sbp->st_ino;
486 1.8 christos sb32p->st_mode = sbp->st_mode;
487 1.8 christos sb32p->st_nlink = sbp->st_nlink;
488 1.8 christos sb32p->st_uid = sbp->st_uid;
489 1.8 christos sb32p->st_gid = sbp->st_gid;
490 1.21 christos sb32p->st_rdev = (uint32_t)sbp->st_rdev;
491 1.8 christos sb32p->st_size = sbp->st_size;
492 1.21 christos sb32p->st_atimespec.tv_sec = (int32_t)sbp->st_atimespec.tv_sec;
493 1.8 christos sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec;
494 1.21 christos sb32p->st_mtimespec.tv_sec = (int32_t)sbp->st_mtimespec.tv_sec;
495 1.8 christos sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec;
496 1.21 christos sb32p->st_ctimespec.tv_sec = (int32_t)sbp->st_ctimespec.tv_sec;
497 1.8 christos sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec;
498 1.8 christos sb32p->st_blksize = sbp->st_blksize;
499 1.8 christos sb32p->st_blocks = sbp->st_blocks;
500 1.8 christos sb32p->st_flags = sbp->st_flags;
501 1.8 christos sb32p->st_gen = sbp->st_gen;
502 1.24 njoly sb32p->st_birthtimespec.tv_sec = (int32_t)sbp->st_birthtimespec.tv_sec;
503 1.24 njoly sb32p->st_birthtimespec.tv_nsec = (netbsd32_long)sbp->st_birthtimespec.tv_nsec;
504 1.8 christos }
505 1.8 christos
506 1.14 perry static __inline void
507 1.21 christos netbsd32_from___stat50(const struct stat *sbp, struct netbsd32_stat50 *sb32p)
508 1.1 mrg {
509 1.46 riastrad
510 1.38 mrg memset(sb32p, 0, sizeof *sb32p);
511 1.21 christos sb32p->st_dev = (uint32_t)sbp->st_dev;
512 1.1 mrg sb32p->st_ino = sbp->st_ino;
513 1.1 mrg sb32p->st_mode = sbp->st_mode;
514 1.1 mrg sb32p->st_nlink = sbp->st_nlink;
515 1.1 mrg sb32p->st_uid = sbp->st_uid;
516 1.1 mrg sb32p->st_gid = sbp->st_gid;
517 1.21 christos sb32p->st_rdev = (uint32_t)sbp->st_rdev;
518 1.8 christos sb32p->st_size = sbp->st_size;
519 1.21 christos sb32p->st_atimespec.tv_sec = (int32_t)sbp->st_atimespec.tv_sec;
520 1.1 mrg sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec;
521 1.21 christos sb32p->st_mtimespec.tv_sec = (int32_t)sbp->st_mtimespec.tv_sec;
522 1.1 mrg sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec;
523 1.21 christos sb32p->st_ctimespec.tv_sec = (int32_t)sbp->st_ctimespec.tv_sec;
524 1.1 mrg sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec;
525 1.24 njoly sb32p->st_birthtimespec.tv_sec = (int32_t)sbp->st_birthtimespec.tv_sec;
526 1.24 njoly sb32p->st_birthtimespec.tv_nsec = (netbsd32_long)sbp->st_birthtimespec.tv_nsec;
527 1.1 mrg sb32p->st_blksize = sbp->st_blksize;
528 1.1 mrg sb32p->st_blocks = sbp->st_blocks;
529 1.1 mrg sb32p->st_flags = sbp->st_flags;
530 1.1 mrg sb32p->st_gen = sbp->st_gen;
531 1.1 mrg }
532 1.1 mrg
533 1.14 perry static __inline void
534 1.21 christos netbsd32_from_stat(const struct stat *sbp, struct netbsd32_stat *sb32p)
535 1.21 christos {
536 1.46 riastrad
537 1.38 mrg memset(sb32p, 0, sizeof *sb32p);
538 1.22 christos sb32p->st_dev = sbp->st_dev;
539 1.21 christos sb32p->st_ino = sbp->st_ino;
540 1.21 christos sb32p->st_mode = sbp->st_mode;
541 1.21 christos sb32p->st_nlink = sbp->st_nlink;
542 1.21 christos sb32p->st_uid = sbp->st_uid;
543 1.21 christos sb32p->st_gid = sbp->st_gid;
544 1.22 christos sb32p->st_rdev = sbp->st_rdev;
545 1.21 christos sb32p->st_size = sbp->st_size;
546 1.22 christos sb32p->st_atimespec.tv_sec = (netbsd32_time_t)sbp->st_atimespec.tv_sec;
547 1.21 christos sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec;
548 1.22 christos sb32p->st_mtimespec.tv_sec = (netbsd32_time_t)sbp->st_mtimespec.tv_sec;
549 1.21 christos sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec;
550 1.22 christos sb32p->st_ctimespec.tv_sec = (netbsd32_time_t)sbp->st_ctimespec.tv_sec;
551 1.21 christos sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec;
552 1.24 njoly sb32p->st_birthtimespec.tv_sec = (netbsd32_time_t)sbp->st_birthtimespec.tv_sec;
553 1.24 njoly sb32p->st_birthtimespec.tv_nsec = (netbsd32_long)sbp->st_birthtimespec.tv_nsec;
554 1.21 christos sb32p->st_blksize = sbp->st_blksize;
555 1.21 christos sb32p->st_blocks = sbp->st_blocks;
556 1.21 christos sb32p->st_flags = sbp->st_flags;
557 1.21 christos sb32p->st_gen = sbp->st_gen;
558 1.21 christos }
559 1.21 christos
560 1.21 christos static __inline void
561 1.21 christos netbsd32_to_ipc_perm(const struct netbsd32_ipc_perm *ip32p,
562 1.21 christos struct ipc_perm *ipp)
563 1.1 mrg {
564 1.1 mrg
565 1.46 riastrad memset(ipp, 0, sizeof(*ipp));
566 1.1 mrg ipp->cuid = ip32p->cuid;
567 1.1 mrg ipp->cgid = ip32p->cgid;
568 1.1 mrg ipp->uid = ip32p->uid;
569 1.1 mrg ipp->gid = ip32p->gid;
570 1.1 mrg ipp->mode = ip32p->mode;
571 1.1 mrg ipp->_seq = ip32p->_seq;
572 1.1 mrg ipp->_key = (key_t)ip32p->_key;
573 1.1 mrg }
574 1.1 mrg
575 1.14 perry static __inline void
576 1.21 christos netbsd32_from_ipc_perm(const struct ipc_perm *ipp,
577 1.21 christos struct netbsd32_ipc_perm *ip32p)
578 1.1 mrg {
579 1.1 mrg
580 1.38 mrg memset(ip32p, 0, sizeof *ip32p);
581 1.1 mrg ip32p->cuid = ipp->cuid;
582 1.1 mrg ip32p->cgid = ipp->cgid;
583 1.1 mrg ip32p->uid = ipp->uid;
584 1.1 mrg ip32p->gid = ipp->gid;
585 1.1 mrg ip32p->mode = ipp->mode;
586 1.1 mrg ip32p->_seq = ipp->_seq;
587 1.1 mrg ip32p->_key = (netbsd32_key_t)ipp->_key;
588 1.1 mrg }
589 1.1 mrg
590 1.14 perry static __inline void
591 1.21 christos netbsd32_to_msg(const struct netbsd32_msg *m32p, struct msg *mp)
592 1.1 mrg {
593 1.1 mrg
594 1.46 riastrad memset(mp, 0, sizeof(*mp));
595 1.16 dsl mp->msg_next = NETBSD32PTR64(m32p->msg_next);
596 1.1 mrg mp->msg_type = (long)m32p->msg_type;
597 1.1 mrg mp->msg_ts = m32p->msg_ts;
598 1.1 mrg mp->msg_spot = m32p->msg_spot;
599 1.1 mrg }
600 1.1 mrg
601 1.14 perry static __inline void
602 1.21 christos netbsd32_from_msg(const struct msg *mp, struct netbsd32_msg *m32p)
603 1.1 mrg {
604 1.1 mrg
605 1.38 mrg memset(m32p, 0, sizeof *m32p);
606 1.16 dsl NETBSD32PTR32(m32p->msg_next, mp->msg_next);
607 1.1 mrg m32p->msg_type = (netbsd32_long)mp->msg_type;
608 1.1 mrg m32p->msg_ts = mp->msg_ts;
609 1.1 mrg m32p->msg_spot = mp->msg_spot;
610 1.1 mrg }
611 1.1 mrg
612 1.14 perry static __inline void
613 1.21 christos netbsd32_to_msqid_ds50(const struct netbsd32_msqid_ds50 *ds32p,
614 1.21 christos struct msqid_ds *dsp)
615 1.21 christos {
616 1.21 christos
617 1.46 riastrad memset(dsp, 0, sizeof(*dsp));
618 1.21 christos netbsd32_to_ipc_perm(&ds32p->msg_perm, &dsp->msg_perm);
619 1.21 christos dsp->_msg_cbytes = (u_long)ds32p->_msg_cbytes;
620 1.21 christos dsp->msg_qnum = (u_long)ds32p->msg_qnum;
621 1.21 christos dsp->msg_qbytes = (u_long)ds32p->msg_qbytes;
622 1.21 christos dsp->msg_lspid = ds32p->msg_lspid;
623 1.21 christos dsp->msg_lrpid = ds32p->msg_lrpid;
624 1.21 christos dsp->msg_rtime = (time_t)ds32p->msg_rtime;
625 1.21 christos dsp->msg_stime = (time_t)ds32p->msg_stime;
626 1.21 christos dsp->msg_ctime = (time_t)ds32p->msg_ctime;
627 1.21 christos }
628 1.21 christos
629 1.21 christos static __inline void
630 1.21 christos netbsd32_to_msqid_ds(const struct netbsd32_msqid_ds *ds32p,
631 1.21 christos struct msqid_ds *dsp)
632 1.1 mrg {
633 1.1 mrg
634 1.46 riastrad memset(dsp, 0, sizeof(*dsp));
635 1.1 mrg netbsd32_to_ipc_perm(&ds32p->msg_perm, &dsp->msg_perm);
636 1.1 mrg dsp->_msg_cbytes = (u_long)ds32p->_msg_cbytes;
637 1.1 mrg dsp->msg_qnum = (u_long)ds32p->msg_qnum;
638 1.1 mrg dsp->msg_qbytes = (u_long)ds32p->msg_qbytes;
639 1.1 mrg dsp->msg_lspid = ds32p->msg_lspid;
640 1.1 mrg dsp->msg_lrpid = ds32p->msg_lrpid;
641 1.1 mrg dsp->msg_rtime = (time_t)ds32p->msg_rtime;
642 1.1 mrg dsp->msg_stime = (time_t)ds32p->msg_stime;
643 1.1 mrg dsp->msg_ctime = (time_t)ds32p->msg_ctime;
644 1.1 mrg }
645 1.1 mrg
646 1.14 perry static __inline void
647 1.21 christos netbsd32_from_msqid_ds50(const struct msqid_ds *dsp,
648 1.21 christos struct netbsd32_msqid_ds50 *ds32p)
649 1.21 christos {
650 1.21 christos
651 1.38 mrg memset(ds32p, 0, sizeof *ds32p);
652 1.21 christos netbsd32_from_ipc_perm(&dsp->msg_perm, &ds32p->msg_perm);
653 1.21 christos ds32p->_msg_cbytes = (netbsd32_u_long)dsp->_msg_cbytes;
654 1.21 christos ds32p->msg_qnum = (netbsd32_u_long)dsp->msg_qnum;
655 1.21 christos ds32p->msg_qbytes = (netbsd32_u_long)dsp->msg_qbytes;
656 1.21 christos ds32p->msg_lspid = dsp->msg_lspid;
657 1.21 christos ds32p->msg_lrpid = dsp->msg_lrpid;
658 1.21 christos ds32p->msg_rtime = (int32_t)dsp->msg_rtime;
659 1.21 christos ds32p->msg_stime = (int32_t)dsp->msg_stime;
660 1.21 christos ds32p->msg_ctime = (int32_t)dsp->msg_ctime;
661 1.21 christos }
662 1.21 christos
663 1.21 christos static __inline void
664 1.21 christos netbsd32_from_msqid_ds(const struct msqid_ds *dsp,
665 1.21 christos struct netbsd32_msqid_ds *ds32p)
666 1.1 mrg {
667 1.1 mrg
668 1.38 mrg memset(ds32p, 0, sizeof *ds32p);
669 1.1 mrg netbsd32_from_ipc_perm(&dsp->msg_perm, &ds32p->msg_perm);
670 1.1 mrg ds32p->_msg_cbytes = (netbsd32_u_long)dsp->_msg_cbytes;
671 1.1 mrg ds32p->msg_qnum = (netbsd32_u_long)dsp->msg_qnum;
672 1.1 mrg ds32p->msg_qbytes = (netbsd32_u_long)dsp->msg_qbytes;
673 1.1 mrg ds32p->msg_lspid = dsp->msg_lspid;
674 1.1 mrg ds32p->msg_lrpid = dsp->msg_lrpid;
675 1.1 mrg ds32p->msg_rtime = dsp->msg_rtime;
676 1.1 mrg ds32p->msg_stime = dsp->msg_stime;
677 1.1 mrg ds32p->msg_ctime = dsp->msg_ctime;
678 1.1 mrg }
679 1.1 mrg
680 1.14 perry static __inline void
681 1.21 christos netbsd32_to_shmid_ds50(const struct netbsd32_shmid_ds50 *ds32p,
682 1.21 christos struct shmid_ds *dsp)
683 1.21 christos {
684 1.21 christos
685 1.46 riastrad memset(dsp, 0, sizeof(*dsp));
686 1.21 christos netbsd32_to_ipc_perm(&ds32p->shm_perm, &dsp->shm_perm);
687 1.21 christos dsp->shm_segsz = ds32p->shm_segsz;
688 1.21 christos dsp->shm_lpid = ds32p->shm_lpid;
689 1.21 christos dsp->shm_cpid = ds32p->shm_cpid;
690 1.21 christos dsp->shm_nattch = ds32p->shm_nattch;
691 1.21 christos dsp->shm_atime = (time_t)ds32p->shm_atime;
692 1.21 christos dsp->shm_dtime = (time_t)ds32p->shm_dtime;
693 1.21 christos dsp->shm_ctime = (time_t)ds32p->shm_ctime;
694 1.21 christos }
695 1.21 christos
696 1.21 christos static __inline void
697 1.21 christos netbsd32_to_shmid_ds(const struct netbsd32_shmid_ds *ds32p,
698 1.21 christos struct shmid_ds *dsp)
699 1.1 mrg {
700 1.1 mrg
701 1.46 riastrad memset(dsp, 0, sizeof(*dsp));
702 1.1 mrg netbsd32_to_ipc_perm(&ds32p->shm_perm, &dsp->shm_perm);
703 1.1 mrg dsp->shm_segsz = ds32p->shm_segsz;
704 1.1 mrg dsp->shm_lpid = ds32p->shm_lpid;
705 1.1 mrg dsp->shm_cpid = ds32p->shm_cpid;
706 1.1 mrg dsp->shm_nattch = ds32p->shm_nattch;
707 1.1 mrg dsp->shm_atime = (long)ds32p->shm_atime;
708 1.21 christos dsp->shm_dtime = (time_t)ds32p->shm_dtime;
709 1.21 christos dsp->shm_ctime = (time_t)ds32p->shm_ctime;
710 1.1 mrg }
711 1.1 mrg
712 1.14 perry static __inline void
713 1.21 christos netbsd32_from_shmid_ds50(const struct shmid_ds *dsp,
714 1.21 christos struct netbsd32_shmid_ds50 *ds32p)
715 1.21 christos {
716 1.21 christos
717 1.38 mrg memset(ds32p, 0, sizeof *ds32p);
718 1.21 christos netbsd32_from_ipc_perm(&dsp->shm_perm, &ds32p->shm_perm);
719 1.21 christos ds32p->shm_segsz = dsp->shm_segsz;
720 1.21 christos ds32p->shm_lpid = dsp->shm_lpid;
721 1.21 christos ds32p->shm_cpid = dsp->shm_cpid;
722 1.21 christos ds32p->shm_nattch = dsp->shm_nattch;
723 1.21 christos ds32p->shm_atime = (int32_t)dsp->shm_atime;
724 1.21 christos ds32p->shm_dtime = (int32_t)dsp->shm_dtime;
725 1.21 christos ds32p->shm_ctime = (int32_t)dsp->shm_ctime;
726 1.21 christos }
727 1.21 christos
728 1.21 christos static __inline void
729 1.21 christos netbsd32_from_shmid_ds(const struct shmid_ds *dsp,
730 1.21 christos struct netbsd32_shmid_ds *ds32p)
731 1.1 mrg {
732 1.1 mrg
733 1.38 mrg memset(ds32p, 0, sizeof *ds32p);
734 1.1 mrg netbsd32_from_ipc_perm(&dsp->shm_perm, &ds32p->shm_perm);
735 1.1 mrg ds32p->shm_segsz = dsp->shm_segsz;
736 1.1 mrg ds32p->shm_lpid = dsp->shm_lpid;
737 1.1 mrg ds32p->shm_cpid = dsp->shm_cpid;
738 1.1 mrg ds32p->shm_nattch = dsp->shm_nattch;
739 1.1 mrg ds32p->shm_atime = (netbsd32_long)dsp->shm_atime;
740 1.1 mrg ds32p->shm_dtime = (netbsd32_long)dsp->shm_dtime;
741 1.1 mrg ds32p->shm_ctime = (netbsd32_long)dsp->shm_ctime;
742 1.1 mrg }
743 1.1 mrg
744 1.14 perry static __inline void
745 1.21 christos netbsd32_to_semid_ds50(const struct netbsd32_semid_ds50 *s32dsp,
746 1.21 christos struct semid_ds *dsp)
747 1.21 christos {
748 1.21 christos
749 1.46 riastrad memset(dsp, 0, sizeof(*dsp));
750 1.21 christos netbsd32_to_ipc_perm(&s32dsp->sem_perm, &dsp->sem_perm);
751 1.21 christos dsp->sem_nsems = (time_t)s32dsp->sem_nsems;
752 1.21 christos dsp->sem_otime = (time_t)s32dsp->sem_otime;
753 1.21 christos dsp->sem_ctime = (time_t)s32dsp->sem_ctime;
754 1.21 christos }
755 1.21 christos
756 1.21 christos static __inline void
757 1.21 christos netbsd32_to_semid_ds(const struct netbsd32_semid_ds *s32dsp,
758 1.21 christos struct semid_ds *dsp)
759 1.1 mrg {
760 1.1 mrg
761 1.46 riastrad memset(dsp, 0, sizeof(*dsp));
762 1.7 cube netbsd32_to_ipc_perm(&s32dsp->sem_perm, &dsp->sem_perm);
763 1.1 mrg dsp->sem_nsems = s32dsp->sem_nsems;
764 1.1 mrg dsp->sem_otime = s32dsp->sem_otime;
765 1.1 mrg dsp->sem_ctime = s32dsp->sem_ctime;
766 1.1 mrg }
767 1.1 mrg
768 1.14 perry static __inline void
769 1.21 christos netbsd32_from_semid_ds50(const struct semid_ds *dsp,
770 1.21 christos struct netbsd32_semid_ds50 *s32dsp)
771 1.21 christos {
772 1.21 christos
773 1.38 mrg memset(s32dsp, 0, sizeof *s32dsp);
774 1.21 christos netbsd32_from_ipc_perm(&dsp->sem_perm, &s32dsp->sem_perm);
775 1.21 christos s32dsp->sem_nsems = (int32_t)dsp->sem_nsems;
776 1.21 christos s32dsp->sem_otime = (int32_t)dsp->sem_otime;
777 1.21 christos s32dsp->sem_ctime = (int32_t)dsp->sem_ctime;
778 1.21 christos }
779 1.21 christos
780 1.21 christos static __inline void
781 1.21 christos netbsd32_from_semid_ds(const struct semid_ds *dsp,
782 1.21 christos struct netbsd32_semid_ds *s32dsp)
783 1.1 mrg {
784 1.1 mrg
785 1.38 mrg memset(s32dsp, 0, sizeof *s32dsp);
786 1.7 cube netbsd32_from_ipc_perm(&dsp->sem_perm, &s32dsp->sem_perm);
787 1.1 mrg s32dsp->sem_nsems = dsp->sem_nsems;
788 1.1 mrg s32dsp->sem_otime = dsp->sem_otime;
789 1.1 mrg s32dsp->sem_ctime = dsp->sem_ctime;
790 1.1 mrg }
791 1.1 mrg
792 1.14 perry static __inline void
793 1.21 christos netbsd32_from_loadavg(struct netbsd32_loadavg *av32,
794 1.21 christos const struct loadavg *av)
795 1.1 mrg {
796 1.1 mrg
797 1.46 riastrad memset(av32, 0, sizeof(*av32));
798 1.1 mrg av32->ldavg[0] = av->ldavg[0];
799 1.1 mrg av32->ldavg[1] = av->ldavg[1];
800 1.1 mrg av32->ldavg[2] = av->ldavg[2];
801 1.1 mrg av32->fscale = (netbsd32_long)av->fscale;
802 1.1 mrg }
803 1.1 mrg
804 1.14 perry static __inline void
805 1.11 cube netbsd32_to_kevent(struct netbsd32_kevent *ke32, struct kevent *ke)
806 1.11 cube {
807 1.46 riastrad
808 1.46 riastrad memset(ke, 0, sizeof(*ke));
809 1.11 cube ke->ident = ke32->ident;
810 1.11 cube ke->filter = ke32->filter;
811 1.11 cube ke->flags = ke32->flags;
812 1.11 cube ke->fflags = ke32->fflags;
813 1.11 cube ke->data = ke32->data;
814 1.40 kamil ke->udata = NETBSD32PTR64(ke32->udata);
815 1.47 rin memcpy(&ke->ext, &ke32->ext, sizeof(ke->ext));
816 1.11 cube }
817 1.11 cube
818 1.14 perry static __inline void
819 1.11 cube netbsd32_from_kevent(struct kevent *ke, struct netbsd32_kevent *ke32)
820 1.11 cube {
821 1.46 riastrad
822 1.46 riastrad memset(ke32, 0, sizeof(*ke32));
823 1.11 cube ke32->ident = ke->ident;
824 1.11 cube ke32->filter = ke->filter;
825 1.11 cube ke32->flags = ke->flags;
826 1.11 cube ke32->fflags = ke->fflags;
827 1.11 cube ke32->data = ke->data;
828 1.40 kamil NETBSD32PTR32(ke32->udata, ke->udata);
829 1.47 rin memcpy(&ke32->ext, &ke->ext, sizeof(ke32->ext));
830 1.11 cube }
831 1.11 cube
832 1.14 perry static __inline void
833 1.7 cube netbsd32_to_sigevent(const struct netbsd32_sigevent *ev32, struct sigevent *ev)
834 1.6 cube {
835 1.46 riastrad
836 1.46 riastrad memset(ev, 0, sizeof(*ev));
837 1.6 cube ev->sigev_notify = ev32->sigev_notify;
838 1.6 cube ev->sigev_signo = ev32->sigev_signo;
839 1.6 cube /*
840 1.6 cube * XXX sival_ptr, sigev_notify_function and
841 1.6 cube * sigev_notify_attributes are currently unused
842 1.6 cube */
843 1.6 cube ev->sigev_value.sival_int = ev32->sigev_value.sival_int;
844 1.16 dsl ev->sigev_notify_function = NETBSD32PTR64(ev32->sigev_notify_function);
845 1.16 dsl ev->sigev_notify_attributes = NETBSD32PTR64(ev32->sigev_notify_attributes);
846 1.6 cube }
847 1.9 christos
848 1.14 perry static __inline int
849 1.9 christos netbsd32_to_dirent12(char *buf, int nbytes)
850 1.8 christos {
851 1.8 christos struct dirent *ndp, *nndp, *endp;
852 1.8 christos struct dirent12 *odp;
853 1.8 christos
854 1.8 christos odp = (struct dirent12 *)(void *)buf;
855 1.8 christos ndp = (struct dirent *)(void *)buf;
856 1.8 christos endp = (struct dirent *)(void *)&buf[nbytes];
857 1.8 christos
858 1.8 christos /*
859 1.8 christos * In-place conversion. This works because odp
860 1.8 christos * is smaller than ndp, but it has to be done
861 1.8 christos * in the right sequence.
862 1.8 christos */
863 1.8 christos for (; ndp < endp; ndp = nndp) {
864 1.8 christos nndp = _DIRENT_NEXT(ndp);
865 1.43 simonb odp->d_fileno = (uint32_t)ndp->d_fileno;
866 1.8 christos if (ndp->d_namlen >= sizeof(odp->d_name))
867 1.8 christos odp->d_namlen = sizeof(odp->d_name) - 1;
868 1.8 christos else
869 1.43 simonb odp->d_namlen = (uint8_t)ndp->d_namlen;
870 1.8 christos odp->d_type = ndp->d_type;
871 1.8 christos (void)memcpy(odp->d_name, ndp->d_name, (size_t)odp->d_namlen);
872 1.8 christos odp->d_name[odp->d_namlen] = '\0';
873 1.8 christos odp->d_reclen = _DIRENT_SIZE(odp);
874 1.8 christos odp = _DIRENT_NEXT(odp);
875 1.8 christos }
876 1.8 christos return ((char *)(void *)odp) - buf;
877 1.8 christos }
878 1.6 cube
879 1.34 christos static __inline int
880 1.26 bouyer netbsd32_copyin_plistref(netbsd32_pointer_t n32p, struct plistref *p)
881 1.26 bouyer {
882 1.26 bouyer struct netbsd32_plistref n32plist;
883 1.26 bouyer int error;
884 1.26 bouyer
885 1.26 bouyer error = copyin(NETBSD32PTR64(n32p), &n32plist,
886 1.26 bouyer sizeof(struct netbsd32_plistref));
887 1.26 bouyer if (error)
888 1.26 bouyer return error;
889 1.26 bouyer p->pref_plist = NETBSD32PTR64(n32plist.pref_plist);
890 1.26 bouyer p->pref_len = n32plist.pref_len;
891 1.26 bouyer return 0;
892 1.26 bouyer }
893 1.26 bouyer
894 1.34 christos static __inline int
895 1.26 bouyer netbsd32_copyout_plistref(netbsd32_pointer_t n32p, struct plistref *p)
896 1.26 bouyer {
897 1.26 bouyer struct netbsd32_plistref n32plist;
898 1.26 bouyer
899 1.46 riastrad memset(&n32plist, 0, sizeof(n32plist));
900 1.26 bouyer NETBSD32PTR32(n32plist.pref_plist, p->pref_plist);
901 1.26 bouyer n32plist.pref_len = p->pref_len;
902 1.26 bouyer return copyout(&n32plist, NETBSD32PTR64(n32p),
903 1.26 bouyer sizeof(struct netbsd32_plistref));
904 1.26 bouyer }
905 1.26 bouyer
906 1.36 mlelstv static __inline int
907 1.36 mlelstv netbsd32_copyin_nvlist_ref_t(netbsd32_pointer_t n32p, nvlist_ref_t *p)
908 1.36 mlelstv {
909 1.36 mlelstv netbsd32_nvlist_ref_t n32nv;
910 1.36 mlelstv int error;
911 1.36 mlelstv
912 1.36 mlelstv error = copyin(NETBSD32PTR64(n32p), &n32nv,
913 1.36 mlelstv sizeof(netbsd32_nvlist_ref_t));
914 1.36 mlelstv if (error)
915 1.36 mlelstv return error;
916 1.36 mlelstv p->buf = NETBSD32PTR64(n32nv.buf);
917 1.36 mlelstv p->len = n32nv.len;
918 1.36 mlelstv p->flags = n32nv.flags;
919 1.36 mlelstv return 0;
920 1.36 mlelstv }
921 1.36 mlelstv
922 1.36 mlelstv static __inline int
923 1.36 mlelstv netbsd32_copyout_nvlist_ref_t(netbsd32_pointer_t n32p, nvlist_ref_t *p)
924 1.36 mlelstv {
925 1.36 mlelstv netbsd32_nvlist_ref_t n32nv;
926 1.36 mlelstv
927 1.46 riastrad memset(&n32nv, 0, sizeof(n32nv));
928 1.36 mlelstv NETBSD32PTR32(n32nv.buf, p->buf);
929 1.36 mlelstv n32nv.len = p->len;
930 1.36 mlelstv n32nv.flags = p->flags;
931 1.36 mlelstv return copyout(&n32nv, NETBSD32PTR64(n32p),
932 1.36 mlelstv sizeof(netbsd32_nvlist_ref_t));
933 1.36 mlelstv }
934 1.36 mlelstv
935 1.29 martin static __inline void
936 1.29 martin netbsd32_to_mq_attr(const struct netbsd32_mq_attr *a32,
937 1.29 martin struct mq_attr *attr)
938 1.29 martin {
939 1.46 riastrad
940 1.46 riastrad memset(attr, 0, sizeof(*attr));
941 1.29 martin attr->mq_flags = a32->mq_flags;
942 1.29 martin attr->mq_maxmsg = a32->mq_maxmsg;
943 1.29 martin attr->mq_msgsize = a32->mq_msgsize;
944 1.29 martin attr->mq_curmsgs = a32->mq_curmsgs;
945 1.29 martin }
946 1.29 martin
947 1.29 martin static __inline void
948 1.29 martin netbsd32_from_mq_attr(const struct mq_attr *attr,
949 1.29 martin struct netbsd32_mq_attr *a32)
950 1.29 martin {
951 1.46 riastrad
952 1.46 riastrad memset(a32, 0, sizeof(*a32));
953 1.29 martin a32->mq_flags = attr->mq_flags;
954 1.29 martin a32->mq_maxmsg = attr->mq_maxmsg;
955 1.29 martin a32->mq_msgsize = attr->mq_msgsize;
956 1.29 martin a32->mq_curmsgs = attr->mq_curmsgs;
957 1.29 martin }
958 1.29 martin
959 1.1 mrg #endif /* _COMPAT_NETBSD32_NETBSD32_CONV_H_ */
960