Skip to content

Commit a8d4790

Browse files
fix: remove HKCU creation for WER (#12)
* refactor: update windows.cpp * chore: update README.md * fix: update call to stack buffer overrun * chore: fix build complete message --------- Co-authored-by: Bobby Galli <bobbyg603@pm.me>
1 parent 59f8158 commit a8d4790

8 files changed

Lines changed: 72 additions & 71 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ This project demonstrates how to:
4747
1. Clone the depot_tools repository:
4848
4949
```bash
50-
# For Linux/macOS
5150
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
5251
```
5352

@@ -59,8 +58,9 @@ export PATH="$PATH:/path/to/depot_tools"
5958
```
6059

6160
```powershell
62-
# For Windows - add to system environment variables or use:
61+
# For Windows - add to system environment variables or use the following powershell commands:
6362
$env:Path = "C:\path\to\depot_tools;$env:Path"
63+
[Environment]::SetEnvironmentVariable("PATH", $env:PATH, "User")
6464
```
6565

6666
3. For Windows, you also need to run:

main.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,26 @@ bool initializeCrashpad(std::string dbName, std::string appName, std::string app
180180
);
181181

182182
#ifdef _WIN32
183-
// Set up WER integration if Crashpad initialization was successful
183+
// Set up Windows Error Reporting (WER) integration if Crashpad initialization was successful.
184+
//
185+
// REGISTRY REQUIREMENT:
186+
// WER integration requires a specific registry configuration in:
187+
// HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\RuntimeExceptionHelperModules
188+
//
189+
// IMPORTANT: Creating registry values in HKEY_LOCAL_MACHINE requires elevated privileges.
190+
// This configuration should typically be created by your installer or setup process.
191+
//
192+
// You must create a DWORD registry VALUE with:
193+
// Name: [full_path_to_crashpad_wer.dll]
194+
// Type: REG_DWORD
195+
// Data: 0 (value contents are ignored by WER)
196+
//
197+
// Example registry value:
198+
// Name: "C:\MyApp\bugsplat-crashpad\build\Debug\crashpad_wer.dll"
199+
// Type: REG_DWORD
200+
// Data: 0x00000000 (0)
201+
//
202+
// This configuration allows WER to delegate crash handling to your Crashpad handler.
184203
if (success) {
185204
setupWerIntegration(client, exeDir);
186205
}

scripts/build_linux.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ echo "Configuring with Debug symbols for better crash reporting..."
2323
cmake .. -DCMAKE_BUILD_TYPE=Debug
2424
make
2525

26-
echo "Build complete. Run the application with: ./Debug/MyCMakeCrasher"
26+
echo "Build complete. Run the application with: ./build/Debug/MyCMakeCrasher"
2727

2828
# Return to root directory
2929
cd ..

scripts/build_macos.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ echo "Configuring with Debug symbols for better crash reporting..."
3131
cmake .. -DCMAKE_BUILD_TYPE=Debug
3232
make
3333

34-
echo "Build complete. Run the application with: ./Debug/MyCMakeCrasher"
34+
echo "Build complete. Run the application with: ./build/Debug/MyCMakeCrasher"
3535

3636
# Verify dSYM bundles were created in the Debug directory
3737
if [ ! -d "Debug/MyCMakeCrasher.dSYM" ] || [ ! -d "Debug/libcrash.dylib.dSYM" ]; then

scripts/build_windows_msvc.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ cmake .. -DCMAKE_BUILD_TYPE=Debug
2626
# Build Debug configuration
2727
cmake --build . --config Debug
2828

29-
Write-Host "Build complete. Run the application with: Debug\MyCMakeCrasher.exe"
29+
Write-Host "Build complete. Run the application with: .\build\Debug\MyCMakeCrasher.exe"
3030

3131
# Return to root directory
3232
Set-Location -Path ".."

scripts/upload_symbols.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ $envFile = Join-Path $rootDir ".env"
99
if (Test-Path $envFile) {
1010
Write-Host "Loading environment from .env file..."
1111
Get-Content $envFile | ForEach-Object {
12-
if ($_ -match '(.+)=(.+)') {
13-
$key = $matches[1]
14-
$value = $matches[2]
12+
if ($_ -match '^\s*([^=\s]+)\s*=\s*(.*)$') {
13+
$key = $matches[1].Trim()
14+
$value = $matches[2].Trim()
15+
16+
# Remove surrounding quotes if present
17+
if ($value -match '^"(.*)"$' -or $value -match "^'(.*)'$") {
18+
$value = $matches[1]
19+
}
20+
1521
Set-Item -Path "Env:$key" -Value $value
1622
}
1723
}

windows.cpp

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,82 +6,66 @@
66
#include <windows.h>
77
#include <winreg.h>
88

9-
bool createWerRegistryKey(const std::string& dllPath) {
10-
const char* registryPath = "SOFTWARE\\Microsoft\\Windows\\Windows Error Reporting\\RuntimeExceptionHandlerModules";
11-
HKEY hKey;
12-
13-
// Open/create the registry key
14-
LONG result = RegCreateKeyExA(
15-
HKEY_CURRENT_USER,
16-
registryPath,
17-
0,
18-
NULL,
19-
REG_OPTION_NON_VOLATILE,
20-
KEY_WRITE,
21-
NULL,
22-
&hKey,
23-
NULL
24-
);
9+
BOOL DoesRegistryValueExist(HKEY hRootKey, LPCWSTR keyPath, LPCWSTR valueName)
10+
{
11+
HKEY hKey = NULL;
12+
LSTATUS result = RegOpenKeyExW(hRootKey, keyPath, 0, KEY_READ, &hKey);
2513

2614
if (result != ERROR_SUCCESS) {
27-
std::cerr << "Failed to open/create WER registry key. Error: " << result << std::endl;
28-
return false;
15+
return FALSE; // Key doesn't exist
2916
}
3017

31-
// Set the DLL path as a DWORD value with data 0x0
32-
DWORD value = 0x0;
33-
result = RegSetValueExA(
34-
hKey,
35-
dllPath.c_str(), // Value name is the full DLL path
36-
0,
37-
REG_DWORD,
38-
reinterpret_cast<const BYTE*>(&value),
39-
sizeof(DWORD)
40-
);
41-
18+
// Check if the specific value exists
19+
result = RegQueryValueExW(hKey, valueName, NULL, NULL, NULL, NULL);
4220
RegCloseKey(hKey);
4321

44-
if (result != ERROR_SUCCESS) {
45-
std::cerr << "Failed to set WER registry value. Error: " << result << std::endl;
46-
return false;
47-
}
22+
return (result == ERROR_SUCCESS);
23+
}
24+
25+
// Check for RuntimeExceptionHelperModules key
26+
BOOL CheckRuntimeExceptionHelper(const std::string& dllPath)
27+
{
28+
const LPCWSTR keyPath = L"SOFTWARE\\Microsoft\\Windows\\Windows Error Reporting\\RuntimeExceptionHelperModules";
29+
30+
// Create the value name we're looking for
31+
std::wstring wideDllPath(dllPath.begin(), dllPath.end());
32+
WCHAR valueName[2048];
33+
swprintf_s(valueName, 2048, wideDllPath.c_str());
4834

49-
std::cout << "Successfully created WER registry key for: " << dllPath << std::endl;
50-
return true;
35+
// Check if our specific value exists
36+
BOOL exists = DoesRegistryValueExist(HKEY_LOCAL_MACHINE, keyPath, valueName);
37+
38+
return exists;
5139
}
5240

41+
5342
void setupWerIntegration(crashpad::CrashpadClient& client, const std::string& exeDir) {
54-
std::string werDllPath = exeDir + "\\crashpad_wer.dll";
55-
std::cout << "Looking for Crashpad WER DLL at: " << werDllPath << std::endl;
56-
43+
std::string werDllPath = exeDir + "\\crashpad_wer.dll";
5744
if (!std::filesystem::exists(werDllPath)) {
58-
std::cout << "Crashpad WER DLL not found - continuing without WER integration" << std::endl;
45+
std::cout << "Crashpad WER DLL not found at: " << werDllPath << " - continuing without WER integration" << std::endl;
5946
return;
6047
}
61-
62-
std::cout << "Crashpad WER DLL found, setting up WER integration..." << std::endl;
63-
64-
// Create registry key for WER integration
65-
bool registryCreated = createWerRegistryKey(werDllPath);
48+
49+
// Check registry key for WER integration
50+
bool registryExists = CheckRuntimeExceptionHelper(werDllPath);
51+
if (!registryExists) {
52+
std::cout << "Crashpad WER registry key: " << werDllPath << " not found" << std::endl;
53+
std::cout << "Create this registry value in HKLM\\SOFTWARE\\Microsoft\\Windows\\Windows Error Reporting\\RuntimeExceptionHelperModules" << std::endl;
54+
std::cout << "Continuing without WER integration" << std::endl;
55+
return;
56+
}
6657

6758
// Register WER module with Crashpad
6859
std::wstring werDllPathW(werDllPath.begin(), werDllPath.end());
6960
bool moduleRegistered = client.RegisterWerModule(werDllPathW);
7061

7162
// Report results
72-
if (registryCreated && moduleRegistered) {
73-
std::cout << "Successfully set up WER integration: " << werDllPath << std::endl;
63+
if (!moduleRegistered) {
64+
std::cerr << "Warning: Failed to register WER module with Crashpad - continuing without WER integration" << std::endl;
7465
return;
7566
}
7667

77-
// Handle partial or complete failure
78-
if (!registryCreated) {
79-
std::cerr << "Warning: Failed to create WER registry key" << std::endl;
80-
}
81-
if (!moduleRegistered) {
82-
std::cerr << "Warning: Failed to register WER module with Crashpad" << std::endl;
83-
}
84-
std::cerr << "WER integration may not work properly" << std::endl;
68+
std::cout << "Successfully set up WER integration: " << werDllPath << std::endl;
8569
}
8670

8771
#endif // _WIN32

windows.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@
88

99
// Windows-specific WER (Windows Error Reporting) integration functions
1010

11-
/**
12-
* Creates a Windows registry key for WER integration.
13-
* Registers the crashpad_wer.dll path in HKEY_CURRENT_USER for Windows Error Reporting.
14-
*
15-
* @param dllPath Full absolute path to crashpad_wer.dll
16-
* @return true if registry key was created successfully, false otherwise
17-
*/
18-
bool createWerRegistryKey(const std::string& dllPath);
1911

2012
/**
2113
* Sets up complete WER integration for Crashpad.

0 commit comments

Comments
 (0)