diff options
author | Thomas Petazzoni <thomas.petazzoni@free-electrons.com> | 2008-07-25 04:45:44 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-25 13:53:28 -0400 |
commit | 2d6ffcca623a9a16df6cdfbe8250b7a5904a5f5e (patch) | |
tree | 70d30cb6516608e9a8a1dce60c59f3a5ff21b305 | |
parent | ba92a43dbaee339cf5915ef766d3d3ffbaaf103c (diff) |
inflate: refactor inflate malloc code
Inflate requires some dynamic memory allocation very early in the boot
process and this is provided with a set of four functions:
malloc/free/gzip_mark/gzip_release.
The old inflate code used a mark/release strategy rather than implement
free. This new version instead keeps a count on the number of outstanding
allocations and when it hits zero, it resets the malloc arena.
This allows removing all the mark and release implementations and unifying
all the malloc/free implementations.
The architecture-dependent code must define two addresses:
- free_mem_ptr, the address of the beginning of the area in which
allocations should be made
- free_mem_end_ptr, the address of the end of the area in which
allocations should be made. If set to 0, then no check is made on
the number of allocations, it just grows as much as needed
The architecture-dependent code can also provide an arch_decomp_wdog()
function call. This function will be called several times during the
decompression process, and allow to notify the watchdog that the system is
still running. If an architecture provides such a call, then it must
define ARCH_HAS_DECOMP_WDOG so that the generic inflate code calls
arch_decomp_wdog().
Work initially done by Matt Mackall, updated to a recent version of the
kernel and improved by me.
[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Cc: Matt Mackall <mpm@selenic.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Mikael Starvik <mikael.starvik@axis.com>
Cc: Jesper Nilsson <jesper.nilsson@axis.com>
Cc: Haavard Skinnemoen <hskinnemoen@atmel.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Acked-by: Paul Mundt <lethal@linux-sh.org>
Acked-by: Yoshinori Sato <ysato@users.sourceforge.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | arch/alpha/boot/misc.c | 39 | ||||
-rw-r--r-- | arch/arm/boot/compressed/misc.c | 59 | ||||
-rw-r--r-- | arch/cris/arch-v10/boot/compressed/misc.c | 36 | ||||
-rw-r--r-- | arch/cris/arch-v32/boot/compressed/misc.c | 39 | ||||
-rw-r--r-- | arch/h8300/boot/compressed/misc.c | 38 | ||||
-rw-r--r-- | arch/m32r/boot/compressed/misc.c | 37 | ||||
-rw-r--r-- | arch/mn10300/boot/compressed/misc.c | 37 | ||||
-rw-r--r-- | arch/sh/boot/compressed/misc_32.c | 38 | ||||
-rw-r--r-- | arch/sh/boot/compressed/misc_64.c | 40 | ||||
-rw-r--r-- | arch/x86/boot/compressed/misc.c | 39 | ||||
-rw-r--r-- | init/do_mounts_rd.c | 25 | ||||
-rw-r--r-- | init/initramfs.c | 22 | ||||
-rw-r--r-- | lib/inflate.c | 52 |
13 files changed, 62 insertions, 439 deletions
diff --git a/arch/alpha/boot/misc.c b/arch/alpha/boot/misc.c index c00646b25f6e..3047a1b3a517 100644 --- a/arch/alpha/boot/misc.c +++ b/arch/alpha/boot/misc.c | |||
@@ -78,8 +78,6 @@ static unsigned outcnt; /* bytes in output buffer */ | |||
78 | static int fill_inbuf(void); | 78 | static int fill_inbuf(void); |
79 | static void flush_window(void); | 79 | static void flush_window(void); |
80 | static void error(char *m); | 80 | static void error(char *m); |
81 | static void gzip_mark(void **); | ||
82 | static void gzip_release(void **); | ||
83 | 81 | ||
84 | static char *input_data; | 82 | static char *input_data; |
85 | static int input_data_size; | 83 | static int input_data_size; |
@@ -88,51 +86,18 @@ static uch *output_data; | |||
88 | static ulg output_ptr; | 86 | static ulg output_ptr; |
89 | static ulg bytes_out; | 87 | static ulg bytes_out; |
90 | 88 | ||
91 | static void *malloc(int size); | ||
92 | static void free(void *where); | ||
93 | static void error(char *m); | 89 | static void error(char *m); |
94 | static void gzip_mark(void **); | 90 | static void gzip_mark(void **); |
95 | static void gzip_release(void **); | 91 | static void gzip_release(void **); |
96 | 92 | ||
97 | extern int end; | 93 | extern int end; |
98 | static ulg free_mem_ptr; | 94 | static ulg free_mem_ptr; |
99 | static ulg free_mem_ptr_end; | 95 | static ulg free_mem_end_ptr; |
100 | 96 | ||
101 | #define HEAP_SIZE 0x3000 | 97 | #define HEAP_SIZE 0x3000 |
102 | 98 | ||
103 | #include "../../../lib/inflate.c" | 99 | #include "../../../lib/inflate.c" |
104 | 100 | ||
105 | static void *malloc(int size) | ||
106 | { | ||
107 | void *p; | ||
108 | |||
109 | if (size <0) error("Malloc error"); | ||
110 | if (free_mem_ptr <= 0) error("Memory error"); | ||
111 | |||
112 | free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */ | ||
113 | |||
114 | p = (void *)free_mem_ptr; | ||
115 | free_mem_ptr += size; | ||
116 | |||
117 | if (free_mem_ptr >= free_mem_ptr_end) | ||
118 | error("Out of memory"); | ||
119 | return p; | ||
120 | } | ||
121 | |||
122 | static void free(void *where) | ||
123 | { /* gzip_mark & gzip_release do the free */ | ||
124 | } | ||
125 | |||
126 | static void gzip_mark(void **ptr) | ||
127 | { | ||
128 | *ptr = (void *) free_mem_ptr; | ||
129 | } | ||
130 | |||
131 | static void gzip_release(void **ptr) | ||
132 | { | ||
133 | free_mem_ptr = (long) *ptr; | ||
134 | } | ||
135 | |||
136 | /* =========================================================================== | 101 | /* =========================================================================== |
137 | * Fill the input buffer. This is called only when the buffer is empty | 102 | * Fill the input buffer. This is called only when the buffer is empty |
138 | * and at least one byte is really needed. | 103 | * and at least one byte is really needed. |
@@ -193,7 +158,7 @@ decompress_kernel(void *output_start, | |||
193 | 158 | ||
194 | /* FIXME FIXME FIXME */ | 159 | /* FIXME FIXME FIXME */ |
195 | free_mem_ptr = (ulg)output_start + ksize; | 160 | free_mem_ptr = (ulg)output_start + ksize; |
196 | free_mem_ptr_end = (ulg)output_start + ksize + 0x200000; | 161 | free_mem_end_ptr = (ulg)output_start + ksize + 0x200000; |
197 | /* FIXME FIXME FIXME */ | 162 | /* FIXME FIXME FIXME */ |
198 | 163 | ||
199 | /* put in temp area to reduce initial footprint */ | 164 | /* put in temp area to reduce initial footprint */ |
diff --git a/arch/arm/boot/compressed/misc.c b/arch/arm/boot/compressed/misc.c index 9b444022cb9b..7145cc7c04f0 100644 --- a/arch/arm/boot/compressed/misc.c +++ b/arch/arm/boot/compressed/misc.c | |||
@@ -217,8 +217,6 @@ static unsigned outcnt; /* bytes in output buffer */ | |||
217 | static int fill_inbuf(void); | 217 | static int fill_inbuf(void); |
218 | static void flush_window(void); | 218 | static void flush_window(void); |
219 | static void error(char *m); | 219 | static void error(char *m); |
220 | static void gzip_mark(void **); | ||
221 | static void gzip_release(void **); | ||
222 | 220 | ||
223 | extern char input_data[]; | 221 | extern char input_data[]; |
224 | extern char input_data_end[]; | 222 | extern char input_data_end[]; |
@@ -227,64 +225,21 @@ static uch *output_data; | |||
227 | static ulg output_ptr; | 225 | static ulg output_ptr; |
228 | static ulg bytes_out; | 226 | static ulg bytes_out; |
229 | 227 | ||
230 | static void *malloc(int size); | ||
231 | static void free(void *where); | ||
232 | static void error(char *m); | 228 | static void error(char *m); |
233 | static void gzip_mark(void **); | ||
234 | static void gzip_release(void **); | ||
235 | 229 | ||
236 | static void putstr(const char *); | 230 | static void putstr(const char *); |
237 | 231 | ||
238 | extern int end; | 232 | extern int end; |
239 | static ulg free_mem_ptr; | 233 | static ulg free_mem_ptr; |
240 | static ulg free_mem_ptr_end; | 234 | static ulg free_mem_end_ptr; |
241 | 235 | ||
242 | #define HEAP_SIZE 0x3000 | 236 | #ifdef STANDALONE_DEBUG |
243 | 237 | #define NO_INFLATE_MALLOC | |
244 | #include "../../../../lib/inflate.c" | 238 | #endif |
245 | |||
246 | #ifndef STANDALONE_DEBUG | ||
247 | static void *malloc(int size) | ||
248 | { | ||
249 | void *p; | ||
250 | |||
251 | if (size <0) error("Malloc error"); | ||
252 | if (free_mem_ptr <= 0) error("Memory error"); | ||
253 | |||
254 | free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */ | ||
255 | |||
256 | p = (void *)free_mem_ptr; | ||
257 | free_mem_ptr += size; | ||
258 | |||
259 | if (free_mem_ptr >= free_mem_ptr_end) | ||
260 | error("Out of memory"); | ||
261 | return p; | ||
262 | } | ||
263 | |||
264 | static void free(void *where) | ||
265 | { /* gzip_mark & gzip_release do the free */ | ||
266 | } | ||
267 | |||
268 | static void gzip_mark(void **ptr) | ||
269 | { | ||
270 | arch_decomp_wdog(); | ||
271 | *ptr = (void *) free_mem_ptr; | ||
272 | } | ||
273 | 239 | ||
274 | static void gzip_release(void **ptr) | 240 | #define ARCH_HAS_DECOMP_WDOG |
275 | { | ||
276 | arch_decomp_wdog(); | ||
277 | free_mem_ptr = (long) *ptr; | ||
278 | } | ||
279 | #else | ||
280 | static void gzip_mark(void **ptr) | ||
281 | { | ||
282 | } | ||
283 | 241 | ||
284 | static void gzip_release(void **ptr) | 242 | #include "../../../../lib/inflate.c" |
285 | { | ||
286 | } | ||
287 | #endif | ||
288 | 243 | ||
289 | /* =========================================================================== | 244 | /* =========================================================================== |
290 | * Fill the input buffer. This is called only when the buffer is empty | 245 | * Fill the input buffer. This is called only when the buffer is empty |
@@ -348,7 +303,7 @@ decompress_kernel(ulg output_start, ulg free_mem_ptr_p, ulg free_mem_ptr_end_p, | |||
348 | { | 303 | { |
349 | output_data = (uch *)output_start; /* Points to kernel start */ | 304 | output_data = (uch *)output_start; /* Points to kernel start */ |
350 | free_mem_ptr = free_mem_ptr_p; | 305 | free_mem_ptr = free_mem_ptr_p; |
351 | free_mem_ptr_end = free_mem_ptr_end_p; | 306 | free_mem_end_ptr = free_mem_ptr_end_p; |
352 | __machine_arch_type = arch_id; | 307 | __machine_arch_type = arch_id; |
353 | 308 | ||
354 | arch_decomp_setup(); | 309 | arch_decomp_setup(); |
diff --git a/arch/cris/arch-v10/boot/compressed/misc.c b/arch/cris/arch-v10/boot/compressed/misc.c index 18e13bce1400..d933c89889db 100644 --- a/arch/cris/arch-v10/boot/compressed/misc.c +++ b/arch/cris/arch-v10/boot/compressed/misc.c | |||
@@ -102,50 +102,16 @@ extern char *input_data; /* lives in head.S */ | |||
102 | static long bytes_out = 0; | 102 | static long bytes_out = 0; |
103 | static uch *output_data; | 103 | static uch *output_data; |
104 | static unsigned long output_ptr = 0; | 104 | static unsigned long output_ptr = 0; |
105 | |||
106 | static void *malloc(int size); | ||
107 | static void free(void *where); | ||
108 | static void gzip_mark(void **); | ||
109 | static void gzip_release(void **); | ||
110 | |||
111 | static void puts(const char *); | 105 | static void puts(const char *); |
112 | 106 | ||
113 | /* the "heap" is put directly after the BSS ends, at end */ | 107 | /* the "heap" is put directly after the BSS ends, at end */ |
114 | 108 | ||
115 | extern int _end; | 109 | extern int _end; |
116 | static long free_mem_ptr = (long)&_end; | 110 | static long free_mem_ptr = (long)&_end; |
111 | static long free_mem_end_ptr; | ||
117 | 112 | ||
118 | #include "../../../../../lib/inflate.c" | 113 | #include "../../../../../lib/inflate.c" |
119 | 114 | ||
120 | static void *malloc(int size) | ||
121 | { | ||
122 | void *p; | ||
123 | |||
124 | if (size < 0) | ||
125 | error("Malloc error"); | ||
126 | |||
127 | free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */ | ||
128 | |||
129 | p = (void *)free_mem_ptr; | ||
130 | free_mem_ptr += size; | ||
131 | |||
132 | return p; | ||
133 | } | ||
134 | |||
135 | static void free(void *where) | ||
136 | { /* Don't care */ | ||
137 | } | ||
138 | |||
139 | static void gzip_mark(void **ptr) | ||
140 | { | ||
141 | *ptr = (void *) free_mem_ptr; | ||
142 | } | ||
143 | |||
144 | static void gzip_release(void **ptr) | ||
145 | { | ||
146 | free_mem_ptr = (long) *ptr; | ||
147 | } | ||
148 | |||
149 | /* decompressor info and error messages to serial console */ | 115 | /* decompressor info and error messages to serial console */ |
150 | 116 | ||
151 | static void | 117 | static void |
diff --git a/arch/cris/arch-v32/boot/compressed/misc.c b/arch/cris/arch-v32/boot/compressed/misc.c index 55b2695c5d70..3595e16e82bc 100644 --- a/arch/cris/arch-v32/boot/compressed/misc.c +++ b/arch/cris/arch-v32/boot/compressed/misc.c | |||
@@ -89,20 +89,14 @@ static unsigned outcnt = 0; /* bytes in output buffer */ | |||
89 | 89 | ||
90 | static void flush_window(void); | 90 | static void flush_window(void); |
91 | static void error(char *m); | 91 | static void error(char *m); |
92 | static void gzip_mark(void **); | ||
93 | static void gzip_release(void **); | ||
94 | 92 | ||
95 | extern char *input_data; /* lives in head.S */ | 93 | extern char *input_data; /* lives in head.S */ |
96 | 94 | ||
97 | static long bytes_out = 0; | 95 | static long bytes_out; |
98 | static uch *output_data; | 96 | static uch *output_data; |
99 | static unsigned long output_ptr = 0; | 97 | static unsigned long output_ptr; |
100 | 98 | ||
101 | static void *malloc(int size); | ||
102 | static void free(void *where); | ||
103 | static void error(char *m); | 99 | static void error(char *m); |
104 | static void gzip_mark(void **); | ||
105 | static void gzip_release(void **); | ||
106 | 100 | ||
107 | static void puts(const char *); | 101 | static void puts(const char *); |
108 | 102 | ||
@@ -110,37 +104,10 @@ static void puts(const char *); | |||
110 | 104 | ||
111 | extern int _end; | 105 | extern int _end; |
112 | static long free_mem_ptr = (long)&_end; | 106 | static long free_mem_ptr = (long)&_end; |
107 | static long free_mem_end_ptr; | ||
113 | 108 | ||
114 | #include "../../../../../lib/inflate.c" | 109 | #include "../../../../../lib/inflate.c" |
115 | 110 | ||
116 | static void *malloc(int size) | ||
117 | { | ||
118 | void *p; | ||
119 | |||
120 | if (size <0) error("Malloc error"); | ||
121 | |||
122 | free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */ | ||
123 | |||
124 | p = (void *)free_mem_ptr; | ||
125 | free_mem_ptr += size; | ||
126 | |||
127 | return p; | ||
128 | } | ||
129 | |||
130 | static void free(void *where) | ||
131 | { /* Don't care */ | ||
132 | } | ||
133 | |||
134 | static void gzip_mark(void **ptr) | ||
135 | { | ||
136 | *ptr = (void *) free_mem_ptr; | ||
137 | } | ||
138 | |||
139 | static void gzip_release(void **ptr) | ||
140 | { | ||
141 | free_mem_ptr = (long) *ptr; | ||
142 | } | ||
143 | |||
144 | /* decompressor info and error messages to serial console */ | 111 | /* decompressor info and error messages to serial console */ |
145 | 112 | ||
146 | static inline void | 113 | static inline void |
diff --git a/arch/h8300/boot/compressed/misc.c b/arch/h8300/boot/compressed/misc.c index 845074588af0..51ab6cbd030f 100644 --- a/arch/h8300/boot/compressed/misc.c +++ b/arch/h8300/boot/compressed/misc.c | |||
@@ -67,8 +67,6 @@ static unsigned outcnt = 0; /* bytes in output buffer */ | |||
67 | static int fill_inbuf(void); | 67 | static int fill_inbuf(void); |
68 | static void flush_window(void); | 68 | static void flush_window(void); |
69 | static void error(char *m); | 69 | static void error(char *m); |
70 | static void gzip_mark(void **); | ||
71 | static void gzip_release(void **); | ||
72 | 70 | ||
73 | extern char input_data[]; | 71 | extern char input_data[]; |
74 | extern int input_len; | 72 | extern int input_len; |
@@ -77,11 +75,7 @@ static long bytes_out = 0; | |||
77 | static uch *output_data; | 75 | static uch *output_data; |
78 | static unsigned long output_ptr = 0; | 76 | static unsigned long output_ptr = 0; |
79 | 77 | ||
80 | static void *malloc(int size); | ||
81 | static void free(void *where); | ||
82 | static void error(char *m); | 78 | static void error(char *m); |
83 | static void gzip_mark(void **); | ||
84 | static void gzip_release(void **); | ||
85 | 79 | ||
86 | int puts(const char *); | 80 | int puts(const char *); |
87 | 81 | ||
@@ -98,38 +92,6 @@ static unsigned long free_mem_end_ptr; | |||
98 | #define TDR *((volatile unsigned char *)0xffff8b) | 92 | #define TDR *((volatile unsigned char *)0xffff8b) |
99 | #define SSR *((volatile unsigned char *)0xffff8c) | 93 | #define SSR *((volatile unsigned char *)0xffff8c) |
100 | 94 | ||
101 | static void *malloc(int size) | ||
102 | { | ||
103 | void *p; | ||
104 | |||
105 | if (size <0) error("Malloc error"); | ||
106 | if (free_mem_ptr == 0) error("Memory error"); | ||
107 | |||
108 | free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */ | ||
109 | |||
110 | p = (void *)free_mem_ptr; | ||
111 | free_mem_ptr += size; | ||
112 | |||
113 | if (free_mem_ptr >= free_mem_end_ptr) | ||
114 | error("Out of memory"); | ||
115 | |||
116 | return p; | ||
117 | } | ||
118 | |||
119 | static void free(void *where) | ||
120 | { /* Don't care */ | ||
121 | } | ||
122 | |||
123 | static void gzip_mark(void **ptr) | ||
124 | { | ||
125 | *ptr = (void *) free_mem_ptr; | ||
126 | } | ||
127 | |||
128 | static void gzip_release(void **ptr) | ||
129 | { | ||
130 | free_mem_ptr = (long) *ptr; | ||
131 | } | ||
132 | |||
133 | int puts(const char *s) | 95 | int puts(const char *s) |
134 | { | 96 | { |
135 | return 0; | 97 | return 0; |
diff --git a/arch/m32r/boot/compressed/misc.c b/arch/m32r/boot/compressed/misc.c index 600d40e33495..d394292498c0 100644 --- a/arch/m32r/boot/compressed/misc.c +++ b/arch/m32r/boot/compressed/misc.c | |||
@@ -70,8 +70,6 @@ static unsigned outcnt = 0; /* bytes in output buffer */ | |||
70 | static int fill_inbuf(void); | 70 | static int fill_inbuf(void); |
71 | static void flush_window(void); | 71 | static void flush_window(void); |
72 | static void error(char *m); | 72 | static void error(char *m); |
73 | static void gzip_mark(void **); | ||
74 | static void gzip_release(void **); | ||
75 | 73 | ||
76 | static unsigned char *input_data; | 74 | static unsigned char *input_data; |
77 | static int input_len; | 75 | static int input_len; |
@@ -82,9 +80,6 @@ static unsigned long output_ptr = 0; | |||
82 | 80 | ||
83 | #include "m32r_sio.c" | 81 | #include "m32r_sio.c" |
84 | 82 | ||
85 | static void *malloc(int size); | ||
86 | static void free(void *where); | ||
87 | |||
88 | static unsigned long free_mem_ptr; | 83 | static unsigned long free_mem_ptr; |
89 | static unsigned long free_mem_end_ptr; | 84 | static unsigned long free_mem_end_ptr; |
90 | 85 | ||
@@ -92,38 +87,6 @@ static unsigned long free_mem_end_ptr; | |||
92 | 87 | ||
93 | #include "../../../../lib/inflate.c" | 88 | #include "../../../../lib/inflate.c" |
94 | 89 | ||
95 | static void *malloc(int size) | ||
96 | { | ||
97 | void *p; | ||
98 | |||
99 | if (size <0) error("Malloc error"); | ||
100 | if (free_mem_ptr == 0) error("Memory error"); | ||
101 | |||
102 | free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */ | ||
103 | |||
104 | p = (void *)free_mem_ptr; | ||
105 | free_mem_ptr += size; | ||
106 | |||
107 | if (free_mem_ptr >= free_mem_end_ptr) | ||
108 | error("Out of memory"); | ||
109 | |||
110 | return p; | ||
111 | } | ||
112 | |||
113 | static void free(void *where) | ||
114 | { /* Don't care */ | ||
115 | } | ||
116 | |||
117 | static void gzip_mark(void **ptr) | ||
118 | { | ||
119 | *ptr = (void *) free_mem_ptr; | ||
120 | } | ||
121 | |||
122 | static void gzip_release(void **ptr) | ||
123 | { | ||
124 | free_mem_ptr = (long) *ptr; | ||
125 | } | ||
126 | |||
127 | void* memset(void* s, int c, size_t n) | 90 | void* memset(void* s, int c, size_t n) |
128 | { | 91 | { |
129 | int i; | 92 | int i; |
diff --git a/arch/mn10300/boot/compressed/misc.c b/arch/mn10300/boot/compressed/misc.c index ded207efc97a..f673383518e4 100644 --- a/arch/mn10300/boot/compressed/misc.c +++ b/arch/mn10300/boot/compressed/misc.c | |||
@@ -153,26 +153,9 @@ static uch *output_data; | |||
153 | static unsigned long output_ptr; | 153 | static unsigned long output_ptr; |
154 | 154 | ||
155 | 155 | ||
156 | static void *malloc(int size); | ||
157 | |||
158 | static inline void free(void *where) | ||
159 | { /* Don't care */ | ||
160 | } | ||
161 | |||
162 | static unsigned long free_mem_ptr = (unsigned long) &end; | 156 | static unsigned long free_mem_ptr = (unsigned long) &end; |
163 | static unsigned long free_mem_end_ptr = (unsigned long) &end + 0x90000; | 157 | static unsigned long free_mem_end_ptr = (unsigned long) &end + 0x90000; |
164 | 158 | ||
165 | static inline void gzip_mark(void **ptr) | ||
166 | { | ||
167 | kputs("."); | ||
168 | *ptr = (void *) free_mem_ptr; | ||
169 | } | ||
170 | |||
171 | static inline void gzip_release(void **ptr) | ||
172 | { | ||
173 | free_mem_ptr = (unsigned long) *ptr; | ||
174 | } | ||
175 | |||
176 | #define INPLACE_MOVE_ROUTINE 0x1000 | 159 | #define INPLACE_MOVE_ROUTINE 0x1000 |
177 | #define LOW_BUFFER_START 0x2000 | 160 | #define LOW_BUFFER_START 0x2000 |
178 | #define LOW_BUFFER_END 0x90000 | 161 | #define LOW_BUFFER_END 0x90000 |
@@ -186,26 +169,6 @@ static int lines, cols; | |||
186 | 169 | ||
187 | #include "../../../../lib/inflate.c" | 170 | #include "../../../../lib/inflate.c" |
188 | 171 | ||
189 | static void *malloc(int size) | ||
190 | { | ||
191 | void *p; | ||
192 | |||
193 | if (size < 0) | ||
194 | error("Malloc error\n"); | ||
195 | if (!free_mem_ptr) | ||
196 | error("Memory error\n"); | ||
197 | |||
198 | free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */ | ||
199 | |||
200 | p = (void *) free_mem_ptr; | ||
201 | free_mem_ptr += size; | ||
202 | |||
203 | if (free_mem_ptr >= free_mem_end_ptr) | ||
204 | error("\nOut of memory\n"); | ||
205 | |||
206 | return p; | ||
207 | } | ||
208 | |||
209 | static inline void scroll(void) | 172 | static inline void scroll(void) |
210 | { | 173 | { |
211 | int i; | 174 | int i; |
diff --git a/arch/sh/boot/compressed/misc_32.c b/arch/sh/boot/compressed/misc_32.c index adcea31e663e..f386997e4d9c 100644 --- a/arch/sh/boot/compressed/misc_32.c +++ b/arch/sh/boot/compressed/misc_32.c | |||
@@ -74,8 +74,6 @@ static unsigned outcnt = 0; /* bytes in output buffer */ | |||
74 | static int fill_inbuf(void); | 74 | static int fill_inbuf(void); |
75 | static void flush_window(void); | 75 | static void flush_window(void); |
76 | static void error(char *m); | 76 | static void error(char *m); |
77 | static void gzip_mark(void **); | ||
78 | static void gzip_release(void **); | ||
79 | 77 | ||
80 | extern char input_data[]; | 78 | extern char input_data[]; |
81 | extern int input_len; | 79 | extern int input_len; |
@@ -84,11 +82,7 @@ static long bytes_out = 0; | |||
84 | static uch *output_data; | 82 | static uch *output_data; |
85 | static unsigned long output_ptr = 0; | 83 | static unsigned long output_ptr = 0; |
86 | 84 | ||
87 | static void *malloc(int size); | ||
88 | static void free(void *where); | ||
89 | static void error(char *m); | 85 | static void error(char *m); |
90 | static void gzip_mark(void **); | ||
91 | static void gzip_release(void **); | ||
92 | 86 | ||
93 | int puts(const char *); | 87 | int puts(const char *); |
94 | 88 | ||
@@ -101,38 +95,6 @@ static unsigned long free_mem_end_ptr; | |||
101 | 95 | ||
102 | #include "../../../../lib/inflate.c" | 96 | #include "../../../../lib/inflate.c" |
103 | 97 | ||
104 | static void *malloc(int size) | ||
105 | { | ||
106 | void *p; | ||
107 | |||
108 | if (size <0) error("Malloc error"); | ||
109 | if (free_mem_ptr == 0) error("Memory error"); | ||
110 | |||
111 | free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */ | ||
112 | |||
113 | p = (void *)free_mem_ptr; | ||
114 | free_mem_ptr += size; | ||
115 | |||
116 | if (free_mem_ptr >= free_mem_end_ptr) | ||
117 | error("Out of memory"); | ||
118 | |||
119 | return p; | ||
120 | } | ||
121 | |||
122 | static void free(void *where) | ||
123 | { /* Don't care */ | ||
124 | } | ||
125 | |||
126 | static void gzip_mark(void **ptr) | ||
127 | { | ||
128 | *ptr = (void *) free_mem_ptr; | ||
129 | } | ||
130 | |||
131 | static void gzip_release(void **ptr) | ||
132 | { | ||
133 | free_mem_ptr = (long) *ptr; | ||
134 | } | ||
135 | |||
136 | #ifdef CONFIG_SH_STANDARD_BIOS | 98 | #ifdef CONFIG_SH_STANDARD_BIOS |
137 | size_t strlen(const char *s) | 99 | size_t strlen(const char *s) |
138 | { | 100 | { |
diff --git a/arch/sh/boot/compressed/misc_64.c b/arch/sh/boot/compressed/misc_64.c index a006ef89b9dd..2941657e18aa 100644 --- a/arch/sh/boot/compressed/misc_64.c +++ b/arch/sh/boot/compressed/misc_64.c | |||
@@ -72,8 +72,6 @@ static unsigned outcnt = 0; /* bytes in output buffer */ | |||
72 | static int fill_inbuf(void); | 72 | static int fill_inbuf(void); |
73 | static void flush_window(void); | 73 | static void flush_window(void); |
74 | static void error(char *m); | 74 | static void error(char *m); |
75 | static void gzip_mark(void **); | ||
76 | static void gzip_release(void **); | ||
77 | 75 | ||
78 | extern char input_data[]; | 76 | extern char input_data[]; |
79 | extern int input_len; | 77 | extern int input_len; |
@@ -82,11 +80,7 @@ static long bytes_out = 0; | |||
82 | static uch *output_data; | 80 | static uch *output_data; |
83 | static unsigned long output_ptr = 0; | 81 | static unsigned long output_ptr = 0; |
84 | 82 | ||
85 | static void *malloc(int size); | ||
86 | static void free(void *where); | ||
87 | static void error(char *m); | 83 | static void error(char *m); |
88 | static void gzip_mark(void **); | ||
89 | static void gzip_release(void **); | ||
90 | 84 | ||
91 | static void puts(const char *); | 85 | static void puts(const char *); |
92 | 86 | ||
@@ -99,40 +93,6 @@ static unsigned long free_mem_end_ptr; | |||
99 | 93 | ||
100 | #include "../../../../lib/inflate.c" | 94 | #include "../../../../lib/inflate.c" |
101 | 95 | ||
102 | static void *malloc(int size) | ||
103 | { | ||
104 | void *p; | ||
105 | |||
106 | if (size < 0) | ||
107 | error("Malloc error\n"); | ||
108 | if (free_mem_ptr == 0) | ||
109 | error("Memory error\n"); | ||
110 | |||
111 | free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */ | ||
112 | |||
113 | p = (void *) free_mem_ptr; | ||
114 | free_mem_ptr += size; | ||
115 | |||
116 | if (free_mem_ptr >= free_mem_end_ptr) | ||
117 | error("\nOut of memory\n"); | ||
118 | |||
119 | return p; | ||
120 | } | ||
121 | |||
122 | static void free(void *where) | ||
123 | { /* Don't care */ | ||
124 | } | ||
125 | |||
126 | static void gzip_mark(void **ptr) | ||
127 | { | ||
128 | *ptr = (void *) free_mem_ptr; | ||
129 | } | ||
130 | |||
131 | static void gzip_release(void **ptr) | ||
132 | { | ||
133 | free_mem_ptr = (long) *ptr; | ||
134 | } | ||
135 | |||
136 | void puts(const char *s) | 96 | void puts(const char *s) |
137 | { | 97 | { |
138 | } | 98 | } |
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c index bc5553b496f7..9fea73706479 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c | |||
@@ -182,8 +182,6 @@ static unsigned outcnt; | |||
182 | static int fill_inbuf(void); | 182 | static int fill_inbuf(void); |
183 | static void flush_window(void); | 183 | static void flush_window(void); |
184 | static void error(char *m); | 184 | static void error(char *m); |
185 | static void gzip_mark(void **); | ||
186 | static void gzip_release(void **); | ||
187 | 185 | ||
188 | /* | 186 | /* |
189 | * This is set up by the setup-routine at boot-time | 187 | * This is set up by the setup-routine at boot-time |
@@ -196,9 +194,6 @@ extern int input_len; | |||
196 | 194 | ||
197 | static long bytes_out; | 195 | static long bytes_out; |
198 | 196 | ||
199 | static void *malloc(int size); | ||
200 | static void free(void *where); | ||
201 | |||
202 | static void *memset(void *s, int c, unsigned n); | 197 | static void *memset(void *s, int c, unsigned n); |
203 | static void *memcpy(void *dest, const void *src, unsigned n); | 198 | static void *memcpy(void *dest, const void *src, unsigned n); |
204 | 199 | ||
@@ -220,40 +215,6 @@ static int lines, cols; | |||
220 | 215 | ||
221 | #include "../../../../lib/inflate.c" | 216 | #include "../../../../lib/inflate.c" |
222 | 217 | ||
223 | static void *malloc(int size) | ||
224 | { | ||
225 | void *p; | ||
226 | |||
227 | if (size < 0) | ||
228 | error("Malloc error"); | ||
229 | if (free_mem_ptr <= 0) | ||
230 | error("Memory error"); | ||
231 | |||
232 | free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */ | ||
233 | |||
234 | p = (void *)free_mem_ptr; | ||
235 | free_mem_ptr += size; | ||
236 | |||
237 | if (free_mem_ptr >= free_mem_end_ptr) | ||
238 | error("Out of memory"); | ||
239 | |||
240 | return p; | ||
241 | } | ||
242 | |||
243 | static void free(void *where) | ||
244 | { /* Don't care */ | ||
245 | } | ||
246 | |||
247 | static void gzip_mark(void **ptr) | ||
248 | { | ||
249 | *ptr = (void *) free_mem_ptr; | ||
250 | } | ||
251 | |||
252 | static void gzip_release(void **ptr) | ||
253 | { | ||
254 | free_mem_ptr = (memptr) *ptr; | ||
255 | } | ||
256 | |||
257 | static void scroll(void) | 218 | static void scroll(void) |
258 | { | 219 | { |
259 | int i; | 220 | int i; |
diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c index 470a328d1454..fedef93b586f 100644 --- a/init/do_mounts_rd.c +++ b/init/do_mounts_rd.c | |||
@@ -303,32 +303,11 @@ static int crd_infd, crd_outfd; | |||
303 | 303 | ||
304 | static int __init fill_inbuf(void); | 304 | static int __init fill_inbuf(void); |
305 | static void __init flush_window(void); | 305 | static void __init flush_window(void); |
306 | static void __init *malloc(size_t size); | ||
307 | static void __init free(void *where); | ||
308 | static void __init error(char *m); | 306 | static void __init error(char *m); |
309 | static void __init gzip_mark(void **); | ||
310 | static void __init gzip_release(void **); | ||
311 | 307 | ||
312 | #include "../lib/inflate.c" | 308 | #define NO_INFLATE_MALLOC |
313 | |||
314 | static void __init *malloc(size_t size) | ||
315 | { | ||
316 | return kmalloc(size, GFP_KERNEL); | ||
317 | } | ||
318 | |||
319 | static void __init free(void *where) | ||
320 | { | ||
321 | kfree(where); | ||
322 | } | ||
323 | |||
324 | static void __init gzip_mark(void **ptr) | ||
325 | { | ||
326 | } | ||
327 | |||
328 | static void __init gzip_release(void **ptr) | ||
329 | { | ||
330 | } | ||
331 | 309 | ||
310 | #include "../lib/inflate.c" | ||
332 | 311 | ||
333 | /* =========================================================================== | 312 | /* =========================================================================== |
334 | * Fill the input buffer. This is called only when the buffer is empty | 313 | * Fill the input buffer. This is called only when the buffer is empty |
diff --git a/init/initramfs.c b/init/initramfs.c index 8eeeccb328c9..644fc01ad5f0 100644 --- a/init/initramfs.c +++ b/init/initramfs.c | |||
@@ -14,16 +14,6 @@ static void __init error(char *x) | |||
14 | message = x; | 14 | message = x; |
15 | } | 15 | } |
16 | 16 | ||
17 | static void __init *malloc(size_t size) | ||
18 | { | ||
19 | return kmalloc(size, GFP_KERNEL); | ||
20 | } | ||
21 | |||
22 | static void __init free(void *where) | ||
23 | { | ||
24 | kfree(where); | ||
25 | } | ||
26 | |||
27 | /* link hash */ | 17 | /* link hash */ |
28 | 18 | ||
29 | #define N_ALIGN(len) ((((len) + 1) & ~3) + 2) | 19 | #define N_ALIGN(len) ((((len) + 1) & ~3) + 2) |
@@ -407,18 +397,10 @@ static long bytes_out; | |||
407 | 397 | ||
408 | static void __init flush_window(void); | 398 | static void __init flush_window(void); |
409 | static void __init error(char *m); | 399 | static void __init error(char *m); |
410 | static void __init gzip_mark(void **); | ||
411 | static void __init gzip_release(void **); | ||
412 | 400 | ||
413 | #include "../lib/inflate.c" | 401 | #define NO_INFLATE_MALLOC |
414 | 402 | ||
415 | static void __init gzip_mark(void **ptr) | 403 | #include "../lib/inflate.c" |
416 | { | ||
417 | } | ||
418 | |||
419 | static void __init gzip_release(void **ptr) | ||
420 | { | ||
421 | } | ||
422 | 404 | ||
423 | /* =========================================================================== | 405 | /* =========================================================================== |
424 | * Write the output window window[0..outcnt-1] and update crc and bytes_out. | 406 | * Write the output window window[0..outcnt-1] and update crc and bytes_out. |
diff --git a/lib/inflate.c b/lib/inflate.c index 9762294be062..1a8e8a978128 100644 --- a/lib/inflate.c +++ b/lib/inflate.c | |||
@@ -230,6 +230,45 @@ STATIC const ush mask_bits[] = { | |||
230 | #define NEEDBITS(n) {while(k<(n)){b|=((ulg)NEXTBYTE())<<k;k+=8;}} | 230 | #define NEEDBITS(n) {while(k<(n)){b|=((ulg)NEXTBYTE())<<k;k+=8;}} |
231 | #define DUMPBITS(n) {b>>=(n);k-=(n);} | 231 | #define DUMPBITS(n) {b>>=(n);k-=(n);} |
232 | 232 | ||
233 | #ifndef NO_INFLATE_MALLOC | ||
234 | /* A trivial malloc implementation, adapted from | ||
235 | * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994 | ||
236 | */ | ||
237 | |||
238 | static unsigned long malloc_ptr; | ||
239 | static int malloc_count; | ||
240 | |||
241 | static void *malloc(int size) | ||
242 | { | ||
243 | void *p; | ||
244 | |||
245 | if (size < 0) | ||
246 | error("Malloc error"); | ||
247 | if (!malloc_ptr) | ||
248 | malloc_ptr = free_mem_ptr; | ||
249 | |||
250 | malloc_ptr = (malloc_ptr + 3) & ~3; /* Align */ | ||
251 | |||
252 | p = (void *)malloc_ptr; | ||
253 | malloc_ptr += size; | ||
254 | |||
255 | if (free_mem_end_ptr && malloc_ptr >= free_mem_end_ptr) | ||
256 | error("Out of memory"); | ||
257 | |||
258 | malloc_count++; | ||
259 | return p; | ||
260 | } | ||
261 | |||
262 | static void free(void *where) | ||
263 | { | ||
264 | malloc_count--; | ||
265 | if (!malloc_count) | ||
266 | malloc_ptr = free_mem_ptr; | ||
267 | } | ||
268 | #else | ||
269 | #define malloc(a) kmalloc(a, GFP_KERNEL) | ||
270 | #define free(a) kfree(a) | ||
271 | #endif | ||
233 | 272 | ||
234 | /* | 273 | /* |
235 | Huffman code decoding is performed using a multi-level table lookup. | 274 | Huffman code decoding is performed using a multi-level table lookup. |
@@ -1045,7 +1084,6 @@ STATIC int INIT inflate(void) | |||
1045 | int e; /* last block flag */ | 1084 | int e; /* last block flag */ |
1046 | int r; /* result code */ | 1085 | int r; /* result code */ |
1047 | unsigned h; /* maximum struct huft's malloc'ed */ | 1086 | unsigned h; /* maximum struct huft's malloc'ed */ |
1048 | void *ptr; | ||
1049 | 1087 | ||
1050 | /* initialize window, bit buffer */ | 1088 | /* initialize window, bit buffer */ |
1051 | wp = 0; | 1089 | wp = 0; |
@@ -1057,12 +1095,12 @@ STATIC int INIT inflate(void) | |||
1057 | h = 0; | 1095 | h = 0; |
1058 | do { | 1096 | do { |
1059 | hufts = 0; | 1097 | hufts = 0; |
1060 | gzip_mark(&ptr); | 1098 | #ifdef ARCH_HAS_DECOMP_WDOG |
1061 | if ((r = inflate_block(&e)) != 0) { | 1099 | arch_decomp_wdog(); |
1062 | gzip_release(&ptr); | 1100 | #endif |
1063 | return r; | 1101 | r = inflate_block(&e); |
1064 | } | 1102 | if (r) |
1065 | gzip_release(&ptr); | 1103 | return r; |
1066 | if (hufts > h) | 1104 | if (hufts > h) |
1067 | h = hufts; | 1105 | h = hufts; |
1068 | } while (!e); | 1106 | } while (!e); |