Loading...
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 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 | /* * sys_ppc32.c: Conversion between 32bit and 64bit native syscalls. * * Copyright (C) 2001 IBM * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu) * * These routines maintain argument size conversion between 32bit and 64bit * environment. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include <linux/config.h> #include <asm/ptrace.h> #include <linux/kernel.h> #include <linux/sched.h> #include <linux/fs.h> #include <linux/mm.h> #include <linux/file.h> #include <linux/signal.h> #include <linux/resource.h> #include <linux/times.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/slab.h> #include <linux/uio.h> #include <linux/aio.h> #include <linux/nfs_fs.h> #include <linux/module.h> #include <linux/sunrpc/svc.h> #include <linux/nfsd/nfsd.h> #include <linux/nfsd/cache.h> #include <linux/nfsd/xdr.h> #include <linux/nfsd/syscall.h> #include <linux/poll.h> #include <linux/personality.h> #include <linux/stat.h> #include <linux/filter.h> #include <linux/highmem.h> #include <linux/highuid.h> #include <linux/mman.h> #include <linux/ipv6.h> #include <linux/in.h> #include <linux/icmpv6.h> #include <linux/syscalls.h> #include <linux/unistd.h> #include <linux/sysctl.h> #include <linux/binfmts.h> #include <linux/dnotify.h> #include <linux/security.h> #include <linux/compat.h> #include <linux/ptrace.h> #include <linux/aio_abi.h> #include <asm/types.h> #include <asm/ipc.h> #include <asm/uaccess.h> #include <asm/unistd.h> #include <asm/semaphore.h> #include <net/scm.h> #include <net/sock.h> #include <linux/elf.h> #include <asm/ppcdebug.h> #include <asm/time.h> #include <asm/ppc32.h> #include <asm/mmu_context.h> #include "pci.h" typedef ssize_t (*io_fn_t)(struct file *, char *, size_t, loff_t *); typedef ssize_t (*iov_fn_t)(struct file *, const struct iovec *, unsigned long, loff_t *); static long do_readv_writev32(int type, struct file *file, const struct compat_iovec *vector, u32 count) { compat_ssize_t tot_len; struct iovec iovstack[UIO_FASTIOV]; struct iovec *iov=iovstack, *ivp; struct inode *inode; long retval, i; io_fn_t fn; iov_fn_t fnv; /* * SuS says "The readv() function *may* fail if the iovcnt argument * was less than or equal to 0, or greater than {IOV_MAX}. Linux has * traditionally returned zero for zero segments, so... */ retval = 0; if (count == 0) goto out; /* First get the "struct iovec" from user memory and * verify all the pointers */ retval = -EINVAL; if (count > UIO_MAXIOV) goto out; if (!file->f_op) goto out; if (count > UIO_FASTIOV) { retval = -ENOMEM; iov = kmalloc(count*sizeof(struct iovec), GFP_KERNEL); if (!iov) goto out; } retval = -EFAULT; if (verify_area(VERIFY_READ, vector, sizeof(struct compat_iovec)*count)) goto out; /* * Single unix specification: * We should -EINVAL if an element length is not >= 0 and fitting an * ssize_t. The total length is fitting an ssize_t * * Be careful here because iov_len is a size_t not an ssize_t */ tot_len = 0; i = count; ivp = iov; retval = -EINVAL; while(i > 0) { compat_ssize_t tmp = tot_len; compat_ssize_t len; u32 buf; if (__get_user(len, &vector->iov_len) || __get_user(buf, &vector->iov_base)) { retval = -EFAULT; goto out; } if (len < 0) /* size_t not fitting an compat_ssize_t .. */ goto out; tot_len += len; if (tot_len < tmp) /* maths overflow on the compat_ssize_t */ goto out; ivp->iov_base = (void *)A(buf); ivp->iov_len = (__kernel_size_t) len; vector++; ivp++; i--; } if (tot_len == 0) { retval = 0; goto out; } inode = file->f_dentry->d_inode; /* VERIFY_WRITE actually means a read, as we write to user space */ retval = locks_verify_area((type == READ ? FLOCK_VERIFY_READ : FLOCK_VERIFY_WRITE), inode, file, file->f_pos, tot_len); if (retval) goto out; if (type == READ) { fn = file->f_op->read; fnv = file->f_op->readv; } else { fn = (io_fn_t)file->f_op->write; fnv = file->f_op->writev; } if (fnv) { retval = fnv(file, iov, count, &file->f_pos); goto out; } /* Do it by hand, with file-ops */ ivp = iov; while (count > 0) { void * base; int len, nr; base = ivp->iov_base; len = ivp->iov_len; ivp++; count--; nr = fn(file, base, len, &file->f_pos); if (nr < 0) { if (!retval) retval = nr; break; } retval += nr; if (nr != len) break; } out: if (iov != iovstack) kfree(iov); if ((retval + (type == READ)) > 0) dnotify_parent(file->f_dentry, (type == READ) ? DN_ACCESS : DN_MODIFY); return retval; } asmlinkage long sys32_readv(int fd, struct compat_iovec *vector, u32 count) { struct file *file; int ret = -EBADF; file = fget(fd); if (!file || !(file->f_mode & FMODE_READ)) goto out; ret = -EINVAL; if (!file->f_op || (!file->f_op->readv && !file->f_op->read)) goto out; ret = do_readv_writev32(READ, file, vector, count); out: if (file) fput(file); return ret; } asmlinkage long sys32_writev(int fd, struct compat_iovec *vector, u32 count) { struct file *file; int ret = -EBADF; file = fget(fd); if (!file || !(file->f_mode & FMODE_WRITE)) goto out; ret = -EINVAL; if (!file->f_op || (!file->f_op->writev && !file->f_op->write)) goto out; ret = do_readv_writev32(WRITE, file, vector, count); out: if (file) fput(file); return ret; } /* readdir & getdents */ #define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de))) #define ROUND_UP(x) (((x)+sizeof(u32)-1) & ~(sizeof(u32)-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, unsigned int d_type) { 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, struct old_linux_dirent32 *dirent, unsigned int count) { int error = -EBADF; struct file * file; struct readdir_callback32 buf; file = fget(fd); if (!file) goto out; buf.count = 0; buf.dirent = dirent; error = vfs_readdir(file, (filldir_t)fillonedir, &buf); if (error < 0) goto out_putf; error = buf.count; out_putf: fput(file); out: 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, unsigned int d_type) { struct linux_dirent32 * dirent; struct getdents_callback32 * buf = (struct getdents_callback32 *) __buf; int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 2); buf->error = -EINVAL; /* only used if we fail.. */ if (reclen > buf->count) return -EINVAL; dirent = buf->previous; if (dirent) { if (__put_user(offset, &dirent->d_off)) goto efault; } dirent = buf->current_dir; if (__put_user(ino, &dirent->d_ino)) goto efault; if (__put_user(reclen, &dirent->d_reclen)) goto efault; if (copy_to_user(dirent->d_name, name, namlen)) goto efault; if (__put_user(0, dirent->d_name + namlen)) goto efault; if (__put_user(d_type, (char *) dirent + reclen - 1)) goto efault; buf->previous = dirent; dirent = (void *)dirent + reclen; buf->current_dir = dirent; buf->count -= reclen; return 0; efault: buf->error = -EFAULT; return -EFAULT; } long sys32_getdents(unsigned int fd, struct linux_dirent32 *dirent, unsigned int count) { struct file * file; struct linux_dirent32 * lastdirent; struct getdents_callback32 buf; int error; error = -EFAULT; if (!access_ok(VERIFY_WRITE, dirent, count)) goto out; error = -EBADF; file = fget(fd); if (!file) goto out; buf.current_dir = dirent; buf.previous = NULL; buf.count = count; buf.error = 0; error = vfs_readdir(file, (filldir_t)filldir, &buf); if (error < 0) goto out_putf; error = buf.error; lastdirent = buf.previous; if (lastdirent) { if (put_user(file->f_pos, &lastdirent->d_off)) error = -EFAULT; else error = count - buf.count; } out_putf: fput(file); out: return error; } /* * Ooo, nasty. We need here to frob 32-bit unsigned longs to * 64-bit unsigned longs. */ static inline int get_fd_set32(unsigned long n, unsigned long *fdset, u32 *ufdset) { if (ufdset) { unsigned long odd; if (verify_area(VERIFY_WRITE, ufdset, n*sizeof(u32))) return -EFAULT; odd = n & 1UL; n &= ~1UL; while (n) { unsigned long h, l; __get_user(l, ufdset); __get_user(h, ufdset+1); ufdset += 2; *fdset++ = h << 32 | l; n -= 2; } if (odd) __get_user(*fdset, ufdset); } else { /* Tricky, must clear full unsigned long in the * kernel fdset at the end, this makes sure that * actually happens. */ memset(fdset, 0, ((n + 1) & ~1)*sizeof(u32)); } return 0; } static inline void set_fd_set32(unsigned long n, u32 *ufdset, unsigned long *fdset) { unsigned long odd; if (!ufdset) return; odd = n & 1UL; n &= ~1UL; while (n) { unsigned long h, l; l = *fdset++; h = l >> 32; __put_user(l, ufdset); __put_user(h, ufdset+1); ufdset += 2; n -= 2; } if (odd) __put_user(*fdset, ufdset); } #define MAX_SELECT_SECONDS ((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1) asmlinkage long sys32_select(int n, u32 *inp, u32 *outp, u32 *exp, u32 tvp_x) { fd_set_bits fds; struct compat_timeval *tvp = (struct compat_timeval *)AA(tvp_x); char *bits; unsigned long nn; long timeout; int ret, size, max_fdset; timeout = MAX_SCHEDULE_TIMEOUT; if (tvp) { time_t sec, usec; if ((ret = verify_area(VERIFY_READ, tvp, sizeof(*tvp))) || (ret = __get_user(sec, &tvp->tv_sec)) || (ret = __get_user(usec, &tvp->tv_usec))) goto out_nofds; ret = -EINVAL; if(sec < 0 || usec < 0) goto out_nofds; if ((unsigned long) sec < MAX_SELECT_SECONDS) { timeout = (usec + 1000000/HZ - 1) / (1000000/HZ); timeout += sec * (unsigned long) HZ; } } ret = -EINVAL; if (n < 0) goto out_nofds; /* max_fdset can increase, so grab it once to avoid race */ max_fdset = current->files->max_fdset; if (n > max_fdset) n = max_fdset; /* * We need 6 bitmaps (in/out/ex for both incoming and outgoing), * since we used fdset we need to allocate memory in units of * long-words. */ ret = -ENOMEM; size = FDS_BYTES(n); bits = kmalloc(6 * size, GFP_KERNEL); if (!bits) goto out_nofds; fds.in = (unsigned long *) bits; fds.out = (unsigned long *) (bits + size); fds.ex = (unsigned long *) (bits + 2*size); fds.res_in = (unsigned long *) (bits + 3*size); fds.res_out = (unsigned long *) (bits + 4*size); fds.res_ex = (unsigned long *) (bits + 5*size); nn = (n + 8*sizeof(u32) - 1) / (8*sizeof(u32)); if ((ret = get_fd_set32(nn, fds.in, inp)) || (ret = get_fd_set32(nn, fds.out, outp)) || (ret = get_fd_set32(nn, fds.ex, exp))) goto out; zero_fd_set(n, fds.res_in); zero_fd_set(n, fds.res_out); zero_fd_set(n, fds.res_ex); ret = do_select(n, &fds, &timeout); if (tvp && !(current->personality & STICKY_TIMEOUTS)) { time_t sec = 0, usec = 0; if (timeout) { sec = timeout / HZ; usec = timeout % HZ; usec *= (1000000/HZ); } put_user(sec, &tvp->tv_sec); put_user(usec, &tvp->tv_usec); } if (ret < 0) goto out; if (!ret) { ret = -ERESTARTNOHAND; if (signal_pending(current)) goto out; ret = 0; } set_fd_set32(nn, inp, fds.res_in); set_fd_set32(nn, outp, fds.res_out); set_fd_set32(nn, exp, fds.res_ex); out: kfree(bits); out_nofds: return ret; } int ppc32_select(u32 n, u32* inp, u32* outp, u32* exp, u32 tvp_x) { /* sign extend n */ return sys32_select((int)n, inp, outp, exp, tvp_x); } int cp_compat_stat(struct kstat *stat, struct compat_stat *statbuf) { long err; if (stat->size > MAX_NON_LFS || !new_valid_dev(stat->dev) || !new_valid_dev(stat->rdev)) return -EOVERFLOW; err = verify_area(VERIFY_WRITE, statbuf, sizeof(*statbuf)); err |= __put_user(new_encode_dev(stat->dev), &statbuf->st_dev); err |= __put_user(stat->ino, &statbuf->st_ino); err |= __put_user(stat->mode, &statbuf->st_mode); err |= __put_user(stat->nlink, &statbuf->st_nlink); err |= __put_user(stat->uid, &statbuf->st_uid); err |= __put_user(stat->gid, &statbuf->st_gid); err |= __put_user(new_encode_dev(stat->rdev), &statbuf->st_rdev); err |= __put_user(stat->size, &statbuf->st_size); err |= __put_user(stat->atime.tv_sec, &statbuf->st_atime); err |= __put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec); err |= __put_user(stat->mtime.tv_sec, &statbuf->st_mtime); err |= __put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec); err |= __put_user(stat->ctime.tv_sec, &statbuf->st_ctime); err |= __put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec); err |= __put_user(stat->blksize, &statbuf->st_blksize); err |= __put_user(stat->blocks, &statbuf->st_blocks); err |= __put_user(0, &statbuf->__unused4[0]); err |= __put_user(0, &statbuf->__unused4[1]); return err; } /* Note: it is necessary to treat option as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_sysfs(u32 option, u32 arg1, u32 arg2) { return sys_sysfs((int)option, arg1, arg2); } /* Handle adjtimex compatibility. */ struct timex32 { u32 modes; s32 offset, freq, maxerror, esterror; s32 status, constant, precision, tolerance; struct compat_timeval time; s32 tick; s32 ppsfreq, jitter, shift, stabil; s32 jitcnt, calcnt, errcnt, stbcnt; s32 :32; s32 :32; s32 :32; s32 :32; s32 :32; s32 :32; s32 :32; s32 :32; s32 :32; s32 :32; s32 :32; s32 :32; }; extern int do_adjtimex(struct timex *); extern void ppc_adjtimex(void); asmlinkage long sys32_adjtimex(struct timex32 *utp) { struct timex txc; int ret; memset(&txc, 0, sizeof(struct timex)); if(get_user(txc.modes, &utp->modes) || __get_user(txc.offset, &utp->offset) || __get_user(txc.freq, &utp->freq) || __get_user(txc.maxerror, &utp->maxerror) || __get_user(txc.esterror, &utp->esterror) || __get_user(txc.status, &utp->status) || __get_user(txc.constant, &utp->constant) || __get_user(txc.precision, &utp->precision) || __get_user(txc.tolerance, &utp->tolerance) || __get_user(txc.time.tv_sec, &utp->time.tv_sec) || __get_user(txc.time.tv_usec, &utp->time.tv_usec) || __get_user(txc.tick, &utp->tick) || __get_user(txc.ppsfreq, &utp->ppsfreq) || __get_user(txc.jitter, &utp->jitter) || __get_user(txc.shift, &utp->shift) || __get_user(txc.stabil, &utp->stabil) || __get_user(txc.jitcnt, &utp->jitcnt) || __get_user(txc.calcnt, &utp->calcnt) || __get_user(txc.errcnt, &utp->errcnt) || __get_user(txc.stbcnt, &utp->stbcnt)) return -EFAULT; ret = do_adjtimex(&txc); /* adjust the conversion of TB to time of day to track adjtimex */ ppc_adjtimex(); if(put_user(txc.modes, &utp->modes) || __put_user(txc.offset, &utp->offset) || __put_user(txc.freq, &utp->freq) || __put_user(txc.maxerror, &utp->maxerror) || __put_user(txc.esterror, &utp->esterror) || __put_user(txc.status, &utp->status) || __put_user(txc.constant, &utp->constant) || __put_user(txc.precision, &utp->precision) || __put_user(txc.tolerance, &utp->tolerance) || __put_user(txc.time.tv_sec, &utp->time.tv_sec) || __put_user(txc.time.tv_usec, &utp->time.tv_usec) || __put_user(txc.tick, &utp->tick) || __put_user(txc.ppsfreq, &utp->ppsfreq) || __put_user(txc.jitter, &utp->jitter) || __put_user(txc.shift, &utp->shift) || __put_user(txc.stabil, &utp->stabil) || __put_user(txc.jitcnt, &utp->jitcnt) || __put_user(txc.calcnt, &utp->calcnt) || __put_user(txc.errcnt, &utp->errcnt) || __put_user(txc.stbcnt, &utp->stbcnt)) ret = -EFAULT; return ret; } /* Stuff for NFS server syscalls... */ struct nfsctl_svc32 { u16 svc32_port; s32 svc32_nthreads; }; struct nfsctl_client32 { s8 cl32_ident[NFSCLNT_IDMAX+1]; s32 cl32_naddr; struct in_addr cl32_addrlist[NFSCLNT_ADDRMAX]; s32 cl32_fhkeytype; s32 cl32_fhkeylen; u8 cl32_fhkey[NFSCLNT_KEYMAX]; }; struct nfsctl_export32 { s8 ex32_client[NFSCLNT_IDMAX+1]; s8 ex32_path[NFS_MAXPATHLEN+1]; compat_dev_t ex32_dev; compat_ino_t ex32_ino; s32 ex32_flags; compat_uid_t ex32_anon_uid; compat_gid_t ex32_anon_gid; }; struct nfsctl_fdparm32 { struct sockaddr gd32_addr; s8 gd32_path[NFS_MAXPATHLEN+1]; s32 gd32_version; }; struct nfsctl_fsparm32 { struct sockaddr gd32_addr; s8 gd32_path[NFS_MAXPATHLEN+1]; s32 gd32_maxlen; }; struct nfsctl_arg32 { s32 ca32_version; /* safeguard */ union { struct nfsctl_svc32 u32_svc; struct nfsctl_client32 u32_client; struct nfsctl_export32 u32_export; struct nfsctl_fdparm32 u32_getfd; struct nfsctl_fsparm32 u32_getfs; } u; #define ca32_svc u.u32_svc #define ca32_client u.u32_client #define ca32_export u.u32_export #define ca32_getfd u.u32_getfd #define ca32_getfs u.u32_getfs }; union nfsctl_res32 { __u8 cr32_getfh[NFS_FHSIZE]; struct knfsd_fh cr32_getfs; }; static int nfs_svc32_trans(struct nfsctl_arg *karg, struct nfsctl_arg32 *arg32) { int err; err = __get_user(karg->ca_version, &arg32->ca32_version); err |= __get_user(karg->ca_svc.svc_port, &arg32->ca32_svc.svc32_port); err |= __get_user(karg->ca_svc.svc_nthreads, &arg32->ca32_svc.svc32_nthreads); return err; } static int nfs_clnt32_trans(struct nfsctl_arg *karg, struct nfsctl_arg32 *arg32) { int err; err = __get_user(karg->ca_version, &arg32->ca32_version); err |= copy_from_user(&karg->ca_client.cl_ident[0], &arg32->ca32_client.cl32_ident[0], NFSCLNT_IDMAX); err |= __get_user(karg->ca_client.cl_naddr, &arg32->ca32_client.cl32_naddr); err |= copy_from_user(&karg->ca_client.cl_addrlist[0], &arg32->ca32_client.cl32_addrlist[0], (sizeof(struct in_addr) * NFSCLNT_ADDRMAX)); err |= __get_user(karg->ca_client.cl_fhkeytype, &arg32->ca32_client.cl32_fhkeytype); err |= __get_user(karg->ca_client.cl_fhkeylen, &arg32->ca32_client.cl32_fhkeylen); err |= copy_from_user(&karg->ca_client.cl_fhkey[0], &arg32->ca32_client.cl32_fhkey[0], NFSCLNT_KEYMAX); if(err) return -EFAULT; return 0; } static int nfs_exp32_trans(struct nfsctl_arg *karg, struct nfsctl_arg32 *arg32) { int err; err = __get_user(karg->ca_version, &arg32->ca32_version); err |= copy_from_user(&karg->ca_export.ex_client[0], &arg32->ca32_export.ex32_client[0], NFSCLNT_IDMAX); err |= copy_from_user(&karg->ca_export.ex_path[0], &arg32->ca32_export.ex32_path[0], NFS_MAXPATHLEN); err |= __get_user(karg->ca_export.ex_dev, &arg32->ca32_export.ex32_dev); err |= __get_user(karg->ca_export.ex_ino, &arg32->ca32_export.ex32_ino); err |= __get_user(karg->ca_export.ex_flags, &arg32->ca32_export.ex32_flags); err |= __get_user(karg->ca_export.ex_anon_uid, &arg32->ca32_export.ex32_anon_uid); err |= __get_user(karg->ca_export.ex_anon_gid, &arg32->ca32_export.ex32_anon_gid); karg->ca_export.ex_anon_uid = karg->ca_export.ex_anon_uid; karg->ca_export.ex_anon_gid = karg->ca_export.ex_anon_gid; if(err) return -EFAULT; return 0; } static int nfs_getfd32_trans(struct nfsctl_arg *karg, struct nfsctl_arg32 *arg32) { int err; err = __get_user(karg->ca_version, &arg32->ca32_version); err |= copy_from_user(&karg->ca_getfd.gd_addr, &arg32->ca32_getfd.gd32_addr, (sizeof(struct sockaddr))); err |= copy_from_user(&karg->ca_getfd.gd_path, &arg32->ca32_getfd.gd32_path, (NFS_MAXPATHLEN+1)); err |= __get_user(karg->ca_getfd.gd_version, &arg32->ca32_getfd.gd32_version); if(err) return -EFAULT; return 0; } static int nfs_getfs32_trans(struct nfsctl_arg *karg, struct nfsctl_arg32 *arg32) { int err; err = __get_user(karg->ca_version, &arg32->ca32_version); err |= copy_from_user(&karg->ca_getfs.gd_addr, &arg32->ca32_getfs.gd32_addr, (sizeof(struct sockaddr))); err |= copy_from_user(&karg->ca_getfs.gd_path, &arg32->ca32_getfs.gd32_path, (NFS_MAXPATHLEN+1)); err |= __get_user(karg->ca_getfs.gd_maxlen, &arg32->ca32_getfs.gd32_maxlen); if(err) return -EFAULT; return 0; } /* This really doesn't need translations, we are only passing * back a union which contains opaque nfs file handle data. */ static int nfs_getfh32_res_trans(union nfsctl_res *kres, union nfsctl_res32 *res32) { int err; err = copy_to_user(res32, kres, sizeof(*res32)); if(err) return -EFAULT; return 0; } /* Note: it is necessary to treat cmd_parm as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ int asmlinkage sys32_nfsservctl(u32 cmd_parm, struct nfsctl_arg32 *arg32, union nfsctl_res32 *res32) { int cmd = (int)cmd_parm; struct nfsctl_arg *karg = NULL; union nfsctl_res *kres = NULL; mm_segment_t oldfs; int err; karg = kmalloc(sizeof(*karg), GFP_USER); if(!karg) return -ENOMEM; if(res32) { kres = kmalloc(sizeof(*kres), GFP_USER); if(!kres) { kfree(karg); return -ENOMEM; } } switch(cmd) { case NFSCTL_SVC: err = nfs_svc32_trans(karg, arg32); break; case NFSCTL_ADDCLIENT: err = nfs_clnt32_trans(karg, arg32); break; case NFSCTL_DELCLIENT: err = nfs_clnt32_trans(karg, arg32); break; case NFSCTL_EXPORT: case NFSCTL_UNEXPORT: err = nfs_exp32_trans(karg, arg32); break; case NFSCTL_GETFD: err = nfs_getfd32_trans(karg, arg32); break; case NFSCTL_GETFS: err = nfs_getfs32_trans(karg, arg32); break; default: err = -EINVAL; break; } if(err) goto done; oldfs = get_fs(); set_fs(KERNEL_DS); err = sys_nfsservctl(cmd, karg, kres); set_fs(oldfs); if (err) goto done; if((cmd == NFSCTL_GETFD) || (cmd == NFSCTL_GETFS)) err = nfs_getfh32_res_trans(kres, res32); done: if(karg) kfree(karg); if(kres) kfree(kres); return err; } /* These are here just in case some old sparc32 binary calls it. */ asmlinkage long sys32_pause(void) { current->state = TASK_INTERRUPTIBLE; schedule(); return -ERESTARTNOHAND; } static inline long get_ts32(struct timespec *o, struct compat_timeval *i) { long usec; if (!access_ok(VERIFY_READ, i, sizeof(*i))) return -EFAULT; if (__get_user(o->tv_sec, &i->tv_sec)) return -EFAULT; if (__get_user(usec, &i->tv_usec)) return -EFAULT; o->tv_nsec = usec * 1000; return 0; } static inline long put_tv32(struct compat_timeval *o, struct timeval *i) { return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) || (__put_user(i->tv_sec, &o->tv_sec) | __put_user(i->tv_usec, &o->tv_usec))); } struct sysinfo32 { s32 uptime; u32 loads[3]; u32 totalram; u32 freeram; u32 sharedram; u32 bufferram; u32 totalswap; u32 freeswap; unsigned short procs; unsigned short pad; u32 totalhigh; u32 freehigh; u32 mem_unit; char _f[20-2*sizeof(int)-sizeof(int)]; }; asmlinkage long sys32_sysinfo(struct sysinfo32 *info) { struct sysinfo s; int ret, err; int bitcount=0; mm_segment_t old_fs = get_fs (); set_fs (KERNEL_DS); ret = sys_sysinfo(&s); set_fs (old_fs); /* Check to see if any memory value is too large for 32-bit and * scale down if needed. */ if ((s.totalram >> 32) || (s.totalswap >> 32)) { while (s.mem_unit < PAGE_SIZE) { s.mem_unit <<= 1; bitcount++; } s.totalram >>=bitcount; s.freeram >>= bitcount; s.sharedram >>= bitcount; s.bufferram >>= bitcount; s.totalswap >>= bitcount; s.freeswap >>= bitcount; s.totalhigh >>= bitcount; s.freehigh >>= bitcount; } err = put_user (s.uptime, &info->uptime); err |= __put_user (s.loads[0], &info->loads[0]); err |= __put_user (s.loads[1], &info->loads[1]); err |= __put_user (s.loads[2], &info->loads[2]); err |= __put_user (s.totalram, &info->totalram); err |= __put_user (s.freeram, &info->freeram); err |= __put_user (s.sharedram, &info->sharedram); err |= __put_user (s.bufferram, &info->bufferram); err |= __put_user (s.totalswap, &info->totalswap); err |= __put_user (s.freeswap, &info->freeswap); err |= __put_user (s.procs, &info->procs); err |= __put_user (s.totalhigh, &info->totalhigh); err |= __put_user (s.freehigh, &info->freehigh); err |= __put_user (s.mem_unit, &info->mem_unit); if (err) return -EFAULT; return ret; } /* Translations due to time_t size differences. Which affects all sorts of things, like timeval and itimerval. */ extern struct timezone sys_tz; asmlinkage long sys32_gettimeofday(struct compat_timeval *tv, struct timezone *tz) { if (tv) { struct timeval ktv; do_gettimeofday(&ktv); if (put_tv32(tv, &ktv)) return -EFAULT; } if (tz) { if (copy_to_user(tz, &sys_tz, sizeof(sys_tz))) return -EFAULT; } return 0; } asmlinkage long sys32_settimeofday(struct compat_timeval *tv, struct timezone *tz) { struct timespec kts; struct timezone ktz; if (tv) { if (get_ts32(&kts, tv)) return -EFAULT; } if (tz) { if (copy_from_user(&ktz, tz, sizeof(ktz))) return -EFAULT; } return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL); } struct msgbuf32 { compat_long_t mtype; char mtext[1]; }; struct semid_ds32 { struct ipc_perm sem_perm; compat_time_t sem_otime; compat_time_t sem_ctime; compat_uptr_t sem_base; compat_uptr_t sem_pending; compat_uptr_t sem_pending_last; compat_uptr_t undo; unsigned short sem_nsems; }; struct semid64_ds32 { struct ipc64_perm sem_perm; unsigned int __unused1; compat_time_t sem_otime; unsigned int __unused2; compat_time_t sem_ctime; compat_ulong_t sem_nsems; compat_ulong_t __unused3; compat_ulong_t __unused4; }; struct msqid_ds32 { struct ipc_perm msg_perm; compat_uptr_t msg_first; compat_uptr_t msg_last; compat_time_t msg_stime; compat_time_t msg_rtime; compat_time_t msg_ctime; compat_ulong_t msg_lcbytes; compat_ulong_t msg_lqbytes; unsigned short msg_cbytes; unsigned short msg_qnum; unsigned short msg_qbytes; compat_ipc_pid_t msg_lspid; compat_ipc_pid_t msg_lrpid; }; struct msqid64_ds32 { struct ipc64_perm msg_perm; unsigned int __unused1; compat_time_t msg_stime; unsigned int __unused2; compat_time_t msg_rtime; unsigned int __unused3; compat_time_t msg_ctime; compat_ulong_t msg_cbytes; compat_ulong_t msg_qnum; compat_ulong_t msg_qbytes; compat_pid_t msg_lspid; compat_pid_t msg_lrpid; compat_ulong_t __unused4; compat_ulong_t __unused5; }; struct shmid_ds32 { struct ipc_perm shm_perm; int shm_segsz; compat_time_t shm_atime; compat_time_t shm_dtime; compat_time_t shm_ctime; compat_ipc_pid_t shm_cpid; compat_ipc_pid_t shm_lpid; unsigned short shm_nattch; unsigned short __unused; compat_uptr_t __unused2; compat_uptr_t __unused3; }; struct shmid64_ds32 { struct ipc64_perm shm_perm; unsigned int __unused1; compat_time_t shm_atime; unsigned int __unused2; compat_time_t shm_dtime; unsigned int __unused3; compat_time_t shm_ctime; unsigned int __unused4; compat_size_t shm_segsz; compat_pid_t shm_cpid; compat_pid_t shm_lpid; compat_ulong_t shm_nattch; compat_ulong_t __unused5; compat_ulong_t __unused6; }; /* * sys32_ipc() is the de-multiplexer for the SysV IPC calls in 32bit * emulation.. * * This is really horribly ugly. */ static long do_sys32_semctl(int first, int second, int third, void *uptr) { union semun fourth; u32 pad; int err, err2; mm_segment_t old_fs; if (!uptr) return -EINVAL; err = -EFAULT; if (get_user(pad, (u32 *)uptr)) return err; if ((third & ~IPC_64) == SETVAL) fourth.val = (int)pad; else fourth.__pad = (void *)A(pad); switch (third & (~IPC_64)) { case IPC_INFO: case IPC_RMID: case SEM_INFO: case GETVAL: case GETPID: case GETNCNT: case GETZCNT: case GETALL: case SETALL: case SETVAL: err = sys_semctl(first, second, third, fourth); break; case IPC_STAT: case SEM_STAT: if (third & IPC_64) { struct semid64_ds s64; struct semid64_ds32 *usp; usp = (struct semid64_ds32 *)A(pad); fourth.__pad = &s64; old_fs = get_fs(); set_fs(KERNEL_DS); err = sys_semctl(first, second, third, fourth); set_fs(old_fs); err2 = copy_to_user(&usp->sem_perm, &s64.sem_perm, sizeof(struct ipc64_perm)); err2 |= __put_user(s64.sem_otime, &usp->sem_otime); err2 |= __put_user(s64.sem_ctime, &usp->sem_ctime); err2 |= __put_user(s64.sem_nsems, &usp->sem_nsems); if (err2) err = -EFAULT; } else { struct semid_ds s; struct semid_ds32 *usp; usp = (struct semid_ds32 *)A(pad); fourth.__pad = &s; old_fs = get_fs(); set_fs(KERNEL_DS); err = sys_semctl(first, second, third, fourth); set_fs(old_fs); err2 = copy_to_user(&usp->sem_perm, &s.sem_perm, sizeof(struct ipc_perm)); err2 |= __put_user(s.sem_otime, &usp->sem_otime); err2 |= __put_user(s.sem_ctime, &usp->sem_ctime); err2 |= __put_user(s.sem_nsems, &usp->sem_nsems); if (err2) err = -EFAULT; } break; case IPC_SET: if (third & IPC_64) { struct semid64_ds s64; struct semid64_ds32 *usp; usp = (struct semid64_ds32 *)A(pad); err = get_user(s64.sem_perm.uid, &usp->sem_perm.uid); err |= __get_user(s64.sem_perm.gid, &usp->sem_perm.gid); err |= __get_user(s64.sem_perm.mode, &usp->sem_perm.mode); if (err) goto out; fourth.__pad = &s64; old_fs = get_fs(); set_fs(KERNEL_DS); err = sys_semctl(first, second, third, fourth); set_fs(old_fs); } else { struct semid_ds s; struct semid_ds32 *usp; usp = (struct semid_ds32 *)A(pad); err = get_user(s.sem_perm.uid, &usp->sem_perm.uid); err |= __get_user(s.sem_perm.gid, &usp->sem_perm.gid); err |= __get_user(s.sem_perm.mode, &usp->sem_perm.mode); if (err) goto out; fourth.__pad = &s; old_fs = get_fs(); set_fs(KERNEL_DS); err = sys_semctl(first, second, third, fourth); set_fs(old_fs); } break; default: err = -EINVAL; } out: return err; } #define MAXBUF (64*1024) static int do_sys32_msgsnd(int first, int second, int third, void *uptr) { struct msgbuf *p; struct msgbuf32 *up = (struct msgbuf32 *)uptr; mm_segment_t old_fs; int err; if (second < 0 || (second >= MAXBUF-sizeof(struct msgbuf))) return -EINVAL; p = kmalloc(second + sizeof(struct msgbuf), GFP_USER); if (!p) return -ENOMEM; err = get_user(p->mtype, &up->mtype); err |= copy_from_user(p->mtext, &up->mtext, second); if (err) { err = -EFAULT; goto out; } old_fs = get_fs(); set_fs(KERNEL_DS); err = sys_msgsnd(first, p, second, third); set_fs(old_fs); out: kfree(p); return err; } static int do_sys32_msgrcv(int first, int second, int msgtyp, int third, int version, void *uptr) { struct msgbuf32 *up; struct msgbuf *p; mm_segment_t old_fs; int err; if (second < 0 || (second >= MAXBUF-sizeof(struct msgbuf))) return -EINVAL; if (!version) { struct ipc_kludge_32 *uipck = (struct ipc_kludge_32 *)uptr; struct ipc_kludge_32 ipck; err = -EINVAL; if (!uptr) goto out; err = -EFAULT; if (copy_from_user(&ipck, uipck, sizeof(struct ipc_kludge_32))) goto out; uptr = (void *)A(ipck.msgp); msgtyp = ipck.msgtyp; } err = -ENOMEM; p = kmalloc(second + sizeof (struct msgbuf), GFP_USER); if (!p) goto out; old_fs = get_fs(); set_fs(KERNEL_DS); err = sys_msgrcv(first, p, second, msgtyp, third); set_fs(old_fs); if (err < 0) goto free_then_out; up = (struct msgbuf32 *)uptr; if (put_user(p->mtype, &up->mtype) || copy_to_user(&up->mtext, p->mtext, err)) err = -EFAULT; free_then_out: kfree(p); out: return err; } static int do_sys32_msgctl(int first, int second, void *uptr) { int err = -EINVAL, err2; mm_segment_t old_fs; switch (second & (~IPC_64)) { case IPC_INFO: case IPC_RMID: case MSG_INFO: err = sys_msgctl(first, second, (struct msqid_ds *)uptr); break; case IPC_SET: if (second & IPC_64) { struct msqid64_ds m64; struct msqid64_ds32 *up = (struct msqid64_ds32 *)uptr; err2 = copy_from_user(&m64.msg_perm, &up->msg_perm, sizeof(struct ipc64_perm)); err2 |= __get_user(m64.msg_qbytes, &up->msg_qbytes); if (err2) { err = -EFAULT; break; } old_fs = get_fs(); set_fs(KERNEL_DS); err = sys_msgctl(first, second, (struct msqid_ds *)&m64); set_fs(old_fs); } else { struct msqid_ds m; struct msqid_ds32 *up = (struct msqid_ds32 *)uptr; err2 = copy_from_user(&m.msg_perm, &up->msg_perm, sizeof(struct ipc_perm)); err2 |= __get_user(m.msg_qbytes, &up->msg_qbytes); if (err2) { err = -EFAULT; break; } old_fs = get_fs(); set_fs(KERNEL_DS); err = sys_msgctl(first, second, &m); set_fs(old_fs); } break; case IPC_STAT: case MSG_STAT: if (second & IPC_64) { struct msqid64_ds m64; struct msqid64_ds32 *up = (struct msqid64_ds32 *)uptr; old_fs = get_fs(); set_fs(KERNEL_DS); err = sys_msgctl(first, second, (struct msqid_ds *)&m64); set_fs(old_fs); err2 = copy_to_user(&up->msg_perm, &m64.msg_perm, sizeof(struct ipc64_perm)); err2 |= __put_user(m64.msg_stime, &up->msg_stime); err2 |= __put_user(m64.msg_rtime, &up->msg_rtime); err2 |= __put_user(m64.msg_ctime, &up->msg_ctime); err2 |= __put_user(m64.msg_cbytes, &up->msg_cbytes); err2 |= __put_user(m64.msg_qnum, &up->msg_qnum); err2 |= __put_user(m64.msg_qbytes, &up->msg_qbytes); err2 |= __put_user(m64.msg_lspid, &up->msg_lspid); err2 |= __put_user(m64.msg_lrpid, &up->msg_lrpid); if (err2) err = -EFAULT; } else { struct msqid64_ds m; struct msqid_ds32 *up = (struct msqid_ds32 *)uptr; old_fs = get_fs(); set_fs(KERNEL_DS); err = sys_msgctl(first, second, (struct msqid_ds *)&m); set_fs(old_fs); err2 = copy_to_user(&up->msg_perm, &m.msg_perm, sizeof(struct ipc_perm)); err2 |= __put_user(m.msg_stime, &up->msg_stime); err2 |= __put_user(m.msg_rtime, &up->msg_rtime); err2 |= __put_user(m.msg_ctime, &up->msg_ctime); err2 |= __put_user(m.msg_cbytes, &up->msg_cbytes); err2 |= __put_user(m.msg_qnum, &up->msg_qnum); err2 |= __put_user(m.msg_qbytes, &up->msg_qbytes); err2 |= __put_user(m.msg_lspid, &up->msg_lspid); err2 |= __put_user(m.msg_lrpid, &up->msg_lrpid); if (err2) err = -EFAULT; } break; } return err; } static int do_sys32_shmat(int first, int second, int third, int version, void *uptr) { unsigned long raddr; u32 *uaddr = (u32 *)A((u32)third); int err = -EINVAL; if (version == 1) return err; err = do_shmat(first, uptr, second, &raddr); if (err) return err; err = put_user(raddr, uaddr); return err; } static int do_sys32_shmctl(int first, int second, void *uptr) { int err = -EINVAL, err2; mm_segment_t old_fs; switch (second & (~IPC_64)) { case IPC_INFO: case IPC_RMID: case SHM_LOCK: case SHM_UNLOCK: err = sys_shmctl(first, second, (struct shmid_ds *)uptr); break; case IPC_SET: if (second & IPC_64) { struct shmid64_ds32 *up = (struct shmid64_ds32 *)uptr; struct shmid64_ds s64; err = get_user(s64.shm_perm.uid, &up->shm_perm.uid); err |= __get_user(s64.shm_perm.gid, &up->shm_perm.gid); err |= __get_user(s64.shm_perm.mode, &up->shm_perm.mode); if (err) break; old_fs = get_fs(); set_fs(KERNEL_DS); err = sys_shmctl(first, second, (struct shmid_ds *)&s64); set_fs(old_fs); } else { struct shmid_ds32 *up = (struct shmid_ds32 *)uptr; struct shmid_ds s; err = get_user(s.shm_perm.uid, &up->shm_perm.uid); err |= __get_user(s.shm_perm.gid, &up->shm_perm.gid); err |= __get_user(s.shm_perm.mode, &up->shm_perm.mode); if (err) break; old_fs = get_fs(); set_fs(KERNEL_DS); err = sys_shmctl(first, second, &s); set_fs(old_fs); } break; case IPC_STAT: case SHM_STAT: if (second & IPC_64) { struct shmid64_ds32 *up = (struct shmid64_ds32 *)uptr; struct shmid64_ds s64; old_fs = get_fs(); set_fs(KERNEL_DS); err = sys_shmctl(first, second, (struct shmid_ds *)&s64); set_fs(old_fs); if (err < 0) break; err2 = copy_to_user(&up->shm_perm, &s64.shm_perm, sizeof(struct ipc64_perm)); err2 |= __put_user(s64.shm_atime, &up->shm_atime); err2 |= __put_user(s64.shm_dtime, &up->shm_dtime); err2 |= __put_user(s64.shm_ctime, &up->shm_ctime); err2 |= __put_user(s64.shm_segsz, &up->shm_segsz); err2 |= __put_user(s64.shm_nattch, &up->shm_nattch); err2 |= __put_user(s64.shm_cpid, &up->shm_cpid); err2 |= __put_user(s64.shm_lpid, &up->shm_lpid); if (err2) err = -EFAULT; } else { struct shmid_ds32 *up = (struct shmid_ds32 *)uptr; struct shmid_ds s; old_fs = get_fs(); set_fs(KERNEL_DS); err = sys_shmctl(first, second, &s); set_fs(old_fs); if (err < 0) break; err2 = copy_to_user(&up->shm_perm, &s.shm_perm, sizeof(struct ipc_perm)); err2 |= __put_user (s.shm_atime, &up->shm_atime); err2 |= __put_user (s.shm_dtime, &up->shm_dtime); err2 |= __put_user (s.shm_ctime, &up->shm_ctime); err2 |= __put_user (s.shm_segsz, &up->shm_segsz); err2 |= __put_user (s.shm_nattch, &up->shm_nattch); err2 |= __put_user (s.shm_cpid, &up->shm_cpid); err2 |= __put_user (s.shm_lpid, &up->shm_lpid); if (err2) err = -EFAULT; } break; case SHM_INFO: { struct shm_info si; struct shm_info32 { int used_ids; u32 shm_tot, shm_rss, shm_swp; u32 swap_attempts, swap_successes; } *uip = (struct shm_info32 *)uptr; old_fs = get_fs(); set_fs(KERNEL_DS); err = sys_shmctl(first, second, (struct shmid_ds *)&si); set_fs(old_fs); if (err < 0) break; err2 = put_user(si.used_ids, &uip->used_ids); err2 |= __put_user(si.shm_tot, &uip->shm_tot); err2 |= __put_user(si.shm_rss, &uip->shm_rss); err2 |= __put_user(si.shm_swp, &uip->shm_swp); err2 |= __put_user(si.swap_attempts, &uip->swap_attempts); err2 |= __put_user(si.swap_successes, &uip->swap_successes); if (err2) err = -EFAULT; break; } } return err; } static int sys32_semtimedop(int semid, struct sembuf *tsems, int nsems, const struct compat_timespec *timeout32) { struct compat_timespec t32; struct timespec *t64 = compat_alloc_user_space(sizeof(*t64)); if (copy_from_user(&t32, timeout32, sizeof(t32))) return -EFAULT; if (put_user(t32.tv_sec, &t64->tv_sec) || put_user(t32.tv_nsec, &t64->tv_nsec)) return -EFAULT; return sys_semtimedop(semid, tsems, nsems, t64); } /* * Note: it is necessary to treat first_parm, second_parm, and * third_parm as unsigned ints, with the corresponding cast to a * signed int to insure that the proper conversion (sign extension) * between the register representation of a signed int (msr in 32-bit * mode) and the register representation of a signed int (msr in * 64-bit mode) is performed. */ asmlinkage long sys32_ipc(u32 call, u32 first_parm, u32 second_parm, u32 third_parm, u32 ptr, u32 fifth) { int first = (int)first_parm; int second = (int)second_parm; int third = (int)third_parm; int version, err; version = call >> 16; /* hack for backward compatibility */ call &= 0xffff; switch (call) { case SEMOP: /* struct sembuf is the same on 32 and 64bit :)) */ err = sys_semtimedop(first, (struct sembuf *)AA(ptr), second, NULL); break; case SEMTIMEDOP: err = sys32_semtimedop(first, (struct sembuf *)AA(ptr), second, (const struct compat_timespec *)AA(fifth)); break; case SEMGET: err = sys_semget(first, second, third); break; case SEMCTL: err = do_sys32_semctl(first, second, third, (void *)AA(ptr)); break; case MSGSND: err = do_sys32_msgsnd(first, second, third, (void *)AA(ptr)); break; case MSGRCV: err = do_sys32_msgrcv(first, second, fifth, third, version, (void *)AA(ptr)); break; case MSGGET: err = sys_msgget((key_t)first, second); break; case MSGCTL: err = do_sys32_msgctl(first, second, (void *)AA(ptr)); break; case SHMAT: err = do_sys32_shmat(first, second, third, version, (void *)AA(ptr)); break; case SHMDT: err = sys_shmdt((char *)AA(ptr)); break; case SHMGET: err = sys_shmget(first, second, third); break; case SHMCTL: err = do_sys32_shmctl(first, second, (void *)AA(ptr)); break; default: err = -ENOSYS; break; } return err; } /* Note: it is necessary to treat out_fd and in_fd as unsigned ints, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_sendfile(u32 out_fd, u32 in_fd, compat_off_t* offset, u32 count) { mm_segment_t old_fs = get_fs(); int ret; off_t of; if (offset && get_user(of, offset)) return -EFAULT; set_fs(KERNEL_DS); ret = sys_sendfile((int)out_fd, (int)in_fd, offset ? &of : NULL, count); set_fs(old_fs); if (offset && put_user(of, offset)) return -EFAULT; return ret; } asmlinkage int sys32_sendfile64(int out_fd, int in_fd, compat_loff_t *offset, s32 count) { mm_segment_t old_fs = get_fs(); int ret; loff_t lof; if (offset && get_user(lof, offset)) return -EFAULT; set_fs(KERNEL_DS); ret = sys_sendfile64(out_fd, in_fd, offset ? &lof : NULL, count); set_fs(old_fs); if (offset && put_user(lof, offset)) return -EFAULT; return ret; } /* * count32() counts the number of arguments/envelopes */ static int count32(u32 * argv, int max) { int i = 0; if (argv != NULL) { for (;;) { u32 p; int error; error = get_user(p,argv); if (error) return error; if (!p) break; argv++; if (++i > max) return -E2BIG; } } return i; } /* * 'copy_string32()' copies argument/envelope strings from user * memory to free pages in kernel mem. These are in a format ready * to be put directly into the top of new user memory. */ static int copy_strings32(int argc, u32 * argv, struct linux_binprm *bprm) { while (argc-- > 0) { u32 str; int len; unsigned long pos; if (get_user(str, argv + argc) || !str || !(len = strnlen_user((char *)A(str), bprm->p))) return -EFAULT; if (bprm->p < len) return -E2BIG; bprm->p -= len; pos = bprm->p; while (len) { char *kaddr; struct page *page; int offset, bytes_to_copy, new, err; offset = pos % PAGE_SIZE; page = bprm->page[pos / PAGE_SIZE]; new = 0; if (!page) { page = alloc_page(GFP_USER); bprm->page[pos / PAGE_SIZE] = page; if (!page) return -ENOMEM; new = 1; } kaddr = (char *)kmap(page); if (new && offset) memset(kaddr, 0, offset); bytes_to_copy = PAGE_SIZE - offset; if (bytes_to_copy > len) { bytes_to_copy = len; if (new) memset(kaddr+offset+len, 0, PAGE_SIZE-offset-len); } err = copy_from_user(kaddr + offset, (char *)A(str), bytes_to_copy); kunmap((unsigned long)kaddr); if (err) return -EFAULT; pos += bytes_to_copy; str += bytes_to_copy; len -= bytes_to_copy; } } return 0; } /* * sys32_execve() executes a new program. */ static int do_execve32(char * filename, u32 * argv, u32 * envp, struct pt_regs * regs) { struct linux_binprm bprm; struct file * file; int retval; int i; sched_balance_exec(); file = open_exec(filename); retval = PTR_ERR(file); if (IS_ERR(file)) return retval; bprm.p = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *); memset(bprm.page, 0, MAX_ARG_PAGES * sizeof(bprm.page[0])); bprm.file = file; bprm.filename = filename; bprm.interp = filename; bprm.sh_bang = 0; bprm.loader = 0; bprm.exec = 0; bprm.security = NULL; bprm.mm = mm_alloc(); retval = -ENOMEM; if (!bprm.mm) goto out_file; retval = init_new_context(current, bprm.mm); if (retval < 0) goto out_mm; bprm.argc = count32(argv, bprm.p / sizeof(u32)); if ((retval = bprm.argc) < 0) goto out_mm; bprm.envc = count32(envp, bprm.p / sizeof(u32)); if ((retval = bprm.envc) < 0) goto out_mm; retval = security_bprm_alloc(&bprm); if (retval) goto out; retval = prepare_binprm(&bprm); if (retval < 0) goto out; retval = copy_strings_kernel(1, &bprm.filename, &bprm); if (retval < 0) goto out; bprm.exec = bprm.p; retval = copy_strings32(bprm.envc, envp, &bprm); if (retval < 0) goto out; retval = copy_strings32(bprm.argc, argv, &bprm); if (retval < 0) goto out; retval = search_binary_handler(&bprm,regs); if (retval >= 0) { /* execve success */ security_bprm_free(&bprm); return retval; } out: /* Something went wrong, return the inode and free the argument pages*/ for (i = 0 ; i < MAX_ARG_PAGES ; i++) { struct page * page = bprm.page[i]; if (page) __free_page(page); } if (bprm.security) security_bprm_free(&bprm); out_mm: if (bprm.mm) mmdrop(bprm.mm); out_file: if (bprm.file) { allow_write_access(bprm.file); fput(bprm.file); } return retval; } long sys32_execve(unsigned long a0, unsigned long a1, unsigned long a2, unsigned long a3, unsigned long a4, unsigned long a5, struct pt_regs *regs) { int error; char * filename; filename = getname((char *) a0); error = PTR_ERR(filename); if (IS_ERR(filename)) goto out; if (regs->msr & MSR_FP) giveup_fpu(current); #ifdef CONFIG_ALTIVEC if (regs->msr & MSR_VEC) giveup_altivec(current); #endif /* CONFIG_ALTIVEC */ error = do_execve32(filename, (u32*) a1, (u32*) a2, regs); if (error == 0) current->ptrace &= ~PT_DTRACE; putname(filename); out: return error; } /* Set up a thread for executing a new program. */ void start_thread32(struct pt_regs* regs, unsigned long nip, unsigned long sp) { set_fs(USER_DS); memset(regs->gpr, 0, sizeof(regs->gpr)); memset(®s->ctr, 0, 4 * sizeof(regs->ctr)); regs->nip = nip; regs->gpr[1] = sp; regs->msr = MSR_USER32; #ifndef CONFIG_SMP if (last_task_used_math == current) last_task_used_math = 0; #endif /* CONFIG_SMP */ current->thread.fpscr = 0; memset(current->thread.fpr, 0, sizeof(current->thread.fpr)); #ifdef CONFIG_ALTIVEC #ifndef CONFIG_SMP if (last_task_used_altivec == current) last_task_used_altivec = 0; #endif /* CONFIG_SMP */ memset(current->thread.vr, 0, sizeof(current->thread.vr)); current->thread.vscr.u[0] = 0; current->thread.vscr.u[1] = 0; current->thread.vscr.u[2] = 0; current->thread.vscr.u[3] = 0x00010000; /* Java mode disabled */ current->thread.vrsave = 0; current->thread.used_vr = 0; #endif /* CONFIG_ALTIVEC */ } /* Note: it is necessary to treat option as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_prctl(u32 option, u32 arg2, u32 arg3, u32 arg4, u32 arg5) { return sys_prctl((int)option, (unsigned long) arg2, (unsigned long) arg3, (unsigned long) arg4, (unsigned long) arg5); } /* Note: it is necessary to treat pid as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_sched_rr_get_interval(u32 pid, struct compat_timespec *interval) { struct timespec t; int ret; mm_segment_t old_fs = get_fs (); set_fs (KERNEL_DS); ret = sys_sched_rr_get_interval((int)pid, &t); set_fs (old_fs); if (put_compat_timespec(&t, interval)) return -EFAULT; return ret; } asmlinkage int sys32_pciconfig_read(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf) { return sys_pciconfig_read((unsigned long) bus, (unsigned long) dfn, (unsigned long) off, (unsigned long) len, (unsigned char *)AA(ubuf)); } asmlinkage int sys32_pciconfig_write(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf) { return sys_pciconfig_write((unsigned long) bus, (unsigned long) dfn, (unsigned long) off, (unsigned long) len, (unsigned char *)AA(ubuf)); } #define IOBASE_BRIDGE_NUMBER 0 #define IOBASE_MEMORY 1 #define IOBASE_IO 2 #define IOBASE_ISA_IO 3 #define IOBASE_ISA_MEM 4 asmlinkage int sys32_pciconfig_iobase(u32 which, u32 in_bus, u32 in_devfn) { struct pci_controller* hose; struct list_head *ln; struct pci_bus *bus = NULL; struct device_node *hose_node; /* Argh ! Please forgive me for that hack, but that's the * simplest way to get existing XFree to not lockup on some * G5 machines... So when something asks for bus 0 io base * (bus 0 is HT root), we return the AGP one instead. */ #ifdef CONFIG_PPC_PMAC if (systemcfg->platform == PLATFORM_POWERMAC && machine_is_compatible("MacRISC4")) if (in_bus == 0) in_bus = 0xf0; #endif /* CONFIG_PPC_PMAC */ /* That syscall isn't quite compatible with PCI domains, but it's * used on pre-domains setup. We return the first match */ for (ln = pci_root_buses.next; ln != &pci_root_buses; ln = ln->next) { bus = pci_bus_b(ln); if (in_bus >= bus->number && in_bus < (bus->number + bus->subordinate)) break; bus = NULL; } if (bus == NULL || bus->sysdata == NULL) return -ENODEV; hose_node = (struct device_node *)bus->sysdata; hose = hose_node->phb; switch (which) { case IOBASE_BRIDGE_NUMBER: return (long)hose->first_busno; case IOBASE_MEMORY: return (long)hose->pci_mem_offset; case IOBASE_IO: return (long)hose->io_base_phys; case IOBASE_ISA_IO: return (long)isa_io_base; case IOBASE_ISA_MEM: return -EINVAL; } return -EOPNOTSUPP; } asmlinkage int ppc64_newuname(struct new_utsname * name) { int errno = sys_newuname(name); if (current->personality == PER_LINUX32 && !errno) { if(copy_to_user(name->machine, "ppc\0\0", 8)) { errno = -EFAULT; } } return errno; } asmlinkage int ppc64_personality(unsigned long personality) { int ret; if (current->personality == PER_LINUX32 && personality == PER_LINUX) personality = PER_LINUX32; ret = sys_personality(personality); if (ret == PER_LINUX32) ret = PER_LINUX; return ret; } /* Note: it is necessary to treat mode as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_access(const char * filename, u32 mode) { return sys_access(filename, (int)mode); } /* Note: it is necessary to treat mode as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_creat(const char * pathname, u32 mode) { return sys_creat(pathname, (int)mode); } /* Note: it is necessary to treat pid and options as unsigned ints, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_waitpid(u32 pid, unsigned int * stat_addr, u32 options) { return sys_waitpid((int)pid, stat_addr, (int)options); } /* Note: it is necessary to treat gidsetsize as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_getgroups(u32 gidsetsize, gid_t *grouplist) { return sys_getgroups((int)gidsetsize, grouplist); } /* Note: it is necessary to treat pid as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_getpgid(u32 pid) { return sys_getpgid((int)pid); } /* Note: it is necessary to treat which and who as unsigned ints, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_getpriority(u32 which, u32 who) { return sys_getpriority((int)which, (int)who); } /* Note: it is necessary to treat pid as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_getsid(u32 pid) { return sys_getsid((int)pid); } /* Note: it is necessary to treat pid and sig as unsigned ints, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_kill(u32 pid, u32 sig) { return sys_kill((int)pid, (int)sig); } /* Note: it is necessary to treat mode as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_mkdir(const char * pathname, u32 mode) { return sys_mkdir(pathname, (int)mode); } long sys32_nice(u32 increment) { /* sign extend increment */ return sys_nice((int)increment); } off_t ppc32_lseek(unsigned int fd, u32 offset, unsigned int origin) { /* sign extend n */ return sys_lseek(fd, (int)offset, origin); } /* * This is just a version for 32-bit applications which does * not force O_LARGEFILE on. */ long sys32_open(const char * filename, int flags, int mode) { char * tmp; int fd, error; tmp = getname(filename); fd = PTR_ERR(tmp); if (!IS_ERR(tmp)) { fd = get_unused_fd(); if (fd >= 0) { struct file * f = filp_open(tmp, flags, mode); error = PTR_ERR(f); if (IS_ERR(f)) goto out_error; fd_install(fd, f); } out: putname(tmp); } return fd; out_error: put_unused_fd(fd); fd = error; goto out; } /* Note: it is necessary to treat bufsiz as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_readlink(const char * path, char * buf, u32 bufsiz) { return sys_readlink(path, buf, (int)bufsiz); } /* Note: it is necessary to treat option as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_sched_get_priority_max(u32 policy) { return sys_sched_get_priority_max((int)policy); } /* Note: it is necessary to treat policy as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_sched_get_priority_min(u32 policy) { return sys_sched_get_priority_min((int)policy); } /* Note: it is necessary to treat pid as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_sched_getparam(u32 pid, struct sched_param *param) { return sys_sched_getparam((int)pid, param); } /* Note: it is necessary to treat pid as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_sched_getscheduler(u32 pid) { return sys_sched_getscheduler((int)pid); } /* Note: it is necessary to treat pid as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_sched_setparam(u32 pid, struct sched_param *param) { return sys_sched_setparam((int)pid, param); } /* Note: it is necessary to treat pid and policy as unsigned ints, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_sched_setscheduler(u32 pid, u32 policy, struct sched_param *param) { return sys_sched_setscheduler((int)pid, (int)policy, param); } /* Note: it is necessary to treat len as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_setdomainname(char *name, u32 len) { return sys_setdomainname(name, (int)len); } /* Note: it is necessary to treat gidsetsize as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_setgroups(u32 gidsetsize, gid_t *grouplist) { return sys_setgroups((int)gidsetsize, grouplist); } asmlinkage long sys32_sethostname(char *name, u32 len) { /* sign extend len */ return sys_sethostname(name, (int)len); } /* Note: it is necessary to treat pid and pgid as unsigned ints, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_setpgid(u32 pid, u32 pgid) { return sys_setpgid((int)pid, (int)pgid); } long sys32_setpriority(u32 which, u32 who, u32 niceval) { /* sign extend which, who and niceval */ return sys_setpriority((int)which, (int)who, (int)niceval); } /* Note: it is necessary to treat newmask as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_ssetmask(u32 newmask) { return sys_ssetmask((int) newmask); } long sys32_syslog(u32 type, char * buf, u32 len) { /* sign extend len */ return sys_syslog(type, buf, (int)len); } /* Note: it is necessary to treat mask as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long sys32_umask(u32 mask) { return sys_umask((int)mask); } struct __sysctl_args32 { u32 name; int nlen; u32 oldval; u32 oldlenp; u32 newval; u32 newlen; u32 __unused[4]; }; extern asmlinkage long sys32_sysctl(struct __sysctl_args32 *args) { struct __sysctl_args32 tmp; int error; size_t oldlen, *oldlenp = NULL; unsigned long addr = (((long)&args->__unused[0]) + 7) & ~7; if (copy_from_user(&tmp, args, sizeof(tmp))) return -EFAULT; if (tmp.oldval && tmp.oldlenp) { /* Duh, this is ugly and might not work if sysctl_args is in read-only memory, but do_sysctl does indirectly a lot of uaccess in both directions and we'd have to basically copy the whole sysctl.c here, and glibc's __sysctl uses rw memory for the structure anyway. */ if (get_user(oldlen, (u32 *)A(tmp.oldlenp)) || put_user(oldlen, (size_t *)addr)) return -EFAULT; oldlenp = (size_t *)addr; } lock_kernel(); error = do_sysctl((int *)A(tmp.name), tmp.nlen, (void *)A(tmp.oldval), oldlenp, (void *)A(tmp.newval), tmp.newlen); unlock_kernel(); if (oldlenp) { if (!error) { if (get_user(oldlen, (size_t *)addr) || put_user(oldlen, (u32 *)A(tmp.oldlenp))) error = -EFAULT; } copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)); } return error; } asmlinkage long sys32_time(compat_time_t* tloc) { compat_time_t secs; struct timeval tv; do_gettimeofday( &tv ); secs = tv.tv_sec; if (tloc) { if (put_user(secs,tloc)) secs = -EFAULT; } return secs; } int sys32_olduname(struct oldold_utsname * name) { int error; if (!name) return -EFAULT; if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname))) return -EFAULT; down_read(&uts_sem); error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN); error -= __put_user(0,name->sysname+__OLD_UTS_LEN); error -= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN); error -= __put_user(0,name->nodename+__OLD_UTS_LEN); error -= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN); error -= __put_user(0,name->release+__OLD_UTS_LEN); error -= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN); error -= __put_user(0,name->version+__OLD_UTS_LEN); error -= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN); error = __put_user(0,name->machine+__OLD_UTS_LEN); up_read(&uts_sem); error = error ? -EFAULT : 0; return error; } unsigned long sys32_mmap2(unsigned long addr, size_t len, unsigned long prot, unsigned long flags, unsigned long fd, unsigned long pgoff) { /* This should remain 12 even if PAGE_SIZE changes */ return sys_mmap(addr, len, prot, flags, fd, pgoff << 12); } int get_compat_timeval(struct timeval *tv, struct compat_timeval *ctv) { return (verify_area(VERIFY_READ, ctv, sizeof(*ctv)) || __get_user(tv->tv_sec, &ctv->tv_sec) || __get_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0; } long sys32_utimes(char *filename, struct compat_timeval *tvs) { char *kfilename; struct timeval ktvs[2]; mm_segment_t old_fs; long ret; kfilename = getname(filename); ret = PTR_ERR(kfilename); if (!IS_ERR(kfilename)) { if (tvs) { if (get_compat_timeval(&ktvs[0], &tvs[0]) || get_compat_timeval(&ktvs[1], &tvs[1])) return -EFAULT; } old_fs = get_fs(); set_fs(KERNEL_DS); ret = do_utimes(kfilename, (tvs ? &ktvs[0] : NULL)); set_fs(old_fs); putname(kfilename); } return ret; } long sys32_tgkill(u32 tgid, u32 pid, int sig) { /* sign extend tgid, pid */ return sys_tgkill((int)tgid, (int)pid, sig); } /* * long long munging: * The 32 bit ABI passes long longs in an odd even register pair. */ compat_ssize_t sys32_pread64(unsigned int fd, char *ubuf, compat_size_t count, u32 reg6, u32 poshi, u32 poslo) { return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo); } compat_ssize_t sys32_pwrite64(unsigned int fd, char *ubuf, compat_size_t count, u32 reg6, u32 poshi, u32 poslo) { return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo); } compat_ssize_t sys32_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count) { return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count); } asmlinkage int sys32_truncate64(const char * path, u32 reg4, unsigned long high, unsigned long low) { return sys_truncate(path, (high << 32) | low); } asmlinkage int sys32_ftruncate64(unsigned int fd, u32 reg4, unsigned long high, unsigned long low) { return sys_ftruncate(fd, (high << 32) | low); } long ppc32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char *buf, size_t len) { return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low, buf, len); } long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low, size_t len, int advice) { return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, len, advice); } long ppc32_fadvise64_64(int fd, int advice, u32 offset_high, u32 offset_low, u32 len_high, u32 len_low) { return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, (u64)len_high << 32 | len_low, advice); } extern long sys_timer_create(clockid_t, sigevent_t *, timer_t *); long ppc32_timer_create(clockid_t clock, struct compat_sigevent __user *ev32, timer_t __user *timer_id) { sigevent_t event; timer_t t; long err; mm_segment_t savefs; if (ev32 == NULL) return sys_timer_create(clock, NULL, timer_id); memset(&event, 0, sizeof(event)); if (!access_ok(VERIFY_READ, ev32, sizeof(struct compat_sigevent)) || __get_user(event.sigev_value.sival_int, &ev32->sigev_value.sival_int) || __get_user(event.sigev_signo, &ev32->sigev_signo) || __get_user(event.sigev_notify, &ev32->sigev_notify) || __get_user(event.sigev_notify_thread_id, &ev32->sigev_notify_thread_id)) return -EFAULT; if (!access_ok(VERIFY_WRITE, timer_id, sizeof(timer_t))) return -EFAULT; savefs = get_fs(); set_fs(KERNEL_DS); err = sys_timer_create(clock, &event, &t); set_fs(savefs); if (err == 0) err = __put_user(t, timer_id); return err; } |