summaryrefslogtreecommitdiff
path: root/doc/mach.info-1
blob: a1bb76ce0714fda9219768b2b442e549c8e0d2c9 (plain)
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
This is ../doc/mach.info, produced by makeinfo version 4.8 from
../doc/mach.texi.

INFO-DIR-SECTION Kernel
START-INFO-DIR-ENTRY
* GNUMach: (mach).              Using and programming the GNU Mach microkernel.
END-INFO-DIR-ENTRY

   This file documents the GNU Mach microkernel.

   This is Edition 0.4, last updated 2001-09-01, of `The GNU Mach
Reference Manual', for Version 1.3.99.

   Copyright (C) 2001 Free Software Foundation, Inc.

   Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Free Software Needs Free Documentation" and
"GNU Lesser General Public License", the Front-Cover texts being (a)
(see below), and with the Back-Cover Texts being (b) (see below).  A
copy of the license is included in the section entitled "GNU Free
Documentation License".

   (a) The FSF's Front-Cover Text is:

   A GNU Manual

   (b) The FSF's Back-Cover Text is:

   You have freedom to copy and modify this GNU Manual, like GNU
software.  Copies published by the Free Software Foundation raise
funds for GNU development.

   This work is based on manual pages under the following copyright and
license:

Mach Operating System
Copyright (C) 1991,1990 Carnegie Mellon University
All Rights Reserved.

   Permission to use, copy, modify and distribute this software and its
documentation is hereby granted, provided that both the copyright
notice and this permission notice appear in all copies of the software,
derivative works or modified versions, and any portions thereof, and
that both notices appear in supporting documentation.

   CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY
DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.


File: mach.info,  Node: Top,  Next: Introduction,  Up: (dir)

Main Menu
*********

This is Edition 0.4, last updated 2001-09-01, of `The GNU Mach
Reference Manual', for Version 1.3.99 of the GNU Mach microkernel.

* Menu:

* Introduction::                  How to use this manual.
* Installing::                    Setting up GNU Mach on your computer.
* Bootstrap::                     Running GNU Mach on your machine.
* Inter Process Communication::   Communication between process.
* Virtual Memory Interface::      Allocating and deallocating virtual memory.
* External Memory Management::    Handling memory pages in user space.
* Threads and Tasks::             Handling of threads and tasks.
* Host Interface::                Interface to a Mach host.
* Processors and Processor Sets:: Handling processors and sets of processors.
* Device Interface::              Accesing kernel devices.
* Kernel Debugger::               How to use the built-in kernel debugger.

Appendices

* Copying::                       The GNU General Public License says how you
                                  can copy and share the GNU Mach microkernel.
* Documentation License::         This manual is under the GNU Free
                                  Documentation License.

Indices

* Concept Index::                 Index of concepts and programs.
* Function and Data Index::       Index of functions, variables and data types.


 --- The Detailed Node Listing ---

Introduction

* Audience::                      The people for whom this manual is written.
* Features::                      Reasons to install and use GNU Mach.
* Overview::                      Basic architecture of the Mach microkernel.
* History::                       The story about Mach.

Installing

* Binary Distributions::          Obtaining ready-to-run GNU distributions.
* Compilation::                   Building GNU Mach from its source code.
* Configuration::                 Configuration options at compilation time.
* Cross-Compilation::             Building GNU Mach from another system.

Bootstrap

* Bootloader::                    Starting the microkernel, or other OSes.
* Modules::                       Starting the first task of the OS.

Inter Process Communication

* Major Concepts::                The concepts behind the Mach IPC system.
* Messaging Interface::           Composing, sending and receiving messages.
* Port Manipulation Interface::   Manipulating ports, port rights, port sets.

Messaging Interface

* Mach Message Call::             Sending and receiving messages.
* Message Format::                The format of Mach messages.
* Exchanging Port Rights::        Sending and receiving port rights.
* Memory::                        Passing memory regions in messages.
* Message Send::                  Sending messages.
* Message Receive::               Receiving messages.
* Atomicity::                     Atomicity of port rights.

Port Manipulation Interface

* Port Creation::                 How to create new ports and port sets.
* Port Destruction::              How to destroy ports and port sets.
* Port Names::                    How to query and manipulate port names.
* Port Rights::                   How to work with port rights.
* Ports and other Tasks::         How to move rights between tasks.
* Receive Rights::                How to work with receive rights.
* Port Sets::                     How to work with port sets.
* Request Notifications::         How to request notifications for events.

Virtual Memory Interface

* Memory Allocation::             Allocation of new virtual memory.
* Memory Deallocation::           Freeing unused virtual memory.
* Data Transfer::                 Reading, writing and copying memory.
* Memory Attributes::             Tweaking memory regions.
* Mapping Memory Objects::        How to map memory objects.
* Memory Statistics::             How to get statistics about memory usage.

External Memory Management

* Memory Object Server::          The basics of external memory management.
* Memory Object Creation::        How new memory objects are created.
* Memory Object Termination::     How memory objects are terminated.
* Memory Objects and Data::       Data transfer to and from memory objects.
* Memory Object Locking::         How memory objects are locked.
* Memory Object Attributes::      Manipulating attributes of memory objects.
* Default Memory Manager::        Setting and using the default memory manager.

Threads and Tasks

* Thread Interface::              Manipulating threads.
* Task Interface::                Manipulating tasks.
* Profiling::                     Profiling threads and tasks.

Thread Interface

* Thread Creation::               Creating threads.
* Thread Termination::            Terminating threads.
* Thread Information::            How to get informations on threads.
* Thread Settings::               How to set threads related informations.
* Thread Execution::              How to control the thread's machine state.
* Scheduling::                    Operations on thread scheduling.
* Thread Special Ports::          How to handle the thread's special ports.
* Exceptions::                    Managing exceptions.

Scheduling

* Thread Priority::               Changing the priority of a thread.
* Hand-Off Scheduling::           Switch to a new thread.
* Scheduling Policy::             Setting the scheduling policy.

Task Interface

* Task Creation::                 Creating tasks.
* Task Termination::              Terminating tasks.
* Task Information::              Informations on tasks.
* Task Execution::                Thread scheduling in a task.
* Task Special Ports::            How to get and set the task's special ports.
* Syscall Emulation::             How to emulate system calls.

Host Interface

* Host Ports::                    Ports representing a host.
* Host Information::              Query information about a host.
* Host Time::                     Functions to query manipulate the host time.
* Host Reboot::                   Rebooting the system.

Processors and Processor Sets

* Processor Set Interface::       How to work with processor sets.
* Processor Interface::           How to work with individual processors.

Processor Set Interface

* Processor Set Ports::           Ports representing a processor set.
* Processor Set Access::          How the processor sets are accessed.
* Processor Set Creation::        How new processor sets are created.
* Processor Set Destruction::     How processor sets are destroyed.
* Tasks and Threads on Sets::     Assigning tasks or threads to processor sets.
* Processor Set Priority::        Specifying the priority of a processor set.
* Processor Set Policy::          Changing the processor set policies.
* Processor Set Info::            Obtaining information about a processor set.

Processor Interface

* Hosted Processors::             Getting a list of all processors on a host.
* Processor Control::             Starting, stopping, controlling processors.
* Processors and Sets::           Combining processors into processor sets.
* Processor Info::                Obtaining information on processors.

Device Interface

* Device Open::                   Opening hardware devices.
* Device Close::                  Closing hardware devices.
* Device Read::                   Reading data from the device.
* Device Write::                  Writing data to the device.
* Device Map::                    Mapping devices into virtual memory.
* Device Status::                 Querying and manipulating a device.
* Device Filter::                 Filtering packets arriving on a device.

Kernel Debugger

* Operation::                     Basic architecture of the kernel debugger.
* Commands::                      Available commands in the kernel debugger.
* Variables::                     Access of variables from the kernel debugger.
* Expressions::                   Usage of expressions in the kernel debugger.

Documentation License

* Free Documentation License::    The GNU Free Documentation License.
* CMU License::                   The CMU license applies to the original Mach
                                  kernel and its documentation.


File: mach.info,  Node: Introduction,  Next: Installing,  Prev: Top,  Up: Top

1 Introduction
**************

GNU Mach is the microkernel of the GNU Project.  It is the base of the
operating system, and provides its functionality to the Hurd servers,
the GNU C Library and all user applications.  The microkernel itself
does not provide much functionality of the system, just enough to make
it possible for the Hurd servers and the C library to implement the
missing features you would expect from a POSIX compatible operating
system.

* Menu:

* Audience::                      The people for whom this manual is written.
* Features::                      Reasons to install and use GNU Mach.
* Overview::                      Basic architecture of the Mach microkernel.
* History::                       The story about Mach.


File: mach.info,  Node: Audience,  Next: Features,  Up: Introduction

1.1 Audience
============

This manual is designed to be useful to everybody who is interested in
using, administering, or programming the Mach microkernel.

   If you are an end-user and you are looking for help on running the
Mach kernel, the first few chapters of this manual describe the
essential parts of installing and using the kernel in the GNU operating
system.

   The rest of this manual is a technical discussion of the Mach
programming interface and its implementation, and would not be helpful
until you want to learn how to extend the system or modify the kernel.

   This manual is organized according to the subsystems of Mach, and
each chapter begins with descriptions of conceptual ideas that are
related to that subsystem.  If you are a programmer and want to learn
more about, say, the Mach IPC subsystem, you can skip to the IPC chapter
(*note Inter Process Communication::), and read about the related
concepts and interface definitions.


File: mach.info,  Node: Features,  Next: Overview,  Prev: Audience,  Up: Introduction

1.2 Features
============

GNU Mach is not the most advanced microkernel known to the planet, nor
is it the fastest or smallest, but it has a rich set of interfaces and
some features which make it useful as the base of the Hurd system.

it's free software
     Anybody can use, modify, and redistribute it under the terms of
     the GNU General Public License (*note Copying::).  GNU Mach is
     part of the GNU system, which is a complete operating system
     licensed under the GPL.

it's built to survive
     As a microkernel, GNU Mach doesn't implement a lot of the features
     commonly found in an operating system, but only the bare minimum
     that is required to implement a full operating system on top of it.
     This means that a lot of the operating system code is maintained
     outside of GNU Mach, and while this code may go through a complete
     redesign, the code of the microkernel can remain comparatively
     stable.

it's scalable
     Mach is particularly well suited for SMP and network cluster
     techniques.  Thread support is provided at the kernel level, and
     the kernel itself takes advantage of that.  Network transparency
     at the IPC level makes resources of the system available across
     machine boundaries (with NORMA IPC, currently not available in GNU
     Mach).

it exists
     The Mach microkernel is real software that works Right Now.  It is
     not a research or a proposal.  You don't have to wait at all
     before you can start using and developing it.  Mach has been used
     in many operating systems in the past, usually as the base for a
     single UNIX server.  In the GNU system, Mach is the base of a
     functional multi-server operating system, the Hurd.


File: mach.info,  Node: Overview,  Next: History,  Prev: Features,  Up: Introduction

1.3 Overview
============

An operating system kernel provides a framework for programs to share a
computer's hardware resources securely and efficiently.  This requires
that the programs are seperated and protected from each other.  To make
running multiple programs in parallel useful, there also needs to be a
facility for programs to exchange information by communication.

   The Mach microkernel provides abstractions of the underlying hardware
resources like devices and memory.  It organizes the running programs
into tasks and threads (points of execution in the tasks).  In addition,
Mach provides a rich interface for inter-process communication.

   What Mach does not provide is a POSIX compatible programming
interface.  In fact, it has no understanding of file systems, POSIX
process semantics, network protocols and many more.  All this is
implemented in tasks running on top of the microkernel.  In the GNU
operating system, the Hurd servers and the C library share the
responsibility to implement the POSIX interface, and the additional
interfaces which are specific to the GNU system.


File: mach.info,  Node: History,  Prev: Overview,  Up: Introduction

1.4 History
===========

XXX A few lines about the history of Mach here.


File: mach.info,  Node: Installing,  Next: Bootstrap,  Prev: Introduction,  Up: Top

2 Installing
************

Before you can use the Mach microkernel in your system you'll need to
install it and all components you want to use with it, e.g. the rest of
the operating system.  You also need a bootloader to load the kernel
from the storage medium and run it when the computer is started.

   GNU Mach is only available for Intel i386-compatible architectures
(such as the Pentium) currently.  If you have a different architecture
and want to run the GNU Mach microkernel, you will need to port the
kernel and all other software of the system to your machine's
architecture.  Porting is an involved process which requires
considerable programming skills, and it is not recommended for the
faint-of-heart.  If you have the talent and desire to do a port, contact
<bug-hurd@gnu.org> in order to coordinate the effort.

* Menu:

* Binary Distributions::          Obtaining ready-to-run GNU distributions.
* Compilation::                   Building GNU Mach from its source code.
* Configuration::                 Configuration options at compile time.
* Cross-Compilation::             Building GNU Mach from another system.


File: mach.info,  Node: Binary Distributions,  Next: Compilation,  Up: Installing

2.1 Binary Distributions
========================

By far the easiest and best way to install GNU Mach and the operating
system is to obtain a GNU binary distribution.  The GNU operating
system consists of GNU Mach, the Hurd, the C library and many
applications.  Without the GNU operating system, you will only have a
microkernel, which is not very useful by itself, without the other
programs.

   Building the whole operating system takes a huge effort, and you are
well advised to not do it yourself, but to get a binary distribution of
the GNU operating system.  The distribution also includes a binary of
the GNU Mach microkernel.

   Information on how to obtain the GNU system can be found in the Hurd
info manual.


File: mach.info,  Node: Compilation,  Next: Configuration,  Prev: Binary Distributions,  Up: Installing

2.2 Compilation
===============

If you already have a running GNU system, and only want to recompile
the kernel, for example to select a different set of included hardware
drivers, you can easily do this.  You need the GNU C compiler and MiG,
the Mach interface generator, which both come in their own packages.

   Building and installing the kernel is as easy as with any other GNU
software package.  The configure script is used to configure the source
and set the compile time options.  The compilation is done by running:

     make

   To install the kernel and its header files, just enter the command:

     make install

   This will install the kernel into $(prefix)/boot/gnumach and the
header files into $(prefix)/include.  You can also only install the
kernel or the header files.  For this, the two targets install-kernel
and install-headers are provided.


File: mach.info,  Node: Configuration,  Next: Cross-Compilation,  Prev: Compilation,  Up: Installing

2.3 Configuration
=================

The following options can be passed to the configure script as command
line arguments and control what components are built into the kernel, or
where it is installed.

   The default for an option is to be disabled, unless otherwise noted.

   This table is out-dated.  Please see the file `i386/README-Drivers'
and the output of `[GNU Mach]/configure --help=recursive'.

`--prefix PREFIX'
     Sets the prefix to PREFIX.  The default prefix is the empty
     string, which is the correct value for the GNU system.  The prefix
     is prepended to all file names at installation time.

`--enable-kdb'
     Enables the in-kernel debugger.  This is only useful if you
     actually anticipate debugging the kernel.  It is not enabled by
     default because it adds considerably to the unpageable memory
     footprint of the kernel.  *Note Kernel Debugger::.

`--enable-kmsg'
     Enables the kernel message device kmsg.

`--enable-lpr'
     Enables the parallel port devices lpr%d.

`--enable-floppy'
     Enables the PC floppy disk controller devices fd%d.

`--enable-ide'
     Enables the IDE controller devices hd%d, hd%ds%d.

   The following options enable drivers for various SCSI controller.
SCSI devices are named sd%d (disks) or cd%d (CD ROMs).

`--enable-advansys'
     Enables the AdvanSys SCSI controller devices sd%d, cd%d.

`--enable-buslogic'
     Enables the BusLogic SCSI controller devices sd%d, cd%d.

`--disable-flashpoint'
     Only meaningful in conjunction with `--enable-buslogic'.  Omits the
     FlshPoint support.  This option is enabled by default if
     `--enable-buslogic' is specified.

`--enable-u1434f'
     Enables the UltraStor 14F/34F SCSI controller devices sd%d, cd%d.

`--enable-ultrastor'
     Enables the UltraStor SCSI controller devices sd%d, cd%d.

`--enable-aha152x'
`--enable-aha2825'
     Enables the Adaptec AHA-152x/2825 SCSI controller devices sd%d,
     cd%d.

`--enable-aha1542'
     Enables the Adaptec AHA-1542 SCSI controller devices sd%d, cd%d.

`--enable-aha1740'
     Enables the Adaptec AHA-1740 SCSI controller devices sd%d, cd%d.

`--enable-aic7xxx'
     Enables the Adaptec AIC7xxx SCSI controller devices sd%d, cd%d.

`--enable-futuredomain'
     Enables the Future Domain 16xx SCSI controller devices sd%d, cd%d.

`--enable-in2000'
     Enables the Always IN 2000 SCSI controller devices sd%d, cd%d.

`--enable-ncr5380'
`--enable-ncr53c400'
     Enables the generic NCR5380/53c400 SCSI controller devices sd%d,
     cd%d.

`--enable-ncr53c406a'
     Enables the NCR53c406a SCSI controller devices sd%d, cd%d.

`--enable-pas16'
     Enables the PAS16 SCSI controller devices sd%d, cd%d.

`--enable-seagate'
     Enables the Seagate ST02 and Future Domain TMC-8xx SCSI controller
     devices sd%d, cd%d.

`--enable-t128'
`--enable-t128f'
`--enable-t228'
     Enables the Trantor T128/T128F/T228 SCSI controller devices sd%d,
     cd%d.

`--enable-ncr53c7xx'
     Enables the NCR53C7,8xx SCSI controller devices sd%d, cd%d.

`--enable-eatadma'
     Enables the EATA-DMA (DPT, NEC, AT&T, SNI, AST, Olivetti,
     Alphatronix) SCSI controller devices sd%d, cd%d.

`--enable-eatapio'
     Enables the EATA-PIO (old DPT PM2001, PM2012A) SCSI controller
     devices sd%d, cd%d.

`--enable-wd7000'
     Enables the WD 7000 SCSI controller devices sd%d, cd%d.

`--enable-eata'
     Enables the EATA ISA/EISA/PCI (DPT and generic EATA/DMA-compliant
     boards) SCSI controller devices sd%d, cd%d.

`--enable-am53c974'
`--enable-am79c974'
     Enables the AM53/79C974 SCSI controller devices sd%d, cd%d.

`--enable-dtc3280'
`--enable-dtc3180'
     Enables the DTC3180/3280 SCSI controller devices sd%d, cd%d.

`--enable-ncr53c8xx'
`--enable-dc390w'
`--enable-dc390u'
`--enable-dc390f'
     Enables the NCR53C8XX SCSI controller devices sd%d, cd%d.

`--enable-dc390t'
`--enable-dc390'
     Enables the Tekram DC-390(T) SCSI controller devices sd%d, cd%d.

`--enable-ppa'
     Enables the IOMEGA Parallel Port ZIP drive device sd%d.

`--enable-qlogicfas'
     Enables the Qlogic FAS SCSI controller devices sd%d, cd%d.

`--enable-qlogicisp'
     Enables the Qlogic ISP SCSI controller devices sd%d, cd%d.

`--enable-gdth'
     Enables the GDT SCSI Disk Array controller devices sd%d, cd%d.

   The following options enable drivers for various ethernet cards.
NIC device names are usually eth%d, except for the pocket adaptors.

   GNU Mach does only autodetect one ethernet card.  To enable any
further cards, the source code has to be edited.

`--enable-ne2000'
`--enable-ne1000'
     Enables the NE2000/NE1000 ISA netword card devices eth%d.

`--enable-3c503'
`--enable-el2'
     Enables the 3Com 503 (Etherlink II) netword card devices eth%d.

`--enable-3c509'
`--enable-3c579'
`--enable-el3'
     Enables the 3Com 509/579 (Etherlink III) netword card devices
     eth%d.

`--enable-wd80x3'
     Enables the WD80X3 netword card devices eth%d.

`--enable-3c501'
`--enable-el1'
     Enables the 3COM 501 netword card devices eth%d.

`--enable-ul'
     Enables the SMC Ultra netword card devices eth%d.

`--enable-ul32'
     Enables the SMC Ultra 32 netword card devices eth%d.

`--enable-hplanplus'
     Enables the HP PCLAN+ (27247B and 27252A) netword card devices
     eth%d.

`--enable-hplan'
     Enables the HP PCLAN (27245 and other 27xxx series) netword card
     devices eth%d.

`--enable-3c59x'
`--enable-3c90x'
`--enable-vortex'
     Enables the 3Com 590/900 series (592/595/597/900/905)
     "Vortex/Boomerang" netword card devices eth%d.

`--enable-seeq8005'
     Enables the Seeq8005 netword card devices eth%d.

`--enable-hp100'
`--enable-hpj2577'
`--enable-hpj2573'
`--enable-hp27248b'
`--enable-hp2585'
     Enables the HP 10/100VG PCLAN (ISA, EISA, PCI) netword card devices
     eth%d.

`--enable-ac3200'
     Enables the Ansel Communications EISA 3200 netword card devices
     eth%d.

`--enable-e2100'
     Enables the Cabletron E21xx netword card devices eth%d.

`--enable-at1700'
     Enables the AT1700 (Fujitsu 86965) netword card devices eth%d.

`--enable-eth16i'
`--enable-eth32'
     Enables the ICL EtherTeam 16i/32 netword card devices eth%d.

`--enable-znet'
`--enable-znote'
     Enables the Zenith Z-Note netword card devices eth%d.

`--enable-eexpress'
     Enables the EtherExpress 16 netword card devices eth%d.

`--enable-eexpresspro'
     Enables the EtherExpressPro netword card devices eth%d.

`--enable-eexpresspro100'
     Enables the Intel EtherExpressPro PCI 10+/100B/100+ netword card
     devices eth%d.

`--enable-depca'
`--enable-de100'
`--enable-de101'
`--enable-de200'
`--enable-de201'
`--enable-de202'
`--enable-de210'
`--enable-de422'
     Enables the DEPCA, DE10x, DE200, DE201, DE202, DE210, DE422
     netword card devices eth%d.

`--enable-ewrk3'
`--enable-de203'
`--enable-de204'
`--enable-de205'
     Enables the EtherWORKS 3 (DE203, DE204, DE205) netword card devices
     eth%d.

`--enable-de4x5'
`--enable-de425'
`--enable-de434'
`--enable-435'
`--enable-de450'
`--enable-500'
     Enables the DE425, DE434, DE435, DE450, DE500 netword card devices
     eth%d.

`--enable-apricot'
     Enables the Apricot XEN-II on board ethernet netword card devices
     eth%d.

`--enable-wavelan'
     Enables the AT&T WaveLAN & DEC RoamAbout DS netword card devices
     eth%d.

`--enable-3c507'
`--enable-el16'
     Enables the 3Com 507 netword card devices eth%d.

`--enable-3c505'
`--enable-elplus'
     Enables the 3Com 505 netword card devices eth%d.

`--enable-de600'
     Enables the D-Link DE-600 netword card devices eth%d.

`--enable-de620'
     Enables the D-Link DE-620 netword card devices eth%d.

`--enable-skg16'
     Enables the Schneider & Koch G16 netword card devices eth%d.

`--enable-ni52'
     Enables the NI5210 netword card devices eth%d.

`--enable-ni65'
     Enables the NI6510 netword card devices eth%d.

`--enable-atp'
     Enables the AT-LAN-TEC/RealTek pocket adaptor netword card devices
     atp%d.

`--enable-lance'
`--enable-at1500'
`--enable-ne2100'
     Enables the AMD LANCE and PCnet (AT1500 and NE2100) netword card
     devices eth%d.

`--enable-elcp'
`--enable-tulip'
     Enables the DECchip Tulip (dc21x4x) PCI netword card devices eth%d.

`--enable-fmv18x'
     Enables the FMV-181/182/183/184 netword card devices eth%d.

`--enable-3c515'
     Enables the 3Com 515 ISA Fast EtherLink netword card devices eth%d.

`--enable-pcnet32'
     Enables the AMD PCI PCnet32 (PCI bus NE2100 cards) netword card
     devices eth%d.

`--enable-ne2kpci'
     Enables the PCI NE2000 netword card devices eth%d.

`--enable-yellowfin'
     Enables the Packet Engines Yellowfin Gigabit-NIC netword card
     devices eth%d.

`--enable-rtl8139'
`--enable-rtl8129'
     Enables the RealTek 8129/8139 (not 8019/8029!)  netword card
     devices eth%d.

`--enable-epic'
`--enable-epic100'
     Enables the SMC 83c170/175 EPIC/100 (EtherPower II) netword card
     devices eth%d.

`--enable-tlan'
     Enables the TI ThunderLAN netword card devices eth%d.

`--enable-viarhine'
     Enables the VIA Rhine netword card devices eth%d.

`--enable-hamachi'
     Enables the Packet Engines "Hamachi" GNIC-2 Gigabit Ethernet
     devices eth%d.

`--enable-intel-gige'
     Enables the Intel PCI Gigabit Ethernet devices eth%d.

`--enable-myson803'
     Enables the Myson MTD803 Ethernet adapter series devices eth%d.

`--enable-natsemi'
     Enables the National Semiconductor DP8381x series PCI Ethernet
     devices eth%d.

`--enable-ns820'
     Enables the National Semiconductor DP8382x series PCI Ethernet
     devices eth%d.

`--enable-starfire'
     Enables the Adaptec Starfire network adapter devices eth%d.

`--enable-sundance'
     Enables the Sundance ST201 "Alta" PCI Ethernet devices eth%d.

`--enable-winbond-840'
     Enables the Winbond W89c840 PCI Ethernet devices eth%d.

   The following options either enable drivers for supported PCMCIA
bridges or control the overall behaviour of the GNU Mach PCMCIA core.
To make use of GNU Mach PCMCIA support you need to have the
corresponding userland applications (GNU Mach Card Services) installed.

`--enable-i82365'
     Enables the driver for the Intel 82365 and compatible PC Card
     controllers, and Yenta-compatible PCI-to-CardBus controllers.

`--enable-pcmcia-isa'
     Enables ISA-bus related bits in the GNU Mach PCMCIA core.  This is
     generally a good idea, since it does not only have effect if your
     PC Card bridge is attached to the ISA bus, but provides more (ISA)
     interrupts to the Card Services for it to assign to the cards in
     turn.

   The following options enable drivers for supported PCMCIA Ethernet
controllers.  NIC device names are usually eth%d.

`--enable-3c574_cs'
     Enables the PCMCIA ethernet driver for the 3Com 3c574 "RoadRunner".

`--enable-3c589_cs'
     Enables the driver for the 3Com 3c589 PCMCIA card.

`--enable-axnet_cs'
     Enables the driver for the Asix AX88190-based PCMCIA cards.

`--enable-fmvj18x_cs'
     Enables the driver for PCMCIA cards with the fmvj18x chipset.

`--enable-nmclan_cs'
     Enables the driver for the New Media Ethernet LAN PCMCIA cards.

`--enable-pcnet_cs'
     Enables the driver for NS8390-based PCMCIA cards.

     This driver supports the D-Link DE-650 and Linksys EthernetCard
     cards, the newer D-Link and Linksys combo cards, Accton EN2212
     cards, the RPTI EP400, and the PreMax PE-200 in non-shared-memory
     mode, and the IBM Credit Card Adapter, the NE4100, the Thomas
     Conrad ethernet card, and the Kingston KNE-PCM/x in shared-memory
     mode.  It will also handle the Socket EA card in either mode.

`--enable-smc91c92_cs'
     Enables the driver for SMC91c92-based PCMCIA cards.

`--enable-xirc2ps_cs'
     Enables the driver for Xircom CreditCard and Realport PCMCIA
     ethernet adapters.

   The following options enable drivers for supported PCMCIA Wireless
LAN network controllers.  NIC device names are usually eth%d.

   Please mind, that you need to have some userland applications (the
GNU Mach Wireless Tools) installed, in order to make use of these
devices.

`--enable-orinoco_cs'
     Enables the driver for the Hermes or Prism 2 chipset based PCMCIA
     wireless adapters, with Lucent/Agere, Intersil or Symbol firmware.

     This driver is suitable for PCMCIA wireless adapters, such as the
     Lucent WavelanIEEE/Orinoco cards and their OEM (Cabletron/EnteraSys
     RoamAbout 802.11, ELSA Airlancer, Melco Buffalo and others).  It
     should also be usable on various Prism II based cards such as the
     Linksys, D-Link and Farallon Skyline. It should also work on Symbol
     cards such as the 3Com AirConnect and Ericsson WLAN.


File: mach.info,  Node: Cross-Compilation,  Prev: Configuration,  Up: Installing

2.4 Cross-Compilation
=====================

Another way to install the kernel is to use an existing operating system
in order to compile the kernel binary.  This is called
"cross-compiling", because it is done between two different platforms.
If the pre-built kernels are not working for you, and you can't ask
someone to compile a custom kernel for your machine, this is your last
chance to get a kernel that boots on your hardware.

   Luckily, the kernel does have light dependencies.  You don't even
need a cross compiler if your build machine has a compiler and is the
same architecture as the system you want to run GNU Mach on.

   You need a cross-mig, though.

   XXX More info needed.


File: mach.info,  Node: Bootstrap,  Next: Inter Process Communication,  Prev: Installing,  Up: Top

3 Bootstrap
***********

Bootstrapping(1) is the procedure by which your machine loads the
microkernel and transfers control to the operating system.

* Menu:

* Bootloader::                    Starting the microkernel, or other OSes.
* Modules::                       Starting the first task of the OS.

   ---------- Footnotes ----------

   (1) The term "bootstrapping" refers to a Dutch legend about a boy
who was able to fly by pulling himself up by his bootstraps.  In
computers, this term refers to any process where a simple system
activates a more complicated system.


File: mach.info,  Node: Bootloader,  Next: Modules,  Up: Bootstrap

3.1 Bootloader
==============

The "bootloader" is the first software that runs on your machine.  Many
hardware architectures have a very simple startup routine which reads a
very simple bootloader from the beginning of the internal hard disk,
then transfers control to it.  Other architectures have startup
routines which are able to understand more of the contents of the hard
disk, and directly start a more advanced bootloader.

   Currently, "GRUB"(1) is the preferred GNU bootloader.  GRUB provides
advanced functionality, and is capable of loading several different
kernels (such as Mach, Linux, DOS, and the *BSD family).  *Note
Introduction: (grub)Top.

   GNU Mach conforms to the Multiboot specification which defines an
interface between the bootloader and the components that run very early
at startup.  GNU Mach can be started by any bootloader which supports
the multiboot standard.  After the bootloader loaded the kernel image to
a designated address in the system memory, it jumps into the startup
code of the kernel.  This code initializes the kernel and detects the
available hardware devices.  Afterwards, the first system task is
started.  *Note Overview: (multiboot)Top.

   ---------- Footnotes ----------

   (1) The GRand Unified Bootloader, available from
`http://www.uruk.org/grub/'.


File: mach.info,  Node: Modules,  Prev: Bootloader,  Up: Bootstrap

3.2 Modules
===========

Because the microkernel does not provide filesystem support and other
features necessary to load the first system task from a storage medium,
the first task is loaded by the bootloader as a module to a specified
address.  In the GNU system, this first program is the `serverboot'
executable.  GNU Mach inserts the host control port and the device
master port into this task and appends the port numbers to the command
line before executing it.

   The `serverboot' program is responsible for loading and executing
the rest of the Hurd servers.  Rather than containing specific
instructions for starting the Hurd, it follows general steps given in a
user-supplied boot script.

   XXX More about boot scripts.


File: mach.info,  Node: Inter Process Communication,  Next: Virtual Memory Interface,  Prev: Bootstrap,  Up: Top

4 Inter Process Communication
*****************************

This chapter describes the details of the Mach IPC system.  First the
actual calls concerned with sending and receiving messages are
discussed, then the details of the port system are described in detail.

* Menu:

* Major Concepts::                The concepts behind the Mach IPC system.
* Messaging Interface::           Composing, sending and receiving messages.
* Port Manipulation Interface::   Manipulating ports, port rights, port sets.


File: mach.info,  Node: Major Concepts,  Next: Messaging Interface,  Up: Inter Process Communication

4.1 Major Concepts
==================

The Mach kernel provides message-oriented, capability-based interprocess
communication.  The interprocess communication (IPC) primitives
efficiently support many different styles of interaction, including
remote procedure calls (RPC), object-oriented distributed programming,
streaming of data, and sending very large amounts of data.

   The IPC primitives operate on three abstractions: messages, ports,
and port sets.  User tasks access all other kernel services and
abstractions via the IPC primitives.

   The message primitives let tasks send and receive messages.  Tasks
send messages to ports.  Messages sent to a port are delivered reliably
(messages may not be lost) and are received in the order in which they
were sent.  Messages contain a fixed-size header and a variable amount
of typed data following the header.  The header describes the
destination and size of the message.

   The IPC implementation makes use of the VM system to efficiently
transfer large amounts of data.  The message body can contain the
address of a region in the sender's address space which should be
transferred as part of the message.  When a task receives a message
containing an out-of-line region of data, the data appears in an unused
portion of the receiver's address space.  This transmission of
out-of-line data is optimized so that sender and receiver share the
physical pages of data copy-on-write, and no actual data copy occurs
unless the pages are written.  Regions of memory up to the size of a
full address space may be sent in this manner.

   Ports hold a queue of messages.  Tasks operate on a port to send and
receive messages by exercising capabilities for the port.  Multiple
tasks can hold send capabilities, or rights, for a port.  Tasks can also
hold send-once rights, which grant the ability to send a single message.
Only one task can hold the receive capability, or receive right, for a
port.  Port rights can be transferred between tasks via messages.  The
sender of a message can specify in the message body that the message
contains a port right.  If a message contains a receive right for a
port, then the receive right is removed from the sender of the message
and the right is transferred to the receiver of the message.  While the
receive right is in transit, tasks holding send rights can still send
messages to the port, and they are queued until a task acquires the
receive right and uses it to receive the messages.

   Tasks can receive messages from ports and port sets.  The port set
abstraction allows a single thread to wait for a message from any of
several ports.  Tasks manipulate port sets with a capability, or
port-set right, which is taken from the same space as the port
capabilities.  The port-set right may not be transferred in a message.
A port set holds receive rights, and a receive operation on a port set
blocks waiting for a message sent to any of the constituent ports.  A
port may not belong to more than one port set, and if a port is a member
of a port set, the holder of the receive right can't receive directly
from the port.

   Port rights are a secure, location-independent way of naming ports.
The port queue is a protected data structure, only accessible via the
kernel's exported message primitives.  Rights are also protected by the
kernel; there is no way for a malicious user task to guess a port name
and send a message to a port to which it shouldn't have access.  Port
rights do not carry any location information.  When a receive right for
a port moves from task to task, and even between tasks on different
machines, the send rights for the port remain unchanged and continue to
function.


File: mach.info,  Node: Messaging Interface,  Next: Port Manipulation Interface,  Prev: Major Concepts,  Up: Inter Process Communication

4.2 Messaging Interface
=======================

This section describes how messages are composed, sent and received
within the Mach IPC system.

* Menu:

* Mach Message Call::             Sending and receiving messages.
* Message Format::                The format of Mach messages.
* Exchanging Port Rights::        Sending and receiving port rights.
* Memory::                        Passing memory regions in messages.
* Message Send::                  Sending messages.
* Message Receive::               Receiving messages.
* Atomicity::                     Atomicity of port rights.


File: mach.info,  Node: Mach Message Call,  Next: Message Format,  Up: Messaging Interface

4.2.1 Mach Message Call
-----------------------

To use the `mach_msg' call, you can include the header files
`mach/port.h' and `mach/message.h'.

 -- Function: mach_msg_return_t mach_msg (mach_msg_header_t *MSG,
          mach_msg_option_t OPTION, mach_msg_size_t SEND_SIZE,
          mach_msg_size_t RCV_SIZE, mach_port_t RCV_NAME,
          mach_msg_timeout_t TIMEOUT, mach_port_t NOTIFY)
     The `mach_msg' function is used to send and receive messages.  Mach
     messages contain typed data, which can include port rights and
     references to large regions of memory.

     MSG is the address of a buffer in the caller's address space.
     Message buffers should be aligned on long-word boundaries.  The
     message options OPTION are bit values, combined with bitwise-or.
     One or both of `MACH_SEND_MSG' and `MACH_RCV_MSG' should be used.
     Other options act as modifiers.  When sending a message, SEND_SIZE
     specifies the size of the message buffer.  Otherwise zero should be
     supplied.  When receiving a message, RCV_SIZE specifies the size
     of the message buffer.  Otherwise zero should be supplied.  When
     receiving a message, RCV_NAME specifies the port or port set.
     Otherwise `MACH_PORT_NULL' should be supplied.  When using the
     `MACH_SEND_TIMEOUT' and `MACH_RCV_TIMEOUT' options, TIMEOUT
     specifies the time in milliseconds to wait before giving up.
     Otherwise `MACH_MSG_TIMEOUT_NONE' should be supplied.  When using
     the `MACH_SEND_NOTIFY', `MACH_SEND_CANCEL', and `MACH_RCV_NOTIFY'
     options, NOTIFY specifies the port used for the notification.
     Otherwise `MACH_PORT_NULL' should be supplied.

     If the option argument is `MACH_SEND_MSG', it sends a message.  The
     SEND_SIZE argument specifies the size of the message to send.  The
     `msgh_remote_port' field of the message header specifies the
     destination of the message.

     If the option argument is `MACH_RCV_MSG', it receives a message.
     The RCV_SIZE argument specifies the size of the message buffer
     that will receive the message; messages larger than RCV_SIZE are
     not received.  The RCV_NAME argument specifies the port or port
     set from which to receive.

     If the option argument is `MACH_SEND_MSG|MACH_RCV_MSG', then
     `mach_msg' does both send and receive operations.  If the send
     operation encounters an error (any return code other than
     `MACH_MSG_SUCCESS'), then the call returns immediately without
     attempting the receive operation.  Semantically the combined call
     is equivalent to separate send and receive calls, but it saves a
     system call and enables other internal optimizations.

     If the option argument specifies neither `MACH_SEND_MSG' nor
     `MACH_RCV_MSG', then `mach_msg' does nothing.

     Some options, like `MACH_SEND_TIMEOUT' and `MACH_RCV_TIMEOUT',
     share a supporting argument.  If these options are used together,
     they make independent use of the supporting argument's value.

 -- Data type: mach_msg_timeout_t
     This is a `natural_t' used by the timeout mechanism.  The units are
     milliseconds.  The value to be used when there is no timeout is
     `MACH_MSG_TIMEOUT_NONE'.


File: mach.info,  Node: Message Format,  Next: Exchanging Port Rights,  Prev: Mach Message Call,  Up: Messaging Interface

4.2.2 Message Format
--------------------

A Mach message consists of a fixed size message header, a
`mach_msg_header_t', followed by zero or more data items.  Data items
are typed.  Each item has a type descriptor followed by the actual data
(or the address of the data, for out-of-line memory regions).

   The following data types are related to Mach ports:

 -- Data type: mach_port_t
     The `mach_port_t' data type is an unsigned integer type which
     represents a port name in the task's port name space.  In GNU
     Mach, this is an `unsigned int'.

   The following data types are related to Mach messages:

 -- Data type: mach_msg_bits_t
     The `mach_msg_bits_t' data type is an `unsigned int' used to store
     various flags for a message.

 -- Data type: mach_msg_size_t
     The `mach_msg_size_t' data type is an `unsigned int' used to store
     the size of a message.

 -- Data type: mach_msg_id_t
     The `mach_msg_id_t' data type is an `integer_t' typically used to
     convey a function or operation id for the receiver.

 -- Data type: mach_msg_header_t
     This structure is the start of every message in the Mach IPC
     system.  It has the following members:

    `mach_msg_bits_t msgh_bits'
          The `msgh_bits' field has the following bits defined, all
          other bits should be zero:

         `MACH_MSGH_BITS_REMOTE_MASK'
         `MACH_MSGH_BITS_LOCAL_MASK'
               The remote and local bits encode `mach_msg_type_name_t'
               values that specify the port rights in the
               `msgh_remote_port' and `msgh_local_port' fields.  The
               remote value must specify a send or send-once right for
               the destination of the message.  If the local value
               doesn't specify a send or send-once right for the
               message's reply port, it must be zero and
               msgh_local_port must be `MACH_PORT_NULL'.

         `MACH_MSGH_BITS_COMPLEX'
               The complex bit must be specified if the message body
               contains port rights or out-of-line memory regions.  If
               it is not specified, then the message body carries no
               port rights or memory, no matter what the type
               descriptors may seem to indicate.

          `MACH_MSGH_BITS_REMOTE' and `MACH_MSGH_BITS_LOCAL' macros
          return the appropriate `mach_msg_type_name_t' values, given a
          `msgh_bits' value.  The `MACH_MSGH_BITS' macro constructs a
          value for `msgh_bits', given two `mach_msg_type_name_t'
          values.

    `mach_msg_size_t msgh_size'
          The `msgh_size' field in the header of a received message
          contains the message's size.  The message size, a byte
          quantity, includes the message header, type descriptors, and
          in-line data.  For out-of-line memory regions, the message
          size includes the size of the in-line address, not the size
          of the actual memory region.  There are no arbitrary limits
          on the size of a Mach message, the number of data items in a
          message, or the size of the data items.

    `mach_port_t msgh_remote_port'
          The `msgh_remote_port' field specifies the destination port
          of the message.  The field must carry a legitimate send or
          send-once right for a port.

    `mach_port_t msgh_local_port'
          The `msgh_local_port' field specifies an auxiliary port right,
          which is conventionally used as a reply port by the recipient
          of the message.  The field must carry a send right, a
          send-once right, `MACH_PORT_NULL', or `MACH_PORT_DEAD'.

    `mach_port_seqno_t msgh_seqno'
          The `msgh_seqno' field provides a sequence number for the
          message.  It is only valid in received messages; its value in
          sent messages is overwritten.

    `mach_msg_id_t msgh_id'
          The `mach_msg' call doesn't use the `msgh_id' field, but it
          conventionally conveys an operation or function id.

 -- Macro: mach_msg_bits_t MACH_MSGH_BITS (mach_msg_type_name_t REMOTE,
          mach_msg_type_name_t LOCAL)
     This macro composes two `mach_msg_type_name_t' values that specify
     the port rights in the `msgh_remote_port' and `msgh_local_port'
     fields of a `mach_msg' call into an appropriate `mach_msg_bits_t'
     value.

 -- Macro: mach_msg_type_name_t MACH_MSGH_BITS_REMOTE
          (mach_msg_bits_t BITS)
     This macro extracts the `mach_msg_type_name_t' value for the remote
     port right in a `mach_msg_bits_t' value.

 -- Macro: mach_msg_type_name_t MACH_MSGH_BITS_LOCAL
          (mach_msg_bits_t BITS)
     This macro extracts the `mach_msg_type_name_t' value for the local
     port right in a `mach_msg_bits_t' value.

 -- Macro: mach_msg_bits_t MACH_MSGH_BITS_PORTS (mach_msg_bits_t BITS)
     This macro extracts the `mach_msg_bits_t' component consisting of
     the `mach_msg_type_name_t' values for the remote and local port
     right in a `mach_msg_bits_t' value.

 -- Macro: mach_msg_bits_t MACH_MSGH_BITS_OTHER (mach_msg_bits_t BITS)
     This macro extracts the `mach_msg_bits_t' component consisting of
     everything except the `mach_msg_type_name_t' values for the remote
     and local port right in a `mach_msg_bits_t' value.

   Each data item has a type descriptor, a `mach_msg_type_t' or a
`mach_msg_type_long_t'.  The `mach_msg_type_long_t' type descriptor
allows larger values for some fields.  The `msgtl_header' field in the
long descriptor is only used for its inline, longform, and deallocate
bits.

 -- Data type: mach_msg_type_name_t
     This is an `unsigned int' and can be used to hold the `msgt_name'
     component of the `mach_msg_type_t' and `mach_msg_type_long_t'
     structure.

 -- Data type: mach_msg_type_size_t
     This is an `unsigned int' and can be used to hold the `msgt_size'
     component of the `mach_msg_type_t' and `mach_msg_type_long_t'
     structure.

 -- Data type: mach_msg_type_number_t
     This is an `natural_t' and can be used to hold the `msgt_number'
     component of the `mach_msg_type_t' and `mach_msg_type_long_t'
     structure.

 -- Data type: mach_msg_type_t
     This structure has the following members:

    `unsigned int msgt_name : 8'
          The `msgt_name' field specifies the data's type.  The
          following types are predefined:

         `MACH_MSG_TYPE_UNSTRUCTURED'

         `MACH_MSG_TYPE_BIT'

         `MACH_MSG_TYPE_BOOLEAN'

         `MACH_MSG_TYPE_INTEGER_16'

         `MACH_MSG_TYPE_INTEGER_32'

         `MACH_MSG_TYPE_CHAR'

         `MACH_MSG_TYPE_BYTE'

         `MACH_MSG_TYPE_INTEGER_8'

         `MACH_MSG_TYPE_REAL'

         `MACH_MSG_TYPE_STRING'

         `MACH_MSG_TYPE_STRING_C'

         `MACH_MSG_TYPE_PORT_NAME'

          The following predefined types specify port rights, and
          receive special treatment.  The next section discusses these
          types in detail.  The type `MACH_MSG_TYPE_PORT_NAME'
          describes port right names, when no rights are being
          transferred, but just names.  For this purpose, it should be
          used in preference to `MACH_MSG_TYPE_INTEGER_32'.

         `MACH_MSG_TYPE_MOVE_RECEIVE'

         `MACH_MSG_TYPE_MOVE_SEND'

         `MACH_MSG_TYPE_MOVE_SEND_ONCE'

         `MACH_MSG_TYPE_COPY_SEND'

         `MACH_MSG_TYPE_MAKE_SEND'

         `MACH_MSG_TYPE_MAKE_SEND_ONCE'

    `msgt_size : 8'
          The `msgt_size' field specifies the size of each datum, in
          bits.  For example, the msgt_size of
          `MACH_MSG_TYPE_INTEGER_32' data is 32.

    `msgt_number : 12'
          The `msgt_number' field specifies how many data elements
          comprise the data item.  Zero is a legitimate number.

          The total length specified by a type descriptor is
          `(msgt_size * msgt_number)', rounded up to an integral number
          of bytes.  In-line data is then padded to an integral number
          of long-words.  This ensures that type descriptors always
          start on long-word boundaries.  It implies that message sizes
          are always an integral multiple of a long-word's size.

    `msgt_inline : 1'
          The `msgt_inline' bit specifies, when `FALSE', that the data
          actually resides in an out-of-line region.  The address of
          the memory region (a `vm_offset_t' or `vm_address_t') follows
          the type descriptor in the message body.  The `msgt_name',
          `msgt_size', and `msgt_number' fields describe the memory
          region, not the address.

    `msgt_longform : 1'
          The `msgt_longform' bit specifies, when `TRUE', that this type
          descriptor is a `mach_msg_type_long_t' instead of a
          `mach_msg_type_t'.  The `msgt_name', `msgt_size', and
          `msgt_number' fields should be zero.  Instead, `mach_msg' uses
          the following `msgtl_name', `msgtl_size', and `msgtl_number'
          fields.

    `msgt_deallocate : 1'
          The `msgt_deallocate' bit is used with out-of-line regions.
          When `TRUE', it specifies that the memory region should be
          deallocated from the sender's address space (as if with
          `vm_deallocate') when the message is sent.

    `msgt_unused : 1'
          The `msgt_unused' bit should be zero.

 -- Macro: boolean_t MACH_MSG_TYPE_PORT_ANY (mach_msg_type_name_t type)
     This macro returns `TRUE' if the given type name specifies a port
     type, otherwise it returns `FALSE'.

 -- Macro: boolean_t MACH_MSG_TYPE_PORT_ANY_SEND (mach_msg_type_name_t
          type)
     This macro returns `TRUE' if the given type name specifies a port
     type with a send or send-once right, otherwise it returns `FALSE'.

 -- Macro: boolean_t MACH_MSG_TYPE_PORT_ANY_RIGHT (mach_msg_type_name_t
          type)
     This macro returns `TRUE' if the given type name specifies a port
     right type which is moved, otherwise it returns `FALSE'.

 -- Data type: mach_msg_type_long_t
     This structure has the following members:

    `mach_msg_type_t msgtl_header'
          Same meaning as `msgt_header'.

    `unsigned short msgtl_name'
          Same meaning as `msgt_name'.

    `unsigned short msgtl_size'
          Same meaning as `msgt_size'.

    `unsigned int msgtl_number'
          Same meaning as `msgt_number'.


File: mach.info,  Node: Exchanging Port Rights,  Next: Memory,  Prev: Message Format,  Up: Messaging Interface

4.2.3 Exchanging Port Rights
----------------------------

Each task has its own space of port rights.  Port rights are named with
positive integers.  Except for the reserved values
`MACH_PORT_NULL (0)'(1) and `MACH_PORT_DEAD (~0)', this is a full 32-bit
name space.  When the kernel chooses a name for a new right, it is free
to pick any unused name (one which denotes no right) in the space.

   There are five basic kinds of rights: receive rights, send rights,
send-once rights, port-set rights, and dead names.  Dead names are not
capabilities.  They act as place-holders to prevent a name from being
otherwise used.

   A port is destroyed, or dies, when its receive right is deallocated.
When a port dies, send and send-once rights for the port turn into dead
names.  Any messages queued at the port are destroyed, which deallocates
the port rights and out-of-line memory in the messages.

   Tasks may hold multiple user-references for send rights and dead
names.  When a task receives a send right which it already holds, the
kernel increments the right's user-reference count.  When a task
deallocates a send right, the kernel decrements its user-reference
count, and the task only loses the send right when the count goes to
zero.

   Send-once rights always have a user-reference count of one, although
a port can have multiple send-once rights, because each send-once right
held by a task has a different name.  In contrast, when a task holds
send rights or a receive right for a port, the rights share a single
name.

   A message body can carry port rights; the `msgt_name' (`msgtl_name')
field in a type descriptor specifies the type of port right and how the
port right is to be extracted from the caller.  The values
`MACH_PORT_NULL' and `MACH_PORT_DEAD' are always valid in place of a
port right in a message body.  In a sent message, the following
`msgt_name' values denote port rights:

`MACH_MSG_TYPE_MAKE_SEND'
     The message will carry a send right, but the caller must supply a
     receive right.  The send right is created from the receive right,
     and the receive right's make-send count is incremented.

`MACH_MSG_TYPE_COPY_SEND'
     The message will carry a send right, and the caller should supply
     a send right.  The user reference count for the supplied send
     right is not changed.  The caller may also supply a dead name and
     the receiving task will get `MACH_PORT_DEAD'.

`MACH_MSG_TYPE_MOVE_SEND'
     The message will carry a send right, and the caller should supply
     a send right.  The user reference count for the supplied send
     right is decremented, and the right is destroyed if the count
     becomes zero.  Unless a receive right remains, the name becomes
     available for recycling.  The caller may also supply a dead name,
     which loses a user reference, and the receiving task will get
     `MACH_PORT_DEAD'.

`MACH_MSG_TYPE_MAKE_SEND_ONCE'
     The message will carry a send-once right, but the caller must
     supply a receive right.  The send-once right is created from the
     receive right.

`MACH_MSG_TYPE_MOVE_SEND_ONCE'
     The message will carry a send-once right, and the caller should
     supply a send-once right.  The caller loses the supplied send-once
     right.  The caller may also supply a dead name, which loses a user
     reference, and the receiving task will get `MACH_PORT_DEAD'.

`MACH_MSG_TYPE_MOVE_RECEIVE'
     The message will carry a receive right, and the caller should
     supply a receive right.  The caller loses the supplied receive
     right, but retains any send rights with the same name.

   If a message carries a send or send-once right, and the port dies
while the message is in transit, then the receiving task will get
`MACH_PORT_DEAD' instead of a right.  The following `msgt_name' values
in a received message indicate that it carries port rights:

`MACH_MSG_TYPE_PORT_SEND'
     This name is an alias for `MACH_MSG_TYPE_MOVE_SEND'.  The message
     carried a send right.  If the receiving task already has send
     and/or receive rights for the port, then that name for the port
     will be reused.  Otherwise, the new right will have a new name.
     If the task already has send rights, it gains a user reference for
     the right (unless this would cause the user-reference count to
     overflow).  Otherwise, it acquires the send right, with a
     user-reference count of one.

`MACH_MSG_TYPE_PORT_SEND_ONCE'
     This name is an alias for `MACH_MSG_TYPE_MOVE_SEND_ONCE'.  The
     message carried a send-once right.  The right will have a new name.

`MACH_MSG_TYPE_PORT_RECEIVE'
     This name is an alias for `MACH_MSG_TYPE_MOVE_RECEIVE'.  The
     message carried a receive right.  If the receiving task already
     has send rights for the port, then that name for the port will be
     reused.  Otherwise, the right will have a new name.  The make-send
     count of the receive right is reset to zero, but the port retains
     other attributes like queued messages, extant send and send-once
     rights, and requests for port-destroyed and no-senders
     notifications.

   When the kernel chooses a new name for a port right, it can choose
any name, other than `MACH_PORT_NULL' and `MACH_PORT_DEAD', which is
not currently being used for a port right or dead name.  It might
choose a name which at some previous time denoted a port right, but is
currently unused.

   ---------- Footnotes ----------

   (1) In the Hurd system, we don't make the assumption that
`MACH_PORT_NULL' is zero and evaluates to false, but rather compare
port names to `MACH_PORT_NULL' explicitely


File: mach.info,  Node: Memory,  Next: Message Send,  Prev: Exchanging Port Rights,  Up: Messaging Interface

4.2.4 Memory
------------

A message body can contain the address of a region in the sender's
address space which should be transferred as part of the message.  The
message carries a logical copy of the memory, but the kernel uses VM
techniques to defer any actual page copies.  Unless the sender or the
receiver modifies the data, the physical pages remain shared.

   An out-of-line transfer occurs when the data's type descriptor
specifies `msgt_inline' as `FALSE'.  The address of the memory region (a
`vm_offset_t' or `vm_address_t') should follow the type descriptor in
the message body.  The type descriptor and the address contribute to
the message's size (`send_size', `msgh_size').  The out-of-line data
does not contribute to the message's size.

   The name, size, and number fields in the type descriptor describe the
type and length of the out-of-line data, not the in-line address.
Out-of-line memory frequently requires long type descriptors
(`mach_msg_type_long_t'), because the `msgt_number' field is too small
to describe a page of 4K bytes.

   Out-of-line memory arrives somewhere in the receiver's address space
as new memory.  It has the same inheritance and protection attributes as
newly `vm_allocate''d memory.  The receiver has the responsibility of
deallocating (with `vm_deallocate') the memory when it is no longer
needed.  Security-conscious receivers should exercise caution when
using out-of-line memory from untrustworthy sources, because the memory
may be backed by an unreliable memory manager.

   Null out-of-line memory is legal.  If the out-of-line region size is
zero (for example, because `msgtl_number' is zero), then the region's
specified address is ignored.  A received null out-of-line memory
region always has a zero address.

   Unaligned addresses and region sizes that are not page multiples are
legal.  A received message can also contain memory with unaligned
addresses and funny sizes.  In the general case, the first and last
pages in the new memory region in the receiver do not contain only data
from the sender, but are partly zero.(1)  The received address points
to the start of the data in the first page.  This possibility doesn't
complicate deallocation, because `vm_deallocate' does the right thing,
rounding the start address down and the end address up to deallocate
all arrived pages.

   Out-of-line memory has a deallocate option, controlled by the
`msgt_deallocate' bit.  If it is `TRUE' and the out-of-line memory
region is not null, then the region is implicitly deallocated from the
sender, as if by `vm_deallocate'.  In particular, the start and end
addresses are rounded so that every page overlapped by the memory
region is deallocated.  The use of `msgt_deallocate' effectively
changes the memory copy into a memory movement.  In a received message,
`msgt_deallocate' is `TRUE' in type descriptors for out-of-line memory.

   Out-of-line memory can carry port rights.

   ---------- Footnotes ----------

   (1) Sending out-of-line memory with a non-page-aligned address, or a
size which is not a page multiple, works but with a caveat.  The extra
bytes in the first and last page of the received memory are not zeroed,
so the receiver can peek at more data than the sender intended to
transfer.  This might be a security problem for the sender.


File: mach.info,  Node: Message Send,  Next: Message Receive,  Prev: Memory,  Up: Messaging Interface

4.2.5 Message Send
------------------

The send operation queues a message to a port.  The message carries a
copy of the caller's data.  After the send, the caller can freely modify
the message buffer or the out-of-line memory regions and the message
contents will remain unchanged.

   Message delivery is reliable and sequenced.  Messages are not lost,
and messages sent to a port, from a single thread, are received in the
order in which they were sent.

   If the destination port's queue is full, then several things can
happen.  If the message is sent to a send-once right (`msgh_remote_port'
carries a send-once right), then the kernel ignores the queue limit and
delivers the message.  Otherwise the caller blocks until there is room
in the queue, unless the `MACH_SEND_TIMEOUT' or `MACH_SEND_NOTIFY'
options are used.  If a port has several blocked senders, then any of
them may queue the next message when space in the queue becomes
available, with the proviso that a blocked sender will not be
indefinitely starved.

   These options modify `MACH_SEND_MSG'.  If `MACH_SEND_MSG' is not
also specified, they are ignored.

`MACH_SEND_TIMEOUT'
     The timeout argument should specify a maximum time (in
     milliseconds) for the call to block before giving up.(1)  If the
     message can't be queued before the timeout interval elapses, then
     the call returns `MACH_SEND_TIMED_OUT'.  A zero timeout is
     legitimate.

`MACH_SEND_NOTIFY'
     The notify argument should specify a receive right for a notify
     port.  If the send were to block, then instead the message is
     queued, `MACH_SEND_WILL_NOTIFY' is returned, and a msg-accepted
     notification is requested.  If `MACH_SEND_TIMEOUT' is also
     specified, then `MACH_SEND_NOTIFY' doesn't take effect until the
     timeout interval elapses.

     With `MACH_SEND_NOTIFY', a task can forcibly queue to a send right
     one message at a time.  A msg-accepted notification is sent to the
     the notify port when another message can be forcibly queued.  If
     an attempt is made to use `MACH_SEND_NOTIFY' before then, the call
     returns a `MACH_SEND_NOTIFY_IN_PROGRESS' error.

     The msg-accepted notification carries the name of the send right.
     If the send right is deallocated before the msg-accepted
     notification is generated, then the msg-accepted notification
     carries the value `MACH_PORT_NULL'.  If the destination port is
     destroyed before the notification is generated, then a send-once
     notification is generated instead.

`MACH_SEND_INTERRUPT'
     If specified, the `mach_msg' call will return
     `MACH_SEND_INTERRUPTED' if a software interrupt aborts the call.
     Otherwise, the send operation will be retried.

`MACH_SEND_CANCEL'
     The notify argument should specify a receive right for a notify
     port.  If the send operation removes the destination port right
     from the caller, and the removed right had a dead-name request
     registered for it, and notify is the notify port for the dead-name
     request, then the dead-name request may be silently canceled
     (instead of resulting in a port-deleted notification).

     This option is typically used to cancel a dead-name request made
     with the `MACH_RCV_NOTIFY' option.  It should only be used as an
     optimization.

   The send operation can generate the following return codes.  These
return codes imply that the call did nothing:

`MACH_SEND_MSG_TOO_SMALL'
     The specified send_size was smaller than the minimum size for a
     message.

`MACH_SEND_NO_BUFFER'
     A resource shortage prevented the kernel from allocating a message
     buffer.

`MACH_SEND_INVALID_DATA'
     The supplied message buffer was not readable.

`MACH_SEND_INVALID_HEADER'
     The `msgh_bits' value was invalid.

`MACH_SEND_INVALID_DEST'
     The `msgh_remote_port' value was invalid.

`MACH_SEND_INVALID_REPLY'
     The `msgh_local_port' value was invalid.

`MACH_SEND_INVALID_NOTIFY'
     When using `MACH_SEND_CANCEL', the notify argument did not denote a
     valid receive right.

   These return codes imply that some or all of the message was
destroyed:

`MACH_SEND_INVALID_MEMORY'
     The message body specified out-of-line data that was not readable.

`MACH_SEND_INVALID_RIGHT'
     The message body specified a port right which the caller didn't
     possess.

`MACH_SEND_INVALID_TYPE'
     A type descriptor was invalid.

`MACH_SEND_MSG_TOO_SMALL'
     The last data item in the message ran over the end of the message.

   These return codes imply that the message was returned to the caller
with a pseudo-receive operation:

`MACH_SEND_TIMED_OUT'
     The timeout interval expired.

`MACH_SEND_INTERRUPTED'
     A software interrupt occurred.

`MACH_SEND_INVALID_NOTIFY'
     When using `MACH_SEND_NOTIFY', the notify argument did not denote a
     valid receive right.

`MACH_SEND_NO_NOTIFY'
     A resource shortage prevented the kernel from setting up a
     msg-accepted notification.

`MACH_SEND_NOTIFY_IN_PROGRESS'
     A msg-accepted notification was already requested, and hasn't yet
     been generated.

   These return codes imply that the message was queued:

`MACH_SEND_WILL_NOTIFY'
     The message was forcibly queued, and a msg-accepted notification
     was requested.

`MACH_MSG_SUCCESS'
     The message was queued.

   Some return codes, like `MACH_SEND_TIMED_OUT', imply that the
message was almost sent, but could not be queued.  In these situations,
the kernel tries to return the message contents to the caller with a
pseudo-receive operation.  This prevents the loss of port rights or
memory which only exist in the message.  For example, a receive right
which was moved into the message, or out-of-line memory sent with the
deallocate bit.

   The pseudo-receive operation is very similar to a normal receive
operation.  The pseudo-receive handles the port rights in the message
header as if they were in the message body.  They are not reversed.
After the pseudo-receive, the message is ready to be resent.  If the
message is not resent, note that out-of-line memory regions may have
moved and some port rights may have changed names.

   The pseudo-receive operation may encounter resource shortages.  This
is similar to a `MACH_RCV_BODY_ERROR' return code from a receive
operation.  When this happens, the normal send return codes are
augmented with the `MACH_MSG_IPC_SPACE', `MACH_MSG_VM_SPACE',
`MACH_MSG_IPC_KERNEL', and `MACH_MSG_VM_KERNEL' bits to indicate the
nature of the resource shortage.

   The queueing of a message carrying receive rights may create a
circular loop of receive rights and messages, which can never be
received.  For example, a message carrying a receive right can be sent
to that receive right.  This situation is not an error, but the kernel
will garbage-collect such loops, destroying the messages and ports
involved.

   ---------- Footnotes ----------

   (1) If MACH_SEND_TIMEOUT is used without MACH_SEND_INTERRUPT, then
the timeout duration might not be accurate.  When the call is
interrupted and automatically retried, the original timeout is used.
If interrupts occur frequently enough, the timeout interval might never
expire.


File: mach.info,  Node: Message Receive,  Next: Atomicity,  Prev: Message Send,  Up: Messaging Interface

4.2.6 Message Receive
---------------------

The receive operation dequeues a message from a port.  The receiving
task acquires the port rights and out-of-line memory regions carried in
the message.

   The `rcv_name' argument specifies a port or port set from which to
receive.  If a port is specified, the caller must possess the receive
right for the port and the port must not be a member of a port set.  If
no message is present, then the call blocks, subject to the
`MACH_RCV_TIMEOUT' option.

   If a port set is specified, the call will receive a message sent to
any of the member ports.  It is permissible for the port set to have no
member ports, and ports may be added and removed while a receive from
the port set is in progress.  The received message can come from any of
the member ports which have messages, with the proviso that a member
port with messages will not be indefinitely starved.  The
`msgh_local_port' field in the received message header specifies from
which port in the port set the message came.

   The `rcv_size' argument specifies the size of the caller's message
buffer.  The `mach_msg' call will not receive a message larger than
`rcv_size'.  Messages that are too large are destroyed, unless the
`MACH_RCV_LARGE' option is used.

   The destination and reply ports are reversed in a received message
header.  The `msgh_local_port' field names the destination port, from
which the message was received, and the `msgh_remote_port' field names
the reply port right.  The bits in `msgh_bits' are also reversed.  The
`MACH_MSGH_BITS_LOCAL' bits have the value `MACH_MSG_TYPE_PORT_SEND' if
the message was sent to a send right, and the value
`MACH_MSG_TYPE_PORT_SEND_ONCE' if was sent to a send-once right.  The
`MACH_MSGH_BITS_REMOTE' bits describe the reply port right.

   A received message can contain port rights and out-of-line memory.
The `msgh_local_port' field does not receive a port right; the act of
receiving the message destroys the send or send-once right for the
destination port.  The msgh_remote_port field does name a received port
right, the reply port right, and the message body can carry port rights
and memory if `MACH_MSGH_BITS_COMPLEX' is present in msgh_bits.
Received port rights and memory should be consumed or deallocated in
some fashion.

   In almost all cases, `msgh_local_port' will specify the name of a
receive right, either `rcv_name' or if `rcv_name' is a port set, a
member of `rcv_name'.  If other threads are concurrently manipulating
the receive right, the situation is more complicated.  If the receive
right is renamed during the call, then `msgh_local_port' specifies the
right's new name.  If the caller loses the receive right after the
message was dequeued from it, then `mach_msg' will proceed instead of
returning `MACH_RCV_PORT_DIED'.  If the receive right was destroyed,
then `msgh_local_port' specifies `MACH_PORT_DEAD'.  If the receive
right still exists, but isn't held by the caller, then
`msgh_local_port' specifies `MACH_PORT_NULL'.

   Received messages are stamped with a sequence number, taken from the
port from which the message was received.  (Messages received from a
port set are stamped with a sequence number from the appropriate member
port.)  Newly created ports start with a zero sequence number, and the
sequence number is reset to zero whenever the port's receive right moves
between tasks.  When a message is dequeued from the port, it is stamped
with the port's sequence number and the port's sequence number is then
incremented.  The dequeue and increment operations are atomic, so that
multiple threads receiving messages from a port can use the
`msgh_seqno' field to reconstruct the original order of the messages.

   These options modify `MACH_RCV_MSG'.  If `MACH_RCV_MSG' is not also
specified, they are ignored.

`MACH_RCV_TIMEOUT'
     The timeout argument should specify a maximum time (in
     milliseconds) for the call to block before giving up.(1)  If no
     message arrives before the timeout interval elapses, then the call
     returns `MACH_RCV_TIMED_OUT'.  A zero timeout is legitimate.

`MACH_RCV_NOTIFY'
     The notify argument should specify a receive right for a notify
     port.  If receiving the reply port creates a new port right in the
     caller, then the notify port is used to request a dead-name
     notification for the new port right.

`MACH_RCV_INTERRUPT'
     If specified, the `mach_msg' call will return
     `MACH_RCV_INTERRUPTED' if a software interrupt aborts the call.
     Otherwise, the receive operation will be retried.

`MACH_RCV_LARGE'
     If the message is larger than `rcv_size', then the message remains
     queued instead of being destroyed.  The call returns
     `MACH_RCV_TOO_LARGE' and the actual size of the message is returned
     in the `msgh_size' field of the message header.

   The receive operation can generate the following return codes.  These
return codes imply that the call did not dequeue a message:

`MACH_RCV_INVALID_NAME'
     The specified `rcv_name' was invalid.

`MACH_RCV_IN_SET'
     The specified port was a member of a port set.

`MACH_RCV_TIMED_OUT'
     The timeout interval expired.

`MACH_RCV_INTERRUPTED'
     A software interrupt occurred.

`MACH_RCV_PORT_DIED'
     The caller lost the rights specified by `rcv_name'.

`MACH_RCV_PORT_CHANGED'
     `rcv_name' specified a receive right which was moved into a port
     set during the call.

`MACH_RCV_TOO_LARGE'
     When using `MACH_RCV_LARGE', and the message was larger than
     `rcv_size'.  The message is left queued, and its actual size is
     returned in the `msgh_size' field of the message buffer.

   These return codes imply that a message was dequeued and destroyed:

`MACH_RCV_HEADER_ERROR'
     A resource shortage prevented the reception of the port rights in
     the message header.

`MACH_RCV_INVALID_NOTIFY'
     When using `MACH_RCV_NOTIFY', the notify argument did not denote a
     valid receive right.

`MACH_RCV_TOO_LARGE'
     When not using `MACH_RCV_LARGE', a message larger than `rcv_size'
     was dequeued and destroyed.

   In these situations, when a message is dequeued and then destroyed,
the reply port and all port rights and memory in the message body are
destroyed.  However, the caller receives the message's header, with all
fields correct, including the destination port but excepting the reply
port, which is `MACH_PORT_NULL'.

   These return codes imply that a message was received:

`MACH_RCV_BODY_ERROR'
     A resource shortage prevented the reception of a port right or
     out-of-line memory region in the message body.  The message header,
     including the reply port, is correct.  The kernel attempts to
     transfer all port rights and memory regions in the body, and only
     destroys those that can't be transferred.

`MACH_RCV_INVALID_DATA'
     The specified message buffer was not writable.  The calling task
     did successfully receive the port rights and out-of-line memory
     regions in the message.

`MACH_MSG_SUCCESS'
     A message was received.

   Resource shortages can occur after a message is dequeued, while
transferring port rights and out-of-line memory regions to the receiving
task.  The `mach_msg' call returns `MACH_RCV_HEADER_ERROR' or
`MACH_RCV_BODY_ERROR' in this situation.  These return codes always
carry extra bits (bitwise-ored) that indicate the nature of the resource
shortage:

`MACH_MSG_IPC_SPACE'
     There was no room in the task's IPC name space for another port
     name.

`MACH_MSG_VM_SPACE'
     There was no room in the task's VM address space for an out-of-line
     memory region.

`MACH_MSG_IPC_KERNEL'
     A kernel resource shortage prevented the reception of a port right.

`MACH_MSG_VM_KERNEL'
     A kernel resource shortage prevented the reception of an
     out-of-line memory region.

   If a resource shortage prevents the reception of a port right, the
port right is destroyed and the caller sees the name `MACH_PORT_NULL'.
If a resource shortage prevents the reception of an out-of-line memory
region, the region is destroyed and the caller receives a zero address.
In addition, the `msgt_size' (`msgtl_size') field in the data's type
descriptor is changed to zero.  If a resource shortage prevents the
reception of out-of-line memory carrying port rights, then the port
rights are always destroyed if the memory region can not be received.
A task never receives port rights or memory regions that it isn't told
about.

   ---------- Footnotes ----------

   (1) If MACH_RCV_TIMEOUT is used without MACH_RCV_INTERRUPT, then the
timeout duration might not be accurate.  When the call is interrupted
and automatically retried, the original timeout is used.  If interrupts
occur frequently enough, the timeout interval might never expire.


File: mach.info,  Node: Atomicity,  Prev: Message Receive,  Up: Messaging Interface

4.2.7 Atomicity
---------------

The `mach_msg' call handles port rights in a message header atomically.
Port rights and out-of-line memory in a message body do not enjoy this
atomicity guarantee.  The message body may be processed front-to-back,
back-to-front, first out-of-line memory then port rights, in some
random order, or even atomically.

   For example, consider sending a message with the destination port
specified as `MACH_MSG_TYPE_MOVE_SEND' and the reply port specified as
`MACH_MSG_TYPE_COPY_SEND'.  The same send right, with one
user-reference, is supplied for both the `msgh_remote_port' and
`msgh_local_port' fields.  Because `mach_msg' processes the message
header atomically, this succeeds.  If `msgh_remote_port' were processed
before `msgh_local_port', then `mach_msg' would return
`MACH_SEND_INVALID_REPLY' in this situation.

   On the other hand, suppose the destination and reply port are both
specified as `MACH_MSG_TYPE_MOVE_SEND', and again the same send right
with one user-reference is supplied for both.  Now the send operation
fails, but because it processes the header atomically, mach_msg can
return either `MACH_SEND_INVALID_DEST' or `MACH_SEND_INVALID_REPLY'.

   For example, consider receiving a message at the same time another
thread is deallocating the destination receive right.  Suppose the reply
port field carries a send right for the destination port.  If the
deallocation happens before the dequeuing, then the receiver gets
`MACH_RCV_PORT_DIED'.  If the deallocation happens after the receive,
then the `msgh_local_port' and the `msgh_remote_port' fields both
specify the same right, which becomes a dead name when the receive
right is deallocated.  If the deallocation happens between the dequeue
and the receive, then the `msgh_local_port' and `msgh_remote_port'
fields both specify `MACH_PORT_DEAD'.  Because the header is processed
atomically, it is not possible for just one of the two fields to hold
`MACH_PORT_DEAD'.

   The `MACH_RCV_NOTIFY' option provides a more likely example.
Suppose a message carrying a send-once right reply port is received with
`MACH_RCV_NOTIFY' at the same time the reply port is destroyed.  If the
reply port is destroyed first, then `msgh_remote_port' specifies
`MACH_PORT_DEAD' and the kernel does not generate a dead-name
notification.  If the reply port is destroyed after it is received,
then `msgh_remote_port' specifies a dead name for which the kernel
generates a dead-name notification.  It is not possible to receive the
reply port right and have it turn into a dead name before the dead-name
notification is requested; as part of the message header the reply port
is received atomically.


File: mach.info,  Node: Port Manipulation Interface,  Prev: Messaging Interface,  Up: Inter Process Communication

4.3 Port Manipulation Interface
===============================

This section describes the interface to create, destroy and manipulate
ports, port rights and port sets.

 -- Data type: ipc_space_t
     This is a `task_t' (and as such a `mach_port_t'), which holds a
     port name associated with a port that represents an IPC space in
     the kernel.  An IPC space is used by the kernel to manage the port
     names and rights available to a task.  The IPC space doesn't get a
     port name of its own.  Instead the port name of the task
     containing the IPC space is used to name the IPC space of the task
     (as is indicated by the fact that the type of `ipc_space_t' is
     actually `task_t').

     The IPC spaces of tasks are the only ones accessible outside of
     the kernel.

* Menu:

* Port Creation::                 How to create new ports and port sets.
* Port Destruction::              How to destroy ports and port sets.
* Port Names::                    How to query and manipulate port names.
* Port Rights::                   How to work with port rights.
* Ports and other Tasks::         How to move rights between tasks.
* Receive Rights::                How to work with receive rights.
* Port Sets::                     How to work with port sets.
* Request Notifications::         How to request notifications for events.


File: mach.info,  Node: Port Creation,  Next: Port Destruction,  Up: Port Manipulation Interface

4.3.1 Port Creation
-------------------

 -- Function: kern_return_t mach_port_allocate (ipc_space_t TASK,
          mach_port_right_t RIGHT, mach_port_t *NAME)
     The `mach_port_allocate' function creates a new right in the
     specified task.  The new right's name is returned in NAME, which
     may be any name that wasn't in use.

     The RIGHT argument takes the following values:

    `MACH_PORT_RIGHT_RECEIVE'
          `mach_port_allocate' creates a port.  The new port is not a
          member of any port set.  It doesn't have any extant send or
          send-once rights.  Its make-send count is zero, its sequence
          number is zero, its queue limit is
          `MACH_PORT_QLIMIT_DEFAULT', and it has no queued messages.
          NAME denotes the receive right for the new port.

          TASK does not hold send rights for the new port, only the
          receive right.  `mach_port_insert_right' and
          `mach_port_extract_right' can be used to convert the receive
          right into a combined send/receive right.

    `MACH_PORT_RIGHT_PORT_SET'
          `mach_port_allocate' creates a port set.  The new port set
          has no members.

    `MACH_PORT_RIGHT_DEAD_NAME'
          `mach_port_allocate' creates a dead name.  The new dead name
          has one user reference.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_TASK' if TASK was invalid, `KERN_INVALID_VALUE' if
     RIGHT was invalid, `KERN_NO_SPACE' if there was no room in TASK's
     IPC name space for another right and `KERN_RESOURCE_SHORTAGE' if
     the kernel ran out of memory.

     The `mach_port_allocate' call is actually an RPC to TASK, normally
     a send right for a task port, but potentially any send right.  In
     addition to the normal diagnostic return codes from the call's
     server (normally the kernel), the call may return `mach_msg'
     return codes.

 -- Function: mach_port_t mach_reply_port ()
     The `mach_reply_port' system call creates a reply port in the
     calling task.

     `mach_reply_port' creates a port, giving the calling task the
     receive right for the port.  The call returns the name of the new
     receive right.

     This is very much like creating a receive right with the
     `mach_port_allocate' call, with two differences.  First,
     `mach_reply_port' is a system call and not an RPC (which requires a
     reply port).  Second, the port created by `mach_reply_port' may be
     optimized for use as a reply port.

     The function returns `MACH_PORT_NULL' if a resource shortage
     prevented the creation of the receive right.

 -- Function: kern_return_t mach_port_allocate_name (ipc_space_t TASK,
          mach_port_right_t RIGHT, mach_port_t NAME)
     The function `mach_port_allocate_name' creates a new right in the
     specified task, with a specified name for the new right.  NAME
     must not already be in use for some right, and it can't be the
     reserved values `MACH_PORT_NULL' and `MACH_PORT_DEAD'.

     The RIGHT argument takes the following values:

    `MACH_PORT_RIGHT_RECEIVE'
          `mach_port_allocate_name' creates a port.  The new port is
          not a member of any port set.  It doesn't have any extant
          send or send-once rights.  Its make-send count is zero, its
          sequence number is zero, its queue limit is
          `MACH_PORT_QLIMIT_DEFAULT', and it has no queued messages.
          NAME denotes the receive right for the new port.

          TASK does not hold send rights for the new port, only the
          receive right.  `mach_port_insert_right' and
          `mach_port_extract_right' can be used to convert the receive
          right into a combined send/receive right.

    `MACH_PORT_RIGHT_PORT_SET'
          `mach_port_allocate_name' creates a port set.  The new port
          set has no members.

    `MACH_PORT_RIGHT_DEAD_NAME'
          `mach_port_allocate_name' creates a new dead name.  The new
          dead name has one user reference.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_TASK' if TASK was invalid, `KERN_INVALID_VALUE' if
     RIGHT was invalid or NAME was `MACH_PORT_NULL' or
     `MACH_PORT_DEAD', `KERN_NAME_EXISTS' if NAME was already in use
     for a port right and `KERN_RESOURCE_SHORTAGE' if the kernel ran
     out of memory.

     The `mach_port_allocate_name' call is actually an RPC to TASK,
     normally a send right for a task port, but potentially any send
     right.  In addition to the normal diagnostic return codes from the
     call's server (normally the kernel), the call may return `mach_msg'
     return codes.


File: mach.info,  Node: Port Destruction,  Next: Port Names,  Prev: Port Creation,  Up: Port Manipulation Interface

4.3.2 Port Destruction
----------------------

 -- Function: kern_return_t mach_port_deallocate (ipc_space_t TASK,
          mach_port_t NAME)
     The function `mach_port_deallocate' releases a user reference for a
     right in TASK's IPC name space.  It allows a task to release a
     user reference for a send or send-once right without failing if
     the port has died and the right is now actually a dead name.

     If NAME denotes a dead name, send right, or send-once right, then
     the right loses one user reference.  If it only had one user
     reference, then the right is destroyed.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_TASK' if TASK was invalid, `KERN_INVALID_NAME' if
     NAME did not denote a right and `KERN_INVALID_RIGHT' if NAME
     denoted an invalid right.

     The `mach_port_deallocate' call is actually an RPC to TASK,
     normally a send right for a task port, but potentially any send
     right.  In addition to the normal diagnostic return codes from the
     call's server (normally the kernel), the call may return `mach_msg'
     return codes.

 -- Function: kern_return_t mach_port_destroy (ipc_space_t TASK,
          mach_port_t NAME)
     The function `mach_port_destroy' deallocates all rights denoted by
     a name.  The name becomes immediately available for reuse.

     For most purposes, `mach_port_mod_refs' and `mach_port_deallocate'
     are preferable.

     If NAME denotes a port set, then all members of the port set are
     implicitly removed from the port set.

     If NAME denotes a receive right that is a member of a port set,
     the receive right is implicitly removed from the port set.  If
     there is a port-destroyed request registered for the port, then
     the receive right is not actually destroyed, but instead is sent
     in a port-destroyed notification to the backup port.  If there is
     no registered port-destroyed request, remaining messages queued to
     the port are destroyed and extant send and send-once rights turn
     into dead names.  If those send and send-once rights have
     dead-name requests registered, then dead-name notifications are
     generated for them.

     If NAME denotes a send-once right, then the send-once right is
     used to produce a send-once notification for the port.

     If NAME denotes a send-once, send, and/or receive right, and it
     has a dead-name request registered, then the registered send-once
     right is used to produce a port-deleted notification for the name.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_TASK' if TASK was invalid, `KERN_INVALID_NAME' if
     NAME did not denote a right.

     The `mach_port_destroy' call is actually an RPC to TASK, normally
     a send right for a task port, but potentially any send right.  In
     addition to the normal diagnostic return codes from the call's
     server (normally the kernel), the call may return `mach_msg'
     return codes.


File: mach.info,  Node: Port Names,  Next: Port Rights,  Prev: Port Destruction,  Up: Port Manipulation Interface

4.3.3 Port Names
----------------

 -- Function: kern_return_t mach_port_names (ipc_space_t TASK,
          mach_port_array_t *NAMES, mach_msg_type_number_t *NCOUNT,
          mach_port_type_array_t *TYPES, mach_msg_type_number_t *TCOUNT)
     The function `mach_port_names' returns information about TASK's
     port name space.  For each name, it also returns what type of
     rights TASK holds.  (The same information returned by
     `mach_port_type'.)  NAMES and TYPES are arrays that are
     automatically allocated when the reply message is received. The
     user should `vm_deallocate' them when the data is no longer needed.

     `mach_port_names' will return in NAMES the names of the ports,
     port sets, and dead names in the task's port name space, in no
     particular order and in NCOUNT the number of names returned.  It
     will return in TYPES the type of each corresponding name, which
     indicates what kind of rights the task holds with that name.
     TCOUNT should be the same as NCOUNT.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_TASK' if TASK was invalid, `KERN_RESOURCE_SHORTAGE'
     if the kernel ran out of memory.

     The `mach_port_names' call is actually an RPC to TASK, normally a
     send right for a task port, but potentially any send right.  In
     addition to the normal diagnostic return codes from the call's
     server (normally the kernel), the call may return `mach_msg'
     return codes.

 -- Function: kern_return_t mach_port_type (ipc_space_t TASK,
          mach_port_t NAME, mach_port_type_t *PTYPE)
     The function `mach_port_type' returns information about TASK's
     rights for a specific name in its port name space.  The returned
     PTYPE is a bitmask indicating what rights TASK holds for the port,
     port set or dead name.  The bitmask is composed of the following
     bits:

    `MACH_PORT_TYPE_SEND'
          The name denotes a send right.

    `MACH_PORT_TYPE_RECEIVE'
          The name denotes a receive right.

    `MACH_PORT_TYPE_SEND_ONCE'
          The name denotes a send-once right.

    `MACH_PORT_TYPE_PORT_SET'
          The name denotes a port set.

    `MACH_PORT_TYPE_DEAD_NAME'
          The name is a dead name.

    `MACH_PORT_TYPE_DNREQUEST'
          A dead-name request has been registered for the right.

    `MACH_PORT_TYPE_MAREQUEST'
          A msg-accepted request for the right is pending.

    `MACH_PORT_TYPE_COMPAT'
          The port right was created in the compatibility mode.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_TASK' if TASK was invalid and `KERN_INVALID_NAME' if
     NAME did not denote a right.

     The `mach_port_type' call is actually an RPC to TASK, normally a
     send right for a task port, but potentially any send right.  In
     addition to the normal diagnostic return codes from the call's
     server (normally the kernel), the call may return `mach_msg'
     return codes.

 -- Function: kern_return_t mach_port_rename (ipc_space_t TASK,
          mach_port_t OLD_NAME, mach_port_t NEW_NAME)
     The function `mach_port_rename' changes the name by which a port,
     port set, or dead name is known to TASK.  OLD_NAME is the original
     name and NEW_NAME the new name for the port right.  NEW_NAME must
     not already be in use, and it can't be the distinguished values
     `MACH_PORT_NULL' and `MACH_PORT_DEAD'.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_TASK' if TASK was invalid, `KERN_INVALID_NAME' if
     OLD_NAME did not denote a right, `KERN_INVALID_VALUE' if NEW_NAME
     was `MACH_PORT_NULL' or `MACH_PORT_DEAD', `KERN_NAME_EXISTS' if
     `new_name' already denoted a right and `KERN_RESOURCE_SHORTAGE' if
     the kernel ran out of memory.

     The `mach_port_rename' call is actually an RPC to TASK, normally a
     send right for a task port, but potentially any send right.  In
     addition to the normal diagnostic return codes from the call's
     server (normally the kernel), the call may return `mach_msg'
     return codes.


File: mach.info,  Node: Port Rights,  Next: Ports and other Tasks,  Prev: Port Names,  Up: Port Manipulation Interface

4.3.4 Port Rights
-----------------

 -- Function: kern_return_t mach_port_get_refs (ipc_space_t TASK,
          mach_port_t NAME, mach_port_right_t RIGHT,
          mach_port_urefs_t *REFS)
     The function `mach_port_get_refs' returns the number of user
     references a task has for a right.

     The RIGHT argument takes the following values:
        * `MACH_PORT_RIGHT_SEND'

        * `MACH_PORT_RIGHT_RECEIVE'

        * `MACH_PORT_RIGHT_SEND_ONCE'

        * `MACH_PORT_RIGHT_PORT_SET'

        * `MACH_PORT_RIGHT_DEAD_NAME'

     If NAME denotes a right, but not the type of right specified, then
     zero is returned.  Otherwise a positive number of user references
     is returned.  Note that a name may simultaneously denote send and
     receive rights.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_TASK' if TASK was invalid, `KERN_INVALID_VALUE' if
     RIGHT was invalid and `KERN_INVALID_NAME' if NAME did not denote a
     right.

     The `mach_port_get_refs' call is actually an RPC to TASK, normally
     a send right for a task port, but potentially any send right.  In
     addition to the normal diagnostic return codes from the call's
     server (normally the kernel), the call may return `mach_msg'
     return codes.

 -- Function: kern_return_t mach_port_mod_refs (ipc_space_t TASK,
          mach_port_t NAME, mach_port_right_t RIGHT,
          mach_port_delta_t DELTA)
     The function `mach_port_mod_refs' requests that the number of user
     references a task has for a right be changed.  This results in the
     right being destroyed, if the number of user references is changed
     to zero.  The task holding the right is TASK, NAME should denote
     the specified right.  RIGHT denotes the type of right being
     modified.  DELTA is the signed change to the number of user
     references.

     The RIGHT argument takes the following values:
        * `MACH_PORT_RIGHT_SEND'

        * `MACH_PORT_RIGHT_RECEIVE'

        * `MACH_PORT_RIGHT_SEND_ONCE'

        * `MACH_PORT_RIGHT_PORT_SET'

        * `MACH_PORT_RIGHT_DEAD_NAME'

     The number of user references for the right is changed by the
     amount DELTA, subject to the following restrictions: port sets,
     receive rights, and send-once rights may only have one user
     reference.  The resulting number of user references can't be
     negative.  If the resulting number of user references is zero, the
     effect is to deallocate the right.  For dead names and send
     rights, there is an implementation-defined maximum number of user
     references.

     If the call destroys the right, then the effect is as described for
     `mach_port_destroy', with the exception that `mach_port_destroy'
     simultaneously destroys all the rights denoted by a name, while
     `mach_port_mod_refs' can only destroy one right.  The name will be
     available for reuse if it only denoted the one right.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_TASK' if TASK was invalid, `KERN_INVALID_VALUE' if
     RIGHT was invalid or the user-reference count would become
     negative, `KERN_INVALID_NAME' if NAME did not denote a right,
     `KERN_INVALID_RIGHT' if NAME denoted a right, but not the
     specified right and `KERN_UREFS_OVERFLOW' if the user-reference
     count would overflow.

     The `mach_port_mod_refs' call is actually an RPC to TASK, normally
     a send right for a task port, but potentially any send right.  In
     addition to the normal diagnostic return codes from the call's
     server (normally the kernel), the call may return `mach_msg'
     return codes.


File: mach.info,  Node: Ports and other Tasks,  Next: Receive Rights,  Prev: Port Rights,  Up: Port Manipulation Interface

4.3.5 Ports and other Tasks
---------------------------

 -- Function: kern_return_t mach_port_insert_right (ipc_space_t TASK,
          mach_port_t NAME, mach_port_t RIGHT,
          mach_msg_type_name_t RIGHT_TYPE)
     The function MACH_PORT_INSERT_RIGHT inserts into TASK the caller's
     right for a port, using a specified name for the right in the
     target task.

     The specified NAME can't be one of the reserved values
     `MACH_PORT_NULL' or `MACH_PORT_DEAD'.  The RIGHT can't be
     `MACH_PORT_NULL' or `MACH_PORT_DEAD'.

     The argument RIGHT_TYPE specifies a right to be inserted and how
     that right should be extracted from the caller.  It should be a
     value appropriate for MSGT_NAME; see `mach_msg'.  If RIGHT_TYPE is
     `MACH_MSG_TYPE_MAKE_SEND', `MACH_MSG_TYPE_MOVE_SEND', or
     `MACH_MSG_TYPE_COPY_SEND', then a send right is inserted.  If the
     target already holds send or receive rights for the port, then
     NAME should denote those rights in the target.  Otherwise, NAME
     should be unused in the target.  If the target already has send
     rights, then those send rights gain an additional user reference.
     Otherwise, the target gains a send right, with a user reference
     count of one.

     If RIGHT_TYPE is `MACH_MSG_TYPE_MAKE_SEND_ONCE' or
     `MACH_MSG_TYPE_MOVE_SEND_ONCE', then a send-once right is inserted.
     The name should be unused in the target.  The target gains a
     send-once right.

     If RIGHT_TYPE is `MACH_MSG_TYPE_MOVE_RECEIVE', then a receive
     right is inserted.  If the target already holds send rights for the
     port, then name should denote those rights in the target.
     Otherwise, name should be unused in the target.  The receive right
     is moved into the target task.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_TASK' if TASK was invalid, `KERN_INVALID_VALUE' if
     RIGHT was not a port right or NAME was `MACH_PORT_NULL' or
     `MACH_PORT_DEAD', `KERN_NAME_EXISTS' if NAME already denoted a
     right, `KERN_INVALID_CAPABILITY' if RIGHT was `MACH_PORT_NULL' or
     `MACH_PORT_DEAD' `KERN_RIGHT_EXISTS' if TASK already had rights
     for the port, with a different name, `KERN_UREFS_OVERFLOW' if the
     user-reference count would overflow and `KERN_RESOURCE_SHORTAGE'
     if the kernel ran out of memory.

     The `mach_port_insert_right' call is actually an RPC to TASK,
     normally a send right for a task port, but potentially any send
     right.  In addition to the normal diagnostic return codes from the
     call's server (normally the kernel), the call may return
     `mach_msg' return codes.

 -- Function: kern_return_t mach_port_extract_right (ipc_space_t TASK,
          mach_port_t NAME, mach_msg_type_name_t DESIRED_TYPE,
          mach_port_t *RIGHT, mach_msg_type_name_t *ACQUIRED_TYPE)
     The function MACH_PORT_EXTRACT_RIGHT extracts a port right from
     the target TASK and returns it to the caller as if the task sent
     the right voluntarily, using DESIRED_TYPE as the value of
     MSGT_NAME.  *Note Mach Message Call::.

     The returned value of ACQUIRED_TYPE will be
     `MACH_MSG_TYPE_PORT_SEND' if a send right is extracted,
     `MACH_MSG_TYPE_PORT_RECEIVE' if a receive right is extracted, and
     `MACH_MSG_TYPE_PORT_SEND_ONCE' if a send-once right is extracted.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_TASK' if TASK was invalid, `KERN_INVALID_NAME' if
     NAME did not denote a right, `KERN_INVALID_RIGHT' if NAME denoted
     a right, but an invalid one, `KERN_INVALID_VALUE' if DESIRED_TYPE
     was invalid.

     The `mach_port_extract_right' call is actually an RPC to TASK,
     normally a send right for a task port, but potentially any send
     right.  In addition to the normal diagnostic return codes from the
     call's server (normally the kernel), the call may return `mach_msg'
     return codes.


File: mach.info,  Node: Receive Rights,  Next: Port Sets,  Prev: Ports and other Tasks,  Up: Port Manipulation Interface

4.3.6 Receive Rights
--------------------

 -- Data type: mach_port_seqno_t
     The `mach_port_seqno_t' data type is an `unsigned int' which
     contains the sequence number of a port.

 -- Data type: mach_port_mscount_t
     The `mach_port_mscount_t' data type is an `unsigned int' which
     contains the make-send count for a port.

 -- Data type: mach_port_msgcount_t
     The `mach_port_msgcount_t' data type is an `unsigned int' which
     contains a number of messages.

 -- Data type: mach_port_rights_t
     The `mach_port_rights_t' data type is an `unsigned int' which
     contains a number of rights for a port.

 -- Data type: mach_port_status_t
     This structure contains some status information about a port,
     which can be queried with `mach_port_get_receive_status'.  It has
     the following members:

    `mach_port_t mps_pset'
          The containing port set.

    `mach_port_seqno_t mps_seqno'
          The sequence number.

    `mach_port_mscount_t mps_mscount'
          The make-send count.

    `mach_port_msgcount_t mps_qlimit'
          The maximum number of messages in the queue.

    `mach_port_msgcount_t mps_msgcount'
          The current number of messages in the queue.

    `mach_port_rights_t mps_sorights'
          The number of send-once rights that exist.

    `boolean_t mps_srights'
          `TRUE' if send rights exist.

    `boolean_t mps_pdrequest'
          `TRUE' if port-deleted notification is requested.

    `boolean_t mps_nsrequest'
          `TRUE' if no-senders notification is requested.

 -- Function: kern_return_t mach_port_get_receive_status
          (ipc_space_t TASK, mach_port_t NAME,
          mach_port_status_t *STATUS)
     The function `mach_port_get_receive_status' returns the current
     status of the specified receive right.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_TASK' if TASK was invalid, `KERN_INVALID_NAME' if
     NAME did not denote a right and `KERN_INVALID_RIGHT' if NAME
     denoted a right, but not a receive right.

     The `mach_port_get_receive_status' call is actually an RPC to TASK,
     normally a send right for a task port, but potentially any send
     right.  In addition to the normal diagnostic return codes from the
     call's server (normally the kernel), the call may return
     `mach_msg' return codes.

 -- Function: kern_return_t mach_port_set_mscount (ipc_space_t TASK,
          mach_port_t NAME, mach_port_mscount_t MSCOUNT)
     The function `mach_port_set_mscount' changes the make-send count of
     TASK's receive right named NAME to MSCOUNT.  All values for
     MSCOUNT are valid.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_TASK' if TASK was invalid, `KERN_INVALID_NAME' if
     NAME did not denote a right and `KERN_INVALID_RIGHT' if NAME
     denoted a right, but not a receive right.

     The `mach_port_set_mscount' call is actually an RPC to TASK,
     normally a send right for a task port, but potentially any send
     right.  In addition to the normal diagnostic return codes from the
     call's server (normally the kernel), the call may return
     `mach_msg' return codes.

 -- Function: kern_return_t mach_port_set_qlimit (ipc_space_t TASK,
          mach_port_t NAME, mach_port_msgcount_t QLIMIT)
     The function `mach_port_set_qlimit' changes the queue limit TASK's
     receive right named NAME to QLIMIT.  Valid values for QLIMIT are
     between zero and `MACH_PORT_QLIMIT_MAX', inclusive.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_TASK' if TASK was invalid, `KERN_INVALID_NAME' if
     NAME did not denote a right, `KERN_INVALID_RIGHT' if NAME denoted
     a right, but not a receive right and `KERN_INVALID_VALUE' if
     QLIMIT was invalid.

     The `mach_port_set_qlimit' call is actually an RPC to TASK,
     normally a send right for a task port, but potentially any send
     right.  In addition to the normal diagnostic return codes from the
     call's server (normally the kernel), the call may return
     `mach_msg' return codes.

 -- Function: kern_return_t mach_port_set_seqno (ipc_space_t TASK,
          mach_port_t NAME, mach_port_seqno_t SEQNO)
     The function `mach_port_set_seqno' changes the sequence number
     TASK's receive right named NAME to SEQNO.  All sequence number
     values are valid.  The next message received from the port will be
     stamped with the specified sequence number.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_TASK' if TASK was invalid, `KERN_INVALID_NAME' if
     NAME did not denote a right and `KERN_INVALID_RIGHT' if NAME
     denoted a right, but not a receive right.

     The `mach_port_set_seqno' call is actually an RPC to TASK,
     normally a send right for a task port, but potentially any send
     right.  In addition to the normal diagnostic return codes from the
     call's server (normally the kernel), the call may return
     `mach_msg' return codes.


File: mach.info,  Node: Port Sets,  Next: Request Notifications,  Prev: Receive Rights,  Up: Port Manipulation Interface

4.3.7 Port Sets
---------------

 -- Function: kern_return_t mach_port_get_set_status (ipc_space_t TASK,
          mach_port_t NAME, mach_port_array_t *MEMBERS,
          mach_msg_type_number_t *COUNT)
     The function `mach_port_get_set_status' returns the members of a
     port set.  MEMBERS is an array that is automatically allocated
     when the reply message is received.  The user should
     `vm_deallocate' it when the data is no longer needed.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_TASK' if TASK was invalid, `KERN_INVALID_NAME' if
     NAME did not denote a right, `KERN_INVALID_RIGHT' if NAME denoted
     a right, but not a receive right and `KERN_RESOURCE_SHORTAGE' if
     the kernel ran out of memory.

     The `mach_port_get_set_status' call is actually an RPC to TASK,
     normally a send right for a task port, but potentially any send
     right.  In addition to the normal diagnostic return codes from the
     call's server (normally the kernel), the call may return `mach_msg'
     return codes.

 -- Function: kern_return_t mach_port_move_member (ipc_space_t TASK,
          mach_port_t MEMBER, mach_port_t AFTER)
     The function MACH_PORT_MOVE_MEMBER moves the receive right MEMBER
     into the port set AFTER.  If the receive right is already a member
     of another port set, it is removed from that set first (the whole
     operation is atomic).  If the port set is `MACH_PORT_NULL', then
     the receive right is not put into a port set, but removed from its
     current port set.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_TASK' if TASK was invalid, `KERN_INVALID_NAME' if
     MEMBER or AFTER did not denote a right, `KERN_INVALID_RIGHT' if
     MEMBER denoted a right, but not a receive right or AFTER denoted a
     right, but not a port set, and `KERN_NOT_IN_SET' if AFTER was
     `MACH_PORT_NULL', but `member' wasn't currently in a port set.

     The `mach_port_move_member' call is actually an RPC to TASK,
     normally a send right for a task port, but potentially any send
     right.  In addition to the normal diagnostic return codes from the
     call's server (normally the kernel), the call may return
     `mach_msg' return codes.


File: mach.info,  Node: Request Notifications,  Prev: Port Sets,  Up: Port Manipulation Interface

4.3.8 Request Notifications
---------------------------

 -- Function: kern_return_t mach_port_request_notification
          (ipc_space_t TASK, mach_port_t NAME, mach_msg_id_t VARIANT,
          mach_port_mscount_t SYNC, mach_port_t NOTIFY,
          mach_msg_type_name_t NOTIFY_TYPE, mach_port_t *PREVIOUS)
     The function `mach_port_request_notification' registers a request
     for a notification and supplies the send-once right NOTIFY to
     which the notification will be sent.  The NOTIFY_TYPE denotes the
     IPC type for the send-once right, which can be
     `MACH_MSG_TYPE_MAKE_SEND_ONCE' or `MACH_MSG_TYPE_MOVE_SEND_ONCE'.
     It is an atomic swap, returning the previously registered
     send-once right (or `MACH_PORT_NULL' for none) in PREVIOUS.  A
     previous notification request may be cancelled by providing
     `MACH_PORT_NULL' for NOTIFY.

     The VARIANT argument takes the following values:

    `MACH_NOTIFY_PORT_DESTROYED'
          SYNC must be zero.  The NAME must specify a receive right,
          and the call requests a port-destroyed notification for the
          receive right.  If the receive right were to have been
          destroyed, say by `mach_port_destroy', then instead the
          receive right will be sent in a port-destroyed notification
          to the registered send-once right.

    `MACH_NOTIFY_DEAD_NAME'
          The call requests a dead-name notification.  NAME specifies
          send, receive, or send-once rights for a port.  If the port
          is destroyed (and the right remains, becoming a dead name),
          then a dead-name notification which carries the name of the
          right will be sent to the registered send-once right.  If
          NOTIFY is not null and sync is non-zero, the name may specify
          a dead name, and a dead-name notification is immediately
          generated.

          Whenever a dead-name notification is generated, the user
          reference count of the dead name is incremented.  For
          example, a send right with two user refs has a registered
          dead-name request.  If the port is destroyed, the send right
          turns into a dead name with three user refs (instead of two),
          and a dead-name notification is generated.

          If the name is made available for reuse, perhaps because of
          `mach_port_destroy' or `mach_port_mod_refs', or the name
          denotes a send-once right which has a message sent to it,
          then the registered send-once right is used to generate a
          port-deleted notification.

    `MACH_NOTIFY_NO_SENDERS'
          The call requests a no-senders notification.  NAME must
          specify a receive right.  If NOTIFY is not null, and the
          receive right's make-send count is greater than or equal to
          the sync value, and it has no extant send rights, than an
          immediate no-senders notification is generated.  Otherwise
          the notification is generated when the receive right next
          loses its last extant send right.  In either case, any
          previously registered send-once right is returned.

          The no-senders notification carries the value the port's
          make-send count had when it was generated.  The make-send
          count is incremented whenever `MACH_MSG_TYPE_MAKE_SEND' is
          used to create a new send right from the receive right.  The
          make-send count is reset to zero when the receive right is
          carried in a message.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_TASK' if TASK was invalid, `KERN_INVALID_VALUE' if
     VARIANT was invalid, `KERN_INVALID_NAME' if NAME did not denote a
     right, `KERN_INVALID_RIGHT' if NAME denoted an invalid right and
     `KERN_INVALID_CAPABILITY' if NOTIFY was invalid.

     When using `MACH_NOTIFY_PORT_DESTROYED', the function returns
     `KERN_INVALID_VALUE' if SYNC wasn't zero.

     When using `MACH_NOTIFY_DEAD_NAME', the function returns
     `KERN_RESOURCE_SHORTAGE' if the kernel ran out of memory,
     `KERN_INVALID_ARGUMENT' if NAME denotes a dead name, but SYNC is
     zero or NOTIFY is `MACH_PORT_NULL', and `KERN_UREFS_OVERFLOW' if
     NAME denotes a dead name, but generating an immediate dead-name
     notification would overflow the name's user-reference count.

     The `mach_port_request_notification' call is actually an RPC to
     TASK, normally a send right for a task port, but potentially any
     send right.  In addition to the normal diagnostic return codes
     from the call's server (normally the kernel), the call may return
     `mach_msg' return codes.


File: mach.info,  Node: Virtual Memory Interface,  Next: External Memory Management,  Prev: Inter Process Communication,  Up: Top

5 Virtual Memory Interface
**************************

 -- Data type: vm_task_t
     This is a `task_t' (and as such a `mach_port_t'), which holds a
     port name associated with a port that represents a virtual memory
     map in the kernel.  An virtual memory map is used by the kernel to
     manage the address space of a task.  The virtual memory map
     doesn't get a port name of its own.  Instead the port name of the
     task provided with the virtual memory is used to name the virtual
     memory map of the task (as is indicated by the fact that the type
     of `vm_task_t' is actually `task_t').

     The virtual memory maps of tasks are the only ones accessible
     outside of the kernel.

* Menu:

* Memory Allocation::             Allocation of new virtual memory.
* Memory Deallocation::           Freeing unused virtual memory.
* Data Transfer::                 Reading, writing and copying memory.
* Memory Attributes::             Tweaking memory regions.
* Mapping Memory Objects::        How to map memory objects.
* Memory Statistics::             How to get statistics about memory usage.


File: mach.info,  Node: Memory Allocation,  Next: Memory Deallocation,  Up: Virtual Memory Interface

5.1 Memory Allocation
=====================

 -- Function: kern_return_t vm_allocate (vm_task_t TARGET_TASK,
          vm_address_t *ADDRESS, vm_size_t SIZE, boolean_t ANYWHERE)
     The function `vm_allocate' allocates a region of virtual memory,
     placing it in the specified TASK's address space.

     The starting address is ADDRESS.  If the ANYWHERE option is false,
     an attempt is made to allocate virtual memory starting at this
     virtual address.  If this address is not at the beginning of a
     virtual page, it will be rounded down to one.  If there is not
     enough space at this address, no memory will be allocated.  If the
     ANYWHERE option is true, the input value of this address will be
     ignored, and the space will be allocated wherever it is available.
     In either case, the address at which memory was actually
     allocated will be returned in ADDRESS.

     SIZE is the number of bytes to allocate (rounded by the system in
     a machine dependent way to an integral number of virtual pages).

     If ANYWHERE is true, the kernel should find and allocate any
     region of the specified size, and return the address of the
     resulting region in address address, rounded to a virtual page
     boundary if there is sufficient space.

     The physical memory is not actually allocated until the new virtual
     memory is referenced.  By default, the kernel rounds all addresses
     down to the nearest page boundary and all memory sizes up to the
     nearest page size.  The global variable `vm_page_size' contains
     the page size.  `mach_task_self' returns the value of the current
     task port which should be used as the TARGET_TASK argument in
     order to allocate memory in the caller's address space.  For
     languages other than C, these values can be obtained by the calls
     `vm_statistics' and `mach_task_self'.  Initially, the pages of
     allocated memory will be protected to allow all forms of access,
     and will be inherited in child tasks as a copy.  Subsequent calls
     to `vm_protect' and `vm_inherit' may be used to change these
     properties.  The allocated region is always zero-filled.

     The function returns `KERN_SUCCESS' if the memory was successfully
     allocated, `KERN_INVALID_ADDRESS' if an invalid address was
     specified and `KERN_NO_SPACE' if there was not enough space left to
     satisfy the request.


File: mach.info,  Node: Memory Deallocation,  Next: Data Transfer,  Prev: Memory Allocation,  Up: Virtual Memory Interface

5.2 Memory Deallocation
=======================

 -- Function: kern_return_t vm_deallocate (vm_task_t TARGET_TASK,
          vm_address_t ADDRESS, vm_size_t SIZE)
     `vm_deallocate' relinquishes access to a region of a TASK's
     address space, causing further access to that memory to fail.  This
     address range will be available for reallocation.  ADDRESS is the
     starting address, which will be rounded down to a page boundary.
     SIZE is the number of bytes to deallocate, which will be rounded
     up to give a page boundary.  Note, that because of the rounding to
     virtual page boundaries, more than SIZE bytes may be deallocated.
     Use `vm_page_size' or `vm_statistics' to find out the current
     virtual page size.

     This call may be used to deallocte memory that was passed to a
     task in a message (via out of line data).  In that case, the
     rounding should cause no trouble, since the region of memory was
     allocated as a set of pages.

     The `vm_deallocate' call affects only the task specified by the
     TARGET_TASK.  Other tasks which may have access to this memory may
     continue to reference it.

     The function returns `KERN_SUCCESS' if the memory was successfully
     deallocated and `KERN_INVALID_ADDRESS' if an invalid or
     non-allocated address was specified.


File: mach.info,  Node: Data Transfer,  Next: Memory Attributes,  Prev: Memory Deallocation,  Up: Virtual Memory Interface

5.3 Data Transfer
=================

 -- Function: kern_return_t vm_read (vm_task_t TARGET_TASK,
          vm_address_t ADDRESS, vm_size_t SIZE, vm_offset_t *DATA,
          mach_msg_type_number_t *DATA_COUNT)
     The function `vm_read' allows one task's virtual memory to be read
     by another task.  The TARGET_TASK is the task whose memory is to
     be read.  ADDRESS is the first address to be read and must be on a
     page boundary.  SIZE is the number of bytes of data to be read and
     must be an integral number of pages.  DATA is the array of data
     copied from the given task, and DATA_COUNT is the size of the data
     array in bytes (will be an integral number of pages).

     Note that the data array is returned in a newly allocated region;
     the task reading the data should `vm_deallocate' this region when
     it is done with the data.

     The function returns `KERN_SUCCESS' if the memory was successfully
     read, `KERN_INVALID_ADDRESS' if an invalid or non-allocated address
     was specified or there was not SIZE bytes of data following the
     address, `KERN_INVALID_ARGUMENT' if the address does not start on a
     page boundary or the size is not an integral number of pages,
     `KERN_PROTECTION_FAILURE' if the address region in the target task
     is protected against reading and `KERN_NO_SPACE' if there was not
     enough room in the callers virtual memory to allocate space for
     the data to be returned.

 -- Function: kern_return_t vm_write (vm_task_t TARGET_TASK,
          vm_address_t ADDRESS, vm_offset_t DATA,
          mach_msg_type_number_t DATA_COUNT)
     The function `vm_write' allows a task to write to the vrtual memory
     of TARGET_TASK.  ADDRESS is the starting address in task to be
     affected.  DATA is an array of bytes to be written, and DATA_COUNT
     the size of the DATA array.

     The current implementation requires that ADDRESS, DATA and
     DATA_COUNT all be page-aligned.  Otherwise,
     `KERN_INVALID_ARGUMENT' is returned.

     The function returns `KERN_SUCCESS' if the memory was successfully
     written, `KERN_INVALID_ADDRESS' if an invalid or non-allocated
     address was specified or there was not DATA_COUNT bytes of
     allocated memory starting at ADDRESS and `KERN_PROTECTION_FAILURE'
     if the address region in the target task is protected against
     writing.

 -- Function: kern_return_t vm_copy (vm_task_t TARGET_TASK,
          vm_address_t SOURCE_ADDRESS, vm_size_t COUNT,
          vm_offset_t DEST_ADDRESS)
     The function `vm_copy' causes the source memory range to be copied
     to the destination address.  The source and destination memory
     ranges may overlap.  The destination address range must already be
     allocated and writable; the source range must be readable.

     `vm_copy' is equivalent to `vm_read' followed by `vm_write'.

     The current implementation requires that ADDRESS, DATA and
     DATA_COUNT all be page-aligned.  Otherwise,
     `KERN_INVALID_ARGUMENT' is returned.

     The function returns `KERN_SUCCESS' if the memory was successfully
     written, `KERN_INVALID_ADDRESS' if an invalid or non-allocated
     address was specified or there was insufficient memory allocated
     at one of the addresses and `KERN_PROTECTION_FAILURE' if the
     destination region was not writable or the source region was not
     readable.


File: mach.info,  Node: Memory Attributes,  Next: Mapping Memory Objects,  Prev: Data Transfer,  Up: Virtual Memory Interface

5.4 Memory Attributes
=====================

 -- Function: kern_return_t vm_region (vm_task_t TARGET_TASK,
          vm_address_t *ADDRESS, vm_size_t *SIZE,
          vm_prot_t *PROTECTION, vm_prot_t *MAX_PROTECTION,
          vm_inherit_t *INHERITANCE, boolean_t *SHARED,
          memory_object_name_t *OBJECT_NAME, vm_offset_t *OFFSET)
     The function `vm_region' returns a description of the specified
     region of TARGET_TASK's virtual address space.  `vm_region' begins
     at ADDRESS and looks forward through memory until it comes to an
     allocated region.  If address is within a region, then that region
     is used.  Various bits of information about the region are
     returned.  If ADDRESS was not within a region, then ADDRESS is set
     to the start of the first region which follows the incoming value.
     In this way an entire address space can be scanned.

     The SIZE returned is the size of the located region in bytes.
     PROTECTION is the current protection of the region, MAX_PROTECTION
     is the maximum allowable protection for this region.  INHERITANCE
     is the inheritance attribute for this region.  SHARED tells if the
     region is shared or not.  The port OBJECT_NAME identifies the
     memory object associated with this region, and OFFSET is the
     offset into the pager object that this region begins at.

     The function returns `KERN_SUCCESS' if the memory region was
     successfully located and the information returned and
     `KERN_NO_SPACE' if there is no region at or above ADDRESS in the
     specified task.

 -- Function: kern_return_t vm_protect (vm_task_t TARGET_TASK,
          vm_address_t ADDRESS, vm_size_t SIZE, boolean_t SET_MAXIMUM,
          vm_prot_t NEW_PROTECTION)
     The function `vm_protect' sets the virtual memory access privileges
     for a range of allocated addresses in TARGET_TASK's virtual
     address space.  The protection argument describes a combination of
     read, write, and execute accesses that should be _permitted_.

     ADDRESS is the starting address, which will be rounded down to a
     page boundary.  SIZE is the size in bytes of the region for which
     protection is to change, and will be rounded up to give a page
     boundary.  If SET_MAXIMUM is set, make the protection change apply
     to the maximum protection associated with this address range;
     otherwise, the current protection on this range is changed.  If
     the maximum protection is reduced below the current protection,
     both will be changed to reflect the new maximum.  NEW_PROTECTION
     is the new protection value for this region; a set of:
     `VM_PROT_READ', `VM_PROT_WRITE', `VM_PROT_EXECUTE'.

     The enforcement of virtual memory protection is machine-dependent.
     Nominally read access requires `VM_PROT_READ' permission, write
     access requires `VM_PROT_WRITE' permission, and execute access
     requires `VM_PROT_EXECUTE' permission.  However, some combinations
     of access rights may not be supported.  In particular, the kernel
     interface allows write access to require `VM_PROT_READ' and
     `VM_PROT_WRITE' permission and execute access to require
     `VM_PROT_READ' permission.

     The function returns `KERN_SUCCESS' if the memory was successfully
     protected, `KERN_INVALID_ADDRESS' if an invalid or non-allocated
     address was specified and `KERN_PROTECTION_FAILURE' if an attempt
     was made to increase the current or maximum protection beyond the
     existing maximum protection value.

 -- Function: kern_return_t vm_inherit (vm_task_t TARGET_TASK,
          vm_address_t ADDRESS, vm_size_t SIZE,
          vm_inherit_t NEW_INHERITANCE)
     The function `vm_inherit' specifies how a region of TARGET_TASK's
     address space is to be passed to child tasks at the time of task
     creation.  Inheritance is an attribute of virtual pages, so
     ADDRESS to start from will be rounded down to a page boundary and
     SIZE, the size in bytes of the region for wihch inheritance is to
     change, will be rounded up to give a page boundary.  How this
     memory is to be inherited in child tasks is specified by
     NEW_INHERITANCE.  Inheritance is specified by using one of these
     following three values:

    `VM_INHERIT_SHARE'
          Child tasks will share this memory with this task.

    `VM_INHERIT_COPY'
          Child tasks will receive a copy of this region.

    `VM_INHERIT_NONE'
          This region will be absent from child tasks.

     Setting `vm_inherit' to `VM_INHERIT_SHARE' and forking a child
     task is the only way two Mach tasks can share physical memory.
     Remember that all the theads of a given task share all the same
     memory.

     The function returns `KERN_SUCCESS' if the memory inheritance was
     successfully set and `KERN_INVALID_ADDRESS' if an invalid or
     non-allocated address was specified.

 -- Function: kern_return_t vm_wire (host_priv_t HOST_PRIV,
          vm_task_t TARGET_TASK, vm_address_t ADDRESS, vm_size_t SIZE,
          vm_prot_t ACCESS)
     The function `vm_wire' allows privileged applications to control
     memory pageability.  HOST_PRIV is the privileged host port for the
     host on which TARGET_TASK resides.  ADDRESS is the starting
     address, which will be rounded down to a page boundary.  SIZE is
     the size in bytes of the region for which protection is to change,
     and will be rounded up to give a page boundary.  ACCESS specifies
     the types of accesses that must not cause page faults.

     The semantics of a successful `vm_wire' operation are that memory
     in the specified range will not cause page faults for any accesses
     included in access.  Data memory can be made non-pageable (wired)
     with a access argument of `VM_PROT_READ | VM_PROT_WRITE'.  A
     special case is that `VM_PROT_NONE' makes the memory pageable.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_HOST' if HOST_PRIV was not the privileged host port,
     `KERN_INVALID_TASK' if TASK was not a valid task,
     `KERN_INVALID_VALUE' if ACCESS specified an invalid access mode,
     `KERN_FAILURE' if some memory in the specified range is not
     present or has an inappropriate protection value, and
     `KERN_INVALID_ARGUMENT' if unwiring (ACCESS is `VM_PROT_NONE') and
     the memory is not already wired.

     The `vm_wire' call is actually an RPC to HOST_PRIV, normally a
     send right for a privileged host port, but potentially any send
     right.  In addition to the normal diagnostic return codes from the
     call's server (normally the kernel), the call may return
     `mach_msg' return codes.

 -- Function: kern_return_t vm_machine_attribute (vm_task_t TASK,
          vm_address_t ADDRESS, vm_size_t SIZE, vm_prot_t ACCESS,
          vm_machine_attribute_t ATTRIBUTE,
          vm_machine_attribute_val_t VALUE)
     The function `vm_machine_attribute' specifies machine-specific
     attributes for a VM mapping, such as cachability, migrability,
     replicability.  This is used on machines that allow the user
     control over the cache (this is the case for MIPS architectures)
     or placement of memory pages as in NUMA architectures (Non-Uniform
     Memory Access time) such as the IBM ACE multiprocessor.

     Machine-specific attributes can be consider additions to the
     machine-independent ones such as protection and inheritance, but
     they are not guaranteed to be supported by any given machine.
     Moreover, implementations of Mach on new architectures might find
     the need for new attribute types and or values besides the ones
     defined in the initial implementation.

     The types currently defined are
    `MATTR_CACHE'
          Controls caching of memory pages

    `MATTR_MIGRATE'
          Controls migrability of memory pages

    `MATTR_REPLICATE'
          Controls replication of memory pages

     Corresponding values, and meaning of a specific call to
     `vm_machine_attribute'
    `MATTR_VAL_ON'
          Enables the attribute.  Being enabled is the default value
          for any applicable attribute.

    `MATTR_VAL_OFF'
          Disables the attribute, making memory non-cached, or
          non-migratable, or non-replicatable.

    `MATTR_VAL_GET'
          Returns the current value of the attribute for the memory
          segment.  If the attribute does not apply uniformly to the
          given range the value returned applies to the initial portion
          of the segment only.

    `MATTR_VAL_CACHE_FLUSH'
          Flush the memory pages from the Cache.  The size value in
          this case might be meaningful even if not a multiple of the
          page size, depending on the implementation.

    `MATTR_VAL_ICACHE_FLUSH'
          Same as above, applied to the Instruction Cache alone.

    `MATTR_VAL_DCACHE_FLUSH'
          Same as above, applied to the Data Cache alone.

     The function returns `KERN_SUCCESS' if call succeeded, and
     `KERN_INVALID_ARGUMENT' if TASK is not a task, or ADDRESS and SIZE
     do not define a valid address range in task, or ATTRIBUTE is not a
     valid attribute type, or it is not implemented, or VALUE is not a
     permissible value for attribute.


File: mach.info,  Node: Mapping Memory Objects,  Next: Memory Statistics,  Prev: Memory Attributes,  Up: Virtual Memory Interface

5.5 Mapping Memory Objects
==========================

 -- Function: kern_return_t vm_map (vm_task_t TARGET_TASK,
          vm_address_t *ADDRESS, vm_size_t SIZE, vm_address_t MASK,
          boolean_t ANYWHERE, memory_object_t MEMORY_OBJECT,
          vm_offset_t OFFSET, boolean_t COPY, vm_prot_t CUR_PROTECTION,
          vm_prot_t MAX_PROTECTION, vm_inherit_t INHERITANCE)
     The function `vm_map' maps a region of virtual memory at the
     specified address, for which data is to be supplied by the given
     memory object, starting at the given offset within that object.
     In addition to the arguments used in `vm_allocate', the `vm_map'
     call allows the specification of an address alignment parameter,
     and of the initial protection and inheritance values.

     If the memory object in question is not currently in use, the
     kernel will perform a `memory_object_init' call at this time.  If
     the copy parameter is asserted, the specified region of the memory
     object will be copied to this address space; changes made to this
     object by other tasks will not be visible in this mapping, and
     changes made in this mapping will not be visible to others (or
     returned to the memory object).

     The `vm_map' call returns once the mapping is established.
     Completion of the call does not require any action on the part of
     the memory manager.

     Warning: Only memory objects that are provided by bona fide memory
     managers should be used in the `vm_map' call.  A memory manager
     must implement the memory object interface described elsewhere in
     this manual.  If other ports are used, a thread that accesses the
     mapped virtual memory may become permanently hung or may receive a
     memory exception.

     TARGET_TASK is the task to be affected.  The starting address is
     ADDRESS.  If the ANYWHERE option is used, this address is ignored.
     The address actually allocated will be returned in ADDRESS. SIZE
     is the number of bytes to allocate (rounded by the system in a
     machine dependent way).  The alignment restriction is specified by
     MASK.  Bits asserted in this mask must not be asserted in the
     address returned.  If ANYWHERE is set, the kernel should find and
     allocate any region of the specified size, and return the address
     of the resulting region in ADDRESS.

     MEMORY_OBJECT is the port that represents the memory object: used
     by user tasks in `vm_map'; used by the make requests for data or
     other management actions.  If this port is `MEMORY_OBJECT_NULL',
     then zero-filled memory is allocated instead.  Within a memory
     object, OFFSET specifes an offset in bytes.  This must be page
     aligned.  If COPY is set, the range of the memory object should be
     copied to the target task, rather than mapped read-write.

     The function returns `KERN_SUCCESS' if the object is mapped,
     `KERN_NO_SPACE' if no unused region of the task's virtual address
     space that meets the address, size, and alignment criteria could be
     found, and `KERN_INVALID_ARGUMENT' if an invalid argument was
     provided.


File: mach.info,  Node: Memory Statistics,  Prev: Mapping Memory Objects,  Up: Virtual Memory Interface

5.6 Memory Statistics
=====================

 -- Data type: vm_statistics_data_t
     This structure is returned in VM_STATS by the `vm_statistics'
     function and provides virtual memory statistics for the system.
     It has the following members:

    `long pagesize'
          The page size in bytes.

    `long free_count'
          The number of free pages.

    `long active_count'
          The umber of active pages.

    `long inactive_count'
          The number of inactive pages.

    `long wire_count'
          The number of pages wired down.

    `long zero_fill_count'
          The number of zero filled pages.

    `long reactivations'
          The number of reactivated pages.

    `long pageins'
          The number of pageins.

    `long pageouts'
          The number of pageouts.

    `long faults'
          The number of faults.

    `long cow_faults'
          The number of copy-on-writes.

    `long lookups'
          The number of object cache lookups.

    `long hits'
          The number of object cache hits.

 -- Function: kern_return_t vm_statistics (vm_task_t TARGET_TASK,
          vm_statistics_data_t *VM_STATS)
     The function `vm_statistics' returns the statistics about the
     kernel's use of virtual memory since the kernel was booted.
     `pagesize' can also be found as a global variable `vm_page_size'
     which is set at task initialization and remains constant for the
     life of the task.


File: mach.info,  Node: External Memory Management,  Next: Threads and Tasks,  Prev: Virtual Memory Interface,  Up: Top

6 External Memory Management
****************************

* Menu:

* Memory Object Server::          The basics of external memory management.
* Memory Object Creation::        How new memory objects are created.
* Memory Object Termination::     How memory objects are terminated.
* Memory Objects and Data::       Data transfer to and from memory objects.
* Memory Object Locking::         How memory objects are locked.
* Memory Object Attributes::      Manipulating attributes of memory objects.
* Default Memory Manager::        Setting and using the default memory manager.


File: mach.info,  Node: Memory Object Server,  Next: Memory Object Creation,  Up: External Memory Management

6.1 Memory Object Server
========================

 -- Function: boolean_t memory_object_server (msg_header_t *IN_MSG,
          msg_header_t *OUT_MSG)
 -- Function: boolean_t memory_object_default_server
          (msg_header_t *IN_MSG, msg_header_t *OUT_MSG)
 -- Function: boolean_t seqnos_memory_object_server
          (msg_header_t *IN_MSG, msg_header_t *OUT_MSG)
 -- Function: boolean_t seqnos_memory_object_default_server
          (msg_header_t *IN_MSG, msg_header_t *OUT_MSG)
     A memory manager is a server task that responds to specific
     messages from the kernel in order to handle memory management
     functions for the kernel.

     In order to isolate the memory manager from the specifics of
     message formatting, the remote procedure call generator produces a
     procedure, `memory_object_server', to handle a received message.
     This function does all necessary argument handling, and actually
     calls one of the following functions: `memory_object_init',
     `memory_object_data_write', `memory_object_data_return',
     `memory_object_data_request', `memory_object_data_unlock',
     `memory_object_lock_completed', `memory_object_copy',
     `memory_object_terminate'.  The *default memory manager* may get
     two additional requests from the kernel: `memory_object_create'
     and `memory_object_data_initialize'.  The remote procedure call
     generator produces a procedure `memory_object_default_server' to
     handle those functions specific to the default memory manager.

     The `seqnos_memory_object_server' and
     `seqnos_memory_object_default_server' differ from
     `memory_object_server' and `memory_object_default_server' in that
     they supply message sequence numbers to the server interfaces.
     They call the `seqnos_memory_object_*' functions, which complement
     the `memory_object_*' set of functions.

     The return value from the `memory_object_server' function indicates
     that the message was appropriate to the memory management interface
     (returning `TRUE'), or that it could not handle this message
     (returning `FALSE').

     The IN_MSG argument is the message that has been received from the
     kernel.  The OUT_MSG is a reply message, but this is not used for
     this server.

     The function returns `TRUE' to indicate that the message in
     question was applicable to this interface, and that the appropriate
     routine was called to interpret the message.  It returns `FALSE' to
     indicate that the message did not apply to this interface, and
     that no other action was taken.


File: mach.info,  Node: Memory Object Creation,  Next: Memory Object Termination,  Prev: Memory Object Server,  Up: External Memory Management

6.2 Memory Object Creation
==========================

 -- Function: kern_return_t memory_object_init
          (memory_object_t MEMORY_OBJECT,
          memory_object_control_t MEMORY_CONTROL,
          memory_object_name_t MEMORY_OBJECT_NAME,
          vm_size_t MEMORY_OBJECT_PAGE_SIZE)
 -- Function: kern_return_t seqnos_memory_object_init
          (memory_object_t MEMORY_OBJECT, mach_port_seqno_t SEQNO,
          memory_object_control_t MEMORY_CONTROL,
          memory_object_name_t MEMORY_OBJECT_NAME,
          vm_size_t MEMORY_OBJECT_PAGE_SIZE)
     The function `memory_object_init' serves as a notification that the
     kernel has been asked to map the given memory object into a task's
     virtual address space.  Additionally, it provides a port on which
     the memory manager may issue cache management requests, and a port
     which the kernel will use to name this data region.  In the event
     that different each will perform a `memory_object_init' call with
     new request and name ports.  The virtual page size that is used by
     the calling kernel is included for planning purposes.

     When the memory manager is prepared to accept requests for data
     for this object, it must call `memory_object_ready' with the
     attribute.  Otherwise the kernel will not process requests on this
     object.  To reject all mappings of this object, the memory manager
     may use `memory_object_destroy'.

     The argument MEMORY_OBJECT is the port that represents the memory
     object data, as supplied to the kernel in a `vm_map' call.
     MEMORY_CONTROL is the request port to which a response is
     requested.  (In the event that a memory object has been supplied
     to more than one the kernel that has made the request.)
     MEMORY_OBJECT_NAME is a port used by the kernel to refer to the
     memory object data in reponse to `vm_region' calls.
     `memory_object_page_size' is the page size to be used by this
     kernel.  All data sizes in calls involving this kernel must be an
     integral multiple of the page size.  Note that different kernels,
     indicated by a different `memory_control', may have different page
     sizes.

     The function should return `KERN_SUCCESS', but since this routine
     is called by the kernel, which does not wait for a reply message,
     this value is ignored.

 -- Function: kern_return_t memory_object_ready
          (memory_object_control_t MEMORY_CONTROL,
          boolean_t MAY_CACHE_OBJECT,
          memory_object_copy_strategy_t COPY_STRATEGY)
     The function `memory_object_ready' informs the kernel that the
     memory manager is ready to receive data or unlock requests on
     behalf of the clients.  The argument MEMORY_CONTROL is the port,
     provided by the kernel in a `memory_object_init' call, to which
     cache management requests may be issued.  If MAY_CACHE_OBJECT is
     set, the kernel may keep data associated with this memory object,
     even after virtual memory references to it are gone.

     COPY_STRATEGY tells how the kernel should copy regions of the
     associated memory object.  There are three possible caching
     strategies: `MEMORY_OBJECT_COPY_NONE' which specifies that nothing
     special should be done when data in the object is copied;
     `MEMORY_OBJECT_COPY_CALL' which specifies that the memory manager
     should be notified via a `memory_object_copy' call before any part
     of the object is copied; and `MEMORY_OBJECT_COPY_DELAY' which
     guarantees that the memory manager does not externally modify the
     data so that the kernel can use its normal copy-on-write
     algorithms.  `MEMORY_OBJECT_COPY_DELAY' is the strategy most
     commonly used.

     This routine does not receive a reply message (and consequently
     has no return value), so only message transmission errors apply.


File: mach.info,  Node: Memory Object Termination,  Next: Memory Objects and Data,  Prev: Memory Object Creation,  Up: External Memory Management

6.3 Memory Object Termination
=============================

 -- Function: kern_return_t memory_object_terminate
          (memory_object_t MEMORY_OBJECT,
          memory_object_control_t MEMORY_CONTROL,
          memory_object_name_t MEMORY_OBJECT_NAME)
 -- Function: kern_return_t seqnos_memory_object_terminate
          (memory_object_t MEMORY_OBJECT, mach_port_seqno_t SEQNO,
          memory_object_control_t MEMORY_CONTROL,
          memory_object_name_t MEMORY_OBJECT_NAME)
     The function `memory_object_terminate' indicates that the kernel
     has completed its use of the given memory object.  All rights to
     the memory object control and name ports are included, so that the
     memory manager can destroy them (using `mach_port_deallocate')
     after doing appropriate bookkeeping.  The kernel will terminate a
     memory object only after all address space mappings of that memory
     object have been deallocated, or upon explicit request by the
     memory manager.

     The argument MEMORY_OBJECT is the port that represents the memory
     object data, as supplied to the kernel in a `vm_map' call.
     MEMORY_CONTROL is the request port to which a response is
     requested.  (In the event that a memory object has been supplied
     to more than one the kernel that has made the request.)
     MEMORY_OBJECT_NAME is a port used by the kernel to refer to the
     memory object data in reponse to `vm_region' calls.

     The function should return `KERN_SUCCESS', but since this routine
     is called by the kernel, which does not wait for a reply message,
     this value is ignored.

 -- Function: kern_return_t memory_object_destroy
          (memory_object_control_t MEMORY_CONTROL, kern_return_t REASON)
     The function `memory_object_destroy' tells the kernel to shut down
     the memory object.  As a result of this call the kernel will no
     longer support paging activity or any `memory_object' calls on this
     object, and all rights to the memory object port, the memory
     control port and the memory name port will be returned to the
     memory manager in a memory_object_terminate call.  If the memory
     manager is concerned that any modified cached data be returned to
     it before the object is terminated, it should call
     `memory_object_lock_request' with SHOULD_FLUSH set and a lock
     value of `VM_PROT_WRITE' before making this call.

     The argument MEMORY_CONTROL is the port, provided by the kernel in
     a `memory_object_init' call, to which cache management requests may
     be issued.  REASON is an error code indicating why the object must
     be destroyed.

     This routine does not receive a reply message (and consequently
     has no return value), so only message transmission errors apply.


File: mach.info,  Node: Memory Objects and Data,  Next: Memory Object Locking,  Prev: Memory Object Termination,  Up: External Memory Management

6.4 Memory Objects and Data
===========================

 -- Function: kern_return_t memory_object_data_return
          (memory_object_t MEMORY_OBJECT,
          memory_object_control_t MEMORY_CONTROL, vm_offset_t OFFSET,
          vm_offset_t DATA, vm_size_t DATA_COUNT, boolean_t DIRTY,
          boolean_t KERNEL_COPY)
 -- Function: kern_return_t seqnos_memory_object_data_return
          (memory_object_t MEMORY_OBJECT, mach_port_seqno_t SEQNO,
          memory_object_control_t MEMORY_CONTROL, vm_offset_t OFFSET,
          vm_offset_t DATA, vm_size_t DATA_COUNT, boolean_t DIRTY,
          boolean_t KERNEL_COPY)
     The function `memory_object_data_return' provides the memory
     manager with data that has been modified while cached in physical
     memory.  Once the memory manager no longer needs this data (e.g.,
     it has been written to another storage medium), it should be
     deallocated using `vm_deallocate'.

     The argument MEMORY_OBJECT is the port that represents the memory
     object data, as supplied to the kernel in a `vm_map' call.
     MEMORY_CONTROL is the request port to which a response is
     requested.  (In the event that a memory object has been supplied
     to more than one the kernel that has made the request.)  OFFSET is
     the offset within a memory object to which this call refers.  This
     will be page aligned.  DATA is the data which has been modified
     while cached in physical memory.  DATA_COUNT is the amount of data
     to be written, in bytes.  This will be an integral number of
     memory object pages.

     The kernel will also use this call to return precious pages.  If an
     unmodified precious age is returned, DIRTY is set to `FALSE',
     otherwise it is `TRUE'.  If KERNEL_COPY is `TRUE', the kernel kept
     a copy of the page.  Precious data remains precious if the kernel
     keeps a copy.  The indication that the kernel kept a copy is only
     a hint if the data is not precious; the cleaned copy may be
     discarded without further notifying the manager.

     The function should return `KERN_SUCCESS', but since this routine
     is called by the kernel, which does not wait for a reply message,
     this value is ignored.

 -- Function: kern_return_t memory_object_data_request
          (memory_object_t MEMORY_OBJECT,
          memory_object_control_t MEMORY_CONTROL, vm_offset_t OFFSET,
          vm_offset_t LENGTH, vm_prot_t DESIRED_ACCESS)
 -- Function: kern_return_t seqnos_memory_object_data_request
          (memory_object_t MEMORY_OBJECT, mach_port_seqno_t SEQNO,
          memory_object_control_t MEMORY_CONTROL, vm_offset_t OFFSET,
          vm_offset_t LENGTH, vm_prot_t DESIRED_ACCESS)
     The function `memory_object_data_request' is a request for data
     from the specified memory object, for at least the access
     specified.  The memory manager is expected to return at least the
     specified data, with as much access as it can allow, using
     `memory_object_data_supply'.  If the memory manager is unable to
     provide the data (for example, because of a hardware error), it
     may use the `memory_object_data_error' call.  The
     `memory_object_data_unavailable' call may be used to tell the
     kernel to supply zero-filled memory for this region.

     The argument MEMORY_OBJECT is the port that represents the memory
     object data, as supplied to the kernel in a `vm_map' call.
     MEMORY_CONTROL is the request port to which a response is
     requested.  (In the event that a memory object has been supplied
     to more than one the kernel that has made the request.)  OFFSET is
     the offset within a memory object to which this call refers.  This
     will be page aligned.  LENGTH is the number of bytes of data,
     starting at OFFSET, to which this call refers.  This will be an
     integral number of memory object pages.  DESIRED_ACCESS is a
     protection value describing the memory access modes which must be
     permitted on the specified cached data.  One or more of:
     `VM_PROT_READ', `VM_PROT_WRITE' or `VM_PROT_EXECUTE'.

     The function should return `KERN_SUCCESS', but since this routine
     is called by the kernel, which does not wait for a reply message,
     this value is ignored.

 -- Function: kern_return_t memory_object_data_supply
          (memory_object_control_t MEMORY_CONTROL, vm_offset_t OFFSET,
          vm_offset_t DATA, vm_size_t DATA_COUNT, vm_prot_t LOCK_VALUE,
          boolean_t PRECIOUS, mach_port_t REPLY)
     The function `memory_object_data_supply' supplies the kernel with
     data for the specified memory object.  Ordinarily, memory managers
     should only provide data in reponse to `memory_object_data_request'
     calls from the kernel (but they may provide data in advance as
     desired).  When data already held by this kernel is provided
     again, the new data is ignored.  The kernel may not provide any
     data (or protection) consistency among pages with different
     virtual page alignments within the same object.

     The argument MEMORY_CONTROL is the port, provided by the kernel in
     a `memory_object_init' call, to which cache management requests may
     be issued.  OFFSET is an offset within a memory object in bytes.
     This must be page aligned.  DATA is the data that is being
     provided to the kernel.  This is a pointer to the data.
     DATA_COUNT is the amount of data to be provided.  Only whole
     virtual pages of data can be accepted; partial pages will be
     discarded.

     LOCK_VALUE is a protection value indicating those forms of access
     that should *not* be permitted to the specified cached data.  The
     lock values must be one or more of the set: `VM_PROT_NONE',
     `VM_PROT_READ', `VM_PROT_WRITE', `VM_PROT_EXECUTE' and
     `VM_PROT_ALL' as defined in `mach/vm_prot.h'.

     If PRECIOUS is `FALSE', the kernel treats the data as a temporary
     and may throw it away if it hasn't been changed.  If the PRECIOUS
     value is `TRUE', the kernel treats its copy as a data repository
     and promises to return it to the manager; the manager may tell the
     kernel to throw it away instead by flushing and not cleaning the
     data (see `memory_object_lock_request').

     If REPLY_TO is not `MACH_PORT_NULL', the kernel will send a
     completion message to the provided port (see
     `memory_object_supply_completed').

     This routine does not receive a reply message (and consequently
     has no return value), so only message transmission errors apply.

 -- Function: kern_return_t memory_object_supply_completed
          (memory_object_t MEMORY_OBJECT,
          memory_object_control_t MEMORY_CONTROL, vm_offset_t OFFSET,
          vm_size_t LENGTH, kern_return_t RESULT,
          vm_offset_t ERROR_OFFSET)
 -- Function: kern_return_t seqnos_memory_object_supply_completed
          (memory_object_t MEMORY_OBJECT, mach_port_seqno_t SEQNO,
          memory_object_control_t MEMORY_CONTROL, vm_offset_t OFFSET,
          vm_size_t LENGTH, kern_return_t RESULT,
          vm_offset_t ERROR_OFFSET)
     The function `memory_object_supply_completed' indicates that a
     previous `memory_object_data_supply' has been completed.  Note that
     this call is made on whatever port was specified in the
     `memory_object_data_supply' call; that port need not be the memory
     object port itself.  No reply is expected after this call.

     The argument MEMORY_OBJECT is the port that represents the memory
     object data, as supplied to the kernel in a `vm_map' call.
     MEMORY_CONTROL is the request port to which a response is
     requested.  (In the event that a memory object has been supplied
     to more than one the kernel that has made the request.)  OFFSET is
     the offset within a memory object to which this call refers.
     LENGTH is the length of the data covered by the lock request.  The
     RESULT parameter indicates what happened during the supply.  If it
     is not `KERN_SUCCESS', then ERROR_OFFSET identifies the first
     offset at which a problem occurred.  The pagein operation stopped
     at this point.  Note that the only failures reported by this
     mechanism are `KERN_MEMORY_PRESENT'.  All other failures (invalid
     argument, error on pagein of supplied data in manager's address
     space) cause the entire operation to fail.


 -- Function: kern_return_t memory_object_data_error
          (memory_object_control_t MEMORY_CONTROL, vm_offset_t OFFSET,
          vm_size_t SIZE, kern_return_t REASON)
     The function `memory_object_data_error' indicates that the memory
     manager cannot return the data requested for the given region,
     specifying a reason for the error.  This is typically used when a
     hardware error is encountered.

     The argument MEMORY_CONTROL is the port, provided by the kernel in
     a `memory_object_init' call, to which cache management requests may
     be issued.  OFFSET is an offset within a memory object in bytes.
     This must be page aligned.  DATA is the data that is being
     provided to the kernel.  This is a pointer to the data.  SIZE is
     the amount of cached data (starting at OFFSET) to be handled.
     This must be an integral number of the memory object page size.
     REASON is an error code indicating what type of error occured.

     This routine does not receive a reply message (and consequently
     has no return value), so only message transmission errors apply.

 -- Function: kern_return_t memory_object_data_unavailable
          (memory_object_control_t MEMORY_CONTROL, vm_offset_t OFFSET,
          vm_size_t SIZE, kern_return_t REASON)
     The function `memory_object_data_unavailable' indicates that the
     memory object does not have data for the given region and that the
     kernel should provide the data for this range.  The memory manager
     may use this call in three different situations.

       1. The object was created by `memory_object_create' and the
          kernel has not yet provided data for this range (either via a
          `memory_object_data_initialize', `memory_object_data_write' or
          a `memory_object_data_return' for the object.

       2. The object was created by an `memory_object_data_copy' and the
          kernel should copy this region from the original memory
          object.

       3. The object is a normal user-created memory object and the
          kernel should supply unlocked zero-filled pages for the range.

     The argument MEMORY_CONTROL is the port, provided by the kernel in
     a `memory_object_init' call, to which cache management requests may
     be issued.  OFFSET is an offset within a memory object, in bytes.
     This must be page aligned.  SIZE is the amount of cached data
     (starting at OFFSET) to be handled.  This must be an integral
     number of the memory object page size.

     This routine does not receive a reply message (and consequently
     has no return value), so only message transmission errors apply.

 -- Function: kern_return_t memory_object_copy
          (memory_object_t OLD_MEMORY_OBJECT,
          memory_object_control_t OLD_MEMORY_CONTROL,
          vm_offset_t OFFSET, vm_size_t LENGTH,
          memory_object_t NEW_MEMORY_OBJECT)
 -- Function: kern_return_t seqnos_memory_object_copy
          (memory_object_t OLD_MEMORY_OBJECT, mach_port_seqno_t SEQNO,
          memory_object_control_t OLD_MEMORY_CONTROL,
          vm_offset_t OFFSET, vm_size_t LENGTH,
          memory_object_t NEW_MEMORY_OBJECT)
     The function `memory_object_copy' indicates that a copy has been
     made of the specified range of the given original memory object.
     This call includes only the new memory object itself; a
     `memory_object_init' call will be made on the new memory object
     after the currently cached pages of the original object are
     prepared.  After the memory manager receives the init call, it
     must reply with the `memory_object_ready' call to assert the
     "ready" attribute.  The kernel will use the new memory object,
     control and name ports to refer to the new copy.

     This call is made when the original memory object had the caching
     parameter set to `MEMORY_OBJECT_COPY_CALL' and a user of the object
     has asked the kernel to copy it.

     Cached pages from the original memory object at the time of the
     copy operation are handled as follows: Readable pages may be
     silently copied to the new memory object (with all access
     permissions).  Pages not copied are locked to prevent write access.

     The new memory object is *temporary*, meaning that the memory
     manager should not change its contents or allow the memory object
     to be mapped in another client.  The memory manager may use the
     `memory_object_data_unavailable' call to indicate that the
     appropriate pages of the original memory object may be used to
     fulfill the data request.

     The argument OLD_MEMORY_OBJECT is the port that represents the old
     memory object data.  OLD_MEMORY_CONTROL is the kernel port for the
     old object.  OFFSET is the offset within a memory object to which
     this call refers.  This will be page aligned.  LENGTH is the
     number of bytes of data, starting at OFFSET, to which this call
     refers.  This will be an integral number of memory object pages.
     NEW_MEMORY_OBJECT is a new memory object created by the kernel;
     see synopsis for further description.  Note that all port rights
     (including receive rights) are included for the new memory object.

     The function should return `KERN_SUCCESS', but since this routine
     is called by the kernel, which does not wait for a reply message,
     this value is ignored.

   The remaining interfaces in this section are obsolet.

 -- Function: kern_return_t memory_object_data_write
          (memory_object_t MEMORY_OBJECT,
          memory_object_control_t MEMORY_CONTROL, vm_offset_t OFFSET,
          vm_offset_t DATA, vm_size_t DATA_COUNT)
 -- Function: kern_return_t seqnos_memory_object_data_write
          (memory_object_t MEMORY_OBJECT, mach_port_seqno_t SEQNO,
          memory_object_control_t MEMORY_CONTROL, vm_offset_t OFFSET,
          vm_offset_t DATA, vm_size_t DATA_COUNT)
     The function `memory_object_data_write' provides the memory manager
     with data that has been modified while cached in physical memory.
     It is the old form of `memory_object_data_return'.  Once the
     memory manager no longer needs this data (e.g., it has been written
     to another storage medium), it should be deallocated using
     `vm_deallocate'.

     The argument MEMORY_OBJECT is the port that represents the memory
     object data, as supplied to the kernel in a `vm_map' call.
     MEMORY_CONTROL is the request port to which a response is
     requested.  (In the event that a memory object has been supplied
     to more than one the kernel that has made the request.)  OFFSET is
     the offset within a memory object to which this call refers.  This
     will be page aligned.  DATA is the data which has been modified
     while cached in physical memory.  DATA_COUNT is the amount of data
     to be written, in bytes.  This will be an integral number of
     memory object pages.

     The function should return `KERN_SUCCESS', but since this routine
     is called by the kernel, which does not wait for a reply message,
     this value is ignored.

 -- Function: kern_return_t memory_object_data_provided
          (memory_object_control_t MEMORY_CONTROL, vm_offset_t OFFSET,
          vm_offset_t DATA, vm_size_t DATA_COUNT, vm_prot_t LOCK_VALUE)
     The function `memory_object_data_provided' supplies the kernel with
     data for the specified memory object.  It is the old form of
     `memory_object_data_supply'.  Ordinarily, memory managers should
     only provide data in reponse to `memory_object_data_request' calls
     from the kernel.  The LOCK_VALUE specifies what type of access
     will not be allowed to the data range.  The lock values must be
     one or more of the set: `VM_PROT_NONE', `VM_PROT_READ',
     `VM_PROT_WRITE', `VM_PROT_EXECUTE' and `VM_PROT_ALL' as defined in
     `mach/vm_prot.h'.

     The argument MEMORY_CONTROL is the port, provided by the kernel in
     a `memory_object_init' call, to which cache management requests may
     be issued.  OFFSET is an offset within a memory object in bytes.
     This must be page aligned.  DATA is the data that is being
     provided to the kernel.  This is a pointer to the data.
     DATA_COUNT is the amount of data to be provided.  This must be an
     integral number of memory object pages.  LOCK_VALUE is a
     protection value indicating those forms of access that should
     *not* be permitted to the specified cached data.

     This routine does not receive a reply message (and consequently
     has no return value), so only message transmission errors apply.


File: mach.info,  Node: Memory Object Locking,  Next: Memory Object Attributes,  Prev: Memory Objects and Data,  Up: External Memory Management

6.5 Memory Object Locking
=========================

 -- Function: kern_return_t memory_object_lock_request
          (memory_object_control_t MEMORY_CONTROL, vm_offset_t OFFSET,
          vm_size_t SIZE, memory_object_return_t SHOULD_CLEAN,
          boolean_t SHOULD_FLUSH, vm_prot_t LOCK_VALUE,
          mach_port_t REPLY_TO)
     The function `memory_object_lock_request' allows a memory manager
     to make cache management requests.  As specified in arguments to
     the call, the kernel will:
        * clean (i.e., write back using `memory_object_data_supply' or
          `memory_object_data_write') any cached data which has been
          modified since the last time it was written

        * flush (i.e., remove any uses of) that data from memory

        * lock (i.e., prohibit the specified uses of) the cached data

     Locks applied to cached data are not cumulative; new lock values
     override previous ones.  Thus, data may also be unlocked using this
     primitive.  The lock values must be one or more of the following
     values: `VM_PROT_NONE', `VM_PROT_READ', `VM_PROT_WRITE',
     `VM_PROT_EXECUTE' and `VM_PROT_ALL' as defined in `mach/vm_prot.h'.

     Only data which is cached at the time of this call is affected.
     When a running thread requires a prohibited access to cached data,
     the kernel will issue a `memory_object_data_unlock' call
     specifying the forms of access required.

     Once all of the actions requested by this call have been
     completed, the kernel issues a `memory_object_lock_completed' call
     on the specified reply port.

     The argument MEMORY_CONTROL is the port, provided by the kernel in
     a `memory_object_init' call, to which cache management requests may
     be issued.  OFFSET is an offset within a memory object, in bytes.
     This must be page aligned.  SIZE is the amount of cached data
     (starting at OFFSET) to be handled.  This must be an integral
     number of the memory object page size.  If SHOULD_CLEAN is set,
     modified data should be written back to the memory manager.  If
     SHOULD_FLUSH is set, the specified cached data should be
     invalidated, and all uses of that data should be revoked.
     LOCK_VALUE is a protection value indicating those forms of access
     that should *not* be permitted to the specified cached data.
     REPLY_TO is a port on which a `memory_object_lock_comleted' call
     should be issued, or `MACH_PORT_NULL' if no acknowledgement is
     desired.

     This routine does not receive a reply message (and consequently
     has no return value), so only message transmission errors apply.

 -- Function: kern_return_t memory_object_lock_completed
          (memory_object_t MEMORY_OBJECT,
          memory_object_control_t MEMORY_CONTROL, vm_offset_t OFFSET,
          vm_size_t LENGTH)
 -- Function: kern_return_t seqnos_memory_object_lock_completed
          (memory_object_t MEMORY_OBJECT, mach_port_seqno_t SEQNO,
          memory_object_control_t MEMORY_CONTROL, vm_offset_t OFFSET,
          vm_size_t LENGTH)
     The function `memory_object_lock_completed' indicates that a
     previous `memory_object_lock_request' has been completed.  Note
     that this call is made on whatever port was specified in the
     `memory_object_lock_request' call; that port need not be the memory
     object port itself.  No reply is expected after this call.

     The argument MEMORY_OBJECT is the port that represents the memory
     object data, as supplied to the kernel in a `vm_map' call.
     MEMORY_CONTROL is the request port to which a response is
     requested.  (In the event that a memory object has been supplied
     to more than one the kernel that has made the request.)  OFFSET is
     the offset within a memory object to which this call refers.
     LENGTH is the length of the data covered by the lock request.

     The function should return `KERN_SUCCESS', but since this routine
     is called by the kernel, which does not wait for a reply message,
     this value is ignored.

 -- Function: kern_return_t memory_object_data_unlock
          (memory_object_t MEMORY_OBJECT,
          memory_object_control_t MEMORY_CONTROL, vm_offset_t OFFSET,
          vm_size_t LENGTH, vm_prot_t DESIRED_ACCESS)
 -- Function: kern_return_t seqnos_memory_object_data_unlock
          (memory_object_t MEMORY_OBJECT, mach_port_seqno_t SEQNO,
          memory_object_control_t MEMORY_CONTROL, vm_offset_t OFFSET,
          vm_size_t LENGTH, vm_prot_t DESIRED_ACCESS)
     The function `memory_object_data_unlock' is a request that the
     memory manager permit at least the desired access to the specified
     data cached by the kernel.  A call to `memory_object_lock_request'
     is expected in response.

     The argument MEMORY_OBJECT is the port that represents the memory
     object data, as supplied to the kernel in a `vm_map' call.
     MEMORY_CONTROL is the request port to which a response is
     requested.  (In the event that a memory object has been supplied
     to more than one the kernel that has made the request.)  OFFSET is
     the offset within a memory object to which this call refers.  This
     will be page aligned.  LENGTH is the number of bytes of data,
     starting at OFFSET, to which this call refers.  This will be an
     integral number of memory object pages.  DESIRED_ACCESS a
     protection value describing the memory access modes which must be
     permitted on the specified cached data.  One or more of:
     `VM_PROT_READ', `VM_PROT_WRITE' or `VM_PROT_EXECUTE'.

     The function should return `KERN_SUCCESS', but since this routine
     is called by the kernel, which does not wait for a reply message,
     this value is ignored.


File: mach.info,  Node: Memory Object Attributes,  Next: Default Memory Manager,  Prev: Memory Object Locking,  Up: External Memory Management

6.6 Memory Object Attributes
============================

 -- Function: kern_return_t memory_object_get_attributes
          (memory_object_control_t MEMORY_CONTROL,
          boolean_t *OBJECT_READY, boolean_t *MAY_CACHE_OBJECT,
          memory_object_copy_strategy_t *COPY_STRATEGY)
     The function `memory_object_get_attribute' retrieves the current
     attributes associated with the memory object.

     The argument MEMORY_CONTROL is the port, provided by the kernel in
     a `memory_object_init' call, to which cache management requests may
     be issued.  If OBJECT_READY is set, the kernel may issue new data
     and unlock requests on the associated memory object.  If
     MAY_CACHE_OBJECT is set, the kernel may keep data associated with
     this memory object, even after virtual memory references to it are
     gone.  COPY_STRATEGY tells how the kernel should copy regions of
     the associated memory object.

     This routine does not receive a reply message (and consequently
     has no return value), so only message transmission errors apply.

 -- Function: kern_return_t memory_object_change_attributes
          (memory_object_control_t MEMORY_CONTROL,
          boolean_t MAY_CACHE_OBJECT,
          memory_object_copy_strategy_t COPY_STRATEGY,
          mach_port_t REPLY_TO)
     The function `memory_object_change_attribute' sets
     performance-related attributes for the specified memory object.
     If the caching attribute is asserted, the kernel is permitted (and
     encouraged) to maintain cached data for this memory object even
     after no virtual address space contains this data.

     There are three possible caching strategies:
     `MEMORY_OBJECT_COPY_NONE' which specifies that nothing special
     should be done when data in the object is copied;
     `MEMORY_OBJECT_COPY_CALL' which specifies that the memory manager
     should be notified via a `memory_object_copy' call before any part
     of the object is copied; and `MEMORY_OBJECT_COPY_DELAY' which
     guarantees that the memory manager does not externally modify the
     data so that the kernel can use its normal copy-on-write
     algorithms.  `MEMORY_OBJECT_COPY_DELAY' is the strategy most
     commonly used.

     The argument MEMORY_CONTROL is the port, provided by the kernel in
     a `memory_object_init' call, to which cache management requests may
     be issued.  If MAY_CACHE_OBJECT is set, the kernel may keep data
     associated with this memory object, even after virtual memory
     references to it are gone.  COPY_STRATEGY tells how the kernel
     should copy regions of the associated memory object.  REPLY_TO is
     a port on which a `memory_object_change_comleted' call will be
     issued upon completion of the attribute change, or
     `MACH_PORT_NULL' if no acknowledgement is desired.

     This routine does not receive a reply message (and consequently
     has no return value), so only message transmission errors apply.

 -- Function: kern_return_t memory_object_change_completed
          (memory_object_t MEMORY_OBJECT, boolean_t MAY_CACHE_OBJECT,
          memory_object_copy_strategy_t COPY_STRATEGY)
 -- Function: kern_return_t seqnos_memory_object_change_completed
          (memory_object_t MEMORY_OBJECT, mach_port_seqno_t SEQNO,
          boolean_t MAY_CACHE_OBJECT,
          memory_object_copy_strategy_t COPY_STRATEGY)
     The function `memory_object_change_completed' indicates the
     completion of an attribute change call.


   The following interface is obsoleted by `memory_object_ready' and
`memory_object_change_attributes'.  If the old form
`memory_object_set_attributes' is used to make a memory object ready,
the kernel will write back data using the old
`memory_object_data_write' interface rather than
`memory_object_data_return'..

 -- Function: kern_return_t memory_object_set_attributes
          (memory_object_control_t MEMORY_CONTROL,
          boolean OBJECT_READY, boolean_t MAY_CACHE_OBJECT,
          memory_object_copy_strategy_t COPY_STRATEGY)
     The function `memory_object_set_attribute' controls how the the
     memory object.  The kernel will only make data or unlock requests
     when the ready attribute is asserted.  If the caching attribute is
     asserted, the kernel is permitted (and encouraged) to maintain
     cached data for this memory object even after no virtual address
     space contains this data.

     There are three possible caching strategies:
     `MEMORY_OBJECT_COPY_NONE' which specifies that nothing special
     should be done when data in the object is copied;
     `MEMORY_OBJECT_COPY_CALL' which specifies that the memory manager
     should be notified via a `memory_object_copy' call before any part
     of the object is copied; and `MEMORY_OBJECT_COPY_DELAY' which
     guarantees that the memory manager does not externally modify the
     data so that the kernel can use its normal copy-on-write
     algorithms.  `MEMORY_OBJECT_COPY_DELAY' is the strategy most
     commonly used.

     The argument MEMORY_CONTROL is the port, provided by the kernel in
     a `memory_object_init' call, to which cache management requests may
     be issued.  If OBJECT_READY is set, the kernel may issue new data
     and unlock requests on the associated memory object.  If
     MAY_CACHE_OBJECT is set, the kernel may keep data associated with
     this memory object, even after virtual memory references to it are
     gone.  COPY_STRATEGY tells how the kernel should copy regions of
     the associated memory object.

     This routine does not receive a reply message (and consequently
     has no return value), so only message transmission errors apply.


File: mach.info,  Node: Default Memory Manager,  Prev: Memory Object Attributes,  Up: External Memory Management

6.7 Default Memory Manager
==========================

 -- Function: kern_return_t vm_set_default_memory_manager (host_t HOST,
          mach_port_t *DEFAULT_MANAGER)
     The function `vm_set_default_memory_manager' sets the kernel's
     default memory manager.  It sets the port to which newly-created
     temporary memory objects are delivered by `memory_object_create' to
     the host.  The old memory manager port is returned.  If
     DEFAULT_MANAGER is `MACH_PORT_NULL' then this routine just returns
     the current default manager port without changing it.

     The argument HOST is a task port to the kernel whose default
     memory manager is to be changed.  DEFAULT_MANAGER is an in/out
     parameter. As input, DEFAULT_MANAGER is the port that the new
     memory manager is listening on for `memory_object_create' calls.
     As output, it is the old default memory manager's port.

     The function returns `KERN_SUCCESS' if the new memory manager is
     installed, and `KERN_INVALID_ARGUMENT' if this task does not have
     the privileges required for this call.

 -- Function: kern_return_t memory_object_create
          (memory_object_t OLD_MEMORY_OBJECT,
          memory_object_t NEW_MEMORY_OBJECT, vm_size_t NEW_OBJECT_SIZE,
          memory_object_control_t NEW_CONTROL,
          memory_object_name_t NEW_NAME, vm_size_t NEW_PAGE_SIZE)
 -- Function: kern_return_t seqnos_memory_object_create
          (memory_object_t OLD_MEMORY_OBJECT, mach_port_seqno_t SEQNO,
          memory_object_t NEW_MEMORY_OBJECT, vm_size_t NEW_OBJECT_SIZE,
          memory_object_control_t NEW_CONTROL,
          memory_object_name_t NEW_NAME, vm_size_t NEW_PAGE_SIZE)
     The function `memory_object_create' is a request that the given
     memory manager accept responsibility for the given memory object
     created by the kernel.  This call will only be made to the system
     *default memory manager*.  The memory object in question initially
     consists of zero-filled memory; only memory pages that are
     actually written will ever be provided to
     `memory_object_data_request' calls, the default memory manager must
     use `memory_object_data_unavailable' for any pages that have not
     previously been written.

     No reply is expected after this call.  Since this call is directed
     to the default memory manager, the kernel assumes that it will be
     ready to handle data requests to this object and does not need the
     confirmation of a `memory_object_set_attributes' call.

     The argument OLD_MEMORY_OBJECT is a memory object provided by the
     default memory manager on which the kernel can make
     `memory_object_create' calls.  NEW_MEMORY_OBJECT is a new memory
     object created by the kernel; see synopsis for further
     description.  Note that all port rights (including receive rights)
     are included for the new memory object.  NEW_OBJECT_SIZE is the
     maximum size of the new object.  NEW_CONTROL is a port, created by
     the kernel, on which a memory manager may issue cache management
     requests for the new object.  NEW_NAME a port used by the kernel
     to refer to the new memory object data in response to `vm_region'
     calls.  NEW_PAGE_SIZE is the page size to be used by this kernel.
     All data sizes in calls involving this kernel must be an integral
     multiple of the page size.  Note that different kernels, indicated
     by different a `memory_control', may have different page sizes.

     The function should return `KERN_SUCCESS', but since this routine
     is called by the kernel, which does not wait for a reply message,
     this value is ignored.

 -- Function: kern_return_t memory_object_data_initialize
          (memory_object_t MEMORY_OBJECT,
          memory_object_control_t MEMORY_CONTROL, vm_offset_t OFFSET,
          vm_offset_t DATA, vm_size_t DATA_COUNT)
 -- Function: kern_return_t seqnos_memory_object_data_initialize
          (memory_object_t MEMORY_OBJECT, mach_port_seqno_t SEQNO,
          memory_object_control_t MEMORY_CONTROL, vm_offset_t OFFSET,
          vm_offset_t DATA, vm_size_t DATA_COUNT)
     The function `memory_object_data_initialize' provides the memory
     manager with initial data for a kernel-created memory object.  If
     the memory manager already has been supplied data (by a previous
     `memory_object_data_initialize', `memory_object_data_write' or
     `memory_object_data_return'), then this data should be ignored.
     Otherwise, this call behaves exactly as does
     `memory_object_data_return' on memory objects created by the kernel
     via `memory_object_create' and thus will only be made to default
     memory managers.  This call will not be made on objects created via
     `memory_object_copy'.

     The argument MEMORY_OBJECT the port that represents the memory
     object data, as supplied by the kernel in a `memory_object_create'
     call.  MEMORY_CONTROL is the request port to which a response is
     requested.  (In the event that a memory object has been supplied
     to more than one the kernel that has made the request.)  OFFSET is
     the offset within a memory object to which this call refers.  This
     will be page aligned.  DATA os the data which has been modified
     while cached in physical memory.  DATA_COUNT is the amount of data
     to be written, in bytes.  This will be an integral number of
     memory object pages.

     The function should return `KERN_SUCCESS', but since this routine
     is called by the kernel, which does not wait for a reply message,
     this value is ignored.


File: mach.info,  Node: Threads and Tasks,  Next: Host Interface,  Prev: External Memory Management,  Up: Top

7 Threads and Tasks
*******************

* Menu:

* Thread Interface::              Manipulating threads.
* Task Interface::                Manipulating tasks.
* Profiling::                     Profiling threads and tasks.


File: mach.info,  Node: Thread Interface,  Next: Task Interface,  Up: Threads and Tasks

7.1 Thread Interface
====================

 -- Data type: thread_t
     This is a `mach_port_t' and used to hold the port name of a thread
     port that represents the thread.  Manipulations of the thread are
     implemented as remote procedure calls to the thread port.  A
     thread can get a port to itself with the `mach_thread_self' system
     call.

* Menu:

* Thread Creation::               Creating new threads.
* Thread Termination::            Terminating existing threads.
* Thread Information::            How to get informations on threads.
* Thread Settings::               How to set threads related informations.
* Thread Execution::              How to control the thread's machine state.
* Scheduling::                    Operations on thread scheduling.
* Thread Special Ports::          How to handle the thread's special ports.
* Exceptions::                    Managing exceptions.


File: mach.info,  Node: Thread Creation,  Next: Thread Termination,  Up: Thread Interface

7.1.1 Thread Creation
---------------------

 -- Function: kern_return_t thread_create (task_t PARENT_TASK,
          thread_t *CHILD_THREAD)
     The function `thread_create' creates a new thread within the task
     specified by PARENT_TASK.  The new thread has no processor state,
     and has a suspend count of 1.  To get a new thread to run, first
     `thread_create' is called to get the new thread's identifier,
     (CHILD_THREAD).  Then `thread_set_state' is called to set a
     processor state, and finally `thread_resume' is called to get the
     thread scheduled to execute.

     When the thread is created send rights to its thread kernel port
     are given to it and returned to the caller in CHILD_THREAD.  The
     new thread's exception port is set to `MACH_PORT_NULL'.

     The function returns `KERN_SUCCESS' if a new thread has been
     created, `KERN_INVALID_ARGUMENT' if PARENT_TASK is not a valid
     task and `KERN_RESOURCE_SHORTAGE' if some critical kernel resource
     is not available.


File: mach.info,  Node: Thread Termination,  Next: Thread Information,  Prev: Thread Creation,  Up: Thread Interface

7.1.2 Thread Termination
------------------------

 -- Function: kern_return_t thread_terminate (thread_t TARGET_THREAD)
     The function `thread_terminate' destroys the thread specified by
     TARGET_THREAD.

     The function returns `KERN_SUCCESS' if the thread has been killed
     and `KERN_INVALID_ARGUMENT' if TARGET_THREAD is not a thread.


File: mach.info,  Node: Thread Information,  Next: Thread Settings,  Prev: Thread Termination,  Up: Thread Interface

7.1.3 Thread Information
------------------------

 -- Function: thread_t mach_thread_self ()
     The `mach_thread_self' system call returns the calling thread's
     thread port.

     `mach_thread_self' has an effect equivalent to receiving a send
     right for the thread port.  `mach_thread_self' returns the name of
     the send right.  In particular, successive calls will increase the
     calling task's user-reference count for the send right.

     As a special exception, the kernel will overrun the user reference
     count of the thread name port, so that this function can not fail
     for that reason.  Because of this, the user should not deallocate
     the port right if an overrun might have happened.  Otherwise the
     reference count could drop to zero and the send right be destroyed
     while the user still expects to be able to use it.  As the kernel
     does not make use of the number of extant send rights anyway, this
     is safe to do (the thread port itself is not destroyed, even when
     there are no send rights anymore).

     The function returns `MACH_PORT_NULL' if a resource shortage
     prevented the reception of the send right or if the thread port is
     currently null and `MACH_PORT_DEAD' if the thread port is currently
     dead.

 -- Function: kern_return_t thread_info (thread_t TARGET_THREAD,
          int FLAVOR, thread_info_t THREAD_INFO,
          mach_msg_type_number_t *THREAD_INFOCNT)
     The function `thread_info' returns the selected information array
     for a thread, as specified by FLAVOR.

     THREAD_INFO is an array of integers that is supplied by the caller
     and returned filled with specified information.  THREAD_INFOCNT is
     supplied as the maximum number of integers in THREAD_INFO.  On
     return, it contains the actual number of integers in THREAD_INFO.
     The maximum number of integers returned by any flavor is
     `THREAD_INFO_MAX'.

     The type of information returned is defined by FLAVOR, which can
     be one of the following:

    `THREAD_BASIC_INFO'
          The function returns basic information about the thread, as
          defined by `thread_basic_info_t'.  This includes the user and
          system time, the run state, and scheduling priority.  The
          number of integers returned is `THREAD_BASIC_INFO_COUNT'.

    `THREAD_SCHED_INFO'
          The function returns information about the schduling policy
          for the thread as defined by `thread_sched_info_t'.  The
          number of integers returned is `THREAD_SCHED_INFO_COUNT'.

     The function returns `KERN_SUCCESS' if the call succeeded and
     `KERN_INVALID_ARGUMENT' if TARGET_THREAD is not a thread or FLAVOR
     is not recognized.  The function returns `MIG_ARRAY_TOO_LARGE' if
     the returned info array is too large for THREAD_INFO.  In this
     case, THREAD_INFO is filled as much as possible and THREAD_INFOCNT
     is set to the number of elements that would have been returned if
     there were enough room.

 -- Data type: struct thread_basic_info
     This structure is returned in THREAD_INFO by the `thread_info'
     function and provides basic information about the thread.  You can
     cast a variable of type `thread_info_t' to a pointer of this type
     if you provided it as the THREAD_INFO parameter for the
     `THREAD_BASIC_INFO' flavor of `thread_info'.  It has the following
     members:

    `time_value_t user_time'
          user run time

    `time_value_t system_time'
          system run time

    `int cpu_usage'
          Scaled cpu usage percentage.  The scale factor is
          `TH_USAGE_SCALE'.

    `int base_priority'
          The base scheduling priority of the thread.

    `int cur_priority'
          The current scheduling priority of the thread.

    `integer_t run_state'
          The run state of the thread.  The possible vlues of this
          field are:
         `TH_STATE_RUNNING'
               The thread is running normally.

         `TH_STATE_STOPPED'
               The thread is suspended.

         `TH_STATE_WAITING'
               The thread is waiting normally.

         `TH_STATE_UNINTERRUPTIBLE'
               The thread is in an uninterruptible wait.

         `TH_STATE_HALTED'
               The thread is halted at a clean point.

    `flags'
          Various flags.  The possible values of this field are:
         `TH_FLAGS_SWAPPED'
               The thread is swapped out.

         `TH_FLAGS_IDLE'
               The thread is an idle thread.

    `int suspend_count'
          The suspend count for the thread.

    `int sleep_time'
          The number of seconds that the thread has been sleeping.

    `time_value_t creation_time'
          The time stamp of creation.

 -- Data type: thread_basic_info_t
     This is a pointer to a `struct thread_basic_info'.

 -- Data type: struct thread_sched_info
     This structure is returned in THREAD_INFO by the `thread_info'
     function and provides schedule information about the thread.  You
     can cast a variable of type `thread_info_t' to a pointer of this
     type if you provided it as the THREAD_INFO parameter for the
     `THREAD_SCHED_INFO' flavor of `thread_info'.  It has the following
     members:

    `int policy'
          The scheduling policy of the thread, *Note Scheduling
          Policy::.

    `integer_t data'
          Policy-dependent scheduling information, *Note Scheduling
          Policy::.

    `int base_priority'
          The base scheduling priority of the thread.

    `int max_priority'
          The maximum scheduling priority of the thread.

    `int cur_priority'
          The current scheduling priority of the thread.

    `int depressed'
          `TRUE' if the thread is depressed.

    `int depress_priority'
          The priority the thread was depressed from.

 -- Data type: thread_sched_info_t
     This is a pointer to a `struct thread_sched_info'.


File: mach.info,  Node: Thread Settings,  Next: Thread Execution,  Prev: Thread Information,  Up: Thread Interface

7.1.4 Thread Settings
---------------------

 -- Function: kern_return_t thread_wire (host_priv_t HOST_PRIV,
          thread_t THREAD, boolean_t WIRED)
     The function `thread_wire' controls the VM privilege level of the
     thread THREAD.  A VM-privileged thread never waits inside the
     kernel for memory allocation from the kernel's free list of pages
     or for allocation of a kernel stack.

     Threads that are part of the default pageout path should be
     VM-privileged, to prevent system deadlocks.  Threads that are not
     part of the default pageout path should not be VM-privileged, to
     prevent the kernel's free list of pages from being exhausted.

     The functions returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_ARGUMENT' if HOST_PRIV or THREAD was invalid.

     The `thread_wire' call is actually an RPC to HOST_PRIV, normally a
     send right for a privileged host port, but potentially any send
     right.  In addition to the normal diagnostic return codes from the
     call's server (normally the kernel), the call may return `mach_msg'
     return codes.


File: mach.info,  Node: Thread Execution,  Next: Scheduling,  Prev: Thread Settings,  Up: Thread Interface

7.1.5 Thread Execution
----------------------

 -- Function: kern_return_t thread_suspend (thread_t TARGET_THREAD)
     Increments the thread's suspend count and prevents the thread from
     executing any more user level instructions.  In this context a user
     level instruction is either a machine instruction executed in user
     mode or a system trap instruction including page faults.  Thus if
     a thread is currently executing within a system trap the kernel
     code may continue to execute until it reaches the system return
     code or it may supend within the kernel code.  In either case,
     when the thread is resumed the system trap will return.  This
     could cause unpredictible results if the user did a suspend and
     then altered the user state of the thread in order to change its
     direction upon a resume.  The call `thread_abort' is provided to
     allow the user to abort any system call that is in progress in a
     predictable way.

     The suspend count may become greater than one with the effect that
     it will take more than one resume call to restart the thread.

     The function returns `KERN_SUCCESS' if the thread has been
     suspended and `KERN_INVALID_ARGUMENT' if TARGET_THREAD is not a
     thread.

 -- Function: kern_return_t thread_resume (thread_t TARGET_THREAD)
     Decrements the threads's suspend count.  If the count becomes zero
     the thread is resumed.  If it is still positive, the thread is left
     suspended.  The suspend count may not become negative.

     The function returns `KERN_SUCCESS' if the thread has been resumed,
     `KERN_FAILURE' if the suspend count is already zero and
     `KERN_INVALID_ARGUMENT' if TARGET_THREAD is not a thread.

 -- Function: kern_return_t thread_abort (thread_t TARGET_THREAD)
     The function `thread_abort' aborts the kernel primitives:
     `mach_msg', `msg_send', `msg_receive' and `msg_rpc' and
     page-faults, making the call return a code indicating that it was
     interrupted.  The call is interrupted whether or not the thread
     (or task containing it) is currently suspended.  If it is
     supsended, the thread receives the interupt when it is resumed.

     A thread will retry an aborted page-fault if its state is not
     modified before it is resumed.  `msg_send' returns
     `SEND_INTERRUPTED'; `msg_receive' returns `RCV_INTERRUPTED';
     `msg_rpc' returns either `SEND_INTERRUPTED' or `RCV_INTERRUPTED',
     depending on which half of the RPC was interrupted.

     The main reason for this primitive is to allow one thread to
     cleanly stop another thread in a manner that will allow the future
     execution of the target thread to be controlled in a predictable
     way.  `thread_suspend' keeps the target thread from executing any
     further instructions at the user level, including the return from
     a system call.  `thread_get_state'/`thread_set_state' allows the
     examination or modification of the user state of a target thread.
     However, if a suspended thread was executing within a system call,
     it also has associated with it a kernel state.  This kernel state
     can not be modified by `thread_set_state' with the result that
     when the thread is resumed the system call may return changing the
     user state and possibly user memory.  `thread_abort' aborts the
     kernel call from the target thread's point of view by resetting
     the kernel state so that the thread will resume execution at the
     system call return with the return code value set to one of the
     interrupted codes.  The system call itself will either be entirely
     completed or entirely aborted, depending on the precise moment at
     which the abort was received.  Thus if the thread's user state has
     been changed by `thread_set_state', it will not be modified by any
     unexpected system call side effects.

     For example to simulate a Unix signal, the following sequence of
     calls may be used:

       1. `thread_suspend': Stops the thread.

       2. `thread_abort': Interrupts any system call in progress,
          setting the return value to `interrupted'.  Since the thread
          is stopped, it will not return to user code.

       3. `thread_set_state': Alters thread's state to simulate a
          procedure call to the signal handler

       4. `thread_resume': Resumes execution at the signal handler.  If
          the thread's stack has been correctly set up, the thread may
          return to the interrupted system call.  (Of course, the code
          to push an extra stack frame and change the registers is VERY
          machine-dependent.)

     Calling `thread_abort' on a non-suspended thread is pretty risky,
     since it is very difficult to know exactly what system trap, if
     any, the thread might be executing and whether an interrupt return
     would cause the thread to do something useful.

     The function returns `KERN_SUCCESS' if the thread received an
     interrupt and `KERN_INVALID_ARGUMENT' if TARGET_THREAD is not a
     thread.

 -- Function: kern_return_t thread_get_state (thread_t TARGET_THREAD,
          int FLAVOR, thread_state_t OLD_STATE,
          mach_msg_type_number_t *OLD_STATECNT)
     The function `thread_get_state' returns the execution state (e.g.
     the machine registers) of TARGET_THREAD as specified by FLAVOR.
     The OLD_STATE is an array of integers that is provided by the
     caller and returned filled with the specified information.
     OLD_STATECNT is input set to the maximum number of integers in
     OLD_STATE and returned equal to the actual number of integers in
     OLD_STATE.

     TARGET_THREAD may not be `mach_thread_self()'.

     The definition of the state structures can be found in
     `machine/thread_status.h'.

     The function returns `KERN_SUCCESS' if the state has been returned,
     `KERN_INVALID_ARGUMENT' if TARGET_THREAD is not a thread or is
     `mach_thread_self' or FLAVOR is unrecogized for this machine.  The
     function returns `MIG_ARRAY_TOO_LARGE' if the returned state is
     too large for OLD_STATE.  In this case, OLD_STATE is filled as
     much as possible and OLD_STATECNT is set to the number of elements
     that would have been returned if there were enough room.

 -- Function: kern_return_t thread_set_state (thread_t TARGET_THREAD,
          int FLAVOR, thread_state_t NEW_STATE,
          mach_msg_type_number_t NEW_STATE_COUNT)
     The function `thread_set_state' sets the execution state (e.g. the
     machine registers) of TARGET_THREAD as specified by FLAVOR.  The
     NEW_STATE is an array of integers.  NEW_STATE_COUNT is the number
     of elements in NEW_STATE.  The entire set of registers is reset.
     This will do unpredictable things if TARGET_THREAD is not
     suspended.

     TARGET_THREAD may not be `mach_thread_self'.

     The definition of the state structures can be found in
     `machine/thread_status.h'.

     The function returns `KERN_SUCCESS' if the state has been set and
     `KERN_INVALID_ARGUMENT' if TARGET_THREAD is not a thread or is
     `mach_thread_self' or FLAVOR is unrecogized for this machine.


File: mach.info,  Node: Scheduling,  Next: Thread Special Ports,  Prev: Thread Execution,  Up: Thread Interface

7.1.6 Scheduling
----------------

* Menu:

* Thread Priority::               Changing the priority of a thread.
* Hand-Off Scheduling::           Switching to a new thread.
* Scheduling Policy::             Setting the scheduling policy.


File: mach.info,  Node: Thread Priority,  Next: Hand-Off Scheduling,  Up: Scheduling

7.1.6.1 Thread Priority
.......................

Threads have three priorities associated with them by the system, a
priority, a maximum priority, and a scheduled priority.  The scheduled
priority is used to make scheduling decisions about the thread.  It is
determined from the priority by the policy (for timesharing, this means
adding an increment derived from cpu usage).  The priority can be set
under user control, but may never exceed the maximum priority.  Changing
the maximum priority requires presentation of the control port for the
thread's processor set; since the control port for the default processor
set is privileged, users cannot raise their maximum priority to unfairly
compete with other users on that set.  Newly created threads obtain
their priority from their task and their max priority from the thread.

 -- Function: kern_return_t thread_priority (thread_t THREAD,
          int PRORITY, boolean_t SET_MAX)
     The function `thread_priority' changes the priority and optionally
     the maximum priority of THREAD.  Priorities range from 0 to 31,
     where lower numbers denote higher priorities.  If the new priority
     is higher than the priority of the current thread, preemption may
     occur as a result of this call.  The maximum priority of the
     thread is also set if SET_MAX is `TRUE'.  This call will fail if
     PRIORITY is greater than the current maximum priority of the
     thread.  As a result, this call can only lower the value of a
     thread's maximum priority.

     The functions returns `KERN_SUCCESS' if the operation completed
     successfully, `KERN_INVALID_ARGUMENT' if THREAD is not a thread or
     PRIORITY is out of range (not in 0..31), and `KERN_FAILURE' if the
     requested operation would violate the thread's maximum priority
     (thread_priority).

 -- Function: kern_return_t thread_max_priority (thread_t THREAD,
          processor_set_t PROCESSOR_SET, int PRIORITY)
     The function `thread_max_priority' changes the maximum priority of
     the thread.  Because it requires presentation of the corresponding
     processor set port, this call can reset the maximum priority to any
     legal value.

     The functions returns `KERN_SUCCESS' if the operation completed
     successfully, `KERN_INVALID_ARGUMENT' if THREAD is not a thread or
     PROCESSOR_SET is not a control port for a processor set or
     PRIORITY is out of range (not in 0..31), and `KERN_FAILURE' if the
     thread is not assigned to the processor set whose control port was
     presented.


File: mach.info,  Node: Hand-Off Scheduling,  Next: Scheduling Policy,  Prev: Thread Priority,  Up: Scheduling

7.1.6.2 Hand-Off Scheduling
...........................

 -- Function: kern_return_t thread_switch (thread_t NEW_THREAD,
          int OPTION, int TIME)
     The function `thread_switch' provides low-level access to the
     scheduler's context switching code.  NEW_THREAD is a hint that
     implements hand-off scheduling.  The operating system will attempt
     to switch directly to the new thread (by passing the normal logic
     that selects the next thread to run) if possible.  Since this is a
     hint, it may be incorrect; it is ignored if it doesn't specify a
     thread on the same host as the current thread or if that thread
     can't be switched to (i.e., not runnable or already running on
     another processor).  In this case, the normal logic to select the
     next thread to run is used; the current thread may continue
     running if there is no other appropriate thread to run.

     Options for OPTION are defined in `mach/thread_switch.h' and
     specify the interpretation of TIME.  The possible values for
     OPTION are:

    `SWITCH_OPTION_NONE'
          No options, the time argument is ignored.

    `SWITCH_OPTION_WAIT'
          The thread is blocked for the specified time.  This can be
          aborted by `thread_abort'.

    `SWITCH_OPTION_DEPRESS'
          The thread's priority is depressed to the lowest possible
          value for the specified time.  This can be aborted by
          `thread_depress_abort'.  This depression is independent of
          operations that change the thread's priority (e.g.
          `thread_priority' will not abort the depression).  The
          minimum time and units of time can be obtained as the
          `min_timeout' value from `host_info'.  The depression is also
          aborted when the current thread is next run (either via
          hand­off scheduling or because the processor set has nothing
          better to do).

     `thread_switch' is often called when the current thread can proceed
     no further for some reason; the various options and arguments allow
     information about this reason to be transmitted to the kernel.  The
     NEW_THREAD argument (handoff scheduling) is useful when the
     identity of the thread that must make progress before the current
     thread runs again is known.  The `WAIT' option is used when the
     amount of time that the current thread must wait before it can do
     anything useful can be estimated and is fairly long.  The
     `DEPRESS' option is used when the amount of time that must be
     waited is fairly short, especially when the identity of the thread
     that is being waited for is not known.

     Users should beware of calling `thread_switch' with an invalid hint
     (e.g. `MACH_PORT_NULL') and no option.  Because the time-sharing
     scheduler varies the priority of threads based on usage, this may
     result in a waste of cpu time if the thread that must be run is of
     lower priority.  The use of the `DEPRESS' option in this situation
     is highly recommended.

     `thread_switch' ignores policies.  Users relying on the preemption
     semantics of a fixed time policy should be aware that
     `thread_switch' ignores these semantics; it will run the specified
     NEW_THREAD indepent of its priority and the priority of any other
     threads that could be run instead.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_ARGUMENT' if THREAD is not a thread or OPTION is not
     a recognized option, and `KERN_FAILURE' if `kern_depress_abort'
     failed because the thread was not depressed.

 -- Function: kern_return_t thread_depress_abort (thread_t THREAD)
     The function `thread_depress_abort' cancels any priority depression
     for THREAD caused by a `swtch_pri' or `thread_switch' call.

     The function returns `KERN_SUCCESS' if the call succeeded and
     `KERN_INVALID_ARGUMENT' if THREAD is not a valid thread.

 -- Function: boolean_t swtch ()
     The system trap `swtch' attempts to switch the current thread off
     the processor.  The return value indicates if more than the current
     thread is running in the processor set.  This is useful for lock
     management routines.

     The call returns `FALSE' if the thread is justified in becoming a
     resource hog by continuing to spin because there's nothing else
     useful that the processor could do.  `TRUE' is returned if the
     thread should make one more check on the lock and then be a good
     citizen and really suspend.

 -- Function: boolean_t swtch_pri (int PRIORITY)
     The system trap `swtch_pri' attempts to switch the current thread
     off the processor as `swtch' does, but depressing the priority of
     the thread to the minimum possible value during the time.
     PRIORITY is not used currently.

     The return value is as for `swtch'.


File: mach.info,  Node: Scheduling Policy,  Prev: Hand-Off Scheduling,  Up: Scheduling

7.1.6.3 Scheduling Policy
.........................

 -- Function: kern_return_t thread_policy (thread_t THREAD, int POLICY,
          int DATA)
     The function `thread_policy' changes the scheduling policy for
     THREAD to POLICY.

     DATA is policy-dependent scheduling information.  There are
     currently two supported policies: `POLICY_TIMESHARE' and
     `POLICY_FIXEDPRI' defined in `mach/policy.h'; this file is
     included by `mach.h'.  DATA is meaningless for timesharing, but is
     the quantum to be used (in milliseconds) for the fixed priority
     policy.  To be meaningful, this quantum must be a multiple of the
     basic system quantum (min_quantum) which can be obtained from
     `host_info'.  The system will always round up to the next multiple
     of the quantum.

     Processor sets may restrict the allowed policies, so this call
     will fail if the processor set to which THREAD is currently
     assigned does not permit POLICY.

     The function returns `KERN_SUCCESS' if the call succeeded.
     `KERN_INVALID_ARGUMENT' if THREAD is not a thread or POLICY is not
     a recognized policy, and `KERN_FAILURE' if the processor set to
     which THREAD is currently assigned does not permit POLICY.


File: mach.info,  Node: Thread Special Ports,  Next: Exceptions,  Prev: Scheduling,  Up: Thread Interface

7.1.7 Thread Special Ports
--------------------------

 -- Function: kern_return_t thread_get_special_port (thread_t THREAD,
          int WHICH_PORT, mach_port_t *SPECIAL_PORT)
     The function `thread_get_special_port' returns send rights to one
     of a set of special ports for the thread specified by THREAD.

     The possible values for WHICH_PORT are `THREAD_KERNEL_PORT' and
     `THREAD_EXCEPTION_PORT'.  A thread also has access to its task's
     special ports.

     The function returns `KERN_SUCCESS' if the port was returned and
     `KERN_INVALID_ARGUMENT' if THREAD is not a thread or WHICH_PORT is
     an invalid port selector.

 -- Function: kern_return_t thread_get_kernel_port (thread_t THREAD,
          mach_port_t *KERNEL_PORT)
     The function `thread_get_kernel_port' is equivalent to the function
     `thread_get_special_port' with the WHICH_PORT argument set to
     `THREAD_KERNEL_PORT'.

 -- Function: kern_return_t thread_get_exception_port (thread_t THREAD,
          mach_port_t *EXCEPTION_PORT)
     The function `thread_get_exception_port' is equivalent to the
     function `thread_get_special_port' with the WHICH_PORT argument
     set to `THREAD_EXCEPTION_PORT'.

 -- Function: kern_return_t thread_set_special_port (thread_t THREAD,
          int WHICH_PORT, mach_port_t SPECIAL_PORT)
     The function `thread_set_special_port' sets one of a set of special
     ports for the thread specified by THREAD.

     The possible values for WHICH_PORT are `THREAD_KERNEL_PORT' and
     `THREAD_EXCEPTION_PORT'.  A thread also has access to its task's
     special ports.

     The function returns `KERN_SUCCESS' if the port was set and
     `KERN_INVALID_ARGUMENT' if THREAD is not a thread or WHICH_PORT is
     an invalid port selector.

 -- Function: kern_return_t thread_set_kernel_port (thread_t THREAD,
          mach_port_t KERNEL_PORT)
     The function `thread_set_kernel_port' is equivalent to the function
     `thread_set_special_port' with the WHICH_PORT argument set to
     `THREAD_KERNEL_PORT'.

 -- Function: kern_return_t thread_set_exception_port (thread_t THREAD,
          mach_port_t EXCEPTION_PORT)
     The function `thread_set_exception_port' is equivalent to the
     function `thread_set_special_port' with the WHICH_PORT argument
     set to `THREAD_EXCEPTION_PORT'.


File: mach.info,  Node: Exceptions,  Prev: Thread Special Ports,  Up: Thread Interface

7.1.8 Exceptions
----------------

 -- Function: kern_return_t catch_exception_raise
          (mach_port_t EXCEPTION_PORT, thread_t THREAD, task_t TASK,
          int EXCEPTION, int CODE, int SUBCODE)
     XXX Fixme

 -- Function: kern_return_t exception_raise
          (mach_port_t EXCEPTION_PORT, mach_port_t THREAD,
          mach_port_t TASK, integer_t EXCEPTION, integer_t CODE,
          integer_t SUBCODE)
     XXX Fixme

 -- Function: kern_return_t evc_wait (unsigned int EVENT)
     The system trap `evc_wait' makes the calling thread wait for the
     event specified by EVENT.

     The call returns `KERN_SUCCESS' if the event has occured,
     `KERN_NO_SPACE' if another thread is waiting for the same event and
     `KERN_INVALID_ARGUMENT' if the event object is invalid.


File: mach.info,  Node: Task Interface,  Next: Profiling,  Prev: Thread Interface,  Up: Threads and Tasks

7.2 Task Interface
==================

 -- Data type: task_t
     This is a `mach_port_t' and used to hold the port name of a task
     port that represents the thread.  Manipulations of the task are
     implemented as remote procedure calls to the task port.  A task
     can get a port to itself with the `mach_task_self' system call.

     The task port name is also used to identify the task's IPC space
     (*note Port Manipulation Interface::) and the task's virtual
     memory map (*note Virtual Memory Interface::).

* Menu:

* Task Creation::                 Creating tasks.
* Task Termination::              Terminating tasks.
* Task Information::              Informations on tasks.
* Task Execution::                Thread scheduling in a task.
* Task Special Ports::            How to get and set the task's special ports.
* Syscall Emulation::             How to emulate system calls.


File: mach.info,  Node: Task Creation,  Next: Task Termination,  Up: Task Interface

7.2.1 Task Creation
-------------------

 -- Function: kern_return_t task_create (task_t PARENT_TASK,
          boolean_t INHERIT_MEMORY, task_t *CHILD_TASK)
     The function `task_create' creates a new task from PARENT_TASK;
     the resulting task (CHILD_TASK) acquires shared or copied parts of
     the parent's address space (see `vm_inherit').  The child task
     initially contains no threads.

     If INHERIT_MEMORY is set, the child task's address space is built
     from the parent task according to its memory inheritance values;
     otherwise, the child task is given an empty address space.

     The child task gets the three special ports created or copied for
     it at task creation.  The `TASK_KERNEL_PORT' is created and send
     rights for it are given to the child and returned to the caller.
     The `TASK_BOOTSTRAP_PORT' and the `TASK_EXCEPTION_PORT' are
     inherited from the parent task.  The new task can get send rights
     to these ports with the call `task_get_special_port'.

     The function returns `KERN_SUCCESS' if a new task has been created,
     `KERN_INVALID_ARGUMENT' if PARENT_TASK is not a valid task port
     and `KERN_RESOURCE_SHORTAGE' if some critical kernel resource is
     unavailable.


File: mach.info,  Node: Task Termination,  Next: Task Information,  Prev: Task Creation,  Up: Task Interface

7.2.2 Task Termination
----------------------

 -- Function: kern_return_t task_terminate (task_t TARGET_TASK)
     The function `task_terminate' destroys the task specified by
     TARGET_TASK and all its threads.  All resources that are used only
     by this task are freed.  Any port to which this task has receive
     and ownership rights is destroyed.

     The function returns `KERN_SUCCESS' if the task has been killed,
     `KERN_INVALID_ARGUMENT' if TARGET_TASK is not a task.


File: mach.info,  Node: Task Information,  Next: Task Execution,  Prev: Task Termination,  Up: Task Interface

7.2.3 Task Information
----------------------

 -- Function: task_t mach_task_self ()
     The `mach_task_self' system call returns the calling thread's task
     port.

     `mach_task_self' has an effect equivalent to receiving a send right
     for the task port.  `mach_task_self' returns the name of the send
     right.  In particular, successive calls will increase the calling
     task's user-reference count for the send right.

     As a special exception, the kernel will overrun the user reference
     count of the task name port, so that this function can not fail
     for that reason.  Because of this, the user should not deallocate
     the port right if an overrun might have happened.  Otherwise the
     reference count could drop to zero and the send right be destroyed
     while the user still expects to be able to use it.  As the kernel
     does not make use of the number of extant send rights anyway, this
     is safe to do (the task port itself is not destroyed, even when
     there are no send rights anymore).

     The funcion returns `MACH_PORT_NULL' if a resource shortage
     prevented the reception of the send right, `MACH_PORT_NULL' if the
     task port is currently null, `MACH_PORT_DEAD' if the task port is
     currently dead.

 -- Function: kern_return_t task_threads (task_t TARGET_TASK,
          thread_array_t *THREAD_LIST,
          mach_msg_type_number_t *THREAD_COUNT)
     The function `task_threads' gets send rights to the kernel port for
     each thread contained in TARGET_TASK.  THREAD_LIST is an array
     that is created as a result of this call.  The caller may wish to
     `vm_deallocate' this array when the data is no longer needed.

     The function returns `KERN_SUCCESS' if the call succeeded and
     `KERN_INVALID_ARGUMENT' if TARGET_TASK is not a task.

 -- Function: kern_return_t task_info (task_t TARGET_TASK, int FLAVOR,
          task_info_t TASK_INFO,
          mach_msg_type_number_t *TASK_INFO_COUNT)
     The function `task_info' returns the selected information array for
     a task, as specified by FLAVOR.  TASK_INFO is an array of integers
     that is supplied by the caller, and filled with specified
     information.  TASK_INFO_COUNT is supplied as the maximum number of
     integers in TASK_INFO.  On return, it contains the actual number
     of integers in TASK_INFO.  The maximum number of integers returned
     by any flavor is `TASK_INFO_MAX'.

     The type of information returned is defined by FLAVOR, which can
     be one of the following:

    `TASK_BASIC_INFO'
          The function returns basic information about the task, as
          defined by `task_basic_info_t'.  This includes the user and
          system time and memory consumption.  The number of integers
          returned is `TASK_BASIC_INFO_COUNT'.

    `TASK_EVENTS_INFO'
          The function returns information about events for the task as
          defined by `thread_sched_info_t'.  This includes statistics
          about virtual memory and IPC events like pageouts, pageins
          and messages sent and received.  The number of integers
          returned is `TASK_EVENTS_INFO_COUNT'.

    `TASK_THREAD_TIMES_INFO'
          The function returns information about the total time for
          live threads as defined by `task_thread_times_info_t'.  The
          number of integers returned is `TASK_THREAD_TIMES_INFO_COUNT'.

     The function returns `KERN_SUCCESS' if the call succeeded and
     `KERN_INVALID_ARGUMENT' if TARGET_TASK is not a thread or FLAVOR
     is not recognized.  The function returns `MIG_ARRAY_TOO_LARGE' if
     the returned info array is too large for TASK_INFO.  In this case,
     TASK_INFO is filled as much as possible and TASK_INFOCNT is set to
     the number of elements that would have been returned if there were
     enough room.

 -- Data type: struct task_basic_info
     This structure is returned in TASK_INFO by the `task_info'
     function and provides basic information about the task.  You can
     cast a variable of type `task_info_t' to a pointer of this type if
     you provided it as the TASK_INFO parameter for the
     `TASK_BASIC_INFO' flavor of `task_info'.  It has the following
     members:

    `integer_t suspend_count'
          suspend count for task

    `integer_t base_priority'
          base scheduling priority

    `vm_size_t virtual_size'
          number of virtual pages

    `vm_size_t resident_size'
          number of resident pages

    `time_value_t user_time'
          total user run time for terminated threads

    `time_value_t system_time'
          total system run time for terminated threads

    `time_value_t creation_time'
          creation time stamp

 -- Data type: task_basic_info_t
     This is a pointer to a `struct task_basic_info'.

 -- Data type: struct task_events_info
     This structure is returned in TASK_INFO by the `task_info'
     function and provides event statistics for the task.  You can cast
     a variable of type `task_info_t' to a pointer of this type if you
     provided it as the TASK_INFO parameter for the `TASK_EVENTS_INFO'
     flavor of `task_info'.  It has the following members:

    `natural_t faults'
          number of page faults

    `natural_t zero_fills'
          number of zero fill pages

    `natural_t reactivations'
          number of reactivated pages

    `natural_t pageins'
          number of actual pageins

    `natural_t cow_faults'
          number of copy-on-write faults

    `natural_t messages_sent'
          number of messages sent

    `natural_t messages_received'
          number of messages received

 -- Data type: task_events_info_t
     This is a pointer to a `struct task_events_info'.

 -- Data type: struct task_thread_times_info
     This structure is returned in TASK_INFO by the `task_info'
     function and provides event statistics for the task.  You can cast
     a variable of type `task_info_t' to a pointer of this type if you
     provided it as the TASK_INFO parameter for the
     `TASK_THREAD_TIMES_INFO' flavor of `task_info'.  It has the
     following members:

    `time_value_t user_time'
          total user run time for live threads

    `time_value_t system_time'
          total system run time for live threads

 -- Data type: task_thread_times_info_t
     This is a pointer to a `struct task_thread_times_info'.


File: mach.info,  Node: Task Execution,  Next: Task Special Ports,  Prev: Task Information,  Up: Task Interface

7.2.4 Task Execution
--------------------

 -- Function: kern_return_t task_suspend (task_t TARGET_TASK)
     The function `task_suspend' increments the task's suspend count and
     stops all threads in the task.  As long as the suspend count is
     positive newly created threads will not run.  This call does not
     return until all threads are suspended.

     The count may become greater than one, with the effect that it
     will take more than one resume call to restart the task.

     The function returns `KERN_SUCCESS' if the task has been suspended
     and `KERN_INVALID_ARGUMENT' if TARGET_TASK is not a task.

 -- Function: kern_return_t task_resume (task_t TARGET_TASK)
     The function `task_resume' decrements the task's suspend count.  If
     it becomes zero, all threads with zero suspend counts in the task
     are resumed.  The count may not become negative.

     The function returns `KERN_SUCCESS' if the task has been resumed,
     `KERN_FAILURE' if the suspend count is already at zero and
     `KERN_INVALID_ARGUMENT' if TARGET_TASK is not a task.

 -- Function: kern_return_t task_priority (task_t TASK, int PRIORITY,
          boolean_t CHANGE_THREADS)
     The priority of a task is used only for creation of new threads; a
     new thread's priority is set to the enclosing task's priority.
     `task_priority' changes this task priority.  It also sets the
     priorities of all threads in the task to this new priority if
     CHANGE_THREADS is `TRUE'.  Existing threads are not affected
     otherwise.  If this priority change violates the maximum priority
     of some threads, as many threads as possible will be changed and
     an error code will be returned.

     The function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_ARGUMENT' if TASK is not a task, or PRIORITY is not
     a valid priority and `KERN_FAILURE' if CHANGE_THREADS was `TRUE'
     and the attempt to change the priority of at least one existing
     thread failed because the new priority would have exceeded that
     thread's maximum priority.

 -- Function: kern_return_t task_ras_control (task_t TARGET_TASK,
          vm_address_t START_PC, vm_address_t END_PC, int FLAVOR)
     The function `task_ras_control' manipulates a task's set of
     restartable atomic sequences.  If a sequence is installed, and any
     thread in the task is preempted within the range
     [START_PC,END_PC], then the thread is resumed at START_PC.  This
     enables applications to build atomic sequences which, when
     executed to completion, will have executed atomically.
     Restartable atomic sequences are intended to be used on systems
     that do not have hardware support for low-overhead atomic
     primitives.

     As a thread can be rolled-back, the code in the sequence should
     have no side effects other than a final store at END_PC. The
     kernel does not guarantee that the sequence is restartable.  It
     assumes the application knows what it's doing.

     A task may have a finite number of atomic sequences that is
     defined at compile time.

     The flavor specifices the particular operation that should be
     applied to this restartable atomic sequence.  Possible values for
     flavor can be:

    `TASK_RAS_CONTROL_PURGE_ALL'
          Remove all registered sequences for this task.

    `TASK_RAS_CONTROL_PURGE_ONE'
          Remove the named registered sequence for this task.

    `TASK_RAS_CONTROL_PURGE_ALL_AND_INSTALL_ONE'
          Atomically remove all registered sequences and install the
          named sequence.

    `TASK_RAS_CONTROL_INSTALL_ONE'
          Install this sequence.

     The function returns `KERN_SUCCESS' if the operation has been
     performed, `KERN_INVALID_ADDRESS' if the START_PC or END_PC values
     are not a valid address for the requested operation (for example,
     it is invalid to purge a sequence that has not been registered),
     `KERN_RESOURCE_SHORTAGE' if an attempt was made to install more
     restartable atomic sequences for a task than can be supported by
     the kernel, `KERN_INVALID_VALUE' if a bad flavor was specified,
     `KERN_INVALID_ARGUMENT' if TARGET_TASK is not a task and
     `KERN_FAILURE' if the call is not not supported on this
     configuration.


File: mach.info,  Node: Task Special Ports,  Next: Syscall Emulation,  Prev: Task Execution,  Up: Task Interface

7.2.5 Task Special Ports
------------------------

 -- Function: kern_return_t task_get_special_port (task_t TASK,
          int WHICH_PORT, mach_port_t *SPECIAL_PORT)
     The function `task_get_special_port' returns send rights to one of
     a set of special ports for the task specified by TASK.

     The special ports associated with a task are the kernel port
     (`TASK_KERNEL_PORT'), the bootstrap port (`TASK_BOOTSTRAP_PORT')
     and the exception port (`TASK_EXCEPTION_PORT').  The bootstrap
     port is a port to which a task may send a message requesting other
     system service ports.  This port is not used by the kernel.  The
     task's exception port is the port to which messages are sent by
     the kernel when an exception occurs and the thread causing the
     exception has no exception port of its own.

     The following macros to call `task_get_special_port' for a specific
     port are defined in `mach/task_special_ports.h':
     `task_get_exception_port' and `task_get_bootstrap_port'.

     The function returns `KERN_SUCCESS' if the port was returned and
     `KERN_INVALID_ARGUMENT' if TASK is not a task or WHICH_PORT is an
     invalid port selector.

 -- Function: kern_return_t task_get_kernel_port (task_t TASK,
          mach_port_t *KERNEL_PORT)
     The function `task_get_kernel_port' is equivalent to the function
     `task_get_special_port' with the WHICH_PORT argument set to
     `TASK_KERNEL_PORT'.

 -- Function: kern_return_t task_get_exception_port (task_t TASK,
          mach_port_t *EXCEPTION_PORT)
     The function `task_get_exception_port' is equivalent to the
     function `task_get_special_port' with the WHICH_PORT argument set
     to `TASK_EXCEPTION_PORT'.

 -- Function: kern_return_t task_get_bootstrap_port (task_t TASK,
          mach_port_t *BOOTSTRAP_PORT)
     The function `task_get_bootstrap_port' is equivalent to the
     function `task_get_special_port' with the WHICH_PORT argument set
     to `TASK_BOOTSTRAP_PORT'.

 -- Function: kern_return_t task_set_special_port (task_t TASK,
          int WHICH_PORT, mach_port_t SPECIAL_PORT)
     The function `thread_set_special_port' sets one of a set of special
     ports for the task specified by TASK.

     The special ports associated with a task are the kernel port
     (`TASK_KERNEL_PORT'), the bootstrap port (`TASK_BOOTSTRAP_PORT')
     and the exception port (`TASK_EXCEPTION_PORT').  The bootstrap
     port is a port to which a thread may send a message requesting
     other system service ports.  This port is not used by the kernel.
     The task's exception port is the port to which messages are sent
     by the kernel when an exception occurs and the thread causing the
     exception has no exception port of its own.

     The function returns `KERN_SUCCESS' if the port was set and
     `KERN_INVALID_ARGUMENT' if TASK is not a task or WHICH_PORT is an
     invalid port selector.

 -- Function: kern_return_t task_set_kernel_port (task_t TASK,
          mach_port_t KERNEL_PORT)
     The function `task_set_kernel_port' is equivalent to the function
     `task_set_special_port' with the WHICH_PORT argument set to
     `TASK_KERNEL_PORT'.

 -- Function: kern_return_t task_set_exception_port (task_t TASK,
          mach_port_t EXCEPTION_PORT)
     The function `task_set_exception_port' is equivalent to the
     function `task_set_special_port' with the WHICH_PORT argument set
     to `TASK_EXCEPTION_PORT'.

 -- Function: kern_return_t task_set_bootstrap_port (task_t TASK,
          mach_port_t BOOTSTRAP_PORT)
     The function `task_set_bootstrap_port' is equivalent to the
     function `task_set_special_port' with the WHICH_PORT argument set
     to `TASK_BOOTSTRAP_PORT'.


File: mach.info,  Node: Syscall Emulation,  Prev: Task Special Ports,  Up: Task Interface

7.2.6 Syscall Emulation
-----------------------

 -- Function: kern_return_t task_get_emulation_vector (task_t TASK,
          int *VECTOR_START, emulation_vector_t *EMULATION_VECTOR,
          mach_msg_type_number_t *EMULATION_VECTOR_COUNT)
     The function `task_get_emulation_vector' gets the user-level
     handler entry points for all emulated system calls.

 -- Function: kern_return_t task_set_emulation_vector (task_t TASK,
          int VECTOR_START, emulation_vector_t EMULATION_VECTOR,
          mach_msg_type_number_t EMULATION_VECTOR_COUNT)
     The function `task_set_emulation_vector' establishes user-level
     handlers for the specified system calls.  Non-emulated system
     calls are specified with an entry of `EML_ROUTINE_NULL'.  System
     call emulation handlers are inherited by the childs of TASK.

 -- Function: kern_return_t task_set_emulation (task_t TASK,
          vm_address_t ROUTINE_ENTRY_PT, int ROUTINE_NUMBER)
     The function `task_set_emulation' establishes a user-level handler
     for the specified system call.  System call emulation handlers are
     inherited by the childs of TASK.


File: mach.info,  Node: Profiling,  Prev: Task Interface,  Up: Threads and Tasks

7.3 Profiling
=============

 -- Function: kern_return_t task_enable_pc_sampling (task_t TASK,
          int *TICKS, sampled_pc_flavor_t FLAVOR)
 -- Function: kern_return_t thread_enable_pc_sampling (thread_t THREAD,
          int *TICKS, sampled_pc_flavor_t FLAVOR)
     The function `task_enable_pc_sampling' enables PC sampling for
     TASK, the function `thread_enable_pc_sampling' enables PC sampling
     for THREAD.  The kernel's idea of clock granularity is returned in
     TICKS in usecs. (this value should not be trusted).  The sampling
     flavor is specified by FLAVOR.

     The function returns `KERN_SUCCESS' if the operation is completed
     successfully and `KERN_INVALID_ARGUMENT' if THREAD is not a valid
     thread.

 -- Function: kern_return_t task_disable_pc_sampling (task_t TASK,
          int *SAMPLE_COUNT)
 -- Function: kern_return_t thread_disable_pc_sampling
          (thread_t THREAD, int *SAMPLE_COUNT)
     The function `task_disable_pc_sampling' disables PC sampling for
     TASK, the function `thread_disable_pc_sampling' disables PC
     sampling for THREAD.  The number of sample elements in the kernel
     for the thread is returned in SAMPLE_COUNT.

     The function returns `KERN_SUCCESS' if the operation is completed
     successfully and `KERN_INVALID_ARGUMENT' if THREAD is not a valid
     thread.

 -- Function: kern_return_t task_get_sampled_pcs (task_t TASK,
          sampled_pc_seqno_t *SEQNO, sampled_pc_array_t SAMPLED_PCS,
          mach_msg_type_number_t *SAMPLE_COUNT)
 -- Function: kern_return_t thread_get_sampled_pcs (thread_t THREAD,
          sampled_pc_seqno_t *SEQNO, sampled_pc_array_t SAMPLED_PCS,
          int *SAMPLE_COUNT)
     The function `task_get_sampled_pcs' extracts the PC samples for
     TASK, the function `thread_get_sampled_pcs' extracts the PC
     samples for THREAD.  SEQNO is the sequence number of the sampled
     PCs.  This is useful for determining when a collector thread has
     missed a sample.  The sampled PCs for the thread are returned in
     SAMPLED_PCS.  SAMPLE_COUNT contains the number of sample elements
     returned.

     The function returns `KERN_SUCCESS' if the operation is completed
     successfully, `KERN_INVALID_ARGUMENT' if THREAD is not a valid
     thread and `KERN_FAILURE' if THREAD is not sampled.

 -- Data type: sampled_pc_t
     This structure is returned in SAMPLED_PCS by the
     `thread_get_sampled_pcs' and `task_get_sampled_pcs' functions and
     provides pc samples for threads or tasks.  It has the following
     members:

    `natural_t id'
          A thread-specific unique identifier.

    `vm_offset_t pc'
          A pc value.

    `sampled_pc_flavor_t sampletype'
          The type of the sample as per flavor.

 -- Data type: sampled_pc_flavor_t
     This data type specifies a pc sample flavor, either as argument
     passed in FLAVOR to the `thread_enable_pc_sample' and
     `thread_disable_pc_sample' functions, or as member `sampletype' in
     the `sample_pc_t' data type.  The flavor is a bitwise-or of the
     possible flavors defined in `mach/pc_sample.h':

    `SAMPLED_PC_PERIODIC'
          default

    `SAMPLED_PC_VM_ZFILL_FAULTS'
          zero filled fault

    `SAMPLED_PC_VM_REACTIVATION_FAULTS'
          reactivation fault

    `SAMPLED_PC_VM_PAGEIN_FAULTS'
          pagein fault

    `SAMPLED_PC_VM_COW_FAULTS'
          copy-on-write fault

    `SAMPLED_PC_VM_FAULTS_ANY'
          any fault

    `SAMPLED_PC_VM_FAULTS'
          the bitwise-or of `SAMPLED_PC_VM_ZFILL_FAULTS',
          `SAMPLED_PC_VM_REACTIVATION_FAULTS',
          `SAMPLED_PC_VM_PAGEIN_FAULTS' and `SAMPLED_PC_VM_COW_FAULTS'.


File: mach.info,  Node: Host Interface,  Next: Processors and Processor Sets,  Prev: Threads and Tasks,  Up: Top

8 Host Interface
****************

This section describes the Mach interface to a host executing a Mach
kernel.  The interface allows to query statistics about a host and
control its behaviour.

   A host is represented by two ports, a name port HOST used to query
information about the host accessible to everyone, and a control port
HOST_PRIV used to manipulate it.  For example, you can query the
current time using the name port, but to change the time you need to
send a message to the host control port.

   Everything described in this section is declared in the header file
`mach.h'.

* Menu:

* Host Ports::                    Ports representing a host.
* Host Information::              Retrieval of information about a host.
* Host Time::                     Operations on the time as seen by a host.
* Host Reboot::                   Rebooting the system.


File: mach.info,  Node: Host Ports,  Next: Host Information,  Up: Host Interface

8.1 Host Ports
==============

 -- Data type: host_t
     This is a `mach_port_t' and used to hold the port name of a host
     name port (or short: host port).  Any task can get a send right to
     the name port of the host running the task using the
     `mach_host_self' system call.  The name port can be used query
     information about the host, for example the current time.

 -- Function: host_t mach_host_self ()
     The `mach_host_self' system call returns the calling thread's host
     name port.  It has an effect equivalent to receiving a send right
     for the host port.  `mach_host_self' returns the name of the send
     right.  In particular, successive calls will increase the calling
     task's user-reference count for the send right.

     As a special exception, the kernel will overrun the user reference
     count of the host name port, so that this function can not fail
     for that reason.  Because of this, the user should not deallocate
     the port right if an overrun might have happened.  Otherwise the
     reference count could drop to zero and the send right be destroyed
     while the user still expects to be able to use it.  As the kernel
     does not make use of the number of extant send rights anyway, this
     is safe to do (the host port itself is never destroyed).

     The function returns `MACH_PORT_NULL' if a resource shortage
     prevented the reception of the send right.

     This function is also available in `mach/mach_traps.h'.

 -- Data type: host_priv_t
     This is a `mach_port_t' and used to hold the port name of a
     privileged host control port.  A send right to the host control
     port is inserted into the first task at bootstrap (*note
     Modules::).  This is the only way to get access to the host
     control port in Mach, so the initial task has to preserve the send
     right carefully, moving a copy of it to other privileged tasks if
     necessary and denying access to unprivileged tasks.


File: mach.info,  Node: Host Information,  Next: Host Time,  Prev: Host Ports,  Up: Host Interface

8.2 Host Information
====================

 -- Function: kern_return_t host_info (host_t HOST, int FLAVOR,
          host_info_t HOST_INFO,
          mach_msg_type_number_t *HOST_INFO_COUNT)
     The `host_info' function returns various information about HOST.
     HOST_INFO is an array of integers that is supplied by the caller.
     It will be filled with the requested information.  HOST_INFO_COUNT
     is supplied as the maximum number of integers in HOST_INFO.  On
     return, it contains the actual number of integers in HOST_INFO.
     The maximum number of integers returned by any flavor is
     `HOST_INFO_MAX'.

     The type of information returned is defined by FLAVOR, which can
     be one of the following:

    `HOST_BASIC_INFO'
          The function returns basic information about the host, as
          defined by `host_basic_info_t'.  This includes the number of
          processors, their type, and the amount of memory installed in
          the system.  The number of integers returned is
          `HOST_BASIC_INFO_COUNT'.  For how to get more information
          about the processor, see *Note Processor Interface::.

    `HOST_PROCESSOR_SLOTS'
          The function returns the numbers of the slots with active
          processors in them.  The number of integers returned can be
          up to `max_cpus', as returned by the `HOST_BASIC_INFO' flavor
          of `host_info'.

    `HOST_SCHED_INFO'
          The function returns information of interest to schedulers as
          defined by `host_sched_info_t'.  The number of integers
          returned is `HOST_SCHED_INFO_COUNT'.

     The function returns `KERN_SUCCESS' if the call succeeded and
     `KERN_INVALID_ARGUMENT' if HOST is not a host or FLAVOR is not
     recognized.  The function returns `MIG_ARRAY_TOO_LARGE' if the
     returned info array is too large for HOST_INFO.  In this case,
     HOST_INFO is filled as much as possible and HOST_INFO_COUNT is set
     to the number of elements that would be returned if there were
     enough room.

 -- Data type: struct host_basic_info
     A pointer to this structure is returned in HOST_INFO by the
     `host_info' function and provides basic information about the host.
     You can cast a variable of type `host_info_t' to a pointer of this
     type if you provided it as the HOST_INFO parameter for the
     `HOST_BASIC_INFO' flavor of `host_info'.  It has the following
     members:

    `int max_cpus'
          The maximum number of possible processors for which the
          kernel is configured.

    `int avail_cpus'
          The number of cpus currently available.

    `vm_size_t memory_size'
          The size of physical memory in bytes.

    `cpu_type_t cpu_type'
          The type of the master processor.

    `cpu_subtype_t cpu_subtype'
          The subtype of the master processor.

     The type and subtype of the individual processors are also
     available by `processor_info', see *Note Processor Interface::.

 -- Data type: host_basic_info_t
     This is a pointer to a `struct host_basic_info'.

 -- Data type: struct host_sched_info
     A pointer to this structure is returned in HOST_INFO by the
     `host_info' function and provides information of interest to
     schedulers.  You can cast a variable of type `host_info_t' to a
     pointer of this type if you provided it as the HOST_INFO parameter
     for the `HOST_SCHED_INFO' flavor of `host_info'.  It has the
     following members:

    `int min_timeout'
          The minimum timeout and unit of time in milliseconds.

    `int min_quantum'
          The minimum quantum and unit of quantum in milliseconds.

 -- Data type: host_sched_info_t
     This is a pointer to a `struct host_sched_info'.

 -- Function: kern_return_t host_kernel_version (host_t HOST,
          kernel_version_t *VERSION)
     The `host_kernel_version' function returns the version string
     compiled into the kernel executing on HOST at the time it was
     built in the character string VERSION.  This string describes the
     version of the kernel.  The constant `KERNEL_VERSION_MAX' should be
     used to dimension storage for the returned string if the
     `kernel_version_t' declaration is not used.

     If the version string compiled into the kernel is longer than
     `KERNEL_VERSION_MAX', the result is truncated and not necessarily
     null-terminated.

     If HOST is not a valid send right to a host port, the function
     returns `KERN_INVALID_ARGUMENT'.  If VERSION points to
     inaccessible memory, it returns `KERN_INVALID_ADDRESS', and
     `KERN_SUCCESS' otherwise.

 -- Function: kern_return_t host_get_boot_info (host_priv_t HOST_PRIV,
          kernel_boot_info_t BOOT_INFO)
     The `host_get_boot_info' function returns the boot-time information
     string supplied by the operator to the kernel executing on
     HOST_PRIV in the character string BOOT_INFO.  The constant
     `KERNEL_BOOT_INFO_MAX' should be used to dimension storage for the
     returned string if the `kernel_boot_info_t' declaration is not
     used.

     If the boot-time information string supplied by the operator is
     longer than `KERNEL_BOOT_INFO_MAX', the result is truncated and not
     necessarily null-terminated.


File: mach.info,  Node: Host Time,  Next: Host Reboot,  Prev: Host Information,  Up: Host Interface

8.3 Host Time
=============

 -- Data type: time_value_t
     This is the representation of a time in Mach.  It is a `struct
     time_value' and consists of the following members:

    `integer_t seconds'
          The number of seconds.

    `integer_t microseconds'
          The number of microseconds.

The number of microseconds should always be smaller than
`TIME_MICROS_MAX' (100000).  A time with this property is "normalized".
Normalized time values can be manipulated with the following macros:

 -- Macro: time_value_add_usec (time_value_t *VAL, integer_t *MICROS)
     Add MICROS microseconds to VAL.  If VAL is normalized and MICROS
     smaller than `TIME_MICROS_MAX', VAL will be normalized afterwards.

 -- Macro: time_value_add (time_value_t *RESULT, time_value_t *ADDEND)
     Add the values in ADDEND to RESULT.  If both are normalized,
     RESULT will be normalized afterwards.

   A variable of type `time_value_t' can either represent a duration or
a fixed point in time.  In the latter case, it shall be interpreted as
the number of seconds and microseconds after the epoch 1. Jan 1970.

 -- Function: kern_return_t host_get_time (host_t HOST,
          time_value_t *CURRENT_TIME)
     Get the current time as seen by HOST.  On success, the time passed
     since the epoch is returned in CURRENT_TIME.

 -- Function: kern_return_t host_set_time (host_priv_t HOST_PRIV,
          time_value_t NEW_TIME)
     Set the time of HOST_PRIV to NEW_TIME.

 -- Function: kern_return_t host_adjust_time (host_priv_t HOST_PRIV,
          time_value_t NEW_ADJUSTMENT, time_value_t *OLD_ADJUSTMENT)
     Arrange for the current time as seen by HOST_PRIV to be gradually
     changed by the adjustment value NEW_ADJUSTMENT, and return the old
     adjustment value in OLD_ADJUSTMENT.

   For efficiency, the current time is available through a mapped-time
interface.

 -- Data type: mapped_time_value_t
     This structure defines the mapped-time interface.  It has the
     following members:

    `integer_t seconds'
          The number of seconds.

    `integer_t microseconds'
          The number of microseconds.

    `integer_t check_seconds'
          This is a copy of the seconds value, which must be checked to
          protect against a race condition when reading out the two
          time values.

   Here is an example how to read out the current time using the
mapped-time interface:

     do
       {
         secs = mtime->seconds;
         usecs = mtime->microseconds;
       }
     while (secs != mtime->check_seconds);


File: mach.info,  Node: Host Reboot,  Prev: Host Time,  Up: Host Interface

8.4 Host Reboot
===============

 -- Function: kern_return_t host_reboot (host_priv_t HOST_PRIV,
          int OPTIONS)
     Reboot the host specified by HOST_PRIV.  The argument OPTIONS
     specifies the flags.  The available flags are defined in
     `sys/reboot.h':

    `RB_HALT'
          Do not reboot, but halt the machine.

    `RB_DEBUGGER'
          Do not reboot, but enter kernel debugger from user space.

     If successful, the function might not return.


File: mach.info,  Node: Processors and Processor Sets,  Next: Device Interface,  Prev: Host Interface,  Up: Top

9 Processors and Processor Sets
*******************************

This section describes the Mach interface to processor sets and
individual processors.  The interface allows to group processors into
sets and control the processors and processor sets.

   A processor is not a central part of the interface.  It is mostly of
relevance as a part of a processor set.  Threads are always assigned to
processor sets, and all processors in a set are equally involved in
executing all threads assigned to that set.

   The processor set is represented by two ports, a name port
PROCESSOR_SET_NAME used to query information about the host accessible
to everyone, and a control port PROCESSOR_SET used to manipulate it.

* Menu:

* Processor Set Interface::       How to work with processor sets.
* Processor Interface::           How to work with individual processors.


File: mach.info,  Node: Processor Set Interface,  Next: Processor Interface,  Up: Processors and Processor Sets

9.1 Processor Set Interface
===========================

* Menu:

* Processor Set Ports::           Ports representing a processor set.
* Processor Set Access::          How the processor sets are accessed.
* Processor Set Creation::        How new processor sets are created.
* Processor Set Destruction::     How processor sets are destroyed.
* Tasks and Threads on Sets::     Assigning tasks, threads to processor sets.
* Processor Set Priority::        Specifying the priority of a processor set.
* Processor Set Policy::          Changing the processor set policies.
* Processor Set Info::            Obtaining information about a processor set.


File: mach.info,  Node: Processor Set Ports,  Next: Processor Set Access,  Up: Processor Set Interface

9.1.1 Processor Set Ports
-------------------------

 -- Data type: processor_set_name_t
     This is a `mach_port_t' and used to hold the port name of a
     processor set name port that names the processor set.  Any task
     can get a send right to name port of a processor set.  The
     processor set name port allows to get information about the
     processor set.

 -- Data type: processor_set_t
     This is a `mach_port_t' and used to hold the port name of a
     privileged processor set control port that represents the
     processor set.  Operations on the processor set are implemented as
     remote procedure calls to the processor set port.  The processor
     set port allows to manipulate the processor set.


File: mach.info,  Node: Processor Set Access,  Next: Processor Set Creation,  Prev: Processor Set Ports,  Up: Processor Set Interface

9.1.2 Processor Set Access
--------------------------

 -- Function: kern_return_t host_processor_sets (host_t HOST,
          processor_set_name_array_t *PROCESSOR_SETS,
          mach_msg_type_number_t *PROCESSOR_SETS_COUNT)
     The function `host_processor_sets' gets send rights to the name
     port for each processor set currently assigned to HOST.

     `host_processor_set_priv' can be used to obtain the control ports
     from these if desired.  PROCESSOR_SETS is an array that is created
     as a result of this call.  The caller may wish to `vm_deallocate'
     this array when the data is no longer needed.
     PROCESSOR_SETS_COUNT is set to the number of processor sets in the
     PROCESSOR_SETS.

     This function returns `KERN_SUCCESS' if the call succeeded and
     `KERN_INVALID_ARGUMENT' if HOST is not a host.

 -- Function: kern_return_t host_processor_set_priv
          (host_priv_t HOST_PRIV, processor_set_name_t SET_NAME,
          processor_set_t *SET)
     The function `host_processor_set_priv' allows a privileged
     application to obtain the control port SET for an existing
     processor set from its name port SET_NAME.  The privileged host
     port HOST_PRIV is required.

     This function returns `KERN_SUCCESS' if the call succeeded and
     `KERN_INVALID_ARGUMENT' if HOST_PRIV is not a valid host control
     port.

 -- Function: kern_return_t processor_set_default (host_t HOST,
          processor_set_name_t *DEFAULT_SET)
     The function `processor_set_default' returns the default processor
     set of HOST in DEFAULT_SET.  The default processor set is used by
     all threads, tasks, and processors that are not explicitly
     assigned to other sets.  processor_set_default returns a port that
     can be used to obtain information about this set (e.g. how many
     threads are assigned to it).  This port cannot be used to perform
     operations on that set.

     This function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_ARGUMENT' if HOST is not a host and
     `KERN_INVALID_ADDRESS' if DEFAULT_SET points to inaccessible
     memory.


File: mach.info,  Node: Processor Set Creation,  Next: Processor Set Destruction,  Prev: Processor Set Access,  Up: Processor Set Interface

9.1.3 Processor Set Creation
----------------------------

 -- Function: kern_return_t processor_set_create (host_t HOST,
          processor_set_t *NEW_SET, processor_set_name_t *NEW_NAME)
     The function `processor_set_create' creates a new processor set on
     HOST and returns the two ports associated with it.  The port
     returned in NEW_SET is the actual port representing the set.  It
     is used to perform operations such as assigning processors, tasks,
     or threads.  The port returned in NEW_NAME identifies the set, and
     is used to obtain information about the set.

     This function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_ARGUMENT' if HOST is not a host,
     `KERN_INVALID_ADDRESS' if NEW_SET or NEW_NAME points to
     inaccessible memory and `KERN_FAILURE' is the operating system does
     not support processor allocation.


File: mach.info,  Node: Processor Set Destruction,  Next: Tasks and Threads on Sets,  Prev: Processor Set Creation,  Up: Processor Set Interface

9.1.4 Processor Set Destruction
-------------------------------

 -- Function: kern_return_t processor_set_destroy
          (processor_set_t PROCESSOR_SET)
     The function `processor_set_destroy' destroys the specified
     processor set.  Any assigned processors, tasks, or threads are
     reassigned to the default set.  The object port for the processor
     set is required (not the name port).  The default processor set
     cannot be destroyed.

     This function returns `KERN_SUCCESS' if the set was destroyed,
     `KERN_FAILURE' if an attempt was made to destroy the default
     processor set, or the operating system does not support processor
     allocation, and `KERN_INVALID_ARGUMENT' if PROCESSOR_SET is not a
     valid processor set control port.


File: mach.info,  Node: Tasks and Threads on Sets,  Next: Processor Set Priority,  Prev: Processor Set Destruction,  Up: Processor Set Interface

9.1.5 Tasks and Threads on Sets
-------------------------------

 -- Function: kern_return_t processor_set_tasks
          (processor_set_t PROCESSOR_SET, task_array_t *TASK_LIST,
          mach_msg_type_number_t *TASK_COUNT)
     The function `processor_set_tasks' gets send rights to the kernel
     port for each task currently assigned to PROCESSOR_SET.

     TASK_LIST is an array that is created as a result of this call.
     The caller may wish to `vm_deallocate' this array when the data is
     no longer needed.  TASK_COUNT is set to the number of tasks in the
     TASK_LIST.

     This function returns `KERN_SUCCESS' if the call succeeded and
     `KERN_INVALID_ARGUMENT' if PROCESSOR_SET is not a processor set.

 -- Function: kern_return_t processor_set_threads
          (processor_set_t PROCESSOR_SET, thread_array_t *THREAD_LIST,
          mach_msg_type_number_t *THREAD_COUNT)
     The function `processor_set_thread' gets send rights to the kernel
     port for each thread currently assigned to PROCESSOR_SET.

     THREAD_LIST is an array that is created as a result of this call.
     The caller may wish to `vm_deallocate' this array when the data is
     no longer needed.  THREAD_COUNT is set to the number of threads in
     the THREAD_LIST.

     This function returns `KERN_SUCCESS' if the call succeeded and
     `KERN_INVALID_ARGUMENT' if PROCESSOR_SET is not a processor set.

 -- Function: kern_return_t task_assign (task_t TASK,
          processor_set_t PROCESSOR_SET, boolean_t ASSIGN_THREADS)
     The function `task_assign' assigns TASK the set PROCESSOR_SET.
     This assignment is for the purposes of determining the initial
     assignment of newly created threads in task.  Any previous
     assignment of the task is nullified.  Existing threads within the
     task are also reassigned if ASSIGN_THREADS is `TRUE'.  They are
     not affected if it is `FALSE'.

     This function returns `KERN_SUCCESS' if the assignment has been
     performed and `KERN_INVALID_ARGUMENT' if TASK is not a task, or
     PROCESSOR_SET is not a processor set on the same host as TASK.

 -- Function: kern_return_t task_assign_default (task_t TASK,
          boolean_t ASSIGN_THREADS)
     The function `task_assign_default' is a variant of `task_assign'
     that assigns the task to the default processor set on that task's
     host.  This variant exists because the control port for the
     default processor set is privileged and not ususally available to
     users.

     This function returns `KERN_SUCCESS' if the assignment has been
     performed and `KERN_INVALID_ARGUMENT' if TASK is not a task.

 -- Function: kern_return_t task_get_assignment (task_t TASK,
          processor_set_name_t *ASSIGNED_SET)
     The function `task_get_assignment' returns the name of the
     processor set to which the thread is currently assigned in
     ASSIGNED_SET.  This port can only be used to obtain information
     about the processor set.

     This function returns `KERN_SUCCESS' if the assignment has been
     performed, `KERN_INVALID_ADDRESS' if PROCESSOR_SET points to
     inaccessible memory, and `KERN_INVALID_ARGUMENT' if TASK is not a
     task.

 -- Function: kern_return_t thread_assign (thread_t THREAD,
          processor_set_t PROCESSOR_SET)
     The function `thread_assign' assigns THREAD the set PROCESSOR_SET.
     After the assignment is completed, the thread only executes on
     processors assigned to the designated processor set.  If there are
     no such processors, then the thread is unable to execute.  Any
     previous assignment of the thread is nullified.  Unix system call
     compatibility code may temporarily force threads to execute on the
     master processor.

     This function returns `KERN_SUCCESS' if the assignment has been
     performed and `KERN_INVALID_ARGUMENT' if THREAD is not a thread,
     or PROCESSOR_SET is not a processor set on the same host as THREAD.

 -- Function: kern_return_t thread_assign_default (thread_t THREAD)
     The function `thread_assign_default' is a variant of
     `thread_assign' that assigns the thread to the default processor
     set on that thread's host.  This variant exists because the
     control port for the default processor set is privileged and not
     ususally available to users.

     This function returns `KERN_SUCCESS' if the assignment has been
     performed and `KERN_INVALID_ARGUMENT' if THREAD is not a thread.

 -- Function: kern_return_t thread_get_assignment (thread_t THREAD,
          processor_set_name_t *ASSIGNED_SET)
     The function `thread_get_assignment' returns the name of the
     processor set to which the thread is currently assigned in
     ASSIGNED_SET.  This port can only be used to obtain information
     about the processor set.

     This function returns `KERN_SUCCESS' if the assignment has been
     performed, `KERN_INVALID_ADDRESS' if PROCESSOR_SET points to
     inaccessible memory, and `KERN_INVALID_ARGUMENT' if THREAD is not
     a thread.


File: mach.info,  Node: Processor Set Priority,  Next: Processor Set Policy,  Prev: Tasks and Threads on Sets,  Up: Processor Set Interface

9.1.6 Processor Set Priority
----------------------------

 -- Function: kern_return_t processor_set_max_priority
          (processor_set_t PROCESSOR_SET, int MAX_PRIORITY,
          boolean_t CHANGE_THREADS)
     The function `processor_set_max_priority' is used to set the
     maximum priority for a processor set.  The priority of a processor
     set is used only for newly created threads (thread's maximum
     priority is set to processor set's) and the assignment of threads
     to the set (thread's maximum priority is reduced if it exceeds the
     set's maximum priority, thread's priority is similarly reduced).
     `processor_set_max_priority' changes this priority.  It also sets
     the maximum priority of all threads assigned to the processor set
     to this new priority if CHANGE_THREADS is `TRUE'.  If this maximum
     priority is less than the priorities of any of these threads,
     their priorities will also be set to this new value.

     This function returns `KERN_SUCCESS' if the call succeeded and
     `KERN_INVALID_ARGUMENT' if PROCESSOR_SET is not a processor set or
     PRIORITY is not a valid priority.


File: mach.info,  Node: Processor Set Policy,  Next: Processor Set Info,  Prev: Processor Set Priority,  Up: Processor Set Interface

9.1.7 Processor Set Policy
--------------------------

 -- Function: kern_return_t processor_set_policy_enable
          (processor_set_t PROCESSOR_SET, int POLICY)
 -- Function: kern_return_t processor_set_policy_disable
          (processor_set_t PROCESSOR_SET, int POLICY,
          boolean_t CHANGE_THREADS)
     Processor sets may restrict the scheduling policies to be used for
     threads assigned to them.  These two calls provide the mechanism
     for designating permitted and forbidden policies.  The current set
     of permitted policies can be obtained from `processor_set_info'.
     Timesharing may not be forbidden by any processor set.  This is a
     compromise to reduce the complexity of the assign operation; any
     thread whose policy is forbidden by the target processor set has
     its policy reset to timesharing.  If the CHANGE_THREADS argument to
     `processor_set_policy_disable' is true, threads currently assigned
     to this processor set and using the newly disabled policy will have
     their policy reset to timesharing.

     `mach/policy.h' contains the allowed policies; it is included by
     `mach.h'.  Not all policies (e.g. fixed priority) are supported by
     all systems.

     This function returns `KERN_SUCCESS' if the operation was completed
     successfully and `KERN_INVALID_ARGUMENT' if PROCESSOR_SET is not a
     processor set or POLICY is not a valid policy, or an attempt was
     made to disable timesharing.


File: mach.info,  Node: Processor Set Info,  Prev: Processor Set Policy,  Up: Processor Set Interface

9.1.8 Processor Set Info
------------------------

 -- Function: kern_return_t processor_set_info
          (processor_set_name_t SET_NAME, int FLAVOR, host_t *HOST,
          processor_set_info_t PROCESSOR_SET_INFO,
          mach_msg_type_number_t *PROCESSOR_SET_INFO_COUNT)
     The function `processor_set_info' returns the selected information
     array for a processor set, as specified by FLAVOR.

     HOST is set to the host on which the processor set resides.  This
     is the non-privileged host port.

     PROCESSOR_SET_INFO is an array of integers that is supplied by the
     caller and returned filled with specified information.
     PROCESSOR_SET_INFO_COUNT is supplied as the maximum number of
     integers in PROCESSOR_SET_INFO.  On return, it contains the actual
     number of integers in PROCESSOR_SET_INFO.  The maximum number of
     integers returned by any flavor is `PROCESSOR_SET_INFO_MAX'.

     The type of information returned is defined by FLAVOR, which can
     be one of the following:

    `PROCESSOR_SET_BASIC_INFO'
          The function returns basic information about the processor
          set, as defined by `processor_set_basic_info_t'.  This
          includes the number of tasks and threads assigned to the
          processor set.  The number of integers returned is
          `PROCESSOR_SET_BASIC_INFO_COUNT'.

    `PROCESSOR_SET_SCHED_INFO'
          The function returns information about the schduling policy
          for the processor set as defined by
          `processor_set_sched_info_t'.  The number of integers
          returned is `PROCESSOR_SET_SCHED_INFO_COUNT'.

     Some machines may define additional (machine-dependent) flavors.

     The function returns `KERN_SUCCESS' if the call succeeded and
     `KERN_INVALID_ARGUMENT' if PROCESSOR_SET is not a processor set or
     FLAVOR is not recognized.  The function returns
     `MIG_ARRAY_TOO_LARGE' if the returned info array is too large for
     PROCESSOR_SET_INFO.  In this case, PROCESSOR_SET_INFO is filled as
     much as possible and PROCESSOR_SET_INFO_COUNT is set to the number
     of elements that would have been returned if there were enough
     room.

 -- Data type: struct processor_set_basic_info
     This structure is returned in PROCESSOR_SET_INFO by the
     `processor_set_info' function and provides basic information about
     the processor set.  You can cast a variable of type
     `processor_set_info_t' to a pointer of this type if you provided it
     as the PROCESSOR_SET_INFO parameter for the
     `PROCESSOR_SET_BASIC_INFO' flavor of `processor_set_info'.  It has
     the following members:

    `int processor_count'
          number of processors

    `int task_count'
          number of tasks

    `int thread_count'
          number of threads

    `int load_average'
          scaled load average

    `int mach_factor'
          scaled mach factor

 -- Data type: processor_set_basic_info_t
     This is a pointer to a `struct processor_set_basic_info'.

 -- Data type: struct processor_set_sched_info
     This structure is returned in PROCESSOR_SET_INFO by the
     `processor_set_info' function and provides schedule information
     about the processor set.  You can cast a variable of type
     `processor_set_info_t' to a pointer of this type if you provided it
     as the PROCESSOR_SET_INFO parameter for the
     `PROCESSOR_SET_SCHED_INFO' flavor of `processor_set_info'.  It has
     the following members:

    `int policies'
          allowed policies

    `int max_priority'
          max priority for new threads

 -- Data type: processor_set_sched_info_t
     This is a pointer to a `struct processor_set_sched_info'.


File: mach.info,  Node: Processor Interface,  Prev: Processor Set Interface,  Up: Processors and Processor Sets

9.2 Processor Interface
=======================

 -- Data type: processor_t
     This is a `mach_port_t' and used to hold the port name of a
     processor port that represents the processor.  Operations on the
     processor are implemented as remote procedure calls to the
     processor port.

* Menu:

* Hosted Processors::             Getting a list of all processors on a host.
* Processor Control::             Starting, stopping, controlling processors.
* Processors and Sets::           Combining processors into processor sets.
* Processor Info::                Obtaining information on processors.


File: mach.info,  Node: Hosted Processors,  Next: Processor Control,  Up: Processor Interface

9.2.1 Hosted Processors
-----------------------

 -- Function: kern_return_t host_processors (host_priv_t HOST_PRIV,
          processor_array_t *PROCESSOR_LIST,
          mach_msg_type_number_t *PROCESSOR_COUNT)
     The function `host_processors' gets send rights to the processor
     port for each processor existing on HOST_PRIV.  This is the
     privileged port that allows its holder to control a processor.

     PROCESSOR_LIST is an array that is created as a result of this
     call.  The caller may wish to `vm_deallocate' this array when the
     data is no longer needed.  PROCESSOR_COUNT is set to the number of
     processors in the PROCESSOR_LIST.

     This function returns `KERN_SUCCESS' if the call succeeded,
     `KERN_INVALID_ARGUMENT' if HOST_PRIV is not a privileged host
     port, and `KERN_INVALID_ADDRESS' if PROCESSOR_COUNT points to
     inaccessible memory.


File: mach.info,  Node: Processor Control,  Next: Processors and Sets,  Prev: Hosted Processors,  Up: Processor Interface

9.2.2 Processor Control
-----------------------

 -- Function: kern_return_t processor_start (processor_t PROCESSOR)
 -- Function: kern_return_t processor_exit (processor_t PROCESSOR)
 -- Function: kern_return_t processor_control (processor_t PROCESSOR,
          processor_info_t *CMD, mach_msg_type_number_t COUNT)
     Some multiprocessors may allow privileged software to control
     processors.  The `processor_start', `processor_exit', and
     `processor_control' operations implement this.  The interpretation
     of the command in CMD is machine dependent.  A newly started
     processor is assigned to the default processor set.  An exited
     processor is removed from the processor set to which it was
     assigned and ceases to be active.

     COUNT contains the length of the command CMD as a number of ints.

     Availability limited.  All of these operations are
     machine-dependent.  They may do nothing.  The ability to restart
     an exited processor is also machine-dependent.

     This function returns `KERN_SUCCESS' if the operation was
     performed, `KERN_FAILURE' if the operation was not performed (a
     likely reason is that it is not supported on this processor),
     `KERN_INVALID_ARGUMENT' if PROCESSOR is not a processor, and
     `KERN_INVALID_ADDRESS' if CMD points to inaccessible memory.


File: mach.info,  Node: Processors and Sets,  Next: Processor Info,  Prev: Processor Control,  Up: Processor Interface

9.2.3 Processors and Sets
-------------------------

 -- Function: kern_return_t processor_assign (processor_t PROCESSOR,
          processor_set_t PROCESSOR_SET, boolean_t WAIT)
     The function `processor_assign' assigns PROCESSOR to the the set
     PROCESSOR_SET.  After the assignment is completed, the processor
     only executes threads that are assigned to that processor set.
     Any previous assignment of the processor is nullified.  The master
     processor cannot be reassigned.  All processors take clock
     interrupts at all times.  The WAIT argument indicates whether the
     caller should wait for the assignment to be completed or should
     return immediately.  Dedicated kernel threads are used to perform
     processor assignment, so setting wait to `FALSE' allows assignment
     requests to be queued and performed faster, especially if the
     kernel has more than one dedicated internal thread for processor
     assignment.  Redirection of other device interrupts away from
     processors assigned to other than the default processor set is
     machine-dependent.  Intermediaries that interpose on ports must be
     sure to interpose on both ports involved in this call if they
     interpose on either.

     This function returns `KERN_SUCCESS' if the assignment has been
     performed, `KERN_INVALID_ARGUMENT' if PROCESSOR is not a
     processor, or PROCESSOR_SET is not a processor set on the same
     host as PROCESSOR.

 -- Function: kern_return_t processor_get_assignment
          (processor_t PROCESSOR, processor_set_name_t *ASSIGNED_SET)
     The function `processor_get_assignment' obtains the current
     assignment of a processor.  The name port of the processor set is
     returned in ASSIGNED_SET.


File: mach.info,  Node: Processor Info,  Prev: Processors and Sets,  Up: Processor Interface

9.2.4 Processor Info
--------------------

 -- Function: kern_return_t processor_info (processor_t PROCESSOR,
          int FLAVOR, host_t *HOST, processor_info_t PROCESSOR_INFO,
          mach_msg_type_number_t *PROCESSOR_INFO_COUNT)
     The function `processor_info' returns the selected information
     array for a processor, as specified by FLAVOR.

     HOST is set to the host on which the processor set resides.  This
     is the non-privileged host port.

     PROCESSOR_INFO is an array of integers that is supplied by the
     caller and returned filled with specified information.
     PROCESSOR_INFO_COUNT is supplied as the maximum number of integers
     in PROCESSOR_INFO.  On return, it contains the actual number of
     integers in PROCESSOR_INFO.  The maximum number of integers
     returned by any flavor is `PROCESSOR_INFO_MAX'.

     The type of information returned is defined by FLAVOR, which can
     be one of the following:

    `PROCESSOR_BASIC_INFO'
          The function returns basic information about the processor,
          as defined by `processor_basic_info_t'.  This includes the
          slot number of the processor.  The number of integers
          returned is `PROCESSOR_BASIC_INFO_COUNT'.

     Machines which require more configuration information beyond the
     slot number are expected to define additional (machine-dependent)
     flavors.

     The function returns `KERN_SUCCESS' if the call succeeded and
     `KERN_INVALID_ARGUMENT' if PROCESSOR is not a processor or FLAVOR
     is not recognized.  The function returns `MIG_ARRAY_TOO_LARGE' if
     the returned info array is too large for PROCESSOR_INFO.  In this
     case, PROCESSOR_INFO is filled as much as possible and
     PROCESSOR_INFOCNT is set to the number of elements that would have
     been returned if there were enough room.

 -- Data type: struct processor_basic_info
     This structure is returned in PROCESSOR_INFO by the
     `processor_info' function and provides basic information about the
     processor.  You can cast a variable of type `processor_info_t' to a
     pointer of this type if you provided it as the PROCESSOR_INFO
     parameter for the `PROCESSOR_BASIC_INFO' flavor of
     `processor_info'.  It has the following members:

    `cpu_type_t cpu_type'
          cpu type

    `cpu_subtype_t cpu_subtype'
          cpu subtype

    `boolean_t running'
          is processor running?

    `int slot_num'
          slot number

    `boolean_t is_master'
          is this the master processor

 -- Data type: processor_basic_info_t
     This is a pointer to a `struct processor_basic_info'.


File: mach.info,  Node: Device Interface,  Next: Kernel Debugger,  Prev: Processors and Processor Sets,  Up: Top

10 Device Interface
*******************

The GNU Mach microkernel provides a simple device interface that allows
the user space programs to access the underlying hardware devices.  Each
device has a unique name, which is a string up to 127 characters long.
To open a device, the device master port has to be supplied.  The device
master port is only available through the bootstrap port.  Anyone who
has control over the device master port can use all hardware devices.

 -- Data type: device_t
     This is a `mach_port_t' and used to hold the port name of a device
     port that represents the device.  Operations on the device are
     implemented as remote procedure calls to the device port.  Each
     device provides a sequence of records.  The length of a record is
     specific to the device.  Data can be transferred "out-of-line" or
     "in-line" (*note Memory::).

   All constants and functions in this chapter are defined in
`device/device.h'.

* Menu:

* Device Reply Server::           Handling device reply messages.
* Device Open::                   Opening hardware devices.
* Device Close::                  Closing hardware devices.
* Device Read::                   Reading data from the device.
* Device Write::                  Writing data to the device.
* Device Map::                    Mapping devices into virtual memory.
* Device Status::                 Querying and manipulating a device.
* Device Filter::                 Filtering packets arriving on a device.


File: mach.info,  Node: Device Reply Server,  Next: Device Open,  Up: Device Interface

10.1 Device Reply Server
========================

Beside the usual synchronous interface, an asynchronous interface is
provided.  For this, the caller has to receive and handle the reply
messages seperately from the function call.

 -- Function: boolean_t device_reply_server (msg_header_t *IN_MSG,
          msg_header_t *OUT_MSG)
     The function `device_reply_server' is produced by the remote
     procedure call generator to handle a received message.  This
     function does all necessary argument handling, and actually calls
     one of the following functions: `ds_device_open_reply',
     `ds_device_read_reply', `ds_device_read_reply_inband',
     `ds_device_write_reply' and `ds_device_write_reply_inband'.

     The IN_MSG argument is the message that has been received from the
     kernel.  The OUT_MSG is a reply message, but this is not used for
     this server.

     The function returns `TRUE' to indicate that the message in
     question was applicable to this interface, and that the appropriate
     routine was called to interpret the message.  It returns `FALSE' to
     indicate that the message did not apply to this interface, and
     that no other action was taken.


File: mach.info,  Node: Device Open,  Next: Device Close,  Prev: Device Reply Server,  Up: Device Interface

10.2 Device Open
================

 -- Function: kern_return_t device_open (mach_port_t MASTER_PORT,
          dev_mode_t MODE, dev_name_t NAME, device_t *DEVICE)
     The function `device_open' opens the device NAME and returns a
     port to it in DEVICE.  The open count for the device is
     incremented by one.  If the open count was 0, the open handler for
     the device is invoked.

     MASTER_PORT must hold the master device port.  NAME specifies the
     device to open, and is a string up to 128 characters long.  MODE
     is the open mode.  It is a bitwise-or of the following constants:

    `D_READ'
          Request read access for the device.

    `D_WRITE'
          Request write access for the device.

    `D_NODELAY'
          Do not delay an open.

     The function returns `D_SUCCESS' if the device was successfully
     opened, `D_INVALID_OPERATION' if MASTER_PORT is not the master
     device port, `D_WOULD_BLOCK' is the device is busy and `D_NOWAIT'
     was specified in mode, `D_ALREADY_OPEN' if the device is already
     open in an incompatible mode and `D_NO_SUCH_DEVICE' if NAME does
     not denote a know device.

 -- Function: kern_return_t device_open_request
          (mach_port_t MASTER_PORT, mach_port_t REPLY_PORT,
          dev_mode_t MODE, dev_name_t NAME)
 -- Function: kern_return_t ds_device_open_reply
          (mach_port_t REPLY_PORT, kern_return_t RETURN,
          device_t *DEVICE)
     This is the asynchronous form of the `device_open' function.
     `device_open_request' performs the open request.  The meaning for
     the parameters is as in `device_open'.  Additionally, the caller
     has to supply a reply port to which the `ds_device_open_reply'
     message is sent by the kernel when the open has been performed.
     The return value of the open operation is stored in RETURN_CODE.

     As neither function receives a reply message, only message
     transmission errors apply.  If no error occurs, `KERN_SUCCESS' is
     returned.


File: mach.info,  Node: Device Close,  Next: Device Read,  Prev: Device Open,  Up: Device Interface

10.3 Device Close
=================

 -- Function: kern_return_t device_close (device_t DEVICE)
     The function `device_close' decrements the open count of the device
     by one.  If the open count drops to zero, the close handler for the
     device is called.  The device to close is specified by its port
     DEVICE.

     The function returns `D_SUCCESS' if the device was successfully
     closed and `D_NO_SUCH_DEVICE' if DEVICE does not denote a device
     port.


File: mach.info,  Node: Device Read,  Next: Device Write,  Prev: Device Close,  Up: Device Interface

10.4 Device Read
================

 -- Function: kern_return_t device_read (device_t DEVICE,
          dev_mode_t MODE, recnum_t RECNUM, int BYTES_WANTED,
          io_buf_ptr_t *DATA, mach_msg_type_number_t *DATA_COUNT)
     The function `device_read' reads BYTES_WANTED bytes from DEVICE,
     and stores them in a buffer allocated with `vm_allocate', which
     address is returned in DATA.  The caller must deallocated it if it
     is no longer needed.  The number of bytes actually returned is
     stored in DATA_COUNT.

     If MODE is `D_NOWAIT', the operation does not block.  Otherwise
     MODE should be 0.  RECNUM is the record number to be read, its
     meaning is device specific.

     The function returns `D_SUCCESS' if some data was successfully
     read, `D_WOULD_BLOCK' if no data is currently available and
     `D_NOWAIT' is specified, and `D_NO_SUCH_DEVICE' if DEVICE does not
     denote a device port.

 -- Function: kern_return_t device_read_inband (device_t DEVICE,
          dev_mode_t MODE, recnum_t RECNUM, int BYTES_WANTED,
          io_buf_ptr_inband_t *DATA, mach_msg_type_number_t *DATA_COUNT)
     The `device_read_inband' function works as the `device_read'
     function, except that the data is returned "in-line" in the reply
     IPC message (*note Memory::).

 -- Function: kern_return_t device_read_request (device_t DEVICE,
          mach_port_t REPLY_PORT, dev_mode_t MODE, recnum_t RECNUM,
          int BYTES_WANTED)
 -- Function: kern_return_t ds_device_read_reply
          (mach_port_t REPLY_PORT, kern_return_t RETURN_CODE,
          io_buf_ptr_t DATA, mach_msg_type_number_t DATA_COUNT)
     This is the asynchronous form of the `device_read' function.
     `device_read_request' performs the read request.  The meaning for
     the parameters is as in `device_read'.  Additionally, the caller
     has to supply a reply port to which the `ds_device_read_reply'
     message is sent by the kernel when the read has been performed.
     The return value of the read operation is stored in RETURN_CODE.

     As neither function receives a reply message, only message
     transmission errors apply.  If no error occurs, `KERN_SUCCESS' is
     returned.

 -- Function: kern_return_t device_read_request_inband
          (device_t DEVICE, mach_port_t REPLY_PORT, dev_mode_t MODE,
          recnum_t RECNUM, int BYTES_WANTED)
 -- Function: kern_return_t ds_device_read_reply_inband
          (mach_port_t REPLY_PORT, kern_return_t RETURN_CODE,
          io_buf_ptr_t DATA, mach_msg_type_number_t DATA_COUNT)
     The `device_read_request_inband' and `ds_device_read_reply_inband'
     functions work as the `device_read_request' and
     `ds_device_read_reply' functions, except that the data is returned
     "in-line" in the reply IPC message (*note Memory::).


File: mach.info,  Node: Device Write,  Next: Device Map,  Prev: Device Read,  Up: Device Interface

10.5 Device Write
=================

 -- Function: kern_return_t device_write (device_t DEVICE,
          dev_mode_t MODE, recnum_t RECNUM, io_buf_ptr_t DATA,
          mach_msg_type_number_t DATA_COUNT, int *BYTES_WRITTEN)
     The function `device_write' writes DATA_COUNT bytes from the
     buffer DATA to DEVICE.  The number of bytes actually written is
     returned in BYTES_WRITTEN.

     If MODE is `D_NOWAIT', the function returns without waiting for
     I/O completion.  Otherwise MODE should be 0.  RECNUM is the record
     number to be written, its meaning is device specific.

     The function returns `D_SUCCESS' if some data was successfully
     written and `D_NO_SUCH_DEVICE' if DEVICE does not denote a device
     port or the device is dead or not completely open.

 -- Function: kern_return_t device_write_inband (device_t DEVICE,
          dev_mode_t MODE, recnum_t RECNUM, int BYTES_WANTED,
          io_buf_ptr_inband_t *DATA, mach_msg_type_number_t *DATA_COUNT)
     The `device_write_inband' function works as the `device_write'
     function, except that the data is sent "in-line" in the request IPC
     message (*note Memory::).

 -- Function: kern_return_t device_write_request (device_t DEVICE,
          mach_port_t REPLY_PORT, dev_mode_t MODE, recnum_t RECNUM,
          io_buf_ptr_t DATA, mach_msg_type_number_t DATA_COUNT)
 -- Function: kern_return_t ds_device_write_reply
          (mach_port_t REPLY_PORT, kern_return_t RETURN_CODE,
          int BYTES_WRITTEN)
     This is the asynchronous form of the `device_write' function.
     `device_write_request' performs the write request.  The meaning for
     the parameters is as in `device_write'.  Additionally, the caller
     has to supply a reply port to which the `ds_device_write_reply'
     message is sent by the kernel when the write has been performed.
     The return value of the write operation is stored in RETURN_CODE.

     As neither function receives a reply message, only message
     transmission errors apply.  If no error occurs, `KERN_SUCCESS' is
     returned.

 -- Function: kern_return_t device_write_request_inband
          (device_t DEVICE, mach_port_t REPLY_PORT, dev_mode_t MODE,
          recnum_t RECNUM, io_buf_ptr_t DATA,
          mach_msg_type_number_t DATA_COUNT)
 -- Function: kern_return_t ds_device_write_reply_inband
          (mach_port_t REPLY_PORT, kern_return_t RETURN_CODE,
          int BYTES_WRITTEN)
     The `device_write_request_inband' and
     `ds_device_write_reply_inband' functions work as the
     `device_write_request' and `ds_device_write_reply' functions,
     except that the data is sent "in-line" in the request IPC message
     (*note Memory::).


File: mach.info,  Node: Device Map,  Next: Device Status,  Prev: Device Write,  Up: Device Interface

10.6 Device Map
===============

 -- Function: kern_return_t device_map (device_t DEVICE,
          vm_prot_t PROT, vm_offset_t OFFSET, vm_size_t SIZE,
          mach_port_t *PAGER, int UNMAP)
     The function `device_map' creates a new memory manager for DEVICE
     and returns a port to it in PAGER.  The memory manager is usable
     as a memory object in a `vm_map' call.  The call is device
     dependant.

     The protection for the memory object is specified by PROT.  The
     memory object starts at OFFSET within the device and extends SIZE
     bytes.  UNMAP is currently unused.

     The function returns `D_SUCCESS' if some data was successfully
     written and `D_NO_SUCH_DEVICE' if DEVICE does not denote a device
     port or the device is dead or not completely open.


File: mach.info,  Node: Device Status,  Next: Device Filter,  Prev: Device Map,  Up: Device Interface

10.7 Device Status
==================

 -- Function: kern_return_t device_set_status (device_t DEVICE,
          dev_flavor_t FLAVOR, dev_status_t STATUS,
          mach_msg_type_number_t STATUS_COUNT)
     The function `device_set_status' sets the status of a device.  The
     possible values for FLAVOR and their interpretation is device
     specific.

     The function returns `D_SUCCESS' if some data was successfully
     written and `D_NO_SUCH_DEVICE' if DEVICE does not denote a device
     port or the device is dead or not completely open.

 -- Function: kern_return_t device_get_status (device_t DEVICE,
          dev_flavor_t FLAVOR, dev_status_t STATUS,
          mach_msg_type_number_t *STATUS_COUNT)
     The function `device_get_status' gets the status of a device.  The
     possible values for FLAVOR and their interpretation is device
     specific.

     The function returns `D_SUCCESS' if some data was successfully
     written and `D_NO_SUCH_DEVICE' if DEVICE does not denote a device
     port or the device is dead or not completely open.


File: mach.info,  Node: Device Filter,  Prev: Device Status,  Up: Device Interface

10.8 Device Filter
==================

 -- Function: kern_return_t device_set_filter (device_t DEVICE,
          mach_port_t RECEIVE_PORT,
          mach_msg_type_name_t RECEIVE_PORT_TYPE, int PRIORITY,
          filter_array_t FILTER, mach_msg_type_number_t FILTER_COUNT)
     The function `device_set_filter' makes it possible to filter out
     selected data arriving at the device and forward it to a port.
     FILTER is a list of filter commands, which are applied to incoming
     data to determine if the data should be sent to RECEIVE_PORT.  The
     IPC type of the send right is specified by RECEIVE_PORT_RIGHT, it
     is either `MACH_MSG_TYPE_MAKE_SEND' or `MACH_MSG_TYPE_MOVE_SEND'.
     The PRIORITY value is used to order multiple filters.

     There can be up to `NET_MAX_FILTER' commands in FILTER.  The
     actual number of commands is passed in FILTER_COUNT.  For the
     purpose of the filter test, an internal stack is provided.  After
     all commands have been processed, the value on the top of the stack
     determines if the data is forwarded or the next filter is tried.

     Each word of the command list specifies a data (push) operation
     (high order NETF_NBPO bits) as well as a binary operator (low
     order NETF_NBPA bits).  The value to be pushed onto the stack is
     chosen as follows.

    `NETF_PUSHLIT'
          Use the next short word of the filter as the value.

    `NETF_PUSHZERO'
          Use 0 as the value.

    `NETF_PUSHWORD+N'
          Use short word N of the "data" portion of the message as the
          value.

    `NETF_PUSHHDR+N'
          Use short word N of the "header" portion of the message as
          the value.

    `NETF_PUSHIND+N'
          Pops the top long word from the stack and then uses short
          word N of the "data" portion of the message as the value.

    `NETF_PUSHHDRIND+N'
          Pops the top long word from the stack and then uses short
          word N of the "header" portion of the message as the value.

    `NETF_PUSHSTK+N'
          Use long word N of the stack (where the top of stack is long
          word 0) as the value.

    `NETF_NOPUSH'
          Don't push a value.

     The unsigned value so chosen is promoted to a long word before
     being pushed.  Once a value is pushed (except for the case of
     `NETF_NOPUSH'), the top two long words of the stack are popped and
     a binary operator applied to them (with the old top of stack as the
     second operand).  The result of the operator is pushed on the
     stack.  These operators are:

    `NETF_NOP'
          Don't pop off any values and do no operation.

    `NETF_EQ'
          Perform an equal comparison.

    `NETF_LT'
          Perform a less than comparison.

    `NETF_LE'
          Perform a less than or equal comparison.

    `NETF_GT'
          Perform a greater than comparison.

    `NETF_GE'
          Perform a greater than or equal comparison.

    `NETF_AND'
          Perform a bitise boolean AND operation.

    `NETF_OR'
          Perform a bitise boolean inclusive OR operation.

    `NETF_XOR'
          Perform a bitise boolean exclusive OR operation.

    `NETF_NEQ'
          Perform a not equal comparison.

    `NETF_LSH'
          Perform a left shift operation.

    `NETF_RSH'
          Perform a right shift operation.

    `NETF_ADD'
          Perform an addition.

    `NETF_SUB'
          Perform a subtraction.

    `NETF_COR'
          Perform an equal comparison. If the comparison is `TRUE',
          terminate the filter list.  Otherwise, pop the result of the
          comparison off the stack.

    `NETF_CAND'
          Perform an equal comparison. If the comparison is `FALSE',
          terminate the filter list.  Otherwise, pop the result of the
          comparison off the stack.

    `NETF_CNOR'
          Perform a not equal comparison. If the comparison is `FALSE',
          terminate the filter list.  Otherwise, pop the result of the
          comparison off the stack.

    `NETF_CNAND'
          Perform a not equal comparison. If the comparison is `TRUE',
          terminate the filter list.  Otherwise, pop the result of the
          comparison off the stack.  The scan of the filter list
          terminates when the filter list is emptied, or a `NETF_C...'
          operation terminates the list. At this time, if the final
          value of the top of the stack is `TRUE', then the message is
          accepted for the filter.

     The function returns `D_SUCCESS' if some data was successfully
     written, `D_INVALID_OPERATION' if RECEIVE_PORT is not a valid send
     right, and `D_NO_SUCH_DEVICE' if DEVICE does not denote a device
     port or the device is dead or not completely open.


File: mach.info,  Node: Kernel Debugger,  Next: Copying,  Prev: Device Interface,  Up: Top

11 Kernel Debugger
******************

The GNU Mach kernel debugger `ddb' is a powerful built-in debugger with
a gdb like syntax.  It is enabled at compile time using the
`--enable-kdb' option.  Whenever you want to enter the debugger while
running the kernel, you can press the key combination <Ctrl-Alt-D>.

* Menu:

* Operation::                     Basic architecture of the kernel debugger.
* Commands::                      Available commands in the kernel debugger.
* Variables::                     Access of variables from the kernel debugger.
* Expressions::                   Usage of expressions in the kernel debugger.


File: mach.info,  Node: Operation,  Next: Commands,  Up: Kernel Debugger

11.1 Operation
==============

The current location is called "dot".  The dot is displayed with a
hexadecimal format at a prompt.  Examine and write commands update dot
to the address of the last line examined or the last location modified,
and set "next" to the address of the next location to be examined or
changed.  Other commands don't change dot, and set next to be the same
as dot.

   The general command syntax is:

     COMMAND[/MODIFIER] ADDRESS [,COUNT]

   `!!' repeats the previous command, and a blank line repeats from the
address next with count 1 and no modifiers.  Specifying ADDRESS sets
dot to the address.  Omitting ADDRESS uses dot.  A missing COUNT is
taken to be 1 for printing commands or infinity for stack traces.

   Current `ddb' is enhanced to support multi-thread debugging.  A
break point can be set only for a specific thread, and the address space
or registers of non current thread can be examined or modified if
supported by machine dependent routines.  For example,

     break/t mach_msg_trap $task11.0

   sets a break point at `mach_msg_trap' for the first thread of task
11 listed by a `show all threads' command.

   In the above example, `$task11.0' is translated to the corresponding
thread structure's address by variable translation mechanism described
later.  If a default target thread is set in a variable `$thread', the
`$task11.0' can be omitted.  In general, if `t' is specified in a
modifier of a command line, a specified thread or a default target
thread is used as a target thread instead of the current one.  The `t'
modifier in a command line is not valid in evaluating expressions in a
command line.  If you want to get a value indirectly from a specific
thread's address space or access to its registers within an expression,
you have to specify a default target thread in advance, and to use `:t'
modifier immediately after the indirect access or the register
reference like as follows:

     set $thread $task11.0
     print $eax:t *(0x100):tuh

   No sign extension and indirection `size(long, half word, byte)' can
be specified with `u', `l', `h' and `b' respectively for the indirect
access.

   Note: Support of non current space/register access and user space
break point depend on the machines.  If not supported, attempts of such
operation may provide incorrect information or may cause strange
behavior.  Even if supported, the user space access is limited to the
pages resident in the main memory at that time.  If a target page is not
in the main memory, an error will be reported.

   `ddb' has a feature like a command `more' for the output.  If an
output line exceeds the number set in the `$lines' variable, it
displays `--db_more--' and waits for a response.  The valid responses
for it are:

`<SPC>'
     one more page

`<RET>'
     one more line

`q'
     abort the current command, and return to the command input mode