This source file includes following definitions.
- main
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include <stdio.h>
22
23 #if defined __APPLE__ && defined __MACH__
24
25
26
27
28
29
30
31
32 int
33 main ()
34 {
35 fprintf (stderr, "Skipping test: cannot trust address space size on this platform\n");
36 return 78;
37 }
38
39 #else
40
41 #include <stdlib.h>
42 #include <string.h>
43 #include <errno.h>
44
45 #if HAVE_GETRLIMIT && HAVE_SETRLIMIT
46 # include <sys/types.h>
47 # include <sys/time.h>
48 # include <sys/resource.h>
49 #endif
50
51 #include "qemu.h"
52 #include "resource-ext.h"
53
54
55
56
57 #define NUM_ROUNDS 1000
58
59
60 #define MAX_ALLOC_ROUND 10000
61
62
63
64
65 #define MAX_ALLOC_TOTAL (NUM_ROUNDS * MAX_ALLOC_ROUND)
66
67 int
68 main (int argc, char *argv[])
69 {
70 uintptr_t initial_rusage_as;
71 int arg;
72 int result;
73
74 if (is_running_under_qemu_user ())
75 {
76 fprintf (stderr, "Skipping test: cannot trust address space size when running under QEMU\n");
77 return 79;
78 }
79
80
81
82
83 #if HAVE_GETRLIMIT && HAVE_SETRLIMIT && defined RLIMIT_DATA
84 {
85 struct rlimit limit;
86
87 if (getrlimit (RLIMIT_DATA, &limit) >= 0)
88 {
89 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > MAX_ALLOC_TOTAL)
90 limit.rlim_max = MAX_ALLOC_TOTAL;
91 limit.rlim_cur = limit.rlim_max;
92 (void) setrlimit (RLIMIT_DATA, &limit);
93 }
94 }
95 #endif
96
97
98
99 initial_rusage_as = get_rusage_as ();
100 #if !defined _AIX
101 if (initial_rusage_as == 0)
102 return 77;
103 #endif
104
105 arg = atoi (argv[1]);
106 if (arg == 0)
107 {
108 void *memory = malloc (MAX_ALLOC_TOTAL);
109 if (memory == NULL)
110 return 1;
111 memset (memory, 17, MAX_ALLOC_TOTAL);
112 result = 80;
113 }
114 else
115 {
116
117
118 int repeat;
119
120 for (repeat = 0; repeat < NUM_ROUNDS; repeat++)
121 {
122
123
124 if (fprintf (stdout, "%011000d\n", 17) == -1
125 && errno == ENOMEM)
126 return 2;
127 }
128
129 result = 0;
130 }
131
132 if (get_rusage_as () > initial_rusage_as + MAX_ALLOC_TOTAL + 100000)
133 return 3;
134
135 return result;
136 }
137
138 #endif