home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / mach / doc / unpublished / manual.doc.Z / manual.doc
Encoding:
Text File  |  1992-08-18  |  170.4 KB  |  4,750 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.                          MACH KERNEL INTERFACE MANUAL
  16.  
  17.                                 Robert V. Baron
  18.                                   David Black
  19.                                 William Bolosky
  20.                                  Jonathan Chew
  21.                                Richard P. Draves
  22.                                 David B. Golub
  23.                                Richard F. Rashid
  24.                              Avadis Tevanian, Jr.
  25.                               Michael Wayne Young
  26.  
  27.                         Department of Computer Science
  28.                           Carnegie-Mellon University
  29.                              Pittsburgh, PA 15213
  30.                                   Version of:
  31.                                 23 August 1990
  32.  
  33.  
  34.  
  35.  
  36.  
  37.                                    ABSTRACT
  38.  
  39. MACH  is  an  operating  system  kernel  under  development  at Carnegie-Mellon
  40. University to support distributed and parallel computation.  MACH  is  designed
  41. to  support  computing environments consisting of networks of uniprocessors and
  42. multiprocessors.  This manual describes the interface to  the  MACH  kernel  in
  43. detail.    The MACH system currently runs on a wide variety of uniprocessor and
  44. multiprocessor architectures.
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.   This research was sponsored by the Defense Advanced Research Projects  Agency
  53. (DOD),  ARPA  Order  No. 4864, monitored by the Space and Naval Warfare Systems
  54. Command under contract N00039-84-C-0467.
  55.  
  56.   The views and conclusions contained in this document are those of the authors
  57. and  should  not  be  interpreted  as  representing  official  policies, either
  58. expressed or implied, of the Defense Advanced Research Projects  Agency  or  of
  59. the U.S.  Government.
  60. 1. Introduction
  61.   MACH is a communication-oriented operating system kernel providing:
  62.  
  63.    - multiple tasks, each with a large, paged virtual memory space,
  64.  
  65.    - multiple  threads  of  execution  within  each  task, with a flexible
  66.      scheduling facility,
  67.  
  68.    - flexible sharing of memory between tasks,
  69.  
  70.    - message-based interprocess communication,
  71.  
  72.    - transparent network extensibility, and
  73.  
  74.    - a flexible capability-based approach to security and protection.
  75.  
  76.   MACH supports multiprocessor scheduling and  is  currently  in  use  on  both
  77. general  purpose  multiprocessor  and  uniprocessor systems.  MACH is currently
  78. supported at CMU on the DEC VAX 8650, 8600, 11/785, 11/780, 11/750 and MicroVAX
  79. II,  the  IBM  RT/PC  and  the  SUN  3.    It  also will run as a shared memory
  80. multiprocessor system on the four processor VAX 11/784 and  two  processor  VAX
  81. 11/782,  the two processor VAX 8300, the VAX 8200 with one or more CPUs, the 20
  82. processor Encore MultiMax and the 30 processor Sequent Balance 21000.  Ports of
  83. MACH to other computers are in progress.
  84.  
  85.  
  86.  
  87. 1.1. Overall system organization
  88.   As  a  working  environment  for developing application programs, MACH can be
  89. viewed as being split into two components:
  90.  
  91.    - a small, extensible system kernel which provides scheduling,  virtual
  92.      memory and interprocess communications and
  93.  
  94.    - several,  possibly  parallel,  operating  system support environments
  95.      which provide the following two items: 1) distributed file access and
  96.      remote  execution  2)  emulation  for  established  operating  system
  97.      environments such as UNIX.
  98.  
  99.   The extensibility of the basic MACH kernel facilitates the  incorporation  of
  100. new  operating system functions; user-state programs can simply be added to the
  101. existing kernel without the need to modify the underlying  kernel  base.    The
  102. basic  kernel  abstractions  have been designed in such a way as to provide for
  103. completely transparent network extensibility of all kernel functions.
  104.  
  105.   MACH is 4.3bsd UNIX binary compatible  on  VAX  architecture  machines.    In
  106. addition,   the   MACH   environment  includes  an  internal  kernel  debugger,
  107. transparent network interprocess communication, remote execution facilities,  a
  108. transparent remote UNIX file system and support for graphics workstations.
  109.  
  110.  
  111.  
  112. 1.2. Basic kernel functionality
  113.   The MACH kernel supports the following basic abstractions:
  114.  
  115.    - A  task is an execution environment and is the basic unit of resource
  116.      allocation.  A  task  includes  a   paged   virtual   address   space
  117.      (potentially  sparse)  and protected access to system resources (such
  118.      as processors, port capabilities and virtual memory).
  119.  
  120.    - A thread is the  basic  unit  of  execution.    It  consists  of  all
  121.      processor  state  (e.g.hardware  registers) necessary for independent
  122.      execution.  A thread executes in the virtual memory and  port  rights
  123.      context  of  a single task.  The conventional notion of a process is,
  124.      in MACH, represented by a task with a single thread of control.
  125.  
  126.    - A port is a simplex communication channel -- implemented as a message
  127.      queue  managed and protected by the kernel.  A port is also the basic
  128.      object reference mechanism in MACH.   Ports  are  used  to  refer  to
  129.      objects;  operations  on objects are requested by sending messages to
  130.      the ports which represent them.
  131.  
  132.    - A port set is a group of ports, implemented as a queue combining  the
  133.      message queues of the constituent ports.  A thread may use a port set
  134.      to receive a message sent to any of several ports.
  135.  
  136.    - A message is a typed collection of data objects used in communication
  137.      between  threads.  Messages may be of any size and may contain inline
  138.      data, pointers to data, and capabilities for ports.
  139.  
  140.    - A memory object is a secondary storage object that is mapped  into  a
  141.      task's virtual memory. Memory objects are commonly files managed by a
  142.      file server, but as far as the MACH kernel  is  concerned,  a  memory
  143.      object  may  be implemented by any object (i.e. port) that can handle
  144.      requests to read and write data.
  145.  
  146.   Message-passing is the primary means of communication both among  tasks,  and
  147. between  tasks  and  the  operating  system  kernel itself.  The only functions
  148. implemented  by  system  traps  are  those  directly  concerned  with   message
  149. communication; all the rest are implemented by messages to a task's task_port.
  150.  
  151.   The MACH kernel functions can be divided into the following catagories:
  152.  
  153.    - basic message primitives and support facilities,
  154.  
  155.    - port and port set management facilities,
  156.  
  157.    - task and thread creation and management facilities,
  158.  
  159.    - virtual memory management functions,
  160.  
  161.    - operations on memory objects.
  162.  
  163.   MACH and other server interfaces are defined in a high-level remote procedure
  164. call language called MIG; from that definition, interfaces for C are generated.
  165. In the future, MIG may generate interfaces in other languages.  In this manual,
  166. calls are shown in the C language.
  167.  
  168.   All MACH kernel procedures return a value indicating the  success  or  reason
  169. for  failure  of that request. The errors unique to each function are described
  170. with those functions; however, since all  requests  involve  primitive  message
  171. operations, errors described in that section may also apply.
  172.  
  173.  
  174.  
  175. 1.3. User operating system environments
  176.   In  addition  to  the  facilities  provided directly by the kernel, MACH also
  177. provides for complete emulation of all 4.3bsd functions  as  described  in  the
  178. 4.3bsd  manual.   This emulation is completely transparent to user programs and
  179. requires no special libraries or other utilities.  On all VAX hardware MACH  is
  180. binary compatible with 4.3bsd.
  181.  
  182.   This  manual  does  not  reproduce  descriptions  of  the  UNIX system calls.
  183. Programmers wishing to use the functions  provided  within  these  environments
  184. should consult the relevant UNIX system manuals.
  185. 2. Message primitives
  186.  
  187.  
  188.  
  189. 2.1. Basic terms
  190.   MACH message primitives manipulate three distinct objects:
  191.  
  192.    1. ports  -  protected kernel objects to which messages may be sent and
  193.       logically queued until reception,
  194.  
  195.    2. port sets - protected kernel objects  which  combine  multiple  port
  196.       queues and from which messages may be dequeued, and
  197.  
  198.    3. messages  -  ordered collections of typed data consisting of a fixed
  199.       size message header and a variable size message body.
  200.  
  201.  
  202.  
  203. 2.2. Ports
  204.   Access rights to a port consist of the ability to send to, receive  from,  or
  205. own  that port.  A task may hold just send rights or any combination of receive
  206. and ownership rights plus send rights.  Threads within a task may only refer to
  207. ports  to  which  that  task has been given access.  When a new port is created
  208. within a task, that task is given all three access rights to that port.
  209.  
  210.   The port access rights are operationally defined as follows:
  211.  
  212.   Send access     to a port implies that a message can be sent  to  that  port.
  213.                   Should  the port be destroyed during the time a task has send
  214.                   access, a message will be sent to that  task  by  the  kernel
  215.                   indicating that the port has disappeared.
  216.  
  217.   Receive access  to  a  port  allows  a message to be dequeued from that port.
  218.                   Only one task may have receive access for a given port  at  a
  219.                   time;  however,  more  than  one  thread within that task may
  220.                   concurrently attempt to receive messages from a  given  port.
  221.                   Receive access implies send rights.
  222.  
  223.   Ownership       of  a  port implies that, should the task with receive access
  224.                   to that port  relinquish  its  receive  access,  the  receive
  225.                   access to the port will be sent to the owner task.  Likewise,
  226.                   should ownership be relinquished, the  ownership  rights  are
  227.                   sent  by the kernel to the receiving task. The name ownership
  228.                   is somewhat misleading as all it really  means  is  that  the
  229.                   task  is  a  backup reciever if the current receiver gives up
  230.                   its rights.  As with receive access, only one task  may  hold
  231.                   ownership  access  to any given port.  Ownership implies send
  232.                   rights.    NOTE:  the  ownership  abstraction  is  considered
  233.                   obsolete and has been replaced with the use of a backup port.
  234.                   This is a port associated with a primary port, to  which  the
  235.                   receive  rights of the primary port will be sent in the event
  236.                   of an attempted destruction  of  the  primary  port.  Current
  237.                   versions of MACH implement both mechanisms, but the ownership
  238.                   rights may disappear in future releases.
  239.  
  240.   Port access rights can be passed in messages.  They are  interpreted  by  the
  241. kernel  and transferred from the sender to the kernel upon message transmission
  242. and to the receiver upon  message  reception.  Send  rights  are  kept  by  the
  243. original  task  as  well as being transmitted to the receiver task, but receive
  244. rights and ownership rights are removed from the orignal task at  the  time  of
  245. the  send,  and  appear  in the user task when the receive is done.  During the
  246. time between a send and receive, the kernel holds the rights and  any  messages
  247. sent  to the port will be queued awaiting a new task to receive on the port. If
  248. the task that was intended to receive  the  rights  dies  before  it  does  the
  249. receive,  the rights are handled as though the receive had been done before the
  250. task died; that is receive rights are transferred to the owner or ownership  is
  251. transferred to the receiver.  If the receiver and owner are both dead, the port
  252. is destroyed.
  253.  
  254.   The message queue associated with a port is of finite  length  and  thus  may
  255. become  full.    Threads  may exercise several options for handling the case of
  256. message transmission to a full queue (see msg_send below).  Unless  a  specific
  257. option is set, msg_send will block until the message can be queued.
  258.  
  259.  
  260.  
  261. 2.3. Port sets
  262.   Conceptually,  a  port  set  is a bag holding zero or more receive rights.  A
  263. port set allows a thread to block waiting for a message sent to any of  several
  264. ports.  A port may be a member of at most one port set at any time.
  265.  
  266.   A  task's  port  set  right, created by port_set_allocate, allows the task to
  267. receive a message from the port set with msg_receive and  manipulate  the  port
  268. set     with     port_set_add,     port_set_remove,     port_set_status,    and
  269. port_set_deallocate.  Unlike port rights, a port set right may not be passed in
  270. messages.
  271.  
  272.  
  273.  
  274. 2.4. Port names
  275.   Every  task  has  its  own port name space, used for port and port set names.
  276. For example, one task with receive and ownership rights for a port may know the
  277. port  by the name 13, while another task with send rights for the same port may
  278. know it by the name 17.  A task only has one name for a port, so  if  the  task
  279. with send rights named 17 receives another message carrying send rights for the
  280. same port, the arriving rights will also be named 17.
  281.  
  282.   Typically  these  names  are  small  integers,  but  that  is  implementation
  283. dependent.   When a task receives a message carrying rights for a new port, the
  284. MACH kernel is free to choose any unused name.  The  port_rename  call  can  be
  285. used to change a task's name for a port.
  286.  
  287.  
  288.  
  289. 2.5. Port types
  290.   There  are  several type defintions for ports used in this manual and defined
  291. in <mach/port.h>. The type port_name_t is used to refer to a port to which  the
  292. task may have no rights. When this type is used in a message definition no port
  293. rights are sent in the message and the kernel does no  mapping  of  ports.  The
  294. type  port_set_name_t  is  used  to  refer to a port set and does not imply any
  295. rights to the set. Only port set names can be passed in messages. In  order  to
  296. pass  the  rights  to a port set, a task must pass each port separately and the
  297. receiving port must then define a new port set with consisting of those  ports.
  298. The  types  port_t, port_rcv_t and port_all_t are used to imply a port to which
  299. the task has the specified rights. Typically port_t is used for a port with any
  300. rights.  One  of  these  types  must be used in the message definition if ports
  301. rights are to be sent in the message.  All of these types are defined to be the
  302. same  basic  C  types,  so  that  they  can be used interchangeably in calls to
  303. primitives.
  304.  
  305.   Most of the MACH calls take a task or thread as their  first  argument  where
  306. this  agrument is said to be the target task/thread.  In most cases the task or
  307. thread is the one doing the call. In  those  cases  any  port_name_t  arguments
  308. represent ports to which the task has or receives rights. But in the case where
  309. task is not the caller, then the target task gets the rights but  doesn't  know
  310. the  name,  and  the  caller  gets the name but does not have any rights to the
  311. port.
  312.  
  313.  
  314.  
  315. 2.6. Messages
  316.   A message consists of a fixed header, followed by a variable amount of  data.
  317. The C type definition for the message header is as follows:
  318.  
  319.     typedef struct {
  320.                     int             :24,
  321.                                     msg_simple : 8;
  322.                     int             msg_size;
  323.                     int             msg_type;
  324.                     port_t          msg_local_port;
  325.                     port_t          msg_remote_port;
  326.                     int             msg_id;
  327.     } msg_header_t;
  328.  
  329. The  msg_local_port  and  msg_remote_port  fields are used to name the ports on
  330. which a message is to be received or sent. In the case of msg_receive this  may
  331. be  either  a  port  or a port set.  The msg_size field is used to describe the
  332. size of the message to be sent, or the maximum size of the message which can be
  333. received.   The size includes the header and inline data and is given in bytes.
  334. The msg_simple field is used to indicate that no ports or out-of-line data  are
  335. contained  in  the  body.    The  msg_id  field may be used by user programs to
  336. identify the meaning of this message to the intended recipient.
  337.  
  338.   The variable data part of a message consists of an array of  descriptors  and
  339. data. Each data descriptor is of the form:
  340.  
  341.     typedef struct  {
  342.             unsigned int    msg_type_name : 8,
  343.                                     /* What kind of data */
  344.                             msg_type_size : 8,
  345.                                     /* How many bits is each item */
  346.                             msg_type_number : 12,
  347.                                     /* How many items are there */
  348.                             msg_type_inline : 1,
  349.                                     /* If true, actual data follows;
  350.                                      *  else a pointer to the data */
  351.                             msg_type_longform : 1,
  352.                                     /* Name, size, number follow */
  353.                             msg_type_deallocate : 1;
  354.                                     /* Deallocate port rights or memory */
  355.     } msg_type_t;
  356.  
  357. msg_type_name     describes  the  basic  type  of  data comprising this object.
  358.                 There are several system-defined data types, including:
  359.  
  360.                    - Ports, including combinations of send,  receive,  and
  361.                      ownership rights,
  362.  
  363.                    - Port  and  port set names.  This is the same language
  364.                      data type  as  port  rights,  but  the  message  only
  365.                      carries  a  task's  name for a port and doesn't cause
  366.                      any transferal of rights.
  367.  
  368.                    - Simple data types, such as integers, characters,  and
  369.                      floating point values.
  370.  
  371. msg_type_size     indicates  the  size in bits of the basic object named in the
  372.                 msg_type_name field.
  373.  
  374. msg_type_number  indicates the number of items of the basic data  type  present
  375.                 after the type descriptor.
  376.  
  377. msg_type_inline   indicates  that  the  actual  data is included after the type
  378.                 descriptor; otherwise, the word following the descriptor  is  a
  379.                 pointer to the data to be sent.
  380.  
  381. msg_type_deallocate
  382.                 indicates that the port rights and/or data pointed to  in  this
  383.                 object  are  to  be  deallocated  after  the  queueing  of this
  384.                 message.  Receive and ownership rights may not  be  deallocated
  385.                 with msg_type_deallocate.
  386.  
  387. msg_type_longform
  388.                 indicates that the name, size, and number fields were too  long
  389.                 to  fit  in  the  structure described above.  Instead, the data
  390.                 type descriptor is described by the following structure:
  391.  
  392.                     typedef struct  {
  393.                             msg_type_t      msg_type_header;
  394.                             short           msg_type_long_name;
  395.                             short           msg_type_long_size;
  396.                             int             msg_type_long_number;
  397.                     } msg_type_long_t;
  398.  
  399.   A data item or a pointer to data follows each data descriptor.
  400.  
  401.   All the C types and constants needed to use the message functions are defined
  402. in <mach/message.h>. The declarations in this section are taken from this file.
  403. msg_send
  404.  
  405. #include <mach/message.h>
  406. msg_return_t msg_send(header, option, timeout)
  407.         msg_header_t    *header;
  408.         msg_option_t    option;
  409.         msg_timeout_t   timeout;
  410.  
  411.  
  412. Arguments
  413.  
  414.   header          The  address of the message to be sent. A message consists of
  415.                   a fixed sized header followed by a variable  number  of  data
  416.                   descriptors  and  data  items.  See  <mach/message.h>  for  a
  417.                   definition of the message structure.
  418.  
  419.   timeout         In the event that  the  destination  port  is  full  and  the
  420.                   SEND_TIMEOUT  option has been specified, this value specifies
  421.                   the maximum wait time (in milliseconds).
  422.  
  423.   option          The failure conditions under which msg_send should terminate;
  424.                   the  value  of  this parameter is an or'ed combination of the
  425.                   following two options.   Unless  one  of  the  two  following
  426.                   values  for  the  option  parameter  is explicitly specified,
  427.                   msg_send does not return until the  message  is  successfully
  428.                   queued for the intended receiver.
  429.  
  430.   SEND_TIMEOUT    specifies  that  the  msg_send request should terminate after
  431.                   the timeout period has elapsed, even if the kernel  has  been
  432.                   unable to queue the message.
  433.  
  434.   SEND_NOTIFY     allows  the  sender  to  give  exactly  one  message  to  the
  435.                   operating  system  without   being   suspended   should   the
  436.                   destination port be full.  When another message can be forced
  437.                   to the receiving port's queue using SEND_NOTIFY, the  sending
  438.                   task  receives  a NOTIFY_MSG_ACCEPTED notification.  A second
  439.                   attempt to send a message with the notify option  before  the
  440.                   notification arrives results in an error.  If SEND_TIMEOUT is
  441.                   also  specified,  msg_send  will  wait  until  the  specified
  442.                   timeout has elapsed before invoking the SEND_NOTIFY option.
  443.  
  444.   SEND_INTERRUPT  Specifies that msg_send should return if a software interrupt
  445.                   occurs in this thread.
  446.  
  447.   MSG_OPTION_NONE A constant defined as zero which may be used to specify  that
  448.                   neither of the previous options are wanted.
  449.  
  450. Description
  451.  
  452.   msg_send  transmits  a  message  from  the  current  task  to the remote port
  453. specified in the message header field (msg_remote_port).  The message  consists
  454. of  its  header,  followed  by  a  variable number of data descriptors and data
  455. items.    (See  the  introduction  to  this  section  for  details  on  message
  456. formatting.)
  457.  
  458.   If the msg_local_port field is not set to PORT_NULL, send rights to that port
  459. will be passed to the receiver of this message. The receiver task may use  that
  460. port to send a reply to this message.
  461.  
  462.   If  the  SEND_NOTIFY  option is used and this call returns a SEND_WILL_NOTIFY
  463. code, then the user can expect to receive a notify  message  from  the  kernel.
  464. This  message  will  either  be  a NOTIFY_MSG_ACCEPTED or a NOTIFY_PORT_DELETED
  465. message depending on what happened to the queued message. The  first  and  only
  466. data item in these messages is the port to which the original message was sent.
  467. The ids and formats for these messages are defined in <mach/notify.h>.
  468.  
  469. Returns
  470.  
  471.   SEND_SUCCESS    The message has been queued for the destination port.
  472.  
  473.   SEND_INVALID_MEMORY
  474.                   The  message  header  or body was not readable by the calling
  475.                   task, or the message body specified  out-of-line  data  which
  476.                   was not readable.
  477.  
  478.   SEND_INVALID_PORT
  479.                   The message refers to a name for which the current task  does
  480.                   not  have  access,  or to which access was explicitly removed
  481.                   from the current task (see port_deallocate) while waiting for
  482.                   the  message  to  be  posted, or a msg_type_name field in the
  483.                   message specifies rights that the name doesn't denote in  the
  484.                   task (eg, specifying MSG_TYPE_SEND and supplying a port set's
  485.                   name).
  486.  
  487.   SEND_TIMED_OUT  The message was not sent since the destination port was still
  488.                   full after timeout milliseconds.
  489.  
  490.   SEND_WILL_NOTIFY
  491.                   The destination port was full but the SEND_NOTIFY option  was
  492.                   specified.    A  notification  message  will be sent when the
  493.                   message can be posted.
  494.  
  495.   SEND_NOTIFY_IN_PROGRESS
  496.                   The  SEND_NOTIFY  option  was  specified  but  a notification
  497.                   request is already outstanding  for  this  thread  and  given
  498.                   destination port.
  499.  
  500. See Also
  501.  
  502.   msg_receive, msg_rpc
  503. msg_receive
  504.  
  505. #include <mach/message.h>
  506. #include <mach/port.h>
  507. msg_return_t msg_receive(header, option, timeout)
  508.         msg_header_t    *header;        /* in/out */
  509.         msg_option_t    option;
  510.         msg_timeout_t   timeout;
  511.  
  512.  
  513. Arguments
  514.  
  515.   header          The  address  of  a  buffer  in  which  the  message is to be
  516.                   received.  Two fields of  the  message  header  must  be  set
  517.                   before  the  call is made:  msg_local_port is set to the name
  518.                   of the port or port set from  which  the  message  is  to  be
  519.                   received  and msg_size must be set to the maximum size of the
  520.                   message that may be received. It must be less than  or  equal
  521.                   to the size of the buffer.
  522.  
  523.   timeout         If RCV_TIMEOUT is specified this value is the maximum time in
  524.                   milliseconds to wait for a message before giving up.
  525.  
  526.   option          The  failure  conditions  under  which   msg_receive   should
  527.                   terminate;  the  value  of  this  parameter  is  a  bit  or'd
  528.                   combination the following two options.  Unless one of the two
  529.                   following  values  for  the  option  parameter  is explicitly
  530.                   specified, msg_receive does not return until  a  message  has
  531.                   been received.
  532.  
  533.   RCV_TIMEOUT     Specifies  that  msg_receive should return when the specified
  534.                   timeout elapses, if a message has not arrived by  that  time;
  535.                   if   not   specified,  the  timeout  will  be  ignored  (i.e.
  536.                   infinite).
  537.  
  538.   RCV_NO_SENDERS  Specifies that msg_receive should return if the receiver  and
  539.                   owner tasks have the only access rights to the port specified
  540.                   in the message header. (Not implemented yet)
  541.  
  542.   RCV_INTERRUPT   Specifies that msg_receive  should  return  when  a  software
  543.                   interrupt has occurred in this thread.
  544.  
  545.   MSG_OPTION_NONE Specifies that none of the above options are desired.
  546.  
  547. Description
  548.  
  549.   msg_receive  retrieves  the next message from a port or port set specified in
  550. the msg_local_port field of the  specified  message  header.    If  a  port  is
  551. specified,  the  port  may  not  be a member of a port set.  The msg_local_port
  552. field will be set to the specific port on which the message was found.
  553.  
  554.   If a port set is specified, the msg_receive will retrieve  messages  sent  to
  555. any  of the set's member ports.  It is not an error for the port set to have no
  556. members, or for members to be added  and  removed  from  a  port  set  while  a
  557. msg_receive on the port set is in progress.
  558.  
  559.   The  message  consists  of its header, followed by a variable amount of data;
  560. the message header supplied to msg_receive must specify the maximum size of the
  561. message  which can be received into the buffer provided.  (See the introduction
  562. to this section for details on message formatting).
  563.  
  564.   If no messages are present on the port(s) in question, msg_receive will  wait
  565. until  a  message arrives, or until one of the specified termination conditions
  566. is met (see above for discussion of the option parameter).
  567.  
  568.   If the received messages  contains  out-of-line  data  (i.e.  for  which  the
  569. msg_type_inline attribute was specified as FALSE), the data will be returned in
  570. a newly-allocated region of memory; the message body will contain a pointer  to
  571. that  new  region.    (See  vm_allocate  call for a description of the state of
  572. newly-allocated memory.) The user may wish to deallocte this  memory  when  the
  573. data is no longer needed.
  574.  
  575. Returns
  576.  
  577.   RCV_SUCCESS     The message has been received.
  578.  
  579.   RCV_INVALID_MEMORY
  580.                   The message specified was not writable by the calling task.
  581.  
  582.   RCV_INVALID_PORT
  583.                   An attempt was made to receive on a port to which the calling
  584.                   task  does  not  have  the  proper  access,  or   which   was
  585.                   deallocated   (see   port_deallocate)  while  waiting  for  a
  586.                   message.
  587.  
  588.   RCV_TOO_LARGE   The message header and body combined are larger than the size
  589.                   specified by msg_size.
  590.  
  591.   RCV_NOT_ENOUGH_MEMORY
  592.                   The message to be received  contains  more  out-of-line  data
  593.                   than can be allocated in the receiving task.
  594.  
  595.   RCV_TIMED_OUT   The message was not received after timeout milliseconds.
  596.  
  597.   RCV_ONLY_SENDER An  attempt  was  made to receive on a port to which only the
  598.                   receive and/or owner  have  access,  and  the  RCV_NO_SENDERS
  599.                   option was specified.
  600.  
  601.   RCV_INTERRUPTED A software interrupt occurred.
  602.  
  603.   RCV_PORT_CHANGE The  port  specified  was  moved  into  a port set during the
  604.                   duration of the msg_receive call.
  605.  
  606. See Also
  607.  
  608.   msg_rpc, msg_send
  609. msg_rpc
  610.  
  611. #include <mach/message.h>
  612. #include <mach/port.h>
  613. msg_return_t msg_rpc(header, option, rcv_size,
  614.                         send_timeout, rcv_timeout)
  615.         msg_header_t    *header;        /* in/out */
  616.         msg_option_t    option;
  617.         msg_size_t      rcv_size;
  618.         msg_timeout_t   send_timeout;
  619.         msg_timeout_t   rcv_timeout;
  620.  
  621.  
  622. Arguments
  623.  
  624.   header          Address of a message buffer  which  will  be  used  for  both
  625.                   msg_send  and  msg_receive.    This buffer contains a message
  626.                   header followed by the data for the message to be sent.   The
  627.                   msg_remote_port field specifies the port to which the message
  628.                   is to be sent.  The msg_local_port field specifies  the  port
  629.                   on  which  a  message is then to be received; if this port is
  630.                   the special value PORT_DEFAULT, it will be  replaced  by  the
  631.                   value PORT_NULL for the purposes of the msg_send operation.
  632.  
  633.   option          A   union   of   the  option  parameters  for  the  component
  634.                   operations.  (see msg_send and msg_receive)
  635.  
  636.   rcv_size        The maximum size allowed for the received message; this  must
  637.                   be less than or equal to the size of the message buffer.  The
  638.                   msg_size field in  the  header  specifies  the  size  of  the
  639.                   message to be sent.
  640.  
  641.   send_timeout;rcv_timeout
  642.                   The timeout values to be applied to the component operations.
  643.                   These  are  only  used  if  the  options  SEND_TIMEOUT and/or
  644.                   RCV_TIMEOUT are specified.
  645.  
  646. Description
  647.  
  648.   msg_rpc is a hybrid call which performs a msg_send followed by a msg_receive,
  649. using the same message buffer.
  650.  
  651. Returns
  652.  
  653.   RPC_SUCCESS     message was successfully sent and a reply was recived.
  654.  
  655.   FAILURES        are the same as those for msg_send and msg_receive; any error
  656.                   during the msg_send portion will terminate the call.
  657.  
  658. See Also
  659.  
  660.   msg_receive, msg_send
  661. 3. Port and port set primitives
  662. port_names
  663.  
  664. #include <mach.h>
  665.  
  666. kern_return_t port_names(task,
  667.                          portnames, portnamesCnt,
  668.                          port_types, port_typesCnt)
  669.         task_t task;
  670.         port_name_array_t *portnames;   /* out array */
  671.         unsigned int *portnamesCnt;     /* out */
  672.         port_type_array_t *port_types;  /* out array */
  673.         unsigned int *port_typesCnt;    /* out */
  674.  
  675.  
  676. Arguments
  677.  
  678.   task            The task whose port name space is queried.
  679.  
  680.   portnames       The names of the ports and port sets in the task's port  name
  681.                   space, in no particular order.
  682.  
  683.   portnamesCnt    The number of names returned.
  684.  
  685.   port_types      The  type of each corresponding name.  Indicates what kind of
  686.                   right the task holds for the port or port set.
  687.  
  688.   port_typesCnt   Should be the same as portnamesCnt.
  689.  
  690. Description
  691.  
  692.   port_names returns the currently valid ports and port set names of task.  For
  693. each  name,  it  also  returns  what  type  of rights task holds. portnames and
  694. port_types are arrays that are automatically allocated when the  reply  message
  695. is received. The user may wish to vm_deallocate them when the data is no longer
  696. needed.
  697.  
  698. Returns
  699.  
  700.   KERN_SUCCESS    The call succeeded.
  701.  
  702.   KERN_INVALID_ARGUMENT
  703.                   task was invalid.
  704.  
  705. See Also
  706.  
  707.   port_type, port_status, port_set_status
  708. port_type
  709.  
  710. #include <mach.h>
  711.  
  712. kern_return_t port_type(task, port_name, port_type)
  713.         task_t task;
  714.         port_name_t port_name;
  715.         port_type_t *port_type;         /* out */
  716.  
  717.  
  718. Arguments
  719.  
  720.   task            The task whose port name space is queried.
  721.  
  722.   port_name       The name being queried.
  723.  
  724.   port_type       The  type of the name.  Indicates what kind of right the task
  725.                   holds for the port or port set.
  726.  
  727. Description
  728.  
  729.   port_type returns information about task's rights for a specific name in  its
  730. port name space.
  731.  
  732. Returns
  733.  
  734.   KERN_SUCCESS    The call succeeded.
  735.  
  736.   KERN_INVALID_ARGUMENT
  737.                   task was invalid or  task  did  not  have  any  rights  named
  738.                   port_name.
  739.  
  740. See Also
  741.  
  742.   port_names, port_status, port_set_status
  743. port_rename
  744.  
  745. #include <mach.h>
  746.  
  747. kern_return_t port_rename(task, old_name, new_name)
  748.         task_t task;
  749.         port_name_t old_name;
  750.         port_name_t new_name;
  751.  
  752.  
  753. Arguments
  754.  
  755.   task            The task whose port name space is changed.
  756.  
  757.   old_name        The name being changed.
  758.  
  759.   new_name        The new value for old_name.
  760.  
  761. Description
  762.  
  763.   port_rename  changes  the  name by which a port or port set is known to task.
  764. new_name must not already be in use, and it can't be a distinguished value like
  765. PORT_NULL.
  766.  
  767. Returns
  768.  
  769.   KERN_SUCCESS    The call succeeded.
  770.  
  771.   KERN_NAME_EXISTS
  772.                   task already has a right named new_name.
  773.  
  774.   KERN_INVALID_ARGUMENT
  775.                   task  was  invalid  or  task  did  not  have any rights named
  776.                   old_name or new_name was an invalid name.
  777.  
  778. See Also
  779.  
  780.   port_names
  781. port_allocate
  782.  
  783. #include <mach.h>
  784.  
  785. kern_return_t port_allocate(task, port_name)
  786.         task_t task;
  787.         port_name_t *port_name;         /* out */
  788.  
  789.  
  790. Arguments
  791.  
  792.   task            The task in which the new port is created.
  793.  
  794.   port_name       The task's name for the new port.
  795.  
  796. Description
  797.  
  798.   port_allocate causes a port  to  be  created  for  the  specified  task;  the
  799. resulting  port's name is returned in port_name.  The target task initially has
  800. all three access rights to the port.  If the caller is not the  task  specified
  801. by  task,  then it does not have any rights to the port.  The new port is not a
  802. member of any port set.
  803.  
  804. Returns
  805.  
  806.   KERN_SUCCESS    The call succeeded.
  807.  
  808.   KERN_INVALID_ARGUMENT
  809.                   task was invalid.
  810.  
  811.   KERN_RESOURCE_SHORTAGE
  812.                   The kernel ran out of memory.
  813.  
  814. See Also
  815.  
  816.   port_deallocate
  817. port_deallocate
  818.  
  819. #include <mach.h>
  820.  
  821. kern_return_t port_deallocate(task, port_name)
  822.         task_t task;
  823.         port_name_t port_name;
  824.  
  825.  
  826. Arguments
  827.  
  828.   task            The task from which to remove the port rights.
  829.  
  830.   port_name       task's name for the rights to be removed.
  831.  
  832. Description
  833.  
  834.   port_deallocate requests that the target task's rights for a port be removed.
  835.  
  836.   If task has receive rights for the port, and the port is a member of  a  port
  837. set, the port is removed from the port set.
  838.  
  839.   If the target task is both the receiver and owner for the port, then the port
  840. is destroyed and all other tasks with send access are notified  of  the  port's
  841. destruction.  If the task is only the receiver for the port, receive rights are
  842. sent to the owner. If the task is only the owner of the port, ownership  rights
  843. are sent to the receiver.
  844.  
  845. Returns
  846.  
  847.   KERN_SUCCESS    The call succeeded.
  848.  
  849.   KERN_INVALID_ARGUMENT
  850.                   task was invalid or port_name does not name a valid port.
  851.  
  852. See Also
  853.  
  854.   port_allocate
  855. port_status
  856.  
  857. #include <mach.h>
  858.  
  859. kern_return_t port_status(task, port_name, enabled,
  860.                           num_msgs, backlog, owner, receiver)
  861.         task_t task;
  862.         port_name_t port_name;
  863.         port_set_name_t *enabled;       /* out */
  864.         int *num_msgs;                  /* out */
  865.         int *backlog;                   /* out */
  866.         boolean_t *owner;               /* out */
  867.         boolean_t *receiver;            /* out */
  868.  
  869.  
  870. Arguments
  871.  
  872.   task            The task owning the port right in question.
  873.  
  874.   port_name       task's name for the port right.
  875.  
  876.   enabled         Returns task's name for the port set  which  the  named  port
  877.                   belongs to, or PORT_NULL if it isn't in a set.
  878.  
  879.   num_msgs        The number of messages queued on this port.
  880.  
  881.   backlog         The  number  of  messages  which  may  be queued to this port
  882.                   without causing the sender to block.
  883.  
  884.   owner           Returned as true iff the task is the owner of the port.
  885.  
  886.   receiver        Returned as true iff the task is the receive of the port.
  887.  
  888. Description
  889.  
  890.   port_status returns the current status  associated  with  task's  port  right
  891. named  port_name.    If  receiver  isn't  true,  then the enabled, num_msg, and
  892. backlog arguments don't return anything meaningful.
  893.  
  894. Returns
  895.  
  896.   KERN_SUCCESS    The call succeeded.
  897.  
  898.   KERN_INVALID_ARGUMENT
  899.                   task was invalid or port_name does not name a valid port.
  900.  
  901. See Also
  902.  
  903.   port_set_backlog, port_set_status
  904. port_set_backlog
  905.  
  906. #include <mach.h>
  907.  
  908. kern_return_t port_set_backlog(task, port_name, backlog)
  909.         task_t task;
  910.         port_name_t port_name;
  911.         int backlog;
  912.  
  913.  
  914. Arguments
  915.  
  916.   task            The task owning the named port right.
  917.  
  918.   port_name       task's name for the port right.
  919.  
  920.   backlog         The new backlog to be set.
  921.  
  922. Description
  923.  
  924.   The  port's  backlog  value  is  the  number  of unreceived messages that are
  925. allowed in its message queue before the kernel will refuse to accept  any  more
  926. sends  to  that  port.    port_set_backlog  changes  the  backlog  value on the
  927. specified port.
  928.  
  929.   task must have receive rights for the named port.
  930.  
  931.   The file <mach/mach_param.h> exports the system default value  for  a  port's
  932. backlog  as  the constant PORT_BACKLOG_DEFAULT and the maximum backlog value as
  933. the constant PORT_BACKLOG_MAX.
  934.  
  935. Returns
  936.  
  937.   KERN_SUCCESS    The call succeeded.
  938.  
  939.   KERN_NOT_RECEIVER
  940.                   port_name doesn't name receive rights in task.
  941.  
  942.   KERN_INVALID_ARGUMENT
  943.                   task was invalid or port_name does not name a valid  port  or
  944.                   the  desired  backlog was non-positive or the desired backlog
  945.                   was greater than PORT_BACKLOG_MAX.
  946.  
  947. See Also
  948.  
  949.   msg_send, port_status
  950. port_set_backup
  951.  
  952. #include <mach.h>
  953.  
  954. kern_return_t port_set_backup(task, primary, backup, previous)
  955.         task_t task;
  956.         port_name_t primary;
  957.         port_t backup;
  958.         port_t *previous;       /* out */
  959.  
  960.  
  961. Arguments
  962.  
  963.   task            The task owning the named port right.
  964.  
  965.   primary         task's name for the primary port.
  966.  
  967.   backup          The new backup port to be set.
  968.  
  969.   previous        The previous backup port.
  970.  
  971. Description
  972.  
  973.   A backup port provides a automatic mechanism to transfer port receive  rights
  974. to another task or thread in the event of a primary port's attempted death.  To
  975. be more precise, if a primary port has a backup port,  and  the  primary  would
  976. have been destroyed by the deallocation of its receive rights, then instead the
  977. receive  right  for  the  primary  port   is   sent   in   a   notify   message
  978. (NOTIFY_PORT_DESTROYED) to the backup port.
  979.  
  980.   A  newly allocated port does not have a backup port. The port_set_backup call
  981. changes the backup of the primary port.  The  target  task  must  hold  receive
  982. rights for the primary port. The caller supplies send rights for the new backup
  983. port to which notification will be sent. The caller receives  send  rights  for
  984. the  previous  backup  port  or  PORT_NULL if the target did not have a backup.
  985. port_set_backup works atomically, so that if one backup port is  exchanged  for
  986. another, the primary port is never left without a backup.
  987.  
  988.   When  the  primary  port  is sent in a notify message to the backup port, the
  989. primary port is left without a  backup  port.    When  the  task  receives  the
  990. notification  and  the  receive  rights to the primary port, it may wish to use
  991. port_set_backup to reestablish the same or a  different  backup  port.  If  the
  992. backup  port  is  destroyed  before  the primary, then the primary port is left
  993. without a backup. (A subsequent port_set_backup call would return PORT_NULL).
  994.  
  995. Returns
  996.  
  997.   KERN_SUCCESS    The call succeeded.
  998.  
  999.   KERN_NOT_RECEIVER
  1000.                   primary doesn't name receive rights in task.
  1001.  
  1002.   KERN_INVALID_ARGUMENT
  1003.                   task was invalid or primary or backup do  not  name  a  valid
  1004.                   port.
  1005.  
  1006. See Also
  1007.  
  1008.   port_deallocate
  1009. port_set_allocate
  1010.  
  1011. #include <mach.h>
  1012.  
  1013. kern_return_t port_set_allocate(task, set_name)
  1014.         task_t task;
  1015.         port_set_name_t *set_name;      /* out */
  1016.  
  1017.  
  1018. Arguments
  1019.  
  1020.   task            The task in which the new port set is created.
  1021.  
  1022.   set_name        The task's name for the new port set.
  1023.  
  1024. Description
  1025.  
  1026.   port_set_allocate causes a port set to be created for the specified task; the
  1027. resulting set's name is returned in set_name.  The new port set is empty.
  1028.  
  1029. Returns
  1030.  
  1031.   KERN_SUCCESS    The call succeeded.
  1032.  
  1033.   KERN_INVALID_ARGUMENT
  1034.                   task was invalid.
  1035.  
  1036.   KERN_RESOURCE_SHORTAGE
  1037.                   The kernel ran out of memory.
  1038.  
  1039. See Also
  1040.  
  1041.   port_set_deallocate
  1042. port_set_deallocate
  1043.  
  1044. #include <mach.h>
  1045.  
  1046. kern_return_t port_set_deallocate(task, set_name)
  1047.         task_t task;
  1048.         port_set_name_t set_name;
  1049.  
  1050.  
  1051. Arguments
  1052.  
  1053.   task            The task owning the port set to be destroyed.
  1054.  
  1055.   set_name        task's name for the doomed port set.
  1056.  
  1057. Description
  1058.  
  1059.   port_set_deallocate requests that the target task's port set be destroyed.
  1060.  
  1061.   If the port set is non-empty, any members are first removed.
  1062.  
  1063. Returns
  1064.  
  1065.   KERN_SUCCESS    The call succeeded.
  1066.  
  1067.   KERN_FAILURE    set_name  is  task's  port  set  used  for  implementing  the
  1068.                   obsolete port_enable and port_disable calls.
  1069.  
  1070.   KERN_INVALID_ARGUMENT
  1071.                   task was invalid or set_name does not name a valid port set.
  1072.  
  1073. See Also
  1074.  
  1075.   port_set_allocate
  1076. port_set_add
  1077.  
  1078. #include <mach.h>
  1079.  
  1080. kern_return_t port_set_add(task, set_name, port_name)
  1081.         task_t task;
  1082.         port_set_name_t set_name;
  1083.         port_name_t port_name;
  1084.  
  1085.  
  1086. Arguments
  1087.  
  1088.   task            The task owning the port set and port right.
  1089.  
  1090.   set_name        task's name for the port set.
  1091.  
  1092.   port_name       task's name for the port.
  1093.  
  1094. Description
  1095.  
  1096.   port_set_add moves the named port into the named port set.   task  must  have
  1097. receive rights for the port.
  1098.  
  1099.   If  the port is already a member of another port set, it is removed from that
  1100. set first.
  1101.  
  1102. Returns
  1103.  
  1104.   KERN_SUCCESS    The call succeeded.
  1105.  
  1106.   KERN_NOT_RECEIVER
  1107.                   port_name doesn't name receive rights in task.
  1108.  
  1109.   KERN_INVALID_ARGUMENT
  1110.                   task was invalid or set_name does not name a valid  port  set
  1111.                   or port_name does not name a valid port.
  1112.  
  1113. See Also
  1114.  
  1115.   port_set_remove
  1116. port_set_remove
  1117.  
  1118. #include <mach.h>
  1119.  
  1120. kern_return_t port_set_remove(task, port_name)
  1121.         task_t task;
  1122.         port_name_t port_name;
  1123.  
  1124.  
  1125. Arguments
  1126.  
  1127.   task            The task owning the receive rights and port set.
  1128.  
  1129.   port_name       task's name for the receive rights to be removed.
  1130.  
  1131. Description
  1132.  
  1133.   port_set_remove  removes  the  named  port  from  a port set.  task must have
  1134. receive rights for the port, and the port must be a member of a port set.
  1135.  
  1136. Returns
  1137.  
  1138.   KERN_SUCCESS    The call succeeded.
  1139.  
  1140.   KERN_NOT_RECEIVER
  1141.                   port_name doesn't name receive rights in task.
  1142.  
  1143.   KERN_NOT_IN_SET The port isn't a member of a set.
  1144.  
  1145.   KERN_INVALID_ARGUMENT
  1146.                   task was invalid or port_name does not name a valid port.
  1147.  
  1148. See Also
  1149.  
  1150.   port_set_add
  1151. port_set_status
  1152.  
  1153. #include <mach.h>
  1154.  
  1155. kern_return_t port_set_status(task, set_name, members, membersCnt)
  1156.         task_t task;
  1157.         port_set_name_t set_name;
  1158.         port_name_array_t *members;     /* out array */
  1159.         unsigned int *membersCnt;       /* out */
  1160.  
  1161.  
  1162. Arguments
  1163.  
  1164.   task            The task whose port set is queried.
  1165.  
  1166.   set_name        task's name for the port set.
  1167.  
  1168.   members         task's names for the port set's members.
  1169.  
  1170.   membersCnt      The number of port names returned.
  1171.  
  1172. Description
  1173.  
  1174.   port_set_status returns the members of a port set.  members is an array  that
  1175. is  automatically  allocated  when  the reply message is received. The user may
  1176. wish to vm_deallocate it when the data is no longer needed.
  1177.  
  1178. Returns
  1179.  
  1180.   KERN_SUCCESS    The call succeeded.
  1181.  
  1182.   KERN_INVALID_ARGUMENT
  1183.                   task was invalid or set_name does not name a valid port set.
  1184.  
  1185. See Also
  1186.  
  1187.   port_status
  1188. port_insert
  1189.  
  1190. #include <mach.h>
  1191.  
  1192. kern_return_t port_insert_send(task, my_port, his_name)
  1193.         task_t task;
  1194.         port_t my_port;
  1195.         port_name_t his_name;
  1196.  
  1197. kern_return_t port_insert_receive(task, my_port, his_name)
  1198.         task_t task;
  1199.         port_t my_port;
  1200.         port_name_t his_name;
  1201.  
  1202.  
  1203. Arguments
  1204.  
  1205.   task            The task getting the new rights.
  1206.  
  1207.   my_port         Rights supplied by the caller.
  1208.  
  1209.   his_name        The name by which task will know the new rights.
  1210.  
  1211. Description
  1212.  
  1213.   port_insert_send  and  port_insert_receive give a task rights with a specific
  1214. name.  If task already has rights named his_name, or has some  other  name  for
  1215. my_port, then the operation will fail.  his_name can't be a distinguished value
  1216. like PORT_NULL.
  1217.  
  1218.   port_insert_send inserts send rights, and port_insert_receive inserts receive
  1219. and ownership rights.
  1220.  
  1221. Returns
  1222.  
  1223.   KERN_SUCCESS    The call succeeded.
  1224.  
  1225.   KERN_NAME_EXISTS
  1226.                   task already has a right named his_name.
  1227.  
  1228.   KERN_FAILURE    task already has rights to my_port.
  1229.  
  1230.   KERN_INVALID_ARGUMENT
  1231.                   task was invalid or new_name was an invalid name.
  1232.  
  1233. Notes
  1234.  
  1235.   There is no way to insert just receive rights or just ownership rights.
  1236.  
  1237. See Also
  1238.  
  1239.   port_extract_send, port_extract_receive
  1240. port_extract
  1241.  
  1242. #include <mach.h>
  1243.  
  1244. kern_return_t port_extract_send(task, his_name, his_port)
  1245.         task_t task;
  1246.         port_name_t his_name;
  1247.         port_t *his_port;               /* out */
  1248.  
  1249. kern_return_t port_extract_receive(task, his_name, his_port)
  1250.         task_t task;
  1251.         port_name_t his_name;
  1252.         port_t *his_port;               /* out */
  1253.  
  1254.  
  1255. Arguments
  1256.  
  1257.   task            The task whose rights the caller takes.
  1258.  
  1259.   his_name        The name by which task knows the rights.
  1260.  
  1261.   his_port        Rights returned to the caller.
  1262.  
  1263. Description
  1264.  
  1265.   port_extract_send  and  port_extract_receive  remove task's rights for a port
  1266. and return the rights to the caller.  task is left with no rights for the port.
  1267.  
  1268.   port_extract_send extracts send rights; task can't have receive or  ownership
  1269. rights  for  the  named  port.  port_extract_receive extracts receive/ownership
  1270. rights, both of which task must hold.
  1271.  
  1272. Returns
  1273.  
  1274.   KERN_SUCCESS    The call succeeded.
  1275.  
  1276.   KERN_INVALID_ARGUMENT
  1277.                   task  was  invalid or his_name does not name a port for which
  1278.                   task has the required rights.
  1279.  
  1280. Notes
  1281.  
  1282.   There is no way to extract just receive rights or just ownership rights.
  1283.  
  1284. See Also
  1285.  
  1286.   port_insert_send, port_insert_receive
  1287. 4. Task and thread primitives
  1288.  
  1289.  
  1290.  
  1291. 4.1. Basic terms
  1292.   The MACH system separates the  traditional  notion  of  a  process  into  two
  1293. subconcepts:
  1294.  
  1295.    - Tasks  contain  the  capabilities,  namely  the port rights, resource
  1296.      limits, and address space of a running  entity.    Tasks  perform  no
  1297.      computation; they are a framework for running threads.
  1298.  
  1299.    - Threads  contain  the  minimal  processing  state  associated  with a
  1300.      computation, e.g. a program counter, a stack pointer, and  a  set  of
  1301.      registers.    A  thread  exists within exactly one task; however, one
  1302.      task may contain many threads.
  1303.  
  1304.   Tasks are the basic unit of protection.   All  threads  within  a  task  have
  1305. access to all of that task's capabilities, and are thus not protected from each
  1306. other.
  1307.  
  1308.   Threads are the basic unit of scheduling.  On a multiprocessor host, multiple
  1309. threads  from  one  task may be executing simultaneously (within the task's one
  1310. address space).  A thread may be in a suspended state (prevented from running),
  1311. or  in  a  runnable  state (may be running or be scheduled to run).  There is a
  1312. non-negative suspend count associated with each thread.  The suspend  count  is
  1313. zero for runnable threads and positive for suspended threads.
  1314.  
  1315.   Tasks may be suspended or resumed as a whole.  A thread may only execute when
  1316. both it and its task are  runnable.    Resuming  a  task  does  not  cause  all
  1317. component  threads  to  begin  executing,  but only those threads which are not
  1318. suspended.
  1319.  
  1320.   Both tasks and threads are represented by ports. These ports are  called  the
  1321. task  kernel  port  and  the thread kernel port. These are the handles that are
  1322. used in the task and thread kernel calls to identify to the kernel  which  task
  1323. or  thread  is  to  be affected by the call. The two primitives task_self() and
  1324. thread_self() return the task and  thread  ports  of  the  currently  executing
  1325. thread.  Tasks  may have access to the task and thread ports of other tasks and
  1326. threads. For example, a task that creates another task or thread gets access to
  1327. the new task or thread port.  Also any thread may pass access to these ports in
  1328. a message to another thread in the same or different task.  Having access to  a
  1329. task  or thread port enables the possessor to perform kernel calls on behalf of
  1330. that task or thread.  Access to a task's kernel port indirectly permits  access
  1331. to all threads within that task via the task_threads call; however, access to a
  1332. thread's kernel port does not currently imply access to its task port.
  1333.  
  1334.   In addition to their kernel ports, tasks and threads have a number of special
  1335. ports  associated  with  them.  In general these are ports that the kernel must
  1336. know about in order to communicate with the task  or  thread  in  a  structured
  1337. manner.
  1338.  
  1339.   There are three ports associated with a task in addition to its kernel port:
  1340.  
  1341.    - The  notify  port,  on  which  the  task  should  attempt  to receive
  1342.      notification of such kernel events as the destruction of  a  port  to
  1343.      which  it  has send rights.  The task has receive rights to this port
  1344.      and can get its value from the primitive task_notify().
  1345.  
  1346.    - The exception port, to  which  the  kernel  sends  messages  when  an
  1347.      exception  occurs.    Exceptions  are synchronous interuptions to the
  1348.      normal flow of program control caused by  the  program  itself.  They
  1349.      include  illegal  memory  accesses, protection violations, arithmetic
  1350.      exceptions, and hardware instructions intended to support  emulation,
  1351.      debugging  and/or  error  detection.  Some  of  these  exceptions are
  1352.      handled transparently by  the  operating  system  but  some  must  be
  1353.      reported  to the user program.  A default exception port is inherited
  1354.      from the parent at task creation time. This port can  be  changed  by
  1355.      the task or any one of its threads in order to take an active role in
  1356.      handling exceptions.
  1357.  
  1358.    - The bootstrap port, to which a new task can send a message that  will
  1359.      return  any  other  system  service  ports  that  the task needs, for
  1360.      example a port to the Network Nameserver or the Environment  Manager.
  1361.      Send  rights  to  this  port  are  inherited  from the parent at task
  1362.      creation.  This is the one port that the  kernel  does  not  actually
  1363.      use, it just makes it available to a new task.
  1364.  
  1365.   There are two ports associated with a thread in addition to its kernel port:
  1366.  
  1367.    - The  thread reply port, which may be used for initial messages from a
  1368.      parent or  for  early  remote  procedure  calls.  The  thread_reply()
  1369.      primitive returns receive rights to this port.
  1370.  
  1371.    - The  thread exception port, to which kernel sends exceptions occuring
  1372.      in this thread. This port is set to PORT_NULL at thread creation  and
  1373.      can  be  set  subsequently by the call thread_set_exception_port.  As
  1374.      long as the thread exception port is  PORT_NULL  the  task  exception
  1375.      port will be used instead.
  1376.  
  1377.  
  1378.  
  1379. 4.2. Access to Tasks: Terminology
  1380.   In  this and following sections, calls are described which may manipulate the
  1381. state of a task.  Although some of the  descriptions  may  refer  to  tasks  as
  1382. performing these calls, it is in fact some thread within a task which makes any
  1383. call.
  1384.  
  1385.   Furthermore, any thread within any task which holds  access  rights  to  that
  1386. task  (i.e.  task  kernel  port)  may  perform  calls  which  take a task as an
  1387. argument.  Customarily, only threads within a task will manipulate that  task's
  1388. state, but this custom is not enforced by the MACH kernel. Debugger tasks are a
  1389. notable exception to this rule.  Similarly, access to a thread is controlled by
  1390. access to its thread kernel port.
  1391. task_create
  1392.  
  1393. #include <mach.h>
  1394.  
  1395. kern_return_t task_create(parent_task, inherit_memory,
  1396.                                  child_task)
  1397.         task_t          parent_task
  1398.         boolean_t       inherit_memory;
  1399.         task_t          *child_task;    /* out */
  1400.  
  1401.  
  1402. Arguments
  1403.  
  1404.   target_task     The task from which the child's capabilities are drawn.
  1405.  
  1406.   inherit_memory  If  set,  the  child  task's  address space is built from the
  1407.                   parent task  according  to  its  memory  inheritance  values;
  1408.                   otherwise, the child task is given an empty address space.
  1409.  
  1410.   child_task      The new task.
  1411.  
  1412. Description
  1413.  
  1414.   task_create   creates  a  new  task  from  parent_task;  the  resulting  task
  1415. (child_task) acquires shared or copied parts of the parent's address space (see
  1416. vm_inherit).  The child task initially contains no threads.
  1417.  
  1418.   The  child  task gets the four special ports created or copied for it at task
  1419. creation. The task_kernel_port is created and send rights for it are  given  to
  1420. the  child  and  returned  to  the  caller. The task_notify_port is created and
  1421. receive, ownership and send rights for it are given to the  child.  The  caller
  1422. has  no  access to it.  The task_bootstrap_port and the task_exception_port are
  1423. inherited from the parent task.  The new task can  get  send  rights  to  these
  1424. ports with the call task_get_special_port.
  1425.  
  1426. Returns
  1427.  
  1428.   KERN_SUCCESS    A new task has been created.
  1429.  
  1430.   KERN_INVALID_ARGUMENT
  1431.                   parent_task is not a valid task port.
  1432.  
  1433.   KERN_RESOURCE_SHORTAGE
  1434.                   Some critical kernel resource is unavailable.
  1435.  
  1436. See Also
  1437.  
  1438.   task_terminate,  task_suspend, task_resume, task_special_ports, task_threads,
  1439. thread_create, thread_resume, vm_inherit
  1440.  
  1441. Notes
  1442.  
  1443.   Not implemented yet. Use fork.
  1444. task_terminate
  1445.  
  1446. #include <mach.h>
  1447.  
  1448. kern_return_t task_terminate(target_task)
  1449.         task_t          target_task;
  1450.  
  1451.  
  1452. Arguments
  1453.  
  1454.   target_task     The task to be destroyed.
  1455.  
  1456. Description
  1457.  
  1458.   task_terminate destroys  the  task  specified  by  target_task  and  all  its
  1459. threads.  All  resources that are used only by this task are freed. Any port to
  1460. which this task has receive and ownership rights is destroyed.
  1461.  
  1462. Returns
  1463.  
  1464.   KERN_SUCCESS    The task has been killed.
  1465.  
  1466.   KERN_INVALID_ARGUMENT
  1467.                   target_task is not a task.
  1468.  
  1469. See Also
  1470.  
  1471.   task_create, task_suspend, task_resume, thread_terminate, thread_suspend
  1472.  
  1473. Notes
  1474.  
  1475.   Not implemented yet.
  1476. task_suspend
  1477.  
  1478. #include <mach.h>
  1479.  
  1480. kern_return_t task_suspend(target_task)
  1481.         task_t          target_task;
  1482.  
  1483.  
  1484. Arguments
  1485.  
  1486.   target_task     The task to be suspended.
  1487.  
  1488. Description
  1489.  
  1490.   Increments  the  task's  suspend  count and stops all threads in the task. As
  1491. long as the suspend count is positive newly created threads will not run.  This
  1492. call does not return until all threads are suspended.
  1493.  
  1494.   The count may become greater than one, with the effect that it will take more
  1495. than one resume call to restart the task.
  1496.  
  1497. Returns
  1498.  
  1499.   KERN_SUCCESS    The task has been suspended.
  1500.  
  1501.   KERN_INVALID_ARGUMENT
  1502.                   target_task is not a task.
  1503.  
  1504. See Also
  1505.  
  1506.   task_create, task_terminate, task_resume, task_info,  thread_suspend
  1507. task_resume
  1508.  
  1509. #include <mach.h>
  1510.  
  1511. kern_return_t task_resume(target_task)
  1512.         task_t          target_task;
  1513.  
  1514.  
  1515. Description
  1516.  
  1517.   Decrements  the  task's  suspend  count. If it becomes zero, all threads with
  1518. zero suspend counts in the task are resumed. The count may not become negative.
  1519.  
  1520. Arguments
  1521.  
  1522.   target_task     The task to be resumed.
  1523.  
  1524. Returns
  1525.  
  1526.   KERN_SUCCESS    The task has been resumed.
  1527.  
  1528.   KERN_FAILURE    The suspend count is already at zero.
  1529.  
  1530.   KERN_INVALID_ARGUMENT
  1531.                   target_task is not a task.
  1532.  
  1533. See Also
  1534.  
  1535.   task_create,   task_terminate,   task_suspend,   task_info,   thread_suspend,
  1536. thread_resume, thread_info
  1537. task_special_ports
  1538.  
  1539. #include <mach.h>
  1540.  
  1541. kern_return_t task_get_special_port(task, which_port, special_port)
  1542.         task_t          task;
  1543.         int             which_port;
  1544.         port_t          *special_port;  /* out */
  1545.  
  1546. kern_return_t task_set_special_port(task, which_port, special_port)
  1547.         task_t          task;
  1548.         int             which_port;
  1549.         port_t          special_port;
  1550.  
  1551.  
  1552. task_t task_self()
  1553.  
  1554. port_t task_notify()
  1555.  
  1556.  
  1557.  
  1558. Arguments
  1559.  
  1560.   task            The task for which to get the port
  1561.  
  1562.   which_port      the port that  is  requested.  Is  one  of  TASK_NOTIFY_PORT,
  1563.                   TASK_BOOTSTRAP_PORT, TASK_EXCEPTION_PORT.
  1564.  
  1565.   special_port    the value of the port that is being requested or being set.
  1566.  
  1567. Description
  1568.  
  1569.   get_special_port returns send rights to one of a set of special ports for the
  1570. task specified by task.  In the case of the task's  own  task_notify_port,  the
  1571. task also gets receive and ownership rights.
  1572.  
  1573.   set_special_port sets one of a set of special ports for the task specified by
  1574. task.
  1575.  
  1576.   task_self returns the port to which kernel calls for the currently  executing
  1577. thread  should  be directed.  Currently, task_self returns the task kernel port
  1578. which is a port for which the kernel has receive rights and which  it  uses  to
  1579. identify  a  task. In the future it may be possible for one task to interpose a
  1580. port as another's task's kernel port. At that time, task_self will still return
  1581. the  port  to which the executing thread should direct kernel calls, but it may
  1582. no longer be a port on which the kernel has receive rights.
  1583.  
  1584.   If one task, the controller, has send access to the kernel  port  of  another
  1585. task,  the subject task, then the controller task can perform kernel operations
  1586. for the subject task. Normally only the task itself and the task  that  created
  1587. it  will  have  access to the task kernel port, but any task may pass rights to
  1588. its kernel port to any other task.
  1589.  
  1590.   task_notify returns receive, ownership and send rights  to  the  notify  port
  1591. associated with the task to which the executing thread belongs. The notify port
  1592. is a port on which the task should receive notification of such  kernel  events
  1593. of the destruction of a port to which it has send rights.
  1594.  
  1595.   The other special ports associated with a task are the bootstrap port and the
  1596. exception port. The bootstrap port is a port to  which  a  thread  may  send  a
  1597. message  requesting  other  system  service ports. This port is not used by the
  1598. kernel. The task's exception port is the port to which messages are sent by the
  1599. kernel  when  an  exception  occurs and the thread causing the exception has no
  1600. exception port of its own.
  1601.  
  1602.   Within the C environment, task_self and task_notify are implemented as macros
  1603. which  execute  the  system traps the first time and thereafter return a cached
  1604. value for the ports. Thus it is unnecessary for a  programmer  to  cache  these
  1605. variables himself and such caching may interfere with the future implementation
  1606. of port interposition.
  1607.  
  1608.   The following macros to call task_set/get_special_port for  a  specific  port
  1609. are     defined     in    <mach/task_special_ports.h>:    task_get_notify_port,
  1610. task_set_notify_port,     task_get_exception_port,     task_set_exception_port,
  1611. task_get_bootstrap_port and task_set_bootstrap_port.
  1612.  
  1613. Returns
  1614.  
  1615.   KERN_SUCCESS    The port was returned or set.
  1616.  
  1617.   KERN_INVALID_ARGUMENT
  1618.                   task is not a task or which_port is an invalid port selector.
  1619.  
  1620. See Also
  1621.  
  1622.   thread_special_ports,mach_init,task_create
  1623.  
  1624. Notes
  1625.  
  1626.   The call on the bootstrap port to get  system  service  ports  has  not  been
  1627. implemented yet.
  1628.  
  1629.   TASK_KERNEL_PORT  may be added to the set of ports that task_set_special_port
  1630. accepts.
  1631. task_info
  1632.  
  1633. #include <mach.h>
  1634.  
  1635. /* the definition of task_info_t from mach.h - mach/task_info.h is */
  1636.  
  1637. typedef int     *task_info_t;           /* variable length array of int */
  1638.  
  1639. /* currently the only interpretation of info is */
  1640.  
  1641.    struct task_basic_info {
  1642.         int             suspend_count;  /* suspend count for task */
  1643.         int             base_priority;  /* base scheduling priority */
  1644.         vm_size_t       virtual_size;   /* number of virtual pages */
  1645.         vm_size_t       resident_size;  /* number of resident pages */
  1646.         time_value_t    user_time;      /* total user run time for
  1647.                                            terminated threads */
  1648.         time_value_t    system_time;    /* total system run time for
  1649.                                            terminated threads */
  1650.    };
  1651. typedef struct task_basic_info          *task_basic_info_t;
  1652.  
  1653. kern_return_t task_info(target_task, flavor, task_info, task_infoCnt)
  1654.         task_t          target_task;
  1655.         int             flavor;
  1656.         task_info_t     task_info;      /* in and out */
  1657.         unsigned int    *task_infoCnt;  /* in and out */
  1658.  
  1659.  
  1660. Arguments
  1661.  
  1662.   target_task     The task to be affected.
  1663.  
  1664.   flavor          The type of statistics  that  are  wanted.    Currently  only
  1665.                   TASK_BASIC_INFO is implemented.
  1666.  
  1667.   task_info       Statistics about the task specified by target_task.
  1668.  
  1669.   task_infoCnt    Size     of    the    info    structure.    Currently    only
  1670.                   TASK_BASIC_INFO_COUNT is implemented.
  1671.  
  1672. Description
  1673.  
  1674.   Returns the selected information array for a task, as  specified  by  flavor.
  1675. task_info  is  an  array of integers that is supplied by the caller, and filled
  1676. with specified information. task_infoCnt is supplied as the maximum  number  of
  1677. integers  in task_info. On return, it contains the actual number of integers in
  1678. task_info.
  1679.  
  1680.   Currently there is only  one  flavor  of  information  which  is  defined  by
  1681. TASK_BASIC_INFO. Its size is defined by TASK_BASIC_INFO_COUNT.
  1682.  
  1683. Returns
  1684.  
  1685.   KERN_SUCCESS    The call succeeded.
  1686.  
  1687.   KERN_INVALID_ARGUMENT
  1688.                   target_task is not a task or flavor is not recognized.
  1689.  
  1690.   MIG_ARRAY_TOO_LARGE
  1691.                   Returned  info array is too large for task_info. task_info is
  1692.                   filled as much as possible.    task_infoCnt  is  set  to  the
  1693.                   number  of  elements  that  would  be  returned if there were
  1694.                   enough room.
  1695.  
  1696. See Also
  1697.  
  1698.   task_special_ports, task_threads, thread_info, thread_state
  1699. task_threads
  1700.  
  1701. #include <mach.h>
  1702.  
  1703. kern_return_t task_threads(target_task, thread_list, thread_count)
  1704.         task_t          target_task;
  1705.         thread_array_t  *thread_list;   /* out, ptr to array */
  1706.         int             *thread_count;  /* out */
  1707.  
  1708.  
  1709. Arguments
  1710.  
  1711.   target_task     The task to be affected.
  1712.  
  1713.   thread_list     The  set  of  threads  contained   within   target_task;   no
  1714.                   particular ordering is guaranteed.
  1715.  
  1716.   thread_count    The number of threads in the thread_list.
  1717.  
  1718. Description
  1719.  
  1720.   task_threads gets send rights to the kernel port for each thread contained in
  1721. target_task. thread_list is an array that is created as a result of this  call.
  1722. The  caller  may  wish  to  vm_deallocate this array when the data is no longer
  1723. needed.
  1724.  
  1725. Returns
  1726.  
  1727.   KERN_SUCCESS    The call succeeded.
  1728.  
  1729.   KERN_INVALID_ARGUMENT
  1730.                   target_task is not a task.
  1731.  
  1732. See Also
  1733.  
  1734.   thread_create, thread_terminate, thread_suspend
  1735. thread_create
  1736.  
  1737. #include <mach.h>
  1738.  
  1739. kern_return_t thread_create(parent_task, child_thread)
  1740.         task_t          parent_task;
  1741.         thread_t        *child_thread;  /* out */
  1742.  
  1743.  
  1744. Description
  1745.  
  1746.   thread_create  creates a new thread within the task specified by parent_task.
  1747. The new thread has no processor state, and has a suspend count of 1.  To get  a
  1748. new  thread  to  run,  first  thread_create  is  called to get the new thread's
  1749. identifier,(child_thread). Then thread_set_state is called to set  a  processor
  1750. state,  and  finally  thread_resume  is  called  to get the thread scheduled to
  1751. execute.
  1752.  
  1753.   When the thread is created send rights to its thread kernel port are given to
  1754. it and returned to the caller in child_thread.  The new thread's exception port
  1755. is set to PORT_NULL.
  1756.  
  1757. Arguments
  1758.  
  1759.   parent_task     The task which is to contain the new thread.
  1760.  
  1761.   child_thread    The new thread.
  1762.  
  1763. Returns
  1764.  
  1765.   KERN_SUCCESS    A new thread has been created.
  1766.  
  1767.   KERN_INVALID_ARGUMENT
  1768.                   parent_task is not a valid task.
  1769.  
  1770.   KERN_RESOURCE_SHORTAGE
  1771.                   Some critical kernel resource is not available.
  1772.  
  1773. See Also
  1774.  
  1775.   task_create, task_threads, thread_terminate,  thread_suspend,  thread_resume,
  1776. thread_special_ports, thread_set_state
  1777. thread_terminate
  1778.  
  1779. #include <mach.h>
  1780.  
  1781. kern_return_t thread_terminate(target_thread)
  1782.         thread_t        target_thread;
  1783.  
  1784.  
  1785. Arguments
  1786.  
  1787.   target_thread   The thread to be destroyed.
  1788.  
  1789. Description
  1790.  
  1791.   thread_terminate destroys the thread specified by target_thread.
  1792.  
  1793. Returns
  1794.  
  1795.   KERN_SUCCESS    The thread has been killed.
  1796.  
  1797.   KERN_INVALID_ARGUMENT
  1798.                   target_thread is not a thread.
  1799.  
  1800. See Also
  1801.  
  1802.   task_terminate, task_threads, thread_create, thread_resume, thread_suspend
  1803. thread_suspend
  1804.  
  1805. #include <mach.h>
  1806.  
  1807. kern_return_t thread_suspend(target_thread);
  1808.         thread_t        target_thread;
  1809.  
  1810.  
  1811. Arguments
  1812.  
  1813.   target_thread   The thread to be suspended.
  1814.  
  1815. Description
  1816.  
  1817.   Increments the thread's suspend count and prevents the thread from  executing
  1818. any  more  user level instructions. In this context a user level instruction is
  1819. either a machine instruction executed in user mode or a system trap instruction
  1820. including page faults.  Thus if a thread is currently executing within a system
  1821. trap the kernel code may continue to execute until it reaches the system return
  1822. code  or  it may supend within the kernel code. In either case, when the thread
  1823. is resumed the system trap will return. This could cause unpredictible  results
  1824. if  the  user  did  a  suspend and then altered the user state of the thread in
  1825. order to change its direction upon a resume. The call thread_abort is  provided
  1826. to allow the user to abort any system call that is in progress in a predictable
  1827. way.
  1828.  
  1829.   The suspend count may become greater than one with the effect  that  it  will
  1830. take more than one resume call to restart the thread.
  1831.  
  1832. Returns
  1833.  
  1834.   KERN_SUCCESS    The thread has been suspended.
  1835.  
  1836.   KERN_INVALID_ARGUMENT
  1837.                   target_thread is not a thread.
  1838.  
  1839. See Also
  1840.  
  1841.   task_suspend,   task_resume,   thread_info,   thread_state,    thread_resume,
  1842. thread_terminate, thread_abort
  1843. thread_resume
  1844.  
  1845. #include <mach.h>
  1846.  
  1847. kern_return_t thread_resume(target_thread)
  1848.         thread_t        target_thread;
  1849.  
  1850.  
  1851. Arguments
  1852.  
  1853.   target_thread   The thread to be resumed.
  1854.  
  1855. Description
  1856.  
  1857.   Decrements  the threads's suspend count. If the count becomes zero the thread
  1858. is resumed. If it is still positive, the thread is left suspended. The  suspend
  1859. count may not become negative.
  1860.  
  1861. Returns
  1862.  
  1863.   KERN_SUCCESS    The thread has been resumed.
  1864.  
  1865.   KERN_FAILURE    The suspend count is already zero.
  1866.  
  1867.   KERN_INVALID_ARGUMENT
  1868.                   target_thread is not a thread.
  1869.  
  1870. See Also
  1871.  
  1872.   task_suspend,  task_resume  thread_info,   thread_create,   thread_terminate,
  1873. thread_suspend
  1874. thread_abort
  1875.  
  1876. #include <mach.h>
  1877.  
  1878. kern_return_t thread_abort(target_thread)
  1879.         thread_t        target_thread;
  1880.  
  1881.  
  1882. Arguments
  1883.  
  1884.   target_thread   The thread to be interrupted.
  1885.  
  1886. Description
  1887.  
  1888.   thread_abort  aborts the kernel primitives: msg_send, msg_receive and msg_rpc
  1889. and page-faults,  making  the  call  return  a  code  indicating  that  it  was
  1890. interrupted.    The  call  is  interrupted  whether  or not the thread (or task
  1891. containing it) is currently suspended.  If it is supsended, the thread receives
  1892. the interupt when it is resumed.  This call also aborts any priority depression
  1893. caused by the DEPRESS option to thread_switch.
  1894.  
  1895.   A thread will retry an aborted page-fault if its state is not modified before
  1896. it   is  resumed.    Msg_send  returns  SEND_INTERRUPTED;  msg_receive  returns
  1897. RCV_INTERRUPTED; msg_rpc returns either  SEND_INTERRUPTED  or  RCV_INTERRUPTED,
  1898. depending on which half of the RPC was interrupted.
  1899.  
  1900.   The  main  reason  for  this primitive is to allow one thread to cleanly stop
  1901. another thread in a manner that will allow the future execution of  the  target
  1902. thread  to  be controlled in a predictable way. thread_suspend keeps the target
  1903. thread from executing any further instructions at the user level, including the
  1904. return  from  a  system  call.  thread_get/set_state  allows the examination or
  1905. modification of the user state of a target  thread.  However,  if  a  suspended
  1906. thread  was  executing  within  a system call, it also has associated with it a
  1907. kernel state. This kernel state can not be modified  by  thread_set_state  with
  1908. the  result that when the thread is resumed the system call may return changing
  1909. the user state and possibly user memory.  thread_abort aborts the  kernel  call
  1910. from  the  target  thread's point of view by resetting the kernel state so that
  1911. the thread will resume execution at the system call return with the return code
  1912. value  set  to one of the interrupted codes. The system call itself will either
  1913. be entirely completed or entirely aborted, depending on the precise  moment  at
  1914. which the abort was received.  Thus if the thread's user state has been changed
  1915. by thread_set_state, it will not be modified by any unexpected system call side
  1916. effects.
  1917.  
  1918.   For example to simulate a Unix signal, the following sequence of calls may be
  1919. used:
  1920.  
  1921.   thread_suspend Stops the thread
  1922.  
  1923.   thread_abort Interrupts any system call in progress, setting the return value
  1924. to  'interrupted'.    Since  the  thread is stopped, it will not return to user
  1925. code.
  1926.  
  1927.   thread_set_state Alters thread's state to simulate a procedure  call  to  the
  1928. signal handler
  1929.  
  1930.   thread_resume Resumes execution at the signal handler.  If the thread's stack
  1931. has been correctly set up, the thread may  return  to  the  interrupted  system
  1932. call.
  1933.  
  1934.   (of course, the code to push an extra stack frame and change the registers is
  1935. VERY machine-dependent.)
  1936.  
  1937.   Calling thread_abort on a non-suspended thread is pretty risky, since  it  is
  1938. very  difficult  to  know exactly what system trap, if any, the thread might be
  1939. executing and whether  an  interrupt  return  would  cause  the  thread  to  do
  1940. something useful.
  1941.  
  1942. Returns
  1943.  
  1944.   KERN_SUCCESS    The thread received an interrupt
  1945.  
  1946.   KERN_INVALID_ARGUMENT
  1947.                   target_thread is not a thread.
  1948.  
  1949. See Also
  1950.  
  1951.   thread_info, thread_state, thread_terminate, thread_suspend, thread_switch
  1952. thread_special_ports
  1953.  
  1954. #include <mach.h>
  1955.  
  1956. kern_return_t thread_get_special_port(thread, which_port, special_port)
  1957.         thread_t        thread;
  1958.         int             which_port;
  1959.         port_t          *special_port;
  1960.  
  1961. kern_return_t thread_set_special_port(thread, which_port, special_port)
  1962.         thread_t        thread;
  1963.         int             which_port;
  1964.         port_t          special_port;
  1965.  
  1966. thread_t thread_self()
  1967.  
  1968. port_t thread_reply()
  1969.  
  1970.  
  1971. Arguments
  1972.  
  1973.   thread          The thread for which to get the port
  1974.  
  1975.   which_port      the port that is requested. Is one  of  THREAD_REPLY_PORT  or
  1976.                   THREAD_EXCEPTION_PORT.
  1977.  
  1978.   special_port    the value of the port that is being requested or being set.
  1979.  
  1980. Description
  1981.  
  1982.   get_special_port returns send rights to one of a set of special ports for the
  1983. thread  specified  by  thread.  In  the  case  of  getting  the  thread's   own
  1984. thread_reply_port, receive and ownership rights are also given to the thread.
  1985.  
  1986.   set_special_port  sets one of a set of special ports for the thread specified
  1987. by thread.
  1988.  
  1989.   thread_self returns  the  port  to  which  kernel  calls  for  the  currently
  1990. executing thread should be directed.  Currently, thread_self returns the thread
  1991. kernel port which is a port for which the kernel has receive rights  and  which
  1992. it  uses  to identify a thread. In the future it may be possible for one thread
  1993. to  interpose  a  port  as  another's  thread's  kernel  port.  At  that  time,
  1994. thread_self  will  still  return  the port to which the executing thread should
  1995. direct kernel calls, but it may no longer be a port on  which  the  kernel  has
  1996. receive rights.
  1997.  
  1998.   If  one thread, the controller, has send access to the kernel port of another
  1999. thread, the subject thread, then  the  controller  thread  can  perform  kernel
  2000. operations  for  the  subject  thread.  Normally only the thread itself and its
  2001. parent task will have access to the thread kernel port, but any thread may pass
  2002. rights to its kernel port to any other thread.
  2003.  
  2004.   thread_reply  returns receive, ownership and send rights to the reply port of
  2005. the calling thread. The reply port is a port to which the  thread  has  receive
  2006. rights.  It  is used to receive any initialization messages and as a reply port
  2007. for early remote procedure calls.
  2008.  
  2009.   The following macros to call thread_get/set_special_port for a specific  port
  2010. are    defined    in    <mach/thread_special_ports.h>:   thread_get_reply_port,
  2011. thread_set_reply_port, thread_get_exception_port and thread_set_exception_port.
  2012.  
  2013.   A thread also has access to its task's special ports.
  2014.  
  2015. Returns
  2016.  
  2017.   KERN_SUCCESS    The port was returned or set.
  2018.  
  2019.   KERN_INVALID_ARGUMENT
  2020.                   thread  is  not  a  thread  or  which_port is an invalid port
  2021.                   selector.
  2022.  
  2023. See Also
  2024.  
  2025.   task_special_ports,thread_create
  2026.  
  2027. Notes
  2028.  
  2029.   THREAD_KERNEL_PORT   may   be   added   to   the   set    of    ports    that
  2030. thread_set_special_port accepts.
  2031. thread_info
  2032.  
  2033. #include <mach.h>
  2034.  
  2035. /* the definition of thread_info_data_t from mach.h - mach/thread_info.h is */
  2036.  
  2037.    typedef      int     *thread_info_t; /* variable length array of int */
  2038.  
  2039. /* only current interpretation of thread_info */
  2040.  
  2041.    struct thread_basic_info {
  2042.         time_value_t    user_time;      /* user run time */
  2043.         time_value_t    system_time;    /* system run time */
  2044.         int             cpu_usage;      /* scaled cpu usage percentage */
  2045.         int             base_priority;  /* base scheduling priority */
  2046.         int             cur_priority;   /* current scheduling priority */
  2047.         int             run_state;      /* run state (see below) */
  2048.         int             flags;          /* various flags (see below) */
  2049.         int             suspend_count;  /* suspend count for thread */
  2050.         long            sleep_time;     /* number of seconds that thread
  2051.                                            has been sleeping */
  2052.    };
  2053.    typedef struct thread_basic_info     *thread_basic_info_t;
  2054.  
  2055.    The possible values of the run_state field are:
  2056.         TH_STATE_RUNNING, thread is running normally
  2057.         TH_STATE_STOPPED, thread is suspended
  2058.         TH_STATE_WAITING, thread is waiting normally
  2059.         TH_STATE_UNINTERRUPTIBLE, thread is in an uninterruptible wait
  2060.         TH_STATE_HALTED, thread is halted at a clean point
  2061.  
  2062.    The possible values of the flags field are:
  2063.         TH_FLAGS_SWAPPED, thread is swapped out
  2064.         TH_FLAGS_IDLE, thread is an idle thread
  2065.  
  2066.  
  2067. kern_return_t thread_info(target_thread, flavor, thread_info,
  2068.                                 thread_infoCnt)
  2069.         thread_t                target_thread;
  2070.         int                     flavor;
  2071.         thread_info_t           thread_info;    /* in and out */
  2072.         unsigned int            *thread_infoCnt;  /* in and out */
  2073.  
  2074.  
  2075. Arguments
  2076.  
  2077.   target_thread   The thread to be affected.
  2078.  
  2079.   flavor          The  type  of  statistics  that  are  wanted.  Currently only
  2080.                   THREAD_BASIC_INFO is implemented.
  2081.  
  2082.   thread_info     Statistics about the thread specified by target_thread.
  2083.  
  2084.   thread_infoCnt  Size    of    the    info    structure.    Currently     only
  2085.                   THREAD_BASIC_INFO_COUNT is implemented.
  2086.  
  2087. Description
  2088.  
  2089.   Returns  the selected information array for a thread, as specified by flavor.
  2090. thread_info is an array of integers that is supplied by the caller and returned
  2091. filled  with  specified  information. thread_infoCnt is supplied as the maximum
  2092. number of integers in thread_info. On return, it contains the actual number  of
  2093. integers in thread_info.
  2094.  
  2095.   Currently  there  is  only  one  flavor  of  information  which is defined by
  2096. THREAD_BASIC_INFO. Its size is defined by THREAD_BASIC_INFO_COUNT.
  2097.  
  2098. Returns
  2099.  
  2100.   KERN_SUCCESS    The call succeeded.
  2101.  
  2102.   KERN_INVALID_ARGUMENT
  2103.                   target_thread is not a thread or flavor is not recognized.
  2104.  
  2105.   MIG_ARRAY_TOO_LARGE
  2106.                   Returned info array is too large for thread_info. thread_info
  2107.                   is  filled as much as possible.  thread_infoCnt is set to the
  2108.                   number of elements that would have  been  returned  if  there
  2109.                   were enough room.
  2110.  
  2111. See Also
  2112.  
  2113.   thread_special_ports, task_threads, task_info, thread_state
  2114. thread_state
  2115.  
  2116. #include <mach.h>
  2117.  
  2118. kern_return_t thread_get_state(target_thread, flavor, old_state,
  2119.                                 old_stateCnt)
  2120.         thread_t                target_thread;
  2121.         int                     flavor;
  2122.         thread_state_data_t     old_state;      /* in and out */
  2123.         unsigned int            *old_stateCnt;  /* in and out */
  2124.  
  2125. kern_return_t thread_set_state(target_thread, flavor, new_state,
  2126.                                 new_stateCnt)
  2127.         thread_t                target_thread;
  2128.         int                     flavor;
  2129.         thread_state_data_t     new_state;
  2130.         unsigned int            new_stateCnt;
  2131.  
  2132.  
  2133. Arguments
  2134.  
  2135.   target_thread   thread to get or set the state for.
  2136.  
  2137.   flavor          The  type  of state that is to be manipulated. Currently must
  2138.                   be   one   of   the   following   values:   VAX_THREAD_STATE,
  2139.                   ROMP_THREAD_STATE,                     SUN_THREAD_STATE_REGS,
  2140.                   SUN_THREAD_STATE_FPA
  2141.  
  2142.   new_state       an array of state information
  2143.  
  2144.   old_state       an array of state information
  2145.  
  2146.   new_stateCnt    the size of the state information array.  Currently  must  be
  2147.                   one   of   the   following   values:  VAX_THREAD_STATE_COUNT,
  2148.                   ROMP_THREAD_STATE_COUNT,         SUN_THREAD_STATE_REGS_COUNT,
  2149.                   SUN_THREAD_STATE_FPA_COUNT
  2150.  
  2151.   old_stateCnt    same as new_stateCnt
  2152.  
  2153. Description
  2154.  
  2155.   thread_get_state  returns the state component (e.g. the machine registers) of
  2156. target_thread as specified by flavor.  The old_state is an  array  of  integers
  2157. that  is  provided  by  the  caller  and  returned  filled  with  the specified
  2158. information. old_stateCnt is input set to the maximum  number  of  integers  in
  2159. old_state and returned equal to the actual number of integers in old_state.
  2160.  
  2161.   thread_set_state  sets  the  state  component (e.g. the machine registers) of
  2162. target_thread as specified by flavor.  The new_state is an array  of  integers.
  2163. new_stateCnt  is  the  number  of  elements  in  new_state.  The  entire set of
  2164. registers is reset. This will do unpredictable things if target_thread  is  not
  2165. suspended.
  2166.  
  2167.   target_thread may not be thread_self for either of these calls.
  2168.  
  2169.   The    definition    of    the    state    structures   can   be   found   in
  2170. <machine/thread_status.h>
  2171.  
  2172. Returns
  2173.  
  2174.   KERN_SUCCESS    The state has been set or returned
  2175.  
  2176.   MIG_ARRAY_TOO_LARGE
  2177.                   Returned   state  is  too  large  for  the  new_state  array.
  2178.                   new_state is filled in as much as possible  and  new_stateCnt
  2179.                   is  set  to  the number of elements that would be returned if
  2180.                   there were enough room.
  2181.  
  2182.   KERN_INVALID_ARGUMENT
  2183.                   target_thread  is not a thread or is thread_self or flavor is
  2184.                   unrecogized for this machine.
  2185.  
  2186. See Also
  2187.  
  2188.   task_info, thread_info
  2189. 5. Virtual memory primitives
  2190.  
  2191.  
  2192.  
  2193. 5.1. Basic terms
  2194.   Each MACH task has a large virtual address space  within  which  its  threads
  2195. execute.  A virtual address space is divided into fixed size pages. The size of
  2196. a virtual page is set at system initialization  and  may  differ  on  different
  2197. machines.  A  virtual address space may be sparse, that is, there may be ranges
  2198. of addresses which are not allocated followed by ranges that are allocated.
  2199.  
  2200.   A task may allocate virtual memory in its address space; physical memory will
  2201. be acquired only when necessary, and seldom-used memory may be paged to backing
  2202. storage.
  2203.  
  2204.   A region of an address space is that  memory  associated  with  a  continuous
  2205. range  of  addresses;  that  is,  a start address and an end address.  The MACH
  2206. kernel will extend regions to include entire virtual  memory  pages  containing
  2207. the  first  and  last  address  in a specified range.  Regions consist of pages
  2208. which have different protection or inheritance characteristics.
  2209.  
  2210.   A task may protect the virtual pages of its address  space  to  allow/prevent
  2211. access  to that memory.  The current protection is used to determine the access
  2212. rights of an executing thread.  In addition, a maximum protection value  limits
  2213. the current protection.
  2214.  
  2215.   A  task  may  specify  that  pages of its address space be inherited by child
  2216. tasks in one of three ways: shared, copied, or  absent.    Inheritance  may  be
  2217. changed  at  any  time;  only  at  the  time  of  task  creation is inheritance
  2218. information used. The only way two MACH  tasks  can  share  the  same  physical
  2219. memory  is  for  one  of  the  tasks  to inherit shared access to memory from a
  2220. parent.  When a child task inherits memory from a  parent,  it  gets  the  same
  2221. protection on that memory that its parent had.
  2222.  
  2223.   Protection  and  inheritance  is  attached to a task's address space, not the
  2224. physical memory contained in that address space.  Tasks which share memory  may
  2225. specify different protection or inheritance for their shared regions.
  2226.  
  2227.   Physical  pages in an address space have paging objects associated with them.
  2228. These objects identify the backing storage to be used when a page is to be read
  2229. in as the result of a reference or written to in order to free physical memory.
  2230. A paging  object  is  identified  outside  of  the  kernel  by  an  unforgeable
  2231. identifier (implemented as a port which is only used for identification and not
  2232. message transmission), and inside the kernel by a data transmission port,  that
  2233. will respond to get and put page calls.
  2234.  
  2235.   In  addition  to  memory  explicitly  allocated using vm_allocate, memory may
  2236. appear in a task's address space as the result of a msg_receive operation.
  2237. vm_allocate
  2238.  
  2239. #include <mach.h>
  2240.  
  2241. kern_return_t vm_allocate(target_task, address, size, anywhere)
  2242.         vm_task_t       target_task;
  2243.         vm_address_t    *address;       /* in/out */
  2244.         vm_size_t       size;
  2245.         boolean_t       anywhere;
  2246.  
  2247.  
  2248. Arguments
  2249.  
  2250.   target_task     Task whose virtual address space is to be affected.
  2251.  
  2252.   address         Starting address.   If  the  anywhere  option  is  false,  an
  2253.                   attempt  is  made to allocate virtual memory starting at this
  2254.                   virtual address. If this address is not at the beginning of a
  2255.                   virtual  page,  it  will be rounded down to one.  If there is
  2256.                   not  enough  space  at  this  address,  no  memory  will   be
  2257.                   allocated.    If the anywhere option is true, the input value
  2258.                   of this address will  be  ignored,  and  the  space  will  be
  2259.                   allocated  wherever  it  is  available.   In either case, the
  2260.                   address at  which  memory  was  actually  allocated  will  be
  2261.                   returned in address.
  2262.  
  2263.   size            Number  of  bytes  to  allocate  (rounded  by the system in a
  2264.                   machine dependent  way  to  an  integral  number  of  virtual
  2265.                   pages).
  2266.  
  2267.   anywhere        If  true,  the  kernel should find and allocate any region of
  2268.                   the specified size, and return the address of  the  resulting
  2269.                   region  in  address.    If  false,  virtual  memory  will  be
  2270.                   allocated starting at address,  rounded  to  a  virtual  page
  2271.                   boundary if there is sufficient space.
  2272.  
  2273. Description
  2274.  
  2275.   vm_allocate allocates a region of virtual memory, placing it in the specified
  2276. task's address space.  The physical memory is not actually allocated until  the
  2277. new  virtual memory is referenced.  By default, the kernel rounds all addresses
  2278. down to the nearest page boundary and all memory sizes up to the  nearest  page
  2279. size.    The  global  variable vm_page_size contains the page size.  task_self_
  2280. returns the value of the  current  task  port  which  should  be  used  as  the
  2281. target_task argument in order to allocate memory in the caller's address space.
  2282. For languages other  than  C,  these  values  can  be  obtained  by  the  calls
  2283. vm_statistics  and task_self.  Initially, the pages of allocated memory will be
  2284. protected to allow all forms of access, and will be inherited in child tasks as
  2285. a  copy.    Subsequent calls to vm_protection and vm_inheritance may be used to
  2286. change these properties.  The allocated region is always zero-filled.
  2287.  
  2288. Returns
  2289.  
  2290.   KERN_SUCCESS    Memory allocated.
  2291.  
  2292.   KERN_INVALID_ADDRESS
  2293.                   Illegal address specified.
  2294.  
  2295.   KERN_NO_SPACE   Not enough space left to satisfy this request
  2296.  
  2297. See Also
  2298.  
  2299.   vm_deallocate, vm_inherit, vm_protect, vm_regions, vm_statistics, task_self_
  2300. vm_deallocate
  2301.  
  2302. #include <mach.h>
  2303.  
  2304. kern_return_t vm_deallocate(target_task, address, size)
  2305.         vm_task_t       target_task;
  2306.         vm_address_t    address;
  2307.         vm_size_t       size;
  2308.  
  2309.  
  2310. Arguments
  2311.  
  2312.   target_task     Task whose virtual memory is to be affected.
  2313.  
  2314.   address         Starting address (will be rounded down to a page boundary).
  2315.  
  2316.   size            Number  of  bytes to deallocate (will be rounded up to give a
  2317.                   page boundary).
  2318.  
  2319. Description
  2320.  
  2321.   vm_deallocate relinquishes access to a region  of  a  task's  address  space,
  2322. causing  further  access  to  that  memory to fail.  This address range will be
  2323. available for reallocation.  Note, that because of the rounding to virtual page
  2324. boundaries,  more  than  size  bytes  may  be  deallocated. Use vm_page_size or
  2325. vm_statistics to find out the current virtual page size.
  2326.  
  2327.   This call may be used to deallocte memory that was passed  to  a  task  in  a
  2328. message  (via  out  of  line  data). In that case, the rounding should cause no
  2329. trouble, since the region of memory was allocated as a set of pages.
  2330.  
  2331.   The vm_deallocate call affects only the task specified  by  the  target_task.
  2332. Other tasks which may have access to this memory may continue to reference it.
  2333.  
  2334. Returns
  2335.  
  2336.   KERN_SUCCESS    Memory deallocated.
  2337.  
  2338.   KERN_INVALID_ADDRESS
  2339.                   Illegal or non-allocated address specified.
  2340.  
  2341. See Also
  2342.  
  2343.   vm_allocate, vm_statistics, msg_receive
  2344. vm_read
  2345.  
  2346. #include <mach.h>
  2347.  
  2348. kern_return_t vm_read(target_task, address, size, data, data_count)
  2349.         vm_task_t       target_task
  2350.         vm_address_t    address;
  2351.         vm_size_t       size;
  2352.         pointer_t       *data;          /* out */
  2353.         int             *data_count;    /* out */
  2354.  
  2355.  
  2356. Arguments
  2357.  
  2358.   target_task     Task whose memory is to be read.
  2359.  
  2360.   address         The first address to be read (must be on a page boundary).
  2361.  
  2362.   size            The number of bytes of data to be read (must be  an  integral
  2363.                   number of pages)
  2364.  
  2365.   data            The array of data copied from the given task.
  2366.  
  2367.   data_count      The  size  of  the data array in bytes.  (will be an integral
  2368.                   number of pages).
  2369.  
  2370. Description
  2371.  
  2372.   vm_read allows one task's virtual memory to be read  by  another  task.  Note
  2373. that  the  data array is returned in a newly allocated region; the task reading
  2374. the data should vm_deallocate this region when it is done with the data.
  2375.  
  2376. Returns
  2377.  
  2378.   KERN_SUCCESS    Memory read.
  2379.  
  2380.   KERN_INVALID_ARGUMENT
  2381.                   Either  the  address does not start on a page boundary or the
  2382.                   size is not an integral number of pages.
  2383.  
  2384.   KERN_NO_SPACE   There is not enough room in the  callers  virtual  memory  to
  2385.                   allocate space for the data to be returned.
  2386.  
  2387.   KERN_PROTECTION_FAILURE
  2388.                   The address region in the target task  is  protected  against
  2389.                   reading.
  2390.  
  2391.   KERN_INVALID_ADDRESS
  2392.                   Illegal or non-allocated address specified, or there was  not
  2393.                   size bytes of data following that address.
  2394.  
  2395. See Also
  2396.  
  2397.   vm_read, vm_write, vm_copy, vm_deallocate
  2398. vm_write
  2399.  
  2400. #include <mach.h>
  2401.  
  2402. kern_return_t vm_write(target_task, address, data, data_count)
  2403.         vm_task_t       target_task;
  2404.         vm_address_t    address;
  2405.         pointer_t       data;
  2406.         int             data_count;
  2407.  
  2408.  
  2409. Arguments
  2410.  
  2411.   target_task     Task whose memory is to be written.
  2412.  
  2413.   address         Starting  address  in  task  to  be  affected (must be a page
  2414.                   boundary).
  2415.  
  2416.   data            An array of bytes to be written.
  2417.  
  2418.   data_count      The size of the data array (must be  an  integral  number  of
  2419.                   pages).
  2420.  
  2421. Description
  2422.  
  2423.   vm_write  allows  a  task's virtual memory to be written by another task. Use
  2424. vm_page_size or vm_statistics to find out the virtual page size.
  2425.  
  2426. Returns
  2427.  
  2428.   KERN_SUCCESS    Memory written.
  2429.  
  2430.   KERN_INVALID_ARGUMENT
  2431.                   Either  the  address does not start on a page boundary or the
  2432.                   size is not an integral number of pages.
  2433.  
  2434.   KERN_PROTECTION_FAILURE
  2435.                   The  address  region  in the target task is protected against
  2436.                   writing.
  2437.  
  2438.   KERN_INVALID_ADDRESS
  2439.                   Illegal  or  non_allocated  address specified or there is not
  2440.                   data_count of allocated memory starting at address.
  2441.  
  2442. See Also
  2443.  
  2444.   vm_copy, vm_protect, vm_read, vm_statistics
  2445. vm_copy
  2446.  
  2447. #include <mach.h>
  2448.  
  2449. kern_return_t vm_copy (target_task, source_address, count, dest_address)
  2450.         vm_task_t       target_task;
  2451.         vm_address_t    source_address;
  2452.         vm_size_t       count;
  2453.         vm_address_t    dest_address;
  2454.  
  2455.  
  2456. Arguments
  2457.  
  2458.   target_task     Task whose virtual memory is to be affected.
  2459.  
  2460.   source_address  Address in target_task of the start of the source range (must
  2461.                   be a page boundary).
  2462.  
  2463.   count           Number  of  bytes  to  copy  (must  be  an integral number of
  2464.                   pages).
  2465.  
  2466.   dest_address    Address in target_task of the start of the destination  range
  2467.                   (must be a page boundary).
  2468.  
  2469. Description
  2470.  
  2471.   vm_copy  causes  the  source  memory  range  to  be copied to the destination
  2472. address; the destination region  may  not  overlap  the  source  region.    The
  2473. destination  address  range  must already be allocated and writable; the source
  2474. range must be readable.
  2475.  
  2476. Returns
  2477.  
  2478.   KERN_SUCCESS    Memory copied.
  2479.  
  2480.   KERN_INVALID_ARGUMENT
  2481.                   Either  the  address does not start on a page boundary or the
  2482.                   size is not an integral number of pages.
  2483.  
  2484.   KERN_PROTECTION_FAILURE
  2485.                   Either  the  destination  region was not not writable, or the
  2486.                   source region was not readable.
  2487.  
  2488.   KERN_INVALID_ADDRESS
  2489.                   Illegal  or  non-allocated  address specified or insufficient
  2490.                   memory allocated at one of the addresses.
  2491.  
  2492. See Also
  2493.  
  2494.   vm_protect, vm_write, vm_statistics
  2495. vm_region
  2496.  
  2497. #include <mach.h>
  2498.  
  2499. kern_return_t  vm_region(target_task, address, size, protection,
  2500.                          max_protection, inheritance, shared,
  2501.                          object_name, offset)
  2502.         vm_task_t               target_task;
  2503.         vm_address_t            *address;               /* in/out */
  2504.         vm_size_t               *size;                  /* out */
  2505.         vm_prot_t               *protection;            /* out */
  2506.         vm_prot_t               *max_protection;        /* out */
  2507.         vm_inherit_t            *inheritance;           /* out */
  2508.         boolean_t               *shared;                /* out */
  2509.         port_t                  *object_name;           /* out */
  2510.         vm_offset_t             *offset;                /* out */
  2511.  
  2512.  
  2513. Arguments
  2514.  
  2515.   target_task     The task for which an address space description is requested.
  2516.  
  2517.   address         The address at which to start looking for a region.
  2518.  
  2519.   size            The size (in bytes) of the located region.
  2520.  
  2521.   protection      The current protection of the region.
  2522.  
  2523.   max_protection  The maximum allowable protection for this region.
  2524.  
  2525.   inheritance     The inheritance attribute for this region.
  2526.  
  2527.   shared          Is this region shared or not.
  2528.  
  2529.   object_name     The port identifying the memory object associated  with  this
  2530.                   region.  (See pager_init.)
  2531.  
  2532.   offset          The offset into the pager object that this region begins at.
  2533.  
  2534. Description
  2535.  
  2536.   vm_region  returns a description of the specified region of the target task's
  2537. virtual address space.  vm_region begins at  address  and  looks  forward  thru
  2538. memory  until it comes to an allocated region.  (If address is within a region,
  2539. then that region is used.)  Various bits of information about  the  region  are
  2540. returned.  If address was not within a region, then address is set to the start
  2541. of the first region which follows the incoming value.  In this  way  an  entire
  2542. address space can be scanned.
  2543.  
  2544. Returns
  2545.  
  2546.   KERN_SUCCESS    Region located and information returned.
  2547.  
  2548.   KERN_NO_SPACE   There is no region at or above address in the specified task.
  2549.  
  2550. See Also
  2551.  
  2552.   vm_allocate, vm_deallocate, vm_protect, vm_inherit
  2553. vm_protect
  2554.  
  2555. #include <mach.h>
  2556.  
  2557. kern_return_t vm_protect(target_task, address, size, set_maximum,
  2558.                                 new_protection)
  2559.         vm_task_t       target_task;
  2560.         vm_address_t    address;
  2561.         vm_size_t       size;
  2562.         boolean_t       set_maximum;
  2563.         vm_prot_t       new_protection;
  2564.  
  2565.  
  2566. Arguments
  2567.  
  2568.   target_task     Task whose virtual memory is to be affected.
  2569.  
  2570.   address         Starting address (will be rounded down to a page boundary).
  2571.  
  2572.   size            Size in bytes of the region for which protection is to change
  2573.                   (will be rounded up to give a page boundary).
  2574.  
  2575.   set_maximum     If set, make the  protection  change  apply  to  the  maximum
  2576.                   protection associated with this address range; otherwise, the
  2577.                   current protection on this range is changed.  If the  maximum
  2578.                   protection is reduced below the current protection, both will
  2579.                   be changed to reflect the new maximum.
  2580.  
  2581.   new_protection  A  new  protection  value  for  this  region;   a   set   of:
  2582.                   VM_PROT_READ, VM_PROT_WRITE, VM_PROT_EXECUTE.
  2583.  
  2584. Description
  2585.  
  2586.   vm_protect sets the virtual memory access privileges for a range of allocated
  2587. addresses in a task's virtual address space.  The protection argument describes
  2588. a combination of read, write, and execute accesses that should be permitted.
  2589.  
  2590.   The  enforcement  of  virtual  memory  protection is machine-dependent.  Some
  2591. combinations of access rights may not be supported.  In particular, the  kernel
  2592. interface  allows  any  of  the  following:    write  permission may imply read
  2593. permission;  read  permission  may  imply  execute  permission;   or,   execute
  2594. permission may imply read permission.
  2595.  
  2596.   All architectures must support the following access combinations:  all (read,
  2597. write, and execute) access;  write-protected  (read  and  execute)  access;  no
  2598. access.
  2599.  
  2600.   For the Vax, RT/PC, and Sun3, all three of the reductions stated above apply.
  2601. That is:  VM_PROT_WRITE allows read, execute and write access, VM_PROT_READ  or
  2602. VM_PROT_EXECUTE allows read and execute access, but not write access.
  2603.  
  2604. Returns
  2605.  
  2606.   KERN_SUCCESS    Memory protected.
  2607.  
  2608.   KERN_PROTECTION_FAILURE
  2609.                   An attempt was  made  to  increase  the  current  or  maximum
  2610.                   protection beyond the existing maximum protection value.
  2611.  
  2612.   KERN_INVALID_ADDRESS
  2613.                   Illegal or non-allocated address specified.
  2614. vm_inherit
  2615.  
  2616. #include <mach.h>
  2617.  
  2618. kern_return_t vm_inherit(target_task, address, size, new_inheritance)
  2619.         vm_task_t       target_task;
  2620.         vm_address_t    address;
  2621.         vm_size_t       size;
  2622.         vm_inherit_t    new_inheritance;
  2623.  
  2624.  
  2625. Arguments
  2626.  
  2627.   target_task     Task whose virtual memory is to be affected.
  2628.  
  2629.   address         Starting address (will be rounded down to a page boundary).
  2630.  
  2631.   size            Size in bytes of the  region  for  which  inheritance  is  to
  2632.                   change (will be rounded up to give a page boundary).
  2633.  
  2634.   new_inheritance How   this   memory  is  to  be  inherited  in  child  tasks.
  2635.                   Inheritance is specified by  using  one  of  these  following
  2636.                   three values:
  2637.  
  2638.   VM_INHERIT_SHARE
  2639.                   Child tasks will share this memory with this task.
  2640.  
  2641.   VM_INHERIT_COPY Child tasks will receive a copy of this region.
  2642.  
  2643.   VM_INHERIT_NONE This region will be absent from child tasks.
  2644.  
  2645. Description
  2646.  
  2647.   vm_inherit specifies how a region of a task's address space is to  be  passed
  2648. to  child  tasks  at the time of task creation.  Inheritance is an attribute of
  2649. virtual pages, thus the addresses and size of memory to be set will be  rounded
  2650. out to refer to whole pages.
  2651.  
  2652.   Setting  vm_inherit  to VM_INHERIT_SHARE and forking a child task is the only
  2653. way two Mach tasks can share physical memory.  Remember that all the theads  of
  2654. a given task share all the same memory.
  2655.  
  2656. Returns
  2657.  
  2658.   KERN_SUCCESS    Memory protected.
  2659.  
  2660.   KERN_INVALID_ADDRESS
  2661.                   Illegal address specified.
  2662.  
  2663. See Also
  2664.  
  2665.   task_create, vm_regions
  2666. vm_statistics
  2667.  
  2668. #include <mach.h>
  2669.  
  2670. struct vm_statistics {
  2671.         long    pagesize;               /* page size in bytes */
  2672.         long    free_count;             /* # of pages free */
  2673.         long    active_count;           /* # of pages active */
  2674.         long    inactive_count;         /* # of pages inactive */
  2675.         long    wire_count;             /* # of pages wired down */
  2676.         long    zero_fill_count;        /* # of zero fill pages */
  2677.         long    reactivations;          /* # of pages reactivated */
  2678.         long    pageins;                /* # of pageins */
  2679.         long    pageouts;               /* # of pageouts */
  2680.         long    faults;                 /* # of faults */
  2681.         long    cow_faults;             /* # of copy-on-writes */
  2682.         long    lookups;                /* object cache lookups */
  2683.         long    hits;                   /* object cache hits */
  2684. };
  2685.  
  2686. typedef struct vm_statistics    vm_statistics_data_t;
  2687.  
  2688. kern_return_t   vm_statistics(target_task, vm_stats)
  2689.         task_t                  target_task;
  2690.         vm_statistics_data_t    *vm_stats;      /* out */
  2691.  
  2692.  
  2693. Arguments
  2694.  
  2695.   target_task     Task which is requesting statistics.
  2696.  
  2697.   vm_stats        The structure that will receive the statistics.
  2698.  
  2699. Description
  2700.  
  2701.   vm_statistics returns the statistics about the kernel's use of virtual memory
  2702. since  the  kernel was booted.  pagesize can also be found as a global variable
  2703. vm_page_size which is set at task initialization and remains constant  for  the
  2704. life of the task.
  2705.  
  2706. Returns
  2707.  
  2708.   KERN_SUCCESS
  2709. vm_machine_attribute
  2710.  
  2711. #include <mach.h>
  2712.  
  2713. kern_return_t vm_machine_attribute (task, address, size, attribute, value)
  2714.         task_t                           task;
  2715.         vm_address_t                     address;
  2716.         vm_size_t                        size;
  2717.         vm_machine_attribute_t           attribute;
  2718.         vm_machine_attribute_val_t      *value;
  2719.  
  2720.  
  2721. Arguments
  2722.  
  2723.   task            The task whose memory is to be affected
  2724.  
  2725.   address         Starting address of the memory segment.
  2726.  
  2727.   size            Size of the memory segment
  2728.  
  2729.   attribute       Attribute type
  2730.  
  2731.   value           Pointer to the attribute's value
  2732.  
  2733. Description
  2734.  
  2735.   vm_machine_attribute  specifies machine-specific attributes for a VM mapping,
  2736. such as cachability, migrability, replicability.  This is used on machines that
  2737. allow the user control over the cache (this is the case for MIPS architectures)
  2738. or placement of memory pages  as  in  NUMA  architectures  (Non-Uniform  Memory
  2739. Access time) such as the IBM ACE multiprocessor.
  2740.  
  2741.   Machine-specific  attributes  can  be  consider  additions  to  the  machine-
  2742. independent  ones  such  as  protection  and  inheritance,  but  they  are  not
  2743. guaranteed  to be supported by any given machine.  Moreover, implementations of
  2744. Mach on new architectures might find the need for new attribute  types  and  or
  2745. values besides the ones defined in the initial implementation.
  2746.  
  2747.   The types currently defined are
  2748.  
  2749.   MATTR_CACHE Controls caching of memory pages
  2750.  
  2751.   MATTR_MIGRATE Controls migrability of memory pages
  2752.  
  2753.   MATTR_REPLICATE Controls replication of memory pages
  2754.  
  2755.   Corresponding values, and meaning of a specific call to vm_machine_attribute
  2756.  
  2757.   MATTR_VAL_ON  Enables  the attribute.  Being enabled is the default value for
  2758. any applicable attribute.
  2759.  
  2760.   MATTR_VAL_OFF  Disables  the  attribute,   making   memory   non-cached,   or
  2761. non-migratable, or non-replicatable.
  2762.  
  2763.   MATTR_VAL_GET  Returns  the  current  value  of  the attribute for the memory
  2764. segment.  If the attribute does not apply uniformly  to  the  given  range  the
  2765. value returned applies to the initial portion of the segment only.
  2766.  
  2767.   MATTR_VAL_CACHE_FLUSH  Flush the memory pages from the Cache.  The size value
  2768. in this case might be meaningful even if not  a  multiple  of  the  page  size,
  2769. depending on the implementation.
  2770.  
  2771.   MATTR_VAL_ICACHE_FLUSH Same as above, applied to the Instruction Cache alone.
  2772.  
  2773.   MATTR_VAL_DCACHE_FLUSH Same as above, applied to the Data Cache alone.
  2774.  
  2775. Returns
  2776.  
  2777.   KERN_SUCCESS    The call succeeded.
  2778.  
  2779.   KERN_INVALID_ARGUMENT
  2780.                   task is not a task, or address and size do not define a valid
  2781.                   address  range in task, or attribute is not a valid attribute
  2782.                   type, or it is not implemented, or value is not a permissible
  2783.                   value for attribute.
  2784.  
  2785. Notes
  2786.  
  2787.   The  initial  implementation  (for  MIPS) does not provide for inheritance of
  2788. machine attributes.  This might change if/when the IBM ACE code will be  merged
  2789. in the mainline.
  2790. 6. Ancillary primitives
  2791. mach_ports
  2792.  
  2793. #include <mach.h>
  2794.  
  2795. kern_return_t mach_ports_register(target_task,
  2796.                                 init_port_set, init_port_array_count)
  2797.         task_t          target_task;
  2798.         port_array_t    init_port_set;         /* array */
  2799.         int             init_port_array_count;
  2800.  
  2801. kern_return_t mach_ports_lookup(target_task,
  2802.                                 init_port_set, init_port_array_count)
  2803.         task_t          target_task;
  2804.         port_array_t    *init_port_set;         /* out array */
  2805.         int             *init_port_array_count; /* out */
  2806.  
  2807.  
  2808. Arguments
  2809.  
  2810.   target_task     Task to be affected.
  2811.  
  2812.   init_port_set   An  array  of  system  ports  to  be registered, or returned.
  2813.                   Although the array size is given as variable, the MACH kernel
  2814.                   will only accept a limited number of ports.
  2815.  
  2816.   init_port_array_count
  2817.                   The number of ports returned in init_port_set.
  2818.  
  2819. Description
  2820.  
  2821.   mach_ports_register registers an array of well-known system  ports  with  the
  2822. kernel on behalf of a specific task.  Currently the ports to be registered are:
  2823. the port to the Network Name Server, the port to the Environment Manager, and a
  2824. port  to the Service server. These port values must be placed in specific slots
  2825. in the init_port_set. The slot  numbers  are  given  by  the  global  constants
  2826. defined  in  mach_init.h: NAME_SERVER_SLOT, ENVIRONMENT_SLOT, and SERVICE_SLOT.
  2827. These ports may later be retrieved with mach_ports_lookup.
  2828.  
  2829.   When a new task is created (see task_create), the child task  will  be  given
  2830. access  to these ports.  Only port send rights may be registered.  Furthermore,
  2831. the number of ports which may be registered is fixed and given  by  the  global
  2832. constant MACH_PORT_SLOTS_USED.  Attempts to register too many ports will fail.
  2833.  
  2834.   It  is intended that this mechanism be used only for task initialization, and
  2835. then only by runtime support modules.  A  parent  task  has  three  choices  in
  2836. passing these system ports to a child task. Most commonly it can do nothing and
  2837. its child will inherit access to the same init_port_set that the parent has; or
  2838. a  parent  task  may register a set of ports it wishes to have passed to all of
  2839. its children by calling mach_ports_register using its task port; or it may make
  2840. necessary  modifications  to  the  set of ports it wishes its child to see, and
  2841. then register those ports using the child's task port  prior  to  starting  the
  2842. child's  thread(s).    The mach_ports_lookup call which is done by mach_init in
  2843. the child task will acquire these initial ports for the child.
  2844.  
  2845.   Tasks other than the Network Name Server and the Environment Mangager  should
  2846. not  need  access to the Service port. The Network Name Server port is the same
  2847. for all tasks on a given machine. The Environment port is the only port  likely
  2848. to have different values for different tasks.
  2849.  
  2850.   Since  the  number  of  ports which may be registered is limited, ports other
  2851. than those used by the runtime system to initialize a task should be passed  to
  2852. children  either through an initial message, or through the Network Name Server
  2853. for public ports, or the Environment Manager for private ports.
  2854.  
  2855. Returns
  2856.  
  2857.   KERN_SUCCESS    Memory allocated.
  2858.  
  2859.   KERN_INVALID_ARGUMENT
  2860.                   An  attempt  was made to register more ports than the current
  2861.                   kernel implementation allows.
  2862.  
  2863. See Also
  2864.  
  2865.   mach_init, netname, env_mgr, service
  2866. host_ipc_statistics
  2867.  
  2868. #include <mach.h>
  2869.  
  2870. kern_return_t host_ipc_statistics(task, statistics)
  2871.         task_t target_task;
  2872.         ipc_statistics_t *statistics;   /* inout */
  2873.  
  2874.  
  2875. Arguments
  2876.  
  2877.   task            Task running on the kernel whose statistics are desired.
  2878.  
  2879.   statistics      The returned statistics.
  2880.  
  2881. Description
  2882.  
  2883.   host_ipc_statistics returns the statistics about MACH IPC, since  the  kernel
  2884. was  booted.  statistics  is  a  fixed  length array provided by the user.  See
  2885. <kern/ipc_statistics.h> for a description of what is returned.
  2886.  
  2887. Returns
  2888.  
  2889.   KERN_SUCCESS    The call succeeded.
  2890.  
  2891. Notes
  2892.  
  2893.   Only kernels compiled with MACH_IPCSTATS enabled support this call.
  2894.  
  2895.   The first argument should be a host port of some kind.
  2896.  
  2897.   The meaning of the statistics varies; not all fields are used.
  2898. 7. External memory management primitives
  2899.  
  2900.  
  2901.  
  2902. 7.1. Memory Managers
  2903.   The MACH kernel allows  users  to  provide  memory  managment  (i.e.  paging)
  2904. services  outside the kernel. A server that provides such functions is called a
  2905. memory manager. There is a default memory manager that is part  of  the  kernel
  2906. and  is  normally  used  to  handle  paging  to both files and temporary memory
  2907. objects.  Users may provide additional memory managers to handle special  kinds
  2908. of  objects,  such  as  fault-tolerant  objects, objects whose backing store is
  2909. across a network link, or objects whose backing store is on devices  for  which
  2910. the kernel does not provide drivers.
  2911.  
  2912.   The  protocol  defined  in  this section consists of messages that the kernel
  2913. will send to memory managers and the primitives that the  kernel  provides  for
  2914. the  use  of  memory  managers.    Use  of  these primitives involves increased
  2915. responsibility. A memory manager is expected to respond in a timely fashion  to
  2916. all  the  requests  that  the  kernel makes of it, otherwise threads within the
  2917. kernel are left hanging and the client task that is attempting to reference the
  2918. memory object is also left hanging.
  2919.  
  2920.   It  is  also  possible  for  a  privileged user to replace the default memory
  2921. manager. This involves increased reliability and responsibility as now all  the
  2922. users of the system will be dependent on the new server.
  2923.  
  2924.  
  2925. 7.1.1. Memory objects: definitions and basics
  2926.   In  MACH,  physical  memory  is  used as a cache of the contents of secondary
  2927. storage objects called memory objects.  The virtual address space of a task  is
  2928. represented  as  a series of mappings from contiguous virtual address ranges to
  2929. such memory objects.  For each memory object the kernel keeps  track  of  those
  2930. pages  that  are  currently  in  the  physical memory cache and it allows tasks
  2931. mapped to that memory to use those physical pages.
  2932.  
  2933.   When a virtual memory request occurs that cannot be resolved through the  use
  2934. of  a  previously  cached  physical page, the kernel must make a request of the
  2935. memory object for the required data.  As the physical page cache becomes  full,
  2936. the  kernel must replace pages from the cache, writing the contents of modified
  2937. pages back to the corresponding memory objects.
  2938.  
  2939.   When a task uses the vm_allocate call, the kernel allocates a  memory  object
  2940. that provides zero-filled memory on reference; this memory object is managed by
  2941. a default memory manager.
  2942.  
  2943.   Alternatively, a task may map a specific memory object into its address space
  2944. by  issuing  a  vm_map  call.    Included  in  this  call is the memory object,
  2945. represented by a port, that is to manage the data in the allocated region.  The
  2946. kernel will use the memory object port to make requests for data, or to request
  2947. that data be written back to the object.  The memory  manager  must  act  as  a
  2948. server  for  these  requests.  The memory manager server interface differs from
  2949. other servers only in that the kernel does not synchronously await replies.
  2950.  
  2951.   A given memory object may be mapped into an arbitrary number of tasks, at any
  2952. addresses  available  in  those  tasks.  When a vm_map call is issued, the MACH
  2953. kernel will recognize the memory object if  it  has  been  mapped  before;  any
  2954. physical memory pages from this memory object already cached from previous uses
  2955. may be shared by later mappings as well.    A  single  MACH  kernel  keeps  the
  2956. physical  memory  cache consistent across all uses of the same memory object at
  2957. similar page alignments on that host.
  2958.  
  2959.   Furthermore, a single memory object may  be  mapped  into  tasks  created  on
  2960. different  hosts  (and therefore be cached by different MACH kernels).  In this
  2961. case, the memory manager is responsible for maintaining any desired consistency
  2962. among the various hosts on which its data resides.
  2963.  
  2964.  
  2965. 7.1.2. Initialization and termination
  2966.   The memory manager must define a protocol for giving out memory object ports.
  2967. This could take the form of the memory manager registering  a  general  service
  2968. port somewhere that clients could find and exporting an object create or object
  2969. lookup call that will return a memory object port. This is  the  port  that  is
  2970. passed to the kernel in the vm_map call.
  2971.  
  2972.   Upon  processing  the  first  vm_map call for a given memory object, the MACH
  2973. kernel will make a memory_object_init call, providing the memory  manager  with
  2974. two  ports:  a  control  port, and a name port.  The memory manager may use the
  2975. memory object control port to supply the kernel with data for it to  cache,  or
  2976. to perform other cache management functions.  These requests will be covered in
  2977. the next section.
  2978.  
  2979.   The memory object name, a port, will only  be  used  by  the  kernel  in  the
  2980. results  from  a  vm_region  call  to  describe  the source of data for a given
  2981. region.  Since this port is not to be used for requests for  data,  the  memory
  2982. manager  may  wish  to provide this port to clients to identify memory which it
  2983. supplies.
  2984.  
  2985.   The initialization call also includes the system page size for  the  host  on
  2986. which  the  mapping took place.  This allows the memory manager to provide data
  2987. to the kernel in whole pages, and  to  detect  mappings  at  inconsistent  page
  2988. alignments.
  2989.  
  2990.   In  order  to  indicate  its readiness to accept requests, the memory manager
  2991. must    respond    to    the    initialization     call     by     making     a
  2992. memory_object_set_attributes call, asserting the readiness parameter.
  2993.  
  2994.   Normally, when a memory object is no longer referenced by any virtual address
  2995. space, the MACH kernel will deallocate its port rights to  that  memory  object
  2996. after   sending  all  port  rights  for  the  control  and  name  ports  in  an
  2997. memory_object_terminate call.  To enhance performance,  a  memory  manager  may
  2998. allow  a MACH kernel to maintain its memory cache for a memory object after all
  2999. virtual address space references to it  are  gone,  by  asserting  the  caching
  3000. parameter  to the memory_object_set_attributes call.  However, allowing caching
  3001. does not prevent the kernel from terminating an object.
  3002.  
  3003.   In the event that a memory manager destroys a  memory  object  port  that  is
  3004. currently mapped into one or more virtual address spaces, future page faults on
  3005. addresses mapped to this object (for which data is not available in the  cache)
  3006. will result in a memory exception.
  3007.  
  3008.  
  3009. 7.1.3. Kernel-created memory objects
  3010.   As noted earlier, memory created using vm_allocate results in the creation of
  3011. a memory object; this object is created by the kernel, and  is  passed  to  the
  3012. default  memory manager, using the memory_object_create call.  Since the memory
  3013. object is initially zero-filled, it only contains data that has been modified.
  3014.  
  3015.   The memory_object_create request will only be  made  of  the  default  memory
  3016. manager.  The default memory manager must not allow any memory object passed in
  3017. a memory_object_create call to be used in any other task,  as  the  kernel  may
  3018. make  assumptions  about  such  an  object that could adversely affect external
  3019. consistency.
  3020.  
  3021.  
  3022.  
  3023. 7.2. Kernel calls supporting memory managers
  3024. vm_map
  3025.  
  3026. #include <mach.h>
  3027.  
  3028. kern_return_t vm_map(target_task, address, size, mask, anywhere,
  3029.                                 memory_object, offset, copy,
  3030.                                 cur_protection, max_protection,
  3031.                                 inheritance)
  3032.         task_t          target_task;
  3033.         vm_offset_t     *address;       /* in/out */
  3034.         vm_size_t       size;
  3035.         vm_offset_t     mask;
  3036.         boolean_t       anywhere;
  3037.         memory_object_t memory_object;
  3038.         vm_offset_t     offset;
  3039.         boolean_t       copy;
  3040.         vm_prot_t       cur_protection;
  3041.         vm_prot_t       max_protection;
  3042.         vm_inherit_t    inheritance;
  3043.  
  3044.  
  3045.  
  3046. Description
  3047.  
  3048.   vm_map maps a region of virtual memory at the specified  address,  for  which
  3049. data is to be supplied by the given memory object, starting at the given offset
  3050. within that object.  In addition to the  arguments  used  in  vm_allocate,  the
  3051. vm_map  call allows the specification of an address alignment parameter, and of
  3052. the initial protection and  inheritance  values.    [See  the  descriptions  of
  3053. vm_allocate, vm_protect, and vm_inherit.]
  3054.  
  3055.   If  the  memory  object  in question is not currently in use, the MACH kernel
  3056. will perform a memory_object_init call at this time.  If the copy parameter  is
  3057. asserted,  the  specified  region  of  the memory object will be copied to this
  3058. address space; changes made to this object by other tasks will not  be  visible
  3059. in this mapping, and changes made in this mapping will not be visible to others
  3060. (or returned to the memory object).
  3061.  
  3062.   The vm_map call returns once the mapping is established.  Completion  of  the
  3063. call does not require any action on the part of the memory manager.
  3064.  
  3065.   Warning:  Only  memory objects that are provided by bona fide memory managers
  3066. should be used in the vm_map call.  A memory manager must implement the  memory
  3067. object  interface described elsewhere in this manual.  If other ports are used,
  3068. a thread that accesses the mapped virtual memory may become permanently hung or
  3069. may receive a memory exception.
  3070.  
  3071. Arguments
  3072.  
  3073.   target_task     Task to be affected.
  3074.  
  3075.   address         Starting  address.    If  the  anywhere  option is used, this
  3076.                   address is ignored.  The address actually allocated  will  be
  3077.                   returned in address.
  3078.  
  3079.   size            Number  of  bytes  to  allocate  (rounded  by the system in a
  3080.                   machine dependent way).
  3081.  
  3082.   mask            Alignment restriction.  Bits asserted in this mask  must  not
  3083.                   be asserted in the address returned.
  3084.  
  3085.   anywhere        If set, the kernel should find and allocate any region of the
  3086.                   specified size, and  return  the  address  of  the  resulting
  3087.                   region in address.
  3088.  
  3089.   memory_object   Port that represents the memory object: used by user tasks in
  3090.                   vm_map; used by the MACH kernel to make requests for data  or
  3091.                   other    management    actions.        If    this   port   is
  3092.                   MEMORY_OBJECT_NULL,  then  zero-filled  memory  is  allocated
  3093.                   instead.
  3094.  
  3095.   offset          An  offset  within  a  memory object, in bytes.  This must be
  3096.                   page aligned.
  3097.  
  3098.   copy            If set, the range of the memory object should  be  copied  to
  3099.                   the target task, rather than mapped read-write.
  3100.  
  3101. Returns
  3102.  
  3103.   KERN_SUCCESS    The object is mapped.
  3104.  
  3105.   KERN_NO_SPACE   No  unused  region  of  the task's virtual address space that
  3106.                   meets the address, size,  and  alignment  criteria  could  be
  3107.                   found.
  3108.  
  3109.   KERN_INVALID_ARGUMENT
  3110.                   An illegal argument was provided.
  3111.  
  3112. See Also
  3113.  
  3114.   memory_object_server, vm_allocate
  3115. memory_object_set_attributes
  3116.  
  3117. #include <mach.h>
  3118.  
  3119. kern_return_t memory_object_set_attributes(memory_control,
  3120.                                 object_ready, may_cache_object,
  3121.                                 copy_strategy)
  3122.         memory_object_control_t
  3123.                         memory_control;
  3124.         boolean_t       object_ready;
  3125.         boolean_t       may_cache_object;
  3126.         memory_object_copy_strategy_t
  3127.                         copy_strategy;
  3128.  
  3129.  
  3130. Description
  3131.  
  3132.   memory_object_set_attributes controls how the MACH  kernel  uses  the  memory
  3133. object.    The  kernel  will  only  make data or unlock requests when the ready
  3134. attribute is asserted.  If the caching attribute is  asserted,  the  kernel  is
  3135. permitted  (and encouraged) to maintain cached data for this memory object even
  3136. after no virtual address space contains this data.
  3137.  
  3138.   There are three possible caching  strategies:  MEMORY_OBJECT_COPY_NONE  which
  3139. specifies  that  nothing  special  should  be  done  when data in the object is
  3140. copied; MEMORY_OBJECT_COPY_CALL which specifies that the memory manager  should
  3141. be  notified  via  a  memory_object_copy  call before any part of the object is
  3142. copied; and MEMORY_OBJECT_COPY_DELAY which guarantees that the  memory  manager
  3143. does  not  externally  modify  the  data  so that the kernel can use its normal
  3144. copy-on-write  algorithms.    MEMORY_OBJECT_COPY_DELAY  is  the  strategy  most
  3145. commonly used.
  3146.  
  3147. Arguments
  3148.  
  3149.   memory_control  The  port,  provided  by  the  kernel in a memory_object_init
  3150.                   call, to which cache management requests may be issued.
  3151.  
  3152.   object_ready    When set, the kernel may issue new data and  unlock  requests
  3153.                   on the associated memory object.
  3154.  
  3155.   may_cache_object
  3156.                   If set, the kernel may keep data associated with this  memory
  3157.                   object, even after virtual memory references to it are gone.
  3158.  
  3159.   copy_strategy   How  the  kernel should copy regions of the associated memory
  3160.                   object.
  3161.  
  3162. Returns
  3163.  
  3164.   KERN_SUCCESS    This  routine  does  not  receive  a   reply   message   (and
  3165.                   consequently   has   no   return   value),  so  only  message
  3166.                   transmission errors apply.
  3167.  
  3168. See Also
  3169.  
  3170.   memory_object_init, memory_object_copy, memory_object_attributes
  3171. memory_object_get_attributes
  3172.  
  3173. #include <mach.h>
  3174.  
  3175. kern_return_t memory_object_get_attributes(memory_control,
  3176.                                 object_ready, may_cache_object,
  3177.                                 copy_strategy)
  3178.         memory_object_control_t
  3179.                         memory_control;
  3180.         boolean_t       *object_ready;
  3181.         boolean_t       *may_cache_object;
  3182.         memory_object_copy_strategy_t
  3183.                         *copy_strategy;
  3184.  
  3185.  
  3186. Description
  3187.  
  3188.   memory_object_get_attributes retrieves the current attributes associated with
  3189. the memory object.
  3190.  
  3191. Arguments
  3192.  
  3193.   memory_control  The  port,  provided  by  the  kernel in a memory_object_init
  3194.                   call, to which cache management requests may be issued.
  3195.  
  3196.   object_ready    When set, the kernel may issue new data and  unlock  requests
  3197.                   on the associated memory object.
  3198.  
  3199.   may_cache_object
  3200.                   If set, the kernel may keep data associated with this  memory
  3201.                   object, even after virtual memory references to it are gone.
  3202.  
  3203.   copy_strategy   How  the  kernel should copy regions of the associated memory
  3204.                   object.
  3205.  
  3206. Returns
  3207.  
  3208.   KERN_SUCCESS    This  routine  does  not  receive  a   reply   message   (and
  3209.                   consequently   has   no   return   value),  so  only  message
  3210.                   transmission errors apply.
  3211.  
  3212. See Also
  3213.  
  3214.   memory_object_set_attributes, memory_object_copy
  3215. memory_object_lock_request
  3216.  
  3217. #include <mach.h>
  3218.  
  3219. kern_return_t   memory_object_lock_request(memory_control,
  3220.                                 offset, size, should_clean
  3221.                                 should_flush, lock_value, reply_to)
  3222.         memory_object_control_t
  3223.                         memory_control;
  3224.         vm_offset_t     offset;
  3225.         vm_size_t       size;
  3226.         boolean_t       should_clean;
  3227.         boolean_t       should_flush;
  3228.         vm_prot_t       lock_value;
  3229.         port_t          reply_to;
  3230.  
  3231.  
  3232. Description
  3233.  
  3234.   memory_object_lock_request allows a memory manager to make  cache  management
  3235. requests.    As  specified  in  arguments  to the call, the kernel will:  clean
  3236. (i.e., write back using memory_object_data_write) any  cached  data  which  has
  3237. been  modified since the last time it was written; flush (i.e., remove any uses
  3238. of) that data from memory; lock (i.e., prohibit  the  specified  uses  of)  the
  3239. cached  data.  Locks applied to cached data are not cumulative; new lock values
  3240. override previous ones.  Thus, data may also be unlocked using this  primitive.
  3241. The  lock  values  must  be one or more of the following values:  VM_PROT_NONE,
  3242. VM_PROT_READ, VM_PROT_WRITE, VM_PROT_EXECUTE  and  VM_PROT_ALL  as  defined  in
  3243. <mach/vm_prot.h>.
  3244.  
  3245.   Only  data  which  is  cached  at  the time of this call is affected.  When a
  3246. running thread requires a prohibited access to cached  data,  the  MACH  kernel
  3247. will  issue  a  memory_object_data_unlock  call  specifying the forms of access
  3248. required.  Once all of the actions requested by this call have been  completed,
  3249. the MACH kernel will issue a memory_object_lock_completed call on the specified
  3250. reply port.
  3251.  
  3252. Arguments
  3253.  
  3254.   memory_control  The port, provided by  the  kernel  in  a  memory_object_init
  3255.                   call, to which cache management requests may be issued.
  3256.  
  3257.   offset          An  offset  within  a  memory object, in bytes.  This must be
  3258.                   page aligned.
  3259.  
  3260.   size            The amount of cached data (starting at offset) to be handled,
  3261.                   must be an integral multiple of the memory object page size.
  3262.  
  3263.   should_clean    If  set,  modified  data should be written back to the memory
  3264.                   manager.
  3265.  
  3266.   should_flush    If set, the specified cached data should be invalidated,  and
  3267.                   all uses of that data should be revoked.
  3268.  
  3269.   lock_value      A  protection  value  indicating  those  forms of access that
  3270.                   should not be permitted to the specified cached data.
  3271.  
  3272.   reply_to        A port on which a memory_object_lock_completed call should be
  3273.                   issued, or PORT_NULL if no acknowledgement is desired.
  3274.  
  3275. Returns
  3276.  
  3277.   KERN_SUCCESS    This   routine   does   not  receive  a  reply  message  (and
  3278.                   consequently  has  no  return   value),   so   only   message
  3279.                   transmission errors apply.
  3280.  
  3281. See Also
  3282.  
  3283.   memory_object_lock_completed, memory_object_data_unlock
  3284. memory_object_data_provided
  3285.  
  3286. #include <mach.h>
  3287.  
  3288. kern_return_t memory_object_data_provided(memory_control,
  3289.                                 offset, data, data_count, lock_value)
  3290.         memory_object_control_t
  3291.                         memory_control;
  3292.         vm_offset_t     offset;
  3293.         pointer_t       data;
  3294.         int             data_count;
  3295.         vm_prot_t       lock_value;
  3296.  
  3297.  
  3298.  
  3299. Description
  3300.  
  3301.   memory_object_data_provided  supplies  the kernel with data for the specified
  3302. memory object.  Ordinarily, memory managers should only provide data in reponse
  3303. to  memory_object_data_request calls from the kernel.  The lock_value specifies
  3304. what type of access will not be allowed to the data range. The lock values must
  3305. be  one  or  more  of  the  set:    VM_PROT_NONE,  VM_PROT_READ, VM_PROT_WRITE,
  3306. VM_PROT_EXECUTE and VM_PROT_ALL as defined in <mach/vm_prot.h>.
  3307.  
  3308. Arguments
  3309.  
  3310.   memory_control  The port, provided by  the  kernel  in  a  memory_object_init
  3311.                   call, to which cache management requests may be issued.
  3312.  
  3313.   offset          An  offset  within  a  memory object, in bytes.  This must be
  3314.                   page aligned.
  3315.  
  3316.   data            Data that is being provided to the kernel. This is a  pointer
  3317.                   to the data.
  3318.  
  3319.   data_count      The  amount  of  data  to  be  provided.  Must be an integral
  3320.                   number of memory object pages.
  3321.  
  3322.   lock_value      A protection value indicating  those  forms  of  access  that
  3323.                   should not be permitted to the specified cached data.
  3324.  
  3325. Returns
  3326.  
  3327.   KERN_SUCCESS    This   routine   does   not  receive  a  reply  message  (and
  3328.                   consequently  has  no  return   value),   so   only   message
  3329.                   transmission errors apply.
  3330.  
  3331. See Also
  3332.  
  3333.   memory_object_data_request,                         memory_object_data_error,
  3334. memory_object_lock_request
  3335. memory_object_data_unavailable
  3336.  
  3337. #include <mach.h>
  3338.  
  3339. kern_return_t memory_object_data_unavailable(memory_control,
  3340.                                 offset, size);
  3341.         memory_object_control_t
  3342.                         memory_control;
  3343.         vm_offset_t     offset;
  3344.         vm_size_t       size;
  3345.  
  3346.  
  3347. Description
  3348.  
  3349.   memory_object_data_unavailable indicates that the memory object does not have
  3350. data  for the given region and that the kernel should provide the data for this
  3351. range. The memory manager may use this call in three different  situations.  1)
  3352. The  object  was  created  by  memory_object_create  and the kernel has not yet
  3353. provided data for this range (either via a memory_object_data_initialize  or  a
  3354. memory_object_data_write.  In  this  case  the kernel should supply zero-filled
  3355. pages for the object. 2) The object was created by  an  memory_object_data_copy
  3356. and  the kernel should copy this region from the original memory object. 3) The
  3357. object is a normal user-created memory object  and  the  kernel  should  supply
  3358. unlocked zero-filled pages for the range.
  3359.  
  3360. Arguments
  3361.  
  3362.   memory_control  The  port,  provided  by  the  kernel in a memory_object_init
  3363.                   call, to which cache management requests may be issued.
  3364.  
  3365.   offset          An offset within a memory object, in bytes.    This  must  be
  3366.                   page aligned.
  3367.  
  3368.   size            The amount of cached data (starting at offset) to be handled.
  3369.                   This must be an integral multiple of the memory  object  page
  3370.                   size.
  3371.  
  3372. Returns
  3373.  
  3374.   KERN_SUCCESS    This   routine   does   not  receive  a  reply  message  (and
  3375.                   consequently  has  no  return   value),   so   only   message
  3376.                   transmission errors apply.
  3377.  
  3378. See Also
  3379.  
  3380.   memory_object_create, memory_object_data_request, memory_object_data_error
  3381. memory_object_data_error
  3382.  
  3383. #include <mach.h>
  3384.  
  3385. kern_return_t memory_object_data_error(memory_control,
  3386.                                 offset, size, reason);
  3387.         memory_object_control_t
  3388.                         memory_control;
  3389.         vm_offset_t     offset;
  3390.         vm_size_t       size;
  3391.         kern_return_t   reason;
  3392.  
  3393.  
  3394. Description
  3395.  
  3396.   memory_object_data_error  indicates that the memory manager cannot return the
  3397. data requested for the given region, specifying a reason for the error.    This
  3398. is typically used when a hardware error is encountered.
  3399.  
  3400. Arguments
  3401.  
  3402.   memory_control  The  port,  provided  by  the  kernel in a memory_object_init
  3403.                   call, to which cache management requests may be issued.
  3404.  
  3405.   offset          An offset within a memory object, in bytes.    This  must  be
  3406.                   page aligned.
  3407.  
  3408.   size            The amount of cached data (starting at offset) to be handled.
  3409.                   This must be an integral multiple of the memory  object  page
  3410.                   size.
  3411.  
  3412.   reason          Could be a Unix error code for a hardware error.
  3413.  
  3414. Returns
  3415.  
  3416.   KERN_SUCCESS    This   routine   does   not  receive  a  reply  message  (and
  3417.                   consequently  has  no  return   value),   so   only   message
  3418.                   transmission errors apply.
  3419.  
  3420. See Also
  3421.  
  3422.   memory_object_data_request, memory_object_data_provided
  3423.  
  3424. Notes
  3425.  
  3426.   The error code is currently ignored.
  3427. memory_object_destroy
  3428.  
  3429. #include <mach.h>
  3430.  
  3431. kern_return_t memory_object_destroy(memory_control, reason);
  3432.         memory_object_control_t
  3433.                         memory_control;
  3434.         kern_return_t   reason;
  3435.  
  3436.  
  3437. Description
  3438.  
  3439.   memory_object_destroy  tells the kernel to shut down the memory object.  As a
  3440. result of this call the kernel will no longer support paging  activity  or  any
  3441. memory_object  calls  on this object, and all rights to the memory object port,
  3442. the memory control port and the memory name port will be returned to the memory
  3443. manager  in  a memory_object_terminate call. If the memory manager is concerned
  3444. that any  modified  cached  data  be  returned  to  it  before  the  object  is
  3445. terminated, it should call memory_object_lock_request with should_flush set and
  3446. a lock value of VM_PROT_WRITE before making this call.
  3447.  
  3448. Arguments
  3449.  
  3450.   memory_control  The port, provided by  the  kernel  in  a  memory_object_init
  3451.                   call, to which cache management requests may be issued.
  3452.  
  3453.   reason          An error code indicating when the object must be destroyed.
  3454.  
  3455. Returns
  3456.  
  3457.   KERN_SUCCESS    This   routine   does   not  receive  a  reply  message  (and
  3458.                   consequently  has  no  return   value),   so   only   message
  3459.                   transmission errors apply.
  3460.  
  3461. See Also
  3462.  
  3463.   memory_object_terminate, memory_object_lock_request
  3464.  
  3465. Notes
  3466.  
  3467.   The error code is currently ingnored.
  3468. vm_set_default_memory_manager
  3469.  
  3470. #include <mach.h>
  3471.  
  3472. routine vm_set_default_memory_manager(host,default_manager)
  3473.         task_t          host;
  3474.         memory_object_t default_manager;        /* in/out */
  3475.  
  3476.  
  3477. Description
  3478.  
  3479.   vm_set_default_memory_manager  sets  the kernel's default memory manager.  It
  3480. sets the port to which newly-created temporary memory objects are delivered  by
  3481. memory_object_create to the host.  The old memory manager port is returned.  If
  3482. default_manager is PORT_NULL then this routine just returns the current default
  3483. manager port without changing it.
  3484.  
  3485. Arguments
  3486.  
  3487.   host            A  task port to the kernel whose default memory manager is to
  3488.                   be changed.
  3489.  
  3490.   default_manager Input as the port that the new memory manager is listening on
  3491.                   for  memory_object_create  calls. Returned as the old default
  3492.                   memory manager's port.
  3493.  
  3494. Returns
  3495.  
  3496.   KERN_SUCCESS    The new memory manager is installed.
  3497.  
  3498.   KERN_INVALID_ARGUMENT
  3499.                   This  task  does  not  have  the privileges required for this
  3500.                   call.
  3501.  
  3502. See Also
  3503.  
  3504.   vm_allocate, memory_object_create, memory_object_data_initialize
  3505.  
  3506. Notes
  3507.  
  3508.   There is no way for the user task to acquire  the  appropriate  privilege  to
  3509. make this call.
  3510.  
  3511.   <<<
  3512. 7.3. Memory Manager calls
  3513.   This  section  describes calls made by the MACH kernelon a memory object that
  3514. has previously been mapped by some task (see vm_map).  A task  that  manages  a
  3515. memory  object  (called  a  memory  manager)  must  act  as  a  server for this
  3516. interface.
  3517.  
  3518.   In order to  isolate  the  memory  manager  from  the  specifics  of  message
  3519. formatting,  the  remote  procedure  call generator, MIG, produces a procedure,
  3520. memory_object_server, to handle  a  received  messag  This  function  does  all
  3521. necessary argument handling, and calls one of the interface functions described
  3522. below.
  3523.  
  3524.   The procedures described in this section are the calls that  the  kernel  may
  3525. make to a memory manager either as a result of a user action on a memory object
  3526. or as part of the kernel's physical memory management. To be  useful  a  memory
  3527. manager  must  define  a  least a couple more protocols. It must make a service
  3528. port available to potential clients and it must provide a way  for  clients  to
  3529. get  a  memory  object  port  to  hand  to the vm_map call. It may also wish to
  3530. provide calls for clients to get or pass information about  a  specific  memory
  3531. object. The memory object name port can be used for this purpose.
  3532.  
  3533.   The  kernel  includes  a  default  memory  manager which handles those memory
  3534. objects that it needs to create  or  are  created  by  a  user  with  the  call
  3535. vm_allocate.  The user may substitute a new default memory manager if he wishes
  3536. with the privileged call vm_set_default_memory_manager.  The final two calls in
  3537. the  section are only made to the default memory manager. Other memory managers
  3538. need not provide these calls.
  3539.  
  3540.   These calls are the result of an asynchronous message  sent  by  the  kernel,
  3541. i.e.,  the  kernel  does  not  wait for a reply to the message.  Thus the error
  3542. returned from these calls are ignored; however, most require some action on the
  3543. part  of  the  memory  manager.  These response actions need not necessarily be
  3544. done in the order requested, but should be done as soon as practical.
  3545.  
  3546.   The calls that are made by the kernel to all memory managers are:
  3547.  
  3548.    - memory_object_init
  3549.  
  3550.    - memory_object_data_request
  3551.  
  3552.    - memory_object_data_write
  3553.  
  3554.    - memory_object_data_unlock
  3555.  
  3556.    - memory_object_lock_completed
  3557.  
  3558.    - memory_object_copy
  3559.  
  3560.    - memory_object_terminate
  3561.  
  3562.   The following two calls must also be provided by the default memory manager.
  3563.  
  3564.    - memory_object_create
  3565.  
  3566.    - memory_object_data_initialize
  3567. memory_object_server
  3568.  
  3569. #include <mach.h>
  3570.  
  3571. boolean_t memory_object_server(in_msg, out_msg)
  3572.         msg_header_t    *in_msg;
  3573.         msg_header_t    *out_msg;
  3574.  
  3575.  
  3576. Description
  3577.  
  3578.   A memory manager is a server task that responds to specific messages from the
  3579. kernel in order to handle memory management functions for the kernel.
  3580.  
  3581.   In  order  to  isolate  the  memory  manager  from  the  specifics of message
  3582. formatting,  the  remote  procedure  call  generator  produces   a   procedure,
  3583. memory_object_server,  to  handle  a  received message.  This function does all
  3584. necessary argument handling, and actually calls one of the following functions:
  3585. memory_object_init,    memory_object_data_write,    memory_object_data_request,
  3586. memory_object_data_unlock,  memory_object_lock_completed,   memory_object_copy,
  3587. memory_object_terminate.  A  default  memory  manager  may  get  two additional
  3588. requests      from       the       kernel:       memory_object_create       and
  3589. memory_object_data_initialize.
  3590.  
  3591.   The  return  value  from the memory_object_server function indicates that the
  3592. message was appropriate to the memory management interface (returning TRUE), or
  3593. that it could not handle this message (returning FALSE).
  3594.  
  3595. Arguments
  3596.  
  3597.   in_msg          The message that has been received from the kernel.
  3598.  
  3599.   out_msg         A reply message. Not used for this server
  3600.  
  3601. Returns
  3602.  
  3603.   TRUE            From  memory_object_server,  indicates  that  the  message in
  3604.                   question was applicable  to  this  interface,  and  that  the
  3605.                   appropriate routine was called to interpret the message.
  3606.  
  3607.   FALSE           From memory_object_server, indicates that the message did not
  3608.                   apply to this interface, and that no other action was taken.
  3609.  
  3610. See Also
  3611.  
  3612.   memory_object_init,memory_object_data_request,memory_object_data_unlock,
  3613. memory_object_data_write,memory_object_copy,memory_object_terminate,
  3614. memory_object_lock_completed,                    memory_object_data_initialize,
  3615. memory_object_create
  3616. memory_object_init
  3617.  
  3618. #include <mach.h>
  3619.  
  3620. kern_return_t memory_object_init(memory_object, memory_control,
  3621.                             memory_object_name, memory_object_page_size)
  3622.         memory_object_t memory_object;
  3623.         memory_object_control_t
  3624.                         memory_control;
  3625.         memory_object_name_t
  3626.                         memory_object_name;
  3627.         vm_size_t       memory_object_page_size;
  3628.  
  3629.  
  3630. Description
  3631.  
  3632.   memory_object_init serves as a notification that a MACH kernel has been asked
  3633. to  map  the  given  memory  object  into  a  task's  virtual  address   space.
  3634. Additionally,  it  provides  a port on which the memory manager may issue cache
  3635. management requests, and a port which the kernel will use  to  name  this  data
  3636. region.    In  the  event that different MACH kernels are asked to map the same
  3637. memory object, each will perform a memory_object_init call with new request and
  3638. name  ports.    The  virtual  page  size  that is used by the calling kernel is
  3639. included for planning purposes.
  3640.  
  3641.   When the memory manager is prepared to accept  requests  for  data  for  this
  3642. object,  it  should  call  memory_object_set_attribute with the attribute ready
  3643. set. Othewise the kernel will not process requests on this object.
  3644.  
  3645. Arguments
  3646.  
  3647.   memory_object   The port that represents the memory object data, as  supplied
  3648.                   to the kernel in a vm_map call.
  3649.  
  3650.   memory_control  The  request  port to which a response is requested.  [In the
  3651.                   event that a memory object has been supplied to more than one
  3652.                   MACH  kernel,  this  argument  identifies the kernel that has
  3653.                   made the request.]
  3654.  
  3655.   memory_object_name
  3656.                   A  port used by the kernel to refer to the memory object data
  3657.                   in reponse to vm_region calls.
  3658.  
  3659.   memory_object_page_size
  3660.                   The  page  size to be used by this kernel.  All data sizes in
  3661.                   calls involving this kernel must be an integral  multiple  of
  3662.                   the  page  size.   [Note that different kernels, indicated by
  3663.                   different memory_controls may have different page sizes.]
  3664.  
  3665. Returns
  3666.  
  3667.   KERN_SUCCESS    Since this routine is called by the kernel,  which  does  not
  3668.                   wait for a reply message, this value is ignored.
  3669.  
  3670. See Also
  3671.  
  3672.   memory_object_set_attributes
  3673. memory_object_data_request
  3674.  
  3675. #include <mach.h>
  3676.  
  3677. kern_return_t memory_object_data_request(memory_object,memory_control,
  3678.                              offset, length, desired_access)
  3679.         memory_object_t memory_object;
  3680.         memory_object_control_t
  3681.                         memory_control;
  3682.         vm_offset_t     offset;
  3683.         vm_size_t       length;
  3684.         vm_prot_t       desired_access;
  3685.  
  3686.  
  3687. Description
  3688.  
  3689.   memory_object_data_request  is  a  request for data from the specified memory
  3690. object, for at least the access specified.  The memory manager is  expected  to
  3691. return  at least the specified data, with as much access as it can allow, using
  3692. memory_object_data_provided.  If the memory manager is unable  to  provide  the
  3693. data   (for   example,   because   of   a  hardware  error),  it  may  use  the
  3694. memory_object_data_error call.  memory_object_data_unavailable call may be used
  3695. to tell the kernel to supply zero-filled memory for this region.
  3696.  
  3697. Arguments
  3698.  
  3699.   memory_object   The  port that represents the memory object data, as supplied
  3700.                   to the kernel in a vm_map call.
  3701.  
  3702.   memory_control  The request port to which a response is requested.   [In  the
  3703.                   event that a memory object has been supplied to more than one
  3704.                   MACH kernel, this argument identifies  the  kernel  that  has
  3705.                   made the request.]
  3706.  
  3707.   offset          The  offset within a memory object to which this call refers.
  3708.                   This will be page aligned.
  3709.  
  3710.   length          The number of bytes of data, starting  at  offset,  to  which
  3711.                   this  call  refers. This will be an integral number of memory
  3712.                   object pages.
  3713.  
  3714.   desired_access  A protection value describing the memory access  modes  which
  3715.                   must  be  permitted on the specified cached data. One or more
  3716.                   of:  VM_PROT_READ, VM_PROT_WRITE or VM_PROT_EXECUTE.
  3717.  
  3718. Returns
  3719.  
  3720.   KERN_SUCCESS    Since this routine is called by the kernel,  which  does  not
  3721.                   wait for a reply message, this value is ignored.
  3722.  
  3723. See Also
  3724.  
  3725.   memory_object_data_provided,                        memory_object_data_error,
  3726. memory_object_data_unavailable
  3727. memory_object_data_write
  3728.  
  3729. #include <mach.h>
  3730.  
  3731. kern_return_t   memory_object_data_write(memory_object, memory_control,
  3732.                                 offset, data, data_count)
  3733.         memory_object_t memory_object;
  3734.         memory_object_control_t
  3735.                         memory_control;
  3736.         vm_offset_t     offset;
  3737.         pointer_t       data;
  3738.         unsigned int    data_count;
  3739.  
  3740.  
  3741. Description
  3742.  
  3743.   memory_object_data_write provides the memory manager with data that has  been
  3744. modified  while  cached  in physical memory.  Once the memory manager no longer
  3745. needs this data (e.g., it has been  written  to  another  storage  medium),  it
  3746. should be deallocated using vm_deallocate.
  3747.  
  3748. Arguments
  3749.  
  3750.   memory_object   The  port that represents the memory object data, as supplied
  3751.                   to the kernel in a vm_map call.
  3752.  
  3753.   memory_control  The request port to which a response is requested.   [In  the
  3754.                   event that a memory object has been supplied to more than one
  3755.                   MACH kernel, this argument identifies  the  kernel  that  has
  3756.                   made the request.]
  3757.  
  3758.   offset          The  offset within a memory object to which this call refers.
  3759.                   This will be page aligned.
  3760.  
  3761.   data            Data which has been modified while cached in physical memory.
  3762.  
  3763.   data_count      The amount of data to be written, in bytes.  This will be  an
  3764.                   integral number of memory object pages.
  3765.  
  3766. Returns
  3767.  
  3768.   KERN_SUCCESS    Since  this  routine  is called by the kernel, which does not
  3769.                   wait for a reply message, this value is ignored.
  3770.  
  3771. See Also
  3772.  
  3773.   vm_deallocate
  3774. memory_object_data_unlock
  3775.  
  3776. #include <mach.h>
  3777.  
  3778. kern_return_t memory_object_data_unlock(memory_object, memory_control,
  3779.                             offset, length, desired_access)
  3780.         memory_object_t memory_object;
  3781.         memory_object_control_t
  3782.                         memory_control;
  3783.         vm_offset_t     offset;
  3784.         vm_size_t       length;
  3785.         vm_prot_t       desired_access;
  3786.  
  3787.  
  3788. Description
  3789.  
  3790.   memory_object_data_unlock is a request that  the  memory  manager  permit  at
  3791. least the desired access to the specified data cached by the kernel.  A call to
  3792. memory_object_lock_request is expected in response.
  3793.  
  3794. Arguments
  3795.  
  3796.   memory_object   The port that represents the memory object data, as  supplied
  3797.                   to the kernel in a vm_map call.
  3798.  
  3799.   memory_control  The  request  port to which a response is requested.  [In the
  3800.                   event that a memory object has been supplied to more than one
  3801.                   MACH  kernel,  this  argument  identifies the kernel that has
  3802.                   made the request.]
  3803.  
  3804.   offset          The offset within a memory object to which this call  refers.
  3805.                   This will be page aligned.
  3806.  
  3807.   length          The  number  of  bytes  of data, starting at offset, to which
  3808.                   this call refers. This will be an integral number  of  memory
  3809.                   object pages.
  3810.  
  3811.   desired_access  A  protection  value describing the memory access modes which
  3812.                   must be permitted on the specified cached data. One  or  more
  3813.                   of:  VM_PROT_READ, VM_PROT_WRITE or VM_PROT_EXECUTE.
  3814.  
  3815. Returns
  3816.  
  3817.   KERN_SUCCESS    Since  this  routine  is called by the kernel, which does not
  3818.                   wait for a reply message, this value is ignored.
  3819.  
  3820. See Also
  3821.  
  3822.   memory_object_lock_request,memory_object_lock_completed
  3823. memory_object_copy
  3824.  
  3825. #include <mach.h>
  3826.  
  3827. kern_return_t memory_object_copy(old_memory_object, old_memory_control,
  3828.                                 offset, length, new_memory_object)
  3829.      memory_object_t            old_memory_object;
  3830.      memory_object_control_t    old_memory_control;
  3831.      vm_offset_t                offset;
  3832.      vm_size_t                  length;
  3833.      memory_object_t            new_memory_object;
  3834.  
  3835.  
  3836.  
  3837. Description
  3838.  
  3839.   memory_object_copy indicates that a copy has been made of the specified range
  3840. of  the  given  original memory object.  This call includes only the new memory
  3841. object itself; a memory_object_init call will be made on the new memory  object
  3842. after the currently cached pages of the original object are prepared. After the
  3843. memory  manager  receives  the  init   call,   it   should   reply   with   the
  3844. memory_object_set_attributes  call  to assert the "ready" attribute. The kernel
  3845. will use the new memory object, contol and name ports to refer to the new copy.
  3846.  
  3847.   This call is made when the original memory object had the  caching  parameter
  3848. set to MEMORY_OBJECT_COPY_CALL and a user of the object has asked the kernel to
  3849. copy it.
  3850.  
  3851.   Cached pages from the  original  memory  object  at  the  time  of  the  copy
  3852. operation  are handled as follows: Readable pages may be silently copied to the
  3853. new memory object (with all access permissions). Pages not copied are locked to
  3854. prevent write access.
  3855.  
  3856.   The  new  memory  object is temporary, meaning that the memory manager should
  3857. not change its contents or allow the memory object  to  be  mapped  in  another
  3858. client.   The memory manager may use the memory_object_data_unavailable call to
  3859. indicate that the appropriate pages of the original memory object may  be  used
  3860. to fulfill the data request.
  3861.  
  3862. Arguments
  3863.  
  3864.   old_memory_object
  3865.                   The port that represents the old memory object date.
  3866.  
  3867.   old_memory_contol
  3868.                   The kernel control port for the old object.
  3869.  
  3870.   offset          The  offset within a memory object to which this call refers.
  3871.                   This will be page aligned.
  3872.  
  3873.   length          The number of bytes of data, starting  at  offset,  to  which
  3874.                   this  call  refers. This will be an integral number of memory
  3875.                   object pages.
  3876.  
  3877.   new_memory_object
  3878.                   A  new  memory object created by the kernel; see synopsis for
  3879.                   further description.  Note that all  port  rights  (including
  3880.                   receive rights) are included for the new memory object.
  3881.  
  3882. Returns
  3883.  
  3884.   KERN_SUCCESS    Since  this  routine  is called by the kernel, which does not
  3885.                   wait for a reply message, this value is ignored.
  3886.  
  3887. See Also
  3888.  
  3889.   memory_object_init,                             memory_object_set_attributes,
  3890. memory_object_data_unavailable
  3891. memory_object_terminate
  3892.  
  3893. #include <mach.h>
  3894.  
  3895. kern_return_t memory_object_terminate(memory_object, memory_control,
  3896.                              memory_object_name)
  3897.         memory_object_t memory_object;
  3898.                       memory_object_control_t
  3899.                         memory_control;
  3900.                        memory_object_name_t
  3901.                         memory_object_name;
  3902.  
  3903.  
  3904. Description
  3905.  
  3906.   memory_object_terminate  indicates that the MACH kernel has completed its use
  3907. of the given memory object.  All rights to the memory object control  and  name
  3908. ports  are  included,  so  that  the  memory  manager  can  destroy them (using
  3909. port_deallocate)  after  doing  appropriate  bookkeeping.    The  kernel   will
  3910. terminate  a memory object only after all address space mappings of that memory
  3911. object have been deallocated, or upon explicit request by the memory manager.
  3912.  
  3913. Arguments
  3914.  
  3915.   memory_object   The port that represents the memory object data, as  supplied
  3916.                   to the kernel in a vm_map call.
  3917.  
  3918.   memory_control  The  request  port to which a response is requested.  [In the
  3919.                   event that a memory object has been supplied to more than one
  3920.                   MACH  kernel,  this  argument  identifies the kernel that has
  3921.                   made the request.]
  3922.  
  3923.   memory_object_name
  3924.                   A  port used by the kernel to refer to the memory object data
  3925.                   in reponse to vm_region calls.
  3926.  
  3927. Returns
  3928.  
  3929.   KERN_SUCCESS    Since this routine is called by the kernel,  which  does  not
  3930.                   wait for a reply message, this value is ignored.
  3931.  
  3932. See Also
  3933.  
  3934.   memory_object_destroy, port_deallocate
  3935. memory_object_create
  3936.  
  3937. #include <mach.h>
  3938.  
  3939. kern_return_t memory_object_create(old_memory_object,new_memory_object,
  3940.                             new_object_size,  new_control,
  3941.                             new_name, new_page_size)
  3942.         memory_object_t old_memory_object;
  3943.                         memory_object_t
  3944.                         new_memory_object;
  3945.         vm_size_t       new_object_size;
  3946.         memory_object_control_t
  3947.                         new_control;
  3948.         memory_object_name_t
  3949.                         new_name;
  3950.         vm_size_t       new_page_size;
  3951.  
  3952.  
  3953. Description
  3954.  
  3955.   memory_object_create  is  a  request  that  the  given  memory manager accept
  3956. responsibility for the given memory object created by the kernel.    This  call
  3957. will  only  be made to the system default memory manager.  The memory object in
  3958. question initially consists of zero-filled memory; only memory pages  that  are
  3959. actually  written will ever be provided to the memory manager.  When processing
  3960. memory_object_data_request  calls,  the  default  memory   manager   must   use
  3961. memory_object_data_unavailable  for  any  pages  that  have not previously been
  3962. written.
  3963.  
  3964.   No reply is expected after this call. Since this  call  is  directed  to  the
  3965. default memory manager, the kernel assumes that it will be ready to handle data
  3966. requests  to  this  object  and  does  not   need   the   confirmation   of   a
  3967. memory_object_set_attributes call.
  3968.  
  3969. Arguments
  3970.  
  3971.   old_memory_object
  3972.                   A memory object provided by the  default  memory  manager  on
  3973.                   which the kernel can make memory_object_create calls.
  3974.  
  3975.   new_memory_object
  3976.                   A new memory object created by the kernel; see  synopsis  for
  3977.                   further  description.    Note that all port rights (including
  3978.                   receive rights) are included for the new memory object.
  3979.  
  3980.   new_object_size Maximum size of the new object.
  3981.  
  3982.   new_control     A port, created by the kernel, on which a memory manager  may
  3983.                   issue cache management requests for the new object.
  3984.  
  3985.   new_name        A  port  used by the kernel to refer to the new memory object
  3986.                   data in response to vm_region calls.
  3987.  
  3988.   new_page_size   The page size to be used by this kernel.  All data  sizes  in
  3989.                   calls  involving  this kernel must be an integral multiple of
  3990.                   the page size.  [Note that different  kernels,  indicated  by
  3991.                   different memory_controls may have different page sizes.]
  3992.  
  3993. Returns
  3994.  
  3995.   KERN_SUCCESS    Since  this  routine  is called by the kernel, which does not
  3996.                   wait for a reply message, this value is ignored.
  3997.  
  3998. See Also
  3999.  
  4000.   memory_object_data_initialize
  4001. memory_object_data_initialize
  4002.  
  4003. #include <mach.h>
  4004.  
  4005. kern_return_t memory_object_data_initialize(memory_object,memory_control,
  4006.                                 offset, data, data_count)
  4007.         memory_object_t memory_object;
  4008.         memory_object_control_t
  4009.                         memory_control;
  4010.         vm_offset_t     offset;
  4011.         pointer_t       data;
  4012.         unsigned int    data_count;
  4013.  
  4014.  
  4015.  
  4016. Description
  4017.  
  4018.   memory_object_data_initialize provides the memory manager with  initial  data
  4019. for  a  kernel-created  memory  object.  If the memory manager already has been
  4020. supplied    data    (by    a    previous    memory_object_data_initialize    or
  4021. memory_object_data_write),  then  this data should be ignored.  Otherwise, this
  4022. call behaves exactly as does memory_object_data_write.  This call will only  be
  4023. made  on memory objects created by the kernel via memory_object_create and thus
  4024. will only be made to default memory managers.  This call will not  be  made  on
  4025. objects created via memory_object_copy.
  4026.  
  4027. Arguments
  4028.  
  4029.   memory_object   The  port that represents the memory object data, as supplied
  4030.                   by the kernel in a memory_object_create call.
  4031.  
  4032.   memory_control  The request port to which a response is requested.   [In  the
  4033.                   event that a memory object has been supplied to more than one
  4034.                   MACH kernel, this argument identifies  the  kernel  that  has
  4035.                   made the request.]
  4036.  
  4037.   offset          The  offset within a memory object to which this call refers.
  4038.                   This will be page aligned.
  4039.  
  4040.   data            Data which has been modified while cached in physical memory.
  4041.  
  4042.   data_count      The amount of data to be written, in bytes. This will  be  an
  4043.                   integral number of memory object pages.
  4044.  
  4045. Returns
  4046.  
  4047.   KERN_SUCCESS    Since  this  routine  is called by the kernel, which does not
  4048.                   wait for a reply message, this value is ignored.
  4049.  
  4050. See Also
  4051.  
  4052.   memory_object_data_write, memory_object_create
  4053. I. Summary of Kernel Calls
  4054.  
  4055.   The following is a summary of calls to the MACH kernel.  The  page  on  which
  4056. the operation is fully described appears within square brackets.
  4057.  
  4058.  
  4059. [4]  msg_return_t msg_send(header, option, timeout)
  4060.              msg_header_t    *header;
  4061.              msg_option_t    option;
  4062.              msg_timeout_t   timeout;
  4063.  
  4064.  
  4065.  
  4066.  
  4067. [5]  msg_return_t msg_receive(header, option, timeout)
  4068.              msg_header_t    *header;        /* in/out */
  4069.              msg_option_t    option;
  4070.              msg_timeout_t   timeout;
  4071.  
  4072.  
  4073.  
  4074.  
  4075. [6]  msg_return_t msg_rpc(header, option, rcv_size,
  4076.                              send_timeout, rcv_timeout)
  4077.              msg_header_t    *header;        /* in/out */
  4078.              msg_option_t    option;
  4079.              msg_size_t      rcv_size;
  4080.              msg_timeout_t   send_timeout;
  4081.              msg_timeout_t   rcv_timeout;
  4082.  
  4083.  
  4084.  
  4085.  
  4086. [8]  kern_return_t port_names(task,
  4087.                               portnames, portnamesCnt,
  4088.                               port_types, port_typesCnt)
  4089.              task_t task;
  4090.              port_name_array_t *portnames;   /* out array */
  4091.              unsigned int *portnamesCnt;     /* out */
  4092.              port_type_array_t *port_types;  /* out array */
  4093.              unsigned int *port_typesCnt;    /* out */
  4094.  
  4095.  
  4096.  
  4097.  
  4098. [9]  kern_return_t port_type(task, port_name, port_type)
  4099.              task_t task;
  4100.              port_name_t port_name;
  4101.              port_type_t *port_type;         /* out */
  4102.  
  4103.  
  4104.  
  4105.  
  4106. [10] kern_return_t port_rename(task, old_name, new_name)
  4107.              task_t task;
  4108.              port_name_t old_name;
  4109.              port_name_t new_name;
  4110.  
  4111.  
  4112.  
  4113.  
  4114. [11] kern_return_t port_allocate(task, port_name)
  4115.              task_t task;
  4116.              port_name_t *port_name;         /* out */
  4117.  
  4118.  
  4119.  
  4120.  
  4121. [12] kern_return_t port_deallocate(task, port_name)
  4122.              task_t task;
  4123.              port_name_t port_name;
  4124.  
  4125.  
  4126.  
  4127.  
  4128. [13] kern_return_t port_status(task, port_name, enabled,
  4129.                                num_msgs, backlog, owner, receiver)
  4130.              task_t task;
  4131.              port_name_t port_name;
  4132.              port_set_name_t *enabled;       /* out */
  4133.              int *num_msgs;                  /* out */
  4134.              int *backlog;                   /* out */
  4135.              boolean_t *owner;               /* out */
  4136.              boolean_t *receiver;            /* out */
  4137.  
  4138.  
  4139.  
  4140.  
  4141. [14] kern_return_t port_set_backlog(task, port_name, backlog)
  4142.              task_t task;
  4143.              port_name_t port_name;
  4144.              int backlog;
  4145.  
  4146.  
  4147.  
  4148.  
  4149. [15] kern_return_t port_set_backup(task, primary, backup, previous)
  4150.              task_t task;
  4151.              port_name_t primary;
  4152.              port_t backup;
  4153.              port_t *previous;       /* out */
  4154.  
  4155.  
  4156.  
  4157.  
  4158. [16] kern_return_t port_set_allocate(task, set_name)
  4159.              task_t task;
  4160.              port_set_name_t *set_name;      /* out */
  4161.  
  4162.  
  4163.  
  4164.  
  4165. [17] kern_return_t port_set_deallocate(task, set_name)
  4166.              task_t task;
  4167.              port_set_name_t set_name;
  4168.  
  4169.  
  4170.  
  4171.  
  4172. [18] kern_return_t port_set_add(task, set_name, port_name)
  4173.              task_t task;
  4174.              port_set_name_t set_name;
  4175.              port_name_t port_name;
  4176.  
  4177.  
  4178.  
  4179.  
  4180. [19] kern_return_t port_set_remove(task, port_name)
  4181.              task_t task;
  4182.              port_name_t port_name;
  4183.  
  4184.  
  4185.  
  4186.  
  4187. [20] kern_return_t port_set_status(task, set_name, members, membersCnt)
  4188.              task_t task;
  4189.              port_set_name_t set_name;
  4190.              port_name_array_t *members;     /* out array */
  4191.              unsigned int *membersCnt;       /* out */
  4192.  
  4193.  
  4194.  
  4195.  
  4196. [21] kern_return_t port_insert_send(task, my_port, his_name)
  4197.              task_t task;
  4198.              port_t my_port;
  4199.              port_name_t his_name;
  4200.  
  4201.  
  4202.  
  4203.  
  4204. [21] kern_return_t port_insert_receive(task, my_port, his_name)
  4205.              task_t task;
  4206.              port_t my_port;
  4207.              port_name_t his_name;
  4208.  
  4209.  
  4210.  
  4211.  
  4212. [22] kern_return_t port_extract_send(task, his_name, his_port)
  4213.              task_t task;
  4214.              port_name_t his_name;
  4215.              port_t *his_port;               /* out */
  4216.  
  4217.  
  4218.  
  4219.  
  4220. [22] kern_return_t port_extract_receive(task, his_name, his_port)
  4221.              task_t task;
  4222.              port_name_t his_name;
  4223.              port_t *his_port;               /* out */
  4224.  
  4225.  
  4226.  
  4227.  
  4228. [24] kern_return_t task_create(parent_task, inherit_memory,
  4229.                                       child_task)
  4230.              task_t          parent_task
  4231.              boolean_t       inherit_memory;
  4232.              task_t          *child_task;    /* out */
  4233.  
  4234.  
  4235.  
  4236.  
  4237. [25] kern_return_t task_terminate(target_task)
  4238.              task_t          target_task;
  4239.  
  4240.  
  4241.  
  4242.  
  4243. [26] kern_return_t task_suspend(target_task)
  4244.              task_t          target_task;
  4245.  
  4246.  
  4247.  
  4248.  
  4249. [27] kern_return_t task_resume(target_task)
  4250.              task_t          target_task;
  4251.  
  4252. [28] kern_return_t task_get_special_port(task, which_port, special_port)
  4253.              task_t          task;
  4254.              int             which_port;
  4255.              port_t          *special_port;  /* out */
  4256.  
  4257.  
  4258.  
  4259.  
  4260. [28] kern_return_t task_set_special_port(task, which_port, special_port)
  4261.              task_t          task;
  4262.              int             which_port;
  4263.              port_t          special_port;
  4264.  
  4265.  
  4266.  
  4267.  
  4268.  
  4269. [28] task_t task_self()
  4270.  
  4271.  
  4272.  
  4273.  
  4274. [28] port_t task_notify()
  4275.  
  4276.  
  4277.  
  4278.  
  4279.  
  4280. [29] kern_return_t task_info(target_task, flavor, task_info, task_infoCnt)
  4281.              task_t          target_task;
  4282.              int             flavor;
  4283.              task_info_t     task_info;      /* in and out */
  4284.              unsigned int    *task_infoCnt;  /* in and out */
  4285.  
  4286.  
  4287.  
  4288.  
  4289. [30] kern_return_t task_threads(target_task, thread_list, thread_count)
  4290.              task_t          target_task;
  4291.              thread_array_t  *thread_list;   /* out, ptr to array */
  4292.              int             *thread_count;  /* out */
  4293.  
  4294.  
  4295.  
  4296.  
  4297. [31] kern_return_t thread_create(parent_task, child_thread)
  4298.              task_t          parent_task;
  4299.              thread_t        *child_thread;  /* out */
  4300.  
  4301.  
  4302.  
  4303.  
  4304. [32] kern_return_t thread_terminate(target_thread)
  4305.              thread_t        target_thread;
  4306.  
  4307.  
  4308.  
  4309.  
  4310. [33] kern_return_t thread_suspend(target_thread);
  4311.              thread_t        target_thread;
  4312.  
  4313.  
  4314.  
  4315.  
  4316. [34] kern_return_t thread_resume(target_thread)
  4317.              thread_t        target_thread;
  4318.  
  4319.  
  4320.  
  4321.  
  4322. [35] kern_return_t thread_abort(target_thread)
  4323.              thread_t        target_thread;
  4324.  
  4325.  
  4326.  
  4327.  
  4328. [36] kern_return_t thread_get_special_port(thread, which_port, special_port)
  4329.              thread_t        thread;
  4330.              int             which_port;
  4331.              port_t          *special_port;
  4332.  
  4333.  
  4334.  
  4335.  
  4336. [36] kern_return_t thread_set_special_port(thread, which_port, special_port)
  4337.              thread_t        thread;
  4338.              int             which_port;
  4339.              port_t          special_port;
  4340.  
  4341.  
  4342.  
  4343.  
  4344. [36] thread_t thread_self()
  4345.  
  4346.  
  4347.  
  4348.  
  4349. [36] port_t thread_reply()
  4350.  
  4351.  
  4352.  
  4353.  
  4354. [37] kern_return_t thread_info(target_thread, flavor, thread_info,
  4355.                                      thread_infoCnt)
  4356.              thread_t                target_thread;
  4357.              int                     flavor;
  4358.              thread_info_t           thread_info;    /* in and out */
  4359.              unsigned int            *thread_infoCnt;  /* in and out */
  4360.  
  4361.  
  4362.  
  4363.  
  4364. [38] kern_return_t thread_get_state(target_thread, flavor, old_state,
  4365.                                      old_stateCnt)
  4366.              thread_t                target_thread;
  4367.              int                     flavor;
  4368.              thread_state_data_t     old_state;      /* in and out */
  4369.              unsigned int            *old_stateCnt;  /* in and out */
  4370.  
  4371.  
  4372.  
  4373.  
  4374. [38] kern_return_t thread_set_state(target_thread, flavor, new_state,
  4375.                                      new_stateCnt)
  4376.              thread_t                target_thread;
  4377.              int                     flavor;
  4378.              thread_state_data_t     new_state;
  4379.              unsigned int            new_stateCnt;
  4380.  
  4381.  
  4382.  
  4383.  
  4384. [40] kern_return_t vm_allocate(target_task, address, size, anywhere)
  4385.              vm_task_t       target_task;
  4386.              vm_address_t    *address;       /* in/out */
  4387.              vm_size_t       size;
  4388.              boolean_t       anywhere;
  4389.  
  4390.  
  4391.  
  4392.  
  4393. [41] kern_return_t vm_deallocate(target_task, address, size)
  4394.              vm_task_t       target_task;
  4395.              vm_address_t    address;
  4396.              vm_size_t       size;
  4397.  
  4398.  
  4399.  
  4400.  
  4401. [42] kern_return_t vm_read(target_task, address, size, data, data_count)
  4402.              vm_task_t       target_task
  4403.              vm_address_t    address;
  4404.              vm_size_t       size;
  4405.              pointer_t       *data;          /* out */
  4406.              int             *data_count;    /* out */
  4407.  
  4408.  
  4409.  
  4410.  
  4411. [43] kern_return_t vm_write(target_task, address, data, data_count)
  4412.              vm_task_t       target_task;
  4413.              vm_address_t    address;
  4414.              pointer_t       data;
  4415.              int             data_count;
  4416.  
  4417.  
  4418.  
  4419.  
  4420. [44] kern_return_t vm_copy (target_task, source_address, count, dest_address)
  4421.              vm_task_t       target_task;
  4422.              vm_address_t    source_address;
  4423.              vm_size_t       count;
  4424.              vm_address_t    dest_address;
  4425.  
  4426.  
  4427.  
  4428.  
  4429. [45] kern_return_t  vm_region(target_task, address, size, protection,
  4430.                               max_protection, inheritance, shared,
  4431.                               object_name, offset)
  4432.              vm_task_t               target_task;
  4433.              vm_address_t            *address;               /* in/out */
  4434.              vm_size_t               *size;                  /* out */
  4435.              vm_prot_t               *protection;            /* out */
  4436.              vm_prot_t               *max_protection;        /* out */
  4437.              vm_inherit_t            *inheritance;           /* out */
  4438.              boolean_t               *shared;                /* out */
  4439.              port_t                  *object_name;           /* out */
  4440.              vm_offset_t             *offset;                /* out */
  4441.  
  4442.  
  4443.  
  4444.  
  4445. [46] kern_return_t vm_protect(target_task, address, size, set_maximum,
  4446.                                      new_protection)
  4447.              vm_task_t       target_task;
  4448.              vm_address_t    address;
  4449.              vm_size_t       size;
  4450.              boolean_t       set_maximum;
  4451.              vm_prot_t       new_protection;
  4452.  
  4453.  
  4454.  
  4455.  
  4456. [47] kern_return_t vm_inherit(target_task, address, size, new_inheritance)
  4457.              vm_task_t       target_task;
  4458.              vm_address_t    address;
  4459.              vm_size_t       size;
  4460.              vm_inherit_t    new_inheritance;
  4461.  
  4462.  
  4463.  
  4464.  
  4465. [48] kern_return_t   vm_statistics(target_task, vm_stats)
  4466.              task_t                  target_task;
  4467.              vm_statistics_data_t    *vm_stats;      /* out */
  4468.  
  4469.  
  4470.  
  4471.  
  4472. [49] kern_return_t vm_machine_attribute (task, address, size, attribute, value)
  4473.              task_t                           task;
  4474.              vm_address_t                     address;
  4475.              vm_size_t                        size;
  4476.              vm_machine_attribute_t           attribute;
  4477.              vm_machine_attribute_val_t      *value;
  4478.  
  4479.  
  4480.  
  4481.  
  4482. [51] kern_return_t mach_ports_register(target_task,
  4483.                                      init_port_set, init_port_array_count)
  4484.              task_t          target_task;
  4485.              port_array_t    init_port_set;         /* array */
  4486.              int             init_port_array_count;
  4487.  
  4488.  
  4489.  
  4490.  
  4491. [51] kern_return_t mach_ports_lookup(target_task,
  4492.                                      init_port_set, init_port_array_count)
  4493.              task_t          target_task;
  4494.              port_array_t    *init_port_set;         /* out array */
  4495.              int             *init_port_array_count; /* out */
  4496.  
  4497.  
  4498.  
  4499.  
  4500. [52] kern_return_t host_ipc_statistics(task, statistics)
  4501.              task_t target_task;
  4502.              ipc_statistics_t *statistics;   /* inout */
  4503.  
  4504.  
  4505.  
  4506.  
  4507. [54] kern_return_t vm_map(target_task, address, size, mask, anywhere,
  4508.                                      memory_object, offset, copy,
  4509.                                      cur_protection, max_protection,
  4510.                                      inheritance)
  4511.              task_t          target_task;
  4512.              vm_offset_t     *address;       /* in/out */
  4513.              vm_size_t       size;
  4514.              vm_offset_t     mask;
  4515.              boolean_t       anywhere;
  4516.              memory_object_t memory_object;
  4517.              vm_offset_t     offset;
  4518.              boolean_t       copy;
  4519.              vm_prot_t       cur_protection;
  4520.              vm_prot_t       max_protection;
  4521.              vm_inherit_t    inheritance;
  4522.  
  4523.  
  4524.  
  4525.  
  4526.  
  4527. [55] kern_return_t memory_object_set_attributes(memory_control,
  4528.                                      object_ready, may_cache_object,
  4529.                                      copy_strategy)
  4530.              memory_object_control_t
  4531.                              memory_control;
  4532.              boolean_t       object_ready;
  4533.              boolean_t       may_cache_object;
  4534.              memory_object_copy_strategy_t
  4535.                              copy_strategy;
  4536.  
  4537.  
  4538.  
  4539.  
  4540. [56] kern_return_t memory_object_get_attributes(memory_control,
  4541.                                      object_ready, may_cache_object,
  4542.                                      copy_strategy)
  4543.              memory_object_control_t
  4544.                              memory_control;
  4545.              boolean_t       *object_ready;
  4546.              boolean_t       *may_cache_object;
  4547.              memory_object_copy_strategy_t
  4548.                              *copy_strategy;
  4549.  
  4550.  
  4551.  
  4552.  
  4553. [57] kern_return_t   memory_object_lock_request(memory_control,
  4554.                                      offset, size, should_clean
  4555.                                      should_flush, lock_value, reply_to)
  4556.              memory_object_control_t
  4557.                              memory_control;
  4558.              vm_offset_t     offset;
  4559.              vm_size_t       size;
  4560.              boolean_t       should_clean;
  4561.              boolean_t       should_flush;
  4562.              vm_prot_t       lock_value;
  4563.              port_t          reply_to;
  4564.  
  4565.  
  4566.  
  4567.  
  4568. [58] kern_return_t memory_object_data_provided(memory_control,
  4569.                                      offset, data, data_count, lock_value)
  4570.              memory_object_control_t
  4571.                              memory_control;
  4572.              vm_offset_t     offset;
  4573.              pointer_t       data;
  4574.              int             data_count;
  4575.              vm_prot_t       lock_value;
  4576.  
  4577.  
  4578.  
  4579.  
  4580.  
  4581. [59] kern_return_t memory_object_data_unavailable(memory_control,
  4582.                                      offset, size);
  4583.              memory_object_control_t
  4584.                              memory_control;
  4585.              vm_offset_t     offset;
  4586.              vm_size_t       size;
  4587.  
  4588.  
  4589.  
  4590.  
  4591. [60] kern_return_t memory_object_data_error(memory_control,
  4592.                                      offset, size, reason);
  4593.              memory_object_control_t
  4594.                              memory_control;
  4595.              vm_offset_t     offset;
  4596.              vm_size_t       size;
  4597.              kern_return_t   reason;
  4598.  
  4599.  
  4600.  
  4601.  
  4602. [61] kern_return_t memory_object_destroy(memory_control, reason);
  4603.              memory_object_control_t
  4604.                              memory_control;
  4605.              kern_return_t   reason;
  4606.  
  4607.  
  4608.  
  4609.  
  4610. [62] routine vm_set_default_memory_manager(host,default_manager)
  4611.              task_t          host;
  4612.              memory_object_t default_manager;        /* in/out */
  4613. II. Summary of External Memory Management Calls
  4614.  
  4615.   The following is a summary of calls that the MACH kernel makes on an external
  4616. memory management server.  The page on which the operation is  fully  described
  4617. appears within square brackets.
  4618.  
  4619.  
  4620. [64] boolean_t memory_object_server(in_msg, out_msg)
  4621.              msg_header_t    *in_msg;
  4622.              msg_header_t    *out_msg;
  4623.  
  4624.  
  4625.  
  4626.  
  4627. [65] kern_return_t memory_object_init(memory_object, memory_control,
  4628.                                  memory_object_name, memory_object_page_size)
  4629.              memory_object_t memory_object;
  4630.              memory_object_control_t
  4631.                              memory_control;
  4632.              memory_object_name_t
  4633.                              memory_object_name;
  4634.              vm_size_t       memory_object_page_size;
  4635.  
  4636.  
  4637.  
  4638.  
  4639. [66] kern_return_t memory_object_data_request(memory_object,memory_control,
  4640.                                   offset, length, desired_access)
  4641.              memory_object_t memory_object;
  4642.              memory_object_control_t
  4643.                              memory_control;
  4644.              vm_offset_t     offset;
  4645.              vm_size_t       length;
  4646.              vm_prot_t       desired_access;
  4647.  
  4648.  
  4649.  
  4650.  
  4651. [67] kern_return_t   memory_object_data_write(memory_object, memory_control,
  4652.                                      offset, data, data_count)
  4653.              memory_object_t memory_object;
  4654.              memory_object_control_t
  4655.                              memory_control;
  4656.              vm_offset_t     offset;
  4657.              pointer_t       data;
  4658.              unsigned int    data_count;
  4659.  
  4660.  
  4661.  
  4662.  
  4663. [68] kern_return_t memory_object_data_unlock(memory_object, memory_control,
  4664.                                  offset, length, desired_access)
  4665.              memory_object_t memory_object;
  4666.              memory_object_control_t
  4667.                              memory_control;
  4668.              vm_offset_t     offset;
  4669.              vm_size_t       length;
  4670.              vm_prot_t       desired_access;
  4671.  
  4672.  
  4673.  
  4674.  
  4675. [69] kern_return_t memory_object_copy(old_memory_object, old_memory_control,
  4676.                                      offset, length, new_memory_object)
  4677.           memory_object_t            old_memory_object;
  4678.           memory_object_control_t    old_memory_control;
  4679.           vm_offset_t                offset;
  4680.           vm_size_t                  length;
  4681.           memory_object_t            new_memory_object;
  4682.  
  4683.  
  4684.  
  4685.  
  4686.  
  4687. [70] kern_return_t memory_object_terminate(memory_object, memory_control,
  4688.                                   memory_object_name)
  4689.              memory_object_t memory_object;
  4690.                            memory_object_control_t
  4691.                              memory_control;
  4692.                             memory_object_name_t
  4693.                              memory_object_name;
  4694.  
  4695.  
  4696.  
  4697.  
  4698. [71] kern_return_t memory_object_create(old_memory_object,new_memory_object,
  4699.                                  new_object_size,  new_control,
  4700.                                  new_name, new_page_size)
  4701.              memory_object_t old_memory_object;
  4702.                              memory_object_t
  4703.                              new_memory_object;
  4704.              vm_size_t       new_object_size;
  4705.              memory_object_control_t
  4706.                              new_control;
  4707.              memory_object_name_t
  4708.                              new_name;
  4709.              vm_size_t       new_page_size;
  4710.  
  4711.  
  4712.  
  4713.  
  4714. [72] kern_return_t memory_object_data_initialize(memory_object,memory_control,
  4715.                                      offset, data, data_count)
  4716.              memory_object_t memory_object;
  4717.              memory_object_control_t
  4718.                              memory_control;
  4719.              vm_offset_t     offset;
  4720.              pointer_t       data;
  4721.              unsigned int    data_count;
  4722.                                Table of Contents
  4723. 1. Introduction                                                               1
  4724.      1.1. Overall system organization                                         1
  4725.      1.2. Basic kernel functionality                                          1
  4726.      1.3. User operating system environments                                  1
  4727. 2. Message primitives                                                         2
  4728.      2.1. Basic terms                                                         2
  4729.      2.2. Ports                                                               2
  4730.      2.3. Port sets                                                           2
  4731.      2.4. Port names                                                          2
  4732.      2.5. Port types                                                          2
  4733.      2.6. Messages                                                            2
  4734. 3. Port and port set primitives                                               7
  4735. 4. Task and thread primitives                                                23
  4736.      4.1. Basic terms                                                        23
  4737.      4.2. Access to Tasks: Terminology                                       23
  4738. 5. Virtual memory primitives                                                 39
  4739.      5.1. Basic terms                                                        39
  4740. 6. Ancillary primitives                                                      50
  4741. 7. External memory management primitives                                     53
  4742.      7.1. Memory Managers                                                    53
  4743.           7.1.1. Memory objects: definitions and basics                      53
  4744.           7.1.2. Initialization and termination                              53
  4745.           7.1.3. Kernel-created memory objects                               53
  4746.      7.2. Kernel calls supporting memory managers                            53
  4747.      7.3. Memory Manager calls                                               63
  4748. I. Summary of Kernel Calls                                                   73
  4749. II. Summary of External Memory Management Calls                              76
  4750.