removed zombies, add missed include
Some checks are pending
Formatting check / formatting-check (push) Waiting to run
Build RPCSX / build-linux (push) Waiting to run
Build RPCSX / build-android (arm64-v8a, armv8-a) (push) Waiting to run
Build RPCSX / build-android (arm64-v8a, armv8.1-a) (push) Waiting to run
Build RPCSX / build-android (arm64-v8a, armv8.2-a) (push) Waiting to run
Build RPCSX / build-android (arm64-v8a, armv8.4-a) (push) Waiting to run
Build RPCSX / build-android (arm64-v8a, armv8.5-a) (push) Waiting to run
Build RPCSX / build-android (arm64-v8a, armv9-a) (push) Waiting to run
Build RPCSX / build-android (arm64-v8a, armv9.1-a) (push) Waiting to run
Build RPCSX / build-android (x86_64, x86-64) (push) Waiting to run

This commit is contained in:
DH 2025-10-05 16:48:13 +03:00
parent ac853e0817
commit bd215fab92
27 changed files with 58 additions and 1722 deletions

View file

@ -1,9 +1,9 @@
#pragma once
#include "orbis-config.hpp"
#include "rx/SharedMutex.hpp"
#include "rx/BitSet.hpp"
#include "rx/Rc.hpp"
#include "rx/SharedMutex.hpp"
#include <array>
#include <cstring>
#include <mutex>

View file

@ -68,7 +68,8 @@ T *knew(Args &&...args) {
utils::kalloc(sizeof(DynamicObject), alignof(DynamicObject)));
return std::construct_at(loc, std::forward<Args>(args)...);
} else {
static_assert(!std::is_polymorphic_v<T>, "Polymorphic type should be derived from rx::RcBase");
static_assert(!std::is_polymorphic_v<T>,
"Polymorphic type should be derived from rx::RcBase");
auto loc = static_cast<T *>(utils::kalloc(sizeof(T), alignof(T)));
return std::construct_at(loc, std::forward<Args>(args)...);

View file

@ -6,11 +6,11 @@
#include "ipmi.hpp"
#include "orbis/note.hpp"
#include "osem.hpp"
#include "rx/IdMap.hpp"
#include "rx/LinkedNode.hpp"
#include "rx/SharedCV.hpp"
#include "rx/SharedMutex.hpp"
#include "thread/types.hpp"
#include "rx/IdMap.hpp"
#include "rx/LinkedNode.hpp"
#include <cstdint>
#include <mutex>
@ -130,7 +130,8 @@ public:
return {};
}
std::pair<rx::Ref<IpmiServer>, ErrorCode> createIpmiServer(utils::kstring name) {
std::pair<rx::Ref<IpmiServer>, ErrorCode>
createIpmiServer(utils::kstring name) {
std::lock_guard lock(m_sem_mtx);
auto [it, inserted] = mIpmiServers.try_emplace(std::move(name), nullptr);
@ -214,8 +215,8 @@ public:
bool isDevKit = false;
rx::Ref<Budget> createProcessTypeBudget(Budget::ProcessType processType,
std::string_view name,
std::span<const BudgetInfo> items) {
std::string_view name,
std::span<const BudgetInfo> items) {
auto budget = orbis::knew<orbis::Budget>(name, processType, items);
processTypeBudgets[static_cast<int>(processType)] =
orbis::knew<orbis::Budget>(name, processType, items);

View file

@ -3,9 +3,9 @@
#include "KernelAllocator.hpp"
#include "error/ErrorCode.hpp"
#include "note.hpp"
#include "rx/Rc.hpp"
#include "rx/SharedMutex.hpp"
#include "stat.hpp"
#include "rx/Rc.hpp"
#include <cstdint>
namespace orbis {

View file

@ -3,9 +3,9 @@
#include "KernelAllocator.hpp"
#include "evf.hpp"
#include "orbis-config.hpp"
#include "rx/Rc.hpp"
#include "rx/SharedCV.hpp"
#include "rx/SharedMutex.hpp"
#include "rx/Rc.hpp"
#include <list>
#include <optional>

View file

@ -2,9 +2,9 @@
#include "KernelAllocator.hpp"
#include "file.hpp"
#include "rx/Rc.hpp"
#include "rx/SharedCV.hpp"
#include "rx/SharedMutex.hpp"
#include "rx/Rc.hpp"
#include <utility>
namespace orbis {

View file

@ -81,8 +81,7 @@ static orbis::FileOps pipe_ops = {
.write = pipe_write,
};
std::pair<rx::Ref<orbis::Pipe>, rx::Ref<orbis::Pipe>>
orbis::createPipe() {
std::pair<rx::Ref<orbis::Pipe>, rx::Ref<orbis::Pipe>> orbis::createPipe() {
auto a = knew<Pipe>();
auto b = knew<Pipe>();
a->event = knew<EventEmitter>();

View file

@ -1,260 +0,0 @@
#pragma once
#include "AppInfo.hpp"
#include "Budget.hpp"
#include "KernelAllocator.hpp"
#include "evf.hpp"
#include "ipmi.hpp"
#include "orbis/note.hpp"
#include "osem.hpp"
#include "thread/types.hpp"
#include "utils/IdMap.hpp"
#include "utils/LinkedNode.hpp"
#include "utils/SharedCV.hpp"
#include "utils/SharedMutex.hpp"
#include <cstdint>
#include <mutex>
#include <pthread.h>
#include <span>
#include <utility>
namespace orbis {
struct Process;
struct Thread;
struct UmtxKey {
// TODO: may contain a reference to a shared memory
std::uintptr_t addr;
orbis::pid_t pid;
auto operator<=>(const UmtxKey &) const = default;
};
struct UmtxCond {
Thread *thr;
rx::shared_cv cv;
UmtxCond(Thread *thr) : thr(thr) {}
};
struct UmtxChain {
rx::shared_mutex mtx;
using queue_type = utils::kmultimap<UmtxKey, UmtxCond>;
queue_type sleep_queue;
queue_type spare_queue;
std::pair<const UmtxKey, UmtxCond> *enqueue(UmtxKey &key, Thread *thr);
void erase(std::pair<const UmtxKey, UmtxCond> *obj);
queue_type::iterator erase(queue_type::iterator it);
uint notify_one(const UmtxKey &key);
uint notify_all(const UmtxKey &key);
uint notify_n(const UmtxKey &key, sint count);
};
enum class FwType : std::uint8_t {
Unknown,
Ps4,
Ps5,
};
struct RcAppInfo : rx::RcBase, AppInfoEx {
orbis::uint32_t appState = 0;
};
class alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__) KernelContext final {
public:
KernelContext();
~KernelContext();
Process *createProcess(pid_t pid);
void deleteProcess(Process *proc);
Process *findProcessById(pid_t pid) const;
Process *findProcessByHostId(std::uint64_t pid) const;
rx::LinkedNode<Process> *getProcessList() { return m_processes; }
long allocatePid() {
std::lock_guard lock(m_thread_id_mtx);
return m_thread_id_map.emplace(0).first;
}
long getTscFreq();
void *kalloc(std::size_t size,
std::size_t align = __STDCPP_DEFAULT_NEW_ALIGNMENT__);
void kfree(void *ptr, std::size_t size);
std::pair<EventFlag *, bool> createEventFlag(utils::kstring name,
std::int32_t flags,
std::uint64_t initPattern) {
std::lock_guard lock(m_evf_mtx);
auto [it, inserted] = m_event_flags.try_emplace(std::move(name), nullptr);
if (inserted) {
it->second = knew<EventFlag>(flags, initPattern);
std::strncpy(it->second->name, it->first.c_str(), 32);
}
return {it->second.get(), inserted};
}
rx::Ref<EventFlag> findEventFlag(std::string_view name) {
std::lock_guard lock(m_evf_mtx);
if (auto it = m_event_flags.find(name); it != m_event_flags.end()) {
return it->second;
}
return {};
}
std::pair<Semaphore *, bool> createSemaphore(utils::kstring name,
std::uint32_t attrs,
std::int32_t initCount,
std::int32_t maxCount) {
std::lock_guard lock(m_sem_mtx);
auto [it, inserted] = m_semaphores.try_emplace(std::move(name), nullptr);
if (inserted) {
it->second = knew<Semaphore>(attrs, initCount, maxCount);
}
return {it->second.get(), inserted};
}
rx::Ref<Semaphore> findSemaphore(std::string_view name) {
std::lock_guard lock(m_sem_mtx);
if (auto it = m_semaphores.find(name); it != m_semaphores.end()) {
return it->second;
}
return {};
}
std::pair<Ref<IpmiServer>, ErrorCode> createIpmiServer(utils::kstring name) {
std::lock_guard lock(m_sem_mtx);
auto [it, inserted] = mIpmiServers.try_emplace(std::move(name), nullptr);
if (!inserted) {
return {it->second, ErrorCode::EXIST};
}
it->second = knew<IpmiServer>(it->first);
if (it->second == nullptr) {
mIpmiServers.erase(it);
return {nullptr, ErrorCode::NOMEM};
}
return {it->second, {}};
}
rx::Ref<IpmiServer> findIpmiServer(std::string_view name) {
std::lock_guard lock(m_sem_mtx);
if (auto it = mIpmiServers.find(name); it != mIpmiServers.end()) {
return it->second;
}
return {};
}
std::tuple<utils::kmap<utils::kstring, char[128]> &,
std::unique_lock<rx::shared_mutex>>
getKernelEnv() {
std::unique_lock lock(m_kenv_mtx);
return {m_kenv, std::move(lock)};
}
void setKernelEnv(std::string_view key, std::string_view value) {
auto &kenvValue = m_kenv[utils::kstring(key)];
auto len = std::min(sizeof(kenvValue) - 1, value.size());
std::memcpy(kenvValue, value.data(), len);
kenvValue[len] = '0';
}
enum {
c_golden_ratio_prime = 2654404609u,
c_umtx_chains = 512,
c_umtx_shifts = 23,
};
// Use getUmtxChain0 or getUmtxChain1
std::tuple<UmtxChain &, UmtxKey, std::unique_lock<rx::shared_mutex>>
getUmtxChainIndexed(int i, Thread *t, uint32_t flags, void *ptr);
// Internal Umtx: Wait/Cv/Sem
auto getUmtxChain0(Thread *t, uint32_t flags, void *ptr) {
return getUmtxChainIndexed(0, t, flags, ptr);
}
// Internal Umtx: Mutex/Umtx/Rwlock
auto getUmtxChain1(Thread *t, uint32_t flags, void *ptr) {
return getUmtxChainIndexed(1, t, flags, ptr);
}
rx::Ref<EventEmitter> deviceEventEmitter;
rx::Ref<RcBase> shmDevice;
rx::Ref<RcBase> dmemDevice;
rx::Ref<RcBase> blockpoolDevice;
rx::Ref<RcBase> gpuDevice;
rx::Ref<RcBase> dceDevice;
rx::shared_mutex gpuDeviceMtx;
uint sdkVersion{};
uint fwSdkVersion{};
uint safeMode{};
utils::RcIdMap<RcBase, sint, 4097, 1> ipmiMap;
RcIdMap<RcAppInfo> appInfos;
RcIdMap<Budget, sint, 4097, 1> budgets;
rx::Ref<Budget> processTypeBudgets[4];
rx::shared_mutex regMgrMtx;
kmap<std::uint32_t, std::uint32_t> regMgrInt;
std::vector<std::tuple<std::uint8_t *, size_t>> dialogs{};
FwType fwType = FwType::Unknown;
bool isDevKit = false;
rx::Ref<Budget> createProcessTypeBudget(Budget::ProcessType processType,
std::string_view name,
std::span<const BudgetInfo> items) {
auto budget = orbis::knew<orbis::Budget>(name, processType, items);
processTypeBudgets[static_cast<int>(processType)] =
orbis::knew<orbis::Budget>(name, processType, items);
return budget;
}
rx::Ref<Budget> getProcessTypeBudget(Budget::ProcessType processType) {
return processTypeBudgets[static_cast<int>(processType)];
}
private:
rx::shared_mutex m_heap_mtx;
rx::shared_mutex m_heap_map_mtx;
void *m_heap_next = this + 1;
utils::kmultimap<std::size_t, void *> m_free_heap;
utils::kmultimap<std::size_t, void *> m_used_node;
UmtxChain m_umtx_chains[2][c_umtx_chains]{};
std::atomic<long> m_tsc_freq{0};
rx::shared_mutex m_thread_id_mtx;
OwningIdMap<char, long, 256, 0> m_thread_id_map;
mutable rx::shared_mutex m_proc_mtx;
utils::LinkedNode<Process> *m_processes = nullptr;
rx::shared_mutex m_evf_mtx;
utils::kmap<utils::kstring, rx::Ref<EventFlag>> m_event_flags;
rx::shared_mutex m_sem_mtx;
utils::kmap<utils::kstring, rx::Ref<Semaphore>> m_semaphores;
rx::shared_mutex mIpmiServerMtx;
utils::kmap<utils::kstring, rx::Ref<IpmiServer>> mIpmiServers;
rx::shared_mutex m_kenv_mtx;
utils::kmap<utils::kstring, char[128]> m_kenv; // max size: 127 + '\0'
};
extern KernelContext &g_context;
} // namespace orbis

File diff suppressed because it is too large Load diff

View file

@ -5,8 +5,8 @@
#include "Pipe.hpp"
#include "amdgpu/tiler_vulkan.hpp"
#include "orbis/KernelAllocator.hpp"
#include "rx/Rc.hpp"
#include "rx/MemoryTable.hpp"
#include "rx/Rc.hpp"
#include "rx/SharedMutex.hpp"
#include "shader/SemanticInfo.hpp"
#include "shader/SpvConverter.hpp"

View file

@ -705,7 +705,7 @@ IoDevice *createHostIoDevice(orbis::kstring hostPath,
}
rx::Ref<orbis::File> wrapSocket(int hostFd, orbis::kstring name, int dom,
int type, int prot) {
int type, int prot) {
auto s = orbis::knew<SocketFile>();
s->name = std::move(name);
s->dom = dom;
@ -716,9 +716,8 @@ rx::Ref<orbis::File> wrapSocket(int hostFd, orbis::kstring name, int dom,
return s;
}
orbis::ErrorCode createSocket(rx::Ref<orbis::File> *file,
orbis::kstring name, int dom, int type,
int prot) {
orbis::ErrorCode createSocket(rx::Ref<orbis::File> *file, orbis::kstring name,
int dom, int type, int prot) {
// ORBIS_LOG_ERROR(__FUNCTION__, name, dom, type, prot);
// *file = orbis::createPipe();
// return {};

View file

@ -75,9 +75,9 @@ orbis::ErrorCode convertErrno();
IoDevice *createHostIoDevice(orbis::kstring hostPath,
orbis::kstring virtualPath);
rx::Ref<orbis::File> wrapSocket(int hostFd, orbis::kstring name, int dom,
int type, int prot);
orbis::ErrorCode createSocket(rx::Ref<orbis::File> *file,
orbis::kstring name, int dom, int type, int prot);
int type, int prot);
orbis::ErrorCode createSocket(rx::Ref<orbis::File> *file, orbis::kstring name,
int dom, int type, int prot);
orbis::File *createHostFile(int hostFd, rx::Ref<IoDevice> device,
bool alignTruncate = false);
IoDevice *createFdWrapDevice(int fd);

View file

@ -778,9 +778,9 @@ static const orbis::FileOps fileOps = {
.ioctl = ajm_ioctl,
};
orbis::ErrorCode AjmDevice::open(rx::Ref<orbis::File> *file,
const char *path, std::uint32_t flags,
std::uint32_t mode, orbis::Thread *thread) {
orbis::ErrorCode AjmDevice::open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) {
auto newFile = orbis::knew<AjmFile>();
newFile->ops = &fileOps;
newFile->device = this;

View file

@ -192,9 +192,9 @@ static const orbis::FileOps fileOps = {
.write = aout_write,
};
orbis::ErrorCode AoutDevice::open(rx::Ref<orbis::File> *file,
const char *path, std::uint32_t flags,
std::uint32_t mode, orbis::Thread *thread) {
orbis::ErrorCode AoutDevice::open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) {
ORBIS_LOG_FATAL("aout device open", path, flags, mode);
auto newFile = orbis::knew<AoutFile>();
newFile->ops = &fileOps;

View file

@ -3,8 +3,8 @@
#include "io-device.hpp"
#include "orbis/error/ErrorCode.hpp"
#include "orbis/file.hpp"
#include "rx/Rc.hpp"
#include "rx/MemoryTable.hpp"
#include "rx/Rc.hpp"
#include "rx/SharedMutex.hpp"
#include <cstdint>

View file

@ -626,9 +626,9 @@ static void createGpu() {
}
}
orbis::ErrorCode DceDevice::open(rx::Ref<orbis::File> *file,
const char *path, std::uint32_t flags,
std::uint32_t mode, orbis::Thread *thread) {
orbis::ErrorCode DceDevice::open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) {
auto newFile = orbis::knew<DceFile>();
newFile->device = this;
newFile->ops = &ops;

View file

@ -385,9 +385,9 @@ orbis::ErrorCode DmemDevice::queryMaxFreeChunkSize(std::uint64_t *start,
return {};
}
orbis::ErrorCode DmemDevice::open(rx::Ref<orbis::File> *file,
const char *path, std::uint32_t flags,
std::uint32_t mode, orbis::Thread *thread) {
orbis::ErrorCode DmemDevice::open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) {
auto newFile = orbis::knew<DmemFile>();
newFile->device = this;
newFile->ops = &ops;

View file

@ -42,9 +42,9 @@ static const orbis::FileOps fileOps = {
.write = evlg_write,
};
orbis::ErrorCode EvlgDevice::open(rx::Ref<orbis::File> *file,
const char *path, std::uint32_t flags,
std::uint32_t mode, orbis::Thread *thread) {
orbis::ErrorCode EvlgDevice::open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) {
auto newFile = orbis::knew<EvlgFile>();
newFile->ops = &fileOps;
newFile->device = this;

View file

@ -155,9 +155,9 @@ static const orbis::FileOps ops = {
.ioctl = hid_ioctl,
};
orbis::ErrorCode HidDevice::open(rx::Ref<orbis::File> *file,
const char *path, std::uint32_t flags,
std::uint32_t mode, orbis::Thread *thread) {
orbis::ErrorCode HidDevice::open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) {
auto newFile = orbis::knew<HidFile>();
newFile->device = this;
newFile->ops = &ops;

View file

@ -52,9 +52,9 @@ void MBusDevice::emitEvent(const MBusEvent &event) {
eventEmitter->emit(orbis::kEvFiltRead);
}
orbis::ErrorCode MBusDevice::open(rx::Ref<orbis::File> *file,
const char *path, std::uint32_t flags,
std::uint32_t mode, orbis::Thread *thread) {
orbis::ErrorCode MBusDevice::open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) {
ORBIS_LOG_FATAL("mbus device open");
auto newFile = orbis::knew<MBusFile>();
newFile->ops = &fileOps;

View file

@ -22,9 +22,9 @@ static const orbis::FileOps ops = {
.write = null_write,
};
orbis::ErrorCode NullDevice::open(rx::Ref<orbis::File> *file,
const char *path, std::uint32_t flags,
std::uint32_t mode, orbis::Thread *thread) {
orbis::ErrorCode NullDevice::open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) {
auto newFile = orbis::knew<NullFile>();
newFile->device = this;
newFile->ops = &ops;

View file

@ -38,9 +38,9 @@ static const orbis::FileOps ops = {
.mmap = rng_mmap,
};
orbis::ErrorCode RngDevice::open(rx::Ref<orbis::File> *file,
const char *path, std::uint32_t flags,
std::uint32_t mode, orbis::Thread *thread) {
orbis::ErrorCode RngDevice::open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) {
auto newFile = orbis::knew<RngFile>();
newFile->device = this;
newFile->ops = &ops;

View file

@ -17,9 +17,9 @@ struct ShmDevice : IoDevice {
orbis::Thread *thread) override;
};
orbis::ErrorCode ShmDevice::open(rx::Ref<orbis::File> *file,
const char *path, std::uint32_t flags,
std::uint32_t mode, orbis::Thread *thread) {
orbis::ErrorCode ShmDevice::open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) {
ORBIS_LOG_WARNING("shm_open", path, flags, mode);
auto hostPath = rx::getShmGuestPath(path);
auto realFlags = O_RDWR; // TODO

View file

@ -25,9 +25,9 @@ static const orbis::FileOps ops = {
.read = zero_read,
};
orbis::ErrorCode ZeroDevice::open(rx::Ref<orbis::File> *file,
const char *path, std::uint32_t flags,
std::uint32_t mode, orbis::Thread *thread) {
orbis::ErrorCode ZeroDevice::open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) {
auto newFile = orbis::knew<ZeroFile>();
newFile->device = this;
newFile->ops = &ops;

View file

@ -14,8 +14,8 @@
#include "orbis/uio.hpp"
#include "orbis/umtx.hpp"
#include "orbis/utils/Logs.hpp"
#include "rx/Rc.hpp"
#include "orbis/vm.hpp"
#include "rx/Rc.hpp"
#include "rx/watchdog.hpp"
#include "thread.hpp"
#include "vfs.hpp"

View file

@ -159,8 +159,7 @@ orbis::SysResult vfs::mount(const std::filesystem::path &guestPath,
}
orbis::SysResult vfs::open(std::string_view path, int flags, int mode,
rx::Ref<orbis::File> *file,
orbis::Thread *thread) {
rx::Ref<orbis::File> *file, orbis::Thread *thread) {
auto [device, devPath] = get(path);
if (device == nullptr) {
return orbis::ErrorCode::NOENT;

View file

@ -3,6 +3,8 @@ using namespace rx;
#ifdef __linux__
#include <linux/futex.h>
#include <sys/syscall.h>
#include <unistd.h>
std::errc shared_atomic32::wait_impl(std::uint32_t oldValue,
std::chrono::microseconds usec_timeout) {