2024-02-23 21:32:32 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2023-11-11 10:13:43 +00:00
|
|
|
|
2024-05-12 16:36:40 +00:00
|
|
|
#include <chrono>
|
2024-04-29 12:16:42 +00:00
|
|
|
#include <thread>
|
2024-07-10 18:02:56 +00:00
|
|
|
|
|
|
|
#include <boost/asio/io_context.hpp>
|
|
|
|
|
2024-02-27 22:10:34 +00:00
|
|
|
#include "common/assert.h"
|
2024-07-30 21:32:40 +00:00
|
|
|
#include "common/debug.h"
|
2024-02-27 22:10:34 +00:00
|
|
|
#include "common/logging/log.h"
|
2024-07-09 09:18:34 +00:00
|
|
|
#include "common/polyfill_thread.h"
|
2024-04-13 21:35:48 +00:00
|
|
|
#include "common/singleton.h"
|
2024-07-10 18:02:56 +00:00
|
|
|
#include "common/thread.h"
|
|
|
|
#include "core/file_format/psf.h"
|
2024-06-05 19:08:18 +00:00
|
|
|
#include "core/file_sys/fs.h"
|
2024-04-13 21:35:48 +00:00
|
|
|
#include "core/libraries/error_codes.h"
|
|
|
|
#include "core/libraries/kernel/cpu_management.h"
|
2024-05-28 11:29:53 +00:00
|
|
|
#include "core/libraries/kernel/event_flag/event_flag.h"
|
2024-04-13 21:35:48 +00:00
|
|
|
#include "core/libraries/kernel/event_queues.h"
|
|
|
|
#include "core/libraries/kernel/file_system.h"
|
|
|
|
#include "core/libraries/kernel/libkernel.h"
|
|
|
|
#include "core/libraries/kernel/memory_management.h"
|
|
|
|
#include "core/libraries/kernel/thread_management.h"
|
|
|
|
#include "core/libraries/kernel/time_management.h"
|
|
|
|
#include "core/libraries/libs.h"
|
|
|
|
#include "core/linker.h"
|
2024-05-16 12:55:50 +00:00
|
|
|
#include "core/memory.h"
|
2024-07-10 18:02:56 +00:00
|
|
|
|
2023-11-05 23:11:54 +00:00
|
|
|
#ifdef _WIN64
|
2023-11-19 10:55:07 +00:00
|
|
|
#include <io.h>
|
2024-06-15 14:51:51 +00:00
|
|
|
#include <objbase.h>
|
2024-02-23 20:57:57 +00:00
|
|
|
#include <windows.h>
|
2024-02-14 22:52:57 +00:00
|
|
|
#else
|
|
|
|
#include <sys/mman.h>
|
2024-07-17 08:56:07 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <date/tz.h>
|
|
|
|
#endif
|
2023-11-05 23:11:54 +00:00
|
|
|
#endif
|
2023-07-13 09:56:36 +00:00
|
|
|
|
2024-04-13 21:35:48 +00:00
|
|
|
namespace Libraries::Kernel {
|
2023-07-13 09:56:36 +00:00
|
|
|
|
2024-02-23 20:57:57 +00:00
|
|
|
static u64 g_stack_chk_guard = 0xDEADBEEF54321ABC; // dummy return
|
2023-07-13 09:56:36 +00:00
|
|
|
|
2024-07-10 18:02:56 +00:00
|
|
|
boost::asio::io_context io_context;
|
|
|
|
std::mutex m_asio_req;
|
|
|
|
std::condition_variable_any cv_asio_req;
|
|
|
|
std::atomic<u32> asio_requests;
|
|
|
|
std::jthread service_thread;
|
|
|
|
|
|
|
|
void KernelSignalRequest() {
|
|
|
|
std::unique_lock lock{m_asio_req};
|
|
|
|
++asio_requests;
|
|
|
|
cv_asio_req.notify_one();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void KernelServiceThread(std::stop_token stoken) {
|
|
|
|
Common::SetCurrentThreadName("Kernel_ServiceThread");
|
|
|
|
|
|
|
|
while (!stoken.stop_requested()) {
|
|
|
|
HLE_TRACE;
|
|
|
|
{
|
|
|
|
std::unique_lock lock{m_asio_req};
|
2024-07-09 09:18:34 +00:00
|
|
|
Common::CondvarWait(cv_asio_req, lock, stoken, [] { return asio_requests != 0; });
|
2024-07-10 18:02:56 +00:00
|
|
|
}
|
|
|
|
if (stoken.stop_requested()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
io_context.run();
|
|
|
|
io_context.reset();
|
|
|
|
|
|
|
|
asio_requests = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-26 16:48:26 +00:00
|
|
|
static void* PS4_SYSV_ABI sceKernelGetProcParam() {
|
|
|
|
auto* linker = Common::Singleton<Core::Linker>::Instance();
|
|
|
|
return reinterpret_cast<void*>(linker->GetProcParam());
|
|
|
|
}
|
|
|
|
|
2024-02-23 20:57:57 +00:00
|
|
|
static PS4_SYSV_ABI void stack_chk_fail() {
|
2024-02-27 22:10:34 +00:00
|
|
|
UNREACHABLE();
|
2024-02-23 20:57:57 +00:00
|
|
|
}
|
2023-11-05 23:11:54 +00:00
|
|
|
|
2024-02-23 20:57:57 +00:00
|
|
|
int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) {
|
2024-05-16 12:55:50 +00:00
|
|
|
LOG_INFO(Kernel_Vmm, "addr = {}, len = {:#x}", fmt::ptr(addr), len);
|
2024-07-30 21:32:40 +00:00
|
|
|
if (len == 0) {
|
|
|
|
return ORBIS_OK;
|
|
|
|
}
|
2024-05-16 12:55:50 +00:00
|
|
|
auto* memory = Core::Memory::Instance();
|
|
|
|
memory->UnmapMemory(std::bit_cast<VAddr>(addr), len);
|
2024-05-05 09:59:26 +00:00
|
|
|
return SCE_OK;
|
2024-02-23 20:57:57 +00:00
|
|
|
}
|
2023-11-11 10:13:43 +00:00
|
|
|
|
2023-11-19 10:55:07 +00:00
|
|
|
struct iovec {
|
|
|
|
void* iov_base; /* Base address. */
|
|
|
|
size_t iov_len; /* Length. */
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t PS4_SYSV_ABI _writev(int fd, const struct iovec* iov, int iovcn) {
|
2024-02-23 20:57:57 +00:00
|
|
|
// weird it gives fd ==0 and writes to stdout , i am not sure if it that is valid (found in
|
|
|
|
// openorbis)
|
2023-11-19 10:55:07 +00:00
|
|
|
size_t total_written = 0;
|
|
|
|
for (int i = 0; i < iovcn; i++) {
|
|
|
|
total_written += ::fwrite(iov[i].iov_base, 1, iov[i].iov_len, stdout);
|
|
|
|
}
|
|
|
|
return total_written;
|
|
|
|
}
|
|
|
|
|
2024-06-30 07:40:06 +00:00
|
|
|
static thread_local int g_posix_errno = 0;
|
2024-02-23 20:57:57 +00:00
|
|
|
int* PS4_SYSV_ABI __Error() {
|
2024-06-30 07:40:06 +00:00
|
|
|
return &g_posix_errno;
|
|
|
|
}
|
|
|
|
|
2024-06-30 21:50:07 +00:00
|
|
|
void ErrSceToPosix(int result) {
|
2024-07-11 11:37:21 +00:00
|
|
|
const int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
|
|
|
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
|
|
|
: POSIX_EOTHER;
|
2024-06-30 07:40:06 +00:00
|
|
|
g_posix_errno = rt;
|
2024-02-23 20:57:57 +00:00
|
|
|
}
|
2023-10-30 18:22:25 +00:00
|
|
|
|
2024-07-11 11:37:21 +00:00
|
|
|
int ErrnoToSceKernelError(int e) {
|
|
|
|
const auto res = SCE_KERNEL_ERROR_UNKNOWN + e;
|
|
|
|
return res > SCE_KERNEL_ERROR_ESTOP ? SCE_KERNEL_ERROR_UNKNOWN : res;
|
|
|
|
}
|
|
|
|
|
2024-08-16 22:20:21 +00:00
|
|
|
void SetPosixErrno(int e) {
|
2024-08-16 22:22:06 +00:00
|
|
|
// Some error numbers are different between supported OSes or the PS4
|
2024-08-16 22:20:21 +00:00
|
|
|
switch (e) {
|
|
|
|
case EPERM:
|
|
|
|
g_posix_errno = POSIX_EPERM;
|
|
|
|
break;
|
|
|
|
case EAGAIN:
|
|
|
|
g_posix_errno = POSIX_EAGAIN;
|
|
|
|
break;
|
|
|
|
case ENOMEM:
|
|
|
|
g_posix_errno = POSIX_ENOMEM;
|
|
|
|
break;
|
|
|
|
case EINVAL:
|
|
|
|
g_posix_errno = POSIX_EINVAL;
|
|
|
|
break;
|
|
|
|
case ENOSPC:
|
|
|
|
g_posix_errno = POSIX_ENOSPC;
|
|
|
|
break;
|
|
|
|
case ERANGE:
|
|
|
|
g_posix_errno = POSIX_ERANGE;
|
|
|
|
break;
|
2024-08-16 22:22:06 +00:00
|
|
|
case EDEADLK:
|
2024-08-16 22:20:21 +00:00
|
|
|
g_posix_errno = POSIX_EDEADLK;
|
|
|
|
break;
|
|
|
|
case ETIMEDOUT:
|
|
|
|
g_posix_errno = POSIX_ETIMEDOUT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_posix_errno = e;
|
|
|
|
}
|
|
|
|
}
|
2024-06-15 11:36:07 +00:00
|
|
|
int PS4_SYSV_ABI sceKernelMmap(void* addr, u64 len, int prot, int flags, int fd, size_t offset,
|
2024-02-23 20:57:57 +00:00
|
|
|
void** res) {
|
2024-06-15 11:36:07 +00:00
|
|
|
LOG_INFO(Kernel_Vmm, "called addr = {}, len = {}, prot = {}, flags = {}, fd = {}, offset = {}",
|
|
|
|
fmt::ptr(addr), len, prot, flags, fd, offset);
|
|
|
|
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
|
|
|
|
auto* memory = Core::Memory::Instance();
|
|
|
|
const auto mem_prot = static_cast<Core::MemoryProt>(prot);
|
|
|
|
const auto mem_flags = static_cast<Core::MemoryMapFlags>(flags);
|
|
|
|
if (fd == -1) {
|
|
|
|
return memory->MapMemory(res, std::bit_cast<VAddr>(addr), len, mem_prot, mem_flags,
|
|
|
|
Core::VMAType::Flexible);
|
|
|
|
} else {
|
|
|
|
const uintptr_t handle = h->GetFile(fd)->f.GetFileMapping();
|
|
|
|
return memory->MapFile(res, std::bit_cast<VAddr>(addr), len, mem_prot, mem_flags, handle,
|
|
|
|
offset);
|
2024-02-14 22:52:57 +00:00
|
|
|
}
|
2023-11-19 10:55:07 +00:00
|
|
|
}
|
|
|
|
|
2024-06-15 11:36:07 +00:00
|
|
|
void* PS4_SYSV_ABI posix_mmap(void* addr, u64 len, int prot, int flags, int fd, u64 offset) {
|
2023-11-19 10:55:07 +00:00
|
|
|
void* ptr;
|
2024-06-26 11:57:18 +00:00
|
|
|
LOG_INFO(Kernel_Vmm, "posix mmap redirect to sceKernelMmap");
|
2024-02-23 20:57:57 +00:00
|
|
|
// posix call the difference is that there is a different behaviour when it doesn't return 0 or
|
|
|
|
// SCE_OK
|
2024-06-15 11:36:07 +00:00
|
|
|
const VAddr ret_addr = (VAddr)__builtin_return_address(0);
|
2023-11-19 10:55:07 +00:00
|
|
|
int result = sceKernelMmap(addr, len, prot, flags, fd, offset, &ptr);
|
2024-02-27 22:10:34 +00:00
|
|
|
ASSERT(result == 0);
|
2023-11-19 10:55:07 +00:00
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2024-03-26 17:19:52 +00:00
|
|
|
static uint64_t g_mspace_atomic_id_mask = 0;
|
|
|
|
static uint64_t g_mstate_table[64] = {0};
|
|
|
|
|
|
|
|
struct HeapInfoInfo {
|
|
|
|
uint64_t size = sizeof(HeapInfoInfo);
|
|
|
|
uint32_t flag;
|
|
|
|
uint32_t getSegmentInfo;
|
|
|
|
uint64_t* mspace_atomic_id_mask;
|
|
|
|
uint64_t* mstate_table;
|
|
|
|
};
|
|
|
|
|
|
|
|
void PS4_SYSV_ABI sceLibcHeapGetTraceInfo(HeapInfoInfo* info) {
|
|
|
|
info->mspace_atomic_id_mask = &g_mspace_atomic_id_mask;
|
|
|
|
info->mstate_table = g_mstate_table;
|
|
|
|
info->getSegmentInfo = 0;
|
|
|
|
}
|
|
|
|
|
2024-04-13 21:35:48 +00:00
|
|
|
s64 PS4_SYSV_ABI ps4__write(int d, const void* buf, std::size_t nbytes) {
|
|
|
|
if (d <= 2) { // stdin,stdout,stderr
|
|
|
|
char* str = strdup((const char*)buf);
|
|
|
|
if (str[nbytes - 1] == '\n')
|
|
|
|
str[nbytes - 1] = 0;
|
|
|
|
LOG_INFO(Tty, "{}", str);
|
|
|
|
free(str);
|
|
|
|
return nbytes;
|
|
|
|
}
|
|
|
|
LOG_ERROR(Kernel, "(STUBBED) called d = {} nbytes = {} ", d, nbytes);
|
|
|
|
UNREACHABLE(); // normal write , is it a posix call??
|
|
|
|
return ORBIS_OK;
|
|
|
|
}
|
|
|
|
|
2024-05-12 16:03:51 +00:00
|
|
|
int PS4_SYSV_ABI sceKernelConvertUtcToLocaltime(time_t time, time_t* local_time,
|
|
|
|
struct OrbisTimesec* st, unsigned long* dst_sec) {
|
|
|
|
LOG_TRACE(Kernel, "Called");
|
2024-07-17 08:56:07 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
// std::chrono::current_zone() not available yet.
|
2024-07-09 09:18:34 +00:00
|
|
|
const auto* time_zone = date::current_zone();
|
2024-07-17 08:56:07 +00:00
|
|
|
#else
|
|
|
|
const auto* time_zone = std::chrono::current_zone();
|
|
|
|
#endif
|
2024-05-12 16:03:51 +00:00
|
|
|
auto info = time_zone->get_info(std::chrono::system_clock::now());
|
|
|
|
|
|
|
|
*local_time = info.offset.count() + info.save.count() * 60 + time;
|
|
|
|
|
|
|
|
if (st != nullptr) {
|
|
|
|
st->t = time;
|
|
|
|
st->west_sec = info.offset.count() * 60;
|
|
|
|
st->dst_sec = info.save.count() * 60;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dst_sec != nullptr) {
|
|
|
|
*dst_sec = info.save.count() * 60;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ORBIS_OK;
|
|
|
|
}
|
|
|
|
|
2024-05-17 05:01:02 +00:00
|
|
|
int PS4_SYSV_ABI sceKernelGetCompiledSdkVersion(int* ver) {
|
2024-05-16 20:24:51 +00:00
|
|
|
auto* param_sfo = Common::Singleton<PSF>::Instance();
|
|
|
|
int version = param_sfo->GetInteger("SYSTEM_VER");
|
|
|
|
LOG_INFO(Kernel, "returned system version = {:#x}", version);
|
2024-05-17 05:01:02 +00:00
|
|
|
*ver = version;
|
2024-06-30 16:22:39 +00:00
|
|
|
return (version > 0) ? ORBIS_OK : ORBIS_KERNEL_ERROR_EINVAL;
|
2024-05-16 20:24:51 +00:00
|
|
|
}
|
2024-05-17 19:53:02 +00:00
|
|
|
|
|
|
|
s64 PS4_SYSV_ABI ps4__read(int d, void* buf, u64 nbytes) {
|
|
|
|
ASSERT_MSG(d == 0, "d is not 0!");
|
|
|
|
|
|
|
|
return static_cast<s64>(
|
|
|
|
strlen(std::fgets(static_cast<char*>(buf), static_cast<int>(nbytes), stdin)));
|
|
|
|
}
|
|
|
|
|
2024-06-05 19:08:18 +00:00
|
|
|
s32 PS4_SYSV_ABI sceKernelLoadStartModule(const char* moduleFileName, size_t args, const void* argp,
|
|
|
|
u32 flags, const void* pOpt, int* pRes) {
|
|
|
|
LOG_INFO(Lib_Kernel, "called filename = {}, args = {}", moduleFileName, args);
|
|
|
|
|
|
|
|
if (flags != 0) {
|
|
|
|
return ORBIS_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
|
2024-07-15 00:37:30 +00:00
|
|
|
const auto path = mnt->GetHostPath(moduleFileName);
|
2024-06-05 19:08:18 +00:00
|
|
|
|
2024-06-15 11:36:07 +00:00
|
|
|
// Load PRX module and relocate any modules that import it.
|
2024-06-05 19:08:18 +00:00
|
|
|
auto* linker = Common::Singleton<Core::Linker>::Instance();
|
2024-06-21 16:02:49 +00:00
|
|
|
u32 handle = linker->LoadModule(path, true);
|
2024-06-15 11:36:07 +00:00
|
|
|
if (handle == -1) {
|
|
|
|
return ORBIS_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
2024-06-05 19:08:18 +00:00
|
|
|
auto* module = linker->GetModule(handle);
|
2024-06-15 11:36:07 +00:00
|
|
|
linker->RelocateAnyImports(module);
|
|
|
|
|
|
|
|
// If the new module has a TLS image, trigger its load when TlsGetAddr is called.
|
|
|
|
if (module->tls.image_size != 0) {
|
|
|
|
linker->AdvanceGenerationCounter();
|
|
|
|
}
|
2024-06-05 19:08:18 +00:00
|
|
|
|
|
|
|
// Retrieve and verify proc param according to libkernel.
|
|
|
|
u64* param = module->GetProcParam<u64*>();
|
|
|
|
ASSERT_MSG(!param || param[0] >= 0x18, "Invalid module param size: {}", param[0]);
|
|
|
|
module->Start(args, argp, param);
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 PS4_SYSV_ABI sceKernelDlsym(s32 handle, const char* symbol, void** addrp) {
|
|
|
|
auto* linker = Common::Singleton<Core::Linker>::Instance();
|
|
|
|
auto* module = linker->GetModule(handle);
|
|
|
|
*addrp = module->FindByName(symbol);
|
|
|
|
if (*addrp == nullptr) {
|
|
|
|
return ORBIS_KERNEL_ERROR_ESRCH;
|
|
|
|
}
|
|
|
|
return ORBIS_OK;
|
|
|
|
}
|
|
|
|
|
2024-06-15 11:36:07 +00:00
|
|
|
static constexpr size_t ORBIS_DBG_MAX_NAME_LENGTH = 256;
|
|
|
|
|
|
|
|
struct OrbisModuleInfoForUnwind {
|
|
|
|
u64 st_size;
|
|
|
|
std::array<char, ORBIS_DBG_MAX_NAME_LENGTH> name;
|
|
|
|
VAddr eh_frame_hdr_addr;
|
|
|
|
VAddr eh_frame_addr;
|
|
|
|
u64 eh_frame_size;
|
|
|
|
VAddr seg0_addr;
|
|
|
|
u64 seg0_size;
|
|
|
|
};
|
|
|
|
|
|
|
|
s32 PS4_SYSV_ABI sceKernelGetModuleInfoForUnwind(VAddr addr, int flags,
|
|
|
|
OrbisModuleInfoForUnwind* info) {
|
|
|
|
if (flags >= 3) {
|
|
|
|
std::memset(info, 0, sizeof(OrbisModuleInfoForUnwind));
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
if (!info) {
|
|
|
|
return ORBIS_KERNEL_ERROR_EFAULT;
|
|
|
|
}
|
|
|
|
if (info->st_size <= sizeof(OrbisModuleInfoForUnwind)) {
|
|
|
|
return ORBIS_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find module that contains specified address.
|
|
|
|
LOG_INFO(Lib_Kernel, "called addr = {:#x}, flags = {:#x}", addr, flags);
|
|
|
|
auto* linker = Common::Singleton<Core::Linker>::Instance();
|
|
|
|
auto* module = linker->FindByAddress(addr);
|
|
|
|
const auto mod_info = module->GetModuleInfoEx();
|
|
|
|
|
|
|
|
// Fill in module info.
|
|
|
|
info->name = mod_info.name;
|
|
|
|
info->eh_frame_hdr_addr = mod_info.eh_frame_hdr_addr;
|
|
|
|
info->eh_frame_addr = mod_info.eh_frame_addr;
|
|
|
|
info->eh_frame_size = mod_info.eh_frame_size;
|
|
|
|
info->seg0_addr = mod_info.segments[0].address;
|
|
|
|
info->seg0_size = mod_info.segments[0].size;
|
|
|
|
return ORBIS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI sceKernelGetModuleInfoFromAddr(VAddr addr, int flags,
|
|
|
|
Core::OrbisKernelModuleInfoEx* info) {
|
|
|
|
LOG_INFO(Lib_Kernel, "called addr = {:#x}, flags = {:#x}", addr, flags);
|
|
|
|
auto* linker = Common::Singleton<Core::Linker>::Instance();
|
|
|
|
auto* module = linker->FindByAddress(addr);
|
|
|
|
*info = module->GetModuleInfoEx();
|
|
|
|
return ORBIS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI sceKernelDebugRaiseException() {
|
|
|
|
UNREACHABLE();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI sceKernelGetCpumode() {
|
2024-06-15 22:50:07 +00:00
|
|
|
return 0;
|
2024-06-15 11:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PS4_SYSV_ABI sched_yield() {
|
|
|
|
return std::this_thread::yield();
|
|
|
|
}
|
|
|
|
|
2024-06-15 14:51:51 +00:00
|
|
|
int PS4_SYSV_ABI sceKernelUuidCreate(OrbisKernelUuid* orbisUuid) {
|
|
|
|
#ifdef _WIN64
|
|
|
|
UUID uuid;
|
|
|
|
UuidCreate(&uuid);
|
|
|
|
orbisUuid->timeLow = uuid.Data1;
|
|
|
|
orbisUuid->timeMid = uuid.Data2;
|
|
|
|
orbisUuid->timeHiAndVersion = uuid.Data3;
|
|
|
|
orbisUuid->clockSeqHiAndReserved = uuid.Data4[0];
|
|
|
|
orbisUuid->clockSeqLow = uuid.Data4[1];
|
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
orbisUuid->node[i] = uuid.Data4[2 + i];
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
LOG_ERROR(Kernel, "sceKernelUuidCreate: Add linux");
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-07-09 10:12:15 +00:00
|
|
|
const char* PS4_SYSV_ABI sceKernelGetFsSandboxRandomWord() {
|
|
|
|
const char* path = "sys";
|
2024-06-26 11:57:18 +00:00
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_connect() {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-06-27 13:37:17 +00:00
|
|
|
int PS4_SYSV_ABI _sigprocmask() {
|
|
|
|
return ORBIS_OK;
|
|
|
|
}
|
|
|
|
|
2024-07-14 06:34:48 +00:00
|
|
|
int PS4_SYSV_ABI posix_getpagesize() {
|
|
|
|
return 4096;
|
|
|
|
}
|
|
|
|
|
2024-04-13 21:35:48 +00:00
|
|
|
void LibKernel_Register(Core::Loader::SymbolsResolver* sym) {
|
2024-07-10 18:02:56 +00:00
|
|
|
service_thread = std::jthread{KernelServiceThread};
|
|
|
|
|
2023-10-06 18:49:53 +00:00
|
|
|
// obj
|
2023-11-05 23:11:54 +00:00
|
|
|
LIB_OBJ("f7uOxY9mM1U", "libkernel", 1, "libkernel", 1, 1, &g_stack_chk_guard);
|
2024-06-26 11:57:18 +00:00
|
|
|
// misc
|
|
|
|
LIB_FUNCTION("JGfTMBOdUJo", "libkernel", 1, "libkernel", 1, 1, sceKernelGetFsSandboxRandomWord);
|
|
|
|
LIB_FUNCTION("XVL8So3QJUk", "libkernel", 1, "libkernel", 1, 1, posix_connect);
|
2024-06-27 13:37:17 +00:00
|
|
|
LIB_FUNCTION("6xVpy0Fdq+I", "libkernel", 1, "libkernel", 1, 1, _sigprocmask);
|
2023-10-06 18:49:53 +00:00
|
|
|
// memory
|
2024-06-15 11:36:07 +00:00
|
|
|
LIB_FUNCTION("OMDRKKAZ8I4", "libkernel", 1, "libkernel", 1, 1, sceKernelDebugRaiseException);
|
2024-04-13 21:35:48 +00:00
|
|
|
LIB_FUNCTION("rTXw65xmLIA", "libkernel", 1, "libkernel", 1, 1, sceKernelAllocateDirectMemory);
|
2024-06-05 19:08:18 +00:00
|
|
|
LIB_FUNCTION("B+vc2AO2Zrc", "libkernel", 1, "libkernel", 1, 1,
|
|
|
|
sceKernelAllocateMainDirectMemory);
|
2024-06-10 19:59:12 +00:00
|
|
|
LIB_FUNCTION("C0f7TJcbfac", "libkernel", 1, "libkernel", 1, 1,
|
|
|
|
sceKernelAvailableDirectMemorySize);
|
2024-06-21 15:22:37 +00:00
|
|
|
LIB_FUNCTION("hwVSPCmp5tM", "libkernel", 1, "libkernel", 1, 1,
|
|
|
|
sceKernelCheckedReleaseDirectMemory);
|
2024-06-10 19:59:12 +00:00
|
|
|
LIB_FUNCTION("rVjRvHJ0X6c", "libkernel", 1, "libkernel", 1, 1, sceKernelVirtualQuery);
|
2024-07-11 12:35:58 +00:00
|
|
|
LIB_FUNCTION("7oxv3PPCumo", "libkernel", 1, "libkernel", 1, 1, sceKernelReserveVirtualRange);
|
2024-07-21 18:29:24 +00:00
|
|
|
LIB_FUNCTION("BC+OG5m9+bw", "libkernel", 1, "libkernel", 1, 1, sceKernelGetDirectMemoryType);
|
2024-04-13 21:35:48 +00:00
|
|
|
LIB_FUNCTION("pO96TwzOm5E", "libkernel", 1, "libkernel", 1, 1, sceKernelGetDirectMemorySize);
|
2024-06-08 06:23:55 +00:00
|
|
|
LIB_FUNCTION("NcaWUxfMNIQ", "libkernel", 1, "libkernel", 1, 1, sceKernelMapNamedDirectMemory);
|
2024-04-13 21:35:48 +00:00
|
|
|
LIB_FUNCTION("L-Q3LEjIbgA", "libkernel", 1, "libkernel", 1, 1, sceKernelMapDirectMemory);
|
2024-05-26 12:51:35 +00:00
|
|
|
LIB_FUNCTION("WFcfL2lzido", "libkernel", 1, "libkernel", 1, 1, sceKernelQueryMemoryProtection);
|
2024-05-30 15:07:36 +00:00
|
|
|
LIB_FUNCTION("BHouLQzh0X0", "libkernel", 1, "libkernel", 1, 1, sceKernelDirectMemoryQuery);
|
2023-10-06 18:49:53 +00:00
|
|
|
LIB_FUNCTION("MBuItvba6z8", "libkernel", 1, "libkernel", 1, 1, sceKernelReleaseDirectMemory);
|
|
|
|
LIB_FUNCTION("cQke9UuBQOk", "libkernel", 1, "libkernel", 1, 1, sceKernelMunmap);
|
2024-05-16 12:55:50 +00:00
|
|
|
LIB_FUNCTION("mL8NDH86iQI", "libkernel", 1, "libkernel", 1, 1, sceKernelMapNamedFlexibleMemory);
|
2024-06-22 15:17:40 +00:00
|
|
|
LIB_FUNCTION("aNz11fnnzi4", "libkernel", 1, "libkernel", 1, 1,
|
|
|
|
sceKernelAvailableFlexibleMemorySize);
|
2024-05-16 12:55:50 +00:00
|
|
|
LIB_FUNCTION("IWIBBdTHit4", "libkernel", 1, "libkernel", 1, 1, sceKernelMapFlexibleMemory);
|
2024-06-05 19:08:18 +00:00
|
|
|
LIB_FUNCTION("p5EcQeEeJAE", "libkernel", 1, "libkernel", 1, 1,
|
|
|
|
_sceKernelRtldSetApplicationHeapAPI);
|
|
|
|
LIB_FUNCTION("wzvqT4UqKX8", "libkernel", 1, "libkernel", 1, 1, sceKernelLoadStartModule);
|
|
|
|
LIB_FUNCTION("LwG8g3niqwA", "libkernel", 1, "libkernel", 1, 1, sceKernelDlsym);
|
2024-06-15 11:36:07 +00:00
|
|
|
LIB_FUNCTION("RpQJJVKTiFM", "libkernel", 1, "libkernel", 1, 1, sceKernelGetModuleInfoForUnwind);
|
|
|
|
LIB_FUNCTION("f7KBOafysXo", "libkernel", 1, "libkernel", 1, 1, sceKernelGetModuleInfoFromAddr);
|
|
|
|
LIB_FUNCTION("VOx8NGmHXTs", "libkernel", 1, "libkernel", 1, 1, sceKernelGetCpumode);
|
2024-06-15 23:01:20 +00:00
|
|
|
LIB_FUNCTION("Xjoosiw+XPI", "libkernel", 1, "libkernel", 1, 1, sceKernelUuidCreate);
|
2024-06-05 19:08:18 +00:00
|
|
|
|
2024-07-25 20:01:12 +00:00
|
|
|
LIB_FUNCTION("2SKEx6bSq-4", "libkernel", 1, "libkernel", 1, 1, sceKernelBatchMap);
|
|
|
|
LIB_FUNCTION("kBJzF8x4SyE", "libkernel", 1, "libkernel", 1, 1, sceKernelBatchMap2);
|
2024-07-29 16:08:06 +00:00
|
|
|
LIB_FUNCTION("DGMG3JshrZU", "libkernel", 1, "libkernel", 1, 1, sceKernelSetVirtualRangeName);
|
2024-07-25 20:01:12 +00:00
|
|
|
|
2023-10-06 18:49:53 +00:00
|
|
|
// equeue
|
2024-04-13 21:35:48 +00:00
|
|
|
LIB_FUNCTION("D0OdFMjp46I", "libkernel", 1, "libkernel", 1, 1, sceKernelCreateEqueue);
|
2024-05-10 20:04:41 +00:00
|
|
|
LIB_FUNCTION("jpFjmgAC5AE", "libkernel", 1, "libkernel", 1, 1, sceKernelDeleteEqueue);
|
2024-04-13 21:35:48 +00:00
|
|
|
LIB_FUNCTION("fzyMKs9kim0", "libkernel", 1, "libkernel", 1, 1, sceKernelWaitEqueue);
|
2024-05-17 21:32:15 +00:00
|
|
|
LIB_FUNCTION("vz+pg2zdopI", "libkernel", 1, "libkernel", 1, 1, sceKernelGetEventUserData);
|
|
|
|
LIB_FUNCTION("4R6-OvI2cEA", "libkernel", 1, "libkernel", 1, 1, sceKernelAddUserEvent);
|
2024-06-15 11:36:07 +00:00
|
|
|
LIB_FUNCTION("WDszmSbWuDk", "libkernel", 1, "libkernel", 1, 1, sceKernelAddUserEventEdge);
|
2024-07-09 10:12:15 +00:00
|
|
|
LIB_FUNCTION("R74tt43xP6k", "libkernel", 1, "libkernel", 1, 1, sceKernelAddHRTimerEvent);
|
2024-06-08 21:23:58 +00:00
|
|
|
LIB_FUNCTION("F6e0kwo4cnk", "libkernel", 1, "libkernel", 1, 1, sceKernelTriggerUserEvent);
|
|
|
|
LIB_FUNCTION("LJDwdSNTnDg", "libkernel", 1, "libkernel", 1, 1, sceKernelDeleteUserEvent);
|
2024-07-14 16:20:31 +00:00
|
|
|
LIB_FUNCTION("mJ7aghmgvfc", "libkernel", 1, "libkernel", 1, 1, sceKernelGetEventId);
|
2024-08-16 17:16:15 +00:00
|
|
|
LIB_FUNCTION("23CPPI1tyBY", "libkernel", 1, "libkernel", 1, 1, sceKernelGetEventFilter);
|
2024-06-08 21:23:58 +00:00
|
|
|
|
2023-10-06 18:49:53 +00:00
|
|
|
// misc
|
2024-04-13 21:35:48 +00:00
|
|
|
LIB_FUNCTION("WslcK1FQcGI", "libkernel", 1, "libkernel", 1, 1, sceKernelIsNeoMode);
|
2023-10-06 18:49:53 +00:00
|
|
|
LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail);
|
2023-11-11 10:13:43 +00:00
|
|
|
LIB_FUNCTION("9BcDykPmo1I", "libkernel", 1, "libkernel", 1, 1, __Error);
|
2023-11-19 10:55:07 +00:00
|
|
|
LIB_FUNCTION("BPE9s9vQQXo", "libkernel", 1, "libkernel", 1, 1, posix_mmap);
|
2024-06-15 11:36:07 +00:00
|
|
|
LIB_FUNCTION("BPE9s9vQQXo", "libScePosix", 1, "libkernel", 1, 1, posix_mmap);
|
2023-11-19 10:55:07 +00:00
|
|
|
LIB_FUNCTION("YSHRBRLn2pI", "libkernel", 1, "libkernel", 1, 1, _writev);
|
2024-03-26 16:48:26 +00:00
|
|
|
LIB_FUNCTION("959qrazPIrg", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcParam);
|
2024-05-12 16:03:51 +00:00
|
|
|
LIB_FUNCTION("-o5uEDpN+oY", "libkernel", 1, "libkernel", 1, 1, sceKernelConvertUtcToLocaltime);
|
2024-05-16 20:24:51 +00:00
|
|
|
LIB_FUNCTION("WB66evu8bsU", "libkernel", 1, "libkernel", 1, 1, sceKernelGetCompiledSdkVersion);
|
2024-05-17 19:53:02 +00:00
|
|
|
LIB_FUNCTION("DRuBt2pvICk", "libkernel", 1, "libkernel", 1, 1, ps4__read);
|
2024-07-14 06:34:48 +00:00
|
|
|
LIB_FUNCTION("k+AXqu2-eBc", "libScePosix", 1, "libkernel", 1, 1, posix_getpagesize);
|
2023-11-11 10:13:43 +00:00
|
|
|
|
2024-04-13 21:35:48 +00:00
|
|
|
Libraries::Kernel::fileSystemSymbolsRegister(sym);
|
|
|
|
Libraries::Kernel::timeSymbolsRegister(sym);
|
|
|
|
Libraries::Kernel::pthreadSymbolsRegister(sym);
|
2024-05-28 11:29:53 +00:00
|
|
|
Libraries::Kernel::RegisterKernelEventFlag(sym);
|
2024-03-26 17:19:52 +00:00
|
|
|
|
|
|
|
// temp
|
|
|
|
LIB_FUNCTION("NWtTN10cJzE", "libSceLibcInternalExt", 1, "libSceLibcInternal", 1, 1,
|
|
|
|
sceLibcHeapGetTraceInfo);
|
2024-04-13 21:35:48 +00:00
|
|
|
LIB_FUNCTION("FxVZqBAA7ks", "libkernel", 1, "libkernel", 1, 1, ps4__write);
|
2024-06-15 11:36:07 +00:00
|
|
|
LIB_FUNCTION("6XG4B33N09g", "libScePosix", 1, "libkernel", 1, 1, sched_yield);
|
2023-10-06 18:49:53 +00:00
|
|
|
}
|
2023-07-13 09:56:36 +00:00
|
|
|
|
2024-04-13 21:35:48 +00:00
|
|
|
} // namespace Libraries::Kernel
|