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