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
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
|
/* $NetBSD: netbsd32_compat_50.c,v 1.53 2022/10/26 23:23:52 riastradh Exp $ */
/*-
* Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Christos Zoulas.
*
* 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 FOUNDATION OR CONTRIBUTORS
* 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.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_50.c,v 1.53 2022/10/26 23:23:52 riastradh Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
#include "opt_compat_netbsd32.h"
#include "opt_ntp.h"
#include "opt_quota.h"
#endif
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/module.h>
#include <sys/mount.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/timevar.h>
#include <sys/timex.h>
#include <sys/ktrace.h>
#include <sys/eventvar.h>
#include <sys/resourcevar.h>
#include <sys/vnode.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/poll.h>
#include <sys/namei.h>
#include <sys/statvfs.h>
#include <sys/syscallargs.h>
#include <sys/syscallvar.h>
#include <sys/proc.h>
#include <sys/dirent.h>
#include <sys/kauth.h>
#include <sys/vfs_syscalls.h>
#include <sys/compat_stub.h>
#include <sys/module_hook.h>
#include <compat/netbsd32/netbsd32.h>
#include <compat/netbsd32/netbsd32_syscall.h>
#include <compat/netbsd32/netbsd32_syscallargs.h>
#include <compat/netbsd32/netbsd32_conv.h>
#include <compat/sys/mount.h>
#include <compat/sys/time.h>
#include <compat/sys/rnd.h>
#if defined(COMPAT_50)
/*
* Common routine to set access and modification times given a vnode.
*/
static int
get_utimes32(const netbsd32_timeval50p_t *tptr, struct timeval *tv,
struct timeval **tvp)
{
int error;
struct netbsd32_timeval50 tv32[2];
if (tptr == NULL) {
*tvp = NULL;
return 0;
}
error = copyin(tptr, tv32, sizeof(tv32));
if (error)
return error;
netbsd32_to_timeval50(&tv32[0], &tv[0]);
netbsd32_to_timeval50(&tv32[1], &tv[1]);
*tvp = tv;
return 0;
}
int
compat_50_netbsd32_mknod(struct lwp *l,
const struct compat_50_netbsd32_mknod_args *uap, register_t *retval)
{
/* {
syscallarg(netbsd32_charp) path;
syscallarg(mode_t) mode;
syscallarg(uint32_t) dev;
} */
return do_sys_mknod(l, SCARG_P32(uap, path), SCARG(uap, mode),
SCARG(uap, dev), UIO_USERSPACE);
}
int
compat_50_netbsd32_select(struct lwp *l,
const struct compat_50_netbsd32_select_args *uap, register_t *retval)
{
/* {
syscallarg(int) nd;
syscallarg(netbsd32_fd_setp_t) in;
syscallarg(netbsd32_fd_setp_t) ou;
syscallarg(netbsd32_fd_setp_t) ex;
syscallarg(netbsd32_timeval50p_t) tv;
} */
int error;
struct netbsd32_timeval50 tv32;
struct timespec ats, *ts = NULL;
if (SCARG_P32(uap, tv)) {
error = copyin(SCARG_P32(uap, tv), &tv32, sizeof(tv32));
if (error != 0)
return error;
if (tv32.tv_usec < 0 || tv32.tv_usec >= 1000000)
return EINVAL;
ats.tv_sec = tv32.tv_sec;
ats.tv_nsec = tv32.tv_usec * 1000;
ts = &ats;
}
return selcommon(retval, SCARG(uap, nd), SCARG_P32(uap, in),
SCARG_P32(uap, ou), SCARG_P32(uap, ex), ts, NULL);
}
int
compat_50_netbsd32_gettimeofday(struct lwp *l,
const struct compat_50_netbsd32_gettimeofday_args *uap, register_t *retval)
{
/* {
syscallarg(netbsd32_timeval50p_t) tp;
syscallarg(netbsd32_timezonep_t) tzp;
} */
struct timeval atv;
struct netbsd32_timeval50 tv32;
int error = 0;
struct netbsd32_timezone tzfake;
if (SCARG_P32(uap, tp)) {
microtime(&atv);
netbsd32_from_timeval50(&atv, &tv32);
error = copyout(&tv32, SCARG_P32(uap, tp), sizeof(tv32));
if (error)
return error;
}
if (SCARG_P32(uap, tzp)) {
/*
* NetBSD has no kernel notion of time zone, so we just
* fake up a timezone struct and return it if demanded.
*/
memset(&tzfake, 0, sizeof(tzfake));
tzfake.tz_minuteswest = 0;
tzfake.tz_dsttime = 0;
error = copyout(&tzfake, SCARG_P32(uap, tzp), sizeof(tzfake));
}
return error;
}
int
compat_50_netbsd32_settimeofday(struct lwp *l,
const struct compat_50_netbsd32_settimeofday_args *uap, register_t *retval)
{
/* {
syscallarg(const netbsd32_timeval50p_t) tv;
syscallarg(const netbsd32_timezonep_t) tzp;
} */
struct netbsd32_timeval50 atv32;
struct timeval atv;
struct timespec ats;
int error;
struct proc *p = l->l_proc;
/* Verify all parameters before changing time. */
/*
* NetBSD has no kernel notion of time zone, and only an
* obsolete program would try to set it, so we log a warning.
*/
if (SCARG_P32(uap, tzp))
printf("pid %d attempted to set the "
"(obsolete) kernel time zone\n", p->p_pid);
if (SCARG_P32(uap, tv) == 0)
return 0;
if ((error = copyin(SCARG_P32(uap, tv), &atv32, sizeof(atv32))) != 0)
return error;
netbsd32_to_timeval50(&atv32, &atv);
if (atv.tv_usec < 0 || atv.tv_usec >= 1000000)
return EINVAL;
TIMEVAL_TO_TIMESPEC(&atv, &ats);
return settime(p, &ats);
}
int
compat_50_netbsd32_utimes(struct lwp *l,
const struct compat_50_netbsd32_utimes_args *uap, register_t *retval)
{
/* {
syscallarg(const netbsd32_charp) path;
syscallarg(const netbsd32_timeval50p_t) tptr;
} */
int error;
struct timeval tv[2], *tvp;
error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
if (error != 0)
return error;
return do_sys_utimes(l, NULL, SCARG_P32(uap, path), FOLLOW,
tvp, UIO_SYSSPACE);
}
int
compat_50_netbsd32_adjtime(struct lwp *l,
const struct compat_50_netbsd32_adjtime_args *uap, register_t *retval)
{
/* {
syscallarg(const netbsd32_timeval50p_t) delta;
syscallarg(netbsd32_timeval50p_t) olddelta;
} */
struct netbsd32_timeval50 atv;
int error;
if ((error = kauth_authorize_system(l->l_cred,
KAUTH_SYSTEM_TIME, KAUTH_REQ_SYSTEM_TIME_ADJTIME, NULL, NULL,
NULL)) != 0)
return error;
if (SCARG_P32(uap, olddelta)) {
memset(&atv, 0, sizeof(atv));
mutex_spin_enter(&timecounter_lock);
atv.tv_sec = time_adjtime / 1000000;
atv.tv_usec = time_adjtime % 1000000;
if (atv.tv_usec < 0) {
atv.tv_usec += 1000000;
atv.tv_sec--;
}
mutex_spin_exit(&timecounter_lock);
error = copyout(&atv, SCARG_P32(uap, olddelta), sizeof(atv));
if (error)
return error;
}
if (SCARG_P32(uap, delta)) {
error = copyin(SCARG_P32(uap, delta), &atv, sizeof(atv));
if (error)
return error;
mutex_spin_enter(&timecounter_lock);
time_adjtime = (int64_t)atv.tv_sec * 1000000 + atv.tv_usec;
if (time_adjtime)
/* We need to save the system time during shutdown */
time_adjusted |= 1;
mutex_spin_exit(&timecounter_lock);
}
return 0;
}
int
compat_50_netbsd32_futimes(struct lwp *l,
const struct compat_50_netbsd32_futimes_args *uap, register_t *retval)
{
/* {
syscallarg(int) fd;
syscallarg(const netbsd32_timeval50p_t) tptr;
} */
int error;
file_t *fp;
struct timeval tv[2], *tvp;
error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
if (error != 0)
return error;
/* fd_getvnode() will use the descriptor for us */
if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
return error;
error = do_sys_utimes(l, fp->f_vnode, NULL, 0, tvp, UIO_SYSSPACE);
fd_putfile(SCARG(uap, fd));
return error;
}
int
compat_50_netbsd32_clock_gettime(struct lwp *l,
const struct compat_50_netbsd32_clock_gettime_args *uap, register_t *retval)
{
/* {
syscallarg(netbsd32_clockid_t) clock_id;
syscallarg(netbsd32_timespec50p_t) tp;
} */
int error;
struct timespec ats;
struct netbsd32_timespec50 ts32;
error = clock_gettime1(SCARG(uap, clock_id), &ats);
if (error != 0)
return error;
netbsd32_from_timespec50(&ats, &ts32);
return copyout(&ts32, SCARG_P32(uap, tp), sizeof(ts32));
}
int
compat_50_netbsd32_clock_settime(struct lwp *l,
const struct compat_50_netbsd32_clock_settime_args *uap, register_t *retval)
{
/* {
syscallarg(netbsd32_clockid_t) clock_id;
syscallarg(const netbsd32_timespec50p_t) tp;
} */
struct netbsd32_timespec50 ts32;
struct timespec ats;
int error;
if ((error = copyin(SCARG_P32(uap, tp), &ts32, sizeof(ts32))) != 0)
return error;
netbsd32_to_timespec50(&ts32, &ats);
return clock_settime1(l->l_proc, SCARG(uap, clock_id), &ats, true);
}
int
compat_50_netbsd32_clock_getres(struct lwp *l,
const struct compat_50_netbsd32_clock_getres_args *uap, register_t *retval)
{
/* {
syscallarg(netbsd32_clockid_t) clock_id;
syscallarg(netbsd32_timespec50p_t) tp;
} */
struct netbsd32_timespec50 ts32;
struct timespec ts;
int error;
error = clock_getres1(SCARG(uap, clock_id), &ts);
if (error != 0)
return error;
if (SCARG_P32(uap, tp)) {
netbsd32_from_timespec50(&ts, &ts32);
error = copyout(&ts32, SCARG_P32(uap, tp), sizeof(ts32));
}
return error;
}
int
compat_50_netbsd32_timer_settime(struct lwp *l,
const struct compat_50_netbsd32_timer_settime_args *uap, register_t *retval)
{
/* {
syscallarg(netbsd32_timer_t) timerid;
syscallarg(int) flags;
syscallarg(const netbsd32_itimerspec50p_t) value;
syscallarg(netbsd32_itimerspec50p_t) ovalue;
} */
int error;
struct itimerspec value, ovalue, *ovp = NULL;
struct netbsd32_itimerspec50 its32;
if ((error = copyin(SCARG_P32(uap, value), &its32, sizeof(its32))) != 0)
return error;
netbsd32_to_timespec50(&its32.it_interval, &value.it_interval);
netbsd32_to_timespec50(&its32.it_value, &value.it_value);
if (SCARG_P32(uap, ovalue))
ovp = &ovalue;
if ((error = dotimer_settime(SCARG(uap, timerid), &value, ovp,
SCARG(uap, flags), l->l_proc)) != 0)
return error;
if (ovp) {
memset(&its32, 0, sizeof(its32));
netbsd32_from_timespec50(&ovp->it_interval, &its32.it_interval);
netbsd32_from_timespec50(&ovp->it_value, &its32.it_value);
return copyout(&its32, SCARG_P32(uap, ovalue), sizeof(its32));
}
return 0;
}
int
compat_50_netbsd32_timer_gettime(struct lwp *l, const struct compat_50_netbsd32_timer_gettime_args *uap, register_t *retval)
{
/* {
syscallarg(netbsd32_timer_t) timerid;
syscallarg(netbsd32_itimerspec50p_t) value;
} */
int error;
struct itimerspec its;
struct netbsd32_itimerspec50 its32;
if ((error = dotimer_gettime(SCARG(uap, timerid), l->l_proc,
&its)) != 0)
return error;
memset(&its32, 0, sizeof(its32));
netbsd32_from_timespec50(&its.it_interval, &its32.it_interval);
netbsd32_from_timespec50(&its.it_value, &its32.it_value);
return copyout(&its32, SCARG_P32(uap, value), sizeof(its32));
}
int
compat_50_netbsd32_nanosleep(struct lwp *l,
const struct compat_50_netbsd32_nanosleep_args *uap, register_t *retval)
{
/* {
syscallarg(const netbsd32_timespec50p_t) rqtp;
syscallarg(netbsd32_timespecp_t) rmtp;
} */
struct netbsd32_timespec50 ts32;
struct timespec rqt, rmt;
int error, error1;
error = copyin(SCARG_P32(uap, rqtp), &ts32, sizeof(ts32));
if (error)
return error;
netbsd32_to_timespec50(&ts32, &rqt);
error = nanosleep1(l, CLOCK_MONOTONIC, 0, &rqt,
SCARG_P32(uap, rmtp) ? &rmt : NULL);
if (SCARG_P32(uap, rmtp) == NULL || (error != 0 && error != EINTR))
return error;
netbsd32_from_timespec50(&rmt, &ts32);
error1 = copyout(&ts32, SCARG_P32(uap,rmtp), sizeof(ts32));
return error1 ? error1 : error;
}
static int
compat_50_netbsd32_sigtimedwait_put_info(const void *src, void *dst, size_t size)
{
const siginfo_t *info = src;
siginfo32_t info32;
netbsd32_si_to_si32(&info32, info);
return copyout(&info32, dst, sizeof(info32));
}
static int
compat_50_netbsd32_sigtimedwait_fetch_timeout(const void *src, void *dst, size_t size)
{
struct timespec *ts = dst;
struct netbsd32_timespec50 ts32;
int error;
error = copyin(src, &ts32, sizeof(ts32));
if (error)
return error;
netbsd32_to_timespec50(&ts32, ts);
return 0;
}
static int
compat_50_netbsd32_sigtimedwait_put_timeout(const void *src, void *dst, size_t size)
{
const struct timespec *ts = src;
struct netbsd32_timespec50 ts32;
netbsd32_from_timespec50(ts, &ts32);
return copyout(&ts32, dst, sizeof(ts32));
}
int
compat_50_netbsd32___sigtimedwait(struct lwp *l,
const struct compat_50_netbsd32___sigtimedwait_args *uap, register_t *retval)
{
/* {
syscallarg(netbsd32_sigsetp_t) set;
syscallarg(netbsd32_siginfop_t) info;
syscallarg(netbsd32_timespec50p_t) timeout;
} */
struct sys_____sigtimedwait50_args ua;
int res;
NETBSD32TOP_UAP(set, const sigset_t);
NETBSD32TOP_UAP(info, siginfo_t);
NETBSD32TOP_UAP(timeout, struct timespec);
res = sigtimedwait1(l, &ua, retval,
copyin,
compat_50_netbsd32_sigtimedwait_put_info,
compat_50_netbsd32_sigtimedwait_fetch_timeout,
compat_50_netbsd32_sigtimedwait_put_timeout);
if (!res)
*retval = 0; /* NetBSD<=5 was not POSIX compliant */
return res;
}
int
compat_50_netbsd32_lutimes(struct lwp *l,
const struct compat_50_netbsd32_lutimes_args *uap, register_t *retval)
{
/* {
syscallarg(const netbsd32_charp) path;
syscallarg(const netbsd32_timeval50p_t) tptr;
} */
int error;
struct timeval tv[2], *tvp;
error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
if (error != 0)
return error;
return do_sys_utimes(l, NULL, SCARG_P32(uap, path), NOFOLLOW,
tvp, UIO_SYSSPACE);
}
int
compat_50_netbsd32__lwp_park(struct lwp *l,
const struct compat_50_netbsd32__lwp_park_args *uap, register_t *retval)
{
/* {
syscallarg(const netbsd32_timespec50p) ts;
syscallarg(lwpid_t) unpark;
syscallarg(netbsd32_voidp) hint;
syscallarg(netbsd32_voidp) unparkhint;
} */
struct timespec ts, *tsp;
struct netbsd32_timespec50 ts32;
int error;
if (SCARG_P32(uap, ts) == NULL)
tsp = NULL;
else {
error = copyin(SCARG_P32(uap, ts), &ts32, sizeof ts32);
if (error != 0)
return error;
netbsd32_to_timespec50(&ts32, &ts);
tsp = &ts;
}
if (SCARG(uap, unpark) != 0) {
error = lwp_unpark(&SCARG(uap, unpark), 1);
if (error != 0)
return error;
}
return lwp_park(CLOCK_REALTIME, TIMER_ABSTIME, tsp);
}
static int
netbsd32_kevent_fetch_timeout(const void *src, void *dest, size_t length)
{
struct netbsd32_timespec50 ts32;
int error;
KASSERT(length == sizeof(struct timespec50));
error = copyin(src, &ts32, sizeof(ts32));
if (error)
return error;
netbsd32_to_timespec50(&ts32, (struct timespec *)dest);
return 0;
}
static int
netbsd32_kevent_fetch_changes(void *ctx, const struct kevent *changelist,
struct kevent *changes, size_t index, int n)
{
const struct netbsd32_kevent *src =
(const struct netbsd32_kevent *)changelist;
struct netbsd32_kevent *kev32, *changes32 = ctx;
int error, i;
error = copyin(src + index, changes32, n * sizeof(*changes32));
if (error)
return error;
for (i = 0, kev32 = changes32; i < n; i++, kev32++, changes++)
netbsd32_to_kevent(kev32, changes);
return 0;
}
static int
netbsd32_kevent_put_events(void *ctx, struct kevent *events,
struct kevent *eventlist, size_t index, int n)
{
struct netbsd32_kevent *kev32, *events32 = ctx;
int i;
for (i = 0, kev32 = events32; i < n; i++, kev32++, events++)
netbsd32_from_kevent(events, kev32);
kev32 = (struct netbsd32_kevent *)eventlist;
return copyout(events32, kev32, n * sizeof(*events32));
}
int
compat_50_netbsd32_kevent(struct lwp *l,
const struct compat_50_netbsd32_kevent_args *uap, register_t *retval)
{
/* {
syscallarg(int) fd;
syscallarg(netbsd32_keventp_t) changelist;
syscallarg(netbsd32_size_t) nchanges;
syscallarg(netbsd32_keventp_t) eventlist;
syscallarg(netbsd32_size_t) nevents;
syscallarg(netbsd32_timespec50p_t) timeout;
} */
int error;
size_t maxalloc, nchanges, nevents;
struct kevent_ops netbsd32_kevent_ops = {
.keo_fetch_timeout = netbsd32_kevent_fetch_timeout,
.keo_fetch_changes = netbsd32_kevent_fetch_changes,
.keo_put_events = netbsd32_kevent_put_events,
};
nchanges = SCARG(uap, nchanges);
nevents = SCARG(uap, nevents);
maxalloc = KQ_NEVENTS;
netbsd32_kevent_ops.keo_private =
kmem_alloc(maxalloc * sizeof(struct netbsd32_kevent), KM_SLEEP);
error = kevent1(retval, SCARG(uap, fd),
NETBSD32PTR64(SCARG(uap, changelist)), nchanges,
NETBSD32PTR64(SCARG(uap, eventlist)), nevents,
NETBSD32PTR64(SCARG(uap, timeout)), &netbsd32_kevent_ops);
kmem_free(netbsd32_kevent_ops.keo_private,
maxalloc * sizeof(struct netbsd32_kevent));
return error;
}
int
compat_50_netbsd32_pselect(struct lwp *l,
const struct compat_50_netbsd32_pselect_args *uap, register_t *retval)
{
/* {
syscallarg(int) nd;
syscallarg(netbsd32_fd_setp_t) in;
syscallarg(netbsd32_fd_setp_t) ou;
syscallarg(netbsd32_fd_setp_t) ex;
syscallarg(const netbsd32_timespec50p_t) ts;
syscallarg(const netbsd32_sigsetp_t) mask;
} */
int error;
struct netbsd32_timespec50 ts32;
struct timespec ats, *ts = NULL;
sigset_t amask, *mask = NULL;
if (SCARG_P32(uap, ts)) {
error = copyin(SCARG_P32(uap, ts), &ts32, sizeof(ts32));
if (error != 0)
return error;
netbsd32_to_timespec50(&ts32, &ats);
ts = &ats;
}
if (SCARG_P32(uap, mask)) {
error = copyin(SCARG_P32(uap, mask), &amask, sizeof(amask));
if (error != 0)
return error;
mask = &amask;
}
return selcommon(retval, SCARG(uap, nd), SCARG_P32(uap, in),
SCARG_P32(uap, ou), SCARG_P32(uap, ex), ts, mask);
}
int
compat_50_netbsd32_pollts(struct lwp *l,
const struct compat_50_netbsd32_pollts_args *uap, register_t *retval)
{
/* {
syscallarg(struct netbsd32_pollfdp_t) fds;
syscallarg(u_int) nfds;
syscallarg(const netbsd32_timespec50p_t) ts;
syscallarg(const netbsd32_sigsetp_t) mask;
} */
int error;
struct netbsd32_timespec50 ts32;
struct timespec ats, *ts = NULL;
sigset_t amask, *mask = NULL;
if (SCARG_P32(uap, ts)) {
error = copyin(SCARG_P32(uap, ts), &ts32, sizeof(ts32));
if (error != 0)
return error;
netbsd32_to_timespec50(&ts32, &ats);
ts = &ats;
}
if (NETBSD32PTR64( SCARG(uap, mask))) {
error = copyin(SCARG_P32(uap, mask), &amask, sizeof(amask));
if (error != 0)
return error;
mask = &amask;
}
return pollcommon(retval, SCARG_P32(uap, fds),
SCARG(uap, nfds), ts, mask);
}
int
compat_50_netbsd32___stat30(struct lwp *l,
const struct compat_50_netbsd32___stat30_args *uap, register_t *retval)
{
/* {
syscallarg(const netbsd32_charp) path;
syscallarg(netbsd32_stat50p_t) ub;
} */
struct netbsd32_stat50 sb32;
struct stat sb;
int error;
const char *path;
path = SCARG_P32(uap, path);
error = do_sys_stat(path, FOLLOW, &sb);
if (error)
return error;
netbsd32_from___stat50(&sb, &sb32);
error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
return error;
}
int
compat_50_netbsd32___fstat30(struct lwp *l,
const struct compat_50_netbsd32___fstat30_args *uap, register_t *retval)
{
/* {
syscallarg(int) fd;
syscallarg(netbsd32_stat50p_t) sb;
} */
struct netbsd32_stat50 sb32;
struct stat ub;
int error;
error = do_sys_fstat(SCARG(uap, fd), &ub);
if (error == 0) {
netbsd32_from___stat50(&ub, &sb32);
error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
}
return error;
}
int
compat_50_netbsd32___lstat30(struct lwp *l,
const struct compat_50_netbsd32___lstat30_args *uap, register_t *retval)
{
/* {
syscallarg(const netbsd32_charp) path;
syscallarg(netbsd32_stat50p_t) ub;
} */
struct netbsd32_stat50 sb32;
struct stat sb;
int error;
const char *path;
path = SCARG_P32(uap, path);
error = do_sys_stat(path, NOFOLLOW, &sb);
if (error)
return error;
netbsd32_from___stat50(&sb, &sb32);
error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
return error;
}
int
compat_50_netbsd32___fhstat40(struct lwp *l, const struct compat_50_netbsd32___fhstat40_args *uap, register_t *retval)
{
/* {
syscallarg(const netbsd32_pointer_t) fhp;
syscallarg(netbsd32_size_t) fh_size;
syscallarg(netbsd32_stat50p_t) sb;
} */
struct stat sb;
struct netbsd32_stat50 sb32;
int error;
error = do_fhstat(l, SCARG_P32(uap, fhp), SCARG(uap, fh_size), &sb);
if (error == 0) {
netbsd32_from___stat50(&sb, &sb32);
error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
}
return error;
}
int
compat_50_netbsd32_wait4(struct lwp *l, const struct compat_50_netbsd32_wait4_args *uap, register_t *retval)
{
/* {
syscallarg(int) pid;
syscallarg(netbsd32_intp) status;
syscallarg(int) options;
syscallarg(netbsd32_rusage50p_t) rusage;
} */
int error, status, pid = SCARG(uap, pid);
struct netbsd32_rusage50 ru32;
struct rusage ru;
error = do_sys_wait(&pid, &status, SCARG(uap, options),
SCARG_P32(uap, rusage) != NULL ? &ru : NULL);
retval[0] = pid;
if (pid == 0)
return error;
if (SCARG_P32(uap, rusage)) {
netbsd32_from_rusage50(&ru, &ru32);
error = copyout(&ru32, SCARG_P32(uap, rusage), sizeof(ru32));
}
if (error == 0 && SCARG_P32(uap, status))
error = copyout(&status, SCARG_P32(uap, status), sizeof(status));
return error;
}
int
compat_50_netbsd32_getrusage(struct lwp *l, const struct compat_50_netbsd32_getrusage_args *uap, register_t *retval)
{
/* {
syscallarg(int) who;
syscallarg(netbsd32_rusage50p_t) rusage;
} */
int error;
struct proc *p = l->l_proc;
struct rusage ru;
struct netbsd32_rusage50 ru32;
error = getrusage1(p, SCARG(uap, who), &ru);
if (error != 0)
return error;
netbsd32_from_rusage50(&ru, &ru32);
return copyout(&ru32, SCARG_P32(uap, rusage), sizeof(ru32));
}
int
compat_50_netbsd32_setitimer(struct lwp *l,
const struct compat_50_netbsd32_setitimer_args *uap, register_t *retval)
{
/* {
syscallarg(int) which;
syscallarg(const netbsd32_itimerval50p_t) itv;
syscallarg(netbsd32_itimerval50p_t) oitv;
} */
struct proc *p = l->l_proc;
struct netbsd32_itimerval50 s32it, *itv32;
int which = SCARG(uap, which);
struct compat_50_netbsd32_getitimer_args getargs;
struct itimerval aitv;
int error;
itv32 = SCARG_P32(uap, itv);
if (itv32) {
if ((error = copyin(itv32, &s32it, sizeof(s32it))))
return error;
netbsd32_to_itimerval50(&s32it, &aitv);
}
if (SCARG_P32(uap, oitv) != 0) {
SCARG(&getargs, which) = which;
SCARG(&getargs, itv) = SCARG(uap, oitv);
if ((error = compat_50_netbsd32_getitimer(l, &getargs, retval)) != 0)
return error;
}
if (itv32 == 0)
return 0;
return dosetitimer(p, which, &aitv);
}
int
compat_50_netbsd32_getitimer(struct lwp *l, const struct compat_50_netbsd32_getitimer_args *uap, register_t *retval)
{
/* {
syscallarg(int) which;
syscallarg(netbsd32_itimerval50p_t) itv;
} */
struct proc *p = l->l_proc;
struct netbsd32_itimerval50 s32it;
struct itimerval aitv;
int error;
error = dogetitimer(p, SCARG(uap, which), &aitv);
if (error)
return error;
netbsd32_from_itimerval50(&aitv, &s32it);
return copyout(&s32it, SCARG_P32(uap, itv), sizeof(s32it));
}
#ifdef NTP
int
compat_50_netbsd32_ntp_gettime(struct lwp *l,
const struct compat_50_netbsd32_ntp_gettime_args *uap, register_t *retval)
{
/* {
syscallarg(netbsd32_ntptimeval50p_t) ntvp;
} */
struct netbsd32_ntptimeval50 ntv32;
struct ntptimeval ntv;
int error = 0;
if (vec_ntp_gettime == NULL)
return EINVAL;
if (SCARG_P32(uap, ntvp)) {
(*vec_ntp_gettime)(&ntv);
memset(&ntv32, 0, sizeof(ntv32));
ntv32.time.tv_sec = (int32_t)ntv.time.tv_sec;
ntv32.time.tv_nsec = ntv.time.tv_nsec;
ntv32.maxerror = (netbsd32_long)ntv.maxerror;
ntv32.esterror = (netbsd32_long)ntv.esterror;
ntv32.tai = (netbsd32_long)ntv.tai;
ntv32.time_state = ntv.time_state;
error = copyout(&ntv32, SCARG_P32(uap, ntvp), sizeof(ntv32));
}
if (!error) {
*retval = (*vec_ntp_timestatus)();
}
return error;
}
#endif
static struct syscall_package compat_netbsd32_50_syscalls[] = {
{ NETBSD32_SYS_compat_50_netbsd32_mknod, 0,
(sy_call_t *)compat_50_netbsd32_mknod },
{ NETBSD32_SYS_compat_50_netbsd32_select, 0,
(sy_call_t *)compat_50_netbsd32_select },
{ NETBSD32_SYS_compat_50_netbsd32_gettimeofday, 0,
(sy_call_t *)compat_50_netbsd32_gettimeofday },
{ NETBSD32_SYS_compat_50_netbsd32_settimeofday, 0,
(sy_call_t *)compat_50_netbsd32_settimeofday },
{ NETBSD32_SYS_compat_50_netbsd32_utimes, 0,
(sy_call_t *)compat_50_netbsd32_utimes },
{ NETBSD32_SYS_compat_50_netbsd32_futimes, 0,
(sy_call_t *)compat_50_netbsd32_futimes },
{ NETBSD32_SYS_compat_50_netbsd32_adjtime, 0,
(sy_call_t *)compat_50_netbsd32_adjtime },
{ NETBSD32_SYS_compat_50_netbsd32_clock_gettime, 0,
(sy_call_t *)compat_50_netbsd32_clock_gettime },
{ NETBSD32_SYS_compat_50_netbsd32_clock_settime, 0,
(sy_call_t *)compat_50_netbsd32_clock_settime },
{ NETBSD32_SYS_compat_50_netbsd32_clock_getres, 0,
(sy_call_t *)compat_50_netbsd32_clock_getres },
{ NETBSD32_SYS_compat_50_netbsd32_timer_settime, 0,
(sy_call_t *)compat_50_netbsd32_timer_settime },
{ NETBSD32_SYS_compat_50_netbsd32_timer_gettime, 0,
(sy_call_t *)compat_50_netbsd32_timer_gettime },
{ NETBSD32_SYS_compat_50_netbsd32_nanosleep, 0,
(sy_call_t *)compat_50_netbsd32_nanosleep },
{ NETBSD32_SYS_compat_50_netbsd32___sigtimedwait, 0,
(sy_call_t *)compat_50_netbsd32___sigtimedwait },
{ NETBSD32_SYS_compat_50_netbsd32_lutimes, 0,
(sy_call_t *)compat_50_netbsd32_lutimes },
{ NETBSD32_SYS_compat_50_netbsd32__lwp_park, 0,
(sy_call_t *)compat_50_netbsd32__lwp_park },
{ NETBSD32_SYS_compat_50_netbsd32_kevent, 0,
(sy_call_t *)compat_50_netbsd32_kevent },
{ NETBSD32_SYS_compat_50_netbsd32_pselect, 0,
(sy_call_t *)compat_50_netbsd32_pselect },
{ NETBSD32_SYS_compat_50_netbsd32_pollts, 0,
(sy_call_t *)compat_50_netbsd32_pollts },
{ NETBSD32_SYS_compat_50_netbsd32___stat30, 0,
(sy_call_t *)compat_50_netbsd32___stat30 },
{ NETBSD32_SYS_compat_50_netbsd32___fstat30, 0,
(sy_call_t *)compat_50_netbsd32___fstat30 },
{ NETBSD32_SYS_compat_50_netbsd32___lstat30, 0,
(sy_call_t *)compat_50_netbsd32___lstat30 },
{ NETBSD32_SYS_compat_50_netbsd32___fhstat40, 0,
(sy_call_t *)compat_50_netbsd32___fhstat40 },
{ NETBSD32_SYS_compat_50_netbsd32_wait4, 0,
(sy_call_t *)compat_50_netbsd32_wait4 },
{ NETBSD32_SYS_compat_50_netbsd32_getrusage, 0,
(sy_call_t *)compat_50_netbsd32_getrusage },
{ NETBSD32_SYS_compat_50_netbsd32_setitimer, 0,
(sy_call_t *)compat_50_netbsd32_setitimer },
{ NETBSD32_SYS_compat_50_netbsd32_getitimer, 0,
(sy_call_t *)compat_50_netbsd32_getitimer },
#ifdef NTP
{ NETBSD32_SYS_compat_50_netbsd32_ntp_gettime, 0,
(sy_call_t *)compat_50_netbsd32_ntp_gettime },
#endif
{ 0, 0, NULL }
};
MODULE(MODULE_CLASS_EXEC, compat_netbsd32_50, "compat_netbsd32_60,compat_50");
static int
compat_netbsd32_50_modcmd(modcmd_t cmd, void *arg)
{
int ret;
switch (cmd) {
case MODULE_CMD_INIT:
ret = syscall_establish(&emul_netbsd32,
compat_netbsd32_50_syscalls);
if (ret == 0)
MODULE_HOOK_SET(rnd_ioctl32_50_hook,
compat32_50_rnd_ioctl);
return ret;
case MODULE_CMD_FINI:
ret = syscall_disestablish(&emul_netbsd32,
compat_netbsd32_50_syscalls);
if (ret == 0)
MODULE_HOOK_UNSET(rnd_ioctl32_50_hook);
return ret;
default:
return ENOTTY;
}
}
#endif /* COMPAT_50 */
|