this repo has no description
1
fork

Configure Feed

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

Some basic impl for Mach thread API

+88 -2
+1
src/libSystem/CMakeLists.txt
··· 125 125 kernel-mach/Futex.cpp 126 126 kernel-mach/FutexSemaphore.cpp 127 127 kernel-mach/compat.cpp 128 + kernel-mach/thread.cpp 128 129 ) 129 130 130 131 add_library(System SHARED ${libc_SRCS} ${bsdkern_SRCS}
+3 -2
src/libSystem/kernel-mach/host.cpp
··· 176 176 177 177 host_t mach_host_self() 178 178 { 179 - host* h = static_cast<host*>(malloc(sizeof(struct host))); 180 - return h; 179 + static struct host h; 180 + return &h; 181 181 } 182 +
+52
src/libSystem/kernel-mach/thread.cpp
··· 1 + #include "thread.h" 2 + #include <fstream> 3 + #include <sstream> 4 + #include <unistd.h> 5 + #include <mach/kern_return.h> 6 + #include "../libc/pthread.h" 7 + 8 + kern_return_t thread_info(thread_act_t target_act, thread_flavor_t flavor, void* infoOut, mach_msg_type_number_t* count) 9 + { 10 + if (!infoOut || !count) 11 + return KERN_INVALID_ARGUMENT; 12 + 13 + switch (flavor) 14 + { 15 + case THREAD_IDENTIFIER_INFO: 16 + { 17 + std::stringstream ss; 18 + std::ifstream fs; 19 + std::string procpath; 20 + thread_identifier_info* info = static_cast<thread_identifier_info*>(infoOut); 21 + 22 + if (*count < THREAD_IDENTIFIER_INFO_COUNT) 23 + return KERN_NO_SPACE; 24 + *count = THREAD_IDENTIFIER_INFO_COUNT; 25 + 26 + //info->thread_handle = Darling::tidForPthread(pthread_t(target_act)); 27 + info->thread_handle = target_act; 28 + info->dispatch_qaddr = 0; 29 + info->thread_id = info->thread_handle; 30 + 31 + ss << "/proc/" << getpid() << "/task/" << info->thread_handle << "/stat"; 32 + procpath = ss.str(); 33 + fs.open(procpath.c_str(), std::ios_base::in); 34 + 35 + if (fs.is_open()) 36 + { 37 + uint64_t dummy; 38 + for (int i = 0; i < 22; i++) 39 + fs >> dummy; 40 + info->thread_id = info->thread_handle << 32; 41 + info->thread_id |= dummy & 0xffffffff; // OR thread start time into lower 32 bits 42 + } 43 + 44 + return KERN_SUCCESS; 45 + } 46 + case THREAD_BASIC_INFO: 47 + return KERN_FAILURE; 48 + default: 49 + return KERN_INVALID_ARGUMENT; 50 + } 51 + } 52 +
+32
src/libSystem/kernel-mach/thread.h
··· 1 + #ifndef THREAD_H 2 + #define THREAD_H 3 + #include <stdint.h> 4 + #include "task.h" 5 + 6 + #define THREAD_BASIC_INFO 3 7 + #define THREAD_IDENTIFIER_INFO 4 8 + 9 + typedef natural_t thread_act_t; 10 + typedef natural_t thread_flavor_t; 11 + 12 + struct thread_identifier_info 13 + { 14 + uint64_t thread_id; 15 + uint64_t thread_handle; 16 + uint64_t dispatch_qaddr; 17 + }; 18 + 19 + #define THREAD_IDENTIFIER_INFO_COUNT (sizeof(struct thread_identifier_info) / sizeof(natural_t)) 20 + 21 + #ifdef __cplusplus 22 + extern "C" { 23 + #endif 24 + 25 + kern_return_t thread_info(thread_act_t target_act, thread_flavor_t flavor, void* infoOut, mach_msg_type_number_t* count); 26 + 27 + #ifdef __cplusplus 28 + } 29 + #endif 30 + 31 + #endif 32 +