home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / mach / doc / unpublished / mig_example / randomUser.c.Z / randomUser.c
Encoding:
C/C++ Source or Header  |  1989-11-01  |  21.2 KB  |  879 lines

  1. #include "random.h"
  2. #include <mach/message.h>
  3. #include <mach/mach_types.h>
  4. #include <mach/mig_errors.h>
  5. #include <mach/msg_type.h>
  6. #if    !defined(KERNEL) && !defined(MIG_NO_STRINGS)
  7. #include <strings.h>
  8. #endif
  9. /* LINTLIBRARY */
  10.  
  11. extern port_t mig_get_reply_port();
  12. extern void mig_dealloc_reply_port();
  13.  
  14. #ifndef    mig_internal
  15. #define    mig_internal    static
  16. #endif
  17.  
  18. #ifndef    TypeCheck
  19. #define    TypeCheck 1
  20. #endif
  21.  
  22. #ifndef    UseExternRCSId
  23. #ifdef    hc
  24. #define    UseExternRCSId        1
  25. #endif
  26. #endif
  27.  
  28. #ifndef    UseStaticMsgType
  29. #if    !defined(hc) || defined(__STDC__)
  30. #define    UseStaticMsgType    1
  31. #endif
  32. #endif
  33.  
  34. #define msg_request_port    msg_remote_port
  35. #define msg_reply_port        msg_local_port
  36.  
  37. mig_external void init_random
  38. #if    (defined(__STDC__) || defined(c_plusplus))
  39.     (port_t rep_port)
  40. #else
  41.     (rep_port)
  42.     port_t rep_port;
  43. #endif
  44. {
  45. #ifdef    lint
  46.     rep_port++;
  47. #endif
  48. }
  49.  
  50. /* Procedure init_seed */
  51. mig_external void init_seed
  52. #if    (defined(__STDC__) || defined(c_plusplus))
  53. (
  54.     port_t server_port,
  55.     dbl seed
  56. )
  57. #else
  58.     (server_port, seed)
  59.     port_t server_port;
  60.     dbl seed;
  61. #endif
  62. {
  63.     typedef struct {
  64.         msg_header_t Head;
  65.         msg_type_t seedType;
  66.         dbl seed;
  67.     } Request;
  68.  
  69.     typedef struct {
  70.         msg_header_t Head;
  71.         msg_type_t RetCodeType;
  72.         kern_return_t RetCode;
  73.     } Reply;
  74.  
  75.     union {
  76.         Request In;
  77.         Reply Out;
  78.     } Mess;
  79.  
  80.     register Request *InP = &Mess.In;
  81.     register Reply *OutP = &Mess.Out;
  82.  
  83.     msg_return_t msg_result;
  84.  
  85. #if    TypeCheck
  86.     boolean_t msg_simple;
  87. #endif    TypeCheck
  88.  
  89.     unsigned int msg_size = 36;
  90.  
  91. #if    UseStaticMsgType
  92.     static msg_type_t seedType = {
  93.         /* msg_type_name = */        MSG_TYPE_INTEGER_32,
  94.         /* msg_type_size = */        32,
  95.         /* msg_type_number = */        2,
  96.         /* msg_type_inline = */        TRUE,
  97.         /* msg_type_longform = */    FALSE,
  98.         /* msg_type_deallocate = */    FALSE,
  99.         /* msg_type_unused = */    0,
  100.     };
  101. #endif    UseStaticMsgType
  102.  
  103. #if    UseStaticMsgType
  104.     static msg_type_t RetCodeCheck = {
  105.         /* msg_type_name = */        MSG_TYPE_INTEGER_32,
  106.         /* msg_type_size = */        32,
  107.         /* msg_type_number = */        1,
  108.         /* msg_type_inline = */        TRUE,
  109.         /* msg_type_longform = */    FALSE,
  110.         /* msg_type_deallocate = */    FALSE,
  111.         /* msg_type_unused = */    0,
  112.     };
  113. #endif    UseStaticMsgType
  114.  
  115. #if    UseStaticMsgType
  116.     InP->seedType = seedType;
  117. #else    UseStaticMsgType
  118.     InP->seedType.msg_type_name = MSG_TYPE_INTEGER_32;
  119.     InP->seedType.msg_type_size = 32;
  120.     InP->seedType.msg_type_number = 2;
  121.     InP->seedType.msg_type_inline = TRUE;
  122.     InP->seedType.msg_type_longform = FALSE;
  123.     InP->seedType.msg_type_deallocate = FALSE;
  124.     InP->seedType.msg_type_unused = 0;
  125. #endif    UseStaticMsgType
  126.  
  127.     InP->seed /* seed */ = /* seed */ seed;
  128.  
  129.     InP->Head.msg_simple = TRUE;
  130.     InP->Head.msg_size = msg_size;
  131.     InP->Head.msg_type = MSG_TYPE_NORMAL | MSG_TYPE_RPC;
  132.     InP->Head.msg_request_port = server_port;
  133.     InP->Head.msg_reply_port = mig_get_reply_port();
  134.     InP->Head.msg_id = 500;
  135.  
  136.     msg_result = msg_rpc(&InP->Head, MSG_OPTION_NONE, sizeof(Reply), 0, 0);
  137.     if (msg_result != RPC_SUCCESS) {
  138.         if (msg_result == RCV_INVALID_PORT)
  139.             mig_dealloc_reply_port();
  140.         { MsgError(msg_result); return; }
  141.     }
  142.  
  143. #if    TypeCheck
  144.     msg_size = OutP->Head.msg_size;
  145.     msg_simple = OutP->Head.msg_simple;
  146. #endif    TypeCheck
  147.  
  148.     if (OutP->Head.msg_id != 600)
  149.         { MsgError(MIG_REPLY_MISMATCH); return; }
  150.  
  151. #if    TypeCheck
  152.     if (((msg_size != 32) || (msg_simple != TRUE)) &&
  153.         ((msg_size != sizeof(death_pill_t)) ||
  154.          (msg_simple != TRUE) ||
  155.          (OutP->RetCode == KERN_SUCCESS)))
  156.         { MsgError(MIG_TYPE_ERROR); return; }
  157. #endif    TypeCheck
  158.  
  159. #if    TypeCheck
  160. #if    UseStaticMsgType
  161.     if (* (int *) &OutP->RetCodeType != * (int *) &RetCodeCheck)
  162. #else    UseStaticMsgType
  163.     if ((OutP->RetCodeType.msg_type_inline != TRUE) ||
  164.         (OutP->RetCodeType.msg_type_longform != FALSE) ||
  165.         (OutP->RetCodeType.msg_type_name != MSG_TYPE_INTEGER_32) ||
  166.         (OutP->RetCodeType.msg_type_number != 1) ||
  167.         (OutP->RetCodeType.msg_type_size != 32))
  168. #endif    UseStaticMsgType
  169.         { MsgError(MIG_TYPE_ERROR); return; }
  170. #endif    TypeCheck
  171.  
  172.     if (OutP->RetCode != KERN_SUCCESS)
  173.         { MsgError(OutP->RetCode); return; }
  174.  
  175.     /* Procedure - no return needed */
  176. }
  177.  
  178. /* Function get_randomf */
  179. mig_external int get_randomf
  180. #if    (defined(__STDC__) || defined(c_plusplus))
  181. (
  182.     port_t server_port
  183. )
  184. #else
  185.     (server_port)
  186.     port_t server_port;
  187. #endif
  188. {
  189.     typedef struct {
  190.         msg_header_t Head;
  191.     } Request;
  192.  
  193.     typedef struct {
  194.         msg_header_t Head;
  195.         msg_type_t RetCodeType;
  196.         kern_return_t RetCode;
  197.         msg_type_t get_randomfType;
  198.         int get_randomf;
  199.     } Reply;
  200.  
  201.     union {
  202.         Request In;
  203.         Reply Out;
  204.     } Mess;
  205.  
  206.     register Request *InP = &Mess.In;
  207.     register Reply *OutP = &Mess.Out;
  208.  
  209.     msg_return_t msg_result;
  210.  
  211. #if    TypeCheck
  212.     boolean_t msg_simple;
  213. #endif    TypeCheck
  214.  
  215.     unsigned int msg_size = 24;
  216.  
  217. #if    UseStaticMsgType
  218.     static msg_type_t RetCodeCheck = {
  219.         /* msg_type_name = */        MSG_TYPE_INTEGER_32,
  220.         /* msg_type_size = */        32,
  221.         /* msg_type_number = */        1,
  222.         /* msg_type_inline = */        TRUE,
  223.         /* msg_type_longform = */    FALSE,
  224.         /* msg_type_deallocate = */    FALSE,
  225.         /* msg_type_unused = */    0,
  226.     };
  227. #endif    UseStaticMsgType
  228.  
  229. #if    UseStaticMsgType
  230.     static msg_type_t get_randomfCheck = {
  231.         /* msg_type_name = */        MSG_TYPE_INTEGER_32,
  232.         /* msg_type_size = */        32,
  233.         /* msg_type_number = */        1,
  234.         /* msg_type_inline = */        TRUE,
  235.         /* msg_type_longform = */    FALSE,
  236.         /* msg_type_deallocate = */    FALSE,
  237.         /* msg_type_unused = */    0,
  238.     };
  239. #endif    UseStaticMsgType
  240.  
  241.     InP->Head.msg_simple = TRUE;
  242.     InP->Head.msg_size = msg_size;
  243.     InP->Head.msg_type = MSG_TYPE_NORMAL | MSG_TYPE_RPC;
  244.     InP->Head.msg_request_port = server_port;
  245.     InP->Head.msg_reply_port = mig_get_reply_port();
  246.     InP->Head.msg_id = 501;
  247.  
  248.     msg_result = msg_rpc(&InP->Head, MSG_OPTION_NONE, sizeof(Reply), 0, 0);
  249.     if (msg_result != RPC_SUCCESS) {
  250.         if (msg_result == RCV_INVALID_PORT)
  251.             mig_dealloc_reply_port();
  252.         { MsgError(msg_result); return OutP->get_randomf; }
  253.     }
  254.  
  255. #if    TypeCheck
  256.     msg_size = OutP->Head.msg_size;
  257.     msg_simple = OutP->Head.msg_simple;
  258. #endif    TypeCheck
  259.  
  260.     if (OutP->Head.msg_id != 601)
  261.         { MsgError(MIG_REPLY_MISMATCH); return OutP->get_randomf; }
  262.  
  263. #if    TypeCheck
  264.     if (((msg_size != 40) || (msg_simple != TRUE)) &&
  265.         ((msg_size != sizeof(death_pill_t)) ||
  266.          (msg_simple != TRUE) ||
  267.          (OutP->RetCode == KERN_SUCCESS)))
  268.         { MsgError(MIG_TYPE_ERROR); return OutP->get_randomf; }
  269. #endif    TypeCheck
  270.  
  271. #if    TypeCheck
  272. #if    UseStaticMsgType
  273.     if (* (int *) &OutP->RetCodeType != * (int *) &RetCodeCheck)
  274. #else    UseStaticMsgType
  275.     if ((OutP->RetCodeType.msg_type_inline != TRUE) ||
  276.         (OutP->RetCodeType.msg_type_longform != FALSE) ||
  277.         (OutP->RetCodeType.msg_type_name != MSG_TYPE_INTEGER_32) ||
  278.         (OutP->RetCodeType.msg_type_number != 1) ||
  279.         (OutP->RetCodeType.msg_type_size != 32))
  280. #endif    UseStaticMsgType
  281.         { MsgError(MIG_TYPE_ERROR); return OutP->get_randomf; }
  282. #endif    TypeCheck
  283.  
  284.     if (OutP->RetCode != KERN_SUCCESS)
  285.         { MsgError(OutP->RetCode); return OutP->get_randomf; }
  286.  
  287. #if    TypeCheck
  288. #if    UseStaticMsgType
  289.     if (* (int *) &OutP->get_randomfType != * (int *) &get_randomfCheck)
  290. #else    UseStaticMsgType
  291.     if ((OutP->get_randomfType.msg_type_inline != TRUE) ||
  292.         (OutP->get_randomfType.msg_type_longform != FALSE) ||
  293.         (OutP->get_randomfType.msg_type_name != MSG_TYPE_INTEGER_32) ||
  294.         (OutP->get_randomfType.msg_type_number != 1) ||
  295.         (OutP->get_randomfType.msg_type_size != 32))
  296. #endif    UseStaticMsgType
  297.         { MsgError(MIG_TYPE_ERROR); return OutP->get_randomf; }
  298. #endif    TypeCheck
  299.  
  300.     return OutP->get_randomf;
  301. }
  302.  
  303. /* Routine get_random */
  304. mig_external kern_return_t get_random
  305. #if    (defined(__STDC__) || defined(c_plusplus))
  306. (
  307.     port_t server_port,
  308.     int *num
  309. )
  310. #else
  311.     (server_port, num)
  312.     port_t server_port;
  313.     int *num;
  314. #endif
  315. {
  316.     typedef struct {
  317.         msg_header_t Head;
  318.     } Request;
  319.  
  320.     typedef struct {
  321.         msg_header_t Head;
  322.         msg_type_t RetCodeType;
  323.         kern_return_t RetCode;
  324.         msg_type_t numType;
  325.         int num;
  326.     } Reply;
  327.  
  328.     union {
  329.         Request In;
  330.         Reply Out;
  331.     } Mess;
  332.  
  333.     register Request *InP = &Mess.In;
  334.     register Reply *OutP = &Mess.Out;
  335.  
  336.     msg_return_t msg_result;
  337.  
  338. #if    TypeCheck
  339.     boolean_t msg_simple;
  340. #endif    TypeCheck
  341.  
  342.     unsigned int msg_size = 24;
  343.  
  344. #if    UseStaticMsgType
  345.     static msg_type_t RetCodeCheck = {
  346.         /* msg_type_name = */        MSG_TYPE_INTEGER_32,
  347.         /* msg_type_size = */        32,
  348.         /* msg_type_number = */        1,
  349.         /* msg_type_inline = */        TRUE,
  350.         /* msg_type_longform = */    FALSE,
  351.         /* msg_type_deallocate = */    FALSE,
  352.         /* msg_type_unused = */    0,
  353.     };
  354. #endif    UseStaticMsgType
  355.  
  356. #if    UseStaticMsgType
  357.     static msg_type_t numCheck = {
  358.         /* msg_type_name = */        MSG_TYPE_INTEGER_32,
  359.         /* msg_type_size = */        32,
  360.         /* msg_type_number = */        1,
  361.         /* msg_type_inline = */        TRUE,
  362.         /* msg_type_longform = */    FALSE,
  363.         /* msg_type_deallocate = */    FALSE,
  364.         /* msg_type_unused = */    0,
  365.     };
  366. #endif    UseStaticMsgType
  367.  
  368.     InP->Head.msg_simple = TRUE;
  369.     InP->Head.msg_size = msg_size;
  370.     InP->Head.msg_type = MSG_TYPE_NORMAL | MSG_TYPE_RPC;
  371.     InP->Head.msg_request_port = server_port;
  372.     InP->Head.msg_reply_port = mig_get_reply_port();
  373.     InP->Head.msg_id = 502;
  374.  
  375.     msg_result = msg_rpc(&InP->Head, MSG_OPTION_NONE, sizeof(Reply), 0, 0);
  376.     if (msg_result != RPC_SUCCESS) {
  377.         if (msg_result == RCV_INVALID_PORT)
  378.             mig_dealloc_reply_port();
  379.         return msg_result;
  380.     }
  381.  
  382. #if    TypeCheck
  383.     msg_size = OutP->Head.msg_size;
  384.     msg_simple = OutP->Head.msg_simple;
  385. #endif    TypeCheck
  386.  
  387.     if (OutP->Head.msg_id != 602)
  388.         return MIG_REPLY_MISMATCH;
  389.  
  390. #if    TypeCheck
  391.     if (((msg_size != 40) || (msg_simple != TRUE)) &&
  392.         ((msg_size != sizeof(death_pill_t)) ||
  393.          (msg_simple != TRUE) ||
  394.          (OutP->RetCode == KERN_SUCCESS)))
  395.         return MIG_TYPE_ERROR;
  396. #endif    TypeCheck
  397.  
  398. #if    TypeCheck
  399. #if    UseStaticMsgType
  400.     if (* (int *) &OutP->RetCodeType != * (int *) &RetCodeCheck)
  401. #else    UseStaticMsgType
  402.     if ((OutP->RetCodeType.msg_type_inline != TRUE) ||
  403.         (OutP->RetCodeType.msg_type_longform != FALSE) ||
  404.         (OutP->RetCodeType.msg_type_name != MSG_TYPE_INTEGER_32) ||
  405.         (OutP->RetCodeType.msg_type_number != 1) ||
  406.         (OutP->RetCodeType.msg_type_size != 32))
  407. #endif    UseStaticMsgType
  408.         return MIG_TYPE_ERROR;
  409. #endif    TypeCheck
  410.  
  411.     if (OutP->RetCode != KERN_SUCCESS)
  412.         return OutP->RetCode;
  413.  
  414. #if    TypeCheck
  415. #if    UseStaticMsgType
  416.     if (* (int *) &OutP->numType != * (int *) &numCheck)
  417. #else    UseStaticMsgType
  418.     if ((OutP->numType.msg_type_inline != TRUE) ||
  419.         (OutP->numType.msg_type_longform != FALSE) ||
  420.         (OutP->numType.msg_type_name != MSG_TYPE_INTEGER_32) ||
  421.         (OutP->numType.msg_type_number != 1) ||
  422.         (OutP->numType.msg_type_size != 32))
  423. #endif    UseStaticMsgType
  424.         return MIG_TYPE_ERROR;
  425. #endif    TypeCheck
  426.  
  427.     *num /* num */ = /* *num */ OutP->num;
  428.  
  429.     return OutP->RetCode;
  430. }
  431.  
  432. /* Routine get_secret */
  433. mig_external kern_return_t get_secret
  434. #if    (defined(__STDC__) || defined(c_plusplus))
  435. (
  436.     port_t server_port,
  437.     string25 password
  438. )
  439. #else
  440.     (server_port, password)
  441.     port_t server_port;
  442.     string25 password;
  443. #endif
  444. {
  445.     typedef struct {
  446.         msg_header_t Head;
  447.         msg_type_t passwordType;
  448.         string25 password;
  449.         char passwordPad[3];
  450.     } Request;
  451.  
  452.     typedef struct {
  453.         msg_header_t Head;
  454.         msg_type_t RetCodeType;
  455.         kern_return_t RetCode;
  456.         msg_type_t passwordType;
  457.         string25 password;
  458.         char passwordPad[3];
  459.     } Reply;
  460.  
  461.     union {
  462.         Request In;
  463.         Reply Out;
  464.     } Mess;
  465.  
  466.     register Request *InP = &Mess.In;
  467.     register Reply *OutP = &Mess.Out;
  468.  
  469.     msg_return_t msg_result;
  470.  
  471. #if    TypeCheck
  472.     boolean_t msg_simple;
  473. #endif    TypeCheck
  474.  
  475.     unsigned int msg_size = 56;
  476.  
  477. #if    UseStaticMsgType
  478.     static msg_type_t passwordType = {
  479.         /* msg_type_name = */        MSG_TYPE_STRING,
  480.         /* msg_type_size = */        200,
  481.         /* msg_type_number = */        1,
  482.         /* msg_type_inline = */        TRUE,
  483.         /* msg_type_longform = */    FALSE,
  484.         /* msg_type_deallocate = */    FALSE,
  485.         /* msg_type_unused = */    0,
  486.     };
  487. #endif    UseStaticMsgType
  488.  
  489. #if    UseStaticMsgType
  490.     static msg_type_t RetCodeCheck = {
  491.         /* msg_type_name = */        MSG_TYPE_INTEGER_32,
  492.         /* msg_type_size = */        32,
  493.         /* msg_type_number = */        1,
  494.         /* msg_type_inline = */        TRUE,
  495.         /* msg_type_longform = */    FALSE,
  496.         /* msg_type_deallocate = */    FALSE,
  497.         /* msg_type_unused = */    0,
  498.     };
  499. #endif    UseStaticMsgType
  500.  
  501. #if    UseStaticMsgType
  502.     static msg_type_t passwordCheck = {
  503.         /* msg_type_name = */        MSG_TYPE_STRING,
  504.         /* msg_type_size = */        200,
  505.         /* msg_type_number = */        1,
  506.         /* msg_type_inline = */        TRUE,
  507.         /* msg_type_longform = */    FALSE,
  508.         /* msg_type_deallocate = */    FALSE,
  509.         /* msg_type_unused = */    0,
  510.     };
  511. #endif    UseStaticMsgType
  512.  
  513. #if    UseStaticMsgType
  514.     InP->passwordType = passwordType;
  515. #else    UseStaticMsgType
  516.     InP->passwordType.msg_type_name = MSG_TYPE_STRING;
  517.     InP->passwordType.msg_type_size = 200;
  518.     InP->passwordType.msg_type_number = 1;
  519.     InP->passwordType.msg_type_inline = TRUE;
  520.     InP->passwordType.msg_type_longform = FALSE;
  521.     InP->passwordType.msg_type_deallocate = FALSE;
  522.     InP->passwordType.msg_type_unused = 0;
  523. #endif    UseStaticMsgType
  524.  
  525.     (void) mig_strncpy(InP->password /* password */, /* password */ password, 25);
  526.     InP->password /* password */[24] = '\0';
  527.  
  528.     InP->Head.msg_simple = TRUE;
  529.     InP->Head.msg_size = msg_size;
  530.     InP->Head.msg_type = MSG_TYPE_ENCRYPTED | MSG_TYPE_RPC;
  531.     InP->Head.msg_request_port = server_port;
  532.     InP->Head.msg_reply_port = mig_get_reply_port();
  533.     InP->Head.msg_id = 503;
  534.  
  535.     msg_result = msg_rpc(&InP->Head, RCV_TIMEOUT, sizeof(Reply), 0, 10000);
  536.     if (msg_result != RPC_SUCCESS) {
  537.         if ((msg_result == RCV_INVALID_PORT) ||
  538.             (msg_result == RCV_TIMED_OUT))
  539.             mig_dealloc_reply_port();
  540.         return msg_result;
  541.     }
  542.  
  543. #if    TypeCheck
  544.     msg_size = OutP->Head.msg_size;
  545.     msg_simple = OutP->Head.msg_simple;
  546. #endif    TypeCheck
  547.  
  548.     if (OutP->Head.msg_id != 603)
  549.         return MIG_REPLY_MISMATCH;
  550.  
  551. #if    TypeCheck
  552.     if (((msg_size != 64) || (msg_simple != TRUE)) &&
  553.         ((msg_size != sizeof(death_pill_t)) ||
  554.          (msg_simple != TRUE) ||
  555.          (OutP->RetCode == KERN_SUCCESS)))
  556.         return MIG_TYPE_ERROR;
  557. #endif    TypeCheck
  558.  
  559. #if    TypeCheck
  560. #if    UseStaticMsgType
  561.     if (* (int *) &OutP->RetCodeType != * (int *) &RetCodeCheck)
  562. #else    UseStaticMsgType
  563.     if ((OutP->RetCodeType.msg_type_inline != TRUE) ||
  564.         (OutP->RetCodeType.msg_type_longform != FALSE) ||
  565.         (OutP->RetCodeType.msg_type_name != MSG_TYPE_INTEGER_32) ||
  566.         (OutP->RetCodeType.msg_type_number != 1) ||
  567.         (OutP->RetCodeType.msg_type_size != 32))
  568. #endif    UseStaticMsgType
  569.         return MIG_TYPE_ERROR;
  570. #endif    TypeCheck
  571.  
  572.     if (OutP->RetCode != KERN_SUCCESS)
  573.         return OutP->RetCode;
  574.  
  575. #if    TypeCheck
  576. #if    UseStaticMsgType
  577.     if (* (int *) &OutP->passwordType != * (int *) &passwordCheck)
  578. #else    UseStaticMsgType
  579.     if ((OutP->passwordType.msg_type_inline != TRUE) ||
  580.         (OutP->passwordType.msg_type_longform != FALSE) ||
  581.         (OutP->passwordType.msg_type_name != MSG_TYPE_STRING) ||
  582.         (OutP->passwordType.msg_type_number != 1) ||
  583.         (OutP->passwordType.msg_type_size != 200))
  584. #endif    UseStaticMsgType
  585.         return MIG_TYPE_ERROR;
  586. #endif    TypeCheck
  587.  
  588.     (void) mig_strncpy(password /* password */, /* password */ OutP->password, 25);
  589.     password /* password */[24] = '\0';
  590.  
  591.     return OutP->RetCode;
  592. }
  593.  
  594. /* Routine get_confidential */
  595. mig_external kern_return_t get_confidential
  596. #if    (defined(__STDC__) || defined(c_plusplus))
  597. (
  598.     port_t server_port,
  599.     int wait,
  600.     int mtype | MSG_TYPE_RPC,
  601.     page_ptr *data
  602. )
  603. #else
  604.     (server_port, wait, mtype, data)
  605.     port_t server_port;
  606.     int wait;
  607.     int mtype;
  608.     page_ptr *data;
  609. #endif
  610. {
  611.     typedef struct {
  612.         msg_header_t Head;
  613.     } Request;
  614.  
  615.     typedef struct {
  616.         msg_header_t Head;
  617.         msg_type_t RetCodeType;
  618.         kern_return_t RetCode;
  619.         msg_type_long_t dataType;
  620.         page_ptr data;
  621.     } Reply;
  622.  
  623.     union {
  624.         Request In;
  625.         Reply Out;
  626.     } Mess;
  627.  
  628.     register Request *InP = &Mess.In;
  629.     register Reply *OutP = &Mess.Out;
  630.  
  631.     msg_return_t msg_result;
  632.  
  633. #if    TypeCheck
  634.     boolean_t msg_simple;
  635. #endif    TypeCheck
  636.  
  637.     unsigned int msg_size = 24;
  638.  
  639. #if    UseStaticMsgType
  640.     static msg_type_t RetCodeCheck = {
  641.         /* msg_type_name = */        MSG_TYPE_INTEGER_32,
  642.         /* msg_type_size = */        32,
  643.         /* msg_type_number = */        1,
  644.         /* msg_type_inline = */        TRUE,
  645.         /* msg_type_longform = */    FALSE,
  646.         /* msg_type_deallocate = */    FALSE,
  647.         /* msg_type_unused = */    0,
  648.     };
  649. #endif    UseStaticMsgType
  650.  
  651.     InP->Head.msg_simple = TRUE;
  652.     InP->Head.msg_size = msg_size;
  653.     InP->Head.msg_type = mtype | MSG_TYPE_RPC;
  654.     InP->Head.msg_request_port = server_port;
  655.     InP->Head.msg_reply_port = mig_get_reply_port();
  656.     InP->Head.msg_id = 504;
  657.  
  658.     msg_result = msg_rpc(&InP->Head, RCV_TIMEOUT, sizeof(Reply), 0, wait);
  659.     if (msg_result != RPC_SUCCESS) {
  660.         if ((msg_result == RCV_INVALID_PORT) ||
  661.             (msg_result == RCV_TIMED_OUT))
  662.             mig_dealloc_reply_port();
  663.         return msg_result;
  664.     }
  665.  
  666. #if    TypeCheck
  667.     msg_size = OutP->Head.msg_size;
  668.     msg_simple = OutP->Head.msg_simple;
  669. #endif    TypeCheck
  670.  
  671.     if (OutP->Head.msg_id != 604)
  672.         return MIG_REPLY_MISMATCH;
  673.  
  674. #if    TypeCheck
  675.     if (((msg_size != 48) || (msg_simple != FALSE)) &&
  676.         ((msg_size != sizeof(death_pill_t)) ||
  677.          (msg_simple != TRUE) ||
  678.          (OutP->RetCode == KERN_SUCCESS)))
  679.         return MIG_TYPE_ERROR;
  680. #endif    TypeCheck
  681.  
  682. #if    TypeCheck
  683. #if    UseStaticMsgType
  684.     if (* (int *) &OutP->RetCodeType != * (int *) &RetCodeCheck)
  685. #else    UseStaticMsgType
  686.     if ((OutP->RetCodeType.msg_type_inline != TRUE) ||
  687.         (OutP->RetCodeType.msg_type_longform != FALSE) ||
  688.         (OutP->RetCodeType.msg_type_name != MSG_TYPE_INTEGER_32) ||
  689.         (OutP->RetCodeType.msg_type_number != 1) ||
  690.         (OutP->RetCodeType.msg_type_size != 32))
  691. #endif    UseStaticMsgType
  692.         return MIG_TYPE_ERROR;
  693. #endif    TypeCheck
  694.  
  695.     if (OutP->RetCode != KERN_SUCCESS)
  696.         return OutP->RetCode;
  697.  
  698. #if    TypeCheck
  699.     if ((OutP->dataType.msg_type_header.msg_type_inline != FALSE) ||
  700.         (OutP->dataType.msg_type_header.msg_type_longform != TRUE) ||
  701.         (OutP->dataType.msg_type_long_name != MSG_TYPE_INTEGER_32) ||
  702.         (OutP->dataType.msg_type_long_number != 4096) ||
  703.         (OutP->dataType.msg_type_long_size != 32))
  704.         return MIG_TYPE_ERROR;
  705. #endif    TypeCheck
  706.  
  707.     *data /* data */ = /* *data */ OutP->data;
  708.  
  709.     return OutP->RetCode;
  710. }
  711.  
  712. /* SimpleRoutine use_random */
  713. mig_external kern_return_t use_random
  714. #if    (defined(__STDC__) || defined(c_plusplus))
  715. (
  716.     port_t server_port,
  717.     string80 info_seed,
  718.     comp_arr info,
  719.     words info_1,
  720.     unsigned int info_1Cnt
  721. )
  722. #else
  723.     (server_port, info_seed, info, info_1, info_1Cnt)
  724.     port_t server_port;
  725.     string80 info_seed;
  726.     comp_arr info;
  727.     words info_1;
  728.     unsigned int info_1Cnt;
  729. #endif
  730. {
  731.     typedef struct {
  732.         msg_header_t Head;
  733.         msg_type_t info_seedType;
  734.         string80 info_seed;
  735.         msg_type_t infoType;
  736.         comp_arr info;
  737.         msg_type_long_t info_1Type;
  738.         words info_1;
  739.     } Request;
  740.  
  741.     union {
  742.         Request In;
  743.     } Mess;
  744.  
  745.     register Request *InP = &Mess.In;
  746.  
  747.     unsigned int msg_size = 10368;
  748.  
  749. #if    UseStaticMsgType
  750.     static msg_type_t info_seedType = {
  751.         /* msg_type_name = */        MSG_TYPE_CHAR,
  752.         /* msg_type_size = */        8,
  753.         /* msg_type_number = */        80,
  754.         /* msg_type_inline = */        TRUE,
  755.         /* msg_type_longform = */    FALSE,
  756.         /* msg_type_deallocate = */    FALSE,
  757.         /* msg_type_unused = */    0,
  758.     };
  759. #endif    UseStaticMsgType
  760.  
  761. #if    UseStaticMsgType
  762.     static msg_type_t infoType = {
  763.         /* msg_type_name = */        MSG_TYPE_INTEGER_32,
  764.         /* msg_type_size = */        32,
  765.         /* msg_type_number = */        2560,
  766.         /* msg_type_inline = */        TRUE,
  767.         /* msg_type_longform = */    FALSE,
  768.         /* msg_type_deallocate = */    FALSE,
  769.         /* msg_type_unused = */    0,
  770.     };
  771. #endif    UseStaticMsgType
  772.  
  773. #if    UseStaticMsgType
  774.     static msg_type_long_t info_1Type = {
  775.     {
  776.         /* msg_type_name = */        0,
  777.         /* msg_type_size = */        0,
  778.         /* msg_type_number = */        0,
  779.         /* msg_type_inline = */        FALSE,
  780.         /* msg_type_longform = */    TRUE,
  781.         /* msg_type_deallocate = */    FALSE,
  782.         /* msg_type_unused = */    0,
  783.     },
  784.         /* msg_type_long_name = */    MSG_TYPE_INTEGER_32,
  785.         /* msg_type_long_size = */    32,
  786.         /* msg_type_long_number = */    0,
  787.     };
  788. #endif    UseStaticMsgType
  789.  
  790. #if    UseStaticMsgType
  791.     InP->info_seedType = info_seedType;
  792. #else    UseStaticMsgType
  793.     InP->info_seedType.msg_type_name = MSG_TYPE_CHAR;
  794.     InP->info_seedType.msg_type_size = 8;
  795.     InP->info_seedType.msg_type_number = 80;
  796.     InP->info_seedType.msg_type_inline = TRUE;
  797.     InP->info_seedType.msg_type_longform = FALSE;
  798.     InP->info_seedType.msg_type_deallocate = FALSE;
  799.     InP->info_seedType.msg_type_unused = 0;
  800. #endif    UseStaticMsgType
  801.  
  802.     InP->info_seed /* info_seed */ = /* info_seed */ info_seed;
  803.  
  804. #if    UseStaticMsgType
  805.     InP->infoType = infoType;
  806. #else    UseStaticMsgType
  807.     InP->infoType.msg_type_name = MSG_TYPE_INTEGER_32;
  808.     InP->infoType.msg_type_size = 32;
  809.     InP->infoType.msg_type_number = 2560;
  810.     InP->infoType.msg_type_inline = TRUE;
  811.     InP->infoType.msg_type_longform = FALSE;
  812.     InP->infoType.msg_type_deallocate = FALSE;
  813.     InP->infoType.msg_type_unused = 0;
  814. #endif    UseStaticMsgType
  815.  
  816.     { typedef struct { char data[10240]; } *sp; * (sp) InP->info /* info */ = * (sp) /* info */ info; }
  817.  
  818. #if    UseStaticMsgType
  819.     InP->info_1Type = info_1Type;
  820. #else    UseStaticMsgType
  821.     InP->info_1Type.msg_type_long_name = MSG_TYPE_INTEGER_32;
  822.     InP->info_1Type.msg_type_long_size = 32;
  823.     InP->info_1Type.msg_type_header.msg_type_inline = FALSE;
  824.     InP->info_1Type.msg_type_header.msg_type_longform = TRUE;
  825.     InP->info_1Type.msg_type_header.msg_type_deallocate = FALSE;
  826.     InP->info_1Type.msg_type_header.msg_type_unused = 0;
  827. #endif    UseStaticMsgType
  828.  
  829.     InP->info_1 /* info_1 */ = /* info_1 */ info_1;
  830.  
  831.     InP->info_1Type.msg_type_long_number /* info_1Cnt */ = /* info_1Type.msg_type_long_number */ info_1Cnt;
  832.  
  833.     InP->Head.msg_simple = FALSE;
  834.     InP->Head.msg_size = msg_size;
  835.     InP->Head.msg_type = MSG_TYPE_NORMAL;
  836.     InP->Head.msg_request_port = server_port;
  837.     InP->Head.msg_reply_port = PORT_NULL;
  838.     InP->Head.msg_id = 505;
  839.  
  840.     return msg_send(&InP->Head, MSG_OPTION_NONE, 0);
  841. }
  842.  
  843. /* SimpleProcedure exit */
  844. mig_external void exit
  845. #if    (defined(__STDC__) || defined(c_plusplus))
  846. (
  847.     port_t server_port
  848. )
  849. #else
  850.     (server_port)
  851.     port_t server_port;
  852. #endif
  853. {
  854.     typedef struct {
  855.         msg_header_t Head;
  856.     } Request;
  857.  
  858.     union {
  859.         Request In;
  860.     } Mess;
  861.  
  862.     register Request *InP = &Mess.In;
  863.  
  864.     msg_return_t msg_result;
  865.  
  866.     unsigned int msg_size = 24;
  867.  
  868.     InP->Head.msg_simple = TRUE;
  869.     InP->Head.msg_size = msg_size;
  870.     InP->Head.msg_type = MSG_TYPE_NORMAL;
  871.     InP->Head.msg_request_port = server_port;
  872.     InP->Head.msg_reply_port = PORT_NULL;
  873.     InP->Head.msg_id = 506;
  874.  
  875.     msg_result = msg_send(&InP->Head, MSG_OPTION_NONE, 0);
  876.     if (msg_result != SEND_SUCCESS)
  877.         { MsgError(msg_result); return; }
  878. }
  879.