diff --git a/libctru/source/os.c b/libctru/source/os.c index 8a65daa..bdf1924 100644 --- a/libctru/source/os.c +++ b/libctru/source/os.c @@ -88,27 +88,6 @@ u64 osGetTime(void) { return tr.value_ms + elapsed_ms; } -//--------------------------------------------------------------------------------- -int __libctru_gtod(struct _reent *ptr, struct timeval *tp, struct timezone *tz) { -//--------------------------------------------------------------------------------- - if (tp != NULL) { - // Retrieve current time, adjusting epoch from 1900 to 1970 - s64 now = osGetTime() - 2208988800000ULL; - - // Convert to struct timeval - tp->tv_sec = now / 1000; - tp->tv_usec = (now - 1000*tp->tv_sec) * 1000; - } - - if (tz != NULL) { - // Provide dummy information, as the 3DS does not have the concept of timezones - tz->tz_minuteswest = 0; - tz->tz_dsttime = 0; - } - - return 0; -} - //--------------------------------------------------------------------------------- double osTickCounterRead(const TickCounter* cnt) { //--------------------------------------------------------------------------------- diff --git a/libctru/source/system/syscalls.c b/libctru/source/system/syscalls.c index 3c64e57..1308326 100644 --- a/libctru/source/system/syscalls.c +++ b/libctru/source/system/syscalls.c @@ -7,17 +7,17 @@ #include <3ds/types.h> #include <3ds/svc.h> #include <3ds/env.h> +#include <3ds/os.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); extern const u8 __tdata_lma[]; extern const u8 __tdata_lma_end[]; extern u8 __tls_start[]; -static struct _reent* __libctru_get_reent() +struct _reent* __SYSCALL(getreent)() { ThreadVars* tv = getThreadVars(); if (tv->magic != THREADVARS_MAGIC) @@ -28,29 +28,80 @@ static struct _reent* __libctru_get_reent() return tv->reent; } -static int __libctru_nanosleep(const struct timespec *req, struct timespec *rem) +//--------------------------------------------------------------------------------- +int __SYSCALL(gettod_r)(struct _reent *ptr, struct timeval *tp, struct timezone *tz) { +//--------------------------------------------------------------------------------- + if (tp != NULL) { + // Retrieve current time, adjusting epoch from 1900 to 1970 + s64 now = osGetTime() - 2208988800000ULL; + + // Convert to struct timeval + tp->tv_sec = now / 1000; + tp->tv_usec = (now - 1000*tp->tv_sec) * 1000; + } + + if (tz != NULL) { + // Provide dummy information, as the 3DS does not have the concept of timezones + tz->tz_minuteswest = 0; + tz->tz_dsttime = 0; + } + + return 0; +} + +int __SYSCALL(nanosleep)(const struct timespec *req, struct timespec *rem) { svcSleepThread(req->tv_sec * 1000000000ull + req->tv_nsec); return 0; } +void __SYSCALL(lock_init) (_LOCK_T *lock) +{ + LightLock_Init(lock); +} + +void __SYSCALL(lock_acquire) (_LOCK_T *lock) +{ + LightLock_Lock(lock); +} + +int __SYSCALL(lock_try_acquire) (_LOCK_T *lock) +{ + return LightLock_TryLock(lock); +} + +void __SYSCALL(lock_release) (_LOCK_T *lock) +{ + LightLock_Unlock(lock); +} + +void __SYSCALL(lock_init_recursive) (_LOCK_RECURSIVE_T *lock) +{ + RecursiveLock_Init(lock); +} + +void __SYSCALL(lock_acquire_recursive) (_LOCK_RECURSIVE_T *lock) +{ + RecursiveLock_Lock(lock); +} + +int __SYSCALL(lock_try_acquire_recursive) (_LOCK_RECURSIVE_T *lock) +{ + return RecursiveLock_TryLock(lock); +} + +void __SYSCALL(lock_release_recursive) (_LOCK_RECURSIVE_T *lock) +{ + RecursiveLock_Unlock(lock); +} + +void __SYSCALL(exit)(int rc) { + __ctru_exit(rc); +} + + void __system_initSyscalls(void) { - // Register newlib syscalls - __syscalls.exit = __ctru_exit; - __syscalls.gettod_r = __libctru_gtod; - __syscalls.getreent = __libctru_get_reent; - __syscalls.nanosleep = __libctru_nanosleep; - - // 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();