this repo has no description
1
fork

Configure Feed

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

Use correct Mach iface for exceptions

If this breaks the build for you, then delete macosxServer.c from your build directory

+70 -28
+2
src/kernel/emulation/linux/CMakeLists.txt
··· 23 23 ) 24 24 25 25 mig(signal/mach_exc.defs) 26 + mig(signal/exc.defs) 26 27 27 28 set(emulation_sources 28 29 ${CMAKE_CURRENT_BINARY_DIR}/signal/mach_excUser.c 30 + ${CMAKE_CURRENT_BINARY_DIR}/signal/excUser.c 29 31 elfcalls_wrapper.c 30 32 base.c 31 33 syscalls.c
+1
src/kernel/emulation/linux/signal/exc.defs
··· 1 + ../../../../../platform-include/mach/exc.defs
+67 -26
src/kernel/emulation/linux/signal/sigexc.c
··· 6 6 #include <linux-syscalls/linux.h> 7 7 #include <pthread/tsd_private.h> 8 8 #include "signal/mach_exc.h" 9 + #include "signal/exc.h" 9 10 #include "sigaltstack.h" 10 11 #include "../mach/lkm.h" 11 12 #include "../../../../lkm/api.h" ··· 52 53 { 53 54 __simple_printf("the predecessor is traced\n"); 54 55 darling_sigexc_self(); 55 - sys_kill(getpid(), SIGTRAP, 1); 56 + sigexc_handler(LINUX_SIGTRAP, NULL, NULL); 56 57 } 57 58 } 58 59 ··· 125 126 for (int i = 1; i <= 31; i++) 126 127 { 127 128 struct linux_sigaction sa; 128 - sa.sa_sigaction = sigexc_handler; 129 + sa.sa_sigaction = (linux_sig_handler*) sigexc_handler; 129 130 sa.sa_mask = 0xffffffff; // all other standard Unix signals should be blocked while the handler is run 130 131 sa.sa_flags = LINUX_SA_RESTORER | LINUX_SA_SIGINFO | LINUX_SA_RESTART | LINUX_SA_ONSTACK; 131 132 sa.sa_restorer = sig_restorer; ··· 171 172 sys_sigaltstack(&orig_stack, NULL); 172 173 } 173 174 174 - static mach_port_t get_exc_port(int type) 175 + static mach_port_t get_exc_port(int type, int* behavior) 175 176 { 176 177 mach_msg_type_number_t count = 0; 177 178 exception_mask_t masks[EXC_TYPES_COUNT]; ··· 182 183 kern_return_t result = task_get_exception_ports(mach_task_self(), 1 << type, 183 184 masks, &count, ports, behaviors, flavors); 184 185 185 - if (result == KERN_SUCCESS) 186 - return ports[type]; 186 + if (result != KERN_SUCCESS) 187 + return 0; 188 + 189 + for (int i = 0; i < count; i++) 190 + { 191 + if (masks[i] & (1 << type)) 192 + { 193 + if (behavior != NULL) 194 + *behavior = behaviors[i]; 195 + return ports[i]; 196 + } 197 + } 187 198 188 199 return 0; 189 200 } ··· 203 214 // Send a Mach message to the debugger. 204 215 // The debugger may use ptrace(PT_THUPDATE) to change how the signal is processed. 205 216 206 - int mach_exception; 217 + int mach_exception, behavior; 207 218 long long codes[EXCEPTION_CODE_MAX] = { 0 }; 208 219 mach_port_t port; 209 220 thread_t thread = mach_thread_self(); ··· 249 260 codes[1] = bsd_signum; 250 261 } 251 262 252 - port = get_exc_port(mach_exception); 263 + port = get_exc_port(mach_exception, &behavior); 253 264 254 265 // Pass register states to LKM 255 266 #if defined(__x86_64__) 256 267 x86_thread_state64_t tstate; 257 268 x86_float_state64_t fstate; 258 269 259 - mcontext_to_thread_state(&ctxt->uc_mcontext.gregs, &tstate); 260 - mcontext_to_float_state(ctxt->uc_mcontext.fpregs, &fstate); 270 + if (ctxt != NULL) 271 + { 272 + mcontext_to_thread_state(&ctxt->uc_mcontext.gregs, &tstate); 273 + mcontext_to_float_state(ctxt->uc_mcontext.fpregs, &fstate); 274 + } 275 + else 276 + { 277 + memset(&tstate, 0, sizeof(tstate)); 278 + memset(&fstate, 0, sizeof(fstate)); 279 + } 261 280 262 281 thread_set_state(thread, x86_THREAD_STATE64, (thread_state_t) &tstate, x86_THREAD_STATE64_COUNT); 263 282 thread_set_state(thread, x86_FLOAT_STATE64, (thread_state_t) &fstate, x86_FLOAT_STATE64_COUNT); ··· 265 284 x86_thread_state32_t tstate; 266 285 x86_float_state32_t fstate; 267 286 268 - mcontext_to_thread_state(&ctxt->uc_mcontext.gregs, &tstate); 269 - mcontext_to_float_state(ctxt->uc_mcontext.fpregs, &fstate); 287 + if (ctxt != NULL) 288 + { 289 + mcontext_to_thread_state(&ctxt->uc_mcontext.gregs, &tstate); 290 + mcontext_to_float_state(ctxt->uc_mcontext.fpregs, &fstate); 291 + } 292 + else 293 + { 294 + memset(&tstate, 0, sizeof(tstate)); 295 + memset(&fstate, 0, sizeof(fstate)); 296 + } 270 297 271 298 thread_set_state(thread, x86_THREAD_STATE32, (thread_state_t) &tstate, x86_THREAD_STATE32_COUNT); 272 299 thread_set_state(thread, x86_FLOAT_STATE32, (thread_state_t) &fstate, x86_FLOAT_STATE32_COUNT); ··· 277 304 { 278 305 _pthread_setspecific_direct(SIGEXC_TSD_KEY, bsd_signum); 279 306 280 - mach_exception_raise(port, mach_thread_self(), thread, mach_exception, codes, sizeof(codes) / sizeof(codes[0])); 307 + if (behavior & MACH_EXCEPTION_CODES) 308 + { 309 + mach_exception_raise(port, thread, mach_task_self(), mach_exception, codes, sizeof(codes) / sizeof(codes[0])); 310 + } 311 + else 312 + { 313 + exception_data_type_t small_codes[2] = { (exception_data_type_t) codes[0], (exception_data_type_t) codes[1] }; 314 + exception_raise(port, thread, mach_task_self(), mach_exception, small_codes, sizeof(small_codes) / sizeof(small_codes[0])); 315 + } 281 316 282 317 bsd_signum = _pthread_getspecific_direct(SIGEXC_TSD_KEY); 283 318 } 284 319 285 320 // Get (possibly updated by GDB) register states from LKM 321 + if (ctxt != NULL) 322 + { 286 323 #if defined(__x86_64__) 287 - mach_msg_type_number_t count; 324 + mach_msg_type_number_t count; 288 325 289 - count = x86_THREAD_STATE64_COUNT; 290 - thread_get_state(thread, x86_THREAD_STATE64, (thread_state_t) &tstate, &count); 291 - count = x86_FLOAT_STATE64_COUNT; 292 - thread_get_state(thread, x86_FLOAT_STATE64, (thread_state_t) &fstate, &count); 326 + count = x86_THREAD_STATE64_COUNT; 327 + thread_get_state(thread, x86_THREAD_STATE64, (thread_state_t) &tstate, &count); 328 + count = x86_FLOAT_STATE64_COUNT; 329 + thread_get_state(thread, x86_FLOAT_STATE64, (thread_state_t) &fstate, &count); 293 330 294 - thread_state_to_mcontext(&tstate, &ctxt->uc_mcontext.gregs); 295 - float_state_to_mcontext(&fstate, ctxt->uc_mcontext.fpregs); 331 + thread_state_to_mcontext(&tstate, &ctxt->uc_mcontext.gregs); 332 + float_state_to_mcontext(&fstate, ctxt->uc_mcontext.fpregs); 296 333 #elif defined(__i386__) 297 - mach_msg_type_number_t count; 334 + mach_msg_type_number_t count; 298 335 299 - count = x86_THREAD_STATE32_COUNT; 300 - thread_get_state(thread, x86_THREAD_STATE32, (thread_state_t) &tstate, &count); 301 - count = x86_FLOAT_STATE32_COUNT; 302 - thread_get_state(thread, x86_FLOAT_STATE32, (thread_state_t) &fstate, &count); 336 + count = x86_THREAD_STATE32_COUNT; 337 + thread_get_state(thread, x86_THREAD_STATE32, (thread_state_t) &tstate, &count); 338 + count = x86_FLOAT_STATE32_COUNT; 339 + thread_get_state(thread, x86_FLOAT_STATE32, (thread_state_t) &fstate, &count); 303 340 304 - thread_state_to_mcontext(&tstate, &ctxt->uc_mcontext.gregs); 305 - float_state_to_mcontext(&fstate, ctxt->uc_mcontext.fpregs); 341 + thread_state_to_mcontext(&tstate, &ctxt->uc_mcontext.gregs); 342 + float_state_to_mcontext(&fstate, ctxt->uc_mcontext.fpregs); 306 343 #endif 344 + } 307 345 308 346 // Pass the signal to the application handler or emulate the effects of the signal if SIG_DFL is set. 309 347 if (bsd_signum) ··· 324 362 case SIGWINCH: 325 363 case SIGURG: 326 364 break; 365 + case SIGTRAP: 366 + if (ctxt == NULL) 367 + break; // This trap wasn't caused by int3, carry on 327 368 328 369 // Other signals cause termination or core dump. 329 370 default:
-2
src/kernel/libsyscall/CMakeLists.txt
··· 23 23 24 24 include_directories(${CMAKE_SOURCE_DIR}/src/lkm/osfmk) 25 25 set(MIG_USER_HEADER_SUFFIX "_internal.h") 26 - mig(mach/exc.defs) 27 26 mig(mach/host_priv.defs) 28 27 mig(mach/host_security.defs) 29 28 mig(mach/ledger.defs) ··· 142 141 custom/errno.c 143 142 144 143 # MIG generated files 145 - ${CMAKE_CURRENT_BINARY_DIR}/mach/excUser.c 146 144 ${CMAKE_CURRENT_BINARY_DIR}/mach/host_privUser.c 147 145 ${CMAKE_CURRENT_BINARY_DIR}/mach/host_securityUser.c 148 146 ${CMAKE_CURRENT_BINARY_DIR}/mach/ledgerUser.c