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