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