Chromium Code Reviews| 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 | |
|
Robert Sesek
2014/11/14 22:06:18
No dtor?
| |
| 41 //! \brief Initializes this object with information about the process whose ID | |
| 42 //! is \a pid. | |
| 43 //! | |
| 44 //! This method must be called successfully prior to calling any other method | |
| 45 //! in this class. This method may only be called once. | |
| 46 //! | |
| 47 //! It is unspecified whether the information that an object of this class | |
| 48 //! returns is loaded at the time Initialize() is called or subsequently, and | |
|
Robert Sesek
2014/11/14 22:06:18
This consideration then requires that the target p
Mark Mentovai
2014/11/14 22:16:45
Robert Sesek wrote:
| |
| 49 //! whether this information is cached in the object or not. | |
| 50 //! | |
| 51 //! \param[in] pid The process ID to obtain information for. | |
| 52 //! | |
| 53 //! \return `true` on success, `false` on failure with a message logged. | |
| 54 bool Initialize(pid_t pid); | |
| 55 | |
| 56 #if defined(OS_MACOSX) || DOXYGEN | |
| 57 //! \brief Initializes this object with information about a process based on | |
| 58 //! its Mach task. | |
| 59 //! | |
| 60 //! This method serves as a stand-in for Initialize() and may be called in its | |
| 61 //! place with the same restrictions and considerations. | |
| 62 //! | |
| 63 //! \param[in] task The Mach task to obtain information for. | |
| 64 //! | |
| 65 //! \return `true` on success, `false` on failure with an message logged. | |
| 66 bool InitializeFromTask(task_t task); | |
| 67 #endif | |
| 68 | |
| 69 //! \return The target task’s process ID. | |
| 70 pid_t ProcessID() const; | |
| 71 | |
| 72 //! \return The target task’s parent process ID. | |
| 73 pid_t ParentProcessID() const; | |
| 74 | |
| 75 //! \return The target process’ real user ID as would be returned to it by | |
| 76 //! `getuid()`. | |
| 77 uid_t RealUserID() const; | |
| 78 | |
| 79 //! \return The target process’ effective user ID as would be returned to it | |
| 80 //! by `geteuid()`. | |
| 81 uid_t EffectiveUserID() const; | |
| 82 | |
| 83 //! \return The target process’ saved set-user ID. | |
| 84 uid_t SavedUserID() const; | |
| 85 | |
| 86 //! \return the target process’ real group ID as would be returned to it by | |
| 87 //! `getgid()`. | |
| 88 gid_t RealGroupID() const; | |
| 89 | |
| 90 //! \return the target process’ effective group ID as would be returned to it | |
| 91 //! by `getegid()`. | |
| 92 gid_t EffectiveGroupID() const; | |
| 93 | |
| 94 //! \return The target process’ saved set-group ID. | |
| 95 gid_t SavedGroupID() const; | |
| 96 | |
| 97 //! \return the target process’ supplementary group list as would be returned | |
| 98 //! to it by `getgroups()`. | |
| 99 std::set<gid_t> SupplementaryGroups() const; | |
| 100 | |
| 101 //! \return All groups that the target process claims membership in, including | |
| 102 //! RealGroupID(), EffectiveGroupID(), SavedGroupID(), and | |
| 103 //! SupplementaryGroups(). | |
| 104 std::set<gid_t> AllGroups() const; | |
| 105 | |
| 106 //! \brief Determines whether the target process has changed privileges. | |
| 107 //! | |
| 108 //! A process is considered to have changed privileges if it has changed its | |
| 109 //! real, effective, or saved set-user or group IDs with the `setuid()`, | |
| 110 //! `seteuid()`, `setreuid()`, `setgid()`, `setegid()`, or `setregid()` system | |
| 111 //! calls since its most recent `execve()`, or if its privileges changed at | |
| 112 //! `execve()` as a result of executing a setuid or setgid executable. | |
| 113 bool DidChangePrivileges() const; | |
| 114 | |
| 115 //! \return `true` if the target task is a 64-bit process. | |
| 116 bool Is64Bit() const; | |
| 117 | |
| 118 //! \brief Determines the target process’ start time. | |
| 119 //! | |
| 120 //! \param[out] start_time The time that the process started. | |
| 121 void StartTime(timeval* start_time) const; | |
| 122 | |
| 123 //! \brief Obtains the arguments used to launch a process. | |
| 124 //! | |
| 125 //! Whether it is possible to obtain this information for a process with | |
| 126 //! different privileges than the running program is system-dependent. | |
| 127 //! | |
| 128 //! \param[out] argv The process’ arguments as passed to its `main()` function | |
| 129 //! as the \a argv parameter, possibly modified by the process. | |
| 130 //! | |
| 131 //! \return `true` on success, with \a argv populated appropriately. | |
| 132 //! Otherwise, `false` with a message logged. | |
| 133 //! | |
| 134 //! \note This function may spuriously return `false` when used to examine a | |
| 135 //! process that it is calling `exec()`. If examining such a process, call | |
| 136 //! this function in a retry loop with a small (100ns) delay to avoid an | |
| 137 //! erroneous assumption that \a pid is not running. | |
| 138 bool Arguments(std::vector<std::string>* argv) const; | |
| 139 | |
| 140 private: | |
| 141 #if defined(OS_MACOSX) | |
| 142 kinfo_proc kern_proc_info_; | |
| 143 #endif | |
| 144 InitializationStateDcheck initialized_; | |
| 145 | |
| 146 DISALLOW_COPY_AND_ASSIGN(ProcessInfo); | |
| 147 }; | |
| 148 | |
| 149 } // namespace crashpad | |
| 150 | |
| 151 #endif // CRASHPAD_UTIL_POSIX_PROCESS_INFO_H_ | |
| OLD | NEW |