summaryrefslogtreecommitdiff
path: root/sys/compat/linux32/common/linux32_misc.c
blob: 0b4e376ae43b41f5263a4370d7001d71460242ce (plain)
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
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
/*	$NetBSD: linux32_misc.c,v 1.3 2006/07/23 22:06:09 ad Exp $ */

/*-
 * Copyright (c) 2006 Emmanuel Dreyfus, 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.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by Emmanuel Dreyfus
 * 4. The name of the author may not be used to endorse or promote 
 *    products derived from this software without specific prior written 
 *    permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE THE AUTHOR 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 AUTHOR 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: linux32_misc.c,v 1.3 2006/07/23 22:06:09 ad Exp $");

#include <sys/types.h>
#include <sys/param.h>
#include <sys/fstypes.h>
#include <sys/signal.h>
#include <sys/dirent.h>
#include <sys/kernel.h>
#include <sys/fcntl.h>
#include <sys/select.h>
#include <sys/sa.h>
#include <sys/proc.h>
#include <sys/ucred.h>
#include <sys/swap.h>

#include <machine/types.h>

#include <sys/syscallargs.h>

#include <compat/netbsd32/netbsd32.h>
#include <compat/netbsd32/netbsd32_conv.h>
#include <compat/netbsd32/netbsd32_syscallargs.h>

#include <compat/linux/common/linux_types.h>
#include <compat/linux/common/linux_signal.h>
#include <compat/linux/common/linux_machdep.h>
#include <compat/linux/common/linux_misc.h>
#include <compat/linux/common/linux_limit.h>
#include <compat/linux/common/linux_oldolduname.h>
#include <compat/linux/linux_syscallargs.h>

#include <compat/linux32/common/linux32_types.h>
#include <compat/linux32/common/linux32_signal.h>
#include <compat/linux32/common/linux32_machdep.h>
#include <compat/linux32/common/linux32_sysctl.h>
#include <compat/linux32/common/linux32_socketcall.h>
#include <compat/linux32/linux32_syscallargs.h>

static int linux32_select1(struct lwp *, register_t *, 
    int, fd_set *, fd_set *, fd_set *, struct timeval *);

int
linux32_sys_uname(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_uname_args /* {
		syscallarg(linux32_utsnamep) up;
	} */ *uap = v;
	struct linux_utsname luts;
	struct linux_utsname *lp;

	strncpy(luts.l_sysname, linux32_sysname, sizeof(luts.l_sysname));
	strncpy(luts.l_nodename, hostname, sizeof(luts.l_nodename));
	strncpy(luts.l_release, linux32_release, sizeof(luts.l_release));
	strncpy(luts.l_version, linux32_version, sizeof(luts.l_version));
#ifdef LINUX_UNAME_ARCH
	strncpy(luts.l_machine, LINUX_UNAME_ARCH, sizeof(luts.l_machine));
#else  
	strncpy(luts.l_machine, machine, sizeof(luts.l_machine));
#endif 
	strncpy(luts.l_domainname, domainname, sizeof(luts.l_domainname));
       
	lp = (struct linux_utsname *)NETBSD32PTR64(SCARG(uap, up));

        return copyout(&luts, lp, sizeof(luts));
}

int
linux32_sys_open(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_open_args /* {
		syscallarg(const netbsd32_charp) path;
		syscallarg(int) flags;
		syscallarg(int) mode;
	} */ *uap = v;
	struct linux_sys_open_args ua;

	NETBSD32TOP_UAP(path, const char);
	NETBSD32TO64_UAP(flags);
	NETBSD32TO64_UAP(mode);

	return linux_sys_open(l, &ua, retval);
}


int
linux32_sys_brk(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_brk_args /* {
		syscallarg(netbsd32_charp) nsize;
	} */ *uap = v;
	struct linux_sys_brk_args ua;

	NETBSD32TOP_UAP(nsize, char);
	return linux_sys_brk(l, &ua, retval);
}

int
linux32_sys_old_mmap(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_old_mmap_args /* {
		syscallarg(linux32_oldmmapp) lmp;
	} */ *uap = v;
	struct linux_sys_old_mmap_args ua;

	NETBSD32TOP_UAP(lmp, struct linux_oldmmap);
	return linux_sys_old_mmap(l, &ua, retval);

	return 0;
}

int
linux32_sys_mprotect(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{ 
	struct linux32_sys_mprotect_args /* {
		syscallarg(netbsd32_voidp) addr;
		syscallarg(netbsd32_long) len;
		syscallarg(int) prot;
	} */ *uap = v; 
	struct sys_mprotect_args ua;

	NETBSD32TOP_UAP(addr, void);
	NETBSD32TOX_UAP(len, long);
	NETBSD32TO64_UAP(prot);
	return (linux_sys_mprotect(l, &ua, retval));
}

int
linux32_sys_stat64(l, v, retval)  
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_stat64_args /* {  
	        syscallarg(netbsd32_charp) path;
	        syscallarg(linux32_statp) sp;
	} */ *uap = v;
	struct sys___stat30_args ua;
	caddr_t sg = stackgap_init(l->l_proc, 0);
	int error;
	struct stat st;
	struct linux32_stat64 st32;
	struct stat *stp;
	struct linux32_stat64 *st32p;
	
	NETBSD32TOP_UAP(path, const char);

	CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));

	stp = stackgap_alloc(l->l_proc, &sg, sizeof(*stp));
	SCARG(&ua, ub) = stp;
		
	if ((error = sys___stat30(l, &ua, retval)) != 0)
		return error;

	if ((error = copyin(stp, &st, sizeof(st))) != 0)
		return error;
	
	linux32_from_stat(&st, &st32);

	st32p = (struct linux32_stat64 *)(long)SCARG(uap, sp);

	if ((error = copyout(&st32, st32p, sizeof(*st32p))) != 0)
		return error;

	return 0;
}

int
linux32_sys_lstat64(l, v, retval)  
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_lstat64_args /* {  
	        syscallarg(netbsd32_charp) path;
	        syscallarg(linux32_stat64p) sp;
	} */ *uap = v;
	struct sys___lstat30_args ua;
	caddr_t sg = stackgap_init(l->l_proc, 0);
	int error;
	struct stat st;
	struct linux32_stat64 st32;
	struct stat *stp;
	struct linux32_stat64 *st32p;
	
	NETBSD32TOP_UAP(path, const char);

	CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));

	stp = stackgap_alloc(l->l_proc, &sg, sizeof(*stp));
	SCARG(&ua, ub) = stp;
		
	if ((error = sys___lstat30(l, &ua, retval)) != 0)
		return error;

	if ((error = copyin(stp, &st, sizeof(st))) != 0)
		return error;
	
	linux32_from_stat(&st, &st32);

	st32p = (struct linux32_stat64 *)(long)SCARG(uap, sp);

	if ((error = copyout(&st32, st32p, sizeof(*st32p))) != 0)
		return error;

	return 0;
}

int
linux32_sys_fstat64(l, v, retval)  
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_fstat64_args /* {  
	        syscallarg(int) fd;
	        syscallarg(linux32_stat64p) sp;
	} */ *uap = v;
	struct sys___fstat30_args ua;
	caddr_t sg = stackgap_init(l->l_proc, 0);
	int error;
	struct stat st;
	struct linux32_stat64 st32;
	struct stat *stp;
	struct linux32_stat64 *st32p;
	
	NETBSD32TO64_UAP(fd);

	stp = stackgap_alloc(l->l_proc, &sg, sizeof(*stp));
	SCARG(&ua, sb) = stp;
		
	if ((error = sys___fstat30(l, &ua, retval)) != 0)
		return error;

	if ((error = copyin(stp, &st, sizeof(st))) != 0)
		return error;
	
	linux32_from_stat(&st, &st32);

	st32p = (struct linux32_stat64 *)(long)SCARG(uap, sp);

	if ((error = copyout(&st32, st32p, sizeof(*st32p))) != 0)
		return error;

	return 0;
}

int
linux32_sys_access(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_access_args /* {
		syscallarg(const netbsd32_charp) path;
		syscallarg(int) flags;
	} */ *uap = v;
	struct sys_access_args ua;
	caddr_t sg;

	NETBSD32TOP_UAP(path, const char);
	NETBSD32TO64_UAP(flags);

	sg = stackgap_init(l->l_proc, 0);
	CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));

	return sys_access(l, &ua, retval);
}

int
linux32_sys_getrlimit(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_getrlimit_args /* {
		syscallarg(int) which;
		syscallarg(netbsd32_orlimitp_t) rlp;
	} */ *uap = v;
	struct proc *p = l->l_proc;
	caddr_t sg = stackgap_init(p, 0);
	struct sys_getrlimit_args ap;
	struct orlimit orl;
	struct rlimit rl;
	int error;

	SCARG(&ap, which) = linux_to_bsd_limit(SCARG(uap, which));
	if ((error = SCARG(&ap, which)) < 0)
		return -error;

	SCARG(&ap, rlp) = stackgap_alloc(p, &sg, sizeof rl);

	if ((error = sys_getrlimit(l, &ap, retval)) != 0)
		return error;

	if ((error = copyin(SCARG(&ap, rlp), &rl, sizeof(rl))) != 0)
		return error;

	bsd_to_linux_rlimit(&orl, &rl);

	return copyout(&orl, NETBSD32PTR64(SCARG(uap, rlp)), sizeof(orl));
}

int
linux32_sys_setrlimit(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_setrlimit_args /* {
		syscallarg(int) which;
		syscallarg(netbsd32_orlimitp_t) rlp;
	} */ *uap = v;
	struct proc *p = l->l_proc;
	caddr_t sg = stackgap_init(p, 0);
	struct sys_getrlimit_args ap;
	struct rlimit rl;
	struct orlimit orl;
	int error;

	SCARG(&ap, which) = linux_to_bsd_limit(SCARG(uap, which));
	SCARG(&ap, rlp) = stackgap_alloc(p, &sg, sizeof rl);
	if ((error = SCARG(&ap, which)) < 0)
		return -error;

	if ((error = copyin(NETBSD32PTR64(SCARG(uap, rlp)), 
	    &orl, sizeof(orl))) != 0)
		return error;

	linux_to_bsd_rlimit(&rl, &orl);

	if ((error = copyout(&rl, SCARG(&ap, rlp), sizeof(rl))) != 0)
		return error;

	return sys_setrlimit(l, &ap, retval);
}

#if defined(__amd64__)
int
linux32_sys_ugetrlimit(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	return linux32_sys_getrlimit(l, v, retval);
}
#endif

extern struct timezone linux_sys_tz;
int
linux32_sys_gettimeofday(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_gettimeofday_args /* {
		syscallarg(netbsd32_timevalp_t) tp;
		syscallarg(netbsd32_timezonep_t) tzp;
	} */ *uap = v;
	struct timeval tv;
	struct netbsd32_timeval tv32;
	int error;

	if (NETBSD32PTR64(SCARG(uap, tp)) != NULL) {
		microtime(&tv);
		netbsd32_from_timeval(&tv, &tv32);
		if ((error = copyout(&tv32, 
		    (caddr_t)NETBSD32PTR64(SCARG(uap, tp)), 
		    sizeof(tv32))) != 0)
			return error;
	}

	/* timezone size does not change */
	if (NETBSD32PTR64(SCARG(uap, tzp)) != NULL) {
		if ((error = copyout(&linux_sys_tz,
		    (caddr_t)NETBSD32PTR64(SCARG(uap, tzp)), 
		    sizeof(linux_sys_tz))) != 0)
			return error;
	}

	return 0;
}

int
linux32_sys_settimeofday(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_settimeofday_args /* {
		syscallarg(netbsd32_timevalp_t) tp;
		syscallarg(netbsd32_timezonep_t) tzp;
	} */ *uap = v;
	struct linux_sys_settimeofday_args ua;

	NETBSD32TOP_UAP(tp, struct timeval);
	NETBSD32TOP_UAP(tzp, struct timezone);

	return linux_sys_settimeofday(l, &ua, retval);
}

int
linux32_sys_fcntl64(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_fcntl64_args /* {
		syscallcarg(int) fd;
                syscallarg(int) cmd;
		syscallarg(netbsd32_voidp) arg; 
	} */ *uap = v;
	struct linux_sys_fcntl64_args ua;

	NETBSD32TO64_UAP(fd);
	NETBSD32TO64_UAP(cmd);
	NETBSD32TOP_UAP(arg, void);

	return linux_sys_fcntl64(l, &ua, retval);
}

int
linux32_sys_fcntl(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_fcntl_args /* {
		syscallcarg(int) fd;
                syscallarg(int) cmd;
		syscallarg(netbsd32_voidp) arg; 
	} */ *uap = v;
	struct linux_sys_fcntl_args ua;

	NETBSD32TO64_UAP(fd);
	NETBSD32TO64_UAP(cmd);
	NETBSD32TOP_UAP(arg, void);

	return linux_sys_fcntl(l, &ua, retval);
}

int
linux32_sys_llseek(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_llseek_args /* {
		syscallcarg(int) fd;
                syscallarg(u_int32_t) ohigh;
                syscallarg(u_int32_t) olow;
		syscallarg(netbsd32_caddr_t) res;
		syscallcarg(int) whence;
	} */ *uap = v;
	struct linux_sys_llseek_args ua;

	NETBSD32TO64_UAP(fd);
	NETBSD32TO64_UAP(ohigh);
	NETBSD32TO64_UAP(olow);
	NETBSD32TOP_UAP(res, char);
	NETBSD32TO64_UAP(whence);

	return linux_sys_llseek(l, &ua, retval);
}


int
linux32_sys_time(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_time_args /* {
		syscallcarg(linux32_timep_t) t;
	} */ *uap = v;
	struct linux_sys_time_args ua;

	NETBSD32TOP_UAP(t, linux_time_t);

	return linux_sys_time(l, &ua, retval);
}


int
linux32_sys_getdents(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_getdents_args /* {
		syscallcarg(int) fd;
		syscallcarg(linux32_direntp_t) dent;
		syscallcarg(unsigned int) count;
	} */ *uap = v;
	struct linux_sys_getdents_args ua;

	NETBSD32TO64_UAP(fd);
	NETBSD32TOP_UAP(dent, struct linux_dirent);
	NETBSD32TO64_UAP(count);

	return linux_sys_getdents(l, &ua, retval);
}


int
linux32_sys_getdents64(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_getdents64_args /* {
		syscallcarg(int) fd;
		syscallcarg(linux32_dirent64p_t) dent;
		syscallcarg(unsigned int) count;
	} */ *uap = v;
	struct linux_sys_getdents64_args ua;

	NETBSD32TO64_UAP(fd);
	NETBSD32TOP_UAP(dent, struct linux_dirent64);
	NETBSD32TO64_UAP(count);

	return linux_sys_getdents64(l, &ua, retval);
}

int
linux32_sys_socketpair(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_socketpair_args /* {
		syscallarg(int) domain;
		syscallarg(int) type;
		syscallarg(int) protocol;
		syscallarg(netbsd32_intp) rsv;
	} */ *uap = v;
	struct linux_sys_socketpair_args ua;

	NETBSD32TO64_UAP(domain);
	NETBSD32TO64_UAP(type);
	NETBSD32TO64_UAP(protocol);
	NETBSD32TOP_UAP(rsv, int)

	return linux_sys_socketpair(l, &ua, retval);
}

int
linux32_sys_sendto(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_sendto_args /* {
		syscallarg(int) s;
		syscallarg(netbsd32_voidp) msg; 
		syscallarg(int) len;
		syscallarg(int) flags;
		syscallarg(netbsd32_osockaddrp_t) to;
		syscallarg(int) tolen;
	} */ *uap = v;
	struct linux_sys_sendto_args ua;

	NETBSD32TO64_UAP(s);
	NETBSD32TOP_UAP(msg, void);
	NETBSD32TO64_UAP(len);
	NETBSD32TO64_UAP(flags);
	NETBSD32TOP_UAP(to, struct osockaddr);
	NETBSD32TO64_UAP(tolen);

	return linux_sys_sendto(l, &ua, retval);
}


int
linux32_sys_recvfrom(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_recvfrom_args /* {
		syscallarg(int) s;
		syscallarg(netbsd32_voidp) buf; 
		syscallarg(netbsd32_size_t) len;
		syscallarg(int) flags;
		syscallarg(netbsd32_osockaddrp_t) from;
		syscallarg(netbsd32_intp) fromlenaddr;
	} */ *uap = v;
	struct linux_sys_recvfrom_args ua;

	NETBSD32TO64_UAP(s);
	NETBSD32TOP_UAP(buf, void);
	NETBSD32TO64_UAP(len);
	NETBSD32TO64_UAP(flags);
	NETBSD32TOP_UAP(from, struct osockaddr);
	NETBSD32TOP_UAP(fromlenaddr, unsigned int);

	return linux_sys_recvfrom(l, &ua, retval);
}

int
linux32_sys_setsockopt(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_setsockopt_args /* {
		syscallarg(int) s;
		syscallarg(int) level;
		syscallarg(int) optname;
		syscallarg(netbsd32_voidp) optval;
		syscallarg(int) optlen;
	} */ *uap = v;
	struct linux_sys_setsockopt_args ua;

	NETBSD32TO64_UAP(s);
	NETBSD32TO64_UAP(level);
	NETBSD32TO64_UAP(optname);
	NETBSD32TOP_UAP(optval, void);
	NETBSD32TO64_UAP(optlen);

	return linux_sys_setsockopt(l, &ua, retval);
}


int
linux32_sys_getsockopt(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_getsockopt_args /* {
		syscallarg(int) s;
		syscallarg(int) level;
		syscallarg(int) optname;
		syscallarg(netbsd32_voidp) optval;
		syscallarg(netbsd32_intp) optlen;
	} */ *uap = v;
	struct linux_sys_getsockopt_args ua;

	NETBSD32TO64_UAP(s);
	NETBSD32TO64_UAP(level);
	NETBSD32TO64_UAP(optname);
	NETBSD32TOP_UAP(optval, void);
	NETBSD32TOP_UAP(optlen, int);

	return linux_sys_getsockopt(l, &ua, retval);
}

int
linux32_sys_socket(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_socket_args /* {
		syscallarg(int) domain;
		syscallarg(int) type;
		syscallarg(int) protocol;
	} */ *uap = v;
	struct linux_sys_socket_args ua;

	NETBSD32TO64_UAP(domain);
	NETBSD32TO64_UAP(type);
	NETBSD32TO64_UAP(protocol);

	return linux_sys_socket(l, &ua, retval);
}

int
linux32_sys_bind(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_bind_args /* {
		syscallarg(int) s;
		syscallarg(netbsd32_osockaddrp_t) name;
		syscallarg(int) namelen;
	} */ *uap = v;
	struct linux_sys_bind_args ua;

	NETBSD32TO64_UAP(s);
	NETBSD32TOP_UAP(name, struct osockaddr)
	NETBSD32TO64_UAP(namelen);

	return linux_sys_bind(l, &ua, retval);
}

int
linux32_sys_connect(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_connect_args /* {
		syscallarg(int) s;
		syscallarg(netbsd32_osockaddrp_t) name;
		syscallarg(int) namelen;
	} */ *uap = v;
	struct linux_sys_connect_args ua;

	NETBSD32TO64_UAP(s);
	NETBSD32TOP_UAP(name, struct osockaddr)
	NETBSD32TO64_UAP(namelen);

	printf("linux32_sys_connect: s = %d, name = %p, namelen = %d\n",
		SCARG(&ua, s), SCARG(&ua, name), SCARG(&ua, namelen));

	return linux_sys_connect(l, &ua, retval);
}

int
linux32_sys_accept(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_accept_args /* {
		syscallarg(int) s;
		syscallarg(netbsd32_osockaddrp_t) name;
		syscallarg(netbsd32_intp) anamelen;
	} */ *uap = v;
	struct linux_sys_accept_args ua;

	NETBSD32TO64_UAP(s);
	NETBSD32TOP_UAP(name, struct osockaddr)
	NETBSD32TOP_UAP(anamelen, int);

	return linux_sys_accept(l, &ua, retval);
}

int
linux32_sys_getpeername(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_getpeername_args /* {
		syscallarg(int) fdes;
		syscallarg(netbsd32_sockaddrp_t) asa;
		syscallarg(netbsd32_intp) alen;
	} */ *uap = v;
	struct linux_sys_getpeername_args ua;

	NETBSD32TO64_UAP(fdes);
	NETBSD32TOP_UAP(asa, struct sockaddr)
	NETBSD32TOP_UAP(alen, int);

	return linux_sys_getpeername(l, &ua, retval);
}

int
linux32_sys_getsockname(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_getsockname_args /* {
		syscallarg(int) fdec;
		syscallarg(netbsd32_charp) asa;
		syscallarg(netbsd32_intp) alen;
	} */ *uap = v;
	struct linux_sys_getsockname_args ua;

	NETBSD32TO64_UAP(fdec);
	NETBSD32TOP_UAP(asa, char)
	NETBSD32TOP_UAP(alen, int);

	return linux_sys_getsockname(l, &ua, retval);
}

int
linux32_sys_sendmsg(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_sendmsg_args /* {
		syscallarg(int) s;
		syscallarg(netbsd32_msghdrp_t) msg;
		syscallarg(int) flags;
	} */ *uap = v;
	struct linux_sys_sendmsg_args ua;

	NETBSD32TO64_UAP(s);
	NETBSD32TOP_UAP(msg, struct msghdr);
	NETBSD32TO64_UAP(flags);

	return linux_sys_sendmsg(l, &ua, retval);
}

int
linux32_sys_recvmsg(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_recvmsg_args /* {
		syscallarg(int) s;
		syscallarg(netbsd32_msghdrp_t) msg;
		syscallarg(int) flags;
	} */ *uap = v;
	struct linux_sys_recvmsg_args ua;

	NETBSD32TO64_UAP(s);
	NETBSD32TOP_UAP(msg, struct msghdr);
	NETBSD32TO64_UAP(flags);

	return linux_sys_recvmsg(l, &ua, retval);
}

int
linux32_sys_send(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_send_args /* {
		syscallarg(int) s;
		syscallarg(netbsd32_voidp) buf;
		syscallarg(int) len;
		syscallarg(int) flags;
	} */ *uap = v;
	struct sys_sendto_args ua;

	NETBSD32TO64_UAP(s);
	NETBSD32TOP_UAP(buf, void);
	NETBSD32TO64_UAP(len);
	NETBSD32TO64_UAP(flags);
	SCARG(&ua, to) = NULL;
	SCARG(&ua, tolen) = 0;

	return sys_sendto(l, &ua, retval);
}

int
linux32_sys_recv(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_recv_args /* {
		syscallarg(int) s;
		syscallarg(netbsd32_voidp) buf;
		syscallarg(int) len;
		syscallarg(int) flags;
	} */ *uap = v;
	struct sys_recvfrom_args ua;

	NETBSD32TO64_UAP(s);
	NETBSD32TOP_UAP(buf, void);
	NETBSD32TO64_UAP(len);
	NETBSD32TO64_UAP(flags);
	SCARG(&ua, from) = NULL;
	SCARG(&ua, fromlenaddr) = NULL;

	return sys_recvfrom(l, &ua, retval);
}

int
linux32_sys_readlink(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_readlink_args /* {
		syscallarg(const netbsd32_charp) name;
		syscallarg(netbsd32_charp) buf;
		syscallarg(int) count;
	} */ *uap = v;
	struct linux_sys_readlink_args ua;

	NETBSD32TOP_UAP(name, const char);
	NETBSD32TOP_UAP(buf, char)
	NETBSD32TO64_UAP(count);

	return linux_sys_readlink(l, &ua, retval);
}


int
linux32_sys_select(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_select_args /* {
		syscallarg(int) nfds;
		syscallarg(netbsd32_fd_setp_t) readfds;
		syscallarg(netbsd32_fd_setp_t) writefds;
		syscallarg(netbsd32_fd_setp_t) exceptfds;
		syscallarg(netbsd32_timevalp_t) timeout;
	} */ *uap = v;

	return linux32_select1(l, retval, SCARG(uap, nfds), 
	    NETBSD32PTR64(SCARG(uap, readfds)),
	    NETBSD32PTR64(SCARG(uap, writefds)), 
	    NETBSD32PTR64(SCARG(uap, exceptfds)), 
	    NETBSD32PTR64(SCARG(uap, timeout)));
}

int
linux32_sys_oldselect(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_oldselect_args /* {
		syscallarg(linux32_oldselectp_t) lsp;
	} */ *uap = v;
	struct linux32_oldselect lsp32;
	int error;

	if ((error = copyin(NETBSD32PTR64(SCARG(uap, lsp)), 
	    &lsp32, sizeof(lsp32))) != 0)
		return error;

	return linux32_select1(l, retval, lsp32.nfds, 
	     NETBSD32PTR64(lsp32.readfds), NETBSD32PTR64(lsp32.writefds),
	     NETBSD32PTR64(lsp32.exceptfds), NETBSD32PTR64(lsp32.timeout));
}

static int
linux32_select1(l, retval, nfds, readfds, writefds, exceptfds, timeout)
        struct lwp *l;
        register_t *retval;
        int nfds;
        fd_set *readfds, *writefds, *exceptfds;
        struct timeval *timeout;
{   
	struct timeval tv0, tv1, utv, otv;
	struct netbsd32_timeval utv32;
	int error;

	/*
	 * Store current time for computation of the amount of
	 * time left.
	 */
	if (timeout) {
		if ((error = copyin(timeout, &utv32, sizeof(utv32))))
			return error;

		netbsd32_to_timeval(&utv32, &utv);
		otv = utv;

		if (itimerfix(&utv)) {
			/*
			 * The timeval was invalid.  Convert it to something
			 * valid that will act as it does under Linux.
			 */
			utv.tv_sec += utv.tv_usec / 1000000;
			utv.tv_usec %= 1000000;
			if (utv.tv_usec < 0) {
				utv.tv_sec -= 1;
				utv.tv_usec += 1000000;
			}
			if (utv.tv_sec < 0)
				timerclear(&utv);
		}
		microtime(&tv0);
	} else {
		timerclear(&utv);
	}

	error = selcommon(l, retval, nfds, 
	    readfds, writefds, exceptfds, &utv, NULL);

	if (error) {
		/*
		 * See fs/select.c in the Linux kernel.  Without this,
		 * Maelstrom doesn't work.
		 */
		if (error == ERESTART)
			error = EINTR;
		return error;
	}

	if (timeout) {
		if (*retval) {
			/*
			 * Compute how much time was left of the timeout,
			 * by subtracting the current time and the time
			 * before we started the call, and subtracting
			 * that result from the user-supplied value.
			 */
			microtime(&tv1);
			timersub(&tv1, &tv0, &tv1);
			timersub(&otv, &tv1, &utv);
			if (utv.tv_sec < 0)
				timerclear(&utv);
		} else {
			timerclear(&utv);
		}
		
		netbsd32_from_timeval(&utv, &utv32);

		if ((error = copyout(&utv32, timeout, sizeof(utv32))))
			return error;
	}

	return 0;
}

int
linux32_sys_pipe(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_pipe_args /* {
		syscallarg(netbsd32_intp) fd;
	} */ *uap = v;
	int error;
	int pfds[2];

	if ((error = sys_pipe(l, 0, retval)))
		return error;

	pfds[0] = (int)retval[0];
	pfds[1] = (int)retval[1];

	if ((error = copyout(pfds, NETBSD32PTR64(SCARG(uap, fd)), 
	    2 * sizeof (int))) != 0)
		return error;

	retval[0] = 0;
	retval[1] = 0;

	return 0;
}


int
linux32_sys_times(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_times_args /* {
		syscallarg(linux32_tmsp_t) tms;
	} */ *uap = v;
	struct linux32_tms ltms32;
	struct linux_tms ltms;
	struct linux_tms *ltmsp;
	struct linux_sys_times_args ua;
	caddr_t sg = stackgap_init(l->l_proc, 0);
	int error;

	ltmsp = stackgap_alloc(l->l_proc, &sg, sizeof(*ltmsp));
	SCARG(&ua, tms) = (struct times *)ltmsp;

	if ((error = linux_sys_times(l, &ua, retval)) != 0)
		return error;

	if ((error = copyin(ltmsp, &ltms, sizeof(ltms))) != 0)
		return error;

	ltms32.ltms32_utime = (linux32_clock_t)ltms.ltms_utime;
	ltms32.ltms32_stime = (linux32_clock_t)ltms.ltms_stime;
	ltms32.ltms32_cutime = (linux32_clock_t)ltms.ltms_cutime;
	ltms32.ltms32_cstime = (linux32_clock_t)ltms.ltms_cstime;

	if ((error = copyout(&ltms32, 
	    NETBSD32PTR64(SCARG(uap, tms)), sizeof(ltms32))) != 0)
		return error;

	return 0;
}

int
linux32_sys_clone(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_clone_args /* {
		syscallarg(int) flags;
		syscallarg(netbsd32_voidp) stack;
	} */ *uap = v;
	struct linux_sys_clone_args ua;
	
	NETBSD32TO64_UAP(flags);
	NETBSD32TOP_UAP(stack, void *);
#ifdef LINUX_NPTL
	SCARG(&ua, parent_tidptr) = NULL;
	SCARG(&ua, child_tidptr) = NULL;
#endif

	return linux_sys_clone(l, &ua, retval);
}

int
linux32_sys_sched_setscheduler(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_sched_setscheduler_args /* {
		syscallarg(int) pid;
		syscallarg(int) policy;
		syscallarg(const linux32_sched_paramp_t) sp;
	} */ *uap = v;
	struct linux_sys_sched_setscheduler_args ua;

	NETBSD32TO64_UAP(pid);
	NETBSD32TO64_UAP(policy);
	NETBSD32TOP_UAP(sp, const struct linux_sched_param);

	return linux_sys_sched_setscheduler(l, &ua, retval);
}


int
linux32_sys_waitpid(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_waitpid_args /* {
		syscallarg(int) pid;
		syscallarg(netbsd32_intp) status;
		syscallarg(int) options;
	} */ *uap = v;
	struct linux_sys_wait4_args ua;

	SCARG(&ua, pid) = SCARG(uap, pid);
	SCARG(&ua, status) = NETBSD32PTR64(SCARG(uap, status));
	SCARG(&ua, options) = SCARG(uap, options);
	SCARG(&ua, rusage) = NULL;

	return linux_sys_wait4(l, &ua, retval);	
}

int
linux32_sys_wait4(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_wait4_args /* {
		syscallarg(int) pid;
		syscallarg(netbsd32_intp) status;
		syscallarg(int) options;
		syscallarg(netbsd32_rusagep_t) rusage;
	} */ *uap = v;
	struct linux_sys_wait4_args ua;

	NETBSD32TO64_UAP(pid);
	NETBSD32TOP_UAP(status, int);
	NETBSD32TO64_UAP(options);
	NETBSD32TOP_UAP(rusage, struct rusage);

	return linux_sys_wait4(l, &ua, retval);	
}

int
linux32_sys_unlink(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_unlink_args /* {
		syscallarg(const netbsd32_charp) path;
	} */ *uap = v;
	struct linux_sys_unlink_args ua;

	NETBSD32TOP_UAP(path, const char);
	
	return linux_sys_unlink(l, &ua, retval);
}

int
linux32_sys_chdir(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_chdir_args /* {
		syscallarg(const netbsd32_charp) path;
	} */ *uap = v;
	struct sys_chdir_args ua;
	caddr_t sg = stackgap_init(l->l_proc, 0);

	NETBSD32TOP_UAP(path, const char);

	CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));
	
	return sys_chdir(l, &ua, retval);
}

int
linux32_sys_link(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_link_args /* {
		syscallarg(const netbsd32_charp) path;
		syscallarg(const netbsd32_charp) link;
	} */ *uap = v;
	struct sys_link_args ua;
	caddr_t sg = stackgap_init(l->l_proc, 0);

	NETBSD32TOP_UAP(path, const char);
	NETBSD32TOP_UAP(link, const char);

	CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));
	CHECK_ALT_CREAT(l, &sg, SCARG(&ua, link));
	
	return sys_link(l, &ua, retval);
}

int
linux32_sys_creat(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_creat_args /* {
		syscallarg(const netbsd32_charp) path;
		syscallarg(int) mode;
	} */ *uap = v;
	struct sys_open_args ua;
	caddr_t sg = stackgap_init(l->l_proc, 0);

	NETBSD32TOP_UAP(path, const char);
	SCARG(&ua, flags) = O_CREAT | O_TRUNC | O_WRONLY;
	NETBSD32TO64_UAP(mode);

	CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));

	return sys_open(l, &ua, retval);
}

int
linux32_sys_mknod(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_mknod_args /* {
		syscallarg(const netbsd32_charp) path;
		syscallarg(int) mode;
		syscallarg(int) dev;
	} */ *uap = v;
	struct linux_sys_mknod_args ua;

	NETBSD32TOP_UAP(path, const char);
	NETBSD32TO64_UAP(mode);
	NETBSD32TO64_UAP(dev);

	return linux_sys_mknod(l, &ua, retval);
}

int
linux32_sys_chmod(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_chmod_args /* {
		syscallarg(const netbsd32_charp) path;
		syscallarg(int) mode;
	} */ *uap = v;
	struct sys_chmod_args ua;
	caddr_t sg = stackgap_init(l->l_proc, 0);

	NETBSD32TOP_UAP(path, const char);
	NETBSD32TO64_UAP(mode);

	CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));

	return sys_chmod(l, &ua, retval);
}

int
linux32_sys_lchown16(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_lchown16_args /* {
		syscallarg(const netbsd32_charp) path;
		syscallarg(int) uid;
		syscallarg(int) gid;
	} */ *uap = v;
        struct sys___posix_lchown_args ua;
        caddr_t sg = stackgap_init(l->l_proc, 0);

	NETBSD32TOP_UAP(path, const char);
        CHECK_ALT_SYMLINK(l, &sg, SCARG(&ua, path));

        if ((linux32_uid_t)SCARG(uap, uid) == (linux32_uid_t)-1)
        	SCARG(&ua, uid) = (uid_t)-1;
	else
        	SCARG(&ua, uid) = SCARG(uap, uid);

        if ((linux32_gid_t)SCARG(uap, gid) == (linux32_gid_t)-1)
        	SCARG(&ua, gid) = (gid_t)-1;
	else
        	SCARG(&ua, gid) = SCARG(uap, gid);
       
        return sys___posix_lchown(l, &ua, retval);
}

int
linux32_sys_break(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
#if 0
	struct linux32_sys_break_args /* {
		syscallarg(const netbsd32_charp) nsize;
	} */ *uap = v;
#endif

	return ENOSYS;
}

int
linux32_sys_stime(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_stime_args /* {
		syscallarg(linux32_timep_t) t;
	} */ *uap = v;
	struct timespec ts;
	linux32_time_t tt32;
	int error;
	
	if ((error = kauth_authorize_generic(l->l_cred,
	    KAUTH_GENERIC_ISSUSER, &l->l_acflag)) != 0)
		return error;

	if ((error = copyin(&tt32, 
	    NETBSD32PTR64(SCARG(uap, t)), 
	    sizeof tt32)) != 0)

	ts.tv_sec = (long)tt32;
	ts.tv_nsec = 0;

	return settime(l->l_proc, &ts);
}

int
linux32_sys_utime(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_utime_args /* {
		syscallarg(const netbsd32_charp) path;
		syscallarg(linux32_utimbufp_t) times;
	} */ *uap = v;
	struct proc *p = l->l_proc;
        caddr_t sg = stackgap_init(p, 0);
        struct sys_utimes_args ua;
        struct timeval tv[2], *tvp;
        struct linux32_utimbuf lut;
        int error;

	NETBSD32TOP_UAP(path, const char);
        CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));


        if (NETBSD32PTR64(SCARG(uap, times)) != NULL) {
                if ((error = copyin(NETBSD32PTR64(SCARG(uap, times)), 
		    &lut, sizeof lut)))
                        return error;

                tv[0].tv_sec = (long)lut.l_actime;
                tv[0].tv_usec = 0;
                tv[1].tv_sec = (long)lut.l_modtime;
		tv[1].tv_usec = 0;

	        tvp = (struct timeval *) stackgap_alloc(p, &sg, sizeof(tv));

                if ((error = copyout(tv, tvp, sizeof(tv))))
                        return error;
                SCARG(&ua, tptr) = tvp;
        } else {
               SCARG(&ua, tptr) = NULL;
	}
                     
        return sys_utimes(l, &ua, retval);
} 

int
linux32_sys_rename(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_rename_args /* {
		syscallarg(const netbsd32_charp) from;
		syscallarg(const netbsd32_charp) to;
	} */ *uap = v;
	struct sys_rename_args ua;
	caddr_t sg = stackgap_init(l->l_proc, 0);

	NETBSD32TOP_UAP(from, const char);
	NETBSD32TOP_UAP(to, const char);

	CHECK_ALT_EXIST(l, &sg, SCARG(&ua, from));
	CHECK_ALT_CREAT(l, &sg, SCARG(&ua, to));
	
	return sys___posix_rename(l, &ua, retval);
}

int
linux32_sys_mkdir(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_mkdir_args /* {
		syscallarg(const netbsd32_charp) path;
		syscallarg(int) mode;
	} */ *uap = v;
	struct sys_mkdir_args ua;
	caddr_t sg = stackgap_init(l->l_proc, 0);

	NETBSD32TOP_UAP(path, const char);
	NETBSD32TO64_UAP(mode);

	CHECK_ALT_CREAT(l, &sg, SCARG(&ua, path));
	
	return sys_mkdir(l, &ua, retval);
}

int
linux32_sys_rmdir(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_rmdir_args /* {
		syscallarg(const netbsd32_charp) path;
	} */ *uap = v;
	struct sys_rmdir_args ua;
	caddr_t sg = stackgap_init(l->l_proc, 0);

	NETBSD32TOP_UAP(path, const char);

	CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));
	
	return sys_rmdir(l, &ua, retval);
}

int
linux32_sys_signal(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_signal_args /* {
		syscallarg(int) signum;
		syscallarg(linux32_handler_t) handler;
	} */ *uap = v;
        struct proc *p = l->l_proc;
        struct sigaction nbsa, obsa;
        int error, sig;

        *retval = -1;

        sig = SCARG(uap, signum);
        if (sig < 0 || sig >= LINUX32__NSIG)
                return EINVAL;

        nbsa.sa_handler = NETBSD32PTR64(SCARG(uap, handler));
        sigemptyset(&nbsa.sa_mask);
        nbsa.sa_flags = SA_RESETHAND | SA_NODEFER;

        if ((error = sigaction1(p, linux32_to_native_signo[sig],
            &nbsa, &obsa, NULL, 0)) != 0)
		return error;

        *retval = (int)(long)obsa.sa_handler;
        return 0;
}

int   
linux32_sys_oldolduname(l, v, retval)
        struct lwp *l;
        void *v;
        register_t *retval;
{
        struct linux32_sys_uname_args /* {
                syscallarg(linux32_oldoldutsnamep_t) up;
        } */ *uap = v; 
        struct linux_oldoldutsname luts;
 
        strncpy(luts.l_sysname, linux32_sysname, sizeof(luts.l_sysname));
        strncpy(luts.l_nodename, hostname, sizeof(luts.l_nodename));
        strncpy(luts.l_release, linux32_release, sizeof(luts.l_release));
        strncpy(luts.l_version, linux32_version, sizeof(luts.l_version));
        strncpy(luts.l_machine, machine, sizeof(luts.l_machine));
 
        return copyout(&luts, NETBSD32PTR64(SCARG(uap, up)), sizeof(luts));
}

int
linux32_sys_getgroups16(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_getgroups16_args /* {
		syscallarg(int) gidsetsize;
		syscallarg(linux32_gidp_t) gidset;
	} */ *uap = v;
	struct linux_sys_getgroups16_args ua;

	NETBSD32TO64_UAP(gidsetsize);
	NETBSD32TOP_UAP(gidset, linux32_gid_t);
	
	return linux_sys_getgroups16(l, &ua, retval);
}

int
linux32_sys_setgroups16(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_setgroups16_args /* {
		syscallarg(int) gidsetsize;
		syscallarg(linux32_gidp_t) gidset;
	} */ *uap = v;
	struct linux_sys_setgroups16_args ua;

	NETBSD32TO64_UAP(gidsetsize);
	NETBSD32TOP_UAP(gidset, linux32_gid_t);
	
	return linux_sys_setgroups16(l, &ua, retval);
}

int
linux32_sys_symlink(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_symlink_args /* {
		syscallarg(const netbsd32_charp) path;
		syscallarg(const netbsd32_charp) link;
	} */ *uap = v;
	struct sys_symlink_args ua;
	caddr_t sg = stackgap_init(l->l_proc, 0);

	NETBSD32TOP_UAP(path, const char);
	NETBSD32TOP_UAP(link, const char);

	CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));
	CHECK_ALT_CREAT(l, &sg, SCARG(&ua, link));
	
	return sys_symlink(l, &ua, retval);
}


int
linux32_sys_swapon(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_swapon_args /* {
		syscallarg(const netbsd32_charp) name;
	} */ *uap = v;
	struct sys_swapctl_args ua;

        SCARG(&ua, cmd) = SWAP_ON;
        SCARG(&ua, arg) = (void *)__UNCONST(NETBSD32PTR64(SCARG(uap, name)));
        SCARG(&ua, misc) = 0;   /* priority */
        return (sys_swapctl(l, &ua, retval));
}

int
linux32_sys_swapoff(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_swapoff_args /* {
		syscallarg(const netbsd32_charp) path;
	} */ *uap = v;
	struct sys_swapctl_args ua;

        SCARG(&ua, cmd) = SWAP_OFF;
        SCARG(&ua, arg) = (void *)__UNCONST(NETBSD32PTR64(SCARG(uap, path)));
        SCARG(&ua, misc) = 0;   /* priority */
        return (sys_swapctl(l, &ua, retval));
}


int
linux32_sys_reboot(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_reboot_args /* {
		syscallarg(int) magic1;
		syscallarg(int) magic2;
		syscallarg(int) cmd;
		syscallarg(netbsd32_voidp) arg;
	} */ *uap = v;
	struct linux_sys_reboot_args ua;

	NETBSD32TO64_UAP(magic1);
	NETBSD32TO64_UAP(magic2);
	NETBSD32TO64_UAP(cmd);
	NETBSD32TOP_UAP(arg, void);
	
	return linux_sys_reboot(l, &ua, retval);
}

int
linux32_sys_truncate(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_truncate_args /* {
		syscallarg(const netbsd32_charp) path;
		syscallarg(netbsd32_charp) buf;
		syscallarg(int) count;
	} */ *uap = v;
	struct compat_43_sys_truncate_args ua;

	NETBSD32TOP_UAP(path, const char);
	NETBSD32TO64_UAP(length);

	return compat_43_sys_truncate(l, &ua, retval);
}

int
linux32_sys_fchown16(l, v, retval)
	struct lwp *l;
	void *v;
	register_t *retval;
{
	struct linux32_sys_fchown16_args /* {
		syscallarg(int) fd;
		syscallarg(int) uid;
		syscallarg(int) gid;
	} */ *uap = v;
        struct sys___posix_fchown_args ua;

	SCARG(&ua, fd) = SCARG(uap, fd);

        if ((linux32_uid_t)SCARG(uap, uid) == (linux32_uid_t)-1)
        	SCARG(&ua, uid) = (uid_t)-1;
	else
        	SCARG(&ua, uid) = SCARG(uap, uid);

        if ((linux32_gid_t)SCARG(uap, gid) == (linux32_gid_t)-1)
        	SCARG(&ua, gid) = (gid_t)-1;
	else
        	SCARG(&ua, gid) = SCARG(uap, gid);
       
        return sys___posix_fchown(l, &ua, retval);
}