diff --git a/core/kernel/filesystem.cpp b/core/kernel/filesystem.cpp index 6a6ac99..6972361 100644 --- a/core/kernel/filesystem.cpp +++ b/core/kernel/filesystem.cpp @@ -353,8 +353,40 @@ size_t readv(int handle, const SceKernelIovec* iov, int iovcnt) { size_t writev(int handle, const SceKernelIovec* iov, int iovcnt) { LOG_USE_MODULE(filesystem); - LOG_ERR(L"todo %S", __FUNCTION__); - return Ok; + if (handle < FILE_DESCRIPTOR_MIN) { + return getErr(ErrCode::_EPERM); + } + + auto file = accessFileManager().getFile(handle); + if (file == nullptr) { + return getErr(ErrCode::_EBADF); + } + if (!(*file)) { + LOG_TRACE(L"file end"); + return 0; + } + + size_t count = 0; + + for (int n = 0; n < iovcnt; n++) { + auto* item = &iov[n]; + + if (item->iov_base == nullptr || item->iov_len == 0) continue; + + auto const start = file->tellp(); + + file->write((const char*)item->iov_base, item->iov_len); + + LOG_TRACE(L"KernelWrite[%d]: 0x%08llx:%llu write(%lld)", handle, (uint64_t)item->iov_base, item->iov_len, start); + + count = file->tellp() - start; + if (!(*file)) { + LOG_TRACE(L"file end"); + break; + } + } + + return count; } int fchmod(int fd, SceKernelMode mode) { @@ -624,4 +656,4 @@ int64_t lwfsLseek(int fd, int64_t offset, int whence) { size_t lwfsWrite(int fd, const void* buf, size_t nbytes) { return Ok; } -} // namespace filesystem \ No newline at end of file +} // namespace filesystem diff --git a/modules/libSceAudioOut/entry.cpp b/modules/libSceAudioOut/entry.cpp index 1eb7b92..17ff7f3 100644 --- a/modules/libSceAudioOut/entry.cpp +++ b/modules/libSceAudioOut/entry.cpp @@ -204,7 +204,7 @@ EXPORT SYSV_ABI int32_t sceAudioOutClose(int32_t handle) { EXPORT SYSV_ABI int32_t sceAudioOutOutput(int32_t handle, const void* ptr) { auto pimpl = getData(); - boost::unique_lock const lock(pimpl->mutexInt); + // boost::unique_lock const lock(pimpl->mutexInt); return writeOut(pimpl, handle, ptr); } @@ -240,7 +240,7 @@ EXPORT SYSV_ABI int32_t sceAudioOutSetVolume(int32_t handle, int32_t flag, int32 EXPORT SYSV_ABI int32_t sceAudioOutOutputs(SceAudioOutOutputParam* param, uint32_t num) { auto pimpl = getData(); - boost::unique_lock const lock(pimpl->mutexInt); + // boost::unique_lock const lock(pimpl->mutexInt); // dont block, causes audio artifacts for (uint32_t i = 0; i < num; i++) { if (auto err = writeOut(pimpl, param[i].handle, param[i].ptr); err != 0) return err; } diff --git a/modules/libSceHttp2/CMakeLists.txt b/modules/libSceHttp2/CMakeLists.txt new file mode 100644 index 0000000..18f1a99 --- /dev/null +++ b/modules/libSceHttp2/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.24) +include(../setupModule.cmake) + +set(libName libSceHttp2) +project(${libName}) + +add_library(${libName} SHARED entry.cpp) + +setupModule(${libName}) diff --git a/modules/libSceHttp2/codes.h b/modules/libSceHttp2/codes.h new file mode 100644 index 0000000..e9f8a9f --- /dev/null +++ b/modules/libSceHttp2/codes.h @@ -0,0 +1,4 @@ +#pragma once +#include + +namespace Err {} // namespace Err diff --git a/modules/libSceHttp2/entry.cpp b/modules/libSceHttp2/entry.cpp new file mode 100644 index 0000000..ada921f --- /dev/null +++ b/modules/libSceHttp2/entry.cpp @@ -0,0 +1,15 @@ +#include "codes.h" +#include "common.h" +#include "logging.h" +#include "types.h" + +LOG_DEFINE_MODULE(libSceHttp2); + +extern "C" { + +EXPORT const char* MODULE_NAME = "libSceHttp2"; + +EXPORT SYSV_ABI int32_t sceHttp2Init() { + return Ok; +} +} diff --git a/modules/libSceHttp2/types.h b/modules/libSceHttp2/types.h new file mode 100644 index 0000000..7832fd4 --- /dev/null +++ b/modules/libSceHttp2/types.h @@ -0,0 +1,2 @@ +#pragma once +#include "codes.h" diff --git a/modules/libSceJson2/CMakeLists.txt b/modules/libSceJson2/CMakeLists.txt new file mode 100644 index 0000000..951752c --- /dev/null +++ b/modules/libSceJson2/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.24) +include(../setupModule.cmake) + +set(libName libSceJson2) +project(${libName}) + +add_library(${libName} SHARED entry.cpp) + +setupModule(${libName}) diff --git a/modules/libSceJson2/codes.h b/modules/libSceJson2/codes.h new file mode 100644 index 0000000..e9f8a9f --- /dev/null +++ b/modules/libSceJson2/codes.h @@ -0,0 +1,4 @@ +#pragma once +#include + +namespace Err {} // namespace Err diff --git a/modules/libSceJson2/entry.cpp b/modules/libSceJson2/entry.cpp new file mode 100644 index 0000000..66e3327 --- /dev/null +++ b/modules/libSceJson2/entry.cpp @@ -0,0 +1,108 @@ +#include "codes.h" +#include "common.h" +#include "logging.h" +#include "types.h" + +LOG_DEFINE_MODULE(libSceJson2); + +extern "C" { + +EXPORT const char* MODULE_NAME = "libSceJson"; + +EXPORT SYSV_ABI int32_t __NID(_ZN3sce4Json12MemAllocatorC2Ev)() { + LOG_USE_MODULE(libSceJson2); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int32_t __NID(_ZN3sce4Json5ValueC1Ev)() { + LOG_USE_MODULE(libSceJson2); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int32_t __NID(_ZN3sce4Json5Value3setEb)() { + LOG_USE_MODULE(libSceJson2); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int32_t __NID(_ZN3sce4Json5Value3setEl)() { + LOG_USE_MODULE(libSceJson2); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int32_t __NID(_ZN3sce4Json5Value3setEm)() { + LOG_USE_MODULE(libSceJson2); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int32_t __NID(_ZN3sce4Json5Value3setEd)() { + LOG_USE_MODULE(libSceJson2); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int32_t __NID(_ZN3sce4Json6StringC1EPKc)() { + LOG_USE_MODULE(libSceJson2); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int32_t __NID(_ZN3sce4Json5Value3setERKNS0_6StringE)() { + LOG_USE_MODULE(libSceJson2); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int32_t __NID(_ZN3sce4Json6StringD1Ev)() { + LOG_USE_MODULE(libSceJson2); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int32_t __NID(_ZN3sce4Json5Value3setENS0_9ValueTypeE)() { + LOG_USE_MODULE(libSceJson2); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int32_t __NID_HEX(5923AE81EE48B028)() { + LOG_USE_MODULE(libSceJson2); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int32_t __NID_HEX(12EF798E6AA7E51C)() { + LOG_USE_MODULE(libSceJson2); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int32_t __NID_HEX(236402F0F6212566)() { + LOG_USE_MODULE(libSceJson2); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int32_t __NID(_ZN3sce4Json11InitializerC1Ev)() { + LOG_USE_MODULE(libSceJson2); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int32_t __NID(_ZN3sce4Json11Initializer10initializeEPKNS0_14InitParameter2E)() { + LOG_USE_MODULE(libSceJson2); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int32_t __NID_HEX(F9DAC3172012EAEE)() { + LOG_USE_MODULE(libSceJson2); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +} diff --git a/modules/libSceJson2/types.h b/modules/libSceJson2/types.h new file mode 100644 index 0000000..7832fd4 --- /dev/null +++ b/modules/libSceJson2/types.h @@ -0,0 +1,2 @@ +#pragma once +#include "codes.h" diff --git a/modules/libSceNpWebApi2/CMakeLists.txt b/modules/libSceNpWebApi2/CMakeLists.txt new file mode 100644 index 0000000..ba0bd60 --- /dev/null +++ b/modules/libSceNpWebApi2/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.24) +include(../setupModule.cmake) + +set(libName libSceNpWebApi2) +project(${libName}) + +add_library(${libName} SHARED entry.cpp) + +setupModule(${libName}) diff --git a/modules/libSceNpWebApi2/codes.h b/modules/libSceNpWebApi2/codes.h new file mode 100644 index 0000000..e9f8a9f --- /dev/null +++ b/modules/libSceNpWebApi2/codes.h @@ -0,0 +1,4 @@ +#pragma once +#include + +namespace Err {} // namespace Err diff --git a/modules/libSceNpWebApi2/entry.cpp b/modules/libSceNpWebApi2/entry.cpp new file mode 100644 index 0000000..5372e8d --- /dev/null +++ b/modules/libSceNpWebApi2/entry.cpp @@ -0,0 +1,15 @@ +#include "codes.h" +#include "common.h" +#include "logging.h" +#include "types.h" + +LOG_DEFINE_MODULE(libSceNpWebApi2); + +extern "C" { + +EXPORT const char* MODULE_NAME = "libSceNpWebApi2"; + +EXPORT SYSV_ABI int32_t sceNpWebApi2Initialize() { + return Ok; +} +} diff --git a/modules/libSceNpWebApi2/types.h b/modules/libSceNpWebApi2/types.h new file mode 100644 index 0000000..7832fd4 --- /dev/null +++ b/modules/libSceNpWebApi2/types.h @@ -0,0 +1,2 @@ +#pragma once +#include "codes.h" diff --git a/modules/libkernel/entry.cpp b/modules/libkernel/entry.cpp index fe81bfd..179b010 100644 --- a/modules/libkernel/entry.cpp +++ b/modules/libkernel/entry.cpp @@ -68,16 +68,6 @@ EXPORT SYSV_ABI void __NID(_exit)(int code) { ::exit(code); } -EXPORT SYSV_ABI size_t __NID(_writev)(int fd, const struct iovec* iov, int iovcn) { - size_t total = 0; - - for (int i = 0; i < iovcn; i++) { - total += ::fwrite(iov[i].iov_base, 1, iov[i].iov_len, stdout); - } - - return total; -} - EXPORT SYSV_ABI int __NID(_is_signal_return)(uint64_t* param) { if ((uintptr_t)param < 4 * 1024) return 1; if (param[0] != 0x48006a40247c8d48 || param[1] != 0x050f000001a1c0c7 || (param[2] & 0xffffff) != 0xfdebf4) @@ -115,6 +105,25 @@ EXPORT SYSV_ABI int sceKernelInternalMemoryGetModuleSegmentInfo(ModulInfo* info) return Ok; } +EXPORT SYSV_ABI int sceKernelConvertUtcToLocaltime(time_t time, time_t* local_time, struct timesec* st, unsigned long* dstsec) { + const auto* tz = std::chrono::current_zone(); + auto sys_inf = tz->get_info(std::chrono::system_clock::now()); + + *local_time = sys_inf.offset.count() + sys_inf.save.count() * 60 + time; + + if (st != nullptr) { + st->t = time; + st->westsec = sys_inf.offset.count() * 60; + st->dstsec = sys_inf.save.count() * 60; + } + + if (dstsec != nullptr) { + *dstsec = sys_inf.save.count() * 60; + } + + return 0; +} + EXPORT SYSV_ABI unsigned int sceKernelSleep(unsigned int seconds) { boost::this_thread::sleep_for(boost::chrono::seconds(seconds)); return Ok; diff --git a/modules/libkernel/fs.cpp b/modules/libkernel/fs.cpp index 67137fa..7f422bd 100644 --- a/modules/libkernel/fs.cpp +++ b/modules/libkernel/fs.cpp @@ -74,6 +74,10 @@ EXPORT SYSV_ABI size_t __NID(_readv)(int handle, const filesystem::SceKernelIove return POSIX_CALL(filesystem::readv(handle, iov, iovcnt)); } +EXPORT SYSV_ABI size_t __NID(_writev)(int handle, const filesystem::SceKernelIovec* iov, int iovcnt) { + return POSIX_CALL(filesystem::writev(handle, iov, iovcnt)); +} + EXPORT SYSV_ABI size_t sceKernelWritev(int handle, const filesystem::SceKernelIovec* iov, int iovcnt) { return filesystem::writev(handle, iov, iovcnt); } @@ -177,4 +181,4 @@ EXPORT SYSV_ABI int64_t sceKernelLwfsLseek(int fd, int64_t offset, int whence) { EXPORT SYSV_ABI size_t sceKernelLwfsWrite(int fd, const void* buf, size_t nbytes) { return filesystem::lwfsWrite(fd, buf, nbytes); } -} \ No newline at end of file +} diff --git a/modules/libkernel/types.h b/modules/libkernel/types.h index c66184f..5b819ea 100644 --- a/modules/libkernel/types.h +++ b/modules/libkernel/types.h @@ -6,7 +6,7 @@ using SceKernelModule = int32_t; using get_thread_atexit_count_func_t = SYSV_ABI int (*)(SceKernelModule); -using thread_atexit_report_func_t = SYSV_ABI void (*)(SceKernelModule); +using thread_atexit_report_func_t = SYSV_ABI void (*)(SceKernelModule); typedef int SceKernelAioSubmitId; typedef void* sigset_t; @@ -92,7 +92,8 @@ struct rusage_t { uint32_t ru_nivcsw = 0; }; -struct iovec { - void* iov_base; - size_t iov_len; +struct timesec { + time_t t; + unsigned long westsec; + unsigned long dstsec; };