From 1ee6b7c9702cde75400d64605af917d1401cb6ed Mon Sep 17 00:00:00 2001 From: Ivan Chikish Date: Mon, 3 Jul 2023 14:10:16 +0300 Subject: [PATCH] Merge orbis-kernel submodule --- orbis-kernel | 1 - orbis-kernel/.gitignore | 2 + orbis-kernel/CMakeLists.txt | 81 + orbis-kernel/LICENSE | 21 + orbis-kernel/examples/CMakeLists.txt | 13 + .../examples/standalone/CMakeLists.txt | 9 + .../orbis-kernel-config/orbis-config.hpp | 68 + orbis-kernel/examples/standalone/src/main.cpp | 253 ++ orbis-kernel/include/orbis/KernelContext.hpp | 97 + orbis-kernel/include/orbis/error.hpp | 4 + .../include/orbis/error/ErrorCode.hpp | 111 + .../include/orbis/error/SysResult.hpp | 22 + orbis-kernel/include/orbis/module.hpp | 7 + orbis-kernel/include/orbis/module/Module.hpp | 141 + .../include/orbis/module/ModuleHandle.hpp | 7 + .../include/orbis/module/ModuleInfo.hpp | 15 + .../include/orbis/module/ModuleInfoEx.hpp | 30 + .../include/orbis/module/ModuleSegment.hpp | 11 + orbis-kernel/include/orbis/sys/syscall.hpp | 599 ++++ orbis-kernel/include/orbis/sys/sysentry.hpp | 15 + orbis-kernel/include/orbis/sys/sysproto.hpp | 593 ++++ orbis-kernel/include/orbis/thread.hpp | 10 + orbis-kernel/include/orbis/thread/Process.hpp | 38 + .../include/orbis/thread/ProcessOps.hpp | 56 + .../include/orbis/thread/ProcessState.hpp | 11 + .../include/orbis/thread/RegisterId.hpp | 23 + orbis-kernel/include/orbis/thread/Thread.hpp | 30 + .../include/orbis/thread/ThreadState.hpp | 7 + orbis-kernel/include/orbis/thread/cpuset.hpp | 12 + orbis-kernel/include/orbis/thread/sysent.hpp | 18 + orbis-kernel/include/orbis/thread/types.hpp | 9 + orbis-kernel/include/orbis/utils/AtomicOp.hpp | 74 + orbis-kernel/include/orbis/utils/BitSet.hpp | 104 + orbis-kernel/include/orbis/utils/IdMap.hpp | 306 ++ .../include/orbis/utils/LinkedNode.hpp | 48 + orbis-kernel/include/orbis/utils/Logs.hpp | 104 + orbis-kernel/include/orbis/utils/Rc.hpp | 124 + .../include/orbis/utils/SharedMutex.hpp | 144 + orbis-kernel/src/module.cpp | 255 ++ orbis-kernel/src/sys/sys_acct.cpp | 4 + orbis-kernel/src/sys/sys_audit.cpp | 11 + orbis-kernel/src/sys/sys_capability.cpp | 6 + orbis-kernel/src/sys/sys_context.cpp | 5 + orbis-kernel/src/sys/sys_cpuset.cpp | 7 + orbis-kernel/src/sys/sys_descrip.cpp | 18 + orbis-kernel/src/sys/sys_environment.cpp | 3 + orbis-kernel/src/sys/sys_event.cpp | 9 + orbis-kernel/src/sys/sys_exec.cpp | 5 + orbis-kernel/src/sys/sys_exit.cpp | 13 + orbis-kernel/src/sys/sys_fork.cpp | 6 + orbis-kernel/src/sys/sys_generic.cpp | 75 + orbis-kernel/src/sys/sys_jail.cpp | 7 + orbis-kernel/src/sys/sys_ktrace.cpp | 4 + orbis-kernel/src/sys/sys_linker.cpp | 10 + orbis-kernel/src/sys/sys_loginclass.cpp | 4 + orbis-kernel/src/sys/sys_mac.cpp | 12 + orbis-kernel/src/sys/sys_module.cpp | 6 + orbis-kernel/src/sys/sys_msg.cpp | 7 + orbis-kernel/src/sys/sys_ntptime.cpp | 5 + orbis-kernel/src/sys/sys_p1003_1b.cpp | 10 + orbis-kernel/src/sys/sys_pipe.cpp | 3 + orbis-kernel/src/sys/sys_procdesc.cpp | 3 + orbis-kernel/src/sys/sys_process.cpp | 3 + orbis-kernel/src/sys/sys_prot.cpp | 32 + orbis-kernel/src/sys/sys_pty_pts.cpp | 3 + orbis-kernel/src/sys/sys_rctl.cpp | 7 + orbis-kernel/src/sys/sys_resource.cpp | 12 + orbis-kernel/src/sys/sys_route.cpp | 3 + orbis-kernel/src/sys/sys_sce.cpp | 870 ++++++ orbis-kernel/src/sys/sys_sem.cpp | 6 + orbis-kernel/src/sys/sys_shm.cpp | 7 + orbis-kernel/src/sys/sys_shutdown.cpp | 3 + orbis-kernel/src/sys/sys_sig.cpp | 44 + orbis-kernel/src/sys/sys_subr_prof.cpp | 3 + orbis-kernel/src/sys/sys_swap_pager.cpp | 4 + orbis-kernel/src/sys/sys_synch.cpp | 3 + orbis-kernel/src/sys/sys_sysctl.cpp | 248 ++ orbis-kernel/src/sys/sys_thr.cpp | 69 + orbis-kernel/src/sys/sys_time.cpp | 15 + orbis-kernel/src/sys/sys_uipc.cpp | 22 + orbis-kernel/src/sys/sys_uipc_mqueue.cpp | 8 + orbis-kernel/src/sys/sys_uipc_sem.cpp | 12 + orbis-kernel/src/sys/sys_uipc_shm.cpp | 4 + orbis-kernel/src/sys/sys_umtx.cpp | 8 + orbis-kernel/src/sys/sys_uuid.cpp | 3 + orbis-kernel/src/sys/sys_vfs.cpp | 93 + orbis-kernel/src/sys/sys_vfs_acl.cpp | 14 + orbis-kernel/src/sys/sys_vfs_aio.cpp | 15 + orbis-kernel/src/sys/sys_vfs_cache.cpp | 3 + orbis-kernel/src/sys/sys_vfs_extattr.cpp | 15 + orbis-kernel/src/sys/sys_vfs_mount.cpp | 5 + orbis-kernel/src/sys/sys_vm_mmap.cpp | 101 + orbis-kernel/src/sys/sys_vm_unix.cpp | 4 + orbis-kernel/src/sysvec.cpp | 2462 +++++++++++++++++ orbis-kernel/src/utils/Logs.cpp | 172 ++ orbis-kernel/src/utils/SharedMutex.cpp | 151 + readme.md | 5 + 97 files changed, 8134 insertions(+), 1 deletion(-) delete mode 160000 orbis-kernel create mode 100644 orbis-kernel/.gitignore create mode 100644 orbis-kernel/CMakeLists.txt create mode 100644 orbis-kernel/LICENSE create mode 100644 orbis-kernel/examples/CMakeLists.txt create mode 100644 orbis-kernel/examples/standalone/CMakeLists.txt create mode 100644 orbis-kernel/examples/standalone/orbis-kernel-config/orbis-config.hpp create mode 100644 orbis-kernel/examples/standalone/src/main.cpp create mode 100644 orbis-kernel/include/orbis/KernelContext.hpp create mode 100644 orbis-kernel/include/orbis/error.hpp create mode 100644 orbis-kernel/include/orbis/error/ErrorCode.hpp create mode 100644 orbis-kernel/include/orbis/error/SysResult.hpp create mode 100644 orbis-kernel/include/orbis/module.hpp create mode 100644 orbis-kernel/include/orbis/module/Module.hpp create mode 100644 orbis-kernel/include/orbis/module/ModuleHandle.hpp create mode 100644 orbis-kernel/include/orbis/module/ModuleInfo.hpp create mode 100644 orbis-kernel/include/orbis/module/ModuleInfoEx.hpp create mode 100644 orbis-kernel/include/orbis/module/ModuleSegment.hpp create mode 100644 orbis-kernel/include/orbis/sys/syscall.hpp create mode 100644 orbis-kernel/include/orbis/sys/sysentry.hpp create mode 100644 orbis-kernel/include/orbis/sys/sysproto.hpp create mode 100644 orbis-kernel/include/orbis/thread.hpp create mode 100644 orbis-kernel/include/orbis/thread/Process.hpp create mode 100644 orbis-kernel/include/orbis/thread/ProcessOps.hpp create mode 100644 orbis-kernel/include/orbis/thread/ProcessState.hpp create mode 100644 orbis-kernel/include/orbis/thread/RegisterId.hpp create mode 100644 orbis-kernel/include/orbis/thread/Thread.hpp create mode 100644 orbis-kernel/include/orbis/thread/ThreadState.hpp create mode 100644 orbis-kernel/include/orbis/thread/cpuset.hpp create mode 100644 orbis-kernel/include/orbis/thread/sysent.hpp create mode 100644 orbis-kernel/include/orbis/thread/types.hpp create mode 100644 orbis-kernel/include/orbis/utils/AtomicOp.hpp create mode 100644 orbis-kernel/include/orbis/utils/BitSet.hpp create mode 100644 orbis-kernel/include/orbis/utils/IdMap.hpp create mode 100644 orbis-kernel/include/orbis/utils/LinkedNode.hpp create mode 100644 orbis-kernel/include/orbis/utils/Logs.hpp create mode 100644 orbis-kernel/include/orbis/utils/Rc.hpp create mode 100644 orbis-kernel/include/orbis/utils/SharedMutex.hpp create mode 100644 orbis-kernel/src/module.cpp create mode 100644 orbis-kernel/src/sys/sys_acct.cpp create mode 100644 orbis-kernel/src/sys/sys_audit.cpp create mode 100644 orbis-kernel/src/sys/sys_capability.cpp create mode 100644 orbis-kernel/src/sys/sys_context.cpp create mode 100644 orbis-kernel/src/sys/sys_cpuset.cpp create mode 100644 orbis-kernel/src/sys/sys_descrip.cpp create mode 100644 orbis-kernel/src/sys/sys_environment.cpp create mode 100644 orbis-kernel/src/sys/sys_event.cpp create mode 100644 orbis-kernel/src/sys/sys_exec.cpp create mode 100644 orbis-kernel/src/sys/sys_exit.cpp create mode 100644 orbis-kernel/src/sys/sys_fork.cpp create mode 100644 orbis-kernel/src/sys/sys_generic.cpp create mode 100644 orbis-kernel/src/sys/sys_jail.cpp create mode 100644 orbis-kernel/src/sys/sys_ktrace.cpp create mode 100644 orbis-kernel/src/sys/sys_linker.cpp create mode 100644 orbis-kernel/src/sys/sys_loginclass.cpp create mode 100644 orbis-kernel/src/sys/sys_mac.cpp create mode 100644 orbis-kernel/src/sys/sys_module.cpp create mode 100644 orbis-kernel/src/sys/sys_msg.cpp create mode 100644 orbis-kernel/src/sys/sys_ntptime.cpp create mode 100644 orbis-kernel/src/sys/sys_p1003_1b.cpp create mode 100644 orbis-kernel/src/sys/sys_pipe.cpp create mode 100644 orbis-kernel/src/sys/sys_procdesc.cpp create mode 100644 orbis-kernel/src/sys/sys_process.cpp create mode 100644 orbis-kernel/src/sys/sys_prot.cpp create mode 100644 orbis-kernel/src/sys/sys_pty_pts.cpp create mode 100644 orbis-kernel/src/sys/sys_rctl.cpp create mode 100644 orbis-kernel/src/sys/sys_resource.cpp create mode 100644 orbis-kernel/src/sys/sys_route.cpp create mode 100644 orbis-kernel/src/sys/sys_sce.cpp create mode 100644 orbis-kernel/src/sys/sys_sem.cpp create mode 100644 orbis-kernel/src/sys/sys_shm.cpp create mode 100644 orbis-kernel/src/sys/sys_shutdown.cpp create mode 100644 orbis-kernel/src/sys/sys_sig.cpp create mode 100644 orbis-kernel/src/sys/sys_subr_prof.cpp create mode 100644 orbis-kernel/src/sys/sys_swap_pager.cpp create mode 100644 orbis-kernel/src/sys/sys_synch.cpp create mode 100644 orbis-kernel/src/sys/sys_sysctl.cpp create mode 100644 orbis-kernel/src/sys/sys_thr.cpp create mode 100644 orbis-kernel/src/sys/sys_time.cpp create mode 100644 orbis-kernel/src/sys/sys_uipc.cpp create mode 100644 orbis-kernel/src/sys/sys_uipc_mqueue.cpp create mode 100644 orbis-kernel/src/sys/sys_uipc_sem.cpp create mode 100644 orbis-kernel/src/sys/sys_uipc_shm.cpp create mode 100644 orbis-kernel/src/sys/sys_umtx.cpp create mode 100644 orbis-kernel/src/sys/sys_uuid.cpp create mode 100644 orbis-kernel/src/sys/sys_vfs.cpp create mode 100644 orbis-kernel/src/sys/sys_vfs_acl.cpp create mode 100644 orbis-kernel/src/sys/sys_vfs_aio.cpp create mode 100644 orbis-kernel/src/sys/sys_vfs_cache.cpp create mode 100644 orbis-kernel/src/sys/sys_vfs_extattr.cpp create mode 100644 orbis-kernel/src/sys/sys_vfs_mount.cpp create mode 100644 orbis-kernel/src/sys/sys_vm_mmap.cpp create mode 100644 orbis-kernel/src/sys/sys_vm_unix.cpp create mode 100644 orbis-kernel/src/sysvec.cpp create mode 100644 orbis-kernel/src/utils/Logs.cpp create mode 100644 orbis-kernel/src/utils/SharedMutex.cpp diff --git a/orbis-kernel b/orbis-kernel deleted file mode 160000 index ab5a28904..000000000 --- a/orbis-kernel +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ab5a289045ff0296478543c3a0a7a224509cacb6 diff --git a/orbis-kernel/.gitignore b/orbis-kernel/.gitignore new file mode 100644 index 000000000..6654b8d8d --- /dev/null +++ b/orbis-kernel/.gitignore @@ -0,0 +1,2 @@ +build/ +compile_commands.json diff --git a/orbis-kernel/CMakeLists.txt b/orbis-kernel/CMakeLists.txt new file mode 100644 index 000000000..1c373699b --- /dev/null +++ b/orbis-kernel/CMakeLists.txt @@ -0,0 +1,81 @@ +set(CMAKE_POSITION_INDEPENDENT_CODE on) + +add_library(obj.orbis-kernel OBJECT + src/module.cpp + src/sysvec.cpp + src/sys/sys_acct.cpp + src/sys/sys_audit.cpp + src/sys/sys_capability.cpp + src/sys/sys_context.cpp + src/sys/sys_cpuset.cpp + src/sys/sys_descrip.cpp + src/sys/sys_environment.cpp + src/sys/sys_event.cpp + src/sys/sys_exec.cpp + src/sys/sys_exit.cpp + src/sys/sys_fork.cpp + src/sys/sys_generic.cpp + src/sys/sys_jail.cpp + src/sys/sys_ktrace.cpp + src/sys/sys_linker.cpp + src/sys/sys_loginclass.cpp + src/sys/sys_mac.cpp + src/sys/sys_module.cpp + src/sys/sys_msg.cpp + src/sys/sys_ntptime.cpp + src/sys/sys_p1003_1b.cpp + src/sys/sys_pipe.cpp + src/sys/sys_procdesc.cpp + src/sys/sys_process.cpp + src/sys/sys_prot.cpp + src/sys/sys_pty_pts.cpp + src/sys/sys_rctl.cpp + src/sys/sys_resource.cpp + src/sys/sys_route.cpp + src/sys/sys_sce.cpp + src/sys/sys_sem.cpp + src/sys/sys_shm.cpp + src/sys/sys_shutdown.cpp + src/sys/sys_sig.cpp + src/sys/sys_subr_prof.cpp + src/sys/sys_swap_pager.cpp + src/sys/sys_synch.cpp + src/sys/sys_sysctl.cpp + src/sys/sys_thr.cpp + src/sys/sys_time.cpp + src/sys/sys_uipc_mqueue.cpp + src/sys/sys_uipc_sem.cpp + src/sys/sys_uipc_shm.cpp + src/sys/sys_uipc.cpp + src/sys/sys_umtx.cpp + src/sys/sys_uuid.cpp + src/sys/sys_vfs_acl.cpp + src/sys/sys_vfs_aio.cpp + src/sys/sys_vfs_cache.cpp + src/sys/sys_vfs_extattr.cpp + src/sys/sys_vfs_mount.cpp + src/sys/sys_vfs.cpp + src/sys/sys_vm_mmap.cpp + src/sys/sys_vm_unix.cpp + + src/utils/Logs.cpp + src/utils/SharedMutex.cpp +) + +target_link_libraries(obj.orbis-kernel PUBLIC orbis::kernel::config) + +target_include_directories(obj.orbis-kernel +PUBLIC + include + +PRIVATE + include/orbis +) + +add_library(orbis-kernel STATIC) +add_library(orbis-kernel-shared SHARED) +add_library(orbis::kernel ALIAS orbis-kernel) +add_library(orbis::kernel-shared ALIAS orbis-kernel-shared) + +target_link_libraries(orbis-kernel PUBLIC obj.orbis-kernel) +target_link_libraries(orbis-kernel-shared PUBLIC obj.orbis-kernel) diff --git a/orbis-kernel/LICENSE b/orbis-kernel/LICENSE new file mode 100644 index 000000000..ad17b590f --- /dev/null +++ b/orbis-kernel/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 - present RPCS4 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/orbis-kernel/examples/CMakeLists.txt b/orbis-kernel/examples/CMakeLists.txt new file mode 100644 index 000000000..f7739190f --- /dev/null +++ b/orbis-kernel/examples/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.25) + +project(orbis-kernel-examples) + +if("${ORBIS_KERNEL_DIR}" STREQUAL "") + set(ORBIS_KERNEL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..) + cmake_path(ABSOLUTE_PATH ORBIS_KERNEL_DIR NORMALIZE) +endif() + +set(CMAKE_CXX_STANDARD 23) +add_subdirectory(standalone) +add_subdirectory(${ORBIS_KERNEL_DIR} orbis-kernel EXCLUDE_FROM_ALL ) + diff --git a/orbis-kernel/examples/standalone/CMakeLists.txt b/orbis-kernel/examples/standalone/CMakeLists.txt new file mode 100644 index 000000000..f6ec613d9 --- /dev/null +++ b/orbis-kernel/examples/standalone/CMakeLists.txt @@ -0,0 +1,9 @@ + +add_library(standalone-config INTERFACE) +target_include_directories(standalone-config INTERFACE orbis-kernel-config) +add_library(orbis::kernel::config ALIAS standalone-config) + +add_executable(standalone src/main.cpp) +target_include_directories(standalone PUBLIC include) + +target_link_libraries(standalone PUBLIC orbis::kernel) diff --git a/orbis-kernel/examples/standalone/orbis-kernel-config/orbis-config.hpp b/orbis-kernel/examples/standalone/orbis-kernel-config/orbis-config.hpp new file mode 100644 index 000000000..76fd40019 --- /dev/null +++ b/orbis-kernel/examples/standalone/orbis-kernel-config/orbis-config.hpp @@ -0,0 +1,68 @@ +#pragma once + +#include "orbis/error.hpp" +#include "orbis/thread/RegisterId.hpp" +#include +#include + +namespace orbis { +using int8_t = std::int8_t; +using int16_t = std::int16_t; +using int32_t = std::int32_t; +using int64_t = std::int64_t; + +using uint8_t = std::uint8_t; +using uint16_t = std::uint16_t; +using uint32_t = std::uint32_t; +using uint64_t = std::uint64_t; + +using size_t = uint64_t; +using ssize_t = int64_t; +using off_t = int64_t; + +using uint = uint32_t; +using sint = int32_t; + +using slong = int64_t; +using ulong = uint64_t; + +template using ptr = T *; +template using cptr = T * const; + +using caddr_t = ptr; + +inline ErrorCode uread(void *kernelAddress, ptr userAddress, + size_t size) { + std::memcpy(kernelAddress, userAddress, size); + return {}; +} + +inline ErrorCode uwrite(ptr userAddress, const void *kernelAddress, + size_t size) { + std::memcpy(userAddress, kernelAddress, size); + return {}; +} + +inline ErrorCode ureadString(char *kernelAddress, size_t kernelSize, ptr userAddress) { + std::strncpy(kernelAddress, userAddress, kernelSize); + if (kernelAddress[kernelSize - 1] != '\0') { + kernelAddress[kernelSize - 1] = '\0'; + return ErrorCode::NAMETOOLONG; + } + + return {}; +} + +template T uread(ptr pointer) { + T result; + uread(&result, pointer, sizeof(T)); + return result; +} + +template void uwrite(ptr pointer, T data) { + uwrite(pointer, &data, sizeof(T)); +} + +uint64_t readRegister(void *context, RegisterId id); +void writeRegister(void *context, RegisterId id, uint64_t value); +} // namespace orbis diff --git a/orbis-kernel/examples/standalone/src/main.cpp b/orbis-kernel/examples/standalone/src/main.cpp new file mode 100644 index 000000000..a6d499971 --- /dev/null +++ b/orbis-kernel/examples/standalone/src/main.cpp @@ -0,0 +1,253 @@ +#include "orbis/sys/syscall.hpp" +#include "orbis/thread/Process.hpp" +#include "orbis/thread/ProcessOps.hpp" +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +struct Registers { + std::uint64_t r15; + std::uint64_t r14; + std::uint64_t r13; + std::uint64_t r12; + std::uint64_t r11; + std::uint64_t r10; + std::uint64_t r9; + std::uint64_t r8; + std::uint64_t rdi; + std::uint64_t rsi; + std::uint64_t rbp; + std::uint64_t rbx; + std::uint64_t rdx; + std::uint64_t rcx; + std::uint64_t rax; + std::uint64_t rsp; + std::uint64_t rflags; +}; + +namespace orbis { +uint64_t readRegister(void *context, RegisterId id) { + auto c = reinterpret_cast(context); + switch (id) { + case RegisterId::r15: return c->r15; + case RegisterId::r14: return c->r14; + case RegisterId::r13: return c->r13; + case RegisterId::r12: return c->r12; + case RegisterId::r11: return c->r11; + case RegisterId::r10: return c->r10; + case RegisterId::r9: return c->r9; + case RegisterId::r8: return c->r8; + case RegisterId::rdi: return c->rdi; + case RegisterId::rsi: return c->rsi; + case RegisterId::rbp: return c->rbp; + case RegisterId::rbx: return c->rbx; + case RegisterId::rdx: return c->rdx; + case RegisterId::rcx: return c->rcx; + case RegisterId::rax: return c->rax; + case RegisterId::rsp: return c->rsp; + case RegisterId::rflags: return c->rflags; + } +} + +void writeRegister(void *context, RegisterId id, uint64_t value) { + auto c = reinterpret_cast(context); + switch (id) { + case RegisterId::r15: c->r15 = value; return; + case RegisterId::r14: c->r14 = value; return; + case RegisterId::r13: c->r13 = value; return; + case RegisterId::r12: c->r12 = value; return; + case RegisterId::r11: c->r11 = value; return; + case RegisterId::r10: c->r10 = value; return; + case RegisterId::r9: c->r9 = value; return; + case RegisterId::r8: c->r8 = value; return; + case RegisterId::rdi: c->rdi = value; return; + case RegisterId::rsi: c->rsi = value; return; + case RegisterId::rbp: c->rbp = value; return; + case RegisterId::rbx: c->rbx = value; return; + case RegisterId::rdx: c->rdx = value; return; + case RegisterId::rcx: c->rcx = value; return; + case RegisterId::rax: c->rax = value; return; + case RegisterId::rsp: c->rsp = value; return; + case RegisterId::rflags: c->rflags = value; return; + } +} +} + +static thread_local orbis::Thread *g_guestThread = nullptr; + +class CPU { + struct Task { + orbis::Thread *thread; + std::function job; + }; + + int m_index; + std::deque m_workQueue; + std::condition_variable m_cv; + std::mutex m_mtx; + std::atomic m_terminate_flag{false}; + std::thread m_hostThread{[this] { entry(); }}; + +public: + CPU(int index) : m_index(index) {} + + int getIndex() const { + return m_index; + } + + void addTask(orbis::Thread *thread, std::function task) { + m_workQueue.push_back({thread, std::move(task)}); + m_cv.notify_one(); + } + + ~CPU() { + m_terminate_flag = true; + m_cv.notify_all(); + m_hostThread.join(); + } + + void entry() { + while (!m_terminate_flag) { + Task task; + { + std::unique_lock lock(m_mtx); + m_cv.wait(lock, + [this] { return !m_workQueue.empty() || m_terminate_flag; }); + + if (m_terminate_flag) { + break; + } + + task = std::move(m_workQueue.front()); + m_workQueue.pop_front(); + } + + task.thread->state = orbis::ThreadState::RUNNING; + g_guestThread = task.thread; + task.job(); + if (task.thread->state == orbis::ThreadState::RUNNING) { + task.thread->state = orbis::ThreadState::INACTIVE; + } + } + } +}; + +class Event { + std::condition_variable m_cv; + std::mutex m_mtx; + std::atomic m_fired; + +public: + void wait() { + std::unique_lock lock(m_mtx); + m_cv.wait(lock, [&] { return m_fired == true; }); + m_fired = false; + } + + void fire() { + m_fired = true; + m_cv.notify_all(); + } +}; + +struct orbis::ProcessOps procOps = { + .exit = [](orbis::Thread *, orbis::sint status) -> orbis::SysResult { + std::printf("sys_exit(%u)\n", status); + std::exit(status); + } +}; + +static orbis::Thread *allocateGuestThread(orbis::Process *process, + orbis::lwpid_t tid) { + auto guestThread = new orbis::Thread{}; + guestThread->state = orbis::ThreadState::RUNQ; + guestThread->tid = tid; + guestThread->tproc = process; + return guestThread; +} + + +static void onSysEnter(orbis::Thread *thread, int id, uint64_t *args, + int argsCount) { + std::printf(" [%u] sys_%u(", thread->tid, id); + + for (int i = 0; i < argsCount; ++i) { + if (i != 0) { + std::printf(", "); + } + + std::printf("%#lx", args[i]); + } + + std::printf(")\n"); +} + +static void onSysExit(orbis::Thread *thread, int id, uint64_t *args, + int argsCount, orbis::SysResult result) { + std::printf("%c: [%u] sys_%u(", result.isError() ? 'E' : 'S', thread->tid, + id); + + for (int i = 0; i < argsCount; ++i) { + if (i != 0) { + std::printf(", "); + } + + std::printf("%#lx", args[i]); + } + + std::printf(") -> Status %d, Value %lx:%lx\n", result.value(), + thread->retval[0], thread->retval[1]); +} + +struct KernelEventLogger : public orbis::KernelContext::EventListener { + void onProcessCreated(orbis::Process *process) override { + std::printf("process %u was created\n", (unsigned)process->pid); + } + void onProcessDeleted(orbis::pid_t pid) override { + std::printf("process %u was deleted\n", (unsigned)pid); + } +}; + +int main() { + KernelEventLogger eventLogger; + orbis::KernelContext context; + context.addEventListener(&eventLogger); + auto initProc = context.createProcess(1); + + initProc->ops = &procOps; + initProc->onSysEnter = onSysEnter; + initProc->onSysExit = onSysExit; + + initProc->state = orbis::ProcessState::NORMAL; + initProc->parentProcess = initProc; + initProc->sysent = &orbis::freebsd9_sysvec; + + auto initMainThread = allocateGuestThread(initProc, 1); + + CPU cpu{0}; + Event completeEvent; + cpu.addTask(initMainThread, [&completeEvent] { + Registers regs{}; + regs.rax = orbis::kSYS_syscall; + regs.rdi = orbis::kSYS_exit; + regs.rsi = 0x64; + g_guestThread->context = ®s; + + orbis::syscall_entry(g_guestThread); + + completeEvent.fire(); + }); + + completeEvent.wait(); + delete initMainThread; + return 0; +} diff --git a/orbis-kernel/include/orbis/KernelContext.hpp b/orbis-kernel/include/orbis/KernelContext.hpp new file mode 100644 index 000000000..864660c18 --- /dev/null +++ b/orbis-kernel/include/orbis/KernelContext.hpp @@ -0,0 +1,97 @@ +#pragma once +#include "orbis/thread/Process.hpp" +#include "utils/LinkedNode.hpp" +#include "utils/SharedMutex.hpp" + +#include +#include +#include +#include + +namespace orbis { +class KernelContext { +public: + struct EventListener { + virtual ~EventListener() = default; + virtual void onProcessCreated(Process *) = 0; + virtual void onProcessDeleted(pid_t pid) = 0; + }; + + ~KernelContext() { + while (m_processes != nullptr) { + deleteProcess(&m_processes->object); + } + } + + void addEventListener(EventListener *listener) { + m_event_listeners.push_back(listener); + } + + void removeEventListener(EventListener *listener) { + auto it = + std::find(m_event_listeners.begin(), m_event_listeners.end(), listener); + + if (it != m_event_listeners.end()) { + m_event_listeners.erase(it); + } + } + + Process *createProcess(pid_t pid) { + auto newProcess = new utils::LinkedNode(); + newProcess->object.context = this; + newProcess->object.pid = pid; + newProcess->object.state = ProcessState::NEW; + + { + std::lock_guard lock(m_proc_mtx); + if (m_processes != nullptr) { + m_processes->insertPrev(*newProcess); + } + + m_processes = newProcess; + } + + for (auto listener : m_event_listeners) { + listener->onProcessCreated(&newProcess->object); + } + + return &newProcess->object; + } + + void deleteProcess(Process *proc) { + auto procNode = reinterpret_cast *>(proc); + auto pid = proc->pid; + + { + std::lock_guard lock(m_proc_mtx); + auto next = procNode->erase(); + + if (procNode == m_processes) { + m_processes = next; + } + } + + delete procNode; + + for (auto listener : m_event_listeners) { + listener->onProcessDeleted(pid); + } + } + + Process *findProcessById(pid_t pid) const { + std::lock_guard lock(m_proc_mtx); + for (auto proc = m_processes; proc != nullptr; proc = proc->next) { + if (proc->object.pid == pid) { + return &proc->object; + } + } + + return nullptr; + } + +private: + mutable shared_mutex m_proc_mtx; + utils::LinkedNode *m_processes = nullptr; + std::vector m_event_listeners; +}; +} // namespace orbis \ No newline at end of file diff --git a/orbis-kernel/include/orbis/error.hpp b/orbis-kernel/include/orbis/error.hpp new file mode 100644 index 000000000..cf2be1435 --- /dev/null +++ b/orbis-kernel/include/orbis/error.hpp @@ -0,0 +1,4 @@ +#pragma once + +#include "error/SysResult.hpp" // IWYU pragma: export +#include "error/ErrorCode.hpp" // IWYU pragma: export diff --git a/orbis-kernel/include/orbis/error/ErrorCode.hpp b/orbis-kernel/include/orbis/error/ErrorCode.hpp new file mode 100644 index 000000000..d5254bc45 --- /dev/null +++ b/orbis-kernel/include/orbis/error/ErrorCode.hpp @@ -0,0 +1,111 @@ +#pragma once + +namespace orbis { +enum class ErrorCode : int { + PERM = 1, // Operation not permitted + NOENT = 2, // No such file or directory + SRCH = 3, // No such process + INTR = 4, // Interrupted system call + IO = 5, // Input/output error + NXIO = 6, // Device not configured + TOOBIG = 7, // Argument list too long + NOEXEC = 8, // Exec format error + BADF = 9, // Bad file descriptor + CHILD = 10, // No child processes + DEADLK = 11, // Resource deadlock avoided + + NOMEM = 12, // Cannot allocate memory + ACCES = 13, // Permission denied + FAULT = 14, // Bad address + NOTBLK = 15, // Block device required + BUSY = 16, // Device busy + EXIST = 17, // File exists + XDEV = 18, // Cross-device link + NODEV = 19, // Operation not supported by device + NOTDIR = 20, // Not a directory + ISDIR = 21, // Is a directory + INVAL = 22, // Invalid argument + NFILE = 23, // Too many open files in system + MFILE = 24, // Too many open files + NOTTY = 25, // Inappropriate ioctl for device + TXTBSY = 26, // Text file busy + FBIG = 27, // File too large + NOSPC = 28, // No space left on device + SPIPE = 29, // Illegal seek + ROFS = 30, // Read-only filesystem + MLINK = 31, // Too many links + PIPE = 32, // Broken pipe + + DOM = 33, // Numerical argument out of domain + RANGE = 34, // Result too large + + AGAIN = 35, // Resource temporarily unavailable + WOULDBLOCK = AGAIN, // Operation would block + INPROGRESS = 36, // Operation now in progress + ALREADY = 37, // Operation already in progress + + NOTSOCK = 38, // Socket operation on non-socket + DESTADDRREQ = 39, // Destination address required + MSGSIZE = 40, // Message too long + PROTOTYPE = 41, // Protocol wrong type for socket + NOPROTOOPT = 42, // Protocol not available + PROTONOSUPPORT = 43, // Protocol not supported + SOCKTNOSUPPORT = 44, // Socket type not supported + OPNOTSUPP = 45, // Operation not supported + NOTSUP = OPNOTSUPP, // Operation not supported + PFNOSUPPORT = 46, // Protocol family not supported + AFNOSUPPORT = 47, // Address family not supported by protocol family + ADDRINUSE = 48, // Address already in use + ADDRNOTAVAIL = 49, // Can't assign requested address + + NETDOWN = 50, // Network is down + NETUNREACH = 51, // Network is unreachable + NETRESET = 52, // Network dropped connection on reset + CONNABORTED = 53, // Software caused connection abort + CONNRESET = 54, // Connection reset by peer + NOBUFS = 55, // No buffer space available + ISCONN = 56, // Socket is already connected + NOTCONN = 57, // Socket is not connected + SHUTDOWN = 58, // Can't send after socket shutdown + TOOMANYREFS = 59, // Too many references: can't splice + TIMEDOUT = 60, // Operation timed out + CONNREFUSED = 61, // Connection refused + + LOOP = 62, // Too many levels of symbolic links + NAMETOOLONG = 63, // File name too long + HOSTDOWN = 64, // Host is down + HOSTUNREACH = 65, // No route to host + NOTEMPTY = 66, // Directory not empty + PROCLIM = 67, // Too many processes + USERS = 68, // Too many users + DQUOT = 69, // Disc quota exceeded + STALE = 70, // Stale NFS file handle + REMOTE = 71, // Too many levels of remote in path + BADRPC = 72, // RPC struct is bad + RPCMISMATCH = 73, // RPC version wrong + PROGUNAVAIL = 74, // RPC prog. not avail + PROGMISMATCH = 75, // Program version wrong + PROCUNAVAIL = 76, // Bad procedure for program + NOLCK = 77, // No locks available + NOSYS = 78, // Function not implemented + FTYPE = 79, // Inappropriate file type or format + AUTH = 80, // Authentication error + NEEDAUTH = 81, // Need authenticator + IDRM = 82, // Identifier removed + NOMSG = 83, // No message of desired type + OVERFLOW = 84, // Value too large to be stored in data type + CANCELED = 85, // Operation canceled + ILSEQ = 86, // Illegal byte sequence + NOATTR = 87, // Attribute not found + + DOOFUS = 88, // Programming error + + BADMSG = 89, // Bad message + MULTIHOP = 90, // Multihop attempted + NOLINK = 91, // Link has been severed + PROTO = 92, // Protocol error + + NOTCAPABLE = 93, // Capabilities insufficient + CAPMODE = 94, // Not permitted in capability mode +}; +} // namespace orbis diff --git a/orbis-kernel/include/orbis/error/SysResult.hpp b/orbis-kernel/include/orbis/error/SysResult.hpp new file mode 100644 index 000000000..d112894a9 --- /dev/null +++ b/orbis-kernel/include/orbis/error/SysResult.hpp @@ -0,0 +1,22 @@ +#pragma once + +namespace orbis { +enum class ErrorCode : int; + +class SysResult { + int mValue = 0; + +public: + SysResult() = default; + SysResult(ErrorCode ec) : mValue(-static_cast(ec)){} + + [[nodiscard]] static SysResult notAnError(ErrorCode ec) { + SysResult result; + result.mValue = static_cast(ec); + return result; + } + + [[nodiscard]] int value() const { return mValue < 0 ? -mValue : mValue; } + [[nodiscard]] bool isError() const { return mValue < 0; } +}; +} // namespace orbis diff --git a/orbis-kernel/include/orbis/module.hpp b/orbis-kernel/include/orbis/module.hpp new file mode 100644 index 000000000..3cf1be79f --- /dev/null +++ b/orbis-kernel/include/orbis/module.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include "module/Module.hpp" // IWYU pragma: export +#include "module/ModuleHandle.hpp" // IWYU pragma: export +#include "module/ModuleInfo.hpp" // IWYU pragma: export +#include "module/ModuleInfoEx.hpp" // IWYU pragma: export +#include "module/ModuleSegment.hpp" // IWYU pragma: export diff --git a/orbis-kernel/include/orbis/module/Module.hpp b/orbis-kernel/include/orbis/module/Module.hpp new file mode 100644 index 000000000..29c6613ef --- /dev/null +++ b/orbis-kernel/include/orbis/module/Module.hpp @@ -0,0 +1,141 @@ +#pragma once + +#include "ModuleHandle.hpp" +#include "ModuleSegment.hpp" + +#include "../utils/Rc.hpp" + +#include "orbis-config.hpp" +#include +#include +#include + +namespace orbis { +struct Thread; +struct Process; + +struct ModuleNeeded { + std::string name; + std::uint16_t version; + std::uint16_t attr; + bool isExport; +}; + +enum class SymbolBind : std::uint8_t { + Local, + Global, + Weak, + Unique = 10 +}; + +enum class SymbolVisibility : std::uint8_t { + Default, + Internal, + Hidden, + Protected +}; + +enum class SymbolType : std::uint8_t { + NoType, + Object, + Function, + Section, + File, + Common, + Tls, + IFunc = 10, +}; + + +struct Symbol { + std::int32_t moduleIndex; + std::uint32_t libraryIndex; + std::uint64_t id; + std::uint64_t address; + std::uint64_t size; + SymbolVisibility visibility; + SymbolBind bind; + SymbolType type; +}; + +struct Relocation { + std::uint64_t offset; + std::uint32_t relType; + std::uint32_t symbolIndex; + std::int64_t addend; +}; + +struct Module { + Process *proc{}; + std::string vfsPath; + char moduleName[256]{}; + char soName[256]{}; + ModuleHandle id{}; + uint32_t tlsIndex{}; + ptr tlsInit{}; + uint32_t tlsInitSize{}; + uint32_t tlsSize{}; + uint32_t tlsOffset{}; + uint32_t tlsAlign{}; + ptr initProc{}; + ptr finiProc{}; + ptr ehFrameHdr{}; + ptr ehFrame{}; + uint32_t ehFrameHdrSize{}; + uint32_t ehFrameSize{}; + ModuleSegment segments[4]{}; + uint32_t segmentCount{}; + std::uint8_t fingerprint[20]{}; + ptr base{}; + uint64_t size{}; + ptr stackStart{}; + ptr stackEnd{}; + ptr processParam{}; + uint64_t processParamSize{}; + ptr moduleParam{}; + uint64_t moduleParamSize{}; + + ptr pltGot{}; + + uint16_t version{}; + uint16_t attributes{}; + uint16_t type{}; + uint16_t flags{}; + uint64_t entryPoint{}; + + uint32_t phNum{}; + uint64_t phdrAddress{}; + + bool isTlsDone = false; + + std::vector symbols; + std::vector pltRelocations; + std::vector nonPltRelocations; + std::vector neededModules; + std::vector neededLibraries; + std::vector> importedModules; + std::vector> namespaceModules; + std::vector needed; + + std::atomic references{0}; + + void incRef() { + if (references.fetch_add(1, std::memory_order::relaxed) > 512) { + assert(!"too many references"); + } + } + + void decRef() { + if (references.fetch_sub(1, std::memory_order::relaxed) == 1 && proc != nullptr) { + destroy(); + } + } + + orbis::SysResult relocate(Process *process); + +private: + void destroy(); +}; + +utils::Ref createModule(Thread *p, std::string vfsPath, const char *name); +} // namespace orbis diff --git a/orbis-kernel/include/orbis/module/ModuleHandle.hpp b/orbis-kernel/include/orbis/module/ModuleHandle.hpp new file mode 100644 index 000000000..28c07f014 --- /dev/null +++ b/orbis-kernel/include/orbis/module/ModuleHandle.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace orbis { +enum class ModuleHandle : std::uint32_t {}; +} // namespace orbis diff --git a/orbis-kernel/include/orbis/module/ModuleInfo.hpp b/orbis-kernel/include/orbis/module/ModuleInfo.hpp new file mode 100644 index 000000000..b4c78e3be --- /dev/null +++ b/orbis-kernel/include/orbis/module/ModuleInfo.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include "ModuleSegment.hpp" + +#include "orbis-config.hpp" + +namespace orbis { +struct ModuleInfo { + uint64_t size; + char name[256]; + ModuleSegment segments[4]; + uint32_t segmentCount; + uint8_t fingerprint[20]; +}; +} // namespace orbis diff --git a/orbis-kernel/include/orbis/module/ModuleInfoEx.hpp b/orbis-kernel/include/orbis/module/ModuleInfoEx.hpp new file mode 100644 index 000000000..e5a615bc3 --- /dev/null +++ b/orbis-kernel/include/orbis/module/ModuleInfoEx.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include "ModuleSegment.hpp" + +#include "orbis-config.hpp" + +namespace orbis { +struct ModuleInfoEx { + uint64_t size; + char name[256]; + uint32_t id; + uint32_t tlsIndex; + ptr tlsInit; + uint32_t tlsInitSize; + uint32_t tlsSize; + uint32_t tlsOffset; + uint32_t tlsAlign; + ptr initProc; + ptr finiProc; + uint64_t reserved1; + uint64_t reserved2; + ptr ehFrameHdr; + ptr ehFrame; + uint32_t ehFrameHdrSize; + uint32_t ehFrameSize; + ModuleSegment segments[4]; + uint32_t segmentCount; + uint32_t refCount; +}; +} // namespace orbis diff --git a/orbis-kernel/include/orbis/module/ModuleSegment.hpp b/orbis-kernel/include/orbis/module/ModuleSegment.hpp new file mode 100644 index 000000000..b5185854c --- /dev/null +++ b/orbis-kernel/include/orbis/module/ModuleSegment.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "orbis-config.hpp" + +namespace orbis { +struct ModuleSegment { + ptr addr; + uint32_t size; + uint32_t prot; +}; +} // namespace orbis diff --git a/orbis-kernel/include/orbis/sys/syscall.hpp b/orbis-kernel/include/orbis/sys/syscall.hpp new file mode 100644 index 000000000..fe72c5927 --- /dev/null +++ b/orbis-kernel/include/orbis/sys/syscall.hpp @@ -0,0 +1,599 @@ +#pragma once + +namespace orbis { +enum Syscall { + kSYS_syscall = 0, + kSYS_exit = 1, + kSYS_fork = 2, + kSYS_read = 3, + kSYS_write = 4, + kSYS_open = 5, + kSYS_close = 6, + kSYS_wait4 = 7, + kSYS_link = 9, + kSYS_unlink = 10, + kSYS_chdir = 12, + kSYS_fchdir = 13, + kSYS_mknod = 14, + kSYS_chmod = 15, + kSYS_chown = 16, + kSYS_break = 17, + kSYS_freebsd4_getfsstat = 18, + kSYS_getpid = 20, + kSYS_mount = 21, + kSYS_unmount = 22, + kSYS_setuid = 23, + kSYS_getuid = 24, + kSYS_geteuid = 25, + kSYS_ptrace = 26, + kSYS_recvmsg = 27, + kSYS_sendmsg = 28, + kSYS_recvfrom = 29, + kSYS_accept = 30, + kSYS_getpeername = 31, + kSYS_getsockname = 32, + kSYS_access = 33, + kSYS_chflags = 34, + kSYS_fchflags = 35, + kSYS_sync = 36, + kSYS_kill = 37, + kSYS_getppid = 39, + kSYS_dup = 41, + kSYS_pipe = 42, + kSYS_getegid = 43, + kSYS_profil = 44, + kSYS_ktrace = 45, + kSYS_getgid = 47, + kSYS_getlogin = 49, + kSYS_setlogin = 50, + kSYS_acct = 51, + kSYS_sigaltstack = 53, + kSYS_ioctl = 54, + kSYS_reboot = 55, + kSYS_revoke = 56, + kSYS_symlink = 57, + kSYS_readlink = 58, + kSYS_execve = 59, + kSYS_umask = 60, + kSYS_chroot = 61, + kSYS_msync = 65, + kSYS_vfork = 66, + kSYS_sbrk = 69, + kSYS_sstk = 70, + kSYS_vadvise = 72, + kSYS_munmap = 73, + kSYS_mprotect = 74, + kSYS_madvise = 75, + kSYS_mincore = 78, + kSYS_getgroups = 79, + kSYS_setgroups = 80, + kSYS_getpgrp = 81, + kSYS_setpgid = 82, + kSYS_setitimer = 83, + kSYS_swapon = 85, + kSYS_getitimer = 86, + kSYS_getdtablesize = 89, + kSYS_dup2 = 90, + kSYS_fcntl = 92, + kSYS_select = 93, + kSYS_fsync = 95, + kSYS_setpriority = 96, + kSYS_socket = 97, + kSYS_connect = 98, + kSYS_getpriority = 100, + kSYS_bind = 104, + kSYS_setsockopt = 105, + kSYS_listen = 106, + kSYS_gettimeofday = 116, + kSYS_getrusage = 117, + kSYS_getsockopt = 118, + kSYS_readv = 120, + kSYS_writev = 121, + kSYS_settimeofday = 122, + kSYS_fchown = 123, + kSYS_fchmod = 124, + kSYS_setreuid = 126, + kSYS_setregid = 127, + kSYS_rename = 128, + kSYS_flock = 131, + kSYS_mkfifo = 132, + kSYS_sendto = 133, + kSYS_shutdown = 134, + kSYS_socketpair = 135, + kSYS_mkdir = 136, + kSYS_rmdir = 137, + kSYS_utimes = 138, + kSYS_adjtime = 140, + kSYS_setsid = 147, + kSYS_quotactl = 148, + kSYS_nlm_syscall = 154, + kSYS_nfssvc = 155, + kSYS_freebsd4_statfs = 157, + kSYS_freebsd4_fstatfs = 158, + kSYS_lgetfh = 160, + kSYS_getfh = 161, + kSYS_freebsd4_getdomainname = 162, + kSYS_freebsd4_setdomainname = 163, + kSYS_freebsd4_uname = 164, + kSYS_sysarch = 165, + kSYS_rtprio = 166, + kSYS_semsys = 169, + kSYS_msgsys = 170, + kSYS_shmsys = 171, + kSYS_freebsd6_pread = 173, + kSYS_freebsd6_pwrite = 174, + kSYS_setfib = 175, + kSYS_ntp_adjtime = 176, + kSYS_setgid = 181, + kSYS_setegid = 182, + kSYS_seteuid = 183, + kSYS_stat = 188, + kSYS_fstat = 189, + kSYS_lstat = 190, + kSYS_pathconf = 191, + kSYS_fpathconf = 192, + kSYS_getrlimit = 194, + kSYS_setrlimit = 195, + kSYS_getdirentries = 196, + kSYS_freebsd6_mmap = 197, + kSYS___syscall = 198, + kSYS_freebsd6_lseek = 199, + kSYS_freebsd6_truncate = 200, + kSYS_freebsd6_ftruncate = 201, + kSYS___sysctl = 202, + kSYS_mlock = 203, + kSYS_munlock = 204, + kSYS_undelete = 205, + kSYS_futimes = 206, + kSYS_getpgid = 207, + kSYS_poll = 209, + kSYS_freebsd7___semctl = 220, + kSYS_semget = 221, + kSYS_semop = 222, + kSYS_freebsd7_msgctl = 224, + kSYS_msgget = 225, + kSYS_msgsnd = 226, + kSYS_msgrcv = 227, + kSYS_shmat = 228, + kSYS_freebsd7_shmctl = 229, + kSYS_shmdt = 230, + kSYS_shmget = 231, + kSYS_clock_gettime = 232, + kSYS_clock_settime = 233, + kSYS_clock_getres = 234, + kSYS_ktimer_create = 235, + kSYS_ktimer_delete = 236, + kSYS_ktimer_settime = 237, + kSYS_ktimer_gettime = 238, + kSYS_ktimer_getoverrun = 239, + kSYS_nanosleep = 240, + kSYS_ffclock_getcounter = 241, + kSYS_ffclock_setestimate = 242, + kSYS_ffclock_getestimate = 243, + kSYS_clock_getcpuclockid2 = 247, + kSYS_ntp_gettime = 248, + kSYS_minherit = 250, + kSYS_rfork = 251, + kSYS_openbsd_poll = 252, + kSYS_issetugid = 253, + kSYS_lchown = 254, + kSYS_aio_read = 255, + kSYS_aio_write = 256, + kSYS_lio_listio = 257, + kSYS_getdents = 272, + kSYS_lchmod = 274, + kSYS_netbsd_lchown = 275, + kSYS_lutimes = 276, + kSYS_netbsd_msync = 277, + kSYS_nstat = 278, + kSYS_nfstat = 279, + kSYS_nlstat = 280, + kSYS_preadv = 289, + kSYS_pwritev = 290, + kSYS_freebsd4_fhstatfs = 297, + kSYS_fhopen = 298, + kSYS_fhstat = 299, + kSYS_modnext = 300, + kSYS_modstat = 301, + kSYS_modfnext = 302, + kSYS_modfind = 303, + kSYS_kldload = 304, + kSYS_kldunload = 305, + kSYS_kldfind = 306, + kSYS_kldnext = 307, + kSYS_kldstat = 308, + kSYS_kldfirstmod = 309, + kSYS_getsid = 310, + kSYS_setresuid = 311, + kSYS_setresgid = 312, + kSYS_aio_return = 314, + kSYS_aio_suspend = 315, + kSYS_aio_cancel = 316, + kSYS_aio_error = 317, + kSYS_oaio_read = 318, + kSYS_oaio_write = 319, + kSYS_olio_listio = 320, + kSYS_yield = 321, + kSYS_mlockall = 324, + kSYS_munlockall = 325, + kSYS___getcwd = 326, + kSYS_sched_setparam = 327, + kSYS_sched_getparam = 328, + kSYS_sched_setscheduler = 329, + kSYS_sched_getscheduler = 330, + kSYS_sched_yield = 331, + kSYS_sched_get_priority_max = 332, + kSYS_sched_get_priority_min = 333, + kSYS_sched_rr_get_interval = 334, + kSYS_utrace = 335, + kSYS_freebsd4_sendfile = 336, + kSYS_kldsym = 337, + kSYS_jail = 338, + kSYS_nnpfs_syscall = 339, + kSYS_sigprocmask = 340, + kSYS_sigsuspend = 341, + kSYS_freebsd4_sigaction = 342, + kSYS_sigpending = 343, + kSYS_freebsd4_sigreturn = 344, + kSYS_sigtimedwait = 345, + kSYS_sigwaitinfo = 346, + kSYS___acl_get_file = 347, + kSYS___acl_set_file = 348, + kSYS___acl_get_fd = 349, + kSYS___acl_set_fd = 350, + kSYS___acl_delete_file = 351, + kSYS___acl_delete_fd = 352, + kSYS___acl_aclcheck_file = 353, + kSYS___acl_aclcheck_fd = 354, + kSYS_extattrctl = 355, + kSYS_extattr_set_file = 356, + kSYS_extattr_get_file = 357, + kSYS_extattr_delete_file = 358, + kSYS_aio_waitcomplete = 359, + kSYS_getresuid = 360, + kSYS_getresgid = 361, + kSYS_kqueue = 362, + kSYS_kevent = 363, + kSYS_extattr_set_fd = 371, + kSYS_extattr_get_fd = 372, + kSYS_extattr_delete_fd = 373, + kSYS___setugid = 374, + kSYS_eaccess = 376, + kSYS_afs3_syscall = 377, + kSYS_nmount = 378, + kSYS___mac_get_proc = 384, + kSYS___mac_set_proc = 385, + kSYS___mac_get_fd = 386, + kSYS___mac_get_file = 387, + kSYS___mac_set_fd = 388, + kSYS___mac_set_file = 389, + kSYS_kenv = 390, + kSYS_lchflags = 391, + kSYS_uuidgen = 392, + kSYS_sendfile = 393, + kSYS_mac_syscall = 394, + kSYS_getfsstat = 395, + kSYS_statfs = 396, + kSYS_fstatfs = 397, + kSYS_fhstatfs = 398, + kSYS_ksem_close = 400, + kSYS_ksem_post = 401, + kSYS_ksem_wait = 402, + kSYS_ksem_trywait = 403, + kSYS_ksem_init = 404, + kSYS_ksem_open = 405, + kSYS_ksem_unlink = 406, + kSYS_ksem_getvalue = 407, + kSYS_ksem_destroy = 408, + kSYS___mac_get_pid = 409, + kSYS___mac_get_link = 410, + kSYS___mac_set_link = 411, + kSYS_extattr_set_link = 412, + kSYS_extattr_get_link = 413, + kSYS_extattr_delete_link = 414, + kSYS___mac_execve = 415, + kSYS_sigaction = 416, + kSYS_sigreturn = 417, + kSYS_getcontext = 421, + kSYS_setcontext = 422, + kSYS_swapcontext = 423, + kSYS_swapoff = 424, + kSYS___acl_get_link = 425, + kSYS___acl_set_link = 426, + kSYS___acl_delete_link = 427, + kSYS___acl_aclcheck_link = 428, + kSYS_sigwait = 429, + kSYS_thr_create = 430, + kSYS_thr_exit = 431, + kSYS_thr_self = 432, + kSYS_thr_kill = 433, + kSYS__umtx_lock = 434, + kSYS__umtx_unlock = 435, + kSYS_jail_attach = 436, + kSYS_extattr_list_fd = 437, + kSYS_extattr_list_file = 438, + kSYS_extattr_list_link = 439, + kSYS_ksem_timedwait = 441, + kSYS_thr_suspend = 442, + kSYS_thr_wake = 443, + kSYS_kldunloadf = 444, + kSYS_audit = 445, + kSYS_auditon = 446, + kSYS_getauid = 447, + kSYS_setauid = 448, + kSYS_getaudit = 449, + kSYS_setaudit = 450, + kSYS_getaudit_addr = 451, + kSYS_setaudit_addr = 452, + kSYS_auditctl = 453, + kSYS__umtx_op = 454, + kSYS_thr_new = 455, + kSYS_sigqueue = 456, + kSYS_kmq_open = 457, + kSYS_kmq_setattr = 458, + kSYS_kmq_timedreceive = 459, + kSYS_kmq_timedsend = 460, + kSYS_kmq_notify = 461, + kSYS_kmq_unlink = 462, + kSYS_abort2 = 463, + kSYS_thr_set_name = 464, + kSYS_aio_fsync = 465, + kSYS_rtprio_thread = 466, + kSYS_sctp_peeloff = 471, + kSYS_sctp_generic_sendmsg = 472, + kSYS_sctp_generic_sendmsg_iov = 473, + kSYS_sctp_generic_recvmsg = 474, + kSYS_pread = 475, + kSYS_pwrite = 476, + kSYS_mmap = 477, + kSYS_lseek = 478, + kSYS_truncate = 479, + kSYS_ftruncate = 480, + kSYS_thr_kill2 = 481, + kSYS_shm_open = 482, + kSYS_shm_unlink = 483, + kSYS_cpuset = 484, + kSYS_cpuset_setid = 485, + kSYS_cpuset_getid = 486, + kSYS_cpuset_getaffinity = 487, + kSYS_cpuset_setaffinity = 488, + kSYS_faccessat = 489, + kSYS_fchmodat = 490, + kSYS_fchownat = 491, + kSYS_fexecve = 492, + kSYS_fstatat = 493, + kSYS_futimesat = 494, + kSYS_linkat = 495, + kSYS_mkdirat = 496, + kSYS_mkfifoat = 497, + kSYS_mknodat = 498, + kSYS_openat = 499, + kSYS_readlinkat = 500, + kSYS_renameat = 501, + kSYS_symlinkat = 502, + kSYS_unlinkat = 503, + kSYS_posix_openpt = 504, + kSYS_gssd_syscall = 505, + kSYS_jail_get = 506, + kSYS_jail_set = 507, + kSYS_jail_remove = 508, + kSYS_closefrom = 509, + kSYS___semctl = 510, + kSYS_msgctl = 511, + kSYS_shmctl = 512, + kSYS_lpathconf = 513, + kSYS_cap_new = 514, + kSYS_cap_getrights = 515, + kSYS_cap_enter = 516, + kSYS_cap_getmode = 517, + kSYS_pdfork = 518, + kSYS_pdkill = 519, + kSYS_pdgetpid = 520, + kSYS_pselect = 522, + kSYS_getloginclass = 523, + kSYS_setloginclass = 524, + kSYS_rctl_get_racct = 525, + kSYS_rctl_get_rules = 526, + kSYS_rctl_get_limits = 527, + kSYS_rctl_add_rule = 528, + kSYS_rctl_remove_rule = 529, + kSYS_posix_fallocate = 530, + kSYS_posix_fadvise = 531, + + kSYS_netcontrol = 99, + kSYS_netabort = 101, + kSYS_netgetsockinfo = 102, + kSYS_socketex = 113, + kSYS_socketclose = 114, + kSYS_netgetiflist = 125, + kSYS_kqueueex = 141, + kSYS_mtypeprotect = 379, + kSYS_regmgr_call = 532, + kSYS_jitshm_create = 533, + kSYS_jitshm_alias = 534, + kSYS_dl_get_list = 535, + kSYS_dl_get_info = 536, + kSYS_dl_notify_event = 537, + kSYS_evf_create = 538, + kSYS_evf_delete = 539, + kSYS_evf_open = 540, + kSYS_evf_close = 541, + kSYS_evf_wait = 542, + kSYS_evf_trywait = 543, + kSYS_evf_set = 544, + kSYS_evf_clear = 545, + kSYS_evf_cancel = 546, + kSYS_query_memory_protection = 547, + kSYS_batch_map = 548, + kSYS_osem_create = 549, + kSYS_osem_delete = 550, + kSYS_osem_open = 551, + kSYS_osem_close = 552, + kSYS_osem_wait = 553, + kSYS_osem_trywait = 554, + kSYS_osem_post = 555, + kSYS_osem_cancel = 556, + kSYS_namedobj_create = 557, + kSYS_namedobj_delete = 558, + kSYS_set_vm_container = 559, + kSYS_debug_init = 560, + kSYS_suspend_process = 561, + kSYS_resume_process = 562, + kSYS_opmc_enable = 563, + kSYS_opmc_disable = 564, + kSYS_opmc_set_ctl = 565, + kSYS_opmc_set_ctr = 566, + kSYS_opmc_get_ctr = 567, + kSYS_budget_create = 568, + kSYS_budget_delete = 569, + kSYS_budget_get = 570, + kSYS_budget_set = 571, + kSYS_virtual_query = 572, + kSYS_mdbg_call = 573, + kSYS_obs_sblock_create = 574, + kSYS_obs_sblock_delete = 575, + kSYS_obs_sblock_enter = 576, + kSYS_obs_sblock_exit = 577, + kSYS_obs_sblock_xenter = 578, + kSYS_obs_sblock_xexit = 579, + kSYS_obs_eport_create = 580, + kSYS_obs_eport_delete = 581, + kSYS_obs_eport_trigger = 582, + kSYS_obs_eport_open = 583, + kSYS_obs_eport_close = 584, + kSYS_is_in_sandbox = 585, + kSYS_dmem_container = 586, + kSYS_get_authinfo = 587, + kSYS_mname = 588, + kSYS_dynlib_dlopen = 589, + kSYS_dynlib_dlclose = 590, + kSYS_dynlib_dlsym = 591, + kSYS_dynlib_get_list = 592, + kSYS_dynlib_get_info = 593, + kSYS_dynlib_load_prx = 594, + kSYS_dynlib_unload_prx = 595, + kSYS_dynlib_do_copy_relocations = 596, + kSYS_dynlib_prepare_dlclose = 597, + kSYS_dynlib_get_proc_param = 598, + kSYS_dynlib_process_needed_and_relocate = 599, + kSYS_sandbox_path = 600, + kSYS_mdbg_service = 601, + kSYS_randomized_path = 602, + kSYS_rdup = 603, + kSYS_dl_get_metadata = 604, + kSYS_workaround8849 = 605, + kSYS_is_development_mode = 606, + kSYS_get_self_auth_info = 607, + kSYS_dynlib_get_info_ex = 608, + kSYS_budget_getid = 609, + kSYS_budget_get_ptype = 610, + kSYS_get_paging_stats_of_all_threads = 611, + kSYS_get_proc_type_info = 612, + kSYS_get_resident_count = 613, + kSYS_prepare_to_suspend_process = 614, + kSYS_get_resident_fmem_count = 615, + kSYS_thr_get_name = 616, + kSYS_set_gpo = 617, + kSYS_get_paging_stats_of_all_objects = 618, + kSYS_test_debug_rwmem = 619, + kSYS_free_stack = 620, + kSYS_suspend_system = 621, + kSYS_ipmimgr_call = 622, + kSYS_get_gpo = 623, + kSYS_get_vm_map_timestamp = 624, + kSYS_opmc_set_hw = 625, + kSYS_opmc_get_hw = 626, + kSYS_get_cpu_usage_all = 627, + kSYS_mmap_dmem = 628, + kSYS_physhm_open = 629, + kSYS_physhm_unlink = 630, + kSYS_resume_internal_hdd = 631, + kSYS_thr_suspend_ucontext = 632, + kSYS_thr_resume_ucontext = 633, + kSYS_thr_get_ucontext = 634, + kSYS_thr_set_ucontext = 635, + kSYS_set_timezone_info = 636, + kSYS_set_phys_fmem_limit = 637, + kSYS_utc_to_localtime = 638, + kSYS_localtime_to_utc = 639, + kSYS_set_uevt = 640, + kSYS_get_cpu_usage_proc = 641, + kSYS_get_map_statistics = 642, + kSYS_set_chicken_switches = 643, + kSYS_extend_page_table_pool = 644, + kSYS_extend_page_table_pool2 = 645, + kSYS_get_kernel_mem_statistics = 646, + kSYS_get_sdk_compiled_version = 647, + kSYS_app_state_change = 648, + kSYS_dynlib_get_obj_member = 649, + kSYS_budget_get_ptype_of_budget = 650, + kSYS_prepare_to_resume_process = 651, + kSYS_process_terminate = 652, + kSYS_blockpool_open = 653, + kSYS_blockpool_map = 654, + kSYS_blockpool_unmap = 655, + kSYS_dynlib_get_info_for_libdbg = 656, + kSYS_blockpool_batch = 657, + kSYS_fdatasync = 658, + kSYS_dynlib_get_list2 = 659, + kSYS_dynlib_get_info2 = 660, + kSYS_aio_submit = 661, + kSYS_aio_multi_delete = 662, + kSYS_aio_multi_wait = 663, + kSYS_aio_multi_poll = 664, + kSYS_aio_get_data = 665, + kSYS_aio_multi_cancel = 666, + kSYS_get_bio_usage_all = 667, + kSYS_aio_create = 668, + kSYS_aio_submit_cmd = 669, + kSYS_aio_init = 670, + kSYS_get_page_table_stats = 671, + kSYS_dynlib_get_list_for_libdbg = 672, + kSYS_blockpool_move = 673, + kSYS_virtual_query_all = 674, + kSYS_reserve_2mb_page = 675, + kSYS_cpumode_yield = 676, + + kSYS_wait6 = 677, + kSYS_cap_rights_limit = 678, + kSYS_cap_ioctls_limit = 679, + kSYS_cap_ioctls_get = 680, + kSYS_cap_fcntls_limit = 681, + kSYS_cap_fcntls_get = 682, + kSYS_bindat = 683, + kSYS_connectat = 684, + kSYS_chflagsat = 685, + kSYS_accept4 = 686, + kSYS_pipe2 = 687, + kSYS_aio_mlock = 688, + kSYS_procctl = 689, + kSYS_ppoll = 690, + kSYS_futimens = 691, + kSYS_utimensat = 692, + kSYS_numa_getaffinity = 693, + kSYS_numa_setaffinity = 694, + kSYS_apr_submit = 700, + kSYS_apr_resolve = 701, + kSYS_apr_stat = 702, + kSYS_apr_wait = 703, + kSYS_apr_ctrl = 704, + kSYS_get_phys_page_size = 705, + kSYS_begin_app_mount = 706, + kSYS_end_app_mount = 707, + kSYS_fsc2h_ctrl = 708, + kSYS_streamwrite = 709, + kSYS_app_save = 710, + kSYS_app_restore = 711, + kSYS_saved_app_delete = 712, + kSYS_get_ppr_sdk_compiled_version = 713, + kSYS_notify_app_event = 714, + kSYS_ioreq = 715, + kSYS_openintr = 716, + kSYS_dl_get_info_2 = 717, + kSYS_acinfo_add = 718, + kSYS_acinfo_delete = 719, + kSYS_acinfo_get_all_for_coredump = 720, + kSYS_ampr_ctrl_debug = 721, + kSYS_workspace_ctrl = 722, +}; +} // namespace orbis diff --git a/orbis-kernel/include/orbis/sys/sysentry.hpp b/orbis-kernel/include/orbis/sys/sysentry.hpp new file mode 100644 index 000000000..8858ec7d6 --- /dev/null +++ b/orbis-kernel/include/orbis/sys/sysentry.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include "orbis-config.hpp" +#include "orbis/thread/sysent.hpp" + +namespace orbis { +extern sysentvec freebsd9_sysvec; +extern sysentvec freebsd11_sysvec; +extern sysentvec ps4_sysvec; +extern sysentvec ps5_sysvec; + +struct Thread; +void syscall_entry(Thread *thread); +const char *getSysentName(SysResult (*sysent)(Thread *, uint64_t *)); +} // namespace orbis diff --git a/orbis-kernel/include/orbis/sys/sysproto.hpp b/orbis-kernel/include/orbis/sys/sysproto.hpp new file mode 100644 index 000000000..f3b5acdcc --- /dev/null +++ b/orbis-kernel/include/orbis/sys/sysproto.hpp @@ -0,0 +1,593 @@ +#include +#include +#include + +namespace orbis { +using acl_type_t = sint; +using key_t = sint; +using semid_t = uint64_t; +using cpusetid_t = sint; +using cpuwhich_t = sint; +using cpulevel_t = sint; +using SceKernelModule = ModuleHandle; + +struct ModuleInfo; +struct ModuleInfoEx; + +struct stack_t; + +SysResult nosys(Thread *thread); + +SysResult sys_exit(Thread *thread, sint status); +SysResult sys_fork(Thread *thread); +SysResult sys_read(Thread *thread, sint fd, ptr buf, size_t nbyte); +SysResult sys_write(Thread *thread, sint fd, ptr buf, size_t nbyte); +SysResult sys_open(Thread *thread, ptr path, sint flags, sint mode); +SysResult sys_close(Thread *thread, sint fd); +SysResult sys_wait4(Thread *thread, sint pid, ptr status, sint options, ptr rusage); +SysResult sys_link(Thread *thread, ptr path, ptr link); +SysResult sys_unlink(Thread *thread, ptr path); +SysResult sys_chdir(Thread *thread, ptr path); +SysResult sys_fchdir(Thread *thread, sint fd); +SysResult sys_mknod(Thread *thread, ptr path, sint mode, sint dev); +SysResult sys_chmod(Thread *thread, ptr path, sint mode); +SysResult sys_chown(Thread *thread, ptr path, sint uid, sint gid); +SysResult sys_obreak(Thread *thread, ptr nsize); +SysResult sys_getpid(Thread *thread); +SysResult sys_mount(Thread *thread, ptr type, ptr path, sint flags, caddr_t data); +SysResult sys_unmount(Thread *thread, ptr path, sint flags); +SysResult sys_setuid(Thread *thread, uid_t uid); +SysResult sys_getuid(Thread *thread); +SysResult sys_geteuid(Thread *thread); +SysResult sys_ptrace(Thread *thread, sint req, pid_t pid, caddr_t addr, sint data); +SysResult sys_recvmsg(Thread *thread, sint s, ptr msg, sint flags); +SysResult sys_sendmsg(Thread *thread, sint s, ptr msg, sint flags); +SysResult sys_recvfrom(Thread *thread, sint s, caddr_t buf, size_t len, sint flags, ptr from, ptr fromlenaddr); +SysResult sys_accept(Thread *thread, sint s, ptr from, ptr fromlenaddr); +SysResult sys_getpeername(Thread *thread, sint fdes, ptr asa, ptr alen); +SysResult sys_getsockname(Thread *thread, sint fdes, ptr asa, ptr alen); +SysResult sys_access(Thread *thread, ptr path, sint flags); +SysResult sys_chflags(Thread *thread, ptr path, sint flags); +SysResult sys_fchflags(Thread *thread, sint fd, sint flags); +SysResult sys_sync(Thread *thread); +SysResult sys_kill(Thread *thread, sint pid, sint signum); +SysResult sys_getppid(Thread *thread); +SysResult sys_dup(Thread *thread, uint fd); +SysResult sys_pipe(Thread *thread); +SysResult sys_getegid(Thread *thread); +SysResult sys_profil(Thread *thread, caddr_t samples, size_t size, size_t offset, uint scale); +SysResult sys_ktrace(Thread *thread, ptr fname, sint ops, sint facs, sint pit); +SysResult sys_getgid(Thread *thread); +SysResult sys_getlogin(Thread *thread, ptr namebuf, uint namelen); +SysResult sys_setlogin(Thread *thread, ptr namebuf); +SysResult sys_acct(Thread *thread, ptr path); +SysResult sys_sigaltstack(Thread *thread, ptr ss, ptr oss); +SysResult sys_ioctl(Thread *thread, sint fd, ulong com, caddr_t data); +SysResult sys_reboot(Thread *thread, sint opt); +SysResult sys_revoke(Thread *thread, ptr path); +SysResult sys_symlink(Thread *thread, ptr path, ptr link); +SysResult sys_readlink(Thread *thread, ptr path, ptr buf, size_t count); +SysResult sys_execve(Thread *thread, ptr fname, ptr> argv, ptr> envv); +SysResult sys_umask(Thread *thread, sint newmask); +SysResult sys_chroot(Thread *thread, ptr path); +SysResult sys_msync(Thread *thread, ptr addr, size_t len, sint flags); +SysResult sys_vfork(Thread *thread); +SysResult sys_sbrk(Thread *thread, sint incr); +SysResult sys_sstk(Thread *thread, sint incr); +SysResult sys_ovadvise(Thread *thread, sint anom); +SysResult sys_munmap(Thread *thread, ptr addr, size_t len); +SysResult sys_mprotect(Thread *thread, ptr addr, size_t len, sint prot); +SysResult sys_madvise(Thread *thread, ptr addr, size_t len, sint behav); +SysResult sys_mincore(Thread *thread, ptr addr, size_t len, ptr vec); +SysResult sys_getgroups(Thread *thread, uint gidsetsize, ptr gidset); +SysResult sys_setgroups(Thread *thread, uint gidsetsize, ptr gidset); +SysResult sys_getpgrp(Thread *thread); +SysResult sys_setpgid(Thread *thread, sint pid, sint pgid); +SysResult sys_setitimer(Thread *thread, uint which, ptr itv, ptr oitv); +SysResult sys_swapon(Thread *thread, ptr name); +SysResult sys_getitimer(Thread *thread, uint which, ptr itv); +SysResult sys_getdtablesize(Thread *thread); +SysResult sys_dup2(Thread *thread, uint from, uint to); +SysResult sys_fcntl(Thread *thread, sint fd, sint cmd, slong arg); +SysResult sys_select(Thread *thread, sint nd, ptr in, ptr out, ptr ex, ptr tv); +SysResult sys_fsync(Thread *thread, sint fd); +SysResult sys_setpriority(Thread *thread, sint which, sint who, sint prio); +SysResult sys_socket(Thread *thread, sint domain, sint type, sint protocol); +SysResult sys_connect(Thread *thread, sint s, caddr_t name, sint namelen); +SysResult sys_getpriority(Thread *thread, sint which, sint who); +SysResult sys_bind(Thread *thread, sint s, caddr_t name, sint namelen); +SysResult sys_setsockopt(Thread *thread, sint s, sint level, sint name, caddr_t val, sint valsize); +SysResult sys_listen(Thread *thread, sint s, sint backlog); +SysResult sys_gettimeofday(Thread *thread, ptr tp, ptr tzp); +SysResult sys_getrusage(Thread *thread, sint who, ptr rusage); +SysResult sys_getsockopt(Thread *thread, sint s, sint level, sint name, caddr_t val, ptr avalsize); +SysResult sys_readv(Thread *thread, sint fd, ptr iovp, uint iovcnt); +SysResult sys_writev(Thread *thread, sint fd, ptr iovp, uint iovcnt); +SysResult sys_settimeofday(Thread *thread, ptr tp, ptr tzp); +SysResult sys_fchown(Thread *thread, sint fd, sint uid, sint gid); +SysResult sys_fchmod(Thread *thread, sint fd, sint mode); +SysResult sys_setreuid(Thread *thread, sint ruid, sint euid); +SysResult sys_setregid(Thread *thread, sint rgid, sint egid); +SysResult sys_rename(Thread *thread, ptr from, ptr to); +SysResult sys_flock(Thread *thread, sint fd, sint how); +SysResult sys_mkfifo(Thread *thread, ptr path, sint mode); +SysResult sys_sendto(Thread *thread, sint s, caddr_t buf, size_t len, sint flags, caddr_t to, sint tolen); +SysResult sys_shutdown(Thread *thread, sint s, sint how); +SysResult sys_socketpair(Thread *thread, sint domain, sint type, sint protocol, ptr rsv); +SysResult sys_mkdir(Thread *thread, ptr path, sint mode); +SysResult sys_rmdir(Thread *thread, ptr path); +SysResult sys_utimes(Thread *thread, ptr path, ptr tptr); +SysResult sys_adjtime(Thread *thread, ptr delta, ptr olddelta); +SysResult sys_setsid(Thread *thread); +SysResult sys_quotactl(Thread *thread, ptr path, sint cmd, sint uid, caddr_t arg); +SysResult sys_nlm_syscall(Thread *thread, sint debug_level, sint grace_period, sint addr_count, ptr> addrs); +SysResult sys_nfssvc(Thread *thread, sint flag, caddr_t argp); +SysResult sys_lgetfh(Thread *thread, ptr fname, ptr fhp); +SysResult sys_getfh(Thread *thread, ptr fname, ptr fhp); +SysResult sys_sysarch(Thread *thread, sint op, ptr parms); +SysResult sys_rtprio(Thread *thread, sint function, pid_t pid, ptr rtp); +SysResult sys_semsys(Thread *thread, sint which, sint a2, sint a3, sint a4, sint a5); +SysResult sys_msgsys(Thread *thread, sint which, sint a2, sint a3, sint a4, sint a5, sint a6); +SysResult sys_shmsys(Thread *thread, sint which, sint a2, sint a3, sint a4); +SysResult sys_freebsd6_pread(Thread *thread, sint fd, ptr buf, size_t nbyte, sint pad, off_t offset); +SysResult sys_freebsd6_pwrite(Thread *thread, sint fd, ptr buf, size_t nbyte, sint pad, off_t offset); +SysResult sys_setfib(Thread *thread, sint fib); +SysResult sys_ntp_adjtime(Thread *thread, ptr tp); +SysResult sys_setgid(Thread *thread, gid_t gid); +SysResult sys_setegid(Thread *thread, gid_t egid); +SysResult sys_seteuid(Thread *thread, uid_t euid); +SysResult sys_stat(Thread *thread, ptr path, ptr ub); +SysResult sys_fstat(Thread *thread, sint fd, ptr ub); +SysResult sys_lstat(Thread *thread, ptr path, ptr ub); +SysResult sys_pathconf(Thread *thread, ptr path, sint name); +SysResult sys_fpathconf(Thread *thread, sint fd, sint name); +SysResult sys_getrlimit(Thread *thread, uint which, ptr rlp); +SysResult sys_setrlimit(Thread *thread, uint which, ptr rlp); +SysResult sys_getdirentries(Thread *thread, sint fd, ptr buf, uint count, ptr basep); +SysResult sys_freebsd6_mmap(Thread *thread, caddr_t addr, size_t len, sint prot, sint flags, sint fd, sint pad, off_t pos); +SysResult sys_freebsd6_lseek(Thread *thread, sint fd, sint pad, off_t offset, sint whence); +SysResult sys_freebsd6_truncate(Thread *thread, ptr path, sint pad, off_t length); +SysResult sys_freebsd6_ftruncate(Thread *thread, sint fd, sint pad, off_t length); +SysResult sys___sysctl(Thread *thread, ptr name, uint namelen, ptr old, ptr oldenp, ptr new_, size_t newlen); +SysResult sys_mlock(Thread *thread, ptr addr, size_t len); +SysResult sys_munlock(Thread *thread, ptr addr, size_t len); +SysResult sys_undelete(Thread *thread, ptr path); +SysResult sys_futimes(Thread *thread, sint fd, ptr tptr); +SysResult sys_getpgid(Thread *thread, pid_t pid); +SysResult sys_poll(Thread *thread, ptr fds, uint nfds, sint timeout); +SysResult sys_semget(Thread *thread, key_t key, sint nsems, sint semflg); +SysResult sys_semop(Thread *thread, sint semid, ptr sops, size_t nspos); +SysResult sys_msgget(Thread *thread, key_t key, sint msgflg); +SysResult sys_msgsnd(Thread *thread, sint msqid, ptr msgp, size_t msgsz, sint msgflg); +SysResult sys_msgrcv(Thread *thread, sint msqid, ptr msgp, size_t msgsz, slong msgtyp, sint msgflg); +SysResult sys_shmat(Thread *thread, sint shmid, ptr shmaddr, sint shmflg); +SysResult sys_shmdt(Thread *thread, ptr shmaddr); +SysResult sys_shmget(Thread *thread, key_t key, size_t size, sint shmflg); +SysResult sys_clock_gettime(Thread *thread, clockid_t clock_id, ptr tp); +SysResult sys_clock_settime(Thread *thread, clockid_t clock_id, ptr tp); +SysResult sys_clock_getres(Thread *thread, clockid_t clock_id, ptr tp); +SysResult sys_ktimer_create(Thread *thread, clockid_t clock_id, ptr evp, ptr timerid); +SysResult sys_ktimer_delete(Thread *thread, sint timerid); +SysResult sys_ktimer_settime(Thread *thread, sint timerid, sint flags, ptr value, ptr ovalue); +SysResult sys_ktimer_gettime(Thread *thread, sint timerid, ptr value); +SysResult sys_ktimer_getoverrun(Thread *thread, sint timerid); +SysResult sys_nanosleep(Thread *thread, ptr rqtp, ptr rmtp); +SysResult sys_ntp_gettime(Thread *thread, ptr ntvp); +SysResult sys_minherit(Thread *thread, ptr addr, size_t len, sint inherit); +SysResult sys_rfork(Thread *thread, sint flags); +SysResult sys_openbsd_poll(Thread *thread, ptr fds, uint nfds, sint timeout); +SysResult sys_issetugid(Thread *thread); +SysResult sys_lchown(Thread *thread, ptr path, sint uid, sint gid); +SysResult sys_aio_read(Thread *thread, ptr aiocbp); +SysResult sys_aio_write(Thread *thread, ptr aiocbp); +SysResult sys_lio_listio(Thread *thread, sint mode, ptr> aiocbp, sint nent, ptr sig); +SysResult sys_getdents(Thread *thread, sint fd, ptr buf, size_t count); +SysResult sys_lchmod(Thread *thread, ptr path, mode_t mode); +SysResult sys_lutimes(Thread *thread, ptr path, ptr tptr); +SysResult sys_nstat(Thread *thread, ptr path, ptr ub); +SysResult sys_nfstat(Thread *thread, sint fd, ptr sb); +SysResult sys_nlstat(Thread *thread, ptr path, ptr ub); +SysResult sys_preadv(Thread *thread, sint fd, ptr iovp, uint iovcnt, off_t offset); +SysResult sys_pwritev(Thread *thread, sint fd, ptr iovp, uint iovcnt, off_t offset); +SysResult sys_fhopen(Thread *thread, ptr u_fhp, sint flags); +SysResult sys_fhstat(Thread *thread, ptr u_fhp, ptr sb); +SysResult sys_modnext(Thread *thread, sint modid); +SysResult sys_modstat(Thread *thread, sint modid, ptr stat); +SysResult sys_modfnext(Thread *thread, sint modid); +SysResult sys_modfind(Thread *thread, ptr name); +SysResult sys_kldload(Thread *thread, ptr file); +SysResult sys_kldunload(Thread *thread, sint fileid); +SysResult sys_kldfind(Thread *thread, ptr name); +SysResult sys_kldnext(Thread *thread, sint fileid); +SysResult sys_kldstat(Thread *thread, sint fileid, ptr stat); +SysResult sys_kldfirstmod(Thread *thread, sint fileid); +SysResult sys_getsid(Thread *thread, pid_t pid); +SysResult sys_setresuid(Thread *thread, uid_t ruid, uid_t euid, uid_t suid); +SysResult sys_setresgid(Thread *thread, gid_t rgid, gid_t egid, gid_t sgid); +SysResult sys_aio_return(Thread *thread, ptr aiocbp); +SysResult sys_aio_suspend(Thread *thread, ptr aiocbp, sint nent, ptr timeout); +SysResult sys_aio_cancel(Thread *thread, sint fd, ptr aiocbp); +SysResult sys_aio_error(Thread *thread, ptr aiocbp); +SysResult sys_oaio_read(Thread *thread, ptr aiocbp); +SysResult sys_oaio_write(Thread *thread, ptr aiocbp); +SysResult sys_olio_listio(Thread *thread, sint mode, ptr> acb_list, sint nent, ptr sig); +SysResult sys_yield(Thread *thread); +SysResult sys_mlockall(Thread *thread, sint how); +SysResult sys_munlockall(Thread *thread); +SysResult sys___getcwd(Thread *thread, ptr buf, uint buflen); +SysResult sys_sched_setparam(Thread *thread, pid_t pid, ptr param); +SysResult sys_sched_getparam(Thread *thread, pid_t pid, ptr param); +SysResult sys_sched_setscheduler(Thread *thread, pid_t pid, sint policy, ptr param); +SysResult sys_sched_getscheduler(Thread *thread, pid_t pid); +SysResult sys_sched_yield(Thread *thread); +SysResult sys_sched_get_priority_max(Thread *thread, sint policy); +SysResult sys_sched_get_priority_min(Thread *thread, sint policy); +SysResult sys_sched_rr_get_interval(Thread *thread, pid_t pid, ptr interval); +SysResult sys_utrace(Thread *thread, ptr addr, size_t len); +SysResult sys_kldsym(Thread *thread, sint fileid, sint cmd, ptr data); +SysResult sys_jail(Thread *thread, ptr jail); +SysResult sys_nnpfs_syscall(Thread *thread, sint operation, ptr a_pathP, sint opcode, ptr a_paramsP, sint a_followSymlinks); +SysResult sys_sigprocmask(Thread *thread, sint how, ptr set, ptr oset); +SysResult sys_sigsuspend(Thread *thread, ptr set); +SysResult sys_sigpending(Thread *thread, ptr set); +SysResult sys_sigtimedwait(Thread *thread, ptr set, ptr info, ptr timeout); +SysResult sys_sigwaitinfo(Thread *thread, ptr set, ptr info); +SysResult sys___acl_get_file(Thread *thread, ptr path, acl_type_t type, ptr aclp); +SysResult sys___acl_set_file(Thread *thread, ptr path, acl_type_t type, ptr aclp); +SysResult sys___acl_get_fd(Thread *thread, sint filedes, acl_type_t type, ptr aclp); +SysResult sys___acl_set_fd(Thread *thread, sint filedes, acl_type_t type, ptr aclp); +SysResult sys___acl_delete_file(Thread *thread, ptr path, acl_type_t type); +SysResult sys___acl_delete_fd(Thread *thread, sint filedes, acl_type_t type); +SysResult sys___acl_aclcheck_file(Thread *thread, ptr path, acl_type_t type, ptr aclp); +SysResult sys___acl_aclcheck_fd(Thread *thread, sint filedes, acl_type_t type, ptr aclp); +SysResult sys_extattrctl(Thread *thread, ptr path, char cmd, ptr filename, sint attrnamespace, ptr attrname); +SysResult sys_extattr_set_file(Thread *thread, ptr path, sint attrnamespace, ptr filename, ptr data, size_t nbytes); +SysResult sys_extattr_get_file(Thread *thread, ptr path, sint attrnamespace, ptr filename, ptr data, size_t nbytes); +SysResult sys_extattr_delete_file(Thread *thread, ptr path, sint attrnamespace, ptr attrname); +SysResult sys_aio_waitcomplete(Thread *thread, ptr> aiocbp, ptr timeout); +SysResult sys_getresuid(Thread *thread, ptr ruid, ptr euid, ptr suid); +SysResult sys_getresgid(Thread *thread, ptr rgid, ptr egid, ptr sgid); +SysResult sys_kqueue(Thread *thread); +SysResult sys_kevent(Thread *thread, sint fd, ptr changelist, sint nchanges, ptr eventlist, sint nevents, ptr timeout); +SysResult sys_extattr_set_fd(Thread *thread, sint fd, sint attrnamespace, ptr attrname, ptr data, size_t nbytes); +SysResult sys_extattr_get_fd(Thread *thread, sint fd, sint attrnamespace, ptr attrname, ptr data, size_t nbytes); +SysResult sys_extattr_delete_fd(Thread *thread, sint fd, sint attrnamespace, ptr attrname); +SysResult sys___setugid(Thread *thread, sint flags); +SysResult sys_eaccess(Thread *thread, ptr path, sint flags); +SysResult sys_afs3_syscall(Thread *thread, slong syscall, slong param1, slong param2, slong param3, slong param4, slong param5, slong param6); +SysResult sys_nmount(Thread *thread, ptr iovp, uint iovcnt, sint flags); +SysResult sys___mac_get_proc(Thread *thread, ptr mac_p); +SysResult sys___mac_set_proc(Thread *thread, ptr mac_p); +SysResult sys___mac_get_fd(Thread *thread, sint fd, ptr mac_p); +SysResult sys___mac_get_file(Thread *thread, ptr path, ptr mac_p); +SysResult sys___mac_set_fd(Thread *thread, sint fd, ptr mac_p); +SysResult sys___mac_set_file(Thread *thread, ptr path, ptr mac_p); +SysResult sys_kenv(Thread *thread, sint what, ptr name, ptr value, sint len); +SysResult sys_lchflags(Thread *thread, ptr path, sint flags); +SysResult sys_uuidgen(Thread *thread, ptr store, sint count); +SysResult sys_sendfile(Thread *thread, sint fd, sint s, off_t offset, size_t nbytes, ptr hdtr, ptr sbytes, sint flags); +SysResult sys_mac_syscall(Thread *thread, ptr policy, sint call, ptr arg); +SysResult sys_getfsstat(Thread *thread, ptr buf, slong bufsize, sint flags); +SysResult sys_statfs(Thread *thread, ptr path, ptr buf); +SysResult sys_fstatfs(Thread *thread, sint fd, ptr buf); +SysResult sys_fhstatfs(Thread *thread, ptr u_fhp, ptr buf); +SysResult sys_ksem_close(Thread *thread, semid_t id); +SysResult sys_ksem_post(Thread *thread, semid_t id); +SysResult sys_ksem_wait(Thread *thread, semid_t id); +SysResult sys_ksem_trywait(Thread *thread, semid_t id); +SysResult sys_ksem_init(Thread *thread, ptr idp, uint value); +SysResult sys_ksem_open(Thread *thread, ptr idp, ptr name, sint oflag, mode_t mode, uint value); +SysResult sys_ksem_unlink(Thread *thread, ptr name); +SysResult sys_ksem_getvalue(Thread *thread, semid_t id, ptr value); +SysResult sys_ksem_destroy(Thread *thread, semid_t id); +SysResult sys___mac_get_pid(Thread *thread, pid_t pid, ptr mac_p); +SysResult sys___mac_get_link(Thread *thread, ptr path_p, ptr mac_p); +SysResult sys___mac_set_link(Thread *thread, ptr path_p, ptr mac_p); +SysResult sys_extattr_set_link(Thread *thread, ptr path, sint attrnamespace, ptr attrname, ptr data, size_t nbytes); +SysResult sys_extattr_get_link(Thread *thread, ptr path, sint attrnamespace, ptr attrname, ptr data, size_t nbytes); +SysResult sys_extattr_delete_link(Thread *thread, ptr path, sint attrnamespace, ptr attrname); +SysResult sys___mac_execve(Thread *thread, ptr fname, ptr> argv, ptr> envv, ptr mac_p); +SysResult sys_sigaction(Thread *thread, sint sig, ptr act, ptr oact); +SysResult sys_sigreturn(Thread *thread, ptr sigcntxp); +SysResult sys_getcontext(Thread *thread, ptr ucp); +SysResult sys_setcontext(Thread *thread, ptr ucp); +SysResult sys_swapcontext(Thread *thread, ptr oucp, ptr ucp); +SysResult sys_swapoff(Thread *thread, ptr name); +SysResult sys___acl_get_link(Thread *thread, ptr path, acl_type_t type, ptr aclp); +SysResult sys___acl_set_link(Thread *thread, ptr path, acl_type_t type, ptr aclp); +SysResult sys___acl_delete_link(Thread *thread, ptr path, acl_type_t type); +SysResult sys___acl_aclcheck_link(Thread *thread, ptr path, acl_type_t type, ptr aclp); +SysResult sys_sigwait(Thread *thread, ptr set, ptr sig); +SysResult sys_thr_create(Thread *thread, ptr ctxt, ptr arg, sint flags); +SysResult sys_thr_exit(Thread *thread, ptr state); +SysResult sys_thr_self(Thread *thread, ptr id); +SysResult sys_thr_kill(Thread *thread, slong id, sint sig); +SysResult sys__umtx_lock(Thread *thread, ptr umtx); +SysResult sys__umtx_unlock(Thread *thread, ptr umtx); +SysResult sys_jail_attach(Thread *thread, sint jid); +SysResult sys_extattr_list_fd(Thread *thread, sint fd, sint attrnamespace, ptr data, size_t nbytes); +SysResult sys_extattr_list_file(Thread *thread, ptr path, sint attrnamespace, ptr data, size_t nbytes); +SysResult sys_extattr_list_link(Thread *thread, ptr path, sint attrnamespace, ptr data, size_t nbytes); +SysResult sys_ksem_timedwait(Thread *thread, semid_t id, ptr abstime); +SysResult sys_thr_suspend(Thread *thread, ptr timeout); +SysResult sys_thr_wake(Thread *thread, slong id); +SysResult sys_kldunloadf(Thread *thread, slong fileid, sint flags); +SysResult sys_audit(Thread *thread, ptr record, uint length); +SysResult sys_auditon(Thread *thread, sint cmd, ptr data, uint length); +SysResult sys_getauid(Thread *thread, ptr auid); +SysResult sys_setauid(Thread *thread, ptr auid); +SysResult sys_getaudit(Thread *thread, ptr auditinfo); +SysResult sys_setaudit(Thread *thread, ptr auditinfo); +SysResult sys_getaudit_addr(Thread *thread, ptr auditinfo_addr, uint length); +SysResult sys_setaudit_addr(Thread *thread, ptr auditinfo_addr, uint length); +SysResult sys_auditctl(Thread *thread, ptr path); +SysResult sys__umtx_op(Thread *thread, ptr obj, sint op, ulong val, ptr uaddr1, ptr uaddr2); +SysResult sys_thr_new(Thread *thread, ptr param, sint param_size); +SysResult sys_sigqueue(Thread *thread, pid_t pid, sint signum, ptr value); +SysResult sys_kmq_open(Thread *thread, ptr path, sint flags, mode_t mode, ptr attr); +SysResult sys_kmq_setattr(Thread *thread, sint mqd, ptr attr, ptr oattr); +SysResult sys_kmq_timedreceive(Thread *thread, sint mqd, ptr msg_ptr, size_t msg_len, ptr msg_prio, ptr abstimeout); +SysResult sys_kmq_timedsend(Thread *thread, sint mqd, ptr msg_ptr, size_t msg_len, ptr msg_prio, ptr abstimeout); +SysResult sys_kmq_notify(Thread *thread, sint mqd, ptr sigev); +SysResult sys_kmq_unlink(Thread *thread, ptr path); +SysResult sys_abort2(Thread *thread, ptr why, sint narg, ptr> args); +SysResult sys_thr_set_name(Thread *thread, slong id, ptr name); +SysResult sys_aio_fsync(Thread *thread, sint op, ptr aiocbp); +SysResult sys_rtprio_thread(Thread *thread, sint function, lwpid_t lwpid, ptr rtp); +SysResult sys_sctp_peeloff(Thread *thread, sint sd, uint32_t name); +SysResult sys_sctp_generic_sendmsg(Thread *thread, sint sd, caddr_t msg, sint mlen, caddr_t to, __socklen_t tolen, ptr sinfo, sint flags); +SysResult sys_sctp_generic_sendmsg_iov(Thread *thread, sint sd, ptr iov, sint iovlen, caddr_t to, __socklen_t tolen, ptr sinfo, sint flags); +SysResult sys_sctp_generic_recvmsg(Thread *thread, sint sd, ptr iov, sint iovlen, caddr_t from, __socklen_t fromlen, ptr sinfo, sint flags); +SysResult sys_pread(Thread *thread, sint fd, ptr buf, size_t nbyte, off_t offset); +SysResult sys_pwrite(Thread *thread, sint fd, ptr buf, size_t nbyte, off_t offset); +SysResult sys_mmap(Thread *thread, caddr_t addr, size_t len, sint prot, sint flags, sint fd, off_t pos); +SysResult sys_lseek(Thread *thread, sint fd, off_t offset, sint whence); +SysResult sys_truncate(Thread *thread, ptr path, off_t length); +SysResult sys_ftruncate(Thread *thread, sint fd, off_t length); +SysResult sys_thr_kill2(Thread *thread, pid_t pid, slong id, sint sig); +SysResult sys_shm_open(Thread *thread, ptr path, sint flags, mode_t mode); +SysResult sys_shm_unlink(Thread *thread, ptr path); +SysResult sys_cpuset(Thread *thread, ptr setid); +SysResult sys_cpuset_setid(Thread *thread, cpuwhich_t which, id_t id, cpusetid_t setid); +SysResult sys_cpuset_getid(Thread *thread, cpulevel_t level, cpuwhich_t which, id_t id, ptr setid); +SysResult sys_cpuset_getaffinity(Thread *thread, cpulevel_t level, cpuwhich_t which, id_t id, size_t cpusetsize, ptr mask); +SysResult sys_cpuset_setaffinity(Thread *thread, cpulevel_t level, cpuwhich_t which, id_t id, size_t cpusetsize, ptr mask); +SysResult sys_faccessat(Thread *thread, sint fd, ptr path, sint mode, sint flag); +SysResult sys_fchmodat(Thread *thread, sint fd, ptr path, mode_t mode, sint flag); +SysResult sys_fchownat(Thread *thread, sint fd, ptr path, uid_t uid, gid_t gid, sint flag); +SysResult sys_fexecve(Thread *thread, sint fd, ptr> argv, ptr> envv); +SysResult sys_fstatat(Thread *thread, sint fd, ptr path, ptr buf, sint flag); +SysResult sys_futimesat(Thread *thread, sint fd, ptr path, ptr times); +SysResult sys_linkat(Thread *thread, sint fd1, ptr path1, sint fd2, ptr path2, sint flag); +SysResult sys_mkdirat(Thread *thread, sint fd, ptr path, mode_t mode); +SysResult sys_mkfifoat(Thread *thread, sint fd, ptr path, mode_t mode); +SysResult sys_mknodat(Thread *thread, sint fd, ptr path, mode_t mode, dev_t dev); +SysResult sys_openat(Thread *thread, sint fd, ptr path, sint flag, mode_t mode); +SysResult sys_readlinkat(Thread *thread, sint fd, ptr path, ptr buf, size_t bufsize); +SysResult sys_renameat(Thread *thread, sint oldfd, ptr old, sint newfd, ptr new_); +SysResult sys_symlinkat(Thread *thread, ptr path1, sint fd, ptr path2); +SysResult sys_unlinkat(Thread *thread, sint fd, ptr path, sint flag); +SysResult sys_posix_openpt(Thread *thread, sint flags); +SysResult sys_gssd_syscall(Thread *thread, ptr path); +SysResult sys_jail_get(Thread *thread, ptr iovp, uint iovcnt, sint flags); +SysResult sys_jail_set(Thread *thread, ptr iovp, uint iovcnt, sint flags); +SysResult sys_jail_remove(Thread *thread, sint jid); +SysResult sys_closefrom(Thread *thread, sint lowfd); +SysResult sys___semctl(Thread *thread, sint semid, sint semnum, sint cmd, ptr arg); +SysResult sys_msgctl(Thread *thread, sint msqid, sint cmd, ptr buf); +SysResult sys_shmctl(Thread *thread, sint shmid, sint cmd, ptr buf); +SysResult sys_lpathconf(Thread *thread, ptr path, sint name); +SysResult sys_cap_new(Thread *thread, sint fd, uint64_t rights); +SysResult sys_cap_getrights(Thread *thread, sint fd, ptr rights); +SysResult sys_cap_enter(Thread *thread); +SysResult sys_cap_getmode(Thread *thread, ptr modep); +SysResult sys_pdfork(Thread *thread, ptr fdp, sint flags); +SysResult sys_pdkill(Thread *thread, sint fd, sint signum); +SysResult sys_pdgetpid(Thread *thread, sint fd, ptr pidp); +SysResult sys_pselect(Thread *thread, sint nd, ptr in, ptr ou, ptr ex, ptr ts, ptr sm); +SysResult sys_getloginclass(Thread *thread, ptr namebuf, size_t namelen); +SysResult sys_setloginclass(Thread *thread, ptr namebuf); +SysResult sys_rctl_get_racct(Thread *thread, ptr inbufp, size_t inbuflen, ptr outbuf, size_t outbuflen); +SysResult sys_rctl_get_rules(Thread *thread, ptr inbufp, size_t inbuflen, ptr outbuf, size_t outbuflen); +SysResult sys_rctl_get_limits(Thread *thread, ptr inbufp, size_t inbuflen, ptr outbuf, size_t outbuflen); +SysResult sys_rctl_add_rule(Thread *thread, ptr inbufp, size_t inbuflen, ptr outbuf, size_t outbuflen); +SysResult sys_rctl_remove_rule(Thread *thread, ptr inbufp, size_t inbuflen, ptr outbuf, size_t outbuflen); +SysResult sys_posix_fallocate(Thread *thread, sint fd, off_t offset, off_t len); +SysResult sys_posix_fadvise(Thread *thread, sint fd, off_t offset, off_t len, sint advice); + +SysResult sys_netcontrol(Thread *thread, sint fd, uint op, ptr buf, uint nbuf); +SysResult sys_netabort(Thread *thread /* TODO */); +SysResult sys_netgetsockinfo(Thread *thread /* TODO */); +SysResult sys_socketex(Thread *thread, ptr name, sint domain, sint type, sint protocol); +SysResult sys_socketclose(Thread *thread /* TODO */); +SysResult sys_netgetiflist(Thread *thread /* TODO */); +SysResult sys_kqueueex(Thread *thread /* TODO */); +SysResult sys_mtypeprotect(Thread *thread /* TODO */); +SysResult sys_regmgr_call(Thread *thread, uint32_t op, uint32_t id, ptr result, ptr value, uint64_t type); +SysResult sys_jitshm_create(Thread *thread /* TODO */); +SysResult sys_jitshm_alias(Thread *thread /* TODO */); +SysResult sys_dl_get_list(Thread *thread /* TODO */); +SysResult sys_dl_get_info(Thread *thread /* TODO */); +SysResult sys_dl_notify_event(Thread *thread /* TODO */); +SysResult sys_evf_create(Thread *thread, ptr name, sint flag, ptr evf); +SysResult sys_evf_delete(Thread *thread, sint fd); +SysResult sys_evf_open(Thread *thread, ptr name); +SysResult sys_evf_close(Thread *thread, sint fd); +SysResult sys_evf_wait(Thread *thread /* TODO */); +SysResult sys_evf_trywait(Thread *thread /* TODO */); +SysResult sys_evf_set(Thread *thread, sint fd); +SysResult sys_evf_clear(Thread *thread, sint fd); +SysResult sys_evf_cancel(Thread *thread, sint fd); +SysResult sys_query_memory_protection(Thread *thread /* TODO */); +SysResult sys_batch_map(Thread *thread /* TODO */); +SysResult sys_osem_create(Thread *thread /* TODO */); +SysResult sys_osem_delete(Thread *thread /* TODO */); +SysResult sys_osem_open(Thread *thread /* TODO */); +SysResult sys_osem_close(Thread *thread /* TODO */); +SysResult sys_osem_wait(Thread *thread /* TODO */); +SysResult sys_osem_trywait(Thread *thread /* TODO */); +SysResult sys_osem_post(Thread *thread /* TODO */); +SysResult sys_osem_cancel(Thread *thread /* TODO */); +SysResult sys_namedobj_create(Thread *thread, ptr name, ptr object, uint64_t type); +SysResult sys_namedobj_delete(Thread *thread /* TODO */); +SysResult sys_set_vm_container(Thread *thread /* TODO */); +SysResult sys_debug_init(Thread *thread /* TODO */); +SysResult sys_suspend_process(Thread *thread, pid_t pid); +SysResult sys_resume_process(Thread *thread, pid_t pid); +SysResult sys_opmc_enable(Thread *thread /* TODO */); +SysResult sys_opmc_disable(Thread *thread /* TODO */); +SysResult sys_opmc_set_ctl(Thread *thread /* TODO */); +SysResult sys_opmc_set_ctr(Thread *thread /* TODO */); +SysResult sys_opmc_get_ctr(Thread *thread /* TODO */); +SysResult sys_budget_create(Thread *thread /* TODO */); +SysResult sys_budget_delete(Thread *thread /* TODO */); +SysResult sys_budget_get(Thread *thread /* TODO */); +SysResult sys_budget_set(Thread *thread /* TODO */); +SysResult sys_virtual_query(Thread *thread, ptr addr, uint64_t unk, ptr info, size_t infosz); +SysResult sys_mdbg_call(Thread *thread /* TODO */); +SysResult sys_obs_sblock_create(Thread *thread /* TODO */); +SysResult sys_obs_sblock_delete(Thread *thread /* TODO */); +SysResult sys_obs_sblock_enter(Thread *thread /* TODO */); +SysResult sys_obs_sblock_exit(Thread *thread /* TODO */); +SysResult sys_obs_sblock_xenter(Thread *thread /* TODO */); +SysResult sys_obs_sblock_xexit(Thread *thread /* TODO */); +SysResult sys_obs_eport_create(Thread *thread /* TODO */); +SysResult sys_obs_eport_delete(Thread *thread /* TODO */); +SysResult sys_obs_eport_trigger(Thread *thread /* TODO */); +SysResult sys_obs_eport_open(Thread *thread /* TODO */); +SysResult sys_obs_eport_close(Thread *thread /* TODO */); +SysResult sys_is_in_sandbox(Thread *thread /* TODO */); +SysResult sys_dmem_container(Thread *thread); +SysResult sys_get_authinfo(Thread *thread, pid_t pid, ptr info); +SysResult sys_mname(Thread *thread, ptr address, uint64_t length, ptr name); +SysResult sys_dynlib_dlopen(Thread *thread /* TODO */); +SysResult sys_dynlib_dlclose(Thread *thread /* TODO */); +SysResult sys_dynlib_dlsym(Thread *thread, SceKernelModule handle, ptr symbol, ptr> addrp); +SysResult sys_dynlib_get_list(Thread *thread, ptr pArray, size_t numArray, ptr pActualNum); +SysResult sys_dynlib_get_info(Thread *thread, SceKernelModule handle, ptr pInfo); +SysResult sys_dynlib_load_prx(Thread *thread, ptr name, uint64_t arg1, ptr pHandle, uint64_t arg3); +SysResult sys_dynlib_unload_prx(Thread *thread, SceKernelModule handle /* TODO*/); +SysResult sys_dynlib_do_copy_relocations(Thread *thread); +SysResult sys_dynlib_prepare_dlclose(Thread *thread /* TODO */); +SysResult sys_dynlib_get_proc_param(Thread *thread, ptr> procParam, ptr procParamSize); +SysResult sys_dynlib_process_needed_and_relocate(Thread *thread); +SysResult sys_sandbox_path(Thread *thread /* TODO */); +SysResult sys_mdbg_service(Thread *thread, uint32_t op, ptr arg0, ptr arg1); +SysResult sys_randomized_path(Thread *thread /* TODO */); +SysResult sys_rdup(Thread *thread /* TODO */); +SysResult sys_dl_get_metadata(Thread *thread /* TODO */); +SysResult sys_workaround8849(Thread *thread /* TODO */); +SysResult sys_is_development_mode(Thread *thread /* TODO */); +SysResult sys_get_self_auth_info(Thread *thread /* TODO */); +SysResult sys_dynlib_get_info_ex(Thread *thread, SceKernelModule handle, ptr unk, ptr destModuleInfoEx); +SysResult sys_budget_getid(Thread *thread); +SysResult sys_budget_get_ptype(Thread *thread, sint budgetId); +SysResult sys_get_paging_stats_of_all_threads(Thread *thread /* TODO */); +SysResult sys_get_proc_type_info(Thread *thread, ptr destProcessInfo); +SysResult sys_get_resident_count(Thread *thread, pid_t pid); +SysResult sys_prepare_to_suspend_process(Thread *thread, pid_t pid); +SysResult sys_get_resident_fmem_count(Thread *thread, pid_t pid); +SysResult sys_thr_get_name(Thread *thread, lwpid_t lwpid); +SysResult sys_set_gpo(Thread *thread /* TODO */); +SysResult sys_get_paging_stats_of_all_objects(Thread *thread /* TODO */); +SysResult sys_test_debug_rwmem(Thread *thread /* TODO */); +SysResult sys_free_stack(Thread *thread /* TODO */); +SysResult sys_suspend_system(Thread *thread /* TODO */); +SysResult sys_ipmimgr_call(Thread *thread, uint64_t id, uint64_t arg2, ptr result, ptr params, uint64_t arg5, uint64_t arg6); +SysResult sys_get_gpo(Thread *thread /* TODO */); +SysResult sys_get_vm_map_timestamp(Thread *thread /* TODO */); +SysResult sys_opmc_set_hw(Thread *thread /* TODO */); +SysResult sys_opmc_get_hw(Thread *thread /* TODO */); +SysResult sys_get_cpu_usage_all(Thread *thread /* TODO */); +SysResult sys_mmap_dmem(Thread *thread /* TODO */); +SysResult sys_physhm_open(Thread *thread /* TODO */); +SysResult sys_physhm_unlink(Thread *thread /* TODO */); +SysResult sys_resume_internal_hdd(Thread *thread /* TODO */); +SysResult sys_thr_suspend_ucontext(Thread *thread /* TODO */); +SysResult sys_thr_resume_ucontext(Thread *thread /* TODO */); +SysResult sys_thr_get_ucontext(Thread *thread /* TODO */); +SysResult sys_thr_set_ucontext(Thread *thread /* TODO */); +SysResult sys_set_timezone_info(Thread *thread /* TODO */); +SysResult sys_set_phys_fmem_limit(Thread *thread /* TODO */); +SysResult sys_utc_to_localtime(Thread *thread /* TODO */); +SysResult sys_localtime_to_utc(Thread *thread /* TODO */); +SysResult sys_set_uevt(Thread *thread /* TODO */); +SysResult sys_get_cpu_usage_proc(Thread *thread /* TODO */); +SysResult sys_get_map_statistics(Thread *thread /* TODO */); +SysResult sys_set_chicken_switches(Thread *thread /* TODO */); +SysResult sys_extend_page_table_pool(Thread *thread); +SysResult sys_extend_page_table_pool2(Thread *thread); +SysResult sys_get_kernel_mem_statistics(Thread *thread /* TODO */); +SysResult sys_get_sdk_compiled_version(Thread *thread /* TODO */); +SysResult sys_app_state_change(Thread *thread /* TODO */); +SysResult sys_dynlib_get_obj_member(Thread *thread, SceKernelModule handle, uint64_t index, ptr> addrp); +SysResult sys_budget_get_ptype_of_budget(Thread *thread /* TODO */); +SysResult sys_prepare_to_resume_process(Thread *thread /* TODO */); +SysResult sys_process_terminate(Thread *thread /* TODO */); +SysResult sys_blockpool_open(Thread *thread /* TODO */); +SysResult sys_blockpool_map(Thread *thread /* TODO */); +SysResult sys_blockpool_unmap(Thread *thread /* TODO */); +SysResult sys_dynlib_get_info_for_libdbg(Thread *thread /* TODO */); +SysResult sys_blockpool_batch(Thread *thread /* TODO */); +SysResult sys_fdatasync(Thread *thread /* TODO */); +SysResult sys_dynlib_get_list2(Thread *thread /* TODO */); +SysResult sys_dynlib_get_info2(Thread *thread /* TODO */); +SysResult sys_aio_submit(Thread *thread /* TODO */); +SysResult sys_aio_multi_delete(Thread *thread /* TODO */); +SysResult sys_aio_multi_wait(Thread *thread /* TODO */); +SysResult sys_aio_multi_poll(Thread *thread /* TODO */); +SysResult sys_aio_get_data(Thread *thread /* TODO */); +SysResult sys_aio_multi_cancel(Thread *thread /* TODO */); +SysResult sys_get_bio_usage_all(Thread *thread /* TODO */); +SysResult sys_aio_create(Thread *thread /* TODO */); +SysResult sys_aio_submit_cmd(Thread *thread /* TODO */); +SysResult sys_aio_init(Thread *thread /* TODO */); +SysResult sys_get_page_table_stats(Thread *thread /* TODO */); +SysResult sys_dynlib_get_list_for_libdbg(Thread *thread /* TODO */); +SysResult sys_blockpool_move(Thread *thread /* TODO */); +SysResult sys_virtual_query_all(Thread *thread /* TODO */); +SysResult sys_reserve_2mb_page(Thread *thread /* TODO */); +SysResult sys_cpumode_yield(Thread *thread /* TODO */); + +SysResult sys_wait6(Thread *thread /* TODO */); +SysResult sys_cap_rights_limit(Thread *thread /* TODO */); +SysResult sys_cap_ioctls_limit(Thread *thread /* TODO */); +SysResult sys_cap_ioctls_get(Thread *thread /* TODO */); +SysResult sys_cap_fcntls_limit(Thread *thread /* TODO */); +SysResult sys_cap_fcntls_get(Thread *thread /* TODO */); +SysResult sys_bindat(Thread *thread /* TODO */); +SysResult sys_connectat(Thread *thread /* TODO */); +SysResult sys_chflagsat(Thread *thread /* TODO */); +SysResult sys_accept4(Thread *thread /* TODO */); +SysResult sys_pipe2(Thread *thread /* TODO */); +SysResult sys_aio_mlock(Thread *thread /* TODO */); +SysResult sys_procctl(Thread *thread /* TODO */); +SysResult sys_ppoll(Thread *thread /* TODO */); +SysResult sys_futimens(Thread *thread /* TODO */); +SysResult sys_utimensat(Thread *thread /* TODO */); +SysResult sys_numa_getaffinity(Thread *thread /* TODO */); +SysResult sys_numa_setaffinity(Thread *thread /* TODO */); +SysResult sys_apr_submit(Thread *thread /* TODO */); +SysResult sys_apr_resolve(Thread *thread /* TODO */); +SysResult sys_apr_stat(Thread *thread /* TODO */); +SysResult sys_apr_wait(Thread *thread /* TODO */); +SysResult sys_apr_ctrl(Thread *thread /* TODO */); +SysResult sys_get_phys_page_size(Thread *thread /* TODO */); +SysResult sys_begin_app_mount(Thread *thread /* TODO */); +SysResult sys_end_app_mount(Thread *thread /* TODO */); +SysResult sys_fsc2h_ctrl(Thread *thread /* TODO */); +SysResult sys_streamwrite(Thread *thread /* TODO */); +SysResult sys_app_save(Thread *thread /* TODO */); +SysResult sys_app_restore(Thread *thread /* TODO */); +SysResult sys_saved_app_delete(Thread *thread /* TODO */); +SysResult sys_get_ppr_sdk_compiled_version(Thread *thread /* TODO */); +SysResult sys_notify_app_event(Thread *thread /* TODO */); +SysResult sys_ioreq(Thread *thread /* TODO */); +SysResult sys_openintr(Thread *thread /* TODO */); +SysResult sys_dl_get_info_2(Thread *thread /* TODO */); +SysResult sys_acinfo_add(Thread *thread /* TODO */); +SysResult sys_acinfo_delete(Thread *thread /* TODO */); +SysResult sys_acinfo_get_all_for_coredump(Thread *thread /* TODO */); +SysResult sys_ampr_ctrl_debug(Thread *thread /* TODO */); +SysResult sys_workspace_ctrl(Thread *thread /* TODO */); +} // namespace orbis diff --git a/orbis-kernel/include/orbis/thread.hpp b/orbis-kernel/include/orbis/thread.hpp new file mode 100644 index 000000000..f67cf8e71 --- /dev/null +++ b/orbis-kernel/include/orbis/thread.hpp @@ -0,0 +1,10 @@ +#pragma once + +#include "thread/cpuset.hpp" // IWYU pragma: export +#include "thread/Process.hpp" // IWYU pragma: export +#include "thread/ProcessOps.hpp" // IWYU pragma: export +#include "thread/ProcessState.hpp" // IWYU pragma: export +#include "thread/sysent.hpp" // IWYU pragma: export +#include "thread/Thread.hpp" // IWYU pragma: export +#include "thread/ThreadState.hpp" // IWYU pragma: export +#include "thread/types.hpp" // IWYU pragma: export diff --git a/orbis-kernel/include/orbis/thread/Process.hpp b/orbis-kernel/include/orbis/thread/Process.hpp new file mode 100644 index 000000000..4cb4ae442 --- /dev/null +++ b/orbis-kernel/include/orbis/thread/Process.hpp @@ -0,0 +1,38 @@ +#pragma once +#include "ProcessState.hpp" +#include "orbis-config.hpp" +#include "orbis/module/Module.hpp" +#include "orbis/utils/IdMap.hpp" +#include "orbis/utils/SharedMutex.hpp" +#include "../thread/types.hpp" +#include "../thread/Thread.hpp" + +#include + +namespace orbis { +class KernelContext; +struct Thread; +struct ProcessOps; +struct sysentvec; + +struct Process { + KernelContext *context = nullptr; + pid_t pid = -1; + sysentvec *sysent = nullptr; + ProcessState state = ProcessState::NEW; + Process *parentProcess = nullptr; + shared_mutex mtx; + void (*onSysEnter)(Thread *thread, int id, uint64_t *args, int argsCount) = nullptr; + void (*onSysExit)(Thread *thread, int id, uint64_t *args, int argsCount, SysResult result) = nullptr; + ptr processParam = nullptr; + uint64_t processParamSize = 0; + const ProcessOps *ops = nullptr; + + std::uint64_t nextTlsSlot = 1; + std::uint64_t lastTlsOffset = 0; + + utils::RcIdMap modulesMap; + utils::OwningIdMap threadsMap; + utils::RcIdMap fileDescriptors; +}; +} // namespace orbis diff --git a/orbis-kernel/include/orbis/thread/ProcessOps.hpp b/orbis-kernel/include/orbis/thread/ProcessOps.hpp new file mode 100644 index 000000000..71e420261 --- /dev/null +++ b/orbis-kernel/include/orbis/thread/ProcessOps.hpp @@ -0,0 +1,56 @@ +#pragma once +#include "../error/SysResult.hpp" +#include "../module/ModuleHandle.hpp" +#include "orbis-config.hpp" +#include "../thread/types.hpp" + +namespace orbis { +struct Thread; +struct Module; + +struct ProcessOps { + SysResult (*mmap)(Thread *thread, caddr_t addr, size_t len, sint prot, sint flags, sint fd, off_t pos); + SysResult (*munmap)(Thread *thread, ptr addr, size_t len); + SysResult (*msync)(Thread *thread, ptr addr, size_t len, sint flags); + SysResult (*mprotect)(Thread *thread, ptr addr, size_t len, sint prot); + SysResult (*minherit)(Thread *thread, ptr addr, size_t len, sint inherit); + SysResult (*madvise)(Thread *thread, ptr addr, size_t len, sint behav); + SysResult (*mincore)(Thread *thread, ptr addr, size_t len, ptr vec); + SysResult (*mlock)(Thread *thread, ptr addr, size_t len); + SysResult (*mlockall)(Thread *thread, sint how); + SysResult (*munlockall)(Thread *thread); + SysResult (*munlock)(Thread *thread, ptr addr, size_t len); + SysResult (*virtual_query)(Thread *thread, ptr addr, sint flags, ptr info, ulong infoSize); + + SysResult (*open)(Thread *thread, ptr path, sint flags, sint mode); + SysResult (*close)(Thread *thread, sint fd); + SysResult (*ioctl)(Thread *thread, sint fd, ulong com, caddr_t argp); + SysResult (*write)(Thread *thread, sint fd, ptr data, ulong size); + SysResult (*read)(Thread *thread, sint fd, ptr data, ulong size); + SysResult (*pread)(Thread *thread, sint fd, ptr data, ulong size, ulong offset); + SysResult (*pwrite)(Thread *thread, sint fd, ptr data, ulong size, ulong offset); + SysResult (*lseek)(Thread *thread, sint fd, ulong offset, sint whence); + SysResult (*ftruncate)(Thread *thread, sint fd, off_t length); + SysResult (*truncate)(Thread *thread, ptr path, off_t length); + + SysResult (*dynlib_get_obj_member)(Thread *thread, ModuleHandle handle, uint64_t index, ptr> addrp); + SysResult (*dynlib_dlsym)(Thread *thread, ModuleHandle handle, ptr symbol, ptr> addrp); + SysResult (*dynlib_do_copy_relocations)(Thread *thread); + SysResult (*dynlib_load_prx)(Thread *thread, ptr name, uint64_t arg1, ptr pHandle, uint64_t arg3); + SysResult (*dynlib_unload_prx)(Thread *thread, ModuleHandle handle); + + SysResult (*thr_create)(Thread *thread, ptr ctxt, ptr arg, sint flags); + SysResult (*thr_new)(Thread *thread, ptr param, sint param_size); + SysResult (*thr_exit)(Thread *thread, ptr state); + SysResult (*thr_kill)(Thread *thread, slong id, sint sig); + SysResult (*thr_kill2)(Thread *thread, pid_t pid, slong id, sint sig); + SysResult (*thr_suspend)(Thread *thread, ptr timeout); + SysResult (*thr_wake)(Thread *thread, slong id); + SysResult (*thr_set_name)(Thread *thread, slong id, ptr name); + + SysResult (*exit)(Thread *thread, sint status); + + SysResult (*processNeeded)(Thread *thread); + SysResult (*registerEhFrames)(Thread *thread); +}; +} // namespace orbis diff --git a/orbis-kernel/include/orbis/thread/ProcessState.hpp b/orbis-kernel/include/orbis/thread/ProcessState.hpp new file mode 100644 index 000000000..7329f9861 --- /dev/null +++ b/orbis-kernel/include/orbis/thread/ProcessState.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include + +namespace orbis { +enum class ProcessState : std::uint32_t { + NEW, // In creation + NORMAL, // threads can be run + ZOMBIE +}; +} // namespace orbis diff --git a/orbis-kernel/include/orbis/thread/RegisterId.hpp b/orbis-kernel/include/orbis/thread/RegisterId.hpp new file mode 100644 index 000000000..cda5efc3c --- /dev/null +++ b/orbis-kernel/include/orbis/thread/RegisterId.hpp @@ -0,0 +1,23 @@ +#pragma once + +namespace orbis { +enum class RegisterId { + r15, + r14, + r13, + r12, + r11, + r10, + r9, + r8, + rdi, + rsi, + rbp, + rbx, + rdx, + rcx, + rax, + rsp, + rflags, +}; +} // namespace orbis diff --git a/orbis-kernel/include/orbis/thread/Thread.hpp b/orbis-kernel/include/orbis/thread/Thread.hpp new file mode 100644 index 000000000..cafcc9a8f --- /dev/null +++ b/orbis-kernel/include/orbis/thread/Thread.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include "orbis-config.hpp" +#include "types.hpp" +#include "ThreadState.hpp" + +#include + +namespace orbis { +struct Process; +struct Thread { + std::mutex lock; + Process *tproc = nullptr; + uint64_t retval[2]{}; + void *context{}; + ptr stackStart; + ptr stackEnd; + uint64_t fsBase{}; + uint64_t gsBase{}; + char name[32]; + + uint64_t sigMask[4] = { + 0x7fff'ffff, + 0 + }; + + lwpid_t tid = -1; + ThreadState state = ThreadState::INACTIVE; +}; +} // namespace orbis diff --git a/orbis-kernel/include/orbis/thread/ThreadState.hpp b/orbis-kernel/include/orbis/thread/ThreadState.hpp new file mode 100644 index 000000000..7c898205d --- /dev/null +++ b/orbis-kernel/include/orbis/thread/ThreadState.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace orbis { +enum class ThreadState : std::uint32_t { INACTIVE, INHIBITED, CAN_RUN, RUNQ, RUNNING }; +} // namespace orbis diff --git a/orbis-kernel/include/orbis/thread/cpuset.hpp b/orbis-kernel/include/orbis/thread/cpuset.hpp new file mode 100644 index 000000000..4e417ce92 --- /dev/null +++ b/orbis-kernel/include/orbis/thread/cpuset.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include "orbis-config.hpp" + +namespace orbis { +static constexpr auto NCPUBITS = sizeof(slong) * 8; +static constexpr auto NCPUWORDS = 128 / NCPUBITS; + +struct cpuset { + slong bits[NCPUWORDS]; +}; +} // namespace orbis diff --git a/orbis-kernel/include/orbis/thread/sysent.hpp b/orbis-kernel/include/orbis/thread/sysent.hpp new file mode 100644 index 000000000..01f37e1b3 --- /dev/null +++ b/orbis-kernel/include/orbis/thread/sysent.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include "orbis-config.hpp" + +namespace orbis { +struct Thread; +using sy_call_t = SysResult(Thread *, uint64_t *); + +struct sysent { + sint narg; + sy_call_t *call; +}; + +struct sysentvec { + sint size; + const sysent *table; +}; +} // namespace orbis diff --git a/orbis-kernel/include/orbis/thread/types.hpp b/orbis-kernel/include/orbis/thread/types.hpp new file mode 100644 index 000000000..7f632162a --- /dev/null +++ b/orbis-kernel/include/orbis/thread/types.hpp @@ -0,0 +1,9 @@ +#pragma once +#include "orbis-config.hpp" + +namespace orbis { +using lwpid_t = int32_t; +using pid_t = int64_t; +using uid_t = uint32_t; +using gid_t = uint32_t; +} // namespace orbis diff --git a/orbis-kernel/include/orbis/utils/AtomicOp.hpp b/orbis-kernel/include/orbis/utils/AtomicOp.hpp new file mode 100644 index 000000000..adac73450 --- /dev/null +++ b/orbis-kernel/include/orbis/utils/AtomicOp.hpp @@ -0,0 +1,74 @@ +#pragma once + +#include +#include +#include + +namespace orbis { +inline namespace utils { +// Atomic operation; returns old value, or pair of old value and return value +// (cancel op if evaluates to false) +template > +inline std::conditional_t, T, std::pair> +atomic_fetch_op(std::atomic &v, F func) { + T _new, old = v.load(); + while (true) { + _new = old; + if constexpr (std::is_void_v) { + std::invoke(func, _new); + if (v.compare_exchange_strong(old, _new)) [[likely]] { + return old; + } + } else { + RT ret = std::invoke(func, _new); + if (!ret || v.compare_exchange_strong(old, _new)) [[likely]] { + return {old, std::move(ret)}; + } + } + } +} + +// Atomic operation; returns function result value, function is the lambda +template > +inline RT atomic_op(std::atomic &v, F func) { + T _new, old = v.load(); + while (true) { + _new = old; + if constexpr (std::is_void_v) { + std::invoke(func, _new); + if (v.compare_exchange_strong(old, _new)) [[likely]] { + return; + } + } else { + RT result = std::invoke(func, _new); + if (v.compare_exchange_strong(old, _new)) [[likely]] { + return result; + } + } + } +} + +#if defined(__ATOMIC_HLE_ACQUIRE) && defined(__ATOMIC_HLE_RELEASE) +static constexpr int s_hle_ack = __ATOMIC_SEQ_CST | __ATOMIC_HLE_ACQUIRE; +static constexpr int s_hle_rel = __ATOMIC_SEQ_CST | __ATOMIC_HLE_RELEASE; +#else +static constexpr int s_hle_ack = __ATOMIC_SEQ_CST; +static constexpr int s_hle_rel = __ATOMIC_SEQ_CST; +#endif + +template +inline bool compare_exchange_hle_acq(std::atomic &dest, T &comp, T exch) { + static_assert(sizeof(T) == 4 || sizeof(T) == 8); + static_assert(std::atomic::is_always_lock_free); + return __atomic_compare_exchange(reinterpret_cast(&dest), &comp, &exch, + false, s_hle_ack, s_hle_ack); +} + +template +inline T fetch_add_hle_rel(std::atomic &dest, T value) { + static_assert(sizeof(T) == 4 || sizeof(T) == 8); + static_assert(std::atomic::is_always_lock_free); + return __atomic_fetch_add(reinterpret_cast(&dest), value, s_hle_rel); +} +} // namespace utils +} // namespace orbis diff --git a/orbis-kernel/include/orbis/utils/BitSet.hpp b/orbis-kernel/include/orbis/utils/BitSet.hpp new file mode 100644 index 000000000..4ce028868 --- /dev/null +++ b/orbis-kernel/include/orbis/utils/BitSet.hpp @@ -0,0 +1,104 @@ +#pragma once +#include +#include +#include + +namespace orbis { +inline namespace utils { +template struct BitSet { + using chunk_type = std::uint64_t; + static constexpr auto BitsPerChunk = sizeof(chunk_type) * 8; + static constexpr auto ChunkCount = (Count + BitsPerChunk - 1) / BitsPerChunk; + chunk_type _bits[ChunkCount]{}; + + constexpr std::size_t countr_one() const { + std::size_t result = 0; + for (auto bits : _bits) { + auto count = std::countr_one(bits); + result += count; + + if (count != BitsPerChunk) { + break; + } + } + + return result; + } + + constexpr std::size_t countr_zero(std::size_t offset = 0) const { + std::size_t result = 0; + + if (auto chunkOffset = offset % BitsPerChunk) { + auto count = + std::countr_zero(_bits[offset / BitsPerChunk] >> chunkOffset); + + if (count != BitsPerChunk) { + return count + offset; + } + + offset = (offset + BitsPerChunk - 1) & ~(BitsPerChunk - 1); + } + + for (auto i = offset / BitsPerChunk; i < ChunkCount; ++i) { + auto count = std::countr_zero(_bits[i]); + result += count; + + if (count != BitsPerChunk) { + break; + } + } + /* + for (auto bits : _bits) { + auto count = std::countr_zero(bits); + result += count; + + if (count != BitsPerChunk) { + break; + } + } + */ + + return result + offset; + } + + bool empty() const { + for (auto bits : _bits) { + if (bits != 0) { + return false; + } + } + + return true; + } + + bool full() const { + if constexpr (Count < BitsPerChunk) { + return _bits[0] == (static_cast(1) << Count) - 1; + } + + for (auto bits : _bits) { + if (bits != ~static_cast(0)) { + return false; + } + } + + return true; + } + + constexpr void clear(std::size_t index) { + _bits[index / BitsPerChunk] &= + ~(static_cast(1) << (index % BitsPerChunk)); + } + + constexpr void set(std::size_t index) { + _bits[index / BitsPerChunk] |= static_cast(1) + << (index % BitsPerChunk); + } + + constexpr bool test(std::size_t index) const { + return (_bits[index / BitsPerChunk] & + (static_cast(1) << (index % BitsPerChunk))) != 0; + } +}; +} // namespace utils +} // namespace orbis diff --git a/orbis-kernel/include/orbis/utils/IdMap.hpp b/orbis-kernel/include/orbis/utils/IdMap.hpp new file mode 100644 index 000000000..d4127d9de --- /dev/null +++ b/orbis-kernel/include/orbis/utils/IdMap.hpp @@ -0,0 +1,306 @@ +#pragma once + +#include "BitSet.hpp" +#include "Rc.hpp" + +#include +#include +#include +#include +#include + +namespace orbis { +inline namespace utils { +template + requires(MaxId > MinId) +class RcIdMap { + static constexpr auto ChunkSize = std::min(MaxId - MinId, 64); + static constexpr auto ChunkCount = + (MaxId - MinId + ChunkSize - 1) / ChunkSize; + + struct IdMapChunk { + BitSet mask = {}; + T *objects[ChunkSize]{}; + + ~IdMapChunk() { + std::size_t index = mask.countr_zero(); + + while (index < ChunkSize) { + objects[index]->decRef(); + index = mask.countr_zero(index + 1); + } + } + + std::size_t insert(T *object) { + std::size_t index = mask.countr_one(); + mask.set(index); + objects[index] = object; + + return index; + } + + T *get(std::size_t index) { return objects[index]; } + + void remove(std::size_t index) { + objects[index]->decRef(); + objects[index] = nullptr; + mask.clear(index); + } + }; + + IdMapChunk m_chunks[ChunkCount]{}; + BitSet m_fullChunks; + +public: + static constexpr auto npos = static_cast(~static_cast(0)); + + struct end_iterator {}; + + class iterator { + const IdMapChunk *chunks = nullptr; + std::size_t chunk = 0; + std::size_t index = 0; + + public: + iterator(const IdMapChunk *chunks) : chunks(chunks) { findNext(); } + + iterator &operator++() { + ++index; + findNext(); + return *this; + } + + std::pair operator*() const { + return {static_cast(chunk * ChunkSize + index + MinId), + chunks[chunk].objects[index]}; + } + + bool operator!=(const end_iterator &) const { return chunk < ChunkCount; } + bool operator==(const end_iterator &) const { return chunk >= ChunkCount; } + + private: + void findNext() { + while (chunk < ChunkCount) { + index = chunks[chunk].mask.countr_zero(index); + + if (index < ChunkSize) { + break; + } + + index = 0; + chunk++; + } + } + }; + + void walk(auto cb) { + for (std::size_t chunk = 0; chunk < ChunkCount; ++chunk) { + std::size_t index = m_chunks[chunk].mask.countr_zero(); + + while (index < ChunkSize) { + cb(static_cast(index + chunk * ChunkSize + MinId), + m_chunks[chunk].objects[index]); + + index = m_chunks[chunk].mask.countr_zero(index + 1); + } + } + } + + iterator begin() const { return iterator{m_chunks}; } + + end_iterator end() const { return {}; } + +private: + IdT insert_impl(T *object) { + auto page = m_fullChunks.countr_one(); + + if (page == ChunkCount) { + return npos; + } + + auto index = m_chunks[page].insert(object); + + if (m_chunks[page].mask.full()) { + m_fullChunks.set(page); + } + + return {static_cast(page * ChunkSize + index + MinId)}; + } + +public: + IdT insert(T *object) { + auto result = insert_impl(object); + + if (result != npos) { + object->incRef(); + } + + return result; + } + + IdT insert(const Ref &ref) { return insert(ref.get()); } + + IdT insert(Ref &&ref) { + auto object = ref.release(); + auto result = insert_impl(object); + + if (result == npos) { + object->decRef(); + } + + return result; + } + + T *get(IdT id) { + const auto rawId = static_cast(id) - MinId; + + if (rawId >= MaxId - MinId) { + return nullptr; + } + + const auto chunk = rawId / ChunkSize; + const auto index = rawId % ChunkSize; + + if (!m_chunks[chunk].mask.test(index)) { + return nullptr; + } + + return m_chunks[chunk].get(index); + } + + bool remove(IdT id) { + const auto rawId = static_cast(id) - MinId; + + if (rawId >= MaxId - MinId) { + return false; + } + + const auto chunk = rawId / ChunkSize; + const auto index = rawId % ChunkSize; + + if (!m_chunks[chunk].mask.test(index)) { + return false; + } + + m_chunks[chunk].remove(index); + m_fullChunks.clear(chunk); + return true; + } +}; + +template + requires(MaxId > MinId) +struct OwningIdMap { + static constexpr auto ChunkSize = std::min(MaxId - MinId, 64); + static constexpr auto ChunkCount = + (MaxId - MinId + ChunkSize - 1) / ChunkSize; + + struct IdMapChunk { + BitSet mask = {}; + alignas(T) std::byte objects[sizeof(T) * ChunkSize]; + + ~IdMapChunk() { + std::size_t pageOffset = 0; + + for (auto page : mask._bits) { + auto tmp = page; + + while (true) { + const auto index = std::countr_zero(tmp); + + if (index >= 64) { + break; + } + + tmp &= ~(static_cast(1) << index); + destroy(pageOffset + index); + } + + pageOffset += 64; + } + } + + template + std::pair emplace_new(ArgsT &&...args) { + std::size_t index = mask.countr_one(); + + if (index >= ChunkSize) { + return {}; + } + + mask.set(index); + + return {index, + std::construct_at(get(index), std::forward(args)...)}; + } + + T *get(std::size_t index) { + return reinterpret_cast(objects + sizeof(T) * index); + } + + void destroy(std::size_t index) { + std::destroy_at(get(index)); + mask.clear(index); + } + }; + + IdMapChunk chunks[ChunkCount]{}; + BitSet fullChunks; + + template + requires(std::is_constructible_v) + std::pair emplace(ArgsT &&...args) { + auto page = fullChunks.countr_one(); + + if (page == ChunkCount) { + return {}; + } + + auto newElem = chunks[page].emplace_new(std::forward(args)...); + + if (chunks[page].mask.full()) { + fullChunks.set(page); + } + + return {static_cast(page * ChunkSize + newElem.first + MinId), + newElem.second}; + } + + T *get(IdT id) { + const auto rawId = static_cast(id) - MinId; + const auto chunk = rawId / ChunkSize; + const auto index = rawId % ChunkSize; + + if (chunk >= ChunkCount) { + return nullptr; + } + + if (!chunks[chunk].mask.test(index)) { + return nullptr; + } + + return chunks[chunk].get(index); + } + + bool destroy(IdT id) { + const auto rawId = static_cast(id) - MinId; + const auto chunk = rawId / ChunkSize; + const auto index = rawId % ChunkSize; + + if (chunk >= ChunkCount) { + return false; + } + + if (!chunks[chunk].mask.test(index)) { + return false; + } + + chunks[chunk].destroy(index); + fullChunks.clear(chunk); + return true; + } +}; +} // namespace utils +} // namespace orbis diff --git a/orbis-kernel/include/orbis/utils/LinkedNode.hpp b/orbis-kernel/include/orbis/utils/LinkedNode.hpp new file mode 100644 index 000000000..84f551749 --- /dev/null +++ b/orbis-kernel/include/orbis/utils/LinkedNode.hpp @@ -0,0 +1,48 @@ +#pragma once + +namespace orbis { +inline namespace utils { +template struct LinkedNode { + T object; + LinkedNode *next = nullptr; + LinkedNode *prev = nullptr; + + void insertNext(LinkedNode &other) { + other.next = next; + other.prev = this; + + if (next != nullptr) { + next->prev = &other; + } + + next = &other; + } + + void insertPrev(LinkedNode &other) { + other.next = this; + other.prev = prev; + + if (prev != nullptr) { + prev->next = &other; + } + + prev = &other; + } + + LinkedNode *erase() { + if (prev != nullptr) { + prev->next = next; + } + + if (next != nullptr) { + next->prev = prev; + } + + prev = nullptr; + auto result = next; + next = nullptr; + return result; + } +}; +} // namespace utils +} // namespace orbis diff --git a/orbis-kernel/include/orbis/utils/Logs.hpp b/orbis-kernel/include/orbis/utils/Logs.hpp new file mode 100644 index 000000000..ca1d6480d --- /dev/null +++ b/orbis-kernel/include/orbis/utils/Logs.hpp @@ -0,0 +1,104 @@ +#pragma once +#include +#include +#include + +namespace orbis { +inline namespace logs { +enum class LogLevel : unsigned char { + Always, + Fatal, + Error, + Todo, + Success, + Warning, + Notice, + Trace +}; + +// Currently enabled log level +inline std::atomic logs_level = LogLevel::Notice; + +template struct log_class_string { + static const T &get_object(const void *arg) { + return *static_cast(arg); + } + static void format(std::string &out, const void *arg); +}; + +template <> struct log_class_string { + static void format(std::string &out, const void *arg); +}; + +template +struct log_class_string : log_class_string {}; + +template <> struct log_class_string { + static void format(std::string &out, const void *arg); +}; + +template <> +struct log_class_string : log_class_string {}; + +template <> +struct log_class_string + : log_class_string {}; + +template <> +struct log_class_string : log_class_string {}; + +template +using log_args_t = const void *(&&)[sizeof...(Args) + 1]; + +struct log_type_info { + decltype(&log_class_string::format) log_string; + + template static constexpr log_type_info make() { + return log_type_info{ + &log_class_string::format, + }; + } +}; + +template +constexpr const log_type_info type_info_v[sizeof...(Args) + 1]{ + log_type_info::make>()...}; + +void _orbis_log_print(LogLevel lvl, const char *msg, std::string_view names, + const log_type_info *sup, ...); + +template +void _orbis_log_impl(LogLevel lvl, const char *msg, const char *names, + const Args &...args) { + // Fast filtering + if (logs_level.load(std::memory_order::relaxed) < lvl) + return; + + _orbis_log_print(lvl, msg, names, type_info_v, + static_cast(&args)...); +} + +} // namespace logs +} // namespace orbis + +#define ORBIS_LOG_FATAL(msg, ...) \ + ::orbis::_orbis_log_impl(::orbis::LogLevel::Fatal, (msg), #__VA_ARGS__, \ + ##__VA_ARGS__) +#define ORBIS_LOG_ERROR(msg, ...) \ + ::orbis::_orbis_log_impl(::orbis::LogLevel::Error, (msg), #__VA_ARGS__, \ + ##__VA_ARGS__) +#define ORBIS_LOG_TODO(msg, ...) \ + ::orbis::_orbis_log_impl(::orbis::LogLevel::Todo, (msg), #__VA_ARGS__, \ + ##__VA_ARGS__) +#define ORBIS_LOG_SUCCESS(msg, ...) \ + ::orbis::_orbis_log_impl(::orbis::LogLevel::Success, (msg), #__VA_ARGS__, \ + ##__VA_ARGS__) +#define ORBIS_LOG_WARNING(msg, ...) \ + ::orbis::_orbis_log_impl(::orbis::LogLevel::Warning, (msg), #__VA_ARGS__, \ + ##__VA_ARGS__) +#define ORBIS_LOG_NOTICE(msg, ...) \ + ::orbis::_orbis_log_impl(::orbis::LogLevel::Notice, (msg), #__VA_ARGS__, \ + ##__VA_ARGS__) +#define ORBIS_LOG_TRACE(msg, ...) \ + ::orbis::_orbis_log_impl(::orbis::LogLevel::Trace, (msg), #__VA_ARGS__, \ + ##__VA_ARGS__) diff --git a/orbis-kernel/include/orbis/utils/Rc.hpp b/orbis-kernel/include/orbis/utils/Rc.hpp new file mode 100644 index 000000000..8eb4b25a4 --- /dev/null +++ b/orbis-kernel/include/orbis/utils/Rc.hpp @@ -0,0 +1,124 @@ +#pragma once + +#include +#include +#include +#include + +namespace orbis { +inline namespace utils { +struct RcBase { + std::atomic references{0}; + + virtual ~RcBase() = default; + + void incRef() { + if (references.fetch_add(1, std::memory_order::relaxed) > 512) { + assert(!"too many references"); + } + } + + // returns true if object was destroyed + bool decRef() { + if (references.fetch_sub(1, std::memory_order::relaxed) == 1) { + delete this; + return true; + } + + return false; + } +}; + +template +concept WithRc = requires(T t) { + t.incRef(); + t.decRef(); +}; + +template class Ref { + T *m_ref = nullptr; + +public: + Ref() = default; + + template + requires(std::is_base_of_v) + Ref(OT *ref) : m_ref(ref) { + ref->incRef(); + } + + template + requires(std::is_base_of_v) + Ref(const Ref &other) : m_ref(other.get()) { + if (m_ref != nullptr) { + m_ref->incRef(); + } + } + + template + requires(std::is_base_of_v) + Ref(Ref &&other) : m_ref(other.release()) {} + + Ref(const Ref &other) : m_ref(other.get()) { + if (m_ref != nullptr) { + m_ref->incRef(); + } + } + Ref(Ref &&other) : m_ref(other.release()) {} + + template + requires(std::is_base_of_v) + Ref &operator=(Ref &&other) { + other.swap(*this); + return *this; + } + + template + requires(std::is_base_of_v) + Ref &operator=(OT *other) { + *this = Ref(other); + return *this; + } + + template + requires(std::is_base_of_v) + Ref &operator=(const Ref &other) { + *this = Ref(other); + return *this; + } + + Ref &operator=(const Ref &other) { + *this = Ref(other); + return *this; + } + + Ref &operator=(Ref &&other) { + other.swap(*this); + return *this; + } + + ~Ref() { + if (m_ref != nullptr) { + m_ref->decRef(); + } + } + + void swap(Ref &other) { std::swap(m_ref, other.m_ref); } + T *get() const { return m_ref; } + T *release() { return std::exchange(m_ref, nullptr); } + T *operator->() const { return m_ref; } + explicit operator bool() const { return m_ref != nullptr; } + bool operator==(std::nullptr_t) const { return m_ref == nullptr; } + bool operator!=(std::nullptr_t) const { return m_ref != nullptr; } + auto operator<=>(const T *other) const { return m_ref <=> other; } + auto operator<=>(const Ref &other) const = default; +}; + +template + requires(std::is_constructible_v) +Ref create(ArgsT &&...args) { + auto result = new T(std::forward(args)...); + return Ref(result); +} +} // namespace utils +} // namespace orbis diff --git a/orbis-kernel/include/orbis/utils/SharedMutex.hpp b/orbis-kernel/include/orbis/utils/SharedMutex.hpp new file mode 100644 index 000000000..eddc5cc4a --- /dev/null +++ b/orbis-kernel/include/orbis/utils/SharedMutex.hpp @@ -0,0 +1,144 @@ +#pragma once + +#include +#include +#include + +namespace orbis { +inline namespace utils { +// IPC-ready shared mutex, using only writer lock is recommended +struct shared_mutex final { + enum : unsigned { + c_one = 1u << 14, // Fixed-point 1.0 value (one writer) + c_sig = 1u << 30, + c_err = 1u << 31, + }; + + std::atomic m_value{}; + + void impl_lock_shared(unsigned val); + void impl_unlock_shared(unsigned old); + void impl_wait(); + void impl_signal(); + void impl_lock(unsigned val); + void impl_unlock(unsigned old); + void impl_lock_upgrade(); + +public: + constexpr shared_mutex() = default; + + bool try_lock_shared() { + // Conditional increment + unsigned value = m_value.load(); + return value < c_one - 1 && + m_value.compare_exchange_strong(value, value + 1); + } + + // Lock with HLE acquire hint + void lock_shared() { + unsigned value = m_value.load(); + if (value < c_one - 1) [[likely]] { + unsigned old = value; + if (compare_exchange_hle_acq(m_value, old, value + 1)) [[likely]] { + return; + } + } + + impl_lock_shared(value + 1); + } + + // Unlock with HLE release hint + void unlock_shared() { + const unsigned value = fetch_add_hle_rel(m_value, -1u); + if (value >= c_one) [[unlikely]] { + impl_unlock_shared(value); + } + } + + bool try_lock() { + unsigned value = 0; + return m_value.compare_exchange_strong(value, c_one); + } + + // Lock with HLE acquire hint + void lock() { + unsigned value = 0; + if (!compare_exchange_hle_acq(m_value, value, +c_one)) [[unlikely]] { + impl_lock(value); + } + } + + // Unlock with HLE release hint + void unlock() { + const unsigned value = fetch_add_hle_rel(m_value, 0u - c_one); + if (value != c_one) [[unlikely]] { + impl_unlock(value); + } + } + + bool try_lock_upgrade() { + unsigned value = m_value.load(); + + // Conditional increment, try to convert a single reader into a writer, + // ignoring other writers + return (value + c_one - 1) % c_one == 0 && + m_value.compare_exchange_strong(value, value + c_one - 1); + } + + void lock_upgrade() { + if (!try_lock_upgrade()) [[unlikely]] { + impl_lock_upgrade(); + } + } + + void lock_downgrade() { + // Convert to reader lock (can result in broken state) + m_value -= c_one - 1; + } + + // Check whether can immediately obtain an exclusive (writer) lock + bool is_free() const { return m_value.load() == 0; } + + // Check whether can immediately obtain a shared (reader) lock + bool is_lockable() const { return m_value.load() < c_one - 1; } +}; + +// Simplified shared (reader) lock implementation. +class reader_lock final { + shared_mutex &m_mutex; + bool m_upgraded = false; + +public: + reader_lock(const reader_lock &) = delete; + reader_lock &operator=(const reader_lock &) = delete; + explicit reader_lock(shared_mutex &mutex) : m_mutex(mutex) { + m_mutex.lock_shared(); + } + + // One-way lock upgrade; note that the observed state could have been changed + void upgrade() { + if (!m_upgraded) { + m_mutex.lock_upgrade(); + m_upgraded = true; + } + } + + // Try to upgrade; if it succeeds, the observed state has NOT been changed + bool try_upgrade() { + return m_upgraded || (m_upgraded = m_mutex.try_lock_upgrade()); + } + + ~reader_lock() { m_upgraded ? m_mutex.unlock() : m_mutex.unlock_shared(); } +}; + +class writer_lock final { + shared_mutex &m_mutex; + +public: + writer_lock(const writer_lock &) = delete; + writer_lock &operator=(const writer_lock &) = delete; + explicit writer_lock(shared_mutex &mutex) : m_mutex(mutex) { m_mutex.lock(); } + ~writer_lock() { m_mutex.unlock(); } +}; +} // namespace utils +} // namespace orbis diff --git a/orbis-kernel/src/module.cpp b/orbis-kernel/src/module.cpp new file mode 100644 index 000000000..bc695bc1e --- /dev/null +++ b/orbis-kernel/src/module.cpp @@ -0,0 +1,255 @@ +#include "module/Module.hpp" +#include "thread.hpp" +#include + +#include "module/Module.hpp" +#include "thread/Process.hpp" +#include + +// TODO: move relocations to the platform specific code +enum RelType { + kRelNone, + kRel64, + kRelPc32, + kRelGot32, + kRelPlt32, + kRelCopy, + kRelGlobDat, + kRelJumpSlot, + kRelRelative, + kRelGotPcRel, + kRel32, + kRel32s, + kRel16, + kRelPc16, + kRel8, + kRelPc8, + kRelDtpMod64, + kRelDtpOff64, + kRelTpOff64, + kRelTlsGd, + kRelTlsLd, + kRelDtpOff32, + kRelGotTpOff, + kRelTpOff32, + kRelPc64, + kRelGotOff64, + kRelGotPc32, + kRelGot64, + kRelGotPcRel64, + kRelGotPc64, + kRelGotPlt64, + kRelPltOff64, + kRelSize32, + kRelSize64, + kRelGotPc32TlsDesc, + kRelTlsDescCall, + kRelTlsDesc, + kRelIRelative, + kRelRelative64, +}; + +static std::uint64_t calculateTlsOffset(std::uint64_t prevOffset, + std::uint64_t size, + std::uint64_t align) { + return (prevOffset + size + align - 1) & ~(align - 1); +} + +static void allocateTlsOffset(orbis::Process *process, orbis::Module *module) { + if (module->isTlsDone) { + return; + } + + auto offset = + calculateTlsOffset(module->tlsIndex == 1 ? 0 : process->lastTlsOffset, + module->tlsSize, module->tlsAlign); + + module->tlsOffset = offset; + process->lastTlsOffset = offset; + module->isTlsDone = true; +} + +static orbis::SysResult doRelocation(orbis::Process *process, + orbis::Module *module, + orbis::Relocation rel) { + auto symbol = module->symbols.at(rel.symbolIndex); + + auto A = rel.addend; + auto B = reinterpret_cast(module->base); + auto where = reinterpret_cast(B + rel.offset); + auto where32 = reinterpret_cast(B + rel.offset); + auto P = reinterpret_cast(where); + + auto findDefModule = [module, symbol] { + if (symbol.moduleIndex == -1 || symbol.bind == orbis::SymbolBind::Local) { + return std::pair(module, symbol.address); + } + + auto &defModule = module->importedModules.at(symbol.moduleIndex); + if (!defModule) { + return std::pair(module, symbol.address); + } + + auto library = module->neededLibraries.at(symbol.libraryIndex); + + std::vector foundInLibs; + for (auto defSym : defModule->symbols) { + if (defSym.id != symbol.id || defSym.bind == orbis::SymbolBind::Local) { + continue; + } + + if (defSym.visibility == orbis::SymbolVisibility::Hidden) { + std::printf("Ignoring hidden symbol\n"); + continue; + } + + auto defLib = defModule->neededLibraries.at(defSym.libraryIndex); + + if (defLib.name == library.name) { + return std::pair(defModule.get(), defSym.address); + } + + foundInLibs.push_back(defLib.name); + } + + for (auto nsDefModule : defModule->namespaceModules) { + for (auto defSym : nsDefModule->symbols) { + if (defSym.id != symbol.id || defSym.bind == orbis::SymbolBind::Local) { + continue; + } + + if (defSym.visibility == orbis::SymbolVisibility::Hidden) { + std::printf("Ignoring hidden symbol\n"); + continue; + } + + auto defLib = nsDefModule->neededLibraries.at(defSym.libraryIndex); + + if (defLib.name == library.name) { + return std::pair(nsDefModule.get(), defSym.address); + } + } + } + + std::printf("'%s' ('%s') uses undefined symbol '%llx' in '%s' ('%s') module\n", + module->moduleName, module->soName, (unsigned long long)symbol.id, defModule->moduleName, defModule->soName); + if (foundInLibs.size() > 0) { + std::printf("Requested library is '%s', exists in libraries: [", + library.name.c_str()); + + for (bool isFirst = true; auto &lib : foundInLibs) { + if (isFirst) { + isFirst = false; + } else { + std::printf(", "); + } + + std::printf("'%s'", lib.c_str()); + } + std::printf("]\n"); + } + return std::pair(module, symbol.address); + }; + + switch (rel.relType) { + case kRelNone: + return {}; + case kRel64: { + auto [defObj, S] = findDefModule(); + *where = reinterpret_cast(defObj->base) + S + A; + return {}; + } + return {}; + case kRelPc32: { + auto [defObj, S] = findDefModule(); + *where32 = reinterpret_cast(defObj->base) + S + A - P; + return {}; + } + // case kRelCopy: + // return{}; + case kRelGlobDat: { + auto [defObj, S] = findDefModule(); + *where = reinterpret_cast(defObj->base) + S; + return {}; + } + case kRelJumpSlot: { + bool isLazyBind = false; // TODO + if (isLazyBind) { + *where += B; + } else { + auto [defObj, S] = findDefModule(); + *where = reinterpret_cast(defObj->base) + S; + } + return {}; + } + + case kRelRelative: + *where = B + A; + return {}; + case kRelDtpMod64: { + auto [defObj, S] = findDefModule(); + *where += defObj->tlsIndex; + return {}; + } + case kRelDtpOff64: { + auto [defObj, S] = findDefModule(); + *where += S + A; + return {}; + } + case kRelTpOff64: { + auto [defObj, S] = findDefModule(); + if (!defObj->isTlsDone) { + allocateTlsOffset(process, module); + } + *where = S - defObj->tlsOffset + A; + return {}; + } + case kRelDtpOff32: { + auto [defObj, S] = findDefModule(); + *where32 += S + A; + return {}; + } + case kRelTpOff32: { + auto [defObj, S] = findDefModule(); + if (!defObj->isTlsDone) { + allocateTlsOffset(process, module); + } + *where32 = S - defObj->tlsOffset + A; + return {}; + } + } + + std::fprintf(stderr, "unimplemented relocation type %u\n", + (unsigned)rel.relType); + std::abort(); + return {}; +} + +orbis::SysResult orbis::Module::relocate(Process *process) { + for (auto rel : pltRelocations) { + auto result = doRelocation(process, this, rel); + + if (result.isError()) { + return result; + } + } + + pltRelocations = {}; + + for (auto rel : nonPltRelocations) { + auto result = doRelocation(process, this, rel); + + if (result.isError()) { + return result; + } + } + + nonPltRelocations = {}; + + return {}; +} + +void orbis::Module::destroy() { + std::lock_guard lock(proc->mtx); + proc->modulesMap.remove(id); +} diff --git a/orbis-kernel/src/sys/sys_acct.cpp b/orbis-kernel/src/sys/sys_acct.cpp new file mode 100644 index 000000000..910225179 --- /dev/null +++ b/orbis-kernel/src/sys/sys_acct.cpp @@ -0,0 +1,4 @@ +#include "sys/sysproto.hpp" +#include "error.hpp" + +orbis::SysResult orbis::sys_acct(Thread *thread, ptr path) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_audit.cpp b/orbis-kernel/src/sys/sys_audit.cpp new file mode 100644 index 000000000..d13154168 --- /dev/null +++ b/orbis-kernel/src/sys/sys_audit.cpp @@ -0,0 +1,11 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_audit(Thread *thread, ptr record, uint length) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_auditon(Thread *thread, sint cmd, ptr data, uint length) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getauid(Thread *thread, ptr auid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setauid(Thread *thread, ptr auid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getaudit(Thread *thread, ptr auditinfo) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setaudit(Thread *thread, ptr auditinfo) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getaudit_addr(Thread *thread, ptr auditinfo_addr, uint length) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setaudit_addr(Thread *thread, ptr auditinfo_addr, uint length) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_auditctl(Thread *thread, ptr path) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_capability.cpp b/orbis-kernel/src/sys/sys_capability.cpp new file mode 100644 index 000000000..3a66c7170 --- /dev/null +++ b/orbis-kernel/src/sys/sys_capability.cpp @@ -0,0 +1,6 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_cap_enter(Thread *thread) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_cap_getmode(Thread *thread, ptr modep) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_cap_new(Thread *thread, sint fd, uint64_t rights) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_cap_getrights(Thread *thread, sint fd, ptr rights) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_context.cpp b/orbis-kernel/src/sys/sys_context.cpp new file mode 100644 index 000000000..c0c6713a6 --- /dev/null +++ b/orbis-kernel/src/sys/sys_context.cpp @@ -0,0 +1,5 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_getcontext(Thread *thread, ptr ucp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setcontext(Thread *thread, ptr ucp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_swapcontext(Thread *thread, ptr oucp, ptr ucp) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_cpuset.cpp b/orbis-kernel/src/sys/sys_cpuset.cpp new file mode 100644 index 000000000..e56fb1217 --- /dev/null +++ b/orbis-kernel/src/sys/sys_cpuset.cpp @@ -0,0 +1,7 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_cpuset(Thread *thread, ptr setid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_cpuset_setid(Thread *thread, cpuwhich_t which, id_t id, cpusetid_t setid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_cpuset_getid(Thread *thread, cpulevel_t level, cpuwhich_t which, id_t id, ptr setid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_cpuset_getaffinity(Thread *thread, cpulevel_t level, cpuwhich_t which, id_t id, size_t cpusetsize, ptr mask) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_cpuset_setaffinity(Thread *thread, cpulevel_t level, cpuwhich_t which, id_t id, size_t cpusetsize, ptr mask) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_descrip.cpp b/orbis-kernel/src/sys/sys_descrip.cpp new file mode 100644 index 000000000..109ccac18 --- /dev/null +++ b/orbis-kernel/src/sys/sys_descrip.cpp @@ -0,0 +1,18 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_getdtablesize(Thread *thread) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_dup2(Thread *thread, uint from, uint to) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_dup(Thread *thread, uint fd) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_fcntl(Thread *thread, sint fd, sint cmd, slong arg) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_close(Thread *thread, sint fd) { + if (auto close = thread->tproc->ops->close) { + return close(thread, fd); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_closefrom(Thread *thread, sint lowfd) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_fstat(Thread *thread, sint fd, ptr ub) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_nfstat(Thread *thread, sint fd, ptr sb) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_fpathconf(Thread *thread, sint fd, sint name) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_flock(Thread *thread, sint fd, sint how) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_environment.cpp b/orbis-kernel/src/sys/sys_environment.cpp new file mode 100644 index 000000000..8e5558e63 --- /dev/null +++ b/orbis-kernel/src/sys/sys_environment.cpp @@ -0,0 +1,3 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_kenv(Thread *thread, sint what, ptr name, ptr value, sint len) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_event.cpp b/orbis-kernel/src/sys/sys_event.cpp new file mode 100644 index 000000000..90537c737 --- /dev/null +++ b/orbis-kernel/src/sys/sys_event.cpp @@ -0,0 +1,9 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_kqueue(Thread *thread) { + return {}; +} + +orbis::SysResult orbis::sys_kevent(Thread *thread, sint fd, ptr changelist, sint nchanges, ptr eventlist, sint nevents, ptr timeout) { + return {}; +} diff --git a/orbis-kernel/src/sys/sys_exec.cpp b/orbis-kernel/src/sys/sys_exec.cpp new file mode 100644 index 000000000..8fde41912 --- /dev/null +++ b/orbis-kernel/src/sys/sys_exec.cpp @@ -0,0 +1,5 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_execve(Thread *thread, ptr fname, ptr> argv, ptr> envv) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_fexecve(Thread *thread, sint fd, ptr> argv, ptr> envv) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___mac_execve(Thread *thread, ptr fname, ptr> argv, ptr> envv, ptr mac_p) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_exit.cpp b/orbis-kernel/src/sys/sys_exit.cpp new file mode 100644 index 000000000..70fff4b0c --- /dev/null +++ b/orbis-kernel/src/sys/sys_exit.cpp @@ -0,0 +1,13 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_exit(Thread *thread, sint status) { + if (auto exit = thread->tproc->ops->exit) { + return exit(thread, status); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_abort2(Thread *thread, ptr why, sint narg, ptr> args) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_wait4(Thread *thread, sint pid, ptr status, sint options, ptr rusage) { return ErrorCode::NOSYS; } + + diff --git a/orbis-kernel/src/sys/sys_fork.cpp b/orbis-kernel/src/sys/sys_fork.cpp new file mode 100644 index 000000000..2238a8580 --- /dev/null +++ b/orbis-kernel/src/sys/sys_fork.cpp @@ -0,0 +1,6 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_fork(Thread *thread) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_pdfork(Thread *thread, ptr fdp, sint flags) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_vfork(Thread *thread) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_rfork(Thread *thread, sint flags) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_generic.cpp b/orbis-kernel/src/sys/sys_generic.cpp new file mode 100644 index 000000000..d2e05ba45 --- /dev/null +++ b/orbis-kernel/src/sys/sys_generic.cpp @@ -0,0 +1,75 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_read(Thread *thread, sint fd, ptr buf, size_t nbyte) { + if (auto read = thread->tproc->ops->read) { + return read(thread, fd, buf, nbyte); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_pread(Thread *thread, sint fd, ptr buf, size_t nbyte, off_t offset) { + if (auto pread = thread->tproc->ops->pread) { + return pread(thread, fd, buf, nbyte, offset); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_freebsd6_pread(Thread *thread, sint fd, ptr buf, size_t nbyte, sint, off_t offset) { + return sys_pread(thread, fd, buf, nbyte, offset); +} +orbis::SysResult orbis::sys_readv(Thread *thread, sint fd, ptr iovp, uint iovcnt) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_preadv(Thread *thread, sint fd, ptr iovp, uint iovcnt, off_t offset) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_write(Thread *thread, sint fd, ptr buf, size_t nbyte) { + if (auto write = thread->tproc->ops->write) { + return write(thread, fd, buf, nbyte); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_pwrite(Thread *thread, sint fd, ptr buf, size_t nbyte, off_t offset) { + if (auto pwrite = thread->tproc->ops->pwrite) { + return pwrite(thread, fd, buf, nbyte, offset); + } + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_freebsd6_pwrite(Thread *thread, sint fd, ptr buf, size_t nbyte, sint, off_t offset) { + return sys_pwrite(thread, fd, buf, nbyte, offset); +} +orbis::SysResult orbis::sys_writev(Thread *thread, sint fd, ptr iovp, uint iovcnt) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_pwritev(Thread *thread, sint fd, ptr iovp, uint iovcnt, off_t offset) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_ftruncate(Thread *thread, sint fd, off_t length) { + if (auto ftruncate = thread->tproc->ops->ftruncate) { + return ftruncate(thread, fd, length); + } + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_freebsd6_ftruncate(Thread *thread, sint fd, sint, off_t length) { + return sys_ftruncate(thread, fd, length); +} +orbis::SysResult orbis::sys_ioctl(Thread *thread, sint fd, ulong com, caddr_t data) { + if (auto ioctl = thread->tproc->ops->ioctl) { + return ioctl(thread, fd, com, data); + } + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_pselect(Thread *thread, sint nd, ptr in, ptr ou, ptr ex, ptr ts, ptr sm) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_select(Thread *thread, sint nd, ptr in, ptr out, ptr ex, ptr tv) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_poll(Thread *thread, ptr fds, uint nfds, sint timeout) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_openbsd_poll(Thread *thread, ptr fds, uint nfds, sint timeout) { return ErrorCode::NOSYS; } + +orbis::SysResult orbis::sys_nlm_syscall(Thread *thread, sint debug_level, sint grace_period, sint addr_count, ptr> addrs) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_nfssvc(Thread *thread, sint flag, caddr_t argp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sysarch(Thread *thread, sint op, ptr parms) { + if (op == 129) { + auto fs = uread((ptr)parms); + std::printf("sys_sysarch: set FS to 0x%zx\n", (std::size_t)fs); + thread->fsBase = fs; + return {}; + } + + std::printf("sys_sysarch(op = %d, parms = %p): unknown op\n", op, parms); + return {}; +} +orbis::SysResult orbis::sys_nnpfs_syscall(Thread *thread, sint operation, ptr a_pathP, sint opcode, ptr a_paramsP, sint a_followSymlinks) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_afs3_syscall(Thread *thread, slong syscall, slong param1, slong param2, slong param3, slong param4, slong param5, slong param6) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_gssd_syscall(Thread *thread, ptr path) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_jail.cpp b/orbis-kernel/src/sys/sys_jail.cpp new file mode 100644 index 000000000..c935367a7 --- /dev/null +++ b/orbis-kernel/src/sys/sys_jail.cpp @@ -0,0 +1,7 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_jail(Thread *thread, ptr jail) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_jail_set(Thread *thread, ptr iovp, uint iovcnt, sint flags) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_jail_get(Thread *thread, ptr iovp, uint iovcnt, sint flags) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_jail_remove(Thread *thread, sint jid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_jail_attach(Thread *thread, sint jid) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_ktrace.cpp b/orbis-kernel/src/sys/sys_ktrace.cpp new file mode 100644 index 000000000..0cfac8749 --- /dev/null +++ b/orbis-kernel/src/sys/sys_ktrace.cpp @@ -0,0 +1,4 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_ktrace(Thread *thread, ptr fname, sint ops, sint facs, sint pit) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_utrace(Thread *thread, ptr addr, size_t len) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_linker.cpp b/orbis-kernel/src/sys/sys_linker.cpp new file mode 100644 index 000000000..c8a8a781c --- /dev/null +++ b/orbis-kernel/src/sys/sys_linker.cpp @@ -0,0 +1,10 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_kldload(Thread *thread, ptr file) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_kldunload(Thread *thread, sint fileid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_kldunloadf(Thread *thread, slong fileid, sint flags) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_kldfind(Thread *thread, ptr name) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_kldnext(Thread *thread, sint fileid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_kldstat(Thread *thread, sint fileid, ptr stat) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_kldfirstmod(Thread *thread, sint fileid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_kldsym(Thread *thread, sint fileid, sint cmd, ptr data) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_loginclass.cpp b/orbis-kernel/src/sys/sys_loginclass.cpp new file mode 100644 index 000000000..efa2e18a9 --- /dev/null +++ b/orbis-kernel/src/sys/sys_loginclass.cpp @@ -0,0 +1,4 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_getloginclass(Thread *thread, ptr namebuf, size_t namelen) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setloginclass(Thread *thread, ptr namebuf) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_mac.cpp b/orbis-kernel/src/sys/sys_mac.cpp new file mode 100644 index 000000000..34f7e8552 --- /dev/null +++ b/orbis-kernel/src/sys/sys_mac.cpp @@ -0,0 +1,12 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys___mac_get_pid(Thread *thread, pid_t pid, ptr mac_p) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___mac_get_proc(Thread *thread, ptr mac_p) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___mac_set_proc(Thread *thread, ptr mac_p) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___mac_get_fd(Thread *thread, sint fd, ptr mac_p) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___mac_get_file(Thread *thread, ptr path, ptr mac_p) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___mac_set_fd(Thread *thread, sint fd, ptr mac_p) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___mac_set_file(Thread *thread, ptr path, ptr mac_p) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___mac_get_link(Thread *thread, ptr path_p, ptr mac_p) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___mac_set_link(Thread *thread, ptr path_p, ptr mac_p) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_mac_syscall(Thread *thread, ptr policy, sint call, ptr arg) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_module.cpp b/orbis-kernel/src/sys/sys_module.cpp new file mode 100644 index 000000000..4081bd7d1 --- /dev/null +++ b/orbis-kernel/src/sys/sys_module.cpp @@ -0,0 +1,6 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_modnext(Thread *thread, sint modid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_modfnext(Thread *thread, sint modid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_modstat(Thread *thread, sint modid, ptr stat) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_modfind(Thread *thread, ptr name) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_msg.cpp b/orbis-kernel/src/sys/sys_msg.cpp new file mode 100644 index 000000000..dfb71cdde --- /dev/null +++ b/orbis-kernel/src/sys/sys_msg.cpp @@ -0,0 +1,7 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_msgctl(Thread *thread, sint msqid, sint cmd, ptr buf) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_msgget(Thread *thread, key_t key, sint msgflg) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_msgsnd(Thread *thread, sint msqid, ptr msgp, size_t msgsz, sint msgflg) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_msgrcv(Thread *thread, sint msqid, ptr msgp, size_t msgsz, slong msgtyp, sint msgflg) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_msgsys(Thread *thread, sint which, sint a2, sint a3, sint a4, sint a5, sint a6) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_ntptime.cpp b/orbis-kernel/src/sys/sys_ntptime.cpp new file mode 100644 index 000000000..ad20168d8 --- /dev/null +++ b/orbis-kernel/src/sys/sys_ntptime.cpp @@ -0,0 +1,5 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_ntp_gettime(Thread *thread, ptr ntvp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_ntp_adjtime(Thread *thread, ptr tp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_adjtime(Thread *thread, ptr delta, ptr olddelta) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_p1003_1b.cpp b/orbis-kernel/src/sys/sys_p1003_1b.cpp new file mode 100644 index 000000000..ce6f07967 --- /dev/null +++ b/orbis-kernel/src/sys/sys_p1003_1b.cpp @@ -0,0 +1,10 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_sched_setparam(Thread *thread, pid_t pid, ptr param) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sched_getparam(Thread *thread, pid_t pid, ptr param) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sched_setscheduler(Thread *thread, pid_t pid, sint policy, ptr param) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sched_getscheduler(Thread *thread, pid_t pid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sched_yield(Thread *thread) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sched_get_priority_max(Thread *thread, sint policy) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sched_get_priority_min(Thread *thread, sint policy) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sched_rr_get_interval(Thread *thread, pid_t pid, ptr interval) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_pipe.cpp b/orbis-kernel/src/sys/sys_pipe.cpp new file mode 100644 index 000000000..411b3215b --- /dev/null +++ b/orbis-kernel/src/sys/sys_pipe.cpp @@ -0,0 +1,3 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_pipe(Thread *thread) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_procdesc.cpp b/orbis-kernel/src/sys/sys_procdesc.cpp new file mode 100644 index 000000000..77cd5e515 --- /dev/null +++ b/orbis-kernel/src/sys/sys_procdesc.cpp @@ -0,0 +1,3 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_pdgetpid(Thread *thread, sint fd, ptr pidp) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_process.cpp b/orbis-kernel/src/sys/sys_process.cpp new file mode 100644 index 000000000..cc247db84 --- /dev/null +++ b/orbis-kernel/src/sys/sys_process.cpp @@ -0,0 +1,3 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_ptrace(Thread *thread, sint req, pid_t pid, caddr_t addr, sint data) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_prot.cpp b/orbis-kernel/src/sys/sys_prot.cpp new file mode 100644 index 000000000..d3ff0cbfa --- /dev/null +++ b/orbis-kernel/src/sys/sys_prot.cpp @@ -0,0 +1,32 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_getpid(Thread *thread) { + thread->retval[0] = thread->tid; + return {}; +} +orbis::SysResult orbis::sys_getppid(Thread *thread) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getpgrp(Thread *thread) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getpgid(Thread *thread, pid_t pid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getsid(Thread *thread, pid_t pid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getuid(Thread *thread) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_geteuid(Thread *thread) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getgid(Thread *thread) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getegid(Thread *thread) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getgroups(Thread *thread, uint gidsetsize, ptr gidset) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setsid(Thread *thread) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setpgid(Thread *thread, sint pid, sint pgid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setuid(Thread *thread, uid_t uid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_seteuid(Thread *thread, uid_t euid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setgid(Thread *thread, gid_t gid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setegid(Thread *thread, gid_t egid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setgroups(Thread *thread, uint gidsetsize, ptr gidset) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setreuid(Thread *thread, sint ruid, sint euid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setregid(Thread *thread, sint rgid, sint egid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setresuid(Thread *thread, uid_t ruid, uid_t euid, uid_t suid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setresgid(Thread *thread, gid_t rgid, gid_t egid, gid_t sgid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getresuid(Thread *thread, ptr ruid, ptr euid, ptr suid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getresgid(Thread *thread, ptr rgid, ptr egid, ptr sgid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_issetugid(Thread *thread) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___setugid(Thread *thread, sint flags) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getlogin(Thread *thread, ptr namebuf, uint namelen) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setlogin(Thread *thread, ptr namebuf) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_pty_pts.cpp b/orbis-kernel/src/sys/sys_pty_pts.cpp new file mode 100644 index 000000000..6406c3fc9 --- /dev/null +++ b/orbis-kernel/src/sys/sys_pty_pts.cpp @@ -0,0 +1,3 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_posix_openpt(Thread *thread, sint flags) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_rctl.cpp b/orbis-kernel/src/sys/sys_rctl.cpp new file mode 100644 index 000000000..7664b8786 --- /dev/null +++ b/orbis-kernel/src/sys/sys_rctl.cpp @@ -0,0 +1,7 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_rctl_get_racct(Thread *thread, ptr inbufp, size_t inbuflen, ptr outbuf, size_t outbuflen) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_rctl_get_rules(Thread *thread, ptr inbufp, size_t inbuflen, ptr outbuf, size_t outbuflen) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_rctl_get_limits(Thread *thread, ptr inbufp, size_t inbuflen, ptr outbuf, size_t outbuflen) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_rctl_add_rule(Thread *thread, ptr inbufp, size_t inbuflen, ptr outbuf, size_t outbuflen) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_rctl_remove_rule(Thread *thread, ptr inbufp, size_t inbuflen, ptr outbuf, size_t outbuflen) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_resource.cpp b/orbis-kernel/src/sys/sys_resource.cpp new file mode 100644 index 000000000..3fab5429d --- /dev/null +++ b/orbis-kernel/src/sys/sys_resource.cpp @@ -0,0 +1,12 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_getpriority(Thread *thread, sint which, sint who) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setpriority(Thread *thread, sint which, sint who, sint prio) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_rtprio_thread(Thread *thread, sint function, lwpid_t lwpid, ptr rtp) { + std::printf("sys_rtprio_thread: unimplemented\n"); + return {}; +} +orbis::SysResult orbis::sys_rtprio(Thread *thread, sint function, pid_t pid, ptr rtp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setrlimit(Thread *thread, uint which, ptr rlp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getrlimit(Thread *thread, uint which, ptr rlp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getrusage(Thread *thread, sint who, ptr rusage) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_route.cpp b/orbis-kernel/src/sys/sys_route.cpp new file mode 100644 index 000000000..3eed54849 --- /dev/null +++ b/orbis-kernel/src/sys/sys_route.cpp @@ -0,0 +1,3 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_setfib(Thread *thread, sint fib) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_sce.cpp b/orbis-kernel/src/sys/sys_sce.cpp new file mode 100644 index 000000000..9c746dada --- /dev/null +++ b/orbis-kernel/src/sys/sys_sce.cpp @@ -0,0 +1,870 @@ +#include "error.hpp" +#include "module/ModuleInfo.hpp" +#include "module/ModuleInfoEx.hpp" +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_netcontrol(Thread *thread, sint fd, uint op, + ptr buf, uint nbuf) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_netabort(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_netgetsockinfo(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_socketex(Thread *thread, ptr name, + sint domain, sint type, sint protocol) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_socketclose(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_netgetiflist(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_kqueueex(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_mtypeprotect(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_regmgr_call(Thread *thread, uint32_t op, + uint32_t id, ptr result, ptr value, + uint64_t type) { + if (op == 25) { + struct nonsys_int { + union { + uint64_t encoded_id; + struct { + uint8_t data[4]; + uint8_t table; + uint8_t index; + uint16_t checksum; + } encoded_id_parts; + }; + uint32_t unk; + uint32_t value; + }; + + auto int_value = reinterpret_cast(value); + + std::printf(" encoded_id = %lx\n", int_value->encoded_id); + std::printf(" data[0] = %02x\n", int_value->encoded_id_parts.data[0]); + std::printf(" data[1] = %02x\n", int_value->encoded_id_parts.data[1]); + std::printf(" data[2] = %02x\n", int_value->encoded_id_parts.data[2]); + std::printf(" data[3] = %02x\n", int_value->encoded_id_parts.data[3]); + std::printf(" table = %u\n", int_value->encoded_id_parts.table); + std::printf(" index = %u\n", int_value->encoded_id_parts.index); + std::printf(" checksum = %x\n", int_value->encoded_id_parts.checksum); + std::printf(" unk = %x\n", int_value->unk); + std::printf(" value = %x\n", int_value->value); + } + + return{}; + +} +orbis::SysResult orbis::sys_jitshm_create(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_jitshm_alias(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_dl_get_list(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_dl_get_info(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_dl_notify_event(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_evf_create(Thread *thread, ptr name, + sint flag, ptr evf) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_evf_delete(Thread *thread, sint fd) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_evf_open(Thread *thread, ptr name) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_evf_close(Thread *thread, sint fd) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_evf_wait(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_evf_trywait(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_evf_set(Thread *thread, sint fd) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_evf_clear(Thread *thread, sint fd) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_evf_cancel(Thread *thread, sint fd) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_query_memory_protection(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_batch_map(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_osem_create(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_osem_delete(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_osem_open(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_osem_close(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_osem_wait(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_osem_trywait(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_osem_post(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_osem_cancel(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_namedobj_create(Thread *thread, ptr name, ptr object, uint64_t type) { + std::printf("sys_namedobj_create(name = %s, object = %p, type = 0x%lx) -> %d\n", name, object, type, 1); + thread->retval[0] = 1; + return {}; +} +orbis::SysResult orbis::sys_namedobj_delete(Thread *thread /* TODO */) { + std::printf("TODO: sys_namedobj_delete\n"); + return {}; +} +orbis::SysResult orbis::sys_set_vm_container(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_debug_init(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_suspend_process(Thread *thread, pid_t pid) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_resume_process(Thread *thread, pid_t pid) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_opmc_enable(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_opmc_disable(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_opmc_set_ctl(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_opmc_set_ctr(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_opmc_get_ctr(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_budget_create(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_budget_delete(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_budget_get(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_budget_set(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_virtual_query(Thread *thread, ptr addr, + uint64_t unk, ptr info, + size_t infosz) { + if (auto virtual_query = thread->tproc->ops->virtual_query) { + return virtual_query(thread, addr, unk, info, infosz); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_mdbg_call(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_obs_sblock_create(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_obs_sblock_delete(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_obs_sblock_enter(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_obs_sblock_exit(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_obs_sblock_xenter(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_obs_sblock_xexit(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_obs_eport_create(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_obs_eport_delete(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_obs_eport_trigger(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_obs_eport_open(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_obs_eport_close(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_is_in_sandbox(Thread *thread /* TODO */) { + std::printf("sys_is_in_sandbox() -> 0\n"); + return{}; +} +orbis::SysResult orbis::sys_dmem_container(Thread *thread) { + thread->retval[0] = 0; // returns default direct memory device + return {}; +} +orbis::SysResult orbis::sys_get_authinfo(Thread *thread, pid_t pid, ptr info) { + struct authinfo { + uint64_t a; + uint64_t b; + }; + + std::memset(info, 0, 136); + ((authinfo *)info)->b = ~0; + + return {}; +} +orbis::SysResult orbis::sys_mname(Thread *thread, ptr address, uint64_t length, ptr name) { + std::printf("sys_mname(%p, %p, '%s')\n", address, (char *)address + length, name); + return {}; +} +orbis::SysResult orbis::sys_dynlib_dlopen(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_dynlib_dlclose(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_dynlib_dlsym(Thread *thread, SceKernelModule handle, + ptr symbol, + ptr> addrp) { + if (thread->tproc->ops->dynlib_dlsym) { + return thread->tproc->ops->dynlib_dlsym(thread, handle, symbol, addrp); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_dynlib_get_list(Thread *thread, + ptr pArray, + size_t numArray, + ptr pActualNum) { + std::size_t actualNum = 0; + for (auto [id, module] : thread->tproc->modulesMap) { + if (actualNum >= numArray) { + break; + } + + pArray[actualNum++] = id; + } + *pActualNum = actualNum; + return {}; +} +orbis::SysResult orbis::sys_dynlib_get_info(Thread *thread, + SceKernelModule handle, + ptr pInfo) { + auto module = thread->tproc->modulesMap.get(handle); + + if (module == nullptr) { + return ErrorCode::SRCH; + } + + if (pInfo->size != sizeof(ModuleInfo)) { + return ErrorCode::INVAL; + } + + ModuleInfo result = {}; + result.size = sizeof(ModuleInfo); + std::strncpy(result.name, module->moduleName, sizeof(result.name)); + std::memcpy(result.segments, module->segments, + sizeof(ModuleSegment) * module->segmentCount); + result.segmentCount = module->segmentCount; + std::memcpy(result.fingerprint, module->fingerprint, + sizeof(result.fingerprint)); + uwrite(pInfo, result); + return {}; +} +orbis::SysResult +orbis::sys_dynlib_load_prx(Thread *thread, ptr name, uint64_t arg1, ptr pHandle, uint64_t arg3) { + if (auto dynlib_load_prx = thread->tproc->ops->dynlib_load_prx) { + return dynlib_load_prx(thread, name, arg1, pHandle, arg3); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult +orbis::sys_dynlib_unload_prx(Thread *thread, SceKernelModule handle) { + if (auto dynlib_unload_prx = thread->tproc->ops->dynlib_unload_prx) { + return dynlib_unload_prx(thread, handle); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult +orbis::sys_dynlib_do_copy_relocations(Thread *thread) { + if (auto dynlib_do_copy_relocations = thread->tproc->ops->dynlib_do_copy_relocations) { + return dynlib_do_copy_relocations(thread); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_dynlib_prepare_dlclose(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} + +// template using le = T; + +orbis::SysResult orbis::sys_dynlib_get_proc_param(Thread *thread, + ptr> procParam, + ptr procParamSize) { + auto proc = thread->tproc; + *procParam = proc->processParam; + *procParamSize = proc->processParamSize; + return {}; +} +orbis::SysResult orbis::sys_dynlib_process_needed_and_relocate(Thread *thread) { + if (auto processNeeded = thread->tproc->ops->processNeeded) { + auto result = processNeeded(thread); + + if (result.value() != 0) { + return result; + } + } + + for (auto [id, module] : thread->tproc->modulesMap) { + auto result = module->relocate(thread->tproc); + if (result.isError()) { + return result; + } + } + + if (auto registerEhFrames = thread->tproc->ops->registerEhFrames) { + auto result = registerEhFrames(thread); + + if (result.value() != 0) { + return result; + } + } + + return {}; +} +orbis::SysResult orbis::sys_sandbox_path(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} + +struct mdbg_property { + orbis::int32_t unk; + orbis::int32_t unk2; + orbis::uint64_t addr_ptr; + orbis::uint64_t areaSize; + orbis::int64_t unk3; + orbis::int64_t unk4; + char name[32]; +}; + +orbis::SysResult orbis::sys_mdbg_service(Thread *thread, uint32_t op, ptr arg0, ptr arg1) { + std::printf("sys_mdbg_service(op = %d, arg0 = %p, arg1 = %p)\n", op, arg0, arg1); + + switch (op) { + case 1: { + auto *prop = (mdbg_property *)arg0; + std::printf( + "sys_mdbg_service set property (name='%s', address=0x%lx, size=%lu)\n", + prop->name, prop->addr_ptr, prop->areaSize); + break; + } + + case 3: { + std::printf("sys_mdbg_service: ERROR CODE: %X\n", (unsigned)reinterpret_cast(arg0)); + break; + } + + case 7: { + std::printf("sys_mdbg_service: %s\n", (char *)arg0); + break; + } + + default: + break; + } + + return{}; +} +orbis::SysResult orbis::sys_randomized_path(Thread *thread /* TODO */) { + std::printf("TODO: sys_randomized_path()\n"); + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_rdup(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_dl_get_metadata(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_workaround8849(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_is_development_mode(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_get_self_auth_info(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult +orbis::sys_dynlib_get_info_ex(Thread *thread, SceKernelModule handle, + ptr unk, + ptr destModuleInfoEx) { + auto module = thread->tproc->modulesMap.get(handle); + if (module == nullptr) { + return ErrorCode::SRCH; + } + + if (destModuleInfoEx->size != sizeof(ModuleInfoEx)) { + return ErrorCode::INVAL; + } + + ModuleInfoEx result = {}; + result.size = sizeof(ModuleInfoEx); + std::strncpy(result.name, module->moduleName, sizeof(result.name)); + result.id = std::to_underlying(handle); + result.tlsIndex = module->tlsIndex; + result.tlsInit = module->tlsInit; + result.tlsInitSize = module->tlsInitSize; + result.tlsSize = module->tlsSize; + result.tlsOffset = module->tlsOffset; + result.tlsAlign = module->tlsAlign; + result.initProc = module->initProc; + result.finiProc = module->finiProc; + result.ehFrameHdr = module->ehFrameHdr; + result.ehFrame = module->ehFrame; + result.ehFrameHdrSize = module->ehFrameHdrSize; + result.ehFrameSize = module->ehFrameSize; + std::memcpy(result.segments, module->segments, + sizeof(ModuleSegment) * module->segmentCount); + result.segmentCount = module->segmentCount; + result.refCount = module->references.load(std::memory_order::relaxed); + uwrite(destModuleInfoEx, result); + + return {}; +} +orbis::SysResult orbis::sys_budget_getid(Thread *thread) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_budget_get_ptype(Thread *thread, sint budgetId) { + thread->retval[0] = 1; + return {}; +} +orbis::SysResult +orbis::sys_get_paging_stats_of_all_threads(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_get_proc_type_info(Thread *thread, + ptr destProcessInfo) { + std::printf("TODO: sys_get_proc_type_info\n"); + + struct dargs { + uint64_t size = sizeof(dargs); + uint32_t ptype; + uint32_t pflags; + } args = { + .ptype = 1, + .pflags = 0 + }; + + uwrite((ptr)destProcessInfo, args); + return{}; +} +orbis::SysResult orbis::sys_get_resident_count(Thread *thread, pid_t pid) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_prepare_to_suspend_process(Thread *thread, + pid_t pid) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_get_resident_fmem_count(Thread *thread, pid_t pid) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_thr_get_name(Thread *thread, lwpid_t lwpid) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_set_gpo(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult +orbis::sys_get_paging_stats_of_all_objects(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_test_debug_rwmem(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_free_stack(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_suspend_system(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} + +enum ImpiOpcode { + kIpmiCreateClient = 2 +}; + +struct IpmiCreateClientParams { + orbis::ptr arg0; + orbis::ptr name; + orbis::ptr arg2; +}; +static_assert(sizeof(IpmiCreateClientParams) == 0x18); + +orbis::SysResult orbis::sys_ipmimgr_call(Thread *thread, uint64_t id, uint64_t arg2, ptr result, ptr params, uint64_t paramsSize, uint64_t arg6) { + std::printf("TODO: sys_ipmimgr_call(id = %lld)\n", (unsigned long long)id); + + if (id == kIpmiCreateClient) { + if (paramsSize != sizeof(IpmiCreateClientParams)) { + return ErrorCode::INVAL; + } + + auto createParams = (ptr)params; + + std::printf("ipmi create client(%p, '%s', %p)\n", + (void *)createParams->arg0, + (char *)createParams->name, + (void *)createParams->arg2 + ); + + return{}; + } + + if (id == 1131 || id == 1024 || id == 800) { + thread->retval[0] = -0x40004; // HACK + return {}; + // return -0x40004; + } + + if (id == 3) { + if (result) { + *result = 0; + } + return {}; + } + + return {}; +} +orbis::SysResult orbis::sys_get_gpo(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_get_vm_map_timestamp(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_opmc_set_hw(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_opmc_get_hw(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_get_cpu_usage_all(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_mmap_dmem(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_physhm_open(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_physhm_unlink(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_resume_internal_hdd(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_thr_suspend_ucontext(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_thr_resume_ucontext(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_thr_get_ucontext(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_thr_set_ucontext(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_set_timezone_info(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_set_phys_fmem_limit(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_utc_to_localtime(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_localtime_to_utc(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_set_uevt(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_get_cpu_usage_proc(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_get_map_statistics(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_set_chicken_switches(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_extend_page_table_pool(Thread *thread) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_extend_page_table_pool2(Thread *thread) { + return ErrorCode::NOSYS; +} +orbis::SysResult +orbis::sys_get_kernel_mem_statistics(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult +orbis::sys_get_sdk_compiled_version(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_app_state_change(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_dynlib_get_obj_member(Thread *thread, SceKernelModule handle, uint64_t index, ptr> addrp) { + if (auto dynlib_get_obj_member = thread->tproc->ops->dynlib_get_obj_member) { + return dynlib_get_obj_member(thread, handle, index, addrp); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult +orbis::sys_budget_get_ptype_of_budget(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult +orbis::sys_prepare_to_resume_process(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_process_terminate(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_blockpool_open(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_blockpool_map(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_blockpool_unmap(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult +orbis::sys_dynlib_get_info_for_libdbg(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_blockpool_batch(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_fdatasync(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_dynlib_get_list2(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_dynlib_get_info2(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_aio_submit(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_aio_multi_delete(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_aio_multi_wait(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_aio_multi_poll(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_aio_get_data(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_aio_multi_cancel(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_get_bio_usage_all(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_aio_create(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_aio_submit_cmd(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_aio_init(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_get_page_table_stats(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult +orbis::sys_dynlib_get_list_for_libdbg(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_blockpool_move(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_virtual_query_all(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_reserve_2mb_page(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_cpumode_yield(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_wait6(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_cap_rights_limit(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_cap_ioctls_limit(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_cap_ioctls_get(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_cap_fcntls_limit(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_cap_fcntls_get(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_bindat(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_connectat(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_chflagsat(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_accept4(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_pipe2(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_aio_mlock(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_procctl(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_ppoll(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_futimens(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_utimensat(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_numa_getaffinity(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_numa_setaffinity(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_apr_submit(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_apr_resolve(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_apr_stat(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_apr_wait(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_apr_ctrl(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_get_phys_page_size(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_begin_app_mount(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_end_app_mount(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_fsc2h_ctrl(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_streamwrite(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_app_save(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_app_restore(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_saved_app_delete(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult +orbis::sys_get_ppr_sdk_compiled_version(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_notify_app_event(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_ioreq(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_openintr(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_dl_get_info_2(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_acinfo_add(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_acinfo_delete(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult +orbis::sys_acinfo_get_all_for_coredump(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_ampr_ctrl_debug(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_workspace_ctrl(Thread *thread /* TODO */) { + return ErrorCode::NOSYS; +} diff --git a/orbis-kernel/src/sys/sys_sem.cpp b/orbis-kernel/src/sys/sys_sem.cpp new file mode 100644 index 000000000..9a3765b01 --- /dev/null +++ b/orbis-kernel/src/sys/sys_sem.cpp @@ -0,0 +1,6 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys___semctl(Thread *thread, sint semid, sint semnum, sint cmd, ptr arg) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_semget(Thread *thread, key_t key, sint nsems, sint semflg) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_semop(Thread *thread, sint semid, ptr sops, size_t nspos) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_semsys(Thread *thread, sint which, sint a2, sint a3, sint a4, sint a5) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_shm.cpp b/orbis-kernel/src/sys/sys_shm.cpp new file mode 100644 index 000000000..7c4da1876 --- /dev/null +++ b/orbis-kernel/src/sys/sys_shm.cpp @@ -0,0 +1,7 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_shmdt(Thread *thread, ptr shmaddr) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_shmat(Thread *thread, sint shmid, ptr shmaddr, sint shmflg) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_shmctl(Thread *thread, sint shmid, sint cmd, ptr buf) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_shmget(Thread *thread, key_t key, size_t size, sint shmflg) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_shmsys(Thread *thread, sint which, sint a2, sint a3, sint a4) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_shutdown.cpp b/orbis-kernel/src/sys/sys_shutdown.cpp new file mode 100644 index 000000000..965b5d20f --- /dev/null +++ b/orbis-kernel/src/sys/sys_shutdown.cpp @@ -0,0 +1,3 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_reboot(Thread *thread, sint opt) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_sig.cpp b/orbis-kernel/src/sys/sys_sig.cpp new file mode 100644 index 000000000..6716b94e0 --- /dev/null +++ b/orbis-kernel/src/sys/sys_sig.cpp @@ -0,0 +1,44 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_sigaction(Thread *thread, sint sig, ptr act, ptr oact) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sigprocmask(Thread *thread, sint how, ptr set, ptr oset) { + if (oset) { + for (std::size_t i = 0; i < 2; ++i) { + oset[i] = thread->sigMask[i]; + } + } + + if (set) { + switch (how) { + case 0: // unblock + for (std::size_t i = 0; i < 2; ++i) { + thread->sigMask[i] &= ~set[i]; + } + case 1: // block + for (std::size_t i = 0; i < 2; ++i) { + thread->sigMask[i] |= set[i]; + } + break; + case 3: // set + for (std::size_t i = 0; i < 2; ++i) { + thread->sigMask[i] = set[i]; + } + break; + + default: + return ErrorCode::INVAL; + } + } + return {}; +} +orbis::SysResult orbis::sys_sigwait(Thread *thread, ptr set, ptr sig) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sigtimedwait(Thread *thread, ptr set, ptr info, ptr timeout) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sigwaitinfo(Thread *thread, ptr set, ptr info) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sigpending(Thread *thread, ptr set) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sigsuspend(Thread *thread, ptr set) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sigaltstack(Thread *thread, ptr ss, ptr oss) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_kill(Thread *thread, sint pid, sint signum) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_pdkill(Thread *thread, sint fd, sint signum) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sigqueue(Thread *thread, pid_t pid, sint signum, ptr value) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sigreturn(Thread *thread, ptr sigcntxp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::nosys(Thread *thread) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_subr_prof.cpp b/orbis-kernel/src/sys/sys_subr_prof.cpp new file mode 100644 index 000000000..cf6f65461 --- /dev/null +++ b/orbis-kernel/src/sys/sys_subr_prof.cpp @@ -0,0 +1,3 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_profil(Thread *thread, caddr_t samples, size_t size, size_t offset, uint scale) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_swap_pager.cpp b/orbis-kernel/src/sys/sys_swap_pager.cpp new file mode 100644 index 000000000..8e1559613 --- /dev/null +++ b/orbis-kernel/src/sys/sys_swap_pager.cpp @@ -0,0 +1,4 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_swapon(Thread *thread, ptr name) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_swapoff(Thread *thread, ptr name) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_synch.cpp b/orbis-kernel/src/sys/sys_synch.cpp new file mode 100644 index 000000000..6d46ef023 --- /dev/null +++ b/orbis-kernel/src/sys/sys_synch.cpp @@ -0,0 +1,3 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_yield(Thread *thread) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_sysctl.cpp b/orbis-kernel/src/sys/sys_sysctl.cpp new file mode 100644 index 000000000..1afeff41a --- /dev/null +++ b/orbis-kernel/src/sys/sys_sysctl.cpp @@ -0,0 +1,248 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys___sysctl(Thread *thread, ptr name, + uint namelen, ptr old, + ptr oldlenp, ptr new_, + size_t newlen) { + enum sysctl_ctl { unspec, kern, vm, vfs, net, debug, hw, machdep, user }; + + // machdep.tsc_freq + + enum sysctl_kern { + usrstack = 33, + kern_14 = 14, + kern_37 = 37, + + // FIXME + smp_cpus = 1000, + sdk_version, + sched_cpusetsize, + proc_ptc, + + }; + + enum sysctl_hw { + pagesize = 7, + }; + + enum sysctl_machdep { + // FIXME + tsc_freq = 1000 + }; + + // for (unsigned int i = 0; i < namelen; ++i) { + // std::printf(" name[%u] = %u\n", i, name[i]); + // } + + if (namelen == 3) { + // 1 - 14 - 41 - debug flags? + + if (name[0] == 1 && name[1] == 14 && name[2] == 41) { + // std::printf(" kern.14.41\n"); + + if (*oldlenp != 4 || new_ != nullptr || newlen != 0) { + return ErrorCode::INVAL; + } + + *(uint32_t *)old = 0; + return {}; + } + } + + if (namelen == 4) { + // 1 - 14 - 35 - 2 + + // sceKernelGetAppInfo + struct app_info { + char unk[72]; + }; + + if (name[0] == 1 && name[1] == 14 && name[2] == 35) { + // std::printf(" kern.14.35.%u\n", name[3]); + memset(old, 0, sizeof(app_info)); + return {}; + } + } + + if (namelen == 2) { + switch (name[0]) { + case sysctl_ctl::unspec: { + switch (name[1]) { + case 3: { + std::printf(" unspec - get name of '%s'\n", + std::string((char *)new_, newlen).c_str()); + auto searchName = std::string_view((char *)new_, newlen); + auto *dest = (std::uint32_t *)old; + std::uint32_t count = 0; + + if (searchName == "kern.smp.cpus") { + if (*oldlenp < 2 * sizeof(uint32_t)) { + return ErrorCode::INVAL; + } + + dest[count++] = kern; + dest[count++] = smp_cpus; + } else if (searchName == "machdep.tsc_freq") { + if (*oldlenp < 2 * sizeof(uint32_t)) { + return ErrorCode::INVAL; + } + + dest[count++] = machdep; + dest[count++] = tsc_freq; + } else if (searchName == "kern.sdk_version") { + if (*oldlenp < 2 * sizeof(uint32_t)) { + return ErrorCode::INVAL; + } + + dest[count++] = kern; + dest[count++] = sdk_version; + } else if (searchName == "kern.sched.cpusetsize") { + if (*oldlenp < 2 * sizeof(uint32_t)) { + return ErrorCode::INVAL; + } + + dest[count++] = kern; + dest[count++] = sched_cpusetsize; + } else if (searchName == "kern.proc.ptc") { + if (*oldlenp < 2 * sizeof(uint32_t)) { + std::printf(" kern.proc.ptc error\n"); + return ErrorCode::INVAL; + } + + dest[count++] = kern; + dest[count++] = proc_ptc; + } + + if (count == 0) { + return ErrorCode::SRCH; + } + + *oldlenp = count * sizeof(uint32_t); + return {}; + } + + default: + break; + } + std::printf(" unspec_%u\n", name[1]); + return {}; + } + + case sysctl_ctl::kern: + switch (name[1]) { + case sysctl_kern::usrstack: { + if (*oldlenp != 8 || new_ != nullptr || newlen != 0) { + return ErrorCode::INVAL; + } + + std::printf("Reporting stack at %p\n", thread->stackEnd); + *(ptr *)old = thread->stackEnd; + return {}; + } + + case sysctl_kern::smp_cpus: + if (*oldlenp != 4 || new_ != nullptr || newlen != 0) { + return ErrorCode::INVAL; + } + + *(uint32_t *)old = 1; + break; + + case sysctl_kern::sdk_version: { + if (*oldlenp != 4 || new_ != nullptr || newlen != 0) { + return ErrorCode::INVAL; + } + + auto processParam = + reinterpret_cast(thread->tproc->processParam); + + auto sdkVersion = processParam // + + sizeof(uint64_t) // size + + sizeof(uint32_t) // magic + + sizeof(uint32_t); // entryCount + + std::printf("Reporting SDK version %x\n", + *reinterpret_cast(sdkVersion)); + *(uint32_t *)old = *reinterpret_cast(sdkVersion); + break; + } + + case sysctl_kern::sched_cpusetsize: + if (*oldlenp != 4 || new_ != nullptr || newlen != 0) { + return ErrorCode::INVAL; + } + + *(std::uint32_t *)old = 4; + break; + + case sysctl_kern::kern_37: { + struct kern37_value { + std::uint64_t size; + std::uint64_t unk[7]; + }; + + if (*oldlenp != sizeof(kern37_value) || new_ != nullptr || + newlen != 0) { + return ErrorCode::INVAL; + } + + auto value = (kern37_value *)old; + value->size = sizeof(kern37_value); + break; + } + + case sysctl_kern::proc_ptc: { + if (*oldlenp != 8 || new_ != nullptr || newlen != 0) { + return ErrorCode::INVAL; + } + + *(std::uint64_t *)old = 1357; + } + + default: + return ErrorCode::INVAL; + } + break; + + case sysctl_ctl::vm: + case sysctl_ctl::vfs: + case sysctl_ctl::net: + case sysctl_ctl::debug: + return ErrorCode::INVAL; + + case sysctl_ctl::hw: + switch (name[1]) { + case sysctl_hw::pagesize: + if (*oldlenp != 4 || new_ != nullptr || newlen != 0) { + return ErrorCode::INVAL; + } + + *(uint32_t *)old = 0x4000; + break; + + default: + break; + } + break; + + case sysctl_ctl::machdep: + switch (name[1]) { + case sysctl_machdep::tsc_freq: { + if (*oldlenp != 8 || new_ != nullptr || newlen != 0) { + return ErrorCode::INVAL; + } + + *(uint64_t *)old = 1000000000ull; + return {}; + + default: + return ErrorCode::INVAL; + } + } + case sysctl_ctl::user: + return ErrorCode::INVAL; + } + } + + return {}; +} diff --git a/orbis-kernel/src/sys/sys_thr.cpp b/orbis-kernel/src/sys/sys_thr.cpp new file mode 100644 index 000000000..dcef55f1e --- /dev/null +++ b/orbis-kernel/src/sys/sys_thr.cpp @@ -0,0 +1,69 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_thr_create(Thread *thread, ptr ctxt, ptr arg, sint flags) { + if (auto thr_create = thread->tproc->ops->thr_create) { + return thr_create(thread, ctxt, arg, flags); + } + + return ErrorCode::NOSYS; +} + +orbis::SysResult orbis::sys_thr_new(Thread *thread, ptr param, sint param_size) { + if (auto thr_new = thread->tproc->ops->thr_new) { + return thr_new(thread, param, param_size); + } + + return ErrorCode::NOSYS; +} + +orbis::SysResult orbis::sys_thr_self(Thread *thread, ptr id) { + uwrite(id, (slong)thread->tid); + return {}; +} + +orbis::SysResult orbis::sys_thr_exit(Thread *thread, ptr state) { + if (auto thr_exit = thread->tproc->ops->thr_exit) { + return thr_exit(thread, state); + } + return ErrorCode::NOSYS; +} + +orbis::SysResult orbis::sys_thr_kill(Thread *thread, slong id, sint sig) { + if (auto thr_kill = thread->tproc->ops->thr_kill) { + return thr_kill(thread, id, sig); + } + + return ErrorCode::NOSYS; +} + +orbis::SysResult orbis::sys_thr_kill2(Thread *thread, pid_t pid, slong id, sint sig) { + if (auto thr_kill2 = thread->tproc->ops->thr_kill2) { + return thr_kill2(thread, pid, id, sig); + } + + return ErrorCode::NOSYS; +} + +orbis::SysResult orbis::sys_thr_suspend(Thread *thread, ptr timeout) { + if (auto thr_suspend = thread->tproc->ops->thr_suspend) { + return thr_suspend(thread, timeout); + } + + return ErrorCode::NOSYS; +} + +orbis::SysResult orbis::sys_thr_wake(Thread *thread, slong id) { + if (auto thr_wake = thread->tproc->ops->thr_wake) { + return thr_wake(thread, id); + } + + return ErrorCode::NOSYS; +} + +orbis::SysResult orbis::sys_thr_set_name(Thread *thread, slong id, ptr name) { + if (auto thr_set_name = thread->tproc->ops->thr_set_name) { + return thr_set_name(thread, id, name); + } + + return ErrorCode::NOSYS; +} diff --git a/orbis-kernel/src/sys/sys_time.cpp b/orbis-kernel/src/sys/sys_time.cpp new file mode 100644 index 000000000..d4f3709c0 --- /dev/null +++ b/orbis-kernel/src/sys/sys_time.cpp @@ -0,0 +1,15 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_clock_gettime(Thread *thread, clockid_t clock_id, ptr tp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_clock_settime(Thread *thread, clockid_t clock_id, ptr tp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_clock_getres(Thread *thread, clockid_t clock_id, ptr tp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_nanosleep(Thread *thread, ptr rqtp, ptr rmtp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_gettimeofday(Thread *thread, ptr tp, ptr tzp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_settimeofday(Thread *thread, ptr tp, ptr tzp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getitimer(Thread *thread, uint which, ptr itv) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setitimer(Thread *thread, uint which, ptr itv, ptr oitv) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_ktimer_create(Thread *thread, clockid_t clock_id, ptr evp, ptr timerid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_ktimer_delete(Thread *thread, sint timerid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_ktimer_settime(Thread *thread, sint timerid, sint flags, ptr value, ptr ovalue) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_ktimer_gettime(Thread *thread, sint timerid, ptr value) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_ktimer_getoverrun(Thread *thread, sint timerid) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_uipc.cpp b/orbis-kernel/src/sys/sys_uipc.cpp new file mode 100644 index 000000000..a72997f06 --- /dev/null +++ b/orbis-kernel/src/sys/sys_uipc.cpp @@ -0,0 +1,22 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_socket(Thread *thread, sint domain, sint type, sint protocol) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_bind(Thread *thread, sint s, caddr_t name, sint namelen) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_listen(Thread *thread, sint s, sint backlog) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_accept(Thread *thread, sint s, ptr from, ptr fromlenaddr) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_connect(Thread *thread, sint s, caddr_t name, sint namelen) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_socketpair(Thread *thread, sint domain, sint type, sint protocol, ptr rsv) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sendto(Thread *thread, sint s, caddr_t buf, size_t len, sint flags, caddr_t to, sint tolen) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sendmsg(Thread *thread, sint s, ptr msg, sint flags) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_recvfrom(Thread *thread, sint s, caddr_t buf, size_t len, sint flags, ptr from, ptr fromlenaddr) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_recvmsg(Thread *thread, sint s, ptr msg, sint flags) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_shutdown(Thread *thread, sint s, sint how) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_setsockopt(Thread *thread, sint s, sint level, sint name, caddr_t val, sint valsize) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getsockopt(Thread *thread, sint s, sint level, sint name, caddr_t val, ptr avalsize) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getsockname(Thread *thread, sint fdes, ptr asa, ptr alen) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getpeername(Thread *thread, sint fdes, ptr asa, ptr alen) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sendfile(Thread *thread, sint fd, sint s, off_t offset, size_t nbytes, ptr hdtr, ptr sbytes, sint flags) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sctp_peeloff(Thread *thread, sint sd, uint32_t name) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sctp_generic_sendmsg(Thread *thread, sint sd, caddr_t msg, sint mlen, caddr_t to, __socklen_t tolen, ptr sinfo, sint flags) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sctp_generic_sendmsg_iov(Thread *thread, sint sd, ptr iov, sint iovlen, caddr_t to, __socklen_t tolen, ptr sinfo, sint flags) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_sctp_generic_recvmsg(Thread *thread, sint sd, ptr iov, sint iovlen, caddr_t from, __socklen_t fromlen, ptr sinfo, sint flags) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_uipc_mqueue.cpp b/orbis-kernel/src/sys/sys_uipc_mqueue.cpp new file mode 100644 index 000000000..045bcc2d5 --- /dev/null +++ b/orbis-kernel/src/sys/sys_uipc_mqueue.cpp @@ -0,0 +1,8 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_kmq_open(Thread *thread, ptr path, sint flags, mode_t mode, ptr attr) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_kmq_unlink(Thread *thread, ptr path) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_kmq_setattr(Thread *thread, sint mqd, ptr attr, ptr oattr) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_kmq_timedreceive(Thread *thread, sint mqd, ptr msg_ptr, size_t msg_len, ptr msg_prio, ptr abstimeout) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_kmq_timedsend(Thread *thread, sint mqd, ptr msg_ptr, size_t msg_len, ptr msg_prio, ptr abstimeout) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_kmq_notify(Thread *thread, sint mqd, ptr sigev) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_uipc_sem.cpp b/orbis-kernel/src/sys/sys_uipc_sem.cpp new file mode 100644 index 000000000..b7eab485b --- /dev/null +++ b/orbis-kernel/src/sys/sys_uipc_sem.cpp @@ -0,0 +1,12 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_ksem_init(Thread *thread, ptr idp, uint value) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_ksem_open(Thread *thread, ptr idp, ptr name, sint oflag, mode_t mode, uint value) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_ksem_unlink(Thread *thread, ptr name) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_ksem_close(Thread *thread, semid_t id) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_ksem_post(Thread *thread, semid_t id) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_ksem_wait(Thread *thread, semid_t id) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_ksem_timedwait(Thread *thread, semid_t id, ptr abstime) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_ksem_trywait(Thread *thread, semid_t id) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_ksem_getvalue(Thread *thread, semid_t id, ptr value) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_ksem_destroy(Thread *thread, semid_t id) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_uipc_shm.cpp b/orbis-kernel/src/sys/sys_uipc_shm.cpp new file mode 100644 index 000000000..79ae5dbcb --- /dev/null +++ b/orbis-kernel/src/sys/sys_uipc_shm.cpp @@ -0,0 +1,4 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_shm_open(Thread *thread, ptr path, sint flags, mode_t mode) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_shm_unlink(Thread *thread, ptr path) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_umtx.cpp b/orbis-kernel/src/sys/sys_umtx.cpp new file mode 100644 index 000000000..2afd71409 --- /dev/null +++ b/orbis-kernel/src/sys/sys_umtx.cpp @@ -0,0 +1,8 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys__umtx_lock(Thread *thread, ptr umtx) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys__umtx_unlock(Thread *thread, ptr umtx) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys__umtx_op(Thread *thread, ptr obj, sint op, ulong val, ptr uaddr1, ptr uaddr2) { + std::printf("TODO: sys__umtx_op\n"); + return {}; +} diff --git a/orbis-kernel/src/sys/sys_uuid.cpp b/orbis-kernel/src/sys/sys_uuid.cpp new file mode 100644 index 000000000..c55196515 --- /dev/null +++ b/orbis-kernel/src/sys/sys_uuid.cpp @@ -0,0 +1,3 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_uuidgen(Thread *thread, ptr store, sint count) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_vfs.cpp b/orbis-kernel/src/sys/sys_vfs.cpp new file mode 100644 index 000000000..7f3f167b7 --- /dev/null +++ b/orbis-kernel/src/sys/sys_vfs.cpp @@ -0,0 +1,93 @@ +#include "sys/sysproto.hpp" +#include "utils/Logs.hpp" + +orbis::SysResult orbis::sys_sync(Thread *thread) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_quotactl(Thread *thread, ptr path, sint cmd, sint uid, caddr_t arg) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_statfs(Thread *thread, ptr path, ptr buf) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_fstatfs(Thread *thread, sint fd, ptr buf) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getfsstat(Thread *thread, ptr buf, slong bufsize, sint flags) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_fchdir(Thread *thread, sint fd) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_chdir(Thread *thread, ptr path) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_chroot(Thread *thread, ptr path) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_open(Thread *thread, ptr path, sint flags, sint mode) { + ORBIS_LOG_NOTICE("sys_open", path, flags, mode); + if (auto open = thread->tproc->ops->open) { + return open(thread, path, flags, mode); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_openat(Thread *thread, sint fd, ptr path, sint flag, mode_t mode) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_mknod(Thread *thread, ptr path, sint mode, sint dev) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_mknodat(Thread *thread, sint fd, ptr path, mode_t mode, dev_t dev) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_mkfifo(Thread *thread, ptr path, sint mode) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_mkfifoat(Thread *thread, sint fd, ptr path, mode_t mode) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_link(Thread *thread, ptr path, ptr link) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_linkat(Thread *thread, sint fd1, ptr path1, sint fd2, ptr path2, sint flag) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_symlink(Thread *thread, ptr path, ptr link) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_symlinkat(Thread *thread, ptr path1, sint fd, ptr path2) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_undelete(Thread *thread, ptr path) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_unlink(Thread *thread, ptr path) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_unlinkat(Thread *thread, sint fd, ptr path, sint flag) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_lseek(Thread *thread, sint fd, off_t offset, sint whence) { + if (auto lseek = thread->tproc->ops->lseek) { + return lseek(thread, fd, offset, whence); + } + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_freebsd6_lseek(Thread *thread, sint fd, sint, off_t offset, sint whence) { + return sys_lseek(thread, fd, offset, whence); +} +orbis::SysResult orbis::sys_access(Thread *thread, ptr path, sint flags) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_faccessat(Thread *thread, sint fd, ptr path, sint mode, sint flag) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_eaccess(Thread *thread, ptr path, sint flags) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_stat(Thread *thread, ptr path, ptr ub) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_fstatat(Thread *thread, sint fd, ptr path, ptr buf, sint flag) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_lstat(Thread *thread, ptr path, ptr ub) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_nstat(Thread *thread, ptr path, ptr ub) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_nlstat(Thread *thread, ptr path, ptr ub) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_pathconf(Thread *thread, ptr path, sint name) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_lpathconf(Thread *thread, ptr path, sint name) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_readlink(Thread *thread, ptr path, ptr buf, size_t count) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_readlinkat(Thread *thread, sint fd, ptr path, ptr buf, size_t bufsize) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_chflags(Thread *thread, ptr path, sint flags) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_lchflags(Thread *thread, ptr path, sint flags) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_fchflags(Thread *thread, sint fd, sint flags) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_chmod(Thread *thread, ptr path, sint mode) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_fchmodat(Thread *thread, sint fd, ptr path, mode_t mode, sint flag) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_lchmod(Thread *thread, ptr path, mode_t mode) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_fchmod(Thread *thread, sint fd, sint mode) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_chown(Thread *thread, ptr path, sint uid, sint gid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_fchownat(Thread *thread, sint fd, ptr path, uid_t uid, gid_t gid, sint flag) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_lchown(Thread *thread, ptr path, sint uid, sint gid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_fchown(Thread *thread, sint fd, sint uid, sint gid) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_utimes(Thread *thread, ptr path, ptr tptr) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_futimesat(Thread *thread, sint fd, ptr path, ptr times) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_lutimes(Thread *thread, ptr path, ptr tptr) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_futimes(Thread *thread, sint fd, ptr tptr) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_truncate(Thread *thread, ptr path, off_t length) { + if (auto truncate = thread->tproc->ops->truncate) { + return truncate(thread, path, length); + } + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_freebsd6_truncate(Thread *thread, ptr path, sint, off_t length) { + return sys_truncate(thread, path, length); +} +orbis::SysResult orbis::sys_fsync(Thread *thread, sint fd) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_rename(Thread *thread, ptr from, ptr to) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_renameat(Thread *thread, sint oldfd, ptr old, sint newfd, ptr new_) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_mkdir(Thread *thread, ptr path, sint mode) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_mkdirat(Thread *thread, sint fd, ptr path, mode_t mode) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_rmdir(Thread *thread, ptr path) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getdirentries(Thread *thread, sint fd, ptr buf, uint count, ptr basep) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getdents(Thread *thread, sint fd, ptr buf, size_t count) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_umask(Thread *thread, sint newmask) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_revoke(Thread *thread, ptr path) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_lgetfh(Thread *thread, ptr fname, ptr fhp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_getfh(Thread *thread, ptr fname, ptr fhp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_fhopen(Thread *thread, ptr u_fhp, sint flags) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_fhstat(Thread *thread, ptr u_fhp, ptr sb) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_fhstatfs(Thread *thread, ptr u_fhp, ptr buf) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_posix_fallocate(Thread *thread, sint fd, off_t offset, off_t len) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_posix_fadvise(Thread *thread, sint fd, off_t offset, off_t len, sint advice) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_vfs_acl.cpp b/orbis-kernel/src/sys/sys_vfs_acl.cpp new file mode 100644 index 000000000..1d1e3f3e0 --- /dev/null +++ b/orbis-kernel/src/sys/sys_vfs_acl.cpp @@ -0,0 +1,14 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys___acl_get_file(Thread *thread, ptr path, acl_type_t type, ptr aclp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___acl_get_link(Thread *thread, ptr path, acl_type_t type, ptr aclp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___acl_set_file(Thread *thread, ptr path, acl_type_t type, ptr aclp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___acl_set_link(Thread *thread, ptr path, acl_type_t type, ptr aclp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___acl_get_fd(Thread *thread, sint filedes, acl_type_t type, ptr aclp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___acl_set_fd(Thread *thread, sint filedes, acl_type_t type, ptr aclp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___acl_delete_link(Thread *thread, ptr path, acl_type_t type) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___acl_delete_file(Thread *thread, ptr path, acl_type_t type) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___acl_delete_fd(Thread *thread, sint filedes, acl_type_t type) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___acl_aclcheck_file(Thread *thread, ptr path, acl_type_t type, ptr aclp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___acl_aclcheck_link(Thread *thread, ptr path, acl_type_t type, ptr aclp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys___acl_aclcheck_fd(Thread *thread, sint filedes, acl_type_t type, ptr aclp) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_vfs_aio.cpp b/orbis-kernel/src/sys/sys_vfs_aio.cpp new file mode 100644 index 000000000..31325b7ab --- /dev/null +++ b/orbis-kernel/src/sys/sys_vfs_aio.cpp @@ -0,0 +1,15 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_aio_return(Thread *thread, ptr aiocbp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_aio_suspend(Thread *thread, ptr aiocbp, sint nent, ptr timeout) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_aio_cancel(Thread *thread, sint fd, ptr aiocbp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_aio_error(Thread *thread, ptr aiocbp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_oaio_read(Thread *thread, ptr aiocbp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_aio_read(Thread *thread, ptr aiocbp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_oaio_write(Thread *thread, ptr aiocbp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_aio_write(Thread *thread, ptr aiocbp) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_olio_listio(Thread *thread, sint mode, ptr> acb_list, sint nent, ptr sig) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_lio_listio(Thread *thread, sint mode, ptr> aiocbp, sint nent, ptr sig) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_aio_waitcomplete(Thread *thread, ptr> aiocbp, ptr timeout) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_aio_fsync(Thread *thread, sint op, ptr aiocbp) { return ErrorCode::NOSYS; } + diff --git a/orbis-kernel/src/sys/sys_vfs_cache.cpp b/orbis-kernel/src/sys/sys_vfs_cache.cpp new file mode 100644 index 000000000..ae0877913 --- /dev/null +++ b/orbis-kernel/src/sys/sys_vfs_cache.cpp @@ -0,0 +1,3 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys___getcwd(Thread *thread, ptr buf, uint buflen) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_vfs_extattr.cpp b/orbis-kernel/src/sys/sys_vfs_extattr.cpp new file mode 100644 index 000000000..72d8d0eab --- /dev/null +++ b/orbis-kernel/src/sys/sys_vfs_extattr.cpp @@ -0,0 +1,15 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_extattrctl(Thread *thread, ptr path, char cmd, ptr filename, sint attrnamespace, ptr attrname) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_extattr_set_fd(Thread *thread, sint fd, sint attrnamespace, ptr attrname, ptr data, size_t nbytes) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_extattr_set_file(Thread *thread, ptr path, sint attrnamespace, ptr filename, ptr data, size_t nbytes) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_extattr_set_link(Thread *thread, ptr path, sint attrnamespace, ptr attrname, ptr data, size_t nbytes) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_extattr_get_fd(Thread *thread, sint fd, sint attrnamespace, ptr attrname, ptr data, size_t nbytes) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_extattr_get_file(Thread *thread, ptr path, sint attrnamespace, ptr filename, ptr data, size_t nbytes) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_extattr_get_link(Thread *thread, ptr path, sint attrnamespace, ptr attrname, ptr data, size_t nbytes) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_extattr_delete_fd(Thread *thread, sint fd, sint attrnamespace, ptr attrname) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_extattr_delete_file(Thread *thread, ptr path, sint attrnamespace, ptr attrname) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_extattr_delete_link(Thread *thread, ptr path, sint attrnamespace, ptr attrname) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_extattr_list_fd(Thread *thread, sint fd, sint attrnamespace, ptr data, size_t nbytes) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_extattr_list_file(Thread *thread, ptr path, sint attrnamespace, ptr data, size_t nbytes) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_extattr_list_link(Thread *thread, ptr path, sint attrnamespace, ptr data, size_t nbytes) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_vfs_mount.cpp b/orbis-kernel/src/sys/sys_vfs_mount.cpp new file mode 100644 index 000000000..188160524 --- /dev/null +++ b/orbis-kernel/src/sys/sys_vfs_mount.cpp @@ -0,0 +1,5 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_mount(Thread *thread, ptr type, ptr path, sint flags, caddr_t data) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_unmount(Thread *thread, ptr path, sint flags) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_nmount(Thread *thread, ptr iovp, uint iovcnt, sint flags) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sys/sys_vm_mmap.cpp b/orbis-kernel/src/sys/sys_vm_mmap.cpp new file mode 100644 index 000000000..950a4ee44 --- /dev/null +++ b/orbis-kernel/src/sys/sys_vm_mmap.cpp @@ -0,0 +1,101 @@ +#include "error.hpp" +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_sbrk(Thread *, sint) { + return ErrorCode::OPNOTSUPP; +} +orbis::SysResult orbis::sys_sstk(Thread *, sint) { + return ErrorCode::OPNOTSUPP; +} + +orbis::SysResult orbis::sys_mmap(Thread *thread, caddr_t addr, size_t len, + sint prot, sint flags, sint fd, off_t pos) { + if (auto impl = thread->tproc->ops->mmap) { + return impl(thread, addr, len, prot, flags, fd, pos); + } + + return ErrorCode::NOSYS; +} + +orbis::SysResult orbis::sys_freebsd6_mmap(Thread *thread, caddr_t addr, + size_t len, sint prot, sint flags, + sint fd, sint, off_t pos) { + return sys_mmap(thread, addr, len, prot, flags, fd, pos); +} +orbis::SysResult orbis::sys_msync(Thread *thread, ptr addr, size_t len, + sint flags) { + if (auto impl = thread->tproc->ops->msync) { + return impl(thread, addr, len, flags); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_munmap(Thread *thread, ptr addr, size_t len) { + if (auto impl = thread->tproc->ops->munmap) { + return impl(thread, addr, len); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_mprotect(Thread *thread, ptr addr, + size_t len, sint prot) { + if (auto impl = thread->tproc->ops->mprotect) { + return impl(thread, addr, len, prot); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_minherit(Thread *thread, ptr addr, size_t len, + sint inherit) { + if (auto impl = thread->tproc->ops->minherit) { + return impl(thread, addr, len, inherit); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_madvise(Thread *thread, ptr addr, size_t len, + sint behav) { + if (auto impl = thread->tproc->ops->madvise) { + return impl(thread, addr, len, behav); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_mincore(Thread *thread, ptr addr, + size_t len, ptr vec) { + if (auto impl = thread->tproc->ops->mincore) { + return impl(thread, addr, len, vec); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_mlock(Thread *thread, ptr addr, + size_t len) { + if (auto impl = thread->tproc->ops->mlock) { + return impl(thread, addr, len); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_mlockall(Thread *thread, sint how) { + if (auto impl = thread->tproc->ops->mlockall) { + return impl(thread, how); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_munlockall(Thread *thread) { + if (auto impl = thread->tproc->ops->munlockall) { + return impl(thread); + } + + return ErrorCode::NOSYS; +} +orbis::SysResult orbis::sys_munlock(Thread *thread, ptr addr, + size_t len) { + if (auto impl = thread->tproc->ops->munlock) { + return impl(thread, addr, len); + } + + return ErrorCode::NOSYS; +} diff --git a/orbis-kernel/src/sys/sys_vm_unix.cpp b/orbis-kernel/src/sys/sys_vm_unix.cpp new file mode 100644 index 000000000..160316b04 --- /dev/null +++ b/orbis-kernel/src/sys/sys_vm_unix.cpp @@ -0,0 +1,4 @@ +#include "sys/sysproto.hpp" + +orbis::SysResult orbis::sys_obreak(Thread *thread, ptr nsize) { return ErrorCode::NOSYS; } +orbis::SysResult orbis::sys_ovadvise(Thread *thread, sint anom) { return ErrorCode::NOSYS; } diff --git a/orbis-kernel/src/sysvec.cpp b/orbis-kernel/src/sysvec.cpp new file mode 100644 index 000000000..00d615875 --- /dev/null +++ b/orbis-kernel/src/sysvec.cpp @@ -0,0 +1,2462 @@ +#include "sys/syscall.hpp" +#include "sys/sysproto.hpp" +#include "sys/sysentry.hpp" +#include + +enum { PSL_C = 0x1 }; + +void orbis::syscall_entry(Thread *thread) { + uint64_t regstbl[] = { + readRegister(thread->context, RegisterId::rdi), + readRegister(thread->context, RegisterId::rsi), + readRegister(thread->context, RegisterId::rdx), + readRegister(thread->context, RegisterId::r10), + readRegister(thread->context, RegisterId::r8), + readRegister(thread->context, RegisterId::r9), + }; + + uint64_t *regsptr = regstbl; + sint regcnt = 6; + + int syscall_num = readRegister(thread->context, RegisterId::rax); + if (syscall_num == kSYS_syscall || syscall_num == kSYS___syscall) { + syscall_num = *regsptr++; + --regcnt; + } + + thread->retval[0] = 0; + thread->retval[1] = readRegister(thread->context, RegisterId::rdx); + + int error = 0; + auto p = thread->tproc; + + if (syscall_num >= p->sysent->size) { + error = int(ErrorCode::NOSYS); + } else { + auto sysent = p->sysent->table[syscall_num]; + uint64_t args[8]; + std::memcpy(args, regsptr, + std::min(regcnt, sysent.narg) * sizeof(uint64_t)); + if (sysent.narg > regcnt) { + if (sysent.narg > std::ssize(args)) { + std::abort(); + } + + error = int(uread(args + regcnt, ptr(readRegister(thread->context, RegisterId::rsp) + sizeof(uint64_t)), + (sysent.narg - regcnt) * sizeof(uint64_t))); + } + + if (error == 0) { + if (thread->tproc->onSysEnter != nullptr) { + thread->tproc->onSysEnter(thread, syscall_num, args, sysent.narg); + } + + auto result = sysent.call(thread, args); + + if (thread->tproc->onSysExit != nullptr) { + thread->tproc->onSysExit(thread, syscall_num, args, sysent.narg, + result); + } + + error = result.value(); + } + } + + auto rflags = readRegister(thread->context, RegisterId::rflags); + + if (error == 0) { + writeRegister(thread->context, RegisterId::rax, thread->retval[0]); + writeRegister(thread->context, RegisterId::rdx, thread->retval[1]); + writeRegister(thread->context, RegisterId::rflags, rflags & ~PSL_C); + } else { + writeRegister(thread->context, RegisterId::rax, error); + writeRegister(thread->context, RegisterId::rflags, rflags | PSL_C); + } +} + +namespace orbis { +namespace detail { +template struct WrapImpl; + +template + requires(sizeof...(Args) < 8) +struct WrapImpl { + constexpr sysent operator()() { + sysent result; + result.narg = sizeof...(Args); + result.call = &WrapImpl::call; + + return result; + } + +private: + static SysResult call(Thread *thread, uint64_t *args) { + return callImpl(thread, args, std::index_sequence_for{}); + } + + template + static SysResult callImpl(Thread *thread, uint64_t *args, + std::index_sequence) { + return Fn(thread, Args(args[I])...); + } +}; +} // namespace detail + +template constexpr auto wrap() -> decltype(detail::WrapImpl()()) { + return detail::WrapImpl()(); +} + +static const std::unordered_map gImplToName = { + {wrap().call, "nosys"}, + {wrap().call, "sys_exit"}, + {wrap().call, "sys_fork"}, + {wrap().call, "sys_read"}, + {wrap().call, "sys_write"}, + {wrap().call, "sys_open"}, + {wrap().call, "sys_close"}, + {wrap().call, "sys_wait4"}, + {wrap().call, "sys_link"}, + {wrap().call, "sys_unlink"}, + {wrap().call, "sys_chdir"}, + {wrap().call, "sys_fchdir"}, + {wrap().call, "sys_mknod"}, + {wrap().call, "sys_chmod"}, + {wrap().call, "sys_chown"}, + {wrap().call, "sys_obreak"}, + {wrap().call, "sys_getpid"}, + {wrap().call, "sys_mount"}, + {wrap().call, "sys_unmount"}, + {wrap().call, "sys_setuid"}, + {wrap().call, "sys_getuid"}, + {wrap().call, "sys_geteuid"}, + {wrap().call, "sys_ptrace"}, + {wrap().call, "sys_recvmsg"}, + {wrap().call, "sys_sendmsg"}, + {wrap().call, "sys_recvfrom"}, + {wrap().call, "sys_accept"}, + {wrap().call, "sys_getpeername"}, + {wrap().call, "sys_getsockname"}, + {wrap().call, "sys_access"}, + {wrap().call, "sys_chflags"}, + {wrap().call, "sys_fchflags"}, + {wrap().call, "sys_sync"}, + {wrap().call, "sys_kill"}, + {wrap().call, "sys_getppid"}, + {wrap().call, "sys_dup"}, + {wrap().call, "sys_pipe"}, + {wrap().call, "sys_getegid"}, + {wrap().call, "sys_profil"}, + {wrap().call, "sys_ktrace"}, + {wrap().call, "sys_getgid"}, + {wrap().call, "sys_getlogin"}, + {wrap().call, "sys_setlogin"}, + {wrap().call, "sys_acct"}, + {wrap().call, "sys_sigaltstack"}, + {wrap().call, "sys_ioctl"}, + {wrap().call, "sys_reboot"}, + {wrap().call, "sys_revoke"}, + {wrap().call, "sys_symlink"}, + {wrap().call, "sys_readlink"}, + {wrap().call, "sys_execve"}, + {wrap().call, "sys_umask"}, + {wrap().call, "sys_chroot"}, + {wrap().call, "sys_msync"}, + {wrap().call, "sys_vfork"}, + {wrap().call, "sys_sbrk"}, + {wrap().call, "sys_sstk"}, + {wrap().call, "sys_ovadvise"}, + {wrap().call, "sys_munmap"}, + {wrap().call, "sys_mprotect"}, + {wrap().call, "sys_madvise"}, + {wrap().call, "sys_mincore"}, + {wrap().call, "sys_getgroups"}, + {wrap().call, "sys_setgroups"}, + {wrap().call, "sys_getpgrp"}, + {wrap().call, "sys_setpgid"}, + {wrap().call, "sys_setitimer"}, + {wrap().call, "sys_swapon"}, + {wrap().call, "sys_getitimer"}, + {wrap().call, "sys_getdtablesize"}, + {wrap().call, "sys_dup2"}, + {wrap().call, "sys_fcntl"}, + {wrap().call, "sys_select"}, + {wrap().call, "sys_fsync"}, + {wrap().call, "sys_setpriority"}, + {wrap().call, "sys_socket"}, + {wrap().call, "sys_connect"}, + {wrap().call, "sys_getpriority"}, + {wrap().call, "sys_bind"}, + {wrap().call, "sys_setsockopt"}, + {wrap().call, "sys_listen"}, + {wrap().call, "sys_gettimeofday"}, + {wrap().call, "sys_getrusage"}, + {wrap().call, "sys_getsockopt"}, + {wrap().call, "sys_readv"}, + {wrap().call, "sys_writev"}, + {wrap().call, "sys_settimeofday"}, + {wrap().call, "sys_fchown"}, + {wrap().call, "sys_fchmod"}, + {wrap().call, "sys_setreuid"}, + {wrap().call, "sys_setregid"}, + {wrap().call, "sys_rename"}, + {wrap().call, "sys_flock"}, + {wrap().call, "sys_mkfifo"}, + {wrap().call, "sys_sendto"}, + {wrap().call, "sys_shutdown"}, + {wrap().call, "sys_socketpair"}, + {wrap().call, "sys_mkdir"}, + {wrap().call, "sys_rmdir"}, + {wrap().call, "sys_utimes"}, + {wrap().call, "sys_adjtime"}, + {wrap().call, "sys_setsid"}, + {wrap().call, "sys_quotactl"}, + {wrap().call, "sys_nlm_syscall"}, + {wrap().call, "sys_nfssvc"}, + {wrap().call, "sys_lgetfh"}, + {wrap().call, "sys_getfh"}, + {wrap().call, "sys_sysarch"}, + {wrap().call, "sys_rtprio"}, + {wrap().call, "sys_semsys"}, + {wrap().call, "sys_msgsys"}, + {wrap().call, "sys_shmsys"}, + {wrap().call, "sys_freebsd6_pread"}, + {wrap().call, "sys_freebsd6_pwrite"}, + {wrap().call, "sys_setfib"}, + {wrap().call, "sys_ntp_adjtime"}, + {wrap().call, "sys_setgid"}, + {wrap().call, "sys_setegid"}, + {wrap().call, "sys_seteuid"}, + {wrap().call, "sys_stat"}, + {wrap().call, "sys_fstat"}, + {wrap().call, "sys_lstat"}, + {wrap().call, "sys_pathconf"}, + {wrap().call, "sys_fpathconf"}, + {wrap().call, "sys_getrlimit"}, + {wrap().call, "sys_setrlimit"}, + {wrap().call, "sys_getdirentries"}, + {wrap().call, "sys_freebsd6_mmap"}, + {wrap().call, "sys_freebsd6_lseek"}, + {wrap().call, "sys_freebsd6_truncate"}, + {wrap().call, "sys_freebsd6_ftruncate"}, + {wrap().call, "sys___sysctl"}, + {wrap().call, "sys_mlock"}, + {wrap().call, "sys_munlock"}, + {wrap().call, "sys_undelete"}, + {wrap().call, "sys_futimes"}, + {wrap().call, "sys_getpgid"}, + {wrap().call, "sys_poll"}, + {wrap().call, "sys_semget"}, + {wrap().call, "sys_semop"}, + {wrap().call, "sys_msgget"}, + {wrap().call, "sys_msgsnd"}, + {wrap().call, "sys_msgrcv"}, + {wrap().call, "sys_shmat"}, + {wrap().call, "sys_shmdt"}, + {wrap().call, "sys_shmget"}, + {wrap().call, "sys_clock_gettime"}, + {wrap().call, "sys_clock_settime"}, + {wrap().call, "sys_clock_getres"}, + {wrap().call, "sys_ktimer_create"}, + {wrap().call, "sys_ktimer_delete"}, + {wrap().call, "sys_ktimer_settime"}, + {wrap().call, "sys_ktimer_gettime"}, + {wrap().call, "sys_ktimer_getoverrun"}, + {wrap().call, "sys_nanosleep"}, + {wrap().call, "sys_ntp_gettime"}, + {wrap().call, "sys_minherit"}, + {wrap().call, "sys_rfork"}, + {wrap().call, "sys_openbsd_poll"}, + {wrap().call, "sys_issetugid"}, + {wrap().call, "sys_lchown"}, + {wrap().call, "sys_aio_read"}, + {wrap().call, "sys_aio_write"}, + {wrap().call, "sys_lio_listio"}, + {wrap().call, "sys_getdents"}, + {wrap().call, "sys_lchmod"}, + {wrap().call, "sys_lutimes"}, + {wrap().call, "sys_nstat"}, + {wrap().call, "sys_nfstat"}, + {wrap().call, "sys_nlstat"}, + {wrap().call, "sys_preadv"}, + {wrap().call, "sys_pwritev"}, + {wrap().call, "sys_fhopen"}, + {wrap().call, "sys_fhstat"}, + {wrap().call, "sys_modnext"}, + {wrap().call, "sys_modstat"}, + {wrap().call, "sys_modfnext"}, + {wrap().call, "sys_modfind"}, + {wrap().call, "sys_kldload"}, + {wrap().call, "sys_kldunload"}, + {wrap().call, "sys_kldfind"}, + {wrap().call, "sys_kldnext"}, + {wrap().call, "sys_kldstat"}, + {wrap().call, "sys_kldfirstmod"}, + {wrap().call, "sys_getsid"}, + {wrap().call, "sys_setresuid"}, + {wrap().call, "sys_setresgid"}, + {wrap().call, "sys_aio_return"}, + {wrap().call, "sys_aio_suspend"}, + {wrap().call, "sys_aio_cancel"}, + {wrap().call, "sys_aio_error"}, + {wrap().call, "sys_oaio_read"}, + {wrap().call, "sys_oaio_write"}, + {wrap().call, "sys_olio_listio"}, + {wrap().call, "sys_yield"}, + {wrap().call, "sys_mlockall"}, + {wrap().call, "sys_munlockall"}, + {wrap().call, "sys___getcwd"}, + {wrap().call, "sys_sched_setparam"}, + {wrap().call, "sys_sched_getparam"}, + {wrap().call, "sys_sched_setscheduler"}, + {wrap().call, "sys_sched_getscheduler"}, + {wrap().call, "sys_sched_yield"}, + {wrap().call, "sys_sched_get_priority_max"}, + {wrap().call, "sys_sched_get_priority_min"}, + {wrap().call, "sys_sched_rr_get_interval"}, + {wrap().call, "sys_utrace"}, + {wrap().call, "sys_kldsym"}, + {wrap().call, "sys_jail"}, + {wrap().call, "sys_nnpfs_syscall"}, + {wrap().call, "sys_sigprocmask"}, + {wrap().call, "sys_sigsuspend"}, + {wrap().call, "sys_sigpending"}, + {wrap().call, "sys_sigtimedwait"}, + {wrap().call, "sys_sigwaitinfo"}, + {wrap().call, "sys___acl_get_file"}, + {wrap().call, "sys___acl_set_file"}, + {wrap().call, "sys___acl_get_fd"}, + {wrap().call, "sys___acl_set_fd"}, + {wrap().call, "sys___acl_delete_file"}, + {wrap().call, "sys___acl_delete_fd"}, + {wrap().call, "sys___acl_aclcheck_file"}, + {wrap().call, "sys___acl_aclcheck_fd"}, + {wrap().call, "sys_extattrctl"}, + {wrap().call, "sys_extattr_set_file"}, + {wrap().call, "sys_extattr_get_file"}, + {wrap().call, "sys_extattr_delete_file"}, + {wrap().call, "sys_aio_waitcomplete"}, + {wrap().call, "sys_getresuid"}, + {wrap().call, "sys_getresgid"}, + {wrap().call, "sys_kqueue"}, + {wrap().call, "sys_kevent"}, + {wrap().call, "sys_extattr_set_fd"}, + {wrap().call, "sys_extattr_get_fd"}, + {wrap().call, "sys_extattr_delete_fd"}, + {wrap().call, "sys___setugid"}, + {wrap().call, "sys_eaccess"}, + {wrap().call, "sys_afs3_syscall"}, + {wrap().call, "sys_nmount"}, + {wrap().call, "sys___mac_get_proc"}, + {wrap().call, "sys___mac_set_proc"}, + {wrap().call, "sys___mac_get_fd"}, + {wrap().call, "sys___mac_get_file"}, + {wrap().call, "sys___mac_set_fd"}, + {wrap().call, "sys___mac_set_file"}, + {wrap().call, "sys_kenv"}, + {wrap().call, "sys_lchflags"}, + {wrap().call, "sys_uuidgen"}, + {wrap().call, "sys_sendfile"}, + {wrap().call, "sys_mac_syscall"}, + {wrap().call, "sys_getfsstat"}, + {wrap().call, "sys_statfs"}, + {wrap().call, "sys_fstatfs"}, + {wrap().call, "sys_fhstatfs"}, + {wrap().call, "sys_ksem_close"}, + {wrap().call, "sys_ksem_post"}, + {wrap().call, "sys_ksem_wait"}, + {wrap().call, "sys_ksem_trywait"}, + {wrap().call, "sys_ksem_init"}, + {wrap().call, "sys_ksem_open"}, + {wrap().call, "sys_ksem_unlink"}, + {wrap().call, "sys_ksem_getvalue"}, + {wrap().call, "sys_ksem_destroy"}, + {wrap().call, "sys___mac_get_pid"}, + {wrap().call, "sys___mac_get_link"}, + {wrap().call, "sys___mac_set_link"}, + {wrap().call, "sys_extattr_set_link"}, + {wrap().call, "sys_extattr_get_link"}, + {wrap().call, "sys_extattr_delete_link"}, + {wrap().call, "sys___mac_execve"}, + {wrap().call, "sys_sigaction"}, + {wrap().call, "sys_sigreturn"}, + {wrap().call, "sys_getcontext"}, + {wrap().call, "sys_setcontext"}, + {wrap().call, "sys_swapcontext"}, + {wrap().call, "sys_swapoff"}, + {wrap().call, "sys___acl_get_link"}, + {wrap().call, "sys___acl_set_link"}, + {wrap().call, "sys___acl_delete_link"}, + {wrap().call, "sys___acl_aclcheck_link"}, + {wrap().call, "sys_sigwait"}, + {wrap().call, "sys_thr_create"}, + {wrap().call, "sys_thr_exit"}, + {wrap().call, "sys_thr_self"}, + {wrap().call, "sys_thr_kill"}, + {wrap().call, "sys__umtx_lock"}, + {wrap().call, "sys__umtx_unlock"}, + {wrap().call, "sys_jail_attach"}, + {wrap().call, "sys_extattr_list_fd"}, + {wrap().call, "sys_extattr_list_file"}, + {wrap().call, "sys_extattr_list_link"}, + {wrap().call, "sys_ksem_timedwait"}, + {wrap().call, "sys_thr_suspend"}, + {wrap().call, "sys_thr_wake"}, + {wrap().call, "sys_kldunloadf"}, + {wrap().call, "sys_audit"}, + {wrap().call, "sys_auditon"}, + {wrap().call, "sys_getauid"}, + {wrap().call, "sys_setauid"}, + {wrap().call, "sys_getaudit"}, + {wrap().call, "sys_setaudit"}, + {wrap().call, "sys_getaudit_addr"}, + {wrap().call, "sys_setaudit_addr"}, + {wrap().call, "sys_auditctl"}, + {wrap().call, "sys__umtx_op"}, + {wrap().call, "sys_thr_new"}, + {wrap().call, "sys_sigqueue"}, + {wrap().call, "sys_kmq_open"}, + {wrap().call, "sys_kmq_setattr"}, + {wrap().call, "sys_kmq_timedreceive"}, + {wrap().call, "sys_kmq_timedsend"}, + {wrap().call, "sys_kmq_notify"}, + {wrap().call, "sys_kmq_unlink"}, + {wrap().call, "sys_abort2"}, + {wrap().call, "sys_thr_set_name"}, + {wrap().call, "sys_aio_fsync"}, + {wrap().call, "sys_rtprio_thread"}, + {wrap().call, "sys_sctp_peeloff"}, + {wrap().call, "sys_sctp_generic_sendmsg"}, + {wrap().call, "sys_sctp_generic_sendmsg_iov"}, + {wrap().call, "sys_sctp_generic_recvmsg"}, + {wrap().call, "sys_pread"}, + {wrap().call, "sys_pwrite"}, + {wrap().call, "sys_mmap"}, + {wrap().call, "sys_lseek"}, + {wrap().call, "sys_truncate"}, + {wrap().call, "sys_ftruncate"}, + {wrap().call, "sys_thr_kill2"}, + {wrap().call, "sys_shm_open"}, + {wrap().call, "sys_shm_unlink"}, + {wrap().call, "sys_cpuset"}, + {wrap().call, "sys_cpuset_setid"}, + {wrap().call, "sys_cpuset_getid"}, + {wrap().call, "sys_cpuset_getaffinity"}, + {wrap().call, "sys_cpuset_setaffinity"}, + {wrap().call, "sys_faccessat"}, + {wrap().call, "sys_fchmodat"}, + {wrap().call, "sys_fchownat"}, + {wrap().call, "sys_fexecve"}, + {wrap().call, "sys_fstatat"}, + {wrap().call, "sys_futimesat"}, + {wrap().call, "sys_linkat"}, + {wrap().call, "sys_mkdirat"}, + {wrap().call, "sys_mkfifoat"}, + {wrap().call, "sys_mknodat"}, + {wrap().call, "sys_openat"}, + {wrap().call, "sys_readlinkat"}, + {wrap().call, "sys_renameat"}, + {wrap().call, "sys_symlinkat"}, + {wrap().call, "sys_unlinkat"}, + {wrap().call, "sys_posix_openpt"}, + {wrap().call, "sys_gssd_syscall"}, + {wrap().call, "sys_jail_get"}, + {wrap().call, "sys_jail_set"}, + {wrap().call, "sys_jail_remove"}, + {wrap().call, "sys_closefrom"}, + {wrap().call, "sys___semctl"}, + {wrap().call, "sys_msgctl"}, + {wrap().call, "sys_shmctl"}, + {wrap().call, "sys_lpathconf"}, + {wrap().call, "sys_cap_new"}, + {wrap().call, "sys_cap_getrights"}, + {wrap().call, "sys_cap_enter"}, + {wrap().call, "sys_cap_getmode"}, + {wrap().call, "sys_pdfork"}, + {wrap().call, "sys_pdkill"}, + {wrap().call, "sys_pdgetpid"}, + {wrap().call, "sys_pselect"}, + {wrap().call, "sys_getloginclass"}, + {wrap().call, "sys_setloginclass"}, + {wrap().call, "sys_rctl_get_racct"}, + {wrap().call, "sys_rctl_get_rules"}, + {wrap().call, "sys_rctl_get_limits"}, + {wrap().call, "sys_rctl_add_rule"}, + {wrap().call, "sys_rctl_remove_rule"}, + {wrap().call, "sys_posix_fallocate"}, + {wrap().call, "sys_posix_fadvise"}, + {wrap().call, "sys_netcontrol"}, + {wrap().call, "sys_netabort"}, + {wrap().call, "sys_netgetsockinfo"}, + {wrap().call, "sys_socketex"}, + {wrap().call, "sys_socketclose"}, + {wrap().call, "sys_netgetiflist"}, + {wrap().call, "sys_kqueueex"}, + {wrap().call, "sys_mtypeprotect"}, + {wrap().call, "sys_regmgr_call"}, + {wrap().call, "sys_jitshm_create"}, + {wrap().call, "sys_jitshm_alias"}, + {wrap().call, "sys_dl_get_list"}, + {wrap().call, "sys_dl_get_info"}, + {wrap().call, "sys_dl_notify_event"}, + {wrap().call, "sys_evf_create"}, + {wrap().call, "sys_evf_delete"}, + {wrap().call, "sys_evf_open"}, + {wrap().call, "sys_evf_close"}, + {wrap().call, "sys_evf_wait"}, + {wrap().call, "sys_evf_trywait"}, + {wrap().call, "sys_evf_set"}, + {wrap().call, "sys_evf_clear"}, + {wrap().call, "sys_evf_cancel"}, + {wrap().call, "sys_query_memory_protection"}, + {wrap().call, "sys_batch_map"}, + {wrap().call, "sys_osem_create"}, + {wrap().call, "sys_osem_delete"}, + {wrap().call, "sys_osem_open"}, + {wrap().call, "sys_osem_close"}, + {wrap().call, "sys_osem_wait"}, + {wrap().call, "sys_osem_trywait"}, + {wrap().call, "sys_osem_post"}, + {wrap().call, "sys_osem_cancel"}, + {wrap().call, "sys_namedobj_create"}, + {wrap().call, "sys_namedobj_delete"}, + {wrap().call, "sys_set_vm_container"}, + {wrap().call, "sys_debug_init"}, + {wrap().call, "sys_suspend_process"}, + {wrap().call, "sys_resume_process"}, + {wrap().call, "sys_opmc_enable"}, + {wrap().call, "sys_opmc_disable"}, + {wrap().call, "sys_opmc_set_ctl"}, + {wrap().call, "sys_opmc_set_ctr"}, + {wrap().call, "sys_opmc_get_ctr"}, + {wrap().call, "sys_budget_create"}, + {wrap().call, "sys_budget_delete"}, + {wrap().call, "sys_budget_get"}, + {wrap().call, "sys_budget_set"}, + {wrap().call, "sys_virtual_query"}, + {wrap().call, "sys_mdbg_call"}, + {wrap().call, "sys_obs_sblock_create"}, + {wrap().call, "sys_obs_sblock_delete"}, + {wrap().call, "sys_obs_sblock_enter"}, + {wrap().call, "sys_obs_sblock_exit"}, + {wrap().call, "sys_obs_sblock_xenter"}, + {wrap().call, "sys_obs_sblock_xexit"}, + {wrap().call, "sys_obs_eport_create"}, + {wrap().call, "sys_obs_eport_delete"}, + {wrap().call, "sys_obs_eport_trigger"}, + {wrap().call, "sys_obs_eport_open"}, + {wrap().call, "sys_obs_eport_close"}, + {wrap().call, "sys_is_in_sandbox"}, + {wrap().call, "sys_dmem_container"}, + {wrap().call, "sys_get_authinfo"}, + {wrap().call, "sys_mname"}, + {wrap().call, "sys_dynlib_dlopen"}, + {wrap().call, "sys_dynlib_dlclose"}, + {wrap().call, "sys_dynlib_dlsym"}, + {wrap().call, "sys_dynlib_get_list"}, + {wrap().call, "sys_dynlib_get_info"}, + {wrap().call, "sys_dynlib_load_prx"}, + {wrap().call, "sys_dynlib_unload_prx"}, + {wrap().call, "sys_dynlib_do_copy_relocations"}, + {wrap().call, "sys_dynlib_prepare_dlclose"}, + {wrap().call, "sys_dynlib_get_proc_param"}, + {wrap().call, "sys_dynlib_process_needed_and_relocate"}, + {wrap().call, "sys_sandbox_path"}, + {wrap().call, "sys_mdbg_service"}, + {wrap().call, "sys_randomized_path"}, + {wrap().call, "sys_rdup"}, + {wrap().call, "sys_dl_get_metadata"}, + {wrap().call, "sys_workaround8849"}, + {wrap().call, "sys_is_development_mode"}, + {wrap().call, "sys_get_self_auth_info"}, + {wrap().call, "sys_dynlib_get_info_ex"}, + {wrap().call, "sys_budget_getid"}, + {wrap().call, "sys_budget_get_ptype"}, + {wrap().call, "sys_get_paging_stats_of_all_threads"}, + {wrap().call, "sys_get_proc_type_info"}, + {wrap().call, "sys_get_resident_count"}, + {wrap().call, "sys_prepare_to_suspend_process"}, + {wrap().call, "sys_get_resident_fmem_count"}, + {wrap().call, "sys_thr_get_name"}, + {wrap().call, "sys_set_gpo"}, + {wrap().call, "sys_get_paging_stats_of_all_objects"}, + {wrap().call, "sys_test_debug_rwmem"}, + {wrap().call, "sys_free_stack"}, + {wrap().call, "sys_suspend_system"}, + {wrap().call, "sys_ipmimgr_call"}, + {wrap().call, "sys_get_gpo"}, + {wrap().call, "sys_get_vm_map_timestamp"}, + {wrap().call, "sys_opmc_set_hw"}, + {wrap().call, "sys_opmc_get_hw"}, + {wrap().call, "sys_get_cpu_usage_all"}, + {wrap().call, "sys_mmap_dmem"}, + {wrap().call, "sys_physhm_open"}, + {wrap().call, "sys_physhm_unlink"}, + {wrap().call, "sys_resume_internal_hdd"}, + {wrap().call, "sys_thr_suspend_ucontext"}, + {wrap().call, "sys_thr_resume_ucontext"}, + {wrap().call, "sys_thr_get_ucontext"}, + {wrap().call, "sys_thr_set_ucontext"}, + {wrap().call, "sys_set_timezone_info"}, + {wrap().call, "sys_set_phys_fmem_limit"}, + {wrap().call, "sys_utc_to_localtime"}, + {wrap().call, "sys_localtime_to_utc"}, + {wrap().call, "sys_set_uevt"}, + {wrap().call, "sys_get_cpu_usage_proc"}, + {wrap().call, "sys_get_map_statistics"}, + {wrap().call, "sys_set_chicken_switches"}, + {wrap().call, "sys_extend_page_table_pool"}, + {wrap().call, "sys_extend_page_table_pool2"}, + {wrap().call, "sys_get_kernel_mem_statistics"}, + {wrap().call, "sys_get_sdk_compiled_version"}, + {wrap().call, "sys_app_state_change"}, + {wrap().call, "sys_dynlib_get_obj_member"}, + {wrap().call, "sys_budget_get_ptype_of_budget"}, + {wrap().call, "sys_prepare_to_resume_process"}, + {wrap().call, "sys_process_terminate"}, + {wrap().call, "sys_blockpool_open"}, + {wrap().call, "sys_blockpool_map"}, + {wrap().call, "sys_blockpool_unmap"}, + {wrap().call, "sys_dynlib_get_info_for_libdbg"}, + {wrap().call, "sys_blockpool_batch"}, + {wrap().call, "sys_fdatasync"}, + {wrap().call, "sys_dynlib_get_list2"}, + {wrap().call, "sys_dynlib_get_info2"}, + {wrap().call, "sys_aio_submit"}, + {wrap().call, "sys_aio_multi_delete"}, + {wrap().call, "sys_aio_multi_wait"}, + {wrap().call, "sys_aio_multi_poll"}, + {wrap().call, "sys_aio_get_data"}, + {wrap().call, "sys_aio_multi_cancel"}, + {wrap().call, "sys_get_bio_usage_all"}, + {wrap().call, "sys_aio_create"}, + {wrap().call, "sys_aio_submit_cmd"}, + {wrap().call, "sys_aio_init"}, + {wrap().call, "sys_get_page_table_stats"}, + {wrap().call, "sys_dynlib_get_list_for_libdbg"}, + {wrap().call, "sys_blockpool_move"}, + {wrap().call, "sys_virtual_query_all"}, + {wrap().call, "sys_reserve_2mb_page"}, + {wrap().call, "sys_cpumode_yield"}, + {wrap().call, "sys_wait6"}, + {wrap().call, "sys_cap_rights_limit"}, + {wrap().call, "sys_cap_ioctls_limit"}, + {wrap().call, "sys_cap_ioctls_get"}, + {wrap().call, "sys_cap_fcntls_limit"}, + {wrap().call, "sys_cap_fcntls_get"}, + {wrap().call, "sys_bindat"}, + {wrap().call, "sys_connectat"}, + {wrap().call, "sys_chflagsat"}, + {wrap().call, "sys_accept4"}, + {wrap().call, "sys_pipe2"}, + {wrap().call, "sys_aio_mlock"}, + {wrap().call, "sys_procctl"}, + {wrap().call, "sys_ppoll"}, + {wrap().call, "sys_futimens"}, + {wrap().call, "sys_utimensat"}, + {wrap().call, "sys_numa_getaffinity"}, + {wrap().call, "sys_numa_setaffinity"}, + {wrap().call, "sys_apr_submit"}, + {wrap().call, "sys_apr_resolve"}, + {wrap().call, "sys_apr_stat"}, + {wrap().call, "sys_apr_wait"}, + {wrap().call, "sys_apr_ctrl"}, + {wrap().call, "sys_get_phys_page_size"}, + {wrap().call, "sys_begin_app_mount"}, + {wrap().call, "sys_end_app_mount"}, + {wrap().call, "sys_fsc2h_ctrl"}, + {wrap().call, "sys_streamwrite"}, + {wrap().call, "sys_app_save"}, + {wrap().call, "sys_app_restore"}, + {wrap().call, "sys_saved_app_delete"}, + {wrap().call, "sys_get_ppr_sdk_compiled_version"}, + {wrap().call, "sys_notify_app_event"}, + {wrap().call, "sys_ioreq"}, + {wrap().call, "sys_openintr"}, + {wrap().call, "sys_dl_get_info_2"}, + {wrap().call, "sys_acinfo_add"}, + {wrap().call, "sys_acinfo_delete"}, + {wrap().call, "sys_acinfo_get_all_for_coredump"}, + {wrap().call, "sys_ampr_ctrl_debug"}, + {wrap().call, "sys_workspace_ctrl"}, +}; + +const char *getSysentName(SysResult (*sysent)(Thread *, uint64_t *)) { + auto it = gImplToName.find(sysent); + if (it == gImplToName.end()) { + return nullptr; + } + + return it->second; +} + +static constexpr sysent freebsd9_sysent[] = { + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), +}; + +// TODO +static constexpr sysent freebsd11_sysent[] = { + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), +}; + +static constexpr sysent ps4_sysent[] = { + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), + wrap(), +}; + +constinit sysentvec freebsd9_sysvec = { + .size = std::size(freebsd9_sysent), + .table = freebsd9_sysent +}; + +constinit sysentvec freebsd11_sysvec = { + .size = std::size(freebsd11_sysent), + .table = freebsd11_sysent +}; + +constinit sysentvec ps4_sysvec = { + .size = std::size(ps4_sysent), + .table = ps4_sysent +}; + +constinit sysentvec ps5_sysvec = { + .size = 0, + .table = nullptr +}; +} // namespace orbis diff --git a/orbis-kernel/src/utils/Logs.cpp b/orbis-kernel/src/utils/Logs.cpp new file mode 100644 index 000000000..9eaf86aa6 --- /dev/null +++ b/orbis-kernel/src/utils/Logs.cpp @@ -0,0 +1,172 @@ +#include "utils/Logs.hpp" +#include +#include +#include +#include +#include + +static void append_hex(std::string &out, std::uintmax_t value) { + std::ostringstream buf; + buf << "0x" << std::hex << value; + out += buf.str(); +} + +namespace orbis::logs { +void log_class_string::format(std::string &out, const void *arg) { + const void *ptr = *reinterpret_cast(arg); + append_hex(out, reinterpret_cast(ptr)); +} + +void log_class_string::format(std::string &out, const void *arg) { + out += *reinterpret_cast(arg); +} + +template <> +void log_class_string::format(std::string &out, const void *arg) { + out += get_object(arg); +} + +template <> +void log_class_string::format(std::string &out, + const void *arg) { + out += get_object(arg); +} + +template <> +void log_class_string>::format(std::string &out, + const void *arg) { + const std::vector &obj = get_object(arg); + out.append(obj.cbegin(), obj.cend()); +} + +template <> +void log_class_string::format(std::string &out, + const void *arg) { + const std::u8string &obj = get_object(arg); + out.append(obj.cbegin(), obj.cend()); +} + +template <> +void log_class_string::format(std::string &out, + const void *arg) { + const std::u8string_view &obj = get_object(arg); + out.append(obj.cbegin(), obj.cend()); +} + +template <> +void log_class_string>::format(std::string &out, + const void *arg) { + const std::vector &obj = get_object(arg); + out.append(obj.cbegin(), obj.cend()); +} + +template <> +void log_class_string::format(std::string &out, const void *arg) { + append_hex(out, static_cast(get_object(arg))); +} + +template <> +void log_class_string::format(std::string &out, + const void *arg) { + append_hex(out, get_object(arg)); +} + +template <> +void log_class_string::format(std::string &out, const void *arg) { + append_hex(out, static_cast(get_object(arg))); +} + +template <> +void log_class_string::format(std::string &out, const void *arg) { + append_hex(out, static_cast(get_object(arg))); +} + +template <> +void log_class_string::format(std::string &out, const void *arg) { + append_hex(out, get_object(arg)); +} + +template <> +void log_class_string::format(std::string &out, const void *arg) { + append_hex(out, static_cast(get_object(arg))); +} + +template <> +void log_class_string::format(std::string &out, const void *arg) { + append_hex(out, get_object(arg)); +} + +template <> +void log_class_string::format(std::string &out, const void *arg) { + append_hex(out, static_cast(get_object(arg))); +} + +template <> +void log_class_string::format(std::string &out, const void *arg) { + append_hex(out, get_object(arg)); +} + +template <> +void log_class_string::format(std::string &out, const void *arg) { + append_hex(out, static_cast(get_object(arg))); +} + +template <> +void log_class_string::format(std::string &out, + const void *arg) { + append_hex(out, get_object(arg)); +} + +template <> +void log_class_string::format(std::string &out, const void *arg) { + std::ostringstream buf(out, std::ios_base::ate); + buf << get_object(arg); +} + +template <> +void log_class_string::format(std::string &out, const void *arg) { + std::ostringstream buf(out, std::ios_base::ate); + buf << get_object(arg); +} + +template <> +void log_class_string::format(std::string &out, const void *arg) { + out += get_object(arg) ? "1" : "0"; +} + +void _orbis_log_print(LogLevel lvl, const char *msg, std::string_view names, + const log_type_info *sup, ...) { + + /*constinit thread_local*/ std::string text; + /*constinit thread_local*/ std::vector args; + + std::size_t args_count = 0; + for (auto v = sup; v && v->log_string; v++) + args_count++; + + text.reserve(50000); + args.resize(args_count); + + va_list c_args; + va_start(c_args, sup); + for (const void *&arg : args) + arg = va_arg(c_args, const void *); + va_end(c_args); + + text += msg; + text += "("; + for (std::size_t i = 0; i < args_count; i++) { + if (i) + text += ", "; + names.remove_prefix(names.find_first_not_of(" \t\n\r")); + std::string_view name = names.substr(0, names.find_first_of(",")); + names.remove_prefix(name.size() + 1); + text += name; + text += "="; + sup[i].log_string(text, args[i]); + } + text += ")"; + + std::fprintf(stderr, "%s\n", text.c_str()); +} +} // namespace orbis::logs diff --git a/orbis-kernel/src/utils/SharedMutex.cpp b/orbis-kernel/src/utils/SharedMutex.cpp new file mode 100644 index 000000000..d36627f3f --- /dev/null +++ b/orbis-kernel/src/utils/SharedMutex.cpp @@ -0,0 +1,151 @@ +#include "utils/SharedMutex.hpp" +#include +#include +#include +#include + +static void busy_wait(unsigned long long cycles = 3000) { + const auto stop = __builtin_ia32_rdtsc() + cycles; + do + _mm_pause(); + while (__builtin_ia32_rdtsc() < stop); +} + +namespace orbis::utils { +void shared_mutex::impl_lock_shared(unsigned val) { + if (val >= c_err) + std::abort(); // "shared_mutex underflow" + + // Try to steal the notification bit + unsigned _old = val; + if (val & c_sig && m_value.compare_exchange_strong(_old, val - c_sig + 1)) { + return; + } + + for (int i = 0; i < 10; i++) { + if (try_lock_shared()) { + return; + } + + unsigned old = m_value; + + if (old & c_sig && m_value.compare_exchange_strong(old, old - c_sig + 1)) { + return; + } + + busy_wait(); + } + + // Acquire writer lock and downgrade + const unsigned old = m_value.fetch_add(c_one); + + if (old == 0) { + lock_downgrade(); + return; + } + + if ((old % c_sig) + c_one >= c_sig) + std::abort; // "shared_mutex overflow" + impl_wait(); + lock_downgrade(); +} +void shared_mutex::impl_unlock_shared(unsigned old) { + if (old - 1 >= c_err) + std::abort(); // "shared_mutex underflow" + + // Check reader count, notify the writer if necessary + if ((old - 1) % c_one == 0) { + impl_signal(); + } +} +void shared_mutex::impl_wait() { + while (true) { + const auto [old, ok] = atomic_fetch_op(m_value, [](unsigned &value) { + if (value >= c_sig) { + value -= c_sig; + return true; + } + + return false; + }); + + if (ok) { + break; + } + + syscall(SYS_futex, &m_value, FUTEX_WAIT, old, 0, 0, 0); + } +} +void shared_mutex::impl_signal() { + m_value += c_sig; + syscall(SYS_futex, &m_value, FUTEX_WAKE, 1, 0, 0, 0); +} +void shared_mutex::impl_lock(unsigned val) { + if (val >= c_err) + std::abort(); // "shared_mutex underflow" + + // Try to steal the notification bit + unsigned _old = val; + if (val & c_sig && + m_value.compare_exchange_strong(_old, val - c_sig + c_one)) { + return; + } + + for (int i = 0; i < 10; i++) { + busy_wait(); + + unsigned old = m_value; + + if (!old && try_lock()) { + return; + } + + if (old & c_sig && + m_value.compare_exchange_strong(old, old - c_sig + c_one)) { + return; + } + } + + const unsigned old = m_value.fetch_add(c_one); + + if (old == 0) { + return; + } + + if ((old % c_sig) + c_one >= c_sig) + std::abort(); // "shared_mutex overflow" + impl_wait(); +} +void shared_mutex::impl_unlock(unsigned old) { + if (old - c_one >= c_err) + std::abort(); // "shared_mutex underflow" + + // 1) Notify the next writer if necessary + // 2) Notify all readers otherwise if necessary (currently indistinguishable + // from writers) + if (old - c_one) { + impl_signal(); + } +} +void shared_mutex::impl_lock_upgrade() { + for (int i = 0; i < 10; i++) { + busy_wait(); + + if (try_lock_upgrade()) { + return; + } + } + + // Convert to writer lock + const unsigned old = m_value.fetch_add(c_one - 1); + + if ((old % c_sig) + c_one - 1 >= c_sig) + std::abort(); // "shared_mutex overflow" + + if (old % c_one == 1) { + return; + } + + impl_wait(); +} +} // namespace orbis::utils diff --git a/readme.md b/readme.md index e3e4a702e..306677367 100644 --- a/readme.md +++ b/readme.md @@ -12,3 +12,8 @@ If you want to contribute as a developer, please contact us in the Discord. ## Building Under construction. + +## License + +RPCSX is licensed under GPLv2 license except directories containing their own LICENSE file, or files containing their own license. +Thus, orbis-kernel is licensed under the MIT license.