Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ST-ize pfCrashHandler. #1015

Merged
merged 2 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Sources/Plasma/CoreLib/hsThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <atomic>
#include <mutex>
#include <condition_variable>
#include <mutex>
#include <thread>
#include "hsLockGuard.h"

#include <string_theory/string>

typedef uint32_t hsMilliseconds;

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Sources/Plasma/CoreLib/hsThread_Unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions Sources/Plasma/CoreLib/hsThread_Win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 5 additions & 7 deletions Sources/Plasma/FeatureLib/pfCrashHandler/plCrashBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,16 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plCrashBase.h"
#include "plCrash_Private.h"

#include <string_theory/format>

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));
}
4 changes: 3 additions & 1 deletion Sources/Plasma/FeatureLib/pfCrashHandler/plCrashBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com

#include "hsThread.h"

namespace ST { class string; }

class plCrashBase
{
protected:
hsGlobalSemaphore* fCrashed;
hsGlobalSemaphore* fHandled;

~plCrashBase();
void IInit(const char* file);
void IInit(const ST::string& file);
};

#endif // _pfCrashBase_h_
20 changes: 10 additions & 10 deletions Sources/Plasma/FeatureLib/pfCrashHandler/plCrashCli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plCrashCli.h"
#include "plCrash_Private.h"

#include <string_theory/format>

#ifdef HS_BUILD_FOR_WIN32

#ifdef _MSC_VER
Expand All @@ -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;
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <dbghelp.h>
#include <shlobj.h>

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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class plCrashSrv : public plCrashBase
void IHandleCrash();

public:
plCrashSrv(const char* file);
plCrashSrv(const ST::string& file);
~plCrashSrv();

void HandleCrash();
Expand Down
10 changes: 6 additions & 4 deletions Sources/Plasma/FeatureLib/pfCrashHandler/plCrash_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string_view>

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

Expand Down