Correct exports; add some file serialization; fix service base object serialization

This commit is contained in:
Hamish Milne 2020-01-08 22:13:56 +00:00 committed by zhupengfei
parent f2de70c3fb
commit 996aba39fe
52 changed files with 197 additions and 33 deletions

1
TODO
View File

@ -5,6 +5,7 @@
☐ Review constructor/initialization code
☐ Review core timing events
☐ Review base class serialization everywhere
Make sure that all base/derived relationships are registered
☐ Serialize codeset with an apploader reference instead
✔ CPU @done(19-08-13 15:41)
✔ Memory @done(19-08-13 15:41)

View File

@ -10,5 +10,6 @@ using oarchive = boost::archive::binary_oarchive;
template void A::serialize<oarchive>(oarchive & ar, const unsigned int file_version);
#define SERIALIZE_EXPORT_IMPL(A) \
BOOST_CLASS_EXPORT_IMPLEMENT(A) \
BOOST_SERIALIZATION_REGISTER_ARCHIVE(iarchive) \
BOOST_SERIALIZATION_REGISTER_ARCHIVE(oarchive)

View File

@ -901,10 +901,18 @@ IOFile& IOFile::operator=(IOFile&& other) {
void IOFile::Swap(IOFile& other) {
std::swap(m_file, other.m_file);
std::swap(m_good, other.m_good);
std::swap(filename, other.filename);
std::swap(openmode, other.openmode);
std::swap(flags, other.flags);
}
bool IOFile::Open(const std::string& filename, const char openmode[], int flags) {
Close();
this->filename = filename;
this->openmode = openmode;
this->flags = flags;
#ifdef _WIN32
if (flags != 0) {
m_file = _wfsopen(Common::UTF8ToUTF16W(filename).c_str(),

View File

@ -14,6 +14,8 @@
#include <string_view>
#include <type_traits>
#include <vector>
#include <boost/serialization/split_member.hpp>
#include <boost/serialization/string.hpp>
#include "common/common_types.h"
#ifdef _MSC_VER
#include "common/string_util.h"
@ -221,7 +223,6 @@ public:
void Swap(IOFile& other);
bool Open(const std::string& filename, const char openmode[], int flags = 0);
bool Close();
template <typename T>
@ -305,8 +306,34 @@ public:
}
private:
bool Open(const std::string& filename, const char openmode[], int flags = 0);
std::FILE* m_file = nullptr;
bool m_good = true;
std::string filename;
std::string openmode;
u32 flags;
template <class Archive>
void save(Archive& ar, const unsigned int) const {
ar << filename;
ar << openmode;
ar << flags;
ar << Tell();
}
template <class Archive>
void load(Archive& ar, const unsigned int) {
ar >> filename;
ar >> openmode;
ar >> flags;
u64 pos;
ar >> pos;
Seek(pos, SEEK_SET);
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
} // namespace FileUtil

View File

@ -14,6 +14,11 @@ public:
virtual ~BackingMem() = default;
virtual u8* GetPtr() = 0;
virtual u32 GetSize() const = 0;
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {}
friend class boost::serialization::access;
};
/// Backing memory implemented by a local buffer
@ -39,6 +44,7 @@ private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<BackingMem>(*this);
ar& data;
}
friend class boost::serialization::access;

View File

@ -80,6 +80,8 @@ public:
static constexpr u64 IPCDelayNanoseconds(3085068);
return IPCDelayNanoseconds;
}
SERIALIZE_DELAY_GENERATOR
};
/**
@ -300,3 +302,5 @@ void ArchiveFactory_ExtSaveData::WriteIcon(const Path& path, const u8* icon_data
}
} // namespace FileSys
SERIALIZE_EXPORT_IMPL(FileSys::ExtSaveDataDelayGenerator)

View File

@ -103,6 +103,9 @@ std::string GetExtDataContainerPath(const std::string& mount_point, bool shared)
*/
Path ConstructExtDataBinaryPath(u32 media_type, u32 high, u32 low);
class ExtSaveDataDelayGenerator;
} // namespace FileSys
BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_ExtSaveData)
BOOST_CLASS_EXPORT_KEY(FileSys::ExtSaveDataDelayGenerator)

View File

@ -41,6 +41,8 @@ public:
static constexpr u64 IPCDelayNanoseconds(269082);
return IPCDelayNanoseconds;
}
SERIALIZE_DELAY_GENERATOR
};
ResultVal<std::unique_ptr<FileBackend>> SDMCArchive::OpenFile(const Path& path,
@ -409,3 +411,5 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_SDMC::GetFormatInfo(const Path& path
return ResultCode(-1);
}
} // namespace FileSys
SERIALIZE_EXPORT_IMPL(FileSys::SDMCDelayGenerator)

View File

@ -86,7 +86,10 @@ private:
friend class boost::serialization::access;
};
class SDMCDelayGenerator;
} // namespace FileSys
BOOST_CLASS_EXPORT_KEY(FileSys::SDMCArchive)
BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_SDMC)
BOOST_CLASS_EXPORT_KEY(FileSys::SDMCDelayGenerator)

View File

@ -39,6 +39,8 @@ public:
static constexpr u64 IPCDelayNanoseconds(269082);
return IPCDelayNanoseconds;
}
SERIALIZE_DELAY_GENERATOR
};
ResultVal<std::unique_ptr<FileBackend>> SDMCWriteOnlyArchive::OpenFile(const Path& path,
@ -100,3 +102,5 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_SDMCWriteOnly::GetFormatInfo(const P
}
} // namespace FileSys
SERIALIZE_EXPORT_IMPL(FileSys::SDMCWriteOnlyDelayGenerator)

View File

@ -72,7 +72,10 @@ private:
friend class boost::serialization::access;
};
class SDMCWriteOnlyDelayGenerator;
} // namespace FileSys
BOOST_CLASS_EXPORT_KEY(FileSys::SDMCWriteOnlyArchive)
BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_SDMCWriteOnly)
BOOST_CLASS_EXPORT_KEY(FileSys::SDMCWriteOnlyDelayGenerator)

View File

@ -5,10 +5,18 @@
#pragma once
#include <cstddef>
#include <boost/serialization/access.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/export.hpp>
#include "common/common_types.h"
#define SERIALIZE_DELAY_GENERATOR \
private: \
template <class Archive> \
void serialize(Archive& ar, const unsigned int) { \
ar& boost::serialization::base_object<DelayGenerator>(*this); \
} \
friend class boost::serialization::access;
namespace FileSys {
class DelayGenerator {
@ -28,6 +36,8 @@ class DefaultDelayGenerator : public DelayGenerator {
public:
u64 GetReadDelayNs(std::size_t length) override;
u64 GetOpenDelayNs() override;
SERIALIZE_DELAY_GENERATOR
};
} // namespace FileSys

View File

@ -8,6 +8,8 @@
#include <memory>
#include <string>
#include <vector>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/unique_ptr.hpp>
#include "common/common_types.h"
#include "common/file_util.h"
#include "core/file_sys/archive_backend.h"
@ -43,6 +45,13 @@ public:
protected:
Mode mode;
std::unique_ptr<FileUtil::IOFile> file;
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<FileBackend>(*this);
ar& mode;
ar& file;
}
};
class DiskDirectory : public DirectoryBackend {

View File

@ -7,6 +7,8 @@
#include <algorithm>
#include <cstddef>
#include <memory>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/unique_ptr.hpp>
#include "common/common_types.h"
#include "core/hle/result.h"
#include "delay_generator.h"
@ -90,6 +92,12 @@ public:
protected:
std::unique_ptr<DelayGenerator> delay_generator;
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& delay_generator;
}
friend class boost::serialization::access;
};
} // namespace FileSys

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "common/archives.h"
#include "common/file_util.h"
#include "core/file_sys/disk_archive.h"
#include "core/file_sys/errors.h"
@ -33,6 +34,8 @@ public:
static constexpr u64 IPCDelayNanoseconds(269082);
return IPCDelayNanoseconds;
}
SERIALIZE_DELAY_GENERATOR
};
ResultVal<std::unique_ptr<FileBackend>> SaveDataArchive::OpenFile(const Path& path,
@ -353,3 +356,5 @@ u64 SaveDataArchive::GetFreeBytes() const {
}
} // namespace FileSys
SERIALIZE_EXPORT_IMPL(FileSys::SaveDataDelayGenerator)

View File

@ -40,4 +40,8 @@ protected:
std::string mount_point;
};
class SaveDataDelayGenerator;
} // namespace FileSys
BOOST_CLASS_EXPORT_KEY(FileSys::SaveDataDelayGenerator)

View File

@ -13,11 +13,7 @@ public:
CAM_Q();
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<Kernel::SessionRequestHandler>(*this);
}
friend class boost::serialization::access;
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::CAM

View File

@ -11,6 +11,9 @@ namespace Service::CFG {
class CFG_NOR final : public ServiceFramework<CFG_NOR> {
public:
CFG_NOR();
private:
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::CFG

View File

@ -14,11 +14,7 @@ public:
~DLP_CLNT() = default;
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<Kernel::SessionRequestHandler>(*this);
}
friend class boost::serialization::access;
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::DLP

View File

@ -14,11 +14,7 @@ public:
~DLP_FKCL() = default;
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<Kernel::SessionRequestHandler>(*this);
}
friend class boost::serialization::access;
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::DLP

View File

@ -16,11 +16,7 @@ public:
private:
void IsChild(Kernel::HLERequestContext& ctx);
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<Kernel::SessionRequestHandler>(*this);
}
friend class boost::serialization::access;
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::DLP

View File

@ -35,11 +35,7 @@ private:
Core::System& system;
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<Kernel::SessionRequestHandler>(*this);
}
friend class boost::serialization::access;
SERVICE_SERIALIZATION_SIMPLE
};
void InstallInterfaces(Core::System& system);

View File

@ -19,6 +19,17 @@ struct FileSessionSlot : public Kernel::SessionRequestHandler::SessionDataBase {
u64 offset; ///< Offset that this session will start reading from.
u64 size; ///< Max size of the file that this session is allowed to access
bool subfile; ///< Whether this file was opened via OpenSubFile or not.
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<Kernel::SessionRequestHandler::SessionDataBase>(
*this);
ar& priority;
ar& offset;
ar& size;
ar& subfile;
}
};
// TODO: File is not a real service, but it can still utilize ServiceFramework::RegisterHandlers.

View File

@ -26,6 +26,8 @@ struct ClientSlot : public Kernel::SessionRequestHandler::SessionDataBase {
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<Kernel::SessionRequestHandler::SessionDataBase>(
*this);
ar& program_id;
}
friend class boost::serialization::access;

View File

@ -203,6 +203,8 @@ public:
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<Kernel::SessionRequestHandler::SessionDataBase>(
*this);
ar& gsp;
ar& interrupt_event;
ar& thread_id;

View File

@ -240,6 +240,8 @@ struct SessionData : public Kernel::SessionRequestHandler::SessionDataBase {
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<Kernel::SessionRequestHandler::SessionDataBase>(
*this);
ar& current_http_context;
ar& session_id;
ar& num_http_contexts;

View File

@ -18,6 +18,8 @@ struct ClientSlot : public Kernel::SessionRequestHandler::SessionDataBase {
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<Kernel::SessionRequestHandler::SessionDataBase>(
*this);
ar& loaded_crs;
}
friend class boost::serialization::access;

View File

@ -25,6 +25,7 @@ namespace Service::MIC {
template <class Archive>
void MIC_U::serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<Kernel::SessionRequestHandler>(*this);
ar&* impl.get();
}
SERIALIZE_IMPL(MIC_U)

View File

@ -14,11 +14,7 @@ public:
~MVD_STD() = default;
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<Kernel::SessionRequestHandler>(*this);
}
friend class boost::serialization::access;
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::MVD

View File

@ -24,6 +24,8 @@ private:
* 2 : Number of notifications
*/
void GetTotalNotifications(Kernel::HLERequestContext& ctx);
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::NEWS

View File

@ -12,6 +12,9 @@ namespace Service::NEWS {
class NEWS_U final : public ServiceFramework<NEWS_U> {
public:
NEWS_U();
private:
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::NEWS

View File

@ -12,6 +12,9 @@ class NIM_AOC final : public ServiceFramework<NIM_AOC> {
public:
NIM_AOC();
~NIM_AOC();
private:
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::NIM

View File

@ -12,6 +12,9 @@ class NIM_S final : public ServiceFramework<NIM_S> {
public:
NIM_S();
~NIM_S();
private:
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::NIM

View File

@ -11,6 +11,9 @@ namespace Service::NWM {
class NWM_CEC final : public ServiceFramework<NWM_CEC> {
public:
NWM_CEC();
private:
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::NWM

View File

@ -11,6 +11,9 @@ namespace Service::NWM {
class NWM_EXT final : public ServiceFramework<NWM_EXT> {
public:
NWM_EXT();
private:
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::NWM

View File

@ -11,6 +11,9 @@ namespace Service::NWM {
class NWM_INF final : public ServiceFramework<NWM_INF> {
public:
NWM_INF();
private:
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::NWM

View File

@ -11,6 +11,9 @@ namespace Service::NWM {
class NWM_SAP final : public ServiceFramework<NWM_SAP> {
public:
NWM_SAP();
private:
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::NWM

View File

@ -11,6 +11,9 @@ namespace Service::NWM {
class NWM_SOC final : public ServiceFramework<NWM_SOC> {
public:
NWM_SOC();
private:
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::NWM

View File

@ -11,6 +11,9 @@ namespace Service::NWM {
class NWM_TST final : public ServiceFramework<NWM_TST> {
public:
NWM_TST();
private:
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::NWM

View File

@ -28,6 +28,7 @@ namespace Service::NWM {
template <class Archive>
void NWM_UDS::serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<Kernel::SessionRequestHandler>(*this);
ar& node_map;
ar& connection_event;
ar& received_beacons;

View File

@ -12,6 +12,9 @@ class PM_APP final : public ServiceFramework<PM_APP> {
public:
PM_APP();
~PM_APP() = default;
private:
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::PM

View File

@ -12,6 +12,9 @@ class PM_DBG final : public ServiceFramework<PM_DBG> {
public:
PM_DBG();
~PM_DBG() = default;
private:
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::PM

View File

@ -18,6 +18,8 @@ public:
~PS_PS() = default;
private:
SERVICE_SERIALIZATION_SIMPLE
/**
* PS_PS::SignRsaSha256 service function
* Inputs:

View File

@ -13,6 +13,9 @@ class DEV final : public ServiceFramework<DEV> {
public:
DEV();
~DEV();
private:
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::PXI

View File

@ -12,6 +12,9 @@ class QTM_C final : public ServiceFramework<QTM_C> {
public:
QTM_C();
~QTM_C() = default;
private:
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::QTM

View File

@ -12,6 +12,9 @@ class QTM_S final : public ServiceFramework<QTM_S> {
public:
QTM_S();
~QTM_S() = default;
private:
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::QTM

View File

@ -12,6 +12,9 @@ class QTM_SP final : public ServiceFramework<QTM_SP> {
public:
QTM_SP();
~QTM_SP() = default;
private:
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::QTM

View File

@ -12,6 +12,9 @@ class QTM_U final : public ServiceFramework<QTM_U> {
public:
QTM_U();
~QTM_U() = default;
private:
SERVICE_SERIALIZATION_SIMPLE
};
} // namespace Service::QTM

View File

@ -219,6 +219,13 @@ extern const std::array<ServiceModuleInfo, 40> service_module_map;
friend class boost::serialization::access; \
friend class ::construct_access;
#define SERVICE_SERIALIZATION_SIMPLE \
template <class Archive> \
void serialize(Archive& ar, const unsigned int) { \
ar& boost::serialization::base_object<Kernel::SessionRequestHandler>(*this); \
} \
friend class boost::serialization::access;
#define SERVICE_CONSTRUCT(T) \
namespace boost::serialization { \
template <class Archive> \

View File

@ -23,6 +23,8 @@ private:
// TODO: Implement a proper CSPRNG in the future when actual security is needed
std::mt19937 rand_gen;
SERVICE_SERIALIZATION_SIMPLE
};
void InstallInterfaces(Core::System& system);

View File

@ -20,6 +20,7 @@ namespace Service::Y2R {
template <class Archive>
void Y2R_U::serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<Kernel::SessionRequestHandler>(*this);
ar& completion_event;
ar& conversion;
ar& dithering_weight_params;

View File

@ -170,7 +170,9 @@ private:
MemorySystem::Impl& impl;
template <class Archive>
void serialize(Archive& ar, const unsigned int) {}
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<BackingMem>(*this);
}
friend class boost::serialization::access;
};