diff --git a/include/libtransistor/context.h b/include/libtransistor/context.h index 190d3039..e14ca1a1 100644 --- a/include/libtransistor/context.h +++ b/include/libtransistor/context.h @@ -9,7 +9,7 @@ */ #define LIBTRANSISTOR_CONTEXT_MAGIC 0x007874635f656361 -#define LIBTRANSISTOR_CONTEXT_VERSION 2 +#define LIBTRANSISTOR_CONTEXT_VERSION 3 // return flags #define RETF_KEEP_LOADED 1 // do not unload NRO from memory @@ -41,6 +41,8 @@ typedef struct { uint32_t workstation_addr; // in uint64_t return_flags; // out + + thread_h main_thread; // in, handle to main thread. } libtransistor_context_t; extern libtransistor_context_t *libtransistor_context; diff --git a/projects/ace_loader/main.c b/projects/ace_loader/main.c index 5da21ca5..b3b1c472 100644 --- a/projects/ace_loader/main.c +++ b/projects/ace_loader/main.c @@ -41,6 +41,8 @@ struct sockaddr_in stdout_server_addr = .sin_port = htons(STDOUT_PORT), }; +thread_h aceloader_main_thread_handle; + uint64_t extra_cleanup(uint64_t arg0); // these handles seems to be always present @@ -120,6 +122,7 @@ void locate_threads(void *base, uint64_t size, int simple) { uint64_t *ptr = tc->sp_mirror; uint64_t sizE = tc->sp_size; + aceloader_main_thread_handle = tc->handle; uint64_t *bend = wkBase + WK_SIZE; switch(simple) { diff --git a/projects/ace_loader/nro.c b/projects/ace_loader/nro.c index 24753923..1cf82834 100644 --- a/projects/ace_loader/nro.c +++ b/projects/ace_loader/nro.c @@ -24,6 +24,8 @@ static char nro_args[NRO_MAX_ARG_BUF]; static int nro_argc; static char *nro_argoffs; +extern thread_h aceloader_main_thread_handle; + uint64_t nro_start() { uint64_t (*entry)(libtransistor_context_t*) = nro_base + 0x80; @@ -63,6 +65,8 @@ uint64_t nro_start() loader_context.return_flags = 0; // out + loader_context.main_thread = aceloader_main_thread_handle; + // Backup and clean main thread TLS pointer void **tls_userspace_pointer = (void**)(get_tls() + 0x1F8); void *tls_backup = *tls_userspace_pointer;