libctru/libctru/source/system/syscalls.c

60 lines
1.7 KiB
C
Raw Normal View History

#include <sys/iosupport.h>
#include <sys/time.h>
#include <sys/lock.h>
#include <sys/reent.h>
#include <string.h>
#include <3ds/types.h>
#include <3ds/svc.h>
#include <3ds/env.h>
#include <3ds/synchronization.h>
#include "../internal.h"
void __ctru_exit(int rc);
int __libctru_gtod(struct _reent *ptr, struct timeval *tp, struct timezone *tz);
2015-11-25 21:46:54 +01:00
extern const u8 __tdata_lma[];
extern const u8 __tdata_lma_end[];
extern u8 __tls_start[];
static struct _reent* __ctru_get_reent()
{
ThreadVars* tv = getThreadVars();
if (tv->magic != THREADVARS_MAGIC)
{
svcBreak(USERBREAK_PANIC);
for (;;);
}
return tv->reent;
}
void __system_initSyscalls(void)
{
// Register newlib syscalls
__syscalls.exit = __ctru_exit;
__syscalls.gettod_r = __libctru_gtod;
__syscalls.getreent = __ctru_get_reent;
// Register locking syscalls
__syscalls.lock_init = LightLock_Init;
__syscalls.lock_acquire = LightLock_Lock;
__syscalls.lock_try_acquire = LightLock_TryLock;
__syscalls.lock_release = LightLock_Unlock;
__syscalls.lock_init_recursive = RecursiveLock_Init;
__syscalls.lock_acquire_recursive = RecursiveLock_Lock;
__syscalls.lock_try_acquire_recursive = RecursiveLock_TryLock;
__syscalls.lock_release_recursive = RecursiveLock_Unlock;
// Initialize thread vars for the main thread
ThreadVars* tv = getThreadVars();
tv->magic = THREADVARS_MAGIC;
tv->reent = _impure_ptr;
2015-11-21 18:55:05 +01:00
tv->thread_ptr = NULL;
2015-11-25 21:46:54 +01:00
tv->tls_tp = __tls_start-8; // ARM ELF TLS ABI mandates an 8-byte header
tv->srv_blocking_policy = false;
2015-11-25 21:46:54 +01:00
u32 tls_size = __tdata_lma_end - __tdata_lma;
if (tls_size)
memcpy(__tls_start, __tdata_lma, tls_size);
}