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
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
|
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
BUILD32 = $(POUND_SIGN)
include $(SRC)/cmd/sgs/Makefile.sub
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2018, Joyent, Inc.
# Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
# Copyright 2024 Oxide Computer Company
#
PROG= elfdump
include $(SRC)/cmd/Makefile.cmd
include $(SRC)/cmd/sgs/Makefile.com
include $(SRC)/common/hexdump/Makefile.com
# Hammerhead: removed struct_layout_sparc.o and struct_layout_sparcv9.o (amd64-only)
COMOBJ = main.o corenote.o \
dwarf.o struct_layout.o \
struct_layout_i386.o struct_layout_amd64.o
COMOBJ32 = elfdump32.o fake_shdr32.o
COMOBJ64 = elfdump64.o fake_shdr64.o
SGSCOMMONOBJ = leb128.o
BLTOBJ = msg.o
EXTOBJ = $(HEXDUMP_OBJS)
OBJS= $(BLTOBJ) $(COMOBJ) $(COMOBJ32) $(COMOBJ64) $(SGSCOMMONOBJ) \
$(EXTOBJ)
MAPFILE= $(MAPFILE.NGB)
MAPOPT= $(MAPFILE:%=-Wl,-M%)
CPPFLAGS= -I. -I../common -I../../include -I../../include/$(MACH) \
-I$(SRC)/lib/libc/inc -I$(SRC)/uts/$(ARCH)/sys \
$(CPPFLAGS.master) -I$(ELFCAP)
LDFLAGS += $(VERSREF) $(MAPOPT) '-R$$ORIGIN/../../lib/$(MACH64)'
LDLIBS += $(ELFLIBDIR64) -lelf $(LDDBGLIBDIR64) -llddbg \
$(CONVLIBDIR64) -lconv
NATIVE_LDFLAGS = $(LDASSERTS) $(BDIRECT)
BLTDEFS = msg.h
BLTDATA = msg.c
BLTMESG = $(SGSMSGDIR)/elfdump
BLTFILES = $(BLTDEFS) $(BLTDATA) $(BLTMESG)
SGSMSGCOM = ../common/elfdump.msg
SGSMSGTARG = $(SGSMSGCOM)
SGSMSGALL = $(SGSMSGCOM)
SGSMSGFLAGS += -h $(BLTDEFS) -d $(BLTDATA) -m $(BLTMESG) -n elfdump_msg
SRCS = $(COMOBJ:%.o=../common/%.c) \
$(COMOBJ32:%32.o=../common/%.c) \
$(SGSCOMMONOBJ:%.o=$(SGSCOMMON)/%.c) $(BLTDATA)
# Hammerhead: Suppress return-type warnings in legacy elfdump common code
# The ELF printing functions use complex switch statements that GCC 14
# incorrectly flags as potentially missing return values
CERRWARN += -Wno-return-type
CLEANFILES += $(BLTFILES) gen_struct_layout
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# Copyright 2015 Nexenta Systems, Inc. All rights reserved.
# Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
#
%.o: ../common/%.c
$(COMPILE.c) -o $@ $<
$(POST_PROCESS_O)
%32.o: ../common/%.c
$(COMPILE.c) -o $@ $<
$(POST_PROCESS_O)
%64.o: ../common/%.c
$(COMPILE.c) -D_ELF64 -o $@ $<
$(POST_PROCESS_O)
%.o: $(SGSCOMMON)/%.c
$(COMPILE.c) -o $@ $<
$(POST_PROCESS_O)
# Hammerhead: Ensure message header is generated before compiling objects
$(OBJS): $(BLTDEFS)
all: $(PROG)
$(PROG): $(OBJS) $(MAPFILE) check_struct_layout
$(LINK.c) -o $@ $(OBJS) $(LDLIBS)
$(POST_PROCESS)
check_struct_layout: gen_struct_layout gen_layout_obj.o
sed -e '/^#include <struct_layout.h>/q' \
../common/struct_layout_$(ARCH).c | sed -e '$$d' \
> struct_layout_$(ARCH).tmp
./gen_struct_layout gen_layout_obj.o $(ARCH) \
>> struct_layout_$(ARCH).tmp
@diff -u struct_layout_$(ARCH).tmp \
../common/struct_layout_$(ARCH).c ||\
{ echo "Error: struct_layout_$(ARCH).c needs update!" ; exit 1; }
touch $@
# We need CTF data in this object.
gen_layout_obj.o : CFLAGS += $(CTF_FLAGS)
gen_layout_obj.o : CFLAGS64 += $(CTF_FLAGS)
gen_layout_obj.o : POST_PROCESS_O = $(CTFCONVERT_O)
gen_struct_layout: ../common/gen_struct_layout.c
$(NATIVECC) $(NATIVE_CFLAGS) -o $@ \
../common/gen_struct_layout.c -lctf
clean:
$(RM) $(OBJS) $(CLEANFILES) gen_struct_layout \
check_struct_layout gen_layout_obj.o \
struct_layout_$(ARCH).tmp
install: all $(ROOTPROG) $(ROOTCCSBINLINK)
include $(SRC)/common/hexdump/Makefile.targ
include $(SRC)/cmd/Makefile.targ
# Derived source and header files (messaging).
catalog: $(BLTMESG)
chkmsg: $(SRCS)
sh $(CHKMSG) $(CHKMSGFLAGS) $(SRCS)
# Hammerhead: GNU Make grouped target syntax (&:) - was dmake + syntax
$(BLTDEFS) $(BLTDATA) $(BLTMESG) &: $(SGSMSGALL)
$(SGSMSG) $(SGSMSGFLAGS) $(SGSMSGALL)
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
#
include ../Makefile.com
.KEEP_STATE:
ARCH = amd64
include ../Makefile.targ
include $(SRC)/Makefile.master.64
# Hammerhead: ROOTPROG64=ROOTPROG, ROOTCCSBINLINK64=ROOTCCSBINLINK (path flattening)
# Removed duplicate 64-bit targets and ../../bin symlink (circular when /bin -> usr/bin)
install: $(ROOTPROG) \
$(ROOTCCSBINLINK)
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef __ELFDUMP_H
#define __ELFDUMP_H
#include <_machelf.h>
#include <debug.h>
/*
* Local include file for elfdump.
*/
#ifdef __cplusplus
extern "C" {
#endif
/*
* flags: This is a bitmask that controls elfdump's operations. There
* are three categories of flag:
*
* SHOW - Specify categories of things in the ELF object to display.
* CALC - Compute something based on the contents of the ELF object.
* CTL - Control options specify general options that are not
* specific to any specific part of the ELF object, but
* which apply at a higher level.
*
* To simplify masking these categories, they are assigned bit ranges
* as follows:
* SHOW: Bottom 24-bits
* CALC: Upper 2 bits of most significant byte
* CTL: Lower 6 bits of most significant byte
*/
#define FLG_SHOW_DYNAMIC 0x00000001
#define FLG_SHOW_EHDR 0x00000002
#define FLG_SHOW_INTERP 0x00000004
#define FLG_SHOW_SHDR 0x00000008
#define FLG_SHOW_NOTE 0x00000010
#define FLG_SHOW_PHDR 0x00000020
#define FLG_SHOW_RELOC 0x00000040
#define FLG_SHOW_SYMBOLS 0x00000080
#define FLG_SHOW_VERSIONS 0x00000100
#define FLG_SHOW_HASH 0x00000200
#define FLG_SHOW_GOT 0x00000400
#define FLG_SHOW_SYMINFO 0x00000800
#define FLG_SHOW_MOVE 0x00001000
#define FLG_SHOW_GROUP 0x00002000
#define FLG_SHOW_CAP 0x00004000
#define FLG_SHOW_UNWIND 0x00008000
#define FLG_SHOW_SORT 0x00010000
#define FLG_CTL_LONGNAME 0x01000000
#define FLG_CTL_DEMANGLE 0x02000000
#define FLG_CTL_FAKESHDR 0x04000000
#define FLG_CTL_MATCH 0x08000000
#define FLG_CTL_OSABI 0x10000000
#define FLG_CALC_CHECKSUM 0x40000000
/* Bitmasks that isolate the parts of a flag value */
#define FLG_MASK_SHOW 0x00ffffff
#define FLG_MASK_CTL 0x3f000000
#define FLG_MASK_CALC 0xc0000000
/*
* Mask that selects the show flags that do not require the ELF
* object to have a section header array.
*/
#define FLG_MASK_SHOW_NOSHDR (FLG_SHOW_EHDR | FLG_SHOW_PHDR)
/*
* Masks to select the flags that require the ELF object to
* have a section header array, within each flag type.
*/
#define FLG_MASK_SHOW_SHDR (FLG_MASK_SHOW & ~FLG_MASK_SHOW_NOSHDR)
#define FLG_MASK_CALC_SHDR FLG_CALC_CHECKSUM
/* Size of buffer used for formatting an index into textual representation */
#define MAXNDXSIZE 10
typedef struct cache {
Elf_Scn *c_scn;
Shdr *c_shdr;
Elf_Data *c_data;
char *c_name;
int c_ndx; /* Section index */
} Cache;
typedef struct got_info {
Word g_reltype; /* it will never happen, but */
/* support mixed relocations */
void *g_rel;
const char *g_symname;
} Got_info;
extern const Cache cache_init;
extern void failure(const char *, const char *);
extern const char *demangle(const char *, uint_t);
/*
* Flags for the match() function:
* MATCH_F_STRICT
* A strict match requires an explicit match to
* a user specified match (-I, -N, -T) option. A
* non-strict match also succeeds if the match
* list is empty.
*
* MATCH_F_PHDR
* The match item is a program header. If this
* flag is not set, the match item is a section
* header.
*
* MATCH_F_NAME
* The name parameter contains valid information.
*
* MATCH_F_NDX
* The ndx argument contains valid information
*
* MATCH_F_TYPE
* The type argument contains valid information
*/
typedef enum {
MATCH_F_STRICT = 1,
MATCH_F_PHDR = 2,
MATCH_F_NAME = 4,
MATCH_F_NDX = 8,
MATCH_F_TYPE = 16
} match_flags_t;
/* It is common for calls to match() to specify all three arguments */
#define MATCH_F_ALL (MATCH_F_NAME | MATCH_F_NDX | MATCH_F_TYPE)
extern int match(match_flags_t, const char *, uint_t, uint_t);
/*
* Possible return values from corenote()
*/
typedef enum {
CORENOTE_R_OK = 0, /* Note data successfully displayed */
CORENOTE_R_OK_DUMP = 1, /* Note OK, but not handled. Display Hex dump */
CORENOTE_R_BADDATA = 2, /* Note data truncated or otherwise malformed */
CORENOTE_R_BADARCH = 3, /* core file note code does not contain */
/* support for given architecture */
CORENOTE_R_BADTYPE = 4 /* Unknown note type */
} corenote_ret_t;
/*
* Define various elfdump() functions into their 32-bit and 64-bit variants.
*/
#if defined(_ELF64)
#define cap cap64
#define checksum checksum64
#define dynamic dynamic64
#define fake_shdr_cache fake_shdr_cache64
#define fake_shdr_cache_free fake_shdr_cache_free64
#define got got64
#define group group64
#define hash hash64
#define interp interp64
#define move move64
#define note note64
#define note_entry note_entry64
#define regular regular64
#define reloc reloc64
#define sections sections64
#define string string64
#define symbols symbols64
#define syminfo syminfo64
#define symlookup symlookup64
#define unwind unwind64
#define versions versions64
#define version_def version_def64
#define version_need version_need64
#else
#define cap cap32
#define checksum checksum32
#define dynamic dynamic32
#define fake_shdr_cache fake_shdr_cache32
#define fake_shdr_cache_free fake_shdr_cache_free32
#define got got32
#define group group32
#define hash hash32
#define interp interp32
#define move move32
#define note note32
#define note_entry note_entry32
#define regular regular32
#define reloc reloc32
#define sections sections32
#define string string32
#define symbols symbols32
#define syminfo syminfo32
#define symlookup symlookup32
#define unwind unwind32
#define versions versions32
#define version_def version_def32
#define version_need version_need32
#endif
extern corenote_ret_t corenote(Half, int, Word, const char *, Word);
extern void dump_eh_frame(const char *, char *, uchar_t *, size_t, uint64_t,
Half e_machine, uchar_t *e_ident, uint64_t gotaddr);
extern void dump_hex_bytes(const void *, size_t, int, int, int);
extern int fake_shdr_cache32(const char *, int, Elf *, Elf32_Ehdr *,
Cache **, size_t *);
extern int fake_shdr_cache64(const char *, int, Elf *, Elf64_Ehdr *,
Cache **, size_t *);
extern void fake_shdr_cache_free32(Cache *, size_t);
extern void fake_shdr_cache_free64(Cache *, size_t);
extern int regular32(const char *, int, Elf *, uint_t, const char *, int,
uchar_t);
extern int regular64(const char *, int, Elf *, uint_t, const char *, int,
uchar_t);
#ifdef __cplusplus
}
#endif
#endif /* __ELFDUMP_H */
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 2012 DEY Storage Systems, Inc. All rights reserved.
* Copyright (c) 2018, Joyent, Inc.
* Copyright 2024 Oxide Computer Company
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/corectl.h>
#include <procfs.h>
#include <msg.h>
#include <_elfdump.h>
#include <struct_layout.h>
#include <conv.h>
#include <ctype.h>
#include <sys/sysmacros.h>
/*
* This module contains the code that displays data from the note
* sections found in illumos core files. The format of these
* note sections are described in the core(5) manpage.
*/
/*
* Much of the code in this file uses the "%*s" format to set
* the left margin indentation. This macro combines the indent
* integer argument and the NULL string that follows it.
*/
#define INDENT state->ns_indent, MSG_ORIG(MSG_STR_EMPTY)
/*
* Indent unit, used for each nesting
*/
#define INDENT_STEP 4
/*
* The PRINT_ macros are convenience wrappers on print_num(),
* print_subtype(), and print_strbuf(). They reduce code
* clutter by hiding the boilerplate arguments.
*
* Assumptions:
* - A variable named "layout" exists in the compilation
* environment, referencing the layout information for the
* current type.
* - The variable "state" references the current note state.
*/
#define PRINT_DEC(_title, _field) \
print_num(state, _title, &layout->_field, SL_FMT_NUM_DEC)
#define PRINT_DEC_2UP(_title1, _field1, _title2, _field2) \
print_num_2up(state, _title1, &layout->_field1, SL_FMT_NUM_DEC, \
_title2, &layout->_field2, SL_FMT_NUM_DEC)
#define PRINT_HEX(_title, _field) \
print_num(state, _title, &layout->_field, SL_FMT_NUM_HEX)
#define PRINT_HEX_2UP(_title1, _field1, _title2, _field2) \
print_num_2up(state, _title1, &layout->_field1, SL_FMT_NUM_HEX, \
_title2, &layout->_field2, SL_FMT_NUM_HEX)
#define PRINT_ZHEX(_title, _field) \
print_num(state, _title, &layout->_field, SL_FMT_NUM_ZHEX)
#define PRINT_ZHEX_2UP(_title1, _field1, _title2, _field2) \
print_num_2up(state, _title1, &layout->_field1, SL_FMT_NUM_ZHEX, \
_title2, &layout->_field2, SL_FMT_NUM_ZHEX)
#define PRINT_SUBTYPE(_title, _field, _func) \
print_subtype(state, _title, &layout->_field, _func)
#define PRINT_STRBUF(_title, _field) \
print_strbuf(state, _title, &layout->_field)
/*
* Structure used to maintain state data for a core note, or a subregion
* (sub-struct) of a core note. These values would otherwise need to be
* passed to nearly every routine.
*/
typedef struct {
Half ns_mach; /* ELF machine type of core file */
const sl_arch_layout_t *ns_arch; /* structure layout def for mach */
int ns_swap; /* True if byte swapping is needed */
int ns_indent; /* Left margin indentation */
int ns_vcol; /* Column where value starts */
int ns_t2col; /* Column where 2up title starts */
int ns_v2col; /* Column where 2up value starts */
const char *ns_data; /* Pointer to struct data area */
Word ns_len; /* Length of struct data area */
} note_state_t;
/*
* Standard signature for a dump function used to process a note
* or a sub-structure within a note.
*/
typedef void (* dump_func_t)(note_state_t *state, const char *title);
/*
* Some core notes contain string buffers of fixed size
* that are expected to contain NULL terminated strings.
* If the NULL is there, we can print these strings directly.
* However, the potential exists for a corrupt file to have
* a non-terminated buffer. This routine examines the given
* string, and if the string is terminated, the string itself
* is returned. Otherwise, it is copied to a static buffer,
* and a pointer to the buffer is returned.
*/
static const char *
safe_str(const char *str, size_t n)
{
static char buf[2048];
size_t i, used;
if (n == 0)
return (MSG_ORIG(MSG_STR_EMPTY));
/*
* If the string is terminated and doesn't need escaping, we can return
* it as is.
*/
for (i = 0; i < n; i++) {
if (str[i] == '\0')
return (str);
if (!isascii(str[i]) || !isprint(str[i])) {
break;
}
}
for (i = 0, used = 0; i < n; i++) {
if (str[i] == '\0') {
if (used + 1 > sizeof (buf))
break;
buf[used++] = str[i];
return (buf);
} else if (isascii(str[i]) && isprint(str[i])) {
if (used + 1 > sizeof (buf))
break;
buf[used++] = str[i];
} else {
size_t len = snprintf(NULL, 0, "\\x%02x", str[i]);
if (used + len > sizeof (buf))
break;
(void) snprintf(buf + used, sizeof (buf) - used,
"\\x%02x", str[i]);
used += len;
}
}
if (i == n && used < sizeof (buf)) {
buf[used] = '\0';
return (buf);
}
/*
* If we got here, we would have overflowed. Figure out where we need to
* start and truncate.
*/
used = MIN(used, sizeof (buf) - 4);
buf[used++] = '.';
buf[used++] = '.';
buf[used++] = '.';
buf[used++] = '\0';
return (buf);
}
/*
* Convenience wrappers on top of the corresponding sl_XXX() functions.
*/
static Word
extract_as_word(note_state_t *state, const sl_field_t *fdesc)
{
return (sl_extract_as_word(state->ns_data, state->ns_swap, fdesc));
}
static Lword
extract_as_lword(note_state_t *state, const sl_field_t *fdesc)
{
return (sl_extract_as_lword(state->ns_data, state->ns_swap, fdesc));
}
static int
extract_as_sword(note_state_t *state, const sl_field_t *fdesc)
{
return (sl_extract_as_sword(state->ns_data, state->ns_swap, fdesc));
}
static const char *
fmt_num(note_state_t *state, const sl_field_t *fdesc,
sl_fmt_num_t fmt_type, sl_fmtbuf_t buf)
{
return (sl_fmt_num(state->ns_data, state->ns_swap, fdesc,
fmt_type, buf));
}
/*
* Return true of the data for the specified field is available.
*/
inline static int
data_present(note_state_t *state, const sl_field_t *fdesc)
{
return ((fdesc->slf_offset + fdesc->slf_eltlen) <= state->ns_len);
}
/*
* indent_enter/exit are used to start/end output for a subitem.
* On entry, a title is output, and the indentation level is raised
* by one unit. On exit, the indentation level is restored to its
* previous value.
*/
static void
indent_enter(note_state_t *state, const char *title,
const sl_field_t *first_fdesc)
{
/*
* If the first field offset and extent fall past the end of the
* available data, then return without printing a title. That note
* is from an older core file that doesn't have all the fields
* that we know about.
*/
if (data_present(state, first_fdesc))
dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_TITLE), INDENT, title);
state->ns_indent += INDENT_STEP;
}
static void
indent_exit(note_state_t *state)
{
state->ns_indent -= INDENT_STEP;
}
/*
* print_num outputs a field on one line, in the format:
*
* title: value
*/
static void
print_num(note_state_t *state, const char *title,
const sl_field_t *fdesc, sl_fmt_num_t fmt_type)
{
sl_fmtbuf_t buf;
/*
* If the field offset and extent fall past the end of the
* available data, then return without doing anything. That note
* is from an older core file that doesn't have all the fields
* that we know about.
*/
if (!data_present(state, fdesc))
return;
dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE), INDENT,
state->ns_vcol - state->ns_indent, title,
fmt_num(state, fdesc, fmt_type, buf));
}
/*
* print_num_2up outputs two fields on one line, in the format:
*
* title1: value1 title2: value2
*/
static void
print_num_2up(note_state_t *state, const char *title1,
const sl_field_t *fdesc1, sl_fmt_num_t fmt_type1, const char *title2,
const sl_field_t *fdesc2, sl_fmt_num_t fmt_type2)
{
sl_fmtbuf_t buf1, buf2;
/*
* If the field offset and extent fall past the end of the
* available data, then return without doing anything. That note
* is from an older core file that doesn't have all the fields
* that we know about.
*/
if (!(data_present(state, fdesc1) &&
data_present(state, fdesc2)))
return;
dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
state->ns_vcol - state->ns_indent, title1,
state->ns_t2col - state->ns_vcol,
fmt_num(state, fdesc1, fmt_type1, buf1),
state->ns_v2col - state->ns_t2col, title2,
fmt_num(state, fdesc2, fmt_type2, buf2));
}
/*
* print_strbuf outputs a fixed sized character buffer field
* on one line, in the format:
*
* title: value
*/
static void
print_strbuf(note_state_t *state, const char *title,
const sl_field_t *fdesc)
{
Word n;
/*
* If we are past the end of the data area, then return
* without doing anything. That note is from an older core
* file that doesn't have all the fields that we know about.
*
* Note that we are willing to accept a partial buffer,
* so we don't use data_present() for this test.
*/
if (fdesc->slf_offset >= state->ns_len)
return;
/*
* We expect the full buffer to be present, but if there
* is less than that, we will still proceed. The use of safe_str()
* protects us from the effect of printing garbage data.
*/
n = state->ns_len - fdesc->slf_offset;
if (n > fdesc->slf_nelts)
n = fdesc->slf_nelts;
dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE), INDENT,
state->ns_vcol - state->ns_indent,
title, safe_str(fdesc->slf_offset + state->ns_data, n));
}
/*
* print_str outputs an arbitrary string value item
* on one line, in the format:
*
* title: str
*/
static void
print_str(note_state_t *state, const char *title, const char *str)
{
dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE), INDENT,
state->ns_vcol - state->ns_indent, title, str);
}
/*
* Used when one dump function needs to call another dump function
* in order to display a subitem. This routine constructs a state
* block for the sub-region, and then calls the dump function with it.
* This limits the amount of data visible to the sub-function to that
* for the sub-item.
*/
static void
print_subtype(note_state_t *state, const char *title,
const sl_field_t *fdesc, dump_func_t dump_func)
{
note_state_t sub_state;
/*
* If there is no data for the sub-item, return immediately.
* Partial data is left to the dump function to handle,
* as that can be a sign of an older core file with less data,
* which can still be interpreted.
*/
if (fdesc->slf_offset >= state->ns_len)
return;
/*
* Construct a state block that reflects the sub-item
*/
sub_state = *state;
sub_state.ns_data += fdesc->slf_offset;
sub_state.ns_len -= fdesc->slf_offset;
if (sub_state.ns_len > fdesc->slf_eltlen)
sub_state.ns_len = fdesc->slf_eltlen;
(* dump_func)(&sub_state, title);
}
/*
* Output a sequence of array elements, giving each
* element an index, in the format:
*
* [ndx] value
*
* entry:
* state - Current state
* base_desc - Field descriptor for 1st element of array
* nelts - # of array elements to display
* check_nelts - If True (1), nelts is clipped to fdesc->slf_nelts.
* If False (1), nelts is not clipped.
* title - Name of array
*/
static void
print_array(note_state_t *state, const sl_field_t *base_desc,
sl_fmt_num_t fmt_type, int nelts, int check_nelts, const char *title)
{
char index1[MAXNDXSIZE], index2[MAXNDXSIZE];
int i;
sl_field_t fdesc1, fdesc2;
if (check_nelts && (check_nelts > base_desc->slf_nelts))
nelts = base_desc->slf_nelts;
if (nelts == 0)
return;
indent_enter(state, title, base_desc);
fdesc1 = fdesc2 = *base_desc;
for (i = 0; i < nelts; ) {
if (i == (nelts - 1)) {
/* One final value is left */
if (!data_present(state, &fdesc1))
break;
(void) snprintf(index1, sizeof (index1),
MSG_ORIG(MSG_FMT_INDEX2), EC_WORD(i));
print_num(state, index1, &fdesc1, fmt_type);
fdesc1.slf_offset += fdesc1.slf_eltlen;
i++;
continue;
}
/* There are at least 2 items left. Show 2 up. */
fdesc2.slf_offset = fdesc1.slf_offset + fdesc1.slf_eltlen;
if (!(data_present(state, &fdesc1) &&
data_present(state, &fdesc2)))
break;
(void) snprintf(index1, sizeof (index1),
MSG_ORIG(MSG_FMT_INDEX2), EC_WORD(i));
(void) snprintf(index2, sizeof (index2),
MSG_ORIG(MSG_FMT_INDEX2), EC_WORD(i + 1));
print_num_2up(state, index1, &fdesc1, fmt_type,
index2, &fdesc2, fmt_type);
fdesc1.slf_offset += 2 * fdesc1.slf_eltlen;
i += 2;
}
indent_exit(state);
}
/*
* Output information from auxv_t structure.
*/
static void
dump_auxv(note_state_t *state, const char *title)
{
const sl_auxv_layout_t *layout = state->ns_arch->auxv;
union {
Conv_cap_val_hw1_buf_t hw1;
Conv_cap_val_hw2_buf_t hw2;
Conv_cap_val_hw3_buf_t hw3;
Conv_cnote_auxv_af_buf_t auxv_af;
Conv_ehdr_flags_buf_t ehdr_flags;
Conv_secflags_buf_t secflags;
Conv_inv_buf_t inv;
} conv_buf;
sl_fmtbuf_t buf;
int ndx, ndx_start;
Word sizeof_auxv;
sizeof_auxv = layout->sizeof_struct.slf_eltlen;
indent_enter(state, title, &layout->sizeof_struct);
/*
* Immediate indent_exit() restores the indent level to
* that of the title. We include indentation as part of
* the index string, which is right justified, and don't
* want the usual indentation spacing.
*/
indent_exit(state);
ndx = 0;
while (state->ns_len > sizeof_auxv) {
char index[(MAXNDXSIZE * 2) + 1];
sl_fmt_num_t num_fmt = SL_FMT_NUM_ZHEX;
const char *vstr = NULL;
Word w;
int type;
sl_field_t a_type_next;
type = extract_as_word(state, &layout->a_type);
ndx_start = ndx;
switch (type) {
case AT_NULL:
a_type_next = layout->a_type;
a_type_next.slf_offset += sizeof_auxv;
while ((state->ns_len - sizeof_auxv) >= sizeof_auxv) {
type = extract_as_word(state, &a_type_next);
if (type != AT_NULL)
break;
ndx++;
state->ns_data += sizeof_auxv;
state->ns_len -= sizeof_auxv;
}
num_fmt = SL_FMT_NUM_HEX;
break;
case AT_IGNORE:
case AT_SUN_IFLUSH:
num_fmt = SL_FMT_NUM_HEX;
break;
case AT_EXECFD:
case AT_PHENT:
case AT_PHNUM:
case AT_PAGESZ:
case AT_SUN_UID:
case AT_SUN_RUID:
case AT_SUN_GID:
case AT_SUN_RGID:
case AT_SUN_LPAGESZ:
case AT_SUN_FPSIZE:
case AT_SUN_FPTYPE:
num_fmt = SL_FMT_NUM_DEC;
break;
case AT_FLAGS: /* processor flags */
w = extract_as_word(state, &layout->a_val);
vstr = conv_ehdr_flags(state->ns_mach, w,
0, &conv_buf.ehdr_flags);
break;
case AT_SUN_HWCAP:
w = extract_as_word(state, &layout->a_val);
vstr = conv_cap_val_hw1(w, state->ns_mach,
0, &conv_buf.hw1);
/*
* conv_cap_val_hw1() produces output like:
*
* 0xfff [ flg1 flg2 0xff]
*
* where the first hex value is the complete value,
* and the second is the leftover bits. We only
* want the part in brackets, and failing that,
* would rather fall back to formatting the full
* value ourselves.
*/
while ((*vstr != '\0') && (*vstr != '['))
vstr++;
if (*vstr != '[')
vstr = NULL;
num_fmt = SL_FMT_NUM_HEX;
break;
case AT_SUN_HWCAP2:
w = extract_as_word(state, &layout->a_val);
vstr = conv_cap_val_hw2(w, state->ns_mach,
0, &conv_buf.hw2);
/*
* conv_cap_val_hw2() produces output like:
*
* 0xfff [ flg1 flg2 0xff]
*
* where the first hex value is the complete value,
* and the second is the leftover bits. We only
* want the part in brackets, and failing that,
* would rather fall back to formatting the full
* value ourselves.
*/
while ((*vstr != '\0') && (*vstr != '['))
vstr++;
if (*vstr != '[')
vstr = NULL;
num_fmt = SL_FMT_NUM_HEX;
break;
case AT_SUN_HWCAP3:
w = extract_as_word(state, &layout->a_val);
vstr = conv_cap_val_hw3(w, state->ns_mach,
0, &conv_buf.hw3);
/*
* conv_cap_val_hw3() produces output like:
*
* 0xfff [ flg1 flg2 0xff]
*
* where the first hex value is the complete value,
* and the second is the leftover bits. We only
* want the part in brackets, and failing that,
* would rather fall back to formatting the full
* value ourselves.
*/
while ((*vstr != '\0') && (*vstr != '['))
vstr++;
if (*vstr != '[')
vstr = NULL;
num_fmt = SL_FMT_NUM_HEX;
break;
case AT_SUN_AUXFLAGS:
w = extract_as_word(state, &layout->a_val);
vstr = conv_cnote_auxv_af(w, 0, &conv_buf.auxv_af);
num_fmt = SL_FMT_NUM_HEX;
break;
}
if (ndx == ndx_start)
(void) snprintf(index, sizeof (index),
MSG_ORIG(MSG_FMT_INDEX2), EC_WORD(ndx));
else
(void) snprintf(index, sizeof (index),
MSG_ORIG(MSG_FMT_INDEXRNG),
EC_WORD(ndx_start), EC_WORD(ndx));
if (vstr == NULL)
vstr = fmt_num(state, &layout->a_val, num_fmt, buf);
dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_AUXVLINE), INDENT, index,
state->ns_vcol - state->ns_indent,
conv_cnote_auxv_type(type, CONV_FMT_DECIMAL,
&conv_buf.inv), vstr);
state->ns_data += sizeof_auxv;
state->ns_len -= sizeof_auxv;
ndx++;
}
}
/*
* Output information from fltset_t structure.
*/
static void
dump_fltset(note_state_t *state, const char *title)
{
#define NELTS 4
const sl_fltset_layout_t *layout = state->ns_arch->fltset;
Conv_cnote_fltset_buf_t buf;
sl_field_t fdesc;
uint32_t mask[NELTS];
int i, nelts;
if (!data_present(state, &layout->sizeof_struct))
return;
fdesc = layout->word;
nelts = fdesc.slf_nelts;
if (nelts > NELTS) /* Type has grown? Show what we understand */
nelts = NELTS;
for (i = 0; i < nelts; i++) {
mask[i] = extract_as_word(state, &fdesc);
fdesc.slf_offset += fdesc.slf_eltlen;
}
print_str(state, title, conv_cnote_fltset(mask, nelts, 0, &buf));
#undef NELTS
}
/*
* Output information from sigset_t structure.
*/
static void
dump_sigset(note_state_t *state, const char *title)
{
#define NELTS 4
const sl_sigset_layout_t *layout = state->ns_arch->sigset;
Conv_cnote_sigset_buf_t buf;
sl_field_t fdesc;
uint32_t mask[NELTS];
int i, nelts;
if (!data_present(state, &layout->sizeof_struct))
return;
fdesc = layout->sigbits;
nelts = fdesc.slf_nelts;
if (nelts > NELTS) /* Type has grown? Show what we understand */
nelts = NELTS;
for (i = 0; i < nelts; i++) {
mask[i] = extract_as_word(state, &fdesc);
fdesc.slf_offset += fdesc.slf_eltlen;
}
print_str(state, title, conv_cnote_sigset(mask, nelts, 0, &buf));
#undef NELTS
}
/*
* Output information from sigaction structure.
*/
static void
dump_sigaction(note_state_t *state, const char *title)
{
const sl_sigaction_layout_t *layout = state->ns_arch->sigaction;
Conv_cnote_sa_flags_buf_t conv_buf;
Word w;
indent_enter(state, title, &layout->sa_flags);
if (data_present(state, &layout->sa_flags)) {
w = extract_as_word(state, &layout->sa_flags);
print_str(state, MSG_ORIG(MSG_CNOTE_T_SA_FLAGS),
conv_cnote_sa_flags(w, 0, &conv_buf));
}
PRINT_ZHEX_2UP(MSG_ORIG(MSG_CNOTE_T_SA_HANDLER), sa_hand,
MSG_ORIG(MSG_CNOTE_T_SA_SIGACTION), sa_sigact);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_SA_MASK), sa_mask, dump_sigset);
indent_exit(state);
}
/*
* Output information from siginfo structure.
*/
static void
dump_siginfo(note_state_t *state, const char *title)
{
const sl_siginfo_layout_t *layout = state->ns_arch->siginfo;
Conv_inv_buf_t inv_buf;
Word w;
int v_si_code, v_si_signo;
if (!data_present(state, &layout->sizeof_struct))
return;
indent_enter(state, title, &layout->f_si_signo);
v_si_signo = extract_as_sword(state, &layout->f_si_signo);
print_str(state, MSG_ORIG(MSG_CNOTE_T_SI_SIGNO),
conv_cnote_signal(v_si_signo, CONV_FMT_DECIMAL, &inv_buf));
w = extract_as_word(state, &layout->f_si_errno);
print_str(state, MSG_ORIG(MSG_CNOTE_T_SI_ERRNO),
conv_cnote_errno(w, CONV_FMT_DECIMAL, &inv_buf));
v_si_code = extract_as_sword(state, &layout->f_si_code);
print_str(state, MSG_ORIG(MSG_CNOTE_T_SI_CODE),
conv_cnote_si_code(state->ns_mach, v_si_signo, v_si_code,
CONV_FMT_DECIMAL, &inv_buf));
if ((v_si_signo == 0) || (v_si_code == SI_NOINFO)) {
indent_exit(state);
return;
}
/* User generated signals have (si_code <= 0) */
if (v_si_code <= 0) {
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_PID), f_si_pid);
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_UID), f_si_uid);
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_CTID), f_si_ctid);
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_ZONEID), f_si_zoneid);
switch (v_si_code) {
case SI_QUEUE:
case SI_TIMER:
case SI_ASYNCIO:
case SI_MESGQ:
indent_enter(state, MSG_ORIG(MSG_CNOTE_T_SI_VALUE),
&layout->f_si_value_int);
PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_SIVAL_INT),
f_si_value_int);
PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_SIVAL_PTR),
f_si_value_ptr);
indent_exit(state);
break;
}
indent_exit(state);
return;
}
/*
* Remaining cases are kernel generated signals. Output any
* signal or code specific information.
*/
if (v_si_code == SI_RCTL)
PRINT_HEX(MSG_ORIG(MSG_CNOTE_T_SI_ENTITY), f_si_entity);
switch (v_si_signo) {
case SIGILL:
case SIGFPE:
case SIGSEGV:
case SIGBUS:
PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_SI_ADDR), f_si_addr);
break;
case SIGCHLD:
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_PID), f_si_pid);
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_STATUS), f_si_status);
break;
case SIGPOLL:
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_BAND), f_si_band);
break;
}
indent_exit(state);
}
/*
* Output information from stack_t structure.
*/
static void
dump_stack(note_state_t *state, const char *title)
{
const sl_stack_layout_t *layout = state->ns_arch->stack;
Conv_cnote_ss_flags_buf_t conv_buf;
Word w;
indent_enter(state, title, &layout->ss_size);
print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_SS_SP), &layout->ss_sp,
SL_FMT_NUM_ZHEX, MSG_ORIG(MSG_CNOTE_T_SS_SIZE), &layout->ss_size,
SL_FMT_NUM_HEX);
if (data_present(state, &layout->ss_flags)) {
w = extract_as_word(state, &layout->ss_flags);
print_str(state, MSG_ORIG(MSG_CNOTE_T_SS_FLAGS),
conv_cnote_ss_flags(w, 0, &conv_buf));
}
indent_exit(state);
}
/*
* Output information from sysset_t structure.
*/
static void
dump_sysset(note_state_t *state, const char *title)
{
#define NELTS 16
const sl_sysset_layout_t *layout = state->ns_arch->sysset;
Conv_cnote_sysset_buf_t buf;
sl_field_t fdesc;
uint32_t mask[NELTS];
int i, nelts;
if (!data_present(state, &layout->sizeof_struct))
return;
fdesc = layout->word;
nelts = fdesc.slf_nelts;
if (nelts > NELTS) /* Type has grown? Show what we understand */
nelts = NELTS;
for (i = 0; i < nelts; i++) {
mask[i] = extract_as_word(state, &fdesc);
fdesc.slf_offset += fdesc.slf_eltlen;
}
print_str(state, title, conv_cnote_sysset(mask, nelts, 0, &buf));
#undef NELTS
}
/*
* Output information from timestruc_t structure.
*/
static void
dump_timestruc(note_state_t *state, const char *title)
{
const sl_timestruc_layout_t *layout = state->ns_arch->timestruc;
indent_enter(state, title, &layout->tv_sec);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_TV_SEC), tv_sec,
MSG_ORIG(MSG_CNOTE_T_TV_NSEC), tv_nsec);
indent_exit(state);
}
/*
* Output information from prsecflags_t structure.
*/
static void
dump_secflags(note_state_t *state, const char *title)
{
const sl_prsecflags_layout_t *layout = state->ns_arch->prsecflags;
Conv_secflags_buf_t inv;
Lword lw;
Word w;
indent_enter(state, title, &layout->pr_version);
w = extract_as_word(state, &layout->pr_version);
if (w != PRSECFLAGS_VERSION_1) {
PRINT_DEC(MSG_INTL(MSG_NOTE_BAD_SECFLAGS_VER), pr_version);
dump_hex_bytes(state->ns_data, state->ns_len, state->ns_indent,
4, 3);
} else {
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_VERSION), pr_version);
lw = extract_as_lword(state, &layout->pr_effective);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_EFFECTIVE),
conv_prsecflags(lw, 0, &inv));
lw = extract_as_lword(state, &layout->pr_inherit);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_INHERIT),
conv_prsecflags(lw, 0, &inv));
lw = extract_as_lword(state, &layout->pr_lower);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_LOWER),
conv_prsecflags(lw, 0, &inv));
lw = extract_as_lword(state, &layout->pr_upper);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_UPPER),
conv_prsecflags(lw, 0, &inv));
}
indent_exit(state);
}
/*
* Output information from utsname structure.
*/
static void
dump_utsname(note_state_t *state, const char *title)
{
const sl_utsname_layout_t *layout = state->ns_arch->utsname;
indent_enter(state, title, &layout->sysname);
PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_UTS_SYSNAME), sysname);
PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_UTS_NODENAME), nodename);
PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_UTS_RELEASE), release);
PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_UTS_VERSION), version);
PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_UTS_MACHINE), machine);
indent_exit(state);
}
/*
* Dump register contents
*/
static void
dump_prgregset(note_state_t *state, const char *title)
{
sl_field_t fdesc1, fdesc2;
sl_fmtbuf_t buf1, buf2;
Conv_inv_buf_t inv_buf1, inv_buf2;
Word w;
fdesc1 = fdesc2 = state->ns_arch->prgregset->elt0;
indent_enter(state, title, &fdesc1);
for (w = 0; w < fdesc1.slf_nelts; ) {
if (w == (fdesc1.slf_nelts - 1)) {
/* One last register is left */
if (!data_present(state, &fdesc1))
break;
dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE),
INDENT, state->ns_vcol - state->ns_indent,
conv_cnote_pr_regname(state->ns_mach, w,
CONV_FMT_DECIMAL, &inv_buf1),
fmt_num(state, &fdesc1, SL_FMT_NUM_ZHEX, buf1));
fdesc1.slf_offset += fdesc1.slf_eltlen;
w++;
continue;
}
/* There are at least 2 more registers left. Show 2 up */
fdesc2.slf_offset = fdesc1.slf_offset + fdesc1.slf_eltlen;
if (!(data_present(state, &fdesc1) &&
data_present(state, &fdesc2)))
break;
dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
state->ns_vcol - state->ns_indent,
conv_cnote_pr_regname(state->ns_mach, w,
CONV_FMT_DECIMAL, &inv_buf1),
state->ns_t2col - state->ns_vcol,
fmt_num(state, &fdesc1, SL_FMT_NUM_ZHEX, buf1),
state->ns_v2col - state->ns_t2col,
conv_cnote_pr_regname(state->ns_mach, w + 1,
CONV_FMT_DECIMAL, &inv_buf2),
fmt_num(state, &fdesc2, SL_FMT_NUM_ZHEX, buf2));
fdesc1.slf_offset += 2 * fdesc1.slf_eltlen;
w += 2;
}
indent_exit(state);
}
/*
* Output information from lwpstatus_t structure.
*/
static void
dump_lwpstatus(note_state_t *state, const char *title)
{
const sl_lwpstatus_layout_t *layout = state->ns_arch->lwpstatus;
Word w, w2;
int32_t i;
union {
Conv_inv_buf_t inv;
Conv_cnote_pr_flags_buf_t flags;
} conv_buf;
indent_enter(state, title, &layout->pr_flags);
if (data_present(state, &layout->pr_flags)) {
w = extract_as_word(state, &layout->pr_flags);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAGS),
conv_cnote_pr_flags(w, 0, &conv_buf.flags));
}
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_LWPID), pr_lwpid);
if (data_present(state, &layout->pr_why)) {
w = extract_as_word(state, &layout->pr_why);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_WHY),
conv_cnote_pr_why(w, 0, &conv_buf.inv));
if (data_present(state, &layout->pr_what)) {
w2 = extract_as_word(state, &layout->pr_what);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_WHAT),
conv_cnote_pr_what(w, w2, 0, &conv_buf.inv));
}
}
if (data_present(state, &layout->pr_cursig)) {
w = extract_as_word(state, &layout->pr_cursig);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_CURSIG),
conv_cnote_signal(w, CONV_FMT_DECIMAL, &conv_buf.inv));
}
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_INFO), pr_info, dump_siginfo);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_LWPPEND), pr_lwppend,
dump_sigset);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_LWPHOLD), pr_lwphold,
dump_sigset);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_ACTION), pr_action,
dump_sigaction);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_ALTSTACK), pr_altstack,
dump_stack);
PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_PR_OLDCONTEXT), pr_oldcontext);
if (data_present(state, &layout->pr_syscall)) {
w = extract_as_word(state, &layout->pr_syscall);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_SYSCALL),
conv_cnote_syscall(w, CONV_FMT_DECIMAL, &conv_buf.inv));
}
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NSYSARG), pr_nsysarg);
if (data_present(state, &layout->pr_errno)) {
w = extract_as_word(state, &layout->pr_errno);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_ERRNO),
conv_cnote_errno(w, CONV_FMT_DECIMAL, &conv_buf.inv));
}
if (data_present(state, &layout->pr_nsysarg)) {
w2 = extract_as_word(state, &layout->pr_nsysarg);
print_array(state, &layout->pr_sysarg, SL_FMT_NUM_ZHEX, w2, 1,
MSG_ORIG(MSG_CNOTE_T_PR_SYSARG));
}
PRINT_HEX_2UP(MSG_ORIG(MSG_CNOTE_T_PR_RVAL1), pr_rval1,
MSG_ORIG(MSG_CNOTE_T_PR_RVAL2), pr_rval2);
PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_CLNAME), pr_clname);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_TSTAMP), pr_tstamp,
dump_timestruc);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_UTIME), pr_utime, dump_timestruc);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_STIME), pr_stime, dump_timestruc);
if (data_present(state, &layout->pr_errpriv)) {
i = extract_as_sword(state, &layout->pr_errpriv);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_ERRPRIV),
conv_cnote_priv(i, CONV_FMT_DECIMAL, &conv_buf.inv));
}
PRINT_ZHEX_2UP(MSG_ORIG(MSG_CNOTE_T_PR_USTACK), pr_ustack,
MSG_ORIG(MSG_CNOTE_T_PR_INSTR), pr_instr);
/*
* In order to line up all the values in a single column,
* we would have to set vcol to a very high value, which results
* in ugly looking output that runs off column 80. So, we use
* two levels of vcol, one for the contents so far, and a
* higher one for the pr_reg sub-struct.
*/
state->ns_vcol += 3;
state->ns_t2col += 3;
state->ns_v2col += 2;
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_REG), pr_reg, dump_prgregset);
state->ns_vcol -= 3;
state->ns_t2col -= 3;
state->ns_v2col -= 2;
/*
* The floating point register state is complex, and highly
* platform dependent. For now, we simply display it as
* a hex dump. This can be replaced if better information
* is required.
*/
if (data_present(state, &layout->pr_fpreg)) {
indent_enter(state, MSG_ORIG(MSG_CNOTE_T_PR_FPREG),
&layout->pr_fpreg);
dump_hex_bytes(layout->pr_fpreg.slf_offset + state->ns_data,
layout->pr_fpreg.slf_eltlen, state->ns_indent, 4, 3);
indent_exit(state);
}
indent_exit(state);
}
/*
* Output information from pstatus_t structure.
*/
static void
dump_pstatus(note_state_t *state, const char *title)
{
const sl_pstatus_layout_t *layout = state->ns_arch->pstatus;
Word w;
union {
Conv_inv_buf_t inv;
Conv_cnote_pr_flags_buf_t flags;
} conv_buf;
indent_enter(state, title, &layout->pr_flags);
if (data_present(state, &layout->pr_flags)) {
w = extract_as_word(state, &layout->pr_flags);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAGS),
conv_cnote_pr_flags(w, 0, &conv_buf.flags));
}
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NLWP), pr_nlwp);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PID), pr_pid,
MSG_ORIG(MSG_CNOTE_T_PR_PPID), pr_ppid);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PGID), pr_pgid,
MSG_ORIG(MSG_CNOTE_T_PR_SID), pr_sid);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_ASLWPID), pr_aslwpid,
MSG_ORIG(MSG_CNOTE_T_PR_AGENTID), pr_agentid);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SIGPEND), pr_sigpend,
dump_sigset);
print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_BRKBASE),
&layout->pr_brkbase, SL_FMT_NUM_ZHEX,
MSG_ORIG(MSG_CNOTE_T_PR_BRKSIZE),
&layout->pr_brksize, SL_FMT_NUM_HEX);
print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_STKBASE),
&layout->pr_stkbase, SL_FMT_NUM_ZHEX,
MSG_ORIG(MSG_CNOTE_T_PR_STKSIZE),
&layout->pr_stksize, SL_FMT_NUM_HEX);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_UTIME), pr_utime, dump_timestruc);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_STIME), pr_stime, dump_timestruc);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CUTIME), pr_cutime,
dump_timestruc);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CSTIME), pr_cstime,
dump_timestruc);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SIGTRACE), pr_sigtrace,
dump_sigset);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_FLTTRACE), pr_flttrace,
dump_fltset);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SYSENTRY), pr_sysentry,
dump_sysset);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SYSEXIT), pr_sysexit,
dump_sysset);
if (data_present(state, &layout->pr_dmodel)) {
w = extract_as_word(state, &layout->pr_dmodel);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_DMODEL),
conv_cnote_pr_dmodel(w, 0, &conv_buf.inv));
}
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_TASKID), pr_taskid,
MSG_ORIG(MSG_CNOTE_T_PR_PROJID), pr_projid);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_NZOMB), pr_nzomb,
MSG_ORIG(MSG_CNOTE_T_PR_ZONEID), pr_zoneid);
/*
* In order to line up all the values in a single column,
* we would have to set vcol to a very high value, which results
* in ugly looking output that runs off column 80. So, we use
* two levels of vcol, one for the contents so far, and a
* higher one for the pr_lwp sub-struct.
*/
state->ns_vcol += 5;
state->ns_t2col += 5;
state->ns_v2col += 5;
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_LWP), pr_lwp, dump_lwpstatus);
state->ns_vcol -= 5;
state->ns_t2col -= 5;
state->ns_v2col -= 5;
indent_exit(state);
}
/*
* Output information from prstatus_t (<sys/old_procfs.h>) structure.
*/
static void
dump_prstatus(note_state_t *state, const char *title)
{
const sl_prstatus_layout_t *layout = state->ns_arch->prstatus;
Word w, w2;
int i;
union {
Conv_inv_buf_t inv;
Conv_cnote_old_pr_flags_buf_t flags;
} conv_buf;
indent_enter(state, title, &layout->pr_flags);
if (data_present(state, &layout->pr_flags)) {
w = extract_as_word(state, &layout->pr_flags);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAGS),
conv_cnote_old_pr_flags(w, 0, &conv_buf.flags));
}
if (data_present(state, &layout->pr_why)) {
w = extract_as_word(state, &layout->pr_why);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_WHY),
conv_cnote_pr_why(w, 0, &conv_buf.inv));
if (data_present(state, &layout->pr_what)) {
w2 = extract_as_word(state, &layout->pr_what);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_WHAT),
conv_cnote_pr_what(w, w2, 0, &conv_buf.inv));
}
}
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_INFO), pr_info, dump_siginfo);
if (data_present(state, &layout->pr_cursig)) {
w = extract_as_word(state, &layout->pr_cursig);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_CURSIG),
conv_cnote_signal(w, CONV_FMT_DECIMAL, &conv_buf.inv));
}
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NLWP), pr_nlwp);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SIGPEND), pr_sigpend,
dump_sigset);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SIGHOLD), pr_sighold,
dump_sigset);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_ALTSTACK), pr_altstack,
dump_stack);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_ACTION), pr_action,
dump_sigaction);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PID), pr_pid,
MSG_ORIG(MSG_CNOTE_T_PR_PPID), pr_ppid);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PGRP), pr_pgrp,
MSG_ORIG(MSG_CNOTE_T_PR_SID), pr_sid);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_UTIME), pr_utime, dump_timestruc);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_STIME), pr_stime, dump_timestruc);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CUTIME), pr_cutime,
dump_timestruc);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CSTIME), pr_cstime,
dump_timestruc);
PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_CLNAME), pr_clname);
if (data_present(state, &layout->pr_syscall)) {
w = extract_as_word(state, &layout->pr_syscall);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_SYSCALL),
conv_cnote_syscall(w, CONV_FMT_DECIMAL, &conv_buf.inv));
}
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NSYSARG), pr_nsysarg);
if (data_present(state, &layout->pr_nsysarg)) {
w2 = extract_as_word(state, &layout->pr_nsysarg);
print_array(state, &layout->pr_sysarg, SL_FMT_NUM_ZHEX, w2, 1,
MSG_ORIG(MSG_CNOTE_T_PR_SYSARG));
}
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_WHO), pr_who);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_LWPPEND), pr_sigpend,
dump_sigset);
PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_PR_OLDCONTEXT), pr_oldcontext);
print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_BRKBASE),
&layout->pr_brkbase, SL_FMT_NUM_ZHEX,
MSG_ORIG(MSG_CNOTE_T_PR_BRKSIZE),
&layout->pr_brksize, SL_FMT_NUM_HEX);
print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_STKBASE),
&layout->pr_stkbase, SL_FMT_NUM_ZHEX,
MSG_ORIG(MSG_CNOTE_T_PR_STKSIZE),
&layout->pr_stksize, SL_FMT_NUM_HEX);
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_PROCESSOR), pr_processor);
if (data_present(state, &layout->pr_bind)) {
i = extract_as_sword(state, &layout->pr_bind);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_BIND),
conv_cnote_psetid(i, CONV_FMT_DECIMAL, &conv_buf.inv));
}
PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_PR_INSTR), pr_instr);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_REG), pr_reg, dump_prgregset);
indent_exit(state);
}
static void
dump_lwpname(note_state_t *state, const char *title)
{
const sl_prlwpname_layout_t *layout = state->ns_arch->prlwpname;
indent_enter(state, title, &layout->pr_lwpid);
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_LWPID), pr_lwpid);
PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_LWPNAME), pr_lwpname);
indent_exit(state);
}
/*
* Print percent from 16-bit binary fraction [0 .. 1]
* Round up .01 to .1 to indicate some small percentage (the 0x7000 below).
*
* Note: This routine was copied from ps(1) and then modified.
*/
static const char *
prtpct_value(note_state_t *state, const sl_field_t *fdesc,
sl_fmtbuf_t buf)
{
uint_t value; /* need 32 bits to compute with */
value = extract_as_word(state, fdesc);
value = ((value * 1000) + 0x7000) >> 15; /* [0 .. 1000] */
if (value >= 1000)
value = 999;
(void) snprintf(buf, sizeof (sl_fmtbuf_t),
MSG_ORIG(MSG_CNOTE_FMT_PRTPCT), value / 10, value % 10);
return (buf);
}
/*
* Version of prtpct() used for a 2-up display of two adjacent percentages.
*/
static void
prtpct_2up(note_state_t *state, const sl_field_t *fdesc1,
const char *title1, const sl_field_t *fdesc2, const char *title2)
{
sl_fmtbuf_t buf1, buf2;
if (!(data_present(state, fdesc1) &&
data_present(state, fdesc2)))
return;
dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
state->ns_vcol - state->ns_indent, title1,
state->ns_t2col - state->ns_vcol,
prtpct_value(state, fdesc1, buf1),
state->ns_v2col - state->ns_t2col, title2,
prtpct_value(state, fdesc2, buf2));
}
/*
* The psinfo_t and prpsinfo_t structs have pr_state and pr_sname
* fields that we wish to print in a 2up format. The pr_state is
* an integer, while pr_sname is a single character.
*/
static void
print_state_sname_2up(note_state_t *state,
const sl_field_t *state_fdesc,
const sl_field_t *sname_fdesc)
{
sl_fmtbuf_t buf1, buf2;
int sname;
/*
* If the field slf_offset and extent fall past the end of the
* available data, then return without doing anything. That note
* is from an older core file that doesn't have all the fields
* that we know about.
*/
if (!(data_present(state, state_fdesc) &&
data_present(state, sname_fdesc)))
return;
sname = extract_as_sword(state, sname_fdesc);
buf2[0] = sname;
buf2[1] = '\0';
dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
state->ns_vcol - state->ns_indent, MSG_ORIG(MSG_CNOTE_T_PR_STATE),
state->ns_t2col - state->ns_vcol,
fmt_num(state, state_fdesc, SL_FMT_NUM_DEC, buf1),
state->ns_v2col - state->ns_t2col, MSG_ORIG(MSG_CNOTE_T_PR_SNAME),
buf2);
}
/*
* Output information from lwpsinfo_t structure.
*/
static void
dump_lwpsinfo(note_state_t *state, const char *title)
{
const sl_lwpsinfo_layout_t *layout = state->ns_arch->lwpsinfo;
Word w;
int32_t i;
union {
Conv_cnote_proc_flag_buf_t proc_flag;
Conv_inv_buf_t inv;
} conv_buf;
indent_enter(state, title, &layout->pr_flag);
if (data_present(state, &layout->pr_flag)) {
w = extract_as_word(state, &layout->pr_flag);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAG),
conv_cnote_proc_flag(w, 0, &conv_buf.proc_flag));
}
print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_LWPID), &layout->pr_lwpid,
SL_FMT_NUM_DEC, MSG_ORIG(MSG_CNOTE_T_PR_ADDR), &layout->pr_addr,
SL_FMT_NUM_ZHEX);
PRINT_HEX(MSG_ORIG(MSG_CNOTE_T_PR_WCHAN), pr_wchan);
if (data_present(state, &layout->pr_stype)) {
w = extract_as_word(state, &layout->pr_stype);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_STYPE),
conv_cnote_pr_stype(w, CONV_FMT_DECIMAL, &conv_buf.inv));
}
print_state_sname_2up(state, &layout->pr_state, &layout->pr_sname);
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NICE), pr_nice);
if (data_present(state, &layout->pr_syscall)) {
w = extract_as_word(state, &layout->pr_syscall);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_SYSCALL),
conv_cnote_syscall(w, CONV_FMT_DECIMAL, &conv_buf.inv));
}
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_OLDPRI), pr_oldpri,
MSG_ORIG(MSG_CNOTE_T_PR_CPU), pr_cpu);
if (data_present(state, &layout->pr_pri) &&
data_present(state, &layout->pr_pctcpu)) {
sl_fmtbuf_t buf1, buf2;
dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
state->ns_vcol - state->ns_indent,
MSG_ORIG(MSG_CNOTE_T_PR_PRI),
state->ns_t2col - state->ns_vcol,
fmt_num(state, &layout->pr_pri, SL_FMT_NUM_DEC, buf1),
state->ns_v2col - state->ns_t2col,
MSG_ORIG(MSG_CNOTE_T_PR_PCTCPU),
prtpct_value(state, &layout->pr_pctcpu, buf2));
}
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_START), pr_start, dump_timestruc);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_TIME), pr_time, dump_timestruc);
PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_CLNAME), pr_clname);
PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_NAME), pr_name);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_ONPRO), pr_onpro,
MSG_ORIG(MSG_CNOTE_T_PR_BINDPRO), pr_bindpro);
if (data_present(state, &layout->pr_bindpset)) {
i = extract_as_sword(state, &layout->pr_bindpset);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_BINDPSET),
conv_cnote_psetid(i, CONV_FMT_DECIMAL, &conv_buf.inv));
}
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_LGRP), pr_lgrp);
indent_exit(state);
}
/*
* Output information from psinfo_t structure.
*/
static void
dump_psinfo(note_state_t *state, const char *title)
{
const sl_psinfo_layout_t *layout = state->ns_arch->psinfo;
Word w;
union {
Conv_cnote_proc_flag_buf_t proc_flag;
Conv_inv_buf_t inv;
} conv_buf;
indent_enter(state, title, &layout->pr_flag);
if (data_present(state, &layout->pr_flag)) {
w = extract_as_word(state, &layout->pr_flag);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAG),
conv_cnote_proc_flag(w, 0, &conv_buf.proc_flag));
}
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NLWP), pr_nlwp);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PID), pr_pid,
MSG_ORIG(MSG_CNOTE_T_PR_PPID), pr_ppid);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PGID), pr_pgid,
MSG_ORIG(MSG_CNOTE_T_PR_SID), pr_sid);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_UID), pr_uid,
MSG_ORIG(MSG_CNOTE_T_PR_EUID), pr_euid);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_GID), pr_gid,
MSG_ORIG(MSG_CNOTE_T_PR_EGID), pr_egid);
print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_ADDR), &layout->pr_addr,
SL_FMT_NUM_ZHEX, MSG_ORIG(MSG_CNOTE_T_PR_SIZE), &layout->pr_size,
SL_FMT_NUM_HEX);
print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_RSSIZE),
&layout->pr_rssize, SL_FMT_NUM_HEX, MSG_ORIG(MSG_CNOTE_T_PR_TTYDEV),
&layout->pr_ttydev, SL_FMT_NUM_DEC);
prtpct_2up(state, &layout->pr_pctcpu, MSG_ORIG(MSG_CNOTE_T_PR_PCTCPU),
&layout->pr_pctmem, MSG_ORIG(MSG_CNOTE_T_PR_PCTMEM));
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_START), pr_start, dump_timestruc);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_TIME), pr_time, dump_timestruc);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CTIME), pr_ctime, dump_timestruc);
PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_FNAME), pr_fname);
PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_PSARGS), pr_psargs);
print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_WSTAT), &layout->pr_wstat,
SL_FMT_NUM_HEX, MSG_ORIG(MSG_CNOTE_T_PR_ARGC), &layout->pr_argc,
SL_FMT_NUM_DEC);
PRINT_ZHEX_2UP(MSG_ORIG(MSG_CNOTE_T_PR_ARGV), pr_argv,
MSG_ORIG(MSG_CNOTE_T_PR_ENVP), pr_envp);
if (data_present(state, &layout->pr_dmodel)) {
w = extract_as_word(state, &layout->pr_dmodel);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_DMODEL),
conv_cnote_pr_dmodel(w, 0, &conv_buf.inv));
}
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_TASKID), pr_taskid,
MSG_ORIG(MSG_CNOTE_T_PR_PROJID), pr_projid);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_NZOMB), pr_nzomb,
MSG_ORIG(MSG_CNOTE_T_PR_POOLID), pr_poolid);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_ZONEID), pr_zoneid,
MSG_ORIG(MSG_CNOTE_T_PR_CONTRACT), pr_contract);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_LWP), pr_lwp, dump_lwpsinfo);
indent_exit(state);
}
/*
* Output information from prpsinfo_t structure.
*/
static void
dump_prpsinfo(note_state_t *state, const char *title)
{
const sl_prpsinfo_layout_t *layout = state->ns_arch->prpsinfo;
Word w;
union {
Conv_cnote_proc_flag_buf_t proc_flag;
Conv_inv_buf_t inv;
} conv_buf;
indent_enter(state, title, &layout->pr_state);
print_state_sname_2up(state, &layout->pr_state, &layout->pr_sname);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_ZOMB), pr_zomb,
MSG_ORIG(MSG_CNOTE_T_PR_NICE), pr_nice);
if (data_present(state, &layout->pr_flag)) {
w = extract_as_word(state, &layout->pr_flag);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAG),
conv_cnote_proc_flag(w, 0, &conv_buf.proc_flag));
}
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_UID), pr_uid,
MSG_ORIG(MSG_CNOTE_T_PR_GID), pr_gid);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PID), pr_pid,
MSG_ORIG(MSG_CNOTE_T_PR_PPID), pr_ppid);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PGRP), pr_pgrp,
MSG_ORIG(MSG_CNOTE_T_PR_SID), pr_sid);
print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_ADDR), &layout->pr_addr,
SL_FMT_NUM_ZHEX, MSG_ORIG(MSG_CNOTE_T_PR_SIZE), &layout->pr_size,
SL_FMT_NUM_HEX);
PRINT_HEX_2UP(MSG_ORIG(MSG_CNOTE_T_PR_RSSIZE), pr_rssize,
MSG_ORIG(MSG_CNOTE_T_PR_WCHAN), pr_wchan);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_START), pr_start, dump_timestruc);
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_TIME), pr_time, dump_timestruc);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PRI), pr_pri,
MSG_ORIG(MSG_CNOTE_T_PR_OLDPRI), pr_oldpri);
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_CPU), pr_cpu);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_OTTYDEV), pr_ottydev,
MSG_ORIG(MSG_CNOTE_T_PR_LTTYDEV), pr_lttydev);
PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_CLNAME), pr_clname);
PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_FNAME), pr_fname);
PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_PSARGS), pr_psargs);
if (data_present(state, &layout->pr_syscall)) {
w = extract_as_word(state, &layout->pr_syscall);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_SYSCALL),
conv_cnote_syscall(w, CONV_FMT_DECIMAL, &conv_buf.inv));
}
PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CTIME), pr_ctime, dump_timestruc);
PRINT_HEX_2UP(MSG_ORIG(MSG_CNOTE_T_PR_BYSIZE), pr_bysize,
MSG_ORIG(MSG_CNOTE_T_PR_BYRSSIZE), pr_byrssize);
print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_ARGC), &layout->pr_argc,
SL_FMT_NUM_DEC, MSG_ORIG(MSG_CNOTE_T_PR_ARGV), &layout->pr_argv,
SL_FMT_NUM_ZHEX);
print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_ENVP), &layout->pr_envp,
SL_FMT_NUM_ZHEX, MSG_ORIG(MSG_CNOTE_T_PR_WSTAT), &layout->pr_wstat,
SL_FMT_NUM_HEX);
prtpct_2up(state, &layout->pr_pctcpu, MSG_ORIG(MSG_CNOTE_T_PR_PCTCPU),
&layout->pr_pctmem, MSG_ORIG(MSG_CNOTE_T_PR_PCTMEM));
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_EUID), pr_euid,
MSG_ORIG(MSG_CNOTE_T_PR_EGID), pr_egid);
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_ASLWPID), pr_aslwpid);
if (data_present(state, &layout->pr_dmodel)) {
w = extract_as_word(state, &layout->pr_dmodel);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_DMODEL),
conv_cnote_pr_dmodel(w, 0, &conv_buf.inv));
}
indent_exit(state);
}
/*
* Output information from prcred_t structure.
*/
static void
dump_prcred(note_state_t *state, const char *title)
{
const sl_prcred_layout_t *layout = state->ns_arch->prcred;
Word ngroups;
indent_enter(state, title, &layout->pr_euid);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_EUID), pr_euid,
MSG_ORIG(MSG_CNOTE_T_PR_RUID), pr_ruid);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_SUID), pr_suid,
MSG_ORIG(MSG_CNOTE_T_PR_EGID), pr_egid);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_RGID), pr_rgid,
MSG_ORIG(MSG_CNOTE_T_PR_SGID), pr_sgid);
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NGROUPS), pr_ngroups);
if (data_present(state, &layout->pr_ngroups)) {
ngroups = extract_as_word(state, &layout->pr_ngroups);
print_array(state, &layout->pr_groups, SL_FMT_NUM_DEC, ngroups,
0, MSG_ORIG(MSG_CNOTE_T_PR_GROUPS));
}
indent_exit(state);
}
/*
* Output information from prpriv_t structure.
*/
static void
dump_prpriv(note_state_t *state, const char *title)
{
const sl_prpriv_layout_t *layout = state->ns_arch->prpriv;
Word nsets;
indent_enter(state, title, &layout->pr_nsets);
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NSETS), pr_nsets);
PRINT_HEX(MSG_ORIG(MSG_CNOTE_T_PR_SETSIZE), pr_setsize);
PRINT_HEX(MSG_ORIG(MSG_CNOTE_T_PR_INFOSIZE), pr_infosize);
if (data_present(state, &layout->pr_nsets)) {
nsets = extract_as_word(state, &layout->pr_nsets);
print_array(state, &layout->pr_sets, SL_FMT_NUM_ZHEX, nsets,
0, MSG_ORIG(MSG_CNOTE_T_PR_SETS));
}
indent_exit(state);
}
static void
dump_prfdinfo(note_state_t *state, const char *title)
{
const sl_prfdinfo_layout_t *layout = state->ns_arch->prfdinfo;
char buf[1024];
uint32_t fileflags, mode, fdflags;
indent_enter(state, title, &layout->pr_fd);
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_FD), pr_fd);
mode = extract_as_word(state, &layout->pr_mode);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_MODE),
conv_cnote_filemode(mode, 0, buf, sizeof (buf)));
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_UID), pr_uid,
MSG_ORIG(MSG_CNOTE_T_PR_GID), pr_gid);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_MAJOR), pr_major,
MSG_ORIG(MSG_CNOTE_T_PR_MINOR), pr_minor);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_RMAJOR), pr_rmajor,
MSG_ORIG(MSG_CNOTE_T_PR_RMINOR), pr_rminor);
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_INO), pr_ino);
PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_SIZE), pr_size,
MSG_ORIG(MSG_CNOTE_T_PR_OFFSET), pr_offset);
fileflags = extract_as_word(state, &layout->pr_fileflags);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FILEFLAGS),
conv_cnote_fileflags(fileflags, 0, buf, sizeof (buf)));
fdflags = extract_as_word(state, &layout->pr_fdflags);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FDFLAGS),
conv_cnote_fdflags(fdflags, 0, buf, sizeof (buf)));
PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_PATH), pr_path);
indent_exit(state);
}
/*
* Output information from priv_impl_info_t structure.
*/
static void
dump_priv_impl_info(note_state_t *state, const char *title)
{
const sl_priv_impl_info_layout_t *layout;
layout = state->ns_arch->priv_impl_info;
indent_enter(state, title, &layout->priv_headersize);
PRINT_HEX_2UP(MSG_ORIG(MSG_CNOTE_T_PRIV_HEADERSIZE), priv_headersize,
MSG_ORIG(MSG_CNOTE_T_PRIV_FLAGS), priv_flags);
print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PRIV_NSETS),
&layout->priv_nsets, SL_FMT_NUM_DEC,
MSG_ORIG(MSG_CNOTE_T_PRIV_SETSIZE), &layout->priv_setsize,
SL_FMT_NUM_HEX);
print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PRIV_MAX), &layout->priv_max,
SL_FMT_NUM_DEC, MSG_ORIG(MSG_CNOTE_T_PRIV_INFOSIZE),
&layout->priv_infosize, SL_FMT_NUM_HEX);
PRINT_HEX(MSG_ORIG(MSG_CNOTE_T_PRIV_GLOBALINFOSIZE),
priv_globalinfosize);
indent_exit(state);
}
/*
* Dump information from an asrset_t array. This data
* structure is specific to sparcv9, and does not appear
* on any other platform.
*
* asrset_t is a simple array, defined in <sys/regset.h> as
* typedef int64_t asrset_t[16]; %asr16 - > %asr31
*
* As such, we do not make use of the struct_layout facilities
* for this routine.
*/
static void
dump_asrset(note_state_t *state, const char *title)
{
static const sl_field_t ftemplate = { 0, sizeof (int64_t), 16, 0 };
sl_field_t fdesc1, fdesc2;
sl_fmtbuf_t buf1, buf2;
char index1[MAXNDXSIZE * 2], index2[MAXNDXSIZE * 2];
Word w, nelts;
fdesc1 = fdesc2 = ftemplate;
/* We expect 16 values, but will print whatever is actually there */
nelts = state->ns_len / ftemplate.slf_eltlen;
if (nelts == 0)
return;
indent_enter(state, title, &fdesc1);
for (w = 0; w < nelts; ) {
(void) snprintf(index1, sizeof (index1),
MSG_ORIG(MSG_FMT_ASRINDEX), w + 16);
if (w == (nelts - 1)) {
/* One last register is left */
dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE),
INDENT, state->ns_vcol - state->ns_indent, index1,
fmt_num(state, &fdesc1, SL_FMT_NUM_ZHEX, buf1));
fdesc1.slf_offset += fdesc1.slf_eltlen;
w++;
continue;
}
/* There are at least 2 more registers left. Show 2 up */
(void) snprintf(index2, sizeof (index2),
MSG_ORIG(MSG_FMT_ASRINDEX), w + 17);
fdesc2.slf_offset = fdesc1.slf_offset + fdesc1.slf_eltlen;
dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
state->ns_vcol - state->ns_indent, index1,
state->ns_t2col - state->ns_vcol,
fmt_num(state, &fdesc1, SL_FMT_NUM_ZHEX, buf1),
state->ns_v2col - state->ns_t2col, index2,
fmt_num(state, &fdesc2, SL_FMT_NUM_ZHEX, buf2));
fdesc1.slf_offset += 2 * fdesc1.slf_eltlen;
w += 2;
}
indent_exit(state);
}
static void
dump_upanic(note_state_t *state, const char *title)
{
const sl_prupanic_layout_t *layout = state->ns_arch->prupanic;
Conv_upanic_buf_t inv;
Word w;
indent_enter(state, title, &layout->pru_version);
w = extract_as_word(state, &layout->pru_version);
if (w != PRUPANIC_VERSION_1) {
PRINT_DEC(MSG_INTL(MSG_NOTE_BAD_UPANIC_VER), pru_version);
dump_hex_bytes(state->ns_data, state->ns_len, state->ns_indent,
4, 3);
} else {
PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PRU_VERSION), pru_version);
w = extract_as_word(state, &layout->pru_flags);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PRU_FLAGS),
conv_prupanic(w, 0, &inv));
if ((w & PRUPANIC_FLAG_MSG_VALID) != 0) {
/*
* We have a message that is _probably_ a text string,
* but the interface allows for arbitrary data. The only
* guarantee is that someone using this is probably up
* to no good. As a result, we basically try to print
* this as a string, but in the face of certain types of
* data, we hex escape it.
*/
print_strbuf(state, MSG_ORIG(MSG_CNOTE_T_PRU_DATA),
&layout->pru_data);
}
}
}
static void
dump_cwd(note_state_t *state, const char *title)
{
const sl_prcwd_layout_t *layout = state->ns_arch->prcwd;
indent_enter(state, title, &layout->prcwd_fsid);
if (data_present(state, &layout->prcwd_fsid)) {
PRINT_HEX(MSG_ORIG(MSG_CNOTE_T_CWD_FSID), prcwd_fsid);
}
if (data_present(state, &layout->prcwd_fsname)) {
print_strbuf(state, MSG_ORIG(MSG_CNOTE_T_CWD_FSNAME),
&layout->prcwd_fsname);
}
if (data_present(state, &layout->prcwd_mntpt)) {
print_strbuf(state, MSG_ORIG(MSG_CNOTE_T_CWD_MNTPT),
&layout->prcwd_mntpt);
}
if (data_present(state, &layout->prcwd_mntspec)) {
print_strbuf(state, MSG_ORIG(MSG_CNOTE_T_CWD_MNTSPEC),
&layout->prcwd_mntspec);
}
if (data_present(state, &layout->prcwd_cwd)) {
print_strbuf(state, MSG_ORIG(MSG_CNOTE_T_CWD_CWD),
&layout->prcwd_cwd);
}
indent_exit(state);
}
corenote_ret_t
corenote(Half mach, int do_swap, Word type,
const char *desc, Word descsz)
{
note_state_t state;
/*
* Get the per-architecture layout definition
*/
state.ns_mach = mach;
state.ns_arch = sl_mach(state.ns_mach);
if (sl_mach(state.ns_mach) == NULL)
return (CORENOTE_R_BADARCH);
state.ns_swap = do_swap;
state.ns_indent = 4;
state.ns_t2col = state.ns_v2col = 0;
state.ns_data = desc;
state.ns_len = descsz;
switch (type) {
case NT_PRSTATUS: /* prstatus_t <sys/old_procfs.h> */
state.ns_vcol = 26;
state.ns_t2col = 46;
state.ns_v2col = 60;
dump_prstatus(&state, MSG_ORIG(MSG_CNOTE_DESC_PRSTATUS_T));
return (CORENOTE_R_OK);
case NT_PRFPREG: /* prfpregset_t <sys/procfs_isa.h> */
return (CORENOTE_R_OK_DUMP);
case NT_PRPSINFO: /* prpsinfo_t <sys/old_procfs.h> */
state.ns_vcol = 20;
state.ns_t2col = 41;
state.ns_v2col = 54;
dump_prpsinfo(&state, MSG_ORIG(MSG_CNOTE_DESC_PRPSINFO_T));
return (CORENOTE_R_OK);
case NT_PRXREG: /* prxregset_t <sys/procfs_isa.h> */
return (CORENOTE_R_OK_DUMP);
case NT_PLATFORM: /* string from sysinfo(SI_PLATFORM) */
dbg_print(0, MSG_ORIG(MSG_NOTE_DESC));
dbg_print(0, MSG_ORIG(MSG_FMT_INDENT), safe_str(desc, descsz));
return (CORENOTE_R_OK);
case NT_AUXV: /* auxv_t array <sys/auxv.h> */
state.ns_vcol = 18;
dump_auxv(&state, MSG_ORIG(MSG_CNOTE_DESC_AUXV_T));
return (CORENOTE_R_OK);
case NT_GWINDOWS: /* gwindows_t SPARC only */
return (CORENOTE_R_OK_DUMP);
case NT_ASRS: /* asrset_t <sys/regset> sparcv9 only */
state.ns_vcol = 18;
state.ns_t2col = 38;
state.ns_v2col = 46;
dump_asrset(&state, MSG_ORIG(MSG_CNOTE_DESC_ASRSET_T));
return (CORENOTE_R_OK);
case NT_LDT: /* ssd array <sys/sysi86.h> IA32 only */
return (CORENOTE_R_OK_DUMP);
case NT_PSTATUS: /* pstatus_t <sys/procfs.h> */
state.ns_vcol = 22;
state.ns_t2col = 42;
state.ns_v2col = 54;
dump_pstatus(&state, MSG_ORIG(MSG_CNOTE_DESC_PSTATUS_T));
return (CORENOTE_R_OK);
case NT_PSINFO: /* psinfo_t <sys/procfs.h> */
state.ns_vcol = 25;
state.ns_t2col = 45;
state.ns_v2col = 58;
dump_psinfo(&state, MSG_ORIG(MSG_CNOTE_DESC_PSINFO_T));
return (CORENOTE_R_OK);
case NT_PRCRED: /* prcred_t <sys/procfs.h> */
state.ns_vcol = 20;
state.ns_t2col = 34;
state.ns_v2col = 44;
dump_prcred(&state, MSG_ORIG(MSG_CNOTE_DESC_PRCRED_T));
return (CORENOTE_R_OK);
case NT_UTSNAME: /* struct utsname <sys/utsname.h> */
state.ns_vcol = 18;
dump_utsname(&state, MSG_ORIG(MSG_CNOTE_DESC_STRUCT_UTSNAME));
return (CORENOTE_R_OK);
case NT_LWPSTATUS: /* lwpstatus_t <sys/procfs.h> */
state.ns_vcol = 24;
state.ns_t2col = 44;
state.ns_v2col = 54;
dump_lwpstatus(&state, MSG_ORIG(MSG_CNOTE_DESC_LWPSTATUS_T));
return (CORENOTE_R_OK);
case NT_LWPSINFO: /* lwpsinfo_t <sys/procfs.h> */
state.ns_vcol = 22;
state.ns_t2col = 42;
state.ns_v2col = 54;
dump_lwpsinfo(&state, MSG_ORIG(MSG_CNOTE_DESC_LWPSINFO_T));
return (CORENOTE_R_OK);
case NT_PRPRIV: /* prpriv_t <sys/procfs.h> */
state.ns_vcol = 21;
state.ns_t2col = 34;
state.ns_v2col = 38;
dump_prpriv(&state, MSG_ORIG(MSG_CNOTE_DESC_PRPRIV_T));
return (CORENOTE_R_OK);
case NT_PRPRIVINFO: /* priv_impl_info_t <sys/priv.h> */
state.ns_vcol = 29;
state.ns_t2col = 41;
state.ns_v2col = 56;
dump_priv_impl_info(&state,
MSG_ORIG(MSG_CNOTE_DESC_PRIV_IMPL_INFO_T));
return (CORENOTE_R_OK);
case NT_CONTENT: /* core_content_t <sys/corectl.h> */
if (sizeof (core_content_t) > descsz)
return (CORENOTE_R_BADDATA);
{
static sl_field_t fdesc = { 0, 8, 0, 0 };
Conv_cnote_cc_content_buf_t conv_buf;
core_content_t content;
state.ns_vcol = 8;
indent_enter(&state,
MSG_ORIG(MSG_CNOTE_DESC_CORE_CONTENT_T),
&fdesc);
content = extract_as_lword(&state, &fdesc);
print_str(&state, MSG_ORIG(MSG_STR_EMPTY),
conv_cnote_cc_content(content, 0, &conv_buf));
indent_exit(&state);
}
return (CORENOTE_R_OK);
case NT_ZONENAME: /* string from getzonenamebyid(3C) */
dbg_print(0, MSG_ORIG(MSG_NOTE_DESC));
dbg_print(0, MSG_ORIG(MSG_FMT_INDENT), safe_str(desc, descsz));
return (CORENOTE_R_OK);
case NT_FDINFO:
state.ns_vcol = 22;
state.ns_t2col = 41;
state.ns_v2col = 54;
dump_prfdinfo(&state, MSG_ORIG(MSG_CNOTE_DESC_PRFDINFO_T));
return (CORENOTE_R_OK);
case NT_SPYMASTER:
state.ns_vcol = 25;
state.ns_t2col = 45;
state.ns_v2col = 58;
dump_psinfo(&state, MSG_ORIG(MSG_CNOTE_DESC_PSINFO_T));
return (CORENOTE_R_OK);
case NT_SECFLAGS:
state.ns_vcol = 23;
state.ns_t2col = 41;
state.ns_v2col = 54;
dump_secflags(&state, MSG_ORIG(MSG_CNOTE_DESC_PRSECFLAGS_T));
return (CORENOTE_R_OK);
case NT_LWPNAME:
state.ns_vcol = 20;
dump_lwpname(&state, MSG_ORIG(MSG_CNOTE_DESC_PRLWPNAME_T));
return (CORENOTE_R_OK);
case NT_UPANIC:
state.ns_vcol = 23;
dump_upanic(&state, MSG_ORIG(MSG_CNOTE_DESC_PRUPANIC_T));
return (CORENOTE_R_OK);
case NT_CWD:
state.ns_vcol = 23;
dump_cwd(&state, MSG_ORIG(MSG_CNOTE_DESC_PRCWD_T));
return (CORENOTE_R_OK);
}
return (CORENOTE_R_BADTYPE);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <_libelf.h>
#include <dwarf.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <strings.h>
#include <debug.h>
#include <conv.h>
#include <msg.h>
#include <_elfdump.h>
/*
* Data from eh_frame section used by dump_cfi()
*/
typedef struct {
const char *file;
const char *sh_name;
Half e_machine; /* ehdr->e_machine */
uchar_t *e_ident; /* ehdr->e_ident */
uint64_t sh_addr; /* Address of eh_frame section */
int do_swap; /* True if object and system byte */
/* order differs */
int cieRflag; /* R flag from current CIE */
uint64_t ciecalign; /* CIE code align factor */
int64_t ciedalign; /* CIE data align factor */
uint64_t fdeinitloc; /* FDE initial location */
uint64_t gotaddr; /* Address of the GOT */
} dump_cfi_state_t;
/*
* Extract an unsigned integer value from an .eh_frame section, converting it
* from its native byte order to that of the running machine if necessary.
*
* entry:
* data - Base address from which to extract datum
* ndx - Address of variable giving index to start byte in data.
* size - # of bytes in datum. Must be one of: 1, 2, 4, 8
* do_swap - True if the data is in a different byte order than that
* of the host system.
*
* exit:
* *ndx is incremented by the size of the extracted datum.
*
* The requested datum is extracted, byte swapped if necessary,
* and returned.
*/
static dwarf_error_t
dwarf_extract_uint(uchar_t *data, size_t len, uint64_t *ndx, int size,
int do_swap, uint64_t *ret)
{
if (((*ndx + size) > len) ||
((*ndx + size) < *ndx))
return (DW_OVERFLOW);
switch (size) {
case 1:
*ret = (data[(*ndx)++]);
return (DW_SUCCESS);
case 2:
{
Half r;
uchar_t *p = (uchar_t *)&r;
data += *ndx;
if (do_swap)
UL_ASSIGN_BSWAP_HALF(p, data);
else
UL_ASSIGN_HALF(p, data);
(*ndx) += 2;
*ret = r;
return (DW_SUCCESS);
}
case 4:
{
Word r;
uchar_t *p = (uchar_t *)&r;
data += *ndx;
if (do_swap)
UL_ASSIGN_BSWAP_WORD(p, data);
else
UL_ASSIGN_WORD(p, data);
(*ndx) += 4;
*ret = r;
return (DW_SUCCESS);
}
case 8:
{
uint64_t r;
uchar_t *p = (uchar_t *)&r;
data += *ndx;
if (do_swap)
UL_ASSIGN_BSWAP_LWORD(p, data);
else
UL_ASSIGN_LWORD(p, data);
(*ndx) += 8;
*ret = r;
return (DW_SUCCESS);
}
default:
return (DW_BAD_ENCODING);
}
/* NOTREACHED */
}
/*
* Map a DWARF register constant to the machine register name it
* corresponds to, formatting the result into buf.
*
* The assignment of DWARF register numbers is part of the system
* specific ABI for each platform.
*
* entry:
* regno - DWARF register number
* mach - ELF machine code for platform
* buf, bufsize - Buffer to receive the formatted result string
*
* exit:
* The results are formatted into buf, and buf is returned.
* If the generated output would exceed the size of the buffer
* provided, it will be clipped to fit.
*/
static const char *
dwarf_regname(Half mach, int regno, char *buf, size_t bufsize)
{
Conv_inv_buf_t inv_buf;
const char *name;
int good_name;
name = conv_dwarf_regname(mach, regno, 0, &good_name, &inv_buf);
/*
* If there is a good mnemonic machine name for the register,
* format the result as 'r# (mnemonic)'. If there is no good
* name for it, then simply format the dwarf name as 'r#'.
*/
if (good_name)
(void) snprintf(buf, bufsize, MSG_ORIG(MSG_REG_FMT_NAME),
regno, name);
else
(void) snprintf(buf, bufsize, MSG_ORIG(MSG_REG_FMT_BASIC),
regno);
return (buf);
}
/*
* Decode eh_frame Call Frame Instructions, printing each one on a
* separate line.
*
* entry:
* data - Address of base of eh_frame section being processed
* off - Offset of current FDE within eh_frame
* ndx - Index of current position within current FDE
* len - Length of FDE
* state - Object, CIE, and FDE state for current request
* msg - Header message to issue before producing output.
* indent - # of indentation characters issued for each line of output.
*
* exit:
* The Call Frame Instructions have been decoded and printed.
*
* *ndx has been incremented to contain the index of the next
* byte of data to be processed in eh_frame.
*
* note:
* The format of Call Frame Instructions in .eh_frame sections is based
* on the DWARF specification.
*/
static void
dump_cfi(uchar_t *data, uint64_t off, uint64_t *ndx, uint_t len,
dump_cfi_state_t *state, const char *msg, int indent)
{
/*
* We use %*s%s to insert leading whitespace and the op name.
* PREFIX supplies these arguments.
*/
#define PREFIX indent, MSG_ORIG(MSG_STR_EMPTY), opname
/* Hide boilerplate clutter in calls to dwarf_regname() */
#define REGNAME(_rnum, _buf) \
dwarf_regname(state->e_machine, _rnum, _buf, sizeof (_buf))
/* Extract the lower 6 bits from an op code */
#define LOW_OP(_op) (_op & 0x3f)
char rbuf1[32], rbuf2[32];
Conv_inv_buf_t inv_buf;
uchar_t op;
const char *opname;
uint64_t oper1, oper2, cur_pc;
int64_t soper;
const char *loc_str;
int i;
dbg_print(0, msg);
/*
* In a CIE/FDE, the length field does not include it's own
* size. Hence, the value passed in is 4 less than the index
* of the actual final location.
*/
len += 4;
/*
* There is a concept of the 'current location', which is the PC
* to which the current item applies. It starts out set to the
* FDE initial location, and can be set or incremented by
* various OP codes. cur_pc is used to track this.
*
* We want to use 'initloc' in the output the first time the location
* is referenced, and then switch to 'loc' for subsequent references.
* loc_str is used to manage that.
*/
cur_pc = state->fdeinitloc;
loc_str = MSG_ORIG(MSG_STR_INITLOC);
while (*ndx < len) {
/*
* The first byte contains the primary op code in the top
* 2 bits, so there are 4 of them. Primary OP code
* 0 uses the lower 6 bits to specify a sub-opcode, allowing
* for 64 of them. The other 3 primary op codes use the
* lower 6 bits to hold an operand (a register #, or value).
*
* Check the primary OP code. If it's 1-3, handle it
* and move to the next loop iteration. For OP code 0,
* fall through to decode the sub-code.
*/
op = data[off + (*ndx)++];
opname = conv_dwarf_cfa(op, 0, &inv_buf);
switch (op >> 6) {
case 0x1: /* v2: DW_CFA_advance_loc, delta */
oper1 = state->ciecalign * LOW_OP(op);
cur_pc += oper1;
dbg_print(0, MSG_ORIG(MSG_CFA_ADV_LOC), PREFIX,
loc_str, EC_XWORD(oper1), EC_XWORD(cur_pc));
loc_str = MSG_ORIG(MSG_STR_LOC);
continue;
case 0x2: /* v2: DW_CFA_offset, reg, offset */
if (uleb_extract(&data[off], ndx, len, &oper1) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
oper1 *= state->ciedalign;
dbg_print(0, MSG_ORIG(MSG_CFA_CFAOFF), PREFIX,
REGNAME(LOW_OP(op), rbuf1), EC_XWORD(oper1));
continue;
case 0x3: /* v2: DW_CFA_restore, reg */
dbg_print(0, MSG_ORIG(MSG_CFA_REG), PREFIX,
REGNAME(LOW_OP(op), rbuf1));
continue;
}
/*
* If we're here, the high order 2 bits are 0. The low 6 bits
* specify a sub-opcode defining the operation.
*/
switch (op) {
case 0x00: /* v2: DW_CFA_nop */
/*
* No-ops are used to fill unused space required
* for alignment. It is common for there to be
* multiple adjacent nops. It saves space to report
* them all with a single line of output.
*/
for (i = 1;
(*ndx < len) && (data[off + *ndx] == 0);
i++, (*ndx)++)
;
dbg_print(0, MSG_ORIG(MSG_CFA_SIMPLEREP), PREFIX, i);
break;
case 0x0a: /* v2: DW_CFA_remember_state */
case 0x0b: /* v2: DW_CFA_restore_state */
case 0x2d: /* GNU: DW_CFA_GNU_window_save */
dbg_print(0, MSG_ORIG(MSG_CFA_SIMPLE), PREFIX);
break;
case 0x01: /* v2: DW_CFA_set_loc, address */
switch (dwarf_ehe_extract(&data[off], len, ndx,
&cur_pc, state->cieRflag, state->e_ident, B_FALSE,
state->sh_addr, off + *ndx, state->gotaddr)) {
case DW_OVERFLOW:
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
case DW_BAD_ENCODING:
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWBADENC),
state->file, state->sh_name,
state->cieRflag);
return;
case DW_SUCCESS:
break;
}
dbg_print(0, MSG_ORIG(MSG_CFA_CFASET), PREFIX,
EC_XWORD(cur_pc));
break;
case 0x02: /* v2: DW_CFA_advance_loc_1, 1-byte delta */
case 0x03: /* v2: DW_CFA_advance_loc_2, 2-byte delta */
case 0x04: /* v2: DW_CFA_advance_loc_4, 4-byte delta */
/*
* Since the codes are contiguous, and the sizes are
* powers of 2, we can compute the word width from
* the code.
*/
i = 1 << (op - 0x02);
switch (dwarf_extract_uint(data + off, len,
ndx, i, state->do_swap, &oper1)) {
case DW_BAD_ENCODING:
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWBADENC),
state->file, state->sh_name,
i);
return;
case DW_OVERFLOW:
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
case DW_SUCCESS:
break;
}
oper1 *= state->ciecalign;
cur_pc += oper1;
dbg_print(0, MSG_ORIG(MSG_CFA_ADV_LOC), PREFIX,
loc_str, EC_XWORD(oper1), EC_XWORD(cur_pc));
loc_str = MSG_ORIG(MSG_STR_LOC);
break;
case 0x05: /* v2: DW_CFA_offset_extended,reg,off */
if (uleb_extract(&data[off], ndx, len, &oper1) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
if (sleb_extract(&data[off], ndx, len, &soper) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
soper *= state->ciedalign;
dbg_print(0, MSG_ORIG(MSG_CFA_CFAOFF), PREFIX,
REGNAME(oper1, rbuf1), EC_SXWORD(soper));
break;
case 0x06: /* v2: DW_CFA_restore_extended, reg */
case 0x0d: /* v2: DW_CFA_def_cfa_register, reg */
case 0x08: /* v2: DW_CFA_same_value, reg */
case 0x07: /* v2: DW_CFA_undefined, reg */
if (uleb_extract(&data[off], ndx, len, &oper1) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
dbg_print(0, MSG_ORIG(MSG_CFA_REG), PREFIX,
REGNAME(oper1, rbuf1));
break;
case 0x09: /* v2: DW_CFA_register, reg, reg */
if (uleb_extract(&data[off], ndx, len, &oper1) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
if (uleb_extract(&data[off], ndx, len, &oper2) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
dbg_print(0, MSG_ORIG(MSG_CFA_REG_REG), PREFIX,
REGNAME(oper1, rbuf1), REGNAME(oper2, rbuf2));
break;
case 0x0c: /* v2: DW_CFA_def_cfa, reg, offset */
if (uleb_extract(&data[off], ndx, len, &oper1) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
if (uleb_extract(&data[off], ndx, len, &oper2) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
dbg_print(0, MSG_ORIG(MSG_CFA_REG_OFFLLU), PREFIX,
REGNAME(oper1, rbuf1), EC_XWORD(oper2));
break;
case 0x0e: /* v2: DW_CFA_def_cfa_offset, offset */
if (uleb_extract(&data[off], ndx, len, &oper1) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
dbg_print(0, MSG_ORIG(MSG_CFA_LLU), PREFIX,
EC_XWORD(oper1));
break;
case 0x0f: /* v3: DW_CFA_def_cfa_expression, blk */
if (uleb_extract(&data[off], ndx, len, &oper1) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
dbg_print(0, MSG_ORIG(MSG_CFA_EBLK), PREFIX,
EC_XWORD(oper1));
/* We currently do not decode the expression block */
*ndx += oper1;
break;
case 0x10: /* v3: DW_CFA_expression, reg, blk */
case 0x16: /* v3: DW_CFA_val_expression,reg,blk */
if (uleb_extract(&data[off], ndx, len, &oper1) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
if (uleb_extract(&data[off], ndx, len, &oper2) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
dbg_print(0, MSG_ORIG(MSG_CFA_REG_EBLK), PREFIX,
REGNAME(oper1, rbuf1), EC_XWORD(oper2));
/* We currently do not decode the expression block */
*ndx += oper2;
break;
case 0x11: /* v3: DW_CFA_offset_extended_sf, reg, off */
if (uleb_extract(&data[off], ndx, len, &oper1) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
if (sleb_extract(&data[off], ndx, len, &soper) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
soper *= state->ciedalign;
dbg_print(0, MSG_ORIG(MSG_CFA_CFAOFF), PREFIX,
REGNAME(oper1, rbuf1), EC_SXWORD(soper));
break;
case 0x12: /* v3: DW_CFA_def_cfa_sf, reg, offset */
if (uleb_extract(&data[off], ndx, len, &oper1) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
if (sleb_extract(&data[off], ndx, len, &soper) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
soper *= state->ciedalign;
dbg_print(0, MSG_ORIG(MSG_CFA_REG_OFFLLD), PREFIX,
REGNAME(oper1, rbuf1), EC_SXWORD(soper));
break;
case 0x13: /* DW_CFA_def_cfa_offset_sf, offset */
if (sleb_extract(&data[off], ndx, len, &soper) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
soper *= state->ciedalign;
dbg_print(0, MSG_ORIG(MSG_CFA_LLD), PREFIX,
EC_SXWORD(soper));
break;
case 0x14: /* v3: DW_CFA_val_offset, reg, offset */
if (uleb_extract(&data[off], ndx, len, &oper1) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
if (sleb_extract(&data[off], ndx, len, &soper) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
soper *= state->ciedalign;
dbg_print(0, MSG_ORIG(MSG_CFA_REG_OFFLLD), PREFIX,
REGNAME(oper1, rbuf1), EC_SXWORD(soper));
break;
case 0x15: /* v3: DW_CFA_val_offset_sf, reg, offset */
if (uleb_extract(&data[off], ndx, len, &oper1) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
if (sleb_extract(&data[off], ndx, len, &soper) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
soper *= state->ciedalign;
dbg_print(0, MSG_ORIG(MSG_CFA_REG_OFFLLD), PREFIX,
REGNAME(oper1, rbuf1), EC_SXWORD(soper));
break;
case 0x1d: /* GNU: DW_CFA_MIPS_advance_loc8, delta */
switch (dwarf_extract_uint(data + off, len,
ndx, 8, state->do_swap, &oper1)) {
case DW_BAD_ENCODING:
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWBADENC),
state->file, state->sh_name,
8);
return;
case DW_OVERFLOW:
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
case DW_SUCCESS:
break;
}
oper1 *= state->ciecalign;
cur_pc += oper1;
dbg_print(0, MSG_ORIG(MSG_CFA_ADV_LOC), PREFIX,
loc_str, EC_XWORD(oper1), EC_XWORD(cur_pc));
loc_str = MSG_ORIG(MSG_STR_LOC);
break;
case 0x2e: /* GNU: DW_CFA_GNU_args_size, size */
if (uleb_extract(&data[off], ndx, len, &oper1) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
dbg_print(0, MSG_ORIG(MSG_CFA_LLU), PREFIX,
EC_XWORD(oper1));
break;
case 0x2f: /* GNU:DW_CFA_GNU_negative_offset_extended,reg,off */
if (uleb_extract(&data[off], ndx, len, &oper1) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
if (sleb_extract(&data[off], ndx, len, &soper) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
state->file, state->sh_name);
return;
}
soper = -soper * state->ciedalign;
soper *= state->ciedalign;
dbg_print(0, MSG_ORIG(MSG_CFA_CFAOFF), PREFIX,
REGNAME(oper1, rbuf1), EC_SXWORD(soper));
break;
default:
/*
* Unrecognized OP code: DWARF data is variable length,
* so we don't know how many bytes to skip in order to
* advance to the next item. We cannot decode beyond
* this point, so dump the remainder in hex.
*/
(*ndx)--; /* Back up to unrecognized opcode */
dump_hex_bytes(data + off + *ndx, len - *ndx,
indent, 8, 1);
(*ndx) = len;
break;
}
}
#undef PREFIX
#undef REGNAME
#undef LOW_OP
}
void
dump_eh_frame(const char *file, char *sh_name, uchar_t *data, size_t datasize,
uint64_t sh_addr, Half e_machine, uchar_t *e_ident, uint64_t gotaddr)
{
Conv_dwarf_ehe_buf_t dwarf_ehe_buf;
dump_cfi_state_t cfi_state;
uint64_t off, ndx, length, id;
uint_t cieid, cielength, cieversion, cieretaddr;
int ciePflag = 0, cieZflag = 0, cieLflag = 0;
int cieLflag_present = 0;
uint_t cieaugndx;
char *cieaugstr = NULL;
boolean_t have_cie = B_FALSE;
cfi_state.file = file;
cfi_state.sh_name = sh_name;
cfi_state.e_machine = e_machine;
cfi_state.e_ident = e_ident;
cfi_state.sh_addr = sh_addr;
cfi_state.do_swap = _elf_sys_encoding() != e_ident[EI_DATA];
cfi_state.gotaddr = gotaddr;
off = 0;
while (off < datasize) {
ndx = 0;
/*
* Extract length in native format. A zero length indicates
* that this CIE is a terminator and that processing for this
* unwind information should end. However, skip this entry and
* keep processing, just in case there is any other information
* remaining in this section. Note, ld(1) will terminate the
* processing of the .eh_frame contents for this file after a
* zero length CIE, thus any information that does follow is
* ignored by ld(1), and is therefore questionable.
*/
if (dwarf_extract_uint(data + off, datasize - off,
&ndx, 4, cfi_state.do_swap, &length) == DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
file, sh_name);
return;
}
if (length == 0) {
dbg_print(0, MSG_ORIG(MSG_UNW_ZEROTERM));
off += 4;
continue;
}
if (length > (datasize - off)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADCIEFDELEN),
file, sh_name, EC_XWORD(length),
EC_XWORD(sh_addr + off));
/*
* If length is wrong, we have no means to find the
* next entry, just give up
*/
return;
}
/*
* extract CIE id in native format
*/
if (dwarf_extract_uint(data + off, datasize - off, &ndx,
4, cfi_state.do_swap, &id) == DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
file, sh_name);
return;
}
/*
* A CIE record has an id of '0', otherwise this is a
* FDE entry and the 'id' is the CIE pointer.
*/
if (id == 0) {
uint64_t persVal, ndx_save = 0;
uint64_t axsize;
have_cie = B_TRUE;
cielength = length;
cieid = id;
ciePflag = cfi_state.cieRflag = cieZflag = 0;
cieLflag = cieLflag_present = 0;
dbg_print(0, MSG_ORIG(MSG_UNW_CIE),
EC_XWORD(sh_addr + off));
dbg_print(0, MSG_ORIG(MSG_UNW_CIELNGTH),
cielength, cieid);
cieversion = data[off + ndx];
ndx += 1;
cieaugstr = (char *)(&data[off + ndx]);
ndx += strlen(cieaugstr) + 1;
dbg_print(0, MSG_ORIG(MSG_UNW_CIEVERS),
cieversion, cieaugstr);
if (uleb_extract(&data[off], &ndx, datasize - off,
&cfi_state.ciecalign) == DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
file, sh_name);
return;
}
if (sleb_extract(&data[off], &ndx, datasize - off,
&cfi_state.ciedalign) == DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
file, sh_name);
return;
}
cieretaddr = data[off + ndx];
ndx += 1;
dbg_print(0, MSG_ORIG(MSG_UNW_CIECALGN),
EC_XWORD(cfi_state.ciecalign),
EC_XWORD(cfi_state.ciedalign), cieretaddr);
if (cieaugstr[0])
dbg_print(0, MSG_ORIG(MSG_UNW_CIEAXVAL));
for (cieaugndx = 0; cieaugstr[cieaugndx]; cieaugndx++) {
switch (cieaugstr[cieaugndx]) {
case 'z':
if (uleb_extract(&data[off], &ndx,
datasize - off, &axsize) ==
DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
file, sh_name);
return;
}
dbg_print(0, MSG_ORIG(MSG_UNW_CIEAXSIZ),
EC_XWORD(axsize));
cieZflag = 1;
/*
* The auxiliary section can contain
* unused padding bytes at the end, so
* save the current index. Along with
* axsize, we will use it to set ndx to
* the proper continuation index after
* the aux data has been processed.
*/
ndx_save = ndx;
break;
case 'P':
ciePflag = data[off + ndx];
ndx += 1;
switch (dwarf_ehe_extract(&data[off],
datasize - off, &ndx, &persVal,
ciePflag, e_ident, B_FALSE, sh_addr,
off + ndx, gotaddr)) {
case DW_OVERFLOW:
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
file, sh_name);
return;
case DW_BAD_ENCODING:
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWBADENC),
file, sh_name, ciePflag);
return;
case DW_SUCCESS:
break;
}
dbg_print(0,
MSG_ORIG(MSG_UNW_CIEAXPERS));
dbg_print(0,
MSG_ORIG(MSG_UNW_CIEAXPERSENC),
ciePflag, conv_dwarf_ehe(ciePflag,
&dwarf_ehe_buf));
dbg_print(0,
MSG_ORIG(MSG_UNW_CIEAXPERSRTN),
EC_XWORD(persVal));
break;
case 'R':
cfi_state.cieRflag = data[off + ndx];
ndx += 1;
dbg_print(0,
MSG_ORIG(MSG_UNW_CIEAXCENC),
cfi_state.cieRflag,
conv_dwarf_ehe(cfi_state.cieRflag,
&dwarf_ehe_buf));
break;
case 'L':
cieLflag_present = 1;
cieLflag = data[off + ndx];
ndx += 1;
dbg_print(0,
MSG_ORIG(MSG_UNW_CIEAXLSDA),
cieLflag, conv_dwarf_ehe(
cieLflag, &dwarf_ehe_buf));
break;
default:
dbg_print(0,
MSG_ORIG(MSG_UNW_CIEAXUNEC),
cieaugstr[cieaugndx]);
break;
}
}
/*
* If the z flag was present, reposition ndx using the
* length given. This will safely move us past any
* unaccessed padding bytes in the auxiliary section.
*/
if (cieZflag)
ndx = ndx_save + axsize;
/*
* Any remaining data are Call Frame Instructions
*/
if ((cielength + 4) > ndx)
dump_cfi(data, off, &ndx, cielength, &cfi_state,
MSG_ORIG(MSG_UNW_CIECFI), 3);
off += cielength + 4;
} else {
uint_t fdelength = length;
int fdecieptr = id;
uint64_t fdeaddrrange;
if (!have_cie) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWNOCIE), file, sh_name);
return;
}
dbg_print(0, MSG_ORIG(MSG_UNW_FDE),
EC_XWORD(sh_addr + off));
dbg_print(0, MSG_ORIG(MSG_UNW_FDELNGTH),
fdelength, fdecieptr);
switch (dwarf_ehe_extract(&data[off], datasize - off,
&ndx, &cfi_state.fdeinitloc, cfi_state.cieRflag,
e_ident, B_FALSE, sh_addr, off + ndx, gotaddr)) {
case DW_OVERFLOW:
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW), file, sh_name);
return;
case DW_BAD_ENCODING:
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWBADENC), file, sh_name,
cfi_state.cieRflag);
return;
case DW_SUCCESS:
break;
}
switch (dwarf_ehe_extract(&data[off], datasize - off,
&ndx, &fdeaddrrange,
(cfi_state.cieRflag & ~DW_EH_PE_pcrel), e_ident,
B_FALSE, sh_addr, off + ndx, gotaddr)) {
case DW_OVERFLOW:
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW), file, sh_name);
return;
case DW_BAD_ENCODING:
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWBADENC), file, sh_name,
(cfi_state.cieRflag & ~DW_EH_PE_pcrel));
return;
case DW_SUCCESS:
break;
}
dbg_print(0, MSG_ORIG(MSG_UNW_FDEINITLOC),
EC_XWORD(cfi_state.fdeinitloc),
EC_XWORD(fdeaddrrange),
EC_XWORD(cfi_state.fdeinitloc + fdeaddrrange - 1));
if ((cieaugstr != NULL) && (cieaugstr[0] != '\0'))
dbg_print(0, MSG_ORIG(MSG_UNW_FDEAXVAL));
if (cieZflag) {
uint64_t val;
uint64_t lndx;
if (uleb_extract(&data[off], &ndx,
datasize - off, &val) == DW_OVERFLOW) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
file, sh_name);
return;
}
lndx = ndx;
ndx += val;
dbg_print(0, MSG_ORIG(MSG_UNW_FDEAXSIZE),
EC_XWORD(val));
if (val && cieLflag_present) {
uint64_t lsda;
switch (dwarf_ehe_extract(&data[off],
datasize - off, &lndx, &lsda,
cieLflag, e_ident, B_FALSE, sh_addr,
off + lndx, gotaddr)) {
case DW_OVERFLOW:
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW),
file, sh_name);
return;
case DW_BAD_ENCODING:
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWBADENC),
file, sh_name, cieLflag);
return;
case DW_SUCCESS:
break;
}
dbg_print(0,
MSG_ORIG(MSG_UNW_FDEAXLSDA),
EC_XWORD(lsda));
}
}
if ((fdelength + 4) > ndx)
dump_cfi(data, off, &ndx, fdelength, &cfi_state,
MSG_ORIG(MSG_UNW_FDECFI), 6);
off += fdelength + 4;
}
}
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 2015, Joyent, Inc. All rights reserved.
*/
/*
* Dump an elf file.
*/
#include <stddef.h>
#include <sys/elf_386.h>
#include <sys/elf_amd64.h>
#include <sys/elf_SPARC.h>
#include <_libelf.h>
#include <dwarf.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <strings.h>
#include <debug.h>
#include <conv.h>
#include <msg.h>
#include <_elfdump.h>
/*
* VERSYM_STATE is used to maintain information about the VERSYM section
* in the object being analyzed. It is filled in by versions(), and used
* by init_symtbl_state() when displaying symbol information.
*
* There are three forms of symbol versioning known to us:
*
* 1) The original form, introduced with Solaris 2.5, in which
* the Versym contains indexes to Verdef records, and the
* Versym values for UNDEF symbols resolved by other objects
* are all set to 0.
* 2) The GNU form, which is backward compatible with the original
* Solaris form, but which adds several extensions:
* - The Versym also contains indexes to Verneed records, recording
* which object/version contributed the external symbol at
* link time. These indexes start with the next value following
* the final Verdef index. The index is written to the previously
* reserved vna_other field of the ELF Vernaux structure.
* - The top bit of the Versym value is no longer part of the index,
* but is used as a "hidden bit" to prevent binding to the symbol.
* - Multiple implementations of a given symbol, contained in varying
* versions are allowed, using special assembler pseudo ops,
* and encoded in the symbol name using '@' characters.
* 3) Modified Solaris form, in which we adopt the first GNU extension
* (Versym indexes to Verneed records), but not the others.
*
* elfdump can handle any of these cases. The presence of a DT_VERSYM
* dynamic element indicates a full GNU object. An object that lacks
* a DT_VERSYM entry, but which has non-zero vna_other fields in the Vernaux
* structures is a modified Solaris object. An object that has neither of
* these uses the original form.
*
* max_verndx contains the largest version index that can appear
* in a Versym entry. This can never be less than 1: In the case where
* there is no verdef/verneed sections, the [0] index is reserved
* for local symbols, and the [1] index for globals. If the original
* Solaris versioning rules are in effect and there is a verdef section,
* then max_verndex is the number of defined versions. If one of the
* other versioning forms is in effect, then:
* 1) If there is no verneed section, it is the same as for
* original Solaris versioning.
* 2) If there is a verneed section, the vna_other field of the
* Vernaux structs contain versions, and max_verndx is the
* largest such index.
*
* If gnu_full is True, the object uses the full GNU form of versioning.
* The value of the gnu_full field is based on the presence of
* a DT_VERSYM entry in the dynamic section: GNU ld produces these, and
* Solaris ld does not.
*
* The gnu_needed field is True if the Versym contains indexes to
* Verneed records, as indicated by non-zero vna_other fields in the Verneed
* section. If gnu_full is True, then gnu_needed will always be true.
* However, gnu_needed can be true without gnu_full. This is the modified
* Solaris form.
*/
typedef struct {
Cache *cache; /* Pointer to cache entry for VERSYM */
Versym *data; /* Pointer to versym array */
int gnu_full; /* True if object uses GNU versioning rules */
int gnu_needed; /* True if object uses VERSYM indexes for */
/* VERNEED (subset of gnu_full) */
int max_verndx; /* largest versym index value */
} VERSYM_STATE;
/*
* SYMTBL_STATE is used to maintain information about a single symbol
* table section, for use by the routines that display symbol information.
*/
typedef struct {
const char *file; /* Name of file */
Ehdr *ehdr; /* ELF header for file */
Cache *cache; /* Cache of all section headers */
uchar_t osabi; /* OSABI to use */
Word shnum; /* # of sections in cache */
Cache *seccache; /* Cache of symbol table section hdr */
Word secndx; /* Index of symbol table section hdr */
const char *secname; /* Name of section */
uint_t flags; /* Command line option flags */
struct { /* Extended section index data */
int checked; /* TRUE if already checked for shxndx */
Word *data; /* NULL, or extended section index */
/* used for symbol table entries */
uint_t n; /* # items in shxndx.data */
} shxndx;
VERSYM_STATE *versym; /* NULL, or associated VERSYM section */
Sym *sym; /* Array of symbols */
Word symn; /* # of symbols */
} SYMTBL_STATE;
/*
* A variable of this type is used to track information related to
* .eh_frame and .eh_frame_hdr sections across calls to unwind_eh_frame().
*/
typedef struct {
Word frame_cnt; /* # .eh_frame sections seen */
Word frame_ndx; /* Section index of 1st .eh_frame */
Word hdr_cnt; /* # .eh_frame_hdr sections seen */
Word hdr_ndx; /* Section index of 1st .eh_frame_hdr */
uint64_t frame_ptr; /* Value of FramePtr field from first */
/* .eh_frame_hdr section */
uint64_t frame_base; /* Data addr of 1st .eh_frame */
} gnu_eh_state_t;
/*
* C++ .exception_ranges entries make use of the signed ptrdiff_t
* type to record self-relative pointer values. We need a type
* for this that is matched to the ELFCLASS being processed.
*/
#if defined(_ELF64)
typedef int64_t PTRDIFF_T;
#else
typedef int32_t PTRDIFF_T;
#endif
/*
* The Sun C++ ABI uses this struct to define each .exception_ranges
* entry. From the ABI:
*
* The field ret_addr is a self relative pointer to the start of the address
* range. The name was chosen because in the current implementation the range
* typically starts at the return address for a call site.
*
* The field length is the difference, in bytes, between the pc of the last
* instruction covered by the exception range and the first. When only a
* single call site is represented without optimization, this will equal zero.
*
* The field handler_addr is a relative pointer which stores the difference
* between the start of the exception range and the address of all code to
* catch exceptions and perform the cleanup for stack unwinding.
*
* The field type_block is a relative pointer which stores the difference
* between the start of the exception range and the address of an array used
* for storing a list of the types of exceptions which can be caught within
* the exception range.
*/
typedef struct {
PTRDIFF_T ret_addr;
Xword length;
PTRDIFF_T handler_addr;
PTRDIFF_T type_block;
Xword reserved;
} exception_range_entry;
/*
* Focal point for verifying symbol names.
*/
static const char *
string(Cache *refsec, Word ndx, Cache *strsec, const char *file, Word name)
{
/*
* If an error in this routine is due to a property of the string
* section, as opposed to a bad offset into the section (a property of
* the referencing section), then we will detect the same error on
* every call involving those sections. We use these static variables
* to retain the information needed to only issue each such error once.
*/
static Cache *last_refsec; /* Last referencing section seen */
static int strsec_err; /* True if error issued */
const char *strs;
Word strn;
if ((strsec->c_data == NULL) || (strsec->c_data->d_buf == NULL))
return (NULL);
strs = (char *)strsec->c_data->d_buf;
strn = strsec->c_data->d_size;
/*
* We only print a diagnostic regarding a bad string table once per
* input section being processed. If the refsec has changed, reset
* our retained error state.
*/
if (last_refsec != refsec) {
last_refsec = refsec;
strsec_err = 0;
}
/* Verify that strsec really is a string table */
if (strsec->c_shdr->sh_type != SHT_STRTAB) {
if (!strsec_err) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_NOTSTRTAB),
file, strsec->c_ndx, refsec->c_ndx);
strsec_err = 1;
}
return (MSG_INTL(MSG_STR_UNKNOWN));
}
/*
* Is the string table offset within range of the available strings?
*/
if (name >= strn) {
/*
* Do we have a empty string table?
*/
if (strs == NULL) {
if (!strsec_err) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, strsec->c_name);
strsec_err = 1;
}
} else {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSTOFF),
file, refsec->c_name, EC_WORD(ndx), strsec->c_name,
EC_WORD(name), EC_WORD(strn - 1));
}
/*
* Return the empty string so that the calling function can
* continue it's output diagnostics.
*/
return (MSG_INTL(MSG_STR_UNKNOWN));
}
return (strs + name);
}
/*
* Relocations can reference section symbols and standard symbols. If the
* former, establish the section name.
*/
static const char *
relsymname(Cache *cache, Cache *csec, Cache *strsec, Word symndx, Word symnum,
Word relndx, Sym *syms, char *secstr, size_t secsz, const char *file)
{
Sym *sym;
const char *name;
if (symndx >= symnum) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_RELBADSYMNDX),
file, EC_WORD(symndx), EC_WORD(relndx));
return (MSG_INTL(MSG_STR_UNKNOWN));
}
sym = (Sym *)(syms + symndx);
name = string(csec, symndx, strsec, file, sym->st_name);
/*
* If the symbol represents a section offset construct an appropriate
* string. Note, although section symbol table entries typically have
* a NULL name pointer, entries do exist that point into the string
* table to their own NULL strings.
*/
if ((ELF_ST_TYPE(sym->st_info) == STT_SECTION) &&
((sym->st_name == 0) || (*name == '\0'))) {
(void) snprintf(secstr, secsz, MSG_INTL(MSG_STR_SECTION),
cache[sym->st_shndx].c_name);
return ((const char *)secstr);
}
return (name);
}
/*
* Focal point for establishing a string table section. Data such as the
* dynamic information simply points to a string table. Data such as
* relocations, reference a symbol table, which in turn is associated with a
* string table.
*/
static int
stringtbl(Cache *cache, int symtab, Word ndx, Word shnum, const char *file,
Word *symnum, Cache **symsec, Cache **strsec)
{
Shdr *shdr = cache[ndx].c_shdr;
/*
* If symtab is non-zero, the ndx we are called with represents a
* shdr which links to a symbol table (which then links to a string
* table)
*/
if (symtab != 0) {
/*
* Validate the symbol table linkage.
*/
if ((shdr->sh_link == 0) || (shdr->sh_link >= shnum)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHLINK),
file, cache[ndx].c_name, EC_WORD(shdr->sh_link));
return (0);
}
/*
* Establish the symbol table index.
*/
ndx = shdr->sh_link;
shdr = cache[ndx].c_shdr;
if ((shdr->sh_entsize == 0) || (shdr->sh_size == 0)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, cache[ndx].c_name);
return (0);
}
/*
* Obtain, and verify the symbol table data.
*/
if ((cache[ndx].c_data == NULL) ||
(cache[ndx].c_data->d_buf == NULL)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, cache[ndx].c_name);
return (0);
}
/*
* Return symbol table information.
*/
if (symnum)
*symnum = (shdr->sh_size / shdr->sh_entsize);
if (symsec)
*symsec = &cache[ndx];
}
/*
* Validate the string table linkage.
*/
if ((shdr->sh_link == 0) || (shdr->sh_link >= shnum)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHLINK),
file, cache[ndx].c_name, EC_WORD(shdr->sh_link));
return (0);
}
if (strsec)
*strsec = &cache[shdr->sh_link];
return (1);
}
/*
* Lookup a symbol and set Sym accordingly.
*
* entry:
* name - Name of symbol to lookup
* cache - Cache of all section headers
* shnum - # of sections in cache
* sym - Address of pointer to receive symbol
* target - NULL, or section to which the symbol must be associated.
* symtab - Symbol table to search for symbol
* file - Name of file
*
* exit:
* If the symbol is found, *sym is set to reference it, and True is
* returned. If target is non-NULL, the symbol must reference the given
* section --- otherwise the section is not checked.
*
* If no symbol is found, False is returned.
*/
static int
symlookup(const char *name, Cache *cache, Word shnum, Sym **sym,
Cache *target, Cache *symtab, const char *file)
{
Shdr *shdr;
Word symn, cnt;
Sym *syms;
if (symtab == 0)
return (0);
shdr = symtab->c_shdr;
/*
* Determine the symbol data and number.
*/
if ((shdr->sh_entsize == 0) || (shdr->sh_size == 0)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, symtab->c_name);
return (0);
}
if ((symtab->c_data == NULL) || (symtab->c_data->d_buf == NULL))
return (0);
/* LINTED */
symn = (Word)(shdr->sh_size / shdr->sh_entsize);
syms = (Sym *)symtab->c_data->d_buf;
/*
* Get the associated string table section.
*/
if ((shdr->sh_link == 0) || (shdr->sh_link >= shnum)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHLINK),
file, symtab->c_name, EC_WORD(shdr->sh_link));
return (0);
}
/*
* Loop through the symbol table to find a match.
*/
*sym = NULL;
for (cnt = 0; cnt < symn; syms++, cnt++) {
const char *symname;
symname = string(symtab, cnt, &cache[shdr->sh_link], file,
syms->st_name);
if (symname && (strcmp(name, symname) == 0) &&
((target == NULL) || (target->c_ndx == syms->st_shndx))) {
/*
* It is possible, though rare, for a local and
* global symbol of the same name to exist, each
* contributed by a different input object. If the
* symbol just found is local, remember it, but
* continue looking.
*/
*sym = syms;
if (ELF_ST_BIND(syms->st_info) != STB_LOCAL)
break;
}
}
return (*sym != NULL);
}
/*
* Print section headers.
*/
static void
sections(const char *file, Cache *cache, Word shnum, Ehdr *ehdr, uchar_t osabi)
{
size_t seccnt;
for (seccnt = 1; seccnt < shnum; seccnt++) {
Cache *_cache = &cache[seccnt];
Shdr *shdr = _cache->c_shdr;
const char *secname = _cache->c_name;
/*
* Although numerous section header entries can be zero, it's
* usually a sign of trouble if the type is zero.
*/
if (shdr->sh_type == 0) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHTYPE),
file, secname, EC_WORD(shdr->sh_type));
}
if (!match(MATCH_F_ALL, secname, seccnt, shdr->sh_type))
continue;
/*
* Identify any sections that are suspicious. A .got section
* shouldn't exist in a relocatable object.
*/
if (ehdr->e_type == ET_REL) {
if (strncmp(secname, MSG_ORIG(MSG_ELF_GOT),
MSG_ELF_GOT_SIZE) == 0) {
(void) fprintf(stderr,
MSG_INTL(MSG_GOT_UNEXPECTED), file,
secname);
}
}
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_ELF_SHDR), EC_WORD(seccnt), secname);
Elf_shdr(0, osabi, ehdr->e_machine, shdr);
}
}
/*
* Obtain a specified Phdr entry.
*/
static Phdr *
getphdr(Word phnum, Word *type_arr, Word type_cnt, const char *file, Elf *elf,
size_t *phndx)
{
Word cnt, tcnt;
Phdr *phdr;
if (phndx != NULL)
*phndx = 0;
if ((phdr = elf_getphdr(elf)) == NULL) {
failure(file, MSG_ORIG(MSG_ELF_GETPHDR));
return (NULL);
}
for (cnt = 0; cnt < phnum; phdr++, cnt++) {
for (tcnt = 0; tcnt < type_cnt; tcnt++) {
if (phdr->p_type == type_arr[tcnt]) {
if (phndx != NULL) {
*phndx = cnt;
}
return (phdr);
}
}
}
return (NULL);
}
/*
* Display the contents of GNU/amd64 .eh_frame and .eh_frame_hdr
* sections.
*
* entry:
* cache - Cache of all section headers
* shndx - Index of .eh_frame or .eh_frame_hdr section to be displayed
* shnum - Total number of sections which exist
* uphdr - NULL, or unwind program header associated with
* the .eh_frame_hdr section.
* ehdr - ELF header for file
* eh_state - Data used across calls to this routine. The
* caller should zero it before the first call, and
* pass it on every call.
* osabi - OSABI to use in displaying information
* file - Name of file
* flags - Command line option flags
*/
static void
unwind_eh_frame(Cache *cache, Word shndx, Word shnum, Phdr *uphdr, Ehdr *ehdr,
gnu_eh_state_t *eh_state, uchar_t osabi, const char *file, uint_t flags)
{
#if defined(_ELF64)
#define MSG_UNW_BINSRTAB2 MSG_UNW_BINSRTAB2_64
#define MSG_UNW_BINSRTABENT MSG_UNW_BINSRTABENT_64
#else
#define MSG_UNW_BINSRTAB2 MSG_UNW_BINSRTAB2_32
#define MSG_UNW_BINSRTABENT MSG_UNW_BINSRTABENT_32
#endif
Cache *_cache = &cache[shndx];
Shdr *shdr = _cache->c_shdr;
uchar_t *data = (uchar_t *)(_cache->c_data->d_buf);
size_t datasize = _cache->c_data->d_size;
Conv_dwarf_ehe_buf_t dwarf_ehe_buf;
uint64_t ndx, frame_ptr, fde_cnt, tabndx;
uint_t vers, frame_ptr_enc, fde_cnt_enc, table_enc;
uint64_t initloc, initloc0 = 0;
uint64_t gotaddr = 0;
int cnt;
for (cnt = 1; cnt < shnum; cnt++) {
if (strncmp(cache[cnt].c_name, MSG_ORIG(MSG_ELF_GOT),
MSG_ELF_GOT_SIZE) == 0) {
gotaddr = cache[cnt].c_shdr->sh_addr;
break;
}
}
if ((data == NULL) || (datasize == 0)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, _cache ->c_name);
return;
}
/*
* Is this a .eh_frame_hdr?
*/
if ((uphdr && (shdr->sh_addr == uphdr->p_vaddr)) ||
(strncmp(_cache->c_name, MSG_ORIG(MSG_SCN_FRMHDR),
MSG_SCN_FRMHDR_SIZE) == 0)) {
/*
* There can only be a single .eh_frame_hdr.
* Flag duplicates.
*/
if (++eh_state->hdr_cnt > 1)
(void) fprintf(stderr, MSG_INTL(MSG_ERR_MULTEHFRMHDR),
file, EC_WORD(shndx), _cache->c_name);
dbg_print(0, MSG_ORIG(MSG_UNW_FRMHDR));
ndx = 0;
vers = data[ndx++];
frame_ptr_enc = data[ndx++];
fde_cnt_enc = data[ndx++];
table_enc = data[ndx++];
dbg_print(0, MSG_ORIG(MSG_UNW_FRMVERS), vers);
switch (dwarf_ehe_extract(data, datasize, &ndx,
&frame_ptr, frame_ptr_enc, ehdr->e_ident, B_TRUE,
shdr->sh_addr, ndx, gotaddr)) {
case DW_OVERFLOW:
(void) fprintf(stderr, MSG_INTL(MSG_ERR_DWOVRFLW),
file, _cache->c_name);
return;
case DW_BAD_ENCODING:
(void) fprintf(stderr, MSG_INTL(MSG_ERR_DWBADENC),
file, _cache->c_name, frame_ptr_enc);
return;
case DW_SUCCESS:
break;
}
if (eh_state->hdr_cnt == 1) {
eh_state->hdr_ndx = shndx;
eh_state->frame_ptr = frame_ptr;
}
dbg_print(0, MSG_ORIG(MSG_UNW_FRPTRENC),
conv_dwarf_ehe(frame_ptr_enc, &dwarf_ehe_buf),
EC_XWORD(frame_ptr));
switch (dwarf_ehe_extract(data, datasize, &ndx, &fde_cnt,
fde_cnt_enc, ehdr->e_ident, B_TRUE, shdr->sh_addr, ndx,
gotaddr)) {
case DW_OVERFLOW:
(void) fprintf(stderr, MSG_INTL(MSG_ERR_DWOVRFLW),
file, _cache->c_name);
return;
case DW_BAD_ENCODING:
(void) fprintf(stderr, MSG_INTL(MSG_ERR_DWBADENC),
file, _cache->c_name, fde_cnt_enc);
return;
case DW_SUCCESS:
break;
}
dbg_print(0, MSG_ORIG(MSG_UNW_FDCNENC),
conv_dwarf_ehe(fde_cnt_enc, &dwarf_ehe_buf),
EC_XWORD(fde_cnt));
dbg_print(0, MSG_ORIG(MSG_UNW_TABENC),
conv_dwarf_ehe(table_enc, &dwarf_ehe_buf));
dbg_print(0, MSG_ORIG(MSG_UNW_BINSRTAB1));
dbg_print(0, MSG_ORIG(MSG_UNW_BINSRTAB2));
for (tabndx = 0; tabndx < fde_cnt; tabndx++) {
uint64_t table;
switch (dwarf_ehe_extract(data, datasize, &ndx,
&initloc, table_enc, ehdr->e_ident, B_TRUE,
shdr->sh_addr, ndx, gotaddr)) {
case DW_OVERFLOW:
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW), file,
_cache->c_name);
return;
case DW_BAD_ENCODING:
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWBADENC), file,
_cache->c_name, table_enc);
return;
case DW_SUCCESS:
break;
}
if ((tabndx != 0) && (initloc0 > initloc))
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADSORT), file,
_cache->c_name, EC_WORD(tabndx));
switch (dwarf_ehe_extract(data, datasize, &ndx, &table,
table_enc, ehdr->e_ident, B_TRUE, shdr->sh_addr,
ndx, gotaddr)) {
case DW_OVERFLOW:
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWOVRFLW), file,
_cache->c_name);
return;
case DW_BAD_ENCODING:
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DWBADENC), file,
_cache->c_name, table_enc);
return;
case DW_SUCCESS:
break;
}
dbg_print(0, MSG_ORIG(MSG_UNW_BINSRTABENT),
EC_XWORD(initloc),
EC_XWORD(table));
initloc0 = initloc;
}
} else { /* Display the .eh_frame section */
eh_state->frame_cnt++;
if (eh_state->frame_cnt == 1) {
eh_state->frame_ndx = shndx;
eh_state->frame_base = shdr->sh_addr;
} else if ((eh_state->frame_cnt > 1) &&
(ehdr->e_type != ET_REL)) {
Conv_inv_buf_t inv_buf;
(void) fprintf(stderr, MSG_INTL(MSG_WARN_MULTEHFRM),
file, EC_WORD(shndx), _cache->c_name,
conv_ehdr_type(osabi, ehdr->e_type, 0, &inv_buf));
}
dump_eh_frame(file, _cache->c_name, data, datasize,
shdr->sh_addr, ehdr->e_machine, ehdr->e_ident, gotaddr);
}
/*
* If we've seen the .eh_frame_hdr and the first .eh_frame section,
* compare the header frame_ptr to the address of the actual frame
* section to ensure the link-editor got this right. Note, this
* diagnostic is only produced when unwind information is explicitly
* asked for, as shared objects built with an older ld(1) may reveal
* this inconsistency. Although an inconsistency, it doesn't seem to
* have any adverse effect on existing tools.
*/
if (((flags & FLG_MASK_SHOW) != FLG_MASK_SHOW) &&
(eh_state->hdr_cnt > 0) && (eh_state->frame_cnt > 0) &&
(eh_state->frame_ptr != eh_state->frame_base))
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADEHFRMPTR),
file, EC_WORD(eh_state->hdr_ndx),
cache[eh_state->hdr_ndx].c_name,
EC_XWORD(eh_state->frame_ptr),
EC_WORD(eh_state->frame_ndx),
cache[eh_state->frame_ndx].c_name,
EC_XWORD(eh_state->frame_base));
#undef MSG_UNW_BINSRTAB2
#undef MSG_UNW_BINSRTABENT
}
/*
* Convert a self relative pointer into an address. A self relative
* pointer adds the address where the pointer resides to the offset
* contained in the pointer. The benefit is that the value of the
* pointer does not require relocation.
*
* entry:
* base_addr - Address of the pointer.
* delta - Offset relative to base_addr giving desired address
*
* exit:
* The computed address is returned.
*
* note:
* base_addr is an unsigned value, while ret_addr is signed. This routine
* used explicit testing and casting to explicitly control type
* conversion, and ensure that we handle the maximum possible range.
*/
static Addr
srelptr(Addr base_addr, PTRDIFF_T delta)
{
if (delta < 0)
return (base_addr - (Addr) (-delta));
return (base_addr + (Addr) delta);
}
/*
* Byte swap a PTRDIFF_T value.
*/
static PTRDIFF_T
swap_ptrdiff(PTRDIFF_T value)
{
PTRDIFF_T r;
uchar_t *dst = (uchar_t *)&r;
uchar_t *src = (uchar_t *)&value;
UL_ASSIGN_BSWAP_XWORD(dst, src);
return (r);
}
/*
* Display exception_range_entry items from the .exception_ranges section
* of a Sun C++ object.
*/
static void
unwind_exception_ranges(Cache *_cache, const char *file, int do_swap)
{
/*
* Translate a PTRDIFF_T self-relative address field of
* an exception_range_entry struct into an address.
*
* entry:
* exc_addr - Address of base of exception_range_entry struct
* cur_ent - Pointer to data in the struct to be translated
*
* _f - Field of struct to be translated
*/
#define SRELPTR(_f) \
srelptr(exc_addr + offsetof(exception_range_entry, _f), cur_ent->_f)
#if defined(_ELF64)
#define MSG_EXR_TITLE MSG_EXR_TITLE_64
#define MSG_EXR_ENTRY MSG_EXR_ENTRY_64
#else
#define MSG_EXR_TITLE MSG_EXR_TITLE_32
#define MSG_EXR_ENTRY MSG_EXR_ENTRY_32
#endif
exception_range_entry scratch, *ent, *cur_ent = &scratch;
char index[MAXNDXSIZE];
Word i, nelts;
Addr addr, addr0 = 0, offset = 0;
Addr exc_addr = _cache->c_shdr->sh_addr;
dbg_print(0, MSG_INTL(MSG_EXR_TITLE));
ent = (exception_range_entry *)(_cache->c_data->d_buf);
nelts = _cache->c_data->d_size / sizeof (exception_range_entry);
for (i = 0; i < nelts; i++, ent++) {
if (do_swap) {
/*
* Copy byte swapped values into the scratch buffer.
* The reserved field is not used, so we skip it.
*/
scratch.ret_addr = swap_ptrdiff(ent->ret_addr);
scratch.length = BSWAP_XWORD(ent->length);
scratch.handler_addr = swap_ptrdiff(ent->handler_addr);
scratch.type_block = swap_ptrdiff(ent->type_block);
} else {
cur_ent = ent;
}
/*
* The table is required to be sorted by the address
* derived from ret_addr, to allow binary searching. Ensure
* that addresses grow monotonically.
*/
addr = SRELPTR(ret_addr);
if ((i != 0) && (addr0 > addr))
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSORT),
file, _cache->c_name, EC_WORD(i));
(void) snprintf(index, MAXNDXSIZE, MSG_ORIG(MSG_FMT_INDEX),
EC_XWORD(i));
dbg_print(0, MSG_INTL(MSG_EXR_ENTRY), index, EC_ADDR(offset),
EC_ADDR(addr), EC_ADDR(cur_ent->length),
EC_ADDR(SRELPTR(handler_addr)),
EC_ADDR(SRELPTR(type_block)));
addr0 = addr;
exc_addr += sizeof (exception_range_entry);
offset += sizeof (exception_range_entry);
}
#undef SRELPTR
#undef MSG_EXR_TITLE
#undef MSG_EXR_ENTRY
}
/*
* For program headers which reflect a single section, check that their values
* and that of the section match.
*/
static void
check_phdr_v_shdr(Phdr *phdr, size_t phndx,
uchar_t osabi, Half mach, Cache *cache, const char *file)
{
Conv_inv_buf_t inv_buf;
#define CHECK(str, pfield, sfield) \
if (phdr->pfield != cache->c_shdr->sfield) { \
fprintf(stderr, MSG_INTL(MSG_SHDR_PHDR_MISMATCH), \
file, \
cache->c_ndx, \
cache->c_name, \
str, \
conv_phdr_type(osabi, mach, phdr->p_type, \
CONV_FMT_ALT_CF, &inv_buf), \
#sfield, \
cache->c_shdr->sfield, \
phndx, \
#pfield, \
phdr->pfield); \
}
CHECK(MSG_INTL(MSG_STR_VADDR), p_vaddr, sh_addr);
CHECK(MSG_INTL(MSG_STR_OFFSET), p_offset, sh_offset);
CHECK(MSG_INTL(MSG_STR_FILESIZE), p_filesz, sh_size);
CHECK(MSG_INTL(MSG_STR_MEMSIZE), p_memsz, sh_size);
CHECK(MSG_INTL(MSG_STR_ALIGNMENT), p_align, sh_addralign);
#undef CHECK
}
/*
* Display information from unwind/exception sections:
*
* - GNU/amd64 .eh_frame and .eh_frame_hdr
* - Sun C++ .exception_ranges
*
*/
static void
unwind(Cache *cache, Word shnum, Word phnum, Ehdr *ehdr, uchar_t osabi,
const char *file, Elf *elf, uint_t flags)
{
static Word phdr_types[] = { PT_SUNW_UNWIND, PT_SUNW_EH_FRAME };
Word cnt;
Phdr *uphdr = NULL;
size_t phndx;
gnu_eh_state_t eh_state;
/*
* Historical background: .eh_frame and .eh_frame_hdr sections
* come from the GNU compilers (particularly C++), and are used
* under all architectures. Their format is based on DWARF. When
* the amd64 ABI was defined, these sections were adopted wholesale
* from the existing practice.
*
* When amd64 support was added to Solaris, support for these
* sections was added, using the SHT_AMD64_UNWIND section type
* to identify them. At first, we ignored them in objects for
* non-amd64 targets, but later broadened our support to include
* other architectures in order to better support gcc-generated
* objects.
*
* .exception_ranges implement the same basic concepts, but
* were invented at Sun for the Sun C++ compiler.
*
* We match these sections by name, rather than section type,
* because they can come in as either SHT_AMD64_UNWIND, or as
* SHT_PROGBITS, and because the type isn't enough to determine
* how they should be interpreted.
*/
/* Find the program header for .eh_frame_hdr if present */
if (phnum) {
uphdr = getphdr(phnum, phdr_types,
sizeof (phdr_types) / sizeof (*phdr_types), file, elf,
&phndx);
}
/*
* eh_state is used to retain data used by unwind_eh_frame()
* across calls.
*/
bzero(&eh_state, sizeof (eh_state));
for (cnt = 1; cnt < shnum; cnt++) {
Cache *_cache = &cache[cnt];
Shdr *shdr = _cache->c_shdr;
int is_exrange;
/*
* Skip sections of the wrong type. On amd64, they
* can be SHT_AMD64_UNWIND. On all platforms, they
* can be SHT_PROGBITS (including amd64, if using
* the GNU compilers).
*
* Skip anything other than these two types. The name
* test below will thin out the SHT_PROGBITS that don't apply.
*/
if ((shdr->sh_type != SHT_PROGBITS) &&
(shdr->sh_type != SHT_AMD64_UNWIND))
continue;
/*
* Only sections with certain well known names are of interest.
* These are:
*
* .eh_frame - amd64/GNU-compiler unwind sections
* .eh_frame_hdr - Sorted table referencing .eh_frame
* .exception_ranges - Sun C++ unwind sections
*
* We do a prefix comparison, allowing for naming conventions
* like .eh_frame.foo, hence the use of strncmp() rather than
* strcmp(). This means that we only really need to test for
* .eh_frame, as it's a prefix of .eh_frame_hdr.
*/
is_exrange = strncmp(_cache->c_name,
MSG_ORIG(MSG_SCN_EXRANGE), MSG_SCN_EXRANGE_SIZE) == 0;
if ((strncmp(_cache->c_name, MSG_ORIG(MSG_SCN_FRM),
MSG_SCN_FRM_SIZE) != 0) && !is_exrange)
continue;
if (!match(MATCH_F_ALL, _cache->c_name, cnt, shdr->sh_type))
continue;
if ((_cache->c_data == NULL) || (_cache->c_data->d_buf == NULL))
continue;
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_ELF_SCN_UNWIND), _cache->c_name);
if (is_exrange) {
unwind_exception_ranges(_cache, file,
_elf_sys_encoding() != ehdr->e_ident[EI_DATA]);
} else {
if ((uphdr != NULL) && (strcmp(_cache->c_name,
MSG_ORIG(MSG_SCN_FRMHDR)) == 0)) {
check_phdr_v_shdr(uphdr, phndx, osabi,
ehdr->e_machine, _cache, file);
}
unwind_eh_frame(cache, cnt, shnum, uphdr, ehdr,
&eh_state, osabi, file, flags);
}
}
}
/*
* Initialize a symbol table state structure
*
* entry:
* state - State structure to be initialized
* cache - Cache of all section headers
* shnum - # of sections in cache
* secndx - Index of symbol table section
* ehdr - ELF header for file
* versym - Information about versym section
* file - Name of file
* flags - Command line option flags
*/
static int
init_symtbl_state(SYMTBL_STATE *state, Cache *cache, Word shnum, Word secndx,
Ehdr *ehdr, uchar_t osabi, VERSYM_STATE *versym, const char *file,
uint_t flags)
{
Shdr *shdr;
state->file = file;
state->ehdr = ehdr;
state->cache = cache;
state->osabi = osabi;
state->shnum = shnum;
state->seccache = &cache[secndx];
state->secndx = secndx;
state->secname = state->seccache->c_name;
state->flags = flags;
state->shxndx.checked = 0;
state->shxndx.data = NULL;
state->shxndx.n = 0;
shdr = state->seccache->c_shdr;
/*
* Check the symbol data and per-item size.
*/
if ((shdr->sh_entsize == 0) || (shdr->sh_size == 0)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, state->secname);
return (0);
}
if ((state->seccache->c_data == NULL) ||
(state->seccache->c_data->d_buf == NULL))
return (0);
/* LINTED */
state->symn = (Word)(shdr->sh_size / shdr->sh_entsize);
state->sym = (Sym *)state->seccache->c_data->d_buf;
/*
* Check associated string table section.
*/
if ((shdr->sh_link == 0) || (shdr->sh_link >= shnum)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHLINK),
file, state->secname, EC_WORD(shdr->sh_link));
return (0);
}
/*
* Determine if there is a associated Versym section
* with this Symbol Table.
*/
if (versym && versym->cache &&
(versym->cache->c_shdr->sh_link == state->secndx))
state->versym = versym;
else
state->versym = NULL;
return (1);
}
/*
* Determine the extended section index used for symbol tables entries.
*/
static void
symbols_getxindex(SYMTBL_STATE *state)
{
uint_t symn;
Word symcnt;
state->shxndx.checked = 1; /* Note that we've been called */
for (symcnt = 1; symcnt < state->shnum; symcnt++) {
Cache *_cache = &state->cache[symcnt];
Shdr *shdr = _cache->c_shdr;
if ((shdr->sh_type != SHT_SYMTAB_SHNDX) ||
(shdr->sh_link != state->secndx))
continue;
if (shdr->sh_entsize == 0)
symn = 0;
else
symn = (uint_t)(shdr->sh_size / shdr->sh_entsize);
if (symn == 0)
continue;
if ((_cache->c_data == NULL) || (_cache->c_data->d_buf == NULL))
continue;
state->shxndx.data = _cache->c_data->d_buf;
state->shxndx.n = symn;
return;
}
}
/*
* Produce a line of output for the given symbol
*
* entry:
* state - Symbol table state
* symndx - Index of symbol within the table
* info - Value of st_info (indicates local/global range)
* symndx_disp - Index to display. This may not be the same
* as symndx if the display is relative to the logical
* combination of the SUNW_ldynsym/dynsym tables.
* sym - Symbol to display
*/
static void
output_symbol(SYMTBL_STATE *state, Word symndx, Word info, Word disp_symndx,
Sym *sym)
{
/*
* Symbol types for which we check that the specified
* address/size land inside the target section.
*/
static const int addr_symtype[] = {
0, /* STT_NOTYPE */
1, /* STT_OBJECT */
1, /* STT_FUNC */
0, /* STT_SECTION */
0, /* STT_FILE */
1, /* STT_COMMON */
0, /* STT_TLS */
0, /* 7 */
0, /* 8 */
0, /* 9 */
0, /* 10 */
0, /* 11 */
0, /* 12 */
0, /* STT_SPARC_REGISTER */
0, /* 14 */
0, /* 15 */
};
#if STT_NUM != (STT_TLS + 1)
#error "STT_NUM has grown. Update addr_symtype[]"
#endif
char index[MAXNDXSIZE];
const char *symname, *sec;
Versym verndx;
int gnuver;
uchar_t type;
Shdr *tshdr;
Word shndx = 0;
Conv_inv_buf_t inv_buf;
/* Ensure symbol index is in range */
if (symndx >= state->symn) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSYMNDX),
state->file, state->secname, EC_WORD(symndx));
return;
}
/*
* If we are using extended symbol indexes, find the
* corresponding SHN_SYMTAB_SHNDX table.
*/
if ((sym->st_shndx == SHN_XINDEX) && (state->shxndx.checked == 0))
symbols_getxindex(state);
/* LINTED */
symname = string(state->seccache, symndx,
&state->cache[state->seccache->c_shdr->sh_link], state->file,
sym->st_name);
tshdr = NULL;
sec = NULL;
if (state->ehdr->e_type == ET_CORE) {
sec = (char *)MSG_INTL(MSG_STR_UNKNOWN);
} else if (state->flags & FLG_CTL_FAKESHDR) {
/*
* If we are using fake section headers derived from
* the program headers, then the section indexes
* in the symbols do not correspond to these headers.
* The section names are not available, so all we can
* do is to display them in numeric form.
*/
sec = conv_sym_shndx(state->osabi, state->ehdr->e_machine,
sym->st_shndx, CONV_FMT_DECIMAL, &inv_buf);
} else if ((sym->st_shndx < SHN_LORESERVE) &&
(sym->st_shndx < state->shnum)) {
shndx = sym->st_shndx;
tshdr = state->cache[shndx].c_shdr;
sec = state->cache[shndx].c_name;
} else if (sym->st_shndx == SHN_XINDEX) {
if (state->shxndx.data) {
Word _shxndx;
if (symndx > state->shxndx.n) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADSYMXINDEX1),
state->file, state->secname,
EC_WORD(symndx));
} else if ((_shxndx =
state->shxndx.data[symndx]) > state->shnum) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADSYMXINDEX2),
state->file, state->secname,
EC_WORD(symndx), EC_WORD(_shxndx));
} else {
shndx = _shxndx;
tshdr = state->cache[shndx].c_shdr;
sec = state->cache[shndx].c_name;
}
} else {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADSYMXINDEX3),
state->file, state->secname, EC_WORD(symndx));
}
} else if ((sym->st_shndx < SHN_LORESERVE) &&
(sym->st_shndx >= state->shnum)) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADSYM5), state->file,
state->secname, EC_WORD(symndx),
demangle(symname, state->flags), sym->st_shndx);
}
/*
* If versioning is available display the
* version index. If not, then use 0.
*/
if (state->versym) {
Versym test_verndx;
verndx = test_verndx = state->versym->data[symndx];
gnuver = state->versym->gnu_full;
/*
* Check to see if this is a defined symbol with a
* version index that is outside the valid range for
* the file. The interpretation of this depends on
* the style of versioning used by the object.
*
* Versions >= VER_NDX_LORESERVE have special meanings,
* and are exempt from this checking.
*
* GNU style version indexes use the top bit of the
* 16-bit index value (0x8000) as the "hidden bit".
* We must mask off this bit in order to compare
* the version against the maximum value.
*/
if (gnuver)
test_verndx &= ~0x8000;
if ((test_verndx > state->versym->max_verndx) &&
(verndx < VER_NDX_LORESERVE))
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADVER),
state->file, state->secname, EC_WORD(symndx),
EC_HALF(test_verndx), state->versym->max_verndx);
} else {
verndx = 0;
gnuver = 0;
}
/*
* Error checking for TLS.
*/
type = ELF_ST_TYPE(sym->st_info);
if (type == STT_TLS) {
if (tshdr &&
(sym->st_shndx != SHN_UNDEF) &&
((tshdr->sh_flags & SHF_TLS) == 0)) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADSYM3), state->file,
state->secname, EC_WORD(symndx),
demangle(symname, state->flags));
}
} else if ((type != STT_SECTION) && sym->st_size &&
tshdr && (tshdr->sh_flags & SHF_TLS)) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADSYM4), state->file,
state->secname, EC_WORD(symndx),
demangle(symname, state->flags));
}
/*
* If a symbol with non-zero size has a type that
* specifies an address, then make sure the location
* it references is actually contained within the
* section. UNDEF symbols don't count in this case,
* so we ignore them.
*
* The meaning of the st_value field in a symbol
* depends on the type of object. For a relocatable
* object, it is the offset within the section.
* For sharable objects, it is the offset relative to
* the base of the object, and for other types, it is
* the virtual address. To get an offset within the
* section for non-ET_REL files, we subtract the
* base address of the section.
*/
if (addr_symtype[type] && (sym->st_size > 0) &&
(sym->st_shndx != SHN_UNDEF) && ((sym->st_shndx < SHN_LORESERVE) ||
(sym->st_shndx == SHN_XINDEX)) && (tshdr != NULL)) {
Word v = sym->st_value;
if (state->ehdr->e_type != ET_REL)
v -= tshdr->sh_addr;
if (((v + sym->st_size) > tshdr->sh_size)) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADSYM6), state->file,
state->secname, EC_WORD(symndx),
demangle(symname, state->flags),
EC_WORD(shndx), EC_XWORD(tshdr->sh_size),
EC_XWORD(sym->st_value), EC_XWORD(sym->st_size));
}
}
/*
* A typical symbol table uses the sh_info field to indicate one greater
* than the symbol table index of the last local symbol, STB_LOCAL.
* Therefore, symbol indexes less than sh_info should have local
* binding. Symbol indexes greater than, or equal to sh_info, should
* have global binding. Note, we exclude UNDEF/NOTY symbols with zero
* value and size, as these symbols may be the result of an mcs(1)
* section deletion.
*/
if (info) {
uchar_t bind = ELF_ST_BIND(sym->st_info);
if ((symndx < info) && (bind != STB_LOCAL)) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADSYM7), state->file,
state->secname, EC_WORD(symndx),
demangle(symname, state->flags), EC_XWORD(info));
} else if ((symndx >= info) && (bind == STB_LOCAL) &&
((sym->st_shndx != SHN_UNDEF) ||
(ELF_ST_TYPE(sym->st_info) != STT_NOTYPE) ||
(sym->st_size != 0) || (sym->st_value != 0))) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADSYM8), state->file,
state->secname, EC_WORD(symndx),
demangle(symname, state->flags), EC_XWORD(info));
}
}
(void) snprintf(index, MAXNDXSIZE,
MSG_ORIG(MSG_FMT_INDEX), EC_XWORD(disp_symndx));
Elf_syms_table_entry(0, ELF_DBG_ELFDUMP, index, state->osabi,
state->ehdr->e_machine, sym, verndx, gnuver, sec, symname);
}
/*
* Process a SHT_SUNW_cap capabilities section.
*/
static int
cap_section(const char *file, Cache *cache, Word shnum, Cache *ccache,
uchar_t osabi, Ehdr *ehdr, uint_t flags)
{
SYMTBL_STATE state;
Word cnum, capnum, nulls, symcaps;
int descapndx, objcap, title;
Cap *cap = (Cap *)ccache->c_data->d_buf;
Shdr *cishdr = NULL, *cshdr = ccache->c_shdr;
Cache *cicache = NULL, *strcache = NULL;
Capinfo *capinfo = NULL;
Word capinfonum = 0;
const char *strs = NULL;
size_t strs_size = 0;
if ((cshdr->sh_entsize == 0) || (cshdr->sh_size == 0)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, ccache->c_name);
return (0);
}
/*
* If this capabilities section is associated with symbols, then the
* sh_link field points to the associated capabilities information
* section. The sh_link field of the capabilities information section
* points to the associated symbol table.
*/
if (cshdr->sh_link) {
Cache *scache;
Shdr *sshdr;
/*
* Validate that the sh_link field points to a capabilities
* information section.
*/
if (cshdr->sh_link >= shnum) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHLINK),
file, ccache->c_name, EC_WORD(cshdr->sh_link));
return (0);
}
cicache = &cache[cshdr->sh_link];
cishdr = cicache->c_shdr;
if (cishdr->sh_type != SHT_SUNW_capinfo) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_INVCAP),
file, ccache->c_name, EC_WORD(cshdr->sh_link));
return (0);
}
capinfo = cicache->c_data->d_buf;
capinfonum = (Word)(cishdr->sh_size / cishdr->sh_entsize);
/*
* Validate that the sh_link field of the capabilities
* information section points to a valid symbol table.
*/
if ((cishdr->sh_link == 0) || (cishdr->sh_link >= shnum)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHLINK),
file, cicache->c_name, EC_WORD(cishdr->sh_link));
return (0);
}
scache = &cache[cishdr->sh_link];
sshdr = scache->c_shdr;
if ((sshdr->sh_type != SHT_SYMTAB) &&
(sshdr->sh_type != SHT_DYNSYM)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_INVCAPINFO1),
file, cicache->c_name, EC_WORD(cishdr->sh_link));
return (0);
}
if (!init_symtbl_state(&state, cache, shnum,
cishdr->sh_link, ehdr, osabi, NULL, file, flags))
return (0);
}
/*
* If this capabilities section contains capability string entries,
* then determine the associated string table. Capabilities entries
* that define names require that the capability section indicate
* which string table to use via sh_info.
*/
if (cshdr->sh_info) {
Shdr *strshdr;
/*
* Validate that the sh_info field points to a string table.
*/
if (cshdr->sh_info >= shnum) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHLINK),
file, ccache->c_name, EC_WORD(cshdr->sh_info));
return (0);
}
strcache = &cache[cshdr->sh_info];
strshdr = strcache->c_shdr;
if (strshdr->sh_type != SHT_STRTAB) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_INVCAP),
file, ccache->c_name, EC_WORD(cshdr->sh_info));
return (0);
}
strs = (const char *)strcache->c_data->d_buf;
strs_size = strcache->c_data->d_size;
}
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_ELF_SCN_CAP), ccache->c_name);
capnum = (Word)(cshdr->sh_size / cshdr->sh_entsize);
nulls = symcaps = 0;
objcap = title = 1;
descapndx = -1;
/*
* Traverse the capabilities section printing each capability group.
* The first capabilities group defines any object capabilities. Any
* following groups define symbol capabilities. In the case where no
* object capabilities exist, but symbol capabilities do, a single
* CA_SUNW_NULL terminator for the object capabilities exists.
*/
for (cnum = 0; cnum < capnum; cap++, cnum++) {
if (cap->c_tag == CA_SUNW_NULL) {
/*
* A CA_SUNW_NULL tag terminates a capabilities group.
* If the first capabilities tag is CA_SUNW_NULL, then
* no object capabilities exist.
*/
if ((nulls++ == 0) && (cnum == 0))
objcap = 0;
title = 1;
} else {
if (title) {
if (nulls == 0) {
/*
* If this capabilities group represents
* the object capabilities (i.e., no
* CA_SUNW_NULL tag has been processed
* yet), then display an object
* capabilities title.
*/
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0,
MSG_INTL(MSG_OBJ_CAP_TITLE));
} else {
/*
* If this is a symbols capabilities
* group (i.e., a CA_SUNW_NULL tag has
* already be found that terminates
* the object capabilities group), then
* display a symbol capabilities title,
* and retain this capabilities index
* for later processing.
*/
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0,
MSG_INTL(MSG_SYM_CAP_TITLE));
descapndx = cnum;
}
Elf_cap_title(0);
title = 0;
}
/*
* Print the capabilities data.
*
* Note that CA_SUNW_PLAT, CA_SUNW_MACH and CA_SUNW_ID
* entries require a string table, which should have
* already been established.
*/
if ((strs == NULL) && ((cap->c_tag == CA_SUNW_PLAT) ||
(cap->c_tag == CA_SUNW_MACH) ||
(cap->c_tag == CA_SUNW_ID))) {
(void) fprintf(stderr,
MSG_INTL(MSG_WARN_INVCAP3), file,
EC_WORD(elf_ndxscn(ccache->c_scn)),
ccache->c_name, EC_WORD(cshdr->sh_info));
}
Elf_cap_entry(0, cap, cnum, strs, strs_size,
ehdr->e_machine);
}
/*
* If this CA_SUNW_NULL tag terminates a symbol capabilities
* group, determine the associated symbols.
*/
if ((cap->c_tag == CA_SUNW_NULL) && (nulls > 1) &&
(descapndx != -1)) {
Capinfo *cip;
Word inum;
symcaps++;
/*
* Make sure we've discovered a SHT_SUNW_capinfo table.
*/
if ((cip = capinfo) == NULL) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_INVCAP), file,
ccache->c_name, EC_WORD(cshdr->sh_link));
return (0);
}
/*
* Determine what symbols reference this capabilities
* group.
*/
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_CAPINFO_ENTRIES));
Elf_syms_table_title(0, ELF_DBG_ELFDUMP);
for (inum = 1, cip++; inum < capinfonum;
inum++, cip++) {
Word gndx = (Word)ELF_C_GROUP(*cip);
if (gndx && (gndx == descapndx)) {
output_symbol(&state, inum, 0,
inum, state.sym + inum);
}
}
descapndx = -1;
continue;
}
/*
* An SF1_SUNW_ADDR32 software capability tag in a 32-bit
* object is suspicious as it has no effect.
*/
if ((cap->c_tag == CA_SUNW_SF_1) &&
(ehdr->e_ident[EI_CLASS] == ELFCLASS32) &&
(cap->c_un.c_val & SF1_SUNW_ADDR32)) {
(void) fprintf(stderr, MSG_INTL(MSG_WARN_INADDR32SF1),
file, ccache->c_name);
}
}
/*
* If this is a dynamic object, with symbol capabilities, then a
* .SUNW_capchain section should exist. This section contains a chain
* of symbol indexes for each capabilities family. This is the list
* that is searched by ld.so.1 to determine the best capabilities
* candidate.
*
* Note, more than one capabilities lead symbol can point to the same
* family chain. For example, a weak/global pair of symbols can both
* represent the same family of capabilities symbols. Therefore, to
* display all possible families we traverse the capabilities
* information section looking for CAPINFO_SUNW_GLOB lead symbols.
* From these we determine the associated capabilities chain to inspect.
*/
if (symcaps &&
((ehdr->e_type == ET_EXEC) || (ehdr->e_type == ET_DYN))) {
Capinfo *cip;
Capchain *chain;
Cache *chcache;
Shdr *chshdr;
Word chainnum, inum;
/*
* Validate that the sh_info field of the capabilities
* information section points to a capabilities chain section.
*/
if (cishdr->sh_info >= shnum) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHLINK),
file, cicache->c_name, EC_WORD(cishdr->sh_info));
return (0);
}
chcache = &cache[cishdr->sh_info];
chshdr = chcache->c_shdr;
if (chshdr->sh_type != SHT_SUNW_capchain) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_INVCAPINFO2),
file, cicache->c_name, EC_WORD(cishdr->sh_info));
return (0);
}
chainnum = (Word)(chshdr->sh_size / chshdr->sh_entsize);
chain = (Capchain *)chcache->c_data->d_buf;
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_ELF_SCN_CAPCHAIN), chcache->c_name);
/*
* Traverse the capabilities information section looking for
* CAPINFO_SUNW_GLOB lead capabilities symbols.
*/
cip = capinfo;
for (inum = 1, cip++; inum < capinfonum; inum++, cip++) {
const char *name;
Sym *sym;
Word sndx, cndx;
Word gndx = (Word)ELF_C_GROUP(*cip);
if ((gndx == 0) || (gndx != CAPINFO_SUNW_GLOB))
continue;
/*
* Determine the symbol that is associated with this
* capability information entry, and use this to
* identify this capability family.
*/
sym = (Sym *)(state.sym + inum);
name = string(cicache, inum, strcache, file,
sym->st_name);
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_CAPCHAIN_TITLE), name);
dbg_print(0, MSG_INTL(MSG_CAPCHAIN_ENTRY));
cndx = (Word)ELF_C_SYM(*cip);
/*
* Traverse this families chain and identify each
* family member.
*/
for (;;) {
char _chain[MAXNDXSIZE], _symndx[MAXNDXSIZE];
if (cndx >= chainnum) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_INVCAPINFO3), file,
cicache->c_name, EC_WORD(inum),
EC_WORD(cndx));
break;
}
if ((sndx = chain[cndx]) == 0)
break;
/*
* Determine this entries symbol reference.
*/
if (sndx > state.symn) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_CHBADSYMNDX), file,
EC_WORD(sndx), chcache->c_name,
EC_WORD(cndx));
name = MSG_INTL(MSG_STR_UNKNOWN);
} else {
sym = (Sym *)(state.sym + sndx);
name = string(chcache, sndx,
strcache, file, sym->st_name);
}
/*
* Display the family member.
*/
(void) snprintf(_chain, MAXNDXSIZE,
MSG_ORIG(MSG_FMT_INTEGER), cndx);
(void) snprintf(_symndx, MAXNDXSIZE,
MSG_ORIG(MSG_FMT_INDEX2), EC_WORD(sndx));
dbg_print(0, MSG_ORIG(MSG_FMT_CHAIN_INFO),
_chain, _symndx, demangle(name, flags));
cndx++;
}
}
}
return (objcap);
}
/*
* Print the capabilities.
*
* A .SUNW_cap section can contain one or more, CA_SUNW_NULL terminated,
* capabilities groups. The first group defines the object capabilities.
* This group defines the minimum capability requirements of the entire
* object file. If this is a dynamic object, this group should be associated
* with a PT_SUNWCAP program header.
*
* Additional capabilities groups define the association of individual symbols
* to specific capabilities.
*/
static void
cap(const char *file, Cache *cache, Word shnum, Word phnum, Ehdr *ehdr,
uchar_t osabi, Elf *elf, uint_t flags)
{
Word cnt;
Shdr *cshdr = NULL;
Cache *ccache = NULL;
Phdr *uphdr = NULL;
size_t phndx;
/*
* Determine if a global capabilities header exists.
*/
if (phnum) {
Phdr *phdr;
if ((phdr = elf_getphdr(elf)) == NULL) {
failure(file, MSG_ORIG(MSG_ELF_GETPHDR));
return;
}
for (cnt = 0; cnt < phnum; phdr++, cnt++) {
if (phdr->p_type == PT_SUNWCAP) {
uphdr = phdr;
phndx = cnt;
break;
}
}
}
/*
* Determine if a capabilities section exists.
*/
for (cnt = 1; cnt < shnum; cnt++) {
Cache *_cache = &cache[cnt];
Shdr *shdr = _cache->c_shdr;
/*
* Process any capabilities information.
*/
if (shdr->sh_type == SHT_SUNW_cap) {
if (cap_section(file, cache, shnum, _cache, osabi,
ehdr, flags)) {
/*
* If this section defined an object capability
* group, retain the section information for
* program header validation.
*/
ccache = _cache;
cshdr = shdr;
}
continue;
}
}
if ((cshdr == NULL) && (uphdr == NULL))
return;
if ((uphdr != NULL) && (cshdr == NULL))
(void) fprintf(stderr, MSG_INTL(MSG_WARN_INVCAP1), file);
/*
* If this object is an executable or shared object, and it provided
* an object capabilities group, then the group should have an
* accompanying PT_SUNWCAP program header.
*/
if (cshdr && ((ehdr->e_type == ET_EXEC) || (ehdr->e_type == ET_DYN))) {
if (uphdr == NULL) {
(void) fprintf(stderr, MSG_INTL(MSG_WARN_INVCAP2),
file, EC_WORD(elf_ndxscn(ccache->c_scn)),
ccache->c_name);
} else {
check_phdr_v_shdr(uphdr, phndx, osabi, ehdr->e_machine,
ccache, file);
}
}
}
/*
* Print the interpreter.
*/
static void
interp(const char *file, Cache *cache, Word shnum, Word phnum, Elf *elf,
Ehdr *ehdr)
{
static Word phdr_types[] = { PT_INTERP };
Word cnt;
Shdr *ishdr = NULL;
Cache *icache = NULL;
Phdr *iphdr = NULL;
size_t phndx;
/*
* Determine if an interp header exists.
*/
if (phnum) {
iphdr = getphdr(phnum, phdr_types,
sizeof (phdr_types) / sizeof (*phdr_types), file, elf,
&phndx);
}
if (iphdr == NULL)
return;
/*
* Determine if an interp section exists.
*/
for (cnt = 1; cnt < shnum; cnt++) {
Cache *_cache = &cache[cnt];
Shdr *shdr = _cache->c_shdr;
/*
* Scan sections to find a section which contains the PT_INTERP
* string. The target section can't be in a NOBITS section.
*/
if ((shdr->sh_type == SHT_NOBITS) ||
(iphdr->p_offset < shdr->sh_offset) ||
(iphdr->p_offset + iphdr->p_filesz) >
(shdr->sh_offset + shdr->sh_size))
continue;
icache = _cache;
ishdr = shdr;
break;
}
/*
* Print the interpreter string based on the offset defined in the
* program header, as this is the offset used by the kernel.
*/
if ((ishdr != NULL) &&
(icache != NULL) &&
(icache->c_data != NULL) &&
(icache->c_data->d_buf != NULL) &&
(icache->c_data->d_size > 0)) {
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_ELF_SCN_INTERP), icache->c_name);
dbg_print(0, MSG_ORIG(MSG_FMT_INDENT),
(char *)icache->c_data->d_buf +
(iphdr->p_offset - ishdr->sh_offset));
} else {
(void) fprintf(stderr, MSG_INTL(MSG_WARN_INVINTERP1), file);
}
/*
* If there are any inconsistences between the program header and
* section information, flag them.
*/
if (icache != NULL) {
check_phdr_v_shdr(iphdr, phndx, ELFOSABI_SOLARIS,
ehdr->e_machine, icache, file);
}
}
/*
* Print the syminfo section.
*/
static void
syminfo(Cache *cache, Word shnum, Ehdr *ehdr, uchar_t osabi, const char *file)
{
Shdr *infoshdr;
Syminfo *info;
Sym *syms;
Dyn *dyns;
Word infonum, cnt, ndx, symnum, dynnum;
Cache *infocache = NULL, *dyncache = NULL, *symsec, *strsec;
Boolean *dynerr = NULL;
for (cnt = 1; cnt < shnum; cnt++) {
if (cache[cnt].c_shdr->sh_type == SHT_SUNW_syminfo) {
infocache = &cache[cnt];
break;
}
}
if (infocache == NULL)
return;
infoshdr = infocache->c_shdr;
if ((infoshdr->sh_entsize == 0) || (infoshdr->sh_size == 0)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, infocache->c_name);
return;
}
if ((infocache->c_data == NULL) || (infocache->c_data->d_buf == NULL))
return;
infonum = (Word)(infoshdr->sh_size / infoshdr->sh_entsize);
info = (Syminfo *)infocache->c_data->d_buf;
/*
* If there is no associated dynamic section, determine if one
* is needed, and if so issue a warning. If there is an
* associated dynamic section, validate it and get the data buffer
* for it.
*/
dyns = NULL;
dynnum = 0;
if (infoshdr->sh_info == 0) {
Syminfo *_info = info + 1;
for (ndx = 1; ndx < infonum; ndx++, _info++) {
if ((_info->si_flags == 0) && (_info->si_boundto == 0))
continue;
if (_info->si_boundto < SYMINFO_BT_LOWRESERVE)
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADSHINFO), file,
infocache->c_name,
EC_WORD(infoshdr->sh_info));
}
} else if ((infoshdr->sh_info >= shnum) ||
(cache[infoshdr->sh_info].c_shdr->sh_type != SHT_DYNAMIC)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHINFO),
file, infocache->c_name, EC_WORD(infoshdr->sh_info));
} else {
dyncache = &cache[infoshdr->sh_info];
if ((dyncache->c_data == NULL) ||
((dyns = dyncache->c_data->d_buf) == NULL)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, dyncache->c_name);
}
if (dyns != NULL) {
if ((dyncache->c_shdr->sh_entsize == 0) ||
(dyncache->c_shdr->sh_size == 0)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, dyncache->c_name);
return;
}
dynnum = dyncache->c_shdr->sh_size /
dyncache->c_shdr->sh_entsize;
/*
* We validate the type of dynamic elements referenced
* from the syminfo. This array is used report any
* bad dynamic entries.
*/
if ((dynerr = calloc(dynnum, sizeof (*dynerr))) ==
NULL) {
int err = errno;
(void) fprintf(stderr, MSG_INTL(MSG_ERR_MALLOC),
file, strerror(err));
return;
}
}
}
/*
* Get the data buffer for the associated symbol table and string table.
*/
if (stringtbl(cache, 1, cnt, shnum, file,
&symnum, &symsec, &strsec) == 0)
return;
syms = symsec->c_data->d_buf;
/*
* Loop through the syminfo entries.
*/
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_ELF_SCN_SYMINFO), infocache->c_name);
Elf_syminfo_title(0);
for (ndx = 1, info++; ndx < infonum; ndx++, info++) {
Sym *sym;
const char *needed, *name;
Word expect_dt;
Word boundto = info->si_boundto;
if ((info->si_flags == 0) && (boundto == 0))
continue;
sym = &syms[ndx];
name = string(infocache, ndx, strsec, file, sym->st_name);
/* Is si_boundto set to one of the reserved values? */
if (boundto >= SYMINFO_BT_LOWRESERVE) {
Elf_syminfo_entry(0, ndx, info, name, NULL);
continue;
}
/*
* si_boundto is referencing a dynamic section. If we don't
* have one, an error was already issued above, so it suffices
* to display an empty string. If we are out of bounds, then
* report that and then display an empty string.
*/
if ((dyns == NULL) || (boundto >= dynnum)) {
if (dyns != NULL)
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADSIDYNNDX), file,
infocache->c_ndx, infocache->c_name,
EC_WORD(ndx), EC_WORD(dynnum - 1),
EC_WORD(boundto));
Elf_syminfo_entry(0, ndx, info, name,
MSG_ORIG(MSG_STR_EMPTY));
continue;
}
/*
* The si_boundto reference expects a specific dynamic element
* type at the given index. The dynamic element is always a
* string that gives an object name. The specific type depends
* on the si_flags present. Ensure that we've got the right
* type.
*/
if (info->si_flags & SYMINFO_FLG_FILTER)
expect_dt = DT_SUNW_FILTER;
else if (info->si_flags & SYMINFO_FLG_AUXILIARY)
expect_dt = DT_SUNW_AUXILIARY;
else if (info->si_flags & (SYMINFO_FLG_DIRECT |
SYMINFO_FLG_LAZYLOAD | SYMINFO_FLG_DIRECTBIND))
expect_dt = DT_NEEDED;
else
expect_dt = DT_NULL; /* means we ignore the type */
if ((dyns[boundto].d_tag != expect_dt) &&
(expect_dt != DT_NULL)) {
Conv_inv_buf_t buf1, buf2;
/* Only complain about each dynamic element once */
if (!dynerr[boundto]) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADSIDYNTAG),
file, infocache->c_ndx, infocache->c_name,
EC_WORD(ndx), dyncache->c_ndx,
dyncache->c_name, EC_WORD(boundto),
conv_dyn_tag(expect_dt, osabi,
ehdr->e_machine, CONV_FMT_ALT_CF, &buf1),
conv_dyn_tag(dyns[boundto].d_tag, osabi,
ehdr->e_machine, CONV_FMT_ALT_CF, &buf2));
dynerr[boundto] = TRUE;
}
}
/*
* Whether or not the DT item we're pointing at is
* of the right type, if it's a type we recognize as
* providing a string, go ahead and show it. Otherwise
* an empty string.
*/
switch (dyns[boundto].d_tag) {
case DT_NEEDED:
case DT_SONAME:
case DT_RPATH:
case DT_RUNPATH:
case DT_CONFIG:
case DT_DEPAUDIT:
case DT_USED:
case DT_AUDIT:
case DT_SUNW_AUXILIARY:
case DT_SUNW_FILTER:
case DT_FILTER:
case DT_AUXILIARY:
needed = string(infocache, boundto,
strsec, file, dyns[boundto].d_un.d_val);
break;
default:
needed = MSG_ORIG(MSG_STR_EMPTY);
}
Elf_syminfo_entry(0, ndx, info, name, needed);
}
if (dyns != NULL)
free(dynerr);
}
/*
* Print version definition section entries.
*/
static void
version_def(Verdef *vdf, Word vdf_num, Cache *vcache, Cache *scache,
const char *file)
{
Word cnt;
char index[MAXNDXSIZE];
Elf_ver_def_title(0);
for (cnt = 1; cnt <= vdf_num; cnt++,
vdf = (Verdef *)((uintptr_t)vdf + vdf->vd_next)) {
Conv_ver_flags_buf_t ver_flags_buf;
const char *name, *dep;
Half vcnt = vdf->vd_cnt - 1;
Half ndx = vdf->vd_ndx;
Verdaux *vdap = (Verdaux *)((uintptr_t)vdf + vdf->vd_aux);
/*
* Obtain the name and first dependency (if any).
*/
name = string(vcache, cnt, scache, file, vdap->vda_name);
vdap = (Verdaux *)((uintptr_t)vdap + vdap->vda_next);
if (vcnt)
dep = string(vcache, cnt, scache, file, vdap->vda_name);
else
dep = MSG_ORIG(MSG_STR_EMPTY);
(void) snprintf(index, MAXNDXSIZE, MSG_ORIG(MSG_FMT_INDEX),
EC_XWORD(ndx));
Elf_ver_line_1(0, index, name, dep,
conv_ver_flags(vdf->vd_flags, 0, &ver_flags_buf));
/*
* Print any additional dependencies.
*/
if (vcnt) {
vdap = (Verdaux *)((uintptr_t)vdap + vdap->vda_next);
for (vcnt--; vcnt; vcnt--,
vdap = (Verdaux *)((uintptr_t)vdap +
vdap->vda_next)) {
dep = string(vcache, cnt, scache, file,
vdap->vda_name);
Elf_ver_line_2(0, MSG_ORIG(MSG_STR_EMPTY), dep);
}
}
}
}
/*
* Print version needed section entries.
*
* entry:
* vnd - Address of verneed data
* vnd_num - # of Verneed entries
* vcache - Cache of verneed section being processed
* scache - Cache of associated string table section
* file - Name of object being processed.
* versym - Information about versym section
*
* exit:
* The versions have been printed. If GNU style versioning
* is in effect, versym->max_verndx has been updated to
* contain the largest version index seen.
*
* note:
* The versym section of an object that follows the original
* Solaris versioning rules only contains indexes into the verdef
* section. Symbols defined in other objects (UNDEF) are given
* a version of 0, indicating that they are not defined by
* this file, and the Verneed entries do not have associated version
* indexes. For these reasons, we do not display a version index
* for original-style Verneed sections.
*
* The GNU versioning extensions alter this: Symbols defined in other
* objects receive a version index in the range above those defined
* by the Verdef section, and the vna_other field of the Vernaux
* structs inside the Verneed section contain the version index for
* that item. We therefore display the index when showing the
* contents of a GNU style Verneed section. You should not
* necessarily expect these indexes to appear in sorted
* order --- it seems that the GNU ld assigns the versions as
* symbols are encountered during linking, and then the results
* are assembled into the Verneed section afterwards.
*/
static void
version_need(Verneed *vnd, Word vnd_num, Cache *vcache, Cache *scache,
const char *file, VERSYM_STATE *versym)
{
Word cnt;
char index[MAXNDXSIZE];
const char *index_str;
Elf_ver_need_title(0, versym->gnu_needed);
for (cnt = 1; cnt <= vnd_num; cnt++,
vnd = (Verneed *)((uintptr_t)vnd + vnd->vn_next)) {
Conv_ver_flags_buf_t ver_flags_buf;
const char *name, *dep;
Half vcnt = vnd->vn_cnt;
Vernaux *vnap = (Vernaux *)((uintptr_t)vnd + vnd->vn_aux);
/*
* Obtain the name of the needed file and the version name
* within it that we're dependent on. Note that the count
* should be at least one, otherwise this is a pretty bogus
* entry.
*/
name = string(vcache, cnt, scache, file, vnd->vn_file);
if (vcnt)
dep = string(vcache, cnt, scache, file, vnap->vna_name);
else
dep = MSG_INTL(MSG_STR_NULL);
if (vnap->vna_other == 0) { /* Traditional form */
index_str = MSG_ORIG(MSG_STR_EMPTY);
} else { /* GNU form */
index_str = index;
/* Format the version index value */
(void) snprintf(index, MAXNDXSIZE,
MSG_ORIG(MSG_FMT_INDEX), EC_XWORD(vnap->vna_other));
if (vnap->vna_other > versym->max_verndx)
versym->max_verndx = vnap->vna_other;
}
Elf_ver_line_1(0, index_str, name, dep,
conv_ver_flags(vnap->vna_flags, 0, &ver_flags_buf));
/*
* Print any additional version dependencies.
*/
if (vcnt) {
vnap = (Vernaux *)((uintptr_t)vnap + vnap->vna_next);
for (vcnt--; vcnt; vcnt--,
vnap = (Vernaux *)((uintptr_t)vnap +
vnap->vna_next)) {
dep = string(vcache, cnt, scache, file,
vnap->vna_name);
if (vnap->vna_other > 0) {
/* Format the next index value */
(void) snprintf(index, MAXNDXSIZE,
MSG_ORIG(MSG_FMT_INDEX),
EC_XWORD(vnap->vna_other));
Elf_ver_line_1(0, index,
MSG_ORIG(MSG_STR_EMPTY), dep,
conv_ver_flags(vnap->vna_flags,
0, &ver_flags_buf));
if (vnap->vna_other >
versym->max_verndx)
versym->max_verndx =
vnap->vna_other;
} else {
Elf_ver_line_3(0,
MSG_ORIG(MSG_STR_EMPTY), dep,
conv_ver_flags(vnap->vna_flags,
0, &ver_flags_buf));
}
}
}
}
}
/*
* Examine the Verneed section for information related to GNU
* style Versym indexing:
* - A non-zero vna_other field indicates that Versym indexes can
* reference Verneed records.
* - If the object uses GNU style Versym indexing, the
* maximum index value is needed to detect bad Versym entries.
*
* entry:
* vnd - Address of verneed data
* vnd_num - # of Verneed entries
* versym - Information about versym section
*
* exit:
* If a non-zero vna_other field is seen, versym->gnu_needed is set.
*
* versym->max_verndx has been updated to contain the largest
* version index seen.
*/
static void
update_gnu_verndx(Verneed *vnd, Word vnd_num, VERSYM_STATE *versym)
{
Word cnt;
for (cnt = 1; cnt <= vnd_num; cnt++,
vnd = (Verneed *)((uintptr_t)vnd + vnd->vn_next)) {
Half vcnt = vnd->vn_cnt;
Vernaux *vnap = (Vernaux *)((uintptr_t)vnd + vnd->vn_aux);
/*
* A non-zero value of vna_other indicates that this
* object references VERNEED items from the VERSYM
* array.
*/
if (vnap->vna_other != 0) {
versym->gnu_needed = 1;
if (vnap->vna_other > versym->max_verndx)
versym->max_verndx = vnap->vna_other;
}
/*
* Check any additional version dependencies.
*/
if (vcnt) {
vnap = (Vernaux *)((uintptr_t)vnap + vnap->vna_next);
for (vcnt--; vcnt; vcnt--,
vnap = (Vernaux *)((uintptr_t)vnap +
vnap->vna_next)) {
if (vnap->vna_other == 0)
continue;
versym->gnu_needed = 1;
if (vnap->vna_other > versym->max_verndx)
versym->max_verndx = vnap->vna_other;
}
}
}
}
/*
* Display version section information if the flags require it.
* Return version information needed by other output.
*
* entry:
* cache - Cache of all section headers
* shnum - # of sections in cache
* file - Name of file
* flags - Command line option flags
* versym - VERSYM_STATE block to be filled in.
*/
static void
versions(Cache *cache, Word shnum, const char *file, uint_t flags,
VERSYM_STATE *versym)
{
GElf_Word cnt;
Cache *verdef_cache = NULL, *verneed_cache = NULL;
/* Gather information about the version sections */
versym->max_verndx = 1;
for (cnt = 1; cnt < shnum; cnt++) {
Cache *_cache = &cache[cnt];
Shdr *shdr = _cache->c_shdr;
Dyn *dyn;
ulong_t numdyn;
switch (shdr->sh_type) {
case SHT_DYNAMIC:
/*
* The GNU ld puts a DT_VERSYM entry in the dynamic
* section so that the runtime linker can use it to
* implement their versioning rules. They allow multiple
* incompatible functions with the same name to exist
* in different versions. The Solaris ld does not
* support this mechanism, and as such, does not
* produce DT_VERSYM. We use this fact to determine
* which ld produced this object, and how to interpret
* the version values.
*/
if ((shdr->sh_entsize == 0) ||
(shdr->sh_size == 0) ||
(_cache->c_data == NULL) ||
(_cache->c_data->d_buf == NULL))
continue;
numdyn = shdr->sh_size / shdr->sh_entsize;
dyn = (Dyn *)_cache->c_data->d_buf;
for (; numdyn-- > 0; dyn++)
if (dyn->d_tag == DT_VERSYM) {
versym->gnu_full =
versym->gnu_needed = 1;
break;
}
break;
case SHT_SUNW_versym:
/* Record data address for later symbol processing */
if (_cache->c_data != NULL) {
versym->cache = _cache;
versym->data = _cache->c_data->d_buf;
continue;
}
break;
case SHT_SUNW_verdef:
case SHT_SUNW_verneed:
/*
* Ensure the data is non-NULL and the number
* of items is non-zero. Otherwise, we don't
* understand the section, and will not use it.
*/
if ((_cache->c_data == NULL) ||
(_cache->c_data->d_buf == NULL)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, _cache->c_name);
continue;
}
if (shdr->sh_info == 0) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADSHINFO),
file, _cache->c_name,
EC_WORD(shdr->sh_info));
continue;
}
/* Make sure the string table index is in range */
if ((shdr->sh_link == 0) || (shdr->sh_link >= shnum)) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADSHLINK), file,
_cache->c_name, EC_WORD(shdr->sh_link));
continue;
}
/*
* The section is usable. Save the cache entry.
*/
if (shdr->sh_type == SHT_SUNW_verdef) {
verdef_cache = _cache;
/*
* Under Solaris rules, if there is a verdef
* section, the max versym index is number
* of version definitions it supplies.
*/
versym->max_verndx = shdr->sh_info;
} else {
verneed_cache = _cache;
}
break;
}
}
/*
* If there is a Verneed section, examine it for information
* related to GNU style versioning.
*/
if (verneed_cache != NULL)
update_gnu_verndx((Verneed *)verneed_cache->c_data->d_buf,
verneed_cache->c_shdr->sh_info, versym);
/*
* Now that all the information is available, display the
* Verdef and Verneed section contents, if requested.
*/
if ((flags & FLG_SHOW_VERSIONS) == 0)
return;
if (verdef_cache != NULL) {
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_ELF_SCN_VERDEF),
verdef_cache->c_name);
version_def((Verdef *)verdef_cache->c_data->d_buf,
verdef_cache->c_shdr->sh_info, verdef_cache,
&cache[verdef_cache->c_shdr->sh_link], file);
}
if (verneed_cache != NULL) {
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_ELF_SCN_VERNEED),
verneed_cache->c_name);
/*
* If GNU versioning applies to this object, version_need()
* will update versym->max_verndx, and it is not
* necessary to call update_gnu_verndx().
*/
version_need((Verneed *)verneed_cache->c_data->d_buf,
verneed_cache->c_shdr->sh_info, verneed_cache,
&cache[verneed_cache->c_shdr->sh_link], file, versym);
}
}
/*
* Search for and process any symbol tables.
*/
void
symbols(Cache *cache, Word shnum, Ehdr *ehdr, uchar_t osabi,
VERSYM_STATE *versym, const char *file, uint_t flags)
{
SYMTBL_STATE state;
Cache *_cache;
Word secndx;
for (secndx = 1; secndx < shnum; secndx++) {
Word symcnt;
Shdr *shdr;
_cache = &cache[secndx];
shdr = _cache->c_shdr;
if ((shdr->sh_type != SHT_SYMTAB) &&
(shdr->sh_type != SHT_DYNSYM) &&
((shdr->sh_type != SHT_SUNW_LDYNSYM) ||
(osabi != ELFOSABI_SOLARIS)))
continue;
if (!match(MATCH_F_ALL, _cache->c_name, secndx, shdr->sh_type))
continue;
if (!init_symtbl_state(&state, cache, shnum, secndx, ehdr,
osabi, versym, file, flags))
continue;
/*
* Loop through the symbol tables entries.
*/
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_ELF_SCN_SYMTAB), state.secname);
Elf_syms_table_title(0, ELF_DBG_ELFDUMP);
for (symcnt = 0; symcnt < state.symn; symcnt++)
output_symbol(&state, symcnt, shdr->sh_info, symcnt,
state.sym + symcnt);
}
}
/*
* Search for and process any SHT_SUNW_symsort or SHT_SUNW_tlssort sections.
* These sections are always associated with the .SUNW_ldynsym./.dynsym pair.
*/
static void
sunw_sort(Cache *cache, Word shnum, Ehdr *ehdr, uchar_t osabi,
VERSYM_STATE *versym, const char *file, uint_t flags)
{
SYMTBL_STATE ldynsym_state, dynsym_state;
Cache *sortcache, *symcache;
Shdr *sortshdr, *symshdr;
Word sortsecndx, symsecndx;
Word ldynsym_cnt;
Word *ndx;
Word ndxn;
int output_cnt = 0;
Conv_inv_buf_t inv_buf;
for (sortsecndx = 1; sortsecndx < shnum; sortsecndx++) {
sortcache = &cache[sortsecndx];
sortshdr = sortcache->c_shdr;
if ((sortshdr->sh_type != SHT_SUNW_symsort) &&
(sortshdr->sh_type != SHT_SUNW_tlssort))
continue;
if (!match(MATCH_F_ALL, sortcache->c_name, sortsecndx,
sortshdr->sh_type))
continue;
/*
* If the section references a SUNW_ldynsym, then we
* expect to see the associated .dynsym immediately
* following. If it references a .dynsym, there is no
* SUNW_ldynsym. If it is any other type, then we don't
* know what to do with it.
*/
if ((sortshdr->sh_link == 0) || (sortshdr->sh_link >= shnum)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHLINK),
file, sortcache->c_name,
EC_WORD(sortshdr->sh_link));
continue;
}
symcache = &cache[sortshdr->sh_link];
symshdr = symcache->c_shdr;
symsecndx = sortshdr->sh_link;
ldynsym_cnt = 0;
switch (symshdr->sh_type) {
case SHT_SUNW_LDYNSYM:
if (!init_symtbl_state(&ldynsym_state, cache, shnum,
symsecndx, ehdr, osabi, versym, file, flags))
continue;
ldynsym_cnt = ldynsym_state.symn;
/*
* We know that the dynsym follows immediately
* after the SUNW_ldynsym, and so, should be at
* (sortshdr->sh_link + 1). However, elfdump is a
* diagnostic tool, so we do the full paranoid
* search instead.
*/
for (symsecndx = 1; symsecndx < shnum; symsecndx++) {
symcache = &cache[symsecndx];
symshdr = symcache->c_shdr;
if (symshdr->sh_type == SHT_DYNSYM)
break;
}
if (symsecndx >= shnum) { /* Dynsym not found! */
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_NODYNSYM),
file, sortcache->c_name);
continue;
}
/* Fallthrough to process associated dynsym */
/* FALLTHROUGH */
case SHT_DYNSYM:
if (!init_symtbl_state(&dynsym_state, cache, shnum,
symsecndx, ehdr, osabi, versym, file, flags))
continue;
break;
default:
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADNDXSEC),
file, sortcache->c_name,
conv_sec_type(osabi, ehdr->e_machine,
symshdr->sh_type, 0, &inv_buf));
continue;
}
/*
* Output header
*/
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
if (ldynsym_cnt > 0) {
dbg_print(0, MSG_INTL(MSG_ELF_SCN_SYMSORT2),
sortcache->c_name, ldynsym_state.secname,
dynsym_state.secname);
/*
* The data for .SUNW_ldynsym and dynsym sections
* is supposed to be adjacent with SUNW_ldynsym coming
* first. Check, and issue a warning if it isn't so.
*/
if (((ldynsym_state.sym + ldynsym_state.symn)
!= dynsym_state.sym) &&
((flags & FLG_CTL_FAKESHDR) == 0))
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_LDYNNOTADJ), file,
ldynsym_state.secname,
dynsym_state.secname);
} else {
dbg_print(0, MSG_INTL(MSG_ELF_SCN_SYMSORT1),
sortcache->c_name, dynsym_state.secname);
}
Elf_syms_table_title(0, ELF_DBG_ELFDUMP);
/* If not first one, insert a line of white space */
if (output_cnt++ > 0)
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
/*
* SUNW_dynsymsort and SUNW_dyntlssort are arrays of
* symbol indices. Iterate over the array entries,
* dispaying the referenced symbols.
*/
ndxn = sortshdr->sh_size / sortshdr->sh_entsize;
ndx = (Word *)sortcache->c_data->d_buf;
for (; ndxn-- > 0; ndx++) {
if (*ndx >= ldynsym_cnt) {
Word sec_ndx = *ndx - ldynsym_cnt;
output_symbol(&dynsym_state, sec_ndx, 0,
*ndx, dynsym_state.sym + sec_ndx);
} else {
output_symbol(&ldynsym_state, *ndx, 0,
*ndx, ldynsym_state.sym + *ndx);
}
}
}
}
/*
* Search for and process any relocation sections.
*/
static void
reloc(Cache *cache, Word shnum, Ehdr *ehdr, const char *file)
{
Word cnt;
for (cnt = 1; cnt < shnum; cnt++) {
Word type, symnum;
Xword relndx, relnum, relsize;
void *rels;
Sym *syms;
Cache *symsec, *strsec;
Cache *_cache = &cache[cnt];
Shdr *shdr = _cache->c_shdr;
char *relname = _cache->c_name;
Conv_inv_buf_t inv_buf;
if (((type = shdr->sh_type) != SHT_RELA) &&
(type != SHT_REL))
continue;
if (!match(MATCH_F_ALL, relname, cnt, type))
continue;
/*
* Decide entry size.
*/
if (((relsize = shdr->sh_entsize) == 0) ||
(relsize > shdr->sh_size)) {
if (type == SHT_RELA)
relsize = sizeof (Rela);
else
relsize = sizeof (Rel);
}
/*
* Determine the number of relocations available.
*/
if (shdr->sh_size == 0) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, relname);
continue;
}
if ((_cache->c_data == NULL) || (_cache->c_data->d_buf == NULL))
continue;
rels = _cache->c_data->d_buf;
relnum = shdr->sh_size / relsize;
/*
* Get the data buffer for the associated symbol table and
* string table.
*/
if (stringtbl(cache, 1, cnt, shnum, file,
&symnum, &symsec, &strsec) == 0)
continue;
syms = symsec->c_data->d_buf;
/*
* Loop through the relocation entries.
*/
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_ELF_SCN_RELOC), _cache->c_name);
Elf_reloc_title(0, ELF_DBG_ELFDUMP, type);
for (relndx = 0; relndx < relnum; relndx++,
rels = (void *)((char *)rels + relsize)) {
Half mach = ehdr->e_machine;
char section[BUFSIZ];
const char *symname;
Word symndx, reltype;
Rela *rela;
Rel *rel;
/*
* Unravel the relocation and determine the symbol with
* which this relocation is associated.
*/
if (type == SHT_RELA) {
rela = (Rela *)rels;
symndx = ELF_R_SYM(rela->r_info);
reltype = ELF_R_TYPE(rela->r_info, mach);
} else {
rel = (Rel *)rels;
symndx = ELF_R_SYM(rel->r_info);
reltype = ELF_R_TYPE(rel->r_info, mach);
}
symname = relsymname(cache, _cache, strsec, symndx,
symnum, relndx, syms, section, BUFSIZ, file);
/*
* A zero symbol index is only valid for a few
* relocations.
*/
if (symndx == 0) {
int badrel = 0;
if ((mach == EM_SPARC) ||
(mach == EM_SPARC32PLUS) ||
(mach == EM_SPARCV9)) {
if ((reltype != R_SPARC_NONE) &&
(reltype != R_SPARC_REGISTER) &&
(reltype != R_SPARC_RELATIVE))
badrel++;
} else if (mach == EM_386) {
if ((reltype != R_386_NONE) &&
(reltype != R_386_RELATIVE))
badrel++;
} else if (mach == EM_AMD64) {
if ((reltype != R_AMD64_NONE) &&
(reltype != R_AMD64_RELATIVE))
badrel++;
}
if (badrel) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADREL1), file,
conv_reloc_type(mach, reltype,
0, &inv_buf));
}
}
Elf_reloc_entry_1(0, ELF_DBG_ELFDUMP,
MSG_ORIG(MSG_STR_EMPTY), ehdr->e_machine, type,
rels, relname, symname, 0);
}
}
}
/*
* This value controls which test dyn_test() performs.
*/
typedef enum { DYN_TEST_ADDR, DYN_TEST_SIZE, DYN_TEST_ENTSIZE } dyn_test_t;
/*
* Used by dynamic() to compare the value of a dynamic element against
* the starting address of the section it references.
*
* entry:
* test_type - Specify which dyn item is being tested.
* sh_type - SHT_* type value for required section.
* sec_cache - Cache entry for section, or NULL if the object lacks
* a section of this type.
* dyn - Dyn entry to be tested
* dynsec_cnt - # of dynamic section being examined. The first
* dynamic section is 1, the next is 2, and so on...
* ehdr - ELF header for file
* file - Name of file
*/
static void
dyn_test(dyn_test_t test_type, Word sh_type, Cache *sec_cache, Dyn *dyn,
Word dynsec_cnt, Ehdr *ehdr, uchar_t osabi, const char *file)
{
Conv_inv_buf_t buf1, buf2;
/*
* These tests are based around the implicit assumption that
* there is only one dynamic section in an object, and also only
* one of the sections it references. We have therefore gathered
* all of the necessary information to test this in a single pass
* over the section headers, which is very efficient. We are not
* aware of any case where more than one dynamic section would
* be meaningful in an ELF object, so this is a reasonable solution.
*
* To test multiple dynamic sections correctly would be more
* expensive in code and time. We would have to build a data structure
* containing all the dynamic elements. Then, we would use the address
* to locate the section it references and ensure the section is of
* the right type and that the address in the dynamic element is
* to the start of the section. Then, we could check the size and
* entsize values against those same sections. This is O(n^2), and
* also complicated.
*
* In the highly unlikely case that there is more than one dynamic
* section, we only test the first one, and simply allow the values
* of the subsequent one to be displayed unchallenged.
*/
if (dynsec_cnt != 1)
return;
/*
* A DT_ item that references a section address should always find
* the section in the file.
*/
if (sec_cache == NULL) {
const char *name;
/*
* Supply section names instead of section types for
* things that reference progbits so that the error
* message will make more sense.
*/
switch (dyn->d_tag) {
case DT_INIT:
name = MSG_ORIG(MSG_ELF_INIT);
break;
case DT_FINI:
name = MSG_ORIG(MSG_ELF_FINI);
break;
default:
name = conv_sec_type(osabi, ehdr->e_machine,
sh_type, 0, &buf1);
break;
}
(void) fprintf(stderr, MSG_INTL(MSG_ERR_DYNNOBCKSEC), file,
name, conv_dyn_tag(dyn->d_tag, osabi, ehdr->e_machine,
CONV_FMT_ALT_CF, &buf2));
return;
}
switch (test_type) {
case DYN_TEST_ADDR:
/* The section address should match the DT_ item value */
if (dyn->d_un.d_val != sec_cache->c_shdr->sh_addr)
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DYNBADADDR), file,
conv_dyn_tag(dyn->d_tag, osabi, ehdr->e_machine,
CONV_FMT_ALT_CF, &buf1), EC_ADDR(dyn->d_un.d_val),
sec_cache->c_ndx, sec_cache->c_name,
EC_ADDR(sec_cache->c_shdr->sh_addr));
break;
case DYN_TEST_SIZE:
/* The section size should match the DT_ item value */
if (dyn->d_un.d_val != sec_cache->c_shdr->sh_size)
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DYNBADSIZE), file,
conv_dyn_tag(dyn->d_tag, osabi, ehdr->e_machine,
CONV_FMT_ALT_CF, &buf1), EC_XWORD(dyn->d_un.d_val),
sec_cache->c_ndx, sec_cache->c_name,
EC_XWORD(sec_cache->c_shdr->sh_size));
break;
case DYN_TEST_ENTSIZE:
/* The sh_entsize value should match the DT_ item value */
if (dyn->d_un.d_val != sec_cache->c_shdr->sh_entsize)
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_DYNBADENTSIZE), file,
conv_dyn_tag(dyn->d_tag, osabi, ehdr->e_machine,
CONV_FMT_ALT_CF, &buf1), EC_XWORD(dyn->d_un.d_val),
sec_cache->c_ndx, sec_cache->c_name,
EC_XWORD(sec_cache->c_shdr->sh_entsize));
break;
}
}
/*
* There are some DT_ entries that have corresponding symbols
* (e.g. DT_INIT and _init). It is expected that these items will
* both have the same value if both are present. This routine
* examines the well known symbol tables for such symbols and
* issues warnings for any that don't match.
*
* entry:
* dyn - Dyn entry to be tested
* symname - Name of symbol that corresponds to dyn
* symtab_cache, dynsym_cache, ldynsym_cache - Symbol tables to check
* target_cache - Section the symname section is expected to be
* associated with.
* cache - Cache of all section headers
* shnum - # of sections in cache
* ehdr - ELF header for file
* osabi - OSABI to apply when interpreting object
* file - Name of file
*/
static void
dyn_symtest(Dyn *dyn, const char *symname, Cache *symtab_cache,
Cache *dynsym_cache, Cache *ldynsym_cache, Cache *target_cache,
Cache *cache, Word shnum, Ehdr *ehdr, uchar_t osabi, const char *file)
{
Conv_inv_buf_t buf;
int i;
Sym *sym;
Cache *_cache = NULL;
for (i = 0; i < 3; i++) {
switch (i) {
case 0:
_cache = symtab_cache;
break;
case 1:
_cache = dynsym_cache;
break;
case 2:
_cache = ldynsym_cache;
break;
}
if ((_cache != NULL) &&
symlookup(symname, cache, shnum, &sym, target_cache,
_cache, file) && (sym->st_value != dyn->d_un.d_val))
(void) fprintf(stderr, MSG_INTL(MSG_ERR_DYNSYMVAL),
file, _cache->c_name, conv_dyn_tag(dyn->d_tag,
osabi, ehdr->e_machine, CONV_FMT_ALT_CF, &buf),
symname, EC_ADDR(sym->st_value));
}
}
/*
* Search for and process a .dynamic section.
*/
static void
dynamic(Cache *cache, Word shnum, Ehdr *ehdr, uchar_t osabi, const char *file,
Word phnum, Elf *elf)
{
struct {
Cache *symtab;
Cache *dynstr;
Cache *dynsym;
Cache *hash;
Cache *fini;
Cache *fini_array;
Cache *init;
Cache *init_array;
Cache *preinit_array;
Cache *rel;
Cache *rela;
Cache *sunw_cap;
Cache *sunw_capinfo;
Cache *sunw_capchain;
Cache *sunw_ldynsym;
Cache *sunw_move;
Cache *sunw_syminfo;
Cache *sunw_symsort;
Cache *sunw_tlssort;
Cache *sunw_verdef;
Cache *sunw_verneed;
Cache *sunw_versym;
} sec;
Word dynsec_ndx;
Word dynsec_num;
int dynsec_cnt;
Word cnt;
int osabi_solaris = osabi == ELFOSABI_SOLARIS;
Phdr *pt_dynamic = NULL;
size_t phndx;
static Word phdr_type[] = { PT_DYNAMIC };
/*
* Make a pass over all the sections, gathering section information
* we'll need below.
*/
dynsec_num = 0;
bzero(&sec, sizeof (sec));
for (cnt = 1; cnt < shnum; cnt++) {
Cache *_cache = &cache[cnt];
switch (_cache->c_shdr->sh_type) {
case SHT_DYNAMIC:
if (dynsec_num == 0) {
dynsec_ndx = cnt;
/* Does it have a valid string table? */
(void) stringtbl(cache, 0, cnt, shnum, file,
0, 0, &sec.dynstr);
}
dynsec_num++;
break;
case SHT_PROGBITS:
/*
* We want to detect the .init and .fini sections,
* if present. These are SHT_PROGBITS, so all we
* have to go on is the section name. Normally comparing
* names is a bad idea, but there are some special
* names (i.e. .init/.fini/.interp) that are very
* difficult to use in any other context, and for
* these symbols, we do the heuristic match.
*/
if (strcmp(_cache->c_name,
MSG_ORIG(MSG_ELF_INIT)) == 0) {
if (sec.init == NULL)
sec.init = _cache;
} else if (strcmp(_cache->c_name,
MSG_ORIG(MSG_ELF_FINI)) == 0) {
if (sec.fini == NULL)
sec.fini = _cache;
}
break;
case SHT_REL:
/*
* We want the SHT_REL section with the lowest
* offset. The linker gathers them together,
* and puts the address of the first one
* into the DT_REL dynamic element.
*/
if ((sec.rel == NULL) ||
(_cache->c_shdr->sh_offset <
sec.rel->c_shdr->sh_offset))
sec.rel = _cache;
break;
case SHT_RELA:
/* RELA is handled just like RELA above */
if ((sec.rela == NULL) ||
(_cache->c_shdr->sh_offset <
sec.rela->c_shdr->sh_offset))
sec.rela = _cache;
break;
/*
* The GRAB macro is used for the simple case in which
* we simply grab the first section of the desired type.
*/
#define GRAB(_sec_type, _sec_field) \
case _sec_type: \
if (sec._sec_field == NULL) \
sec._sec_field = _cache; \
break
GRAB(SHT_SYMTAB, symtab);
GRAB(SHT_DYNSYM, dynsym);
GRAB(SHT_FINI_ARRAY, fini_array);
GRAB(SHT_HASH, hash);
GRAB(SHT_INIT_ARRAY, init_array);
GRAB(SHT_SUNW_move, sunw_move);
GRAB(SHT_PREINIT_ARRAY, preinit_array);
GRAB(SHT_SUNW_cap, sunw_cap);
GRAB(SHT_SUNW_capinfo, sunw_capinfo);
GRAB(SHT_SUNW_capchain, sunw_capchain);
GRAB(SHT_SUNW_LDYNSYM, sunw_ldynsym);
GRAB(SHT_SUNW_syminfo, sunw_syminfo);
GRAB(SHT_SUNW_symsort, sunw_symsort);
GRAB(SHT_SUNW_tlssort, sunw_tlssort);
GRAB(SHT_SUNW_verdef, sunw_verdef);
GRAB(SHT_SUNW_verneed, sunw_verneed);
GRAB(SHT_SUNW_versym, sunw_versym);
#undef GRAB
}
}
if (phnum) {
pt_dynamic = getphdr(phnum, phdr_type, 1, file, elf, &phndx);
}
/*
* If no dynamic section, return immediately. If more than one
* dynamic section, then something odd is going on and an error
* is in order, but then continue on and display them all.
*/
if (dynsec_num == 0) {
return;
}
if (dynsec_num > 1)
(void) fprintf(stderr, MSG_INTL(MSG_ERR_MULTDYN),
file, EC_WORD(dynsec_num));
dynsec_cnt = 0;
for (cnt = dynsec_ndx; (cnt < shnum) && (dynsec_cnt < dynsec_num);
cnt++) {
Dyn *dyn;
ulong_t numdyn;
int ndx, end_ndx;
Cache *_cache = &cache[cnt], *strsec;
Shdr *shdr = _cache->c_shdr;
int dumped = 0;
if (shdr->sh_type != SHT_DYNAMIC)
continue;
dynsec_cnt++;
/*
* Verify the associated string table section.
*/
if (stringtbl(cache, 0, cnt, shnum, file, 0, 0, &strsec) == 0)
continue;
if ((shdr->sh_entsize == 0) || (shdr->sh_size == 0)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, _cache->c_name);
continue;
}
if ((_cache->c_data == NULL) || (_cache->c_data->d_buf == NULL))
continue;
/* The first time through, check v. PT_DYNAMIC */
if (dynsec_cnt == 1) {
Conv_inv_buf_t inv_buf;
if ((pt_dynamic == NULL) && (ehdr->e_type != ET_REL)) {
fprintf(stderr, MSG_INTL(MSG_SHDR_NO_PHDR),
file, _cache->c_ndx, _cache->c_name,
conv_phdr_type(osabi, ehdr->e_machine,
PT_DYNAMIC, CONV_FMT_ALT_CF, &inv_buf));
}
if (pt_dynamic != NULL) {
check_phdr_v_shdr(pt_dynamic, phndx,
osabi, ehdr->e_machine, _cache, file);
}
}
numdyn = shdr->sh_size / shdr->sh_entsize;
dyn = (Dyn *)_cache->c_data->d_buf;
/*
* We expect the REL/RELA entries to reference the reloc
* section with the lowest address. However, this is
* not true for dumped objects. Detect if this object has
* been dumped so that we can skip the reloc address test
* in that case.
*/
for (ndx = 0; ndx < numdyn; dyn++, ndx++) {
if (dyn->d_tag == DT_FLAGS_1) {
dumped = (dyn->d_un.d_val & DF_1_CONFALT) != 0;
break;
}
}
dyn = (Dyn *)_cache->c_data->d_buf;
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_ELF_SCN_DYNAMIC), _cache->c_name);
Elf_dyn_title(0);
for (ndx = 0; ndx < numdyn; dyn++, ndx++) {
union {
Conv_inv_buf_t inv;
Conv_dyn_flag_buf_t flag;
Conv_dyn_flag1_buf_t flag1;
Conv_dyn_posflag1_buf_t posflag1;
Conv_dyn_feature1_buf_t feature1;
} c_buf;
const char *name = NULL;
/*
* Print the information numerically, and if possible
* as a string. If a string is available, name is
* set to reference it.
*
* Also, take this opportunity to sanity check
* the values of DT elements. In the code above,
* we gathered information on sections that are
* referenced by the dynamic section. Here, we
* compare the attributes of those sections to
* the DT_ items that reference them and report
* on inconsistencies.
*
* Things not currently tested that could be improved
* in later revisions include:
* - We don't check PLT or GOT related items
* - We don't handle computing the lengths of
* relocation arrays. To handle this
* requires examining data that spans
* across sections, in a contiguous span
* within a single segment.
* - DT_VERDEFNUM and DT_VERNEEDNUM can't be
* verified without parsing the sections.
* - We don't handle DT_SUNW_SYMSZ, which would
* be the sum of the lengths of .dynsym and
* .SUNW_ldynsym
* - DT_SUNW_STRPAD can't be verified other than
* to check that it's not larger than
* the string table.
* - Some items come in "all or none" clusters
* that give an address, element size,
* and data length in bytes. We don't
* verify that there are no missing items
* in such groups.
*/
switch (dyn->d_tag) {
case DT_NULL:
/*
* Special case: DT_NULLs can come in groups
* that we prefer to reduce to a single line.
*/
end_ndx = ndx;
while ((end_ndx < (numdyn - 1)) &&
((dyn + 1)->d_tag == DT_NULL)) {
dyn++;
end_ndx++;
}
Elf_dyn_null_entry(0, dyn, ndx, end_ndx);
ndx = end_ndx;
continue;
/*
* String items all reference the dynstr. The string()
* function does the necessary sanity checking.
*/
case DT_NEEDED:
case DT_SONAME:
case DT_FILTER:
case DT_AUXILIARY:
case DT_CONFIG:
case DT_RPATH:
case DT_RUNPATH:
case DT_USED:
case DT_DEPAUDIT:
case DT_AUDIT:
name = string(_cache, ndx, strsec,
file, dyn->d_un.d_ptr);
break;
case DT_SUNW_AUXILIARY:
case DT_SUNW_FILTER:
if (osabi_solaris)
name = string(_cache, ndx, strsec,
file, dyn->d_un.d_ptr);
break;
case DT_FLAGS:
name = conv_dyn_flag(dyn->d_un.d_val,
0, &c_buf.flag);
break;
case DT_FLAGS_1:
name = conv_dyn_flag1(dyn->d_un.d_val, 0,
&c_buf.flag1);
break;
case DT_POSFLAG_1:
name = conv_dyn_posflag1(dyn->d_un.d_val, 0,
&c_buf.posflag1);
break;
case DT_FEATURE_1:
name = conv_dyn_feature1(dyn->d_un.d_val, 0,
&c_buf.feature1);
break;
case DT_DEPRECATED_SPARC_REGISTER:
name = MSG_INTL(MSG_STR_DEPRECATED);
break;
case DT_SUNW_LDMACH:
if (!osabi_solaris)
break;
name = conv_ehdr_mach((Half)dyn->d_un.d_val,
0, &c_buf.inv);
break;
/*
* Cases below this point are strictly sanity checking,
* and do not generate a name string. The TEST_ macros
* are used to hide the boiler plate arguments neeeded
* by dyn_test().
*/
#define TEST_ADDR(_sh_type, _sec_field) \
dyn_test(DYN_TEST_ADDR, _sh_type, \
sec._sec_field, dyn, dynsec_cnt, ehdr, \
osabi, file)
#define TEST_SIZE(_sh_type, _sec_field) \
dyn_test(DYN_TEST_SIZE, _sh_type, \
sec._sec_field, dyn, dynsec_cnt, ehdr, \
osabi, file)
#define TEST_ENTSIZE(_sh_type, _sec_field) \
dyn_test(DYN_TEST_ENTSIZE, _sh_type, \
sec._sec_field, dyn, dynsec_cnt, ehdr, \
osabi, file)
case DT_FINI:
dyn_symtest(dyn, MSG_ORIG(MSG_SYM_FINI),
sec.symtab, sec.dynsym, sec.sunw_ldynsym,
sec.fini, cache, shnum, ehdr, osabi, file);
TEST_ADDR(SHT_PROGBITS, fini);
break;
case DT_FINI_ARRAY:
TEST_ADDR(SHT_FINI_ARRAY, fini_array);
break;
case DT_FINI_ARRAYSZ:
TEST_SIZE(SHT_FINI_ARRAY, fini_array);
break;
case DT_HASH:
TEST_ADDR(SHT_HASH, hash);
break;
case DT_INIT:
dyn_symtest(dyn, MSG_ORIG(MSG_SYM_INIT),
sec.symtab, sec.dynsym, sec.sunw_ldynsym,
sec.init, cache, shnum, ehdr, osabi, file);
TEST_ADDR(SHT_PROGBITS, init);
break;
case DT_INIT_ARRAY:
TEST_ADDR(SHT_INIT_ARRAY, init_array);
break;
case DT_INIT_ARRAYSZ:
TEST_SIZE(SHT_INIT_ARRAY, init_array);
break;
case DT_MOVEENT:
TEST_ENTSIZE(SHT_SUNW_move, sunw_move);
break;
case DT_MOVESZ:
TEST_SIZE(SHT_SUNW_move, sunw_move);
break;
case DT_MOVETAB:
TEST_ADDR(SHT_SUNW_move, sunw_move);
break;
case DT_PREINIT_ARRAY:
TEST_ADDR(SHT_PREINIT_ARRAY, preinit_array);
break;
case DT_PREINIT_ARRAYSZ:
TEST_SIZE(SHT_PREINIT_ARRAY, preinit_array);
break;
case DT_REL:
if (!dumped)
TEST_ADDR(SHT_REL, rel);
break;
case DT_RELENT:
TEST_ENTSIZE(SHT_REL, rel);
break;
case DT_RELA:
if (!dumped)
TEST_ADDR(SHT_RELA, rela);
break;
case DT_RELAENT:
TEST_ENTSIZE(SHT_RELA, rela);
break;
case DT_STRTAB:
TEST_ADDR(SHT_STRTAB, dynstr);
break;
case DT_STRSZ:
TEST_SIZE(SHT_STRTAB, dynstr);
break;
case DT_SUNW_CAP:
if (osabi_solaris)
TEST_ADDR(SHT_SUNW_cap, sunw_cap);
break;
case DT_SUNW_CAPINFO:
if (osabi_solaris)
TEST_ADDR(SHT_SUNW_capinfo,
sunw_capinfo);
break;
case DT_SUNW_CAPCHAIN:
if (osabi_solaris)
TEST_ADDR(SHT_SUNW_capchain,
sunw_capchain);
break;
case DT_SUNW_SYMTAB:
TEST_ADDR(SHT_SUNW_LDYNSYM, sunw_ldynsym);
break;
case DT_SYMENT:
TEST_ENTSIZE(SHT_DYNSYM, dynsym);
break;
case DT_SYMINENT:
TEST_ENTSIZE(SHT_SUNW_syminfo, sunw_syminfo);
break;
case DT_SYMINFO:
TEST_ADDR(SHT_SUNW_syminfo, sunw_syminfo);
break;
case DT_SYMINSZ:
TEST_SIZE(SHT_SUNW_syminfo, sunw_syminfo);
break;
case DT_SYMTAB:
TEST_ADDR(SHT_DYNSYM, dynsym);
break;
case DT_SUNW_SORTENT:
/*
* This entry is related to both the symsort and
* tlssort sections.
*/
if (osabi_solaris) {
int test_tls =
(sec.sunw_tlssort != NULL);
int test_sym =
(sec.sunw_symsort != NULL) ||
!test_tls;
if (test_sym)
TEST_ENTSIZE(SHT_SUNW_symsort,
sunw_symsort);
if (test_tls)
TEST_ENTSIZE(SHT_SUNW_tlssort,
sunw_tlssort);
}
break;
case DT_SUNW_SYMSORT:
if (osabi_solaris)
TEST_ADDR(SHT_SUNW_symsort,
sunw_symsort);
break;
case DT_SUNW_SYMSORTSZ:
if (osabi_solaris)
TEST_SIZE(SHT_SUNW_symsort,
sunw_symsort);
break;
case DT_SUNW_TLSSORT:
if (osabi_solaris)
TEST_ADDR(SHT_SUNW_tlssort,
sunw_tlssort);
break;
case DT_SUNW_TLSSORTSZ:
if (osabi_solaris)
TEST_SIZE(SHT_SUNW_tlssort,
sunw_tlssort);
break;
case DT_VERDEF:
TEST_ADDR(SHT_SUNW_verdef, sunw_verdef);
break;
case DT_VERNEED:
TEST_ADDR(SHT_SUNW_verneed, sunw_verneed);
break;
case DT_VERSYM:
TEST_ADDR(SHT_SUNW_versym, sunw_versym);
break;
#undef TEST_ADDR
#undef TEST_SIZE
#undef TEST_ENTSIZE
}
if (name == NULL)
name = MSG_ORIG(MSG_STR_EMPTY);
Elf_dyn_entry(0, dyn, ndx, name,
osabi, ehdr->e_machine);
}
}
}
/*
* Search for and process a MOVE section.
*/
static void
move(Cache *cache, Word shnum, const char *file, uint_t flags)
{
Word cnt;
const char *fmt = NULL;
for (cnt = 1; cnt < shnum; cnt++) {
Word movenum, symnum, ndx;
Sym *syms;
Cache *_cache = &cache[cnt];
Shdr *shdr = _cache->c_shdr;
Cache *symsec, *strsec;
Move *move;
if (shdr->sh_type != SHT_SUNW_move)
continue;
if (!match(MATCH_F_ALL, _cache->c_name, cnt, shdr->sh_type))
continue;
/*
* Determine the move data and number.
*/
if ((shdr->sh_entsize == 0) || (shdr->sh_size == 0)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, _cache->c_name);
continue;
}
if ((_cache->c_data == NULL) || (_cache->c_data->d_buf == NULL))
continue;
move = (Move *)_cache->c_data->d_buf;
movenum = shdr->sh_size / shdr->sh_entsize;
/*
* Get the data buffer for the associated symbol table and
* string table.
*/
if (stringtbl(cache, 1, cnt, shnum, file,
&symnum, &symsec, &strsec) == 0)
return;
syms = (Sym *)symsec->c_data->d_buf;
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_ELF_SCN_MOVE), _cache->c_name);
dbg_print(0, MSG_INTL(MSG_MOVE_TITLE));
if (fmt == NULL)
fmt = MSG_INTL(MSG_MOVE_ENTRY);
for (ndx = 0; ndx < movenum; move++, ndx++) {
const char *symname;
char index[MAXNDXSIZE], section[BUFSIZ];
Word symndx, shndx;
Sym *sym;
/*
* Check for null entries
*/
if ((move->m_info == 0) && (move->m_value == 0) &&
(move->m_poffset == 0) && (move->m_repeat == 0) &&
(move->m_stride == 0)) {
dbg_print(0, fmt, MSG_ORIG(MSG_STR_EMPTY),
EC_XWORD(move->m_poffset), 0, 0, 0,
EC_LWORD(0), MSG_ORIG(MSG_STR_EMPTY));
continue;
}
if (((symndx = ELF_M_SYM(move->m_info)) == 0) ||
(symndx >= symnum)) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADMINFO), file,
_cache->c_name, EC_XWORD(move->m_info));
(void) snprintf(index, MAXNDXSIZE,
MSG_ORIG(MSG_FMT_INDEX), EC_XWORD(symndx));
dbg_print(0, fmt, index,
EC_XWORD(move->m_poffset),
ELF_M_SIZE(move->m_info), move->m_repeat,
move->m_stride, move->m_value,
MSG_INTL(MSG_STR_UNKNOWN));
continue;
}
symname = relsymname(cache, _cache, strsec,
symndx, symnum, ndx, syms, section, BUFSIZ, file);
sym = (Sym *)(syms + symndx);
/*
* Additional sanity check.
*/
shndx = sym->st_shndx;
if (!((shndx == SHN_COMMON) ||
(((shndx >= 1) && (shndx <= shnum)) &&
(cache[shndx].c_shdr)->sh_type == SHT_NOBITS))) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADSYM2), file,
_cache->c_name, EC_WORD(symndx),
demangle(symname, flags));
}
(void) snprintf(index, MAXNDXSIZE,
MSG_ORIG(MSG_FMT_INDEX), EC_XWORD(symndx));
dbg_print(0, fmt, index, EC_XWORD(move->m_poffset),
ELF_M_SIZE(move->m_info), move->m_repeat,
move->m_stride, move->m_value,
demangle(symname, flags));
}
}
}
/*
* parse_note_t is used to track the state used by parse_note_entry()
* between calls, and also to return the results of each call.
*/
typedef struct {
/* pns_ fields track progress through the data */
const char *pns_file; /* File name */
Cache *pns_cache; /* Note section cache entry */
size_t pns_size; /* # unprocessed data bytes */
Word *pns_data; /* # to next unused data byte */
/* pn_ fields return the results for a single call */
Word pn_namesz; /* Value of note namesz field */
Word pn_descsz; /* Value of note descsz field */
Word pn_type; /* Value of note type field */
const char *pn_name; /* if (namesz > 0) ptr to name bytes */
const char *pn_desc; /* if (descsx > 0) ptr to data bytes */
} parse_note_t;
/*
* Extract the various sub-parts of a note entry, and advance the
* data pointer past it.
*
* entry:
* The state pns_ fields contain current values for the Note section
*
* exit:
* On success, True (1) is returned, the state pns_ fields have been
* advanced to point at the start of the next entry, and the information
* for the recovered note entry is found in the state pn_ fields.
*
* On failure, False (0) is returned. The values contained in state
* are undefined.
*/
static int
parse_note_entry(parse_note_t *state)
{
size_t pad, noteoff;
noteoff = (Word)state->pns_cache->c_data->d_size - state->pns_size;
/*
* Make sure we can at least reference the 3 initial entries
* (4-byte words) of the note information block.
*/
if (state->pns_size >= (sizeof (Word) * 3)) {
state->pns_size -= (sizeof (Word) * 3);
} else {
(void) fprintf(stderr, MSG_INTL(MSG_NOTE_BADDATASZ),
state->pns_file, state->pns_cache->c_name,
EC_WORD(noteoff));
return (0);
}
/*
* Make sure any specified name string can be referenced.
*/
if ((state->pn_namesz = *state->pns_data++) != 0) {
if (state->pns_size >= state->pn_namesz) {
state->pns_size -= state->pn_namesz;
} else {
(void) fprintf(stderr, MSG_INTL(MSG_NOTE_BADNMSZ),
state->pns_file, state->pns_cache->c_name,
EC_WORD(noteoff), EC_WORD(state->pn_namesz));
return (0);
}
}
/*
* Make sure any specified descriptor can be referenced.
*/
if ((state->pn_descsz = *state->pns_data++) != 0) {
/*
* If namesz isn't a 4-byte multiple, account for any
* padding that must exist before the descriptor.
*/
if ((pad = (state->pn_namesz & (sizeof (Word) - 1))) != 0) {
pad = sizeof (Word) - pad;
state->pns_size -= pad;
}
if (state->pns_size >= state->pn_descsz) {
state->pns_size -= state->pn_descsz;
} else {
(void) fprintf(stderr, MSG_INTL(MSG_NOTE_BADDESZ),
state->pns_file, state->pns_cache->c_name,
EC_WORD(noteoff), EC_WORD(state->pn_namesz));
return (0);
}
}
state->pn_type = *state->pns_data++;
/* Name */
if (state->pn_namesz) {
state->pn_name = (char *)state->pns_data;
pad = (state->pn_namesz +
(sizeof (Word) - 1)) & ~(sizeof (Word) - 1);
/* LINTED */
state->pns_data = (Word *)(state->pn_name + pad);
}
/*
* If multiple information blocks exist within a .note section
* account for any padding that must exist before the next
* information block.
*/
if ((pad = (state->pn_descsz & (sizeof (Word) - 1))) != 0) {
pad = sizeof (Word) - pad;
if (state->pns_size > pad)
state->pns_size -= pad;
}
/* Data */
if (state->pn_descsz) {
state->pn_desc = (const char *)state->pns_data;
/* LINTED */
state->pns_data = (Word *)(state->pn_desc +
state->pn_descsz + pad);
}
return (1);
}
/*
* Callback function for use with conv_str_to_c_literal() below.
*/
/*ARGSUSED2*/
static void
c_literal_cb(const void *ptr, size_t size, void *uvalue)
{
(void) fwrite(ptr, size, 1, stdout);
}
/*
* Traverse a note section analyzing each note information block.
* The data buffers size is used to validate references before they are made,
* and is decremented as each element is processed.
*/
void
note_entry(Cache *cache, Word *data, size_t size, Ehdr *ehdr, const char *file)
{
int cnt = 0;
int is_corenote;
int do_swap;
Conv_inv_buf_t inv_buf;
parse_note_t pnstate;
pnstate.pns_file = file;
pnstate.pns_cache = cache;
pnstate.pns_size = size;
pnstate.pns_data = data;
do_swap = _elf_sys_encoding() != ehdr->e_ident[EI_DATA];
/*
* Print out a single `note' information block.
*/
while (pnstate.pns_size > 0) {
if (parse_note_entry(&pnstate) == 0)
return;
/*
* Is this a Solaris core note? Such notes all have
* the name "CORE".
*/
is_corenote = (ehdr->e_type == ET_CORE) &&
(pnstate.pn_namesz == (MSG_STR_CORE_SIZE + 1)) &&
(strncmp(MSG_ORIG(MSG_STR_CORE), pnstate.pn_name,
MSG_STR_CORE_SIZE + 1) == 0);
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_FMT_NOTEENTNDX), EC_WORD(cnt));
cnt++;
dbg_print(0, MSG_ORIG(MSG_NOTE_NAMESZ),
EC_WORD(pnstate.pn_namesz));
dbg_print(0, MSG_ORIG(MSG_NOTE_DESCSZ),
EC_WORD(pnstate.pn_descsz));
if (is_corenote)
dbg_print(0, MSG_ORIG(MSG_NOTE_TYPE_STR),
conv_cnote_type(pnstate.pn_type, 0, &inv_buf));
else
dbg_print(0, MSG_ORIG(MSG_NOTE_TYPE),
EC_WORD(pnstate.pn_type));
if (pnstate.pn_namesz) {
dbg_print(0, MSG_ORIG(MSG_NOTE_NAME));
/*
* The name string can contain embedded 'null'
* bytes and/or unprintable characters. Also,
* the final NULL is documented in the ELF ABI
* as being included in the namesz. So, display
* the name using C literal string notation, and
* include the terminating NULL in the output.
* We don't show surrounding double quotes, as
* that implies the termination that we are showing
* explicitly.
*/
(void) fwrite(MSG_ORIG(MSG_STR_8SP),
MSG_STR_8SP_SIZE, 1, stdout);
conv_str_to_c_literal(pnstate.pn_name,
pnstate.pn_namesz, c_literal_cb, NULL);
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
}
if (pnstate.pn_descsz) {
int hexdump = 1;
/*
* If this is a core note, let the corenote()
* function handle it.
*/
if (is_corenote) {
/* We only issue the bad arch error once */
static int badnote_done = 0;
corenote_ret_t corenote_ret;
corenote_ret = corenote(ehdr->e_machine,
do_swap, pnstate.pn_type, pnstate.pn_desc,
pnstate.pn_descsz);
switch (corenote_ret) {
case CORENOTE_R_OK_DUMP:
hexdump = 1;
break;
case CORENOTE_R_OK:
hexdump = 0;
break;
case CORENOTE_R_BADDATA:
(void) fprintf(stderr,
MSG_INTL(MSG_NOTE_BADCOREDATA),
file);
break;
case CORENOTE_R_BADARCH:
if (badnote_done)
break;
(void) fprintf(stderr,
MSG_INTL(MSG_NOTE_BADCOREARCH),
file,
conv_ehdr_mach(ehdr->e_machine,
0, &inv_buf));
break;
case CORENOTE_R_BADTYPE:
(void) fprintf(stderr,
MSG_INTL(MSG_NOTE_BADCORETYPE),
file,
EC_WORD(pnstate.pn_type));
break;
}
}
/*
* The default thing when we don't understand
* the note data is to display it as hex bytes.
*/
if (hexdump) {
dbg_print(0, MSG_ORIG(MSG_NOTE_DESC));
dump_hex_bytes(pnstate.pn_desc,
pnstate.pn_descsz, 8, 4, 4);
}
}
}
}
/*
* Search for and process .note sections.
*
* Returns the number of note sections seen.
*/
static Word
note(Cache *cache, Word shnum, Ehdr *ehdr, const char *file)
{
Word cnt, note_cnt = 0;
/*
* Otherwise look for any .note sections.
*/
for (cnt = 1; cnt < shnum; cnt++) {
Cache *_cache = &cache[cnt];
Shdr *shdr = _cache->c_shdr;
if (shdr->sh_type != SHT_NOTE)
continue;
note_cnt++;
if (!match(MATCH_F_ALL, _cache->c_name, cnt, shdr->sh_type))
continue;
/*
* As these sections are often hand rolled, make sure they're
* properly aligned before proceeding, and issue an error
* as necessary.
*
* Note that we will continue on to display the note even
* if it has bad alignment. We can do this safely, because
* libelf knows the alignment required for SHT_NOTE, and
* takes steps to deliver a properly aligned buffer to us
* even if the actual file is misaligned.
*/
if (shdr->sh_offset & (sizeof (Word) - 1))
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADALIGN),
file, _cache->c_name);
if ((_cache->c_data == NULL) || (_cache->c_data->d_buf == NULL))
continue;
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_ELF_SCN_NOTE), _cache->c_name);
note_entry(_cache, (Word *)_cache->c_data->d_buf,
/* LINTED */
(Word)_cache->c_data->d_size, ehdr, file);
}
return (note_cnt);
}
/*
* The Linux Standard Base defines a special note named .note.ABI-tag
* that is used to maintain Linux ABI information. Presence of this section
* is a strong indication that the object should be considered to be
* ELFOSABI_LINUX.
*
* This function returns True (1) if such a note is seen, and False (0)
* otherwise.
*/
static int
has_linux_abi_note(Cache *cache, Word shnum, const char *file)
{
Word cnt;
for (cnt = 1; cnt < shnum; cnt++) {
parse_note_t pnstate;
Cache *_cache = &cache[cnt];
Shdr *shdr = _cache->c_shdr;
/*
* Section must be SHT_NOTE, must have the name
* .note.ABI-tag, and must have data.
*/
if ((shdr->sh_type != SHT_NOTE) ||
(strcmp(MSG_ORIG(MSG_STR_NOTEABITAG),
_cache->c_name) != 0) ||
(_cache->c_data == NULL) ||
(_cache->c_data->d_buf == NULL))
continue;
pnstate.pns_file = file;
pnstate.pns_cache = _cache;
pnstate.pns_size = _cache->c_data->d_size;
pnstate.pns_data = (Word *)_cache->c_data->d_buf;
while (pnstate.pns_size > 0) {
Word *w;
if (parse_note_entry(&pnstate) == 0)
break;
/*
* The type must be 1, and the name must be "GNU".
* The descsz must be at least 16 bytes.
*/
if ((pnstate.pn_type != 1) ||
(pnstate.pn_namesz != (MSG_STR_GNU_SIZE + 1)) ||
(strncmp(MSG_ORIG(MSG_STR_GNU), pnstate.pn_name,
MSG_STR_CORE_SIZE + 1) != 0) ||
(pnstate.pn_descsz < 16))
continue;
/*
* desc contains 4 32-bit fields. Field 0 must be 0,
* indicating Linux. The second, third, and fourth
* fields represent the earliest Linux kernel
* version compatible with this object.
*/
/*LINTED*/
w = (Word *) pnstate.pn_desc;
if (*w == 0)
return (1);
}
}
return (0);
}
/*
* Determine an individual hash entry. This may be the initial hash entry,
* or an associated chain entry.
*/
static void
hash_entry(Cache *refsec, Cache *strsec, const char *hsecname, Word hashndx,
Word symndx, Word symn, Sym *syms, const char *file, ulong_t bkts,
uint_t flags, int chain)
{
Sym *sym;
const char *symname, *str;
char _bucket[MAXNDXSIZE], _symndx[MAXNDXSIZE];
ulong_t nbkt, nhash;
if (symndx > symn) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_HSBADSYMNDX), file,
EC_WORD(symndx), EC_WORD(hashndx));
symname = MSG_INTL(MSG_STR_UNKNOWN);
} else {
sym = (Sym *)(syms + symndx);
symname = string(refsec, symndx, strsec, file, sym->st_name);
}
if (chain == 0) {
(void) snprintf(_bucket, MAXNDXSIZE, MSG_ORIG(MSG_FMT_INTEGER),
hashndx);
str = (const char *)_bucket;
} else
str = MSG_ORIG(MSG_STR_EMPTY);
(void) snprintf(_symndx, MAXNDXSIZE, MSG_ORIG(MSG_FMT_INDEX2),
EC_WORD(symndx));
dbg_print(0, MSG_ORIG(MSG_FMT_HASH_INFO), str, _symndx,
demangle(symname, flags));
/*
* Determine if this string is in the correct bucket.
*/
nhash = elf_hash(symname);
nbkt = nhash % bkts;
if (nbkt != hashndx) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADHASH), file,
hsecname, symname, EC_WORD(hashndx), nbkt);
}
}
#define MAXCOUNT 500
static void
hash(Cache *cache, Word shnum, const char *file, uint_t flags)
{
static int count[MAXCOUNT];
Word cnt;
Word ndx, bkts, nchain;
char number[MAXNDXSIZE];
for (cnt = 1; cnt < shnum; cnt++) {
Word *hash, *chain;
Cache *_cache = &cache[cnt];
Shdr *sshdr, *hshdr = _cache->c_shdr;
char *ssecname, *hsecname = _cache->c_name;
Sym *syms;
Word symn;
if (hshdr->sh_type != SHT_HASH)
continue;
/*
* Check the hash table data and size.
*/
if ((hshdr->sh_entsize == 0) || (hshdr->sh_size == 0)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, hsecname);
continue;
}
if ((_cache->c_data == NULL) ||
(_cache->c_data->d_buf == NULL)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, hsecname);
continue;
}
hash = (Word *)_cache->c_data->d_buf;
bkts = *hash++;
nchain = *hash++;
chain = hash + bkts;
/*
* The section holds the sizes in addition to the buckets and
* chains.
*/
if (_cache->c_data->d_size <
(bkts + nchain + 2) * sizeof (uint_t)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, hsecname);
continue;
}
/*
* Get the data buffer for the associated symbol table.
*/
if ((hshdr->sh_link == 0) || (hshdr->sh_link >= shnum)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHLINK),
file, hsecname, EC_WORD(hshdr->sh_link));
continue;
}
_cache = &cache[hshdr->sh_link];
ssecname = _cache->c_name;
if ((_cache->c_data == NULL) || (_cache->c_data->d_buf == NULL))
continue;
if ((syms = (Sym *)_cache->c_data->d_buf) == NULL) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, ssecname);
continue;
}
sshdr = _cache->c_shdr;
if ((sshdr->sh_entsize == 0) || (sshdr->sh_size == 0)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, ssecname);
continue;
}
/* LINTED */
symn = (Word)(sshdr->sh_size / sshdr->sh_entsize);
/*
* Check that there is a chain for each symbol.
*/
if (symn > nchain) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, ssecname);
continue;
}
/*
* Get the associated string table section.
*/
if ((sshdr->sh_link == 0) || (sshdr->sh_link >= shnum)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHLINK),
file, ssecname, EC_WORD(sshdr->sh_link));
continue;
}
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_ELF_SCN_HASH), hsecname);
dbg_print(0, MSG_INTL(MSG_ELF_HASH_INFO));
/*
* Loop through the hash buckets, printing the appropriate
* symbols.
*/
for (ndx = 0; ndx < bkts; ndx++, hash++) {
Word _ndx, _cnt;
if (*hash == 0) {
count[0]++;
continue;
}
/*
* Each hash bucket must contain to a valid chain index.
* Because the symbol table is checked to be the same
* length as the chain array, this also implicitly
* checks those bounds.
*/
if (*hash > nchain) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADCHAINIDX), file,
ssecname, EC_WORD(*hash), EC_WORD(ndx),
EC_WORD(nchain));
continue;
}
hash_entry(_cache, &cache[sshdr->sh_link], hsecname,
ndx, *hash, symn, syms, file, bkts, flags, 0);
/*
* Determine if any other symbols are chained to this
* bucket.
*/
_ndx = chain[*hash];
_cnt = 1;
while (_ndx) {
if (_ndx > nchain) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADCHAINIDX), file,
ssecname, EC_WORD(_ndx),
EC_WORD(ndx), EC_WORD(nchain));
break;
}
hash_entry(_cache, &cache[sshdr->sh_link],
hsecname, ndx, _ndx, symn, syms, file,
bkts, flags, 1);
_ndx = chain[_ndx];
_cnt++;
}
if (_cnt >= MAXCOUNT) {
(void) fprintf(stderr,
MSG_INTL(MSG_HASH_OVERFLW), file,
_cache->c_name, EC_WORD(ndx),
EC_WORD(_cnt));
} else
count[_cnt]++;
}
break;
}
/*
* Print out the count information.
*/
bkts = cnt = 0;
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
for (ndx = 0; ndx < MAXCOUNT; ndx++) {
Word _cnt;
if ((_cnt = count[ndx]) == 0)
continue;
(void) snprintf(number, MAXNDXSIZE,
MSG_ORIG(MSG_FMT_INTEGER), _cnt);
dbg_print(0, MSG_INTL(MSG_ELF_HASH_BKTS1), number,
EC_WORD(ndx));
bkts += _cnt;
cnt += (Word)(ndx * _cnt);
}
if (cnt) {
(void) snprintf(number, MAXNDXSIZE, MSG_ORIG(MSG_FMT_INTEGER),
bkts);
dbg_print(0, MSG_INTL(MSG_ELF_HASH_BKTS2), number,
EC_WORD(cnt));
}
}
static void
group(Cache *cache, Word shnum, const char *file, uint_t flags)
{
Word scnt;
for (scnt = 1; scnt < shnum; scnt++) {
Cache *_cache = &cache[scnt];
Shdr *shdr = _cache->c_shdr;
Word *grpdata, gcnt, grpcnt, symnum, unknown;
Cache *symsec, *strsec;
Sym *syms, *sym;
char flgstrbuf[MSG_GRP_COMDAT_SIZE + 10];
const char *grpnam;
if (shdr->sh_type != SHT_GROUP)
continue;
if (!match(MATCH_F_ALL, _cache->c_name, scnt, shdr->sh_type))
continue;
if ((_cache->c_data == NULL) ||
((grpdata = (Word *)_cache->c_data->d_buf) == NULL))
continue;
grpcnt = shdr->sh_size / sizeof (Word);
/*
* Get the data buffer for the associated symbol table and
* string table.
*/
if (stringtbl(cache, 1, scnt, shnum, file,
&symnum, &symsec, &strsec) == 0)
return;
syms = symsec->c_data->d_buf;
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_ELF_SCN_GRP), _cache->c_name);
dbg_print(0, MSG_INTL(MSG_GRP_TITLE));
/*
* The first element of the group defines the group. The
* associated symbol is defined by the sh_link field.
*/
if ((shdr->sh_info == SHN_UNDEF) || (shdr->sh_info > symnum)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHINFO),
file, _cache->c_name, EC_WORD(shdr->sh_info));
return;
}
(void) strcpy(flgstrbuf, MSG_ORIG(MSG_STR_OSQBRKT));
if (grpdata[0] & GRP_COMDAT) {
(void) strcat(flgstrbuf, MSG_ORIG(MSG_GRP_COMDAT));
}
if ((unknown = (grpdata[0] & ~GRP_COMDAT)) != 0) {
size_t len = strlen(flgstrbuf);
(void) snprintf(&flgstrbuf[len],
(MSG_GRP_COMDAT_SIZE + 10 - len),
MSG_ORIG(MSG_GRP_UNKNOWN), unknown);
}
(void) strcat(flgstrbuf, MSG_ORIG(MSG_STR_CSQBRKT));
sym = (Sym *)(syms + shdr->sh_info);
/*
* The GNU assembler can use section symbols as the signature
* symbol as described by this comment in the gold linker
* (found via google):
*
* It seems that some versions of gas will create a
* section group associated with a section symbol, and
* then fail to give a name to the section symbol. In
* such a case, use the name of the section.
*
* In order to support such objects, we do the same.
*/
grpnam = string(_cache, 0, strsec, file, sym->st_name);
if (((sym->st_name == 0) || (*grpnam == '\0')) &&
(ELF_ST_TYPE(sym->st_info) == STT_SECTION))
grpnam = cache[sym->st_shndx].c_name;
dbg_print(0, MSG_INTL(MSG_GRP_SIGNATURE), flgstrbuf,
demangle(grpnam, flags));
for (gcnt = 1; gcnt < grpcnt; gcnt++) {
char index[MAXNDXSIZE];
const char *name;
(void) snprintf(index, MAXNDXSIZE,
MSG_ORIG(MSG_FMT_INDEX), EC_XWORD(gcnt));
if ((grpdata[gcnt] == 0) || (grpdata[gcnt] >= shnum))
name = MSG_INTL(MSG_GRP_INVALSCN);
else
name = cache[grpdata[gcnt]].c_name;
(void) printf(MSG_ORIG(MSG_GRP_ENTRY), index, name,
EC_XWORD(grpdata[gcnt]));
}
}
}
static void
got(Cache *cache, Word shnum, Ehdr *ehdr, const char *file)
{
Cache *gotcache = NULL, *symtab = NULL;
Addr gotbgn, gotend;
Shdr *gotshdr;
Word cnt, gotents, gotndx;
size_t gentsize;
Got_info *gottable;
char *gotdata;
Sym *gotsym;
Xword gotsymaddr;
uint_t sys_encoding;
/*
* First, find the got.
*/
for (cnt = 1; cnt < shnum; cnt++) {
if (strncmp(cache[cnt].c_name, MSG_ORIG(MSG_ELF_GOT),
MSG_ELF_GOT_SIZE) == 0) {
gotcache = &cache[cnt];
break;
}
}
if (gotcache == NULL)
return;
/*
* A got section within a relocatable object is suspicious.
*/
if (ehdr->e_type == ET_REL) {
(void) fprintf(stderr, MSG_INTL(MSG_GOT_UNEXPECTED), file,
gotcache->c_name);
}
gotshdr = gotcache->c_shdr;
if (gotshdr->sh_size == 0) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, gotcache->c_name);
return;
}
gotbgn = gotshdr->sh_addr;
gotend = gotbgn + gotshdr->sh_size;
/*
* Some architectures don't properly set the sh_entsize for the GOT
* table. If it's not set, default to a size of a pointer.
*/
if ((gentsize = gotshdr->sh_entsize) == 0)
gentsize = sizeof (Xword);
if ((gotcache->c_data == NULL) || (gotcache->c_data->d_buf == NULL))
return;
/* LINTED */
gotents = (Word)(gotshdr->sh_size / gentsize);
gotdata = gotcache->c_data->d_buf;
if ((gottable = calloc(gotents, sizeof (Got_info))) == 0) {
int err = errno;
(void) fprintf(stderr, MSG_INTL(MSG_ERR_MALLOC), file,
strerror(err));
return;
}
/*
* Now we scan through all the sections looking for any relocations
* that may be against the GOT. Since these may not be isolated to a
* .rel[a].got section we check them all.
* While scanning sections save the symbol table entry (a symtab
* overriding a dynsym) so that we can lookup _GLOBAL_OFFSET_TABLE_.
*/
for (cnt = 1; cnt < shnum; cnt++) {
Word type, symnum;
Xword relndx, relnum, relsize;
void *rels;
Sym *syms;
Cache *symsec, *strsec;
Cache *_cache = &cache[cnt];
Shdr *shdr;
shdr = _cache->c_shdr;
type = shdr->sh_type;
if ((symtab == 0) && (type == SHT_DYNSYM)) {
symtab = _cache;
continue;
}
if (type == SHT_SYMTAB) {
symtab = _cache;
continue;
}
if ((type != SHT_RELA) && (type != SHT_REL))
continue;
/*
* Decide entry size.
*/
if (((relsize = shdr->sh_entsize) == 0) ||
(relsize > shdr->sh_size)) {
if (type == SHT_RELA)
relsize = sizeof (Rela);
else
relsize = sizeof (Rel);
}
/*
* Determine the number of relocations available.
*/
if (shdr->sh_size == 0) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, _cache->c_name);
continue;
}
if ((_cache->c_data == NULL) || (_cache->c_data->d_buf == NULL))
continue;
rels = _cache->c_data->d_buf;
relnum = shdr->sh_size / relsize;
/*
* Get the data buffer for the associated symbol table and
* string table.
*/
if (stringtbl(cache, 1, cnt, shnum, file,
&symnum, &symsec, &strsec) == 0)
continue;
syms = symsec->c_data->d_buf;
/*
* Loop through the relocation entries.
*/
for (relndx = 0; relndx < relnum; relndx++,
rels = (void *)((char *)rels + relsize)) {
char section[BUFSIZ];
Addr offset;
Got_info *gip;
Word symndx, reltype;
Rela *rela;
Rel *rel;
/*
* Unravel the relocation.
*/
if (type == SHT_RELA) {
rela = (Rela *)rels;
symndx = ELF_R_SYM(rela->r_info);
reltype = ELF_R_TYPE(rela->r_info,
ehdr->e_machine);
offset = rela->r_offset;
} else {
rel = (Rel *)rels;
symndx = ELF_R_SYM(rel->r_info);
reltype = ELF_R_TYPE(rel->r_info,
ehdr->e_machine);
offset = rel->r_offset;
}
/*
* Only pay attention to relocations against the GOT.
*/
if ((offset < gotbgn) || (offset >= gotend))
continue;
if ((gotshdr->sh_entsize == 0) ||
(gotshdr->sh_size == 0)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
file, gotcache->c_name);
continue;
}
/* LINTED */
gotndx = (Word)((offset - gotbgn) /
gotshdr->sh_entsize);
gip = &gottable[gotndx];
if (gip->g_reltype != 0) {
(void) fprintf(stderr,
MSG_INTL(MSG_GOT_MULTIPLE), file,
EC_WORD(gotndx), EC_ADDR(offset));
continue;
}
if (symndx)
gip->g_symname = relsymname(cache, _cache,
strsec, symndx, symnum, relndx, syms,
section, BUFSIZ, file);
gip->g_reltype = reltype;
gip->g_rel = rels;
}
}
if (symlookup(MSG_ORIG(MSG_SYM_GOT), cache, shnum, &gotsym, NULL,
symtab, file))
gotsymaddr = gotsym->st_value;
else
gotsymaddr = gotbgn;
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_ELF_SCN_GOT), gotcache->c_name);
Elf_got_title(0);
sys_encoding = _elf_sys_encoding();
for (gotndx = 0; gotndx < gotents; gotndx++) {
Got_info *gip;
Sword gindex;
Addr gaddr;
Xword gotentry;
gip = &gottable[gotndx];
gaddr = gotbgn + (gotndx * gentsize);
gindex = (Sword)(gaddr - gotsymaddr) / (Sword)gentsize;
if (gentsize == sizeof (Word))
/* LINTED */
gotentry = (Xword)(*((Word *)(gotdata) + gotndx));
else
/* LINTED */
gotentry = *((Xword *)(gotdata) + gotndx);
Elf_got_entry(0, gindex, gaddr, gotentry, ehdr->e_machine,
ehdr->e_ident[EI_DATA], sys_encoding,
gip->g_reltype, gip->g_rel, gip->g_symname);
}
free(gottable);
}
void
checksum(Elf *elf)
{
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_STR_CHECKSUM), elf_checksum(elf));
}
/*
* This variable is used by regular() to communicate the address of
* the section header cache to sort_shdr_ndx_arr(). Unfortunately,
* the qsort() interface does not include a userdata argument by which
* such arbitrary data can be passed, so we are stuck using global data.
*/
static Cache *sort_shdr_ndx_arr_cache;
/*
* Used with qsort() to sort the section indices so that they can be
* used to access the section headers in order of increasing data offset.
*
* entry:
* sort_shdr_ndx_arr_cache - Contains address of
* section header cache.
* v1, v2 - Point at elements of sort_shdr_bits array to be compared.
*
* exit:
* Returns -1 (less than), 0 (equal) or 1 (greater than).
*/
static int
sort_shdr_ndx_arr(const void *v1, const void *v2)
{
Cache *cache1 = sort_shdr_ndx_arr_cache + *((size_t *)v1);
Cache *cache2 = sort_shdr_ndx_arr_cache + *((size_t *)v2);
if (cache1->c_shdr->sh_offset < cache2->c_shdr->sh_offset)
return (-1);
if (cache1->c_shdr->sh_offset > cache2->c_shdr->sh_offset)
return (1);
return (0);
}
static int
shdr_cache(const char *file, Elf *elf, Ehdr *ehdr, size_t shstrndx,
size_t shnum, Cache **cache_ret, Word flags)
{
Elf_Scn *scn;
Elf_Data *data;
size_t ndx;
Shdr *nameshdr = NULL;
char *names = NULL;
Cache *cache, *_cache;
size_t *shdr_ndx_arr, shdr_ndx_arr_cnt;
/*
* Obtain the .shstrtab data buffer to provide the required section
* name strings.
*/
if (shstrndx == SHN_UNDEF) {
/*
* It is rare, but legal, for an object to lack a
* header string table section.
*/
names = NULL;
(void) fprintf(stderr, MSG_INTL(MSG_ERR_NOSHSTRSEC), file);
} else if ((scn = elf_getscn(elf, shstrndx)) == NULL) {
failure(file, MSG_ORIG(MSG_ELF_GETSCN));
(void) fprintf(stderr, MSG_INTL(MSG_ELF_ERR_SHDR),
EC_XWORD(shstrndx));
} else if ((data = elf_getdata(scn, NULL)) == NULL) {
failure(file, MSG_ORIG(MSG_ELF_GETDATA));
(void) fprintf(stderr, MSG_INTL(MSG_ELF_ERR_DATA),
EC_XWORD(shstrndx));
} else if ((nameshdr = elf_getshdr(scn)) == NULL) {
failure(file, MSG_ORIG(MSG_ELF_GETSHDR));
(void) fprintf(stderr, MSG_INTL(MSG_ELF_ERR_SCN),
EC_WORD(elf_ndxscn(scn)));
} else if ((names = data->d_buf) == NULL)
(void) fprintf(stderr, MSG_INTL(MSG_ERR_SHSTRNULL), file);
/*
* Allocate a cache to maintain a descriptor for each section.
*/
if ((*cache_ret = cache = malloc(shnum * sizeof (Cache))) == NULL) {
int err = errno;
(void) fprintf(stderr, MSG_INTL(MSG_ERR_MALLOC),
file, strerror(err));
return (0);
}
*cache = cache_init;
_cache = cache;
_cache++;
/*
* Allocate an array that will hold the section index for
* each section that has data in the ELF file:
*
* - Is not a NOBITS section
* - Data has non-zero length
*
* Note that shnum is an upper bound on the size required. It
* is likely that we won't use a few of these array elements.
* Allocating a modest amount of extra memory in this case means
* that we can avoid an extra loop to count the number of needed
* items, and can fill this array immediately in the first loop
* below.
*/
if ((shdr_ndx_arr = malloc(shnum * sizeof (*shdr_ndx_arr))) == NULL) {
int err = errno;
(void) fprintf(stderr, MSG_INTL(MSG_ERR_MALLOC),
file, strerror(err));
return (0);
}
shdr_ndx_arr_cnt = 0;
/*
* Traverse the sections of the file. This gathering of data is
* carried out in two passes. First, the section headers are captured
* and the section header names are evaluated. A verification pass is
* then carried out over the section information. Files have been
* known to exhibit overlapping (and hence erroneous) section header
* information.
*
* Finally, the data for each section is obtained. This processing is
* carried out after section verification because should any section
* header overlap occur, and a file needs translating (ie. xlate'ing
* information from a non-native architecture file), then the process
* of translation can corrupt the section header information. Of
* course, if there is any section overlap, the data related to the
* sections is going to be compromised. However, it is the translation
* of this data that has caused problems with elfdump()'s ability to
* extract the data.
*/
for (ndx = 1, scn = NULL; (scn = elf_nextscn(elf, scn)) != NULL;
ndx++, _cache++) {
char scnndxnm[100];
_cache->c_ndx = ndx;
_cache->c_scn = scn;
if ((_cache->c_shdr = elf_getshdr(scn)) == NULL) {
failure(file, MSG_ORIG(MSG_ELF_GETSHDR));
(void) fprintf(stderr, MSG_INTL(MSG_ELF_ERR_SCN),
EC_WORD(elf_ndxscn(scn)));
}
/*
* If this section has data in the file, include it in
* the array of sections to check for address overlap.
*/
if (_cache->c_shdr != NULL &&
(_cache->c_shdr->sh_size != 0) &&
(_cache->c_shdr->sh_type != SHT_NOBITS))
shdr_ndx_arr[shdr_ndx_arr_cnt++] = ndx;
/*
* If a shstrtab exists, assign the section name.
*/
if (names && _cache->c_shdr) {
if (_cache->c_shdr->sh_name != 0 &&
(nameshdr != NULL &&
nameshdr->sh_size > _cache->c_shdr->sh_name)) {
const char *symname;
char *secname;
secname = names + _cache->c_shdr->sh_name;
/*
* A SUN naming convention employs a "%" within
* a section name to indicate a section/symbol
* name. This originated from the compilers
* -xF option, that places functions into their
* own sections. This convention (which has no
* formal standard) has also been followed for
* COMDAT sections. To demangle the symbol
* name, the name must be separated from the
* section name.
*/
if (((flags & FLG_CTL_DEMANGLE) == 0) ||
((symname = strchr(secname, '%')) == NULL))
_cache->c_name = secname;
else {
size_t secsz = ++symname - secname;
size_t strsz;
symname = demangle(symname, flags);
strsz = secsz + strlen(symname) + 1;
if ((_cache->c_name =
malloc(strsz)) == NULL) {
int err = errno;
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_MALLOC),
file, strerror(err));
free(shdr_ndx_arr);
return (0);
}
(void) snprintf(_cache->c_name, strsz,
MSG_ORIG(MSG_FMT_SECSYM),
EC_WORD(secsz), secname, symname);
}
continue;
}
/*
* Generate an error if the section name index is zero
* or exceeds the shstrtab data. Fall through to
* fabricate a section name.
*/
if ((_cache->c_shdr->sh_name == 0) ||
/* LINTED */
(nameshdr->sh_size <= _cache->c_shdr->sh_name)) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADSHNAME), file,
EC_WORD(ndx),
EC_XWORD(_cache->c_shdr->sh_name));
}
}
/*
* If there exists no shstrtab data, or a section header has no
* name (an invalid index of 0), then compose a name for the
* section.
*/
(void) snprintf(scnndxnm, sizeof (scnndxnm),
MSG_INTL(MSG_FMT_SCNNDX), ndx);
if ((_cache->c_name = malloc(strlen(scnndxnm) + 1)) == NULL) {
int err = errno;
(void) fprintf(stderr, MSG_INTL(MSG_ERR_MALLOC),
file, strerror(err));
free(shdr_ndx_arr);
return (0);
}
(void) strcpy(_cache->c_name, scnndxnm);
}
/*
* Having collected all the sections, validate their address range.
* Cases have existed where the section information has been invalid.
* This can lead to all sorts of other, hard to diagnose errors, as
* each section is processed individually (ie. with elf_getdata()).
* Here, we carry out some address comparisons to catch a family of
* overlapping memory issues we have observed (likely, there are others
* that we have yet to discover).
*
* Note, should any memory overlap occur, obtaining any additional
* data from the file is questionable. However, it might still be
* possible to inspect the ELF header, Programs headers, or individual
* sections, so rather than bailing on an error condition, continue
* processing to see if any data can be salvaged.
*/
if (shdr_ndx_arr_cnt > 1) {
sort_shdr_ndx_arr_cache = cache;
qsort(shdr_ndx_arr, shdr_ndx_arr_cnt,
sizeof (*shdr_ndx_arr), sort_shdr_ndx_arr);
}
for (ndx = 0; ndx < shdr_ndx_arr_cnt; ndx++) {
Cache *_cache = cache + shdr_ndx_arr[ndx];
Shdr *shdr = _cache->c_shdr;
Off bgn1, bgn = shdr->sh_offset;
Off end1, end = shdr->sh_offset + shdr->sh_size;
size_t ndx1;
/*
* Check the section against all following ones, reporting
* any overlaps. Since we've sorted the sections by offset,
* we can stop after the first comparison that fails. There
* are no overlaps in a properly formed ELF file, in which
* case this algorithm runs in O(n) time. This will degenerate
* to O(n^2) for a completely broken file. Such a file is
* (1) highly unlikely, and (2) unusable, so it is reasonable
* for the analysis to take longer.
*/
for (ndx1 = ndx + 1; ndx1 < shdr_ndx_arr_cnt; ndx1++) {
Cache *_cache1 = cache + shdr_ndx_arr[ndx1];
Shdr *shdr1 = _cache1->c_shdr;
bgn1 = shdr1->sh_offset;
end1 = shdr1->sh_offset + shdr1->sh_size;
if (((bgn1 <= bgn) && (end1 > bgn)) ||
((bgn1 < end) && (end1 >= end))) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_SECMEMOVER), file,
EC_WORD(elf_ndxscn(_cache->c_scn)),
_cache->c_name, EC_OFF(bgn), EC_OFF(end),
EC_WORD(elf_ndxscn(_cache1->c_scn)),
_cache1->c_name, EC_OFF(bgn1),
EC_OFF(end1));
} else { /* No overlap, so can stop */
break;
}
}
/*
* In addition to checking for sections overlapping
* each other (done above), we should also make sure
* the section doesn't overlap the section header array.
*/
bgn1 = ehdr->e_shoff;
end1 = ehdr->e_shoff + (ehdr->e_shentsize * ehdr->e_shnum);
if (((bgn1 <= bgn) && (end1 > bgn)) ||
((bgn1 < end) && (end1 >= end))) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_SHDRMEMOVER), file, EC_OFF(bgn1),
EC_OFF(end1),
EC_WORD(elf_ndxscn(_cache->c_scn)),
_cache->c_name, EC_OFF(bgn), EC_OFF(end));
}
}
/*
* Obtain the data for each section.
*/
for (ndx = 1; ndx < shnum; ndx++) {
Cache *_cache = &cache[ndx];
Elf_Scn *scn = _cache->c_scn;
if ((_cache->c_data = elf_getdata(scn, NULL)) == NULL) {
failure(file, MSG_ORIG(MSG_ELF_GETDATA));
(void) fprintf(stderr, MSG_INTL(MSG_ELF_ERR_SCNDATA),
EC_WORD(elf_ndxscn(scn)));
}
/*
* If a string table, verify that it has NULL first and
* final bytes.
*/
if ((_cache->c_shdr->sh_type == SHT_STRTAB) &&
(_cache->c_data != NULL) &&
(_cache->c_data->d_buf != NULL) &&
(_cache->c_data->d_size > 0)) {
const char *s = _cache->c_data->d_buf;
if ((*s != '\0') ||
(*(s + _cache->c_data->d_size - 1) != '\0'))
(void) fprintf(stderr, MSG_INTL(MSG_ERR_MALSTR),
file, _cache->c_name);
}
}
free(shdr_ndx_arr);
return (1);
}
/*
* Generate a cache of section headers and related information
* for use by the rest of elfdump. If requested (or the file
* contains no section headers), we generate a fake set of
* headers from the information accessible from the program headers.
* Otherwise, we use the real section headers contained in the file.
*/
static int
create_cache(const char *file, int fd, Elf *elf, Ehdr *ehdr, Cache **cache,
size_t shstrndx, size_t *shnum, uint_t *flags)
{
/*
* If there are no section headers, then resort to synthesizing
* section headers from the program headers. This is normally
* only done by explicit request, but in this case there's no
* reason not to go ahead, since the alternative is simply to quit.
*/
if ((*shnum <= 1) && ((*flags & FLG_CTL_FAKESHDR) == 0)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_NOSHDR), file);
*flags |= FLG_CTL_FAKESHDR;
}
if (*flags & FLG_CTL_FAKESHDR) {
if (fake_shdr_cache(file, fd, elf, ehdr, cache, shnum) == 0)
return (0);
} else {
if (shdr_cache(file, elf, ehdr, shstrndx, *shnum,
cache, *flags) == 0)
return (0);
}
return (1);
}
int
regular(const char *file, int fd, Elf *elf, uint_t flags,
const char *wname, int wfd, uchar_t osabi)
{
enum { CACHE_NEEDED, CACHE_OK, CACHE_FAIL} cache_state = CACHE_NEEDED;
Elf_Scn *scn;
Ehdr *ehdr;
size_t ndx, shstrndx, shnum, phnum;
Shdr *shdr;
Cache *cache;
VERSYM_STATE versym = { 0 };
int ret = 0;
int addr_align;
if ((ehdr = elf_getehdr(elf)) == NULL) {
failure(file, MSG_ORIG(MSG_ELF_GETEHDR));
return (ret);
}
if (elf_getshdrnum(elf, &shnum) == -1) {
failure(file, MSG_ORIG(MSG_ELF_GETSHDRNUM));
return (ret);
}
if (elf_getshdrstrndx(elf, &shstrndx) == -1) {
failure(file, MSG_ORIG(MSG_ELF_GETSHDRSTRNDX));
return (ret);
}
if (elf_getphdrnum(elf, &phnum) == -1) {
failure(file, MSG_ORIG(MSG_ELF_GETPHDRNUM));
return (ret);
}
/*
* If the user requested section headers derived from the
* program headers (-P option) and this file doesn't have
* any program headers (i.e. ET_REL), then we can't do it.
*/
if ((phnum == 0) && (flags & FLG_CTL_FAKESHDR)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_PNEEDSPH), file);
return (ret);
}
if ((scn = elf_getscn(elf, 0)) != NULL) {
if ((shdr = elf_getshdr(scn)) == NULL) {
failure(file, MSG_ORIG(MSG_ELF_GETSHDR));
(void) fprintf(stderr, MSG_INTL(MSG_ELF_ERR_SCN), 0);
return (ret);
}
} else
shdr = NULL;
/*
* Print the elf header.
*/
if (flags & FLG_SHOW_EHDR)
Elf_ehdr(0, ehdr, shdr);
/*
* If the section headers or program headers have inadequate
* alignment for the class of object, print a warning. libelf
* can handle such files, but programs that use them can crash
* when they dereference unaligned items.
*
* Note that the AMD64 ABI, although it is a 64-bit architecture,
* allows access to data types smaller than 128-bits to be on
* word alignment.
*/
if (ehdr->e_machine == EM_AMD64)
addr_align = sizeof (Word);
else
addr_align = sizeof (Addr);
if (ehdr->e_phoff & (addr_align - 1))
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADPHDRALIGN), file);
if (ehdr->e_shoff & (addr_align - 1))
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHDRALIGN), file);
/*
* Determine the Operating System ABI (osabi) we will use to
* interpret the object.
*/
if (flags & FLG_CTL_OSABI) {
/*
* If the user explicitly specifies '-O none', we need
* to display a completely generic view of the file.
* However, libconv is written to assume that ELFOSABI_NONE
* is equivalent to ELFOSABI_SOLARIS. To get the desired
* effect, we use an osabi that libconv has no knowledge of.
*/
if (osabi == ELFOSABI_NONE)
osabi = ELFOSABI_UNKNOWN4;
} else {
/* Determine osabi from file */
osabi = ehdr->e_ident[EI_OSABI];
if (osabi == ELFOSABI_NONE) {
/*
* Chicken/Egg scenario:
*
* Ideally, we wait to create the section header cache
* until after the program headers are printed. If we
* only output program headers, we can skip building
* the cache entirely.
*
* Proper interpretation of program headers requires
* the osabi, which is supposed to be in the ELF header.
* However, many systems (Solaris and Linux included)
* have a history of setting the osabi to the generic
* SysV ABI (ELFOSABI_NONE). We assume ELFOSABI_SOLARIS
* in such cases, but would like to check the object
* to see if it has a Linux .note.ABI-tag section,
* which implies ELFOSABI_LINUX. This requires a
* section header cache.
*
* To break the cycle, we create section headers now
* if osabi is ELFOSABI_NONE, and later otherwise.
* If it succeeds, we use them, if not, we defer
* exiting until after the program headers are out.
*/
if (create_cache(file, fd, elf, ehdr, &cache,
shstrndx, &shnum, &flags) == 0) {
cache_state = CACHE_FAIL;
} else {
cache_state = CACHE_OK;
if (has_linux_abi_note(cache, shnum, file)) {
Conv_inv_buf_t ibuf1, ibuf2;
(void) fprintf(stderr,
MSG_INTL(MSG_INFO_LINUXOSABI), file,
conv_ehdr_osabi(osabi, 0, &ibuf1),
conv_ehdr_osabi(ELFOSABI_LINUX,
0, &ibuf2));
osabi = ELFOSABI_LINUX;
}
}
}
/*
* We treat ELFOSABI_NONE identically to ELFOSABI_SOLARIS.
* Mapping NONE to SOLARIS simplifies the required test.
*/
if (osabi == ELFOSABI_NONE)
osabi = ELFOSABI_SOLARIS;
}
/*
* Print the program headers.
*/
if ((flags & FLG_SHOW_PHDR) && (phnum != 0)) {
Phdr *phdr;
if ((phdr = elf_getphdr(elf)) == NULL) {
failure(file, MSG_ORIG(MSG_ELF_GETPHDR));
return (ret);
}
for (ndx = 0; ndx < phnum; phdr++, ndx++) {
if (!match(MATCH_F_PHDR| MATCH_F_NDX | MATCH_F_TYPE,
NULL, ndx, phdr->p_type))
continue;
dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(0, MSG_INTL(MSG_ELF_PHDR), EC_WORD(ndx));
Elf_phdr(0, osabi, ehdr->e_machine, phdr);
}
}
/*
* If we have flag bits set that explicitly require a show or calc
* operation, but none of them require the section headers, then
* we are done and can return now.
*/
if (((flags & (FLG_MASK_SHOW | FLG_MASK_CALC)) != 0) &&
((flags & (FLG_MASK_SHOW_SHDR | FLG_MASK_CALC_SHDR)) == 0))
return (ret);
/*
* Everything from this point on requires section headers.
* If we have no section headers, there is no reason to continue.
*
* If we tried above to create the section header cache and failed,
* it is time to exit. Otherwise, create it if needed.
*/
switch (cache_state) {
case CACHE_NEEDED:
if (create_cache(file, fd, elf, ehdr, &cache, shstrndx,
&shnum, &flags) == 0)
return (ret);
break;
case CACHE_OK:
break;
case CACHE_FAIL:
return (ret);
}
if (shnum <= 1)
goto done;
/*
* If -w was specified, find and write out the section(s) data.
*/
if (wfd) {
for (ndx = 1; ndx < shnum; ndx++) {
Cache *_cache = &cache[ndx];
if (match(MATCH_F_STRICT | MATCH_F_ALL, _cache->c_name,
ndx, _cache->c_shdr->sh_type) &&
_cache->c_data && _cache->c_data->d_buf) {
if (write(wfd, _cache->c_data->d_buf,
_cache->c_data->d_size) !=
_cache->c_data->d_size) {
int err = errno;
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_WRITE), wname,
strerror(err));
/*
* Return an exit status of 1, because
* the failure is not related to the
* ELF file, but by system resources.
*/
ret = 1;
goto done;
}
}
}
}
/*
* If we have no flag bits set that explicitly require a show or calc
* operation, but match options (-I, -N, -T) were used, then run
* through the section headers and see if we can't deduce show flags
* from the match options given.
*
* We don't do this if -w was specified, because (-I, -N, -T) used
* with -w in lieu of some other option is supposed to be quiet.
*/
if ((wfd == 0) && (flags & FLG_CTL_MATCH) &&
((flags & (FLG_MASK_SHOW | FLG_MASK_CALC)) == 0)) {
for (ndx = 1; ndx < shnum; ndx++) {
Cache *_cache = &cache[ndx];
if (!match(MATCH_F_STRICT | MATCH_F_ALL, _cache->c_name,
ndx, _cache->c_shdr->sh_type))
continue;
switch (_cache->c_shdr->sh_type) {
case SHT_PROGBITS:
/*
* Heuristic time: It is usually bad form
* to assume the meaning/format of a PROGBITS
* section based on its name. However, there
* are ABI mandated exceptions. Check for
* these special names.
*/
/* The ELF ABI specifies .interp and .got */
if (strcmp(_cache->c_name,
MSG_ORIG(MSG_ELF_INTERP)) == 0) {
flags |= FLG_SHOW_INTERP;
break;
}
if (strcmp(_cache->c_name,
MSG_ORIG(MSG_ELF_GOT)) == 0) {
flags |= FLG_SHOW_GOT;
break;
}
/*
* The GNU compilers, and amd64 ABI, define
* .eh_frame and .eh_frame_hdr. The Sun
* C++ ABI defines .exception_ranges.
*/
if ((strncmp(_cache->c_name,
MSG_ORIG(MSG_SCN_FRM),
MSG_SCN_FRM_SIZE) == 0) ||
(strncmp(_cache->c_name,
MSG_ORIG(MSG_SCN_EXRANGE),
MSG_SCN_EXRANGE_SIZE) == 0)) {
flags |= FLG_SHOW_UNWIND;
break;
}
break;
case SHT_SYMTAB:
case SHT_DYNSYM:
case SHT_SUNW_LDYNSYM:
case SHT_SUNW_versym:
case SHT_SYMTAB_SHNDX:
flags |= FLG_SHOW_SYMBOLS;
break;
case SHT_RELA:
case SHT_REL:
flags |= FLG_SHOW_RELOC;
break;
case SHT_HASH:
flags |= FLG_SHOW_HASH;
break;
case SHT_DYNAMIC:
flags |= FLG_SHOW_DYNAMIC;
break;
case SHT_NOTE:
flags |= FLG_SHOW_NOTE;
break;
case SHT_GROUP:
flags |= FLG_SHOW_GROUP;
break;
case SHT_SUNW_symsort:
case SHT_SUNW_tlssort:
flags |= FLG_SHOW_SORT;
break;
case SHT_SUNW_cap:
flags |= FLG_SHOW_CAP;
break;
case SHT_SUNW_move:
flags |= FLG_SHOW_MOVE;
break;
case SHT_SUNW_syminfo:
flags |= FLG_SHOW_SYMINFO;
break;
case SHT_SUNW_verdef:
case SHT_SUNW_verneed:
flags |= FLG_SHOW_VERSIONS;
break;
case SHT_AMD64_UNWIND:
flags |= FLG_SHOW_UNWIND;
break;
}
}
}
if (flags & FLG_SHOW_SHDR)
sections(file, cache, shnum, ehdr, osabi);
if (flags & FLG_SHOW_INTERP)
interp(file, cache, shnum, phnum, elf, ehdr);
if ((osabi == ELFOSABI_SOLARIS) || (osabi == ELFOSABI_LINUX))
versions(cache, shnum, file, flags, &versym);
if (flags & FLG_SHOW_SYMBOLS)
symbols(cache, shnum, ehdr, osabi, &versym, file, flags);
if ((flags & FLG_SHOW_SORT) && (osabi == ELFOSABI_SOLARIS))
sunw_sort(cache, shnum, ehdr, osabi, &versym, file, flags);
if (flags & FLG_SHOW_HASH)
hash(cache, shnum, file, flags);
if (flags & FLG_SHOW_GOT)
got(cache, shnum, ehdr, file);
if (flags & FLG_SHOW_GROUP)
group(cache, shnum, file, flags);
if (flags & FLG_SHOW_SYMINFO)
syminfo(cache, shnum, ehdr, osabi, file);
if (flags & FLG_SHOW_RELOC)
reloc(cache, shnum, ehdr, file);
if (flags & FLG_SHOW_DYNAMIC)
dynamic(cache, shnum, ehdr, osabi, file, phnum, elf);
if (flags & FLG_SHOW_NOTE) {
Word note_cnt;
size_t note_shnum;
Cache *note_cache;
note_cnt = note(cache, shnum, ehdr, file);
/*
* Solaris core files have section headers, but these
* headers do not include SHT_NOTE sections that reference
* the core note sections. This means that note() won't
* find the core notes. Fake section headers (-P option)
* recover these sections, but it is inconvenient to require
* users to specify -P in this situation. If the following
* are all true:
*
* - No note sections were found
* - This is a core file
* - We are not already using fake section headers
*
* then we will automatically generate fake section headers
* and then process them in a second call to note().
*/
if ((note_cnt == 0) && (ehdr->e_type == ET_CORE) &&
!(flags & FLG_CTL_FAKESHDR) &&
(fake_shdr_cache(file, fd, elf, ehdr,
¬e_cache, ¬e_shnum) != 0)) {
(void) note(note_cache, note_shnum, ehdr, file);
fake_shdr_cache_free(note_cache, note_shnum);
}
}
if ((flags & FLG_SHOW_MOVE) && (osabi == ELFOSABI_SOLARIS))
move(cache, shnum, file, flags);
if (flags & FLG_CALC_CHECKSUM)
checksum(elf);
if ((flags & FLG_SHOW_CAP) && (osabi == ELFOSABI_SOLARIS))
cap(file, cache, shnum, phnum, ehdr, osabi, elf, flags);
if ((flags & FLG_SHOW_UNWIND) &&
((osabi == ELFOSABI_SOLARIS) || (osabi == ELFOSABI_LINUX)))
unwind(cache, shnum, phnum, ehdr, osabi, file, elf, flags);
/* Release the memory used to cache section headers */
done:
if (flags & FLG_CTL_FAKESHDR)
fake_shdr_cache_free(cache, shnum);
else
free(cache);
return (ret);
}
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2012 DEY Storage Systems, Inc. All rights reserved.
# Copyright 2018 Joyent, Inc.
# Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
# Copyright 2024 Oxide Computer Company
#
@ _START_
# Message file for cmd/sgs/elfdump.
@ MSG_ID_ELFDUMP
# Usage Messages
@ MSG_USAGE_BRIEF "usage: %s [-cCdegGhHiklmnrSsuvy] [-I index] \
[-N name] [-O osabi] [-T type] [-p | -w outfile] \
file...\n"
@ MSG_USAGE_DETAIL1 "\t[-c]\t\tdump section header information\n"
@ MSG_USAGE_DETAIL2 "\t[-C]\t\tdemangle symbol names\n"
@ MSG_USAGE_DETAIL3 "\t[-d]\t\tdump the contents of the .dynamic section\n"
@ MSG_USAGE_DETAIL4 "\t[-e]\t\tdump the elf header\n"
@ MSG_USAGE_DETAIL5 "\t[-g]\t\tdump the contents of the .group sections\n"
@ MSG_USAGE_DETAIL6 "\t[-G]\t\tdump the contents of the .got section\n"
@ MSG_USAGE_DETAIL7 "\t[-h]\t\tdump the contents of the .hash section\n"
@ MSG_USAGE_DETAIL8 "\t[-H]\t\tdump the contents of the .SUNW_cap section\n"
@ MSG_USAGE_DETAIL9 "\t[-i]\t\tdump the contents of the .interp section\n"
@ MSG_USAGE_DETAIL10 "\t[-I index]\tqualify an option with an index\n"
@ MSG_USAGE_DETAIL11 "\t[-l]\t\tdump with no truncated section names\n"
@ MSG_USAGE_DETAIL12 "\t[-k]\t\tcalculate elf checksum\n"
@ MSG_USAGE_DETAIL13 "\t[-m]\t\tdump the contents of the .SUNW_move \
section\n"
@ MSG_USAGE_DETAIL14 "\t[-n]\t\tdump the contents of the .note section\n"
@ MSG_USAGE_DETAIL15 "\t[-N name]\tqualify an option with a `name'\n"
@ MSG_USAGE_DETAIL16 "\t[-O osabi]\tuse given osabi to interpret object\n"
@ MSG_USAGE_DETAIL17 "\t[-P]\t\tuse program headers to generate \
section headers\n"
@ MSG_USAGE_DETAIL18 "\t[-p]\t\tdump the program headers\n"
@ MSG_USAGE_DETAIL19 "\t[-r]\t\tdump the contents of the relocation \
sections\n"
@ MSG_USAGE_DETAIL20 "\t[-S]\t\tdump the contents of the sort index \
sections\n"
@ MSG_USAGE_DETAIL21 "\t[-s]\t\tdump the contents of the symbol table \
sections\n"
@ MSG_USAGE_DETAIL22 "\t[-T type]\tqualify an option with a section or \
program header type\n"
@ MSG_USAGE_DETAIL23 "\t[-u]\t\tdump the contents of a frame unwind \
section\n"
@ MSG_USAGE_DETAIL24 "\t[-v]\t\tdump the contents of the version sections\n"
@ MSG_USAGE_DETAIL25 "\t[-w file]\twrite the contents of specified section \
to `file'\n"
@ MSG_USAGE_DETAIL26 "\t[-y]\t\tdump the contents of the .SUNW_syminfo \
section\n"
# Errors
@ MSG_ERR_BADFILE "%s: invalid file type\n"
@ MSG_ERR_BADREL1 "%s: bad relocation entry: %s: relocation requires \
symbol\n"
@ MSG_ERR_NOSHDR "%s: section headers are not present: synthesizing \
from program headers (-P option)\n"
@ MSG_ERR_PNEEDSPH "%s: file without program headers is incompatible \
with -P option\n"
@ MSG_ERR_NOSHSTRSEC "%s: no header string table section (shstrtab). \
header names are not available\n"
@ MSG_ERR_SHSTRNULL "%s: zero size section header string table \
(shstrtab). header names are not available\n"
@ MSG_ERR_FAILURE "%s: %s failed: %s\n"
@ MSG_ERR_BADSHDRALIGN "%s: bad section header array alignment\n"
@ MSG_ERR_BADPHDRALIGN "%s: bad program header array alignment\n"
@ MSG_ERR_BADSHNAME "%s: section[%d]: invalid sh_name: %lld\n"
@ MSG_ERR_BADSHLINK "%s: %s: invalid sh_link: %d\n"
@ MSG_ERR_BADSHINFO "%s: %s: invalid sh_info: %d\n"
@ MSG_ERR_BADSHTYPE "%s: %s: invalid sh_type: %d\n"
@ MSG_ERR_BADALIGN "%s: %s: bad sh_offset alignment\n"
@ MSG_ERR_BADSYM2 "%s: %s: index[%d]: bad symbol entry: %s: must be \
SHN_COMMON or defined in SHT_NOBITS section\n"
@ MSG_ERR_BADSYM3 "%s: %s: index[%d]: bad symbol entry: %s: must be \
defined in a SHF_TLS section\n"
@ MSG_ERR_BADSYM4 "%s: %s: index[%d]: bad symbol entry: %s: must be \
defined in a non-SHF_TLS section\n"
@ MSG_ERR_BADSYM5 "%s: %s: index[%d]: bad symbol entry: %s: \
invalid shndx: %d\n"
@ MSG_ERR_BADSYM6 "%s: %s: index[%d]: bad symbol entry: %s: section[%d] \
size: %#llx: symbol (address %#llx, size %#llx) \
lies outside of containing section\n"
@ MSG_ERR_BADSYM7 "%s: %s: index[%d]: suspicious global symbol entry: \
%s: lies within local symbol range (index < %lld)\n"
@ MSG_ERR_BADSYM8 "%s: %s: index[%d]: suspicious local symbol entry: \
%s: lies within global symbol range (index >= %lld)\n"
@ MSG_ERR_RELBADSYMNDX "%s: bad symbol reference %d: from relocation \
entry: %d\n"
@ MSG_ERR_HSBADSYMNDX "%s: bad symbol reference %d: from hash entry: %d\n"
@ MSG_ERR_BADSYMXINDEX1 "%s: %s: index[%d]: invalid SHN_XINDEX reference: \
SHT_SYMTAB_SHNDX section truncated: no entry for this \
symbol\n"
@ MSG_ERR_BADSYMXINDEX2 "%s: %s: index[%d]: invalid SHN_XINDEX reference: \
bad SHT_SYMTAB_SHNDX entry: invalid shndx: 0x%x\n"
@ MSG_ERR_BADSYMXINDEX3 "%s: %s: index[%d]: invalid SHN_XINDEX reference: \
SHT_SYMTAB_SHNDX section not found\n"
@ MSG_ERR_BADSTOFF "%s: %s: index[%d]: bad %s offset: 0x%x: max 0x%x\n"
@ MSG_ERR_BADSZ "%s: %s: zero size or zero entry size information\n"
@ MSG_ERR_BADMINFO "%s: %s: invalid m_info: 0x%llx\n"
@ MSG_ERR_BADHASH "%s: %s: bad hash entry: symbol %s: exists in bucket \
%d, should be bucket %ld\n"
@ MSG_ERR_NODYNSYM "%s: %s: associated SHT_DYNSYM section not found\n"
@ MSG_ERR_BADNDXSEC "%s: %s: unexpected section type associated with \
index section: %s\n"
@ MSG_ERR_BADSYMNDX "%s: %s: bad symbol index: %d\n"
@ MSG_ERR_BADVER "%s: %s: index[%d]: version %d is out of range: \
version definitions available: 0-%d\n"
@ MSG_ERR_NOTSTRTAB "%s: section[%d] is not a string table as expected \
by section[%d]\n";
@ MSG_ERR_BADCHAINIDX "%s: %s: invalid chain index %d for bucket %d (max %d)\n"
@ MSG_ERR_LDYNNOTADJ "%s: bad dynamic symbol table layout: %s and %s \
sections are not adjacent\n"
@ MSG_ERR_SECMEMOVER "%s: memory overlap between section[%d]: %s: %llx:%llx \
and section[%d]: %s: %llx:%llx\n"
@ MSG_ERR_SHDRMEMOVER "%s: memory overlap between section header table: \
%llx:%llx and section[%d]: %s: %llx:%llx\n"
@ MSG_ERR_MULTDYN "%s: %d dynamic sections seen (1 expected)\n"
@ MSG_ERR_DYNNOBCKSEC "%s: object lacks %s section required by %s dynamic \
entry\n"
@ MSG_ERR_DYNBADADDR "%s: %s (%#llx) does not match \
shdr[%d: %s].sh_addr (%#llx)\n"
@ MSG_ERR_DYNBADSIZE "%s: %s (%#llx) does not match \
shdr[%d: %s].sh_size (%#llx)\n"
@ MSG_ERR_DYNBADENTSIZE "%s: %s (%#llx) does not match \
shdr[%d: %s].sh_entsize (%#llx)\n"
@ MSG_ERR_DYNSYMVAL "%s: %s: symbol value does not match \
%s entry: %s: value: %#llx\n"
@ MSG_ERR_MALSTR "%s: %s: malformed string table, initial or final \
byte\n"
@ MSG_ERR_MULTEHFRMHDR "%s: [%d: %s] multiple .eh_frame_hdr sections seen \
(1 expected)\n"
@ MSG_ERR_BADEHFRMPTR "%s: section[%d: %s] FramePtr (%#llx) does not match \
shdr[%d: %s].sh_addr (%#llx)\n"
@ MSG_ERR_BADSORT "%s: %s: index[%d]: invalid sort order\n"
@ MSG_ERR_BADSIDYNNDX "%s: [%d: %s][%d]: dynamic section index out of \
range (0 - %d): %d\n";
@ MSG_ERR_BADSIDYNTAG "%s: [%d: %s][%d]: dynamic element \
[%d: %s][%d] should have type %s: %s\n";
@ MSG_ERR_BADCIEFDELEN "%s: %s: invalid CIE/FDE length: %#llx at %#llx\n"
@ MSG_WARN_INVINTERP1 "%s: PT_INTERP header has no associated section\n"
@ MSG_WARN_INVCAP1 "%s: PT_SUNWCAP header has no associated section\n"
@ MSG_WARN_INVCAP2 "%s: capabilities section[%d]: %s: requires PT_CAP \
program header\n"
@ MSG_WARN_INVCAP3 "%s: capabilities section[%d]: %s: requires string \
table: invalid sh_info: %d\n";
@ MSG_WARN_INADDR32SF1 "%s: capabilities section %s: software capability \
ADDR32: is ineffective within a 32-bit object\n"
@ MSG_WARN_MULTEHFRM "%s: section[%d: %s]: %s object has multiple \
.eh_frame sections\n"
@ MSG_INFO_LINUXOSABI "%s: %s object has Linux .note.ABI-tag section. \
Assuming %s\n"
@ MSG_ERR_DWOVRFLW "%s: %s: encoded DWARF data exceeds section size\n"
@ MSG_ERR_DWBADENC "%s: %s: bad DWARF encoding: %#x\n"
@ MSG_ERR_DWNOCIE "%s: %s: no CIE prior to FDE\n"
# exception_range_entry table entries.
# TRANSLATION_NOTE - the following entries provide for a series of one or more
# standard 32-bit and 64-bit .exception_ranges table entries that align with
# the initial title.
@ MSG_EXR_TITLE_32 " index offset ret_addr \
length handler type_blk"
@ MSG_EXR_ENTRY_32 "%10.10s 0x%8.8llx 0x%8.8llx 0x%8.8llx 0x%8.8llx \
0x%8.8llx"
@ MSG_EXR_TITLE_64 " index offset ret_addr \
length handler type_blk"
@ MSG_EXR_ENTRY_64 "%10.10s 0x%16.16llx 0x%16.16llx 0x%16.16llx \
0x%16.16llx 0x%16.16llx"
# Elf Output Messages
@ MSG_ELF_SHDR "Section Header[%d]: sh_name: %s"
@ MSG_ELF_PHDR "Program Header[%d]:"
@ MSG_ELF_SCN_CAP "Capabilities Section: %s"
@ MSG_ELF_SCN_CAPCHAIN "Capabilities Chain Section: %s"
@ MSG_ELF_SCN_INTERP "Interpreter Section: %s"
@ MSG_ELF_SCN_VERDEF "Version Definition Section: %s"
@ MSG_ELF_SCN_VERNEED "Version Needed Section: %s"
@ MSG_ELF_SCN_SYMTAB "Symbol Table Section: %s"
@ MSG_ELF_SCN_RELOC "Relocation Section: %s"
@ MSG_ELF_SCN_UNWIND "Unwind Section: %s"
@ MSG_ELF_SCN_DYNAMIC "Dynamic Section: %s"
@ MSG_ELF_SCN_NOTE "Note Section: %s"
@ MSG_ELF_SCN_HASH "Hash Section: %s"
@ MSG_ELF_SCN_SYMINFO "Syminfo Section: %s"
@ MSG_ELF_SCN_GOT "Global Offset Table Section: %s"
@ MSG_ELF_SCN_GRP "Group Section: %s"
@ MSG_ELF_SCN_MOVE "Move Section: %s"
@ MSG_ELF_SCN_SYMSORT1 "Symbol Sort Section: %s (%s)"
@ MSG_ELF_SCN_SYMSORT2 "Symbol Sort Section: %s (%s / %s)"
@ MSG_OBJ_CAP_TITLE " Object Capabilities:"
@ MSG_SYM_CAP_TITLE " Symbol Capabilities:"
@ MSG_CAPINFO_ENTRIES " Symbols:"
@ MSG_CAPCHAIN_TITLE " Capabilities family: %s"
@ MSG_CAPCHAIN_ENTRY " chainndx symndx name"
@ MSG_ERR_INVCAP "%s: capabilities section: %s: contains symbol \
capabilities groups, but no capabilities information \
section is defined: invalid sh_link: %d\n"
@ MSG_ERR_INVCAPINFO1 "%s: capabilities information section: %s: no symbol \
table is defined: invalid sh_link: %d\n"
@ MSG_ERR_INVCAPINFO2 "%s: capabilities information section: %s: no \
capabilities chain is defined: invalid sh_info: %d\n"
@ MSG_ERR_INVCAPINFO3 "%s: capabilities information section: %s: index %d: \
bad capabilities chain index defined: %d\n"
@ MSG_ERR_CHBADSYMNDX "%s: bad symbol reference %d: from capability chain: \
%s entry: %d\n"
@ MSG_ELF_HASH_BKTS1 "%10.10s buckets contain %8d symbols"
@ MSG_ELF_HASH_BKTS2 "%10.10s buckets %8d symbols (globals)"
@ MSG_ELF_HASH_INFO " bucket symndx name"
@ MSG_HASH_OVERFLW "%s: warning: section %s: too many symbols to count, \
bucket=%d count=%d"
@ MSG_ELF_ERR_SHDR "\tunable to obtain section header: shstrtab[%lld]\n"
@ MSG_ELF_ERR_DATA "\tunable to obtain section data: shstrtab[%lld]\n"
@ MSG_ELF_ERR_SCN "\tunable to obtain section header: section[%d]\n"
@ MSG_ELF_ERR_SCNDATA "\tunable to obtain section data: section[%d]\n"
@ MSG_ARCHIVE_SYMTAB_32 "\nSymbol Table: (archive, 32-bit offsets)"
@ MSG_ARCHIVE_SYMTAB_64 "\nSymbol Table: (archive, 64-bit offsets)"
@ MSG_ARCHIVE_FIELDS_32 " index offset member name and symbol"
@ MSG_ARCHIVE_FIELDS_64 " index offset member name and symbol"
@ MSG_GOT_MULTIPLE "%s: multiple relocations against \
the same GOT entry ndx: %d addr: 0x%llx\n"
@ MSG_GOT_UNEXPECTED "%s: warning: section %s: section unexpected within \
relocatable object\n"
# Miscellaneous clutter
@ MSG_STR_NULL "(null)"
@ MSG_STR_DEPRECATED "(deprecated value)"
@ MSG_STR_UNKNOWN "<unknown>"
@ MSG_STR_SECTION "%s (section)"
@ MSG_STR_CHECKSUM "elf checksum: 0x%lx"
@ MSG_STR_VADDR "virtual address"
@ MSG_STR_OFFSET "offset"
@ MSG_STR_FILESIZE "file size"
@ MSG_STR_MEMSIZE "memory size"
@ MSG_STR_ALIGNMENT "alignment"
@ MSG_FMT_SCNNDX "section[%d]"
@ MSG_FMT_NOTEENTNDX " entry [%d]";
@ MSG_ERR_MALLOC "%s: malloc: %s\n"
@ MSG_ERR_OPEN "%s: open: %s\n"
@ MSG_ERR_READ "%s: read: %s\n"
@ MSG_ERR_WRITE "%s: write: %s\n"
@ MSG_ERR_BAD_T_SHT "%s: unrecognized section header type: %s\n"
@ MSG_ERR_BAD_T_PT "%s: unrecognized program header type: %s\n"
@ MSG_ERR_BAD_T_OSABI "%s: unrecognized operating system ABI: %s\n"
@ MSG_ERR_AMBIG_MATCH "%s: ambiguous use of -I, -N, or -T. Remove \
-p option or section selection option(s)\n"
# Program/section correspondence messages
@ MSG_SHDR_PHDR_MISMATCH "%s: Section[%d: %s]: %s does not \
match %s segment: %s=%x: Program \
Header[%d].%s=%x\n"
@ MSG_SHDR_NO_PHDR "%s: Section[%d: %s]: has no matching \
%s segment\n"
#
# SHT_MOVE messages
#
@ MSG_MOVE_TITLE " symndx offset size repeat stride \
value with respect to"
@ MSG_MOVE_ENTRY "%10.10s %#10llx %6d %6d %6d %#16llx %s"
#
# SHT_GROUP messages
#
@ MSG_GRP_TITLE " index flags / section signature symbol"
@ MSG_GRP_SIGNATURE " [0] %-24s %s"
@ MSG_GRP_INVALSCN "<invalid section>"
#
# SHT_NOTE messages
#
@ MSG_NOTE_BADDATASZ "%s: %s: note header exceeds section size. \
offset: 0x%x\n"
@ MSG_NOTE_BADNMSZ "%s: %s: note name value exceeds section size. \
offset: 0x%x namesize: 0x%x\n"
@ MSG_NOTE_BADDESZ "%s: %s: note data size exceeds section size. \
offset: 0x%x datasize: 0x%x\n"
@ MSG_NOTE_BADCOREARCH "%s: elfdump core file note support not available for \
architecture: %s\n"
@ MSG_NOTE_BADCOREDATA "%s: elfdump core file note data truncated or \
otherwise malformed\n"
@ MSG_NOTE_BADCORETYPE "%s: unknown note type %#x\n"
@ MSG_NOTE_BAD_SECFLAGS_VER "unknown prsecflags_t version: "
@ MSG_NOTE_BAD_UPANIC_VER "unknown prupanic_t version: "
@ _END_
# The following strings represent reserved words, files, pathnames and symbols.
# Reference to this strings is via the MSG_ORIG() macro, and thus no message
# translation is required.
@ MSG_STR_OSQBRKT "["
@ MSG_STR_CSQBRKT "]"
@ MSG_GRP_COMDAT " COMDAT "
@ MSG_GRP_ENTRY "%10.10s %s [%lld]\n"
@ MSG_GRP_UNKNOWN " 0x%x "
@ MSG_ELF_GOT ".got"
@ MSG_ELF_INIT ".init"
@ MSG_ELF_FINI ".fini"
@ MSG_ELF_INTERP ".interp"
@ MSG_ELF_GETEHDR "elf_getehdr"
@ MSG_ELF_GETPHDR "elf_getphdr"
@ MSG_ELF_GETSHDR "elf_getshdr"
@ MSG_ELF_GETSCN "elf_getscn"
@ MSG_ELF_GETDATA "elf_getdata"
@ MSG_ELF_GETARHDR "elf_getarhdr"
@ MSG_ELF_GETARSYM "elf_getarsym"
@ MSG_ELF_RAND "elf_rand"
@ MSG_ELF_BEGIN "elf_begin"
@ MSG_ELF_GETPHDRNUM "elf_getphdrnum"
@ MSG_ELF_GETSHDRNUM "elf_getshdrnum"
@ MSG_ELF_GETSHDRSTRNDX "elf_getshdrstrndx"
@ MSG_ELF_XLATETOM "elf_xlatetom"
@ MSG_ELF_ARSYM "ARSYM"
@ MSG_SYM_INIT "_init"
@ MSG_SYM_FINI "_fini"
@ MSG_SYM_GOT "_GLOBAL_OFFSET_TABLE_"
@ MSG_STR_OPTIONS "CcdeGgHhiI:klmN:nO:PprSsT:uvw:y"
@ MSG_STR_8SP " "
@ MSG_STR_EMPTY ""
@ MSG_STR_CORE "CORE"
@ MSG_STR_NOTEABITAG ".note.ABI-tag"
@ MSG_STR_GNU "GNU"
@ MSG_STR_LOC "loc"
@ MSG_STR_INITLOC "initloc"
@ MSG_FMT_INDENT " %s"
@ MSG_FMT_INDEX " [%lld]"
@ MSG_FMT_INDEX2 "[%d]"
@ MSG_FMT_ASRINDEX "[ asr%d ]"
@ MSG_FMT_INDEXRNG "[%d-%d]"
@ MSG_FMT_INTEGER " %d"
@ MSG_FMT_HASH_INFO "%10.10s %-10s %s"
@ MSG_FMT_CHAIN_INFO "%10.10s %-10s %s"
@ MSG_FMT_ARSYM1_32 "%10.10s 0x%8.8llx (%s):%s"
@ MSG_FMT_ARSYM2_32 "%10.10s 0x%8.8llx"
@ MSG_FMT_ARSYM1_64 "%10.10s 0x%16.16llx (%s):%s"
@ MSG_FMT_ARSYM2_64 "%10.10s 0x%16.16llx"
@ MSG_FMT_ARNAME "%s(%s)"
@ MSG_FMT_NLSTR "\n%s:"
@ MSG_FMT_NLSTRNL "\n%s:\n"
@ MSG_FMT_SECSYM "%.*s%s"
@ MSG_HEXDUMP_ROW "%*s%-*s%s"
@ MSG_SUNW_OST_SGS "SUNW_OST_SGS"
# Unwind info
@ MSG_SCN_FRM ".eh_frame"
@ MSG_SCN_FRMHDR ".eh_frame_hdr"
@ MSG_SCN_EXRANGE ".exception_ranges"
@ MSG_UNW_FRMHDR "Frame Header:"
@ MSG_UNW_FRMVERS " Version: %d"
@ MSG_UNW_FRPTRENC " FramePtrEnc: %-20s FramePtr: %#llx"
@ MSG_UNW_FDCNENC " FdeCntEnc: %-20s FdeCnt: %lld"
@ MSG_UNW_TABENC " TableEnc: %-20s"
@ MSG_UNW_BINSRTAB1 " Binary Search Table:"
@ MSG_UNW_BINSRTAB2_32 " InitialLoc FdeLoc"
@ MSG_UNW_BINSRTAB2_64 " InitialLoc FdeLoc"
@ MSG_UNW_BINSRTABENT_32 " 0x%08llx 0x%08llx"
@ MSG_UNW_BINSRTABENT_64 " 0x%016llx 0x%016llx"
@ MSG_UNW_ZEROTERM "ZERO terminator: [0x00000000]"
@ MSG_UNW_CIE "CIE: [%#llx]"
@ MSG_UNW_CIELNGTH " length: 0x%02x cieid: %d"
@ MSG_UNW_CIEVERS " version: %d augmentation: `%s'"
@ MSG_UNW_CIECALGN " codealign: %#llx dataalign: %lld \
retaddr: %d"
@ MSG_UNW_CIEAXVAL " Augmentation Data:"
@ MSG_UNW_CIEAXSIZ " size: %lld"
@ MSG_UNW_CIEAXPERS " personality:"
@ MSG_UNW_CIEAXPERSENC " encoding: 0x%02x %s"
@ MSG_UNW_CIEAXPERSRTN " routine: %#08llx"
@ MSG_UNW_CIEAXCENC " code pointer encoding: 0x%02x %s"
@ MSG_UNW_CIEAXLSDA " lsda encoding: 0x%02x %s"
@ MSG_UNW_CIEAXUNEC " Unexpected aug val: %c"
@ MSG_UNW_CIECFI " CallFrameInstructions:"
@ MSG_UNW_FDE " FDE: [%#llx]"
@ MSG_UNW_FDELNGTH " length: %#x cieptr: %#x"
@ MSG_UNW_FDEINITLOC " initloc: %#llx addrrange: %#llx endloc: %#llx"
@ MSG_UNW_FDEAXVAL " Augmentation Data:"
@ MSG_UNW_FDEAXSIZE " size: %#llx"
@ MSG_UNW_FDEAXLSDA " lsda: %#llx"
@ MSG_UNW_FDECFI " CallFrameInstructions:"
# Unwind section Call Frame Instructions. These all start with a leading
# "%*s%s", used to insert leading white space and the opcode name.
@ MSG_CFA_ADV_LOC "%*s%s: %s + %llu => %#llx"
@ MSG_CFA_CFAOFF "%*s%s: %s, cfa%+lld"
@ MSG_CFA_CFASET "%*s%s: cfa=%#llx"
@ MSG_CFA_LLD "%*s%s: %lld"
@ MSG_CFA_LLU "%*s%s: %llu"
@ MSG_CFA_REG "%*s%s: %s"
@ MSG_CFA_REG_OFFLLD "%*s%s: %s, offset=%lld"
@ MSG_CFA_REG_OFFLLU "%*s%s: %s, offset=%llu"
@ MSG_CFA_REG_REG "%*s%s: %s, %s"
@ MSG_CFA_SIMPLE "%*s%s"
@ MSG_CFA_SIMPLEREP "%*s%s [%d]"
@ MSG_CFA_EBLK "%*s%s: expr(%llu bytes)"
@ MSG_CFA_REG_EBLK "%*s%s: %s, expr(%llu bytes)"
# Architecture specific register name formats
@ MSG_REG_FMT_BASIC "r%d"
@ MSG_REG_FMT_NAME "r%d (%s)"
# Note messages
@ MSG_NOTE_TYPE " type: %#x"
@ MSG_NOTE_TYPE_STR " type: %s"
@ MSG_NOTE_NAMESZ " namesz: %#x"
@ MSG_NOTE_NAME " name:"
@ MSG_NOTE_DESCSZ " descsz: %#x"
@ MSG_NOTE_DESC " desc:"
@ MSG_CNOTE_DESC_ASRSET_T "desc: (asrset_t)"
@ MSG_CNOTE_DESC_AUXV_T "desc: (auxv_t)"
@ MSG_CNOTE_DESC_CORE_CONTENT_T "desc: (core_content_t)"
@ MSG_CNOTE_DESC_LWPSINFO_T "desc: (lwpsinfo_t)"
@ MSG_CNOTE_DESC_LWPSTATUS_T "desc: (lwpstatus_t)"
@ MSG_CNOTE_DESC_PRCRED_T "desc: (prcred_t)"
@ MSG_CNOTE_DESC_PRIV_IMPL_INFO_T "desc: (priv_impl_info_t)"
@ MSG_CNOTE_DESC_PRPRIV_T "desc: (prpriv_t)"
@ MSG_CNOTE_DESC_PRPSINFO_T "desc: (prpsinfo_t)"
@ MSG_CNOTE_DESC_PRSTATUS_T "desc: (prstatus_t)"
@ MSG_CNOTE_DESC_PSINFO_T "desc: (psinfo_t)"
@ MSG_CNOTE_DESC_PSTATUS_T "desc: (pstatus_t)"
@ MSG_CNOTE_DESC_STRUCT_UTSNAME "desc: (struct utsname)"
@ MSG_CNOTE_DESC_PRFDINFO_T "desc: (prfdinfo_core_t)"
@ MSG_CNOTE_DESC_PRSECFLAGS_T "desc: (prsecflags_t)"
@ MSG_CNOTE_DESC_PRLWPNAME_T "desc: (prlwpname_t)"
@ MSG_CNOTE_DESC_PRUPANIC_T "desc: (prupanic_t)"
@ MSG_CNOTE_DESC_PRCWD_T "desc: (prcwd_t)"
@ MSG_CNOTE_FMT_LINE "%*s%-*s%s"
@ MSG_CNOTE_FMT_LINE_2UP "%*s%-*s%-*s%-*s%s"
@ MSG_CNOTE_FMT_D "%d"
@ MSG_CNOTE_FMT_LLD "%lld"
@ MSG_CNOTE_FMT_U "%u"
@ MSG_CNOTE_FMT_LLU "%llu"
@ MSG_CNOTE_FMT_X "%#x"
@ MSG_CNOTE_FMT_LLX "%#llx"
@ MSG_CNOTE_FMT_Z2X "0x%2.2x"
@ MSG_CNOTE_FMT_Z4X "0x%4.4x"
@ MSG_CNOTE_FMT_Z8X "0x%8.8x"
@ MSG_CNOTE_FMT_Z16LLX "0x%16.16llx"
@ MSG_CNOTE_FMT_TITLE "%*s%s"
@ MSG_CNOTE_FMT_AUXVLINE "%*s%10.10s %-*s %s"
@ MSG_CNOTE_FMT_PRTPCT "%u.%u%%"
@ MSG_CNOTE_T_PRIV_FLAGS "priv_flags:"
@ MSG_CNOTE_T_PRIV_GLOBALINFOSIZE "priv_globalinfosize:"
@ MSG_CNOTE_T_PRIV_HEADERSIZE "priv_headersize:"
@ MSG_CNOTE_T_PRIV_INFOSIZE "priv_infosize:"
@ MSG_CNOTE_T_PRIV_MAX "priv_max:"
@ MSG_CNOTE_T_PRIV_NSETS "priv_nsets:"
@ MSG_CNOTE_T_PRIV_SETSIZE "priv_setsize:"
@ MSG_CNOTE_T_PR_ACTION "pr_action:"
@ MSG_CNOTE_T_PR_ADDR "pr_addr:"
@ MSG_CNOTE_T_PR_AGENTID "pr_agentid:"
@ MSG_CNOTE_T_PR_ALTSTACK "pr_altstack:"
@ MSG_CNOTE_T_PR_ARGC "pr_argc:"
@ MSG_CNOTE_T_PR_ARGV "pr_argv:"
@ MSG_CNOTE_T_PR_ASLWPID "pr_aslwpid:"
@ MSG_CNOTE_T_PR_BIND "pr_bind:"
@ MSG_CNOTE_T_PR_BINDPRO "pr_bindpro:"
@ MSG_CNOTE_T_PR_BINDPSET "pr_bindpset:"
@ MSG_CNOTE_T_PR_BRKBASE "pr_brkbase:"
@ MSG_CNOTE_T_PR_BRKSIZE "pr_brksize:"
@ MSG_CNOTE_T_PR_BYRSSIZE "pr_byrssize:"
@ MSG_CNOTE_T_PR_BYSIZE "pr_bysize:"
@ MSG_CNOTE_T_PR_CLNAME "pr_clname:"
@ MSG_CNOTE_T_PR_CONTRACT "pr_contract:"
@ MSG_CNOTE_T_PR_CPU "pr_cpu:"
@ MSG_CNOTE_T_PR_CSTIME "pr_cstime:"
@ MSG_CNOTE_T_PR_CTIME "pr_ctime:"
@ MSG_CNOTE_T_PR_CURSIG "pr_cursig:"
@ MSG_CNOTE_T_PR_CUTIME "pr_cutime:"
@ MSG_CNOTE_T_PR_DMODEL "pr_dmodel:"
@ MSG_CNOTE_T_PR_EGID "pr_egid:"
@ MSG_CNOTE_T_PR_ENVP "pr_envp:"
@ MSG_CNOTE_T_PR_ERRNO "pr_errno:"
@ MSG_CNOTE_T_PR_ERRPRIV "pr_errpriv:"
@ MSG_CNOTE_T_PR_EUID "pr_euid:"
@ MSG_CNOTE_T_PR_FLAG "pr_flag:"
@ MSG_CNOTE_T_PR_FLAGS "pr_flags:"
@ MSG_CNOTE_T_PR_FLTTRACE "pr_flttrace:"
@ MSG_CNOTE_T_PR_FNAME "pr_fname:"
@ MSG_CNOTE_T_PR_FPREG "pr_fpreg:"
@ MSG_CNOTE_T_PR_GID "pr_gid:"
@ MSG_CNOTE_T_PR_GROUPS "pr_groups:"
@ MSG_CNOTE_T_PR_INFO "pr_info:"
@ MSG_CNOTE_T_PR_INFOSIZE "pr_infosize:"
@ MSG_CNOTE_T_PR_INSTR "pr_instr:"
@ MSG_CNOTE_T_PR_LGRP "pr_lgrp:"
@ MSG_CNOTE_T_PR_LTTYDEV "pr_lttydev:"
@ MSG_CNOTE_T_PR_LWP "pr_lwp:"
@ MSG_CNOTE_T_PR_LWPHOLD "pr_lwphold:"
@ MSG_CNOTE_T_PR_LWPID "pr_lwpid:"
@ MSG_CNOTE_T_PR_LWPNAME "pr_lwpname:"
@ MSG_CNOTE_T_PR_LWPPEND "pr_lwppend:"
@ MSG_CNOTE_T_PR_NAME "pr_name:"
@ MSG_CNOTE_T_PR_NGROUPS "pr_ngroups:"
@ MSG_CNOTE_T_PR_NICE "pr_nice:"
@ MSG_CNOTE_T_PR_NLWP "pr_nlwp:"
@ MSG_CNOTE_T_PR_NSETS "pr_nsets:"
@ MSG_CNOTE_T_PR_NSYSARG "pr_nsysarg:"
@ MSG_CNOTE_T_PR_NZOMB "pr_nzomb:"
@ MSG_CNOTE_T_PR_OLDCONTEXT "pr_oldcontext:"
@ MSG_CNOTE_T_PR_OLDPRI "pr_oldpri:"
@ MSG_CNOTE_T_PR_ONPRO "pr_onpro:"
@ MSG_CNOTE_T_PR_OTTYDEV "pr_ottydev:"
@ MSG_CNOTE_T_PR_PCTCPU "pr_pctcpu:"
@ MSG_CNOTE_T_PR_PCTMEM "pr_pctmem:"
@ MSG_CNOTE_T_PR_PGID "pr_pgid:"
@ MSG_CNOTE_T_PR_PGRP "pr_pgrp:"
@ MSG_CNOTE_T_PR_PID "pr_pid:"
@ MSG_CNOTE_T_PR_POOLID "pr_poolid:"
@ MSG_CNOTE_T_PR_PPID "pr_ppid:"
@ MSG_CNOTE_T_PR_PRI "pr_pri:"
@ MSG_CNOTE_T_PR_PROCESSOR "pr_processor:"
@ MSG_CNOTE_T_PR_PROJID "pr_projid:"
@ MSG_CNOTE_T_PR_PSARGS "pr_psargs:"
@ MSG_CNOTE_T_PR_REG "pr_reg:"
@ MSG_CNOTE_T_PR_RGID "pr_rgid:"
@ MSG_CNOTE_T_PR_RSSIZE "pr_rssize:"
@ MSG_CNOTE_T_PR_RUID "pr_ruid:"
@ MSG_CNOTE_T_PR_RVAL1 "pr_rval1:"
@ MSG_CNOTE_T_PR_RVAL2 "pr_rval2:"
@ MSG_CNOTE_T_PR_SETS "pr_sets:"
@ MSG_CNOTE_T_PR_SETSIZE "pr_setsize:"
@ MSG_CNOTE_T_PR_SGID "pr_sgid:"
@ MSG_CNOTE_T_PR_SID "pr_sid:"
@ MSG_CNOTE_T_PR_SIGHOLD "pr_sighold:"
@ MSG_CNOTE_T_PR_SIGPEND "pr_sigpend:"
@ MSG_CNOTE_T_PR_SIGTRACE "pr_sigtrace:"
@ MSG_CNOTE_T_PR_SIZE "pr_size:"
@ MSG_CNOTE_T_PR_SNAME "pr_sname:"
@ MSG_CNOTE_T_PR_START "pr_start:"
@ MSG_CNOTE_T_PR_STATE "pr_state:"
@ MSG_CNOTE_T_PR_STIME "pr_stime:"
@ MSG_CNOTE_T_PR_STKBASE "pr_stkbase:"
@ MSG_CNOTE_T_PR_STKSIZE "pr_stksize:"
@ MSG_CNOTE_T_PR_STYPE "pr_stype:"
@ MSG_CNOTE_T_PR_SUID "pr_suid:"
@ MSG_CNOTE_T_PR_SYSARG "pr_sysarg:"
@ MSG_CNOTE_T_PR_SYSCALL "pr_syscall:"
@ MSG_CNOTE_T_PR_SYSENTRY "pr_sysentry:"
@ MSG_CNOTE_T_PR_SYSEXIT "pr_sysexit:"
@ MSG_CNOTE_T_PR_TASKID "pr_taskid:"
@ MSG_CNOTE_T_PR_TIME "pr_time:"
@ MSG_CNOTE_T_PR_TSTAMP "pr_tstamp:"
@ MSG_CNOTE_T_PR_TTYDEV "pr_ttydev:"
@ MSG_CNOTE_T_PR_UID "pr_uid:"
@ MSG_CNOTE_T_PR_USTACK "pr_ustack:"
@ MSG_CNOTE_T_PR_UTIME "pr_utime:"
@ MSG_CNOTE_T_PR_WCHAN "pr_wchan:"
@ MSG_CNOTE_T_PR_WHAT "pr_what:"
@ MSG_CNOTE_T_PR_WHO "pr_who:"
@ MSG_CNOTE_T_PR_WHY "pr_why:"
@ MSG_CNOTE_T_PR_WSTAT "pr_wstat:"
@ MSG_CNOTE_T_PR_ZOMB "pr_zomb:"
@ MSG_CNOTE_T_PR_ZONEID "pr_zoneid:"
@ MSG_CNOTE_T_PR_EFFECTIVE "pr_effective:"
@ MSG_CNOTE_T_PR_INHERIT "pr_inherit:"
@ MSG_CNOTE_T_PR_LOWER "pr_lower:"
@ MSG_CNOTE_T_PR_UPPER "pr_upper:"
@ MSG_CNOTE_T_PR_VERSION "pr_version:"
@ MSG_CNOTE_T_SA_FLAGS "sa_flags:"
@ MSG_CNOTE_T_SA_HANDLER "sa_handler:"
@ MSG_CNOTE_T_SA_MASK "sa_mask:"
@ MSG_CNOTE_T_SA_SIGACTION "sa_sigaction:"
@ MSG_CNOTE_T_SIVAL_INT "sival_int:"
@ MSG_CNOTE_T_SIVAL_PTR "sival_ptr:"
@ MSG_CNOTE_T_SI_ADDR "si_addr:"
@ MSG_CNOTE_T_SI_BAND "si_band:"
@ MSG_CNOTE_T_SI_CODE "si_code:"
@ MSG_CNOTE_T_SI_CTID "si_ctid:"
@ MSG_CNOTE_T_SI_ENTITY "si_entity"
@ MSG_CNOTE_T_SI_ERRNO "si_errno:"
@ MSG_CNOTE_T_SI_PID "si_pid:"
@ MSG_CNOTE_T_SI_SIGNO "si_signo:"
@ MSG_CNOTE_T_SI_STATUS "si_status:"
@ MSG_CNOTE_T_SI_UID "si_uid:"
@ MSG_CNOTE_T_SI_VALUE "si_value:"
@ MSG_CNOTE_T_SI_ZONEID "si_zoneid:"
@ MSG_CNOTE_T_SS_FLAGS "ss_flags:"
@ MSG_CNOTE_T_SS_SIZE "ss_size:"
@ MSG_CNOTE_T_SS_SP "ss_sp:"
@ MSG_CNOTE_T_TV_NSEC "tv_nsec:"
@ MSG_CNOTE_T_TV_SEC "tv_sec:"
@ MSG_CNOTE_T_UTS_MACHINE "machine:"
@ MSG_CNOTE_T_UTS_NODENAME "nodename:"
@ MSG_CNOTE_T_UTS_RELEASE "release:"
@ MSG_CNOTE_T_UTS_SYSNAME "sysname:"
@ MSG_CNOTE_T_UTS_VERSION "version:"
@ MSG_CNOTE_T_PR_FD "pr_fd:"
@ MSG_CNOTE_T_PR_MODE "pr_mode:"
@ MSG_CNOTE_T_PR_PATH "pr_path:"
@ MSG_CNOTE_T_PR_MAJOR "pr_major:"
@ MSG_CNOTE_T_PR_MINOR "pr_minor:"
@ MSG_CNOTE_T_PR_RMAJOR "pr_rmajor:"
@ MSG_CNOTE_T_PR_RMINOR "pr_rminor:"
@ MSG_CNOTE_T_PR_OFFSET "pr_offset:"
@ MSG_CNOTE_T_PR_INO "pr_ino:"
@ MSG_CNOTE_T_PR_FILEFLAGS "pr_fileflags:"
@ MSG_CNOTE_T_PR_FDFLAGS "pr_fdflags:"
@ MSG_CNOTE_T_PRU_VERSION "pru_version:"
@ MSG_CNOTE_T_PRU_FLAGS "pru_flags:"
@ MSG_CNOTE_T_PRU_DATA "pru_data:"
@ MSG_CNOTE_T_CWD_FSID "prcwd_fsid:"
@ MSG_CNOTE_T_CWD_FSNAME "prcwd_fsname:"
@ MSG_CNOTE_T_CWD_MNTPT "prcwd_mntpt:"
@ MSG_CNOTE_T_CWD_MNTSPEC "prcwd_mntspec:"
@ MSG_CNOTE_T_CWD_CWD "prcwd_cwd:"
# Names of fake sections generated from program header data
@ MSG_PHDRNAM_CAP ".SUNW_cap(phdr)"
@ MSG_PHDRNAM_CAPINFO ".SUNW_capinfo(phdr)"
@ MSG_PHDRNAM_CAPCHAIN ".SUNW_capchain(phdr)"
@ MSG_PHDRNAM_DYN ".dynamic(phdr)"
@ MSG_PHDRNAM_DYNSTR ".dynstr(phdr)"
@ MSG_PHDRNAM_DYNSYM ".dynsym(phdr)"
@ MSG_PHDRNAM_FINIARR ".fini_array(phdr)"
@ MSG_PHDRNAM_HASH ".hash(phdr)"
@ MSG_PHDRNAM_INITARR ".init_array(phdr)"
@ MSG_PHDRNAM_INTERP ".interp(phdr)"
@ MSG_PHDRNAM_LDYNSYM ".SUNW_ldynsym(phdr)"
@ MSG_PHDRNAM_MOVE ".move(phdr)"
@ MSG_PHDRNAM_NOTE ".note(phdr)"
@ MSG_PHDRNAM_PREINITARR ".preinit_array(phdr)"
@ MSG_PHDRNAM_REL ".rel(phdr)"
@ MSG_PHDRNAM_RELA ".rela(phdr)"
@ MSG_PHDRNAM_SYMINFO ".syminfo(phdr)"
@ MSG_PHDRNAM_SYMSORT ".SUNW_symsort(phdr)"
@ MSG_PHDRNAM_TLSSORT ".SUNW_tlssort(phdr)"
@ MSG_PHDRNAM_UNWIND ".eh_frame_hdr(phdr)"
@ MSG_PHDRNAM_VER ".SUNW_version(phdr)"
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Generate a cache of section header information for an ELF
* object from the information found in its program headers.
*
* Malicious code can remove or corrupt section headers. The
* resulting program will be difficult to analyze, but is still
* runnable. Hence, scribbling on the section headers or removing
* them is an effective form of obfuscation. On the other hand,
* program headers must be accurate or the program will not run.
* Section headers derived from them will necessarily lack information
* found in the originals (particularly for non-allocable sections),
* but will provide essential symbol information. The focus is on
* recovering information that elfdump knows how to display, and that
* might be interesting in a forensic situation.
*
* There are some things we don't attempt to create sections for:
*
* plt, got
* We have no way to determine the length of either of
* these sections from the information available via
* the program headers or dynamic section. The data in
* the PLT is of little use to elfdump. The data in the
* GOT might be somewhat more interesting, especially as
* it pertains to relocations. However, the sizing issue
* remains.
*
* text, data, bss
* Although we could create these, there is little value
* to doing so. elfdump cannot display the arbitrary
* data in these sections, so this would amount to a
* simple repetition of the information already displayed
* in the program headers, with no additional benefit.
*/
#include <sys/elf_amd64.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <strings.h>
#include <conv.h>
#include <msg.h>
#include <_elfdump.h>
/*
* Common information about the object that is needed by
* all the routines in this module.
*/
typedef struct {
const char *file;
int fd;
Ehdr *ehdr;
Phdr *phdr;
size_t phnum;
} FSTATE;
/*
* These values uniquely identify the sections that we know
* how to recover.
*
* Note: We write the sections to the cache array in this same order.
* It simplifies this code if the dynamic, dynstr, dynsym, and ldynsym
* sections occupy known slots in the cache array. Other sections reference
* them by index, and if they are at a known spot, there is no need
* for a fixup pass. Putting them in positions [1-4] solves this.
*
* The order they are in was chosen such that if any one of them exists,
* all of the ones before it must also exist. This means that if the
* desired section exists, it will end up in the desired index in the
* cache array.
*
* The order of the other sections is arbitrary. I've arranged them
* in roughly related groups.
*/
typedef enum {
SINFO_T_NULL = 0,
SINFO_T_DYN = 1,
SINFO_T_DYNSTR = 2,
SINFO_T_DYNSYM = 3,
SINFO_T_LDYNSYM = 4,
SINFO_T_HASH = 5,
SINFO_T_SYMINFO = 6,
SINFO_T_SYMSORT = 7,
SINFO_T_TLSSORT = 8,
SINFO_T_VERNEED = 9,
SINFO_T_VERDEF = 10,
SINFO_T_VERSYM = 11,
SINFO_T_INTERP = 12,
SINFO_T_CAP = 13,
SINFO_T_CAPINFO = 14,
SINFO_T_CAPCHAIN = 15,
SINFO_T_UNWIND = 16,
SINFO_T_MOVE = 17,
SINFO_T_REL = 18,
SINFO_T_RELA = 19,
SINFO_T_PREINITARR = 20,
SINFO_T_INITARR = 21,
SINFO_T_FINIARR = 22,
SINFO_T_NOTE = 23,
SINFO_T_NUM = 24 /* Count of items. Must come last */
} SINFO_TYPE;
/*
* Table of per-section constant data used to set up the section
* header cache and the various sub-parts it references. Indexed by
* SINFO_T value.
*
* note: The sh_flags value should be either SHF_ALLOC, or 0.
* get_data() sets SHF_WRITE if the program header containing the
* section is writable. The other flags require information that
* the program headers don't contain (i.e. SHF_STRINGS, etc) so
* we don't set them.
*/
typedef struct {
const char *name;
Word sh_type;
Word sh_flags;
Word sh_addralign;
Word sh_entsize;
Elf_Type libelf_type;
} SINFO_DATA;
/*
* Many of these sections use an alignment given by M_WORD_ALIGN, a
* value that varies depending on the object target machine. Since we
* don't know that value at compile time, we settle for a value of
* 4 for ELFCLASS32 objects, and 8 for ELFCLASS64. This matches the
* platforms we current support (sparc and x86), and is good enough for
* a fake section header in any event, as the resulting object is only
* analyzed, and is not executed.
*/
#ifdef _ELF64
#define FAKE_M_WORD_ALIGN 8
#else
#define FAKE_M_WORD_ALIGN 4
#endif
static SINFO_DATA sinfo_data[SINFO_T_NUM] = {
/* SINFO_T_NULL */
{ 0 },
/* SINFO_T_DYN */
{ MSG_ORIG(MSG_PHDRNAM_DYN), SHT_DYNAMIC, SHF_ALLOC,
FAKE_M_WORD_ALIGN, sizeof (Dyn), ELF_T_DYN },
/* SINFO_T_DYNSTR */
{ MSG_ORIG(MSG_PHDRNAM_DYNSTR), SHT_STRTAB, SHF_ALLOC,
1, 0, ELF_T_BYTE },
/* SINFO_T_DYNSYM */
{ MSG_ORIG(MSG_PHDRNAM_DYNSYM), SHT_DYNSYM, SHF_ALLOC,
FAKE_M_WORD_ALIGN, sizeof (Sym), ELF_T_SYM },
/* SINFO_T_LDYNSYM */
{ MSG_ORIG(MSG_PHDRNAM_LDYNSYM), SHT_SUNW_LDYNSYM, SHF_ALLOC,
FAKE_M_WORD_ALIGN, sizeof (Sym), ELF_T_SYM },
/* SINFO_T_HASH */
{ MSG_ORIG(MSG_PHDRNAM_HASH), SHT_HASH, SHF_ALLOC,
FAKE_M_WORD_ALIGN, sizeof (Word), ELF_T_WORD },
/* SINFO_T_SYMINFO */
{ MSG_ORIG(MSG_PHDRNAM_SYMINFO), SHT_SUNW_syminfo, SHF_ALLOC,
FAKE_M_WORD_ALIGN, sizeof (Syminfo), ELF_T_SYMINFO },
/* SINFO_T_SYMSORT */
{ MSG_ORIG(MSG_PHDRNAM_SYMSORT), SHT_SUNW_symsort, SHF_ALLOC,
FAKE_M_WORD_ALIGN, sizeof (Word), ELF_T_WORD },
/* SINFO_T_TLSSORT */
{ MSG_ORIG(MSG_PHDRNAM_TLSSORT), SHT_SUNW_tlssort, SHF_ALLOC,
FAKE_M_WORD_ALIGN, sizeof (Word), ELF_T_WORD },
/* SINFO_T_VERNEED */
{ MSG_ORIG(MSG_PHDRNAM_VER), SHT_SUNW_verneed, SHF_ALLOC,
FAKE_M_WORD_ALIGN, 1, ELF_T_VNEED },
/* SINFO_T_VERDEF */
{ MSG_ORIG(MSG_PHDRNAM_VER), SHT_SUNW_verdef, SHF_ALLOC,
FAKE_M_WORD_ALIGN, 1, ELF_T_VDEF },
/* SINFO_T_VERSYM */
{ MSG_ORIG(MSG_PHDRNAM_VER), SHT_SUNW_versym, SHF_ALLOC,
FAKE_M_WORD_ALIGN, sizeof (Versym), ELF_T_HALF },
/* SINFO_T_INTERP */
{ MSG_ORIG(MSG_PHDRNAM_INTERP), SHT_PROGBITS, SHF_ALLOC,
1, 0, ELF_T_BYTE },
/* SINFO_T_CAP */
{ MSG_ORIG(MSG_PHDRNAM_CAP), SHT_SUNW_cap, SHF_ALLOC,
sizeof (Addr), sizeof (Cap), ELF_T_CAP },
/* SINFO_T_CAPINFO */
{ MSG_ORIG(MSG_PHDRNAM_CAPINFO), SHT_SUNW_capinfo, SHF_ALLOC,
FAKE_M_WORD_ALIGN, sizeof (Capinfo), ELF_T_WORD },
/* SINFO_T_CAPCHAIN */
{ MSG_ORIG(MSG_PHDRNAM_CAPCHAIN), SHT_SUNW_capchain, SHF_ALLOC,
FAKE_M_WORD_ALIGN, sizeof (Capchain), ELF_T_WORD },
/* SINFO_T_UNWIND */
{ MSG_ORIG(MSG_PHDRNAM_UNWIND), SHT_AMD64_UNWIND, SHF_ALLOC,
sizeof (Addr), 0, ELF_T_BYTE },
/* SINFO_T_MOVE */
{ MSG_ORIG(MSG_PHDRNAM_MOVE), SHT_SUNW_move, SHF_ALLOC,
sizeof (Lword), sizeof (Move), ELF_T_MOVE },
/* SINFO_T_REL */
{ MSG_ORIG(MSG_PHDRNAM_REL), SHT_REL, SHF_ALLOC,
FAKE_M_WORD_ALIGN, sizeof (Rel), ELF_T_REL },
/* SINFO_T_RELA */
{ MSG_ORIG(MSG_PHDRNAM_RELA), SHT_RELA, SHF_ALLOC,
FAKE_M_WORD_ALIGN, sizeof (Rela), ELF_T_RELA },
/* SINFO_T_PREINITARR */
{ MSG_ORIG(MSG_PHDRNAM_PREINITARR), SHT_PREINIT_ARRAY, SHF_ALLOC,
sizeof (Addr), sizeof (Addr), ELF_T_ADDR },
/* SINFO_T_INITARR */
{ MSG_ORIG(MSG_PHDRNAM_INITARR), SHT_INIT_ARRAY, SHF_ALLOC,
sizeof (Addr), sizeof (Addr), ELF_T_ADDR },
/* SINFO_T_FINIARR */
{ MSG_ORIG(MSG_PHDRNAM_FINIARR), SHT_FINI_ARRAY, SHF_ALLOC,
sizeof (Addr), sizeof (Addr), ELF_T_ADDR },
/* SINFO_T_NOTE */
{ MSG_ORIG(MSG_PHDRNAM_NOTE), SHT_NOTE, 0,
FAKE_M_WORD_ALIGN, 1, ELF_T_NOTE }
};
/*
* As we read program headers and dynamic elements, we build up
* the data for our fake section headers in variables of the
* SINFO type. SINFO is used to track the sections that can only
* appear a fixed number of times (usually once).
*
* SINFO_LISTELT is used for sections that can occur an arbitrary
* number of times. They are kept in a doubly linked circular
* buffer.
*/
typedef struct {
SINFO_TYPE type; /* Our type code for the section */
Addr vaddr; /* Virtual memory address */
Off offset; /* File offset of data. Ignored unless */
/* vaddr is 0. Used by program headers */
size_t size; /* # bytes in section */
size_t vercnt; /* Used by verdef and verneed to hold count */
Shdr *shdr; /* Constructed shdr */
Elf_Data *data; /* Constructed data descriptor */
} SINFO;
typedef struct _sinfo_listelt {
struct _sinfo_listelt *next;
struct _sinfo_listelt *prev;
SINFO sinfo;
} SINFO_LISTELT;
/*
* Free dynamic memory used by SINFO structures.
*
* entry:
* sinfo - Address of first SINFO structure to free
* n - # of structures to clear
*
* exit:
* For each SINFO struct, the section header, data descriptor,
* and data buffer are freed if non-NULL. The relevant
* fields are set to NULL, and the type is set to SINFO_T_NULL.
*/
static void
sinfo_free(SINFO *sinfo, size_t n)
{
for (; n-- > 0; sinfo++) {
if (sinfo->data != NULL) {
if (sinfo->data->d_buf != NULL)
free(sinfo->data->d_buf);
free(sinfo->data);
sinfo->data = NULL;
}
if (sinfo->shdr) {
free(sinfo->shdr);
sinfo->shdr = NULL;
}
sinfo->type = SINFO_T_NULL;
}
}
/*
* Allocate a new SINFO_LISTELT and put it at the end of the
* doubly linked list anchored by the given list root node.
*
* On success, a new node has been put at the end of the circular
* doubly linked list, and a pointer to the SINFO sub-structure is
* returned. On failure, an error is printed, and NULL is returned.
*/
static SINFO *
sinfo_list_alloc(FSTATE *fstate, SINFO_LISTELT *root)
{
SINFO_LISTELT *elt;
if ((elt = malloc(sizeof (*elt))) == NULL) {
int err = errno;
(void) fprintf(stderr, MSG_INTL(MSG_ERR_MALLOC),
fstate->file, strerror(err));
return (0);
}
elt->next = root;
elt->prev = root->prev;
root->prev = elt;
elt->prev->next = elt;
bzero(&elt->sinfo, sizeof (elt->sinfo));
return (&elt->sinfo);
}
/*
* Release the memory used by the given list, restoring it to
* an empty list.
*/
static void
sinfo_list_free_all(SINFO_LISTELT *root)
{
SINFO_LISTELT *elt;
for (elt = root->next; elt != root; elt = elt->next)
sinfo_free(&elt->sinfo, 1);
root->next = root->prev = root;
}
/*
* Given a virtual address and desired size of the data to be found
* at that address, look through the program headers for the PT_LOAD
* segment that contains it and return the offset within the ELF file
* at which it resides.
*
* entry:
* fstate - Object state
* addr - virtual address to be translated
* size - Size of the data to be found at that address, in bytes
* zero_bytes - NULL, or address to receive the number of data
* bytes at the end of the data that are not contained
* in the file, and which must be zero filled by the caller.
* If zero_bytes is NULL, the file must contain all of the
* desired data. If zero_bytes is not NULL, then the program
* header must reserve the space for all of the data (p_memsz)
* but it is acceptable for only part of the data to be in
* the file (p_filesz). *zero_bytes is set to the difference
* in size, and is the number of bytes the caller must
* set to 0 rather than reading from the file.
* phdr_ret - NULL, or address of variable to receive pointer
* to program header that contains offset.
* exit:
* On success: If zero_bytes is non-NULL, it is updated. If phdr_ret
* is non-NULL, it is updated. The file offset is returned.
*
* On failure, 0 is returned. Since any ELF file we can understand
* must start with an ELF magic number, 0 cannot be a valid file
* offset for a virtual address, and is therefore unambiguous as
* a failure indication.
*/
static Off
map_addr_to_offset(FSTATE *fstate, Addr addr, size_t size, size_t *zero_bytes,
Phdr **phdr_ret)
{
Off offset;
Addr end_addr = addr + size;
size_t avail_file;
Phdr *phdr = fstate->phdr;
size_t phnum = fstate->phnum;
for (; phnum--; phdr++) {
if (phdr->p_type != PT_LOAD)
continue;
if ((addr >= phdr->p_vaddr) &&
(end_addr <= (phdr->p_vaddr + phdr->p_memsz))) {
/*
* Subtract segment virtual address, leaving the
* offset relative to the segment (not the file).
*/
offset = addr - phdr->p_vaddr;
avail_file = phdr->p_filesz - offset;
/*
* The addr/size are in bounds for this segment.
* Is there enough data in the file to satisfy
* the request? If zero_bytes is NULL, it must
* all be in the file. Otherwise it can be
* zero filled.
*/
if (zero_bytes == NULL) {
if (size > avail_file)
continue;
} else {
*zero_bytes = (size > avail_file) ?
(size - avail_file) : 0;
}
if (phdr_ret != NULL)
*phdr_ret = phdr;
/* Add segment file offset, giving overall offset */
return (phdr->p_offset + offset);
}
}
/* If we get here, the mapping failed */
return (0);
}
/*
* This routine is the same thing as map_addr_to_offset(), except that
* it goes the other way, mapping from offset to virtual address.
*
* The comments for map_addr_to_offset() are applicable if you
* reverse offset and address.
*/
static Addr
map_offset_to_addr(FSTATE *fstate, Off offset, size_t size, size_t *zero_bytes,
Phdr **phdr_ret)
{
Off end_offset = offset + size;
size_t avail_file;
Phdr *phdr = fstate->phdr;
size_t phnum = fstate->phnum;
for (; phnum--; phdr++) {
if (phdr->p_type != PT_LOAD)
continue;
if ((offset >= phdr->p_offset) &&
(end_offset <= (phdr->p_offset + phdr->p_memsz))) {
/*
* Subtract segment offset, leaving the
* offset relative to the segment (not the file).
*/
offset -= phdr->p_offset;
avail_file = phdr->p_filesz - offset;
/*
* The offset/size are in bounds for this segment.
* Is there enough data in the file to satisfy
* the request? If zero_bytes is NULL, it must
* all be in the file. Otherwise it can be
* zero filled.
*/
if (zero_bytes == NULL) {
if (size > avail_file)
continue;
} else {
*zero_bytes = (size > avail_file) ?
(size - avail_file) : 0;
}
if (phdr_ret != NULL)
*phdr_ret = phdr;
/* Add segment virtual address, giving overall addr */
return (phdr->p_vaddr + offset);
}
}
/* If we get here, the mapping failed */
return (0);
}
/*
* Use elf_xlatetom() to convert the bytes in buf from their
* in-file representation to their in-memory representation.
*
* Returns True(1) for success. On failure, an error message is printed
* and False(0) is returned.
*/
static int
xlate_data(FSTATE *fstate, void *buf, size_t nbyte, Elf_Type xlate_type)
{
Elf_Data data;
data.d_type = xlate_type;
data.d_size = nbyte;
data.d_off = 0;
data.d_align = 0;
data.d_version = fstate->ehdr->e_version;
data.d_buf = buf;
if (elf_xlatetom(&data, &data,
fstate->ehdr->e_ident[EI_DATA]) == NULL) {
failure(fstate->file, MSG_ORIG(MSG_ELF_XLATETOM));
return (0);
}
return (1);
}
/*
* Read nbytes of data into buf, starting at the specified offset
* within the ELF file.
*
* entry:
* fstate - Object state
* offset - Offset within the file at which desired data resides.
* buf - Buffer to receive the data
* nbyte - # of bytes to read into buf
* xlate_type - An ELF xlate type, specifying the type of data
* being input. If xlate_type is ELF_T_BYTE, xlate is not
* done. Otherwise, xlate_data() is called to convert the
* data into its in-memory representation.
* exit:
* On success, the data has been written into buf, xlate_data()
* called on it if required, and True(1) is returned. Otherwise
* False(0) is returned.
*
* note:
* This routine does not move the file pointer.
*/
static int
read_data(FSTATE *fstate, Off offset, void *buf, size_t nbyte,
Elf_Type xlate_type)
{
if (pread(fstate->fd, buf, nbyte, offset) != nbyte) {
int err = errno;
(void) fprintf(stderr, MSG_INTL(MSG_ERR_READ),
fstate->file, strerror(err));
return (0);
}
if (xlate_type != ELF_T_BYTE)
return (xlate_data(fstate, buf, nbyte, xlate_type));
return (1);
}
/*
* Read the hash nbucket/nchain values from the start of the hash
* table found at the given virtual address in the mapped ELF object.
*
* On success, *nbucket, and *nchain have been filled in with their
* values, *total contains the number of elements in the hash table,
* and this routine returns True (1).
*
* On failure, False (0) is returned.
*/
static int
hash_size(FSTATE *fstate, SINFO *hash_sinfo,
Word *nbucket, Word *nchain, size_t *total)
{
Off offset;
Word buf[2];
offset = map_addr_to_offset(fstate, hash_sinfo->vaddr,
sizeof (buf), NULL, NULL);
if (offset == 0)
return (0);
if (read_data(fstate, offset, buf, sizeof (buf), ELF_T_WORD) == 0)
return (0);
*nbucket = buf[0];
*nchain = buf[1];
*total = 2 + *nbucket + *nchain;
return (1);
}
/*
* Read a Verdef structure at the specified file offset and return
* its vd_cnt, vd_aux, and vd_next fields.
*/
static int
read_verdef(FSTATE *fstate, Off offset, Half *cnt, Word *aux, Word *next)
{
Verdef verdef;
if (read_data(fstate, offset, &verdef, sizeof (verdef),
ELF_T_BYTE) == 0)
return (0);
/* xlate vd_cnt */
if (xlate_data(fstate, &verdef.vd_cnt, sizeof (verdef.vd_cnt),
ELF_T_HALF) == 0)
return (0);
/*
* xlate vd_aux and vd_next. These items are adjacent and are
* both Words, so they can be handled in a single operation.
*/
if (xlate_data(fstate, &verdef.vd_aux,
2 * sizeof (Word), ELF_T_WORD) == 0)
return (0);
*cnt = verdef.vd_cnt;
*aux = verdef.vd_aux;
*next = verdef.vd_next;
return (1);
}
/*
* Read a Verdaux structure at the specified file offset and return
* its vda_next field.
*/
static int
read_verdaux(FSTATE *fstate, Off offset, Word *next)
{
Verdaux verdaux;
if (read_data(fstate, offset, &verdaux, sizeof (verdaux),
ELF_T_BYTE) == 0)
return (0);
/* xlate vda_next */
if (xlate_data(fstate, &verdaux.vda_next, sizeof (verdaux.vda_next),
ELF_T_WORD) == 0)
return (0);
*next = verdaux.vda_next;
return (1);
}
/*
* Read a Verneed structure at the specified file offset and return
* its vn_cnt, vn_aux, and vn_next fields.
*/
static int
read_verneed(FSTATE *fstate, Off offset, Half *cnt, Word *aux, Word *next)
{
Verneed verneed;
if (read_data(fstate, offset, &verneed, sizeof (verneed),
ELF_T_BYTE) == 0)
return (0);
/* xlate vn_cnt */
if (xlate_data(fstate, &verneed.vn_cnt, sizeof (verneed.vn_cnt),
ELF_T_HALF) == 0)
return (0);
/*
* xlate vn_aux and vn_next. These items are adjacent and are
* both Words, so they can be handled in a single operation.
*/
if (xlate_data(fstate, &verneed.vn_aux,
2 * sizeof (Word), ELF_T_WORD) == 0)
return (0);
*cnt = verneed.vn_cnt;
*aux = verneed.vn_aux;
*next = verneed.vn_next;
return (1);
}
/*
* Read a Vernaux structure at the specified file offset and return
* its vna_next field.
*/
static int
read_vernaux(FSTATE *fstate, Off offset, Word *next)
{
Vernaux vernaux;
if (read_data(fstate, offset, &vernaux, sizeof (vernaux),
ELF_T_BYTE) == 0)
return (0);
/* xlate vna_next */
if (xlate_data(fstate, &vernaux.vna_next, sizeof (vernaux.vna_next),
ELF_T_WORD) == 0)
return (0);
*next = vernaux.vna_next;
return (1);
}
/*
* Compute the size of Verdef and Verneed sections. Both of these
* sections are made up of interleaved main nodes (Verdef and Verneed)
* and auxiliary blocks (Verdaux and Vernaux). These nodes refer to
* each other by relative offsets. The linker has a lot of flexibility
* in how it lays out these items, and we cannot assume a standard
* layout. To determine the size of the section, we must read each
* main node and compute the high water mark of the memory it and its
* auxiliary structs access.
*
* Although Verdef/Verdaux and Verneed/Vernaux are different types,
* their logical organization is the same. Each main block has
* a cnt field that tells how many auxiliary blocks it has, an
* aux field that gives the offset of the first auxiliary block, and
* an offset to the next main block. Each auxiliary block contains
* an offset to the next auxiliary block. By breaking the type specific
* code into separate sub-functions, we can process both Verdef and
* sections Verdaux from a single routine.
*
* entry:
* fstate - Object state
* sec - Section to be processed (SINFO_T_VERDEF or SINFO_T_VERNEED).
*
* exit:
* On success, sec->size is set to the section size in bytes, and
* True (1) is returned. On failure, False (0) is returned.
*/
static int
verdefneed_size(FSTATE *fstate, SINFO *sec)
{
int (* read_main)(FSTATE *, Off, Half *, Word *, Word *);
int (* read_aux)(FSTATE *, Off, Word *);
size_t size_main, size_aux;
Off offset, aux_offset;
Off highwater, extent;
size_t num_main = sec->vercnt;
Half v_cnt;
Word v_aux, v_next, va_next;
/*
* Set up the function pointers to the type-specific code
* for fetching data from the main and auxiliary blocks.
*/
if (sec->type == SINFO_T_VERDEF) {
read_main = read_verdef;
read_aux = read_verdaux;
size_main = sizeof (Verdef);
size_aux = sizeof (Verdaux);
} else { /* SINFO_T_VERNEED */
read_main = read_verneed;
read_aux = read_vernaux;
size_main = sizeof (Verneed);
size_aux = sizeof (Vernaux);
}
/*
* Map starting address to file offset. Save the starting offset
* in the SINFO size field. Once we have the high water offset, we
* can subtract this from it to get the size.
*
* Note: The size argument set here is a lower bound --- the
* size of the main blocks without any auxiliary ones. It's
* the best we can do until the size has been determined for real.
*/
offset = highwater = map_addr_to_offset(fstate, sec->vaddr,
size_main * num_main, NULL, NULL);
if (offset == 0)
return (0);
sec->size = offset;
for (; num_main-- > 0; offset += v_next) {
/* Does this move the high water mark up? */
extent = offset + size_main;
if (extent > highwater)
highwater = extent;
if ((*read_main)(fstate, offset, &v_cnt, &v_aux, &v_next) == 0)
return (0);
/*
* If there are auxiliary structures referenced,
* check their position to see if it pushes
* the high water mark.
*/
aux_offset = offset + v_aux;
for (; v_cnt-- > 0; aux_offset += va_next) {
extent = aux_offset + size_aux;
if (extent > highwater)
highwater = extent;
if ((*read_aux)(fstate, aux_offset, &va_next) == 0)
return (0);
}
}
sec->size = highwater - sec->size;
return (1);
}
/*
* Allocate and fill in a fake section header, data descriptor,
* and data buffer for the given section. Fill them in and read
* the associated data into the buffer.
*
* entry:
* fstate - Object state
* sec - Section information
*
* exit:
* On success, the actions described above are complete, and
* True (1) is returned.
*
* On failure, an error is reported, all resources used by sec
* are released, and sec->type is set to SINFO_T_NULL, effectively
* eliminating its contents from any further use. False (0) is
* returned.
*/
static int
get_data(FSTATE *fstate, SINFO *sec)
{
SINFO_DATA *tinfo;
size_t read_bytes, zero_bytes;
Phdr *phdr = NULL;
/*
* If this is a NULL section, or if we've already processed
* this item, then we are already done.
*/
if ((sec->type == SINFO_T_NULL) || (sec->shdr != NULL))
return (1);
if (((sec->shdr = malloc(sizeof (*sec->shdr))) == NULL) ||
((sec->data = malloc(sizeof (*sec->data))) == NULL)) {
int err = errno;
sinfo_free(sec, 1);
(void) fprintf(stderr, MSG_INTL(MSG_ERR_MALLOC),
fstate->file, strerror(err));
return (0);
}
tinfo = &sinfo_data[sec->type];
/*
* Fill in fake section header
*
* sh_name should be the offset of the name in the shstrtab
* section referenced by the ELF header. There is no
* value to elfdump in creating shstrtab, so we set
* sh_name to 0, knowing that elfdump doesn't look at it.
*/
sec->shdr->sh_name = 0;
sec->shdr->sh_type = tinfo->sh_type;
sec->shdr->sh_flags = tinfo->sh_flags;
if ((tinfo->sh_flags & SHF_ALLOC) == 0) {
/*
* Non-allocable section: Pass the addr (which is probably
* 0) and offset through without inspection.
*/
sec->shdr->sh_addr = sec->vaddr;
sec->shdr->sh_offset = sec->offset;
zero_bytes = 0;
} else if (sec->vaddr == 0) {
/*
* Allocable section with a 0 vaddr. Figure out the
* real address by mapping the offset to it using the
* program headers.
*/
sec->shdr->sh_addr = map_offset_to_addr(fstate, sec->offset,
sec->size, &zero_bytes, &phdr);
sec->shdr->sh_offset = sec->offset;
} else {
/*
* Allocable section with non-0 vaddr. Use the vaddr
* to derive the offset.
*/
sec->shdr->sh_addr = sec->vaddr;
sec->shdr->sh_offset = map_addr_to_offset(fstate,
sec->vaddr, sec->size, &zero_bytes, &phdr);
}
if (sec->shdr->sh_offset == 0) {
sinfo_free(sec, 1);
return (0);
}
/*
* If the program header has its write flags set, then set
* the section write flag.
*/
if (phdr && ((phdr->p_flags & PF_W) != 0))
sec->shdr->sh_flags |= SHF_WRITE;
sec->shdr->sh_size = sec->size;
sec->shdr->sh_link = 0;
sec->shdr->sh_info = 0;
sec->shdr->sh_addralign = tinfo->sh_addralign;
sec->shdr->sh_entsize = tinfo->sh_entsize;
/*
* Some sections define special meanings for sh_link and sh_info.
*/
switch (tinfo->sh_type) {
case SHT_DYNAMIC:
sec->shdr->sh_link = SINFO_T_DYNSTR;
break;
case SHT_DYNSYM:
sec->shdr->sh_link = SINFO_T_DYNSTR;
sec->shdr->sh_info = 1; /* First global symbol */
break;
case SHT_SUNW_LDYNSYM:
sec->shdr->sh_link = SINFO_T_DYNSTR;
/*
* ldynsym is all local symbols, so the index of the
* first global is equivalent to the number of symbols.
*/
sec->shdr->sh_info = sec->shdr->sh_size / sizeof (Sym);
break;
case SHT_HASH:
case SHT_SUNW_move:
case SHT_REL:
case SHT_RELA:
case SHT_SUNW_versym:
sec->shdr->sh_link = SINFO_T_DYNSYM;
break;
case SHT_SUNW_verdef:
case SHT_SUNW_verneed:
sec->shdr->sh_link = SINFO_T_DYNSTR;
sec->shdr->sh_info = sec->vercnt;
break;
case SHT_SUNW_syminfo:
sec->shdr->sh_link = SINFO_T_DYNSYM;
sec->shdr->sh_info = SINFO_T_DYN;
break;
case SHT_SUNW_symsort:
case SHT_SUNW_tlssort:
sec->shdr->sh_link = SINFO_T_LDYNSYM;
break;
}
/* Fill in fake Elf_Data descriptor */
sec->data->d_type = tinfo->libelf_type;
sec->data->d_size = sec->size;
sec->data->d_off = 0;
sec->data->d_align = tinfo->sh_addralign;
sec->data->d_version = fstate->ehdr->e_version;
if (sec->size == 0) {
sec->data->d_buf = NULL;
return (1);
}
if ((sec->data->d_buf = malloc(sec->size)) == NULL) {
int err = errno;
sinfo_free(sec, 1);
(void) fprintf(stderr, MSG_INTL(MSG_ERR_MALLOC),
fstate->file, strerror(err));
return (0);
}
read_bytes = sec->size - zero_bytes;
if ((read_bytes > 0) &&
(read_data(fstate, sec->shdr->sh_offset, sec->data->d_buf,
read_bytes, ELF_T_BYTE) == 0)) {
sinfo_free(sec, 1);
return (0);
}
if (zero_bytes > 0)
bzero(read_bytes + (char *)sec->data->d_buf, zero_bytes);
if ((tinfo->libelf_type != ELF_T_BYTE) &&
(elf_xlatetom(sec->data, sec->data,
fstate->ehdr->e_ident[EI_DATA]) == NULL)) {
sinfo_free(sec, 1);
failure(fstate->file, MSG_ORIG(MSG_ELF_XLATETOM));
return (0);
}
return (1);
}
/*
* Generate a section header cache made up of information derived
* from the program headers.
*
* entry:
* file - Name of object
* fd - Open file handle for object
* elf - ELF descriptor
* ehdr - Elf header
* cache, shnum - Addresses of variables to receive resulting
* cache and number of sections.
*
* exit:
* On success, *cache and *shnum are set, and True (1) is returned.
* On failure, False (0) is returned.
*
* note:
* The cache returned by this routine must be freed using
* fake_shdr_cache_free(), and not by a direct call to free().
* Otherwise, memory will leak.
*/
int
fake_shdr_cache(const char *file, int fd, Elf *elf, Ehdr *ehdr,
Cache **cache, size_t *shnum)
{
/*
* The C language guarantees that a structure of homogeneous
* items will receive exactly the same layout in a structure
* as a plain array of the same type. Hence, this structure, which
* gives us by-name or by-index access to the various section
* info descriptors we maintain.
*
* We use this for sections where
* - Only one instance is allowed
* - We need to be able to access them easily by
* name (for instance, when mining the .dynamic
* section for information to build them up.
*
* NOTE: These fields must be in the same order as the
* SINFO_T_ type codes that correspond to them. Otherwise,
* they will end up in the wrong order in the cache array,
* and the sh_link/sh_info fields may be wrong.
*/
struct {
/* Note: No entry is needed for SINFO_T_NULL */
SINFO dyn;
SINFO dynstr;
SINFO dynsym;
SINFO ldynsym;
SINFO hash;
SINFO syminfo;
SINFO symsort;
SINFO tlssort;
SINFO verneed;
SINFO verdef;
SINFO versym;
SINFO interp;
SINFO cap;
SINFO capinfo;
SINFO capchain;
SINFO unwind;
SINFO move;
SINFO rel;
SINFO rela;
SINFO preinitarr;
SINFO initarr;
SINFO finiarr;
} sec;
static const size_t sinfo_n = sizeof (sec) / sizeof (sec.dyn);
SINFO *secarr = (SINFO *) &sec;
/*
* Doubly linked circular list, used to track sections
* where multiple sections of a given type can exist.
* seclist is the root of the list. Its sinfo field is not
* used --- it serves to anchor the root of the list, allowing
* rapid access to the first and last element in the list.
*/
SINFO_LISTELT seclist;
FSTATE fstate;
size_t ndx;
size_t num_sinfo, num_list_sinfo;
SINFO *sinfo;
SINFO_LISTELT *sinfo_list;
Cache *_cache;
fstate.file = file;
fstate.fd = fd;
fstate.ehdr = ehdr;
if (elf_getphdrnum(elf, &fstate.phnum) == -1) {
failure(file, MSG_ORIG(MSG_ELF_GETPHDRNUM));
return (0);
}
if ((fstate.phdr = elf_getphdr(elf)) == NULL) {
failure(file, MSG_ORIG(MSG_ELF_GETPHDR));
return (0);
}
bzero(&sec, sizeof (sec)); /* Initialize "by-name" sec info */
seclist.next = seclist.prev = &seclist; /* Empty circular list */
/*
* Go through the program headers and look for information
* we can use to synthesize section headers. By far the most
* valuable thing is a dynamic section, the contents of
* which point at all sections used by ld.so.1.
*/
for (ndx = 0; ndx < fstate.phnum; ndx++) {
/*
* A program header with no file size does
* not have a backing section.
*/
if (fstate.phdr[ndx].p_filesz == 0)
continue;
switch (fstate.phdr[ndx].p_type) {
default:
/* Header we can't use. Move on to next one */
continue;
case PT_DYNAMIC:
sec.dyn.type = SINFO_T_DYN;
sinfo = &sec.dyn;
break;
case PT_INTERP:
sec.interp.type = SINFO_T_INTERP;
sinfo = &sec.interp;
break;
case PT_NOTE:
if ((sinfo = sinfo_list_alloc(&fstate, &seclist)) ==
NULL)
continue;
sinfo->type = SINFO_T_NOTE;
break;
case PT_SUNW_UNWIND:
case PT_SUNW_EH_FRAME:
sec.unwind.type = SINFO_T_UNWIND;
sinfo = &sec.unwind;
break;
case PT_SUNWCAP:
sec.cap.type = SINFO_T_CAP;
sinfo = &sec.cap;
break;
}
/*
* Capture the position/extent information for
* the header in the SINFO struct set up by the
* switch statement above.
*/
sinfo->vaddr = fstate.phdr[ndx].p_vaddr;
sinfo->offset = fstate.phdr[ndx].p_offset;
sinfo->size = fstate.phdr[ndx].p_filesz;
}
/*
* If we found a dynamic section, look through it and
* gather information about the sections it references.
*/
if (sec.dyn.type == SINFO_T_DYN)
(void) get_data(&fstate, &sec.dyn);
if ((sec.dyn.type == SINFO_T_DYN) && (sec.dyn.data->d_buf != NULL)) {
Dyn *dyn;
for (dyn = sec.dyn.data->d_buf; dyn->d_tag != DT_NULL; dyn++) {
switch (dyn->d_tag) {
case DT_HASH:
sec.hash.type = SINFO_T_HASH;
sec.hash.vaddr = dyn->d_un.d_ptr;
break;
case DT_STRTAB:
sec.dynstr.type = SINFO_T_DYNSTR;
sec.dynstr.vaddr = dyn->d_un.d_ptr;
break;
case DT_SYMTAB:
sec.dynsym.type = SINFO_T_DYNSYM;
sec.dynsym.vaddr = dyn->d_un.d_ptr;
break;
case DT_RELA:
sec.rela.type = SINFO_T_RELA;
sec.rela.vaddr = dyn->d_un.d_ptr;
break;
case DT_RELASZ:
sec.rela.size = dyn->d_un.d_val;
break;
case DT_STRSZ:
sec.dynstr.size = dyn->d_un.d_val;
break;
case DT_REL:
sec.rel.type = SINFO_T_REL;
sec.rel.vaddr = dyn->d_un.d_ptr;
break;
case DT_RELSZ:
sec.rel.size = dyn->d_un.d_val;
break;
case DT_INIT_ARRAY:
sec.initarr.type = SINFO_T_INITARR;
sec.initarr.vaddr = dyn->d_un.d_ptr;
break;
case DT_INIT_ARRAYSZ:
sec.initarr.size = dyn->d_un.d_val;
break;
case DT_FINI_ARRAY:
sec.finiarr.type = SINFO_T_FINIARR;
sec.finiarr.vaddr = dyn->d_un.d_ptr;
break;
case DT_FINI_ARRAYSZ:
sec.finiarr.size = dyn->d_un.d_val;
break;
case DT_PREINIT_ARRAY:
sec.preinitarr.type = SINFO_T_PREINITARR;
sec.preinitarr.vaddr = dyn->d_un.d_ptr;
break;
case DT_PREINIT_ARRAYSZ:
sec.preinitarr.size = dyn->d_un.d_val;
break;
case DT_SUNW_CAPINFO:
sec.capinfo.type = SINFO_T_CAPINFO;
sec.capinfo.vaddr = dyn->d_un.d_ptr;
break;
case DT_SUNW_CAPCHAIN:
sec.capchain.type = SINFO_T_CAPCHAIN;
sec.capchain.vaddr = dyn->d_un.d_ptr;
break;
case DT_SUNW_SYMTAB:
sec.ldynsym.type = SINFO_T_LDYNSYM;
sec.ldynsym.vaddr = dyn->d_un.d_ptr;
break;
case DT_SUNW_SYMSZ:
sec.ldynsym.size = dyn->d_un.d_val;
break;
case DT_SUNW_SYMSORT:
sec.symsort.type = SINFO_T_SYMSORT;
sec.symsort.vaddr = dyn->d_un.d_ptr;
break;
case DT_SUNW_SYMSORTSZ:
sec.symsort.size = dyn->d_un.d_val;
break;
case DT_SUNW_TLSSORT:
sec.tlssort.type = SINFO_T_TLSSORT;
sec.tlssort.vaddr = dyn->d_un.d_ptr;
break;
case DT_SUNW_TLSSORTSZ:
sec.tlssort.size = dyn->d_un.d_val;
break;
case DT_MOVETAB:
sec.move.type = SINFO_T_MOVE;
sec.move.vaddr = dyn->d_un.d_ptr;
break;
case DT_MOVESZ:
sec.move.size = dyn->d_un.d_val;
break;
case DT_SYMINFO:
sec.syminfo.type = SINFO_T_SYMINFO;
sec.syminfo.vaddr = dyn->d_un.d_ptr;
break;
case DT_SYMINSZ:
sec.syminfo.size = dyn->d_un.d_val;
break;
case DT_VERSYM:
sec.versym.type = SINFO_T_VERSYM;
sec.versym.vaddr = dyn->d_un.d_ptr;
break;
case DT_VERDEF:
sec.verdef.type = SINFO_T_VERDEF;
sec.verdef.vaddr = dyn->d_un.d_ptr;
break;
case DT_VERDEFNUM:
sec.verdef.vercnt = dyn->d_un.d_val;
sec.verdef.size = sizeof (Verdef) *
dyn->d_un.d_val;
break;
case DT_VERNEED:
sec.verneed.type = SINFO_T_VERNEED;
sec.verneed.vaddr = dyn->d_un.d_ptr;
break;
case DT_VERNEEDNUM:
sec.verneed.vercnt = dyn->d_un.d_val;
sec.verneed.size = sizeof (Verneed) *
dyn->d_un.d_val;
break;
}
}
}
/*
* Different sections depend on each other, and are meaningless
* without them. For instance, even if a .dynsym exists,
* no use can be made of it without a dynstr. These relationships
* fan out: Disqualifying the .dynsym will disqualify the hash
* section, and so forth.
*
* Disqualify sections that don't have the necessary prerequisites.
*/
/* Things that need the dynamic string table */
if (sec.dynstr.size == 0)
sec.dynstr.type = SINFO_T_NULL;
if (sec.dynstr.type != SINFO_T_DYNSTR) {
sinfo_free(&sec.dyn, 1); /* Data already fetched */
sec.dynsym.type = SINFO_T_NULL;
sec.dynsym.type = SINFO_T_NULL;
sec.verdef.type = SINFO_T_NULL;
sec.verneed.type = SINFO_T_NULL;
}
/*
* The length of the hash section is encoded in its first two
* elements (nbucket, and nchain). The length of the dynsym,
* ldynsym, and versym are not given in the dynamic section,
* but are known to be the same as nchain.
*
* If we don't have a hash table, or cannot read nbuckets and
* nchain, we have to invalidate all of these.
*/
if (sec.hash.type == SINFO_T_HASH) {
Word nbucket;
Word nchain;
size_t total;
if (hash_size(&fstate, &sec.hash,
&nbucket, &nchain, &total) == 0) {
sec.hash.type = SINFO_T_NULL;
} else {
/* Use these counts to set sizes for related sections */
sec.hash.size = total * sizeof (Word);
sec.dynsym.size = nchain * sizeof (Sym);
sec.versym.size = nchain * sizeof (Versym);
/*
* The ldynsym size received the DT_SUNW_SYMSZ
* value, which is the combined size of .dynsym
* and .ldynsym. Now that we have the dynsym size,
* use it to lower the ldynsym size to its real size.
*/
if (sec.ldynsym.size > sec.dynsym.size)
sec.ldynsym.size -= sec.dynsym.size;
}
}
/*
* If the hash table is not present, or if the call to
* hash_size() failed, then discard the sections that
* need it to determine their length.
*/
if (sec.hash.type != SINFO_T_HASH) {
sec.dynsym.type = SINFO_T_NULL;
sec.ldynsym.type = SINFO_T_NULL;
sec.versym.type = SINFO_T_NULL;
}
/*
* The runtime linker does not receive size information for
* Verdef and Verneed sections. We have to read their data
* in pieces and calculate it.
*/
if ((sec.verdef.type == SINFO_T_VERDEF) &&
(verdefneed_size(&fstate, &sec.verdef) == 0))
sec.verdef.type = SINFO_T_NULL;
if ((sec.verneed.type == SINFO_T_VERNEED) &&
(verdefneed_size(&fstate, &sec.verneed) == 0))
sec.verneed.type = SINFO_T_NULL;
/* Discard any section with a zero length */
ndx = sinfo_n;
for (sinfo = secarr; ndx-- > 0; sinfo++)
if ((sinfo->type != SINFO_T_NULL) && (sinfo->size == 0))
sinfo->type = SINFO_T_NULL;
/* Things that need the dynamic symbol table */
if (sec.dynsym.type != SINFO_T_DYNSYM) {
sec.ldynsym.type = SINFO_T_NULL;
sec.hash.type = SINFO_T_NULL;
sec.syminfo.type = SINFO_T_NULL;
sec.versym.type = SINFO_T_NULL;
sec.move.type = SINFO_T_NULL;
sec.rel.type = SINFO_T_NULL;
sec.rela.type = SINFO_T_NULL;
}
/* Things that need the dynamic local symbol table */
if (sec.ldynsym.type != SINFO_T_DYNSYM) {
sec.symsort.type = SINFO_T_NULL;
sec.tlssort.type = SINFO_T_NULL;
}
/*
* Look through the results and fetch the data for any sections
* we have found. At the same time, count the number.
*/
num_sinfo = num_list_sinfo = 0;
ndx = sinfo_n;
for (sinfo = secarr; ndx-- > 0; sinfo++) {
if ((sinfo->type != SINFO_T_NULL) && (sinfo->data == NULL))
(void) get_data(&fstate, sinfo);
if (sinfo->data != NULL)
num_sinfo++;
}
for (sinfo_list = seclist.next; sinfo_list != &seclist;
sinfo_list = sinfo_list->next) {
sinfo = &sinfo_list->sinfo;
if ((sinfo->type != SINFO_T_NULL) && (sinfo->data == NULL))
(void) get_data(&fstate, sinfo);
if (sinfo->data != NULL)
num_list_sinfo++;
}
/*
* Allocate the cache array and fill it in. The cache array
* ends up taking all the dynamic memory we've allocated
* to build up sec and seclist, so on success, we have nothing
* left to clean up. If we can't allocate the cache array
* though, we have to free up everything else.
*/
*shnum = num_sinfo + num_list_sinfo + 1; /* Extra for 1st NULL sec. */
if ((*cache = _cache = malloc((*shnum) * sizeof (Cache))) == NULL) {
int err = errno;
(void) fprintf(stderr, MSG_INTL(MSG_ERR_MALLOC),
file, strerror(err));
sinfo_free(secarr, num_sinfo);
sinfo_list_free_all(&seclist);
return (0);
}
*_cache = cache_init;
_cache++;
ndx = 1;
for (sinfo = secarr; num_sinfo > 0; sinfo++) {
if (sinfo->data != NULL) {
_cache->c_scn = NULL;
_cache->c_shdr = sinfo->shdr;
_cache->c_data = sinfo->data;
_cache->c_name = (char *)sinfo_data[sinfo->type].name;
_cache->c_ndx = ndx++;
_cache++;
num_sinfo--;
}
}
for (sinfo_list = seclist.next; num_list_sinfo > 0;
sinfo_list = sinfo_list->next) {
sinfo = &sinfo_list->sinfo;
if (sinfo->data != NULL) {
_cache->c_scn = NULL;
_cache->c_shdr = sinfo->shdr;
_cache->c_data = sinfo->data;
_cache->c_name = (char *)sinfo_data[sinfo->type].name;
_cache->c_ndx = ndx++;
_cache++;
num_list_sinfo--;
}
}
return (1);
}
/*
* Release all the memory referenced by a cache array allocated
* by fake_shdr_cache().
*/
void
fake_shdr_cache_free(Cache *cache, size_t shnum)
{
Cache *_cache;
for (_cache = cache; shnum--; _cache++) {
if (_cache->c_data != NULL) {
if (_cache->c_data->d_buf != NULL)
free(_cache->c_data->d_buf);
free(_cache->c_data);
}
if (_cache->c_shdr)
free(_cache->c_shdr);
}
free(cache);
}
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/
/*
* Copyright 2015 Nexenta Systems, Inc. All rights reserved.
* Copyright 2018 Joyent, Inc.
* Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
*/
/*
* A little program who's only purpose is to get all the
* CTF type information we want into an object.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <sys/corectl.h>
#define _STRUCTURED_PROC 1
#include <sys/procfs.h>
#include <sys/auxv.h>
#include <sys/old_procfs.h>
#include <sys/utsname.h>
#include <sys/secflags.h>
/* prgregset_t is a define on intel */
#ifdef prgregset_t
typedef prgregset_t
#undef prgregset_t
prgregset_t;
#endif
/* instantiate the types for CTF */
auxv_t auxv;
prgregset_t prgregset;
lwpstatus_t lwpstatus;
pstatus_t pstatus;
prstatus_t prstatus;
psinfo_t psinfo;
prpsinfo_t prpsinfo;
lwpsinfo_t lwpsinfo;
prcred_t prcred;
prpriv_t prpriv;
priv_impl_info_t priv_impl;
fltset_t fltset;
siginfo_t siginfo;
sigset_t sigset;
struct sigaction sigact;
stack_t stack;
sysset_t sysset;
timestruc_t ts;
struct utsname uts;
prfdinfo_core_t ptfd;
prsecflags_t psf;
prlwpname_t psn;
prupanic_t pru;
prcwd_t cwd;
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright 2015 Nexenta Systems, Inc. All rights reserved.
* Copyright 2018 Joyent, Inc.
* Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
*/
/*
* This program is used to generate the contents of the
* struct_layout_XXX.c files that contain per-architecture
* structure layout information.
*
* Although not part of elfdump, it is built by the makefile
* along with it. Note, the Makefile only builds versions that
* are natively supported and therefore you must manually run
* this for other architectures.
*
* To use it:
*
* 1) Run it, capturing the output in a file.
* 2) If this is a replacement for an existing file,
* diff the new and old copies to ensure only
* the changes you expected are present.
* 3) Put the new file in the common directory under the name
* struct_layout_XXX.c, where XXX is the name of
* the architecture (i386, amd64, sparc, sparcv9, etc).
* 2) Add any necessary header and copyright comments.
* 3) If this is a new architecture:
* - Add an extern statement for struct_layout_XXX()
* to struct_layout.h
* - Add a case for it to the function sl_struct_layout()
* in struct_layout.c.
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <err.h>
#include <sys/types.h>
#include <libctf.h>
/*
* This extracts CTF information from a temporary object file.
*
* START and END bracket a struct layout definition. They issue
* the typedef boilerplate, and the standard first element (sizeof)
* which captures the overall size of the structure.
*
* SCALAR_FIELD is for scalar struct fields
*
* ARRAY_FIELD is for array struct fields
*
* ARRAY_TYPE is for plain (non-struct) array types
*/
#define START(_name, _type) \
do_start(#_name, #_type)
#define END (void) \
do_end()
#define SCALAR_FIELD(_type, _field, _sign) \
do_scalar_field(#_type, #_field, _sign, NULL)
#define SCALAR_FIELD4(_type, _field, _sign, _rtype) \
do_scalar_field(#_type, #_field, _sign, _rtype)
#define ARRAY_FIELD(_type, _field, _sign) \
do_array_field(#_type, #_field, _sign, NULL)
#define ARRAY_TYPE(_type, _sign) \
do_array_type(#_type, "elt0", _sign)
static void do_start(char *_name, char *_type);
static void do_end(void);
static void do_start_name(char *name);
static void do_start_sizeof(char *_type, char *realtype);
static void do_scalar_field(char *_type, char *_field,
int _sign, char *dotfield);
static void do_array_field(char *_type, char *_field,
int _sign, char *dotfield);
static void do_array_type(char *_type, char *_field, int _sign);
static void get_ctf_file(char *fname);
static int get_field_info(char *tname, char *fname, char *dotname,
int *offp, int *sizep);
static ctf_file_t *ctf;
static char *objfile;
static char *machname;
/* auxv_t, <sys/auxv.h> */
static void
gen_auxv(void)
{
START(auxv, auxv_t);
SCALAR_FIELD(auxv_t, a_type, 1);
SCALAR_FIELD(auxv_t, a_un.a_val, 1);
SCALAR_FIELD(auxv_t, a_un.a_ptr, 0);
SCALAR_FIELD(auxv_t, a_un.a_fcn, 0);
END;
}
/* prgregset_t, <sys/prgregset.h> */
static void
gen_prgregset(void)
{
START(prgregset, prgregset_t);
ARRAY_TYPE(prgregset_t, 0);
END;
}
/* lwpstatus_t, <sys/procfs.h> */
static void
gen_lwpstatus(void)
{
START(lwpstatus, lwpstatus_t);
SCALAR_FIELD(lwpstatus_t, pr_flags, 0);
SCALAR_FIELD(lwpstatus_t, pr_lwpid, 0);
SCALAR_FIELD(lwpstatus_t, pr_why, 0);
SCALAR_FIELD(lwpstatus_t, pr_what, 0);
SCALAR_FIELD(lwpstatus_t, pr_cursig, 0);
SCALAR_FIELD(lwpstatus_t, pr_info, 0);
SCALAR_FIELD(lwpstatus_t, pr_lwppend, 0);
SCALAR_FIELD(lwpstatus_t, pr_lwphold, 0);
SCALAR_FIELD(lwpstatus_t, pr_action, 0);
SCALAR_FIELD(lwpstatus_t, pr_altstack, 0);
SCALAR_FIELD(lwpstatus_t, pr_oldcontext, 0);
SCALAR_FIELD(lwpstatus_t, pr_syscall, 0);
SCALAR_FIELD(lwpstatus_t, pr_nsysarg, 0);
SCALAR_FIELD(lwpstatus_t, pr_errno, 0);
ARRAY_FIELD(lwpstatus_t, pr_sysarg, 0);
SCALAR_FIELD(lwpstatus_t, pr_rval1, 0);
SCALAR_FIELD(lwpstatus_t, pr_rval2, 0);
ARRAY_FIELD(lwpstatus_t, pr_clname, 0);
SCALAR_FIELD(lwpstatus_t, pr_tstamp, 0);
SCALAR_FIELD(lwpstatus_t, pr_utime, 0);
SCALAR_FIELD(lwpstatus_t, pr_stime, 0);
SCALAR_FIELD(lwpstatus_t, pr_errpriv, 0);
SCALAR_FIELD(lwpstatus_t, pr_ustack, 0);
SCALAR_FIELD(lwpstatus_t, pr_instr, 0);
SCALAR_FIELD(lwpstatus_t, pr_reg, 0);
SCALAR_FIELD(lwpstatus_t, pr_fpreg, 0);
END;
}
/* pstatus_t, <sys/procfs.h> */
static void
gen_pstatus(void)
{
START(pstatus, pstatus_t);
SCALAR_FIELD(pstatus_t, pr_flags, 1);
SCALAR_FIELD(pstatus_t, pr_nlwp, 1);
SCALAR_FIELD(pstatus_t, pr_pid, 0);
SCALAR_FIELD(pstatus_t, pr_ppid, 0);
SCALAR_FIELD(pstatus_t, pr_pgid, 0);
SCALAR_FIELD(pstatus_t, pr_sid, 0);
SCALAR_FIELD(pstatus_t, pr_aslwpid, 1);
SCALAR_FIELD(pstatus_t, pr_agentid, 1);
SCALAR_FIELD(pstatus_t, pr_sigpend, 0);
SCALAR_FIELD(pstatus_t, pr_brkbase, 0);
SCALAR_FIELD(pstatus_t, pr_brksize, 0);
SCALAR_FIELD(pstatus_t, pr_stkbase, 0);
SCALAR_FIELD(pstatus_t, pr_stksize, 0);
SCALAR_FIELD(pstatus_t, pr_utime, 0);
SCALAR_FIELD(pstatus_t, pr_stime, 0);
SCALAR_FIELD(pstatus_t, pr_cutime, 0);
SCALAR_FIELD(pstatus_t, pr_cstime, 0);
SCALAR_FIELD(pstatus_t, pr_sigtrace, 0);
SCALAR_FIELD(pstatus_t, pr_flttrace, 0);
SCALAR_FIELD(pstatus_t, pr_sysentry, 0);
SCALAR_FIELD(pstatus_t, pr_sysexit, 0);
SCALAR_FIELD(pstatus_t, pr_dmodel, 0);
SCALAR_FIELD(pstatus_t, pr_taskid, 1);
SCALAR_FIELD(pstatus_t, pr_projid, 1);
SCALAR_FIELD(pstatus_t, pr_nzomb, 1);
SCALAR_FIELD(pstatus_t, pr_zoneid, 1);
SCALAR_FIELD(pstatus_t, pr_lwp, 0);
END;
}
/* prstatus_t, <sys/old_procfs.h> */
static void
gen_prstatus(void)
{
START(prstatus, prstatus_t);
SCALAR_FIELD(prstatus_t, pr_flags, 1);
SCALAR_FIELD(prstatus_t, pr_why, 1);
SCALAR_FIELD(prstatus_t, pr_what, 1);
SCALAR_FIELD(prstatus_t, pr_info, 0);
SCALAR_FIELD(prstatus_t, pr_cursig, 1);
SCALAR_FIELD(prstatus_t, pr_nlwp, 0);
SCALAR_FIELD(prstatus_t, pr_sigpend, 0);
SCALAR_FIELD(prstatus_t, pr_sighold, 0);
SCALAR_FIELD(prstatus_t, pr_altstack, 0);
SCALAR_FIELD(prstatus_t, pr_action, 0);
SCALAR_FIELD(prstatus_t, pr_pid, 0);
SCALAR_FIELD(prstatus_t, pr_ppid, 0);
SCALAR_FIELD(prstatus_t, pr_pgrp, 0);
SCALAR_FIELD(prstatus_t, pr_sid, 0);
SCALAR_FIELD(prstatus_t, pr_utime, 0);
SCALAR_FIELD(prstatus_t, pr_stime, 0);
SCALAR_FIELD(prstatus_t, pr_cutime, 0);
SCALAR_FIELD(prstatus_t, pr_cstime, 0);
ARRAY_FIELD(prstatus_t, pr_clname, 0);
SCALAR_FIELD(prstatus_t, pr_syscall, 1);
SCALAR_FIELD(prstatus_t, pr_nsysarg, 1);
ARRAY_FIELD(prstatus_t, pr_sysarg, 1);
SCALAR_FIELD(prstatus_t, pr_who, 0);
SCALAR_FIELD(prstatus_t, pr_lwppend, 0);
SCALAR_FIELD(prstatus_t, pr_oldcontext, 0);
SCALAR_FIELD(prstatus_t, pr_brkbase, 0);
SCALAR_FIELD(prstatus_t, pr_brksize, 0);
SCALAR_FIELD(prstatus_t, pr_stkbase, 0);
SCALAR_FIELD(prstatus_t, pr_stksize, 0);
SCALAR_FIELD(prstatus_t, pr_processor, 1);
SCALAR_FIELD(prstatus_t, pr_bind, 1);
SCALAR_FIELD(prstatus_t, pr_instr, 1);
SCALAR_FIELD(prstatus_t, pr_reg, 0);
END;
}
/* psinfo_t, <sys/procfs.h> */
static void
gen_psinfo(void)
{
START(psinfo, psinfo_t);
SCALAR_FIELD(psinfo_t, pr_flag, 1);
SCALAR_FIELD(psinfo_t, pr_nlwp, 1);
SCALAR_FIELD(psinfo_t, pr_pid, 0);
SCALAR_FIELD(psinfo_t, pr_ppid, 0);
SCALAR_FIELD(psinfo_t, pr_pgid, 0);
SCALAR_FIELD(psinfo_t, pr_sid, 0);
SCALAR_FIELD(psinfo_t, pr_uid, 0);
SCALAR_FIELD(psinfo_t, pr_euid, 0);
SCALAR_FIELD(psinfo_t, pr_gid, 0);
SCALAR_FIELD(psinfo_t, pr_egid, 0);
SCALAR_FIELD(psinfo_t, pr_addr, 0);
SCALAR_FIELD(psinfo_t, pr_size, 0);
SCALAR_FIELD(psinfo_t, pr_rssize, 0);
SCALAR_FIELD(psinfo_t, pr_ttydev, 0);
SCALAR_FIELD(psinfo_t, pr_pctcpu, 0);
SCALAR_FIELD(psinfo_t, pr_pctmem, 0);
SCALAR_FIELD(psinfo_t, pr_start, 0);
SCALAR_FIELD(psinfo_t, pr_time, 0);
SCALAR_FIELD(psinfo_t, pr_ctime, 0);
ARRAY_FIELD(psinfo_t, pr_fname, 0);
ARRAY_FIELD(psinfo_t, pr_psargs, 0);
SCALAR_FIELD(psinfo_t, pr_wstat, 1);
SCALAR_FIELD(psinfo_t, pr_argc, 1);
SCALAR_FIELD(psinfo_t, pr_argv, 0);
SCALAR_FIELD(psinfo_t, pr_envp, 0);
SCALAR_FIELD(psinfo_t, pr_dmodel, 0);
SCALAR_FIELD(psinfo_t, pr_taskid, 0);
SCALAR_FIELD(psinfo_t, pr_projid, 0);
SCALAR_FIELD(psinfo_t, pr_nzomb, 1);
SCALAR_FIELD(psinfo_t, pr_poolid, 0);
SCALAR_FIELD(psinfo_t, pr_zoneid, 0);
SCALAR_FIELD(psinfo_t, pr_contract, 0);
SCALAR_FIELD(psinfo_t, pr_lwp, 0);
END;
}
/* prpsinfo_t, <sys/old_procfs.h> */
static void
gen_prpsinfo(void)
{
START(prpsinfo, prpsinfo_t);
SCALAR_FIELD(prpsinfo_t, pr_state, 0);
SCALAR_FIELD(prpsinfo_t, pr_sname, 0);
SCALAR_FIELD(prpsinfo_t, pr_zomb, 0);
SCALAR_FIELD(prpsinfo_t, pr_nice, 0);
SCALAR_FIELD(prpsinfo_t, pr_flag, 0);
SCALAR_FIELD(prpsinfo_t, pr_uid, 0);
SCALAR_FIELD(prpsinfo_t, pr_gid, 0);
SCALAR_FIELD(prpsinfo_t, pr_pid, 0);
SCALAR_FIELD(prpsinfo_t, pr_ppid, 0);
SCALAR_FIELD(prpsinfo_t, pr_pgrp, 0);
SCALAR_FIELD(prpsinfo_t, pr_sid, 0);
SCALAR_FIELD(prpsinfo_t, pr_addr, 0);
SCALAR_FIELD(prpsinfo_t, pr_size, 0);
SCALAR_FIELD(prpsinfo_t, pr_rssize, 0);
SCALAR_FIELD(prpsinfo_t, pr_wchan, 0);
SCALAR_FIELD(prpsinfo_t, pr_start, 0);
SCALAR_FIELD(prpsinfo_t, pr_time, 0);
SCALAR_FIELD(prpsinfo_t, pr_pri, 1);
SCALAR_FIELD(prpsinfo_t, pr_oldpri, 0);
SCALAR_FIELD(prpsinfo_t, pr_cpu, 0);
SCALAR_FIELD(prpsinfo_t, pr_ottydev, 0);
SCALAR_FIELD(prpsinfo_t, pr_lttydev, 0);
ARRAY_FIELD(prpsinfo_t, pr_clname, 0);
ARRAY_FIELD(prpsinfo_t, pr_fname, 0);
ARRAY_FIELD(prpsinfo_t, pr_psargs, 0);
SCALAR_FIELD(prpsinfo_t, pr_syscall, 1);
SCALAR_FIELD(prpsinfo_t, pr_ctime, 0);
SCALAR_FIELD(prpsinfo_t, pr_bysize, 0);
SCALAR_FIELD(prpsinfo_t, pr_byrssize, 0);
SCALAR_FIELD(prpsinfo_t, pr_argc, 1);
SCALAR_FIELD(prpsinfo_t, pr_argv, 0);
SCALAR_FIELD(prpsinfo_t, pr_envp, 0);
SCALAR_FIELD(prpsinfo_t, pr_wstat, 1);
SCALAR_FIELD(prpsinfo_t, pr_pctcpu, 0);
SCALAR_FIELD(prpsinfo_t, pr_pctmem, 0);
SCALAR_FIELD(prpsinfo_t, pr_euid, 0);
SCALAR_FIELD(prpsinfo_t, pr_egid, 0);
SCALAR_FIELD(prpsinfo_t, pr_aslwpid, 0);
SCALAR_FIELD(prpsinfo_t, pr_dmodel, 0);
END;
}
/* lwpsinfo_t, <sys/procfs.h> */
static void
gen_lwpsinfo(void)
{
START(lwpsinfo, lwpsinfo_t);
SCALAR_FIELD(lwpsinfo_t, pr_flag, 1);
SCALAR_FIELD(lwpsinfo_t, pr_lwpid, 0);
SCALAR_FIELD(lwpsinfo_t, pr_addr, 0);
SCALAR_FIELD(lwpsinfo_t, pr_wchan, 0);
SCALAR_FIELD(lwpsinfo_t, pr_stype, 0);
SCALAR_FIELD(lwpsinfo_t, pr_state, 0);
SCALAR_FIELD(lwpsinfo_t, pr_sname, 0);
SCALAR_FIELD(lwpsinfo_t, pr_nice, 0);
SCALAR_FIELD(lwpsinfo_t, pr_syscall, 0);
SCALAR_FIELD(lwpsinfo_t, pr_oldpri, 0);
SCALAR_FIELD(lwpsinfo_t, pr_cpu, 0);
SCALAR_FIELD(lwpsinfo_t, pr_pri, 1);
SCALAR_FIELD(lwpsinfo_t, pr_pctcpu, 0);
SCALAR_FIELD(lwpsinfo_t, pr_start, 0);
SCALAR_FIELD(lwpsinfo_t, pr_time, 0);
ARRAY_FIELD(lwpsinfo_t, pr_clname, 0);
ARRAY_FIELD(lwpsinfo_t, pr_name, 0);
SCALAR_FIELD(lwpsinfo_t, pr_onpro, 1);
SCALAR_FIELD(lwpsinfo_t, pr_bindpro, 1);
SCALAR_FIELD(lwpsinfo_t, pr_bindpset, 1);
SCALAR_FIELD(lwpsinfo_t, pr_lgrp, 1);
END;
}
/* prcred_t, <sys/procfs.h> */
static void
gen_prcred(void)
{
START(prcred, prcred_t);
SCALAR_FIELD(prcred_t, pr_euid, 0);
SCALAR_FIELD(prcred_t, pr_ruid, 0);
SCALAR_FIELD(prcred_t, pr_suid, 0);
SCALAR_FIELD(prcred_t, pr_egid, 0);
SCALAR_FIELD(prcred_t, pr_rgid, 0);
SCALAR_FIELD(prcred_t, pr_sgid, 0);
SCALAR_FIELD(prcred_t, pr_ngroups, 1);
ARRAY_FIELD(prcred_t, pr_groups, 0);
END;
}
/* prpriv_t, <sys/procfs.h> */
static void
gen_prpriv(void)
{
START(prpriv, prpriv_t);
SCALAR_FIELD(prpriv_t, pr_nsets, 0);
SCALAR_FIELD(prpriv_t, pr_setsize, 0);
SCALAR_FIELD(prpriv_t, pr_infosize, 0);
ARRAY_FIELD(prpriv_t, pr_sets, 0);
END;
}
/* priv_impl_info_t, <sys/priv.h> */
static void
gen_priv_impl_info(void)
{
START(priv_impl_info, priv_impl_info_t);
SCALAR_FIELD(priv_impl_info_t, priv_headersize, 0);
SCALAR_FIELD(priv_impl_info_t, priv_flags, 0);
SCALAR_FIELD(priv_impl_info_t, priv_nsets, 0);
SCALAR_FIELD(priv_impl_info_t, priv_setsize, 0);
SCALAR_FIELD(priv_impl_info_t, priv_max, 0);
SCALAR_FIELD(priv_impl_info_t, priv_infosize, 0);
SCALAR_FIELD(priv_impl_info_t, priv_globalinfosize, 0);
END;
}
/* fltset_t, <sys/fault.h> */
static void
gen_fltset(void)
{
START(fltset, fltset_t);
ARRAY_FIELD(fltset_t, word, 0);
END;
}
/*
* Layout description of siginfo_t, <sys/siginfo.h>
*
* Note: many siginfo_t members are #defines mapping to
* long dotted members of sub-structs or unions, and
* we need the full member spec (with dots) for those.
*/
static void
gen_siginfo(void)
{
START(siginfo, siginfo_t);
SCALAR_FIELD(siginfo_t, si_signo, 0);
SCALAR_FIELD(siginfo_t, si_errno, 0);
SCALAR_FIELD(siginfo_t, si_code, 1);
SCALAR_FIELD4(siginfo_t, si_value.sival_int, 0,
"__data.__proc.__pdata.__kill.__value.sival_int");
SCALAR_FIELD4(siginfo_t, si_value.sival_ptr, 0,
"__data.__proc.__pdata.__kill.__value.sival_ptr");
SCALAR_FIELD4(siginfo_t, si_pid, 0,
"__data.__proc.__pid");
SCALAR_FIELD4(siginfo_t, si_uid, 0,
"__data.__proc.__pdata.__kill.__uid");
SCALAR_FIELD4(siginfo_t, si_ctid, 0,
"__data.__proc.__ctid");
SCALAR_FIELD4(siginfo_t, si_zoneid, 0,
"__data.__proc.__zoneid");
SCALAR_FIELD4(siginfo_t, si_entity, 0,
"__data.__rctl.__entity");
SCALAR_FIELD4(siginfo_t, si_addr, 0,
"__data.__fault.__addr");
SCALAR_FIELD4(siginfo_t, si_status, 0,
"__data.__proc.__pdata.__cld.__status");
SCALAR_FIELD4(siginfo_t, si_band, 0,
"__data.__file.__band");
END;
}
/* sigset_t, <sys/signal.h> */
static void
gen_sigset(void)
{
START(sigset, sigset_t);
ARRAY_FIELD(sigset_t, __sigbits, 0);
END;
}
/* struct sigaction, <sys/signal.h> */
static void
gen_sigaction(void)
{
START(sigaction, struct sigaction);
SCALAR_FIELD(struct sigaction, sa_flags, 0);
SCALAR_FIELD4(struct sigaction, sa_handler, 0,
"_funcptr._handler");
SCALAR_FIELD4(struct sigaction, sa_sigaction, 0,
"_funcptr._sigaction");
SCALAR_FIELD(struct sigaction, sa_mask, 0);
END;
}
/* stack_t, <sys/signal.h> */
static void
gen_stack(void)
{
START(stack, stack_t);
SCALAR_FIELD(stack_t, ss_sp, 0);
SCALAR_FIELD(stack_t, ss_size, 0);
SCALAR_FIELD(stack_t, ss_flags, 0);
END;
}
/* sysset_t, <sys/syscall.h> */
static void
gen_sysset(void)
{
START(sysset, sysset_t);
ARRAY_FIELD(sysset_t, word, 0);
END;
}
/* timestruc_t, <sys/time_impl.h> */
static void
gen_timestruc(void)
{
START(timestruc, timestruc_t);
SCALAR_FIELD(timestruc_t, tv_sec, 0);
SCALAR_FIELD(timestruc_t, tv_nsec, 0);
END;
}
/* struct utsname, <sys/utsname.h> */
static void
gen_utsname(void)
{
START(utsname, struct utsname);
ARRAY_FIELD(struct utsname, sysname, 0);
ARRAY_FIELD(struct utsname, nodename, 0);
ARRAY_FIELD(struct utsname, release, 0);
ARRAY_FIELD(struct utsname, version, 0);
ARRAY_FIELD(struct utsname, machine, 0);
END;
}
static void
gen_prfdinfo(void)
{
START(prfdinfo, prfdinfo_core_t);
SCALAR_FIELD(prfdinfo_core_t, pr_fd, 0);
SCALAR_FIELD(prfdinfo_core_t, pr_mode, 0);
SCALAR_FIELD(prfdinfo_core_t, pr_uid, 0);
SCALAR_FIELD(prfdinfo_core_t, pr_gid, 0);
SCALAR_FIELD(prfdinfo_core_t, pr_major, 0);
SCALAR_FIELD(prfdinfo_core_t, pr_minor, 0);
SCALAR_FIELD(prfdinfo_core_t, pr_rmajor, 0);
SCALAR_FIELD(prfdinfo_core_t, pr_rminor, 0);
SCALAR_FIELD(prfdinfo_core_t, pr_ino, 0);
SCALAR_FIELD(prfdinfo_core_t, pr_offset, 0);
SCALAR_FIELD(prfdinfo_core_t, pr_size, 0);
SCALAR_FIELD(prfdinfo_core_t, pr_fileflags, 0);
SCALAR_FIELD(prfdinfo_core_t, pr_fdflags, 0);
ARRAY_FIELD(prfdinfo_core_t, pr_path, 0);
END;
}
static void
gen_prsecflags(void)
{
START(prsecflags, prsecflags_t);
SCALAR_FIELD(prsecflags_t, pr_version, 0);
SCALAR_FIELD(prsecflags_t, pr_effective, 0);
SCALAR_FIELD(prsecflags_t, pr_inherit, 0);
SCALAR_FIELD(prsecflags_t, pr_lower, 0);
SCALAR_FIELD(prsecflags_t, pr_upper, 0);
END;
}
static void
gen_prlwpname(void)
{
START(prlwpname, prlwpname_t);
SCALAR_FIELD(prlwpname_t, pr_lwpid, 0);
ARRAY_FIELD(prlwpname_t, pr_lwpname, 0);
END;
}
static void
gen_prupanic(void)
{
START(prupanic, prupanic_t);
SCALAR_FIELD(prupanic_t, pru_version, 0);
SCALAR_FIELD(prupanic_t, pru_flags, 0);
ARRAY_FIELD(prupanic_t, pru_data, 0);
END;
}
static void
gen_prcwd(void)
{
START(prcwd, prcwd_t);
SCALAR_FIELD(prcwd_t, prcwd_fsid, 0);
ARRAY_FIELD(prcwd_t, prcwd_fsname, 0);
ARRAY_FIELD(prcwd_t, prcwd_mntpt, 0);
ARRAY_FIELD(prcwd_t, prcwd_mntspec, 0);
ARRAY_FIELD(prcwd_t, prcwd_cwd, 0);
END;
}
/*ARGSUSED*/
int
main(int argc, char *argv[])
{
const char *fmt = "\t&%s_layout,\n";
/* get obj file for input */
if (argc < 3) {
(void) fprintf(stderr,
"usage: %s {object_file} {MACH}\n", argv[0]);
exit(1);
}
objfile = argv[1];
machname = argv[2];
get_ctf_file(objfile);
(void) printf("#include <struct_layout.h>\n");
gen_auxv();
gen_prgregset();
gen_lwpstatus();
gen_pstatus();
gen_prstatus();
gen_psinfo();
gen_prpsinfo();
gen_lwpsinfo();
gen_prcred();
gen_prpriv();
gen_priv_impl_info();
gen_fltset();
gen_siginfo();
gen_sigset();
gen_sigaction();
gen_stack();
gen_sysset();
gen_timestruc();
gen_utsname();
gen_prfdinfo();
gen_prsecflags();
gen_prlwpname();
gen_prupanic();
gen_prcwd();
/*
* Generate the full arch_layout description
*/
(void) printf(
"\n\n\n\nstatic const sl_arch_layout_t layout_%s = {\n",
machname);
(void) printf(fmt, "auxv");
(void) printf(fmt, "fltset");
(void) printf(fmt, "lwpsinfo");
(void) printf(fmt, "lwpstatus");
(void) printf(fmt, "prcred");
(void) printf(fmt, "priv_impl_info");
(void) printf(fmt, "prpriv");
(void) printf(fmt, "psinfo");
(void) printf(fmt, "pstatus");
(void) printf(fmt, "prgregset");
(void) printf(fmt, "prpsinfo");
(void) printf(fmt, "prstatus");
(void) printf(fmt, "sigaction");
(void) printf(fmt, "siginfo");
(void) printf(fmt, "sigset");
(void) printf(fmt, "stack");
(void) printf(fmt, "sysset");
(void) printf(fmt, "timestruc");
(void) printf(fmt, "utsname");
(void) printf(fmt, "prfdinfo");
(void) printf(fmt, "prsecflags");
(void) printf(fmt, "prlwpname");
(void) printf(fmt, "prupanic");
(void) printf(fmt, "prcwd");
(void) printf("};\n");
/*
* A public function, to make the information available
*/
(void) printf("\n\nconst sl_arch_layout_t *\n");
(void) printf("struct_layout_%s(void)\n", machname);
(void) printf("{\n\treturn (&layout_%s);\n}\n", machname);
return (0);
}
/*
* Helper functions using the CTF library to get type info.
*/
static void
get_ctf_file(char *fname)
{
int ctferr;
objfile = fname;
if ((ctf = ctf_open(objfile, &ctferr)) == NULL) {
errx(1, "Couldn't open object file %s: %s\n", objfile,
ctf_errmsg(ctferr));
}
}
static void
print_row(int boff, int eltlen, int nelts, int issigned, char *comment)
{
(void) printf("\t{ %d,\t%d,\t%d,\t%d },\t\t/* %s */\n",
boff, eltlen, nelts, issigned, comment);
}
static void
do_start(char *sname, char *tname)
{
do_start_name(sname);
do_start_sizeof(tname, NULL);
}
static void
do_start_name(char *sname)
{
(void) printf("\n\nstatic const sl_%s_layout_t %s_layout = {\n",
sname, sname);
}
static void
do_end(void)
{
(void) printf("};\n");
}
static void
do_start_sizeof(char *tname, char *rtname)
{
char comment[100];
ctf_id_t stype;
int sz;
if (rtname == NULL)
rtname = tname;
if ((stype = ctf_lookup_by_name(ctf, rtname)) == CTF_ERR)
errx(1, "Couldn't find type %s", rtname);
if ((stype = ctf_type_resolve(ctf, stype)) == CTF_ERR)
errx(1, "Couldn't resolve type %s", tname);
if ((sz = (int)ctf_type_size(ctf, stype)) < 0) {
errx(1, "Couldn't get size for type %s", tname);
} else if (sz == 0) {
errx(1, "Invalid type size 0 for %s", tname);
}
(void) snprintf(comment, sizeof (comment), "sizeof (%s)", tname);
print_row(0, sz, 0, 0, comment);
}
static void
do_scalar_field(char *tname, char *fname, int _sign, char *dotfield)
{
int rc, off, sz, ftype;
rc = get_field_info(tname, fname, dotfield, &off, &ftype);
if (rc < 0)
errx(1, "Can't get field info for %s->%s", tname, fname);
if ((ftype = ctf_type_resolve(ctf, ftype)) == CTF_ERR)
errx(1, "Couldn't resolve type of %s->%s", tname, fname);
if ((sz = (int)ctf_type_size(ctf, ftype)) < 0) {
errx(1, "Couldn't get size for type ID %d", ftype);
} else if (sz == 0) {
errx(1, "Invalid type size 0 for type ID %d", ftype);
}
print_row(off, sz, 0, _sign, fname);
}
static void
do_array_field(char *tname, char *fname,
int _sign, char *dotfield)
{
char comment[100];
ctf_arinfo_t ai;
int typekind;
int esz, rc, off, ftype;
rc = get_field_info(tname, fname, dotfield, &off, &ftype);
if (rc < 0)
errx(1, "Can't get field info for %s->%s", tname, fname);
if ((ftype = ctf_type_resolve(ctf, ftype)) == CTF_ERR)
errx(1, "Couldn't resolve type of %s->%s", tname, fname);
typekind = ctf_type_kind(ctf, ftype);
if (typekind != CTF_K_ARRAY)
errx(1, "Wrong type for %s->%s", tname, fname);
rc = ctf_array_info(ctf, ftype, &ai);
if (rc != 0)
errx(1, "Can't get array info for %s->%s\n", tname, fname);
esz = ctf_type_size(ctf, ai.ctr_contents);
if (esz < 0)
errx(1, "Can't get element size for %s->%s\n", tname, fname);
(void) snprintf(comment, sizeof (comment), "%s[]", fname);
print_row(off, esz, ai.ctr_nelems, _sign, comment);
}
static void
do_array_type(char *tname, char *fname, int _sign)
{
ctf_arinfo_t ai;
int stype, typekind;
int esz, rc;
if ((stype = ctf_lookup_by_name(ctf, tname)) == CTF_ERR)
errx(1, "Couldn't find type %s", tname);
if ((stype = ctf_type_resolve(ctf, stype)) == CTF_ERR)
errx(1, "Couldn't resolve type %s", tname);
typekind = ctf_type_kind(ctf, stype);
if (typekind != CTF_K_ARRAY)
errx(1, "Wrong type for %s->%s", tname, fname);
rc = ctf_array_info(ctf, stype, &ai);
if (rc != 0)
errx(1, "Can't get array info for %s->%s\n", tname, fname);
esz = ctf_type_size(ctf, ai.ctr_contents);
if (esz < 0)
errx(1, "Can't get element size for %s->%s\n", tname, fname);
print_row(0, esz, ai.ctr_nelems, _sign, fname);
}
struct gfinfo {
char *tname; /* top type name, i.e. the struct */
char *fname; /* field name */
char *dotname; /* full field name with dots (optional) */
char *prefix; /* current field search prefix */
int base_off;
int fld_off;
int fld_type;
};
static int gfi_iter(const char *fname, ctf_id_t mbrtid,
ulong_t off, void *varg);
/*
* Lookup field "fname" in type "tname". If "dotname" is non-NULL,
* that's the full field name with dots, i.e. a_un.un_foo, which
* we must search for by walking the struct CTF recursively.
*/
static int
get_field_info(char *tname, char *fname, char *dotname,
int *offp, int *tidp)
{
struct gfinfo gfi;
ctf_id_t stype;
int typekind;
int rc;
if ((stype = ctf_lookup_by_name(ctf, tname)) == CTF_ERR)
errx(1, "Couldn't find type %s", tname);
if ((stype = ctf_type_resolve(ctf, stype)) == CTF_ERR)
errx(1, "Couldn't resolve type %s", tname);
/* If fname has a dot, use it as dotname too. */
if (dotname == NULL && strchr(fname, '.') != NULL)
dotname = fname;
gfi.tname = tname;
gfi.fname = fname;
gfi.dotname = dotname;
gfi.prefix = "";
gfi.base_off = 0;
gfi.fld_off = 0;
gfi.fld_type = 0;
typekind = ctf_type_kind(ctf, stype);
switch (typekind) {
case CTF_K_STRUCT:
case CTF_K_UNION:
rc = ctf_member_iter(ctf, stype, gfi_iter, &gfi);
break;
default:
errx(1, "Unexpected top-level type for %s", tname);
break;
}
if (rc < 0)
errx(1, "Error getting info for %s.%s", tname, fname);
if (rc == 0)
errx(1, "Did not find %s.%s", tname, fname);
*offp = gfi.fld_off;
*tidp = gfi.fld_type;
return (0);
}
/*
* Iteration callback for ctf_member_iter
* Return <0 on error, 0 to keep looking, >0 for found.
*
* If no dotname, simple search for fieldname.
* If we're asked to search with dotname, we need to do a full
* recursive walk of the types under the dotname.
*/
int
gfi_iter(const char *fieldname, ctf_id_t mbrtid, ulong_t off, void *varg)
{
char namebuf[100];
struct gfinfo *gfi = varg;
char *saveprefix;
int saveoff;
int typekind;
int byteoff;
int len, rc;
byteoff = gfi->base_off + (int)(off >> 3);
/* Easy cases first: no dotname */
if (gfi->dotname == NULL) {
if (strcmp(gfi->fname, fieldname) == 0) {
gfi->fld_off = byteoff;
gfi->fld_type = mbrtid;
return (1);
}
return (0);
}
/* Exact match on the dotname? */
(void) snprintf(namebuf, sizeof (namebuf), "%s%s",
gfi->prefix, fieldname);
if (strcmp(gfi->dotname, namebuf) == 0) {
gfi->fld_off = byteoff;
gfi->fld_type = mbrtid;
return (1);
}
/*
* May need to recurse under this field, but
* only if there's a match through '.'
*/
(void) strlcat(namebuf, ".", sizeof (namebuf));
len = strlen(namebuf);
if (strncmp(gfi->dotname, namebuf, len) != 0)
return (0);
typekind = ctf_type_kind(ctf, mbrtid);
switch (typekind) {
case CTF_K_STRUCT:
case CTF_K_UNION:
break;
default:
return (0);
}
/* Recursively walk members */
saveprefix = gfi->prefix;
saveoff = gfi->base_off;
gfi->prefix = namebuf;
gfi->base_off = byteoff;
rc = ctf_member_iter(ctf, mbrtid, gfi_iter, gfi);
gfi->prefix = saveprefix;
gfi->base_off = saveoff;
return (rc);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2024 Oxide Computer Company
*/
/*
* Dump an elf file.
*/
#include <sys/param.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <_libelf.h>
#include <link.h>
#include <stdarg.h>
#include <unistd.h>
#include <libgen.h>
#include <libintl.h>
#include <locale.h>
#include <errno.h>
#include <strings.h>
#include <debug.h>
#include <conv.h>
#include <msg.h>
#include <_elfdump.h>
#include <sys/elf_SPARC.h>
#include <sys/elf_amd64.h>
#include <sys/hexdump.h>
const Cache cache_init = {NULL, NULL, NULL, NULL, 0};
/*
* The -I, -N, and -T options are called "match options", because
* they allow selecting the items to be displayed based on matching
* their index, name, or type.
*
* The ELF information to which -I, -N, or -T are applied in
* the current invocation is called the "match item".
*/
typedef enum {
MATCH_ITEM_PT, /* Program header (PT_) */
MATCH_ITEM_SHT /* Section header (SHT_) */
} match_item_t;
/* match_opt_t is used to note which match option was used */
typedef enum {
MATCH_OPT_NAME, /* Record contains a name */
MATCH_OPT_NDX, /* Record contains a single index */
MATCH_OPT_RANGE, /* Record contains an index range */
MATCH_OPT_TYPE, /* Record contains a type (shdr or phdr) */
} match_opt_t;
typedef struct _match {
struct _match *next; /* Pointer to next item in list */
match_opt_t opt_type;
union {
const char *name; /* MATCH_OPT_NAME */
struct { /* MATCH_OPT_NDX and MATCH_OPT_RANGE */
int start;
int end; /* Only for MATCH_OPT_RANGE */
} ndx;
uint32_t type; /* MATCH_OPT_TYPE */
} value;
} match_rec_t;
static struct {
match_item_t item_type; /* Type of item being matched */
match_rec_t *list; /* Records for (-I, -N, -T) options */
} match_state;
const char *
_elfdump_msg(Msg mid)
{
return (gettext(MSG_ORIG(mid)));
}
/*
* Determine whether a symbol name should be demangled.
*/
const char *
demangle(const char *name, uint_t flags)
{
if (flags & FLG_CTL_DEMANGLE)
return (Elf_demangle_name(name));
else
return ((char *)name);
}
/*
* Define our own standard error routine.
*/
void
failure(const char *file, const char *func)
{
(void) fprintf(stderr, MSG_INTL(MSG_ERR_FAILURE),
file, func, elf_errmsg(elf_errno()));
}
/*
* The full usage message
*/
static void
detail_usage()
{
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL1));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL2));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL3));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL4));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL5));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL6));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL7));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL8));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL9));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL10));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL11));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL12));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL13));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL14));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL15));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL16));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL17));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL18));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL19));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL20));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL21));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL22));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL23));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL24));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL25));
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_DETAIL26));
}
/*
* Output a block of raw data as hex bytes. Each row is given
* the index of the first byte in the row.
*
* entry:
* data - Pointer to first byte of data to be displayed
* n - # of bytes of data
* bytes_per_col - # of space separated bytes to output in each column.
* col_per_row - # of columns to output per row
*
* exit:
* The formatted data has been sent to stdout.
*/
typedef struct {
uint_t dd_indent;
} dump_data_t;
static int
dump_hex_bytes_cb(void *arg, uint64_t addr, const char *str,
size_t len __unused)
{
char index[MAXNDXSIZE];
dump_data_t *dd = arg;
size_t index_width;
(void) snprintf(index, sizeof (index), MSG_ORIG(MSG_FMT_INDEX2),
EC_WORD(addr));
index_width = strlen(index);
index_width = S_ROUND(index_width, 8);
dbg_print(0, MSG_ORIG(MSG_HEXDUMP_ROW),
dd->dd_indent, MSG_ORIG(MSG_STR_EMPTY),
index_width, index, str);
return (0);
}
void
dump_hex_bytes(const void *data, size_t n, int indent, int bytes_per_col,
int col_per_row)
{
hexdump_t h;
dump_data_t dd = {
.dd_indent = indent
};
hexdump_init(&h);
hexdump_set_grouping(&h, bytes_per_col);
hexdump_set_width(&h, bytes_per_col * col_per_row);
(void) hexdumph(&h, data, n, HDF_DOUBLESPACE, dump_hex_bytes_cb, &dd);
hexdump_fini(&h);
}
/*
* Convert the ASCII representation of an index, or index range, into
* binary form, and store it in rec:
*
* index: An positive or 0 valued integer
* range: Two indexes, separated by a ':' character, denoting
* a range of allowed values. If the second value is omitted,
* any values equal to or greater than the first will match.
*
* exit:
* On success, *rec is filled in with a MATCH_OPT_NDX or MATCH_OPT_RANGE
* value, and this function returns (1). On failure, the contents
* of *rec are undefined, and (0) is returned.
*/
int
process_index_opt(const char *str, match_rec_t *rec)
{
#define SKIP_BLANK for (; *str && isspace(*str); str++)
char *endptr;
rec->value.ndx.start = strtol(str, &endptr, 10);
/* Value must use some of the input, and be 0 or positive */
if ((str == endptr) || (rec->value.ndx.start < 0))
return (0);
str = endptr;
SKIP_BLANK;
if (*str != ':') {
rec->opt_type = MATCH_OPT_NDX;
} else {
str++; /* Skip the ':' */
rec->opt_type = MATCH_OPT_RANGE;
SKIP_BLANK;
if (*str == '\0') {
rec->value.ndx.end = -1; /* Indicates "to end" */
} else {
rec->value.ndx.end = strtol(str, &endptr, 10);
if ((str == endptr) || (rec->value.ndx.end < 0))
return (0);
str = endptr;
SKIP_BLANK;
}
}
/* Syntax error if anything is left over */
if (*str != '\0')
return (0);
return (1);
#undef SKIP_BLANK
}
/*
* Convert a string containing a specific type of ELF constant, or an ASCII
* representation of a number, to an integer. Strings starting with '0'
* are taken to be octal, those staring with '0x' are hex, and all
* others are decimal.
*
* entry:
* str - String to be converted
* ctype - Constant type
* v - Address of variable to receive resulting value.
*
* exit:
* On success, returns True (1) and *v is set to the value.
* On failure, returns False (0) and *v is undefined.
*/
typedef enum {
ATOUI_PT,
ATOUI_SHT,
ATOUI_OSABI
} atoui_type_t;
static int
atoui(const char *str, atoui_type_t type, uint32_t *v)
{
conv_strtol_uvalue_t uvalue;
char *endptr;
if (conv_iter_strtol_init(str, &uvalue) != 0) {
switch (type) {
case ATOUI_PT:
if (conv_iter_phdr_type(CONV_OSABI_ALL, CONV_FMT_ALT_CF,
conv_iter_strtol, &uvalue) == CONV_ITER_DONE)
break;
(void) conv_iter_phdr_type(CONV_OSABI_ALL,
CONV_FMT_ALT_NF, conv_iter_strtol, &uvalue);
break;
case ATOUI_SHT:
if (conv_iter_sec_type(CONV_OSABI_ALL, CONV_MACH_ALL,
CONV_FMT_ALT_CF, conv_iter_strtol, &uvalue) ==
CONV_ITER_DONE)
break;
(void) conv_iter_sec_type(CONV_OSABI_ALL, CONV_MACH_ALL,
CONV_FMT_ALT_NF, conv_iter_strtol, &uvalue);
break;
case ATOUI_OSABI:
if (conv_iter_ehdr_osabi(CONV_FMT_ALT_CF,
conv_iter_strtol, &uvalue) == CONV_ITER_DONE)
break;
(void) conv_iter_ehdr_osabi(CONV_FMT_ALT_NF,
conv_iter_strtol, &uvalue);
break;
}
if (uvalue.csl_found) {
*v = uvalue.csl_value;
return (1);
}
}
*v = strtoull(str, &endptr, 0);
/* If the left over part contains anything but whitespace, fail */
for (; *endptr; endptr++)
if (!isspace(*endptr))
return (0);
return (1);
}
/*
* Called after getopt() processing is finished if there is a non-empty
* match list. Prepares the matching code for use.
*
* exit:
* Returns True (1) if no errors are encountered. Writes an
* error string to stderr and returns False (0) otherwise.
*/
static int
match_prepare(char *argv0, uint_t flags)
{
match_rec_t *list;
const char *str;
int minus_p = (flags & FLG_SHOW_PHDR) != 0;
atoui_type_t atoui_type;
/*
* Flag ambiguous attempt to use match option with both -p and
* and one or more section SHOW options. In this case, we
* can't tell what type of item we're supposed to match against.
*/
if (minus_p && (flags & FLG_MASK_SHOW_SHDR)) {
(void) fprintf(stderr, MSG_INTL(MSG_ERR_AMBIG_MATCH),
basename(argv0));
return (0);
}
/* Set the match type, based on the presence of the -p option */
if (minus_p) {
match_state.item_type = MATCH_ITEM_PT;
atoui_type = ATOUI_PT;
} else {
match_state.item_type = MATCH_ITEM_SHT;
atoui_type = ATOUI_SHT;
}
/*
* Scan match list and perform any necessary fixups:
*
* MATCH_OPT_NAME: If -p is specified, convert MATCH_OPT_NAME (-N)
* requests into MATCH_OPT_TYPE (-T).
*
* MATCH_OPT_TYPE: Now that we know item type we are matching
* against, we can convert the string saved in the name
* field during getopt() processing into an integer and
* write it into the type field.
*/
for (list = match_state.list; list; list = list->next) {
if ((list->opt_type == MATCH_OPT_NAME) && minus_p)
list->opt_type = MATCH_OPT_TYPE;
if (list->opt_type != MATCH_OPT_TYPE)
continue;
str = list->value.name;
if (atoui(str, atoui_type, &list->value.type) == 0) {
const char *fmt = minus_p ?
MSG_INTL(MSG_ERR_BAD_T_PT) :
MSG_INTL(MSG_ERR_BAD_T_SHT);
(void) fprintf(stderr, fmt, basename(argv0), str);
return (0);
}
}
return (1);
}
/*
* Returns True (1) if the item with the given name or index should
* be displayed, and False (0) if it should not be.
*
* entry:
* match_flags - Bitmask specifying matching options, as described
* in _elfdump.h.
* name - If MATCH_F_NAME flag is set, name of item under
* consideration. Otherwise ignored.
* should not be considered.
* ndx - If MATCH_F_NDX flag is set, index of item under consideration.
* type - If MATCH_F_TYPE is set, type of item under consideration.
* If MATCH_F_PHDR is set, this would be a program
* header type (PT_). Otherwise, a section header type (SHT_).
*
* exit:
* True will be returned if the given name/index matches those given
* by one of the (-I, -N -T) command line options, or if no such option
* was used in the command invocation and MATCH_F_STRICT is not
* set.
*/
int
match(match_flags_t match_flags, const char *name, uint_t ndx, uint_t type)
{
match_item_t item_type = (match_flags & MATCH_F_PHDR) ?
MATCH_ITEM_PT : MATCH_ITEM_SHT;
match_rec_t *list;
/*
* If there is no match list, then we use the MATCH_F_STRICT
* flag to decide what to return. In the strict case, we return
* False (0), in the normal case, True (1).
*/
if (match_state.list == NULL)
return ((match_flags & MATCH_F_STRICT) == 0);
/*
* If item being checked is not the current match type,
* then allow it.
*/
if (item_type != match_state.item_type)
return (1);
/* Run through the match records and check for a hit */
for (list = match_state.list; list; list = list->next) {
switch (list->opt_type) {
case MATCH_OPT_NAME:
if (((match_flags & MATCH_F_NAME) == 0) ||
(name == NULL))
break;
if (strcmp(list->value.name, name) == 0)
return (1);
break;
case MATCH_OPT_NDX:
if ((match_flags & MATCH_F_NDX) &&
(ndx == list->value.ndx.start))
return (1);
break;
case MATCH_OPT_RANGE:
/*
* A range end value less than 0 means that any value
* above the start is acceptible.
*/
if ((match_flags & MATCH_F_NDX) &&
(ndx >= list->value.ndx.start) &&
((list->value.ndx.end < 0) ||
(ndx <= list->value.ndx.end)))
return (1);
break;
case MATCH_OPT_TYPE:
if ((match_flags & MATCH_F_TYPE) &&
(type == list->value.type))
return (1);
break;
}
}
/* Nothing matched */
return (0);
}
/*
* Add an entry to match_state.list for use by match(). This routine is for
* use during getopt() processing. It should not be called once
* match_prepare() has been called.
*
* Return True (1) for success. On failure, an error is written
* to stderr, and False (0) is returned.
*/
static int
add_match_record(char *argv0, match_rec_t *data)
{
match_rec_t *rec;
match_rec_t *list;
if ((rec = malloc(sizeof (*rec))) == NULL) {
int err = errno;
(void) fprintf(stderr, MSG_INTL(MSG_ERR_MALLOC),
basename(argv0), strerror(err));
return (0);
}
*rec = *data;
/* Insert at end of match_state.list */
if (match_state.list == NULL) {
match_state.list = rec;
} else {
for (list = match_state.list; list->next != NULL;
list = list->next)
;
list->next = rec;
}
rec->next = NULL;
return (1);
}
static int
decide(const char *file, int fd, Elf *elf, uint_t flags,
const char *wname, int wfd, uchar_t osabi)
{
int r;
if (gelf_getclass(elf) == ELFCLASS64)
r = regular64(file, fd, elf, flags, wname, wfd, osabi);
else
r = regular32(file, fd, elf, flags, wname, wfd, osabi);
return (r);
}
static int
archive(const char *file, int fd, Elf *elf, uint_t flags,
const char *wname, int wfd, uchar_t osabi)
{
Elf_Cmd cmd = ELF_C_READ;
Elf_Arhdr *arhdr;
Elf *_elf = NULL;
size_t ptr;
Elf_Arsym *arsym = NULL;
/*
* Determine if the archive symbol table itself is required.
*/
if ((flags & FLG_SHOW_SYMBOLS) &&
match(MATCH_F_NAME, MSG_ORIG(MSG_ELF_ARSYM), 0, 0)) {
/*
* Get the archive symbol table.
*/
if (((arsym = elf_getarsym(elf, &ptr)) == 0) && elf_errno()) {
/*
* The arsym could be 0 even though there was no error.
* Print the error message only when there was
* real error from elf_getarsym().
*/
failure(file, MSG_ORIG(MSG_ELF_GETARSYM));
return (0);
}
}
/*
* Print the archive symbol table only when the archive symbol
* table exists and it was requested to print.
*/
if (arsym) {
size_t cnt;
char index[MAXNDXSIZE];
size_t offset = 0, _offset = 0;
const char *fmt_arsym1, *fmt_arsym2;
/*
* Print out all the symbol entries. The format width used
* corresponds to whether the archive symbol table is 32
* or 64-bit. We see them via Elf_Arhdr as size_t values
* in either case with no information loss (see the comments
* in libelf/getarsym.c) so this is done simply to improve
* the user presentation.
*/
if (_elf_getarsymwordsize(elf) == 8) {
dbg_print(0, MSG_INTL(MSG_ARCHIVE_SYMTAB_64));
dbg_print(0, MSG_INTL(MSG_ARCHIVE_FIELDS_64));
fmt_arsym1 = MSG_ORIG(MSG_FMT_ARSYM1_64);
fmt_arsym2 = MSG_ORIG(MSG_FMT_ARSYM2_64);
} else {
dbg_print(0, MSG_INTL(MSG_ARCHIVE_SYMTAB_32));
dbg_print(0, MSG_INTL(MSG_ARCHIVE_FIELDS_32));
fmt_arsym1 = MSG_ORIG(MSG_FMT_ARSYM1_32);
fmt_arsym2 = MSG_ORIG(MSG_FMT_ARSYM2_32);
}
for (cnt = 0; cnt < ptr; cnt++, arsym++) {
/*
* For each object obtain an elf descriptor so that we
* can establish the members name. Note, we have had
* archives where the archive header has not been
* obtainable so be lenient with errors.
*/
if ((offset == 0) || ((arsym->as_off != 0) &&
(arsym->as_off != _offset))) {
if (_elf)
(void) elf_end(_elf);
if (elf_rand(elf, arsym->as_off) !=
arsym->as_off) {
failure(file, MSG_ORIG(MSG_ELF_RAND));
arhdr = NULL;
} else if ((_elf = elf_begin(fd,
ELF_C_READ, elf)) == 0) {
failure(file, MSG_ORIG(MSG_ELF_BEGIN));
arhdr = NULL;
} else if ((arhdr = elf_getarhdr(_elf)) == 0) {
failure(file,
MSG_ORIG(MSG_ELF_GETARHDR));
arhdr = NULL;
}
_offset = arsym->as_off;
if (offset == 0)
offset = _offset;
}
(void) snprintf(index, MAXNDXSIZE,
MSG_ORIG(MSG_FMT_INDEX), EC_XWORD(cnt));
if (arsym->as_off)
dbg_print(0, fmt_arsym1, index,
EC_XWORD(arsym->as_off),
arhdr ? arhdr->ar_name :
MSG_INTL(MSG_STR_UNKNOWN), (arsym->as_name ?
demangle(arsym->as_name, flags) :
MSG_INTL(MSG_STR_NULL)));
else
dbg_print(0, fmt_arsym2, index,
EC_XWORD(arsym->as_off));
}
if (_elf)
(void) elf_end(_elf);
/*
* If we only need the archive symbol table return.
*/
if ((flags & FLG_SHOW_SYMBOLS) &&
match(MATCH_F_STRICT | MATCH_F_NAME,
MSG_ORIG(MSG_ELF_ARSYM), -1, -1))
return (0);
/*
* Reset elf descriptor in preparation for processing each
* member.
*/
if (offset)
(void) elf_rand(elf, offset);
}
/*
* Process each object within the archive.
*/
while ((_elf = elf_begin(fd, cmd, elf)) != NULL) {
char name[MAXPATHLEN];
if ((arhdr = elf_getarhdr(_elf)) == NULL) {
failure(file, MSG_ORIG(MSG_ELF_GETARHDR));
return (0);
}
if (*arhdr->ar_name != '/') {
(void) snprintf(name, MAXPATHLEN,
MSG_ORIG(MSG_FMT_ARNAME), file, arhdr->ar_name);
dbg_print(0, MSG_ORIG(MSG_FMT_NLSTR), name);
switch (elf_kind(_elf)) {
case ELF_K_AR:
if (archive(name, fd, _elf, flags,
wname, wfd, osabi) == 1)
return (1);
break;
case ELF_K_ELF:
if (decide(name, fd, _elf, flags,
wname, wfd, osabi) == 1)
return (1);
break;
default:
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BADFILE), name);
break;
}
}
cmd = elf_next(_elf);
(void) elf_end(_elf);
}
return (0);
}
int
main(int argc, char **argv, char **envp)
{
Elf *elf;
int var, fd, wfd = 0;
char *wname = NULL;
uint_t flags = 0;
match_rec_t match_data;
int ret;
uchar_t osabi = ELFOSABI_NONE;
/*
* Establish locale.
*/
(void) setlocale(LC_MESSAGES, MSG_ORIG(MSG_STR_EMPTY));
(void) textdomain(MSG_ORIG(MSG_SUNW_OST_SGS));
(void) setvbuf(stdout, NULL, _IOLBF, 0);
(void) setvbuf(stderr, NULL, _IOLBF, 0);
opterr = 0;
while ((var = getopt(argc, argv, MSG_ORIG(MSG_STR_OPTIONS))) != EOF) {
switch (var) {
case 'C':
flags |= FLG_CTL_DEMANGLE;
break;
case 'c':
flags |= FLG_SHOW_SHDR;
break;
case 'd':
flags |= FLG_SHOW_DYNAMIC;
break;
case 'e':
flags |= FLG_SHOW_EHDR;
break;
case 'G':
flags |= FLG_SHOW_GOT;
break;
case 'g':
flags |= FLG_SHOW_GROUP;
break;
case 'H':
flags |= FLG_SHOW_CAP;
break;
case 'h':
flags |= FLG_SHOW_HASH;
break;
case 'I':
if (!process_index_opt(optarg, &match_data))
goto usage_brief;
if (!add_match_record(argv[0], &match_data))
return (1);
flags |= FLG_CTL_MATCH;
break;
case 'i':
flags |= FLG_SHOW_INTERP;
break;
case 'k':
flags |= FLG_CALC_CHECKSUM;
break;
case 'l':
flags |= FLG_CTL_LONGNAME;
break;
case 'm':
flags |= FLG_SHOW_MOVE;
break;
case 'N':
match_data.opt_type = MATCH_OPT_NAME;
match_data.value.name = optarg;
if (!add_match_record(argv[0], &match_data))
return (1);
flags |= FLG_CTL_MATCH;
break;
case 'n':
flags |= FLG_SHOW_NOTE;
break;
case 'O':
{
uint32_t val;
/*
* osabi is a uchar_t in the ELF header.
* Don't accept any value that exceeds
* that range.
*/
if ((atoui(optarg, ATOUI_OSABI, &val) == 0) ||
(val > 255)) {
(void) fprintf(stderr,
MSG_INTL(MSG_ERR_BAD_T_OSABI),
basename(argv[0]), optarg);
return (1);
}
osabi = val;
}
flags |= FLG_CTL_OSABI;
break;
case 'P':
flags |= FLG_CTL_FAKESHDR;
break;
case 'p':
flags |= FLG_SHOW_PHDR;
break;
case 'r':
flags |= FLG_SHOW_RELOC;
break;
case 'S':
flags |= FLG_SHOW_SORT;
break;
case 's':
flags |= FLG_SHOW_SYMBOLS;
break;
case 'T':
/*
* We can't evaluate the value yet, because
* we need to know if -p is used or not in
* order to tell if we're seeing section header
* or program header types. So, we save the
* string in the name field, and then convert
* it to a type integer in a following pass.
*/
match_data.opt_type = MATCH_OPT_TYPE;
match_data.value.name = optarg;
if (!add_match_record(argv[0], &match_data))
return (1);
flags |= FLG_CTL_MATCH;
break;
case 'u':
flags |= FLG_SHOW_UNWIND;
break;
case 'v':
flags |= FLG_SHOW_VERSIONS;
break;
case 'w':
wname = optarg;
break;
case 'y':
flags |= FLG_SHOW_SYMINFO;
break;
case '?':
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_BRIEF),
basename(argv[0]));
detail_usage();
return (1);
default:
break;
}
}
/* -p and -w are mutually exclusive. -w only works with sections */
if (((flags & FLG_SHOW_PHDR) != 0) && (wname != NULL))
goto usage_brief;
/* If a match argument is present, prepare the match state */
if ((match_state.list != NULL) && (match_prepare(argv[0], flags) == 0))
return (1);
/*
* Decide what to do if no options specifying something to
* show or do are present.
*
* If there is no -w and no match options, then we will set all
* the show flags, causing a full display of everything in the
* file that we know how to handle.
*
* Otherwise, if there is no match list, we generate a usage
* error and quit.
*
* In the case where there is a match list, we go ahead and call
* regular() anyway, leaving it to decide what to do. If -w is
* present, regular() will use the match list to handle it.
* In addition, in the absence of explicit show/calc flags, regular()
* will compare the section headers to the match list and use
* that to generate the FLG_ bits that will display the information
* specified by the match list.
*/
if ((flags & ~FLG_MASK_CTL) == 0) {
if (!wname && (match_state.list == NULL))
flags |= FLG_MASK_SHOW;
else if (match_state.list == NULL)
goto usage_brief;
}
/* There needs to be at least 1 filename left following the options */
if ((var = argc - optind) == 0)
goto usage_brief;
/*
* If the -l/-C option is specified, set up the liblddbg.so.
*/
if (flags & FLG_CTL_LONGNAME)
dbg_desc->d_extra |= DBG_E_LONG;
if (flags & FLG_CTL_DEMANGLE)
dbg_desc->d_extra |= DBG_E_DEMANGLE;
/*
* If the -w option has indicated an output file open it. It's
* arguable whether this option has much use when multiple files are
* being processed.
*
* If wname is non-NULL, we know that -p was not specified, due
* to the test above.
*/
if (wname) {
if ((wfd = open(wname, (O_RDWR | O_CREAT | O_TRUNC),
0666)) < 0) {
int err = errno;
(void) fprintf(stderr, MSG_INTL(MSG_ERR_OPEN),
wname, strerror(err));
return (1);
}
}
/*
* Open the input file, initialize the elf interface, and
* process it.
*/
ret = 0;
for (; (optind < argc) && (ret == 0); optind++) {
const char *file = argv[optind];
if ((fd = open(argv[optind], O_RDONLY)) == -1) {
int err = errno;
(void) fprintf(stderr, MSG_INTL(MSG_ERR_OPEN),
file, strerror(err));
continue;
}
(void) elf_version(EV_CURRENT);
if ((elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL) {
failure(file, MSG_ORIG(MSG_ELF_BEGIN));
(void) close(fd);
continue;
}
if (var > 1)
dbg_print(0, MSG_ORIG(MSG_FMT_NLSTRNL), file);
switch (elf_kind(elf)) {
case ELF_K_AR:
ret = archive(file, fd, elf, flags, wname, wfd, osabi);
break;
case ELF_K_ELF:
ret = decide(file, fd, elf, flags, wname, wfd, osabi);
break;
default:
(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADFILE), file);
break;
}
(void) close(fd);
(void) elf_end(elf);
}
if (wfd)
(void) close(wfd);
return (ret);
usage_brief:
/* Control comes here for a simple usage message and exit */
(void) fprintf(stderr, MSG_INTL(MSG_USAGE_BRIEF),
basename(argv[0]));
return (1);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <msg.h>
#include <_elfdump.h>
#include <struct_layout.h>
#include <conv.h>
/*
* Functions for extracting and formatting numeric values from
* structure data.
*/
/*
* Extract the integral field into the value union given and
* perform any necessary byte swapping to make the result readable
* on the elfdump host.
*/
void
sl_extract_num_field(const char *data, int do_swap, const sl_field_t *fdesc,
sl_data_t *field_data)
{
/* Copy the value bytes into our union */
(void) memcpy(field_data, data + fdesc->slf_offset,
fdesc->slf_eltlen);
/* Do byte swapping as necessary */
if (do_swap) {
switch (fdesc->slf_eltlen) {
case 2:
field_data->sld_ui16 = BSWAP_HALF(field_data->sld_ui16);
break;
case 4:
field_data->sld_ui32 = BSWAP_WORD(field_data->sld_ui32);
break;
case 8:
field_data->sld_ui64 =
BSWAP_LWORD(field_data->sld_ui64);
break;
}
}
}
/*
* Extract the given integer field, and return its value, cast
* to Word. Note that this operation must not be used on values
* that can be negative, or larger than 32-bits, as information
* can be lost.
*/
Word
sl_extract_as_word(const char *data, int do_swap, const sl_field_t *fdesc)
{
sl_data_t v;
/* Extract the value from the raw data */
sl_extract_num_field(data, do_swap, fdesc, &v);
if (fdesc->slf_sign) {
switch (fdesc->slf_eltlen) {
case 1:
return ((Word) v.sld_i8);
case 2:
return ((Word) v.sld_i16);
case 4:
return ((Word) v.sld_i32);
case 8:
return ((Word) v.sld_i64);
}
} else {
switch (fdesc->slf_eltlen) {
case 1:
return ((Word) v.sld_ui8);
case 2:
return ((Word) v.sld_ui16);
case 4:
return ((Word) v.sld_ui32);
case 8:
return ((Word) v.sld_ui64);
}
}
/* This should not be reached */
assert(0);
return (0);
}
/*
* Extract the given integer field, and return its value, cast
* to Lword. Note that this operation must not be used on values
* that can be negative, as information can be lost.
*/
Lword
sl_extract_as_lword(const char *data, int do_swap, const sl_field_t *fdesc)
{
sl_data_t v;
/* Extract the value from the raw data */
sl_extract_num_field(data, do_swap, fdesc, &v);
if (fdesc->slf_sign) {
switch (fdesc->slf_eltlen) {
case 1:
return ((Lword) v.sld_i8);
case 2:
return ((Lword) v.sld_i16);
case 4:
return ((Lword) v.sld_i32);
case 8:
return ((Lword) v.sld_i64);
}
} else {
switch (fdesc->slf_eltlen) {
case 1:
return ((Lword) v.sld_ui8);
case 2:
return ((Lword) v.sld_ui16);
case 4:
return ((Lword) v.sld_ui32);
case 8:
return ((Lword) v.sld_ui64);
}
}
/* This should not be reached */
assert(0);
return (0);
}
/*
* Extract the given integer field, and return its value, cast
* to int32_t. Note that this operation must not be used on unsigned
* values larger than 31-bits, or on signed values larger than 32-bits,
* as information can be lost.
*/
Sword
sl_extract_as_sword(const char *data, int do_swap, const sl_field_t *fdesc)
{
sl_data_t v;
/* Extract the value from the raw data */
sl_extract_num_field(data, do_swap, fdesc, &v);
if (fdesc->slf_sign) {
switch (fdesc->slf_eltlen) {
case 1:
return ((Sword)v.sld_i8);
case 2:
return ((Sword)v.sld_i16);
case 4:
return ((Sword)v.sld_i32);
case 8:
return ((Sword)v.sld_i64);
}
} else {
switch (fdesc->slf_eltlen) {
case 1:
return ((Sword)v.sld_ui8);
case 2:
return ((Sword)v.sld_ui16);
case 4:
return ((Sword)v.sld_ui32);
case 8:
return ((Sword)v.sld_ui64);
}
}
/* This should not be reached */
assert(0);
return (0);
}
/*
* Extract the integral field and format it into the supplied buffer.
*/
const char *
sl_fmt_num(const char *data, int do_swap, const sl_field_t *fdesc,
sl_fmt_num_t fmt_type, sl_fmtbuf_t buf)
{
/*
* These static arrays are indexed by [fdesc->slf_sign][fmt_type]
* to get a format string to use for the specified combination.
*/
static const char *fmt_i8[2][3] = {
{
MSG_ORIG(MSG_CNOTE_FMT_U),
MSG_ORIG(MSG_CNOTE_FMT_X),
MSG_ORIG(MSG_CNOTE_FMT_Z2X)
},
{
MSG_ORIG(MSG_CNOTE_FMT_D),
MSG_ORIG(MSG_CNOTE_FMT_X),
MSG_ORIG(MSG_CNOTE_FMT_Z2X)
}
};
static const char *fmt_i16[2][3] = {
{
MSG_ORIG(MSG_CNOTE_FMT_U),
MSG_ORIG(MSG_CNOTE_FMT_X),
MSG_ORIG(MSG_CNOTE_FMT_Z4X)
},
{
MSG_ORIG(MSG_CNOTE_FMT_D),
MSG_ORIG(MSG_CNOTE_FMT_X),
MSG_ORIG(MSG_CNOTE_FMT_Z4X)
}
};
static const char *fmt_i32[2][3] = {
{
MSG_ORIG(MSG_CNOTE_FMT_U),
MSG_ORIG(MSG_CNOTE_FMT_X),
MSG_ORIG(MSG_CNOTE_FMT_Z8X)
},
{
MSG_ORIG(MSG_CNOTE_FMT_D),
MSG_ORIG(MSG_CNOTE_FMT_X),
MSG_ORIG(MSG_CNOTE_FMT_Z8X)
}
};
static const char *fmt_i64[2][3] = {
{
MSG_ORIG(MSG_CNOTE_FMT_LLU),
MSG_ORIG(MSG_CNOTE_FMT_LLX),
MSG_ORIG(MSG_CNOTE_FMT_Z16LLX)
},
{
MSG_ORIG(MSG_CNOTE_FMT_LLD),
MSG_ORIG(MSG_CNOTE_FMT_LLX),
MSG_ORIG(MSG_CNOTE_FMT_Z16LLX)
}
};
sl_data_t v;
/* Extract the value from the raw data */
sl_extract_num_field(data, do_swap, fdesc, &v);
/*
* Format into the buffer. Note that we depend on the signed
* and unsigned versions of each width being equivalent as long
* as the format specifies the proper formatting.
*/
switch (fdesc->slf_eltlen) {
case 1:
(void) snprintf(buf, sizeof (sl_fmtbuf_t),
fmt_i8[fdesc->slf_sign][fmt_type], (uint32_t)v.sld_ui8);
break;
case 2:
(void) snprintf(buf, sizeof (sl_fmtbuf_t),
fmt_i16[fdesc->slf_sign][fmt_type], (uint32_t)v.sld_ui16);
break;
case 4:
(void) snprintf(buf, sizeof (sl_fmtbuf_t),
fmt_i32[fdesc->slf_sign][fmt_type], v.sld_ui32);
break;
case 8:
(void) snprintf(buf, sizeof (sl_fmtbuf_t),
fmt_i64[fdesc->slf_sign][fmt_type], v.sld_ui64);
break;
}
return (buf);
}
/*
* Return structure layout definition for the given machine type,
* or NULL if the specified machine is not supported.
*/
const sl_arch_layout_t *
sl_mach(Half mach)
{
switch (mach) {
case EM_386:
return (struct_layout_i386());
case EM_AMD64:
return (struct_layout_amd64());
}
/* Unsupported architecture */
return (NULL);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 2012 DEY Storage Systems, Inc. All rights reserved.
* Copyright 2018 Joyent, Inc.
* Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
*/
#ifndef _STRUCT_LAYOUT_H
#define _STRUCT_LAYOUT_H
#include <conv.h>
#include <_machelf.h>
/*
* Local include file for elfdump, used to define structure layout
* definitions for various system structs.
*/
#ifdef __cplusplus
extern "C" {
#endif
/*
* illumos defines system structs that elfdump needs to display
* data from. We have a variety of hurdles to overcome in doing this:
*
* - The size of system types can differ between ELFCLASS32 and
* ELFCLASS64.
* - Stucture layout can differ between architectures, so a given
* field can have a different struct offset than is native
* for the system running elfdump. Depending on the struct
* in question, the layout for one platform may be impossible
* to achieve on another.
* - The byte order of the core object can differ from that
* of the system running elfdump.
*
* The result is that in the fully general case, each architecture
* can have a slightly different definition of these structures.
* The usual approach of assigning a pointer of the desired structure
* type and then accessing fields through that pointer cannot be used
* here. That approach can only be used to access structures with the
* native layout of the elfdump host. We want any instance of elfdump
* to be able to examine a Solaris object for any supported architecture,
* so we need a more flexible approach.
*
* The solution to this problem lies in the fact that the binary
* layout of these public types cannot be changed, except in backward
* compatible ways. They are written to core files or published in
* other ways such that we can't make changes that would make it
* impossible to analyze old files. This means that we can build
* table of offsets and sizes for each field of each struct, on
* a per-archecture basis. These tables can be used to access the
* struct fields directly from the note desc data, and elfdump
* on any host can read the data from any other host.
*
* When reading these tables, it can be very helpful to examine
* the struct definition at the same time.
*/
/*
* sl_field_t is used to describe a struct field
*/
typedef struct {
ushort_t slf_offset; /* Offset from start of struct */
ushort_t slf_eltlen; /* Size of datum, in bytes */
ushort_t slf_nelts; /* 0 for scalar, # of els for array */
uchar_t slf_sign; /* True (1) if signed quantity */
} sl_field_t;
/*
* This type is used to extract and manipulate data described by
* sl_field_t. We rely on the C guarantee that all the fields in
* a union have offset 0.
*/
typedef union {
char sld_i8;
uchar_t sld_ui8;
short sld_i16;
ushort_t sld_ui16;
int32_t sld_i32;
uint32_t sld_ui32;
int64_t sld_i64;
uint64_t sld_ui64;
} sl_data_t;
/*
* Buffer large enough to format any integral value in a field
*/
typedef char sl_fmtbuf_t[CONV_INV_BUFSIZE * 2];
/*
* Types of formatting done by fmt_num()
*/
typedef enum {
SL_FMT_NUM_DEC = 0, /* Decimal integer */
SL_FMT_NUM_HEX = 1, /* Hex integer, with natural width */
SL_FMT_NUM_ZHEX = 2, /* Hex integer, fixed width with zero fill */
} sl_fmt_num_t;
/*
* Layout description of auxv_t, from <sys/auxv.h>.
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t a_type;
sl_field_t a_val;
sl_field_t a_ptr;
sl_field_t a_fcn;
} sl_auxv_layout_t;
/*
* Layout description of prgregset_t, an architecture specific
* array of general register c values
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t elt0;
} sl_prgregset_layout_t;
/*
* Layout description of lwpstatus_t, from <sys/procfs.h>.
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t pr_flags;
sl_field_t pr_lwpid;
sl_field_t pr_why;
sl_field_t pr_what;
sl_field_t pr_cursig;
sl_field_t pr_info;
sl_field_t pr_lwppend;
sl_field_t pr_lwphold;
sl_field_t pr_action;
sl_field_t pr_altstack;
sl_field_t pr_oldcontext;
sl_field_t pr_syscall;
sl_field_t pr_nsysarg;
sl_field_t pr_errno;
sl_field_t pr_sysarg;
sl_field_t pr_rval1;
sl_field_t pr_rval2;
sl_field_t pr_clname;
sl_field_t pr_tstamp;
sl_field_t pr_utime;
sl_field_t pr_stime;
sl_field_t pr_errpriv;
sl_field_t pr_ustack;
sl_field_t pr_instr;
sl_field_t pr_reg;
sl_field_t pr_fpreg;
} sl_lwpstatus_layout_t;
/*
* Layout description of pstatus_t, from <sys/procfs.h>.
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t pr_flags;
sl_field_t pr_nlwp;
sl_field_t pr_pid;
sl_field_t pr_ppid;
sl_field_t pr_pgid;
sl_field_t pr_sid;
sl_field_t pr_aslwpid;
sl_field_t pr_agentid;
sl_field_t pr_sigpend;
sl_field_t pr_brkbase;
sl_field_t pr_brksize;
sl_field_t pr_stkbase;
sl_field_t pr_stksize;
sl_field_t pr_utime;
sl_field_t pr_stime;
sl_field_t pr_cutime;
sl_field_t pr_cstime;
sl_field_t pr_sigtrace;
sl_field_t pr_flttrace;
sl_field_t pr_sysentry;
sl_field_t pr_sysexit;
sl_field_t pr_dmodel;
sl_field_t pr_taskid;
sl_field_t pr_projid;
sl_field_t pr_nzomb;
sl_field_t pr_zoneid;
sl_field_t pr_lwp;
} sl_pstatus_layout_t;
/*
* Layout description of prstatus_t, from <sys/old_procfs.h>.
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t pr_flags;
sl_field_t pr_why;
sl_field_t pr_what;
sl_field_t pr_info;
sl_field_t pr_cursig;
sl_field_t pr_nlwp;
sl_field_t pr_sigpend;
sl_field_t pr_sighold;
sl_field_t pr_altstack;
sl_field_t pr_action;
sl_field_t pr_pid;
sl_field_t pr_ppid;
sl_field_t pr_pgrp;
sl_field_t pr_sid;
sl_field_t pr_utime;
sl_field_t pr_stime;
sl_field_t pr_cutime;
sl_field_t pr_cstime;
sl_field_t pr_clname;
sl_field_t pr_syscall;
sl_field_t pr_nsysarg;
sl_field_t pr_sysarg;
sl_field_t pr_who;
sl_field_t pr_lwppend;
sl_field_t pr_oldcontext;
sl_field_t pr_brkbase;
sl_field_t pr_brksize;
sl_field_t pr_stkbase;
sl_field_t pr_stksize;
sl_field_t pr_processor;
sl_field_t pr_bind;
sl_field_t pr_instr;
sl_field_t pr_reg;
} sl_prstatus_layout_t;
/*
* Layout description of psinfo_t, from <sys/procfs.h>.
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t pr_flag;
sl_field_t pr_nlwp;
sl_field_t pr_pid;
sl_field_t pr_ppid;
sl_field_t pr_pgid;
sl_field_t pr_sid;
sl_field_t pr_uid;
sl_field_t pr_euid;
sl_field_t pr_gid;
sl_field_t pr_egid;
sl_field_t pr_addr;
sl_field_t pr_size;
sl_field_t pr_rssize;
sl_field_t pr_ttydev;
sl_field_t pr_pctcpu;
sl_field_t pr_pctmem;
sl_field_t pr_start;
sl_field_t pr_time;
sl_field_t pr_ctime;
sl_field_t pr_fname;
sl_field_t pr_psargs;
sl_field_t pr_wstat;
sl_field_t pr_argc;
sl_field_t pr_argv;
sl_field_t pr_envp;
sl_field_t pr_dmodel;
sl_field_t pr_taskid;
sl_field_t pr_projid;
sl_field_t pr_nzomb;
sl_field_t pr_poolid;
sl_field_t pr_zoneid;
sl_field_t pr_contract;
sl_field_t pr_lwp;
} sl_psinfo_layout_t;
/*
* Layout description of prpsinfo_t, from <sys/old_procfs.h>.
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t pr_state;
sl_field_t pr_sname;
sl_field_t pr_zomb;
sl_field_t pr_nice;
sl_field_t pr_flag;
sl_field_t pr_uid;
sl_field_t pr_gid;
sl_field_t pr_pid;
sl_field_t pr_ppid;
sl_field_t pr_pgrp;
sl_field_t pr_sid;
sl_field_t pr_addr;
sl_field_t pr_size;
sl_field_t pr_rssize;
sl_field_t pr_wchan;
sl_field_t pr_start;
sl_field_t pr_time;
sl_field_t pr_pri;
sl_field_t pr_oldpri;
sl_field_t pr_cpu;
sl_field_t pr_ottydev;
sl_field_t pr_lttydev;
sl_field_t pr_clname;
sl_field_t pr_fname;
sl_field_t pr_psargs;
sl_field_t pr_syscall;
sl_field_t pr_ctime;
sl_field_t pr_bysize;
sl_field_t pr_byrssize;
sl_field_t pr_argc;
sl_field_t pr_argv;
sl_field_t pr_envp;
sl_field_t pr_wstat;
sl_field_t pr_pctcpu;
sl_field_t pr_pctmem;
sl_field_t pr_euid;
sl_field_t pr_egid;
sl_field_t pr_aslwpid;
sl_field_t pr_dmodel;
} sl_prpsinfo_layout_t;
/*
* Layout description of lwpsinfo_t, from <sys/procfs.h>.
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t pr_flag;
sl_field_t pr_lwpid;
sl_field_t pr_addr;
sl_field_t pr_wchan;
sl_field_t pr_stype;
sl_field_t pr_state;
sl_field_t pr_sname;
sl_field_t pr_nice;
sl_field_t pr_syscall;
sl_field_t pr_oldpri;
sl_field_t pr_cpu;
sl_field_t pr_pri;
sl_field_t pr_pctcpu;
sl_field_t pr_start;
sl_field_t pr_time;
sl_field_t pr_clname;
sl_field_t pr_name;
sl_field_t pr_onpro;
sl_field_t pr_bindpro;
sl_field_t pr_bindpset;
sl_field_t pr_lgrp;
} sl_lwpsinfo_layout_t;
/*
* Layout description of prcred_t, from <sys/procfs.h>.
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t pr_euid;
sl_field_t pr_ruid;
sl_field_t pr_suid;
sl_field_t pr_egid;
sl_field_t pr_rgid;
sl_field_t pr_sgid;
sl_field_t pr_ngroups;
sl_field_t pr_groups;
} sl_prcred_layout_t;
/*
* Layout description of prpriv_t, from <sys/procfs.h>.
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t pr_nsets;
sl_field_t pr_setsize;
sl_field_t pr_infosize;
sl_field_t pr_sets;
} sl_prpriv_layout_t;
/*
* Layout description of priv_impl_info_t, from <sys/priv.h>.
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t priv_headersize;
sl_field_t priv_flags;
sl_field_t priv_nsets;
sl_field_t priv_setsize;
sl_field_t priv_max;
sl_field_t priv_infosize;
sl_field_t priv_globalinfosize;
} sl_priv_impl_info_layout_t;
/*
* Layout description of fltset_t, from <sys/fault.h>.
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t word;
} sl_fltset_layout_t;
/*
* Layout description of siginfo_t, from <sys/siginfo.h>.
*
* siginfo_t is unusual, in that it contains a large union
* full of private fields. There are macros defined to give
* access to these fields via the names documented in the
* siginfo manpage. We stick to the documented names
* rather than try to unravel the undocumented blob. Hence,
* the layout description below is a "logical" view of siginfo_t.
* The fields below are not necessarily in the same order as
* they appear in siginfo_t, nor are they everything that is in
* that struct. They may also overlap each other, if they are
* contained within of the union.
*
* The f_ prefixes are used to prevent our field names from
* clashing with the macros defined in siginfo.h.
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t f_si_signo;
sl_field_t f_si_errno;
sl_field_t f_si_code;
sl_field_t f_si_value_int;
sl_field_t f_si_value_ptr;
sl_field_t f_si_pid;
sl_field_t f_si_uid;
sl_field_t f_si_ctid;
sl_field_t f_si_zoneid;
sl_field_t f_si_entity;
sl_field_t f_si_addr;
sl_field_t f_si_status;
sl_field_t f_si_band;
} sl_siginfo_layout_t;
/*
* Layout description of sigset_t, from <sys/signal.h>.
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t sigbits;
} sl_sigset_layout_t;
/*
* Layout description of struct sigaction, from <sys/signal.h>.
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t sa_flags;
sl_field_t sa_hand;
sl_field_t sa_sigact;
sl_field_t sa_mask;
} sl_sigaction_layout_t;
/*
* Layout description of stack_t, from <sys/signal.h>.
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t ss_sp;
sl_field_t ss_size;
sl_field_t ss_flags;
} sl_stack_layout_t;
/*
* Layout description of sysset_t, from <sys/syscall.h>.
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t word;
} sl_sysset_layout_t;
/*
* Layout description of timestruc_t, from <sys/time_impl.h>.
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t tv_sec;
sl_field_t tv_nsec;
} sl_timestruc_layout_t;
/*
* Layout description of struct utsname, from <sys/utsname.h>.
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t sysname;
sl_field_t nodename;
sl_field_t release;
sl_field_t version;
sl_field_t machine;
} sl_utsname_layout_t;
/*
* Layout description of prfdinfo_core_t, from <sys/procfs.h>.
*/
typedef struct {
sl_field_t sizeof_struct;
sl_field_t pr_fd;
sl_field_t pr_mode;
sl_field_t pr_uid;
sl_field_t pr_gid;
sl_field_t pr_major;
sl_field_t pr_minor;
sl_field_t pr_rmajor;
sl_field_t pr_rminor;
sl_field_t pr_ino;
sl_field_t pr_offset;
sl_field_t pr_size;
sl_field_t pr_fileflags;
sl_field_t pr_fdflags;
sl_field_t pr_path;
} sl_prfdinfo_layout_t;
typedef struct {
sl_field_t sizeof_struct;
sl_field_t pr_version;
sl_field_t pr_effective;
sl_field_t pr_inherit;
sl_field_t pr_lower;
sl_field_t pr_upper;
} sl_prsecflags_layout_t;
typedef struct {
sl_field_t sizeof_struct;
sl_field_t pr_lwpid;
sl_field_t pr_lwpname;
} sl_prlwpname_layout_t;
typedef struct {
sl_field_t sizeof_struct;
sl_field_t pru_version;
sl_field_t pru_flags;
sl_field_t pru_data;
} sl_prupanic_layout_t;
typedef struct {
sl_field_t sizeof_struct;
sl_field_t prcwd_fsid;
sl_field_t prcwd_fsname;
sl_field_t prcwd_mntpt;
sl_field_t prcwd_mntspec;
sl_field_t prcwd_cwd;
} sl_prcwd_layout_t;
/*
* This type collects all of the layout definitions for
* a given architecture.
*/
typedef struct {
const sl_auxv_layout_t *auxv; /* auxv_t */
const sl_fltset_layout_t *fltset; /* fltset_t */
const sl_lwpsinfo_layout_t *lwpsinfo; /* lwpsinfo_t */
const sl_lwpstatus_layout_t *lwpstatus; /* lwpstatus_t */
const sl_prcred_layout_t *prcred; /* prcred_t */
const sl_priv_impl_info_layout_t *priv_impl_info; /* priv_impl_info_t */
const sl_prpriv_layout_t *prpriv; /* prpriv_t */
const sl_psinfo_layout_t *psinfo; /* psinfo_t */
const sl_pstatus_layout_t *pstatus; /* pstatus_t */
const sl_prgregset_layout_t *prgregset; /* prgregset_t */
const sl_prpsinfo_layout_t *prpsinfo; /* prpsinfo_t */
const sl_prstatus_layout_t *prstatus; /* prstatus_t */
const sl_sigaction_layout_t *sigaction; /* struct sigaction */
const sl_siginfo_layout_t *siginfo; /* siginfo_t */
const sl_sigset_layout_t *sigset; /* sigset_t */
const sl_stack_layout_t *stack; /* stack_t */
const sl_sysset_layout_t *sysset; /* sysset_t */
const sl_timestruc_layout_t *timestruc; /* timestruc_t */
const sl_utsname_layout_t *utsname; /* struct utsname */
const sl_prfdinfo_layout_t *prfdinfo; /* prdinfo_t */
const sl_prsecflags_layout_t *prsecflags; /* prsecflags_t */
const sl_prlwpname_layout_t *prlwpname; /* prlwpname_t */
const sl_prupanic_layout_t *prupanic; /* prupanic_t */
const sl_prcwd_layout_t *prcwd; /* prcwd_t */
} sl_arch_layout_t;
extern void sl_extract_num_field(const char *data, int do_swap,
const sl_field_t *fdesc, sl_data_t *field_data);
extern Word sl_extract_as_word(const char *data, int do_swap,
const sl_field_t *fdesc);
extern Lword sl_extract_as_lword(const char *data, int do_swap,
const sl_field_t *fdesc);
extern Sword sl_extract_as_sword(const char *data, int do_swap,
const sl_field_t *fdesc);
extern const char *sl_fmt_num(const char *data, int do_swap,
const sl_field_t *fdesc, sl_fmt_num_t fmt_type,
sl_fmtbuf_t buf);
extern const sl_arch_layout_t *sl_mach(Half);
extern const sl_arch_layout_t *struct_layout_i386(void);
extern const sl_arch_layout_t *struct_layout_amd64(void);
#ifdef __cplusplus
}
#endif
#endif /* _STRUCT_LAYOUT_H */
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 2012 DEY Storage Systems, Inc. All rights reserved.
* Copyright 2018 Joyent, Inc.
* Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
*/
#include <struct_layout.h>
static const sl_auxv_layout_t auxv_layout = {
{ 0, 16, 0, 0 }, /* sizeof (auxv_t) */
{ 0, 4, 0, 1 }, /* a_type */
{ 8, 8, 0, 1 }, /* a_un.a_val */
{ 8, 8, 0, 0 }, /* a_un.a_ptr */
{ 8, 8, 0, 0 }, /* a_un.a_fcn */
};
static const sl_prgregset_layout_t prgregset_layout = {
{ 0, 224, 0, 0 }, /* sizeof (prgregset_t) */
{ 0, 8, 28, 0 }, /* elt0 */
};
static const sl_lwpstatus_layout_t lwpstatus_layout = {
{ 0, 1296, 0, 0 }, /* sizeof (lwpstatus_t) */
{ 0, 4, 0, 0 }, /* pr_flags */
{ 4, 4, 0, 0 }, /* pr_lwpid */
{ 8, 2, 0, 0 }, /* pr_why */
{ 10, 2, 0, 0 }, /* pr_what */
{ 12, 2, 0, 0 }, /* pr_cursig */
{ 16, 256, 0, 0 }, /* pr_info */
{ 272, 16, 0, 0 }, /* pr_lwppend */
{ 288, 16, 0, 0 }, /* pr_lwphold */
{ 304, 32, 0, 0 }, /* pr_action */
{ 336, 24, 0, 0 }, /* pr_altstack */
{ 360, 8, 0, 0 }, /* pr_oldcontext */
{ 368, 2, 0, 0 }, /* pr_syscall */
{ 370, 2, 0, 0 }, /* pr_nsysarg */
{ 372, 4, 0, 0 }, /* pr_errno */
{ 376, 8, 8, 0 }, /* pr_sysarg[] */
{ 440, 8, 0, 0 }, /* pr_rval1 */
{ 448, 8, 0, 0 }, /* pr_rval2 */
{ 456, 1, 8, 0 }, /* pr_clname[] */
{ 464, 16, 0, 0 }, /* pr_tstamp */
{ 480, 16, 0, 0 }, /* pr_utime */
{ 496, 16, 0, 0 }, /* pr_stime */
{ 524, 4, 0, 0 }, /* pr_errpriv */
{ 528, 8, 0, 0 }, /* pr_ustack */
{ 536, 8, 0, 0 }, /* pr_instr */
{ 544, 224, 0, 0 }, /* pr_reg */
{ 768, 528, 0, 0 }, /* pr_fpreg */
};
static const sl_pstatus_layout_t pstatus_layout = {
{ 0, 1680, 0, 0 }, /* sizeof (pstatus_t) */
{ 0, 4, 0, 1 }, /* pr_flags */
{ 4, 4, 0, 1 }, /* pr_nlwp */
{ 8, 4, 0, 0 }, /* pr_pid */
{ 12, 4, 0, 0 }, /* pr_ppid */
{ 16, 4, 0, 0 }, /* pr_pgid */
{ 20, 4, 0, 0 }, /* pr_sid */
{ 24, 4, 0, 1 }, /* pr_aslwpid */
{ 28, 4, 0, 1 }, /* pr_agentid */
{ 32, 16, 0, 0 }, /* pr_sigpend */
{ 48, 8, 0, 0 }, /* pr_brkbase */
{ 56, 8, 0, 0 }, /* pr_brksize */
{ 64, 8, 0, 0 }, /* pr_stkbase */
{ 72, 8, 0, 0 }, /* pr_stksize */
{ 80, 16, 0, 0 }, /* pr_utime */
{ 96, 16, 0, 0 }, /* pr_stime */
{ 112, 16, 0, 0 }, /* pr_cutime */
{ 128, 16, 0, 0 }, /* pr_cstime */
{ 144, 16, 0, 0 }, /* pr_sigtrace */
{ 160, 16, 0, 0 }, /* pr_flttrace */
{ 176, 64, 0, 0 }, /* pr_sysentry */
{ 240, 64, 0, 0 }, /* pr_sysexit */
{ 304, 1, 0, 0 }, /* pr_dmodel */
{ 308, 4, 0, 1 }, /* pr_taskid */
{ 312, 4, 0, 1 }, /* pr_projid */
{ 316, 4, 0, 1 }, /* pr_nzomb */
{ 320, 4, 0, 1 }, /* pr_zoneid */
{ 384, 1296, 0, 0 }, /* pr_lwp */
};
static const sl_prstatus_layout_t prstatus_layout = {
{ 0, 824, 0, 0 }, /* sizeof (prstatus_t) */
{ 0, 4, 0, 1 }, /* pr_flags */
{ 4, 2, 0, 1 }, /* pr_why */
{ 6, 2, 0, 1 }, /* pr_what */
{ 8, 256, 0, 0 }, /* pr_info */
{ 264, 2, 0, 1 }, /* pr_cursig */
{ 266, 2, 0, 0 }, /* pr_nlwp */
{ 268, 16, 0, 0 }, /* pr_sigpend */
{ 284, 16, 0, 0 }, /* pr_sighold */
{ 304, 24, 0, 0 }, /* pr_altstack */
{ 328, 32, 0, 0 }, /* pr_action */
{ 360, 4, 0, 0 }, /* pr_pid */
{ 364, 4, 0, 0 }, /* pr_ppid */
{ 368, 4, 0, 0 }, /* pr_pgrp */
{ 372, 4, 0, 0 }, /* pr_sid */
{ 376, 16, 0, 0 }, /* pr_utime */
{ 392, 16, 0, 0 }, /* pr_stime */
{ 408, 16, 0, 0 }, /* pr_cutime */
{ 424, 16, 0, 0 }, /* pr_cstime */
{ 440, 1, 8, 0 }, /* pr_clname[] */
{ 448, 2, 0, 1 }, /* pr_syscall */
{ 450, 2, 0, 1 }, /* pr_nsysarg */
{ 456, 8, 8, 1 }, /* pr_sysarg[] */
{ 520, 4, 0, 0 }, /* pr_who */
{ 524, 16, 0, 0 }, /* pr_lwppend */
{ 544, 8, 0, 0 }, /* pr_oldcontext */
{ 552, 8, 0, 0 }, /* pr_brkbase */
{ 560, 8, 0, 0 }, /* pr_brksize */
{ 568, 8, 0, 0 }, /* pr_stkbase */
{ 576, 8, 0, 0 }, /* pr_stksize */
{ 584, 2, 0, 1 }, /* pr_processor */
{ 586, 2, 0, 1 }, /* pr_bind */
{ 592, 8, 0, 1 }, /* pr_instr */
{ 600, 224, 0, 0 }, /* pr_reg */
};
static const sl_psinfo_layout_t psinfo_layout = {
{ 0, 416, 0, 0 }, /* sizeof (psinfo_t) */
{ 0, 4, 0, 1 }, /* pr_flag */
{ 4, 4, 0, 1 }, /* pr_nlwp */
{ 8, 4, 0, 0 }, /* pr_pid */
{ 12, 4, 0, 0 }, /* pr_ppid */
{ 16, 4, 0, 0 }, /* pr_pgid */
{ 20, 4, 0, 0 }, /* pr_sid */
{ 24, 4, 0, 0 }, /* pr_uid */
{ 28, 4, 0, 0 }, /* pr_euid */
{ 32, 4, 0, 0 }, /* pr_gid */
{ 36, 4, 0, 0 }, /* pr_egid */
{ 40, 8, 0, 0 }, /* pr_addr */
{ 48, 8, 0, 0 }, /* pr_size */
{ 56, 8, 0, 0 }, /* pr_rssize */
{ 72, 8, 0, 0 }, /* pr_ttydev */
{ 80, 2, 0, 0 }, /* pr_pctcpu */
{ 82, 2, 0, 0 }, /* pr_pctmem */
{ 88, 16, 0, 0 }, /* pr_start */
{ 104, 16, 0, 0 }, /* pr_time */
{ 120, 16, 0, 0 }, /* pr_ctime */
{ 136, 1, 16, 0 }, /* pr_fname[] */
{ 152, 1, 80, 0 }, /* pr_psargs[] */
{ 232, 4, 0, 1 }, /* pr_wstat */
{ 236, 4, 0, 1 }, /* pr_argc */
{ 240, 8, 0, 0 }, /* pr_argv */
{ 248, 8, 0, 0 }, /* pr_envp */
{ 256, 1, 0, 0 }, /* pr_dmodel */
{ 260, 4, 0, 0 }, /* pr_taskid */
{ 264, 4, 0, 0 }, /* pr_projid */
{ 268, 4, 0, 1 }, /* pr_nzomb */
{ 272, 4, 0, 0 }, /* pr_poolid */
{ 276, 4, 0, 0 }, /* pr_zoneid */
{ 280, 4, 0, 0 }, /* pr_contract */
{ 288, 128, 0, 0 }, /* pr_lwp */
};
static const sl_prpsinfo_layout_t prpsinfo_layout = {
{ 0, 328, 0, 0 }, /* sizeof (prpsinfo_t) */
{ 0, 1, 0, 0 }, /* pr_state */
{ 1, 1, 0, 0 }, /* pr_sname */
{ 2, 1, 0, 0 }, /* pr_zomb */
{ 3, 1, 0, 0 }, /* pr_nice */
{ 4, 4, 0, 0 }, /* pr_flag */
{ 8, 4, 0, 0 }, /* pr_uid */
{ 12, 4, 0, 0 }, /* pr_gid */
{ 16, 4, 0, 0 }, /* pr_pid */
{ 20, 4, 0, 0 }, /* pr_ppid */
{ 24, 4, 0, 0 }, /* pr_pgrp */
{ 28, 4, 0, 0 }, /* pr_sid */
{ 32, 8, 0, 0 }, /* pr_addr */
{ 40, 8, 0, 0 }, /* pr_size */
{ 48, 8, 0, 0 }, /* pr_rssize */
{ 56, 8, 0, 0 }, /* pr_wchan */
{ 64, 16, 0, 0 }, /* pr_start */
{ 80, 16, 0, 0 }, /* pr_time */
{ 96, 4, 0, 1 }, /* pr_pri */
{ 100, 1, 0, 0 }, /* pr_oldpri */
{ 101, 1, 0, 0 }, /* pr_cpu */
{ 102, 2, 0, 0 }, /* pr_ottydev */
{ 104, 8, 0, 0 }, /* pr_lttydev */
{ 112, 1, 8, 0 }, /* pr_clname[] */
{ 120, 1, 16, 0 }, /* pr_fname[] */
{ 136, 1, 80, 0 }, /* pr_psargs[] */
{ 216, 2, 0, 1 }, /* pr_syscall */
{ 224, 16, 0, 0 }, /* pr_ctime */
{ 240, 8, 0, 0 }, /* pr_bysize */
{ 248, 8, 0, 0 }, /* pr_byrssize */
{ 256, 4, 0, 1 }, /* pr_argc */
{ 264, 8, 0, 0 }, /* pr_argv */
{ 272, 8, 0, 0 }, /* pr_envp */
{ 280, 4, 0, 1 }, /* pr_wstat */
{ 284, 2, 0, 0 }, /* pr_pctcpu */
{ 286, 2, 0, 0 }, /* pr_pctmem */
{ 288, 4, 0, 0 }, /* pr_euid */
{ 292, 4, 0, 0 }, /* pr_egid */
{ 296, 4, 0, 0 }, /* pr_aslwpid */
{ 300, 1, 0, 0 }, /* pr_dmodel */
};
static const sl_lwpsinfo_layout_t lwpsinfo_layout = {
{ 0, 128, 0, 0 }, /* sizeof (lwpsinfo_t) */
{ 0, 4, 0, 1 }, /* pr_flag */
{ 4, 4, 0, 0 }, /* pr_lwpid */
{ 8, 8, 0, 0 }, /* pr_addr */
{ 16, 8, 0, 0 }, /* pr_wchan */
{ 24, 1, 0, 0 }, /* pr_stype */
{ 25, 1, 0, 0 }, /* pr_state */
{ 26, 1, 0, 0 }, /* pr_sname */
{ 27, 1, 0, 0 }, /* pr_nice */
{ 28, 2, 0, 0 }, /* pr_syscall */
{ 30, 1, 0, 0 }, /* pr_oldpri */
{ 31, 1, 0, 0 }, /* pr_cpu */
{ 32, 4, 0, 1 }, /* pr_pri */
{ 36, 2, 0, 0 }, /* pr_pctcpu */
{ 40, 16, 0, 0 }, /* pr_start */
{ 56, 16, 0, 0 }, /* pr_time */
{ 72, 1, 8, 0 }, /* pr_clname[] */
{ 80, 1, 16, 0 }, /* pr_name[] */
{ 96, 4, 0, 1 }, /* pr_onpro */
{ 100, 4, 0, 1 }, /* pr_bindpro */
{ 104, 4, 0, 1 }, /* pr_bindpset */
{ 108, 4, 0, 1 }, /* pr_lgrp */
};
static const sl_prcred_layout_t prcred_layout = {
{ 0, 32, 0, 0 }, /* sizeof (prcred_t) */
{ 0, 4, 0, 0 }, /* pr_euid */
{ 4, 4, 0, 0 }, /* pr_ruid */
{ 8, 4, 0, 0 }, /* pr_suid */
{ 12, 4, 0, 0 }, /* pr_egid */
{ 16, 4, 0, 0 }, /* pr_rgid */
{ 20, 4, 0, 0 }, /* pr_sgid */
{ 24, 4, 0, 1 }, /* pr_ngroups */
{ 28, 4, 1, 0 }, /* pr_groups[] */
};
static const sl_prpriv_layout_t prpriv_layout = {
{ 0, 16, 0, 0 }, /* sizeof (prpriv_t) */
{ 0, 4, 0, 0 }, /* pr_nsets */
{ 4, 4, 0, 0 }, /* pr_setsize */
{ 8, 4, 0, 0 }, /* pr_infosize */
{ 12, 4, 1, 0 }, /* pr_sets[] */
};
static const sl_priv_impl_info_layout_t priv_impl_info_layout = {
{ 0, 28, 0, 0 }, /* sizeof (priv_impl_info_t) */
{ 0, 4, 0, 0 }, /* priv_headersize */
{ 4, 4, 0, 0 }, /* priv_flags */
{ 8, 4, 0, 0 }, /* priv_nsets */
{ 12, 4, 0, 0 }, /* priv_setsize */
{ 16, 4, 0, 0 }, /* priv_max */
{ 20, 4, 0, 0 }, /* priv_infosize */
{ 24, 4, 0, 0 }, /* priv_globalinfosize */
};
static const sl_fltset_layout_t fltset_layout = {
{ 0, 16, 0, 0 }, /* sizeof (fltset_t) */
{ 0, 4, 4, 0 }, /* word[] */
};
static const sl_siginfo_layout_t siginfo_layout = {
{ 0, 256, 0, 0 }, /* sizeof (siginfo_t) */
{ 0, 4, 0, 0 }, /* si_signo */
{ 8, 4, 0, 0 }, /* si_errno */
{ 4, 4, 0, 1 }, /* si_code */
{ 32, 4, 0, 0 }, /* si_value.sival_int */
{ 32, 8, 0, 0 }, /* si_value.sival_ptr */
{ 16, 4, 0, 0 }, /* si_pid */
{ 24, 4, 0, 0 }, /* si_uid */
{ 48, 4, 0, 0 }, /* si_ctid */
{ 52, 4, 0, 0 }, /* si_zoneid */
{ 16, 4, 0, 0 }, /* si_entity */
{ 16, 8, 0, 0 }, /* si_addr */
{ 32, 4, 0, 0 }, /* si_status */
{ 24, 8, 0, 0 }, /* si_band */
};
static const sl_sigset_layout_t sigset_layout = {
{ 0, 16, 0, 0 }, /* sizeof (sigset_t) */
{ 0, 4, 4, 0 }, /* __sigbits[] */
};
static const sl_sigaction_layout_t sigaction_layout = {
{ 0, 32, 0, 0 }, /* sizeof (struct sigaction) */
{ 0, 4, 0, 0 }, /* sa_flags */
{ 8, 8, 0, 0 }, /* sa_handler */
{ 8, 8, 0, 0 }, /* sa_sigaction */
{ 16, 16, 0, 0 }, /* sa_mask */
};
static const sl_stack_layout_t stack_layout = {
{ 0, 24, 0, 0 }, /* sizeof (stack_t) */
{ 0, 8, 0, 0 }, /* ss_sp */
{ 8, 8, 0, 0 }, /* ss_size */
{ 16, 4, 0, 0 }, /* ss_flags */
};
static const sl_sysset_layout_t sysset_layout = {
{ 0, 64, 0, 0 }, /* sizeof (sysset_t) */
{ 0, 4, 16, 0 }, /* word[] */
};
static const sl_timestruc_layout_t timestruc_layout = {
{ 0, 16, 0, 0 }, /* sizeof (timestruc_t) */
{ 0, 8, 0, 0 }, /* tv_sec */
{ 8, 8, 0, 0 }, /* tv_nsec */
};
static const sl_utsname_layout_t utsname_layout = {
{ 0, 1285, 0, 0 }, /* sizeof (struct utsname) */
{ 0, 1, 257, 0 }, /* sysname[] */
{ 257, 1, 257, 0 }, /* nodename[] */
{ 514, 1, 257, 0 }, /* release[] */
{ 771, 1, 257, 0 }, /* version[] */
{ 1028, 1, 257, 0 }, /* machine[] */
};
static const sl_prfdinfo_layout_t prfdinfo_layout = {
{ 0, 1088, 0, 0 }, /* sizeof (prfdinfo_core_t) */
{ 0, 4, 0, 0 }, /* pr_fd */
{ 4, 4, 0, 0 }, /* pr_mode */
{ 8, 4, 0, 0 }, /* pr_uid */
{ 12, 4, 0, 0 }, /* pr_gid */
{ 16, 4, 0, 0 }, /* pr_major */
{ 20, 4, 0, 0 }, /* pr_minor */
{ 24, 4, 0, 0 }, /* pr_rmajor */
{ 28, 4, 0, 0 }, /* pr_rminor */
{ 32, 8, 0, 0 }, /* pr_ino */
{ 40, 8, 0, 0 }, /* pr_offset */
{ 48, 8, 0, 0 }, /* pr_size */
{ 56, 4, 0, 0 }, /* pr_fileflags */
{ 60, 4, 0, 0 }, /* pr_fdflags */
{ 64, 1, 1024, 0 }, /* pr_path[] */
};
static const sl_prsecflags_layout_t prsecflags_layout = {
{ 0, 40, 0, 0 }, /* sizeof (prsecflags_t) */
{ 0, 4, 0, 0 }, /* pr_version */
{ 8, 8, 0, 0 }, /* pr_effective */
{ 16, 8, 0, 0 }, /* pr_inherit */
{ 24, 8, 0, 0 }, /* pr_lower */
{ 32, 8, 0, 0 }, /* pr_upper */
};
static const sl_prlwpname_layout_t prlwpname_layout = {
{ 0, 40, 0, 0 }, /* sizeof (prlwpname_t) */
{ 0, 8, 0, 0 }, /* pr_lwpid */
{ 8, 1, 32, 0 }, /* pr_lwpname[] */
};
static const sl_prupanic_layout_t prupanic_layout = {
{ 0, 1032, 0, 0 }, /* sizeof (prupanic_t) */
{ 0, 4, 0, 0 }, /* pru_version */
{ 4, 4, 0, 0 }, /* pru_flags */
{ 8, 1, 1024, 0 }, /* pru_data[] */
};
static const sl_prcwd_layout_t prcwd_layout = {
{ 0, 3096, 0, 0 }, /* sizeof (prcwd_t) */
{ 0, 8, 0, 0 }, /* prcwd_fsid */
{ 8, 1, 16, 0 }, /* prcwd_fsname[] */
{ 24, 1, 1024, 0 }, /* prcwd_mntpt[] */
{ 1048, 1, 1024, 0 }, /* prcwd_mntspec[] */
{ 2072, 1, 1024, 0 }, /* prcwd_cwd[] */
};
static const sl_arch_layout_t layout_amd64 = {
&auxv_layout,
&fltset_layout,
&lwpsinfo_layout,
&lwpstatus_layout,
&prcred_layout,
&priv_impl_info_layout,
&prpriv_layout,
&psinfo_layout,
&pstatus_layout,
&prgregset_layout,
&prpsinfo_layout,
&prstatus_layout,
&sigaction_layout,
&siginfo_layout,
&sigset_layout,
&stack_layout,
&sysset_layout,
×truc_layout,
&utsname_layout,
&prfdinfo_layout,
&prsecflags_layout,
&prlwpname_layout,
&prupanic_layout,
&prcwd_layout,
};
const sl_arch_layout_t *
struct_layout_amd64(void)
{
return (&layout_amd64);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 2012 DEY Storage Systems, Inc. All rights reserved.
* Copyright 2018 Joyent, Inc.
* Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
*/
#include <struct_layout.h>
static const sl_auxv_layout_t auxv_layout = {
{ 0, 8, 0, 0 }, /* sizeof (auxv_t) */
{ 0, 4, 0, 1 }, /* a_type */
{ 4, 4, 0, 1 }, /* a_un.a_val */
{ 4, 4, 0, 0 }, /* a_un.a_ptr */
{ 4, 4, 0, 0 }, /* a_un.a_fcn */
};
static const sl_prgregset_layout_t prgregset_layout = {
{ 0, 76, 0, 0 }, /* sizeof (prgregset_t) */
{ 0, 4, 19, 0 }, /* elt0 */
};
static const sl_lwpstatus_layout_t lwpstatus_layout = {
{ 0, 800, 0, 0 }, /* sizeof (lwpstatus_t) */
{ 0, 4, 0, 0 }, /* pr_flags */
{ 4, 4, 0, 0 }, /* pr_lwpid */
{ 8, 2, 0, 0 }, /* pr_why */
{ 10, 2, 0, 0 }, /* pr_what */
{ 12, 2, 0, 0 }, /* pr_cursig */
{ 16, 128, 0, 0 }, /* pr_info */
{ 144, 16, 0, 0 }, /* pr_lwppend */
{ 160, 16, 0, 0 }, /* pr_lwphold */
{ 176, 32, 0, 0 }, /* pr_action */
{ 208, 12, 0, 0 }, /* pr_altstack */
{ 220, 4, 0, 0 }, /* pr_oldcontext */
{ 224, 2, 0, 0 }, /* pr_syscall */
{ 226, 2, 0, 0 }, /* pr_nsysarg */
{ 228, 4, 0, 0 }, /* pr_errno */
{ 232, 4, 8, 0 }, /* pr_sysarg[] */
{ 264, 4, 0, 0 }, /* pr_rval1 */
{ 268, 4, 0, 0 }, /* pr_rval2 */
{ 272, 1, 8, 0 }, /* pr_clname[] */
{ 280, 8, 0, 0 }, /* pr_tstamp */
{ 288, 8, 0, 0 }, /* pr_utime */
{ 296, 8, 0, 0 }, /* pr_stime */
{ 332, 4, 0, 0 }, /* pr_errpriv */
{ 336, 4, 0, 0 }, /* pr_ustack */
{ 340, 4, 0, 0 }, /* pr_instr */
{ 344, 76, 0, 0 }, /* pr_reg */
{ 420, 380, 0, 0 }, /* pr_fpreg */
};
static const sl_pstatus_layout_t pstatus_layout = {
{ 0, 1136, 0, 0 }, /* sizeof (pstatus_t) */
{ 0, 4, 0, 1 }, /* pr_flags */
{ 4, 4, 0, 1 }, /* pr_nlwp */
{ 8, 4, 0, 0 }, /* pr_pid */
{ 12, 4, 0, 0 }, /* pr_ppid */
{ 16, 4, 0, 0 }, /* pr_pgid */
{ 20, 4, 0, 0 }, /* pr_sid */
{ 24, 4, 0, 1 }, /* pr_aslwpid */
{ 28, 4, 0, 1 }, /* pr_agentid */
{ 32, 16, 0, 0 }, /* pr_sigpend */
{ 48, 4, 0, 0 }, /* pr_brkbase */
{ 52, 4, 0, 0 }, /* pr_brksize */
{ 56, 4, 0, 0 }, /* pr_stkbase */
{ 60, 4, 0, 0 }, /* pr_stksize */
{ 64, 8, 0, 0 }, /* pr_utime */
{ 72, 8, 0, 0 }, /* pr_stime */
{ 80, 8, 0, 0 }, /* pr_cutime */
{ 88, 8, 0, 0 }, /* pr_cstime */
{ 96, 16, 0, 0 }, /* pr_sigtrace */
{ 112, 16, 0, 0 }, /* pr_flttrace */
{ 128, 64, 0, 0 }, /* pr_sysentry */
{ 192, 64, 0, 0 }, /* pr_sysexit */
{ 256, 1, 0, 0 }, /* pr_dmodel */
{ 260, 4, 0, 1 }, /* pr_taskid */
{ 264, 4, 0, 1 }, /* pr_projid */
{ 268, 4, 0, 1 }, /* pr_nzomb */
{ 272, 4, 0, 1 }, /* pr_zoneid */
{ 336, 800, 0, 0 }, /* pr_lwp */
};
static const sl_prstatus_layout_t prstatus_layout = {
{ 0, 432, 0, 0 }, /* sizeof (prstatus_t) */
{ 0, 4, 0, 1 }, /* pr_flags */
{ 4, 2, 0, 1 }, /* pr_why */
{ 6, 2, 0, 1 }, /* pr_what */
{ 8, 128, 0, 0 }, /* pr_info */
{ 136, 2, 0, 1 }, /* pr_cursig */
{ 138, 2, 0, 0 }, /* pr_nlwp */
{ 140, 16, 0, 0 }, /* pr_sigpend */
{ 156, 16, 0, 0 }, /* pr_sighold */
{ 172, 12, 0, 0 }, /* pr_altstack */
{ 184, 32, 0, 0 }, /* pr_action */
{ 216, 4, 0, 0 }, /* pr_pid */
{ 220, 4, 0, 0 }, /* pr_ppid */
{ 224, 4, 0, 0 }, /* pr_pgrp */
{ 228, 4, 0, 0 }, /* pr_sid */
{ 232, 8, 0, 0 }, /* pr_utime */
{ 240, 8, 0, 0 }, /* pr_stime */
{ 248, 8, 0, 0 }, /* pr_cutime */
{ 256, 8, 0, 0 }, /* pr_cstime */
{ 264, 1, 8, 0 }, /* pr_clname[] */
{ 272, 2, 0, 1 }, /* pr_syscall */
{ 274, 2, 0, 1 }, /* pr_nsysarg */
{ 276, 4, 8, 1 }, /* pr_sysarg[] */
{ 308, 4, 0, 0 }, /* pr_who */
{ 312, 16, 0, 0 }, /* pr_lwppend */
{ 328, 4, 0, 0 }, /* pr_oldcontext */
{ 332, 4, 0, 0 }, /* pr_brkbase */
{ 336, 4, 0, 0 }, /* pr_brksize */
{ 340, 4, 0, 0 }, /* pr_stkbase */
{ 344, 4, 0, 0 }, /* pr_stksize */
{ 348, 2, 0, 1 }, /* pr_processor */
{ 350, 2, 0, 1 }, /* pr_bind */
{ 352, 4, 0, 1 }, /* pr_instr */
{ 356, 76, 0, 0 }, /* pr_reg */
};
static const sl_psinfo_layout_t psinfo_layout = {
{ 0, 336, 0, 0 }, /* sizeof (psinfo_t) */
{ 0, 4, 0, 1 }, /* pr_flag */
{ 4, 4, 0, 1 }, /* pr_nlwp */
{ 8, 4, 0, 0 }, /* pr_pid */
{ 12, 4, 0, 0 }, /* pr_ppid */
{ 16, 4, 0, 0 }, /* pr_pgid */
{ 20, 4, 0, 0 }, /* pr_sid */
{ 24, 4, 0, 0 }, /* pr_uid */
{ 28, 4, 0, 0 }, /* pr_euid */
{ 32, 4, 0, 0 }, /* pr_gid */
{ 36, 4, 0, 0 }, /* pr_egid */
{ 40, 4, 0, 0 }, /* pr_addr */
{ 44, 4, 0, 0 }, /* pr_size */
{ 48, 4, 0, 0 }, /* pr_rssize */
{ 56, 4, 0, 0 }, /* pr_ttydev */
{ 60, 2, 0, 0 }, /* pr_pctcpu */
{ 62, 2, 0, 0 }, /* pr_pctmem */
{ 64, 8, 0, 0 }, /* pr_start */
{ 72, 8, 0, 0 }, /* pr_time */
{ 80, 8, 0, 0 }, /* pr_ctime */
{ 88, 1, 16, 0 }, /* pr_fname[] */
{ 104, 1, 80, 0 }, /* pr_psargs[] */
{ 184, 4, 0, 1 }, /* pr_wstat */
{ 188, 4, 0, 1 }, /* pr_argc */
{ 192, 4, 0, 0 }, /* pr_argv */
{ 196, 4, 0, 0 }, /* pr_envp */
{ 200, 1, 0, 0 }, /* pr_dmodel */
{ 204, 4, 0, 0 }, /* pr_taskid */
{ 208, 4, 0, 0 }, /* pr_projid */
{ 212, 4, 0, 1 }, /* pr_nzomb */
{ 216, 4, 0, 0 }, /* pr_poolid */
{ 220, 4, 0, 0 }, /* pr_zoneid */
{ 224, 4, 0, 0 }, /* pr_contract */
{ 232, 104, 0, 0 }, /* pr_lwp */
};
static const sl_prpsinfo_layout_t prpsinfo_layout = {
{ 0, 260, 0, 0 }, /* sizeof (prpsinfo_t) */
{ 0, 1, 0, 0 }, /* pr_state */
{ 1, 1, 0, 0 }, /* pr_sname */
{ 2, 1, 0, 0 }, /* pr_zomb */
{ 3, 1, 0, 0 }, /* pr_nice */
{ 4, 4, 0, 0 }, /* pr_flag */
{ 8, 4, 0, 0 }, /* pr_uid */
{ 12, 4, 0, 0 }, /* pr_gid */
{ 16, 4, 0, 0 }, /* pr_pid */
{ 20, 4, 0, 0 }, /* pr_ppid */
{ 24, 4, 0, 0 }, /* pr_pgrp */
{ 28, 4, 0, 0 }, /* pr_sid */
{ 32, 4, 0, 0 }, /* pr_addr */
{ 36, 4, 0, 0 }, /* pr_size */
{ 40, 4, 0, 0 }, /* pr_rssize */
{ 44, 4, 0, 0 }, /* pr_wchan */
{ 48, 8, 0, 0 }, /* pr_start */
{ 56, 8, 0, 0 }, /* pr_time */
{ 64, 4, 0, 1 }, /* pr_pri */
{ 68, 1, 0, 0 }, /* pr_oldpri */
{ 69, 1, 0, 0 }, /* pr_cpu */
{ 70, 2, 0, 0 }, /* pr_ottydev */
{ 72, 4, 0, 0 }, /* pr_lttydev */
{ 76, 1, 8, 0 }, /* pr_clname[] */
{ 84, 1, 16, 0 }, /* pr_fname[] */
{ 100, 1, 80, 0 }, /* pr_psargs[] */
{ 180, 2, 0, 1 }, /* pr_syscall */
{ 184, 8, 0, 0 }, /* pr_ctime */
{ 192, 4, 0, 0 }, /* pr_bysize */
{ 196, 4, 0, 0 }, /* pr_byrssize */
{ 200, 4, 0, 1 }, /* pr_argc */
{ 204, 4, 0, 0 }, /* pr_argv */
{ 208, 4, 0, 0 }, /* pr_envp */
{ 212, 4, 0, 1 }, /* pr_wstat */
{ 216, 2, 0, 0 }, /* pr_pctcpu */
{ 218, 2, 0, 0 }, /* pr_pctmem */
{ 220, 4, 0, 0 }, /* pr_euid */
{ 224, 4, 0, 0 }, /* pr_egid */
{ 228, 4, 0, 0 }, /* pr_aslwpid */
{ 232, 1, 0, 0 }, /* pr_dmodel */
};
static const sl_lwpsinfo_layout_t lwpsinfo_layout = {
{ 0, 104, 0, 0 }, /* sizeof (lwpsinfo_t) */
{ 0, 4, 0, 1 }, /* pr_flag */
{ 4, 4, 0, 0 }, /* pr_lwpid */
{ 8, 4, 0, 0 }, /* pr_addr */
{ 12, 4, 0, 0 }, /* pr_wchan */
{ 16, 1, 0, 0 }, /* pr_stype */
{ 17, 1, 0, 0 }, /* pr_state */
{ 18, 1, 0, 0 }, /* pr_sname */
{ 19, 1, 0, 0 }, /* pr_nice */
{ 20, 2, 0, 0 }, /* pr_syscall */
{ 22, 1, 0, 0 }, /* pr_oldpri */
{ 23, 1, 0, 0 }, /* pr_cpu */
{ 24, 4, 0, 1 }, /* pr_pri */
{ 28, 2, 0, 0 }, /* pr_pctcpu */
{ 32, 8, 0, 0 }, /* pr_start */
{ 40, 8, 0, 0 }, /* pr_time */
{ 48, 1, 8, 0 }, /* pr_clname[] */
{ 56, 1, 16, 0 }, /* pr_name[] */
{ 72, 4, 0, 1 }, /* pr_onpro */
{ 76, 4, 0, 1 }, /* pr_bindpro */
{ 80, 4, 0, 1 }, /* pr_bindpset */
{ 84, 4, 0, 1 }, /* pr_lgrp */
};
static const sl_prcred_layout_t prcred_layout = {
{ 0, 32, 0, 0 }, /* sizeof (prcred_t) */
{ 0, 4, 0, 0 }, /* pr_euid */
{ 4, 4, 0, 0 }, /* pr_ruid */
{ 8, 4, 0, 0 }, /* pr_suid */
{ 12, 4, 0, 0 }, /* pr_egid */
{ 16, 4, 0, 0 }, /* pr_rgid */
{ 20, 4, 0, 0 }, /* pr_sgid */
{ 24, 4, 0, 1 }, /* pr_ngroups */
{ 28, 4, 1, 0 }, /* pr_groups[] */
};
static const sl_prpriv_layout_t prpriv_layout = {
{ 0, 16, 0, 0 }, /* sizeof (prpriv_t) */
{ 0, 4, 0, 0 }, /* pr_nsets */
{ 4, 4, 0, 0 }, /* pr_setsize */
{ 8, 4, 0, 0 }, /* pr_infosize */
{ 12, 4, 1, 0 }, /* pr_sets[] */
};
static const sl_priv_impl_info_layout_t priv_impl_info_layout = {
{ 0, 28, 0, 0 }, /* sizeof (priv_impl_info_t) */
{ 0, 4, 0, 0 }, /* priv_headersize */
{ 4, 4, 0, 0 }, /* priv_flags */
{ 8, 4, 0, 0 }, /* priv_nsets */
{ 12, 4, 0, 0 }, /* priv_setsize */
{ 16, 4, 0, 0 }, /* priv_max */
{ 20, 4, 0, 0 }, /* priv_infosize */
{ 24, 4, 0, 0 }, /* priv_globalinfosize */
};
static const sl_fltset_layout_t fltset_layout = {
{ 0, 16, 0, 0 }, /* sizeof (fltset_t) */
{ 0, 4, 4, 0 }, /* word[] */
};
static const sl_siginfo_layout_t siginfo_layout = {
{ 0, 128, 0, 0 }, /* sizeof (siginfo_t) */
{ 0, 4, 0, 0 }, /* si_signo */
{ 8, 4, 0, 0 }, /* si_errno */
{ 4, 4, 0, 1 }, /* si_code */
{ 20, 4, 0, 0 }, /* si_value.sival_int */
{ 20, 4, 0, 0 }, /* si_value.sival_ptr */
{ 12, 4, 0, 0 }, /* si_pid */
{ 16, 4, 0, 0 }, /* si_uid */
{ 28, 4, 0, 0 }, /* si_ctid */
{ 32, 4, 0, 0 }, /* si_zoneid */
{ 12, 4, 0, 0 }, /* si_entity */
{ 12, 4, 0, 0 }, /* si_addr */
{ 20, 4, 0, 0 }, /* si_status */
{ 16, 4, 0, 0 }, /* si_band */
};
static const sl_sigset_layout_t sigset_layout = {
{ 0, 16, 0, 0 }, /* sizeof (sigset_t) */
{ 0, 4, 4, 0 }, /* __sigbits[] */
};
static const sl_sigaction_layout_t sigaction_layout = {
{ 0, 32, 0, 0 }, /* sizeof (struct sigaction) */
{ 0, 4, 0, 0 }, /* sa_flags */
{ 4, 4, 0, 0 }, /* sa_handler */
{ 4, 4, 0, 0 }, /* sa_sigaction */
{ 8, 16, 0, 0 }, /* sa_mask */
};
static const sl_stack_layout_t stack_layout = {
{ 0, 12, 0, 0 }, /* sizeof (stack_t) */
{ 0, 4, 0, 0 }, /* ss_sp */
{ 4, 4, 0, 0 }, /* ss_size */
{ 8, 4, 0, 0 }, /* ss_flags */
};
static const sl_sysset_layout_t sysset_layout = {
{ 0, 64, 0, 0 }, /* sizeof (sysset_t) */
{ 0, 4, 16, 0 }, /* word[] */
};
static const sl_timestruc_layout_t timestruc_layout = {
{ 0, 8, 0, 0 }, /* sizeof (timestruc_t) */
{ 0, 4, 0, 0 }, /* tv_sec */
{ 4, 4, 0, 0 }, /* tv_nsec */
};
static const sl_utsname_layout_t utsname_layout = {
{ 0, 1285, 0, 0 }, /* sizeof (struct utsname) */
{ 0, 1, 257, 0 }, /* sysname[] */
{ 257, 1, 257, 0 }, /* nodename[] */
{ 514, 1, 257, 0 }, /* release[] */
{ 771, 1, 257, 0 }, /* version[] */
{ 1028, 1, 257, 0 }, /* machine[] */
};
static const sl_prfdinfo_layout_t prfdinfo_layout = {
{ 0, 1088, 0, 0 }, /* sizeof (prfdinfo_core_t) */
{ 0, 4, 0, 0 }, /* pr_fd */
{ 4, 4, 0, 0 }, /* pr_mode */
{ 8, 4, 0, 0 }, /* pr_uid */
{ 12, 4, 0, 0 }, /* pr_gid */
{ 16, 4, 0, 0 }, /* pr_major */
{ 20, 4, 0, 0 }, /* pr_minor */
{ 24, 4, 0, 0 }, /* pr_rmajor */
{ 28, 4, 0, 0 }, /* pr_rminor */
{ 32, 8, 0, 0 }, /* pr_ino */
{ 40, 8, 0, 0 }, /* pr_offset */
{ 48, 8, 0, 0 }, /* pr_size */
{ 56, 4, 0, 0 }, /* pr_fileflags */
{ 60, 4, 0, 0 }, /* pr_fdflags */
{ 64, 1, 1024, 0 }, /* pr_path[] */
};
static const sl_prsecflags_layout_t prsecflags_layout = {
{ 0, 40, 0, 0 }, /* sizeof (prsecflags_t) */
{ 0, 4, 0, 0 }, /* pr_version */
{ 8, 8, 0, 0 }, /* pr_effective */
{ 16, 8, 0, 0 }, /* pr_inherit */
{ 24, 8, 0, 0 }, /* pr_lower */
{ 32, 8, 0, 0 }, /* pr_upper */
};
static const sl_prlwpname_layout_t prlwpname_layout = {
{ 0, 40, 0, 0 }, /* sizeof (prlwpname_t) */
{ 0, 8, 0, 0 }, /* pr_lwpid */
{ 8, 1, 32, 0 }, /* pr_lwpname[] */
};
static const sl_prupanic_layout_t prupanic_layout = {
{ 0, 1032, 0, 0 }, /* sizeof (prupanic_t) */
{ 0, 4, 0, 0 }, /* pru_version */
{ 4, 4, 0, 0 }, /* pru_flags */
{ 8, 1, 1024, 0 }, /* pru_data[] */
};
static const sl_prcwd_layout_t prcwd_layout = {
{ 0, 3096, 0, 0 }, /* sizeof (prcwd_t) */
{ 0, 8, 0, 0 }, /* prcwd_fsid */
{ 8, 1, 16, 0 }, /* prcwd_fsname[] */
{ 24, 1, 1024, 0 }, /* prcwd_mntpt[] */
{ 1048, 1, 1024, 0 }, /* prcwd_mntspec[] */
{ 2072, 1, 1024, 0 }, /* prcwd_cwd[] */
};
static const sl_arch_layout_t layout_i386 = {
&auxv_layout,
&fltset_layout,
&lwpsinfo_layout,
&lwpstatus_layout,
&prcred_layout,
&priv_impl_info_layout,
&prpriv_layout,
&psinfo_layout,
&pstatus_layout,
&prgregset_layout,
&prpsinfo_layout,
&prstatus_layout,
&sigaction_layout,
&siginfo_layout,
&sigset_layout,
&stack_layout,
&sysset_layout,
×truc_layout,
&utsname_layout,
&prfdinfo_layout,
&prsecflags_layout,
&prlwpname_layout,
&prupanic_layout,
&prcwd_layout,
};
const sl_arch_layout_t *
struct_layout_i386(void)
{
return (&layout_i386);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 2012 DEY Storage Systems, Inc. All rights reserved.
* Copyright 2018 Joyent, Inc.
* Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
*/
#include <struct_layout.h>
static const sl_auxv_layout_t auxv_layout = {
{ 0, 8, 0, 0 }, /* sizeof (auxv_t) */
{ 0, 4, 0, 1 }, /* a_type */
{ 4, 4, 0, 1 }, /* a_un.a_val */
{ 4, 4, 0, 0 }, /* a_un.a_ptr */
{ 4, 4, 0, 0 }, /* a_un.a_fcn */
};
static const sl_prgregset_layout_t prgregset_layout = {
{ 0, 152, 0, 0 }, /* sizeof (prgregset_t) */
{ 0, 4, 38, 0 }, /* elt0 */
};
static const sl_lwpstatus_layout_t lwpstatus_layout = {
{ 0, 896, 0, 0 }, /* sizeof (lwpstatus_t) */
{ 0, 4, 0, 0 }, /* pr_flags */
{ 4, 4, 0, 0 }, /* pr_lwpid */
{ 8, 2, 0, 0 }, /* pr_why */
{ 10, 2, 0, 0 }, /* pr_what */
{ 12, 2, 0, 0 }, /* pr_cursig */
{ 16, 128, 0, 0 }, /* pr_info */
{ 144, 16, 0, 0 }, /* pr_lwppend */
{ 160, 16, 0, 0 }, /* pr_lwphold */
{ 176, 32, 0, 0 }, /* pr_action */
{ 208, 12, 0, 0 }, /* pr_altstack */
{ 220, 4, 0, 0 }, /* pr_oldcontext */
{ 224, 2, 0, 0 }, /* pr_syscall */
{ 226, 2, 0, 0 }, /* pr_nsysarg */
{ 228, 4, 0, 0 }, /* pr_errno */
{ 232, 4, 8, 0 }, /* pr_sysarg[] */
{ 264, 4, 0, 0 }, /* pr_rval1 */
{ 268, 4, 0, 0 }, /* pr_rval2 */
{ 272, 1, 8, 0 }, /* pr_clname[] */
{ 280, 8, 0, 0 }, /* pr_tstamp */
{ 288, 8, 0, 0 }, /* pr_utime */
{ 296, 8, 0, 0 }, /* pr_stime */
{ 332, 4, 0, 0 }, /* pr_errpriv */
{ 336, 4, 0, 0 }, /* pr_ustack */
{ 340, 4, 0, 0 }, /* pr_instr */
{ 344, 152, 0, 0 }, /* pr_reg */
{ 496, 400, 0, 0 }, /* pr_fpreg */
};
static const sl_pstatus_layout_t pstatus_layout = {
{ 0, 1232, 0, 0 }, /* sizeof (pstatus_t) */
{ 0, 4, 0, 1 }, /* pr_flags */
{ 4, 4, 0, 1 }, /* pr_nlwp */
{ 8, 4, 0, 0 }, /* pr_pid */
{ 12, 4, 0, 0 }, /* pr_ppid */
{ 16, 4, 0, 0 }, /* pr_pgid */
{ 20, 4, 0, 0 }, /* pr_sid */
{ 24, 4, 0, 1 }, /* pr_aslwpid */
{ 28, 4, 0, 1 }, /* pr_agentid */
{ 32, 16, 0, 0 }, /* pr_sigpend */
{ 48, 4, 0, 0 }, /* pr_brkbase */
{ 52, 4, 0, 0 }, /* pr_brksize */
{ 56, 4, 0, 0 }, /* pr_stkbase */
{ 60, 4, 0, 0 }, /* pr_stksize */
{ 64, 8, 0, 0 }, /* pr_utime */
{ 72, 8, 0, 0 }, /* pr_stime */
{ 80, 8, 0, 0 }, /* pr_cutime */
{ 88, 8, 0, 0 }, /* pr_cstime */
{ 96, 16, 0, 0 }, /* pr_sigtrace */
{ 112, 16, 0, 0 }, /* pr_flttrace */
{ 128, 64, 0, 0 }, /* pr_sysentry */
{ 192, 64, 0, 0 }, /* pr_sysexit */
{ 256, 1, 0, 0 }, /* pr_dmodel */
{ 260, 4, 0, 1 }, /* pr_taskid */
{ 264, 4, 0, 1 }, /* pr_projid */
{ 268, 4, 0, 1 }, /* pr_nzomb */
{ 272, 4, 0, 1 }, /* pr_zoneid */
{ 336, 896, 0, 0 }, /* pr_lwp */
};
static const sl_prstatus_layout_t prstatus_layout = {
{ 0, 508, 0, 0 }, /* sizeof (prstatus_t) */
{ 0, 4, 0, 1 }, /* pr_flags */
{ 4, 2, 0, 1 }, /* pr_why */
{ 6, 2, 0, 1 }, /* pr_what */
{ 8, 128, 0, 0 }, /* pr_info */
{ 136, 2, 0, 1 }, /* pr_cursig */
{ 138, 2, 0, 0 }, /* pr_nlwp */
{ 140, 16, 0, 0 }, /* pr_sigpend */
{ 156, 16, 0, 0 }, /* pr_sighold */
{ 172, 12, 0, 0 }, /* pr_altstack */
{ 184, 32, 0, 0 }, /* pr_action */
{ 216, 4, 0, 0 }, /* pr_pid */
{ 220, 4, 0, 0 }, /* pr_ppid */
{ 224, 4, 0, 0 }, /* pr_pgrp */
{ 228, 4, 0, 0 }, /* pr_sid */
{ 232, 8, 0, 0 }, /* pr_utime */
{ 240, 8, 0, 0 }, /* pr_stime */
{ 248, 8, 0, 0 }, /* pr_cutime */
{ 256, 8, 0, 0 }, /* pr_cstime */
{ 264, 1, 8, 0 }, /* pr_clname[] */
{ 272, 2, 0, 1 }, /* pr_syscall */
{ 274, 2, 0, 1 }, /* pr_nsysarg */
{ 276, 4, 8, 1 }, /* pr_sysarg[] */
{ 308, 4, 0, 0 }, /* pr_who */
{ 312, 16, 0, 0 }, /* pr_lwppend */
{ 328, 4, 0, 0 }, /* pr_oldcontext */
{ 332, 4, 0, 0 }, /* pr_brkbase */
{ 336, 4, 0, 0 }, /* pr_brksize */
{ 340, 4, 0, 0 }, /* pr_stkbase */
{ 344, 4, 0, 0 }, /* pr_stksize */
{ 348, 2, 0, 1 }, /* pr_processor */
{ 350, 2, 0, 1 }, /* pr_bind */
{ 352, 4, 0, 1 }, /* pr_instr */
{ 356, 152, 0, 0 }, /* pr_reg */
};
static const sl_psinfo_layout_t psinfo_layout = {
{ 0, 336, 0, 0 }, /* sizeof (psinfo_t) */
{ 0, 4, 0, 1 }, /* pr_flag */
{ 4, 4, 0, 1 }, /* pr_nlwp */
{ 8, 4, 0, 0 }, /* pr_pid */
{ 12, 4, 0, 0 }, /* pr_ppid */
{ 16, 4, 0, 0 }, /* pr_pgid */
{ 20, 4, 0, 0 }, /* pr_sid */
{ 24, 4, 0, 0 }, /* pr_uid */
{ 28, 4, 0, 0 }, /* pr_euid */
{ 32, 4, 0, 0 }, /* pr_gid */
{ 36, 4, 0, 0 }, /* pr_egid */
{ 40, 4, 0, 0 }, /* pr_addr */
{ 44, 4, 0, 0 }, /* pr_size */
{ 48, 4, 0, 0 }, /* pr_rssize */
{ 56, 4, 0, 0 }, /* pr_ttydev */
{ 60, 2, 0, 0 }, /* pr_pctcpu */
{ 62, 2, 0, 0 }, /* pr_pctmem */
{ 64, 8, 0, 0 }, /* pr_start */
{ 72, 8, 0, 0 }, /* pr_time */
{ 80, 8, 0, 0 }, /* pr_ctime */
{ 88, 1, 16, 0 }, /* pr_fname[] */
{ 104, 1, 80, 0 }, /* pr_psargs[] */
{ 184, 4, 0, 1 }, /* pr_wstat */
{ 188, 4, 0, 1 }, /* pr_argc */
{ 192, 4, 0, 0 }, /* pr_argv */
{ 196, 4, 0, 0 }, /* pr_envp */
{ 200, 1, 0, 0 }, /* pr_dmodel */
{ 204, 4, 0, 0 }, /* pr_taskid */
{ 208, 4, 0, 0 }, /* pr_projid */
{ 212, 4, 0, 1 }, /* pr_nzomb */
{ 216, 4, 0, 0 }, /* pr_poolid */
{ 220, 4, 0, 0 }, /* pr_zoneid */
{ 224, 4, 0, 0 }, /* pr_contract */
{ 232, 104, 0, 0 }, /* pr_lwp */
};
static const sl_prpsinfo_layout_t prpsinfo_layout = {
{ 0, 260, 0, 0 }, /* sizeof (prpsinfo_t) */
{ 0, 1, 0, 0 }, /* pr_state */
{ 1, 1, 0, 0 }, /* pr_sname */
{ 2, 1, 0, 0 }, /* pr_zomb */
{ 3, 1, 0, 0 }, /* pr_nice */
{ 4, 4, 0, 0 }, /* pr_flag */
{ 8, 4, 0, 0 }, /* pr_uid */
{ 12, 4, 0, 0 }, /* pr_gid */
{ 16, 4, 0, 0 }, /* pr_pid */
{ 20, 4, 0, 0 }, /* pr_ppid */
{ 24, 4, 0, 0 }, /* pr_pgrp */
{ 28, 4, 0, 0 }, /* pr_sid */
{ 32, 4, 0, 0 }, /* pr_addr */
{ 36, 4, 0, 0 }, /* pr_size */
{ 40, 4, 0, 0 }, /* pr_rssize */
{ 44, 4, 0, 0 }, /* pr_wchan */
{ 48, 8, 0, 0 }, /* pr_start */
{ 56, 8, 0, 0 }, /* pr_time */
{ 64, 4, 0, 1 }, /* pr_pri */
{ 68, 1, 0, 0 }, /* pr_oldpri */
{ 69, 1, 0, 0 }, /* pr_cpu */
{ 70, 2, 0, 0 }, /* pr_ottydev */
{ 72, 4, 0, 0 }, /* pr_lttydev */
{ 76, 1, 8, 0 }, /* pr_clname[] */
{ 84, 1, 16, 0 }, /* pr_fname[] */
{ 100, 1, 80, 0 }, /* pr_psargs[] */
{ 180, 2, 0, 1 }, /* pr_syscall */
{ 184, 8, 0, 0 }, /* pr_ctime */
{ 192, 4, 0, 0 }, /* pr_bysize */
{ 196, 4, 0, 0 }, /* pr_byrssize */
{ 200, 4, 0, 1 }, /* pr_argc */
{ 204, 4, 0, 0 }, /* pr_argv */
{ 208, 4, 0, 0 }, /* pr_envp */
{ 212, 4, 0, 1 }, /* pr_wstat */
{ 216, 2, 0, 0 }, /* pr_pctcpu */
{ 218, 2, 0, 0 }, /* pr_pctmem */
{ 220, 4, 0, 0 }, /* pr_euid */
{ 224, 4, 0, 0 }, /* pr_egid */
{ 228, 4, 0, 0 }, /* pr_aslwpid */
{ 232, 1, 0, 0 }, /* pr_dmodel */
};
static const sl_lwpsinfo_layout_t lwpsinfo_layout = {
{ 0, 104, 0, 0 }, /* sizeof (lwpsinfo_t) */
{ 0, 4, 0, 1 }, /* pr_flag */
{ 4, 4, 0, 0 }, /* pr_lwpid */
{ 8, 4, 0, 0 }, /* pr_addr */
{ 12, 4, 0, 0 }, /* pr_wchan */
{ 16, 1, 0, 0 }, /* pr_stype */
{ 17, 1, 0, 0 }, /* pr_state */
{ 18, 1, 0, 0 }, /* pr_sname */
{ 19, 1, 0, 0 }, /* pr_nice */
{ 20, 2, 0, 0 }, /* pr_syscall */
{ 22, 1, 0, 0 }, /* pr_oldpri */
{ 23, 1, 0, 0 }, /* pr_cpu */
{ 24, 4, 0, 1 }, /* pr_pri */
{ 28, 2, 0, 0 }, /* pr_pctcpu */
{ 32, 8, 0, 0 }, /* pr_start */
{ 40, 8, 0, 0 }, /* pr_time */
{ 48, 1, 8, 0 }, /* pr_clname[] */
{ 56, 1, 16, 0 }, /* pr_name[] */
{ 72, 4, 0, 1 }, /* pr_onpro */
{ 76, 4, 0, 1 }, /* pr_bindpro */
{ 80, 4, 0, 1 }, /* pr_bindpset */
{ 84, 4, 0, 1 }, /* pr_lgrp */
};
static const sl_prcred_layout_t prcred_layout = {
{ 0, 32, 0, 0 }, /* sizeof (prcred_t) */
{ 0, 4, 0, 0 }, /* pr_euid */
{ 4, 4, 0, 0 }, /* pr_ruid */
{ 8, 4, 0, 0 }, /* pr_suid */
{ 12, 4, 0, 0 }, /* pr_egid */
{ 16, 4, 0, 0 }, /* pr_rgid */
{ 20, 4, 0, 0 }, /* pr_sgid */
{ 24, 4, 0, 1 }, /* pr_ngroups */
{ 28, 4, 1, 0 }, /* pr_groups[] */
};
static const sl_prpriv_layout_t prpriv_layout = {
{ 0, 16, 0, 0 }, /* sizeof (prpriv_t) */
{ 0, 4, 0, 0 }, /* pr_nsets */
{ 4, 4, 0, 0 }, /* pr_setsize */
{ 8, 4, 0, 0 }, /* pr_infosize */
{ 12, 4, 1, 0 }, /* pr_sets[] */
};
static const sl_priv_impl_info_layout_t priv_impl_info_layout = {
{ 0, 28, 0, 0 }, /* sizeof (priv_impl_info_t) */
{ 0, 4, 0, 0 }, /* priv_headersize */
{ 4, 4, 0, 0 }, /* priv_flags */
{ 8, 4, 0, 0 }, /* priv_nsets */
{ 12, 4, 0, 0 }, /* priv_setsize */
{ 16, 4, 0, 0 }, /* priv_max */
{ 20, 4, 0, 0 }, /* priv_infosize */
{ 24, 4, 0, 0 }, /* priv_globalinfosize */
};
static const sl_fltset_layout_t fltset_layout = {
{ 0, 16, 0, 0 }, /* sizeof (fltset_t) */
{ 0, 4, 4, 0 }, /* word[] */
};
static const sl_siginfo_layout_t siginfo_layout = {
{ 0, 128, 0, 0 }, /* sizeof (siginfo_t) */
{ 0, 4, 0, 0 }, /* si_signo */
{ 8, 4, 0, 0 }, /* si_errno */
{ 4, 4, 0, 1 }, /* si_code */
{ 20, 4, 0, 0 }, /* si_value.sival_int */
{ 20, 4, 0, 0 }, /* si_value.sival_ptr */
{ 12, 4, 0, 0 }, /* si_pid */
{ 16, 4, 0, 0 }, /* si_uid */
{ 28, 4, 0, 0 }, /* si_ctid */
{ 32, 4, 0, 0 }, /* si_zoneid */
{ 12, 4, 0, 0 }, /* si_entity */
{ 12, 4, 0, 0 }, /* si_addr */
{ 20, 4, 0, 0 }, /* si_status */
{ 16, 4, 0, 0 }, /* si_band */
};
static const sl_sigset_layout_t sigset_layout = {
{ 0, 16, 0, 0 }, /* sizeof (sigset_t) */
{ 0, 4, 4, 0 }, /* __sigbits[] */
};
static const sl_sigaction_layout_t sigaction_layout = {
{ 0, 32, 0, 0 }, /* sizeof (struct sigaction) */
{ 0, 4, 0, 0 }, /* sa_flags */
{ 4, 4, 0, 0 }, /* sa_handler */
{ 4, 4, 0, 0 }, /* sa_sigaction */
{ 8, 16, 0, 0 }, /* sa_mask */
};
static const sl_stack_layout_t stack_layout = {
{ 0, 12, 0, 0 }, /* sizeof (stack_t) */
{ 0, 4, 0, 0 }, /* ss_sp */
{ 4, 4, 0, 0 }, /* ss_size */
{ 8, 4, 0, 0 }, /* ss_flags */
};
static const sl_sysset_layout_t sysset_layout = {
{ 0, 64, 0, 0 }, /* sizeof (sysset_t) */
{ 0, 4, 16, 0 }, /* word[] */
};
static const sl_timestruc_layout_t timestruc_layout = {
{ 0, 8, 0, 0 }, /* sizeof (timestruc_t) */
{ 0, 4, 0, 0 }, /* tv_sec */
{ 4, 4, 0, 0 }, /* tv_nsec */
};
static const sl_utsname_layout_t utsname_layout = {
{ 0, 1285, 0, 0 }, /* sizeof (struct utsname) */
{ 0, 1, 257, 0 }, /* sysname[] */
{ 257, 1, 257, 0 }, /* nodename[] */
{ 514, 1, 257, 0 }, /* release[] */
{ 771, 1, 257, 0 }, /* version[] */
{ 1028, 1, 257, 0 }, /* machine[] */
};
static const sl_prfdinfo_layout_t prfdinfo_layout = {
{ 0, 1088, 0, 0 }, /* sizeof (prfdinfo_core_t) */
{ 0, 4, 0, 0 }, /* pr_fd */
{ 4, 4, 0, 0 }, /* pr_mode */
{ 8, 4, 0, 0 }, /* pr_uid */
{ 12, 4, 0, 0 }, /* pr_gid */
{ 16, 4, 0, 0 }, /* pr_major */
{ 20, 4, 0, 0 }, /* pr_minor */
{ 24, 4, 0, 0 }, /* pr_rmajor */
{ 28, 4, 0, 0 }, /* pr_rminor */
{ 32, 8, 0, 0 }, /* pr_ino */
{ 40, 8, 0, 0 }, /* pr_offset */
{ 48, 8, 0, 0 }, /* pr_size */
{ 56, 4, 0, 0 }, /* pr_fileflags */
{ 60, 4, 0, 0 }, /* pr_fdflags */
{ 64, 1, 1024, 0 }, /* pr_path[] */
};
static const sl_prsecflags_layout_t prsecflags_layout = {
{ 0, 40, 0, 0 }, /* sizeof (prsecflags_t) */
{ 0, 4, 0, 0 }, /* pr_version */
{ 8, 8, 0, 0 }, /* pr_effective */
{ 16, 8, 0, 0 }, /* pr_inherit */
{ 24, 8, 0, 0 }, /* pr_lower */
{ 32, 8, 0, 0 }, /* pr_upper */
};
static const sl_prlwpname_layout_t prlwpname_layout = {
{ 0, 40, 0, 0 }, /* sizeof (prlwpname_t) */
{ 0, 8, 0, 0 }, /* pr_lwpid */
{ 8, 1, 32, 0 }, /* pr_lwpname[] */
};
static const sl_prupanic_layout_t prupanic_layout = {
{ 0, 1032, 0, 0 }, /* sizeof (prupanic_t) */
{ 0, 4, 0, 0 }, /* pru_version */
{ 4, 4, 0, 0 }, /* pru_flags */
{ 8, 1, 1024, 0 }, /* pru_data[] */
};
static const sl_prcwd_layout_t prcwd_layout = {
{ 0, 3096, 0, 0 }, /* sizeof (prcwd_t) */
{ 0, 8, 0, 0 }, /* prcwd_fsid */
{ 8, 1, 16, 0 }, /* prcwd_fsname[] */
{ 24, 1, 1024, 0 }, /* prcwd_mntpt[] */
{ 1048, 1, 1024, 0 }, /* prcwd_mntspec[] */
{ 2072, 1, 1024, 0 }, /* prcwd_cwd[] */
};
static const sl_arch_layout_t layout_sparc = {
&auxv_layout,
&fltset_layout,
&lwpsinfo_layout,
&lwpstatus_layout,
&prcred_layout,
&priv_impl_info_layout,
&prpriv_layout,
&psinfo_layout,
&pstatus_layout,
&prgregset_layout,
&prpsinfo_layout,
&prstatus_layout,
&sigaction_layout,
&siginfo_layout,
&sigset_layout,
&stack_layout,
&sysset_layout,
×truc_layout,
&utsname_layout,
&prfdinfo_layout,
&prsecflags_layout,
&prlwpname_layout,
&prupanic_layout,
&prcwd_layout,
};
const sl_arch_layout_t *
struct_layout_sparc(void)
{
return (&layout_sparc);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 2012 DEY Storage Systems, Inc. All rights reserved.
* Copyright 2018 Joyent, Inc.
* Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
*/
#include <struct_layout.h>
static const sl_auxv_layout_t auxv_layout = {
{ 0, 16, 0, 0 }, /* sizeof (auxv_t) */
{ 0, 4, 0, 1 }, /* a_type */
{ 8, 8, 0, 1 }, /* a_un.a_val */
{ 8, 8, 0, 0 }, /* a_un.a_ptr */
{ 8, 8, 0, 0 }, /* a_un.a_fcn */
};
static const sl_prgregset_layout_t prgregset_layout = {
{ 0, 304, 0, 0 }, /* sizeof (prgregset_t) */
{ 0, 8, 38, 0 }, /* elt0 */
};
static const sl_lwpstatus_layout_t lwpstatus_layout = {
{ 0, 1392, 0, 0 }, /* sizeof (lwpstatus_t) */
{ 0, 4, 0, 0 }, /* pr_flags */
{ 4, 4, 0, 0 }, /* pr_lwpid */
{ 8, 2, 0, 0 }, /* pr_why */
{ 10, 2, 0, 0 }, /* pr_what */
{ 12, 2, 0, 0 }, /* pr_cursig */
{ 16, 256, 0, 0 }, /* pr_info */
{ 272, 16, 0, 0 }, /* pr_lwppend */
{ 288, 16, 0, 0 }, /* pr_lwphold */
{ 304, 32, 0, 0 }, /* pr_action */
{ 336, 24, 0, 0 }, /* pr_altstack */
{ 360, 8, 0, 0 }, /* pr_oldcontext */
{ 368, 2, 0, 0 }, /* pr_syscall */
{ 370, 2, 0, 0 }, /* pr_nsysarg */
{ 372, 4, 0, 0 }, /* pr_errno */
{ 376, 8, 8, 0 }, /* pr_sysarg[] */
{ 440, 8, 0, 0 }, /* pr_rval1 */
{ 448, 8, 0, 0 }, /* pr_rval2 */
{ 456, 1, 8, 0 }, /* pr_clname[] */
{ 464, 16, 0, 0 }, /* pr_tstamp */
{ 480, 16, 0, 0 }, /* pr_utime */
{ 496, 16, 0, 0 }, /* pr_stime */
{ 524, 4, 0, 0 }, /* pr_errpriv */
{ 528, 8, 0, 0 }, /* pr_ustack */
{ 536, 8, 0, 0 }, /* pr_instr */
{ 544, 304, 0, 0 }, /* pr_reg */
{ 848, 544, 0, 0 }, /* pr_fpreg */
};
static const sl_pstatus_layout_t pstatus_layout = {
{ 0, 1776, 0, 0 }, /* sizeof (pstatus_t) */
{ 0, 4, 0, 1 }, /* pr_flags */
{ 4, 4, 0, 1 }, /* pr_nlwp */
{ 8, 4, 0, 0 }, /* pr_pid */
{ 12, 4, 0, 0 }, /* pr_ppid */
{ 16, 4, 0, 0 }, /* pr_pgid */
{ 20, 4, 0, 0 }, /* pr_sid */
{ 24, 4, 0, 1 }, /* pr_aslwpid */
{ 28, 4, 0, 1 }, /* pr_agentid */
{ 32, 16, 0, 0 }, /* pr_sigpend */
{ 48, 8, 0, 0 }, /* pr_brkbase */
{ 56, 8, 0, 0 }, /* pr_brksize */
{ 64, 8, 0, 0 }, /* pr_stkbase */
{ 72, 8, 0, 0 }, /* pr_stksize */
{ 80, 16, 0, 0 }, /* pr_utime */
{ 96, 16, 0, 0 }, /* pr_stime */
{ 112, 16, 0, 0 }, /* pr_cutime */
{ 128, 16, 0, 0 }, /* pr_cstime */
{ 144, 16, 0, 0 }, /* pr_sigtrace */
{ 160, 16, 0, 0 }, /* pr_flttrace */
{ 176, 64, 0, 0 }, /* pr_sysentry */
{ 240, 64, 0, 0 }, /* pr_sysexit */
{ 304, 1, 0, 0 }, /* pr_dmodel */
{ 308, 4, 0, 1 }, /* pr_taskid */
{ 312, 4, 0, 1 }, /* pr_projid */
{ 316, 4, 0, 1 }, /* pr_nzomb */
{ 320, 4, 0, 1 }, /* pr_zoneid */
{ 384, 1392, 0, 0 }, /* pr_lwp */
};
static const sl_prstatus_layout_t prstatus_layout = {
{ 0, 904, 0, 0 }, /* sizeof (prstatus_t) */
{ 0, 4, 0, 1 }, /* pr_flags */
{ 4, 2, 0, 1 }, /* pr_why */
{ 6, 2, 0, 1 }, /* pr_what */
{ 8, 256, 0, 0 }, /* pr_info */
{ 264, 2, 0, 1 }, /* pr_cursig */
{ 266, 2, 0, 0 }, /* pr_nlwp */
{ 268, 16, 0, 0 }, /* pr_sigpend */
{ 284, 16, 0, 0 }, /* pr_sighold */
{ 304, 24, 0, 0 }, /* pr_altstack */
{ 328, 32, 0, 0 }, /* pr_action */
{ 360, 4, 0, 0 }, /* pr_pid */
{ 364, 4, 0, 0 }, /* pr_ppid */
{ 368, 4, 0, 0 }, /* pr_pgrp */
{ 372, 4, 0, 0 }, /* pr_sid */
{ 376, 16, 0, 0 }, /* pr_utime */
{ 392, 16, 0, 0 }, /* pr_stime */
{ 408, 16, 0, 0 }, /* pr_cutime */
{ 424, 16, 0, 0 }, /* pr_cstime */
{ 440, 1, 8, 0 }, /* pr_clname[] */
{ 448, 2, 0, 1 }, /* pr_syscall */
{ 450, 2, 0, 1 }, /* pr_nsysarg */
{ 456, 8, 8, 1 }, /* pr_sysarg[] */
{ 520, 4, 0, 0 }, /* pr_who */
{ 524, 16, 0, 0 }, /* pr_lwppend */
{ 544, 8, 0, 0 }, /* pr_oldcontext */
{ 552, 8, 0, 0 }, /* pr_brkbase */
{ 560, 8, 0, 0 }, /* pr_brksize */
{ 568, 8, 0, 0 }, /* pr_stkbase */
{ 576, 8, 0, 0 }, /* pr_stksize */
{ 584, 2, 0, 1 }, /* pr_processor */
{ 586, 2, 0, 1 }, /* pr_bind */
{ 592, 8, 0, 1 }, /* pr_instr */
{ 600, 304, 0, 0 }, /* pr_reg */
};
static const sl_psinfo_layout_t psinfo_layout = {
{ 0, 416, 0, 0 }, /* sizeof (psinfo_t) */
{ 0, 4, 0, 1 }, /* pr_flag */
{ 4, 4, 0, 1 }, /* pr_nlwp */
{ 8, 4, 0, 0 }, /* pr_pid */
{ 12, 4, 0, 0 }, /* pr_ppid */
{ 16, 4, 0, 0 }, /* pr_pgid */
{ 20, 4, 0, 0 }, /* pr_sid */
{ 24, 4, 0, 0 }, /* pr_uid */
{ 28, 4, 0, 0 }, /* pr_euid */
{ 32, 4, 0, 0 }, /* pr_gid */
{ 36, 4, 0, 0 }, /* pr_egid */
{ 40, 8, 0, 0 }, /* pr_addr */
{ 48, 8, 0, 0 }, /* pr_size */
{ 56, 8, 0, 0 }, /* pr_rssize */
{ 72, 8, 0, 0 }, /* pr_ttydev */
{ 80, 2, 0, 0 }, /* pr_pctcpu */
{ 82, 2, 0, 0 }, /* pr_pctmem */
{ 88, 16, 0, 0 }, /* pr_start */
{ 104, 16, 0, 0 }, /* pr_time */
{ 120, 16, 0, 0 }, /* pr_ctime */
{ 136, 1, 16, 0 }, /* pr_fname[] */
{ 152, 1, 80, 0 }, /* pr_psargs[] */
{ 232, 4, 0, 1 }, /* pr_wstat */
{ 236, 4, 0, 1 }, /* pr_argc */
{ 240, 8, 0, 0 }, /* pr_argv */
{ 248, 8, 0, 0 }, /* pr_envp */
{ 256, 1, 0, 0 }, /* pr_dmodel */
{ 260, 4, 0, 0 }, /* pr_taskid */
{ 264, 4, 0, 0 }, /* pr_projid */
{ 268, 4, 0, 1 }, /* pr_nzomb */
{ 272, 4, 0, 0 }, /* pr_poolid */
{ 276, 4, 0, 0 }, /* pr_zoneid */
{ 280, 4, 0, 0 }, /* pr_contract */
{ 288, 128, 0, 0 }, /* pr_lwp */
};
static const sl_prpsinfo_layout_t prpsinfo_layout = {
{ 0, 328, 0, 0 }, /* sizeof (prpsinfo_t) */
{ 0, 1, 0, 0 }, /* pr_state */
{ 1, 1, 0, 0 }, /* pr_sname */
{ 2, 1, 0, 0 }, /* pr_zomb */
{ 3, 1, 0, 0 }, /* pr_nice */
{ 4, 4, 0, 0 }, /* pr_flag */
{ 8, 4, 0, 0 }, /* pr_uid */
{ 12, 4, 0, 0 }, /* pr_gid */
{ 16, 4, 0, 0 }, /* pr_pid */
{ 20, 4, 0, 0 }, /* pr_ppid */
{ 24, 4, 0, 0 }, /* pr_pgrp */
{ 28, 4, 0, 0 }, /* pr_sid */
{ 32, 8, 0, 0 }, /* pr_addr */
{ 40, 8, 0, 0 }, /* pr_size */
{ 48, 8, 0, 0 }, /* pr_rssize */
{ 56, 8, 0, 0 }, /* pr_wchan */
{ 64, 16, 0, 0 }, /* pr_start */
{ 80, 16, 0, 0 }, /* pr_time */
{ 96, 4, 0, 1 }, /* pr_pri */
{ 100, 1, 0, 0 }, /* pr_oldpri */
{ 101, 1, 0, 0 }, /* pr_cpu */
{ 102, 2, 0, 0 }, /* pr_ottydev */
{ 104, 8, 0, 0 }, /* pr_lttydev */
{ 112, 1, 8, 0 }, /* pr_clname[] */
{ 120, 1, 16, 0 }, /* pr_fname[] */
{ 136, 1, 80, 0 }, /* pr_psargs[] */
{ 216, 2, 0, 1 }, /* pr_syscall */
{ 224, 16, 0, 0 }, /* pr_ctime */
{ 240, 8, 0, 0 }, /* pr_bysize */
{ 248, 8, 0, 0 }, /* pr_byrssize */
{ 256, 4, 0, 1 }, /* pr_argc */
{ 264, 8, 0, 0 }, /* pr_argv */
{ 272, 8, 0, 0 }, /* pr_envp */
{ 280, 4, 0, 1 }, /* pr_wstat */
{ 284, 2, 0, 0 }, /* pr_pctcpu */
{ 286, 2, 0, 0 }, /* pr_pctmem */
{ 288, 4, 0, 0 }, /* pr_euid */
{ 292, 4, 0, 0 }, /* pr_egid */
{ 296, 4, 0, 0 }, /* pr_aslwpid */
{ 300, 1, 0, 0 }, /* pr_dmodel */
};
static const sl_lwpsinfo_layout_t lwpsinfo_layout = {
{ 0, 128, 0, 0 }, /* sizeof (lwpsinfo_t) */
{ 0, 4, 0, 1 }, /* pr_flag */
{ 4, 4, 0, 0 }, /* pr_lwpid */
{ 8, 8, 0, 0 }, /* pr_addr */
{ 16, 8, 0, 0 }, /* pr_wchan */
{ 24, 1, 0, 0 }, /* pr_stype */
{ 25, 1, 0, 0 }, /* pr_state */
{ 26, 1, 0, 0 }, /* pr_sname */
{ 27, 1, 0, 0 }, /* pr_nice */
{ 28, 2, 0, 0 }, /* pr_syscall */
{ 30, 1, 0, 0 }, /* pr_oldpri */
{ 31, 1, 0, 0 }, /* pr_cpu */
{ 32, 4, 0, 1 }, /* pr_pri */
{ 36, 2, 0, 0 }, /* pr_pctcpu */
{ 40, 16, 0, 0 }, /* pr_start */
{ 56, 16, 0, 0 }, /* pr_time */
{ 72, 1, 8, 0 }, /* pr_clname[] */
{ 80, 1, 16, 0 }, /* pr_name[] */
{ 96, 4, 0, 1 }, /* pr_onpro */
{ 100, 4, 0, 1 }, /* pr_bindpro */
{ 104, 4, 0, 1 }, /* pr_bindpset */
{ 108, 4, 0, 1 }, /* pr_lgrp */
};
static const sl_prcred_layout_t prcred_layout = {
{ 0, 32, 0, 0 }, /* sizeof (prcred_t) */
{ 0, 4, 0, 0 }, /* pr_euid */
{ 4, 4, 0, 0 }, /* pr_ruid */
{ 8, 4, 0, 0 }, /* pr_suid */
{ 12, 4, 0, 0 }, /* pr_egid */
{ 16, 4, 0, 0 }, /* pr_rgid */
{ 20, 4, 0, 0 }, /* pr_sgid */
{ 24, 4, 0, 1 }, /* pr_ngroups */
{ 28, 4, 1, 0 }, /* pr_groups[] */
};
static const sl_prpriv_layout_t prpriv_layout = {
{ 0, 16, 0, 0 }, /* sizeof (prpriv_t) */
{ 0, 4, 0, 0 }, /* pr_nsets */
{ 4, 4, 0, 0 }, /* pr_setsize */
{ 8, 4, 0, 0 }, /* pr_infosize */
{ 12, 4, 1, 0 }, /* pr_sets[] */
};
static const sl_priv_impl_info_layout_t priv_impl_info_layout = {
{ 0, 28, 0, 0 }, /* sizeof (priv_impl_info_t) */
{ 0, 4, 0, 0 }, /* priv_headersize */
{ 4, 4, 0, 0 }, /* priv_flags */
{ 8, 4, 0, 0 }, /* priv_nsets */
{ 12, 4, 0, 0 }, /* priv_setsize */
{ 16, 4, 0, 0 }, /* priv_max */
{ 20, 4, 0, 0 }, /* priv_infosize */
{ 24, 4, 0, 0 }, /* priv_globalinfosize */
};
static const sl_fltset_layout_t fltset_layout = {
{ 0, 16, 0, 0 }, /* sizeof (fltset_t) */
{ 0, 4, 4, 0 }, /* word[] */
};
static const sl_siginfo_layout_t siginfo_layout = {
{ 0, 256, 0, 0 }, /* sizeof (siginfo_t) */
{ 0, 4, 0, 0 }, /* si_signo */
{ 8, 4, 0, 0 }, /* si_errno */
{ 4, 4, 0, 1 }, /* si_code */
{ 32, 4, 0, 0 }, /* si_value.sival_int */
{ 32, 8, 0, 0 }, /* si_value.sival_ptr */
{ 16, 4, 0, 0 }, /* si_pid */
{ 24, 4, 0, 0 }, /* si_uid */
{ 48, 4, 0, 0 }, /* si_ctid */
{ 52, 4, 0, 0 }, /* si_zoneid */
{ 16, 4, 0, 0 }, /* si_entity */
{ 16, 8, 0, 0 }, /* si_addr */
{ 32, 4, 0, 0 }, /* si_status */
{ 24, 8, 0, 0 }, /* si_band */
};
static const sl_sigset_layout_t sigset_layout = {
{ 0, 16, 0, 0 }, /* sizeof (sigset_t) */
{ 0, 4, 4, 0 }, /* __sigbits[] */
};
static const sl_sigaction_layout_t sigaction_layout = {
{ 0, 32, 0, 0 }, /* sizeof (struct sigaction) */
{ 0, 4, 0, 0 }, /* sa_flags */
{ 8, 8, 0, 0 }, /* sa_handler */
{ 8, 8, 0, 0 }, /* sa_sigaction */
{ 16, 16, 0, 0 }, /* sa_mask */
};
static const sl_stack_layout_t stack_layout = {
{ 0, 24, 0, 0 }, /* sizeof (stack_t) */
{ 0, 8, 0, 0 }, /* ss_sp */
{ 8, 8, 0, 0 }, /* ss_size */
{ 16, 4, 0, 0 }, /* ss_flags */
};
static const sl_sysset_layout_t sysset_layout = {
{ 0, 64, 0, 0 }, /* sizeof (sysset_t) */
{ 0, 4, 16, 0 }, /* word[] */
};
static const sl_timestruc_layout_t timestruc_layout = {
{ 0, 16, 0, 0 }, /* sizeof (timestruc_t) */
{ 0, 8, 0, 0 }, /* tv_sec */
{ 8, 8, 0, 0 }, /* tv_nsec */
};
static const sl_utsname_layout_t utsname_layout = {
{ 0, 1285, 0, 0 }, /* sizeof (struct utsname) */
{ 0, 1, 257, 0 }, /* sysname[] */
{ 257, 1, 257, 0 }, /* nodename[] */
{ 514, 1, 257, 0 }, /* release[] */
{ 771, 1, 257, 0 }, /* version[] */
{ 1028, 1, 257, 0 }, /* machine[] */
};
static const sl_prfdinfo_layout_t prfdinfo_layout = {
{ 0, 1088, 0, 0 }, /* sizeof (prfdinfo_core_t) */
{ 0, 4, 0, 0 }, /* pr_fd */
{ 4, 4, 0, 0 }, /* pr_mode */
{ 8, 4, 0, 0 }, /* pr_uid */
{ 12, 4, 0, 0 }, /* pr_gid */
{ 16, 4, 0, 0 }, /* pr_major */
{ 20, 4, 0, 0 }, /* pr_minor */
{ 24, 4, 0, 0 }, /* pr_rmajor */
{ 28, 4, 0, 0 }, /* pr_rminor */
{ 32, 8, 0, 0 }, /* pr_ino */
{ 40, 8, 0, 0 }, /* pr_offset */
{ 48, 8, 0, 0 }, /* pr_size */
{ 56, 4, 0, 0 }, /* pr_fileflags */
{ 60, 4, 0, 0 }, /* pr_fdflags */
{ 64, 1, 1024, 0 }, /* pr_path[] */
};
static const sl_prsecflags_layout_t prsecflags_layout = {
{ 0, 40, 0, 0 }, /* sizeof (prsecflags_t) */
{ 0, 4, 0, 0 }, /* pr_version */
{ 8, 8, 0, 0 }, /* pr_effective */
{ 16, 8, 0, 0 }, /* pr_inherit */
{ 24, 8, 0, 0 }, /* pr_lower */
{ 32, 8, 0, 0 }, /* pr_upper */
};
static const sl_prlwpname_layout_t prlwpname_layout = {
{ 0, 40, 0, 0 }, /* sizeof (prlwpname_t) */
{ 0, 8, 0, 0 }, /* pr_lwpid */
{ 8, 1, 32, 0 }, /* pr_lwpname[] */
};
static const sl_prupanic_layout_t prupanic_layout = {
{ 0, 1032, 0, 0 }, /* sizeof (prupanic_t) */
{ 0, 4, 0, 0 }, /* pru_version */
{ 4, 4, 0, 0 }, /* pru_flags */
{ 8, 1, 1024, 0 }, /* pru_data[] */
};
static const sl_prcwd_layout_t prcwd_layout = {
{ 0, 3096, 0, 0 }, /* sizeof (prcwd_t) */
{ 0, 8, 0, 0 }, /* prcwd_fsid */
{ 8, 1, 16, 0 }, /* prcwd_fsname[] */
{ 24, 1, 1024, 0 }, /* prcwd_mntpt[] */
{ 1048, 1, 1024, 0 }, /* prcwd_mntspec[] */
{ 2072, 1, 1024, 0 }, /* prcwd_cwd[] */
};
static const sl_arch_layout_t layout_sparcv9 = {
&auxv_layout,
&fltset_layout,
&lwpsinfo_layout,
&lwpstatus_layout,
&prcred_layout,
&priv_impl_info_layout,
&prpriv_layout,
&psinfo_layout,
&pstatus_layout,
&prgregset_layout,
&prpsinfo_layout,
&prstatus_layout,
&sigaction_layout,
&siginfo_layout,
&sigset_layout,
&stack_layout,
&sysset_layout,
×truc_layout,
&utsname_layout,
&prfdinfo_layout,
&prsecflags_layout,
&prlwpname_layout,
&prupanic_layout,
&prcwd_layout,
};
const sl_arch_layout_t *
struct_layout_sparcv9(void)
{
return (&layout_sparcv9);
}
|