Linux preempt-rt

Check our new training course

Real-Time Linux with PREEMPT_RT

Check our new training course
with Creative Commons CC-BY-SA
lecture and lab materials

Bootlin logo

Elixir Cross Referencer

   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
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
/* $Id: sys_sparc32.c,v 1.12 1997/05/14 14:50:58 jj Exp $
 * sys_sparc32.c: Conversion between 32bit and 64bit native syscalls.
 *
 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
 *
 * These routines maintain argument size conversion between 32bit and 64bit
 * environment.
 */

#include <linux/kernel.h>
#include <linux/fs.h> 
#include <linux/signal.h>
#include <linux/utime.h>
#include <linux/resource.h>
#include <linux/sched.h>
#include <linux/times.h>
#include <linux/utime.h>
#include <linux/utsname.h>
#include <linux/timex.h>
#include <linux/smp.h>
#include <linux/smp_lock.h>
#include <linux/sem.h>
#include <linux/msg.h>
#include <linux/shm.h>
#include <linux/malloc.h>
#include <linux/uio.h>
#include <linux/nfs_fs.h>
#include <linux/smb_fs.h>
#include <linux/ncp_fs.h>
#include <linux/quota.h>

#include <asm/types.h>
#include <asm/poll.h>
#include <asm/ipc.h>
#include <asm/uaccess.h>

/* As gcc will warn about casting u32 to some ptr, we have to cast it to unsigned long first, and that's what is A() for.
 * You just do (void *)A(x), instead of having to type (void *)((unsigned long)x) or instead of just (void *)x, which will
 * produce warnings */
#define A(x) ((unsigned long)x)
 
extern asmlinkage int sys_ioperm(unsigned long from, unsigned long num, int on);
extern asmlinkage unsigned long sys_brk(unsigned long brk);
extern asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags, unsigned long fd, unsigned long off);
extern asmlinkage int sys_bdflush(int func, long data);
extern asmlinkage int sys_uselib(const char * library);
extern asmlinkage long sys_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg);
extern asmlinkage int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg);
extern asmlinkage int sys_mknod(const char * filename, int mode, dev_t dev);
extern asmlinkage int sys_mkdir(const char * pathname, int mode);
extern asmlinkage int sys_rmdir(const char * pathname);
extern asmlinkage int sys_unlink(const char * pathname);
extern asmlinkage int sys_symlink(const char * oldname, const char * newname);
extern asmlinkage int sys_link(const char * oldname, const char * newname);
extern asmlinkage int sys_rename(const char * oldname, const char * newname);
extern asmlinkage int sys_quotactl(int cmd, const char *special, int id, caddr_t addr);
extern asmlinkage int sys_statfs(const char * path, struct statfs * buf);
extern asmlinkage int sys_fstatfs(unsigned int fd, struct statfs * buf);
extern asmlinkage int sys_truncate(const char * path, unsigned long length);
extern asmlinkage int sys_ftruncate(unsigned int fd, unsigned long length);
extern asmlinkage int sys_utime(char * filename, struct utimbuf * times);
extern asmlinkage int sys_utimes(char * filename, struct timeval * utimes);
extern asmlinkage int sys_access(const char * filename, int mode);
extern asmlinkage int sys_chdir(const char * filename);
extern asmlinkage int sys_chroot(const char * filename);
extern asmlinkage int sys_chmod(const char * filename, mode_t mode);
extern asmlinkage int sys_chown(const char * filename, uid_t user, gid_t group);
extern asmlinkage int sys_open(const char * filename,int flags,int mode);
extern asmlinkage int sys_creat(const char * pathname, int mode);
extern asmlinkage long sys_lseek(unsigned int fd, off_t offset, unsigned int origin);
extern asmlinkage int sys_llseek(unsigned int fd, unsigned long offset_high, unsigned long offset_low, loff_t *result, unsigned int origin);
extern asmlinkage long sys_read(unsigned int fd, char * buf, unsigned long count);
extern asmlinkage long sys_write(unsigned int fd, const char * buf, unsigned long count);
extern asmlinkage long sys_readv(unsigned long fd, const struct iovec * vector, unsigned long count);
extern asmlinkage long sys_writev(unsigned long fd, const struct iovec * vector, unsigned long count);
extern asmlinkage int sys_select(int n, fd_set *inp, fd_set *outp, fd_set *exp, struct timeval *tvp);
extern asmlinkage int sys_poll(struct pollfd * ufds, unsigned int nfds, int timeout);
extern asmlinkage int sys_newstat(char * filename, struct stat * statbuf);
extern asmlinkage int sys_newlstat(char * filename, struct stat * statbuf);
extern asmlinkage int sys_newfstat(unsigned int fd, struct stat * statbuf);
extern asmlinkage int sys_readlink(const char * path, char * buf, int bufsiz);
extern asmlinkage int sys_sysfs(int option, ...);
extern asmlinkage int sys_ustat(dev_t dev, struct ustat * ubuf);
extern asmlinkage int sys_umount(char * name);
extern asmlinkage int sys_mount(char * dev_name, char * dir_name, char * type, unsigned long new_flags, void *data);
extern asmlinkage int sys_syslog(int type, char * bug, int count);
extern asmlinkage int sys_personality(unsigned long personality);
extern asmlinkage int sys_wait4(pid_t pid,unsigned int * stat_addr, int options, struct rusage * ru);
extern asmlinkage int sys_waitpid(pid_t pid,unsigned int * stat_addr, int options);
extern asmlinkage int sys_sysinfo(struct sysinfo *info);
extern asmlinkage int sys_getitimer(int which, struct itimerval *value);
extern asmlinkage int sys_setitimer(int which, struct itimerval *value, struct itimerval *ovalue);
extern asmlinkage int sys_sched_setscheduler(pid_t pid, int policy, struct sched_param *param);
extern asmlinkage int sys_sched_setparam(pid_t pid, struct sched_param *param);
extern asmlinkage int sys_sched_getparam(pid_t pid, struct sched_param *param);
extern asmlinkage int sys_sched_rr_get_interval(pid_t pid, struct timespec *interval);
extern asmlinkage int sys_nanosleep(struct timespec *rqtp, struct timespec *rmtp);
extern asmlinkage int sys_sigprocmask(int how, sigset_t *set, sigset_t *oset);
extern asmlinkage int sys_sigpending(sigset_t *set);
extern asmlinkage unsigned long sys_signal(int signum, __sighandler_t handler);
extern asmlinkage int sys_reboot(int magic1, int magic2, int cmd, void * arg);
extern asmlinkage int sys_acct(const char *name);
extern asmlinkage int sys_getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
extern asmlinkage long sys_times(struct tms * tbuf);
extern asmlinkage int sys_getgroups(int gidsetsize, gid_t *grouplist);
extern asmlinkage int sys_setgroups(int gidsetsize, gid_t *grouplist);
extern asmlinkage int sys_newuname(struct new_utsname * name);
extern asmlinkage int sys_olduname(struct oldold_utsname * name);
extern asmlinkage int sys_sethostname(char *name, int len);
extern asmlinkage int sys_gethostname(char *name, int len);
extern asmlinkage int sys_setdomainname(char *name, int len);
extern asmlinkage int sys_getrlimit(unsigned int resource, struct rlimit *rlim);
extern asmlinkage int sys_setrlimit(unsigned int resource, struct rlimit *rlim);
extern asmlinkage int sys_getrusage(int who, struct rusage *ru);
extern asmlinkage int sys_time(int * tloc);
extern asmlinkage int sys_gettimeofday(struct timeval *tv, struct timezone *tz);
extern asmlinkage int sys_settimeofday(struct timeval *tv, struct timezone *tz);
extern asmlinkage int sys_adjtimex(struct timex *txc_p);
extern asmlinkage int sys_msync(unsigned long start, size_t len, int flags);
extern asmlinkage int sys_mlock(unsigned long start, size_t len);
extern asmlinkage int sys_munlock(unsigned long start, size_t len);
extern asmlinkage int sys_munmap(unsigned long addr, size_t len);
extern asmlinkage int sys_mprotect(unsigned long start, size_t len, unsigned long prot);
extern asmlinkage unsigned long sys_mremap(unsigned long addr, unsigned long old_len, unsigned long new_len, unsigned long flags);
extern asmlinkage int sys_swapoff(const char * specialfile);
extern asmlinkage int sys_swapon(const char * specialfile, int swap_flags);
extern asmlinkage int sys_bind(int fd, struct sockaddr *umyaddr, int addrlen);
extern asmlinkage int sys_accept(int fd, struct sockaddr *upeer_sockaddr, int *upeer_addrlen);
extern asmlinkage int sys_connect(int fd, struct sockaddr *uservaddr, int addrlen);
extern asmlinkage int sys_getsockname(int fd, struct sockaddr *usockaddr, int *usockaddr_len);
extern asmlinkage int sys_getpeername(int fd, struct sockaddr *usockaddr, int *usockaddr_len);
extern asmlinkage int sys_send(int fd, void * buff, size_t len, unsigned flags);
extern asmlinkage int sys_sendto(int fd, void * buff, size_t len, unsigned flags, struct sockaddr *addr, int addr_len);
extern asmlinkage int sys_recv(int fd, void * ubuf, size_t size, unsigned flags);
extern asmlinkage int sys_recvfrom(int fd, void * ubuf, size_t size, unsigned flags, struct sockaddr *addr, int *addr_len); 
extern asmlinkage int sys_setsockopt(int fd, int level, int optname, char *optval, int optlen);
extern asmlinkage int sys_getsockopt(int fd, int level, int optname, char *optval, int *optlen);
extern asmlinkage int sys_sendmsg(int fd, struct msghdr *msg, unsigned flags);
extern asmlinkage int sys_recvmsg(int fd, struct msghdr *msg, unsigned int flags);
extern asmlinkage int sys_socketcall(int call, unsigned long *args);
extern asmlinkage int sys_nfsservctl(int cmd, void *argp, void *resp);
extern asmlinkage int sys_listen(int fd, int backlog);
extern asmlinkage int sys_socket(int family, int type, int protocol);
extern asmlinkage int sys_socketpair(int family, int type, int protocol, int usockvec[2]);
extern asmlinkage int sys_shutdown(int fd, int how);

asmlinkage int sys32_ioperm(u32 from, u32 num, int on)
{
	return sys_ioperm((unsigned long)from, (unsigned long)num, on);
}

struct msgbuf32 { s32 mtype; char mtext[1]; };

struct ipc_perm32
{
	key_t    	  key;
        __kernel_uid_t32  uid;
        __kernel_gid_t32  gid;
        __kernel_uid_t32  cuid;
        __kernel_gid_t32  cgid;
        __kernel_mode_t32 mode;
        unsigned short  seq;
};

struct semid_ds32 {
        struct ipc_perm32 sem_perm;               /* permissions .. see ipc.h */
        __kernel_time_t32 sem_otime;              /* last semop time */
        __kernel_time_t32 sem_ctime;              /* last change time */
        u32 sem_base;              /* ptr to first semaphore in array */
        u32 sem_pending;          /* pending operations to be processed */
        u32 sem_pending_last;    /* last pending operation */
        u32 undo;                  /* undo requests on this array */
        unsigned short  sem_nsems;              /* no. of semaphores in array */
};

struct msqid_ds32
{
        struct ipc_perm32 msg_perm;
        u32 msg_first;
        u32 msg_last;
        __kernel_time_t32 msg_stime;
        __kernel_time_t32 msg_rtime;
        __kernel_time_t32 msg_ctime;
        u32 wwait;
        u32 rwait;
        unsigned short msg_cbytes;
        unsigned short msg_qnum;  
        unsigned short msg_qbytes;
        __kernel_ipc_pid_t32 msg_lspid;
        __kernel_ipc_pid_t32 msg_lrpid;
};

struct shmid_ds32 {
        struct ipc_perm32       shm_perm;
        int                     shm_segsz;
        __kernel_time_t32       shm_atime;
        __kernel_time_t32       shm_dtime;
        __kernel_time_t32       shm_ctime;
        __kernel_ipc_pid_t32    shm_cpid; 
        __kernel_ipc_pid_t32    shm_lpid; 
        unsigned short          shm_nattch;
        unsigned short          shm_npages;
        u32			shm_pages;
        u32			attaches; 
};
                                                        
/*
 * sys32_ipc() is the de-multiplexer for the SysV IPC calls in 32bit emulation..
 *
 * This is really horribly ugly.
 */

asmlinkage int sys32_ipc (u32 call, int first, int second, int third, u32 ptr, u32 fifth)
{
	int version, err;

	lock_kernel();
	version = call >> 16; /* hack for backward compatibility */
	call &= 0xffff;

	if (call <= SEMCTL)
		switch (call) {
		case SEMOP:
			/* struct sembuf is the same on 32 and 64bit :)) */
			err = sys_semop (first, (struct sembuf *)A(ptr), second);
			goto out;
		case SEMGET:
			err = sys_semget (first, second, third);
			goto out;
		case SEMCTL: {
			union semun fourth;
			void *pad;
			unsigned long old_fs;
			struct semid_ds s;
			
			err = -EINVAL;
			if (!ptr)
				goto out;
			err = -EFAULT;
			if(get_user(pad, (void **)A(ptr)))
				goto out;
			fourth.__pad = pad;
			switch (third) {
				case IPC_INFO:
				case SEM_INFO:
				case GETVAL:
				case GETPID:
				case GETNCNT:
				case GETZCNT:
				case GETALL:
				case SETALL:
				case IPC_RMID:
					err = sys_semctl (first, second, third, fourth);
					goto out;
				case IPC_SET:
					if (get_user (s.sem_perm.uid, &(((struct semid_ds32 *)A(pad))->sem_perm.uid)) ||
					    __get_user (s.sem_perm.gid, &(((struct semid_ds32 *)A(pad))->sem_perm.gid)) ||
					    __get_user (s.sem_perm.mode, &(((struct semid_ds32 *)A(pad))->sem_perm.mode))) {
						err = -EFAULT;
						goto out;
					}
					/* Fall through */
				case SEM_STAT:
				case IPC_STAT:
					fourth.__pad = &s;
					break;
			}
			old_fs = get_fs();
			set_fs (KERNEL_DS);
			err = sys_semctl (first, second, third, fourth);
			set_fs (old_fs);
			switch (third) {
				case SEM_STAT:
				case IPC_STAT:
					if (put_user (s.sem_perm.key, &(((struct semid_ds32 *)A(pad))->sem_perm.key)) ||
					    __put_user (s.sem_perm.uid, &(((struct semid_ds32 *)A(pad))->sem_perm.uid)) ||
					    __put_user (s.sem_perm.gid, &(((struct semid_ds32 *)A(pad))->sem_perm.gid)) ||
					    __put_user (s.sem_perm.cuid, &(((struct semid_ds32 *)A(pad))->sem_perm.cuid)) ||
					    __put_user (s.sem_perm.cgid, &(((struct semid_ds32 *)A(pad))->sem_perm.cgid)) ||
					    __put_user (s.sem_perm.mode, &(((struct semid_ds32 *)A(pad))->sem_perm.mode)) ||
					    __put_user (s.sem_perm.seq, &(((struct semid_ds32 *)A(pad))->sem_perm.seq)) ||
					    __put_user (s.sem_otime, &(((struct semid_ds32 *)A(pad))->sem_otime)) ||
					    __put_user (s.sem_ctime, &(((struct semid_ds32 *)A(pad))->sem_ctime)) ||
					    __put_user (s.sem_nsems, &(((struct semid_ds32 *)A(pad))->sem_nsems)))
						err = -EFAULT;
			}
			goto out;
			}
		default:
			err = -EINVAL;
			goto out;
		}
	if (call <= MSGCTL) 
		switch (call) {
		case MSGSND:
			{
				struct msgbuf *p = kmalloc (second + sizeof (struct msgbuf), GFP_KERNEL);
				
				if (!p) err = -ENOMEM;
				else {
					if (get_user(p->mtype, &(((struct msgbuf32 *)A(ptr))->mtype)) ||
					    __copy_from_user(p->mtext, &(((struct msgbuf32 *)A(ptr))->mtext), second))
						err = -EFAULT;
					else {
						unsigned long old_fs = get_fs();
						set_fs (KERNEL_DS);
						err = sys_msgsnd (first, p, second, third);
						set_fs (old_fs);
					}
					kfree (p);
				}
			}
			goto out;
		case MSGRCV:
			{
				struct msgbuf *p;
				unsigned long old_fs;
				
				if (!version) {
					struct ipc_kludge tmp;
					err = -EINVAL;
					if (!ptr)
						goto out;
					err = -EFAULT;
					if(copy_from_user(&tmp,(struct ipc_kludge *)A(ptr), sizeof (tmp)))
						goto out;
					ptr = tmp.msgp;
					fifth = tmp.msgtyp;
				}
				p = kmalloc (second + sizeof (struct msgbuf), GFP_KERNEL);
				if (!p) {
					err = -EFAULT;
					goto out;
				}
				old_fs = get_fs();
				set_fs (KERNEL_DS);
				err = sys_msgrcv (first, p, second, fifth, third);
				set_fs (old_fs);
				if (put_user (p->mtype, &(((struct msgbuf32 *)A(ptr))->mtype)) ||
				    __copy_to_user(&(((struct msgbuf32 *)A(ptr))->mtext), p->mtext, second))
					err = -EFAULT;
				kfree (p);
				goto out;
			}
		case MSGGET:
			err = sys_msgget ((key_t) first, second);
			goto out;
		case MSGCTL:
			{
				struct msqid_ds m;
				unsigned long old_fs;
				
				switch (second) {
					case IPC_INFO:
					case MSG_INFO:
						/* struct msginfo is the same */
					case IPC_RMID:
						/* and this doesn't care about ptr */
						err = sys_msgctl (first, second, (struct msqid_ds *)A(ptr));
						goto out;
						
					case IPC_SET:
						if (get_user (m.msg_perm.uid, &(((struct msqid_ds32 *)A(ptr))->msg_perm.uid)) ||
						    __get_user (m.msg_perm.gid, &(((struct msqid_ds32 *)A(ptr))->msg_perm.gid)) ||
						    __get_user (m.msg_perm.mode, &(((struct msqid_ds32 *)A(ptr))->msg_perm.mode)) ||
						    __get_user (m.msg_qbytes, &(((struct msqid_ds32 *)A(ptr))->msg_qbytes))) {
							err = -EFAULT;  
							goto out;
						}
					default:
						break;
				}
				old_fs = get_fs();
				set_fs (KERNEL_DS);
				err = sys_msgctl (first, second, &m);
				set_fs (old_fs);
				switch (second) {
					case MSG_STAT:
					case IPC_STAT:
						if (put_user (m.msg_perm.key, &(((struct msqid_ds32 *)A(ptr))->msg_perm.key)) ||
						    __put_user (m.msg_perm.uid, &(((struct msqid_ds32 *)A(ptr))->msg_perm.uid)) ||
						    __put_user (m.msg_perm.gid, &(((struct msqid_ds32 *)A(ptr))->msg_perm.gid)) ||
						    __put_user (m.msg_perm.cuid, &(((struct msqid_ds32 *)A(ptr))->msg_perm.cuid)) ||
						    __put_user (m.msg_perm.cgid, &(((struct msqid_ds32 *)A(ptr))->msg_perm.cgid)) ||
						    __put_user (m.msg_perm.mode, &(((struct msqid_ds32 *)A(ptr))->msg_perm.mode)) ||
						    __put_user (m.msg_perm.seq, &(((struct msqid_ds32 *)A(ptr))->msg_perm.seq)) ||
						    __put_user (m.msg_stime, &(((struct msqid_ds32 *)A(ptr))->msg_stime)) ||
						    __put_user (m.msg_rtime, &(((struct msqid_ds32 *)A(ptr))->msg_rtime)) ||
						    __put_user (m.msg_ctime, &(((struct msqid_ds32 *)A(ptr))->msg_ctime)) ||
						    __put_user (m.msg_cbytes, &(((struct msqid_ds32 *)A(ptr))->msg_cbytes)) ||
						    __put_user (m.msg_qnum, &(((struct msqid_ds32 *)A(ptr))->msg_qnum)) ||
						    __put_user (m.msg_qbytes, &(((struct msqid_ds32 *)A(ptr))->msg_qbytes)) ||
						    __put_user (m.msg_lspid, &(((struct msqid_ds32 *)A(ptr))->msg_lspid)) ||
						    __put_user (m.msg_lrpid, &(((struct msqid_ds32 *)A(ptr))->msg_lrpid)))
							err = -EFAULT;
						break;
					default:
						break;
				}
			}
			goto out;
		default:
			err = -EINVAL;
			goto out;
		}
	if (call <= SHMCTL) 
		switch (call) {
		case SHMAT:
			switch (version) {
			case 0: default: {
				unsigned long raddr;
				err = sys_shmat (first, (char *)A(ptr), second, &raddr);
				if (err)
					goto out;
				err = -EFAULT;
				if(put_user (raddr, ((u32 *)A(third))))
					goto out;
				err = 0;
				goto out;
				}
			case 1: /* If iBCS2 should ever run, then for sure in 64bit mode, not 32bit... */
				err = -EINVAL;
				goto out;
			}
		case SHMDT: 
			err = sys_shmdt ((char *)A(ptr));
			goto out;
		case SHMGET:
			err = sys_shmget (first, second, third);
			goto out;
		case SHMCTL:
			{
				struct shmid_ds s;
				unsigned long old_fs;
				
				switch (second) {
					case IPC_INFO:
						/* struct shminfo is the same */
					case SHM_LOCK:
					case SHM_UNLOCK:
					case IPC_RMID:
						/* and these three aren't using ptr at all */
						err = sys_shmctl (first, second, (struct shmid_ds *)A(ptr));
						goto out;
						
					case IPC_SET:
						if (get_user (s.shm_perm.uid, &(((struct shmid_ds32 *)A(ptr))->shm_perm.uid)) ||
						    __get_user (s.shm_perm.gid, &(((struct shmid_ds32 *)A(ptr))->shm_perm.gid)) ||
						    __get_user (s.shm_perm.mode, &(((struct shmid_ds32 *)A(ptr))->shm_perm.mode))) {
							err = -EFAULT; 
							goto out;
						}
					default:
						break;
				}
				old_fs = get_fs();
				set_fs (KERNEL_DS);
				err = sys_shmctl (first, second, &s);
				set_fs (old_fs);
				switch (second) {
					case SHM_INFO:
						{
							struct shm_info32 { int used_ids; u32 shm_tot; u32 shm_rss; u32 shm_swp; u32 swap_attempts; u32 swap_successes; };
							struct shm_info *si = (struct shm_info *)&s;

							if (put_user (si->used_ids, &(((struct shm_info32 *)A(ptr))->used_ids)) ||
							    __put_user (si->shm_tot, &(((struct shm_info32 *)A(ptr))->shm_tot)) ||
							    __put_user (si->shm_rss, &(((struct shm_info32 *)A(ptr))->shm_rss)) ||
							    __put_user (si->shm_swp, &(((struct shm_info32 *)A(ptr))->shm_swp)) ||
							    __put_user (si->swap_attempts, &(((struct shm_info32 *)A(ptr))->swap_attempts)) ||
							    __put_user (si->swap_successes, &(((struct shm_info32 *)A(ptr))->swap_successes)))
								err = -EFAULT;
						}
						break;
					case SHM_STAT:
					case IPC_STAT:
						if (put_user (s.shm_perm.key, &(((struct shmid_ds32 *)A(ptr))->shm_perm.key)) ||
						    __put_user (s.shm_perm.uid, &(((struct shmid_ds32 *)A(ptr))->shm_perm.uid)) ||
						    __put_user (s.shm_perm.gid, &(((struct shmid_ds32 *)A(ptr))->shm_perm.gid)) ||
						    __put_user (s.shm_perm.cuid, &(((struct shmid_ds32 *)A(ptr))->shm_perm.cuid)) ||
						    __put_user (s.shm_perm.cgid, &(((struct shmid_ds32 *)A(ptr))->shm_perm.cgid)) ||
						    __put_user (s.shm_perm.mode, &(((struct shmid_ds32 *)A(ptr))->shm_perm.mode)) ||
						    __put_user (s.shm_perm.seq, &(((struct shmid_ds32 *)A(ptr))->shm_perm.seq)) ||
						    __put_user (s.shm_atime, &(((struct shmid_ds32 *)A(ptr))->shm_atime)) ||
						    __put_user (s.shm_dtime, &(((struct shmid_ds32 *)A(ptr))->shm_dtime)) ||
						    __put_user (s.shm_ctime, &(((struct shmid_ds32 *)A(ptr))->shm_ctime)) ||
						    __put_user (s.shm_segsz, &(((struct shmid_ds32 *)A(ptr))->shm_segsz)) ||
						    __put_user (s.shm_nattch, &(((struct shmid_ds32 *)A(ptr))->shm_nattch)) ||
						    __put_user (s.shm_lpid, &(((struct shmid_ds32 *)A(ptr))->shm_cpid)) ||
						    __put_user (s.shm_cpid, &(((struct shmid_ds32 *)A(ptr))->shm_lpid)))
							err = -EFAULT;
						break;
					default:
						break;
				}
			}
			goto out;
		default:
			err = -EINVAL;
			goto out;
		}
	else
		err = -EINVAL;
out:
	unlock_kernel();
	return err;
}

asmlinkage unsigned long sys32_mmap(u32 addr, u32 len, u32 prot, u32 flags, u32 fd, u32 off)
{
	return sys_mmap((unsigned long)addr, (unsigned long)len, (unsigned long)prot, (unsigned long)flags, 
			(unsigned long)fd, (unsigned long)off);
}

asmlinkage int sys32_bdflush(int func, s32 data)
{
	return sys_bdflush(func, (long)data);
}

asmlinkage int sys32_uselib(u32 library)
{
	return sys_uselib((const char *)A(library));
}

asmlinkage long sys32_fcntl(unsigned int fd, unsigned int cmd, u32 arg)
{
	switch (cmd) {
	case F_GETLK:
	case F_SETLK:
	case F_SETLKW:
		{
			struct flock f;
			unsigned long old_fs;
			long ret;
			
			if (get_user (f.l_type, &(((struct flock32 *)A(arg))->l_type)) ||
			    __get_user (f.l_whence, &(((struct flock32 *)A(arg))->l_whence)) ||
			    __get_user (f.l_start, &(((struct flock32 *)A(arg))->l_start)) ||
			    __get_user (f.l_len, &(((struct flock32 *)A(arg))->l_len)) ||
			    __get_user (f.l_pid, &(((struct flock32 *)A(arg))->l_pid)))
				return -EFAULT;
			old_fs = get_fs(); set_fs (KERNEL_DS);
			ret = sys_fcntl(fd, cmd, (unsigned long)&f);
			set_fs (old_fs);
   			if (__put_user (f.l_type, &(((struct flock32 *)A(arg))->l_type)) ||
			    __put_user (f.l_whence, &(((struct flock32 *)A(arg))->l_whence)) ||
			    __put_user (f.l_start, &(((struct flock32 *)A(arg))->l_start)) ||
			    __put_user (f.l_len, &(((struct flock32 *)A(arg))->l_len)) ||
			    __put_user (f.l_pid, &(((struct flock32 *)A(arg))->l_pid)))
				return -EFAULT;
			return ret;
		}
	default:
		return sys_fcntl(fd, cmd, (unsigned long)arg);
	}
}

/* Conversion of args should be probably done in all the locations where it is handled,
   using if (current->tss.flags & SPARC_FLAG_32BIT */
asmlinkage int sys32_ioctl(unsigned int fd, unsigned int cmd, u32 arg)
{
	return sys_ioctl(fd, cmd, (unsigned long)arg);
}

asmlinkage int sys32_mknod(u32 filename, int mode, __kernel_dev_t32 dev)
{
	return sys_mknod((const char *)A(filename), mode, dev);
}

asmlinkage int sys32_mkdir(u32 pathname, int mode)
{
	return sys_mkdir((const char *)A(pathname), mode);
}

asmlinkage int sys32_rmdir(u32 pathname)
{
	return sys_rmdir((const char *)A(pathname));
}

asmlinkage int sys32_unlink(u32 pathname)
{
	return sys_unlink((const char *)A(pathname));
}

asmlinkage int sys32_symlink(u32 oldname, u32 newname)
{
	return sys_symlink((const char *)A(oldname), (const char *)A(newname));
}

asmlinkage int sys32_link(u32 oldname, u32 newname)
{
	return sys_link((const char *)A(oldname), (const char *)A(newname));
}

asmlinkage int sys32_rename(u32 oldname, u32 newname)
{
	return sys_rename((const char *)A(oldname), (const char *)A(newname));
}

struct dqblk32 {
    __u32 dqb_bhardlimit;
    __u32 dqb_bsoftlimit;
    __u32 dqb_curblocks;
    __u32 dqb_ihardlimit;
    __u32 dqb_isoftlimit;
    __u32 dqb_curinodes;
    __kernel_time_t32 dqb_btime;
    __kernel_time_t32 dqb_itime;
};
                                
asmlinkage int sys32_quotactl(int cmd, u32 special, int id, u32 addr)
{
	int cmds = cmd >> SUBCMDSHIFT;
	int err;
	struct dqblk d;
	unsigned long old_fs;
	
	switch (cmds) {
	case Q_GETQUOTA:
		break;
	case Q_SETQUOTA:
	case Q_SETUSE:
	case Q_SETQLIM:
		if (copy_from_user (&d, (struct dqblk32 *)A(addr), sizeof (struct dqblk32)))
			return -EFAULT;
		d.dqb_itime = ((struct dqblk32 *)&d)->dqb_itime;
		d.dqb_btime = ((struct dqblk32 *)&d)->dqb_btime;
		break;
	default:
		return sys_quotactl(cmd, (const char *)A(special), id, (caddr_t)A(addr));
	}
	old_fs = get_fs ();
	set_fs (KERNEL_DS);
	err = sys_quotactl(cmd, (const char *)A(special), id, (caddr_t)A(addr));
	set_fs (old_fs);
	if (cmds == Q_GETQUOTA) {
		__kernel_time_t b = d.dqb_btime, i = d.dqb_itime;
		((struct dqblk32 *)&d)->dqb_itime = i;
		((struct dqblk32 *)&d)->dqb_btime = b;
		if (copy_to_user ((struct dqblk32 *)A(addr), &d, sizeof (struct dqblk32)))
			return -EFAULT;
	}
	return err;
}

static int put_statfs (u32 buf, struct statfs *s)
{
	if (put_user (s->f_type, &(((struct statfs32 *)A(buf))->f_type)) ||
	    __put_user (s->f_bsize, &(((struct statfs32 *)A(buf))->f_bsize)) ||
	    __put_user (s->f_blocks, &(((struct statfs32 *)A(buf))->f_blocks)) ||
	    __put_user (s->f_bfree, &(((struct statfs32 *)A(buf))->f_bfree)) ||
	    __put_user (s->f_bavail, &(((struct statfs32 *)A(buf))->f_bavail)) ||
	    __put_user (s->f_files, &(((struct statfs32 *)A(buf))->f_files)) ||
	    __put_user (s->f_ffree, &(((struct statfs32 *)A(buf))->f_ffree)) ||
	    __put_user (s->f_namelen, &(((struct statfs32 *)A(buf))->f_namelen)) ||
	    __put_user (s->f_fsid.val[0], &(((struct statfs32 *)A(buf))->f_fsid.val[0])) ||
	    __put_user (s->f_fsid.val[1], &(((struct statfs32 *)A(buf))->f_fsid.val[1])))
		return -EFAULT;
	return 0;
}

asmlinkage int sys32_statfs(u32 path, u32 buf)
{
	int ret;
	struct statfs s;
	unsigned long old_fs = get_fs();
	
	set_fs (KERNEL_DS);
	ret = sys_statfs((const char *)A(path), &s);
	set_fs (old_fs);
	if (put_statfs(buf, &s)) return -EFAULT;
	return ret;
}

asmlinkage int sys32_fstatfs(unsigned int fd, u32 buf)
{
	int ret;
	struct statfs s;
	unsigned long old_fs = get_fs();
	
	set_fs (KERNEL_DS);
	ret = sys_fstatfs(fd, &s);
	set_fs (old_fs);
	if (put_statfs(buf, &s)) return -EFAULT;
	return ret;
}

asmlinkage int sys32_truncate(u32 path, u32 length)
{
	return sys_truncate((const char *)A(path), (unsigned long)length);
}

asmlinkage int sys32_ftruncate(unsigned int fd, u32 length)
{
	return sys_ftruncate(fd, (unsigned long)length);
}

asmlinkage int sys32_utime(u32 filename, u32 times)
{
	struct utimbuf32 { __kernel_time_t32 actime, modtime; };
	struct utimbuf t;
	unsigned long old_fs;
	int ret;
	
	if (get_user (t.actime, &(((struct utimbuf32 *)A(times))->actime)) ||
	    __get_user (t.modtime, &(((struct utimbuf32 *)A(times))->modtime)))
		return -EFAULT;
	old_fs = get_fs();
	set_fs (KERNEL_DS); 
	ret = sys_utime((char *)A(filename), &t);
	set_fs (old_fs);
	return ret;
}

asmlinkage int sys32_utimes(u32 filename, u32 utimes)
{
	/* struct timeval is the same :)) */
	return sys_utimes((char *)A(filename), (struct timeval *)A(utimes));
}

asmlinkage int sys32_access(u32 filename, int mode)
{
	return sys_access((const char *)A(filename), mode);
}

asmlinkage int sys32_chdir(u32 filename)
{
	return sys_chdir((const char *)A(filename));
}

asmlinkage int sys32_chroot(u32 filename)
{
	return sys_chroot((const char *)A(filename));
}

asmlinkage int sys32_chmod(u32 filename, __kernel_mode_t32 mode)
{
	return sys_chmod((const char *)A(filename), mode);
}

asmlinkage int sys32_chown(u32 filename, __kernel_uid_t32 user, __kernel_gid_t32 group)
{
	return sys_chown((const char *)A(filename), user, group);
}

asmlinkage int sys32_open(u32 filename, int flags, int mode)
{
	return sys_open((const char *)A(filename), flags, mode);
}

asmlinkage int sys32_creat(u32 pathname, int mode)
{
	return sys_creat((const char *)A(pathname), mode);
}

asmlinkage long sys32_lseek(unsigned int fd, s32 offset, unsigned int origin)
{
	return sys_lseek(fd, (off_t)offset, origin);
}

asmlinkage int sys32_llseek(unsigned int fd, u32 offset_high, u32 offset_low, u32 result, unsigned int origin)
{
	/* loff_t is the same :)) */
	return sys_llseek(fd, (unsigned long)offset_high, (unsigned long)offset_low, (loff_t *)A(result), origin);
}

asmlinkage long sys32_read(unsigned int fd, u32 buf, u32 count)
{
	return sys_read(fd, (char *)A(buf), (unsigned long)count);
}

asmlinkage long sys32_write(unsigned int fd, u32 buf, u32 count)
{
	return sys_write(fd, (const char *)A(buf), (unsigned long)count);
}

struct iovec32 { u32 iov_base; __kernel_size_t32 iov_len; };

asmlinkage long sys32_readv(u32 fd, u32 vector, u32 count)
{
	struct iovec *v;
	struct iovec vf[UIO_FASTIOV];
	u32 i;
	long ret;
	unsigned long old_fs;
	
	if (!count) return 0; if (count > UIO_MAXIOV) return -EINVAL;
	if (count <= UIO_FASTIOV)
		v = vf;
	else {
		lock_kernel ();
		v = kmalloc (count * sizeof (struct iovec), GFP_KERNEL);
		if (!v) {
			ret = -ENOMEM;
			goto out;
		}
	}
	for (i = 0; i < count; i++) {
		if (__get_user ((unsigned long)(v[i].iov_base), &((((struct iovec32 *)A(vector))+i)->iov_base)) ||
		    __get_user (v[i].iov_len, &((((struct iovec32 *)A(vector))+i)->iov_len))) {
		    	ret = -EFAULT;
		    	goto out;
		}
	}
	old_fs = get_fs();
	set_fs (KERNEL_DS);
	ret = sys_readv((unsigned long)fd, v, (unsigned long)count);
	set_fs (old_fs);
out:
	if (count > UIO_FASTIOV) {
		kfree (v);
		unlock_kernel ();
	}
	return ret;
}

asmlinkage long sys32_writev(u32 fd, u32 vector, u32 count)
{
	struct iovec *v;
	struct iovec vf[UIO_FASTIOV];
	u32 i;
	long ret;
	unsigned long old_fs;
	
	if (!count) return 0; if (count > UIO_MAXIOV) return -EINVAL;
	if (count <= UIO_FASTIOV)
		v = vf;
	else {
		lock_kernel ();
		v = kmalloc (count * sizeof (struct iovec), GFP_KERNEL);
		if (!v) {
			ret = -ENOMEM;
			goto out;
		}
	}
	for (i = 0; i < count; i++) {
		if (__get_user ((unsigned long)(v[i].iov_base), &((((struct iovec32 *)A(vector))+i)->iov_base)) ||
		    __get_user (v[i].iov_len, &((((struct iovec32 *)A(vector))+i)->iov_len))) {
			ret = -EFAULT;
			goto out;
		}
	}
	old_fs = get_fs();
	set_fs (KERNEL_DS);
	ret = sys_writev((unsigned long)fd, v, (unsigned long)count);
	set_fs (old_fs);
out:	
	if (count > UIO_FASTIOV) {
		kfree (v);
		unlock_kernel ();
	}
	return ret;
}

/* readdir & getdents */

#define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
#define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1))

struct old_linux_dirent32 {
	u32		d_ino;
	u32		d_offset;
	unsigned short	d_namlen;
	char		d_name[1];
};

struct readdir_callback32 {
	struct old_linux_dirent32 * dirent;
	int count;
};

static int fillonedir(void * __buf, const char * name, int namlen, off_t offset, ino_t ino)
{
	struct readdir_callback32 * buf = (struct readdir_callback32 *) __buf;
	struct old_linux_dirent32 * dirent;

	if (buf->count)
		return -EINVAL;
	buf->count++;
	dirent = buf->dirent;
	put_user(ino, &dirent->d_ino);
	put_user(offset, &dirent->d_offset);
	put_user(namlen, &dirent->d_namlen);
	copy_to_user(dirent->d_name, name, namlen);
	put_user(0, dirent->d_name + namlen);
	return 0;
}

asmlinkage int old32_readdir(unsigned int fd, u32 dirent, unsigned int count)
{
	int error = -EBADF;
	struct file * file;
	struct readdir_callback32 buf;

	lock_kernel();
	if (fd >= NR_OPEN || !(file = current->files->fd[fd]))
		goto out;
	error = -ENOTDIR;
	if (!file->f_op || !file->f_op->readdir)
		goto out;
	error = verify_area(VERIFY_WRITE, (void *)A(dirent), sizeof(struct old_linux_dirent32));
	if (error)
		goto out;
	buf.count = 0;
	buf.dirent = (struct old_linux_dirent32 *)A(dirent);
	error = file->f_op->readdir(file->f_inode, file, &buf, fillonedir);
	if (error < 0)
		goto out;
	error = buf.count;
out:
	unlock_kernel();
	return error;
}

struct linux_dirent32 {
	u32		d_ino;
	u32		d_off;
	unsigned short	d_reclen;
	char		d_name[1];
};

struct getdents_callback32 {
	struct linux_dirent32 * current_dir;
	struct linux_dirent32 * previous;
	int count;
	int error;
};

static int filldir(void * __buf, const char * name, int namlen, off_t offset, ino_t ino)
{
	struct linux_dirent32 * dirent;
	struct getdents_callback32 * buf = (struct getdents_callback32 *) __buf;
	int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1);

	buf->error = -EINVAL;	/* only used if we fail.. */
	if (reclen > buf->count)
		return -EINVAL;
	dirent = buf->previous;
	if (dirent)
		put_user(offset, &dirent->d_off);
	dirent = buf->current_dir;
	buf->previous = dirent;
	put_user(ino, &dirent->d_ino);
	put_user(reclen, &dirent->d_reclen);
	copy_to_user(dirent->d_name, name, namlen);
	put_user(0, dirent->d_name + namlen);
	((char *) dirent) += reclen;
	buf->current_dir = dirent;
	buf->count -= reclen;
	return 0;
}

asmlinkage int sys32_getdents(unsigned int fd, u32 dirent, unsigned int count)
{
	struct file * file;
	struct linux_dirent32 * lastdirent;
	struct getdents_callback32 buf;
	int error = -EBADF;

	lock_kernel();
	if (fd >= NR_OPEN || !(file = current->files->fd[fd]))
		goto out;
	error = -ENOTDIR;
	if (!file->f_op || !file->f_op->readdir)
		goto out;
	error = verify_area(VERIFY_WRITE, (void *)A(dirent), count);
	if (error)
		goto out;
	buf.current_dir = (struct linux_dirent32 *) A(dirent);
	buf.previous = NULL;
	buf.count = count;
	buf.error = 0;
	error = file->f_op->readdir(file->f_inode, file, &buf, filldir);
	if (error < 0)
		goto out;
	lastdirent = buf.previous;
	if (!lastdirent) {
		error = buf.error;
	} else {
		put_user(file->f_pos, &lastdirent->d_off);
		error = count - buf.count;
	}
out:
	unlock_kernel();
	return error;
}

/* end of readdir & getdents */

asmlinkage int sys32_select(int n, u32 inp, u32 outp, u32 exp, u32 tvp)
{
	unsigned long old_fs;
	char *p;
	u32 *q;
	int i, ret = -EINVAL, nn;
	u32 *Inp, *Outp, *Exp;
	
	if (n < 0 || n > PAGE_SIZE*2) return -EINVAL;
	lock_kernel ();
	p = (char *)__get_free_page (GFP_KERNEL);
	if (!p) goto out;
	q = (u32 *)p;
	nn = (n + 8 * sizeof(unsigned long) - 1) / (8 * sizeof (unsigned long));
	Inp = (u32 *)A(inp); Outp = (u32 *)A(outp); Exp = (u32 *)A(exp);
	ret = -EFAULT;
	for (i = 0; i < ret; i++, Inp += 2, Outp += 2, Exp += 2, q += 2) {
		if (__get_user (q[1], Inp) ||
		    __get_user (q[0], Inp+1) ||
		    __get_user (q[1+PAGE_SIZE/4], Outp) ||
		    __get_user (q[PAGE_SIZE/4], Outp+1) ||
		    __get_user (q[1+PAGE_SIZE/2], Exp) ||
		    __get_user (q[PAGE_SIZE/2], Exp+1))
			goto out;
	}
	old_fs = get_fs ();
	set_fs (KERNEL_DS);
	ret = sys_select(n, (fd_set *)p, (fd_set *)(p + PAGE_SIZE/4), (fd_set *)(p + PAGE_SIZE/2), (struct timeval *)A(tvp));
	set_fs (old_fs);
	q = (u32 *)p;
	Inp = (u32 *)A(inp); Outp = (u32 *)A(outp); Exp = (u32 *)A(exp);
	for (i = 0; i < ret; i++, Inp += 2, Outp += 2, Exp += 2, q += 2) {
		if (__put_user (q[1], Inp) ||
		    __put_user (q[0], Inp+1) ||
		    __put_user (q[1+PAGE_SIZE/4], Outp) ||
		    __put_user (q[PAGE_SIZE/4], Outp+1) ||
		    __put_user (q[1+PAGE_SIZE/2], Exp) ||
		    __put_user (q[PAGE_SIZE/2], Exp+1)) {
		    	ret = -EFAULT;
			goto out;
		}
	}
out:
	free_page ((unsigned long)p);
	return ret;
}

asmlinkage int sys32_poll(u32 ufds, unsigned int nfds, int timeout)
{
	return sys_poll((struct pollfd *)A(ufds), nfds, timeout);
}

static inline int putstat(u32 statbuf, struct stat *s)
{
	if (put_user (s->st_dev, &(((struct stat32 *)A(statbuf))->st_dev)) ||
	    __put_user (s->st_ino, &(((struct stat32 *)A(statbuf))->st_ino)) ||
	    __put_user (s->st_mode, &(((struct stat32 *)A(statbuf))->st_mode)) ||
	    __put_user (s->st_nlink, &(((struct stat32 *)A(statbuf))->st_nlink)) ||
	    __put_user (s->st_uid, &(((struct stat32 *)A(statbuf))->st_uid)) ||
	    __put_user (s->st_gid, &(((struct stat32 *)A(statbuf))->st_gid)) ||
	    __put_user (s->st_rdev, &(((struct stat32 *)A(statbuf))->st_rdev)) ||
	    __put_user (s->st_size, &(((struct stat32 *)A(statbuf))->st_size)) ||
	    __put_user (s->st_atime, &(((struct stat32 *)A(statbuf))->st_atime)) ||
	    __put_user (s->st_mtime, &(((struct stat32 *)A(statbuf))->st_mtime)) ||
	    __put_user (s->st_ctime, &(((struct stat32 *)A(statbuf))->st_ctime)) ||
	    __put_user (s->st_blksize, &(((struct stat32 *)A(statbuf))->st_blksize)) ||
	    __put_user (s->st_blocks, &(((struct stat32 *)A(statbuf))->st_blocks)))
		return -EFAULT;
	return 0;
}

asmlinkage int sys32_newstat(u32 filename, u32 statbuf)
{
	int ret;
	struct stat s;
	unsigned long old_fs = get_fs();
	
	set_fs (KERNEL_DS);
	ret = sys_newstat((char *)A(filename), &s);
	set_fs (old_fs);
	if (putstat (statbuf, &s)) return -EFAULT;
	return ret;
}

asmlinkage int sys32_newlstat(u32 filename, u32 statbuf)
{
	int ret;
	struct stat s;
	unsigned long old_fs = get_fs();
	
	set_fs (KERNEL_DS);
	ret = sys_newlstat((char *)A(filename), &s);
	set_fs (old_fs);
	if (putstat (statbuf, &s)) return -EFAULT;
	return ret;
}

asmlinkage int sys32_newfstat(unsigned int fd, u32 statbuf)
{
	int ret;
	struct stat s;
	unsigned long old_fs = get_fs();
	
	set_fs (KERNEL_DS);
	ret = sys_newfstat(fd, &s);
	set_fs (old_fs);
	if (putstat (statbuf, &s)) return -EFAULT;
	return ret;
}

asmlinkage int sys32_readlink(u32 path, u32 buf, int bufsiz)
{
	return sys_readlink((const char *)A(path), (char *)A(buf), bufsiz);
}

asmlinkage int sys32_sysfs(int option, ...)
{
        va_list args;
	unsigned int x;
	int ret = -EINVAL;

        va_start(args, option);
        switch (option) {
                case 1:
			ret = sys_sysfs(option, (const char *)A(va_arg(args, u32)));
			break;
                case 2:
			x = va_arg(args, unsigned int);
			ret = sys_sysfs(option, x, (char *)A(va_arg(args, u32)));
			break;
                case 3:
			ret = sys_sysfs(option);
			break;
	}
        va_end(args);
	return ret;
}

asmlinkage int sys32_ustat(dev_t dev, u32 ubuf)
{
	/* ustat is the same :)) */
	return sys_ustat(dev, (struct ustat *)A(ubuf));
}

asmlinkage int sys32_umount(u32 name)
{
	return sys_umount((char *)A(name));
}

asmlinkage int sys32_mount(u32 dev_name, u32 dir_name, u32 type, u32 new_flags, u32 data)
{
	return sys_mount((char *)A(dev_name), (char *)A(dir_name), (char *)A(type), 
			 (unsigned long)new_flags, (void *)A(data));
}

asmlinkage int sys32_syslog(int type, u32 bug, int count)
{
	return sys_syslog(type, (char *)A(bug), count);
}

asmlinkage int sys32_personality(u32 personality)
{
	return sys_personality((unsigned long)personality);
}

struct rusage32 {
        struct timeval ru_utime;
        struct timeval ru_stime;
        s32    ru_maxrss;
        s32    ru_ixrss;
        s32    ru_idrss;
        s32    ru_isrss;
        s32    ru_minflt;
        s32    ru_majflt;
        s32    ru_nswap;
        s32    ru_inblock;
        s32    ru_oublock;
        s32    ru_msgsnd; 
        s32    ru_msgrcv; 
        s32    ru_nsignals;
        s32    ru_nvcsw;
        s32    ru_nivcsw;
};

static int put_rusage (u32 ru, struct rusage *r)
{
	if (put_user (r->ru_utime.tv_sec, &(((struct rusage32 *)A(ru))->ru_utime.tv_sec)) ||
	    __put_user (r->ru_utime.tv_usec, &(((struct rusage32 *)A(ru))->ru_utime.tv_usec)) ||
	    __put_user (r->ru_stime.tv_sec, &(((struct rusage32 *)A(ru))->ru_stime.tv_sec)) ||
	    __put_user (r->ru_stime.tv_usec, &(((struct rusage32 *)A(ru))->ru_stime.tv_usec)) ||
	    __put_user (r->ru_maxrss, &(((struct rusage32 *)A(ru))->ru_maxrss)) ||
	    __put_user (r->ru_ixrss, &(((struct rusage32 *)A(ru))->ru_ixrss)) ||
	    __put_user (r->ru_idrss, &(((struct rusage32 *)A(ru))->ru_idrss)) ||
	    __put_user (r->ru_isrss, &(((struct rusage32 *)A(ru))->ru_isrss)) ||
	    __put_user (r->ru_minflt, &(((struct rusage32 *)A(ru))->ru_minflt)) ||
	    __put_user (r->ru_majflt, &(((struct rusage32 *)A(ru))->ru_majflt)) ||
	    __put_user (r->ru_nswap, &(((struct rusage32 *)A(ru))->ru_nswap)) ||
	    __put_user (r->ru_inblock, &(((struct rusage32 *)A(ru))->ru_inblock)) ||
	    __put_user (r->ru_oublock, &(((struct rusage32 *)A(ru))->ru_oublock)) ||
	    __put_user (r->ru_msgsnd, &(((struct rusage32 *)A(ru))->ru_msgsnd)) ||
	    __put_user (r->ru_msgrcv, &(((struct rusage32 *)A(ru))->ru_msgrcv)) ||
	    __put_user (r->ru_nsignals, &(((struct rusage32 *)A(ru))->ru_nsignals)) ||
	    __put_user (r->ru_nvcsw, &(((struct rusage32 *)A(ru))->ru_nvcsw)) ||
	    __put_user (r->ru_nivcsw, &(((struct rusage32 *)A(ru))->ru_nivcsw)))
		return -EFAULT;
	return 0;
}

asmlinkage int sys32_wait4(__kernel_pid_t32 pid, u32 stat_addr, int options, u32 ru)
{
	if (!ru)
		return sys_wait4(pid, (unsigned int *)A(stat_addr), options, NULL);
	else {
		struct rusage r;
		int ret;
		unsigned long old_fs = get_fs();
		
		set_fs (KERNEL_DS);
		ret = sys_wait4(pid, (unsigned int *)A(stat_addr), options, &r);
		set_fs (old_fs);
		if (put_rusage (ru, &r)) return -EFAULT;
		return ret;
	}
}

asmlinkage int sys32_waitpid(__kernel_pid_t32 pid, u32 stat_addr, int options)
{
	return sys_waitpid(pid, (unsigned int *)A(stat_addr), options);
}

struct sysinfo32 {
        s32 uptime;
        u32 loads[3];
        u32 totalram;
        u32 freeram;
        u32 sharedram;
        u32 bufferram;
        u32 totalswap;
        u32 freeswap;
        unsigned short procs;
        char _f[22];
};

asmlinkage int sys32_sysinfo(u32 info)
{
	struct sysinfo s;
	int ret;
	unsigned long old_fs = get_fs ();
	
	set_fs (KERNEL_DS);
	ret = sys_sysinfo(&s);
	set_fs (old_fs);
	if (put_user (s.uptime, &(((struct sysinfo32 *)A(info))->uptime)) ||
	    __put_user (s.loads[0], &(((struct sysinfo32 *)A(info))->loads[0])) ||
	    __put_user (s.loads[1], &(((struct sysinfo32 *)A(info))->loads[1])) ||
	    __put_user (s.loads[2], &(((struct sysinfo32 *)A(info))->loads[2])) ||
	    __put_user (s.totalram, &(((struct sysinfo32 *)A(info))->totalram)) ||
	    __put_user (s.freeram, &(((struct sysinfo32 *)A(info))->freeram)) ||
	    __put_user (s.sharedram, &(((struct sysinfo32 *)A(info))->sharedram)) ||
	    __put_user (s.bufferram, &(((struct sysinfo32 *)A(info))->bufferram)) ||
	    __put_user (s.totalswap, &(((struct sysinfo32 *)A(info))->totalswap)) ||
	    __put_user (s.freeswap, &(((struct sysinfo32 *)A(info))->freeswap)) ||
	    __put_user (s.procs, &(((struct sysinfo32 *)A(info))->procs)))
		return -EFAULT;
	return ret;
}

asmlinkage int sys32_getitimer(int which, u32 value)
{
	/* itimerval is the same :)) */
	return sys_getitimer(which, (struct itimerval *)A(value));
}

asmlinkage int sys32_setitimer(int which, u32 value, u32 ovalue)
{
	return sys_setitimer(which, (struct itimerval *)A(value), (struct itimerval *)A(ovalue));
}

asmlinkage int sys32_sched_setscheduler(__kernel_pid_t32 pid, int policy, u32 param)
{
	/* sched_param is the same :)) */
	return sys_sched_setscheduler(pid, policy, (struct sched_param *)A(param));
}

asmlinkage int sys32_sched_setparam(__kernel_pid_t32 pid, u32 param)
{
	return sys_sched_setparam(pid, (struct sched_param *)A(param));
}

asmlinkage int sys32_sched_getparam(__kernel_pid_t32 pid, u32 param)
{
	return sys_sched_getparam(pid, (struct sched_param *)A(param));
}

struct timespec32 {
	s32    tv_sec;
	s32    tv_nsec;
};
                
asmlinkage int sys32_sched_rr_get_interval(__kernel_pid_t32 pid, u32 interval)
{
	struct timespec t;
	int ret;
	unsigned long old_fs = get_fs ();
	
	set_fs (KERNEL_DS);
	ret = sys_sched_rr_get_interval(pid, &t);
	set_fs (old_fs);
	if (put_user (t.tv_sec, &(((struct timespec32 *)A(interval))->tv_sec)) ||
	    __put_user (t.tv_nsec, &(((struct timespec32 *)A(interval))->tv_nsec)))
		return -EFAULT;
	return ret;
}

asmlinkage int sys32_nanosleep(u32 rqtp, u32 rmtp)
{
	struct timespec t;
	int ret;
	unsigned long old_fs = get_fs ();
	
	if (get_user (t.tv_sec, &(((struct timespec32 *)A(rqtp))->tv_sec)) ||
	    __get_user (t.tv_nsec, &(((struct timespec32 *)A(rqtp))->tv_nsec)))
		return -EFAULT;
	set_fs (KERNEL_DS);
	ret = sys_nanosleep(&t, rmtp ? &t : NULL);
	set_fs (old_fs);
	if (rmtp && ret == -EINTR) {
		if (__put_user (t.tv_sec, &(((struct timespec32 *)A(rmtp))->tv_sec)) ||
	    	    __put_user (t.tv_nsec, &(((struct timespec32 *)A(rmtp))->tv_nsec)))
			return -EFAULT;
	}
	return ret;
}

asmlinkage int sys32_sigprocmask(int how, u32 set, u32 oset)
{
	sigset_t s;
	int ret;
	unsigned long old_fs = get_fs();
	
	if (set && get_user (s, (sigset_t32 *)A(set))) return -EFAULT;
	set_fs (KERNEL_DS);
	ret = sys_sigprocmask(how, set ? &s : NULL, oset ? &s : NULL);
	set_fs (old_fs);
	if (oset && put_user (s, (sigset_t32 *)A(oset))) return -EFAULT;
	return ret;
}

asmlinkage int sys32_sigpending(u32 set)
{
	sigset_t s;
	int ret;
	unsigned long old_fs = get_fs();
		
	set_fs (KERNEL_DS);
	ret = sys_sigpending(&s);
	set_fs (old_fs);
	if (put_user (s, (sigset_t32 *)A(set))) return -EFAULT;
	return ret;
}

asmlinkage unsigned long sys32_signal(int signum, u32 handler)
{
	return sys_signal(signum, (__sighandler_t)A(handler));
}

asmlinkage int sys32_reboot(int magic1, int magic2, int cmd, u32 arg)
{
	return sys_reboot(magic1, magic2, cmd, (void *)A(arg));
}

asmlinkage int sys32_acct(u32 name)
{
	return sys_acct((const char *)A(name));
}

asmlinkage int sys32_getresuid(u32 ruid, u32 euid, u32 suid)
{
	uid_t a, b, c;
	int ret;
	unsigned long old_fs = get_fs();
		
	set_fs (KERNEL_DS);
	ret = sys_getresuid(&a, &b, &c);
	set_fs (old_fs);
	if (put_user (a, (__kernel_uid_t32 *)A(ruid)) ||
	    put_user (b, (__kernel_uid_t32 *)A(euid)) ||
	    put_user (c, (__kernel_uid_t32 *)A(suid)))
		return -EFAULT;
	return ret;
}

struct tms32 {
	__kernel_clock_t32 tms_utime;
	__kernel_clock_t32 tms_stime;
	__kernel_clock_t32 tms_cutime;
	__kernel_clock_t32 tms_cstime;
};
                                
asmlinkage long sys32_times(u32 tbuf)
{
	struct tms t;
	long ret;
	unsigned long old_fs = get_fs ();
	
	set_fs (KERNEL_DS);
	ret = sys_times(tbuf ? &t : NULL);
	set_fs (old_fs);
	if (tbuf && (
	    put_user (t.tms_utime, &(((struct tms32 *)A(tbuf))->tms_utime)) ||
	    __put_user (t.tms_stime, &(((struct tms32 *)A(tbuf))->tms_stime)) ||
	    __put_user (t.tms_cutime, &(((struct tms32 *)A(tbuf))->tms_cutime)) ||
	    __put_user (t.tms_cstime, &(((struct tms32 *)A(tbuf))->tms_cstime))))
		return -EFAULT;
	return ret;
}

asmlinkage int sys32_getgroups(int gidsetsize, u32 grouplist)
{
	gid_t gl[NGROUPS];
	int ret, i;
	unsigned long old_fs = get_fs ();
	
	set_fs (KERNEL_DS);
	ret = sys_getgroups(gidsetsize, gl);
	set_fs (old_fs);
	if (ret > 0 && ret <= NGROUPS)
		for (i = 0; i < ret; i++, grouplist += sizeof(__kernel_gid_t32))
			if (__put_user (gl[i], (__kernel_gid_t32 *)A(grouplist)))
				return -EFAULT;
	return ret;
}

asmlinkage int sys32_setgroups(int gidsetsize, u32 grouplist)
{
	gid_t gl[NGROUPS];
	int ret, i;
	unsigned long old_fs = get_fs ();
	
	if ((unsigned) gidsetsize > NGROUPS)
		return -EINVAL;
	for (i = 0; i < gidsetsize; i++, grouplist += sizeof(__kernel_gid_t32))
		if (__get_user (gl[i], (__kernel_gid_t32 *)A(grouplist)))
			return -EFAULT;
        set_fs (KERNEL_DS);
	ret = sys_setgroups(gidsetsize, gl);
	set_fs (old_fs);
	return ret;
}

asmlinkage int sys32_newuname(u32 name)
{
	/* utsname is the same :)) */
	return sys_newuname((struct new_utsname *)A(name));
}

asmlinkage int sys32_olduname(u32 name)
{
	return sys_olduname((struct oldold_utsname *)A(name));
}

asmlinkage int sys32_sethostname(u32 name, int len)
{
	return sys_sethostname((char *)A(name), len);
}

asmlinkage int sys32_gethostname(u32 name, int len)
{
	return sys_gethostname((char *)A(name), len);
}

asmlinkage int sys32_setdomainname(u32 name, int len)
{
	return sys_setdomainname((char *)A(name), len);
}

struct rlimit32 {
	s32	rlim_cur;
	s32	rlim_max;
};

asmlinkage int sys32_getrlimit(unsigned int resource, u32 rlim)
{
	struct rlimit r;
	int ret;
	unsigned long old_fs = get_fs ();
	
	set_fs (KERNEL_DS);
	ret = sys_getrlimit(resource, &r);
	set_fs (old_fs);
	if (!ret && (
	    put_user (r.rlim_cur, &(((struct rlimit32 *)A(rlim))->rlim_cur)) ||
	    __put_user (r.rlim_max, &(((struct rlimit32 *)A(rlim))->rlim_max))))
		return -EFAULT;
	return ret;
}

asmlinkage int sys32_setrlimit(unsigned int resource, u32 rlim)
{
	struct rlimit r;
	int ret;
	unsigned long old_fs = get_fs ();

	if (resource >= RLIM_NLIMITS) return -EINVAL;	
	if (get_user (r.rlim_cur, &(((struct rlimit32 *)A(rlim))->rlim_cur)) ||
	    __get_user (r.rlim_max, &(((struct rlimit32 *)A(rlim))->rlim_max)))
		return -EFAULT;
	set_fs (KERNEL_DS);
	ret = sys_setrlimit(resource, &r);
	set_fs (old_fs);
	return ret;
}

asmlinkage int sys32_getrusage(int who, u32 ru)
{
	struct rusage r;
	int ret;
	unsigned long old_fs = get_fs();
		
	set_fs (KERNEL_DS);
	ret = sys_getrusage(who, &r);
	set_fs (old_fs);
	if (put_rusage (ru, &r)) return -EFAULT;
	return ret;
}

asmlinkage int sys32_time(u32 tloc)
{
	return sys_time((int *)A(tloc));
}

asmlinkage int sys32_gettimeofday(u32 tv, u32 tz)
{
	/* both timeval and timezone are ok :)) */
	return sys_gettimeofday((struct timeval *)A(tv), (struct timezone *)A(tz));
}

asmlinkage int sys32_settimeofday(u32 tv, u32 tz)
{
	return sys_settimeofday((struct timeval *)A(tv), (struct timezone *)A(tz));
}

struct timex32 {
	unsigned int modes;
	s32 offset;
	s32 freq;
	s32 maxerror;
	s32 esterror;
	int status;
	s32 constant;
	s32 precision;
	s32 tolerance;
	struct timeval time;
	s32 tick;
	s32 ppsfreq;
	s32 jitter;
	int shift;
	s32 stabil;
	s32 jitcnt;
	s32 calcnt;
	s32 errcnt;
	s32 stbcnt;
	int  :32; int  :32; int  :32; int  :32;
	int  :32; int  :32; int  :32; int  :32;
	int  :32; int  :32; int  :32; int  :32;
};

asmlinkage int sys32_adjtimex(u32 txc_p)
{
	struct timex t;
	int ret;
	unsigned long old_fs = get_fs ();

	if (get_user (t.modes, &(((struct timex32 *)A(txc_p))->modes)) ||
	    __get_user (t.offset, &(((struct timex32 *)A(txc_p))->offset)) ||
	    __get_user (t.freq, &(((struct timex32 *)A(txc_p))->freq)) ||
	    __get_user (t.maxerror, &(((struct timex32 *)A(txc_p))->maxerror)) ||
	    __get_user (t.esterror, &(((struct timex32 *)A(txc_p))->esterror)) ||
	    __get_user (t.status, &(((struct timex32 *)A(txc_p))->status)) ||
	    __get_user (t.constant, &(((struct timex32 *)A(txc_p))->constant)) ||
	    __get_user (t.tick, &(((struct timex32 *)A(txc_p))->tick)) ||
	    __get_user (t.shift, &(((struct timex32 *)A(txc_p))->shift)))
		return -EFAULT;
	set_fs (KERNEL_DS);
	ret = sys_adjtimex(&t);
	set_fs (old_fs);
	if ((unsigned)ret >= 0 && (
	    __put_user (t.modes, &(((struct timex32 *)A(txc_p))->modes)) ||
	    __put_user (t.offset, &(((struct timex32 *)A(txc_p))->offset)) ||
	    __put_user (t.freq, &(((struct timex32 *)A(txc_p))->freq)) ||
	    __put_user (t.maxerror, &(((struct timex32 *)A(txc_p))->maxerror)) ||
	    __put_user (t.esterror, &(((struct timex32 *)A(txc_p))->esterror)) ||
	    __put_user (t.status, &(((struct timex32 *)A(txc_p))->status)) ||
	    __put_user (t.constant, &(((struct timex32 *)A(txc_p))->constant)) ||
	    __put_user (t.precision, &(((struct timex32 *)A(txc_p))->precision)) ||
	    __put_user (t.tolerance, &(((struct timex32 *)A(txc_p))->tolerance)) ||
	    __put_user (t.time.tv_sec, &(((struct timex32 *)A(txc_p))->time.tv_sec)) ||
	    __put_user (t.time.tv_usec, &(((struct timex32 *)A(txc_p))->time.tv_usec)) ||
	    __put_user (t.tick, &(((struct timex32 *)A(txc_p))->tick)) ||
	    __put_user (t.ppsfreq, &(((struct timex32 *)A(txc_p))->ppsfreq)) ||
	    __put_user (t.jitter, &(((struct timex32 *)A(txc_p))->jitter)) ||
	    __put_user (t.shift, &(((struct timex32 *)A(txc_p))->shift)) ||
	    __put_user (t.stabil, &(((struct timex32 *)A(txc_p))->stabil)) ||
	    __put_user (t.jitcnt, &(((struct timex32 *)A(txc_p))->jitcnt)) ||
	    __put_user (t.calcnt, &(((struct timex32 *)A(txc_p))->calcnt)) ||
	    __put_user (t.errcnt, &(((struct timex32 *)A(txc_p))->errcnt)) ||
	    __put_user (t.stbcnt, &(((struct timex32 *)A(txc_p))->stbcnt))))
		return -EFAULT;
	return ret;
}

asmlinkage int sys32_msync(u32 start, __kernel_size_t32 len, int flags)
{
	return sys_msync((unsigned long)start, (size_t)len, flags);
}

asmlinkage int sys32_mlock(u32 start, __kernel_size_t32 len)
{
	return sys_mlock((unsigned long)start, (size_t)len);
}

asmlinkage int sys32_munlock(u32 start, __kernel_size_t32 len)
{
	return sys_munlock((unsigned long)start, (size_t)len);
}

asmlinkage unsigned long sparc32_brk(u32 brk)
{
	return sys_brk((unsigned long)brk);
}

asmlinkage int sys32_munmap(u32 addr, __kernel_size_t32 len)
{
	return sys_munmap((unsigned long)addr, (size_t)len);
}

asmlinkage int sys32_mprotect(u32 start, __kernel_size_t32 len, u32 prot)
{
	return sys_mprotect((unsigned long)start, (size_t)len, (unsigned long)prot);
}

asmlinkage unsigned long sys32_mremap(u32 addr, u32 old_len, u32 new_len, u32 flags)
{
	return sys_mremap((unsigned long)addr, (unsigned long)old_len, (unsigned long)new_len, (unsigned long)flags);
}

asmlinkage int sys32_swapoff(u32 specialfile)
{
	return sys_swapoff((const char *)A(specialfile));
}

asmlinkage int sys32_swapon(u32 specialfile, int swap_flags)
{
	return sys_swapon((const char *)A(specialfile), swap_flags);
}

asmlinkage int sys32_bind(int fd, u32 umyaddr, int addrlen)
{
	/* sockaddr is the same :)) */
	return sys_bind(fd, (struct sockaddr *)A(umyaddr), addrlen);
}

asmlinkage int sys32_accept(int fd, u32 upeer_sockaddr, u32 upeer_addrlen)
{
	return sys_accept(fd, (struct sockaddr *)A(upeer_sockaddr), (int *)A(upeer_addrlen));
}

asmlinkage int sys32_connect(int fd, u32 uservaddr, int addrlen)
{
	return sys_connect(fd, (struct sockaddr *)A(uservaddr), addrlen);
}

asmlinkage int sys32_getsockname(int fd, u32 usockaddr, u32 usockaddr_len)
{
	return sys_getsockname(fd, (struct sockaddr *)A(usockaddr), (int *)A(usockaddr_len));
}

asmlinkage int sys32_getpeername(int fd, u32 usockaddr, u32 usockaddr_len)
{
	return sys_getpeername(fd, (struct sockaddr *)A(usockaddr), (int *)A(usockaddr_len));
}

asmlinkage int sys32_send(int fd, u32 buff, __kernel_size_t32 len, unsigned flags)
{
	return sys_send(fd, (void *)A(buff), (size_t)len, flags);
}

asmlinkage int sys32_sendto(int fd, u32 buff, __kernel_size_t32 len, unsigned flags, u32 addr, int addr_len)
{
	return sys_sendto(fd, (void *)A(buff), (size_t)len, flags, (struct sockaddr *)A(addr), addr_len);
}

asmlinkage int sys32_recv(int fd, u32 ubuf, __kernel_size_t32 size, unsigned flags)
{
	return sys_recv(fd, (void *)A(ubuf), (size_t)size, flags);
}

asmlinkage int sys32_recvfrom(int fd, u32 ubuf, __kernel_size_t32 size, unsigned flags, u32 addr, u32 addr_len)
{
	return sys_recvfrom(fd, (void *)A(ubuf), (size_t)size, flags, (struct sockaddr *)A(addr), (int *)A(addr_len));
}
 
asmlinkage int sys32_setsockopt(int fd, int level, int optname, u32 optval, int optlen)
{
	/* XXX handle ip_fw32->ip_fw conversion for IP firewalling and accounting.
	       Do it using some macro in ip_sockglue.c
	   Other optval arguments are mostly just ints or 32<->64bit transparent */
	return sys_setsockopt(fd, level, optname, (char *)A(optval), optlen);
}

asmlinkage int sys32_getsockopt(int fd, int level, int optname, u32 optval, u32 optlen)
{
	return sys_getsockopt(fd, level, optname, (char *)A(optval), (int *)A(optlen));
}

struct msghdr32 {
        u32               msg_name;
        int               msg_namelen;
        u32               msg_iov;
        __kernel_size_t32 msg_iovlen;
        u32               msg_control;
        __kernel_size_t32 msg_controllen;
        unsigned          msg_flags;
};

struct cmsghdr32 {
        __kernel_size_t32 cmsg_len;
        int               cmsg_level;
        int               cmsg_type;
        unsigned char     cmsg_data[0];
};

asmlinkage int sys32_sendmsg(int fd, u32 msg, unsigned flags)
{
	struct msghdr m;
	int count;
	struct iovec *v;
	struct iovec vf[UIO_FASTIOV];
	u32 i, vector;
	long ret;
	unsigned long old_fs;
	
	if (get_user ((long)m.msg_name, &(((struct msghdr32 *)A(msg))->msg_name)) ||
	    __get_user (m.msg_namelen, &(((struct msghdr32 *)A(msg))->msg_namelen)) ||
	    __get_user (vector, &(((struct msghdr32 *)A(msg))->msg_iov)) ||
	    __get_user (m.msg_iovlen, &(((struct msghdr32 *)A(msg))->msg_iovlen)) ||
	    __get_user ((long)m.msg_control, &(((struct msghdr32 *)A(msg))->msg_control)) ||
	    __get_user (m.msg_controllen, &(((struct msghdr32 *)A(msg))->msg_controllen)) ||
	    __get_user (m.msg_flags, &(((struct msghdr32 *)A(msg))->msg_flags)))
		return -EFAULT;
	
	count = m.msg_iovlen;
	if (!count) return 0; if (count > UIO_MAXIOV) return -EINVAL;
	if (count <= UIO_FASTIOV)
		v = vf;
	else {
		lock_kernel ();
		v = kmalloc (count * sizeof (struct iovec), GFP_KERNEL);
		if (!v) {
			ret = -ENOMEM;
			goto out;
		}
	}

	for (i = 0; i < count; i++) {
		if (__get_user ((unsigned long)(v[i].iov_base), &((((struct iovec32 *)A(vector))+i)->iov_base)) ||
		    __get_user (v[i].iov_len, &((((struct iovec32 *)A(vector))+i)->iov_len))) {
		    	ret = -EFAULT;
		    	goto out;
		}
	}
	
	m.msg_iov = v;

	if (m.msg_controllen) {
		/* XXX Handle msg_control stuff... Or should that go into ip_sockglue.c etc.? */
	}
	old_fs = get_fs();
	set_fs (KERNEL_DS);
	ret = sys_sendmsg(fd, &m, flags);
	set_fs (old_fs);
out:
	if (count > UIO_FASTIOV) {
		kfree (v);
		unlock_kernel ();
	}
	return ret;
}

asmlinkage int sys32_recvmsg(int fd, u32 msg, unsigned int flags)
{
	struct msghdr m;
	int count;
	struct iovec *v;
	struct iovec vf[UIO_FASTIOV];
	u32 i, vector;
	long ret;
	unsigned long old_fs;
	
	if (get_user ((long)m.msg_name, &(((struct msghdr32 *)A(msg))->msg_name)) ||
	    __get_user (m.msg_namelen, &(((struct msghdr32 *)A(msg))->msg_namelen)) ||
	    __get_user (vector, &(((struct msghdr32 *)A(msg))->msg_iov)) ||
	    __get_user (m.msg_iovlen, &(((struct msghdr32 *)A(msg))->msg_iovlen)) ||
	    __get_user ((long)m.msg_control, &(((struct msghdr32 *)A(msg))->msg_control)) ||
	    __get_user (m.msg_controllen, &(((struct msghdr32 *)A(msg))->msg_controllen)) ||
	    __get_user (m.msg_flags, &(((struct msghdr32 *)A(msg))->msg_flags)))
		return -EFAULT;
	
	count = m.msg_iovlen;
	if (!count) return 0; if (count > UIO_MAXIOV) return -EINVAL;
	if (count <= UIO_FASTIOV)
		v = vf;
	else {
		lock_kernel ();
		v = kmalloc (count * sizeof (struct iovec), GFP_KERNEL);
		if (!v) {
			ret = -ENOMEM;
			goto out;
		}
	}

	for (i = 0; i < count; i++) {
		if (__get_user ((unsigned long)(v[i].iov_base), &((((struct iovec32 *)A(vector))+i)->iov_base)) ||
		    __get_user (v[i].iov_len, &((((struct iovec32 *)A(vector))+i)->iov_len))) {
		    	ret = -EFAULT;
		    	goto out;
		}
	}
	
	m.msg_iov = v;

	if (m.msg_controllen) {
		/* XXX Handle msg_control stuff... Or should that go into ip_sockglue.c etc.? */
	}
	old_fs = get_fs();
	set_fs (KERNEL_DS);
	ret = sys_recvmsg(fd, &m, flags);
	set_fs (old_fs);
	if (ret >= 0) {
		/* XXX Handle msg_control stuff... */
		if (put_user (m.msg_flags, &(((struct msghdr32 *)A(msg))->msg_flags)) ||
		    __put_user (m.msg_controllen, &(((struct msghdr32 *)A(msg))->msg_controllen)))
			return -EFAULT;
	}
out:
	if (count > UIO_FASTIOV) {
		kfree (v);
		unlock_kernel ();
	}
	return ret;
}

asmlinkage int sys32_socketcall(int call, u32 args)
{
	static unsigned char nargs[18]={0,3,3,3,2,3,3,3,
				        4,4,4,6,6,2,5,5,3,3};
	u32 a[6];
	u32 a0,a1;
	int err = -EINVAL;
	int i;
				 
	lock_kernel();
	if(call<1||call>SYS_RECVMSG)
		goto out;
	err = -EFAULT;

	for (i = 0; i < nargs[call]; i++, args += sizeof (u32))
		if (get_user(a[i], (u32 *)A(args)))
			goto out;
		
	a0=a[0];
	a1=a[1];
	
	switch(call) 
	{
		case SYS_SOCKET:
			err = sys_socket(a0, a1, a[2]);
			break;
		case SYS_BIND:
			err = sys32_bind(a0, a1, a[2]);
			break;
		case SYS_CONNECT:
			err = sys32_connect(a0, a1, a[2]);
			break;
		case SYS_LISTEN:
			err = sys_listen(a0, a1);
			break;
		case SYS_ACCEPT:
			err = sys32_accept(a0, a1, a[2]);
			break;
		case SYS_GETSOCKNAME:
			err = sys32_getsockname(a0, a1, a[2]);
			break;
		case SYS_GETPEERNAME:
			err = sys32_getpeername(a0, a1, a[2]);
			break;
		case SYS_SOCKETPAIR:
			err = sys_socketpair(a0, a1, a[2], (int *)A(a[3]));
			break;
		case SYS_SEND:
			err = sys32_send(a0, a1, a[2], a[3]);
			break;
		case SYS_SENDTO:
			err = sys32_sendto(a0, a1, a[2], a[3], a[4], a[5]);
			break;
		case SYS_RECV:
			err = sys32_recv(a0, a1, a[2], a[3]);
			break;
		case SYS_RECVFROM:
			err = sys32_recvfrom(a0, a1, a[2], a[3], a[4], a[5]);
			break;
		case SYS_SHUTDOWN:
			err = sys_shutdown(a0,a1);
			break;
		case SYS_SETSOCKOPT:
			err = sys32_setsockopt(a0, a1, a[2], a[3], a[4]);
			break;
		case SYS_GETSOCKOPT:
			err = sys32_getsockopt(a0, a1, a[2], a[3], a[4]);
			break;
		case SYS_SENDMSG:
			err = sys32_sendmsg(a0, a1, a[2]);
			break;
		case SYS_RECVMSG:
			err = sys32_recvmsg(a0, a1, a[2]);
			break;
		default:
			err = -EINVAL;
			break;
	}
out:
	unlock_kernel();
	return err;
}

extern void check_pending(int signum);

asmlinkage int sparc32_sigaction (int signum, u32 action, u32 oldaction)
{
	struct sigaction32 new_sa, old_sa;
	struct sigaction *p;
	int err = -EINVAL;

	lock_kernel();
	if(signum < 0) {
		current->tss.new_signal = 1;
		signum = -signum;
	}

	if (signum<1 || signum>32)
		goto out;
	p = signum - 1 + current->sig->action;
	if (action) {
		err = -EINVAL;
		if (signum==SIGKILL || signum==SIGSTOP)
			goto out;
		err = -EFAULT;
		if(copy_from_user(&new_sa, A(action), sizeof(struct sigaction32)))
			goto out;
		if (((__sighandler_t)A(new_sa.sa_handler)) != SIG_DFL && 
		    ((__sighandler_t)A(new_sa.sa_handler)) != SIG_IGN) {
			err = verify_area(VERIFY_READ, (__sighandler_t)A(new_sa.sa_handler), 1);
			if (err)
				goto out;
		}
	}

	if (oldaction) {
		err = -EFAULT;
		old_sa.sa_handler = (unsigned)(u64)(p->sa_handler);
		old_sa.sa_mask = (sigset_t32)(p->sa_mask);
		old_sa.sa_flags = (unsigned)(p->sa_flags);
		old_sa.sa_restorer = (unsigned)(u64)(p->sa_restorer);
		if (copy_to_user(A(oldaction), p, sizeof(struct sigaction32)))
			goto out;	
	}

	if (action) {
		p->sa_handler = (__sighandler_t)A(new_sa.sa_handler);
		p->sa_mask = (sigset_t)(new_sa.sa_mask);
		p->sa_flags = new_sa.sa_flags;
		p->sa_restorer = (void (*)(void))A(new_sa.sa_restorer);
		check_pending(signum);
	}

	err = 0;
out:
	unlock_kernel();
	return err;
}

asmlinkage int sys32_nfsservctl(int cmd, u32 argp, u32 resp)
{
	/* XXX handle argp and resp args */
	return sys_nfsservctl(cmd, (void *)A(argp), (void *)A(resp));
}

struct ncp_mount_data32 {
        int version;
        unsigned int ncp_fd;
        __kernel_uid_t32 mounted_uid;
        __kernel_pid_t32 wdog_pid;
        unsigned char mounted_vol[NCP_VOLNAME_LEN + 1];
        unsigned int time_out;
        unsigned int retry_count;
        unsigned int flags;
        __kernel_uid_t32 uid;
        __kernel_gid_t32 gid;
        __kernel_mode_t32 file_mode;
        __kernel_mode_t32 dir_mode;
};

void *do_ncp_super_data_conv(void *raw_data)
{
	struct ncp_mount_data *n = (struct ncp_mount_data *)raw_data;
	struct ncp_mount_data32 *n32 = (struct ncp_mount_data32 *)raw_data;

	n->dir_mode = n32->dir_mode;
	n->file_mode = n32->file_mode;
	n->gid = n32->gid;
	n->uid = n32->uid;
	memmove (n->mounted_vol, n32->mounted_vol, (sizeof (n32->mounted_vol) + 3 * sizeof (unsigned int)));
	n->wdog_pid = n32->wdog_pid;
	n->mounted_uid = n32->mounted_uid;
	return raw_data;
}

struct smb_mount_data32 {
        int version;
        unsigned int fd;
        __kernel_uid_t32 mounted_uid;
        struct sockaddr_in addr;
        char server_name[17];
        char client_name[17];
        char service[64];
        char root_path[64];
        char username[64];
        char password[64];
        char domain[64];
        unsigned short max_xmit;
        __kernel_uid_t32 uid;
        __kernel_gid_t32 gid;
        __kernel_mode_t32 file_mode;
        __kernel_mode_t32 dir_mode;
};

void *do_smb_super_data_conv(void *raw_data)
{
	struct smb_mount_data *s = (struct smb_mount_data *)raw_data;
	struct smb_mount_data32 *s32 = (struct smb_mount_data32 *)raw_data;

	s->dir_mode = s32->dir_mode;
	s->file_mode = s32->file_mode;
	s->gid = s32->gid;
	s->uid = s32->uid;
	memmove (&s->addr, &s32->addr, (((long)&s->uid) - ((long)&s->addr)));
	s->mounted_uid = s32->mounted_uid;
	return raw_data;
}