diff --git a/Sources/Plasma/CoreLib/hsThread.h b/Sources/Plasma/CoreLib/hsThread.h index bcd64c6ba3..1ea216d656 100644 --- a/Sources/Plasma/CoreLib/hsThread.h +++ b/Sources/Plasma/CoreLib/hsThread.h @@ -43,11 +43,14 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define hsThread_Defined #include "HeadSpin.h" +#include "hsLockGuard.h" + #include -#include #include +#include #include -#include "hsLockGuard.h" + +#include typedef uint32_t hsMilliseconds; @@ -153,7 +156,7 @@ class hsGlobalSemaphore { #endif #endif public: - hsGlobalSemaphore(int initialValue = 0, const char* name = nullptr); + hsGlobalSemaphore(int initialValue = 0, const ST::string& name = {}); ~hsGlobalSemaphore(); #ifdef HS_BUILD_FOR_WIN32 diff --git a/Sources/Plasma/CoreLib/hsThread_Unix.cpp b/Sources/Plasma/CoreLib/hsThread_Unix.cpp index 3b25b5fe54..4bd0febafb 100644 --- a/Sources/Plasma/CoreLib/hsThread_Unix.cpp +++ b/Sources/Plasma/CoreLib/hsThread_Unix.cpp @@ -72,14 +72,14 @@ int clock_gettime(int clocktype, struct timespec* ts) ///////////////////////////////////////////////////////////////////////////// -hsGlobalSemaphore::hsGlobalSemaphore(int initialValue, const char* name) +hsGlobalSemaphore::hsGlobalSemaphore(int initialValue, const ST::string& name) { #ifdef USE_SEMA fPSema = nullptr; - fNamed = (name != nullptr); + fNamed = !name.empty(); if (fNamed) { /* Named semaphore shared between processes */ - fPSema = sem_open(name, O_CREAT, 0666, initialValue); + fPSema = sem_open(name.c_str(), O_CREAT, 0666, initialValue); if (fPSema == SEM_FAILED) { hsAssert(0, "hsOSException"); diff --git a/Sources/Plasma/CoreLib/hsThread_Win.cpp b/Sources/Plasma/CoreLib/hsThread_Win.cpp index 31237010ef..c34f2dbe5a 100644 --- a/Sources/Plasma/CoreLib/hsThread_Win.cpp +++ b/Sources/Plasma/CoreLib/hsThread_Win.cpp @@ -46,9 +46,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsThread.h" #include "hsExceptions.h" -hsGlobalSemaphore::hsGlobalSemaphore(int initialValue, const char *name) +hsGlobalSemaphore::hsGlobalSemaphore(int initialValue, const ST::string& name) { - fSemaH = ::CreateSemaphore(nullptr, initialValue, kPosInfinity32, name); + fSemaH = ::CreateSemaphoreW(nullptr, initialValue, kPosInfinity32, name.to_wchar().data()); if (fSemaH == nullptr) throw hsOSException(-1); } diff --git a/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashBase.cpp b/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashBase.cpp index 7a0f737bd8..eb87ded4ad 100644 --- a/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashBase.cpp +++ b/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashBase.cpp @@ -43,18 +43,16 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plCrashBase.h" #include "plCrash_Private.h" +#include + plCrashBase::~plCrashBase() { delete fCrashed; delete fHandled; } -void plCrashBase::IInit(const char* file) +void plCrashBase::IInit(const ST::string& file) { - char sema[128]; - snprintf(sema, std::size(sema), "%s-%s", file, CRASH_NOTIFY_SUFFIX); - fCrashed = new hsGlobalSemaphore(0, sema); - - snprintf(sema, std::size(sema), "%s-%s", file, CRASH_HANDLE_SUFFIX); - fHandled = new hsGlobalSemaphore(0, sema); + fCrashed = new hsGlobalSemaphore(0, ST::format("{}-{}", file, CRASH_NOTIFY_SUFFIX)); + fHandled = new hsGlobalSemaphore(0, ST::format("{}-{}", file, CRASH_HANDLE_SUFFIX)); } diff --git a/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashBase.h b/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashBase.h index a480f7ead0..7207f65ac3 100644 --- a/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashBase.h +++ b/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashBase.h @@ -45,6 +45,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsThread.h" +namespace ST { class string; } + class plCrashBase { protected: @@ -52,7 +54,7 @@ class plCrashBase hsGlobalSemaphore* fHandled; ~plCrashBase(); - void IInit(const char* file); + void IInit(const ST::string& file); }; #endif // _pfCrashBase_h_ diff --git a/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashCli.cpp b/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashCli.cpp index 851d1f9c57..22d1a40c44 100644 --- a/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashCli.cpp +++ b/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashCli.cpp @@ -43,6 +43,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plCrashCli.h" #include "plCrash_Private.h" +#include + #ifdef HS_BUILD_FOR_WIN32 #ifdef _MSC_VER @@ -63,17 +65,15 @@ static void IPureVirtualCall() plCrashCli::plCrashCli() : fLink(), fLinkH() { - char mapname[128]; - char cmdline[128]; - snprintf(mapname, std::size(mapname), "Plasma20CrashHandler-%u", GetCurrentProcessId()); - snprintf(cmdline, std::size(cmdline), "%s %s", CRASH_HANDLER_EXE, mapname); + ST::string mapname = ST::format("Plasma20CrashHandler-{}", GetCurrentProcessId()); + ST::string cmdline = ST::format("{} {}", CRASH_HANDLER_EXE, mapname); memset(&fCrashSrv, 0, sizeof(PROCESS_INFORMATION)); // Initialize the semas IInit(mapname); // Initialize the shared memory - fLinkH = CreateFileMappingA(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, sizeof(plCrashMemLink), mapname); + fLinkH = CreateFileMappingW(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, sizeof(plCrashMemLink), mapname.to_wchar().data()); hsAssert(fLinkH, "Failed to create plCrashHandler mapping"); if (!fLinkH) return; @@ -87,11 +87,11 @@ plCrashCli::plCrashCli() fLink->fClientProcessID = GetCurrentProcessId(); // Start the plCrashHandler before a crash - STARTUPINFOA info; memset(&info, 0, sizeof(info)); - info.cb = sizeof(STARTUPINFOA); - CreateProcessA( - CRASH_HANDLER_EXE, // plCrashHandler.exe - cmdline, // plCrashHandler.exe Plasma20CrashHandler-%u + STARTUPINFOW info{}; + info.cb = sizeof(info); + CreateProcessW( + CRASH_HANDLER_EXE.data(), // plCrashHandler.exe + cmdline.to_wchar().data(), // plCrashHandler.exe Plasma20CrashHandler-%u nullptr, nullptr, FALSE, diff --git a/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp b/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp index 0a3dcd4f7a..7b9f54cb17 100644 --- a/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp +++ b/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp @@ -50,14 +50,14 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include -plCrashSrv::plCrashSrv(const char* file) +plCrashSrv::plCrashSrv(const ST::string& file) : fLink(), fLinkH() { // Init semas IInit(file); // Open the linked memory - fLinkH = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, file); + fLinkH = OpenFileMappingW(FILE_MAP_ALL_ACCESS, FALSE, file.to_wchar().data()); hsAssert(fLinkH, "Failed to open plCrashHandler mapping"); if (!fLinkH) return; @@ -87,7 +87,7 @@ void plCrashSrv::IHandleCrash() nullptr ); - MINIDUMP_EXCEPTION_INFORMATION e; + MINIDUMP_EXCEPTION_INFORMATION e{}; e.ClientPointers = TRUE; e.ExceptionPointers = fLink->fExceptionPtrs; e.ThreadId = fLink->fClientThreadID; diff --git a/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.h b/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.h index b8c5f8b4a7..2d42650001 100644 --- a/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.h +++ b/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.h @@ -59,7 +59,7 @@ class plCrashSrv : public plCrashBase void IHandleCrash(); public: - plCrashSrv(const char* file); + plCrashSrv(const ST::string& file); ~plCrashSrv(); void HandleCrash(); diff --git a/Sources/Plasma/FeatureLib/pfCrashHandler/plCrash_Private.h b/Sources/Plasma/FeatureLib/pfCrashHandler/plCrash_Private.h index 4274234a51..e928c47dcd 100644 --- a/Sources/Plasma/FeatureLib/pfCrashHandler/plCrash_Private.h +++ b/Sources/Plasma/FeatureLib/pfCrashHandler/plCrash_Private.h @@ -46,14 +46,16 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" #include "hsWindows.h" -#define CRASH_NOTIFY_SUFFIX "CrashNotify" -#define CRASH_HANDLE_SUFFIX "CrashHandled" +#include + +constexpr std::string_view CRASH_NOTIFY_SUFFIX = "CrashNotify"; +constexpr std::string_view CRASH_HANDLE_SUFFIX = "CrashHandled"; #ifdef HS_BUILD_FOR_WIN32 # ifdef PLASMA_EXTERNAL_RELEASE -# define CRASH_HANDLER_EXE "UruCrashHandler.exe" + constexpr std::wstring_view CRASH_HANDLER_EXE = L"UruCrashHandler.exe"; # else -# define CRASH_HANDLER_EXE "plCrashHandler.exe" + constexpr std::wstring_view CRASH_HANDLER_EXE = L"plCrashHandler.exe"; # endif // PLASMA_EXTERNAL_RELEASE #endif // HS_BUILD_FOR_WIN32