Skip to content

Commit eb90c9f

Browse files
committed
fix(callstack): Crash
1 parent d23aea8 commit eb90c9f

File tree

6 files changed

+27
-31
lines changed

6 files changed

+27
-31
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"typeindex": "cpp",
8080
"typeinfo": "cpp",
8181
"variant": "cpp",
82-
"expected": "cpp"
82+
"expected": "cpp",
83+
"shared_mutex": "cpp"
8384
}
8485
}

src/crashreporter/CallStack.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
#include "CallStack.h"
22
#include "../utils/utils.h"
33

4-
std::string CallStack::RegisterPluginCallstack(std::string plugin_name, std::string stackMsg)
4+
uint64_t stackID = 0;
5+
6+
uint64_t CallStack::RegisterPluginCallstack(std::string plugin_name, std::string stackMsg)
57
{
6-
std::string stackID = get_uuid();
78
if (callStacks.find(plugin_name) == callStacks.end())
89
callStacks.insert({ plugin_name, {} });
910

10-
while (callStacks[plugin_name].find(stackID) != callStacks[plugin_name].end())
11-
stackID = get_uuid();
12-
13-
callStacks[plugin_name].insert({ stackID, stackMsg });
11+
++stackID;
12+
if (stackID % 2000000000 == 0)
13+
stackID = 0;
1414

15+
callStacks[plugin_name].insert_or_assign(stackID, stackMsg);
1516
return stackID;
1617
}
17-
void CallStack::UnregisterPluginCallstack(std::string plugin_name, std::string stackID)
18+
19+
void CallStack::UnregisterPluginCallstack(std::string plugin_name, uint64_t stackID)
1820
{
1921
if (callStacks.find(plugin_name) == callStacks.end()) return;
2022
if (callStacks[plugin_name].find(stackID) == callStacks[plugin_name].end()) return;
2123

2224
callStacks[plugin_name].erase(stackID);
2325
}
2426

25-
std::unordered_map<std::string, std::string> CallStack::GetPluginCallstack(std::string plugin_name)
27+
std::unordered_map<uint64_t, std::string> CallStack::GetPluginCallstack(std::string plugin_name)
2628
{
2729
if (callStacks.find(plugin_name) == callStacks.end()) return {};
2830

src/crashreporter/CallStack.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
class CallStack
1212
{
1313
private:
14-
std::map<std::string, std::unordered_map<std::string, std::string>> callStacks;
14+
std::map<std::string, std::unordered_map<uint64_t, std::string>> callStacks;
1515
public:
1616
CallStack() = default;
1717

18-
std::string RegisterPluginCallstack(std::string plugin_name, std::string stackMsg);
19-
void UnregisterPluginCallstack(std::string plugin_name, std::string stackID);
18+
uint64_t RegisterPluginCallstack(std::string plugin_name, std::string stackMsg);
19+
void UnregisterPluginCallstack(std::string plugin_name, uint64_t stackID);
2020

21-
std::unordered_map<std::string, std::string> GetPluginCallstack(std::string plugin_name);
21+
std::unordered_map<uint64_t, std::string> GetPluginCallstack(std::string plugin_name);
2222
};
2323

2424
extern CallStack* g_callStack;

src/crashreporter/RegisterCallStack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class RegisterCallStack
77
{
88
private:
99
std::string plugin_name;
10-
std::string id;
10+
uint64_t id;
1111

1212
public:
1313
RegisterCallStack(std::string plugin_name, std::string stack_msg);

src/entrypoint.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ bool Swiftly::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen, bool
214214

215215
PRINT("Succesfully started.\n");
216216

217+
PRINTF("%s\n", get_uuid().c_str());
218+
217219
return true;
218220
}
219221

src/utils/utils.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -224,21 +224,12 @@ std::string str_toupper(std::string s)
224224

225225
std::string get_uuid()
226226
{
227-
static std::random_device dev;
228-
static std::mt19937 rng(dev());
229-
230-
std::uniform_int_distribution<int> dist(0, 15);
231-
232-
const char* v = "0123456789abcdef";
233-
const bool dash[] = { 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0 };
234-
235-
std::string res;
236-
for (int i = 0; i < 16; i++)
237-
{
238-
if (dash[i])
239-
res += "-";
240-
res += v[dist(rng)];
241-
res += v[dist(rng)];
242-
}
243-
return res;
227+
std::srand(std::time(nullptr));
228+
return string_format(
229+
"%x%x-%x-%x-%x-%x%x%x",
230+
(rand() & 0xFFFF), (rand() & 0xFFFF),
231+
(rand() & 0xFFFF),
232+
((rand() & 0x0fff) | 0x4000),
233+
(rand() % 0x3fff + 0x8000),
234+
(rand() & 0xFFFF), (rand() & 0xFFFF), (rand() & 0xFFFF));
244235
}

0 commit comments

Comments
 (0)