From 8bf5940012162997c2927c7c6c3bf725ae76c842 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Fri, 1 Apr 2022 12:24:22 +0900 Subject: [PATCH] c wrapper for SetProcessProfiles The wrapper is to call SetProcessFiles (C++ API) from crosvm via FFI. Bug: 223790172 Bug: 216788146 Test: m Change-Id: If342ca0d19deb1cb7ee581bba2cc543385199cbe --- libprocessgroup/processgroup.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp index 54772b6f9..edda41428 100644 --- a/libprocessgroup/processgroup.cpp +++ b/libprocessgroup/processgroup.cpp @@ -159,6 +159,20 @@ bool SetTaskProfiles(int tid, const std::vector& profiles, bool use return TaskProfiles::GetInstance().SetTaskProfiles(tid, profiles, use_fd_cache); } +// C wrapper for SetProcessProfiles. +// No need to have this in the header file because this function is specifically for crosvm. Crosvm +// which is written in Rust has its own declaration of this foreign function and doesn't rely on the +// header. See +// 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 profiles_(num_profiles); + for (size_t i = 0; i < num_profiles; i++) { + profiles_.emplace_back(profiles[i]); + } + return SetProcessProfiles(uid, pid, profiles_); +} + static std::string ConvertUidToPath(const char* cgroup, uid_t uid) { return StringPrintf("%s/uid_%d", cgroup, uid); }