summaryrefslogtreecommitdiffstats
path: root/libc
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-10-28 17:14:48 -0700
committerSteve Kondik <steve@cyngn.com>2016-03-09 02:01:46 -0800
commit4954aab7dfaab4709cdf973c71c4e39419489729 (patch)
tree1d4cb33175890320792a89179ec0a482d17343fe /libc
parent02b1d48d51ffed14442390c80e773f3ac89396ff (diff)
downloadbionic-4954aab7dfaab4709cdf973c71c4e39419489729.tar.gz
bionic-4954aab7dfaab4709cdf973c71c4e39419489729.tar.bz2
bionic-4954aab7dfaab4709cdf973c71c4e39419489729.zip
Add prlimit to LP32.
Bug: http://b/24918750 Change-Id: I0151cd66ccf79a6169610de35bb9c288c0fa4917
Diffstat (limited to 'libc')
-rw-r--r--libc/bionic/legacy_32_bit_support.cpp19
-rw-r--r--libc/include/sys/resource.h3
2 files changed, 19 insertions, 3 deletions
diff --git a/libc/bionic/legacy_32_bit_support.cpp b/libc/bionic/legacy_32_bit_support.cpp
index a10766471..1336b4399 100644
--- a/libc/bionic/legacy_32_bit_support.cpp
+++ b/libc/bionic/legacy_32_bit_support.cpp
@@ -91,3 +91,22 @@ int getrlimit64(int resource, rlimit64* limits64) {
int setrlimit64(int resource, const rlimit64* limits64) {
return prlimit64(0, resource, limits64, NULL);
}
+
+// There is no prlimit system call, so we need to use prlimit64.
+int prlimit(pid_t pid, int resource, const rlimit* n32, rlimit* o32) {
+ rlimit64 n64;
+ if (n32 != nullptr) {
+ n64.rlim_cur = (n32->rlim_cur == RLIM_INFINITY) ? RLIM64_INFINITY : n32->rlim_cur;
+ n64.rlim_max = (n32->rlim_max == RLIM_INFINITY) ? RLIM64_INFINITY : n32->rlim_max;
+ }
+
+ rlimit64 o64;
+ int result = prlimit64(pid, resource,
+ (n32 != nullptr) ? &n64 : nullptr,
+ (o32 != nullptr) ? &o64 : nullptr);
+ if (result != -1 && o32 != nullptr) {
+ o32->rlim_cur = (o64.rlim_cur == RLIM64_INFINITY) ? RLIM_INFINITY : o64.rlim_cur;
+ o32->rlim_max = (o64.rlim_max == RLIM64_INFINITY) ? RLIM_INFINITY : o64.rlim_max;
+ }
+ return result;
+}
diff --git a/libc/include/sys/resource.h b/libc/include/sys/resource.h
index 3f8dd4571..8209dfb72 100644
--- a/libc/include/sys/resource.h
+++ b/libc/include/sys/resource.h
@@ -53,10 +53,7 @@ extern int setpriority(int, int, int);
extern int getrusage(int, struct rusage*);
-#if __LP64__
-/* Implementing prlimit for 32-bit isn't worth the effort. */
extern int prlimit(pid_t, int, const struct rlimit*, struct rlimit*);
-#endif
extern int prlimit64(pid_t, int, const struct rlimit64*, struct rlimit64*);
__END_DECLS