| 393 | } |
| 394 | |
| 395 | FEXCore::Core::InternalThreadState* |
| 396 | ContextImpl::CreateThread(uint64_t InitialRIP, uint64_t StackPointer, const FEXCore::Core::CPUState* NewThreadState) { |
| 397 | FEXCore::Core::InternalThreadState* Thread = new FEXCore::Core::InternalThreadState { |
| 398 | .CTX = this, |
| 399 | }; |
| 400 | |
| 401 | Thread->CurrentFrame->State.gregs[X86State::REG_RSP] = StackPointer; |
| 402 | Thread->CurrentFrame->State.rip = InitialRIP; |
| 403 | |
| 404 | // Copy over the new thread state to the new object |
| 405 | if (NewThreadState) { |
| 406 | memcpy(&Thread->CurrentFrame->State, NewThreadState, sizeof(FEXCore::Core::CPUState)); |
| 407 | } |
| 408 | |
| 409 | // Set up the thread manager state |
| 410 | Thread->CurrentFrame->Thread = Thread; |
| 411 | |
| 412 | InitializeCompiler(Thread); |
| 413 | |
| 414 | Thread->CurrentFrame->State.DeferredSignalRefCount.Store(0); |
| 415 | |
| 416 | if (Config.BlockJITNaming() || Config.GlobalJITNaming() || Config.LibraryJITNaming()) { |
| 417 | // Allocate a JIT symbol buffer only if enabled. |
| 418 | Thread->SymbolBuffer = JITSymbols::AllocateBuffer(); |
| 419 | } |
| 420 | |
| 421 | return Thread; |
| 422 | } |
| 423 | |
| 424 | void ContextImpl::DestroyThread(FEXCore::Core::InternalThreadState* Thread) { |
| 425 | FEXCore::Allocator::VirtualProtect(&Thread->InterruptFaultPage, sizeof(Thread->InterruptFaultPage), |