%!PS (but not EPSF through switch or no memory) %%Creator: dvips by Radical Eye Software %%Title: machsys.dvi %%Pages: 30 -1 %%BoundingBox: 0 0 612 792 %! /TeXDict 200 dict def TeXDict begin /bdf{bind def}def /Inch{Resolution mul} bdf /Dots{72 div Resolution mul}bdf /bop-aux{}bdf /dopage{/page-height exch def /page-width exch def 72 Resolution div dup neg scale translate}bdf /@letter{Resolution dup -10 mul 8.5 11 dopage}bdf /@note{@letter}bdf /@a4{ Resolution dup -10.6929133858 mul 21 2.54 div 29.7 2.54 div dopage}bdf /@translate{translate}bdf /@scale{scale}bdf /@rotate{rotate}bdf /@landscape{[ 0 1 -1 0 0 0]concat Resolution dup 8.5 11 dopage}bdf /@legal{Resolution dup -13 mul 8.5 14 dopage}bdf /@11x17{statusdict /11x17tray known{statusdict begin 11x17tray end}if Resolution dup -16 mul 11 17 dopage}bdf /@manualfeed{ statusdict /manualfeed true put}bdf /@copies{/#copies exch def}bdf /@draft{ /bop-aux{gsave initmatrix 72 dup scale page-width 2 div page-height 2 div translate page-height page-width atan rotate /Helvetica-Bold findfont 2 scalefont setfont(DRAFT)dup stringwidth pop 2 div neg -1 moveto .95 setgray show grestore}bdf}bdf /@FontMatrix[1 0 0 -1 0 0]def /@FontBBox[0 0 1 1]def /dmystr(ZZf@@)def /newname{dmystr cvn}bdf /df{/fontname exch def dmystr 2 fontname cvx(@@@)cvs putinterval newname 7 dict def newname load begin /FontType 3 def /FontMatrix @FontMatrix def /FontBBox @FontBBox def /BitMaps 256 array def /BuildChar{CharBuilder}def /Encoding 256 array def 0 1 255{ Encoding exch /.undef put}for end fontname{/foo setfont}2 array copy cvx def fontname load 0 dmystr 5 string copy cvn cvx put}bdf /dfe{newname newname load definefont setfont}bdf /ch-image{ch-data 0 get}bdf /ch-width{ch-data 1 get} bdf /ch-height{ch-data 2 get}bdf /ch-xoff{ch-data 3 get}bdf /ch-yoff{ch-data 4 get}bdf /ch-tfmw{ch-data 5 get}bdf /CharBuilder{save 3 1 roll exch /BitMaps get exch get /ch-data exch def ch-data null ne{ch-tfmw 0 ch-xoff neg ch-yoff neg ch-width ch-xoff sub ch-height ch-yoff sub setcachedevice ch-width ch-height true[1 0 0 1 ch-xoff ch-yoff]{ch-image}imagemask}if restore}bdf /dc{ /ch-code exch def dup 0 get length 1 lt{pop[<00>1 1 0 0 8.00]}if /ch-data exch def newname load /BitMaps get ch-code ch-data put newname load /Encoding get ch-code dup( )cvs cvn put}bdf /bop{gsave /SaveImage save def /bop-aux load exec 0 0 moveto}bdf /eop{clear SaveImage restore showpage grestore}bdf /@start {/Resolution exch def}bdf /p{show}bdf /RuleMatrix[1 0 0 -1 0 -1]def /BlackDots 8 string def /v{gsave currentpoint translate false RuleMatrix{BlackDots} imagemask grestore}bdf /a{moveto}bdf /delta 0 def /tail{dup /delta exch def 0 rmoveto}bdf /b{exch p tail}bdf /c{p delta 4 sub tail}bdf /d{p delta 3 sub tail }bdf /e{p delta 2 sub tail}bdf /f{p delta 1 sub tail}bdf /g{p delta 0 rmoveto} bdf /h{p delta 1 add tail}bdf /i{p delta 2 add tail}bdf /j{p delta 3 add tail} bdf /k{p delta 4 add tail}bdf /l{p -4 0 rmoveto}bdf /m{p -3 0 rmoveto}bdf /n{ p -2 0 rmoveto}bdf /o{p -1 0 rmoveto}bdf /q{p 1 0 rmoveto}bdf /r{p 2 0 rmoveto }bdf /s{p 3 0 rmoveto}bdf /t{p 4 0 rmoveto}bdf /w{0 rmoveto}bdf /x{0 exch rmoveto}bdf /y{3 -1 roll p moveto}bdf /bos{/section save def}bdf /eos{clear section restore}bdf /SDict 200 dict def SDict begin /@SpecialDefaults{/hs 8.5 Inch def /vs 11 Inch def /ho 0 def /vo 0 def /hsc 1 def /vsc 1 def /ang 0 def /CLIP false def /BBcalc false def}bdf /@hsize{/hs exch def /CLIP true def}bdf /@vsize{/vs exch def /CLIP true def}bdf /@hoffset{/ho exch def}bdf /@voffset{ /vo exch def}bdf /@hscale{@scaleunit div /hsc exch def}bdf /@vscale{ @scaleunit div /vsc exch def}bdf /@angle{/ang exch def rotate}bdf /@scaleunit 1 def /@rwi{10 div /rwi exch def}bdf /@llx{/llx exch def}bdf /@lly{/lly exch def}bdf /@urx{/urx exch def}bdf /@ury{/ury exch def /BBcalc true def}bdf /@setclipper{BBcalc{rwi urx llx sub div dup scale llx neg lly neg translate}{ hsc vsc scale}ifelse CLIP{newpath 0 0 moveto hs 0 rlineto 0 vs rlineto hs neg 0 rlineto closepath clip}{initclip}ifelse}bdf end /@MacSetUp{userdict /md known{userdict /md get type /dicttype eq{md begin /letter{}def /note{}def /legal{}def /od{txpose 1 0 mtx defaultmatrix dtransform exch atan/pa exch def newpath clippath mark{transform{itransform moveto}}{transform{itransform lineto}}{6 -2 roll transform 6 -2 roll transform 6 -2 roll transform{ itransform 6 2 roll itransform 6 2 roll itransform 6 2 roll curveto}}{{ closepath}}pathforall newpath counttomark array astore /gc xdf pop ct 39 0 put 10 fz 0 fs 2 F/|______Courier fnt invertflag{PaintBlack}if}def /txpose{pxs pys scale ppr aload pop por{noflips{pop exch neg exch translate pop 1 -1 scale}if xflip yflip and{pop exch neg exch translate 180 rotate 1 -1 scale ppr 3 get ppr 1 get neg sub neg ppr 2 get ppr 0 get neg sub neg translate}if xflip yflip not and{pop exch neg exch translate pop 180 rotate ppr 3 get ppr 1 get neg sub neg 0 translate}if yflip xflip not and{ppr 1 get neg ppr 0 get neg translate} if}{noflips{translate pop pop 270 rotate 1 -1 scale}if xflip yflip and{ translate pop pop 90 rotate 1 -1 scale ppr 3 get ppr 1 get neg sub neg ppr 2 get ppr 0 get neg sub neg translate}if xflip yflip not and{translate pop pop 90 rotate ppr 3 get ppr 1 get neg sub neg 0 translate}if yflip xflip not and{ translate pop pop 270 rotate ppr 2 get ppr 0 get neg sub neg 0 exch translate} if}ifelse scaleby96{ppr aload pop 4 -1 roll add 2 div 3 1 roll add 2 div 2 copy translate .96 dup scale neg exch neg exch translate}if}def /cp{pop pop showpage pm restore}def end}if}if}def /psf$TeXscale{65536 div}def /startTexFig {/psf$SavedState save def userdict maxlength dict begin Resolution 72 div dup neg scale currentpoint translate /psf$ury exch psf$TeXscale def /psf$urx exch psf$TeXscale def /psf$lly exch psf$TeXscale def /psf$llx exch psf$TeXscale def /psf$y exch psf$TeXscale def /psf$x exch psf$TeXscale def currentpoint /psf$cy exch def /psf$cx exch def /psf$sx psf$x psf$urx psf$llx sub div def /psf$sy psf$y psf$ury psf$lly sub div def psf$sx psf$sy scale psf$cx psf$sx div psf$llx sub psf$cy psf$sy div psf$ury sub translate /showpage{}def /erasepage{ }def /copypage{}def @MacSetUp}def /doclip{psf$llx psf$lly psf$urx psf$ury currentpoint 6 2 roll newpath 4 copy 4 2 roll moveto 6 -1 roll exch lineto exch lineto exch lineto closepath clip newpath moveto}def /endTexFig{end psf$SavedState restore}def /@beginspecial{SDict begin /SpecialSave save def gsave Resolution 72 div dup neg scale currentpoint translate @SpecialDefaults} bdf /@setspecial{ho vo translate @setclipper /showpage{}def newpath}bdf /@endspecial{grestore clear SpecialSave restore end}bdf /@defspecial{SDict begin}bdf /@fedspecial{end}bdf /li{lineto}bdf /rl{rlineto}bdf /rc{rcurveto} bdf /np{/SaveX currentpoint /SaveY exch def def newpath}bdf /st{stroke SaveX SaveY moveto}bdf /fil{fill SaveX SaveY moveto}bdf /ellipse{/endangle exch def /startangle exch def /yrad exch def /xrad exch def /savematrix matrix currentmatrix def translate xrad yrad scale 0 0 1 startangle endangle arc savematrix setmatrix}bdf end %! TeXDict begin /ReEncodeForTeX{findfont /basefontdict exch def /newfont basefontdict maxlength 2 add dict def basefontdict{exch dup /FID ne{dup /Encoding eq{exch dup length array copy}{exch}ifelse newfont 3 1 roll put}{ pop pop}ifelse}forall normalvec fixup basefontdict /FontInfo get /isFixedPitch get{courvec fixup}if 256 dict begin newfont /Encoding get 0 1 255{2 copy get 3 index 2 index get 1000 mul ptsize div def pop}for pop pop newfont /Metrics currentdict put end newname newfont definefont}bind def /fixup{aload length 2 idiv{dup newfont /CharStrings get exch known{newfont /Encoding get 3 1 roll put}{pop pop}ifelse}repeat}bind def /normalvec[0 /Gamma 1 /Delta 2 /Theta 3 /Lambda 4 /Xi 5 /Pi 6 /Sigma 7 /Upsilon 8 /Phi 9 /Psi 10 /Omega 12 /fi 13 /fl 16 /dotlessi 18 /grave 19 /acute 20 /caron 21 /breve 22 /macron 23 /ring 24 /cedilla 25 /germandbls 26 /ae 27 /oe 28 /oslash 29 /AE 30 /OE 31 /Oslash 34 /quotedblright 60 /exclamdown 62 /questiondown 92 /quotedblleft 94 /circumflex 95 /dotaccent 123 /endash 124 /emdash 125 /quotedbl 126 /tilde 127 /dieresis] def /courvec[11 /arrowup 12 /arrowdown 13 /quotesingle 14 /exclamdown 15 /questiondown 34 /quotedbl 60 /less 62 /greater 92 /backslash 95 /underscore 123 /braceleft 124 /bar 125 /braceright]def /pf{exch pop 655360 div mul Resolution mul 7227 div /ptsize exch def /PSname exch def exch /TeXname exch def dmystr 2 TeXname cvx(@@@)cvs putinterval PSname ReEncodeForTeX newname exch[ptsize 0 0 ptsize neg 0 0]makefont def TeXname{/foo setfont}2 array copy cvx def TeXname load 0 dmystr 5 string copy cvn cvx put}bind def /ObliqueFont{ /ObliqueAngle exch def /ObliqueBaseName exch def /ObliqueFontName exch def /ObliqueTransform[1 0 ObliqueAngle sin ObliqueAngle cos div 1 0 0]def /basefontdict ObliqueBaseName findfont ObliqueTransform makefont def /newfont basefontdict maxlength dict def basefontdict{exch dup /FID ne{dup /Encoding eq {exch dup length array copy newfont 3 1 roll put}{exch newfont 3 1 roll put} ifelse}{pop pop}ifelse}forall newfont /FontName ObliqueFontName put ObliqueFontName newfont definefont pop}bind def /CopyFont{findfont dup length dict /newfont exch def{1 index /FID ne{newfont 3 1 roll put}{pop pop}ifelse} forall newfont /FontName 2 index put newfont definefont pop}bind def /SmallCapsFont{/SmallCapsBaseName exch def /SmallCapsFontName exch def /basefontdict SmallCapsBaseName findfont def /newfont basefontdict maxlength 10 add dict def newfont begin /FontName SmallCapsFontName def /FontBaseDict basefontdict 1000 scalefont def /FontSCDict FontBaseDict .8 scalefont def /FontType 3 def /BuildChar{SmallCapChar}def /FontMatrix dup basefontdict exch get def /FontBBox dup basefontdict exch get def /Encoding dup basefontdict exch get def /CharStrings dup basefontdict exch get def /FontInfo dup basefontdict exch get def end SmallCapsFontName newfont definefont pop}bind def /SmallCapChar{/achar(A)def achar exch 0 exch put begin achar 0 get dup 97 ge exch 122 le and{achar 0 achar 0 get 32 sub put FontSCDict}{FontBaseDict} ifelse setfont achar stringwidth FontBBox setcachedevice newpath 0 0 moveto achar show end}bind def end TeXDict begin 300 @start bos /fa [ 0 0 0 0 0 0 0 0 0 0 0 0 33 33 0 0 17 0 20 20 20 20 20 20 20 33 43 43 30 60 60 47 15 20 30 30 30 60 50 20 20 20 30 34 15 20 15 17 30 30 30 30 30 30 30 30 30 30 20 20 20 34 30 30 56 43 40 43 43 40 37 47 47 23 30 47 40 56 43 47 37 47 43 33 40 43 43 60 43 43 40 20 30 20 20 20 20 30 33 27 33 27 20 30 33 17 20 33 17 50 33 30 33 33 27 23 20 33 30 43 30 30 27 30 60 20 20 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 20 30 30 10 30 30 30 30 17 30 30 20 20 33 33 0 30 30 30 15 0 32 21 20 30 30 30 60 60 0 30 0 20 20 20 20 20 20 20 20 0 20 20 0 20 20 20 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 60 0 18 0 0 0 0 40 47 60 20 0 0 0 0 0 43 0 0 0 17 0 0 17 30 43 33 0 0 0 0 ] /Times-Bold 1000 655360 943718 pf /fb [ 0 0 0 0 0 0 0 0 0 0 0 0 28 28 0 0 14 0 17 17 17 17 17 17 17 28 36 36 25 50 50 39 12 17 25 25 25 50 41 17 17 17 25 28 12 17 12 14 25 25 25 25 25 25 25 25 25 25 17 17 17 28 25 25 46 36 33 36 36 33 30 39 39 19 25 39 33 47 36 39 30 39 36 28 33 36 36 50 36 36 33 17 25 17 17 17 17 25 28 22 28 22 17 25 28 14 17 28 14 41 28 25 28 28 22 19 17 28 25 36 25 25 22 25 50 17 17 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 25 25 8 25 25 25 25 14 25 25 17 17 28 28 0 25 25 25 12 0 27 17 17 25 25 25 50 50 0 25 0 17 17 17 17 17 17 17 17 0 17 17 0 17 17 17 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 50 0 15 0 0 0 0 33 39 50 16 0 0 0 0 0 36 0 0 0 14 0 0 14 25 36 28 0 0 0 0 ] /Times-Bold 1000 655360 786432 pf /fc [ 0 0 0 0 0 0 0 0 0 0 0 0 0 25 25 25 25 0 25 25 25 25 25 25 25 25 0 0 25 0 0 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 25 25 25 25 25 25 25 25 25 25 25 25 0 0 0 25 25 25 25 0 25 25 25 25 25 25 25 0 0 25 0 25 25 25 25 25 25 25 25 0 25 25 0 25 25 25 25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 0 0 0 0 25 25 0 25 0 0 0 0 0 0 0 0 0 25 0 0 25 25 0 25 0 0 0 0 ] /Courier 1000 655360 655360 pf /fd [ 0 0 0 0 0 0 0 0 0 0 0 0 23 23 0 0 12 0 14 14 14 14 14 14 14 23 30 30 21 42 42 32 10 14 21 21 21 42 35 14 14 14 21 24 10 14 10 12 21 21 21 21 21 21 21 21 21 21 14 14 14 24 21 21 39 30 28 30 30 28 25 32 32 16 21 32 28 39 30 32 25 32 30 23 28 30 30 42 30 30 28 14 21 14 14 14 14 21 23 18 23 18 14 21 23 12 14 23 12 35 23 21 23 23 18 16 14 23 21 30 21 21 18 21 42 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 21 21 7 21 21 21 21 12 21 21 14 14 23 23 0 21 21 21 10 0 22 15 14 21 21 21 42 42 0 21 0 14 14 14 14 14 14 14 14 0 14 14 0 14 14 14 42 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 42 0 12 0 0 0 0 28 32 42 14 0 0 0 0 0 30 0 0 0 12 0 0 12 21 30 23 0 0 0 0 ] /Times-Bold 1000 655360 655360 pf /fe [ 0 0 0 0 0 0 0 0 0 0 0 0 21 21 0 0 12 0 14 14 14 14 14 14 14 21 28 28 21 37 39 30 10 14 23 21 21 35 32 14 14 14 21 28 10 14 10 12 21 21 21 21 21 21 21 21 21 21 14 14 16 28 21 21 38 25 25 28 30 25 25 30 30 14 18 28 23 35 28 30 25 30 25 21 23 30 25 35 25 23 23 16 23 16 14 14 14 21 21 18 21 18 12 21 21 12 12 18 12 30 21 21 21 21 16 16 12 21 18 28 18 18 16 21 37 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 21 21 7 21 21 21 21 9 23 21 14 14 21 21 0 21 21 21 10 0 22 15 14 23 23 21 37 42 0 21 0 14 14 14 14 14 14 14 14 0 14 14 0 14 14 14 37 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 37 0 11 0 0 0 0 23 30 39 13 0 0 0 0 0 28 0 0 0 12 0 0 12 21 28 21 0 0 0 0 ] /Times-Italic 1000 655360 655360 pf /ff [ 0 0 0 0 0 0 0 0 0 0 0 0 23 23 0 0 12 0 14 14 14 14 14 14 14 21 28 30 21 37 37 30 10 14 18 21 21 35 32 14 14 14 21 23 10 14 10 12 21 21 21 21 21 21 21 21 21 21 12 12 14 23 18 18 38 30 28 28 30 25 23 30 30 14 16 30 25 37 30 30 23 30 28 23 25 30 30 39 30 30 25 14 18 14 14 14 14 18 21 18 21 18 14 21 21 12 12 21 12 32 21 21 21 21 14 16 12 21 21 30 21 21 18 21 42 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 21 21 7 21 21 21 21 7 18 21 14 14 23 23 0 21 21 21 10 0 19 15 14 18 18 21 42 42 0 18 0 14 14 14 14 14 14 14 14 0 14 14 0 14 14 14 42 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 37 0 11 0 0 0 0 25 30 37 13 0 0 0 0 0 28 0 0 0 12 0 0 12 21 30 21 0 0 0 0 ] /Times-Roman 1000 655360 655360 pf /fg [ 0 0 0 0 0 0 0 0 0 0 0 0 0 22 22 22 22 0 22 22 22 22 22 22 22 22 0 0 22 0 0 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 22 22 22 22 22 22 22 22 22 22 22 22 22 0 0 0 22 22 22 22 0 22 22 22 22 22 22 22 0 0 22 0 22 22 22 22 22 22 22 22 0 22 22 0 22 22 22 22 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 22 0 0 0 0 22 22 0 22 0 0 0 0 0 0 0 0 0 22 0 0 22 22 0 22 0 0 0 0 ] /Courier 1000 655360 589824 pf end TeXDict begin @letter %%Page: 28 1 bop 150 162 a ff(28)1132 b fe(4)41 b(MACH)10 b(ENVIRONMENT)150 307 y fa(4)60 b(Mach)15 b(Envir)o(onment)150 400 y ff(See)d(the)f(section)f(\\General)i(Mac\ h)g(Information")e(at)h(the)f(end)h(of)g(the)g fe(A)g(Pr)n(ogrammers')-5 b (s)12 b(Guide)e(to)h(the)f(Mach)150 450 y(User)h(Envir)n(onment)f ff(to)f(\ \014nd)g(the)h(current)g(include)f(\014le)h(names)h(and)f(paths)f(needed)i (to)e(compile)h(code)g(using)f(the)150 499 y(Mach)i(system)g(calls.)g eop %%Page: 27 2 bop 150 162 a fe(3.3)41 b(Inheritance)10 b(of)g(Shar)n(ed)g(versus)i(Copied) d(Memory)759 b ff(27)329 307 y fg(mem[0])25 b(=)e(CHILD_CHA)q(NG)q(ED;)329 353 y(printf\(")q(\\n")q(\);)329 399 y(printf\(")q(CHI)q(LD)q(:)j(lock)e(=)e(%d\\\ n",)j(*lock\);)329 444 y(printf\(")q(CHI)q(LD)q(:)h(changing)f(lock)f(to)g (%d\\n",)h(CHILD_WAIT)q(\);)329 490 y(printf\(")q(\\n")q(\);)329 535 y(*lock) g(=)e(CHILD_WAIT)q(;)329 581 y(while)i(\(*lock)g(==)e(CHILD_WAI)q(T\))q(;)509 627 y(/*)g(wait)h(for)g(parent)h(to)e(change)i(lock)f(*/)329 672 y(if)g(\(\(r\ et)g(=)f(vm_deallo)q(cat)q(e\()q(ta)q(sk_)q(se)q(lf\()q(\),)j(lock,)509 718 y (sizeof\(int)q(\),)g(TRUE\)\))f(!=)e(KERN_SUC)q(CES)q(S\))j({)509 764 y(mach_\ error)q(\(")q(vm_)q(de)q(al)q(loc)q(at)q(e)f(returned)h(value)f(of)e(",)g(ret\ \);)509 809 y(printf\("Ex)q(it)q(ing)q(.\\)q(n")q(\);)509 855 y(exit\(\);)329 901 y(})329 946 y(if)h(\(\(ret)g(=)f(vm_deallo)q(cat)q(e\()q(ta)q(sk_)q(se)q (lf\()q(\),)j(mem,)509 992 y(MAXDATA)f(*)e(sizeof\(ch)q(ar\))q(,)j(TRUE\)\))f (!=)e(KERN_SUCC)q(ESS)q(\))j({)509 1038 y(mach_error)q(\(")q(vm_)q(de)q(al)q (loc)q(at)q(e)f(returned)h(value)f(of)e(",)g(ret\);)509 1083 y(printf\("Ex)q (it)q(ing)q(.\\)q(n")q(\);)509 1129 y(exit\(\);)329 1175 y(})329 1220 y(print\ f\(")q(CHI)q(LD)q(:)j(Finished.\\)q(n")q(\);)150 1266 y(})g eop %%Page: 26 3 bop 150 162 a ff(26)1045 b fe(3)41 b(USE)11 b(OF)f(VIRTUAL)i(MEMOR)o(Y)509 307 y fg(TRUE\)\))25 b(!=)e(KERN_SUCC)q(ESS)q(\))j({)509 353 y(mach_error)q (\(")q(vm_)q(al)q(lo)q(cat)q(e)g(returned)f(value)g(of)e(",)g(ret\);)509 399 y (printf\("Ex)q(it)q(ing)j(with)e(error.\\n)q("\))q(;)509 444 y(exit\(\);)329 490 y(})329 535 y(if)g(\(\(ret)g(=)f(vm_inheri)q(t\(t)q(as)q(k_)q(sel)q(f\()q (\),)j(lock,)e(sizeof\(i)q(nt)q(\),)509 581 y(VM_INHERIT)q(_S)q(HAR)q(E\))q (\))i(!=)d(KERN_SUCC)q(ESS)q(\))j({)509 627 y(mach_error)q(\(")q(vm_)q(in)q (he)q(rit)g(returned)g(value)e(of)g(",)f(ret\);)509 672 y(printf\("Ex)q(it)q (ing)j(with)e(error.\\n)q("\))q(;)509 718 y(exit\(\);)329 764 y(})329 809 y (*lock)h(=)e(NO_ONE_WAI)q(T;)329 855 y(if)h(\(\(ret)g(=)f(vm_alloca)q(te\()q (ta)q(sk)q(_se)q(lf)q(\(\),)j(&mem,)f(sizeof\(in)q(t\))h(*)d(MAXDATA,)509 901 y(TRUE\)\))i(!=)e(KERN_SUCC)q(ESS)q(\))j({)509 946 y(mach_error)q(\(")q(vm_)q (al)q(lo)q(cat)q(e)g(returned)f(value)g(of)e(",)g(ret\);)509 992 y(printf\("E\ x)q(it)q(ing)j(with)e(error.\\n)q("\))q(;)509 1038 y(exit\(\);)329 1083 y(}) 329 1129 y(mem[0])h(=)e(COPY_ON_W)q(RI)q(TE;)329 1220 y(printf\(")q(val)q(ue) j(of)d(lock)h(before)h(fork:)g(%d\\n",)g(*lock\);)329 1266 y(pid)f(=)f(fork\(\ \);)329 1312 y(if)h(\(pid\))g({)509 1357 y(printf\("PA)q(RE)q(NT:)i(copied)f (memory)g(=)45 b(%d\\n",)688 1403 y(mem[0]\);)509 1449 y(printf\("PA)q(RE)q (NT:)26 b(changing)g(to)d(%d\\n",)i(PARENT_C)q(HAN)q(GE)q(D\);)509 1494 y(mem\ [0])g(=)d(PARENT_C)q(HA)q(NGE)q(D;)509 1540 y(printf\("\\n)q("\))q(;)509 1586 y(printf\("PA)q(RE)q(NT:)k(lock)e(=)f(%d\\n",)i(*lock\);)509 1631 y(printf\("\ PA)q(RE)q(NT:)h(changing)g(lock)e(to)f(%d\\n",)i(PARENT_W)q(AIT)q(\);)509 1677 y(printf\("\\n)q("\))q(;)509 1723 y(*lock)f(=)f(PARENT_WA)q(IT)q(;)509 1768 y (while)h(\(*lock)h(==)e(PARENT_W)q(AIT)q(\);)576 1814 y(/*)g(wait)h(for)g(chi\ ld)g(to)g(change)h(the)e(value)i(*/)576 1860 y(/*)e(beware)i(of)e(optimizi)q (ng)j(compilers)g(*/)509 1905 y(printf\("PA)q(RE)q(NT:)g(copied)f(memory)g (=)e(%d\\n",)688 1951 y(mem[0]\);)509 1997 y(printf\("PA)q(RE)q(NT:)j(lock)e (=)f(%d\\n",)i(*lock\);)509 2042 y(printf\("PA)q(RE)q(NT:)h(Finished)q(.\\n)q ("\))q(;)509 2088 y(*lock)e(=)f(PARENT_WA)q(IT)q(;)509 2134 y(exit\(\);)329 2179 y(})329 2225 y(while)i(\(*lock)g(!=)e(PARENT_WA)q(IT)q(\);)509 2271 y (/*)g(wait)h(for)g(parent)h(to)e(change)i(lock)f(*/)509 2316 y(/*)f(beware)i (of)e(optimizin)q(g)j(compilers)g(*/)329 2362 y(printf\(")q(CHI)q(LD)q(:)g (copied)e(memory)h(=)e(%d\\n",)i(mem[0]\);)329 2408 y(printf\(")q(CHI)q(LD)q (:)h(changing)f(to)f(%d\\n",)g(CHILD_CH)q(AN)q(GED)q(\);)g eop %%Page: 25 4 bop 150 162 a fe(3.3)41 b(Inheritance)10 b(of)g(Shar)n(ed)g(versus)i(Copied) d(Memory)759 b ff(25)150 307 y fd(3.3.2)42 b(Pr)o(ogramming)9 b(Example)g(III\ ,)j(cowtest.c)150 394 y fg(/*)172 440 y(*)23 b(This)h(program)i(demonstrat)q (es)g(the)e(use)f(of)h(vm_inherit)i(and)e(copy)g(on)f(write)172 486 y(*)g(mem\ ory.)j(A)c(child)j(and)f(parent)g(process)i(will)e(share)g(memory,)i(polling) f(this)172 531 y(*)e(memory)i(to)e(see)h(whos)g(turn)g(it)f(is)h(to)f(proceed\ .)48 b(First)25 b(some)f(memory)h(is)e(allocated)q(,)172 577 y(*)g(and)h(vm_i\ nheri)q(t)h(is)f(called)h(on)e(this)h(memory,)h(the)f(variable)i('lock'.)47 b (Next)25 b(more)172 623 y(*)e(memory)i(is)e(allocate)q(d)j(for)d(the)h(copy)g (on)f(write)i(test.)f(A)f(fork)h(is)f(executed)q(,)j(and)172 668 y(*)d(The)h (parent)h(then)f(stores)h(new)e(data)i(in)e(the)g(copy)i(on)e(write)h(memory) 172 714 y(*)f(previous)q(ly)j(allocated)q(,)f(and)f(sets)g(the)g(shared)h(var\ iable)g(signalin)q(g)h(to)d(the)172 760 y(*)g(child)i(that)f(he)f(is)g(now)h (waiting.)48 b(The)24 b(child,)h(polling)g(the)f(shared)h(variable,)172 805 y (*)e(realizes)j(it)d(is)g(his)h(turn.)47 b(The)24 b(child)g(prints)h(the)f (value)g(of)g(the)f(variable)172 851 y(*)g(lock)h(and)g(a)f(value)h(of)g(the) f(copy)h(on)g(write)g(memory)h(as)e(the)h(child)g(sees)g(it.)172 897 y(*)f (You)h(will)g(notice)h(that)f(the)g(value)g(of)f(the)h(lock)g(is)f(what)h(the) g(parent)172 942 y(*)f(set)h(it)f(to)g(be,)h(but)g(the)f(value)i(of)e(the)h (copy)g(on)f(write)i(memory)g(is)e(the)g(original)172 988 y(*)g(value)i(and)e (not)h(what)g(the)g(parent)h(changed)g(it)e(to)h(be.)172 1034 y(*)f(The)h(par\ ent)h(then)f(awakes)h(and)e(prints)i(out)f(the)g(two)f(values)i(once)f(more.) 172 1079 y(*)f(The)h(program)h(then)f(ends)g(with)g(the)g(parent)h(signaling) h(the)e(child)g(via)g(the)172 1125 y(*)f(shared)i(variable)h(lock.)172 1171 y (********)q(**)q(***)q(**)q(***)q(**)q(**)q(***)q(**)q(***)q(**)q(**)q(***)q (**)q(***)q(**)q(**)q(***)q(**)q(***)q(**)q(/)150 1216 y(#include)g() 150 1262 y(#include)g()150 1353 y(#define)f(NO_ONE_W)q(AIT)h(0)150 1399 y(#define)f(PARENT_W)q(AIT)h(1)150 1445 y(#define)f(CHILD_WA)q(IT)h(2) 150 1490 y(#define)f(COPY_ON_)q(WRI)q(TE)h(0)150 1536 y(#define)f(PARENT_C)q (HAN)q(GE)q(D)h(1)150 1582 y(#define)f(CHILD_CH)q(ANG)q(ED)h(2)150 1673 y(#de\ fine)f(MAXDATA)h(100)150 1764 y(main\(argc)q(,)g(argv\))329 1810 y(int)114 b (argc;)329 1856 y(char)92 b(*argv[];)150 1901 y({)329 1947 y(int)293 b(pid;) 329 1993 y(int)g(*mem;)329 2038 y(int)g(*lock;)329 2084 y(kern_ret)q(urn)q (_t)71 b(ret;)329 2175 y(if)24 b(\(argc)g(>)f(1\))g({)509 2221 y(printf\("co) q(wt)q(est)j(takes)f(no)e(switches.)49 b("\);)509 2267 y(printf\("Th)q(is)26 b (program)f(is)f(an)f(example)i(of)e(copy)i(on)e(write)h(\\n"\);)509 2312 y (printf\("me)q(mo)q(ry)i(and)e(of)f(the)g(use)h(of)f(vm_inher)q(it)q(.\\n)q ("\))q(;)509 2358 y(exit\(\);)329 2403 y(})329 2449 y(if)h(\(\(ret)g(=)f(vm_a\ lloca)q(te\()q(ta)q(sk)q(_se)q(lf)q(\(\),)j(&lock,)f(sizeof\(i)q(nt\))q(,)g eop %%Page: 24 5 bop 150 162 a ff(24)1045 b fe(3)41 b(USE)11 b(OF)f(VIRTUAL)i(MEMOR)o(Y)212 307 y ff(Through)f(execution)g(of)g(this)f(program,)i(the)f(user)h(will)e(not\ ice)h(that)g(the)g(changes)h(to)f(the)g(copied)h(memory)150 357 y(are)h(not)e (seen)i(from)f(the)f(child)g(to)h(the)g(parent;)g(that)f(is)h(when)g(the)g (parent)g(changes)g(the)g(value,)h(the)f(child)f(does)150 407 y(not)e(see)j (this)d(change.)17 b(On)10 b(the)g(other)g(hand,)g(any)g(change)h(in)f(the)g (shared)h(memory)g(is)f(noticed)f(by)h(both)f(tasks.)212 457 y(The)j(copied)g (memory)g(in)e(this)h(example)h(is)g(actually)f(copy-on-write)e(memory)m(.)20 b(That)12 b(is,)g(the)f(memory)h(is)150 506 y(never)f(really)e(copied)i(until) d(one)i(of)g(the)g(tasks)h(desires)f(to)g(write)g(in)f(this)h(region.)150 617 y fd(3.3.1)42 b(V)n(irtual)10 b(Memory)n(,)g(Inheritance)150 694 y fc(vm_inhe\ rit)f ff(allows)g(a)i(task)f(to)f(specify)h(how)f(the)h(various)f(regions)g (of)h(its)f(memory)h(will)f(be)h(passed)h(to)e(any)150 744 y(child)k(tasks)h (that)f(it)g(forks.)26 b(By)13 b(default)h(all)f(memory)h(is)g(passed)h(to)e (the)g(child)g(as)i(a)f(logical)f(copy)h(\(actually)150 794 y(copy-on-write\)\ .)h fc(vm_inherit)9 b ff(allows)h(a)h(task)g(to)f(specify)g(that)g(certain)g (page-regions)g(of)h(its)e(memory)i(are)150 844 y(to)f(be)g(shared)h(with)e (any)h(children)g(it)f(subsequently)g(forks,)i(or)e(are)j(not)d(to)h(be)g(pas\ sed)h(at)g(all)f(to)f(that)h(child.)212 894 y(The)19 b(inheritance)f(paramete\ r)i(may)f(be)f(set)h(to)f fc(VM_INHERIT_SHARE)p ff(,)f fc(VM_INHERIT_COPY)g ff (or)150 943 y fc(VM_INHERIT_NONE)p ff(.)e(The)j fc(size)e ff(parameter)h(is)f (measured)i(in)e(bytes)g(but)f(only)h(integral)f(numbers)h(of)150 993 y(pages) 11 b(are)g(dealt)f(with.)15 b(The)10 b(pages)h(are)g(selected)g(by)f(rounding) e(down)i(the)g(start)f(address)i(to)f(a)h(page)f(boundary)150 1043 y(and)g (then)g(rounding)e(up)i(the)g(end)h(address)g(to)e(a)i(page)g(boundary)m(.) 240 1130 y fg(int)292 b(*lock;)240 1176 y(kern_retur)q(n_)q(t)70 b(ret;)240 1267 y(if)23 b(\(\(ret)h(=)f(vm_inher)q(it\()q(ta)q(sk_)q(se)q(lf)q(\(\),)j (lock,)f(sizeof\(int)q(\),)307 1313 y(VM_INHERI)q(T_S)q(HA)q(RE)q(\)\))h(!=)d (KERN_SUCC)q(ES)q(S\))j({)307 1359 y(mach_erro)q(r\(")q(vm)q(_i)q(nhe)q(ri)q (t)f(returned)h(value)f(of)e(",)g(ret\);)307 1404 y(exit\(1\);)240 1450 y(})g eop %%Page: 23 6 bop 150 162 a fe(3.2)41 b(V)m(irtual)9 b(Memory)i(Copying)1099 b ff(23)150 307 y fb(3.2)50 b(V)n(irtual)12 b(Memory)h(Copying)150 385 y ff(The)e fc(vm_c\ opy)e ff(primitive)g(is)g(another)h(alternative)g(to)f fc(vm_read)p ff(.)15 b (In)10 b(either)g(case)h(the)f(task)g(port)f(used)i(as)f(the)150 435 y(\014rs\ t)i(parameter)i(may)f(specify)f(the)h(caller)r(')n(s)f(address)h(space)g(or)g (that)e(of)i(some)g(other)f(task.)22 b(If)12 b(another)g(task')n(s)150 485 y (port)f(is)g(used)h fc(vm_read)f ff(copies)g(memory)h(from)g(that)f(task')n (s)g(address)h(space)h(to)e(the)g(caller)r(')n(s)g(address)h(space.)150 534 y (On)i(the)g(other)f(hand,)i fc(vm_copy)f ff(moves)g(the)g(memory)h(from)f(one) g(part)f(of)h(the)g(designated)g(task')n(s)g(address)150 584 y(space)g(to)e (another)g(section)g(of)g(that)g(address)h(space.)23 b(The)13 b(fact)g(that)f (these)h(primitives)e(do)h(not)f(actually)h(copy)150 634 y(the)h(data)h(regio\ ns,)f(but)g(only)f(map)i(the)f(regions)f(as)i(copy-on-write)e(pages,)j(means) f(that)f(they)g(actually)g(have)150 684 y(some)h(use)f(even)h(in)e(copying)g (data)h(in)g(the)g(caller)r(')n(s)f(own)h(address)g(space.)26 b(If)13 b(a)g (task)g(wants)g(multiple)f(virtual)150 734 y(memory)g(references)i(to)d(the)h (same)h(data,)g(it)e(can)i(use)f(either)g(of)f(these)h(primitives)f(to)g(set) h(this)f(up.)20 b(No)12 b(data)g(is)150 783 y(actually)e(copied)g(until)e(one) j(of)f(the)g(virtual)e(memory)j(areas)h(is)e(modi\014ed.)212 833 y(The)h(dest\ ination)e(region)g(must)h(be)h(allocated)f(prior)f(to)h(the)g(call)g(to)g fc (vm_copy)p ff(.)240 908 y fg(int)292 b(*data1,)26 b(*data2;)240 954 y(kern_re\ tur)q(n_)q(t)70 b(rtn;)240 1045 y(/*)23 b(note)h(that)g(data2)h(was)e(previou\ s)q(ly)j(allocated)q(.)f(*/)240 1136 y(if)e(\(\(rtn)h(=)f(vm_copy\()q(tas)q (k_)q(sel)q(f\()q(\),)j(data1,)f(vm_page_s)q(ize)q(,)h(data2\)\))f(!=)307 1182 y(KERN_SUCC)q(ESS)q(\))h({)307 1228 y(mach_erro)q(r\(")q(vm)q(_c)q(opy)g(retu\ rned)g(value)e(of)g(",)f(rtn\);)307 1273 y(exit\(1\);)240 1319 y(})212 1408 y ff(An)8 b(complete)h(example)g(of)f(a)g(program)g(using)g fc(vm_copy)f ff(can) i(be)g(found)e(in)g(the)h(Mach)h(example)g(directory)150 1458 y(as)i fc(vm_co\ py.c)p ff(.)150 1574 y fb(3.3)50 b(Inheritance)12 b(of)g(Shar)o(ed)g(versus)h (Copied)e(Memory)150 1652 y ff(This)f(\014nal)h(virtual)e(memory)h(example)i (illustrates)d(the)h(use)h(of)f fc(vm_inherit)p ff(,)g(and)g(the)h(dif)o(fere\ nce)g(between)150 1702 y(copied)h(and)f(shared)i(memory)m(.)21 b(The)12 b(pro\ blem)f(posed)h(is)f(to)g(have)i(two)e(memory)h(regions,)g(one)g(inherited)e (and)150 1752 y(shared)h(by)f(a)h(child)f(task)g(and)h(one)g(region)e(simply) h(copied)g(by)h(the)f(UNIX)g(fork)g(call.)17 b(T)m(o)11 b(show)f(the)h(dif)o (ference)150 1802 y(between)g(the)f(two)f(acquisition)g(methods,)h(the)g(pare\ nt)g(and)g(child)g(will)f(take)h(turns)f(printing)f(out)i(and)g(changing)150 1851 y(the)g(values)h(of)e(the)i(two)e(regions.)212 1901 y(The)14 b(\014rst)f (step)h(towards)f(a)g(solution)f(is)h(to)g(allocate)g(and)h(\014ll)e(with)h (data)g(two)g(regions)g(of)g(memory)m(.)25 b(The)150 1951 y(address)13 b(of)e (the)h(memory)h(that)e(is)h(to)f(be)i(shared)f(by)g(the)g(child)f(task)h(is)g (passed)h(to)e fc(vm_inherit)p ff(,)h(using)f(the)150 2001 y(VM)p fc(_)p ff (INHERIT)p fc(_)p ff(SHARED)i(\015ag.)23 b(The)14 b(shared)f(memory)g(is)g (used)g(in)f(this)g(program)g(as)i(a)f(lock)f(to)g(regulate)150 2051 y(whethe\ r)e(the)g(child)g(or)f(parent)i(process)f(is)g(to)g(proceed.)16 b(After)10 b (forking,)f(the)h(child)g(will)f(wait)h(while)f(the)h(parent)150 2100 y(print\ s)g(out)h(the)g(value)h(of)f(the)g(shared)h(memory)g(and)g(the)f(value)h(of)f (the)h(copied)f(memory)m(.)20 b(After)12 b(the)f(parent)g(is)150 2150 y(\014n\ ished,)g(he)g(changes)g(the)g(lock)f(causing)h(himself)f(to)g(wait)g(and)h (signaling)e(the)i(child)e(to)h(continue.)17 b(The)11 b(child)150 2200 y(prin\ ts)i(the)h(contents)g(of)g(the)g(two)f(regions)h(then)g(changes)h(the)f(lock) f(and)i(waits.)27 b(The)15 b(lock)f(change)h(signals)150 2250 y(the)g(parent) g(to)f(once)i(again)f(print)f(the)h(memory)g(values.)31 b(The)16 b(parent)f (changes)h(the)f(lock)f(and)i(exits.)29 b(The)150 2300 y(child)11 b(notices)h (the)h(lock)e(change,)j(deallocates)f(the)f(two)g(memory)h(regions,)f(and)h (exits.)21 b(Be)12 b(aware)i(that)e(code)150 2350 y(which)f(loops)g(on)h(a)g (lock)g(that)f(some)i(other)e(task)h(is)g(going)e(to)h(modify)g(is)h(sometime\ s)h(deleted)f(by)f(optimizing)150 2399 y(compilers.)34 b(Either)16 b(the)g (variable)g(should)f(be)i(tagged)f(as)h("volitile")e(if)h(your)f(compiler)h (understands)g(that)150 2449 y(construct)10 b(or)g(optimizing)e(may)j(need)f (to)g(be)h(turned)e(of)o(f.)g eop %%Page: 22 7 bop 150 162 a ff(22)1045 b fe(3)41 b(USE)11 b(OF)f(VIRTUAL)i(MEMOR)o(Y)509 307 y fg(printf\("vm)q(re)q(ad:)26 b(Exiting.)q(\\n")q(\);)509 353 y(exit\(\)\ ;)329 399 y(})329 444 y(printf\(")q(Suc)q(ce)q(ss)q(ful)g(vm_read.)q(\\n")q (\);)329 535 y(if)e(\(vm_page_s)q(iz)q(e)h(!=)f(data_cnt\))i({)509 581 y(prin\ tf\("vm)q(re)q(ad:)g(Number)f(of)e(bytes)i(read)f(not)g(equal)g(to)f(number"\ \))q(;)509 627 y(printf\("av)q(ai)q(lab)q(le)j(and)e(requested)q(.)48 b(\\n"\ \);)329 672 y(})329 718 y(min)24 b(=)f(\(vm_page_)q(siz)q(e)j(<)c(data_cnt)q (\))k(?)c(vm_page_)q(si)q(ze)k(:)d(data_cnt;)329 809 y(for)h(\(i)f(=)g(0;)g (\(i)h(<)e(min\);)j(i++\))f({)509 855 y(if)f(\(data1[i])j(!=)d(data2[i])q(\)) i({)688 901 y(printf\("v)q(mr)q(ead)q(:)h(Data)e(not)f(read)h(correctl)q(y.)q (\\n")q(\);)688 946 y(printf\("v)q(mr)q(ead)q(:)i(Exiting.\\n)q("\))q(;)688 992 y(exit\(\);)509 1038 y(})329 1083 y(})329 1129 y(printf\(")q(Che)q(ck)q (ed)g(data)e(successfu)q(ll)q(y.\\)q(n")q(\);)329 1220 y(if)g(\(\(rtn)g(=)f (vm_deallo)q(cat)q(e\()q(ta)q(sk_)q(se)q(lf\()q(\),)j(data1,)509 1266 y(vm_pa\ ge_si)q(ze)q(\)\))g(!=)d(KERN_SUCC)q(ES)q(S\))j({)509 1312 y(mach_error)q(\(") q(vm_)q(de)q(al)q(loc)q(at)q(e)f(returned)h(value)f(of)e(",)g(rtn\);)509 1357 y(printf\("vm)q(re)q(ad:)j(Exiting.)q(\\n")q(\);)509 1403 y(exit\(\);)329 1449 y(})329 1540 y(if)e(\(\(rtn)g(=)f(vm_deallo)q(cat)q(e\()q(ta)q(sk_)q(se)q(lf\ \()q(\),)j(data2,)509 1586 y(data_cnt\)\))g(!=)d(KERN_SUC)q(CE)q(SS\))j({)509 1631 y(mach_error)q(\(")q(vm_)q(de)q(al)q(loc)q(at)q(e)f(returned)h(value)f (of)e(",)g(rtn\);)509 1677 y(printf\("vm)q(re)q(ad:)j(Exiting.)q(\\n")q(\);) 509 1723 y(exit\(\);)329 1768 y(})150 1814 y(})g eop %%Page: 21 8 bop 150 162 a fe(3.1)41 b(Allocation,)9 b(Deallocation,)g(and)g(Reading)872 b ff(21)150 307 y fd(3.1.4)42 b(Pr)o(ogramming)9 b(Example)g(II,)i(vm)r 13 2 v 13 w(r)o(ead.c)150 394 y fg(/*)172 440 y(*)172 486 y(*)23 b(This)h(program)i (is)d(a)g(test)h(of)f(vm_alloca)q(te)q(,)i(vm_read)h(and)d(vm_deall)q(oc)q (ate)q(.)172 531 y(*)g(First)i(some)f(memory)h(is)e(allocated)q(,)j(and)d(fil\ led)i(with)f(data.)47 b(vm_read)25 b(is)172 577 y(*)e(then)h(called,)i(with)e (reading)h(starting)h(at)d(the)h(previously)i(allocate)q(d)f(chunk.)172 623 y (*)e(The)h(contents)i(of)d(the)h(two)f(pieces)i(of)e(memory,)j(one)d(retreive) q(d)j(by)d(vm_alloca)q(te,)j(and)172 668 y(*)d(one)h(by)f(vm_read)i(is)f(comp\ ared.)i(vm_deallo)q(cat)q(e)g(is)d(then)h(used)g(to)f(rid)h(of)f(the)172 714 y (*)g(two)h(chunks)h(of)e(memory.)172 760 y(*)172 805 y(********)q(**)q(***)q (**)q(***)q(**)q(**)q(***)q(**)q(***)q(**)q(**)q(***)q(**)q(***)q(**)q(**)q (***)q(**)q(***)q(**)q(**)q(***)q(/)150 897 y(#include)j()150 942 y (#include)g()150 1034 y(main\(argc)q(,)g(argv\))329 1079 y(int)114 b (argc;)329 1125 y(char)92 b(*argv[];)150 1171 y({)329 1216 y(char)271 b(*data\ 1,)25 b(*temp;)329 1262 y(char)271 b(*data2;)329 1308 y(int)293 b(data_cnt,) 26 b(i,)d(min;)329 1353 y(kern_ret)q(urn)q(_t)71 b(rtn;)329 1536 y(if)24 b (\(argc)g(>)f(1\))g({)509 1582 y(printf\("vm)q(_r)q(ead)j(takes)f(no)e(switch\ es.)49 b("\);)509 1627 y(printf\("Th)q(is)26 b(program)f(is)f(an)f(example)i (vm_read\\)q(n"\))q(;)509 1673 y(exit\(\);)329 1719 y(})329 1810 y(if)f(\(\(r\ tn)g(=)f(vm_alloca)q(te\()q(ta)q(sk)q(_se)q(lf)q(\(\),)j(&data1,)g(vm_page_si) q(ze)q(,)509 1856 y(TRUE\)\))f(!=)e(KERN_SUCC)q(ESS)q(\))j({)509 1901 y(mach_\ error)q(\(")q(vm_)q(al)q(lo)q(cat)q(e)g(returned)f(value)g(of)e(",)g(rtn\);) 509 1947 y(printf\("vm)q(re)q(ad:)j(Exiting.)q(\\n")q(\);)509 1993 y(exit\(\)\ ;)329 2038 y(})329 2130 y(temp)e(=)f(data1;)329 2175 y(for)h(\(i)f(=)g(0;)g (\(i)h(<)e(vm_page_)q(si)q(ze\))q(;)k(i++\))509 2221 y(temp[i])f(=)e(i;)329 2267 y(printf\(")q(Fil)q(le)q(d)j(space)e(allocated)i(with)e(some)g(data.\\n") q(\);)329 2312 y(printf\(")q(Doi)q(ng)i(vm_read..)q(..)q(\\n)q("\);)329 2358 y (if)e(\(\(rtn)g(=)f(vm_read\(t)q(ask)q(_s)q(el)q(f\(\))q(,)j(data1,)f(vm_page\ _si)q(ze)q(,)g(&data2,)509 2403 y(&data_cnt\))q(\))h(!=)d(KERN_SUCC)q(ESS)q (\))j({)509 2449 y(mach_error)q(\(")q(vm_)q(re)q(ad)g(returned)g(value)e(of)f (",)h(rtn\);)g eop %%Page: 20 9 bop 150 162 a ff(20)1045 b fe(3)41 b(USE)11 b(OF)f(VIRTUAL)i(MEMOR)o(Y)240 307 y fg(char)270 b(*data1;)240 353 y(kern_retur)q(n_)q(t)70 b(rtn;)240 444 y (if)23 b(\(\(rtn)h(=)f(vm_deall)q(oca)q(te)q(\(ta)q(sk)q(_s)q(elf)q(\(\))q (,)i(data1,)307 490 y(vm_page_s)q(ize)q(\)\))h(!=)d(KERN_SUC)q(CE)q(SS\))j ({)307 535 y(mach_erro)q(r\(")q(vm)q(_d)q(eal)q(lo)q(cat)q(e)g(returned)f(val\ ue)g(of)e(",)g(rtn\);)307 581 y(printf\("v)q(mre)q(ad)q(:)j(Exiting.\\v)q(er) q(b+\\)q(+n)q("\);)307 627 y(exit\(1\);)240 672 y(})150 837 y fd(3.1.3)42 b (V)n(irtual)10 b(Memory)g(Reading)150 914 y fc(vm_read)k ff(makes)h(it)e(poss\ ible)h(for)f(one)h(task)h(to)e(read)i(the)f(virtual)e(memory)j(of)f(another)n (.)27 b(In)13 b(the)h(example)150 964 y(below)m(,)c(a)g(task)f(is)h(reading)f (its)g(own)g(memory)m(.)16 b(The)10 b(\014rst)f(parameter)i(to)e fc(vm_read)g ff(is)g(the)g(task)h(whose)g(address)150 1014 y(space)h(is)e(to)f(be)i(read.) 16 b(Note)9 b(the)g(parameter)h fc(address)p ff(,)f(which)g(is)g(the)g(\014rs\ t)g(address)h(to)e(be)i(read,)g(must)f(be)h(on)f(a)150 1064 y(page)g(boundary) m(.)14 b(Size)9 b(is)f(in)g(bytes)g(and)g(must)g(be)h(an)f(integral)g(number) g(of)g(pages.)16 b(The)9 b(data)f(read)h(is)f(returned)g(in)150 1114 y(a)j (newly)g(allocated)g(region.)17 b(The)11 b(size)h(in)e(bytes)h(of)f(this)g (new)h(region)f(is)h(also)g(returned.)17 b fc(vm_deallocate)150 1163 y ff(sho\ uld)9 b(be)i(used)f(on)g(the)g(region)g(returned)f(by)h fc(vm_read)g ff(when) g(it)g(is)g(no)g(longer)f(needed.)240 1251 y fg(char)270 b(*data1,)26 b(*data\ 2;)240 1296 y(int)292 b(data_cnt)q(;)240 1342 y(kern_retur)q(n_)q(t)70 b(rtn;) 240 1433 y(if)23 b(\(\(rtn)h(=)f(vm_read\()q(tas)q(k_)q(sel)q(f\()q(\),)j(dat\ a1,)f(vm_page_s)q(ize)q(,)h(&data2,)307 1479 y(&data_cnt)q(\)\))g(!=)d(KERN_S\ UCC)q(ES)q(S\))j({)307 1525 y(mach_erro)q(r\(")q(vm)q(_r)q(ead)g(returned)g (value)e(of)g(",)f(rtn\);)307 1570 y(printf\("v)q(mre)q(ad)q(:)j(Exiting.\\v) q(er)q(b+\\)q(+n)q("\);)307 1616 y(exit\(1\);)262 1662 y(})g eop %%Page: 19 10 bop 1758 162 a ff(19)150 307 y fa(3)60 b(Use)15 b(of)f(V)n(irtual)g(Memory) 150 408 y fb(3.1)50 b(Allocation,)12 b(Deallocation,)f(and)h(Reading)150 486 y ff(The)d(program)g(for)f(this)g(section)g(will)f(demonstrate)i fc(vm_allocate) p ff(,)f fc(vm_read)p ff(,)h(and)g fc(vm_deallocate)p ff(.)150 536 y(The)i (purpose)f(of)g(this)f(example)i(is)f(to)g(check)h fc(vm_read)f ff(to)f(be)i (sure)f(the)h(data)f(was)h(read)g(correctly)m(.)212 585 y(The)20 b(\014rst)g (step)f(in)g(solving)f(this)g(problem)h(is)h(to)f(get)g(a)h(chunk)f(of)g(memo\ ry)h(and)g(\014ll)e(it)h(with)f(data.)150 635 y fc(vm_allocate)10 b ff(is)g (used)h(to)f(get)h(the)f(virtual)f(memory)m(.)18 b(Data)11 b(is)g(then)f(stor\ ed)g(in)g(it.)16 b(The)c(next)e(step)h(is)f(to)g(call)150 685 y fc(vm_read)p ff(.)20 b fc(vm_read)11 b ff(allows)g(a)i(task)f(to)f(read)h(another)g(task') n(s)f(virtual)f(memory)m(.)22 b(Passing)11 b(the)h(address)g(of)150 735 y(the) f(previously)f(allocated)i(memory)g(as)g(a)h(starting)d(point,)h fc(vm_read)g ff(is)g(called.)20 b(Note)12 b(that)f(our)g(example)h(is)150 785 y(a)h(simpli\ \014ed)f(use)h(of)f fc(vm_read)g ff(since)h(a)g(task)g(is)f(reading)g(its)g (own)g(memory)m(.)24 b fc(vm_read)12 b ff(returns)f(a)j(newly)150 834 y(alloc\ ated)h(region)f(containg)g(the)g(data)h(read.)30 b(Note)15 b(that)f(the)g(par\ ameter)i fc(size)p ff(,)g(which)f(is)f(the)h(number)f(of)150 884 y(bytes)c (to)f(be)i(read,)g(must)f(be)h(an)f(integral)f(number)h(of)g(pages.)16 b fc (vm_read)10 b ff(can)h(be)f(checked)i(by)d(comparing)h(the)150 934 y(data)h (received)g(with)f(the)g(previously)f(allocated)i(chunk.)17 b(If)10 b(both)g (spaces)i(contain)e(the)g(same)i(data,)g fc(vm_read)150 984 y ff(worked)j(cor\ rectly)m(.)30 b(T)m(o)16 b(clean)g(up)e(before)i(ending)e(this)g(example)i (program,)g(both)f(allocated)g(spaces)h(must)150 1034 y(be)e(deallocated)g (by)g(calling)f fc(vm_deallocate)p ff(.)26 b(Note)14 b(that)f(the)h(data)g (returned)g(by)f fc(vm_read)h ff(must)g(be)150 1084 y(deallocated.)150 1193 y fd(3.1.1)42 b(V)n(irtual)10 b(Memory)g(Allocation)150 1270 y fc(vm_allocate)e ff(allocates)g(a)h(region)f(of)g(virtual)f(memory)m(,)j(placing)e(it)f(in)h (the)g(speci\014ed)h(task')n(s)f(address)h(space.)150 1320 y(The)17 b(size)f (parameter)h(is)f(the)g(number)g(of)f(bytes)h(to)g(allocate)g(which)f(is)h (rounded)f(to)h(an)g(integeral)f(number)150 1370 y(of)g(virtual)e(pages.)32 b (If)14 b(last)h(parameter)i(is)e fc(TRUE)f ff(the)h(kernel)g(allocates)h(a)g (region)e(of)h(memory)g(at)h(the)f(next)150 1420 y(convenient)e(location)f (and)h(returns)g(the)g(virtual)f(address)h(as)h(the)g(second)f(parameter)n (.)26 b(If)13 b(the)g(last)g(parameter)150 1470 y(is)g fc(FALSE)p ff(,)h(the) f(kernel)g(allocates)h(memory)g(starting)e(at)i(the)f(address)h(speci\014ed)h (by)e(the)g(second)h(parameter)n(.)150 1520 y fc(vm_page_size)c ff(is)i(a)g (global)e(constant)h(de\014ned)h(via)f fc(mach.h)p ff(.)19 b(A)12 b(page)g (of)f(newly)g(allocated)g(memory)h(is)150 1569 y(zero-\014lled)e(when)g(it)g (is)g(\014rst)g(touched.)240 1651 y fg(char)270 b(*data1;)240 1696 y(kern_ret\ ur)q(n_)q(t)70 b(rtn;)240 1788 y(if)23 b(\(\(rtn)h(=)f(vm_alloc)q(ate)q(\(t)q (ask)q(_s)q(el)q(f\(\))q(,)j(&data1,)f(vm_page_s)q(iz)q(e,)307 1833 y(TRUE\)\ \))g(!=)e(KERN_SUCC)q(ES)q(S\))j({)307 1879 y(mach_erro)q(r\(")q(vm)q(_a)q (llo)q(ca)q(te)g(returned)g(value)e(of)f(",)h(rtn\);)307 1925 y(printf\("v)q (mre)q(ad)q(:)i(Exiting.\\v)q(er)q(b+\\)q(+n)q("\);)307 1970 y(exit\(1\);)240 2016 y(})150 2172 y fd(3.1.2)42 b(V)n(irtual)10 b(Memory)g(Deallocation)150 2250 y fc(vm_deallocate)h ff(af)o(fects)i(only)e(the)h(memory)h(of)f(task)g (speci\014ed)h(as)f(the)g(\014rst)g(parameter)n(.)23 b(This)12 b(function)150 2300 y(reliquished)e(access)k(to)c(the)i(memory)g(speci\014ed)g(in)f(the)g (parameters:)18 b(address)12 b(and)g(size.)20 b(Other)11 b(tasks)h(which)150 2350 y(have)g(access)h(to)e(this)f(physical)g(memory)i(may)g(continue)e(to)h (use)g(it.)18 b(Note)11 b(the)g(size)h(is)f(expected)h(in)e(bytes)h(and)150 2399 y(is)j(rounded)f(up)g(to)h(give)f(a)i(page)f(boundary)m(.)26 b(Never)15 b (use)f fc(vm_deallocate)f ff(on)h(memory)g(that)f(has)i(been)150 2449 y(acqui\ red)10 b(by)g(UNIX)g fc(malloc)p ff(.)g eop %%Page: 18 11 bop 150 162 a ff(18)580 b fe(2)41 b(MESSAGE)11 b(COMMUNICA)n(TION)d(BETWEEN) k(PROCESSES)509 307 y fg(if)23 b(\(\(err)h(=)f(env_del_)q(por)q(t\()q(env)q (ir)q(on)q(men)q(t_)q(por)q(t,)j(port_name)q(\)\))688 353 y(!=)d(KERN_SUC)q (CES)q(S\))j({)688 399 y(mach_erro)q(r\()q("PA)q(RE)q(NT:)g(env_del_)q(por)q (t)g(returned)f(",)f(err\);)688 444 y(exit\(1\);)509 490 y(})509 535 y(if)f (\(\(err)h(=)f(port_dea)q(llo)q(ca)q(te\()q(ta)q(sk)q(_se)q(lf)q(\(\),)j(my_p\ ort\))q(\))688 581 y(!=)d(KERN_SUC)q(CES)q(S\))j({)688 627 y(mach_erro)q(r\() q("PA)q(RE)q(NT:)g(port_dea)q(llo)q(ca)q(te)g(returned)g(",)d(err\);)688 672 y (exit\(1\);)509 718 y(})509 764 y(printf\("PA)q(RE)q(NT:)j(Finished)g(success\ fu)q(ll)q(y.\\)q(n")q(\);)329 809 y(})329 855 y(else)47 b(printf\("E)q(rro)q (r)26 b(from)e(fork.\\n"\);)150 901 y(})g eop %%Page: 17 12 bop 150 162 a fe(2.12)41 b(Pr)n(ogramming)10 b(Example)h(I,)f(simp)r 13 2 v 12 w(ipc.c)890 b ff(17)329 307 y fg(for)24 b(\(i)f(=)g(0;)g(i)g(<)g(MAXDATA;) j(i++\))509 353 y(printf\("%d)g(",)d(msg_rcv.)q(in)q(lin)q(e_)q(da)q(ta[)q (i])q(\);)329 399 y(printf\(")q(\\n")q(\);)329 444 y(setup_si)q(mp_)q(re)q (pl)q(y\(&)q(ms)q(g_x)q(mt)q(,)j(&msg_rcv\);)329 490 y(if)e(\(\(ret)g(=)f(msg\ _send\()q(&ms)q(g_)q(xm)q(t,)j(MSG_OPTIO)q(N_N)q(ON)q(E,)509 535 y(0\)\))d (!=)h(SEND_SUCCE)q(SS)q(\){)509 581 y(mach_error)q(\(")q(PAR)q(EN)q(T:)i(msg_\ send)g(returned)f(value)g(of)e(",)g(ret\);)509 627 y(exit\(1\);)329 672 y(}) 329 718 y(printf\(")q(PAR)q(EN)q(T:)j(Successfu)q(l)g(msg_send.\\)q(n")q(\);) 150 764 y(})150 992 y(main)e(\(argc,)h(argv\))329 1038 y(int)293 b(argc;)329 1083 y(char)271 b(**argv;)150 1175 y({)329 1220 y(kern_ret)q(urn)q(_t)71 b (err;)329 1266 y(port_t)227 b(my_port;)329 1312 y(env_name)q(_t)138 b(port_na\ me)q(;)329 1357 y(int)293 b(fret;)329 1449 y(if)24 b(\(argc)g(>)f(1\))g({)509 1494 y(printf\("no)j(argument)q(s)f(to)f(simp_ipc\\n)q("\))q(;)509 1540 y(exi\ t\(1\);)329 1586 y(})329 1631 y(/*)g(create)g(a)f(port)h(name)g(that)h(both)f (the)f(child)i(and)e(parent)i(will)f(know)h(*/)329 1677 y(sprintf\()q(por)q (t_)q(na)q(me,)h("ipc_tes)q(t_%)q(d")q(,)f(getpid\(\))q(\);)329 1768 y(/*)f (create)g(and)g(register)i(port)e(for)g(parent)h(to)e(receive)i(on)e(*/)329 1860 y(if)h(\(\(my_port)i(=)d(Register\(p)q(or)q(t_n)q(am)q(e\)\))j(==)e(PORT\ _NULL\))509 1905 y(exit\(1\);)329 1997 y(/*)g(fork)g(returns)h(0)e(if)g(child\ ,)i(and)f(the)f(child's)j(ID)d(to)g(the)h(parent.)48 b(*/)329 2042 y(fret)24 b (=)f(fork\(\);)329 2088 y(if)h(\(fret)g(==)f(0\))h({)e(/*)i(child)g(process)h (*/)509 2134 y(if)e(\(\(my_port)j(=)d(LookFor\(p)q(ort)q(_n)q(am)q(e\)\))j (==)d(PORT_NUL)q(L\))688 2179 y(exit\(1\);)509 2225 y(child_rout)q(in)q(e\(m) q(y_)q(po)q(rt\))q(;)509 2271 y(printf\("CH)q(IL)q(D:)j(Finished)g(successful) q(ly)q(.\\n)q("\))q(;)329 2316 y(})329 2362 y(else)e(if)g(\(fret)g(>0\))g({)f (/*)g(parent)i(process)g(*/)509 2408 y(parent_rou)q(ti)q(ne\()q(my)q(_p)q(ort) q(\);)g eop %%Page: 16 13 bop 150 162 a ff(16)580 b fe(2)41 b(MESSAGE)11 b(COMMUNICA)n(TION)d(BETWEEN) k(PROCESSES)150 307 y fg(})150 535 y(/*)23 b(This)h(routine)i(is)d(called)i (to)e(demonstra)q(te)j(the)e(passing)h(of)e(a)g(simple)i(message.)172 581 y (*)e(Please)i(see)f(program)h(comment)g(for)f(order)h(of)e(events.)i(*/)150 672 y(void)f(child_rou)q(ti)q(ne\()q(my)q(_p)q(ort)q(\))329 718 y(port_t)227 b (my_port;)150 809 y({)329 855 y(msg_retu)q(rn_)q(t)93 b(ret;)329 901 y(int) 293 b(i;)329 946 y(struct)25 b(simp_msg)q(_st)q(ru)q(ct)48 b(msg_xmt,)26 b (msg_rcv;)329 1038 y(setup_si)q(mp_)q(re)q(qu)q(est)q(\(&)q(msg)q(_x)q(mt)q (,)f(my_port\))q(;)329 1083 y(if)f(\(\(ret)g(=)f(msg_rpc\(&)q(msg)q(_x)q(mt)q (.h,)j(MSG_OPTI)q(ON_)q(NO)q(NE,)g(sizeof\(m)q(sg_)q(xm)q(t\))q(,)f(0,)509 1129 y(0\)\))e(!=)h(RPC_SUCCES)q(S\))i({)509 1175 y(mach_error)q(\(")q(CHI)q (LD)q(:)g(msg_rpc)f(returned)h(value)e(of)f(",)h(ret\);)509 1220 y(exit\(1\);) 329 1266 y(})329 1312 y(printf\(")q(CHI)q(LD)q(:)i(Successful)g(msg_rpc.\\)q (n")q(\);)150 1357 y(})150 1586 y(void)e(parent_ro)q(ut)q(ine)q(\(m)q(y_)q (por)q(t\))329 1631 y(port_t)227 b(my_port;)150 1723 y({)329 1768 y(msg_retu) q(rn_)q(t)93 b(ret;)329 1814 y(int)293 b(i;)329 1860 y(int)g(x;)329 1905 y (msg_head)q(er_)q(t)93 b(msg_xmt;)329 1951 y(struct)25 b(simp_msg)q(_st)q(ru) q(ct)h(msg_rcv;)329 2042 y(msg_rcv.)q(h.m)q(sg)q(_l)q(oca)q(l_)q(por)q(t)g (=)d(my_port;)329 2088 y(msg_rcv.)q(h.m)q(sg)q(_s)q(ize)j(=)d(sizeof\(ms)q (g_)q(rcv)q(\);)329 2134 y(if)h(\(\(ret)g(=)f(msg_recei)q(ve\()q(&m)q(sg)q (_rc)q(v.)q(h,)j(MSG_OPTIO)q(N_N)q(ON)q(E,)g(0\)\))e(!=)509 2179 y(RCV_SUCCES) q(S\))i({)509 2225 y(mach_error)q(\(")q(PAR)q(EN)q(T:)g(msg_recei)q(ve)g(retu\ rned)g(value)e(of)f(",)h(ret\);)509 2271 y(exit\(1\);)329 2316 y(})329 2362 y (printf\(")q(PAR)q(EN)q(T:)i(Successfu)q(l)g(msg_receiv)q(e.)q(\\n")q(\);)329 2408 y(printf\(")q(PAR)q(EN)q(T:)g(Data.."\);)g eop %%Page: 15 14 bop 150 162 a fe(2.12)41 b(Pr)n(ogramming)10 b(Example)h(I,)f(simp)r 13 2 v 12 w(ipc.c)890 b ff(15)172 307 y fg(*)23 b(associat)q(ed)j(with)e(the)g(given) g(name.)172 353 y(*/)150 444 y(port_t)h(LookFor\(n)q(ame)q(\))329 490 y(env_n\ ame)q(_t)138 b(name;)150 581 y({)329 627 y(port_t)227 b(result;)329 672 y(ker\ n_ret)q(urn)q(_t)71 b(error;)329 764 y(if)24 b(\(\(error)h(=)e(env_get_po)q (rt)q(\(e)q(nvi)q(ro)q(nme)q(nt)q(_p)q(ort)q(,)j(name,)509 809 y(&result\)\)) g(!=)d(KERN_SUCC)q(ES)q(S\))j({)688 855 y(mach_erro)q(r\()q("CH)q(IL)q(D:)g (env_get_p)q(ort)g(returned)g(",)867 901 y(error\);)688 946 y(exit\(1\);)509 992 y(})329 1083 y(printf\(")q(CHI)q(LD)q(:)g(Successful)g(env_get_p)q(or)q (t.)q(\\n")q(\);)329 1129 y(return\(r)q(esu)q(lt)q(\);)150 1175 y(})150 1403 y (/*)d(This)h(routine)i(is)d(used)h(by)f(the)h(parent)h(to)e(create)i(a)e(port\ ,)h(and)g(to)f(associat)q(e)i(the)172 1449 y(*)e(port)h(name)g(with)g(the)g (port)g(via)g(the)g(environmen)q(t)i(manager.)172 1494 y(*)d(port_all)q(oca)q (te)j(is)d(used)h(to)g(allocate)h(a)e(port,)i(and)e(then)h(env_set_)q(po)q (rt)i(is)d(called)172 1540 y(*)g(passing)j(the)d(name)h(of)g(the)f(port,)i (and)e(the)h(newly)h(allocated)h(port.)69 b(*/)150 1631 y(port_t)25 b(Registe\ r\()q(nam)q(e\))329 1677 y(env_name)q(_t)317 b(name;)150 1768 y({)329 1814 y (port_t)227 b(result;)329 1860 y(kern_ret)q(urn)q(_t)71 b(error;)329 1951 y (if)24 b(\(\(error)h(=)e(port_alloc)q(at)q(e\()q(tas)q(k_)q(sel)q(f\()q(\),)j (&result\)\))g(!=)d(KERN_SUC)q(CE)q(SS\))j({)509 1997 y(mach_error)q(\(")q (PAR)q(EN)q(T:)g(port_allo)q(ca)q(te)g(returned)g(value)e(of)f(",)h(error\);) 509 2042 y(exit\(1\);)329 2088 y(})329 2134 y(if)g(\(\(error)h(=)e(env_set_po) q(rt)q(\(e)q(nvi)q(ro)q(nme)q(nt)q(_p)q(ort)q(,)j(name,)509 2179 y(result\)\)) f(!=)f(KERN_SUCCE)q(SS)q(\))h({)509 2225 y(mach_error)q(\(")q(PAR)q(EN)q(T:)h (env_set_p)q(or)q(t)f(returned)h(value)f(of)e(",)g(error\);)509 2271 y(exit\(\ 1\);)329 2316 y(})329 2362 y(printf\(")q(PAR)q(EN)q(T:)j(Successfu)q(l)g(env_\ set_po)q(rt)q(.\\n)q("\))q(;)329 2408 y(return\(r)q(esu)q(lt)q(\);)g eop %%Page: 14 15 bop 150 162 a ff(14)580 b fe(2)41 b(MESSAGE)11 b(COMMUNICA)n(TION)d(BETWEEN) k(PROCESSES)150 307 y fg({)329 353 y(int)24 b(i;)329 444 y(msg_xmt-)q(>h.)q (ms)q(g_)q(loc)q(al)q(_po)q(rt)i(=)d(thread_re)q(pl)q(y\(\))q(;)329 490 y(msg\ _xmt-)q(>h.)q(ms)q(g_)q(rem)q(ot)q(e_p)q(or)q(t)j(=)c(my_port;)329 535 y(msg_\ xmt-)q(>h.)q(ms)q(g_)q(siz)q(e)k(=)c(sizeof\(s)q(tr)q(uct)k(simp_msg)q(_st)q (ru)q(ct)q(\);)329 581 y(msg_xmt-)q(>h.)q(ms)q(g_)q(id)g(=)d(0x12345678)q(;) 329 627 y(msg_xmt-)q(>h.)q(ms)q(g_)q(typ)q(e)j(=)c(MSG_TYPE)q(_N)q(ORM)q(AL)q (;)329 672 y(msg_xmt-)q(>h.)q(ms)q(g_)q(sim)q(pl)q(e)j(=)e(TRUE;)329 764 y (msg_xmt-)q(>t.)q(ms)q(g_)q(typ)q(e_)q(nam)q(e)j(=)d(MSG_TYPE_I)q(NT)q(EGE)q (R_)q(32;)329 809 y(msg_xmt-)q(>t.)q(ms)q(g_)q(typ)q(e_)q(siz)q(e)j(=)d(32;) 329 855 y(msg_xmt-)q(>t.)q(ms)q(g_)q(typ)q(e_)q(num)q(be)q(r)j(=)c(MAXDATA;) 329 901 y(msg_xmt-)q(>t.)q(ms)q(g_)q(typ)q(e_)q(inl)q(in)q(e)k(=)c(TRUE;)329 946 y(msg_xmt-)q(>t.)q(ms)q(g_)q(typ)q(e_)q(lon)q(gf)q(or)q(m)j(=)e(FALSE;) 329 992 y(msg_xmt-)q(>t.)q(ms)q(g_)q(typ)q(e_)q(dea)q(ll)q(oc)q(ate)j(=)d(FAL\ SE;)329 1038 y(for)h(\(i)f(=)g(0;)g(i)g(<)g(MAXDATA;)j(i++\))509 1083 y(msg_x\ mt->i)q(nl)q(ine)q(_d)q(at)q(a[i)q(])g(=)c(i;)150 1175 y(})150 1312 y(/*)h (This)h(procedur)q(e)h(is)f(used)g(to)f(set)h(up)f(the)h(reply)g(message)h (that)g(the)e(parent)i(is)172 1357 y(*)e(sending)j(to)d(the)g(child.)48 b(Not\ e)24 b(that)g(the)g(remote_por)q(t)i(of)d(the)h(received)h(message)172 1403 y (*)e(designat)q(es)j(where)e(the)g(reply)g(message)i(will)e(be)f(sent.)i(No)e (data)h(is)f(sent)h(in)g(this)172 1449 y(*)f(message,)j(so)d(the)h(size)g(of) f(the)h(message)h(is)e(simply)i(the)f(size)g(of)f(the)h(message)172 1494 y (*)f(header.)48 b(*/)150 1586 y(void)24 b(setup_sim)q(p_)q(rep)q(ly)q(\(m)q (sg_)q(xm)q(t,)i(msg_rcv\))329 1631 y(msg_head)q(er_)q(t)272 b(*msg_xmt)q(;) 329 1677 y(struct)25 b(simp_msg)q(_st)q(ru)q(ct)48 b(*msg_rcv)q(;)150 1768 y ({)329 1814 y(msg_xmt-)q(>ms)q(g_)q(re)q(mot)q(e_)q(por)q(t)26 b(=)d(msg_rcv-\ >h)q(.m)q(sg_)q(re)q(mot)q(e_)q(po)q(rt;)329 1860 y(msg_xmt-)q(>ms)q(g_)q(lo) q(cal)q(_p)q(ort)j(=)d(PORT_NULL)q(;)329 1905 y(msg_xmt-)q(>ms)q(g_)q(id)j (=)d(0x1234567)q(8;)329 1951 y(msg_xmt-)q(>ms)q(g_)q(si)q(ze)j(=)d(sizeof\(ms\ g)q(_h)q(ead)q(er)q(_t)q(\);)329 1997 y(msg_xmt-)q(>ms)q(g_)q(ty)q(pe)j(=)d (MSG_TYPE_N)q(OR)q(MAL)q(;)329 2042 y(msg_xmt-)q(>ms)q(g_)q(si)q(mpl)q(e)j (=)c(TRUE;)150 2088 y(})150 2271 y(/*)h(This)h(procedur)q(e)h(is)f(used)g(by) f(the)h(child)g(to)f(get)h(the)g(communica)q(tio)q(n)i(port.)172 2316 y(*)d (The)h(child)g(got)g(the)g(name)g(as)f(part)h(of)f(its)h(inherited)i(static)f (variable)h(space.)172 2362 y(*)d(Port)h(rights,)i(however,)f(are)f(not)g(inh\ erited)i(across)f(forks.)g(env_get_po)q(rt)q(,)172 2408 y(*)e(a)g(utility)i (of)f(the)f(environm)q(ent)j(manager)g(is)d(called)i(to)e(return)i(the)f(port) g eop %%Page: 13 16 bop 150 162 a fe(2.12)41 b(Pr)n(ogramming)10 b(Example)h(I,)f(simp)r 13 2 v 12 w(ipc.c)890 b ff(13)150 307 y fb(2.12)50 b(Pr)o(ogramming)13 b(Example)g (I,)g(simp)s 15 2 v 16 w(ipc.c)150 394 y fg(/*)172 440 y(*)23 b(This)h(progra\ m)i(is)d(an)g(illustrat)q(io)q(n)j(of)d(MACH)h(message)h(passing)h(from)e(a)e (child)172 486 y(*)h(to)g(the)h(parent)h(process)g(and)f(back.)47 b(In)23 b (this)h(example,)i(the)e(child)g(is)f(passing)172 531 y(*)g(a)g(simple)i(mess\ age)g(where)g(the)e(data)i(is)e(stored)i(in)e(the)h(message.)h(The)f(program) 172 577 y(*)f(allocate)q(s)i(a)e(port)h(to)g(use)f(for)h(communica)q(tio)q (n.)49 b(The)23 b(environm)q(ent)j(manager)172 623 y(*)d(is)g(used)i(to)e(reg\ ister)j(the)d(port)h(with)g(a)f(name)h(that)g(both)g(the)g(parent)172 668 y (*)f(and)h(child)g(know.)h(The)f(program)h(forks)f(a)f(child)i(process)g(whic\ h)172 714 y(*)e(then)h(uses)g(env_get_)q(po)q(rt)i(to)d(acquire)i(the)f(port) g(needed)h(for)f(communicat)q(io)q(n.)172 760 y(*)f(A)g(message,)j(containin) q(g)f(the)f(data)g(the)g(parent)h(needs,)g(is)e(formed)i(by)e(the)h(child)172 805 y(*)f(and)h(sent)g(with)g(msg_rpc)h(to)f(the)f(parent.)48 b(msg_rpc)25 b (does)f(a)f(send)h(and)g(a)f(receive)172 851 y(*)g(using)i(the)e(same)h(messa\ ge)i(buffer.)48 b(The)23 b(parent)i(does)f(a)f(receive)i(on)f(the)172 897 y (*)f(establis)q(hed)j(communic)q(ati)q(on)g(port)e(receiving)i(the)e(message) h(from)f(the)g(child.)172 942 y(*)f(Upon)h(receivin)q(g)h(the)f(child's)h(mes\ sage,)h(the)e(parent)h(construct)q(s)g(and)f(sends)172 988 y(*)f(a)g(confirma\ t)q(io)q(n)i(or)f(reply)g(message)i(back)e(to)f(the)h(child)g(indicatin)q(g)i (he)d(received)172 1034 y(*)g(the)h(child's)h(message)h(and)d(data.)47 b(The) 24 b(call)g(to)f(msg_rpc)i(by)f(the)f(child)172 1079 y(*)g(receives)j(the)e (parent's)h(reply.)48 b(The)23 b(child)i(then)f(tells)g(the)g(environme)q(nt) 172 1125 y(*)f(manager)j(the)d(communic)q(ati)q(on)j(port)e(is)f(no)h(longer) h(needed,)g(and)f(calls)172 1171 y(*)f(port_dea)q(llo)q(ca)q(te.)172 1216 y (*)172 1262 y(********)q(**)q(***)q(**)q(***)q(**)q(**)q(***)q(**)q(***)q(**) q(**)q(***)q(**)q(***)q(**)q(**)q(***)q(**)q(***)q(**)q(**)q(/)150 1353 y(#in\ clude)j()150 1399 y(#include)g()150 1445 y(#include)g()150 1490 y(#include)g()150 1536 y(#in\ clude)g()150 1627 y(#define)f(MAXDATA)h(20)150 1719 y(/*)46 b(simple)25 b(message)g(structure)h(*/)150 1764 y(struct)f(simp_\ msg_)q(str)q(uc)q(t)h({)329 1810 y(msg_head)q(er_)q(t)93 b(h;)329 1856 y(msg_\ type)q(_t)138 b(t;)329 1901 y(int)293 b(inline_da)q(ta)q([MA)q(XD)q(ATA)q(];) 150 1947 y(};)150 2130 y(/*)23 b(This)h(routine)i(is)d(used)h(to)f(set)h(up)f (the)h(message)h(containin)q(g)h(the)d(data)h(that)172 2175 y(*)f(the)h(child) g(will)g(send)h(to)e(the)g(parent.)48 b(Here)24 b(the)g(data)g(is)f(a)g(simpl\ e)i(array)g(of)172 2221 y(*)e(integers)q(.)48 b(*/)150 2312 y(void)24 b(setup\ _sim)q(p_)q(req)q(ue)q(st)q(\(ms)q(g_)q(xmt)q(,)i(my_port\))329 2358 y(struct) f(simp_msg)q(_st)q(ru)q(ct)48 b(*msg_xmt)q(;)329 2403 y(port_t)227 b(my_port;) g eop %%Page: 12 17 bop 150 162 a ff(12)580 b fe(2)41 b(MESSAGE)11 b(COMMUNICA)n(TION)d(BETWEEN) k(PROCESSES)240 307 y fg(msg_xmt.t.)q(ms)q(g_t)q(yp)q(e_)q(dea)q(ll)q(oca)q (te)26 b(=)d(FALSE;)240 353 y(/*)g(set)h(msg_xmt.ou)q(t_)q(of_)q(li)q(ne_)q (da)q(ta)i(to)d(point)i(to)e(the)h(data)g(*/)g eop %%Page: 11 18 bop 150 162 a fe(2.11)41 b(A)11 b(Non-Simple)d(Message)1107 b ff(11)240 307 y fg(};)240 353 y(struct)25 b(simp_msg_s)q(tr)q(uct)49 b(msg_xmt;)240 444 y(if) 23 b(\(\(ret)h(=)f(msg_rpc\()q(&ms)q(g_)q(xmt)q(.h)q(,)j(MSG_OPTION)q(_N)q (ONE)q(,)g(sizeof\(msg)q(_x)q(mt\))q(,)g(0,)307 490 y(0\)\))e(!=)f(RPC_SUCCE) q(SS\))j({)307 535 y(mach_erro)q(r\(")q(CH)q(IL)q(D:)g(msg_rpc)f(returned)h (value)e(of)g(",)f(ret\);)307 581 y(exit\(1\);)240 627 y(})150 806 y fb(2.11) 50 b(A)12 b(Non-Simple)g(Message)150 885 y ff(Messages)h(are)f fe(non-simple) d ff(if)i(they)g(contain)f(ports)g(or)h(out-of-line)e(data.)19 b(The)11 b(nex\ t)g(example)h(shows)f(how)g(to)150 935 y(construct)e(a)i(data)g(containing)d (out-of-line)g(data.)16 b(The)11 b(most)f(common)g(reasons)h(for)f(sending)f (data)h(out-of-line)150 985 y(are)j(that)e(the)h(data)h(block)e(is)h(very)g (lar)o(ge)g(or)g(is)g(of)g(variable)f(size.)22 b(In-line)11 b(data)i(is)e(cop\ ied)h(by)g(the)g(sender)g(into)150 1035 y(the)h(message)i(structure)d(and)h (then)f(often)h(copied)g(out)f(of)g(the)h(message)i(by)d(the)h(receiver)n(.) 25 b(Out-of-line)10 b(data,)150 1085 y(however)n(,)j(is)f(mapped)g(by)g(the)f (kernel)h(from)g(the)g(address)g(space)h(of)f(the)g(sender)g(to)f(the)h(addre\ ss)g(space)i(of)d(the)150 1135 y(receiver)n(.)22 b(No)13 b(actual)f(copying)f (of)h(data)h(is)f(done)g(unless)g(one)g(of)g(the)h(two)e(tasks)i(subsequently) e(modi\014es)h(the)150 1184 y(data.)k(This)10 b(is)g(an)h(example)g(of)f(copy\ -on-write)e(data)j(sharing.)212 1235 y(The)16 b(\014elds)f(that)f(change)h (values)g(from)g(those)f(in)h(the)f(simple)h(message)h(example)g(are)g fc(msg\ _simple)p ff(,)150 1285 y fc(msg_type_inline)p ff(,)f(and)g(possibly)e fc(msg\ _type_deallocate)p ff(.)28 b(See)16 b(Section)e(2.6)h(for)f(details)g(on)150 1335 y fc(msg_remote_port)i ff(and)i fc(msg_local_port)p ff(.)38 b(An)17 b (example)i(program)e(of)h(non-simple)e(message)150 1384 y(passing)j(can)g(be) h(found)e(in)g(the)h(Mach)h(examples)f(directory)m(.)42 b(This)19 b(example)h (is)e(not)h(included)f(in)g(this)150 1434 y(document,)10 b(but)g(can)h(be)f (found)g(in)f(the)h(\014le)h fc(ool_ipc.c)e ff(in)h(the)g(Mach)h(examples)g (directory)m(.)240 1525 y fg(struct)25 b(ool_msg_st)q(ru)q(ct)h({)307 1571 y (msg_heade)q(r_t)94 b(h;)307 1616 y(msg_type_)q(t)138 b(t;)307 1662 y(int)293 b(*out_of_li)q(ne)q(_da)q(ta)q(;)240 1708 y(};)240 1753 y(struct)25 b(ool_msg\ _st)q(ru)q(ct)71 b(msg_xmt;)240 1799 y(port_t)226 b(comm_por)q(t;)240 1947 y (msg_xmt.h.)q(ms)q(g_l)q(oc)q(al)q(_po)q(rt)26 b(=)d(thread_re)q(ply)q(\(\))q (;)240 1993 y(msg_xmt.h.)q(ms)q(g_r)q(em)q(ot)q(e_p)q(or)q(t)i(=)e(comm_por)q (t;)240 2038 y(msg_xmt.h.)q(ms)q(g_s)q(iz)q(e)j(=)c(sizeof\(s)q(tr)q(uct)k (ool_msg_)q(str)q(uc)q(t\);)240 2084 y(msg_xmt.h.)q(ms)q(g_i)q(d)g(=)d(0x1234\ 5678)q(;)240 2130 y(msg_xmt.h.)q(ms)q(g_t)q(yp)q(e)j(=)c(MSG_TYPE)q(_N)q(ORM) q(AL)q(;)240 2175 y(msg_xmt.h.)q(ms)q(g_s)q(im)q(pl)q(e)j(=)e(FALSE;)240 2267 y(msg_xmt.t.)q(ms)q(g_t)q(yp)q(e_)q(nam)q(e)j(=)c(MSG_TYPE)q(_I)q(NTE)q(GE)q (R_)q(32;)240 2312 y(msg_xmt.t.)q(ms)q(g_t)q(yp)q(e_)q(siz)q(e)k(=)c(32;)240 2358 y(msg_xmt.t.)q(ms)q(g_t)q(yp)q(e_)q(num)q(be)q(r)j(=)e(MAXDATA;)240 2403 y(msg_xmt.t.)q(ms)q(g_t)q(yp)q(e_)q(inl)q(in)q(e)i(=)e(FALSE;)240 2449 y(msg_\ xmt.t.)q(ms)q(g_t)q(yp)q(e_)q(lon)q(gf)q(orm)j(=)d(FALSE;)g eop %%Page: 10 19 bop 150 162 a ff(10)580 b fe(2)41 b(MESSAGE)11 b(COMMUNICA)n(TION)d(BETWEEN) k(PROCESSES)240 307 y fg(msg_rcv.h.)q(ms)q(g_l)q(oc)q(al)q(_po)q(rt)26 b(=)d (comm_port)q(;)240 353 y(if)g(\(\(ret)h(=)f(msg_rece)q(ive)q(\(&)q(msg)q(_r)q (cv)q(.h,)j(MSG_OPTI)q(ON_)q(NO)q(NE,)g(0\)\))e(!=)307 399 y(RCV_SUCCE)q(SS\)) q({)307 444 y(mach_erro)q(r\(")q(CH)q(IL)q(D:)i(msg_recei)q(ve)g(returned)g (value)e(of)f(",)h(ret\);)307 490 y(exit\(1\);)240 535 y(})150 711 y fb(2.9) 50 b(Setting)11 b(up)h(a)g(Reply)g(Message)150 790 y ff(At)e(this)f(point)f (a)j(message)h(has)e(already)h(been)f(received)h(in)f(the)g(structure)f fc (msg_rcv)p ff(.)15 b(A)10 b(reply)g(message)i(is)e(to)150 839 y(be)e(construc\ ted)g(and)g(sent)g(to)f(the)h(sender)g(of)g fc(msg_rcv)p ff(.)15 b(Note)8 b (that)f(the)h(reply)f(message,)k fc(msg_xmt)c ff(is)h(simply)150 889 y(a)13 b fc(msg_header_t)f ff(since)h(no)f(data)h(is)g(required.)23 b(The)13 b fc(msg_\ remote_port)e ff(\014eld,)j(where)f(to)f(send)h(the)150 939 y(message,)g(is)e (set)h(to)e(the)h(remote)g(port)f(of)h(the)g(previously)e(received)j(message.) 20 b(The)12 b(earlier)f fc(msg_receive)150 989 y ff(call)g(set)g(the)g(remote) g(port)f(\014eld)h(of)g fc(msg_rcv)g ff(to)f(the)h fc(msg_local_port)f ff(\ \014eld)g(speci\014ed)i(by)f(the)g(sender)n(.)150 1039 y(See)g(the)f(comment) h(in)f(Section)g(2.6)g(about)g(setting)f(up)h(the)g fc(msg_local_port)f ff (\014eld.)240 1128 y fg(struct)25 b(simp_msg_s)q(tr)q(uct)h({)307 1173 y(msg_\ heade)q(r_t)94 b(h;)307 1219 y(msg_type_)q(t)138 b(t;)307 1265 y(int)293 b (inline_dat)q(a[)q(MAX)q(DA)q(TA])q(;)240 1310 y(};)240 1356 y(msg_header)q (_t)273 b(msg_xmt;)240 1402 y(struct)25 b(simp_msg_s)q(tr)q(uct)49 b(*msg_rcv\ ;)240 1546 y(msg_xmt.h.)q(ms)q(g_r)q(em)q(ot)q(e_p)q(or)q(t)25 b(=)e(msg_rcv-) q(>h.)q(ms)q(g_)q(rem)q(ot)q(e_p)q(or)q(t;)240 1591 y(msg_xmt.h.)q(ms)q(g_l)q (oc)q(al)q(_po)q(rt)j(=)d(PORT_NULL)q(;)i(/*)f(no)f(reply)h(expected)i(*/)240 1637 y(msg_xmt.h.)q(ms)q(g_i)q(d)g(=)d(0x12345678)q(;)240 1683 y(msg_xmt.h.)q (ms)q(g_s)q(iz)q(e)j(=)c(sizeof\(m)q(sg)q(_he)q(ad)q(er_)q(t\))q(;)240 1728 y (msg_xmt.h.)q(ms)q(g_t)q(yp)q(e)k(=)c(MSG_TYPE)q(_N)q(ORM)q(AL)q(;)240 1774 y (msg_xmt.h.)q(ms)q(g_s)q(im)q(pl)q(e)j(=)e(TRUE;)150 1950 y fb(2.10)50 b(RPC,) 13 b(Send/Receive)150 2028 y fc(msg_rpc)18 b ff(does)h(a)g fc(msg_send)f ff (followed)f(by)i(a)g fc(msg_receive)f ff(using)f(the)i(same)h(message)g(buf)o (fer)n(.)150 2078 y fc(msg_size)9 b ff(is,)g(as)h(usual,)f(the)g(size)h(of)f (the)g(message)i(that)d(is)h(being)g(sent.)15 b(The)10 b(third)e(parameter)i (to)f fc(msg_rpc)150 2128 y ff(represents)i(the)f(maximum)h(size)g(of)f(the)g (message)i(buf)o(fer)e(for)g(the)g(message)i(to)d(be)i(received.)17 b(In)10 b (this)f(case)j(it)d(is)150 2178 y(the)h(size)h(of)f(the)g(message)i(being)e (sent)g(because)i(we)f(know)e(that)h(the)g(reply)g(message)i(is)e(smaller)n (.)240 2267 y fg(msg_return)q(_t)93 b(ret;)240 2312 y(struct)25 b(simp_msg_s) q(tr)q(uct)h({)307 2358 y(msg_heade)q(r_t)94 b(h;)307 2403 y(msg_type_)q(t) 138 b(t;)307 2449 y(int)293 b(inline_dat)q(a[)q(MAX)q(DA)q(TA])q(;)g eop %%Page: 9 20 bop 150 162 a fe(2.7)41 b(Sending)10 b(Messages)1230 b ff(9)240 307 y fg(msg\ _xmt.t.)q(ms)q(g_t)q(yp)q(e_)q(num)q(be)q(r)25 b(=)e(MAXDATA;)240 353 y(msg_x\ mt.t.)q(ms)q(g_t)q(yp)q(e_)q(inl)q(in)q(e)i(=)e(TRUE;)240 399 y(msg_xmt.t.)q (ms)q(g_t)q(yp)q(e_)q(lon)q(gf)q(orm)j(=)d(FALSE;)240 444 y(msg_xmt.t.)q(ms)q (g_t)q(yp)q(e_)q(dea)q(ll)q(oca)q(te)j(=)d(FALSE;)240 490 y(/*)g(fill)h(the)g (msg_xmt.in)q(li)q(ne_)q(da)q(ta)i(array)e(with)h(the)e(desired)j(data)e(*/) 150 668 y fb(2.7)50 b(Sending)11 b(Messages)150 746 y ff(The)h(\014rst)e(para\ meter)i(to)f fc(msg_send)f ff(is)h(the)g(address)g(of)g(a)h fc(msg_header_t)p ff(.)17 b(This)10 b(message)j(will)d(be)h(sent)150 796 y(to)j(the)g(port)g (indicated)f(by)i(the)f fc(msg_remote_port)f ff(\014eld.)28 b(Send)15 b(right\ s)e(to)h fc(msg_local_port)f ff(are)150 846 y(given)d(to)f(the)h(receiver)h (so)g(that)e(it)h(may)h(send)f(a)h(reply)f(message.)240 936 y fg(msg_return)q (_t)93 b(ret;)240 982 y(struct)25 b(simp_msg_s)q(tr)q(uct)h({)307 1027 y(msg_\ heade)q(r_t)94 b(h;)307 1073 y(msg_type_)q(t)138 b(t;)307 1119 y(int)293 b (inline_dat)q(a[)q(MAX)q(DA)q(TA])q(;)240 1164 y(};)240 1210 y(struct)25 b (simp_msg_s)q(tr)q(uct)49 b(msg_xmt;)240 1301 y(if)23 b(\(\(ret)h(=)f(msg_sen\ d)q(\(&m)q(sg)q(_xm)q(t.)q(h,)j(MSG_OPTIO)q(N_)q(NON)q(E,)g(0\)\))e(!=)f(SEND\ _SUCC)q(ES)q(S\){)307 1347 y(mach_erro)q(r\(")q(CH)q(IL)q(D:)j(msg_send)g(ret\ urned)f(value)g(of)e(",)g(ret\);)307 1393 y(exit\(1\);)240 1438 y(})150 1616 y fb(2.8)50 b(Receiving)12 b(Messages)150 1695 y fc(msg_receive)34 b ff(is)g (used)h(to)g(retrieve)f(the)h(next)f(message)j(from)d(a)i(port)e(speci\014ed) h(in)f(the)150 1745 y fc(msg_remote_port)19 b ff(\014eld.)45 b(The)20 b(\014e\ ld)g fc(msg_size)g ff(must)g(be)g(set)g(to)g(the)g(size)g(of)g(the)g(buf)o (fer)g(for)150 1795 y(the)12 b(message)j(and)d(thus)g(the)g(maximum)h(permitt\ ed)f(size)h(of)f(the)h(message)h(being)e(received.)23 b(If)12 b(the)g(message) 150 1844 y(that)k(is)g(queued)h(on)f(the)g(port)g(is)g(too)g(big,)h(the)g(rec\ eive)g(will)e(fail.)34 b(When)17 b fc(msg_receive)e ff(returns,)j(the)150 1894 y fc(msg_remote_port)13 b ff(\014eld)h(will)e(be)j(set)f(to)f(the)h(sender)r (')n(s)g fc(msg_local_port)f ff(\014eld,)i(or)f(the)g(port)f(that)150 1944 y (reply)i(messages)i(are)e(expected)h(on)f(and)g fc(msg_size)g ff(will)e(be)j (set)f(to)g(the)g(size)g(of)g(the)g(message)i(that)d(was)150 1994 y(received.) 240 2084 y fg(msg_return)q(_t)93 b(ret;)240 2130 y(struct)25 b(simp_msg_s)q (tr)q(uct)h({)307 2175 y(msg_heade)q(r_t)94 b(h;)307 2221 y(msg_type_)q(t)138 b(t;)307 2267 y(int)293 b(inline_dat)q(a[)q(MAX)q(DA)q(TA])q(;)240 2312 y(};) 240 2358 y(struct)25 b(simp_msg_s)q(tr)q(uct)49 b(msg_rcv;)240 2449 y(msg_rcv\ .h.)q(ms)q(g_s)q(iz)q(e)26 b(=)c(sizeof\(m)q(sg)q(_rc)q(v\))q(;)g eop %%Page: 8 21 bop 150 162 a ff(8)601 b fe(2)41 b(MESSAGE)11 b(COMMUNICA)n(TION)d(BETWEEN)k (PROCESSES)666 307 y fg(&comm_port)q(\)\))26 b(!=)d(KERN_SUC)q(CES)q(S\))j ({)307 353 y(mach_erro)q(r\(")q(en)q(v_)q(get)q(_p)q(ort)g(returned)g(",)d (error\);)307 399 y(exit\(1\);)240 444 y(})150 615 y fb(2.6)50 b(Setting)11 b (up)h(a)g(Simple)g(Message)150 692 y ff(A)f(message)h(consists)e(of)g(a)i(\ \014xed)e(length)g(header)h(de\014ned)g(by)f(the)h(structure)f fc(msg_header_\ t)f ff(followed)g(by)150 742 y(a)k(variable)g(number)g(of)f(typed)h(data)g (items.)23 b(A)13 b(message)i(is)e fe(simple)f ff(if)g(it)g(does)h(not)f(cont\ ain)h(any)f(out-of-line)150 792 y(data)j(\(pointers\))d(or)i(any)h(ports.)27 b (The)15 b fc(msg_remote_port)d ff(\014eld)j(must)f(contain)f(the)i(port)e(to) g(which)h(the)150 842 y(message)f(is)e(to)g(be)h(sent.)19 b(In)11 b(this)f (case)j(it)e(is)g fc(comm_port)p ff(.)19 b(The)12 b fc(msg_local_port)e ff (\014eld)h(should)f(be)i(set)150 892 y(to)g(the)h(port)e(or)i(port)f(set)h (on)f(which)g(a)i(reply)e(message)i(is)f(expected.)24 b fc(thread_reply\(\))p ff(,)12 b(which)h(returns)150 942 y(the)c(thread')n(s)g(reply)g(port)g(is)g (used)h(as)g(the)f(reply)g(port.)15 b(An)9 b(example)i(of)e(using)f(a)i(port) f(set)h(for)f(the)g(reply)g(port)f(can)150 991 y(be)j(found)e(in)g fe(A)i(Pr) n(ogrammer)r(')-5 b(s)11 b(Guide)e(to)h(the)g(Mach)g(User)h(Envir)n(onment)p ff(.)240 1077 y fg(typedef)25 b(struct)g({)486 1123 y(unsigned)h(int)91 b(:24\ ,)845 1168 y(msg_simpl)q(e)25 b(:)e(8;)486 1214 y(unsigned)j(int)91 b(msg_siz\ e;)161 b(/*)23 b(in)g(bytes)i(*/)486 1260 y(int)293 b(msg_type;)161 b(/*)23 b (NORMAL,)i(EMERGENCY)h(*/)486 1305 y(port_t)227 b(msg_local)q(_po)q(rt)q(;) 486 1351 y(port_t)g(msg_remot)q(e_p)q(or)q(t;)486 1397 y(int)293 b(msg_id;) 205 b(/*)23 b(user)h(supplied)i(id)d(*/)240 1442 y(})f(msg_head)q(er)q(_t;) 240 1579 y(struct)j(simp_msg_s)q(tr)q(uct)h({)307 1625 y(msg_heade)q(r_t)94 b (h;)307 1671 y(msg_type_)q(t)138 b(t;)307 1716 y(int)293 b(inline_dat)q(a[)q (MAX)q(DA)q(TA])q(;)240 1762 y(};)240 1808 y(struct)25 b(simp_msg_s)q(tr)q (uct)49 b(msg_xmt;)240 1853 y(port_t)226 b(comm_por)q(t;)240 1991 y(msg_xmt=) 25 b(&msg_xmt)q(_d)q(ata)q(;)240 2037 y(msg_xmt.h.)q(ms)q(g_l)q(oc)q(al)q(_po) q(rt)h(=)d(thread_re)q(ply)q(\(\))q(;)240 2083 y(msg_xmt.h.)q(ms)q(g_r)q(em)q (ot)q(e_p)q(or)q(t)i(=)e(comm_por)q(t;)240 2128 y(msg_xmt.h.)q(ms)q(g_s)q(iz) q(e)j(=)c(sizeof\(s)q(tr)q(uct)k(simp_msg)q(_st)q(ru)q(ct\))q(;)240 2174 y (msg_xmt.h.)q(ms)q(g_i)q(d)g(=)d(0x12345678)q(;)240 2220 y(msg_xmt.h.)q(ms)q (g_t)q(yp)q(e)j(=)c(MSG_TYPE)q(_N)q(ORM)q(AL)q(;)240 2265 y(msg_xmt.h.)q(ms)q (g_s)q(im)q(pl)q(e)j(=)e(TRUE;)240 2403 y(msg_xmt.t.)q(ms)q(g_t)q(yp)q(e_)q (nam)q(e)j(=)c(MSG_TYPE)q(_I)q(NTE)q(GE)q(R_)q(32;)240 2449 y(msg_xmt.t.)q (ms)q(g_t)q(yp)q(e_)q(siz)q(e)k(=)c(32;)g eop %%Page: 7 22 bop 150 162 a fe(2.3)41 b(Port)11 b(Deallocation)1232 b ff(7)150 307 y fb (2.3)50 b(Port)13 b(Deallocation)150 385 y fc(port_deallocate)d ff(is)i(used) f(to)g(relinquish)f(a)i(task')n(s)f(access)j(to)d(a)h(port.)18 b(If)12 b(the) f(task)h(has)f(ownership)g(and)150 435 y(receive)j(rights)d(to)i(the)f(port,) h(the)g fc(port_deallocate)e ff(destroys)i(the)f(port)g(and)h(noti\014es)f (\(on)h(their)f(notify)150 485 y(ports\))d(all)h(the)g(other)g(tasks)g(that)g (have)h(send)f(rights)f(to)h(the)g(port.)240 571 y fg(port_t)226 b(my_port;) 240 616 y(kern_retur)q(n_)q(t)70 b(error;)240 707 y(if)23 b(\(\(error)i(=)e (port_deal)q(lo)q(cat)q(e\()q(ta)q(sk_)q(se)q(lf\()q(\),)j(my_port\)\))g(!=)e (KERN_SUCCE)q(SS)q(\))h({)307 753 y(mach_erro)q(r\(")q(PA)q(RE)q(NT:)h(port_d\ ea)q(llo)q(ca)q(te)g(returned)g(value)e(of)f(",)h(error\);)307 799 y(exit\(1\ \);)240 844 y(})150 1015 y fb(2.4)50 b(Envir)o(onment)12 b(Manager)g(Server/C\ hecking)f(in)h(a)h(Port)150 1093 y ff(The)c(Environment)f(Manager)i(is)e(used) h(as)h(a)f(repository)e(for)h(named)i(ports.)k fc(env_get_port)8 b ff(can)i (be)f(used)g(to)150 1143 y(associate)h(a)g(name)g(with)e(a)i(port.)k(Note)9 b (that)g(the)g(port)f(must)h(have)h(been)g(previously)d(acquired)i(either)g (through)f(a)150 1193 y(message,)13 b(or)d(from)g fc(port_allocate)p ff(,)g (or)h(be)f(one)h(of)f(the)h(special)g(system)g(ports)e(that)h(are)i(aquired)e (on)g(task)150 1243 y(creation.)16 b(Name)11 b(has)g(been)g(set)f(to)g(a)h (string.)240 1328 y fg(env_name_t)138 b(name;)240 1374 y(port_t)226 b(comm_po\ r)q(t;)240 1420 y(kern_retur)q(n_)q(t)70 b(error;)240 1558 y(if)23 b(\(\(erro\ r)i(=)e(env_set_p)q(or)q(t\(e)q(nv)q(ir)q(onm)q(en)q(t_p)q(or)q(t,)j(name,) 710 1604 y(comm_por)q(t\))q(\))f(!=)f(KERN_SUCCE)q(SS)q(\))h({)307 1650 y(mac\ h_erro)q(r\(")q(PA)q(RE)q(NT:)h(env_set_)q(por)q(t)g(returned)f(value)g(of)e (",)g(error\);)307 1695 y(exit\(1\);)240 1741 y(})150 1912 y fb(2.5)50 b(Envi\ r)o(onment)12 b(Manager)g(Server/Looking)g(up)f(a)i(Port)150 1990 y fc(env_ge\ t_port)20 b ff(can)i(be)f(used)g(to)f(look)g(up)h(a)g(port)f(when)h(the)g(nam\ e)h(of)e(the)h(port)f(is)g(known.)47 b(If)150 2039 y fc(env_set_port)13 b ff (has)h(not)f(been)h(called)g(to)g(associate)g(a)h(port)d(with)h(the)h(given)f (name,)j fc(env_get_port)150 2089 y ff(will)9 b(fail.)240 2175 y fg(env_name_\ t)138 b(name;)240 2221 y(port_t)226 b(comm_por)q(t;)240 2267 y(kern_retur)q (n_)q(t)70 b(error;)240 2358 y(/*)23 b(Name)h(has)g(been)g(previously)i(set)e (to)f(a)g(desired)i(string.)h(*/)240 2449 y(if)d(\(\(error)i(=)e(env_get_p)q (or)q(t\(e)q(nv)q(ir)q(onm)q(en)q(t_p)q(or)q(t,)j(name,)g eop %%Page: 6 23 bop 150 162 a ff(6)601 b fe(2)41 b(MESSAGE)11 b(COMMUNICA)n(TION)d(BETWEEN)k (PROCESSES)212 307 y ff(Next)e(the)g(parent)h(takes)f(a)h(message)h(structure) e(and)g(\014lls)g(in)f(the)h(header)h(\014elds)g(needed)g(by)150 357 y fc(msg\ _receive)p ff(:)31 b fc(msg_remote_port)p ff(,)20 b(representing)e(the)h(port) f(on)g(which)h(the)f(message)j(is)e(to)f(be)150 407 y(received,)24 b(and)d fc (msg_size)p ff(,)i(the)d(maximum)i(size)f(of)f(the)h(expected)g(message.)49 b (W)n(ith)20 b(this)f(message)150 457 y(structure,)9 b(the)h(parent)f(calls)g fc(msg_receive)p ff(.)15 b fc(msg_receive)8 b ff(returns)h(the)g(message)j (queued)d(on)g(the)g(port)150 506 y(designated)h(by)g(the)g fc(msg_remote_por\ t)f ff(\014eld.)15 b(Remember)d(that)e(the)g(child')n(s)f(message)j(contained) d(a)i(port)150 556 y(to)g(send)h(a)h(reply)e(message)i(to,)f(the)g fc(msg_loc\ al_port)f ff(\014eld.)20 b(Upon)11 b(return)g(from)h fc(msg_receive)p ff(,)f (the)150 606 y fc(msg_remote_port)e ff(\014eld)h(is)g(set)h(to)e(the)i(child') n(s)e fc(msg_local_port)g ff(\014eld,)h(the)g(expected)h(reply)f(port.)212 661 y(In)f(our)g(example,)h(the)f(parent)g(is)g(going)f(to)g(send)i(a)f(message)i (back)f(to)e(the)h(child)f(indicating)g(that)g(it)g(received)150 711 y(the)h (message)i(containing)d(the)h(data.)16 b(This)9 b(reply)g(message)i(contains) e(no)g(data)h(itself;)e(it)h(is)g(just)g(a)g(con\014rmation.)150 761 y(The)k (parent)g(sets)g(the)f fc(msg_remote_port)g ff(\014eld)g(of)h(the)f(reply)g (message)j(to)d(the)g fc(msg_remote_port)150 811 y ff(\014eld)d(of)g(the)h (previously)e(received)i(message.)17 b fc(msg_send)9 b ff(is)g(now)g(called)h (to)f(send)g(the)g(reply)g(message)i(to)e(the)150 861 y(port)g(indicated)h (by)g(the)g fc(msg_remote_port)f ff(\014eld.)212 916 y(The)16 b(earlier)e(cal\ l)h(of)f fc(msg_rpc)g ff(by)g(the)h(child)e(will)h(now)g(receive)h(the)g(pare\ nt')n(s)f(reply)g(message.)30 b(Our)150 966 y(example)11 b(is)e(over)h(except) g(for)f(cleaning)h(up.)15 b fc(env_del_port)9 b ff(is)h(called)g(to)f(let)g (the)h(Environment)e(Manager)150 1016 y(know)13 b(the)g(name/port)g(associati\ on)g(is)g(no)g(longer)g(needed.)25 b fc(port_deallocate)12 b ff(is)i(then)f (called)g(by)g(the)150 1065 y(parent)d(which)g(owns)g(the)g(communication)g (port)f(to)h(destroy)f(it.)212 1121 y(Detailed)14 b(discussion)e(of)h(the)h (various)e(calls)i(used)g(by)f(the)g(example)i(are)f(given)f(next)g(and)g(the) h(complete)150 1170 y(text)c(of)g(the)g(program)g(is)g(given)f(in)h(Section)g (2.12.)150 1319 y fb(2.1)50 b(Mach)12 b(Err)o(or)h(Printing)150 1407 y fc(mac\ h_error)c ff(is)i(an)f(error)g(routine)f(that)h(accepts)i(a)e(string)f(and)i (an)f(error)g(value.)16 b(The)11 b(string)e(is)h(then)g(printed)150 1457 y (along)g(with)f(an)h(error)g(string)f(associated)i(with)f(the)g(value.)240 1571 y fg(kern_retur)q(n_)q(_t)48 b(error;)240 1617 y(mach_error)q(\(")q(PAR) q(EN)q(T:)26 b(port_allo)q(ca)q(te)g(returned)g(value)e(of",)g(error\);)150 1841 y fb(2.2)50 b(Port)13 b(Allocation)150 1930 y fc(port_allocate)c ff(is)h (used)g(to)g(create)h(a)f(port.)15 b(The)c(\014rst)f(ar)o(gument)g(to)f fc (port_allocate)g ff(is)h(the)g(task)g(the)150 1979 y(port)f(is)h(to)g(belong) f(to,)h(in)g(this)f(case)j(the)e(process)h(itself)f(or)g fc(task_self\(\))p ff (.)240 2094 y fg(port_t)226 b(result;)240 2140 y(kern_retur)q(n_)q(t)70 b(err\ or;)240 2231 y(if)23 b(\(\(error)i(=)e(port_allo)q(ca)q(te\()q(ta)q(sk)q(_se) q(lf)q(\(\),)j(&result\))q(\))f(!=)f(KERN_SUCCE)q(SS)q(\))i({)307 2277 y(mach\ _erro)q(r\(")q(PA)q(RE)q(NT:)g(port_all)q(oca)q(te)g(returned)g(value)e(of)g (",)f(error\);)307 2322 y(exit\(1\);)240 2368 y(})g eop %%Page: 5 24 bop 1779 162 a ff(5)150 307 y fa(2)60 b(Message)14 b(Communication)g(Between) g(Pr)o(ocesses)150 400 y ff(The)c(\014rst)e(sample)i(program)e(shows)h(how)g (to)f(pass)h(messages)i(between)e(two)g(tasks.)15 b(This)9 b(is)g(a)g(good)f (illustration)150 450 y(of)k(the)g(following)f(fundamental)h(Mach)h(features:) 20 b(allocation,)12 b(deallocation,)g(and)h(use)g(of)f(ports;)g(use)h(of)f (the)150 499 y(Environment)g(Manager;)i(setting)d(up)i(message)h(structures;) f(and)g(communication)f(between)h(two)f(processes)150 549 y(via)h(messages)i (on)d(ports.)23 b(In)13 b(this)f(example)h(the)g(parent)g(task)g(will)e(fork) i(a)g(child)f(task,)i(which)f(will)e(send)i(the)150 599 y(parent)e(a)g(messag\ e)i(containing)c(data.)17 b(The)12 b(parent)e(will)g(then)g(notify)f(the)i (child)f(that)g(he)h(received)h(the)e(data)h(by)150 649 y(sending)f(a)g(reply) g(message.)212 699 y(At)f(this)g(point,)f(the)h(reader)h(should)f(be)g(aware) i(that)e(most)18 b(programmers)10 b(do)f(not)f(code)i(IPC)f(at)h(this)e(level) h(of)150 748 y(detail,)j(but)e(instead)h(use)h(the)g(Mach)g(Interface)g(Gener\ ator)g(\(MIG\))f(to)f(produce)i(the)f(message)i(handling)d(code.)150 798 y (The)k(use)g(of)f(MIG)g(is)g(explained)f(in)h(the)g fe(Pr)n(ogrammers')-5 b (s)14 b(Guide)f(to)g(the)g(Mach)g(User)h(Envir)n(onment)p ff(.)24 b(Users)150 848 y(who)9 b(are)h(new)f(the)g(the)19 b(probably)7 b(want)j(to)e(read)i(that) e(document)h(before)h(attempting)e(to)g(write)h(code)h(following)150 898 y (these)h(examples.)212 948 y(This)i(example)h(uses)f(a)h(Mach)f(version)f(of) h(the)f(UNIX)h(fork)f(utility)e(to)j(create)h(a)f(child)f(task.)24 b(The)13 b (UNIX)150 998 y(part)i(of)g(the)h(fork)e(creates)j(a)f(complete)g(copy)f(of)g (the)g(parent')n(s)g(address)h(space)h(and)f(prepares)g(the)f(child)g(to)150 1047 y(begin)e(executing)h(immediately)f(after)h(the)g(fork)f(call.)26 b(The) 15 b(Mach)f(part)g(of)f(the)h(fork)f(creates)i(two)f(ports)f(for)150 1097 y (the)f(child)f(task:)19 b(its)12 b(task)g(kernel)g(port,)g(de\014ned)g(by)g fc (task_self\(\))p ff(;)g(and)g(a)h(noti\014cation)d(port,)i(de\014ned)g(by)150 1147 y fc(task_notify\(\))p ff(.)25 b(The)14 b(task)f(port)g(is)g(the)h(port) e(that)h(represents)h(that)f(task)h(in)f(calls)g(to)g(the)h(kernel.)25 b(The) 150 1197 y(notify)11 b(port)g(is)h(the)g(port)g(on)g(which)g(the)g(task)g(may) h(receive)h(special)e(messages)j(from)d(the)g(kernel.)22 b(The)13 b(child)150 1247 y(task)f(also)f(inherits)g(an)h(exception)f(port,)g(a)h(bootstrap)f(port) f(and)i(some)h(ports)d(for)i(system)g(servers)g(such)g(as)g(the)150 1296 y (Environment)e(Manager)i(and)f(the)g(Netmsgserver)n(.)20 b(Access)12 b(to)f (user)h(de\014ned)f(ports)f(is)i(not)e(inherited)g(through)150 1346 y(forking\ .)18 b(The)12 b(thread)f(that)g(is)g(created)i(has)f(a)g(thread)f(kernel)g (port,)g(referenced)i(by)e fc(thread_self\(\))p ff(,)g(and)150 1396 y(a)h(thr\ ead)f(reply)g(port,)g(referenced)i(by)e fc(thread_reply\(\))f ff(created)j (for)d(it.)19 b(The)12 b(thread)f(kernel)h(port)e(is)h(the)150 1446 y(port)e (that)h(represents)h(the)f(thread)g(in)g(kernel)g(call.)16 b(The)11 b(thread) f(reply)g(port)f(is)h(a)h(port)e(on)h(which)g(the)g(thread)g(can)150 1496 y (receive)h(any)g(initialization)c(messages)12 b(from)e(its)g(parent.)212 1545 y(Message)k(passing)e(between)g(the)g(parent)g(and)h(child)e(cannot)h(take)h (place)g(until)d(a)j(port)e(is)h(known)f(by)h(both)150 1595 y(processes.)17 b (Before)10 b(forking,)f(a)i(string)e(is)h(constructed)f(to)h(be)g(used)h(as)g (the)f(name)h(of)f(the)g(communication)f(port)150 1645 y(and)i(a)h(port)e(is) h(allocated)g(using)f(the)h fc(port_allocate)g ff(call.)18 b(Then)12 b(the)f (Environment)f(Manager)i(function)150 1695 y fc(env_set_port)j ff(is)g(called) h(to)f(associate)i(the)e(name)i(with)d(the)i(port.)31 b(This)15 b(name)i(is)f (available)f(to)g(both)150 1745 y(processes)c(after)f(forking)e(since)i(it)f (is)g(a)i(static)e(variable.)16 b(After)9 b(the)h(fork)f(the)g(child)g(can)h (acquire)g(send)g(rights)f(to)150 1795 y(the)h(port)f(using)h fc(env_get_port) p ff(.)212 1844 y(Now)k(that)g(both)f(tasks)h(have)h(access)h(to)d(the)h(comm\ unication)g(port,)g(a)h(message)h(is)e(constructed)g(by)f(the)150 1894 y(chil\ d.)37 b(This)18 b(message)h(contains)e(a)i(\014xed)e(sized)h(message)i(header) e(and)g(a)g(variable)g(sized)g(data)g(portion.)150 1944 y(When)12 b(construct\ ing)f(the)h(message,)j(the)d(child)f(sets)i(the)f fc(msg_remote_port)f ff(\ \014eld)h(in)g(the)g(header)h(to)e(the)150 1994 y(communication)f(port)f(esta\ blished)h(earlier)n(.)16 b(This)11 b(\014eld)f(designates)h(the)f(port)f(to)h (which)g(the)h(message)h(is)e(to)g(be)150 2044 y(sent.)15 b(Another)9 b(heade\ r)h(\014eld)f(that)f(the)h(child)f(must)h(be)h(sure)f(to)g(set)g(properly)f (is)h fc(msg_local_port)p ff(.)14 b(This)9 b(is)150 2093 y(the)h(port)f(on)h (which)g(the)g(child)f(will)g(wait)h(for)g(a)h(reply)e(message.)18 b(In)10 b (this)f(example,)j(the)e(child)f(will)g(receive)i(the)150 2143 y(reply)f(mess\ age)j(on)d(his)g(thread)h(reply)f(port.)16 b(The)c(task)f(that)f(receives)i (the)e(message)j(constructed)d(by)g(the)h(child)150 2193 y(automatically)g (receives)i(send)e(rights)g(to)g(the)g fc(msg_local_port)p ff(.)19 b(Since)12 b(the)g(child)e(task)i(wishes)g(to)f(send)150 2243 y(a)h(message)g(and)g(then) e(immediately)h(receive)h(a)g(reply)e(message,)k(it)c(uses)i fc(msg_rpc)e ff (instead)h(of)g fc(msg_send)150 2293 y ff(and)g fc(msg_receive)p ff(.)18 b fc (msg_rpc)11 b ff(does)g(a)h(send)g(followed)d(by)i(a)h(receive)g(using)f(the) g(same)h(message)h(buf)o(fer)150 2342 y(for)d(both)f(calls.)g eop %%Page: 4 25 bop 150 162 a ff(4)1265 b fe(1)41 b(INTRODUCTION)150 307 y fd(1.2.5)h(Standa\ rd)10 b(Mach)h(Servers)150 385 y ff(There)i(are)f(a)h(couple)e(of)h(standard) f(servers)i(that)e(support)f(use)i(of)g(Mach)g(style)g(communications.)20 b (One)12 b(is)f(the)150 435 y(NetMsgServer)n(.)27 b(It)14 b(passes)h(Mach)g (IPC)e(messages)j(between)f(machines.)28 b(It)13 b(also)h(provides)f(network-\ wide)150 485 y(port)g(registration)f(and)h(lookup)g(functions.)24 b(The)15 b (names)g(of)e(these)h(calls)g(are)h fc(netname_check_in)d ff(and)150 534 y fc (netname_look_up)p ff(.)i(The)d(man)g(section)e fc(netname.3)h ff(documents)f (them.)16 b(The)11 b(other)e(general)i(purpose)150 584 y(Mach)16 b(server)h (is)e(the)h(Environment)e(Manager)n(.)33 b(It)15 b(can)i(register)e(or)g(look\ up)g(ports)f(or)i(named)g(strings)f(but)150 634 y(does)k(not)f(communicate)i (with)d(other)h(Environment)g(Managers.)42 b(The)20 b(functions)d(that)h(it)g (provides)g(are)150 684 y(documented)10 b(in)g(the)h(manual)g fe(The)f(Mach)g (Envir)n(onment)h(Manager)f ff(or)g(in)g(the)g(man)h(sections)g fc(env_conn.3) p ff(,)150 734 y fc(env_list.3)p ff(,)d(and)g fc(env_port.3)p ff(.)14 b(In)7 b (general,)i(one)f(decides)h(to)e(register)g(a)i(port)e(with)f(the)i(NetMsgSer\ ver)150 783 y(if)15 b(it)g(is)h(to)f(be)i(known)e(by)g(tasks)h(on)g(arbitrary) f(remote)h(machines)h(within)d(the)h(local)h(network.)32 b(Ports)15 b(are)150 833 y(registered)e(with)f(the)g(Environment)g(Manager)i(if)e(they)h(are)h(to) e(be)h(used)g(only)f(by)h(tasks)g(which)f(share)i(access)150 883 y(to)i(the)h (same)h(Environment)e(Manager)n(.)35 b(Often)17 b(such)g(tasks)g(are)g(part)g (of)f(the)h(same)h(creation)f(tree)g(or)f(are)150 933 y(performing)9 b(a)i (computation)e(on)h(a)h(single)e(node.)212 983 y(The)j(examples)h(in)d(this)h (document)g(demonstrate)h(the)f(creation)g(of)g(tasks)h(and)f(threads,)h(mess\ age)h(passing)150 1032 y(between)d(tasks,)h(shared)g(memory)f(communication)f (between)i(tasks)f(and)g(threads,)h(and)f(the)g(use)g(of)g(the)g(virtual)150 1082 y(memory)h(primitives.)g eop %%Page: 3 26 bop 150 162 a fe(1.2)41 b(Basic)11 b(Mach)f(Concepts)1173 b ff(3)150 307 y (from)15 b(multiple)e(clients)h(may)h(\014nd)g(one)g(request)f(blocked,)i(but) e(be)h(able)g(to)f(continue)g(working)f(on)i(another)150 357 y(request.)25 b (Creating)13 b(or)g(destroying)f(a)i(thread)f(is)g(also)h(a)g(much)f(less)h (expensive)g(operation)e(than)h(creating)g(or)150 407 y(destroying)c(a)h(task\ .)150 557 y fd(1.2.3)42 b(Communications)150 649 y ff(There)13 b(are)g(two)e (basic)h(ways)h(to)e(communicate)i(between)f(tasks)g(or)g(between)h(threads)f (within)e(a)i(task:)19 b(shared)150 698 y(memory)i(and)g(message)h(passing)e (\(IPC\).)g(The)h(most)g(obvious)e(and)i(probably)e(most)h(ef)o(\014cient)h (form)f(of)150 748 y(communication)8 b(between)i(two)e(threads)h(in)g(the)g (same)h(task)f(is)g(through)e(shared)j(memory)m(.)16 b(The)10 b(most)f(common) 150 798 y(form)j(of)g(communication)g(between)h(tasks)g(is)f(through)f(messag\ e)j(passing.)22 b(However)n(,)14 b(threads)f(in)e(the)i(same)150 848 y(task)h (may)h(send)g(messages)h(to)d(each)j(other)d(as)i(long)e(as)i(the)g(programme\ r)f(is)g(careful)h(about)e(which)h(threads)150 898 y(are)j(waiting)d(for)i (messages)i(on)d(which)h(ports.)32 b(Also,)17 b(it)f(is)f(possible)h(for)f (a)i(task)f(to)f(share)i(memory)f(with)150 947 y(tasks)d(that)g(have)h(a)g (common)g(ancestor)n(.)25 b(Since)13 b(these)h(tasks)f(will)g(probably)f(be)h (on)g(the)g(same)i(machine)f(this)150 997 y(sharing)d(can)i(be)f(ef)o(\014cie\ nt.)22 b(Unrelated)12 b(tasks)g(can)h(also)f(share)h(memory)m(,)g(but)f(that) f(style)h(of)f(memory)i(sharing)150 1047 y(is)j(made)h(potentially)d(more)j (complex)f(when)g(two)g(unrelated)g(tasks)g(are)h(not)e(located)h(on)g(the)g (same)i(node.)150 1097 y(Memory)10 b(sharing)g(between)g(unrelated)g(tasks)g (is)g(not)f(covered)i(in)e(this)g(tutorial.)14 b(When)c(two)g(threads/tasks)f (are)150 1147 y(using)h(the)h(same)h(memory)m(,)g(locking)e(is)h(often)f(need\ ed.)19 b(Unfortunately)m(,)9 b(hardware)j(mechanisms)g(for)e(locking)150 1197 y(memory)g(locations)f(vary)h(from)g(one)g(machine)g(to)g(another)n(.)15 b (The)10 b(Mach)h(C)e(threads)h(library)f(package)i(provides)150 1246 y(machin\ e-independent)i(locking)f(primitives.)24 b(T)m(asks)14 b(that)f(don')o(t)g (use)h(the)f(C)g(threads)h(library)e(must)h(provide)150 1296 y(their)c(own)h (locking)f(protocols.)150 1446 y fd(1.2.4)42 b(V)n(irtual)10 b(Memory)g(Primi\ tives)g(versus)h(Malloc)150 1538 y ff(The)17 b(Mach)h(kernel)e(provides)g(a)h (set)g(of)g(primitives)e(to)h(allow)g(a)i(programmer)f(to)f(manipulate)g(the) h(virtual)150 1588 y(address)e(space)g(of)f(a)h(task.)27 b(The)15 b(two)e(mos\ t)h(fundamental)g(ones)h(are)f fc(vm_allocate)g ff(to)f(get)h(new)h(virtual) 150 1638 y(memory)g(and)f fc(vm_deallocate)f ff(to)g(free)i(virtual)e(memory) m(.)28 b(The)15 b(programmer)f(also)h(has)f(available)g(the)150 1687 y(UNIX)c (functions)f fc(sbrk)p ff(,)h fc(malloc)g ff(and)h fc(calloc)p ff(.)212 1744 y (The)e(decision)f(to)g(use)h(one)g(allocation)e(method)h(rather)h(than)f(anot\ her)g(should)f(be)i(based)g(on)f(several)i(factors.)150 1794 y fc(sbrk)h ff (is)f(now)g(obsolete)h(and)g(only)e(retained)i(for)f(backward)h(compatibility) e(with)g(older)i(UNIX)f(programs.)18 b(It)150 1844 y(is)13 b(not)g(recommende\ d)h(that)f(new)g(programs)g(which)g(expect)h(to)f(use)g(Mach)h(features)g(sho\ uld)e(use)i fc(sbrk)p ff(.)24 b(In)150 1894 y(fact,)10 b fc(sbrk)f ff(calls)g fc(vm_allocate)g ff(to)f(increase)j(the)e(user)r(')n(s)f(address)i(space.)17 b fc(vm_allocate)8 b ff(always)i(adds)150 1944 y(new)m(,)k(zero-\014lled)f(virt\ ual)e(memory)j(in)e(paged-aligned,)h(multiple)f(of)g(page-sized)i(chunks)e (\(where)i(a)f(page)g(is)150 1994 y(currenly)h(4K)g(or)g(8K)g(bytes)g(\).)27 b fc(Malloc)14 b ff(allocates)h(approximately)e(the)h(size)h(it)e(is)h(asked)h (for)f(\(plus)f(a)i(few)150 2043 y(bytes\))9 b(out)g(of)g(a)h(pre-allocated)f (heap.)16 b fc(calloc)10 b ff(is)f(the)g(same)i(as)f fc(malloc)f ff(except)h (that)f(it)g(zeros)h(the)g(memory)150 2093 y(before)j(returning)e(it.)21 b fc (malloc)13 b ff(and)f fc(calloc)g ff(are)i(library)d(subroutine)g(calls)i(whi\ le)f fc(vm_allocate)f ff(is)i(a)150 2143 y(kernel)d(syscall)g(which)g(is)g (somewhat)h(more)g(expensive.)212 2200 y(The)h(the)g(most)f(obvious)f(basis)i (on)f(which)g(to)g(choose)h(an)g(allocation)e(function)g(is)h(the)g(size)i (of)e(the)g(desired)150 2250 y(space.)18 b(There)12 b(is)e(one)h(other)f(cons\ ideration,)g(however)n(,)i(which)e(is)g(the)h(desirability)d(of)j(page-aligne\ d)f(storage.)150 2300 y(If)i(the)h(memory)g(that)f(is)h(allocated)f(is)h(to)f (be)h(passed)g(out-of-line)e(in)h(a)h(message,)j(it)c(is)g(more)h(ef)o(\014ci\ ent)g(if)f(it)g(is)150 2350 y(page-aligned.)27 b(Note)14 b(that)g(it)f(is)h (essential)h(that)e(the)i(correct)f(deallocation)f(function)g(be)i(used.)28 b (If)14 b(memory)150 2399 y(has)d(been)g fc(vm_allocate)p ff(d)e(it)h(must)g (be)h fc(vm_deallocate)p ff(d,)f(if)f(it)h(was)h fc(malloc)p ff(ed)f(it)g(mus\ t)g(be)h fc(free)p ff(d.)150 2449 y(Memory)f(that)g(is)g(received)h(out-of-li\ ne)d(from)i(a)h(message)h(has)f(been)f fc(vm_allocate)p ff(d)f(by)h(the)g(ker\ nel.)g eop %%Page: 2 27 bop 150 162 a ff(2)1265 b fe(1)41 b(INTRODUCTION)150 307 y ff(Aug.)15 b(1986) 9 b(or)g(in)f(the)i fe(Mach)f(Kernel)g(Interface)g(Manual)p ff(.)14 b(The)c (latter)f(document)g(gives)g(the)g(complete)h(calling)150 357 y(semantics)h (for)f(all)g(the)g(Mach)h(system)f(calls.)150 475 y fd(1.2.1)42 b(Ports,)11 b (Port)g(Names)f(and)g(Port)h(Sets)150 555 y ff(Recently)f(a)h(new)f(abstracti\ on)f(has)i(been)g(added)f(to)g(Mach:)15 b(the)10 b fe(port)g(set)p ff(.)16 b (A)10 b fc(port)24 b(set)10 b ff(is)g(a)h(group)e(of)h(ports)150 605 y(which) f(can)h(be)f(received)h(on)f(in)f(parallel.)15 b(That)10 b(is,)f(a)h(thread)f (can)h(do)f(a)g fc(msg)r 13 2 v 13 w(receive)g ff(call)g(on)g(a)h(port)e(set) h(and)150 655 y(will)g(receive)i(the)f(\014rst)g(message)i(that)e(appears)h (on)f(any)h(of)f(the)g(ports)f(in)h(the)g(set.)16 b(In)10 b(earlier)h(version\ s)e(of)h(Mach)150 704 y(there)j(was)h(only)d(one)i(port)f(set,)i(which)f(was) g(the)g(set)g(of)g(all)f fc(enabled)h ff(ports.)23 b(Port)12 b(sets)h(are)h (only)e(used)h(for)150 754 y(receiving)e(messages,)k(you)c(can)i(not)d(send)i (to)g(a)g(port)f(set.)20 b(When)12 b(ports)f(are)i(created)g(they)e(are)i(not) e(a)h(member)150 804 y(of)d(any)h(port)f(set)h(but)f(may)h(be)g(added)g(to)f (a)i(port)d(set)i(by)g(the)f(call)h fc(port)r 13 2 v 13 w(set)r 13 2 v 12 w (add)p ff(.)16 b(A)10 b(port)e(may)j(be)f(a)g(member)150 854 y(of)i(only)f (one)i(port)e(set)i(at)f(a)h(time,)g(and)g(the)f(task)g(must)g(have)h(receive) g(rights)e(to)h(a)h(port)e(before)i(it)e(can)i(enter)g(it)150 904 y(into)f (a)h(port)f(set.)24 b(A)14 b(port)e(set)h(cannot)g(be)g(sent)g(in)f(a)i(messa\ ge.)26 b(If)12 b(a)i(task)f(wishes)g(to)f(transfer)h(an)g(entire)g(port)150 953 y(set)e(to)f(another)g(task,)h(each)g(of)g(the)f(ports)g(must)g(be)h(sent) f(as)h(a)g(separate)h(port)e(with)f(receive)i(rights)f(and)g(then)g(the)150 1003 y(receipient)g(must)g(rede\014ne)h(a)g(new)g(port)e(set)h(with)g(all)f (the)i(ports)e(in)h(it.)212 1054 y(A)i fc(port)25 b(name)11 b ff(is)g(a)h(new) f(term)h(used)f(to)g(re\014ne)h(the)f(way)g(in)g(which)g(ports)f(are)i(referr\ ed)g(to.)18 b(The)12 b(use)f(of)150 1104 y(the)f(term)g(port)f(or)h(the)g(typ\ e)g fc(port)r 13 2 v 12 w(t)g ff(implies)g(that)f(the)h(task)g(has)h(at)f(lea\ st)g(send)g(rights)f(for)h(the)f(port.)15 b(The)c(term)150 1154 y fc(port)25 b (name)10 b ff(and)h(type)f fc(port)r 13 2 v 12 w(name)r 13 2 v 13 w(t)h ff (implies)f(that)f(the)i(task)f(may)i(not)d(have)i(any)g(rights)e(to)h(the)h (port)e(and)150 1204 y(could)h(be)h(holding)e(its)h(name)h(for)f(some)i(other) e(task.)17 b(The)11 b(only)f(place)h(where)g(the)g(distinction)d(is)i(importa\ nt)g(in)150 1254 y(code)i(is)f(the)h(type)f(used)g(during)f(message)k(passing\ .)19 b(If)11 b(the)g(type)h fc(port)r 13 2 v 12 w(t)g ff(is)f(used,)h(the)g (kernel)f(will)f(map)i(the)150 1303 y(port)e(rights)f(to)h(the)g(receipient)h (of)f(the)h(message.)18 b(If)11 b(the)f(type)h fc(port)r 13 2 v 12 w(name)r 13 2 v 13 w(t)f ff(is)h(used)g(no)f(rights)f(mapping)h(is)150 1353 y(done)i(and) g(the)g(agrument)g(gets)g(passed)h(as)g(a)g(simple)e(integer)n(.)21 b(All)11 b (three)h(types)g fc(port)r 13 2 v 13 w(t,)27 b(port)r 13 2 v 13 w(name)r 13 2 v 12 w(t)150 1403 y ff(and)10 b fc(port)r 13 2 v 13 w(set)r 13 2 v 12 w(name) r 13 2 v 13 w(t)g ff(are)h(de\014ned)f(to)f(be)i(the)e(same)j(basic)e(C)g(typ\ e)f(and)h(may)h(be)f(used)g(interchangeabley)150 1453 y(in)g(C)h(code.)18 b (This)11 b(allows)g(for)f(backwards)i(compatibility)c(with)i(code)h(that)g (was)g(written)f(when)h(only)f fc(port)r 13 2 v 12 w(t)150 1503 y ff(existed) g(and)g(allows)g(primitives)f(to)g(work)h(for)g(either)g(ports,)g(port)f(sets) i(or)e(port)h(names.)150 1620 y fd(1.2.2)42 b(T)l(asks)10 b(versus)h(Thr)o (eads)150 1701 y ff(Mach)k(tasks)f(have)g(independent)f(address)i(spaces)h (and)e(typically)e(communicate)j(by)e(sending)h(messages)i(to)150 1750 y(each) c(other)n(.)19 b(Separate)12 b(tasks)f(can)h(be)g(used)g(to)e(perform)h(parts) g(of)g(a)h(computation)e(on)h(dif)o(ferent)g(workstations)150 1800 y(connecte\ d)16 b(by)g(a)h(network.)32 b(The)16 b(port)f(and)i(message)g(passing)f(facil\ ities)f(of)h(Mach)g(have)h(been)f(designed)150 1850 y(to)d(allow)g(transparen\ t)h(communication)f(between)h(tasks)g(whether)g(they)f(are)i(on)e(the)h(same) h(node)f(or)f(on)h(two)150 1900 y(separate)g(nodes)e(in)g(a)h(network.)21 b (All)12 b(message)i(operations)e(are)h(location)e(independent)h(and,)h(in)f (theory)m(,)h(it)e(is)150 1950 y(impossible)f(to)g(tell)h(whether)f(a)i(messa\ ge)h(has)e(been)h(sent)e(to)h(or)g(received)g(from)g(a)h(task)f(on)f(the)h (same)h(machine)150 1999 y(or)i(a)h(remote)g(one.)29 b(In)14 b(practice,)j (however)n(,)f(the)e(timing)g(and)g(failure)g(modes)h(are)h(dif)o(ferent)d (between)i(local)150 2049 y(messages)f(and)f(remote)g(messages.)24 b(System) 13 b(services)g(such)g(as)g(remote)g(\014le)g(access)h(and)f(network)e(messag\ e)150 2099 y(communication)f(are)h(themselves)g(implemented)f(as)h(tasks)f (communicating)g(via)g(messages.)212 2150 y(Threads,)h(on)d(the)h(other)f(han\ d,)i(share)g(their)e(memory)h(and)g(access)i(rights)d(with)g(the)h(other)f (threads)h(in)f(a)i(task.)150 2200 y(They)16 b(often)f(communicate)h(within)d (a)j(task)f(through)f(shared)i(memory)g(locations.)30 b(Threads)16 b(are)g (intended)150 2250 y(to)e(allow)f(separate)j(execution)e(units)f(to)g(work)h (in)g(parallel)g(on)g(the)g(same)i(problem.)27 b(This)14 b(gives)g(a)h(user)g (an)150 2300 y(easy)d(way)g(to)f(get)g(parallel)g(computation)f(on)h(a)h(mult\ i-processor)n(.)18 b(On)11 b(a)h(single)f(processor)n(,)h(multiple)e(threads) 150 2350 y(may)h(simplify)e(the)h(structure)g(of)g(a)h(program)f(that)g(is)g (logically)f(doing)g(several)i(dif)o(ferent)f(functions.)15 b(Multiple)150 2399 y(threads)d(are)i(also)e(useful)g(if)g(some)h(of)f(a)h(program')n(s)f (actions)h(may)g(cause)g(a)g(line)f(of)g(exection)h(to)e(be)i(blocked,)150 2449 y(while)f(other)h(lines)g(of)f(execution)h(could)g(usefully)f(continue.) 23 b(For)13 b(example,)i(server)e(that)g(handles)g(requests)g eop eos end TeXDict begin 300 @start bos /fa [ 0 0 0 0 0 0 0 0 0 0 0 0 33 33 0 0 17 0 20 20 20 20 20 20 20 33 43 43 30 60 60 47 15 20 30 30 30 60 50 20 20 20 30 34 15 20 15 17 30 30 30 30 30 30 30 30 30 30 20 20 20 34 30 30 56 43 40 43 43 40 37 47 47 23 30 47 40 56 43 47 37 47 43 33 40 43 43 60 43 43 40 20 30 20 20 20 20 30 33 27 33 27 20 30 33 17 20 33 17 50 33 30 33 33 27 23 20 33 30 43 30 30 27 30 60 20 20 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 20 30 30 10 30 30 30 30 17 30 30 20 20 33 33 0 30 30 30 15 0 32 21 20 30 30 30 60 60 0 30 0 20 20 20 20 20 20 20 20 0 20 20 0 20 20 20 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 60 0 18 0 0 0 0 40 47 60 20 0 0 0 0 0 43 0 0 0 17 0 0 17 30 43 33 0 0 0 0 ] /Times-Bold 1000 655360 943718 pf /fb [ 0 0 0 0 0 0 0 0 0 0 0 0 28 28 0 0 14 0 17 17 17 17 17 17 17 28 36 36 25 50 50 39 12 17 25 25 25 50 41 17 17 17 25 28 12 17 12 14 25 25 25 25 25 25 25 25 25 25 17 17 17 28 25 25 46 36 33 36 36 33 30 39 39 19 25 39 33 47 36 39 30 39 36 28 33 36 36 50 36 36 33 17 25 17 17 17 17 25 28 22 28 22 17 25 28 14 17 28 14 41 28 25 28 28 22 19 17 28 25 36 25 25 22 25 50 17 17 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 25 25 8 25 25 25 25 14 25 25 17 17 28 28 0 25 25 25 12 0 27 17 17 25 25 25 50 50 0 25 0 17 17 17 17 17 17 17 17 0 17 17 0 17 17 17 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 50 0 15 0 0 0 0 33 39 50 16 0 0 0 0 0 36 0 0 0 14 0 0 14 25 36 28 0 0 0 0 ] /Times-Bold 1000 655360 786432 pf /fc [ 0 0 0 0 0 0 0 0 0 0 0 0 0 25 25 25 25 0 25 25 25 25 25 25 25 25 0 0 25 0 0 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 25 25 25 25 25 25 25 25 25 25 25 25 0 0 0 25 25 25 25 0 25 25 25 25 25 25 25 0 0 25 0 25 25 25 25 25 25 25 25 0 25 25 0 25 25 25 25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 0 0 0 0 25 25 0 25 0 0 0 0 0 0 0 0 0 25 0 0 25 25 0 25 0 0 0 0 ] /Courier 1000 655360 655360 pf /fd [ 0 0 0 0 0 0 0 0 0 0 0 0 23 23 0 0 12 0 14 14 14 14 14 14 14 23 30 30 21 42 42 32 10 14 21 21 21 42 35 14 14 14 21 24 10 14 10 12 21 21 21 21 21 21 21 21 21 21 14 14 14 24 21 21 39 30 28 30 30 28 25 32 32 16 21 32 28 39 30 32 25 32 30 23 28 30 30 42 30 30 28 14 21 14 14 14 14 21 23 18 23 18 14 21 23 12 14 23 12 35 23 21 23 23 18 16 14 23 21 30 21 21 18 21 42 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 21 21 7 21 21 21 21 12 21 21 14 14 23 23 0 21 21 21 10 0 22 15 14 21 21 21 42 42 0 21 0 14 14 14 14 14 14 14 14 0 14 14 0 14 14 14 42 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 42 0 12 0 0 0 0 28 32 42 14 0 0 0 0 0 30 0 0 0 12 0 0 12 21 30 23 0 0 0 0 ] /Times-Bold 1000 655360 655360 pf /fe [ 0 0 0 0 0 0 0 0 0 0 0 0 21 21 0 0 12 0 14 14 14 14 14 14 14 21 28 28 21 37 39 30 10 14 23 21 21 35 32 14 14 14 21 28 10 14 10 12 21 21 21 21 21 21 21 21 21 21 14 14 16 28 21 21 38 25 25 28 30 25 25 30 30 14 18 28 23 35 28 30 25 30 25 21 23 30 25 35 25 23 23 16 23 16 14 14 14 21 21 18 21 18 12 21 21 12 12 18 12 30 21 21 21 21 16 16 12 21 18 28 18 18 16 21 37 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 21 21 7 21 21 21 21 9 23 21 14 14 21 21 0 21 21 21 10 0 22 15 14 23 23 21 37 42 0 21 0 14 14 14 14 14 14 14 14 0 14 14 0 14 14 14 37 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 37 0 11 0 0 0 0 23 30 39 13 0 0 0 0 0 28 0 0 0 12 0 0 12 21 28 21 0 0 0 0 ] /Times-Italic 1000 655360 655360 pf /ff df[<07E01FF83FFC7FFE7FFEFFFFFFFFFFFFFF FFFFFFFFFF7FFE7FFE3FFC1FF807E0>16 16 -2 -2 21]15 dc dfe /fg df[<60F0F060>4 4 -4 0 12]58 dc dfe /fh [ 0 0 0 0 0 0 0 0 0 0 0 0 23 23 0 0 12 0 14 14 14 14 14 14 14 21 28 30 21 37 37 30 10 14 18 21 21 35 32 14 14 14 21 23 10 14 10 12 21 21 21 21 21 21 21 21 21 21 12 12 14 23 18 18 38 30 28 28 30 25 23 30 30 14 16 30 25 37 30 30 23 30 28 23 25 30 30 39 30 30 25 14 18 14 14 14 14 18 21 18 21 18 14 21 21 12 12 21 12 32 21 21 21 21 14 16 12 21 21 30 21 21 18 21 42 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 21 21 7 21 21 21 21 7 18 21 14 14 23 23 0 21 21 21 10 0 19 15 14 18 18 21 42 42 0 18 0 14 14 14 14 14 14 14 14 0 14 14 0 14 14 14 42 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 37 0 11 0 0 0 0 25 30 37 13 0 0 0 0 0 28 0 0 0 12 0 0 12 21 30 21 0 0 0 0 ] /Times-Roman 1000 655360 655360 pf /fi [ 0 0 0 0 0 0 0 0 0 0 0 0 21 21 0 0 10 0 12 12 12 12 12 12 12 21 27 27 19 37 37 29 9 12 19 19 19 37 31 12 12 12 19 21 9 12 9 10 19 19 19 19 19 19 19 19 19 19 12 12 12 21 19 19 35 27 25 27 27 25 23 29 29 15 19 29 25 35 27 29 23 29 27 21 25 27 27 37 27 27 25 12 19 12 12 12 12 19 21 17 21 17 12 19 21 10 12 21 10 31 21 19 21 21 17 15 12 21 19 27 19 19 17 19 37 12 12 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 19 19 6 19 19 19 19 10 19 19 12 12 21 21 0 19 19 19 9 0 20 13 12 19 19 19 37 37 0 19 0 12 12 12 12 12 12 12 12 0 12 12 0 12 12 12 37 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 37 0 11 0 0 0 0 25 29 37 12 0 0 0 0 0 27 0 0 0 10 0 0 10 19 27 21 0 0 0 0 ] /Times-Bold 1000 655360 589824 pf /fj [ 0 0 0 0 0 0 0 0 0 0 0 0 19 19 0 0 10 0 12 12 12 12 12 12 12 19 25 25 19 33 35 27 9 12 21 19 19 31 29 12 12 12 19 25 9 12 9 10 19 19 19 19 19 19 19 19 19 19 12 12 15 25 19 19 34 23 23 25 27 23 23 27 27 12 17 25 21 31 25 27 23 27 23 19 21 27 23 31 23 21 21 15 21 15 12 12 12 19 19 17 19 17 10 19 19 10 10 17 10 27 19 19 19 19 15 15 10 19 17 25 17 17 15 19 33 12 12 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 19 19 6 19 19 19 19 8 21 19 12 12 19 19 0 19 19 19 9 0 20 13 12 21 21 19 33 37 0 19 0 12 12 12 12 12 12 12 12 0 12 12 0 12 12 12 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 33 0 10 0 0 0 0 21 27 35 12 0 0 0 0 0 25 0 0 0 10 0 0 10 19 25 19 0 0 0 0 ] /Times-Italic 1000 655360 589824 pf /fk [ 0 0 0 0 0 0 0 0 0 0 0 0 21 21 0 0 10 0 12 12 12 12 12 12 12 19 25 27 19 33 33 27 9 12 17 19 19 31 29 12 12 12 19 21 9 12 9 10 19 19 19 19 19 19 19 19 19 19 10 10 12 21 17 17 34 27 25 25 27 23 21 27 27 12 15 27 23 33 27 27 21 27 25 21 23 27 27 35 27 27 23 12 17 12 12 12 12 17 19 17 19 17 12 19 19 10 10 19 10 29 19 19 19 19 12 15 10 19 19 27 19 19 17 19 37 12 12 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 19 19 6 19 19 19 19 7 17 19 12 12 21 21 0 19 19 19 9 0 17 13 12 17 17 19 37 37 0 17 0 12 12 12 12 12 12 12 12 0 12 12 0 12 12 12 37 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 33 0 10 0 0 0 0 23 27 33 12 0 0 0 0 0 25 0 0 0 10 0 0 10 19 27 19 0 0 0 0 ] /Times-Roman 1000 655360 589824 pf /fl [ 0 0 0 0 0 0 0 0 0 0 0 0 18 18 0 0 9 0 11 11 11 11 11 11 11 17 22 24 17 30 30 24 8 11 15 17 17 28 26 11 11 11 17 19 8 11 8 9 17 17 17 17 17 17 17 17 17 17 9 9 11 19 15 15 31 24 22 22 24 20 18 24 24 11 13 24 20 30 24 24 18 24 22 18 20 24 24 31 24 24 20 11 15 11 11 11 11 15 17 15 17 15 11 17 17 9 9 17 9 26 17 17 17 17 11 13 9 17 17 24 17 17 15 17 33 11 11 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 17 17 6 17 17 17 17 6 15 17 11 11 18 18 0 17 17 17 8 0 15 12 11 15 15 17 33 33 0 15 0 11 11 11 11 11 11 11 11 0 11 11 0 11 11 11 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30 0 9 0 0 0 0 20 24 30 10 0 0 0 0 0 22 0 0 0 9 0 0 9 17 24 17 0 0 0 0 ] /Times-Roman 1000 655360 524288 pf end TeXDict begin @letter %%Page: 1 28 bop 1779 162 a fh(1)150 307 y fa(1)60 b(Intr)o(oduction)150 408 y fb(1.1)50 b (T)-5 b(utorial)12 b(Documents)150 487 y fh(This)k(document)g(is)g(one)h(of)f (two)f(tutorials)g(designed)h(to)g(teach)h(basic)f(Mach)h(programming)f(skill\ s.)32 b(This)150 536 y(manual)12 b(explains)e(the)h(use)h(of)f(the)g(Mach)h (kernel)f(calls.)19 b(It)11 b(begins)g(with)f(an)i(introduction)c(to)j(the)g (basic)g(Mach)150 586 y(abstractions)i(of)h(ports,)h(messages,)i(virtual)c (memory)m(,)j(tasks)e(and)g(threads.)27 b(It)14 b(then)f(contains)h(a)g(numbe\ r)g(of)150 636 y(simple)c(programs)g(which)g(send)h(and)f(receive)h(Mach)g (messages,)i(and)d(use)h(virtual)d(memory)m(.)212 686 y(There)23 b(is)f(a)g (companion)f(document)h(to)f(this)g(one,)k fe(A)e(Pr)n(ogrammer)r(')-5 b(s)22 b(Guide)f(to)g(the)h(Mach)f(User)150 736 y(Envir)n(onment)h fh(that)g(explain\ s)f(the)h(use)h(of)f(higher)f(level)h(methods)g(for)g(implementing)f(multi-th\ readed)150 786 y(programs)c(and)h(interprocess)f(communication.)38 b(Before) 17 b(writing)f(programs)h(that)g(use)h(the)g(system)g(calls)150 836 y(directl\ y)m(,)12 b(the)g(user)g(should)f(be)h(aware)h(that)f(the)f(methods)h(outlined) e(in)i(the)g(other)f(document)h(may)g(be)h(used)f(to)150 885 y(solve)e(his)g (problem)g(more)g(simply)m(.)212 935 y(The)j(\014nal)f(section)g(of)g fe(A)h (Pr)n(ogrammer)r(')-5 b(s)12 b(Guide)g(to)f(the)h(Mach)g(User)h(Envir)n(onmen\ t)f fh(describes)h(where)g(to)150 985 y(\014nd)d(the)g(mach)h(environment)f (on-line)f(at)h(CMU)g(and)g(how)g(to)g(use)g(it.)150 1105 y fb(1.2)50 b(Basic) 13 b(Mach)f(Concepts)150 1183 y fh(In)i(many)g(ways)g(the)g(Mach)h(operating) e(system)h(can)h(be)f(viewed)g(as)h(an)f(extension)f(of)h(the)f(UNIX)h(operat\ ing)150 1233 y(system.)i(Existing)8 b(4.3bsd)i(programs)f(which)g(do)h(not)e (use)j(knowledge)e(about)g(internal)f(UNIX)i(data)g(structures)150 1283 y(wil\ l)e(continue)h(to)g(function)f(in)i(Mach.)16 b(However)n(,)11 b(Mach)f(provid\ es)f(a)h(number)g(of)f(new)h(features)g(not)f(available)150 1332 y(in)h(tradi\ tional)f(UNIX)h(systems.)18 b(The)11 b(primary)f(motivation)f(for)h(the)h(dif) o(ferences)g(between)g(Mach)h(and)e(UNIX)150 1382 y(was)17 b(a)g(desire)f(to) g(better)g(support)f(multiprocessors)g(and)h(to)g(provide)f(a)i(solid)e(found\ ation)g(for)g(distributed)150 1432 y(computing.)212 1482 y(In)9 b(order)g(to) g(use)h(Mach')n(s)f(new)h(features,)g(the)f(programmer)h(needs)g(to)e(be)i (familiar)f(with)f(four)g(fundamental)150 1532 y(Mach)j(abstractions:)258 1616 y ff(\017)20 b fh(A)11 b fe(task)g fh(is)g(an)g(execution)f(environment,)g (including)f(a)i(paged)g(virtual)e(address)j(space)g(and)f(protected)299 1665 y(access)i(to)d(system)h(resources)h(such)e(as)i(processors)f(and)f(ports.)16 b(In)11 b(general)f(for)h(a)g(task)f(to)g(be)h(useful,)299 1715 y(it)d(must)h (have)g(at)g(least)g(one)g(thread)f(executing)h(within)e(it.)14 b(Thus)9 b (when)g(we)g(speak)g(of)g(communicating)299 1765 y(with)j(a)g(task,)h(it)f (means)h(to)f(communicate)h(with)e(a)h(thread)g(running)f(in)g(that)h(task.) 22 b(A)12 b(task)g(with)f(one)299 1815 y(thread)g(is)f(the)g(Mach)h(equivalen\ t)e(of)h(a)h(traditional)d(process.)258 1899 y ff(\017)20 b fh(A)12 b fe(thr) n(ead)f fh(is)g(the)g(basic)g(unit)f(of)h(execution.)18 b(It)11 b(consists)g (of)f(a)i(processor)g(state,)g(an)f(execution)g(stack)299 1949 y(and)g(a)f (limited)f(amount)h(of)g(per)g(thread)g(static)g(storage.)16 b(It)10 b(shares) h(all)f(other)f(memory)i(and)f(resources)299 1998 y(with)e(all)h(the)g(other) f(threads)h(executing)g(in)f(the)h(same)h(task.)16 b(A)9 b(thread)g(can)g(onl\ y)f(execute)i(in)f(one)g(task.)258 2082 y ff(\017)20 b fh(A)12 b fe(port)e fh (is)i(a)f(communication)g(channel)h(-)f(a)h(logical)e(queue)i(of)f(messages)i (protected)e(by)g(the)g(kernel.)299 2132 y(Only)h(one)g(task)g(can)g(receive) h(messages)h(from)e(a)g(port,)g(but)f(all)h(tasks)g(that)f(have)i(access)h (to)d(the)h(port)299 2182 y(can)f(send)g(messages.)258 2266 y ff(\017)20 b fh (A)11 b fe(message)g fh(is)f(a)h(typed)e(collection)g(of)h(data)h(objects)f (used)g(in)g(communication)g(between)g(threads.)212 2350 y(This)16 b(tutorial) f(presents)h(and)h(explains)e(several)i(simple)g(programs)f(which)g(make)h (use)g(of)f(these)g(Mach)150 2399 y(abstractions)8 b(to)h(solve)g(simple)f (programming)h(problems.)15 b(A)9 b(more)g(detailed)g(explanation)e(of)i(the) g(basic)g(Mach)150 2449 y(abstractions)i(can)h(be)g(found)f(in)g(the)g(Unix)g (Review)g(article)h fe(Thr)n(eads)g(of)f(a)g(New)h(System)p fh(,)g(Richard)f (F)m(.)h(Rashid,)g eop %%Page: 0 29 bop 338 307 a fa(A)15 b(Pr)o(ogrammer)q(')m(s)d(Guide)j(to)f(the)h(Mach)g (System)g(Calls)832 507 y fh(Linda)10 b(R.)h(W)m(almer)812 557 y(Mary)f(R.)h (Thompson)697 757 y(Department)f(of)g(Computer)f(Science)740 806 y(Carnegie-M\ ellon)g(University)798 856 y(Pittsbur)o(gh,)g(P)l(A)h(15213)703 1056 y fd(V)l (ersion)h(of:)k(December)d(28,)e(1989)905 1459 y fi(Abstract)355 1527 y fk (This)d(document)f(is)i(one)e(of)i(two)g(tutorials)g(designed)d(to)j(teach)e (basic)h(Mach)f(programming)h(skills.)299 1573 y(This)k(manual)g(explains)e (the)i(use)f(of)i(the)f(Mach)f(kernel)h(calls.)20 b(The)10 b(companion)g(docu\ ment)f(to)j(this)299 1619 y(one,)j fj(A)g(Pr)o(ogrammer')-5 b(s)12 b(Guide)i (to)g(the)g(Mach)g(User)f(Envir)o(onment)f fk(explains)g(the)i(use)g(of)g(hig\ her)299 1664 y(level)8 b(methods)f(for)h(implementing)g(multi-threaded)f(prog\ rams)g(and)g(interprocess)g(communication.)299 1710 y(Before)12 b(writing)h (programs)e(that)h(use)f(the)g(system)g(calls)g(directly)n(,)i(the)e(user)h (should)e(be)h(aware)h(that)299 1756 y(the)d(methods)e(outlined)h(in)g(the)h (other)f(document)f(may)h(be)f(used)g(to)i(solve)e(his)i(problem)f(more)g(sim\ ply)n(.)355 1801 y(Comments,)h(suggestions)e(and)h(additions)g(to)i(this)f (document)f(are)h(welcome.)150 2150 y fl(The)j(material)f(developed)f(under)g (this)i(subcontract)e(was)i(or)f(is)i(sponsored)c(by)i(the)h(Defense)f(Advanc\ ed)e(Research)i(Projects)h(Agency)150 2200 y(\(DoD\),)c(ARP)m(A)h(order)f(486\ 4,)f(monitored)g(by)h(the)g(Space)g(and)f(Naval)h(W)m(arfare)h(Systems)f(Comm\ and)f(under)g(Contract)h(Number)f(N00039-)150 2249 y(87-C-0251.)212 2299 y (The)14 b(views)g(and)g(conclusions)e(contained)h(in)h(this)h(document)d(are) i(those)g(of)g(the)g(authors)g(and)f(should)g(not)h(be)g(interpreted)f(as)150 2349 y(representing)5 b(of)o(\014cial)j(policies,)f(either)g(expressed)e(or)i (implied,)g(of)g(the)g(Defense)f(Advanced)f(Research)h(Projects)h(Agency)e (or)i(Department)150 2399 y(of)13 b(the)g(Navy)n(,)h(Space)f(and)f(Naval)h (W)m(arfare)h(Systems)f(Command,)g(or)h(Carnegie-Mellon)d(University)n(,)j (unless)f(designated)e(by)i(other)150 2449 y(documentation.)g eop %%Page: 1 30 bop 1788 162 a fh(i)150 307 y fa(Contents)150 400 y fd(1)41 b(Intr)o(oductio\ n)1342 b(1)212 450 y fh(1.1)44 b(T)o(utorial)8 b(Documents)38 b fg(:)20 b(:)h (:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f (:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)57 b fh(1)212 499 y(1.2)44 b (Basic)10 b(Mach)h(Concepts)39 b fg(:)21 b(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f (:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g (:)h(:)f(:)g(:)57 b fh(1)308 549 y(1.2.1)50 b(Ports,)10 b(Port)f(Names)j(and) e(Port)g(Sets)29 b fg(:)20 b(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h (:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)57 b fh(2)308 599 y(1.2.2)50 b(T)m(ask\ s)11 b(versus)f(Threads)i fg(:)20 b(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g (:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)57 b fh (2)308 649 y(1.2.3)50 b(Communications)16 b fg(:)k(:)g(:)g(:)h(:)f(:)g(:)h (:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f (:)g(:)h(:)f(:)g(:)57 b fh(3)308 699 y(1.2.4)50 b(V)n(irtual)8 b(Memory)i(Pri\ mitives)f(versus)i(Malloc)26 b fg(:)21 b(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g (:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)57 b fh(3)308 748 y(1.2.5)50 b(Standard)10 b (Mach)g(Servers)h fg(:)21 b(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g (:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)57 b fh(4)150 840 y fd(2)41 b(Message)11 b(Communication)e(Between)i(Pr)o(ocesses)785 b(5)212 890 y fh(2.1)44 b(Mach)11 b(Error)f(Printing)30 b fg(:)20 b(:)h(:)f(:)g(:)g(:)h (:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g (:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)57 b fh(6)212 939 y(2.2)44 b(Port)9 b(Allocati\ on)16 b fg(:)k(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h (:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g (:)57 b fh(6)212 989 y(2.3)44 b(Port)9 b(Deallocation)j fg(:)21 b(:)f(:)g(:)h (:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f (:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)57 b fh(7)212 1039 y(2.4)44 b (Environment)9 b(Manager)i(Server/Checking)e(in)h(a)h(Port)37 b fg(:)21 b(:)f (:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)57 b fh(7)212 1089 y(2.5)44 b(Environment)9 b(Manager)i(Server/Looking)e(up)h(a)g(Port)15 b fg(:)20 b(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g (:)57 b fh(7)212 1139 y(2.6)44 b(Setting)9 b(up)h(a)g(Simple)g(Message)18 b fg (:)i(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h (:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)57 b fh(8)212 1188 y(2.7)44 b(Sending) 9 b(Messages)31 b fg(:)20 b(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g (:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f (:)g(:)57 b fh(9)212 1238 y(2.8)44 b(Receiving)9 b(Messages)31 b fg(:)20 b (:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h (:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)57 b fh(9)212 1288 y(2.9) 44 b(Setting)9 b(up)h(a)g(Reply)g(Message)36 b fg(:)20 b(:)h(:)f(:)g(:)h(:)f (:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g (:)h(:)f(:)g(:)36 b fh(10)212 1338 y(2.10)23 b(RPC,)10 b(Send/Receive)42 b fg (:)20 b(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g (:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)36 b fh(10)212 1388 y(2.11)23 b(A)10 b(Non-Simple)f(Message)37 b fg(:)20 b(:)g(:)g(:)h(:)f(:)g (:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h (:)f(:)g(:)h(:)f(:)g(:)36 b fh(11)212 1438 y(2.12)23 b(Programming)9 b(Exampl\ e)i(I,)g(simp)r 13 2 v 13 w(ipc.c)21 b fg(:)g(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f (:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)36 b fh(13)150 1529 y fd(3)41 b(Use)11 b(of)f(V)n(irtual)g(Memory)1136 b(19)212 1579 y fh (3.1)44 b(Allocation,)9 b(Deallocation,)h(and)g(Reading)22 b fg(:)e(:)g(:)g (:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f (:)g(:)36 b fh(19)308 1628 y(3.1.1)50 b(V)n(irtual)8 b(Memory)i(Allocation)39 b fg(:)21 b(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g (:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)36 b fh(19)308 1678 y(3.1.2)50 b(V)n(irtual)8 b (Memory)i(Deallocation)36 b fg(:)20 b(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h (:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)36 b fh(19)308 1728 y(3.1.\ 3)50 b(V)n(irtual)8 b(Memory)i(Reading)j fg(:)20 b(:)g(:)h(:)f(:)g(:)g(:)h (:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g (:)36 b fh(20)308 1778 y(3.1.4)50 b(Programming)9 b(Example)i(II,)g(vm)r 13 2 v 13 w(read.c)g fg(:)21 b(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g (:)h(:)f(:)g(:)h(:)f(:)g(:)36 b fh(21)212 1828 y(3.2)44 b(V)n(irtual)8 b(Memo\ ry)j(Copying)f fg(:)20 b(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h (:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)36 b fh (23)212 1878 y(3.3)44 b(Inheritance)10 b(of)g(Shared)g(versus)h(Copied)e(Memo\ ry)32 b fg(:)20 b(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g (:)h(:)f(:)g(:)36 b fh(23)308 1927 y(3.3.1)50 b(V)n(irtual)8 b(Memory)m(,)j (Inheritance)21 b fg(:)g(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g (:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)36 b fh(24)308 1977 y(3.3.2)50 b (Programming)9 b(Example)i(III,)f(cowtest.c)43 b fg(:)20 b(:)g(:)h(:)f(:)g (:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)36 b fh(25)150 2069 y fd(4)41 b(Mach)11 b(Envir)o(onment)1199 b(28)g eop eos end %%EOF