2 * Copyright (c) 2015-2016 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* File: kern/mach_node.h
32 * Implementation of mach node support.
33 * This is the basis for flipc, which provides inter-node communication.
37 #include <mach/mach_types.h>
38 #include <mach/boolean.h>
39 #include <mach/kern_return.h>
41 #include <kern/kern_types.h>
42 #include <kern/assert.h>
44 #include <kern/host.h>
45 #include <kern/kalloc.h>
46 #include <kern/mach_node_link.h>
47 #include <kern/mach_node.h>
48 #include <kern/ipc_mig.h> // mach_msg_send_from_kernel_proper()
51 #include <ipc/ipc_types.h>
52 #include <ipc/ipc_init.h>
53 #include <ipc/ipc_kmsg.h>
54 #include <ipc/ipc_port.h>
55 #include <ipc/ipc_pset.h>
56 #include <ipc/ipc_table.h>
57 #include <ipc/ipc_entry.h>
59 #include <ipc/flipc.h>
61 #include <libkern/OSAtomic.h> // OSAddAtomic64(), OSCompareAndSwap()
62 #include <libkern/OSByteOrder.h> // OSHostByteOrder()
66 #define MNL_NAME_TABLE_SIZE (256) // Hash is evenly distributed, so ^2 is ok
67 #define MNL_NAME_HASH(name) (name % MNL_NAME_TABLE_SIZE)
69 /*** Visible outside mach_node layer ***/
70 mach_node_id_t localnode_id
= -1; // This node's FLIPC id.
72 mach_node_t localnode
; // This node's mach_node_t struct
75 /*** Private to mach_node layer ***/
76 static int mach_nodes_to_publish
;
77 static mach_node_t mach_node_table
[MACH_NODES_MAX
];
78 static lck_spin_t mach_node_table_lock_data
;
79 #define MACH_NODE_TABLE_LOCK() lck_spin_lock(&mach_node_table_lock_data)
80 #define MACH_NODE_TABLE_UNLOCK() lck_spin_unlock(&mach_node_table_lock_data)
81 #define MACH_NODE_TABLE_LOCK_INIT() lck_spin_init(&mach_node_table_lock_data, \
82 &ipc_lck_grp, &ipc_lck_attr)
84 static volatile SInt64 mnl_name_next
;
85 static queue_head_t mnl_name_table
[MNL_NAME_TABLE_SIZE
];
86 static lck_spin_t mnl_name_table_lock_data
;
87 #define MNL_NAME_TABLE_LOCK() lck_spin_lock(&mnl_name_table_lock_data)
88 #define MNL_NAME_TABLE_UNLOCK() lck_spin_unlock(&mnl_name_table_lock_data)
89 #define MNL_NAME_TABLE_LOCK_INIT() lck_spin_init(&mnl_name_table_lock_data, \
90 &ipc_lck_grp, &ipc_lck_attr)
92 static void mach_node_init(void);
93 static void mnl_name_table_init(void);
94 static void mach_node_table_init(void);
95 static void mach_node_publish(mach_node_t node
);
97 static mach_node_t
mach_node_alloc_init(mach_node_id_t node_id
);
98 static kern_return_t
mach_node_register(mach_node_t node
);
101 /* mach_node_init() is run lazily when a node link driver registers
102 * or the node special port is set.
103 * The variable localnode_id is used to determine if init has already run.
108 mach_node_id_t node_id
= 0; // TODO: Read from device tree?
109 if (OSCompareAndSwap((UInt32
)(HOST_LOCAL_NODE
),
112 printf("mach_node_init(): localnode_id=%d of %d\n",
113 localnode_id
, MACH_NODES_MAX
);
114 mach_node_table_init();
115 mnl_name_table_init();
117 } // TODO: else block until init is finished (init completion race)
121 mach_node_table_init(void)
123 MACH_NODE_TABLE_LOCK_INIT();
124 MACH_NODE_TABLE_LOCK();
126 /* Start with an enpty node table. */
127 bzero(mach_node_table
, sizeof(mach_node_t
) * MACH_NODES_MAX
);
128 mach_nodes_to_publish
= 0;
130 /* Allocate localnode's struct */
131 localnode
= mach_node_for_id_locked(localnode_id
, 1, 1);
132 assert(MACH_NODE_VALID(localnode
));
134 MACH_NODE_TABLE_UNLOCK();
136 /* Set up localnode's struct */
137 bzero(localnode
, sizeof(localnode
));
138 localnode
->info
.datamodel
= LOCAL_DATA_MODEL
;
139 localnode
->info
.byteorder
= OSHostByteOrder();
140 localnode
->info
.proto_vers_min
= MNL_PROTOCOL_V1
;
141 localnode
->info
.proto_vers_max
= MNL_PROTOCOL_V1
;
142 localnode
->proto_vers
= MNL_PROTOCOL_V1
;
143 localnode
->published
= 0;
144 localnode
->active
= 1;
146 MACH_NODE_UNLOCK(localnode
);
149 /* Sends a publication message to the local node's bootstrap server.
150 * This function is smart and will only send a notification if one as really
151 * needed - it can be called speculatively on any node at any time.
153 * Note: MUST be called with the node table lock held.
157 mach_node_publish(mach_node_t node
)
161 if (!MACH_NODE_VALID(node
) || (!node
->active
) || (node
->published
))
162 return; // node is invalid or not suitable for publication
164 ipc_port_t bs_port
= localnode
->bootstrap_port
;
165 if (!IP_VALID(bs_port
))
166 return; // No bootstrap server to notify!
168 /* Node is suitable and server is present, so make registration message */
169 struct mach_node_server_register_msg msg
;
171 msg
.node_header
.header
.msgh_remote_port
= bs_port
;
172 msg
.node_header
.header
.msgh_size
= sizeof(msg
);
173 msg
.node_header
.header
.msgh_local_port
= MACH_PORT_NULL
;
174 msg
.node_header
.header
.msgh_voucher_port
= MACH_PORT_NULL
;
175 msg
.node_header
.header
.msgh_id
= MACH_NODE_SERVER_MSG_ID
;
176 msg
.node_header
.node_id
= node
->info
.node_id
;
177 msg
.node_header
.options
= 0;
178 msg
.datamodel
= node
->info
.datamodel
;
179 msg
.byteorder
= node
->info
.byteorder
;
181 if (node
== localnode
) {
182 msg
.node_header
.identifier
= MACH_NODE_SM_REG_LOCAL
;
183 msg
.node_header
.header
.msgh_bits
=
184 MACH_MSGH_BITS_SET(MACH_MSG_TYPE_COPY_SEND
, 0, 0, 0);
186 msg
.node_header
.identifier
= MACH_NODE_SM_REG_REMOTE
;
187 msg
.node_header
.header
.msgh_local_port
= node
->bootstrap_port
;
188 msg
.node_header
.header
.msgh_bits
= MACH_MSGH_BITS_SET
189 (MACH_MSG_TYPE_COPY_SEND
, MACH_MSG_TYPE_MAKE_SEND
, 0, 0);
192 kr
= mach_msg_send_from_kernel_proper(&msg
.node_header
.header
,
194 if (kr
== KERN_SUCCESS
) {
196 mach_nodes_to_publish
--;
198 printf("mach_node_publish(%d)=%d\n", node
->info
.node_id
, kr
);
201 /* Called whenever the node special port changes */
203 mach_node_port_changed(void)
207 mach_node_init(); // Lazy init of mach_node layer
209 /* Cleanup previous bootstrap port if necessary */
210 MACH_NODE_LOCK(localnode
);
211 flipc_node_retire(localnode
);
212 bs_port
= localnode
->bootstrap_port
;
213 if (IP_VALID(bs_port
)) {
214 localnode
->bootstrap_port
= IP_NULL
;
215 // TODO: destroy send right to outgoing bs_port
218 kernel_get_special_port(host_priv_self(), HOST_NODE_PORT
, &bs_port
);
219 assert(IP_VALID(bs_port
));
220 localnode
->bootstrap_port
= bs_port
;
221 flipc_node_prepare(localnode
);
222 MACH_NODE_UNLOCK(localnode
);
224 /* Cleanup the publication state of all nodes in the table */
225 MACH_NODE_TABLE_LOCK();
226 // TODO: Signup for bootstrap port death notifications
227 localnode
->active
= 1;
229 mach_nodes_to_publish
= 0;
232 for (n
=0; n
<MACH_NODES_MAX
; n
++) {
233 mach_node_t np
= mach_node_table
[n
];
234 // Publish all active nodes (except the local node)
235 if (!MACH_NODE_VALID(np
))
239 mach_nodes_to_publish
++;
242 mach_node_publish(localnode
); // Always publish local node first
244 for (n
=0; n
<MACH_NODES_MAX
; n
++)
245 mach_node_publish(mach_node_table
[n
]);
247 MACH_NODE_TABLE_UNLOCK();
249 // TODO: notify all active nodes we are bootstrapped
252 /* Allocate/init a mach_node struct and fill in the node_id field.
253 * This does NOT insert the node struct into the node table.
256 mach_node_alloc_init(mach_node_id_t node_id
)
258 mach_node_t node
= MACH_NODE_ALLOC();
259 if (MACH_NODE_VALID(node
)) {
260 bzero(node
, sizeof(struct mach_node
));
261 MACH_NODE_LOCK_INIT(node
);
262 node
->info
.node_id
= node_id
;
268 /* This function takes a mach_node struct with a completed info field and
269 * registers it with the mach_node and flipc (if flipc is enabled) layers.
272 mach_node_register(mach_node_t node
)
274 assert(MACH_NODE_VALID(node
));
275 mach_node_id_t nid
= node
->info
.node_id
;
276 assert(MACH_NODE_ID_VALID(nid
));
279 ipc_space_t proxy_space
= IS_NULL
;
280 ipc_pset_t pp_set
= IPS_NULL
; // pset for proxy ports
281 ipc_port_t bs_port
= MACH_PORT_NULL
;
282 ipc_port_t ack_port
= MACH_PORT_NULL
;
284 printf("mach_node_register(%d)\n", nid
);
286 /* TODO: Support non-native byte order and data models */
287 if ((node
->info
.byteorder
!= OSHostByteOrder()) ||
288 (node
->info
.datamodel
!= LOCAL_DATA_MODEL
)) {
289 printf("mach_node_register: unsupported byte order (%d) or width (%d)",
290 node
->info
.byteorder
, node
->info
.datamodel
);
291 return KERN_INVALID_ARGUMENT
;
294 /* Create the space that holds all local rights assigned to <nid> */
295 kr
= ipc_space_create_special(&proxy_space
);
296 if (kr
!= KERN_SUCCESS
)
298 proxy_space
->is_node_id
= nid
;
300 /* Create the bootstrap proxy port for this remote node */
301 bs_port
= ipc_port_alloc_special(proxy_space
);
302 if (bs_port
== MACH_PORT_NULL
) {
303 kr
= KERN_RESOURCE_SHORTAGE
;
307 /* Create the control (ack) port for this remote node */
308 ack_port
= ipc_port_alloc_special(proxy_space
);
309 if (ack_port
== MACH_PORT_NULL
) {
310 kr
= KERN_RESOURCE_SHORTAGE
;
314 /* Create the set that holds all proxy ports for this remote node */
315 pp_set
= ipc_pset_alloc_special(proxy_space
);
316 if (pp_set
== IPS_NULL
) {
317 kr
= KERN_RESOURCE_SHORTAGE
;
321 /* Add the bootstrap port to the proxy port set */
322 uint64_t wq_link_id
= waitq_link_reserve(NULL
);
323 uint64_t wq_reserved_prepost
= waitq_prepost_reserve(NULL
, 10,
330 &wq_reserved_prepost
);
334 waitq_link_release(wq_link_id
);
335 waitq_prepost_release_reserve(wq_reserved_prepost
);
337 /* Add the control port to the proxy port set */
338 wq_link_id
= waitq_link_reserve(NULL
);
339 wq_reserved_prepost
= waitq_prepost_reserve(NULL
, 10,
346 &wq_reserved_prepost
);
350 waitq_link_release(wq_link_id
);
351 waitq_prepost_release_reserve(wq_reserved_prepost
);
353 // Setup mach_node struct
356 node
->proxy_space
= proxy_space
;
357 node
->proxy_port_set
= pp_set
;
358 node
->bootstrap_port
= bs_port
;
359 node
->proto_vers
= node
->info
.proto_vers_max
;
360 node
->control_port
= ack_port
;
362 // Place new mach_node struct into node table
363 MACH_NODE_TABLE_LOCK();
365 mach_node_t old_node
= mach_node_table
[nid
];
366 if (!MACH_NODE_VALID(old_node
) || (old_node
->dead
)) {
367 node
->antecedent
= old_node
;
368 flipc_node_prepare(node
);
369 mach_node_table
[nid
] = node
;
370 mach_nodes_to_publish
++;
371 mach_node_publish(node
);
374 printf("mach_node_register: id %d already active!", nid
);
377 MACH_NODE_TABLE_UNLOCK();
380 if (kr
!= KERN_SUCCESS
) { // Dispose of whatever we allocated
383 ipc_pset_destroy(pp_set
);
387 ipc_port_dealloc_special(bs_port
, proxy_space
);
390 ipc_port_dealloc_special(ack_port
, proxy_space
);
393 ipc_space_terminate(proxy_space
);
400 /* Gets or allocates a locked mach_node struct for the specified <node_id>.
401 * The current node is locked and returned if it is not dead, or if it is dead
402 * and <alloc_if_dead> is false. A new node struct is allocated, locked and
403 * returned if the node is dead and <alloc_if_dead> is true, or if the node
404 * is absent and <alloc_if_absent> is true. MACH_NODE_NULL is returned if
405 * the node is absent and <alloc_if_absent> is false. MACH_NODE_NULL is also
406 * returned if a new node structure was not able to be allocated.
408 * Note: This function must be called with the node table lock held!
411 mach_node_for_id_locked(mach_node_id_t node_id
,
412 boolean_t alloc_if_dead
,
413 boolean_t alloc_if_absent
)
415 if ((node_id
< 0) || (node_id
>= MACH_NODES_MAX
))
416 return MACH_NODE_NULL
;
418 mach_node_t node
= mach_node_table
[node_id
];
420 if ( (!MACH_NODE_VALID(node
) && alloc_if_absent
) ||
421 (MACH_NODE_VALID(node
) && node
->dead
&& alloc_if_dead
) ) {
422 node
= mach_node_alloc_init(node_id
);
423 if (MACH_NODE_VALID(node
)) {
424 node
->antecedent
= mach_node_table
[node_id
];
425 mach_node_table
[node_id
] = node
;
429 if (MACH_NODE_VALID(node
))
430 MACH_NODE_LOCK(node
);
437 /*** Mach Node Link Name and Hash Table Implementation ***/
439 /* Allocate a new unique name and return it.
440 * Dispose of this with mnl_name_free().
441 * Returns MNL_NAME_NULL on failure.
446 return (mnl_name_t
)OSAddAtomic64(MACH_NODES_MAX
, &mnl_name_next
);
450 /* Deallocate a unique name that was allocated via mnl_name_alloc().
453 mnl_name_free(mnl_name_t name __unused
)
455 ; // Nothing to do for now since we don't recycle mnl names.
459 /* Called once from mach_node_init(), this sets up the hash table structures.
462 mnl_name_table_init(void)
464 MNL_NAME_TABLE_LOCK_INIT();
465 MNL_NAME_TABLE_LOCK();
467 // Set the first name to this node's bootstrap name
468 mnl_name_next
= localnode_id
+ MACH_NODES_MAX
;
470 for (int i
=0; i
<MNL_NAME_TABLE_SIZE
; i
++)
471 queue_head_init(mnl_name_table
[i
]);
473 MNL_NAME_TABLE_UNLOCK();
477 /* Initialize the data structures in the mnl_obj structure at the head of the
478 * provided object. This should be called on an object before it is passed to
479 * any other mnl_obj* routine.
482 mnl_obj_init(mnl_obj_t obj
)
484 queue_chain_init(obj
->links
);
485 obj
->name
= MNL_NAME_NULL
;
489 /* Search the local node's hash table for the object associated with a
490 * mnl_name_t and return it. Returns MNL_NAME_NULL on failure.
493 mnl_obj_lookup(mnl_name_t name
)
495 mnl_obj_t obj
= MNL_OBJ_NULL
;
497 if (name
!= MNL_NAME_NULL
) {
498 qe_foreach_element(obj
, &mnl_name_table
[MNL_NAME_HASH(name
)], links
) {
499 if (obj
->name
== name
)
507 /* Search the local node's hash table for the object associated with a
508 * mnl_name_t and remove it. The pointer to the removed object is returned so
509 * that the caller can appropriately dispose of the object.
510 * Returns MNL_NAME_NULL on failure.
513 mnl_obj_remove(mnl_name_t name
)
515 mnl_obj_t obj
= MNL_OBJ_NULL
;
517 if (name
!= MNL_NAME_NULL
) {
518 qe_foreach_element_safe(obj
, &mnl_name_table
[MNL_NAME_HASH(name
)], links
) {
519 if (obj
->name
== name
)
520 remqueue(&obj
->links
);
527 /* Insert an object into the local node's hash table. If the name of the
528 * provided object is MNL_NAME_NULL then a new mnl_name is allocated and
529 * assigned to the object.
530 * Returns KERN_SUCCESS if obj was added to hash table
531 * Returns KERN_INVALID_ARGUMENT if obj is invalid
532 * Returns KERN_NAME_EXISTS if obj's name already exists in hash table
535 mnl_obj_insert(mnl_obj_t obj
)
537 if (!MNL_OBJ_VALID(obj
))
538 return KERN_INVALID_ARGUMENT
;
540 MNL_NAME_TABLE_LOCK();
542 if (!MNL_NAME_VALID(obj
->name
)) {
543 // obj is unnammed, so lets allocate a fresh one
544 obj
->name
= mnl_name_alloc();
547 enqueue(&mnl_name_table
[MNL_NAME_HASH(obj
->name
)], &obj
->links
);
548 MNL_NAME_TABLE_UNLOCK();
550 if(obj
->name
>= (MACH_NODES_MAX
<<1))
551 panic("Unexpected MNL_NAME %lld in obj %p", obj
->name
, obj
);
557 /*** Mach Node Link Driver Interface Implementation ***/
559 /* Allocate a mnl_msg struct plus additional payload. Link drivers are not
560 * required to use this to allocate messages; any wired and mapped kernel
561 * memory is acceptable.
564 * payload Number of additional bytes to allocate for message payload
565 * flags Currently unused; 0 should be passed
568 * MNL_MSG_NULL: Allocation failed
569 * *: Pointer to new mnl_msg struct of requested size
572 mnl_msg_alloc(int payload
,
573 uint32_t flags __unused
)
575 mnl_msg_t msg
= kalloc(MNL_MSG_SIZE
+ payload
);
577 if (MNL_MSG_VALID(msg
)) {
578 bzero(msg
, MNL_MSG_SIZE
); // Only zero the header
586 /* Free a mnl_msg struct allocated by mnl_msg_alloc().
589 * msg Pointer to the message buffer to be freed
590 * flags Currently unused; 0 should be passed
593 mnl_msg_free(mnl_msg_t msg
,
594 uint32_t flags __unused
)
596 if (MNL_MSG_VALID(msg
))
597 kfree(msg
, MNL_MSG_SIZE
+ msg
->size
);
601 /* The link driver calls this to setup a new (or restarted) node, and to get
602 * an mnl_node_info struct for use as a parameter to other mnl functions.
603 * If MNL_NODE_NULL is returned, the operation failed. Otherwise, a pointer
604 * to a new mnl_node struct is returned. The caller should set all fields
605 * in the structure, then call mnl_register() to complete node registration.
608 * nid The id of the node to be instantiated
609 * flags Currently unused; 0 should be passed
612 * MNL_NODE_NULL: Operation failed
613 * *: Pointer to a new mnl_node struct
616 mnl_instantiate(mach_node_id_t nid
,
617 uint32_t flags __unused
)
619 mach_node_init(); // Lazy init of mach_node layer
621 if ((nid
==localnode_id
) || !MACH_NODE_ID_VALID(nid
))
622 return MNL_NODE_NULL
;
624 return (mnl_node_info_t
)mach_node_alloc_init(nid
);
627 /* The link driver calls mnl_register() to complete the node registration
628 * process. KERN_SUCCESS is returned if registration succeeded, otherwise
629 * an error is returned.
632 * node Pointer to the node's mnl_node structure
633 * flags Currently unused; 0 should be passed
636 * KERN_SUCCESS: Registration succeeded
637 * KERN_INVALID_ARGUMENT: Field(s) in <node> contained unacceptable values
638 * KERN_*: Values returned from underlying functions
641 mnl_register(mnl_node_info_t node
,
642 uint32_t flags __unused
)
644 if (MNL_NODE_VALID(node
) && (node
->node_id
!= localnode_id
))
645 return mach_node_register((mach_node_t
)node
);
647 return KERN_INVALID_ARGUMENT
;
651 /* The link driver calls this to report that the link has been raised in one
652 * or both directions. If the link is two uni-directional channels, each link
653 * driver will independently call this function, each only raising the link
654 * they are responsible for. The mach_node layer will not communicate with
655 * the remote node until both rx and tx links are up.
658 * node Pointer to the node's mnl_node structure
659 * link Indicates which link(s) are up (see MNL_LINK_* defines)
660 * flags Currently unused; 0 should be passed
663 * KERN_SUCCESS: Link state changed successfully.
664 * KERN_INVALID_ARGUMENT: An argument value was not allowed.
665 * KERN_*: Values returned from underlying functions.
668 mnl_set_link_state(mnl_node_info_t node
,
670 uint32_t flags __unused
)
673 mach_node_t mnode
= (mach_node_t
)node
;
675 if (!MACH_NODE_VALID(mnode
) || !(link
& MNL_LINK_UP
) || (link
& mnode
->link
))
676 return KERN_INVALID_ARGUMENT
; // bad node, or bad link argument
678 MACH_NODE_LOCK(mnode
);
687 MACH_NODE_UNLOCK(mnode
);
692 /* The link driver calls this to indicate a node has terminated and is no
693 * longer available for messaging. This may be due to a crash or an orderly
694 * shutdown, but either way the remote node no longer retains any state about
695 * the remaining nodes. References held on behalf of the terminated node
696 * will be cleaned up. After this is called, both the rx and tx links are
697 * marked as down. If the remote node restarts, the link driver can bring
698 * up the link using mnl_instantiate() again.
701 * node Pointer to the node's mnl_node structure
702 * flags Currently unused; 0 should be passed
705 * KERN_SUCCESS: Node was terminated.
706 * KERN_INVALID_ARGUMENT: Node id was invalid or non-existant.
707 * KERN_*: Values returned from underlying functions.
710 mnl_terminate(mnl_node_info_t node
,
711 uint32_t flags __unused
)
713 kern_return_t kr
= KERN_SUCCESS
;
714 mach_node_t mnode
= (mach_node_t
)node
;
716 if (!MACH_NODE_VALID(mnode
))
717 return KERN_INVALID_ARGUMENT
; // bad node
719 MACH_NODE_LOCK(mnode
);
721 kr
= KERN_NODE_DOWN
; // node is already terminated
725 mnode
->link
= MNL_LINK_DOWN
;
727 mnode
->suspended
= 0;
730 flipc_node_retire(mnode
);
732 // Wake any threads sleeping on the proxy port set
733 if (mnode
->proxy_port_set
!= IPS_NULL
) {
734 ips_lock(mnode
->proxy_port_set
);
735 ipc_pset_destroy(mnode
->proxy_port_set
);
736 mnode
->proxy_port_set
= IPS_NULL
;
739 // TODO: Inform node name server (if registered) of termination
742 MACH_NODE_UNLOCK(mnode
);
747 /* The link driver calls this to deliver an incoming message. Note that the
748 * link driver must dispose of the memory pointed to by <msg> after the
749 * function call returns.
752 * node Pointer to the node's mnl_node structure
753 * msg Pointer to the message buffer
754 * flags Currently unused; 0 should be passed
757 mnl_msg_from_node(mnl_node_info_t node __unused
,
759 uint32_t flags __unused
)
761 assert(MNL_MSG_VALID(msg
));
762 assert(MACH_NODE_ID_VALID(msg
->node_id
));
763 assert(MNL_NODE_VALID(node
));
765 /* If node message forwarding is supported, the from_node_id arg may not
766 * match fmsg->info.node_id. The former is the node from which we received
767 * the message; the latter is the node that generated the message originally.
768 * We always use fmsg->info.node_id, which is where the ack needs to go.
773 case MACH_NODE_SUB_FLIPC
:
774 flipc_msg_from_node((mach_node_t
)node
, msg
, flags
);
779 PE_enter_debugger("mnl_msg_from_node(): Invalid subsystem");
786 /* The link driver calls this to fetch the next message to transmit.
787 * This function will block until a message is available, or will return
788 * FLIPC_MSG_NULL if the link is to be terminated. After the caller has
789 * completed the transmission and no longer needs the msg buffer, it should
790 * call mnl_msg_complete().
793 * node Pointer to the node's mnl_node structure
794 * flags Currently unused; 0 should be passed
797 mnl_msg_to_node(mnl_node_info_t node __unused
,
798 uint32_t flags __unused
)
800 assert(MNL_NODE_VALID(node
));
803 thread_set_thread_name(current_thread(), "MNL_Link");
806 return flipc_msg_to_remote_node((mach_node_t
)node
, 0);
810 /* The link driver calls this to indicate that the specified msg buffer has
811 * been sent over the link and can be deallocated.
814 * node Pointer to the node's mnl_node structure
815 * msg Pointer to the message buffer
816 * flags Currently unused; 0 should be passed
819 mnl_msg_complete(mnl_node_info_t node __unused
,
824 case MACH_NODE_SUB_NODE
:
825 mnl_msg_free(msg
, flags
);
828 case MACH_NODE_SUB_FLIPC
:
829 flipc_msg_free(msg
, flags
);
834 PE_enter_debugger("mnl_msg_complete(): Invalid subsystem");
840 #else // MACH_FLIPC not configured, so provide KPI stubs
843 mnl_msg_alloc(int payload __unused
, uint32_t flags __unused
)
849 mnl_msg_free(mnl_msg_t msg __unused
, uint32_t flags __unused
)
855 mnl_instantiate(mach_node_id_t nid __unused
, uint32_t flags __unused
)
857 return MNL_NODE_NULL
;
861 mnl_register(mnl_node_info_t node __unused
, uint32_t flags __unused
)
867 mnl_set_link_state(mnl_node_info_t node __unused
,
869 uint32_t flags __unused
)
875 mnl_terminate(mnl_node_info_t node __unused
, uint32_t flags __unused
)
881 mnl_msg_from_node(mnl_node_info_t node __unused
,
882 mnl_msg_t msg __unused
,
883 uint32_t flags __unused
)
889 mnl_msg_to_node(mnl_node_info_t node __unused
, uint32_t flags __unused
)
895 mnl_msg_complete(mnl_node_info_t node __unused
,
896 mnl_msg_t msg __unused
,
897 uint32_t flags __unused
)