mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
feat(libkernel): libkernel time functions impl
This commit is contained in:
@@ -8,6 +8,7 @@ add_library(libkernel SHARED EXCLUDE_FROM_ALL
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Pthread/src/Cond.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Pthread/src/Attr.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Pthread/src/Thread.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Time/Time.cpp
|
||||
)
|
||||
|
||||
target_include_directories(libkernel PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
|
||||
@@ -169,12 +169,6 @@ int APS5_VABI mkdir_nid_postfix(const char* path, uint16_t mode) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI nanosleep_nid_postfix(const KernelTimespec* rqtp, KernelTimespec* rmtp) {
|
||||
(void)rqtp;
|
||||
(void)rmtp;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI open_nid_postfix(const char* path, int flags, int mode) {
|
||||
(void)path;
|
||||
@@ -918,20 +912,6 @@ int APS5_VABI sceKernelGetPageTableStats(int* cpu_total, int* cpu_available, int
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t APS5_VABI sceKernelGetProcessTime(void) {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t APS5_VABI sceKernelGetProcessTimeCounter(void) {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t APS5_VABI sceKernelGetProcessTimeCounterFrequency(void) {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* APS5_VABI sceKernelGetProcParam(void) {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
@@ -1089,12 +1069,6 @@ int APS5_VABI sceKernelMtypeprotect(const void* addr, size_t len, int type, int
|
||||
}
|
||||
|
||||
|
||||
int APS5_VABI sceKernelNanosleep(const KernelTimespec* rqtp, KernelTimespec* rmtp) {
|
||||
(void)rqtp;
|
||||
(void)rmtp;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceKernelOpen(const char* path, int flags, uint16_t mode) {
|
||||
(void)path;
|
||||
@@ -1291,11 +1265,6 @@ int APS5_VABI sceKernelUnlink(const char* path) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceKernelUsleep(KernelUseconds microseconds) {
|
||||
(void)microseconds;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceKernelUuidCreate(uint32_t* uuid) {
|
||||
(void)uuid;
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
#include "prx/libkernel/Time/include/Time.hpp"
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstdint>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
static std::uint64_t GetMonotonicNanos() {
|
||||
#ifdef _WIN32
|
||||
static const std::uint64_t freq = [] {
|
||||
LARGE_INTEGER f{};
|
||||
QueryPerformanceFrequency(&f);
|
||||
return static_cast<std::uint64_t>(f.QuadPart);
|
||||
}();
|
||||
LARGE_INTEGER counter{};
|
||||
QueryPerformanceCounter(&counter);
|
||||
return static_cast<std::uint64_t>(counter.QuadPart) * 1000000000ULL / freq;
|
||||
#else
|
||||
struct timespec ts{};
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return static_cast<std::uint64_t>(ts.tv_sec) * 1000000000ULL +
|
||||
static_cast<std::uint64_t>(ts.tv_nsec);
|
||||
#endif
|
||||
}
|
||||
|
||||
static std::uint64_t GetStartNanos() {
|
||||
static const std::uint64_t start = GetMonotonicNanos();
|
||||
return start;
|
||||
}
|
||||
|
||||
static void SleepNanos(std::uint64_t nanos) {
|
||||
if (nanos == 0) {
|
||||
return;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
const DWORD millis = static_cast<DWORD>(nanos / 1000000ULL);
|
||||
if (millis > 0) {
|
||||
Sleep(millis);
|
||||
}
|
||||
#else
|
||||
struct timespec req{};
|
||||
req.tv_sec = static_cast<time_t>(nanos / 1000000000ULL);
|
||||
req.tv_nsec = static_cast<long>(nanos % 1000000000ULL);
|
||||
while (nanosleep(&req, &req) == -1 && errno == EINTR) {}
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
std::uint64_t APS5_VABI sceKernelGetProcessTime() {
|
||||
return (GetMonotonicNanos() - GetStartNanos()) / 1000ULL;
|
||||
}
|
||||
|
||||
std::uint64_t APS5_VABI sceKernelGetProcessTimeCounter() {
|
||||
return GetMonotonicNanos() - GetStartNanos();
|
||||
}
|
||||
|
||||
std::uint64_t APS5_VABI sceKernelGetProcessTimeCounterFrequency() {
|
||||
return 1000000000ULL;
|
||||
}
|
||||
|
||||
int APS5_VABI sceKernelUsleep_nid_postfix(KernelUseconds microseconds) {
|
||||
SleepNanos(static_cast<std::uint64_t>(microseconds) * 1000ULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceKernelNanosleep(const KernelTimespec* rqtp, KernelTimespec* rmtp) {
|
||||
if (rqtp == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
if (rqtp->tv_sec < 0 || rqtp->tv_nsec < 0 || rqtp->tv_nsec >= 1000000000LL) {
|
||||
return -1;
|
||||
}
|
||||
SleepNanos(static_cast<std::uint64_t>(rqtp->tv_sec) * 1000000000ULL +
|
||||
static_cast<std::uint64_t>(rqtp->tv_nsec));
|
||||
if (rmtp != nullptr) {
|
||||
rmtp->tv_sec = 0;
|
||||
rmtp->tv_nsec = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI nanosleep_nid_postfix(const KernelTimespec* rqtp, KernelTimespec* rmtp) {
|
||||
return sceKernelNanosleep(rqtp, rmtp);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef CORE_LIBS_PRX_LIBKERNEL_TIME_INCLUDE_TIME_HPP
|
||||
#define CORE_LIBS_PRX_LIBKERNEL_TIME_INCLUDE_TIME_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include "SceTypes.hpp"
|
||||
#include "prx/libc/include/general/VabiMacros.hpp"
|
||||
|
||||
extern "C" {
|
||||
|
||||
std::uint64_t APS5_VABI sceKernelGetProcessTime();
|
||||
std::uint64_t APS5_VABI sceKernelGetProcessTimeCounter();
|
||||
std::uint64_t APS5_VABI sceKernelGetProcessTimeCounterFrequency();
|
||||
int APS5_VABI sceKernelUsleep_nid_postfix(KernelUseconds microseconds);
|
||||
int APS5_VABI sceKernelNanosleep(const KernelTimespec* rqtp, KernelTimespec* rmtp);
|
||||
int APS5_VABI nanosleep_nid_postfix(const KernelTimespec* rqtp, KernelTimespec* rmtp);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user