OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #ifndef CRASHPAD_UTIL_POSIX_PROCESS_INFO_H_ |
| 16 #define CRASHPAD_UTIL_POSIX_PROCESS_INFO_H_ |
| 17 |
| 18 #include <sys/sysctl.h> |
| 19 #include <sys/time.h> |
| 20 #include <sys/types.h> |
| 21 #include <unistd.h> |
| 22 |
| 23 #include <set> |
| 24 #include <string> |
| 25 #include <vector> |
| 26 |
| 27 #include "base/basictypes.h" |
| 28 #include "build/build_config.h" |
| 29 #include "util/misc/initialization_state_dcheck.h" |
| 30 |
| 31 #if defined(OS_MACOSX) |
| 32 #include <mach/mach.h> |
| 33 #endif |
| 34 |
| 35 namespace crashpad { |
| 36 |
| 37 class ProcessInfo { |
| 38 public: |
| 39 ProcessInfo(); |
| 40 ~ProcessInfo(); |
| 41 |
| 42 //! \brief Initializes this object with information about the process whose ID |
| 43 //! is \a pid. |
| 44 //! |
| 45 //! This method must be called successfully prior to calling any other method |
| 46 //! in this class. This method may only be called once. |
| 47 //! |
| 48 //! It is unspecified whether the information that an object of this class |
| 49 //! returns is loaded at the time Initialize() is called or subsequently, and |
| 50 //! whether this information is cached in the object or not. |
| 51 //! |
| 52 //! \param[in] pid The process ID to obtain information for. |
| 53 //! |
| 54 //! \return `true` on success, `false` on failure with a message logged. |
| 55 bool Initialize(pid_t pid); |
| 56 |
| 57 #if defined(OS_MACOSX) || DOXYGEN |
| 58 //! \brief Initializes this object with information about a process based on |
| 59 //! its Mach task. |
| 60 //! |
| 61 //! This method serves as a stand-in for Initialize() and may be called in its |
| 62 //! place with the same restrictions and considerations. |
| 63 //! |
| 64 //! \param[in] task The Mach task to obtain information for. |
| 65 //! |
| 66 //! \return `true` on success, `false` on failure with an message logged. |
| 67 bool InitializeFromTask(task_t task); |
| 68 #endif |
| 69 |
| 70 //! \return The target task’s process ID. |
| 71 pid_t ProcessID() const; |
| 72 |
| 73 //! \return The target task’s parent process ID. |
| 74 pid_t ParentProcessID() const; |
| 75 |
| 76 //! \return The target process’ real user ID as would be returned to it by |
| 77 //! `getuid()`. |
| 78 uid_t RealUserID() const; |
| 79 |
| 80 //! \return The target process’ effective user ID as would be returned to it |
| 81 //! by `geteuid()`. |
| 82 uid_t EffectiveUserID() const; |
| 83 |
| 84 //! \return The target process’ saved set-user ID. |
| 85 uid_t SavedUserID() const; |
| 86 |
| 87 //! \return the target process’ real group ID as would be returned to it by |
| 88 //! `getgid()`. |
| 89 gid_t RealGroupID() const; |
| 90 |
| 91 //! \return the target process’ effective group ID as would be returned to it |
| 92 //! by `getegid()`. |
| 93 gid_t EffectiveGroupID() const; |
| 94 |
| 95 //! \return The target process’ saved set-group ID. |
| 96 gid_t SavedGroupID() const; |
| 97 |
| 98 //! \return the target process’ supplementary group list as would be returned |
| 99 //! to it by `getgroups()`. |
| 100 std::set<gid_t> SupplementaryGroups() const; |
| 101 |
| 102 //! \return All groups that the target process claims membership in, including |
| 103 //! RealGroupID(), EffectiveGroupID(), SavedGroupID(), and |
| 104 //! SupplementaryGroups(). |
| 105 std::set<gid_t> AllGroups() const; |
| 106 |
| 107 //! \brief Determines whether the target process has changed privileges. |
| 108 //! |
| 109 //! A process is considered to have changed privileges if it has changed its |
| 110 //! real, effective, or saved set-user or group IDs with the `setuid()`, |
| 111 //! `seteuid()`, `setreuid()`, `setgid()`, `setegid()`, or `setregid()` system |
| 112 //! calls since its most recent `execve()`, or if its privileges changed at |
| 113 //! `execve()` as a result of executing a setuid or setgid executable. |
| 114 bool DidChangePrivileges() const; |
| 115 |
| 116 //! \return `true` if the target task is a 64-bit process. |
| 117 bool Is64Bit() const; |
| 118 |
| 119 //! \brief Determines the target process’ start time. |
| 120 //! |
| 121 //! \param[out] start_time The time that the process started. |
| 122 void StartTime(timeval* start_time) const; |
| 123 |
| 124 //! \brief Obtains the arguments used to launch a process. |
| 125 //! |
| 126 //! Whether it is possible to obtain this information for a process with |
| 127 //! different privileges than the running program is system-dependent. |
| 128 //! |
| 129 //! \param[out] argv The process’ arguments as passed to its `main()` function |
| 130 //! as the \a argv parameter, possibly modified by the process. |
| 131 //! |
| 132 //! \return `true` on success, with \a argv populated appropriately. |
| 133 //! Otherwise, `false` with a message logged. |
| 134 //! |
| 135 //! \note This function may spuriously return `false` when used to examine a |
| 136 //! process that it is calling `exec()`. If examining such a process, call |
| 137 //! this function in a retry loop with a small (100ns) delay to avoid an |
| 138 //! erroneous assumption that \a pid is not running. |
| 139 bool Arguments(std::vector<std::string>* argv) const; |
| 140 |
| 141 private: |
| 142 #if defined(OS_MACOSX) |
| 143 kinfo_proc kern_proc_info_; |
| 144 #endif |
| 145 InitializationStateDcheck initialized_; |
| 146 |
| 147 DISALLOW_COPY_AND_ASSIGN(ProcessInfo); |
| 148 }; |
| 149 |
| 150 } // namespace crashpad |
| 151 |
| 152 #endif // CRASHPAD_UTIL_POSIX_PROCESS_INFO_H_ |
OLD | NEW |