toolkit/crashreporter/google-breakpad/src/client/solaris/handler/solaris_lwp.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/google-breakpad/src/client/solaris/handler/solaris_lwp.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,160 @@
     1.4 +// Copyright (c) 2007, Google Inc.
     1.5 +// All rights reserved.
     1.6 +//
     1.7 +// Redistribution and use in source and binary forms, with or without
     1.8 +// modification, are permitted provided that the following conditions are
     1.9 +// met:
    1.10 +//
    1.11 +//     * Redistributions of source code must retain the above copyright
    1.12 +// notice, this list of conditions and the following disclaimer.
    1.13 +//     * Redistributions in binary form must reproduce the above
    1.14 +// copyright notice, this list of conditions and the following disclaimer
    1.15 +// in the documentation and/or other materials provided with the
    1.16 +// distribution.
    1.17 +//     * Neither the name of Google Inc. nor the names of its
    1.18 +// contributors may be used to endorse or promote products derived from
    1.19 +// this software without specific prior written permission.
    1.20 +//
    1.21 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.22 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.23 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.24 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.25 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.26 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.27 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.28 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.29 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.30 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.31 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.32 +
    1.33 +// Author: Alfred Peng
    1.34 +
    1.35 +#ifndef CLIENT_SOLARIS_HANDLER_SOLARIS_LWP_H__
    1.36 +#define CLIENT_SOLARIS_HANDLER_SOLARIS_LWP_H__
    1.37 +
    1.38 +#if defined(sparc) || defined(__sparc)
    1.39 +#define TARGET_CPU_SPARC 1
    1.40 +#elif defined(i386) || defined(__i386)
    1.41 +#define TARGET_CPU_X86 1
    1.42 +#else
    1.43 +#error "cannot determine cpu type"
    1.44 +#endif
    1.45 +
    1.46 +#include <signal.h>
    1.47 +#include <stdint.h>
    1.48 +#include <sys/user.h>
    1.49 +#include <ucontext.h>
    1.50 +
    1.51 +#ifndef _KERNEL
    1.52 +#define _KERNEL
    1.53 +#define MUST_UNDEF_KERNEL
    1.54 +#endif  // _KERNEL
    1.55 +#include <sys/procfs.h>
    1.56 +#ifdef MUST_UNDEF_KERNEL
    1.57 +#undef _KERNEL
    1.58 +#undef MUST_UNDEF_KERNEL
    1.59 +#endif  // MUST_UNDEF_KERNEL
    1.60 +
    1.61 +namespace google_breakpad {
    1.62 +
    1.63 +// Max module path name length.
    1.64 +static const int kMaxModuleNameLength = 256;
    1.65 +
    1.66 +// Holding infomaton about a module in the process.
    1.67 +struct ModuleInfo {
    1.68 +  char name[kMaxModuleNameLength];
    1.69 +  uintptr_t start_addr;
    1.70 +  int size;
    1.71 +};
    1.72 +
    1.73 +// A callback to run when getting a lwp in the process.
    1.74 +// Return true will go on to the next lwp while return false will stop the
    1.75 +// iteration.
    1.76 +typedef bool (*LwpCallback)(lwpstatus_t* lsp, void *context); 
    1.77 +
    1.78 +// A callback to run when a new module is found in the process.
    1.79 +// Return true will go on to the next module while return false will stop the
    1.80 +// iteration.
    1.81 +typedef bool (*ModuleCallback)(const ModuleInfo &module_info, void *context);
    1.82 +
    1.83 +// A callback to run when getting a lwpid in the process.
    1.84 +// Return true will go on to the next lwp while return false will stop the
    1.85 +// iteration.
    1.86 +typedef bool (*LwpidCallback)(int lwpid, void *context);
    1.87 +
    1.88 +// Holding the callback information.
    1.89 +template<class CallbackFunc>
    1.90 +struct CallbackParam {
    1.91 +  // Callback function address.
    1.92 +  CallbackFunc call_back;
    1.93 +  // Callback context;
    1.94 +  void *context;
    1.95 +
    1.96 +  CallbackParam() : call_back(NULL), context(NULL) {
    1.97 +  }
    1.98 +
    1.99 +  CallbackParam(CallbackFunc func, void *func_context) :
   1.100 +    call_back(func), context(func_context) {
   1.101 +  }
   1.102 +};
   1.103 +
   1.104 +///////////////////////////////////////////////////////////////////////////////
   1.105 +
   1.106 +//
   1.107 +// SolarisLwp
   1.108 +//
   1.109 +// Provides handy support for operation on Solaris lwps.
   1.110 +// It uses proc file system to get lwp information.
   1.111 +//
   1.112 +// TODO(Alfred): Currently it only supports x86. Add SPARC support.
   1.113 +//
   1.114 +class SolarisLwp {
   1.115 + public:
   1.116 +  // Create a SolarisLwp instance to list all the lwps in a process.
   1.117 +  explicit SolarisLwp(int pid);
   1.118 +  ~SolarisLwp();
   1.119 +
   1.120 +  int getpid() const { return this->pid_; }
   1.121 +
   1.122 +  // Control all the lwps in the process.
   1.123 +  // Return the number of suspended/resumed lwps in the process.
   1.124 +  // Return -1 means failed to control lwps.
   1.125 +  int ControlAllLwps(bool suspend);
   1.126 +
   1.127 +  // Get the count of lwps in the process.
   1.128 +  // Return -1 means error.
   1.129 +  int GetLwpCount() const;
   1.130 +
   1.131 +  // Iterate the lwps of process.
   1.132 +  // Whenever there is a lwp found, the callback will be invoked to process
   1.133 +  // the information.
   1.134 +  // Return the callback return value or -1 on error.
   1.135 +  int Lwp_iter_all(int pid, CallbackParam<LwpCallback> *callback_param) const;
   1.136 +
   1.137 +  // Get the module count of the current process.
   1.138 +  int GetModuleCount() const;
   1.139 +
   1.140 +  // Get the mapped modules in the address space.
   1.141 +  // Whenever a module is found, the callback will be invoked to process the
   1.142 +  // information.
   1.143 +  // Return how may modules are found.
   1.144 +  int ListModules(CallbackParam<ModuleCallback> *callback_param) const;
   1.145 +
   1.146 +  // Get the bottom of the stack from esp.
   1.147 +  uintptr_t GetLwpStackBottom(uintptr_t current_esp) const;
   1.148 +
   1.149 +  // Finds a signal context on the stack given the ebp of our signal handler.
   1.150 +  bool FindSigContext(uintptr_t sighandler_ebp, ucontext_t **sig_ctx);
   1.151 +
   1.152 + private:
   1.153 +  // Check if the address is a valid virtual address.
   1.154 +  bool IsAddressMapped(uintptr_t address) const;
   1.155 +
   1.156 + private:
   1.157 +  // The pid of the process we are listing lwps.
   1.158 +  int pid_;
   1.159 +};
   1.160 +
   1.161 +}  // namespace google_breakpad
   1.162 +
   1.163 +#endif  // CLIENT_SOLARIS_HANDLER_SOLARIS_LWP_H__

mercurial