diff --git a/libprocessgroup/cgroup_map.cpp b/libprocessgroup/cgroup_map.cpp index ce7f10b00..c8ae2161a 100644 --- a/libprocessgroup/cgroup_map.cpp +++ b/libprocessgroup/cgroup_map.cpp @@ -104,7 +104,7 @@ std::string CgroupController::GetProcsFilePath(const std::string& rel_path, uid_ return proc_path.append(CGROUP_PROCS_FILE); } -bool CgroupController::GetTaskGroup(int tid, std::string* group) const { +bool CgroupController::GetTaskGroup(pid_t tid, std::string* group) const { std::string file_name = StringPrintf("/proc/%d/cgroup", tid); std::string content; if (!android::base::ReadFileToString(file_name, &content)) { diff --git a/libprocessgroup/cgroup_map.h b/libprocessgroup/cgroup_map.h index 5cdf8b28c..5c6d3e21c 100644 --- a/libprocessgroup/cgroup_map.h +++ b/libprocessgroup/cgroup_map.h @@ -43,7 +43,8 @@ class CgroupController { std::string GetTasksFilePath(const std::string& path) const; std::string GetProcsFilePath(const std::string& path, uid_t uid, pid_t pid) const; - bool GetTaskGroup(int tid, std::string* group) const; + bool GetTaskGroup(pid_t tid, std::string* group) const; + private: enum ControllerState { UNKNOWN = 0, diff --git a/libprocessgroup/include/processgroup/processgroup.h b/libprocessgroup/include/processgroup/processgroup.h index ca6868c1b..ffffeb48b 100644 --- a/libprocessgroup/include/processgroup/processgroup.h +++ b/libprocessgroup/include/processgroup/processgroup.h @@ -33,19 +33,20 @@ bool CgroupsAvailable(); bool CgroupGetControllerPath(const std::string& cgroup_name, std::string* path); bool CgroupGetControllerFromPath(const std::string& path, std::string* cgroup_name); bool CgroupGetAttributePath(const std::string& attr_name, std::string* path); -bool CgroupGetAttributePathForTask(const std::string& attr_name, int tid, std::string* path); +bool CgroupGetAttributePathForTask(const std::string& attr_name, pid_t tid, std::string* path); -bool SetTaskProfiles(int tid, const std::vector& profiles, bool use_fd_cache = false); +bool SetTaskProfiles(pid_t tid, const std::vector& profiles, + bool use_fd_cache = false); bool SetProcessProfiles(uid_t uid, pid_t pid, const std::vector& profiles); bool SetUserProfiles(uid_t uid, const std::vector& profiles); __END_DECLS -bool SetTaskProfiles(int tid, std::initializer_list profiles, +bool SetTaskProfiles(pid_t tid, std::initializer_list profiles, bool use_fd_cache = false); bool SetProcessProfiles(uid_t uid, pid_t pid, std::initializer_list profiles); #if _LIBCPP_STD_VER > 17 -bool SetTaskProfiles(int tid, std::span profiles, +bool SetTaskProfiles(pid_t tid, std::span profiles, bool use_fd_cache = false); bool SetProcessProfiles(uid_t uid, pid_t pid, std::span profiles); #endif @@ -67,35 +68,35 @@ void DropTaskProfilesResourceCaching(); // Return 0 if all processes were killed and the cgroup was successfully removed. // Returns -1 in the case of an error occurring or if there are processes still running. -int killProcessGroup(uid_t uid, int initialPid, int signal); +int killProcessGroup(uid_t uid, pid_t initialPid, int signal); // Returns the same as killProcessGroup(), however it does not retry, which means // that it only returns 0 in the case that the cgroup exists and it contains no processes. -int killProcessGroupOnce(uid_t uid, int initialPid, int signal); +int killProcessGroupOnce(uid_t uid, pid_t initialPid, int signal); // Sends the provided signal to all members of a process group, but does not wait for processes to // exit, or for the cgroup to be removed. Callers should also ensure that killProcessGroup is called // later to ensure the cgroup is fully removed, otherwise system resources will leak. // Returns true if no errors are encountered sending signals, otherwise false. -bool sendSignalToProcessGroup(uid_t uid, int initialPid, int signal); +bool sendSignalToProcessGroup(uid_t uid, pid_t initialPid, int signal); -int createProcessGroup(uid_t uid, int initialPid, bool memControl = false); +int createProcessGroup(uid_t uid, pid_t initialPid, bool memControl = false); // Set various properties of a process group. For these functions to work, the process group must // have been created by passing memControl=true to createProcessGroup. -bool setProcessGroupSwappiness(uid_t uid, int initialPid, int swappiness); -bool setProcessGroupSoftLimit(uid_t uid, int initialPid, int64_t softLimitInBytes); -bool setProcessGroupLimit(uid_t uid, int initialPid, int64_t limitInBytes); +bool setProcessGroupSwappiness(uid_t uid, pid_t initialPid, int swappiness); +bool setProcessGroupSoftLimit(uid_t uid, pid_t initialPid, int64_t softLimitInBytes); +bool setProcessGroupLimit(uid_t uid, pid_t initialPid, int64_t limitInBytes); void removeAllEmptyProcessGroups(void); // Provides the path for an attribute in a specific process group // Returns false in case of error, true in case of success -bool getAttributePathForTask(const std::string& attr_name, int tid, std::string* path); +bool getAttributePathForTask(const std::string& attr_name, pid_t tid, std::string* path); // Check if a profile can be applied without failing. // Returns true if it can be applied without failing, false otherwise -bool isProfileValidForProcess(const std::string& profile_name, int uid, int pid); +bool isProfileValidForProcess(const std::string& profile_name, uid_t uid, pid_t pid); #endif // __ANDROID_VNDK__ diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp index 3209adf16..94d950209 100644 --- a/libprocessgroup/processgroup.cpp +++ b/libprocessgroup/processgroup.cpp @@ -82,7 +82,7 @@ static std::string ConvertUidToPath(const char* cgroup, uid_t uid) { return StringPrintf("%s/uid_%u", cgroup, uid); } -static std::string ConvertUidPidToPath(const char* cgroup, uid_t uid, int pid) { +static std::string ConvertUidPidToPath(const char* cgroup, uid_t uid, pid_t pid) { return StringPrintf("%s/uid_%u/pid_%d", cgroup, uid, pid); } @@ -147,7 +147,7 @@ bool CgroupGetAttributePath(const std::string& attr_name, std::string* path) { return true; } -bool CgroupGetAttributePathForTask(const std::string& attr_name, int tid, std::string* path) { +bool CgroupGetAttributePathForTask(const std::string& attr_name, pid_t tid, std::string* path) { const TaskProfiles& tp = TaskProfiles::GetInstance(); const IProfileAttribute* attr = tp.GetAttribute(attr_name); @@ -198,17 +198,18 @@ bool SetProcessProfilesCached(uid_t uid, pid_t pid, const std::vector(profiles), true); } -bool SetTaskProfiles(int tid, const std::vector& profiles, bool use_fd_cache) { +bool SetTaskProfiles(pid_t tid, const std::vector& profiles, bool use_fd_cache) { return TaskProfiles::GetInstance().SetTaskProfiles(tid, std::span(profiles), use_fd_cache); } -bool SetTaskProfiles(int tid, std::initializer_list profiles, bool use_fd_cache) { +bool SetTaskProfiles(pid_t tid, std::initializer_list profiles, + bool use_fd_cache) { return TaskProfiles::GetInstance().SetTaskProfiles( tid, std::span(profiles), use_fd_cache); } -bool SetTaskProfiles(int tid, std::span profiles, bool use_fd_cache) { +bool SetTaskProfiles(pid_t tid, std::span profiles, bool use_fd_cache) { return TaskProfiles::GetInstance().SetTaskProfiles(tid, profiles, use_fd_cache); } @@ -232,7 +233,7 @@ bool SetUserProfiles(uid_t uid, const std::vector& profiles) { false); } -static int RemoveCgroup(const char* cgroup, uid_t uid, int pid) { +static int RemoveCgroup(const char* cgroup, uid_t uid, pid_t pid) { auto path = ConvertUidPidToPath(cgroup, uid, pid); int ret = TEMP_FAILURE_RETRY(rmdir(path.c_str())); @@ -370,7 +371,7 @@ err: return false; } -bool sendSignalToProcessGroup(uid_t uid, int initialPid, int signal) { +bool sendSignalToProcessGroup(uid_t uid, pid_t initialPid, int signal) { std::set pgids, pids; if (CgroupsAvailable()) { @@ -525,7 +526,7 @@ static populated_status cgroupIsPopulated(int events_fd) { // implementation of this function. The default retry value was 40 for killing and 400 for cgroup // removal with 5ms sleeps between each retry. static int KillProcessGroup( - uid_t uid, int initialPid, int signal, bool once = false, + uid_t uid, pid_t initialPid, int signal, bool once = false, std::chrono::steady_clock::time_point until = std::chrono::steady_clock::now() + 2200ms) { CHECK_GE(uid, 0); CHECK_GT(initialPid, 0); @@ -632,15 +633,15 @@ static int KillProcessGroup( return ret; } -int killProcessGroup(uid_t uid, int initialPid, int signal) { +int killProcessGroup(uid_t uid, pid_t initialPid, int signal) { return KillProcessGroup(uid, initialPid, signal); } -int killProcessGroupOnce(uid_t uid, int initialPid, int signal) { +int killProcessGroupOnce(uid_t uid, pid_t initialPid, int signal) { return KillProcessGroup(uid, initialPid, signal, true); } -static int createProcessGroupInternal(uid_t uid, int initialPid, std::string cgroup, +static int createProcessGroupInternal(uid_t uid, pid_t initialPid, std::string cgroup, bool activate_controllers) { auto uid_path = ConvertUidToPath(cgroup.c_str(), uid); @@ -687,7 +688,7 @@ static int createProcessGroupInternal(uid_t uid, int initialPid, std::string cgr return ret; } -int createProcessGroup(uid_t uid, int initialPid, bool memControl) { +int createProcessGroup(uid_t uid, pid_t initialPid, bool memControl) { CHECK_GE(uid, 0); CHECK_GT(initialPid, 0); @@ -712,7 +713,7 @@ int createProcessGroup(uid_t uid, int initialPid, bool memControl) { return createProcessGroupInternal(uid, initialPid, cgroup, true); } -static bool SetProcessGroupValue(int tid, const std::string& attr_name, int64_t value) { +static bool SetProcessGroupValue(pid_t tid, const std::string& attr_name, int64_t value) { if (!isMemoryCgroupSupported()) { LOG(ERROR) << "Memcg is not mounted."; return false; @@ -731,23 +732,23 @@ static bool SetProcessGroupValue(int tid, const std::string& attr_name, int64_t return true; } -bool setProcessGroupSwappiness(uid_t, int pid, int swappiness) { +bool setProcessGroupSwappiness(uid_t, pid_t pid, int swappiness) { return SetProcessGroupValue(pid, "MemSwappiness", swappiness); } -bool setProcessGroupSoftLimit(uid_t, int pid, int64_t soft_limit_in_bytes) { +bool setProcessGroupSoftLimit(uid_t, pid_t pid, int64_t soft_limit_in_bytes) { return SetProcessGroupValue(pid, "MemSoftLimit", soft_limit_in_bytes); } -bool setProcessGroupLimit(uid_t, int pid, int64_t limit_in_bytes) { +bool setProcessGroupLimit(uid_t, pid_t pid, int64_t limit_in_bytes) { return SetProcessGroupValue(pid, "MemLimit", limit_in_bytes); } -bool getAttributePathForTask(const std::string& attr_name, int tid, std::string* path) { +bool getAttributePathForTask(const std::string& attr_name, pid_t tid, std::string* path) { return CgroupGetAttributePathForTask(attr_name, tid, path); } -bool isProfileValidForProcess(const std::string& profile_name, int uid, int pid) { +bool isProfileValidForProcess(const std::string& profile_name, uid_t uid, pid_t pid) { const TaskProfile* tp = TaskProfiles::GetInstance().GetProfile(profile_name); if (tp == nullptr) { diff --git a/libprocessgroup/sched_policy.cpp b/libprocessgroup/sched_policy.cpp index 169b1d3e0..1005b1e3e 100644 --- a/libprocessgroup/sched_policy.cpp +++ b/libprocessgroup/sched_policy.cpp @@ -38,7 +38,7 @@ static inline SchedPolicy _policy(SchedPolicy p) { #if defined(__ANDROID__) -int set_cpuset_policy(int tid, SchedPolicy policy) { +int set_cpuset_policy(pid_t tid, SchedPolicy policy) { if (tid == 0) { tid = GetThreadId(); } @@ -64,7 +64,7 @@ int set_cpuset_policy(int tid, SchedPolicy policy) { return 0; } -int set_sched_policy(int tid, SchedPolicy policy) { +int set_sched_policy(pid_t tid, SchedPolicy policy) { if (tid == 0) { tid = GetThreadId(); } @@ -154,7 +154,7 @@ bool schedboost_enabled() { return enabled; } -static int getCGroupSubsys(int tid, const char* subsys, std::string& subgroup) { +static int getCGroupSubsys(pid_t tid, const char* subsys, std::string& subgroup) { auto controller = CgroupMap::GetInstance().FindController(subsys); if (!controller.IsUsable()) return -1; @@ -185,7 +185,7 @@ static int get_sched_policy_from_group(const std::string& group, SchedPolicy* po return 0; } -int get_sched_policy(int tid, SchedPolicy* policy) { +int get_sched_policy(pid_t tid, SchedPolicy* policy) { if (tid == 0) { tid = GetThreadId(); } diff --git a/libprocessgroup/task_profiles.cpp b/libprocessgroup/task_profiles.cpp index d5bd47cb2..2353cf18a 100644 --- a/libprocessgroup/task_profiles.cpp +++ b/libprocessgroup/task_profiles.cpp @@ -136,7 +136,7 @@ bool ProfileAttribute::GetPathForProcess(uid_t uid, pid_t pid, std::string* path return GetPathForTask(pid, path); } -bool ProfileAttribute::GetPathForTask(int tid, std::string* path) const { +bool ProfileAttribute::GetPathForTask(pid_t tid, std::string* path) const { std::string subgroup; if (!controller()->GetTaskGroup(tid, &subgroup)) { return false; @@ -179,13 +179,13 @@ bool SetClampsAction::ExecuteForTask(int) const { // To avoid issues in sdk_mac build #if defined(__ANDROID__) -bool SetTimerSlackAction::IsTimerSlackSupported(int tid) { +bool SetTimerSlackAction::IsTimerSlackSupported(pid_t tid) { auto file = StringPrintf("/proc/%d/timerslack_ns", tid); return (access(file.c_str(), W_OK) == 0); } -bool SetTimerSlackAction::ExecuteForTask(int tid) const { +bool SetTimerSlackAction::ExecuteForTask(pid_t tid) const { static bool sys_supports_timerslack = IsTimerSlackSupported(tid); // v4.6+ kernels support the /proc//timerslack_ns interface. @@ -250,7 +250,7 @@ bool SetAttributeAction::ExecuteForProcess(uid_t uid, pid_t pid) const { return WriteValueToFile(path); } -bool SetAttributeAction::ExecuteForTask(int tid) const { +bool SetAttributeAction::ExecuteForTask(pid_t tid) const { std::string path; if (!attribute_->GetPathForTask(tid, &path)) { @@ -288,7 +288,7 @@ bool SetAttributeAction::IsValidForProcess(uid_t, pid_t pid) const { return IsValidForTask(pid); } -bool SetAttributeAction::IsValidForTask(int tid) const { +bool SetAttributeAction::IsValidForTask(pid_t tid) const { std::string path; if (!attribute_->GetPathForTask(tid, &path)) { @@ -316,7 +316,7 @@ SetCgroupAction::SetCgroupAction(const CgroupController& c, const std::string& p FdCacheHelper::Init(controller_.GetProcsFilePath(path_, 0, 0), fd_[ProfileAction::RCT_PROCESS]); } -bool SetCgroupAction::AddTidToCgroup(int tid, int fd, ResourceCacheType cache_type) const { +bool SetCgroupAction::AddTidToCgroup(pid_t tid, int fd, ResourceCacheType cache_type) const { if (tid <= 0) { return true; } @@ -401,7 +401,7 @@ bool SetCgroupAction::ExecuteForProcess(uid_t uid, pid_t pid) const { return true; } -bool SetCgroupAction::ExecuteForTask(int tid) const { +bool SetCgroupAction::ExecuteForTask(pid_t tid) const { CacheUseResult result = UseCachedFd(ProfileAction::RCT_TASK, tid); if (result != ProfileAction::UNUSED) { return result == ProfileAction::SUCCESS; @@ -489,7 +489,7 @@ WriteFileAction::WriteFileAction(const std::string& task_path, const std::string } bool WriteFileAction::WriteValueToFile(const std::string& value_, ResourceCacheType cache_type, - int uid, int pid, bool logfailures) const { + uid_t uid, pid_t pid, bool logfailures) const { std::string value(value_); value = StringReplace(value, "", std::to_string(uid), true); @@ -564,7 +564,7 @@ bool WriteFileAction::ExecuteForProcess(uid_t uid, pid_t pid) const { DIR* d; struct dirent* de; char proc_path[255]; - int t_pid; + pid_t t_pid; sprintf(proc_path, "/proc/%d/task", pid); if (!(d = opendir(proc_path))) { @@ -590,7 +590,7 @@ bool WriteFileAction::ExecuteForProcess(uid_t uid, pid_t pid) const { return true; } -bool WriteFileAction::ExecuteForTask(int tid) const { +bool WriteFileAction::ExecuteForTask(pid_t tid) const { return WriteValueToFile(value_, ProfileAction::RCT_TASK, getuid(), tid, logfailures_); } @@ -655,7 +655,7 @@ bool ApplyProfileAction::ExecuteForProcess(uid_t uid, pid_t pid) const { return true; } -bool ApplyProfileAction::ExecuteForTask(int tid) const { +bool ApplyProfileAction::ExecuteForTask(pid_t tid) const { for (const auto& profile : profiles_) { profile->ExecuteForTask(tid); } @@ -683,7 +683,7 @@ bool ApplyProfileAction::IsValidForProcess(uid_t uid, pid_t pid) const { return true; } -bool ApplyProfileAction::IsValidForTask(int tid) const { +bool ApplyProfileAction::IsValidForTask(pid_t tid) const { for (const auto& profile : profiles_) { if (!profile->IsValidForTask(tid)) { return false; @@ -707,7 +707,7 @@ bool TaskProfile::ExecuteForProcess(uid_t uid, pid_t pid) const { return true; } -bool TaskProfile::ExecuteForTask(int tid) const { +bool TaskProfile::ExecuteForTask(pid_t tid) const { if (tid == 0) { tid = GetThreadId(); } @@ -761,7 +761,7 @@ bool TaskProfile::IsValidForProcess(uid_t uid, pid_t pid) const { return true; } -bool TaskProfile::IsValidForTask(int tid) const { +bool TaskProfile::IsValidForTask(pid_t tid) const { for (const auto& element : elements_) { if (!element->IsValidForTask(tid)) return false; } @@ -1043,7 +1043,7 @@ bool TaskProfiles::SetProcessProfiles(uid_t uid, pid_t pid, std::span p } template -bool TaskProfiles::SetTaskProfiles(int tid, std::span profiles, bool use_fd_cache) { +bool TaskProfiles::SetTaskProfiles(pid_t tid, std::span profiles, bool use_fd_cache) { bool success = true; for (const auto& name : profiles) { TaskProfile* profile = GetProfile(name); @@ -1069,9 +1069,9 @@ template bool TaskProfiles::SetProcessProfiles(uid_t uid, pid_t pid, template bool TaskProfiles::SetProcessProfiles(uid_t uid, pid_t pid, std::span profiles, bool use_fd_cache); -template bool TaskProfiles::SetTaskProfiles(int tid, std::span profiles, +template bool TaskProfiles::SetTaskProfiles(pid_t tid, std::span profiles, bool use_fd_cache); -template bool TaskProfiles::SetTaskProfiles(int tid, std::span profiles, +template bool TaskProfiles::SetTaskProfiles(pid_t tid, std::span profiles, bool use_fd_cache); template bool TaskProfiles::SetUserProfiles(uid_t uid, std::span profiles, bool use_fd_cache); diff --git a/libprocessgroup/task_profiles.h b/libprocessgroup/task_profiles.h index 16ffe6350..2fa193177 100644 --- a/libprocessgroup/task_profiles.h +++ b/libprocessgroup/task_profiles.h @@ -37,7 +37,7 @@ class IProfileAttribute { virtual const CgroupController* controller() const = 0; virtual const std::string& file_name() const = 0; virtual bool GetPathForProcess(uid_t uid, pid_t pid, std::string* path) const = 0; - virtual bool GetPathForTask(int tid, std::string* path) const = 0; + virtual bool GetPathForTask(pid_t tid, std::string* path) const = 0; virtual bool GetPathForUID(uid_t uid, std::string* path) const = 0; }; @@ -57,7 +57,7 @@ class ProfileAttribute : public IProfileAttribute { const std::string& file_v2_name) override; bool GetPathForProcess(uid_t uid, pid_t pid, std::string* path) const override; - bool GetPathForTask(int tid, std::string* path) const override; + bool GetPathForTask(pid_t tid, std::string* path) const override; bool GetPathForUID(uid_t uid, std::string* path) const override; private: @@ -83,7 +83,7 @@ class ProfileAction { virtual void EnableResourceCaching(ResourceCacheType) {} virtual void DropResourceCaching(ResourceCacheType) {} virtual bool IsValidForProcess(uid_t uid, pid_t pid) const { return false; } - virtual bool IsValidForTask(int tid) const { return false; } + virtual bool IsValidForTask(pid_t tid) const { return false; } protected: enum CacheUseResult { SUCCESS, FAIL, UNUSED }; @@ -96,7 +96,7 @@ class SetClampsAction : public ProfileAction { const char* Name() const override { return "SetClamps"; } bool ExecuteForProcess(uid_t uid, pid_t pid) const override; - bool ExecuteForTask(int tid) const override; + bool ExecuteForTask(pid_t tid) const override; protected: int boost_; @@ -108,14 +108,14 @@ class SetTimerSlackAction : public ProfileAction { SetTimerSlackAction(unsigned long slack) noexcept : slack_(slack) {} const char* Name() const override { return "SetTimerSlack"; } - bool ExecuteForTask(int tid) const override; + bool ExecuteForTask(pid_t tid) const override; bool IsValidForProcess(uid_t uid, pid_t pid) const override { return true; } - bool IsValidForTask(int tid) const override { return true; } + bool IsValidForTask(pid_t tid) const override { return true; } private: unsigned long slack_; - static bool IsTimerSlackSupported(int tid); + static bool IsTimerSlackSupported(pid_t tid); }; // Set attribute profile element @@ -126,10 +126,10 @@ class SetAttributeAction : public ProfileAction { const char* Name() const override { return "SetAttribute"; } bool ExecuteForProcess(uid_t uid, pid_t pid) const override; - bool ExecuteForTask(int tid) const override; + bool ExecuteForTask(pid_t tid) const override; bool ExecuteForUID(uid_t uid) const override; bool IsValidForProcess(uid_t uid, pid_t pid) const override; - bool IsValidForTask(int tid) const override; + bool IsValidForTask(pid_t tid) const override; private: const IProfileAttribute* attribute_; @@ -146,11 +146,11 @@ class SetCgroupAction : public ProfileAction { const char* Name() const override { return "SetCgroup"; } bool ExecuteForProcess(uid_t uid, pid_t pid) const override; - bool ExecuteForTask(int tid) const override; + bool ExecuteForTask(pid_t tid) const override; void EnableResourceCaching(ResourceCacheType cache_type) override; void DropResourceCaching(ResourceCacheType cache_type) override; bool IsValidForProcess(uid_t uid, pid_t pid) const override; - bool IsValidForTask(int tid) const override; + bool IsValidForTask(pid_t tid) const override; const CgroupController* controller() const { return &controller_; } @@ -160,7 +160,7 @@ class SetCgroupAction : public ProfileAction { android::base::unique_fd fd_[ProfileAction::RCT_COUNT]; mutable std::mutex fd_mutex_; - bool AddTidToCgroup(int tid, int fd, ResourceCacheType cache_type) const; + bool AddTidToCgroup(pid_t tid, int fd, ResourceCacheType cache_type) const; CacheUseResult UseCachedFd(ResourceCacheType cache_type, int id) const; }; @@ -172,11 +172,11 @@ class WriteFileAction : public ProfileAction { const char* Name() const override { return "WriteFile"; } bool ExecuteForProcess(uid_t uid, pid_t pid) const override; - bool ExecuteForTask(int tid) const override; + bool ExecuteForTask(pid_t tid) const override; void EnableResourceCaching(ResourceCacheType cache_type) override; void DropResourceCaching(ResourceCacheType cache_type) override; bool IsValidForProcess(uid_t uid, pid_t pid) const override; - bool IsValidForTask(int tid) const override; + bool IsValidForTask(pid_t tid) const override; private: std::string task_path_, proc_path_, value_; @@ -184,8 +184,8 @@ class WriteFileAction : public ProfileAction { android::base::unique_fd fd_[ProfileAction::RCT_COUNT]; mutable std::mutex fd_mutex_; - bool WriteValueToFile(const std::string& value, ResourceCacheType cache_type, int uid, int pid, - bool logfailures) const; + bool WriteValueToFile(const std::string& value, ResourceCacheType cache_type, uid_t uid, + pid_t pid, bool logfailures) const; CacheUseResult UseCachedFd(ResourceCacheType cache_type, const std::string& value) const; }; @@ -198,12 +198,12 @@ class TaskProfile { void MoveTo(TaskProfile* profile); bool ExecuteForProcess(uid_t uid, pid_t pid) const; - bool ExecuteForTask(int tid) const; + bool ExecuteForTask(pid_t tid) const; bool ExecuteForUID(uid_t uid) const; void EnableResourceCaching(ProfileAction::ResourceCacheType cache_type); void DropResourceCaching(ProfileAction::ResourceCacheType cache_type); bool IsValidForProcess(uid_t uid, pid_t pid) const; - bool IsValidForTask(int tid) const; + bool IsValidForTask(pid_t tid) const; private: const std::string name_; @@ -219,11 +219,11 @@ class ApplyProfileAction : public ProfileAction { const char* Name() const override { return "ApplyProfileAction"; } bool ExecuteForProcess(uid_t uid, pid_t pid) const override; - bool ExecuteForTask(int tid) const override; + bool ExecuteForTask(pid_t tid) const override; void EnableResourceCaching(ProfileAction::ResourceCacheType cache_type) override; void DropResourceCaching(ProfileAction::ResourceCacheType cache_type) override; bool IsValidForProcess(uid_t uid, pid_t pid) const override; - bool IsValidForTask(int tid) const override; + bool IsValidForTask(pid_t tid) const override; private: std::vector> profiles_; @@ -240,7 +240,7 @@ class TaskProfiles { template bool SetProcessProfiles(uid_t uid, pid_t pid, std::span profiles, bool use_fd_cache); template - bool SetTaskProfiles(int tid, std::span profiles, bool use_fd_cache); + bool SetTaskProfiles(pid_t tid, std::span profiles, bool use_fd_cache); template bool SetUserProfiles(uid_t uid, std::span profiles, bool use_fd_cache);