Everything Y ou Alw a ys W anted � T o Kno w Ab out MIG � But W ere Afraid T o Ask Richa rd P � Draves rpd�cs�cmu�edu Scho ol of Computer Science Ca rnegie Mellon Universit y Pittsburgh� P A ����� �
Mig Stub generato r fo r Mach IPC� � P ack� unpack� demultiplex messages� � NOT transpa rent language�level RPCs� � Do esn�t hide IPC features� � Assumes client�server mo del� � �
Mig Histo ry early Matchmaker Mary Thompson Keith Wright Mike Jones - exceptions Mike Young - C late Matchmaker Mike Jones real types Lisp, Pascal, C MIG Mike Young Rich Draves - rewrote Draves & Golub - features �
Mig Programming Mo del Clients call stubs � mach�po rt �t server� po rt� kr � getbalan ce �s er ve r�p or t� �balanc e� � Server lo op p ro cesses requests � extern boolean� t bank�serv er �� � mach�po rt �t server� po rt� �define MAX�SIZ E ��� �void� mach�msg �s er ve r�b an k� se rv er � MAX�SIZE � server� po rt �� kern�re tu rn �t getbala nce �s er ve r� po rt � balance� mach�po rt �t server�p or t� int �balanc e� �� out �� � ��� � �
Mig Example �� file example �d ef s �� subsystem example ������ �include �mach�st d� ty pe s� de fs � �� manipula te a bank account �� routine getbala nc e� server � mach�po rt �t � out balance � int�� Client call� �include �example �h � mach�port �t server� int balance � kern�retu rn �t kr� kr � getbalan ce �s er ve r� �balanc e� � Server function� kern�retu rn �t getbala nc e� se rv er � balance� mach�port �t server� int �balanc e� �� out �� � �balance � server�b al an ce � return KERN�SUC CE SS � � �
T yp e De�nitions �� from mach�st d� ty pe s� de fs �� type mach�por t� t � MACH�MSG �T YP E� CO PY �S END � type int � MACH�MSG �T YP E� IN TE GE R� �� � type kern�ret ur n� t � int� �� pointer to out�of� li ne memory �� type pointer� t � �array�� of MACH�MSG �T YPE �B YT E� �� a ���byte structur e �� type mach�por t� st at us �t � struct� �� of int� �� C declarat io ns for these types �� import �mach�st d� ty pe s� h� � �
Asynchronous Messages �� file example �d ef s �� subsystem example ������ �include �mach�st d� ty pe s� de fs � �� set bank account balance �� routine setbala nc e� server � mach�po rt �t � in balance � int�� �� set it with an asynchr on ou s message �� simplerou ti ne asetbal an ce � server � mach�po rt �t � in balance � int�� Client and server co de lo oks lik e RPC� � Message�o rdering p roblems in multi�threaded � servers� Control��o w w o rries� � Not recommended fo r general use� � �
Asynchronous Messages Client call� �include �example �h � mach�port �t server� int balance � kern�retu rn �t kr� kr � setbalan ce �s er ve r� balance �� ��� kr � asetbala nc e� se rv er � balance� � Server function� kern�retu rn �t setbala nc e� se rv er � balance� mach�port �t server� int balance � �� in �� � server�ba la nc e � balance� return KERN�SUC CE SS � � kern�retu rn �t asetbal an ce �s er ve r� balance� mach�port �t server� int balance � �� in �� � server�ba la nc e � balance� return KERN�SUC CE SS � � �
Structure Arguments �� file example �d ef s �� subsystem example ������ �include �mach�st d� ty pe s� de fs � �include �example �t yp es �d ef s� routine structd em o� server � mach�po rt �t � in arg� � small�s tr uc t� t� out arg� � small�s tr uc t� t� inout arg� � small�s tr uc t� t�� �� file example �t yp es �d ef s �� �include �mach�st d� ty pe s� de fs � type small�st ru ct �t � struct� �� of int� import �example �t yp es �h �� �� file example �t yp es �h �� �ifndef �EXAMPL E� TY PE S� H� �define �EXAMPL E� TY PE S� H� typedef struct small�st ru ct � int one� int two���� � small�str uc t� t� �endif �EXAMPL E� TY PE S� H� �
Structure Arguments Client call� �include �example �h � mach�port �t server� small�str uc t� t arg�� arg�� arg�� kern�retu rn �t kr� kr � structde mo �s er ve r� arg�� �arg�� �arg��� Server function� kern�retu rn �t structd em o� se rv er � arg�� arg�� arg�� mach�port �t server� small�str uc t� t arg�� �� in �� small�str uc t� t �arg�� �� out �� small�str uc t� t �arg�� �� inout �� � �arg� � �arg�� �arg� � arg�� return KERN�SUC CE SS � � ��
Out�Of�Line Arguments �� file example �d ef s �� subsystem example ������ �include �mach�st d� ty pe s� de fs � �include �example �t yp es �d ef s� routine oolmemo ry de mo � server � mach�po rt �t � in arg� � some�me mo ry �t � out arg� � some�me mo ry �t �� �� file example �t yp es �d ef s �� �� � Variable �s iz ed out�of� li ne memory� � Mig type name is some�me mo ry �t � � C type name is vm�addr es s� t �� type some�mem or y� t � �array�� of MACH�MSG� TY PE �B YT E ctype� vm�addre ss �t � �� for C declarat io n of vm�addr es s� t �� import �mach�ma ch in e� vm �t yp es �h �� ��
Out�Of�Line Arguments Client call� �include �example �h � mach�port �t server� vm�addres s� t arg�� arg�� vm�size�t size�� size�� kern�retu rn �t kr� �void� vm�alloc at e� ma ch �t as k� se lf �� � �arg�� size�� TRUE�� kr � oolmemor yd em o� se rv er � arg�� size�� �arg�� �size�� � �void� vm�deall oc at e� ma ch �t as k� se lf ��� arg�� size��� �void� vm�deall oc at e� ma ch �t as k� se lf ��� arg�� size��� Server function� kern�retu rn �t oolmemo ry de mo �s er ve r� arg�� size�� arg�� size�� mach�port �t server� vm�addres s� t arg�� �� in �� vm�size�t size�� �� in �� vm�addres s� t �arg�� �� out �� vm�size�t �size�� �� out �� � �arg� � arg�� �size� � size�� return KERN�SUC CE SS � � ��
Deallo cation �� file example �d ef s �� subsystem example ������ �include �mach�st d� ty pe s� de fs � �include �example �t yp es �d ef s� �� dealloca te arg� while sending the reply �� routine oolmemo ry de mo � server � mach�po rt �t � in arg� � some�me mo ry �t � out arg� � some�me mo ry �t � dealloc �� Server function� kern�retu rn �t oolmemo ry de mo �s er ve r� arg�� size�� arg�� size�� mach�port �t server� vm�addres s� t arg�� �� in �� vm�size�t size�� �� in �� vm�addres s� t �arg�� �� out� dealloc �� vm�size�t �size�� �� out �� � �� � Out�of� li ne memory from the client in arg� is � returne d to the client with automati c dealloca ti on � �� �arg� � arg�� �size� � size�� return KERN�SUC CE SS � � ��
Recommend
More recommend