1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/kernel.h>
23#include <linux/slab.h>
24
25#include <linux/uaccess.h>
26
27#define memzero(s,n) memset ((s),0,(n))
28#define puts srm_printk
29extern long srm_printk(const char *, ...)
30 __attribute__ ((format (printf, 1, 2)));
31
32
33
34
35#define OF(args) args
36#define STATIC static
37
38typedef unsigned char uch;
39typedef unsigned short ush;
40typedef unsigned long ulg;
41
42#define WSIZE 0x8000
43
44
45static uch *inbuf;
46static uch *window;
47
48static unsigned insize;
49static unsigned inptr;
50static unsigned outcnt;
51
52
53#define ASCII_FLAG 0x01
54#define CONTINUATION 0x02
55#define EXTRA_FIELD 0x04
56#define ORIG_NAME 0x08
57#define COMMENT 0x10
58#define ENCRYPTED 0x20
59#define RESERVED 0xC0
60
61#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
62
63
64#ifdef DEBUG
65# define Assert(cond,msg) {if(!(cond)) error(msg);}
66# define Trace(x) fprintf x
67# define Tracev(x) {if (verbose) fprintf x ;}
68# define Tracevv(x) {if (verbose>1) fprintf x ;}
69# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
70# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
71#else
72# define Assert(cond,msg)
73# define Trace(x)
74# define Tracev(x)
75# define Tracevv(x)
76# define Tracec(c,x)
77# define Tracecv(c,x)
78#endif
79
80static int fill_inbuf(void);
81static void flush_window(void);
82static void error(char *m);
83
84static char *input_data;
85static int input_data_size;
86
87static uch *output_data;
88static ulg output_ptr;
89static ulg bytes_out;
90
91static void error(char *m);
92static void gzip_mark(void **);
93static void gzip_release(void **);
94
95extern int end;
96static ulg free_mem_ptr;
97static ulg free_mem_end_ptr;
98
99#define HEAP_SIZE 0x3000
100
101#include "../../../lib/inflate.c"
102
103
104
105
106
107int fill_inbuf(void)
108{
109 if (insize != 0)
110 error("ran out of input data");
111
112 inbuf = input_data;
113 insize = input_data_size;
114
115 inptr = 1;
116 return inbuf[0];
117}
118
119
120
121
122
123void flush_window(void)
124{
125 ulg c = crc;
126 unsigned n;
127 uch *in, *out, ch;
128
129 in = window;
130 out = &output_data[output_ptr];
131 for (n = 0; n < outcnt; n++) {
132 ch = *out++ = *in++;
133 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
134 }
135 crc = c;
136 bytes_out += (ulg)outcnt;
137 output_ptr += (ulg)outcnt;
138 outcnt = 0;
139
140}
141
142static void error(char *x)
143{
144 puts("\n\n");
145 puts(x);
146 puts("\n\n -- System halted");
147
148 while(1);
149}
150
151unsigned int
152decompress_kernel(void *output_start,
153 void *input_start,
154 size_t ksize,
155 size_t kzsize)
156{
157 output_data = (uch *)output_start;
158 input_data = (uch *)input_start;
159 input_data_size = kzsize;
160
161
162 free_mem_ptr = (ulg)output_start + ksize;
163 free_mem_end_ptr = (ulg)output_start + ksize + 0x200000;
164
165
166
167 window = malloc(WSIZE);
168
169 makecrc();
170
171 gunzip();
172
173 return output_ptr;
174}
175