Compare commits

...

8 commits

Author SHA1 Message Date
DH e27926d629 ajm: rewrite using new ioctl handling api
Some checks failed
Formatting check / formatting-check (push) Has been cancelled
Build RPCSX / build-linux (push) Has been cancelled
Build RPCSX / build-android (arm64-v8a, armv8-a) (push) Has been cancelled
Build RPCSX / build-android (arm64-v8a, armv8.1-a) (push) Has been cancelled
Build RPCSX / build-android (arm64-v8a, armv8.2-a) (push) Has been cancelled
Build RPCSX / build-android (arm64-v8a, armv8.4-a) (push) Has been cancelled
Build RPCSX / build-android (arm64-v8a, armv8.5-a) (push) Has been cancelled
Build RPCSX / build-android (arm64-v8a, armv9-a) (push) Has been cancelled
Build RPCSX / build-android (arm64-v8a, armv9.1-a) (push) Has been cancelled
Build RPCSX / build-android (x86_64, x86-64) (push) Has been cancelled
2025-10-11 20:22:03 +03:00
DH 8cfb4e8d16 orbis: add type-safe IoDeviceWithIoctl 2025-10-11 20:21:27 +03:00
DH 014012c219 orbis: remove process list from context & initial serialization support
modernize kenv
add LockableKernelObject utility
2025-10-11 18:06:29 +03:00
DH f71e3410c1 rx/serializer: fix array handling with gcc 2025-10-11 18:01:41 +03:00
kalaposfos13 ecfb47ecaf
Update hidapi to fix deprecation error and update gitignore (#110)
* Update .gitignore to ignore logs

* Update hidapi
2025-10-11 17:44:44 +03:00
DH 5f109c0e34 fix includes 2025-10-11 16:00:40 +03:00
DH aee92cce57 kernel: avoid global storage usage for process/thread local variables
enables multiple guest processes emulation in single host process
2025-10-11 15:22:34 +03:00
DH 05dee2c8e3 Move IoDevice to orbis 2025-10-11 14:49:51 +03:00
95 changed files with 1786 additions and 1382 deletions

3
.gitignore vendored
View file

@ -61,3 +61,6 @@ build*/
.cache/
rpcs3/git-version.h
.rx.version
log-*.txt
tty.txt

@ -1 +1 @@
Subproject commit 6bfdcf7368169efe1b745cd4468d45cda05ef8de
Subproject commit f42423643ec9011c98cccc0bb790722bbbd3f30b

View file

@ -2,7 +2,9 @@
#include "rx/Rc.hpp"
#include "rx/Serializer.hpp"
#include "rx/SharedMutex.hpp"
#include "rx/TypeId.hpp"
#include <cstddef>
#include <memory>
#include <mutex>
@ -43,6 +45,28 @@ struct KernelObject : KernelObjectBase, StateT {
}
};
template <rx::Serializable StateT>
struct LockableKernelObject : KernelObjectBase, StateT {
mutable rx::shared_mutex mtx;
template <typename... Args>
LockableKernelObject(Args &&...args)
: KernelObjectBase(rx::TypeId::get<StateT>()),
StateT(std::forward<Args>(args)...) {}
virtual void serialize(rx::Serializer &s) const {
std::lock_guard lock(*this);
s.serialize(static_cast<const StateT &>(*this));
}
virtual void deserialize(rx::Deserializer &s) {
s.deserialize(static_cast<StateT &>(*this));
}
void lock() const { mtx.lock(); }
void unlock() const { mtx.unlock(); }
};
namespace detail {
struct StaticObjectCtl {
std::size_t offset = -1ull;
@ -75,8 +99,6 @@ struct ProcessScope;
struct ThreadScope;
} // namespace detail
template <typename NamespaceT, typename ScopeT> std::byte *getScopeStorage();
template <typename NamespaceT, typename ScopeT>
struct StaticKernelObjectStorage {
template <typename T> static std::uint32_t Allocate() {
@ -91,41 +113,30 @@ struct StaticKernelObjectStorage {
instance.m_size = offset + sizeof(T);
instance.m_alignment =
std::max<std::size_t>(alignof(T), instance.m_alignment);
// std::printf(
// "%s::Allocate(%s, %zu, %zu) -> %zu\n",
// rx::TypeId::get<StaticKernelObjectStorage<NamespaceT,
// ScopeT>>().getName().data(), rx::TypeId::get<T>().getName().data(),
// sizeof(T), alignof(T), offset);
return offset;
}
static std::size_t GetSize() { return GetInstance().m_size; }
static std::size_t GetAlignment() { return GetInstance().m_alignment; }
static std::byte *getScopeStorage() {
return kernel::getScopeStorage<NamespaceT, ScopeT>();
}
static void ConstructAll() {
static void ConstructAll(std::byte *storage) {
auto &instance = GetInstance();
auto storage = getScopeStorage();
for (auto objectCtl : instance.m_registry) {
objectCtl.construct(storage + objectCtl.offset);
}
}
static void DestructAll() {
static void DestructAll(std::byte *storage) {
auto &instance = GetInstance();
auto storage = getScopeStorage();
for (auto objectCtl : instance.m_registry) {
objectCtl.destruct(storage + objectCtl.offset);
}
}
static void SerializeAll(rx::Serializer &s) {
static void SerializeAll(std::byte *storage, rx::Serializer &s) {
auto &instance = GetInstance();
auto storage = getScopeStorage();
s.serialize(instance.m_size);
s.serialize(instance.m_registry.size());
@ -135,9 +146,8 @@ struct StaticKernelObjectStorage {
}
}
static void DeserializeAll(rx::Deserializer &s) {
static void DeserializeAll(std::byte *storage, rx::Deserializer &s) {
auto &instance = GetInstance();
auto storage = getScopeStorage();
auto size = s.deserialize<std::size_t>();
auto registrySize = s.deserialize<std::size_t>();
@ -163,18 +173,11 @@ private:
std::size_t m_alignment = 1;
};
template <typename NamespaceT, typename ScopeT, rx::Serializable T>
class StaticObjectRef {
std::uint32_t mOffset;
template <typename Namespace, typename Scope, rx::Serializable T>
struct StaticObjectRef {
std::uint32_t offset;
public:
explicit StaticObjectRef(std::uint32_t offset) : mOffset(offset) {}
T *get() {
return reinterpret_cast<T *>(getScopeStorage<NamespaceT, ScopeT>() +
mOffset);
}
T *operator->() { return get(); }
T *get(std::byte *storage) { return reinterpret_cast<T *>(storage + offset); }
};
} // namespace kernel

View file

@ -6,6 +6,7 @@ add_library(obj.orbis-kernel OBJECT
src/sysvec.cpp
src/event.cpp
src/evf.cpp
src/IoDevice.cpp
src/ipmi.cpp
src/KernelAllocator.cpp
src/KernelContext.cpp
@ -65,6 +66,9 @@ add_library(obj.orbis-kernel OBJECT
src/sys/sys_vm_mmap.cpp
src/sys/sys_vm_unix.cpp
src/thread/Process.cpp
src/thread/Thread.cpp
src/utils/Logs.cpp
)

View file

@ -0,0 +1,185 @@
#pragma once
#include "error/ErrorCode.hpp"
#include "orbis-config.hpp"
#include "rx/Rc.hpp"
#include <bit>
#include <type_traits>
namespace orbis {
enum OpenFlags {
kOpenFlagReadOnly = 0x0,
kOpenFlagWriteOnly = 0x1,
kOpenFlagReadWrite = 0x2,
kOpenFlagNonBlock = 0x4,
kOpenFlagAppend = 0x8,
kOpenFlagShLock = 0x10,
kOpenFlagExLock = 0x20,
kOpenFlagAsync = 0x40,
kOpenFlagFsync = 0x80,
kOpenFlagCreat = 0x200,
kOpenFlagTrunc = 0x400,
kOpenFlagExcl = 0x800,
kOpenFlagDSync = 0x1000,
kOpenFlagDirect = 0x10000,
kOpenFlagDirectory = 0x20000,
};
struct File;
struct Thread;
struct IoDevice : rx::RcBase {
virtual ErrorCode open(rx::Ref<File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
Thread *thread) = 0;
virtual ErrorCode unlink(const char *path, bool recursive, Thread *thread) {
return ErrorCode::NOTSUP;
}
virtual ErrorCode createSymlink(const char *target, const char *linkPath,
Thread *thread) {
return ErrorCode::NOTSUP;
}
virtual ErrorCode mkdir(const char *path, int mode, Thread *thread) {
return ErrorCode::NOTSUP;
}
virtual ErrorCode rmdir(const char *path, Thread *thread) {
return ErrorCode::NOTSUP;
}
virtual ErrorCode rename(const char *from, const char *to, Thread *thread) {
return ErrorCode::NOTSUP;
}
virtual ErrorCode ioctl(std::uint64_t request, orbis::ptr<void> argp,
Thread *thread);
};
namespace ioctl {
inline constexpr std::uint32_t VoidBit = 0x20000000;
inline constexpr std::uint32_t OutBit = 0x40000000;
inline constexpr std::uint32_t InBit = 0x80000000;
inline constexpr std::uint32_t DirMask = VoidBit | InBit | OutBit;
constexpr bool isVoid(std::uint32_t cmd) { return (cmd & DirMask) == VoidBit; }
constexpr bool isIn(std::uint32_t cmd) { return (cmd & DirMask) == InBit; }
constexpr bool isOut(std::uint32_t cmd) { return (cmd & DirMask) == OutBit; }
constexpr bool isInOut(std::uint32_t cmd) {
return (cmd & DirMask) == (OutBit | InBit);
}
constexpr std::uint32_t paramSize(std::uint32_t cmd) {
return (cmd >> 16) & ((1 << 13) - 1);
}
constexpr std::uint32_t group(std::uint32_t cmd) { return (cmd >> 8) & 0xff; }
constexpr std::uint32_t id(std::uint32_t cmd) { return cmd & 0xff; }
} // namespace ioctl
struct IoctlHandlerEntry;
using IoctlHandler = ErrorCode (*)(Thread *thread, orbis::ptr<void> arg,
IoDevice *device, void (*impl)());
struct IoctlHandlerEntry {
IoctlHandler handler;
void (*impl)();
std::uint32_t cmd;
};
template <int Group> struct IoDeviceWithIoctl : IoDevice {
IoctlHandlerEntry ioctlTable[256]{};
template <std::uint32_t Cmd, typename InstanceT, typename T>
requires requires {
requires std::is_base_of_v<IoDeviceWithIoctl, InstanceT>;
requires ioctl::paramSize(Cmd) == sizeof(T);
requires ioctl::group(Cmd) == Group;
requires std::is_const_v<T> || ioctl::isInOut(Cmd);
requires !std::is_const_v<T> || ioctl::isIn(Cmd);
}
void addIoctl(ErrorCode (*handler)(Thread *thread, InstanceT *device,
T &arg)) {
constexpr auto id = ioctl::id(Cmd);
assert(ioctlTable[id].handler == unhandledIoctl);
IoctlHandlerEntry &entry = ioctlTable[id];
entry.handler = [](Thread *thread, orbis::ptr<void> arg, IoDevice *device,
void (*opaqueImpl)()) -> ErrorCode {
auto impl = std::bit_cast<decltype(handler)>(opaqueImpl);
std::remove_cvref_t<T> _arg;
ORBIS_RET_ON_ERROR(orbis::uread(_arg, orbis::ptr<T>(arg)));
ORBIS_RET_ON_ERROR(impl(thread, static_cast<InstanceT *>(device), _arg));
if constexpr (ioctl::isInOut(Cmd)) {
return orbis::uwrite(orbis::ptr<T>(arg), _arg);
} else {
return {};
}
};
entry.impl = std::bit_cast<void (*)()>(handler);
entry.cmd = Cmd;
}
template <std::uint32_t Cmd, typename InstanceT>
requires requires {
requires std::is_base_of_v<IoDeviceWithIoctl, InstanceT>;
requires ioctl::group(Cmd) == Group;
requires ioctl::isVoid(Cmd);
}
void addIoctl(ErrorCode (*handler)(Thread *thread, InstanceT *device)) {
constexpr auto id = ioctl::id(Cmd);
assert(ioctlTable[id].handler == unhandledIoctl);
IoctlHandlerEntry &entry = ioctlTable[id];
entry.handler = [](Thread *thread, orbis::ptr<void>, IoDevice *device,
void (*opaqueImpl)()) -> ErrorCode {
auto impl = std::bit_cast<decltype(handler)>(opaqueImpl);
return impl(thread, static_cast<InstanceT *>(device));
};
entry.impl = std::bit_cast<void (*)()>(handler);
entry.cmd = Cmd;
}
template <std::uint32_t Cmd, typename InstanceT, typename T>
requires requires {
requires std::is_base_of_v<IoDeviceWithIoctl, InstanceT>;
requires ioctl::paramSize(Cmd) == sizeof(T);
requires ioctl::group(Cmd) == Group;
requires ioctl::isOut(Cmd);
}
void addIoctl(std::pair<ErrorCode, T> (*handler)(Thread *thread,
InstanceT *device)) {
constexpr auto id = ioctl::id(Cmd);
assert(ioctlTable[id].handler == unhandledIoctl);
IoctlHandlerEntry &entry = ioctlTable[id];
entry.handler = [](Thread *thread, orbis::ptr<void> arg, IoDevice *device,
void (*opaqueImpl)()) -> ErrorCode {
auto impl = std::bit_cast<decltype(handler)>(opaqueImpl);
auto [errc, value] = impl(thread, static_cast<InstanceT *>(device));
ORBIS_RET_ON_ERROR(errc);
return orbis::uwrite(orbis::ptr<T>(arg), value);
};
entry.impl = std::bit_cast<void (*)()>(handler);
entry.cmd = Cmd;
}
ErrorCode ioctl(std::uint64_t request, orbis::ptr<void> argp,
Thread *thread) override {
auto id = request & 0xff;
if (ioctlTable[id].handler == nullptr || ioctlTable[id].cmd != request) {
return IoDevice::ioctl(request, argp, thread);
}
return ioctlTable[id].handler(thread, argp, this, ioctlTable[id].impl);
}
};
} // namespace orbis

View file

@ -1,15 +1,14 @@
#pragma once
#include "AppInfo.hpp"
#include "Budget.hpp"
#include "IoDevice.hpp"
#include "KernelObject.hpp"
#include "evf.hpp"
#include "ipmi.hpp"
#include "orbis/note.hpp"
#include "osem.hpp"
#include "rx/IdMap.hpp"
#include "rx/LinkedNode.hpp"
#include "rx/SharedMutex.hpp"
#include "thread/types.hpp"
#include <cstdint>
#include <mutex>
@ -31,23 +30,11 @@ struct RcAppInfo : rx::RcBase, AppInfoEx {
orbis::uint32_t appState = 0;
};
class alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__) KernelContext final {
class 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();
std::pair<EventFlag *, bool> createEventFlag(kstring name, std::int32_t flags,
@ -122,25 +109,23 @@ public:
return {};
}
std::tuple<kmap<kstring, char[128]> &, std::unique_lock<rx::shared_mutex>>
std::tuple<kmap<kstring, rx::StaticString<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[kstring(key)];
auto len = std::min(sizeof(kenvValue) - 1, value.size());
std::memcpy(kenvValue, value.data(), len);
kenvValue[len] = '0';
std::unique_lock lock(m_kenv_mtx);
m_kenv[kstring(key)] = value;
}
rx::Ref<EventEmitter> deviceEventEmitter;
rx::Ref<rx::RcBase> shmDevice;
rx::Ref<rx::RcBase> dmemDevice;
rx::Ref<rx::RcBase> blockpoolDevice;
rx::Ref<IoDevice> shmDevice;
rx::Ref<IoDevice> dmemDevice;
rx::Ref<IoDevice> blockpoolDevice;
rx::Ref<rx::RcBase> gpuDevice;
rx::Ref<rx::RcBase> dceDevice;
rx::Ref<IoDevice> dceDevice;
rx::shared_mutex gpuDeviceMtx;
uint sdkVersion{};
uint fwSdkVersion{};
@ -176,11 +161,6 @@ public:
private:
std::atomic<long> m_tsc_freq{0};
rx::shared_mutex m_thread_id_mtx;
rx::OwningIdMap<char, long, 256, 0> m_thread_id_map;
mutable rx::shared_mutex m_proc_mtx;
rx::LinkedNode<Process> *m_processes = nullptr;
rx::shared_mutex m_evf_mtx;
kmap<kstring, rx::Ref<EventFlag>> m_event_flags;
@ -191,7 +171,7 @@ private:
kmap<kstring, rx::Ref<IpmiServer>> mIpmiServers;
rx::shared_mutex m_kenv_mtx;
kmap<kstring, char[128]> m_kenv; // max size: 127 + '\0'
kmap<kstring, rx::StaticString<128>> m_kenv; // max size: 127 + '\0'
};
extern GlobalObjectRef<KernelContext> g_context;

View file

@ -1,23 +1,22 @@
#pragma once
#include "rx/Serializer.hpp"
#include <cstddef>
#include <kernel/KernelObject.hpp>
namespace orbis {
struct OrbisNamespace;
template <rx::Serializable StateT>
using GlobalObjectRef =
kernel::StaticObjectRef<OrbisNamespace, kernel::detail::GlobalScope,
StateT>;
extern std::byte *g_globalStorage;
template <rx::Serializable StateT>
using ProcessLocalObjectRef =
kernel::StaticObjectRef<OrbisNamespace, kernel::detail::ProcessScope,
StateT>;
template <rx::Serializable T> class GlobalObjectRef {
std::uint32_t mOffset;
template <rx::Serializable StateT>
using ThreadLocalObjectRef =
kernel::StaticObjectRef<OrbisNamespace, kernel::detail::ThreadScope,
StateT>;
public:
explicit GlobalObjectRef(std::uint32_t offset) : mOffset(offset) {}
T *get() { return reinterpret_cast<T *>(g_globalStorage + mOffset); }
T *operator->() { return get(); }
T &operator*() { return *get(); }
};
template <rx::Serializable StateT>
GlobalObjectRef<StateT> createGlobalObject() {
@ -33,8 +32,7 @@ createProcessLocalObject() {
auto layoutOffset = kernel::StaticKernelObjectStorage<
OrbisNamespace,
kernel::detail::ProcessScope>::template Allocate<StateT>();
return kernel::StaticObjectRef<OrbisNamespace, kernel::detail::ProcessScope,
StateT>(layoutOffset);
return {layoutOffset};
}
template <rx::Serializable StateT>
@ -42,67 +40,30 @@ kernel::StaticObjectRef<OrbisNamespace, kernel::detail::ThreadScope, StateT>
createThreadLocalObject() {
auto layoutOffset = kernel::StaticKernelObjectStorage<
OrbisNamespace, kernel::detail::ThreadScope>::template Allocate<StateT>();
return kernel::StaticObjectRef<OrbisNamespace, kernel::detail::ThreadScope,
StateT>(layoutOffset);
return {layoutOffset};
}
inline void constructAllGlobals() {
kernel::StaticKernelObjectStorage<
OrbisNamespace, kernel::detail::GlobalScope>::ConstructAll();
}
inline void constructAllProcessLocals() {
kernel::StaticKernelObjectStorage<
OrbisNamespace, kernel::detail::ProcessScope>::ConstructAll();
}
inline void constructAllThreadLocals() {
kernel::StaticKernelObjectStorage<
OrbisNamespace, kernel::detail::ThreadScope>::ConstructAll();
OrbisNamespace,
kernel::detail::GlobalScope>::ConstructAll(g_globalStorage);
}
inline void destructAllGlobals() {
kernel::StaticKernelObjectStorage<OrbisNamespace,
kernel::detail::GlobalScope>::DestructAll();
}
inline void destructAllProcessLocals() {
kernel::StaticKernelObjectStorage<
OrbisNamespace, kernel::detail::ProcessScope>::DestructAll();
}
inline void destructAllThreadLocals() {
kernel::StaticKernelObjectStorage<OrbisNamespace,
kernel::detail::ThreadScope>::DestructAll();
OrbisNamespace,
kernel::detail::GlobalScope>::DestructAll(g_globalStorage);
}
inline void serializeAllGlobals(rx::Serializer &s) {
kernel::StaticKernelObjectStorage<
OrbisNamespace, kernel::detail::GlobalScope>::SerializeAll(s);
}
inline void serializeAllProcessLocals(rx::Serializer &s) {
kernel::StaticKernelObjectStorage<
OrbisNamespace, kernel::detail::ProcessScope>::SerializeAll(s);
}
inline void serializeAllThreadLocals(rx::Serializer &s) {
kernel::StaticKernelObjectStorage<
OrbisNamespace, kernel::detail::ThreadScope>::SerializeAll(s);
OrbisNamespace,
kernel::detail::GlobalScope>::SerializeAll(g_globalStorage, s);
}
inline void deserializeAllGlobals(rx::Deserializer &s) {
kernel::StaticKernelObjectStorage<
OrbisNamespace, kernel::detail::GlobalScope>::DeserializeAll(s);
}
inline void deserializeAllProcessLocals(rx::Deserializer &s) {
kernel::StaticKernelObjectStorage<
OrbisNamespace, kernel::detail::ProcessScope>::DeserializeAll(s);
}
inline void deserializeAllThreadLocals(rx::Deserializer &s) {
kernel::StaticKernelObjectStorage<
OrbisNamespace, kernel::detail::ThreadScope>::DeserializeAll(s);
OrbisNamespace,
kernel::detail::GlobalScope>::DeserializeAll(g_globalStorage, s);
}
} // namespace orbis

View file

@ -5,6 +5,7 @@
#include "note.hpp"
#include "rx/Rc.hpp"
#include "rx/SharedMutex.hpp"
#include "IoDevice.hpp"
#include "stat.hpp"
#include <cstdint>
@ -77,7 +78,7 @@ struct File : rx::RcBase {
rx::shared_mutex mtx;
rx::Ref<EventEmitter> event;
const FileOps *ops = nullptr;
rx::Ref<RcBase> device;
rx::Ref<IoDevice> device;
std::uint64_t nextOff = 0;
int flags = 0;
int mode = 0;

View file

@ -1,6 +1,8 @@
#pragma once
#include "orbis-config.hpp"
#include "../KernelAllocator.hpp"
#include "../KernelObject.hpp"
#include "../event.hpp"
#include "../evf.hpp"
#include "../ipmi.hpp"
@ -15,6 +17,7 @@
#include "orbis/file.hpp"
#include "orbis/module/Module.hpp"
#include "rx/IdMap.hpp"
#include "rx/Serializer.hpp"
#include "rx/SharedMutex.hpp"
#include <optional>
@ -52,7 +55,15 @@ enum class ProcessType : std::uint8_t {
};
struct Process final {
using Storage =
kernel::StaticKernelObjectStorage<OrbisNamespace,
kernel::detail::ProcessScope>;
~Process();
KernelContext *context = nullptr;
std::byte *storage = nullptr;
pid_t pid = -1;
int gfxRing = 0;
std::uint64_t hostPid = -1;
@ -88,7 +99,7 @@ struct Process final {
rx::RcIdMap<EventFlag, sint, 4097, 1> evfMap;
rx::RcIdMap<Semaphore, sint, 4097, 1> semMap;
rx::RcIdMap<Module, ModuleHandle> modulesMap;
rx::OwningIdMap<Thread, lwpid_t> threadsMap;
rx::RcIdMap<Thread, lwpid_t> threadsMap;
rx::RcIdMap<orbis::File, sint> fileDescriptors;
// Named objects for debugging
@ -101,5 +112,25 @@ struct Process final {
// Named memory ranges for debugging
rx::shared_mutex namedMemMutex;
kmap<NamedMemoryRange, kstring> namedMem;
// FIXME: implement process destruction
void incRef() {}
void decRef() {}
void serialize(rx::Serializer &) const;
void deserialize(rx::Deserializer &);
template <rx::Serializable T>
T *get(
kernel::StaticObjectRef<OrbisNamespace, kernel::detail::ProcessScope, T>
ref) {
return ref.get(storage);
}
};
pid_t allocatePid();
Process *createProcess(Process *parentProcess = nullptr, pid_t pid = -1);
void deleteProcess(Process *proc);
Process *findProcessById(pid_t pid);
Process *findProcessByHostId(std::uint64_t pid);
} // namespace orbis

View file

@ -3,9 +3,12 @@
#include "ThreadState.hpp"
#include "cpuset.hpp"
#include "orbis-config.hpp"
#include "rx/Serializer.hpp"
#include "rx/StaticString.hpp"
#include "types.hpp"
#include "../KernelAllocator.hpp"
#include "../KernelObject.hpp"
#include "../ucontext.hpp"
#include "rx/SharedAtomic.hpp"
#include "rx/SharedCV.hpp"
@ -16,9 +19,16 @@ namespace orbis {
struct Process;
static constexpr std::uint32_t kThreadSuspendFlag = 1 << 31;
struct Thread {
struct Thread final {
using Storage =
kernel::StaticKernelObjectStorage<OrbisNamespace,
kernel::detail::ThreadScope>;
~Thread();
rx::shared_mutex mtx;
Process *tproc = nullptr;
std::byte *storage = nullptr;
uint64_t retval[2]{};
void *context{};
kvector<void *> altStack;
@ -26,7 +36,7 @@ struct Thread {
ptr<void> stackEnd;
uint64_t fsBase{};
uint64_t gsBase{};
char name[32]{};
rx::StaticString<32> name;
cpuset affinity{~0u};
SigSet sigMask = {0x7fff'ffff, ~0u, ~0u, ~0u};
@ -75,11 +85,19 @@ struct Thread {
void notifyUnblockedSignal(int signo);
void setSigMask(SigSet newSigMask);
template <rx::Serializable T>
T *get(kernel::StaticObjectRef<OrbisNamespace, kernel::detail::ThreadScope, T>
ref) {
return ref.get(storage);
}
// FIXME: implement thread destruction
void incRef() {}
void decRef() {}
};
Thread *createThread(Process *process, std::string_view name);
extern thread_local Thread *g_currentThread;
struct scoped_unblock {

View file

@ -0,0 +1,75 @@
#include "IoDevice.hpp"
#include "thread/Thread.hpp"
#include "utils/Logs.hpp"
static std::string iocGroupToString(unsigned iocGroup) {
if (iocGroup >= 128) {
const char *sceGroups[] = {
"DEV",
"DMEM",
"GC",
"DCE",
"UVD",
"VCE",
"DBGGC",
"TWSI",
"MDBG",
"DEVENV",
"AJM",
"TRACE",
"IBS",
"MBUS",
"HDMI",
"CAMERA",
"FAN",
"THERMAL",
"PFS",
"ICC_CONFIG",
"IPC",
"IOSCHED",
"ICC_INDICATOR",
"EXFATFS",
"ICC_NVS",
"DVE",
"ICC_POWER",
"AV_CONTROL",
"ICC_SC_CONFIGURATION",
"ICC_DEVICE_POWER",
"SSHOT",
"DCE_SCANIN",
"FSCTRL",
"HMD",
"SHM",
"PHYSHM",
"HMDDFU",
"BLUETOOTH_HID",
"SBI",
"S3DA",
"SPM",
"BLOCKPOOL",
"SDK_EVENTLOG",
};
if (iocGroup - 127 >= std::size(sceGroups)) {
return "'?'";
}
return sceGroups[iocGroup - 127];
}
if (isprint(iocGroup)) {
return "'" + std::string(1, (char)iocGroup) + "'";
}
return "'?'";
}
orbis::ErrorCode orbis::IoDevice::ioctl(std::uint64_t request,
orbis::ptr<void> argp, Thread *thread) {
auto group = iocGroupToString(ioctl::group(request));
auto paramSize = ioctl::paramSize(request);
ORBIS_LOG_ERROR("unhandled ioctl", request, group, paramSize, argp,
thread->tid);
thread->where();
return ErrorCode::NOTSUP;
}

View file

@ -39,7 +39,8 @@ struct KernelMemoryResource {
};
static KernelMemoryResource *sMemoryResource;
static std::byte *sGlobalStorage;
std::byte *g_globalStorage;
using GlobalStorage =
kernel::StaticKernelObjectStorage<OrbisNamespace,
kernel::detail::GlobalScope>;
@ -69,15 +70,15 @@ void initializeAllocator() {
rx::print(stderr, "global: size {}, alignment {}\n", GlobalStorage::GetSize(),
GlobalStorage::GetAlignment());
// allocate whole global storage
sGlobalStorage = (std::byte *)sMemoryResource->kalloc(
g_globalStorage = (std::byte *)sMemoryResource->kalloc(
GlobalStorage::GetSize(), GlobalStorage::GetAlignment());
}
void deinitializeAllocator() {
sMemoryResource->kfree(sGlobalStorage, GlobalStorage::GetSize());
sMemoryResource->kfree(g_globalStorage, GlobalStorage::GetSize());
delete sMemoryResource;
sMemoryResource = nullptr;
sGlobalStorage = nullptr;
g_globalStorage = nullptr;
}
void *KernelMemoryResource::kalloc(std::size_t size, std::size_t align) {
@ -213,9 +214,3 @@ void *kalloc(std::size_t size, std::size_t align) {
return sMemoryResource->kalloc(size, align);
}
} // namespace orbis
template <>
std::byte *
kernel::getScopeStorage<orbis::OrbisNamespace, kernel::detail::GlobalScope>() {
return orbis::sGlobalStorage;
}

View file

@ -24,71 +24,6 @@ KernelContext::KernelContext() {
}
KernelContext::~KernelContext() {}
Process *KernelContext::createProcess(pid_t pid) {
auto newProcess = knew<rx::LinkedNode<Process>>();
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;
}
return &newProcess->object;
}
void KernelContext::deleteProcess(Process *proc) {
auto procNode = reinterpret_cast<rx::LinkedNode<Process> *>(proc);
{
std::lock_guard lock(m_proc_mtx);
auto next = procNode->erase();
if (procNode == m_processes) {
m_processes = next;
}
}
kdelete(procNode);
}
Process *KernelContext::findProcessById(pid_t pid) const {
for (std::size_t i = 0; i < 20; ++i) {
{
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;
}
}
}
std::this_thread::sleep_for(std::chrono::microseconds(50));
}
return nullptr;
}
Process *KernelContext::findProcessByHostId(std::uint64_t pid) const {
for (std::size_t i = 0; i < 20; ++i) {
{
std::lock_guard lock(m_proc_mtx);
for (auto proc = m_processes; proc != nullptr; proc = proc->next) {
if (proc->object.hostPid == pid) {
return &proc->object;
}
}
}
std::this_thread::sleep_for(std::chrono::microseconds(50));
}
return nullptr;
}
long KernelContext::getTscFreq() {
auto cal_tsc = []() -> long {
const long timer_freq = 1'000'000'000;

View file

@ -12,8 +12,8 @@ static orbis::ErrorCode pipe_read(orbis::File *file, orbis::Uio *uio,
while (true) {
if (pipe->data.empty()) {
// pipe->cv.wait(file->mtx);
// ORBIS_LOG_ERROR(__FUNCTION__, "wakeup", thread->name, thread->tid,
// file); continue;
// ORBIS_LOG_ERROR(__FUNCTION__, "wakeup", thread->name.c_str(),
// thread->tid, file); continue;
return orbis::ErrorCode::WOULDBLOCK;
}
@ -32,8 +32,8 @@ static orbis::ErrorCode pipe_read(orbis::File *file, orbis::Uio *uio,
uio->offset += size;
std::memcpy(vec.base, pipe->data.data(), size);
ORBIS_LOG_ERROR(__FUNCTION__, thread->name, thread->tid, file, size,
pipe->data.size(), uio->offset, file->nextOff);
ORBIS_LOG_ERROR(__FUNCTION__, thread->name.c_str(), thread->tid, file,
size, pipe->data.size(), uio->offset, file->nextOff);
if (pipe->data.size() == size) {
pipe->data.clear();
@ -55,7 +55,7 @@ static orbis::ErrorCode pipe_read(orbis::File *file, orbis::Uio *uio,
static orbis::ErrorCode pipe_write(orbis::File *file, orbis::Uio *uio,
orbis::Thread *thread) {
auto pipe = static_cast<orbis::Pipe *>(file)->other;
ORBIS_LOG_ERROR(__FUNCTION__, thread->name, thread->tid, file);
ORBIS_LOG_ERROR(__FUNCTION__, thread->name.c_str(), thread->tid, file);
std::size_t cnt = 0;
for (auto vec : std::span(uio->iov, uio->iovcnt)) {
@ -70,8 +70,8 @@ static orbis::ErrorCode pipe_write(orbis::File *file, orbis::Uio *uio,
uio->resid -= cnt;
uio->offset += cnt;
ORBIS_LOG_ERROR(__FUNCTION__, thread->name, thread->tid, file, uio->resid,
uio->offset, file->nextOff, cnt);
ORBIS_LOG_ERROR(__FUNCTION__, thread->name.c_str(), thread->tid, file,
uio->resid, uio->offset, file->nextOff, cnt);
thread->where();
return {};
}

View file

@ -78,7 +78,7 @@ orbis::SysResult orbis::sys_cpuset_getaffinity(Thread *thread, cpulevel_t level,
case CpuLevel::Which:
switch (CpuWhich(which)) {
case CpuWhich::Tid: {
Thread *whichThread = nullptr;
rx::Ref<Thread> whichThread = nullptr;
if (id == ~id_t(0) || thread->tid == id) {
whichThread = thread;
} else {
@ -97,7 +97,7 @@ orbis::SysResult orbis::sys_cpuset_getaffinity(Thread *thread, cpulevel_t level,
if (id == ~id_t(0) || id == thread->tproc->pid) {
whichProcess = thread->tproc;
} else {
whichProcess = g_context->findProcessById(id);
whichProcess = findProcessById(id);
if (whichProcess == nullptr) {
return ErrorCode::SRCH;
@ -132,7 +132,7 @@ orbis::SysResult orbis::sys_cpuset_setaffinity(Thread *thread, cpulevel_t level,
case CpuLevel::Which:
switch (CpuWhich(which)) {
case CpuWhich::Tid: {
Thread *whichThread = nullptr;
rx::Ref<Thread> whichThread = nullptr;
if (id == ~id_t(0) || thread->tid == id) {
whichThread = thread;
} else {
@ -163,7 +163,7 @@ orbis::SysResult orbis::sys_cpuset_setaffinity(Thread *thread, cpulevel_t level,
} else {
ORBIS_LOG_ERROR(__FUNCTION__, "process not found", level, which, id,
cpusetsize);
whichProcess = g_context->findProcessById(id);
whichProcess = findProcessById(id);
if (whichProcess == nullptr) {
return ErrorCode::SRCH;

View file

@ -18,7 +18,7 @@ orbis::SysResult orbis::sys_kenv(Thread *thread, sint what,
size_t entry = 0;
// Entry: size of both full buffers, the '=' and the '\0' at the end
if (value == nullptr || len == 0) {
entry = key.size() + 1 + strnlen(env_value, 128) + 1;
entry = key.size() + 1 + env_value.size() + 1;
} else {
char buf[128 * 2 + 2];
@ -28,9 +28,8 @@ orbis::SysResult orbis::sys_kenv(Thread *thread, sint what,
*_buf++ = '=';
const size_t value_size = strnlen(env_value, 128);
std::strncpy(_buf, env_value, value_size);
_buf += value_size;
std::strncpy(_buf, env_value.data(), env_value.size());
_buf += env_value.size();
*_buf++ = '\0';
@ -58,16 +57,16 @@ orbis::SysResult orbis::sys_kenv(Thread *thread, sint what,
if (it == kenv.end()) {
return ErrorCode::NOENT;
}
const char *buf = it->second;
ORBIS_RET_ON_ERROR(uwriteRaw(value, buf, std::min(len, 128)));
ORBIS_RET_ON_ERROR(uwriteRaw(value, it->second.data(), it->second.size()));
break;
}
case kenv_set: {
if (len < 1) {
return ErrorCode::INVAL;
}
char *_value_buf = kenv[kstring(_name)];
ORBIS_RET_ON_ERROR(ureadString(_value_buf, 128, value));
auto &_value_buf = kenv[kstring(_name)];
ORBIS_RET_ON_ERROR(
ureadString(_value_buf.data(), _value_buf.max_size() + 1, value));
break;
}
case kenv_unset: {

View file

@ -89,7 +89,7 @@ static SysResult keventChange(KQueue *kq, KEvent &change, Thread *thread) {
nodeIt = kq->notes.begin();
if (change.filter == kEvFiltProc) {
auto process = g_context->findProcessById(change.ident);
auto process = findProcessById(change.ident);
if (process == nullptr) {
return ErrorCode::SRCH;
}

View file

@ -25,7 +25,7 @@ orbis::SysResult orbis::sys_wait4(Thread *thread, sint pid, ptr<sint> status,
int hostPid = pid;
if (pid > 0) {
auto process = g_context->findProcessById(pid);
auto process = findProcessById(pid);
if (process == nullptr) {
return ErrorCode::SRCH;
}
@ -42,7 +42,7 @@ orbis::SysResult orbis::sys_wait4(Thread *thread, sint pid, ptr<sint> status,
ORBIS_LOG_ERROR(__FUNCTION__, pid, status, options, rusage, result, stat);
auto process = g_context->findProcessByHostId(result);
auto process = findProcessByHostId(result);
if (process == nullptr) {
ORBIS_LOG_ERROR("host process not found", result);
continue;

View file

@ -303,129 +303,8 @@ orbis::SysResult orbis::sys_freebsd6_ftruncate(Thread *thread, sint fd, sint,
off_t length) {
return sys_ftruncate(thread, fd, length);
}
// clang-format off
#define IOCPARM_SHIFT 13 /* number of bits for ioctl size */
#define IOCPARM_MASK ((1 << IOCPARM_SHIFT) - 1) /* parameter length mask */
#define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
#define IOCBASECMD(x) ((x) & ~(IOCPARM_MASK << 16))
#define IOCGROUP(x) (((x) >> 8) & 0xff)
#define IOCPARM_MAX (1 << IOCPARM_SHIFT) /* max size of ioctl */
#define IOC_VOID 0x20000000 /* no parameters */
#define IOC_OUT 0x40000000 /* copy out parameters */
#define IOC_IN 0x80000000 /* copy in parameters */
#define IOC_INOUT (IOC_IN | IOC_OUT)
#define IOC_DIRMASK (IOC_VOID | IOC_OUT | IOC_IN)
#define _IOC(inout, group, num, len) \
((unsigned long)((inout) | (((len) & IOCPARM_MASK) << 16) | ((group) << 8) | \
(num)))
#define _IO(g, n) _IOC(IOC_VOID, (g), (n), 0)
#define _IOWINT(g, n) _IOC(IOC_VOID, (g), (n), sizeof(int))
#define _IOR(g, n, t) _IOC(IOC_OUT, (g), (n), sizeof(t))
#define _IOW(g, n, t) _IOC(IOC_IN, (g), (n), sizeof(t))
/* this should be _IORW, but stdio got there first */
#define _IOWR(g, n, t) _IOC(IOC_INOUT, (g), (n), sizeof(t))
// clang-format on
static std::string iocGroupToString(unsigned iocGroup) {
if (iocGroup >= 128) {
const char *sceGroups[] = {
"DEV",
"DMEM",
"GC",
"DCE",
"UVD",
"VCE",
"DBGGC",
"TWSI",
"MDBG",
"DEVENV",
"AJM",
"TRACE",
"IBS",
"MBUS",
"HDMI",
"CAMERA",
"FAN",
"THERMAL",
"PFS",
"ICC_CONFIG",
"IPC",
"IOSCHED",
"ICC_INDICATOR",
"EXFATFS",
"ICC_NVS",
"DVE",
"ICC_POWER",
"AV_CONTROL",
"ICC_SC_CONFIGURATION",
"ICC_DEVICE_POWER",
"SSHOT",
"DCE_SCANIN",
"FSCTRL",
"HMD",
"SHM",
"PHYSHM",
"HMDDFU",
"BLUETOOTH_HID",
"SBI",
"S3DA",
"SPM",
"BLOCKPOOL",
"SDK_EVENTLOG",
};
if (iocGroup - 127 >= std::size(sceGroups)) {
return "'?'";
}
return sceGroups[iocGroup - 127];
}
if (isprint(iocGroup)) {
return "'" + std::string(1, (char)iocGroup) + "'";
}
return "'?'";
}
static void printIoctl(unsigned long arg) {
std::printf("0x%lx { IO%s%s %lu(%s), %lu, %lu }\n", arg,
arg & IOC_OUT ? "R" : "", arg & IOC_IN ? "W" : "", IOCGROUP(arg),
iocGroupToString(IOCGROUP(arg)).c_str(), arg & 0xFF,
IOCPARM_LEN(arg));
}
static void ioctlToStream(std::ostream &stream, unsigned long arg) {
stream << "0x" << std::hex << arg << " { IO";
if ((arg & IOC_OUT) != 0) {
stream << 'R';
}
if ((arg & IOC_IN) != 0) {
stream << 'W';
}
if ((arg & IOC_VOID) != 0) {
stream << 'i';
}
stream << " 0x" << IOCGROUP(arg);
stream << "('" << iocGroupToString(IOCGROUP(arg)) << "'), ";
stream << std::dec << (arg & 0xFF) << ", " << IOCPARM_LEN(arg) << " }";
}
static std::string ioctlToString(unsigned long arg) {
std::ostringstream stream;
ioctlToStream(stream, arg);
return std::move(stream).str();
}
orbis::SysResult orbis::sys_ioctl(Thread *thread, sint fd, ulong com,
caddr_t data) {
auto str = ioctlToString(com);
// ORBIS_LOG_WARNING(__FUNCTION__, fd, com, str);
rx::Ref<File> file = thread->tproc->fileDescriptors.get(fd);
if (file == nullptr) {
return ErrorCode::BADF;
@ -433,6 +312,10 @@ orbis::SysResult orbis::sys_ioctl(Thread *thread, sint fd, ulong com,
auto ioctl = file->ops->ioctl;
if (ioctl == nullptr) {
if (auto device = file->device.get()) {
return device->ioctl(com, data, thread);
}
return ErrorCode::NOTSUP;
}

View file

@ -24,7 +24,7 @@ orbis::SysResult orbis::sys_rtprio_thread(Thread *thread, sint function,
ORBIS_LOG_ERROR(__FUNCTION__, function, lwpid, rtp->prio, rtp->type);
thread->where();
Thread *targetThread;
rx::Ref<Thread> targetThread;
if (lwpid == thread->tid || lwpid == -1) {
targetThread = thread;
} else {

View file

@ -940,7 +940,7 @@ orbis::SysResult orbis::sys_dmem_container(Thread *thread, uint id) {
orbis::SysResult orbis::sys_get_authinfo(Thread *thread, pid_t pid,
ptr<AuthInfo> info) {
auto process = pid > 0 ? g_context->findProcessById(pid) : thread->tproc;
auto process = pid > 0 ? findProcessById(pid) : thread->tproc;
if (process == nullptr) {
return ErrorCode::SRCH;
}
@ -1188,21 +1188,20 @@ orbis::SysResult orbis::sys_randomized_path(Thread *thread, sint type,
}
orbis::SysResult orbis::sys_rdup(Thread *thread, sint pid, sint fd) {
ORBIS_LOG_TODO(__FUNCTION__, pid, fd);
for (auto it = g_context->getProcessList(); it != nullptr; it = it->next) {
auto &p = it->object;
if (p.pid != pid) {
continue;
}
auto process = pid == -1 || pid == thread->tproc->pid ? thread->tproc
: findProcessById(pid);
auto file = p.fileDescriptors.get(fd);
if (file == nullptr) {
return ErrorCode::BADF;
}
thread->retval[0] = thread->tproc->fileDescriptors.insert(std::move(file));
return {};
if (!process) {
return ErrorCode::SRCH;
}
return ErrorCode::SRCH;
auto file = process->fileDescriptors.get(fd);
if (file == nullptr) {
return ErrorCode::BADF;
}
thread->retval[0] = thread->tproc->fileDescriptors.insert(std::move(file));
return {};
}
orbis::SysResult orbis::sys_dl_get_metadata(Thread *thread /* TODO */) {
return ErrorCode::NOSYS;
@ -1297,7 +1296,7 @@ orbis::SysResult orbis::sys_budget_get_ptype(Thread *thread, sint pid) {
if (pid < 0 || pid == thread->tproc->pid) {
process = thread->tproc;
} else {
process = g_context->findProcessById(pid);
process = findProcessById(pid);
if (!process) {
return ErrorCode::SRCH;
@ -1337,14 +1336,14 @@ orbis::SysResult orbis::sys_get_resident_fmem_count(Thread *thread, pid_t pid) {
}
orbis::SysResult orbis::sys_thr_get_name(Thread *thread, lwpid_t lwpid,
char *buf, size_t buflen) {
Thread *searchThread;
rx::Ref<Thread> searchThread;
if (thread->tid == lwpid || lwpid == -1) {
searchThread = thread;
} else {
searchThread = thread->tproc->threadsMap.get(lwpid - thread->tproc->pid);
if (searchThread == nullptr) {
if (auto process = g_context->findProcessById(lwpid)) {
if (auto process = findProcessById(lwpid)) {
searchThread = process->threadsMap.get(lwpid - process->pid);
}
}
@ -1354,11 +1353,11 @@ orbis::SysResult orbis::sys_thr_get_name(Thread *thread, lwpid_t lwpid,
}
}
auto namelen = std::strlen(searchThread->name);
auto namelen = searchThread->name.length();
auto writeLen = std::min(namelen + 1, buflen);
if (writeLen > 0) {
ORBIS_RET_ON_ERROR(uwriteRaw(buf, searchThread->name, writeLen - 1));
ORBIS_RET_ON_ERROR(uwriteRaw(buf, searchThread->name.data(), writeLen - 1));
buf[writeLen] = 0;
}

View file

@ -114,7 +114,7 @@ orbis::SysResult orbis::sys_kill(Thread *thread, sint pid, sint signum) {
int hostPid = pid;
if (pid > 0) {
auto process = g_context->findProcessById(pid);
auto process = findProcessById(pid);
if (process == nullptr) {
return ErrorCode::SRCH;
}

View file

@ -225,7 +225,7 @@ SysResult kern_sysctl(Thread *thread, ptr<sint> name, uint namelen,
ORBIS_LOG_ERROR("KERN_PROC_PROC 2");
if (namelen >= 4) {
auto process = g_context->findProcessById(name[3]);
auto process = findProcessById(name[3]);
if (process == nullptr || process->exitStatus.has_value()) {
return ErrorCode::SRCH;
}
@ -259,7 +259,7 @@ SysResult kern_sysctl(Thread *thread, ptr<sint> name, uint namelen,
if (name[0] == kern && name[1] == proc && name[2] == 36) {
Process *process = thread->tproc;
if (process->pid != name[3]) {
process = g_context->findProcessById(name[3]);
process = findProcessById(name[3]);
if (process == nullptr) {
ORBIS_LOG_ERROR("get sdk version by pid: process not found", name[3],
thread->tproc->pid);
@ -290,7 +290,7 @@ SysResult kern_sysctl(Thread *thread, ptr<sint> name, uint namelen,
// 1 - 14 - 35 - pid
Process *process = thread->tproc;
if (process->pid != name[3] && name[3] != -1) {
process = g_context->findProcessById(name[3]);
process = findProcessById(name[3]);
if (process == nullptr) {
ORBIS_LOG_ERROR("appinfo process not found", name[3],
thread->tproc->pid);
@ -461,7 +461,7 @@ SysResult kern_sysctl(Thread *thread, ptr<sint> name, uint namelen,
if (name[0] == kern && name[1] == proc && name[2] == 68) {
Process *process = thread->tproc;
if (process->pid != name[3]) {
process = g_context->findProcessById(name[3]);
process = findProcessById(name[3]);
if (process == nullptr) {
ORBIS_LOG_ERROR("get ps5 sdk version by pid: process not found",
name[3], thread->tproc->pid);

View file

@ -0,0 +1,179 @@
#include "thread/Process.hpp"
#include "KernelAllocator.hpp"
#include "KernelContext.hpp"
#include "KernelObject.hpp"
#include "kernel/KernelObject.hpp"
#include "rx/LinkedNode.hpp"
#include "rx/Serializer.hpp"
#include "rx/align.hpp"
#include "thread/Thread.hpp"
#include <algorithm>
struct ProcessIdList {
rx::OwningIdMap<std::uint8_t, orbis::pid_t, 256, 0> pidMap;
void serialize(rx::Serializer &s) const {
pidMap.walk([&s](std::uint8_t id, orbis::pid_t value) {
s.serialize(id);
s.serialize(value);
});
s.serialize<std::uint8_t>(-1);
}
void deserialize(rx::Deserializer &s) {
while (true) {
auto id = s.deserialize<std::uint8_t>();
if (id == static_cast<std::uint8_t>(-1)) {
break;
}
auto value = s.deserialize<orbis::pid_t>();
if (s.failure()) {
break;
}
if (!pidMap.emplace_at(id, value)) {
s.setFailure();
return;
}
}
}
};
static auto g_processIdList =
orbis::createGlobalObject<kernel::LockableKernelObject<ProcessIdList>>();
orbis::pid_t orbis::allocatePid() {
std::lock_guard lock(*g_processIdList);
return g_processIdList->pidMap.emplace(0).first * 10000 + 1;
}
struct ProcessList {
rx::LinkedNode<orbis::Process> *list = nullptr;
void serialize(rx::Serializer &s) const {
for (auto proc = list; proc != nullptr; proc = proc->next) {
s.serialize(proc->object.pid);
s.serialize(proc->object);
}
s.serialize<pid_t>(-1);
}
void deserialize(rx::Deserializer &s) {
while (true) {
auto pid = s.deserialize<pid_t>();
if (pid == static_cast<pid_t>(-1) || s.failure()) {
break;
}
auto process = orbis::createProcess(nullptr, pid);
s.deserialize(*process);
if (s.failure()) {
break;
}
}
}
};
static auto g_processList =
orbis::createGlobalObject<kernel::LockableKernelObject<ProcessList>>();
void orbis::deleteProcess(orbis::Process *proc) {
auto procNode = reinterpret_cast<rx::LinkedNode<Process> *>(proc);
{
std::lock_guard lock(*g_processList);
auto next = procNode->erase();
if (procNode == g_processList->list) {
g_processList->list = next;
}
}
kdelete(procNode);
}
orbis::Process *orbis::findProcessById(pid_t pid) {
for (std::size_t i = 0; i < 20; ++i) {
{
std::lock_guard lock(*g_processList);
for (auto proc = g_processList->list; proc != nullptr;
proc = proc->next) {
if (proc->object.pid == pid) {
return &proc->object;
}
}
}
std::this_thread::sleep_for(std::chrono::microseconds(50));
}
return nullptr;
}
orbis::Process *orbis::findProcessByHostId(std::uint64_t pid) {
for (std::size_t i = 0; i < 20; ++i) {
{
std::lock_guard lock(*g_processList);
for (auto proc = g_processList->list; proc != nullptr;
proc = proc->next) {
if (proc->object.hostPid == pid) {
return &proc->object;
}
}
}
std::this_thread::sleep_for(std::chrono::microseconds(50));
}
return nullptr;
}
void orbis::Process::serialize(rx::Serializer &s) const {
Process::Storage::SerializeAll(storage, s);
}
void orbis::Process::deserialize(rx::Deserializer &s) {
Process::Storage::DeserializeAll(storage, s);
}
orbis::Process::~Process() {
Process::Storage::DestructAll(storage);
auto size = sizeof(Process);
size = rx::alignUp(size, Process::Storage::GetAlignment());
size += Process::Storage::GetSize();
kfree(this, size);
}
orbis::Process *orbis::createProcess(Process *parentProcess, pid_t pid) {
if (pid == static_cast<pid_t>(-1)) {
pid = allocatePid();
}
auto size = sizeof(rx::LinkedNode<Process>);
size = rx::alignUp(size, Process::Storage::GetAlignment());
auto storageOffset = size;
size += Process::Storage::GetSize();
auto memory = (std::byte *)kalloc(
size, std::max<std::size_t>(alignof(rx::LinkedNode<Process>),
Process::Storage::GetAlignment()));
auto result = new (memory) rx::LinkedNode<Process>();
result->object.context = g_context.get();
result->object.storage = memory + storageOffset;
result->object.parentProcess = parentProcess;
result->object.pid = pid;
Process::Storage::ConstructAll(result->object.storage);
std::lock_guard lock(*g_processList);
if (auto list = g_processList->list) {
list->insertPrev(*result);
}
g_processList->list = result;
return &result->object;
}

View file

@ -0,0 +1,38 @@
#include "thread/Thread.hpp"
#include "thread/Process.hpp"
orbis::Thread::~Thread() {
Thread::Storage::DestructAll(storage);
auto size = sizeof(Thread);
size = rx::alignUp(size, Thread::Storage::GetAlignment());
size += Thread::Storage::GetSize();
kfree(this, size);
}
orbis::Thread *orbis::createThread(Process *process, std::string_view name) {
auto size = sizeof(Thread);
size = rx::alignUp(size, Thread::Storage::GetAlignment());
auto storageOffset = size;
size += Thread::Storage::GetSize();
auto memory = (std::byte *)kalloc(
size,
std::max<std::size_t>(alignof(Thread), Thread::Storage::GetAlignment()));
auto result = new (memory) Thread();
result->storage = memory + storageOffset;
result->tproc = process;
result->name = name;
Thread::Storage::ConstructAll(result->storage);
std::lock_guard lock(process->mtx);
auto baseId = process->threadsMap.insert(result);
result->tproc = process;
result->tid = process->pid + baseId;
result->state = orbis::ThreadState::RUNNING;
return result;
}

View file

@ -339,9 +339,8 @@ static orbis::ErrorCode host_mmap(orbis::File *file, void **address,
if (!hostFile->dirEntries.empty())
return orbis::ErrorCode::ISDIR;
auto result =
vm::map(*address, size, prot, flags, vm::kMapInternalReserveOnly,
hostFile->device.cast<IoDevice>().get(), offset);
auto result = vm::map(*address, size, prot, flags,
vm::kMapInternalReserveOnly, hostFile->device.get(), offset);
if (result == (void *)-1) {
return orbis::ErrorCode::NOMEM;
@ -695,8 +694,8 @@ static const orbis::FileOps socketOps = {
.getsockopt = socket_getsockopt,
};
IoDevice *createHostIoDevice(orbis::kstring hostPath,
orbis::kstring virtualPath) {
orbis::IoDevice *createHostIoDevice(orbis::kstring hostPath,
orbis::kstring virtualPath) {
while (hostPath.size() > 0 && hostPath.ends_with("/")) {
hostPath.resize(hostPath.size() - 1);
}
@ -778,44 +777,44 @@ orbis::ErrorCode HostFsDevice::open(rx::Ref<orbis::File> *file,
int realFlags = flags & O_ACCMODE;
flags &= ~O_ACCMODE;
if ((flags & kOpenFlagAppend) != 0) {
if ((flags & orbis::kOpenFlagAppend) != 0) {
realFlags |= O_APPEND;
flags &= ~kOpenFlagAppend;
flags &= ~orbis::kOpenFlagAppend;
}
if ((flags & kOpenFlagNonBlock) != 0) {
if ((flags & orbis::kOpenFlagNonBlock) != 0) {
realFlags |= O_NONBLOCK;
flags &= ~kOpenFlagNonBlock;
flags &= ~orbis::kOpenFlagNonBlock;
}
if ((flags & kOpenFlagFsync) != 0) {
if ((flags & orbis::kOpenFlagFsync) != 0) {
realFlags |= O_FSYNC;
flags &= ~kOpenFlagFsync;
flags &= ~orbis::kOpenFlagFsync;
}
if ((flags & kOpenFlagAsync) != 0) {
if ((flags & orbis::kOpenFlagAsync) != 0) {
realFlags |= O_ASYNC;
flags &= ~kOpenFlagAsync;
flags &= ~orbis::kOpenFlagAsync;
}
if ((flags & kOpenFlagTrunc) != 0) {
if ((flags & orbis::kOpenFlagTrunc) != 0) {
realFlags |= O_TRUNC;
flags &= ~kOpenFlagTrunc;
flags &= ~orbis::kOpenFlagTrunc;
}
if ((flags & kOpenFlagCreat) != 0) {
if ((flags & orbis::kOpenFlagCreat) != 0) {
realFlags |= O_CREAT;
flags &= ~kOpenFlagCreat;
flags &= ~orbis::kOpenFlagCreat;
}
if ((flags & kOpenFlagExcl) != 0) {
if ((flags & orbis::kOpenFlagExcl) != 0) {
realFlags |= O_EXCL;
flags &= ~kOpenFlagExcl;
flags &= ~orbis::kOpenFlagExcl;
}
if ((flags & kOpenFlagDirectory) != 0) {
if ((flags & orbis::kOpenFlagDirectory) != 0) {
realFlags |= O_DIRECTORY;
flags &= ~kOpenFlagDirectory;
flags &= ~orbis::kOpenFlagDirectory;
}
if (flags != 0) {
@ -937,7 +936,7 @@ orbis::ErrorCode HostFsDevice::rename(const char *from, const char *to,
return convertErrorCode(ec);
}
orbis::File *createHostFile(int hostFd, rx::Ref<IoDevice> device,
orbis::File *createHostFile(int hostFd, rx::Ref<orbis::IoDevice> device,
bool alignTruncate) {
auto newFile = orbis::knew<HostFile>();
newFile->hostFd = hostFd;
@ -947,7 +946,7 @@ orbis::File *createHostFile(int hostFd, rx::Ref<IoDevice> device,
return newFile;
}
struct FdWrapDevice : public IoDevice {
struct FdWrapDevice : public orbis::IoDevice {
int fd;
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
@ -959,7 +958,7 @@ struct FdWrapDevice : public IoDevice {
}
};
IoDevice *createFdWrapDevice(int fd) {
orbis::IoDevice *createFdWrapDevice(int fd) {
auto result = orbis::knew<FdWrapDevice>();
result->fd = fd;
return result;

View file

@ -1,56 +1,13 @@
#pragma once
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "rx/Rc.hpp"
#include <cstdint>
#include <system_error>
enum OpenFlags {
kOpenFlagReadOnly = 0x0,
kOpenFlagWriteOnly = 0x1,
kOpenFlagReadWrite = 0x2,
kOpenFlagNonBlock = 0x4,
kOpenFlagAppend = 0x8,
kOpenFlagShLock = 0x10,
kOpenFlagExLock = 0x20,
kOpenFlagAsync = 0x40,
kOpenFlagFsync = 0x80,
kOpenFlagCreat = 0x200,
kOpenFlagTrunc = 0x400,
kOpenFlagExcl = 0x800,
kOpenFlagDSync = 0x1000,
kOpenFlagDirect = 0x10000,
kOpenFlagDirectory = 0x20000,
};
struct IoDevice : rx::RcBase {
virtual orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) = 0;
virtual orbis::ErrorCode unlink(const char *path, bool recursive,
orbis::Thread *thread) {
return orbis::ErrorCode::NOTSUP;
}
virtual orbis::ErrorCode createSymlink(const char *target,
const char *linkPath,
orbis::Thread *thread) {
return orbis::ErrorCode::NOTSUP;
}
virtual orbis::ErrorCode mkdir(const char *path, int mode,
orbis::Thread *thread) {
return orbis::ErrorCode::NOTSUP;
}
virtual orbis::ErrorCode rmdir(const char *path, orbis::Thread *thread) {
return orbis::ErrorCode::NOTSUP;
}
virtual orbis::ErrorCode rename(const char *from, const char *to,
orbis::Thread *thread) {
return orbis::ErrorCode::NOTSUP;
}
};
struct HostFsDevice : IoDevice {
struct HostFsDevice : orbis::IoDevice {
orbis::kstring hostPath;
orbis::kstring virtualPath;
@ -72,12 +29,12 @@ struct HostFsDevice : IoDevice {
orbis::ErrorCode convertErrorCode(const std::error_code &code);
orbis::ErrorCode convertErrno();
IoDevice *createHostIoDevice(orbis::kstring hostPath,
orbis::kstring virtualPath);
orbis::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);
orbis::File *createHostFile(int hostFd, rx::Ref<IoDevice> device,
orbis::File *createHostFile(int hostFd, rx::Ref<orbis::IoDevice> device,
bool alignTruncate = false);
IoDevice *createFdWrapDevice(int fd);
orbis::IoDevice *createFdWrapDevice(int fd);

View file

@ -3,57 +3,59 @@
#include "audio/AudioDevice.hpp"
#include <cstdint>
namespace orbis {
struct IoDevice;
}
IoDevice *createDceCharacterDevice();
IoDevice *createDipswCharacterDevice();
IoDevice *createDmemCharacterDevice(int index);
IoDevice *createGcCharacterDevice();
IoDevice *createHidCharacterDevice();
IoDevice *createHmd3daCharacterDevice();
IoDevice *createHmdCmdCharacterDevice();
IoDevice *createHmdMmapCharacterDevice();
IoDevice *createHmdSnsrCharacterDevice();
IoDevice *createNullCharacterDevice();
IoDevice *createZeroCharacterDevice();
IoDevice *createRngCharacterDevice();
IoDevice *createAjmCharacterDevice();
IoDevice *createIccConfigurationCharacterDevice();
IoDevice *createNpdrmCharacterDevice();
IoDevice *createConsoleCharacterDevice(int inputFd, int outputFd);
IoDevice *createSblSrvCharacterDevice();
IoDevice *createShmDevice();
IoDevice *createBlockPoolDevice();
IoDevice *createUrandomCharacterDevice();
IoDevice *createCameraCharacterDevice();
IoDevice *createNotificationCharacterDevice(int index);
IoDevice *createMBusCharacterDevice();
IoDevice *createBtCharacterDevice();
IoDevice *createXptCharacterDevice();
IoDevice *createCdCharacterDevice();
IoDevice *createMetaDbgCharacterDevice();
IoDevice *createHddCharacterDevice(std::uint64_t size);
IoDevice *createAoutCharacterDevice(std::int8_t id, AudioDevice *device);
IoDevice *createAVControlCharacterDevice();
IoDevice *createHDMICharacterDevice();
IoDevice *createMBusAVCharacterDevice();
IoDevice *createScaninCharacterDevice();
IoDevice *createS3DACharacterDevice();
IoDevice *createGbaseCharacterDevice();
IoDevice *createDevStatCharacterDevice();
IoDevice *createDevCtlCharacterDevice();
IoDevice *createDevActCharacterDevice();
IoDevice *createUVDCharacterDevice();
IoDevice *createVCECharacterDevice();
IoDevice *createEvlgCharacterDevice(int outputFd);
IoDevice *createSrtcCharacterDevice();
IoDevice *createScreenShotCharacterDevice();
IoDevice *createLvdCtlCharacterDevice();
IoDevice *createIccPowerCharacterDevice();
IoDevice *createCaymanRegCharacterDevice();
IoDevice *createA53IoCharacterDevice();
IoDevice *createNsidCtlCharacterDevice();
IoDevice *createHmd2CmdCharacterDevice();
IoDevice *createHmd2ImuCharacterDevice();
IoDevice *createHmd2GazeCharacterDevice();
IoDevice *createHmd2GenDataCharacterDevice();
orbis::IoDevice *createDceCharacterDevice();
orbis::IoDevice *createDipswCharacterDevice();
orbis::IoDevice *createDmemCharacterDevice(int index);
orbis::IoDevice *createGcCharacterDevice();
orbis::IoDevice *createHidCharacterDevice();
orbis::IoDevice *createHmd3daCharacterDevice();
orbis::IoDevice *createHmdCmdCharacterDevice();
orbis::IoDevice *createHmdMmapCharacterDevice();
orbis::IoDevice *createHmdSnsrCharacterDevice();
orbis::IoDevice *createNullCharacterDevice();
orbis::IoDevice *createZeroCharacterDevice();
orbis::IoDevice *createRngCharacterDevice();
orbis::IoDevice *createAjmCharacterDevice();
orbis::IoDevice *createIccConfigurationCharacterDevice();
orbis::IoDevice *createNpdrmCharacterDevice();
orbis::IoDevice *createConsoleCharacterDevice(int inputFd, int outputFd);
orbis::IoDevice *createSblSrvCharacterDevice();
orbis::IoDevice *createShmDevice();
orbis::IoDevice *createBlockPoolDevice();
orbis::IoDevice *createUrandomCharacterDevice();
orbis::IoDevice *createCameraCharacterDevice();
orbis::IoDevice *createNotificationCharacterDevice(int index);
orbis::IoDevice *createMBusCharacterDevice();
orbis::IoDevice *createBtCharacterDevice();
orbis::IoDevice *createXptCharacterDevice();
orbis::IoDevice *createCdCharacterDevice();
orbis::IoDevice *createMetaDbgCharacterDevice();
orbis::IoDevice *createHddCharacterDevice(std::uint64_t size);
orbis::IoDevice *createAoutCharacterDevice(std::int8_t id, AudioDevice *device);
orbis::IoDevice *createAVControlCharacterDevice();
orbis::IoDevice *createHDMICharacterDevice();
orbis::IoDevice *createMBusAVCharacterDevice();
orbis::IoDevice *createScaninCharacterDevice();
orbis::IoDevice *createS3DACharacterDevice();
orbis::IoDevice *createGbaseCharacterDevice();
orbis::IoDevice *createDevStatCharacterDevice();
orbis::IoDevice *createDevCtlCharacterDevice();
orbis::IoDevice *createDevActCharacterDevice();
orbis::IoDevice *createUVDCharacterDevice();
orbis::IoDevice *createVCECharacterDevice();
orbis::IoDevice *createEvlgCharacterDevice(int outputFd);
orbis::IoDevice *createSrtcCharacterDevice();
orbis::IoDevice *createScreenShotCharacterDevice();
orbis::IoDevice *createLvdCtlCharacterDevice();
orbis::IoDevice *createIccPowerCharacterDevice();
orbis::IoDevice *createCaymanRegCharacterDevice();
orbis::IoDevice *createA53IoCharacterDevice();
orbis::IoDevice *createNsidCtlCharacterDevice();
orbis::IoDevice *createHmd2CmdCharacterDevice();
orbis::IoDevice *createHmd2ImuCharacterDevice();
orbis::IoDevice *createHmd2GazeCharacterDevice();
orbis::IoDevice *createHmd2GenDataCharacterDevice();

View file

@ -1,8 +1,8 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
#include <chrono>
#include <thread>
struct A53IoFile : orbis::File {};
@ -26,7 +26,7 @@ static const orbis::FileOps fileOps = {
.read = a53io_read,
};
struct A53IoDevice : IoDevice {
struct A53IoDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -39,4 +39,6 @@ struct A53IoDevice : IoDevice {
}
};
IoDevice *createA53IoCharacterDevice() { return orbis::knew<A53IoDevice>(); }
orbis::IoDevice *createA53IoCharacterDevice() {
return orbis::knew<A53IoDevice>();
}

File diff suppressed because it is too large Load diff

View file

@ -27,7 +27,7 @@
struct AoutFile : orbis::File {};
struct AoutDevice : public IoDevice {
struct AoutDevice : public orbis::IoDevice {
std::int8_t id;
rx::Ref<AudioDevice> audioDevice;
@ -205,6 +205,7 @@ orbis::ErrorCode AoutDevice::open(rx::Ref<orbis::File> *file, const char *path,
return {};
}
IoDevice *createAoutCharacterDevice(std::int8_t id, AudioDevice *device) {
orbis::IoDevice *createAoutCharacterDevice(std::int8_t id,
AudioDevice *device) {
return orbis::knew<AoutDevice>(id, device);
}

View file

@ -34,7 +34,7 @@ static const orbis::FileOps fileOps = {
.ioctl = av_control_ioctl,
};
struct AVControlDevice : IoDevice {
struct AVControlDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -47,6 +47,6 @@ struct AVControlDevice : IoDevice {
}
};
IoDevice *createAVControlCharacterDevice() {
orbis::IoDevice *createAVControlCharacterDevice() {
return orbis::knew<AVControlDevice>();
}

View file

@ -1,6 +1,6 @@
#include "blockpool.hpp"
#include "dmem.hpp"
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/KernelContext.hpp"
#include "orbis/file.hpp"
@ -139,4 +139,6 @@ orbis::ErrorCode BlockPoolDevice::unmap(void *address, std::uint64_t len,
}
return orbis::ErrorCode::INVAL;
}
IoDevice *createBlockPoolDevice() { return orbis::knew<BlockPoolDevice>(); }
orbis::IoDevice *createBlockPoolDevice() {
return orbis::knew<BlockPoolDevice>();
}

View file

@ -1,6 +1,6 @@
#pragma once
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/error/ErrorCode.hpp"
#include "orbis/file.hpp"
#include "rx/MemoryTable.hpp"
@ -8,7 +8,7 @@
#include "rx/SharedMutex.hpp"
#include <cstdint>
struct BlockPoolDevice : public IoDevice {
struct BlockPoolDevice : public orbis::IoDevice {
rx::shared_mutex mtx;
rx::MemoryAreaTable<> pool;

View file

@ -16,7 +16,7 @@ static const orbis::FileOps fileOps = {
.ioctl = bt_ioctl,
};
struct BtDevice : IoDevice {
struct BtDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -29,4 +29,4 @@ struct BtDevice : IoDevice {
}
};
IoDevice *createBtCharacterDevice() { return orbis::knew<BtDevice>(); }
orbis::IoDevice *createBtCharacterDevice() { return orbis::knew<BtDevice>(); }

View file

@ -49,7 +49,7 @@ static const orbis::FileOps fileOps = {
.write = camera_write,
};
struct CameraDevice : IoDevice {
struct CameraDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -62,4 +62,6 @@ struct CameraDevice : IoDevice {
}
};
IoDevice *createCameraCharacterDevice() { return orbis::knew<CameraDevice>(); }
orbis::IoDevice *createCameraCharacterDevice() {
return orbis::knew<CameraDevice>();
}

View file

@ -4,7 +4,7 @@
#include "orbis/thread/Thread.hpp"
#include "orbis/utils/Logs.hpp"
struct CaymanRegDevice : IoDevice {
struct CaymanRegDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -34,6 +34,6 @@ orbis::ErrorCode CaymanRegDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createCaymanRegCharacterDevice() {
orbis::IoDevice *createCaymanRegCharacterDevice() {
return orbis::knew<CaymanRegDevice>();
}

View file

@ -23,7 +23,7 @@ static const orbis::FileOps fileOps = {
.ioctl = cd_ioctl,
};
struct CdDevice : IoDevice {
struct CdDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -36,4 +36,4 @@ struct CdDevice : IoDevice {
}
};
IoDevice *createCdCharacterDevice() { return orbis::knew<CdDevice>(); }
orbis::IoDevice *createCdCharacterDevice() { return orbis::knew<CdDevice>(); }

View file

@ -9,7 +9,7 @@
#include <unistd.h>
struct ConsoleFile : orbis::File {};
struct ConsoleDevice : IoDevice {
struct ConsoleDevice : orbis::IoDevice {
int inputFd;
int outputFd;
@ -76,6 +76,6 @@ orbis::ErrorCode ConsoleDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createConsoleCharacterDevice(int inputFd, int outputFd) {
orbis::IoDevice *createConsoleCharacterDevice(int inputFd, int outputFd) {
return orbis::knew<ConsoleDevice>(inputFd, outputFd);
}

View file

@ -653,4 +653,4 @@ void DceDevice::initializeProcess(orbis::Process *process) {
}
}
IoDevice *createDceCharacterDevice() { return orbis::knew<DceDevice>(); }
orbis::IoDevice *createDceCharacterDevice() { return orbis::knew<DceDevice>(); }

View file

@ -10,7 +10,7 @@
static constexpr auto kVmIdCount = 6;
struct DceDevice : IoDevice {
struct DceDevice : orbis::IoDevice {
rx::shared_mutex mtx;
std::uint32_t eopCount = 0;
std::uint32_t freeVmIds = (1 << (kVmIdCount + 1)) - 1;

View file

@ -48,7 +48,7 @@ static const orbis::FileOps fileOps = {
.ioctl = devact_ioctl,
};
struct DevActDevice : IoDevice {
struct DevActDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -61,4 +61,6 @@ struct DevActDevice : IoDevice {
}
};
IoDevice *createDevActCharacterDevice() { return orbis::knew<DevActDevice>(); }
orbis::IoDevice *createDevActCharacterDevice() {
return orbis::knew<DevActDevice>();
}

View file

@ -16,7 +16,7 @@ static const orbis::FileOps fileOps = {
.ioctl = devctl_ioctl,
};
struct DevCtlDevice : IoDevice {
struct DevCtlDevice : orbis::IoDevice {
orbis::kstring data;
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
@ -30,4 +30,6 @@ struct DevCtlDevice : IoDevice {
}
};
IoDevice *createDevCtlCharacterDevice() { return orbis::knew<DevCtlDevice>(); }
orbis::IoDevice *createDevCtlCharacterDevice() {
return orbis::knew<DevCtlDevice>();
}

View file

@ -16,7 +16,7 @@ static const orbis::FileOps fileOps = {
.ioctl = devstat_ioctl,
};
struct DevStatDevice : IoDevice {
struct DevStatDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -29,6 +29,6 @@ struct DevStatDevice : IoDevice {
}
};
IoDevice *createDevStatCharacterDevice() {
orbis::IoDevice *createDevStatCharacterDevice() {
return orbis::knew<DevStatDevice>();
}

View file

@ -60,7 +60,7 @@ static const orbis::FileOps ops = {
.ioctl = dipsw_ioctl,
};
struct DipswDevice : public IoDevice {
struct DipswDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -72,4 +72,6 @@ struct DipswDevice : public IoDevice {
}
};
IoDevice *createDipswCharacterDevice() { return orbis::knew<DipswDevice>(); }
orbis::IoDevice *createDipswCharacterDevice() {
return orbis::knew<DipswDevice>();
}

View file

@ -86,7 +86,7 @@ orbis::ErrorCode DmemDevice::mmap(void **address, std::uint64_t len,
static orbis::ErrorCode dmem_ioctl(orbis::File *file, std::uint64_t request,
void *argp, orbis::Thread *thread) {
auto device = static_cast<DmemDevice *>(file->device.get());
auto device = file->device.rawStaticCast<DmemDevice>();
std::lock_guard lock(device->mtx);
switch (request) {
@ -250,7 +250,7 @@ static orbis::ErrorCode dmem_mmap(orbis::File *file, void **address,
std::uint64_t size, std::int32_t prot,
std::int32_t flags, std::int64_t offset,
orbis::Thread *thread) {
auto device = static_cast<DmemDevice *>(file->device.get());
auto device = file->device.rawStaticCast<DmemDevice>();
return device->mmap(address, size, prot, flags, offset);
}
@ -395,7 +395,7 @@ orbis::ErrorCode DmemDevice::open(rx::Ref<orbis::File> *file, const char *path,
return {};
}
IoDevice *createDmemCharacterDevice(int index) {
orbis::IoDevice *createDmemCharacterDevice(int index) {
auto *newDevice = orbis::knew<DmemDevice>();
newDevice->index = index;
newDevice->dmemTotalSize = dmemSize;

View file

@ -1,6 +1,6 @@
#pragma once
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/error/ErrorCode.hpp"
#include "orbis/file.hpp"
@ -10,7 +10,7 @@
#include <rx/MemoryTable.hpp>
#include <unistd.h>
struct DmemDevice : public IoDevice {
struct DmemDevice : public orbis::IoDevice {
rx::shared_mutex mtx;
int index;
int shmFd = -1;

View file

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/error/ErrorCode.hpp"
#include "orbis/file.hpp"
@ -8,7 +8,7 @@
#include <unistd.h>
struct EvlgFile : orbis::File {};
struct EvlgDevice : IoDevice {
struct EvlgDevice : orbis::IoDevice {
int outputFd;
EvlgDevice(int outputFd) : outputFd(outputFd) {}
@ -53,6 +53,6 @@ orbis::ErrorCode EvlgDevice::open(rx::Ref<orbis::File> *file, const char *path,
return {};
}
IoDevice *createEvlgCharacterDevice(int outputFd) {
orbis::IoDevice *createEvlgCharacterDevice(int outputFd) {
return orbis::knew<EvlgDevice>(outputFd);
}

View file

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
@ -36,7 +36,7 @@ static const orbis::FileOps fileOps = {
.ioctl = gbase_ioctl,
};
struct GbaseDevice : IoDevice {
struct GbaseDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -49,4 +49,6 @@ struct GbaseDevice : IoDevice {
}
};
IoDevice *createGbaseCharacterDevice() { return orbis::knew<GbaseDevice>(); }
orbis::IoDevice *createGbaseCharacterDevice() {
return orbis::knew<GbaseDevice>();
}

View file

@ -1,7 +1,7 @@
#include "gpu/DeviceCtl.hpp"
#include "io-device.hpp"
#include "iodev/dce.hpp"
#include "iodev/dmem.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/KernelContext.hpp"
#include "orbis/file.hpp"
@ -24,7 +24,7 @@ struct ComputeQueue {
std::uint64_t len{};
};
struct GcDevice : public IoDevice {
struct GcDevice : public orbis::IoDevice {
rx::shared_mutex mtx;
orbis::kmap<orbis::pid_t, int> clients;
orbis::kmap<std::uint64_t, ComputeQueue> computeQueues;
@ -490,4 +490,4 @@ void GcDevice::removeClient(orbis::Process *process) {
}
}
IoDevice *createGcCharacterDevice() { return orbis::knew<GcDevice>(); }
orbis::IoDevice *createGcCharacterDevice() { return orbis::knew<GcDevice>(); }

View file

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/error/ErrorCode.hpp"
#include "orbis/file.hpp"
@ -9,7 +9,7 @@
struct HddFile : orbis::File {};
struct HddDevice : IoDevice {
struct HddDevice : orbis::IoDevice {
std::uint64_t size;
HddDevice(std::uint64_t size) : size(size) {}
@ -146,6 +146,6 @@ orbis::ErrorCode HddDevice::open(rx::Ref<orbis::File> *fs, const char *path,
return {};
}
IoDevice *createHddCharacterDevice(std::uint64_t size) {
orbis::IoDevice *createHddCharacterDevice(std::uint64_t size) {
return orbis::knew<HddDevice>(size);
}

View file

@ -1,5 +1,5 @@
#include "io-device.hpp"
#include "orbis-config.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
@ -75,7 +75,7 @@ static const orbis::FileOps fileOps = {
.ioctl = hdmi_ioctl,
};
struct HDMIDevice : IoDevice {
struct HDMIDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -88,4 +88,6 @@ struct HDMIDevice : IoDevice {
}
};
IoDevice *createHDMICharacterDevice() { return orbis::knew<HDMIDevice>(); }
orbis::IoDevice *createHDMICharacterDevice() {
return orbis::knew<HDMIDevice>();
}

View file

@ -1,13 +1,12 @@
#include "gpu/DeviceCtl.hpp"
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/KernelContext.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
#include "orbis/utils/Logs.hpp"
#include <chrono>
struct HidDevice : public IoDevice {
struct HidDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -165,4 +164,4 @@ orbis::ErrorCode HidDevice::open(rx::Ref<orbis::File> *file, const char *path,
return {};
}
IoDevice *createHidCharacterDevice() { return orbis::knew<HidDevice>(); }
orbis::IoDevice *createHidCharacterDevice() { return orbis::knew<HidDevice>(); }

View file

@ -1,8 +1,9 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
struct Hmd2CmdDevice : public IoDevice {
struct Hmd2CmdDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -30,6 +31,6 @@ orbis::ErrorCode Hmd2CmdDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createHmd2CmdCharacterDevice() {
orbis::IoDevice *createHmd2CmdCharacterDevice() {
return orbis::knew<Hmd2CmdDevice>();
}

View file

@ -1,8 +1,9 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
struct Hmd2GazeDevice : public IoDevice {
struct Hmd2GazeDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -31,6 +32,6 @@ orbis::ErrorCode Hmd2GazeDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createHmd2GazeCharacterDevice() {
orbis::IoDevice *createHmd2GazeCharacterDevice() {
return orbis::knew<Hmd2GazeDevice>();
}

View file

@ -1,8 +1,9 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
struct Hmd2GenDataDevice : public IoDevice {
struct Hmd2GenDataDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -31,6 +32,6 @@ orbis::ErrorCode Hmd2GenDataDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createHmd2GenDataCharacterDevice() {
orbis::IoDevice *createHmd2GenDataCharacterDevice() {
return orbis::knew<Hmd2GenDataDevice>();
}

View file

@ -1,8 +1,9 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
struct Hmd2ImuDevice : public IoDevice {
struct Hmd2ImuDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -30,6 +31,6 @@ orbis::ErrorCode Hmd2ImuDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createHmd2ImuCharacterDevice() {
orbis::IoDevice *createHmd2ImuCharacterDevice() {
return orbis::knew<Hmd2ImuDevice>();
}

View file

@ -1,9 +1,9 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
struct Hmd3daDevice : public IoDevice {
struct Hmd3daDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -32,4 +32,6 @@ orbis::ErrorCode Hmd3daDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createHmd3daCharacterDevice() { return orbis::knew<Hmd3daDevice>(); }
orbis::IoDevice *createHmd3daCharacterDevice() {
return orbis::knew<Hmd3daDevice>();
}

View file

@ -1,8 +1,9 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
struct HmdCmdDevice : public IoDevice {
struct HmdCmdDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -31,4 +32,6 @@ orbis::ErrorCode HmdCmdDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createHmdCmdCharacterDevice() { return orbis::knew<HmdCmdDevice>(); }
orbis::IoDevice *createHmdCmdCharacterDevice() {
return orbis::knew<HmdCmdDevice>();
}

View file

@ -1,9 +1,10 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
#include "vm.hpp"
struct HmdMmapDevice : public IoDevice {
struct HmdMmapDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -49,6 +50,6 @@ orbis::ErrorCode HmdMmapDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createHmdMmapCharacterDevice() {
orbis::IoDevice *createHmdMmapCharacterDevice() {
return orbis::knew<HmdMmapDevice>();
}

View file

@ -1,9 +1,9 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
struct HmdSnsrDevice : public IoDevice {
struct HmdSnsrDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -33,6 +33,6 @@ orbis::ErrorCode HmdSnsrDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createHmdSnsrCharacterDevice() {
orbis::IoDevice *createHmdSnsrCharacterDevice() {
return orbis::knew<HmdSnsrDevice>();
}

View file

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
@ -18,7 +18,7 @@ static const orbis::FileOps fileOps = {
.ioctl = icc_configuration_ioctl,
};
struct IccConfigurationDevice : IoDevice {
struct IccConfigurationDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -31,6 +31,6 @@ struct IccConfigurationDevice : IoDevice {
}
};
IoDevice *createIccConfigurationCharacterDevice() {
orbis::IoDevice *createIccConfigurationCharacterDevice() {
return orbis::knew<IccConfigurationDevice>();
}

View file

@ -1,10 +1,10 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
#include "orbis/utils/Logs.hpp"
struct IccPowerDevice : IoDevice {
struct IccPowerDevice : orbis::IoDevice {
std::uint8_t bootphase = 0;
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
@ -69,6 +69,6 @@ orbis::ErrorCode IccPowerDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createIccPowerCharacterDevice() {
orbis::IoDevice *createIccPowerCharacterDevice() {
return orbis::knew<IccPowerDevice>();
}

View file

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
@ -17,7 +17,7 @@ static const orbis::FileOps fileOps = {
.ioctl = lvdctl_ioctl,
};
struct LvdCtlDevice : IoDevice {
struct LvdCtlDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -30,4 +30,6 @@ struct LvdCtlDevice : IoDevice {
}
};
IoDevice *createLvdCtlCharacterDevice() { return orbis::knew<LvdCtlDevice>(); }
orbis::IoDevice *createLvdCtlCharacterDevice() {
return orbis::knew<LvdCtlDevice>();
}

View file

@ -1,5 +1,4 @@
#include "mbus.hpp"
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/uio.hpp"
@ -65,4 +64,6 @@ orbis::ErrorCode MBusDevice::open(rx::Ref<orbis::File> *file, const char *path,
return {};
}
IoDevice *createMBusCharacterDevice() { return orbis::knew<MBusDevice>(); }
orbis::IoDevice *createMBusCharacterDevice() {
return orbis::knew<MBusDevice>();
}

View file

@ -1,11 +1,13 @@
#pragma once
#include "io-device.hpp"
#include "iodev/MBusEvent.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/note.hpp"
#include "rx/SharedCV.hpp"
#include "rx/SharedMutex.hpp"
struct MBusDevice : IoDevice {
struct MBusDevice : orbis::IoDevice {
rx::shared_mutex mtx;
rx::shared_cv cv;
orbis::kdeque<MBusEvent> events;

View file

@ -1,5 +1,4 @@
#include "mbus_av.hpp"
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/note.hpp"
@ -65,4 +64,6 @@ void MBusAVDevice::emitEvent(const MBusEvent &event) {
eventEmitter->emit(orbis::kEvFiltRead);
}
IoDevice *createMBusAVCharacterDevice() { return orbis::knew<MBusAVDevice>(); }
orbis::IoDevice *createMBusAVCharacterDevice() {
return orbis::knew<MBusAVDevice>();
}

View file

@ -1,11 +1,13 @@
#pragma once
#include "io-device.hpp"
#include "iodev/MBusEvent.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/note.hpp"
#include "rx/SharedCV.hpp"
#include "rx/SharedMutex.hpp"
struct MBusAVDevice : IoDevice {
struct MBusAVDevice : orbis::IoDevice {
rx::shared_mutex mtx;
rx::shared_cv cv;
orbis::kdeque<MBusEvent> events;

View file

@ -1,8 +1,7 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
#include <chrono>
#include <thread>
struct MetaDbgFile : orbis::File {};
@ -26,7 +25,7 @@ static const orbis::FileOps fileOps = {
.read = metadbg_read,
};
struct MetaDbgDevice : IoDevice {
struct MetaDbgDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -39,6 +38,6 @@ struct MetaDbgDevice : IoDevice {
}
};
IoDevice *createMetaDbgCharacterDevice() {
orbis::IoDevice *createMetaDbgCharacterDevice() {
return orbis::knew<MetaDbgDevice>();
}

View file

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
@ -12,7 +12,7 @@
#include <thread>
struct NotificationFile : orbis::File {};
struct NotificationDevice : IoDevice {
struct NotificationDevice : orbis::IoDevice {
int index;
rx::shared_mutex mutex;
orbis::kvector<std::byte> data;
@ -104,6 +104,6 @@ orbis::ErrorCode NotificationDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createNotificationCharacterDevice(int index) {
orbis::IoDevice *createNotificationCharacterDevice(int index) {
return orbis::knew<NotificationDevice>(index);
}

View file

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
@ -16,7 +16,7 @@ static const orbis::FileOps fileOps = {
.ioctl = npdrm_ioctl,
};
struct NpdrmDevice : IoDevice {
struct NpdrmDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -29,4 +29,6 @@ struct NpdrmDevice : IoDevice {
}
};
IoDevice *createNpdrmCharacterDevice() { return orbis::knew<NpdrmDevice>(); }
orbis::IoDevice *createNpdrmCharacterDevice() {
return orbis::knew<NpdrmDevice>();
}

View file

@ -1,10 +1,9 @@
#include "../io-devices.hpp"
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
#include "vfs.hpp"
#include <chrono>
#include <thread>
struct NsidCtlFile : orbis::File {};
@ -34,7 +33,7 @@ static const orbis::FileOps fileOps = {
.read = nsid_ctl_read,
};
struct NsidCtlDevice : IoDevice {
struct NsidCtlDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -47,6 +46,6 @@ struct NsidCtlDevice : IoDevice {
}
};
IoDevice *createNsidCtlCharacterDevice() {
orbis::IoDevice *createNsidCtlCharacterDevice() {
return orbis::knew<NsidCtlDevice>();
}

View file

@ -1,9 +1,10 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/uio.hpp"
#include <span>
struct NullDevice : public IoDevice {
struct NullDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -32,4 +33,6 @@ orbis::ErrorCode NullDevice::open(rx::Ref<orbis::File> *file, const char *path,
return {};
}
IoDevice *createNullCharacterDevice() { return orbis::knew<NullDevice>(); }
orbis::IoDevice *createNullCharacterDevice() {
return orbis::knew<NullDevice>();
}

View file

@ -1,9 +1,10 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
#include "vm.hpp"
struct RngDevice : public IoDevice {
struct RngDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -48,4 +49,4 @@ orbis::ErrorCode RngDevice::open(rx::Ref<orbis::File> *file, const char *path,
return {};
}
IoDevice *createRngCharacterDevice() { return orbis::knew<RngDevice>(); }
orbis::IoDevice *createRngCharacterDevice() { return orbis::knew<RngDevice>(); }

View file

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
@ -16,7 +16,7 @@ static const orbis::FileOps fileOps = {
.ioctl = s3da_ioctl,
};
struct S3DADevice : IoDevice {
struct S3DADevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -29,4 +29,6 @@ struct S3DADevice : IoDevice {
}
};
IoDevice *createS3DACharacterDevice() { return orbis::knew<S3DADevice>(); }
orbis::IoDevice *createS3DACharacterDevice() {
return orbis::knew<S3DADevice>();
}

View file

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/error/ErrorCode.hpp"
#include "orbis/file.hpp"
@ -9,7 +9,7 @@
struct SblSrvFile : public orbis::File {};
struct SblSrvDevice : IoDevice {
struct SblSrvDevice : orbis::IoDevice {
rx::shared_mutex mtx;
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
@ -53,4 +53,6 @@ orbis::ErrorCode SblSrvDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createSblSrvCharacterDevice() { return orbis::knew<SblSrvDevice>(); }
orbis::IoDevice *createSblSrvCharacterDevice() {
return orbis::knew<SblSrvDevice>();
}

View file

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
@ -18,7 +18,7 @@ static const orbis::FileOps fileOps = {
.ioctl = scanin_ioctl,
};
struct ScaninDevice : IoDevice {
struct ScaninDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -31,4 +31,6 @@ struct ScaninDevice : IoDevice {
}
};
IoDevice *createScaninCharacterDevice() { return orbis::knew<ScaninDevice>(); }
orbis::IoDevice *createScaninCharacterDevice() {
return orbis::knew<ScaninDevice>();
}

View file

@ -1,4 +1,5 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/error/ErrorCode.hpp"
#include "orbis/file.hpp"
@ -9,7 +10,7 @@
#include <filesystem>
#include <sys/mman.h>
struct ShmDevice : IoDevice {
struct ShmDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -56,4 +57,4 @@ orbis::ErrorCode ShmDevice::unlink(const char *path, bool recursive,
return convertErrorCode(ec);
}
IoDevice *createShmDevice() { return orbis::knew<ShmDevice>(); }
orbis::IoDevice *createShmDevice() { return orbis::knew<ShmDevice>(); }

View file

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
@ -17,7 +17,7 @@ static const orbis::FileOps fileOps = {
.ioctl = srtc_ioctl,
};
struct SrtcDevice : IoDevice {
struct SrtcDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -30,4 +30,6 @@ struct SrtcDevice : IoDevice {
}
};
IoDevice *createSrtcCharacterDevice() { return orbis::knew<SrtcDevice>(); }
orbis::IoDevice *createSrtcCharacterDevice() {
return orbis::knew<SrtcDevice>();
}

View file

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
@ -18,7 +18,7 @@ static const orbis::FileOps fileOps = {
.ioctl = sshot_ioctl,
};
struct ScreenShotDevice : IoDevice {
struct ScreenShotDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -31,6 +31,6 @@ struct ScreenShotDevice : IoDevice {
}
};
IoDevice *createScreenShotCharacterDevice() {
orbis::IoDevice *createScreenShotCharacterDevice() {
return orbis::knew<ScreenShotDevice>();
}

View file

@ -1,10 +1,11 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/uio.hpp"
#include <cstring>
#include <span>
struct UrandomDevice : public IoDevice {
struct UrandomDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -36,6 +37,6 @@ orbis::ErrorCode UrandomDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createUrandomCharacterDevice() {
orbis::IoDevice *createUrandomCharacterDevice() {
return orbis::knew<UrandomDevice>();
}

View file

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
@ -16,7 +16,7 @@ static const orbis::FileOps fileOps = {
.ioctl = uvd_ioctl,
};
struct UVDDevice : IoDevice {
struct UVDDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -29,4 +29,4 @@ struct UVDDevice : IoDevice {
}
};
IoDevice *createUVDCharacterDevice() { return orbis::knew<UVDDevice>(); }
orbis::IoDevice *createUVDCharacterDevice() { return orbis::knew<UVDDevice>(); }

View file

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
@ -29,7 +29,7 @@ static const orbis::FileOps fileOps = {
.ioctl = vce_ioctl,
};
struct VCEDevice : IoDevice {
struct VCEDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -42,4 +42,4 @@ struct VCEDevice : IoDevice {
}
};
IoDevice *createVCECharacterDevice() { return orbis::knew<VCEDevice>(); }
orbis::IoDevice *createVCECharacterDevice() { return orbis::knew<VCEDevice>(); }

View file

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
@ -22,7 +22,7 @@ static const orbis::FileOps fileOps = {
.ioctl = xpt_ioctl,
};
struct XptDevice : IoDevice {
struct XptDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -35,4 +35,4 @@ struct XptDevice : IoDevice {
}
};
IoDevice *createXptCharacterDevice() { return orbis::knew<XptDevice>(); }
orbis::IoDevice *createXptCharacterDevice() { return orbis::knew<XptDevice>(); }

View file

@ -1,10 +1,11 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/uio.hpp"
#include <cstring>
#include <span>
struct ZeroDevice : public IoDevice {
struct ZeroDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -35,4 +36,6 @@ orbis::ErrorCode ZeroDevice::open(rx::Ref<orbis::File> *file, const char *path,
return {};
}
IoDevice *createZeroCharacterDevice() { return orbis::knew<ZeroDevice>(); }
orbis::IoDevice *createZeroCharacterDevice() {
return orbis::knew<ZeroDevice>();
}

View file

@ -4,6 +4,7 @@
#include "io-device.hpp"
#include "orbis/KernelContext.hpp"
#include "orbis/osem.hpp"
#include "orbis/thread/Process.hpp"
#include "orbis/utils/Logs.hpp"
#include "rx/format.hpp"
#include "rx/hexdump.hpp"
@ -179,7 +180,7 @@ orbis::EventFlag *ipmi::createEventFlag(std::string_view name, uint32_t attrs,
void ipmi::createShm(const char *name, uint32_t flags, uint32_t mode,
uint64_t size) {
rx::Ref<orbis::File> shm;
auto shmDevice = orbis::g_context->shmDevice.staticCast<IoDevice>();
auto shmDevice = orbis::g_context->shmDevice.staticCast<orbis::IoDevice>();
shmDevice->open(&shm, name, flags, mode, nullptr);
shm->ops->truncate(shm.get(), size, nullptr);
}
@ -357,7 +358,7 @@ ipmi::IpmiServer &ipmi::createIpmiServer(orbis::Process *process,
if ((packet.info.type & ~0x8010) == 0x41) {
auto msgHeader = std::bit_cast<orbis::IpmiSyncMessageHeader *>(
packet.message.data());
auto process = orbis::g_context->findProcessById(msgHeader->pid);
auto process = orbis::findProcessById(msgHeader->pid);
if (process == nullptr) {
continue;
}
@ -378,7 +379,7 @@ ipmi::IpmiServer &ipmi::createIpmiServer(orbis::Process *process,
if ((packet.info.type & ~0x10) == 0x43) {
auto msgHeader = (orbis::IpmiAsyncMessageHeader *)packet.message.data();
auto process = orbis::g_context->findProcessById(msgHeader->pid);
auto process = orbis::findProcessById(msgHeader->pid);
if (process == nullptr) {
continue;
}

View file

@ -974,7 +974,8 @@ rx::Ref<orbis::Module> rx::linker::loadModule(std::span<std::byte> image,
static rx::Ref<orbis::Module> loadModuleFileImpl(std::string_view path,
orbis::Thread *thread) {
rx::Ref<orbis::File> instance;
if (vfs::open(path, kOpenFlagReadOnly, 0, &instance, thread).isError()) {
if (vfs::open(path, orbis::kOpenFlagReadOnly, 0, &instance, thread)
.isError()) {
return {};
}

View file

@ -534,20 +534,6 @@ static void guestInitFd(orbis::Thread *mainThread) {
mainThread->tproc->fileDescriptors.insert(stderrFile);
}
static orbis::Process *createGuestProcess() {
auto pid = orbis::g_context->allocatePid() * 10000 + 1;
return orbis::g_context->createProcess(pid);
}
static orbis::Thread *createGuestThread() {
auto process = createGuestProcess();
auto [baseId, thread] = process->threadsMap.emplace();
thread->tproc = process;
thread->tid = process->pid + baseId;
thread->state = orbis::ThreadState::RUNNING;
return thread;
}
struct ExecEnv {
std::uint64_t entryPoint;
std::uint64_t interpBase;
@ -789,7 +775,7 @@ static orbis::SysResult launchDaemon(orbis::Thread *thread, std::string path,
std::vector<std::string> argv,
std::vector<std::string> envv,
orbis::AppInfoEx appInfo) {
auto childPid = orbis::g_context->allocatePid() * 10000 + 1;
auto childPid = orbis::allocatePid();
auto flag = orbis::knew<std::atomic<bool>>();
*flag = false;
@ -805,7 +791,7 @@ static orbis::SysResult launchDaemon(orbis::Thread *thread, std::string path,
return {};
}
auto process = orbis::g_context->createProcess(childPid);
auto process = orbis::createProcess(thread->tproc, childPid);
auto logFd = ::open(("log-" + std::to_string(childPid) + ".txt").c_str(),
O_CREAT | O_TRUNC | O_WRONLY, 0666);
@ -817,7 +803,6 @@ static orbis::SysResult launchDaemon(orbis::Thread *thread, std::string path,
process->onSysEnter = thread->tproc->onSysEnter;
process->onSysExit = thread->tproc->onSysExit;
process->ops = thread->tproc->ops;
process->parentProcess = thread->tproc;
process->appInfo = appInfo;
process->authInfo = {
@ -845,10 +830,9 @@ static orbis::SysResult launchDaemon(orbis::Thread *thread, std::string path,
*flag = true;
auto [baseId, newThread] = process->threadsMap.emplace();
newThread->tproc = process;
newThread->tid = process->pid + baseId;
newThread->state = orbis::ThreadState::RUNNING;
auto newThread = orbis::createThread(process, path);
newThread->hostTid = ::gettid();
newThread->nativeHandle = pthread_self();
newThread->context = thread->context;
newThread->fsBase = thread->fsBase;
@ -869,7 +853,7 @@ static orbis::SysResult launchDaemon(orbis::Thread *thread, std::string path,
{
rx::Ref<orbis::File> file;
auto result = vfs::open(path, kOpenFlagReadOnly, 0, &file, thread);
auto result = vfs::open(path, orbis::kOpenFlagReadOnly, 0, &file, thread);
if (result.isError()) {
return result;
}
@ -1060,8 +1044,8 @@ int main(int argc, const char *argv[]) {
rx::thread::initialize();
// vm::printHostStats();
orbis::g_context->allocatePid();
auto initProcess = orbis::g_context->createProcess(asRoot ? 1 : 10);
orbis::allocatePid();
auto initProcess = orbis::createProcess(nullptr, asRoot ? 1 : 10);
// pthread_setname_np(pthread_self(), "10.MAINTHREAD");
int status = 0;
@ -1216,10 +1200,9 @@ int main(int argc, const char *argv[]) {
initProcess->isInSandbox = true;
}
auto [baseId, mainThread] = initProcess->threadsMap.emplace();
mainThread->tproc = initProcess;
mainThread->tid = initProcess->pid + baseId;
mainThread->state = orbis::ThreadState::RUNNING;
auto mainThread = orbis::createThread(initProcess, "");
mainThread->hostTid = ::gettid();
mainThread->nativeHandle = pthread_self();
orbis::g_currentThread = mainThread;
if (!isSystem && !vfs::exists(guestArgv[0], mainThread) &&
@ -1345,7 +1328,8 @@ int main(int argc, const char *argv[]) {
// version
if (orbis::g_context->fwType != orbis::FwType::Ps5 &&
orbis::g_context->fwSdkVersion >= 0x5050000) {
auto fakeIpmiThread = createGuestThread();
auto fakeIpmiThread =
orbis::createThread(initProcess, "SceSysAudioSystemIpc");
ipmi::audioIpmiClient =
ipmi::createIpmiClient(fakeIpmiThread, "SceSysAudioSystemIpc");
// HACK: here is a bug in audiod because we send this very early and

View file

@ -303,7 +303,7 @@ orbis::SysResult open(orbis::Thread *thread, orbis::ptr<const char> path,
orbis::SysResult shm_open(orbis::Thread *thread, const char *path,
orbis::sint flags, orbis::sint mode,
rx::Ref<orbis::File> *file) {
auto dev = static_cast<IoDevice *>(orbis::g_context->shmDevice.get());
auto dev = orbis::g_context->shmDevice;
return dev->open(file, path, flags, mode, thread);
}
orbis::SysResult unlink(orbis::Thread *thread, orbis::ptr<const char> path) {
@ -537,13 +537,14 @@ SysResult thr_new(orbis::Thread *thread, orbis::ptr<thr_param> param,
return result;
}
auto proc = thread->tproc;
std::lock_guard lock(proc->mtx);
auto [baseId, childThread] = proc->threadsMap.emplace();
std::lock_guard lockThr(childThread->mtx);
childThread->tproc = proc;
childThread->tid = proc->pid + baseId;
childThread->state = orbis::ThreadState::RUNQ;
char _name[32]{};
if (_param.name != 0) {
ORBIS_RET_ON_ERROR(ureadString(_name, sizeof(_name), _param.name));
}
auto childThread = orbis::createThread(thread->tproc, _name);
std::lock_guard lock(childThread->mtx);
childThread->stackStart = _param.stack_base;
childThread->stackEnd = _param.stack_base + _param.stack_size;
childThread->fsBase = reinterpret_cast<std::uintptr_t>(_param.tls_base);
@ -560,11 +561,6 @@ SysResult thr_new(orbis::Thread *thread, orbis::ptr<thr_param> param,
childThread->stackStart, _param.rtp, _param.name,
_param.spare[0], _param.spare[1]);
if (_param.name != 0) {
ORBIS_RET_ON_ERROR(
ureadString(childThread->name, sizeof(childThread->name), _param.name));
}
if (_param.rtp != 0) {
rtprio _rtp;
ORBIS_RET_ON_ERROR(uread(_rtp, _param.rtp));
@ -760,7 +756,7 @@ SysResult processNeeded(Thread *thread) {
}
SysResult fork(Thread *thread, slong flags) {
auto childPid = g_context->allocatePid() * 10000 + 1;
auto childPid = orbis::allocatePid();
ORBIS_LOG_TODO(__FUNCTION__, flags, childPid, thread->tid);
thread->where();
auto flag = knew<std::atomic<bool>>();
@ -783,13 +779,12 @@ SysResult fork(Thread *thread, slong flags) {
return {};
}
auto process = g_context->createProcess(childPid);
auto process = orbis::createProcess(thread->tproc, childPid);
process->hostPid = ::getpid();
process->sysent = thread->tproc->sysent;
process->onSysEnter = thread->tproc->onSysEnter;
process->onSysExit = thread->tproc->onSysExit;
process->ops = thread->tproc->ops;
process->parentProcess = thread->tproc;
process->authInfo = thread->tproc->authInfo;
process->sdkVersion = thread->tproc->sdkVersion;
process->type = thread->tproc->type;
@ -813,11 +808,8 @@ SysResult fork(Thread *thread, slong flags) {
*flag = true;
auto [baseId, newThread] = process->threadsMap.emplace();
newThread->tproc = process;
auto newThread = orbis::createThread(process, thread->name);
newThread->hostTid = ::gettid();
newThread->tid = process->pid + baseId;
newThread->state = orbis::ThreadState::RUNNING;
newThread->context = thread->context;
newThread->fsBase = thread->fsBase;

View file

@ -18,7 +18,7 @@ static orbis::FileOps devfs_ops = {
.stat = devfs_stat,
};
struct DevFs : IoDevice {
struct DevFs : orbis::IoDevice {
std::map<std::string, rx::Ref<IoDevice>, std::less<>> devices;
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
@ -50,7 +50,7 @@ struct DevFs : IoDevice {
}
};
struct ProcFs : IoDevice {
struct ProcFs : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -60,7 +60,8 @@ struct ProcFs : IoDevice {
};
static rx::shared_mutex gMountMtx;
static std::map<std::string, rx::Ref<IoDevice>, std::greater<>> gMountsMap;
static std::map<std::string, rx::Ref<orbis::IoDevice>, std::greater<>>
gMountsMap;
static rx::Ref<DevFs> gDevFs;
void vfs::fork() {
@ -93,16 +94,16 @@ void vfs::deinitialize() {
gMountsMap.clear();
}
void vfs::addDevice(std::string name, IoDevice *device) {
void vfs::addDevice(std::string name, orbis::IoDevice *device) {
std::lock_guard lock(gMountMtx);
gDevFs->devices[std::move(name)] = device;
}
std::pair<rx::Ref<IoDevice>, std::string>
std::pair<rx::Ref<orbis::IoDevice>, std::string>
vfs::get(const std::filesystem::path &guestPath) {
std::string normalPath = std::filesystem::path(guestPath).lexically_normal();
std::string_view path = normalPath;
rx::Ref<IoDevice> device;
rx::Ref<orbis::IoDevice> device;
std::lock_guard lock(gMountMtx);
@ -141,7 +142,7 @@ vfs::get(const std::filesystem::path &guestPath) {
}
orbis::SysResult vfs::mount(const std::filesystem::path &guestPath,
IoDevice *dev) {
orbis::IoDevice *dev) {
auto mp = guestPath.lexically_normal().string();
if (!mp.ends_with("/")) {
mp += "/";

View file

@ -5,16 +5,19 @@
#include "rx/Rc.hpp"
#include <filesystem>
namespace orbis {
struct IoDevice;
}
namespace vfs {
void fork();
void initialize();
void deinitialize();
void addDevice(std::string name, IoDevice *device);
std::pair<rx::Ref<IoDevice>, std::string>
void addDevice(std::string name, orbis::IoDevice *device);
std::pair<rx::Ref<orbis::IoDevice>, std::string>
get(const std::filesystem::path &guestPath);
orbis::SysResult mount(const std::filesystem::path &guestPath, IoDevice *dev);
orbis::SysResult mount(const std::filesystem::path &guestPath,
orbis::IoDevice *dev);
orbis::SysResult open(std::string_view path, int flags, int mode,
rx::Ref<orbis::File> *file, orbis::Thread *thread);
bool exists(std::string_view path, orbis::Thread *thread);

View file

@ -649,7 +649,7 @@ struct Block {
static Block gBlocks[kBlockCount];
struct MapInfo {
rx::Ref<IoDevice> device;
rx::Ref<orbis::IoDevice> device;
std::uint64_t offset;
std::uint32_t flags;
char name[32];
@ -776,7 +776,7 @@ constexpr auto kMainDirectMemorySize =
kPhysicalMemorySize - kFlexibleMemorySize;
void *vm::map(void *addr, std::uint64_t len, std::int32_t prot,
std::int32_t flags, std::int32_t internalFlags, IoDevice *device,
std::int32_t flags, std::int32_t internalFlags, orbis::IoDevice *device,
std::uint64_t offset) {
std::println(stderr, "vm::map(addr = {}, len = {}, prot = {}, flags = {})",
addr, len, mapProtToString(prot), mapFlagsToString(flags));

View file

@ -1,6 +1,5 @@
#pragma once
#include "io-device.hpp"
#include <cstddef>
#include "orbis/IoDevice.hpp"
#include <cstdint>
#include <string>
@ -72,7 +71,7 @@ void reset();
void initialize(std::uint64_t pid);
void deinitialize();
void *map(void *addr, std::uint64_t len, std::int32_t prot, std::int32_t flags,
std::int32_t internalFlags = 0, IoDevice *device = nullptr,
std::int32_t internalFlags = 0, orbis::IoDevice *device = nullptr,
std::uint64_t offset = 0);
bool unmap(void *addr, std::uint64_t size);
bool protect(void *addr, std::uint64_t size, std::int32_t prot);

View file

@ -3,6 +3,7 @@
#include "BitSet.hpp"
#include "Rc.hpp"
#include "SharedMutex.hpp"
#include "FunctionRef.hpp"
#include <algorithm>
#include <bit>
@ -324,10 +325,24 @@ struct OwningIdMap {
std::construct_at(get(index), std::forward<ArgsT>(args)...)};
}
template <typename... ArgsT>
T *emplace_new_at(std::size_t index, ArgsT &&...args) {
if (mask.test(index)) {
return {};
}
mask.set(index);
return std::construct_at(get(index), std::forward<ArgsT>(args)...);
}
T *get(std::size_t index) {
return reinterpret_cast<T *>(objects + sizeof(T) * index);
}
const T *get(std::size_t index) const {
return reinterpret_cast<const T *>(objects + sizeof(T) * index);
}
void destroy(std::size_t index) {
std::destroy_at(get(index));
mask.clear(index);
@ -337,6 +352,25 @@ struct OwningIdMap {
IdMapChunk chunks[ChunkCount]{};
BitSet<ChunkCount> fullChunks;
template <typename... ArgsT>
requires(std::is_constructible_v<T, ArgsT...>)
T *emplace_at(IdT id, ArgsT &&...args) {
auto page = static_cast<std::uint64_t>(id) / ChunkSize;
if (page >= ChunkCount) {
return {};
}
auto newElem =
chunks[page].emplace_new_at(static_cast<std::uint64_t>(id) % ChunkSize,
std::forward<ArgsT>(args)...);
if (chunks[page].mask.full()) {
fullChunks.set(page);
}
return newElem;
}
template <typename... ArgsT>
requires(std::is_constructible_v<T, ArgsT...>)
std::pair<IdT, T *> emplace(ArgsT &&...args) {
@ -390,13 +424,13 @@ struct OwningIdMap {
return true;
}
void walk(auto cb) {
void walk(FunctionRef<void(IdT, const T &)> cb) const {
for (std::size_t chunk = 0; chunk < ChunkCount; ++chunk) {
std::size_t index = chunks[chunk].mask.countr_zero();
while (index < ChunkSize) {
auto id = static_cast<IdT>(index + chunk * ChunkSize + MinId);
cb(id, chunks[chunk].get(id));
cb(id, *chunks[chunk].get(id));
index = chunks[chunk].mask.countr_zero(index + 1);
}

View file

@ -68,6 +68,7 @@ void callDeserializeFunction(Deserializer &s, T &value)
}
template <typename T>
requires(!std::is_array_v<T>)
T callDeserializeFunction(Deserializer &s)
requires requires(T &value) { deserialize<T>(s); }
{
@ -257,7 +258,19 @@ private:
bool mFailure = false;
};
template <detail::TriviallyRelocatable T> struct TypeSerializer<T> {
template <detail::TriviallyRelocatable T>
requires std::is_array_v<T>
struct TypeSerializer<T> {
static void serialize(Serializer &s, const T &t) {
std::byte rawBytes[sizeof(T)];
std::memcpy(rawBytes, &t, sizeof(T));
s.write(rawBytes);
}
};
template <detail::TriviallyRelocatable T>
requires(!std::is_array_v<T>)
struct TypeSerializer<T> {
static void serialize(Serializer &s, const T &t) {
std::byte rawBytes[sizeof(T)];
std::memcpy(rawBytes, &t, sizeof(T));