xref: /xnu-12377.61.12/bsd/skywalk/core/skywalk_proc_info.c (revision 4d495c6e23c53686cf65f45067f79024cf5dcee8)
1 /*
2  * Copyright (c) 2016-2020 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
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.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
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.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 
29 #include <sys/types.h>
30 #include <sys/kernel_types.h>
31 #include <sys/errno.h>
32 #include <sys/kernel.h>
33 #include <sys/file_internal.h>
34 #include <sys/proc_info.h>
35 #include <sys/sys_domain.h>
36 #include <sys/kern_event.h>
37 #include <string.h>
38 #include <skywalk/os_skywalk_private.h>
39 
40 static uint32_t
ch_mode_to_flags(uint32_t ch_mode)41 ch_mode_to_flags(uint32_t ch_mode)
42 {
43 	uint32_t        flags = 0;
44 
45 	if ((ch_mode & CHMODE_EXCLUSIVE) != 0) {
46 		flags |= PROC_CHANNEL_FLAGS_EXCLUSIVE;
47 	}
48 	if ((ch_mode & CHMODE_USER_PACKET_POOL) != 0) {
49 		flags |= PROC_CHANNEL_FLAGS_USER_PACKET_POOL;
50 	}
51 	if ((ch_mode & CHMODE_DEFUNCT_OK) != 0) {
52 		flags |= PROC_CHANNEL_FLAGS_DEFUNCT_OK;
53 	}
54 	if ((ch_mode & CHMODE_LOW_LATENCY) != 0) {
55 		flags |= PROC_CHANNEL_FLAGS_LOW_LATENCY;
56 	}
57 	return flags;
58 }
59 
60 errno_t
fill_channelinfo(struct kern_channel * channel,struct proc_channel_info * info)61 fill_channelinfo(struct kern_channel *channel, struct proc_channel_info *info)
62 {
63 	errno_t                 error = 0;
64 	struct kern_nexus       *nexus;
65 
66 	lck_mtx_lock(&channel->ch_lock);
67 	uuid_copy(info->chi_instance, channel->ch_info->cinfo_nx_uuid);
68 	info->chi_port = channel->ch_info->cinfo_nx_port;
69 	info->chi_flags = ch_mode_to_flags(channel->ch_info->cinfo_ch_mode);
70 	nexus = channel->ch_nexus;
71 	if (nexus != NULL) {
72 		struct kern_nexus_provider *nx_prov = nexus->nx_prov;
73 		if (nx_prov != NULL) {
74 			struct kern_nexus_domain_provider *dom_prov;
75 			dom_prov = nx_prov->nxprov_dom_prov;
76 			if (dom_prov != NULL) {
77 				struct nxdom *dom;
78 				dom = dom_prov->nxdom_prov_dom;
79 				if (dom != NULL) {
80 					info->chi_type = dom->nxdom_type;
81 				}
82 			}
83 		}
84 	}
85 	lck_mtx_unlock(&channel->ch_lock);
86 	return error;
87 }
88