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 |
41 | ch_mode_to_flags(uint32_t ch_mode) |
42 | { |
43 | uint32_t flags = 0; |
44 | |
45 | if ((ch_mode & CHMODE_MONITOR_RX) != 0) { |
46 | flags |= PROC_CHANNEL_FLAGS_MONITOR_RX; |
47 | } |
48 | if ((ch_mode & CHMODE_MONITOR_TX) != 0) { |
49 | flags |= PROC_CHANNEL_FLAGS_MONITOR_TX; |
50 | } |
51 | if ((ch_mode & CHMODE_MONITOR_NO_COPY) != 0) { |
52 | flags |= PROC_CHANNEL_FLAGS_MONITOR_NO_COPY; |
53 | } |
54 | if ((ch_mode & CHMODE_EXCLUSIVE) != 0) { |
55 | flags |= PROC_CHANNEL_FLAGS_EXCLUSIVE; |
56 | } |
57 | if ((ch_mode & CHMODE_USER_PACKET_POOL) != 0) { |
58 | flags |= PROC_CHANNEL_FLAGS_USER_PACKET_POOL; |
59 | } |
60 | if ((ch_mode & CHMODE_DEFUNCT_OK) != 0) { |
61 | flags |= PROC_CHANNEL_FLAGS_DEFUNCT_OK; |
62 | } |
63 | if ((ch_mode & CHMODE_LOW_LATENCY) != 0) { |
64 | flags |= PROC_CHANNEL_FLAGS_LOW_LATENCY; |
65 | } |
66 | return flags; |
67 | } |
68 | |
69 | errno_t |
70 | fill_channelinfo(struct kern_channel *channel, struct proc_channel_info *info) |
71 | { |
72 | errno_t error = 0; |
73 | struct kern_nexus *nexus; |
74 | |
75 | lck_mtx_lock(lck: &channel->ch_lock); |
76 | uuid_copy(dst: info->chi_instance, src: channel->ch_info->cinfo_nx_uuid); |
77 | info->chi_port = channel->ch_info->cinfo_nx_port; |
78 | info->chi_flags = ch_mode_to_flags(ch_mode: channel->ch_info->cinfo_ch_mode); |
79 | nexus = channel->ch_nexus; |
80 | if (nexus != NULL) { |
81 | struct kern_nexus_provider *nx_prov = nexus->nx_prov; |
82 | if (nx_prov != NULL) { |
83 | struct kern_nexus_domain_provider *dom_prov; |
84 | dom_prov = nx_prov->nxprov_dom_prov; |
85 | if (dom_prov != NULL) { |
86 | struct nxdom *dom; |
87 | dom = dom_prov->nxdom_prov_dom; |
88 | if (dom != NULL) { |
89 | info->chi_type = dom->nxdom_type; |
90 | } |
91 | } |
92 | } |
93 | } |
94 | lck_mtx_unlock(lck: &channel->ch_lock); |
95 | return error; |
96 | } |
97 | |