Skip to content

Commit

Permalink
fixed_typemap.hpp: make it a bit fool-proof
Browse files Browse the repository at this point in the history
Require objects to be non-copyable (move is still allowed).
  • Loading branch information
Nekotekina committed Mar 2, 2021
1 parent d0edd44 commit 24b158c
Show file tree
Hide file tree
Showing 19 changed files with 121 additions and 57 deletions.
4 changes: 4 additions & 0 deletions Utilities/bin_patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class patch_engine

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();

Expand Down
3 changes: 3 additions & 0 deletions rpcs3/Emu/Cell/Modules/StaticHLE.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class statichle_handler
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);

Expand Down
5 changes: 5 additions & 0 deletions rpcs3/Emu/Cell/Modules/cellAvconfExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions rpcs3/Emu/Cell/Modules/cellFs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions rpcs3/Emu/Cell/Modules/cellMusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions rpcs3/Emu/Cell/Modules/cellMusicDecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions rpcs3/Emu/Cell/Modules/cellRec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion rpcs3/Emu/Cell/Modules/cellRudp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 9 additions & 11 deletions rpcs3/Emu/Cell/Modules/cellScreenshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,33 @@ 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())
photo = Emu.GetTitle();
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())
game = Emu.GetTitle();
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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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;

Expand All @@ -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;

Expand Down
9 changes: 6 additions & 3 deletions rpcs3/Emu/Cell/Modules/cellScreenshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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;
};
56 changes: 30 additions & 26 deletions rpcs3/Emu/Cell/Modules/cellSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ void fmt_class_string<CellSearchError>::format(std::string& out, u64 arg)
});
}

namespace {
enum class search_state
{
not_initialized = 0,
Expand Down Expand Up @@ -94,20 +93,25 @@ 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
{
// TODO: Figured out the correct values to set here
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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}
Expand Down
6 changes: 4 additions & 2 deletions rpcs3/Emu/Cell/Modules/cellWebBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions rpcs3/Emu/Cell/PPUAnalyser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions rpcs3/Emu/Cell/PPUModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 24b158c

Please sign in to comment.