From f303897b010de98b925d46df8a04b176ed7b3efa Mon Sep 17 00:00:00 2001 From: roblabla Date: Fri, 8 Dec 2017 01:08:34 +0100 Subject: [PATCH 1/3] Put the main thread handle in the thread context --- include/libtransistor/context.h | 2 ++ projects/ace_loader/main.c | 3 +++ projects/ace_loader/nro.c | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/include/libtransistor/context.h b/include/libtransistor/context.h index 190d3039..be1cdc93 100644 --- a/include/libtransistor/context.h +++ b/include/libtransistor/context.h @@ -41,6 +41,8 @@ typedef struct { uint32_t workstation_addr; // in uint64_t return_flags; // out + + thread_h 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..60379bd3 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..9314a0a5 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; From 82a8a427d246869871b8f9d0b78b6f0471fa4397 Mon Sep 17 00:00:00 2001 From: roblabla Date: Fri, 8 Dec 2017 01:26:24 +0100 Subject: [PATCH 2/3] Increment context version, make global lowercased --- include/libtransistor/context.h | 2 +- projects/ace_loader/main.c | 4 ++-- projects/ace_loader/nro.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/libtransistor/context.h b/include/libtransistor/context.h index be1cdc93..84258e60 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 diff --git a/projects/ace_loader/main.c b/projects/ace_loader/main.c index 60379bd3..b3b1c472 100644 --- a/projects/ace_loader/main.c +++ b/projects/ace_loader/main.c @@ -41,7 +41,7 @@ struct sockaddr_in stdout_server_addr = .sin_port = htons(STDOUT_PORT), }; -thread_h ACELOADER_MAIN_THREAD_HANDLE; +thread_h aceloader_main_thread_handle; uint64_t extra_cleanup(uint64_t arg0); @@ -122,7 +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; + 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 9314a0a5..1cf82834 100644 --- a/projects/ace_loader/nro.c +++ b/projects/ace_loader/nro.c @@ -24,7 +24,7 @@ static char nro_args[NRO_MAX_ARG_BUF]; static int nro_argc; static char *nro_argoffs; -extern thread_h ACELOADER_MAIN_THREAD_HANDLE; +extern thread_h aceloader_main_thread_handle; uint64_t nro_start() { @@ -65,7 +65,7 @@ uint64_t nro_start() loader_context.return_flags = 0; // out - loader_context.main_thread = ACELOADER_MAIN_THREAD_HANDLE; + loader_context.main_thread = aceloader_main_thread_handle; // Backup and clean main thread TLS pointer void **tls_userspace_pointer = (void**)(get_tls() + 0x1F8); From 952466b5b03903a9715a3aa30a588cd558f34c48 Mon Sep 17 00:00:00 2001 From: roblabla Date: Fri, 8 Dec 2017 01:27:32 +0100 Subject: [PATCH 3/3] Specify that thread_main is an in paramter in ctx --- include/libtransistor/context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/libtransistor/context.h b/include/libtransistor/context.h index 84258e60..e14ca1a1 100644 --- a/include/libtransistor/context.h +++ b/include/libtransistor/context.h @@ -42,7 +42,7 @@ typedef struct { uint64_t return_flags; // out - thread_h main_thread; + thread_h main_thread; // in, handle to main thread. } libtransistor_context_t; extern libtransistor_context_t *libtransistor_context;