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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#![allow(dead_code)]

// This file contains the kernel syscalls as they are defined in the kernel source with
// some minor exceptions which are documented below.

use crate::kty::{
    self,
    bpf_attr, cap_user_data_t, cap_user_header_t, clockid_t, c_void, epoll_event, gid_t,
    key_serial_t, k_int, k_uint, k_ulong, loff_t, sigset_t, size_t, timespec, timex,
    uid_t, umode_t, c_char, aio_context_t, clock_t, fd_set, file_handle, getcpu_cache,
    iocb, io_event, iovec, itimerspec, itimerval, kexec_segment, k_long,
    linux_dirent64, mq_attr, mqd_t, new_utsname, off_t,
    perf_event_attr, pid_t, pollfd, qid_t, rlimit, rlimit64,
    robust_list_head, rusage, __s32, sched_attr, sched_param, sigaction, siginfo_t,
    ssize_t, stack_t, statfs, sysinfo, timer_t,
    timeval, timezone, tms, k_uchar,
};

use crate::syscall::raw::arch::{SCT};

pub unsafe fn acct(name: *const c_char) -> k_int {
    call!(kty::__NR_acct, name) as k_int
}

pub unsafe fn add_key(_type: *const c_char, _description: *const c_char,
                      _payload: *const c_void, plen: size_t,
                      ringid: key_serial_t) -> key_serial_t {
    call!(kty::__NR_add_key, _type, _description, _payload, plen, ringid) as key_serial_t
}

pub unsafe fn adjtimex(txc_p: *mut timex) -> k_int {
    call!(kty::__NR_adjtimex, txc_p) as k_int
}

pub unsafe fn bpf(cmd: k_int, uattr: *mut bpf_attr, size: k_uint) -> k_int {
    call!(kty::__NR_bpf, cmd, uattr, size) as k_int
}

pub unsafe fn brk(brk: k_ulong) -> k_int {
    call!(kty::__NR_brk, brk) as k_int
}

pub unsafe fn capget(header: cap_user_header_t, dataptr: cap_user_data_t) -> k_int {
    call!(kty::__NR_capget, header, dataptr) as k_int
}

pub unsafe fn capset(header: cap_user_header_t, data: cap_user_data_t) -> k_int {
    call!(kty::__NR_capset, header, data) as k_int
}

pub unsafe fn chdir(filename: *const c_char) -> k_int {
    call!(kty::__NR_chdir, filename) as k_int
}

pub unsafe fn chroot(filename: *const c_char) -> k_int {
    call!(kty::__NR_chroot, filename) as k_int
}

pub unsafe fn clock_adjtime(which_clock: clockid_t, utx: *mut timex) -> k_int {
    call!(kty::__NR_clock_adjtime, which_clock, utx) as k_int
}

pub unsafe fn clock_getres(which_clock: clockid_t, tp: *mut timespec) -> k_int {
    call!(kty::__NR_clock_getres, which_clock, tp) as k_int
}

pub unsafe fn clock_gettime(which_clock: clockid_t, tp: *mut timespec) -> k_int {
    call!(kty::__NR_clock_gettime, which_clock, tp) as k_int
}

pub unsafe fn clock_nanosleep(which_clock: clockid_t, flags: k_int, rqtp: *const timespec,
                              rmtp: *mut timespec) -> k_int {
    call!(kty::__NR_clock_nanosleep, which_clock, flags, rqtp, rmtp) as k_int
}

pub unsafe fn clock_settime(which_clock: clockid_t, tp: *const timespec) -> k_int {
    call!(kty::__NR_clock_settime, which_clock, tp) as k_int
}

pub unsafe fn close(fd: k_uint) -> k_int {
    call!(kty::__NR_close, fd) as k_int
}

pub unsafe fn delete_module(name_user: *const c_char, flags: k_uint) -> k_int {
    call!(kty::__NR_delete_module, name_user, flags) as k_int
}

pub unsafe fn dup3(oldfd: k_uint, newfd: k_uint, flags: k_int) -> k_int {
    call!(kty::__NR_dup3, oldfd, newfd, flags) as k_int
}

pub unsafe fn dup(fildes: k_uint) -> k_int {
    call!(kty::__NR_dup, fildes) as k_int
}

pub unsafe fn epoll_create1(flags: k_int) -> k_int {
    call!(kty::__NR_epoll_create1, flags) as k_int
}

pub unsafe fn epoll_ctl(epfd: k_int, op: k_int, fd: k_int,
                        event: *mut epoll_event) -> k_int {
    call!(kty::__NR_epoll_ctl, epfd, op, fd, event) as k_int
}

pub unsafe fn epoll_pwait(epfd: k_int, events: *mut epoll_event, maxevents: k_int,
                          timeout: k_int, sigmask: *const sigset_t,
                          sigsetsize: size_t) -> k_int {
    call!(kty::__NR_epoll_pwait, epfd, events, maxevents, timeout, sigmask,
          sigsetsize) as k_int
}

pub unsafe fn eventfd2(count: k_uint, flags: k_int) -> k_int {
    call!(kty::__NR_eventfd2, count, flags) as k_int
}

pub unsafe fn execveat(fd: k_int, filename: *const c_char, argv: *const *const c_char,
                       envp: *const *const c_char, flags: k_int) -> k_int {
    call!(kty::__NR_execveat, fd, filename, argv, envp, flags) as k_int
}

pub unsafe fn execve(filename: *const c_char, argv: *const *const c_char,
                     envp: *const *mut c_char) -> k_int {
    call!(kty::__NR_execve, filename, argv, envp) as k_int
}

pub unsafe fn exit(error_code: k_int) {
    call!(kty::__NR_exit, error_code);
}

pub unsafe fn exit_group(error_code: k_int) {
    call!(kty::__NR_exit_group, error_code);
}

pub unsafe fn faccessat(dfd: k_int, filename: *const c_char, mode: k_int) -> k_int {
    call!(kty::__NR_faccessat, dfd, filename, mode) as k_int
}

pub unsafe fn fanotify_init(flags: k_uint, event_f_flags: k_uint) -> k_int {
    call!(kty::__NR_fanotify_init, flags, event_f_flags) as k_int
}

pub unsafe fn fchdir(fd: k_uint) -> k_int {
    call!(kty::__NR_fchdir, fd) as k_int
}

pub unsafe fn fchmodat(dfd: k_int, filename: *const c_char, mode: umode_t) -> k_int {
    call!(kty::__NR_fchmodat, dfd, filename, mode) as k_int
}

pub unsafe fn fchmod(fd: k_uint, mode: umode_t) -> k_int {
    call!(kty::__NR_fchmod, fd, mode) as k_int
}

pub unsafe fn fchownat(dfd: k_int, filename: *const c_char, user: uid_t, group: gid_t,
                       flag: k_int) -> k_int {
    call!(kty::__NR_fchownat, dfd, filename, user, group, flag) as k_int
}

pub unsafe fn fchown(fd: k_uint, user: uid_t, group: gid_t) -> k_int {
    call!(kty::__NR_fchown, fd, user, group) as k_int
}

pub unsafe fn fcntl(fd: k_uint, cmd: k_uint, arg: k_ulong) -> k_int {
    call!(kty::__NR_fcntl, fd, cmd, arg) as k_int
}

pub unsafe fn fdatasync(fd: k_uint) -> k_int {
    call!(kty::__NR_fdatasync, fd) as k_int
}

pub unsafe fn fgetxattr(fd: k_int, name: *const c_char, value: *mut c_void,
                        size: size_t) -> ssize_t {
    call!(kty::__NR_fgetxattr, fd, name, value, size) as ssize_t
}

pub unsafe fn finit_module(fd: k_int, uargs: *const c_char, flags: k_int) -> k_int {
    call!(kty::__NR_finit_module, fd, uargs, flags) as k_int
}

pub unsafe fn flistxattr(fd: k_int, list: *mut c_char, size: size_t) -> ssize_t {
    call!(kty::__NR_flistxattr, fd, list, size) as ssize_t
}

pub unsafe fn flock(fd: k_uint, cmd: k_uint) -> k_int {
    call!(kty::__NR_flock, fd, cmd) as k_int
}

pub unsafe fn fremovexattr(fd: k_int, name: *const c_char) -> k_int {
    call!(kty::__NR_fremovexattr, fd, name) as k_int
}

pub unsafe fn fsetxattr(fd: k_int, name: *const c_char, value: *const c_void,
                        size: size_t, flags: k_int) -> k_int {
    call!(kty::__NR_fsetxattr, fd, name, value, size, flags) as k_int
}

pub unsafe fn fstatfs(fd: k_uint, buf: *mut statfs) -> k_int {
    call!(kty::__NR_fstatfs, fd, buf) as k_int
}

pub unsafe fn fsync(fd: k_uint) -> k_int {
    call!(kty::__NR_fsync, fd) as k_int
}

// length is k_ulong in the kernel but loff_t here for easier cross platform code
pub unsafe fn ftruncate(fd: k_uint, length: loff_t) -> k_int {
    call!(kty::__NR_ftruncate, fd, length) as k_int
}

pub unsafe fn futex(uaddr: *mut u32, op: k_int, val: u32, utime: *mut timespec,
                    uaddr2: *mut u32, val3: u32) -> k_int {
    call!(kty::__NR_futex, uaddr, op, val, utime, uaddr2, val3) as k_int
}

pub unsafe fn getcpu(cpup: *mut k_uint, nodep: *mut k_uint,
                     unused: *mut getcpu_cache) -> k_int {
    call!(kty::__NR_getcpu, cpup, nodep, unused) as k_int
}

pub unsafe fn getcwd(buf: *mut c_char, size: k_ulong) -> k_int {
    call!(kty::__NR_getcwd, buf, size) as k_int
}

pub unsafe fn getdents64(fd: k_uint, dirent: *mut linux_dirent64,
                         count: k_uint) -> k_int {
    call!(kty::__NR_getdents64, fd, dirent, count) as k_int
}

pub unsafe fn getegid() -> gid_t {
    call!(kty::__NR_getegid) as gid_t
}

pub unsafe fn geteuid() -> uid_t {
    call!(kty::__NR_geteuid) as uid_t
}

pub unsafe fn getgid() -> gid_t {
    call!(kty::__NR_getgid) as gid_t
}

pub unsafe fn getgroups(gidsetsize: k_int, grouplist: *mut gid_t) -> k_int {
    call!(kty::__NR_getgroups, gidsetsize, grouplist) as k_int
}

pub unsafe fn getitimer(which: k_int, value: *mut itimerval) -> k_int {
    call!(kty::__NR_getitimer, which, value) as k_int
}

pub unsafe fn get_mempolicy(policy: *mut k_int, nmask: *mut k_ulong, maxnode: k_ulong,
                            addr: k_ulong, flags: k_ulong) -> k_int {
    call!(kty::__NR_get_mempolicy, policy, nmask, maxnode, addr, flags) as k_int
}

pub unsafe fn getpgid(pid: pid_t) -> pid_t {
    call!(kty::__NR_getpgid, pid) as pid_t
}

pub unsafe fn getpid() -> pid_t {
    call!(kty::__NR_getpid) as pid_t
}

pub unsafe fn getppid() -> pid_t {
    call!(kty::__NR_getppid) as pid_t
}

pub unsafe fn getpriority(which: k_int, who: k_int) -> k_int {
    call!(kty::__NR_getpriority, which, who) as k_int
}

pub unsafe fn getrandom(buf: *mut c_char, count: size_t, flags: k_uint) -> k_int {
    call!(kty::__NR_getrandom, buf, count, flags) as k_int
}

pub unsafe fn getresgid(rgidp: *mut gid_t, egidp: *mut gid_t,
                        sgidp: *mut gid_t) -> k_int {
    call!(kty::__NR_getresgid, rgidp, egidp, sgidp) as k_int
}

pub unsafe fn getresuid(ruidp: *mut uid_t, euidp: *mut uid_t,
                        suidp: *mut uid_t) -> k_int {
    call!(kty::__NR_getresuid, ruidp, euidp, suidp) as k_int
}

pub unsafe fn getrlimit(resource: k_uint, rlim: *mut rlimit) -> k_int {
    call!(kty::__NR_getrlimit, resource, rlim) as k_int
}

pub unsafe fn get_robust_list(pid: k_int, head_ptr: *mut *mut robust_list_head,
                              len_ptr: *mut size_t) -> k_long {
    call!(kty::__NR_get_robust_list, pid, head_ptr, len_ptr) as k_long
}

pub unsafe fn getrusage(who: k_int, ru: *mut rusage) -> k_int {
    call!(kty::__NR_getrusage, who, ru) as k_int
}

pub unsafe fn getsid(pid: pid_t) -> pid_t {
    call!(kty::__NR_getsid, pid) as pid_t
}

pub unsafe fn gettid() -> pid_t {
    call!(kty::__NR_gettid) as pid_t
}

pub unsafe fn gettimeofday(tv: *mut timeval, tz: *mut timezone) -> k_int {
    call!(kty::__NR_gettimeofday, tv, tz) as k_int
}

pub unsafe fn getuid() -> uid_t {
    call!(kty::__NR_getuid) as uid_t
}

pub unsafe fn getxattr(pathname: *const c_char, name: *const c_char, value: *mut c_void,
                       size: size_t) -> ssize_t {
    call!(kty::__NR_getxattr, pathname, name, value, size) as ssize_t
}

pub unsafe fn init_module(umod: *mut c_void, len: k_ulong,
                          uargs: *const c_char) -> k_int {
    call!(kty::__NR_init_module, umod, len, uargs) as k_int
}

pub unsafe fn inotify_add_watch(fd: k_int, pathname: *const c_char, mask: u32) -> k_int {
    call!(kty::__NR_inotify_add_watch, fd, pathname, mask) as k_int
}

pub unsafe fn inotify_init1(flags: k_int) -> k_int {
    call!(kty::__NR_inotify_init1, flags) as k_int
}

pub unsafe fn inotify_rm_watch(fd: k_int, wd: __s32) -> k_int {
    call!(kty::__NR_inotify_rm_watch, fd, wd) as k_int
}

pub unsafe fn io_cancel(ctx_id: aio_context_t, iocb: *mut iocb,
                        result: *mut io_event) -> k_int {
    call!(kty::__NR_io_cancel, ctx_id, iocb, result) as k_int
}

pub unsafe fn ioctl(fd: k_uint, cmd: k_uint, arg: k_ulong) -> k_int {
    call!(kty::__NR_ioctl, fd, cmd, arg) as k_int
}

pub unsafe fn io_destroy(ctx: aio_context_t) -> k_int {
    call!(kty::__NR_io_destroy, ctx) as k_int
}

pub unsafe fn io_getevents(ctx_id: aio_context_t, min_nr: k_long, nr: k_long,
                           events: *mut io_event, timeout: *mut timespec) -> k_int {
    call!(kty::__NR_io_getevents, ctx_id, min_nr, nr, events, timeout) as k_int
}

pub unsafe fn ioprio_get(which: k_int, who: k_int) -> k_int {
    call!(kty::__NR_ioprio_get, which, who) as k_int
}

pub unsafe fn ioprio_set(which: k_int, who: k_int, ioprio: k_int) -> k_int {
    call!(kty::__NR_ioprio_set, which, who, ioprio) as k_int
}

pub unsafe fn io_setup(nr_events: k_uint, ctxp: *mut aio_context_t) -> k_int {
    call!(kty::__NR_io_setup, nr_events, ctxp) as k_int
}

pub unsafe fn io_submit(ctx_id: aio_context_t, nr: k_long,
                        iocbpp: *mut *mut iocb) -> k_int {
    call!(kty::__NR_io_submit, ctx_id, nr, iocbpp) as k_int
}

pub unsafe fn kcmp(pid1: pid_t, pid2: pid_t, ty: k_int, idx1: k_ulong,
                   idx2: k_ulong) -> k_int {
    call!(kty::__NR_kcmp, pid1, pid2, ty, idx1, idx2) as k_int
}

#[cfg(target_arch = "x86_64")]
pub unsafe fn kexec_file_load(kernel_fd: k_int, initrd_fd: k_int, cmdline_len: k_ulong,
                              cmdline_ptr: *const c_char, flags: k_ulong) -> k_long {
    call!(kty::__NR_kexec_file_load, kernel_fd, initrd_fd, cmdline_len, cmdline_ptr,
          flags) as k_long
}

pub unsafe fn kexec_load(entry: k_ulong, nr_segments: k_ulong,
                         segments: *mut kexec_segment, flags: k_ulong) -> k_long {
    call!(kty::__NR_kexec_load, entry, nr_segments, segments, flags) as k_long
}

pub unsafe fn keyctl(option: k_int, arg2: k_ulong, arg3: k_ulong, arg4: k_ulong,
                     arg5: k_ulong) -> k_long {
    call!(kty::__NR_keyctl, option, arg2, arg3, arg4, arg5) as k_long
}

pub unsafe fn kill(pid: pid_t, sig: k_int) -> k_int {
    call!(kty::__NR_kill, pid, sig) as k_int
}

pub unsafe fn lgetxattr(pathname: *const c_char, name: *const c_char, value: *mut c_void,
                        size: size_t) -> ssize_t {
    call!(kty::__NR_lgetxattr, pathname, name, value, size) as ssize_t
}

pub unsafe fn linkat(olddfd: k_int, oldname: *const c_char, newdfd: k_int,
                     newname: *const c_char, flags: k_int) -> k_int {
    call!(kty::__NR_linkat, olddfd, oldname, newdfd, newname, flags) as k_int
}

pub unsafe fn listxattr(pathname: *const c_char, list: *mut c_char,
                        size: size_t) -> ssize_t {
    call!(kty::__NR_listxattr, pathname, list, size) as ssize_t
}

pub unsafe fn llistxattr(pathname: *const c_char, list: *mut c_char,
                         size: size_t) -> ssize_t {
    call!(kty::__NR_llistxattr, pathname, list, size) as ssize_t
}

pub unsafe fn lremovexattr(pathname: *const c_char, name: *const c_char) -> k_int {
    call!(kty::__NR_lremovexattr, pathname, name) as k_int
}

pub unsafe fn lseek(fd: k_uint, offset: off_t, whence: k_uint) -> off_t {
    call!(kty::__NR_lseek, fd, offset, whence) as off_t
}

pub unsafe fn lsetxattr(pathname: *const c_char, name: *const c_char,
                        value: *const c_void, size: size_t, flags: k_int) -> k_int {
    call!(kty::__NR_lsetxattr, pathname, name, value, size, flags) as k_int
}

pub unsafe fn madvise(start: k_ulong, len_in: size_t, behavior: k_int) -> k_int {
    call!(kty::__NR_madvise, start, len_in, behavior) as k_int
}

pub unsafe fn mbind(start: k_ulong, len: k_ulong, mode: k_ulong, nmask: *const k_ulong,
                    maxnode: k_ulong, flags: k_uint) -> k_long {
    call!(kty::__NR_mbind, start, len, mode, nmask, maxnode, flags) as k_long
}

pub unsafe fn memfd_create(uname: *const c_char, flags: k_uint) -> k_int {
    call!(kty::__NR_memfd_create, uname, flags) as k_int
}

// pub unsafe fn migrate_pages(pid: pid_t, maxnode: k_ulong, old_nodes: *const k_ulong,
//                             new_nodes: *const k_ulong) -> k_long {
//     call!(kty::__NR_migrate_pages, pid, maxnode, old_nodes, new_nodes) as k_long
// }

pub unsafe fn mincore(start: k_ulong, len: size_t, vec: *mut k_uchar) -> k_int {
    call!(kty::__NR_mincore, start, len, vec) as k_int
}

pub unsafe fn mkdirat(dfd: k_int, pathname: *const c_char, mode: umode_t) -> k_int {
    call!(kty::__NR_mkdirat, dfd, pathname, mode) as k_int
}

pub unsafe fn mknodat(dfd: k_int, filename: *const c_char, mode: umode_t,
                      dev: k_uint) -> k_int {
    call!(kty::__NR_mknodat, dfd, filename, mode, dev) as k_int
}

pub unsafe fn mlockall(flags: k_int) -> k_int {
    call!(kty::__NR_mlockall, flags) as k_int
}

pub unsafe fn mlock(start: k_ulong, len: size_t) -> k_int {
    call!(kty::__NR_mlock, start, len) as k_int
}

// pub unsafe fn mmap_pgoff(addr: k_ulong, len: k_ulong, prot: k_ulong, flags: k_ulong,
//                          fd: k_ulong, pgoff: k_ulong) -> k_long {
//     call!(kty::__NR_mmap_pgoff, addr, len, prot, flags, fd, pgoff) as k_long
// }

pub unsafe fn mount(dev_name: *mut c_char, dir_name: *mut c_char, ty: *mut c_char,
                    flags: k_ulong, data: *mut c_void) -> k_int {
    call!(kty::__NR_mount, dev_name, dir_name, ty, flags, data) as k_int
}

pub unsafe fn move_pages(pid: pid_t, nr_pages: k_ulong, pages: *const *mut c_void,
                         nodes: *const k_int, status: *mut k_int,
                         flags: k_int) -> k_long {
    call!(kty::__NR_move_pages, pid, nr_pages, pages, nodes, status, flags) as k_long
}

pub unsafe fn mprotect(start: k_ulong, len: size_t, prot: k_ulong) -> k_int {
    call!(kty::__NR_mprotect, start, len, prot) as k_int
}

pub unsafe fn mq_getsetattr(mqdes: mqd_t, u_mqstat: *const mq_attr,
                            u_omqstat: *mut mq_attr) -> k_int {
    call!(kty::__NR_mq_getsetattr, mqdes, u_mqstat, u_omqstat) as k_int
}

//pub unsafe fn mq_notify(mqdes: mqd_t, u_notification: *const sigevent) -> k_int {
//    call!(kty::__NR_mq_notify, mqdes, u_notification) as k_int
//}

pub unsafe fn mq_open(u_name: *const c_char, oflag: k_int, mode: umode_t,
                      u_attr: *mut mq_attr) -> mqd_t {
    call!(kty::__NR_mq_open, u_name, oflag, mode, u_attr) as mqd_t
}

pub unsafe fn mq_timedreceive(mqdes: mqd_t, u_msg_ptr: *mut c_char, msg_len: size_t,
                              u_msg_prio: *mut k_uint,
                              u_abs_timeout: *const timespec) -> ssize_t {
    call!(kty::__NR_mq_timedreceive, mqdes, u_msg_ptr, msg_len, u_msg_prio,
          u_abs_timeout) as ssize_t
}

pub unsafe fn mq_timedsend(mqdes: mqd_t, u_msg_ptr: *const c_char, msg_len: size_t,
                           msg_prio: k_uint, u_abs_timeout: *const timespec) -> k_int {
    call!(kty::__NR_mq_timedsend, mqdes, u_msg_ptr, msg_len, msg_prio,
          u_abs_timeout) as k_int
}

pub unsafe fn mq_unlink(u_name: *const c_char) -> k_int {
    call!(kty::__NR_mq_unlink, u_name) as k_int
}

pub unsafe fn mremap(addr: k_ulong, old_len: k_ulong, new_len: k_ulong, flags: k_ulong,
                     new_addr: k_ulong) -> *mut c_void {
    call!(kty::__NR_mremap, addr, old_len, new_len, flags, new_addr) as *mut c_void
}

pub unsafe fn msync(start: k_ulong, len: size_t, flags: k_int) -> k_int {
    call!(kty::__NR_msync, start, len, flags) as k_int
}

pub unsafe fn munlockall() -> k_int {
    call!(kty::__NR_munlockall) as k_int
}

pub unsafe fn munlock(start: k_ulong, len: size_t) -> k_int {
    call!(kty::__NR_munlock, start, len) as k_int
}

pub unsafe fn munmap(addr: k_ulong, len: size_t) -> k_int {
    call!(kty::__NR_munmap, addr, len) as k_int
}

pub unsafe fn name_to_handle_at(dfd: k_int, name: *const c_char, handle: *mut file_handle,
                                mnt_id: *mut k_int, flag: k_int) -> k_int {
    call!(kty::__NR_name_to_handle_at, dfd, name, handle, mnt_id, flag) as k_int
}

pub unsafe fn nanosleep(rqtp: *mut timespec, rmtp: *mut timespec) -> k_int {
    call!(kty::__NR_nanosleep, rqtp, rmtp) as k_int
}

pub unsafe fn newuname(name: *mut new_utsname) -> k_int {
    call!(kty::__NR_newuname, name) as k_int
}

pub unsafe fn openat(dfd: k_int, filename: *const c_char, flags: k_int,
                     mode: umode_t) -> k_int {
    call!(kty::__NR_openat, dfd, filename, flags, mode) as k_int
}

pub unsafe fn open_by_handle_at(mountdirfd: k_int, handle: *mut file_handle,
                                flags: k_int) -> k_int {
    call!(kty::__NR_open_by_handle_at, mountdirfd, handle, flags) as k_int
}

// pub unsafe fn pciconfig_read(bus: k_ulong, dfn: k_ulong, off: k_ulong, len: k_ulong,
//                              buf: *mut c_void) -> k_int {
//     call!(kty::__NR_pciconfig_read, bus, dfn, off, len, buf) as k_int
// }
//
// pub unsafe fn pciconfig_write(bus: k_ulong, dfn: k_ulong, off: k_ulong, len: k_ulong,
//                               buf: *mut c_void) -> k_int {
//     call!(kty::__NR_pciconfig_write, bus, dfn, off, len, buf) as k_int
// }

pub unsafe fn perf_event_open(attr_uptr: *mut perf_event_attr, pid: pid_t, cpu: k_int,
                              group_fd: k_int, flags: k_ulong) -> k_int {
    call!(kty::__NR_perf_event_open, attr_uptr, pid, cpu, group_fd, flags) as k_int
}

pub unsafe fn personality(personality: k_uint) -> k_int {
    call!(kty::__NR_personality, personality) as k_int
}

pub unsafe fn pipe2(fildes: *mut k_int, flags: k_int) -> k_int {
    call!(kty::__NR_pipe2, fildes, flags) as k_int
}

pub unsafe fn pivot_root(new_root: *const c_char, put_old: *const c_char) -> k_int {
    call!(kty::__NR_pivot_root, new_root, put_old) as k_int
}

pub unsafe fn ppoll(ufds: *mut pollfd, nfds: k_uint, tsp: *mut timespec,
                    sigmask: *const sigset_t, sigsetsize: size_t) -> k_int {
    call!(kty::__NR_ppoll, ufds, nfds, tsp, sigmask, sigsetsize) as k_int
}

pub unsafe fn prctl(option: k_int, arg2: k_ulong, arg3: k_ulong, arg4: k_ulong,
                    arg5: k_ulong) -> k_int {
    call!(kty::__NR_prctl, option, arg2, arg3, arg4, arg5) as k_int
}

pub unsafe fn preadv(fd: k_ulong, vec: *const iovec, vlen: k_ulong, pos_l: k_ulong,
                     pos_h: k_ulong) -> ssize_t {
    call!(kty::__NR_preadv, fd, vec, vlen, pos_l, pos_h) as ssize_t
}

pub unsafe fn prlimit64(pid: pid_t, resource: k_uint, new_rlim: *const rlimit64,
                        old_rlim: *mut rlimit64) -> k_int {
    call!(kty::__NR_prlimit64, pid, resource, new_rlim, old_rlim) as k_int
}

pub unsafe fn process_vm_readv(pid: pid_t, lvec: *const iovec, liovcnt: k_ulong,
                               rvec: *const iovec, riovcnt: k_ulong,
                               flags: k_ulong) -> ssize_t {
    call!(kty::__NR_process_vm_readv, pid, lvec, liovcnt, rvec, riovcnt, flags) as ssize_t
}

pub unsafe fn process_vm_writev(pid: pid_t, lvec: *const iovec, liovcnt: k_ulong,
                                rvec: *const iovec, riovcnt: k_ulong,
                                flags: k_ulong) -> ssize_t {
    call!(kty::__NR_process_vm_writev, pid, lvec, liovcnt, rvec, riovcnt,
          flags) as ssize_t
}

pub unsafe fn pselect6(n: k_int, inp: *mut fd_set, outp: *mut fd_set, exp: *mut fd_set,
                       tsp: *mut timespec, sig: *mut c_void) -> k_int {
    call!(kty::__NR_pselect6, n, inp, outp, exp, tsp, sig) as k_int
}

pub unsafe fn ptrace(request: k_long, pid: k_long, addr: k_ulong,
                     data: k_ulong) -> k_long {
    call!(kty::__NR_ptrace, request, pid, addr, data) as k_long
}

pub unsafe fn pwritev(fd: k_ulong, vec: *const iovec, vlen: k_ulong, pos_l: k_ulong,
                      pos_h: k_ulong) -> ssize_t {
    call!(kty::__NR_pwritev, fd, vec, vlen, pos_l, pos_h) as ssize_t
}

pub unsafe fn quotactl(cmd: k_uint, special: *const c_char, id: qid_t,
                       addr: *mut c_void) -> k_int {
    call!(kty::__NR_quotactl, cmd, special, id, addr) as k_int
}

pub unsafe fn read(fd: k_uint, buf: *mut c_char, count: size_t) -> ssize_t {
    call!(kty::__NR_read, fd, buf, count) as ssize_t
}

pub unsafe fn readlinkat(dfd: k_int, pathname: *const c_char, buf: *mut c_char,
                         bufsiz: k_int) -> ssize_t {
    call!(kty::__NR_readlinkat, dfd, pathname, buf, bufsiz) as ssize_t
}

pub unsafe fn readv(fd: k_ulong, vec: *const iovec, vlen: k_ulong) -> ssize_t {
    call!(kty::__NR_readv, fd, vec, vlen) as ssize_t
}

pub unsafe fn reboot(magic1: k_int, magic2: k_int, cmd: k_uint,
                     arg: *mut c_void) -> k_int {
    call!(kty::__NR_reboot, magic1, magic2, cmd, arg) as k_int
}

pub unsafe fn remap_file_pages(start: k_ulong, size: k_ulong, prot: k_ulong,
                               pgoff: k_ulong, flags: k_ulong) -> k_int {
    call!(kty::__NR_remap_file_pages, start, size, prot, pgoff, flags) as k_int
}

pub unsafe fn removexattr(pathname: *const c_char, name: *const c_char) -> k_int {
    call!(kty::__NR_removexattr, pathname, name) as k_int
}

pub unsafe fn renameat2(olddfd: k_int, oldname: *const c_char, newdfd: k_int,
                        newname: *const c_char, flags: k_uint) -> k_int {
    call!(kty::__NR_renameat2, olddfd, oldname, newdfd, newname, flags) as k_int
}

pub unsafe fn renameat(olddfd: k_int, oldname: *const c_char, newdfd: k_int,
                       newname: *const c_char) -> k_int {
    call!(kty::__NR_renameat, olddfd, oldname, newdfd, newname) as k_int
}

pub unsafe fn request_key(_type: *const c_char, _description: *const c_char,
                          _callout_info: *const c_char,
                          destringid: key_serial_t) -> key_serial_t {
    call!(kty::__NR_request_key, _type, _description, _callout_info,
          destringid) as key_serial_t
}

pub unsafe fn restart_syscall() -> k_int {
    call!(kty::__NR_restart_syscall) as k_int
}

pub unsafe fn rt_sigaction(sig: k_int, act: *const sigaction, oact: *mut sigaction,
                           sigsetsize: size_t) -> k_int {
    call!(kty::__NR_rt_sigaction, sig, act, oact, sigsetsize) as k_int
}

pub unsafe fn rt_sigpending(uset: *mut sigset_t, sigsetsize: size_t) -> k_int {
    call!(kty::__NR_rt_sigpending, uset, sigsetsize) as k_int
}

pub unsafe fn rt_sigprocmask(how: k_int, nset: *mut sigset_t, oset: *mut sigset_t,
                             sigsetsize: size_t) -> k_int {
    call!(kty::__NR_rt_sigprocmask, how, nset, oset, sigsetsize) as k_int
}

pub unsafe fn rt_sigqueueinfo(pid: pid_t, sig: k_int, uinfo: *mut siginfo_t) -> k_int {
    call!(kty::__NR_rt_sigqueueinfo, pid, sig, uinfo) as k_int
}

pub unsafe fn rt_sigsuspend(unewset: *mut sigset_t, sigsetsize: size_t) -> k_int {
    call!(kty::__NR_rt_sigsuspend, unewset, sigsetsize) as k_int
}

pub unsafe fn rt_sigtimedwait(uthese: *const sigset_t, uinfo: *mut siginfo_t,
                              uts: *const timespec, sigsetsize: size_t) -> k_int {
    call!(kty::__NR_rt_sigtimedwait, uthese, uinfo, uts, sigsetsize) as k_int
}

pub unsafe fn rt_tgsigqueueinfo(tgid: pid_t, pid: pid_t, sig: k_int,
                                uinfo: *mut siginfo_t) -> k_int {
    call!(kty::__NR_rt_tgsigqueueinfo, tgid, pid, sig, uinfo) as k_int
}

pub unsafe fn rt_sigreturn() {
    call!(kty::__NR_rt_sigreturn);
}

pub unsafe fn sched_getaffinity(pid: pid_t, len: k_uint,
                                user_mask_ptr: *mut k_ulong) -> k_int {
    call!(kty::__NR_sched_getaffinity, pid, len, user_mask_ptr) as k_int
}

pub unsafe fn sched_getattr(pid: pid_t, uattr: *mut sched_attr, size: k_uint,
                            flags: k_uint) -> k_int {
    call!(kty::__NR_sched_getattr, pid, uattr, size, flags) as k_int
}

pub unsafe fn sched_getparam(pid: pid_t, param: *mut sched_param) -> k_int {
    call!(kty::__NR_sched_getparam, pid, param) as k_int
}

pub unsafe fn sched_get_priority_max(policy: k_int) -> k_int {
    call!(kty::__NR_sched_get_priority_max, policy) as k_int
}

pub unsafe fn sched_get_priority_min(policy: k_int) -> k_int {
    call!(kty::__NR_sched_get_priority_min, policy) as k_int
}

pub unsafe fn sched_getscheduler(pid: pid_t) -> k_int {
    call!(kty::__NR_sched_getscheduler, pid) as k_int
}

pub unsafe fn sched_rr_get_interval(pid: pid_t, k_interval: *mut timespec) -> k_int {
    call!(kty::__NR_sched_rr_get_interval, pid, k_interval) as k_int
}

pub unsafe fn sched_setaffinity(pid: pid_t, len: k_uint,
                                user_mask_ptr: *mut k_ulong) -> k_int {
    call!(kty::__NR_sched_setaffinity, pid, len, user_mask_ptr) as k_int
}

pub unsafe fn sched_setattr(pid: pid_t, uattr: *mut sched_attr, flags: k_uint) -> k_int {
    call!(kty::__NR_sched_setattr, pid, uattr, flags) as k_int
}

pub unsafe fn sched_setparam(pid: pid_t, param: *mut sched_param) -> k_int {
    call!(kty::__NR_sched_setparam, pid, param) as k_int
}

pub unsafe fn sched_setscheduler(pid: pid_t, policy: k_int,
                                 param: *mut sched_param) -> k_int {
    call!(kty::__NR_sched_setscheduler, pid, policy, param) as k_int
}

pub unsafe fn sched_yield() -> k_int {
    call!(kty::__NR_sched_yield) as k_int
}

pub unsafe fn seccomp(op: k_uint, flags: k_uint, uargs: *const c_char) -> k_int {
    call!(kty::__NR_seccomp, op, flags, uargs) as k_int
}

pub unsafe fn setdomainname(name: *mut c_char, len: k_int) -> k_int {
    call!(kty::__NR_setdomainname, name, len) as k_int
}

pub unsafe fn setfsgid(gid: gid_t) -> k_int {
    call!(kty::__NR_setfsgid, gid) as k_int
}

pub unsafe fn setfsuid(uid: uid_t) -> k_int {
    call!(kty::__NR_setfsuid, uid) as k_int
}

pub unsafe fn setgid(gid: gid_t) -> k_int {
    call!(kty::__NR_setgid, gid) as k_int
}

pub unsafe fn setgroups(gidsetsize: k_int, grouplist: *mut gid_t) -> k_int {
    call!(kty::__NR_setgroups, gidsetsize, grouplist) as k_int
}

pub unsafe fn sethostname(name: *mut c_char, len: k_int) -> k_int {
    call!(kty::__NR_sethostname, name, len) as k_int
}

pub unsafe fn setitimer(which: k_int, value: *mut itimerval,
                        ovalue: *mut itimerval) -> k_int {
    call!(kty::__NR_setitimer, which, value, ovalue) as k_int
}

pub unsafe fn set_mempolicy(mode: k_int, nmask: *const k_ulong,
                            maxnode: k_ulong) -> k_long {
    call!(kty::__NR_set_mempolicy, mode, nmask, maxnode) as k_long
}

pub unsafe fn setns(fd: k_int, nstype: k_int) -> k_int {
    call!(kty::__NR_setns, fd, nstype) as k_int
}

pub unsafe fn setpgid(pid: pid_t, pgid: pid_t) -> k_int {
    call!(kty::__NR_setpgid, pid, pgid) as k_int
}

pub unsafe fn setpriority(which: k_int, who: k_int, niceval: k_int) -> k_int {
    call!(kty::__NR_setpriority, which, who, niceval) as k_int
}

pub unsafe fn setregid(rgid: gid_t, egid: gid_t) -> k_int {
    call!(kty::__NR_setregid, rgid, egid) as k_int
}

pub unsafe fn setresgid(rgid: gid_t, egid: gid_t, sgid: gid_t) -> k_int {
    call!(kty::__NR_setresgid, rgid, egid, sgid) as k_int
}

pub unsafe fn setresuid(ruid: uid_t, euid: uid_t, suid: uid_t) -> k_int {
    call!(kty::__NR_setresuid, ruid, euid, suid) as k_int
}

pub unsafe fn setreuid(ruid: uid_t, euid: uid_t) -> k_int {
    call!(kty::__NR_setreuid, ruid, euid) as k_int
}

pub unsafe fn setrlimit(resource: k_uint, rlim: *mut rlimit) -> k_int {
    call!(kty::__NR_setrlimit, resource, rlim) as k_int
}

pub unsafe fn set_robust_list(head: *mut robust_list_head, len: size_t) -> k_long {
    call!(kty::__NR_set_robust_list, head, len) as k_long
}

pub unsafe fn setsid() -> pid_t {
    call!(kty::__NR_setsid) as pid_t
}

pub unsafe fn set_tid_address(tidptr: *mut k_int) -> k_long {
    call!(kty::__NR_set_tid_address, tidptr) as k_long
}

pub unsafe fn settimeofday(tv: *mut timeval, tz: *mut timezone) -> k_int {
    call!(kty::__NR_settimeofday, tv, tz) as k_int
}

pub unsafe fn setuid(uid: uid_t) -> k_int {
    call!(kty::__NR_setuid, uid) as k_int
}

pub unsafe fn setxattr(pathname: *const c_char, name: *const c_char, value: *const c_void,
                       size: size_t, flags: k_int) -> k_int {
    call!(kty::__NR_setxattr, pathname, name, value, size, flags) as k_int
}

pub unsafe fn signalfd4(ufd: k_int, user_mask: *const sigset_t, sizemask: size_t,
                        flags: k_int) -> k_int {
    call!(kty::__NR_signalfd4, ufd, user_mask, sizemask, flags) as k_int
}

pub unsafe fn sigaltstack(uss: *const stack_t, uoss: *mut stack_t) -> k_int {
    call!(kty::__NR_sigaltstack, uss, uoss) as k_int
}

// There are two of the following and I don't know which one is the correct one. Both are
// deprecated anyway.

//pub unsafe fn sigsuspend(mask: old_sigset_t) -> k_int {
//    call!(kty::__NR_sigsuspend, mask) as k_int
//}
//
//pub unsafe fn sigsuspend(unused1: k_int, unused2: k_int, mask: old_sigset_t) -> k_int {
//    call!(kty::__NR_sigsuspend, unused1, unused2, mask) as k_int
//}

pub unsafe fn splice(fd_in: k_int, off_in: *mut loff_t, fd_out: k_int,
                     off_out: *mut loff_t, len: size_t, flags: k_uint) -> ssize_t {
    call!(kty::__NR_splice, fd_in, off_in, fd_out, off_out, len, flags) as ssize_t
}

pub unsafe fn statfs(pathname: *const c_char, buf: *mut statfs) -> k_int {
    call!(kty::__NR_statfs, pathname, buf) as k_int
}

pub unsafe fn swapoff(specialfile: *const c_char) -> k_int {
    call!(kty::__NR_swapoff, specialfile) as k_int
}

pub unsafe fn swapon(specialfile: *const c_char, swap_flags: k_int) -> k_int {
    call!(kty::__NR_swapon, specialfile, swap_flags) as k_int
}

pub unsafe fn symlinkat(oldname: *const c_char, newdfd: k_int,
                        newname: *const c_char) -> k_int {
    call!(kty::__NR_symlinkat, oldname, newdfd, newname) as k_int
}

pub unsafe fn sync() {
    call!(kty::__NR_sync);
}

pub unsafe fn syncfs(fd: k_int) -> k_int {
    call!(kty::__NR_syncfs, fd) as k_int
}

pub unsafe fn sysinfo(info: *mut sysinfo) -> k_int {
    call!(kty::__NR_sysinfo, info) as k_int
}

pub unsafe fn syslog(ty: k_int, buf: *mut c_char, len: k_int) -> k_int {
    call!(kty::__NR_syslog, ty, buf, len) as k_int
}

pub unsafe fn tee(fdin: k_int, fdout: k_int, len: size_t, flags: k_uint) -> ssize_t {
    call!(kty::__NR_tee, fdin, fdout, len, flags) as ssize_t
}

pub unsafe fn tgkill(tgid: pid_t, pid: pid_t, sig: k_int) -> k_int {
    call!(kty::__NR_tgkill, tgid, pid, sig) as k_int
}

//pub unsafe fn timer_create(which_clock: clockid_t, timer_event_spec: *mut sigevent,
//                           created_timer_id: *mut timer_t) -> k_int {
//    call!(kty::__NR_timer_create, which_clock, timer_event_spec,
//          created_timer_id) as k_int
//}

pub unsafe fn timer_delete(timer_id: timer_t) -> k_int {
    call!(kty::__NR_timer_delete, timer_id) as k_int
}

pub unsafe fn timerfd_create(clockid: k_int, flags: k_int) -> k_int {
    call!(kty::__NR_timerfd_create, clockid, flags) as k_int
}

pub unsafe fn timerfd_gettime(ufd: k_int, otmr: *mut itimerspec) -> k_int {
    call!(kty::__NR_timerfd_gettime, ufd, otmr) as k_int
}

pub unsafe fn timerfd_settime(ufd: k_int, flags: k_int, utmr: *const itimerspec,
                              otmr: *mut itimerspec) -> k_int {
    call!(kty::__NR_timerfd_settime, ufd, flags, utmr, otmr) as k_int
}

pub unsafe fn timer_getoverrun(timer_id: timer_t) -> k_int {
    call!(kty::__NR_timer_getoverrun, timer_id) as k_int
}

pub unsafe fn timer_gettime(timer_id: timer_t, setting: *mut itimerspec) -> k_int {
    call!(kty::__NR_timer_gettime, timer_id, setting) as k_int
}

pub unsafe fn timer_settime(timer_id: timer_t, flags: k_int,
                            new_setting: *const itimerspec,
                            old_setting: *mut itimerspec) -> k_int {
    call!(kty::__NR_timer_settime, timer_id, flags, new_setting, old_setting) as k_int
}

pub unsafe fn times(tbuf: *mut tms) -> clock_t {
    call!(kty::__NR_times, tbuf) as clock_t
}

pub unsafe fn tkill(pid: pid_t, sig: k_int) -> k_int {
    call!(kty::__NR_tkill, pid, sig) as k_int
}

pub unsafe fn truncate(path: *const c_char, length: k_long) -> k_int {
    call!(kty::__NR_truncate, path, length) as k_int
}

pub unsafe fn umask(mask: k_int) -> umode_t {
    call!(kty::__NR_umask, mask) as umode_t
}

pub unsafe fn umount(name: *mut c_char, flags: k_int) -> k_int {
    call!(kty::__NR_umount, name, flags) as k_int
}

pub unsafe fn unlinkat(dfd: k_int, pathname: *const c_char, flag: k_int) -> k_int {
    call!(kty::__NR_unlinkat, dfd, pathname, flag) as k_int
}

pub unsafe fn unshare(unshare_flags: k_ulong) -> k_int {
    call!(kty::__NR_unshare, unshare_flags) as k_int
}

pub unsafe fn utimensat(dfd: k_int, filename: *const c_char, utimes: *const timespec,
                        flags: k_int) -> k_int {
    call!(kty::__NR_utimensat, dfd, filename, utimes, flags) as k_int
}

pub unsafe fn sendfile64(out_fd: k_int, in_fd: k_int, offset: *mut loff_t,
                         count: size_t) -> ssize_t {
    call!(kty::__NR_sendfile64, out_fd, in_fd, offset, count) as ssize_t
}

pub unsafe fn vhangup() -> k_int {
    call!(kty::__NR_vhangup) as k_int
}

pub unsafe fn vmsplice(fd: k_int, iov: *const iovec, nr_segs: k_ulong,
                       flags: k_uint) -> ssize_t {
    call!(kty::__NR_vmsplice, fd, iov, nr_segs, flags) as ssize_t
}

pub unsafe fn waitid(which: k_int, upid: pid_t, infop: *mut siginfo_t, options: k_int,
                     ru: *mut rusage) -> k_int {
    call!(kty::__NR_waitid, which, upid, infop, options, ru) as k_int
}

pub unsafe fn write(fd: k_uint, buf: *const c_char, count: size_t) -> ssize_t {
    call!(kty::__NR_write, fd, buf, count) as ssize_t
}

pub unsafe fn writev(fd: k_ulong, vec: *const iovec, vlen: k_ulong) -> ssize_t {
    call!(kty::__NR_writev, fd, vec, vlen) as ssize_t
}

// 64 bit calls for 32 bit systems
#[cfg(any(target_arch = "x86", target_arch = "arm"))]
pub use self::_64_calls::*;

#[cfg(any(target_arch = "x86", target_arch = "arm"))]
mod _64_calls {
    use kty::{
        self, k_int, c_char, k_ulong, size_t, k_uint, stat64, statfs64, loff_t,
    };
    use ::arch::{SCT};

    pub unsafe fn fcntl64(fd: k_uint, cmd: k_uint, arg: k_ulong) -> k_int {
        call!(kty::__NR_fcntl64, fd, cmd, arg) as k_int
    }

    pub unsafe fn fstat64(fd: k_ulong, statbuf: *mut stat64) -> k_int {
        call!(kty::__NR_fstat64, fd, statbuf) as k_int
    }

    pub unsafe fn fstatat64(dfd: k_int, filename: *const c_char, statbuf: *mut stat64,
                            flag: k_int) -> k_int {
        call!(kty::__NR_fstatat64, dfd, filename, statbuf, flag) as k_int
    }

    pub unsafe fn fstatfs64(fd: k_uint, sz: size_t, buf: *mut statfs64) -> k_int {
        call!(kty::__NR_fstatfs64, fd, sz, buf) as k_int
    }

    pub unsafe fn statfs64(pathname: *const c_char, sz: size_t,
                           buf: *mut statfs64) -> k_int {
        call!(kty::__NR_statfs64, pathname, sz, buf) as k_int
    }

    pub unsafe fn llseek(fd: k_uint, offset_high: k_ulong, offset_low: k_ulong,
                         result: *mut loff_t, whence: k_uint) -> k_int {
        call!(kty::__NR_llseek, fd, offset_high, offset_low, result, whence) as k_int
    }
}

// new calls for 64 bit systems
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
pub use self::new_calls::*;

#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
mod new_calls {
    use crate::kty::{
        self, k_int, c_char, k_uint, stat,
    };
    use crate::syscall::raw::arch::{SCT};

    pub unsafe fn newfstatat(dfd: k_int, filename: *const c_char, statbuf: *mut stat,
                             flag: k_int) -> k_int {
        call!(kty::__NR_newfstatat, dfd, filename, statbuf, flag) as k_int
    }

    pub unsafe fn newfstat(fd: k_uint, statbuf: *mut stat) -> k_int {
        call!(kty::__NR_newfstat, fd, statbuf) as k_int
    }
}

// ipc interface
//
// XXX: This interface is quite complex. See the code in ipc/syscall.c. This MUST be
// audited before it is used.
#[cfg(target_arch = "x86")]
pub use self::ipc_one::*;

#[cfg(target_arch = "x86")]
mod ipc_one {
    use crate::kty::{
        self, k_int, c_char, c_void, IPC_64, msgbuf, k_long, ssize_t, timespec,
        key_t, sembuf, k_ulong, size_t, c_long, msqid64_ds, shmid64_ds, k_uint,
    };
    use crate::syscall::raw::arch::{SCT};

    pub unsafe fn semop(semid: k_int, tsops: *mut sembuf, nsops: k_uint) -> k_int {
        call!(kty::__NR_ipc, kty::SEMOP, semid, nsops, 0, tsops) as k_int
    }

    pub unsafe fn semtimedop(semid: k_int, tsops: *mut sembuf, nsops: k_uint,
                             timeout: *const timespec) -> k_int {
        call!(kty::__NR_ipc, kty::SEMTIMEDOP, semid, nsops, 0, tsops, timeout) as k_int
    }

    pub unsafe fn semget(key: key_t, nsems: k_int, semflg: k_int) -> k_int {
        call!(kty::__NR_ipc, kty::SEMGET, key, nsems, semflg) as k_int
    }

    pub unsafe fn semctl(semid: k_int, semnum: k_int, cmd: k_int, arg: k_ulong) -> k_int {
        // I kid you not: The last argument goes as a pointer that is immediately
        // dereferenced in the kernel.
        call!(kty::__NR_ipc, kty::SEMCTL, semid, semnum, cmd | IPC_64,
              &arg as *const _) as k_int
    }

    pub unsafe fn msgsnd(msqid: k_int, msgp: *mut msgbuf, msgsz: size_t,
                         msgflg: k_int) -> k_int {
        call!(kty::__NR_ipc, kty::MSGSND, msqid, msgsz, msgflg, msgp) as k_int
    }

    pub unsafe fn msgrcv(msqid: k_int, msgp: *mut msgbuf, msgsz: size_t, msgtyp: k_long,
                         msgflg: k_int) -> ssize_t {
        let mut data = [msgp as c_long, msgtyp];
        call!(kty::__NR_ipc, kty::MSGRCV, msqid, msgsz, msgflg,
              data.as_mut_ptr()) as ssize_t
    }

    pub unsafe fn msgget(key: key_t, msgflg: k_int) -> k_int {
        call!(kty::__NR_ipc, kty::MSGGET, key, msgflg) as k_int
    }

    // See shmctl comment
    pub unsafe fn msgctl(msqid: k_int, cmd: k_int, buf: *mut msqid64_ds) -> k_int {
        call!(kty::__NR_ipc, kty::MSGCTL, msqid, cmd | IPC_64, 0, buf, 0) as k_int
    }

    pub unsafe fn shmdt(shmaddr: *mut c_char) -> k_int {
        call!(kty::__NR_ipc, kty::SHMDT, 0, 0, 0, shmaddr) as k_int
    }

    // here the kernel defines shmid_ds instead of shmid64_ds. But shmid_ds is deprecated
    // and glibc and friends will always use shmid64_ds. We have to add the IPC_64 flag to
    // tell the kernel that we're using shmid64_ds.
    pub unsafe fn shmctl(shmid: k_int, cmd: k_int, buf: *mut shmid64_ds) -> k_int {
        call!(kty::__NR_ipc, kty::SHMCTL, shmid, cmd | IPC_64, 0, buf, 0) as k_int
    }

    pub unsafe fn shmget(key: key_t, size: size_t, shmflg: k_int) -> k_int {
        call!(kty::__NR_ipc, kty::SHMGET, key, size, shmflg) as k_int
    }

    pub unsafe fn shmat(shmid: k_int, mut shmaddr: *mut c_char,
                        shmflg: k_int) -> *mut c_void {
        call!(kty::__NR_ipc, kty::SHMAT, shmid, shmflg, &mut shmaddr as *mut _,
              shmaddr) as *mut c_void
    }
}

// separate ipc calls
#[cfg(any(target_arch = "x86_64", target_arch = "arm", target_arch = "aarch64"))]
pub use self::ipc_sep::*;

#[cfg(any(target_arch = "x86_64", target_arch = "arm", target_arch = "aarch64"))]
mod ipc_sep {
    use crate::kty::{
        self, k_int, c_char, c_void, IPC_64, msgbuf, k_long, ssize_t, timespec,
        key_t, sembuf, k_ulong, size_t, msqid64_ds, shmid64_ds, k_uint,
    };
    use crate::syscall::raw::arch::{SCT};

    pub unsafe fn semop(semid: k_int, tsops: *mut sembuf, nsops: k_uint) -> k_int {
        call!(kty::__NR_semop, semid, tsops, nsops) as k_int
    }

    pub unsafe fn semtimedop(semid: k_int, tsops: *mut sembuf, nsops: k_uint,
                             timeout: *const timespec) -> k_int {
        call!(kty::__NR_semtimedop, semid, tsops, nsops, timeout) as k_int
    }

    pub unsafe fn semget(key: key_t, nsems: k_int, semflg: k_int) -> k_int {
        call!(kty::__NR_semget, key, nsems, semflg) as k_int
    }

    pub unsafe fn semctl(semid: k_int, semnum: k_int, cmd: k_int, arg: k_ulong) -> k_int {
        call!(kty::__NR_semctl, semid, semnum, cmd | IPC_64, arg) as k_int
    }

    pub unsafe fn msgsnd(msqid: k_int, msgp: *mut msgbuf, msgsz: size_t,
                         msgflg: k_int) -> k_int {
        call!(kty::__NR_msgsnd, msqid, msgp, msgsz, msgflg) as k_int
    }

    pub unsafe fn msgrcv(msqid: k_int, msgp: *mut msgbuf, msgsz: size_t, msgtyp: k_long,
                         msgflg: k_int) -> ssize_t {
        call!(kty::__NR_msgrcv, msqid, msgp, msgsz, msgtyp, msgflg) as ssize_t
    }

    pub unsafe fn msgget(key: key_t, msgflg: k_int) -> k_int {
        call!(kty::__NR_msgget, key, msgflg) as k_int
    }

    // See shmctl comment
    pub unsafe fn msgctl(msqid: k_int, cmd: k_int, buf: *mut msqid64_ds) -> k_int {
        call!(kty::__NR_msgctl, msqid, cmd | IPC_64, buf) as k_int
    }

    pub unsafe fn shmdt(shmaddr: *mut c_char) -> k_int {
        call!(kty::__NR_shmdt, shmaddr) as k_int
    }

    // here the kernel defines shmid_ds instead of shmid64_ds. But shmid_ds is deprecated
    // and glibc and friends will always use shmid64_ds. We have to add the IPC_64 flag to
    // tell the kernel that we're using shmid64_ds.
    pub unsafe fn shmctl(shmid: k_int, cmd: k_int, buf: *mut shmid64_ds) -> k_int {
        call!(kty::__NR_shmctl, shmid, cmd | IPC_64, buf) as k_int
    }

    pub unsafe fn shmget(key: key_t, size: size_t, shmflg: k_int) -> k_int {
        call!(kty::__NR_shmget, key, size, shmflg) as k_int
    }

    pub unsafe fn shmat(shmid: k_int, shmaddr: *mut c_char,
                        shmflg: k_int) -> *mut c_void {
        call!(kty::__NR_shmat, shmid, shmaddr, shmflg) as *mut c_void
    }
}

// socketcall interface
#[cfg(target_arch = "x86")]
pub use self::sock_one::*;

#[cfg(target_arch = "x86")]
mod sock_one {
    use crate::kty::{
        self, k_int, sockaddr, c_char, c_void, size_t, k_uint, ssize_t, k_ulong, msghdr,
        timespec, mmsghdr,
    };
    use crate::syscall::raw::arch::{SCT};

    macro_rules! socketcall {
        ($nr:expr) => { socketcall!($nr, 0, 0, 0, 0, 0, 0) };
        ($nr:expr, $a1:expr) => { socketcall!($nr, $a1, 0, 0, 0, 0, 0) };
        ($nr:expr, $a1:expr, $a2:expr) => { socketcall!($nr, $a1, $a2, 0, 0, 0, 0) };
        ($nr:expr, $a1:expr, $a2:expr, $a3:expr) => {
            socketcall!($nr, $a1, $a2, $a3, 0, 0, 0)
        };
        ($nr:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr) => {
            socketcall!($nr, $a1, $a2, $a3, $a4, 0, 0)
        };
        ($nr:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr) => {
            socketcall!($nr, $a1, $a2, $a3, $a4, $a5, 0)
        };
        ($nr:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr, $a6:expr) => {{
            let args = [$a1 as k_ulong,  $a2 as k_ulong, $a3 as k_ulong,
                        $a4 as k_ulong,  $a5 as k_ulong, $a6 as k_ulong];
            call!($nr, args.as_ptr())
        }};
    }

    pub unsafe fn socket(family: k_int, ty: k_int, protocol: k_int) -> k_int {
        socketcall!(kty::SYS_SOCKET, family, ty, protocol) as k_int
    }

    pub unsafe fn bind(fd: k_int, umyaddr: *mut sockaddr, addrlen: k_int) -> k_int {
        socketcall!(kty::SYS_BIND, fd, umyaddr, addrlen) as k_int
    }

    pub unsafe fn connect(fd: k_int, uservaddr: *mut sockaddr, addrlen: k_int) -> k_int {
        socketcall!(kty::SYS_CONNECT, fd, uservaddr, addrlen) as k_int
    }

    pub unsafe fn listen(fd: k_int, backlog: k_int) -> k_int {
        socketcall!(kty::SYS_LISTEN, fd, backlog) as k_int
    }

    pub unsafe fn accept4(fd: k_int, upeer_sockaddr: *mut sockaddr,
                          upeer_addrlen: *mut k_int, flags: k_int) -> k_int {
        socketcall!(kty::SYS_ACCEPT4, fd, upeer_sockaddr, upeer_addrlen, flags) as k_int
    }

    pub unsafe fn accept(fd: k_int, upeer_sockaddr: *mut sockaddr,
                         upeer_addrlen: *mut k_int) -> k_int {
        socketcall!(kty::SYS_ACCEPT, fd, upeer_sockaddr, upeer_addrlen) as k_int
    }

    pub unsafe fn getsockname(fd: k_int, usockaddr: *mut sockaddr,
                              usockaddr_len: *mut k_int) -> k_int {
        socketcall!(kty::SYS_GETSOCKNAME, fd, usockaddr, usockaddr_len) as k_int
    }

    pub unsafe fn getsockopt(fd: k_int, level: k_int, optname: k_int,
                             optval: *mut c_char, optlen: *mut k_int) -> k_int {
        socketcall!(kty::SYS_GETSOCKOPT, fd, level, optname, optval, optlen) as k_int
    }

    pub unsafe fn getpeername(fd: k_int, usockaddr: *mut sockaddr,
                              usockaddr_len: *mut k_int) -> k_int {
        socketcall!(kty::SYS_GETPEERNAME, fd, usockaddr, usockaddr_len) as k_int
    }

    pub unsafe fn socketpair(family: k_int, ty: k_int, protocol: k_int,
                             usockvec: *mut k_int) -> k_int {
        socketcall!(kty::SYS_SOCKETPAIR, family, ty, protocol, usockvec) as k_int
    }

    pub unsafe fn recvfrom(fd: k_int, ubuf: *mut c_void, size: size_t, flags: k_uint,
                           addr: *mut sockaddr, addr_len: *mut k_int) -> ssize_t {
        socketcall!(kty::SYS_RECVFROM, fd, ubuf, size, flags, addr, addr_len) as ssize_t
    }

    pub unsafe fn recvmmsg(fd: k_int, mmsg: *mut mmsghdr, vlen: k_uint, flags: k_uint,
                           timeout: *mut timespec) -> ssize_t {
        socketcall!(kty::SYS_RECVMMSG, fd, mmsg, vlen, flags, timeout) as ssize_t
    }

    pub unsafe fn recvmsg(fd: k_int, msg: *mut msghdr, flags: k_uint) -> ssize_t {
        socketcall!(kty::SYS_RECVMSG, fd, msg, flags) as ssize_t
    }

    pub unsafe fn sendmmsg(fd: k_int, mmsg: *mut mmsghdr, vlen: k_uint,
                           flags: k_uint) -> ssize_t {
        socketcall!(kty::SYS_SENDMMSG, fd, mmsg, vlen, flags) as ssize_t
    }

    pub unsafe fn sendmsg(fd: k_int, msg: *mut msghdr, flags: k_uint) -> ssize_t {
        socketcall!(kty::SYS_SENDMSG, fd, msg, flags) as ssize_t
    }

    pub unsafe fn sendto(fd: k_int, buff: *mut c_void, len: size_t, flags: k_uint,
                         addr: *mut sockaddr, addr_len: k_int) -> ssize_t {
        socketcall!(kty::SYS_SENDTO, fd, buff, len, flags, addr, addr_len) as ssize_t
    }

    pub unsafe fn shutdown(fd: k_int, how: k_int) -> k_int {
        socketcall!(kty::SYS_SHUTDOWN, fd, how) as k_int
    }

    pub unsafe fn setsockopt(fd: k_int, level: k_int, optname: k_int,
                             optval: *mut c_char, optlen: k_int) -> k_int {
        socketcall!(kty::SYS_SETSOCKOPT, fd, level, optname, optval, optlen) as k_int
    }
}

// separate socket calls
#[cfg(any(target_arch = "x86_64", target_arch = "arm", target_arch = "aarch64"))]
pub use self::sock_sep::*;

#[cfg(any(target_arch = "x86_64", target_arch = "arm", target_arch = "aarch64"))]
mod sock_sep {
    use crate::kty::{
        self, k_int, sockaddr, c_char, c_void, size_t, k_uint, ssize_t, msghdr,
        timespec, mmsghdr,
    };
    use crate::syscall::raw::arch::{SCT};

    pub unsafe fn socket(family: k_int, ty: k_int, protocol: k_int) -> k_int {
        call!(kty::__NR_socket, family, ty, protocol) as k_int
    }

    pub unsafe fn bind(fd: k_int, umyaddr: *mut sockaddr, addrlen: k_int) -> k_int {
        call!(kty::__NR_bind, fd, umyaddr, addrlen) as k_int
    }

    pub unsafe fn connect(fd: k_int, uservaddr: *mut sockaddr, addrlen: k_int) -> k_int {
        call!(kty::__NR_connect, fd, uservaddr, addrlen) as k_int
    }

    pub unsafe fn listen(fd: k_int, backlog: k_int) -> k_int {
        call!(kty::__NR_listen, fd, backlog) as k_int
    }

    pub unsafe fn accept4(fd: k_int, upeer_sockaddr: *mut sockaddr,
                          upeer_addrlen: *mut k_int, flags: k_int) -> k_int {
        call!(kty::__NR_accept4, fd, upeer_sockaddr, upeer_addrlen, flags) as k_int
    }

    pub unsafe fn accept(fd: k_int, upeer_sockaddr: *mut sockaddr,
                         upeer_addrlen: *mut k_int) -> k_int {
        call!(kty::__NR_accept, fd, upeer_sockaddr, upeer_addrlen) as k_int
    }

    pub unsafe fn getsockname(fd: k_int, usockaddr: *mut sockaddr,
                              usockaddr_len: *mut k_int) -> k_int {
        call!(kty::__NR_getsockname, fd, usockaddr, usockaddr_len) as k_int
    }

    pub unsafe fn getsockopt(fd: k_int, level: k_int, optname: k_int,
                             optval: *mut c_char, optlen: *mut k_int) -> k_int {
        call!(kty::__NR_getsockopt, fd, level, optname, optval, optlen) as k_int
    }

    pub unsafe fn getpeername(fd: k_int, usockaddr: *mut sockaddr,
                              usockaddr_len: *mut k_int) -> k_int {
        call!(kty::__NR_getpeername, fd, usockaddr, usockaddr_len) as k_int
    }

    pub unsafe fn socketpair(family: k_int, ty: k_int, protocol: k_int,
                             usockvec: *mut k_int) -> k_int {
        call!(kty::__NR_socketpair, family, ty, protocol, usockvec) as k_int
    }

    pub unsafe fn recvfrom(fd: k_int, ubuf: *mut c_void, size: size_t, flags: k_uint,
                           addr: *mut sockaddr, addr_len: *mut k_int) -> ssize_t {
        call!(kty::__NR_recvfrom, fd, ubuf, size, flags, addr, addr_len) as ssize_t
    }

    pub unsafe fn recvmmsg(fd: k_int, mmsg: *mut mmsghdr, vlen: k_uint, flags: k_uint,
                           timeout: *mut timespec) -> ssize_t {
        call!(kty::__NR_recvmmsg, fd, mmsg, vlen, flags, timeout) as ssize_t
    }

    pub unsafe fn recvmsg(fd: k_int, msg: *mut msghdr, flags: k_uint) -> ssize_t {
        call!(kty::__NR_recvmsg, fd, msg, flags) as ssize_t
    }

    pub unsafe fn sendmmsg(fd: k_int, mmsg: *mut mmsghdr, vlen: k_uint,
                           flags: k_uint) -> ssize_t {
        call!(kty::__NR_sendmmsg, fd, mmsg, vlen, flags) as ssize_t
    }

    pub unsafe fn sendmsg(fd: k_int, msg: *mut msghdr, flags: k_uint) -> ssize_t {
        call!(kty::__NR_sendmsg, fd, msg, flags) as ssize_t
    }

    pub unsafe fn sendto(fd: k_int, buff: *mut c_void, len: size_t, flags: k_uint,
                         addr: *mut sockaddr, addr_len: k_int) -> ssize_t {
        call!(kty::__NR_sendto, fd, buff, len, flags, addr, addr_len) as ssize_t
    }

    pub unsafe fn shutdown(fd: k_int, how: k_int) -> k_int {
        call!(kty::__NR_shutdown, fd, how) as k_int
    }

    pub unsafe fn setsockopt(fd: k_int, level: k_int, optname: k_int,
                             optval: *mut c_char, optlen: k_int) -> k_int {
        call!(kty::__NR_setsockopt, fd, level, optname, optval, optlen) as k_int
    }
}

// syscalls with 64-bit arguments
//
// these implementations cannot be used on 32 bit systems
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
pub use self::wide::*;

#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
mod wide {
    use crate::kty::{
        self, k_int, c_char, size_t, k_uint, ssize_t, loff_t, __u64,
    };
    use crate::syscall::raw::arch::{SCT};

    #[cfg(any(target_arch = "aarch64"))]
    pub unsafe fn fadvise64_64(fd: k_int, offset: loff_t, len: loff_t,
                               advice: k_int) -> k_int {
        call!(kty::__NR_fadvise64_64, fd, offset, len, advice) as k_int
    }

    #[cfg(any(target_arch = "x86_64"))]
    pub unsafe fn fadvise64(fd: k_int, offset: loff_t, len: size_t,
                            advice: k_int) -> k_int {
        call!(kty::__NR_fadvise64, fd, offset, len, advice) as k_int
    }

    pub unsafe fn fallocate(fd: k_int, mode: k_int, offset: loff_t,
                            len: loff_t) -> k_int {
        call!(kty::__NR_fallocate, fd, mode, offset, len) as k_int
    }

    pub unsafe fn fanotify_mark(fanotify_fd: k_int, flags: k_uint, mask: __u64,
                                dfd: k_int, pathname: *const c_char) -> k_int {
        call!(kty::__NR_fanotify_mark, fanotify_fd, flags, mask, dfd, pathname) as k_int
    }

    // pub unsafe fn ftruncate64(fd: k_uint, length: loff_t) -> k_int {
    //     call!(kty::__NR_ftruncate64, fd, length) as k_int
    // }

    pub unsafe fn lookup_dcookie(cookie64: u64, buf: *mut c_char, len: size_t) -> k_int {
        call!(kty::__NR_lookup_dcookie, cookie64, buf, len) as k_int
    }

    pub unsafe fn pread64(fd: k_uint, buf: *mut c_char, count: size_t,
                          pos: loff_t) -> ssize_t {
        call!(kty::__NR_pread64, fd, buf, count, pos) as ssize_t
    }

    pub unsafe fn pwrite64(fd: k_uint, buf: *const c_char, count: size_t,
                           pos: loff_t) -> ssize_t {
        call!(kty::__NR_pwrite64, fd, buf, count, pos) as ssize_t
    }

    pub unsafe fn readahead(fd: k_int, offset: loff_t, count: size_t) -> ssize_t {
        call!(kty::__NR_readahead, fd, offset, count) as ssize_t
    }

    // pub unsafe fn sync_file_range2(fd: k_int, flags: k_uint, offset: loff_t,
    //                                nbytes: loff_t) -> k_int {
    //     call!(kty::__NR_sync_file_range2, fd, flags, offset, nbytes) as k_int
    // }

    pub unsafe fn sync_file_range(fd: k_int, offset: loff_t, nbytes: loff_t,
                                  flags: k_uint) -> k_int {
        call!(kty::__NR_sync_file_range, fd, offset, nbytes, flags) as k_int
    }

    // pub unsafe fn truncate64(path: *const c_char, length: loff_t) -> k_int {
    //     call!(kty::__NR_truncate64, path, length) as k_int
    // }
}

#[cfg(target_os = "TODO: add something like cfg(false)")]
mod deprecated {
    pub unsafe fn chown16(filename: *const c_char, user: old_uid_t,
                          group: old_gid_t) -> k_int {
        call!(kty::__NR_chown16, filename, user, group) as k_int
    }

    pub unsafe fn fchown16(fd: k_uint, user: old_uid_t, group: old_gid_t) -> k_int {
        call!(kty::__NR_fchown16, fd, user, group) as k_int
    }

    pub unsafe fn getegid16() -> old_gid_t {
        call!(kty::__NR_getegid16) as old_gid_t
    }

    pub unsafe fn geteuid16() -> old_uid_t {
        call!(kty::__NR_geteuid16) as old_uid_t
    }

    pub unsafe fn getgid16() -> old_gid_t {
        call!(kty::__NR_getgid16) as old_gid_t
    }

    pub unsafe fn getgroups16(gidsetsize: k_int, grouplist: *mut old_gid_t) -> k_int {
        call!(kty::__NR_getgroups16, gidsetsize, grouplist) as k_int
    }

    pub unsafe fn getresgid16(rgidp: *mut old_gid_t, egidp: *mut old_gid_t,
                              sgidp: *mut old_gid_t) -> k_int {
        call!(kty::__NR_getresgid16, rgidp, egidp, sgidp) as k_int
    }

    pub unsafe fn getresuid16(ruidp: *mut old_uid_t, euidp: *mut old_uid_t,
                              suidp: *mut old_uid_t) -> k_int {
        call!(kty::__NR_getresuid16, ruidp, euidp, suidp) as k_int
    }

    pub unsafe fn getuid16() -> old_uid_t {
        call!(kty::__NR_getuid16) as old_uid_t
    }

    pub unsafe fn lchown16(filename: *const c_char, user: old_uid_t,
                           group: old_gid_t) -> k_int {
        call!(kty::__NR_lchown16, filename, user, group) as k_int
    }

    pub unsafe fn setfsgid16(gid: old_gid_t) -> k_int {
        call!(kty::__NR_setfsgid16, gid) as k_int
    }

    pub unsafe fn setfsuid16(uid: old_uid_t) -> k_int {
        call!(kty::__NR_setfsuid16, uid) as k_int
    }

    pub unsafe fn setgid16(gid: old_gid_t) -> k_int {
        call!(kty::__NR_setgid16, gid) as k_int
    }

    pub unsafe fn setgroups16(gidsetsize: k_int, grouplist: *mut old_gid_t) -> k_int {
        call!(kty::__NR_setgroups16, gidsetsize, grouplist) as k_int
    }

    pub unsafe fn setregid16(rgid: old_gid_t, egid: old_gid_t) -> k_int {
        call!(kty::__NR_setregid16, rgid, egid) as k_int
    }

    pub unsafe fn setresgid16(rgid: old_gid_t, egid: old_gid_t,
                              sgid: old_gid_t) -> k_int {
        call!(kty::__NR_setresgid16, rgid, egid, sgid) as k_int
    }

    pub unsafe fn setresuid16(ruid: old_uid_t, euid: old_uid_t,
                              suid: old_uid_t) -> k_int {
        call!(kty::__NR_setresuid16, ruid, euid, suid) as k_int
    }

    pub unsafe fn setreuid16(ruid: old_uid_t, euid: old_uid_t) -> k_int {
        call!(kty::__NR_setreuid16, ruid, euid) as k_int
    }

    pub unsafe fn setuid16(uid: old_uid_t) -> k_int {
        call!(kty::__NR_setuid16, uid) as k_int
    }

    pub unsafe fn gethostname(name: *mut c_char, len: k_int) -> k_int {
        call!(kty::__NR_gethostname, name, len) as k_int
    }

    pub unsafe fn old_getrlimit(resource: k_uint, rlim: *mut rlimit) -> k_int {
        call!(kty::__NR_old_getrlimit, resource, rlim) as k_int
    }

    pub unsafe fn old_mmap(arg: *mut mmap_arg_struct) -> k_long {
        call!(kty::__NR_old_mmap, arg) as k_long
    }

    pub unsafe fn old_readdir(fd: k_uint, dirent: *mut old_linux_dirent,
                              count: k_uint) -> k_int {
        call!(kty::__NR_old_readdir, fd, dirent, count) as k_int
    }

    pub unsafe fn old_select(arg: *mut sel_arg_struct) -> k_int {
        call!(kty::__NR_old_select, arg) as k_int
    }

    pub unsafe fn oldumount(name: *mut c_char) -> k_int {
        call!(kty::__NR_oldumount, name) as k_int
    }

    pub unsafe fn olduname(name: *mut oldold_utsname) -> k_int {
        call!(kty::__NR_olduname, name) as k_int
    }

    pub unsafe fn sendfile(out_fd: k_int, in_fd: k_int, offset: *mut off_t,
                           count: size_t) -> ssize_t {
        call!(kty::__NR_sendfile, out_fd, in_fd, offset, count) as ssize_t
    }

    pub unsafe fn sigaction(sig: k_int, act: *const old_sigaction,
                            oact: *mut old_sigaction) -> k_int {
        call!(kty::__NR_sigaction, sig, act, oact) as k_int
    }

    pub unsafe fn sigpending(set: *mut old_sigset_t) -> k_int {
        call!(kty::__NR_sigpending, set) as k_int
    }

    pub unsafe fn sigprocmask(how: k_int, nset: *mut old_sigset_t,
                              oset: *mut old_sigset_t) -> k_int {
        call!(kty::__NR_sigprocmask, how, nset, oset) as k_int
    }

    pub unsafe fn signalfd(ufd: k_int, user_mask: *const sigset_t,
                           sizemask: size_t) -> k_int {
        call!(kty::__NR_signalfd, ufd, user_mask, sizemask) as k_int
    }

    pub unsafe fn signal(sig: k_int, handler: usize) -> usize {
        call!(kty::__NR_signal, sig, handler) as usize
    }

    pub unsafe fn bdflush(func: k_int, data: k_long) -> k_int {
        call!(kty::__NR_bdflush, func, data) as k_int
    }

    pub unsafe fn fstat(fd: k_uint, statbuf: *mut __old_kernel_stat) -> k_int {
        call!(kty::__NR_fstat, fd, statbuf) as k_int
    }

    pub unsafe fn lstat(filename: *const c_char,
                        statbuf: *mut __old_kernel_stat) -> k_int {
        call!(kty::__NR_lstat, filename, statbuf) as k_int
    }

    pub unsafe fn nice(increment: k_int) -> k_int {
        call!(kty::__NR_nice, increment) as k_int
    }

    pub unsafe fn sgetmask() -> k_long {
        call!(kty::__NR_sgetmask) as k_long
    }

    pub unsafe fn ssetmask(newmask: k_int) -> k_long {
        call!(kty::__NR_ssetmask, newmask) as k_long
    }

    pub unsafe fn stat(filename: *const c_char,
                       statbuf: *mut __old_kernel_stat) -> k_int {
        call!(kty::__NR_stat, filename, statbuf) as k_int
    }

    pub unsafe fn stime(tptr: *mut time_t) -> k_int {
        call!(kty::__NR_stime, tptr) as k_int
    }

    pub unsafe fn sysctl(args: *mut __sysctl_args) -> k_int {
        call!(kty::__NR_sysctl, args) as k_int
    }

    pub unsafe fn uname(name: *mut old_utsname) -> k_int {
        call!(kty::__NR_uname, name) as k_int
    }

    pub unsafe fn uselib(library: *const c_char) -> k_int {
        call!(kty::__NR_uselib, library) as k_int
    }

    pub unsafe fn waitpid(pid: pid_t, stat_addr: *mut k_int, options: k_int) -> k_int {
        call!(kty::__NR_waitpid, pid, stat_addr, options) as k_int
    }

    pub unsafe fn wait4(upid: pid_t, stat_addr: *mut k_int, options: k_int,
                        ru: *mut rusage) -> pid_t {
        call!(kty::__NR_wait4, upid, stat_addr, options, ru) as pid_t
    }

    pub unsafe fn send(fd: k_int, buff: *mut c_void, len: size_t,
                       flags: k_uint) -> ssize_t {
        call!(kty::__NR_send, fd, buff, len, flags) as ssize_t
    }

    pub unsafe fn recv(fd: k_int, ubuf: *mut c_void, size: size_t,
                       flags: k_uint) -> ssize_t {
        call!(kty::__NR_recv, fd, ubuf, size, flags) as ssize_t
    }

    pub unsafe fn time(tloc: *mut time_t) -> time_t {
        call!(kty::__NR_time, tloc) as time_t
    }

    pub unsafe fn utime(filename: *const c_char, times: *const utimbuf) -> k_int {
        call!(kty::__NR_utime, filename, times) as k_int
    }

    pub unsafe fn alarm(seconds: k_uint) -> k_uint {
        call!(kty::__NR_alarm, seconds) as k_uint
    }

    pub unsafe fn newlstat(filename: *const c_char, statbuf: *mut stat) -> k_int {
        call!(kty::__NR_newlstat, filename, statbuf) as k_int
    }

    pub unsafe fn newstat(filename: *const c_char, statbuf: *mut stat) -> k_int {
        call!(kty::__NR_newstat, filename, statbuf) as k_int
    }

    pub unsafe fn lstat64(filename: *const c_char, statbuf: *mut stat64) -> k_int {
        call!(kty::__NR_lstat64, filename, statbuf) as k_int
    }

    pub unsafe fn stat64(filename: *const c_char, statbuf: *mut stat64) -> k_int {
        call!(kty::__NR_stat64, filename, statbuf) as k_int
    }

    pub unsafe fn access(filename: *const c_char, mode: k_int) -> k_int {
        call!(kty::__NR_access, filename, mode) as k_int
    }

    pub unsafe fn chmod(filename: *const c_char, mode: umode_t) -> k_int {
        call!(kty::__NR_chmod, filename, mode) as k_int
    }

    pub unsafe fn chown(filename: *const c_char, user: uid_t, group: gid_t) -> k_int {
        call!(kty::__NR_chown, filename, user, group) as k_int
    }

    pub unsafe fn creat(pathname: *const c_char, mode: umode_t) -> k_int {
        call!(kty::__NR_creat, pathname, mode) as k_int
    }

    pub unsafe fn dup2(oldfd: k_uint, newfd: k_uint) -> k_int {
        call!(kty::__NR_dup2, oldfd, newfd) as k_int
    }

    pub unsafe fn epoll_create(size: k_int) -> k_int {
        call!(kty::__NR_epoll_create, size) as k_int
    }

    pub unsafe fn epoll_wait(epfd: k_int, events: *mut epoll_event, maxevents: k_int,
                             timeout: k_int) -> k_int {
        call!(kty::__NR_epoll_wait, epfd, events, maxevents, timeout) as k_int
    }

    pub unsafe fn eventfd(count: k_uint) -> k_int {
        call!(kty::__NR_eventfd, count) as k_int
    }

    pub unsafe fn fork() -> pid_t {
        call!(kty::__NR_fork) as pid_t
    }

    pub unsafe fn futimesat(dfd: k_int, filename: *const c_char,
                            utimes: *mut timeval) -> k_int {
        call!(kty::__NR_futimesat, dfd, filename, utimes) as k_int
    }

    pub unsafe fn getdents(fd: k_uint, dirent: *mut linux_dirent, count: k_uint) -> k_int {
        call!(kty::__NR_getdents, fd, dirent, count) as k_int
    }

    pub unsafe fn getpgrp() -> pid_t {
        call!(kty::__NR_getpgrp) as pid_t
    }

    pub unsafe fn inotify_init() -> k_int {
        call!(kty::__NR_inotify_init) as k_int
    }

    pub unsafe fn lchown(filename: *const c_char, user: uid_t, group: gid_t) -> k_int {
        call!(kty::__NR_lchown, filename, user, group) as k_int
    }

    pub unsafe fn link(oldname: *const c_char, newname: *const c_char) -> k_int {
        call!(kty::__NR_link, oldname, newname) as k_int
    }

    pub unsafe fn mkdir(pathname: *const c_char, mode: umode_t) -> k_int {
        call!(kty::__NR_mkdir, pathname, mode) as k_int
    }

    pub unsafe fn mknod(filename: *const c_char, mode: umode_t, dev: k_uint) -> k_int {
        call!(kty::__NR_mknod, filename, mode, dev) as k_int
    }

    pub unsafe fn open(filename: *const c_char, flags: k_int, mode: umode_t) -> k_int {
        call!(kty::__NR_open, filename, flags, mode) as k_int
    }

    pub unsafe fn pause() -> k_int {
        call!(kty::__NR_pause) as k_int
    }

    pub unsafe fn pipe(fildes: *mut k_int) -> k_int {
        call!(kty::__NR_pipe, fildes) as k_int
    }

    pub unsafe fn poll(ufds: *mut pollfd, nfds: k_uint, timeout_msecs: k_int) -> k_int {
        call!(kty::__NR_poll, ufds, nfds, timeout_msecs) as k_int
    }

    pub unsafe fn readlink(path: *const c_char, buf: *mut c_char,
                           bufsiz: k_int) -> ssize_t {
        call!(kty::__NR_readlink, path, buf, bufsiz) as ssize_t
    }

    pub unsafe fn rename(oldname: *const c_char, newname: *const c_char) -> k_int {
        call!(kty::__NR_rename, oldname, newname) as k_int
    }

    pub unsafe fn rmdir(pathname: *const c_char) -> k_int {
        call!(kty::__NR_rmdir, pathname) as k_int
    }

    pub unsafe fn select(n: k_int, inp: *mut fd_set, outp: *mut fd_set, exp: *mut fd_set,
                         tvp: *mut timeval) -> k_int {
        call!(kty::__NR_select, n, inp, outp, exp, tvp) as k_int
    }

    pub unsafe fn symlink(oldname: *const c_char, newname: *const c_char) -> k_int {
        call!(kty::__NR_symlink, oldname, newname) as k_int
    }

    pub unsafe fn sysfs(option: k_int, arg1: k_ulong, arg2: k_ulong) -> k_int {
        call!(kty::__NR_sysfs, option, arg1, arg2) as k_int
    }

    pub unsafe fn unlink(pathname: *const c_char) -> k_int {
        call!(kty::__NR_unlink, pathname) as k_int
    }

    pub unsafe fn ustat(dev: k_uint, ubuf: *mut ustat) -> k_int {
        call!(kty::__NR_ustat, dev, ubuf) as k_int
    }

    pub unsafe fn utimes(filename: *const c_char, utimes: *const timeval) -> k_int {
        call!(kty::__NR_utimes, filename, utimes) as k_int
    }

    pub unsafe fn vfork() -> pid_t {
        call!(kty::__NR_vfork) as pid_t
    }
}