Fix monitor for Android-ARM64

PiperOrigin-RevId: 431926820
Change-Id: Ie5adc1ec6accc7e68782c26b65fac0c32cded498
This commit is contained in:
Sandboxed API Team 2022-03-02 06:42:10 -08:00 committed by Copybara-Service
parent 692f0260b3
commit 3f042fa54f
2 changed files with 12 additions and 5 deletions

View File

@ -598,10 +598,17 @@ bool Monitor::InitSendCwd() {
return true; return true;
} }
bool Monitor::InitApplyLimit(pid_t pid, __rlimit_resource resource, bool Monitor::InitApplyLimit(pid_t pid, int resource,
const rlimit64& rlim) const { const rlimit64& rlim) const {
#if defined(__ANDROID__)
using RlimitResource = int;
#else
using RlimitResource = __rlimit_resource;
#endif
rlimit64 curr_limit; rlimit64 curr_limit;
if (prlimit64(pid, resource, nullptr, &curr_limit) == -1) { if (prlimit64(pid, static_cast<RlimitResource>(resource), nullptr,
&curr_limit) == -1) {
PLOG(ERROR) << "prlimit64(" << pid << ", " << util::GetRlimitName(resource) PLOG(ERROR) << "prlimit64(" << pid << ", " << util::GetRlimitName(resource)
<< ")"; << ")";
} else if (rlim.rlim_cur > curr_limit.rlim_max) { } else if (rlim.rlim_cur > curr_limit.rlim_max) {
@ -613,7 +620,8 @@ bool Monitor::InitApplyLimit(pid_t pid, __rlimit_resource resource,
return true; return true;
} }
if (prlimit64(pid, resource, &rlim, nullptr) == -1) { if (prlimit64(pid, static_cast<RlimitResource>(resource), &rlim, nullptr) ==
-1) {
PLOG(ERROR) << "prlimit64(" << pid << ", " << util::GetRlimitName(resource) PLOG(ERROR) << "prlimit64(" << pid << ", " << util::GetRlimitName(resource)
<< ", " << rlim.rlim_cur << ")"; << ", " << rlim.rlim_cur << ")";
return false; return false;

View File

@ -94,8 +94,7 @@ class Monitor final {
bool InitApplyLimits(); bool InitApplyLimits();
// Applies individual limit on the sandboxee. // Applies individual limit on the sandboxee.
bool InitApplyLimit(pid_t pid, __rlimit_resource resource, bool InitApplyLimit(pid_t pid, int resource, const rlimit64& rlim) const;
const rlimit64& rlim) const;
// Kills the main traced PID with PTRACE_KILL. // Kills the main traced PID with PTRACE_KILL.
void KillSandboxee(); void KillSandboxee();