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 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335
|
/*--------------------------------------------------------------------*/
/*--- pthread intercepts for thread checking. ---*/
/*--- hg_intercepts.c ---*/
/*--------------------------------------------------------------------*/
/*
This file is part of Helgrind, a Valgrind tool for detecting errors
in threaded programs.
Copyright (C) 2007-2015 OpenWorks LLP
info@open-works.co.uk
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.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307, USA.
The GNU General Public License is contained in the file COPYING.
Neither the names of the U.S. Department of Energy nor the
University of California nor the names of its contributors may be
used to endorse or promote products derived from this software
without prior written permission.
*/
/* RUNS ON SIMULATED CPU
Interceptors for pthread_* functions, so that tc_main can see
significant thread events.
Important: when adding a function wrapper to this file, remember to
add a test case to tc20_verifywrap.c. A common cause of failure is
for wrappers to not engage on different distros, and
tc20_verifywrap essentially checks that each wrapper is really
doing something.
*/
// DDD: for Darwin, need to have non-"@*"-suffixed versions for all pthread
// functions that currently have them.
// Note also, in the comments and code below, all Darwin symbols start
// with a leading underscore, which is not shown either in the comments
// nor in the redirect specs.
#include "pub_tool_basics.h"
#include "pub_tool_redir.h"
#include "pub_tool_clreq.h"
#include "helgrind.h"
#include "config.h"
#if defined(VGO_solaris)
/* See porting comments in drd/drd_pthread_intercepts.c
However when a POSIX threads API function (for example pthread_cond_init)
is built upon the Solaris one (cond_init), intercept only the bottom one.
Helgrind does not contain generic synchronization nesting like DRD
and double intercept confuses it. */
#include <synch.h>
#include <thread.h>
#endif /* VGO_solaris */
#define TRACE_PTH_FNS 0
#define TRACE_QT4_FNS 0
#define TRACE_GNAT_FNS 0
/*----------------------------------------------------------------*/
/*--- ---*/
/*----------------------------------------------------------------*/
#if defined(VGO_solaris)
/* On Solaris, libpthread is just a filter library on top of libc.
* Threading and synchronization functions in runtime linker are not
* intercepted.
*/
#define PTH_FUNC(ret_ty, f, args...) \
ret_ty I_WRAP_SONAME_FNNAME_ZZ(VG_Z_LIBC_SONAME,f)(args); \
ret_ty I_WRAP_SONAME_FNNAME_ZZ(VG_Z_LIBC_SONAME,f)(args)
/* pthread_t is typedef'd to 'unsigned int' but in DO_CREQ_* macros
sizeof(Word) is expected. */
#define CREQ_PTHREAD_T Word
#define SEM_ERROR ret
#else
#define PTH_FUNC(ret_ty, f, args...) \
ret_ty I_WRAP_SONAME_FNNAME_ZZ(VG_Z_LIBPTHREAD_SONAME,f)(args); \
ret_ty I_WRAP_SONAME_FNNAME_ZZ(VG_Z_LIBPTHREAD_SONAME,f)(args)
#define CREQ_PTHREAD_T pthread_t
#define SEM_ERROR errno
#endif /* VGO_solaris */
// Do a client request. These are macros rather than a functions so
// as to avoid having an extra frame in stack traces.
// NB: these duplicate definitions in helgrind.h. But here, we
// can have better typing (Word etc) and assertions, whereas
// in helgrind.h we can't. Obviously it's important the two
// sets of definitions are kept in sync.
// nuke the previous definitions
#undef DO_CREQ_v_W
#undef DO_CREQ_v_WW
#undef DO_CREQ_W_WW
#undef DO_CREQ_v_WWW
#define DO_CREQ_v_W(_creqF, _ty1F,_arg1F) \
do { \
Word _arg1; \
assert(sizeof(_ty1F) == sizeof(Word)); \
_arg1 = (Word)(_arg1F); \
VALGRIND_DO_CLIENT_REQUEST_STMT((_creqF), \
_arg1, 0,0,0,0); \
} while (0)
#define DO_CREQ_v_WW(_creqF, _ty1F,_arg1F, _ty2F,_arg2F) \
do { \
Word _arg1, _arg2; \
assert(sizeof(_ty1F) == sizeof(Word)); \
assert(sizeof(_ty2F) == sizeof(Word)); \
_arg1 = (Word)(_arg1F); \
_arg2 = (Word)(_arg2F); \
VALGRIND_DO_CLIENT_REQUEST_STMT((_creqF), \
_arg1,_arg2,0,0,0); \
} while (0)
#define DO_CREQ_W_WW(_resF, _creqF, _ty1F,_arg1F, \
_ty2F,_arg2F) \
do { \
Word _res, _arg1, _arg2; \
assert(sizeof(_ty1F) == sizeof(Word)); \
assert(sizeof(_ty2F) == sizeof(Word)); \
_arg1 = (Word)(_arg1F); \
_arg2 = (Word)(_arg2F); \
_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(2, \
(_creqF), \
_arg1,_arg2,0,0,0); \
_resF = _res; \
} while (0)
#define DO_CREQ_v_WWW(_creqF, _ty1F,_arg1F, \
_ty2F,_arg2F, _ty3F, _arg3F) \
do { \
Word _arg1, _arg2, _arg3; \
assert(sizeof(_ty1F) == sizeof(Word)); \
assert(sizeof(_ty2F) == sizeof(Word)); \
assert(sizeof(_ty3F) == sizeof(Word)); \
_arg1 = (Word)(_arg1F); \
_arg2 = (Word)(_arg2F); \
_arg3 = (Word)(_arg3F); \
VALGRIND_DO_CLIENT_REQUEST_STMT((_creqF), \
_arg1,_arg2,_arg3,0,0); \
} while (0)
#define DO_CREQ_v_WWWW(_creqF, _ty1F,_arg1F, \
_ty2F, _arg2F, _ty3F, _arg3F, \
_ty4F, _arg4F) \
do { \
Word _arg1, _arg2, _arg3, _arg4; \
assert(sizeof(_ty1F) == sizeof(Word)); \
assert(sizeof(_ty2F) == sizeof(Word)); \
assert(sizeof(_ty3F) == sizeof(Word)); \
assert(sizeof(_ty4F) == sizeof(Word)); \
_arg1 = (Word)(_arg1F); \
_arg2 = (Word)(_arg2F); \
_arg3 = (Word)(_arg3F); \
_arg4 = (Word)(_arg4F); \
VALGRIND_DO_CLIENT_REQUEST_STMT((_creqF), \
_arg1,_arg2,_arg3,_arg4,0); \
} while (0)
#define DO_PthAPIerror(_fnnameF, _errF) \
do { \
const char* _fnname = (_fnnameF); \
long _err = (long)(int)(_errF); \
const char* _errstr = lame_strerror(_err); \
DO_CREQ_v_WWW(_VG_USERREQ__HG_PTH_API_ERROR, \
char*,_fnname, \
long,_err, char*,_errstr); \
} while (0)
/* Needed for older glibcs (2.3 and older, at least) who don't
otherwise "know" about pthread_rwlock_anything or about
PTHREAD_MUTEX_RECURSIVE (amongst things). */
#define _GNU_SOURCE 1
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <pthread.h>
/* A standalone memcmp. */
__attribute__((noinline))
static int my_memcmp ( const void* ptr1, const void* ptr2, size_t size)
{
const unsigned char* uchar_ptr1 = (const unsigned char*) ptr1;
const unsigned char* uchar_ptr2 = (const unsigned char*) ptr2;
size_t i;
for (i = 0; i < size; ++i) {
if (uchar_ptr1[i] != uchar_ptr2[i])
return (uchar_ptr1[i] < uchar_ptr2[i]) ? -1 : 1;
}
return 0;
}
/* A lame version of strerror which doesn't use the real libc
strerror_r, since using the latter just generates endless more
threading errors (glibc goes off and does tons of crap w.r.t.
locales etc) */
static const HChar* lame_strerror ( long err )
{
switch (err) {
case EPERM: return "EPERM: Operation not permitted";
case ENOENT: return "ENOENT: No such file or directory";
case ESRCH: return "ESRCH: No such process";
case EINTR: return "EINTR: Interrupted system call";
case EBADF: return "EBADF: Bad file number";
case EAGAIN: return "EAGAIN: Try again";
case ENOMEM: return "ENOMEM: Out of memory";
case EACCES: return "EACCES: Permission denied";
case EFAULT: return "EFAULT: Bad address";
case EEXIST: return "EEXIST: File exists";
case EINVAL: return "EINVAL: Invalid argument";
case EMFILE: return "EMFILE: Too many open files";
case ENOSYS: return "ENOSYS: Function not implemented";
case EOVERFLOW: return "EOVERFLOW: Value too large "
"for defined data type";
case EBUSY: return "EBUSY: Device or resource busy";
case ETIMEDOUT: return "ETIMEDOUT: Connection timed out";
case EDEADLK: return "EDEADLK: Resource deadlock would occur";
case EOPNOTSUPP: return "EOPNOTSUPP: Operation not supported on "
"transport endpoint"; /* honest, guv */
case ETIME: return "ETIME: Timer expired";
default: return "hg_intercepts.c: lame_strerror(): "
"unhandled case -- please fix me!";
}
}
#if defined(VGO_solaris)
/*
* Solaris provides higher throughput, parallelism and scalability than other
* operating systems, at the cost of more fine-grained locking activity.
* This means for example that when a thread is created under Linux, just one
* big lock in glibc is used for all thread setup. Solaris libc uses several
* fine-grained locks and the creator thread resumes its activities as soon
* as possible, leaving for example stack and TLS setup activities to the
* created thread.
*
* This situation confuses Helgrind as it assumes there is some false ordering
* in place between creator and created thread; and therefore many types of
* race conditions in the application would not be reported. To prevent such
* false ordering, command line option --ignore-thread-creation is set to
* 'yes' by default on Solaris. All activity (loads, stores, client requests)
* is therefore ignored during:
* - pthread_create() call in the creator thread [libc.so]
* - thread creation phase (stack and TLS setup) in the created thread [libc.so]
*
* As explained in the comments for _ti_bind_guard(), whenever the runtime
* linker has to perform any activity (such as resolving a symbol), it protects
* its data structures by calling into rt_bind_guard() which in turn invokes
* _ti_bind_guard() in libc. Pointers to _ti_bind_guard() and _ti_bind_clear()
* are passed from libc to runtime linker in _ld_libc() call during libc_init().
* All activity is also ignored during:
* - runtime dynamic linker work between rt_bind_guard() and rt_bind_clear()
* calls [ld.so]
*
* This also means that Helgrind does not report race conditions in libc (when
* --ignore-thread-creation=yes) and runtime linker itself (unconditionally)
* during these ignored sequences.
*/
#include "pub_tool_libcassert.h"
#include "pub_tool_vki.h"
/*
* Original function pointers for _ti_bind_guard() and _ti_bind_clear()
* from libc. They are intercepted in function wrapper of _ld_libc().
*/
typedef int (*hg_rtld_guard_fn)(int flags);
static hg_rtld_guard_fn hg_rtld_bind_guard = NULL;
static hg_rtld_guard_fn hg_rtld_bind_clear = NULL;
static void hg_init(void) __attribute__((constructor));
static void hg_init(void)
{
if ((hg_rtld_bind_guard == NULL) || (hg_rtld_bind_clear == NULL)) {
fprintf(stderr,
"Bind guard functions for the runtime linker (ld.so.1) were not intercepted.\n"
"This means the interface between libc and runtime linker changed\n"
"and Helgrind needs to be ported properly. Giving up.\n");
tl_assert(0);
}
}
/*
* Intercepts for _ti_bind_guard() and _ti_bind_clear() functions from libc.
* These are intercepted during _ld_libc() call by identifying CI_BIND_GUARD
* and CI_BIND_CLEAR, to provide resilience against function renaming.
*/
static int _ti_bind_guard_intercept_WRK(int flags)
{
VALGRIND_DO_CLIENT_REQUEST_STMT(_VG_USERREQ__HG_RTLD_BIND_GUARD,
flags, 0, 0, 0, 0);
return hg_rtld_bind_guard(flags);
}
static int _ti_bind_clear_intercept_WRK(int flags)
{
int ret = hg_rtld_bind_clear(flags);
VALGRIND_DO_CLIENT_REQUEST_STMT(_VG_USERREQ__HG_RTLD_BIND_CLEAR,
flags, 0, 0, 0, 0);
return ret;
}
/*
* Wrapped _ld_libc() from the runtime linker ld.so.1.
*/
void I_WRAP_SONAME_FNNAME_ZZ(VG_Z_LD_SO_1, ZuldZulibc)(vki_Lc_interface *ptr);
void I_WRAP_SONAME_FNNAME_ZZ(VG_Z_LD_SO_1, ZuldZulibc)(vki_Lc_interface *ptr)
{
OrigFn fn;
int tag;
VALGRIND_GET_ORIG_FN(fn);
vki_Lc_interface *funcs = ptr;
for (tag = funcs->ci_tag; tag != 0; tag = (++funcs)->ci_tag) {
switch (tag) {
case VKI_CI_BIND_GUARD:
if (funcs->vki_ci_un.ci_func != _ti_bind_guard_intercept_WRK) {
hg_rtld_bind_guard = funcs->vki_ci_un.ci_func;
funcs->vki_ci_un.ci_func = _ti_bind_guard_intercept_WRK;
}
break;
case VKI_CI_BIND_CLEAR:
if (funcs->vki_ci_un.ci_func != _ti_bind_clear_intercept_WRK) {
hg_rtld_bind_clear = funcs->vki_ci_un.ci_func;
funcs->vki_ci_un.ci_func = _ti_bind_clear_intercept_WRK;
}
break;
}
}
CALL_FN_v_W(fn, ptr);
}
#endif /* VGO_solaris */
/*----------------------------------------------------------------*/
/*--- pthread_create, pthread_join, pthread_exit ---*/
/*----------------------------------------------------------------*/
static void* mythread_wrapper ( void* xargsV )
{
volatile Word* xargs = (volatile Word*) xargsV;
void*(*fn)(void*) = (void*(*)(void*))xargs[0];
void* arg = (void*)xargs[1];
pthread_t me = pthread_self();
/* Tell the tool what my pthread_t is. */
DO_CREQ_v_W(_VG_USERREQ__HG_SET_MY_PTHREAD_T, CREQ_PTHREAD_T, me);
/* allow the parent to proceed. We can't let it proceed until
we're ready because (1) we need to make sure it doesn't exit and
hence deallocate xargs[] while we still need it, and (2) we
don't want either parent nor child to proceed until the tool has
been notified of the child's pthread_t.
Note that parent and child access args[] without a lock,
effectively using args[2] as a spinlock in order to get the
parent to wait until the child passes this point. The parent
disables checking on xargs[] before creating the child and
re-enables it once the child goes past this point, so the user
never sees the race. The previous approach (suppressing the
resulting error) was flawed, because it could leave shadow
memory for args[] in a state in which subsequent use of it by
the parent would report further races. */
xargs[2] = 0;
/* Now we can no longer safely use xargs[]. */
return (void*) fn( (void*)arg );
}
//-----------------------------------------------------------
// glibc: pthread_create@GLIBC_2.0
// glibc: pthread_create@@GLIBC_2.1
// glibc: pthread_create@@GLIBC_2.2.5
// darwin: pthread_create
// darwin: pthread_create_suspended_np (trapped)
//
/* ensure this has its own frame, so as to make it more distinguishable
in suppressions */
__attribute__((noinline))
static int pthread_create_WRK(pthread_t *thread, const pthread_attr_t *attr,
void *(*start) (void *), void *arg)
{
int ret;
OrigFn fn;
volatile Word xargs[3];
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_create wrapper"); fflush(stderr);
}
xargs[0] = (Word)start;
xargs[1] = (Word)arg;
xargs[2] = 1; /* serves as a spinlock -- sigh */
/* Disable checking on the spinlock and the two words used to
convey args to the child. Basically we need to make it appear
as if the child never accessed this area, since merely
suppressing the resulting races does not address the issue that
that piece of the parent's stack winds up in the "wrong" state
and therefore may give rise to mysterious races when the parent
comes to re-use this piece of stack in some other frame. */
VALGRIND_HG_DISABLE_CHECKING(&xargs, sizeof(xargs));
VALGRIND_DO_CLIENT_REQUEST_STMT(_VG_USERREQ__HG_PTHREAD_CREATE_BEGIN,
0, 0, 0, 0, 0);
CALL_FN_W_WWWW(ret, fn, thread,attr,mythread_wrapper,&xargs[0]);
VALGRIND_DO_CLIENT_REQUEST_STMT(_VG_USERREQ__HG_PTHREAD_CREATE_END,
0, 0, 0, 0, 0);
if (ret == 0) {
/* we have to wait for the child to notify the tool of its
pthread_t before continuing */
while (xargs[2] != 0) {
/* Do nothing. We need to spin until the child writes to
xargs[2]. However, that can lead to starvation in the
child and very long delays (eg, tc19_shadowmem on
ppc64-linux Fedora Core 6). So yield the cpu if we can,
to let the child run at the earliest available
opportunity. */
sched_yield();
}
} else {
DO_PthAPIerror( "pthread_create", ret );
}
/* Reenable checking on the area previously used to communicate
with the child. */
VALGRIND_HG_ENABLE_CHECKING(&xargs, sizeof(xargs));
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: pth_create -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, pthreadZucreateZAZa, // pthread_create@*
pthread_t *thread, const pthread_attr_t *attr,
void *(*start) (void *), void *arg) {
return pthread_create_WRK(thread, attr, start, arg);
}
#elif defined(VGO_darwin)
PTH_FUNC(int, pthreadZucreate, // pthread_create
pthread_t *thread, const pthread_attr_t *attr,
void *(*start) (void *), void *arg) {
return pthread_create_WRK(thread, attr, start, arg);
}
PTH_FUNC(int, pthreadZucreateZuZa, // pthread_create_*
pthread_t *thread, const pthread_attr_t *attr,
void *(*start) (void *), void *arg) {
// trap anything else
assert(0);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, pthreadZucreate, // pthread_create
pthread_t *thread, const pthread_attr_t *attr,
void *(*start) (void *), void *arg) {
return pthread_create_WRK(thread, attr, start, arg);
}
#else
# error "Unsupported OS"
#endif
#if defined(VGO_solaris)
/* Solaris also provides thr_create() in addition to pthread_create().
* Both pthread_create(3C) and thr_create(3C) are based on private
* _thrp_create().
*/
__attribute__((noinline))
static int thr_create_WRK(void *stk, size_t stksize, void *(*start)(void *),
void *arg, long flags, thread_t *new_thread)
{
int ret;
OrigFn fn;
volatile Word xargs[3];
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< thr_create wrapper"); fflush(stderr);
}
xargs[0] = (Word)start;
xargs[1] = (Word)arg;
xargs[2] = 1; /* serves as a spinlock -- sigh */
/* See comments in pthread_create_WRK() */
VALGRIND_HG_DISABLE_CHECKING(&xargs, sizeof(xargs));
VALGRIND_DO_CLIENT_REQUEST_STMT(_VG_USERREQ__HG_PTHREAD_CREATE_BEGIN,
0, 0, 0, 0, 0);
CALL_FN_W_6W(ret, fn, stk, stksize, mythread_wrapper, start, flags,
new_thread);
VALGRIND_DO_CLIENT_REQUEST_STMT(_VG_USERREQ__HG_PTHREAD_CREATE_END,
0, 0, 0, 0, 0);
if (ret == 0) {
while (xargs[2] != 0) {
/* See comments in pthread_create_WRK(). */
sched_yield();
}
} else {
DO_PthAPIerror("thr_create", ret);
}
VALGRIND_HG_ENABLE_CHECKING(&xargs, sizeof(xargs));
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: thr_create -> %d >>\n", ret);
}
return ret;
}
PTH_FUNC(int, thrZucreate, // thr_create
void *stk, size_t stksize, void *(*start)(void *),
void *arg, long flags, thread_t *new_thread) {
return thr_create_WRK(stk, stksize, start, arg, flags, new_thread);
}
#endif /* VGO_solaris */
//-----------------------------------------------------------
// glibc: pthread_join
// darwin: pthread_join
// darwin: pthread_join$NOCANCEL$UNIX2003
// darwin pthread_join$UNIX2003
__attribute__((noinline))
static int pthread_join_WRK(pthread_t thread, void** value_pointer)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_join wrapper"); fflush(stderr);
}
CALL_FN_W_WW(ret, fn, thread,value_pointer);
/* At least with NPTL as the thread library, this is safe because
it is guaranteed (by NPTL) that the joiner will completely gone
before pthread_join (the original) returns. See email below.*/
if (ret == 0 /*success*/) {
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_JOIN_POST, CREQ_PTHREAD_T, thread);
} else {
DO_PthAPIerror( "pthread_join", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: pth_join -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, pthreadZujoin, // pthread_join
pthread_t thread, void** value_pointer) {
return pthread_join_WRK(thread, value_pointer);
}
#elif defined(VGO_darwin)
PTH_FUNC(int, pthreadZujoinZa, // pthread_join*
pthread_t thread, void** value_pointer) {
return pthread_join_WRK(thread, value_pointer);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, pthreadZujoin, // pthread_join
pthread_t thread, void** value_pointer) {
return pthread_join_WRK(thread, value_pointer);
}
#else
# error "Unsupported OS"
#endif
/* Behaviour of pthread_join on NPTL:
Me:
I have a question re the NPTL pthread_join implementation.
Suppose I am the thread 'stayer'.
If I call pthread_join(quitter), is it guaranteed that the
thread 'quitter' has really exited before pthread_join returns?
IOW, is it guaranteed that 'quitter' will not execute any further
instructions after pthread_join returns?
I believe this is true based on the following analysis of
glibc-2.5 sources. However am not 100% sure and would appreciate
confirmation.
'quitter' will be running start_thread() in nptl/pthread_create.c
The last action of start_thread() is to exit via
__exit_thread_inline(0), which simply does sys_exit
(nptl/pthread_create.c:403)
'stayer' meanwhile is waiting for lll_wait_tid (pd->tid)
(call at nptl/pthread_join.c:89)
As per comment at nptl/sysdeps/unix/sysv/linux/i386/lowlevellock.h:536,
lll_wait_tid will not return until kernel notifies via futex
wakeup that 'quitter' has terminated.
Hence pthread_join cannot return until 'quitter' really has
completely disappeared.
Drepper:
> As per comment at nptl/sysdeps/unix/sysv/linux/i386/lowlevellock.h:536,
> lll_wait_tid will not return until kernel notifies via futex
> wakeup that 'quitter' has terminated.
That's the key. The kernel resets the TID field after the thread is
done. No way the joiner can return before the thread is gone.
*/
#if defined(VGO_solaris)
/* Solaris also provides thr_join() in addition to pthread_join().
* Both pthread_join(3C) and thr_join(3C) are based on private _thrp_join().
*
* :TODO: No functionality is currently provided for joinee == 0 and departed.
* This would require another client request, of course.
*/
__attribute__((noinline))
static int thr_join_WRK(thread_t joinee, thread_t *departed, void **thread_return)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< thr_join wrapper"); fflush(stderr);
}
CALL_FN_W_WWW(ret, fn, joinee, departed, thread_return);
if (ret == 0 /*success*/) {
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_JOIN_POST, CREQ_PTHREAD_T, joinee);
} else {
DO_PthAPIerror("thr_join", ret);
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: thr_join -> %d >>\n", ret);
}
return ret;
}
PTH_FUNC(int, thrZujoin, // thr_join
thread_t joinee, thread_t *departed, void **thread_return) {
return thr_join_WRK(joinee, departed, thread_return);
}
#endif /* VGO_solaris */
//-----------------------------------------------------------
// Ada gcc gnat runtime:
// The gnat gcc Ada runtime does not use pthread_join. Instead, it uses
// a combination of other pthread primitives to ensure a child thread
// is gone. This combination is somewhat functionally equivalent to a
// pthread_join.
// We wrap two hook procedures called by the gnat gcc Ada runtime
// that allows helgrind to understand the semantic of Ada task dependencies
// and termination.
// System.Tasking.Debug.Master_Hook is called by a task Dependent to
// indicate that its master is identified by master+master_level.
void I_WRAP_SONAME_FNNAME_ZU
(Za,
system__tasking__debug__master_hook)
(void *dependent, void *master, int master_level);
void I_WRAP_SONAME_FNNAME_ZU
(Za,
system__tasking__debug__master_hook)
(void *dependent, void *master, int master_level)
{
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_GNAT_FNS) {
fprintf(stderr, "<< GNAT master_hook wrapper "
"dependent %p master %p master_level %d\n",
dependent, master, master_level); fflush(stderr);
}
// We call the wrapped function, even if it is a null body.
CALL_FN_v_WWW(fn, dependent, master, master_level);
DO_CREQ_v_WWW(_VG_USERREQ__HG_GNAT_MASTER_HOOK,
void*,dependent, void*,master,
Word, (Word)master_level);
if (TRACE_GNAT_FNS) {
fprintf(stderr, " :: GNAT master_hook >>\n");
}
}
// System.Tasking.Debug.Master_Completed_Hook is called by a task to
// indicate that it has completed a master.
// This indicates that all its Dependent tasks (that identified themselves
// with the Master_Hook call) are terminated. Helgrind can consider
// at this point that the equivalent of a 'pthread_join' has been done
// between self_id and all dependent tasks at master_level.
void I_WRAP_SONAME_FNNAME_ZU
(Za,
system__tasking__debug__master_completed_hook)
(void *self_id, int master_level);
void I_WRAP_SONAME_FNNAME_ZU
(Za,
system__tasking__debug__master_completed_hook)
(void *self_id, int master_level)
{
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_GNAT_FNS) {
fprintf(stderr, "<< GNAT master_completed_hook wrapper "
"self_id %p master_level %d\n",
self_id, master_level); fflush(stderr);
}
// We call the wrapped function, even if it is a null body.
CALL_FN_v_WW(fn, self_id, master_level);
DO_CREQ_v_WW(_VG_USERREQ__HG_GNAT_MASTER_COMPLETED_HOOK,
void*,self_id, Word,(Word)master_level);
if (TRACE_GNAT_FNS) {
fprintf(stderr, " :: GNAT master_completed_hook >>\n");
}
}
/*----------------------------------------------------------------*/
/*--- pthread_mutex_t functions ---*/
/*----------------------------------------------------------------*/
/* Handled: pthread_mutex_init pthread_mutex_destroy
pthread_mutex_lock
pthread_mutex_trylock pthread_mutex_timedlock
pthread_mutex_unlock
*/
//-----------------------------------------------------------
#if !defined(VGO_solaris)
// glibc: pthread_mutex_init
// darwin: pthread_mutex_init
PTH_FUNC(int, pthreadZumutexZuinit, // pthread_mutex_init
pthread_mutex_t *mutex,
pthread_mutexattr_t* attr)
{
int ret;
long mbRec;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_mxinit %p", mutex); fflush(stderr);
}
mbRec = 0;
if (attr) {
int ty, zzz;
zzz = pthread_mutexattr_gettype(attr, &ty);
if (zzz == 0 && ty == PTHREAD_MUTEX_RECURSIVE)
mbRec = 1;
}
CALL_FN_W_WW(ret, fn, mutex,attr);
if (ret == 0 /*success*/) {
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_INIT_POST,
pthread_mutex_t*,mutex, long,mbRec);
} else {
DO_PthAPIerror( "pthread_mutex_init", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: mxinit -> %d >>\n", ret);
}
return ret;
}
#else /* VGO_solaris */
// Solaris: mutex_init (pthread_mutex_init calls here)
PTH_FUNC(int, mutexZuinit, // mutex_init
mutex_t *mutex, int type, void *arg)
{
int ret;
long mbRec;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< mxinit %p", mutex); fflush(stderr);
}
mbRec = ((type & LOCK_RECURSIVE) != 0) ? 1 : 0;
CALL_FN_W_WWW(ret, fn, mutex, type, arg);
if (ret == 0 /*success*/) {
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_INIT_POST,
mutex_t *, mutex, long, mbRec);
} else {
DO_PthAPIerror("mutex_init", ret);
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: mxinit -> %d >>\n", ret);
}
return ret;
}
#endif /* VGO_solaris */
//-----------------------------------------------------------
// glibc: pthread_mutex_destroy
// darwin: pthread_mutex_destroy
// Solaris: mutex_destroy (pthread_mutex_destroy is a weak alias)
__attribute__((noinline))
static int mutex_destroy_WRK(pthread_mutex_t *mutex)
{
int ret;
unsigned long mutex_is_init;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_mxdestroy %p", mutex); fflush(stderr);
}
if (mutex != NULL) {
static const pthread_mutex_t mutex_init = PTHREAD_MUTEX_INITIALIZER;
mutex_is_init = my_memcmp(mutex, &mutex_init, sizeof(*mutex)) == 0;
} else {
mutex_is_init = 0;
}
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_DESTROY_PRE,
pthread_mutex_t*, mutex, unsigned long, mutex_is_init);
CALL_FN_W_W(ret, fn, mutex);
if (ret != 0) {
DO_PthAPIerror( "pthread_mutex_destroy", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: mxdestroy -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux) || defined(VGO_darwin)
PTH_FUNC(int, pthreadZumutexZudestroy, // pthread_mutex_destroy
pthread_mutex_t *mutex) {
return mutex_destroy_WRK(mutex);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, mutexZudestroy, // mutex_destroy
pthread_mutex_t *mutex) {
return mutex_destroy_WRK(mutex);
}
#else
# error "Unsupported OS"
#endif
//-----------------------------------------------------------
// glibc: pthread_mutex_lock
// darwin: pthread_mutex_lock
// Solaris: mutex_lock (pthread_mutex_lock is a weak alias)
__attribute__((noinline))
static int mutex_lock_WRK(pthread_mutex_t *mutex)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_mxlock %p", mutex); fflush(stderr);
}
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_PRE,
pthread_mutex_t*,mutex, long,0/*!isTryLock*/);
CALL_FN_W_W(ret, fn, mutex);
/* There's a hole here: libpthread now knows the lock is locked,
but the tool doesn't, so some other thread could run and detect
that the lock has been acquired by someone (this thread). Does
this matter? Not sure, but I don't think so. */
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_POST,
pthread_mutex_t *, mutex, long, (ret == 0) ? True : False);
if (ret != 0) {
DO_PthAPIerror( "pthread_mutex_lock", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: mxlock -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux) || defined(VGO_darwin)
PTH_FUNC(int, pthreadZumutexZulock, // pthread_mutex_lock
pthread_mutex_t *mutex) {
return mutex_lock_WRK(mutex);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, mutexZulock, // mutex_lock
pthread_mutex_t *mutex) {
return mutex_lock_WRK(mutex);
}
#else
# error "Unsupported OS"
#endif
#if defined(VGO_solaris)
/* Internal to libc. Mutex is usually initialized only implicitly,
* by zeroing mutex_t structure.
*/
__attribute__((noinline))
PTH_FUNC(void, lmutexZulock, // lmutex_lock
mutex_t *mutex)
{
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< lmxlock %p", mutex); fflush(stderr);
}
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_PRE,
mutex_t *, mutex, long, 0 /*!isTryLock*/);
CALL_FN_v_W(fn, mutex);
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_POST,
mutex_t *, mutex, long, True);
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: lmxlock >>\n");
}
}
#endif /* VGO_solaris */
//-----------------------------------------------------------
// glibc: pthread_mutex_trylock
// darwin: pthread_mutex_trylock
// Solaris: mutex_trylock (pthread_mutex_trylock is a weak alias)
//
// pthread_mutex_trylock. The handling needed here is very similar
// to that for pthread_mutex_lock, except that we need to tell
// the pre-lock creq that this is a trylock-style operation, and
// therefore not to complain if the lock is nonrecursive and
// already locked by this thread -- because then it'll just fail
// immediately with EBUSY.
__attribute__((noinline))
static int mutex_trylock_WRK(pthread_mutex_t *mutex)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_mxtrylock %p", mutex); fflush(stderr);
}
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_PRE,
pthread_mutex_t*,mutex, long,1/*isTryLock*/);
CALL_FN_W_W(ret, fn, mutex);
/* There's a hole here: libpthread now knows the lock is locked,
but the tool doesn't, so some other thread could run and detect
that the lock has been acquired by someone (this thread). Does
this matter? Not sure, but I don't think so. */
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_POST,
pthread_mutex_t *, mutex, long, (ret == 0) ? True : False);
if (ret != 0) {
if (ret != EBUSY)
DO_PthAPIerror( "pthread_mutex_trylock", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: mxtrylock -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux) || defined(VGO_darwin)
PTH_FUNC(int, pthreadZumutexZutrylock, // pthread_mutex_trylock
pthread_mutex_t *mutex) {
return mutex_trylock_WRK(mutex);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, mutexZutrylock, // mutex_trylock
pthread_mutex_t *mutex) {
return mutex_trylock_WRK(mutex);
}
#else
# error "Unsupported OS"
#endif
//-----------------------------------------------------------
// glibc: pthread_mutex_timedlock
// darwin: (doesn't appear to exist)
// Solaris: pthread_mutex_timedlock
//
// pthread_mutex_timedlock. Identical logic to pthread_mutex_trylock.
__attribute__((noinline))
static int mutex_timedlock_WRK(pthread_mutex_t *mutex,
void *timeout)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_mxtimedlock %p %p", mutex, timeout);
fflush(stderr);
}
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_PRE,
pthread_mutex_t*,mutex, long,1/*isTryLock-ish*/);
CALL_FN_W_WW(ret, fn, mutex,timeout);
/* There's a hole here: libpthread now knows the lock is locked,
but the tool doesn't, so some other thread could run and detect
that the lock has been acquired by someone (this thread). Does
this matter? Not sure, but I don't think so. */
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_POST,
pthread_mutex_t *, mutex, long, (ret == 0) ? True : False);
if (ret != 0) {
if (ret != ETIMEDOUT)
DO_PthAPIerror( "pthread_mutex_timedlock", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: mxtimedlock -> %d >>\n", ret);
}
return ret;
}
PTH_FUNC(int, pthreadZumutexZutimedlock, // pthread_mutex_timedlock
pthread_mutex_t *mutex,
void *timeout) {
return mutex_timedlock_WRK(mutex, timeout);
}
#if defined(VGO_solaris)
PTH_FUNC(int, pthreadZumutexZureltimedlock, // pthread_mutex_reltimedlock
pthread_mutex_t *mutex,
void *timeout) {
return mutex_timedlock_WRK(mutex, timeout);
}
#endif
//-----------------------------------------------------------
// glibc: pthread_mutex_unlock
// darwin: pthread_mutex_unlock
// Solaris: mutex_unlock (pthread_mutex_unlock is a weak alias)
__attribute__((noinline))
static int mutex_unlock_WRK(pthread_mutex_t *mutex)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_mxunlk %p", mutex); fflush(stderr);
}
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_PRE,
pthread_mutex_t*,mutex);
CALL_FN_W_W(ret, fn, mutex);
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_POST,
pthread_mutex_t*,mutex);
if (ret != 0) {
DO_PthAPIerror( "pthread_mutex_unlock", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " mxunlk -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux) || defined(VGO_darwin)
PTH_FUNC(int, pthreadZumutexZuunlock, // pthread_mutex_unlock
pthread_mutex_t *mutex) {
return mutex_unlock_WRK(mutex);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, mutexZuunlock, // mutex_unlock
pthread_mutex_t *mutex) {
return mutex_unlock_WRK(mutex);
}
#else
# error "Unsupported OS"
#endif
#if defined(VGO_solaris)
/* Internal to libc. */
__attribute__((noinline))
PTH_FUNC(void, lmutexZuunlock, // lmutex_unlock
mutex_t *mutex)
{
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< lmxunlk %p", mutex); fflush(stderr);
}
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_PRE,
mutex_t *, mutex);
CALL_FN_v_W(fn, mutex);
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_POST,
mutex_t*, mutex);
if (TRACE_PTH_FNS) {
fprintf(stderr, " lmxunlk >>\n");
}
}
#endif /* VGO_solaris */
/*----------------------------------------------------------------*/
/*--- pthread_cond_t functions ---*/
/*----------------------------------------------------------------*/
/* Handled: pthread_cond_wait pthread_cond_timedwait
pthread_cond_signal pthread_cond_broadcast
pthread_cond_init
pthread_cond_destroy
*/
//-----------------------------------------------------------
// glibc: pthread_cond_wait@GLIBC_2.2.5
// glibc: pthread_cond_wait@@GLIBC_2.3.2
// darwin: pthread_cond_wait
// darwin: pthread_cond_wait$NOCANCEL$UNIX2003
// darwin: pthread_cond_wait$UNIX2003
// Solaris: cond_wait (pthread_cond_wait is built atop of cond_wait)
//
__attribute__((noinline))
static int pthread_cond_wait_WRK(pthread_cond_t* cond,
pthread_mutex_t* mutex)
{
int ret;
OrigFn fn;
unsigned long mutex_is_valid;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_cond_wait %p %p", cond, mutex);
fflush(stderr);
}
/* Tell the tool a cond-wait is about to happen, so it can check
for bogus argument values. In return it tells us whether it
thinks the mutex is valid or not. */
DO_CREQ_W_WW(mutex_is_valid,
_VG_USERREQ__HG_PTHREAD_COND_WAIT_PRE,
pthread_cond_t*,cond, pthread_mutex_t*,mutex);
assert(mutex_is_valid == 1 || mutex_is_valid == 0);
/* Tell the tool we're about to drop the mutex. This reflects the
fact that in a cond_wait, we show up holding the mutex, and the
call atomically drops the mutex and waits for the cv to be
signalled. */
if (mutex_is_valid) {
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_PRE,
pthread_mutex_t*,mutex);
}
CALL_FN_W_WW(ret, fn, cond,mutex);
/* this conditional look stupid, but compare w/ same logic for
pthread_cond_timedwait below */
if (mutex_is_valid) {
/* and now we have the mutex again if (ret == 0) */
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_POST,
pthread_mutex_t *, mutex, long, (ret == 0) ? True : False);
}
DO_CREQ_v_WWWW(_VG_USERREQ__HG_PTHREAD_COND_WAIT_POST,
pthread_cond_t*,cond, pthread_mutex_t*,mutex, long,0,
long, (ret == 0 && mutex_is_valid) ? True : False);
if (ret != 0) {
DO_PthAPIerror( "pthread_cond_wait", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " cowait -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, pthreadZucondZuwaitZAZa, // pthread_cond_wait@*
pthread_cond_t* cond, pthread_mutex_t* mutex) {
return pthread_cond_wait_WRK(cond, mutex);
}
#elif defined(VGO_darwin)
PTH_FUNC(int, pthreadZucondZuwaitZa, // pthread_cond_wait*
pthread_cond_t* cond, pthread_mutex_t* mutex) {
return pthread_cond_wait_WRK(cond, mutex);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, condZuwait, // cond_wait
pthread_cond_t *cond, pthread_mutex_t *mutex) {
return pthread_cond_wait_WRK(cond, mutex);
}
#else
# error "Unsupported OS"
#endif
//-----------------------------------------------------------
// glibc: pthread_cond_timedwait@@GLIBC_2.3.2
// glibc: pthread_cond_timedwait@GLIBC_2.2.5
// glibc: pthread_cond_timedwait@GLIBC_2.0
// darwin: pthread_cond_timedwait
// darwin: pthread_cond_timedwait$NOCANCEL$UNIX2003
// darwin: pthread_cond_timedwait$UNIX2003
// darwin: pthread_cond_timedwait_relative_np (trapped)
// Solaris: cond_timedwait (pthread_cond_timedwait is built on cond_timedwait)
// Solaris: cond_reltimedwait (pthread_cond_reltimedwait_np is built on this)
//
__attribute__((noinline))
static int pthread_cond_timedwait_WRK(pthread_cond_t* cond,
pthread_mutex_t* mutex,
struct timespec* abstime,
int timeout_error)
{
int ret;
OrigFn fn;
unsigned long mutex_is_valid;
Bool abstime_is_valid;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_cond_timedwait %p %p %p",
cond, mutex, abstime);
fflush(stderr);
}
/* Tell the tool a cond-wait is about to happen, so it can check
for bogus argument values. In return it tells us whether it
thinks the mutex is valid or not. */
DO_CREQ_W_WW(mutex_is_valid,
_VG_USERREQ__HG_PTHREAD_COND_WAIT_PRE,
pthread_cond_t*,cond, pthread_mutex_t*,mutex);
assert(mutex_is_valid == 1 || mutex_is_valid == 0);
abstime_is_valid = abstime->tv_nsec >= 0 && abstime->tv_nsec < 1000000000;
/* Tell the tool we're about to drop the mutex. This reflects the
fact that in a cond_wait, we show up holding the mutex, and the
call atomically drops the mutex and waits for the cv to be
signalled. */
if (mutex_is_valid && abstime_is_valid) {
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_PRE,
pthread_mutex_t*,mutex);
}
CALL_FN_W_WWW(ret, fn, cond,mutex,abstime);
if (mutex_is_valid && !abstime_is_valid && ret != EINVAL) {
DO_PthAPIerror("Bug in libpthread: pthread_cond_timedwait "
"invalid abstime did not cause"
" EINVAL", ret);
}
if (mutex_is_valid && abstime_is_valid) {
/* and now we have the mutex again if (ret == 0 || ret == timeout) */
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_POST,
pthread_mutex_t *, mutex,
long, (ret == 0 || ret == timeout_error) ? True : False);
}
DO_CREQ_v_WWWW(_VG_USERREQ__HG_PTHREAD_COND_WAIT_POST,
pthread_cond_t*,cond, pthread_mutex_t*,mutex,
long,ret == timeout_error,
long, (ret == 0 || ret == timeout_error) && mutex_is_valid
? True : False);
if (ret != 0 && ret != timeout_error) {
DO_PthAPIerror( "pthread_cond_timedwait", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " cotimedwait -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, pthreadZucondZutimedwaitZAZa, // pthread_cond_timedwait@*
pthread_cond_t* cond, pthread_mutex_t* mutex,
struct timespec* abstime) {
return pthread_cond_timedwait_WRK(cond, mutex, abstime, ETIMEDOUT);
}
#elif defined(VGO_darwin)
PTH_FUNC(int, pthreadZucondZutimedwait, // pthread_cond_timedwait
pthread_cond_t* cond, pthread_mutex_t* mutex,
struct timespec* abstime) {
return pthread_cond_timedwait_WRK(cond, mutex, abstime, ETIMEDOUT);
}
PTH_FUNC(int, pthreadZucondZutimedwaitZDZa, // pthread_cond_timedwait$*
pthread_cond_t* cond, pthread_mutex_t* mutex,
struct timespec* abstime) {
return pthread_cond_timedwait_WRK(cond, mutex, abstime, ETIMEDOUT);
}
PTH_FUNC(int, pthreadZucondZutimedwaitZuZa, // pthread_cond_timedwait_*
pthread_cond_t* cond, pthread_mutex_t* mutex,
struct timespec* abstime) {
assert(0);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, condZutimedwait, // cond_timedwait
pthread_cond_t *cond, pthread_mutex_t *mutex,
struct timespec *abstime) {
return pthread_cond_timedwait_WRK(cond, mutex, abstime, ETIME);
}
PTH_FUNC(int, condZureltimedwait, // cond_reltimedwait
pthread_cond_t *cond, pthread_mutex_t *mutex,
struct timespec *reltime) {
return pthread_cond_timedwait_WRK(cond, mutex, reltime, ETIME);
}
#else
# error "Unsupported OS"
#endif
//-----------------------------------------------------------
// glibc: pthread_cond_signal@GLIBC_2.0
// glibc: pthread_cond_signal@GLIBC_2.2.5
// glibc: pthread_cond_signal@@GLIBC_2.3.2
// darwin: pthread_cond_signal
// darwin: pthread_cond_signal_thread_np (don't intercept this)
// Solaris: cond_signal (pthread_cond_signal is a weak alias)
//
__attribute__((noinline))
static int pthread_cond_signal_WRK(pthread_cond_t* cond)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_cond_signal %p", cond);
fflush(stderr);
}
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_COND_SIGNAL_PRE,
pthread_cond_t*,cond);
CALL_FN_W_W(ret, fn, cond);
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_COND_SIGNAL_POST,
pthread_cond_t*,cond);
if (ret != 0) {
DO_PthAPIerror( "pthread_cond_signal", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " cosig -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, pthreadZucondZusignalZAZa, // pthread_cond_signal@*
pthread_cond_t* cond) {
return pthread_cond_signal_WRK(cond);
}
#elif defined(VGO_darwin)
PTH_FUNC(int, pthreadZucondZusignal, // pthread_cond_signal
pthread_cond_t* cond) {
return pthread_cond_signal_WRK(cond);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, condZusignal, // cond_signal
pthread_cond_t *cond) {
return pthread_cond_signal_WRK(cond);
}
#else
# error "Unsupported OS"
#endif
//-----------------------------------------------------------
// glibc: pthread_cond_broadcast@GLIBC_2.0
// glibc: pthread_cond_broadcast@GLIBC_2.2.5
// glibc: pthread_cond_broadcast@@GLIBC_2.3.2
// darwin: pthread_cond_broadcast
// Solaris: cond_broadcast (pthread_cond_broadcast is a weak alias)
//
// Note, this is pretty much identical, from a dependency-graph
// point of view, with cond_signal, so the code is duplicated.
// Maybe it should be commoned up.
//
__attribute__((noinline))
static int pthread_cond_broadcast_WRK(pthread_cond_t* cond)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_cond_broadcast %p", cond);
fflush(stderr);
}
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_COND_BROADCAST_PRE,
pthread_cond_t*,cond);
CALL_FN_W_W(ret, fn, cond);
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_COND_BROADCAST_POST,
pthread_cond_t*,cond);
if (ret != 0) {
DO_PthAPIerror( "pthread_cond_broadcast", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " cobro -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, pthreadZucondZubroadcastZAZa, // pthread_cond_broadcast@*
pthread_cond_t* cond) {
return pthread_cond_broadcast_WRK(cond);
}
#elif defined(VGO_darwin)
PTH_FUNC(int, pthreadZucondZubroadcast, // pthread_cond_broadcast
pthread_cond_t* cond) {
return pthread_cond_broadcast_WRK(cond);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, condZubroadcast, // cond_broadcast
pthread_cond_t *cond) {
return pthread_cond_broadcast_WRK(cond);
}
#else
# error "Unsupported OS"
#endif
// glibc: pthread_cond_init@GLIBC_2.0
// glibc: pthread_cond_init@GLIBC_2.2.5
// glibc: pthread_cond_init@@GLIBC_2.3.2
// darwin: pthread_cond_init
// Solaris: cond_init (pthread_cond_init is built atop on this function)
// Easy way out: Handling of attr could have been messier.
// It turns out that pthread_cond_init under linux ignores
// all information in cond_attr, so do we.
// FIXME: MacOS X?
#if !defined(VGO_solaris)
__attribute__((noinline))
static int pthread_cond_init_WRK(pthread_cond_t* cond, pthread_condattr_t *cond_attr)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_cond_init %p", cond);
fflush(stderr);
}
CALL_FN_W_WW(ret, fn, cond, cond_attr);
if (ret == 0) {
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_COND_INIT_POST,
pthread_cond_t*,cond, pthread_condattr_t*, cond_attr);
} else {
DO_PthAPIerror( "pthread_cond_init", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " coinit -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, pthreadZucondZuinitZAZa, // pthread_cond_init@*
pthread_cond_t* cond, pthread_condattr_t* cond_attr) {
return pthread_cond_init_WRK(cond, cond_attr);
}
#elif defined(VGO_darwin)
PTH_FUNC(int, pthreadZucondZuinit, // pthread_cond_init
pthread_cond_t* cond, pthread_condattr_t * cond_attr) {
return pthread_cond_init_WRK(cond, cond_attr);
}
#else
# error "Unsupported OS"
#endif
#else /* VGO_solaris */
__attribute__((noinline))
PTH_FUNC(int, condZuinit, // cond_init
cond_t *cond, int type, void *arg)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< cond_init %p", cond); fflush(stderr);
}
CALL_FN_W_WWW(ret, fn, cond, type, arg);
if (ret == 0) {
/* Luckily evh__HG_PTHREAD_COND_INIT_POST() ignores cond_attr.
See also comment for pthread_cond_init_WRK(). */
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_COND_INIT_POST,
cond_t *, cond, void *, NULL);
} else {
DO_PthAPIerror("cond_init", ret);
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " cond_init -> %d >>\n", ret);
}
return ret;
}
#endif /* VGO_solaris */
//-----------------------------------------------------------
// glibc: pthread_cond_destroy@@GLIBC_2.3.2
// glibc: pthread_cond_destroy@GLIBC_2.2.5
// glibc: pthread_cond_destroy@GLIBC_2.0
// darwin: pthread_cond_destroy
// Solaris: cond_destroy (pthread_cond_destroy is a weak alias)
//
__attribute__((noinline))
static int pthread_cond_destroy_WRK(pthread_cond_t* cond)
{
int ret;
unsigned long cond_is_init;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_cond_destroy %p", cond);
fflush(stderr);
}
if (cond != NULL) {
const pthread_cond_t cond_init = PTHREAD_COND_INITIALIZER;
cond_is_init = my_memcmp(cond, &cond_init, sizeof(*cond)) == 0;
} else {
cond_is_init = 0;
}
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_COND_DESTROY_PRE,
pthread_cond_t*, cond, unsigned long, cond_is_init);
CALL_FN_W_W(ret, fn, cond);
if (ret != 0) {
DO_PthAPIerror( "pthread_cond_destroy", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " codestr -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, pthreadZucondZudestroyZAZa, // pthread_cond_destroy@*
pthread_cond_t* cond) {
return pthread_cond_destroy_WRK(cond);
}
#elif defined(VGO_darwin)
PTH_FUNC(int, pthreadZucondZudestroy, // pthread_cond_destroy
pthread_cond_t* cond) {
return pthread_cond_destroy_WRK(cond);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, condZudestroy, // cond_destroy
pthread_cond_t *cond) {
return pthread_cond_destroy_WRK(cond);
}
#else
# error "Unsupported OS"
#endif
/*----------------------------------------------------------------*/
/*--- pthread_barrier_t functions ---*/
/*----------------------------------------------------------------*/
#if defined(HAVE_PTHREAD_BARRIER_INIT)
/* Handled: pthread_barrier_init
pthread_barrier_wait
pthread_barrier_destroy
Unhandled: pthread_barrierattr_destroy
pthread_barrierattr_getpshared
pthread_barrierattr_init
pthread_barrierattr_setpshared
-- are these important?
*/
//-----------------------------------------------------------
// glibc: pthread_barrier_init
// darwin: (doesn't appear to exist)
// Solaris: pthread_barrier_init
PTH_FUNC(int, pthreadZubarrierZuinit, // pthread_barrier_init
pthread_barrier_t* bar,
pthread_barrierattr_t* attr, unsigned long count)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_barrier_init %p %p %lu",
bar, attr, count);
fflush(stderr);
}
DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_BARRIER_INIT_PRE,
pthread_barrier_t*, bar,
unsigned long, count,
unsigned long, 0/*!resizable*/);
CALL_FN_W_WWW(ret, fn, bar,attr,count);
if (ret != 0) {
DO_PthAPIerror( "pthread_barrier_init", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " pthread_barrier_init -> %d >>\n", ret);
}
return ret;
}
//-----------------------------------------------------------
// glibc: pthread_barrier_wait
// darwin: (doesn't appear to exist)
// Solaris: pthread_barrier_wait
PTH_FUNC(int, pthreadZubarrierZuwait, // pthread_barrier_wait
pthread_barrier_t* bar)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_barrier_wait %p", bar);
fflush(stderr);
}
/* That this works correctly, and doesn't screw up when a thread
leaving the barrier races round to the front and re-enters while
other threads are still leaving it, is quite subtle. See
comments in the handler for PTHREAD_BARRIER_WAIT_PRE in
hg_main.c. */
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_BARRIER_WAIT_PRE,
pthread_barrier_t*,bar);
CALL_FN_W_W(ret, fn, bar);
if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) {
DO_PthAPIerror( "pthread_barrier_wait", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " pthread_barrier_wait -> %d >>\n", ret);
}
return ret;
}
//-----------------------------------------------------------
// glibc: pthread_barrier_destroy
// darwin: (doesn't appear to exist)
// Solaris: pthread_barrier_destroy
PTH_FUNC(int, pthreadZubarrierZudestroy, // pthread_barrier_destroy
pthread_barrier_t* bar)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_barrier_destroy %p", bar);
fflush(stderr);
}
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_BARRIER_DESTROY_PRE,
pthread_barrier_t*,bar);
CALL_FN_W_W(ret, fn, bar);
if (ret != 0) {
DO_PthAPIerror( "pthread_barrier_destroy", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " pthread_barrier_destroy -> %d >>\n", ret);
}
return ret;
}
#endif // defined(HAVE_PTHREAD_BARRIER_INIT)
/*----------------------------------------------------------------*/
/*--- pthread_spinlock_t functions ---*/
/*----------------------------------------------------------------*/
#if defined(HAVE_PTHREAD_SPIN_LOCK) \
&& !defined(DISABLE_PTHREAD_SPINLOCK_INTERCEPT)
/* Handled: pthread_spin_init pthread_spin_destroy
pthread_spin_lock pthread_spin_trylock
pthread_spin_unlock
Unhandled:
*/
/* This is a nasty kludge, in that glibc "knows" that initialising a
spin lock unlocks it, and pthread_spin_{init,unlock} are names for
the same function. Hence we have to have a wrapper which does both
things, without knowing which the user intended to happen.
Solaris has distinct functions for init/unlock but client requests
are immutable in helgrind.h so follow the glibc lead. */
//-----------------------------------------------------------
// glibc: pthread_spin_init
// glibc: pthread_spin_unlock
// darwin: (doesn't appear to exist)
// Solaris: pthread_spin_init
// Solaris: pthread_spin_unlock
__attribute__((noinline))
static int pthread_spin_init_or_unlock_WRK(pthread_spinlock_t* lock,
int pshared) {
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_spin_iORu %p", lock); fflush(stderr);
}
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_SPIN_INIT_OR_UNLOCK_PRE,
pthread_spinlock_t*, lock);
CALL_FN_W_WW(ret, fn, lock,pshared);
if (ret == 0 /*success*/) {
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_SPIN_INIT_OR_UNLOCK_POST,
pthread_spinlock_t*,lock);
} else {
DO_PthAPIerror( "pthread_spinlock_{init,unlock}", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: spiniORu -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, pthreadZuspinZuinit, // pthread_spin_init
pthread_spinlock_t* lock, int pshared) {
return pthread_spin_init_or_unlock_WRK(lock, pshared);
}
PTH_FUNC(int, pthreadZuspinZuunlock, // pthread_spin_unlock
pthread_spinlock_t* lock) {
/* this is never actually called */
return pthread_spin_init_or_unlock_WRK(lock, 0/*pshared*/);
}
#elif defined(VGO_darwin)
#elif defined(VGO_solaris)
PTH_FUNC(int, pthreadZuspinZuinit, // pthread_spin_init
pthread_spinlock_t *lock, int pshared) {
return pthread_spin_init_or_unlock_WRK(lock, pshared);
}
PTH_FUNC(int, pthreadZuspinZuunlock, // pthread_spin_unlock
pthread_spinlock_t *lock) {
return pthread_spin_init_or_unlock_WRK(lock, 0/*pshared*/);
}
#else
# error "Unsupported OS"
#endif
//-----------------------------------------------------------
// glibc: pthread_spin_destroy
// darwin: (doesn't appear to exist)
// Solaris: pthread_spin_destroy
__attribute__((noinline))
static int pthread_spin_destroy_WRK(pthread_spinlock_t *lock)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_spin_destroy %p", lock);
fflush(stderr);
}
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_SPIN_DESTROY_PRE,
pthread_spinlock_t*,lock);
CALL_FN_W_W(ret, fn, lock);
if (ret != 0) {
DO_PthAPIerror( "pthread_spin_destroy", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: spindestroy -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, pthreadZuspinZudestroy, // pthread_spin_destroy
pthread_spinlock_t *lock) {
return pthread_spin_destroy_WRK(lock);
}
#elif defined(VGO_darwin)
#elif defined(VGO_solaris)
PTH_FUNC(int, pthreadZuspinZudestroy, // pthread_spin_destroy
pthread_spinlock_t *lock) {
return pthread_spin_destroy_WRK(lock);
}
#else
# error "Unsupported OS"
#endif
//-----------------------------------------------------------
// glibc: pthread_spin_lock
// darwin: (doesn't appear to exist)
// Solaris: pthread_spin_lock
__attribute__((noinline))
static int pthread_spin_lock_WRK(pthread_spinlock_t *lock)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_spinlock %p", lock);
fflush(stderr);
}
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_SPIN_LOCK_PRE,
pthread_spinlock_t*,lock, long,0/*!isTryLock*/);
CALL_FN_W_W(ret, fn, lock);
/* There's a hole here: libpthread now knows the lock is locked,
but the tool doesn't, so some other thread could run and detect
that the lock has been acquired by someone (this thread). Does
this matter? Not sure, but I don't think so. */
if (ret == 0 /*success*/) {
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_SPIN_LOCK_POST,
pthread_spinlock_t*,lock);
} else {
DO_PthAPIerror( "pthread_spin_lock", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: spinlock -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, pthreadZuspinZulock, // pthread_spin_lock
pthread_spinlock_t *lock) {
return pthread_spin_lock_WRK(lock);
}
#elif defined(VGO_darwin)
#elif defined(VGO_solaris)
PTH_FUNC(int, pthreadZuspinZulock, // pthread_spin_lock
pthread_spinlock_t *lock) {
return pthread_spin_lock_WRK(lock);
}
#else
# error "Unsupported OS"
#endif
//-----------------------------------------------------------
// glibc: pthread_spin_trylock
// darwin: (doesn't appear to exist)
// Solaris: pthread_spin_trylock
__attribute__((noinline))
static int pthread_spin_trylock_WRK(pthread_spinlock_t *lock)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_spin_trylock %p", lock);
fflush(stderr);
}
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_SPIN_LOCK_PRE,
pthread_spinlock_t*,lock, long,1/*isTryLock*/);
CALL_FN_W_W(ret, fn, lock);
/* There's a hole here: libpthread now knows the lock is locked,
but the tool doesn't, so some other thread could run and detect
that the lock has been acquired by someone (this thread). Does
this matter? Not sure, but I don't think so. */
if (ret == 0 /*success*/) {
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_SPIN_LOCK_POST,
pthread_spinlock_t*,lock);
} else {
if (ret != EBUSY)
DO_PthAPIerror( "pthread_spin_trylock", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: spin_trylock -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, pthreadZuspinZutrylock, // pthread_spin_trylock
pthread_spinlock_t *lock) {
return pthread_spin_trylock_WRK(lock);
}
#elif defined(VGO_darwin)
#elif defined(VGO_solaris)
PTH_FUNC(int, pthreadZuspinZutrylock, // pthread_spin_trylock
pthread_spinlock_t *lock) {
return pthread_spin_trylock_WRK(lock);
}
#else
# error "Unsupported OS"
#endif
#endif // defined(HAVE_PTHREAD_SPIN_LOCK)
/*----------------------------------------------------------------*/
/*--- pthread_rwlock_t functions ---*/
/*----------------------------------------------------------------*/
/* Android's pthread.h doesn't say anything about rwlocks, hence these
functions have to be conditionally compiled. */
#if defined(HAVE_PTHREAD_RWLOCK_T)
/* Handled: pthread_rwlock_init pthread_rwlock_destroy
pthread_rwlock_rdlock
pthread_rwlock_wrlock
pthread_rwlock_unlock
pthread_rwlock_tryrdlock
pthread_rwlock_trywrlock
Unhandled: pthread_rwlock_timedrdlock
pthread_rwlock_timedwrlock
*/
//-----------------------------------------------------------
// glibc: pthread_rwlock_init
// darwin: pthread_rwlock_init
// darwin: pthread_rwlock_init$UNIX2003
// Solaris: rwlock_init (pthread_rwlock_init is built atop of rwlock_init)
__attribute__((noinline))
static int pthread_rwlock_init_WRK(pthread_rwlock_t *rwl,
pthread_rwlockattr_t* attr)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_rwl_init %p", rwl); fflush(stderr);
}
CALL_FN_W_WW(ret, fn, rwl,attr);
if (ret == 0 /*success*/) {
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_RWLOCK_INIT_POST,
pthread_rwlock_t*,rwl);
} else {
DO_PthAPIerror( "pthread_rwlock_init", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: rwl_init -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, pthreadZurwlockZuinit, // pthread_rwlock_init
pthread_rwlock_t *rwl,
pthread_rwlockattr_t* attr) {
return pthread_rwlock_init_WRK(rwl, attr);
}
#elif defined(VGO_darwin)
PTH_FUNC(int, pthreadZurwlockZuinitZa, // pthread_rwlock_init*
pthread_rwlock_t *rwl,
pthread_rwlockattr_t* attr) {
return pthread_rwlock_init_WRK(rwl, attr);
}
#elif defined(VGO_solaris)
static int pthread_rwlock_init_WRK(pthread_rwlock_t *rwl,
pthread_rwlockattr_t* attr)
__attribute__((unused));
#else
# error "Unsupported OS"
#endif
#if defined(VGO_solaris)
PTH_FUNC(int, rwlockZuinit, // rwlock_init
rwlock_t *rwlock,
int type,
void *arg)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< rwl_init %p", rwlock); fflush(stderr);
}
CALL_FN_W_WWW(ret, fn, rwlock, type, arg);
if (ret == 0 /*success*/) {
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_RWLOCK_INIT_POST,
rwlock_t *, rwlock);
} else {
DO_PthAPIerror("rwlock_init", ret);
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: rwl_init -> %d >>\n", ret);
}
return ret;
}
#endif /* VGO_solaris */
//-----------------------------------------------------------
// glibc: pthread_rwlock_destroy
// darwin: pthread_rwlock_destroy
// darwin: pthread_rwlock_destroy$UNIX2003
// Solaris: rwlock_destroy (pthread_rwlock_destroy is a weak alias)
//
__attribute__((noinline))
static int pthread_rwlock_destroy_WRK(pthread_rwlock_t* rwl)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_rwl_destroy %p", rwl); fflush(stderr);
}
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_RWLOCK_DESTROY_PRE,
pthread_rwlock_t*,rwl);
CALL_FN_W_W(ret, fn, rwl);
if (ret != 0) {
DO_PthAPIerror( "pthread_rwlock_destroy", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: rwl_destroy -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, pthreadZurwlockZudestroy, // pthread_rwlock_destroy
pthread_rwlock_t *rwl) {
return pthread_rwlock_destroy_WRK(rwl);
}
#elif defined(VGO_darwin)
PTH_FUNC(int, pthreadZurwlockZudestroyZa, // pthread_rwlock_destroy*
pthread_rwlock_t *rwl) {
return pthread_rwlock_destroy_WRK(rwl);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, rwlockZudestroy, // rwlock_destroy
pthread_rwlock_t *rwl) {
return pthread_rwlock_destroy_WRK(rwl);
}
#else
# error "Unsupported OS"
#endif
//-----------------------------------------------------------
// glibc: pthread_rwlock_wrlock
// darwin: pthread_rwlock_wrlock
// darwin: pthread_rwlock_wrlock$UNIX2003
// Solaris: rw_wrlock (pthread_rwlock_wrlock is a weak alias)
//
__attribute__((noinline))
static int pthread_rwlock_wrlock_WRK(pthread_rwlock_t* rwlock)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_rwl_wlk %p", rwlock); fflush(stderr);
}
DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE,
pthread_rwlock_t*,rwlock,
long,1/*isW*/, long,0/*!isTryLock*/);
CALL_FN_W_W(ret, fn, rwlock);
DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_POST,
pthread_rwlock_t*,rwlock, long,1/*isW*/,
long, (ret == 0) ? True : False);
if (ret != 0) {
DO_PthAPIerror( "pthread_rwlock_wrlock", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: rwl_wlk -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, pthreadZurwlockZuwrlock, // pthread_rwlock_wrlock
pthread_rwlock_t* rwlock) {
return pthread_rwlock_wrlock_WRK(rwlock);
}
#elif defined(VGO_darwin)
PTH_FUNC(int, pthreadZurwlockZuwrlockZa, // pthread_rwlock_wrlock*
pthread_rwlock_t* rwlock) {
return pthread_rwlock_wrlock_WRK(rwlock);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, rwZuwrlock, // rw_wrlock
pthread_rwlock_t *rwlock) {
return pthread_rwlock_wrlock_WRK(rwlock);
}
#else
# error "Unsupported OS"
#endif
#if defined(VGO_solaris)
/* Internal to libc. */
PTH_FUNC(void, lrwZuwrlock, // lrw_wrlock
rwlock_t *rwlock)
{
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< lrw_wlk %p", rwlock); fflush(stderr);
}
DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE,
pthread_rwlock_t *, rwlock,
long, 1/*isW*/, long, 0/*!isTryLock*/);
CALL_FN_v_W(fn, rwlock);
DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_POST,
pthread_rwlock_t *, rwlock, long, 1/*isW*/, long, True);
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: lrw_wlk >>\n");
}
}
#endif /* VGO_solaris */
//-----------------------------------------------------------
// glibc: pthread_rwlock_rdlock
// darwin: pthread_rwlock_rdlock
// darwin: pthread_rwlock_rdlock$UNIX2003
// Solaris: rw_rdlock (pthread_rwlock_rdlock is a weak alias)
//
__attribute__((noinline))
static int pthread_rwlock_rdlock_WRK(pthread_rwlock_t* rwlock)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_rwl_rlk %p", rwlock); fflush(stderr);
}
DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE,
pthread_rwlock_t*,rwlock,
long,0/*!isW*/, long,0/*!isTryLock*/);
CALL_FN_W_W(ret, fn, rwlock);
DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_POST,
pthread_rwlock_t*,rwlock, long,0/*!isW*/,
long, (ret == 0) ? True : False);
if (ret != 0) {
DO_PthAPIerror( "pthread_rwlock_rdlock", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: rwl_rlk -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, pthreadZurwlockZurdlock, // pthread_rwlock_rdlock
pthread_rwlock_t* rwlock) {
return pthread_rwlock_rdlock_WRK(rwlock);
}
#elif defined(VGO_darwin)
PTH_FUNC(int, pthreadZurwlockZurdlockZa, // pthread_rwlock_rdlock*
pthread_rwlock_t* rwlock) {
return pthread_rwlock_rdlock_WRK(rwlock);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, rwZurdlock, // rw_rdlock
pthread_rwlock_t *rwlock) {
return pthread_rwlock_rdlock_WRK(rwlock);
}
#else
# error "Unsupported OS"
#endif
#if defined(VGO_solaris)
/* Internal to libc. */
PTH_FUNC(void, lrwZurdlock, // lrw_rdlock
rwlock_t *rwlock)
{
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< lrw_rlk %p", rwlock); fflush(stderr);
}
DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE,
pthread_rwlock_t *, rwlock,
long, 0/*!isW*/, long, 0/*!isTryLock*/);
CALL_FN_v_W(fn, rwlock);
DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_POST,
pthread_rwlock_t *, rwlock, long, 0/*!isW*/, long, True);
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: lrw_rlk ->>\n");
}
}
#endif /* VGO_solaris */
//-----------------------------------------------------------
// glibc: pthread_rwlock_trywrlock
// darwin: pthread_rwlock_trywrlock
// darwin: pthread_rwlock_trywrlock$UNIX2003
// Solaris: rw_trywrlock (pthread_rwlock_trywrlock is a weak alias)
//
__attribute__((noinline))
static int pthread_rwlock_trywrlock_WRK(pthread_rwlock_t* rwlock)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_rwl_trywlk %p", rwlock); fflush(stderr);
}
DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE,
pthread_rwlock_t*,rwlock,
long,1/*isW*/, long,1/*isTryLock*/);
CALL_FN_W_W(ret, fn, rwlock);
/* There's a hole here: libpthread now knows the lock is locked,
but the tool doesn't, so some other thread could run and detect
that the lock has been acquired by someone (this thread). Does
this matter? Not sure, but I don't think so. */
DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_POST,
pthread_rwlock_t*,rwlock, long,1/*isW*/,
long, (ret == 0) ? True : False);
if (ret != 0) {
if (ret != EBUSY)
DO_PthAPIerror( "pthread_rwlock_trywrlock", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: rwl_trywlk -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, pthreadZurwlockZutrywrlock, // pthread_rwlock_trywrlock
pthread_rwlock_t* rwlock) {
return pthread_rwlock_trywrlock_WRK(rwlock);
}
#elif defined(VGO_darwin)
PTH_FUNC(int, pthreadZurwlockZutrywrlockZa, // pthread_rwlock_trywrlock*
pthread_rwlock_t* rwlock) {
return pthread_rwlock_trywrlock_WRK(rwlock);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, rwZutrywrlock, // rw_trywrlock
pthread_rwlock_t *rwlock) {
return pthread_rwlock_trywrlock_WRK(rwlock);
}
#else
# error "Unsupported OS"
#endif
//-----------------------------------------------------------
// glibc: pthread_rwlock_tryrdlock
// darwin: pthread_rwlock_tryrdlock
// darwin: pthread_rwlock_tryrdlock$UNIX2003
// Solaris: rw_tryrdlock (pthread_rwlock_tryrdlock is a weak alias)
//
__attribute__((noinline))
static int pthread_rwlock_tryrdlock_WRK(pthread_rwlock_t* rwlock)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_rwl_tryrlk %p", rwlock); fflush(stderr);
}
DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE,
pthread_rwlock_t*,rwlock,
long,0/*!isW*/, long,1/*isTryLock*/);
CALL_FN_W_W(ret, fn, rwlock);
/* There's a hole here: libpthread now knows the lock is locked,
but the tool doesn't, so some other thread could run and detect
that the lock has been acquired by someone (this thread). Does
this matter? Not sure, but I don't think so. */
DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_POST,
pthread_rwlock_t*,rwlock, long,0/*!isW*/,
long, (ret == 0) ? True : False);
if (ret != 0) {
if (ret != EBUSY)
DO_PthAPIerror( "pthread_rwlock_tryrdlock", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: rwl_tryrlk -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, pthreadZurwlockZutryrdlock, // pthread_rwlock_tryrdlock
pthread_rwlock_t* rwlock) {
return pthread_rwlock_tryrdlock_WRK(rwlock);
}
#elif defined(VGO_darwin)
PTH_FUNC(int, pthreadZurwlockZutryrdlockZa, // pthread_rwlock_tryrdlock*
pthread_rwlock_t* rwlock) {
return pthread_rwlock_tryrdlock_WRK(rwlock);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, rwZutryrdlock, // rw_tryrdlock
pthread_rwlock_t *rwlock) {
return pthread_rwlock_tryrdlock_WRK(rwlock);
}
#else
# error "Unsupported OS"
#endif
//-----------------------------------------------------------
// glibc: Unhandled
// darwin: Unhandled
// Solaris: pthread_rwlock_timedrdlock
// Solaris: pthread_rwlock_reltimedrdlock_np
//
__attribute__((noinline)) __attribute__((unused))
static int pthread_rwlock_timedrdlock_WRK(pthread_rwlock_t *rwlock,
const struct timespec *timeout)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_rwl_timedrdl %p", rwlock); fflush(stderr);
}
DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE,
pthread_rwlock_t *, rwlock,
long, 0/*isW*/, long, 0/*isTryLock*/);
CALL_FN_W_WW(ret, fn, rwlock, timeout);
DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_POST,
pthread_rwlock_t *, rwlock, long, 0/*isW*/,
long, (ret == 0) ? True : False);
if (ret != 0) {
DO_PthAPIerror("pthread_rwlock_timedrdlock", ret);
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: rwl_timedrdl -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
#elif defined(VGO_darwin)
#elif defined(VGO_solaris)
PTH_FUNC(int, pthreadZurwlockZutimedrdlock, // pthread_rwlock_timedrdlock
pthread_rwlock_t *rwlock,
const struct timespec *timeout) {
return pthread_rwlock_timedrdlock_WRK(rwlock, timeout);
}
PTH_FUNC(int, pthreadZurwlockZureltimedrdlockZunp, // pthread_rwlock_timedrdlock_np
pthread_rwlock_t *rwlock,
const struct timespec *timeout) {
return pthread_rwlock_timedrdlock_WRK(rwlock, timeout);
}
#else
# error "Unsupported OS"
#endif
//-----------------------------------------------------------
// glibc: Unhandled
// darwin: Unhandled
// Solaris: pthread_rwlock_timedwrlock
// Solaris: pthread_rwlock_reltimedwrlock_np
//
__attribute__((noinline)) __attribute__((unused))
static int pthread_rwlock_timedwrlock_WRK(pthread_rwlock_t *rwlock,
const struct timespec *timeout)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_rwl_timedwrl %p", rwlock); fflush(stderr);
}
DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE,
pthread_rwlock_t *, rwlock,
long, 1/*isW*/, long, 0/*isTryLock*/);
CALL_FN_W_WW(ret, fn, rwlock, timeout);
DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_POST,
pthread_rwlock_t *, rwlock, long, 1/*isW*/,
long, (ret == 0) ? True : False);
if (ret != 0) {
DO_PthAPIerror("pthread_rwlock_timedwrlock", ret);
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: rwl_timedwrl -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
#elif defined(VGO_darwin)
#elif defined(VGO_solaris)
PTH_FUNC(int, pthreadZurwlockZutimedwrlock, // pthread_rwlock_timedwrlock
pthread_rwlock_t *rwlock,
const struct timespec *timeout) {
return pthread_rwlock_timedwrlock_WRK(rwlock, timeout);
}
PTH_FUNC(int, pthreadZurwlockZureltimedwrlockZunp, // pthread_rwlock_timedwrlock_np
pthread_rwlock_t *rwlock,
const struct timespec *timeout) {
return pthread_rwlock_timedwrlock_WRK(rwlock, timeout);
}
#else
# error "Unsupported OS"
#endif
//-----------------------------------------------------------
// glibc: pthread_rwlock_unlock
// darwin: pthread_rwlock_unlock
// darwin: pthread_rwlock_unlock$UNIX2003
// Solaris: rw_unlock (pthread_rwlock_unlock is a weak alias)
__attribute__((noinline))
static int pthread_rwlock_unlock_WRK(pthread_rwlock_t* rwlock)
{
int ret;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_PTH_FNS) {
fprintf(stderr, "<< pthread_rwl_unlk %p", rwlock); fflush(stderr);
}
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_RWLOCK_UNLOCK_PRE,
pthread_rwlock_t*,rwlock);
CALL_FN_W_W(ret, fn, rwlock);
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_RWLOCK_UNLOCK_POST,
pthread_rwlock_t*,rwlock);
if (ret != 0) {
DO_PthAPIerror( "pthread_rwlock_unlock", ret );
}
if (TRACE_PTH_FNS) {
fprintf(stderr, " :: rwl_unlk -> %d >>\n", ret);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, pthreadZurwlockZuunlock, // pthread_rwlock_unlock
pthread_rwlock_t* rwlock) {
return pthread_rwlock_unlock_WRK(rwlock);
}
#elif defined(VGO_darwin)
PTH_FUNC(int, pthreadZurwlockZuunlockZa, // pthread_rwlock_unlock*
pthread_rwlock_t* rwlock) {
return pthread_rwlock_unlock_WRK(rwlock);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, rwZuunlock, // rw_unlock
pthread_rwlock_t *rwlock) {
return pthread_rwlock_unlock_WRK(rwlock);
}
#else
# error "Unsupported OS"
#endif
#endif /* defined(HAVE_PTHREAD_RWLOCK_T) */
/*----------------------------------------------------------------*/
/*--- POSIX semaphores ---*/
/*----------------------------------------------------------------*/
#include <semaphore.h>
#include <fcntl.h> /* O_CREAT */
#define TRACE_SEM_FNS 0
/* Handled:
int sem_init(sem_t *sem, int pshared, unsigned value);
int sem_destroy(sem_t *sem);
int sem_wait(sem_t *sem);
int sem_post(sem_t *sem);
sem_t* sem_open(const char *name, int oflag,
... [mode_t mode, unsigned value]);
[complete with its idiotic semantics]
int sem_close(sem_t* sem);
Unhandled:
int sem_trywait(sem_t *sem);
int sem_timedwait(sem_t *restrict sem,
const struct timespec *restrict abs_timeout);
*/
//-----------------------------------------------------------
// glibc: sem_init@@GLIBC_2.2.5
// glibc: sem_init@@GLIBC_2.1
// glibc: sem_init@GLIBC_2.0
// darwin: sem_init
// Solaris: sema_init (sem_init is built on top of sem_init)
//
#if !defined(VGO_solaris)
__attribute__((noinline))
static int sem_init_WRK(sem_t* sem, int pshared, unsigned long value)
{
OrigFn fn;
int ret;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_SEM_FNS) {
fprintf(stderr, "<< sem_init(%p,%d,%lu) ", sem,pshared,value);
fflush(stderr);
}
CALL_FN_W_WWW(ret, fn, sem,pshared,value);
if (ret == 0) {
DO_CREQ_v_WW(_VG_USERREQ__HG_POSIX_SEM_INIT_POST,
sem_t*, sem, unsigned long, value);
} else {
DO_PthAPIerror( "sem_init", errno );
}
if (TRACE_SEM_FNS) {
fprintf(stderr, " sem_init -> %d >>\n", ret);
fflush(stderr);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, semZuinitZAZa, // sem_init@*
sem_t* sem, int pshared, unsigned long value) {
return sem_init_WRK(sem, pshared, value);
}
#elif defined(VGO_darwin)
PTH_FUNC(int, semZuinit, // sem_init
sem_t* sem, int pshared, unsigned long value) {
return sem_init_WRK(sem, pshared, value);
}
#else
# error "Unsupported OS"
#endif
#else /* VGO_solaris */
PTH_FUNC(int, semaZuinit, // sema_init
sema_t *sem,
unsigned int value,
int type,
void *arg)
{
OrigFn fn;
int ret;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_SEM_FNS) {
fprintf(stderr, "<< sema_init(%p, %d, %u) ", sem, type, value);
fflush(stderr);
}
CALL_FN_W_WWWW(ret, fn, sem, value, type, arg);
if (ret == 0) {
DO_CREQ_v_WW(_VG_USERREQ__HG_POSIX_SEM_INIT_POST,
sema_t *, sem, Word, value);
} else {
DO_PthAPIerror("sema_init", ret);
}
if (TRACE_SEM_FNS) {
fprintf(stderr, " sema_init -> %d >>\n", ret);
fflush(stderr);
}
return ret;
}
#endif /* VGO_solaris */
//-----------------------------------------------------------
// glibc: sem_destroy@GLIBC_2.0
// glibc: sem_destroy@@GLIBC_2.1
// glibc: sem_destroy@@GLIBC_2.2.5
// darwin: sem_destroy
// Solaris: sema_destroy (sem_destroy is built on top of sema_destroy)
__attribute__((noinline))
static int sem_destroy_WRK(sem_t* sem)
{
OrigFn fn;
int ret;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_SEM_FNS) {
fprintf(stderr, "<< sem_destroy(%p) ", sem);
fflush(stderr);
}
DO_CREQ_v_W(_VG_USERREQ__HG_POSIX_SEM_DESTROY_PRE, sem_t*, sem);
CALL_FN_W_W(ret, fn, sem);
if (ret != 0) {
DO_PthAPIerror( "sem_destroy", SEM_ERROR );
}
if (TRACE_SEM_FNS) {
fprintf(stderr, " sem_destroy -> %d >>\n", ret);
fflush(stderr);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, semZudestroyZAZa, // sem_destroy*
sem_t* sem) {
return sem_destroy_WRK(sem);
}
#elif defined(VGO_darwin)
PTH_FUNC(int, semZudestroy, // sem_destroy
sem_t* sem) {
return sem_destroy_WRK(sem);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, semaZudestroy, // sema_destroy
sem_t *sem) {
return sem_destroy_WRK(sem);
}
#else
# error "Unsupported OS"
#endif
//-----------------------------------------------------------
// glibc: sem_wait
// glibc: sem_wait@GLIBC_2.0
// glibc: sem_wait@@GLIBC_2.1
// darwin: sem_wait
// darwin: sem_wait$NOCANCEL$UNIX2003
// darwin: sem_wait$UNIX2003
// Solaris: sema_wait (sem_wait is built on top of sema_wait)
//
/* wait: decrement semaphore - acquire lockage */
__attribute__((noinline))
static int sem_wait_WRK(sem_t* sem)
{
OrigFn fn;
int ret;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_SEM_FNS) {
fprintf(stderr, "<< sem_wait(%p) ", sem);
fflush(stderr);
}
DO_CREQ_v_W(_VG_USERREQ__HG_POSIX_SEM_WAIT_PRE, sem_t*,sem);
CALL_FN_W_W(ret, fn, sem);
DO_CREQ_v_WW(_VG_USERREQ__HG_POSIX_SEM_WAIT_POST, sem_t*,sem,
long, (ret == 0) ? True : False);
if (ret != 0) {
DO_PthAPIerror( "sem_wait", SEM_ERROR );
}
if (TRACE_SEM_FNS) {
fprintf(stderr, " sem_wait -> %d >>\n", ret);
fflush(stderr);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, semZuwait, sem_t* sem) { /* sem_wait */
return sem_wait_WRK(sem);
}
PTH_FUNC(int, semZuwaitZAZa, sem_t* sem) { /* sem_wait@* */
return sem_wait_WRK(sem);
}
#elif defined(VGO_darwin)
PTH_FUNC(int, semZuwait, sem_t* sem) { /* sem_wait */
return sem_wait_WRK(sem);
}
PTH_FUNC(int, semZuwaitZDZa, sem_t* sem) { /* sem_wait$* */
return sem_wait_WRK(sem);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, semaZuwait, sem_t *sem) { /* sema_wait */
return sem_wait_WRK(sem);
}
#else
# error "Unsupported OS"
#endif
//-----------------------------------------------------------
// glibc: sem_post
// glibc: sem_post@GLIBC_2.0
// glibc: sem_post@@GLIBC_2.1
// darwin: sem_post
// Solaris: sema_post (sem_post is built on top of sema_post)
//
/* post: increment semaphore - release lockage */
__attribute__((noinline))
static int sem_post_WRK(sem_t* sem)
{
OrigFn fn;
int ret;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_SEM_FNS) {
fprintf(stderr, "<< sem_post(%p) ", sem);
fflush(stderr);
}
DO_CREQ_v_W(_VG_USERREQ__HG_POSIX_SEM_POST_PRE, sem_t*,sem);
CALL_FN_W_W(ret, fn, sem);
DO_CREQ_v_W(_VG_USERREQ__HG_POSIX_SEM_POST_POST, sem_t*,sem);
if (ret != 0) {
DO_PthAPIerror( "sem_post", SEM_ERROR );
}
if (TRACE_SEM_FNS) {
fprintf(stderr, " sem_post -> %d >>\n", ret);
fflush(stderr);
}
return ret;
}
#if defined(VGO_linux)
PTH_FUNC(int, semZupost, sem_t* sem) { /* sem_post */
return sem_post_WRK(sem);
}
PTH_FUNC(int, semZupostZAZa, sem_t* sem) { /* sem_post@* */
return sem_post_WRK(sem);
}
#elif defined(VGO_darwin)
PTH_FUNC(int, semZupost, sem_t* sem) { /* sem_post */
return sem_post_WRK(sem);
}
#elif defined(VGO_solaris)
PTH_FUNC(int, semaZupost, sem_t *sem) { /* sema_post */
return sem_post_WRK(sem);
}
#else
# error "Unsupported OS"
#endif
//-----------------------------------------------------------
// glibc: sem_open
// darwin: sem_open
// Solaris: sem_open
//
PTH_FUNC(sem_t*, semZuopen,
const char* name, long oflag,
long mode, unsigned long value)
{
/* A copy of sem_init_WRK (more or less). Is this correct? */
OrigFn fn;
sem_t* ret;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_SEM_FNS) {
fprintf(stderr, "<< sem_open(\"%s\",%ld,%lx,%lu) ",
name,oflag,mode,value);
fflush(stderr);
}
CALL_FN_W_WWWW(ret, fn, name,oflag,mode,value);
if (ret != SEM_FAILED && (oflag & O_CREAT)) {
DO_CREQ_v_WW(_VG_USERREQ__HG_POSIX_SEM_INIT_POST,
sem_t*, ret, unsigned long, value);
}
if (ret == SEM_FAILED) {
DO_PthAPIerror( "sem_open", errno );
}
if (TRACE_SEM_FNS) {
fprintf(stderr, " sem_open -> %p >>\n", ret);
fflush(stderr);
}
return ret;
}
//-----------------------------------------------------------
// glibc: sem_close
// darwin: sem_close
// Solaris: sem_close
PTH_FUNC(int, sem_close, sem_t* sem)
{
OrigFn fn;
int ret;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_SEM_FNS) {
fprintf(stderr, "<< sem_close(%p) ", sem);
fflush(stderr);
}
DO_CREQ_v_W(_VG_USERREQ__HG_POSIX_SEM_DESTROY_PRE, sem_t*, sem);
CALL_FN_W_W(ret, fn, sem);
if (ret != 0) {
DO_PthAPIerror( "sem_close", errno );
}
if (TRACE_SEM_FNS) {
fprintf(stderr, " close -> %d >>\n", ret);
fflush(stderr);
}
return ret;
}
/*----------------------------------------------------------------*/
/*--- Qt 4 threading functions (w/ GNU name mangling) ---*/
/*----------------------------------------------------------------*/
/* Handled:
QMutex::lock()
QMutex::unlock()
QMutex::tryLock()
QMutex::tryLock(int)
QMutex::QMutex(QMutex::RecursionMode) _ZN6QMutexC1ENS_13RecursionModeE
QMutex::QMutex(QMutex::RecursionMode) _ZN6QMutexC2ENS_13RecursionModeE
QMutex::~QMutex() _ZN6QMutexD1Ev
QMutex::~QMutex() _ZN6QMutexD2Ev
Unhandled:
QReadWriteLock::lockForRead()
QReadWriteLock::lockForWrite()
QReadWriteLock::unlock()
QReadWriteLock::tryLockForRead(int)
QReadWriteLock::tryLockForRead()
QReadWriteLock::tryLockForWrite(int)
QReadWriteLock::tryLockForWrite()
QWaitCondition::wait(QMutex*, unsigned long)
QWaitCondition::wakeAll()
QWaitCondition::wakeOne()
QSemaphore::*
*/
/* More comments, 19 Nov 08, based on assessment of qt-4.5.0TP1,
at least on Unix:
It's apparently only necessary to intercept QMutex, since that is
not implemented using pthread_mutex_t; instead Qt4 has its own
implementation based on atomics (to check the non-contended case)
and pthread_cond_wait (to wait in the contended case).
QReadWriteLock is built on top of QMutex, counters, and a wait
queue. So we don't need to handle it specially once QMutex
handling is correct -- presumably the dependencies through QMutex
are sufficient to avoid any false race reports. On the other hand,
it is an open question whether too many dependencies are observed
-- in which case we may miss races (false negatives). I suspect
this is likely to be the case, unfortunately.
QWaitCondition is built on pthread_cond_t, pthread_mutex_t, QMutex
and QReadWriteLock. Same compositional-correctness justificiation
and limitations as fro QReadWriteLock.
Ditto QSemaphore (from cursory examination).
Does it matter that only QMutex is handled directly? Open
question. From testing with drd/tests/qt4_* and with KDE4 apps, it
appears that no false errors are reported; however it is not clear
if this is causing false negatives.
Another problem with Qt4 is thread exiting. Threads are created
with pthread_create (fine); but they detach and simply exit when
done. There is no use of pthread_join, and the provided
wait-for-a-thread-to-exit mechanism (QThread::wait, I believe)
relies on a system of mutexes and flags. I suspect this also
causes too many dependencies to appear. Consequently H sometimes
fails to detect races at exit in some very short-lived racy
programs, because it appears that a thread can exit _and_ have an
observed dependency edge back to the main thread (presumably)
before the main thread reaps the child (that is, calls
QThread::wait).
This theory is supported by the observation that if all threads are
made to wait at a pthread_barrier_t immediately before they exit,
then H's detection of races in such programs becomes reliable;
without the barrier, it is varies from run to run, depending
(according to investigation) on whether aforementioned
exit-before-reaping behaviour happens or not.
Finally, why is it necessary to intercept the QMutex constructors
and destructors? The constructors are intercepted only as a matter
of convenience, so H can print accurate "first observed at"
clauses. However, it is actually necessary to intercept the
destructors (as it is with pthread_mutex_destroy) in order that
locks get removed from LAOG when they are destroyed.
*/
// soname is libQtCore.so.4 ; match against libQtCore.so*
#define QT4_FUNC(ret_ty, f, args...) \
ret_ty I_WRAP_SONAME_FNNAME_ZU(libQtCoreZdsoZa,f)(args); \
ret_ty I_WRAP_SONAME_FNNAME_ZU(libQtCoreZdsoZa,f)(args)
// soname is libQt5Core.so.4 ; match against libQt5Core.so*
#define QT5_FUNC(ret_ty, f, args...) \
ret_ty I_WRAP_SONAME_FNNAME_ZU(libQt5CoreZdsoZa,f)(args); \
ret_ty I_WRAP_SONAME_FNNAME_ZU(libQt5CoreZdsoZa,f)(args)
//-----------------------------------------------------------
// QMutex::lock()
__attribute__((noinline))
static void QMutex_lock_WRK(void* self)
{
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_QT4_FNS) {
fprintf(stderr, "<< QMutex::lock %p", self); fflush(stderr);
}
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_PRE,
void*,self, long,0/*!isTryLock*/);
CALL_FN_v_W(fn, self);
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_POST,
void *, self, long, True);
if (TRACE_QT4_FNS) {
fprintf(stderr, " :: Q::lock done >>\n");
}
}
QT4_FUNC(void, _ZN6QMutex4lockEv, void* self) {
QMutex_lock_WRK(self);
}
QT5_FUNC(void, _ZN6QMutex4lockEv, void* self) {
QMutex_lock_WRK(self);
}
//-----------------------------------------------------------
// QMutex::unlock()
__attribute__((noinline))
static void QMutex_unlock_WRK(void* self)
{
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_QT4_FNS) {
fprintf(stderr, "<< QMutex::unlock %p", self); fflush(stderr);
}
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_PRE,
void*, self);
CALL_FN_v_W(fn, self);
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_POST,
void*, self);
if (TRACE_QT4_FNS) {
fprintf(stderr, " Q::unlock done >>\n");
}
}
QT4_FUNC(void, _ZN6QMutex6unlockEv, void* self) {
QMutex_unlock_WRK(self);
}
QT5_FUNC(void, _ZN6QMutex6unlockEv, void* self) {
QMutex_unlock_WRK(self);
}
//-----------------------------------------------------------
// bool QMutex::tryLock()
// using 'long' to mimic C++ 'bool'
__attribute__((noinline))
static long QMutex_tryLock_WRK(void* self)
{
OrigFn fn;
long ret;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_QT4_FNS) {
fprintf(stderr, "<< QMutex::tryLock %p", self); fflush(stderr);
}
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_PRE,
void*,self, long,1/*isTryLock*/);
CALL_FN_W_W(ret, fn, self);
// assumes that only the low 8 bits of the 'bool' are significant
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_POST,
void *, self, long, (ret & 0xFF) ? True : False);
if (TRACE_QT4_FNS) {
fprintf(stderr, " :: Q::tryLock -> %lu >>\n", ret);
}
return ret;
}
QT4_FUNC(long, _ZN6QMutex7tryLockEv, void* self) {
return QMutex_tryLock_WRK(self);
}
QT5_FUNC(long, _ZN6QMutex7tryLockEv, void* self) {
return QMutex_tryLock_WRK(self);
}
//-----------------------------------------------------------
// bool QMutex::tryLock(int)
// using 'long' to mimic C++ 'bool'
__attribute__((noinline))
static long QMutex_tryLock_int_WRK(void* self, long arg2)
{
OrigFn fn;
long ret;
VALGRIND_GET_ORIG_FN(fn);
if (TRACE_QT4_FNS) {
fprintf(stderr, "<< QMutex::tryLock(int) %p %d", self, (int)arg2);
fflush(stderr);
}
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_PRE,
void*,self, long,1/*isTryLock*/);
CALL_FN_W_WW(ret, fn, self,arg2);
// assumes that only the low 8 bits of the 'bool' are significant
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_POST,
void *, self, long, (ret & 0xFF) ? True : False);
if (TRACE_QT4_FNS) {
fprintf(stderr, " :: Q::tryLock(int) -> %lu >>\n", ret);
}
return ret;
}
QT4_FUNC(long, _ZN6QMutex7tryLockEi, void* self, long arg2) {
return QMutex_tryLock_int_WRK(self, arg2);
}
QT5_FUNC(long, _ZN6QMutex7tryLockEi, void* self, long arg2) {
return QMutex_tryLock_int_WRK(self, arg2);
}
//-----------------------------------------------------------
// It's not really very clear what the args are here. But from
// a bit of dataflow analysis of the generated machine code of
// the original function, it appears this takes two args, and
// returns nothing. Nevertheless preserve return value just in
// case. A bit of debug printing indicates that the first arg
// is that of the mutex and the second is either zero or one,
// probably being the recursion mode, therefore.
// QMutex::QMutex(QMutex::RecursionMode) ("C1ENS" variant)
__attribute__((noinline))
static void* QMutex_constructor_WRK(void* mutex, long recmode)
{
OrigFn fn;
long ret;
VALGRIND_GET_ORIG_FN(fn);
CALL_FN_W_WW(ret, fn, mutex, recmode);
// fprintf(stderr, "QMutex constructor 1: %p <- %p %p\n", ret, arg1, arg2);
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_INIT_POST,
void*,mutex, long,1/*mbRec*/);
return (void*)ret;
}
QT4_FUNC(void*, _ZN6QMutexC1ENS_13RecursionModeE, void* self, long recmode) {
return QMutex_constructor_WRK(self, recmode);
}
QT5_FUNC(void*, _ZN6QMutexC1ENS_13RecursionModeE, void* self, long recmode) {
return QMutex_constructor_WRK(self, recmode);
}
//-----------------------------------------------------------
// QMutex::~QMutex() ("D1Ev" variant)
__attribute__((noinline))
static void* QMutex_destructor_WRK(void* mutex)
{
OrigFn fn;
long ret;
VALGRIND_GET_ORIG_FN(fn);
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_MUTEX_DESTROY_PRE,
void*,mutex);
CALL_FN_W_W(ret, fn, mutex);
return (void*)ret;
}
QT4_FUNC(void*, _ZN6QMutexD1Ev, void* self) {
return QMutex_destructor_WRK(self);
}
QT5_FUNC(void*, _ZN6QMutexD1Ev, void* self) {
return QMutex_destructor_WRK(self);
}
//-----------------------------------------------------------
// QMutex::QMutex(QMutex::RecursionMode) ("C2ENS" variant)
QT4_FUNC(void*, _ZN6QMutexC2ENS_13RecursionModeE,
void* mutex,
long recmode)
{
assert(0);
/*NOTREACHED*/
/* Android's gcc behaves like it doesn't know that assert(0)
never returns. Hence: */
return NULL;
}
QT5_FUNC(void*, _ZN6QMutexC2ENS_13RecursionModeE, void* self, long recmode)
{
assert(0);
/*NOTREACHED*/
return NULL;
}
//-----------------------------------------------------------
// QMutex::~QMutex() ("D2Ev" variant)
QT4_FUNC(void*, _ZN6QMutexD2Ev, void* mutex)
{
assert(0);
/* Android's gcc behaves like it doesn't know that assert(0)
never returns. Hence: */
return NULL;
}
QT5_FUNC(void*, _ZN6QMutexD2Ev, void* self)
{
assert(0);
/*NOTREACHED*/
return NULL;
}
// QReadWriteLock is not intercepted directly. See comments
// above.
//// QReadWriteLock::lockForRead()
//// _ZN14QReadWriteLock11lockForReadEv == QReadWriteLock::lockForRead()
//QT4_FUNC(void, ZuZZN14QReadWriteLock11lockForReadEv,
// // _ZN14QReadWriteLock11lockForReadEv
// void* self)
//{
// OrigFn fn;
// VALGRIND_GET_ORIG_FN(fn);
// if (TRACE_QT4_FNS) {
// fprintf(stderr, "<< QReadWriteLock::lockForRead %p", self);
// fflush(stderr);
// }
//
// DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE,
// void*,self,
// long,0/*!isW*/, long,0/*!isTryLock*/);
//
// CALL_FN_v_W(fn, self);
//
// DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_POST,
// void*,self, long,0/*!isW*/, long, True);
//
// if (TRACE_QT4_FNS) {
// fprintf(stderr, " :: Q::lockForRead :: done >>\n");
// }
//}
//
//// QReadWriteLock::lockForWrite()
//// _ZN14QReadWriteLock12lockForWriteEv == QReadWriteLock::lockForWrite()
//QT4_FUNC(void, ZuZZN14QReadWriteLock12lockForWriteEv,
// // _ZN14QReadWriteLock12lockForWriteEv
// void* self)
//{
// OrigFn fn;
// VALGRIND_GET_ORIG_FN(fn);
// if (TRACE_QT4_FNS) {
// fprintf(stderr, "<< QReadWriteLock::lockForWrite %p", self);
// fflush(stderr);
// }
//
// DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE,
// void*,self,
// long,1/*isW*/, long,0/*!isTryLock*/);
//
// CALL_FN_v_W(fn, self);
//
// DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_POST,
// void*,self, long,1/*isW*/, long, True);
//
// if (TRACE_QT4_FNS) {
// fprintf(stderr, " :: Q::lockForWrite :: done >>\n");
// }
//}
//
//// QReadWriteLock::unlock()
//// _ZN14QReadWriteLock6unlockEv == QReadWriteLock::unlock()
//QT4_FUNC(void, ZuZZN14QReadWriteLock6unlockEv,
// // _ZN14QReadWriteLock6unlockEv
// void* self)
//{
// OrigFn fn;
// VALGRIND_GET_ORIG_FN(fn);
// if (TRACE_QT4_FNS) {
// fprintf(stderr, "<< QReadWriteLock::unlock %p", self);
// fflush(stderr);
// }
//
// DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_RWLOCK_UNLOCK_PRE,
// void*,self);
//
// CALL_FN_v_W(fn, self);
//
// DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_RWLOCK_UNLOCK_POST,
// void*,self);
//
// if (TRACE_QT4_FNS) {
// fprintf(stderr, " :: Q::unlock :: done >>\n");
// }
//}
/*----------------------------------------------------------------*/
/*--- Replacements for basic string functions, that don't ---*/
/*--- overrun the input arrays. ---*/
/*----------------------------------------------------------------*/
#include "../shared/vg_replace_strmem.c"
/*--------------------------------------------------------------------*/
/*--- end hg_intercepts.c ---*/
/*--------------------------------------------------------------------*/
|