1 /**
2  * Copyright (C) 2018 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 #define _GNU_SOURCE
17 #include <sys/types.h>
18 #include <sys/wait.h>
19 
20 #include <errno.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <sys/resource.h>
24 #include <sys/time.h>
25 #include <unistd.h>
26 
main(void)27 int main(void) {
28   struct rlimit rlim;
29   size_t i;
30 
31   int result = getrlimit(RLIMIT_AS, &rlim);
32   printf("%lu\n", rlim.rlim_cur);
33   printf("%lu\n", rlim.rlim_max);
34 
35   rlim.rlim_cur = 384 * 1024 * 1024;
36   result = setrlimit(RLIMIT_AS, &rlim);
37 
38   /*
39    * Issue exists only in kitkat. It passes in
40    * android M onwards. In failure scenario, device reboots.
41    */
42   size_t to_alloc = 1.6 * 1024 * 1024 * 1024;
43   char *mem = (char *)malloc(to_alloc);
44 
45   printf("%p\n", mem);
46   if (mem) {
47     for (i = 0; i < to_alloc; i++) {
48       mem[i] = 0;
49     }
50     printf("filled\n");
51   }
52 
53   free(mem);
54   return 0;
55 }
56