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

Commit c6797cf

Browse files
committed
Change the parameters of start
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.
1 parent 01f61aa commit c6797cf

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

lib/crt0.nro.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ _mod_header:
4141
start:
4242
sub sp, sp, 0x10
4343
stp x29, x30, [sp]
44-
adrp x1, _start // aslr base
44+
adrp x3, _start // aslr base
4545
bl _libtransistor_start
4646
ldp x29, x30, [sp], 0x10
4747
ret

lib/crt0.nso.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ _mod_header:
3737

3838
.section .text, "e"
3939
start:
40-
adrp x1, _start // aslr base
40+
adrp x3, _start // aslr base
4141
bl _libtransistor_start
4242
loop:
4343
b loop

lib/crt0_common.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,17 @@ static int bsslog_write(struct _reent *reent, void *v, const char *ptr, int len)
158158

159159
static jmp_buf exit_jmpbuf;
160160
static int exit_value;
161+
static thread_h MAIN_HANDLE;
161162

162-
int _libtransistor_start(libtransistor_context_t *ctx, void *aslr_base) {
163+
int _libtransistor_start(void *exception_info_ptr, thread_h main_handle, libtransistor_context_t *ctx, void *aslr_base) {
163164
if(relocate(aslr_base)) {
164165
return -4;
165166
}
166167

168+
MAIN_HANDLE = main_handle;
169+
170+
dbg_printf("exception_ptr: %x", exception_info_ptr);
171+
dbg_printf("main handle: %x", main_handle);
167172
dbg_printf("aslr base: %p", aslr_base);
168173
dbg_printf("ctx: %p", ctx);
169174

projects/ace_loader/nro.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extern thread_h aceloader_main_thread_handle;
2828

2929
uint64_t nro_start()
3030
{
31-
uint64_t (*entry)(libtransistor_context_t*) = nro_base + 0x80;
31+
uint64_t (*entry)(void *, thread_h, libtransistor_context_t*) = nro_base + 0x80;
3232
uint64_t ret;
3333

3434
// generate memory block
@@ -73,7 +73,7 @@ uint64_t nro_start()
7373
*(void**)(get_tls() + 0x1f8) = NULL;
7474

7575
// run NRO
76-
ret = entry(&loader_context);
76+
ret = entry(NULL, aceloader_main_thread_handle, &loader_context);
7777

7878
// Restore TLS
7979
*tls_userspace_pointer = tls_backup;

0 commit comments

Comments
 (0)