this repo has no description
1
fork

Configure Feed

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

A tiny bit more task_info.

Conflicts:
src/libSystem/kernel-mach/task.cpp

authored by

Chris Wulff and committed by
Lubos Dolezel
f9a90acc eaa2a2e6

+156
+128
src/libSystem/kernel-mach/task.cpp
··· 3 3 #include <sys/types.h> 4 4 #include <unistd.h> 5 5 #include <cstdlib> 6 + #include <iostream> 7 + #include <execinfo.h> 6 8 7 9 darwin_task_t mach_task_self_ = new darwin_task(::getpid()); 8 10 ··· 11 13 free(port); 12 14 return KERN_SUCCESS; 13 15 } 16 + 17 + kern_return_t pid_for_task(mach_port_name_t t, int *pid) 18 + { 19 + // TODO: this is supposed to be for the specified task but for now, just return our pid 20 + if (pid) 21 + { 22 + *pid = mach_task_self_->pid; 23 + } 24 + return KERN_SUCCESS; 25 + } 26 + 27 + kern_return_t mach_port_mod_refs(ipc_space_t task, mach_port_name_t name, mach_port_right_t right, mach_port_delta_t delta) 28 + { 29 + return KERN_SUCCESS; 30 + } 31 + 32 + // task_info structures 33 + 34 + #define TASK_DYLD_INFO 17 35 + 36 + struct task_dyld_info { 37 + mach_vm_address_t all_image_info_addr; 38 + mach_vm_size_t all_image_info_size; 39 + integer_t all_image_info_format; 40 + }; 41 + typedef struct task_dyld_info task_dyld_info_data_t; 42 + typedef struct task_dyld_info *task_dyld_info_t; 43 + #define TASK_DYLD_ALL_IMAGE_INFO_32 0 44 + #define TASK_DYLD_ALL_IMAGE_INFO_64 1 45 + 46 + enum dyld_image_mode { dyld_image_adding=0, dyld_image_removing=1 }; 47 + typedef void (*dyld_image_notifier)(enum dyld_image_mode mode, uint32_t infoCount, const struct dyld_image_info info[]); 48 + 49 + struct dyld_all_image_infos { 50 + uint32_t version; 51 + uint32_t infoArrayCount; 52 + const struct dyld_image_info* infoArray; 53 + dyld_image_notifier notification; 54 + bool processDetachedFromSharedRegion; 55 + bool libSystemInitialized; 56 + const struct mach_header* dyldImageLoadAddress; 57 + void* jitInfo; 58 + const char* dyldVersion; 59 + const char* errorMessage; 60 + uintptr_t terminationFlags; 61 + void* coreSymbolicationShmPage; 62 + uintptr_t systemOrderFlag; 63 + uintptr_t uuidArrayCount; 64 + const struct dyld_uuid_info* uuidArray; 65 + struct dyld_all_image_infos* dyldAllImageInfosAddress; 66 + uintptr_t initialImageCount; 67 + uintptr_t errorKind; 68 + const char* errorClientOfDylibPath; 69 + const char* errorTargetDylibPath; 70 + const char* errorSymbol; 71 + uintptr_t sharedCacheSlide; 72 + }; 73 + 74 + struct dyld_all_image_infos dyld_all_image_infos = { 12 }; 75 + 76 + kern_return_t task_info(task_name_t target_task, task_flavor_t flavor, task_info_t task_info_out, mach_msg_type_number_t *task_info_outCnt) 77 + { 78 + std::cerr << "task_info(" << target_task << ", " << flavor << ", " << task_info_out << ", " << task_info_outCnt << " = " << *task_info_outCnt << ")" << std::endl; 79 + 80 + switch (flavor) 81 + { 82 + case TASK_DYLD_INFO: 83 + { 84 + task_dyld_info_t dyld_info = (task_dyld_info_t)task_info_out; 85 + dyld_info->all_image_info_addr = (mach_vm_address_t)&dyld_all_image_infos; 86 + dyld_info->all_image_info_size = sizeof(dyld_all_image_infos); 87 + #ifdef __x86_64__ 88 + dyld_info->all_image_info_format = TASK_DYLD_ALL_IMAGE_INFO_64; 89 + #else 90 + dyld_info->all_image_info_format = TASK_DYLD_ALL_IMAGE_INFO_32; 91 + #endif 92 + break; 93 + } 94 + default: 95 + // TODO: get the requested info flavor. For now, just zero the provided buffer 96 + for (int i=0; i<*task_info_outCnt; i++) 97 + { 98 + task_info_out[i] = 0; 99 + } 100 + break; 101 + } 102 + 103 + return KERN_SUCCESS; 104 + } 105 + 106 + kern_return_t mach_vm_region_recurse(vm_map_t target_task, mach_vm_address_t *address, mach_vm_size_t *size, natural_t *nesting_depth, vm_region_recurse_info_t info, mach_msg_type_number_t *infoCnt) 107 + { 108 + // TODO 109 + *infoCnt = 0; 110 + return KERN_SUCCESS; 111 + } 112 + 113 + int proc_name(int pid, void * buffer, uint32_t buffersize) 114 + { 115 + // TODO: get process name 116 + if (buffer) 117 + { 118 + *(char*)buffer = 0; 119 + } 120 + return 0; 121 + } 122 + 123 + int proc_pidpath(int pid, void * buffer, uint32_t buffersize) 124 + { 125 + // TODO: get process path 126 + if (buffer) 127 + { 128 + *(char*)buffer = 0; 129 + } 130 + return 0; 131 + } 132 + 133 + int proc_pidinfo(int pid, int flavor, uint64_t arg, void *buffer, int buffersize) 134 + { 135 + // TODO: get other pid info? 136 + if (buffer) 137 + { 138 + *(char*)buffer = 0; 139 + } 140 + return 0; 141 + }
+28
src/libSystem/kernel-mach/task.h
··· 11 11 12 12 typedef darwin_task* darwin_task_t; 13 13 14 + typedef unsigned int natural_t; 15 + typedef int integer_t; 16 + 17 + typedef natural_t mach_port_name_t; 18 + typedef mach_port_name_t mach_port_t; 19 + typedef mach_port_t ipc_space_t; 20 + typedef natural_t mach_port_right_t; 21 + typedef integer_t mach_port_delta_t; 22 + typedef mach_port_t task_name_t; 23 + typedef natural_t task_flavor_t; 24 + typedef integer_t *task_info_t; 25 + typedef natural_t mach_msg_type_number_t; 26 + typedef mach_port_t vm_map_t; 27 + typedef uint64_t mach_vm_address_t; 28 + typedef uint64_t mach_vm_size_t; 29 + typedef int *vm_region_recurse_info_t; 30 + 14 31 #ifdef __cplusplus 15 32 extern "C" 16 33 { ··· 18 35 extern darwin_task_t mach_task_self_; 19 36 inline darwin_task_t mach_task_self() { return mach_task_self_; } 20 37 kern_return_t mach_port_deallocate(darwin_task_t task, void* port); 38 + kern_return_t pid_for_task(mach_port_name_t t, int *pid); 39 + kern_return_t mach_port_mod_refs(ipc_space_t task, mach_port_name_t name, mach_port_right_t right, mach_port_delta_t delta); 40 + kern_return_t task_info(task_name_t target_task, task_flavor_t flavor, task_info_t task_info_out, mach_msg_type_number_t *task_info_outCnt); 41 + 42 + // mach_vm.h 43 + kern_return_t mach_vm_region_recurse(vm_map_t target_task, mach_vm_address_t *address, mach_vm_size_t *size, natural_t *nesting_depth, vm_region_recurse_info_t info, mach_msg_type_number_t *infoCnt); 44 + 45 + // libproc.h 46 + int proc_name(int pid, void * buffer, uint32_t buffersize); 47 + int proc_pidpath(int pid, void * buffer, uint32_t buffersize); 48 + int proc_pidinfo(int pid, int flavor, uint64_t arg, void *buffer, int buffersize); 21 49 #ifdef __cplusplus 22 50 } 23 51 #endif