orbis: remove process list from context & initial serialization support

modernize kenv
add LockableKernelObject utility
This commit is contained in:
DH 2025-10-11 18:06:29 +03:00
parent f71e3410c1
commit 014012c219
22 changed files with 372 additions and 215 deletions

View file

@ -8,9 +8,7 @@
#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>
@ -37,18 +35,6 @@ 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,
@ -123,17 +109,15 @@ 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;
@ -177,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;
@ -192,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

@ -15,6 +15,7 @@ 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>

View file

@ -59,6 +59,8 @@ struct Process final {
kernel::StaticKernelObjectStorage<OrbisNamespace,
kernel::detail::ProcessScope>;
~Process();
KernelContext *context = nullptr;
std::byte *storage = nullptr;
@ -97,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
@ -115,18 +117,8 @@ struct Process final {
void incRef() {}
void decRef() {}
void allocate() {
if (auto size = Storage::GetSize()) {
storage = (std::byte *)kalloc(size, Storage::GetAlignment());
}
}
void deallocate() {
if (auto size = Storage::GetSize()) {
kfree(storage, size);
storage = nullptr;
}
}
void serialize(rx::Serializer &) const;
void deserialize(rx::Deserializer &);
template <rx::Serializable T>
T *get(
@ -135,4 +127,10 @@ struct Process final {
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

@ -4,6 +4,7 @@
#include "cpuset.hpp"
#include "orbis-config.hpp"
#include "rx/Serializer.hpp"
#include "rx/StaticString.hpp"
#include "types.hpp"
#include "../KernelAllocator.hpp"
@ -23,6 +24,8 @@ struct Thread final {
kernel::StaticKernelObjectStorage<OrbisNamespace,
kernel::detail::ThreadScope>;
~Thread();
rx::shared_mutex mtx;
Process *tproc = nullptr;
std::byte *storage = nullptr;
@ -33,7 +36,7 @@ struct Thread final {
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};
@ -82,19 +85,6 @@ struct Thread final {
void notifyUnblockedSignal(int signo);
void setSigMask(SigSet newSigMask);
void allocate() {
if (auto size = Storage::GetSize()) {
storage = (std::byte *)kalloc(size, Storage::GetAlignment());
}
}
void deallocate() {
if (auto size = Storage::GetSize()) {
kfree(storage, size);
storage = nullptr;
}
}
template <rx::Serializable T>
T *get(kernel::StaticObjectRef<OrbisNamespace, kernel::detail::ThreadScope, T>
ref) {
@ -106,6 +96,8 @@ struct Thread final {
void decRef() {}
};
Thread *createThread(Process *process, std::string_view name);
extern thread_local Thread *g_currentThread;
struct scoped_unblock {