mach.texi 313 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316
  1. \input texinfo @c -*- Texinfo -*-
  2. @setfilename mach.info
  3. @settitle The GNU Mach Reference Manual
  4. @setchapternewpage odd
  5. @comment Tell install-info what to do.
  6. @dircategory Kernel
  7. @direntry
  8. * GNUMach: (mach). Using and programming the GNU Mach microkernel.
  9. @end direntry
  10. @c Should have a glossary.
  11. @c Unify some of our indices.
  12. @syncodeindex pg cp
  13. @syncodeindex vr fn
  14. @syncodeindex tp fn
  15. @c Get the Mach version we are documenting.
  16. @include version.texi
  17. @set EDITION 0.4
  18. @c @set ISBN X-XXXXXX-XX-X
  19. @copying
  20. This file documents the GNU Mach microkernel.
  21. This is edition @value{EDITION}, last updated on @value{UPDATED}, of @cite{The
  22. GNU Mach Reference Manual}, for version @value{VERSION}.
  23. Copyright @copyright{} 2001, 2002, 2006, 2007, 2008 Free Software
  24. Foundation, Inc.
  25. @c @sp 2
  26. @c Published by the Free Software Foundation @*
  27. @c 59 Temple Place -- Suite 330, @*
  28. @c Boston, MA 02111-1307 USA @*
  29. @c ISBN @value{ISBN} @*
  30. @quotation
  31. Permission is granted to copy, distribute and/or modify this document
  32. under the terms of the GNU Free Documentation License, Version 1.2 or
  33. any later version published by the Free Software Foundation; with no
  34. Invariant Section, with no Front-Cover Texts, and with no Back-Cover
  35. Texts. A copy of the license is included in the section entitled
  36. ``GNU Free Documentation License''.
  37. This work is based on manual pages under the following copyright and license:
  38. @noindent
  39. Mach Operating System@*
  40. Copyright @copyright{} 1991,1990 Carnegie Mellon University@*
  41. All Rights Reserved.
  42. Permission to use, copy, modify and distribute this software and its
  43. documentation is hereby granted, provided that both the copyright
  44. notice and this permission notice appear in all copies of the
  45. software, derivative works or modified versions, and any portions
  46. thereof, and that both notices appear in supporting documentation.
  47. CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  48. CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  49. ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  50. @end quotation
  51. @end copying
  52. @iftex
  53. @shorttitlepage The GNU Mach Reference Manual
  54. @end iftex
  55. @titlepage
  56. @center @titlefont{The GNU Mach}
  57. @sp 1
  58. @center @titlefont{Reference Manual}
  59. @sp 2
  60. @center Marcus Brinkmann
  61. @center with
  62. @center Gordon Matzigkeit, Gibran Hasnaoui,
  63. @center Robert V. Baron, Richard P. Draves, Mary R. Thompson, Joseph S. Barrera
  64. @sp 3
  65. @center Edition @value{EDITION}
  66. @sp 1
  67. @center last updated @value{UPDATED}
  68. @sp 1
  69. @center for version @value{VERSION}
  70. @page
  71. @vskip 0pt plus 1filll
  72. @insertcopying
  73. @end titlepage
  74. @c @titlepage
  75. @c @finalout
  76. @c @title The GNU Mach Reference Manual
  77. @c @author Marcus Brinkmann
  78. @c @author Gordon Matzigkeit
  79. @c @author Gibran Hasnaoui
  80. @c @author Robert V. Baron @c (rvb)
  81. @c @author Richard P. Draves @c (rpd)
  82. @c @author Mary R. Thompson @c (mrt)
  83. @c @author Joseph S. Barrera @c (jsb)
  84. @c @c The following occur rarely in the rcs commit logs of the man pages:
  85. @c @c Dan Stodolsky, (danner)
  86. @c @c David B. Golub, (dbg)
  87. @c @c Terri Watson, (elf)
  88. @c @c Lori Iannamico, (lli) [distribution coordinator]
  89. @c @c Further authors of kernel_interfaces.ps:
  90. @c @c David Black [OSF]
  91. @c @c William Bolosky
  92. @c @c Jonathan Chew
  93. @c @c Alessandro Forin
  94. @c @c Richard F. Rashid
  95. @c @c Avadis Tevanian Jr.
  96. @c @c Michael W. Young
  97. @c @c See also
  98. @c @c http://www.cs.cmu.edu/afs/cs/project/mach/public/www/people-former.html
  99. @page
  100. @ifnottex
  101. @node Top
  102. @top Main Menu
  103. @insertcopying
  104. @end ifnottex
  105. @menu
  106. * Introduction:: How to use this manual.
  107. * Installing:: Setting up GNU Mach on your computer.
  108. * Bootstrap:: Running GNU Mach on your machine.
  109. * Inter Process Communication:: Communication between process.
  110. * Virtual Memory Interface:: Allocating and deallocating virtual memory.
  111. * External Memory Management:: Handling memory pages in user space.
  112. * Threads and Tasks:: Handling of threads and tasks.
  113. * Host Interface:: Interface to a Mach host.
  114. * Processors and Processor Sets:: Handling processors and sets of processors.
  115. * Device Interface:: Accessing kernel devices.
  116. * Kernel Debugger:: How to use the built-in kernel debugger.
  117. Appendices
  118. * Copying:: The GNU General Public License says how you
  119. can copy and share the GNU Mach microkernel.
  120. * Documentation License:: This manual is under the GNU Free
  121. Documentation License.
  122. Indices
  123. * Concept Index:: Index of concepts and programs.
  124. * Function and Data Index:: Index of functions, variables and data types.
  125. @detailmenu
  126. --- The Detailed Node Listing ---
  127. Introduction
  128. * Audience:: The people for whom this manual is written.
  129. * Features:: Reasons to install and use GNU Mach.
  130. * Overview:: Basic architecture of the Mach microkernel.
  131. * History:: The story about Mach.
  132. Installing
  133. * Binary Distributions:: Obtaining ready-to-run GNU distributions.
  134. * Compilation:: Building GNU Mach from its source code.
  135. * Configuration:: Configuration options at compilation time.
  136. * Cross-Compilation:: Building GNU Mach from another system.
  137. Bootstrap
  138. * Bootloader:: Starting the microkernel, or other OSes.
  139. * Modules:: Starting the first task of the OS.
  140. Inter Process Communication
  141. * Major Concepts:: The concepts behind the Mach IPC system.
  142. * Messaging Interface:: Composing, sending and receiving messages.
  143. * Port Manipulation Interface:: Manipulating ports, port rights, port sets.
  144. Messaging Interface
  145. * Mach Message Call:: Sending and receiving messages.
  146. * Message Format:: The format of Mach messages.
  147. * Exchanging Port Rights:: Sending and receiving port rights.
  148. * Memory:: Passing memory regions in messages.
  149. * Message Send:: Sending messages.
  150. * Message Receive:: Receiving messages.
  151. * Atomicity:: Atomicity of port rights.
  152. Port Manipulation Interface
  153. * Port Creation:: How to create new ports and port sets.
  154. * Port Destruction:: How to destroy ports and port sets.
  155. * Port Names:: How to query and manipulate port names.
  156. * Port Rights:: How to work with port rights.
  157. * Ports and other Tasks:: How to move rights between tasks.
  158. * Receive Rights:: How to work with receive rights.
  159. * Port Sets:: How to work with port sets.
  160. * Request Notifications:: How to request notifications for events.
  161. * Inherited Ports:: How to work with the inherited system ports.
  162. Virtual Memory Interface
  163. * Memory Allocation:: Allocation of new virtual memory.
  164. * Memory Deallocation:: Freeing unused virtual memory.
  165. * Data Transfer:: Reading, writing and copying memory.
  166. * Memory Attributes:: Tweaking memory regions.
  167. * Mapping Memory Objects:: How to map memory objects.
  168. * Memory Statistics:: How to get statistics about memory usage.
  169. External Memory Management
  170. * Memory Object Server:: The basics of external memory management.
  171. * Memory Object Creation:: How new memory objects are created.
  172. * Memory Object Termination:: How memory objects are terminated.
  173. * Memory Objects and Data:: Data transfer to and from memory objects.
  174. * Memory Object Locking:: How memory objects are locked.
  175. * Memory Object Attributes:: Manipulating attributes of memory objects.
  176. * Default Memory Manager:: Setting and using the default memory manager.
  177. Threads and Tasks
  178. * Thread Interface:: Manipulating threads.
  179. * Task Interface:: Manipulating tasks.
  180. * Profiling:: Profiling threads and tasks.
  181. Thread Interface
  182. * Thread Creation:: Creating threads.
  183. * Thread Termination:: Terminating threads.
  184. * Thread Information:: How to get informations on threads.
  185. * Thread Settings:: How to set threads related informations.
  186. * Thread Execution:: How to control the thread's machine state.
  187. * Scheduling:: Operations on thread scheduling.
  188. * Thread Special Ports:: How to handle the thread's special ports.
  189. * Exceptions:: Managing exceptions.
  190. Scheduling
  191. * Thread Priority:: Changing the priority of a thread.
  192. * Hand-Off Scheduling:: Switch to a new thread.
  193. * Scheduling Policy:: Setting the scheduling policy.
  194. Task Interface
  195. * Task Creation:: Creating tasks.
  196. * Task Termination:: Terminating tasks.
  197. * Task Information:: Informations on tasks.
  198. * Task Execution:: Thread scheduling in a task.
  199. * Task Special Ports:: How to get and set the task's special ports.
  200. * Syscall Emulation:: How to emulate system calls.
  201. Host Interface
  202. * Host Ports:: Ports representing a host.
  203. * Host Information:: Query information about a host.
  204. * Host Time:: Functions to query manipulate the host time.
  205. * Host Reboot:: Rebooting the system.
  206. Processors and Processor Sets
  207. * Processor Set Interface:: How to work with processor sets.
  208. * Processor Interface:: How to work with individual processors.
  209. Processor Set Interface
  210. * Processor Set Ports:: Ports representing a processor set.
  211. * Processor Set Access:: How the processor sets are accessed.
  212. * Processor Set Creation:: How new processor sets are created.
  213. * Processor Set Destruction:: How processor sets are destroyed.
  214. * Tasks and Threads on Sets:: Assigning tasks or threads to processor sets.
  215. * Processor Set Priority:: Specifying the priority of a processor set.
  216. * Processor Set Policy:: Changing the processor set policies.
  217. * Processor Set Info:: Obtaining information about a processor set.
  218. Processor Interface
  219. * Hosted Processors:: Getting a list of all processors on a host.
  220. * Processor Control:: Starting, stopping, controlling processors.
  221. * Processors and Sets:: Combining processors into processor sets.
  222. * Processor Info:: Obtaining information on processors.
  223. Device Interface
  224. * Device Open:: Opening hardware devices.
  225. * Device Close:: Closing hardware devices.
  226. * Device Read:: Reading data from the device.
  227. * Device Write:: Writing data to the device.
  228. * Device Map:: Mapping devices into virtual memory.
  229. * Device Status:: Querying and manipulating a device.
  230. * Device Filter:: Filtering packets arriving on a device.
  231. Kernel Debugger
  232. * Operation:: Basic architecture of the kernel debugger.
  233. * Commands:: Available commands in the kernel debugger.
  234. * Variables:: Access of variables from the kernel debugger.
  235. * Expressions:: Usage of expressions in the kernel debugger.
  236. Documentation License
  237. * GNU Free Documentation License:: The GNU Free Documentation License.
  238. * CMU License:: The CMU license applies to the original Mach
  239. kernel and its documentation.
  240. @end detailmenu
  241. @end menu
  242. @node Introduction
  243. @chapter Introduction
  244. GNU Mach is the microkernel of the GNU Project. It is the base of the
  245. operating system, and provides its functionality to the Hurd servers,
  246. the GNU C Library and all user applications. The microkernel itself
  247. does not provide much functionality of the system, just enough to make
  248. it possible for the Hurd servers and the C library to implement the missing
  249. features you would expect from a POSIX compatible operating system.
  250. @menu
  251. * Audience:: The people for whom this manual is written.
  252. * Features:: Reasons to install and use GNU Mach.
  253. * Overview:: Basic architecture of the Mach microkernel.
  254. * History:: The story about Mach.
  255. @end menu
  256. @node Audience
  257. @section Audience
  258. This manual is designed to be useful to everybody who is interested in
  259. using, administering, or programming the Mach microkernel.
  260. If you are an end-user and you are looking for help on running the Mach
  261. kernel, the first few chapters of this manual describe the essential
  262. parts of installing and using the kernel in the GNU operating system.
  263. The rest of this manual is a technical discussion of the Mach
  264. programming interface and its implementation, and would not be helpful
  265. until you want to learn how to extend the system or modify the kernel.
  266. This manual is organized according to the subsystems of Mach, and each
  267. chapter begins with descriptions of conceptual ideas that are related to
  268. that subsystem. If you are a programmer and want to learn more about,
  269. say, the Mach IPC subsystem, you can skip to the IPC chapter
  270. (@pxref{Inter Process Communication}), and read about the related
  271. concepts and interface definitions.
  272. @node Features
  273. @section Features
  274. GNU Mach is not the most advanced microkernel known to the planet,
  275. nor is it the fastest or smallest, but it has a rich set of interfaces and
  276. some features which make it useful as the base of the Hurd system.
  277. @table @asis
  278. @item it's free software
  279. Anybody can use, modify, and redistribute it under the terms of the GNU
  280. General Public License (@pxref{Copying}). GNU Mach is part of the GNU
  281. system, which is a complete operating system licensed under the GPL.
  282. @item it's built to survive
  283. As a microkernel, GNU Mach doesn't implement a lot of the features
  284. commonly found in an operating system, but only the bare minimum
  285. that is required to implement a full operating system on top of it.
  286. This means that a lot of the operating system code is maintained outside
  287. of GNU Mach, and while this code may go through a complete redesign, the
  288. code of the microkernel can remain comparatively stable.
  289. @item it's scalable
  290. Mach is particularly well suited for SMP and network cluster techniques.
  291. Thread support is provided at the kernel level, and the kernel itself
  292. takes advantage of that. Network transparency at the IPC level makes
  293. resources of the system available across machine boundaries (with NORMA
  294. IPC, currently not available in GNU Mach).
  295. @item it exists
  296. The Mach microkernel is real software that works Right Now.
  297. It is not a research or a proposal. You don't have to wait at all
  298. before you can start using and developing it. Mach has been used in
  299. many operating systems in the past, usually as the base for a single
  300. UNIX server. In the GNU system, Mach is the base of a functional
  301. multi-server operating system, the Hurd.
  302. @end table
  303. @node Overview
  304. @section Overview
  305. @c This paragraph by Gordon Matzigkeit from the Hurd manual.
  306. An operating system kernel provides a framework for programs to share a
  307. computer's hardware resources securely and efficiently. This requires
  308. that the programs are separated and protected from each other. To make
  309. running multiple programs in parallel useful, there also needs to be a
  310. facility for programs to exchange information by communication.
  311. The Mach microkernel provides abstractions of the underlying hardware
  312. resources like devices and memory. It organizes the running programs
  313. into tasks and threads (points of execution in the tasks). In addition,
  314. Mach provides a rich interface for inter-process communication.
  315. What Mach does not provide is a POSIX compatible programming interface.
  316. In fact, it has no understanding of file systems, POSIX process semantics,
  317. network protocols and many more. All this is implemented in tasks
  318. running on top of the microkernel. In the GNU operating system, the Hurd
  319. servers and the C library share the responsibility to implement the POSIX
  320. interface, and the additional interfaces which are specific to the GNU
  321. system.
  322. @node History
  323. @section History
  324. XXX A few lines about the history of Mach here.
  325. @node Installing
  326. @chapter Installing
  327. Before you can use the Mach microkernel in your system you'll need to install
  328. it and all components you want to use with it, e.g. the rest of the operating
  329. system. You also need a bootloader to load the kernel from the storage
  330. medium and run it when the computer is started.
  331. GNU Mach is only available for Intel i386-compatible architectures
  332. (such as the Pentium) currently. If you have a different architecture
  333. and want to run the GNU Mach microkernel, you will need to port the
  334. kernel and all other software of the system to your machine's architecture.
  335. Porting is an involved process which requires considerable programming skills,
  336. and it is not recommended for the faint-of-heart.
  337. If you have the talent and desire to do a port, contact
  338. @email{bug-hurd@@gnu.org} in order to coordinate the effort.
  339. @menu
  340. * Binary Distributions:: Obtaining ready-to-run GNU distributions.
  341. * Compilation:: Building GNU Mach from its source code.
  342. * Configuration:: Configuration options at compile time.
  343. * Cross-Compilation:: Building GNU Mach from another system.
  344. @end menu
  345. @node Binary Distributions
  346. @section Binary Distributions
  347. By far the easiest and best way to install GNU Mach and the operating
  348. system is to obtain a GNU binary distribution. The GNU operating
  349. system consists of GNU Mach, the Hurd, the C library and many applications.
  350. Without the GNU operating system, you will only have a microkernel, which
  351. is not very useful by itself, without the other programs.
  352. Building the whole operating system takes a huge effort, and you are well
  353. advised to not do it yourself, but to get a binary distribution of the
  354. GNU operating system. The distribution also includes a binary of the
  355. GNU Mach microkernel.
  356. Information on how to obtain the GNU system can be found in the Hurd
  357. info manual.
  358. @node Compilation
  359. @section Compilation
  360. If you already have a running GNU system, and only want to recompile
  361. the kernel, for example to select a different set of included hardware
  362. drivers, you can easily do this. You need the GNU C compiler and
  363. MIG, the Mach interface generator, which both come in their own
  364. packages.
  365. Building and installing the kernel is as easy as with any other GNU
  366. software package. The configure script is used to configure the source
  367. and set the compile time options. The compilation is done by running:
  368. @example
  369. make
  370. @end example
  371. To install the kernel and its header files, just enter the command:
  372. @example
  373. make install
  374. @end example
  375. This will install the kernel as @file{EXEC_PREFIX/boot/gnumach}, the header
  376. files into @file{PREFIX/include/}, the list of message ids as
  377. @file{PREFIX/share/msgids/gnumach.msgids} and the documentation into
  378. @file{PREFIX/share/info/}.
  379. Note that there is also a way to only install the header and documentation
  380. files without having to actually build the whole package: run @command{make
  381. install-data} after having ran @command{configure} to do so. (This is needed
  382. for bootstrapping a cross compiler and similar procedures.)
  383. @node Configuration
  384. @section Configuration
  385. See the following tables for the options can be passed to the
  386. @command{configure} script as command line arguments to control what components
  387. are built into the kernel, how certain things are configured and so on.
  388. See the top-level @file{INSTALL} file for information about generic
  389. @command{configure} options, like under which paths to install the package's
  390. components. It also describes how to control the process by setting
  391. environment variables.
  392. The file @file{i386/README-Drivers} has some i386-specific information for
  393. device drivers. You should only need to consult this file in case a device
  394. driver is not working for you.
  395. @subsection Table of configure switches not related to device drivers
  396. @table @code
  397. @item --enable-kdb
  398. In-kernel debugger. This is only useful if you actually anticipate debugging
  399. the kernel. It is not enabled by default because it adds considerably to the
  400. unpageable memory footprint of the kernel. @xref{Kernel Debugger}.
  401. @end table
  402. @table @code
  403. @item --enable-pae
  404. @acronym{PAE, Physical Address Extension} feature (@samp{ix86}-only),
  405. which is available on modern @samp{ix86} processors; on @samp{ix86-at} disabled
  406. by default, on @samp{ix86-xen} enabled by default.
  407. @end table
  408. @subsection Turning device drivers on or off
  409. Each device driver has an associated configure switch. The following table
  410. indicates whether a device driver is enabled by default or not. It also gives
  411. --- if possible at all --- the configure switches to use for disabling or
  412. enabling device drivers, in case you're not satisfied with the default choices.
  413. You can specify @samp{--enable-device-drivers=WHICH} (where WHICH on
  414. @samp{ix86-at} must be one of @samp{default}, @samp{qemu}, @samp{none}) to
  415. preset a certain subset of all available device drivers.
  416. @samp{--enable-device-drivers} is sugar for
  417. @samp{--enable-device-drivers=default} (and is the implicit default
  418. nevertheless) and @samp{--disable-device-drivers} is short for
  419. @samp{--enable-device-drivers=none}. @samp{qemu} will include only the set of
  420. device drivers that is useful when using the resulting kernel binary to drive a
  421. Hurd system in the @acronym{QEMU} system emulator. This is only useful for
  422. reducing the kernel build time and the kernel image size.
  423. @subsection What the configure switches do
  424. Each configure switch has two effects. First, it defines a @acronym{CPP}
  425. symbol that turns on or off the hooks that autoconfigure the device and add it
  426. to the list of available devices. Second, it adds the source code for the
  427. driver to a make variable so that the code for the driver is compiled and
  428. linked into the kernel. Also follow this route to find the file(s) which are
  429. implementing a certain device driver.
  430. @subsection Table of configure switches related to device drivers
  431. (@samp{%d} in the following denotes a unit number, starting with @samp{0}.)
  432. @table @code
  433. @item --disable-kmsg
  434. Kernel message device @samp{kmsg}.
  435. @item --enable-lpr
  436. Parallel port device driver for the @samp{lpr%d} devices. On @samp{ix86-at}
  437. enabled by @samp{default}.
  438. @item --enable-floppy
  439. PC floppy disk controller device driver for the @samp{fd%d} devices. On
  440. @samp{ix86-at} enabled by @samp{default} and for @samp{qemu}.
  441. @item --enable-ide
  442. IDE controller device driver for the @samp{hd%d} and @samp{hd%ds%d} (disks and
  443. their partitions) devices. On @samp{ix86-at} enabled by @samp{default} and for
  444. @samp{qemu}.
  445. @end table
  446. The following options control drivers for various SCSI controller. SCSI
  447. devices are named @samp{sd%d} and @samp{sd%ds$d} (disks and their partitions)
  448. or @samp{cd%d} (CD ROMs).
  449. @table @code
  450. @item --enable-advansys
  451. AdvanSys SCSI controller device driver. On @samp{ix86-at} enabled by
  452. @samp{default}.
  453. @item --enable-buslogic
  454. BusLogic SCSI controller device driver. On @samp{ix86-at} enabled by
  455. @samp{default}.
  456. @item --enable-flashpoint
  457. Only meaningful in conjunction with the above BusLogic SCSI controller device
  458. driver. Enable the FlashPoint support.
  459. @item --enable-u14-34f
  460. UltraStor 14F/34F SCSI controller device driver. On @samp{ix86-at} enabled by
  461. @samp{default}.
  462. @item --enable-ultrastor
  463. UltraStor SCSI controller device driver. On @samp{ix86-at} enabled by
  464. @samp{default}.
  465. @item --enable-aha152x
  466. Adaptec AHA-152x/2825 SCSI controller device driver. On @samp{ix86-at} enabled
  467. by @samp{default}.
  468. @item --enable-aha1542
  469. Adaptec AHA-1542 SCSI controller device driver. On @samp{ix86-at} enabled by
  470. @samp{default}.
  471. @item --enable-aha1740
  472. Adaptec AHA-1740 SCSI controller device driver. On @samp{ix86-at} enabled by
  473. @samp{default}.
  474. @item --enable-aic7xxx
  475. Adaptec AIC7xxx SCSI controller device driver. On @samp{ix86-at} enabled by
  476. @samp{default}.
  477. @item --enable-fdomain
  478. Future Domain 16xx SCSI controller device driver. On @samp{ix86-at} enabled by
  479. @samp{default}.
  480. @item --enable-in2000
  481. Always IN 2000 SCSI controller device driver. On @samp{ix86-at} enabled by
  482. @samp{default}.
  483. @item --enable-g_NCR5380
  484. Generic NCR5380/53c400 SCSI controller device driver.
  485. @item --enable-NCR53c406a
  486. NCR53c406a SCSI controller device driver.
  487. @item --enable-pas16
  488. PAS16 SCSI controller device driver. On @samp{ix86-at} enabled by
  489. @samp{default}.
  490. @item --enable-seagate
  491. Seagate ST02 and Future Domain TMC-8xx SCSI controller device driver. On
  492. @samp{ix86-at} enabled by @samp{default}.
  493. @item --enable-t128
  494. Trantor T128/T128F/T228 SCSI controller device driver. On @samp{ix86-at}
  495. enabled by @samp{default}.
  496. @item --enable-53c78xx
  497. NCR53C7,8xx SCSI controller device driver. On @samp{ix86-at} enabled by
  498. @samp{default}.
  499. @item --enable-eata_dma
  500. EATA-DMA (DPT, NEC, AT&T, SNI, AST, Olivetti, Alphatronix) SCSI controller
  501. device driver.
  502. @item --enable-eata_pio
  503. EATA-PIO (old DPT PM2001, PM2012A) SCSI controller device driver. On
  504. @samp{ix86-at} enabled by @samp{default}.
  505. @item --enable-wd7000
  506. WD 7000 SCSI controller device driver. On @samp{ix86-at} enabled by
  507. @samp{default}.
  508. @item --enable-eata
  509. EATA ISA/EISA/PCI (DPT and generic EATA/DMA-compliant boards) SCSI controller
  510. device driver. On @samp{ix86-at} enabled by @samp{default}.
  511. @item --enable-am53c974
  512. AM53/79C974 SCSI controller device driver. On @samp{ix86-at} enabled by
  513. @samp{default}.
  514. @item --enable-dtc
  515. DTC3180/3280 SCSI controller device driver. On @samp{ix86-at} enabled by
  516. @samp{default}.
  517. @item --enable-ncr53c8xx
  518. NCR53C8XX, dc390w, dc390u, dc390f SCSI controller device driver. On
  519. @samp{ix86-at} enabled by @samp{default}.
  520. @item --enable-tmscsim
  521. Tekram DC-390(T) SCSI controller device driver. On @samp{ix86-at} enabled by
  522. @samp{default}.
  523. @item --enable-ppa
  524. IOMEGA Parallel Port ZIP drive device driver. On @samp{ix86-at} enabled by
  525. @samp{default}.
  526. @item --enable-qlogicfas
  527. Qlogic FAS SCSI controller device driver. On @samp{ix86-at} enabled by
  528. @samp{default}.
  529. @item --enable-qlogicisp
  530. Qlogic ISP SCSI controller device driver. On @samp{ix86-at} enabled by
  531. @samp{default}.
  532. @item --enable-gdth
  533. GDT SCSI Disk Array controller device driver. On @samp{ix86-at} enabled by
  534. @samp{default}.
  535. @end table
  536. The following options enable drivers for various ethernet cards. NIC devices
  537. are usually named @samp{eth%d}, except for the pocket adaptors.
  538. @c GNU Mach does only autodetect one ethernet card. To enable any further
  539. @c cards, the source code has to be edited.
  540. @c XXX Reference to the source code.
  541. @table @code
  542. @item --enable-ne
  543. NE2000/NE1000 ISA network card device driver. On @samp{ix86-at} enabled by
  544. @samp{default} and for @samp{qemu}.
  545. @item --enable-3c503
  546. 3Com 503 (Etherlink II) network card device driver. On @samp{ix86-at} enabled
  547. by @samp{default}.
  548. @item --enable-3c509
  549. 3Com 509/579 (Etherlink III) network card device driver. On @samp{ix86-at}
  550. enabled by @samp{default}.
  551. @item --enable-wd
  552. WD80X3 network card device driver. On @samp{ix86-at} enabled by
  553. @samp{default}.
  554. @item --enable-3c501
  555. 3COM 501/Etherlink I network card device driver. On @samp{ix86-at} enabled by
  556. @samp{default}.
  557. @item --enable-smc-ultra
  558. SMC Ultra network card device driver. On @samp{ix86-at} enabled by
  559. @samp{default}.
  560. @item --enable-smc-ultra32
  561. SMC Ultra 32 network card device driver. On @samp{ix86-at} enabled by
  562. @samp{default}.
  563. @item --enable-hp-plus
  564. HP PCLAN+ (27247B and 27252A) network card device driver. On @samp{ix86-at}
  565. enabled by @samp{default}.
  566. @item --enable-hp
  567. HP PCLAN (27245 and other 27xxx series) network card device driver. On
  568. @samp{ix86-at} enabled by @samp{default}.
  569. @item --enable-3c59x
  570. 3Com 590/900 series (592/595/597/900/905) "Vortex/Boomerang" network card
  571. device driver. On @samp{ix86-at} enabled by @samp{default}.
  572. @item --enable-seeq8005
  573. Seeq8005 network card device driver. On @samp{ix86-at} enabled by
  574. @samp{default}.
  575. @item --enable-hp100
  576. HP 10/100VG PCLAN (ISA, EISA, PCI) network card device driver. On
  577. @samp{ix86-at} enabled by @samp{default}.
  578. @item --enable-ac3200
  579. Ansel Communications EISA 3200 network card device driver. On @samp{ix86-at}
  580. enabled by @samp{default}.
  581. @item --enable-e2100
  582. Cabletron E21xx network card device driver. On @samp{ix86-at} enabled by
  583. @samp{default}.
  584. @item --enable-at1700
  585. AT1700 (Fujitsu 86965) network card device driver. On @samp{ix86-at} enabled
  586. by @samp{default}.
  587. @item --enable-eth16i
  588. ICL EtherTeam 16i/32 network card device driver. On @samp{ix86-at} enabled by
  589. @samp{default}.
  590. @item --enable-znet
  591. Zenith Z-Note network card device driver. On @samp{ix86-at} enabled by
  592. @samp{default}.
  593. @item --enable-eexpress
  594. EtherExpress 16 network card device driver. On @samp{ix86-at} enabled by
  595. @samp{default}.
  596. @item --enable-eepro
  597. EtherExpressPro network card device driver. On @samp{ix86-at} enabled by
  598. @samp{default}.
  599. @item --enable-eepro100
  600. Intel EtherExpressPro PCI 10+/100B/100+ network card device driver. On
  601. @samp{ix86-at} enabled by @samp{default}.
  602. @item --enable-depca
  603. DEPCA, DE10x, DE200, DE201, DE202, DE210, DE422 network card device driver. On
  604. @samp{ix86-at} enabled by @samp{default}.
  605. @item --enable-ewrk3
  606. EtherWORKS 3 (DE203, DE204, DE205) network card device driver. On
  607. @samp{ix86-at} enabled by @samp{default}.
  608. @item --enable-de4x5
  609. DE425, DE434, DE435, DE450, DE500 network card device driver. On
  610. @samp{ix86-at} enabled by @samp{default}.
  611. @item --enable-apricot
  612. Apricot XEN-II on board ethernet network card device driver. On @samp{ix86-at}
  613. enabled by @samp{default}.
  614. @item --enable-wavelan
  615. AT&T WaveLAN & DEC RoamAbout DS network card device driver.
  616. @item --enable-3c507
  617. 3Com 507 network card device driver. On @samp{ix86-at} enabled by
  618. @samp{default}.
  619. @item --enable-3c505
  620. 3Com 505/Etherlink II network card device driver. On @samp{ix86-at} enabled by
  621. @samp{default}.
  622. @item --enable-de600
  623. D-Link DE-600 network card device driver. On @samp{ix86-at} enabled by
  624. @samp{default}.
  625. @item --enable-de620
  626. D-Link DE-620 network card device driver. On @samp{ix86-at} enabled by
  627. @samp{default}.
  628. @item --enable-sk_g16
  629. Schneider & Koch G16 network card device driver. On @samp{ix86-at} enabled by
  630. @samp{default}.
  631. @item --enable-ni52
  632. NI5210 network card device driver. On @samp{ix86-at} enabled by
  633. @samp{default}.
  634. @item --enable-ni65
  635. NI6510 network card device driver. On @samp{ix86-at} enabled by
  636. @samp{default}.
  637. @item --enable-atp
  638. AT-LAN-TEC/RealTek pocket adaptor network card device driver for the
  639. @samp{atp%d} devices.
  640. @item --enable-lance
  641. AMD LANCE and PCnet (AT1500 and NE2100) network card device driver. On
  642. @samp{ix86-at} enabled by @samp{default}.
  643. @item --enable-tulip
  644. DECchip Tulip (dc21x4x) PCI network card device driver. On @samp{ix86-at}
  645. enabled by @samp{default}.
  646. @item --enable-fmv18x
  647. FMV-181/182/183/184 network card device driver. On @samp{ix86-at} enabled by
  648. @samp{default}.
  649. @item --enable-3c515
  650. 3Com 515 ISA Fast EtherLink network card device driver. On @samp{ix86-at}
  651. enabled by @samp{default}.
  652. @item --enable-pcnet32
  653. AMD PCI PCnet32 (PCI bus NE2100 cards) network card device driver. On
  654. @samp{ix86-at} enabled by @samp{default}.
  655. @item --enable-ne2k-pci
  656. PCI NE2000 network card device driver. On @samp{ix86-at} enabled by
  657. @samp{default}.
  658. @item --enable-yellowfin
  659. Packet Engines Yellowfin Gigabit-NIC network card device driver. On
  660. @samp{ix86-at} enabled by @samp{default}.
  661. @item --enable-rtl8139
  662. RealTek 8129/8139 (not 8019/8029!) network card device driver. On
  663. @samp{ix86-at} enabled by @samp{default}.
  664. @item --enable-epic100
  665. SMC 83c170/175 EPIC/100 (EtherPower II) network card device driver. On
  666. @samp{ix86-at} enabled by @samp{default}.
  667. @item --enable-tlan
  668. TI ThunderLAN network card device driver. On @samp{ix86-at} enabled by
  669. @samp{default}.
  670. @item --enable-via-rhine
  671. VIA Rhine network card device driver. On @samp{ix86-at} enabled by
  672. @samp{default}.
  673. @item --enable-hamachi
  674. Packet Engines "Hamachi" GNIC-2 Gigabit Ethernet device driver. On
  675. @samp{ix86-at} enabled by @samp{default}.
  676. @item --enable-intel-gige
  677. Intel PCI Gigabit Ethernet device driver. On @samp{ix86-at} enabled by
  678. @samp{default}.
  679. @item --enable-myson803
  680. Myson MTD803 Ethernet adapter series device driver. On @samp{ix86-at} enabled
  681. by @samp{default}.
  682. @item --enable-natsemi
  683. National Semiconductor DP8381x series PCI Ethernet device driver. On
  684. @samp{ix86-at} enabled by @samp{default}.
  685. @item --enable-ns820
  686. National Semiconductor DP8382x series PCI Ethernet device driver. On
  687. @samp{ix86-at} enabled by @samp{default}.
  688. @item --enable-starfire
  689. Adaptec Starfire network adapter device driver. On @samp{ix86-at} enabled by
  690. @samp{default}.
  691. @item --enable-sundance
  692. Sundance ST201 "Alta" PCI Ethernet device driver. On @samp{ix86-at} enabled by
  693. @samp{default}.
  694. @item --enable-winbond-840
  695. Winbond W89c840 PCI Ethernet device driver. On @samp{ix86-at} enabled by
  696. @samp{default}.
  697. @end table
  698. The following options either control device drivers for supported PCMCIA
  699. bridges or control the overall behaviour of the GNU Mach PCMCIA core. To make
  700. use of GNU Mach PCMCIA support you need to have the corresponding userland
  701. applications (GNU Mach Card Services) installed.
  702. @table @code
  703. @item --enable-i82365
  704. Device driver for the Intel 82365 and compatible PC Card controllers, and
  705. Yenta-compatible PCI-to-CardBus controllers. On @samp{ix86-at} enabled by
  706. @samp{default}.
  707. @item --enable-pcmcia-isa
  708. ISA bus related bits in the GNU Mach PCMCIA core. Keeping it enabled is
  709. generally a good idea, since it does not only have effect if your PC Card
  710. bridge is attached to the ISA bus, but provides more (ISA) interrupts to the
  711. Card Services for it to assign to the cards in turn. On @samp{ix86-at} enabled
  712. by @samp{default}.
  713. @end table
  714. The following options control device drivers for supported PCMCIA Ethernet
  715. controllers. NIC devices are usually named @samp{eth%d}.
  716. @table @code
  717. @item --enable-3c574_cs
  718. PCMCIA ethernet driver for the 3Com 3c574 ``RoadRunner''. On @samp{ix86-at}
  719. enabled by @samp{default}.
  720. @item --enable-3c589_cs
  721. Driver for the 3Com 3c589 PCMCIA card. On @samp{ix86-at} enabled by
  722. @samp{default}.
  723. @item --enable-axnet_cs
  724. Driver for the Asix AX88190-based PCMCIA cards. On @samp{ix86-at} enabled by
  725. @samp{default}.
  726. @item --enable-fmvj18x_cs
  727. Driver for PCMCIA cards with the fmvj18x chipset. On @samp{ix86-at} enabled by
  728. @samp{default}.
  729. @item --enable-nmclan_cs
  730. Driver for the New Media Ethernet LAN PCMCIA cards. On @samp{ix86-at} enabled
  731. by @samp{default}.
  732. @item --enable-pcnet_cs
  733. Driver for NS8390-based PCMCIA cards. This driver supports the D-Link DE-650
  734. and Linksys EthernetCard cards, the newer D-Link and Linksys combo cards,
  735. Accton EN2212 cards, the RPTI EP400, and the PreMax PE-200 in non-shared-memory
  736. mode, and the IBM Credit Card Adapter, the NE4100, the Thomas Conrad ethernet
  737. card, and the Kingston KNE-PCM/x in shared-memory mode. It will also handle
  738. the Socket EA card in either mode. On @samp{ix86-at} enabled by
  739. @samp{default}.
  740. @item --enable-smc91c92_cs
  741. Driver for SMC91c92-based PCMCIA cards. On @samp{ix86-at} enabled by
  742. @samp{default}.
  743. @item --enable-xirc2ps_cs
  744. Driver for Xircom CreditCard and Realport PCMCIA ethernet adapters. On
  745. @samp{ix86-at} enabled by @samp{default}.
  746. @end table
  747. The following options control device drivers for supported PCMCIA Wireless LAN
  748. network controllers. NIC devices are usually named @samp{eth%d}.
  749. Please mind, that you need to have some userland applications (the GNU Mach
  750. Wireless Tools) installed, in order to make use of these devices.
  751. @table @code
  752. @item --enable-orinoco_cs
  753. Driver for the Hermes or Prism 2 chipset based PCMCIA wireless adapters, with
  754. Lucent/Agere, Intersil or Symbol firmware. This driver is suitable for PCMCIA
  755. wireless adapters, such as the Lucent WavelanIEEE/Orinoco cards and their OEM
  756. (Cabletron/EnteraSys RoamAbout 802.11, ELSA Airlancer, Melco Buffalo and
  757. others). It should also be usable on various Prism II based cards such as the
  758. Linksys, D-Link and Farallon Skyline. It should also work on Symbol cards such
  759. as the 3Com AirConnect and Ericsson WLAN. On @samp{ix86-at} enabled by
  760. @samp{default}.
  761. @end table
  762. @node Cross-Compilation
  763. @section Cross-Compilation
  764. Another way to install the kernel is to use an existing operating system
  765. in order to compile the kernel binary.
  766. This is called @dfn{cross-compiling}, because it is done between two
  767. different platforms. If the pre-built kernels are not working for
  768. you, and you can't ask someone to compile a custom kernel for your
  769. machine, this is your last chance to get a kernel that boots on your
  770. hardware.
  771. Luckily, the kernel does have light dependencies. You don't even
  772. need a cross compiler if your build machine has a compiler and is
  773. the same architecture as the system you want to run GNU Mach on.
  774. You need a cross-mig, though.
  775. XXX More info needed.
  776. @node Bootstrap
  777. @chapter Bootstrap
  778. Bootstrapping@footnote{The term @dfn{bootstrapping} refers to a Dutch
  779. legend about a boy who was able to fly by pulling himself up by his
  780. bootstraps. In computers, this term refers to any process where a
  781. simple system activates a more complicated system.} is the procedure by
  782. which your machine loads the microkernel and transfers control to the
  783. operating system.
  784. @menu
  785. * Bootloader:: Starting the microkernel, or other OSes.
  786. * Modules:: Starting the first task of the OS.
  787. @end menu
  788. @node Bootloader
  789. @section Bootloader
  790. The @dfn{bootloader} is the first software that runs on your machine.
  791. Many hardware architectures have a very simple startup routine which
  792. reads a very simple bootloader from the beginning of the internal hard
  793. disk, then transfers control to it. Other architectures have startup
  794. routines which are able to understand more of the contents of the hard
  795. disk, and directly start a more advanced bootloader.
  796. @cindex GRUB
  797. @cindex GRand Unified Bootloader
  798. @dfn{GRUB}@footnote{The GRand Unified Bootloader, available
  799. from @uref{http://gnu.org/software/grub/}.} is the GNU bootloader.
  800. GRUB provides advanced functionality, and is capable of loading several
  801. different kernels (such as Mach, Linux, DOS, and the *BSD family).
  802. @xref{Top, , Introduction, grub, GRUB Manual}.
  803. GNU Mach conforms to the Multiboot specification which defines an
  804. interface between the bootloader and the components that run very early
  805. at startup. GNU Mach can be started by any bootloader which supports
  806. the multiboot standard. After the bootloader loaded the kernel image to
  807. a designated address in the system memory, it jumps into the startup
  808. code of the kernel. This code initializes the kernel and detects the
  809. available hardware devices. Afterwards, the first system task is
  810. started. @xref{Top, , Overview, multiboot, Multiboot Specification}.
  811. @node Modules
  812. @section Modules
  813. @pindex serverboot
  814. This is outdated.
  815. Because the microkernel does not provide filesystem support and other
  816. features necessary to load the first system task from a storage medium,
  817. the first task is loaded by the bootloader as a module to a specified
  818. address. In the GNU system, this first program is the @code{serverboot}
  819. executable. GNU Mach inserts the host control port and the device
  820. master port into this task and appends the port numbers to the command
  821. line before executing it.
  822. The @code{serverboot} program is responsible for loading and executing
  823. the rest of the Hurd servers. Rather than containing specific
  824. instructions for starting the Hurd, it follows general steps given in a
  825. user-supplied boot script.
  826. XXX More about boot scripts.
  827. @node Inter Process Communication
  828. @chapter Inter Process Communication
  829. This chapter describes the details of the Mach IPC system. First the
  830. actual calls concerned with sending and receiving messages are
  831. discussed, then the details of the port system are described in detail.
  832. @menu
  833. * Major Concepts:: The concepts behind the Mach IPC system.
  834. * Messaging Interface:: Composing, sending and receiving messages.
  835. * Port Manipulation Interface:: Manipulating ports, port rights, port sets.
  836. @end menu
  837. @node Major Concepts
  838. @section Major Concepts
  839. @cindex interprocess communication (IPC)
  840. @cindex IPC (interprocess communication)
  841. @cindex communication between tasks
  842. @cindex remote procedure calls (RPC)
  843. @cindex RPC (remote procedure calls)
  844. @cindex messages
  845. The Mach kernel provides message-oriented, capability-based interprocess
  846. communication. The interprocess communication (IPC) primitives
  847. efficiently support many different styles of interaction, including
  848. remote procedure calls (RPC), object-oriented distributed programming,
  849. streaming of data, and sending very large amounts of data.
  850. The IPC primitives operate on three abstractions: messages, ports, and
  851. port sets. User tasks access all other kernel services and abstractions
  852. via the IPC primitives.
  853. The message primitives let tasks send and receive messages. Tasks send
  854. messages to ports. Messages sent to a port are delivered reliably
  855. (messages may not be lost) and are received in the order in which they
  856. were sent. Messages contain a fixed-size header and a variable amount
  857. of typed data following the header. The header describes the
  858. destination and size of the message.
  859. The IPC implementation makes use of the VM system to efficiently
  860. transfer large amounts of data. The message body can contain the
  861. address of a region in the sender's address space which should be
  862. transferred as part of the message. When a task receives a message
  863. containing an out-of-line region of data, the data appears in an unused
  864. portion of the receiver's address space. This transmission of
  865. out-of-line data is optimized so that sender and receiver share the
  866. physical pages of data copy-on-write, and no actual data copy occurs
  867. unless the pages are written. Regions of memory up to the size of a
  868. full address space may be sent in this manner.
  869. Ports hold a queue of messages. Tasks operate on a port to send and
  870. receive messages by exercising capabilities for the port. Multiple
  871. tasks can hold send capabilities, or rights, for a port. Tasks can also
  872. hold send-once rights, which grant the ability to send a single message.
  873. Only one task can hold the receive capability, or receive right, for a
  874. port. Port rights can be transferred between tasks via messages. The
  875. sender of a message can specify in the message body that the message
  876. contains a port right. If a message contains a receive right for a
  877. port, then the receive right is removed from the sender of the message
  878. and the right is transferred to the receiver of the message. While the
  879. receive right is in transit, tasks holding send rights can still send
  880. messages to the port, and they are queued until a task acquires the
  881. receive right and uses it to receive the messages.
  882. Tasks can receive messages from ports and port sets. The port set
  883. abstraction allows a single thread to wait for a message from any of
  884. several ports. Tasks manipulate port sets with a capability, or
  885. port-set right, which is taken from the same space as the port
  886. capabilities. The port-set right may not be transferred in a message.
  887. A port set holds receive rights, and a receive operation on a port set
  888. blocks waiting for a message sent to any of the constituent ports. A
  889. port may not belong to more than one port set, and if a port is a member
  890. of a port set, the holder of the receive right can't receive directly
  891. from the port.
  892. Port rights are a secure, location-independent way of naming ports. The
  893. port queue is a protected data structure, only accessible via the
  894. kernel's exported message primitives. Rights are also protected by the
  895. kernel; there is no way for a malicious user task to guess a port name
  896. and send a message to a port to which it shouldn't have access. Port
  897. rights do not carry any location information. When a receive right for
  898. a port moves from task to task, and even between tasks on different
  899. machines, the send rights for the port remain unchanged and continue to
  900. function.
  901. @node Messaging Interface
  902. @section Messaging Interface
  903. This section describes how messages are composed, sent and received
  904. within the Mach IPC system.
  905. @menu
  906. * Mach Message Call:: Sending and receiving messages.
  907. * Message Format:: The format of Mach messages.
  908. * Exchanging Port Rights:: Sending and receiving port rights.
  909. * Memory:: Passing memory regions in messages.
  910. * Message Send:: Sending messages.
  911. * Message Receive:: Receiving messages.
  912. * Atomicity:: Atomicity of port rights.
  913. @end menu
  914. @node Mach Message Call
  915. @subsection Mach Message Call
  916. To use the @code{mach_msg} call, you can include the header files
  917. @file{mach/port.h} and @file{mach/message.h}.
  918. @deftypefun mach_msg_return_t mach_msg (@w{mach_msg_header_t *@var{msg}}, @w{mach_msg_option_t @var{option}}, @w{mach_msg_size_t @var{send_size}}, @w{mach_msg_size_t @var{rcv_size}}, @w{mach_port_t @var{rcv_name}}, @w{mach_msg_timeout_t @var{timeout}}, @w{mach_port_t @var{notify}})
  919. The @code{mach_msg} function is used to send and receive messages. Mach
  920. messages contain typed data, which can include port rights and
  921. references to large regions of memory.
  922. @var{msg} is the address of a buffer in the caller's address space.
  923. Message buffers should be aligned on long-word boundaries. The message
  924. options @var{option} are bit values, combined with bitwise-or. One or
  925. both of @code{MACH_SEND_MSG} and @code{MACH_RCV_MSG} should be used.
  926. Other options act as modifiers. When sending a message, @var{send_size}
  927. specifies the size of the message buffer. Otherwise zero should be
  928. supplied. When receiving a message, @var{rcv_size} specifies the size
  929. of the message buffer. Otherwise zero should be supplied. When
  930. receiving a message, @var{rcv_name} specifies the port or port set.
  931. Otherwise @code{MACH_PORT_NULL} should be supplied. When using the
  932. @code{MACH_SEND_TIMEOUT} and @code{MACH_RCV_TIMEOUT} options,
  933. @var{timeout} specifies the time in milliseconds to wait before giving
  934. up. Otherwise @code{MACH_MSG_TIMEOUT_NONE} should be supplied. When
  935. using the @code{MACH_SEND_NOTIFY}, @code{MACH_SEND_CANCEL}, and
  936. @code{MACH_RCV_NOTIFY} options, @var{notify} specifies the port used for
  937. the notification. Otherwise @code{MACH_PORT_NULL} should be supplied.
  938. If the option argument is @code{MACH_SEND_MSG}, it sends a message. The
  939. @var{send_size} argument specifies the size of the message to send. The
  940. @code{msgh_remote_port} field of the message header specifies the
  941. destination of the message.
  942. If the option argument is @code{MACH_RCV_MSG}, it receives a message.
  943. The @var{rcv_size} argument specifies the size of the message buffer
  944. that will receive the message; messages larger than @var{rcv_size} are
  945. not received. The @var{rcv_name} argument specifies the port or port
  946. set from which to receive.
  947. If the option argument is @code{MACH_SEND_MSG|MACH_RCV_MSG}, then
  948. @code{mach_msg} does both send and receive operations. If the send
  949. operation encounters an error (any return code other than
  950. @code{MACH_MSG_SUCCESS}), then the call returns immediately without
  951. attempting the receive operation. Semantically the combined call is
  952. equivalent to separate send and receive calls, but it saves a system
  953. call and enables other internal optimizations.
  954. If the option argument specifies neither @code{MACH_SEND_MSG} nor
  955. @code{MACH_RCV_MSG}, then @code{mach_msg} does nothing.
  956. Some options, like @code{MACH_SEND_TIMEOUT} and @code{MACH_RCV_TIMEOUT},
  957. share a supporting argument. If these options are used together, they
  958. make independent use of the supporting argument's value.
  959. @end deftypefun
  960. @deftp {Data type} mach_msg_timeout_t
  961. This is a @code{natural_t} used by the timeout mechanism. The units are
  962. milliseconds. The value to be used when there is no timeout is
  963. @code{MACH_MSG_TIMEOUT_NONE}.
  964. @end deftp
  965. @node Message Format
  966. @subsection Message Format
  967. @cindex message format
  968. @cindex format of a message
  969. @cindex composing messages
  970. @cindex message composition
  971. A Mach message consists of a fixed size message header, a
  972. @code{mach_msg_header_t}, followed by zero or more data items. Data
  973. items are typed. Each item has a type descriptor followed by the actual
  974. data (or the address of the data, for out-of-line memory regions).
  975. The following data types are related to Mach ports:
  976. @deftp {Data type} mach_port_t
  977. The @code{mach_port_t} data type is an unsigned integer type which
  978. represents a port name in the task's port name space. In GNU Mach, this
  979. is an @code{unsigned int}.
  980. @end deftp
  981. @c This is defined elsewhere.
  982. @c @deftp {Data type} mach_port_seqno_t
  983. @c The @code{mach_port_seqno_t} data type is an unsigned integer type which
  984. @c represents a sequence number of a message. In GNU Mach, this is an
  985. @c @code{unsigned int}.
  986. @c @end deftp
  987. The following data types are related to Mach messages:
  988. @deftp {Data type} mach_msg_bits_t
  989. The @code{mach_msg_bits_t} data type is an @code{unsigned int} used to
  990. store various flags for a message.
  991. @end deftp
  992. @deftp {Data type} mach_msg_size_t
  993. The @code{mach_msg_size_t} data type is an @code{unsigned int} used to
  994. store the size of a message.
  995. @end deftp
  996. @deftp {Data type} mach_msg_id_t
  997. The @code{mach_msg_id_t} data type is an @code{integer_t} typically used to
  998. convey a function or operation id for the receiver.
  999. @end deftp
  1000. @deftp {Data type} mach_msg_header_t
  1001. This structure is the start of every message in the Mach IPC system. It
  1002. has the following members:
  1003. @table @code
  1004. @item mach_msg_bits_t msgh_bits
  1005. The @code{msgh_bits} field has the following bits defined, all other
  1006. bits should be zero:
  1007. @table @code
  1008. @item MACH_MSGH_BITS_REMOTE_MASK
  1009. @itemx MACH_MSGH_BITS_LOCAL_MASK
  1010. The remote and local bits encode @code{mach_msg_type_name_t} values that
  1011. specify the port rights in the @code{msgh_remote_port} and
  1012. @code{msgh_local_port} fields. The remote value must specify a send or
  1013. send-once right for the destination of the message. If the local value
  1014. doesn't specify a send or send-once right for the message's reply port,
  1015. it must be zero and msgh_local_port must be @code{MACH_PORT_NULL}.
  1016. @item MACH_MSGH_BITS_COMPLEX
  1017. The complex bit must be specified if the message body contains port
  1018. rights or out-of-line memory regions. If it is not specified, then the
  1019. message body carries no port rights or memory, no matter what the type
  1020. descriptors may seem to indicate.
  1021. @end table
  1022. @code{MACH_MSGH_BITS_REMOTE} and @code{MACH_MSGH_BITS_LOCAL} macros
  1023. return the appropriate @code{mach_msg_type_name_t} values, given a
  1024. @code{msgh_bits} value. The @code{MACH_MSGH_BITS} macro constructs a
  1025. value for @code{msgh_bits}, given two @code{mach_msg_type_name_t}
  1026. values.
  1027. @item mach_msg_size_t msgh_size
  1028. The @code{msgh_size} field in the header of a received message contains
  1029. the message's size. The message size, a byte quantity, includes the
  1030. message header, type descriptors, and in-line data. For out-of-line
  1031. memory regions, the message size includes the size of the in-line
  1032. address, not the size of the actual memory region. There are no
  1033. arbitrary limits on the size of a Mach message, the number of data items
  1034. in a message, or the size of the data items.
  1035. @item mach_port_t msgh_remote_port
  1036. The @code{msgh_remote_port} field specifies the destination port of the
  1037. message. The field must carry a legitimate send or send-once right for
  1038. a port.
  1039. @item mach_port_t msgh_local_port
  1040. The @code{msgh_local_port} field specifies an auxiliary port right,
  1041. which is conventionally used as a reply port by the recipient of the
  1042. message. The field must carry a send right, a send-once right,
  1043. @code{MACH_PORT_NULL}, or @code{MACH_PORT_DEAD}.
  1044. @item unsigned long msgh_protected_payload
  1045. The @code{msgh_protected_payload} field carries a payload that is set
  1046. by the kernel during message delivery. The payload is an opaque
  1047. identifier that can be used by the receiver to lookup the associated
  1048. data structure.
  1049. It is only valid in received messages. See @ref{Message Receive} for
  1050. further information.
  1051. @item mach_port_seqno_t msgh_seqno
  1052. The @code{msgh_seqno} field provides a sequence number for the message.
  1053. It is only valid in received messages; its value in sent messages is
  1054. overwritten.
  1055. @c XXX The "MESSAGE RECEIVE" section discusses message sequence numbers.
  1056. @item mach_msg_id_t msgh_id
  1057. The @code{mach_msg} call doesn't use the @code{msgh_id} field, but it
  1058. conventionally conveys an operation or function id.
  1059. @end table
  1060. @end deftp
  1061. @deftypefn Macro mach_msg_bits_t MACH_MSGH_BITS (@w{mach_msg_type_name_t @var{remote}}, @w{mach_msg_type_name_t @var{local}})
  1062. This macro composes two @code{mach_msg_type_name_t} values that specify
  1063. the port rights in the @code{msgh_remote_port} and
  1064. @code{msgh_local_port} fields of a @code{mach_msg} call into an
  1065. appropriate @code{mach_msg_bits_t} value.
  1066. @end deftypefn
  1067. @deftypefn Macro mach_msg_type_name_t MACH_MSGH_BITS_REMOTE (@w{mach_msg_bits_t @var{bits}})
  1068. This macro extracts the @code{mach_msg_type_name_t} value for the remote
  1069. port right in a @code{mach_msg_bits_t} value.
  1070. @end deftypefn
  1071. @deftypefn Macro mach_msg_type_name_t MACH_MSGH_BITS_LOCAL (@w{mach_msg_bits_t @var{bits}})
  1072. This macro extracts the @code{mach_msg_type_name_t} value for the local
  1073. port right in a @code{mach_msg_bits_t} value.
  1074. @end deftypefn
  1075. @deftypefn Macro mach_msg_bits_t MACH_MSGH_BITS_PORTS (@w{mach_msg_bits_t @var{bits}})
  1076. This macro extracts the @code{mach_msg_bits_t} component consisting of
  1077. the @code{mach_msg_type_name_t} values for the remote and local port
  1078. right in a @code{mach_msg_bits_t} value.
  1079. @end deftypefn
  1080. @deftypefn Macro mach_msg_bits_t MACH_MSGH_BITS_OTHER (@w{mach_msg_bits_t @var{bits}})
  1081. This macro extracts the @code{mach_msg_bits_t} component consisting of
  1082. everything except the @code{mach_msg_type_name_t} values for the remote
  1083. and local port right in a @code{mach_msg_bits_t} value.
  1084. @end deftypefn
  1085. Each data item has a type descriptor, a @code{mach_msg_type_t} or a
  1086. @code{mach_msg_type_long_t}. The @code{mach_msg_type_long_t} type
  1087. descriptor allows larger values for some fields. The
  1088. @code{msgtl_header} field in the long descriptor is only used for its
  1089. inline, longform, and deallocate bits.
  1090. @deftp {Data type} mach_msg_type_name_t
  1091. This is an @code{unsigned int} and can be used to hold the
  1092. @code{msgt_name} component of the @code{mach_msg_type_t} and
  1093. @code{mach_msg_type_long_t} structure.
  1094. @end deftp
  1095. @deftp {Data type} mach_msg_type_size_t
  1096. This is an @code{unsigned int} and can be used to hold the
  1097. @code{msgt_size} component of the @code{mach_msg_type_t} and
  1098. @code{mach_msg_type_long_t} structure.
  1099. @end deftp
  1100. @deftp {Data type} mach_msg_type_number_t
  1101. This is an @code{natural_t} and can be used to hold the
  1102. @code{msgt_number} component of the @code{mach_msg_type_t} and
  1103. @code{mach_msg_type_long_t} structure.
  1104. @c XXX This is used for the size of arrays, too. Mmh?
  1105. @end deftp
  1106. @deftp {Data type} mach_msg_type_t
  1107. This structure has the following members:
  1108. @table @code
  1109. @item unsigned int msgt_name : 8
  1110. The @code{msgt_name} field specifies the data's type. The following
  1111. types are predefined:
  1112. @table @code
  1113. @item MACH_MSG_TYPE_UNSTRUCTURED
  1114. @item MACH_MSG_TYPE_BIT
  1115. @item MACH_MSG_TYPE_BOOLEAN
  1116. @item MACH_MSG_TYPE_INTEGER_16
  1117. @item MACH_MSG_TYPE_INTEGER_32
  1118. @item MACH_MSG_TYPE_CHAR
  1119. @item MACH_MSG_TYPE_BYTE
  1120. @item MACH_MSG_TYPE_INTEGER_8
  1121. @item MACH_MSG_TYPE_REAL
  1122. @item MACH_MSG_TYPE_STRING
  1123. @item MACH_MSG_TYPE_STRING_C
  1124. @item MACH_MSG_TYPE_PORT_NAME
  1125. @item MACH_MSG_TYPE_PROTECTED_PAYLOAD
  1126. @end table
  1127. The following predefined types specify port rights, and receive special
  1128. treatment. The next section discusses these types in detail. The type
  1129. @c XXX cross ref
  1130. @code{MACH_MSG_TYPE_PORT_NAME} describes port right names, when no
  1131. rights are being transferred, but just names. For this purpose, it
  1132. should be used in preference to @code{MACH_MSG_TYPE_INTEGER_32}.
  1133. @table @code
  1134. @item MACH_MSG_TYPE_MOVE_RECEIVE
  1135. @item MACH_MSG_TYPE_MOVE_SEND
  1136. @item MACH_MSG_TYPE_MOVE_SEND_ONCE
  1137. @item MACH_MSG_TYPE_COPY_SEND
  1138. @item MACH_MSG_TYPE_MAKE_SEND
  1139. @item MACH_MSG_TYPE_MAKE_SEND_ONCE
  1140. @end table
  1141. The type @code{MACH_MSG_TYPE_PROTECTED_PAYLOAD} is used by the kernel
  1142. to indicate that a delivered message carries a payload in the
  1143. @code{msgh_protected_payload} field. See @ref{Message Receive} for
  1144. more information.
  1145. @item msgt_size : 8
  1146. The @code{msgt_size} field specifies the size of each datum, in bits. For
  1147. example, the msgt_size of @code{MACH_MSG_TYPE_INTEGER_32} data is 32.
  1148. @item msgt_number : 12
  1149. The @code{msgt_number} field specifies how many data elements comprise
  1150. the data item. Zero is a legitimate number.
  1151. The total length specified by a type descriptor is @w{@code{(msgt_size *
  1152. msgt_number)}}, rounded up to an integral number of bytes. In-line data
  1153. is then padded to an integral number of long-words. This ensures that
  1154. type descriptors always start on long-word boundaries. It implies that
  1155. message sizes are always an integral multiple of a long-word's size.
  1156. @item msgt_inline : 1
  1157. The @code{msgt_inline} bit specifies, when @code{FALSE}, that the data
  1158. actually resides in an out-of-line region. The address of the memory
  1159. region (a @code{vm_offset_t} or @code{vm_address_t}) follows the type
  1160. descriptor in the message body. The @code{msgt_name}, @code{msgt_size},
  1161. and @code{msgt_number} fields describe the memory region, not the
  1162. address.
  1163. @item msgt_longform : 1
  1164. The @code{msgt_longform} bit specifies, when @code{TRUE}, that this type
  1165. descriptor is a @code{mach_msg_type_long_t} instead of a
  1166. @code{mach_msg_type_t}. The @code{msgt_name}, @code{msgt_size}, and
  1167. @code{msgt_number} fields should be zero. Instead, @code{mach_msg} uses
  1168. the following @code{msgtl_name}, @code{msgtl_size}, and
  1169. @code{msgtl_number} fields.
  1170. @item msgt_deallocate : 1
  1171. The @code{msgt_deallocate} bit is used with out-of-line regions. When
  1172. @code{TRUE}, it specifies that the memory region should be deallocated
  1173. from the sender's address space (as if with @code{vm_deallocate}) when
  1174. the message is sent.
  1175. @item msgt_unused : 1
  1176. The @code{msgt_unused} bit should be zero.
  1177. @end table
  1178. @end deftp
  1179. @deftypefn Macro boolean_t MACH_MSG_TYPE_PORT_ANY (mach_msg_type_name_t type)
  1180. This macro returns @code{TRUE} if the given type name specifies a port
  1181. type, otherwise it returns @code{FALSE}.
  1182. @end deftypefn
  1183. @deftypefn Macro boolean_t MACH_MSG_TYPE_PORT_ANY_SEND (mach_msg_type_name_t type)
  1184. This macro returns @code{TRUE} if the given type name specifies a port
  1185. type with a send or send-once right, otherwise it returns @code{FALSE}.
  1186. @end deftypefn
  1187. @deftypefn Macro boolean_t MACH_MSG_TYPE_PORT_ANY_RIGHT (mach_msg_type_name_t type)
  1188. This macro returns @code{TRUE} if the given type name specifies a port
  1189. right type which is moved, otherwise it returns @code{FALSE}.
  1190. @end deftypefn
  1191. @deftp {Data type} mach_msg_type_long_t
  1192. This structure has the following members:
  1193. @table @code
  1194. @item mach_msg_type_t msgtl_header
  1195. Same meaning as @code{msgt_header}.
  1196. @c XXX cross ref
  1197. @item unsigned short msgtl_name
  1198. Same meaning as @code{msgt_name}.
  1199. @item unsigned short msgtl_size
  1200. Same meaning as @code{msgt_size}.
  1201. @item unsigned int msgtl_number
  1202. Same meaning as @code{msgt_number}.
  1203. @end table
  1204. @end deftp
  1205. @node Exchanging Port Rights
  1206. @subsection Exchanging Port Rights
  1207. @cindex sending port rights
  1208. @cindex receiving port rights
  1209. @cindex moving port rights
  1210. Each task has its own space of port rights. Port rights are named with
  1211. positive integers. Except for the reserved values
  1212. @w{@code{MACH_PORT_NULL (0)}@footnote{In the Hurd system, we don't make
  1213. the assumption that @code{MACH_PORT_NULL} is zero and evaluates to
  1214. false, but rather compare port names to @code{MACH_PORT_NULL}
  1215. explicitly}} and @w{@code{MACH_PORT_DEAD (~0)}}, this is a full 32-bit
  1216. name space. When the kernel chooses a name for a new right, it is free
  1217. to pick any unused name (one which denotes no right) in the space.
  1218. There are five basic kinds of rights: receive rights, send rights,
  1219. send-once rights, port-set rights, and dead names. Dead names are not
  1220. capabilities. They act as place-holders to prevent a name from being
  1221. otherwise used.
  1222. A port is destroyed, or dies, when its receive right is deallocated.
  1223. When a port dies, send and send-once rights for the port turn into dead
  1224. names. Any messages queued at the port are destroyed, which deallocates
  1225. the port rights and out-of-line memory in the messages.
  1226. Tasks may hold multiple user-references for send rights and dead names.
  1227. When a task receives a send right which it already holds, the kernel
  1228. increments the right's user-reference count. When a task deallocates a
  1229. send right, the kernel decrements its user-reference count, and the task
  1230. only loses the send right when the count goes to zero.
  1231. Send-once rights always have a user-reference count of one, although a
  1232. port can have multiple send-once rights, because each send-once right
  1233. held by a task has a different name. In contrast, when a task holds
  1234. send rights or a receive right for a port, the rights share a single
  1235. name.
  1236. A message body can carry port rights; the @code{msgt_name}
  1237. (@code{msgtl_name}) field in a type descriptor specifies the type of
  1238. port right and how the port right is to be extracted from the caller.
  1239. The values @code{MACH_PORT_NULL} and @code{MACH_PORT_DEAD} are always
  1240. valid in place of a port right in a message body. In a sent message,
  1241. the following @code{msgt_name} values denote port rights:
  1242. @table @code
  1243. @item MACH_MSG_TYPE_MAKE_SEND
  1244. The message will carry a send right, but the caller must supply a
  1245. receive right. The send right is created from the receive right, and
  1246. the receive right's make-send count is incremented.
  1247. @item MACH_MSG_TYPE_COPY_SEND
  1248. The message will carry a send right, and the caller should supply a send
  1249. right. The user reference count for the supplied send right is not
  1250. changed. The caller may also supply a dead name and the receiving task
  1251. will get @code{MACH_PORT_DEAD}.
  1252. @item MACH_MSG_TYPE_MOVE_SEND
  1253. The message will carry a send right, and the caller should supply a send
  1254. right. The user reference count for the supplied send right is
  1255. decremented, and the right is destroyed if the count becomes zero.
  1256. Unless a receive right remains, the name becomes available for
  1257. recycling. The caller may also supply a dead name, which loses a user
  1258. reference, and the receiving task will get @code{MACH_PORT_DEAD}.
  1259. @item MACH_MSG_TYPE_MAKE_SEND_ONCE
  1260. The message will carry a send-once right, but the caller must supply a
  1261. receive right. The send-once right is created from the receive right.
  1262. @item MACH_MSG_TYPE_MOVE_SEND_ONCE
  1263. The message will carry a send-once right, and the caller should supply a
  1264. send-once right. The caller loses the supplied send-once right. The
  1265. caller may also supply a dead name, which loses a user reference, and
  1266. the receiving task will get @code{MACH_PORT_DEAD}.
  1267. @item MACH_MSG_TYPE_MOVE_RECEIVE
  1268. The message will carry a receive right, and the caller should supply a
  1269. receive right. The caller loses the supplied receive right, but retains
  1270. any send rights with the same name.
  1271. @end table
  1272. If a message carries a send or send-once right, and the port dies while
  1273. the message is in transit, then the receiving task will get
  1274. @code{MACH_PORT_DEAD} instead of a right. The following
  1275. @code{msgt_name} values in a received message indicate that it carries
  1276. port rights:
  1277. @table @code
  1278. @item MACH_MSG_TYPE_PORT_SEND
  1279. This name is an alias for @code{MACH_MSG_TYPE_MOVE_SEND}. The message
  1280. carried a send right. If the receiving task already has send and/or
  1281. receive rights for the port, then that name for the port will be reused.
  1282. Otherwise, the new right will have a new name. If the task already has
  1283. send rights, it gains a user reference for the right (unless this would
  1284. cause the user-reference count to overflow). Otherwise, it acquires the
  1285. send right, with a user-reference count of one.
  1286. @item MACH_MSG_TYPE_PORT_SEND_ONCE
  1287. This name is an alias for @code{MACH_MSG_TYPE_MOVE_SEND_ONCE}. The
  1288. message carried a send-once right. The right will have a new name.
  1289. @item MACH_MSG_TYPE_PORT_RECEIVE
  1290. This name is an alias for @code{MACH_MSG_TYPE_MOVE_RECEIVE}. The
  1291. message carried a receive right. If the receiving task already has send
  1292. rights for the port, then that name for the port will be reused.
  1293. Otherwise, the right will have a new name. The make-send count of the
  1294. receive right is reset to zero, but the port retains other attributes
  1295. like queued messages, extant send and send-once rights, and requests for
  1296. port-destroyed and no-senders notifications.
  1297. @end table
  1298. When the kernel chooses a new name for a port right, it can choose any
  1299. name, other than @code{MACH_PORT_NULL} and @code{MACH_PORT_DEAD}, which
  1300. is not currently being used for a port right or dead name. It might
  1301. choose a name which at some previous time denoted a port right, but is
  1302. currently unused.
  1303. @node Memory
  1304. @subsection Memory
  1305. @cindex sending memory
  1306. @cindex receiving memory
  1307. A message body can contain the address of a region in the sender's
  1308. address space which should be transferred as part of the message. The
  1309. message carries a logical copy of the memory, but the kernel uses VM
  1310. techniques to defer any actual page copies. Unless the sender or the
  1311. receiver modifies the data, the physical pages remain shared.
  1312. An out-of-line transfer occurs when the data's type descriptor specifies
  1313. @code{msgt_inline} as @code{FALSE}. The address of the memory region (a
  1314. @code{vm_offset_t} or @code{vm_address_t}) should follow the type
  1315. descriptor in the message body. The type descriptor and the address
  1316. contribute to the message's size (@code{send_size}, @code{msgh_size}).
  1317. The out-of-line data does not contribute to the message's size.
  1318. The name, size, and number fields in the type descriptor describe the
  1319. type and length of the out-of-line data, not the in-line address.
  1320. Out-of-line memory frequently requires long type descriptors
  1321. (@code{mach_msg_type_long_t}), because the @code{msgt_number} field is
  1322. too small to describe a page of 4K bytes.
  1323. Out-of-line memory arrives somewhere in the receiver's address space as
  1324. new memory. It has the same inheritance and protection attributes as
  1325. newly @code{vm_allocate}'d memory. The receiver has the responsibility
  1326. of deallocating (with @code{vm_deallocate}) the memory when it is no
  1327. longer needed. Security-conscious receivers should exercise caution
  1328. when using out-of-line memory from untrustworthy sources, because the
  1329. memory may be backed by an unreliable memory manager.
  1330. Null out-of-line memory is legal. If the out-of-line region size is
  1331. zero (for example, because @code{msgtl_number} is zero), then the
  1332. region's specified address is ignored. A received null out-of-line
  1333. memory region always has a zero address.
  1334. Unaligned addresses and region sizes that are not page multiples are
  1335. legal. A received message can also contain memory with unaligned
  1336. addresses and funny sizes. In the general case, the first and last
  1337. pages in the new memory region in the receiver do not contain only data
  1338. from the sender, but are partly zero.@footnote{Sending out-of-line
  1339. memory with a non-page-aligned address, or a size which is not a page
  1340. multiple, works but with a caveat. The extra bytes in the first and
  1341. last page of the received memory are not zeroed, so the receiver can
  1342. peek at more data than the sender intended to transfer. This might be a
  1343. security problem for the sender.} The received address points to the
  1344. start of the data in the first page. This possibility doesn't
  1345. complicate deallocation, because @code{vm_deallocate} does the right
  1346. thing, rounding the start address down and the end address up to
  1347. deallocate all arrived pages.
  1348. Out-of-line memory has a deallocate option, controlled by the
  1349. @code{msgt_deallocate} bit. If it is @code{TRUE} and the out-of-line
  1350. memory region is not null, then the region is implicitly deallocated
  1351. from the sender, as if by @code{vm_deallocate}. In particular, the
  1352. start and end addresses are rounded so that every page overlapped by the
  1353. memory region is deallocated. The use of @code{msgt_deallocate}
  1354. effectively changes the memory copy into a memory movement. In a
  1355. received message, @code{msgt_deallocate} is @code{TRUE} in type
  1356. descriptors for out-of-line memory.
  1357. Out-of-line memory can carry port rights.
  1358. @node Message Send
  1359. @subsection Message Send
  1360. @cindex sending messages
  1361. The send operation queues a message to a port. The message carries a
  1362. copy of the caller's data. After the send, the caller can freely modify
  1363. the message buffer or the out-of-line memory regions and the message
  1364. contents will remain unchanged.
  1365. Message delivery is reliable and sequenced. Messages are not lost, and
  1366. messages sent to a port, from a single thread, are received in the order
  1367. in which they were sent.
  1368. If the destination port's queue is full, then several things can happen.
  1369. If the message is sent to a send-once right (@code{msgh_remote_port}
  1370. carries a send-once right), then the kernel ignores the queue limit and
  1371. delivers the message. Otherwise the caller blocks until there is room
  1372. in the queue, unless the @code{MACH_SEND_TIMEOUT} or
  1373. @code{MACH_SEND_NOTIFY} options are used. If a port has several blocked
  1374. senders, then any of them may queue the next message when space in the
  1375. queue becomes available, with the proviso that a blocked sender will not
  1376. be indefinitely starved.
  1377. These options modify @code{MACH_SEND_MSG}. If @code{MACH_SEND_MSG} is
  1378. not also specified, they are ignored.
  1379. @table @code
  1380. @item MACH_SEND_TIMEOUT
  1381. The timeout argument should specify a maximum time (in milliseconds) for
  1382. the call to block before giving up.@footnote{If MACH_SEND_TIMEOUT is
  1383. used without MACH_SEND_INTERRUPT, then the timeout duration might not be
  1384. accurate. When the call is interrupted and automatically retried, the
  1385. original timeout is used. If interrupts occur frequently enough, the
  1386. timeout interval might never expire.} If the message can't be queued
  1387. before the timeout interval elapses, then the call returns
  1388. @code{MACH_SEND_TIMED_OUT}. A zero timeout is legitimate.
  1389. @item MACH_SEND_NOTIFY
  1390. The notify argument should specify a receive right for a notify port.
  1391. If the send were to block, then instead the message is queued,
  1392. @code{MACH_SEND_WILL_NOTIFY} is returned, and a msg-accepted
  1393. notification is requested. If @code{MACH_SEND_TIMEOUT} is also
  1394. specified, then @code{MACH_SEND_NOTIFY} doesn't take effect until the
  1395. timeout interval elapses.
  1396. With @code{MACH_SEND_NOTIFY}, a task can forcibly queue to a send right
  1397. one message at a time. A msg-accepted notification is sent to the
  1398. notify port when another message can be forcibly queued. If an attempt
  1399. is made to use @code{MACH_SEND_NOTIFY} before then, the call returns a
  1400. @code{MACH_SEND_NOTIFY_IN_PROGRESS} error.
  1401. The msg-accepted notification carries the name of the send right. If
  1402. the send right is deallocated before the msg-accepted notification is
  1403. generated, then the msg-accepted notification carries the value
  1404. @code{MACH_PORT_NULL}. If the destination port is destroyed before the
  1405. notification is generated, then a send-once notification is generated
  1406. instead.
  1407. @item MACH_SEND_INTERRUPT
  1408. If specified, the @code{mach_msg} call will return
  1409. @code{MACH_SEND_INTERRUPTED} if a software interrupt aborts the call.
  1410. Otherwise, the send operation will be retried.
  1411. @item MACH_SEND_CANCEL
  1412. The notify argument should specify a receive right for a notify port.
  1413. If the send operation removes the destination port right from the
  1414. caller, and the removed right had a dead-name request registered for it,
  1415. and notify is the notify port for the dead-name request, then the
  1416. dead-name request may be silently canceled (instead of resulting in a
  1417. port-deleted notification).
  1418. This option is typically used to cancel a dead-name request made with
  1419. the @code{MACH_RCV_NOTIFY} option. It should only be used as an optimization.
  1420. @end table
  1421. The send operation can generate the following return codes. These
  1422. return codes imply that the call did nothing:
  1423. @table @code
  1424. @item MACH_SEND_MSG_TOO_SMALL
  1425. The specified send_size was smaller than the minimum size for a message.
  1426. @item MACH_SEND_NO_BUFFER
  1427. A resource shortage prevented the kernel from allocating a message
  1428. buffer.
  1429. @item MACH_SEND_INVALID_DATA
  1430. The supplied message buffer was not readable.
  1431. @item MACH_SEND_INVALID_HEADER
  1432. The @code{msgh_bits} value was invalid.
  1433. @item MACH_SEND_INVALID_DEST
  1434. The @code{msgh_remote_port} value was invalid.
  1435. @item MACH_SEND_INVALID_REPLY
  1436. The @code{msgh_local_port} value was invalid.
  1437. @item MACH_SEND_INVALID_NOTIFY
  1438. When using @code{MACH_SEND_CANCEL}, the notify argument did not denote a
  1439. valid receive right.
  1440. @end table
  1441. These return codes imply that some or all of the message was destroyed:
  1442. @table @code
  1443. @item MACH_SEND_INVALID_MEMORY
  1444. The message body specified out-of-line data that was not readable.
  1445. @item MACH_SEND_INVALID_RIGHT
  1446. The message body specified a port right which the caller didn't possess.
  1447. @item MACH_SEND_INVALID_TYPE
  1448. A type descriptor was invalid.
  1449. @item MACH_SEND_MSG_TOO_SMALL
  1450. The last data item in the message ran over the end of the message.
  1451. @end table
  1452. These return codes imply that the message was returned to the caller
  1453. with a pseudo-receive operation:
  1454. @table @code
  1455. @item MACH_SEND_TIMED_OUT
  1456. The timeout interval expired.
  1457. @item MACH_SEND_INTERRUPTED
  1458. A software interrupt occurred.
  1459. @item MACH_SEND_INVALID_NOTIFY
  1460. When using @code{MACH_SEND_NOTIFY}, the notify argument did not denote a
  1461. valid receive right.
  1462. @item MACH_SEND_NO_NOTIFY
  1463. A resource shortage prevented the kernel from setting up a msg-accepted
  1464. notification.
  1465. @item MACH_SEND_NOTIFY_IN_PROGRESS
  1466. A msg-accepted notification was already requested, and hasn't yet been
  1467. generated.
  1468. @end table
  1469. These return codes imply that the message was queued:
  1470. @table @code
  1471. @item MACH_SEND_WILL_NOTIFY
  1472. The message was forcibly queued, and a msg-accepted notification was
  1473. requested.
  1474. @item MACH_MSG_SUCCESS
  1475. The message was queued.
  1476. @end table
  1477. Some return codes, like @code{MACH_SEND_TIMED_OUT}, imply that the
  1478. message was almost sent, but could not be queued. In these situations,
  1479. the kernel tries to return the message contents to the caller with a
  1480. pseudo-receive operation. This prevents the loss of port rights or
  1481. memory which only exist in the message. For example, a receive right
  1482. which was moved into the message, or out-of-line memory sent with the
  1483. deallocate bit.
  1484. The pseudo-receive operation is very similar to a normal receive
  1485. operation. The pseudo-receive handles the port rights in the message
  1486. header as if they were in the message body. They are not reversed.
  1487. After the pseudo-receive, the message is ready to be resent. If the
  1488. message is not resent, note that out-of-line memory regions may have
  1489. moved and some port rights may have changed names.
  1490. The pseudo-receive operation may encounter resource shortages. This is
  1491. similar to a @code{MACH_RCV_BODY_ERROR} return code from a receive
  1492. operation. When this happens, the normal send return codes are
  1493. augmented with the @code{MACH_MSG_IPC_SPACE}, @code{MACH_MSG_VM_SPACE},
  1494. @code{MACH_MSG_IPC_KERNEL}, and @code{MACH_MSG_VM_KERNEL} bits to
  1495. indicate the nature of the resource shortage.
  1496. The queueing of a message carrying receive rights may create a circular
  1497. loop of receive rights and messages, which can never be received. For
  1498. example, a message carrying a receive right can be sent to that receive
  1499. right. This situation is not an error, but the kernel will
  1500. garbage-collect such loops, destroying the messages and ports involved.
  1501. @node Message Receive
  1502. @subsection Message Receive
  1503. The receive operation dequeues a message from a port. The receiving
  1504. task acquires the port rights and out-of-line memory regions carried in
  1505. the message.
  1506. The @code{rcv_name} argument specifies a port or port set from which to
  1507. receive. If a port is specified, the caller must possess the receive
  1508. right for the port and the port must not be a member of a port set. If
  1509. no message is present, then the call blocks, subject to the
  1510. @code{MACH_RCV_TIMEOUT} option.
  1511. If a port set is specified, the call will receive a message sent to any
  1512. of the member ports. It is permissible for the port set to have no
  1513. member ports, and ports may be added and removed while a receive from
  1514. the port set is in progress. The received message can come from any of
  1515. the member ports which have messages, with the proviso that a member
  1516. port with messages will not be indefinitely starved. The
  1517. @code{msgh_local_port} field in the received message header specifies
  1518. from which port in the port set the message came.
  1519. The @code{rcv_size} argument specifies the size of the caller's message
  1520. buffer. The @code{mach_msg} call will not receive a message larger than
  1521. @code{rcv_size}. Messages that are too large are destroyed, unless the
  1522. @code{MACH_RCV_LARGE} option is used.
  1523. The destination and reply ports are reversed in a received message
  1524. header. The @code{msgh_local_port} field names the destination port,
  1525. from which the message was received, and the @code{msgh_remote_port}
  1526. field names the reply port right. The bits in @code{msgh_bits} are also
  1527. reversed. The @code{MACH_MSGH_BITS_LOCAL} bits have the value
  1528. @code{MACH_MSG_TYPE_PORT_SEND} if the message was sent to a send right,
  1529. and the value @code{MACH_MSG_TYPE_PORT_SEND_ONCE} if was sent to a
  1530. send-once right. The @code{MACH_MSGH_BITS_REMOTE} bits describe the
  1531. reply port right.
  1532. A received message can contain port rights and out-of-line memory. The
  1533. @code{msgh_local_port} field does not receive a port right; the act of
  1534. receiving the message destroys the send or send-once right for the
  1535. destination port. The msgh_remote_port field does name a received port
  1536. right, the reply port right, and the message body can carry port rights
  1537. and memory if @code{MACH_MSGH_BITS_COMPLEX} is present in msgh_bits.
  1538. Received port rights and memory should be consumed or deallocated in
  1539. some fashion.
  1540. In almost all cases, @code{msgh_local_port} will specify the name of a
  1541. receive right, either @code{rcv_name} or if @code{rcv_name} is a port
  1542. set, a member of @code{rcv_name}. If other threads are concurrently
  1543. manipulating the receive right, the situation is more complicated. If
  1544. the receive right is renamed during the call, then
  1545. @code{msgh_local_port} specifies the right's new name. If the caller
  1546. loses the receive right after the message was dequeued from it, then
  1547. @code{mach_msg} will proceed instead of returning
  1548. @code{MACH_RCV_PORT_DIED}. If the receive right was destroyed, then
  1549. @code{msgh_local_port} specifies @code{MACH_PORT_DEAD}. If the receive
  1550. right still exists, but isn't held by the caller, then
  1551. @code{msgh_local_port} specifies @code{MACH_PORT_NULL}.
  1552. Servers usually associate some state with a receive right. To that
  1553. end, they might use a hash table to look up the state for the port a
  1554. message was sent to. To optimize this, a task may associate an opaque
  1555. @var{payload} with a receive right using the
  1556. @code{mach_port_set_protected_payload} function. Once this is done,
  1557. the kernel will set the @code{msgh_protected_payload} field to
  1558. @var{payload} when delivering a message to this right and indicate
  1559. this by setting the local part of @code{msgh_bits} to
  1560. @code{MACH_MSG_TYPE_PROTECTED_PAYLOAD}.
  1561. The support for protected payloads was added to GNU Mach. To preserve
  1562. binary compatibility, the @code{msgh_local_port} and
  1563. @code{msgh_local_port} share the same location. This makes it
  1564. possible to add the payload information without increasing the size of
  1565. @code{mach_msg_header_t}. This is an implementation detail. Which
  1566. field is valid is determined by the local part of the
  1567. @code{msgh_bits}. Existing software is not affected. When a receive
  1568. right is transferred to another task, its payload is cleared.
  1569. Received messages are stamped with a sequence number, taken from the
  1570. port from which the message was received. (Messages received from a
  1571. port set are stamped with a sequence number from the appropriate member
  1572. port.) Newly created ports start with a zero sequence number, and the
  1573. sequence number is reset to zero whenever the port's receive right moves
  1574. between tasks. When a message is dequeued from the port, it is stamped
  1575. with the port's sequence number and the port's sequence number is then
  1576. incremented. The dequeue and increment operations are atomic, so that
  1577. multiple threads receiving messages from a port can use the
  1578. @code{msgh_seqno} field to reconstruct the original order of the
  1579. messages.
  1580. These options modify @code{MACH_RCV_MSG}. If @code{MACH_RCV_MSG} is not
  1581. also specified, they are ignored.
  1582. @table @code
  1583. @item MACH_RCV_TIMEOUT
  1584. The timeout argument should specify a maximum time (in milliseconds) for
  1585. the call to block before giving up.@footnote{If MACH_RCV_TIMEOUT is used
  1586. without MACH_RCV_INTERRUPT, then the timeout duration might not be
  1587. accurate. When the call is interrupted and automatically retried, the
  1588. original timeout is used. If interrupts occur frequently enough, the
  1589. timeout interval might never expire.} If no message arrives before the
  1590. timeout interval elapses, then the call returns
  1591. @code{MACH_RCV_TIMED_OUT}. A zero timeout is legitimate.
  1592. @item MACH_RCV_NOTIFY
  1593. The notify argument should specify a receive right for a notify port.
  1594. If receiving the reply port creates a new port right in the caller, then
  1595. the notify port is used to request a dead-name notification for the new
  1596. port right.
  1597. @item MACH_RCV_INTERRUPT
  1598. If specified, the @code{mach_msg} call will return
  1599. @code{MACH_RCV_INTERRUPTED} if a software interrupt aborts the call.
  1600. Otherwise, the receive operation will be retried.
  1601. @item MACH_RCV_LARGE
  1602. If the message is larger than @code{rcv_size}, then the message remains
  1603. queued instead of being destroyed. The call returns
  1604. @code{MACH_RCV_TOO_LARGE} and the actual size of the message is returned
  1605. in the @code{msgh_size} field of the message header.
  1606. @end table
  1607. The receive operation can generate the following return codes. These
  1608. return codes imply that the call did not dequeue a message:
  1609. @table @code
  1610. @item MACH_RCV_INVALID_NAME
  1611. The specified @code{rcv_name} was invalid.
  1612. @item MACH_RCV_IN_SET
  1613. The specified port was a member of a port set.
  1614. @item MACH_RCV_TIMED_OUT
  1615. The timeout interval expired.
  1616. @item MACH_RCV_INTERRUPTED
  1617. A software interrupt occurred.
  1618. @item MACH_RCV_PORT_DIED
  1619. The caller lost the rights specified by @code{rcv_name}.
  1620. @item MACH_RCV_PORT_CHANGED
  1621. @code{rcv_name} specified a receive right which was moved into a port
  1622. set during the call.
  1623. @item MACH_RCV_TOO_LARGE
  1624. When using @code{MACH_RCV_LARGE}, and the message was larger than
  1625. @code{rcv_size}. The message is left queued, and its actual size is
  1626. returned in the @code{msgh_size} field of the message buffer.
  1627. @end table
  1628. These return codes imply that a message was dequeued and destroyed:
  1629. @table @code
  1630. @item MACH_RCV_HEADER_ERROR
  1631. A resource shortage prevented the reception of the port rights in the
  1632. message header.
  1633. @item MACH_RCV_INVALID_NOTIFY
  1634. When using @code{MACH_RCV_NOTIFY}, the notify argument did not denote a
  1635. valid receive right.
  1636. @item MACH_RCV_TOO_LARGE
  1637. When not using @code{MACH_RCV_LARGE}, a message larger than
  1638. @code{rcv_size} was dequeued and destroyed.
  1639. @end table
  1640. In these situations, when a message is dequeued and then destroyed, the
  1641. reply port and all port rights and memory in the message body are
  1642. destroyed. However, the caller receives the message's header, with all
  1643. fields correct, including the destination port but excepting the reply
  1644. port, which is @code{MACH_PORT_NULL}.
  1645. These return codes imply that a message was received:
  1646. @table @code
  1647. @item MACH_RCV_BODY_ERROR
  1648. A resource shortage prevented the reception of a port right or
  1649. out-of-line memory region in the message body. The message header,
  1650. including the reply port, is correct. The kernel attempts to transfer
  1651. all port rights and memory regions in the body, and only destroys those
  1652. that can't be transferred.
  1653. @item MACH_RCV_INVALID_DATA
  1654. The specified message buffer was not writable. The calling task did
  1655. successfully receive the port rights and out-of-line memory regions in
  1656. the message.
  1657. @item MACH_MSG_SUCCESS
  1658. A message was received.
  1659. @end table
  1660. Resource shortages can occur after a message is dequeued, while
  1661. transferring port rights and out-of-line memory regions to the receiving
  1662. task. The @code{mach_msg} call returns @code{MACH_RCV_HEADER_ERROR} or
  1663. @code{MACH_RCV_BODY_ERROR} in this situation. These return codes always
  1664. carry extra bits (bitwise-ored) that indicate the nature of the resource
  1665. shortage:
  1666. @table @code
  1667. @item MACH_MSG_IPC_SPACE
  1668. There was no room in the task's IPC name space for another port name.
  1669. @item MACH_MSG_VM_SPACE
  1670. There was no room in the task's VM address space for an out-of-line
  1671. memory region.
  1672. @item MACH_MSG_IPC_KERNEL
  1673. A kernel resource shortage prevented the reception of a port right.
  1674. @item MACH_MSG_VM_KERNEL
  1675. A kernel resource shortage prevented the reception of an out-of-line
  1676. memory region.
  1677. @end table
  1678. If a resource shortage prevents the reception of a port right, the port
  1679. right is destroyed and the caller sees the name @code{MACH_PORT_NULL}.
  1680. If a resource shortage prevents the reception of an out-of-line memory
  1681. region, the region is destroyed and the caller receives a zero address.
  1682. In addition, the @code{msgt_size} (@code{msgtl_size}) field in the
  1683. data's type descriptor is changed to zero. If a resource shortage
  1684. prevents the reception of out-of-line memory carrying port rights, then
  1685. the port rights are always destroyed if the memory region can not be
  1686. received. A task never receives port rights or memory regions that it
  1687. isn't told about.
  1688. @node Atomicity
  1689. @subsection Atomicity
  1690. The @code{mach_msg} call handles port rights in a message header
  1691. atomically. Port rights and out-of-line memory in a message body do not
  1692. enjoy this atomicity guarantee. The message body may be processed
  1693. front-to-back, back-to-front, first out-of-line memory then port rights,
  1694. in some random order, or even atomically.
  1695. For example, consider sending a message with the destination port
  1696. specified as @code{MACH_MSG_TYPE_MOVE_SEND} and the reply port specified
  1697. as @code{MACH_MSG_TYPE_COPY_SEND}. The same send right, with one
  1698. user-reference, is supplied for both the @code{msgh_remote_port} and
  1699. @code{msgh_local_port} fields. Because @code{mach_msg} processes the
  1700. message header atomically, this succeeds. If @code{msgh_remote_port}
  1701. were processed before @code{msgh_local_port}, then @code{mach_msg} would
  1702. return @code{MACH_SEND_INVALID_REPLY} in this situation.
  1703. On the other hand, suppose the destination and reply port are both
  1704. specified as @code{MACH_MSG_TYPE_MOVE_SEND}, and again the same send
  1705. right with one user-reference is supplied for both. Now the send
  1706. operation fails, but because it processes the header atomically,
  1707. mach_msg can return either @code{MACH_SEND_INVALID_DEST} or
  1708. @code{MACH_SEND_INVALID_REPLY}.
  1709. For example, consider receiving a message at the same time another
  1710. thread is deallocating the destination receive right. Suppose the reply
  1711. port field carries a send right for the destination port. If the
  1712. deallocation happens before the dequeuing, then the receiver gets
  1713. @code{MACH_RCV_PORT_DIED}. If the deallocation happens after the
  1714. receive, then the @code{msgh_local_port} and the @code{msgh_remote_port}
  1715. fields both specify the same right, which becomes a dead name when the
  1716. receive right is deallocated. If the deallocation happens between the
  1717. dequeue and the receive, then the @code{msgh_local_port} and
  1718. @code{msgh_remote_port} fields both specify @code{MACH_PORT_DEAD}.
  1719. Because the header is processed atomically, it is not possible for just
  1720. one of the two fields to hold @code{MACH_PORT_DEAD}.
  1721. The @code{MACH_RCV_NOTIFY} option provides a more likely example.
  1722. Suppose a message carrying a send-once right reply port is received with
  1723. @code{MACH_RCV_NOTIFY} at the same time the reply port is destroyed. If
  1724. the reply port is destroyed first, then @code{msgh_remote_port}
  1725. specifies @code{MACH_PORT_DEAD} and the kernel does not generate a
  1726. dead-name notification. If the reply port is destroyed after it is
  1727. received, then @code{msgh_remote_port} specifies a dead name for which
  1728. the kernel generates a dead-name notification. It is not possible to
  1729. receive the reply port right and have it turn into a dead name before
  1730. the dead-name notification is requested; as part of the message header
  1731. the reply port is received atomically.
  1732. @node Port Manipulation Interface
  1733. @section Port Manipulation Interface
  1734. This section describes the interface to create, destroy and manipulate
  1735. ports, port rights and port sets.
  1736. @cindex IPC space port
  1737. @cindex port representing an IPC space
  1738. @deftp {Data type} ipc_space_t
  1739. This is a @code{task_t} (and as such a @code{mach_port_t}), which holds
  1740. a port name associated with a port that represents an IPC space in the
  1741. kernel. An IPC space is used by the kernel to manage the port names and
  1742. rights available to a task. The IPC space doesn't get a port name of
  1743. its own. Instead the port name of the task containing the IPC space is
  1744. used to name the IPC space of the task (as is indicated by the fact that
  1745. the type of @code{ipc_space_t} is actually @code{task_t}).
  1746. The IPC spaces of tasks are the only ones accessible outside of
  1747. the kernel.
  1748. @end deftp
  1749. @menu
  1750. * Port Creation:: How to create new ports and port sets.
  1751. * Port Destruction:: How to destroy ports and port sets.
  1752. * Port Names:: How to query and manipulate port names.
  1753. * Port Rights:: How to work with port rights.
  1754. * Ports and other Tasks:: How to move rights between tasks.
  1755. * Receive Rights:: How to work with receive rights.
  1756. * Port Sets:: How to work with port sets.
  1757. * Request Notifications:: How to request notifications for events.
  1758. * Inherited Ports:: How to work with the inherited system ports.
  1759. @end menu
  1760. @node Port Creation
  1761. @subsection Port Creation
  1762. @deftypefun kern_return_t mach_port_allocate (@w{ipc_space_t @var{task}}, @w{mach_port_right_t @var{right}}, @w{mach_port_t *@var{name}})
  1763. The @code{mach_port_allocate} function creates a new right in the
  1764. specified task. The new right's name is returned in @var{name}, which
  1765. may be any name that wasn't in use.
  1766. The @var{right} argument takes the following values:
  1767. @table @code
  1768. @item MACH_PORT_RIGHT_RECEIVE
  1769. @code{mach_port_allocate} creates a port. The new port is not a member
  1770. of any port set. It doesn't have any extant send or send-once rights.
  1771. Its make-send count is zero, its sequence number is zero, its queue
  1772. limit is @code{MACH_PORT_QLIMIT_DEFAULT}, and it has no queued messages.
  1773. @var{name} denotes the receive right for the new port.
  1774. @var{task} does not hold send rights for the new port, only the receive
  1775. right. @code{mach_port_insert_right} and @code{mach_port_extract_right}
  1776. can be used to convert the receive right into a combined send/receive
  1777. right.
  1778. @item MACH_PORT_RIGHT_PORT_SET
  1779. @code{mach_port_allocate} creates a port set. The new port set has no
  1780. members.
  1781. @item MACH_PORT_RIGHT_DEAD_NAME
  1782. @code{mach_port_allocate} creates a dead name. The new dead name has
  1783. one user reference.
  1784. @end table
  1785. The function returns @code{KERN_SUCCESS} if the call succeeded,
  1786. @code{KERN_INVALID_TASK} if @var{task} was invalid,
  1787. @code{KERN_INVALID_VALUE} if @var{right} was invalid, @code{KERN_NO_SPACE} if
  1788. there was no room in @var{task}'s IPC name space for another right and
  1789. @code{KERN_RESOURCE_SHORTAGE} if the kernel ran out of memory.
  1790. The @code{mach_port_allocate} call is actually an RPC to @var{task},
  1791. normally a send right for a task port, but potentially any send right.
  1792. In addition to the normal diagnostic return codes from the call's server
  1793. (normally the kernel), the call may return @code{mach_msg} return codes.
  1794. @end deftypefun
  1795. @deftypefun mach_port_t mach_reply_port ()
  1796. The @code{mach_reply_port} system call creates a reply port in the
  1797. calling task.
  1798. @code{mach_reply_port} creates a port, giving the calling task the
  1799. receive right for the port. The call returns the name of the new
  1800. receive right.
  1801. This is very much like creating a receive right with the
  1802. @code{mach_port_allocate} call, with two differences. First,
  1803. @code{mach_reply_port} is a system call and not an RPC (which requires a
  1804. reply port). Second, the port created by @code{mach_reply_port} may be
  1805. optimized for use as a reply port.
  1806. The function returns @code{MACH_PORT_NULL} if a resource shortage
  1807. prevented the creation of the receive right.
  1808. @end deftypefun
  1809. @deftypefun kern_return_t mach_port_allocate_name (@w{ipc_space_t @var{task}}, @w{mach_port_right_t @var{right}}, @w{mach_port_t @var{name}})
  1810. The function @code{mach_port_allocate_name} creates a new right in the
  1811. specified task, with a specified name for the new right. @var{name}
  1812. must not already be in use for some right, and it can't be the reserved
  1813. values @code{MACH_PORT_NULL} and @code{MACH_PORT_DEAD}.
  1814. The @var{right} argument takes the following values:
  1815. @table @code
  1816. @item MACH_PORT_RIGHT_RECEIVE
  1817. @code{mach_port_allocate_name} creates a port. The new port is not a
  1818. member of any port set. It doesn't have any extant send or send-once
  1819. rights. Its make-send count is zero, its sequence number is zero, its
  1820. queue limit is @code{MACH_PORT_QLIMIT_DEFAULT}, and it has no queued
  1821. messages. @var{name} denotes the receive right for the new port.
  1822. @var{task} does not hold send rights for the new port, only the receive
  1823. right. @code{mach_port_insert_right} and @code{mach_port_extract_right}
  1824. can be used to convert the receive right into a combined send/receive
  1825. right.
  1826. @item MACH_PORT_RIGHT_PORT_SET
  1827. @code{mach_port_allocate_name} creates a port set. The new port set has
  1828. no members.
  1829. @item MACH_PORT_RIGHT_DEAD_NAME
  1830. @code{mach_port_allocate_name} creates a new dead name. The new dead
  1831. name has one user reference.
  1832. @end table
  1833. The function returns @code{KERN_SUCCESS} if the call succeeded,
  1834. @code{KERN_INVALID_TASK} if @var{task} was invalid,
  1835. @code{KERN_INVALID_VALUE} if @var{right} was invalid or @var{name} was
  1836. @code{MACH_PORT_NULL} or @code{MACH_PORT_DEAD}, @code{KERN_NAME_EXISTS}
  1837. if @var{name} was already in use for a port right and
  1838. @code{KERN_RESOURCE_SHORTAGE} if the kernel ran out of memory.
  1839. The @code{mach_port_allocate_name} call is actually an RPC to
  1840. @var{task}, normally a send right for a task port, but potentially any
  1841. send right. In addition to the normal diagnostic return codes from the
  1842. call's server (normally the kernel), the call may return @code{mach_msg}
  1843. return codes.
  1844. @end deftypefun
  1845. @node Port Destruction
  1846. @subsection Port Destruction
  1847. @deftypefun kern_return_t mach_port_deallocate (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}})
  1848. The function @code{mach_port_deallocate} releases a user reference for a
  1849. right in @var{task}'s IPC name space. It allows a task to release a
  1850. user reference for a send or send-once right without failing if the port
  1851. has died and the right is now actually a dead name.
  1852. If @var{name} denotes a dead name, send right, or send-once right, then
  1853. the right loses one user reference. If it only had one user reference,
  1854. then the right is destroyed.
  1855. The function returns @code{KERN_SUCCESS} if the call succeeded,
  1856. @code{KERN_INVALID_TASK} if @var{task} was invalid,
  1857. @code{KERN_INVALID_NAME} if @var{name} did not denote a right and
  1858. @code{KERN_INVALID_RIGHT} if @var{name} denoted an invalid right.
  1859. The @code{mach_port_deallocate} call is actually an RPC to
  1860. @var{task}, normally a send right for a task port, but potentially any
  1861. send right. In addition to the normal diagnostic return codes from the
  1862. call's server (normally the kernel), the call may return @code{mach_msg}
  1863. return codes.
  1864. @end deftypefun
  1865. @deftypefun kern_return_t mach_port_destroy (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}})
  1866. The function @code{mach_port_destroy} deallocates all rights denoted by
  1867. a name. The name becomes immediately available for reuse.
  1868. For most purposes, @code{mach_port_mod_refs} and
  1869. @code{mach_port_deallocate} are preferable.
  1870. If @var{name} denotes a port set, then all members of the port set are
  1871. implicitly removed from the port set.
  1872. If @var{name} denotes a receive right that is a member of a port set,
  1873. the receive right is implicitly removed from the port set. If there is
  1874. a port-destroyed request registered for the port, then the receive right
  1875. is not actually destroyed, but instead is sent in a port-destroyed
  1876. notification to the backup port. If there is no registered
  1877. port-destroyed request, remaining messages queued to the port are
  1878. destroyed and extant send and send-once rights turn into dead names. If
  1879. those send and send-once rights have dead-name requests registered, then
  1880. dead-name notifications are generated for them.
  1881. If @var{name} denotes a send-once right, then the send-once right is
  1882. used to produce a send-once notification for the port.
  1883. If @var{name} denotes a send-once, send, and/or receive right, and it
  1884. has a dead-name request registered, then the registered send-once right
  1885. is used to produce a port-deleted notification for the name.
  1886. The function returns @code{KERN_SUCCESS} if the call succeeded,
  1887. @code{KERN_INVALID_TASK} if @var{task} was invalid,
  1888. @code{KERN_INVALID_NAME} if @var{name} did not denote a right.
  1889. The @code{mach_port_destroy} call is actually an RPC to
  1890. @var{task}, normally a send right for a task port, but potentially any
  1891. send right. In addition to the normal diagnostic return codes from the
  1892. call's server (normally the kernel), the call may return @code{mach_msg}
  1893. return codes.
  1894. @end deftypefun
  1895. @node Port Names
  1896. @subsection Port Names
  1897. @deftypefun kern_return_t mach_port_names (@w{ipc_space_t @var{task}}, @w{mach_port_array_t *@var{names}}, @w{mach_msg_type_number_t *@var{ncount}}, @w{mach_port_type_array_t *@var{types}}, @w{mach_msg_type_number_t *@var{tcount}})
  1898. The function @code{mach_port_names} returns information about
  1899. @var{task}'s port name space. For each name, it also returns what type
  1900. of rights @var{task} holds. (The same information returned by
  1901. @code{mach_port_type}.) @var{names} and @var{types} are arrays that are
  1902. automatically allocated when the reply message is received. The user
  1903. should @code{vm_deallocate} them when the data is no longer needed.
  1904. @code{mach_port_names} will return in @var{names} the names of the
  1905. ports, port sets, and dead names in the task's port name space, in no
  1906. particular order and in @var{ncount} the number of names returned. It
  1907. will return in @var{types} the type of each corresponding name, which
  1908. indicates what kind of rights the task holds with that name.
  1909. @var{tcount} should be the same as @var{ncount}.
  1910. The function returns @code{KERN_SUCCESS} if the call succeeded,
  1911. @code{KERN_INVALID_TASK} if @var{task} was invalid,
  1912. @code{KERN_RESOURCE_SHORTAGE} if the kernel ran out of memory.
  1913. The @code{mach_port_names} call is actually an RPC to @var{task},
  1914. normally a send right for a task port, but potentially any send right.
  1915. In addition to the normal diagnostic return codes from the call's server
  1916. (normally the kernel), the call may return @code{mach_msg} return codes.
  1917. @end deftypefun
  1918. @deftypefun kern_return_t mach_port_type (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_port_type_t *@var{ptype}})
  1919. The function @code{mach_port_type} returns information about
  1920. @var{task}'s rights for a specific name in its port name space. The
  1921. returned @var{ptype} is a bitmask indicating what rights @var{task}
  1922. holds for the port, port set or dead name. The bitmask is composed of
  1923. the following bits:
  1924. @table @code
  1925. @item MACH_PORT_TYPE_SEND
  1926. The name denotes a send right.
  1927. @item MACH_PORT_TYPE_RECEIVE
  1928. The name denotes a receive right.
  1929. @item MACH_PORT_TYPE_SEND_ONCE
  1930. The name denotes a send-once right.
  1931. @item MACH_PORT_TYPE_PORT_SET
  1932. The name denotes a port set.
  1933. @item MACH_PORT_TYPE_DEAD_NAME
  1934. The name is a dead name.
  1935. @item MACH_PORT_TYPE_DNREQUEST
  1936. A dead-name request has been registered for the right.
  1937. @item MACH_PORT_TYPE_MAREQUEST
  1938. A msg-accepted request for the right is pending.
  1939. @item MACH_PORT_TYPE_COMPAT
  1940. The port right was created in the compatibility mode.
  1941. @end table
  1942. The function returns @code{KERN_SUCCESS} if the call succeeded,
  1943. @code{KERN_INVALID_TASK} if @var{task} was invalid and
  1944. @code{KERN_INVALID_NAME} if @var{name} did not denote a right.
  1945. The @code{mach_port_type} call is actually an RPC to @var{task},
  1946. normally a send right for a task port, but potentially any send right.
  1947. In addition to the normal diagnostic return codes from the call's server
  1948. (normally the kernel), the call may return @code{mach_msg} return codes.
  1949. @end deftypefun
  1950. @deftypefun kern_return_t mach_port_rename (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{old_name}}, @w{mach_port_t @var{new_name}})
  1951. The function @code{mach_port_rename} changes the name by which a port,
  1952. port set, or dead name is known to @var{task}. @var{old_name} is the
  1953. original name and @var{new_name} the new name for the port right.
  1954. @var{new_name} must not already be in use, and it can't be the
  1955. distinguished values @code{MACH_PORT_NULL} and @code{MACH_PORT_DEAD}.
  1956. The function returns @code{KERN_SUCCESS} if the call succeeded,
  1957. @code{KERN_INVALID_TASK} if @var{task} was invalid,
  1958. @code{KERN_INVALID_NAME} if @var{old_name} did not denote a right,
  1959. @code{KERN_INVALID_VALUE} if @var{new_name} was @code{MACH_PORT_NULL} or
  1960. @code{MACH_PORT_DEAD}, @code{KERN_NAME_EXISTS} if @code{new_name}
  1961. already denoted a right and @code{KERN_RESOURCE_SHORTAGE} if the kernel
  1962. ran out of memory.
  1963. The @code{mach_port_rename} call is actually an RPC to @var{task},
  1964. normally a send right for a task port, but potentially any send right.
  1965. In addition to the normal diagnostic return codes from the call's server
  1966. (normally the kernel), the call may return @code{mach_msg} return codes.
  1967. @end deftypefun
  1968. @node Port Rights
  1969. @subsection Port Rights
  1970. @deftypefun kern_return_t mach_port_get_refs (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_port_right_t @var{right}}, @w{mach_port_urefs_t *@var{refs}})
  1971. The function @code{mach_port_get_refs} returns the number of user
  1972. references a task has for a right.
  1973. The @var{right} argument takes the following values:
  1974. @itemize @bullet
  1975. @item @code{MACH_PORT_RIGHT_SEND}
  1976. @item @code{MACH_PORT_RIGHT_RECEIVE}
  1977. @item @code{MACH_PORT_RIGHT_SEND_ONCE}
  1978. @item @code{MACH_PORT_RIGHT_PORT_SET}
  1979. @item @code{MACH_PORT_RIGHT_DEAD_NAME}
  1980. @end itemize
  1981. If @var{name} denotes a right, but not the type of right specified, then
  1982. zero is returned. Otherwise a positive number of user references is
  1983. returned. Note that a name may simultaneously denote send and receive
  1984. rights.
  1985. The function returns @code{KERN_SUCCESS} if the call succeeded,
  1986. @code{KERN_INVALID_TASK} if @var{task} was invalid,
  1987. @code{KERN_INVALID_VALUE} if @var{right} was invalid and
  1988. @code{KERN_INVALID_NAME} if @var{name} did not denote a right.
  1989. The @code{mach_port_get_refs} call is actually an RPC to @var{task},
  1990. normally a send right for a task port, but potentially any send right.
  1991. In addition to the normal diagnostic return codes from the call's server
  1992. (normally the kernel), the call may return @code{mach_msg} return codes.
  1993. @end deftypefun
  1994. @deftypefun kern_return_t mach_port_mod_refs (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_port_right_t @var{right}}, @w{mach_port_delta_t @var{delta}})
  1995. The function @code{mach_port_mod_refs} requests that the number of user
  1996. references a task has for a right be changed. This results in the right
  1997. being destroyed, if the number of user references is changed to zero.
  1998. The task holding the right is @var{task}, @var{name} should denote the
  1999. specified right. @var{right} denotes the type of right being modified.
  2000. @var{delta} is the signed change to the number of user references.
  2001. The @var{right} argument takes the following values:
  2002. @itemize @bullet
  2003. @item @code{MACH_PORT_RIGHT_SEND}
  2004. @item @code{MACH_PORT_RIGHT_RECEIVE}
  2005. @item @code{MACH_PORT_RIGHT_SEND_ONCE}
  2006. @item @code{MACH_PORT_RIGHT_PORT_SET}
  2007. @item @code{MACH_PORT_RIGHT_DEAD_NAME}
  2008. @end itemize
  2009. The number of user references for the right is changed by the amount
  2010. @var{delta}, subject to the following restrictions: port sets, receive
  2011. rights, and send-once rights may only have one user reference. The
  2012. resulting number of user references can't be negative. If the resulting
  2013. number of user references is zero, the effect is to deallocate the
  2014. right. For dead names and send rights, there is an
  2015. implementation-defined maximum number of user references.
  2016. If the call destroys the right, then the effect is as described for
  2017. @code{mach_port_destroy}, with the exception that
  2018. @code{mach_port_destroy} simultaneously destroys all the rights denoted
  2019. by a name, while @code{mach_port_mod_refs} can only destroy one right.
  2020. The name will be available for reuse if it only denoted the one right.
  2021. The function returns @code{KERN_SUCCESS} if the call succeeded,
  2022. @code{KERN_INVALID_TASK} if @var{task} was invalid,
  2023. @code{KERN_INVALID_VALUE} if @var{right} was invalid or the
  2024. user-reference count would become negative, @code{KERN_INVALID_NAME} if
  2025. @var{name} did not denote a right, @code{KERN_INVALID_RIGHT} if
  2026. @var{name} denoted a right, but not the specified right and
  2027. @code{KERN_UREFS_OVERFLOW} if the user-reference count would overflow.
  2028. The @code{mach_port_mod_refs} call is actually an RPC to @var{task},
  2029. normally a send right for a task port, but potentially any send right.
  2030. In addition to the normal diagnostic return codes from the call's server
  2031. (normally the kernel), the call may return @code{mach_msg} return codes.
  2032. @end deftypefun
  2033. @node Ports and other Tasks
  2034. @subsection Ports and other Tasks
  2035. @deftypefun kern_return_t mach_port_insert_right (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_port_t @var{right}}, @w{mach_msg_type_name_t @var{right_type}})
  2036. The function @var{mach_port_insert_right} inserts into @var{task} the
  2037. caller's right for a port, using a specified name for the right in the
  2038. target task.
  2039. The specified @var{name} can't be one of the reserved values
  2040. @code{MACH_PORT_NULL} or @code{MACH_PORT_DEAD}. The @var{right} can't
  2041. be @code{MACH_PORT_NULL} or @code{MACH_PORT_DEAD}.
  2042. The argument @var{right_type} specifies a right to be inserted and how
  2043. that right should be extracted from the caller. It should be a value
  2044. appropriate for @var{msgt_name}; see @code{mach_msg}. @c XXX cross ref
  2045. If @var{right_type} is @code{MACH_MSG_TYPE_MAKE_SEND},
  2046. @code{MACH_MSG_TYPE_MOVE_SEND}, or @code{MACH_MSG_TYPE_COPY_SEND}, then
  2047. a send right is inserted. If the target already holds send or receive
  2048. rights for the port, then @var{name} should denote those rights in the
  2049. target. Otherwise, @var{name} should be unused in the target. If the
  2050. target already has send rights, then those send rights gain an
  2051. additional user reference. Otherwise, the target gains a send right,
  2052. with a user reference count of one.
  2053. If @var{right_type} is @code{MACH_MSG_TYPE_MAKE_SEND_ONCE} or
  2054. @code{MACH_MSG_TYPE_MOVE_SEND_ONCE}, then a send-once right is inserted.
  2055. The name should be unused in the target. The target gains a send-once
  2056. right.
  2057. If @var{right_type} is @code{MACH_MSG_TYPE_MOVE_RECEIVE}, then a receive
  2058. right is inserted. If the target already holds send rights for the
  2059. port, then name should denote those rights in the target. Otherwise,
  2060. name should be unused in the target. The receive right is moved into
  2061. the target task.
  2062. The function returns @code{KERN_SUCCESS} if the call succeeded,
  2063. @code{KERN_INVALID_TASK} if @var{task} was invalid,
  2064. @code{KERN_INVALID_VALUE} if @var{right} was not a port right or
  2065. @var{name} was @code{MACH_PORT_NULL} or @code{MACH_PORT_DEAD},
  2066. @code{KERN_NAME_EXISTS} if @var{name} already denoted a right,
  2067. @code{KERN_INVALID_CAPABILITY} if @var{right} was @code{MACH_PORT_NULL}
  2068. or @code{MACH_PORT_DEAD} @code{KERN_RIGHT_EXISTS} if @var{task} already
  2069. had rights for the port, with a different name,
  2070. @code{KERN_UREFS_OVERFLOW} if the user-reference count would overflow
  2071. and @code{KERN_RESOURCE_SHORTAGE} if the kernel ran out of memory.
  2072. The @code{mach_port_insert_right} call is actually an RPC to @var{task},
  2073. normally a send right for a task port, but potentially any send right.
  2074. In addition to the normal diagnostic return codes from the call's server
  2075. (normally the kernel), the call may return @code{mach_msg} return codes.
  2076. @end deftypefun
  2077. @deftypefun kern_return_t mach_port_extract_right (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_msg_type_name_t @var{desired_type}}, @w{mach_port_t *@var{right}}, @w{mach_msg_type_name_t *@var{acquired_type}})
  2078. The function @var{mach_port_extract_right} extracts a port right from
  2079. the target @var{task} and returns it to the caller as if the task sent
  2080. the right voluntarily, using @var{desired_type} as the value of
  2081. @var{msgt_name}. @xref{Mach Message Call}.
  2082. The returned value of @var{acquired_type} will be
  2083. @code{MACH_MSG_TYPE_PORT_SEND} if a send right is extracted,
  2084. @code{MACH_MSG_TYPE_PORT_RECEIVE} if a receive right is extracted, and
  2085. @code{MACH_MSG_TYPE_PORT_SEND_ONCE} if a send-once right is extracted.
  2086. The function returns @code{KERN_SUCCESS} if the call succeeded,
  2087. @code{KERN_INVALID_TASK} if @var{task} was invalid,
  2088. @code{KERN_INVALID_NAME} if @var{name} did not denote a right,
  2089. @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but an invalid one,
  2090. @code{KERN_INVALID_VALUE} if @var{desired_type} was invalid.
  2091. The @code{mach_port_extract_right} call is actually an RPC to
  2092. @var{task}, normally a send right for a task port, but potentially any
  2093. send right. In addition to the normal diagnostic return codes from the
  2094. call's server (normally the kernel), the call may return @code{mach_msg}
  2095. return codes.
  2096. @end deftypefun
  2097. @node Receive Rights
  2098. @subsection Receive Rights
  2099. @deftp {Data type} mach_port_seqno_t
  2100. The @code{mach_port_seqno_t} data type is an @code{unsigned int} which
  2101. contains the sequence number of a port.
  2102. @end deftp
  2103. @deftp {Data type} mach_port_mscount_t
  2104. The @code{mach_port_mscount_t} data type is an @code{unsigned int} which
  2105. contains the make-send count for a port.
  2106. @end deftp
  2107. @deftp {Data type} mach_port_msgcount_t
  2108. The @code{mach_port_msgcount_t} data type is an @code{unsigned int} which
  2109. contains a number of messages.
  2110. @end deftp
  2111. @deftp {Data type} mach_port_rights_t
  2112. The @code{mach_port_rights_t} data type is an @code{unsigned int} which
  2113. contains a number of rights for a port.
  2114. @end deftp
  2115. @deftp {Data type} mach_port_status_t
  2116. This structure contains some status information about a port, which can
  2117. be queried with @code{mach_port_get_receive_status}. It has the following
  2118. members:
  2119. @table @code
  2120. @item mach_port_t mps_pset
  2121. The containing port set.
  2122. @item mach_port_seqno_t mps_seqno
  2123. The sequence number.
  2124. @item mach_port_mscount_t mps_mscount
  2125. The make-send count.
  2126. @item mach_port_msgcount_t mps_qlimit
  2127. The maximum number of messages in the queue.
  2128. @item mach_port_msgcount_t mps_msgcount
  2129. The current number of messages in the queue.
  2130. @item mach_port_rights_t mps_sorights
  2131. The number of send-once rights that exist.
  2132. @item boolean_t mps_srights
  2133. @code{TRUE} if send rights exist.
  2134. @item boolean_t mps_pdrequest
  2135. @code{TRUE} if port-deleted notification is requested.
  2136. @item boolean_t mps_nsrequest
  2137. @code{TRUE} if no-senders notification is requested.
  2138. @end table
  2139. @end deftp
  2140. @deftypefun kern_return_t mach_port_get_receive_status (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_port_status_t *@var{status}})
  2141. The function @code{mach_port_get_receive_status} returns the current
  2142. status of the specified receive right.
  2143. The function returns @code{KERN_SUCCESS} if the call succeeded,
  2144. @code{KERN_INVALID_TASK} if @var{task} was invalid,
  2145. @code{KERN_INVALID_NAME} if @var{name} did not denote a right and
  2146. @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but not a
  2147. receive right.
  2148. The @code{mach_port_get_receive_status} call is actually an RPC to @var{task},
  2149. normally a send right for a task port, but potentially any send right.
  2150. In addition to the normal diagnostic return codes from the call's server
  2151. (normally the kernel), the call may return @code{mach_msg} return codes.
  2152. @end deftypefun
  2153. @deftypefun kern_return_t mach_port_set_mscount (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_port_mscount_t @var{mscount}})
  2154. The function @code{mach_port_set_mscount} changes the make-send count of
  2155. @var{task}'s receive right named @var{name} to @var{mscount}. All
  2156. values for @var{mscount} are valid.
  2157. The function returns @code{KERN_SUCCESS} if the call succeeded,
  2158. @code{KERN_INVALID_TASK} if @var{task} was invalid,
  2159. @code{KERN_INVALID_NAME} if @var{name} did not denote a right and
  2160. @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but not a
  2161. receive right.
  2162. The @code{mach_port_set_mscount} call is actually an RPC to @var{task},
  2163. normally a send right for a task port, but potentially any send right.
  2164. In addition to the normal diagnostic return codes from the call's server
  2165. (normally the kernel), the call may return @code{mach_msg} return codes.
  2166. @end deftypefun
  2167. @deftypefun kern_return_t mach_port_set_qlimit (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_port_msgcount_t @var{qlimit}})
  2168. The function @code{mach_port_set_qlimit} changes the queue limit
  2169. @var{task}'s receive right named @var{name} to @var{qlimit}. Valid
  2170. values for @var{qlimit} are between zero and
  2171. @code{MACH_PORT_QLIMIT_MAX}, inclusive.
  2172. The function returns @code{KERN_SUCCESS} if the call succeeded,
  2173. @code{KERN_INVALID_TASK} if @var{task} was invalid,
  2174. @code{KERN_INVALID_NAME} if @var{name} did not denote a right,
  2175. @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but not a
  2176. receive right and @code{KERN_INVALID_VALUE} if @var{qlimit} was invalid.
  2177. The @code{mach_port_set_qlimit} call is actually an RPC to @var{task},
  2178. normally a send right for a task port, but potentially any send right.
  2179. In addition to the normal diagnostic return codes from the call's server
  2180. (normally the kernel), the call may return @code{mach_msg} return codes.
  2181. @end deftypefun
  2182. @deftypefun kern_return_t mach_port_set_seqno (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_port_seqno_t @var{seqno}})
  2183. The function @code{mach_port_set_seqno} changes the sequence number
  2184. @var{task}'s receive right named @var{name} to @var{seqno}. All
  2185. sequence number values are valid. The next message received from the
  2186. port will be stamped with the specified sequence number.
  2187. The function returns @code{KERN_SUCCESS} if the call succeeded,
  2188. @code{KERN_INVALID_TASK} if @var{task} was invalid,
  2189. @code{KERN_INVALID_NAME} if @var{name} did not denote a right and
  2190. @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but not a
  2191. receive right.
  2192. The @code{mach_port_set_seqno} call is actually an RPC to @var{task},
  2193. normally a send right for a task port, but potentially any send right.
  2194. In addition to the normal diagnostic return codes from the call's server
  2195. (normally the kernel), the call may return @code{mach_msg} return codes.
  2196. @end deftypefun
  2197. @deftypefun kern_return_t mach_port_set_protected_payload (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{unsigned long @var{payload}})
  2198. The function @code{mach_port_set_protected_payload} sets the protected
  2199. payload associated with the right @var{name} to @var{payload}.
  2200. Section @ref{Message Receive} describes how setting a protected
  2201. payload affects the messages delivered to @var{name}.
  2202. The function returns @code{KERN_SUCCESS} if the call succeeded,
  2203. @code{KERN_INVALID_TASK} if @var{task} was invalid,
  2204. @code{KERN_INVALID_NAME} if @var{name} did not denote a right and
  2205. @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but not a
  2206. receive right.
  2207. The @code{mach_port_set_protected_payload} call is actually an RPC to
  2208. @var{task}, normally a send right for a task port, but potentially any
  2209. send right. In addition to the normal diagnostic return codes from
  2210. the call's server (normally the kernel), the call may return
  2211. @code{mach_msg} return codes.
  2212. @end deftypefun
  2213. @deftypefun kern_return_t mach_port_clear_protected_payload (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{unsigned long @var{payload}})
  2214. The function @code{mach_port_clear_protected_payload} clears the
  2215. protected payload associated with the right @var{name}.
  2216. The function returns @code{KERN_SUCCESS} if the call succeeded,
  2217. @code{KERN_INVALID_TASK} if @var{task} was invalid,
  2218. @code{KERN_INVALID_NAME} if @var{name} did not denote a right and
  2219. @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but not a
  2220. receive right.
  2221. The @code{mach_port_clear_protected_payload} call is actually an RPC
  2222. to @var{task}, normally a send right for a task port, but potentially
  2223. any send right. In addition to the normal diagnostic return codes
  2224. from the call's server (normally the kernel), the call may return
  2225. @code{mach_msg} return codes.
  2226. @end deftypefun
  2227. @node Port Sets
  2228. @subsection Port Sets
  2229. @deftypefun kern_return_t mach_port_get_set_status (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_port_array_t *@var{members}}, @w{mach_msg_type_number_t *@var{count}})
  2230. The function @code{mach_port_get_set_status} returns the members of a
  2231. port set. @var{members} is an array that is automatically allocated
  2232. when the reply message is received. The user should
  2233. @code{vm_deallocate} it when the data is no longer needed.
  2234. The function returns @code{KERN_SUCCESS} if the call succeeded,
  2235. @code{KERN_INVALID_TASK} if @var{task} was invalid,
  2236. @code{KERN_INVALID_NAME} if @var{name} did not denote a right,
  2237. @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but not a
  2238. receive right and @code{KERN_RESOURCE_SHORTAGE} if the kernel ran out of
  2239. memory.
  2240. The @code{mach_port_get_set_status} call is actually an RPC to
  2241. @var{task}, normally a send right for a task port, but potentially any
  2242. send right. In addition to the normal diagnostic return codes from the
  2243. call's server (normally the kernel), the call may return @code{mach_msg}
  2244. return codes.
  2245. @end deftypefun
  2246. @deftypefun kern_return_t mach_port_move_member (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{member}}, @w{mach_port_t @var{after}})
  2247. The function @var{mach_port_move_member} moves the receive right
  2248. @var{member} into the port set @var{after}. If the receive right is
  2249. already a member of another port set, it is removed from that set first
  2250. (the whole operation is atomic). If the port set is
  2251. @code{MACH_PORT_NULL}, then the receive right is not put into a port
  2252. set, but removed from its current port set.
  2253. The function returns @code{KERN_SUCCESS} if the call succeeded,
  2254. @code{KERN_INVALID_TASK} if @var{task} was invalid,
  2255. @code{KERN_INVALID_NAME} if @var{member} or @var{after} did not denote a
  2256. right, @code{KERN_INVALID_RIGHT} if @var{member} denoted a right, but
  2257. not a receive right or @var{after} denoted a right, but not a port set,
  2258. and @code{KERN_NOT_IN_SET} if @var{after} was @code{MACH_PORT_NULL}, but
  2259. @code{member} wasn't currently in a port set.
  2260. The @code{mach_port_move_member} call is actually an RPC to @var{task},
  2261. normally a send right for a task port, but potentially any send right.
  2262. In addition to the normal diagnostic return codes from the call's server
  2263. (normally the kernel), the call may return @code{mach_msg} return codes.
  2264. @end deftypefun
  2265. @node Request Notifications
  2266. @subsection Request Notifications
  2267. @deftypefun kern_return_t mach_port_request_notification (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_msg_id_t @var{variant}}, @w{mach_port_mscount_t @var{sync}}, @w{mach_port_t @var{notify}}, @w{mach_msg_type_name_t @var{notify_type}}, @w{mach_port_t *@var{previous}})
  2268. The function @code{mach_port_request_notification} registers a request
  2269. for a notification and supplies the send-once right @var{notify} to
  2270. which the notification will be sent. The @var{notify_type} denotes the
  2271. IPC type for the send-once right, which can be
  2272. @code{MACH_MSG_TYPE_MAKE_SEND_ONCE} or
  2273. @code{MACH_MSG_TYPE_MOVE_SEND_ONCE}. It is an atomic swap, returning
  2274. the previously registered send-once right (or @code{MACH_PORT_NULL} for
  2275. none) in @var{previous}. A previous notification request may be
  2276. cancelled by providing @code{MACH_PORT_NULL} for @var{notify}.
  2277. The @var{variant} argument takes the following values:
  2278. @table @code
  2279. @item MACH_NOTIFY_PORT_DESTROYED
  2280. @var{sync} must be zero. The @var{name} must specify a receive right,
  2281. and the call requests a port-destroyed notification for the receive
  2282. right. If the receive right were to have been destroyed, say by
  2283. @code{mach_port_destroy}, then instead the receive right will be sent in
  2284. a port-destroyed notification to the registered send-once right.
  2285. @item MACH_NOTIFY_DEAD_NAME
  2286. The call requests a dead-name notification. @var{name} specifies send,
  2287. receive, or send-once rights for a port. If the port is destroyed (and
  2288. the right remains, becoming a dead name), then a dead-name notification
  2289. which carries the name of the right will be sent to the registered
  2290. send-once right. If @var{notify} is not null and sync is non-zero, the
  2291. name may specify a dead name, and a dead-name notification is
  2292. immediately generated.
  2293. Whenever a dead-name notification is generated, the user reference count
  2294. of the dead name is incremented. For example, a send right with two
  2295. user refs has a registered dead-name request. If the port is destroyed,
  2296. the send right turns into a dead name with three user refs (instead of
  2297. two), and a dead-name notification is generated.
  2298. If the name is made available for reuse, perhaps because of
  2299. @code{mach_port_destroy} or @code{mach_port_mod_refs}, or the name
  2300. denotes a send-once right which has a message sent to it, then the
  2301. registered send-once right is used to generate a port-deleted
  2302. notification.
  2303. @item MACH_NOTIFY_NO_SENDERS
  2304. The call requests a no-senders notification. @var{name} must specify a
  2305. receive right. If @var{notify} is not null, and the receive right's
  2306. make-send count is greater than or equal to the sync value, and it has
  2307. no extant send rights, than an immediate no-senders notification is
  2308. generated. Otherwise the notification is generated when the receive
  2309. right next loses its last extant send right. In either case, any
  2310. previously registered send-once right is returned.
  2311. The no-senders notification carries the value the port's make-send count
  2312. had when it was generated. The make-send count is incremented whenever
  2313. @code{MACH_MSG_TYPE_MAKE_SEND} is used to create a new send right from
  2314. the receive right. The make-send count is reset to zero when the
  2315. receive right is carried in a message.
  2316. @end table
  2317. The function returns @code{KERN_SUCCESS} if the call succeeded,
  2318. @code{KERN_INVALID_TASK} if @var{task} was invalid,
  2319. @code{KERN_INVALID_VALUE} if @var{variant} was invalid,
  2320. @code{KERN_INVALID_NAME} if @var{name} did not denote a right,
  2321. @code{KERN_INVALID_RIGHT} if @var{name} denoted an invalid right and
  2322. @code{KERN_INVALID_CAPABILITY} if @var{notify} was invalid.
  2323. When using @code{MACH_NOTIFY_PORT_DESTROYED}, the function returns
  2324. @code{KERN_INVALID_VALUE} if @var{sync} wasn't zero.
  2325. When using @code{MACH_NOTIFY_DEAD_NAME}, the function returns
  2326. @code{KERN_RESOURCE_SHORTAGE} if the kernel ran out of memory,
  2327. @code{KERN_INVALID_ARGUMENT} if @var{name} denotes a dead name, but
  2328. @var{sync} is zero or @var{notify} is @code{MACH_PORT_NULL}, and
  2329. @code{KERN_UREFS_OVERFLOW} if @var{name} denotes a dead name, but
  2330. generating an immediate dead-name notification would overflow the name's
  2331. user-reference count.
  2332. The @code{mach_port_request_notification} call is actually an RPC to
  2333. @var{task}, normally a send right for a task port, but potentially any
  2334. send right. In addition to the normal diagnostic return codes from the
  2335. call's server (normally the kernel), the call may return @code{mach_msg}
  2336. return codes.
  2337. @end deftypefun
  2338. @node Inherited Ports
  2339. @subsection Inherited Ports
  2340. The inherited ports concept is not used in the Hurd, and so the _SLOT
  2341. macros are not defined in GNU Mach.
  2342. The following section documents how @code{mach_ports_register} and
  2343. @code{mach_ports_lookup} were originally intended to be used.
  2344. @deftypefun kern_return_t mach_ports_register (@w{task_t @var{target_task}}, @w{port_array_t @var{init_port_set}}, @w{int @var{init_port_array_count}})
  2345. @deftypefunx kern_return_t mach_ports_lookup (@w{task_t @var{target_task}}, @w{port_array_t *@var{init_port_set}}, @w{int *@var{init_port_array_count}})
  2346. @code{mach_ports_register} manipulates the inherited ports array,
  2347. @code{mach_ports_lookup} is used to acquire specific parent ports.
  2348. @var{target_task} is the task to be affected. @var{init_port_set} is an
  2349. array of system ports to be registered, or returned. Although the array
  2350. size is given as variable, the kernel will only accept a limited number
  2351. of ports. @var{init_port_array_count} is the number of ports returned
  2352. in @var{init_port_set}.
  2353. @code{mach_ports_register} registers an array of well-known system ports
  2354. with the kernel on behalf of a specific task. Currently the ports to be
  2355. registered are: the port to the Network Name Server, the port to the
  2356. Environment Manager, and a port to the Service server. These port
  2357. values must be placed in specific slots in the init_port_set. The slot
  2358. numbers are given by the global constants defined in @file{mach_init.h}:
  2359. @code{NAME_SERVER_SLOT}, @code{ENVIRONMENT_SLOT}, and
  2360. @code{SERVICE_SLOT}. These ports may later be retrieved with
  2361. @code{mach_ports_lookup}.
  2362. When a new task is created (see @code{task_create}), the child task will
  2363. be given access to these ports. Only port send rights may be
  2364. registered. Furthermore, the number of ports which may be registered is
  2365. fixed and given by the global constant @code{MACH_PORT_SLOTS_USED}
  2366. Attempts to register too many ports will fail.
  2367. It is intended that this mechanism be used only for task initialization,
  2368. and then only by runtime support modules. A parent task has three
  2369. choices in passing these system ports to a child task. Most commonly it
  2370. can do nothing and its child will inherit access to the same
  2371. @var{init_port_set} that the parent has; or a parent task may register a
  2372. set of ports it wishes to have passed to all of its children by calling
  2373. @code{mach_ports_register} using its task port; or it may make necessary
  2374. modifications to the set of ports it wishes its child to see, and then
  2375. register those ports using the child's task port prior to starting the
  2376. child's thread(s). The @code{mach_ports_lookup} call which is done by
  2377. @code{mach_init} in the child task will acquire these initial ports for
  2378. the child.
  2379. Tasks other than the Network Name Server and the Environment Manager
  2380. should not need access to the Service port. The Network Name Server port
  2381. is the same for all tasks on a given machine. The Environment port is
  2382. the only port likely to have different values for different tasks.
  2383. Since the number of ports which may be registered is limited, ports
  2384. other than those used by the runtime system to initialize a task should
  2385. be passed to children either through an initial message, or through the
  2386. Network Name Server for public ports, or the Environment Manager for
  2387. private ports.
  2388. The function returns @code{KERN_SUCCESS} if the memory was allocated,
  2389. and @code{KERN_INVALID_ARGUMENT} if an attempt was made to register more
  2390. ports than the current kernel implementation allows.
  2391. @end deftypefun
  2392. @node Virtual Memory Interface
  2393. @chapter Virtual Memory Interface
  2394. @cindex virtual memory map port
  2395. @cindex port representing a virtual memory map
  2396. @deftp {Data type} vm_task_t
  2397. This is a @code{task_t} (and as such a @code{mach_port_t}), which holds
  2398. a port name associated with a port that represents a virtual memory map
  2399. in the kernel. An virtual memory map is used by the kernel to manage
  2400. the address space of a task. The virtual memory map doesn't get a port
  2401. name of its own. Instead the port name of the task provided with the
  2402. virtual memory is used to name the virtual memory map of the task (as is
  2403. indicated by the fact that the type of @code{vm_task_t} is actually
  2404. @code{task_t}).
  2405. The virtual memory maps of tasks are the only ones accessible outside of
  2406. the kernel.
  2407. @end deftp
  2408. @menu
  2409. * Memory Allocation:: Allocation of new virtual memory.
  2410. * Memory Deallocation:: Freeing unused virtual memory.
  2411. * Data Transfer:: Reading, writing and copying memory.
  2412. * Memory Attributes:: Tweaking memory regions.
  2413. * Mapping Memory Objects:: How to map memory objects.
  2414. * Memory Statistics:: How to get statistics about memory usage.
  2415. @end menu
  2416. @node Memory Allocation
  2417. @section Memory Allocation
  2418. @deftypefun kern_return_t vm_allocate (@w{vm_task_t @var{target_task}}, @w{vm_address_t *@var{address}}, @w{vm_size_t @var{size}}, @w{boolean_t @var{anywhere}})
  2419. The function @code{vm_allocate} allocates a region of virtual memory,
  2420. placing it in the specified @var{task}'s address space.
  2421. The starting address is @var{address}. If the @var{anywhere} option is
  2422. false, an attempt is made to allocate virtual memory starting at this
  2423. virtual address. If this address is not at the beginning of a virtual
  2424. page, it will be rounded down to one. If there is not enough space at
  2425. this address, no memory will be allocated. If the @var{anywhere} option
  2426. is true, the input value of this address will be ignored, and the space
  2427. will be allocated wherever it is available. In either case, the address
  2428. at which memory was actually allocated will be returned in
  2429. @var{address}.
  2430. @var{size} is the number of bytes to allocate (rounded by the system in
  2431. a machine dependent way to an integral number of virtual pages).
  2432. If @var{anywhere} is true, the kernel should find and allocate any
  2433. region of the specified size, and return the address of the resulting
  2434. region in address address, rounded to a virtual page boundary if there
  2435. is sufficient space.
  2436. The physical memory is not actually allocated until the new virtual
  2437. memory is referenced. By default, the kernel rounds all addresses down
  2438. to the nearest page boundary and all memory sizes up to the nearest page
  2439. size. The global variable @code{vm_page_size} contains the page size.
  2440. @code{mach_task_self} returns the value of the current task port which
  2441. should be used as the @var{target_task} argument in order to allocate
  2442. memory in the caller's address space. For languages other than C, these
  2443. values can be obtained by the calls @code{vm_statistics} and
  2444. @code{mach_task_self}. Initially, the pages of allocated memory will be
  2445. protected to allow all forms of access, and will be inherited in child
  2446. tasks as a copy. Subsequent calls to @code{vm_protect} and
  2447. @code{vm_inherit} may be used to change these properties. The allocated
  2448. region is always zero-filled.
  2449. The function returns @code{KERN_SUCCESS} if the memory was successfully
  2450. allocated, @code{KERN_INVALID_ADDRESS} if an invalid address was
  2451. specified and @code{KERN_NO_SPACE} if there was not enough space left to
  2452. satisfy the request.
  2453. @end deftypefun
  2454. @node Memory Deallocation
  2455. @section Memory Deallocation
  2456. @deftypefun kern_return_t vm_deallocate (@w{vm_task_t @var{target_task}}, @w{vm_address_t @var{address}}, @w{vm_size_t @var{size}})
  2457. @code{vm_deallocate} relinquishes access to a region of a @var{task}'s
  2458. address space, causing further access to that memory to fail. This
  2459. address range will be available for reallocation. @var{address} is the
  2460. starting address, which will be rounded down to a page boundary.
  2461. @var{size} is the number of bytes to deallocate, which will be rounded
  2462. up to give a page boundary. Note, that because of the rounding to
  2463. virtual page boundaries, more than @var{size} bytes may be deallocated.
  2464. Use @code{vm_page_size} or @code{vm_statistics} to find out the current
  2465. virtual page size.
  2466. This call may be used to deallocate memory that was passed to a task in a
  2467. message (via out of line data). In that case, the rounding should cause
  2468. no trouble, since the region of memory was allocated as a set of pages.
  2469. The @code{vm_deallocate} call affects only the task specified by the
  2470. @var{target_task}. Other tasks which may have access to this memory may
  2471. continue to reference it.
  2472. The function returns @code{KERN_SUCCESS} if the memory was successfully
  2473. deallocated and @code{KERN_INVALID_ADDRESS} if an invalid or
  2474. non-allocated address was specified.
  2475. @end deftypefun
  2476. @node Data Transfer
  2477. @section Data Transfer
  2478. @deftypefun kern_return_t vm_read (@w{vm_task_t @var{target_task}}, @w{vm_address_t @var{address}}, @w{vm_size_t @var{size}}, @w{vm_offset_t *@var{data}}, @w{mach_msg_type_number_t *@var{data_count}})
  2479. The function @code{vm_read} allows one task's virtual memory to be read
  2480. by another task. The @var{target_task} is the task whose memory is to
  2481. be read. @var{address} is the first address to be read and must be on a
  2482. page boundary. @var{size} is the number of bytes of data to be read and
  2483. must be an integral number of pages. @var{data} is the array of data
  2484. copied from the given task, and @var{data_count} is the size of the data
  2485. array in bytes (will be an integral number of pages).
  2486. Note that the data array is returned in a newly allocated region; the
  2487. task reading the data should @code{vm_deallocate} this region when it is
  2488. done with the data.
  2489. The function returns @code{KERN_SUCCESS} if the memory was successfully
  2490. read, @code{KERN_INVALID_ADDRESS} if an invalid or non-allocated address
  2491. was specified or there was not @var{size} bytes of data following the
  2492. address, @code{KERN_INVALID_ARGUMENT} if the address does not start on a
  2493. page boundary or the size is not an integral number of pages,
  2494. @code{KERN_PROTECTION_FAILURE} if the address region in the target task
  2495. is protected against reading and @code{KERN_NO_SPACE} if there was not
  2496. enough room in the callers virtual memory to allocate space for the data
  2497. to be returned.
  2498. @end deftypefun
  2499. @deftypefun kern_return_t vm_write (@w{vm_task_t @var{target_task}}, @w{vm_address_t @var{address}}, @w{vm_offset_t @var{data}}, @w{mach_msg_type_number_t @var{data_count}})
  2500. The function @code{vm_write} allows a task to write to the virtual memory
  2501. of @var{target_task}. @var{address} is the starting address in task to
  2502. be affected. @var{data} is an array of bytes to be written, and
  2503. @var{data_count} the size of the @var{data} array.
  2504. The current implementation requires that @var{address}, @var{data} and
  2505. @var{data_count} all be page-aligned. Otherwise,
  2506. @code{KERN_INVALID_ARGUMENT} is returned.
  2507. The function returns @code{KERN_SUCCESS} if the memory was successfully
  2508. written, @code{KERN_INVALID_ADDRESS} if an invalid or non-allocated
  2509. address was specified or there was not @var{data_count} bytes of
  2510. allocated memory starting at @var{address} and
  2511. @code{KERN_PROTECTION_FAILURE} if the address region in the target task
  2512. is protected against writing.
  2513. @end deftypefun
  2514. @deftypefun kern_return_t vm_copy (@w{vm_task_t @var{target_task}}, @w{vm_address_t @var{source_address}}, @w{vm_size_t @var{count}}, @w{vm_offset_t @var{dest_address}})
  2515. The function @code{vm_copy} causes the source memory range to be copied
  2516. to the destination address. The source and destination memory ranges
  2517. may overlap. The destination address range must already be allocated
  2518. and writable; the source range must be readable.
  2519. @code{vm_copy} is equivalent to @code{vm_read} followed by
  2520. @code{vm_write}.
  2521. The current implementation requires that @var{address}, @var{data} and
  2522. @var{data_count} all be page-aligned. Otherwise,
  2523. @code{KERN_INVALID_ARGUMENT} is returned.
  2524. The function returns @code{KERN_SUCCESS} if the memory was successfully
  2525. written, @code{KERN_INVALID_ADDRESS} if an invalid or non-allocated
  2526. address was specified or there was insufficient memory allocated at one
  2527. of the addresses and @code{KERN_PROTECTION_FAILURE} if the destination
  2528. region was not writable or the source region was not readable.
  2529. @end deftypefun
  2530. @node Memory Attributes
  2531. @section Memory Attributes
  2532. @deftypefun kern_return_t vm_region (@w{vm_task_t @var{target_task}}, @w{vm_address_t *@var{address}}, @w{vm_size_t *@var{size}}, @w{vm_prot_t *@var{protection}}, @w{vm_prot_t *@var{max_protection}}, @w{vm_inherit_t *@var{inheritance}}, @w{boolean_t *@var{shared}}, @w{memory_object_name_t *@var{object_name}}, @w{vm_offset_t *@var{offset}})
  2533. The function @code{vm_region} returns a description of the specified
  2534. region of @var{target_task}'s virtual address space. @code{vm_region}
  2535. begins at @var{address} and looks forward through memory until it comes
  2536. to an allocated region. If address is within a region, then that region
  2537. is used. Various bits of information about the region are returned. If
  2538. @var{address} was not within a region, then @var{address} is set to the
  2539. start of the first region which follows the incoming value. In this way
  2540. an entire address space can be scanned.
  2541. The @var{size} returned is the size of the located region in bytes.
  2542. @var{protection} is the current protection of the region,
  2543. @var{max_protection} is the maximum allowable protection for this
  2544. region. @var{inheritance} is the inheritance attribute for this region.
  2545. @var{shared} tells if the region is shared or not. The port
  2546. @var{object_name} identifies the memory object associated with this
  2547. region, and @var{offset} is the offset into the pager object that this
  2548. region begins at.
  2549. @c XXX cross ref pager_init
  2550. The function returns @code{KERN_SUCCESS} if the memory region was
  2551. successfully located and the information returned and @code{KERN_NO_SPACE} if
  2552. there is no region at or above @var{address} in the specified task.
  2553. @end deftypefun
  2554. @deftypefun kern_return_t vm_protect (@w{vm_task_t @var{target_task}}, @w{vm_address_t @var{address}}, @w{vm_size_t @var{size}}, @w{boolean_t @var{set_maximum}}, @w{vm_prot_t @var{new_protection}})
  2555. The function @code{vm_protect} sets the virtual memory access privileges
  2556. for a range of allocated addresses in @var{target_task}'s virtual
  2557. address space. The protection argument describes a combination of read,
  2558. write, and execute accesses that should be @emph{permitted}.
  2559. @var{address} is the starting address, which will be rounded down to a
  2560. page boundary. @var{size} is the size in bytes of the region for which
  2561. protection is to change, and will be rounded up to give a page boundary.
  2562. If @var{set_maximum} is set, make the protection change apply to the
  2563. maximum protection associated with this address range; otherwise, the
  2564. current protection on this range is changed. If the maximum protection
  2565. is reduced below the current protection, both will be changed to reflect
  2566. the new maximum. @var{new_protection} is the new protection value for
  2567. this region; a set of: @code{VM_PROT_READ}, @code{VM_PROT_WRITE},
  2568. @code{VM_PROT_EXECUTE}.
  2569. The enforcement of virtual memory protection is machine-dependent.
  2570. Nominally read access requires @code{VM_PROT_READ} permission, write
  2571. access requires @code{VM_PROT_WRITE} permission, and execute access
  2572. requires @code{VM_PROT_EXECUTE} permission. However, some combinations
  2573. of access rights may not be supported. In particular, the kernel
  2574. interface allows write access to require @code{VM_PROT_READ} and
  2575. @code{VM_PROT_WRITE} permission and execute access to require
  2576. @code{VM_PROT_READ} permission.
  2577. If a region is wired, changing its protection also updates the
  2578. access types for which no page faults must occur.
  2579. The function returns @code{KERN_SUCCESS} if the memory was successfully
  2580. protected, @code{KERN_INVALID_ADDRESS} if an invalid or non-allocated
  2581. address was specified and @code{KERN_PROTECTION_FAILURE} if an attempt
  2582. was made to increase the current or maximum protection beyond the
  2583. existing maximum protection value.
  2584. @end deftypefun
  2585. @deftypefun kern_return_t vm_inherit (@w{vm_task_t @var{target_task}}, @w{vm_address_t @var{address}}, @w{vm_size_t @var{size}}, @w{vm_inherit_t @var{new_inheritance}})
  2586. The function @code{vm_inherit} specifies how a region of
  2587. @var{target_task}'s address space is to be passed to child tasks at the
  2588. time of task creation. Inheritance is an attribute of virtual pages, so
  2589. @var{address} to start from will be rounded down to a page boundary and
  2590. @var{size}, the size in bytes of the region for which inheritance is to
  2591. change, will be rounded up to give a page boundary. How this memory is
  2592. to be inherited in child tasks is specified by @var{new_inheritance}.
  2593. Inheritance is specified by using one of these following three values:
  2594. @table @code
  2595. @item VM_INHERIT_SHARE
  2596. Child tasks will share this memory with this task.
  2597. @item VM_INHERIT_COPY
  2598. Child tasks will receive a copy of this region.
  2599. @item VM_INHERIT_NONE
  2600. This region will be absent from child tasks.
  2601. @end table
  2602. Setting @code{vm_inherit} to @code{VM_INHERIT_SHARE} and forking a child
  2603. task is the only way two Mach tasks can share physical memory. Remember
  2604. that all the threads of a given task share all the same memory.
  2605. The function returns @code{KERN_SUCCESS} if the memory inheritance was
  2606. successfully set and @code{KERN_INVALID_ADDRESS} if an invalid or
  2607. non-allocated address was specified.
  2608. @end deftypefun
  2609. @deftypefun kern_return_t vm_wire (@w{host_t @var{host}}, @w{vm_task_t @var{target_task}}, @w{vm_address_t @var{address}}, @w{vm_size_t @var{size}}, @w{vm_prot_t @var{access}})
  2610. The function @code{vm_wire} allows applications to control
  2611. memory pageability. @var{host} is the host port for the
  2612. host on which @var{target_task} resides. @var{address} is the starting
  2613. address, which will be rounded down to a page boundary. @var{size} is
  2614. the size in bytes of the region for which protection is to change, and
  2615. will be rounded up to give a page boundary. @var{access} specifies the
  2616. types of accesses that must not cause page faults. If the host port is
  2617. not privileged, the amount of memory is limited per task.
  2618. The semantics of a successful @code{vm_wire} operation are that memory
  2619. in the specified range will not cause page faults for any accesses
  2620. included in access. Data memory can be made non-pageable (wired) with a
  2621. access argument of @code{VM_PROT_READ | VM_PROT_WRITE}. A special case
  2622. is that @code{VM_PROT_NONE} makes the memory pageable.
  2623. Wiring doesn't stack, i.e. a single call to @code{vm_wire} with
  2624. @var{access} @code{VM_PROT_NONE} unwires the specified range,
  2625. regardless of how many times it was previously wired. Conversely,
  2626. a single call to @code{vm_wire} with @var{access}
  2627. @code{VM_PROT_READ | VM_PROT_WRITE} wires the specified range,
  2628. regardless of how many times it was previously unwired.
  2629. The function returns @code{KERN_SUCCESS} if the call succeeded,
  2630. @code{KERN_INVALID_HOST} if @var{host} was not a valid host
  2631. port, @code{KERN_INVALID_TASK} if @var{task} was not a valid task,
  2632. @code{KERN_INVALID_VALUE} if @var{access} specified an invalid access
  2633. mode, and @code{KERN_NO_SPACE} if some memory in the specified range
  2634. is not present or has an inappropriate protection value.
  2635. The @code{vm_wire} call is actually an RPC to @var{host}, normally
  2636. a send right for a privileged host port, but potentially any send right.
  2637. In addition to the normal diagnostic return codes from the call's server
  2638. (normally the kernel), the call may return @code{mach_msg} return codes.
  2639. @end deftypefun
  2640. @deftypefun kern_return_t vm_wire_all (@w{host_t @var{host}}, @w{vm_task_t @var{target_task}}, @w{vm_wire_t @var{flags}})
  2641. The function @code{vm_wire_all} allows applications to control
  2642. memory pageability, as with @code{vm_wire}, but applies to all
  2643. current and/or future mappings.
  2644. The argument @var{flags} are bit values, combined with bitwise-or.
  2645. @table @code
  2646. @item VM_WIRE_CURRENT
  2647. All currently existing entries are wired, with access types matching
  2648. their protection.
  2649. @item VM_WIRE_FUTURE
  2650. All future entries are automatically wired, with access types matching
  2651. their protection.
  2652. @end table
  2653. If flags specifies no bits (@code{VM_WIRE_NONE}), all current entries
  2654. are unwired, and future entries are no longer automatically wired.
  2655. The function returns @code{KERN_SUCCESS} if the call succeeded,
  2656. @code{KERN_INVALID_HOST} if @var{host} was not a valid host port,
  2657. @code{KERN_INVALID_TASK} if @var{task} was not a valid task,
  2658. and @code{KERN_INVALID_VALUE} if @var{flags} specifies invalid bits.
  2659. The @code{vm_wire_all} call is actually an RPC to @var{host}, normally
  2660. a send right for a privileged host port, but potentially any send right.
  2661. In addition to the normal diagnostic return codes from the call's server
  2662. (normally the kernel), the call may return @code{mach_msg} return codes.
  2663. @end deftypefun
  2664. @deftypefun kern_return_t vm_machine_attribute (@w{vm_task_t @var{task}}, @w{vm_address_t @var{address}}, @w{vm_size_t @var{size}}, @w{vm_prot_t @var{access}}, @w{vm_machine_attribute_t @var{attribute}}, @w{vm_machine_attribute_val_t @var{value}})
  2665. The function @code{vm_machine_attribute} specifies machine-specific
  2666. attributes for a VM mapping, such as cachability, migrability,
  2667. replicability. This is used on machines that allow the user control
  2668. over the cache (this is the case for MIPS architectures) or placement of
  2669. memory pages as in NUMA architectures (Non-Uniform Memory Access time)
  2670. such as the IBM ACE multiprocessor.
  2671. Machine-specific attributes can be consider additions to the
  2672. machine-independent ones such as protection and inheritance, but they
  2673. are not guaranteed to be supported by any given machine. Moreover,
  2674. implementations of Mach on new architectures might find the need for new
  2675. attribute types and or values besides the ones defined in the initial
  2676. implementation.
  2677. The types currently defined are
  2678. @table @code
  2679. @item MATTR_CACHE
  2680. Controls caching of memory pages
  2681. @item MATTR_MIGRATE
  2682. Controls migrability of memory pages
  2683. @item MATTR_REPLICATE
  2684. Controls replication of memory pages
  2685. @end table
  2686. Corresponding values, and meaning of a specific call to
  2687. @code{vm_machine_attribute}
  2688. @table @code
  2689. @item MATTR_VAL_ON
  2690. Enables the attribute. Being enabled is the default value for any
  2691. applicable attribute.
  2692. @item MATTR_VAL_OFF
  2693. Disables the attribute, making memory non-cached, or non-migratable, or
  2694. non-replicatable.
  2695. @item MATTR_VAL_GET
  2696. Returns the current value of the attribute for the memory segment. If
  2697. the attribute does not apply uniformly to the given range the value
  2698. returned applies to the initial portion of the segment only.
  2699. @item MATTR_VAL_CACHE_FLUSH
  2700. Flush the memory pages from the Cache. The size value in this case
  2701. might be meaningful even if not a multiple of the page size, depending
  2702. on the implementation.
  2703. @item MATTR_VAL_ICACHE_FLUSH
  2704. Same as above, applied to the Instruction Cache alone.
  2705. @item MATTR_VAL_DCACHE_FLUSH
  2706. Same as above, applied to the Data Cache alone.
  2707. @end table
  2708. The function returns @code{KERN_SUCCESS} if call succeeded, and
  2709. @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task, or
  2710. @var{address} and @var{size} do not define a valid address range in
  2711. task, or @var{attribute} is not a valid attribute type, or it is not
  2712. implemented, or @var{value} is not a permissible value for attribute.
  2713. @end deftypefun
  2714. @node Mapping Memory Objects
  2715. @section Mapping Memory Objects
  2716. @deftypefun kern_return_t vm_map (@w{vm_task_t @var{target_task}}, @w{vm_address_t *@var{address}}, @w{vm_size_t @var{size}}, @w{vm_address_t @var{mask}}, @w{boolean_t @var{anywhere}}, @w{memory_object_t @var{memory_object}}, @w{vm_offset_t @var{offset}}, @w{boolean_t @var{copy}}, @w{vm_prot_t @var{cur_protection}}, @w{vm_prot_t @var{max_protection}}, @w{vm_inherit_t @var{inheritance}})
  2717. The function @code{vm_map} maps a region of virtual memory at the
  2718. specified address, for which data is to be supplied by the given memory
  2719. object, starting at the given offset within that object. In addition to
  2720. the arguments used in @code{vm_allocate}, the @code{vm_map} call allows
  2721. the specification of an address alignment parameter, and of the initial
  2722. protection and inheritance values.
  2723. @c XXX See the descriptions of vm_allocate, vm_protect , and vm_inherit
  2724. If the memory object in question is not currently in use, the kernel
  2725. will perform a @code{memory_object_init} call at this time. If the copy
  2726. parameter is asserted, the specified region of the memory object will be
  2727. copied to this address space; changes made to this object by other tasks
  2728. will not be visible in this mapping, and changes made in this mapping
  2729. will not be visible to others (or returned to the memory object).
  2730. The @code{vm_map} call returns once the mapping is established.
  2731. Completion of the call does not require any action on the part of the
  2732. memory manager.
  2733. Warning: Only memory objects that are provided by bona fide memory
  2734. managers should be used in the @code{vm_map} call. A memory manager
  2735. must implement the memory object interface described elsewhere in this
  2736. manual. If other ports are used, a thread that accesses the mapped
  2737. virtual memory may become permanently hung or may receive a memory
  2738. exception.
  2739. @var{target_task} is the task to be affected. The starting address is
  2740. @var{address}. If the @var{anywhere} option is used, this address is
  2741. ignored. The address actually allocated will be returned in
  2742. @var{address}. @var{size} is the number of bytes to allocate (rounded by
  2743. the system in a machine dependent way). The alignment restriction is
  2744. specified by @var{mask}. Bits asserted in this mask must not be
  2745. asserted in the address returned. If @var{anywhere} is set, the kernel
  2746. should find and allocate any region of the specified size, and return
  2747. the address of the resulting region in @var{address}.
  2748. @var{memory_object} is the port that represents the memory object: used
  2749. by user tasks in @code{vm_map}; used by the make requests for data or
  2750. other management actions. If this port is @code{MEMORY_OBJECT_NULL},
  2751. then zero-filled memory is allocated instead. Within a memory object,
  2752. @var{offset} specifies an offset in bytes. This must be page aligned.
  2753. If @var{copy} is set, the range of the memory object should be copied to
  2754. the target task, rather than mapped read-write.
  2755. The function returns @code{KERN_SUCCESS} if the object is mapped,
  2756. @code{KERN_NO_SPACE} if no unused region of the task's virtual address
  2757. space that meets the address, size, and alignment criteria could be
  2758. found, and @code{KERN_INVALID_ARGUMENT} if an invalid argument was provided.
  2759. @end deftypefun
  2760. @node Memory Statistics
  2761. @section Memory Statistics
  2762. @deftp {Data type} vm_statistics_data_t
  2763. This structure is returned in @var{vm_stats} by the @code{vm_statistics}
  2764. function and provides virtual memory statistics for the system. It has
  2765. the following members:
  2766. @table @code
  2767. @item long pagesize
  2768. The page size in bytes.
  2769. @item long free_count
  2770. The number of free pages.
  2771. @item long active_count
  2772. The umber of active pages.
  2773. @item long inactive_count
  2774. The number of inactive pages.
  2775. @item long wire_count
  2776. The number of pages wired down.
  2777. @item long zero_fill_count
  2778. The number of zero filled pages.
  2779. @item long reactivations
  2780. The number of reactivated pages.
  2781. @item long pageins
  2782. The number of pageins.
  2783. @item long pageouts
  2784. The number of pageouts.
  2785. @item long faults
  2786. The number of faults.
  2787. @item long cow_faults
  2788. The number of copy-on-writes.
  2789. @item long lookups
  2790. The number of object cache lookups.
  2791. @item long hits
  2792. The number of object cache hits.
  2793. @end table
  2794. @end deftp
  2795. @deftypefun kern_return_t vm_statistics (@w{vm_task_t @var{target_task}}, @w{vm_statistics_data_t *@var{vm_stats}})
  2796. The function @code{vm_statistics} returns the statistics about the
  2797. kernel's use of virtual memory since the kernel was booted.
  2798. @code{pagesize} can also be found as a global variable
  2799. @code{vm_page_size} which is set at task initialization and remains
  2800. constant for the life of the task.
  2801. @end deftypefun
  2802. @node External Memory Management
  2803. @chapter External Memory Management
  2804. @menu
  2805. * Memory Object Server:: The basics of external memory management.
  2806. * Memory Object Creation:: How new memory objects are created.
  2807. * Memory Object Termination:: How memory objects are terminated.
  2808. * Memory Objects and Data:: Data transfer to and from memory objects.
  2809. * Memory Object Locking:: How memory objects are locked.
  2810. * Memory Object Attributes:: Manipulating attributes of memory objects.
  2811. * Default Memory Manager:: Setting and using the default memory manager.
  2812. @end menu
  2813. @node Memory Object Server
  2814. @section Memory Object Server
  2815. @deftypefun boolean_t memory_object_server (@w{msg_header_t *@var{in_msg}}, @w{msg_header_t *@var{out_msg}})
  2816. @deftypefunx boolean_t memory_object_default_server (@w{msg_header_t *@var{in_msg}}, @w{msg_header_t *@var{out_msg}})
  2817. @deftypefunx boolean_t seqnos_memory_object_server (@w{msg_header_t *@var{in_msg}}, @w{msg_header_t *@var{out_msg}})
  2818. @deftypefunx boolean_t seqnos_memory_object_default_server (@w{msg_header_t *@var{in_msg}}, @w{msg_header_t *@var{out_msg}})
  2819. A memory manager is a server task that responds to specific messages
  2820. from the kernel in order to handle memory management functions for the
  2821. kernel.
  2822. In order to isolate the memory manager from the specifics of message
  2823. formatting, the remote procedure call generator produces a procedure,
  2824. @code{memory_object_server}, to handle a received message. This
  2825. function does all necessary argument handling, and actually calls one of
  2826. the following functions: @code{memory_object_init},
  2827. @code{memory_object_data_return},
  2828. @code{memory_object_data_request}, @code{memory_object_data_unlock},
  2829. @code{memory_object_lock_completed}, @code{memory_object_copy},
  2830. @code{memory_object_terminate}. The @strong{default memory manager} may
  2831. get two additional requests from the kernel: @code{memory_object_create}
  2832. and @code{memory_object_data_initialize}. The remote procedure call
  2833. generator produces a procedure @code{memory_object_default_server} to
  2834. handle those functions specific to the default memory manager.
  2835. The @code{seqnos_memory_object_server} and
  2836. @code{seqnos_memory_object_default_server} differ from
  2837. @code{memory_object_server} and @code{memory_object_default_server} in
  2838. that they supply message sequence numbers to the server interfaces.
  2839. They call the @code{seqnos_memory_object_*} functions, which complement
  2840. the @code{memory_object_*} set of functions.
  2841. The return value from the @code{memory_object_server} function indicates
  2842. that the message was appropriate to the memory management interface
  2843. (returning @code{TRUE}), or that it could not handle this message
  2844. (returning @code{FALSE}).
  2845. The @var{in_msg} argument is the message that has been received from the
  2846. kernel. The @var{out_msg} is a reply message, but this is not used for
  2847. this server.
  2848. The function returns @code{TRUE} to indicate that the message in
  2849. question was applicable to this interface, and that the appropriate
  2850. routine was called to interpret the message. It returns @code{FALSE} to
  2851. indicate that the message did not apply to this interface, and that no
  2852. other action was taken.
  2853. @end deftypefun
  2854. @node Memory Object Creation
  2855. @section Memory Object Creation
  2856. @deftypefun kern_return_t memory_object_init (@w{memory_object_t @var{memory_object}}, @w{memory_object_control_t @var{memory_control}}, @w{memory_object_name_t @var{memory_object_name}}, @w{vm_size_t @var{memory_object_page_size}})
  2857. @deftypefunx kern_return_t seqnos_memory_object_init (@w{memory_object_t @var{memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_control_t @var{memory_control}}, @w{memory_object_name_t @var{memory_object_name}}, @w{vm_size_t @var{memory_object_page_size}})
  2858. The function @code{memory_object_init} serves as a notification that the
  2859. kernel has been asked to map the given memory object into a task's
  2860. virtual address space. Additionally, it provides a port on which the
  2861. memory manager may issue cache management requests, and a port which the
  2862. kernel will use to name this data region. In the event that different
  2863. each will perform a @code{memory_object_init} call with new request and
  2864. name ports. The virtual page size that is used by the calling kernel is
  2865. included for planning purposes.
  2866. When the memory manager is prepared to accept requests for data for
  2867. this object, it must call @code{memory_object_ready}.
  2868. Otherwise the kernel will not process requests on this object. To
  2869. reject all mappings of this object, the memory manager may use
  2870. @code{memory_object_destroy}.
  2871. The argument @var{memory_object} is the port that represents the memory
  2872. object data, as supplied to the kernel in a @code{vm_map} call.
  2873. @var{memory_control} is the request port to which a response is
  2874. requested. (In the event that a memory object has been supplied to more
  2875. than one the kernel that has made the request.)
  2876. @var{memory_object_name} is a port used by the kernel to refer to the
  2877. memory object data in response to @code{vm_region} calls.
  2878. @code{memory_object_page_size} is the page size to be used by this
  2879. kernel. All data sizes in calls involving this kernel must be an
  2880. integral multiple of the page size. Note that different kernels,
  2881. indicated by a different @code{memory_control}, may have different page
  2882. sizes.
  2883. The function should return @code{KERN_SUCCESS}, but since this routine
  2884. is called by the kernel, which does not wait for a reply message, this
  2885. value is ignored.
  2886. @end deftypefun
  2887. @deftypefun kern_return_t memory_object_ready (@w{memory_object_control_t @var{memory_control}}, @w{boolean_t @var{may_cache_object}}, @w{memory_object_copy_strategy_t @var{copy_strategy}})
  2888. The function @code{memory_object_ready} informs the kernel that the
  2889. memory manager is ready to receive data or unlock requests on behalf of
  2890. the clients. The argument @var{memory_control} is the port, provided by
  2891. the kernel in a @code{memory_object_init} call, to which cache
  2892. management requests may be issued. If @var{may_cache_object} is set,
  2893. the kernel may keep data associated with this memory object, even after
  2894. virtual memory references to it are gone.
  2895. @var{copy_strategy} tells how the kernel should copy regions of the
  2896. associated memory object. There are three possible caching strategies:
  2897. @code{MEMORY_OBJECT_COPY_NONE} which specifies that nothing special
  2898. should be done when data in the object is copied;
  2899. @code{MEMORY_OBJECT_COPY_CALL} which specifies that the memory manager
  2900. should be notified via a @code{memory_object_copy} call before any part
  2901. of the object is copied; and @code{MEMORY_OBJECT_COPY_DELAY} which
  2902. guarantees that the memory manager does not externally modify the data
  2903. so that the kernel can use its normal copy-on-write algorithms.
  2904. @code{MEMORY_OBJECT_COPY_DELAY} is the strategy most commonly used.
  2905. This routine does not receive a reply message (and consequently has no
  2906. return value), so only message transmission errors apply.
  2907. @end deftypefun
  2908. @node Memory Object Termination
  2909. @section Memory Object Termination
  2910. @deftypefun kern_return_t memory_object_terminate (@w{memory_object_t @var{memory_object}}, @w{memory_object_control_t @var{memory_control}}, @w{memory_object_name_t @var{memory_object_name}})
  2911. @deftypefunx kern_return_t seqnos_memory_object_terminate (@w{memory_object_t @var{memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_control_t @var{memory_control}}, @w{memory_object_name_t @var{memory_object_name}})
  2912. The function @code{memory_object_terminate} indicates that the kernel
  2913. has completed its use of the given memory object. All rights to the
  2914. memory object control and name ports are included, so that the memory
  2915. manager can destroy them (using @code{mach_port_deallocate}) after doing
  2916. appropriate bookkeeping. The kernel will terminate a memory object only
  2917. after all address space mappings of that memory object have been
  2918. deallocated, or upon explicit request by the memory manager.
  2919. The argument @var{memory_object} is the port that represents the memory
  2920. object data, as supplied to the kernel in a @code{vm_map} call.
  2921. @var{memory_control} is the request port to which a response is
  2922. requested. (In the event that a memory object has been supplied to more
  2923. than one the kernel that has made the request.)
  2924. @var{memory_object_name} is a port used by the kernel to refer to the
  2925. memory object data in response to @code{vm_region} calls.
  2926. The function should return @code{KERN_SUCCESS}, but since this routine
  2927. is called by the kernel, which does not wait for a reply message, this
  2928. value is ignored.
  2929. @end deftypefun
  2930. @deftypefun kern_return_t memory_object_destroy (@w{memory_object_control_t @var{memory_control}}, @w{kern_return_t @var{reason}})
  2931. The function @code{memory_object_destroy} tells the kernel to shut down
  2932. the memory object. As a result of this call the kernel will no longer
  2933. support paging activity or any @code{memory_object} calls on this
  2934. object, and all rights to the memory object port, the memory control
  2935. port and the memory name port will be returned to the memory manager in
  2936. a memory_object_terminate call. If the memory manager is concerned that
  2937. any modified cached data be returned to it before the object is
  2938. terminated, it should call @code{memory_object_lock_request} with
  2939. @var{should_flush} set and a lock value of @code{VM_PROT_WRITE} before
  2940. making this call.
  2941. The argument @var{memory_control} is the port, provided by the kernel in
  2942. a @code{memory_object_init} call, to which cache management requests may
  2943. be issued. @var{reason} is an error code indicating why the object
  2944. must be destroyed.
  2945. @c The error code is currently ignored.
  2946. This routine does not receive a reply message (and consequently has no
  2947. return value), so only message transmission errors apply.
  2948. @end deftypefun
  2949. @node Memory Objects and Data
  2950. @section Memory Objects and Data
  2951. @deftypefun kern_return_t memory_object_data_return (@w{memory_object_t @var{memory_object}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_offset_t @var{data}}, @w{vm_size_t @var{data_count}}, @w{boolean_t @var{dirty}}, @w{boolean_t @var{kernel_copy}})
  2952. @deftypefunx kern_return_t seqnos_memory_object_data_return (@w{memory_object_t @var{memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_offset_t @var{data}}, @w{vm_size_t @var{data_count}}, @w{boolean_t @var{dirty}}, @w{boolean_t @var{kernel_copy}})
  2953. The function @code{memory_object_data_return} provides the memory
  2954. manager with data that has been modified while cached in physical
  2955. memory. Once the memory manager no longer needs this data (e.g., it has
  2956. been written to another storage medium), it should be deallocated using
  2957. @code{vm_deallocate}.
  2958. The argument @var{memory_object} is the port that represents the memory
  2959. object data, as supplied to the kernel in a @code{vm_map} call.
  2960. @var{memory_control} is the request port to which a response is
  2961. requested. (In the event that a memory object has been supplied to more
  2962. than one the kernel that has made the request.) @var{offset} is the
  2963. offset within a memory object to which this call refers. This will be
  2964. page aligned. @var{data} is the data which has been modified while
  2965. cached in physical memory. @var{data_count} is the amount of data to be
  2966. written, in bytes. This will be an integral number of memory object
  2967. pages.
  2968. The kernel will also use this call to return precious pages. If an
  2969. unmodified precious age is returned, @var{dirty} is set to @code{FALSE},
  2970. otherwise it is @code{TRUE}. If @var{kernel_copy} is @code{TRUE}, the
  2971. kernel kept a copy of the page. Precious data remains precious if the
  2972. kernel keeps a copy. The indication that the kernel kept a copy is only
  2973. a hint if the data is not precious; the cleaned copy may be discarded
  2974. without further notifying the manager.
  2975. The function should return @code{KERN_SUCCESS}, but since this routine
  2976. is called by the kernel, which does not wait for a reply message, this
  2977. value is ignored.
  2978. @end deftypefun
  2979. @deftypefun kern_return_t memory_object_data_request (@w{memory_object_t @var{memory_object}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_offset_t @var{length}}, @w{vm_prot_t @var{desired_access}})
  2980. @deftypefunx kern_return_t seqnos_memory_object_data_request (@w{memory_object_t @var{memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_offset_t @var{length}}, @w{vm_prot_t @var{desired_access}})
  2981. The function @code{memory_object_data_request} is a request for data
  2982. from the specified memory object, for at least the access specified.
  2983. The memory manager is expected to return at least the specified data,
  2984. with as much access as it can allow, using
  2985. @code{memory_object_data_supply}. If the memory manager is unable to
  2986. provide the data (for example, because of a hardware error), it may use
  2987. the @code{memory_object_data_error} call. The
  2988. @code{memory_object_data_unavailable} call may be used to tell the
  2989. kernel to supply zero-filled memory for this region.
  2990. The argument @var{memory_object} is the port that represents the memory
  2991. object data, as supplied to the kernel in a @code{vm_map} call.
  2992. @var{memory_control} is the request port to which a response is
  2993. requested. (In the event that a memory object has been supplied to more
  2994. than one the kernel that has made the request.) @var{offset} is the
  2995. offset within a memory object to which this call refers. This will be
  2996. page aligned. @var{length} is the number of bytes of data, starting at
  2997. @var{offset}, to which this call refers. This will be an integral
  2998. number of memory object pages. @var{desired_access} is a protection
  2999. value describing the memory access modes which must be permitted on the
  3000. specified cached data. One or more of: @code{VM_PROT_READ},
  3001. @code{VM_PROT_WRITE} or @code{VM_PROT_EXECUTE}.
  3002. The function should return @code{KERN_SUCCESS}, but since this routine
  3003. is called by the kernel, which does not wait for a reply message, this
  3004. value is ignored.
  3005. @end deftypefun
  3006. @deftypefun kern_return_t memory_object_data_supply (@w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_offset_t @var{data}}, @w{vm_size_t @var{data_count}}, @w{vm_prot_t @var{lock_value}}, @w{boolean_t @var{precious}}, @w{mach_port_t @var{reply}})
  3007. The function @code{memory_object_data_supply} supplies the kernel with
  3008. data for the specified memory object. Ordinarily, memory managers
  3009. should only provide data in response to @code{memory_object_data_request}
  3010. calls from the kernel (but they may provide data in advance as desired).
  3011. When data already held by this kernel is provided again, the new data is
  3012. ignored. The kernel may not provide any data (or protection)
  3013. consistency among pages with different virtual page alignments within
  3014. the same object.
  3015. The argument @var{memory_control} is the port, provided by the kernel in
  3016. a @code{memory_object_init} call, to which cache management requests may
  3017. be issued. @var{offset} is an offset within a memory object in bytes.
  3018. This must be page aligned. @var{data} is the data that is being
  3019. provided to the kernel. This is a pointer to the data.
  3020. @var{data_count} is the amount of data to be provided. Only whole
  3021. virtual pages of data can be accepted; partial pages will be discarded.
  3022. @var{lock_value} is a protection value indicating those forms of access
  3023. that should @strong{not} be permitted to the specified cached data. The
  3024. lock values must be one or more of the set: @code{VM_PROT_NONE},
  3025. @code{VM_PROT_READ}, @code{VM_PROT_WRITE}, @code{VM_PROT_EXECUTE} and
  3026. @code{VM_PROT_ALL} as defined in @file{mach/vm_prot.h}.
  3027. If @var{precious} is @code{FALSE}, the kernel treats the data as a
  3028. temporary and may throw it away if it hasn't been changed. If the
  3029. @var{precious} value is @code{TRUE}, the kernel treats its copy as a
  3030. data repository and promises to return it to the manager; the manager
  3031. may tell the kernel to throw it away instead by flushing and not
  3032. cleaning the data (see @code{memory_object_lock_request}).
  3033. If @var{reply_to} is not @code{MACH_PORT_NULL}, the kernel will send a
  3034. completion message to the provided port (see
  3035. @code{memory_object_supply_completed}).
  3036. This routine does not receive a reply message (and consequently has no
  3037. return value), so only message transmission errors apply.
  3038. @end deftypefun
  3039. @deftypefun kern_return_t memory_object_supply_completed (@w{memory_object_t @var{memory_object}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{length}}, @w{kern_return_t @var{result}}, @w{vm_offset_t @var{error_offset}})
  3040. @deftypefunx kern_return_t seqnos_memory_object_supply_completed (@w{memory_object_t @var{memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{length}}, @w{kern_return_t @var{result}}, @w{vm_offset_t @var{error_offset}})
  3041. The function @code{memory_object_supply_completed} indicates that a
  3042. previous @code{memory_object_data_supply} has been completed. Note that
  3043. this call is made on whatever port was specified in the
  3044. @code{memory_object_data_supply} call; that port need not be the memory
  3045. object port itself. No reply is expected after this call.
  3046. The argument @var{memory_object} is the port that represents the memory
  3047. object data, as supplied to the kernel in a @code{vm_map} call.
  3048. @var{memory_control} is the request port to which a response is
  3049. requested. (In the event that a memory object has been supplied to more
  3050. than one the kernel that has made the request.) @var{offset} is the
  3051. offset within a memory object to which this call refers. @var{length}
  3052. is the length of the data covered by the lock request. The @var{result}
  3053. parameter indicates what happened during the supply. If it is not
  3054. @code{KERN_SUCCESS}, then @var{error_offset} identifies the first offset
  3055. at which a problem occurred. The pagein operation stopped at this
  3056. point. Note that the only failures reported by this mechanism are
  3057. @code{KERN_MEMORY_PRESENT}. All other failures (invalid argument, error
  3058. on pagein of supplied data in manager's address space) cause the entire
  3059. operation to fail.
  3060. @end deftypefun
  3061. @deftypefun kern_return_t memory_object_data_error (@w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{size}}, @w{kern_return_t @var{reason}})
  3062. The function @code{memory_object_data_error} indicates that the memory
  3063. manager cannot return the data requested for the given region,
  3064. specifying a reason for the error. This is typically used when a
  3065. hardware error is encountered.
  3066. The argument @var{memory_control} is the port, provided by the kernel in
  3067. a @code{memory_object_init} call, to which cache management requests may
  3068. be issued. @var{offset} is an offset within a memory object in bytes.
  3069. This must be page aligned. @var{data} is the data that is being
  3070. provided to the kernel. This is a pointer to the data. @var{size} is
  3071. the amount of cached data (starting at @var{offset}) to be handled.
  3072. This must be an integral number of the memory object page size.
  3073. @var{reason} is an error code indicating what type of error occurred.
  3074. @c The error code is currently ignored.
  3075. This routine does not receive a reply message (and consequently has no
  3076. return value), so only message transmission errors apply.
  3077. @end deftypefun
  3078. @deftypefun kern_return_t memory_object_data_unavailable (@w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{size}}, @w{kern_return_t @var{reason}})
  3079. The function @code{memory_object_data_unavailable} indicates that the
  3080. memory object does not have data for the given region and that the
  3081. kernel should provide the data for this range. The memory manager may
  3082. use this call in three different situations.
  3083. @enumerate
  3084. @item
  3085. The object was created by @code{memory_object_create} and the kernel has
  3086. not yet provided data for this range (either via a
  3087. @code{memory_object_data_initialize}, or
  3088. a @code{memory_object_data_return} for the object.
  3089. @item
  3090. The object was created by an @code{memory_object_data_copy} and the
  3091. kernel should copy this region from the original memory object.
  3092. @item
  3093. The object is a normal user-created memory object and the kernel should
  3094. supply unlocked zero-filled pages for the range.
  3095. @end enumerate
  3096. The argument @var{memory_control} is the port, provided by the kernel in
  3097. a @code{memory_object_init} call, to which cache management requests may
  3098. be issued. @var{offset} is an offset within a memory object, in bytes.
  3099. This must be page aligned. @var{size} is the amount of cached data
  3100. (starting at @var{offset}) to be handled. This must be an integral
  3101. number of the memory object page size.
  3102. This routine does not receive a reply message (and consequently has no
  3103. return value), so only message transmission errors apply.
  3104. @end deftypefun
  3105. @deftypefun kern_return_t memory_object_copy (@w{memory_object_t @var{old_memory_object}}, @w{memory_object_control_t @var{old_memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{length}}, @w{memory_object_t @var{new_memory_object}})
  3106. @deftypefunx kern_return_t seqnos_memory_object_copy (@w{memory_object_t @var{old_memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_control_t @var{old_memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{length}}, @w{memory_object_t @var{new_memory_object}})
  3107. The function @code{memory_object_copy} indicates that a copy has been
  3108. made of the specified range of the given original memory object. This
  3109. call includes only the new memory object itself; a
  3110. @code{memory_object_init} call will be made on the new memory object
  3111. after the currently cached pages of the original object are prepared.
  3112. After the memory manager receives the init call, it must reply with the
  3113. @code{memory_object_ready} call to assert the "ready" attribute. The
  3114. kernel will use the new memory object, control and name ports to refer
  3115. to the new copy.
  3116. This call is made when the original memory object had the caching
  3117. parameter set to @code{MEMORY_OBJECT_COPY_CALL} and a user of the object
  3118. has asked the kernel to copy it.
  3119. Cached pages from the original memory object at the time of the copy
  3120. operation are handled as follows: Readable pages may be silently copied
  3121. to the new memory object (with all access permissions). Pages not
  3122. copied are locked to prevent write access.
  3123. The new memory object is @strong{temporary}, meaning that the memory
  3124. manager should not change its contents or allow the memory object to be
  3125. mapped in another client. The memory manager may use the
  3126. @code{memory_object_data_unavailable} call to indicate that the
  3127. appropriate pages of the original memory object may be used to fulfill
  3128. the data request.
  3129. The argument @var{old_memory_object} is the port that represents the old
  3130. memory object data. @var{old_memory_control} is the kernel port for the
  3131. old object. @var{offset} is the offset within a memory object to which
  3132. this call refers. This will be page aligned. @var{length} is the
  3133. number of bytes of data, starting at @var{offset}, to which this call
  3134. refers. This will be an integral number of memory object pages.
  3135. @var{new_memory_object} is a new memory object created by the kernel;
  3136. see synopsis for further description. Note that all port rights
  3137. (including receive rights) are included for the new memory object.
  3138. The function should return @code{KERN_SUCCESS}, but since this routine
  3139. is called by the kernel, which does not wait for a reply message, this
  3140. value is ignored.
  3141. @end deftypefun
  3142. @node Memory Object Locking
  3143. @section Memory Object Locking
  3144. @deftypefun kern_return_t memory_object_lock_request (@w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{size}}, @w{memory_object_return_t @var{should_clean}}, @w{boolean_t @var{should_flush}}, @w{vm_prot_t @var{lock_value}}, @w{mach_port_t @var{reply_to}})
  3145. The function @code{memory_object_lock_request} allows a memory manager
  3146. to make cache management requests. As specified in arguments to the
  3147. call, the kernel will:
  3148. @itemize
  3149. @item
  3150. clean (i.e., write back using @code{memory_object_data_supply} any cached data which has been modified
  3151. since the last time it was written
  3152. @item
  3153. flush (i.e., remove any uses of) that data from memory
  3154. @item
  3155. lock (i.e., prohibit the specified uses of) the cached data
  3156. @end itemize
  3157. Locks applied to cached data are not cumulative; new lock values
  3158. override previous ones. Thus, data may also be unlocked using this
  3159. primitive. The lock values must be one or more of the following values:
  3160. @code{VM_PROT_NONE}, @code{VM_PROT_READ}, @code{VM_PROT_WRITE},
  3161. @code{VM_PROT_EXECUTE} and @code{VM_PROT_ALL} as defined in
  3162. @file{mach/vm_prot.h}.
  3163. Only data which is cached at the time of this call is affected. When a
  3164. running thread requires a prohibited access to cached data, the kernel
  3165. will issue a @code{memory_object_data_unlock} call specifying the forms
  3166. of access required.
  3167. Once all of the actions requested by this call have been completed, the
  3168. kernel issues a @code{memory_object_lock_completed} call on the
  3169. specified reply port.
  3170. The argument @var{memory_control} is the port, provided by the kernel in
  3171. a @code{memory_object_init} call, to which cache management requests may
  3172. be issued. @var{offset} is an offset within a memory object, in bytes.
  3173. This must be page aligned. @var{size} is the amount of cached data
  3174. (starting at @var{offset}) to be handled. This must be an integral
  3175. number of the memory object page size. If @var{should_clean} is set,
  3176. modified data should be written back to the memory manager. If
  3177. @var{should_flush} is set, the specified cached data should be
  3178. invalidated, and all uses of that data should be revoked.
  3179. @var{lock_value} is a protection value indicating those forms of access
  3180. that should @strong{not} be permitted to the specified cached data.
  3181. @var{reply_to} is a port on which a @code{memory_object_lock_completed}
  3182. call should be issued, or @code{MACH_PORT_NULL} if no acknowledgement is
  3183. desired.
  3184. This routine does not receive a reply message (and consequently has no
  3185. return value), so only message transmission errors apply.
  3186. @end deftypefun
  3187. @deftypefun kern_return_t memory_object_lock_completed (@w{memory_object_t @var{memory_object}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{length}})
  3188. @deftypefunx kern_return_t seqnos_memory_object_lock_completed (@w{memory_object_t @var{memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{length}})
  3189. The function @code{memory_object_lock_completed} indicates that a
  3190. previous @code{memory_object_lock_request} has been completed. Note
  3191. that this call is made on whatever port was specified in the
  3192. @code{memory_object_lock_request} call; that port need not be the memory
  3193. object port itself. No reply is expected after this call.
  3194. The argument @var{memory_object} is the port that represents the memory
  3195. object data, as supplied to the kernel in a @code{vm_map} call.
  3196. @var{memory_control} is the request port to which a response is
  3197. requested. (In the event that a memory object has been supplied to more
  3198. than one the kernel that has made the request.) @var{offset} is the
  3199. offset within a memory object to which this call refers. @var{length}
  3200. is the length of the data covered by the lock request.
  3201. The function should return @code{KERN_SUCCESS}, but since this routine
  3202. is called by the kernel, which does not wait for a reply message, this
  3203. value is ignored.
  3204. @end deftypefun
  3205. @deftypefun kern_return_t memory_object_data_unlock (@w{memory_object_t @var{memory_object}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{length}}, @w{vm_prot_t @var{desired_access}})
  3206. @deftypefunx kern_return_t seqnos_memory_object_data_unlock (@w{memory_object_t @var{memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{length}}, @w{vm_prot_t @var{desired_access}})
  3207. The function @code{memory_object_data_unlock} is a request that the
  3208. memory manager permit at least the desired access to the specified data
  3209. cached by the kernel. A call to @code{memory_object_lock_request} is
  3210. expected in response.
  3211. The argument @var{memory_object} is the port that represents the memory
  3212. object data, as supplied to the kernel in a @code{vm_map} call.
  3213. @var{memory_control} is the request port to which a response is
  3214. requested. (In the event that a memory object has been supplied to more
  3215. than one the kernel that has made the request.) @var{offset} is the
  3216. offset within a memory object to which this call refers. This will be
  3217. page aligned. @var{length} is the number of bytes of data, starting at
  3218. @var{offset}, to which this call refers. This will be an integral
  3219. number of memory object pages. @var{desired_access} a protection value
  3220. describing the memory access modes which must be permitted on the
  3221. specified cached data. One or more of: @code{VM_PROT_READ},
  3222. @code{VM_PROT_WRITE} or @code{VM_PROT_EXECUTE}.
  3223. The function should return @code{KERN_SUCCESS}, but since this routine
  3224. is called by the kernel, which does not wait for a reply message, this
  3225. value is ignored.
  3226. @end deftypefun
  3227. @node Memory Object Attributes
  3228. @section Memory Object Attributes
  3229. @deftypefun kern_return_t memory_object_get_attributes (@w{memory_object_control_t @var{memory_control}}, @w{boolean_t *@var{object_ready}}, @w{boolean_t *@var{may_cache_object}}, @w{memory_object_copy_strategy_t *@var{copy_strategy}})
  3230. The function @code{memory_object_get_attribute} retrieves the current
  3231. attributes associated with the memory object.
  3232. The argument @var{memory_control} is the port, provided by the kernel in
  3233. a @code{memory_object_init} call, to which cache management requests may
  3234. be issued. If @var{object_ready} is set, the kernel may issue new data
  3235. and unlock requests on the associated memory object. If
  3236. @var{may_cache_object} is set, the kernel may keep data associated with
  3237. this memory object, even after virtual memory references to it are gone.
  3238. @var{copy_strategy} tells how the kernel should copy regions of the
  3239. associated memory object.
  3240. This routine does not receive a reply message (and consequently has no
  3241. return value), so only message transmission errors apply.
  3242. @end deftypefun
  3243. @deftypefun kern_return_t memory_object_change_attributes (@w{memory_object_control_t @var{memory_control}}, @w{boolean_t @var{may_cache_object}}, @w{memory_object_copy_strategy_t @var{copy_strategy}}, @w{mach_port_t @var{reply_to}})
  3244. The function @code{memory_object_change_attribute} informs the kernel
  3245. that the memory manager is ready to receive data or unlock requests on
  3246. behalf of the clients and sets performance-related attributes for the
  3247. specified memory object. If the caching attribute is asserted, the
  3248. kernel is permitted (and encouraged) to maintain cached data for this
  3249. memory object even after no virtual address space contains this data.
  3250. There are three possible caching strategies:
  3251. @code{MEMORY_OBJECT_COPY_NONE} which specifies that nothing special
  3252. should be done when data in the object is copied;
  3253. @code{MEMORY_OBJECT_COPY_CALL} which specifies that the memory manager
  3254. should be notified via a @code{memory_object_copy} call before any part
  3255. of the object is copied; and @code{MEMORY_OBJECT_COPY_DELAY} which
  3256. guarantees that the memory manager does not externally modify the data
  3257. so that the kernel can use its normal copy-on-write algorithms.
  3258. @code{MEMORY_OBJECT_COPY_DELAY} is the strategy most commonly used.
  3259. The argument @var{memory_control} is the port, provided by the kernel in
  3260. a @code{memory_object_init} call, to which cache management requests may
  3261. be issued. If @var{may_cache_object} is set, the kernel may keep data
  3262. associated with this memory object, even after virtual memory references
  3263. to it are gone. @var{copy_strategy} tells how the kernel should copy
  3264. regions of the associated memory object. @var{reply_to} is a port on
  3265. which a @code{memory_object_change_completed} call will be issued upon
  3266. completion of the attribute change, or @code{MACH_PORT_NULL} if no
  3267. acknowledgement is desired.
  3268. This routine does not receive a reply message (and consequently has no
  3269. return value), so only message transmission errors apply.
  3270. @end deftypefun
  3271. @deftypefun kern_return_t memory_object_change_completed (@w{memory_object_t @var{memory_object}}, @w{boolean_t @var{may_cache_object}}, @w{memory_object_copy_strategy_t @var{copy_strategy}})
  3272. @deftypefunx kern_return_t seqnos_memory_object_change_completed (@w{memory_object_t @var{memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{boolean_t @var{may_cache_object}}, @w{memory_object_copy_strategy_t @var{copy_strategy}})
  3273. The function @code{memory_object_change_completed} indicates the
  3274. completion of an attribute change call.
  3275. @c Warning: This routine does NOT contain a memory_object_control_t because
  3276. @c the memory_object_change_attributes call may cause memory object
  3277. @c termination (by uncaching the object). This would yield an invalid
  3278. @c port.
  3279. @end deftypefun
  3280. @node Default Memory Manager
  3281. @section Default Memory Manager
  3282. @deftypefun kern_return_t vm_set_default_memory_manager (@w{host_t @var{host}}, @w{mach_port_t *@var{default_manager}})
  3283. The function @code{vm_set_default_memory_manager} sets the kernel's
  3284. default memory manager. It sets the port to which newly-created
  3285. temporary memory objects are delivered by @code{memory_object_create} to
  3286. the host. The old memory manager port is returned. If
  3287. @var{default_manager} is @code{MACH_PORT_NULL} then this routine just returns
  3288. the current default manager port without changing it.
  3289. The argument @var{host} is a task port to the kernel whose default
  3290. memory manager is to be changed. @var{default_manager} is an in/out
  3291. parameter. As input, @var{default_manager} is the port that the new
  3292. memory manager is listening on for @code{memory_object_create} calls.
  3293. As output, it is the old default memory manager's port.
  3294. The function returns @code{KERN_SUCCESS} if the new memory manager is
  3295. installed, and @code{KERN_INVALID_ARGUMENT} if this task does not have
  3296. the privileges required for this call.
  3297. @end deftypefun
  3298. @deftypefun kern_return_t memory_object_create (@w{memory_object_t @var{old_memory_object}}, @w{memory_object_t @var{new_memory_object}}, @w{vm_size_t @var{new_object_size}}, @w{memory_object_control_t @var{new_control}}, @w{memory_object_name_t @var{new_name}}, @w{vm_size_t @var{new_page_size}})
  3299. @deftypefunx kern_return_t seqnos_memory_object_create (@w{memory_object_t @var{old_memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_t @var{new_memory_object}}, @w{vm_size_t @var{new_object_size}}, @w{memory_object_control_t @var{new_control}}, @w{memory_object_name_t @var{new_name}}, @w{vm_size_t @var{new_page_size}})
  3300. The function @code{memory_object_create} is a request that the given
  3301. memory manager accept responsibility for the given memory object created
  3302. by the kernel. This call will only be made to the system
  3303. @strong{default memory manager}. The memory object in question
  3304. initially consists of zero-filled memory; only memory pages that are
  3305. actually written will ever be provided to
  3306. @code{memory_object_data_request} calls, the default memory manager must
  3307. use @code{memory_object_data_unavailable} for any pages that have not
  3308. previously been written.
  3309. No reply is expected after this call. Since this call is directed to
  3310. the default memory manager, the kernel assumes that it will be ready to
  3311. handle data requests to this object and does not need the confirmation
  3312. of a @code{memory_object_ready} call.
  3313. The argument @var{old_memory_object} is a memory object provided by the
  3314. default memory manager on which the kernel can make
  3315. @code{memory_object_create} calls. @var{new_memory_object} is a new
  3316. memory object created by the kernel; see synopsis for further
  3317. description. Note that all port rights (including receive rights) are
  3318. included for the new memory object. @var{new_object_size} is the
  3319. maximum size of the new object. @var{new_control} is a port, created by
  3320. the kernel, on which a memory manager may issue cache management
  3321. requests for the new object. @var{new_name} a port used by the kernel
  3322. to refer to the new memory object data in response to @code{vm_region}
  3323. calls. @var{new_page_size} is the page size to be used by this kernel.
  3324. All data sizes in calls involving this kernel must be an integral
  3325. multiple of the page size. Note that different kernels, indicated by
  3326. different a @code{memory_control}, may have different page sizes.
  3327. The function should return @code{KERN_SUCCESS}, but since this routine
  3328. is called by the kernel, which does not wait for a reply message, this
  3329. value is ignored.
  3330. @end deftypefun
  3331. @deftypefun kern_return_t memory_object_data_initialize (@w{memory_object_t @var{memory_object}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_offset_t @var{data}}, @w{vm_size_t @var{data_count}})
  3332. @deftypefunx kern_return_t seqnos_memory_object_data_initialize (@w{memory_object_t @var{memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_offset_t @var{data}}, @w{vm_size_t @var{data_count}})
  3333. The function @code{memory_object_data_initialize} provides the memory
  3334. manager with initial data for a kernel-created memory object. If the
  3335. memory manager already has been supplied data (by a previous
  3336. @code{memory_object_data_initialize}, or
  3337. @code{memory_object_data_return}), then this data should be ignored.
  3338. Otherwise, this call behaves exactly as does
  3339. @code{memory_object_data_return} on memory objects created by the kernel
  3340. via @code{memory_object_create} and thus will only be made to default
  3341. memory managers. This call will not be made on objects created via
  3342. @code{memory_object_copy}.
  3343. The argument @var{memory_object} the port that represents the memory
  3344. object data, as supplied by the kernel in a @code{memory_object_create}
  3345. call. @var{memory_control} is the request port to which a response is
  3346. requested. (In the event that a memory object has been supplied to more
  3347. than one the kernel that has made the request.) @var{offset} is the
  3348. offset within a memory object to which this call refers. This will be
  3349. page aligned. @var{data} is the data which has been modified while
  3350. cached in physical memory. @var{data_count} is the amount of data to be
  3351. written, in bytes. This will be an integral number of memory object
  3352. pages.
  3353. The function should return @code{KERN_SUCCESS}, but since this routine
  3354. is called by the kernel, which does not wait for a reply message, this
  3355. value is ignored.
  3356. @end deftypefun
  3357. @node Threads and Tasks
  3358. @chapter Threads and Tasks
  3359. @menu
  3360. * Thread Interface:: Manipulating threads.
  3361. * Task Interface:: Manipulating tasks.
  3362. * Profiling:: Profiling threads and tasks.
  3363. @end menu
  3364. @node Thread Interface
  3365. @section Thread Interface
  3366. @cindex thread port
  3367. @cindex port representing a thread
  3368. @deftp {Data type} thread_t
  3369. This is a @code{mach_port_t} and used to hold the port name of a
  3370. thread port that represents the thread. Manipulations of the thread are
  3371. implemented as remote procedure calls to the thread port. A thread can
  3372. get a port to itself with the @code{mach_thread_self} system call.
  3373. @end deftp
  3374. @menu
  3375. * Thread Creation:: Creating new threads.
  3376. * Thread Termination:: Terminating existing threads.
  3377. * Thread Information:: How to get informations on threads.
  3378. * Thread Settings:: How to set threads related informations.
  3379. * Thread Execution:: How to control the thread's machine state.
  3380. * Scheduling:: Operations on thread scheduling.
  3381. * Thread Special Ports:: How to handle the thread's special ports.
  3382. * Exceptions:: Managing exceptions.
  3383. @end menu
  3384. @node Thread Creation
  3385. @subsection Thread Creation
  3386. @deftypefun kern_return_t thread_create (@w{task_t @var{parent_task}}, @w{thread_t *@var{child_thread}})
  3387. The function @code{thread_create} creates a new thread within the task
  3388. specified by @var{parent_task}. The new thread has no processor state,
  3389. and has a suspend count of 1. To get a new thread to run, first
  3390. @code{thread_create} is called to get the new thread's identifier,
  3391. (@var{child_thread}). Then @code{thread_set_state} is called to set a
  3392. processor state, and finally @code{thread_resume} is called to get the
  3393. thread scheduled to execute.
  3394. When the thread is created send rights to its thread kernel port are
  3395. given to it and returned to the caller in @var{child_thread}. The new
  3396. thread's exception port is set to @code{MACH_PORT_NULL}.
  3397. The function returns @code{KERN_SUCCESS} if a new thread has been
  3398. created, @code{KERN_INVALID_ARGUMENT} if @var{parent_task} is not a
  3399. valid task and @code{KERN_RESOURCE_SHORTAGE} if some critical kernel
  3400. resource is not available.
  3401. @end deftypefun
  3402. @node Thread Termination
  3403. @subsection Thread Termination
  3404. @deftypefun kern_return_t thread_terminate (@w{thread_t @var{target_thread}})
  3405. The function @code{thread_terminate} destroys the thread specified by
  3406. @var{target_thread}.
  3407. The function returns @code{KERN_SUCCESS} if the thread has been killed
  3408. and @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread.
  3409. @end deftypefun
  3410. @node Thread Information
  3411. @subsection Thread Information
  3412. @deftypefun thread_t mach_thread_self ()
  3413. The @code{mach_thread_self} system call returns the calling thread's
  3414. thread port.
  3415. @code{mach_thread_self} has an effect equivalent to receiving a send
  3416. right for the thread port. @code{mach_thread_self} returns the name of
  3417. the send right. In particular, successive calls will increase the
  3418. calling task's user-reference count for the send right.
  3419. @c author{marcus}
  3420. As a special exception, the kernel will overrun the user reference count
  3421. of the thread name port, so that this function can not fail for that
  3422. reason. Because of this, the user should not deallocate the port right
  3423. if an overrun might have happened. Otherwise the reference count could
  3424. drop to zero and the send right be destroyed while the user still
  3425. expects to be able to use it. As the kernel does not make use of the
  3426. number of extant send rights anyway, this is safe to do (the thread port
  3427. itself is not destroyed, even when there are no send rights anymore).
  3428. The function returns @code{MACH_PORT_NULL} if a resource shortage
  3429. prevented the reception of the send right or if the thread port is
  3430. currently null and @code{MACH_PORT_DEAD} if the thread port is currently
  3431. dead.
  3432. @end deftypefun
  3433. @deftypefun kern_return_t thread_info (@w{thread_t @var{target_thread}}, @w{int @var{flavor}}, @w{thread_info_t @var{thread_info}}, @w{mach_msg_type_number_t *@var{thread_infoCnt}})
  3434. The function @code{thread_info} returns the selected information array
  3435. for a thread, as specified by @var{flavor}.
  3436. @var{thread_info} is an array of integers that is supplied by the caller
  3437. and returned filled with specified information. @var{thread_infoCnt} is
  3438. supplied as the maximum number of integers in @var{thread_info}. On
  3439. return, it contains the actual number of integers in @var{thread_info}.
  3440. The maximum number of integers returned by any flavor is
  3441. @code{THREAD_INFO_MAX}.
  3442. The type of information returned is defined by @var{flavor}, which can
  3443. be one of the following:
  3444. @table @code
  3445. @item THREAD_BASIC_INFO
  3446. The function returns basic information about the thread, as defined by
  3447. @code{thread_basic_info_t}. This includes the user and system time, the
  3448. run state, and scheduling priority. The number of integers returned is
  3449. @code{THREAD_BASIC_INFO_COUNT}.
  3450. @item THREAD_SCHED_INFO
  3451. The function returns information about the scheduling policy for the
  3452. thread as defined by @code{thread_sched_info_t}. The number of integers
  3453. returned is @code{THREAD_SCHED_INFO_COUNT}.
  3454. @end table
  3455. The function returns @code{KERN_SUCCESS} if the call succeeded and
  3456. @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread or
  3457. @var{flavor} is not recognized. The function returns
  3458. @code{MIG_ARRAY_TOO_LARGE} if the returned info array is too large for
  3459. @var{thread_info}. In this case, @var{thread_info} is filled as much as
  3460. possible and @var{thread_infoCnt} is set to the number of elements that
  3461. would have been returned if there were enough room.
  3462. @end deftypefun
  3463. @deftp {Data type} {struct thread_basic_info}
  3464. This structure is returned in @var{thread_info} by the
  3465. @code{thread_info} function and provides basic information about the
  3466. thread. You can cast a variable of type @code{thread_info_t} to a
  3467. pointer of this type if you provided it as the @var{thread_info}
  3468. parameter for the @code{THREAD_BASIC_INFO} flavor of @code{thread_info}.
  3469. It has the following members:
  3470. @table @code
  3471. @item time_value_t user_time
  3472. user run time
  3473. @item time_value_t system_time
  3474. system run time
  3475. @item int cpu_usage
  3476. Scaled cpu usage percentage. The scale factor is @code{TH_USAGE_SCALE}.
  3477. @item int base_priority
  3478. The base scheduling priority of the thread.
  3479. @item int cur_priority
  3480. The current scheduling priority of the thread.
  3481. @item integer_t run_state
  3482. The run state of the thread. The possible values of this field are:
  3483. @table @code
  3484. @item TH_STATE_RUNNING
  3485. The thread is running normally.
  3486. @item TH_STATE_STOPPED
  3487. The thread is suspended.
  3488. @item TH_STATE_WAITING
  3489. The thread is waiting normally.
  3490. @item TH_STATE_UNINTERRUPTIBLE
  3491. The thread is in an uninterruptible wait.
  3492. @item TH_STATE_HALTED
  3493. The thread is halted at a clean point.
  3494. @end table
  3495. @item flags
  3496. Various flags. The possible values of this field are:
  3497. @table @code
  3498. @item TH_FLAGS_SWAPPED
  3499. The thread is swapped out.
  3500. @item TH_FLAGS_IDLE
  3501. The thread is an idle thread.
  3502. @end table
  3503. @item int suspend_count
  3504. The suspend count for the thread.
  3505. @item int sleep_time
  3506. The number of seconds that the thread has been sleeping.
  3507. @item time_value_t creation_time
  3508. The time stamp of creation.
  3509. @end table
  3510. @end deftp
  3511. @deftp {Data type} thread_basic_info_t
  3512. This is a pointer to a @code{struct thread_basic_info}.
  3513. @end deftp
  3514. @deftp {Data type} {struct thread_sched_info}
  3515. This structure is returned in @var{thread_info} by the
  3516. @code{thread_info} function and provides schedule information about the
  3517. thread. You can cast a variable of type @code{thread_info_t} to a
  3518. pointer of this type if you provided it as the @var{thread_info}
  3519. parameter for the @code{THREAD_SCHED_INFO} flavor of @code{thread_info}.
  3520. It has the following members:
  3521. @table @code
  3522. @item int policy
  3523. The scheduling policy of the thread, @ref{Scheduling Policy}.
  3524. @item integer_t data
  3525. Policy-dependent scheduling information, @ref{Scheduling Policy}.
  3526. @item int base_priority
  3527. The base scheduling priority of the thread.
  3528. @item int max_priority
  3529. The maximum scheduling priority of the thread.
  3530. @item int cur_priority
  3531. The current scheduling priority of the thread.
  3532. @item int depressed
  3533. @code{TRUE} if the thread is depressed.
  3534. @item int depress_priority
  3535. The priority the thread was depressed from.
  3536. @end table
  3537. @end deftp
  3538. @deftp {Data type} thread_sched_info_t
  3539. This is a pointer to a @code{struct thread_sched_info}.
  3540. @end deftp
  3541. @node Thread Settings
  3542. @subsection Thread Settings
  3543. @deftypefun kern_return_t thread_wire (@w{host_priv_t @var{host_priv}}, @w{thread_t @var{thread}}, @w{boolean_t @var{wired}})
  3544. The function @code{thread_wire} controls the VM privilege level of the
  3545. thread @var{thread}. A VM-privileged thread never waits inside the
  3546. kernel for memory allocation from the kernel's free list of pages or for
  3547. allocation of a kernel stack.
  3548. Threads that are part of the default pageout path should be
  3549. VM-privileged, to prevent system deadlocks. Threads that are not part
  3550. of the default pageout path should not be VM-privileged, to prevent the
  3551. kernel's free list of pages from being exhausted.
  3552. The functions returns @code{KERN_SUCCESS} if the call succeeded,
  3553. @code{KERN_INVALID_ARGUMENT} if @var{host_priv} or @var{thread} was
  3554. invalid.
  3555. The @code{thread_wire} call is actually an RPC to @var{host_priv},
  3556. normally a send right for a privileged host port, but potentially any
  3557. send right. In addition to the normal diagnostic return codes from the
  3558. call's server (normally the kernel), the call may return @code{mach_msg}
  3559. return codes.
  3560. @c See also: vm_wire(2), vm_set_default_memory_manager(2).
  3561. @end deftypefun
  3562. @node Thread Execution
  3563. @subsection Thread Execution
  3564. @deftypefun kern_return_t thread_suspend (@w{thread_t @var{target_thread}})
  3565. Increments the thread's suspend count and prevents the thread from
  3566. executing any more user level instructions. In this context a user
  3567. level instruction is either a machine instruction executed in user mode
  3568. or a system trap instruction including page faults. Thus if a thread is
  3569. currently executing within a system trap the kernel code may continue to
  3570. execute until it reaches the system return code or it may suspend within
  3571. the kernel code. In either case, when the thread is resumed the system
  3572. trap will return. This could cause unpredictable results if the user
  3573. did a suspend and then altered the user state of the thread in order to
  3574. change its direction upon a resume. The call @code{thread_abort} is
  3575. provided to allow the user to abort any system call that is in progress
  3576. in a predictable way.
  3577. The suspend count may become greater than one with the effect that it
  3578. will take more than one resume call to restart the thread.
  3579. The function returns @code{KERN_SUCCESS} if the thread has been
  3580. suspended and @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not
  3581. a thread.
  3582. @end deftypefun
  3583. @deftypefun kern_return_t thread_resume (@w{thread_t @var{target_thread}})
  3584. Decrements the thread's suspend count. If the count becomes zero the
  3585. thread is resumed. If it is still positive, the thread is left
  3586. suspended. The suspend count may not become negative.
  3587. The function returns @code{KERN_SUCCESS} if the thread has been resumed,
  3588. @code{KERN_FAILURE} if the suspend count is already zero and
  3589. @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread.
  3590. @end deftypefun
  3591. @deftypefun kern_return_t thread_abort (@w{thread_t @var{target_thread}})
  3592. The function @code{thread_abort} aborts the kernel primitives:
  3593. @code{mach_msg}, @code{msg_send}, @code{msg_receive} and @code{msg_rpc}
  3594. and page-faults, making the call return a code indicating that it was
  3595. interrupted. The call is interrupted whether or not the thread (or task
  3596. containing it) is currently suspended. If it is suspended, the thread
  3597. receives the interrupt when it is resumed.
  3598. A thread will retry an aborted page-fault if its state is not modified
  3599. before it is resumed. @code{msg_send} returns @code{SEND_INTERRUPTED};
  3600. @code{msg_receive} returns @code{RCV_INTERRUPTED}; @code{msg_rpc}
  3601. returns either @code{SEND_INTERRUPTED} or @code{RCV_INTERRUPTED},
  3602. depending on which half of the RPC was interrupted.
  3603. The main reason for this primitive is to allow one thread to cleanly
  3604. stop another thread in a manner that will allow the future execution of
  3605. the target thread to be controlled in a predictable way.
  3606. @code{thread_suspend} keeps the target thread from executing any further
  3607. instructions at the user level, including the return from a system call.
  3608. @code{thread_get_state}/@code{thread_set_state} allows the examination
  3609. or modification of the user state of a target thread. However, if a
  3610. suspended thread was executing within a system call, it also has
  3611. associated with it a kernel state. This kernel state can not be
  3612. modified by @code{thread_set_state} with the result that when the thread
  3613. is resumed the system call may return changing the user state and
  3614. possibly user memory. @code{thread_abort} aborts the kernel call from
  3615. the target thread's point of view by resetting the kernel state so that
  3616. the thread will resume execution at the system call return with the
  3617. return code value set to one of the interrupted codes. The system call
  3618. itself will either be entirely completed or entirely aborted, depending
  3619. on the precise moment at which the abort was received. Thus if the
  3620. thread's user state has been changed by @code{thread_set_state}, it will
  3621. not be modified by any unexpected system call side effects.
  3622. For example to simulate a Unix signal, the following sequence of calls
  3623. may be used:
  3624. @enumerate
  3625. @item
  3626. @code{thread_suspend}: Stops the thread.
  3627. @item
  3628. @code{thread_abort}: Interrupts any system call in progress, setting the
  3629. return value to `interrupted'. Since the thread is stopped, it will not
  3630. return to user code.
  3631. @item
  3632. @code{thread_set_state}: Alters thread's state to simulate a procedure
  3633. call to the signal handler
  3634. @item
  3635. @code{thread_resume}: Resumes execution at the signal handler. If the
  3636. thread's stack has been correctly set up, the thread may return to the
  3637. interrupted system call. (Of course, the code to push an extra stack
  3638. frame and change the registers is VERY machine-dependent.)
  3639. @end enumerate
  3640. Calling @code{thread_abort} on a non-suspended thread is pretty risky,
  3641. since it is very difficult to know exactly what system trap, if any, the
  3642. thread might be executing and whether an interrupt return would cause
  3643. the thread to do something useful.
  3644. The function returns @code{KERN_SUCCESS} if the thread received an
  3645. interrupt and @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not
  3646. a thread.
  3647. @end deftypefun
  3648. @deftypefun kern_return_t thread_get_state (@w{thread_t @var{target_thread}}, @w{int @var{flavor}}, @w{thread_state_t @var{old_state}}, @w{mach_msg_type_number_t *@var{old_stateCnt}})
  3649. The function @code{thread_get_state} returns the execution state
  3650. (e.g. the machine registers) of @var{target_thread} as specified by
  3651. @var{flavor}. The @var{old_state} is an array of integers that is
  3652. provided by the caller and returned filled with the specified
  3653. information. @var{old_stateCnt} is input set to the maximum number of
  3654. integers in @var{old_state} and returned equal to the actual number of
  3655. integers in @var{old_state}.
  3656. @var{target_thread} may not be @code{mach_thread_self()}.
  3657. The definition of the state structures can be found in
  3658. @file{machine/thread_status.h}.
  3659. The function returns @code{KERN_SUCCESS} if the state has been returned,
  3660. @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread or
  3661. is @code{mach_thread_self} or @var{flavor} is unrecognized for this machine.
  3662. The function returns @code{MIG_ARRAY_TOO_LARGE} if the returned state is
  3663. too large for @var{old_state}. In this case, @var{old_state} is filled
  3664. as much as possible and @var{old_stateCnt} is set to the number of
  3665. elements that would have been returned if there were enough room.
  3666. @end deftypefun
  3667. @deftypefun kern_return_t thread_set_state (@w{thread_t @var{target_thread}}, @w{int @var{flavor}}, @w{thread_state_t @var{new_state}}, @w{mach_msg_type_number_t @var{new_state_count}})
  3668. The function @code{thread_set_state} sets the execution state (e.g. the
  3669. machine registers) of @var{target_thread} as specified by @var{flavor}.
  3670. The @var{new_state} is an array of integers. @var{new_state_count} is
  3671. the number of elements in @var{new_state}. The entire set of registers
  3672. is reset. This will do unpredictable things if @var{target_thread} is
  3673. not suspended.
  3674. @var{target_thread} may not be @code{mach_thread_self}.
  3675. The definition of the state structures can be found in
  3676. @file{machine/thread_status.h}.
  3677. The function returns @code{KERN_SUCCESS} if the state has been set and
  3678. @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread or
  3679. is @code{mach_thread_self} or @var{flavor} is unrecognized for this
  3680. machine.
  3681. @end deftypefun
  3682. @node Scheduling
  3683. @subsection Scheduling
  3684. @menu
  3685. * Thread Priority:: Changing the priority of a thread.
  3686. * Hand-Off Scheduling:: Switching to a new thread.
  3687. * Scheduling Policy:: Setting the scheduling policy.
  3688. @end menu
  3689. @node Thread Priority
  3690. @subsubsection Thread Priority
  3691. Threads have three priorities associated with them by the system, a
  3692. priority, a maximum priority, and a scheduled priority. The scheduled
  3693. priority is used to make scheduling decisions about the thread. It is
  3694. determined from the priority by the policy (for timesharing, this means
  3695. adding an increment derived from cpu usage). The priority can be set
  3696. under user control, but may never exceed the maximum priority. Changing
  3697. the maximum priority requires presentation of the control port for the
  3698. thread's processor set; since the control port for the default processor
  3699. set is privileged, users cannot raise their maximum priority to unfairly
  3700. compete with other users on that set. Newly created threads obtain
  3701. their priority from their task and their max priority from the thread.
  3702. @deftypefun kern_return_t thread_priority (@w{thread_t @var{thread}}, @w{int @var{prority}}, @w{boolean_t @var{set_max}})
  3703. The function @code{thread_priority} changes the priority and optionally
  3704. the maximum priority of @var{thread}. Priorities range from 0 to 49,
  3705. where lower numbers denote higher priorities. If the new priority is
  3706. higher than the priority of the current thread, preemption may occur as
  3707. a result of this call. The maximum priority of the thread is also set
  3708. if @var{set_max} is @code{TRUE}. This call will fail if @var{priority}
  3709. is greater than the current maximum priority of the thread. As a
  3710. result, this call can only lower the value of a thread's maximum
  3711. priority.
  3712. The functions returns @code{KERN_SUCCESS} if the operation completed
  3713. successfully, @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a
  3714. thread or @var{priority} is out of range (not in 0..49), and
  3715. @code{KERN_FAILURE} if the requested operation would violate the
  3716. thread's maximum priority (thread_priority).
  3717. @end deftypefun
  3718. @deftypefun kern_return_t thread_max_priority (@w{thread_t @var{thread}}, @w{processor_set_t @var{processor_set}}, @w{int @var{priority}})
  3719. The function @code{thread_max_priority} changes the maximum priority of
  3720. the thread. Because it requires presentation of the corresponding
  3721. processor set port, this call can reset the maximum priority to any
  3722. legal value.
  3723. The functions returns @code{KERN_SUCCESS} if the operation completed
  3724. successfully, @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a
  3725. thread or @var{processor_set} is not a control port for a processor set
  3726. or @var{priority} is out of range (not in 0..49), and
  3727. @code{KERN_FAILURE} if the thread is not assigned to the processor set
  3728. whose control port was presented.
  3729. @end deftypefun
  3730. @node Hand-Off Scheduling
  3731. @subsubsection Hand-Off Scheduling
  3732. @deftypefun kern_return_t thread_switch (@w{thread_t @var{new_thread}}, @w{int @var{option}}, @w{int @var{time}})
  3733. The function @code{thread_switch} provides low-level access to the
  3734. scheduler's context switching code. @var{new_thread} is a hint that
  3735. implements hand-off scheduling. The operating system will attempt to
  3736. switch directly to the new thread (bypassing the normal logic that
  3737. selects the next thread to run) if possible. Since this is a hint, it
  3738. may be incorrect; it is ignored if it doesn't specify a thread on the
  3739. same host as the current thread or if that thread can't be switched to
  3740. (i.e., not runnable or already running on another processor or giving
  3741. a plainly invalid hint, such as @code{MACH_PORT_NULL}). In this case,
  3742. the normal logic to select the next thread to run is used; the current
  3743. thread may continue running if there is no other appropriate thread to
  3744. run.
  3745. Options for @var{option} are defined in @file{mach/thread_switch.h} and
  3746. specify the interpretation of @var{time}. The possible values for
  3747. @var{option} are:
  3748. @table @code
  3749. @item SWITCH_OPTION_NONE
  3750. No options, the time argument is ignored.
  3751. @item SWITCH_OPTION_WAIT
  3752. The thread is blocked for the specified time (in milliseconds;
  3753. specifying @code{0} will wait for the next tick). This can be aborted
  3754. by @code{thread_abort}.
  3755. @item SWITCH_OPTION_DEPRESS
  3756. The thread's priority is depressed to the lowest possible value for the
  3757. specified time. This can be aborted by @code{thread_depress_abort}.
  3758. This depression is independent of operations that change the thread's
  3759. priority (e.g. @code{thread_priority} will not abort the depression).
  3760. The minimum time and units of time can be obtained as the
  3761. @code{min_timeout} value from @code{host_info}. The depression is also
  3762. aborted when the current thread is next run (either via hand-off
  3763. scheduling or because the processor set has nothing better to do).
  3764. @end table
  3765. @code{thread_switch} is often called when the current thread can proceed
  3766. no further for some reason; the various options and arguments allow
  3767. information about this reason to be transmitted to the kernel. The
  3768. @var{new_thread} argument (handoff scheduling) is useful when the
  3769. identity of the thread that must make progress before the current thread
  3770. runs again is known. The @code{WAIT} option is used when the amount of
  3771. time that the current thread must wait before it can do anything useful
  3772. can be estimated and is fairly long. The @code{DEPRESS} option is used
  3773. when the amount of time that must be waited is fairly short, especially
  3774. when the identity of the thread that is being waited for is not known.
  3775. Users should beware of calling @code{thread_switch} with an invalid hint
  3776. (e.g. @code{MACH_PORT_NULL}) and no option. Because the time-sharing
  3777. scheduler varies the priority of threads based on usage, this may result
  3778. in a waste of cpu time if the thread that must be run is of lower
  3779. priority. The use of the @code{DEPRESS} option in this situation is
  3780. highly recommended.
  3781. @code{thread_switch} ignores policies. Users relying on the preemption
  3782. semantics of a fixed time policy should be aware that
  3783. @code{thread_switch} ignores these semantics; it will run the specified
  3784. @var{new_thread} independent of its priority and the priority of any other
  3785. threads that could be run instead.
  3786. The function returns @code{KERN_SUCCESS} if the call succeeded,
  3787. @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a thread or
  3788. @var{option} is not a recognized option, and @code{KERN_FAILURE} if
  3789. @code{kern_depress_abort} failed because the thread was not depressed.
  3790. @end deftypefun
  3791. @deftypefun kern_return_t thread_depress_abort (@w{thread_t @var{thread}})
  3792. The function @code{thread_depress_abort} cancels any priority depression
  3793. for @var{thread} caused by a @code{swtch_pri} or @code{thread_switch}
  3794. call.
  3795. The function returns @code{KERN_SUCCESS} if the call succeeded and
  3796. @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a valid thread.
  3797. @end deftypefun
  3798. @deftypefun boolean_t swtch ()
  3799. @c XXX Clear up wording.
  3800. The system trap @code{swtch} attempts to switch the current thread off
  3801. the processor. The return value indicates if more than the current
  3802. thread is running in the processor set. This is useful for lock
  3803. management routines.
  3804. The call returns @code{FALSE} if the thread is justified in becoming a
  3805. resource hog by continuing to spin because there's nothing else useful
  3806. that the processor could do. @code{TRUE} is returned if the thread
  3807. should make one more check on the lock and then be a good citizen and
  3808. really suspend.
  3809. @end deftypefun
  3810. @deftypefun boolean_t swtch_pri (@w{int @var{priority}})
  3811. The system trap @code{swtch_pri} attempts to switch the current thread
  3812. off the processor as @code{swtch} does, but depressing the priority of
  3813. the thread to the minimum possible value during the time.
  3814. @var{priority} is not used currently.
  3815. The return value is as for @code{swtch}.
  3816. @end deftypefun
  3817. @node Scheduling Policy
  3818. @subsubsection Scheduling Policy
  3819. @deftypefun kern_return_t thread_policy (@w{thread_t @var{thread}}, @w{int @var{policy}}, @w{int @var{data}})
  3820. The function @code{thread_policy} changes the scheduling policy for
  3821. @var{thread} to @var{policy}.
  3822. @var{data} is policy-dependent scheduling information. There are
  3823. currently two supported policies: @code{POLICY_TIMESHARE} and
  3824. @code{POLICY_FIXEDPRI} defined in @file{mach/policy.h}; this file is
  3825. included by @file{mach.h}. @var{data} is meaningless for timesharing,
  3826. but is the quantum to be used (in milliseconds) for the fixed priority
  3827. policy. To be meaningful, this quantum must be a multiple of the basic
  3828. system quantum (min_quantum) which can be obtained from
  3829. @code{host_info}. The system will always round up to the next multiple
  3830. of the quantum.
  3831. Processor sets may restrict the allowed policies, so this call will fail
  3832. if the processor set to which @var{thread} is currently assigned does
  3833. not permit @var{policy}.
  3834. The function returns @code{KERN_SUCCESS} if the call succeeded.
  3835. @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a thread or
  3836. @var{policy} is not a recognized policy, and @code{KERN_FAILURE} if the
  3837. processor set to which @var{thread} is currently assigned does not
  3838. permit @var{policy}.
  3839. @end deftypefun
  3840. @node Thread Special Ports
  3841. @subsection Thread Special Ports
  3842. @deftypefun kern_return_t thread_get_special_port (@w{thread_t @var{thread}}, @w{int @var{which_port}}, @w{mach_port_t *@var{special_port}})
  3843. The function @code{thread_get_special_port} returns send rights to one
  3844. of a set of special ports for the thread specified by @var{thread}.
  3845. The possible values for @var{which_port} are @code{THREAD_KERNEL_PORT}
  3846. and @code{THREAD_EXCEPTION_PORT}. A thread also has access to its
  3847. task's special ports.
  3848. The function returns @code{KERN_SUCCESS} if the port was returned and
  3849. @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a thread or
  3850. @var{which_port} is an invalid port selector.
  3851. @end deftypefun
  3852. @deftypefun kern_return_t thread_get_kernel_port (@w{thread_t @var{thread}}, @w{mach_port_t *@var{kernel_port}})
  3853. The function @code{thread_get_kernel_port} is equivalent to the function
  3854. @code{thread_get_special_port} with the @var{which_port} argument set to
  3855. @code{THREAD_KERNEL_PORT}.
  3856. @end deftypefun
  3857. @deftypefun kern_return_t thread_get_exception_port (@w{thread_t @var{thread}}, @w{mach_port_t *@var{exception_port}})
  3858. The function @code{thread_get_exception_port} is equivalent to the
  3859. function @code{thread_get_special_port} with the @var{which_port}
  3860. argument set to @code{THREAD_EXCEPTION_PORT}.
  3861. @end deftypefun
  3862. @deftypefun kern_return_t thread_set_special_port (@w{thread_t @var{thread}}, @w{int @var{which_port}}, @w{mach_port_t @var{special_port}})
  3863. The function @code{thread_set_special_port} sets one of a set of special
  3864. ports for the thread specified by @var{thread}.
  3865. The possible values for @var{which_port} are @code{THREAD_KERNEL_PORT}
  3866. and @code{THREAD_EXCEPTION_PORT}. A thread also has access to its
  3867. task's special ports.
  3868. The function returns @code{KERN_SUCCESS} if the port was set and
  3869. @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a thread or
  3870. @var{which_port} is an invalid port selector.
  3871. @end deftypefun
  3872. @deftypefun kern_return_t thread_set_kernel_port (@w{thread_t @var{thread}}, @w{mach_port_t @var{kernel_port}})
  3873. The function @code{thread_set_kernel_port} is equivalent to the function
  3874. @code{thread_set_special_port} with the @var{which_port} argument set to
  3875. @code{THREAD_KERNEL_PORT}.
  3876. @end deftypefun
  3877. @deftypefun kern_return_t thread_set_exception_port (@w{thread_t @var{thread}}, @w{mach_port_t @var{exception_port}})
  3878. The function @code{thread_set_exception_port} is equivalent to the
  3879. function @code{thread_set_special_port} with the @var{which_port}
  3880. argument set to @code{THREAD_EXCEPTION_PORT}.
  3881. @end deftypefun
  3882. @node Exceptions
  3883. @subsection Exceptions
  3884. @deftypefun kern_return_t catch_exception_raise (@w{mach_port_t @var{exception_port}}, @w{thread_t @var{thread}}, @w{task_t @var{task}}, @w{int @var{exception}}, @w{int @var{code}}, @w{int @var{subcode}})
  3885. XXX Fixme
  3886. @end deftypefun
  3887. @deftypefun kern_return_t exception_raise (@w{mach_port_t @var{exception_port}}, @w{mach_port_t @var{thread}}, @w{mach_port_t @var{task}}, @w{integer_t @var{exception}}, @w{integer_t @var{code}}, @w{integer_t @var{subcode}})
  3888. XXX Fixme
  3889. @end deftypefun
  3890. @deftypefun kern_return_t evc_wait (@w{unsigned int @var{event}})
  3891. @c XXX This is for user space drivers, the description is incomplete.
  3892. The system trap @code{evc_wait} makes the calling thread wait for the
  3893. event specified by @var{event}.
  3894. The call returns @code{KERN_SUCCESS} if the event has occurred,
  3895. @code{KERN_NO_SPACE} if another thread is waiting for the same event and
  3896. @code{KERN_INVALID_ARGUMENT} if the event object is invalid.
  3897. @end deftypefun
  3898. @node Task Interface
  3899. @section Task Interface
  3900. @cindex task port
  3901. @cindex port representing a task
  3902. @deftp {Data type} task_t
  3903. This is a @code{mach_port_t} and used to hold the port name of a task
  3904. port that represents the thread. Manipulations of the task are
  3905. implemented as remote procedure calls to the task port. A task can get
  3906. a port to itself with the @code{mach_task_self} system call.
  3907. The task port name is also used to identify the task's IPC space
  3908. (@pxref{Port Manipulation Interface}) and the task's virtual memory map
  3909. (@pxref{Virtual Memory Interface}).
  3910. @end deftp
  3911. @menu
  3912. * Task Creation:: Creating tasks.
  3913. * Task Termination:: Terminating tasks.
  3914. * Task Information:: Informations on tasks.
  3915. * Task Execution:: Thread scheduling in a task.
  3916. * Task Special Ports:: How to get and set the task's special ports.
  3917. * Syscall Emulation:: How to emulate system calls.
  3918. @end menu
  3919. @node Task Creation
  3920. @subsection Task Creation
  3921. @deftypefun kern_return_t task_create (@w{task_t @var{parent_task}}, @w{boolean_t @var{inherit_memory}}, @w{task_t *@var{child_task}})
  3922. The function @code{task_create} creates a new task from
  3923. @var{parent_task}; the resulting task (@var{child_task}) acquires shared
  3924. or copied parts of the parent's address space (see @code{vm_inherit}).
  3925. The child task initially contains no threads.
  3926. If @var{inherit_memory} is set, the child task's address space is built
  3927. from the parent task according to its memory inheritance values;
  3928. otherwise, the child task is given an empty address space.
  3929. The child task gets the three special ports created or copied for it at
  3930. task creation. The @code{TASK_KERNEL_PORT} is created and send rights
  3931. for it are given to the child and returned to the caller.
  3932. @c The following is only relevant if MACH_IPC_COMPAT is used.
  3933. @c The @code{TASK_NOTIFY_PORT} is created and receive, ownership and send rights
  3934. @c for it are given to the child. The caller has no access to it.
  3935. The @code{TASK_BOOTSTRAP_PORT} and the @code{TASK_EXCEPTION_PORT} are
  3936. inherited from the parent task. The new task can get send rights to
  3937. these ports with the call @code{task_get_special_port}.
  3938. The function returns @code{KERN_SUCCESS} if a new task has been created,
  3939. @code{KERN_INVALID_ARGUMENT} if @var{parent_task} is not a valid task
  3940. port and @code{KERN_RESOURCE_SHORTAGE} if some critical kernel resource
  3941. is unavailable.
  3942. @end deftypefun
  3943. @node Task Termination
  3944. @subsection Task Termination
  3945. @deftypefun kern_return_t task_terminate (@w{task_t @var{target_task}})
  3946. The function @code{task_terminate} destroys the task specified by
  3947. @var{target_task} and all its threads. All resources that are used only
  3948. by this task are freed. Any port to which this task has receive and
  3949. ownership rights is destroyed.
  3950. The function returns @code{KERN_SUCCESS} if the task has been killed,
  3951. @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a task.
  3952. @end deftypefun
  3953. @node Task Information
  3954. @subsection Task Information
  3955. @deftypefun task_t mach_task_self ()
  3956. The @code{mach_task_self} system call returns the calling thread's task
  3957. port.
  3958. @code{mach_task_self} has an effect equivalent to receiving a send right
  3959. for the task port. @code{mach_task_self} returns the name of the send
  3960. right. In particular, successive calls will increase the calling task's
  3961. user-reference count for the send right.
  3962. As a special exception, the kernel will overrun the user reference count
  3963. of the task name port, so that this function can not fail for that
  3964. reason. Because of this, the user should not deallocate the port right
  3965. if an overrun might have happened. Otherwise the reference count could
  3966. drop to zero and the send right be destroyed while the user still
  3967. expects to be able to use it. As the kernel does not make use of the
  3968. number of extant send rights anyway, this is safe to do (the task port
  3969. itself is not destroyed, even when there are no send rights anymore).
  3970. The function returns @code{MACH_PORT_NULL} if a resource shortage
  3971. prevented the reception of the send right, @code{MACH_PORT_NULL} if the
  3972. task port is currently null, @code{MACH_PORT_DEAD} if the task port is
  3973. currently dead.
  3974. @end deftypefun
  3975. @deftypefun kern_return_t task_threads (@w{task_t @var{target_task}}, @w{thread_array_t *@var{thread_list}}, @w{mach_msg_type_number_t *@var{thread_count}})
  3976. The function @code{task_threads} gets send rights to the kernel port for
  3977. each thread contained in @var{target_task}. @var{thread_list} is an
  3978. array that is created as a result of this call. The caller may wish to
  3979. @code{vm_deallocate} this array when the data is no longer needed.
  3980. The function returns @code{KERN_SUCCESS} if the call succeeded and
  3981. @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a task.
  3982. @end deftypefun
  3983. @deftypefun kern_return_t task_info (@w{task_t @var{target_task}}, @w{int @var{flavor}}, @w{task_info_t @var{task_info}}, @w{mach_msg_type_number_t *@var{task_info_count}})
  3984. The function @code{task_info} returns the selected information array for
  3985. a task, as specified by @var{flavor}. @var{task_info} is an array of
  3986. integers that is supplied by the caller, and filled with specified
  3987. information. @var{task_info_count} is supplied as the maximum number of
  3988. integers in @var{task_info}. On return, it contains the actual number
  3989. of integers in @var{task_info}. The maximum number of integers returned
  3990. by any flavor is @code{TASK_INFO_MAX}.
  3991. The type of information returned is defined by @var{flavor}, which can
  3992. be one of the following:
  3993. @table @code
  3994. @item TASK_BASIC_INFO
  3995. The function returns basic information about the task, as defined by
  3996. @code{task_basic_info_t}. This includes the user and system time and
  3997. memory consumption. The number of integers returned is
  3998. @code{TASK_BASIC_INFO_COUNT}.
  3999. @item TASK_EVENTS_INFO
  4000. The function returns information about events for the task as defined by
  4001. @code{thread_sched_info_t}. This includes statistics about virtual
  4002. memory and IPC events like pageouts, pageins and messages sent and
  4003. received. The number of integers returned is
  4004. @code{TASK_EVENTS_INFO_COUNT}.
  4005. @item TASK_THREAD_TIMES_INFO
  4006. The function returns information about the total time for live threads
  4007. as defined by @code{task_thread_times_info_t}. The number of integers
  4008. returned is @code{TASK_THREAD_TIMES_INFO_COUNT}.
  4009. @end table
  4010. The function returns @code{KERN_SUCCESS} if the call succeeded and
  4011. @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a thread or
  4012. @var{flavor} is not recognized. The function returns
  4013. @code{MIG_ARRAY_TOO_LARGE} if the returned info array is too large for
  4014. @var{task_info}. In this case, @var{task_info} is filled as much as
  4015. possible and @var{task_infoCnt} is set to the number of elements that
  4016. would have been returned if there were enough room.
  4017. @end deftypefun
  4018. @deftp {Data type} {struct task_basic_info}
  4019. This structure is returned in @var{task_info} by the @code{task_info}
  4020. function and provides basic information about the task. You can cast a
  4021. variable of type @code{task_info_t} to a pointer of this type if you
  4022. provided it as the @var{task_info} parameter for the
  4023. @code{TASK_BASIC_INFO} flavor of @code{task_info}. It has the following
  4024. members:
  4025. @table @code
  4026. @item integer_t suspend_count
  4027. suspend count for task
  4028. @item integer_t base_priority
  4029. base scheduling priority
  4030. @item vm_size_t virtual_size
  4031. number of virtual pages
  4032. @item vm_size_t resident_size
  4033. number of resident pages
  4034. @item time_value_t user_time
  4035. total user run time for terminated threads
  4036. @item time_value_t system_time
  4037. total system run time for terminated threads
  4038. @item time_value_t creation_time
  4039. creation time stamp
  4040. @end table
  4041. @end deftp
  4042. @deftp {Data type} task_basic_info_t
  4043. This is a pointer to a @code{struct task_basic_info}.
  4044. @end deftp
  4045. @deftp {Data type} {struct task_events_info}
  4046. This structure is returned in @var{task_info} by the @code{task_info}
  4047. function and provides event statistics for the task. You can cast a
  4048. variable of type @code{task_info_t} to a pointer of this type if you
  4049. provided it as the @var{task_info} parameter for the
  4050. @code{TASK_EVENTS_INFO} flavor of @code{task_info}. It has the
  4051. following members:
  4052. @table @code
  4053. @item natural_t faults
  4054. number of page faults
  4055. @item natural_t zero_fills
  4056. number of zero fill pages
  4057. @item natural_t reactivations
  4058. number of reactivated pages
  4059. @item natural_t pageins
  4060. number of actual pageins
  4061. @item natural_t cow_faults
  4062. number of copy-on-write faults
  4063. @item natural_t messages_sent
  4064. number of messages sent
  4065. @item natural_t messages_received
  4066. number of messages received
  4067. @end table
  4068. @end deftp
  4069. @deftp {Data type} task_events_info_t
  4070. This is a pointer to a @code{struct task_events_info}.
  4071. @end deftp
  4072. @deftp {Data type} {struct task_thread_times_info}
  4073. This structure is returned in @var{task_info} by the @code{task_info}
  4074. function and provides event statistics for the task. You can cast a
  4075. variable of type @code{task_info_t} to a pointer of this type if you
  4076. provided it as the @var{task_info} parameter for the
  4077. @code{TASK_THREAD_TIMES_INFO} flavor of @code{task_info}. It has the
  4078. following members:
  4079. @table @code
  4080. @item time_value_t user_time
  4081. total user run time for live threads
  4082. @item time_value_t system_time
  4083. total system run time for live threads
  4084. @end table
  4085. @end deftp
  4086. @deftp {Data type} task_thread_times_info_t
  4087. This is a pointer to a @code{struct task_thread_times_info}.
  4088. @end deftp
  4089. @deftypefun kern_return_t task_set_name (@w{task_t @var{target_task}}, @w{kernel_debug_name_t @var{name}})
  4090. The function @code{task_set_name} sets the name of @var{target_task}
  4091. to @var{name}, truncating it if necessary.
  4092. This is a debugging aid. The name is used in diagnostic messages
  4093. printed by the kernel.
  4094. The function returns @code{KERN_SUCCESS} if the call succeeded.
  4095. @end deftypefun
  4096. @node Task Execution
  4097. @subsection Task Execution
  4098. @deftypefun kern_return_t task_suspend (@w{task_t @var{target_task}})
  4099. The function @code{task_suspend} increments the task's suspend count and
  4100. stops all threads in the task. As long as the suspend count is positive
  4101. newly created threads will not run. This call does not return until all
  4102. threads are suspended.
  4103. The count may become greater than one, with the effect that it will take
  4104. more than one resume call to restart the task.
  4105. The function returns @code{KERN_SUCCESS} if the task has been suspended
  4106. and @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a task.
  4107. @end deftypefun
  4108. @deftypefun kern_return_t task_resume (@w{task_t @var{target_task}})
  4109. The function @code{task_resume} decrements the task's suspend count. If
  4110. it becomes zero, all threads with zero suspend counts in the task are
  4111. resumed. The count may not become negative.
  4112. The function returns @code{KERN_SUCCESS} if the task has been resumed,
  4113. @code{KERN_FAILURE} if the suspend count is already at zero and
  4114. @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a task.
  4115. @end deftypefun
  4116. @c XXX Should probably be in the "Scheduling" node of the Thread Interface.
  4117. @deftypefun kern_return_t task_priority (@w{task_t @var{task}}, @w{int @var{priority}}, @w{boolean_t @var{change_threads}})
  4118. The priority of a task is used only for creation of new threads; a new
  4119. thread's priority is set to the enclosing task's priority.
  4120. @code{task_priority} changes this task priority. It also sets the
  4121. priorities of all threads in the task to this new priority if
  4122. @var{change_threads} is @code{TRUE}. Existing threads are not affected
  4123. otherwise. If this priority change violates the maximum priority of
  4124. some threads, as many threads as possible will be changed and an error
  4125. code will be returned.
  4126. The function returns @code{KERN_SUCCESS} if the call succeeded,
  4127. @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task, or
  4128. @var{priority} is not a valid priority and @code{KERN_FAILURE} if
  4129. @var{change_threads} was @code{TRUE} and the attempt to change the
  4130. priority of at least one existing thread failed because the new priority
  4131. would have exceeded that thread's maximum priority.
  4132. @end deftypefun
  4133. @deftypefun kern_return_t task_ras_control (@w{task_t @var{target_task}}, @w{vm_address_t @var{start_pc}}, @w{vm_address_t @var{end_pc}}, @w{int @var{flavor}})
  4134. The function @code{task_ras_control} manipulates a task's set of
  4135. restartable atomic sequences. If a sequence is installed, and any
  4136. thread in the task is preempted within the range
  4137. [@var{start_pc},@var{end_pc}], then the thread is resumed at
  4138. @var{start_pc}. This enables applications to build atomic sequences
  4139. which, when executed to completion, will have executed atomically.
  4140. Restartable atomic sequences are intended to be used on systems that do
  4141. not have hardware support for low-overhead atomic primitives.
  4142. As a thread can be rolled-back, the code in the sequence should have no
  4143. side effects other than a final store at @var{end_pc}. The kernel does
  4144. not guarantee that the sequence is restartable. It assumes the
  4145. application knows what it's doing.
  4146. A task may have a finite number of atomic sequences that is defined at
  4147. compile time.
  4148. The flavor specifies the particular operation that should be applied to
  4149. this restartable atomic sequence. Possible values for flavor can be:
  4150. @table @code
  4151. @item TASK_RAS_CONTROL_PURGE_ALL
  4152. Remove all registered sequences for this task.
  4153. @item TASK_RAS_CONTROL_PURGE_ONE
  4154. Remove the named registered sequence for this task.
  4155. @item TASK_RAS_CONTROL_PURGE_ALL_AND_INSTALL_ONE
  4156. Atomically remove all registered sequences and install the named
  4157. sequence.
  4158. @item TASK_RAS_CONTROL_INSTALL_ONE
  4159. Install this sequence.
  4160. @end table
  4161. The function returns @code{KERN_SUCCESS} if the operation has been
  4162. performed, @code{KERN_INVALID_ADDRESS} if the @var{start_pc} or
  4163. @var{end_pc} values are not a valid address for the requested operation
  4164. (for example, it is invalid to purge a sequence that has not been
  4165. registered), @code{KERN_RESOURCE_SHORTAGE} if an attempt was made to
  4166. install more restartable atomic sequences for a task than can be
  4167. supported by the kernel, @code{KERN_INVALID_VALUE} if a bad flavor was
  4168. specified, @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a
  4169. task and @code{KERN_FAILURE} if the call is not not supported on this
  4170. configuration.
  4171. @end deftypefun
  4172. @node Task Special Ports
  4173. @subsection Task Special Ports
  4174. @deftypefun kern_return_t task_get_special_port (@w{task_t @var{task}}, @w{int @var{which_port}}, @w{mach_port_t *@var{special_port}})
  4175. The function @code{task_get_special_port} returns send rights to one of
  4176. a set of special ports for the task specified by @var{task}.
  4177. The special ports associated with a task are the kernel port
  4178. (@code{TASK_KERNEL_PORT}), the bootstrap port
  4179. (@code{TASK_BOOTSTRAP_PORT}) and the exception port
  4180. (@code{TASK_EXCEPTION_PORT}). The bootstrap port is a port to which a
  4181. task may send a message requesting other system service ports. This
  4182. port is not used by the kernel. The task's exception port is the port
  4183. to which messages are sent by the kernel when an exception occurs and
  4184. the thread causing the exception has no exception port of its own.
  4185. The following macros to call @code{task_get_special_port} for a specific
  4186. port are defined in @code{mach/task_special_ports.h}:
  4187. @code{task_get_exception_port} and @code{task_get_bootstrap_port}.
  4188. The function returns @code{KERN_SUCCESS} if the port was returned and
  4189. @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task or
  4190. @var{which_port} is an invalid port selector.
  4191. @end deftypefun
  4192. @deftypefun kern_return_t task_get_kernel_port (@w{task_t @var{task}}, @w{mach_port_t *@var{kernel_port}})
  4193. The function @code{task_get_kernel_port} is equivalent to the function
  4194. @code{task_get_special_port} with the @var{which_port} argument set to
  4195. @code{TASK_KERNEL_PORT}.
  4196. @end deftypefun
  4197. @deftypefun kern_return_t task_get_exception_port (@w{task_t @var{task}}, @w{mach_port_t *@var{exception_port}})
  4198. The function @code{task_get_exception_port} is equivalent to the
  4199. function @code{task_get_special_port} with the @var{which_port} argument
  4200. set to @code{TASK_EXCEPTION_PORT}.
  4201. @end deftypefun
  4202. @deftypefun kern_return_t task_get_bootstrap_port (@w{task_t @var{task}}, @w{mach_port_t *@var{bootstrap_port}})
  4203. The function @code{task_get_bootstrap_port} is equivalent to the
  4204. function @code{task_get_special_port} with the @var{which_port} argument
  4205. set to @code{TASK_BOOTSTRAP_PORT}.
  4206. @end deftypefun
  4207. @deftypefun kern_return_t task_set_special_port (@w{task_t @var{task}}, @w{int @var{which_port}}, @w{mach_port_t @var{special_port}})
  4208. The function @code{thread_set_special_port} sets one of a set of special
  4209. ports for the task specified by @var{task}.
  4210. The special ports associated with a task are the kernel port
  4211. (@code{TASK_KERNEL_PORT}), the bootstrap port
  4212. (@code{TASK_BOOTSTRAP_PORT}) and the exception port
  4213. (@code{TASK_EXCEPTION_PORT}). The bootstrap port is a port to which a
  4214. thread may send a message requesting other system service ports. This
  4215. port is not used by the kernel. The task's exception port is the port
  4216. to which messages are sent by the kernel when an exception occurs and
  4217. the thread causing the exception has no exception port of its own.
  4218. The function returns @code{KERN_SUCCESS} if the port was set and
  4219. @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task or
  4220. @var{which_port} is an invalid port selector.
  4221. @end deftypefun
  4222. @deftypefun kern_return_t task_set_kernel_port (@w{task_t @var{task}}, @w{mach_port_t @var{kernel_port}})
  4223. The function @code{task_set_kernel_port} is equivalent to the function
  4224. @code{task_set_special_port} with the @var{which_port} argument set to
  4225. @code{TASK_KERNEL_PORT}.
  4226. @end deftypefun
  4227. @deftypefun kern_return_t task_set_exception_port (@w{task_t @var{task}}, @w{mach_port_t @var{exception_port}})
  4228. The function @code{task_set_exception_port} is equivalent to the
  4229. function @code{task_set_special_port} with the @var{which_port} argument
  4230. set to @code{TASK_EXCEPTION_PORT}.
  4231. @end deftypefun
  4232. @deftypefun kern_return_t task_set_bootstrap_port (@w{task_t @var{task}}, @w{mach_port_t @var{bootstrap_port}})
  4233. The function @code{task_set_bootstrap_port} is equivalent to the
  4234. function @code{task_set_special_port} with the @var{which_port} argument
  4235. set to @code{TASK_BOOTSTRAP_PORT}.
  4236. @end deftypefun
  4237. @node Syscall Emulation
  4238. @subsection Syscall Emulation
  4239. @deftypefun kern_return_t task_get_emulation_vector (@w{task_t @var{task}}, @w{int *@var{vector_start}}, @w{emulation_vector_t *@var{emulation_vector}}, @w{mach_msg_type_number_t *@var{emulation_vector_count}})
  4240. The function @code{task_get_emulation_vector} gets the user-level
  4241. handler entry points for all emulated system calls.
  4242. @c XXX Fixme
  4243. @end deftypefun
  4244. @deftypefun kern_return_t task_set_emulation_vector (@w{task_t @var{task}}, @w{int @var{vector_start}}, @w{emulation_vector_t @var{emulation_vector}}, @w{mach_msg_type_number_t @var{emulation_vector_count}})
  4245. The function @code{task_set_emulation_vector} establishes user-level
  4246. handlers for the specified system calls. Non-emulated system calls are
  4247. specified with an entry of @code{EML_ROUTINE_NULL}. System call
  4248. emulation handlers are inherited by the children of @var{task}.
  4249. @c XXX Fixme
  4250. @end deftypefun
  4251. @deftypefun kern_return_t task_set_emulation (@w{task_t @var{task}}, @w{vm_address_t @var{routine_entry_pt}}, @w{int @var{routine_number}})
  4252. The function @code{task_set_emulation} establishes a user-level handler
  4253. for the specified system call. System call emulation handlers are
  4254. inherited by the children of @var{task}.
  4255. @c XXX Fixme
  4256. @end deftypefun
  4257. @c XXX Fixme datatype emulation_vector_t
  4258. @node Profiling
  4259. @section Profiling
  4260. @deftypefun kern_return_t task_enable_pc_sampling (@w{task_t @var{task}}, @w{int *@var{ticks}}, @w{sampled_pc_flavor_t @var{flavor}})
  4261. @deftypefunx kern_return_t thread_enable_pc_sampling (@w{thread_t @var{thread}}, @w{int *@var{ticks}}, @w{sampled_pc_flavor_t @var{flavor}})
  4262. The function @code{task_enable_pc_sampling} enables PC sampling for
  4263. @var{task}, the function @code{thread_enable_pc_sampling} enables PC
  4264. sampling for @var{thread}. The kernel's idea of clock granularity is
  4265. returned in @var{ticks} in usecs. (this value should not be trusted). The
  4266. sampling flavor is specified by @var{flavor}.
  4267. The function returns @code{KERN_SUCCESS} if the operation is completed successfully
  4268. and @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a valid thread.
  4269. @end deftypefun
  4270. @deftypefun kern_return_t task_disable_pc_sampling (@w{task_t @var{task}}, @w{int *@var{sample_count}})
  4271. @deftypefunx kern_return_t thread_disable_pc_sampling (@w{thread_t @var{thread}}, @w{int *@var{sample_count}})
  4272. The function @code{task_disable_pc_sampling} disables PC sampling for
  4273. @var{task}, the function @code{thread_disable_pc_sampling} disables PC
  4274. sampling for @var{thread}. The number of sample elements in the kernel
  4275. for the thread is returned in @var{sample_count}.
  4276. The function returns @code{KERN_SUCCESS} if the operation is completed successfully
  4277. and @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a valid thread.
  4278. @end deftypefun
  4279. @deftypefun kern_return_t task_get_sampled_pcs (@w{task_t @var{task}}, @w{sampled_pc_seqno_t *@var{seqno}}, @w{sampled_pc_array_t @var{sampled_pcs}}, @w{mach_msg_type_number_t *@var{sample_count}})
  4280. @deftypefunx kern_return_t thread_get_sampled_pcs (@w{thread_t @var{thread}}, @w{sampled_pc_seqno_t *@var{seqno}}, @w{sampled_pc_array_t @var{sampled_pcs}}, @w{int *@var{sample_count}})
  4281. The function @code{task_get_sampled_pcs} extracts the PC samples for
  4282. @var{task}, the function @code{thread_get_sampled_pcs} extracts the PC
  4283. samples for @var{thread}. @var{seqno} is the sequence number of the
  4284. sampled PCs. This is useful for determining when a collector thread has
  4285. missed a sample. The sampled PCs for the thread are returned in
  4286. @var{sampled_pcs}. @var{sample_count} contains the number of sample
  4287. elements returned.
  4288. The function returns @code{KERN_SUCCESS} if the operation is completed successfully,
  4289. @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a valid thread and
  4290. @code{KERN_FAILURE} if @var{thread} is not sampled.
  4291. @end deftypefun
  4292. @deftp {Data type} sampled_pc_t
  4293. This structure is returned in @var{sampled_pcs} by the
  4294. @code{thread_get_sampled_pcs} and @code{task_get_sampled_pcs} functions
  4295. and provides pc samples for threads or tasks. It has the following
  4296. members:
  4297. @table @code
  4298. @item natural_t id
  4299. A thread-specific unique identifier.
  4300. @item vm_offset_t pc
  4301. A pc value.
  4302. @item sampled_pc_flavor_t sampletype
  4303. The type of the sample as per flavor.
  4304. @end table
  4305. @end deftp
  4306. @deftp {Data type} sampled_pc_flavor_t
  4307. This data type specifies a pc sample flavor, either as argument passed
  4308. in @var{flavor} to the @code{thread_enable_pc_sample} and
  4309. @code{thread_disable_pc_sample} functions, or as member
  4310. @code{sampletype} in the @code{sample_pc_t} data type. The flavor is a
  4311. bitwise-or of the possible flavors defined in @file{mach/pc_sample.h}:
  4312. @table @code
  4313. @item SAMPLED_PC_PERIODIC
  4314. default
  4315. @item SAMPLED_PC_VM_ZFILL_FAULTS
  4316. zero filled fault
  4317. @item SAMPLED_PC_VM_REACTIVATION_FAULTS
  4318. reactivation fault
  4319. @item SAMPLED_PC_VM_PAGEIN_FAULTS
  4320. pagein fault
  4321. @item SAMPLED_PC_VM_COW_FAULTS
  4322. copy-on-write fault
  4323. @item SAMPLED_PC_VM_FAULTS_ANY
  4324. any fault
  4325. @item SAMPLED_PC_VM_FAULTS
  4326. the bitwise-or of @code{SAMPLED_PC_VM_ZFILL_FAULTS},
  4327. @code{SAMPLED_PC_VM_REACTIVATION_FAULTS},
  4328. @code{SAMPLED_PC_VM_PAGEIN_FAULTS} and @code{SAMPLED_PC_VM_COW_FAULTS}.
  4329. @end table
  4330. @end deftp
  4331. @c XXX sampled_pc_array_t, sampled_pc_seqno_t
  4332. @node Host Interface
  4333. @chapter Host Interface
  4334. @cindex host interface
  4335. This section describes the Mach interface to a host executing a Mach
  4336. kernel. The interface allows to query statistics about a host and
  4337. control its behaviour.
  4338. A host is represented by two ports, a name port @var{host} used to query
  4339. information about the host accessible to everyone, and a control port
  4340. @var{host_priv} used to manipulate it. For example, you can query the
  4341. current time using the name port, but to change the time you need to
  4342. send a message to the host control port.
  4343. Everything described in this section is declared in the header file
  4344. @file{mach.h}.
  4345. @menu
  4346. * Host Ports:: Ports representing a host.
  4347. * Host Information:: Retrieval of information about a host.
  4348. * Host Time:: Operations on the time as seen by a host.
  4349. * Host Reboot:: Rebooting the system.
  4350. @end menu
  4351. @node Host Ports
  4352. @section Host Ports
  4353. @cindex host ports
  4354. @cindex ports representing a host
  4355. @cindex host name port
  4356. @deftp {Data type} host_t
  4357. This is a @code{mach_port_t} and used to hold the port name of a host
  4358. name port (or short: host port). Any task can get a send right to the
  4359. name port of the host running the task using the @code{mach_host_self}
  4360. system call. The name port can be used query information about the
  4361. host, for example the current time.
  4362. @end deftp
  4363. @deftypefun host_t mach_host_self ()
  4364. The @code{mach_host_self} system call returns the calling thread's host
  4365. name port. It has an effect equivalent to receiving a send right for
  4366. the host port. @code{mach_host_self} returns the name of the send
  4367. right. In particular, successive calls will increase the calling task's
  4368. user-reference count for the send right.
  4369. As a special exception, the kernel will overrun the user reference count
  4370. of the host name port, so that this function can not fail for that
  4371. reason. Because of this, the user should not deallocate the port right
  4372. if an overrun might have happened. Otherwise the reference count could
  4373. drop to zero and the send right be destroyed while the user still
  4374. expects to be able to use it. As the kernel does not make use of the
  4375. number of extant send rights anyway, this is safe to do (the host port
  4376. itself is never destroyed).
  4377. The function returns @code{MACH_PORT_NULL} if a resource shortage
  4378. prevented the reception of the send right.
  4379. This function is also available in @file{mach/mach_traps.h}.
  4380. @end deftypefun
  4381. @cindex host control port
  4382. @deftp {Data type} host_priv_t
  4383. This is a @code{mach_port_t} and used to hold the port name of a
  4384. privileged host control port. A send right to the host control port is
  4385. inserted into the first task at bootstrap (@pxref{Modules}). This is
  4386. the only way to get access to the host control port in Mach, so the
  4387. initial task has to preserve the send right carefully, moving a copy of
  4388. it to other privileged tasks if necessary and denying access to
  4389. unprivileged tasks.
  4390. @end deftp
  4391. @node Host Information
  4392. @section Host Information
  4393. @deftypefun kern_return_t host_info (@w{host_t @var{host}}, @w{int @var{flavor}}, @w{host_info_t @var{host_info}}, @w{mach_msg_type_number_t *@var{host_info_count}})
  4394. The @code{host_info} function returns various information about
  4395. @var{host}. @var{host_info} is an array of integers that is supplied by
  4396. the caller. It will be filled with the requested information.
  4397. @var{host_info_count} is supplied as the maximum number of integers in
  4398. @var{host_info}. On return, it contains the actual number of integers
  4399. in @var{host_info}. The maximum number of integers returned by any
  4400. flavor is @code{HOST_INFO_MAX}.
  4401. The type of information returned is defined by @var{flavor}, which can
  4402. be one of the following:
  4403. @table @code
  4404. @item HOST_BASIC_INFO
  4405. The function returns basic information about the host, as defined by
  4406. @code{host_basic_info_t}. This includes the number of processors, their
  4407. type, and the amount of memory installed in the system. The number of
  4408. integers returned is @code{HOST_BASIC_INFO_COUNT}. For how to get more
  4409. information about the processor, see @ref{Processor Interface}.
  4410. @item HOST_PROCESSOR_SLOTS
  4411. The function returns the numbers of the slots with active processors in
  4412. them. The number of integers returned can be up to @code{max_cpus}, as
  4413. returned by the @code{HOST_BASIC_INFO} flavor of @code{host_info}.
  4414. @item HOST_SCHED_INFO
  4415. The function returns information of interest to schedulers as defined by
  4416. @code{host_sched_info_t}. The number of integers returned is
  4417. @code{HOST_SCHED_INFO_COUNT}.
  4418. @end table
  4419. The function returns @code{KERN_SUCCESS} if the call succeeded and
  4420. @code{KERN_INVALID_ARGUMENT} if @var{host} is not a host or @var{flavor}
  4421. is not recognized. The function returns @code{MIG_ARRAY_TOO_LARGE} if
  4422. the returned info array is too large for @var{host_info}. In this case,
  4423. @var{host_info} is filled as much as possible and @var{host_info_count}
  4424. is set to the number of elements that would be returned if there were
  4425. enough room.
  4426. @c BUGS Availability limited. Systems without this call support a
  4427. @c host_info call with an incompatible calling sequence.
  4428. @end deftypefun
  4429. @deftp {Data type} {struct host_basic_info}
  4430. A pointer to this structure is returned in @var{host_info} by the
  4431. @code{host_info} function and provides basic information about the host.
  4432. You can cast a variable of type @code{host_info_t} to a pointer of this
  4433. type if you provided it as the @var{host_info} parameter for the
  4434. @code{HOST_BASIC_INFO} flavor of @code{host_info}. It has the following
  4435. members:
  4436. @table @code
  4437. @item int max_cpus
  4438. The maximum number of possible processors for which the kernel is
  4439. configured.
  4440. @item int avail_cpus
  4441. The number of cpus currently available.
  4442. @item vm_size_t memory_size
  4443. The size of physical memory in bytes.
  4444. @item cpu_type_t cpu_type
  4445. The type of the master processor.
  4446. @item cpu_subtype_t cpu_subtype
  4447. The subtype of the master processor.
  4448. @end table
  4449. The type and subtype of the individual processors are also available
  4450. by @code{processor_info}, see @ref{Processor Interface}.
  4451. @end deftp
  4452. @deftp {Data type} host_basic_info_t
  4453. This is a pointer to a @code{struct host_basic_info}.
  4454. @end deftp
  4455. @deftp {Data type} {struct host_sched_info}
  4456. A pointer to this structure is returned in @var{host_info} by the
  4457. @code{host_info} function and provides information of interest to
  4458. schedulers. You can cast a variable of type @code{host_info_t} to a
  4459. pointer of this type if you provided it as the @var{host_info} parameter
  4460. for the @code{HOST_SCHED_INFO} flavor of @code{host_info}. It has the
  4461. following members:
  4462. @table @code
  4463. @item int min_timeout
  4464. The minimum timeout and unit of time in milliseconds.
  4465. @item int min_quantum
  4466. The minimum quantum and unit of quantum in milliseconds.
  4467. @end table
  4468. @end deftp
  4469. @deftp {Data type} host_sched_info_t
  4470. This is a pointer to a @code{struct host_sched_info}.
  4471. @end deftp
  4472. @deftypefun kern_return_t host_kernel_version (@w{host_t @var{host}}, @w{kernel_version_t *@var{version}})
  4473. The @code{host_kernel_version} function returns the version string
  4474. compiled into the kernel executing on @var{host} at the time it was
  4475. built in the character string @var{version}. This string describes the
  4476. version of the kernel. The constant @code{KERNEL_VERSION_MAX} should be
  4477. used to dimension storage for the returned string if the
  4478. @code{kernel_version_t} declaration is not used.
  4479. If the version string compiled into the kernel is longer than
  4480. @code{KERNEL_VERSION_MAX}, the result is truncated and not necessarily
  4481. null-terminated.
  4482. If @var{host} is not a valid send right to a host port, the function
  4483. returns @code{KERN_INVALID_ARGUMENT}. If @var{version} points to
  4484. inaccessible memory, it returns @code{KERN_INVALID_ADDRESS}, and
  4485. @code{KERN_SUCCESS} otherwise.
  4486. @end deftypefun
  4487. @deftypefun kern_return_t host_get_boot_info (@w{host_priv_t @var{host_priv}}, @w{kernel_boot_info_t @var{boot_info}})
  4488. The @code{host_get_boot_info} function returns the boot-time information
  4489. string supplied by the operator to the kernel executing on
  4490. @var{host_priv} in the character string @var{boot_info}. The constant
  4491. @code{KERNEL_BOOT_INFO_MAX} should be used to dimension storage for the
  4492. returned string if the @code{kernel_boot_info_t} declaration is not
  4493. used.
  4494. If the boot-time information string supplied by the operator is longer
  4495. than @code{KERNEL_BOOT_INFO_MAX}, the result is truncated and not
  4496. necessarily null-terminated.
  4497. @end deftypefun
  4498. @node Host Time
  4499. @section Host Time
  4500. @deftp {Data type} time_value_t
  4501. This is the representation of a time in Mach. It is a @code{struct
  4502. time_value} and consists of the following members:
  4503. @table @code
  4504. @item integer_t seconds
  4505. The number of seconds.
  4506. @item integer_t microseconds
  4507. The number of microseconds.
  4508. @end table
  4509. @end deftp
  4510. The number of microseconds should always be smaller than
  4511. @code{TIME_MICROS_MAX} (100000). A time with this property is
  4512. @dfn{normalized}. Normalized time values can be manipulated with the
  4513. following macros:
  4514. @defmac time_value_add_usec (@w{time_value_t *@var{val}}, @w{integer_t *@var{micros}})
  4515. Add @var{micros} microseconds to @var{val}. If @var{val} is normalized
  4516. and @var{micros} smaller than @code{TIME_MICROS_MAX}, @var{val} will be
  4517. normalized afterwards.
  4518. @end defmac
  4519. @defmac time_value_add (@w{time_value_t *@var{result}}, @w{time_value_t *@var{addend}})
  4520. Add the values in @var{addend} to @var{result}. If both are normalized,
  4521. @var{result} will be normalized afterwards.
  4522. @end defmac
  4523. A variable of type @code{time_value_t} can either represent a duration
  4524. or a fixed point in time. In the latter case, it shall be interpreted as
  4525. the number of seconds and microseconds after the epoch 1. Jan 1970.
  4526. @deftypefun kern_return_t host_get_time (@w{host_t @var{host}}, @w{time_value_t *@var{current_time}})
  4527. Get the current time as seen by @var{host}. On success, the time passed
  4528. since the epoch is returned in @var{current_time}.
  4529. @end deftypefun
  4530. @deftypefun kern_return_t host_set_time (@w{host_priv_t @var{host_priv}}, @w{time_value_t @var{new_time}})
  4531. Set the time of @var{host_priv} to @var{new_time}.
  4532. @end deftypefun
  4533. @deftypefun kern_return_t host_adjust_time (@w{host_priv_t @var{host_priv}}, @w{time_value_t @var{new_adjustment}}, @w{time_value_t *@var{old_adjustment}})
  4534. Arrange for the current time as seen by @var{host_priv} to be gradually
  4535. changed by the adjustment value @var{new_adjustment}, and return the old
  4536. adjustment value in @var{old_adjustment}.
  4537. @end deftypefun
  4538. For efficiency, the current time is available through a mapped-time
  4539. interface.
  4540. @deftp {Data type} mapped_time_value_t
  4541. This structure defines the mapped-time interface. It has the following
  4542. members:
  4543. @table @code
  4544. @item integer_t seconds
  4545. The number of seconds.
  4546. @item integer_t microseconds
  4547. The number of microseconds.
  4548. @item integer_t check_seconds
  4549. This is a copy of the seconds value, which must be checked to protect
  4550. against a race condition when reading out the two time values.
  4551. @end table
  4552. @end deftp
  4553. Here is an example how to read out the current time using the
  4554. mapped-time interface:
  4555. @c XXX Complete the example.
  4556. @example
  4557. do
  4558. @{
  4559. secs = mtime->seconds;
  4560. usecs = mtime->microseconds;
  4561. @}
  4562. while (secs != mtime->check_seconds);
  4563. @end example
  4564. @node Host Reboot
  4565. @section Host Reboot
  4566. @deftypefun kern_return_t host_reboot (@w{host_priv_t @var{host_priv}}, @w{int @var{options}})
  4567. Reboot the host specified by @var{host_priv}. The argument
  4568. @var{options} specifies the flags. The available flags are defined in
  4569. @file{sys/reboot.h}:
  4570. @table @code
  4571. @item RB_HALT
  4572. Do not reboot, but halt the machine.
  4573. @item RB_DEBUGGER
  4574. Do not reboot, but enter kernel debugger from user space.
  4575. @end table
  4576. If successful, the function might not return.
  4577. @end deftypefun
  4578. @node Processors and Processor Sets
  4579. @chapter Processors and Processor Sets
  4580. This section describes the Mach interface to processor sets and
  4581. individual processors. The interface allows to group processors into
  4582. sets and control the processors and processor sets.
  4583. A processor is not a central part of the interface. It is mostly of
  4584. relevance as a part of a processor set. Threads are always assigned to
  4585. processor sets, and all processors in a set are equally involved in
  4586. executing all threads assigned to that set.
  4587. The processor set is represented by two ports, a name port
  4588. @var{processor_set_name} used to query information about the host
  4589. accessible to everyone, and a control port @var{processor_set} used to
  4590. manipulate it.
  4591. @menu
  4592. * Processor Set Interface:: How to work with processor sets.
  4593. * Processor Interface:: How to work with individual processors.
  4594. @end menu
  4595. @node Processor Set Interface
  4596. @section Processor Set Interface
  4597. @menu
  4598. * Processor Set Ports:: Ports representing a processor set.
  4599. * Processor Set Access:: How the processor sets are accessed.
  4600. * Processor Set Creation:: How new processor sets are created.
  4601. * Processor Set Destruction:: How processor sets are destroyed.
  4602. * Tasks and Threads on Sets:: Assigning tasks, threads to processor sets.
  4603. * Processor Set Priority:: Specifying the priority of a processor set.
  4604. * Processor Set Policy:: Changing the processor set policies.
  4605. * Processor Set Info:: Obtaining information about a processor set.
  4606. @end menu
  4607. @node Processor Set Ports
  4608. @subsection Processor Set Ports
  4609. @cindex processor set ports
  4610. @cindex ports representing a processor set
  4611. @cindex processor set name port
  4612. @cindex port representing a processor set name
  4613. @deftp {Data type} processor_set_name_t
  4614. This is a @code{mach_port_t} and used to hold the port name of a
  4615. processor set name port that names the processor set. Any task can get
  4616. a send right to name port of a processor set. The processor set name
  4617. port allows to get information about the processor set.
  4618. @end deftp
  4619. @cindex processor set port
  4620. @deftp {Data type} processor_set_t
  4621. This is a @code{mach_port_t} and used to hold the port name of a
  4622. privileged processor set control port that represents the processor set.
  4623. Operations on the processor set are implemented as remote procedure
  4624. calls to the processor set port. The processor set port allows to
  4625. manipulate the processor set.
  4626. @end deftp
  4627. @node Processor Set Access
  4628. @subsection Processor Set Access
  4629. @deftypefun kern_return_t host_processor_sets (@w{host_t @var{host}}, @w{processor_set_name_array_t *@var{processor_sets}}, @w{mach_msg_type_number_t *@var{processor_sets_count}})
  4630. The function @code{host_processor_sets} gets send rights to the name
  4631. port for each processor set currently assigned to @var{host}.
  4632. @code{host_processor_set_priv} can be used to obtain the control ports
  4633. from these if desired. @var{processor_sets} is an array that is
  4634. created as a result of this call. The caller may wish to
  4635. @code{vm_deallocate} this array when the data is no longer needed.
  4636. @var{processor_sets_count} is set to the number of processor sets in the
  4637. @var{processor_sets}.
  4638. This function returns @code{KERN_SUCCESS} if the call succeeded and
  4639. @code{KERN_INVALID_ARGUMENT} if @var{host} is not a host.
  4640. @end deftypefun
  4641. @deftypefun kern_return_t host_processor_set_priv (@w{host_priv_t @var{host_priv}}, @w{processor_set_name_t @var{set_name}}, @w{processor_set_t *@var{set}})
  4642. The function @code{host_processor_set_priv} allows a privileged
  4643. application to obtain the control port @var{set} for an existing
  4644. processor set from its name port @var{set_name}. The privileged host
  4645. port @var{host_priv} is required.
  4646. This function returns @code{KERN_SUCCESS} if the call succeeded and
  4647. @code{KERN_INVALID_ARGUMENT} if @var{host_priv} is not a valid host
  4648. control port.
  4649. @end deftypefun
  4650. @deftypefun kern_return_t processor_set_default (@w{host_t @var{host}}, @w{processor_set_name_t *@var{default_set}})
  4651. The function @code{processor_set_default} returns the default processor
  4652. set of @var{host} in @var{default_set}. The default processor set is
  4653. used by all threads, tasks, and processors that are not explicitly
  4654. assigned to other sets. processor_set_default returns a port that can
  4655. be used to obtain information about this set (e.g. how many threads are
  4656. assigned to it). This port cannot be used to perform operations on that
  4657. set.
  4658. This function returns @code{KERN_SUCCESS} if the call succeeded,
  4659. @code{KERN_INVALID_ARGUMENT} if @var{host} is not a host and
  4660. @code{KERN_INVALID_ADDRESS} if @var{default_set} points to
  4661. inaccessible memory.
  4662. @end deftypefun
  4663. @node Processor Set Creation
  4664. @subsection Processor Set Creation
  4665. @deftypefun kern_return_t processor_set_create (@w{host_t @var{host}}, @w{processor_set_t *@var{new_set}}, @w{processor_set_name_t *@var{new_name}})
  4666. The function @code{processor_set_create} creates a new processor set on
  4667. @var{host} and returns the two ports associated with it. The port
  4668. returned in @var{new_set} is the actual port representing the set. It
  4669. is used to perform operations such as assigning processors, tasks, or
  4670. threads. The port returned in @var{new_name} identifies the set, and is
  4671. used to obtain information about the set.
  4672. This function returns @code{KERN_SUCCESS} if the call succeeded,
  4673. @code{KERN_INVALID_ARGUMENT} if @var{host} is not a host,
  4674. @code{KERN_INVALID_ADDRESS} if @var{new_set} or @var{new_name} points to
  4675. inaccessible memory and @code{KERN_FAILURE} is the operating system does
  4676. not support processor allocation.
  4677. @end deftypefun
  4678. @node Processor Set Destruction
  4679. @subsection Processor Set Destruction
  4680. @deftypefun kern_return_t processor_set_destroy (@w{processor_set_t @var{processor_set}})
  4681. The function @code{processor_set_destroy} destroys the specified
  4682. processor set. Any assigned processors, tasks, or threads are
  4683. reassigned to the default set. The object port for the processor set is
  4684. required (not the name port). The default processor set cannot be
  4685. destroyed.
  4686. This function returns @code{KERN_SUCCESS} if the set was destroyed,
  4687. @code{KERN_FAILURE} if an attempt was made to destroy the default
  4688. processor set, or the operating system does not support processor
  4689. allocation, and @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is
  4690. not a valid processor set control port.
  4691. @end deftypefun
  4692. @node Tasks and Threads on Sets
  4693. @subsection Tasks and Threads on Sets
  4694. @deftypefun kern_return_t processor_set_tasks (@w{processor_set_t @var{processor_set}}, @w{task_array_t *@var{task_list}}, @w{mach_msg_type_number_t *@var{task_count}})
  4695. The function @code{processor_set_tasks} gets send rights to the kernel
  4696. port for each task currently assigned to @var{processor_set}.
  4697. @var{task_list} is an array that is created as a result of this call.
  4698. The caller may wish to @code{vm_deallocate} this array when the data is
  4699. no longer needed. @var{task_count} is set to the number of tasks in the
  4700. @var{task_list}.
  4701. This function returns @code{KERN_SUCCESS} if the call succeeded and
  4702. @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is not a processor
  4703. set.
  4704. @end deftypefun
  4705. @deftypefun kern_return_t processor_set_threads (@w{processor_set_t @var{processor_set}}, @w{thread_array_t *@var{thread_list}}, @w{mach_msg_type_number_t *@var{thread_count}})
  4706. The function @code{processor_set_thread} gets send rights to the kernel
  4707. port for each thread currently assigned to @var{processor_set}.
  4708. @var{thread_list} is an array that is created as a result of this call.
  4709. The caller may wish to @code{vm_deallocate} this array when the data is
  4710. no longer needed. @var{thread_count} is set to the number of threads in
  4711. the @var{thread_list}.
  4712. This function returns @code{KERN_SUCCESS} if the call succeeded and
  4713. @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is not a processor
  4714. set.
  4715. @end deftypefun
  4716. @deftypefun kern_return_t task_assign (@w{task_t @var{task}}, @w{processor_set_t @var{processor_set}}, @w{boolean_t @var{assign_threads}})
  4717. The function @code{task_assign} assigns @var{task} the set
  4718. @var{processor_set}. This assignment is for the purposes of determining
  4719. the initial assignment of newly created threads in task. Any previous
  4720. assignment of the task is nullified. Existing threads within the task
  4721. are also reassigned if @var{assign_threads} is @code{TRUE}. They are
  4722. not affected if it is @code{FALSE}.
  4723. This function returns @code{KERN_SUCCESS} if the assignment has been
  4724. performed and @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task,
  4725. or @var{processor_set} is not a processor set on the same host as
  4726. @var{task}.
  4727. @end deftypefun
  4728. @deftypefun kern_return_t task_assign_default (@w{task_t @var{task}}, @w{boolean_t @var{assign_threads}})
  4729. The function @code{task_assign_default} is a variant of
  4730. @code{task_assign} that assigns the task to the default processor set on
  4731. that task's host. This variant exists because the control port for the
  4732. default processor set is privileged and not usually available to users.
  4733. This function returns @code{KERN_SUCCESS} if the assignment has been
  4734. performed and @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task.
  4735. @end deftypefun
  4736. @deftypefun kern_return_t task_get_assignment (@w{task_t @var{task}}, @w{processor_set_name_t *@var{assigned_set}})
  4737. The function @code{task_get_assignment} returns the name of the
  4738. processor set to which the thread is currently assigned in
  4739. @var{assigned_set}. This port can only be used to obtain information
  4740. about the processor set.
  4741. This function returns @code{KERN_SUCCESS} if the assignment has been
  4742. performed, @code{KERN_INVALID_ADDRESS} if @var{processor_set} points to
  4743. inaccessible memory, and @code{KERN_INVALID_ARGUMENT} if @var{task} is
  4744. not a task.
  4745. @end deftypefun
  4746. @deftypefun kern_return_t thread_assign (@w{thread_t @var{thread}}, @w{processor_set_t @var{processor_set}})
  4747. The function @code{thread_assign} assigns @var{thread} the set
  4748. @var{processor_set}. After the assignment is completed, the thread only
  4749. executes on processors assigned to the designated processor set. If
  4750. there are no such processors, then the thread is unable to execute. Any
  4751. previous assignment of the thread is nullified. Unix system call
  4752. compatibility code may temporarily force threads to execute on the
  4753. master processor.
  4754. This function returns @code{KERN_SUCCESS} if the assignment has been
  4755. performed and @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a
  4756. thread, or @var{processor_set} is not a processor set on the same host
  4757. as @var{thread}.
  4758. @end deftypefun
  4759. @deftypefun kern_return_t thread_assign_default (@w{thread_t @var{thread}})
  4760. The function @code{thread_assign_default} is a variant of
  4761. @code{thread_assign} that assigns the thread to the default processor
  4762. set on that thread's host. This variant exists because the control port
  4763. for the default processor set is privileged and not usually available
  4764. to users.
  4765. This function returns @code{KERN_SUCCESS} if the assignment has been
  4766. performed and @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a
  4767. thread.
  4768. @end deftypefun
  4769. @deftypefun kern_return_t thread_get_assignment (@w{thread_t @var{thread}}, @w{processor_set_name_t *@var{assigned_set}})
  4770. The function @code{thread_get_assignment} returns the name of the
  4771. processor set to which the thread is currently assigned in
  4772. @var{assigned_set}. This port can only be used to obtain information
  4773. about the processor set.
  4774. This function returns @code{KERN_SUCCESS} if the assignment has been
  4775. performed, @code{KERN_INVALID_ADDRESS} if @var{processor_set} points to
  4776. inaccessible memory, and @code{KERN_INVALID_ARGUMENT} if @var{thread} is
  4777. not a thread.
  4778. @end deftypefun
  4779. @node Processor Set Priority
  4780. @subsection Processor Set Priority
  4781. @deftypefun kern_return_t processor_set_max_priority (@w{processor_set_t @var{processor_set}}, @w{int @var{max_priority}}, @w{boolean_t @var{change_threads}})
  4782. The function @code{processor_set_max_priority} is used to set the
  4783. maximum priority for a processor set. The priority of a processor set
  4784. is used only for newly created threads (thread's maximum priority is set
  4785. to processor set's) and the assignment of threads to the set (thread's
  4786. maximum priority is reduced if it exceeds the set's maximum priority,
  4787. thread's priority is similarly reduced).
  4788. @code{processor_set_max_priority} changes this priority. It also sets
  4789. the maximum priority of all threads assigned to the processor set to
  4790. this new priority if @var{change_threads} is @code{TRUE}. If this
  4791. maximum priority is less than the priorities of any of these threads,
  4792. their priorities will also be set to this new value.
  4793. This function returns @code{KERN_SUCCESS} if the call succeeded and
  4794. @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is not a processor
  4795. set or @var{priority} is not a valid priority.
  4796. @end deftypefun
  4797. @node Processor Set Policy
  4798. @subsection Processor Set Policy
  4799. @deftypefun kern_return_t processor_set_policy_enable (@w{processor_set_t @var{processor_set}}, @w{int @var{policy}})
  4800. @deftypefunx kern_return_t processor_set_policy_disable (@w{processor_set_t @var{processor_set}}, @w{int @var{policy}}, @w{boolean_t @var{change_threads}})
  4801. Processor sets may restrict the scheduling policies to be used for
  4802. threads assigned to them. These two calls provide the mechanism for
  4803. designating permitted and forbidden policies. The current set of
  4804. permitted policies can be obtained from @code{processor_set_info}.
  4805. Timesharing may not be forbidden by any processor set. This is a
  4806. compromise to reduce the complexity of the assign operation; any thread
  4807. whose policy is forbidden by the target processor set has its policy
  4808. reset to timesharing. If the @var{change_threads} argument to
  4809. @code{processor_set_policy_disable} is true, threads currently assigned
  4810. to this processor set and using the newly disabled policy will have
  4811. their policy reset to timesharing.
  4812. @file{mach/policy.h} contains the allowed policies; it is included by
  4813. @file{mach.h}. Not all policies (e.g. fixed priority) are supported by
  4814. all systems.
  4815. This function returns @code{KERN_SUCCESS} if the operation was completed
  4816. successfully and @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is
  4817. not a processor set or @var{policy} is not a valid policy, or an attempt
  4818. was made to disable timesharing.
  4819. @end deftypefun
  4820. @node Processor Set Info
  4821. @subsection Processor Set Info
  4822. @deftypefun kern_return_t processor_set_info (@w{processor_set_name_t @var{set_name}}, @w{int @var{flavor}}, @w{host_t *@var{host}}, @w{processor_set_info_t @var{processor_set_info}}, @w{mach_msg_type_number_t *@var{processor_set_info_count}})
  4823. The function @code{processor_set_info} returns the selected information array
  4824. for a processor set, as specified by @var{flavor}.
  4825. @var{host} is set to the host on which the processor set resides. This
  4826. is the non-privileged host port.
  4827. @var{processor_set_info} is an array of integers that is supplied by the
  4828. caller and returned filled with specified information.
  4829. @var{processor_set_info_count} is supplied as the maximum number of
  4830. integers in @var{processor_set_info}. On return, it contains the actual
  4831. number of integers in @var{processor_set_info}. The maximum number of
  4832. integers returned by any flavor is @code{PROCESSOR_SET_INFO_MAX}.
  4833. The type of information returned is defined by @var{flavor}, which can
  4834. be one of the following:
  4835. @table @code
  4836. @item PROCESSOR_SET_BASIC_INFO
  4837. The function returns basic information about the processor set, as
  4838. defined by @code{processor_set_basic_info_t}. This includes the number
  4839. of tasks and threads assigned to the processor set. The number of
  4840. integers returned is @code{PROCESSOR_SET_BASIC_INFO_COUNT}.
  4841. @item PROCESSOR_SET_SCHED_INFO
  4842. The function returns information about the scheduling policy for the
  4843. processor set as defined by @code{processor_set_sched_info_t}. The
  4844. number of integers returned is @code{PROCESSOR_SET_SCHED_INFO_COUNT}.
  4845. @end table
  4846. Some machines may define additional (machine-dependent) flavors.
  4847. The function returns @code{KERN_SUCCESS} if the call succeeded and
  4848. @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is not a processor
  4849. set or @var{flavor} is not recognized. The function returns
  4850. @code{MIG_ARRAY_TOO_LARGE} if the returned info array is too large for
  4851. @var{processor_set_info}. In this case, @var{processor_set_info} is
  4852. filled as much as possible and @var{processor_set_info_count} is set to the
  4853. number of elements that would have been returned if there were enough
  4854. room.
  4855. @end deftypefun
  4856. @deftp {Data type} {struct processor_set_basic_info}
  4857. This structure is returned in @var{processor_set_info} by the
  4858. @code{processor_set_info} function and provides basic information about
  4859. the processor set. You can cast a variable of type
  4860. @code{processor_set_info_t} to a pointer of this type if you provided it
  4861. as the @var{processor_set_info} parameter for the
  4862. @code{PROCESSOR_SET_BASIC_INFO} flavor of @code{processor_set_info}. It
  4863. has the following members:
  4864. @table @code
  4865. @item int processor_count
  4866. number of processors
  4867. @item int task_count
  4868. number of tasks
  4869. @item int thread_count
  4870. number of threads
  4871. @item int load_average
  4872. scaled load average
  4873. @item int mach_factor
  4874. scaled mach factor
  4875. @end table
  4876. @end deftp
  4877. @deftp {Data type} processor_set_basic_info_t
  4878. This is a pointer to a @code{struct processor_set_basic_info}.
  4879. @end deftp
  4880. @deftp {Data type} {struct processor_set_sched_info}
  4881. This structure is returned in @var{processor_set_info} by the
  4882. @code{processor_set_info} function and provides schedule information
  4883. about the processor set. You can cast a variable of type
  4884. @code{processor_set_info_t} to a pointer of this type if you provided it
  4885. as the @var{processor_set_info} parameter for the
  4886. @code{PROCESSOR_SET_SCHED_INFO} flavor of @code{processor_set_info}. It
  4887. has the following members:
  4888. @table @code
  4889. @item int policies
  4890. allowed policies
  4891. @item int max_priority
  4892. max priority for new threads
  4893. @end table
  4894. @end deftp
  4895. @deftp {Data type} processor_set_sched_info_t
  4896. This is a pointer to a @code{struct processor_set_sched_info}.
  4897. @end deftp
  4898. @node Processor Interface
  4899. @section Processor Interface
  4900. @cindex processor port
  4901. @cindex port representing a processor
  4902. @deftp {Data type} processor_t
  4903. This is a @code{mach_port_t} and used to hold the port name of a
  4904. processor port that represents the processor. Operations on the
  4905. processor are implemented as remote procedure calls to the processor
  4906. port.
  4907. @end deftp
  4908. @menu
  4909. * Hosted Processors:: Getting a list of all processors on a host.
  4910. * Processor Control:: Starting, stopping, controlling processors.
  4911. * Processors and Sets:: Combining processors into processor sets.
  4912. * Processor Info:: Obtaining information on processors.
  4913. @end menu
  4914. @node Hosted Processors
  4915. @subsection Hosted Processors
  4916. @deftypefun kern_return_t host_processors (@w{host_priv_t @var{host_priv}}, @w{processor_array_t *@var{processor_list}}, @w{mach_msg_type_number_t *@var{processor_count}})
  4917. The function @code{host_processors} gets send rights to the processor
  4918. port for each processor existing on @var{host_priv}. This is the
  4919. privileged port that allows its holder to control a processor.
  4920. @var{processor_list} is an array that is created as a result of this
  4921. call. The caller may wish to @code{vm_deallocate} this array when the
  4922. data is no longer needed. @var{processor_count} is set to the number of
  4923. processors in the @var{processor_list}.
  4924. This function returns @code{KERN_SUCCESS} if the call succeeded,
  4925. @code{KERN_INVALID_ARGUMENT} if @var{host_priv} is not a privileged host
  4926. port, and @code{KERN_INVALID_ADDRESS} if @var{processor_count} points to
  4927. inaccessible memory.
  4928. @end deftypefun
  4929. @node Processor Control
  4930. @subsection Processor Control
  4931. @deftypefun kern_return_t processor_start (@w{processor_t @var{processor}})
  4932. @deftypefunx kern_return_t processor_exit (@w{processor_t @var{processor}})
  4933. @deftypefunx kern_return_t processor_control (@w{processor_t @var{processor}}, @w{processor_info_t *@var{cmd}}, @w{mach_msg_type_number_t @var{count}})
  4934. Some multiprocessors may allow privileged software to control
  4935. processors. The @code{processor_start}, @code{processor_exit}, and
  4936. @code{processor_control} operations implement this. The interpretation
  4937. of the command in @var{cmd} is machine dependent. A newly started
  4938. processor is assigned to the default processor set. An exited processor
  4939. is removed from the processor set to which it was assigned and ceases to
  4940. be active.
  4941. @var{count} contains the length of the command @var{cmd} as a number of
  4942. ints.
  4943. Availability limited. All of these operations are machine-dependent.
  4944. They may do nothing. The ability to restart an exited processor is also
  4945. machine-dependent.
  4946. This function returns @code{KERN_SUCCESS} if the operation was
  4947. performed, @code{KERN_FAILURE} if the operation was not performed (a
  4948. likely reason is that it is not supported on this processor),
  4949. @code{KERN_INVALID_ARGUMENT} if @var{processor} is not a processor, and
  4950. @code{KERN_INVALID_ADDRESS} if @var{cmd} points to inaccessible memory.
  4951. @end deftypefun
  4952. @node Processors and Sets
  4953. @subsection Processors and Sets
  4954. @deftypefun kern_return_t processor_assign (@w{processor_t @var{processor}}, @w{processor_set_t @var{processor_set}}, @w{boolean_t @var{wait}})
  4955. The function @code{processor_assign} assigns @var{processor} to the
  4956. set @var{processor_set}. After the assignment is completed, the
  4957. processor only executes threads that are assigned to that processor set.
  4958. Any previous assignment of the processor is nullified. The master
  4959. processor cannot be reassigned. All processors take clock interrupts at
  4960. all times. The @var{wait} argument indicates whether the caller should
  4961. wait for the assignment to be completed or should return immediately.
  4962. Dedicated kernel threads are used to perform processor assignment, so
  4963. setting wait to @code{FALSE} allows assignment requests to be queued and
  4964. performed faster, especially if the kernel has more than one dedicated
  4965. internal thread for processor assignment. Redirection of other device
  4966. interrupts away from processors assigned to other than the default
  4967. processor set is machine-dependent. Intermediaries that interpose on
  4968. ports must be sure to interpose on both ports involved in this call if
  4969. they interpose on either.
  4970. This function returns @code{KERN_SUCCESS} if the assignment has been
  4971. performed, @code{KERN_INVALID_ARGUMENT} if @var{processor} is not a
  4972. processor, or @var{processor_set} is not a processor set on the same
  4973. host as @var{processor}.
  4974. @end deftypefun
  4975. @deftypefun kern_return_t processor_get_assignment (@w{processor_t @var{processor}}, @w{processor_set_name_t *@var{assigned_set}})
  4976. The function @code{processor_get_assignment} obtains the current
  4977. assignment of a processor. The name port of the processor set is
  4978. returned in @var{assigned_set}.
  4979. @end deftypefun
  4980. @node Processor Info
  4981. @subsection Processor Info
  4982. @deftypefun kern_return_t processor_info (@w{processor_t @var{processor}}, @w{int @var{flavor}}, @w{host_t *@var{host}}, @w{processor_info_t @var{processor_info}}, @w{mach_msg_type_number_t *@var{processor_info_count}})
  4983. The function @code{processor_info} returns the selected information array
  4984. for a processor, as specified by @var{flavor}.
  4985. @var{host} is set to the host on which the processor set resides. This
  4986. is the non-privileged host port.
  4987. @var{processor_info} is an array of integers that is supplied by the
  4988. caller and returned filled with specified information.
  4989. @var{processor_info_count} is supplied as the maximum number of integers in
  4990. @var{processor_info}. On return, it contains the actual number of
  4991. integers in @var{processor_info}. The maximum number of integers
  4992. returned by any flavor is @code{PROCESSOR_INFO_MAX}.
  4993. The type of information returned is defined by @var{flavor}, which can
  4994. be one of the following:
  4995. @table @code
  4996. @item PROCESSOR_BASIC_INFO
  4997. The function returns basic information about the processor, as defined
  4998. by @code{processor_basic_info_t}. This includes the slot number of the
  4999. processor. The number of integers returned is
  5000. @code{PROCESSOR_BASIC_INFO_COUNT}.
  5001. @end table
  5002. Machines which require more configuration information beyond the slot
  5003. number are expected to define additional (machine-dependent) flavors.
  5004. The function returns @code{KERN_SUCCESS} if the call succeeded and
  5005. @code{KERN_INVALID_ARGUMENT} if @var{processor} is not a processor or
  5006. @var{flavor} is not recognized. The function returns
  5007. @code{MIG_ARRAY_TOO_LARGE} if the returned info array is too large for
  5008. @var{processor_info}. In this case, @var{processor_info} is filled as
  5009. much as possible and @var{processor_infoCnt} is set to the number of
  5010. elements that would have been returned if there were enough room.
  5011. @end deftypefun
  5012. @deftp {Data type} {struct processor_basic_info}
  5013. This structure is returned in @var{processor_info} by the
  5014. @code{processor_info} function and provides basic information about the
  5015. processor. You can cast a variable of type @code{processor_info_t} to a
  5016. pointer of this type if you provided it as the @var{processor_info}
  5017. parameter for the @code{PROCESSOR_BASIC_INFO} flavor of
  5018. @code{processor_info}. It has the following members:
  5019. @table @code
  5020. @item cpu_type_t cpu_type
  5021. cpu type
  5022. @item cpu_subtype_t cpu_subtype
  5023. cpu subtype
  5024. @item boolean_t running
  5025. is processor running?
  5026. @item int slot_num
  5027. slot number
  5028. @item boolean_t is_master
  5029. is this the master processor
  5030. @end table
  5031. @end deftp
  5032. @deftp {Data type} processor_basic_info_t
  5033. This is a pointer to a @code{struct processor_basic_info}.
  5034. @end deftp
  5035. @node Device Interface
  5036. @chapter Device Interface
  5037. The GNU Mach microkernel provides a simple device interface that allows
  5038. the user space programs to access the underlying hardware devices. Each
  5039. device has a unique name, which is a string up to 127 characters long.
  5040. To open a device, the device master port has to be supplied. The device
  5041. master port is only available through the bootstrap port. Anyone who
  5042. has control over the device master port can use all hardware devices.
  5043. @c XXX FIXME bootstrap port, bootstrap
  5044. @cindex device port
  5045. @cindex port representing a device
  5046. @deftp {Data type} device_t
  5047. This is a @code{mach_port_t} and used to hold the port name of a
  5048. device port that represents the device. Operations on the device are
  5049. implemented as remote procedure calls to the device port. Each device
  5050. provides a sequence of records. The length of a record is specific to
  5051. the device. Data can be transferred ``out-of-line'' or ``in-line''
  5052. (@pxref{Memory}).
  5053. @end deftp
  5054. All constants and functions in this chapter are defined in
  5055. @file{device/device.h}.
  5056. @menu
  5057. * Device Reply Server:: Handling device reply messages.
  5058. * Device Open:: Opening hardware devices.
  5059. * Device Close:: Closing hardware devices.
  5060. * Device Read:: Reading data from the device.
  5061. * Device Write:: Writing data to the device.
  5062. * Device Map:: Mapping devices into virtual memory.
  5063. * Device Status:: Querying and manipulating a device.
  5064. * Device Filter:: Filtering packets arriving on a device.
  5065. @end menu
  5066. @node Device Reply Server
  5067. @section Device Reply Server
  5068. Beside the usual synchronous interface, an asynchronous interface is
  5069. provided. For this, the caller has to receive and handle the reply
  5070. messages separately from the function call.
  5071. @deftypefun boolean_t device_reply_server (@w{msg_header_t *@var{in_msg}}, @w{msg_header_t *@var{out_msg}})
  5072. The function @code{device_reply_server} is produced by the
  5073. remote procedure call generator to handle a received message. This
  5074. function does all necessary argument handling, and actually calls one of
  5075. the following functions: @code{ds_device_open_reply},
  5076. @code{ds_device_read_reply}, @code{ds_device_read_reply_inband},
  5077. @code{ds_device_write_reply} and @code{ds_device_write_reply_inband}.
  5078. The @var{in_msg} argument is the message that has been received from the
  5079. kernel. The @var{out_msg} is a reply message, but this is not used for
  5080. this server.
  5081. The function returns @code{TRUE} to indicate that the message in
  5082. question was applicable to this interface, and that the appropriate
  5083. routine was called to interpret the message. It returns @code{FALSE} to
  5084. indicate that the message did not apply to this interface, and that no
  5085. other action was taken.
  5086. @end deftypefun
  5087. @node Device Open
  5088. @section Device Open
  5089. @deftypefun kern_return_t device_open (@w{mach_port_t @var{master_port}}, @w{dev_mode_t @var{mode}}, @w{dev_name_t @var{name}}, @w{device_t *@var{device}})
  5090. The function @code{device_open} opens the device @var{name} and returns
  5091. a port to it in @var{device}. The open count for the device is
  5092. incremented by one. If the open count was 0, the open handler for the
  5093. device is invoked.
  5094. @var{master_port} must hold the master device port. @var{name}
  5095. specifies the device to open, and is a string up to 128 characters long.
  5096. @var{mode} is the open mode. It is a bitwise-or of the following
  5097. constants:
  5098. @table @code
  5099. @item D_READ
  5100. Request read access for the device.
  5101. @item D_WRITE
  5102. Request write access for the device.
  5103. @item D_NODELAY
  5104. Do not delay an open.
  5105. @c XXX Is this really used at all? Maybe for tape drives? What does it mean?
  5106. @end table
  5107. The function returns @code{D_SUCCESS} if the device was successfully
  5108. opened, @code{D_INVALID_OPERATION} if @var{master_port} is not the
  5109. master device port, @code{D_WOULD_BLOCK} is the device is busy and
  5110. @code{D_NOWAIT} was specified in mode, @code{D_ALREADY_OPEN} if the
  5111. device is already open in an incompatible mode and
  5112. @code{D_NO_SUCH_DEVICE} if @var{name} does not denote a know device.
  5113. @end deftypefun
  5114. @deftypefun kern_return_t device_open_request (@w{mach_port_t @var{master_port}}, @w{mach_port_t @var{reply_port}}, @w{dev_mode_t @var{mode}}, @w{dev_name_t @var{name}})
  5115. @deftypefunx kern_return_t ds_device_open_reply (@w{mach_port_t @var{reply_port}}, @w{kern_return_t @var{return}}, @w{device_t *@var{device}})
  5116. This is the asynchronous form of the @code{device_open} function.
  5117. @code{device_open_request} performs the open request. The meaning for
  5118. the parameters is as in @code{device_open}. Additionally, the caller
  5119. has to supply a reply port to which the @code{ds_device_open_reply}
  5120. message is sent by the kernel when the open has been performed. The
  5121. return value of the open operation is stored in @var{return_code}.
  5122. As neither function receives a reply message, only message transmission
  5123. errors apply. If no error occurs, @code{KERN_SUCCESS} is returned.
  5124. @end deftypefun
  5125. @node Device Close
  5126. @section Device Close
  5127. @deftypefun kern_return_t device_close (@w{device_t @var{device}})
  5128. The function @code{device_close} decrements the open count of the device
  5129. by one. If the open count drops to zero, the close handler for the
  5130. device is called. The device to close is specified by its port
  5131. @var{device}.
  5132. The function returns @code{D_SUCCESS} if the device was successfully
  5133. closed and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
  5134. device port.
  5135. @end deftypefun
  5136. @node Device Read
  5137. @section Device Read
  5138. @deftypefun kern_return_t device_read (@w{device_t @var{device}}, @w{dev_mode_t @var{mode}}, @w{recnum_t @var{recnum}}, @w{int @var{bytes_wanted}}, @w{io_buf_ptr_t *@var{data}}, @w{mach_msg_type_number_t *@var{data_count}})
  5139. The function @code{device_read} reads @var{bytes_wanted} bytes from
  5140. @var{device}, and stores them in a buffer allocated with
  5141. @code{vm_allocate}, which address is returned in @var{data}. The caller
  5142. must deallocated it if it is no longer needed. The number of bytes
  5143. actually returned is stored in @var{data_count}.
  5144. If @var{mode} is @code{D_NOWAIT}, the operation does not block.
  5145. Otherwise @var{mode} should be 0. @var{recnum} is the record number to
  5146. be read, its meaning is device specific.
  5147. The function returns @code{D_SUCCESS} if some data was successfully
  5148. read, @code{D_WOULD_BLOCK} if no data is currently available and
  5149. @code{D_NOWAIT} is specified, and @code{D_NO_SUCH_DEVICE} if
  5150. @var{device} does not denote a device port.
  5151. @end deftypefun
  5152. @deftypefun kern_return_t device_read_inband (@w{device_t @var{device}}, @w{dev_mode_t @var{mode}}, @w{recnum_t @var{recnum}}, @w{int @var{bytes_wanted}}, @w{io_buf_ptr_inband_t *@var{data}}, @w{mach_msg_type_number_t *@var{data_count}})
  5153. The @code{device_read_inband} function works as the @code{device_read}
  5154. function, except that the data is returned ``in-line'' in the reply IPC
  5155. message (@pxref{Memory}).
  5156. @end deftypefun
  5157. @deftypefun kern_return_t device_read_request (@w{device_t @var{device}}, @w{mach_port_t @var{reply_port}}, @w{dev_mode_t @var{mode}}, @w{recnum_t @var{recnum}}, @w{int @var{bytes_wanted}})
  5158. @deftypefunx kern_return_t ds_device_read_reply (@w{mach_port_t @var{reply_port}}, @w{kern_return_t @var{return_code}}, @w{io_buf_ptr_t @var{data}}, @w{mach_msg_type_number_t @var{data_count}})
  5159. This is the asynchronous form of the @code{device_read} function.
  5160. @code{device_read_request} performs the read request. The meaning for
  5161. the parameters is as in @code{device_read}. Additionally, the caller
  5162. has to supply a reply port to which the @code{ds_device_read_reply}
  5163. message is sent by the kernel when the read has been performed. The
  5164. return value of the read operation is stored in @var{return_code}.
  5165. As neither function receives a reply message, only message transmission
  5166. errors apply. If no error occurs, @code{KERN_SUCCESS} is returned.
  5167. @end deftypefun
  5168. @deftypefun kern_return_t device_read_request_inband (@w{device_t @var{device}}, @w{mach_port_t @var{reply_port}}, @w{dev_mode_t @var{mode}}, @w{recnum_t @var{recnum}}, @w{int @var{bytes_wanted}})
  5169. @deftypefunx kern_return_t ds_device_read_reply_inband (@w{mach_port_t @var{reply_port}}, @w{kern_return_t @var{return_code}}, @w{io_buf_ptr_t @var{data}}, @w{mach_msg_type_number_t @var{data_count}})
  5170. The @code{device_read_request_inband} and
  5171. @code{ds_device_read_reply_inband} functions work as the
  5172. @code{device_read_request} and @code{ds_device_read_reply} functions,
  5173. except that the data is returned ``in-line'' in the reply IPC message
  5174. (@pxref{Memory}).
  5175. @end deftypefun
  5176. @node Device Write
  5177. @section Device Write
  5178. @deftypefun kern_return_t device_write (@w{device_t @var{device}}, @w{dev_mode_t @var{mode}}, @w{recnum_t @var{recnum}}, @w{io_buf_ptr_t @var{data}}, @w{mach_msg_type_number_t @var{data_count}}, @w{int *@var{bytes_written}})
  5179. The function @code{device_write} writes @var{data_count} bytes from the
  5180. buffer @var{data} to @var{device}. The number of bytes actually written
  5181. is returned in @var{bytes_written}.
  5182. If @var{mode} is @code{D_NOWAIT}, the function returns without waiting
  5183. for I/O completion. Otherwise @var{mode} should be 0. @var{recnum} is
  5184. the record number to be written, its meaning is device specific.
  5185. The function returns @code{D_SUCCESS} if some data was successfully
  5186. written and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
  5187. device port or the device is dead or not completely open.
  5188. @end deftypefun
  5189. @deftypefun kern_return_t device_write_inband (@w{device_t @var{device}}, @w{dev_mode_t @var{mode}}, @w{recnum_t @var{recnum}}, @w{int @var{bytes_wanted}}, @w{io_buf_ptr_inband_t *@var{data}}, @w{mach_msg_type_number_t *@var{data_count}})
  5190. The @code{device_write_inband} function works as the @code{device_write}
  5191. function, except that the data is sent ``in-line'' in the request IPC
  5192. message (@pxref{Memory}).
  5193. @end deftypefun
  5194. @deftypefun kern_return_t device_write_request (@w{device_t @var{device}}, @w{mach_port_t @var{reply_port}}, @w{dev_mode_t @var{mode}}, @w{recnum_t @var{recnum}}, @w{io_buf_ptr_t @var{data}}, @w{mach_msg_type_number_t @var{data_count}})
  5195. @deftypefunx kern_return_t ds_device_write_reply (@w{mach_port_t @var{reply_port}}, @w{kern_return_t @var{return_code}}, @w{int @var{bytes_written}})
  5196. This is the asynchronous form of the @code{device_write} function.
  5197. @code{device_write_request} performs the write request. The meaning for
  5198. the parameters is as in @code{device_write}. Additionally, the caller
  5199. has to supply a reply port to which the @code{ds_device_write_reply}
  5200. message is sent by the kernel when the write has been performed. The
  5201. return value of the write operation is stored in @var{return_code}.
  5202. As neither function receives a reply message, only message transmission
  5203. errors apply. If no error occurs, @code{KERN_SUCCESS} is returned.
  5204. @end deftypefun
  5205. @deftypefun kern_return_t device_write_request_inband (@w{device_t @var{device}}, @w{mach_port_t @var{reply_port}}, @w{dev_mode_t @var{mode}}, @w{recnum_t @var{recnum}}, @w{io_buf_ptr_t @var{data}}, @w{mach_msg_type_number_t @var{data_count}})
  5206. @deftypefunx kern_return_t ds_device_write_reply_inband (@w{mach_port_t @var{reply_port}}, @w{kern_return_t @var{return_code}}, @w{int @var{bytes_written}})
  5207. The @code{device_write_request_inband} and
  5208. @code{ds_device_write_reply_inband} functions work as the
  5209. @code{device_write_request} and @code{ds_device_write_reply} functions,
  5210. except that the data is sent ``in-line'' in the request IPC message
  5211. (@pxref{Memory}).
  5212. @end deftypefun
  5213. @node Device Map
  5214. @section Device Map
  5215. @deftypefun kern_return_t device_map (@w{device_t @var{device}}, @w{vm_prot_t @var{prot}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{size}}, @w{mach_port_t *@var{pager}}, @w{int @var{unmap}})
  5216. The function @code{device_map} creates a new memory manager for
  5217. @var{device} and returns a port to it in @var{pager}. The memory
  5218. manager is usable as a memory object in a @code{vm_map} call. The call
  5219. is device dependent.
  5220. The protection for the memory object is specified by @var{prot}. The
  5221. memory object starts at @var{offset} within the device and extends
  5222. @var{size} bytes. @var{unmap} is currently unused.
  5223. @c XXX I suppose the caller should set it to 0.
  5224. The function returns @code{D_SUCCESS} if some data was successfully
  5225. written and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
  5226. device port or the device is dead or not completely open.
  5227. @end deftypefun
  5228. @node Device Status
  5229. @section Device Status
  5230. @deftypefun kern_return_t device_set_status (@w{device_t @var{device}}, @w{dev_flavor_t @var{flavor}}, @w{dev_status_t @var{status}}, @w{mach_msg_type_number_t @var{status_count}})
  5231. The function @code{device_set_status} sets the status of a device. The
  5232. possible values for @var{flavor} and their interpretation is device
  5233. specific.
  5234. The function returns @code{D_SUCCESS} if some data was successfully
  5235. written and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
  5236. device port or the device is dead or not completely open.
  5237. @end deftypefun
  5238. @deftypefun kern_return_t device_get_status (@w{device_t @var{device}}, @w{dev_flavor_t @var{flavor}}, @w{dev_status_t @var{status}}, @w{mach_msg_type_number_t *@var{status_count}})
  5239. The function @code{device_get_status} gets the status of a device. The
  5240. possible values for @var{flavor} and their interpretation is device
  5241. specific.
  5242. The function returns @code{D_SUCCESS} if some data was successfully
  5243. written and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
  5244. device port or the device is dead or not completely open.
  5245. @end deftypefun
  5246. @node Device Filter
  5247. @section Device Filter
  5248. @deftypefun kern_return_t device_set_filter (@w{device_t @var{device}}, @w{mach_port_t @var{receive_port}}, @w{mach_msg_type_name_t @var{receive_port_type}}, @w{int @var{priority}}, @w{filter_array_t @var{filter}}, @w{mach_msg_type_number_t @var{filter_count}})
  5249. The function @code{device_set_filter} makes it possible to filter out
  5250. selected data arriving at or leaving the device and forward it to a port.
  5251. @var{filter} is a list of filter commands, which are applied to incoming
  5252. data to determine if the data should be sent to @var{receive_port}. The
  5253. IPC type of the send right is specified by @var{receive_port_right}, it
  5254. is either @code{MACH_MSG_TYPE_MAKE_SEND} or
  5255. @code{MACH_MSG_TYPE_MOVE_SEND}. The @var{priority} value is used to
  5256. order multiple filters.
  5257. There can be up to @code{NET_MAX_FILTER} commands in @var{filter}. The
  5258. actual number of commands is passed in @var{filter_count}. For the
  5259. purpose of the filter test, an internal stack is provided. After all
  5260. commands have been processed, the value on the top of the stack
  5261. determines if the data is forwarded or the next filter is tried.
  5262. The first command is a header which contains two fields: one for flags
  5263. and the other for the type of interpreter used to run the rest of the
  5264. commands.
  5265. Any combination of the following flags is allowed but at least one of them
  5266. must be specified.
  5267. @table @code
  5268. @item NETF_IN
  5269. The filter will be applied to data received by the device.
  5270. @item NETF_OUT
  5271. The filter will be applied to data transmitted by the device.
  5272. @end table
  5273. Unless the type is given explicitly the native NETF interpreter will be used.
  5274. To select an alternative implementation use one of the following types:
  5275. @table @code
  5276. @item NETF_BPF
  5277. Use Berkeley Packet Filter.
  5278. @end table
  5279. For the listener to know what kind of packet is being received, when the
  5280. filter code accepts a packet the message sent to @var{receive_port} is
  5281. tagged with either NETF_IN or NETF_OUT.
  5282. @c XXX The following description was taken verbatim from the
  5283. @c kernel_interface.pdf document.
  5284. Each word of the command list specifies a data (push) operation (high
  5285. order NETF_NBPO bits) as well as a binary operator (low order NETF_NBPA
  5286. bits). The value to be pushed onto the stack is chosen as follows.
  5287. @table @code
  5288. @item NETF_PUSHLIT
  5289. Use the next short word of the filter as the value.
  5290. @item NETF_PUSHZERO
  5291. Use 0 as the value.
  5292. @item NETF_PUSHWORD+N
  5293. Use short word N of the ``data'' portion of the message as the value.
  5294. @item NETF_PUSHHDR+N
  5295. Use short word N of the ``header'' portion of the message as the value.
  5296. @item NETF_PUSHIND+N
  5297. Pops the top long word from the stack and then uses short word N of the
  5298. ``data'' portion of the message as the value.
  5299. @item NETF_PUSHHDRIND+N
  5300. Pops the top long word from the stack and then uses short word N of the
  5301. ``header'' portion of the message as the value.
  5302. @item NETF_PUSHSTK+N
  5303. Use long word N of the stack (where the top of stack is long word 0) as
  5304. the value.
  5305. @item NETF_NOPUSH
  5306. Don't push a value.
  5307. @end table
  5308. The unsigned value so chosen is promoted to a long word before being
  5309. pushed. Once a value is pushed (except for the case of
  5310. @code{NETF_NOPUSH}), the top two long words of the stack are popped and
  5311. a binary operator applied to them (with the old top of stack as the
  5312. second operand). The result of the operator is pushed on the stack.
  5313. These operators are:
  5314. @table @code
  5315. @item NETF_NOP
  5316. Don't pop off any values and do no operation.
  5317. @item NETF_EQ
  5318. Perform an equal comparison.
  5319. @item NETF_LT
  5320. Perform a less than comparison.
  5321. @item NETF_LE
  5322. Perform a less than or equal comparison.
  5323. @item NETF_GT
  5324. Perform a greater than comparison.
  5325. @item NETF_GE
  5326. Perform a greater than or equal comparison.
  5327. @item NETF_AND
  5328. Perform a bitise boolean AND operation.
  5329. @item NETF_OR
  5330. Perform a bitise boolean inclusive OR operation.
  5331. @item NETF_XOR
  5332. Perform a bitise boolean exclusive OR operation.
  5333. @item NETF_NEQ
  5334. Perform a not equal comparison.
  5335. @item NETF_LSH
  5336. Perform a left shift operation.
  5337. @item NETF_RSH
  5338. Perform a right shift operation.
  5339. @item NETF_ADD
  5340. Perform an addition.
  5341. @item NETF_SUB
  5342. Perform a subtraction.
  5343. @item NETF_COR
  5344. Perform an equal comparison. If the comparison is @code{TRUE}, terminate
  5345. the filter list. Otherwise, pop the result of the comparison off the
  5346. stack.
  5347. @item NETF_CAND
  5348. Perform an equal comparison. If the comparison is @code{FALSE},
  5349. terminate the filter list. Otherwise, pop the result of the comparison
  5350. off the stack.
  5351. @item NETF_CNOR
  5352. Perform a not equal comparison. If the comparison is @code{FALSE},
  5353. terminate the filter list. Otherwise, pop the result of the comparison
  5354. off the stack.
  5355. @item NETF_CNAND
  5356. Perform a not equal comparison. If the comparison is @code{TRUE},
  5357. terminate the filter list. Otherwise, pop the result of the comparison
  5358. off the stack. The scan of the filter list terminates when the filter
  5359. list is emptied, or a @code{NETF_C...} operation terminates the list. At
  5360. this time, if the final value of the top of the stack is @code{TRUE},
  5361. then the message is accepted for the filter.
  5362. @end table
  5363. The function returns @code{D_SUCCESS} if some data was successfully
  5364. written, @code{D_INVALID_OPERATION} if @var{receive_port} is not a valid
  5365. send right, and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote
  5366. a device port or the device is dead or not completely open.
  5367. @end deftypefun
  5368. @node Kernel Debugger
  5369. @chapter Kernel Debugger
  5370. The GNU Mach kernel debugger @code{ddb} is a powerful built-in debugger
  5371. with a gdb like syntax. It is enabled at compile time using the
  5372. @option{--enable-kdb} option. Whenever you want to enter the debugger
  5373. while running the kernel, you can press the key combination
  5374. @key{Ctrl-Alt-D}.
  5375. @menu
  5376. * Operation:: Basic architecture of the kernel debugger.
  5377. * Commands:: Available commands in the kernel debugger.
  5378. * Variables:: Access of variables from the kernel debugger.
  5379. * Expressions:: Usage of expressions in the kernel debugger.
  5380. @end menu
  5381. @node Operation
  5382. @section Operation
  5383. The current location is called @dfn{dot}. The dot is displayed with a
  5384. hexadecimal format at a prompt. Examine and write commands update dot
  5385. to the address of the last line examined or the last location modified,
  5386. and set @dfn{next} to the address of the next location to be examined or
  5387. changed. Other commands don't change dot, and set next to be the same
  5388. as dot.
  5389. The general command syntax is:
  5390. @example
  5391. @var{command}[/@var{modifier}] @var{address} [,@var{count}]
  5392. @end example
  5393. @kbd{!!} repeats the previous command, and a blank line repeats from the
  5394. address next with count 1 and no modifiers. Specifying @var{address} sets
  5395. dot to the address. Omitting @var{address} uses dot. A missing @var{count}
  5396. is taken to be 1 for printing commands or infinity for stack traces.
  5397. Current @code{ddb} is enhanced to support multi-thread debugging. A
  5398. break point can be set only for a specific thread, and the address space
  5399. or registers of non current thread can be examined or modified if
  5400. supported by machine dependent routines. For example,
  5401. @example
  5402. break/t mach_msg_trap $task11.0
  5403. @end example
  5404. sets a break point at @code{mach_msg_trap} for the first thread of task
  5405. 11 listed by a @code{show all threads} command.
  5406. In the above example, @code{$task11.0} is translated to the
  5407. corresponding thread structure's address by variable translation
  5408. mechanism described later. If a default target thread is set in a
  5409. variable @code{$thread}, the @code{$task11.0} can be omitted. In
  5410. general, if @code{t} is specified in a modifier of a command line, a
  5411. specified thread or a default target thread is used as a target thread
  5412. instead of the current one. The @code{t} modifier in a command line is
  5413. not valid in evaluating expressions in a command line. If you want to
  5414. get a value indirectly from a specific thread's address space or access
  5415. to its registers within an expression, you have to specify a default
  5416. target thread in advance, and to use @code{:t} modifier immediately
  5417. after the indirect access or the register reference like as follows:
  5418. @example
  5419. set $thread $task11.0
  5420. print $eax:t *(0x100):tuh
  5421. @end example
  5422. No sign extension and indirection @code{size(long, half word, byte)} can
  5423. be specified with @code{u}, @code{l}, @code{h} and @code{b} respectively
  5424. for the indirect access.
  5425. Note: Support of non current space/register access and user space break
  5426. point depend on the machines. If not supported, attempts of such
  5427. operation may provide incorrect information or may cause strange
  5428. behavior. Even if supported, the user space access is limited to the
  5429. pages resident in the main memory at that time. If a target page is not
  5430. in the main memory, an error will be reported.
  5431. @code{ddb} has a feature like a command @code{more} for the output. If
  5432. an output line exceeds the number set in the @code{$lines} variable, it
  5433. displays @samp{--db_more--} and waits for a response. The valid
  5434. responses for it are:
  5435. @table @kbd
  5436. @item @key{SPC}
  5437. one more page
  5438. @item @key{RET}
  5439. one more line
  5440. @item q
  5441. abort the current command, and return to the command input mode
  5442. @end table
  5443. @node Commands
  5444. @section Commands
  5445. @table @code
  5446. @item examine(x) [/@var{modifier}] @var{addr}[,@var{count}] [ @var{thread} ]
  5447. Display the addressed locations according to the formats in the
  5448. modifier. Multiple modifier formats display multiple locations. If no
  5449. format is specified, the last formats specified for this command is
  5450. used. Address space other than that of the current thread can be
  5451. specified with @code{t} option in the modifier and @var{thread}
  5452. parameter. The format characters are
  5453. @table @code
  5454. @item b
  5455. look at by bytes(8 bits)
  5456. @item h
  5457. look at by half words(16 bits)
  5458. @item l
  5459. look at by long words(32 bits)
  5460. @item a
  5461. print the location being displayed
  5462. @item ,
  5463. skip one unit producing no output
  5464. @item A
  5465. print the location with a line number if possible
  5466. @item x
  5467. display in unsigned hex
  5468. @item z
  5469. display in signed hex
  5470. @item o
  5471. display in unsigned octal
  5472. @item d
  5473. display in signed decimal
  5474. @item u
  5475. display in unsigned decimal
  5476. @item r
  5477. display in current radix, signed
  5478. @item c
  5479. display low 8 bits as a character. Non-printing characters are
  5480. displayed as an octal escape code (e.g. '\000').
  5481. @item s
  5482. display the null-terminated string at the location. Non-printing
  5483. characters are displayed as octal escapes.
  5484. @item m
  5485. display in unsigned hex with character dump at the end of each line.
  5486. The location is also displayed in hex at the beginning of each line.
  5487. @item i
  5488. display as an instruction
  5489. @item I
  5490. display as an instruction with possible alternate formats depending on
  5491. the machine:
  5492. @table @code
  5493. @item vax
  5494. don't assume that each external label is a procedure entry mask
  5495. @item i386
  5496. don't round to the next long word boundary
  5497. @item mips
  5498. print register contents
  5499. @end table
  5500. @end table
  5501. @item xf
  5502. Examine forward. It executes an examine command with the last specified
  5503. parameters to it except that the next address displayed by it is used as
  5504. the start address.
  5505. @item xb
  5506. Examine backward. It executes an examine command with the last
  5507. specified parameters to it except that the last start address subtracted
  5508. by the size displayed by it is used as the start address.
  5509. @item print[/axzodurc] @var{addr1} [ @var{addr2} @dots{} ]
  5510. Print @var{addr}'s according to the modifier character. Valid formats
  5511. are: @code{a} @code{x} @code{z} @code{o} @code{d} @code{u} @code{r}
  5512. @code{c}. If no modifier is specified, the last one specified to it is
  5513. used. @var{addr} can be a string, and it is printed as it is. For
  5514. example,
  5515. @example
  5516. print/x "eax = " $eax "\necx = " $ecx "\n"
  5517. @end example
  5518. will print like
  5519. @example
  5520. eax = xxxxxx
  5521. ecx = yyyyyy
  5522. @end example
  5523. @item write[/bhlt] @var{addr} [ @var{thread} ] @var{expr1} [ @var{expr2} @dots{} ]
  5524. Write the expressions at succeeding locations. The write unit size can
  5525. be specified in the modifier with a letter b (byte), h (half word) or
  5526. l(long word) respectively. If omitted, long word is assumed. Target
  5527. address space can also be specified with @code{t} option in the modifier
  5528. and @var{thread} parameter. Warning: since there is no delimiter
  5529. between expressions, strange things may happen. It's best to enclose
  5530. each expression in parentheses.
  5531. @item set $@var{variable} [=] @var{expr}
  5532. Set the named variable or register with the value of @var{expr}. Valid
  5533. variable names are described below.
  5534. @item break[/tuTU] @var{addr}[,@var{count}] [ @var{thread1} @dots{} ]
  5535. Set a break point at @var{addr}. If count is supplied, continues
  5536. (@var{count}-1) times before stopping at the break point. If the break
  5537. point is set, a break point number is printed with @samp{#}. This
  5538. number can be used in deleting the break point or adding conditions to
  5539. it.
  5540. @table @code
  5541. @item t
  5542. Set a break point only for a specific thread. The thread is specified
  5543. by @var{thread} parameter, or default one is used if the parameter is
  5544. omitted.
  5545. @item u
  5546. Set a break point in user space address. It may be combined with
  5547. @code{t} or @code{T} option to specify the non-current target user
  5548. space. Without @code{u} option, the address is considered in the kernel
  5549. space, and wrong space address is rejected with an error message. This
  5550. option can be used only if it is supported by machine dependent
  5551. routines.
  5552. @item T
  5553. Set a break point only for threads in a specific task. It is like
  5554. @code{t} option except that the break point is valid for all threads
  5555. which belong to the same task as the specified target thread.
  5556. @item U
  5557. Set a break point in shared user space address. It is like @code{u}
  5558. option, except that the break point is valid for all threads which share
  5559. the same address space even if @code{t} option is specified. @code{t}
  5560. option is used only to specify the target shared space. Without
  5561. @code{t} option, @code{u} and @code{U} have the same meanings. @code{U}
  5562. is useful for setting a user space break point in non-current address
  5563. space with @code{t} option such as in an emulation library space. This
  5564. option can be used only if it is supported by machine dependent
  5565. routines.
  5566. @end table
  5567. Warning: if a user text is shadowed by a normal user space debugger,
  5568. user space break points may not work correctly. Setting a break point
  5569. at the low-level code paths may also cause strange behavior.
  5570. @item delete[/tuTU] @var{addr}|#@var{number} [ @var{thread1} @dots{} ]
  5571. Delete the break point. The target break point can be specified by a
  5572. break point number with @code{#}, or by @var{addr} like specified in
  5573. @code{break} command.
  5574. @item cond #@var{number} [ @var{condition} @var{commands} ]
  5575. Set or delete a condition for the break point specified by the
  5576. @var{number}. If the @var{condition} and @var{commands} are null, the
  5577. condition is deleted. Otherwise the condition is set for it. When the
  5578. break point is hit, the @var{condition} is evaluated. The
  5579. @var{commands} will be executed if the condition is true and the break
  5580. point count set by a break point command becomes zero. @var{commands}
  5581. is a list of commands separated by semicolons. Each command in the list
  5582. is executed in that order, but if a @code{continue} command is executed,
  5583. the command execution stops there, and the stopped thread resumes
  5584. execution. If the command execution reaches the end of the list, and it
  5585. enters into a command input mode. For example,
  5586. @example
  5587. set $work0 0
  5588. break/Tu xxx_start $task7.0
  5589. cond #1 (1) set $work0 1; set $work1 0; cont
  5590. break/T vm_fault $task7.0
  5591. cond #2 ($work0) set $work1 ($work1+1); cont
  5592. break/Tu xxx_end $task7.0
  5593. cond #3 ($work0) print $work1 " faults\n"; set $work0 0
  5594. cont
  5595. @end example
  5596. will print page fault counts from @code{xxx_start} to @code{xxx_end} in
  5597. @code{task7}.
  5598. @item step[/p] [,@var{count}]
  5599. Single step @var{count} times. If @code{p} option is specified, print
  5600. each instruction at each step. Otherwise, only print the last
  5601. instruction.
  5602. Warning: depending on machine type, it may not be possible to
  5603. single-step through some low-level code paths or user space code. On
  5604. machines with software-emulated single-stepping (e.g., pmax), stepping
  5605. through code executed by interrupt handlers will probably do the wrong
  5606. thing.
  5607. @item continue[/c]
  5608. Continue execution until a breakpoint or watchpoint. If @code{/c},
  5609. count instructions while executing. Some machines (e.g., pmax) also
  5610. count loads and stores.
  5611. Warning: when counting, the debugger is really silently single-stepping.
  5612. This means that single-stepping on low-level code may cause strange
  5613. behavior.
  5614. @item until
  5615. Stop at the next call or return instruction.
  5616. @item next[/p]
  5617. Stop at the matching return instruction. If @code{p} option is
  5618. specified, print the call nesting depth and the cumulative instruction
  5619. count at each call or return. Otherwise, only print when the matching
  5620. return is hit.
  5621. @item match[/p]
  5622. A synonym for @code{next}.
  5623. @item trace[/tu] [ @var{frame_addr}|@var{thread} ][,@var{count}]
  5624. Stack trace. @code{u} option traces user space; if omitted, only traces
  5625. kernel space. If @code{t} option is specified, it shows the stack trace
  5626. of the specified thread or a default target thread. Otherwise, it shows
  5627. the stack trace of the current thread from the frame address specified
  5628. by a parameter or from the current frame. @var{count} is the number of
  5629. frames to be traced. If the @var{count} is omitted, all frames are
  5630. printed.
  5631. Warning: If the target thread's stack is not in the main memory at that
  5632. time, the stack trace will fail. User space stack trace is valid only
  5633. if the machine dependent code supports it.
  5634. @item search[/bhl] @var{addr} @var{value} [@var{mask}] [,@var{count}]
  5635. Search memory for a value. This command might fail in interesting ways
  5636. if it doesn't find the searched-for value. This is because @code{ddb}
  5637. doesn't always recover from touching bad memory. The optional count
  5638. argument limits the search.
  5639. @item macro @var{name} @var{commands}
  5640. Define a debugger macro as @var{name}. @var{commands} is a list of
  5641. commands to be associated with the macro. In the expressions of the
  5642. command list, a variable @code{$argxx} can be used to get a parameter
  5643. passed to the macro. When a macro is called, each argument is evaluated
  5644. as an expression, and the value is assigned to each parameter,
  5645. @code{$arg1}, @code{$arg2}, @dots{} respectively. 10 @code{$arg}
  5646. variables are reserved to each level of macros, and they can be used as
  5647. local variables. The nesting of macro can be allowed up to 5 levels.
  5648. For example,
  5649. @example
  5650. macro xinit set $work0 $arg1
  5651. macro xlist examine/m $work0,4; set $work0 *($work0)
  5652. xinit *(xxx_list)
  5653. xlist
  5654. @enddots{}
  5655. @end example
  5656. will print the contents of a list starting from @code{xxx_list} by each
  5657. @code{xlist} command.
  5658. @item dmacro @var{name}
  5659. Delete the macro named @var{name}.
  5660. @item show all threads[/uls]
  5661. Display all tasks and threads information. This version of @code{ddb}
  5662. prints more information than previous one. It shows UNIX process
  5663. information like @command{ps} for each task. The UNIX process
  5664. information may not be shown if it is not supported in the machine, or
  5665. the bottom of the stack of the target task is not in the main memory at
  5666. that time. It also shows task and thread identification numbers. These
  5667. numbers can be used to specify a task or a thread symbolically in
  5668. various commands. The numbers are valid only in the same debugger
  5669. session. If the execution is resumed again, the numbers may change.
  5670. The current thread can be distinguished from others by a @code{#} after
  5671. the thread id instead of @code{:}. Without @code{l} option, it only
  5672. shows thread id, thread structure address and the status for each
  5673. thread. The status consists of 6 letters, R(run), W(wait), S(suspended),
  5674. O(swapped out), N(interruptible), and F(loating) point arithmetic used (if
  5675. supported by the platform). If the corresponding
  5676. status bit is off, @code{.} is printed instead. If @code{l} option is
  5677. specified, more detail information is printed for each thread. If the
  5678. @code{s} option is given, scheduling information is displayed.
  5679. @item show all tasks
  5680. Displays all tasks similar to @code{show all threads}, but omits
  5681. information about the individual threads.
  5682. @item show task [ @var{addr} ]
  5683. Display the information of a task specified by @var{addr}. If
  5684. @var{addr} is omitted, current task information is displayed.
  5685. @item show thread [ @var{addr} ]
  5686. Display the information of a thread specified by @var{addr}. If
  5687. @var{addr} is omitted, current thread information is displayed.
  5688. @item show registers[/tu [ @var{thread} ]]
  5689. Display the register set. Target thread can be specified with @code{t}
  5690. option and @var{thread} parameter. If @code{u} option is specified, it
  5691. displays user registers instead of kernel or currently saved one.
  5692. Warning: The support of @code{t} and @code{u} option depends on the
  5693. machine. If not supported, incorrect information will be displayed.
  5694. @item show map @var{addr}
  5695. Prints the @code{vm_map} at @var{addr}.
  5696. @item show object @var{addr}
  5697. Prints the @code{vm_object} at @var{addr}.
  5698. @item show page @var{addr}
  5699. Prints the @code{vm_page} structure at @var{addr}.
  5700. @item show port @var{addr}
  5701. Prints the @code{ipc_port} structure at @var{addr}.
  5702. @item show ipc_port[/t [ @var{thread} ]]
  5703. Prints all @code{ipc_port} structure's addresses the target thread has.
  5704. The target thread is a current thread or that specified by a parameter.
  5705. @item show macro [ @var{name} ]
  5706. Show the definitions of macros. If @var{name} is specified, only the
  5707. definition of it is displayed. Otherwise, definitions of all macros are
  5708. displayed.
  5709. @item show watches
  5710. Displays all watchpoints.
  5711. @item watch[/T] @var{addr},@var{size} [ @var{task} ]
  5712. Set a watchpoint for a region. Execution stops when an attempt to
  5713. modify the region occurs. The @var{size} argument defaults to 4.
  5714. Without @code{T} option, @var{addr} is assumed to be a kernel address.
  5715. If you want to set a watch point in user space, specify @code{T} and
  5716. @var{task} parameter where the address belongs to. If the @var{task}
  5717. parameter is omitted, a task of the default target thread or a current
  5718. task is assumed. If you specify a wrong space address, the request is
  5719. rejected with an error message.
  5720. Warning: Attempts to watch wired kernel memory may cause unrecoverable
  5721. error in some systems such as i386. Watchpoints on user addresses work
  5722. best.
  5723. @item dwatch[/T] @var{addr} [ @var{task} ]
  5724. Clears a watchpoint previously set for a region.
  5725. Without @code{T} option, @var{addr} is assumed to be a kernel address.
  5726. If you want to clear a watch point in user space, specify @code{T} and
  5727. @var{task} parameter where the address belongs to. If the @var{task}
  5728. parameter is omitted, a task of the default target thread or a current
  5729. task is assumed. If you specify a wrong space address, the request is
  5730. rejected with an error message.
  5731. @item debug traps /on|/off
  5732. Enables or disables debugging of all traps with @code{ddb}.
  5733. @item debug references /on|/off
  5734. Enables or disables debugging of all port reference counting errors
  5735. with @code{ddb}.
  5736. @end table
  5737. @node Variables
  5738. @section Variables
  5739. The debugger accesses registers and variables as $@var{name}. Register
  5740. names are as in the @code{show registers} command. Some variables are
  5741. suffixed with numbers, and may have some modifier following a colon
  5742. immediately after the variable name. For example, register variables
  5743. can have @code{u} and @code{t} modifier to indicate user register and
  5744. that of a default target thread instead of that of the current thread
  5745. (e.g. @code{$eax:tu}).
  5746. Built-in variables currently supported are:
  5747. @table @code
  5748. @item task@var{xx}[.@var{yy}]
  5749. Task or thread structure address. @var{xx} and @var{yy} are task and
  5750. thread identification numbers printed by a @code{show all threads}
  5751. command respectively. This variable is read only.
  5752. @item map@var{xx}
  5753. VM map structure address. @var{xx} is a task identification number
  5754. printed by a @code{show all tasks} command. This variable is read
  5755. only.
  5756. @item thread
  5757. The default target thread. The value is used when @code{t} option is
  5758. specified without explicit thread structure address parameter in command
  5759. lines or expression evaluation.
  5760. @item radix
  5761. Input and output radix
  5762. @item maxoff
  5763. Addresses are printed as @var{symbol}+@var{offset} unless offset is greater than
  5764. maxoff.
  5765. @item maxwidth
  5766. The width of the displayed line.
  5767. @item lines
  5768. The number of lines. It is used by @code{more} feature.
  5769. @item tabstops
  5770. Tab stop width.
  5771. @item arg@var{xx}
  5772. Parameters passed to a macro. @var{xx} can be 1 to 10.
  5773. @item work@var{xx}
  5774. Work variable. @var{xx} can be 0 to 31.
  5775. @end table
  5776. @node Expressions
  5777. @section Expressions
  5778. Almost all expression operators in C are supported except @code{~},
  5779. @code{^}, and unary @code{&}. Special rules in @code{ddb} are:
  5780. @table @code
  5781. @item @var{identifier}
  5782. name of a symbol. It is translated to the address(or value) of it.
  5783. @code{.} and @code{:} can be used in the identifier. If supported by
  5784. an object format dependent routine,
  5785. [@var{file_name}:]@var{func}[:@var{line_number}]
  5786. [@var{file_name}:]@var{variable}, and
  5787. @var{file_name}[:@var{line_number}] can be accepted as a symbol. The
  5788. symbol may be prefixed with @code{@var{symbol_table_name}::} like
  5789. @code{emulator::mach_msg_trap} to specify other than kernel symbols.
  5790. @item @var{number}
  5791. radix is determined by the first two letters:
  5792. @table @code
  5793. @item 0x
  5794. hex
  5795. @item 0o
  5796. octal
  5797. @item 0t
  5798. decimal
  5799. @end table
  5800. otherwise, follow current radix.
  5801. @item .
  5802. dot
  5803. @item +
  5804. next
  5805. @item ..
  5806. address of the start of the last line examined. Unlike dot or next,
  5807. this is only changed by @code{examine} or @code{write} command.
  5808. @item ´
  5809. last address explicitly specified.
  5810. @item $@var{variable}
  5811. register name or variable. It is translated to the value of it. It may
  5812. be followed by a @code{:} and modifiers as described above.
  5813. @item a
  5814. multiple of right hand side.
  5815. @item *@var{expr}
  5816. indirection. It may be followed by a @code{:} and modifiers as
  5817. described above.
  5818. @end table
  5819. @include gpl.texi
  5820. @node Documentation License
  5821. @appendix Documentation License
  5822. This manual is copyrighted and licensed under the GNU Free Documentation
  5823. license.
  5824. Parts of this manual are derived from the Mach manual packages
  5825. originally provided by Carnegie Mellon University.
  5826. @menu
  5827. * GNU Free Documentation License:: The GNU Free Documentation License.
  5828. * CMU License:: The CMU license applies to the original Mach
  5829. kernel and its documentation.
  5830. @end menu
  5831. @include fdl.texi
  5832. @node CMU License
  5833. @appendixsec CMU License
  5834. @quotation
  5835. @display
  5836. Mach Operating System
  5837. Copyright @copyright{} 1991,1990,1989 Carnegie Mellon University
  5838. All Rights Reserved.
  5839. @end display
  5840. Permission to use, copy, modify and distribute this software and its
  5841. documentation is hereby granted, provided that both the copyright
  5842. notice and this permission notice appear in all copies of the
  5843. software, derivative works or modified versions, and any portions
  5844. thereof, and that both notices appear in supporting documentation.
  5845. @sc{carnegie mellon allows free use of this software in its ``as is''
  5846. condition. carnegie mellon disclaims any liability of any kind for
  5847. any damages whatsoever resulting from the use of this software.}
  5848. Carnegie Mellon requests users of this software to return to
  5849. @display
  5850. Software Distribution Coordinator
  5851. School of Computer Science
  5852. Carnegie Mellon University
  5853. Pittsburgh PA 15213-3890
  5854. @end display
  5855. @noindent
  5856. or @email{Software.Distribution@@CS.CMU.EDU} any improvements or
  5857. extensions that they make and grant Carnegie Mellon the rights to
  5858. redistribute these changes.
  5859. @end quotation
  5860. @node Concept Index
  5861. @unnumbered Concept Index
  5862. @printindex cp
  5863. @node Function and Data Index
  5864. @unnumbered Function and Data Index
  5865. @printindex fn
  5866. @summarycontents
  5867. @contents
  5868. @bye