1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-25 12:12:50 +01:00

fixed_typemap.hpp: make it a bit fool-proof

Require objects to be non-copyable (move is still allowed).
This commit is contained in:
Nekotekina 2021-03-02 19:22:39 +03:00
parent 004ebfdaee
commit 52fe86b56c
19 changed files with 121 additions and 57 deletions

View File

@ -89,6 +89,10 @@ public:
patch_engine();
patch_engine(const patch_engine&) = delete;
patch_engine& operator=(const patch_engine&) = delete;
// Returns the directory in which patch_config.yml is located
static std::string get_patch_config_path();

View File

@ -22,6 +22,9 @@ public:
statichle_handler(int);
~statichle_handler();
statichle_handler(const statichle_handler&) = delete;
statichle_handler& operator=(const statichle_handler&) = delete;
bool load_patterns();
bool check_against_patterns(vm::cptr<u8>& data, u32 size, u32 addr);

View File

@ -38,7 +38,12 @@ struct avconf_manager
std::vector<CellAudioInDeviceInfo> devices;
void copy_device_info(u32 num, vm::ptr<CellAudioInDeviceInfo> info);
avconf_manager();
avconf_manager(const avconf_manager&) = delete;
avconf_manager& operator=(const avconf_manager&) = delete;
};
avconf_manager::avconf_manager()

View File

@ -938,6 +938,8 @@ struct fs_aio_thread : ppu_thread
struct fs_aio_manager
{
std::shared_ptr<fs_aio_thread> thread;
shared_mutex mutex;
};
s32 cellFsAioInit(vm::cptr<char> mount_point)

View File

@ -63,8 +63,10 @@ void fmt_class_string<CellMusic2Error>::format(std::string& out, u64 arg)
struct music_state
{
vm::ptr<void(u32 event, vm::ptr<void> param, vm::ptr<void> userData)> func;
vm::ptr<void> userData;
shared_mutex mutex;
vm::ptr<void(u32 event, vm::ptr<void> param, vm::ptr<void> userData)> func{};
vm::ptr<void> userData{};
};
error_code cellMusicGetSelectionContext(vm::ptr<CellMusicSelectionContext> context)

View File

@ -85,14 +85,18 @@ using CellMusicDecode2Callback = void(u32, vm::ptr<void> param, vm::ptr<void> us
struct music_decode
{
vm::ptr<CellMusicDecodeCallback> func;
vm::ptr<void> userData;
vm::ptr<CellMusicDecodeCallback> func{};
vm::ptr<void> userData{};
shared_mutex mutex;
};
struct music_decode2
{
vm::ptr<CellMusicDecode2Callback> func;
vm::ptr<void> userData;
vm::ptr<CellMusicDecode2Callback> func{};
vm::ptr<void> userData{};
shared_mutex mutex;
};
error_code cellMusicDecodeInitialize(s32 mode, u32 container, s32 spuPriority, vm::ptr<CellMusicDecodeCallback> func, vm::ptr<void> userData)

View File

@ -58,8 +58,10 @@ using CellRecCallback = void(s32 recStatus, s32 recError, vm::ptr<void> userdata
struct rec_info
{
vm::ptr<CellRecCallback> cb;
vm::ptr<void> cbUserData;
vm::ptr<CellRecCallback> cb{};
vm::ptr<void> cbUserData{};
shared_mutex mutex;
};
error_code cellRecOpen(vm::cptr<char> pDirName, vm::cptr<char> pFileName, vm::cptr<CellRecParam> pParam, u32 container, vm::ptr<CellRecCallback> cb, vm::ptr<void> cbUserData)

View File

@ -65,7 +65,9 @@ struct rudp_info
// event handler function
vm::ptr<CellRudpEventHandler> handler = vm::null;
vm::ptr<void> handler_arg;
vm::ptr<void> handler_arg{};
shared_mutex mutex;
};
error_code cellRudpInit(vm::ptr<CellRudpAllocator> allocator)

View File

@ -26,14 +26,12 @@ void fmt_class_string<CellScreenShotError>::format(std::string& out, u64 arg)
});
}
shared_mutex screenshot_mtx;
std::string screenshot_manager::get_overlay_path() const
std::string screenshot_info::get_overlay_path() const
{
return vfs::get(overlay_dir_name + "/" + overlay_file_name);
}
std::string screenshot_manager::get_photo_title() const
std::string screenshot_info::get_photo_title() const
{
std::string photo = photo_title;
if (photo.empty())
@ -41,7 +39,7 @@ std::string screenshot_manager::get_photo_title() const
return photo;
}
std::string screenshot_manager::get_game_title() const
std::string screenshot_info::get_game_title() const
{
std::string game = game_title;
if (game.empty())
@ -49,12 +47,12 @@ std::string screenshot_manager::get_game_title() const
return game;
}
std::string screenshot_manager::get_game_comment() const
std::string screenshot_info::get_game_comment() const
{
return game_comment;
}
std::string screenshot_manager::get_screenshot_path(const std::string& date_path) const
std::string screenshot_info::get_screenshot_path(const std::string& date_path) const
{
u32 counter = 0;
std::string path = vfs::get("/dev_hdd0/photo/" + date_path + "/" + get_photo_title());
@ -86,7 +84,7 @@ error_code cellScreenShotSetParameter(vm::cptr<CellScreenShotSetParam> param)
return CELL_SCREENSHOT_ERROR_PARAM;
auto& manager = g_fxo->get<screenshot_manager>();
std::lock_guard lock(screenshot_mtx);
std::lock_guard lock(manager.mutex);
if (param->photo_title && param->photo_title[0] != '\0')
manager.photo_title = std::string(param->photo_title.get_ptr());
@ -124,7 +122,7 @@ error_code cellScreenShotSetOverlayImage(vm::cptr<char> srcDir, vm::cptr<char> s
}
auto& manager = g_fxo->get<screenshot_manager>();
std::lock_guard lock(screenshot_mtx);
std::lock_guard lock(manager.mutex);
manager.overlay_dir_name = std::string(srcDir.get_ptr());
manager.overlay_file_name = std::string(srcFile.get_ptr());
@ -139,7 +137,7 @@ error_code cellScreenShotEnable()
cellScreenshot.warning("cellScreenShotEnable()");
auto& manager = g_fxo->get<screenshot_manager>();
std::lock_guard lock(screenshot_mtx);
std::lock_guard lock(manager.mutex);
manager.is_enabled = true;
@ -151,7 +149,7 @@ error_code cellScreenShotDisable()
cellScreenshot.warning("cellScreenShotDisable()");
auto& manager = g_fxo->get<screenshot_manager>();
std::lock_guard lock(screenshot_mtx);
std::lock_guard lock(manager.mutex);
manager.is_enabled = false;

View File

@ -27,9 +27,7 @@ struct CellScreenShotSetParam
vm::bptr<void> reserved;
};
extern shared_mutex screenshot_mtx;
struct screenshot_manager
struct screenshot_info
{
bool is_enabled{false};
@ -48,3 +46,8 @@ struct screenshot_manager
std::string get_game_comment() const;
std::string get_screenshot_path(const std::string& date_path) const;
};
struct screenshot_manager : public screenshot_info
{
shared_mutex mutex;
};

View File

@ -55,7 +55,6 @@ void fmt_class_string<CellSearchError>::format(std::string& out, u64 arg)
});
}
namespace {
enum class search_state
{
not_initialized = 0,
@ -94,8 +93,14 @@ struct search_content_t
} data;
};
using ContentIdType = std::pair<u64, std::shared_ptr<search_content_t>>;
using ContentIdMap = std::unordered_map<u64, std::shared_ptr<search_content_t>>;
using content_id_type = std::pair<u64, std::shared_ptr<search_content_t>>;
struct content_id_map
{
std::unordered_map<u64, std::shared_ptr<search_content_t>> map;
shared_mutex mutex;
};
struct search_object_t
{
@ -103,11 +108,10 @@ struct search_object_t
static const u32 id_base = 1;
static const u32 id_step = 1;
static const u32 id_count = 1024; // TODO
static const u32 invalid = 0xFFFFFFFF;
std::vector<ContentIdType> content_ids;
std::vector<content_id_type> content_ids;
};
}
error_code cellSearchInitialize(CellSearchMode mode, u32 container, vm::ptr<CellSearchSystemCallback> func, vm::ptr<void> userData)
{
cellSearch.warning("cellSearchInitialize(mode=0x%x, container=0x%x, func=*0x%x, userData=*0x%x)", +mode, container, func, userData);
@ -242,7 +246,7 @@ error_code cellSearchStartListSearch(CellSearchListSearchType type, CellSearchSo
const u32 id = *outSearchId = idm::make<search_object_t>();
sysutil_register_cb([=, &content_map = g_fxo->get<ContentIdMap>(), &search](ppu_thread& ppu) -> s32
sysutil_register_cb([=, &content_map = g_fxo->get<content_id_map>(), &search](ppu_thread& ppu) -> s32
{
auto curr_search = idm::get<search_object_t>(id);
vm::var<CellSearchResultParam> resultParam;
@ -320,8 +324,8 @@ error_code cellSearchStartListSearch(CellSearchListSearchType type, CellSearchSo
}
const u64 hash = std::hash<std::string>()(item_path);
auto found = content_map.find(hash);
if (found == content_map.end()) // content isn't yet being tracked
auto found = content_map.map.find(hash);
if (found == content_map.map.end()) // content isn't yet being tracked
{
//auto ext_offset = item.name.find_last_of('.'); // used later if no "Title" found
@ -391,7 +395,7 @@ error_code cellSearchStartListSearch(CellSearchListSearchType type, CellSearchSo
}
}
content_map.emplace(hash, curr_find);
content_map.map.emplace(hash, curr_find);
curr_search->content_ids.emplace_back(hash, curr_find); // place this file's "ID" into the list of found types
cellSearch.notice("cellSearchStartListSearch(): Content ID: %08X Path: \"%s\"", hash, item_path);
@ -467,9 +471,9 @@ error_code cellSearchStartContentSearchInList(vm::cptr<CellSearchContentId> list
return CELL_SEARCH_ERROR_GENERIC;
}
auto& content_map = g_fxo->get<ContentIdMap>();
auto found = content_map.find(*reinterpret_cast<const u64*>(listId->data));
if (found == content_map.end())
auto& content_map = g_fxo->get<content_id_map>();
auto found = content_map.map.find(*reinterpret_cast<const u64*>(listId->data));
if (found == content_map.map.end())
{
// content ID not found, perform a search first
return CELL_SEARCH_ERROR_CONTENT_NOT_FOUND;
@ -553,8 +557,8 @@ error_code cellSearchStartContentSearchInList(vm::cptr<CellSearchContentId> list
const std::string item_path(vpath + "/" + item.name);
const u64 hash = std::hash<std::string>()(item_path);
auto found = content_map.find(hash);
if (found == content_map.end()) // content isn't yet being tracked
auto found = content_map.map.find(hash);
if (found == content_map.map.end()) // content isn't yet being tracked
{
auto ext_offset = item.name.find_last_of('.'); // used later if no "Title" found
@ -783,7 +787,7 @@ error_code cellSearchStartContentSearchInList(vm::cptr<CellSearchContentId> list
strcpy_trunc(info.albumTitle, "ALBUM TITLE");
}
content_map.emplace(hash, curr_find);
content_map.map.emplace(hash, curr_find);
curr_search->content_ids.emplace_back(hash, curr_find); // place this file's "ID" into the list of found types
cellSearch.notice("cellSearchStartContentSearchInList(): Content ID: %08X Path: \"%s\"", hash, item_path);
@ -871,7 +875,7 @@ error_code cellSearchStartContentSearch(CellSearchContentSearchType type, CellSe
const u32 id = *outSearchId = idm::make<search_object_t>();
sysutil_register_cb([=, &content_map = g_fxo->get<ContentIdMap>(), &search](ppu_thread& ppu) -> s32
sysutil_register_cb([=, &content_map = g_fxo->get<content_id_map>(), &search](ppu_thread& ppu) -> s32
{
auto curr_search = idm::get<search_object_t>(id);
vm::var<CellSearchResultParam> resultParam;
@ -906,8 +910,8 @@ error_code cellSearchStartContentSearch(CellSearchContentSearchType type, CellSe
const std::string item_path(relative_vpath + "/" + item.name);
const u64 hash = std::hash<std::string>()(item_path);
auto found = content_map.find(hash);
if (found == content_map.end()) // content isn't yet being tracked
auto found = content_map.map.find(hash);
if (found == content_map.map.end()) // content isn't yet being tracked
{
auto ext_offset = item.name.find_last_of('.'); // used later if no "Title" found
@ -985,7 +989,7 @@ error_code cellSearchStartContentSearch(CellSearchContentSearchType type, CellSe
strcpy_trunc(info.albumTitle, "ALBUM TITLE");
}
content_map.emplace(hash, curr_find);
content_map.map.emplace(hash, curr_find);
curr_search->content_ids.emplace_back(hash, curr_find); // place this file's "ID" into the list of found types
cellSearch.notice("cellSearchStartContentSearch(): Content ID: %08X Path: \"%s\"", hash, item_path);
@ -1228,9 +1232,9 @@ error_code cellSearchGetContentInfoByContentId(vm::cptr<CellSearchContentId> con
return CELL_SEARCH_ERROR_GENERIC;
}
auto& content_map = g_fxo->get<ContentIdMap>();
auto found = content_map.find(*reinterpret_cast<const u64*>(contentId->data));
if (found != content_map.end())
auto& content_map = g_fxo->get<content_id_map>();
auto found = content_map.map.find(*reinterpret_cast<const u64*>(contentId->data));
if (found != content_map.map.end())
{
const auto& content_info = found->second;
switch (content_info->type)
@ -1439,9 +1443,9 @@ error_code cellSearchGetContentInfoPath(vm::cptr<CellSearchContentId> contentId,
}
const u64 id = *reinterpret_cast<const u64*>(contentId->data);
auto& content_map = g_fxo->get<ContentIdMap>();
auto found = content_map.find(id);
if(found != content_map.end())
auto& content_map = g_fxo->get<content_id_map>();
auto found = content_map.map.find(id);
if(found != content_map.map.end())
{
std::memcpy(infoPath.get_ptr(), &found->second->infoPath, sizeof(found->second->infoPath));
}

View File

@ -8,8 +8,10 @@ LOG_CHANNEL(cellSysutil);
struct browser_info
{
vm::ptr<CellWebBrowserSystemCallback> system_cb;
vm::ptr<void> userData;
vm::ptr<CellWebBrowserSystemCallback> system_cb{};
vm::ptr<void> userData{};
shared_mutex mutex;
};
error_code cellWebBrowserActivate()

View File

@ -69,6 +69,16 @@ struct ppu_segment
// PPU Module Information
struct ppu_module
{
ppu_module() = default;
ppu_module(const ppu_module&) = delete;
ppu_module(ppu_module&&) = default;
ppu_module& operator=(const ppu_module&) = delete;
ppu_module& operator=(ppu_module&&) = default;
uchar sha1[20]{};
std::string name;
std::string path;

View File

@ -101,6 +101,12 @@ const ppu_static_module* ppu_module_manager::get_module(const std::string& name)
// Global linkage information
struct ppu_linkage_info
{
ppu_linkage_info() = default;
ppu_linkage_info(const ppu_linkage_info&) = delete;
ppu_linkage_info& operator=(const ppu_linkage_info&) = delete;
struct module_data
{
struct info

View File

@ -2597,6 +2597,13 @@ extern void ppu_initialize()
}
}
struct ppu_toc_manager
{
std::unordered_map<u32, u32> toc_map;
shared_mutex mutex;
};
bool ppu_initialize(const ppu_module& info, bool check_only)
{
if (g_cfg.core.ppu_decoder != ppu_decoder_type::llvm)
@ -2607,7 +2614,7 @@ bool ppu_initialize(const ppu_module& info, bool check_only)
}
// Temporarily
s_ppu_toc = &g_fxo->get<std::unordered_map<u32, u32>>();
s_ppu_toc = &g_fxo->get<ppu_toc_manager>().toc_map;
for (const auto& func : info.funcs)
{
@ -2994,7 +3001,7 @@ bool ppu_initialize(const ppu_module& info, bool check_only)
}
// Keep allocating workload
const auto [obj_name, part] = std::as_const(workload)[i];
const auto& [obj_name, part] = std::as_const(workload)[i];
// Allocate "core"
std::lock_guard jlock(g_fxo->get<jit_core_allocator>().sem);

View File

@ -1665,6 +1665,12 @@ void spu_thread::cpu_task()
struct raw_spu_cleanup
{
raw_spu_cleanup() = default;
raw_spu_cleanup(const raw_spu_cleanup&) = delete;
raw_spu_cleanup& operator =(const raw_spu_cleanup&) = delete;
~raw_spu_cleanup()
{
std::memset(spu_thread::g_raw_spu_id, 0, sizeof(spu_thread::g_raw_spu_id));

View File

@ -17,6 +17,8 @@ class pad_thread
{
public:
pad_thread(void* _curthread, void* _curwindow, std::string_view title_id); // void * instead of QThread * and QWindow * because of include in emucore
pad_thread(const pad_thread&) = delete;
pad_thread& operator=(const pad_thread&) = delete;
~pad_thread();
PadInfo& GetInfo() { return m_info; }

View File

@ -481,11 +481,11 @@ void gs_frame::take_screenshot(const std::vector<u8> sshot_data, const u32 sshot
}
}
screenshot_manager manager;
screenshot_info manager;
{
auto& fxo = g_fxo->get<screenshot_manager>();
std::lock_guard lock(screenshot_mtx);
manager = fxo;
auto& s = g_fxo->get<screenshot_manager>();
std::lock_guard lock(s.mutex);
manager = s;
}
struct scoped_png_ptrs

View File

@ -49,6 +49,8 @@ namespace stx
template <typename T>
static typeinfo make_typeinfo()
{
static_assert(!std::is_copy_assignable_v<T> && !std::is_copy_constructible_v<T>, "Please make sure the object cannot be accidentally copied.");
typeinfo r;
r.create = &call_ctor<T>;
r.destroy = &call_dtor<T>;