crashpad_support.cc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (c) 2022 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/common/gin_helper/dictionary.h"
  5. #include "shell/common/node_includes.h"
  6. #if BUILDFLAG(IS_LINUX)
  7. #include "components/crash/core/app/crashpad.h" // nogncheck
  8. #endif
  9. namespace {
  10. #if BUILDFLAG(IS_LINUX)
  11. int GetCrashdumpSignalFD() {
  12. int fd;
  13. return crash_reporter::GetHandlerSocket(&fd, nullptr) ? fd : -1;
  14. }
  15. int GetCrashpadHandlerPID() {
  16. int pid;
  17. return crash_reporter::GetHandlerSocket(nullptr, &pid) ? pid : -1;
  18. }
  19. #endif
  20. void Initialize(v8::Local<v8::Object> exports,
  21. v8::Local<v8::Value> unused,
  22. v8::Local<v8::Context> context,
  23. void* priv) {
  24. gin_helper::Dictionary dict(context->GetIsolate(), exports);
  25. #if BUILDFLAG(IS_LINUX)
  26. dict.SetMethod("getCrashdumpSignalFD", &GetCrashdumpSignalFD);
  27. dict.SetMethod("getCrashpadHandlerPID", &GetCrashpadHandlerPID);
  28. #endif
  29. }
  30. } // namespace
  31. NODE_LINKED_BINDING_CONTEXT_AWARE(electron_common_crashpad_support, Initialize)