thread affinity, task_set_exception_ports

This commit is contained in:
Stefanos Kornilios Mitsis Poiitidis 2024-09-14 15:54:16 +03:00
parent 062244a722
commit a7032b1004
2 changed files with 27 additions and 0 deletions

View file

@ -22,6 +22,9 @@
#include <unordered_map>
#include <unistd.h>
#include <fcntl.h>
void set_thread_affinity();
extern "C" {
#include "x64emu.h"
#include "x64run.h"
@ -305,6 +308,7 @@ static void RunMainEntry(VAddr addr, EntryParams* params, ExitFunc exit_func) {
SetRSI(emu, rsi);
emu->quit = 0;
set_thread_affinity();
Run(emu, 0);
UNIMPLEMENTED_MSG("Missing RunMainEntry() implementation for target CPU architecture.");
@ -334,6 +338,7 @@ void* RunThreadEntry(u64 thread, void* arg) {
emu->quit = 0;
set_thread_affinity();
Run(emu, 0);
auto rv = emu->regs[_RAX].q[0];
@ -414,6 +419,7 @@ void Linker::Execute() {
SetRDX(emu, 0);
emu->quit = 0;
set_thread_affinity();
Run(emu, 0);
}
}
@ -648,6 +654,7 @@ void* heap_api_malloc(Core::HeapAPI* heap_api, size_t size) {
SetRSP(emu, rsp);
SetRDI(emu, size);
set_thread_affinity();
Run(emu, 0);
return (void*)emu->regs[_RAX].q[0];

View file

@ -5,7 +5,19 @@
#include "common/memory_patcher.h"
#include "emulator.h"
#include <mach/task.h>
#include <mach/mach_init.h>
#include <mach/mach_port.h>
void set_thread_affinity();
int main(int argc, char* argv[]) {
set_thread_affinity();
task_set_exception_ports(
mach_task_self(),
EXC_MASK_BAD_ACCESS,
MACH_PORT_NULL,//m_exception_port,
EXCEPTION_DEFAULT,
0);
if (argc == 1) {
fmt::print("Usage: {} <elf or eboot.bin path>\n", argv[0]);
return -1;
@ -24,3 +36,11 @@ int main(int argc, char* argv[]) {
return 0;
}
#include <pthread.h>
#import <mach/thread_act.h>
void set_thread_affinity() {
thread_affinity_policy_data_t policyData1 = { 1 };
thread_policy_set(pthread_mach_thread_np(pthread_self()), THREAD_AFFINITY_POLICY, (thread_policy_t)&policyData1, 1);
}