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

Commit

Permalink
Change the parameters of start
Browse files Browse the repository at this point in the history
On the switch, `start` takes two parameters : an exception pointer,
and a handle to the main thread. For libtransistor, we'll also add
a third one: a context handle. This should allow ace_loader to start
apps expecting the usual switch treatment, while still providing the
context to libtransistor binaries.
  • Loading branch information
roblabla committed Jan 1, 2018
1 parent 01f61aa commit c6797cf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/crt0.nro.S
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ _mod_header:
start:
sub sp, sp, 0x10
stp x29, x30, [sp]
adrp x1, _start // aslr base
adrp x3, _start // aslr base
bl _libtransistor_start
ldp x29, x30, [sp], 0x10
ret
Expand Down
2 changes: 1 addition & 1 deletion lib/crt0.nso.S
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ _mod_header:

.section .text, "e"
start:
adrp x1, _start // aslr base
adrp x3, _start // aslr base
bl _libtransistor_start
loop:
b loop
Expand Down
7 changes: 6 additions & 1 deletion lib/crt0_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,17 @@ static int bsslog_write(struct _reent *reent, void *v, const char *ptr, int len)

static jmp_buf exit_jmpbuf;
static int exit_value;
static thread_h MAIN_HANDLE;

int _libtransistor_start(libtransistor_context_t *ctx, void *aslr_base) {
int _libtransistor_start(void *exception_info_ptr, thread_h main_handle, libtransistor_context_t *ctx, void *aslr_base) {
if(relocate(aslr_base)) {
return -4;
}

MAIN_HANDLE = main_handle;

dbg_printf("exception_ptr: %x", exception_info_ptr);
dbg_printf("main handle: %x", main_handle);
dbg_printf("aslr base: %p", aslr_base);
dbg_printf("ctx: %p", ctx);

Expand Down
4 changes: 2 additions & 2 deletions projects/ace_loader/nro.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern thread_h aceloader_main_thread_handle;

uint64_t nro_start()
{
uint64_t (*entry)(libtransistor_context_t*) = nro_base + 0x80;
uint64_t (*entry)(void *, thread_h, libtransistor_context_t*) = nro_base + 0x80;
uint64_t ret;

// generate memory block
Expand Down Expand Up @@ -73,7 +73,7 @@ uint64_t nro_start()
*(void**)(get_tls() + 0x1f8) = NULL;

// run NRO
ret = entry(&loader_context);
ret = entry(NULL, aceloader_main_thread_handle, &loader_context);

// Restore TLS
*tls_userspace_pointer = tls_backup;
Expand Down

0 comments on commit c6797cf

Please sign in to comment.