this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mach_host server progress

+384 -6
+277
kernel-include/mach/host_info.h
··· 1 + /* 2 + * Copyright (c) 2000-2009 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 + * @OSF_COPYRIGHT@ 30 + */ 31 + /* 32 + * Mach Operating System 33 + * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University 34 + * All Rights Reserved. 35 + * 36 + * Permission to use, copy, modify and distribute this software and its 37 + * documentation is hereby granted, provided that both the copyright 38 + * notice and this permission notice appear in all copies of the 39 + * software, derivative works or modified versions, and any portions 40 + * thereof, and that both notices appear in supporting documentation. 41 + * 42 + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 + * 46 + * Carnegie Mellon requests users of this software to return to 47 + * 48 + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 + * School of Computer Science 50 + * Carnegie Mellon University 51 + * Pittsburgh PA 15213-3890 52 + * 53 + * any improvements or extensions that they make and grant Carnegie Mellon 54 + * the rights to redistribute these changes. 55 + */ 56 + /* 57 + */ 58 + 59 + /* 60 + * File: mach/host_info.h 61 + * 62 + * Definitions for host_info call. 63 + */ 64 + 65 + #ifndef _MACH_HOST_INFO_H_ 66 + #define _MACH_HOST_INFO_H_ 67 + 68 + #include <mach/message.h> 69 + #include <mach/vm_statistics.h> 70 + #include <mach/machine.h> 71 + #include <mach/machine/vm_types.h> 72 + #include <mach/time_value.h> 73 + 74 + #include <sys/cdefs.h> 75 + 76 + /* 77 + * Generic information structure to allow for expansion. 78 + */ 79 + typedef integer_t *host_info_t; /* varying array of int. */ 80 + typedef integer_t *host_info64_t; /* varying array of int. */ 81 + 82 + #define HOST_INFO_MAX (1024) /* max array size */ 83 + typedef integer_t host_info_data_t[HOST_INFO_MAX]; 84 + 85 + #define KERNEL_VERSION_MAX (512) 86 + typedef char kernel_version_t[KERNEL_VERSION_MAX]; 87 + 88 + #define KERNEL_BOOT_INFO_MAX (4096) 89 + typedef char kernel_boot_info_t[KERNEL_BOOT_INFO_MAX]; 90 + 91 + /* 92 + * Currently defined information. 93 + */ 94 + /* host_info() */ 95 + typedef integer_t host_flavor_t; 96 + #define HOST_BASIC_INFO 1 /* basic info */ 97 + #define HOST_SCHED_INFO 3 /* scheduling info */ 98 + #define HOST_RESOURCE_SIZES 4 /* kernel struct sizes */ 99 + #define HOST_PRIORITY_INFO 5 /* priority information */ 100 + #define HOST_SEMAPHORE_TRAPS 7 /* Has semaphore traps */ 101 + #define HOST_MACH_MSG_TRAP 8 /* Has mach_msg_trap */ 102 + 103 + #ifdef MACH_KERNEL_PRIVATE 104 + struct host_basic_info_old { 105 + integer_t max_cpus; /* max number of cpus possible */ 106 + uint32_t avail_cpus; /* number of cpus now available */ 107 + natural_t memory_size; /* size of memory in bytes */ 108 + cpu_type_t cpu_type; /* cpu type */ 109 + cpu_subtype_t cpu_subtype; /* cpu subtype */ 110 + }; 111 + 112 + typedef struct host_basic_info_old host_basic_info_data_old_t; 113 + typedef struct host_basic_info_old *host_basic_info_old_t; 114 + #define HOST_BASIC_INFO_OLD_COUNT ((mach_msg_type_number_t) \ 115 + (sizeof(host_basic_info_data_old_t)/sizeof(integer_t))) 116 + #endif 117 + 118 + #pragma pack(4) 119 + 120 + struct host_basic_info { 121 + integer_t max_cpus; /* max number of CPUs possible */ 122 + integer_t avail_cpus; /* number of CPUs now available */ 123 + natural_t memory_size; /* size of memory in bytes, capped at 2 GB */ 124 + cpu_type_t cpu_type; /* cpu type */ 125 + cpu_subtype_t cpu_subtype; /* cpu subtype */ 126 + cpu_threadtype_t cpu_threadtype; /* cpu threadtype */ 127 + integer_t physical_cpu; /* number of physical CPUs now available */ 128 + integer_t physical_cpu_max; /* max number of physical CPUs possible */ 129 + integer_t logical_cpu; /* number of logical cpu now available */ 130 + integer_t logical_cpu_max; /* max number of physical CPUs possible */ 131 + uint64_t max_mem; /* actual size of physical memory */ 132 + }; 133 + 134 + #pragma pack() 135 + 136 + typedef struct host_basic_info host_basic_info_data_t; 137 + typedef struct host_basic_info *host_basic_info_t; 138 + #define HOST_BASIC_INFO_COUNT ((mach_msg_type_number_t) \ 139 + (sizeof(host_basic_info_data_t)/sizeof(integer_t))) 140 + 141 + struct host_sched_info { 142 + integer_t min_timeout; /* minimum timeout in milliseconds */ 143 + integer_t min_quantum; /* minimum quantum in milliseconds */ 144 + }; 145 + 146 + typedef struct host_sched_info host_sched_info_data_t; 147 + typedef struct host_sched_info *host_sched_info_t; 148 + #define HOST_SCHED_INFO_COUNT ((mach_msg_type_number_t) \ 149 + (sizeof(host_sched_info_data_t)/sizeof(integer_t))) 150 + 151 + struct kernel_resource_sizes { 152 + natural_t task; 153 + natural_t thread; 154 + natural_t port; 155 + natural_t memory_region; 156 + natural_t memory_object; 157 + }; 158 + 159 + typedef struct kernel_resource_sizes kernel_resource_sizes_data_t; 160 + typedef struct kernel_resource_sizes *kernel_resource_sizes_t; 161 + #define HOST_RESOURCE_SIZES_COUNT ((mach_msg_type_number_t) \ 162 + (sizeof(kernel_resource_sizes_data_t)/sizeof(integer_t))) 163 + 164 + struct host_priority_info { 165 + integer_t kernel_priority; 166 + integer_t system_priority; 167 + integer_t server_priority; 168 + integer_t user_priority; 169 + integer_t depress_priority; 170 + integer_t idle_priority; 171 + integer_t minimum_priority; 172 + integer_t maximum_priority; 173 + }; 174 + 175 + typedef struct host_priority_info host_priority_info_data_t; 176 + typedef struct host_priority_info *host_priority_info_t; 177 + #define HOST_PRIORITY_INFO_COUNT ((mach_msg_type_number_t) \ 178 + (sizeof(host_priority_info_data_t)/sizeof(integer_t))) 179 + 180 + /* host_statistics() */ 181 + #define HOST_LOAD_INFO 1 /* System loading stats */ 182 + #define HOST_VM_INFO 2 /* Virtual memory stats */ 183 + #define HOST_CPU_LOAD_INFO 3 /* CPU load stats */ 184 + 185 + /* host_statistics64() */ 186 + #define HOST_VM_INFO64 4 /* 64-bit virtual memory stats */ 187 + #define HOST_EXTMOD_INFO64 5 /* External modification stats */ 188 + 189 + 190 + struct host_load_info { 191 + integer_t avenrun[3]; /* scaled by LOAD_SCALE */ 192 + integer_t mach_factor[3]; /* scaled by LOAD_SCALE */ 193 + }; 194 + 195 + typedef struct host_load_info host_load_info_data_t; 196 + typedef struct host_load_info *host_load_info_t; 197 + #define HOST_LOAD_INFO_COUNT ((mach_msg_type_number_t) \ 198 + (sizeof(host_load_info_data_t)/sizeof(integer_t))) 199 + 200 + /* in <mach/vm_statistics.h> */ 201 + /* vm_statistics64 */ 202 + #define HOST_VM_INFO64_COUNT ((mach_msg_type_number_t) \ 203 + (sizeof(vm_statistics64_data_t)/sizeof(integer_t))) 204 + 205 + /* size of the latest version of the structure */ 206 + #define HOST_VM_INFO64_LATEST_COUNT HOST_VM_INFO64_COUNT 207 + 208 + /* in <mach/vm_statistics.h> */ 209 + /* vm_extmod_statistics */ 210 + #define HOST_EXTMOD_INFO64_COUNT ((mach_msg_type_number_t) \ 211 + (sizeof(vm_extmod_statistics_data_t)/sizeof(integer_t))) 212 + 213 + /* size of the latest version of the structure */ 214 + #define HOST_EXTMOD_INFO64_LATEST_COUNT HOST_EXTMOD_INFO64_COUNT 215 + 216 + /* vm_statistics */ 217 + #define HOST_VM_INFO_COUNT ((mach_msg_type_number_t) \ 218 + (sizeof(vm_statistics_data_t)/sizeof(integer_t))) 219 + 220 + /* size of the latest version of the structure */ 221 + #define HOST_VM_INFO_LATEST_COUNT HOST_VM_INFO_COUNT 222 + #define HOST_VM_INFO_REV2_COUNT HOST_VM_INFO_LATEST_COUNT 223 + /* previous versions: adjust the size according to what was added each time */ 224 + #define HOST_VM_INFO_REV1_COUNT /* added "speculative_count" (1 int) */ \ 225 + ((mach_msg_type_number_t) \ 226 + (HOST_VM_INFO_REV2_COUNT - 1)) 227 + #define HOST_VM_INFO_REV0_COUNT /* added "purgable" info (2 ints) */ \ 228 + ((mach_msg_type_number_t) \ 229 + (HOST_VM_INFO_REV1_COUNT - 2)) 230 + 231 + struct host_cpu_load_info { /* number of ticks while running... */ 232 + natural_t cpu_ticks[CPU_STATE_MAX]; /* ... in the given mode */ 233 + }; 234 + 235 + typedef struct host_cpu_load_info host_cpu_load_info_data_t; 236 + typedef struct host_cpu_load_info *host_cpu_load_info_t; 237 + #define HOST_CPU_LOAD_INFO_COUNT ((mach_msg_type_number_t) \ 238 + (sizeof (host_cpu_load_info_data_t) / sizeof (integer_t))) 239 + 240 + #ifdef PRIVATE 241 + /* 242 + * CPU Statistics information 243 + */ 244 + struct _processor_statistics_np { 245 + int32_t ps_cpuid; 246 + 247 + uint32_t ps_csw_count; 248 + uint32_t ps_preempt_count; 249 + uint32_t ps_preempted_rt_count; 250 + uint32_t ps_preempted_by_rt_count; 251 + 252 + uint32_t ps_rt_sched_count; 253 + 254 + uint32_t ps_interrupt_count; 255 + uint32_t ps_ipi_count; 256 + uint32_t ps_timer_pop_count; 257 + 258 + uint64_t ps_runq_count_sum __attribute((aligned(8))); 259 + 260 + uint32_t ps_idle_transitions; 261 + uint32_t ps_quantum_timer_expirations; 262 + }; 263 + 264 + #endif /* PRIVATE */ 265 + 266 + #ifdef KERNEL_PRIVATE 267 + 268 + extern kern_return_t set_sched_stats_active( 269 + boolean_t active); 270 + 271 + extern kern_return_t get_sched_statistics( 272 + struct _processor_statistics_np *out, 273 + uint32_t *count); 274 + #endif /* KERNEL_PRIVATE */ 275 + 276 + 277 + #endif /* _MACH_HOST_INFO_H_ */
+3 -1
lkm/api.h
··· 1 1 #ifndef LKM_API_H 2 2 #define LKM_API_H 3 3 4 - #define DARLING_MACH_API_VERSION 1 4 + #define DARLING_MACH_API_VERSION 1 5 + #define DARLING_MACH_API_VERSION_STR "1" 5 6 6 7 #define DARLING_MACH_API_BASE 0x1000 7 8 ··· 9 10 NR_mach_reply_port, 10 11 NR__kernelrpc_mach_port_mod_refs, 11 12 NR_task_self_trap, 13 + NR_host_self_trap, 12 14 NR__kernelrpc_mach_port_allocate, 13 15 NR_mach_msg_overwrite_trap 14 16 };
+5 -1
lkm/ipc_port.c
··· 301 301 { 302 302 if (target->port->is_server_port) 303 303 { 304 - 304 + mig_subsystem_t subsystem = target->port->server_port.subsystem; 305 + if (subsystem == MIG_SUBSYSTEM_NULL) 306 + { 307 + return KERN_NOT_SUPPORTED; 308 + } 305 309 } 306 310 else 307 311 {
+27
lkm/linuxmach.c
··· 43 43 &mach_chardev_ops, 44 44 }; 45 45 46 + darling_mach_port_t* host_port; 47 + 46 48 static int mach_init(void) 47 49 { 48 50 int err = misc_register(&mach_dev); 49 51 if (err < 0) 50 52 goto fail; 51 53 54 + if (ipc_port_new(&host_port) != KERN_SUCCESS) 55 + { 56 + err = -ENOMEM; 57 + goto fail; 58 + } 59 + ipc_port_make_host(host_port); 60 + 52 61 printk(KERN_INFO "Darling Mach kernel emulation loaded\n"); 53 62 return 0; 54 63 ··· 58 67 } 59 68 static void mach_exit(void) 60 69 { 70 + ipc_port_put(host_port); 61 71 misc_deregister(&mach_dev); 62 72 printk(KERN_INFO "Darling Mach kernel emulation unloaded\n"); 63 73 } ··· 206 216 ret = ipc_space_make_send(&task->namespace, task->task_self, false, &name); 207 217 208 218 ipc_port_unlock(task->task_self); 219 + 220 + if (ret == KERN_SUCCESS) 221 + return name; 222 + else 223 + return 0; 224 + } 225 + 226 + mach_port_name_t mach_host_self_trap(mach_task_t* task) 227 + { 228 + mach_port_name_t name; 229 + kern_return_t ret; 230 + 231 + ipc_port_lock(host_port); 232 + 233 + ret = ipc_space_make_send(&task->namespace, host_port, false, &name); 234 + 235 + ipc_port_unlock(host_port); 209 236 210 237 if (ret == KERN_SUCCESS) 211 238 return name;
+1
lkm/linuxmach.h
··· 24 24 kern_return_t _kernelrpc_mach_port_mod_refs_trap(mach_task_t* task, 25 25 struct mach_port_mod_refs_args* args); 26 26 mach_port_name_t mach_task_self_trap(mach_task_t* task); 27 + mach_port_name_t mach_host_self_trap(mach_task_t* task); 27 28 kern_return_t _kernelrpc_mach_port_allocate_trap(mach_task_t* task, 28 29 struct mach_port_allocate_args* args); 29 30 kern_return_t mach_msg_overwrite_trap(mach_task_t* task,
+2
lkm/mach_includes.h
··· 4 4 #include <mach/port.h> 5 5 #include <mach/message.h> 6 6 #include <mach/mig.h> 7 + #include <mach/mach_types.h> 7 8 8 9 /* Undef some names that conflict with Linux defines */ 9 10 #undef __used ··· 18 19 #undef NSEC_PER_USEC 19 20 #undef NSEC_PER_MSEC 20 21 #undef NSEC_PER_SEC 22 + #undef USEC_PER_SEC 21 23 22 24 #endif
+69 -4
lkm/servers/mach_host.c
··· 1 1 #include "../mach_includes.h" 2 - #include "../mig_includes_pre.h" 3 - #include "../mig/mach_hostServer.h" 2 + #include <mach/host_info.h> 3 + #include <mach_debug/zone_info.h> 4 + #include <mach_debug/hash_info.h> 5 + #include <mach_debug/lockgroup_info.h> 6 + #include "../api.h" 7 + #include <generated/utsrelease.h> 8 + #include <linux/string.h> 9 + #include <linux/cpumask.h> 10 + #include <linux/mm.h> 11 + #include <linux/thread_info.h> 12 + #include <asm/page.h> 13 + 14 + static const char KERNEL_VERSION[] = "Darling Mach (API level " DARLING_MACH_API_VERSION_STR ") on Linux " UTS_RELEASE; 4 15 5 16 kern_return_t host_info 6 17 ( ··· 10 21 mach_msg_type_number_t *host_info_outCnt 11 22 ) 12 23 { 24 + switch (flavor) 25 + { 26 + case HOST_BASIC_INFO: 27 + { 28 + struct host_basic_info* hinfo; 29 + struct sysinfo i; 30 + 31 + hinfo = (struct host_basic_info*) host_info_out; 32 + 33 + if (*host_info_outCnt < HOST_BASIC_INFO_OLD_COUNT) 34 + return KERN_FAILURE; 35 + 36 + si_meminfo(&i); 37 + hinfo->memory_size = i.totalram; 38 + hinfo->max_cpus = num_possible_cpus(); 39 + hinfo->avail_cpus = num_online_cpus(); 40 + #if defined(__i386__) 41 + hinfo->cpu_type = CPU_TYPE_I386; 42 + hinfo->cpu_subtype = CPU_SUBTYPE_I386_ALL; 43 + #elif defined(__x86_64__) 44 + if (!test_thread_flag(TIF_IA32)) 45 + { 46 + hinfo->cpu_type = CPU_TYPE_X86_64; 47 + hinfo->cpu_subtype = CPU_SUBTYPE_X86_64_ALL; 48 + } 49 + else 50 + { 51 + hinfo->cpu_type = CPU_TYPE_I386; 52 + hinfo->cpu_subtype = CPU_SUBTYPE_I386_ALL; 53 + } 54 + #else 55 + hinfo->cpu_type = 0; 56 + hinfo->cpu_subtype = 0; 57 + #endif 58 + 59 + if (*host_info_outCnt <= HOST_BASIC_INFO_COUNT) 60 + { 61 + // TODO 62 + *host_info_outCnt = HOST_BASIC_INFO_COUNT; 63 + } 64 + else 65 + *host_info_outCnt = HOST_BASIC_INFO_OLD_COUNT; 66 + 67 + return KERN_SUCCESS; 68 + } 69 + //case HOST_PROCESSOR_SLOTS: 70 + // break; 71 + case HOST_SCHED_INFO: 72 + break; 73 + default: 74 + return KERN_NOT_SUPPORTED; 75 + } 13 76 return KERN_NOT_SUPPORTED; 14 77 } 15 78 ··· 19 82 kernel_version_t kernel_version 20 83 ) 21 84 { 22 - return KERN_NOT_SUPPORTED; 85 + strncpy(kernel_version, KERNEL_VERSION, sizeof(KERNEL_VERSION)); 86 + return KERN_SUCCESS; 23 87 } 24 88 25 89 kern_return_t _host_page_size ··· 28 92 vm_size_t *out_page_size 29 93 ) 30 94 { 31 - return KERN_NOT_SUPPORTED; 95 + *out_page_size = PAGE_SIZE; 96 + return KERN_SUCCESS; 32 97 } 33 98 34 99 kern_return_t mach_memory_object_memory_entry