diff options
Diffstat (limited to 'lib/inflate.c')
-rw-r--r-- | lib/inflate.c | 52 |
1 files changed, 45 insertions, 7 deletions
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); |