PageRenderTime 21ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/thirdparty/breakpad/client/solaris/handler/solaris_lwp.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 160 lines | 61 code | 28 blank | 71 comment | 2 complexity | dc5caee85dd9833017a4351a306ac8f1 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-3.0, GPL-2.0
  1. // Copyright (c) 2007, Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. // Author: Alfred Peng
  30. #ifndef CLIENT_SOLARIS_HANDLER_SOLARIS_LWP_H__
  31. #define CLIENT_SOLARIS_HANDLER_SOLARIS_LWP_H__
  32. #if defined(sparc) || defined(__sparc)
  33. #define TARGET_CPU_SPARC 1
  34. #elif defined(i386) || defined(__i386)
  35. #define TARGET_CPU_X86 1
  36. #else
  37. #error "cannot determine cpu type"
  38. #endif
  39. #include <signal.h>
  40. #include <stdint.h>
  41. #include <sys/user.h>
  42. #include <ucontext.h>
  43. #ifndef _KERNEL
  44. #define _KERNEL
  45. #define MUST_UNDEF_KERNEL
  46. #endif // _KERNEL
  47. #include <sys/procfs.h>
  48. #ifdef MUST_UNDEF_KERNEL
  49. #undef _KERNEL
  50. #undef MUST_UNDEF_KERNEL
  51. #endif // MUST_UNDEF_KERNEL
  52. namespace google_breakpad {
  53. // Max module path name length.
  54. static const int kMaxModuleNameLength = 256;
  55. // Holding infomaton about a module in the process.
  56. struct ModuleInfo {
  57. char name[kMaxModuleNameLength];
  58. uintptr_t start_addr;
  59. int size;
  60. };
  61. // A callback to run when getting a lwp in the process.
  62. // Return true will go on to the next lwp while return false will stop the
  63. // iteration.
  64. typedef bool (*LwpCallback)(lwpstatus_t* lsp, void *context);
  65. // A callback to run when a new module is found in the process.
  66. // Return true will go on to the next module while return false will stop the
  67. // iteration.
  68. typedef bool (*ModuleCallback)(const ModuleInfo &module_info, void *context);
  69. // A callback to run when getting a lwpid in the process.
  70. // Return true will go on to the next lwp while return false will stop the
  71. // iteration.
  72. typedef bool (*LwpidCallback)(int lwpid, void *context);
  73. // Holding the callback information.
  74. template<class CallbackFunc>
  75. struct CallbackParam {
  76. // Callback function address.
  77. CallbackFunc call_back;
  78. // Callback context;
  79. void *context;
  80. CallbackParam() : call_back(NULL), context(NULL) {
  81. }
  82. CallbackParam(CallbackFunc func, void *func_context) :
  83. call_back(func), context(func_context) {
  84. }
  85. };
  86. ///////////////////////////////////////////////////////////////////////////////
  87. //
  88. // SolarisLwp
  89. //
  90. // Provides handy support for operation on Solaris lwps.
  91. // It uses proc file system to get lwp information.
  92. //
  93. // TODO(Alfred): Currently it only supports x86. Add SPARC support.
  94. //
  95. class SolarisLwp {
  96. public:
  97. // Create a SolarisLwp instance to list all the lwps in a process.
  98. explicit SolarisLwp(int pid);
  99. ~SolarisLwp();
  100. int getpid() const { return this->pid_; }
  101. // Control all the lwps in the process.
  102. // Return the number of suspended/resumed lwps in the process.
  103. // Return -1 means failed to control lwps.
  104. int ControlAllLwps(bool suspend);
  105. // Get the count of lwps in the process.
  106. // Return -1 means error.
  107. int GetLwpCount() const;
  108. // Iterate the lwps of process.
  109. // Whenever there is a lwp found, the callback will be invoked to process
  110. // the information.
  111. // Return the callback return value or -1 on error.
  112. int Lwp_iter_all(int pid, CallbackParam<LwpCallback> *callback_param) const;
  113. // Get the module count of the current process.
  114. int GetModuleCount() const;
  115. // Get the mapped modules in the address space.
  116. // Whenever a module is found, the callback will be invoked to process the
  117. // information.
  118. // Return how may modules are found.
  119. int ListModules(CallbackParam<ModuleCallback> *callback_param) const;
  120. // Get the bottom of the stack from esp.
  121. uintptr_t GetLwpStackBottom(uintptr_t current_esp) const;
  122. // Finds a signal context on the stack given the ebp of our signal handler.
  123. bool FindSigContext(uintptr_t sighandler_ebp, ucontext_t **sig_ctx);
  124. private:
  125. // Check if the address is a valid virtual address.
  126. bool IsAddressMapped(uintptr_t address) const;
  127. private:
  128. // The pid of the process we are listing lwps.
  129. int pid_;
  130. };
  131. } // namespace google_breakpad
  132. #endif // CLIENT_SOLARIS_HANDLER_SOLARIS_LWP_H__