aboutsummaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
authorJustin Weiss2019-10-05 21:35:06 -0700
committerJustin Weiss2019-10-05 21:41:37 -0700
commit93c24a5631ba5281046d2cd1b141cc2f0ce1d29f (patch)
treee7f11673ffaaa21b0cbd2fad2e5e3b367982a03b /frontend
parentd5c8842cedcf268d34ffe0be6abe4f8545cf2c5f (diff)
downloadpcsx_rearmed-93c24a5631ba5281046d2cd1b141cc2f0ce1d29f.tar.gz
pcsx_rearmed-93c24a5631ba5281046d2cd1b141cc2f0ce1d29f.tar.bz2
pcsx_rearmed-93c24a5631ba5281046d2cd1b141cc2f0ce1d29f.zip
3DS: Switch from svc* to the thread* API
svcCreateThread doesn't fully set up thread vars, which causes svcBreaks / crashes when calling certain functions -- reentrant ones, for example. threadCreate, etc. are higher-level functions that do all the correct setup and cleanup. Since we're treating the thread structure as opaque, calling it an int_32t seems OK.
Diffstat (limited to 'frontend')
-rw-r--r--frontend/3ds/3ds_utils.h8
-rw-r--r--frontend/3ds/pthread.h20
2 files changed, 10 insertions, 18 deletions
diff --git a/frontend/3ds/3ds_utils.h b/frontend/3ds/3ds_utils.h
index 3d50a66..1f12b84 100644
--- a/frontend/3ds/3ds_utils.h
+++ b/frontend/3ds/3ds_utils.h
@@ -2,6 +2,7 @@
#define _3DS_UTILS_H
#include <stdio.h>
+#include <stdbool.h>
#define MEMOP_PROT 6
#define MEMOP_MAP 4
@@ -15,9 +16,10 @@ int32_t svcCloseHandle(uint32_t handle);
int32_t svcControlMemory(void* addr_out, void* addr0, void* addr1, uint32_t size, uint32_t op, uint32_t perm);
int32_t svcControlProcessMemory(uint32_t process, void* addr0, void* addr1, uint32_t size, uint32_t op, uint32_t perm);
-int32_t svcCreateThread(int32_t* thread, void *(*entrypoint)(void*), void* arg, void* stack_top, int32_t thread_priority, int32_t processor_id);
-int32_t svcWaitSynchronization(int32_t handle, int64_t nanoseconds);
-void svcExitThread(void) __attribute__((noreturn));
+int32_t threadCreate(void *(*entrypoint)(void*), void* arg, size_t stack_size, int32_t prio, int32_t affinity, bool detached);
+int32_t threadJoin(int32_t thread, int64_t timeout_ns);
+void threadFree(int32_t thread);
+void threadExit(int32_t rc) __attribute__((noreturn));
int32_t svcBackdoor(int32_t (*callback)(void));
diff --git a/frontend/3ds/pthread.h b/frontend/3ds/pthread.h
index 42de161..9f43707 100644
--- a/frontend/3ds/pthread.h
+++ b/frontend/3ds/pthread.h
@@ -10,23 +10,13 @@
#define CTR_PTHREAD_STACK_SIZE 0x10000
-typedef struct
-{
- int32_t handle;
- uint32_t* stack;
-}pthread_t;
+typedef int32_t pthread_t;
typedef int pthread_attr_t;
static inline int pthread_create(pthread_t *thread,
const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg)
{
-
- thread->stack = linearMemAlign(CTR_PTHREAD_STACK_SIZE, 8);
-
- svcCreateThread(&thread->handle, start_routine, arg,
- (uint32_t*)((uint32_t)thread->stack + CTR_PTHREAD_STACK_SIZE),
- 0x25, -2);
-
+ thread = threadCreate(start_routine, arg, CTR_PTHREAD_STACK_SIZE, 0x25, -2, FALSE);
return 1;
}
@@ -35,10 +25,10 @@ static inline int pthread_join(pthread_t thread, void **retval)
{
(void)retval;
- if(svcWaitSynchronization(thread.handle, INT64_MAX))
+ if(threadJoin(thread, INT64_MAX))
return -1;
- linearFree(thread.stack);
+ threadFree(thread);
return 0;
}
@@ -48,7 +38,7 @@ static inline void pthread_exit(void *retval)
{
(void)retval;
- svcExitThread();
+ threadExit(0);
}