Initial kernel allocator

This commit is contained in:
Ivan Chikish 2023-07-04 19:19:17 +03:00
parent 0f76e72de1
commit d7a34f0904
25 changed files with 247 additions and 144 deletions

View File

@ -3,6 +3,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE on)
add_library(obj.orbis-kernel OBJECT
src/module.cpp
src/sysvec.cpp
src/KernelContext.cpp
src/sys/sys_acct.cpp
src/sys/sys_audit.cpp
src/sys/sys_capability.cpp

View File

@ -0,0 +1,57 @@
#pragma once
#include "utils/Rc.hpp"
#include <utility>
#include <vector>
#include <deque>
#include <map>
#include <unordered_map>
namespace orbis {
inline namespace utils {
void *kalloc(std::size_t size, std::size_t align);
void kfree(void* ptr, std::size_t size);
template <typename T> struct kallocator {
using value_type = T;
template <typename U> struct rebind { using other = kallocator<U>; };
T *allocate(std::size_t n) {
return static_cast<T *>(kalloc(sizeof(T) * n, alignof(T)));
}
void deallocate(T *p, std::size_t n) {
kfree(p, sizeof(T) * n);
}
template <typename U>
friend constexpr bool operator==(const kallocator &,
const kallocator<U> &) noexcept {
return true;
}
};
template <typename T> using kvector = std::vector<T, kallocator<T>>;
template <typename T> using kdeque = std::deque<T, kallocator<T>>;
template <typename K, typename T, typename Cmp = std::less<>>
using kmap = std::map<K, T, Cmp, kallocator<std::pair<const K, T>>>;
template <typename K, typename T, typename Hash = std::hash<K>,
typename Pred = std::equal_to<K>>
using kunmap =
std::unordered_map<K, T, Hash, Pred, kallocator<std::pair<const K, T>>>;
} // namespace utils
template <typename T, typename... Args> T *knew(Args &&...args) {
auto loc = static_cast<T *>(utils::kalloc(sizeof(T), alignof(T)));
auto res = std::construct_at(loc, std::forward<Args>(args)...);
if constexpr (WithRc<T>)
res->_total_size = sizeof(T);
return res;
}
template <typename T> void kdelete(T *ptr) {
ptr->~T();
utils::kfree(ptr, sizeof(T));
}
} // namespace orbis

View File

@ -1,97 +1,41 @@
#pragma once
#include "orbis/thread/Process.hpp"
#include "utils/LinkedNode.hpp"
#include "utils/SharedMutex.hpp"
#include "orbis/thread/types.hpp"
#include "KernelAllocator.hpp"
#include <algorithm>
#include <mutex>
#include <utility>
#include <vector>
namespace orbis {
class KernelContext {
struct Process;
class alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__) KernelContext final {
public:
struct EventListener {
virtual ~EventListener() = default;
virtual void onProcessCreated(Process *) = 0;
virtual void onProcessDeleted(pid_t pid) = 0;
};
KernelContext();
~KernelContext();
~KernelContext() {
while (m_processes != nullptr) {
deleteProcess(&m_processes->object);
}
}
Process *createProcess(pid_t pid);
void deleteProcess(Process *proc);
Process *findProcessById(pid_t pid) const;
void addEventListener(EventListener *listener) {
m_event_listeners.push_back(listener);
}
void removeEventListener(EventListener *listener) {
auto it =
std::find(m_event_listeners.begin(), m_event_listeners.end(), listener);
if (it != m_event_listeners.end()) {
m_event_listeners.erase(it);
}
}
Process *createProcess(pid_t pid) {
auto newProcess = new utils::LinkedNode<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;
}
for (auto listener : m_event_listeners) {
listener->onProcessCreated(&newProcess->object);
}
return &newProcess->object;
}
void deleteProcess(Process *proc) {
auto procNode = reinterpret_cast<utils::LinkedNode<Process> *>(proc);
auto pid = proc->pid;
{
std::lock_guard lock(m_proc_mtx);
auto next = procNode->erase();
if (procNode == m_processes) {
m_processes = next;
}
}
delete procNode;
for (auto listener : m_event_listeners) {
listener->onProcessDeleted(pid);
}
}
Process *findProcessById(pid_t pid) const {
std::lock_guard lock(m_proc_mtx);
for (auto proc = m_processes; proc != nullptr; proc = proc->next) {
if (proc->object.pid == pid) {
return &proc->object;
}
}
return nullptr;
}
static void *kalloc(std::size_t size,
std::size_t align = __STDCPP_DEFAULT_NEW_ALIGNMENT__);
static void kfree(void *ptr, std::size_t size);
private:
mutable shared_mutex m_proc_mtx;
utils::LinkedNode<Process> *m_processes = nullptr;
std::vector<EventListener *> m_event_listeners;
struct node {
std::size_t size;
node *next;
};
mutable shared_mutex m_heap_mtx;
void *m_heap_next = this + 1;
node *m_free_list = nullptr;
};
} // namespace orbis
extern KernelContext &g_context;
} // namespace orbis

View File

@ -4,6 +4,7 @@
#include "ModuleSegment.hpp"
#include "../utils/Rc.hpp"
#include "../KernelAllocator.hpp"
#include "orbis-config.hpp"
#include <cstddef>
@ -65,7 +66,7 @@ struct Relocation {
std::int64_t addend;
};
struct Module {
struct Module final {
Process *proc{};
std::string vfsPath;
char moduleName[256]{};
@ -108,16 +109,17 @@ struct Module {
bool isTlsDone = false;
std::vector<Symbol> symbols;
std::vector<Relocation> pltRelocations;
std::vector<Relocation> nonPltRelocations;
std::vector<ModuleNeeded> neededModules;
std::vector<ModuleNeeded> neededLibraries;
std::vector<utils::Ref<Module>> importedModules;
std::vector<utils::Ref<Module>> namespaceModules;
std::vector<std::string> needed;
utils::kvector<Symbol> symbols;
utils::kvector<Relocation> pltRelocations;
utils::kvector<Relocation> nonPltRelocations;
utils::kvector<ModuleNeeded> neededModules;
utils::kvector<ModuleNeeded> neededLibraries;
utils::kvector<utils::Ref<Module>> importedModules;
utils::kvector<utils::Ref<Module>> namespaceModules;
utils::kvector<std::string> needed;
std::atomic<unsigned> references{0};
unsigned _total_size = 0;
void incRef() {
if (references.fetch_add(1, std::memory_order::relaxed) > 512) {

View File

@ -6,9 +6,13 @@
#include <utility>
namespace orbis {
template <typename T, typename... Args> T *knew(Args &&...args);
inline namespace utils {
void kfree(void* ptr, std::size_t size);
struct RcBase {
std::atomic<unsigned> references{0};
unsigned _total_size = 0; // Set by knew/kcreate
virtual ~RcBase() = default;
@ -21,7 +25,9 @@ struct RcBase {
// returns true if object was destroyed
bool decRef() {
if (references.fetch_sub(1, std::memory_order::relaxed) == 1) {
delete this;
auto size = _total_size;
this->~RcBase();
orbis::utils::kfree(this, size);
return true;
}
@ -116,9 +122,8 @@ public:
template <WithRc T, typename... ArgsT>
requires(std::is_constructible_v<T, ArgsT...>)
Ref<T> create(ArgsT &&...args) {
auto result = new T(std::forward<ArgsT>(args)...);
return Ref<T>(result);
Ref<T> kcreate(ArgsT &&...args) {
return Ref<T>(knew<T>(std::forward<ArgsT>(args)...));
}
} // namespace utils
} // namespace orbis

View File

@ -0,0 +1,91 @@
#include "orbis/KernelContext.hpp"
#include "orbis/thread/Process.hpp"
#include <sys/mman.h>
#include <sys/unistd.h>
namespace orbis {
KernelContext &g_context = *[]() -> KernelContext * {
// Allocate global shared kernel memory
// TODO: randomize for hardening and reduce size
auto ptr = mmap(reinterpret_cast<void *>(0x200'0000'0000), 0x1'0000'0000,
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0);
if (!ptr)
std::abort();
return new (ptr) KernelContext;
}();
KernelContext::KernelContext() {}
KernelContext::~KernelContext() {}
Process *KernelContext::createProcess(pid_t pid) {
auto newProcess = knew<utils::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<utils::LinkedNode<Process> *>(proc);
auto pid = proc->pid;
{
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 {
std::lock_guard lock(m_proc_mtx);
for (auto proc = m_processes; proc != nullptr; proc = proc->next) {
if (proc->object.pid == pid) {
return &proc->object;
}
}
return nullptr;
}
void *KernelContext::kalloc(std::size_t size, std::size_t align) {
std::lock_guard lock(g_context.m_heap_mtx);
align = std::max(align, sizeof(node));
auto heap = reinterpret_cast<std::uintptr_t>(g_context.m_heap_next);
heap = (heap + (align - 1)) & ~(align - 1);
auto result = reinterpret_cast<void *>(heap);
g_context.m_heap_next = reinterpret_cast<void *>(heap + size);
return result;
}
void KernelContext::kfree(void *ptr, std::size_t size) {
std::lock_guard lock(g_context.m_heap_mtx);
if (!size)
std::abort();
// TODO: create node and put it into
}
inline namespace utils {
void kfree(void *ptr, std::size_t size) {
return KernelContext::kfree(ptr, size);
}
void *kalloc(std::size_t size, std::size_t align) {
return KernelContext::kalloc(size, align);
}
} // namespace utils
} // namespace orbis

View File

@ -2,7 +2,6 @@
#include "thread.hpp"
#include <utility>
#include "module/Module.hpp"
#include "thread/Process.hpp"
#include <string_view>

View File

@ -1,4 +1,5 @@
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include <fcntl.h>
#include <string>
#include <unistd.h>
@ -108,7 +109,7 @@ static std::int32_t host_io_open(IoDevice *device, orbis::Ref<IoDeviceInstance>
return 1; // TODO: convert errno
}
auto newInstance = new HostIoDeviceInstance();
auto newInstance = orbis::knew<HostIoDeviceInstance>();
newInstance->hostFd = hostFd;
@ -124,7 +125,7 @@ static std::int32_t host_io_open(IoDevice *device, orbis::Ref<IoDeviceInstance>
}
IoDevice *createHostIoDevice(const char *hostPath) {
auto result = new HostIoDevice();
auto result = orbis::knew<HostIoDevice>();
result->open = host_io_open;
result->hostPath = hostPath;
return result;

View File

@ -1,5 +1,6 @@
#include "bridge.hpp"
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include <cinttypes>
#include <cstddef>
#include <cstdio>
@ -245,7 +246,7 @@ static std::int32_t dce_device_open(IoDevice *device,
orbis::Ref<IoDeviceInstance> *instance,
const char *path, std::uint32_t flags,
std::uint32_t mode) {
auto *newInstance = new DceInstance();
auto *newInstance = orbis::knew<DceInstance>();
newInstance->ioctl = dce_instance_ioctl;
newInstance->mmap = dce_instance_mmap;
io_device_instance_init(device, newInstance);
@ -254,7 +255,7 @@ static std::int32_t dce_device_open(IoDevice *device,
}
IoDevice *createDceCharacterDevice() {
auto *newDevice = new DceDevice();
auto *newDevice = orbis::knew<DceDevice>();
newDevice->open = dce_device_open;
return newDevice;
}

View File

@ -1,4 +1,5 @@
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include <cstdio>
struct DmemDevice : public IoDevice {
@ -26,7 +27,7 @@ static std::int64_t dipsw_instance_ioctl(IoDeviceInstance *instance,
}
// 0x8010880a
// 0x8010880a
if (request == 0x8010880a) { // write data? used on initilization
struct Args {
std::uint64_t address;
@ -50,7 +51,7 @@ static std::int32_t dipsw_device_open(IoDevice *device,
orbis::Ref<IoDeviceInstance> *instance,
const char *path, std::uint32_t flags,
std::uint32_t mode) {
auto *newInstance = new DmemInstance();
auto *newInstance = orbis::knew<DmemInstance>();
newInstance->ioctl = dipsw_instance_ioctl;
io_device_instance_init(device, newInstance);
*instance = newInstance;
@ -58,7 +59,7 @@ static std::int32_t dipsw_device_open(IoDevice *device,
}
IoDevice *createDipswCharacterDevice() {
auto *newDevice = new DmemDevice();
auto *newDevice = orbis::knew<DmemDevice>();
newDevice->open = dipsw_device_open;
return newDevice;
}

View File

@ -1,4 +1,5 @@
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include <cinttypes>
#include <cstdio>
#include "vm.hpp"
@ -105,7 +106,7 @@ static std::int32_t dmem_device_open(IoDevice *device,
orbis::Ref<IoDeviceInstance> *instance,
const char *path, std::uint32_t flags,
std::uint32_t mode) {
auto *newInstance = new DmemInstance{};
auto *newInstance = orbis::knew<DmemInstance>();
newInstance->ioctl = dmem_instance_ioctl;
newInstance->mmap = dmem_instance_mmap;
@ -115,7 +116,7 @@ static std::int32_t dmem_device_open(IoDevice *device,
}
IoDevice *createDmemCharacterDevice(int index) {
auto *newDevice = new DmemDevice();
auto *newDevice = orbis::knew<DmemDevice>();
newDevice->open = dmem_device_open;
newDevice->index = index;
newDevice->nextOffset = 0;

View File

@ -1,5 +1,6 @@
#include "bridge.hpp"
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include <atomic>
#include <cinttypes>
#include <cstdio>
@ -251,7 +252,7 @@ static std::int32_t gc_device_open(IoDevice *device,
orbis::Ref<IoDeviceInstance> *instance,
const char *path, std::uint32_t flags,
std::uint32_t mode) {
auto *newInstance = new GcInstance{};
auto *newInstance = orbis::knew<GcInstance>();
newInstance->ioctl = gc_instance_ioctl;
newInstance->mmap = gc_instance_mmap;
io_device_instance_init(device, newInstance);
@ -260,7 +261,7 @@ static std::int32_t gc_device_open(IoDevice *device,
}
IoDevice *createGcCharacterDevice() {
auto *newDevice = new GcDevice;
auto *newDevice = orbis::knew<GcDevice>();
newDevice->open = gc_device_open;
return newDevice;
}

View File

@ -1,4 +1,5 @@
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include "vm.hpp"
#include <cinttypes>
#include <cstdio>
@ -25,7 +26,7 @@ static std::int32_t hid_device_open(IoDevice *device,
orbis::Ref<IoDeviceInstance> *instance,
const char *path, std::uint32_t flags,
std::uint32_t mode) {
auto *newInstance = new HidInstance{};
auto *newInstance = orbis::knew<HidInstance>();
newInstance->ioctl = hid_instance_ioctl;
newInstance->mmap = hid_instance_mmap;
@ -35,7 +36,7 @@ static std::int32_t hid_device_open(IoDevice *device,
}
IoDevice *createHidCharacterDevice() {
auto *newDevice = new HidDevice;
auto *newDevice = orbis::knew<HidDevice>();
newDevice->open = hid_device_open;
return newDevice;
}

View File

@ -1,4 +1,5 @@
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include <cstdio>
struct Hmd3daDevice : public IoDevice {
@ -19,7 +20,7 @@ static std::int32_t hmd_3da_device_open(IoDevice *device,
orbis::Ref<IoDeviceInstance> *instance,
const char *path, std::uint32_t flags,
std::uint32_t mode) {
auto *newInstance = new Hmd3daInstance{};
auto *newInstance = orbis::knew<Hmd3daInstance>();
newInstance->ioctl = hmd_3da_instance_ioctl;
io_device_instance_init(device, newInstance);
@ -28,7 +29,7 @@ static std::int32_t hmd_3da_device_open(IoDevice *device,
}
IoDevice *createHmd3daCharacterDevice() {
auto *newDevice = new Hmd3daDevice();
auto *newDevice = orbis::knew<Hmd3daDevice>();
newDevice->open = hmd_3da_device_open;
return newDevice;
}

View File

@ -1,4 +1,5 @@
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include <cstdio>
struct HmdCmdDevice : public IoDevice {
@ -19,7 +20,7 @@ static std::int32_t hmd_cmd_device_open(IoDevice *device,
orbis::Ref<IoDeviceInstance> *instance,
const char *path, std::uint32_t flags,
std::uint32_t mode) {
auto *newInstance = new HmdCmdInstance{};
auto *newInstance = orbis::knew<HmdCmdInstance>();
newInstance->ioctl = hmd_cmd_instance_ioctl;
io_device_instance_init(device, newInstance);
@ -29,7 +30,7 @@ static std::int32_t hmd_cmd_device_open(IoDevice *device,
}
IoDevice *createHmdCmdCharacterDevice() {
auto *newDevice = new HmdCmdDevice();
auto *newDevice = orbis::knew<HmdCmdDevice>();
newDevice->open = hmd_cmd_device_open;
return newDevice;
}

View File

@ -1,4 +1,5 @@
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include "vm.hpp"
#include <cinttypes>
#include <cstdio>
@ -31,7 +32,7 @@ static std::int32_t hmd_mmap_device_open(IoDevice *device,
orbis::Ref<IoDeviceInstance> *instance,
const char *path, std::uint32_t flags,
std::uint32_t mode) {
auto *newInstance = new HmdMmapInstance{};
auto *newInstance = orbis::knew<HmdMmapInstance>();
newInstance->ioctl = hmd_mmap_instance_ioctl;
newInstance->mmap = hmd_mmap_instance_mmap;
@ -41,7 +42,7 @@ static std::int32_t hmd_mmap_device_open(IoDevice *device,
}
IoDevice *createHmdMmapCharacterDevice() {
auto *newDevice = new HmdMmapDevice();
auto *newDevice = orbis::knew<HmdMmapDevice>();
newDevice->open = hmd_mmap_device_open;
return newDevice;
}

View File

@ -1,5 +1,5 @@
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include <cstdio>
struct HmdSnsrDevice : public IoDevice {};
@ -19,7 +19,7 @@ static std::int32_t smd_snr_device_open(IoDevice *device,
orbis::Ref<IoDeviceInstance> *instance,
const char *path, std::uint32_t flags,
std::uint32_t mode) {
auto *newInstance = new HmdSnsrInstance{};
auto *newInstance = orbis::knew<HmdSnsrInstance>();
newInstance->ioctl = smd_snr_instance_ioctl;
io_device_instance_init(device, newInstance);
*instance = newInstance;
@ -27,7 +27,7 @@ static std::int32_t smd_snr_device_open(IoDevice *device,
}
IoDevice *createHmdSnsrCharacterDevice() {
auto *newDevice = new HmdSnsrDevice();
auto *newDevice = orbis::knew<HmdSnsrDevice>();
newDevice->open = smd_snr_device_open;
return newDevice;
}

View File

@ -1,4 +1,5 @@
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
struct NullDevice : public IoDevice {};
@ -13,7 +14,7 @@ static std::int64_t null_instance_write(IoDeviceInstance *instance,
static std::int32_t null_device_open(IoDevice *device, orbis::Ref<IoDeviceInstance> *instance,
const char *path, std::uint32_t flags,
std::uint32_t mode) {
auto *newInstance = new NullInstance{};
auto *newInstance = orbis::knew<NullInstance>();
newInstance->write = null_instance_write;
io_device_instance_init(device, newInstance);
@ -22,7 +23,7 @@ static std::int32_t null_device_open(IoDevice *device, orbis::Ref<IoDeviceInstan
}
IoDevice *createNullCharacterDevice() {
auto *newDevice = new NullDevice();
auto *newDevice = orbis::knew<NullDevice>();
newDevice->open = null_device_open;
return newDevice;
}

View File

@ -1,4 +1,5 @@
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include "vm.hpp"
#include <cinttypes>
#include <cstdio>
@ -23,7 +24,7 @@ static std::int32_t rng_device_open(IoDevice *device,
orbis::Ref<IoDeviceInstance> *instance,
const char *path, std::uint32_t flags,
std::uint32_t mode) {
auto *newInstance = new RngInstance{};
auto *newInstance = orbis::knew<RngInstance>();
newInstance->ioctl = rng_instance_ioctl;
newInstance->mmap = rng_instance_mmap;
@ -33,7 +34,7 @@ static std::int32_t rng_device_open(IoDevice *device,
}
IoDevice *createRngCharacterDevice() {
auto *newDevice = new RngDevice{};
auto *newDevice = orbis::knew<RngDevice>();
newDevice->open = rng_device_open;
return newDevice;
}

View File

@ -1,4 +1,5 @@
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include <fstream>
struct StderrInstance : public IoDeviceInstance {};
@ -25,7 +26,7 @@ static std::int32_t stderr_device_open(IoDevice *device,
std::uint32_t mode) {
auto stderrDevice = static_cast<StderrDevice *>(device);
if (stderrDevice->instance == nullptr) {
auto *newInstance = new StderrInstance{};
auto *newInstance = orbis::knew<StderrInstance>();
newInstance->write = stderr_instance_write;
newInstance->close = stderr_instance_close;
@ -42,7 +43,7 @@ static std::int32_t stderr_device_open(IoDevice *device,
}
IoDevice *createStderrCharacterDevice() {
auto *newDevice = new StderrDevice();
auto *newDevice = orbis::knew<StderrDevice>();
newDevice->open = stderr_device_open;
return newDevice;
}

View File

@ -1,4 +1,5 @@
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
struct StdinDevice : public IoDevice {
};
@ -14,7 +15,7 @@ static std::int64_t stdin_instance_read(IoDeviceInstance *instance, void *data,
static std::int32_t open(IoDevice *device, orbis::Ref<IoDeviceInstance> *instance,
const char *path, std::uint32_t flags,
std::uint32_t mode) {
auto *newInstance = new StdinInstance{};
auto *newInstance = orbis::knew<StdinInstance>();
newInstance->read = stdin_instance_read;
io_device_instance_init(device, newInstance);
*instance = newInstance;
@ -22,7 +23,7 @@ static std::int32_t open(IoDevice *device, orbis::Ref<IoDeviceInstance> *instanc
}
IoDevice *createStdinCharacterDevice() {
auto *newDevice = new StdinDevice();
auto *newDevice = orbis::knew<StdinDevice>();
newDevice->open = open;
return newDevice;
}

View File

@ -1,4 +1,5 @@
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include <cstdio>
@ -28,7 +29,7 @@ static std::int32_t stdout_device_open(IoDevice *device,
std::uint32_t mode) {
auto stdoutDevice = static_cast<StdoutDevice *>(device);
if (stdoutDevice->instance == nullptr) {
auto *newInstance = new StdoutInstance{};
auto *newInstance = orbis::knew<StdoutInstance>();
newInstance->write = stdout_instance_write;
newInstance->close = stdout_instance_close;
io_device_instance_init(device, newInstance);
@ -43,7 +44,7 @@ static std::int32_t stdout_device_open(IoDevice *device,
}
IoDevice *createStdoutCharacterDevice() {
auto *newDevice = new StdoutDevice();
auto *newDevice = orbis::knew<StdoutDevice>();
newDevice->open = stdout_device_open;
return newDevice;
}

View File

@ -1,4 +1,5 @@
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include <cstring>
struct ZeroDevice : public IoDevice {
@ -17,7 +18,7 @@ static std::int32_t zero_device_open(IoDevice *device,
orbis::Ref<IoDeviceInstance> *instance,
const char *path, std::uint32_t flags,
std::uint32_t mode) {
auto *newInstance = new ZeroInstance{};
auto *newInstance = orbis::knew<ZeroInstance>();
newInstance->read = zero_device_read;
io_device_instance_init(device, newInstance);
@ -26,7 +27,7 @@ static std::int32_t zero_device_open(IoDevice *device,
}
IoDevice *createZeroCharacterDevice() {
auto *newDevice = new ZeroDevice();
auto *newDevice = orbis::knew<ZeroDevice>();
newDevice->open = zero_device_open;
return newDevice;
}

View File

@ -1,6 +1,7 @@
#include "linker.hpp"
#include "align.hpp"
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/module/Module.hpp"
#include "vfs.hpp"
#include "vm.hpp"
@ -280,7 +281,7 @@ void rx::linker::override(std::string originalModuleName,
Ref<orbis::Module> rx::linker::loadModule(std::span<std::byte> image,
orbis::Process *process) {
Ref<orbis::Module> result{new orbis::Module{}};
Ref<orbis::Module> result{orbis::knew<orbis::Module>()};
Elf64_Ehdr header;
std::memcpy(&header, image.data(), sizeof(Elf64_Ehdr));
@ -842,7 +843,7 @@ Ref<orbis::Module> rx::linker::loadModuleFile(const char *path,
}
static Ref<orbis::Module> createSceFreeTypeFull(orbis::Process *process) {
auto result = orbis::create<orbis::Module>();
auto result = orbis::knew<orbis::Module>();
std::strncpy(result->soName, "libSceFreeTypeFull.prx",
sizeof(result->soName) - 1);

View File

@ -521,15 +521,6 @@ static int ps4Exec(orbis::Process *mainProcess,
return 0;
}
struct KernelEventLogger : public orbis::KernelContext::EventListener {
void onProcessCreated(orbis::Process *process) override {
std::printf("process %u was created\n", (unsigned)process->pid);
}
void onProcessDeleted(orbis::pid_t pid) override {
std::printf("process %u was deleted\n", (unsigned)pid);
}
};
static void usage(const char *argv0) {
std::printf("%s [<options>...] <virtual path to elf> [args...]\n", argv0);
std::printf(" options:\n");
@ -653,9 +644,6 @@ int main(int argc, const char *argv[]) {
setupSigHandlers();
// rx::vm::printHostStats();
KernelEventLogger eventLogger;
orbis::KernelContext context;
context.addEventListener(&eventLogger);
rx::vfs::initialize();
@ -712,7 +700,7 @@ int main(int argc, const char *argv[]) {
runRpsxGpu();
// rx::vm::printHostStats();
auto initProcess = context.createProcess(10);
auto initProcess = orbis::g_context.createProcess(10);
initProcess->sysent = &orbis::ps4_sysvec;
initProcess->onSysEnter = onSysEnter;
initProcess->onSysExit = onSysExit;