• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <portability.h>
18 #include <sys/resource.h>
19 #include <resource_portable.h>
20 
21 #if RLIMIT_NOFILE_PORTABLE==RLIMIT_NOFILE
22 #error Bad build environment
23 #endif
24 
mips_change_resource(int resource)25 static inline int mips_change_resource(int resource)
26 {
27     switch(resource) {
28     case RLIMIT_NOFILE_PORTABLE:
29         return RLIMIT_NOFILE;
30     case RLIMIT_AS_PORTABLE:
31         return RLIMIT_AS;
32     case RLIMIT_RSS_PORTABLE:
33         return RLIMIT_RSS;
34     case RLIMIT_NPROC_PORTABLE:
35         return RLIMIT_NPROC;
36     case RLIMIT_MEMLOCK_PORTABLE:
37         return RLIMIT_MEMLOCK;
38     }
39     return resource;
40 }
41 
42 extern int REAL(getrlimit)(int resource, struct rlimit *rlp);
WRAP(getrlimit)43 int WRAP(getrlimit)(int resource, struct rlimit *rlp)
44 {
45     return REAL(getrlimit)(mips_change_resource(resource), rlp);
46 }
47 
48 extern int REAL(setrlimit)(int resource, const struct rlimit *rlp);
WRAP(setrlimit)49 int WRAP(setrlimit)(int resource, const struct rlimit *rlp)
50 {
51     return REAL(setrlimit)(mips_change_resource(resource), rlp);
52 }
53