added sceKernelSleep and small fix on usleep

This commit is contained in:
raziel1000 2024-06-08 18:43:08 -06:00
parent d3adcf2e6c
commit a790c30c28
2 changed files with 10 additions and 17 deletions

View File

@ -13,10 +13,6 @@ namespace Libraries::Kernel {
int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) { int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) {
LOG_INFO(Kernel_Fs, "path = {} flags = {:#x} mode = {}", path, flags, mode); LOG_INFO(Kernel_Fs, "path = {} flags = {:#x} mode = {}", path, flags, mode);
if (strcmp(path, "/dev/urandom") == 0 || strcmp(path, "/dev/random") == 0) {
std::srand(std::time(nullptr));
return 2222; // random hackish descriptor
}
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance(); auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance(); auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
@ -79,9 +75,6 @@ int PS4_SYSV_ABI sceKernelClose(int d) {
if (d < 3) { // d probably hold an error code if (d < 3) { // d probably hold an error code
return ORBIS_KERNEL_ERROR_EPERM; return ORBIS_KERNEL_ERROR_EPERM;
} }
if (d == 2222) { // random / urandom
return SCE_OK;
}
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance(); auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
auto* file = h->GetFile(d); auto* file = h->GetFile(d);
if (file == nullptr) { if (file == nullptr) {
@ -151,14 +144,6 @@ s64 PS4_SYSV_ABI lseek(int d, s64 offset, int whence) {
} }
s64 PS4_SYSV_ABI sceKernelRead(int d, void* buf, size_t nbytes) { s64 PS4_SYSV_ABI sceKernelRead(int d, void* buf, size_t nbytes) {
if (d == 2222) { // random / urandom
auto charbuff = static_cast<char*>(buf);
for (size_t i = 0; i < nbytes; i++)
charbuff[i] = std::rand() & 0xFF;
return nbytes;
}
if (buf == nullptr) { if (buf == nullptr) {
return SCE_KERNEL_ERROR_EFAULT; return SCE_KERNEL_ERROR_EFAULT;
} }

View File

@ -53,12 +53,19 @@ int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) {
return SCE_OK; return SCE_OK;
} }
void PS4_SYSV_ABI sceKernelUsleep(u32 microseconds) { int PS4_SYSV_ABI sceKernelUsleep(u32 microseconds) {
std::this_thread::sleep_for(std::chrono::microseconds(microseconds)); std::this_thread::sleep_for(std::chrono::microseconds(microseconds));
return SCE_OK;
} }
void PS4_SYSV_ABI posix_usleep(u32 microseconds) { int PS4_SYSV_ABI posix_usleep(u32 microseconds) {
std::this_thread::sleep_for(std::chrono::microseconds(microseconds)); std::this_thread::sleep_for(std::chrono::microseconds(microseconds));
return SCE_OK;
}
int PS4_SYSV_ABI sceKernelSleep(u32 seconds) {
std::this_thread::sleep_for(std::chrono::seconds(seconds));
return SCE_OK;
} }
struct iovec { struct iovec {
@ -273,6 +280,7 @@ void LibKernel_Register(Core::Loader::SymbolsResolver* sym) {
LIB_FUNCTION("BPE9s9vQQXo", "libkernel", 1, "libkernel", 1, 1, posix_mmap); LIB_FUNCTION("BPE9s9vQQXo", "libkernel", 1, "libkernel", 1, 1, posix_mmap);
LIB_FUNCTION("1jfXLRVzisc", "libkernel", 1, "libkernel", 1, 1, sceKernelUsleep); LIB_FUNCTION("1jfXLRVzisc", "libkernel", 1, "libkernel", 1, 1, sceKernelUsleep);
LIB_FUNCTION("QcteRwbsnV0", "libScePosix", 1, "libkernel", 1, 1, posix_usleep); LIB_FUNCTION("QcteRwbsnV0", "libScePosix", 1, "libkernel", 1, 1, posix_usleep);
LIB_FUNCTION("-ZR+hG7aDHw", "libkernel", 1, "libkernel", 1, 1, sceKernelSleep);
LIB_FUNCTION("YSHRBRLn2pI", "libkernel", 1, "libkernel", 1, 1, _writev); LIB_FUNCTION("YSHRBRLn2pI", "libkernel", 1, "libkernel", 1, 1, _writev);
LIB_FUNCTION("959qrazPIrg", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcParam); LIB_FUNCTION("959qrazPIrg", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcParam);
LIB_FUNCTION("-o5uEDpN+oY", "libkernel", 1, "libkernel", 1, 1, sceKernelConvertUtcToLocaltime); LIB_FUNCTION("-o5uEDpN+oY", "libkernel", 1, "libkernel", 1, 1, sceKernelConvertUtcToLocaltime);