Added shader state; WIP kernel objects

This commit is contained in:
Hamish Milne 2019-08-11 00:20:09 +01:00 committed by zhupengfei
parent 45788b9c82
commit f79c9668a3
33 changed files with 576 additions and 68 deletions

View file

@ -13,9 +13,6 @@
namespace Kernel {
ClientPort::ClientPort(KernelSystem& kernel) : Object(kernel), kernel(kernel) {}
ClientPort::~ClientPort() = default;
ResultVal<std::shared_ptr<ClientSession>> ClientPort::Connect() {
// Note: Threads do not wait for the server endpoint to call
// AcceptSession before returning from this call.
@ -26,7 +23,7 @@ ResultVal<std::shared_ptr<ClientSession>> ClientPort::Connect() {
active_sessions++;
// Create a new session pair, let the created sessions inherit the parent port's HLE handler.
auto [server, client] = kernel.CreateSessionPair(server_port->GetName(), SharedFrom(this));
auto [server, client] = g_kernel->CreateSessionPair(server_port->GetName(), SharedFrom(this));
if (server_port->hle_handler)
server_port->hle_handler->ClientConnected(server);

View file

@ -17,8 +17,6 @@ class ClientSession;
class ClientPort final : public Object {
public:
explicit ClientPort(KernelSystem& kernel);
~ClientPort() override;
friend class ServerPort;
std::string GetTypeName() const override {
@ -52,13 +50,25 @@ public:
void ConnectionClosed();
private:
KernelSystem& kernel;
std::shared_ptr<ServerPort> server_port; ///< ServerPort associated with this client port.
u32 max_sessions = 0; ///< Maximum number of simultaneous sessions the port can have
u32 active_sessions = 0; ///< Number of currently open sessions to this port
std::string name; ///< Name of client port (optional)
friend class KernelSystem;
private:
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int file_version)
{
ar & boost::serialization::base_object<Object>(*this);
ar & server_port;
ar & max_sessions;
ar & active_sessions;
ar & name;
}
};
} // namespace Kernel

View file

@ -49,6 +49,16 @@ private:
std::string name; ///< Name of event (optional)
friend class KernelSystem;
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int file_version)
{
ar & boost::serialization::base_object<WaitObject>(*this);
ar & reset_type;
ar & signaled;
ar & name;
}
};
} // namespace Kernel

View file

@ -7,6 +7,8 @@
#include <array>
#include <cstddef>
#include <memory>
#include <boost/serialization/array.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include "common/common_types.h"
#include "core/hle/kernel/object.h"
#include "core/hle/result.h"
@ -116,6 +118,16 @@ private:
u16 next_free_slot;
KernelSystem& kernel;
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int file_version)
{
ar & objects;
ar & generations;
ar & next_generation;
ar & next_free_slot;
}
};
} // namespace Kernel

View file

@ -2,6 +2,8 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "common/archives.h"
#include "common/serialization/atomic.h"
#include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/config_mem.h"
#include "core/hle/kernel/handle_table.h"
@ -16,6 +18,8 @@
namespace Kernel {
KernelSystem* g_kernel;
/// Initialize the kernel
KernelSystem::KernelSystem(Memory::MemorySystem& memory, Core::Timing& timing,
std::function<void()> prepare_reschedule_callback, u32 system_mode)
@ -101,4 +105,23 @@ void KernelSystem::AddNamedPort(std::string name, std::shared_ptr<ClientPort> po
named_ports.emplace(std::move(name), std::move(port));
}
template <class Archive>
void KernelSystem::serialize(Archive& ar, const unsigned int file_version)
{
ar & named_ports;
// TODO: CPU
// NB: subsystem references and prepare_reschedule_callback are constant
ar & *resource_limits.get();
ar & next_object_id;
//ar & *timer_manager.get();
ar & next_process_id;
ar & process_list;
ar & current_process;
// ar & *thread_manager.get();
//ar & *config_mem_handler.get();
//ar & *shared_page_handler.get();
}
SERIALIZE_IMPL(KernelSystem)
} // namespace Kernel

View file

@ -11,6 +11,9 @@
#include <string>
#include <unordered_map>
#include <vector>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/unordered_map.hpp>
#include <boost/serialization/vector.hpp>
#include "common/common_types.h"
#include "core/hle/kernel/memory.h"
#include "core/hle/result.h"
@ -283,6 +286,12 @@ private:
std::unique_ptr<SharedPage::Handler> shared_page_handler;
std::unique_ptr<IPCDebugger::Recorder> ipc_recorder;
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int file_version);
};
extern KernelSystem* g_kernel;
} // namespace Kernel

View file

@ -60,6 +60,17 @@ struct MemoryRegionInfo {
* @param size the size of the region to free.
*/
void Free(u32 offset, u32 size);
private:
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int file_version)
{
ar & base;
ar & size;
ar & used;
// TODO: boost icl / free_blocks
}
};
} // namespace Kernel

View file

@ -58,6 +58,18 @@ public:
private:
KernelSystem& kernel;
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int file_version)
{
ar & boost::serialization::base_object<WaitObject>(*this);
ar & lock_count;
ar & priority;
ar & name;
ar & holding_thread;
ar & kernel; // TODO: Check that this works!
}
};
/**

View file

@ -8,7 +8,17 @@
namespace Kernel {
Object::Object(KernelSystem& kernel) : object_id{kernel.GenerateObjectID()} {}
// TODO: Remove this
Object::Object(KernelSystem& kernel)
{
}
Object::Object() = default;
void Object::Init(KernelSystem& kernel)
{
object_id = kernel.GenerateObjectID();
}
Object::~Object() = default;

View file

@ -7,6 +7,7 @@
#include <atomic>
#include <memory>
#include <string>
#include <boost/serialization/access.hpp>
#include "common/common_types.h"
#include "core/hle/kernel/kernel.h"
@ -41,8 +42,11 @@ enum {
class Object : NonCopyable, public std::enable_shared_from_this<Object> {
public:
explicit Object(KernelSystem& kernel);
Object();
virtual ~Object();
virtual void Init(KernelSystem& kernel);
/// Returns a unique identifier for the object. For debugging purposes only.
u32 GetObjectId() const {
return object_id.load(std::memory_order_relaxed);
@ -64,6 +68,13 @@ public:
private:
std::atomic<u32> object_id;
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int file_version)
{
ar & object_id;
}
};
template <typename T>

View file

@ -18,7 +18,8 @@
namespace Kernel {
std::shared_ptr<CodeSet> KernelSystem::CreateCodeSet(std::string name, u64 program_id) {
auto codeset{std::make_shared<CodeSet>(*this)};
auto codeset{std::make_shared<CodeSet>()};
codeset->Init(*this);
codeset->name = std::move(name);
codeset->program_id = program_id;
@ -26,11 +27,9 @@ std::shared_ptr<CodeSet> KernelSystem::CreateCodeSet(std::string name, u64 progr
return codeset;
}
CodeSet::CodeSet(KernelSystem& kernel) : Object(kernel) {}
CodeSet::~CodeSet() {}
std::shared_ptr<Process> KernelSystem::CreateProcess(std::shared_ptr<CodeSet> code_set) {
auto process{std::make_shared<Process>(*this)};
auto process{std::make_shared<Process>()};
process->Init(*this);
process->codeset = std::move(code_set);
process->flags.raw = 0;
@ -401,9 +400,8 @@ ResultCode Process::Unmap(VAddr target, VAddr source, u32 size, VMAPermission pe
return RESULT_SUCCESS;
}
Kernel::Process::Process(KernelSystem& kernel)
: Object(kernel), handle_table(kernel), vm_manager(kernel.memory), kernel(kernel) {
Kernel::Process::Process() : kernel(*g_kernel), handle_table(*g_kernel), vm_manager(g_kernel->memory)
{
kernel.memory.RegisterPageTable(&vm_manager.page_table);
}
Kernel::Process::~Process() {

View file

@ -11,8 +11,13 @@
#include <string>
#include <vector>
#include <boost/container/static_vector.hpp>
#include <boost/serialization/array.hpp>
#include <boost/serialization/bitset.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/vector.hpp>
#include "common/bit_field.h"
#include "common/common_types.h"
#include "common/serialization/boost_vector.hpp"
#include "core/hle/kernel/handle_table.h"
#include "core/hle/kernel/object.h"
#include "core/hle/kernel/vm_manager.h"
@ -25,6 +30,17 @@ struct AddressMapping {
u32 size;
bool read_only;
bool unk_flag;
private:
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int file_version)
{
ar & address;
ar & size;
ar & read_only;
ar & unk_flag;
}
};
union ProcessFlags {
@ -52,13 +68,20 @@ struct MemoryRegionInfo;
class CodeSet final : public Object {
public:
explicit CodeSet(KernelSystem& kernel);
~CodeSet() override;
struct Segment {
std::size_t offset = 0;
VAddr addr = 0;
u32 size = 0;
private:
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int file_version)
{
ar & offset;
ar & addr;
ar & size;
}
};
std::string GetTypeName() const override {
@ -106,11 +129,24 @@ public:
std::string name;
/// Title ID corresponding to the process
u64 program_id;
private:
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int file_version)
{
ar & boost::serialization::base_object<Object>(*this);
// TODO: memory reference
ar & segments;
ar & entrypoint;
ar & name;
ar & program_id;
}
};
class Process final : public Object {
public:
explicit Process(Kernel::KernelSystem& kernel);
explicit Process();
~Process() override;
std::string GetTypeName() const override {
@ -195,5 +231,26 @@ public:
private:
KernelSystem& kernel;
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int file_version)
{
ar & boost::serialization::base_object<Object>(*this);
ar & handle_table;
ar & codeset;
ar & resource_limit;
ar & svc_access_mask;
ar & handle_table_size;
ar & (boost::container::vector<AddressMapping, boost::container::dtl::static_storage_allocator<AddressMapping, 8> >&)address_mappings;
ar & flags.raw;
ar & kernel_version;
ar & ideal_processor;
ar & process_id;
ar & vm_manager;
ar & memory_used;
ar & memory_region;
ar & tls_slots;
}
};
} // namespace Kernel

View file

@ -9,11 +9,9 @@
namespace Kernel {
ResourceLimit::ResourceLimit(KernelSystem& kernel) : Object(kernel) {}
ResourceLimit::~ResourceLimit() {}
std::shared_ptr<ResourceLimit> ResourceLimit::Create(KernelSystem& kernel, std::string name) {
auto resource_limit{std::make_shared<ResourceLimit>(kernel)};
auto resource_limit{std::make_shared<ResourceLimit>()};
resource_limit->Init(kernel);
resource_limit->name = std::move(name);
return resource_limit;

View file

@ -6,6 +6,8 @@
#include <array>
#include <memory>
#include <boost/serialization/array.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include "common/common_types.h"
#include "core/hle/kernel/object.h"
@ -33,8 +35,6 @@ enum ResourceTypes {
class ResourceLimit final : public Object {
public:
explicit ResourceLimit(KernelSystem& kernel);
~ResourceLimit() override;
/**
* Creates a resource limit object.
@ -110,6 +110,35 @@ public:
/// Current CPU time that the processes in this category are utilizing
s32 current_cpu_time = 0;
private:
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int file_version)
{
ar & boost::serialization::base_object<Object>(*this);
// NB most of these aren't used at all currently, but we're adding them here for forwards compatibility
ar & name;
ar & max_priority;
ar & max_commit;
ar & max_threads;
ar & max_events;
ar & max_mutexes;
ar & max_semaphores;
ar & max_timers;
ar & max_shared_mems;
ar & max_address_arbiters;
ar & max_cpu_time;
ar & current_commit;
ar & current_threads;
ar & current_events;
ar & current_mutexes;
ar & current_semaphores;
ar & current_timers;
ar & current_shared_mems;
ar & current_address_arbiters;
ar & current_cpu_time;
}
};
class ResourceLimitList {
@ -126,6 +155,13 @@ public:
private:
std::array<std::shared_ptr<ResourceLimit>, 4> resource_limits;
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int file_version)
{
ar & resource_limits;
}
};
} // namespace Kernel

View file

@ -43,6 +43,17 @@ public:
* @return The number of free slots the semaphore had before this call
*/
ResultVal<s32> Release(s32 release_count);
private:
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int file_version)
{
ar & boost::serialization::base_object<WaitObject>(*this);
ar & max_count;
ar & available_count;
ar & name;
}
};
} // namespace Kernel

View file

@ -13,9 +13,6 @@
namespace Kernel {
ServerPort::ServerPort(KernelSystem& kernel) : WaitObject(kernel) {}
ServerPort::~ServerPort() {}
ResultVal<std::shared_ptr<ServerSession>> ServerPort::Accept() {
if (pending_sessions.empty()) {
return ERR_NO_PENDING_SESSIONS;
@ -36,8 +33,10 @@ void ServerPort::Acquire(Thread* thread) {
}
KernelSystem::PortPair KernelSystem::CreatePortPair(u32 max_sessions, std::string name) {
auto server_port{std::make_shared<ServerPort>(*this)};
auto client_port{std::make_shared<ClientPort>(*this)};
auto server_port{std::make_shared<ServerPort>()};
server_port->Init(*this);
auto client_port{std::make_shared<ClientPort>()};
client_port->Init(*this);
server_port->name = name + "_Server";
client_port->name = name + "_Client";

View file

@ -20,8 +20,6 @@ class SessionRequestHandler;
class ServerPort final : public WaitObject {
public:
explicit ServerPort(KernelSystem& kernel);
~ServerPort() override;
std::string GetTypeName() const override {
return "ServerPort";

View file

@ -13,7 +13,7 @@
namespace Kernel {
ServerSession::ServerSession(KernelSystem& kernel) : WaitObject(kernel), kernel(kernel) {}
ServerSession::ServerSession() : kernel(*g_kernel) {}
ServerSession::~ServerSession() {
// This destructor will be called automatically when the last ServerSession handle is closed by
// the emulated application.
@ -30,7 +30,8 @@ ServerSession::~ServerSession() {
ResultVal<std::shared_ptr<ServerSession>> ServerSession::Create(KernelSystem& kernel,
std::string name) {
auto server_session{std::make_shared<ServerSession>(kernel)};
auto server_session{std::make_shared<ServerSession>()};
server_session->Init(kernel);
server_session->name = std::move(name);
server_session->parent = nullptr;

View file

@ -38,7 +38,7 @@ class Thread;
class ServerSession final : public WaitObject {
public:
~ServerSession() override;
explicit ServerSession(KernelSystem& kernel);
explicit ServerSession();
std::string GetName() const override {
return name;

View file

@ -37,9 +37,9 @@ u32 ThreadManager::NewThreadId() {
return next_thread_id++;
}
Thread::Thread(KernelSystem& kernel)
: WaitObject(kernel), context(kernel.GetThreadManager().NewContext()),
thread_manager(kernel.GetThreadManager()) {}
Thread::Thread()
: context(g_kernel->GetThreadManager().NewContext()),
thread_manager(g_kernel->GetThreadManager()) {}
Thread::~Thread() {}
Thread* ThreadManager::GetCurrentThread() const {
@ -309,7 +309,8 @@ ResultVal<std::shared_ptr<Thread>> KernelSystem::CreateThread(std::string name,
ErrorSummary::InvalidArgument, ErrorLevel::Permanent);
}
auto thread{std::make_shared<Thread>(*this)};
auto thread{std::make_shared<Thread>()};
thread->Init(*this);
thread_manager->thread_list.push_back(thread);
thread_manager->ready_queue.prepare(priority);

View file

@ -149,7 +149,7 @@ private:
class Thread final : public WaitObject {
public:
explicit Thread(KernelSystem&);
explicit Thread();
~Thread() override;
std::string GetName() const override {

View file

@ -8,7 +8,8 @@
#include <memory>
#include <utility>
#include <vector>
#include "boost/serialization/split_member.hpp"
#include <boost/serialization/map.hpp>
#include <boost/serialization/split_member.hpp>
#include "common/common_types.h"
#include "core/hle/result.h"
#include "core/memory.h"
@ -81,6 +82,21 @@ struct VirtualMemoryArea {
/// Tests if this area can be merged to the right with `next`.
bool CanBeMergedWith(const VirtualMemoryArea& next) const;
private:
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int file_version)
{
ar & base;
ar & size;
ar & type;
ar & permissions;
ar & meminfo_state;
// TODO: backing memory ref
ar & paddr;
ar & mmio_handler;
}
};
/**
@ -195,9 +211,10 @@ public:
private:
friend class boost::serialization::access;
template<class Archive>
void save(Archive & ar, const unsigned int file_version)
template <class Archive>
void save(Archive& ar, const unsigned int file_version) const
{
ar & vma_map;
for (int i = 0; i < page_table.pointers.size(); i++) {
ar << memory.GetFCRAMOffset(page_table.pointers[i]);
}
@ -205,9 +222,10 @@ private:
ar & page_table.attributes;
}
template<class Archive>
void load(Archive & ar, const unsigned int file_version)
template <class Archive>
void load(Archive& ar, const unsigned int file_version)
{
ar & vma_map;
for (int i = 0; i < page_table.pointers.size(); i++) {
u32 offset{};
ar >> offset;

View file

@ -7,6 +7,9 @@
#include <functional>
#include <memory>
#include <vector>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/vector.hpp>
#include "common/common_types.h"
#include "core/hle/kernel/object.h"
@ -62,6 +65,17 @@ private:
/// Function to call when this object becomes available
std::function<void()> hle_notifier;
private:
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int file_version)
{
ar & boost::serialization::base_object<Object>(*this);
ar & waiting_threads;
// NB: hle_notifier *not* serialized since it's a callback!
// Fortunately it's only used in one place (DSP) so we can reconstruct it there
}
};
// Specialization of DynamicObjectCast for WaitObjects

View file

@ -14,6 +14,7 @@
#include "core/hle/ipc_helpers.h"
#include "core/hle/result.h"
#include "core/hle/service/err_f.h"
#undef exception_info
namespace Service::ERR {