Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Put the main thread handle in the thread context #51

Merged
merged 3 commits into from
Dec 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/libtransistor/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions projects/ace_loader/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 4 additions & 0 deletions projects/ace_loader/nro.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down