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
|
#
# 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.
#
# lib/brand/Makefile
#
# include global definitions
include ../../Makefile.master
#
# Build everything in parallel; use .WAIT for dependencies
.PARALLEL:
# Hammerhead: Remove solaris10 (32-bit brand, Hammerhead is 64-bit only)
SUBDIRS= shared .WAIT sn1 ipkg labeled $($(MACH)_SUBDIRS)
MSGSUBDIRS= shared $($(MACH)_MSGSUBDIRS)
all : TARGET= all
install : TARGET= install
clean : TARGET= clean
clobber : TARGET= clobber
_msg : TARGET= _msg
.KEEP_STATE:
all install clean clobber: $(SUBDIRS)
_msg: $(MSGSUBDIRS)
$(filter-out .WAIT,$(SUBDIRS)): FRC
@cd $@; pwd; $(MAKE) $(TARGET)
FRC:
#
# 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.
#
include $(SRC)/Makefile.master
ROOTDIR= $(ROOT)/usr/lib/brand
ROOTTEMPLATEDIR= $(ROOT)/etc/zones
ROOTBRANDDIR= $(ROOTDIR)/$(BRAND)
ROOTBRANDDIR64= $(ROOTDIR)/$(BRAND)/$(MACH64)
ROOTSHAREDDIR= $(ROOTDIR)/shared
ETCBRANDDIR= $(ROOT)/etc/brand/$(BRAND)
ROOTPROGS= $(PROGS:%=$(ROOTBRANDDIR)/%)
ROOTTXTS= $(TXTS:%=$(ROOTBRANDDIR)/%)
ROOTXMLDOCS= $(XMLDOCS:%=$(ROOTBRANDDIR)/%)
ROOTSHARED= $(SHARED:%=$(ROOTSHAREDDIR)/%)
ETCUSER= $(USERFILES:%=$(ETCBRANDDIR)/%)
BRAND_SHARED= $(SRC)/lib/brand/shared
ROOTTEMPLATES= $(TEMPLATES:%=$(ROOTTEMPLATEDIR)/%)
$(ROOTBRANDDIR) : FILEMODE = 755
$(ROOTXMLDOCS) : FILEMODE = 444
$(ROOTSHARED) : FILEMODE = 755
$(ROOTTEMPLATEDIR) : FILEMODE = 755
$(ROOTTEMPLATES) : FILEMODE = 444
$(ROOTTXTS) : FILEMODE = 444
$(ROOTPROGS) : FILEMODE = 755
$(ROOTBRANDDIR)/% $(ROOTBRANDDIR64)/% $(ROOTTEMPLATEDIR)/% $(ROOTSHAREDDIR)/% $(ETCBRANDDIR)/%: %
$(INS.file)
$(ETCUSER) : FILEMODE = 644
$(ETCUSER) : OWNER = root
$(ETCUSER) : GROUP = sys
.SUFFIXES: .ksh
.ksh:
$(RM) $@
$(CAT) $< > $@
$(CHMOD) +x $@
#
# 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.
#
default: all
# Build everything in parallel; use .WAIT for dependencies
.PARALLEL:
SUBDIRS = zone
all : TARGET= all
install : TARGET= install
clean : TARGET= clean
clobber : TARGET= clobber
all install clean clobber: $(SUBDIRS)
$(SUBDIRS): FRC
@cd $@; pwd; $(MAKE) $(TARGET)
FRC:
#
# 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.
#
# lib/brand/ipkg/Makefile.ipkg
#
# include global definitions
BRAND = ipkg
include $(SRC)/lib/brand/Makefile.brand
#
# 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.
#
TEMPLATES= SUNWdefault.xml SUNWblank.xml
XMLDOCS= config.xml platform.xml
CLOBBERFILES= $(ROOTXMLDOCS) $(ROOTTEMPLATES)
all:
include $(SRC)/cmd/Makefile.cmd
include ../Makefile.ipkg
install: $(ROOTXMLDOCS) $(ROOTTEMPLATES)
clean:
include $(SRC)/cmd/Makefile.targ
<?xml version="1.0"?>
<!--
Copyright 2010 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
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
DO NOT EDIT THIS FILE. Use zonecfg(8) instead.
-->
<!DOCTYPE zone PUBLIC "-//Sun Microsystems Inc//DTD Zones//EN" "file:///usr/share/lib/xml/dtd/zonecfg.dtd.1">
<zone name="blank" zonepath="" autoboot="false" brand="ipkg">
</zone>
<?xml version="1.0"?>
<!--
Copyright 2010 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
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
DO NOT EDIT THIS FILE. Use zonecfg(8) instead.
-->
<!DOCTYPE zone PUBLIC "-//Sun Microsystems Inc//DTD Zones//EN" "file:///usr/share/lib/xml/dtd/zonecfg.dtd.1">
<zone name="default" zonepath="" autoboot="false" brand="ipkg">
</zone>
<?xml version="1.0"?>
<!--
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.
DO NOT EDIT THIS FILE.
Copyright 2014 Nexenta Systems, Inc. All rights reserved.
-->
<!DOCTYPE brand PUBLIC "-//Sun Microsystems Inc//DTD Brands//EN"
"file:///usr/share/lib/xml/dtd/brand.dtd.1">
<brand name="ipkg">
<modname></modname>
<initname>/sbin/init</initname>
<login_cmd>/usr/bin/login -z %Z %u</login_cmd>
<forcedlogin_cmd>/usr/bin/login -z %Z -f %u</forcedlogin_cmd>
<user_cmd>/usr/bin/getent passwd %u</user_cmd>
<!-- We may not be able to do the create in pkg(1) proper. -->
<install>/usr/lib/brand/ipkg/pkgcreatezone -z %z -R %R</install>
<installopts>a:c:d:e:hk:P:p:suv</installopts>
<boot></boot>
<sysboot>/usr/lib/brand/ipkg/prestate %z %R 2 0</sysboot>
<halt></halt>
<shutdown>/sbin/shutdown -y -g0 -i5</shutdown>
<verify_cfg></verify_cfg>
<verify_adm></verify_adm>
<postclone></postclone>
<postinstall></postinstall>
<attach>/usr/lib/brand/ipkg/attach %z %R</attach>
<detach>/usr/lib/brand/ipkg/detach -z %z -R %R</detach>
<clone>/usr/lib/brand/ipkg/clone -z %z -R %R</clone>
<uninstall>/usr/lib/brand/ipkg/uninstall %z %R</uninstall>
<prestatechange>/usr/lib/brand/ipkg/prestate %z %R</prestatechange>
<poststatechange>/usr/lib/brand/ipkg/poststate %z %R</poststatechange>
<query>/usr/lib/brand/shared/query %z %R</query>
<privilege set="default" name="contract_event" />
<privilege set="default" name="contract_identity" />
<privilege set="default" name="contract_observer" />
<privilege set="default" name="file_chown" />
<privilege set="default" name="file_chown_self" />
<privilege set="default" name="file_dac_execute" />
<privilege set="default" name="file_dac_read" />
<privilege set="default" name="file_dac_search" />
<privilege set="default" name="file_dac_write" />
<privilege set="default" name="file_owner" />
<privilege set="default" name="file_setid" />
<privilege set="default" name="ipc_dac_read" />
<privilege set="default" name="ipc_dac_write" />
<privilege set="default" name="ipc_owner" />
<privilege set="default" name="net_bindmlp" />
<privilege set="default" name="net_icmpaccess" />
<privilege set="default" name="net_mac_aware" />
<privilege set="default" name="net_observability" />
<privilege set="default" name="net_privaddr" />
<privilege set="default" name="net_rawaccess" ip-type="exclusive" />
<privilege set="default" name="proc_chroot" />
<privilege set="default" name="sys_audit" />
<privilege set="default" name="proc_audit" />
<privilege set="default" name="proc_lock_memory" />
<privilege set="default" name="proc_owner" />
<privilege set="default" name="proc_secflags" />
<privilege set="default" name="proc_setid" />
<privilege set="default" name="proc_taskid" />
<privilege set="default" name="sys_acct" />
<privilege set="default" name="sys_admin" />
<privilege set="default" name="sys_ip_config" ip-type="exclusive" />
<privilege set="default" name="sys_iptun_config" ip-type="exclusive" />
<privilege set="default" name="sys_mount" />
<privilege set="default" name="sys_nfs" />
<privilege set="default" name="sys_ppp_config" ip-type="exclusive" />
<privilege set="default" name="sys_resource" />
<privilege set="default" name="sys_smb" />
<privilege set="prohibited" name="dtrace_kernel" />
<privilege set="prohibited" name="proc_zone" />
<privilege set="prohibited" name="sys_config" />
<privilege set="prohibited" name="sys_devices" />
<privilege set="prohibited" name="sys_ip_config" ip-type="shared" />
<privilege set="prohibited" name="sys_linkdir" />
<privilege set="prohibited" name="sys_net_config" />
<privilege set="prohibited" name="sys_res_config" />
<privilege set="prohibited" name="sys_suser_compat" />
<privilege set="prohibited" name="xvm_control" />
<privilege set="prohibited" name="virt_manage" />
<privilege set="prohibited" name="sys_ppp_config" ip-type="shared" />
<privilege set="required" name="proc_exec" />
<privilege set="required" name="proc_fork" />
<privilege set="required" name="sys_ip_config" ip-type="exclusive" />
<privilege set="required" name="sys_mount" />
</brand>
<?xml version="1.0"?>
<!--
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 2018 Nexenta Systems, Inc.
Copyright 2021 Joyent, Inc.
DO NOT EDIT THIS FILE.
-->
<!DOCTYPE platform PUBLIC "-//Sun Microsystems Inc//Zones Platform//EN"
"file:///usr/share/lib/xml/dtd/zone_platform.dtd.1">
<platform name="ipkg" allow-exclusive-ip="true">
<!-- Global filesystems to mount when booting the zone -->
<global_mount special="/dev" directory="/dev" type="dev"
opt="attrdir=%R/root/dev"/>
<!-- Local filesystems to mount when booting the zone -->
<mount special="/proc" directory="/proc" type="proc" />
<mount special="ctfs" directory="/system/contract" type="ctfs" />
<mount special="mnttab" directory="/etc/mnttab" type="mntfs" />
<mount special="objfs" directory="/system/object" type="objfs" />
<mount special="swap" directory="/etc/svc/volatile" type="tmpfs" />
<mount special="sharefs" directory="/etc/dfs/sharetab" type="sharefs" />
<!-- Devices to create under /dev -->
<device match="arp" />
<device match="bpf" />
<device match="conslog" />
<device match="cpu/self/cpuid" />
<device match="crypto" />
<device match="cryptoadm" />
<device match="dsk" />
<device match="dtrace/*" />
<device match="dtrace/provider/*" />
<device match="eventfd" />
<device match="fd" />
<device match="full" />
<device match="ipnet" />
<device match="kstat" />
<device match="lo0" />
<device match="lofictl" />
<device match="lofi" />
<device match="log" />
<device match="logindmux" />
<device match="nsmb" />
<device match="net/*" />
<device match="null" />
<device match="openprom" arch="sparc" />
<device match="poll" />
<device match="pool" />
<device match="ptmx" />
<device match="pts/*" />
<device match="random" />
<device match="rdsk" />
<device match="rlofi" />
<device match="rmt" />
<device match="sad/user" />
<device match="signalfd" />
<device match="smbsrv" />
<device match="smbsrv1" />
<device match="svvslo0" />
<device match="svvslo1" />
<device match="svvslo2" />
<device match="svvslo3" />
<device match="swap" />
<device match="sysevent" />
<device match="tcp" />
<device match="tcp6" />
<device match="term" />
<device match="ticlts" />
<device match="ticots" />
<device match="ticotsord" />
<device match="tty" />
<device match="udp" />
<device match="udp6" />
<device match="urandom" />
<device match="zero" />
<device match="zfs" />
<!-- Devices to create in exclusive IP zone only -->
<device match="dld" ip-type="exclusive" />
<device match="icmp" ip-type="exclusive" />
<device match="icmp6" ip-type="exclusive" />
<device match="ip" ip-type="exclusive" />
<device match="ip6" ip-type="exclusive" />
<device match="ipauth" ip-type="exclusive" />
<device match="ipf" ip-type="exclusive" />
<device match="ipl" ip-type="exclusive" />
<device match="iplookup" ip-type="exclusive" />
<device match="ipmpstub" ip-type="exclusive" />
<device match="ipnat" ip-type="exclusive" />
<device match="ipscan" ip-type="exclusive" />
<device match="ipsecah" ip-type="exclusive" />
<device match="ipsecesp" ip-type="exclusive" />
<device match="ipstate" ip-type="exclusive" />
<device match="ipsync" ip-type="exclusive" />
<device match="keysock" ip-type="exclusive" />
<device match="rawip" ip-type="exclusive" />
<device match="rawip6" ip-type="exclusive" />
<device match="rts" ip-type="exclusive" />
<device match="sad/admin" ip-type="exclusive" />
<device match="sctp" ip-type="exclusive" />
<device match="sctp6" ip-type="exclusive" />
<device match="spdsock" ip-type="exclusive" />
<device match="sppp" ip-type="exclusive" />
<device match="sppptun" ip-type="exclusive" />
<device match="vni" ip-type="exclusive" />
<!-- Renamed devices to create under /dev -->
<device match="zcons/%z/zoneconsole" name="zconsole" />
<!-- Symlinks to create under /dev -->
<symlink source="console" target="zconsole" />
<symlink source="dtremote" target="/dev/null" />
<symlink source="msglog" target="zconsole" />
<symlink source="stderr" target="./fd/2" />
<symlink source="stdin" target="./fd/0" />
<symlink source="stdout" target="./fd/1" />
<symlink source="syscon" target="zconsole" />
<symlink source="sysmsg" target="zconsole" />
<symlink source="systty" target="zconsole" />
</platform>
#
# 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.
#
default: all
.PARALLEL:
SUBDIRS = zone
all : TARGET= all
install : TARGET= install
clean : TARGET= clean
clobber : TARGET= clobber
all install clean clobber: $(SUBDIRS)
$(SUBDIRS): FRC
@cd $@; pwd; $(MAKE) $(TARGET)
FRC:
#
# 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.
#
# lib/brand/labeled/Makefile.labeled
#
# include global definitions
BRAND = labeled
include $(SRC)/lib/brand/Makefile.brand
#
# 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.
#
XMLDOCS= config.xml platform.xml
CLOBBERFILES= $(ROOTXMLDOCS)
all:
include $(SRC)/cmd/Makefile.cmd
include ../Makefile.labeled
install: $(ROOTXMLDOCS)
clean:
include $(SRC)/cmd/Makefile.targ
<?xml version="1.0"?>
<!--
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.
DO NOT EDIT THIS FILE.
Copyright 2014 Nexenta Systems, Inc. All rights reserved.
-->
<!DOCTYPE brand PUBLIC "-//Sun Microsystems Inc//DTD Brands//EN"
"file:///usr/share/lib/xml/dtd/brand.dtd.1">
<brand name="labeled">
<modname></modname>
<initname>/sbin/init</initname>
<login_cmd>/usr/bin/login -z %Z %u</login_cmd>
<forcedlogin_cmd>/usr/bin/login -z %Z -f %u</forcedlogin_cmd>
<user_cmd>/usr/bin/getent passwd %u</user_cmd>
<!-- We may not be able to do the create in pkg(1) proper. -->
<install>/usr/lib/brand/ipkg/pkgcreatezone -z %z -R %R</install>
<installopts>a:c:d:e:hk:P:p:suv</installopts>
<boot></boot>
<sysboot>/usr/lib/brand/ipkg/prestate %z %R 2 0</sysboot>
<halt></halt>
<shutdown>/sbin/shutdown -y -g0 -i5</shutdown>
<verify_cfg></verify_cfg>
<verify_adm></verify_adm>
<postclone></postclone>
<postinstall></postinstall>
<attach>/usr/lib/brand/ipkg/attach %z %R</attach>
<detach>/usr/lib/brand/ipkg/detach -z %z -R %R</detach>
<clone>/usr/lib/brand/ipkg/clone -z %z -R %R</clone>
<uninstall>/usr/lib/brand/ipkg/uninstall %z %R</uninstall>
<prestatechange>/usr/lib/brand/ipkg/prestate %z %R</prestatechange>
<poststatechange>/usr/lib/brand/ipkg/poststate %z %R</poststatechange>
<query>/usr/lib/brand/shared/query %z %R</query>
<privilege set="default" name="contract_event" />
<privilege set="default" name="contract_identity" />
<privilege set="default" name="contract_observer" />
<privilege set="default" name="file_chown" />
<privilege set="default" name="file_chown_self" />
<privilege set="default" name="file_dac_execute" />
<privilege set="default" name="file_dac_read" />
<privilege set="default" name="file_dac_search" />
<privilege set="default" name="file_dac_write" />
<privilege set="default" name="file_owner" />
<privilege set="default" name="file_setid" />
<privilege set="default" name="ipc_dac_read" />
<privilege set="default" name="ipc_dac_write" />
<privilege set="default" name="ipc_owner" />
<privilege set="default" name="net_bindmlp" />
<privilege set="default" name="net_icmpaccess" />
<privilege set="default" name="net_mac_aware" />
<privilege set="default" name="net_observability" />
<privilege set="default" name="net_privaddr" />
<privilege set="default" name="net_rawaccess" ip-type="exclusive" />
<privilege set="default" name="proc_chroot" />
<privilege set="default" name="sys_audit" />
<privilege set="default" name="proc_audit" />
<privilege set="default" name="proc_lock_memory" />
<privilege set="default" name="proc_owner" />
<privilege set="default" name="proc_secflags" />
<privilege set="default" name="proc_setid" />
<privilege set="default" name="proc_taskid" />
<privilege set="default" name="sys_acct" />
<privilege set="default" name="sys_admin" />
<privilege set="default" name="sys_ip_config" ip-type="exclusive" />
<privilege set="default" name="sys_iptun_config" ip-type="exclusive" />
<privilege set="default" name="sys_mount" />
<privilege set="default" name="sys_nfs" />
<privilege set="default" name="sys_resource" />
<privilege set="default" name="sys_ppp_config" ip-type="exclusive" />
<privilege set="prohibited" name="dtrace_kernel" />
<privilege set="prohibited" name="proc_zone" />
<privilege set="prohibited" name="sys_config" />
<privilege set="prohibited" name="sys_devices" />
<privilege set="prohibited" name="sys_ip_config" ip-type="shared" />
<privilege set="prohibited" name="sys_linkdir" />
<privilege set="prohibited" name="sys_net_config" />
<privilege set="prohibited" name="sys_res_config" />
<privilege set="prohibited" name="sys_suser_compat" />
<privilege set="prohibited" name="xvm_control" />
<privilege set="prohibited" name="virt_manage" />
<privilege set="prohibited" name="sys_ppp_config" ip-type="shared" />
<privilege set="required" name="proc_exec" />
<privilege set="required" name="proc_fork" />
<privilege set="required" name="sys_ip_config" ip-type="exclusive" />
<privilege set="required" name="sys_mount" />
</brand>
<?xml version="1.0"?>
<!--
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.
DO NOT EDIT THIS FILE.
-->
<!DOCTYPE platform PUBLIC "-//Sun Microsystems Inc//Zones Platform//EN"
"file:///usr/share/lib/xml/dtd/zone_platform.dtd.1">
<platform name="labeled" allow-exclusive-ip="true">
<!-- Global filesystems to mount when booting the zone -->
<global_mount special="/dev" directory="/dev" type="dev"
opt="attrdir=%R/root/dev"/>
<!--
etc/gconf has GNOME settings; this mount facilitates sharing
the global zone settings with the labeled zone.
-->
<global_mount special="/etc/gconf" directory="/etc/gconf-global"
type="lofs"/>
<!--
Export rendezvous files for global zone services including
Xorg, nscd, and labeld.
-->
<global_mount special="/var/tsol/doors"
directory="/var/tsol/doors" type="lofs"/>
<!-- Local filesystems to mount when booting the zone -->
<mount special="/proc" directory="/proc" type="proc" />
<mount special="ctfs" directory="/system/contract" type="ctfs" />
<mount special="mnttab" directory="/etc/mnttab" type="mntfs" />
<mount special="objfs" directory="/system/object" type="objfs" />
<mount special="swap" directory="/etc/svc/volatile" type="tmpfs" />
<!-- Devices to create under /dev -->
<device match="arp" />
<device match="bpf" />
<device match="conslog" />
<device match="cpu/self/cpuid" />
<device match="crypto" />
<device match="cryptoadm" />
<device match="dsk" />
<device match="dtrace/*" />
<device match="dtrace/provider/*" />
<device match="eventfd" />
<device match="fd" />
<device match="full" />
<device match="ipnet" />
<device match="kstat" />
<device match="lo0" />
<device match="log" />
<device match="logindmux" />
<device match="nsmb" />
<device match="net/*" />
<device match="null" />
<device match="openprom" arch="sparc" />
<device match="poll" />
<device match="pool" />
<device match="ptmx" />
<device match="pts/*" />
<device match="random" />
<device match="rdsk" />
<device match="rmt" />
<device match="sad/user" />
<device match="svvslo0" />
<device match="svvslo1" />
<device match="svvslo2" />
<device match="svvslo3" />
<device match="swap" />
<device match="sysevent" />
<device match="tcp" />
<device match="tcp6" />
<device match="term" />
<device match="ticlts" />
<device match="ticots" />
<device match="ticotsord" />
<device match="tty" />
<device match="udp" />
<device match="udp6" />
<device match="urandom" />
<device match="zero" />
<device match="zfs" />
<!-- Devices to create in exclusive IP zone only -->
<device match="dld" ip-type="exclusive" />
<device match="icmp" ip-type="exclusive" />
<device match="icmp6" ip-type="exclusive" />
<device match="ip" ip-type="exclusive" />
<device match="ip6" ip-type="exclusive" />
<device match="ipauth" ip-type="exclusive" />
<device match="ipf" ip-type="exclusive" />
<device match="ipl" ip-type="exclusive" />
<device match="iplookup" ip-type="exclusive" />
<device match="ipmpstub" ip-type="exclusive" />
<device match="ipnat" ip-type="exclusive" />
<device match="ipscan" ip-type="exclusive" />
<device match="ipsecah" ip-type="exclusive" />
<device match="ipsecesp" ip-type="exclusive" />
<device match="ipstate" ip-type="exclusive" />
<device match="ipsync" ip-type="exclusive" />
<device match="keysock" ip-type="exclusive" />
<device match="rawip" ip-type="exclusive" />
<device match="rawip6" ip-type="exclusive" />
<device match="rts" ip-type="exclusive" />
<device match="sad/admin" ip-type="exclusive" />
<device match="sctp" ip-type="exclusive" />
<device match="sctp6" ip-type="exclusive" />
<device match="spdsock" ip-type="exclusive" />
<device match="sppp" ip-type="exclusive" />
<device match="sppptun" ip-type="exclusive" />
<device match="vni" ip-type="exclusive" />
<!-- Renamed devices to create under /dev -->
<device match="zcons/%z/zoneconsole" name="zconsole" />
<!-- Symlinks to create under /dev -->
<symlink source="console" target="zconsole" />
<symlink source="dtremote" target="/dev/null" />
<symlink source="msglog" target="zconsole" />
<symlink source="stderr" target="./fd/2" />
<symlink source="stdin" target="./fd/0" />
<symlink source="stdout" target="./fd/1" />
<symlink source="syscon" target="zconsole" />
<symlink source="sysmsg" target="zconsole" />
<symlink source="systty" target="zconsole" />
</platform>
#
# 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) 2010, Oracle and/or its affiliates. All rights reserved.
#
default: all
# Build everything in parallel; use .WAIT for dependencies
.PARALLEL:
SUBDIRS = brand zone
MSGSUBDIRS = zone
all : TARGET= all
install : TARGET= install
clean : TARGET= clean
clobber : TARGET= clobber
_msg : TARGET= _msg
.KEEP_STATE:
all install clean clobber: $(SUBDIRS)
_msg: $(MSGSUBDIRS)
$(SUBDIRS): FRC
@cd $@; pwd; $(MAKE) $(TARGET)
FRC:
#
# 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) 2010, Oracle and/or its affiliates. All rights reserved.
#
include $(SRC)/lib/Makefile.lib
default: all
# Hammerhead: amd64-only
SUBDIRS = $(MACH64)
all : TARGET= all
clean : TARGET= clean
clobber : TARGET= clobber
install : TARGET= install
_msg : TARGET= _msg
.KEEP_STATE:
all install clean clobber _msg: $(SUBDIRS)
$(SUBDIRS): FRC
@cd $@; pwd; $(MAKE) $(TARGET)
FRC:
#
# 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) 2010, Oracle and/or its affiliates. All rights reserved.
#
# Copyright 2013 Nexenta Systems, Inc. All rights reserved.
#
# Copyright 2019 Joyent, Inc.
#
COBJS = brand_util.o
ASOBJS = crt.o handler.o runexe.o
OFFSETS_SRC = ../common/offsets.in
OFFSETS_H = assym.h
OBJECTS = $(COBJS) $(ASOBJS)
CLOBBERFILES += $(OFFSETS_H)
include $(SRC)/lib/Makefile.lib
SRCDIR = ../common
CSRCS = $(COBJS:%o=../common/%c)
ASSRCS = $(ASOBJS:%o=$(ISASRCDIR)/%s)
SRCS = $(CSRCS) $(ASSRCS)
CPPFLAGS += -D_REENTRANT -U_ASM -I. -I../sys
CFLAGS += $(CCVERBOSE)
ASFLAGS += $(ASFLAGS_$(CURTYPE)) -D_ASM -I. -I../sys
ASFLAGS64 += $(ASFLAGS_$(CURTYPE)) -D_ASM -I. -I../sys
#
# Disable stack protection as this code might be running in an s10 context.
#
STACKPROTECT = none
# intentional code after abort()
SMOFF += unreachable
.KEEP_STATE:
# Hammerhead: Enable secondary expansion for $$(PICS) syntax (GNU Make)
.SECONDEXPANSION:
#
# build the offset header before trying to compile any files. (it's included
# by brand_misc.h, so it's needed for all objects, not just assembly ones.)
#
# Note we have to build assym.h via its dependency on pics/% so that the
# target dependent assignment of CTF_FLAGS will be there, otherwise make
# will see two different commands to build it (endless rebuilds).
#
all: pics .WAIT $$(PICS)
$(OBJECTS:%=pics/%): $(OFFSETS_H)
$(OFFSETS_H): $(OFFSETS_SRC)
$(OFFSETS_CREATE) < $(OFFSETS_SRC) >$@
pics/%.o: $(ISASRCDIR)/%.S
$(COMPILE.s) -o $@ $<
$(POST_PROCESS_S_O)
include $(SRC)/lib/Makefile.targ
#
# 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) 2010, Oracle and/or its affiliates. All rights reserved.
#
ISASRCDIR = .
include ../Makefile.com
include $(SRC)/lib/Makefile.lib.64
CPPFLAGS += -D_SYSCALL32
install: all
/*
* 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) 2010, Oracle and/or its affiliates. All rights reserved.
*/
#include <sys/asm_linkage.h>
#if defined(lint)
void
_start(void)
{
}
#else /* lint */
/*
* Initial entry point for the brand emulation library.
*
* This platform specific assembly entry point exists just to invoke
* the common brand library startup routine. That routine expects to
* be called with the following arguments:
* brand_init(int argc, char *argv[], char *envp[])
*
* There are no arguments explicitly passed to this entry point,
* routine, but we do know how our initial stack has been setup by
* the kernel. The stack format is documented in:
* usr/src/cmd/sgs/rtld/amd64/boot.s
*
* So this routine will troll through the stack to setup the argument
* values for the common brand library startup routine and then invoke
* it. This routine is modeled after the default crt1.s`_start()
* routines.
*/
ENTRY_NP(_start)
/* Make stack traces look pretty, build a fake stack frame. */
pushq $0 / Build a stack frame. retpc = NULL
pushq $0 / fp = NULL
movq %rsp, %rbp / first stack frame
/*
* Calculate the location of the envp array by adding the size of
* the argv array to the start of the argv array.
*/
movq 16(%rbp), %rdi / argc in %rax (1st param)
leaq 24(%rbp), %rsi / &argv[0] in %rbx (2nd param)
leaq 32(%rbp,%rdi,8), %rdx / envp in %rcx (3rd param)
/* Hammerhead: Use PLT call for PIC compatibility (GNU ld) */
call brand_init@PLT
/*NOTREACHED*/
SET_SIZE(_start)
#endif /* lint */
/*
* 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) 2010, Oracle and/or its affiliates. All rights reserved.
*/
#include <brand_misc.h>
/*
* Each JMP must occupy 16 bytes
*/
#define JMP \
pushq $_CONST(. - brand_handler_table); \
jmp brand_handler; \
.align 16;
#define JMP4 JMP; JMP; JMP; JMP
#define JMP16 JMP4; JMP4; JMP4; JMP4
#define JMP64 JMP16; JMP16; JMP16; JMP16
#define JMP256 JMP64; JMP64; JMP64; JMP64
#if defined(lint)
void
brand_handler_table(void)
{}
void
brand_handler(void)
{
}
#else /* lint */
/*
* On entry to this table, %rax will hold the return address. The
* location where we enter the table is a function of the system
* call number. The table needs the same alignment as the individual
* entries.
*/
.align 16
ENTRY_NP(brand_handler_table)
JMP256
SET_SIZE(brand_handler_table)
/*
* %rax - userland return address
* stack contains:
* | --------------------------------------
* v 8 | syscall arguments |
* %rsp+0 | syscall number |
* --------------------------------------
*/
ENTRY_NP(brand_handler)
pushq %rbp /* allocate stack frame */
movq %rsp, %rbp
/* Save registers at the time of the syscall. */
movq $0, EH_LOCALS_GREG(REG_TRAPNO)(%rbp)
movq $0, EH_LOCALS_GREG(REG_ERR)(%rbp)
movq %r15, EH_LOCALS_GREG(REG_R15)(%rbp)
movq %r14, EH_LOCALS_GREG(REG_R14)(%rbp)
movq %r13, EH_LOCALS_GREG(REG_R13)(%rbp)
movq %r12, EH_LOCALS_GREG(REG_R12)(%rbp)
movq %r11, EH_LOCALS_GREG(REG_R11)(%rbp)
movq %r10, EH_LOCALS_GREG(REG_R10)(%rbp)
movq %r9, EH_LOCALS_GREG(REG_R9)(%rbp)
movq %r8, EH_LOCALS_GREG(REG_R8)(%rbp)
movq %rdi, EH_LOCALS_GREG(REG_RDI)(%rbp)
movq %rsi, EH_LOCALS_GREG(REG_RSI)(%rbp)
movq %rbx, EH_LOCALS_GREG(REG_RBX)(%rbp)
movq %rcx, EH_LOCALS_GREG(REG_RCX)(%rbp)
movq %rdx, EH_LOCALS_GREG(REG_RDX)(%rbp)
xorq %rcx, %rcx
movw %cs, %cx
movq %rcx, EH_LOCALS_GREG(REG_CS)(%rbp)
movw %ds, %cx
movq %rcx, EH_LOCALS_GREG(REG_DS)(%rbp)
movw %es, %cx
movq %rcx, EH_LOCALS_GREG(REG_ES)(%rbp)
movw %fs, %cx
movq %rcx, EH_LOCALS_GREG(REG_FS)(%rbp)
movw %gs, %cx
movq %rcx, EH_LOCALS_GREG(REG_GS)(%rbp)
movw %ss, %cx
movq %rcx, EH_LOCALS_GREG(REG_SS)(%rbp)
pushfq /* save syscall flags */
popq %r12
movq %r12, EH_LOCALS_GREG(REG_RFL)(%rbp)
movq EH_ARGS_OFFSET(0)(%rbp), %r12 /* save syscall rbp */
movq %r12, EH_LOCALS_GREG(REG_RBP)(%rbp)
movq %rbp, %r12 /* save syscall rsp */
addq $CPTRSIZE, %r12
movq %r12, EH_LOCALS_GREG(REG_RSP)(%rbp)
movq %fs:0, %r12 /* save syscall fsbase */
movq %r12, EH_LOCALS_GREG(REG_FSBASE)(%rbp)
movq $0, EH_LOCALS_GREG(REG_GSBASE)(%rbp)
/*
* The kernel drops us into the middle of the brand_handle_table
* above that then pushes that table offset onto the stack, and calls
* into brand_handler. That offset indicates the system call number
* while %rax holds the return address for the system call. We replace
* the value on the stack with the return address, and use the value to
* compute the system call number by dividing by the table entry size.
*/
xchgq CPTRSIZE(%rbp), %rax /* swap JMP table offset and ret addr */
shrq $4, %rax /* table_offset/size = syscall num */
movq %rax, EH_LOCALS_GREG(REG_RAX)(%rbp) /* save syscall num */
/*
* Finish setting up our stack frame. We would normally do this
* upon entry to this function, but in this case we delayed it
* because a "sub" operation can modify flags and we wanted to
* save the flags into the gregset_t above before they get modified.
*
* Our stack frame format is documented in brand_misc.h.
*/
subq $EH_LOCALS_SIZE, %rsp
/* Look up the system call's entry in the sysent table */
movq brand_sysent_table@GOTPCREL(%rip), %r11 /* %r11 = sysent_tbl */
shlq $4, %rax /* each entry is 16 bytes */
addq %rax, %r11 /* %r11 = sysent entry address */
/*
* Get the return value flag and the number of arguments from the
* sysent table.
*/
movq CPTRSIZE(%r11), %r12 /* number of args + rv flag */
andq $RV_MASK, %r12 /* strip out number of args */
movq %r12, EH_LOCALS_RVFLAG(%rbp) /* save rv flag */
/*
* Setup arguments for our emulation call. Our input arguments,
* 0 to N, will become emulation call arguments 1 to N+1.
*
* Note: Syscall argument passing is different from function call
* argument passing on amd64. For function calls, the fourth arg
* is passed via %rcx, but for system calls the 4th argument is
* passed via %r10. This is because in amd64, the syscall
* instruction puts lower 32 bit of %rflags in %r11 and puts the
* %rip value to %rcx.
*/
movq EH_ARGS_OFFSET(4)(%rbp), %r12 /* copy 8th arg */
movq %r12, EH_ARGS_OFFSET(2)(%rsp)
movq EH_ARGS_OFFSET(3)(%rbp), %r12 /* copy 7th arg */
movq %r12, EH_ARGS_OFFSET(1)(%rsp)
movq %r9, EH_ARGS_OFFSET(0)(%rsp)
movq %r8, %r9
movq %r10, %r8
movq %rdx, %rcx
movq %rsi, %rdx
movq %rdi, %rsi
/*
* The first parameter to the emulation callback function is a
* pointer to a sysret_t structure.
*/
movq %rbp, %rdi
addq $EH_LOCALS_SYSRET, %rdi /* arg0 == sysret_t ptr */
/* invoke the emulation routine */
ALTENTRY(brand_handler_savepc)
call *(%r11)
/* restore scratch and parameter registers */
movq EH_LOCALS_GREG(REG_R12)(%rbp), %r12 /* restore %r12 */
movq EH_LOCALS_GREG(REG_R11)(%rbp), %r11 /* restore %r11 */
movq EH_LOCALS_GREG(REG_R10)(%rbp), %r10 /* restore %r10 */
movq EH_LOCALS_GREG(REG_R9)(%rbp), %r9 /* restore %r9 */
movq EH_LOCALS_GREG(REG_R8)(%rbp), %r8 /* restore %r8 */
movq EH_LOCALS_GREG(REG_RCX)(%rbp), %rcx /* restore %rcx */
movq EH_LOCALS_GREG(REG_RDX)(%rbp), %rdx /* restore %rdx */
movq EH_LOCALS_GREG(REG_RSI)(%rbp), %rsi /* restore %rsi */
movq EH_LOCALS_GREG(REG_RDI)(%rbp), %rdi /* restore %rdi */
/* Check for syscall emulation success or failure */
cmpq $0, %rax
je success
stc /* failure, set carry flag */
jmp return /* return, %rax == errno */
success:
/* There is always at least one return value. */
movq EH_LOCALS_SYSRET1(%rbp), %rax /* %rax == sys_rval1 */
cmpq $RV_DEFAULT, EH_LOCALS_RVFLAG(%rbp) /* check rv flag */
je clear_carry
mov EH_LOCALS_SYSRET2(%rbp), %rdx /* %rdx == sys_rval2 */
clear_carry:
clc /* success, clear carry flag */
return:
movq %rbp, %rsp /* restore stack */
popq %rbp
ret /* ret to instr after syscall */
SET_SIZE(brand_handler)
#endif /* lint */
/*
* 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) 2010, Oracle and/or its affiliates. All rights reserved.
*/
#include <sys/asm_linkage.h>
#include <brand_misc.h>
#if defined(lint)
/*ARGSUSED*/
void
brand_runexe(void *argv, ulong_t entry)
{
}
#else /* lint */
/*
* Prepare to jump to the target program we actually want to run.
* If this program is dynamically linked then we'll be jumping to
* another copy of the linker. If it's a statically linked program
* we'll be jumping directy to it's main entry point. In any case,
* we need to reset our current state stack and register state to
* something similar to the initial process state setup by the kernel
* and documented at:
* usr/src/cmd/sgs/rtld/i386/boot.s
* usr/src/cmd/sgs/rtld/sparcv9/boot.s
*
* Of course this is the same stack format as when this executable
* was first started, so here we'll just roll back the stack and
* frame pointers to their values when this processes first started
* execution.
*/
ENTRY_NP(brand_runexe)
movq %rdi, %rax / %rax = &argv[0]
movq %rsi, %rbx / Brand app entry point in %rbx
subq $8, %rax / Top of stack - must point at argc
movq %rax, %rsp / Set %rsp to what linkers expect
/*
* We also have to make sure to clear %rdx since nornally ld.so.1 will
* set that to non-zero if there is an exit function that should be
* invoked when the process is terminating. This isn't actually
* necessary if the target program we're jumping to is a dynamically
* linked program since in that case we're actually jumping to another
* copy of ld.so.1 and it will just reset %rdx, but if the target
* program we're jumping to is a statically linked binary that uses
* the standard sun compiler supplied crt1.o`_start(), it will check
* to see if %g1 is set.
*/
movq $0, %rdx
jmp *%rbx / And away we go...
/*
* target will never return.
*/
SET_SIZE(brand_runexe)
#endif /* lint */
/*
* 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) 2010, Oracle and/or its affiliates. All rights reserved.
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <sys/auxv.h>
#include <sys/bitmap.h>
#include <sys/brand.h>
#include <sys/inttypes.h>
#include <sys/lwp.h>
#include <sys/syscall.h>
#include <sys/systm.h>
#include <sys/utsname.h>
#include <fcntl.h>
#include <brand_misc.h>
#include <sys/brand.h>
extern brand_sysent_table_t brand_sysent_table[];
/*LINTED: static unused*/
static volatile int brand_abort_err;
/*LINTED: static unused*/
static volatile const char *brand_abort_msg;
/*LINTED: static unused*/
static volatile const char *brand_abort_file;
/*LINTED: static unused*/
static volatile int brand_abort_line;
/*
* Principles of emulation 101.
*
*
* *** Setting errno
*
* Just don't do it. This emulation library is loaded onto a
* seperate link map from the application who's address space we're
* running in. We have our own private copy of libc, so there for,
* the errno value accessible from here is is also private and changing
* it will not affect any errno value that the processes who's address
* space we are running in will see. To return an error condition we
* should return the errno value we'd like the system to return.
* For more information about this see the comments in brand_misc.h.
* Basically, when we return to the caller that initiated the system
* call it's their responsibility to set errno.
*
*
* *** Recursion Considerations
*
* When emulating system calls we need to be very careful about what
* library calls we invoke. Library calls should be kept to a minimum.
* One issue is that library calls can invoke system calls, so if we're
* emulating a system call and we invoke a library call that depends on
* that system call we will probably enter a recursive loop, which would
* be bad.
*
*
* *** Return Values.
*
* See brand_misc.h.
*
* *** Agent lwp considerations
*
* It is currently impossible to do any emulation for these system call
* when they are being invoked on behalf of an agent lwp. To understand why
* it's impossible you have to understand how agent lwp syscalls work.
*
* The agent lwp syscall process works as follows:
* 1 The controlling process stops the target.
* 2 The controlling process injects an agent lwp which is also stopped.
* This agent lwp assumes the userland stack and register values
* of another stopped lwp in the current process.
* 3 The controlling process configures the agent lwp to start
* executing the requested system call.
* 4 The controlling process configure /proc to stop the agent lwp when
* it enters the requested system call.
* 5 The controlling processes allows the agent lwp to start executing.
* 6 The agent lwp traps into the kernel to perform the requested system
* call and immediately stop.
* 7 The controlling process copies all the arguments for the requested
* system call onto the agent lwp's stack.
* 8 The controlling process configures /proc to stop the agent lwp
* when it completes the requested system call.
* 9 The controlling processes allows the agent lwp to start executing.
* 10 The agent lwp executes the system call and then stop before returning
* to userland.
* 11 The controlling process copies the return value and return arguments
* back from the agent lwps stack.
* 12 The controlling process destroys the agent lwp and restarts
* the target process.
*
* The fundamental problem is that when the agent executes the request
* system call in step 5, if we're emulating that system call then the
* lwp is redirected back to our emulation layer without blocking
* in the kernel. But our emulation layer can't access the arguments
* for the system call because they haven't been copied to the stack
* yet and they still only exist in the controlling processes address
* space. This prevents us from being able to do any emulation of
* agent lwp system calls. Hence, currently our brand trap interposition
* callback (XXX_brand_syscall_callback_common) will detect if a system
* call is being made by an agent lwp, and if this is the case it will
* never redirect the system call to this emulation library.
*
* In the future, if this proves to be a problem the the easiest solution
* would probably be to replace the branded versions of these application
* with their native counterparts. Ie, truss, plimit, and pfiles could be
* replace with wrapper scripts that execute the native versions of these
* applications. In the case of plimit and pfiles this should be pretty
* strait forward. Truss would probably be more tricky since it can
* execute applications which would be branded applications, so in that
* case it might be necessary to create a loadable library which could
* be LD_PRELOADed into truss and this library would interpose on the
* exec() system call to allow truss to correctly execute branded
* processes. It should be pointed out that this solution could work
* because "native agent lwps" (ie, agent lwps created by native
* processes) can be treated differently from "branded aged lwps" (ie,
* agent lwps created by branded processes), since native agent lwps
* would presumably be making native system calls and hence not need
* any interposition.
*
* *** General considerations
*
* One of the differences between the lx brand and the s10
* brand, is that the s10 brand only interposes on syscalls
* that need some kind of emulation, whereas the lx brand interposes
* on _all_ system calls. Lx branded system calls that don't need
* any emulation are then redirected back to the kernel from the
* userland library via the IN_KERNEL_SYSCALL macro. The lx-syscall
* dtrace provider depends on this behavior.
*
*/
/*ARGSUSED*/
void
_brand_abort(int err, const char *msg, const char *file, int line)
{
sysret_t rval;
/* Save the error message into convenient globals */
brand_abort_err = err;
brand_abort_msg = msg;
brand_abort_file = file;
brand_abort_line = line;
/* kill ourselves */
abort();
/* If abort() didn't work, try something stronger. */
(void) __systemcall(&rval, SYS_lwp_kill + 1024, _lwp_self(), SIGKILL);
}
int
brand_uucopy(const void *from, void *to, size_t size)
{
sysret_t rval;
if (__systemcall(&rval, SYS_uucopy + 1024, from, to, size) != 0)
return (EFAULT);
return (0);
}
/*
* ATTENTION: uucopystr() does NOT ensure that string are null terminated!
*/
int
brand_uucopystr(const void *from, void *to, size_t size)
{
sysret_t rval;
if (__systemcall(&rval, SYS_uucopystr + 1024, from, to, size) != 0)
return (EFAULT);
return (0);
}
/*
* This function is defined to be NOSYS but it won't be called from the
* the kernel since the NOSYS system calls are not enabled in the kernel.
* Thus, the only time this function is called is directly from within the
* indirect system call path.
*/
/*ARGSUSED*/
long
brand_unimpl(sysret_t *rv, uintptr_t p1)
{
sysret_t rval;
/*
* We'd like to print out some kind of error message here like
* "unsupported syscall", but we can't because it's not safe to
* assume that stderr or STDERR_FILENO actually points to something
* that is a terminal, and if we wrote to those files we could
* inadvertantly write to some applications open files, which would
* be bad.
*
* Normally, if an application calls an invalid system call
* it get a SIGSYS sent to it. So we'll just go ahead and send
* ourselves a signal here. Note that this is far from ideal since
* if the application has registered a signal handler, that signal
* handler may recieve a ucontext_t as the third parameter to
* indicate the context of the process when the signal was
* generated, and in this case that context will not be what the
* application is expecting. Hence, we should probably create a
* brandsys() kernel function that can deliver the signal to us
* with the correct ucontext_t.
*/
(void) __systemcall(&rval, SYS_lwp_kill + 1024, _lwp_self(), SIGSYS);
return (ENOSYS);
}
#if defined(__sparc) && !defined(__sparcv9)
/*
* Yuck. For 32-bit sparc applications, handle indirect system calls.
* Note that we declare this interface to use the maximum number of
* system call arguments. If we recieve a system call that uses less
* arguments, then the additional arguments will be garbage, but they
* will also be ignored so that should be ok.
*/
long
brand_indir(sysret_t *rv, int code,
uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4,
uintptr_t a5, uintptr_t a6, uintptr_t a7)
{
brand_sysent_table_t *sst = &(brand_sysent_table[code]);
brand_assert(code < NSYSCALL);
switch (sst->st_args & NARGS_MASK) {
case 0:
return ((sst->st_callc)(rv));
case 1:
return ((sst->st_callc)(rv, a0));
case 2:
return ((sst->st_callc)(rv, a0, a1));
case 3:
return ((sst->st_callc)(rv, a0, a1, a2));
case 4:
return ((sst->st_callc)(rv, a0, a1, a2, a3));
case 5:
return ((sst->st_callc)(rv, a0, a1, a2, a3, a4));
case 6:
return ((sst->st_callc)(rv, a0, a1, a2, a3, a4, a5));
case 7:
return ((sst->st_callc)(rv, a0, a1, a2, a3, a4, a5, a6));
case 8:
return ((sst->st_callc)(rv, a0, a1, a2, a3, a4, a5, a6, a7));
}
brand_abort(0, "invalid entry in brand_sysent_table");
return (EINVAL);
}
#endif /* __sparc && !__sparcv9 */
/*
* Close a libc file handle, but don't actually close the underlying
* file descriptor.
*/
static void
brand_close_fh(FILE *file)
{
int fd, fd_new;
if (file == NULL)
return;
if ((fd = fileno(file)) < 0)
return;
/*
* We're a branded process but our handler isn't installed yet. We
* can't use the dup() syscall since it no longer exists. Unfortunately
* in an S10 branded zone, this will all pick up the old libc and not
* use emulation, which makes it fairly impossible to use safely.
*/
fd_new = fcntl(fd, F_DUPFD, 0);
if (fd_new == -1)
return;
(void) fclose(file);
(void) dup2(fd_new, fd);
(void) close(fd_new);
}
/*ARGSUSED*/
void
brand_pre_init()
{
int i;
/* Sanity check our translation table return value codes */
for (i = 0; i < NSYSCALL; i++) {
brand_sysent_table_t *est = &(brand_sysent_table[i]);
brand_assert(BIT_ONLYONESET(est->st_args & RV_MASK));
}
/*
* We need to shutdown all libc stdio. libc stdio normally goes to
* file descriptors, but since we're actually part of a another
* process we don't own these file descriptors and we can't make
* any assumptions about their state.
*/
brand_close_fh(stdin);
brand_close_fh(stdout);
brand_close_fh(stderr);
}
/*ARGSUSED*/
ulong_t
brand_post_init(int version, int argc, char *argv[], char *envp[])
{
sysret_t rval;
brand_proc_reg_t reg;
brand_elf_data_t sed;
auxv_t *ap;
uintptr_t *p;
int err;
/*
* Register our syscall emulation table with the kernel.
* Note that we don't have to do invoke (syscall_number + 1024)
* until we've actually establised a syscall emulation callback
* handler address, which is what we're doing with this brand
* syscall.
*/
reg.sbr_version = version;
#ifdef __x86
reg.sbr_handler = (caddr_t)brand_handler_table;
#else /* !__x86 */
reg.sbr_handler = (caddr_t)brand_handler;
#endif /* !__x86 */
if ((err = __systemcall(&rval, SYS_brand, B_REGISTER, ®)) != 0) {
brand_abort(err, "Failed to brand current process");
/*NOTREACHED*/
}
/* Get data about the executable we're running from the kernel. */
if ((err = __systemcall(&rval, SYS_brand + 1024,
B_ELFDATA, (void *)&sed)) != 0) {
brand_abort(err,
"Failed to get required brand ELF data from the kernel");
/*NOTREACHED*/
}
/*
* Find the aux vector on the stack.
*/
p = (uintptr_t *)envp;
while (*p != 0)
p++;
/*
* p is now pointing at the 0 word after the environ pointers.
* After that is the aux vectors.
*
* The aux vectors are currently pointing to the brand emulation
* library and associated linker. We're going to change them to
* point to the brand executable and associated linker (or to no
* linker for static binaries). This matches the process data
* stored within the kernel and visible from /proc, which was
* all setup in sn1_elfexec(). We do this so that when a debugger
* attaches to the process it sees the process as a normal solaris
* process, this brand emulation library and everything on it's
* link map will not be visible, unless our librtld_db plugin
* is used. Note that this is very different from how Linux
* branded processes are implemented within lx branded zones.
* In that situation, the primary linkmap of the process is the
* brand emulation libraries linkmap, not the Linux applications
* linkmap.
*
* We also need to clear the AF_SUN_NOPLM flag from the AT_SUN_AUXFLAGS
* aux vector. This flag told our linker that we don't have a
* primary link map. Now that our linker is done initializing, we
* want to clear this flag before we transfer control to the
* applications copy of the linker, since we want that linker to have
* a primary link map which will be the link map for the application
* we're running.
*/
p++;
for (ap = (auxv_t *)p; ap->a_type != AT_NULL; ap++) {
switch (ap->a_type) {
case AT_BASE:
/* Hide AT_BASE if static binary */
if (sed.sed_base == 0) {
ap->a_type = AT_IGNORE;
ap->a_un.a_val = 0;
} else {
ap->a_un.a_val = sed.sed_base;
}
break;
case AT_ENTRY:
ap->a_un.a_val = sed.sed_entry;
break;
case AT_PHDR:
ap->a_un.a_val = sed.sed_phdr;
break;
case AT_PHENT:
ap->a_un.a_val = sed.sed_phent;
break;
case AT_PHNUM:
ap->a_un.a_val = sed.sed_phnum;
break;
case AT_SUN_AUXFLAGS:
ap->a_un.a_val &= ~AF_SUN_NOPLM;
break;
case AT_SUN_EMULATOR:
/*
* ld.so.1 inspects AT_SUN_EMULATOR to see if
* if it is the linker for the brand emulation
* library. Hide AT_SUN_EMULATOR, as the
* linker we are about to jump to is the linker
* for the binary.
*/
ap->a_type = AT_IGNORE;
ap->a_un.a_val = 0;
break;
case AT_SUN_LDDATA:
/* Hide AT_SUN_LDDATA if static binary */
if (sed.sed_lddata == 0) {
ap->a_type = AT_IGNORE;
ap->a_un.a_val = 0;
} else {
ap->a_un.a_val = sed.sed_lddata;
}
break;
default:
break;
}
}
return (sed.sed_ldentry);
}
\
\ Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
\
\ 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
\
#include <sys/types.h>
#include <sys/regset.h>
#include <sys/ucontext.h>
#include <sys/syscall.h>
greg_t SIZEOF_GREG_T
gregset_t SIZEOF_GREGSET_T
sysret_t SIZEOF_SYSRET_T
/*
* 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) 2010, Oracle and/or its affiliates. All rights reserved.
*/
#ifndef _BRAND_MISC_H
#define _BRAND_MISC_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* This header file must uses _ASM defines to allow it to be included
* in assmebly source files
*/
#include <sys/asm_linkage.h>
#include <sys/regset.h>
#include <sys/syscall.h>
#if !defined(_ASM)
#include <sys/brand.h>
#endif
#include "assym.h"
/*
* Our syscall emulation callback handler adds one argument to each
* system call, so we'll need to allocate space for one more argument
* above the maximum number of arguments that a system call can normally
* take. Also, we assume that each syscall argument is a long, ie, we
* don't support long long syscall parameters.
*/
#if defined(__sparc)
/*
* 32-bit and 64-bit sparc syscalls can take up to 8 arguments.
* 32-bit sparc indirect syscalls can take up to 9 arguments.
* Arguments 1 - 6 are passed via %o0 - %o5.
* Additional arguments are passed on the stack.
* So make space for 4 arguments on the stack.
*/
#define EH_ARGS_COUNT 4
#elif defined(__amd64)
/*
* amd64 syscalls can take up to 8 arguments.
* Arguments 1 - 6 are passed via: %rdi, %rsi, %rdx, %r10, %r8, %r9
* Additional arguments are passed on the stack.
* So make space for 3 arguments on the stack.
*/
#define EH_ARGS_COUNT 3
#else /* !__sparc && !__amd64 */
/*
* ia32 syscalls can take up to 8 arguments.
* All arguments are passed on the stack.
* So make space for 9 arguments on the stack.
*/
#define EH_ARGS_COUNT 9
#endif /* !__sparc && !__amd64 */
#define EH_ARGS_SIZE (CPTRSIZE * EH_ARGS_COUNT)
#define EH_ARGS_OFFSET(x) (STACK_BIAS + MINFRAME + (CPTRSIZE * (x)))
#define EH_LOCALS_SIZE (EH_ARGS_SIZE + SIZEOF_GREGSET_T + \
SIZEOF_SYSRET_T + CPTRSIZE)
#if defined(__sparc)
/*
* On sparc, all emulation callback handler variable access is done
* relative to %sp, so access offsets are positive.
*/
#define EH_LOCALS_START (STACK_BIAS + MINFRAME + EH_ARGS_SIZE)
#define EH_LOCALS_END_TGT (STACK_BIAS + MINFRAME + EH_LOCALS_SIZE)
#else /* !__sparc */
/*
* On x86, all emulation callback handler variable access is done
* relative to %ebp/%rbp, so access offsets are negative.
*/
#define EH_LOCALS_START (-(EH_LOCALS_SIZE - \
(STACK_BIAS + MINFRAME + EH_ARGS_SIZE)))
#define EH_LOCALS_END_TGT 0
#endif /* !__sparc */
/*
* In our emulation callback handler, our stack will look like:
* -------------------------------------------------
* %bp | long rvflag |
* | | sysret_t sysret |
* v | gregset_t gregs |
* %sp | long callback args[EH_ARGS_COUNT] |
* -------------------------------------------------
* For ia32, use %ebp and %esp instead of %bp and %sp.
* For amd64, use %rbp and %rsp instead of %bp and %sp.
*
* Our emulation callback handler always saves enough space to hold the
* maximum number of stack arguments to a system call. This is architecture
* specific and is defined via EH_ARGS_COUNT.
*/
#define EH_LOCALS_GREGS (EH_LOCALS_START)
#define EH_LOCALS_GREG(x) (EH_LOCALS_GREGS + (SIZEOF_GREG_T * (x)))
#define EH_LOCALS_SYSRET (EH_LOCALS_GREGS + SIZEOF_GREGSET_T)
#define EH_LOCALS_SYSRET1 (EH_LOCALS_SYSRET)
#define EH_LOCALS_SYSRET2 (EH_LOCALS_SYSRET + CPTRSIZE)
#define EH_LOCALS_RVFLAG (EH_LOCALS_SYSRET + SIZEOF_SYSRET_T)
#define EH_LOCALS_END (EH_LOCALS_RVFLAG + CPTRSIZE)
#if (EH_LOCALS_END != EH_LOCALS_END_TGT)
#error "brand_misc.h EH_LOCALS_* macros don't add up"
#endif /* (EH_LOCALS_END != EH_LOCALS_END_TGT) */
/*
* The second parameter of each entry in the {BRAND}_sysent_table
* contains the number of parameters and flags that describe the
* syscall return value encoding.
*
* When declaring new syscall emulation functions, it is very important
* to to set the proper RV_* flags in the brand_sysent_table. Upon failure,
* syscall emulation fuctions should return an errno value. Upon success
* syscall emulation functions should return 0 and set the sysret_t return
* value parameters accordingly.
*
* There are five possible syscall macro wrappers used in the kernel's system
* call sysent table. These turn into the following return values:
* SYSENT_CL -> SYSENT_C or SYSENT_CI
* SYSENT_C SE_64RVAL RV_DEFAULT
* SYSENT_CI SE_32RVAL1 RV_DEFAULT
* SYSENT_2CI SE_32RVAL1|SE_32RVAL2 RV_32RVAL2
* SYSENT_AP SE_64RVAL RV_64RVAL
*
*/
#define NARGS_MASK 0x000000FF /* Mask for syscalls argument count */
#define RV_MASK 0x0000FF00 /* Mask for return value flags */
#define RV_DEFAULT 0x00000100 /* syscall returns "default" values */
#define RV_32RVAL2 0x00000200 /* syscall returns two 32-bit values */
#define RV_64RVAL 0x00000400 /* syscall returns a 64-bit value */
#if !defined(_ASM)
/*
* We define our own version of assert because the default one will
* try to emit a localized message. That is bad because first, we can't
* emit messages to random file descriptors, and second localizing a message
* requires allocating memory and we can't do that either.
*/
#define brand_assert(ex) (void)((ex) || \
(_brand_abort(0, #ex, __FILE__, __LINE__), 0))
#define brand_abort(err, msg) _brand_abort((err), (msg), __FILE__, __LINE__)
#define EMULATE(cb, args) { (sysent_cb_t)(uintptr_t)(cb), (args) }
#define NOSYS EMULATE(brand_unimpl, (0 | RV_DEFAULT))
typedef long (*sysent_cb_t)();
typedef struct brand_sysent_table {
sysent_cb_t st_callc;
uintptr_t st_args;
} brand_sysent_table_t;
/*
* These macros invoke a brandsys subcommand, B_TRUSS_POINT, used to expose
* a call to an interpositioned syscall that would have otherwise gone
* unnoticed by truss(1) because the interpositioned system call did not call
* any system calls before returning.
*/
#define B_TRUSS_POINT_5(rval, syscall_num, err, a0, a1, a2, a3, a4) \
__systemcall(rval, SYS_brand + 1024, \
B_TRUSS_POINT, (syscall_num), (err), (a0), (a1), (a2), (a3), \
(a4))
#define B_TRUSS_POINT_4(rval, syscall_num, err, a0, a1, a2, a3) \
B_TRUSS_POINT_5(rval, (syscall_num), (err), (a0), (a1), (a2), (a3), 0)
#define B_TRUSS_POINT_3(rval, syscall_num, err, a0, a1, a2) \
B_TRUSS_POINT_5(rval, (syscall_num), (err), (a0), (a1), (a2), 0, 0)
#define B_TRUSS_POINT_2(rval, syscall_num, err, a0, a1) \
B_TRUSS_POINT_5(rval, (syscall_num), (err), (a0), (a1), 0, 0, 0)
#define B_TRUSS_POINT_1(rval, syscall_num, err, a0) \
B_TRUSS_POINT_5(rval, (syscall_num), (err), (a0), 0, 0, 0, 0)
#define B_TRUSS_POINT_0(rval, syscall_num, err) \
B_TRUSS_POINT_5(rval, (syscall_num), (err), 0, 0, 0, 0, 0)
/*
* From runexe.s
*/
extern void brand_runexe(void *, ulong_t);
/*
* From handler.s
*/
extern void brand_handler_table(void);
extern void brand_handler(void);
extern void brand_error(void);
extern void brand_success(void);
/*
* From brand_util.c
*/
extern long brand_unimpl(sysret_t *rv, uintptr_t p1);
extern void _brand_abort(int, const char *, const char *, int);
extern int brand_uucopy(const void *, void *, size_t);
extern int brand_uucopystr(const void *, void *, size_t);
extern void brand_pre_init();
extern ulong_t brand_post_init(int, int, char **, char **);
#if defined(__sparc) && !defined(__sparcv9)
extern long brand_indir(sysret_t *, int, uintptr_t, uintptr_t, uintptr_t,
uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
#endif /* __sparc && !__sparcv9 */
#endif /* !_ASM */
#ifdef __cplusplus
}
#endif
#endif /* _BRAND_MISC_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 (c) 2010, Oracle and/or its affiliates. All rights reserved.
#
# Copyright (c) 2018, Joyent, Inc.
include $(SRC)/lib/Makefile.lib
LIBRARY = $(BRAND)_librtld_db.a
VERS = .1
CSRCS = $(COBJS:%o=$(BRAND_SHARED)/librtld_db/common/%c)
SRCS = $(CSRCS)
SRCDIR = $(BRAND_SHARED)/librtld_db/common
UTSBASE = $(SRC)/uts
#
# ATTENTION:
# Librtl_db brand plugin libraries should NOT directly invoke any
# libproc.so interfaces or be linked against libproc. If a librtl_db
# brand plugin library uses libproc.so interfaces then it may break
# any other librtld_db consumers (like mdb) that tries to attach
# to a branded process. The only safe interfaces that the a librtld_db
# brand plugin library can use to access a target process are the
# proc_service(3PROC) apis.
#
# Hammerhead: Disable -zdefs because ps_pauxv, ps_pdmodel, ps_plog etc.
# are proc_service(3PROC) callbacks provided by the caller at runtime
ZDEFS =
# Hammerhead: Don't add mapfile to DYNFLAGS - it's already in MAPFILES via SRCDIR
DYNFLAGS += $(VERSREF)
LIBS = $(DYNLIB)
LDLIBS += -lc -lrtld_db
CFLAGS += $(CCVERBOSE)
CPPFLAGS += -D_REENTRANT \
-I$(SRC)/cmd/sgs/librtld_db/common \
-I$(SRC)/cmd/sgs/include \
-I$(SRC)/cmd/sgs/include/$(MACH)
# not linted
SMATCH=off
ROOTLIBDIR = $(ROOT)/usr/lib/brand/$(BRAND)
# Hammerhead: 64-bit only - flatten brand library path
ROOTLIBDIR64 = $(ROOT)/usr/lib/brand/$(BRAND)
#
# The top level Makefiles define define TEXT_DOMAIN. But librtld_db.so.1
# isn't internationalized and this library won't be either. The only
# messages that this library can generate are messages used for debugging
# the operation of the library itself.
#
DTEXTDOM =
.KEEP_STATE:
all: $(LIBS)
pics/%64.o: $(BRAND_SHARED)/librtld_db/common/%.c
$(COMPILE.c) -D_ELF64 $(PICFLAGS) -o $@ $<
$(POST_PROCESS_O)
include $(SRC)/lib/Makefile.targ
/*
* 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) 2010, Oracle and/or its affiliates. All rights reserved.
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <libproc.h>
#include <proc_service.h>
#include <synch.h>
#include <sys/types.h>
#include <sys/link.h>
#include <rtld_db.h>
#include <sys/brand.h>
/*
* ATTENTION:
* Librtl_db brand plugin libraries should NOT directly invoke any
* libproc.so interfaces or be linked against libproc. If a librtl_db
* brand plugin library uses libproc.so interfaces then it may break
* any other librtld_db consumers (like mdb) that tries to attach
* to a branded process. The only safe interfaces that the a librtld_db
* brand plugin library can use to access a target process are the
* proc_service(3PROC) apis.
*/
/*
* M_DATA comes from some streams header file but is also redifined in
* _rtld_db.h, so nuke the old streams definition here.
*/
#ifdef M_DATA
#undef M_DATA
#endif /* M_DATA */
/*
* For 32-bit versions of this library, this file get's compiled once.
* For 64-bit versions of this library, this file get's compiled twice,
* once with _ELF64 defined and once without. The expectation is that
* the 64-bit version of the library can properly deal with both 32-bit
* and 64-bit elf files, hence in the 64-bit library there are two copies
* of all the interfaces in this file, one set named *32 and one named *64.
*
* This also means that we need to be careful when declaring local pointers
* that point to objects in another processes address space, since these
* pointers may not match the current processes pointer width. Basically,
* we should not use any objects that change size between 32 and 64 bit
* modes like: long, void *, uintprt_t, caddr_t, psaddr_t, size_t, etc.
* Instead we should declare all pointers as uint32_t. Then when we
* are compiled to deal with 64-bit targets we'll re-define uing32_t
* to be a uint64_t.
*/
#ifdef _LP64
#ifdef _ELF64
#define uint32_t uint64_t
#define Elf32_Dyn Elf64_Dyn
#define validate_rdebug32 validate_rdebug64
#define _rd_loadobj_iter32 _rd_loadobj_iter64
#define _rd_get_dyns32 _rd_get_dyns64
#define dummy_ldb32 dummy_ldb64
#define dummy_ldb_init32 dummy_ldb_init64
#define dummy_ldb_fini32 dummy_ldb_fini64
#define dummy_ldb_loadobj_iter32 dummy_ldb_loadobj_iter64
#define dummy_ldb_get_dyns32 dummy_ldb_get_dyns64
#define brand_ldb_init32 brand_ldb_init64
#define brand_ldb_fini32 brand_ldb_fini64
#define brand_ldb_loadobj_iter32 brand_ldb_loadobj_iter64
#define brand_ldb_get_dyns32 brand_ldb_get_dyns64
#endif /* _ELF64 */
#endif /* _LP64 */
/* Included from usr/src/cmd/sgs/librtld_db/common */
#include <_rtld_db.h>
/*ARGSUSED*/
static rd_helper_data_t
dummy_ldb_init32(rd_agent_t *rap, struct ps_prochandle *php)
{
return (NULL);
}
/*ARGSUSED*/
static void
dummy_ldb_fini32(rd_helper_data_t rhd)
{
}
/*ARGSUSED*/
static int
dummy_ldb_loadobj_iter32(rd_helper_data_t rhd, rl_iter_f *cb, void *client_data)
{
return (RD_OK);
}
/*ARGSUSED*/
static rd_err_e
dummy_ldb_get_dyns32(rd_helper_data_t rhd,
psaddr_t addr, void **dynpp, size_t *dynpp_sz)
{
*dynpp = NULL;
*dynpp_sz = 0;
return (RD_OK);
}
static rd_helper_ops_t dummy_ldb32 = {
LM_ID_BRAND,
dummy_ldb_init32,
dummy_ldb_fini32,
dummy_ldb_loadobj_iter32,
dummy_ldb_get_dyns32
};
static uint32_t
brand_ldb_getauxval32(struct ps_prochandle *php, int type)
{
const auxv_t *auxvp = NULL;
if (ps_pauxv(php, &auxvp) != PS_OK)
return ((uint32_t)-1);
while (auxvp->a_type != AT_NULL) {
if (auxvp->a_type == type)
return ((uint32_t)(uintptr_t)auxvp->a_un.a_ptr);
auxvp++;
}
return ((uint32_t)-1);
}
/*
* Normally, the native Solaris librtldb_db plugin uses a bunch of different
* methods to try and find the rdebug structure associated with the target
* process we're debugging. For details on the different methods see
* _rd_reset32(). Thankfully our job is easier. We know that the brand
* library is always linked against the native linker, and when the
* process was first executed we saved off a pointer to the brand linkers
* rdebug structure in one of our brand specific aux vectors,
* AT_SUN_BRAND_COMMON_LDDATA. So we'll just look that up here.
*/
/*ARGSUSED*/
static rd_helper_data_t
brand_ldb_init32(rd_agent_t *rap, struct ps_prochandle *php)
{
struct rd_agent *rap_new;
uint32_t lddata_addr;
int rd_dmodel;
if (ps_pdmodel(php, &rd_dmodel) != PS_OK) {
ps_plog("brand_ldb_init: lookup of data model failed");
return (NULL);
}
#ifdef _ELF64
assert(rd_dmodel == PR_MODEL_LP64);
#else /* !_ELF64 */
assert(rd_dmodel == PR_MODEL_ILP32);
#endif /* !_ELF64 */
lddata_addr = brand_ldb_getauxval32(php, AT_SUN_BRAND_COMMON_LDDATA);
if (lddata_addr == (uint32_t)-1) {
ps_plog("brand_ldb_init: no LDDATA found in aux vector");
return (NULL);
}
ps_plog("brand_ldb_init: found LDDATA auxv ld.so.1 data seg "
"at: 0x%p", lddata_addr);
/*
* Ok. So this is kinda ugly. Basically we know that we're going to
* be parsing data from link maps that are generated by a Solaris
* linker. As it turns out, that's exactly what the default
* Solaris librtld_db library is designed to do. So rather than
* duplicate all that link map parsing code here we'll simply
* invoke the native librtld_db that normally does this, and when
* we do we'll point them at our emulation libraries link map.
*
* Of course these interfacess aren't really public interfaces
* and they take a "struct rd_agent" as a parameter. So here
* we'll allocate and initialize a new "struct rd_agent", point
* it at our emulation libraries link map, and initialize just
* enough of the structure to make the librtld_db interfaces
* that we want to use happy.
*/
if ((rap_new = calloc(sizeof (*rap_new), 1)) == NULL) {
ps_plog("brand_ldb_init: can't allocate memory");
return (NULL);
}
rap_new->rd_dmodel = rd_dmodel;
rap_new->rd_psp = php;
rap_new->rd_rdebug = lddata_addr;
(void) mutex_init(&rap_new->rd_mutex, USYNC_THREAD, 0);
/*
* When we get invoked from librtld_db, and we call back into it,
* librtld_db will once again check if there is a plugin and
* invoke it. Since we don't want to enter a recursive loop
* we're going to specify a different plugin interface for
* our linkmap, and these new plugin interfaces won't actually
* do anything other than return.
*/
rap_new->rd_helper.rh_ops = &dummy_ldb32;
/*
* validate_rdebug32() requires the following "struct rd_agent"
* members to be initialized:
* rd_psp, rd_rdebug
*
* validate_rdebug32() initializes the following "struct rd_agent"
* members:
* rd_flags, rd_rdebugvers, rd_rtlddbpriv
*/
if (validate_rdebug32(rap_new) != RD_OK) {
ps_plog("brand_ldb_init: can't find valid r_debug data");
free(rap_new);
return (NULL);
}
ps_plog("brand_ldb_init: finished, helper_data=0x%p", rap_new);
return ((rd_helper_data_t)rap_new);
}
static void
brand_ldb_fini32(rd_helper_data_t rhd)
{
struct rd_agent *rap = (struct rd_agent *)rhd;
ps_plog("brand_ldb_fini: cleaning up brand helper");
free(rap);
}
/*ARGSUSED*/
static int
brand_ldb_loadobj_iter32(rd_helper_data_t rhd, rl_iter_f *cb, void *client_data)
{
struct rd_agent *rap = (struct rd_agent *)rhd;
int err;
ps_plog("brand_ldb_loadobj_iter(helper_data=0x%p)", rhd);
assert(rap->rd_psp == php);
RDAGLOCK(rap);
/*
* _rd_loadobj_iter32() requires the following "struct rd_agent"
* members to be initialized:
* rd_rtlddbpriv, rd_rdebugvers, rd_flags,
* rd_helper.rh_ops, rd_dmodel
*/
err = _rd_loadobj_iter32(rap, cb, client_data);
RDAGUNLOCK(rap);
ps_plog("brand_ldb_loadobj_iter: finished, err = %d", err);
return (err);
}
/*ARGSUSED*/
static rd_err_e
brand_ldb_get_dyns32(rd_helper_data_t rhd,
psaddr_t addr, void **dynpp, size_t *dynpp_sz)
{
struct rd_agent *rap = (struct rd_agent *)rhd;
int err;
ps_plog("brand_ldb_get_dyns(helper_data=0x%p)", rhd);
err = _rd_get_dyns32(rap, addr, (Elf32_Dyn **)dynpp, dynpp_sz);
ps_plog("brand_ldb_get_dyns: finished, err = %d", err);
return (err);
}
/*
* Librtld_db plugin linkage struct.
*
* When we get loaded by librtld_db, it will look for the symbol below
* to find our plugin entry points.
*/
rd_helper_ops_t RTLD_DB_BRAND_OPS = {
LM_ID_NONE,
brand_ldb_init32,
brand_ldb_fini32,
brand_ldb_loadobj_iter32,
brand_ldb_get_dyns32
};
#
# 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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
#
#
# MAPFILE HEADER START
#
# WARNING: STOP NOW. DO NOT MODIFY THIS FILE.
# Object versioning must comply with the rules detailed in
#
# usr/src/lib/README.mapfiles
#
# You should not be making modifications here until you've read the most current
# copy of that file. If you need help, contact a gatekeeper for guidance.
#
# MAPFILE HEADER END
#
$mapfile_version 2
SYMBOL_VERSION SUNWprivate_1.1 {
global:
rtld_db_brand_ops32 {
ASSERT = {
TYPE = OBJECT;
SIZE = addrsize[5];
};
};
$if _ELF64
rtld_db_brand_ops64 {
ASSERT = {
TYPE = OBJECT;
SIZE = addrsize[5];
};
};
$endif
local:
*;
};
#Externally defined symbols
SYMBOL_SCOPE {
global:
ps_pauxv { FLAGS = NODIRECT PARENT; };
ps_pdmodel { FLAGS = NODIRECT PARENT; };
ps_pglobal_lookup { FLAGS = NODIRECT PARENT; };
ps_pglobal_sym { FLAGS = NODIRECT PARENT; };
ps_plog { FLAGS = NODIRECT PARENT; };
ps_pread { FLAGS = NODIRECT PARENT; };
ps_pwrite { FLAGS = NODIRECT PARENT; };
};
#
# 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) 2010, Oracle and/or its affiliates. All rights reserved.
#
PROG=query
SHARED= common.ksh query uninstall.ksh
include $(SRC)/cmd/Makefile.cmd
include ../../Makefile.brand
$(ROOTSHAREDDIR)/common.ksh : FILEMODE = 0444
$(ROOTSHAREDDIR)/uninstall.ksh : FILEMODE = 0444
POFILES= common.po query.po uninstall.po
POFILE= shared.po
$(POFILE): $(POFILES)
$(RM) $@
$(CAT) $(POFILES) > $@
all: $(PROG)
install: $(ROOTSHARED)
clean:
include $(SRC)/cmd/Makefile.targ
#
# 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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
#
# Send the error message to the screen and to the logfile.
#
error()
{
typeset fmt="$1"
shift
printf "${MSG_PREFIX}ERROR: ${fmt}\n" "$@"
[[ -n $LOGFILE ]] && printf "[$(date)] ERROR: ${fmt}\n" "$@" >&2
}
fatal()
{
typeset fmt="$1"
shift
error "$fmt" "$@"
exit $EXIT_CODE
}
fail_fatal() {
typeset fmt="$1"
shift
error "$fmt" "$@"
exit $ZONE_SUBPROC_FATAL
}
#
# Send the provided printf()-style arguments to the screen and to the logfile.
#
log()
{
typeset fmt="$1"
shift
printf "${MSG_PREFIX}${fmt}\n" "$@"
[[ -n $LOGFILE ]] && printf "[$(date)] ${MSG_PREFIX}${fmt}\n" "$@" >&2
}
#
# Print provided text to the screen if the shell variable "OPT_V" is set.
# The text is always sent to the logfile.
#
vlog()
{
typeset fmt="$1"
shift
[[ -n $OPT_V ]] && printf "${MSG_PREFIX}${fmt}\n" "$@"
[[ -n $LOGFILE ]] && printf "[$(date)] ${MSG_PREFIX}${fmt}\n" "$@" >&2
}
#
# Validate that the directory is safe.
#
# It is possible for a malicious zone root user to modify a zone's filesystem
# so that modifications made to the zone's filesystem by administrators in the
# global zone modify the global zone's filesystem. We can prevent this by
# ensuring that all components of paths accessed by scripts are real (i.e.,
# non-symlink) directories.
#
# NOTE: The specified path should be an absolute path as would be seen from
# within the zone. Also, this function does not check parent directories.
# If, for example, you need to ensure that every component of the path
# '/foo/bar/baz' is a directory and not a symlink, then do the following:
#
# safe_dir /foo
# safe_dir /foo/bar
# safe_dir /foo/bar/baz
#
safe_dir()
{
typeset dir="$1"
if [[ -h $ZONEROOT/$dir || ! -d $ZONEROOT/$dir ]]; then
fatal "$e_baddir" "$dir"
fi
}
# Like safe_dir except the dir doesn't have to exist.
safe_opt_dir()
{
typeset dir="$1"
[[ ! -e $ZONEROOT/$dir ]] && return
if [[ -h $ZONEROOT/$dir || ! -d $ZONEROOT/$dir ]]; then
fatal "$e_baddir" "$dir"
fi
}
# Only make a copy if we haven't already done so.
safe_backup()
{
typeset src="$1"
typeset dst="$2"
if [[ ! -h $src && ! -h $dst && ! -d $dst && ! -f $dst ]]; then
/bin/cp -p $src $dst || fatal "$e_badfile" "$src"
fi
}
# Make a copy even if the destination already exists.
safe_copy()
{
typeset src="$1"
typeset dst="$2"
if [[ ! -h $src && ! -h $dst && ! -d $dst ]]; then
/bin/cp -p $src $dst || fatal "$e_badfile" "$src"
fi
}
# Move a file
safe_move()
{
typeset src="$1"
typeset dst="$2"
if [[ ! -h $src && ! -h $dst && ! -d $dst ]]; then
/bin/mv $src $dst || fatal "$e_badfile" "$src"
fi
}
safe_rm()
{
if [[ ! -h $ZONEROOT/$1 && -f $ZONEROOT/$1 ]]; then
rm -f "$ZONEROOT/$1"
fi
}
#
# Replace the file with a wrapper pointing to the native brand code.
# However, we only do the replacement if the file hasn't already been
# replaced with our wrapper. This function expects the cwd to be the
# location of the file we're replacing.
#
# Some of the files we're replacing are hardlinks to isaexec so we need to 'rm'
# the file before we setup the wrapper while others are hardlinks to rc scripts
# that we need to maintain.
#
safe_replace()
{
typeset filename="$1"
typeset runname="$2"
typeset mode="$3"
typeset own="$4"
typeset rem="$5"
if [ -h $filename -o ! -f $filename ]; then
return
fi
egrep -s "Solaris Brand Replacement" $filename
if [ $? -eq 0 ]; then
return
fi
safe_backup $filename $filename.pre_p2v
if [ $rem = "remove" ]; then
rm -f $filename
fi
cat <<-END >$filename || exit 1
#!/bin/sh -p
#
# Solaris Brand Replacement
#
# Attention. This file has been replaced with a new version for
# use in a virtualized environment. Modification of this script is not
# supported and all changes will be lost upon reboot. The
# {name}.pre_p2v version of this file is a backup copy of the
# original and should not be deleted.
#
END
echo ". $runname \"\$@\"" >>$filename || exit 1
chmod $mode $filename
chown $own $filename
}
safe_wrap()
{
typeset filename="$1"
typeset runname="$2"
typeset mode="$3"
typeset own="$4"
if [ -f $filename ]; then
log "$e_cannot_wrap" "$filename"
exit 1
fi
cat <<-END >$filename || exit 1
#!/bin/sh
#
# Solaris Brand Wrapper
#
# Attention. This file has been created for use in a
# virtualized environment. Modification of this script
# is not supported and all changes will be lost upon reboot.
#
END
echo ". $runname \"\$@\"" >>$filename || exit 1
chmod $mode $filename
chown $own $filename
}
#
# Read zonecfg fs entries and save the relevant data, one entry per
# line.
# This assumes the properties from the zonecfg output, e.g.:
# fs:
# dir: /opt
# special: /opt
# raw not specified
# type: lofs
# options: [noexec,ro,noatime]
#
# and it assumes the order of the fs properties as above.
#
get_fs_info()
{
zonecfg -z $zonename info fs | nawk '{
if ($1 == "options:") {
# Remove brackets.
options=substr($2, 2, length($2) - 2);
printf("%s %s %s %s\n", dir, type, special, options);
} else if ($1 == "dir:") {
dir=$2;
} else if ($1 == "special:") {
special=$2;
} else if ($1 == "type:") {
type=$2
}
}' >> $fstmpfile
}
#
# Mount zonecfg fs entries into the zonepath.
#
mnt_fs()
{
if [ ! -s $fstmpfile ]; then
return;
fi
# Sort the fs entries so we can handle nested mounts.
sort $fstmpfile | nawk -v zonepath=$zonepath '{
if (NF == 4)
options="-o " $4;
else
options=""
# Create the mount point. Ignore errors since we might have
# a nested mount with a pre-existing mount point.
cmd="/bin/mkdir -p " zonepath "/root" $1 " >/dev/null 2>&1"
system(cmd);
cmd="/sbin/mount -F " $2 " " options " " $3 " " \
zonepath "/root" $1;
if (system(cmd) != 0) {
printf("command failed: %s\n", cmd);
exit 1;
}
}' >>$LOGFILE
}
#
# Unmount zonecfg fs entries from the zonepath.
#
umnt_fs()
{
if [ ! -s $fstmpfile ]; then
return;
fi
# Reverse sort the fs entries so we can handle nested unmounts.
sort -r $fstmpfile | nawk -v zonepath=$zonepath '{
cmd="/sbin/umount " zonepath "/root" $1
if (system(cmd) != 0) {
printf("command failed: %s\n", cmd);
}
}' >>$LOGFILE
}
# Find the dataset mounted on the zonepath.
get_zonepath_ds() {
ZONEPATH_DS=`/sbin/zfs list -H -t filesystem -o name,mountpoint | \
/bin/nawk -v zonepath=$1 '{
if ($2 == zonepath)
print $1
}'`
if [ -z "$ZONEPATH_DS" ]; then
fail_fatal "$f_no_ds"
fi
}
#
# Perform validation and cleanup in the zoneroot after unpacking the archive.
#
post_unpack()
{
#
# Check if the image was created with a valid libc.so.1.
#
hwcap=`moe -v -32 $ZONEROOT/lib/libc.so.1 2>&1`
if (( $? != 0 )); then
vlog "$f_hwcap_info" "$hwcap"
fail_fatal "$f_sanity_hwcap"
fi
( cd "$ZONEROOT" && \
find . \( -type b -o -type c \) -exec rm -f "{}" \; )
}
#
# Determine flar compression style from identification file.
#
get_compression()
{
typeset ident=$1
typeset line=$(grep "^files_compressed_method=" $ident)
print ${line##*=}
}
#
# Determine flar archive style from identification file.
#
get_archiver()
{
typeset ident=$1
typeset line=$(grep "^files_archived_method=" $ident)
print ${line##*=}
}
#
# Unpack flar into current directory (which should be zoneroot). The flash
# archive is standard input. See flash_archive(5) man page.
#
# We can't use "flar split" since it will only unpack into a directory called
# "archive". We need to unpack in place in order to properly handle nested
# fs mounts within the zone root. This function does the unpacking into the
# current directory.
#
# This code is derived from the gen_split() function in /usr/sbin/flar so
# we keep the same style as the original.
#
install_flar()
{
typeset result
typeset archiver_command
typeset archiver_arguments
vlog "cd $ZONEROOT && $stage1 "$insrc" | install_flar"
# Read cookie
read -r input_line
if (( $? != 0 )); then
log "$not_readable" "$install_media"
return 1
fi
# The cookie has format FlAsH-aRcHiVe-m.n where m and n are integers.
if [[ ${input_line%%-[0-9]*.[0-9]*} != "FlAsH-aRcHiVe" ]]; then
log "$not_flar"
return 1
fi
while [ true ]
do
# We should always be at the start of a section here
read -r input_line
if [[ ${input_line%%=*} != "section_begin" ]]; then
log "$bad_flar"
return 1
fi
section_name=${input_line##*=}
# If we're at the archive, we're done skipping sections.
if [[ "$section_name" == "archive" ]]; then
break
fi
#
# Save identification section to a file so we can determine
# how to unpack the archive.
#
if [[ "$section_name" == "identification" ]]; then
/bin/rm -f identification
while read -r input_line
do
if [[ ${input_line%%=*} == \
"section_begin" ]]; then
/bin/rm -f identification
log "$bad_flar"
return 1
fi
if [[ $input_line == \
"section_end=$section_name" ]]; then
break;
fi
echo $input_line >> identification
done
continue
fi
#
# Otherwise skip past this section; read lines until detecting
# section_end. According to flash_archive(5) we can have
# an arbitrary number of sections but the archive section
# must be last.
#
success=0
while read -r input_line
do
if [[ $input_line == "section_end=$section_name" ]];
then
success=1
break
fi
# Fail if we miss the end of the section
if [[ ${input_line%%=*} == "section_begin" ]]; then
/bin/rm -f identification
log "$bad_flar"
return 1
fi
done
if (( $success == 0 )); then
#
# If we get here we read to the end of the file before
# seeing the end of the section we were reading.
#
/bin/rm -f identification
log "$bad_flar"
return 1
fi
done
# Check for an archive made from a ZFS root pool.
egrep -s "^rootpool=" identification
if (( $? == 0 )); then
/bin/rm -f identification
log "$bad_zfs_flar"
return 1
fi
# Get the information needed to unpack the archive.
archiver=$(get_archiver identification)
if [[ $archiver == "pax" ]]; then
# pax archiver specified
archiver_command="/usr/bin/pax"
if [[ -s $fspaxfile ]]; then
archiver_arguments="-r -p e -c \
$(/bin/cat $fspaxfile)"
else
archiver_arguments="-r -p e"
fi
elif [[ $archiver == "cpio" || -z $archiver ]]; then
# cpio archived specified OR no archiver specified - use default
archiver_command="/usr/bin/cpio"
archiver_arguments="-icdumfE $fscpiofile"
else
# unknown archiver specified
log "$unknown_archiver" $archiver
return 1
fi
if [[ ! -x $archiver_command ]]; then
/bin/rm -f identification
log "$cmd_not_exec" $archiver_command
return 1
fi
compression=$(get_compression identification)
# We're done with the identification file
/bin/rm -f identification
# Extract archive
if [[ $compression == "compress" ]]; then
/usr/bin/zcat | \
$archiver_command $archiver_arguments 2>/dev/null
else
$archiver_command $archiver_arguments 2>/dev/null
fi
result=$?
post_unpack
(( $result != 0 )) && return 1
return 0
}
#
# Get the archive base.
#
# We must unpack the archive in the right place within the zonepath so
# that files are installed into the various mounted filesystems that are set
# up in the zone's configuration. These are already mounted for us by the
# mntfs function.
#
# Archives can be made of either a physical host's root file system or a
# zone's zonepath. For a physical system, if the archive is made using an
# absolute path (/...) we can't use it. For a zone the admin can make the
# archive from a variety of locations;
#
# a) zonepath itself: This will be a single dir, probably named with the
# zone name, it will contain a root dir and under the root we'll see all
# the top level dirs; etc, var, usr... We must be above the ZONEPATH
# when we unpack the archive but this will only work if the the archive's
# top-level dir name matches the ZONEPATH base-level dir name. If not,
# this is an error.
#
# b) inside the zonepath: We'll see root and it will contain all the top
# level dirs; etc, var, usr.... We must be in the ZONEPATH when we unpack
# the archive.
#
# c) inside the zonepath root: We'll see all the top level dirs, ./etc,
# ./var, ./usr.... This is also the case we see when we get an archive
# of a physical system. We must be in ZONEROOT when we unpack the archive.
#
# Note that there can be a directory named "root" under the ZONEPATH/root
# directory.
#
# This function handles the above possibilities so that we reject absolute
# path archives and figure out where in the file system we need to be to
# properly unpack the archive into the zone. It sets the ARCHIVE_BASE
# variable to the location where the achive should be unpacked.
#
get_archive_base()
{
stage1=$1
archive=$2
stage2=$3
vlog "$m_analyse_archive"
base=`$stage1 $archive | $stage2 2>/dev/null | nawk -F/ '{
# Check for an absolute path archive
if (substr($0, 1, 1) == "/")
exit 1
if ($1 != ".")
dirs[$1] = 1
else
dirs[$2] = 1
}
END {
for (d in dirs) {
cnt++
if (d == "bin") sawbin = 1
if (d == "etc") sawetc = 1
if (d == "root") sawroot = 1
if (d == "var") sawvar = 1
}
if (cnt == 1) {
# If only one top-level dir named root, we are in the
# zonepath, otherwise this must be an archive *of*
# the zonepath so print the top-level dir name.
if (sawroot)
print "*zonepath*"
else
for (d in dirs) print d
} else {
# We are either in the zonepath or in the zonepath/root
# (or at the top level of a full system archive which
# looks like the zonepath/root case). Figure out which
# one.
if (sawroot && !sawbin && !sawetc && !sawvar)
print "*zonepath*"
else
print "*zoneroot*"
}
}'`
if (( $? != 0 )); then
umnt_fs
fatal "$e_absolute_archive"
fi
if [[ "$base" == "*zoneroot*" ]]; then
ARCHIVE_BASE=$ZONEROOT
elif [[ "$base" == "*zonepath*" ]]; then
ARCHIVE_BASE=$ZONEPATH
else
# We need to be in the dir above the ZONEPATH but we need to
# validate that $base matches the final component of ZONEPATH.
bname=`basename $ZONEPATH`
if [[ "$bname" != "$base" ]]; then
umnt_fs
fatal "$e_mismatch_archive" "$base" "$bname"
fi
ARCHIVE_BASE=`dirname $ZONEPATH`
fi
}
#
# Unpack cpio archive into zoneroot.
#
install_cpio()
{
stage1=$1
archive=$2
get_archive_base "$stage1" "$archive" "cpio -it"
cpioopts="-idmfE $fscpiofile"
vlog "cd \"$ARCHIVE_BASE\" && $stage1 \"$archive\" | cpio $cpioopts"
# Ignore errors from cpio since we expect some errors depending on
# how the archive was made.
( cd "$ARCHIVE_BASE" && $stage1 "$archive" | cpio $cpioopts )
post_unpack
return 0
}
#
# Unpack pax archive into zoneroot.
#
install_pax()
{
archive=$1
get_archive_base "cat" "$archive" "pax"
if [[ -s $fspaxfile ]]; then
filtopt="-c $(/bin/cat $fspaxfile)"
fi
vlog "cd \"$ARCHIVE_BASE\" && pax -r -f \"$archive\" $filtopt"
# Ignore errors from pax since we expect some errors depending on
# how the archive was made.
( cd "$ARCHIVE_BASE" && pax -r -f "$archive" $filtopt )
post_unpack
return 0
}
#
# Unpack UFS dump into zoneroot.
#
install_ufsdump()
{
archive=$1
vlog "cd \"$ZONEROOT\" && ufsrestore rf \"$archive\""
#
# ufsrestore goes interactive if you ^C it. To prevent that,
# we make sure its stdin is not a terminal.
#
( cd "$ZONEROOT" && ufsrestore rf "$archive" < /dev/null )
result=$?
post_unpack
return $result
}
#
# Copy directory hierarchy into zoneroot.
#
install_dir()
{
source_dir=$1
cpioopts="-pdm"
first=1
filt=$(for i in $(cat $fspaxfile)
do
echo $i | egrep -s "/" && continue
if [[ $first == 1 ]]; then
printf "^%s" $i
first=0
else
printf "|^%s" $i
fi
done)
list=$(cd "$source_dir" && ls -d * | egrep -v "$filt")
flist=$(for i in $list
do
printf "%s " "$i"
done)
findopts="-xdev ( -type d -o -type f -o -type l ) -print"
vlog "cd \"$source_dir\" && find $flist $findopts | "
vlog "cpio $cpioopts \"$ZONEROOT\""
# Ignore errors from cpio since we expect some errors depending on
# how the archive was made.
( cd "$source_dir" && find $flist $findopts | \
cpio $cpioopts "$ZONEROOT" )
post_unpack
return 0
}
#
# This is a common function for laying down a zone image from a variety of
# different sources. This can be used to either install a fresh zone or as
# part of zone migration during attach.
#
# The first argument specifies the type of image: archive, directory or stdin.
# The second argument specifies the image itself. In the case of stdin, the
# second argument specifies the format of the stream (cpio, flar, etc.).
# Any validation or post-processing on the image is done elsewhere.
#
# This function calls a 'sanity_check' function which must be provided by
# the script which includes this code.
#
install_image()
{
intype=$1
insrc=$2
if [[ -z "$intype" || -z "$insrc" ]]; then
return 1
fi
filetype="unknown"
filetypename="unknown"
stage1="cat"
if [[ "$intype" == "directory" ]]; then
if [[ "$insrc" == "-" ]]; then
# Indicates that the existing zonepath is prepopulated.
filetype="existing"
filetypename="existing"
else
if [[ "$(echo $insrc | cut -c 1)" != "/" ]]; then
fatal "$e_path_abs" "$insrc"
fi
if [[ ! -e "$insrc" ]]; then
log "$e_not_found" "$insrc"
fatal "$e_install_abort"
fi
if [[ ! -r "$insrc" ]]; then
log "$e_not_readable" "$insrc"
fatal "$e_install_abort"
fi
if [[ ! -d "$insrc" ]]; then
log "$e_not_dir"
fatal "$e_install_abort"
fi
sanity_check $insrc
filetype="directory"
filetypename="directory"
fi
else
# Common code for both archive and stdin stream.
if [[ "$intype" == "archive" ]]; then
if [[ ! -f "$insrc" ]]; then
log "$e_unknown_archive"
fatal "$e_install_abort"
fi
ftype="$(LC_ALL=C file $insrc | cut -d: -f 2)"
else
# For intype == stdin, the insrc parameter specifies
# the stream format coming on stdin.
ftype="$insrc"
insrc="-"
fi
# Setup vars for the archive type we have.
case "$ftype" in
*cpio*) filetype="cpio"
filetypename="cpio archive"
;;
*bzip2*) filetype="bzip2"
filetypename="bzipped cpio archive"
;;
*gzip*) filetype="gzip"
filetypename="gzipped cpio archive"
;;
*ufsdump*) filetype="ufsdump"
filetypename="ufsdump archive"
;;
"flar")
filetype="flar"
filetypename="flash archive"
;;
"flash")
filetype="flar"
filetypename="flash archive"
;;
*Flash\ Archive*)
filetype="flar"
filetypename="flash archive"
;;
"tar")
filetype="tar"
filetypename="tar archive"
;;
*USTAR\ tar\ archive)
filetype="tar"
filetypename="tar archive"
;;
"pax")
filetype="xustar"
filetypename="pax (xustar) archive"
;;
*USTAR\ tar\ archive\ extended\ format*)
filetype="xustar"
filetypename="pax (xustar) archive"
;;
"zfs")
filetype="zfs"
filetypename="ZFS send stream"
;;
*ZFS\ snapshot\ stream*)
filetype="zfs"
filetypename="ZFS send stream"
;;
*) log "$e_unknown_archive"
fatal "$e_install_abort"
;;
esac
fi
vlog "$filetypename"
# Check for a non-empty root if no '-d -' option.
if [[ "$filetype" != "existing" ]]; then
cnt=$(ls $ZONEROOT | wc -l)
if (( $cnt != 0 )); then
fatal "$e_root_full" "$ZONEROOT"
fi
fi
fstmpfile=$(/usr/bin/mktemp -t -p /var/tmp)
if [[ -z "$fstmpfile" ]]; then
fatal "$e_tmpfile"
fi
# Make sure we always have the files holding the directories to filter
# out when extracting from a CPIO or PAX archive. We'll add the fs
# entries to these files in get_fs_info()
fscpiofile=$(/usr/bin/mktemp -t -p /var/tmp fs.cpio.XXXXXX)
if [[ -z "$fscpiofile" ]]; then
rm -f $fstmpfile
fatal "$e_tmpfile"
fi
# Filter out these directories.
echo 'dev/*' >>$fscpiofile
echo 'devices/*' >>$fscpiofile
echo 'devices' >>$fscpiofile
echo 'proc/*' >>$fscpiofile
echo 'tmp/*' >>$fscpiofile
echo 'var/run/*' >>$fscpiofile
echo 'system/contract/*' >>$fscpiofile
echo 'system/object/*' >>$fscpiofile
fspaxfile=$(/usr/bin/mktemp -t -p /var/tmp fs.pax.XXXXXX)
if [[ -z "$fspaxfile" ]]; then
rm -f $fstmpfile $fscpiofile
fatal "$e_tmpfile"
fi
printf "%s " \
"dev devices proc tmp var/run system/contract system/object" \
>>$fspaxfile
# Set up any fs mounts so the archive will install into the correct
# locations.
get_fs_info
mnt_fs
if (( $? != 0 )); then
umnt_fs >/dev/null 2>&1
rm -f $fstmpfile $fscpiofile $fspaxfile
fatal "$mount_failed"
fi
if [[ "$filetype" == "existing" ]]; then
log "$no_installing"
else
log "$installing"
fi
#
# Install the image into the zonepath.
#
unpack_result=0
stage1="cat"
if [[ "$filetype" == "gzip" ]]; then
stage1="gzcat"
filetype="cpio"
elif [[ "$filetype" == "bzip2" ]]; then
stage1="bzcat"
filetype="cpio"
fi
if [[ "$filetype" == "cpio" ]]; then
install_cpio "$stage1" "$insrc"
unpack_result=$?
elif [[ "$filetype" == "flar" ]]; then
( cd "$ZONEROOT" && $stage1 $insrc | install_flar )
unpack_result=$?
elif [[ "$filetype" == "xustar" ]]; then
install_pax "$insrc"
unpack_result=$?
elif [[ "$filetype" = "tar" ]]; then
vlog "cd \"$ZONEROOT\" && tar -xf \"$insrc\""
# Ignore errors from tar since we expect some errors depending
# on how the archive was made.
( cd "$ZONEROOT" && tar -xf "$insrc" )
unpack_result=0
post_unpack
elif [[ "$filetype" == "ufsdump" ]]; then
install_ufsdump "$insrc"
unpack_result=$?
elif [[ "$filetype" == "directory" ]]; then
install_dir "$insrc"
unpack_result=$?
elif [[ "$filetype" == "zfs" ]]; then
#
# Given a 'zfs send' stream file, receive the snapshot into
# the zone's dataset. We're getting the original system's
# zonepath dataset. Destroy the existing dataset created
# above since this recreates it.
#
if [[ -z "$DATASET" ]]; then
fatal "$f_nodataset"
fi
/sbin/zfs destroy "$DATASET"
if (( $? != 0 )); then
log "$f_zfsdestroy" "$DATASET"
fi
vlog "$stage1 $insrc | zfs receive -F $DATASET"
( $stage1 $insrc | /sbin/zfs receive -F $DATASET )
unpack_result=$?
fi
# Clean up any fs mounts used during unpacking.
umnt_fs
rm -f $fstmpfile $fscpiofile $fspaxfile
chmod 700 $zonepath
(( $unpack_result != 0 )) && fatal "$f_unpack_failed"
# Verify this is a valid image.
sanity_check $ZONEROOT
return 0
}
# Setup i18n output
TEXTDOMAIN="SUNW_OST_OSCMD"
export TEXTDOMAIN
e_cannot_wrap=$(gettext "%s: error: wrapper file already exists")
e_baddir=$(gettext "Invalid '%s' directory within the zone")
e_badfile=$(gettext "Invalid '%s' file within the zone")
e_path_abs=$(gettext "Pathname specified to -a '%s' must be absolute.")
e_not_found=$(gettext "%s: error: file or directory not found.")
e_install_abort=$(gettext "Installation aborted.")
e_not_readable=$(gettext "Cannot read directory '%s'")
e_not_dir=$(gettext "Error: must be a directory")
e_unknown_archive=$(gettext "Error: Unknown archive format. Must be a flash archive, a cpio archive (can also be gzipped or bzipped), a pax XUSTAR archive, or a level 0 ufsdump archive.")
e_absolute_archive=$(gettext "Error: archive contains absolute paths instead of relative paths.")
e_mismatch_archive=$(gettext "Error: the archive top-level directory (%s) does not match the zonepath (%s).")
e_tmpfile=$(gettext "Unable to create temporary file")
e_root_full=$(gettext "Zonepath root %s exists and contains data; remove or move aside prior to install.")
f_mkdir=$(gettext "Unable to create directory %s.")
f_chmod=$(gettext "Unable to chmod directory %s.")
f_chown=$(gettext "Unable to chown directory %s.")
f_hwcap_info=$(gettext "HWCAP: %s\n")
f_sanity_hwcap=$(gettext \
"The image was created with an incompatible libc.so.1 hwcap lofs mount.\n"\
" The zone will not boot on this platform. See the zone's\n"\
" documentation for the recommended way to create the archive.")
m_analyse_archive=$(gettext "Analysing the archive")
not_readable=$(gettext "Cannot read file '%s'")
not_flar=$(gettext "Input is not a flash archive")
bad_flar=$(gettext "Flash archive is a corrupt")
bad_zfs_flar=$(gettext "Flash archive contains a ZFS send stream.\n\tRecreate the flar using the -L option with cpio or pax.")
f_unpack_failed=$(gettext "Unpacking the archive failed")
unknown_archiver=$(gettext "Archiver %s is not supported")
cmd_not_exec=$(gettext "Required command '%s' not executable!")
#
# Exit values used by the script, as #defined in <sys/zone.h>
#
# ZONE_SUBPROC_OK
# ===============
# Installation was successful
#
# ZONE_SUBPROC_USAGE
# ==================
# Improper arguments were passed, so print a usage message before exiting
#
# ZONE_SUBPROC_NOTCOMPLETE
# ========================
# Installation did not complete, but another installation attempt can be
# made without an uninstall
#
# ZONE_SUBPROC_FATAL
# ==================
# Installation failed and an uninstall will be required before another
# install can be attempted
#
ZONE_SUBPROC_OK=0
ZONE_SUBPROC_USAGE=253
ZONE_SUBPROC_NOTCOMPLETE=254
ZONE_SUBPROC_FATAL=255
#!/bin/ksh -p
#
# 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) 2010, Oracle and/or its affiliates. All rights reserved.
#
PATH=/usr/bin:/usr/sbin
export PATH
. /usr/lib/brand/shared/common.ksh
zonename=$1
zonepath=$2
cmd=$3
if [ $3 == "datasets" ]; then
get_zonepath_ds $zonepath
DS=`/sbin/zfs list -H -t filesystem -o name $ZONEPATH_DS/ROOT`
if [ ! -z "$DS" ]; then
echo "$DS\c"
else
fail_fatal "$f_no_ds"
fi
fi
exit $ZONE_SUBPROC_OK
#
# 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) 2010, Oracle and/or its affiliates. All rights reserved.
#
#
# get script name (bname)
#
bname=`basename $0`
#
# common shell script functions
#
. /usr/lib/brand/shared/common.ksh
#
# error messages
#
m_usage=$(gettext "Usage: %s: [-hFn]")
m_1_zfs_promote=$(gettext "promoting '%s'.")
m_1_zfs_destroy=$(gettext "destroying '%s'.")
m_2_zfs_rename=$(gettext "renaming '%s' to '%s'.")
m_3_zfs_set=$(gettext "setting property %s='%s' for '%s'.")
m_rm_r=$(gettext "recursively deleting '%s'.")
m_rm=$(gettext "deleting '%s'.")
w_no_ds=$(gettext "Warning: no zonepath dataset found.")
f_usage_err=$(gettext "Error: invalid usage")
f_abort=$(gettext "Error: internal error detected, aborting.")
f_1_zfs_promote=$(gettext "Error: promoting ZFS dataset '%s'.")
f_2_zfs_rename=$(gettext "Error: renaming ZFS dataset '%s' to '%s'.")
f_3_zfs_set=$(gettext "Error: setting ZFS propery %s='%s' for '%s'.")
f_1_zfs_destroy=$(gettext "Error: destroying ZFS dataset.")
f_2_zfs_get=$(gettext "Error: reading ZFS dataset property '%s' from '%s'.")
f_user_snap=$(gettext "Error: user snapshot(s) detected.")
f_stray_snap=$(gettext "Error: uncloned snapshot(s) detected.")
f_stray_clone=$(gettext "Error: cloned zone datasets found outsize of zone.")
f_rm_snap=$(gettext "Error: please delete snapshot(s) and retry uninstall.")
f_rm_clone=$(gettext "Error: please delete clone(s) and retry uninstall.")
f_iu_clone=$(gettext "Error: cloned zone dataset(s) in use.")
f_dis_clone=$(gettext "Error: please stop using clone(s) and retry uninstall.")
#
# functions
#
print_array()
{
typeset -n pa_array=$1
(( pa_i = 0 ))
while (( $pa_i < ${#pa_array[@]} )); do
printf "\t${pa_array[$pa_i]}\n"
(( pa_i = $pa_i + 1 ))
done
}
usage()
{
printf "$m_usage\n" "$bname"
exit $ZONE_SUBPROC_USAGE
}
usage_err()
{
printf "$f_usage_err\n" >&2
usage >&2
}
rm_zonepath()
{
# cleanup stuff we know about and leave any user data alone
[[ -z "$opt_n" ]] && [[ -n "$opt_v" ]] &&
printf "$m_rm\n" "$zonepath/SUNWattached.xml"
$nop /bin/rm -f "$zonepath/SUNWattached.xml"
[[ -z "$opt_n" ]] && [[ -n "$opt_v" ]] &&
printf "$m_rm_r\n" "$zonepath/lu"
$nop /bin/rm -rf "$zonepath/lu"
[[ -z "$opt_n" ]] && [[ -n "$opt_v" ]] &&
printf "$m_rm_r\n" "$zonepath/dev"
$nop /bin/rm -rf "$zonepath/dev"
[[ -z "$opt_n" ]] && [[ -n "$opt_v" ]] &&
printf "$m_rm_r\n" "$zonepath/root"
$nop /bin/rm -rf "$zonepath/root"
[[ -z "$opt_n" ]] && [[ -n "$opt_v" ]] &&
printf "$m_rm\n" "$zonepath"
$nop /bin/rmdir "$zonepath" 2>/dev/null
}
zfs_destroy()
{
zd_fs1="$1"
# first figure out if the target fs has an origin snapshot
zd_origin=`/sbin/zfs get -H -o value origin "$zd_fs1"`
if [[ $? != 0 ]]; then
printf "$f_2_zfs_get\n" origin "$zd_fs1" >&2
exit $ZONE_SUBPROC_FATAL
fi
[[ -z "$opt_n" ]] && [[ -n "$opt_v" ]] &&
printf "$m_1_zfs_destroy\n" "$zd_fs1"
#
# note that we specify the '-r' flag so that we destroy any
# descendants (filesystems and snapshot) of the specified
# filesystem.
#
$nop /sbin/zfs destroy -r "$zd_fs1"
if [[ $? != 0 ]]; then
printf "$f_1_zfs_destroy\n" "$zd_fs1" >&2
exit $ZONE_SUBPROC_FATAL
fi
[[ "$zd_origin" == "-" ]] && return
[[ -z "$opt_n" ]] && [[ -n "$opt_v" ]] &&
printf "$m_1_zfs_destroy\n" "$zd_origin"
$nop /sbin/zfs destroy "$zd_origin" 2>/dev/null
#
# we ignore errors while trying to destroy the origin since
# the origin could have been used as the source for other
# clones
#
}
zfs_promote()
{
zp_fs1="$1"
[[ -z "$opt_n" ]] &&
printf "$m_1_zfs_promote\n" "$zp_fs1"
$nop /sbin/zfs promote "$zp_fs1"
if [[ $? != 0 ]]; then
printf "$f_1_zfs_promote\n" "$zp_fs1" >&2
exit $ZONE_SUBPROC_FATAL
fi
}
zfs_rename()
{
zr_fs1="$1"
zr_fs2="$2"
[[ -z "$opt_n" ]] &&
printf "$m_2_zfs_rename\n" "$zr_fs1" "$zr_fs2"
$nop /sbin/zfs rename "$zr_fs1" "$zr_fs2"
if [[ $? != 0 ]]; then
printf "$f_2_zfs_rename\n" "$zr_fs1" "$zr_fs2" >&2
return 1
fi
return 0
}
zfs_set()
{
zs_prop=$1
zs_value=$2
zs_fs1=$3
[[ -z "$opt_n" ]] && [[ -n "$opt_v" ]] &&
printf "$m_3_zfs_set\n" "$zs_prop" "$zs_value" "$zs_fs1"
$nop /sbin/zfs set "$zs_prop"="$zs_value" "$zs_fs1"
if [[ $? != 0 ]]; then
printf "$f_3_zfs_set\n" "$zs_prop" "$zs_value" "$zs_fs1"
return 1
fi
return 0
}
zfs_set_array()
{
zsa_prop=$1
zsa_value=$2
typeset -n zsa_array=$3
zsa_ignore_errors=$4
(( zsa_i = 0 ))
while (( $zsa_i < ${#zsa_array[@]} )); do
zfs_set "$zsa_prop" "$zsa_value" "${zsa_array[$zsa_i]}"
[[ $? != 0 ]] && [[ -z "$zsa_ignore_errors" ]] &&
return 1
(( zsa_i = $zsa_i + 1 ))
done
return 0
}
(( snap_rename_zbe_i = 1 ))
(( snap_rename_snap_i = 1 ))
snap_rename_init()
{
(( snap_rename_zbe_i = 1 ))
(( snap_rename_snap_i = 1 ))
}
snap_rename()
{
eval sr_fs=\${$1}
eval sr_snap=\${$2}
if [[ "$sr_snap" == ~(Elr)(zbe-[0-9][0-9]*) ]]; then
sr_snap="zbe-$snap_rename_zbe_i"
(( snap_rename_zbe_i = $snap_rename_zbe_i + 1 ))
elif [[ "$sr_snap" == ~(Er)(_snap[0-9]*) ]]; then
sr_snap=${sr_snap##~(Er)([0-9]*)}
sr_snap="${sr_snap}${snap_rename_snap_i}"
(( snap_rename_snap_i = $snap_rename_snap_i + 1 ))
else
printf "$f_user_snap\n" >&2
printf "\t$sr_fs@$sr_snap\n" >&2
printf "$f_rm_snap\n" >&2
exit $ZONE_SUBPROC_FATAL
fi
eval $2="$sr_snap"
}
# find the dataset associated with $zonepath
uninstall_get_zonepath_ds()
{
ZONEPATH_DS=`/sbin/zfs list -t filesystem -o name,mountpoint | \
/bin/nawk -v zonepath=$zonepath '{
if ($2 == zonepath)
print $1
}'`
if [ -z "$ZONEPATH_DS" ]; then
# there is no $zonepath dataset
rm_zonepath
exit $ZONE_SUBPROC_OK
fi
}
# find the dataset associated with $ZONEPATH_DS/ROOT
uninstall_get_zonepath_root_ds()
{
ZONEPATH_RDS=`/sbin/zfs list -H -t filesystem -o name \
$ZONEPATH_DS/ROOT 2>/dev/null`
if [ -z "$ZONEPATH_RDS" ]; then
# there is no $ZONEPATH_DS/ROOT dataset
c=`/sbin/zfs list -H -t filesystem -r $ZONEPATH_DS | wc -l`
if [ $c = 1 ]; then
# $zonepath dataset has no descendents
zfs_destroy "$ZONEPATH_DS"
fi
rm_zonepath
exit $ZONE_SUBPROC_OK
fi
}
destroy_zone_dataset()
{
fs=$1
pool=${fs%%/*}
# Fastpath. if there are no snapshots of $fs then just delete it.
c=`/sbin/zfs list -H -t snapshot -o name -r $fs | grep "^$fs@" |
LC_ALL=C LANG=C wc -l`
if (( $c == 0 )) ; then
zfs_destroy "$fs"
return
fi
#
# This zone BE has snapshots. This can happen if a zone has
# multiple BEs (in which case we have snapshots named "zbe-XXX"),
# if this zone has been used as the source for a clone of
# another zone (in which case we have snapshots named
# "XXX_snap"), or if an administrator has been doing manual
# snapshotting.
#
# To be able to destroy this dataset (which we'll call the
# origin) we need to get rid of all it's snapshots. The "easiest"
# way to do this is to:
#
# - delete any uncloned origin snapshots
# - find the oldest clone of the youngest origin snapshot (which
# we'll call the oldest clone)
# - check if there are any snapshots naming conflicts between
# the origin and the oldest clone.
# - if so, find any clones of those conflicting origin snapshots
# - make sure that those clones are not zoned an in-use.
# - if any of those clones are zoned, unzone them.
# - rename origin snapshots to eliminate naming conflicts
# - for any clones that we unzoned, rezone them.
# - promote the oldest clone
# - destroy the origin and all it's descendants
#
#
# Get a list of all the cloned datasets within the zpool
# containing the origin filesystem. Filter out any filesystems
# that are descendants of origin because we are planning to
# destroy them anyway.
#
unset clones clones_origin
(( clones_c = 0 ))
pool=${fs%%/*}
LANG=C LC_ALL=C /sbin/zfs list -H -t filesystem -s creation \
-o name,origin -r "$pool" |
while IFS=" " read name origin; do
# skip non-clone filesystems
[[ "$origin" == "-" ]] &&
continue
# skip desendents of the origin we plan to destroy
[[ "$name" == ~()(${fs}/*) ]] &&
continue
# record this clone and it's origin
clones[$clones_c]="$name"
clones_origin[$clones_c]="$origin"
(( clones_c = $clones_c + 1 ))
done
#
# Now do a sanity check. Search for clones of a child datasets
# of the dataset we want to destroy, that are not themselves
# children of the dataset we're going to destroy). This should
# really never happen unless the global zone admin has cloned a
# snapshot of a zone filesystem to a location outside of that
# zone. bad admin...
#
unset stray_clones
(( stray_clones_c = 0 ))
(( j = 0 ))
while (( $j < $clones_c )); do
# is the clone origin a descendant of $fs?
if [[ "${clones_origin[$j]}" != ~()(${fs}/*) ]]; then
# we don't care.
(( j = $j + 1 ))
continue
fi
stray_clones[$stray_clones_c]=${clones[$j]}
(( stray_clones_c = $stray_clones_c + 1 ))
(( j = $j + 1 ))
done
if (( stray_clones_c > 0 )); then
#
# sigh. the admin has done something strange.
# tell them to clean it up and retry.
#
printf "$f_stray_clone\n" >&2
print_array stray_clones >&2
printf "$f_rm_clone\n" >&2
exit $ZONE_SUBPROC_FATAL
fi
# Find all the snapshots of the origin filesystem.
unset s_origin
(( s_origin_c = 0 ))
/sbin/zfs list -H -t snapshot -s creation -o name -r $fs |
grep "^$fs@" | while read name; do
s_origin[$s_origin_c]=$name
(( s_origin_c = $s_origin_c + 1 ))
done
#
# Now go through the origin snapshots and find those which don't
# have clones. We're going to explicity delete these snapshots
# before we do the promotion.
#
unset s_delete
(( s_delete_c = 0 ))
(( j = 0 ))
while (( $j < $s_origin_c )); do
(( k = 0 ))
while (( $k < $clones_c )); do
# if we have a match then break out of this loop
[[ "${s_origin[$j]}" == "${clones_origin[$k]}" ]] &&
break
(( k = $k + 1 ))
done
if (( $k != $clones_c )); then
# this snapshot has a clone, move on to the next one
(( j = $j + 1 ))
continue
fi
# snapshot has no clones so add it to our delete list
s_delete[$s_delete_c]=${s_origin[$j]}
(( s_delete_c = $s_delete_c + 1 ))
# remove it from the origin snapshot list
(( k = $j + 1 ))
while (( $k < $s_origin_c )); do
s_origin[(( $k - 1 ))]=${s_origin[$k]}
(( k = $k + 1 ))
done
(( s_origin_c = $s_origin_c - 1 ))
done
#
# Fastpath. If there are no remaining snapshots then just
# delete the origin filesystem (and all it's descendents) and
# move onto the next zone BE.
#
if (( $s_origin_c == 0 )); then
zfs_destroy "$fs"
return
fi
# find the youngest snapshot of $fs
s_youngest=${s_origin[(( $s_origin_c - 1 ))]}
# Find the oldest clone of the youngest snapshot of $fs
unset s_clone
(( j = $clones_c - 1 ))
while (( $j >= 0 )); do
if [[ "$s_youngest" == "${clones_origin[$j]}" ]]; then
s_clone=${clones[$j]}
break
fi
(( j = $j - 1 ))
done
if [[ -z "$s_clone" ]]; then
# uh oh. something has gone wrong. bail.
printf "$f_stray_snap\n" >&2
printf "\t$s_youngest\n" >&2
printf "$f_rm_snap\n" >&2
exit $ZONE_SUBPROC_FATAL
fi
# create an array of clone snapshot names
unset s_clone_s
(( s_clone_s_c = 0 ))
/sbin/zfs list -H -t snapshot -s creation -o name -r $s_clone |
grep "^$s_clone@" | while read name; do
s_clone_s[$s_clone_s_c]=${name##*@}
(( s_clone_s_c = $s_clone_s_c + 1 ))
done
# create an arrays of possible origin snapshot renames
unset s_origin_snap
unset s_rename
(( j = 0 ))
while (( $j < $s_origin_c )); do
s_origin_snap[$j]=${s_origin[$j]##*@}
s_rename[$j]=${s_origin[$j]##*@}
(( j = $j + 1 ))
done
#
# Search for snapshot name collisions between the origin and
# oldest clone. If we find one, generate a new name for the
# origin snapshot and re-do the collision check.
#
snap_rename_init
(( j = 0 ))
while (( $j < $s_origin_c )); do
(( k = 0 ))
while (( $k < $s_clone_s_c )); do
# if there's no naming conflict continue
if [[ "${s_rename[$j]}" != "${s_clone_s[$k]}" ]]; then
(( k = $k + 1 ))
continue
fi
#
# The origin snapshot conflicts with a clone
# snapshot. Choose a new name and then restart
# then check that against clone snapshot names.
#
snap_rename fs "s_rename[$j]"
(( k = 0 ))
continue;
done
# if we didn't rename this snapshot then continue
if [[ "${s_rename[$j]}" == "${s_origin_snap[$j]}" ]]; then
(( j = $j + 1 ))
continue
fi
#
# We need to rename this origin snapshot because it
# conflicts with a clone snapshot name. So above we
# chose a name that didn't conflict with any other clone
# snapshot names. But we also have to avoid naming
# conflicts with any other origin snapshot names. So
# check for that now.
#
(( k = 0 ))
while (( $k < $s_origin_c )); do
# don't compare against ourself
if (( $j == $k )); then
(( k = $k + 1 ))
continue
fi
# if there's no naming conflict continue
if [[ "${s_rename[$j]}" != "${s_rename[$k]}" ]]; then
(( k = $k + 1 ))
continue
fi
#
# The new origin snapshot name conflicts with
# another origin snapshot name. Choose a new
# name and then go back to check the new name
# for uniqueness against all the clone snapshot
# names.
#
snap_rename fs "s_rename[$j]"
continue 2;
done
#
# A new unique name has been chosen. Move on to the
# next origin snapshot.
#
(( j = $j + 1 ))
snap_rename_init
done
#
# So now we know what snapshots need to be renamed before the
# promotion. But there's an additional problem. If any of the
# filesystems cloned from these snapshots have the "zoned"
# attribute set (which is highly likely) or if they are in use
# (and can't be unmounted and re-mounted) then the snapshot
# rename will fail. So now we'll search for all the clones of
# snapshots we plan to rename and look for ones that are zoned.
#
# We'll ignore any snapshot clones that may be in use but are
# not zoned. If these clones are in-use, the rename will fail
# and we'll abort, there's not much else we can do about it.
# But if they are not in use the snapshot rename will unmount
# and remount the clone. This is ok because when the zoned
# attribute is off, we know that the clone was originally
# mounted from the global zone. (So unmounting and remounting
# it from the global zone is ok.)
#
# But we'll abort this whole operation if we find any clones
# that that are zoned and in use. (This can happen if another
# zone has been cloned from this one and is now booted.) The
# reason we do this is because those zoned filesystems could
# have originally mounted from within the zone. So if we
# cleared the zone attribute and did the rename, we'd be
# remounting the filesystem from the global zone. This would
# result in the zone losing the ability to unmount the
# filesystem, which would be bad.
#
unset zoned_clones zoned_iu_clones
(( zoned_clones_c = 0 ))
(( zoned_iu_clones_c = 0 ))
(( j = 0 ))
# walk through all the clones
while (( $j < $clones_c )); do
# walk through all the origin snapshots
(( k = 0 ))
while (( $k < $s_origin_c )); do
#
# check if this clone originated from a snapshot that
# we need to rename.
#
[[ "${clones_origin[$j]}" == "${s_origin[$k]}" ]] &&
[[ "${s_origin_snap[$k]}" != "${s_rename[$k]}" ]] &&
break
(( k = $k + 1 ))
continue
done
if (( $k == $s_origin_c )); then
# This isn't a clone of a snapshot we want to rename.
(( j = $j + 1 ))
continue;
fi
# get the zoned attr for this clone.
zoned=`LC_ALL=C LANG=C \
/sbin/zfs get -H -o value zoned ${clones[$j]}`
if [[ "$zoned" != on ]]; then
# This clone isn't zoned so ignore it.
(( j = $j + 1 ))
continue
fi
# remember this clone so we can muck with it's zoned attr.
zoned_clones[$zoned_clones_c]=${clones[$j]}
(( zoned_clones_c = $zoned_clones_c + 1 ))
# check if it's in use
mounted=`LC_ALL=C LANG=C \
/sbin/zfs get -H -o value mounted ${clones[$j]}`
if [[ "$mounted" != yes ]]; then
# Good news. This clone isn't in use.
(( j = $j + 1 ))
continue
fi
# Sigh. This clone is in use so we're destined to fail.
zoned_iu_clones[$zoned_iu_clones_c]=${clones[$j]}
(( zoned_iu_clones_c = $zoned_iu_clones_c + 1 ))
# keep looking for errors so we can report them all at once.
(( j = $j + 1 ))
done
if (( zoned_iu_clones_c > 0 )); then
#
# Tell the admin
#
printf "$f_iu_clone\n" >&2
print_array zoned_iu_clones >&2
printf "$f_dis_clone\n" >&2
exit $ZONE_SUBPROC_FATAL
fi
#
# Ok. So we're finally done with planning and we can do some
# damage. We're going to:
# - destroy unused snapshots
# - unzone clones which originate from snapshots we need to rename
# - rename conflicting snapshots
# - rezone any clones which we unzoned
# - promote the oldest clone of the youngest snapshot
# - finally destroy the origin filesystem.
#
# delete any unsed snapshot
(( j = 0 ))
while (( $j < $s_delete_c )); do
zfs_destroy "${s_delete[$j]}"
(( j = $j + 1 ))
done
# unzone clones
zfs_set_array zoned off zoned_clones ||
zfs_set_array zoned on zoned_clones 1
# rename conflicting snapshots
(( j = 0 ))
while (( $j < $s_origin_c )); do
if [[ "${s_origin_snap[$j]}" != "${s_rename[$j]}" ]]; then
zfs_rename "${s_origin[$j]}" "$fs@${s_rename[$j]}"
if [[ $? != 0 ]]; then
# re-zone the clones before aborting
zfs_set_array zoned on zoned_clones 1
exit $ZONE_SUBPROC_FATAL
fi
fi
(( j = $j + 1 ))
done
# re-zone the clones
zfs_set_array zoned on zoned_clones 1
# promote the youngest clone of the oldest snapshot
zfs_promote "$s_clone"
# destroy the origin filesystem and it's descendants
zfs_destroy "$fs"
}
#
# This function expects an array named fs_all to exist which is initialized
# with the zone's ZFS datasets that should be destroyed. fs_all_c is the
# count of the number of elements in the array. ZONEPATH_RDS is the
# zonepath/root dataset and ZONEPATH_DS is the zonepath dataset.
#
destroy_zone_datasets()
{
# Destroy the zone BEs datasets one by one.
(( i = 0 ))
while (( $i < $fs_all_c )); do
fs=${fs_all[$i]}
destroy_zone_dataset "$fs"
(( i = $i + 1 ))
done
#
# Check if there are any other datasets left. There may be datasets
# associated with other GZ BEs, so we need to leave things alone in
# that case.
#
c=`/sbin/zfs list -H -t filesystem -r $ZONEPATH_RDS | wc -l`
if [ $c = 1 ]; then
zfs_destroy "$ZONEPATH_RDS"
fi
c=`/sbin/zfs list -H -t filesystem -r $ZONEPATH_DS | wc -l`
if [ $c = 1 ]; then
zfs_destroy "$ZONEPATH_DS"
fi
rm_zonepath
}
#
# 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.
#
default: all
include Makefile.sn1
# Build everything in parallel; use .WAIT for dependencies
.PARALLEL:
SUBDIRS = librtld_db sn1_brand zone
MSGSUBDIRS = zone
all : TARGET= all
install : TARGET= install
clean : TARGET= clean
clobber : TARGET= clobber
_msg : TARGET= _msg
.KEEP_STATE:
all install clean clobber: $(SUBDIRS)
_msg: $(MSGSUBDIRS)
$(SUBDIRS): FRC
@cd $@; pwd; $(MAKE) $(TARGET)
FRC:
#
# 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.
#
# lib/brand/sn1/Makefile.sn1
#
# include global definitions
BRAND = sn1
include $(SRC)/lib/brand/Makefile.brand
#
# 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.
#
default: all
include $(SRC)/lib/Makefile.lib
# Hammerhead: amd64-only
SUBDIRS = $(MACH64)
all : TARGET= all
clean : TARGET= clean
clobber : TARGET= clobber
install : TARGET= install
.KEEP_STATE:
all install clean clobber: $(SUBDIRS)
$(SUBDIRS): FRC
@cd $@; pwd; $(MAKE) $(TARGET)
FRC:
#
# 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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
#
COBJS = brand_librtld_db.o
OBJECTS = $(COBJS) $(COBJS64)
include ../../Makefile.sn1
include $(BRAND_SHARED)/librtld_db/Makefile.com
#
# 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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
#
COBJS64 = brand_librtld_db64.o
include ../Makefile.com
include $(SRC)/lib/Makefile.lib.64
CLOBBERFILES = $(ROOTLIBDIR64)/$(DYNLIB)
install: all $(ROOTLIBS64)
#
# 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 $(SRC)/lib/Makefile.lib
default: all
# Hammerhead: amd64-only
SUBDIRS = $(MACH64)
all : TARGET= all
clean : TARGET= clean
clobber : TARGET= clobber
install : TARGET= install
_msg : TARGET= _msg
.KEEP_STATE:
all install clean clobber _msg: $(SUBDIRS)
$(SUBDIRS): FRC
@cd $@; pwd; $(MAKE) $(TARGET)
FRC:
#
# 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 2020 Joyent, Inc.
#
LIBRARY = sn1_brand.a
VERS = .1
COBJS = sn1_brand.o
ASOBJS = crt.o handler.o runexe.o brand_util.o
OBJECTS = $(COBJS)
include ../../Makefile.sn1
include $(SRC)/lib/Makefile.lib
SRCDIR = ../common
UTSBASE = $(SRC)/uts
LIBS = $(DYNLIB)
CSRCS = $(COBJS:%o=../common/%c)
SHAREDOBJS = $(ASOBJS:%o=$(ISAOBJDIR)/%o)
SRCS = $(CSRCS)
#
# Note that the architecture specific makefiles MUST update DYNFLAGS to
# explicily specify an interpreter for the brand emulation library.
# Normally this would be the native linker, /.SUNWnative/usr/lib/ld.so.1
# or /.SUNWnative/usr/lib/64/ld.so.1.
#
# Note that we make sure to link our brand emulation library
# libmapmalloc. This is required because in most cases there will be two
# copies of libc in the same process and we don't want them to fight over
# the heap. So for our brand library we link against libmapmalloc so that
# if we (our or copy of libc) try to allocate any memory it will be done
# via mmap() instead of brk().
#
# XXX: Note that we also set the runtime path for the emulation library to
# point into /.SUNWnative/. This ensures that our brand library get's the
# native versions of any libraries it needs. Unfortunatly this is a total
# hack since it doesn't work for suid binaries. What we really need to do
# is enhance the linker so that when it's running on a brand linkmap it
# looks for all libraries in the brands "native" directory (for both
# regular and suid binaries).
#
NATIVE_DIR = /.SUNWnative
CPPFLAGS += -D_REENTRANT -U_ASM \
-I. -I$(BRAND_SHARED)/brand/sys -I$(UTSBASE)/common/brand/sn1
CFLAGS += $(CCVERBOSE)
DYNFLAGS += $(DYNFLAGS_$(CLASS))
DYNFLAGS += $(BLOCAL) $(ZNOVERSION) -Wl,-e_start
#DYNFLAGS += -R$(NATIVE_DIR)/lib -R$(NATIVE_DIR)/usr/lib
LDLIBS += -lmapmalloc -lc
ZGUIDANCE = -Wl,-zguidance=nounused
$(LIBS): PICS += $(SHAREDOBJS)
.KEEP_STATE:
all: $(LIBS)
include $(SRC)/lib/Makefile.targ
#
# 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.
#
# lib/brand/sn1/amd64/Makefile
ISAOBJDIR = $(BRAND_SHARED)/brand/amd64/pics/
include ../Makefile.com
include $(SRC)/lib/Makefile.lib.64
CPPFLAGS += -I$(BRAND_SHARED)/brand/amd64
#
# see ../Makefile.com for why we MUST explicity make ld.so.1 our interpreter
#
DYNFLAGS += -Wl,-I$(NATIVE_DIR)/usr/lib/64/ld.so.1
CPPFLAGS += -D_SYSCALL32
CLEANFILES += $(DYNLIB)
CLOBBERFILES += $(ROOTLIBS64)
install: all $(ROOTLIBS64)
#
# 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.
#
#
# MAPFILE HEADER START
#
# WARNING: STOP NOW. DO NOT MODIFY THIS FILE.
# Object versioning must comply with the rules detailed in
#
# usr/src/lib/README.mapfiles
#
# You should not be making modifications here until you've read the most current
# copy of that file. If you need help, contact a gatekeeper for guidance.
#
# MAPFILE HEADER END
#
$mapfile_version 2
#
# Scope everything local -- our .init section is our only public interface.
#
SYMBOL_SCOPE {
local:
*;
};
/*
* 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.
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <sys/auxv.h>
#include <sys/bitmap.h>
#include <sys/brand.h>
#include <sys/inttypes.h>
#include <sys/lwp.h>
#include <sys/syscall.h>
#include <sys/systm.h>
#include <sys/utsname.h>
#include <fcntl.h>
#include <sn1_brand.h>
#include <brand_misc.h>
/*
* See usr/src/lib/brand/shared/brand/common/brand_util.c for general
* emulation notes.
*
* *** sn1 brand emulation scope considerations
*
* Given that the sn1 brand exists for testing purposes, it should
* eventually be enhanced to redirect all system calls through the
* brand emulation library. This will ensure the maximum testing
* exposure for the brandz infrastructure. Some other options to
* consider for improving brandz test exposure are:
* - Folding the sn1 brand into the native brand and only enabling
* it on DEBUG builds.
* - Modifying the zones test suite to use sn1 branded zones by default,
* and adapting functional test harnesses to use sn1 branded zones
* by default instead of native zones.
*/
static long
sn1_uname(sysret_t *rv, uintptr_t p1)
{
struct utsname un, *unp = (struct utsname *)p1;
int rev, err;
if ((err = __systemcall(rv, SYS_uname + 1024, &un)) != 0)
return (err);
rev = atoi(&un.release[2]);
brand_assert(rev >= 10);
(void) sprintf(un.release, "5.%d", rev - 1);
if (uucopy(&un, unp, sizeof (un)) != 0)
return (EFAULT);
return (0);
}
/*ARGSUSED*/
int
brand_init(int argc, char *argv[], char *envp[])
{
ulong_t ldentry;
brand_pre_init();
ldentry = brand_post_init(SN1_VERSION, argc, argv, envp);
brand_runexe(argv, ldentry);
/*NOTREACHED*/
brand_abort(0, "brand_runexe() returned");
return (-1);
}
#define IN_KERNEL_SYSCALL(name, num) \
static long \
sn1_##name(sysret_t *rv, \
uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_t a3, \
uintptr_t a4, uintptr_t a5, uintptr_t a6, uintptr_t a7) \
{ \
return (__systemcall(rv, num + 1024, \
a0, a1, a2, a3, a4, a5, a6, a7)); \
}
/*
* These are branded system calls, which have been redirected to this
* userland emulation library, and are emulated by passing them strait
* on to the kernel as native system calls.
*/
IN_KERNEL_SYSCALL(read, SYS_read) /* 3 */
IN_KERNEL_SYSCALL(write, SYS_write) /* 4 */
IN_KERNEL_SYSCALL(time, SYS_time) /* 13 */
IN_KERNEL_SYSCALL(getpid, SYS_getpid) /* 20 */
IN_KERNEL_SYSCALL(mount, SYS_mount) /* 21 */
IN_KERNEL_SYSCALL(getuid, SYS_getuid) /* 24 */
IN_KERNEL_SYSCALL(times, SYS_times) /* 43 */
IN_KERNEL_SYSCALL(getgid, SYS_getgid) /* 47 */
IN_KERNEL_SYSCALL(utssys, SYS_utssys) /* 57 */
IN_KERNEL_SYSCALL(waitid, SYS_waitid) /* 107 */
/*
* This table must have at least NSYSCALL entries in it.
*
* The second parameter of each entry in the brand_sysent_table
* contains the number of parameters and flags that describe the
* syscall return value encoding. See the block comments at the
* top of this file for more information about the syscall return
* value flags and when they should be used.
*/
brand_sysent_table_t brand_sysent_table[] = {
#if defined(__sparc) && !defined(__sparcv9)
EMULATE(brand_indir, 9 | RV_64RVAL), /* 0 */
#else /* !__sparc || __sparcv9 */
NOSYS, /* 0 */
#endif /* !__sparc || __sparcv9 */
NOSYS, /* 1 */
NOSYS, /* 2 */
EMULATE(sn1_read, 3 | RV_DEFAULT), /* 3 */
EMULATE(sn1_write, 3 | RV_DEFAULT), /* 4 */
NOSYS, /* 5 */
NOSYS, /* 6 */
NOSYS, /* 7 */
NOSYS, /* 8 */
NOSYS, /* 9 */
NOSYS, /* 10 */
NOSYS, /* 11 */
NOSYS, /* 12 */
EMULATE(sn1_time, 0 | RV_DEFAULT), /* 13 */
NOSYS, /* 14 */
NOSYS, /* 15 */
NOSYS, /* 16 */
NOSYS, /* 17 */
NOSYS, /* 18 */
NOSYS, /* 19 */
EMULATE(sn1_getpid, 0 | RV_32RVAL2), /* 20 */
EMULATE(sn1_mount, 8 | RV_DEFAULT), /* 21 */
NOSYS, /* 22 */
NOSYS, /* 23 */
EMULATE(sn1_getuid, 0 | RV_32RVAL2), /* 24 */
NOSYS, /* 25 */
NOSYS, /* 26 */
NOSYS, /* 27 */
NOSYS, /* 28 */
NOSYS, /* 29 */
NOSYS, /* 30 */
NOSYS, /* 31 */
NOSYS, /* 32 */
NOSYS, /* 33 */
NOSYS, /* 34 */
NOSYS, /* 35 */
NOSYS, /* 36 */
NOSYS, /* 37 */
NOSYS, /* 38 */
NOSYS, /* 39 */
NOSYS, /* 40 */
NOSYS, /* 41 */
NOSYS, /* 42 */
EMULATE(sn1_times, 1 | RV_DEFAULT), /* 43 */
NOSYS, /* 44 */
NOSYS, /* 45 */
NOSYS, /* 46 */
EMULATE(sn1_getgid, 0 | RV_32RVAL2), /* 47 */
NOSYS, /* 48 */
NOSYS, /* 49 */
NOSYS, /* 50 */
NOSYS, /* 51 */
NOSYS, /* 52 */
NOSYS, /* 53 */
NOSYS, /* 54 */
NOSYS, /* 55 */
NOSYS, /* 56 */
EMULATE(sn1_utssys, 4 | RV_32RVAL2), /* 57 */
NOSYS, /* 58 */
NOSYS, /* 59 */
NOSYS, /* 60 */
NOSYS, /* 61 */
NOSYS, /* 62 */
NOSYS, /* 63 */
NOSYS, /* 64 */
NOSYS, /* 65 */
NOSYS, /* 66 */
NOSYS, /* 67 */
NOSYS, /* 68 */
NOSYS, /* 69 */
NOSYS, /* 70 */
NOSYS, /* 71 */
NOSYS, /* 72 */
NOSYS, /* 73 */
NOSYS, /* 74 */
NOSYS, /* 75 */
NOSYS, /* 76 */
NOSYS, /* 77 */
NOSYS, /* 78 */
NOSYS, /* 79 */
NOSYS, /* 80 */
NOSYS, /* 81 */
NOSYS, /* 82 */
NOSYS, /* 83 */
NOSYS, /* 84 */
NOSYS, /* 85 */
NOSYS, /* 86 */
NOSYS, /* 87 */
NOSYS, /* 88 */
NOSYS, /* 89 */
NOSYS, /* 90 */
NOSYS, /* 91 */
NOSYS, /* 92 */
NOSYS, /* 93 */
NOSYS, /* 94 */
NOSYS, /* 95 */
NOSYS, /* 96 */
NOSYS, /* 97 */
NOSYS, /* 98 */
NOSYS, /* 99 */
NOSYS, /* 100 */
NOSYS, /* 101 */
NOSYS, /* 102 */
NOSYS, /* 103 */
NOSYS, /* 104 */
NOSYS, /* 105 */
NOSYS, /* 106 */
EMULATE(sn1_waitid, 4 | RV_DEFAULT), /* 107 */
NOSYS, /* 108 */
NOSYS, /* 109 */
NOSYS, /* 110 */
NOSYS, /* 111 */
NOSYS, /* 112 */
NOSYS, /* 113 */
NOSYS, /* 114 */
NOSYS, /* 115 */
NOSYS, /* 116 */
NOSYS, /* 117 */
NOSYS, /* 118 */
NOSYS, /* 119 */
NOSYS, /* 120 */
NOSYS, /* 121 */
NOSYS, /* 122 */
NOSYS, /* 123 */
NOSYS, /* 124 */
NOSYS, /* 125 */
NOSYS, /* 126 */
NOSYS, /* 127 */
NOSYS, /* 128 */
NOSYS, /* 129 */
NOSYS, /* 130 */
NOSYS, /* 131 */
NOSYS, /* 132 */
NOSYS, /* 133 */
NOSYS, /* 134 */
EMULATE(sn1_uname, 1 | RV_DEFAULT), /* 135 */
NOSYS, /* 136 */
NOSYS, /* 137 */
NOSYS, /* 138 */
NOSYS, /* 139 */
NOSYS, /* 140 */
NOSYS, /* 141 */
NOSYS, /* 142 */
NOSYS, /* 143 */
NOSYS, /* 144 */
NOSYS, /* 145 */
NOSYS, /* 146 */
NOSYS, /* 147 */
NOSYS, /* 148 */
NOSYS, /* 149 */
NOSYS, /* 150 */
NOSYS, /* 151 */
NOSYS, /* 152 */
NOSYS, /* 153 */
NOSYS, /* 154 */
NOSYS, /* 155 */
NOSYS, /* 156 */
NOSYS, /* 157 */
NOSYS, /* 158 */
NOSYS, /* 159 */
NOSYS, /* 160 */
NOSYS, /* 161 */
NOSYS, /* 162 */
NOSYS, /* 163 */
NOSYS, /* 164 */
NOSYS, /* 165 */
NOSYS, /* 166 */
NOSYS, /* 167 */
NOSYS, /* 168 */
NOSYS, /* 169 */
NOSYS, /* 170 */
NOSYS, /* 171 */
NOSYS, /* 172 */
NOSYS, /* 173 */
NOSYS, /* 174 */
NOSYS, /* 175 */
NOSYS, /* 176 */
NOSYS, /* 177 */
NOSYS, /* 178 */
NOSYS, /* 179 */
NOSYS, /* 180 */
NOSYS, /* 181 */
NOSYS, /* 182 */
NOSYS, /* 183 */
NOSYS, /* 184 */
NOSYS, /* 185 */
NOSYS, /* 186 */
NOSYS, /* 187 */
NOSYS, /* 188 */
NOSYS, /* 189 */
NOSYS, /* 190 */
NOSYS, /* 191 */
NOSYS, /* 192 */
NOSYS, /* 193 */
NOSYS, /* 194 */
NOSYS, /* 195 */
NOSYS, /* 196 */
NOSYS, /* 197 */
NOSYS, /* 198 */
NOSYS, /* 199 */
NOSYS, /* 200 */
NOSYS, /* 201 */
NOSYS, /* 202 */
NOSYS, /* 203 */
NOSYS, /* 204 */
NOSYS, /* 205 */
NOSYS, /* 206 */
NOSYS, /* 207 */
NOSYS, /* 208 */
NOSYS, /* 209 */
NOSYS, /* 210 */
NOSYS, /* 211 */
NOSYS, /* 212 */
NOSYS, /* 213 */
NOSYS, /* 214 */
NOSYS, /* 215 */
NOSYS, /* 216 */
NOSYS, /* 217 */
NOSYS, /* 218 */
NOSYS, /* 219 */
NOSYS, /* 220 */
NOSYS, /* 221 */
NOSYS, /* 222 */
NOSYS, /* 223 */
NOSYS, /* 224 */
NOSYS, /* 225 */
NOSYS, /* 226 */
NOSYS, /* 227 */
NOSYS, /* 228 */
NOSYS, /* 229 */
NOSYS, /* 230 */
NOSYS, /* 231 */
NOSYS, /* 232 */
NOSYS, /* 233 */
NOSYS, /* 234 */
NOSYS, /* 235 */
NOSYS, /* 236 */
NOSYS, /* 237 */
NOSYS, /* 238 */
NOSYS, /* 239 */
NOSYS, /* 240 */
NOSYS, /* 241 */
NOSYS, /* 242 */
NOSYS, /* 243 */
NOSYS, /* 244 */
NOSYS, /* 245 */
NOSYS, /* 246 */
NOSYS, /* 247 */
NOSYS, /* 248 */
NOSYS, /* 249 */
NOSYS, /* 250 */
NOSYS, /* 251 */
NOSYS, /* 252 */
NOSYS, /* 253 */
NOSYS, /* 254 */
NOSYS /* 255 */
};
#
# 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.
#
BRAND= sn1
PROGS= sn1_boot
XMLDOCS= config.xml platform.xml
TEMPLATES= SUNWsn1.xml
CLOBBERFILES= $(PROGS)
all: $(PROGS)
include $(SRC)/cmd/Makefile.cmd
include ../../Makefile.brand
POFILES= $(PROGS:%=%.po)
POFILE= sn1_zone.po
$(POFILE): $(POFILES)
$(RM) $@
$(CAT) $(POFILES) > $@
clean:
-$(RM) $(PROGS) $(POFILES) $(POFILE)
install: $(PROGS) $(ROOTPROGS) $(ROOTXMLDOCS) $(ROOTTEMPLATES)
include $(SRC)/cmd/Makefile.targ
<?xml version="1.0"?>
<!--
Copyright 2010 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
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
DO NOT EDIT THIS FILE. Use zonecfg(8) instead.
-->
<!DOCTYPE zone PUBLIC "-//Sun Microsystems Inc//DTD Zones//EN" "file:///usr/share/lib/xml/dtd/zonecfg.dtd.1">
<zone name="default" zonepath="" autoboot="false" brand="sn1">
</zone>
<?xml version="1.0"?>
<!--
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.
DO NOT EDIT THIS FILE.
-->
<!DOCTYPE brand PUBLIC "-//Sun Microsystems Inc//DTD Brands//EN"
"file:///usr/share/lib/xml/dtd/brand.dtd.1">
<brand name="sn1">
<modname>sn1_brand</modname>
<initname>/sbin/init</initname>
<login_cmd>/usr/bin/login -z %Z %u</login_cmd>
<forcedlogin_cmd>/usr/bin/login -z %Z -f %u</forcedlogin_cmd>
<user_cmd>/usr/bin/getent passwd %u</user_cmd>
<install>/usr/lib/brand/ipkg/pkgcreatezone -z %z -R %R</install>
<boot>/usr/lib/brand/sn1/sn1_boot %R</boot>
<sysboot>/usr/lib/brand/ipkg/prestate %z %R 2 0</sysboot>
<verify_cfg></verify_cfg>
<verify_adm></verify_adm>
<attach>/usr/lib/brand/ipkg/attach %z %R</attach>
<detach>/usr/lib/brand/ipkg/detach -z %z -R %R</detach>
<clone>/usr/lib/brand/ipkg/clone -z %z -R %R</clone>
<uninstall>/usr/lib/brand/ipkg/uninstall %z %R</uninstall>
<prestatechange>/usr/lib/brand/ipkg/prestate %z %R</prestatechange>
<poststatechange>/usr/lib/brand/ipkg/poststate %z %R</poststatechange>
<query>/usr/lib/brand/shared/query %z %R</query>
<privilege set="default" name="contract_event" />
<privilege set="default" name="contract_identity" />
<privilege set="default" name="contract_observer" />
<privilege set="default" name="file_chown" />
<privilege set="default" name="file_chown_self" />
<privilege set="default" name="file_dac_execute" />
<privilege set="default" name="file_dac_read" />
<privilege set="default" name="file_dac_search" />
<privilege set="default" name="file_dac_write" />
<privilege set="default" name="file_owner" />
<privilege set="default" name="file_setid" />
<privilege set="default" name="ipc_dac_read" />
<privilege set="default" name="ipc_dac_write" />
<privilege set="default" name="ipc_owner" />
<privilege set="default" name="net_bindmlp" />
<privilege set="default" name="net_icmpaccess" />
<privilege set="default" name="net_mac_aware" />
<privilege set="default" name="net_observability" />
<privilege set="default" name="net_privaddr" />
<privilege set="default" name="net_rawaccess" ip-type="exclusive" />
<privilege set="default" name="proc_chroot" />
<privilege set="default" name="sys_audit" />
<privilege set="default" name="proc_audit" />
<privilege set="default" name="proc_lock_memory" />
<privilege set="default" name="proc_owner" />
<privilege set="default" name="proc_secflags" />
<privilege set="default" name="proc_setid" />
<privilege set="default" name="proc_taskid" />
<privilege set="default" name="sys_acct" />
<privilege set="default" name="sys_admin" />
<privilege set="default" name="sys_ip_config" ip-type="exclusive" />
<privilege set="default" name="sys_iptun_config" ip-type="exclusive" />
<privilege set="default" name="sys_mount" />
<privilege set="default" name="sys_nfs" />
<privilege set="default" name="sys_resource" />
<privilege set="default" name="sys_ppp_config" ip-type="exclusive" />
<privilege set="prohibited" name="dtrace_kernel" />
<privilege set="prohibited" name="proc_zone" />
<privilege set="prohibited" name="sys_config" />
<privilege set="prohibited" name="sys_devices" />
<privilege set="prohibited" name="sys_ip_config" ip-type="shared" />
<privilege set="prohibited" name="sys_linkdir" />
<privilege set="prohibited" name="sys_net_config" />
<privilege set="prohibited" name="sys_res_config" />
<privilege set="prohibited" name="sys_suser_compat" />
<privilege set="prohibited" name="xvm_control" />
<privilege set="prohibited" name="virt_manage" />
<privilege set="prohibited" name="sys_ppp_config" ip-type="shared" />
<privilege set="required" name="proc_exec" />
<privilege set="required" name="proc_fork" />
<privilege set="required" name="sys_ip_config" ip-type="exclusive" />
<privilege set="required" name="sys_mount" />
</brand>
<?xml version="1.0"?>
<!--
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.
DO NOT EDIT THIS FILE.
-->
<!DOCTYPE platform PUBLIC "-//Sun Microsystems Inc//Zones Platform//EN"
"file:///usr/share/lib/xml/dtd/zone_platform.dtd.1">
<platform name="native" allow-exclusive-ip="true">
<!-- Global filesystems to mount when booting the zone -->
<global_mount special="/dev" directory="/dev" type="dev"
opt="attrdir=%R/dev"/>
<global_mount special="/usr" directory="/.SUNWnative/usr"
opt="ro,nodevices" type="lofs" />
<global_mount special="/lib" directory="/.SUNWnative/lib"
opt="ro,nodevices" type="lofs" />
<!-- Local filesystems to mount when booting the zone -->
<mount special="/proc" directory="/proc" type="proc" />
<mount special="ctfs" directory="/system/contract" type="ctfs" />
<mount special="mnttab" directory="/etc/mnttab" type="mntfs" />
<mount special="objfs" directory="/system/object" type="objfs" />
<mount special="swap" directory="/etc/svc/volatile" type="tmpfs" />
<!-- Devices to create under /dev -->
<device match="arp" />
<device match="bpf" />
<device match="conslog" />
<device match="cpu/self/cpuid" />
<device match="crypto" />
<device match="cryptoadm" />
<device match="dsk" />
<device match="dtrace/*" />
<device match="dtrace/provider/*" />
<device match="eventfd" />
<device match="fd" />
<device match="full" />
<device match="ipnet" />
<device match="kstat" />
<device match="lo0" />
<device match="lofictl" />
<device match="lofi" />
<device match="log" />
<device match="logindmux" />
<device match="nsmb" />
<device match="net/*" />
<device match="null" />
<device match="openprom" arch="sparc" />
<device match="poll" />
<device match="pool" />
<device match="ptmx" />
<device match="pts/*" />
<device match="random" />
<device match="rdsk" />
<device match="rlofi" />
<device match="rmt" />
<device match="sad/user" />
<device match="svvslo0" />
<device match="svvslo1" />
<device match="svvslo2" />
<device match="svvslo3" />
<device match="swap" />
<device match="sysevent" />
<device match="tcp" />
<device match="tcp6" />
<device match="term" />
<device match="ticlts" />
<device match="ticots" />
<device match="ticotsord" />
<device match="tty" />
<device match="udp" />
<device match="udp6" />
<device match="urandom" />
<device match="zero" />
<device match="zfs" />
<!-- Devices to create in exclusive IP zone only -->
<device match="dld" ip-type="exclusive" />
<device match="icmp" ip-type="exclusive" />
<device match="icmp6" ip-type="exclusive" />
<device match="ip" ip-type="exclusive" />
<device match="ip6" ip-type="exclusive" />
<device match="ipauth" ip-type="exclusive" />
<device match="ipf" ip-type="exclusive" />
<device match="ipl" ip-type="exclusive" />
<device match="iplookup" ip-type="exclusive" />
<device match="ipmpstub" ip-type="exclusive" />
<device match="ipnat" ip-type="exclusive" />
<device match="ipscan" ip-type="exclusive" />
<device match="ipsecah" ip-type="exclusive" />
<device match="ipsecesp" ip-type="exclusive" />
<device match="ipstate" ip-type="exclusive" />
<device match="ipsync" ip-type="exclusive" />
<device match="iptunq" ip-type="exclusive" />
<device match="keysock" ip-type="exclusive" />
<device match="rawip" ip-type="exclusive" />
<device match="rawip6" ip-type="exclusive" />
<device match="rts" ip-type="exclusive" />
<device match="sad/admin" ip-type="exclusive" />
<device match="sctp" ip-type="exclusive" />
<device match="sctp6" ip-type="exclusive" />
<device match="spdsock" ip-type="exclusive" />
<device match="sppp" ip-type="exclusive" />
<device match="sppptun" ip-type="exclusive" />
<!-- Renamed devices to create under /dev -->
<device match="zcons/%z/zoneconsole" name="zconsole" />
<!-- Symlinks to create under /dev -->
<symlink source="console" target="zconsole" />
<symlink source="dtremote" target="/dev/null" />
<symlink source="msglog" target="zconsole" />
<symlink source="stderr" target="./fd/2" />
<symlink source="stdin" target="./fd/0" />
<symlink source="stdout" target="./fd/1" />
<symlink source="syscon" target="zconsole" />
<symlink source="sysmsg" target="zconsole" />
<symlink source="systty" target="zconsole" />
</platform>
#!/bin/ksh -p
#
# 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.
#
# sn1 boot script.
#
# The argument to this script is the root of the zone.
#
PATH=/bin:/sbin:/usr/bin:/usr/sbin; export PATH
ZONEROOT=$1
if [ `uname -p` = "amd64" ] || [ `uname -p` = "i386" ]; then
ARCH64=amd64
elif [ `uname -p` = "sparc" ]; then
ARCH64=sparcv9
else
echo "Unsupported architecture: " `uname -p` >&2
exit 2
fi
exit 0
#
# 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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
default: all
include Makefile.s10
# Build everything in parallel; use .WAIT for dependencies
.PARALLEL:
SUBDIRS = librtld_db s10_npreload s10_brand s10_support s10_replacefile \
zone cmd
MSGSUBDIRS = s10_support zone
all : TARGET= all
install : TARGET= install
clean : TARGET= clean
clobber : TARGET= clobber
_msg : TARGET= _msg
.KEEP_STATE:
all install clean clobber: $(SUBDIRS)
_msg: $(MSGSUBDIRS)
$(SUBDIRS): FRC
@cd $@; pwd; $(MAKE) $(TARGET)
FRC:
#
# 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 global definitions
BRAND = solaris10
include $(SRC)/lib/brand/Makefile.brand
#
# 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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
PROGS = s10_native s10_isaexec_wrapper \
s10_net_physical
include $(SRC)/cmd/Makefile.cmd
include ../Makefile.s10
# override the install directory
ROOTBIN = $(ROOTBRANDDIR)
CLOBBERFILES = $(ROOTPROGS)
.KEEP_STATE:
all: $(PROGS)
install: all $(ROOTPROGS)
clean:
$(RM) $(PROGS) $(CLEANFILES)
include $(SRC)/cmd/Makefile.targ
#!/bin/sh
#
# 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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
#
# This script is invoked by isaexec-governed executable wrappers from within
# s10-branded zones. It circumvents the native isaexec so that native wrappers
# will function correctly.
#
# All native executables must be run using the native linker.
# By default, the kernel loads the linker at /lib/ld.so.1, which
# in an s10 zone is the s10 linker. Hence when we run the native
# executable below, we explicitly specify /.SUNWnative/lib/ld.so.1 as our 32-
# bit linker and /.SUNWnative/lib/64/ld.so.1 as our 64-bit linker.
# For convience we define "n" to be the native path prefix.
# The initial s10_native argument is used as a way to tell the brand
# emulation that it needs to set up the process to run as an unbranded
# process.
#
# If this script gets setup with a mode that makes it suid, then things won't
# work because the script will be running with the incorrect name.
#
n=/.SUNWnative
bname=`/bin/basename $0`
dname=`/bin/dirname $0`
echo $dname | /bin/grep "^/" >/dev/null || dname=`/bin/pwd`/$dname
dname=`(cd $dname 2>/dev/null && /bin/pwd 2>/dev/null)`
arch64=/
LC_ALL=C /usr/bin/file $n/$dname/$bname | /bin/grep "64-bit" \
>/dev/null && arch64=/64/
# This wrapper is running in the S10 zone so there is no L10N for the
# following error msg.
if [ ! -f $n$dname/$bname ]; then
echo "Error: \"$dname/$bname\" is not installed in the global zone"
exit 1
fi
exec $n/usr/lib/brand/solaris10/s10_native \
$n/lib${arch64}ld.so.1 \
-e LD_NOENVIRON=1 \
-e LD_NOCONFIG=1 \
-e LD_PRELOAD_32=s10_npreload.so.1 \
-e LD_PRELOAD_64=s10_npreload.so.1 \
-e LD_LIBRARY_PATH_32="$n/lib:$n/usr/lib:$n/usr/lib/mps" \
-e LD_LIBRARY_PATH_64="$n/lib/64:$n/usr/lib/64:$n/usr/lib/mps/64" \
$n$dname/$bname "$@"
#!/bin/sh
#
# 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.
#
exit 0
#!/sbin/sh
#
# 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) 2010, Oracle and/or its affiliates. All rights reserved.
#
# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
# All rights reserved.
#
# THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
# The copyright notice above does not evidence any
# actual or intended publication of such source code.
#
. /lib/svc/share/smf_include.sh
. /lib/svc/share/net_include.sh
#
# This file replaces the Solaris 10 net-physical script in S10C at
# boot time. Any S10C specific changes to net-physical script needs
# to be made in this file.
#
#
# In a shared-IP zone we need this service to be up, but all of the work
# it tries to do is irrelevant (and will actually lead to the service
# failing if we try to do it), so just bail out.
# In exclusive-IP zones we proceed.
#
if [ `/sbin/zonename -t` = shared ]; then
exit 0
fi
# Print warnings to console
warn_failed_ifs() {
echo "Failed to $1 interface(s): $2" >/dev/msglog
}
#
# Cause ifconfig to not automatically start in.mpathd when IPMP groups are
# configured. This is not strictly necessary but makes it so that in.mpathd
# will always be started explicitly from /etc/init.d/inetinit, when we're
# sure that /usr is mounted.
#
SUNW_NO_MPATHD=; export SUNW_NO_MPATHD
smf_netstrategy
#
# If the system was net booted by DHCP, hand DHCP management off to the
# DHCP agent (ifconfig communicates to the DHCP agent through the
# loopback interface).
#
if [ -n "$_INIT_NET_IF" -a "$_INIT_NET_STRATEGY" = "dhcp" ]; then
/sbin/dhcpagent -a
fi
#
# For IPv4 interfaces that were configured by the kernel and not
# configured by DHCP, reset the netmask using the local "/etc/netmasks"
# file if one exists, and then reset the broadcast address based on
# the netmask.
#
/sbin/ifconfig -auD4 netmask + broadcast +
#
# All the IPv4 and IPv6 interfaces are plumbed before doing any
# interface configuration. This prevents errors from plumb failures
# getting mixed in with the configured interface lists that the script
# outputs.
#
# Moreover in S10C, we process IPMP interfaces before non-IPMP
# interfaces to avoid accidental implicit IPMP group creation.
# Therefore we keep track of IPMP and non-IPMP interfaces in two
# different lists i.e. ipmp[6]_list vs inet[6]_list.
#
# Get the list of IPv4 interfaces to configure by breaking
# /etc/hostname.* into separate args by using "." as a shell separator
# character.
#
interface_names="`echo /etc/hostname.*[0-9] 2>/dev/null`"
if [ "$interface_names" != "/etc/hostname.*[0-9]" ]; then
ORIGIFS="$IFS"
IFS="$IFS."
set -- $interface_names
IFS="$ORIGIFS"
while [ $# -ge 2 ]; do
shift
if [ "$1" = "xx0" ]; then
#
# For some unknown historical reason the xx0
# ifname is ignored.
#
shift
continue
fi
if [ $# -gt 1 -a "$2" != "/etc/hostname" ]; then
while [ $# -gt 1 -a "$1" != "/etc/hostname" ]; do
shift
done
else
read one rest < /etc/hostname.$1
if [ "$one" = ipmp ]; then
ipmp_list="$ipmp_list $1"
else
inet_list="$inet_list $1"
fi
shift
fi
done
fi
#
# Get the list of IPv6 interfaces to configure by breaking
# /etc/hostname6.* into separate args by using "." as a shell separator
# character.
#
interface_names="`echo /etc/hostname6.*[0-9] 2>/dev/null`"
if [ "$interface_names" != "/etc/hostname6.*[0-9]" ]; then
ORIGIFS="$IFS"
IFS="$IFS."
set -- $interface_names
IFS="$ORIGIFS"
while [ $# -ge 2 ]; do
shift
if [ $# -gt 1 -a "$2" != "/etc/hostname6" ]; then
while [ $# -gt 1 -a "$1" != "/etc/hostname6" ]; do
shift
done
else
read one rest < /etc/hostname6.$1
if [ "$one" = ipmp ]; then
ipmp6_list="$ipmp6_list $1"
else
inet6_list="$inet6_list $1"
fi
shift
fi
done
fi
#
# Create all of the IPv4 IPMP interfaces.
#
if [ -n "$ipmp_list" ]; then
set -- $ipmp_list
while [ $# -gt 0 ]; do
if /sbin/ifconfig $1 ipmp; then
ipmp_created="$ipmp_created $1"
else
ipmp_failed="$ipmp_failed $1"
fi
shift
done
[ -n "$ipmp_failed" ] && warn_failed_ifs "create IPv4 IPMP" \
"$ipmp_failed"
fi
#
# Step through the IPv4 interface list and try to plumb every interface.
# Generate list of plumbed and failed IPv4 interfaces.
#
if [ -n "$inet_list" ]; then
set -- $inet_list
while [ $# -gt 0 ]; do
/sbin/ifconfig $1 plumb
if /sbin/ifconfig $1 inet >/dev/null 2>&1; then
inet_plumbed="$inet_plumbed $1"
else
inet_failed="$inet_failed $1"
fi
shift
done
[ -n "$inet_failed" ] && warn_failed_ifs "plumb IPv4" $inet_failed
fi
#
# Step through the IPv6 interface list and plumb every interface.
# Generate list of plumbed and failed IPv6 interfaces. Each plumbed
# interface will be brought up later, after processing any contents of
# the /etc/hostname6.* file.
#
if [ -n "$inet6_list" ]; then
set -- $inet6_list
while [ $# -gt 0 ]; do
/sbin/ifconfig $1 inet6 plumb
if /sbin/ifconfig $1 inet6 >/dev/null 2>&1; then
inet6_plumbed="$inet6_plumbed $1"
else
inet6_failed="$inet6_failed $1"
fi
shift
done
[ -n "$inet6_failed" ] && warn_failed_ifs "plumb IPv6" $inet6_failed
fi
#
# Create all of the IPv6 IPMP interfaces.
#
if [ -n "$ipmp6_list" ]; then
set -- $ipmp6_list
while [ $# -gt 0 ]; do
if /sbin/ifconfig $1 inet6 ipmp; then
ipmp6_created="$ipmp6_created $1"
else
ipmp6_failed="$ipmp6_failed $1"
fi
shift
done
[ -n "$ipmp6_failed" ] && warn_failed_ifs "create IPv6 IPMP" \
"$ipmp6_failed"
fi
#
# Process IPMP interfaces before non-IPMP interfaces
# to avoid accidental implicit IPMP group creation.
#
if [ -n "$ipmp_created" ]; then
i4s_fail=
echo "configuring IPv4 IPMP interfaces:\c"
set -- $ipmp_created
while [ $# -gt 0 ]; do
inet_process_hostname /sbin/ifconfig $1 inet \
</etc/hostname.$1 >/dev/null
[ $? != 0 ] && i4s_fail="$i4s_fail $1"
echo " $1\c"
shift
done
echo "."
[ -n "$i4s_fail" ] && warn_failed_ifs "configure IPv4 IPMP" \
$i4s_fail
fi
if [ -n "$ipmp6_created" ]; then
i6_fail=
echo "configuring IPv6 IPMP interfaces:\c"
set -- $ipmp6_created
while [ $# -gt 0 ]; do
inet6_process_hostname /sbin/ifconfig $1 inet6 \
</etc/hostname6.$1 >/dev/null &&
/sbin/ifconfig $1 inet6 up
[ $? != 0 ] && i6_fail="$i6_fail $1"
echo " $1\c"
shift
done
echo "."
[ -n "$i6_fail" ] && warn_failed_ifs "configure IPv6 IPMP" \
$i6_fail
fi
#
# Process the /etc/hostname.* files of plumbed IPv4 interfaces. If an
# /etc/hostname file is not present or is empty, the ifconfig auto-dhcp
# / auto-revarp command will attempt to set the address, later.
#
# If /etc/hostname.lo0 exists the loop below will do additional
# configuration of lo0.
#
if [ -n "$inet_plumbed" ]; then
i4s_fail=
echo "configuring IPv4 interfaces:\c"
set -- $inet_plumbed
while [ $# -gt 0 ]; do
l3protect=`/sbin/ifconfig $1|grep -c L3PROTECT`
if [ $l3protect != 0 ]; then
echo "Ignoring /etc/hostname.$1" > /dev/msglog
else
inet_process_hostname /sbin/ifconfig $1 inet \
</etc/hostname.$1 >/dev/null
[ $? != 0 ] && i4s_fail="$i4s_fail $1"
echo " $1\c"
fi
shift
done
echo "."
[ -n "$i4s_fail" ] && warn_failed_ifs "configure IPv4" $i4s_fail
fi
#
# Process the /etc/hostname6.* files of plumbed IPv6 interfaces. After
# processing the hostname6 file, bring the interface up. If
# /etc/hostname6.lo0 exists the loop below will do additional
# configuration of lo0.
#
if [ -n "$inet6_plumbed" ]; then
i6_fail=
echo "configuring IPv6 interfaces:\c"
set -- $inet6_plumbed
while [ $# -gt 0 ]; do
l3protect=`/sbin/ifconfig $1|grep -c L3PROTECT`
if [ $l3protect != 0 ]; then
echo "Ignoring /etc/hostname6.$1" > /dev/msglog
else
inet6_process_hostname /sbin/ifconfig $1 inet6 \
</etc/hostname6.$1 >/dev/null &&
/sbin/ifconfig $1 inet6 up
[ $? != 0 ] && i6_fail="$i6_fail $1"
echo " $1\c"
fi
shift
done
echo "."
[ -n "$i6_fail" ] && warn_failed_ifs "configure IPv6" $i6_fail
fi
# Run DHCP if requested. Skip boot-configured interface.
interface_names="`echo /etc/dhcp.*[0-9] 2>/dev/null`"
if [ "$interface_names" != '/etc/dhcp.*[0-9]' ]; then
#
# First find the primary interface. Default to the first
# interface if not specified. First primary interface found
# "wins". Use care not to "reconfigure" a net-booted interface
# configured using DHCP. Run through the list of interfaces
# again, this time trying DHCP.
#
i4d_fail=
firstif=
primary=
ORIGIFS="$IFS"
IFS="${IFS}."
set -- $interface_names
while [ $# -ge 2 ]; do
shift
[ -z "$firstif" ] && firstif=$1
for i in `shcat /etc/dhcp\.$1`; do
if [ "$i" = primary ]; then
primary=$1
break
fi
done
[ -n "$primary" ] && break
shift
done
[ -z "$primary" ] && primary="$firstif"
cmdline=`shcat /etc/dhcp\.${primary}`
if [ "$_INIT_NET_IF" != "$primary" ]; then
echo "starting DHCP on primary interface $primary"
/sbin/ifconfig $primary auto-dhcp primary $cmdline
# Exit code 4 means ifconfig timed out waiting for dhcpagent
[ $? != 0 ] && [ $? != 4 ] && i4d_fail="$i4d_fail $primary"
fi
set -- $interface_names
while [ $# -ge 2 ]; do
shift
cmdline=`shcat /etc/dhcp\.$1`
if [ "$1" != "$primary" -a \
"$1" != "$_INIT_NET_IF" ]; then
echo "starting DHCP on interface $1"
/sbin/ifconfig $1 dhcp start wait 0 $cmdline
# Exit code can't be timeout when wait is 0
[ $? != 0 ] && i4d_fail="$i4d_fail $1"
fi
shift
done
IFS="$ORIGIFS"
unset ORIGIFS
[ -n "$i4d_fail" ] && warn_failed_ifs "configure IPv4 DHCP" $i4d_fail
fi
# In order to avoid bringing up the interfaces that have
# intentionally been left down, perform RARP only if the system
# has no configured hostname in /etc/nodename
hostname="`shcat /etc/nodename 2>/dev/null`"
if [ "$_INIT_NET_STRATEGY" = "rarp" -o -z "$hostname" ]; then
/sbin/ifconfig -adD4 auto-revarp netmask + broadcast + up
fi
#
# Process IPv4 and IPv6 interfaces that failed to plumb. Find an
# alternative interface to host the addresses.
#
[ -n "$inet_failed" ] && move_addresses inet
[ -n "$inet6_failed" ] && move_addresses inet6
#
# If the /etc/defaultrouter file exists, process it now so that the next
# stage of booting will have access to NFS.
#
if [ -f /etc/defaultrouter ]; then
while read router rubbish; do
case "$router" in
'#'* | '') ;; # Ignore comments, empty lines
*) /sbin/route -n add default -gateway $router ;;
esac
done </etc/defaultrouter
fi
#
# We tell smf this service is online if any of the following is true:
# - no interfaces were configured for plumbing and no DHCP failures
# - there are any DHCP interfaces started
# - any non-loopback, non-DHCP IPv4 interfaces are up and have a non-zero
# address
# - any non-loopback IPv6 interfaces are up
#
# If we weren't asked to configure any interfaces, exit
if [ -z "$inet_list" ] && [ -z "$inet6_list" ]; then
# Config error if DHCP was attempted without plumbed interfaces
[ -n "$i4d_fail" ] && exit $SMF_EXIT_ERR_CONFIG
exit $SMF_EXIT_OK
fi
# Any DHCP interfaces?
[ -n "`/sbin/ifconfig -a4 dhcp status 2>/dev/null`" ] && exit $SMF_EXIT_OK
# Any non-loopback, non-DHCP IPv4 interfaces with usable addresses up?
if [ -n "`/sbin/ifconfig -a4uD`" ]; then
/sbin/ifconfig -a4uD | while read intf addr rest; do
[ $intf = inet ] && [ $addr != 127.0.0.1 ] &&
[ $addr != 0.0.0.0 ] && exit 0
done && exit $SMF_EXIT_OK
fi
# Any non-loopback IPv6 interfaces up?
if [ -n "`/sbin/ifconfig -au6`" ]; then
/sbin/ifconfig -au6 | while read intf addr rest; do
[ $intf = inet6 ] && [ $addr != ::1/128 ] && exit 0
done && exit $SMF_EXIT_OK
fi
# This service was supposed to configure something yet didn't. Exit
# with config error.
exit $SMF_EXIT_ERR_CONFIG
#
# 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.
#
default: all
include $(SRC)/lib/Makefile.lib
# Hammerhead: amd64-only
SUBDIRS = $(MACH64)
all : TARGET= all
clean : TARGET= clean
clobber : TARGET= clobber
install : TARGET= install
.KEEP_STATE:
all install clean clobber: $(SUBDIRS)
$(SUBDIRS): FRC
@cd $@; pwd; $(MAKE) $(TARGET)
FRC:
#
# 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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
COBJS = brand_librtld_db.o
OBJECTS = $(COBJS) $(COBJS64)
include ../../Makefile.s10
include $(BRAND_SHARED)/librtld_db/Makefile.com
#
# 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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
#
COBJS64 = brand_librtld_db64.o
include ../Makefile.com
include $(SRC)/lib/Makefile.lib.64
CLOBBERFILES = $(ROOTLIBDIR64)/$(DYNLIB)
install: all $(ROOTLIBS64)
#
# 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 $(SRC)/lib/Makefile.lib
default: all
# Hammerhead: amd64-only
SUBDIRS = $(MACH64)
all : TARGET= all
clean : TARGET= clean
clobber : TARGET= clobber
install : TARGET= install
_msg : TARGET= _msg
.KEEP_STATE:
all install clean clobber _msg: $(SUBDIRS)
$(SUBDIRS): FRC
@cd $@; pwd; $(MAKE) $(TARGET)
FRC:
#
# 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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2016 by Delphix. All rights reserved.
# Copyright 2020 Joyent, Inc.
#
LIBRARY = s10_brand.a
VERS = .1
COBJS = s10_brand.o s10_deleted.o s10_signal.o
ASOBJS = crt.o handler.o runexe.o brand_util.o
OBJECTS = $(COBJS)
include ../../Makefile.s10
include $(SRC)/lib/Makefile.lib
SRCDIR = ../common
UTSBASE = $(SRC)/uts
LIBS = $(DYNLIB)
CSRCS = $(COBJS:%o=../common/%c)
SHAREDOBJS = $(ASOBJS:%o=$(ISAOBJDIR)/%o)
SRCS = $(CSRCS)
#
# Note that the architecture specific makefiles MUST update DYNFLAGS to
# explicitly specify an interpreter for the brand emulation library so that we
# use /lib/ld.so.1 or /lib/64/ld.so.1, which in a s10 zone is the Solaris 10
# linker. This is different from some other brands where the linker that is
# used is the native system linker (/.SUNWnative/.../ld.so.1). We have to do
# this because the linker has a very incestuous relationship with libc and we
# don't want to use the native linker with the s10 version of libc. (This may
# come as a surprise to the reader, but when our library is loaded it get's
# linked against the s10 version of libc.) Although the linker interfaces are
# normally stable, there are examples, such as with the solaris8 brand, where
# we could not combine the brand's libc with the native linker. Since we want
# to run in a known configuration, we use the S10 libc/linker combination.
#
# There is one more non-obvious side effect of using the s10 linker that
# should be mentioned. Since the linker is used to setup processes before
# libc is loaded, it makes system calls directly (ie avoiding libc), and
# it makes these system calls before our library has been initialized.
# Since our library hasn't been initialized yet, there's no way for us
# to intercept and emulate any of those system calls. So if any of those
# system calls ever change in the native code such that they break the s10
# linker then we're kinda screwed and will need to re-visit the current
# solution. (The likely solution then will probably be to start using the
# native linker with our brand emulation library.)
#
# Note that we make sure to link our brand emulation library
# libmapmalloc. This is required because in most cases there will be two
# copies of libc in the same process and we don't want them to fight over
# the heap. So for our brand library we link against libmapmalloc so that
# if we (our or copy of libc) try to allocate any memory it will be done
# via mmap() instead of brk().
#
CPPFLAGS += -D_REENTRANT -U_ASM \
-I. -I$(BRAND_SHARED)/brand/sys -I../sys \
-I$(UTSBASE)/common/brand/solaris10 \
-I$(SRC)/uts/common/fs/zfs
CFLAGS += $(CCVERBOSE)
# Needed to handle zfs include files
CSTD= $(CSTD_GNU99)
DYNFLAGS += $(DYNFLAGS_$(CLASS))
DYNFLAGS += $(BLOCAL) $(ZNOVERSION) -Wl,-e_start
LDLIBS += -lmapmalloc -lc
#
# Disable stack protection as we're running in an s10 context.
#
STACKPROTECT = none
CERRWARN += $(CNOWARN_UNINIT)
$(LIBS): PICS += $(SHAREDOBJS)
.KEEP_STATE:
all: $(LIBS)
include $(SRC)/lib/Makefile.targ
#
# 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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
ISAOBJDIR = $(BRAND_SHARED)/brand/amd64/pics/
include ../Makefile.com
include $(SRC)/lib/Makefile.lib.64
CPPFLAGS += -I$(BRAND_SHARED)/brand/amd64
#
# see ../Makefile.com for why we MUST explicity make ld.so.1 our interpreter
#
# S10 linker
DYNFLAGS += -Wl,-I/lib/64/ld.so.1
CPPFLAGS += -D_SYSCALL32
CLEANFILES += $(DYNLIB)
CLOBBERFILES += $(ROOTLIBS64)
install: all $(ROOTLIBS64)
#
# 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.
#
#
# MAPFILE HEADER START
#
# WARNING: STOP NOW. DO NOT MODIFY THIS FILE.
# Object versioning must comply with the rules detailed in
#
# usr/src/lib/README.mapfiles
#
# You should not be making modifications here until you've read the most current
# copy of that file. If you need help, contact a gatekeeper for guidance.
#
# MAPFILE HEADER END
#
$mapfile_version 2
#
# Scope everything local -- our .init section is our only public interface.
#
SYMBOL_SCOPE {
local:
*;
};
/*
* 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 2016 Toomas Soome <tsoome@me.com>
* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2024 Oxide Computer Company
*/
#include <errno.h>
#include <fcntl.h>
#include <dirent.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <thread.h>
#include <sys/auxv.h>
#include <sys/brand.h>
#include <sys/inttypes.h>
#include <sys/lwp.h>
#include <sys/syscall.h>
#include <sys/systm.h>
#include <sys/utsname.h>
#include <sys/sysconfig.h>
#include <sys/systeminfo.h>
#include <sys/zone.h>
#include <sys/stat.h>
#include <sys/mntent.h>
#include <sys/ctfs.h>
#include <sys/priv.h>
#include <sys/acctctl.h>
#include <libgen.h>
#include <bsm/audit.h>
#include <sys/crypto/ioctl.h>
#include <sys/fs/zfs.h>
#include <sys/zfs_ioctl.h>
#include <sys/ucontext.h>
#include <sys/mntio.h>
#include <sys/mnttab.h>
#include <sys/attr.h>
#include <sys/lofi.h>
#include <atomic.h>
#include <sys/acl.h>
#include <sys/socket.h>
#include <sys/fdsync.h>
#include <s10_brand.h>
#include <brand_misc.h>
#include <s10_misc.h>
#include <s10_signal.h>
/*
* See usr/src/lib/brand/shared/brand/common/brand_util.c for general
* emulation notes.
*/
static zoneid_t zoneid;
static boolean_t emul_global_zone = B_FALSE;
static s10_emul_bitmap_t emul_bitmap;
pid_t zone_init_pid;
/*
* S10_FEATURE_IS_PRESENT is a macro that helps facilitate conditional
* emulation. For each constant N defined in the s10_emulated_features
* enumeration in usr/src/uts/common/brand/solaris10/s10_brand.h,
* S10_FEATURE_IS_PRESENT(N) is true iff the feature/backport represented by N
* is present in the Solaris 10 image hosted within the zone. In other words,
* S10_FEATURE_IS_PRESENT(N) is true iff the file /usr/lib/brand/solaris10/M,
* where M is the enum value of N, was present in the zone when the zone booted.
*
*
* *** Sample Usage
*
* Suppose that you need to backport a fix to Solaris 10 and there is
* emulation in place for the fix. Suppose further that the emulation won't be
* needed if the fix is backported (i.e., if the fix is present in the hosted
* Solaris 10 environment, then the brand won't need the emulation). Then if
* you add a constant named "S10_FEATURE_X" to the end of the
* s10_emulated_features enumeration that represents the backported fix and
* S10_FEATURE_X evaluates to four, then you should create a file named
* /usr/lib/brand/solaris10/4 as part of your backport. Additionally, you
* should retain the aforementioned emulation but modify it so that it's
* performed only when S10_FEATURE_IS_PRESENT(S10_FEATURE_X) is false. Thus the
* emulation function should look something like the following:
*
* static int
* my_emul_function(sysret_t *rv, ...)
* {
* if (S10_FEATURE_IS_PRESENT(S10_FEATURE_X)) {
* // Don't emulate
* return (__systemcall(rv, ...));
* } else {
* // Emulate whatever needs to be emulated when the
* // backport isn't present in the Solaris 10 image.
* }
* }
*/
#define S10_FEATURE_IS_PRESENT(s10_emulated_features_constant) \
((emul_bitmap[(s10_emulated_features_constant) >> 3] & \
(1 << ((s10_emulated_features_constant) & 0x7))) != 0)
brand_sysent_table_t brand_sysent_table[];
#define S10_UTS_RELEASE "5.10"
#define S10_UTS_VERSION "Generic_Virtual"
/*
* If the ioctl fd's major doesn't match "major", then pass through the
* ioctl, since it is not the expected device. major should be a
* pointer to a static dev_t initialized to -1, and devname should be
* the path of the device.
*
* Returns 1 if the ioctl was handled (in which case *err contains the
* error code), or 0 if it still needs handling.
*/
static int
passthru_otherdev_ioctl(dev_t *majordev, const char *devname, int *err,
sysret_t *rval, int fdes, int cmd, intptr_t arg)
{
struct stat sbuf;
if (*majordev == (dev_t)-1) {
if ((*err = __systemcall(rval, SYS_fstatat + 1024,
AT_FDCWD, devname, &sbuf, 0) != 0) != 0)
goto doioctl;
*majordev = major(sbuf.st_rdev);
}
if ((*err = __systemcall(rval, SYS_fstatat + 1024, fdes,
NULL, &sbuf, 0)) != 0)
goto doioctl;
if (major(sbuf.st_rdev) == *majordev)
return (0);
doioctl:
*err = (__systemcall(rval, SYS_ioctl + 1024, fdes, cmd, arg));
return (1);
}
/*
* Figures out the PID of init for the zone. Also returns a boolean
* indicating whether this process currently has that pid: if so,
* then at this moment, we are init.
*/
static boolean_t
get_initpid_info(void)
{
pid_t pid;
sysret_t rval;
int err;
/*
* Determine the current process PID and the PID of the zone's init.
* We use care not to call getpid() here, because we're not supposed
* to call getpid() until after the program is fully linked-- the
* first call to getpid() is a signal from the linker to debuggers
* that linking has been completed.
*/
if ((err = __systemcall(&rval, SYS_brand,
B_S10_PIDINFO, &pid, &zone_init_pid)) != 0) {
brand_abort(err, "Failed to get init's pid");
}
/*
* Note that we need to be cautious with the pid we get back--
* it should not be stashed and used in place of getpid(), since
* we might fork(2). So we keep zone_init_pid and toss the pid
* we otherwise got.
*/
if (pid == zone_init_pid)
return (B_TRUE);
return (B_FALSE);
}
/* Free the thread-local storage provided by mntfs_get_mntentbuf(). */
static void
mntfs_free_mntentbuf(void *arg)
{
struct mntentbuf *embufp = arg;
if (embufp == NULL)
return;
if (embufp->mbuf_emp)
free(embufp->mbuf_emp);
if (embufp->mbuf_buf)
free(embufp->mbuf_buf);
bzero(embufp, sizeof (struct mntentbuf));
free(embufp);
}
/* Provide the thread-local storage required by mntfs_ioctl(). */
static struct mntentbuf *
mntfs_get_mntentbuf(size_t size)
{
static mutex_t keylock;
static thread_key_t key;
static int once_per_keyname = 0;
void *tsd = NULL;
struct mntentbuf *embufp;
/* Create the key. */
if (!once_per_keyname) {
(void) mutex_lock(&keylock);
if (!once_per_keyname) {
if (thr_keycreate(&key, mntfs_free_mntentbuf)) {
(void) mutex_unlock(&keylock);
return (NULL);
} else {
once_per_keyname++;
}
}
(void) mutex_unlock(&keylock);
}
/*
* The thread-specific datum for this key is the address of a struct
* mntentbuf. If this is the first time here then we allocate the struct
* and its contents, and associate its address with the thread; if there
* are any problems then we abort.
*/
if (thr_getspecific(key, &tsd))
return (NULL);
if (tsd == NULL) {
if (!(embufp = calloc(1, sizeof (struct mntentbuf))) ||
!(embufp->mbuf_emp = malloc(sizeof (struct extmnttab))) ||
thr_setspecific(key, embufp)) {
mntfs_free_mntentbuf(embufp);
return (NULL);
}
} else {
embufp = tsd;
}
/* Return the buffer, resizing it if necessary. */
if (size > embufp->mbuf_bufsize) {
if (embufp->mbuf_buf)
free(embufp->mbuf_buf);
if ((embufp->mbuf_buf = malloc(size)) == NULL) {
embufp->mbuf_bufsize = 0;
return (NULL);
} else {
embufp->mbuf_bufsize = size;
}
}
return (embufp);
}
/*
* The MNTIOC_GETMNTENT command in this release differs from that in early
* versions of Solaris 10.
*
* Previously, the command would copy a pointer to a struct extmnttab to an
* address provided as an argument. The pointer would be somewhere within a
* mapping already present within the user's address space. In addition, the
* text to which the struct's members pointed would also be within a
* pre-existing mapping. Now, the user is required to allocate memory for both
* the struct and the text buffer, and to pass the address of each within a
* struct mntentbuf. In order to conceal these details from a Solaris 10 client
* we allocate some thread-local storage in which to create the necessary data
* structures; this is static, thread-safe memory that will be cleaned up
* without the caller's intervention.
*
* MNTIOC_GETEXTMNTENT and MNTIOC_GETMNTANY are new in this release; they should
* not work for older clients.
*/
int
mntfs_ioctl(sysret_t *rval, int fdes, int cmd, intptr_t arg)
{
int err;
struct stat statbuf;
struct mntentbuf *embufp;
static size_t bufsize = MNT_LINE_MAX;
/* Do not emulate mntfs commands from up-to-date clients. */
if (S10_FEATURE_IS_PRESENT(S10_FEATURE_ALTERED_MNTFS_IOCTL))
return (__systemcall(rval, SYS_ioctl + 1024, fdes, cmd, arg));
/* Do not emulate mntfs commands directed at other file systems. */
if ((err = __systemcall(rval, SYS_fstatat + 1024,
fdes, NULL, &statbuf, 0)) != 0)
return (err);
if (strcmp(statbuf.st_fstype, MNTTYPE_MNTFS) != 0)
return (__systemcall(rval, SYS_ioctl + 1024, fdes, cmd, arg));
if (cmd == MNTIOC_GETEXTMNTENT || cmd == MNTIOC_GETMNTANY)
return (EINVAL);
if ((embufp = mntfs_get_mntentbuf(bufsize)) == NULL)
return (ENOMEM);
/*
* MNTIOC_GETEXTMNTENT advances the file pointer once it has
* successfully copied out the result to the address provided. We
* therefore need to check the user-supplied address now since the
* one we'll be providing is guaranteed to work.
*/
if (brand_uucopy(&embufp->mbuf_emp, (void *)arg, sizeof (void *)) != 0)
return (EFAULT);
/*
* Keep retrying for as long as we fail for want of a large enough
* buffer.
*/
for (;;) {
if ((err = __systemcall(rval, SYS_ioctl + 1024, fdes,
MNTIOC_GETEXTMNTENT, embufp)) != 0)
return (err);
if (rval->sys_rval1 == MNTFS_TOOLONG) {
/* The buffer wasn't large enough. */
(void) atomic_swap_ulong((unsigned long *)&bufsize,
2 * embufp->mbuf_bufsize);
if ((embufp = mntfs_get_mntentbuf(bufsize)) == NULL)
return (ENOMEM);
} else {
break;
}
}
if (brand_uucopy(&embufp->mbuf_emp, (void *)arg, sizeof (void *)) != 0)
return (EFAULT);
return (0);
}
/*
* Assign the structure member value from the s (source) structure to the
* d (dest) structure.
*/
#define struct_assign(d, s, val) (((d).val) = ((s).val))
/*
* The CRYPTO_GET_FUNCTION_LIST parameter structure crypto_function_list_t
* changed between S10 and Nevada, so we have to emulate the old S10
* crypto_function_list_t structure when interposing on the ioctl syscall.
*/
typedef struct s10_crypto_function_list {
boolean_t fl_digest_init;
boolean_t fl_digest;
boolean_t fl_digest_update;
boolean_t fl_digest_key;
boolean_t fl_digest_final;
boolean_t fl_encrypt_init;
boolean_t fl_encrypt;
boolean_t fl_encrypt_update;
boolean_t fl_encrypt_final;
boolean_t fl_decrypt_init;
boolean_t fl_decrypt;
boolean_t fl_decrypt_update;
boolean_t fl_decrypt_final;
boolean_t fl_mac_init;
boolean_t fl_mac;
boolean_t fl_mac_update;
boolean_t fl_mac_final;
boolean_t fl_sign_init;
boolean_t fl_sign;
boolean_t fl_sign_update;
boolean_t fl_sign_final;
boolean_t fl_sign_recover_init;
boolean_t fl_sign_recover;
boolean_t fl_verify_init;
boolean_t fl_verify;
boolean_t fl_verify_update;
boolean_t fl_verify_final;
boolean_t fl_verify_recover_init;
boolean_t fl_verify_recover;
boolean_t fl_digest_encrypt_update;
boolean_t fl_decrypt_digest_update;
boolean_t fl_sign_encrypt_update;
boolean_t fl_decrypt_verify_update;
boolean_t fl_seed_random;
boolean_t fl_generate_random;
boolean_t fl_session_open;
boolean_t fl_session_close;
boolean_t fl_session_login;
boolean_t fl_session_logout;
boolean_t fl_object_create;
boolean_t fl_object_copy;
boolean_t fl_object_destroy;
boolean_t fl_object_get_size;
boolean_t fl_object_get_attribute_value;
boolean_t fl_object_set_attribute_value;
boolean_t fl_object_find_init;
boolean_t fl_object_find;
boolean_t fl_object_find_final;
boolean_t fl_key_generate;
boolean_t fl_key_generate_pair;
boolean_t fl_key_wrap;
boolean_t fl_key_unwrap;
boolean_t fl_key_derive;
boolean_t fl_init_token;
boolean_t fl_init_pin;
boolean_t fl_set_pin;
boolean_t prov_is_hash_limited;
uint32_t prov_hash_threshold;
uint32_t prov_hash_limit;
} s10_crypto_function_list_t;
typedef struct s10_crypto_get_function_list {
uint_t fl_return_value;
crypto_provider_id_t fl_provider_id;
s10_crypto_function_list_t fl_list;
} s10_crypto_get_function_list_t;
/*
* The structure returned by the CRYPTO_GET_FUNCTION_LIST ioctl on /dev/crypto
* increased in size due to:
* 6482533 Threshold for HW offload via PKCS11 interface
* between S10 and Nevada. This is a relatively simple process of filling
* in the S10 structure fields with the Nevada data.
*
* We stat the device to make sure that the ioctl is meant for /dev/crypto.
*
*/
static int
crypto_ioctl(sysret_t *rval, int fdes, int cmd, intptr_t arg)
{
int err;
s10_crypto_get_function_list_t s10_param;
crypto_get_function_list_t native_param;
static dev_t crypto_dev = (dev_t)-1;
if (passthru_otherdev_ioctl(&crypto_dev, "/dev/crypto", &err,
rval, fdes, cmd, arg) == 1)
return (err);
if (brand_uucopy((const void *)arg, &s10_param, sizeof (s10_param))
!= 0)
return (EFAULT);
struct_assign(native_param, s10_param, fl_provider_id);
if ((err = __systemcall(rval, SYS_ioctl + 1024, fdes, cmd,
&native_param)) != 0)
return (err);
struct_assign(s10_param, native_param, fl_return_value);
struct_assign(s10_param, native_param, fl_provider_id);
struct_assign(s10_param, native_param, fl_list.fl_digest_init);
struct_assign(s10_param, native_param, fl_list.fl_digest);
struct_assign(s10_param, native_param, fl_list.fl_digest_update);
struct_assign(s10_param, native_param, fl_list.fl_digest_key);
struct_assign(s10_param, native_param, fl_list.fl_digest_final);
struct_assign(s10_param, native_param, fl_list.fl_encrypt_init);
struct_assign(s10_param, native_param, fl_list.fl_encrypt);
struct_assign(s10_param, native_param, fl_list.fl_encrypt_update);
struct_assign(s10_param, native_param, fl_list.fl_encrypt_final);
struct_assign(s10_param, native_param, fl_list.fl_decrypt_init);
struct_assign(s10_param, native_param, fl_list.fl_decrypt);
struct_assign(s10_param, native_param, fl_list.fl_decrypt_update);
struct_assign(s10_param, native_param, fl_list.fl_decrypt_final);
struct_assign(s10_param, native_param, fl_list.fl_mac_init);
struct_assign(s10_param, native_param, fl_list.fl_mac);
struct_assign(s10_param, native_param, fl_list.fl_mac_update);
struct_assign(s10_param, native_param, fl_list.fl_mac_final);
struct_assign(s10_param, native_param, fl_list.fl_sign_init);
struct_assign(s10_param, native_param, fl_list.fl_sign);
struct_assign(s10_param, native_param, fl_list.fl_sign_update);
struct_assign(s10_param, native_param, fl_list.fl_sign_final);
struct_assign(s10_param, native_param, fl_list.fl_sign_recover_init);
struct_assign(s10_param, native_param, fl_list.fl_sign_recover);
struct_assign(s10_param, native_param, fl_list.fl_verify_init);
struct_assign(s10_param, native_param, fl_list.fl_verify);
struct_assign(s10_param, native_param, fl_list.fl_verify_update);
struct_assign(s10_param, native_param, fl_list.fl_verify_final);
struct_assign(s10_param, native_param, fl_list.fl_verify_recover_init);
struct_assign(s10_param, native_param, fl_list.fl_verify_recover);
struct_assign(s10_param, native_param,
fl_list.fl_digest_encrypt_update);
struct_assign(s10_param, native_param,
fl_list.fl_decrypt_digest_update);
struct_assign(s10_param, native_param, fl_list.fl_sign_encrypt_update);
struct_assign(s10_param, native_param,
fl_list.fl_decrypt_verify_update);
struct_assign(s10_param, native_param, fl_list.fl_seed_random);
struct_assign(s10_param, native_param, fl_list.fl_generate_random);
struct_assign(s10_param, native_param, fl_list.fl_session_open);
struct_assign(s10_param, native_param, fl_list.fl_session_close);
struct_assign(s10_param, native_param, fl_list.fl_session_login);
struct_assign(s10_param, native_param, fl_list.fl_session_logout);
struct_assign(s10_param, native_param, fl_list.fl_object_create);
struct_assign(s10_param, native_param, fl_list.fl_object_copy);
struct_assign(s10_param, native_param, fl_list.fl_object_destroy);
struct_assign(s10_param, native_param, fl_list.fl_object_get_size);
struct_assign(s10_param, native_param,
fl_list.fl_object_get_attribute_value);
struct_assign(s10_param, native_param,
fl_list.fl_object_set_attribute_value);
struct_assign(s10_param, native_param, fl_list.fl_object_find_init);
struct_assign(s10_param, native_param, fl_list.fl_object_find);
struct_assign(s10_param, native_param, fl_list.fl_object_find_final);
struct_assign(s10_param, native_param, fl_list.fl_key_generate);
struct_assign(s10_param, native_param, fl_list.fl_key_generate_pair);
struct_assign(s10_param, native_param, fl_list.fl_key_wrap);
struct_assign(s10_param, native_param, fl_list.fl_key_unwrap);
struct_assign(s10_param, native_param, fl_list.fl_key_derive);
struct_assign(s10_param, native_param, fl_list.fl_init_token);
struct_assign(s10_param, native_param, fl_list.fl_init_pin);
struct_assign(s10_param, native_param, fl_list.fl_set_pin);
struct_assign(s10_param, native_param, fl_list.prov_is_hash_limited);
struct_assign(s10_param, native_param, fl_list.prov_hash_threshold);
struct_assign(s10_param, native_param, fl_list.prov_hash_limit);
return (brand_uucopy(&s10_param, (void *)arg, sizeof (s10_param)));
}
/*
* The process contract CT_TGET and CT_TSET parameter structure ct_param_t
* changed between S10 and Nevada, so we have to emulate the old S10
* ct_param_t structure when interposing on the ioctl syscall.
*/
typedef struct s10_ct_param {
uint32_t ctpm_id;
uint32_t ctpm_pad;
uint64_t ctpm_value;
} s10_ct_param_t;
/*
* We have to emulate process contract ioctls for init(8) because the
* ioctl parameter structure changed between S10 and Nevada. This is
* a relatively simple process of filling Nevada structure fields,
* shuffling values, and initiating a native system call.
*
* For now, we'll assume that all consumers of CT_TGET and CT_TSET will
* need emulation. We'll issue a stat to make sure that the ioctl
* is meant for the contract file system.
*
*/
static int
ctfs_ioctl(sysret_t *rval, int fdes, int cmd, intptr_t arg)
{
int err;
s10_ct_param_t s10param;
ct_param_t param;
struct stat statbuf;
if ((err = __systemcall(rval, SYS_fstatat + 1024,
fdes, NULL, &statbuf, 0)) != 0)
return (err);
if (strcmp(statbuf.st_fstype, MNTTYPE_CTFS) != 0)
return (__systemcall(rval, SYS_ioctl + 1024, fdes, cmd, arg));
if (brand_uucopy((const void *)arg, &s10param, sizeof (s10param)) != 0)
return (EFAULT);
param.ctpm_id = s10param.ctpm_id;
param.ctpm_size = sizeof (uint64_t);
param.ctpm_value = &s10param.ctpm_value;
if ((err = __systemcall(rval, SYS_ioctl + 1024, fdes, cmd, ¶m))
!= 0)
return (err);
if (cmd == CT_TGET)
return (brand_uucopy(&s10param, (void *)arg,
sizeof (s10param)));
return (0);
}
/*
* ZFS ioctls have changed in each Solaris 10 (S10) release as well as in
* Solaris Next. The brand wraps ZFS commands so that the native commands
* are used, but we want to be sure no command sneaks in that uses ZFS
* without our knowledge. We'll abort the process if we see a ZFS ioctl.
*/
static int
zfs_ioctl(sysret_t *rval, int fdes, int cmd, intptr_t arg)
{
static dev_t zfs_dev = (dev_t)-1;
int err;
if (passthru_otherdev_ioctl(&zfs_dev, ZFS_DEV, &err,
rval, fdes, cmd, arg) == 1)
return (err);
brand_abort(0, "ZFS ioctl!");
/*NOTREACHED*/
return (0);
}
struct s10_lofi_ioctl {
uint32_t li_id;
boolean_t li_force;
char li_filename[MAXPATHLEN + 1];
};
static int
lofi_ioctl(sysret_t *rval, int fdes, int cmd, intptr_t arg)
{
static dev_t lofi_dev = (dev_t)-1;
struct s10_lofi_ioctl s10_param;
struct lofi_ioctl native_param;
int err;
if (passthru_otherdev_ioctl(&lofi_dev, "/dev/lofictl", &err,
rval, fdes, cmd, arg) == 1)
return (err);
if (brand_uucopy((const void *)arg, &s10_param,
sizeof (s10_param)) != 0)
return (EFAULT);
/*
* Somewhat weirdly, EIO is what the S10 lofi driver would
* return for unrecognised cmds.
*/
if (cmd >= LOFI_CHECK_COMPRESSED)
return (EIO);
bzero(&native_param, sizeof (native_param));
struct_assign(native_param, s10_param, li_id);
struct_assign(native_param, s10_param, li_force);
/*
* Careful here, this has changed from [MAXPATHLEN + 1] to
* [MAXPATHLEN].
*/
bcopy(s10_param.li_filename, native_param.li_filename,
sizeof (native_param.li_filename));
native_param.li_filename[MAXPATHLEN - 1] = '\0';
err = __systemcall(rval, SYS_ioctl + 1024, fdes, cmd, &native_param);
struct_assign(s10_param, native_param, li_id);
/* li_force is input-only */
bcopy(native_param.li_filename, s10_param.li_filename,
sizeof (native_param.li_filename));
(void) brand_uucopy(&s10_param, (void *)arg, sizeof (s10_param));
return (err);
}
int
s10_ioctl(sysret_t *rval, int fdes, int cmd, intptr_t arg)
{
switch (cmd) {
case CRYPTO_GET_FUNCTION_LIST:
return (crypto_ioctl(rval, fdes, cmd, arg));
case CT_TGET:
/*FALLTHRU*/
case CT_TSET:
return (ctfs_ioctl(rval, fdes, cmd, arg));
case MNTIOC_GETMNTENT:
/*FALLTHRU*/
case MNTIOC_GETEXTMNTENT:
/*FALLTHRU*/
case MNTIOC_GETMNTANY:
return (mntfs_ioctl(rval, fdes, cmd, arg));
}
switch (cmd & ~0xff) {
case ZFS_IOC:
return (zfs_ioctl(rval, fdes, cmd, arg));
case LOFI_IOC_BASE:
return (lofi_ioctl(rval, fdes, cmd, arg));
default:
break;
}
return (__systemcall(rval, SYS_ioctl + 1024, fdes, cmd, arg));
}
/*
* Unfortunately, pwrite()'s behavior differs between S10 and Nevada when
* applied to files opened with O_APPEND. The offset argument is ignored and
* the buffer is appended to the target file in S10, whereas the current file
* position is ignored in Nevada (i.e., pwrite() acts as though the target file
* wasn't opened with O_APPEND). This is a result of the fix for CR 6655660
* (pwrite() must ignore the O_APPEND/FAPPEND flag).
*
* We emulate the old S10 pwrite() behavior by checking whether the target file
* was opened with O_APPEND. If it was, then invoke the write() system call
* instead of pwrite(); otherwise, invoke the pwrite() system call as usual.
*/
static int
s10_pwrite(sysret_t *rval, int fd, const void *bufferp, size_t num_bytes,
off_t offset)
{
int err;
if ((err = __systemcall(rval, SYS_fcntl + 1024, fd, F_GETFL, 0, 0)) !=
0) {
return (err);
}
if (rval->sys_rval1 & O_APPEND)
return (__systemcall(rval, SYS_write + 1024, fd, bufferp,
num_bytes));
return (__systemcall(rval, SYS_pwrite + 1024, fd, bufferp, num_bytes,
offset));
}
#if !defined(_LP64)
/*
* This is the large file version of the pwrite() system call for 32-bit
* processes. This exists for the same reason that s10_pwrite() exists; see
* the comment above s10_pwrite().
*/
static int
s10_pwrite64(sysret_t *rval, int fd, const void *bufferp, size32_t num_bytes,
uint32_t offset_1, uint32_t offset_2)
{
int err;
if ((err = __systemcall(rval, SYS_fcntl + 1024, fd, F_GETFL, 0, 0)) !=
0) {
return (err);
}
if (rval->sys_rval1 & O_APPEND)
return (__systemcall(rval, SYS_write + 1024, fd, bufferp,
num_bytes));
return (__systemcall(rval, SYS_pwrite64 + 1024, fd, bufferp,
num_bytes, offset_1, offset_2));
}
#endif /* !_LP64 */
/*
* These are convenience macros that s10_getdents_common() uses. Both treat
* their arguments, which should be character pointers, as dirent pointers or
* dirent64 pointers and yield their d_name and d_reclen fields. These
* macros shouldn't be used outside of s10_getdents_common().
*/
#define dirent_name(charptr) ((charptr) + name_offset)
#define dirent_reclen(charptr) \
(*(unsigned short *)(uintptr_t)((charptr) + reclen_offset))
/*
* This function contains code that is common to both s10_getdents() and
* s10_getdents64(). See the comment above s10_getdents() for details.
*
* rval, fd, buf, and nbyte should be passed unmodified from s10_getdents()
* and s10_getdents64(). getdents_syscall_id should be either SYS_getdents
* or SYS_getdents64. name_offset should be the the byte offset of
* the d_name field in the dirent structures passed to the kernel via the
* syscall represented by getdents_syscall_id. reclen_offset should be
* the byte offset of the d_reclen field in the aforementioned dirent
* structures.
*/
static int
s10_getdents_common(sysret_t *rval, int fd, char *buf, size_t nbyte,
int getdents_syscall_id, size_t name_offset, size_t reclen_offset)
{
int err;
size_t buf_size;
char *local_buf;
char *buf_current;
/*
* Use a special brand operation, B_S10_ISFDXATTRDIR, to determine
* whether the specified file descriptor refers to an extended file
* attribute directory. If it doesn't, then SYS_getdents won't
* reveal extended file attributes, in which case we can simply
* hand the syscall to the native kernel.
*/
if ((err = __systemcall(rval, SYS_brand + 1024, B_S10_ISFDXATTRDIR,
fd)) != 0)
return (err);
if (rval->sys_rval1 == 0)
return (__systemcall(rval, getdents_syscall_id + 1024, fd, buf,
nbyte));
/*
* The file descriptor refers to an extended file attributes directory.
* We need to create a dirent buffer that's as large as buf into which
* the native SYS_getdents will store the special extended file
* attribute directory's entries. We can't dereference buf because
* it might be an invalid pointer!
*/
if (nbyte > MAXGETDENTS_SIZE)
nbyte = MAXGETDENTS_SIZE;
local_buf = (char *)malloc(nbyte);
if (local_buf == NULL) {
/*
* getdents(2) doesn't return an error code indicating a memory
* allocation error and it doesn't make sense to return any of
* its documented error codes for a malloc(3C) failure. We'll
* use ENOMEM even though getdents(2) doesn't use it because it
* best describes the failure.
*/
(void) B_TRUSS_POINT_3(rval, getdents_syscall_id, ENOMEM, fd,
buf, nbyte);
rval->sys_rval1 = -1;
rval->sys_rval2 = 0;
return (EIO);
}
/*
* Issue a native SYS_getdents syscall but use our local dirent buffer
* instead of buf. This will allow us to examine the returned dirent
* structures immediately and copy them to buf later. That way the
* calling process won't be able to see the dirent structures until
* we finish examining them.
*/
if ((err = __systemcall(rval, getdents_syscall_id + 1024, fd, local_buf,
nbyte)) != 0) {
free(local_buf);
return (err);
}
buf_size = rval->sys_rval1;
if (buf_size == 0) {
free(local_buf);
return (0);
}
/*
* Look for SUNWattr_ro (VIEW_READONLY) and SUNWattr_rw
* (VIEW_READWRITE) in the directory entries and remove them
* from the dirent buffer.
*/
for (buf_current = local_buf;
(size_t)(buf_current - local_buf) < buf_size; /* cstyle */) {
if (strcmp(dirent_name(buf_current), VIEW_READONLY) != 0 &&
strcmp(dirent_name(buf_current), VIEW_READWRITE) != 0) {
/*
* The dirent refers to an attribute that should
* be visible to Solaris 10 processes. Keep it
* and examine the next entry in the buffer.
*/
buf_current += dirent_reclen(buf_current);
} else {
/*
* We found either SUNWattr_ro (VIEW_READONLY)
* or SUNWattr_rw (VIEW_READWRITE). Remove it
* from the dirent buffer by decrementing
* buf_size by the size of the entry and
* overwriting the entry with the remaining
* entries.
*/
buf_size -= dirent_reclen(buf_current);
(void) memmove(buf_current, buf_current +
dirent_reclen(buf_current), buf_size -
(size_t)(buf_current - local_buf));
}
}
/*
* Copy local_buf into buf so that the calling process can see
* the results.
*/
if ((err = brand_uucopy(local_buf, buf, buf_size)) != 0) {
free(local_buf);
rval->sys_rval1 = -1;
rval->sys_rval2 = 0;
return (err);
}
rval->sys_rval1 = buf_size;
free(local_buf);
return (0);
}
/*
* Solaris Next added two special extended file attributes, SUNWattr_ro and
* SUNWattr_rw, which are called "extended system attributes". They have
* special semantics (e.g., a process cannot unlink SUNWattr_ro) and should
* not appear in solaris10-branded zones because no Solaris 10 applications,
* including system commands such as tar(1), are coded to correctly handle these
* special attributes.
*
* This emulation function solves the aforementioned problem by emulating
* the getdents(2) syscall and filtering both system attributes out of resulting
* directory entry lists. The emulation function only filters results when
* the given file descriptor refers to an extended file attribute directory.
* Filtering getdents(2) results is expensive because it requires dynamic
* memory allocation; however, the performance cost is tolerable because
* we don't expect Solaris 10 processes to frequently examine extended file
* attribute directories.
*
* The brand's emulation library needs two getdents(2) emulation functions
* because getdents(2) comes in two flavors: non-largefile-aware getdents(2)
* and largefile-aware getdents64(2). s10_getdents() handles the non-largefile-
* aware case for 32-bit processes and all getdents(2) syscalls for 64-bit
* processes (64-bit processes use largefile-aware interfaces by default).
* See s10_getdents64() below for the largefile-aware getdents64(2) emulation
* function for 32-bit processes.
*/
static int
s10_getdents(sysret_t *rval, int fd, struct dirent *buf, size_t nbyte)
{
return (s10_getdents_common(rval, fd, (char *)buf, nbyte, SYS_getdents,
offsetof(struct dirent, d_name),
offsetof(struct dirent, d_reclen)));
}
#ifndef _LP64
/*
* This is the largefile-aware version of getdents(2) for 32-bit processes.
* This exists for the same reason that s10_getdents() exists. See the comment
* above s10_getdents().
*/
static int
s10_getdents64(sysret_t *rval, int fd, struct dirent64 *buf, size_t nbyte)
{
return (s10_getdents_common(rval, fd, (char *)buf, nbyte,
SYS_getdents64, offsetof(struct dirent64, d_name),
offsetof(struct dirent64, d_reclen)));
}
#endif /* !_LP64 */
#define S10_TRIVIAL_ACL_CNT 6
#define NATIVE_TRIVIAL_ACL_CNT 3
/*
* Check if the ACL qualifies as a trivial ACL based on the native
* interpretation.
*/
static boolean_t
has_trivial_native_acl(int cmd, int cnt, const char *fname, int fd)
{
int i, err;
sysret_t rval;
ace_t buf[NATIVE_TRIVIAL_ACL_CNT];
if (fname != NULL)
err = __systemcall(&rval, SYS_pathconf + 1024, fname,
_PC_ACL_ENABLED);
else
err = __systemcall(&rval, SYS_fpathconf + 1024, fd,
_PC_ACL_ENABLED);
if (err != 0 || rval.sys_rval1 != _ACL_ACE_ENABLED)
return (B_FALSE);
/*
* If we just got the ACL cnt, we don't need to get it again, its
* passed in as the cnt arg.
*/
if (cmd != ACE_GETACLCNT) {
if (fname != NULL) {
if (__systemcall(&rval, SYS_acl + 1024, fname,
ACE_GETACLCNT, 0, NULL) != 0)
return (B_FALSE);
} else {
if (__systemcall(&rval, SYS_facl + 1024, fd,
ACE_GETACLCNT, 0, NULL) != 0)
return (B_FALSE);
}
cnt = rval.sys_rval1;
}
if (cnt != NATIVE_TRIVIAL_ACL_CNT)
return (B_FALSE);
if (fname != NULL) {
if (__systemcall(&rval, SYS_acl + 1024, fname, ACE_GETACL, cnt,
buf) != 0)
return (B_FALSE);
} else {
if (__systemcall(&rval, SYS_facl + 1024, fd, ACE_GETACL, cnt,
buf) != 0)
return (B_FALSE);
}
/*
* The following is based on the logic from the native OS
* ace_trivial_common() to determine if the native ACL is trivial.
*/
for (i = 0; i < cnt; i++) {
switch (buf[i].a_flags & ACE_TYPE_FLAGS) {
case ACE_OWNER:
case ACE_GROUP|ACE_IDENTIFIER_GROUP:
case ACE_EVERYONE:
break;
default:
return (B_FALSE);
}
if (buf[i].a_flags & (ACE_FILE_INHERIT_ACE|
ACE_DIRECTORY_INHERIT_ACE|ACE_NO_PROPAGATE_INHERIT_ACE|
ACE_INHERIT_ONLY_ACE))
return (B_FALSE);
/*
* Special check for some special bits
*
* Don't allow anybody to deny reading basic
* attributes or a files ACL.
*/
if (buf[i].a_access_mask & (ACE_READ_ACL|ACE_READ_ATTRIBUTES) &&
buf[i].a_type == ACE_ACCESS_DENIED_ACE_TYPE)
return (B_FALSE);
/*
* Delete permissions are never set by default
*/
if (buf[i].a_access_mask & (ACE_DELETE|ACE_DELETE_CHILD))
return (B_FALSE);
/*
* only allow owner@ to have
* write_acl/write_owner/write_attributes/write_xattr/
*/
if (buf[i].a_type == ACE_ACCESS_ALLOWED_ACE_TYPE &&
(!(buf[i].a_flags & ACE_OWNER) && (buf[i].a_access_mask &
(ACE_WRITE_OWNER|ACE_WRITE_ACL| ACE_WRITE_ATTRIBUTES|
ACE_WRITE_NAMED_ATTRS))))
return (B_FALSE);
}
return (B_TRUE);
}
/*
* The following logic is based on the S10 adjust_ace_pair_common() code.
*/
static void
s10_adjust_ace_mask(void *pair, size_t access_off, size_t pairsize, mode_t mode)
{
char *datap = (char *)pair;
uint32_t *amask0 = (uint32_t *)(uintptr_t)(datap + access_off);
uint32_t *amask1 = (uint32_t *)(uintptr_t)(datap + pairsize +
access_off);
if (mode & S_IROTH)
*amask1 |= ACE_READ_DATA;
else
*amask0 |= ACE_READ_DATA;
if (mode & S_IWOTH)
*amask1 |= ACE_WRITE_DATA|ACE_APPEND_DATA;
else
*amask0 |= ACE_WRITE_DATA|ACE_APPEND_DATA;
if (mode & S_IXOTH)
*amask1 |= ACE_EXECUTE;
else
*amask0 |= ACE_EXECUTE;
}
/*
* Construct a trivial S10 style ACL.
*/
static int
make_trivial_s10_acl(const char *fname, int fd, ace_t *bp)
{
int err;
sysret_t rval;
struct stat64 buf;
ace_t trivial_s10_acl[] = {
{(uint_t)-1, 0, ACE_OWNER, ACE_ACCESS_DENIED_ACE_TYPE},
{(uint_t)-1, ACE_WRITE_ACL|ACE_WRITE_OWNER|ACE_WRITE_ATTRIBUTES|
ACE_WRITE_NAMED_ATTRS, ACE_OWNER,
ACE_ACCESS_ALLOWED_ACE_TYPE},
{(uint_t)-1, 0, ACE_GROUP|ACE_IDENTIFIER_GROUP,
ACE_ACCESS_DENIED_ACE_TYPE},
{(uint_t)-1, 0, ACE_GROUP|ACE_IDENTIFIER_GROUP,
ACE_ACCESS_ALLOWED_ACE_TYPE},
{(uint_t)-1, ACE_WRITE_ACL|ACE_WRITE_OWNER|ACE_WRITE_ATTRIBUTES|
ACE_WRITE_NAMED_ATTRS, ACE_EVERYONE,
ACE_ACCESS_DENIED_ACE_TYPE},
{(uint_t)-1, ACE_READ_ACL|ACE_READ_ATTRIBUTES|
ACE_READ_NAMED_ATTRS|ACE_SYNCHRONIZE, ACE_EVERYONE,
ACE_ACCESS_ALLOWED_ACE_TYPE}
};
if (fname != NULL) {
if ((err = __systemcall(&rval, SYS_fstatat64 + 1024, AT_FDCWD,
fname, &buf, 0)) != 0)
return (err);
} else {
if ((err = __systemcall(&rval, SYS_fstatat64 + 1024, fd,
NULL, &buf, 0)) != 0)
return (err);
}
s10_adjust_ace_mask(&trivial_s10_acl[0], offsetof(ace_t, a_access_mask),
sizeof (ace_t), (buf.st_mode & 0700) >> 6);
s10_adjust_ace_mask(&trivial_s10_acl[2], offsetof(ace_t, a_access_mask),
sizeof (ace_t), (buf.st_mode & 0070) >> 3);
s10_adjust_ace_mask(&trivial_s10_acl[4], offsetof(ace_t, a_access_mask),
sizeof (ace_t), buf.st_mode & 0007);
if (brand_uucopy(&trivial_s10_acl, bp, sizeof (trivial_s10_acl)) != 0)
return (EFAULT);
return (0);
}
/*
* The definition of a trivial ace-style ACL (used by ZFS and NFSv4) has been
* simplified since S10. Instead of 6 entries on a trivial S10 ACE ACL we now
* have 3 streamlined entries. The new, simpler trivial style confuses S10
* commands such as 'ls -v' or 'cp -p' which don't see the expected S10 trivial
* ACL entries and thus assume that there is a complex ACL on the file.
*
* See: PSARC/2010/029 Improved ACL interoperability
*
* Note that the trival ACL detection code is implemented in acl_trival() in
* lib/libsec/common/aclutils.c. It always uses the acl() syscall (not the
* facl syscall) to determine if an ACL is trivial. However, we emulate both
* acl() and facl() so that the two provide consistent results.
*
* We don't currently try to emulate setting of ACLs since the primary
* consumer of this feature is SMB or NFSv4 servers, neither of which are
* supported in solaris10-branded zones. If ACLs are used they must be set on
* files using the native OS interpretation.
*/
int
s10_acl(sysret_t *rval, const char *fname, int cmd, int nentries, void *aclbufp)
{
int res;
res = __systemcall(rval, SYS_acl + 1024, fname, cmd, nentries, aclbufp);
switch (cmd) {
case ACE_GETACLCNT:
if (res == 0 && has_trivial_native_acl(ACE_GETACLCNT,
rval->sys_rval1, fname, 0)) {
rval->sys_rval1 = S10_TRIVIAL_ACL_CNT;
}
break;
case ACE_GETACL:
if (res == 0 &&
has_trivial_native_acl(ACE_GETACL, 0, fname, 0) &&
nentries >= S10_TRIVIAL_ACL_CNT) {
res = make_trivial_s10_acl(fname, 0, aclbufp);
rval->sys_rval1 = S10_TRIVIAL_ACL_CNT;
}
break;
}
return (res);
}
int
s10_facl(sysret_t *rval, int fdes, int cmd, int nentries, void *aclbufp)
{
int res;
res = __systemcall(rval, SYS_facl + 1024, fdes, cmd, nentries, aclbufp);
switch (cmd) {
case ACE_GETACLCNT:
if (res == 0 && has_trivial_native_acl(ACE_GETACLCNT,
rval->sys_rval1, NULL, fdes)) {
rval->sys_rval1 = S10_TRIVIAL_ACL_CNT;
}
break;
case ACE_GETACL:
if (res == 0 &&
has_trivial_native_acl(ACE_GETACL, 0, NULL, fdes) &&
nentries >= S10_TRIVIAL_ACL_CNT) {
res = make_trivial_s10_acl(NULL, fdes, aclbufp);
rval->sys_rval1 = S10_TRIVIAL_ACL_CNT;
}
break;
}
return (res);
}
#define S10_AC_PROC (0x1 << 28)
#define S10_AC_TASK (0x2 << 28)
#define S10_AC_FLOW (0x4 << 28)
#define S10_AC_MODE(x) ((x) & 0xf0000000)
#define S10_AC_OPTION(x) ((x) & 0x0fffffff)
/*
* The mode shift, mode mask and option mask for acctctl have changed. The
* mode is currently the top full byte and the option is the lower 3 full bytes.
*/
int
s10_acctctl(sysret_t *rval, int cmd, void *buf, size_t bufsz)
{
int mode = S10_AC_MODE(cmd);
int option = S10_AC_OPTION(cmd);
switch (mode) {
case S10_AC_PROC:
mode = AC_PROC;
break;
case S10_AC_TASK:
mode = AC_TASK;
break;
case S10_AC_FLOW:
mode = AC_FLOW;
break;
default:
return (B_TRUSS_POINT_3(rval, SYS_acctctl, EINVAL, cmd, buf,
bufsz));
}
return (__systemcall(rval, SYS_acctctl + 1024, mode | option, buf,
bufsz));
}
/*
* The Audit Policy parameters have changed due to:
* 6466722 audituser and AUDIT_USER are defined, unused, undocumented and
* should be removed.
*
* In S10 we had the following flag:
* #define AUDIT_USER 0x0040
* which doesn't exist in Solaris Next where the subsequent flags are shifted
* down. For example, in S10 we had:
* #define AUDIT_GROUP 0x0080
* but on Solaris Next we have:
* #define AUDIT_GROUP 0x0040
* AUDIT_GROUP has the value AUDIT_USER had in S10 and all of the subsequent
* bits are also shifted one place.
*
* When we're getting or setting the Audit Policy parameters we need to
* shift the outgoing or incoming bits into their proper positions. Since
* S10_AUDIT_USER was always unused, we always clear that bit on A_GETPOLICY.
*
* The command we care about, BSM_AUDITCTL, passes the most parameters (3),
* so declare this function to take up to 4 args and just pass them on.
* The number of parameters for s10_auditsys needs to be equal to the BSM_*
* subcommand that has the most parameters, since we want to pass all
* parameters through, regardless of which subcommands we interpose on.
*
* Note that the auditsys system call uses the SYSENT_AP macro wrapper instead
* of the more common SYSENT_CI macro. This means the return value is a
* SE_64RVAL so the syscall table uses RV_64RVAL.
*/
#define S10_AUDIT_HMASK 0xffffffc0
#define S10_AUDIT_LMASK 0x3f
#define S10_AUC_NOSPACE 0x3
int
s10_auditsys(sysret_t *rval, int bsmcmd, intptr_t a0, intptr_t a1, intptr_t a2)
{
int err;
uint32_t m;
if (bsmcmd != BSM_AUDITCTL)
return (__systemcall(rval, SYS_auditsys + 1024, bsmcmd, a0, a1,
a2));
if ((int)a0 == A_GETPOLICY) {
if ((err = __systemcall(rval, SYS_auditsys + 1024, bsmcmd, a0,
&m, a2)) != 0)
return (err);
m = ((m & S10_AUDIT_HMASK) << 1) | (m & S10_AUDIT_LMASK);
if (brand_uucopy(&m, (void *)a1, sizeof (m)) != 0)
return (EFAULT);
return (0);
} else if ((int)a0 == A_SETPOLICY) {
if (brand_uucopy((const void *)a1, &m, sizeof (m)) != 0)
return (EFAULT);
m = ((m >> 1) & S10_AUDIT_HMASK) | (m & S10_AUDIT_LMASK);
return (__systemcall(rval, SYS_auditsys + 1024, bsmcmd, a0, &m,
a2));
} else if ((int)a0 == A_GETCOND) {
if ((err = __systemcall(rval, SYS_auditsys + 1024, bsmcmd, a0,
&m, a2)) != 0)
return (err);
if (m == AUC_NOSPACE)
m = S10_AUC_NOSPACE;
if (brand_uucopy(&m, (void *)a1, sizeof (m)) != 0)
return (EFAULT);
return (0);
} else if ((int)a0 == A_SETCOND) {
if (brand_uucopy((const void *)a1, &m, sizeof (m)) != 0)
return (EFAULT);
if (m == S10_AUC_NOSPACE)
m = AUC_NOSPACE;
return (__systemcall(rval, SYS_auditsys + 1024, bsmcmd, a0, &m,
a2));
}
return (__systemcall(rval, SYS_auditsys + 1024, bsmcmd, a0, a1, a2));
}
/*
* Determine whether the executable passed to SYS_exec or SYS_execve is a
* native executable. The s10_npreload.so invokes the B_S10_NATIVE brand
* operation which patches up the processes exec info to eliminate any trace
* of the wrapper. That will make pgrep and other commands that examine
* process' executable names and command-line parameters work properly.
*/
static int
s10_exec_native(sysret_t *rval, const char *fname, const char **argp,
const char **envp)
{
const char *filename = fname;
char path[64];
int err;
/* Get a copy of the executable we're trying to run */
path[0] = '\0';
(void) brand_uucopystr(filename, path, sizeof (path));
/* Check if we're trying to run a native binary */
if (strncmp(path, "/.SUNWnative/usr/lib/brand/solaris10/s10_native",
sizeof (path)) != 0)
return (0);
/* Skip the first element in the argv array */
argp++;
/*
* The the path of the dynamic linker is the second parameter
* of s10_native_exec().
*/
if (brand_uucopy(argp, &filename, sizeof (char *)) != 0)
return (EFAULT);
/* If an exec call succeeds, it never returns */
err = __systemcall(rval, SYS_brand + 1024, B_EXEC_NATIVE, filename,
argp, envp, NULL, NULL, NULL);
brand_assert(err != 0);
return (err);
}
/*
* Interpose on the SYS_exec syscall to detect native wrappers.
*/
int
s10_exec(sysret_t *rval, const char *fname, const char **argp)
{
int err;
if ((err = s10_exec_native(rval, fname, argp, NULL)) != 0)
return (err);
/* If an exec call succeeds, it never returns */
err = __systemcall(rval, SYS_execve + 1024, fname, argp, NULL, 0);
brand_assert(err != 0);
return (err);
}
/*
* Interpose on the SYS_execve syscall to detect native wrappers.
*/
int
s10_execve(sysret_t *rval, const char *fname, const char **argp,
const char **envp)
{
int err;
if ((err = s10_exec_native(rval, fname, argp, envp)) != 0)
return (err);
/* If an exec call succeeds, it never returns */
err = __systemcall(rval, SYS_execve + 1024, fname, argp, envp, 0);
brand_assert(err != 0);
return (err);
}
/*
* fcntl(2) added an additional argument which we need to pass as zero.
*/
int
s10_fcntl(sysret_t *rval, int fd, int cmd, intptr_t arg)
{
return (__systemcall(rval, SYS_fcntl + 1024, fd, cmd, arg, 0));
}
/*
* Interpose on the SYS_fdsync system call. The structure was chagned to use a
* distinct enum rather than passing a combination of the <sys/file.h> flags
* FSYNC and FDSYNC. The prior system call implementation only passed those two
* flags on to the VFS operation. The system call did not check if the 'flag'
* argument was zero or not; however, we know that in illumos it was always
* called with either FSYNC or FDSYNC explicitly. To try and fail open in a
* sense, we translate any call with no explicit level to a normal fsync(3C)
* style operation.
*/
static int
s10_fdsync(sysret_t *rval, int fd, int flag)
{
uint32_t level;
if ((flag & FSYNC) != 0) {
level = FDSYNC_FILE;
} else if ((flag & FDSYNC) != 0) {
level = FDSYNC_DATA;
} else {
level = FDSYNC_FILE;
}
return (__systemcall(rval, SYS_fdsync + 1024, fd, level));
}
/*
* S10's issetugid() syscall is now a subcode to privsys().
*/
static int
s10_issetugid(sysret_t *rval)
{
return (__systemcall(rval, SYS_privsys + 1024, PRIVSYS_ISSETUGID,
0, 0, 0, 0, 0));
}
/*
* S10's socket() syscall does not split type and flags
*/
static int
s10_so_socket(sysret_t *rval, int domain, int type, int protocol,
char *devpath, int version)
{
if ((type & ~SOCK_TYPE_MASK) != 0) {
errno = EINVAL;
return (-1);
}
return (__systemcall(rval, SYS_so_socket + 1024, domain, type,
protocol, devpath, version));
}
/*
* S10's pipe() syscall has a different calling convention
*/
static int
s10_pipe(sysret_t *rval)
{
int fds[2], err;
if ((err = __systemcall(rval, SYS_pipe + 1024, fds, 0)) != 0)
return (err);
rval->sys_rval1 = fds[0];
rval->sys_rval2 = fds[1];
return (0);
}
/*
* S10's accept() syscall takes three arguments
*/
static int
s10_accept(sysret_t *rval, int sock, struct sockaddr *addr, uint_t *addrlen,
int version)
{
return (__systemcall(rval, SYS_accept + 1024, sock, addr, addrlen,
version, 0));
}
static long
s10_uname(sysret_t *rv, uintptr_t p1)
{
struct utsname un, *unp = (struct utsname *)p1;
int rev, err;
if ((err = __systemcall(rv, SYS_uname + 1024, &un)) != 0)
return (err);
rev = atoi(&un.release[2]);
brand_assert(rev >= 11);
bzero(un.release, _SYS_NMLN);
(void) strlcpy(un.release, S10_UTS_RELEASE, _SYS_NMLN);
bzero(un.version, _SYS_NMLN);
(void) strlcpy(un.version, S10_UTS_VERSION, _SYS_NMLN);
/* copy out the modified uname info */
return (brand_uucopy(&un, unp, sizeof (un)));
}
int
s10_sysconfig(sysret_t *rv, int which)
{
long value;
/*
* We must interpose on the sysconfig(2) requests
* that deal with the realtime signal number range.
* All others get passed to the native sysconfig(2).
*/
switch (which) {
case _CONFIG_RTSIG_MAX:
value = S10_SIGRTMAX - S10_SIGRTMIN + 1;
break;
case _CONFIG_SIGRT_MIN:
value = S10_SIGRTMIN;
break;
case _CONFIG_SIGRT_MAX:
value = S10_SIGRTMAX;
break;
default:
return (__systemcall(rv, SYS_sysconfig + 1024, which));
}
(void) B_TRUSS_POINT_1(rv, SYS_sysconfig, 0, which);
rv->sys_rval1 = value;
rv->sys_rval2 = 0;
return (0);
}
int
s10_sysinfo(sysret_t *rv, int command, char *buf, long count)
{
char *value;
int len;
/*
* We must interpose on the sysinfo(2) commands SI_RELEASE and
* SI_VERSION; all others get passed to the native sysinfo(2)
* command.
*/
switch (command) {
case SI_RELEASE:
value = S10_UTS_RELEASE;
break;
case SI_VERSION:
value = S10_UTS_VERSION;
break;
default:
/*
* The default action is to pass the command to the
* native sysinfo(2) syscall.
*/
return (__systemcall(rv, SYS_systeminfo + 1024,
command, buf, count));
}
len = strlen(value) + 1;
if (count > 0) {
if (brand_uucopystr(value, buf, count) != 0)
return (EFAULT);
/*
* Assure NULL termination of buf as brand_uucopystr() doesn't.
*/
if (len > count && brand_uucopy("\0", buf + (count - 1), 1)
!= 0)
return (EFAULT);
}
/*
* On success, sysinfo(2) returns the size of buffer required to hold
* the complete value plus its terminating NULL byte.
*/
(void) B_TRUSS_POINT_3(rv, SYS_systeminfo, 0, command, buf, count);
rv->sys_rval1 = len;
rv->sys_rval2 = 0;
return (0);
}
#if defined(__x86)
#if defined(__amd64)
/*
* 64-bit x86 LWPs created by SYS_lwp_create start here if they need to set
* their %fs registers to the legacy Solaris 10 selector value.
*
* This function does three things:
*
* 1. Trap to the kernel so that it can set %fs to the legacy Solaris 10
* selector value.
* 2. Read the LWP's true entry point (the entry point supplied by libc
* when SYS_lwp_create was invoked) from %r14.
* 3. Eliminate this function's stack frame and pass control to the LWP's
* true entry point.
*
* See the comment above s10_lwp_create_correct_fs() (see below) for the reason
* why this function exists.
*/
/*ARGSUSED*/
static void
s10_lwp_create_entry_point(void *ulwp_structp)
{
sysret_t rval;
/*
* The new LWP's %fs register is initially zero, but libc won't
* function correctly when %fs is zero. Change the LWP's %fs register
* via SYS_brand.
*/
(void) __systemcall(&rval, SYS_brand + 1024, B_S10_FSREGCORRECTION);
/*
* Jump to the true entry point, which is stored in %r14.
* Remove our stack frame before jumping so that
* s10_lwp_create_entry_point() won't be seen in stack traces.
*
* NOTE: s10_lwp_create_entry_point() pushes %r12 onto its stack frame
* so that it can use it as a temporary register. We don't restore %r12
* in this assembly block because we don't care about its value (and
* neither does _lwp_start()). Besides, the System V ABI AMD64
* Actirecture Processor Supplement doesn't specify that %r12 should
* have a special value when LWPs start, so we can ignore its value when
* we jump to the true entry point. Furthermore, %r12 is a callee-saved
* register, so the true entry point should push %r12 onto its stack
* before using the register. We ignore %r14 after we read it for
* similar reasons.
*
* NOTE: The compiler will generate a function epilogue for this
* function despite the fact that the LWP will never execute it.
* We could hand-code this entire function in assembly to eliminate
* the epilogue, but the epilogue is only three or four instructions,
* so we wouldn't save much space. Besides, why would we want
* to create yet another ugly, hard-to-maintain assembly function when
* we could write most of it in C?
*/
__asm__ __volatile__(
"movq %0, %%rdi\n\t" /* pass ulwp_structp as arg1 */
"movq %%rbp, %%rsp\n\t" /* eliminate the stack frame */
"popq %%rbp\n\t"
"jmp *%%r14\n\t" /* jump to the true entry point */
: : "r" (ulwp_structp));
/*NOTREACHED*/
}
/*
* The S10 libc expects that %fs will be nonzero for new 64-bit x86 LWPs but the
* Nevada kernel clears %fs for such LWPs. Unforunately, new LWPs do not issue
* SYS_lwp_private (see s10_lwp_private() below) after they are created, so
* we must ensure that new LWPs invoke a brand operation that sets %fs to a
* nonzero value immediately after their creation.
*
* The easiest way to do this is to make new LWPs start at a special function,
* s10_lwp_create_entry_point() (see its definition above), that invokes the
* brand operation that corrects %fs. We'll store the entry points of new LWPs
* in their %r14 registers so that s10_lwp_create_entry_point() can find and
* call them after invoking the special brand operation. %r14 is a callee-saved
* register; therefore, any functions invoked by s10_lwp_create_entry_point()
* and all functions dealing with signals (e.g., sigacthandler()) will preserve
* %r14 for s10_lwp_create_entry_point().
*
* The Nevada kernel can safely work with nonzero %fs values because the kernel
* configures per-thread %fs segment descriptors so that the legacy %fs selector
* value will still work. See the comment in lwp_load() regarding %fs and
* %fsbase in 64-bit x86 processes.
*
* This emulation exists thanks to CRs 6467491 and 6501650.
*/
static int
s10_lwp_create_correct_fs(sysret_t *rval, ucontext_t *ucp, int flags,
id_t *new_lwp)
{
ucontext_t s10_uc;
/*
* Copy the supplied ucontext_t structure to the local stack
* frame and store the new LWP's entry point (the value of %rip
* stored in the ucontext_t) in the new LWP's %r14 register.
* Then make s10_lwp_create_entry_point() the new LWP's entry
* point.
*/
if (brand_uucopy(ucp, &s10_uc, sizeof (s10_uc)) != 0)
return (EFAULT);
s10_uc.uc_mcontext.gregs[REG_R14] = s10_uc.uc_mcontext.gregs[REG_RIP];
s10_uc.uc_mcontext.gregs[REG_RIP] = (greg_t)s10_lwp_create_entry_point;
/* fix up the signal mask */
if (s10_uc.uc_flags & UC_SIGMASK)
(void) s10sigset_to_native(&s10_uc.uc_sigmask,
&s10_uc.uc_sigmask);
/*
* Issue SYS_lwp_create to create the new LWP. We pass the
* modified ucontext_t to make sure that the new LWP starts at
* s10_lwp_create_entry_point().
*/
return (__systemcall(rval, SYS_lwp_create + 1024, &s10_uc,
flags, new_lwp));
}
#endif /* __amd64 */
/*
* SYS_lwp_private is issued by libc_init() to set %fsbase in 64-bit x86
* processes. The Nevada kernel sets %fs to zero but the S10 libc expects
* %fs to be nonzero. We'll pass the issued system call to the kernel untouched
* and invoke a brand operation to set %fs to the legacy S10 selector value.
*
* This emulation exists thanks to CRs 6467491 and 6501650.
*/
static int
s10_lwp_private(sysret_t *rval, int cmd, int which, uintptr_t base)
{
#if defined(__amd64)
int err;
/*
* The current LWP's %fs register should be zero. Determine whether the
* Solaris 10 libc with which we're working functions correctly when %fs
* is zero by calling thr_main() after issuing the SYS_lwp_private
* syscall. If thr_main() barfs (returns -1), then change the LWP's %fs
* register via SYS_brand and patch brand_sysent_table so that issuing
* SYS_lwp_create executes s10_lwp_create_correct_fs() rather than the
* default s10_lwp_create(). s10_lwp_create_correct_fs() will
* guarantee that new LWPs will have correct %fs values.
*/
if ((err = __systemcall(rval, SYS_lwp_private + 1024, cmd, which,
base)) != 0)
return (err);
if (thr_main() == -1) {
/*
* SYS_lwp_private is only issued by libc_init(), which is
* executed when libc is first loaded by ld.so.1. Thus we
* are guaranteed to be single-threaded at this point. Even
* if we were multithreaded at this point, writing a 64-bit
* value to the st_callc field of a brand_sysent_table
* entry is guaranteed to be atomic on 64-bit x86 chips
* as long as the field is not split across cache lines
* (It shouldn't be.). See chapter 8, section 1.1 of
* "The Intel 64 and IA32 Architectures Software Developer's
* Manual," Volume 3A for more details.
*/
brand_sysent_table[SYS_lwp_create].st_callc =
(sysent_cb_t)(uintptr_t)s10_lwp_create_correct_fs;
return (__systemcall(rval, SYS_brand + 1024,
B_S10_FSREGCORRECTION));
}
return (0);
#else /* !__amd64 */
return (__systemcall(rval, SYS_lwp_private + 1024, cmd, which, base));
#endif /* !__amd64 */
}
#endif /* __x86 */
/*
* The Opensolaris versions of lwp_mutex_timedlock() and lwp_mutex_trylock()
* add an extra argument to the interfaces, a uintptr_t value for the mutex's
* mutex_owner field. The Solaris 10 libc assigns the mutex_owner field at
* user-level, so we just make the extra argument be zero in both syscalls.
*/
static int
s10_lwp_mutex_timedlock(sysret_t *rval, lwp_mutex_t *lp, timespec_t *tsp)
{
return (__systemcall(rval, SYS_lwp_mutex_timedlock + 1024, lp, tsp, 0));
}
static int
s10_lwp_mutex_trylock(sysret_t *rval, lwp_mutex_t *lp)
{
return (__systemcall(rval, SYS_lwp_mutex_trylock + 1024, lp, 0));
}
/*
* If the emul_global_zone flag is set then emulate some aspects of the
* zone system call. In particular, emulate the global zone ID on the
* ZONE_LOOKUP subcommand and emulate some of the global zone attributes
* on the ZONE_GETATTR subcommand. If the flag is not set or we're performing
* some other operation, simply pass the calls through.
*/
int
s10_zone(sysret_t *rval, int cmd, void *arg1, void *arg2, void *arg3,
void *arg4)
{
char *aval;
int len;
zoneid_t zid;
int attr;
char *buf;
size_t bufsize;
/*
* We only emulate the zone syscall for a subset of specific commands,
* otherwise we just pass the call through.
*/
if (!emul_global_zone)
return (__systemcall(rval, SYS_zone + 1024, cmd, arg1, arg2,
arg3, arg4));
switch (cmd) {
case ZONE_LOOKUP:
(void) B_TRUSS_POINT_1(rval, SYS_zone, 0, cmd);
rval->sys_rval1 = GLOBAL_ZONEID;
rval->sys_rval2 = 0;
return (0);
case ZONE_GETATTR:
zid = (zoneid_t)(uintptr_t)arg1;
attr = (int)(uintptr_t)arg2;
buf = (char *)arg3;
bufsize = (size_t)arg4;
/*
* If the request is for the global zone then we're emulating
* that, otherwise pass this thru.
*/
if (zid != GLOBAL_ZONEID)
goto passthru;
switch (attr) {
case ZONE_ATTR_NAME:
aval = GLOBAL_ZONENAME;
break;
case ZONE_ATTR_BRAND:
aval = NATIVE_BRAND_NAME;
break;
default:
/*
* We only emulate a subset of the attrs, use the
* real zone id to pass thru the rest.
*/
arg1 = (void *)(uintptr_t)zoneid;
goto passthru;
}
(void) B_TRUSS_POINT_5(rval, SYS_zone, 0, cmd, zid, attr,
buf, bufsize);
len = strlen(aval) + 1;
if (len > bufsize)
return (ENAMETOOLONG);
if (buf != NULL) {
if (len == 1) {
if (brand_uucopy("\0", buf, 1) != 0)
return (EFAULT);
} else {
if (brand_uucopystr(aval, buf, len) != 0)
return (EFAULT);
/*
* Assure NULL termination of "buf" as
* brand_uucopystr() does NOT.
*/
if (brand_uucopy("\0", buf + (len - 1), 1) != 0)
return (EFAULT);
}
}
rval->sys_rval1 = len;
rval->sys_rval2 = 0;
return (0);
default:
break;
}
passthru:
return (__systemcall(rval, SYS_zone + 1024, cmd, arg1, arg2, arg3,
arg4));
}
/*ARGSUSED*/
int
brand_init(int argc, char *argv[], char *envp[])
{
sysret_t rval;
ulong_t ldentry;
int err;
char *bname;
brand_pre_init();
/*
* Cache the pid of the zone's init process and determine if
* we're init(8) for the zone. Remember: we might be init
* now, but as soon as we fork(2) we won't be.
*/
(void) get_initpid_info();
/* get the current zoneid */
err = __systemcall(&rval, SYS_zone, ZONE_LOOKUP, NULL);
brand_assert(err == 0);
zoneid = (zoneid_t)rval.sys_rval1;
/* Get the zone's emulation bitmap. */
if ((err = __systemcall(&rval, SYS_zone, ZONE_GETATTR, zoneid,
S10_EMUL_BITMAP, emul_bitmap, sizeof (emul_bitmap))) != 0) {
brand_abort(err, "The zone's patch level is unsupported");
/*NOTREACHED*/
}
bname = basename(argv[0]);
/*
* In general we want the S10 commands that are zone-aware to continue
* to behave as they normally do within a zone. Since these commands
* are zone-aware, they should continue to "do the right thing".
* However, some zone-aware commands aren't going to work the way
* we expect them to inside the branded zone. In particular, the pkg
* and patch commands will not properly manage all pkgs/patches
* unless the commands think they are running in the global zone. For
* these commands we want to emulate the global zone.
*
* We don't do any emulation for pkgcond since it is typically used
* in pkg/patch postinstall scripts and we want those scripts to do
* the right thing inside a zone.
*
* One issue is the handling of hollow pkgs. Since the pkgs are
* hollow, they won't use pkgcond in their postinstall scripts. These
* pkgs typically are installing drivers so we handle that by
* replacing add_drv and rem_drv in the s10_boot script.
*/
if (strcmp("pkgadd", bname) == 0 || strcmp("pkgrm", bname) == 0 ||
strcmp("patchadd", bname) == 0 || strcmp("patchrm", bname) == 0)
emul_global_zone = B_TRUE;
ldentry = brand_post_init(S10_VERSION, argc, argv, envp);
brand_runexe(argv, ldentry);
/*NOTREACHED*/
brand_abort(0, "brand_runexe() returned");
return (-1);
}
/*
* This table must have at least NSYSCALL entries in it.
*
* The second parameter of each entry in the brand_sysent_table
* contains the number of parameters and flags that describe the
* syscall return value encoding. See the block comments at the
* top of this file for more information about the syscall return
* value flags and when they should be used.
*/
brand_sysent_table_t brand_sysent_table[] = {
#if defined(__sparc) && !defined(__sparcv9)
EMULATE(brand_indir, 9 | RV_64RVAL), /* 0 */
#else
NOSYS, /* 0 */
#endif
NOSYS, /* 1 */
EMULATE(s10_forkall, 0 | RV_32RVAL2), /* 2 */
NOSYS, /* 3 */
NOSYS, /* 4 */
EMULATE(s10_open, 3 | RV_DEFAULT), /* 5 */
NOSYS, /* 6 */
EMULATE(s10_wait, 0 | RV_32RVAL2), /* 7 */
EMULATE(s10_creat, 2 | RV_DEFAULT), /* 8 */
EMULATE(s10_link, 2 | RV_DEFAULT), /* 9 */
EMULATE(s10_unlink, 1 | RV_DEFAULT), /* 10 */
EMULATE(s10_exec, 2 | RV_DEFAULT), /* 11 */
NOSYS, /* 12 */
NOSYS, /* 13 */
EMULATE(s10_mknod, 3 | RV_DEFAULT), /* 14 */
EMULATE(s10_chmod, 2 | RV_DEFAULT), /* 15 */
EMULATE(s10_chown, 3 | RV_DEFAULT), /* 16 */
NOSYS, /* 17 */
EMULATE(s10_stat, 2 | RV_DEFAULT), /* 18 */
NOSYS, /* 19 */
NOSYS, /* 20 */
NOSYS, /* 21 */
EMULATE(s10_umount, 1 | RV_DEFAULT), /* 22 */
NOSYS, /* 23 */
NOSYS, /* 24 */
NOSYS, /* 25 */
NOSYS, /* 26 */
NOSYS, /* 27 */
EMULATE(s10_fstat, 2 | RV_DEFAULT), /* 28 */
NOSYS, /* 29 */
EMULATE(s10_utime, 2 | RV_DEFAULT), /* 30 */
NOSYS, /* 31 */
NOSYS, /* 32 */
EMULATE(s10_access, 2 | RV_DEFAULT), /* 33 */
NOSYS, /* 34 */
NOSYS, /* 35 */
NOSYS, /* 36 */
EMULATE(s10_kill, 2 | RV_DEFAULT), /* 37 */
NOSYS, /* 38 */
NOSYS, /* 39 */
NOSYS, /* 40 */
EMULATE(s10_dup, 1 | RV_DEFAULT), /* 41 */
EMULATE(s10_pipe, 0 | RV_32RVAL2), /* 42 */
NOSYS, /* 43 */
NOSYS, /* 44 */
NOSYS, /* 45 */
NOSYS, /* 46 */
NOSYS, /* 47 */
NOSYS, /* 48 */
NOSYS, /* 49 */
NOSYS, /* 50 */
NOSYS, /* 51 */
NOSYS, /* 52 */
NOSYS, /* 53 */
EMULATE(s10_ioctl, 3 | RV_DEFAULT), /* 54 */
NOSYS, /* 55 */
NOSYS, /* 56 */
NOSYS, /* 57 */
EMULATE(s10_fdsync, 2 | RV_DEFAULT), /* 58 */
EMULATE(s10_execve, 3 | RV_DEFAULT), /* 59 */
NOSYS, /* 60 */
NOSYS, /* 61 */
EMULATE(s10_fcntl, 3 | RV_DEFAULT), /* 62 */
NOSYS, /* 63 */
NOSYS, /* 64 */
NOSYS, /* 65 */
NOSYS, /* 66 */
NOSYS, /* 67 */
NOSYS, /* 68 */
NOSYS, /* 69 */
NOSYS, /* 70 */
EMULATE(s10_acctctl, 3 | RV_DEFAULT), /* 71 */
NOSYS, /* 72 */
NOSYS, /* 73 */
NOSYS, /* 74 */
EMULATE(s10_issetugid, 0 | RV_DEFAULT), /* 75 */
EMULATE(s10_fsat, 6 | RV_DEFAULT), /* 76 */
NOSYS, /* 77 */
NOSYS, /* 78 */
EMULATE(s10_rmdir, 1 | RV_DEFAULT), /* 79 */
EMULATE(s10_mkdir, 2 | RV_DEFAULT), /* 80 */
EMULATE(s10_getdents, 3 | RV_DEFAULT), /* 81 */
NOSYS, /* 82 */
NOSYS, /* 83 */
NOSYS, /* 84 */
NOSYS, /* 85 */
NOSYS, /* 86 */
EMULATE(s10_poll, 3 | RV_DEFAULT), /* 87 */
EMULATE(s10_lstat, 2 | RV_DEFAULT), /* 88 */
EMULATE(s10_symlink, 2 | RV_DEFAULT), /* 89 */
EMULATE(s10_readlink, 3 | RV_DEFAULT), /* 90 */
NOSYS, /* 91 */
NOSYS, /* 92 */
EMULATE(s10_fchmod, 2 | RV_DEFAULT), /* 93 */
EMULATE(s10_fchown, 3 | RV_DEFAULT), /* 94 */
EMULATE(s10_sigprocmask, 3 | RV_DEFAULT), /* 95 */
EMULATE(s10_sigsuspend, 1 | RV_DEFAULT), /* 96 */
NOSYS, /* 97 */
EMULATE(s10_sigaction, 3 | RV_DEFAULT), /* 98 */
EMULATE(s10_sigpending, 2 | RV_DEFAULT), /* 99 */
NOSYS, /* 100 */
NOSYS, /* 101 */
NOSYS, /* 102 */
NOSYS, /* 103 */
NOSYS, /* 104 */
NOSYS, /* 105 */
NOSYS, /* 106 */
EMULATE(s10_waitid, 4 | RV_DEFAULT), /* 107 */
EMULATE(s10_sigsendsys, 2 | RV_DEFAULT), /* 108 */
NOSYS, /* 109 */
NOSYS, /* 110 */
NOSYS, /* 111 */
NOSYS, /* 112 */
NOSYS, /* 113 */
NOSYS, /* 114 */
NOSYS, /* 115 */
NOSYS, /* 116 */
NOSYS, /* 117 */
NOSYS, /* 118 */
NOSYS, /* 119 */
NOSYS, /* 120 */
NOSYS, /* 121 */
NOSYS, /* 122 */
#if defined(__x86)
EMULATE(s10_xstat, 3 | RV_DEFAULT), /* 123 */
EMULATE(s10_lxstat, 3 | RV_DEFAULT), /* 124 */
EMULATE(s10_fxstat, 3 | RV_DEFAULT), /* 125 */
EMULATE(s10_xmknod, 4 | RV_DEFAULT), /* 126 */
#else
NOSYS, /* 123 */
NOSYS, /* 124 */
NOSYS, /* 125 */
NOSYS, /* 126 */
#endif
NOSYS, /* 127 */
NOSYS, /* 128 */
NOSYS, /* 129 */
EMULATE(s10_lchown, 3 | RV_DEFAULT), /* 130 */
NOSYS, /* 131 */
NOSYS, /* 132 */
NOSYS, /* 133 */
EMULATE(s10_rename, 2 | RV_DEFAULT), /* 134 */
EMULATE(s10_uname, 1 | RV_DEFAULT), /* 135 */
NOSYS, /* 136 */
EMULATE(s10_sysconfig, 1 | RV_DEFAULT), /* 137 */
NOSYS, /* 138 */
EMULATE(s10_sysinfo, 3 | RV_DEFAULT), /* 139 */
NOSYS, /* 140 */
NOSYS, /* 141 */
NOSYS, /* 142 */
EMULATE(s10_fork1, 0 | RV_32RVAL2), /* 143 */
EMULATE(s10_sigtimedwait, 3 | RV_DEFAULT), /* 144 */
NOSYS, /* 145 */
NOSYS, /* 146 */
EMULATE(s10_lwp_sema_wait, 1 | RV_DEFAULT), /* 147 */
NOSYS, /* 148 */
NOSYS, /* 149 */
NOSYS, /* 150 */
NOSYS, /* 151 */
NOSYS, /* 152 */
NOSYS, /* 153 */
EMULATE(s10_utimes, 2 | RV_DEFAULT), /* 154 */
NOSYS, /* 155 */
NOSYS, /* 156 */
NOSYS, /* 157 */
NOSYS, /* 158 */
EMULATE(s10_lwp_create, 3 | RV_DEFAULT), /* 159 */
NOSYS, /* 160 */
NOSYS, /* 161 */
NOSYS, /* 162 */
EMULATE(s10_lwp_kill, 2 | RV_DEFAULT), /* 163 */
NOSYS, /* 164 */
EMULATE(s10_lwp_sigmask, 3 | RV_32RVAL2), /* 165 */
#if defined(__x86)
EMULATE(s10_lwp_private, 3 | RV_DEFAULT), /* 166 */
#else
NOSYS, /* 166 */
#endif
NOSYS, /* 167 */
NOSYS, /* 168 */
EMULATE(s10_lwp_mutex_lock, 1 | RV_DEFAULT), /* 169 */
NOSYS, /* 170 */
NOSYS, /* 171 */
NOSYS, /* 172 */
NOSYS, /* 173 */
EMULATE(s10_pwrite, 4 | RV_DEFAULT), /* 174 */
NOSYS, /* 175 */
NOSYS, /* 176 */
NOSYS, /* 177 */
NOSYS, /* 178 */
NOSYS, /* 179 */
NOSYS, /* 180 */
NOSYS, /* 181 */
NOSYS, /* 182 */
NOSYS, /* 183 */
NOSYS, /* 184 */
EMULATE(s10_acl, 4 | RV_DEFAULT), /* 185 */
EMULATE(s10_auditsys, 4 | RV_64RVAL), /* 186 */
NOSYS, /* 187 */
NOSYS, /* 188 */
NOSYS, /* 189 */
EMULATE(s10_sigqueue, 4 | RV_DEFAULT), /* 190 */
NOSYS, /* 191 */
NOSYS, /* 192 */
NOSYS, /* 193 */
NOSYS, /* 194 */
NOSYS, /* 195 */
NOSYS, /* 196 */
NOSYS, /* 197 */
NOSYS, /* 198 */
NOSYS, /* 199 */
EMULATE(s10_facl, 4 | RV_DEFAULT), /* 200 */
NOSYS, /* 201 */
NOSYS, /* 202 */
NOSYS, /* 203 */
NOSYS, /* 204 */
EMULATE(s10_signotify, 3 | RV_DEFAULT), /* 205 */
NOSYS, /* 206 */
NOSYS, /* 207 */
NOSYS, /* 208 */
NOSYS, /* 209 */
EMULATE(s10_lwp_mutex_timedlock, 2 | RV_DEFAULT), /* 210 */
NOSYS, /* 211 */
NOSYS, /* 212 */
#if defined(_LP64)
NOSYS, /* 213 */
#else
EMULATE(s10_getdents64, 3 | RV_DEFAULT), /* 213 */
#endif
NOSYS, /* 214 */
#if defined(_LP64)
NOSYS, /* 215 */
NOSYS, /* 216 */
NOSYS, /* 217 */
#else
EMULATE(s10_stat64, 2 | RV_DEFAULT), /* 215 */
EMULATE(s10_lstat64, 2 | RV_DEFAULT), /* 216 */
EMULATE(s10_fstat64, 2 | RV_DEFAULT), /* 217 */
#endif
NOSYS, /* 218 */
NOSYS, /* 219 */
NOSYS, /* 220 */
NOSYS, /* 221 */
NOSYS, /* 222 */
#if defined(_LP64)
NOSYS, /* 223 */
NOSYS, /* 224 */
NOSYS, /* 225 */
#else
EMULATE(s10_pwrite64, 5 | RV_DEFAULT), /* 223 */
EMULATE(s10_creat64, 2 | RV_DEFAULT), /* 224 */
EMULATE(s10_open64, 3 | RV_DEFAULT), /* 225 */
#endif
NOSYS, /* 226 */
EMULATE(s10_zone, 5 | RV_DEFAULT), /* 227 */
NOSYS, /* 228 */
NOSYS, /* 229 */
EMULATE(s10_so_socket, 5 | RV_DEFAULT), /* 230 */
NOSYS, /* 231 */
NOSYS, /* 232 */
NOSYS, /* 233 */
EMULATE(s10_accept, 4 | RV_DEFAULT), /* 234 */
NOSYS, /* 235 */
NOSYS, /* 236 */
NOSYS, /* 237 */
NOSYS, /* 238 */
NOSYS, /* 239 */
NOSYS, /* 240 */
NOSYS, /* 241 */
NOSYS, /* 242 */
NOSYS, /* 243 */
NOSYS, /* 244 */
NOSYS, /* 245 */
NOSYS, /* 246 */
NOSYS, /* 247 */
NOSYS, /* 248 */
NOSYS, /* 249 */
NOSYS, /* 250 */
EMULATE(s10_lwp_mutex_trylock, 1 | RV_DEFAULT), /* 251 */
NOSYS, /* 252 */
NOSYS, /* 253 */
NOSYS, /* 254 */
NOSYS /* 255 */
};
/*
* 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) 2010, Oracle and/or its affiliates. All rights reserved.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <utime.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/poll.h>
#include <sys/file.h>
#include <sys/syscall.h>
#include <s10_brand.h>
#include <brand_misc.h>
#include <s10_misc.h>
/*
* This file contains the emulation functions for all of the
* obsolete system call traps that existed in Solaris 10 but
* that have been deleted in the current version of Solaris.
*/
static int
s10_fstatat(sysret_t *rval,
int fd, const char *path, struct stat *sb, int flags)
{
return (__systemcall(rval, SYS_fstatat + 1024,
fd, path, sb, flags));
}
int
s10_stat(sysret_t *rval, const char *path, struct stat *sb)
{
return (__systemcall(rval, SYS_fstatat + 1024,
AT_FDCWD, path, sb, 0));
}
int
s10_lstat(sysret_t *rval, const char *path, struct stat *sb)
{
return (__systemcall(rval, SYS_fstatat + 1024,
AT_FDCWD, path, sb, AT_SYMLINK_NOFOLLOW));
}
int
s10_fstat(sysret_t *rval, int filedes, struct stat *sb)
{
return (__systemcall(rval, SYS_fstatat + 1024,
filedes, NULL, sb, 0));
}
#if !defined(_LP64)
static int
s10_fstatat64(sysret_t *rval,
int fd, const char *path, struct stat64 *sb, int flags)
{
return (__systemcall(rval, SYS_fstatat64 + 1024,
fd, path, sb, flags));
}
int
s10_stat64(sysret_t *rval, const char *path, struct stat64 *sb)
{
return (__systemcall(rval, SYS_fstatat64 + 1024,
AT_FDCWD, path, sb, 0));
}
int
s10_lstat64(sysret_t *rval, const char *path, struct stat64 *sb)
{
return (__systemcall(rval, SYS_fstatat64 + 1024,
AT_FDCWD, path, sb, AT_SYMLINK_NOFOLLOW));
}
int
s10_fstat64(sysret_t *rval, int filedes, struct stat64 *sb)
{
return (__systemcall(rval, SYS_fstatat64 + 1024,
filedes, NULL, sb, 0));
}
#endif /* !_LP64 */
static int
s10_openat(sysret_t *rval, int fd, const char *path, int oflag, mode_t mode)
{
return (__systemcall(rval, SYS_openat + 1024,
fd, path, oflag, mode));
}
int
s10_open(sysret_t *rval, char *path, int oflag, mode_t mode)
{
return (__systemcall(rval, SYS_openat + 1024,
AT_FDCWD, path, oflag, mode));
}
int
s10_creat(sysret_t *rval, char *path, mode_t mode)
{
return (__systemcall(rval, SYS_openat + 1024,
AT_FDCWD, path, O_WRONLY | O_CREAT | O_TRUNC, mode));
}
#if !defined(_LP64)
static int
s10_openat64(sysret_t *rval, int fd, const char *path, int oflag, mode_t mode)
{
return (__systemcall(rval, SYS_openat64 + 1024,
fd, path, oflag, mode));
}
int
s10_open64(sysret_t *rval, char *path, int oflag, mode_t mode)
{
return (__systemcall(rval, SYS_openat64 + 1024,
AT_FDCWD, path, oflag, mode));
}
int
s10_creat64(sysret_t *rval, char *path, mode_t mode)
{
return (__systemcall(rval, SYS_openat64 + 1024,
AT_FDCWD, path, O_WRONLY | O_CREAT | O_TRUNC, mode));
}
#endif /* !_LP64 */
int
s10_fork1(sysret_t *rval)
{
return (__systemcall(rval, SYS_forksys + 1024, 0, 0));
}
int
s10_forkall(sysret_t *rval)
{
return (__systemcall(rval, SYS_forksys + 1024, 1, 0));
}
int
s10_dup(sysret_t *rval, int fd)
{
return (__systemcall(rval, SYS_fcntl + 1024, fd, F_DUPFD, 0, 0));
}
int
s10_poll(sysret_t *rval, struct pollfd *fds, nfds_t nfd, int timeout)
{
timespec_t ts;
timespec_t *tsp;
if (timeout < 0)
tsp = NULL;
else {
ts.tv_sec = timeout / MILLISEC;
ts.tv_nsec = (timeout % MILLISEC) * MICROSEC;
tsp = &ts;
}
return (__systemcall(rval, SYS_pollsys + 1024,
fds, nfd, tsp, NULL));
}
int
s10_lwp_mutex_lock(sysret_t *rval, void *mp)
{
return (__systemcall(rval, SYS_lwp_mutex_timedlock + 1024,
mp, NULL, 0));
}
int
s10_lwp_sema_wait(sysret_t *rval, void *sp)
{
return (__systemcall(rval, SYS_lwp_sema_timedwait + 1024,
sp, NULL, 0));
}
int
s10_chmod(sysret_t *rval, const char *name, mode_t mode)
{
return (__systemcall(rval, SYS_fchmodat + 1024,
AT_FDCWD, name, mode, 0));
}
int
s10_fchmod(sysret_t *rval, int filedes, mode_t mode)
{
return (__systemcall(rval, SYS_fchmodat + 1024,
filedes, NULL, mode, 0));
}
static int
s10_fchownat(sysret_t *rval,
int fd, const char *name, uid_t uid, gid_t gid, int flag)
{
return (__systemcall(rval, SYS_fchownat + 1024,
fd, name, uid, gid, flag));
}
int
s10_chown(sysret_t *rval, const char *name, uid_t uid, gid_t gid)
{
return (__systemcall(rval, SYS_fchownat + 1024,
AT_FDCWD, name, uid, gid, 0));
}
int
s10_lchown(sysret_t *rval, const char *name, uid_t uid, gid_t gid)
{
return (__systemcall(rval, SYS_fchownat + 1024,
AT_FDCWD, name, uid, gid, AT_SYMLINK_NOFOLLOW));
}
int
s10_fchown(sysret_t *rval, int filedes, uid_t uid, gid_t gid)
{
return (__systemcall(rval, SYS_fchownat + 1024,
filedes, NULL, uid, gid, 0));
}
int
s10_mkdir(sysret_t *rval, const char *dname, int dmode)
{
return (__systemcall(rval, SYS_mkdirat + 1024,
AT_FDCWD, dname, dmode));
}
int
s10_mknod(sysret_t *rval, const char *fname, int fmode, dev_t dev)
{
return (__systemcall(rval, SYS_mknodat + 1024,
AT_FDCWD, fname, fmode, dev));
}
int
s10_link(sysret_t *rval, const char *path1, const char *path2)
{
return (__systemcall(rval, SYS_linkat + 1024,
AT_FDCWD, path1, AT_FDCWD, path2, 0));
}
static int
s10_unlinkat(sysret_t *rval, int fd, const char *name, int flags)
{
return (__systemcall(rval, SYS_unlinkat + 1024,
fd, name, flags));
}
int
s10_unlink(sysret_t *rval, const char *name)
{
return (__systemcall(rval, SYS_unlinkat + 1024,
AT_FDCWD, name, 0));
}
int
s10_rmdir(sysret_t *rval, const char *name)
{
return (__systemcall(rval, SYS_unlinkat + 1024,
AT_FDCWD, name, AT_REMOVEDIR));
}
static int
s10_renameat(sysret_t *rval,
int oldfd, const char *oldname, int newfd, const char *newname)
{
return (__systemcall(rval, SYS_renameat + 1024,
oldfd, oldname, newfd, newname));
}
int
s10_rename(sysret_t *rval, const char *oldname, const char *newname)
{
return (__systemcall(rval, SYS_renameat + 1024,
AT_FDCWD, oldname, AT_FDCWD, newname));
}
int
s10_symlink(sysret_t *rval, const char *path1, const char *path2)
{
return (__systemcall(rval, SYS_symlinkat + 1024,
path1, AT_FDCWD, path2));
}
int
s10_readlink(sysret_t *rval, const char *path, char *buf, size_t bufsize)
{
return (__systemcall(rval, SYS_readlinkat + 1024,
AT_FDCWD, path, buf, bufsize));
}
static int
s10_faccessat(sysret_t *rval, int fd, const char *fname, int amode, int flag)
{
return (__systemcall(rval, SYS_faccessat + 1024,
fd, fname, amode, flag));
}
int
s10_access(sysret_t *rval, const char *fname, int amode)
{
return (__systemcall(rval, SYS_faccessat + 1024,
AT_FDCWD, fname, amode, 0));
}
int
s10_utime(sysret_t *rval, const char *path, const struct utimbuf *times)
{
struct utimbuf ltimes;
timespec_t ts[2];
timespec_t *tsp;
if (times == NULL) {
tsp = NULL;
} else {
if (brand_uucopy(times, <imes, sizeof (ltimes)) != 0)
return (EFAULT);
ts[0].tv_sec = ltimes.actime;
ts[0].tv_nsec = 0;
ts[1].tv_sec = ltimes.modtime;
ts[1].tv_nsec = 0;
tsp = ts;
}
return (__systemcall(rval, SYS_utimesys + 1024, 1,
AT_FDCWD, path, tsp, 0));
}
int
s10_utimes(sysret_t *rval, const char *path, const struct timeval times[2])
{
struct timeval ltimes[2];
timespec_t ts[2];
timespec_t *tsp;
if (times == NULL) {
tsp = NULL;
} else {
if (brand_uucopy(times, ltimes, sizeof (ltimes)) != 0)
return (EFAULT);
ts[0].tv_sec = ltimes[0].tv_sec;
ts[0].tv_nsec = ltimes[0].tv_usec * 1000;
ts[1].tv_sec = ltimes[1].tv_sec;
ts[1].tv_nsec = ltimes[1].tv_usec * 1000;
tsp = ts;
}
return (__systemcall(rval, SYS_utimesys + 1024, 1,
AT_FDCWD, path, tsp, 0));
}
static int
s10_futimesat(sysret_t *rval,
int fd, const char *path, const struct timeval times[2])
{
struct timeval ltimes[2];
timespec_t ts[2];
timespec_t *tsp;
if (times == NULL) {
tsp = NULL;
} else {
if (brand_uucopy(times, ltimes, sizeof (ltimes)) != 0)
return (EFAULT);
ts[0].tv_sec = ltimes[0].tv_sec;
ts[0].tv_nsec = ltimes[0].tv_usec * 1000;
ts[1].tv_sec = ltimes[1].tv_sec;
ts[1].tv_nsec = ltimes[1].tv_usec * 1000;
tsp = ts;
}
if (path == NULL)
return (__systemcall(rval, SYS_utimesys + 1024, 0, fd, tsp));
return (__systemcall(rval, SYS_utimesys + 1024, 1, fd, path, tsp, 0));
}
#if defined(__x86)
/* ARGSUSED */
int
s10_xstat(sysret_t *rval, int version, const char *path, struct stat *statb)
{
#if defined(__amd64)
return (EINVAL);
#else
if (version != _STAT_VER)
return (EINVAL);
return (__systemcall(rval, SYS_fstatat + 1024,
AT_FDCWD, path, statb, 0));
#endif
}
/* ARGSUSED */
int
s10_lxstat(sysret_t *rval, int version, const char *path, struct stat *statb)
{
#if defined(__amd64)
return (EINVAL);
#else
if (version != _STAT_VER)
return (EINVAL);
return (__systemcall(rval, SYS_fstatat + 1024,
AT_FDCWD, path, statb, AT_SYMLINK_NOFOLLOW));
#endif
}
/* ARGSUSED */
int
s10_fxstat(sysret_t *rval, int version, int fd, struct stat *statb)
{
#if defined(__amd64)
return (EINVAL);
#else
if (version != _STAT_VER)
return (EINVAL);
return (__systemcall(rval, SYS_fstatat + 1024,
fd, NULL, statb, 0));
#endif
}
/* ARGSUSED */
int
s10_xmknod(sysret_t *rval, int version, const char *path,
mode_t mode, dev_t dev)
{
#if defined(__amd64)
return (EINVAL);
#else
if (version != _MKNOD_VER)
return (EINVAL);
return (__systemcall(rval, SYS_mknodat + 1024,
AT_FDCWD, path, mode, dev));
#endif
}
#endif /* __x86 */
/*
* This is the fsat() system call trap in s10.
* It has been removed in the current system.
*/
int
s10_fsat(sysret_t *rval,
int code, uintptr_t arg1, uintptr_t arg2,
uintptr_t arg3, uintptr_t arg4, uintptr_t arg5)
{
switch (code) {
case 0: /* openat */
return (s10_openat(rval, (int)arg1,
(const char *)arg2, (int)arg3, (mode_t)arg4));
case 1: /* openat64 */
#if defined(_LP64)
return (EINVAL);
#else
return (s10_openat64(rval, (int)arg1,
(const char *)arg2, (int)arg3, (mode_t)arg4));
#endif
case 2: /* fstatat64 */
#if defined(_LP64)
return (EINVAL);
#else
return (s10_fstatat64(rval, (int)arg1,
(const char *)arg2, (struct stat64 *)arg3, (int)arg4));
#endif
case 3: /* fstatat */
return (s10_fstatat(rval, (int)arg1,
(const char *)arg2, (struct stat *)arg3, (int)arg4));
case 4: /* fchownat */
return (s10_fchownat(rval, (int)arg1, (char *)arg2,
(uid_t)arg3, (gid_t)arg4, (int)arg5));
case 5: /* unlinkat */
return (s10_unlinkat(rval, (int)arg1, (char *)arg2,
(int)arg3));
case 6: /* futimesat */
return (s10_futimesat(rval, (int)arg1,
(const char *)arg2, (const struct timeval *)arg3));
case 7: /* renameat */
return (s10_renameat(rval, (int)arg1, (char *)arg2,
(int)arg3, (char *)arg4));
case 8: /* faccessat */
return (s10_faccessat(rval, (int)arg1, (char *)arg2,
(int)arg3, (int)arg4));
case 9: /* openattrdirat */
return (s10_openat(rval, (int)arg1,
(const char *)arg2, FXATTRDIROPEN, 0));
}
return (EINVAL);
}
/*
* Interposition upon SYS_umount
*/
int
s10_umount(sysret_t *rval, const char *path)
{
return (__systemcall(rval, SYS_umount2 + 1024, path, 0));
}
/*
* 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) 2010, Oracle and/or its affiliates. All rights reserved.
*/
#include <sys/types.h>
#include <sys/brand.h>
#include <sys/errno.h>
#include <sys/sysconfig.h>
#include <sys/ucontext.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <strings.h>
#include <signal.h>
#include <s10_brand.h>
#include <brand_misc.h>
#include <s10_misc.h>
#include <s10_signal.h>
s10_sighandler_t s10_handlers[S10_NSIG - 1];
/*
* Theory of operation:
*
* As of now, Solaris 10 and solaris_nevada signal numbers match all the
* way through SIGJVM2 (1 - 40) and the first 8 realtime signals (41 - 48).
* However, solaris_nevada provides 32 realtime signals rather than 8 for S10.
*
* We do not assume that the current range of realtime signals is
* _SIGRTMIN - _SIGRTMAX. As a hedge against future changes,
* we obtain the realtime signal range via SIGRTMIN and SIGRTMAX.
*
* Therefore, we must interpose on the various signal calls to translate
* signal masks and signal handlers that deal with SIGRTMIN - SIGRTMAX to
* refer to a potentially different range and to intercenpt any "illegal"
* signals that might otherwise be sent to an S10 process.
*
* Important exception:
* We cannot interpose on the SYS_context system call in order to deal with the
* sigset_t contained within the ucontext_t structure because the getcontext()
* part of this system call trap would then return an incorrect set of machine
* registers. See the getcontext() functions in libc to get the gory details.
* The kernel code for getcontext() and setcontext() has been made brand-aware
* in order to deal with this.
*
* Simple translation is all that is required to handle most system calls,
* but signal handlers also must be interposed upon so that a user signal
* handler sees proper signal numbers in its arguments, any passed siginfo_t
* and in the signal mask reported in its ucontext_t.
*
* libc adds its own signal handler to handled signals such that the
* signal delivery mechanism looks like:
*
* signal ->
* libc sigacthandler() ->
* user signal handler()
*
* With interposition, this will instead look like:
*
* signal ->
* s10_sigacthandler() ->
* libc sigacthandler() ->
* user signal handler()
*/
/*
* A little exposition on SIGRTMIN and SIGRTMAX:
*
* For configurability reasons, in Solaris SIGRTMIN and SIGRTMAX are actually
* #defined to be routines:
*
* #define SIGRTMIN ((int)_sysconf(_SC_SIGRT_MIN))
* #define SIGRTMAX ((int)_sysconf(_SC_SIGRT_MAX))
*
* This means we need routines that will call the native sysconfig() system
* call to find out what the native values for SIGRTMIN and SIGRTMAX are, and
* those are native_sigrtmin() and native_sigrtmax(), respectively.
*
* To try and mitigate confusion this might cause, rather than use SIGRTMIN and
* SIGRTMAX directly, mnemonic convenience macros are #defined to clarify the
* matter:
*
* S10_SIGRTMIN
* S10_SIGRTMAX
* NATIVE_SIGRTMIN
* NATIVE_SIGRTMAX
*/
static int
native_sigrtmin()
{
static int sigrtmin;
sysret_t rval;
if (sigrtmin)
return (sigrtmin);
sigrtmin = __systemcall(&rval, SYS_sysconfig + 1024, _CONFIG_SIGRT_MIN)?
_SIGRTMIN : (int)rval.sys_rval1;
return (sigrtmin);
}
static int
native_sigrtmax()
{
static int sigrtmax;
sysret_t rval;
if (sigrtmax)
return (sigrtmax);
sigrtmax = __systemcall(&rval, SYS_sysconfig + 1024, _CONFIG_SIGRT_MAX)?
_SIGRTMAX : (int)rval.sys_rval1;
return (sigrtmax);
}
#define NATIVE_SIGRTMIN (native_sigrtmin())
#define NATIVE_SIGRTMAX (native_sigrtmax())
/*
* These #defines are setup to create the SIGADDSET and SIGISMEMBER macros,
* needed because the sigaddset(3C) and sigismember(3C) calls make function
* calls that end up being recursive in an interpositioned system call
* environment.
*/
#define MAXBITNO (NBPW*8)
#define SIGWORD(n) ((n-1)/MAXBITNO)
#define BITMASK(n) (1L<<((n-1)%MAXBITNO))
#define SIGADDSET(sigset, sig) \
((sigset)->__sigbits[SIGWORD(sig)] |= BITMASK(sig))
#define SIGISMEMBER(sigset, sig) \
(((sigset)->__sigbits[SIGWORD(sig)] & BITMASK(sig)) != 0)
/*
* Convert an S10 signal number to its native value.
*/
static int
s10sig_to_native(int sig)
{
/* signals 1 .. SIGJVM2 are the same between S10 and native */
if (sig <= SIGJVM2)
return (sig);
/*
* If a signal is > SIGJVM2 but is < S10_SIGRTMIN, it's being used
* for some private purpose we likely wouldn't emulate properly.
*/
if (sig < S10_SIGRTMIN) /* can't happen */
return (-1);
/*
* If an app passes in a signal that is out of range, it
* expects to get back EINVAL.
*/
if (sig > S10_MAXSIG)
return (-1);
/*
* Map S10 RT signals to their native counterparts to the degree
* possible. If the signal would be out of the native RT signal
* range, return an error to the caller.
*/
sig -= S10_SIGRTMIN;
if (sig > (NATIVE_SIGRTMAX - NATIVE_SIGRTMIN))
return (-1);
return (NATIVE_SIGRTMIN + sig);
}
/*
* Convert an S10 sigset_t to its native version.
*/
int
s10sigset_to_native(const sigset_t *s10_set, sigset_t *native_set)
{
int sig;
int nativesig;
sigset_t srcset, newset;
if (brand_uucopy(s10_set, &srcset, sizeof (sigset_t)) != 0)
return (EFAULT);
(void) sigemptyset(&newset);
/*
* Shortcut: we know the first 32 signals are the same in both
* s10 and native Solaris. Just assign the first word.
*/
newset.__sigbits[0] = srcset.__sigbits[0];
/*
* Copy the remainder of the initial set of common signals.
*/
for (sig = 33; sig <= SIGJVM2; sig++)
if (SIGISMEMBER(&srcset, sig))
SIGADDSET(&newset, sig);
/* convert any S10 RT signals to their native equivalents */
for (sig = S10_SIGRTMIN; sig <= S10_SIGRTMAX; sig++) {
if (SIGISMEMBER(&srcset, sig) &&
(nativesig = s10sig_to_native(sig)) > 0)
SIGADDSET(&newset, nativesig);
}
if (brand_uucopy(&newset, native_set, sizeof (sigset_t)) != 0)
return (EFAULT);
return (0);
}
/*
* Convert a native signal number to its S10 value.
*/
int
nativesig_to_s10(int sig)
{
/* signals 1 .. SIGJVM2 are the same between native and S10 */
if (sig <= SIGJVM2)
return (sig);
/*
* We have no way to emulate native signals between (SIGJVM2 + 1) and
* NATIVE_SIGRTMIN, so return an error to the caller.
*/
if (sig < NATIVE_SIGRTMIN) /* can't happen */
return (-1);
/*
* Map native RT signals to their S10 counterparts to the degree
* possible. If the signal would be out of range for S10, return
* an error to the caller.
*/
sig -= NATIVE_SIGRTMIN;
if (sig > (S10_SIGRTMAX - S10_SIGRTMIN))
return (-1);
return (S10_SIGRTMIN + sig);
}
/*
* Convert a native sigset_t to its S10 version.
*/
int
nativesigset_to_s10(const sigset_t *native_set, sigset_t *s10_set)
{
int sig;
int s10sig;
sigset_t srcset, newset;
if (brand_uucopy(native_set, &srcset, sizeof (sigset_t)) != 0)
return (EFAULT);
(void) sigemptyset(&newset);
/*
* Shortcut: we know the first 32 signals are the same in both
* s10 and native Solaris. Just assign the first word.
*/
newset.__sigbits[0] = srcset.__sigbits[0];
/*
* Copy the remainder of the initial set of common signals.
*/
for (sig = 33; sig <= SIGJVM2; sig++)
if (SIGISMEMBER(&srcset, sig))
SIGADDSET(&newset, sig);
/* convert any RT signals to their S10 values */
for (sig = NATIVE_SIGRTMIN; sig <= NATIVE_SIGRTMAX; sig++) {
if (SIGISMEMBER(&srcset, sig) &&
(s10sig = nativesig_to_s10(sig)) > 0)
SIGADDSET(&newset, s10sig);
}
if (brand_uucopy(&newset, s10_set, sizeof (sigset_t)) != 0)
return (EFAULT);
return (0);
}
/*
* This is our interposed signal handler.
* Fix up the arguments received from the kernel and jump
* to the s10 signal handler, normally libc's sigacthandler().
*/
static void
s10_sigacthandler(int sig, siginfo_t *sip, void *uvp)
{
int s10_sig;
ucontext_t *ucp;
s10_sig = nativesig_to_s10(sig);
if (s10_sig <= 0) /* can't happen? */
brand_abort(sig, "Received an impossible signal");
if (sip != NULL) {
/*
* All we really have to do is map the signal number,
* which changes only for the realtime signals,
* so all the rest of the siginfo structure is the
* same between s10 and native.
*/
if (sip->si_signo != sig) /* can't happen? */
brand_abort(sig, "Received an impossible siginfo");
sip->si_signo = s10_sig;
}
if ((ucp = uvp) != NULL &&
(ucp->uc_flags & UC_SIGMASK))
(void) nativesigset_to_s10(&ucp->uc_sigmask, &ucp->uc_sigmask);
s10_handlers[s10_sig - 1](s10_sig, sip, uvp);
}
/*
* Interposition upon SYS_lwp_sigmask
*/
int
s10_lwp_sigmask(sysret_t *rval, int how, uint_t bits0, uint_t bits1)
{
sigset_t s10_blockset;
sigset_t native_blockset;
int err;
s10_blockset.__sigbits[0] = bits0;
s10_blockset.__sigbits[1] = bits1;
s10_blockset.__sigbits[2] = 0;
s10_blockset.__sigbits[3] = 0;
(void) s10sigset_to_native(&s10_blockset, &native_blockset);
err = __systemcall(rval, SYS_lwp_sigmask + 1024,
how,
native_blockset.__sigbits[0],
native_blockset.__sigbits[1],
native_blockset.__sigbits[2],
native_blockset.__sigbits[3]);
if (err != 0)
return (err);
native_blockset.__sigbits[0] = (int)rval->sys_rval1;
native_blockset.__sigbits[1] = (int)rval->sys_rval2;
native_blockset.__sigbits[2] = 0;
native_blockset.__sigbits[3] = 0;
(void) nativesigset_to_s10(&native_blockset, &s10_blockset);
rval->sys_rval1 = s10_blockset.__sigbits[0];
rval->sys_rval2 = s10_blockset.__sigbits[1];
return (0);
}
/*
* Interposition upon SYS_sigprocmask
*/
int
s10_sigprocmask(sysret_t *rval, int how, const sigset_t *set, sigset_t *oset)
{
sigset_t sigset_set, sigset_oset;
sigset_t *set_ptr, *oset_ptr;
int err;
oset_ptr = (oset == NULL) ? NULL : &sigset_oset;
set_ptr = (set == NULL) ? NULL : &sigset_set;
if (set_ptr != NULL &&
(err = s10sigset_to_native(set, set_ptr)) != 0)
return (err);
if ((err = __systemcall(rval, SYS_sigprocmask + 1024,
how, set_ptr, oset_ptr)) != 0)
return (err);
if (oset_ptr != NULL &&
(err = nativesigset_to_s10(oset_ptr, oset)) != 0)
return (err);
return (0);
}
/*
* Interposition upon SYS_sigsuspend
*/
int
s10_sigsuspend(sysret_t *rval, const sigset_t *set)
{
sigset_t sigset_set;
int err;
if ((err = s10sigset_to_native(set, &sigset_set)) != 0) {
(void) B_TRUSS_POINT_1(rval, SYS_sigsuspend, err, set);
return (err);
}
return (__systemcall(rval, SYS_sigsuspend + 1024, &sigset_set));
}
/*
* Interposition upon SYS_sigaction
*
* There is a fair amount of complexity here due to the need to interpose
* on any registered user signal handler.
*
* The idea is that if a user signal handler is installed, we must install
* our own signal handler between the system and the signal handler being
* registered. If the signal handler to be registered is SIG_DFL or SIG_IGN,
* we should remove our interpositioned handler as it's no longer needed.
*
* The way we do this is we set the signal handler to call s10_sigacthandler(),
* and then store the address of the passed signal handler in a global
* per-process array, s10_handlers[].
*
* We rely on the fact that the s10 libc blocks all signals during
* its call to the sigaction() system call to guarantee atomicity.
*/
int
s10_sigaction(sysret_t *rval,
int sig, const struct sigaction *act, struct sigaction *oact)
{
struct sigaction sigact, osigact;
struct sigaction *sigactp, *osigactp;
int err, nativesig;
void (*handler)();
if ((nativesig = s10sig_to_native(sig)) < 0) {
(void) B_TRUSS_POINT_3(rval, SYS_sigaction, EINVAL,
sig, act, oact);
return (EINVAL);
}
if (act == NULL) {
sigactp = NULL;
} else {
sigactp = &sigact;
if (brand_uucopy(act, sigactp, sizeof (struct sigaction)) != 0)
return (EFAULT);
if ((err = s10sigset_to_native(&sigactp->sa_mask,
&sigactp->sa_mask)) != 0) {
(void) B_TRUSS_POINT_3(rval, SYS_sigaction, err,
sig, act, oact);
return (err);
}
}
osigactp = ((oact == NULL) ? NULL : &osigact);
if (sigactp != NULL) {
handler = sigactp->sa_handler;
if (handler != SIG_DFL && handler != SIG_IGN)
sigactp->sa_sigaction = s10_sigacthandler;
}
if ((err = __systemcall(rval, SYS_sigaction + 1024,
nativesig, sigactp, osigactp)) != 0)
return (err);
/*
* Translate the old signal mask if we are supposed to return the old
* struct sigaction.
*
* Note that we may have set the signal handler, but may return EFAULT
* here if the oact parameter is bad.
*
* That's OK, because the direct system call acts the same way.
*/
if (osigactp != NULL) {
err = nativesigset_to_s10(&osigactp->sa_mask,
&osigactp->sa_mask);
if (osigactp->sa_sigaction == s10_sigacthandler)
osigactp->sa_sigaction = s10_handlers[sig - 1];
if (err == 0 && brand_uucopy(osigactp, oact,
sizeof (struct sigaction)) != 0)
err = EFAULT;
}
/*
* Do not store SIG_DFL or SIG_IGN into the array of remembered
* signal handlers. Only store bona-fide function addresses.
* This is to avoid a race condition in which some thread
* sets the signal handler to SIG_DFL or SIG_IGN while some
* other thread is fielding the signal but has not yet reached
* s10_sigacthandler(). s10_sigacthandler() will unconditionally
* call the remembered signal handler and it it calls SIG_DFL or
* SIG_IGN, the process will incur a SIGSEGV or SIGBUS signal.
* This also allows a vfork() child to set signal handlers
* to SIG_DFL or SIG_IGN without corrupting the parent's
* address space.
*/
if (sigactp != NULL &&
handler != SIG_DFL && handler != SIG_IGN)
s10_handlers[sig - 1] = handler;
return (err);
}
/*
* Interposition upon SYS_sigpending
*/
int
s10_sigpending(sysret_t *rval, int flag, sigset_t *set)
{
sigset_t sigset_set;
int err;
if ((err = __systemcall(rval, SYS_sigpending + 1024,
flag, &sigset_set)) != 0)
return (err);
if ((err = nativesigset_to_s10(&sigset_set, set)) != 0)
return (err);
return (0);
}
/*
* Interposition upon SYS_sigsendsys
*/
int
s10_sigsendsys(sysret_t *rval, procset_t *psp, int sig)
{
int nativesig;
if ((nativesig = s10sig_to_native(sig)) < 0) {
(void) B_TRUSS_POINT_2(rval, SYS_sigsendsys, EINVAL,
psp, sig);
return (EINVAL);
}
return (__systemcall(rval, SYS_sigsendsys + 1024, psp, nativesig));
}
/*
* Convert the siginfo_t code and status fields to an old style
* wait status for s10_wait(), below.
*/
static int
wstat(int code, int status)
{
int stat = (status & 0377);
switch (code) {
case CLD_EXITED:
stat <<= 8;
break;
case CLD_DUMPED:
stat |= WCOREFLG;
break;
case CLD_KILLED:
break;
case CLD_TRAPPED:
case CLD_STOPPED:
stat <<= 8;
stat |= WSTOPFLG;
break;
case CLD_CONTINUED:
stat = WCONTFLG;
break;
}
return (stat);
}
/*
* Interposition upon SYS_wait
*/
int
s10_wait(sysret_t *rval)
{
int err;
siginfo_t info;
err = s10_waitid(rval, P_ALL, 0, &info, WEXITED | WTRAPPED);
if (err != 0)
return (err);
rval->sys_rval1 = info.si_pid;
rval->sys_rval2 = wstat(info.si_code, info.si_status);
return (0);
}
/*
* Interposition upon SYS_waitid
*/
int
s10_waitid(sysret_t *rval,
idtype_t idtype, id_t id, siginfo_t *infop, int options)
{
int err, sig;
err = __systemcall(rval, SYS_waitid + 1024, idtype, id, infop, options);
if (err != 0)
return (err);
/*
* If the process being waited for terminated or stopped due to a
* signal, translate the signal number from its native value to its
* S10 equivalent.
*
* If we can't legally translate the signal number, just sort of punt
* and leave it untranslated.
*
* We shouldn't return EINVAL as the syscall didn't technically fail.
*/
if (infop->si_signo == SIGCLD && infop->si_code != CLD_EXITED &&
(sig = nativesig_to_s10(infop->si_status)) > 0)
infop->si_status = sig;
return (0);
}
/*
* Interposition upon SYS_sigtimedwait
*/
int
s10_sigtimedwait(sysret_t *rval,
const sigset_t *set, siginfo_t *info, const timespec_t *timeout)
{
sigset_t sigset_set;
int err, sig;
if ((err = s10sigset_to_native(set, &sigset_set)) != 0) {
(void) B_TRUSS_POINT_3(rval, SYS_sigtimedwait, err,
set, info, timeout);
return (err);
}
if ((err = __systemcall(rval, SYS_sigtimedwait + 1024,
&sigset_set, info, timeout)) != 0)
return (err);
if (info != NULL) {
/*
* If we can't legally translate the signal number in the
* siginfo_t, just sort of punt and leave it untranslated.
*
* We shouldn't return EINVAL as the syscall didn't technically
* fail.
*/
if ((sig = nativesig_to_s10(info->si_signo)) > 0)
info->si_signo = sig;
}
/*
* If we can't legally translate the signal number returned by the
* sigtimedwait syscall, just sort of punt and leave it untranslated.
*
* We shouldn't return EINVAL as the syscall didn't technically
* fail.
*/
if ((sig = nativesig_to_s10((int)rval->sys_rval1)) > 0)
rval->sys_rval1 = sig;
return (0);
}
/*
* Interposition upon SYS_sigqueue
*/
int
s10_sigqueue(sysret_t *rval, pid_t pid, int signo, void *value, int si_code)
{
int nativesig;
if ((nativesig = s10sig_to_native(signo)) < 0) {
(void) B_TRUSS_POINT_4(rval, SYS_sigqueue, EINVAL,
pid, signo, value, si_code);
return (EINVAL);
}
if (pid == 1)
pid = zone_init_pid;
/*
* The native version of this syscall takes an extra argument.
* The new last arg "block" flag should be zero. The block flag
* is used by the Opensolaris AIO implementation, which is now
* part of libc.
*/
return (__systemcall(rval, SYS_sigqueue + 1024,
pid, nativesig, value, si_code, 0));
}
/*
* Interposition upon SYS_signotify
*/
int
s10_signotify(sysret_t *rval,
int cmd, siginfo_t *siginfo, signotify_id_t *sn_id)
{
siginfo_t *infop, info;
infop = siginfo;
/* only check for a valid siginfo pointer in the case of SN_PROC */
if (cmd == SN_PROC) {
int nativesig;
if (brand_uucopy(infop, &info, sizeof (siginfo_t)) != 0)
return (EFAULT);
if ((nativesig = s10sig_to_native(info.si_signo)) < 0) {
(void) B_TRUSS_POINT_3(rval, SYS_signotify, EINVAL,
cmd, siginfo, sn_id);
return (EINVAL);
}
info.si_signo = nativesig;
infop = &info;
}
return (__systemcall(rval, SYS_signotify + 1024, cmd, infop, sn_id));
}
/*
* Interposition upon SYS_kill
*/
int
s10_kill(sysret_t *rval, pid_t pid, int sig)
{
int nativesig;
if ((nativesig = s10sig_to_native(sig)) < 0) {
(void) B_TRUSS_POINT_2(rval, SYS_kill, EINVAL, pid, sig);
return (EINVAL);
}
if (pid == 1)
pid = zone_init_pid;
return (__systemcall(rval, SYS_kill + 1024, pid, nativesig));
}
/*
* Interposition upon SYS_lwp_create
*
* See also the s10_lwp_create_correct_fs() function in s10_brand.c
* for the special case of creating an lwp in a 64-bit x86 process.
*/
int
s10_lwp_create(sysret_t *rval, ucontext_t *ucp, int flags, id_t *new_lwp)
{
ucontext_t s10_uc;
if (brand_uucopy(ucp, &s10_uc, sizeof (ucontext_t)) != 0)
return (EFAULT);
if (s10_uc.uc_flags & UC_SIGMASK)
(void) s10sigset_to_native(&s10_uc.uc_sigmask,
&s10_uc.uc_sigmask);
return (__systemcall(rval, SYS_lwp_create + 1024,
&s10_uc, flags, new_lwp));
}
/*
* Interposition upon SYS_lwp_kill
*/
int
s10_lwp_kill(sysret_t *rval, id_t lwpid, int sig)
{
int nativesig;
if ((nativesig = s10sig_to_native(sig)) < 0) {
(void) B_TRUSS_POINT_2(rval, SYS_lwp_kill, EINVAL,
lwpid, sig);
return (EINVAL);
}
return (__systemcall(rval, SYS_lwp_kill + 1024, lwpid, nativesig));
}
/*
* 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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
*/
#ifndef _S10_MISC_H
#define _S10_MISC_H
#ifdef __cplusplus
extern "C" {
#endif
#if !defined(_ASM)
/*
* From s10_deleted.c
*/
extern int s10_stat();
extern int s10_lstat();
extern int s10_fstat();
extern int s10_stat64();
extern int s10_lstat64();
extern int s10_fstat64();
extern int s10_open();
extern int s10_open64();
extern int s10_chmod();
extern int s10_fchmod();
extern int s10_chown();
extern int s10_lchown();
extern int s10_fchown();
extern int s10_mkdir();
extern int s10_mknod();
extern int s10_link();
extern int s10_unlink();
extern int s10_symlink();
extern int s10_readlink();
extern int s10_rmdir();
extern int s10_rename();
extern int s10_access();
extern int s10_creat();
extern int s10_creat64();
extern int s10_fork1();
extern int s10_forkall();
extern int s10_dup();
extern int s10_poll();
extern int s10_lwp_mutex_lock();
extern int s10_lwp_sema_wait();
extern int s10_utime();
extern int s10_utimes();
extern int s10_xstat();
extern int s10_lxstat();
extern int s10_fxstat();
extern int s10_xmknod();
extern int s10_fsat();
extern int s10_umount();
/*
* From s10_signal.c
*/
extern int s10sigset_to_native(const sigset_t *, sigset_t *);
extern int s10_kill();
extern int s10_lwp_create();
extern int s10_lwp_kill();
extern int s10_lwp_sigmask();
extern int s10_sigaction();
extern int s10_signotify();
extern int s10_sigpending();
extern int s10_sigprocmask();
extern int s10_sigqueue();
extern int s10_sigsendsys();
extern int s10_sigsuspend();
extern int s10_sigtimedwait();
extern int s10_wait();
extern int s10_waitid();
#endif /* !_ASM */
#ifdef __cplusplus
}
#endif
#endif /* _S10_MISC_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 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _S10_SIGNAL_H
#define _S10_SIGNAL_H
#ifdef __cplusplus
extern "C" {
#endif
#if !defined(_ASM)
#include <sys/types.h>
#include <sys/signal.h>
extern pid_t zone_init_pid;
typedef void (*s10_sighandler_t)(int, siginfo_t *, void *);
#endif /* !_ASM */
#ifdef __cplusplus
}
#endif
#endif /* _S10_SIGNAL_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 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
include $(SRC)/lib/Makefile.lib
default: all
# Hammerhead: amd64-only
SUBDIRS = $(MACH64)
all : TARGET= all
clean : TARGET= clean
clobber : TARGET= clobber
install : TARGET= install
_msg : TARGET= _msg
.KEEP_STATE:
all install clean clobber _msg: $(SUBDIRS)
$(SUBDIRS): FRC
@cd $@; pwd; $(MAKE) $(TARGET)
FRC:
#
# 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.
#
LIBRARY = s10_npreload.a
VERS = .1
COBJS = s10_npreload.o
OBJECTS = $(COBJS)
UTSBASE = $(SRC)/uts
include ../../Makefile.s10
include $(SRC)/lib/Makefile.lib
LIBS = $(DYNLIB)
CSRCS = $(COBJS:%o=../common/%c)
SRCS = $(CSRCS)
SRCDIR = ../common
CPPFLAGS += -D_REENTRANT -U_ASM -I../sys \
-I$(UTSBASE)/common/brand/solaris10
CFLAGS += $(CCVERBOSE)
DYNFLAGS += $(BLOCAL) $(ZNOVERSION)
# Hammerhead: Add -ldl for dlinfo (GNU ld requires explicit linkage)
LDLIBS += -ldl -lc
CLEANFILES += $(DYNLIB)
.KEEP_STATE:
all: $(LIBS)
include $(SRC)/lib/Makefile.targ
#
# 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 ../Makefile.com
include $(SRC)/lib/Makefile.lib.64
CLOBBERFILES = $(ROOTLIBDIR64)/$(DYNLIB)
install: all $(ROOTLIBS64)
#
# 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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
#
# MAPFILE HEADER START
#
# WARNING: STOP NOW. DO NOT MODIFY THIS FILE.
# Object versioning must comply with the rules detailed in
#
# usr/src/lib/README.mapfiles
#
# You should not be making modifications here until you've read the most current
# copy of that file. If you need help, contact a gatekeeper for guidance.
#
# MAPFILE HEADER END
#
$mapfile_version 2
SYMBOL_VERSION SUNWprivate_1.0 {
local:
*;
};
/*
* 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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
*/
#pragma init(init)
#include <s10_brand.h>
#include <stdlib.h>
#include <sys/syscall.h>
#include <dlfcn.h>
#include <link.h>
#include <limits.h>
#include <sys/mman.h>
#include <strings.h>
/* MAXCOMLEN is only defined in user.h in the kernel. */
#define MAXCOMLEN 16
/*
* This is a library that is LD_PRELOADed into native processes.
* Its primary function is to perform one brand operation, B_S10_NATIVE,
* which checks that this is actually a native process. If it is, then
* the operation changes the executable name so that it is no longer
* ld.so.1. Instead it changes it to be the name of the real native
* executable that we're runnning. This allows things like pgrep to work
* as expected. Note that this brand operation only changes the process
* name wrt the kernel. From the process' perspective, AT_SUN_EXECNAME is
* still ld.so.1. ld.so.1 removes itself and its arguments from the argv list.
*/
void
init(void)
{
int i;
Dl_argsinfo_t argsinfo;
sysret_t rval;
char *pcomm;
char cmd_buf[MAXCOMLEN + 1];
char arg_buf[PSARGSZ];
if (dlinfo(RTLD_SELF, RTLD_DI_ARGSINFO, &argsinfo) == -1)
return;
/* get the base cmd name */
if ((pcomm = strrchr(argsinfo.dla_argv[0], '/')) != NULL)
pcomm = pcomm + 1;
else
pcomm = argsinfo.dla_argv[0];
(void) strlcpy(cmd_buf, pcomm, sizeof (cmd_buf));
(void) strlcpy(arg_buf, argsinfo.dla_argv[0], sizeof (arg_buf));
for (i = 1; i < argsinfo.dla_argc; i++) {
(void) strlcat(arg_buf, " ", sizeof (arg_buf));
if (strlcat(arg_buf, argsinfo.dla_argv[i], sizeof (arg_buf))
>= sizeof (arg_buf))
break;
}
(void) __systemcall(&rval, SYS_brand, B_S10_NATIVE, cmd_buf, arg_buf);
}
#
# 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) 2010, Oracle and/or its affiliates. All rights reserved.
#
PROG = s10_replacefile
PROGS = $(PROG)
OBJS = s10_replacefile
all: $(PROG)
include ../Makefile.s10
include $(SRC)/cmd/Makefile.cmd
# override the install directory
ROOTBIN = $(ROOTBRANDDIR)
CLOBBERFILES = $(OBJS) $(ROOTPROGS)
UTSBASE = $(SRC)/uts
CFLAGS += $(CCVERBOSE)
CPPFLAGS += -D_REENTRANT
.KEEP_STATE:
install: all $(ROOTPROGS)
clean:
$(RM) $(PROG) $(OBJS)
include $(SRC)/cmd/Makefile.targ
/*
* 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) 2010, Oracle and/or its affiliates. All rights reserved.
*/
#include <stdio.h>
#include <strings.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mount.h>
#include <sys/mntent.h>
#include <unistd.h>
/*
* This program aids the Solaris 10 patch tools (specifically
* /usr/lib/patch/patch_common_lib) in DAP patching.
*
* Whenever the patch tools replace a critical system component (e.g.,
* /lib/libc.so.1), they move the old component to a temporary location,
* move the new component to where the old component was, and establish
* an overlay mount of the old component on top of the new component.
* The patch tools do this with a shell script; consequently, the three
* operations occur in three processes.
*
* This doesn't work inside Solaris 10 Containers (S10Cs). Suppose the
* patch tools need to replace /lib/libc.so.1. The tools will move the old
* libc.so.1 to a temporary location. But when they try to move the new
* libc.so.1, they fork a mv(1) process, which loads the solaris10 brand's
* emulation library. The emulation library will try to load the zone's
* libc.so.1, but the library no longer exists; consequently, the emulation
* library aborts and the zone's users won't be able to start any processes.
*
* This program solves the problem by combining the move and mount operations
* into a single process. The emulation library will already have loaded
* libc.so.1 for the process by the time the process starts to replace
* libc.so.1.
*
* This program takes six parameters that correspond to six variables within
* /usr/lib/patch/patch_common_lib:InstallSafemodeObject():
*
* argv[1] - dstActual (the path to the file that will be replaced)
* argv[2] - tmp_file (the temporary location to which the file will be
* moved)
* argv[3] - tmpDst (the path to the replacement file)
* argv[4] - tmpFile (the path to a temporary copy of the running system's
* version of the file being replaced; the source [special] of
* the overlay mount)
* argv[5] - cksumTmpDst (checksum of the file represented by tmpDst)
* argv[6] - cksumTmpFile (checksum of the file represented by tmpFile)
*
* NOTE: This program will only establish an overlay mount if argv[4] or argv[5]
* is emtpy or if argv[4] and argv[5] differ.
*
* This program returns zero when it succeeds. Non-negative values indicate
* failure.
*/
int
main(int argc, char **argv)
{
struct stat statbuf;
char mntoptions[MAX_MNTOPT_STR];
/*
* Check the number of arguments that were passed to s10_replacefile.
*/
if (argc != 7) {
(void) fprintf(stderr, "Usage: %s dstActual tmp_file tmpDst "
"tmpFile cksumTmpDst cksumTmpFile\n", argv[0]);
return (1);
}
/*
* Move the destination file (dstActual) out of the way and move the
* new file (tmpDst) into its place.
*
* NOTE: s10_replacefile won't print error messages here because
* the Solaris 10 patch tools will.
*/
if (rename(argv[1], argv[2]) != 0)
return (2);
if (rename(argv[3], argv[1]) != 0)
return (3);
/*
* If there was a lofs mount on dstActual (which we just moved), then
* s10_replacefile should reestablish the lofs mount. A lofs mount
* existed if tmpFile exists.
*/
if (stat(argv[4], &statbuf) == 0 && (statbuf.st_mode & S_IFREG)) {
/*
* Create a lofs overlay mount only if the checksums of the
* old file at dstActual and the new file at dstActual differ.
*/
if (argv[5][0] == '\0' || argv[6][0] == '\0' ||
strcmp(argv[5], argv[6]) != 0) {
mntoptions[0] = '\0';
if (mount(argv[4], argv[1], MS_OVERLAY | MS_OPTIONSTR,
MNTTYPE_LOFS, NULL, 0, mntoptions,
sizeof (mntoptions)) != 0) {
/*
* Although the patch tools will print error
* messages, the tools won't know that
* s10_replacefile failed to establish an
* overlay mount. Printing an error message
* here clarifies the problem for the user.
*/
(void) fprintf(stderr, "ERROR: Failed to "
"overlay mount %s onto %s\n", argv[4],
argv[1]);
return (4);
}
} else {
/*
* dstActual does not need an overlay mount. Delete
* tmpFile.
*/
(void) unlink(argv[4]);
}
}
return (0);
}
#
# 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.
#
PROG = s10_support
PROGS = $(PROG)
OBJS = s10_support
all: $(PROG)
include ../Makefile.s10
include $(SRC)/cmd/Makefile.cmd
# override the install directory
ROOTBIN = $(ROOTBRANDDIR)
UTSBASE = $(SRC)/uts
CFLAGS += $(CCVERBOSE)
CPPFLAGS += -D_REENTRANT -I$(UTSBASE)/common/brand/solaris10
LDLIBS += -lzonecfg
.KEEP_STATE:
install: all $(ROOTPROGS)
clean:
$(RM) $(OBJS)
include $(SRC)/cmd/Makefile.targ
/*
* 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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* s10_support is a small cli utility used to perform some brand-specific
* tasks when verifying a zone. This utility is not intended to be called
* by users - it is intended to be invoked by the zones utilities.
*/
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <limits.h>
#include <s10_brand.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <stropts.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/varargs.h>
#include <unistd.h>
#include <libintl.h>
#include <locale.h>
#include <dirent.h>
#include <sys/systeminfo.h>
#include <libzonecfg.h>
static void s10_err(char *msg, ...) __NORETURN;
static void usage(void) __NORETURN;
/*
* XXX This is a temporary flag for the initial release to enable the
* use of features which are not yet tested or fully implemented.
*/
static boolean_t override = B_FALSE;
static char *bname = NULL;
/*
* DELETE_LIST_PATH represents the path to a solaris10-branded zone's "delete
* list", which is generated by patchrm when it needs to remove files after
* the zone reboots. See set_zone_emul_bitmap() below for additional details.
*/
#define DELETE_LIST_PATH "/var/sadm/patch/.delete_list"
#define PKGINFO_RD_LEN 128
#define PATCHLIST "PATCHLIST="
#if !defined(TEXT_DOMAIN) /* should be defined by cc -D */
#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */
#endif
/*PRINTFLIKE1*/
static void
s10_err(char *msg, ...)
{
char buf[1024];
va_list ap;
va_start(ap, msg);
(void) vsnprintf(buf, sizeof (buf), msg, ap);
va_end(ap);
/* This needs go to stdout so the msgs show up through zoneadm. */
(void) printf("Error: %s\n", buf);
exit(1);
/*NOTREACHED*/
}
static int
s10_verify(char *xmlfile)
{
zone_dochandle_t handle;
struct zone_devtab devtab;
if ((handle = zonecfg_init_handle()) == NULL)
s10_err(gettext("internal libzonecfg.so.1 error"), 0);
if (zonecfg_get_xml_handle(xmlfile, handle) != Z_OK) {
zonecfg_fini_handle(handle);
s10_err(gettext("zonecfg provided an invalid XML file"));
}
/*
* Check to see whether the zone has any unsupported devices
* configured.
*
* The audio framework has changed in Solaris Next as compared to
* S10. Data indicates the less than 1/10 of 1 percent of zones
* are using /dev/sound. Given the low usage vs. the effort to
* provide emulation, /dev/sound is currently disallowed. We can
* revisit this if there is enough demand.
*/
if (zonecfg_setdevent(handle) != Z_OK) {
zonecfg_fini_handle(handle);
s10_err(gettext("zonecfg provided an invalid XML file"));
}
if (zonecfg_getdevent(handle, &devtab) == Z_OK) {
if (strncmp(devtab.zone_dev_match, "/dev/sound", 10) == 0 &&
!override) {
zonecfg_fini_handle(handle);
s10_err(gettext("solaris10 zones do not currently "
"support /dev/sound"));
}
}
(void) zonecfg_enddevent(handle);
zonecfg_fini_handle(handle);
return (0);
}
/*
* Read an entry from a pkginfo file. Some of these lines can
* either be arbitrarily long or be continued by a backslash at the end of
* the line. This function coalesces lines that are longer than the read
* buffer, and lines that are continued, into one buffer which is returned.
* The caller must free this memory. NULL is returned when we hit EOF or
* if we run out of memory (errno is set to ENOMEM).
*/
static char *
read_pkg_data(FILE *fp)
{
char *start;
char *inp;
char *p;
int char_cnt = 0;
errno = 0;
if ((start = (char *)malloc(PKGINFO_RD_LEN)) == NULL) {
errno = ENOMEM;
return (NULL);
}
inp = start;
while ((p = fgets(inp, PKGINFO_RD_LEN, fp)) != NULL) {
int len;
len = strlen(inp);
if (inp[len - 1] == '\n' &&
(len == 1 || inp[len - 2] != '\\')) {
char_cnt = len;
break;
}
if (inp[len - 1] == '\n' && inp[len - 2] == '\\')
char_cnt += len - 2;
else
char_cnt += PKGINFO_RD_LEN - 1;
if ((p = realloc(start, char_cnt + PKGINFO_RD_LEN)) == NULL) {
errno = ENOMEM;
break;
}
start = p;
inp = start + char_cnt;
}
if (errno == ENOMEM || (p == NULL && char_cnt == 0)) {
free(start);
start = NULL;
}
return (start);
}
/*
* Read the SUNWcakr pkginfo file and get the PATCHLIST for the pkg.
*/
static int
get_ku_patchlist(char *zonepath, char **patchlist)
{
char pkginfo[MAXPATHLEN];
FILE *fp;
char *buf;
int err = 0;
if (snprintf(pkginfo, sizeof (pkginfo),
"%s/root/var/sadm/pkg/SUNWcakr/pkginfo", zonepath)
>= sizeof (pkginfo))
s10_err(gettext("error formating pkg path"));
if ((fp = fopen(pkginfo, "r")) == NULL)
return (errno);
while ((buf = read_pkg_data(fp)) != NULL) {
if (strncmp(buf, PATCHLIST, sizeof (PATCHLIST) - 1) == 0) {
int len;
/* remove trailing newline */
len = strlen(buf);
buf[len - 1] = '\0';
if ((*patchlist =
strdup(buf + sizeof (PATCHLIST) - 1)) == NULL)
err = ENOMEM;
free(buf);
break;
}
free(buf);
}
(void) fclose(fp);
return (err);
}
/*
* Verify that we have the minimum KU needed.
* Note that KU patches are accumulative so future KUs will still deliver
* 141444 or 141445.
*/
static boolean_t
have_valid_ku(char *zonename)
{
char *p;
char *lastp;
char *pstr;
char *patchlist = NULL;
char zonepath[MAXPATHLEN];
char sanity_skip[MAXPATHLEN];
struct stat64 buf;
boolean_t is_xpv = B_FALSE;
char platform[80];
char *xpv_vers = "142910";
char *vers_table[] = {
"141444-09",
"141445-09"};
if (zone_get_zonepath(zonename, zonepath, sizeof (zonepath)) != Z_OK)
s10_err(gettext("error getting zone's path"));
/*
* If the zone was installed to bypass sanity checking for internal
* testing purposes, just return success.
*/
if (snprintf(sanity_skip, sizeof (sanity_skip), "%s/root/.sanity_skip",
zonepath) >= sizeof (sanity_skip))
s10_err(gettext("error formating file path"));
if (stat64(sanity_skip, &buf) == 0)
return (B_TRUE);
if (get_ku_patchlist(zonepath, &patchlist) != 0 || patchlist == NULL)
return (B_FALSE);
/*
* Check if we're running on the i86xpv platform. If so, the zone
* needs a different ku patch to work properly.
*/
if (sysinfo(SI_PLATFORM, platform, sizeof (platform)) != -1 &&
strcmp(platform, "i86xpv") == 0)
is_xpv = B_TRUE;
pstr = patchlist;
while ((p = strtok_r(pstr, " ", &lastp)) != NULL) {
if (is_xpv) {
if (strncmp(p, xpv_vers, 6) == 0)
return (B_TRUE);
} else {
if (strcmp(p, vers_table[0]) == 0 ||
strcmp(p, vers_table[1]) == 0)
return (B_TRUE);
}
pstr = NULL;
}
if (is_xpv)
s10_err(gettext("the zone must have patch 142910 installed "
"when running in a paravirtualized domain"));
return (B_FALSE);
}
/*
* Convert the specified file basename into an unsigned integer. If the
* basename contains characters that cannot be converted into digits or the
* basename isn't NULL or newline-terminated, then this function returns
* the unsigned equivalent of -1.
*/
static unsigned int
basename_to_uint(const char *basenamep)
{
char *filename_endptr;
unsigned int bit_index;
errno = 0;
bit_index = (unsigned int)strtoul(basenamep, &filename_endptr, 10);
if (errno != 0 || (*filename_endptr != '\n' &&
*filename_endptr != '\0') || filename_endptr == basenamep)
return ((unsigned int)-1);
return (bit_index);
}
/*
* Determine which features/behaviors should be emulated and construct a bitmap
* representing the results. Associate the bitmap with the zone so that
* the brand's emulation library will be able to retrieve the bitmap and
* determine how the zone's process' behaviors should be emulated.
*
* This function does not return if an error occurs.
*/
static void
set_zone_emul_bitmap(char *zonename)
{
char zoneroot[MAXPATHLEN];
char path[MAXPATHLEN];
DIR *req_emulation_dirp;
struct dirent *emul_feature_filep;
s10_emul_bitmap_t bitmap;
unsigned int bit_index;
zoneid_t zoneid;
FILE *delete_listp;
/*
* If the Solaris 10 directory containing emulation feature files
* doesn't exist in the zone, then assume that it only needs the
* most basic emulation and, therefore, doesn't need a bitmap.
*/
if (zone_get_rootpath(zonename, zoneroot, sizeof (zoneroot)) != Z_OK)
s10_err(gettext("error getting zone's path"));
if (snprintf(path, sizeof (path), "%s" S10_REQ_EMULATION_DIR,
zoneroot) >= sizeof (path))
s10_err(gettext("zone's emulation versioning directory's path "
"%s" S10_REQ_EMULATION_DIR " is too long"), zoneroot);
if ((req_emulation_dirp = opendir(path)) == NULL)
return;
bzero(bitmap, sizeof (bitmap));
/*
* Iterate over the contents of the directory and determine which
* features the brand should emulate for this zone.
*/
while ((emul_feature_filep = readdir(req_emulation_dirp)) != NULL) {
if (strcmp(emul_feature_filep->d_name, ".") == 0 ||
strcmp(emul_feature_filep->d_name, "..") == 0)
continue;
/*
* Convert the file's name to an unsigned integer. Ignore
* files whose names aren't unsigned integers.
*/
bit_index = basename_to_uint(emul_feature_filep->d_name);
if (bit_index == (unsigned int)-1)
continue;
/*
* Determine if the brand can emulate the feature specified
* by bit_index.
*/
if (bit_index >= S10_NUM_EMUL_FEATURES) {
/*
* The zone requires emulation that the brand can't
* provide. Notify the user by displaying an error
* message.
*/
s10_err(gettext("The zone's version of Solaris 10 is "
"incompatible with the\ncurrent version of the "
"solaris10 brand.\nPlease update your Solaris "
"system to the latest release."));
} else {
/*
* Set the feature's flag in the bitmap.
*/
bitmap[(bit_index >> 3)] |= (1 << (bit_index & 0x7));
}
}
(void) closedir(req_emulation_dirp);
/*
* The zone's administrator might have removed a patch that delivered
* an emulation feature file the last time the zone ran. If so, then
* the zone's patch utilities won't delete the file until the zone's
* svc:/system/patch-finish:delete SMF service runs. This is
* problematic because the zone will be using system libraries whose
* ioctl structures and syscall invocations will differ from those
* expected by the emulation library. For example, if an administrator
* removes a patch that affects the formats of MNTFS ioctls, then the
* administrator's zone will use a version of libc.so.1 that issues
* MNTFS ioctls that use older structure versions than the zone's
* emulation library will expect.
*
* Fortunately, the patchrm utility creates a hidden file,
* /var/sadm/patch/.delete_list, which lists all files that
* svc:/system/patch-finish:delete will delete. We'll determine whether
* this file exists in the zone and disable the emulation bits
* associated with the emulation feature files that will be deleted.
*
* NOTE: The patch tools lofs mount backup copies of critical system
* libraries, such as /lib/libc.so.1, over their replacements whenever
* administrators add or remove DAP patches. Consequently, there isn't
* a window of vulnerability between patch addition or removal and
* zone reboot. The aforementioned problem only occurs after a zone
* reboots.
*/
if (snprintf(path, sizeof (path), "%s" DELETE_LIST_PATH, zoneroot) >=
sizeof (path))
s10_err(gettext("zone's delete list's path %s" DELETE_LIST_PATH
" is too long"), zoneroot);
if ((delete_listp = fopen(path, "r")) != NULL) {
while (fgets(path, sizeof (path), delete_listp) != NULL) {
char *const basenamep = path +
sizeof (S10_REQ_EMULATION_DIR);
/*
* Make sure that the file is in the directory
* containing emulation feature files. If it is,
* then basenamep should refer to the basename of
* the file.
*/
if (strncmp(path, S10_REQ_EMULATION_DIR,
sizeof (S10_REQ_EMULATION_DIR) - 1) != 0)
continue;
if (*(basenamep - 1) != '/')
continue;
/*
* Convert the file's basename into a bit index in
* the emulation bitmap. If the file's basename isn't
* integral, then skip the file. Otherwise, clear the
* corresponding bit in the bitmap.
*/
bit_index = basename_to_uint(basenamep);
if (bit_index == (unsigned int)-1)
continue;
if (bit_index < S10_NUM_EMUL_FEATURES)
bitmap[(bit_index >> 3)] &=
~(1 << (bit_index & 0x7));
}
if (ferror(delete_listp) != 0 || feof(delete_listp) == 0)
s10_err(gettext("The program encountered an error while"
" reading from %s" DELETE_LIST_PATH "."), zoneroot);
(void) fclose(delete_listp);
} else if (errno != ENOENT) {
/*
* The delete list exists but couldn't be opened. Warn the
* administrator.
*/
s10_err(gettext("Unable to open %s" DELETE_LIST_PATH ": %s"),
zoneroot, strerror(errno));
}
/*
* We're done scanning files. Set the zone's emulation bitmap.
*/
if ((zoneid = getzoneidbyname(zonename)) < 0)
s10_err(gettext("unable to get zoneid"));
if (zone_setattr(zoneid, S10_EMUL_BITMAP, bitmap, sizeof (bitmap)) != 0)
s10_err(gettext("error setting zone's emulation bitmap"));
}
static int
s10_boot(char *zonename)
{
if (!have_valid_ku(zonename))
s10_err(gettext("The installed version of Solaris 10 is "
"not supported"));
set_zone_emul_bitmap(zonename);
return (0);
}
static void
usage()
{
(void) fprintf(stderr, gettext(
"usage:\t%s verify <xml file>\n"
"\t%s boot\n"),
bname, bname);
exit(1);
}
int
main(int argc, char *argv[])
{
(void) setlocale(LC_ALL, "");
(void) textdomain(TEXT_DOMAIN);
bname = basename(argv[0]);
if (argc != 3)
usage();
/*
* XXX This is a temporary env variable for the initial release to
* enable the use of features which are not yet tested or fully
* implemented.
*/
if (getenv("S10BRAND_TEST") != NULL)
override = B_TRUE;
if (strcmp(argv[1], "verify") == 0)
return (s10_verify(argv[2]));
if (strcmp(argv[1], "boot") == 0)
return (s10_boot(argv[2]));
usage();
/*NOTREACHED*/
}
#
# 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.
#
PROGS = attach clone detach image_install p2v postattach poststate \
prestate preuninstall s10_boot uninstall
XMLDOCS= config.xml platform.xml smf_disable.lst pkgrm.lst common.ksh \
version
USERFILES= smf_disable.conf pkgrm.conf
TEMPLATES = SUNWsolaris10.xml
CLOBBERFILES= $(ROOTPROGS) $(ROOTXMLDOCS) $(ROOTTEMPLATES) $(ETCUSER)
include $(SRC)/cmd/Makefile.cmd
include ../Makefile.s10
.KEEP_STATE:
all: $(PROGS)
POFILES = $(PROGS:%=%.po) common.po
POFILE = s10_zone.po
$(POFILE): $(POFILES)
$(RM) $@
$(CAT) $(POFILES) > $@
install: $(PROGS) $(ROOTPROGS) $(ROOTXMLDOCS) $(ROOTTEMPLATES) $(ETCUSER)
clean:
-$(RM) $(PROGS) $(POFILES) $(POFILE)
include $(SRC)/cmd/Makefile.targ
<?xml version="1.0"?>
<!--
Copyright 2009 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
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
DO NOT EDIT THIS FILE. Use zonecfg(8) instead.
-->
<!DOCTYPE zone PUBLIC "-//Sun Microsystems Inc//DTD Zones//EN" "file:///usr/share/lib/xml/dtd/zonecfg.dtd.1">
<zone name="default" zonepath="" autoboot="false" brand="solaris10">
</zone>
#!/bin/ksh -p
#
# 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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
. /usr/lib/brand/solaris10/common.ksh
m_attach_log=$(gettext "Log File: %s")
m_zfs=$(gettext "A ZFS file system was created for the zone.")
m_attaching=$(gettext "Attaching...")
m_usage=$(gettext "solaris10 brand usage:\n\tattach [-a archive | -d directory | -r recv_type]\n\tThe -a archive option specifies an archive name which can be a flar,\n\ttar, pax or cpio archive.\n\tThe -d directory option specifies an existing directory.\n\tThe -r recv_type option specifies the type of archive to be read from\n\tstdin.")
m_complete=$(gettext "Attach complete.")
install_fail=$(gettext "*** Attach FAILED ***")
f_n_unimpl=$(gettext "The -n option is not yet implemented.")
f_zfs=$(gettext "Error creating a ZFS file system (%s) for the zone.")
f_nodataset=$(gettext "Error: there is no ZFS file system for the zone.")
f_zfsdestroy=$(gettext "Error destroying ZFS file system %s.")
f_sanity_notzone=$(gettext "Error: this is a system image and not a zone image.")
f_baddir=$(gettext "Invalid '%s' directory within the zone")
# Clean up on interrupt
trap_cleanup()
{
msg=$(gettext "Installation cancelled due to interrupt.")
log "$msg"
# umount any mounted file systems
umnt_fs
trap_exit
}
# If the attach failed then clean up the ZFS datasets we created.
trap_exit()
{
if [[ $EXIT_CODE != $ZONE_SUBPROC_OK && $rm_ds == 1 ]]; then
/usr/lib/brand/solaris10/uninstall $ZONENAME $ZONEPATH -F
fi
exit $EXIT_CODE
}
EXIT_CODE=$ZONE_SUBPROC_USAGE
install_media="-"
rm_ds=0
trap trap_cleanup INT
trap trap_exit EXIT
# If we weren't passed at least two arguments, exit now.
(( $# < 2 )) && exit $ZONE_SUBPROC_USAGE
ZONENAME="$1"
ZONEPATH="$2"
# XXX shared/common script currently uses lower case zonename & zonepath
zonename="$ZONENAME"
zonepath="$ZONEPATH"
shift; shift # remove ZONENAME and ZONEPATH from arguments array
ZONEROOT="$ZONEPATH/root"
logdir="$ZONEROOT/var/log"
noexecute=0
unset inst_type
# Other brand attach options are invalid for this brand.
while getopts "a:d:nr:" opt; do
case $opt in
a)
if [[ -n "$inst_type" ]]; then
fatal "$incompat_options" "$m_usage"
fi
inst_type="archive"
install_media="$OPTARG"
;;
d)
if [[ -n "$inst_type" ]]; then
fatal "$incompat_options" "$m_usage"
fi
inst_type="directory"
install_media="$OPTARG"
# '-d -' means use the existing zonepath.
if [[ "$install_media" == "$ZONEPATH" ]]; then
install_media="-"
fi
;;
n) noexecute=1 ;;
r)
if [[ -n "$inst_type" ]]; then
fatal "$incompat_options" "$m_usage"
fi
inst_type="stdin"
install_media="$OPTARG"
;;
?) printf "$m_usage\n"
exit $ZONE_SUBPROC_USAGE;;
*) printf "$m_usage\n"
exit $ZONE_SUBPROC_USAGE;;
esac
done
shift $((OPTIND-1))
if [[ $noexecute == 1 && -n "$inst_type" ]]; then
fatal "$m_usage"
fi
if [ $noexecute -eq 1 ]; then
#
# The zone doesn't have to exist when the -n option is used, so do
# this work early.
#
# XXX do the sw validation for solaris10 minimal patch level to ensure
# everything will be ok.
EXIT_CODE=$ZONE_SUBPROC_NOTCOMPLETE
fatal "$f_n_unimpl"
fi
EXIT_CODE=$ZONE_SUBPROC_NOTCOMPLETE
if [[ -z "$inst_type" ]]; then
inst_type="directory"
elif [[ "$install_media" != "-" ]]; then
#
# If we're not using a pre-existing zone directory layout then create
# the zone datasets and mount them.
#
unset DATASET
pdir=$(/bin/dirname $ZONEPATH)
zds=$(/sbin/zfs list -H -t filesystem -o name $pdir 2>/dev/null)
if (( $? == 0 )); then
pnm=$(/bin/basename $ZONEPATH)
/sbin/zfs create "$zds/$pnm"
if (( $? == 0 )); then
vlog "$m_zfs"
DATASET="$zds/$pnm"
rm_ds=1
else
log "$f_zfs" "$zds/$pnm"
fi
fi
create_active_ds
fi
#
# The zone's datasets are now in place, validate that things
# are setup correctly.
#
get_zonepath_ds $zonepath
/sbin/zfs list -H -o name $ZONEPATH_DS/ROOT >/dev/null 2>&1
(( $? != 0 )) && fail_fatal "$f_no_active_ds"
zfs set mountpoint=legacy $ZONEPATH_DS/ROOT >/dev/null 2>&1
zfs set zoned=on $ZONEPATH_DS/ROOT >/dev/null 2>&1
get_active_ds $ZONEPATH_DS
zfs list -H -o name $ACTIVE_DS >/dev/null 2>&1
(( $? != 0 )) && fail_fatal "$f_zfs_create"
zfs set canmount=noauto $ACTIVE_DS >/dev/null 2>&1
zfs inherit mountpoint $ACTIVE_DS >/dev/null 2>&1
zfs inherit zoned $ACTIVE_DS >/dev/null 2>&1
if [ ! -d $ZONEROOT ]; then
mkdir -p $ZONEROOT || fail_fatal "$f_mkdir" "$ZONEROOT"
chmod 700 $ZONEPATH || fail_fatal "$f_chmod" "$ZONEPATH"
fi
mnted=`zfs get -H mounted $ACTIVE_DS | cut -f3`
if [[ $mnted = "no" ]]; then
mount -F zfs $ACTIVE_DS $ZONEROOT || fail_fatal "$f_zfs_mount"
fi
LOGFILE=$(/usr/bin/mktemp -t -p /var/tmp $zonename.attach_log.XXXXXX)
if [[ -z "$LOGFILE" ]]; then
fatal "$e_tmpfile"
fi
exec 2>>"$LOGFILE"
log "$m_attach_log" "$LOGFILE"
log "$m_attaching"
install_image "$inst_type" "$install_media"
mk_zone_dirs
#
# Perform a final check that this is really a zone image and not an archive of
# a system image which would need p2v. Check for a well-known S10 SMF service
# that shouldn't exist in a zone.
#
if [[ -e $ZONEROOT/var/svc/manifest/system/sysevent.xml ]]; then
log "$f_sanity_notzone"
exit $ZONE_SUBPROC_NOTCOMPLETE
fi
EXIT_CODE=$ZONE_SUBPROC_OK
log "$m_complete"
zone_logfile="${logdir}/$zonename.attach$$.log"
safe_dir /var
safe_dir /var/log
safe_copy $LOGFILE $zone_logfile
log "$m_attach_log" "$zone_logfile"
rm -f $LOGFILE
exit $ZONE_SUBPROC_OK
#!/bin/ksh -p
#
# 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.
#
. /usr/lib/brand/solaris10/common.ksh
m_usage=$(gettext "solaris10 brand usage: clone {sourcezone}.")
f_nosource=$(gettext "Error: unable to determine source zone dataset.")
f_sysunconfig=$(gettext "Error: sys-unconfig failed.")
# Other brand clone options are invalid for this brand.
while getopts "R:z:" opt; do
case $opt in
R) ZONEPATH="$OPTARG" ;;
z) ZONENAME="$OPTARG" ;;
*) printf "$m_usage\n"
exit $ZONE_SUBPROC_USAGE;;
esac
done
shift $((OPTIND-1))
if [ $# -ne 1 ]; then
fail_usage "$0 {sourcezone}";
fi
ZONEROOT="$ZONEPATH/root"
sourcezone=$1
# Find the active source zone dataset to clone.
sourcezonepath=`/usr/sbin/zonecfg -z $sourcezone info zonepath | \
/usr/bin/cut -f2 -d' '`
if [ -z "$sourcezonepath" ]; then
fail_fatal "$f_nosource"
fi
get_zonepath_ds $sourcezonepath
get_active_ds $ZONEPATH_DS
ACTIVE_SRC=$ACTIVE_DS
#
# Now set up the zone's datasets
#
#
# First make the top-level dataset.
#
pdir=`/bin/dirname $ZONEPATH`
zpname=`/bin/basename $ZONEPATH`
get_zonepath_ds $pdir
zpds=$ZONEPATH_DS
# Create the datasets.
/sbin/zfs create $zpds/$zpname
if (( $? != 0 )); then
fail_fatal "$f_zfs_create"
fi
/sbin/zfs create -o mountpoint=legacy -o zoned=on $zpds/$zpname/ROOT
if (( $? != 0 )); then
fail_fatal "$f_zfs_create"
fi
# make snapshot
SNAPNAME=${ZONENAME}_snap
SNAPNUM=0
while [ $SNAPNUM -lt 100 ]; do
zfs snapshot $ACTIVE_SRC@$SNAPNAME
if [ $? = 0 ]; then
break
fi
SNAPNUM=`expr $SNAPNUM + 1`
SNAPNAME="${ZONENAME}_snap$SNAPNUM"
done
if [ $SNAPNUM -ge 100 ]; then
fail_fatal "$f_zfs_create"
fi
# do clone
get_active_ds $zpds/$zpname
zfs clone -o canmount=noauto $ACTIVE_SRC@$SNAPNAME $ACTIVE_DS
(( $? != 0 )) && fail_fatal "$f_zfs_create"
if [ ! -d $ZONEROOT ]; then
mkdir -p $ZONEROOT || fail_fatal "$f_mkdir" "$ZONEROOT"
chmod 700 $ZONEPATH || fail_fatal "$f_chmod" "$ZONEPATH"
fi
mount -F zfs $ACTIVE_DS $ZONEROOT || fail_fatal "$f_zfs_mount"
# Don't re-sysunconfig if we've already done so
if [[ ! -f $ZONEROOT/etc/.UNCONFIGURED ]]; then
/usr/sbin/zoneadm -z $ZONENAME boot -f -- -m milestone=none
if (( $? != 0 )); then
error "$e_badboot"
fail_incomplete "$f_sysunconfig"
fi
sysunconfig_zone
if (( $? != 0 )); then
/usr/sbin/zoneadm -z $ZONENAME halt
fail_incomplete "$f_sysunconfig"
fi
/usr/sbin/zoneadm -z $ZONENAME halt
fi
# Add a service tag for this zone.
add_svc_tag "$ZONENAME" "clone $sourcezone"
exit $ZONE_SUBPROC_OK
#
# 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.
#
unset LD_LIBRARY_PATH
PATH=/usr/bin:/usr/sbin
export PATH
. /usr/lib/brand/shared/common.ksh
# Values for service tags.
STCLIENT=/usr/bin/stclient
ST_PRODUCT_NAME="Solaris 10 Containers"
ST_PRODUCT_REV="1.0"
ST_PRODUCT_UUID="urn:uuid:2f459121-dec7-11de-9af7-080020a9ed93"
w_sanity_detail=$(gettext " WARNING: Skipping image sanity checks.")
f_sanity_detail=$(gettext "Missing %s at %s")
f_sanity_sparse=$(gettext "Is this a sparse zone image? The image must be whole-root.")
f_sanity_vers=$(gettext "The image release version must be 10 (got %s), the zone is not usable on this system.")
f_not_s10_image=$(gettext "%s doesn't look like a Solaris 10 image.")
f_sanity_nopatch=$(gettext "Unable to determine the image's patch level.")
f_sanity_downrev=$(gettext "The image patch level is downrev for running in a solaris10 branded zone.\n(patchlist %s)")
f_need_newer_emul=$(gettext "The image requires a newer version of the solaris10 brand emulation.")
f_zfs_create=$(gettext "Unable to create the zone's ZFS dataset.")
f_no_ds=$(gettext "No zonepath dataset; the zonepath must be a ZFS dataset.")
f_multiple_ds=$(gettext "Multiple active datasets.")
f_no_active_ds=$(gettext "No active dataset; the zone's ZFS root dataset must be configured as\n\ta zone boot environment.")
f_zfs_unmount=$(gettext "Unable to unmount the zone's root ZFS dataset (%s).\nIs there a global zone process inside the zone root?\nThe current zone boot environment will remain mounted.\n")
f_zfs_mount=$(gettext "Unable to mount the zone's ZFS dataset.")
incompat_options=$(gettext "mutually exclusive options.\n%s")
sanity_ok=$(gettext " Sanity Check: Passed. Looks like a Solaris 10 image.")
sanity_fail=$(gettext " Sanity Check: FAILED (see log for details).")
e_badboot=$(gettext "Zone boot failed")
e_nosingleuser=$(gettext "ERROR: zone did not finish booting to single-user.")
e_unconfig=$(gettext "sys-unconfig failed")
v_unconfig=$(gettext "Performing zone sys-unconfig")
v_no_tags=$(gettext "Service tags facility not present.")
e_bad_uuid=$(gettext "Failed to get zone UUID")
v_addtag=$(gettext "Adding service tag: %s")
v_deltag=$(gettext "Removing service tag: %s")
e_addtag_fail=$(gettext "Adding service tag failed (error: %s)")
sanity_check()
{
typeset dir="$1"
res=0
#
# Check for some required directories and make sure this isn't a
# sparse zone image.
#
checks="etc etc/svc var var/svc"
for x in $checks; do
if [[ ! -e $dir/$x ]]; then
log "$f_sanity_detail" "$x" "$dir"
res=1
fi
done
# Files from SUNWcsr and SUNWcsu that are in sparse inherit-pkg-dirs.
checks="lib/svc sbin/zonename usr/bin/chmod"
for x in $checks; do
if [[ ! -e $dir/$x ]]; then
log "$f_sanity_detail" "$x" "$dir"
log "$f_sanity_sparse"
res=1
fi
done
if (( $res != 0 )); then
log "$sanity_fail"
fatal "$install_fail" "$ZONENAME"
fi
if [[ "$SANITY_SKIP" == 1 ]]; then
log "$w_sanity_detail"
return
fi
#
# Check image release to be sure its S10.
#
image_vers="unknown"
if [[ -f $dir/var/sadm/system/admin/INST_RELEASE ]]; then
image_vers=$(nawk -F= '{if ($1 == "VERSION") print $2}' \
$dir/var/sadm/system/admin/INST_RELEASE)
fi
if [[ "$image_vers" != "10" ]]; then
log "$f_sanity_vers" "$image_vers"
res=1
fi
#
# Make sure we have the minimal KU patch we support. These are the
# KUs for S10u8.
#
if [[ $(uname -p) == "amd64" || $(uname -p) == "i386" ]]; then
req_patch="141445-09"
else
req_patch="141444-09"
fi
for i in $dir/var/sadm/pkg/SUNWcakr*
do
if [[ ! -d $i || ! -f $i/pkginfo ]]; then
log "$f_sanity_nopatch"
res=1
fi
done
#
# Check the core kernel pkg for the required KU patch.
#
found=0
for i in $dir/var/sadm/pkg/SUNWcakr*/pkginfo
do
patches=$(nawk -F= '{if ($1 == "PATCHLIST") print $2}' $i)
for patch in $patches
do
if [[ $patch == $req_patch ]]; then
found=1
break
fi
done
if (( $found == 1 )); then
break
fi
done
if (( $found != 1 )); then
log "$f_sanity_downrev" "$patches"
res=1
fi
#
# Check the S10 image for a required version of the emulation.
#
VERS_FILE=/usr/lib/brand/solaris10/version
s10vers_needs=0
if [[ -f $dir/$VERS_FILE ]]; then
s10vers_needs=$(/bin/egrep -v "^#" $dir/$VERS_FILE)
fi
# Now get the current emulation version.
emul_vers=$(/bin/egrep -v "^#" $VERS_FILE)
# Verify that the emulation can run this version of S10.
if (( $s10vers_needs > $emul_vers )); then
log "$f_need_newer_emul"
res=1
fi
if (( $res != 0 )); then
log "$sanity_fail"
fatal "$install_fail" "$ZONENAME"
fi
vlog "$sanity_ok"
}
# Find the active dataset under the zonepath dataset to mount on zonepath/root.
# $1 ZONEPATH_DS
get_active_ds() {
ACTIVE_DS=$1/ROOT/zbe-0
}
#
# Make sure the active dataset is mounted for the zone.
#
mount_active_ds() {
get_zonepath_ds $zonepath
get_active_ds $ZONEPATH_DS
# If already mounted then we're done.
mnted=`zfs get -H mounted $ACTIVE_DS | cut -f3`
[[ $mnted = "yes" ]] && return
mount -F zfs $ACTIVE_DS $zonepath/root || fail_fatal "$f_zfs_mount"
}
#
# Set up ZFS dataset hierarchy for the zone root dataset.
#
create_active_ds() {
# Find the zone's current dataset. This should have been created by
# zoneadm (or the attach hook).
get_zonepath_ds $zonepath
#
# We need to tolerate errors while creating the datasets and making the
# mountpoint, since these could already exist from an attach scenario.
#
/sbin/zfs list -H -o name $ZONEPATH_DS/ROOT >/dev/null 2>&1
if (( $? != 0 )); then
/sbin/zfs create -o mountpoint=legacy -o zoned=on \
$ZONEPATH_DS/ROOT
if (( $? != 0 )); then
fail_fatal "$f_zfs_create"
fi
else
/sbin/zfs set mountpoint=legacy $ZONEPATH_DS/ROOT \
>/dev/null 2>&1
/sbin/zfs set zoned=on $ZONEPATH_DS/ROOT \
>/dev/null 2>&1
fi
get_active_ds $ZONEPATH_DS
zfs list -H -o name $ACTIVE_DS >/dev/null 2>&1
if (( $? != 0 )); then
zfs create -o canmount=noauto $ACTIVE_DS
(( $? != 0 )) && fail_fatal "$f_zfs_create"
else
zfs set canmount=noauto $ACTIVE_DS >/dev/null 2>&1
zfs inherit mountpoint $ACTIVE_DS >/dev/null 2>&1
zfs inherit zoned $ACTIVE_DS >/dev/null 2>&1
fi
if [ ! -d $ZONEROOT ]; then
/bin/mkdir -m 0755 -p $ZONEROOT || \
fail_fatal "$f_mkdir" "$ZONEROOT"
fi
/bin/chmod 700 $ZONEPATH || fail_fatal "$f_chmod" "$ZONEPATH"
mount -F zfs $ACTIVE_DS $ZONEROOT || fail_fatal "$f_zfs_mount"
}
#
# Before booting the zone we may need to create a few mnt points, just in
# case they don't exist for some reason.
#
# Whenever we reach into the zone while running in the global zone we
# need to validate that none of the interim directories are symlinks
# that could cause us to inadvertently modify the global zone.
#
mk_zone_dirs() {
vlog "$v_mkdirs"
if [[ ! -f $ZONEROOT/tmp && ! -d $ZONEROOT/tmp ]]; then
mkdir -m 1777 -p $ZONEROOT/tmp || exit $EXIT_CODE
fi
if [[ ! -f $ZONEROOT/var/run && ! -d $ZONEROOT/var/run ]]; then
mkdir -m 1755 -p $ZONEROOT/var/run || exit $EXIT_CODE
fi
if [[ ! -f $ZONEROOT/var/tmp && ! -d $ZONEROOT/var/tmp ]]; then
mkdir -m 1777 -p $ZONEROOT/var/tmp || exit $EXIT_CODE
fi
if [[ ! -h $ZONEROOT/etc && ! -f $ZONEROOT/etc/mnttab ]]; then
/usr/bin/touch $ZONEROOT/etc/mnttab || exit $EXIT_CODE
/bin/chmod 444 $ZONEROOT/etc/mnttab || exit $EXIT_CODE
fi
if [[ ! -f $ZONEROOT/proc && ! -d $ZONEROOT/proc ]]; then
mkdir -m 755 -p $ZONEROOT/proc || exit $EXIT_CODE
fi
if [[ ! -f $ZONEROOT/dev && ! -d $ZONEROOT/dev ]]; then
mkdir -m 755 -p $ZONEROOT/dev || exit $EXIT_CODE
fi
if [[ ! -h $ZONEROOT/etc && ! -h $ZONEROOT/etc/svc && \
! -d $ZONEROOT/etc/svc ]]; then
mkdir -m 755 -p $ZONEROOT/etc/svc/volatile || exit $EXIT_CODE
fi
}
#
# We're sys-unconfig-ing the zone. This will normally halt the zone, however
# there are problems with sys-unconfig and it can hang when the zone is booted
# to milestone=none. Sys-unconfig also sometimes hangs halting the zone.
# Thus, we take some care to workaround these sys-unconfig limitations.
#
# On entry we expect the zone to be booted. We use sys-unconfig -R to make it
# think its working on an alternate root and let the caller halt the zone.
#
sysunconfig_zone() {
/usr/sbin/zlogin -S $ZONENAME /usr/sbin/sys-unconfig -R /./ \
>/dev/null 2>&1
if (( $? != 0 )); then
error "$e_unconfig"
return 1
fi
return 0
}
#
# Get zone's uuid for service tag.
#
get_inst_uuid()
{
typeset ZONENAME="$1"
ZONEUUID=`zoneadm -z $ZONENAME list -p | nawk -F: '{print $5}'`
[[ $? -ne 0 || -z $ZONEUUID ]] && return 1
INSTANCE_UUID="urn:st:${ZONEUUID}"
return 0
}
#
# Add a service tag for a given zone. We use two UUIDs-- the first,
# the Product UUID, comes from the Sun swoRDFish ontology. The second
# is the UUID of the zone itself, which forms the instance UUID.
#
add_svc_tag()
{
typeset ZONENAME="$1"
typeset SOURCE="$2"
if [ ! -x $STCLIENT ]; then
vlog "$v_no_tags"
return 0
fi
get_inst_uuid "$ZONENAME" || (error "$e_bad_uuid"; return 1)
vlog "$v_addtag" "$INSTANCE_UUID"
$STCLIENT -a \
-p "$ST_PRODUCT_NAME" \
-e "$ST_PRODUCT_REV" \
-t "$ST_PRODUCT_UUID" \
-i "$INSTANCE_UUID" \
-P "none" \
-m "Sun" \
-A `uname -p` \
-z "$ZONENAME" \
-S "$SOURCE" >/dev/null 2>&1
err=$?
# 226 means "duplicate record," which we can ignore.
if [[ $err -ne 0 && $err -ne 226 ]]; then
error "$e_addtag_fail" "$err"
return 1
fi
return 0
}
#
# Remove a service tag for a given zone.
#
del_svc_tag()
{
typeset ZONENAME="$1"
if [ ! -x $STCLIENT ]; then
vlog "$v_no_tags"
return 0
fi
get_inst_uuid "$ZONENAME" || (error "$e_bad_uuid"; return 1)
vlog "$v_deltag" "$INSTANCE_UUID"
$STCLIENT -d -i "$INSTANCE_UUID" >/dev/null 2>&1
return 0
}
<?xml version="1.0"?>
<!--
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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
DO NOT EDIT THIS FILE.
Copyright 2014 Nexenta Systems, Inc. All rights reserved.
-->
<!DOCTYPE brand PUBLIC "-//Sun Microsystems Inc//DTD Brands//EN"
"file:///usr/share/lib/xml/dtd/brand.dtd.1">
<brand name="solaris10">
<modname>s10_brand</modname>
<initname>/sbin/init</initname>
<login_cmd>/usr/bin/login -z %Z %u</login_cmd>
<forcedlogin_cmd>/usr/bin/login -z %Z -f %u</forcedlogin_cmd>
<user_cmd>/usr/bin/getent passwd %u</user_cmd>
<install>/usr/lib/brand/solaris10/image_install %z %R</install>
<installopts>a:d:Fpsuv</installopts>
<boot>/usr/lib/brand/solaris10/s10_boot %z %R</boot>
<sysboot>/usr/lib/brand/solaris10/prestate %z %R 2 0</sysboot>
<halt></halt>
<shutdown>/sbin/shutdown -y -g0 -i5</shutdown>
<verify_cfg>/usr/lib/brand/solaris10/s10_support verify</verify_cfg>
<verify_adm></verify_adm>
<postattach>/usr/lib/brand/solaris10/postattach %z %R</postattach>
<attach>/usr/lib/brand/solaris10/attach %z %R</attach>
<detach>/usr/lib/brand/solaris10/detach %z %R</detach>
<clone>/usr/lib/brand/solaris10/clone -z %z -R %R</clone>
<preuninstall>/usr/lib/brand/solaris10/preuninstall %z %R</preuninstall>
<uninstall>/usr/lib/brand/solaris10/uninstall %z %R</uninstall>
<prestatechange>/usr/lib/brand/solaris10/prestate %z %R</prestatechange>
<poststatechange>/usr/lib/brand/solaris10/poststate %z %R</poststatechange>
<query>/usr/lib/brand/shared/query %z %R</query>
<privilege set="default" name="contract_event" />
<privilege set="default" name="contract_identity" />
<privilege set="default" name="contract_observer" />
<privilege set="default" name="file_chown" />
<privilege set="default" name="file_chown_self" />
<privilege set="default" name="file_dac_execute" />
<privilege set="default" name="file_dac_read" />
<privilege set="default" name="file_dac_search" />
<privilege set="default" name="file_dac_write" />
<privilege set="default" name="file_owner" />
<privilege set="default" name="file_setid" />
<privilege set="default" name="ipc_dac_read" />
<privilege set="default" name="ipc_dac_write" />
<privilege set="default" name="ipc_owner" />
<privilege set="default" name="net_bindmlp" />
<privilege set="default" name="net_icmpaccess" />
<privilege set="default" name="net_mac_aware" />
<privilege set="default" name="net_observability" />
<privilege set="default" name="net_privaddr" />
<privilege set="default" name="net_rawaccess" ip-type="exclusive" />
<privilege set="default" name="proc_chroot" />
<privilege set="default" name="sys_audit" />
<privilege set="default" name="proc_audit" />
<privilege set="default" name="proc_lock_memory" />
<privilege set="default" name="proc_owner" />
<privilege set="default" name="proc_setid" />
<privilege set="default" name="proc_taskid" />
<privilege set="default" name="sys_acct" />
<privilege set="default" name="sys_admin" />
<privilege set="default" name="sys_ip_config" ip-type="exclusive" />
<privilege set="default" name="sys_iptun_config" ip-type="exclusive" />
<privilege set="default" name="sys_mount" />
<privilege set="default" name="sys_nfs" />
<privilege set="default" name="sys_resource" />
<privilege set="default" name="sys_ppp_config" ip-type="exclusive" />
<privilege set="prohibited" name="dtrace_kernel" />
<privilege set="prohibited" name="proc_zone" />
<privilege set="prohibited" name="sys_config" />
<privilege set="prohibited" name="sys_devices" />
<privilege set="prohibited" name="sys_ip_config" ip-type="shared" />
<privilege set="prohibited" name="sys_linkdir" />
<privilege set="prohibited" name="sys_net_config" />
<privilege set="prohibited" name="sys_res_config" />
<privilege set="prohibited" name="sys_suser_compat" />
<privilege set="prohibited" name="xvm_control" />
<privilege set="prohibited" name="virt_manage" />
<privilege set="prohibited" name="sys_ppp_config" ip-type="shared" />
<privilege set="required" name="proc_exec" />
<privilege set="required" name="proc_fork" />
<privilege set="required" name="sys_ip_config" ip-type="exclusive" />
<privilege set="required" name="sys_mount" />
</brand>
#!/bin/ksh -p
#
# 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.
#
. /usr/lib/brand/solaris10/common.ksh
m_usage=$(gettext "solaris10 brand usage: detach [-n].")
EXIT_CODE=$ZONE_SUBPROC_USAGE
# If we weren't passed at least two arguments, exit now.
(( $# < 2 )) && exit $ZONE_SUBPROC_USAGE
ZONENAME="$1"
ZONEPATH="$2"
# XXX shared/common script currently uses lower case zonename & zonepath
zonename="$ZONENAME"
zonepath="$ZONEPATH"
shift; shift # remove ZONENAME and ZONEPATH from arguments array
noexecute=0
# Other brand attach options are invalid for this brand.
while getopts "n" opt; do
case $opt in
n) noexecute=1 ;;
?) printf "$m_usage\n"
exit $ZONE_SUBPROC_USAGE;;
*) printf "$m_usage\n"
exit $ZONE_SUBPROC_USAGE;;
esac
done
shift $((OPTIND-1))
if [[ $noexecute == 1 ]]; then
cat /etc/zones/$ZONENAME.xml
exit $ZONE_SUBPROC_OK
fi
get_zonepath_ds $ZONEPATH
get_active_ds $ZONEPATH_DS
zfs set zoned=off $ACTIVE_DS >/dev/null 2>&1
zfs set canmount=on $ACTIVE_DS >/dev/null 2>&1
zfs set mountpoint=$ZONEPATH/root $ACTIVE_DS >/dev/null 2>&1
cp /etc/zones/$ZONENAME.xml $ZONEPATH/SUNWdetached.xml
# Remove the service tag for this zone.
del_svc_tag "$ZONENAME"
exit $ZONE_SUBPROC_OK
#!/bin/ksh -p
#
# 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.
#
. /usr/lib/brand/solaris10/common.ksh
m_usage=$(gettext "solaris10 brand usage:\n\tinstall -u | -p [-v | -s] -a archive | -d directory.\n\tThe -a archive option specifies an archive name which can be a flar,\n\ttar, pax or cpio archive.\n\tThe -d directory option specifies an existing directory.\n\tThe -u option unconfigures the zone, -p preserves the configuration.")
no_install=$(gettext "Could not create install directory '%s'")
product_vers=$(gettext " Product: %s")
install_vers=$(gettext " Installer: %s")
install_zone=$(gettext " Zone: %s")
install_path=$(gettext " Path: %s")
installing=$(gettext " Installing: This may take several minutes...")
no_installing=$(gettext " Installing: Using pre-existing data in zonepath")
install_prog=$(gettext " Installing: %s")
install_fail=$(gettext " Result: *** Installation FAILED ***")
install_log=$(gettext " Log File: %s")
install_good=$(gettext " Result: Installation completed successfully.")
sanity_ok=$(gettext " Sanity Check: Passed. Looks like a Solaris 10 system.")
sanity_fail=$(gettext " Sanity Check: FAILED (see log for details).")
p2ving=$(gettext "Postprocessing: This may take a while...")
p2v_prog=$(gettext " Postprocess: ")
p2v_done=$(gettext " Result: Postprocessing complete.")
p2v_fail=$(gettext " Result: Postprocessing failed.")
root_full=$(gettext "Zonepath root %s exists and contains data; remove or move aside prior to install.")
media_missing=\
$(gettext "you must specify an installation source using '-a', '-d' or '-r'.\n%s")
cfgchoice_missing=\
$(gettext "you must specify -u (sys-unconfig) or -p (preserve identity).\n%s")
mount_failed=$(gettext "ERROR: zonecfg(8) 'fs' mount failed")
not_flar=$(gettext "Input is not a flash archive")
bad_flar=$(gettext "Flash archive is a corrupt")
unknown_archiver=$(gettext "Archiver %s is not supported")
# Clean up on interrupt
trap_cleanup()
{
msg=$(gettext "Installation cancelled due to interrupt.")
log "$msg"
# umount any mounted file systems
umnt_fs
trap_exit
}
# If the install failed then clean up the ZFS datasets we created.
trap_exit()
{
if (( $EXIT_CODE != $ZONE_SUBPROC_OK )); then
/usr/lib/brand/solaris10/uninstall $ZONENAME $ZONEPATH -F
fi
exit $EXIT_CODE
}
#
# The main body of the script starts here.
#
# This script should never be called directly by a user but rather should
# only be called by zoneadm to install a s10 system image into a zone.
#
#
# Exit code to return if install is interrupted or exit code is otherwise
# unspecified.
#
EXIT_CODE=$ZONE_SUBPROC_USAGE
trap trap_cleanup INT
trap trap_exit EXIT
# If we weren't passed at least two arguments, exit now.
(( $# < 2 )) && exit $ZONE_SUBPROC_USAGE
ZONENAME="$1"
ZONEPATH="$2"
# XXX shared/common script currently uses lower case zonename & zonepath
zonename="$ZONENAME"
zonepath="$ZONEPATH"
ZONEROOT="$ZONEPATH/root"
logdir="$ZONEROOT/var/log"
shift; shift # remove ZONENAME and ZONEPATH from arguments array
unset inst_type
unset msg
unset silent_mode
unset OPT_V
#
# It is worth noting here that we require the end user to pick one of
# -u (sys-unconfig) or -p (preserve config). This is because we can't
# really know in advance which option makes a better default. Forcing
# the user to pick one or the other means that they will consider their
# choice and hopefully not be surprised or disappointed with the result.
#
unset unconfig_zone
unset preserve_zone
unset SANITY_SKIP
while getopts "a:d:Fpr:suv" opt
do
case "$opt" in
a)
if [[ -n "$inst_type" ]]; then
fatal "$incompat_options" "$m_usage"
fi
inst_type="archive"
install_media="$OPTARG"
;;
d)
if [[ -n "$inst_type" ]]; then
fatal "$incompat_options" "$m_usage"
fi
inst_type="directory"
install_media="$OPTARG"
;;
F) SANITY_SKIP=1;;
p) preserve_zone="-p";;
r)
if [[ -n "$inst_type" ]]; then
fatal "$incompat_options" "$m_usage"
fi
inst_type="stdin"
install_media="$OPTARG"
;;
s) silent_mode=1;;
u) unconfig_zone="-u";;
v) OPT_V="-v";;
*) printf "$m_usage\n"
exit $ZONE_SUBPROC_USAGE;;
esac
done
shift OPTIND-1
# The install can't be both verbose AND silent...
if [[ -n $silent_mode && -n $OPT_V ]]; then
fatal "$incompat_options" "$m_usage"
fi
if [[ -z $install_media ]]; then
fatal "$media_missing" "$m_usage"
fi
# The install can't both preserve and unconfigure
if [[ -n $unconfig_zone && -n $preserve_zone ]]; then
fatal "$incompat_options" "$m_usage"
fi
# Must pick one or the other.
if [[ -z $unconfig_zone && -z $preserve_zone ]]; then
fatal "$cfgchoice_missing" "$m_usage"
fi
LOGFILE=$(/usr/bin/mktemp -t -p /var/tmp $ZONENAME.install_log.XXXXXX)
if [[ -z "$LOGFILE" ]]; then
fatal "$e_tmpfile"
fi
zone_logfile="${logdir}/$ZONENAME.install$$.log"
exec 2>>"$LOGFILE"
log "$install_log" "$LOGFILE"
vlog "Starting pre-installation tasks."
#
# From here on out, an unspecified exit or interrupt should exit with
# ZONE_SUBPROC_NOTCOMPLETE, meaning a user will need to do an uninstall before
# attempting another install, as we've modified the directories we were going
# to install to in some way.
#
EXIT_CODE=$ZONE_SUBPROC_NOTCOMPLETE
create_active_ds
vlog "Installation started for zone \"$ZONENAME\""
install_image "$inst_type" "$install_media"
[[ "$SANITY_SKIP" == "1" ]] && touch $ZONEROOT/.sanity_skip
log "$p2ving"
vlog "running: p2v $OPT_V $unconfig_zone $ZONENAME $ZONEPATH"
#
# Run p2v.
#
# Getting the output to the right places is a little tricky because what
# we want is for p2v to output in the same way the installer does: verbose
# messages to the log file always, and verbose messages printed to the
# user if the user passes -v. This rules out simple redirection. And
# we can't use tee or other tricks because they cause us to lose the
# return value from the p2v script due to the way shell pipelines work.
#
# The simplest way to do this seems to be to hand off the management of
# the log file to the p2v script. So we run p2v with -l to tell it where
# to find the log file and then reopen the log (O_APPEND) when p2v is done.
#
/usr/lib/brand/solaris10/p2v -l "$LOGFILE" -m "$p2v_prog" \
$OPT_V $unconfig_zone $ZONENAME $ZONEPATH
p2v_result=$?
exec 2>>$LOGFILE
if (( $p2v_result == 0 )); then
vlog "$p2v_done"
else
log "$p2v_fail"
log ""
log "$install_fail"
log "$install_log" "$LOGFILE"
exit $ZONE_SUBPROC_FATAL
fi
# Add a service tag for this zone.
add_svc_tag "$ZONENAME" "install $inst_type `basename $install_media`"
log ""
log "$install_good" "$ZONENAME"
safe_dir /var
safe_dir /var/log
safe_copy $LOGFILE $zone_logfile
log "$install_log" "$zone_logfile"
rm -f $LOGFILE
# This needs to be set since the exit trap handler is going run.
EXIT_CODE=$ZONE_SUBPROC_OK
exit $ZONE_SUBPROC_OK
#!/bin/ksh -p
#
# 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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
# NOTE: this script runs in the global zone and touches the non-global
# zone, so care should be taken to validate any modifications so that they
# are safe.
. /usr/lib/brand/solaris10/common.ksh
LOGFILE=
MSG_PREFIX="p2v: "
EXIT_CODE=1
usage()
{
echo "$0 [-s] [-m msgprefix] [-u] [-v] [-b patchid]* zonename" >&2
exit $EXIT_CODE
}
# Clean up on interrupt
trap_cleanup()
{
msg=$(gettext "Postprocessing cancelled due to interrupt.")
error "$msg"
if (( $zone_is_running != 0 )); then
error "$e_shutdown" "$ZONENAME"
/usr/sbin/zoneadm -z $ZONENAME halt
fi
#
# Delete temporary files created during the hollow package removal
# process.
#
rm -f $hollow_pkgs $hollow_file_list $hollow_dir_list
exit $EXIT_CODE
}
#
# Disable any existing live-upgrade configuration.
# We have already called safe_dir to validate the etc/lu directory.
#
fix_lu()
{
ludir=$ZONEROOT/etc/lu
[[ ! -d $ludir ]] && return
safe_rm etc/lutab
safe_rm etc/lu/.BE_CONFIG
safe_rm etc/lu/.CURR_VARS
safe_rm etc/lu/ludb.local.xml
for i in $ludir/ICF* $ludir/vtoc* $ludir/GRUB*
do
nm=`basename $i`
safe_rm etc/lu/$nm
done
}
#
# For an exclusive stack zone, fix up the network configuration files.
# We need to do this even if unconfiguring the zone so sys-unconfig works
# correctly.
#
fix_net()
{
[[ "$STACK_TYPE" == "shared" ]] && return
NETIF_CNT=$(/bin/ls $ZONEROOT/etc/hostname.* 2>/dev/null | \
/usr/bin/wc -l)
if (( $NETIF_CNT != 1 )); then
vlog "$v_nonetfix"
return
fi
NET=$(LC_ALL=C /usr/sbin/zonecfg -z $ZONENAME info net)
if (( $? != 0 )); then
error "$e_badinfo" "net"
return
fi
NETIF=$(echo $NET | /bin/nawk '{
for (i = 1; i < NF; i++) {
if ($i == "physical:") {
if (length(net) == 0) {
i++
net = $i
} else {
multiple=1
}
}
}
}
END { if (!multiple)
print net
}')
if [[ -z "$NETIF" ]]; then
vlog "$v_nonetfix"
return
fi
OLD_HOSTNET=$(/bin/ls $ZONEROOT/etc/hostname.*)
if [[ "$OLD_HOSTNET" != "$ZONEROOT/etc/hostname.$NETIF" ]]; then
safe_move $OLD_HOSTNET $ZONEROOT/etc/hostname.$NETIF
fi
}
#
# Disable all of the shares since the zone cannot be an NFS server.
# Note that we disable the various instances of the svc:/network/shares/group
# SMF service in the fix_smf function.
#
fix_nfs()
{
zonedfs=$ZONEROOT/etc/dfs
[[ ! -d $zonedfs ]] && return
if [[ -h $zonedfs/dfstab || ! -f $zonedfs/dfstab ]]; then
error "$e_badfile" "/etc/dfs/dfstab"
return
fi
tmpfile=$(mktemp -t)
if [[ $? == 1 || -z "$tmpfile" ]]; then
error "$e_tmpfile"
return
fi
/bin/nawk '{
if (substr($1, 0, 1) == "#") {
print $0
} else {
print "#", $0
modified=1
}
}
END {
if (modified == 1) {
printf("# Modified by p2v ")
system("/bin/date")
exit 0
}
exit 1
}' $zonedfs/dfstab >>$tmpfile
if (( $? == 0 )); then
if [[ ! -f $zonedfs/dfstab.pre_p2v ]]; then
safe_copy $zonedfs/dfstab $zonedfs/dfstab.pre_p2v
fi
safe_copy $tmpfile $zonedfs/dfstab
chown root:sys $zonedfs/dfstab || \
fail_fatal "$f_chown" "$zonedfs/dfstab"
chmod 644 $zonedfs/dfstab || \
fail_fatal "$f_chmod" "$zonedfs/dfstab"
fi
/bin/rm -f $tmpfile
}
#
# Comment out most of the old mounts since they are either unneeded or
# likely incorrect within a zone. Specific mounts can be manually
# reenabled if the corresponding device is added to the zone.
#
fix_vfstab()
{
if [[ -h $ZONEROOT/etc/vfstab || ! -f $ZONEROOT/etc/vfstab ]]; then
error "$e_badfile" "/etc/vfstab"
return
fi
tmpfile=$(mktemp -t)
if [[ $? == 1 || -z "$tmpfile" ]]; then
error "$e_tmpfile"
return
fi
/bin/nawk '{
if (substr($1, 0, 1) == "#") {
print $0
} else if ($1 == "fd" || $1 == "/proc" || $1 == "swap" ||
$1 == "ctfs" || $1 == "objfs" || $1 == "sharefs" ||
$4 == "nfs" || $4 == "lofs") {
print $0
} else {
print "#", $0
modified=1
}
}
END {
if (modified == 1) {
printf("# Modified by p2v ")
system("/bin/date")
exit 0
}
exit 1
}' $ZONEROOT/etc/vfstab >>$tmpfile
if (( $? == 0 )); then
if [[ ! -f $ZONEROOT/etc/vfstab.pre_p2v ]]; then
safe_copy $ZONEROOT/etc/vfstab \
$ZONEROOT/etc/vfstab.pre_p2v
fi
safe_copy $tmpfile $ZONEROOT/etc/vfstab
chown root:sys $ZONEROOT/etc/vfstab || \
fail_fatal "$f_chown" "$ZONEROOT/etc/vfstab"
chmod 644 $ZONEROOT/etc/vfstab || \
fail_fatal "$f_chmod" "$ZONEROOT/etc/vfstab"
fi
/bin/rm -f $tmpfile
}
#
# Collect the data needed to delete SMF services. Since we're p2v-ing a
# physical image there are SMF services which must be deleted.
#
fix_smf_pre_uoa()
{
#
# Start by getting the svc manifests that are delivered by hollow
# pkgs then use 'svccfg inventory' to get the names of the svcs
# delivered by those manifests. The svc names are saved into a
# temporary file.
#
SMFTMPFILE=$(mktemp -t smf.XXXXXX)
if [[ $? == 1 || -z "$SMFTMPFILE" ]]; then
error "$e_tmpfile"
return
fi
for i in $ZONEROOT/var/sadm/pkg/*
do
pkg=$(/bin/basename $i)
[[ ! -f $ZONEROOT/var/sadm/pkg/$pkg/save/pspool/$pkg/pkgmap ]] \
&& continue
/bin/egrep -s "SUNW_PKG_HOLLOW=true" \
$ZONEROOT/var/sadm/pkg/$pkg/pkginfo || continue
for j in $(/bin/nawk '{if ($2 == "f" &&
substr($4, 1, 17) == "var/svc/manifest/") print $4}' \
$ZONEROOT/var/sadm/pkg/$pkg/save/pspool/$pkg/pkgmap)
do
svcs=$(SVCCFG_NOVALIDATE=1 \
SVCCFG_REPOSITORY=$ZONEROOT/etc/svc/repository.db \
/sbin/svccfg inventory $ZONEROOT/$j)
for k in $svcs
do
echo $k /$j >> $SMFTMPFILE
done
done
done
}
#
# Delete or disable SMF services.
# Zone is booted to milestone=none when this function is called.
# Use the SMF data collected by fix_smf_pre_uoa() to delete the services.
#
fix_smf()
{
#
# Zone was already booted to milestone=none, wait until SMF door exists.
#
for i in 0 1 2 3 4 5 6 7 8 9
do
[[ -r $ZONEROOT/etc/svc/volatile/repository_door ]] && break
sleep 5
done
if [[ $i -eq 9 && ! -r $ZONEROOT/etc/svc/volatile/repository_door ]];
then
#
# The zone never booted, something is wrong.
#
error "$e_nosmf"
error "$e_bootfail"
/bin/rm -f $SMFTMPFILE
return 1
fi
insttmpfile=$(mktemp -t instsmf.XXXXXX)
if [[ $? == 1 || -z "$insttmpfile" ]]; then
error "$e_tmpfile"
/bin/rm -f $SMFTMPFILE
return 1
fi
vlog "$v_rmhollowsvcs"
while read fmri mfst
do
# Delete the svc.
vlog "$v_delsvc" "$fmri"
echo "/sbin/svccfg delete -f $fmri"
echo "/sbin/svccfg delhash -d $mfst"
echo "rm -f $mfst"
done < $SMFTMPFILE > $ZONEROOT/tmp/smf_rm
/usr/sbin/zlogin -S $ZONENAME /bin/sh /tmp/smf_rm >/dev/null 2>&1
/bin/rm -f $SMFTMPFILE
# Get a list of the svcs that now exist in the zone.
LANG=C /usr/sbin/zlogin -S $ZONENAME /usr/bin/svcs -aH | \
/bin/nawk '{print $3}' >>$insttmpfile
[[ -n $LOGFILE ]] && \
printf "[$(date)] ${MSG_PREFIX}${v_svcsinzone}\n" >&2
[[ -n $LOGFILE ]] && cat $insttmpfile >&2
#
# Import ip-interface-management service in S10C, network
# loopback service requires ipmgmtd in exclusive stack zones.
#
/usr/sbin/zlogin -S $ZONENAME /sbin/svccfg import \
$ZONEROOT/var/svc/manifest/network/network-ipmgmt.xml
#
# Fix network services if shared stack.
#
if [[ "$STACK_TYPE" == "shared" ]]; then
vlog "$v_fixnetsvcs"
NETPHYSDEF="svc:/network/physical:default"
NETPHYSNWAM="svc:/network/physical:nwam"
/bin/egrep -s "$NETPHYSDEF" $insttmpfile
if (( $? == 0 )); then
vlog "$v_enblsvc" "$NETPHYSDEF"
/usr/sbin/zlogin -S $ZONENAME \
/sbin/svcadm enable $NETPHYSDEF || \
error "$e_dissvc" "$NETPHYSDEF"
fi
/bin/egrep -s "$NETPHYSNWAM" $insttmpfile
if (( $? == 0 )); then
vlog "$v_dissvc" "$NETPHYSNWAM"
/usr/sbin/zlogin -S $ZONENAME \
/sbin/svcadm disable $NETPHYSNWAM || \
error "$e_enblsvc" "$NETPHYSNWAM"
fi
for i in $(/bin/egrep network/routing $insttmpfile)
do
# Disable the svc.
vlog "$v_dissvc" "$i"
/usr/sbin/zlogin -S $ZONENAME \
/sbin/svcadm disable $i || \
error "$e_dissvc" $i
done
fi
#
# Disable well-known services that don't run in a zone.
#
vlog "$v_rminvalidsvcs"
for i in $(/bin/egrep -hv "^#" \
/usr/lib/brand/solaris10/smf_disable.lst \
/etc/brand/solaris10/smf_disable.conf)
do
# Skip svcs not installed in the zone.
/bin/egrep -s "$i:" $insttmpfile || continue
# Disable the svc.
vlog "$v_dissvc" "$i"
/usr/sbin/zlogin -S $ZONENAME /sbin/svcadm disable $i || \
error "$e_dissvc" $i
done
#
# Since zones can't be NFS servers, disable all of the instances of
# the shares svc.
#
for i in $(/bin/egrep network/shares/group $insttmpfile)
do
vlog "$v_dissvc" "$i"
/usr/sbin/zlogin -S $ZONENAME /sbin/svcadm disable $i || \
error "$e_dissvc" $i
done
/bin/rm -f $insttmpfile
return 0
}
#
# Remove well-known pkgs that do not work inside a zone.
#
rm_pkgs()
{
/bin/cat <<-EOF > $ZONEROOT/tmp/admin || fatal "$e_adminf"
mail=
instance=overwrite
partial=nocheck
runlevel=nocheck
idepend=nocheck
rdepend=nocheck
space=nocheck
setuid=nocheck
conflict=nocheck
action=nocheck
basedir=default
EOF
for i in $(/bin/egrep -hv "^#" /usr/lib/brand/solaris10/pkgrm.lst \
/etc/brand/solaris10/pkgrm.conf)
do
[[ ! -d $ZONEROOT/var/sadm/pkg/$i ]] && continue
vlog "$v_rmpkg" "$i"
/usr/sbin/zlogin -S $ZONENAME \
/usr/sbin/pkgrm -na /tmp/admin $i >&2 || error "$e_rmpkg" $i
done
}
#
# Zoneadmd writes a one-line index file into the zone when the zone boots,
# so any information about installed zones from the original system will
# be lost at that time. Here we'll warn the sysadmin about any pre-existing
# zones that they might want to clean up by hand, but we'll leave the zonepaths
# in place in case they're on shared storage and will be migrated to
# a new host.
#
warn_zones()
{
zoneconfig=$ZONEROOT/etc/zones
[[ ! -d $zoneconfig ]] && return
if [[ -h $zoneconfig/index || ! -f $zoneconfig/index ]]; then
error "$e_badfile" "/etc/zones/index"
return
fi
NGZ=$(/bin/nawk -F: '{
if (substr($1, 0, 1) == "#" || $1 == "global")
next
if ($2 == "installed")
printf("%s ", $1)
}' $zoneconfig/index)
# Return if there are no installed zones to warn about.
[[ -z "$NGZ" ]] && return
log "$v_rmzones" "$NGZ"
NGZP=$(/bin/nawk -F: '{
if (substr($1, 0, 1) == "#" || $1 == "global")
continue
if ($2 == "installed")
printf("%s ", $3)
}' $zoneconfig/index)
log "$v_rmzonepaths"
for i in $NGZP
do
log " %s" "$i"
done
}
#
# ^C Should cleanup; if the zone is running, it should try to halt it.
#
zone_is_running=0
trap trap_cleanup INT
#
# Parse the command line options.
#
OPT_U=
OPT_V=
OPT_M=
OPT_L=
while getopts "uvm:l:" opt
do
case "$opt" in
u) OPT_U="-u";;
v) OPT_V="-v";;
m) MSG_PREFIX="$OPTARG"; OPT_M="-m \"$OPTARG\"";;
l) LOGFILE="$OPTARG"; OPT_L="-l \"$OPTARG\"";;
*) usage;;
esac
done
shift OPTIND-1
(( $# < 1 )) && usage
(( $# > 2 )) && usage
[[ -n $LOGFILE ]] && exec 2>>$LOGFILE
ZONENAME=$1
ZONEPATH=$2
# XXX shared/common script currently uses lower case zonename & zonepath
zonename="$ZONENAME"
zonepath="$ZONEPATH"
ZONEROOT=$ZONEPATH/root
e_badinfo=$(gettext "Failed to get '%s' zone resource")
e_badfile=$(gettext "Invalid '%s' file within the zone")
v_mkdirs=$(gettext "Creating mount points")
v_nonetfix=$(gettext "Cannot update /etc/hostname.{net} file")
v_adjust=$(gettext "Updating the image to run within a zone")
v_stacktype=$(gettext "Stack type '%s'")
v_booting=$(gettext "Booting zone to single user mode")
e_bootfail=$(gettext "Failed to boot zone to single user mode.")
e_nosmf=$(gettext "SMF repository unavailable.")
v_svcsinzone=$(gettext "The following SMF services are installed:")
v_rmhollowsvcs=$(gettext "Deleting SMF services from hollow packages")
v_fixnetsvcs=$(gettext "Adjusting network SMF services")
v_rminvalidsvcs=$(gettext "Disabling invalid SMF services")
v_delsvc=$(gettext "Delete SMF svc '%s'")
e_delsvc=$(gettext "deleting SMF svc '%s'")
v_enblsvc=$(gettext "Enable SMF svc '%s'")
e_enblsvc=$(gettext "enabling SMF svc '%s'")
v_dissvc=$(gettext "Disable SMF svc '%s'")
e_dissvc=$(gettext "disabling SMF svc '%s'")
e_adminf=$(gettext "Unable to create admin file")
v_rmpkg=$(gettext "Remove package '%s'")
e_rmpkg=$(gettext "removing package '%s'")
v_rmzones=$(gettext "The following zones in this image will be unusable: %s")
v_rmzonepaths=$(gettext "These zonepaths could be removed from this image:")
v_halting=$(gettext "Halting zone")
e_shutdown=$(gettext "Shutting down zone %s...")
e_badhalt=$(gettext "Zone halt failed")
v_exitgood=$(gettext "Postprocessing successful.")
e_exitfail=$(gettext "Postprocessing failed.")
#
# Do some validation on the paths we'll be accessing
#
safe_dir /etc
safe_dir /var
safe_dir /var/sadm
safe_dir /var/sadm/install
safe_dir /var/sadm/pkg
safe_opt_dir /etc/dfs
safe_opt_dir /etc/lu
safe_opt_dir /etc/zones
mk_zone_dirs
# Now do the work to update the zone.
# Check for zones inside of image.
warn_zones
fix_smf_pre_uoa
log "$v_adjust"
#
# Any errors in these functions are not considered fatal. The zone can be
# be fixed up manually afterwards and it may need some additional manual
# cleanup in any case.
#
STACK_TYPE=$(/usr/sbin/zoneadm -z $ZONENAME list -p | \
/bin/nawk -F: '{print $7}')
if (( $? != 0 )); then
error "$e_badinfo" "stacktype"
fi
vlog "$v_stacktype" "$STACK_TYPE"
fix_lu
fix_net
fix_nfs
fix_vfstab
vlog "$v_booting"
#
# Boot the zone so that we can do all of the SMF updates needed on the zone's
# repository.
#
zone_is_running=1
/usr/sbin/zoneadm -z $ZONENAME boot -f -- -m milestone=none
if (( $? != 0 )); then
error "$e_badboot"
/bin/rm -f $SMFTMPFILE
fatal "$e_exitfail"
fi
#
# Remove all files and directories installed by hollow packages. Such files
# and directories shouldn't exist inside zones.
#
hollow_pkgs=$(mktemp -t .hollow.pkgs.XXXXXX)
hollow_file_list=$(mktemp $ZONEROOT/.hollow.pkgs.files.XXXXXX)
hollow_dir_list=$(mktemp $ZONEROOT/.hollow.pkgs.dirs.XXXXXX)
[ -f "$hollow_pkgs" -a -f "$hollow_file_list" -a -f "$hollow_dir_list" ] || {
error "$e_tmpfile"
rm -f $hollow_pkgs $hollow_file_list $hollow_dir_list
fatal "$e_exitfail"
}
for pkg_name in $ZONEROOT/var/sadm/pkg/*; do
grep 'SUNW_PKG_HOLLOW=true' $pkg_name/pkginfo >/dev/null 2>&1 && \
basename $pkg_name >>$hollow_pkgs
done
/bin/nawk -v hollowpkgs=$hollow_pkgs -v filelist=$hollow_file_list \
-v dirlist=$hollow_dir_list '
BEGIN {
while (getline p <hollowpkgs > 0)
pkgs[p] = 1;
close(hollowpkgs);
}
{
# fld is the field where the pkg names begin.
# nm is the file/dir entry name.
if ($2 == "f") {
fld=10;
nm=$1;
} else if ($2 == "d") {
fld=7;
nm=$1;
} else if ($2 == "s" || $2 == "l") {
fld=4;
split($1, a, "=");
nm=a[1];
} else {
next;
}
# Determine whether the file or directory is delivered by any
# non-hollow packages. Files and directories can be
# delivered by multiple pkgs. The file or directory should only
# be removed if it is only delivered by hollow packages.
for (i = fld; i <= NF; i++) {
if (pkgs[get_pkg_name($i)] != 1) {
# We encountered a non-hollow package. Skip
# this entry.
next;
}
}
# The file or directory is only delivered by hollow packages.
# Mark it for removal.
if (fld != 7)
print nm >>filelist
else
print nm >>dirlist
}
# Get the clean pkg name from the fld entry.
function get_pkg_name(fld) {
# Remove any pkg control prefix (e.g. *, !)
first = substr(fld, 1, 1)
if (match(first, /[A-Za-z]/)) {
pname = fld
} else {
pname = substr(fld, 2)
}
# Then remove any class action script name
pos = index(pname, ":")
if (pos != 0)
pname = substr(pname, 1, pos - 1)
return (pname)
}
' $ZONEROOT/var/sadm/install/contents
/usr/sbin/zlogin -S $ZONENAME "cat /$(basename $hollow_file_list) | xargs rm -f"
/usr/sbin/zlogin -S $ZONENAME "sort -r /$(basename $hollow_dir_list) | \
xargs rmdir >/dev/null 2>&1"
rm -f $hollow_pkgs $hollow_file_list $hollow_dir_list
# cleanup SMF services
fix_smf || failed=1
# remove invalid pkgs
[[ -z $failed ]] && rm_pkgs
if [[ -z $failed && -n $OPT_U ]]; then
vlog "$v_unconfig"
sysunconfig_zone
if (( $? != 0 )); then
failed=1
fi
fi
vlog "$v_halting"
/usr/sbin/zoneadm -z $ZONENAME halt
if (( $? != 0 )); then
error "$e_badhalt"
failed=1
fi
zone_is_running=0
if [[ -n $failed ]]; then
fatal "$e_exitfail"
fi
vlog "$v_exitgood"
exit 0
#
# 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.
#
# This is a list of SVr4 packages which should be removed when installing
# the zone. Site-specific packages which must be removed should be listed
# in this file. During the zone installation, the packages will be removed
# if they existed on the original physical system.
#
#
# 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.
#
# This is a list of SVr4 packages which should be removed when installing
# the zone. Do not edit this file. Site-specific packages which must be
# removed should be listed in the /etc/brand/solaris10/pkgrm.conf file.
# During the zone installation, the packages will be removed if they existed
# on the original physical system.
#
VRTSvxvm
<?xml version="1.0"?>
<!--
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.
DO NOT EDIT THIS FILE.
-->
<!DOCTYPE platform PUBLIC "-//Sun Microsystems Inc//Zones Platform//EN"
"file:///usr/share/lib/xml/dtd/zone_platform.dtd.1">
<platform name="solaris10" allow-exclusive-ip="true">
<!-- Global filesystems to mount when booting the zone -->
<global_mount special="/dev" directory="/dev" type="dev"
opt="attrdir=%R/dev"/>
<!--
Local filesystems to mount when booting the zone. The
/.SUNWnative/platform entry is needed so that we can symlink a
platform-specific libc_psr for platforms which were not delivered
with S10. The /.SUNWnative/sbin entry is needed so that we can
replace ifconfig with its native counterpart (this is required for
exclusive-stack S10 zones to work).
-->
<global_mount special="/usr" directory="/.SUNWnative/usr"
opt="ro,nodevices" type="lofs" />
<global_mount special="/lib" directory="/.SUNWnative/lib"
opt="ro,nodevices" type="lofs" />
<global_mount special="/platform" directory="/.SUNWnative/platform"
opt="ro,nodevices" type="lofs" />
<global_mount special="/sbin" directory="/.SUNWnative/sbin"
opt="ro,nodevices" type="lofs" />
<!-- Local filesystems to mount when booting the zone -->
<mount special="/proc" directory="/proc" type="proc" />
<mount special="ctfs" directory="/system/contract" type="ctfs" />
<mount special="mnttab" directory="/etc/mnttab" type="mntfs" />
<mount special="objfs" directory="/system/object" type="objfs" />
<mount special="swap" directory="/etc/svc/volatile" type="tmpfs" />
<!-- Devices to create under /dev -->
<device match="arp" />
<device match="bpf" />
<device match="conslog" />
<device match="cpu/self/cpuid" />
<device match="crypto" />
<device match="cryptoadm" />
<device match="dsk" />
<device match="dtrace/*" />
<device match="dtrace/provider/*" />
<device match="fd" />
<device match="full" />
<device match="ipnet" />
<device match="kstat" />
<device match="lo0" />
<device match="lofictl" />
<device match="lofi" />
<device match="log" />
<device match="logindmux" />
<device match="nsmb" />
<device match="net/*" />
<device match="null" />
<device match="openprom" arch="sparc" />
<device match="poll" />
<device match="pool" />
<device match="ptmx" />
<device match="pts/*" />
<device match="random" />
<device match="rdsk" />
<device match="rlofi" />
<device match="rmt" />
<device match="sad/user" />
<device match="svvslo0" />
<device match="svvslo1" />
<device match="svvslo2" />
<device match="svvslo3" />
<device match="swap" />
<device match="sysevent" />
<device match="tcp" />
<device match="tcp6" />
<device match="term" />
<device match="ticlts" />
<device match="ticots" />
<device match="ticotsord" />
<device match="tty" />
<device match="udp" />
<device match="udp6" />
<device match="urandom" />
<device match="zero" />
<device match="zfs" />
<!-- Devices to create in exclusive IP zone only -->
<device match="dld" ip-type="exclusive" />
<device match="icmp" ip-type="exclusive" />
<device match="icmp6" ip-type="exclusive" />
<device match="ip" ip-type="exclusive" />
<device match="ip6" ip-type="exclusive" />
<device match="ipauth" ip-type="exclusive" />
<device match="ipf" ip-type="exclusive" />
<device match="ipl" ip-type="exclusive" />
<device match="iplookup" ip-type="exclusive" />
<device match="ipmpstub" ip-type="exclusive" />
<device match="ipnat" ip-type="exclusive" />
<device match="ipscan" ip-type="exclusive" />
<device match="ipsecah" ip-type="exclusive" />
<device match="ipsecesp" ip-type="exclusive" />
<device match="ipstate" ip-type="exclusive" />
<device match="ipsync" ip-type="exclusive" />
<device match="keysock" ip-type="exclusive" />
<device match="rawip" ip-type="exclusive" />
<device match="rawip6" ip-type="exclusive" />
<device match="rts" ip-type="exclusive" />
<device match="sad/admin" ip-type="exclusive" />
<device match="sctp" ip-type="exclusive" />
<device match="sctp6" ip-type="exclusive" />
<device match="spdsock" ip-type="exclusive" />
<device match="sppp" ip-type="exclusive" />
<device match="sppptun" ip-type="exclusive" />
<device match="vni" ip-type="exclusive" />
<!-- Renamed devices to create under /dev -->
<device match="zcons/%z/zoneconsole" name="zconsole" />
<!-- Symlinks to create under /dev -->
<symlink source="console" target="zconsole" />
<symlink source="dtremote" target="/dev/null" />
<symlink source="msglog" target="zconsole" />
<symlink source="stderr" target="./fd/2" />
<symlink source="stdin" target="./fd/0" />
<symlink source="stdout" target="./fd/1" />
<symlink source="syscon" target="zconsole" />
<symlink source="sysmsg" target="zconsole" />
<symlink source="systty" target="zconsole" />
</platform>
#!/bin/ksh -p
#
# 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.
#
#
# This postattach hook adds the service tag for the zone.
# We need this in a postattach hook since the zone doesn't have
# a UUID when the attach hook is run.
#
. /usr/lib/brand/solaris10/common.ksh
install_media="-"
# If we weren't passed at least two arguments, exit now.
(( $# < 2 )) && exit $ZONE_SUBPROC_OK
ZONENAME="$1"
ZONEPATH="$2"
shift 2
noexecute=0
unset inst_type
#
# This hook will see the same options as the attach hook, so make sure
# we accept all of these.
#
while getopts "a:d:nr:" opt; do
case $opt in
a)
inst_type="archive"
install_media="$OPTARG"
;;
d)
inst_type="directory"
install_media="$OPTARG"
;;
n) noexecute=1 ;;
r)
inst_type="stdin"
install_media="$OPTARG"
;;
?) exit $ZONE_SUBPROC_OK;;
*) exit $ZONE_SUBPROC_OK;;
esac
done
shift $((OPTIND-1))
[ $noexecute -eq 1 ] && exit $ZONE_SUBPROC_OK
[[ -z "$inst_type" ]] && inst_type="directory"
# Add a service tag for this zone.
add_svc_tag "$ZONENAME" "attach $inst_type `basename $install_media`"
exit $ZONE_SUBPROC_OK
#!/bin/ksh -p
#
# 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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
. /usr/lib/brand/solaris10/common.ksh
# States
# ZONE_STATE_CONFIGURED 0 (never see)
# ZONE_STATE_INCOMPLETE 1 (never see)
# ZONE_STATE_INSTALLED 2
# ZONE_STATE_READY 3
# ZONE_STATE_RUNNING 4
# ZONE_STATE_SHUTTING_DOWN 5
# ZONE_STATE_DOWN 6
# ZONE_STATE_MOUNTED 7
# cmd
#
# ready 0
# boot 1
# halt 4
zonename=$1
zonepath=$2
state=$3
cmd=$4
altroot=$5 # unused at this time for s10 branded zones
# If we're readying the zone, update the zone index file to look like this is
# the global zone.
if (( $cmd == 0 )); then
echo "global:installed:/" > $zonepath/root/etc/zones/index
fi
exit 0
#!/bin/ksh -p
#
# 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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
. /usr/lib/brand/solaris10/common.ksh
# States
# ZONE_STATE_CONFIGURED 0 (never see)
# ZONE_STATE_INCOMPLETE 1 (never see)
# ZONE_STATE_INSTALLED 2
# ZONE_STATE_READY 3
# ZONE_STATE_RUNNING 4
# ZONE_STATE_SHUTTING_DOWN 5
# ZONE_STATE_DOWN 6
# ZONE_STATE_MOUNTED 7
# cmd
#
# ready 0
# boot 1
# halt 4
zonename=$1
zonepath=$2
state=$3
cmd=$4
altroot=$5 # unused at this time for s10 branded zones
# If we're not readying the zone, then just return.
if (( $cmd == 0 )); then
# Mount active dataset on the root.
mount_active_ds
fi
exit $ZONE_SUBPROC_OK
#!/bin/ksh -p
#
# 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.
#
#
# This preuninstall hook removes the service tag for the zone.
# We need this in a preuninstall hook since once the zone state is
# changed to 'incomplete' (which happens before we run the uninstall hook)
# then the zone gets a new UUID and we can no longer figure out which
# service tag instance to delete.
#
#
# common shell script functions
#
. /usr/lib/brand/solaris10/common.ksh
# If we weren't passed at least two arguments, exit now.
(( $# < 2 )) && exit $ZONE_SUBPROC_USAGE
ZONENAME=$1
ZONEPATH=$2
shift 2
#
# This hook will see the same options as the uninstall hook, so make sure
# we accept these even though all but -n are ignored.
#
options="FhHnv"
nop=""
# process options
OPTIND=1
while getopts :$options OPT ; do
case $OPT in
F ) ;;
h|H ) exit $ZONE_SUBPROC_OK ;;
n ) nop="echo" ;;
v ) ;;
esac
done
shift `expr $OPTIND - 1`
[ $# -gt 0 ] && exit $ZONE_SUBPROC_OK
# Remove the service tag for this zone.
$nop del_svc_tag "$ZONENAME"
exit $ZONE_SUBPROC_OK
#!/bin/ksh -p
#
# 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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2024 OmniOS Community Edition (OmniOSce) Association.
#
# s10 boot script.
#
# The arguments to this script are the zone name and the zonepath.
#
. /usr/lib/brand/solaris10/common.ksh
ZONENAME=$1
ZONEPATH=$2
ZONEROOT=$ZONEPATH/root
w_missing=$(gettext "Warning: \"%s\" is not installed in the global zone")
arch=`uname -p`
if [ "$arch" = "amd64" ] || [ "$arch" = "i386" ]; then
ARCH32=i86
ARCH64=amd64
elif [ "$arch" = "sparc" ]; then
# 32-bit SPARC not supported!
ARCH32=
ARCH64=sparcv9
else
echo "Unsupported architecture: $arch"
exit 2
fi
#
# Run the s10_support boot hook.
#
/usr/lib/brand/solaris10/s10_support boot $ZONENAME
if (( $? != 0 )) ; then
exit 1
fi
BRANDDIR=/.SUNWnative/usr/lib/brand/solaris10;
FILEDIR=$BRANDDIR/files;
EXIT_CODE=1
#
# Replace the specified file in the booting zone with a wrapper script that
# invokes s10_isaexec_wrapper. This is a convenience function that reduces
# clutter and code duplication.
#
# Parameters:
# $1 The full path of the file to replace (e.g., /sbin/ifconfig)
# $2 The access mode of the replacement file in hex (e.g., 0555)
# $3 The name of the replacement file's owner (e.g., root:bin)
#
# NOTE: The checks performed in the 'if' statement below are not generic: they
# depend on the success of the zone filesystem structure validation performed
# above to ensure that intermediate directories exist and aren't symlinks.
#
replace_with_native() {
path_dname=$ZONEROOT/`dirname $1`
[ ! -f $1 ] && printf "$w_missing" "$1"
if [ ! -h $path_dname -a -d $path_dname ]; then
safe_replace $ZONEROOT/$1 $BRANDDIR/s10_isaexec_wrapper $2 $3 \
remove
fi
}
#
# Create a new wrapper script that invokes s10_isaexec_wrapper in the
# brand (for a non-existing s10c file) pointing to the native brand file.
#
# Parameters:
# $1 The full path of the wrapper file to create
# $2 The access mode of the replacement file in hex (e.g., 0555)
# $3 The name of the replacement file's owner (e.g., root:bin)
#
wrap_with_native() {
[ ! -f $1 ] && printf "$w_missing" "$1"
path_dname=$ZONEROOT/`dirname $1`
if [ ! -h $path_dname -a -d $path_dname -a ! -f $ZONEROOT/$1 ]; then
safe_wrap $ZONEROOT/$1 $BRANDDIR/s10_isaexec_wrapper $2 $3
fi
}
#
# Before we boot we validate and fix, if necessary, the required files within
# the zone. These modifications can be lost if a patch is applied within the
# zone, so we validate and fix the zone every time it boots.
#
#
# BINARY REPLACEMENT
#
# This section of the boot script is responsible for replacing Solaris 10
# binaries within the booting zone with Nevada binaries. This is a two-step
# process: First, the directory structure of the zone is validated to ensure
# that binary replacement will proceed safely. Second, Solaris 10 binaries
# are replaced with Nevada binaries.
#
# Here's an example. Suppose that you want to replace /usr/bin/zcat with the
# Nevada /usr/bin/zcat binary. Then you should do the following:
#
# 1. Go to the section below labeled "STEP ONE" and add the following
# two lines:
#
# safe_dir /usr
# safe_dir /usr/bin
#
# These lines ensure that both /usr and /usr/bin are directories
# within the booting zone that can be safely accessed by the global
# zone.
# 2. Go to the section below labeled "STEP TWO" and add the following
# line:
#
# replace_with_native /usr/bin/zcat 0555 root:bin
#
# Details about the binary replacement procedure can be found in the Solaris 10
# Containers Developer Guide.
#
#
# STEP ONE
#
# Validate that the zone filesystem looks like we expect it to.
#
safe_dir /lib
safe_dir /lib/svc
safe_dir /lib/svc/method
safe_dir /lib/svc/share
safe_dir /usr
safe_dir /usr/bin
safe_dir /usr/lib
safe_dir /usr/lib/autofs
safe_dir /usr/lib/fs
safe_dir /usr/lib/fs/autofs
safe_dir /usr/lib/fs/ufs
safe_dir /usr/lib/fs/zfs
safe_dir /usr/lib/inet
safe_dir /usr/lib/zfs
safe_dir /usr/sbin
if [ -n "$ARCH32" ]; then
safe_dir /usr/lib/ipf/$ARCH32
safe_dir /usr/sbin/$ARCH32
fi
if [ -n "$ARCH64" ]; then
safe_dir /usr/lib/ipf/$ARCH64
safe_dir /usr/sbin/$ARCH64
fi
safe_dir /sbin
safe_dir /var
safe_dir /var/svc
safe_dir /var/svc/manifest
safe_dir /var/svc/manifest/network
#
# Some of the native networking daemons such as in.mpathd are
# expected under /lib/inet
#
mkdir -m 0755 -p $ZONEROOT/lib/inet
chown root:bin $ZONEROOT/lib/inet
safe_dir /lib/inet
#
# STEP TWO
#
# Replace Solaris 10 binaries with Nevada binaries.
#
#
# Replace various network-related programs with native wrappers.
#
replace_with_native /sbin/dhcpagent 0555 root:bin
replace_with_native /sbin/dhcpinfo 0555 root:bin
replace_with_native /sbin/ifconfig 0555 root:bin
replace_with_native /usr/bin/netstat 0555 root:bin
replace_with_native /usr/lib/inet/in.ndpd 0555 root:bin
replace_with_native /usr/sbin/in.routed 0555 root:bin
replace_with_native /usr/sbin/ndd 0555 root:bin
replace_with_native /usr/sbin/snoop 0555 root:bin
replace_with_native /usr/sbin/if_mpadm 0555 root:bin
#
# Replace IPFilter commands with native wrappers
#
replace_with_native /usr/lib/ipf/ipftest 0555 root:bin
replace_with_native /usr/sbin/ipf 0555 root:bin
replace_with_native /usr/sbin/ipfs 0555 root:bin
replace_with_native /usr/sbin/ipfstat 0555 root:bin
replace_with_native /usr/sbin/ipmon 0555 root:bin
replace_with_native /usr/sbin/ipnat 0555 root:bin
replace_with_native /usr/sbin/ippool 0555 root:bin
#
# Replace in.mpathd daemon at /usr/lib/inet by native wrapper
#
if [ ! -h $ZONEROOT/usr/lib/inet -a -d $ZONEROOT/usr/lib/inet ]; then
safe_replace $ZONEROOT/usr/lib/inet/in.mpathd \
/lib/inet/in.mpathd 0555 root:bin remove
fi
#
# Create wrapper at /lib/inet/in.mpathd as well because native ifconfig
# looks up in.mpathd under /lib/inet.
#
wrap_with_native /lib/inet/in.mpathd 0555 root:bin
# Create native wrapper for /sbin/ipmpstat
wrap_with_native /sbin/ipmpstat 0555 root:bin
#
# Create ipmgmtd wrapper to native binary in s10 container
# and copy ipmgmt service manifest and method.
#
wrap_with_native /lib/inet/ipmgmtd 0555 root:bin
safe_copy /lib/svc/manifest/network/network-ipmgmt.xml \
$ZONEROOT/var/svc/manifest/network/network-ipmgmt.xml
safe_copy /lib/svc/method/net-ipmgmt \
$ZONEROOT/lib/svc/method/net-ipmgmt
#
# To handle certain IPMP configurations, we need updated
# net-physical method script and native net_include.sh
#
filename=$ZONEROOT/lib/svc/method/net-physical
safe_backup $filename $filename.pre_p2v
safe_copy /usr/lib/brand/solaris10/s10_net_physical $filename
filename=$ZONEROOT/lib/svc/share/net_include.sh
safe_backup $filename $filename.pre_p2v
safe_copy /lib/svc/share/net_include.sh $filename
#
# PSARC 2009/306 removed the ND_SET/ND_GET ioctl's for modifying
# IP/TCP/UDP/SCTP/ICMP tunables. If S10 ndd(8) is used within an
# S10 container, the kernel will return EINVAL. So we need this.
#
replace_with_native /usr/sbin/ndd 0555 root:bin
#
# Replace various ZFS-related programs with native wrappers. These commands
# either link with libzfs, dlopen libzfs or link with libraries that link
# or dlopen libzfs. Commands which fall into these categories but which can
# only be used in the global zone are not wrapped. The libdiskmgt dm_in_use
# code uses libfs, but only the zpool_in_use() -> zpool_read_label() code path.
# That code does not issue ioctls on /dev/zfs and does not need wrapping.
#
replace_with_native /sbin/zfs 0555 root:bin
replace_with_native /sbin/zpool 0555 root:bin
replace_with_native /usr/lib/fs/ufs/quota 0555 root:bin
replace_with_native /usr/lib/fs/zfs/fstyp 0555 root:bin
replace_with_native /usr/lib/zfs/availdevs 0555 root:bin
replace_with_native /usr/sbin/df 0555 root:bin
replace_with_native /usr/sbin/zstreamdump 0555 root:bin
#
# Replace automount and automountd with native wrappers.
#
replace_with_native /usr/lib/fs/autofs/automount 0555 root:bin
replace_with_native /usr/lib/autofs/automountd 0555 root:bin
#
# The class-specific dispadmin(8) and priocntl(1) binaries must be native
# wrappers, and we must have all of the ones the native zone does. This
# allows new scheduling classes to appear without causing dispadmin and
# priocntl to be unhappy.
#
rm -rf $ZONEROOT/usr/lib/class
mkdir $ZONEROOT/usr/lib/class || exit 1
find /usr/lib/class -type d -o -type f | while read x; do
[ -d $x ] && mkdir -p -m 755 $ZONEROOT$x
[ -f $x ] && wrap_with_native $x 0555 root:bin
done
#
# END OF STEP TWO
#
#
# Replace add_drv and rem_drv with /bin/true so that pkgs/patches which
# install or remove drivers will work. NOTE: add_drv and rem_drv are hard
# linked to isaexec so we want to remove the current executable and
# then copy true so that we don't clobber isaexec.
#
filename=$ZONEROOT/sbin/add_drv
[ ! -f $filename.pre_p2v ] && safe_backup $filename $filename.pre_p2v
rm -f $filename
safe_copy $ZONEROOT/bin/true $filename
filename=$ZONEROOT/sbin/rem_drv
[ ! -f $filename.pre_p2v ] && safe_backup $filename $filename.pre_p2v
rm -f $filename
safe_copy $ZONEROOT/bin/true $filename
exit 0
#
# 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.
#
# This is a list of SMF services which should be disabled when installing
# the zone. Site-specific services which must be disabled should be listed
# in this file. During the zone installation, the services will be disabled
# if they existed on the original physical system.
#
#
# 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.
#
# This is a list of SMF services which should be disabled when installing
# the zone. Do not edit this file. Site-specific services which must be
# disabled should be listed in the /etc/brand/solaris10/smf_disable.conf
# file. During the zone installation, the services will be disabled if
# they existed on the original physical system.
#
svc:/network/smb/server
svc:/system/virtualbox/vboxservice
svc:/ldoms/ldmd
#!/bin/ksh93 -p
#
# 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.
#
#
# common shell script functions
#
. /usr/lib/brand/solaris10/common.ksh
. /usr/lib/brand/shared/uninstall.ksh
#
# options processing
#
# If we weren't passed at least two arguments, exit now.
(( $# < 2 )) && exit $ZONE_SUBPROC_USAGE
zonename=$1
zonepath=$2
shift 2
options="FhHnv"
options_repeat=""
options_seen=""
opt_F=""
opt_n=""
opt_v=""
# check for bad or duplicate options
OPTIND=1
while getopts $options OPT ; do
case $OPT in
\? ) usage_err ;; # invalid argument
: ) usage_err ;; # argument expected
* )
opt=`echo $OPT | sed 's/-\+//'`
if [ -n "$options_repeat" ]; then
echo $options_repeat | grep $opt >/dev/null
[ $? = 0 ] && break
fi
( echo $options_seen | grep $opt >/dev/null ) &&
usage_err
options_seen="${options_seen}${opt}"
;;
esac
done
# check for a help request
OPTIND=1
while getopts :$options OPT ; do
case $OPT in
h|H ) usage
esac
done
# process options
OPTIND=1
while getopts :$options OPT ; do
case $OPT in
F ) opt_F="-F" ;;
n ) opt_n="-n" ;;
v ) opt_v="-v" ;;
esac
done
shift `expr $OPTIND - 1`
[ $# -gt 0 ] && usage_err
#
# main
#
zoneroot=$zonepath/root
nop=""
if [[ -n "$opt_n" ]]; then
nop="echo"
#
# in '-n' mode we should never return success (since we haven't
# actually done anything). so override ZONE_SUBPROC_OK here.
#
ZONE_SUBPROC_OK=$ZONE_SUBPROC_FATAL
fi
#
# We want uninstall to work in the face of various problems, such as a
# zone with no delegated root dataset or multiple active datasets, so we
# don't use the common functions. Instead, we do our own work and
# are tolerant of errors.
#
uninstall_get_zonepath_ds
uninstall_get_zonepath_root_ds
# find all the zone BE datasets.
unset fs_all
(( fs_all_c = 0 ))
/sbin/zfs list -H -t filesystem -o name -r $ZONEPATH_RDS | while read fs; do
# only look at filesystems directly below $ZONEPATH_RDS
[[ "$fs" != ~()($ZONEPATH_RDS/+([^/])) ]] && continue
fs_all[$fs_all_c]=$fs
(( fs_all_c = $fs_all_c + 1 ))
done
destroy_zone_datasets
exit $ZONE_SUBPROC_OK
#
# 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.
#
# This is the current latest version of the solaris10 brand emulation. The
# version should be incremented if new capabilities are added to the
# emulation for new features backported to S10. The S10 required emulation
# version should also be incremented so that the enhanced version of S10
# won't be usable in an older version of the solaris10 brand.
#
0
|