Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7b9e7e10 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "libprocessgroup: Provide SetProcessProfiles() and SetTaskProfiles()...

Merge "libprocessgroup: Provide SetProcessProfiles() and SetTaskProfiles() alternatives" am: 7bc4533a am: 30ba7697 am: 240d11c5 am: ccdc353a am: 5202a3d9

Original change: https://android-review.googlesource.com/c/platform/system/core/+/2174784



Change-Id: I49ba37701965e1818c8386b30b830c6e10d1944b
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 82dbf877 5202a3d9
Loading
Loading
Loading
Loading
+16 −0
Original line number Original line Diff line number Diff line
@@ -18,7 +18,10 @@


#include <sys/cdefs.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/types.h>
#include <initializer_list>
#include <span>
#include <string>
#include <string>
#include <string_view>
#include <vector>
#include <vector>


__BEGIN_DECLS
__BEGIN_DECLS
@@ -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 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);
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__
#ifndef __ANDROID_VNDK__


bool SetProcessProfilesCached(uid_t uid, pid_t pid, const std::vector<std::string>& profiles);
bool SetProcessProfilesCached(uid_t uid, pid_t pid, const std::vector<std::string>& profiles);
+24 −3
Original line number Original line Diff line number Diff line
@@ -148,14 +148,35 @@ void DropTaskProfilesResourceCaching() {
}
}


bool SetProcessProfiles(uid_t uid, pid_t pid, const std::vector<std::string>& profiles) {
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);
    return TaskProfiles::GetInstance().SetProcessProfiles(uid, pid, profiles, false);
}
}


bool SetProcessProfilesCached(uid_t uid, pid_t pid, const std::vector<std::string>& profiles) {
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) {
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);
    return TaskProfiles::GetInstance().SetTaskProfiles(tid, profiles, use_fd_cache);
}
}


@@ -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
// 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,
extern "C" bool android_set_process_profiles(uid_t uid, pid_t pid, size_t num_profiles,
                                             const char* profiles[]) {
                                             const char* profiles[]) {
    std::vector<std::string> profiles_;
    std::vector<std::string_view> profiles_;
    profiles_.reserve(num_profiles);
    profiles_.reserve(num_profiles);
    for (size_t i = 0; i < num_profiles; i++) {
    for (size_t i = 0; i < num_profiles; i++) {
        profiles_.emplace_back(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) {
static std::string ConvertUidToPath(const char* cgroup, uid_t uid) {
+16 −4
Original line number Original line Diff line number Diff line
@@ -804,8 +804,9 @@ const IProfileAttribute* TaskProfiles::GetAttribute(std::string_view name) const
    return nullptr;
    return nullptr;
}
}


bool TaskProfiles::SetProcessProfiles(uid_t uid, pid_t pid,
template <typename T>
                                      const std::vector<std::string>& profiles, bool use_fd_cache) {
bool TaskProfiles::SetProcessProfiles(uid_t uid, pid_t pid, std::span<const T> profiles,
                                      bool use_fd_cache) {
    bool success = true;
    bool success = true;
    for (const auto& name : profiles) {
    for (const auto& name : profiles) {
        TaskProfile* profile = GetProfile(name);
        TaskProfile* profile = GetProfile(name);
@@ -825,8 +826,8 @@ bool TaskProfiles::SetProcessProfiles(uid_t uid, pid_t pid,
    return success;
    return success;
}
}


bool TaskProfiles::SetTaskProfiles(int tid, const std::vector<std::string>& profiles,
template <typename T>
                                   bool use_fd_cache) {
bool TaskProfiles::SetTaskProfiles(int tid, std::span<const T> profiles, bool use_fd_cache) {
    bool success = true;
    bool success = true;
    for (const auto& name : profiles) {
    for (const auto& name : profiles) {
        TaskProfile* profile = GetProfile(name);
        TaskProfile* profile = GetProfile(name);
@@ -845,3 +846,14 @@ bool TaskProfiles::SetTaskProfiles(int tid, const std::vector<std::string>& prof
    }
    }
    return success;
    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);
+6 −3
Original line number Original line Diff line number Diff line
@@ -18,8 +18,10 @@


#include <sys/cdefs.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/types.h>
#include <functional>
#include <map>
#include <map>
#include <mutex>
#include <mutex>
#include <span>
#include <string>
#include <string>
#include <string_view>
#include <string_view>
#include <vector>
#include <vector>
@@ -210,9 +212,10 @@ class TaskProfiles {
    TaskProfile* GetProfile(std::string_view name) const;
    TaskProfile* GetProfile(std::string_view name) const;
    const IProfileAttribute* GetAttribute(std::string_view name) const;
    const IProfileAttribute* GetAttribute(std::string_view name) const;
    void DropResourceCaching(ProfileAction::ResourceCacheType cache_type) const;
    void DropResourceCaching(ProfileAction::ResourceCacheType cache_type) const;
    bool SetProcessProfiles(uid_t uid, pid_t pid, const std::vector<std::string>& profiles,
    template <typename T>
                            bool use_fd_cache);
    bool SetProcessProfiles(uid_t uid, pid_t pid, std::span<const T> profiles, bool use_fd_cache);
    bool SetTaskProfiles(int tid, const std::vector<std::string>& profiles, bool use_fd_cache);
    template <typename T>
    bool SetTaskProfiles(int tid, std::span<const T> profiles, bool use_fd_cache);


  private:
  private:
    TaskProfiles();
    TaskProfiles();