Loading libprocessgroup/include/processgroup/processgroup.h +16 −0 Original line number Diff line number Diff line Loading @@ -18,7 +18,10 @@ #include <sys/cdefs.h> #include <sys/types.h> #include <initializer_list> #include <span> #include <string> #include <string_view> #include <vector> __BEGIN_DECLS Loading @@ -33,6 +36,19 @@ bool CgroupGetAttributePathForTask(const std::string& attr_name, int tid, std::s bool SetTaskProfiles(int tid, const std::vector<std::string>& profiles, bool use_fd_cache = false); bool SetProcessProfiles(uid_t uid, pid_t pid, const std::vector<std::string>& profiles); __END_DECLS bool SetTaskProfiles(int tid, std::initializer_list<std::string_view> profiles, bool use_fd_cache = false); bool SetProcessProfiles(uid_t uid, pid_t pid, std::initializer_list<std::string_view> profiles); #if _LIBCPP_STD_VER > 17 bool SetTaskProfiles(int tid, std::span<const std::string_view> profiles, bool use_fd_cache = false); bool SetProcessProfiles(uid_t uid, pid_t pid, std::span<const std::string_view> profiles); #endif __BEGIN_DECLS #ifndef __ANDROID_VNDK__ bool SetProcessProfilesCached(uid_t uid, pid_t pid, const std::vector<std::string>& profiles); Loading libprocessgroup/processgroup.cpp +24 −3 Original line number Diff line number Diff line Loading @@ -148,14 +148,35 @@ void DropTaskProfilesResourceCaching() { } bool SetProcessProfiles(uid_t uid, pid_t pid, const std::vector<std::string>& profiles) { return TaskProfiles::GetInstance().SetProcessProfiles( uid, pid, std::span<const std::string>(profiles), false); } bool SetProcessProfiles(uid_t uid, pid_t pid, std::initializer_list<std::string_view> profiles) { return TaskProfiles::GetInstance().SetProcessProfiles( uid, pid, std::span<const std::string_view>(profiles), false); } bool SetProcessProfiles(uid_t uid, pid_t pid, std::span<const std::string_view> profiles) { return TaskProfiles::GetInstance().SetProcessProfiles(uid, pid, profiles, false); } bool SetProcessProfilesCached(uid_t uid, pid_t pid, const std::vector<std::string>& profiles) { return TaskProfiles::GetInstance().SetProcessProfiles(uid, pid, profiles, true); return TaskProfiles::GetInstance().SetProcessProfiles( uid, pid, std::span<const std::string>(profiles), true); } bool SetTaskProfiles(int tid, const std::vector<std::string>& profiles, bool use_fd_cache) { return TaskProfiles::GetInstance().SetTaskProfiles(tid, std::span<const std::string>(profiles), use_fd_cache); } bool SetTaskProfiles(int tid, std::initializer_list<std::string_view> profiles, bool use_fd_cache) { return TaskProfiles::GetInstance().SetTaskProfiles( tid, std::span<const std::string_view>(profiles), use_fd_cache); } bool SetTaskProfiles(int tid, std::span<const std::string_view> profiles, bool use_fd_cache) { return TaskProfiles::GetInstance().SetTaskProfiles(tid, profiles, use_fd_cache); } Loading @@ -166,12 +187,12 @@ bool SetTaskProfiles(int tid, const std::vector<std::string>& profiles, bool use // https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3574427/5/src/linux/android.rs#12 extern "C" bool android_set_process_profiles(uid_t uid, pid_t pid, size_t num_profiles, const char* profiles[]) { std::vector<std::string> profiles_; std::vector<std::string_view> profiles_; profiles_.reserve(num_profiles); for (size_t i = 0; i < num_profiles; i++) { profiles_.emplace_back(profiles[i]); } return SetProcessProfiles(uid, pid, profiles_); return SetProcessProfiles(uid, pid, std::span<const std::string_view>(profiles_)); } static std::string ConvertUidToPath(const char* cgroup, uid_t uid) { Loading libprocessgroup/task_profiles.cpp +16 −4 Original line number Diff line number Diff line Loading @@ -804,8 +804,9 @@ const IProfileAttribute* TaskProfiles::GetAttribute(std::string_view name) const return nullptr; } bool TaskProfiles::SetProcessProfiles(uid_t uid, pid_t pid, const std::vector<std::string>& profiles, bool use_fd_cache) { template <typename T> bool TaskProfiles::SetProcessProfiles(uid_t uid, pid_t pid, std::span<const T> profiles, bool use_fd_cache) { bool success = true; for (const auto& name : profiles) { TaskProfile* profile = GetProfile(name); Loading @@ -825,8 +826,8 @@ bool TaskProfiles::SetProcessProfiles(uid_t uid, pid_t pid, return success; } bool TaskProfiles::SetTaskProfiles(int tid, const std::vector<std::string>& profiles, bool use_fd_cache) { template <typename T> bool TaskProfiles::SetTaskProfiles(int tid, std::span<const T> profiles, bool use_fd_cache) { bool success = true; for (const auto& name : profiles) { TaskProfile* profile = GetProfile(name); Loading @@ -845,3 +846,14 @@ bool TaskProfiles::SetTaskProfiles(int tid, const std::vector<std::string>& prof } return success; } template bool TaskProfiles::SetProcessProfiles(uid_t uid, pid_t pid, std::span<const std::string> profiles, bool use_fd_cache); template bool TaskProfiles::SetProcessProfiles(uid_t uid, pid_t pid, std::span<const std::string_view> profiles, bool use_fd_cache); template bool TaskProfiles::SetTaskProfiles(int tid, std::span<const std::string> profiles, bool use_fd_cache); template bool TaskProfiles::SetTaskProfiles(int tid, std::span<const std::string_view> profiles, bool use_fd_cache); libprocessgroup/task_profiles.h +6 −3 Original line number Diff line number Diff line Loading @@ -18,8 +18,10 @@ #include <sys/cdefs.h> #include <sys/types.h> #include <functional> #include <map> #include <mutex> #include <span> #include <string> #include <string_view> #include <vector> Loading Loading @@ -210,9 +212,10 @@ class TaskProfiles { TaskProfile* GetProfile(std::string_view name) const; const IProfileAttribute* GetAttribute(std::string_view name) const; void DropResourceCaching(ProfileAction::ResourceCacheType cache_type) const; bool SetProcessProfiles(uid_t uid, pid_t pid, const std::vector<std::string>& profiles, bool use_fd_cache); bool SetTaskProfiles(int tid, const std::vector<std::string>& profiles, bool use_fd_cache); template <typename T> bool SetProcessProfiles(uid_t uid, pid_t pid, std::span<const T> profiles, bool use_fd_cache); template <typename T> bool SetTaskProfiles(int tid, std::span<const T> profiles, bool use_fd_cache); private: TaskProfiles(); Loading Loading
libprocessgroup/include/processgroup/processgroup.h +16 −0 Original line number Diff line number Diff line Loading @@ -18,7 +18,10 @@ #include <sys/cdefs.h> #include <sys/types.h> #include <initializer_list> #include <span> #include <string> #include <string_view> #include <vector> __BEGIN_DECLS Loading @@ -33,6 +36,19 @@ bool CgroupGetAttributePathForTask(const std::string& attr_name, int tid, std::s bool SetTaskProfiles(int tid, const std::vector<std::string>& profiles, bool use_fd_cache = false); bool SetProcessProfiles(uid_t uid, pid_t pid, const std::vector<std::string>& profiles); __END_DECLS bool SetTaskProfiles(int tid, std::initializer_list<std::string_view> profiles, bool use_fd_cache = false); bool SetProcessProfiles(uid_t uid, pid_t pid, std::initializer_list<std::string_view> profiles); #if _LIBCPP_STD_VER > 17 bool SetTaskProfiles(int tid, std::span<const std::string_view> profiles, bool use_fd_cache = false); bool SetProcessProfiles(uid_t uid, pid_t pid, std::span<const std::string_view> profiles); #endif __BEGIN_DECLS #ifndef __ANDROID_VNDK__ bool SetProcessProfilesCached(uid_t uid, pid_t pid, const std::vector<std::string>& profiles); Loading
libprocessgroup/processgroup.cpp +24 −3 Original line number Diff line number Diff line Loading @@ -148,14 +148,35 @@ void DropTaskProfilesResourceCaching() { } bool SetProcessProfiles(uid_t uid, pid_t pid, const std::vector<std::string>& profiles) { return TaskProfiles::GetInstance().SetProcessProfiles( uid, pid, std::span<const std::string>(profiles), false); } bool SetProcessProfiles(uid_t uid, pid_t pid, std::initializer_list<std::string_view> profiles) { return TaskProfiles::GetInstance().SetProcessProfiles( uid, pid, std::span<const std::string_view>(profiles), false); } bool SetProcessProfiles(uid_t uid, pid_t pid, std::span<const std::string_view> profiles) { return TaskProfiles::GetInstance().SetProcessProfiles(uid, pid, profiles, false); } bool SetProcessProfilesCached(uid_t uid, pid_t pid, const std::vector<std::string>& profiles) { return TaskProfiles::GetInstance().SetProcessProfiles(uid, pid, profiles, true); return TaskProfiles::GetInstance().SetProcessProfiles( uid, pid, std::span<const std::string>(profiles), true); } bool SetTaskProfiles(int tid, const std::vector<std::string>& profiles, bool use_fd_cache) { return TaskProfiles::GetInstance().SetTaskProfiles(tid, std::span<const std::string>(profiles), use_fd_cache); } bool SetTaskProfiles(int tid, std::initializer_list<std::string_view> profiles, bool use_fd_cache) { return TaskProfiles::GetInstance().SetTaskProfiles( tid, std::span<const std::string_view>(profiles), use_fd_cache); } bool SetTaskProfiles(int tid, std::span<const std::string_view> profiles, bool use_fd_cache) { return TaskProfiles::GetInstance().SetTaskProfiles(tid, profiles, use_fd_cache); } Loading @@ -166,12 +187,12 @@ bool SetTaskProfiles(int tid, const std::vector<std::string>& profiles, bool use // https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3574427/5/src/linux/android.rs#12 extern "C" bool android_set_process_profiles(uid_t uid, pid_t pid, size_t num_profiles, const char* profiles[]) { std::vector<std::string> profiles_; std::vector<std::string_view> profiles_; profiles_.reserve(num_profiles); for (size_t i = 0; i < num_profiles; i++) { profiles_.emplace_back(profiles[i]); } return SetProcessProfiles(uid, pid, profiles_); return SetProcessProfiles(uid, pid, std::span<const std::string_view>(profiles_)); } static std::string ConvertUidToPath(const char* cgroup, uid_t uid) { Loading
libprocessgroup/task_profiles.cpp +16 −4 Original line number Diff line number Diff line Loading @@ -804,8 +804,9 @@ const IProfileAttribute* TaskProfiles::GetAttribute(std::string_view name) const return nullptr; } bool TaskProfiles::SetProcessProfiles(uid_t uid, pid_t pid, const std::vector<std::string>& profiles, bool use_fd_cache) { template <typename T> bool TaskProfiles::SetProcessProfiles(uid_t uid, pid_t pid, std::span<const T> profiles, bool use_fd_cache) { bool success = true; for (const auto& name : profiles) { TaskProfile* profile = GetProfile(name); Loading @@ -825,8 +826,8 @@ bool TaskProfiles::SetProcessProfiles(uid_t uid, pid_t pid, return success; } bool TaskProfiles::SetTaskProfiles(int tid, const std::vector<std::string>& profiles, bool use_fd_cache) { template <typename T> bool TaskProfiles::SetTaskProfiles(int tid, std::span<const T> profiles, bool use_fd_cache) { bool success = true; for (const auto& name : profiles) { TaskProfile* profile = GetProfile(name); Loading @@ -845,3 +846,14 @@ bool TaskProfiles::SetTaskProfiles(int tid, const std::vector<std::string>& prof } return success; } template bool TaskProfiles::SetProcessProfiles(uid_t uid, pid_t pid, std::span<const std::string> profiles, bool use_fd_cache); template bool TaskProfiles::SetProcessProfiles(uid_t uid, pid_t pid, std::span<const std::string_view> profiles, bool use_fd_cache); template bool TaskProfiles::SetTaskProfiles(int tid, std::span<const std::string> profiles, bool use_fd_cache); template bool TaskProfiles::SetTaskProfiles(int tid, std::span<const std::string_view> profiles, bool use_fd_cache);
libprocessgroup/task_profiles.h +6 −3 Original line number Diff line number Diff line Loading @@ -18,8 +18,10 @@ #include <sys/cdefs.h> #include <sys/types.h> #include <functional> #include <map> #include <mutex> #include <span> #include <string> #include <string_view> #include <vector> Loading Loading @@ -210,9 +212,10 @@ class TaskProfiles { TaskProfile* GetProfile(std::string_view name) const; const IProfileAttribute* GetAttribute(std::string_view name) const; void DropResourceCaching(ProfileAction::ResourceCacheType cache_type) const; bool SetProcessProfiles(uid_t uid, pid_t pid, const std::vector<std::string>& profiles, bool use_fd_cache); bool SetTaskProfiles(int tid, const std::vector<std::string>& profiles, bool use_fd_cache); template <typename T> bool SetProcessProfiles(uid_t uid, pid_t pid, std::span<const T> profiles, bool use_fd_cache); template <typename T> bool SetTaskProfiles(int tid, std::span<const T> profiles, bool use_fd_cache); private: TaskProfiles(); Loading