2005-10-31 21:01:13

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 1/20] inflate: lindent and manual formatting changes

inflate: lindent and general reformatting

Signed-off-by: Matt Mackall <[email protected]>

Index: tiny/lib/inflate.c
===================================================================
--- tiny.orig/lib/inflate.c 2005-09-27 19:31:03.000000000 -0700
+++ tiny/lib/inflate.c 2005-09-27 19:58:58.000000000 -0700
@@ -1,17 +1,17 @@
#define DEBG(x)
#define DEBG1(x)
/* inflate.c -- Not copyrighted 1992 by Mark Adler
- version c10p1, 10 January 1993 */
-
-/*
+ * version c10p1, 10 January 1993
+ *
* Adapted for booting Linux by Hannu Savolainen 1993
- * based on gzip-1.0.3
+ * based on gzip-1.0.3
*
* Nicolas Pitre <[email protected]>, 1999/04/14 :
- * Little mods for all variable to reside either into rodata or bss segments
- * by marking constant variables with 'const' and initializing all the others
- * at run-time only. This allows for the kernel uncompressor to run
- * directly from Flash or ROM memory on embedded systems.
+ * Little mods for all variable to reside either into rodata or bss
+ * segments by marking constant variables with 'const' and
+ * initializing all the others at run-time only. This allows for the
+ * kernel uncompressor to run directly from Flash or ROM memory on
+ * embedded systems.
*/

/*
@@ -50,14 +50,13 @@
chunks), otherwise the dynamic method is used. In the latter case, the
codes are customized to the probabilities in the current block, and so
can code it much better than the pre-determined fixed codes.
-
+
The Huffman codes themselves are decoded using a multi-level table
lookup, in order to maximize the speed of decoding plus the speed of
building the decoding tables. See the comments below that precede the
lbits and dbits tuning parameters.
*/

-
/*
Notes beyond the 1.93a appnote.txt:

@@ -122,7 +121,7 @@ static char rcsid[] = "#Id: inflate.c,v
#ifndef INIT
#define INIT
#endif
-
+
#define slide window

/* Huffman code lookup table entry--this entry is four bytes for machines
@@ -133,17 +132,16 @@ static char rcsid[] = "#Id: inflate.c,v
an unused code. If a code with e == 99 is looked up, this implies an
error in the data. */
struct huft {
- uch e; /* number of extra bits or operation */
- uch b; /* number of bits in this code or subcode */
- union {
- ush n; /* literal, length base, or distance base */
- struct huft *t; /* pointer to next level of table */
- } v;
+ uch e; /* number of extra bits or operation */
+ uch b; /* number of bits in this code or subcode */
+ union {
+ ush n; /* literal, length base, or distance base */
+ struct huft *t; /* pointer to next level of table */
+ } v;
};

-
/* Function prototypes */
-STATIC int INIT huft_build OF((unsigned *, unsigned, unsigned,
+STATIC int INIT huft_build OF((unsigned *, unsigned, unsigned,
const ush *, const ush *, struct huft **, int *));
STATIC int INIT huft_free OF((struct huft *));
STATIC int INIT inflate_codes OF((struct huft *, struct huft *, int, int));
@@ -153,7 +151,6 @@ STATIC int INIT inflate_dynamic OF((void
STATIC int INIT inflate_block OF((int *));
STATIC int INIT inflate OF((void));

-
/* The inflate algorithm uses a sliding 32 K byte window on the uncompressed
stream to find repeated byte strings. This is implemented here as a
circular buffer. The index is updated simply by incrementing and then
@@ -167,29 +164,44 @@ STATIC int INIT inflate OF((void));
#define flush_output(w) (wp=(w),flush_window())

/* Tables for deflate from PKZIP's appnote.txt. */
-static const unsigned border[] = { /* Order of the bit length code lengths */
- 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
-static const ush cplens[] = { /* Copy lengths for literal codes 257..285 */
- 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
- 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
- /* note: see note #13 above about the 258 in this list. */
-static const ush cplext[] = { /* Extra bits for literal codes 257..285 */
- 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
- 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99}; /* 99==invalid */
-static const ush cpdist[] = { /* Copy offsets for distance codes 0..29 */
- 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
- 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
- 8193, 12289, 16385, 24577};
-static const ush cpdext[] = { /* Extra bits for distance codes */
- 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
- 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
- 12, 12, 13, 13};

+/* Order of the bit length code lengths */
+static const unsigned border[] = {
+ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
+};
+
+/* Copy lengths for literal codes 257..285 */
+static const ush cplens[] = {
+ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
+ 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
+};
+
+/* Extra bits for literal codes 257..285
+ * note: see note #13 above about the 258 in this list.
+ * 99==invalid
+ */
+static const ush cplext[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
+ 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99
+};
+
+/* Copy offsets for distance codes 0..29 */
+static const ush cpdist[] = {
+ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
+ 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
+ 8193, 12289, 16385, 24577
+};

+/* Extra bits for distance codes */
+static const ush cpdext[] = {
+ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
+ 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
+ 12, 12, 13, 13
+};

/* Macros for inflate() bit peeking and grabbing.
The usage is:
-
+
NEEDBITS(j)
x = b & mask_bits[j];
DUMPBITS(j)
@@ -217,19 +229,18 @@ static const ush cpdext[] = { /*
the stream.
*/

-STATIC ulg bb; /* bit buffer */
-STATIC unsigned bk; /* bits in bit buffer */
+STATIC ulg bb; /* bit buffer */
+STATIC unsigned bk; /* bits in bit buffer */

STATIC const ush mask_bits[] = {
- 0x0000,
- 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
- 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
+ 0x0000,
+ 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
+ 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
};

#define NEXTBYTE() ({ int v = get_byte(); if (v < 0) goto underrun; (uch)v; })
-#define NEEDBITS(n) {while(k<(n)){b|=((ulg)NEXTBYTE())<<k;k+=8;}}
-#define DUMPBITS(n) {b>>=(n);k-=(n);}
-
+#define NEEDBITS(n) do {while(k<(n)){b|=((ulg)NEXTBYTE())<<k;k+=8;}} while(0)
+#define DUMPBITS(n) do {b>>=(n);k-=(n);} while(0)

/*
Huffman code decoding is performed using a multi-level table lookup.
@@ -263,771 +274,757 @@ STATIC const ush mask_bits[] = {
possibly even between compilers. Your mileage may vary.
*/

-
-STATIC const int lbits = 9; /* bits in base literal/length lookup table */
-STATIC const int dbits = 6; /* bits in base distance lookup table */
-
+STATIC const int lbits = 9; /* bits in base literal/length lookup table */
+STATIC const int dbits = 6; /* bits in base distance lookup table */

/* If BMAX needs to be larger than 16, then h and x[] should be ulg. */
-#define BMAX 16 /* maximum bit length of any code (16 for explode) */
-#define N_MAX 288 /* maximum number of codes in any set */
-
+#define BMAX 16 /* maximum bit length of any code (16 for explode) */
+#define N_MAX 288 /* maximum number of codes in any set */

-STATIC unsigned hufts; /* track memory usage */
+STATIC unsigned hufts; /* track memory usage */

-
-STATIC int INIT huft_build(
- unsigned *b, /* code lengths in bits (all assumed <= BMAX) */
- unsigned n, /* number of codes (assumed <= N_MAX) */
- unsigned s, /* number of simple-valued codes (0..s-1) */
- const ush *d, /* list of base values for non-simple codes */
- const ush *e, /* list of extra bits for non-simple codes */
- struct huft **t, /* result: starting table */
- int *m /* maximum lookup bits, returns actual */
- )
-/* Given a list of code lengths and a maximum table size, make a set of
- tables to decode that set of codes. Return zero on success, one if
- the given code set is incomplete (the tables are still built in this
- case), two if the input is invalid (all zero length codes or an
- oversubscribed set of lengths), and three if not enough memory. */
+/*
+ * huft-build - build a huffman decoding table
+ * @b: code lengths in bits (all assumed <= BMAX)
+ * @n: number of codes (assumed <= N_MAX)
+ * @s: number of simple-valued codes (0..s-1)
+ * @d: list of base values for non-simple codes
+ * @e: list of extra bits for non-simple codes
+ * @t: returns pointer to starting table
+ * @m: maximum lookup bits, returns actual
+ *
+ * Given a list of code lengths and a maximum table size, make a set
+ * of tables to decode that set of codes. Return zero on success, one
+ * if the given code set is incomplete (the tables are still built in
+ * this case), two if the input is invalid (all zero length codes or
+ * an oversubscribed set of lengths), and three if not enough
+ * memory.
+ */
+STATIC int INIT huft_build(unsigned *b, unsigned n, unsigned s, const ush * d,
+ const ush * e, struct huft **t, int *m)
{
- unsigned a; /* counter for codes of length k */
- unsigned c[BMAX+1]; /* bit length count table */
- unsigned f; /* i repeats in table every f entries */
- int g; /* maximum code length */
- int h; /* table level */
- register unsigned i; /* counter, current code */
- register unsigned j; /* counter */
- register int k; /* number of bits in current code */
- int l; /* bits per table (returned in m) */
- register unsigned *p; /* pointer into c[], b[], or v[] */
- register struct huft *q; /* points to current table */
- struct huft r; /* table entry for structure assignment */
- struct huft *u[BMAX]; /* table stack */
- unsigned v[N_MAX]; /* values in order of bit length */
- register int w; /* bits before this table == (l * h) */
- unsigned x[BMAX+1]; /* bit offsets, then code stack */
- unsigned *xp; /* pointer into x */
- int y; /* number of dummy codes added */
- unsigned z; /* number of entries in current table */
-
-DEBG("huft1 ");
-
- /* Generate counts for each bit length */
- memzero(c, sizeof(c));
- p = b; i = n;
- do {
- Tracecv(*p, (stderr, (n-i >= ' ' && n-i <= '~' ? "%c %d\n" : "0x%x %d\n"),
- n-i, *p));
- c[*p]++; /* assume all entries <= BMAX */
- p++; /* Can't combine with above line (Solaris bug) */
- } while (--i);
- if (c[0] == n) /* null input--all zero length codes */
- {
- *t = (struct huft *)NULL;
- *m = 0;
- return 2;
- }
-
-DEBG("huft2 ");
-
- /* Find minimum and maximum length, bound *m by those */
- l = *m;
- for (j = 1; j <= BMAX; j++)
- if (c[j])
- break;
- k = j; /* minimum code length */
- if ((unsigned)l < j)
- l = j;
- for (i = BMAX; i; i--)
- if (c[i])
- break;
- g = i; /* maximum code length */
- if ((unsigned)l > i)
- l = i;
- *m = l;
-
-DEBG("huft3 ");
-
- /* Adjust last length count to fill out codes, if needed */
- for (y = 1 << j; j < i; j++, y <<= 1)
- if ((y -= c[j]) < 0)
- return 2; /* bad input: more codes than bits */
- if ((y -= c[i]) < 0)
- return 2;
- c[i] += y;
-
-DEBG("huft4 ");
-
- /* Generate starting offsets into the value table for each length */
- x[1] = j = 0;
- p = c + 1; xp = x + 2;
- while (--i) { /* note that i == g from above */
- *xp++ = (j += *p++);
- }
-
-DEBG("huft5 ");
-
- /* Make a table of values in order of bit lengths */
- p = b; i = 0;
- do {
- if ((j = *p++) != 0)
- v[x[j]++] = i;
- } while (++i < n);
- n = x[g]; /* set n to length of v */
-
-DEBG("h6 ");
-
- /* Generate the Huffman codes and for each, make the table entries */
- x[0] = i = 0; /* first Huffman code is zero */
- p = v; /* grab values in bit order */
- h = -1; /* no tables yet--level -1 */
- w = -l; /* bits decoded == (l * h) */
- u[0] = (struct huft *)NULL; /* just to keep compilers happy */
- q = (struct huft *)NULL; /* ditto */
- z = 0; /* ditto */
-DEBG("h6a ");
-
- /* go through the bit lengths (k already is bits in shortest code) */
- for (; k <= g; k++)
- {
-DEBG("h6b ");
- a = c[k];
- while (a--)
- {
-DEBG("h6b1 ");
- /* here i is the Huffman code of length k bits for value *p */
- /* make tables up to required level */
- while (k > w + l)
- {
-DEBG1("1 ");
- h++;
- w += l; /* previous table always l bits */
-
- /* compute minimum size table less than or equal to l bits */
- z = (z = g - w) > (unsigned)l ? l : z; /* upper limit on table size */
- if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */
- { /* too few codes for k-w bit table */
-DEBG1("2 ");
- f -= a + 1; /* deduct codes from patterns left */
- xp = c + k;
- if (j < z)
- while (++j < z) /* try smaller tables up to z bits */
- {
- if ((f <<= 1) <= *++xp)
- break; /* enough codes to use up j bits */
- f -= *xp; /* else deduct codes from patterns */
- }
- }
-DEBG1("3 ");
- z = 1 << j; /* table entries for j-bit table */
-
- /* allocate and link in new table */
- if ((q = (struct huft *)malloc((z + 1)*sizeof(struct huft))) ==
- (struct huft *)NULL)
- {
- if (h)
- huft_free(u[0]);
- return 3; /* not enough memory */
- }
-DEBG1("4 ");
- hufts += z + 1; /* track memory usage */
- *t = q + 1; /* link to list for huft_free() */
- *(t = &(q->v.t)) = (struct huft *)NULL;
- u[h] = ++q; /* table starts after link */
-
-DEBG1("5 ");
- /* connect to last table, if there is one */
- if (h)
- {
- x[h] = i; /* save pattern for backing up */
- r.b = (uch)l; /* bits to dump before this table */
- r.e = (uch)(16 + j); /* bits in this table */
- r.v.t = q; /* pointer to this table */
- j = i >> (w - l); /* (get around Turbo C bug) */
- u[h-1][j] = r; /* connect to last table */
- }
-DEBG1("6 ");
- }
-DEBG("h6c ");
-
- /* set up table entry in r */
- r.b = (uch)(k - w);
- if (p >= v + n)
- r.e = 99; /* out of values--invalid code */
- else if (*p < s)
- {
- r.e = (uch)(*p < 256 ? 16 : 15); /* 256 is end-of-block code */
- r.v.n = (ush)(*p); /* simple code is just the value */
- p++; /* one compiler does not like *p++ */
- }
- else
- {
- r.e = (uch)e[*p - s]; /* non-simple--look up in lists */
- r.v.n = d[*p++ - s];
- }
-DEBG("h6d ");
-
- /* fill code-like entries with r */
- f = 1 << (k - w);
- for (j = i >> w; j < z; j += f)
- q[j] = r;
-
- /* backwards increment the k-bit code i */
- for (j = 1 << (k - 1); i & j; j >>= 1)
- i ^= j;
- i ^= j;
-
- /* backup over finished tables */
- while ((i & ((1 << w) - 1)) != x[h])
- {
- h--; /* don't need to update q */
- w -= l;
- }
-DEBG("h6e ");
- }
-DEBG("h6f ");
- }
+ unsigned a; /* counter for codes of length k */
+ unsigned c[BMAX + 1]; /* bit length count table */
+ unsigned f; /* i repeats in table every f entries */
+ int g; /* maximum code length */
+ int h; /* table level */
+ register unsigned i; /* counter, current code */
+ register unsigned j; /* counter */
+ register int k; /* number of bits in current code */
+ int l; /* bits per table (returned in m) */
+ register unsigned *p; /* pointer into c[], b[], or v[] */
+ register struct huft *q; /* points to current table */
+ struct huft r; /* table entry for structure assignment */
+ struct huft *u[BMAX]; /* table stack */
+ unsigned v[N_MAX]; /* values in order of bit length */
+ register int w; /* bits before this table == (l * h) */
+ unsigned x[BMAX + 1]; /* bit offsets, then code stack */
+ unsigned *xp; /* pointer into x */
+ int y; /* number of dummy codes added */
+ unsigned z; /* number of entries in current table */
+
+ DEBG("huft1 ");
+
+ /* Generate counts for each bit length */
+ memzero(c, sizeof(c));
+ p = b;
+ i = n;
+ do {
+ Tracecv(*p, (stderr, (n - i >= ' ' && n - i <= '~' ?
+ "%c %d\n" : "0x%x %d\n"), n - i, *p));
+ c[*p]++; /* assume all entries <= BMAX */
+ p++;
+ } while (--i);
+
+ if (c[0] == n) { /* null input--all zero length codes */
+ *t = (struct huft *)NULL;
+ *m = 0;
+ return 2;
+ }
+
+ DEBG("huft2 ");
+
+ /* Find minimum and maximum length, bound *m by those */
+ l = *m;
+ for (j = 1; j <= BMAX; j++)
+ if (c[j])
+ break;
+ k = j; /* minimum code length */
+
+ if ((unsigned)l < j)
+ l = j;
+ for (i = BMAX; i; i--)
+ if (c[i])
+ break;
+ g = i; /* maximum code length */
+
+ if ((unsigned)l > i)
+ l = i;
+ *m = l;
+
+ DEBG("huft3 ");
+
+ /* Adjust last length count to fill out codes, if needed */
+ for (y = 1 << j; j < i; j++, y <<= 1)
+ if ((y -= c[j]) < 0)
+ return 2; /* bad input: more codes than bits */
+
+ if ((y -= c[i]) < 0)
+ return 2;
+ c[i] += y;
+
+ DEBG("huft4 ");
+
+ /* Generate starting offsets into the value table for each length */
+ x[1] = j = 0;
+ p = c + 1;
+ xp = x + 2;
+ /* note that i == g from above */
+ while (--i)
+ *xp++ = (j += *p++);
+
+ DEBG("huft5 ");
+
+ /* Make a table of values in order of bit lengths */
+ p = b;
+ i = 0;
+ do {
+ if ((j = *p++) != 0)
+ v[x[j]++] = i;
+ } while (++i < n);
+
+ n = x[g]; /* set n to length of v */
+
+ DEBG("h6 ");
+
+ /* Generate the Huffman codes and for each, make the table entries */
+ x[0] = i = 0; /* first Huffman code is zero */
+ p = v; /* grab values in bit order */
+ h = -1; /* no tables yet--level -1 */
+ w = -l; /* bits decoded == (l * h) */
+ u[0] = (struct huft *)NULL; /* just to keep compilers happy */
+ q = (struct huft *)NULL; /* ditto */
+ z = 0; /* ditto */
+ DEBG("h6a ");
+
+ /* go through the bit lengths (k already is bits in shortest code) */
+ for (; k <= g; k++) {
+ DEBG("h6b ");
+ a = c[k];
+ while (a--) {
+ DEBG("h6b1 ");
+ /* i is the Huffman code of length k for value *p */
+ /* make tables up to required level */
+ while (k > w + l) {
+ DEBG1("1 ");
+ h++;
+ w += l; /* previous table always l bits */
+
+ /* compute min size <= l bits */
+ /* upper limit on table size */
+ z = (z = g - w) > (unsigned)l ? l : z;
+
+ /* try a k-w bit table */
+ if ((f = 1 << (j = k - w)) > a + 1) {
+ /* too few codes for k-w bit table */
+ DEBG1("2 ");
+ /* deduct codes from patterns left */
+ f -= a + 1;
+ xp = c + k;
+ /* try smaller tables up to z bits */
+ if (j < z) {
+ /* enough codes for j bits? */
+ while (++j < z) {
+ if ((f <<= 1) <= *++xp)
+ break;
+ /* deduct from pats */
+ f -= *xp;
+ }
+ }
+ }
+
+ DEBG1("3 ");
+ /* table entries for j-bit table */
+ z = 1 << j;
+
+ /* allocate and link in new table */
+ if ((q = (struct huft *)malloc(
+ (z + 1) * sizeof(struct huft)))
+ == (struct huft *)NULL) {
+ if (h)
+ huft_free(u[0]);
+ return 3; /* not enough memory */
+ }
+ DEBG1("4 ");
+ hufts += z + 1; /* track memory usage */
+ *t = q + 1; /* link to list for huft_free */
+ *(t = &(q->v.t)) = (struct huft *)NULL;
+ u[h] = ++q; /* table starts after link */
+
+ DEBG1("5 ");
+ /* connect to last table, if there is one */
+ if (h) {
+ /* save pattern for backing up */
+ x[h] = i;
+ /* bits to dump before this table */
+ r.b = (uch)l;
+ /* bits in this table */
+ r.e = (uch)(16 + j);
+ /* pointer to this table */
+ r.v.t = q;
+ /* (get around Turbo C bug) */
+ j = i >> (w - l);
+ /* connect to last table */
+ u[h - 1][j] = r;
+ }
+ DEBG1("6 ");
+ }
+ DEBG("h6c ");
+
+ /* set up table entry in r */
+ r.b = (uch) (k - w);
+ if (p >= v + n)
+ r.e = 99; /* out of values--invalid code */
+ else if (*p < s) {
+ /* 256 is end-of-block code */
+ r.e = (uch) (*p < 256 ? 16 : 15);
+ /* simple code is just the value */
+ r.v.n = (ush) (*p);
+ /* one compiler does not like *p++ */
+ p++;
+ } else {
+ /* non-simple--look up in lists */
+ r.e = (uch)e[*p - s];
+ r.v.n = d[*p++ - s];
+ }
+ DEBG("h6d ");
+
+ /* fill code-like entries with r */
+ f = 1 << (k - w);
+ for (j = i >> w; j < z; j += f)
+ q[j] = r;
+
+ /* backwards increment the k-bit code i */
+ for (j = 1 << (k - 1); i & j; j >>= 1)
+ i ^= j;
+ i ^= j;
+
+ /* backup over finished tables */
+ while ((i & ((1 << w) - 1)) != x[h]) {
+ h--; /* don't need to update q */
+ w -= l;
+ }
+ DEBG("h6e ");
+ }
+ DEBG("h6f ");
+ }

-DEBG("huft7 ");
+ DEBG("huft7 ");

- /* Return true (1) if we were given an incomplete table */
- return y != 0 && g != 1;
+ /* Return true (1) if we were given an incomplete table */
+ return y != 0 && g != 1;
}

-
-
-STATIC int INIT huft_free(
- struct huft *t /* table to free */
- )
-/* Free the malloc'ed tables built by huft_build(), which makes a linked
- list of the tables it made, with the links in a dummy first entry of
- each table. */
+/*
+ * huft_free - free a huffman table
+ * @t: table to free
+ *
+ * Free the malloc'ed tables built by huft_build(), which makes a
+ * linked list of the tables it made, with the links in a dummy first
+ * entry of each table.
+ */
+STATIC int INIT huft_free(struct huft *t)
{
- register struct huft *p, *q;
+ register struct huft *p, *q;

-
- /* Go through linked list, freeing from the malloced (t[-1]) address. */
- p = t;
- while (p != (struct huft *)NULL)
- {
- q = (--p)->v.t;
- free((char*)p);
- p = q;
- }
- return 0;
+ /* Go through list, freeing from the malloced (t[-1]) address. */
+ p = t;
+ while (p != (struct huft *)NULL) {
+ q = (--p)->v.t;
+ free((char *)p);
+ p = q;
+ }
+ return 0;
}

-
-STATIC int INIT inflate_codes(
- struct huft *tl, /* literal/length decoder tables */
- struct huft *td, /* distance decoder tables */
- int bl, /* number of bits decoded by tl[] */
- int bd /* number of bits decoded by td[] */
- )
-/* inflate (decompress) the codes in a deflated (compressed) block.
- Return an error code or zero if it all goes ok. */
+/*
+ * inflate_codes - decompress the codes in a deflated block
+ * @tl: literal/length decoder tables
+ * @td: distance decoder tables
+ * @bl: number of bits decoded by tl
+ * @bd: number of bits decoded by td
+ *
+ * inflate (decompress) the codes in a deflated (compressed) block.
+ * Return an error code or zero if it all goes ok.
+ */
+STATIC int inflate_codes(struct huft *tl, struct huft *td, int bl, int bd)
{
- register unsigned e; /* table entry flag/number of extra bits */
- unsigned n, d; /* length and index for copy */
- unsigned w; /* current window position */
- struct huft *t; /* pointer to table entry */
- unsigned ml, md; /* masks for bl and bd bits */
- register ulg b; /* bit buffer */
- register unsigned k; /* number of bits in bit buffer */
-
-
- /* make local copies of globals */
- b = bb; /* initialize bit buffer */
- k = bk;
- w = wp; /* initialize window position */
-
- /* inflate the coded data */
- ml = mask_bits[bl]; /* precompute masks for speed */
- md = mask_bits[bd];
- for (;;) /* do until end of block */
- {
- NEEDBITS((unsigned)bl)
- if ((e = (t = tl + ((unsigned)b & ml))->e) > 16)
- do {
- if (e == 99)
- return 1;
- DUMPBITS(t->b)
- e -= 16;
- NEEDBITS(e)
- } while ((e = (t = t->v.t + ((unsigned)b & mask_bits[e]))->e) > 16);
- DUMPBITS(t->b)
- if (e == 16) /* then it's a literal */
- {
- slide[w++] = (uch)t->v.n;
- Tracevv((stderr, "%c", slide[w-1]));
- if (w == WSIZE)
- {
- flush_output(w);
- w = 0;
- }
- }
- else /* it's an EOB or a length */
- {
- /* exit if end of block */
- if (e == 15)
- break;
-
- /* get length of block to copy */
- NEEDBITS(e)
- n = t->v.n + ((unsigned)b & mask_bits[e]);
- DUMPBITS(e);
-
- /* decode distance of block to copy */
- NEEDBITS((unsigned)bd)
- if ((e = (t = td + ((unsigned)b & md))->e) > 16)
- do {
- if (e == 99)
- return 1;
- DUMPBITS(t->b)
- e -= 16;
- NEEDBITS(e)
- } while ((e = (t = t->v.t + ((unsigned)b & mask_bits[e]))->e) > 16);
- DUMPBITS(t->b)
- NEEDBITS(e)
- d = w - t->v.n - ((unsigned)b & mask_bits[e]);
- DUMPBITS(e)
- Tracevv((stderr,"\\[%d,%d]", w-d, n));
-
- /* do the copy */
- do {
- n -= (e = (e = WSIZE - ((d &= WSIZE-1) > w ? d : w)) > n ? n : e);
+ register unsigned e; /* table entry flag/number of extra bits */
+ unsigned n, d; /* length and index for copy */
+ unsigned w; /* current window position */
+ struct huft *t; /* pointer to table entry */
+ unsigned ml, md; /* masks for bl and bd bits */
+ register ulg b; /* bit buffer */
+ register unsigned k; /* number of bits in bit buffer */
+
+ /* make local copies of globals */
+ b = bb; /* initialize bit buffer */
+ k = bk;
+ w = wp; /* initialize window position */
+
+ /* inflate the coded data */
+ ml = mask_bits[bl]; /* precompute masks for speed */
+ md = mask_bits[bd];
+ for (;;) { /* do until end of block */
+ NEEDBITS((unsigned)bl);
+ if ((e = (t = tl + ((unsigned)b & ml))->e) > 16)
+ do {
+ if (e == 99)
+ return 1;
+ DUMPBITS(t->b);
+ e -= 16;
+ NEEDBITS(e);
+ } while ((e = (t = t->v.t + ((unsigned)b &
+ mask_bits[e]))->e) > 16);
+ DUMPBITS(t->b);
+ if (e == 16) { /* then it's a literal */
+ slide[w++] = (uch)t->v.n;
+ Tracevv((stderr, "%c", slide[w - 1]));
+ if (w == WSIZE) {
+ flush_output(w);
+ w = 0;
+ }
+ } else { /* it's an EOB or a length */
+ /* exit if end of block */
+ if (e == 15)
+ break;
+
+ /* get length of block to copy */
+ NEEDBITS(e);
+ n = t->v.n + ((unsigned)b & mask_bits[e]);
+ DUMPBITS(e);
+
+ /* decode distance of block to copy */
+ NEEDBITS((unsigned)bd);
+ if ((e = (t = td + ((unsigned)b & md))->e) > 16)
+ do {
+ if (e == 99)
+ return 1;
+ DUMPBITS(t->b);
+ e -= 16;
+ NEEDBITS(e);
+ } while ((e = (t = t->v.t + ((unsigned)b
+ & mask_bits[e]))->e) > 16);
+ DUMPBITS(t->b);
+ NEEDBITS(e);
+ d = w - t->v.n - ((unsigned)b & mask_bits[e]);
+ DUMPBITS(e)
+ Tracevv((stderr, "\\[%d,%d]", w - d, n));
+
+ /* do the copy */
+ do {
+ n -= (e = (e = WSIZE - ((d &= WSIZE - 1) > w ?
+ d : w)) > n ? n : e);
#if !defined(NOMEMCPY) && !defined(DEBUG)
- if (w - d >= e) /* (this test assumes unsigned comparison) */
- {
- memcpy(slide + w, slide + d, e);
- w += e;
- d += e;
- }
- else /* do it slow to avoid memcpy() overlap */
-#endif /* !NOMEMCPY */
- do {
- slide[w++] = slide[d++];
- Tracevv((stderr, "%c", slide[w-1]));
- } while (--e);
- if (w == WSIZE)
- {
- flush_output(w);
- w = 0;
- }
- } while (n);
- }
- }
-
-
- /* restore the globals from the locals */
- wp = w; /* restore global window pointer */
- bb = b; /* restore global bit buffer */
- bk = k;
+ /* (this test assumes unsigned comparison) */
+ if (w - d >= e) {
+ memcpy(slide + w, slide + d, e);
+ w += e;
+ d += e;
+ } else
+#endif /* !NOMEMCPY */
+ /* avoid memcpy() overlap */
+ do {
+ slide[w++] = slide[d++];
+ Tracevv((stderr, "%c",
+ slide[w - 1]));
+ } while (--e);
+ if (w == WSIZE) {
+ flush_output(w);
+ w = 0;
+ }
+ } while (n);
+ }
+ }
+
+ /* restore the globals from the locals */
+ wp = w; /* restore global window pointer */
+ bb = b; /* restore global bit buffer */
+ bk = k;

- /* done */
- return 0;
+ /* done */
+ return 0;

- underrun:
- return 4; /* Input underrun */
+ underrun:
+ return 4; /* Input underrun */
}

-
-
+/* inflate_stored - "decompress" an inflated type 0 (stored) block. */
STATIC int INIT inflate_stored(void)
-/* "decompress" an inflated type 0 (stored) block. */
{
- unsigned n; /* number of bytes in block */
- unsigned w; /* current window position */
- register ulg b; /* bit buffer */
- register unsigned k; /* number of bits in bit buffer */
-
-DEBG("<stor");
-
- /* make local copies of globals */
- b = bb; /* initialize bit buffer */
- k = bk;
- w = wp; /* initialize window position */
-
-
- /* go to byte boundary */
- n = k & 7;
- DUMPBITS(n);
-
-
- /* get the length and its complement */
- NEEDBITS(16)
- n = ((unsigned)b & 0xffff);
- DUMPBITS(16)
- NEEDBITS(16)
- if (n != (unsigned)((~b) & 0xffff))
- return 1; /* error in compressed data */
- DUMPBITS(16)
-
-
- /* read and output the compressed data */
- while (n--)
- {
- NEEDBITS(8)
- slide[w++] = (uch)b;
- if (w == WSIZE)
- {
- flush_output(w);
- w = 0;
- }
- DUMPBITS(8)
- }
-
-
- /* restore the globals from the locals */
- wp = w; /* restore global window pointer */
- bb = b; /* restore global bit buffer */
- bk = k;
+ unsigned n; /* number of bytes in block */
+ unsigned w; /* current window position */
+ register ulg b; /* bit buffer */
+ register unsigned k; /* number of bits in bit buffer */
+
+ DEBG("<stor");
+
+ /* make local copies of globals */
+ b = bb; /* initialize bit buffer */
+ k = bk;
+ w = wp; /* initialize window position */
+
+ /* go to byte boundary */
+ n = k & 7;
+ DUMPBITS(n);
+
+ /* get the length and its complement */
+ NEEDBITS(16);
+ n = ((unsigned)b & 0xffff);
+ DUMPBITS(16);
+ NEEDBITS(16);
+ if (n != (unsigned)((~b) & 0xffff))
+ return 1; /* error in compressed data */
+ DUMPBITS(16);
+
+ /* read and output the compressed data */
+ while (n--) {
+ NEEDBITS(8);
+ slide[w++] = (uch)b;
+ if (w == WSIZE) {
+ flush_output(w);
+ w = 0;
+ }
+ DUMPBITS(8);
+ }
+
+ /* restore the globals from the locals */
+ wp = w; /* restore global window pointer */
+ bb = b; /* restore global bit buffer */
+ bk = k;

- DEBG(">");
- return 0;
+ DEBG(">");
+ return 0;

- underrun:
- return 4; /* Input underrun */
+ underrun:
+ return 4; /* Input underrun */
}


-/*
+/* inflate_fixed - decompress a block with fixed Huffman codes
+ *
+ * decompress an inflated type 1 (fixed Huffman codes) block. We
+ * should either replace this with a custom decoder, or at least
+ * precompute the Huffman tables.
+ *
* We use `noinline' here to prevent gcc-3.5 from using too much stack space
*/
STATIC int noinline INIT inflate_fixed(void)
-/* decompress an inflated type 1 (fixed Huffman codes) block. We should
- either replace this with a custom decoder, or at least precompute the
- Huffman tables. */
{
- int i; /* temporary variable */
- struct huft *tl; /* literal/length code table */
- struct huft *td; /* distance code table */
- int bl; /* lookup bits for tl */
- int bd; /* lookup bits for td */
- unsigned l[288]; /* length list for huft_build */
-
-DEBG("<fix");
-
- /* set up literal table */
- for (i = 0; i < 144; i++)
- l[i] = 8;
- for (; i < 256; i++)
- l[i] = 9;
- for (; i < 280; i++)
- l[i] = 7;
- for (; i < 288; i++) /* make a complete, but wrong code set */
- l[i] = 8;
- bl = 7;
- if ((i = huft_build(l, 288, 257, cplens, cplext, &tl, &bl)) != 0)
- return i;
-
-
- /* set up distance table */
- for (i = 0; i < 30; i++) /* make an incomplete code set */
- l[i] = 5;
- bd = 5;
- if ((i = huft_build(l, 30, 0, cpdist, cpdext, &td, &bd)) > 1)
- {
- huft_free(tl);
-
- DEBG(">");
- return i;
- }
-
-
- /* decompress until an end-of-block code */
- if (inflate_codes(tl, td, bl, bd))
- return 1;
-
-
- /* free the decoding tables, return */
- huft_free(tl);
- huft_free(td);
- return 0;
+ int i; /* temporary variable */
+ struct huft *tl; /* literal/length code table */
+ struct huft *td; /* distance code table */
+ int bl; /* lookup bits for tl */
+ int bd; /* lookup bits for td */
+ unsigned l[288]; /* length list for huft_build */
+
+ DEBG("<fix");
+
+ /* set up literal table */
+ for (i = 0; i < 144; i++)
+ l[i] = 8;
+ for (; i < 256; i++)
+ l[i] = 9;
+ for (; i < 280; i++)
+ l[i] = 7;
+ for (; i < 288; i++) /* make a complete, but wrong code set */
+ l[i] = 8;
+ bl = 7;
+ if ((i = huft_build(l, 288, 257, cplens, cplext, &tl, &bl)) != 0)
+ return i;
+
+ /* set up distance table */
+ for (i = 0; i < 30; i++) /* make an incomplete code set */
+ l[i] = 5;
+ bd = 5;
+ if ((i = huft_build(l, 30, 0, cpdist, cpdext, &td, &bd)) > 1) {
+ huft_free(tl);
+
+ DEBG(">");
+ return i;
+ }
+
+ /* decompress until an end-of-block code */
+ if (inflate_codes(tl, td, bl, bd))
+ return 1;
+
+ /* free the decoding tables, return */
+ huft_free(tl);
+ huft_free(td);
+ return 0;
}


-/*
+/* inflate_dynamic - decompress a type 2 (dynamic Huffman codes) block.
+ *
* We use `noinline' here to prevent gcc-3.5 from using too much stack space
*/
STATIC int noinline INIT inflate_dynamic(void)
-/* decompress an inflated type 2 (dynamic Huffman codes) block. */
{
- int i; /* temporary variables */
- unsigned j;
- unsigned l; /* last length */
- unsigned m; /* mask for bit lengths table */
- unsigned n; /* number of lengths to get */
- struct huft *tl; /* literal/length code table */
- struct huft *td; /* distance code table */
- int bl; /* lookup bits for tl */
- int bd; /* lookup bits for td */
- unsigned nb; /* number of bit length codes */
- unsigned nl; /* number of literal/length codes */
- unsigned nd; /* number of distance codes */
+ int i; /* temporary variables */
+ unsigned j;
+ unsigned l; /* last length */
+ unsigned m; /* mask for bit lengths table */
+ unsigned n; /* number of lengths to get */
+ struct huft *tl; /* literal/length code table */
+ struct huft *td; /* distance code table */
+ int bl; /* lookup bits for tl */
+ int bd; /* lookup bits for td */
+ unsigned nb; /* number of bit length codes */
+ unsigned nl; /* number of literal/length codes */
+ unsigned nd; /* number of distance codes */
#ifdef PKZIP_BUG_WORKAROUND
- unsigned ll[288+32]; /* literal/length and distance code lengths */
+ unsigned ll[288 + 32]; /* literal/length and distance code lengths */
#else
- unsigned ll[286+30]; /* literal/length and distance code lengths */
+ unsigned ll[286 + 30]; /* literal/length and distance code lengths */
#endif
- register ulg b; /* bit buffer */
- register unsigned k; /* number of bits in bit buffer */
+ register ulg b; /* bit buffer */
+ register unsigned k; /* number of bits in bit buffer */

-DEBG("<dyn");
+ DEBG("<dyn");

- /* make local bit buffer */
- b = bb;
- k = bk;
-
-
- /* read in table lengths */
- NEEDBITS(5)
- nl = 257 + ((unsigned)b & 0x1f); /* number of literal/length codes */
- DUMPBITS(5)
- NEEDBITS(5)
- nd = 1 + ((unsigned)b & 0x1f); /* number of distance codes */
- DUMPBITS(5)
- NEEDBITS(4)
- nb = 4 + ((unsigned)b & 0xf); /* number of bit length codes */
- DUMPBITS(4)
+ /* make local bit buffer */
+ b = bb;
+ k = bk;
+
+ /* read in table lengths */
+ NEEDBITS(5);
+ nl = 257 + ((unsigned)b & 0x1f); /* number of literal/length codes */
+ DUMPBITS(5);
+ NEEDBITS(5);
+ nd = 1 + ((unsigned)b & 0x1f); /* number of distance codes */
+ DUMPBITS(5);
+ NEEDBITS(4);
+ nb = 4 + ((unsigned)b & 0xf); /* number of bit length codes */
+ DUMPBITS(4);
#ifdef PKZIP_BUG_WORKAROUND
- if (nl > 288 || nd > 32)
+ if (nl > 288 || nd > 32)
#else
- if (nl > 286 || nd > 30)
+ if (nl > 286 || nd > 30)
#endif
- return 1; /* bad lengths */
+ return 1; /* bad lengths */

-DEBG("dyn1 ");
+ DEBG("dyn1 ");

- /* read in bit-length-code lengths */
- for (j = 0; j < nb; j++)
- {
- NEEDBITS(3)
- ll[border[j]] = (unsigned)b & 7;
- DUMPBITS(3)
- }
- for (; j < 19; j++)
- ll[border[j]] = 0;
-
-DEBG("dyn2 ");
-
- /* build decoding table for trees--single level, 7 bit lookup */
- bl = 7;
- if ((i = huft_build(ll, 19, 19, NULL, NULL, &tl, &bl)) != 0)
- {
- if (i == 1)
- huft_free(tl);
- return i; /* incomplete code set */
- }
-
-DEBG("dyn3 ");
-
- /* read in literal and distance code lengths */
- n = nl + nd;
- m = mask_bits[bl];
- i = l = 0;
- while ((unsigned)i < n)
- {
- NEEDBITS((unsigned)bl)
- j = (td = tl + ((unsigned)b & m))->b;
- DUMPBITS(j)
- j = td->v.n;
- if (j < 16) /* length of code in bits (0..15) */
- ll[i++] = l = j; /* save last length in l */
- else if (j == 16) /* repeat last length 3 to 6 times */
- {
- NEEDBITS(2)
- j = 3 + ((unsigned)b & 3);
- DUMPBITS(2)
- if ((unsigned)i + j > n)
- return 1;
- while (j--)
- ll[i++] = l;
- }
- else if (j == 17) /* 3 to 10 zero length codes */
- {
- NEEDBITS(3)
- j = 3 + ((unsigned)b & 7);
- DUMPBITS(3)
- if ((unsigned)i + j > n)
- return 1;
- while (j--)
- ll[i++] = 0;
- l = 0;
- }
- else /* j == 18: 11 to 138 zero length codes */
- {
- NEEDBITS(7)
- j = 11 + ((unsigned)b & 0x7f);
- DUMPBITS(7)
- if ((unsigned)i + j > n)
- return 1;
- while (j--)
- ll[i++] = 0;
- l = 0;
- }
- }
-
-DEBG("dyn4 ");
-
- /* free decoding table for trees */
- huft_free(tl);
-
-DEBG("dyn5 ");
-
- /* restore the global bit buffer */
- bb = b;
- bk = k;
-
-DEBG("dyn5a ");
-
- /* build the decoding tables for literal/length and distance codes */
- bl = lbits;
- if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl)) != 0)
- {
-DEBG("dyn5b ");
- if (i == 1) {
- error("incomplete literal tree");
- huft_free(tl);
- }
- return i; /* incomplete code set */
- }
-DEBG("dyn5c ");
- bd = dbits;
- if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd)) != 0)
- {
-DEBG("dyn5d ");
- if (i == 1) {
- error("incomplete distance tree");
+ /* read in bit-length-code lengths */
+ for (j = 0; j < nb; j++) {
+ NEEDBITS(3);
+ ll[border[j]] = (unsigned)b & 7;
+ DUMPBITS(3);
+ }
+ for (; j < 19; j++)
+ ll[border[j]] = 0;
+
+ DEBG("dyn2 ");
+
+ /* build decoding table for trees--single level, 7 bit lookup */
+ bl = 7;
+ if ((i = huft_build(ll, 19, 19, NULL, NULL, &tl, &bl)) != 0) {
+ if (i == 1)
+ huft_free(tl);
+ return i; /* incomplete code set */
+ }
+
+ DEBG("dyn3 ");
+
+ /* read in literal and distance code lengths */
+ n = nl + nd;
+ m = mask_bits[bl];
+ i = l = 0;
+ while ((unsigned)i < n) {
+ NEEDBITS((unsigned)bl);
+ j = (td = tl + ((unsigned)b & m))->b;
+ DUMPBITS(j);
+ j = td->v.n;
+ if (j < 16) /* length of code in bits (0..15) */
+ ll[i++] = l = j; /* save last length in l */
+ else if (j == 16) { /* repeat last length 3 to 6 times */
+ NEEDBITS(2);
+ j = 3 + ((unsigned)b & 3);
+ DUMPBITS(2);
+ if ((unsigned)i + j > n)
+ return 1;
+ while (j--)
+ ll[i++] = l;
+ } else if (j == 17) { /* 3 to 10 zero length codes */
+ NEEDBITS(3);
+ j = 3 + ((unsigned)b & 7);
+ DUMPBITS(3);
+ if ((unsigned)i + j > n)
+ return 1;
+ while (j--)
+ ll[i++] = 0;
+ l = 0;
+ } else { /* j == 18: 11 to 138 zero length codes */
+ NEEDBITS(7);
+ j = 11 + ((unsigned)b & 0x7f);
+ DUMPBITS(7);
+ if ((unsigned)i + j > n)
+ return 1;
+ while (j--)
+ ll[i++] = 0;
+ l = 0;
+ }
+ }
+
+ DEBG("dyn4 ");
+
+ /* free decoding table for trees */
+ huft_free(tl);
+
+ DEBG("dyn5 ");
+
+ /* restore the global bit buffer */
+ bb = b;
+ bk = k;
+
+ DEBG("dyn5a ");
+
+ /* build the decoding tables for literal/length and distance codes */
+ bl = lbits;
+ if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl)) != 0) {
+ DEBG("dyn5b ");
+ if (i == 1) {
+ error("incomplete literal tree");
+ huft_free(tl);
+ }
+ return i; /* incomplete code set */
+ }
+ DEBG("dyn5c ");
+ bd = dbits;
+ if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd)) != 0) {
+ DEBG("dyn5d ");
+ if (i == 1) {
+ error("incomplete distance tree");
#ifdef PKZIP_BUG_WORKAROUND
- i = 0;
- }
+ i = 0;
+ }
#else
- huft_free(td);
- }
- huft_free(tl);
- return i; /* incomplete code set */
+ huft_free(td);
+ }
+ huft_free(tl);
+ return i; /* incomplete code set */
#endif
- }
+ }

-DEBG("dyn6 ");
+ DEBG("dyn6 ");

- /* decompress until an end-of-block code */
- if (inflate_codes(tl, td, bl, bd))
- return 1;
+ /* decompress until an end-of-block code */
+ if (inflate_codes(tl, td, bl, bd))
+ return 1;

-DEBG("dyn7 ");
+ DEBG("dyn7 ");

- /* free the decoding tables, return */
- huft_free(tl);
- huft_free(td);
+ /* free the decoding tables, return */
+ huft_free(tl);
+ huft_free(td);

- DEBG(">");
- return 0;
+ DEBG(">");
+ return 0;

- underrun:
- return 4; /* Input underrun */
+ underrun:
+ return 4; /* Input underrun */
}

-
-
-STATIC int INIT inflate_block(
- int *e /* last block flag */
- )
-/* decompress an inflated block */
+/* inflate_block - decompress a deflated block
+ * @e: last block flag
+ */
+STATIC int INIT inflate_block(int *e)
{
- unsigned t; /* block type */
- register ulg b; /* bit buffer */
- register unsigned k; /* number of bits in bit buffer */
+ unsigned t; /* block type */
+ register ulg b; /* bit buffer */
+ register unsigned k; /* number of bits in bit buffer */
+
+ DEBG("<blk");
+
+ /* make local bit buffer */
+ b = bb;
+ k = bk;
+
+ /* read in last block bit */
+ NEEDBITS(1);
+ *e = (int)b & 1;
+ DUMPBITS(1);
+
+ /* read in block type */
+ NEEDBITS(2);
+ t = (unsigned)b & 3;
+ DUMPBITS(2);
+
+ /* restore the global bit buffer */
+ bb = b;
+ bk = k;
+
+ /* inflate that block type */
+ if (t == 2)
+ return inflate_dynamic();
+ if (t == 0)
+ return inflate_stored();
+ if (t == 1)
+ return inflate_fixed();

- DEBG("<blk");
+ DEBG(">");

- /* make local bit buffer */
- b = bb;
- k = bk;
+ /* bad block type */
+ return 2;

-
- /* read in last block bit */
- NEEDBITS(1)
- *e = (int)b & 1;
- DUMPBITS(1)
-
-
- /* read in block type */
- NEEDBITS(2)
- t = (unsigned)b & 3;
- DUMPBITS(2)
-
-
- /* restore the global bit buffer */
- bb = b;
- bk = k;
-
- /* inflate that block type */
- if (t == 2)
- return inflate_dynamic();
- if (t == 0)
- return inflate_stored();
- if (t == 1)
- return inflate_fixed();
-
- DEBG(">");
-
- /* bad block type */
- return 2;
-
- underrun:
- return 4; /* Input underrun */
+ underrun:
+ return 4; /* Input underrun */
}

-
-
+/* inflate - decompress an inflated entry */
STATIC int INIT inflate(void)
-/* decompress an inflated entry */
{
- int e; /* last block flag */
- int r; /* result code */
- unsigned h; /* maximum struct huft's malloc'ed */
- void *ptr;
-
- /* initialize window, bit buffer */
- wp = 0;
- bk = 0;
- bb = 0;
-
-
- /* decompress until the last block */
- h = 0;
- do {
- hufts = 0;
- gzip_mark(&ptr);
- if ((r = inflate_block(&e)) != 0) {
- gzip_release(&ptr);
- return r;
- }
- gzip_release(&ptr);
- if (hufts > h)
- h = hufts;
- } while (!e);
-
- /* Undo too much lookahead. The next read will be byte aligned so we
- * can discard unused bits in the last meaningful byte.
- */
- while (bk >= 8) {
- bk -= 8;
- inptr--;
- }
+ int e; /* last block flag */
+ int r; /* result code */
+ unsigned h; /* maximum struct huft's malloc'ed */
+ void *ptr;
+
+ /* initialize window, bit buffer */
+ wp = 0;
+ bk = 0;
+ bb = 0;
+
+ /* decompress until the last block */
+ h = 0;
+ do {
+ hufts = 0;
+ gzip_mark(&ptr);
+ if ((r = inflate_block(&e)) != 0) {
+ gzip_release(&ptr);
+ return r;
+ }
+ gzip_release(&ptr);
+ if (hufts > h)
+ h = hufts;
+ } while (!e);
+
+ /* Undo too much lookahead. The next read will be byte aligned so we
+ * can discard unused bits in the last meaningful byte.
+ */
+ while (bk >= 8) {
+ bk -= 8;
+ inptr--;
+ }

- /* flush out slide */
- flush_output(wp);
+ /* flush out slide */
+ flush_output(wp);

-
- /* return success */
+ /* return success */
#ifdef DEBUG
- fprintf(stderr, "<%u> ", h);
-#endif /* DEBUG */
- return 0;
+ fprintf(stderr, "<%u> ", h);
+#endif /* DEBUG */
+ return 0;
}

/**********************************************************************
@@ -1041,44 +1038,42 @@ static ulg crc; /* initialized in makec
#define CRC_VALUE (crc ^ 0xffffffffUL)

/*
- * Code to compute the CRC-32 table. Borrowed from
+ * Code to compute the CRC-32 table. Borrowed from
* gzip-1.0.3/makecrc.c.
+ * Not copyrighted 1990 Mark Adler
*/

-static void INIT
-makecrc(void)
+static void INIT makecrc(void)
{
-/* Not copyrighted 1990 Mark Adler */

- unsigned long c; /* crc shift register */
- unsigned long e; /* polynomial exclusive-or pattern */
- int i; /* counter for all possible eight bit values */
- int k; /* byte being shifted into crc apparatus */
-
- /* terms of polynomial defining this crc (except x^32): */
- static const int p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
-
- /* Make exclusive-or pattern from polynomial */
- e = 0;
- for (i = 0; i < sizeof(p)/sizeof(int); i++)
- e |= 1L << (31 - p[i]);
-
- crc_32_tab[0] = 0;
-
- for (i = 1; i < 256; i++)
- {
- c = 0;
- for (k = i | 256; k != 1; k >>= 1)
- {
- c = c & 1 ? (c >> 1) ^ e : c >> 1;
- if (k & 1)
- c ^= e;
- }
- crc_32_tab[i] = c;
- }
+ unsigned long c; /* crc shift register */
+ unsigned long e; /* polynomial exclusive-or pattern */
+ int i; /* counter for all possible eight bit values */
+ int k; /* byte being shifted into crc apparatus */
+
+ /* terms of polynomial defining this crc (except x^32): */
+ static const int p[] =
+ { 0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26 };
+
+ /* Make exclusive-or pattern from polynomial */
+ e = 0;
+ for (i = 0; i < sizeof(p) / sizeof(int); i++)
+ e |= 1L << (31 - p[i]);
+
+ crc_32_tab[0] = 0;
+
+ for (i = 1; i < 256; i++) {
+ c = 0;
+ for (k = i | 256; k != 1; k >>= 1) {
+ c = c & 1 ? (c >> 1) ^ e : c >> 1;
+ if (k & 1)
+ c ^= e;
+ }
+ crc_32_tab[i] = c;
+ }

- /* this is initialized here so this code could reside in ROM */
- crc = (ulg)0xffffffffUL; /* shift register contents */
+ /* this is initialized here so this code could reside in ROM */
+ crc = (ulg)0xffffffffUL; /* shift register contents */
}

/* gzip flag byte */
@@ -1095,118 +1090,118 @@ makecrc(void)
*/
static int INIT gunzip(void)
{
- uch flags;
- unsigned char magic[2]; /* magic header */
- char method;
- ulg orig_crc = 0; /* original crc */
- ulg orig_len = 0; /* original uncompressed length */
- int res;
-
- magic[0] = NEXTBYTE();
- magic[1] = NEXTBYTE();
- method = NEXTBYTE();
-
- if (magic[0] != 037 ||
- ((magic[1] != 0213) && (magic[1] != 0236))) {
- error("bad gzip magic numbers");
- return -1;
- }
-
- /* We only support method #8, DEFLATED */
- if (method != 8) {
- error("internal error, invalid method");
- return -1;
- }
-
- flags = (uch)get_byte();
- if ((flags & ENCRYPTED) != 0) {
- error("Input is encrypted");
- return -1;
- }
- if ((flags & CONTINUATION) != 0) {
- error("Multi part input");
- return -1;
- }
- if ((flags & RESERVED) != 0) {
- error("Input has invalid flags");
- return -1;
- }
- NEXTBYTE(); /* Get timestamp */
- NEXTBYTE();
- NEXTBYTE();
- NEXTBYTE();
-
- (void)NEXTBYTE(); /* Ignore extra flags for the moment */
- (void)NEXTBYTE(); /* Ignore OS type for the moment */
-
- if ((flags & EXTRA_FIELD) != 0) {
- unsigned len = (unsigned)NEXTBYTE();
- len |= ((unsigned)NEXTBYTE())<<8;
- while (len--) (void)NEXTBYTE();
- }
-
- /* Get original file name if it was truncated */
- if ((flags & ORIG_NAME) != 0) {
- /* Discard the old name */
- while (NEXTBYTE() != 0) /* null */ ;
- }
-
- /* Discard file comment if any */
- if ((flags & COMMENT) != 0) {
- while (NEXTBYTE() != 0) /* null */ ;
- }
-
- /* Decompress */
- if ((res = inflate())) {
- switch (res) {
- case 0:
- break;
- case 1:
- error("invalid compressed format (err=1)");
- break;
- case 2:
- error("invalid compressed format (err=2)");
- break;
- case 3:
- error("out of memory");
- break;
- case 4:
- error("out of input data");
- break;
- default:
- error("invalid compressed format (other)");
- }
- return -1;
- }
-
- /* Get the crc and original length */
- /* crc32 (see algorithm.doc)
- * uncompressed input size modulo 2^32
- */
- orig_crc = (ulg) NEXTBYTE();
- orig_crc |= (ulg) NEXTBYTE() << 8;
- orig_crc |= (ulg) NEXTBYTE() << 16;
- orig_crc |= (ulg) NEXTBYTE() << 24;
-
- orig_len = (ulg) NEXTBYTE();
- orig_len |= (ulg) NEXTBYTE() << 8;
- orig_len |= (ulg) NEXTBYTE() << 16;
- orig_len |= (ulg) NEXTBYTE() << 24;
-
- /* Validate decompression */
- if (orig_crc != CRC_VALUE) {
- error("crc error");
- return -1;
- }
- if (orig_len != bytes_out) {
- error("length error");
- return -1;
- }
- return 0;
-
- underrun: /* NEXTBYTE() goto's here if needed */
- error("out of input data");
- return -1;
+ uch flags;
+ unsigned char magic[2]; /* magic header */
+ char method;
+ ulg orig_crc = 0; /* original crc */
+ ulg orig_len = 0; /* original uncompressed length */
+ int res;
+
+ magic[0] = NEXTBYTE();
+ magic[1] = NEXTBYTE();
+ method = NEXTBYTE();
+
+ if (magic[0] != 037 || ((magic[1] != 0213) && (magic[1] != 0236))) {
+ error("bad gzip magic numbers");
+ return -1;
+ }
+
+ /* We only support method #8, DEFLATED */
+ if (method != 8) {
+ error("internal error, invalid method");
+ return -1;
+ }
+
+ flags = (uch)get_byte();
+ if ((flags & ENCRYPTED) != 0) {
+ error("Input is encrypted");
+ return -1;
+ }
+ if ((flags & CONTINUATION) != 0) {
+ error("Multi part input");
+ return -1;
+ }
+ if ((flags & RESERVED) != 0) {
+ error("Input has invalid flags");
+ return -1;
+ }
+ NEXTBYTE(); /* Get timestamp */
+ NEXTBYTE();
+ NEXTBYTE();
+ NEXTBYTE();
+
+ (void)NEXTBYTE(); /* Ignore extra flags for the moment */
+ (void)NEXTBYTE(); /* Ignore OS type for the moment */
+
+ if ((flags & EXTRA_FIELD) != 0) {
+ unsigned len = (unsigned)NEXTBYTE();
+ len |= ((unsigned)NEXTBYTE()) << 8;
+ while (len--)
+ (void)NEXTBYTE();
+ }
+
+ /* Get original file name if it was truncated */
+ if ((flags & ORIG_NAME) != 0) {
+ /* Discard the old name */
+ while (NEXTBYTE() != 0) /* null */
+ ;
+ }
+
+ /* Discard file comment if any */
+ if ((flags & COMMENT) != 0) {
+ while (NEXTBYTE() != 0) /* null */
+ ;
+ }
+
+ /* Decompress */
+ if ((res = inflate())) {
+ switch (res) {
+ case 0:
+ break;
+ case 1:
+ error("invalid compressed format (err=1)");
+ break;
+ case 2:
+ error("invalid compressed format (err=2)");
+ break;
+ case 3:
+ error("out of memory");
+ break;
+ case 4:
+ error("out of input data");
+ break;
+ default:
+ error("invalid compressed format (other)");
+ }
+ return -1;
+ }
+
+ /* Get the crc and original length */
+ /* crc32 (see algorithm.doc)
+ * uncompressed input size modulo 2^32
+ */
+ orig_crc = (ulg)NEXTBYTE();
+ orig_crc |= (ulg)NEXTBYTE() << 8;
+ orig_crc |= (ulg)NEXTBYTE() << 16;
+ orig_crc |= (ulg)NEXTBYTE() << 24;
+
+ orig_len = (ulg)NEXTBYTE();
+ orig_len |= (ulg)NEXTBYTE() << 8;
+ orig_len |= (ulg)NEXTBYTE() << 16;
+ orig_len |= (ulg)NEXTBYTE() << 24;
+
+ /* Validate decompression */
+ if (orig_crc != CRC_VALUE) {
+ error("crc error");
+ return -1;
+ }
+ if (orig_len != bytes_out) {
+ error("length error");
+ return -1;
+ }
+ return 0;
+
+ underrun: /* NEXTBYTE() goto's here if needed */
+ error("out of input data");
+ return -1;
}
-
-


2005-10-31 20:59:58

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 5/20] inflate: cleanup Huffman table code

inflate: cleanup huffman table code

sensible names for huft struct members
get rid of assignment-in-expression usage

Signed-off-by: Matt Mackall <[email protected]>

Index: 2.6.14/lib/inflate.c
===================================================================
--- 2.6.14.orig/lib/inflate.c 2005-10-28 21:03:12.000000000 -0700
+++ 2.6.14/lib/inflate.c 2005-10-28 21:04:46.000000000 -0700
@@ -117,12 +117,12 @@
an unused code. If a code with e == 99 is looked up, this implies an
error in the data. */
struct huft {
- u8 e; /* number of extra bits or operation */
- u8 b; /* number of bits in this code or subcode */
union {
- u16 n; /* literal, length base, or distance base */
- struct huft *t; /* pointer to next level of table */
- } v;
+ u16 val; /* literal, length base, or distance base */
+ struct huft *next; /* pointer to next level of table */
+ };
+ u8 extra; /* number of extra bits or operation */
+ u8 bits; /* number of bits in this code or subcode */
};

struct iostate {
@@ -393,11 +393,14 @@ static int INIT huft_build(unsigned *b,
DEBG("huft3 ");

/* Adjust last length count to fill out codes, if needed */
- for (y = 1 << j; j < i; j++, y <<= 1)
- if ((y -= c[j]) < 0)
+ for (y = 1 << j; j < i; j++, y <<= 1) {
+ y -= c[j];
+ if (y < 0)
return 2; /* bad input: more codes than bits */
+ }

- if ((y -= c[i]) < 0)
+ y -= c[i];
+ if (y < 0)
return 2;
c[i] += y;

@@ -408,8 +411,12 @@ static int INIT huft_build(unsigned *b,
p = c + 1;
xp = x + 2;
/* note that i == g from above */
- while (--i)
- *xp++ = (j += *p++);
+ while (--i) {
+ j += *p;
+ *xp = j;
+ p++;
+ xp++;
+ }

DEBG("huft5 ");

@@ -417,7 +424,8 @@ static int INIT huft_build(unsigned *b,
p = b;
i = 0;
do {
- if ((j = *p++))
+ j = *p++;
+ if (j)
v[x[j]++] = i;
} while (++i < n);

@@ -450,10 +458,12 @@ static int INIT huft_build(unsigned *b,

/* compute min size <= l bits */
/* upper limit on table size */
- z = (z = g - w) > (unsigned)l ? l : z;
+ z = min(l, g - w);

/* try a k-w bit table */
- if ((f = 1 << (j = k - w)) > a + 1) {
+ j = k - w;
+ f = 1 << j;
+ if (f > a + 1) {
/* too few codes for k-w bit table */
DEBG1("2 ");
/* deduct codes from patterns left */
@@ -463,7 +473,8 @@ static int INIT huft_build(unsigned *b,
if (j < z) {
/* enough codes for j bits? */
while (++j < z) {
- if ((f <<= 1) <= *++xp)
+ f <<= 1;
+ if (f <= *++xp)
break;
/* deduct from pats */
f -= *xp;
@@ -476,15 +487,17 @@ static int INIT huft_build(unsigned *b,
z = 1 << j;

/* allocate and link in new table */
- if (!(q = (struct huft *)malloc(
- (z + 1) * sizeof(struct huft)))) {
+ q = malloc((z + 1) * sizeof(struct huft));
+ if (!q) {
if (h)
huft_free(u[0]);
return 3; /* not enough memory */
}
+
DEBG1("4 ");
*t = q + 1; /* link to list for huft_free */
- *(t = &(q->v.t)) = 0;
+ t = &q->next;
+ *t = NULL;
u[h] = ++q; /* table starts after link */

DEBG1("5 ");
@@ -493,11 +506,11 @@ static int INIT huft_build(unsigned *b,
/* save pattern for backing up */
x[h] = i;
/* bits to dump before this table */
- r.b = (u8)l;
+ r.bits = (u8)l;
/* bits in this table */
- r.e = (u8)(16 + j);
+ r.extra = (u8)(16 + j);
/* pointer to this table */
- r.v.t = q;
+ r.next = q;
/* (get around Turbo C bug) */
j = i >> (w - l);
/* connect to last table */
@@ -508,20 +521,20 @@ static int INIT huft_build(unsigned *b,
DEBG("h6c ");

/* set up table entry in r */
- r.b = (u8) (k - w);
+ r.bits = (u8)(k - w);
if (p >= v + n)
- r.e = 99; /* out of values--invalid code */
+ r.extra = 99; /* out of values--invalid code */
else if (*p < s) {
/* 256 is end-of-block code */
- r.e = (u8)(*p < 256 ? 16 : 15);
+ r.extra = (u8)(*p < 256 ? 16 : 15);
/* simple code is just the value */
- r.v.n = (u16)(*p);
+ r.val = (u16)(*p);
/* one compiler does not like *p++ */
p++;
} else {
/* non-simple--look up in lists */
- r.e = (u8)e[*p - s];
- r.v.n = d[*p++ - s];
+ r.extra = (u8)e[*p - s];
+ r.val = d[*p++ - s];
}
DEBG("h6d ");

@@ -559,16 +572,16 @@ static int INIT huft_build(unsigned *b,
* linked list of the tables it made, with the links in a dummy first
* entry of each table.
*/
-STATIC int INIT huft_free(struct huft *t)
+static int INIT huft_free(struct huft *t)
{
- struct huft *p, *q;
+ struct huft *q;

/* Go through list, freeing from the malloced (t[-1]) address. */
- p = t;
- while (p) {
- q = (--p)->v.t;
- free((char *)p);
- p = q;
+ while (t) {
+ t -= 1;
+ q = t->next;
+ free(t);
+ t = q;
}
return 0;
}
@@ -587,45 +600,40 @@ STATIC int INIT huft_free(struct huft *t
static int INIT inflate_codes(struct iostate *io, struct huft *tl, struct huft *td,
int bl, int bd)
{
- unsigned e; /* table entry flag/number of extra bits */
unsigned len, dist;
struct huft *t; /* pointer to table entry */

/* inflate the coded data */
for (;;) { /* do until end of block */
t = tl + readbits(io, bl);
- e = t->e;
- while (e > 16) {
- if (e == 99)
+ while (t->extra > 16) {
+ if (t->extra == 99)
return 1;
- dumpbits(io, t->b);
- t = t->v.t + readbits(io, e - 16);
- e = t->e;
+ dumpbits(io, t->bits);
+ t = &t->next[readbits(io, t->extra - 16)];
}
- dumpbits(io, t->b);
- if (e == 16) { /* then it's a literal */
- put_byte(io, t->v.n);
+ dumpbits(io, t->bits);
+ if (t->extra == 16) { /* then it's a literal */
+ put_byte(io, t->val);
} else { /* it's an EOB or a length */
/* exit if end of block */
- if (e == 15)
+ if (t->extra == 15)
break;

/* get length of block to copy */
- len = t->v.n + pullbits(io, e);
+ len = t->val + pullbits(io, t->extra);

/* decode distance of block to copy */
t = td + readbits(io, bd);
- e = t->e;
- while (e > 16) {
- if (e == 99)
+ while (t->extra > 16) {
+ if (t->extra == 99)
return 1;
- dumpbits(io, t->b);
- t = t->v.t + readbits(io, e - 16);
- e = t->e;
+ dumpbits(io, t->bits);
+ t = &t->next[readbits(io, t->extra - 16)];
}
- dumpbits(io, t->b);
+ dumpbits(io, t->bits);

- dist = t->v.n + pullbits(io, e);
+ dist = t->val + pullbits(io, t->extra);
copy_bytes(io, len, dist);
}
}
@@ -767,8 +775,8 @@ static int noinline INIT inflate_dynamic
i = l = 0;
while ((unsigned)i < n) {
td = tl + readbits(io, bl);
- dumpbits(io, td->b);
- j = td->v.n;
+ dumpbits(io, td->bits);
+ j = td->val;
if (j < 16) /* length of code in bits (0..15) */
ll[i++] = l = j; /* save last length in l */
else if (j == 16) { /* repeat last length 3 to 6 times */

2005-10-31 21:01:00

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 7/20] inflate: eliminate memzero usage

inflate: replace call to memzero with simple loop

This is the only user of memzero in the inflate code and it's only for
16 bytes. Removing this lets us drop a copy of memzero from most
lib/inflate users.

Signed-off-by: Matt Mackall <[email protected]>

Index: 2.6.14/lib/inflate.c
===================================================================
--- 2.6.14.orig/lib/inflate.c 2005-10-31 12:21:21.000000000 -0800
+++ 2.6.14/lib/inflate.c 2005-10-31 12:21:22.000000000 -0800
@@ -365,8 +365,10 @@ static int INIT huft_build(unsigned *b,

DEBG("huft1 ");

+ for (i = 0; i < BMAX + 1; i++)
+ c[i] = 0;
+
/* Generate counts for each bit length */
- memzero(c, sizeof(c));
p = b;
i = n;
do {

2005-10-31 21:00:59

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 3/20] inflate: clean up input logic

inflate: cleanup input logic

Transform ugly macros to inlines
Kill mask_bits table
Eliminate magic underrun handling (dealt with by getbyte())

Signed-off-by: Matt Mackall <[email protected]>

Index: tiny/lib/inflate.c
===================================================================
--- tiny.orig/lib/inflate.c 2005-09-28 18:21:30.000000000 -0700
+++ tiny/lib/inflate.c 2005-09-28 18:22:39.000000000 -0700
@@ -183,24 +183,23 @@ static const u16 cpdext[] = {
12, 12, 13, 13
};

-/* Macros for inflate() bit peeking and grabbing.
+/* Inlines for inflate() bit peeking and grabbing.
The usage is:

- NEEDBITS(j)
- x = b & mask_bits[j];
- DUMPBITS(j)
-
- where NEEDBITS makes sure that b has at least j bits in it, and
- DUMPBITS removes the bits from b. The macros use the variable k for
- the number of bits in b. Normally, b and k are initialized at the
- beginning of a routine that uses these macros from a global bit
- buffer and count.
+ x = readbits(&b, &k, j);
+ dumpbits(&b, &k, j);
+
+ x = pullbits(&b, &k, j);
+
+ where readbits makes sure that b has at least j bits in it, and
+ dumpbits removes the bits from b, while k tracks the number of bits
+ in b.

If we assume that EOB will be the longest code, then we will never
- ask for bits with NEEDBITS that are beyond the end of the stream.
- So, NEEDBITS should not read any more bytes than are needed to
- meet the request. Then no bytes need to be "returned" to the buffer
- at the end of the last block.
+ ask for bits that are beyond the end of the stream. So, readbits
+ should not read any more bytes than are needed to meet the request.
+ Then no bytes need to be "returned" to the buffer at the end of the
+ last block.

However, this assumption is not true for fixed blocks--the EOB code
is 7 bits, but the other literal/length codes can be 8 or 9 bits.
@@ -216,15 +215,25 @@ static const u16 cpdext[] = {
static u32 bb; /* bit buffer */
static unsigned bk; /* bits in bit buffer */

-static const u16 mask_bits[] = {
- 0x0000,
- 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
- 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
-};
+static inline u32 readbits(u32 *b, u32 *k, int n)
+{
+ for( ; *k < n; *k += 8)
+ *b |= (u32)get_byte() << *k;
+ return *b & ((1 << n) - 1);
+}

-#define NEXTBYTE() ({ int v = get_byte(); if (v < 0) goto underrun; (u8)v; })
-#define NEEDBITS(n) do {while(k<(n)){b|=((u32)NEXTBYTE())<<k;k+=8;}} while(0)
-#define DUMPBITS(n) do {b>>=(n);k-=(n);} while(0)
+static inline void dumpbits(u32 *b, u32 *k, int n)
+{
+ *b >>= n;
+ *k -= n;
+}
+
+static inline u32 pullbits(u32 *b, u32 *k, int n)
+{
+ u32 r = readbits(b, k, n);
+ dumpbits(b, k, n);
+ return r;
+}

/*
Huffman code decoding is performed using a multi-level table lookup.
@@ -541,7 +550,6 @@ static int inflate_codes(struct huft *tl
unsigned n, d; /* length and index for copy */
unsigned w; /* current window position */
struct huft *t; /* pointer to table entry */
- unsigned ml, md; /* masks for bl and bd bits */
u32 b; /* bit buffer */
unsigned k; /* number of bits in bit buffer */

@@ -551,20 +559,17 @@ static int inflate_codes(struct huft *tl
w = outcnt; /* initialize window position */

/* inflate the coded data */
- ml = mask_bits[bl]; /* precompute masks for speed */
- md = mask_bits[bd];
for (;;) { /* do until end of block */
- NEEDBITS((unsigned)bl);
- if ((e = (t = tl + ((unsigned)b & ml))->e) > 16)
- do {
- if (e == 99)
- return 1;
- DUMPBITS(t->b);
- e -= 16;
- NEEDBITS(e);
- } while ((e = (t = t->v.t + ((unsigned)b &
- mask_bits[e]))->e) > 16);
- DUMPBITS(t->b);
+ t = tl + readbits(&b, &k, bl);
+ e = t->e;
+ while (e > 16) {
+ if (e == 99)
+ return 1;
+ dumpbits(&b, &k, t->b);
+ t = t->v.t + readbits(&b, &k, e - 16);
+ e = t->e;
+ }
+ dumpbits(&b, &k, t->b);
if (e == 16) { /* then it's a literal */
window[w++] = (u8)t->v.n;
if (w == WSIZE) {
@@ -577,25 +582,21 @@ static int inflate_codes(struct huft *tl
break;

/* get length of block to copy */
- NEEDBITS(e);
- n = t->v.n + ((unsigned)b & mask_bits[e]);
- DUMPBITS(e);
+ n = t->v.n + pullbits(&b, &k, e);

/* decode distance of block to copy */
- NEEDBITS((unsigned)bd);
- if ((e = (t = td + ((unsigned)b & md))->e) > 16)
- do {
- if (e == 99)
- return 1;
- DUMPBITS(t->b);
- e -= 16;
- NEEDBITS(e);
- } while ((e = (t = t->v.t + ((unsigned)b
- & mask_bits[e]))->e) > 16);
- DUMPBITS(t->b);
- NEEDBITS(e);
- d = w - t->v.n - ((unsigned)b & mask_bits[e]);
- DUMPBITS(e)
+ t = td + readbits(&b, &k, bd);
+ e = t->e;
+ while (e > 16) {
+ if (e == 99)
+ return 1;
+ dumpbits(&b, &k, t->b);
+ t = t->v.t + readbits(&b, &k, e - 16);
+ e = t->e;
+ }
+ dumpbits(&b, &k, t->b);
+
+ d = w - t->v.n - pullbits(&b, &k, e);

/* do the copy */
do {
@@ -628,9 +629,6 @@ static int inflate_codes(struct huft *tl

/* done */
return 0;
-
- underrun:
- return 4; /* Input underrun */
}

/* inflate_stored - "decompress" an inflated type 0 (stored) block. */
@@ -649,27 +647,20 @@ static int INIT inflate_stored(void)
w = outcnt; /* initialize window position */

/* go to byte boundary */
- n = k & 7;
- DUMPBITS(n);
+ dumpbits(&b, &k, k & 7);

/* get the length and its complement */
- NEEDBITS(16);
- n = ((unsigned)b & 0xffff);
- DUMPBITS(16);
- NEEDBITS(16);
- if (n != (unsigned)((~b) & 0xffff))
+ n = pullbits(&b, &k, 16);
+ if (n != (~pullbits(&b, &k, 16) & 0xffff))
return 1; /* error in compressed data */
- DUMPBITS(16);

/* read and output the compressed data */
while (n--) {
- NEEDBITS(8);
- window[w++] = (u8)b;
+ window[w++] = (u8)get_byte();
if (w == WSIZE) {
flush_output(w);
w = 0;
}
- DUMPBITS(8);
}

/* restore the globals from the locals */
@@ -679,9 +670,6 @@ static int INIT inflate_stored(void)

DEBG(">");
return 0;
-
- underrun:
- return 4; /* Input underrun */
}


@@ -748,7 +736,6 @@ static int noinline INIT inflate_dynamic
int i; /* temporary variables */
unsigned j;
unsigned l; /* last length */
- unsigned m; /* mask for bit lengths table */
unsigned n; /* number of lengths to get */
struct huft *tl; /* literal/length code table */
struct huft *td; /* distance code table */
@@ -768,26 +755,17 @@ static int noinline INIT inflate_dynamic
k = bk;

/* read in table lengths */
- NEEDBITS(5);
- nl = 257 + ((unsigned)b & 0x1f); /* number of literal/length codes */
- DUMPBITS(5);
- NEEDBITS(5);
- nd = 1 + ((unsigned)b & 0x1f); /* number of distance codes */
- DUMPBITS(5);
- NEEDBITS(4);
- nb = 4 + ((unsigned)b & 0xf); /* number of bit length codes */
- DUMPBITS(4);
+ nl = 257 + pullbits(&b, &k, 5); /* number of literal/length codes */
+ nd = 1 + pullbits(&b, &k, 5); /* number of distance codes */
+ nb = 4 + pullbits(&b, &k, 4); /* number of bit length codes */
if (nl > 286 || nd > 30)
return 1; /* bad lengths */

DEBG("dyn1 ");

/* read in bit-length-code lengths */
- for (j = 0; j < nb; j++) {
- NEEDBITS(3);
- ll[border[j]] = (unsigned)b & 7;
- DUMPBITS(3);
- }
+ for (j = 0; j < nb; j++)
+ ll[border[j]] = pullbits(&b, &k, 3);
for (; j < 19; j++)
ll[border[j]] = 0;

@@ -805,36 +783,28 @@ static int noinline INIT inflate_dynamic

/* read in literal and distance code lengths */
n = nl + nd;
- m = mask_bits[bl];
i = l = 0;
while ((unsigned)i < n) {
- NEEDBITS((unsigned)bl);
- j = (td = tl + ((unsigned)b & m))->b;
- DUMPBITS(j);
+ td = tl + readbits(&b, &k, bl);
+ dumpbits(&b, &k, td->b);
j = td->v.n;
if (j < 16) /* length of code in bits (0..15) */
ll[i++] = l = j; /* save last length in l */
else if (j == 16) { /* repeat last length 3 to 6 times */
- NEEDBITS(2);
- j = 3 + ((unsigned)b & 3);
- DUMPBITS(2);
- if ((unsigned)i + j > n)
+ j = 3 + pullbits(&b, &k, 2);
+ if ((unsigned)i + j > n)
return 1;
while (j--)
ll[i++] = l;
} else if (j == 17) { /* 3 to 10 zero length codes */
- NEEDBITS(3);
- j = 3 + ((unsigned)b & 7);
- DUMPBITS(3);
+ j = 3 + pullbits(&b, &k, 3);
if ((unsigned)i + j > n)
return 1;
while (j--)
ll[i++] = 0;
l = 0;
} else { /* j == 18: 11 to 138 zero length codes */
- NEEDBITS(7);
- j = 11 + ((unsigned)b & 0x7f);
- DUMPBITS(7);
+ j = 11 + pullbits(&b, &k, 7);
if ((unsigned)i + j > n)
return 1;
while (j--)
@@ -892,9 +862,6 @@ static int noinline INIT inflate_dynamic

DEBG(">");
return 0;
-
- underrun:
- return 4; /* Input underrun */
}

/* inflate_block - decompress a deflated block
@@ -903,28 +870,11 @@ static int noinline INIT inflate_dynamic
static int INIT inflate_block(int *e)
{
unsigned t; /* block type */
- u32 b; /* bit buffer */
- unsigned k; /* number of bits in bit buffer */

DEBG("<blk");

- /* make local bit buffer */
- b = bb;
- k = bk;
-
- /* read in last block bit */
- NEEDBITS(1);
- *e = (int)b & 1;
- DUMPBITS(1);
-
- /* read in block type */
- NEEDBITS(2);
- t = (unsigned)b & 3;
- DUMPBITS(2);
-
- /* restore the global bit buffer */
- bb = b;
- bk = k;
+ *e = pullbits(&bb, &bk, 1); /* read in last block bit */
+ t = pullbits(&bb, &bk, 2); /* read in block type */

/* inflate that block type */
if (t == 2)
@@ -938,9 +888,6 @@ static int INIT inflate_block(int *e)

/* bad block type */
return 2;
-
- underrun:
- return 4; /* Input underrun */
}

/* inflate - decompress an inflated entry */
@@ -1050,9 +997,9 @@ static int INIT gunzip(void)
u32 orig_len = 0; /* original uncompressed length */
int res;

- magic[0] = NEXTBYTE();
- magic[1] = NEXTBYTE();
- method = NEXTBYTE();
+ magic[0] = get_byte();
+ magic[1] = get_byte();
+ method = get_byte();

if (magic[0] != 037 || ((magic[1] != 0213) && (magic[1] != 0236))) {
error("bad gzip magic numbers");
@@ -1078,29 +1025,29 @@ static int INIT gunzip(void)
error("Input has invalid flags");
return -1;
}
- NEXTBYTE(); /* Get timestamp */
- NEXTBYTE();
- NEXTBYTE();
- NEXTBYTE();
+ get_byte(); /* Get timestamp */
+ get_byte();
+ get_byte();
+ get_byte();

- (void)NEXTBYTE(); /* Ignore extra flags for the moment */
- (void)NEXTBYTE(); /* Ignore OS type for the moment */
+ get_byte(); /* Ignore extra flags for the moment */
+ get_byte(); /* Ignore OS type for the moment */

if (flags & EXTRA_FIELD) {
- unsigned len = (unsigned)NEXTBYTE();
- len |= ((unsigned)NEXTBYTE()) << 8;
+ unsigned len = (unsigned)get_byte();
+ len |= ((unsigned)get_byte()) << 8;
while (len--)
- (void)NEXTBYTE();
+ get_byte();
}

/* Discard original file name if it was truncated */
if (flags & ORIG_NAME)
- while (NEXTBYTE())
+ while (get_byte())
;

/* Discard file comment if any */
if (flags & COMMENT)
- while (NEXTBYTE())
+ while (get_byte())
;

/* Decompress */
@@ -1130,15 +1077,15 @@ static int INIT gunzip(void)
/* crc32 (see algorithm.doc)
* uncompressed input size modulo 2^32
*/
- orig_crc = (u32)NEXTBYTE();
- orig_crc |= (u32)NEXTBYTE() << 8;
- orig_crc |= (u32)NEXTBYTE() << 16;
- orig_crc |= (u32)NEXTBYTE() << 24;
-
- orig_len = (u32)NEXTBYTE();
- orig_len |= (u32)NEXTBYTE() << 8;
- orig_len |= (u32)NEXTBYTE() << 16;
- orig_len |= (u32)NEXTBYTE() << 24;
+ orig_crc = (u32)get_byte();
+ orig_crc |= (u32)get_byte() << 8;
+ orig_crc |= (u32)get_byte() << 16;
+ orig_crc |= (u32)get_byte() << 24;
+
+ orig_len = (u32)get_byte();
+ orig_len |= (u32)get_byte() << 8;
+ orig_len |= (u32)get_byte() << 16;
+ orig_len |= (u32)get_byte() << 24;

/* Validate decompression */
if (orig_crc != CRC_VALUE) {
@@ -1150,8 +1097,4 @@ static int INIT gunzip(void)
return -1;
}
return 0;
-
- underrun: /* NEXTBYTE() goto's here if needed */
- error("out of input data");
- return -1;
}

2005-10-31 21:00:15

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 8/20] inflate: (arch) kill unneeded declarations

inflate: remove a bunch of declarations/definitions from callers

This removes:

- memset/memzero/memcpy implementations
- OF
- STATIC
- gzip flag byte defines
- unused debug defines

and saves an average of 50 lines in each of 12 users.

Signed-off-by: Matt Mackall <[email protected]>

Index: 2.6.14/arch/alpha/boot/misc.c
===================================================================
--- 2.6.14.orig/arch/alpha/boot/misc.c 2005-10-28 20:39:32.000000000 -0700
+++ 2.6.14/arch/alpha/boot/misc.c 2005-10-28 21:05:01.000000000 -0700
@@ -22,7 +22,6 @@

#include <asm/uaccess.h>

-#define memzero(s,n) memset ((s),0,(n))
#define puts srm_printk
extern long srm_printk(const char *, ...)
__attribute__ ((format (printf, 1, 2)));
@@ -30,8 +29,6 @@ extern long srm_printk(const char *, ...
/*
* gzip delarations
*/
-#define OF(args) args
-#define STATIC static

typedef unsigned char uch;
typedef unsigned short ush;
@@ -47,34 +44,8 @@ static unsigned insize; /* valid bytes
static unsigned inptr; /* index of next byte to be processed in inbuf */
static unsigned outcnt; /* bytes in output buffer */

-/* gzip flag byte */
-#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
-#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
-#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
-#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
-#define COMMENT 0x10 /* bit 4 set: file comment present */
-#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
-#define RESERVED 0xC0 /* bit 6,7: reserved */
-
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())

-/* Diagnostic functions */
-#ifdef DEBUG
-# define Assert(cond,msg) {if(!(cond)) error(msg);}
-# define Trace(x) fprintf x
-# define Tracev(x) {if (verbose) fprintf x ;}
-# define Tracevv(x) {if (verbose>1) fprintf x ;}
-# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
-# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
-#else
-# define Assert(cond,msg)
-# define Trace(x)
-# define Tracev(x)
-# define Tracevv(x)
-# define Tracec(c,x)
-# define Tracecv(c,x)
-#endif
-
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
Index: 2.6.14/arch/arm/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm/boot/compressed/misc.c 2005-10-28 20:39:32.000000000 -0700
+++ 2.6.14/arch/arm/boot/compressed/misc.c 2005-10-28 21:05:01.000000000 -0700
@@ -45,90 +45,8 @@ icedcc_putstr(const char *ptr)
#define __ptr_t void *

/*
- * Optimised C version of memzero for the ARM.
+ * gzip declarations
*/
-void __memzero (__ptr_t s, size_t n)
-{
- union { void *vp; unsigned long *ulp; unsigned char *ucp; } u;
- int i;
-
- u.vp = s;
-
- for (i = n >> 5; i > 0; i--) {
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- }
-
- if (n & 1 << 4) {
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- }
-
- if (n & 1 << 3) {
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- }
-
- if (n & 1 << 2)
- *u.ulp++ = 0;
-
- if (n & 1 << 1) {
- *u.ucp++ = 0;
- *u.ucp++ = 0;
- }
-
- if (n & 1)
- *u.ucp++ = 0;
-}
-
-static inline __ptr_t memcpy(__ptr_t __dest, __const __ptr_t __src,
- size_t __n)
-{
- int i = 0;
- unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;
-
- for (i = __n >> 3; i > 0; i--) {
- *d++ = *s++;
- *d++ = *s++;
- *d++ = *s++;
- *d++ = *s++;
- *d++ = *s++;
- *d++ = *s++;
- *d++ = *s++;
- *d++ = *s++;
- }
-
- if (__n & 1 << 2) {
- *d++ = *s++;
- *d++ = *s++;
- *d++ = *s++;
- *d++ = *s++;
- }
-
- if (__n & 1 << 1) {
- *d++ = *s++;
- *d++ = *s++;
- }
-
- if (__n & 1)
- *d++ = *s++;
-
- return __dest;
-}
-
-/*
- * gzip delarations
- */
-#define OF(args) args
-#define STATIC static

typedef unsigned char uch;
typedef unsigned short ush;
@@ -144,34 +62,8 @@ static unsigned insize; /* valid bytes
static unsigned inptr; /* index of next byte to be processed in inbuf */
static unsigned outcnt; /* bytes in output buffer */

-/* gzip flag byte */
-#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
-#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
-#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
-#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
-#define COMMENT 0x10 /* bit 4 set: file comment present */
-#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
-#define RESERVED 0xC0 /* bit 6,7: reserved */
-
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())

-/* Diagnostic functions */
-#ifdef DEBUG
-# define Assert(cond,msg) {if(!(cond)) error(msg);}
-# define Trace(x) fprintf x
-# define Tracev(x) {if (verbose) fprintf x ;}
-# define Tracevv(x) {if (verbose>1) fprintf x ;}
-# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
-# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
-#else
-# define Assert(cond,msg)
-# define Trace(x)
-# define Tracev(x)
-# define Tracevv(x)
-# define Tracec(c,x)
-# define Tracecv(c,x)
-#endif
-
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
Index: 2.6.14/arch/arm26/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm26/boot/compressed/misc.c 2005-10-28 20:39:32.000000000 -0700
+++ 2.6.14/arch/arm26/boot/compressed/misc.c 2005-10-28 21:05:01.000000000 -0700
@@ -30,90 +30,8 @@ unsigned int __machine_arch_type;
#define __ptr_t void *

/*
- * Optimised C version of memzero for the ARM.
- */
-void __memzero (__ptr_t s, size_t n)
-{
- union { void *vp; unsigned long *ulp; unsigned char *ucp; } u;
- int i;
-
- u.vp = s;
-
- for (i = n >> 5; i > 0; i--) {
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- }
-
- if (n & 1 << 4) {
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- }
-
- if (n & 1 << 3) {
- *u.ulp++ = 0;
- *u.ulp++ = 0;
- }
-
- if (n & 1 << 2)
- *u.ulp++ = 0;
-
- if (n & 1 << 1) {
- *u.ucp++ = 0;
- *u.ucp++ = 0;
- }
-
- if (n & 1)
- *u.ucp++ = 0;
-}
-
-static inline __ptr_t memcpy(__ptr_t __dest, __const __ptr_t __src,
- size_t __n)
-{
- int i = 0;
- unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;
-
- for (i = __n >> 3; i > 0; i--) {
- *d++ = *s++;
- *d++ = *s++;
- *d++ = *s++;
- *d++ = *s++;
- *d++ = *s++;
- *d++ = *s++;
- *d++ = *s++;
- *d++ = *s++;
- }
-
- if (__n & 1 << 2) {
- *d++ = *s++;
- *d++ = *s++;
- *d++ = *s++;
- *d++ = *s++;
- }
-
- if (__n & 1 << 1) {
- *d++ = *s++;
- *d++ = *s++;
- }
-
- if (__n & 1)
- *d++ = *s++;
-
- return __dest;
-}
-
-/*
* gzip delarations
*/
-#define OF(args) args
-#define STATIC static

typedef unsigned char uch;
typedef unsigned short ush;
@@ -129,34 +47,8 @@ static unsigned insize; /* valid bytes
static unsigned inptr; /* index of next byte to be processed in inbuf */
static unsigned outcnt; /* bytes in output buffer */

-/* gzip flag byte */
-#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
-#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
-#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
-#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
-#define COMMENT 0x10 /* bit 4 set: file comment present */
-#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
-#define RESERVED 0xC0 /* bit 6,7: reserved */
-
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())

-/* Diagnostic functions */
-#ifdef DEBUG
-# define Assert(cond,msg) {if(!(cond)) error(msg);}
-# define Trace(x) fprintf x
-# define Tracev(x) {if (verbose) fprintf x ;}
-# define Tracevv(x) {if (verbose>1) fprintf x ;}
-# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
-# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
-#else
-# define Assert(cond,msg)
-# define Trace(x)
-# define Tracev(x)
-# define Tracevv(x)
-# define Tracec(c,x)
-# define Tracecv(c,x)
-#endif
-
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
Index: 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-28 20:39:32.000000000 -0700
+++ 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-28 21:05:01.000000000 -0700
@@ -29,16 +29,6 @@
* gzip declarations
*/

-#define OF(args) args
-#define STATIC static
-
-void* memset(void* s, int c, size_t n);
-void* memcpy(void* __dest, __const void* __src,
- size_t __n);
-
-#define memzero(s, n) memset ((s), 0, (n))
-
-
typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;
@@ -56,33 +46,7 @@ unsigned inptr = 0; /* index of next byt

static unsigned outcnt = 0; /* bytes in output buffer */

-/* gzip flag byte */
-#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
-#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
-#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
-#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
-#define COMMENT 0x10 /* bit 4 set: file comment present */
-#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
-#define RESERVED 0xC0 /* bit 6,7: reserved */
-
-#define get_byte() inbuf[inptr++]
-
-/* Diagnostic functions */
-#ifdef DEBUG
-# define Assert(cond,msg) {if(!(cond)) error(msg);}
-# define Trace(x) fprintf x
-# define Tracev(x) {if (verbose) fprintf x ;}
-# define Tracevv(x) {if (verbose>1) fprintf x ;}
-# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
-# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
-#else
-# define Assert(cond,msg)
-# define Trace(x)
-# define Tracev(x)
-# define Tracevv(x)
-# define Tracec(c,x)
-# define Tracecv(c,x)
-#endif
+#define get_byte() inbuf[inptr++]

static int fill_inbuf(void);
static void flush_window(void);
@@ -166,25 +130,6 @@ puts(const char *s)
#endif
}

-void*
-memset(void* s, int c, size_t n)
-{
- int i;
- char *ss = (char*)s;
-
- for (i=0;i<n;i++) ss[i] = c;
-}
-
-void*
-memcpy(void* __dest, __const void* __src,
- size_t __n)
-{
- int i;
- char *d = (char *)__dest, *s = (char *)__src;
-
- for (i=0;i<__n;i++) d[i] = s[i];
-}
-
/* ===========================================================================
* Write the output window window[0..outcnt-1] and update crc and bytes_out.
* (Used for the decompressed data only.)
Index: 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-28 20:39:32.000000000 -0700
+++ 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-28 21:05:01.000000000 -0700
@@ -31,16 +31,6 @@
* gzip declarations
*/

-#define OF(args) args
-#define STATIC static
-
-void* memset(void* s, int c, size_t n);
-void* memcpy(void* __dest, __const void* __src,
- size_t __n);
-
-#define memzero(s, n) memset ((s), 0, (n))
-
-
typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;
@@ -58,34 +48,8 @@ unsigned inptr = 0; /* index of next byt

static unsigned outcnt = 0; /* bytes in output buffer */

-/* gzip flag byte */
-#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
-#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
-#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
-#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
-#define COMMENT 0x10 /* bit 4 set: file comment present */
-#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
-#define RESERVED 0xC0 /* bit 6,7: reserved */
-
#define get_byte() inbuf[inptr++]

-/* Diagnostic functions */
-#ifdef DEBUG
-# define Assert(cond,msg) {if(!(cond)) error(msg);}
-# define Trace(x) fprintf x
-# define Tracev(x) {if (verbose) fprintf x ;}
-# define Tracevv(x) {if (verbose>1) fprintf x ;}
-# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
-# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
-#else
-# define Assert(cond,msg)
-# define Trace(x)
-# define Tracev(x)
-# define Tracevv(x)
-# define Tracec(c,x)
-# define Tracecv(c,x)
-#endif
-
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
@@ -180,25 +144,6 @@ puts(const char *s)
#endif
}

-void*
-memset(void* s, int c, size_t n)
-{
- int i;
- char *ss = (char*)s;
-
- for (i=0;i<n;i++) ss[i] = c;
-}
-
-void*
-memcpy(void* __dest, __const void* __src,
- size_t __n)
-{
- int i;
- char *d = (char *)__dest, *s = (char *)__src;
-
- for (i=0;i<__n;i++) d[i] = s[i];
-}
-
/* ===========================================================================
* Write the output window window[0..outcnt-1] and update crc and bytes_out.
* (Used for the decompressed data only.)
Index: 2.6.14/arch/i386/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/i386/boot/compressed/misc.c 2005-10-28 20:39:32.000000000 -0700
+++ 2.6.14/arch/i386/boot/compressed/misc.c 2005-10-28 21:05:01.000000000 -0700
@@ -19,21 +19,11 @@
* gzip declarations
*/

-#define OF(args) args
-#define STATIC static
-
-#undef memset
-#undef memcpy
-
/*
* Why do we do this? Don't ask me..
*
* Incomprehensible are the ways of bootloaders.
*/
-static void* memset(void *, int, size_t);
-static void* memcpy(void *, __const void *, size_t);
-#define memzero(s, n) memset ((s), 0, (n))
-
typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;
@@ -48,33 +38,7 @@ static unsigned insize = 0; /* valid by
static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
static unsigned outcnt = 0; /* bytes in output buffer */

-/* gzip flag byte */
-#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
-#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
-#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
-#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
-#define COMMENT 0x10 /* bit 4 set: file comment present */
-#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
-#define RESERVED 0xC0 /* bit 6,7: reserved */
-
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
-
-/* Diagnostic functions */
-#ifdef DEBUG
-# define Assert(cond,msg) {if(!(cond)) error(msg);}
-# define Trace(x) fprintf x
-# define Tracev(x) {if (verbose) fprintf x ;}
-# define Tracevv(x) {if (verbose>1) fprintf x ;}
-# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
-# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
-#else
-# define Assert(cond,msg)
-# define Trace(x)
-# define Tracev(x)
-# define Tracevv(x)
-# define Tracec(c,x)
-# define Tracecv(c,x)
-#endif

static int fill_inbuf(void);
static void flush_window(void);
@@ -163,7 +127,9 @@ static void scroll(void)
{
int i;

- memcpy ( vidmem, vidmem + cols * 2, ( lines - 1 ) * cols * 2 );
+ for (i = 0; i < (lines - 1) * cols * 2; i++)
+ vidmem[i] = vidmem[i + cols * 2];
+
for ( i = ( lines - 1 ) * cols * 2; i < lines * cols * 2; i += 2 )
vidmem[i] = ' ';
}
@@ -205,25 +171,6 @@ static void putstr(const char *s)
outb_p(0xff & (pos >> 1), vidport+1);
}

-static void* memset(void* s, int c, size_t n)
-{
- int i;
- char *ss = (char*)s;
-
- for (i=0;i<n;i++) ss[i] = c;
- return s;
-}
-
-static void* memcpy(void* __dest, __const void* __src,
- size_t __n)
-{
- int i;
- char *d = (char *)__dest, *s = (char *)__src;
-
- for (i=0;i<__n;i++) d[i] = s[i];
- return __dest;
-}
-
/* ===========================================================================
* Fill the input buffer. This is called only when the buffer is empty
* and at least one byte is really needed.
Index: 2.6.14/arch/m32r/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/m32r/boot/compressed/misc.c 2005-10-28 20:39:32.000000000 -0700
+++ 2.6.14/arch/m32r/boot/compressed/misc.c 2005-10-28 21:05:01.000000000 -0700
@@ -19,13 +19,6 @@
* gzip declarations
*/

-#define OF(args) args
-#define STATIC static
-
-#undef memset
-#undef memcpy
-#define memzero(s, n) memset ((s), 0, (n))
-
typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;
@@ -40,34 +33,8 @@ static unsigned insize = 0; /* valid by
static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
static unsigned outcnt = 0; /* bytes in output buffer */

-/* gzip flag byte */
-#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
-#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
-#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
-#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
-#define COMMENT 0x10 /* bit 4 set: file comment present */
-#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
-#define RESERVED 0xC0 /* bit 6,7: reserved */
-
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())

-/* Diagnostic functions */
-#ifdef DEBUG
-# define Assert(cond,msg) {if(!(cond)) error(msg);}
-# define Trace(x) fprintf x
-# define Tracev(x) {if (verbose) fprintf x ;}
-# define Tracevv(x) {if (verbose>1) fprintf x ;}
-# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
-# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
-#else
-# define Assert(cond,msg)
-# define Trace(x)
-# define Tracev(x)
-# define Tracevv(x)
-# define Tracec(c,x)
-# define Tracecv(c,x)
-#endif
-
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
@@ -125,25 +92,6 @@ static void gzip_release(void **ptr)
free_mem_ptr = (long) *ptr;
}

-void* memset(void* s, int c, size_t n)
-{
- int i;
- char *ss = (char*)s;
-
- for (i=0;i<n;i++) ss[i] = c;
- return s;
-}
-
-void* memcpy(void* __dest, __const void* __src,
- size_t __n)
-{
- int i;
- char *d = (char *)__dest, *s = (char *)__src;
-
- for (i=0;i<__n;i++) d[i] = s[i];
- return __dest;
-}
-
/* ===========================================================================
* Fill the input buffer. This is called only when the buffer is empty
* and at least one byte is really needed.
Index: 2.6.14/arch/sh/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh/boot/compressed/misc.c 2005-10-28 20:39:32.000000000 -0700
+++ 2.6.14/arch/sh/boot/compressed/misc.c 2005-10-28 21:05:01.000000000 -0700
@@ -21,13 +21,6 @@
* gzip declarations
*/

-#define OF(args) args
-#define STATIC static
-
-#undef memset
-#undef memcpy
-#define memzero(s, n) memset ((s), 0, (n))
-
typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;
@@ -42,34 +35,8 @@ static unsigned insize = 0; /* valid by
static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
static unsigned outcnt = 0; /* bytes in output buffer */

-/* gzip flag byte */
-#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
-#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
-#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
-#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
-#define COMMENT 0x10 /* bit 4 set: file comment present */
-#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
-#define RESERVED 0xC0 /* bit 6,7: reserved */
-
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())

-/* Diagnostic functions */
-#ifdef DEBUG
-# define Assert(cond,msg) {if(!(cond)) error(msg);}
-# define Trace(x) fprintf x
-# define Tracev(x) {if (verbose) fprintf x ;}
-# define Tracevv(x) {if (verbose>1) fprintf x ;}
-# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
-# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
-#else
-# define Assert(cond,msg)
-# define Trace(x)
-# define Tracev(x)
-# define Tracevv(x)
-# define Tracec(c,x)
-# define Tracecv(c,x)
-#endif
-
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
@@ -156,25 +123,6 @@ int puts(const char *s)
}
#endif

-void* memset(void* s, int c, size_t n)
-{
- int i;
- char *ss = (char*)s;
-
- for (i=0;i<n;i++) ss[i] = c;
- return s;
-}
-
-void* memcpy(void* __dest, __const void* __src,
- size_t __n)
-{
- int i;
- char *d = (char *)__dest, *s = (char *)__src;
-
- for (i=0;i<__n;i++) d[i] = s[i];
- return __dest;
-}
-
/* ===========================================================================
* Fill the input buffer. This is called only when the buffer is empty
* and at least one byte is really needed.
Index: 2.6.14/arch/sh64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh64/boot/compressed/misc.c 2005-10-28 20:39:32.000000000 -0700
+++ 2.6.14/arch/sh64/boot/compressed/misc.c 2005-10-28 21:05:01.000000000 -0700
@@ -21,13 +21,6 @@ int cache_control(unsigned int command);
* gzip declarations
*/

-#define OF(args) args
-#define STATIC static
-
-#undef memset
-#undef memcpy
-#define memzero(s, n) memset ((s), 0, (n))
-
typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;
@@ -42,34 +35,8 @@ static unsigned insize = 0; /* valid byt
static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
static unsigned outcnt = 0; /* bytes in output buffer */

-/* gzip flag byte */
-#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
-#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
-#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
-#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
-#define COMMENT 0x10 /* bit 4 set: file comment present */
-#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
-#define RESERVED 0xC0 /* bit 6,7: reserved */
-
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())

-/* Diagnostic functions */
-#ifdef DEBUG
-# define Assert(cond,msg) {if(!(cond)) error(msg);}
-# define Trace(x) fprintf x
-# define Tracev(x) {if (verbose) fprintf x ;}
-# define Tracevv(x) {if (verbose>1) fprintf x ;}
-# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
-# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
-#else
-# define Assert(cond,msg)
-# define Trace(x)
-# define Tracev(x)
-# define Tracevv(x)
-# define Tracec(c,x)
-# define Tracecv(c,x)
-#endif
-
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
@@ -138,26 +105,6 @@ void puts(const char *s)
{
}

-void *memset(void *s, int c, size_t n)
-{
- int i;
- char *ss = (char *) s;
-
- for (i = 0; i < n; i++)
- ss[i] = c;
- return s;
-}
-
-void *memcpy(void *__dest, __const void *__src, size_t __n)
-{
- int i;
- char *d = (char *) __dest, *s = (char *) __src;
-
- for (i = 0; i < __n; i++)
- d[i] = s[i];
- return __dest;
-}
-
/* ===========================================================================
* Fill the input buffer. This is called only when the buffer is empty
* and at least one byte is really needed.
Index: 2.6.14/arch/x86_64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/x86_64/boot/compressed/misc.c 2005-10-28 20:39:32.000000000 -0700
+++ 2.6.14/arch/x86_64/boot/compressed/misc.c 2005-10-28 21:05:01.000000000 -0700
@@ -17,13 +17,6 @@
* gzip declarations
*/

-#define OF(args) args
-#define STATIC static
-
-#undef memset
-#undef memcpy
-#define memzero(s, n) memset ((s), 0, (n))
-
typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;
@@ -38,33 +31,7 @@ static unsigned insize = 0; /* valid by
static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
static unsigned outcnt = 0; /* bytes in output buffer */

-/* gzip flag byte */
-#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
-#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
-#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
-#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
-#define COMMENT 0x10 /* bit 4 set: file comment present */
-#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
-#define RESERVED 0xC0 /* bit 6,7: reserved */
-
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
-
-/* Diagnostic functions */
-#ifdef DEBUG
-# define Assert(cond,msg) {if(!(cond)) error(msg);}
-# define Trace(x) fprintf x
-# define Tracev(x) {if (verbose) fprintf x ;}
-# define Tracevv(x) {if (verbose>1) fprintf x ;}
-# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
-# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
-#else
-# define Assert(cond,msg)
-# define Trace(x)
-# define Tracev(x)
-# define Tracevv(x)
-# define Tracec(c,x)
-# define Tracecv(c,x)
-#endif

static int fill_inbuf(void);
static void flush_window(void);
@@ -92,9 +59,6 @@ static unsigned long output_ptr = 0;

static void *malloc(int size);
static void free(void *where);
-
-void* memset(void* s, int c, unsigned n);
-void* memcpy(void* dest, const void* src, unsigned n);

static void putstr(const char *);

@@ -152,7 +116,9 @@ static void scroll(void)
{
int i;

- memcpy ( vidmem, vidmem + cols * 2, ( lines - 1 ) * cols * 2 );
+ for (i = 0; i < (lines - 1) * cols * 2; i++)
+ vidmem[i] = vidmem[i + cols * 2];
+
for ( i = ( lines - 1 ) * cols * 2; i < lines * cols * 2; i += 2 )
vidmem[i] = ' ';
}
@@ -194,24 +160,6 @@ static void putstr(const char *s)
outb_p(0xff & (pos >> 1), vidport+1);
}

-void* memset(void* s, int c, unsigned n)
-{
- int i;
- char *ss = (char*)s;
-
- for (i=0;i<n;i++) ss[i] = c;
- return s;
-}
-
-void* memcpy(void* dest, const void* src, unsigned n)
-{
- int i;
- char *d = (char *)dest, *s = (char *)src;
-
- for (i=0;i<n;i++) d[i] = s[i];
- return dest;
-}
-
/* ===========================================================================
* Fill the input buffer. This is called only when the buffer is empty
* and at least one byte is really needed.
Index: 2.6.14/init/do_mounts_rd.c
===================================================================
--- 2.6.14.orig/init/do_mounts_rd.c 2005-10-28 20:39:32.000000000 -0700
+++ 2.6.14/init/do_mounts_rd.c 2005-10-28 21:05:01.000000000 -0700
@@ -273,12 +273,6 @@ int __init rd_load_disk(int n)
* gzip declarations
*/

-#define OF(args) args
-
-#ifndef memzero
-#define memzero(s, n) memset ((s), 0, (n))
-#endif
-
typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;
@@ -299,16 +293,7 @@ static long bytes_out;
static int crd_infd, crd_outfd;

#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
-
-/* Diagnostic functions (stubbed out) */
-#define Assert(cond,msg)
-#define Trace(x)
-#define Tracev(x)
-#define Tracevv(x)
-#define Tracec(c,x)
-#define Tracecv(c,x)

-#define STATIC static
#define INIT __init

static int __init fill_inbuf(void);
Index: 2.6.14/init/initramfs.c
===================================================================
--- 2.6.14.orig/init/initramfs.c 2005-10-28 20:39:32.000000000 -0700
+++ 2.6.14/init/initramfs.c 2005-10-28 21:05:01.000000000 -0700
@@ -343,12 +343,6 @@ static void __init flush_buffer(char *bu
* gzip declarations
*/

-#define OF(args) args
-
-#ifndef memzero
-#define memzero(s, n) memset ((s), 0, (n))
-#endif
-
typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;
@@ -365,16 +359,7 @@ static unsigned outcnt; /* bytes in out
static long bytes_out;

#define get_byte() (inptr < insize ? inbuf[inptr++] : -1)
-
-/* Diagnostic functions (stubbed out) */
-#define Assert(cond,msg)
-#define Trace(x)
-#define Tracev(x)
-#define Tracevv(x)
-#define Tracec(c,x)
-#define Tracecv(c,x)

-#define STATIC static
#define INIT __init

static void __init flush_window(void);

2005-10-31 21:00:35

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 17/20] inflate: mark some arrays as initdata

inflate: mark some arrays as INITDATA and define it in in-core callers

Signed-off-by: Matt Mackall <[email protected]>

Index: tiny/init/do_mounts_rd.c
===================================================================
--- tiny.orig/init/do_mounts_rd.c 2005-09-30 23:45:21.000000000 -0700
+++ tiny/init/do_mounts_rd.c 2005-09-30 23:45:37.000000000 -0700
@@ -271,6 +271,7 @@ int __init rd_load_disk(int n)

/* gzip declarations */
#define INIT __init
+#define INITDATA __initdata
#define NO_INFLATE_MALLOC

#include "../lib/inflate.c"
Index: tiny/lib/inflate.c
===================================================================
--- tiny.orig/lib/inflate.c 2005-09-30 23:45:33.000000000 -0700
+++ tiny/lib/inflate.c 2005-09-30 23:48:16.000000000 -0700
@@ -104,6 +104,9 @@
#ifndef INIT
#define INIT
#endif
+#ifndef INITDATA
+#define INITDATA
+#endif

#include <asm/types.h>

@@ -144,7 +147,7 @@ static void free(void *where)
malloc_ptr = free_mem_ptr;
}

-static u8 window[0x8000]; /* use a statically allocated window */
+static u8 INITDATA window[0x8000]; /* use a statically allocated window */
#else
static u8 *window; /* dynamically allocate */
#define malloc(a) kmalloc(a, GFP_KERNEL)
@@ -236,12 +239,12 @@ static void copy_bytes(struct iostate *i
/* Tables for deflate from PKZIP's appnote.txt. */

/* Order of the bit length code lengths */
-static const unsigned border[] = {
+static INITDATA unsigned border[] = {
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
};

/* Copy lengths for literal codes 257..285 */
-static const u16 cplens[] = {
+static INITDATA u16 cplens[] = {
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
};
@@ -250,20 +253,20 @@ static const u16 cplens[] = {
* note: see note #13 above about the 258 in this list.
* 99==invalid
*/
-static const u16 cplext[] = {
+static INITDATA u16 cplext[] = {
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99
};

/* Copy offsets for distance codes 0..29 */
-static const u16 cpdist[] = {
+static INITDATA u16 cpdist[] = {
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
8193, 12289, 16385, 24577
};

/* Extra bits for distance codes */
-static const u16 cpdext[] = {
+static INITDATA u16 cpdext[] = {
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
12, 12, 13, 13
Index: tiny/init/initramfs.c
===================================================================
--- tiny.orig/init/initramfs.c 2005-09-30 23:44:47.000000000 -0700
+++ tiny/init/initramfs.c 2005-09-30 23:46:20.000000000 -0700
@@ -332,6 +332,7 @@ static void __init flush_buffer(u8 *buf,
/* gzip declarations */

#define INIT __init
+#define INITDATA __initdata
#define NO_INFLATE_MALLOC

#include "../lib/inflate.c"

2005-10-31 21:01:52

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 14/20] inflate: (arch) use an error callback rather than a global

inflate: error handling cleanup

This passes the error function as a callback rather than using a
global symbol.

Signed-off-by: Matt Mackall <[email protected]>

Index: 2.6.14/arch/alpha/boot/misc.c
===================================================================
--- 2.6.14.orig/arch/alpha/boot/misc.c 2005-10-28 22:04:21.000000000 -0700
+++ 2.6.14/arch/alpha/boot/misc.c 2005-10-28 22:04:23.000000000 -0700
@@ -28,8 +28,6 @@ extern long srm_printk(const char *, ...
* gzip delarations
*/

-static void error(char *m);
-
static char *input_data;
static int input_data_size;

@@ -50,7 +48,7 @@ static void flush_window(const u8 *buf,
*output_data++ = *buf++;
}

-static void error(char *x)
+static void error(const char *x)
{
puts("\n\n");
puts(x);
@@ -76,7 +74,7 @@ decompress_kernel(void *output_start,
/* FIXME FIXME FIXME */

/* puts("Uncompressing Linux..."); */
- count = gunzip(input_data, input_data_size, NULL, flush_window);
+ count = gunzip(input_data, input_data_size, NULL, flush_window, error);
/* puts(" done, booting the kernel.\n"); */
return count;
}
Index: 2.6.14/arch/arm/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm/boot/compressed/misc.c 2005-10-28 22:04:21.000000000 -0700
+++ 2.6.14/arch/arm/boot/compressed/misc.c 2005-10-28 22:04:23.000000000 -0700
@@ -46,8 +46,6 @@ icedcc_putstr(const char *ptr)
* gzip declarations
*/

-static void error(char *m);
-
extern char input_data[];
extern char input_data_end[];

@@ -75,7 +73,7 @@ static void flush_window(const u8 *buf,
putstr(".");
}

-static void error(char *x)
+static void error(const char *x)
{
putstr("\n\n");
putstr(x);
@@ -98,7 +96,8 @@ decompress_kernel(u32 output_start, u32
arch_decomp_setup();

putstr("Uncompressing Linux...");
- gunzip(input_data, input_data_end - input_data, NULL, flush_window);
+ gunzip(input_data, input_data_end - input_data, NULL, flush_window,
+ error);
putstr(" done, booting the kernel.\n");
return output_ptr;
}
@@ -111,7 +110,8 @@ int main()
output_data = output_buffer;

putstr("Uncompressing Linux...");
- gunzip(input_data, input_data_end - input_data, NULL, flush_window);
+ gunzip(input_data, input_data_end - input_data, NULL, flush_window,
+ error);
putstr("done.\n");
return 0;
}
Index: 2.6.14/arch/arm26/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm26/boot/compressed/misc.c 2005-10-28 22:04:21.000000000 -0700
+++ 2.6.14/arch/arm26/boot/compressed/misc.c 2005-10-28 22:04:23.000000000 -0700
@@ -31,8 +31,6 @@ unsigned int __machine_arch_type;
* gzip delarations
*/

-static void error(char *m);
-
extern char input_data[];
extern char input_data_end[];
static u8 *output_data;
@@ -59,7 +57,7 @@ static void flush_window(const u8 *buf,
puts(".");
}

-static void error(char *x)
+static void error(const char *x)
{
int ptr;

@@ -84,7 +82,8 @@ decompress_kernel(u32 output_start, u32
arch_decomp_setup();

puts("Uncompressing Linux...");
- gunzip(input_data, input_data_end - input_data, NULL, flush_window);
+ gunzip(input_data, input_data_end - input_data, NULL, flush_window,
+ error);
puts(" done, booting the kernel.\n");
return output_ptr;
}
@@ -97,7 +96,8 @@ int main()
output_data = output_buffer;

puts("Uncompressing Linux...");
- gunzip(input_data, input_data_end - input_data, NULL, flush_window);
+ gunzip(input_data, input_data_end - input_data, NULL, flush_window,
+ error);
puts("done.\n");
return 0;
}
Index: 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-28 22:04:21.000000000 -0700
+++ 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-28 22:04:23.000000000 -0700
@@ -30,8 +30,6 @@

unsigned compsize; /* compressed size, used by head.S */

-static void error(char *m);
-
extern char *input_data; /* lives in head.S */
static u8 *output_data;

@@ -79,8 +77,7 @@ static void flush_window(const u8 *buf,
*output_data++ = *buf++;
}

-static void
-error(char *x)
+static void error(const char *x)
{
puts("\n\n");
puts(x);
@@ -136,6 +133,6 @@ decompress_kernel()
}

puts("Uncompressing Linux...\n");
- compsize = gunzip(input_data, 0x7fffffff, NULL, flush_window);
+ compsize = gunzip(input_data, 0x7fffffff, NULL, flush_window, error);
puts("Done. Now booting the kernel.\n");
}
Index: 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-28 22:04:21.000000000 -0700
+++ 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-28 22:04:23.000000000 -0700
@@ -30,8 +30,6 @@
* gzip declarations
*/

-static void error(char *m);
-
extern char *input_data; /* lives in head.S */
static u8 *output_data;

@@ -91,8 +89,7 @@ static void flush_window(const u8 *buf,
*output_data++ = *buf++;
}

-static void
-error(char *x)
+static void error(const char *x)
{
puts("\n\n");
puts(x);
@@ -179,6 +176,6 @@ decompress_kernel()
}

puts("Uncompressing Linux...\n");
- gunzip(input_data, 0x7fffffff, NULL, flush_window);
+ gunzip(input_data, 0x7fffffff, NULL, flush_window, error);
puts("Done. Now booting the kernel.\n");
}
Index: 2.6.14/arch/i386/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/i386/boot/compressed/misc.c 2005-10-28 22:04:21.000000000 -0700
+++ 2.6.14/arch/i386/boot/compressed/misc.c 2005-10-28 22:04:23.000000000 -0700
@@ -24,8 +24,6 @@
* Incomprehensible are the ways of bootloaders.
*/

-static void error(char *m);
-
/*
* This is set up by the setup-routine at boot-time
*/
@@ -125,7 +123,7 @@ static void flush_window(const u8 *buf,
}
}

-static void error(char *x)
+static void error(const char *x)
{
putstr("\n\n");
putstr(x);
@@ -214,7 +212,7 @@ asmlinkage int decompress_kernel(struct
else setup_output_buffer_if_we_run_high(mv);

putstr("Uncompressing Linux... ");
- gunzip(input_data, input_len, NULL, flush_window);
+ gunzip(input_data, input_len, NULL, flush_window, error);
putstr("Ok, booting the kernel.\n");
if (high_loaded) close_output_buffer_if_we_run_high(mv);
return high_loaded;
Index: 2.6.14/arch/m32r/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/m32r/boot/compressed/misc.c 2005-10-28 22:04:21.000000000 -0700
+++ 2.6.14/arch/m32r/boot/compressed/misc.c 2005-10-28 22:04:23.000000000 -0700
@@ -17,8 +17,6 @@
* gzip declarations
*/

-static void error(char *m);
-
static unsigned char *input_data;
static int input_len;
static u8 *output_data;
@@ -39,7 +37,7 @@ static void flush_window(const u8 *buf,
*output_data++ = *buf++;
}

-static void error(char *x)
+static void error(const char *x)
{
puts("\n\n");
puts(x);
@@ -61,6 +59,6 @@ decompress_kernel(int mmu_on, unsigned c
input_len = zimage_len;

puts("Uncompressing Linux... ");
- gunzip(input_data, input_len, NULL, flush_window);
+ gunzip(input_data, input_len, NULL, flush_window, error);
puts("Ok, booting the kernel.\n");
}
Index: 2.6.14/arch/sh/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh/boot/compressed/misc.c 2005-10-28 22:04:21.000000000 -0700
+++ 2.6.14/arch/sh/boot/compressed/misc.c 2005-10-28 22:04:23.000000000 -0700
@@ -19,8 +19,6 @@
* gzip declarations
*/

-static void error(char *m);
-
extern char input_data[];
extern int input_len;
static u8 *output_data;
@@ -67,7 +65,7 @@ static void flush_window(const u8 *buf,
*output_data++ = *buf++;
}

-static void error(char *x)
+static void error(const char *x)
{
puts("\n\n");
puts(x);
@@ -88,6 +86,6 @@ void decompress_kernel(void)
free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;

puts("Uncompressing Linux... ");
- gunzip(input_data, input_len, NULL, flush_window);
+ gunzip(input_data, input_len, NULL, flush_window, error);
puts("Ok, booting the kernel.\n");
}
Index: 2.6.14/arch/sh64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh64/boot/compressed/misc.c 2005-10-28 22:04:21.000000000 -0700
+++ 2.6.14/arch/sh64/boot/compressed/misc.c 2005-10-28 22:04:23.000000000 -0700
@@ -19,8 +19,6 @@ int cache_control(unsigned int command);
* gzip declarations
*/

-static void error(char *m);
-
extern char input_data[];
extern int input_len;
static u8 *output_data;
@@ -49,7 +47,7 @@ static void flush_window(const u8 *buf,
puts(".");
}

-static void error(char *x)
+static void error(const char *x)
{
puts("\n\n");
puts(x);
@@ -70,7 +68,7 @@ void decompress_kernel(void)

puts("Uncompressing Linux... ");
cache_control(CACHE_ENABLE);
- gunzip(input_data, input_len, NULL, flush_window);
+ gunzip(input_data, input_len, NULL, flush_window, error);
puts("\n");

#if 0
Index: 2.6.14/arch/x86_64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/x86_64/boot/compressed/misc.c 2005-10-28 22:04:21.000000000 -0700
+++ 2.6.14/arch/x86_64/boot/compressed/misc.c 2005-10-28 22:04:23.000000000 -0700
@@ -16,8 +16,6 @@
* gzip declarations
*/

-static void error(char *m);
-
/*
* This is set up by the setup-routine at boot-time
*/
@@ -114,7 +112,7 @@ static void flush_window(const u8 *buf,
}
}

-static void error(char *x)
+static void error(const char *x)
{
putstr("\n\n");
putstr(x);
@@ -192,7 +190,7 @@ int decompress_kernel(struct moveparams
else setup_output_buffer_if_we_run_high(mv);

putstr(".\nDecompressing Linux...");
- gunzip(input_data, input_len, NULL, flush_window);
+ gunzip(input_data, input_len, NULL, flush_window, error);
putstr("done.\nBooting the kernel.\n");
if (high_loaded) close_output_buffer_if_we_run_high(mv);
return high_loaded;
Index: 2.6.14/init/do_mounts_rd.c
===================================================================
--- 2.6.14.orig/init/do_mounts_rd.c 2005-10-28 22:04:21.000000000 -0700
+++ 2.6.14/init/do_mounts_rd.c 2005-10-28 22:04:23.000000000 -0700
@@ -281,12 +281,17 @@ static int crd_infd, crd_outfd;

#define INIT __init

-static void __init error(char *m);
-
#define NO_INFLATE_MALLOC

#include "../lib/inflate.c"

+static void __init error(const char *x)
+{
+ printk(KERN_ERR "%s\n", x);
+ exit_code = 1;
+ unzip_error = 1;
+}
+
/*
* Fill the input buffer. This is called only when the buffer is empty
* and at least one byte is really needed.
@@ -310,13 +315,6 @@ static void __init flush_buffer(const u8
}
}

-static void __init error(char *x)
-{
- printk(KERN_ERR "%s\n", x);
- exit_code = 1;
- unzip_error = 1;
-}
-
static int __init crd_load(int in_fd, int out_fd)
{
int result;
@@ -330,7 +328,7 @@ static int __init crd_load(int in_fd, in
printk(KERN_ERR "RAMDISK: Couldn't allocate gzip buffer\n");
return -1;
}
- result = gunzip(inbuf, INBUFSIZ, fill_inbuf, flush_buffer);
+ result = gunzip(inbuf, INBUFSIZ, fill_inbuf, flush_buffer, error);
if (unzip_error)
result = 1;
kfree(inbuf);
Index: 2.6.14/init/initramfs.c
===================================================================
--- 2.6.14.orig/init/initramfs.c 2005-10-28 22:04:21.000000000 -0700
+++ 2.6.14/init/initramfs.c 2005-10-28 22:04:23.000000000 -0700
@@ -7,8 +7,8 @@
#include <linux/string.h>
#include <linux/syscalls.h>

-static __initdata char *message;
-static void __init error(char *x)
+static __initdata const char *message;
+static void __init error(const char *x)
{
if (!message)
message = x;
@@ -335,13 +335,12 @@ static void __init flush_buffer(const u8

#define INIT __init

-static void __init error(char *m);
-
#define NO_INFLATE_MALLOC

#include "../lib/inflate.c"

-static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only)
+static const char * __init unpack_to_rootfs(char *buf, unsigned len,
+ int check_only)
{
int written, cnt;
dry_run = check_only;
@@ -369,7 +368,7 @@ static char * __init unpack_to_rootfs(ch
continue;
}
this_header = 0;
- cnt = gunzip(buf, len, NULL, flush_buffer);
+ cnt = gunzip(buf, len, NULL, flush_buffer, error);
if (state != Reset)
error("junk in gzipped archive");
this_header = saved_offset + cnt;
@@ -397,8 +396,9 @@ static void __init free_initrd(void)

void __init populate_rootfs(void)
{
- char *err = unpack_to_rootfs(__initramfs_start,
- __initramfs_end - __initramfs_start, 0);
+ const char *err =
+ unpack_to_rootfs(__initramfs_start,
+ __initramfs_end - __initramfs_start, 0);
if (err)
panic(err);
#ifdef CONFIG_BLK_DEV_INITRD
Index: 2.6.14/lib/inflate.c
===================================================================
--- 2.6.14.orig/lib/inflate.c 2005-10-28 22:04:19.000000000 -0700
+++ 2.6.14/lib/inflate.c 2005-10-28 22:04:23.000000000 -0700
@@ -121,8 +121,9 @@ static void *malloc(int size)
{
void *p;

- if (size <0)
- error("Malloc error");
+ if (size < 0)
+ return NULL;
+
if (!malloc_ptr)
malloc_ptr = free_mem_ptr;

@@ -132,7 +133,7 @@ static void *malloc(int size)
malloc_ptr += size;

if (malloc_ptr >= free_mem_end_ptr)
- error("Out of memory");
+ return NULL;

malloc_count++;
return p;
@@ -176,6 +177,7 @@ struct iostate {
int ipos, isize, itotal, opos, osize, ototal, bits;
void (*fill)(u8 *ibuf, int len);
void (*flush)(const u8 *obuf, int len);
+ void (*error)(const char *msg);
u32 buf, crc;
};

@@ -879,7 +881,7 @@ static int noinline INIT inflate_dynamic
if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl))) {
DEBG("dyn5b ");
if (i == 1) {
- error("incomplete literal tree");
+ io->error("incomplete literal tree");
huft_free(tl);
}
return i; /* incomplete code set */
@@ -889,7 +891,7 @@ static int noinline INIT inflate_dynamic
if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd))) {
DEBG("dyn5d ");
if (i == 1) {
- error("incomplete distance tree");
+ io->error("incomplete distance tree");
huft_free(td);
}
huft_free(tl);
@@ -992,9 +994,11 @@ static void INIT makecrc(void)
* @isize: size of pool
* @fill: function to fill the input pool
* @flush: function to flush the output pool
+ * @error: function to report an error
*/
static int INIT gunzip(u8 *ibuf, int isize, void (*fill)(u8 *buf, int size),
- void (*flush)(const u8 *buf, int size))
+ void (*flush)(const u8 *buf, int size),
+ void (*error)(const char *msg))
{
u8 flags;
unsigned char magic[2]; /* magic header */

2005-10-31 21:03:16

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 12/20] inflate: internalize (arch) most of the output window handling

inflate: internalize most of the output window handling

This moves the inflate window definition and handling into
lib/inflate.c and rather than calling a global flush_window function,
now calls a flush callback. The callback in most callers is also
greatly simplified.

Signed-off-by: Matt Mackall <[email protected]>

Index: 2.6.14/lib/inflate.c
===================================================================
--- 2.6.14.orig/lib/inflate.c 2005-10-28 21:10:35.000000000 -0700
+++ 2.6.14/lib/inflate.c 2005-10-28 21:13:20.000000000 -0700
@@ -144,7 +144,10 @@ static void free(void *where)
if (!malloc_count)
malloc_ptr = free_mem_ptr;
}
+
+static u8 window[0x8000]; /* use a statically allocated window */
#else
+static u8 *window; /* dynamically allocate */
#define malloc(a) kmalloc(a, GFP_KERNEL)
#define free(a) kfree(a)
#endif
@@ -170,8 +173,9 @@ struct huft {

struct iostate {
u8 *window, *ibuf;
- int ipos, isize, itotal, opos, osize, bits;
+ int ipos, isize, itotal, opos, osize, ototal, bits;
void (*fill)(u8 *ibuf, int len);
+ void (*flush)(const u8 *obuf, int len);
u32 buf, crc;
};

@@ -191,10 +195,6 @@ static int INIT inflate(struct iostate *
stream to find repeated byte strings. This is implemented here as a
circular buffer. The index is updated simply by incrementing and then
ANDing with 0x7fff (32K-1). */
-/* It is left to other modules to supply the 32 K area. It is assumed
- to be usable as if it were declared "u8 window[32768];" or as just
- "u8 *window;" and then malloc'ed in the latter case. The definition
- must be in unzip.h, included above. */

static void flush_output(struct iostate *io)
{
@@ -204,8 +204,8 @@ static void flush_output(struct iostate
io->crc = crc_32_tab[(io->window[i] ^ (int)io->crc) & 0xff]
^ (io->crc >> 8);

- outcnt = io->opos;
- flush_window();
+ io->flush(io->window, io->opos);
+ io->ototal += io->opos;
io->opos = 0;
}

@@ -991,8 +991,10 @@ static void INIT makecrc(void)
* @ibuf: input character pool
* @isize: size of pool
* @fill: function to fill the input pool
+ * @flush: function to flush the output pool
*/
-static int INIT gunzip(u8 *ibuf, int isize, void (*fill)(u8 *buf, int size))
+static int INIT gunzip(u8 *ibuf, int isize, void (*fill)(u8 *buf, int size),
+ void (*flush)(const u8 *buf, int size))
{
u8 flags;
unsigned char magic[2]; /* magic header */
@@ -1002,13 +1004,13 @@ static int INIT gunzip(u8 *ibuf, int isi
int res;
struct iostate io;

- io.window = window;
- io.osize = WSIZE;
- io.opos = io.bits = io.buf = io.ipos = io.itotal = 0;
+ io.osize = 0x8000; /* 32k for inflate */
+ io.opos = io.bits = io.buf = io.ipos = io.itotal = io.ototal = 0;
io.crc = 0xffffffffUL;
io.isize = isize;
io.ibuf = ibuf;
io.fill = fill;
+ io.flush = flush;

makecrc(); /* initialize the CRC table */

@@ -1066,7 +1068,16 @@ static int INIT gunzip(u8 *ibuf, int isi
;

/* Decompress */
- if ((res = inflate(&io))) {
+ io.window = window ? window : malloc(io.osize);
+ if (!io.window) {
+ error("couldn't allocate gunzip window\n");
+ return -1;
+ }
+ res = inflate(&io);
+ if (!window)
+ free(io.window);
+
+ if (res) {
switch (res) {
case 0:
break;
@@ -1106,7 +1117,7 @@ static int INIT gunzip(u8 *ibuf, int isi
error("crc error");
return -1;
}
- if (orig_len != bytes_out) {
+ if (orig_len != io.ototal) {
error("length error");
return -1;
}
Index: 2.6.14/arch/alpha/boot/misc.c
===================================================================
--- 2.6.14.orig/arch/alpha/boot/misc.c 2005-10-28 21:09:20.000000000 -0700
+++ 2.6.14/arch/alpha/boot/misc.c 2005-10-28 21:13:20.000000000 -0700
@@ -32,21 +32,12 @@ typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;

-#define WSIZE 0x8000 /* Window size must be at least 32k, */
- /* and a power of two */
-
-static uch *window; /* Sliding window buffer */
-static unsigned outcnt; /* bytes in output buffer */
-
-static void flush_window(void);
static void error(char *m);

static char *input_data;
static int input_data_size;

static uch *output_data;
-static ulg output_ptr;
-static ulg bytes_out;

extern int end;
static ulg free_mem_ptr;
@@ -56,24 +47,11 @@ static ulg free_mem_ptr_end;

#include "../../../lib/inflate.c"

-/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update bytes_out.
- * (Used for the decompressed data only.)
- */
-void flush_window(void)
+/* flush gunzip output window */
+static void flush_window(const u8 *buf, int len)
{
- unsigned n;
- uch *in, *out, ch;
-
- in = window;
- out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++)
- ch = *out++ = *in++;
-
- bytes_out += (ulg)outcnt;
- output_ptr += (ulg)outcnt;
- outcnt = 0;
-/* puts("."); */
+ while(len--)
+ *output_data++ = *buf++;
}

static void error(char *x)
@@ -91,6 +69,7 @@ decompress_kernel(void *output_start,
size_t ksize,
size_t kzsize)
{
+ int count;
output_data = (uch *)output_start;
input_data = (uch *)input_start;
input_data_size = kzsize; /* use compressed size */
@@ -100,11 +79,8 @@ decompress_kernel(void *output_start,
free_mem_ptr_end = (ulg)output_start + ksize + 0x200000;
/* FIXME FIXME FIXME */

- /* put in temp area to reduce initial footprint */
- window = malloc(WSIZE);
-
/* puts("Uncompressing Linux..."); */
- gunzip(input_data, input_data_size, NULL);
+ count = gunzip(input_data, input_data_size, NULL, flush_window);
/* puts(" done, booting the kernel.\n"); */
- return output_ptr;
+ return count;
}
Index: 2.6.14/arch/arm/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm/boot/compressed/misc.c 2005-10-28 21:09:20.000000000 -0700
+++ 2.6.14/arch/arm/boot/compressed/misc.c 2005-10-28 21:13:20.000000000 -0700
@@ -50,21 +50,12 @@ typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;

-#define WSIZE 0x8000 /* Window size must be at least 32k, */
- /* and a power of two */
-
-static uch window[WSIZE]; /* Sliding window buffer */
-static unsigned outcnt; /* bytes in output buffer */
-
-static void flush_window(void);
static void error(char *m);

extern char input_data[];
extern char input_data_end[];

static uch *output_data;
-static ulg output_ptr;
-static ulg bytes_out;

static void putstr(const char *);

@@ -80,23 +71,11 @@ static ulg free_mem_ptr_end;
#define NO_INFLATE_MALLOC
#endif

-/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update bytes_out.
- * (Used for the decompressed data only.)
- */
-void flush_window(void)
+/* flush gunzip output window */
+static void flush_window(const u8 *buf, int len)
{
- unsigned n;
- uch *in, *out, ch;
-
- in = window;
- out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++)
- ch = *out++ = *in++;
-
- bytes_out += (ulg)outcnt;
- output_ptr += (ulg)outcnt;
- outcnt = 0;
+ while(len--)
+ *output_data++ = *buf++;
putstr(".");
}

@@ -123,7 +102,7 @@ decompress_kernel(ulg output_start, ulg
arch_decomp_setup();

putstr("Uncompressing Linux...");
- gunzip(input_data, input_data_end - input_data, NULL);
+ gunzip(input_data, input_data_end - input_data, NULL, flush_window);
putstr(" done, booting the kernel.\n");
return output_ptr;
}
@@ -136,7 +115,7 @@ int main()
output_data = output_buffer;

putstr("Uncompressing Linux...");
- gunzip(input_data, input_data_end - input_data, NULL);
+ gunzip(input_data, input_data_end - input_data, NULL, flush_window);
putstr("done.\n");
return 0;
}
Index: 2.6.14/arch/arm26/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm26/boot/compressed/misc.c 2005-10-28 21:09:20.000000000 -0700
+++ 2.6.14/arch/arm26/boot/compressed/misc.c 2005-10-28 21:13:20.000000000 -0700
@@ -35,21 +35,11 @@ typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;

-#define WSIZE 0x8000 /* Window size must be at least 32k, */
- /* and a power of two */
-
-static uch window[WSIZE]; /* Sliding window buffer */
-static unsigned outcnt; /* bytes in output buffer */
-
-static void flush_window(void);
static void error(char *m);

extern char input_data[];
extern char input_data_end[];
-
static uch *output_data;
-static ulg output_ptr;
-static ulg bytes_out;

static void puts(const char *);

@@ -65,23 +55,11 @@ static ulg free_mem_ptr_end;
#define NO_INFLATE_MALLOC
#endif

-/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update bytes_out.
- * (Used for the decompressed data only.)
- */
-void flush_window(void)
+/* flush the gunzip output window */
+static void flush_window(const u8 *buf, int len)
{
- unsigned n;
- uch *in, *out, ch;
-
- in = window;
- out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++)
- ch = *out++ = *in++;
-
- bytes_out += (ulg)outcnt;
- output_ptr += (ulg)outcnt;
- outcnt = 0;
+ while (len--)
+ *output_data++ = *buf++;
puts(".");
}

@@ -110,7 +88,7 @@ decompress_kernel(ulg output_start, ulg
arch_decomp_setup();

puts("Uncompressing Linux...");
- gunzip(input_data, input_data_end - input_data, NULL);
+ gunzip(input_data, input_data_end - input_data, NULL, flush_window);
puts(" done, booting the kernel.\n");
return output_ptr;
}
@@ -123,7 +101,7 @@ int main()
output_data = output_buffer;

puts("Uncompressing Linux...");
- gunzip(input_data, input_data_end - input_data, NULL);
+ gunzip(input_data, input_data_end - input_data, NULL, flush_window);
puts("done.\n");
return 0;
}
Index: 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-28 21:09:20.000000000 -0700
+++ 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-28 21:13:20.000000000 -0700
@@ -32,21 +32,12 @@ typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;

-#define WSIZE 0x8000 /* Window size must be at least 32k, */
- /* and a power of two */
-
-static uch window[WSIZE]; /* Sliding window buffer */
unsigned compsize; /* compressed size, used by head.S */
-static unsigned outcnt = 0; /* bytes in output buffer */

-static void flush_window(void);
static void error(char *m);

extern char *input_data; /* lives in head.S */
-
-static long bytes_out = 0;
static uch *output_data;
-static unsigned long output_ptr = 0;

static void puts(const char *);

@@ -85,25 +76,11 @@ puts(const char *s)
#endif
}

-/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update bytes_out.
- * (Used for the decompressed data only.)
- */
-
-static void
-flush_window()
+/* flush the gunzip output window */
+static void flush_window(const u8 *buf, int len)
{
- unsigned n;
- uch *in, *out, ch;
-
- in = window;
- out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++)
- ch = *out++ = *in++;
-
- bytes_out += (ulg)outcnt;
- output_ptr += (ulg)outcnt;
- outcnt = 0;
+ while (len--)
+ *output_data++ = *buf++;
}

static void
@@ -163,6 +140,6 @@ decompress_kernel()
}

puts("Uncompressing Linux...\n");
- compsize = gunzip(input_data, 0x7fffffff, NULL);
+ compsize = gunzip(input_data, 0x7fffffff, NULL, flush_window);
puts("Done. Now booting the kernel.\n");
}
Index: 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-28 21:09:20.000000000 -0700
+++ 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-28 21:13:20.000000000 -0700
@@ -34,20 +34,10 @@ typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;

-#define WSIZE 0x8000 /* Window size must be at least 32k, */
- /* and a power of two */
-
-static uch window[WSIZE]; /* Sliding window buffer */
-static unsigned outcnt = 0; /* bytes in output buffer */
-
-static void flush_window(void);
static void error(char *m);

extern char *input_data; /* lives in head.S */
-
-static long bytes_out = 0;
static uch *output_data;
-static unsigned long output_ptr = 0;

static void puts(const char *);

@@ -98,25 +88,11 @@ puts(const char *s)
#endif
}

-/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update bytes_out.
- * (Used for the decompressed data only.)
- */
-
-static void
-flush_window()
+/* flush the gunzip output window */
+static void flush_window(const u8 *buf, int len)
{
- unsigned n;
- uch *in, *out, ch;
-
- in = window;
- out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++)
- ch = *out++ = *in++;
-
- bytes_out += (ulg)outcnt;
- output_ptr += (ulg)outcnt;
- outcnt = 0;
+ while (len--)
+ *output_data++ = *buf++;
}

static void
@@ -207,6 +183,6 @@ decompress_kernel()
}

puts("Uncompressing Linux...\n");
- gunzip(input_data, 0x7fffffff, NULL);
+ gunzip(input_data, 0x7fffffff, NULL, flush_window);
puts("Done. Now booting the kernel.\n");
}
Index: 2.6.14/arch/i386/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/i386/boot/compressed/misc.c 2005-10-28 21:09:20.000000000 -0700
+++ 2.6.14/arch/i386/boot/compressed/misc.c 2005-10-28 21:13:20.000000000 -0700
@@ -27,13 +27,6 @@ typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;

-#define WSIZE 0x8000 /* Window size must be at least 32k, */
- /* and a power of two */
-
-static uch window[WSIZE]; /* Sliding window buffer */
-static unsigned outcnt = 0; /* bytes in output buffer */
-
-static void flush_window(void);
static void error(char *m);

/*
@@ -49,10 +42,8 @@ static unsigned char *real_mode; /* Poin

extern char input_data[];
extern int input_len;
-
-static long bytes_out = 0;
+static long bytes_out;
static uch *output_data;
-static unsigned long output_ptr = 0;

static void putstr(const char *);

@@ -126,43 +117,15 @@ static void putstr(const char *s)
outb_p(0xff & (pos >> 1), vidport+1);
}

-/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update bytes_out.
- * (Used for the decompressed data only.)
- */
-static void flush_window_low(void)
-{
- unsigned n;
- uch *in, *out, ch;
-
- in = window;
- out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++)
- ch = *out++ = *in++;
-
- bytes_out += (ulg)outcnt;
- output_ptr += (ulg)outcnt;
- outcnt = 0;
-}
-
-static void flush_window_high(void)
+/* flush the gunzip output buffer */
+static void flush_window(const u8 *buf, int len)
{
- unsigned n;
- uch *in, ch;
- in = window;
- for (n = 0; n < outcnt; n++) {
- ch = *output_data++ = *in++;
- if ((ulg)output_data == low_buffer_end) output_data=high_buffer_start;
- }
-
- bytes_out += (ulg)outcnt;
- outcnt = 0;
-}
-
-static void flush_window(void)
-{
- if (high_loaded) flush_window_high();
- else flush_window_low();
+ bytes_out += len;
+ while (len--) {
+ *output_data++ = *buf++;
+ if (high_loaded && (u32)output_data == low_buffer_end)
+ output_data = high_buffer_start;
+ }
}

static void error(char *x)
@@ -254,7 +217,7 @@ asmlinkage int decompress_kernel(struct
else setup_output_buffer_if_we_run_high(mv);

putstr("Uncompressing Linux... ");
- gunzip(input_data, input_len, NULL);
+ gunzip(input_data, input_len, NULL, flush_window);
putstr("Ok, booting the kernel.\n");
if (high_loaded) close_output_buffer_if_we_run_high(mv);
return high_loaded;
Index: 2.6.14/arch/m32r/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/m32r/boot/compressed/misc.c 2005-10-28 21:09:20.000000000 -0700
+++ 2.6.14/arch/m32r/boot/compressed/misc.c 2005-10-28 21:13:20.000000000 -0700
@@ -21,21 +21,11 @@ typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;

-#define WSIZE 0x8000 /* Window size must be at least 32k, */
- /* and a power of two */
-
-static uch window[WSIZE]; /* Sliding window buffer */
-static unsigned outcnt = 0; /* bytes in output buffer */
-
-static void flush_window(void);
static void error(char *m);

static unsigned char *input_data;
static int input_len;
-
-static long bytes_out = 0;
static uch *output_data;
-static unsigned long output_ptr = 0;

#include "m32r_sio.c"

@@ -46,23 +36,11 @@ static unsigned long free_mem_end_ptr;

#include "../../../../lib/inflate.c"

-/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update bytes_out.
- * (Used for the decompressed data only.)
- */
-static void flush_window(void)
+/* flush the gunzip output buffer */
+static void flush_window(const u8 *buf, int len)
{
- unsigned n;
- uch *in, *out, ch;
-
- in = window;
- out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++)
- ch = *out++ = *in++;
-
- bytes_out += (ulg)outcnt;
- output_ptr += (ulg)outcnt;
- outcnt = 0;
+ while (len--)
+ *output_data++ = *buf++;
}

static void error(char *x)
@@ -87,6 +65,6 @@ decompress_kernel(int mmu_on, unsigned c
input_len = zimage_len;

puts("Uncompressing Linux... ");
- gunzip(input_data, input_len, NULL);
+ gunzip(input_data, input_len, NULL, flush_window);
puts("Ok, booting the kernel.\n");
}
Index: 2.6.14/arch/sh/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh/boot/compressed/misc.c 2005-10-28 21:09:20.000000000 -0700
+++ 2.6.14/arch/sh/boot/compressed/misc.c 2005-10-28 21:13:20.000000000 -0700
@@ -23,21 +23,11 @@ typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;

-#define WSIZE 0x8000 /* Window size must be at least 32k, */
- /* and a power of two */
-
-static uch window[WSIZE]; /* Sliding window buffer */
-static unsigned outcnt = 0; /* bytes in output buffer */
-
-static void flush_window(void);
static void error(char *m);

extern char input_data[];
extern int input_len;
-
-static long bytes_out = 0;
static uch *output_data;
-static unsigned long output_ptr = 0;

int puts(const char *);

@@ -74,23 +64,11 @@ int puts(const char *s)
}
#endif

-/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update bytes_out.
- * (Used for the decompressed data only.)
- */
-static void flush_window(void)
-{
- unsigned n;
- uch *in, *out, ch;
-
- in = window;
- out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++)
- ch = *out++ = *in++;
-
- bytes_out += (ulg)outcnt;
- output_ptr += (ulg)outcnt;
- outcnt = 0;
+/* flush the gunzip output window */
+static void flush_window(const u8 *buf, int len)
+{
+ while (len--)
+ *output_data++ = *buf++;
}

static void error(char *x)
@@ -114,6 +92,6 @@ void decompress_kernel(void)
free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;

puts("Uncompressing Linux... ");
- gunzip(input_data, input_len, NULL);
+ gunzip(input_data, input_len, NULL, flush_window);
puts("Ok, booting the kernel.\n");
}
Index: 2.6.14/arch/sh64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh64/boot/compressed/misc.c 2005-10-28 21:09:20.000000000 -0700
+++ 2.6.14/arch/sh64/boot/compressed/misc.c 2005-10-28 21:13:20.000000000 -0700
@@ -23,21 +23,11 @@ typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;

-#define WSIZE 0x8000 /* Window size must be at least 32k, */
- /* and a power of two */
-
-static uch window[WSIZE]; /* Sliding window buffer */
-static unsigned outcnt = 0; /* bytes in output buffer */
-
-static void flush_window(void);
static void error(char *m);

extern char input_data[];
extern int input_len;
-
-static long bytes_out = 0;
static uch *output_data;
-static unsigned long output_ptr = 0;

static void puts(const char *);

@@ -54,23 +44,12 @@ void puts(const char *s)
{
}

-/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update bytes_out.
- * (Used for the decompressed data only.)
- */
-static void flush_window(void)
+/* flush the gunzip window */
+static void flush_window(const u8 *buf, int len)
{
- unsigned n;
- uch *in, *out, ch;
+ while(len--)
+ *output_data++ = *buf++;

- in = window;
- out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++)
- ch = *out++ = *in++;
-
- bytes_out += (ulg) outcnt;
- output_ptr += (ulg) outcnt;
- outcnt = 0;
puts(".");
}

@@ -95,7 +74,7 @@ void decompress_kernel(void)

puts("Uncompressing Linux... ");
cache_control(CACHE_ENABLE);
- gunzip(input_data, input_len, NULL);
+ gunzip(input_data, input_len, NULL, flush_window);
puts("\n");

#if 0
Index: 2.6.14/arch/x86_64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/x86_64/boot/compressed/misc.c 2005-10-28 21:09:20.000000000 -0700
+++ 2.6.14/arch/x86_64/boot/compressed/misc.c 2005-10-28 21:13:20.000000000 -0700
@@ -20,13 +20,6 @@ typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;

-#define WSIZE 0x8000 /* Window size must be at least 32k, */
- /* and a power of two */
-
-static uch window[WSIZE]; /* Sliding window buffer */
-static unsigned outcnt = 0; /* bytes in output buffer */
-
-static void flush_window(void);
static void error(char *m);

/*
@@ -43,9 +36,8 @@ static unsigned char *real_mode; /* Poin
extern unsigned char input_data[];
extern int input_len;

-static long bytes_out = 0;
+static long bytes_out;
static uch *output_data;
-static unsigned long output_ptr = 0;

static void putstr(const char *);

@@ -115,43 +107,15 @@ static void putstr(const char *s)
outb_p(0xff & (pos >> 1), vidport+1);
}

-/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update bytes_out.
- * (Used for the decompressed data only.)
- */
-static void flush_window_low(void)
+/* flush the gunzip output window */
+static void flush_window(const u8 *buf, int len)
{
- unsigned n;
- uch *in, *out, ch;
-
- in = window;
- out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++)
- ch = *out++ = *in++;
-
- bytes_out += (ulg)outcnt;
- output_ptr += (ulg)outcnt;
- outcnt = 0;
-}
-
-static void flush_window_high(void)
-{
- unsigned n;
- uch *in, ch;
- in = window;
- for (n = 0; n < outcnt; n++) {
- ch = *output_data++ = *in++;
- if ((ulg)output_data == low_buffer_end) output_data=high_buffer_start;
- }
-
- bytes_out += (ulg)outcnt;
- outcnt = 0;
-}
-
-static void flush_window(void)
-{
- if (high_loaded) flush_window_high();
- else flush_window_low();
+ bytes_out += len;
+ while (len--) {
+ *output_data++ = *buf++;
+ if (high_loaded && output_data == (u8 *)low_buffer_end)
+ output_data = high_buffer_start;
+ }
}

static void error(char *x)
@@ -201,7 +165,7 @@ void setup_output_buffer_if_we_run_high(
mv->high_buffer_start = high_buffer_start;
}

-void close_output_buffer_if_we_run_high(struct moveparams *mv)
+void close_output_buffer_if_we_run_high(struct moveparams *mv, int bytes_out)
{
if (bytes_out > low_buffer_size) {
mv->lcount = low_buffer_size;
@@ -232,7 +196,7 @@ int decompress_kernel(struct moveparams
else setup_output_buffer_if_we_run_high(mv);

putstr(".\nDecompressing Linux...");
- gunzip(input_data, input_len, NULL);
+ gunzip(input_data, input_len, NULL, flush_window);
putstr("done.\nBooting the kernel.\n");
if (high_loaded) close_output_buffer_if_we_run_high(mv);
return high_loaded;
Index: 2.6.14/init/do_mounts_rd.c
===================================================================
--- 2.6.14.orig/init/do_mounts_rd.c 2005-10-28 21:09:20.000000000 -0700
+++ 2.6.14/init/do_mounts_rd.c 2005-10-28 21:13:20.000000000 -0700
@@ -278,20 +278,13 @@ typedef unsigned short ush;
typedef unsigned long ulg;

#define INBUFSIZ 4096
-#define WSIZE 0x8000 /* window size--must be a power of two, and */
- /* at least 32K for zip's deflate method */
-
static uch *inbuf;
-static uch *window;
-static unsigned outcnt; /* bytes in output buffer */
static int exit_code;
static int unzip_error;
-static long bytes_out;
static int crd_infd, crd_outfd;

#define INIT __init

-static void __init flush_window(void);
static void __init error(char *m);

#define NO_INFLATE_MALLOC
@@ -308,27 +301,17 @@ static void __init fill_inbuf(u8 *buf, i
error("RAMDISK: ran out of compressed data");
}

-/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update bytes_out.
- * (Used for the decompressed data only.)
- */
-static void __init flush_window(void)
+/* Write the output window from gunzip */
+static void __init flush_buffer(const u8 *buf, int len)
{
- unsigned n, written;
- uch *in, ch;
-
- written = sys_write(crd_outfd, window, outcnt);
- if (written != outcnt && unzip_error == 0) {
- printk(KERN_ERR "RAMDISK: incomplete write (%d != %d) %ld\n",
- written, outcnt, bytes_out);
- unzip_error = 1;
- }
- in = window;
- for (n = 0; n < outcnt; n++)
- ch = *in++;
+ unsigned written;

- bytes_out += (ulg)outcnt;
- outcnt = 0;
+ written = sys_write(crd_outfd, buf, len);
+ if (written != len && unzip_error == 0) {
+ printk(KERN_ERR "RAMDISK: incomplete write (%d != %d)\n",
+ written, len);
+ unzip_error = 1;
+ }
}

static void __init error(char *x)
@@ -342,9 +325,7 @@ static int __init crd_load(int in_fd, in
{
int result;

- outcnt = 0; /* bytes in output buffer */
exit_code = 0;
- bytes_out = 0;

crd_infd = in_fd;
crd_outfd = out_fd;
@@ -353,17 +334,10 @@ static int __init crd_load(int in_fd, in
printk(KERN_ERR "RAMDISK: Couldn't allocate gzip buffer\n");
return -1;
}
- window = kmalloc(WSIZE, GFP_KERNEL);
- if (window == 0) {
- printk(KERN_ERR "RAMDISK: Couldn't allocate gzip window\n");
- kfree(inbuf);
- return -1;
- }
- result = gunzip(inbuf, INBUFSIZ, fill_inbuf);
+ result = gunzip(inbuf, INBUFSIZ, fill_inbuf, flush_buffer);
if (unzip_error)
result = 1;
kfree(inbuf);
- kfree(window);
return result;
}

Index: 2.6.14/init/initramfs.c
===================================================================
--- 2.6.14.orig/init/initramfs.c 2005-10-28 21:09:20.000000000 -0700
+++ 2.6.14/init/initramfs.c 2005-10-28 21:13:20.000000000 -0700
@@ -309,12 +309,12 @@ static int __init write_buffer(char *buf
return len - count;
}

-static void __init flush_buffer(char *buf, unsigned len)
+static void __init flush_buffer(const u8 *buf, int len)
{
int written;
if (message)
return;
- while ((written = write_buffer(buf, len)) < len && !message) {
+ while ((written = write_buffer((char *)buf, len)) < len && !message) {
char c = buf[written];
if (c == '0') {
buf += written;
@@ -337,41 +337,14 @@ typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;

-#define WSIZE 0x8000 /* window size--must be a power of two, and */
- /* at least 32K for zip's deflate method */
-
-static uch *window;
-
-static unsigned outcnt; /* bytes in output buffer */
-static long bytes_out;
-
#define INIT __init

-static void __init flush_window(void);
static void __init error(char *m);

#define NO_INFLATE_MALLOC

#include "../lib/inflate.c"

-/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update bytes_out.
- * (Used for the decompressed data only.)
- */
-static void __init flush_window(void)
-{
- unsigned n;
- uch *in, ch;
-
- flush_buffer(window, outcnt);
- in = window;
- for (n = 0; n < outcnt; n++)
- ch = *in++;
-
- bytes_out += (ulg)outcnt;
- outcnt = 0;
-}
-
static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only)
{
int written, cnt;
@@ -379,8 +352,7 @@ static char * __init unpack_to_rootfs(ch
header_buf = kmalloc(110, GFP_KERNEL);
symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL);
name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL);
- window = kmalloc(WSIZE, GFP_KERNEL);
- if (!window || !header_buf || !symlink_buf || !name_buf)
+ if (!header_buf || !symlink_buf || !name_buf)
panic("can't allocate buffers");
state = Start;
this_header = 0;
@@ -401,16 +373,13 @@ static char * __init unpack_to_rootfs(ch
continue;
}
this_header = 0;
- outcnt = 0; /* bytes in output buffer */
- bytes_out = 0;
- cnt = gunzip(buf, len, NULL);
+ cnt = gunzip(buf, len, NULL, flush_buffer);
if (state != Reset)
error("junk in gzipped archive");
this_header = saved_offset + cnt;
buf += cnt;
len -= cnt;
}
- kfree(window);
kfree(name_buf);
kfree(symlink_buf);
kfree(header_buf);

2005-10-31 21:02:23

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 9/20] inflate: (arch) refactor inflate malloc code

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.

This also fixes bogus usage of malloc/free rather than kmalloc/kfree
in initramfs.c.

Signed-off-by: Matt Mackall <[email protected]>

Index: 2.6.14/arch/alpha/boot/misc.c
===================================================================
--- 2.6.14.orig/arch/alpha/boot/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/alpha/boot/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -4,8 +4,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
- *
* Modified for ARM Linux by Russell King
*
* Nicolas Pitre <[email protected]> 1999/04/14 :
@@ -49,8 +47,6 @@ static unsigned outcnt; /* bytes in out
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);

static char *input_data;
static int input_data_size;
@@ -59,12 +55,6 @@ static uch *output_data;
static ulg output_ptr;
static ulg bytes_out;

-static void *malloc(int size);
-static void free(void *where);
-static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
-
extern int end;
static ulg free_mem_ptr;
static ulg free_mem_ptr_end;
@@ -73,37 +63,6 @@ static ulg free_mem_ptr_end;

#include "../../../lib/inflate.c"

-static void *malloc(int size)
-{
- void *p;
-
- if (size <0) error("Malloc error");
- if (free_mem_ptr <= 0) error("Memory error");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *)free_mem_ptr;
- free_mem_ptr += size;
-
- if (free_mem_ptr >= free_mem_ptr_end)
- error("Out of memory");
- return p;
-}
-
-static void free(void *where)
-{ /* gzip_mark & gzip_release do the free */
-}
-
-static void gzip_mark(void **ptr)
-{
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- free_mem_ptr = (long) *ptr;
-}
-
/* ===========================================================================
* Fill the input buffer. This is called only when the buffer is empty
* and at least one byte is really needed.
Index: 2.6.14/arch/arm/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm/boot/compressed/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/arm/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -4,8 +4,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
- *
* Modified for ARM Linux by Russell King
*
* Nicolas Pitre <[email protected]> 1999/04/14 :
@@ -67,8 +65,6 @@ static unsigned outcnt; /* bytes in out
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);

extern char input_data[];
extern char input_data_end[];
@@ -77,12 +73,6 @@ static uch *output_data;
static ulg output_ptr;
static ulg bytes_out;

-static void *malloc(int size);
-static void free(void *where);
-static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
-
static void putstr(const char *);

extern int end;
@@ -93,47 +83,8 @@ static ulg free_mem_ptr_end;

#include "../../../../lib/inflate.c"

-#ifndef STANDALONE_DEBUG
-static void *malloc(int size)
-{
- void *p;
-
- if (size <0) error("Malloc error");
- if (free_mem_ptr <= 0) error("Memory error");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *)free_mem_ptr;
- free_mem_ptr += size;
-
- if (free_mem_ptr >= free_mem_ptr_end)
- error("Out of memory");
- return p;
-}
-
-static void free(void *where)
-{ /* gzip_mark & gzip_release do the free */
-}
-
-static void gzip_mark(void **ptr)
-{
- arch_decomp_wdog();
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- arch_decomp_wdog();
- free_mem_ptr = (long) *ptr;
-}
-#else
-static void gzip_mark(void **ptr)
-{
-}
-
-static void gzip_release(void **ptr)
-{
-}
+#ifdef STANDALONE_DEBUG
+#define NO_INFLATE_MALLOC
#endif

/* ===========================================================================
Index: 2.6.14/arch/arm26/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm26/boot/compressed/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/arm26/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -4,8 +4,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
- *
* Modified for ARM Linux by Russell King
*
* Nicolas Pitre <[email protected]> 1999/04/14 :
@@ -52,8 +50,6 @@ static unsigned outcnt; /* bytes in out
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);

extern char input_data[];
extern char input_data_end[];
@@ -62,12 +58,6 @@ static uch *output_data;
static ulg output_ptr;
static ulg bytes_out;

-static void *malloc(int size);
-static void free(void *where);
-static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
-
static void puts(const char *);

extern int end;
@@ -78,47 +68,8 @@ static ulg free_mem_ptr_end;

#include "../../../../lib/inflate.c"

-#ifndef STANDALONE_DEBUG
-static void *malloc(int size)
-{
- void *p;
-
- if (size <0) error("Malloc error");
- if (free_mem_ptr <= 0) error("Memory error");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *)free_mem_ptr;
- free_mem_ptr += size;
-
- if (free_mem_ptr >= free_mem_ptr_end)
- error("Out of memory");
- return p;
-}
-
-static void free(void *where)
-{ /* gzip_mark & gzip_release do the free */
-}
-
-static void gzip_mark(void **ptr)
-{
- arch_decomp_wdog();
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- arch_decomp_wdog();
- free_mem_ptr = (long) *ptr;
-}
-#else
-static void gzip_mark(void **ptr)
-{
-}
-
-static void gzip_release(void **ptr)
-{
-}
+#ifdef STANDALONE_DEBUG
+#define NO_INFLATE_MALLOC
#endif

/* ===========================================================================
Index: 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -6,7 +6,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
* puts by Nick Holloway 1993, better puts by Martin Mares 1995
* adoptation for Linux/CRIS Axis Communications AB, 1999
*
@@ -51,57 +50,22 @@ static unsigned outcnt = 0; /* bytes in
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);

extern char *input_data; /* lives in head.S */

static long bytes_out = 0;
static uch *output_data;
static unsigned long output_ptr = 0;
-
-static void *malloc(int size);
-static void free(void *where);
-static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
-
+
static void puts(const char *);

/* the "heap" is put directly after the BSS ends, at end */

extern int end;
static long free_mem_ptr = (long)&end;
-
-#include "../../../../../lib/inflate.c"
-
-static void *malloc(int size)
-{
- void *p;
-
- if (size <0) error("Malloc error");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *)free_mem_ptr;
- free_mem_ptr += size;
-
- return p;
-}
-
-static void free(void *where)
-{ /* Don't care */
-}
+static long free_mem_end_ptr = 0xffffffff;

-static void gzip_mark(void **ptr)
-{
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- free_mem_ptr = (long) *ptr;
-}
+#include "../../../../../lib/inflate.c"

/* decompressor info and error messages to serial console */

Index: 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -6,7 +6,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
* puts by Nick Holloway 1993, better puts by Martin Mares 1995
* adoptation for Linux/CRIS Axis Communications AB, 1999
*
@@ -53,8 +52,6 @@ static unsigned outcnt = 0; /* bytes in
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);

extern char *input_data; /* lives in head.S */

@@ -62,49 +59,16 @@ static long bytes_out = 0;
static uch *output_data;
static unsigned long output_ptr = 0;

-static void *malloc(int size);
-static void free(void *where);
-static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
-
static void puts(const char *);

/* the "heap" is put directly after the BSS ends, at end */

extern int _end;
static long free_mem_ptr = (long)&_end;
+static long free_mem_end_ptr = 0xffffffff;

#include "../../../../../lib/inflate.c"

-static void *malloc(int size)
-{
- void *p;
-
- if (size <0) error("Malloc error");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *)free_mem_ptr;
- free_mem_ptr += size;
-
- return p;
-}
-
-static void free(void *where)
-{ /* Don't care */
-}
-
-static void gzip_mark(void **ptr)
-{
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- free_mem_ptr = (long) *ptr;
-}
-
/* decompressor info and error messages to serial console */

static inline void
Index: 2.6.14/arch/i386/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/i386/boot/compressed/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/i386/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -4,7 +4,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
* puts by Nick Holloway 1993, better puts by Martin Mares 1995
* High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
*/
@@ -43,9 +42,7 @@ static unsigned outcnt = 0; /* bytes in
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
-
+
/*
* This is set up by the setup-routine at boot-time
*/
@@ -64,9 +61,6 @@ static long bytes_out = 0;
static uch *output_data;
static unsigned long output_ptr = 0;

-static void *malloc(int size);
-static void free(void *where);
-
static void putstr(const char *);

extern int end;
@@ -91,38 +85,6 @@ static void * xquad_portio = NULL;

#include "../../../../lib/inflate.c"

-static void *malloc(int size)
-{
- void *p;
-
- if (size <0) error("Malloc error");
- if (free_mem_ptr <= 0) error("Memory error");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *)free_mem_ptr;
- free_mem_ptr += size;
-
- if (free_mem_ptr >= free_mem_end_ptr)
- error("Out of memory");
-
- return p;
-}
-
-static void free(void *where)
-{ /* Don't care */
-}
-
-static void gzip_mark(void **ptr)
-{
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- free_mem_ptr = (long) *ptr;
-}
-
static void scroll(void)
{
int i;
Index: 2.6.14/arch/m32r/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/m32r/boot/compressed/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/m32r/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -4,8 +4,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
- *
* Adapted for SH by Stuart Menefy, Aug 1999
*
* 2003-02-12: Support M32R by Takeo Takahashi
@@ -38,8 +36,6 @@ static unsigned outcnt = 0; /* bytes in
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);

static unsigned char *input_data;
static int input_len;
@@ -50,9 +46,6 @@ static unsigned long output_ptr = 0;

#include "m32r_sio.c"

-static void *malloc(int size);
-static void free(void *where);
-
static unsigned long free_mem_ptr;
static unsigned long free_mem_end_ptr;

@@ -60,38 +53,6 @@ static unsigned long free_mem_end_ptr;

#include "../../../../lib/inflate.c"

-static void *malloc(int size)
-{
- void *p;
-
- if (size <0) error("Malloc error");
- if (free_mem_ptr == 0) error("Memory error");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *)free_mem_ptr;
- free_mem_ptr += size;
-
- if (free_mem_ptr >= free_mem_end_ptr)
- error("Out of memory");
-
- return p;
-}
-
-static void free(void *where)
-{ /* Don't care */
-}
-
-static void gzip_mark(void **ptr)
-{
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- free_mem_ptr = (long) *ptr;
-}
-
/* ===========================================================================
* Fill the input buffer. This is called only when the buffer is empty
* and at least one byte is really needed.
Index: 2.6.14/arch/sh/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh/boot/compressed/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/sh/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -4,8 +4,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
- *
* Adapted for SH by Stuart Menefy, Aug 1999
*
* Modified to use standard LinuxSH BIOS by Greg Banks 7Jul2000
@@ -40,8 +38,6 @@ static unsigned outcnt = 0; /* bytes in
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);

extern char input_data[];
extern int input_len;
@@ -50,12 +46,6 @@ static long bytes_out = 0;
static uch *output_data;
static unsigned long output_ptr = 0;

-static void *malloc(int size);
-static void free(void *where);
-static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
-
int puts(const char *);

extern int _text; /* Defined in vmlinux.lds.S */
@@ -67,38 +57,6 @@ static unsigned long free_mem_end_ptr;

#include "../../../../lib/inflate.c"

-static void *malloc(int size)
-{
- void *p;
-
- if (size <0) error("Malloc error");
- if (free_mem_ptr == 0) error("Memory error");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *)free_mem_ptr;
- free_mem_ptr += size;
-
- if (free_mem_ptr >= free_mem_end_ptr)
- error("Out of memory");
-
- return p;
-}
-
-static void free(void *where)
-{ /* Don't care */
-}
-
-static void gzip_mark(void **ptr)
-{
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- free_mem_ptr = (long) *ptr;
-}
-
#ifdef CONFIG_SH_STANDARD_BIOS
size_t strlen(const char *s)
{
Index: 2.6.14/arch/sh64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh64/boot/compressed/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/sh64/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -4,8 +4,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
- *
* Adapted for SHmedia from sh by Stuart Menefy, May 2002
*/

@@ -40,8 +38,6 @@ static unsigned outcnt = 0; /* bytes in
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);

extern char input_data[];
extern int input_len;
@@ -50,12 +46,6 @@ static long bytes_out = 0;
static uch *output_data;
static unsigned long output_ptr = 0;

-static void *malloc(int size);
-static void free(void *where);
-static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
-
static void puts(const char *);

extern int _text; /* Defined in vmlinux.lds.S */
@@ -67,40 +57,6 @@ static unsigned long free_mem_end_ptr;

#include "../../../../lib/inflate.c"

-static void *malloc(int size)
-{
- void *p;
-
- if (size < 0)
- error("Malloc error\n");
- if (free_mem_ptr == 0)
- error("Memory error\n");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *) free_mem_ptr;
- free_mem_ptr += size;
-
- if (free_mem_ptr >= free_mem_end_ptr)
- error("\nOut of memory\n");
-
- return p;
-}
-
-static void free(void *where)
-{ /* Don't care */
-}
-
-static void gzip_mark(void **ptr)
-{
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- free_mem_ptr = (long) *ptr;
-}
-
void puts(const char *s)
{
}
Index: 2.6.14/arch/x86_64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/x86_64/boot/compressed/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/x86_64/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -4,7 +4,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
* puts by Nick Holloway 1993, better puts by Martin Mares 1995
* High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
*/
@@ -36,9 +35,7 @@ static unsigned outcnt = 0; /* bytes in
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
-
+
/*
* This is set up by the setup-routine at boot-time
*/
@@ -57,9 +54,6 @@ static long bytes_out = 0;
static uch *output_data;
static unsigned long output_ptr = 0;

-static void *malloc(int size);
-static void free(void *where);
-
static void putstr(const char *);

extern int end;
@@ -80,38 +74,6 @@ static int lines, cols;

#include "../../../../lib/inflate.c"

-static void *malloc(int size)
-{
- void *p;
-
- if (size <0) error("Malloc error");
- if (free_mem_ptr <= 0) error("Memory error");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *)free_mem_ptr;
- free_mem_ptr += size;
-
- if (free_mem_ptr >= free_mem_end_ptr)
- error("Out of memory");
-
- return p;
-}
-
-static void free(void *where)
-{ /* Don't care */
-}
-
-static void gzip_mark(void **ptr)
-{
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- free_mem_ptr = (long) *ptr;
-}
-
static void scroll(void)
{
int i;
Index: 2.6.14/init/do_mounts_rd.c
===================================================================
--- 2.6.14.orig/init/do_mounts_rd.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/init/do_mounts_rd.c 2005-10-28 22:04:13.000000000 -0700
@@ -298,32 +298,11 @@ static int crd_infd, crd_outfd;

static int __init fill_inbuf(void);
static void __init flush_window(void);
-static void __init *malloc(size_t size);
-static void __init free(void *where);
static void __init error(char *m);
-static void __init gzip_mark(void **);
-static void __init gzip_release(void **);

-#include "../lib/inflate.c"
-
-static void __init *malloc(size_t size)
-{
- return kmalloc(size, GFP_KERNEL);
-}
-
-static void __init free(void *where)
-{
- kfree(where);
-}
-
-static void __init gzip_mark(void **ptr)
-{
-}
-
-static void __init gzip_release(void **ptr)
-{
-}
+#define NO_INFLATE_MALLOC

+#include "../lib/inflate.c"

/* ===========================================================================
* Fill the input buffer. This is called only when the buffer is empty
Index: 2.6.14/init/initramfs.c
===================================================================
--- 2.6.14.orig/init/initramfs.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/init/initramfs.c 2005-10-28 22:04:13.000000000 -0700
@@ -14,16 +14,6 @@ static void __init error(char *x)
message = x;
}

-static void __init *malloc(size_t size)
-{
- return kmalloc(size, GFP_KERNEL);
-}
-
-static void __init free(void *where)
-{
- kfree(where);
-}
-
/* link hash */

static __initdata struct hash {
@@ -51,7 +41,7 @@ static char __init *find_link(int major,
continue;
return (*p)->name;
}
- q = (struct hash *)malloc(sizeof(struct hash));
+ q = kmalloc(sizeof(struct hash), GFP_KERNEL);
if (!q)
panic("can't allocate link hash entry");
q->ino = ino;
@@ -70,7 +60,7 @@ static void __init free_hash(void)
while (*p) {
q = *p;
*p = q->next;
- free(q);
+ kfree(q);
}
}
}
@@ -364,18 +354,10 @@ static long bytes_out;

static void __init flush_window(void);
static void __init error(char *m);
-static void __init gzip_mark(void **);
-static void __init gzip_release(void **);

-#include "../lib/inflate.c"
+#define NO_INFLATE_MALLOC

-static void __init gzip_mark(void **ptr)
-{
-}
-
-static void __init gzip_release(void **ptr)
-{
-}
+#include "../lib/inflate.c"

/* ===========================================================================
* Write the output window window[0..outcnt-1] and update crc and bytes_out.
@@ -402,10 +384,10 @@ static char * __init unpack_to_rootfs(ch
{
int written;
dry_run = check_only;
- header_buf = malloc(110);
- symlink_buf = malloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1);
- name_buf = malloc(N_ALIGN(PATH_MAX));
- window = malloc(WSIZE);
+ header_buf = kmalloc(110, GFP_KERNEL);
+ symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL);
+ name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL);
+ window = kmalloc(WSIZE, GFP_KERNEL);
if (!window || !header_buf || !symlink_buf || !name_buf)
panic("can't allocate buffers");
state = Start;
@@ -441,10 +423,10 @@ static char * __init unpack_to_rootfs(ch
buf += inptr;
len -= inptr;
}
- free(window);
- free(name_buf);
- free(symlink_buf);
- free(header_buf);
+ kfree(window);
+ kfree(name_buf);
+ kfree(symlink_buf);
+ kfree(header_buf);
return message;
}

Index: 2.6.14/lib/inflate.c
===================================================================
--- 2.6.14.orig/lib/inflate.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/lib/inflate.c 2005-10-28 22:04:13.000000000 -0700
@@ -109,6 +109,46 @@

#include <asm/types.h>

+#ifndef NO_INFLATE_MALLOC
+/* A trivial malloc implementation, adapted from
+ * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
+ */
+
+static unsigned long malloc_ptr;
+static int malloc_count;
+
+static void *malloc(int size)
+{
+ void *p;
+
+ if (size <0)
+ error("Malloc error");
+ if (!malloc_ptr)
+ malloc_ptr = free_mem_ptr;
+
+ malloc_ptr = (malloc_ptr + 3) & ~3; /* Align */
+
+ p = (void *)malloc_ptr;
+ malloc_ptr += size;
+
+ if (malloc_ptr >= free_mem_end_ptr)
+ error("Out of memory");
+
+ malloc_count++;
+ return p;
+}
+
+static void free(void *where)
+{
+ malloc_count--;
+ if (!malloc_count)
+ malloc_ptr = free_mem_ptr;
+}
+#else
+#define malloc(a) kmalloc(a, GFP_KERNEL)
+#define free(a) kfree(a)
+#endif
+
static u32 crc_32_tab[256];
static u32 crc; /* dummy var until users get cleaned up */
#define CRCPOLY_LE 0xedb88320
@@ -895,16 +935,12 @@ static int INIT inflate(struct iostate *
{
int e; /* last block flag */
int r; /* result code */
- void *ptr;

/* decompress until the last block */
do {
- gzip_mark(&ptr);
- if ((r = inflate_block(io, &e))) {
- gzip_release(&ptr);
+ r = inflate_block(io, &e);
+ if (r)
return r;
- }
- gzip_release(&ptr);
} while (!e);

popbytes(io);

2005-10-31 21:03:47

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 10/20] inflate: (arch) kill external CRC calculation

inflate: move CRC calculation

Each inflate user was doing its own open-coded CRC calculation and
initializing its own CRC table. This is now hidden inside
lib/inflate.c

Signed-off-by: Matt Mackall <[email protected]>

Index: 2.6.14/arch/alpha/boot/misc.c
===================================================================
--- 2.6.14.orig/arch/alpha/boot/misc.c 2005-10-28 22:04:13.000000000 -0700
+++ 2.6.14/arch/alpha/boot/misc.c 2005-10-28 22:04:15.000000000 -0700
@@ -80,22 +80,19 @@ int fill_inbuf(void)
}

/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update crc and bytes_out.
+ * Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/
void flush_window(void)
{
- ulg c = crc;
unsigned n;
uch *in, *out, ch;

in = window;
out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++) {
+ for (n = 0; n < outcnt; n++)
ch = *out++ = *in++;
- c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
- }
- crc = c;
+
bytes_out += (ulg)outcnt;
output_ptr += (ulg)outcnt;
outcnt = 0;
@@ -129,7 +126,6 @@ decompress_kernel(void *output_start,
/* put in temp area to reduce initial footprint */
window = malloc(WSIZE);

- makecrc();
/* puts("Uncompressing Linux..."); */
gunzip();
/* puts(" done, booting the kernel.\n"); */
Index: 2.6.14/arch/arm/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
+++ 2.6.14/arch/arm/boot/compressed/misc.c 2005-10-28 22:04:15.000000000 -0700
@@ -104,22 +104,19 @@ int fill_inbuf(void)
}

/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update crc and bytes_out.
+ * Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/
void flush_window(void)
{
- ulg c = crc;
unsigned n;
uch *in, *out, ch;

in = window;
out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++) {
+ for (n = 0; n < outcnt; n++)
ch = *out++ = *in++;
- c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
- }
- crc = c;
+
bytes_out += (ulg)outcnt;
output_ptr += (ulg)outcnt;
outcnt = 0;
@@ -148,7 +145,6 @@ decompress_kernel(ulg output_start, ulg

arch_decomp_setup();

- makecrc();
putstr("Uncompressing Linux...");
gunzip();
putstr(" done, booting the kernel.\n");
@@ -162,7 +158,6 @@ int main()
{
output_data = output_buffer;

- makecrc();
putstr("Uncompressing Linux...");
gunzip();
putstr("done.\n");
Index: 2.6.14/arch/arm26/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm26/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
+++ 2.6.14/arch/arm26/boot/compressed/misc.c 2005-10-28 22:04:15.000000000 -0700
@@ -89,22 +89,19 @@ int fill_inbuf(void)
}

/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update crc and bytes_out.
+ * Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/
void flush_window(void)
{
- ulg c = crc;
unsigned n;
uch *in, *out, ch;

in = window;
out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++) {
+ for (n = 0; n < outcnt; n++)
ch = *out++ = *in++;
- c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
- }
- crc = c;
+
bytes_out += (ulg)outcnt;
output_ptr += (ulg)outcnt;
outcnt = 0;
@@ -135,7 +132,6 @@ decompress_kernel(ulg output_start, ulg

arch_decomp_setup();

- makecrc();
puts("Uncompressing Linux...");
gunzip();
puts(" done, booting the kernel.\n");
@@ -149,7 +145,6 @@ int main()
{
output_data = output_buffer;

- makecrc();
puts("Uncompressing Linux...");
gunzip();
puts("done.\n");
Index: 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
+++ 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-28 22:04:15.000000000 -0700
@@ -95,24 +95,21 @@ puts(const char *s)
}

/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update crc and bytes_out.
+ * Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/

static void
flush_window()
{
- ulg c = crc; /* temporary variable */
unsigned n;
uch *in, *out, ch;
-
+
in = window;
- out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++) {
+ out = &output_data[output_ptr];
+ for (n = 0; n < outcnt; n++)
ch = *out++ = *in++;
- c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
- }
- crc = c;
+
bytes_out += (ulg)outcnt;
output_ptr += (ulg)outcnt;
outcnt = 0;
@@ -167,8 +164,6 @@ decompress_kernel()

setup_normal_output_buffer();

- makecrc();
-
__asm__ volatile ("move vr,%0" : "=rm" (revision));
if (revision < 10)
{
Index: 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
+++ 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-28 22:04:15.000000000 -0700
@@ -109,24 +109,21 @@ puts(const char *s)
}

/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update crc and bytes_out.
+ * Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/

static void
flush_window()
{
- ulg c = crc; /* temporary variable */
unsigned n;
uch *in, *out, ch;

in = window;
out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++) {
+ for (n = 0; n < outcnt; n++)
ch = *out++ = *in++;
- c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
- }
- crc = c;
+
bytes_out += (ulg)outcnt;
output_ptr += (ulg)outcnt;
outcnt = 0;
@@ -212,8 +209,6 @@ decompress_kernel()

setup_normal_output_buffer();

- makecrc();
-
__asm__ volatile ("move $vr,%0" : "=rm" (revision));
if (revision < 32)
{
Index: 2.6.14/arch/i386/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/i386/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
+++ 2.6.14/arch/i386/boot/compressed/misc.c 2005-10-28 22:04:15.000000000 -0700
@@ -150,22 +150,19 @@ static int fill_inbuf(void)
}

/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update crc and bytes_out.
+ * Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/
static void flush_window_low(void)
{
- ulg c = crc; /* temporary variable */
unsigned n;
uch *in, *out, ch;
-
+
in = window;
- out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++) {
+ out = &output_data[output_ptr];
+ for (n = 0; n < outcnt; n++)
ch = *out++ = *in++;
- c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
- }
- crc = c;
+
bytes_out += (ulg)outcnt;
output_ptr += (ulg)outcnt;
outcnt = 0;
@@ -173,16 +170,14 @@ static void flush_window_low(void)

static void flush_window_high(void)
{
- ulg c = crc; /* temporary variable */
unsigned n;
uch *in, ch;
in = window;
for (n = 0; n < outcnt; n++) {
ch = *output_data++ = *in++;
if ((ulg)output_data == low_buffer_end) output_data=high_buffer_start;
- c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
}
- crc = c;
+
bytes_out += (ulg)outcnt;
outcnt = 0;
}
@@ -281,7 +276,6 @@ asmlinkage int decompress_kernel(struct
if (free_mem_ptr < 0x100000) setup_normal_output_buffer();
else setup_output_buffer_if_we_run_high(mv);

- makecrc();
putstr("Uncompressing Linux... ");
gunzip();
putstr("Ok, booting the kernel.\n");
Index: 2.6.14/arch/m32r/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/m32r/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
+++ 2.6.14/arch/m32r/boot/compressed/misc.c 2005-10-28 22:04:15.000000000 -0700
@@ -70,22 +70,19 @@ static int fill_inbuf(void)
}

/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update crc and bytes_out.
+ * Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/
static void flush_window(void)
{
- ulg c = crc; /* temporary variable */
unsigned n;
uch *in, *out, ch;

in = window;
out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++) {
+ for (n = 0; n < outcnt; n++)
ch = *out++ = *in++;
- c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
- }
- crc = c;
+
bytes_out += (ulg)outcnt;
output_ptr += (ulg)outcnt;
outcnt = 0;
@@ -112,7 +109,6 @@ decompress_kernel(int mmu_on, unsigned c
input_data = zimage_data;
input_len = zimage_len;

- makecrc();
puts("Uncompressing Linux... ");
gunzip();
puts("Ok, booting the kernel.\n");
Index: 2.6.14/arch/sh/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
+++ 2.6.14/arch/sh/boot/compressed/misc.c 2005-10-28 22:04:15.000000000 -0700
@@ -98,22 +98,19 @@ static int fill_inbuf(void)
}

/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update crc and bytes_out.
+ * Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/
static void flush_window(void)
{
- ulg c = crc; /* temporary variable */
unsigned n;
uch *in, *out, ch;

in = window;
out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++) {
+ for (n = 0; n < outcnt; n++)
ch = *out++ = *in++;
- c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
- }
- crc = c;
+
bytes_out += (ulg)outcnt;
output_ptr += (ulg)outcnt;
outcnt = 0;
@@ -139,7 +136,6 @@ void decompress_kernel(void)
free_mem_ptr = (unsigned long)&_end;
free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;

- makecrc();
puts("Uncompressing Linux... ");
gunzip();
puts("Ok, booting the kernel.\n");
Index: 2.6.14/arch/sh64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh64/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
+++ 2.6.14/arch/sh64/boot/compressed/misc.c 2005-10-28 22:04:15.000000000 -0700
@@ -78,22 +78,19 @@ static int fill_inbuf(void)
}

/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update crc and bytes_out.
+ * Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/
static void flush_window(void)
{
- ulg c = crc; /* temporary variable */
unsigned n;
uch *in, *out, ch;

in = window;
out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++) {
+ for (n = 0; n < outcnt; n++)
ch = *out++ = *in++;
- c = crc_32_tab[((int) c ^ ch) & 0xff] ^ (c >> 8);
- }
- crc = c;
+
bytes_out += (ulg) outcnt;
output_ptr += (ulg) outcnt;
outcnt = 0;
@@ -119,7 +116,6 @@ void decompress_kernel(void)
free_mem_ptr = (unsigned long) &_end;
free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;

- makecrc();
puts("Uncompressing Linux... ");
cache_control(CACHE_ENABLE);
gunzip();
Index: 2.6.14/arch/x86_64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/x86_64/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
+++ 2.6.14/arch/x86_64/boot/compressed/misc.c 2005-10-28 22:04:15.000000000 -0700
@@ -139,22 +139,19 @@ static int fill_inbuf(void)
}

/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update crc and bytes_out.
+ * Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/
static void flush_window_low(void)
{
- ulg c = crc; /* temporary variable */
unsigned n;
uch *in, *out, ch;
-
+
in = window;
- out = &output_data[output_ptr];
- for (n = 0; n < outcnt; n++) {
+ out = &output_data[output_ptr];
+ for (n = 0; n < outcnt; n++)
ch = *out++ = *in++;
- c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
- }
- crc = c;
+
bytes_out += (ulg)outcnt;
output_ptr += (ulg)outcnt;
outcnt = 0;
@@ -162,16 +159,14 @@ static void flush_window_low(void)

static void flush_window_high(void)
{
- ulg c = crc; /* temporary variable */
unsigned n;
uch *in, ch;
in = window;
for (n = 0; n < outcnt; n++) {
ch = *output_data++ = *in++;
if ((ulg)output_data == low_buffer_end) output_data=high_buffer_start;
- c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
}
- crc = c;
+
bytes_out += (ulg)outcnt;
outcnt = 0;
}
@@ -259,7 +254,6 @@ int decompress_kernel(struct moveparams
if (free_mem_ptr < 0x100000) setup_normal_output_buffer();
else setup_output_buffer_if_we_run_high(mv);

- makecrc();
putstr(".\nDecompressing Linux...");
gunzip();
putstr("done.\nBooting the kernel.\n");
Index: 2.6.14/init/do_mounts_rd.c
===================================================================
--- 2.6.14.orig/init/do_mounts_rd.c 2005-10-28 22:04:13.000000000 -0700
+++ 2.6.14/init/do_mounts_rd.c 2005-10-28 22:04:15.000000000 -0700
@@ -325,15 +325,14 @@ static int __init fill_inbuf(void)
}

/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update crc and bytes_out.
+ * Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/
static void __init flush_window(void)
{
- ulg c = crc; /* temporary variable */
unsigned n, written;
uch *in, ch;
-
+
written = sys_write(crd_outfd, window, outcnt);
if (written != outcnt && unzip_error == 0) {
printk(KERN_ERR "RAMDISK: incomplete write (%d != %d) %ld\n",
@@ -341,11 +340,9 @@ static void __init flush_window(void)
unzip_error = 1;
}
in = window;
- for (n = 0; n < outcnt; n++) {
+ for (n = 0; n < outcnt; n++)
ch = *in++;
- c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
- }
- crc = c;
+
bytes_out += (ulg)outcnt;
outcnt = 0;
}
@@ -366,7 +363,6 @@ static int __init crd_load(int in_fd, in
outcnt = 0; /* bytes in output buffer */
exit_code = 0;
bytes_out = 0;
- crc = (ulg)0xffffffffL; /* shift register contents */

crd_infd = in_fd;
crd_outfd = out_fd;
@@ -381,7 +377,6 @@ static int __init crd_load(int in_fd, in
kfree(inbuf);
return -1;
}
- makecrc();
result = gunzip();
if (unzip_error)
result = 1;
Index: 2.6.14/init/initramfs.c
===================================================================
--- 2.6.14.orig/init/initramfs.c 2005-10-28 22:04:13.000000000 -0700
+++ 2.6.14/init/initramfs.c 2005-10-28 22:04:15.000000000 -0700
@@ -360,22 +360,19 @@ static void __init error(char *m);
#include "../lib/inflate.c"

/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update crc and bytes_out.
+ * Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/
static void __init flush_window(void)
{
- ulg c = crc; /* temporary variable */
unsigned n;
uch *in, ch;

flush_buffer(window, outcnt);
in = window;
- for (n = 0; n < outcnt; n++) {
+ for (n = 0; n < outcnt; n++)
ch = *in++;
- c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
- }
- crc = c;
+
bytes_out += (ulg)outcnt;
outcnt = 0;
}
@@ -414,8 +411,6 @@ static char * __init unpack_to_rootfs(ch
inptr = 0;
outcnt = 0; /* bytes in output buffer */
bytes_out = 0;
- crc = (ulg)0xffffffffL; /* shift register contents */
- makecrc();
gunzip();
if (state != Reset)
error("junk in gzipped archive");
Index: 2.6.14/lib/inflate.c
===================================================================
--- 2.6.14.orig/lib/inflate.c 2005-10-28 22:04:13.000000000 -0700
+++ 2.6.14/lib/inflate.c 2005-10-28 22:04:15.000000000 -0700
@@ -150,7 +150,6 @@ static void free(void *where)
#endif

static u32 crc_32_tab[256];
-static u32 crc; /* dummy var until users get cleaned up */
#define CRCPOLY_LE 0xedb88320

/* Huffman code lookup table entry--this entry is four bytes for machines
@@ -993,6 +992,8 @@ static int INIT gunzip(void)
io.opos = io.bits = io.buf = 0;
io.crc = 0xffffffffUL;

+ makecrc(); /* initialize the CRC table */
+
magic[0] = get_byte();
magic[1] = get_byte();
method = get_byte();

2005-10-31 21:04:35

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 4/20] inflate: start moving globals into iostate

inflate: move globals into a state structure

Signed-off-by: Matt Mackall <[email protected]>

Index: 2.6.14/lib/inflate.c
===================================================================
--- 2.6.14.orig/lib/inflate.c 2005-10-28 20:41:17.000000000 -0700
+++ 2.6.14/lib/inflate.c 2005-10-28 21:16:13.000000000 -0700
@@ -125,16 +125,23 @@ struct huft {
} v;
};

+struct iostate {
+ u8 *window;
+ int opos, osize, bits;
+ u32 buf;
+};
+
/* Function prototypes */
static int INIT huft_build(unsigned *, unsigned, unsigned,
const u16 *, const u16 *, struct huft **, int *);
static int INIT huft_free(struct huft *);
-static int INIT inflate_codes(struct huft *, struct huft *, int, int);
-static int INIT inflate_stored(void);
-static int INIT inflate_fixed(void);
-static int INIT inflate_dynamic(void);
-static int INIT inflate_block(int *);
-static int INIT inflate(void);
+static int INIT inflate_codes(struct iostate *, struct huft *, struct huft *,
+ int, int);
+static int INIT inflate_stored(struct iostate *);
+static int INIT inflate_fixed(struct iostate *);
+static int INIT inflate_dynamic(struct iostate *);
+static int INIT inflate_block(struct iostate *, int *);
+static int INIT inflate(struct iostate *);

/* The inflate algorithm uses a sliding 32 K byte window on the uncompressed
stream to find repeated byte strings. This is implemented here as a
@@ -145,7 +152,36 @@ static int INIT inflate(void);
"u8 *window;" and then malloc'ed in the latter case. The definition
must be in unzip.h, included above. */

-#define flush_output(w) (outcnt=(w),flush_window())
+static void flush_output(struct iostate *io)
+{
+ outcnt = io->opos;
+ flush_window();
+ io->opos = 0;
+}
+
+static inline void put_byte(struct iostate *io, u8 byte)
+{
+ io->window[io->opos++] = byte;
+ if (io->opos == io->osize)
+ flush_output(io);
+}
+
+static void copy_bytes(struct iostate *io, int len, int dist)
+{
+ int part, pos = io->opos - dist;
+
+ do {
+ pos &= io->osize - 1;
+ part = min(len, io->osize - max(pos, io->opos));
+ len -= part;
+
+ while (part--)
+ io->window[io->opos++] = io->window[pos++];
+
+ if (io->opos == io->osize)
+ flush_output(io);
+ } while (len);
+}

/* Tables for deflate from PKZIP's appnote.txt. */

@@ -186,10 +222,10 @@ static const u16 cpdext[] = {
/* Inlines for inflate() bit peeking and grabbing.
The usage is:

- x = readbits(&b, &k, j);
- dumpbits(&b, &k, j);
+ x = readbits(io, j);
+ dumpbits(io, j);

- x = pullbits(&b, &k, j);
+ x = pullbits(io, j);

where readbits makes sure that b has at least j bits in it, and
dumpbits removes the bits from b, while k tracks the number of bits
@@ -212,29 +248,32 @@ static const u16 cpdext[] = {
the stream.
*/

-static u32 bb; /* bit buffer */
-static unsigned bk; /* bits in bit buffer */
-
-static inline u32 readbits(u32 *b, u32 *k, int n)
+static inline u32 readbits(struct iostate *io, int n)
{
- for( ; *k < n; *k += 8)
- *b |= (u32)get_byte() << *k;
- return *b & ((1 << n) - 1);
+ for( ; io->bits < n; io->bits += 8)
+ io->buf |= (u32)get_byte() << io->bits;
+ return io->buf & ((1 << n) - 1);
}

-static inline void dumpbits(u32 *b, u32 *k, int n)
+static inline void dumpbits(struct iostate *io, int n)
{
- *b >>= n;
- *k -= n;
+ io->buf >>= n;
+ io->bits -= n;
}

-static inline u32 pullbits(u32 *b, u32 *k, int n)
+static inline u32 pullbits(struct iostate *io, int n)
{
- u32 r = readbits(b, k, n);
- dumpbits(b, k, n);
+ u32 r = readbits(io, n);
+ dumpbits(io, n);
return r;
}

+static inline void popbytes(struct iostate *io)
+{
+ inptr -= (io->bits >> 3);
+ io->bits &= 7;
+}
+
/*
Huffman code decoding is performed using a multi-level table lookup.
The fastest way to decode is to simply build a lookup table whose
@@ -536,6 +575,7 @@ STATIC int INIT huft_free(struct huft *t

/*
* inflate_codes - decompress the codes in a deflated block
+ * @io: current i/o state
* @tl: literal/length decoder tables
* @td: distance decoder tables
* @bl: number of bits decoded by tl
@@ -544,129 +584,75 @@ STATIC int INIT huft_free(struct huft *t
* inflate (decompress) the codes in a deflated (compressed) block.
* Return an error code or zero if it all goes ok.
*/
-static int inflate_codes(struct huft *tl, struct huft *td, int bl, int bd)
+static int INIT inflate_codes(struct iostate *io, struct huft *tl, struct huft *td,
+ int bl, int bd)
{
unsigned e; /* table entry flag/number of extra bits */
- unsigned n, d; /* length and index for copy */
- unsigned w; /* current window position */
+ unsigned len, dist;
struct huft *t; /* pointer to table entry */
- u32 b; /* bit buffer */
- unsigned k; /* number of bits in bit buffer */
-
- /* make local copies of globals */
- b = bb; /* initialize bit buffer */
- k = bk;
- w = outcnt; /* initialize window position */

/* inflate the coded data */
for (;;) { /* do until end of block */
- t = tl + readbits(&b, &k, bl);
+ t = tl + readbits(io, bl);
e = t->e;
while (e > 16) {
if (e == 99)
return 1;
- dumpbits(&b, &k, t->b);
- t = t->v.t + readbits(&b, &k, e - 16);
+ dumpbits(io, t->b);
+ t = t->v.t + readbits(io, e - 16);
e = t->e;
}
- dumpbits(&b, &k, t->b);
+ dumpbits(io, t->b);
if (e == 16) { /* then it's a literal */
- window[w++] = (u8)t->v.n;
- if (w == WSIZE) {
- flush_output(w);
- w = 0;
- }
+ put_byte(io, t->v.n);
} else { /* it's an EOB or a length */
/* exit if end of block */
if (e == 15)
break;

/* get length of block to copy */
- n = t->v.n + pullbits(&b, &k, e);
+ len = t->v.n + pullbits(io, e);

/* decode distance of block to copy */
- t = td + readbits(&b, &k, bd);
+ t = td + readbits(io, bd);
e = t->e;
while (e > 16) {
if (e == 99)
return 1;
- dumpbits(&b, &k, t->b);
- t = t->v.t + readbits(&b, &k, e - 16);
+ dumpbits(io, t->b);
+ t = t->v.t + readbits(io, e - 16);
e = t->e;
}
- dumpbits(&b, &k, t->b);
+ dumpbits(io, t->b);

- d = w - t->v.n - pullbits(&b, &k, e);
-
- /* do the copy */
- do {
- n -= (e = (e = WSIZE - ((d &= WSIZE - 1) > w ?
- d : w)) > n ? n : e);
-#if !defined(NOMEMCPY) && !defined(DEBUG)
- /* (this test assumes unsigned comparison) */
- if (w - d >= e) {
- memcpy(window + w, window + d, e);
- w += e;
- d += e;
- } else
-#endif /* !NOMEMCPY */
- /* avoid memcpy() overlap */
- do {
- window[w++] = window[d++];
- } while (--e);
- if (w == WSIZE) {
- flush_output(w);
- w = 0;
- }
- } while (n);
+ dist = t->v.n + pullbits(io, e);
+ copy_bytes(io, len, dist);
}
}

- /* restore the globals from the locals */
- outcnt = w; /* restore global window pointer */
- bb = b; /* restore global bit buffer */
- bk = k;
-
- /* done */
return 0;
}

-/* inflate_stored - "decompress" an inflated type 0 (stored) block. */
-static int INIT inflate_stored(void)
+/* inflate_stored - "decompress" an inflated type 0 (stored) block.
+ * @io: current i/o state
+ */
+static int INIT inflate_stored(struct iostate *io)
{
unsigned n; /* number of bytes in block */
- unsigned w; /* current window position */
- u32 b; /* bit buffer */
- unsigned k; /* number of bits in bit buffer */

DEBG("<stor");

- /* make local copies of globals */
- b = bb; /* initialize bit buffer */
- k = bk;
- w = outcnt; /* initialize window position */
-
/* go to byte boundary */
- dumpbits(&b, &k, k & 7);
+ dumpbits(io, io->bits & 7);

/* get the length and its complement */
- n = pullbits(&b, &k, 16);
- if (n != (~pullbits(&b, &k, 16) & 0xffff))
+ n = pullbits(io, 16);
+ if (n != (~pullbits(io, 16) & 0xffff))
return 1; /* error in compressed data */

/* read and output the compressed data */
- while (n--) {
- window[w++] = (u8)get_byte();
- if (w == WSIZE) {
- flush_output(w);
- w = 0;
- }
- }
-
- /* restore the globals from the locals */
- outcnt = w; /* restore global window pointer */
- bb = b; /* restore global bit buffer */
- bk = k;
+ while (n--)
+ put_byte(io, get_byte());

DEBG(">");
return 0;
@@ -674,6 +660,7 @@ static int INIT inflate_stored(void)


/* inflate_fixed - decompress a block with fixed Huffman codes
+ * @io: current i/o state
*
* decompress an inflated type 1 (fixed Huffman codes) block. We
* should either replace this with a custom decoder, or at least
@@ -681,7 +668,7 @@ static int INIT inflate_stored(void)
*
* We use `noinline' here to prevent gcc-3.5 from using too much stack space
*/
-static int noinline INIT inflate_fixed(void)
+static int noinline INIT inflate_fixed(struct iostate *io)
{
int i; /* temporary variable */
struct huft *tl; /* literal/length code table */
@@ -717,7 +704,7 @@ static int noinline INIT inflate_fixed(v
}

/* decompress until an end-of-block code */
- if (inflate_codes(tl, td, bl, bd))
+ if (inflate_codes(io, tl, td, bl, bd))
return 1;

/* free the decoding tables, return */
@@ -731,7 +718,7 @@ static int noinline INIT inflate_fixed(v
*
* We use `noinline' here to prevent gcc-3.5 from using too much stack space
*/
-static int noinline INIT inflate_dynamic(void)
+static int noinline INIT inflate_dynamic(struct iostate *io)
{
int i; /* temporary variables */
unsigned j;
@@ -745,19 +732,13 @@ static int noinline INIT inflate_dynamic
unsigned nl; /* number of literal/length codes */
unsigned nd; /* number of distance codes */
unsigned ll[286 + 30]; /* literal/length and distance code lengths */
- u32 b; /* bit buffer */
- unsigned k; /* number of bits in bit buffer */

DEBG("<dyn");

- /* make local bit buffer */
- b = bb;
- k = bk;
-
/* read in table lengths */
- nl = 257 + pullbits(&b, &k, 5); /* number of literal/length codes */
- nd = 1 + pullbits(&b, &k, 5); /* number of distance codes */
- nb = 4 + pullbits(&b, &k, 4); /* number of bit length codes */
+ nl = 257 + pullbits(io, 5); /* number of literal/length codes */
+ nd = 1 + pullbits(io, 5); /* number of distance codes */
+ nb = 4 + pullbits(io, 4); /* number of bit length codes */
if (nl > 286 || nd > 30)
return 1; /* bad lengths */

@@ -765,7 +746,7 @@ static int noinline INIT inflate_dynamic

/* read in bit-length-code lengths */
for (j = 0; j < nb; j++)
- ll[border[j]] = pullbits(&b, &k, 3);
+ ll[border[j]] = pullbits(io, 3);
for (; j < 19; j++)
ll[border[j]] = 0;

@@ -785,26 +766,26 @@ static int noinline INIT inflate_dynamic
n = nl + nd;
i = l = 0;
while ((unsigned)i < n) {
- td = tl + readbits(&b, &k, bl);
- dumpbits(&b, &k, td->b);
+ td = tl + readbits(io, bl);
+ dumpbits(io, td->b);
j = td->v.n;
if (j < 16) /* length of code in bits (0..15) */
ll[i++] = l = j; /* save last length in l */
else if (j == 16) { /* repeat last length 3 to 6 times */
- j = 3 + pullbits(&b, &k, 2);
+ j = 3 + pullbits(io, 2);
if ((unsigned)i + j > n)
return 1;
while (j--)
ll[i++] = l;
} else if (j == 17) { /* 3 to 10 zero length codes */
- j = 3 + pullbits(&b, &k, 3);
+ j = 3 + pullbits(io, 3);
if ((unsigned)i + j > n)
return 1;
while (j--)
ll[i++] = 0;
l = 0;
} else { /* j == 18: 11 to 138 zero length codes */
- j = 11 + pullbits(&b, &k, 7);
+ j = 11 + pullbits(io, 7);
if ((unsigned)i + j > n)
return 1;
while (j--)
@@ -820,10 +801,6 @@ static int noinline INIT inflate_dynamic

DEBG("dyn5 ");

- /* restore the global bit buffer */
- bb = b;
- bk = k;
-
DEBG("dyn5a ");

/* build the decoding tables for literal/length and distance codes */
@@ -851,7 +828,7 @@ static int noinline INIT inflate_dynamic
DEBG("dyn6 ");

/* decompress until an end-of-block code */
- if (inflate_codes(tl, td, bl, bd))
+ if (inflate_codes(io, tl, td, bl, bd))
return 1;

DEBG("dyn7 ");
@@ -865,24 +842,25 @@ static int noinline INIT inflate_dynamic
}

/* inflate_block - decompress a deflated block
+ * @io: current i/o state
* @e: last block flag
*/
-static int INIT inflate_block(int *e)
+static int INIT inflate_block(struct iostate *io, int *e)
{
unsigned t; /* block type */

DEBG("<blk");

- *e = pullbits(&bb, &bk, 1); /* read in last block bit */
- t = pullbits(&bb, &bk, 2); /* read in block type */
+ *e = pullbits(io, 1); /* read in last block bit */
+ t = pullbits(io, 2); /* read in block type */

/* inflate that block type */
if (t == 2)
- return inflate_dynamic();
+ return inflate_dynamic(io);
if (t == 0)
- return inflate_stored();
+ return inflate_stored(io);
if (t == 1)
- return inflate_fixed();
+ return inflate_fixed(io);

DEBG(">");

@@ -890,40 +868,27 @@ static int INIT inflate_block(int *e)
return 2;
}

-/* inflate - decompress an inflated entry */
-static int INIT inflate(void)
+/* inflate - decompress an inflated entry
+ * @io: current i/o state
+ */
+static int INIT inflate(struct iostate *io)
{
int e; /* last block flag */
int r; /* result code */
void *ptr;

- /* initialize window, bit buffer */
- outcnt = 0;
- bk = 0;
- bb = 0;
-
/* decompress until the last block */
do {
gzip_mark(&ptr);
- if ((r = inflate_block(&e))) {
+ if ((r = inflate_block(io, &e))) {
gzip_release(&ptr);
return r;
}
gzip_release(&ptr);
} while (!e);

- /* Undo too much lookahead. The next read will be byte aligned so we
- * can discard unused bits in the last meaningful byte.
- */
- while (bk >= 8) {
- bk -= 8;
- inptr--;
- }
-
- /* flush out window */
- flush_output(outcnt);
-
- /* return success */
+ popbytes(io);
+ flush_output(io);
return 0;
}

@@ -996,6 +961,11 @@ static int INIT gunzip(void)
u32 orig_crc = 0; /* original crc */
u32 orig_len = 0; /* original uncompressed length */
int res;
+ struct iostate io;
+
+ io.window = window;
+ io.osize = WSIZE;
+ io.opos = io.bits = io.buf = 0;

magic[0] = get_byte();
magic[1] = get_byte();
@@ -1051,7 +1021,7 @@ static int INIT gunzip(void)
;

/* Decompress */
- if ((res = inflate())) {
+ if ((res = inflate(&io))) {
switch (res) {
case 0:
break;

2005-10-31 21:03:00

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 11/20] inflate: (arch) kill get_byte

inflate: replace get_byte with readbyte

Each inflate user was providing a get_byte macro that hid the details
of tracking the input buffer. This is now handled with new variables
in the iostate structure and a callback (most users pass NULL as the
entire input is provided in a single buffer).

Signed-off-by: Matt Mackall <[email protected]>

Index: 2.6.14/arch/alpha/boot/misc.c
===================================================================
--- 2.6.14.orig/arch/alpha/boot/misc.c 2005-10-28 22:04:15.000000000 -0700
+++ 2.6.14/arch/alpha/boot/misc.c 2005-10-28 22:04:17.000000000 -0700
@@ -35,16 +35,9 @@ typedef unsigned long ulg;
#define WSIZE 0x8000 /* Window size must be at least 32k, */
/* and a power of two */

-static uch *inbuf; /* input buffer */
static uch *window; /* Sliding window buffer */
-
-static unsigned insize; /* valid bytes in inbuf */
-static unsigned inptr; /* index of next byte to be processed in inbuf */
static unsigned outcnt; /* bytes in output buffer */

-#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
-
-static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);

@@ -64,22 +57,6 @@ static ulg free_mem_ptr_end;
#include "../../../lib/inflate.c"

/* ===========================================================================
- * Fill the input buffer. This is called only when the buffer is empty
- * and at least one byte is really needed.
- */
-int fill_inbuf(void)
-{
- if (insize != 0)
- error("ran out of input data");
-
- inbuf = input_data;
- insize = input_data_size;
-
- inptr = 1;
- return inbuf[0];
-}
-
-/* ===========================================================================
* Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/
@@ -127,7 +104,7 @@ decompress_kernel(void *output_start,
window = malloc(WSIZE);

/* puts("Uncompressing Linux..."); */
- gunzip();
+ gunzip(input_data, input_data_size, NULL);
/* puts(" done, booting the kernel.\n"); */
return output_ptr;
}
Index: 2.6.14/arch/arm/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm/boot/compressed/misc.c 2005-10-28 22:04:15.000000000 -0700
+++ 2.6.14/arch/arm/boot/compressed/misc.c 2005-10-28 22:04:17.000000000 -0700
@@ -53,16 +53,9 @@ typedef unsigned long ulg;
#define WSIZE 0x8000 /* Window size must be at least 32k, */
/* and a power of two */

-static uch *inbuf; /* input buffer */
static uch window[WSIZE]; /* Sliding window buffer */
-
-static unsigned insize; /* valid bytes in inbuf */
-static unsigned inptr; /* index of next byte to be processed in inbuf */
static unsigned outcnt; /* bytes in output buffer */

-#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
-
-static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);

@@ -88,22 +81,6 @@ static ulg free_mem_ptr_end;
#endif

/* ===========================================================================
- * Fill the input buffer. This is called only when the buffer is empty
- * and at least one byte is really needed.
- */
-int fill_inbuf(void)
-{
- if (insize != 0)
- error("ran out of input data");
-
- inbuf = input_data;
- insize = &input_data_end[0] - &input_data[0];
-
- inptr = 1;
- return inbuf[0];
-}
-
-/* ===========================================================================
* Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/
@@ -146,7 +123,7 @@ decompress_kernel(ulg output_start, ulg
arch_decomp_setup();

putstr("Uncompressing Linux...");
- gunzip();
+ gunzip(input_data, input_data_end - input_data, NULL);
putstr(" done, booting the kernel.\n");
return output_ptr;
}
@@ -159,7 +136,7 @@ int main()
output_data = output_buffer;

putstr("Uncompressing Linux...");
- gunzip();
+ gunzip(input_data, input_data_end - input_data, NULL);
putstr("done.\n");
return 0;
}
Index: 2.6.14/arch/arm26/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm26/boot/compressed/misc.c 2005-10-28 22:04:15.000000000 -0700
+++ 2.6.14/arch/arm26/boot/compressed/misc.c 2005-10-28 22:04:17.000000000 -0700
@@ -38,16 +38,9 @@ typedef unsigned long ulg;
#define WSIZE 0x8000 /* Window size must be at least 32k, */
/* and a power of two */

-static uch *inbuf; /* input buffer */
static uch window[WSIZE]; /* Sliding window buffer */
-
-static unsigned insize; /* valid bytes in inbuf */
-static unsigned inptr; /* index of next byte to be processed in inbuf */
static unsigned outcnt; /* bytes in output buffer */

-#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
-
-static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);

@@ -73,22 +66,6 @@ static ulg free_mem_ptr_end;
#endif

/* ===========================================================================
- * Fill the input buffer. This is called only when the buffer is empty
- * and at least one byte is really needed.
- */
-int fill_inbuf(void)
-{
- if (insize != 0)
- error("ran out of input data");
-
- inbuf = input_data;
- insize = &input_data_end[0] - &input_data[0];
-
- inptr = 1;
- return inbuf[0];
-}
-
-/* ===========================================================================
* Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/
@@ -133,7 +110,7 @@ decompress_kernel(ulg output_start, ulg
arch_decomp_setup();

puts("Uncompressing Linux...");
- gunzip();
+ gunzip(input_data, input_data_end - input_data, NULL);
puts(" done, booting the kernel.\n");
return output_ptr;
}
@@ -146,7 +123,7 @@ int main()
output_data = output_buffer;

puts("Uncompressing Linux...");
- gunzip();
+ gunzip(input_data, input_data_end - input_data, NULL);
puts("done.\n");
return 0;
}
Index: 2.6.14/arch/cris/arch-v10/boot/compressed/head.S
===================================================================
--- 2.6.14.orig/arch/cris/arch-v10/boot/compressed/head.S 2005-10-28 22:01:13.000000000 -0700
+++ 2.6.14/arch/cris/arch-v10/boot/compressed/head.S 2005-10-28 22:04:17.000000000 -0700
@@ -104,7 +104,7 @@ basse: move.d pc, r5
;; when mounting from flash

move.d [_input_data], r9 ; flash address of compressed kernel
- add.d [_inptr], r9 ; size of compressed kernel
+ add.d [_compsize], r9 ; size of compressed kernel

;; Restore command line magic and address.
move.d _cmd_line_magic, $r10
Index: 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-28 22:04:15.000000000 -0700
+++ 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-28 22:04:17.000000000 -0700
@@ -35,19 +35,10 @@ typedef unsigned long ulg;
#define WSIZE 0x8000 /* Window size must be at least 32k, */
/* and a power of two */

-static uch *inbuf; /* input buffer */
static uch window[WSIZE]; /* Sliding window buffer */
-
-unsigned inptr = 0; /* index of next byte to be processed in inbuf
- * After decompression it will contain the
- * compressed size, and head.S will read it.
- */
-
+unsigned compsize; /* compressed size, used by head.S */
static unsigned outcnt = 0; /* bytes in output buffer */

-#define get_byte() inbuf[inptr++]
-
-static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);

@@ -172,6 +163,6 @@ decompress_kernel()
}

puts("Uncompressing Linux...\n");
- gunzip();
+ compsize = gunzip(input_data, 0x7fffffff, NULL);
puts("Done. Now booting the kernel.\n");
}
Index: 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-28 22:04:15.000000000 -0700
+++ 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-28 22:04:17.000000000 -0700
@@ -37,19 +37,9 @@ typedef unsigned long ulg;
#define WSIZE 0x8000 /* Window size must be at least 32k, */
/* and a power of two */

-static uch *inbuf; /* input buffer */
static uch window[WSIZE]; /* Sliding window buffer */
-
-unsigned inptr = 0; /* index of next byte to be processed in inbuf
- * After decompression it will contain the
- * compressed size, and head.S will read it.
- */
-
static unsigned outcnt = 0; /* bytes in output buffer */

-#define get_byte() inbuf[inptr++]
-
-static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);

@@ -217,6 +207,6 @@ decompress_kernel()
}

puts("Uncompressing Linux...\n");
- gunzip();
+ gunzip(input_data, 0x7fffffff, NULL);
puts("Done. Now booting the kernel.\n");
}
Index: 2.6.14/arch/i386/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/i386/boot/compressed/misc.c 2005-10-28 22:04:15.000000000 -0700
+++ 2.6.14/arch/i386/boot/compressed/misc.c 2005-10-28 22:04:17.000000000 -0700
@@ -30,16 +30,9 @@ typedef unsigned long ulg;
#define WSIZE 0x8000 /* Window size must be at least 32k, */
/* and a power of two */

-static uch *inbuf; /* input buffer */
static uch window[WSIZE]; /* Sliding window buffer */
-
-static unsigned insize = 0; /* valid bytes in inbuf */
-static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
static unsigned outcnt = 0; /* bytes in output buffer */

-#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
-
-static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);

@@ -134,22 +127,6 @@ static void putstr(const char *s)
}

/* ===========================================================================
- * Fill the input buffer. This is called only when the buffer is empty
- * and at least one byte is really needed.
- */
-static int fill_inbuf(void)
-{
- if (insize != 0) {
- error("ran out of input data");
- }
-
- inbuf = input_data;
- insize = input_len;
- inptr = 1;
- return inbuf[0];
-}
-
-/* ===========================================================================
* Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/
@@ -277,7 +254,7 @@ asmlinkage int decompress_kernel(struct
else setup_output_buffer_if_we_run_high(mv);

putstr("Uncompressing Linux... ");
- gunzip();
+ gunzip(input_data, input_len, NULL);
putstr("Ok, booting the kernel.\n");
if (high_loaded) close_output_buffer_if_we_run_high(mv);
return high_loaded;
Index: 2.6.14/arch/m32r/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/m32r/boot/compressed/misc.c 2005-10-28 22:04:15.000000000 -0700
+++ 2.6.14/arch/m32r/boot/compressed/misc.c 2005-10-28 22:04:17.000000000 -0700
@@ -24,16 +24,9 @@ typedef unsigned long ulg;
#define WSIZE 0x8000 /* Window size must be at least 32k, */
/* and a power of two */

-static uch *inbuf; /* input buffer */
static uch window[WSIZE]; /* Sliding window buffer */
-
-static unsigned insize = 0; /* valid bytes in inbuf */
-static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
static unsigned outcnt = 0; /* bytes in output buffer */

-#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
-
-static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);

@@ -54,22 +47,6 @@ static unsigned long free_mem_end_ptr;
#include "../../../../lib/inflate.c"

/* ===========================================================================
- * Fill the input buffer. This is called only when the buffer is empty
- * and at least one byte is really needed.
- */
-static int fill_inbuf(void)
-{
- if (insize != 0) {
- error("ran out of input data");
- }
-
- inbuf = input_data;
- insize = input_len;
- inptr = 1;
- return inbuf[0];
-}
-
-/* ===========================================================================
* Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/
@@ -110,6 +87,6 @@ decompress_kernel(int mmu_on, unsigned c
input_len = zimage_len;

puts("Uncompressing Linux... ");
- gunzip();
+ gunzip(input_data, input_len, NULL);
puts("Ok, booting the kernel.\n");
}
Index: 2.6.14/arch/sh/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh/boot/compressed/misc.c 2005-10-28 22:04:15.000000000 -0700
+++ 2.6.14/arch/sh/boot/compressed/misc.c 2005-10-28 22:04:17.000000000 -0700
@@ -26,16 +26,9 @@ typedef unsigned long ulg;
#define WSIZE 0x8000 /* Window size must be at least 32k, */
/* and a power of two */

-static uch *inbuf; /* input buffer */
static uch window[WSIZE]; /* Sliding window buffer */
-
-static unsigned insize = 0; /* valid bytes in inbuf */
-static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
static unsigned outcnt = 0; /* bytes in output buffer */

-#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
-
-static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);

@@ -82,22 +75,6 @@ int puts(const char *s)
#endif

/* ===========================================================================
- * Fill the input buffer. This is called only when the buffer is empty
- * and at least one byte is really needed.
- */
-static int fill_inbuf(void)
-{
- if (insize != 0) {
- error("ran out of input data");
- }
-
- inbuf = input_data;
- insize = input_len;
- inptr = 1;
- return inbuf[0];
-}
-
-/* ===========================================================================
* Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/
@@ -137,6 +114,6 @@ void decompress_kernel(void)
free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;

puts("Uncompressing Linux... ");
- gunzip();
+ gunzip(input_data, input_len, NULL);
puts("Ok, booting the kernel.\n");
}
Index: 2.6.14/arch/sh64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh64/boot/compressed/misc.c 2005-10-28 22:04:15.000000000 -0700
+++ 2.6.14/arch/sh64/boot/compressed/misc.c 2005-10-28 22:04:17.000000000 -0700
@@ -26,16 +26,9 @@ typedef unsigned long ulg;
#define WSIZE 0x8000 /* Window size must be at least 32k, */
/* and a power of two */

-static uch *inbuf; /* input buffer */
static uch window[WSIZE]; /* Sliding window buffer */
-
-static unsigned insize = 0; /* valid bytes in inbuf */
-static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
static unsigned outcnt = 0; /* bytes in output buffer */

-#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
-
-static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);

@@ -62,22 +55,6 @@ void puts(const char *s)
}

/* ===========================================================================
- * Fill the input buffer. This is called only when the buffer is empty
- * and at least one byte is really needed.
- */
-static int fill_inbuf(void)
-{
- if (insize != 0) {
- error("ran out of input data\n");
- }
-
- inbuf = input_data;
- insize = input_len;
- inptr = 1;
- return inbuf[0];
-}
-
-/* ===========================================================================
* Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/
@@ -118,7 +95,7 @@ void decompress_kernel(void)

puts("Uncompressing Linux... ");
cache_control(CACHE_ENABLE);
- gunzip();
+ gunzip(input_data, input_len, NULL);
puts("\n");

#if 0
Index: 2.6.14/arch/x86_64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/x86_64/boot/compressed/misc.c 2005-10-28 22:04:15.000000000 -0700
+++ 2.6.14/arch/x86_64/boot/compressed/misc.c 2005-10-28 22:04:17.000000000 -0700
@@ -23,16 +23,9 @@ typedef unsigned long ulg;
#define WSIZE 0x8000 /* Window size must be at least 32k, */
/* and a power of two */

-static uch *inbuf; /* input buffer */
static uch window[WSIZE]; /* Sliding window buffer */
-
-static unsigned insize = 0; /* valid bytes in inbuf */
-static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
static unsigned outcnt = 0; /* bytes in output buffer */

-#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
-
-static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);

@@ -123,22 +116,6 @@ static void putstr(const char *s)
}

/* ===========================================================================
- * Fill the input buffer. This is called only when the buffer is empty
- * and at least one byte is really needed.
- */
-static int fill_inbuf(void)
-{
- if (insize != 0) {
- error("ran out of input data");
- }
-
- inbuf = input_data;
- insize = input_len;
- inptr = 1;
- return inbuf[0];
-}
-
-/* ===========================================================================
* Write the output window window[0..outcnt-1] and update bytes_out.
* (Used for the decompressed data only.)
*/
@@ -255,7 +232,7 @@ int decompress_kernel(struct moveparams
else setup_output_buffer_if_we_run_high(mv);

putstr(".\nDecompressing Linux...");
- gunzip();
+ gunzip(input_data, input_len, NULL);
putstr("done.\nBooting the kernel.\n");
if (high_loaded) close_output_buffer_if_we_run_high(mv);
return high_loaded;
Index: 2.6.14/init/do_mounts_rd.c
===================================================================
--- 2.6.14.orig/init/do_mounts_rd.c 2005-10-28 22:04:15.000000000 -0700
+++ 2.6.14/init/do_mounts_rd.c 2005-10-28 22:04:17.000000000 -0700
@@ -283,20 +283,14 @@ typedef unsigned long ulg;

static uch *inbuf;
static uch *window;
-
-static unsigned insize; /* valid bytes in inbuf */
-static unsigned inptr; /* index of next byte to be processed in inbuf */
static unsigned outcnt; /* bytes in output buffer */
static int exit_code;
static int unzip_error;
static long bytes_out;
static int crd_infd, crd_outfd;

-#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
-
#define INIT __init

-static int __init fill_inbuf(void);
static void __init flush_window(void);
static void __init error(char *m);

@@ -304,24 +298,14 @@ static void __init error(char *m);

#include "../lib/inflate.c"

-/* ===========================================================================
+/*
* Fill the input buffer. This is called only when the buffer is empty
* and at least one byte is really needed.
- * Returning -1 does not guarantee that gunzip() will ever return.
*/
-static int __init fill_inbuf(void)
+static void __init fill_inbuf(u8 *buf, int len)
{
- if (exit_code) return -1;
-
- insize = sys_read(crd_infd, inbuf, INBUFSIZ);
- if (insize == 0) {
+ if (!sys_read(crd_infd, buf, len))
error("RAMDISK: ran out of compressed data");
- return -1;
- }
-
- inptr = 1;
-
- return inbuf[0];
}

/* ===========================================================================
@@ -358,8 +342,6 @@ static int __init crd_load(int in_fd, in
{
int result;

- insize = 0; /* valid bytes in inbuf */
- inptr = 0; /* index of next byte to be processed in inbuf */
outcnt = 0; /* bytes in output buffer */
exit_code = 0;
bytes_out = 0;
@@ -377,7 +359,7 @@ static int __init crd_load(int in_fd, in
kfree(inbuf);
return -1;
}
- result = gunzip();
+ result = gunzip(inbuf, INBUFSIZ, fill_inbuf);
if (unzip_error)
result = 1;
kfree(inbuf);
Index: 2.6.14/init/initramfs.c
===================================================================
--- 2.6.14.orig/init/initramfs.c 2005-10-28 22:04:15.000000000 -0700
+++ 2.6.14/init/initramfs.c 2005-10-28 22:04:17.000000000 -0700
@@ -340,16 +340,11 @@ typedef unsigned long ulg;
#define WSIZE 0x8000 /* window size--must be a power of two, and */
/* at least 32K for zip's deflate method */

-static uch *inbuf;
static uch *window;

-static unsigned insize; /* valid bytes in inbuf */
-static unsigned inptr; /* index of next byte to be processed in inbuf */
static unsigned outcnt; /* bytes in output buffer */
static long bytes_out;

-#define get_byte() (inptr < insize ? inbuf[inptr++] : -1)
-
#define INIT __init

static void __init flush_window(void);
@@ -379,7 +374,7 @@ static void __init flush_window(void)

static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only)
{
- int written;
+ int written, cnt;
dry_run = check_only;
header_buf = kmalloc(110, GFP_KERNEL);
symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL);
@@ -406,17 +401,14 @@ static char * __init unpack_to_rootfs(ch
continue;
}
this_header = 0;
- insize = len;
- inbuf = buf;
- inptr = 0;
outcnt = 0; /* bytes in output buffer */
bytes_out = 0;
- gunzip();
+ cnt = gunzip(buf, len, NULL);
if (state != Reset)
error("junk in gzipped archive");
- this_header = saved_offset + inptr;
- buf += inptr;
- len -= inptr;
+ this_header = saved_offset + cnt;
+ buf += cnt;
+ len -= cnt;
}
kfree(window);
kfree(name_buf);
Index: 2.6.14/lib/inflate.c
===================================================================
--- 2.6.14.orig/lib/inflate.c 2005-10-28 22:04:15.000000000 -0700
+++ 2.6.14/lib/inflate.c 2005-10-28 22:04:17.000000000 -0700
@@ -169,8 +169,9 @@ struct huft {
};

struct iostate {
- u8 *window;
- int opos, osize, bits;
+ u8 *window, *ibuf;
+ int ipos, isize, itotal, opos, osize, bits;
+ void (*fill)(u8 *ibuf, int len);
u32 buf, crc;
};

@@ -297,10 +298,21 @@ static const u16 cpdext[] = {
the stream.
*/

+static inline u32 readbyte(struct iostate *io)
+{
+ if (io->ipos == io->isize) {
+ io->fill(io->ibuf, io->isize);
+ io->itotal += io->ipos;
+ io->ipos = 0;
+ }
+
+ return io->ibuf[io->ipos++];
+}
+
static inline u32 readbits(struct iostate *io, int n)
{
for( ; io->bits < n; io->bits += 8)
- io->buf |= (u32)get_byte() << io->bits;
+ io->buf |= readbyte(io) << io->bits;
return io->buf & ((1 << n) - 1);
}

@@ -319,7 +331,7 @@ static inline u32 pullbits(struct iostat

static inline void popbytes(struct iostate *io)
{
- inptr -= (io->bits >> 3);
+ io->ipos -= (io->bits >> 3);
io->bits &= 7;
}

@@ -711,7 +723,7 @@ static int INIT inflate_stored(struct io

/* read and output the compressed data */
while (n--)
- put_byte(io, get_byte());
+ put_byte(io, readbyte(io));

DEBG(">");
return 0;
@@ -975,9 +987,12 @@ static void INIT makecrc(void)
#define RESERVED 0xC0 /* bit 6,7: reserved */

/*
- * Do the uncompression!
+ * gunzip - do the uncompression!
+ * @ibuf: input character pool
+ * @isize: size of pool
+ * @fill: function to fill the input pool
*/
-static int INIT gunzip(void)
+static int INIT gunzip(u8 *ibuf, int isize, void (*fill)(u8 *buf, int size))
{
u8 flags;
unsigned char magic[2]; /* magic header */
@@ -989,14 +1004,17 @@ static int INIT gunzip(void)

io.window = window;
io.osize = WSIZE;
- io.opos = io.bits = io.buf = 0;
+ io.opos = io.bits = io.buf = io.ipos = io.itotal = 0;
io.crc = 0xffffffffUL;
+ io.isize = isize;
+ io.ibuf = ibuf;
+ io.fill = fill;

makecrc(); /* initialize the CRC table */

- magic[0] = get_byte();
- magic[1] = get_byte();
- method = get_byte();
+ magic[0] = readbyte(&io);
+ magic[1] = readbyte(&io);
+ method = readbyte(&io);

if (magic[0] != 037 || ((magic[1] != 0213) && (magic[1] != 0236))) {
error("bad gzip magic numbers");
@@ -1009,7 +1027,7 @@ static int INIT gunzip(void)
return -1;
}

- flags = (u8)get_byte();
+ flags = readbyte(&io);
if (flags & ENCRYPTED) {
error("Input is encrypted");
return -1;
@@ -1022,29 +1040,29 @@ static int INIT gunzip(void)
error("Input has invalid flags");
return -1;
}
- get_byte(); /* Get timestamp */
- get_byte();
- get_byte();
- get_byte();
+ readbyte(&io); /* skip timestamp */
+ readbyte(&io);
+ readbyte(&io);
+ readbyte(&io);

- get_byte(); /* Ignore extra flags for the moment */
- get_byte(); /* Ignore OS type for the moment */
+ readbyte(&io); /* Ignore extra flags */
+ readbyte(&io); /* Ignore OS type */

if (flags & EXTRA_FIELD) {
- unsigned len = (unsigned)get_byte();
- len |= ((unsigned)get_byte()) << 8;
+ unsigned len = readbyte(&io);
+ len |= readbyte(&io) << 8;
while (len--)
- get_byte();
+ readbyte(&io);
}

/* Discard original file name if it was truncated */
if (flags & ORIG_NAME)
- while (get_byte())
+ while (readbyte(&io))
;

/* Discard file comment if any */
if (flags & COMMENT)
- while (get_byte())
+ while (readbyte(&io))
;

/* Decompress */
@@ -1073,15 +1091,15 @@ static int INIT gunzip(void)
/* Get the crc and original length
* uncompressed input size modulo 2^32
*/
- orig_crc = (u32)get_byte();
- orig_crc |= (u32)get_byte() << 8;
- orig_crc |= (u32)get_byte() << 16;
- orig_crc |= (u32)get_byte() << 24;
-
- orig_len = (u32)get_byte();
- orig_len |= (u32)get_byte() << 8;
- orig_len |= (u32)get_byte() << 16;
- orig_len |= (u32)get_byte() << 24;
+ orig_crc = readbyte(&io);
+ orig_crc |= readbyte(&io) << 8;
+ orig_crc |= readbyte(&io) << 16;
+ orig_crc |= readbyte(&io) << 24;
+
+ orig_len = readbyte(&io);
+ orig_len |= readbyte(&io) << 8;
+ orig_len |= readbyte(&io) << 16;
+ orig_len |= readbyte(&io) << 24;

/* Validate decompression */
if (orig_crc != ~io.crc) {
@@ -1092,5 +1110,6 @@ static int INIT gunzip(void)
error("length error");
return -1;
}
- return 0;
+
+ return io.itotal + io.ipos;
}

2005-10-31 21:04:32

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 6/20] inflate: internalize CRC calculation, cleanup table calculation

inflate: cleanup CRC calculation

Move CRC calculation into inflate code
Cleanup table calculation code

Signed-off-by: Matt Mackall <[email protected]>

Index: 2.6.14/lib/inflate.c
===================================================================
--- 2.6.14.orig/lib/inflate.c 2005-10-28 22:01:17.000000000 -0700
+++ 2.6.14/lib/inflate.c 2005-10-28 22:01:18.000000000 -0700
@@ -109,6 +109,10 @@

#include <asm/types.h>

+static u32 crc_32_tab[256];
+static u32 crc; /* dummy var until users get cleaned up */
+#define CRCPOLY_LE 0xedb88320
+
/* Huffman code lookup table entry--this entry is four bytes for machines
that have 16-bit pointers (e.g. PC's in the small or medium model).
Valid extra bits are 0..13. e == 15 is EOB (end of block), e == 16
@@ -128,7 +132,7 @@ struct huft {
struct iostate {
u8 *window;
int opos, osize, bits;
- u32 buf;
+ u32 buf, crc;
};

/* Function prototypes */
@@ -154,6 +158,12 @@ static int INIT inflate(struct iostate *

static void flush_output(struct iostate *io)
{
+ int i;
+
+ for (i = 0; i < io->opos; i++)
+ io->crc = crc_32_tab[(io->window[i] ^ (int)io->crc) & 0xff]
+ ^ (io->crc >> 8);
+
outcnt = io->opos;
flush_window();
io->opos = 0;
@@ -906,47 +916,16 @@ static int INIT inflate(struct iostate *
*
**********************************************************************/

-static u32 crc_32_tab[256];
-static u32 crc; /* initialized in makecrc() so it'll reside in bss */
-#define CRC_VALUE (crc ^ 0xffffffffUL)
-
-/*
- * Code to compute the CRC-32 table. Borrowed from
- * gzip-1.0.3/makecrc.c.
- * Not copyrighted 1990 Mark Adler
- */
-
static void INIT makecrc(void)
{
+ unsigned i, j;
+ u32 c = 1;

- unsigned long c; /* crc shift register */
- unsigned long e; /* polynomial exclusive-or pattern */
- int i; /* counter for all possible eight bit values */
- int k; /* byte being shifted into crc apparatus */
-
- /* terms of polynomial defining this crc (except x^32): */
- static const int p[] =
- { 0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26 };
-
- /* Make exclusive-or pattern from polynomial */
- e = 0;
- for (i = 0; i < sizeof(p) / sizeof(int); i++)
- e |= 1L << (31 - p[i]);
-
- crc_32_tab[0] = 0;
-
- for (i = 1; i < 256; i++) {
- c = 0;
- for (k = i | 256; k != 1; k >>= 1) {
- c = c & 1 ? (c >> 1) ^ e : c >> 1;
- if (k & 1)
- c ^= e;
- }
- crc_32_tab[i] = c;
+ for (i = 128; i; i >>= 1) {
+ c = (c >> 1) ^ ((c & 1) ? CRCPOLY_LE : 0);
+ for (j = 0; j < 256; j += 2 * i)
+ crc_32_tab[i + j] = c ^ crc_32_tab[j];
}
-
- /* this is initialized here so this code could reside in ROM */
- crc = 0xffffffffUL; /* shift register contents */
}

/* gzip flag byte */
@@ -966,14 +945,15 @@ static int INIT gunzip(void)
u8 flags;
unsigned char magic[2]; /* magic header */
char method;
- u32 orig_crc = 0; /* original crc */
- u32 orig_len = 0; /* original uncompressed length */
+ u32 orig_crc;
+ u32 orig_len;
int res;
struct iostate io;

io.window = window;
io.osize = WSIZE;
io.opos = io.bits = io.buf = 0;
+ io.crc = 0xffffffffUL;

magic[0] = get_byte();
magic[1] = get_byte();
@@ -1051,8 +1031,7 @@ static int INIT gunzip(void)
return -1;
}

- /* Get the crc and original length */
- /* crc32 (see algorithm.doc)
+ /* Get the crc and original length
* uncompressed input size modulo 2^32
*/
orig_crc = (u32)get_byte();
@@ -1066,7 +1045,7 @@ static int INIT gunzip(void)
orig_len |= (u32)get_byte() << 24;

/* Validate decompression */
- if (orig_crc != CRC_VALUE) {
+ if (orig_crc != ~io.crc) {
error("crc error");
return -1;
}

2005-10-31 21:02:24

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 19/20] inflate: (arch) use proper linking

inflate: remove include of lib/inflate.c and use proper linking

- make free_mem_ptr vars nonstatic
- make gunzip nonstatic
- add gunzip prototype to new inflate.h
- add per-arch Makefile bits
- change inflate.c includes to inflate.h includes
- change NO_INFLATE_MALLOC to CORE
- compile core kernel version of inflate with -DCORE

Signed-off-by: Matt Mackall <[email protected]>

Index: 2.6.14/arch/alpha/boot/misc.c
===================================================================
--- 2.6.14.orig/arch/alpha/boot/misc.c 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/arch/alpha/boot/misc.c 2005-10-30 13:07:25.000000000 -0800
@@ -14,6 +14,7 @@
*/

#include <linux/kernel.h>
+#include <linux/inflate.h>
#include <asm/uaccess.h>

#define puts srm_printk
@@ -27,11 +28,7 @@ static u8 *output_data;

#define HEAP_SIZE 0x2000

-/* gzip delarations */
-static u32 free_mem_ptr;
-static u32 free_mem_ptr_end;
-
-#include "../../../lib/inflate.c"
+static u32 free_mem_ptr, free_mem_ptr_end; /* for gunzip */

/* flush gunzip output window */
static void flush_window(const u8 *buf, int len)
Index: 2.6.14/arch/arm/boot/compressed/Makefile
===================================================================
--- 2.6.14.orig/arch/arm/boot/compressed/Makefile 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/arch/arm/boot/compressed/Makefile 2005-10-30 13:07:25.000000000 -0800
@@ -95,8 +95,11 @@ LDFLAGS_vmlinux += -p --no-undefined -X
# would otherwise mess up our GOT table
CFLAGS_misc.o := -Dstatic=

+$(obj)/inflate.o: lib/inflate.c
+ $(call cmd,cc_o_c)
+
$(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/$(HEAD) $(obj)/piggy.o \
- $(addprefix $(obj)/, $(OBJS)) FORCE
+ $(addprefix $(obj)/, $(OBJS)) $(obj)/inflate.o FORCE
$(call if_changed,ld)
@:

Index: 2.6.14/arch/arm/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm/boot/compressed/misc.c 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/arch/arm/boot/compressed/misc.c 2005-10-30 13:07:25.000000000 -0800
@@ -14,6 +14,7 @@
unsigned int __machine_arch_type;

#include <linux/string.h>
+#include <linux/inflate.h>
#include <asm/arch/uncompress.h>

#ifdef STANDALONE_DEBUG
@@ -36,31 +37,17 @@ icedcc_putstr(const char *ptr)

#endif

-#define __ptr_t void *
-
-/*
- * gzip declarations
- */
-
extern char input_data[];
extern char input_data_end[];
+extern int end;

static u8 *output_data;
-
static void putstr(const char *);

-extern int end;
-static u32 free_mem_ptr;
-static u32 free_mem_ptr_end;
+u32 free_mem_ptr, free_mem_ptr_end; /* for gunzip */

#define HEAP_SIZE 0x2000

-#include "../../../../lib/inflate.c"
-
-#ifdef STANDALONE_DEBUG
-#define NO_INFLATE_MALLOC
-#endif
-
/* flush gunzip output window */
static void flush_window(const u8 *buf, int len)
{
Index: 2.6.14/arch/arm26/boot/compressed/Makefile
===================================================================
--- 2.6.14.orig/arch/arm26/boot/compressed/Makefile 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/arch/arm26/boot/compressed/Makefile 2005-10-30 13:07:25.000000000 -0800
@@ -8,7 +8,7 @@
#

HEAD = head.o
-OBJS = misc.o
+OBJS = misc.o inflate.o
FONTC = drivers/video/console/font_acorn_8x8.c

OBJS += ll_char_wr.o font.o
@@ -40,11 +40,14 @@ LDFLAGS_piggy.o := -r -b binary
$(obj)/piggy.o: $(obj)/piggy.gz FORCE
$(call if_changed,ld)

+$(obj)/inflate.o: lib/inflate.c
+ $(call cmd,cc_o_c)
+
$(obj)/font.o: $(FONTC)
$(CC) $(CFLAGS) -Dstatic= -c $(FONTC) -o $(obj)/font.o

$(obj)/vmlinux.lds: $(obj)/vmlinux.lds.in Makefile arch/arm26/boot/Makefile .config
@sed "$(SEDFLAGS)" < $< > $@

-$(obj)/misc.o: $(obj)/misc.c $(obj)/uncompress.h lib/inflate.c
+$(obj)/misc.o: $(obj)/misc.c $(obj)/uncompress.h

Index: 2.6.14/arch/arm26/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm26/boot/compressed/misc.c 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/arch/arm26/boot/compressed/misc.c 2005-10-30 13:07:25.000000000 -0800
@@ -14,6 +14,7 @@
unsigned int __machine_arch_type;

#include <linux/kernel.h>
+#include <linux/inflate.h>
#include <asm/uaccess.h>
#include "uncompress.h"

@@ -30,15 +31,7 @@ static void puts(const char *);

#define HEAP_SIZE 0x2000

-/* gzip delarations */
-static u32 free_mem_ptr;
-static u32 free_mem_ptr_end;
-
-#include "../../../../lib/inflate.c"
-
-#ifdef STANDALONE_DEBUG
-#define NO_INFLATE_MALLOC
-#endif
+u32 free_mem_ptr, free_mem_ptr_end; /* for gunzip */

/* flush the gunzip output window */
static void flush_window(const u8 *buf, int len)
Index: 2.6.14/arch/cris/arch-v10/boot/compressed/Makefile
===================================================================
--- 2.6.14.orig/arch/cris/arch-v10/boot/compressed/Makefile 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/arch/cris/arch-v10/boot/compressed/Makefile 2005-10-30 13:07:25.000000000 -0800
@@ -9,7 +9,7 @@ CFLAGS = -O2
LD = ld-cris
OBJCOPY = objcopy-cris
OBJCOPYFLAGS = -O binary --remove-section=.bss
-OBJECTS = $(target)/head.o $(target)/misc.o
+OBJECTS = $(target)/head.o $(target)/misc.o $(target)/inflate.o

# files to compress
SYSTEM = $(objtree)/vmlinux.bin
@@ -29,6 +29,9 @@ $(target_compressed_dir)/vmlinuz: $(targ
$(target)/head.o: $(src)/head.S
$(CC) -D__ASSEMBLY__ -traditional -c $< -o $@

+$(target)/inflate.o: lib/inflate.c
+ $(CC) -D__KERNEL__ -c $< -o $@
+
$(target)/misc.o: $(src)/misc.c
$(CC) -D__KERNEL__ -c $< -o $@

Index: 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-30 13:07:25.000000000 -0800
@@ -16,6 +16,7 @@

#include <linux/config.h>
#include <linux/types.h>
+#include <linux/inflate.h>
#include <asm/arch/svinto.h>

extern int end; /* the "heap" is put directly after the BSS ends, at end */
@@ -25,11 +26,8 @@ static u8 *output_data;

static void puts(const char *);

-/* gzip declarations */
-static long free_mem_ptr = (long)&end;
-static long free_mem_end_ptr = 0xffffffff;
-
-#include "../../../../../lib/inflate.c"
+/* for gunzip */
+long free_mem_ptr = (long)&end, free_mem_end_ptr = 0xffffffff;

/* decompressor info and error messages to serial console */

Index: 2.6.14/arch/cris/arch-v32/boot/compressed/Makefile
===================================================================
--- 2.6.14.orig/arch/cris/arch-v32/boot/compressed/Makefile 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/arch/cris/arch-v32/boot/compressed/Makefile 2005-10-30 13:07:25.000000000 -0800
@@ -12,7 +12,7 @@ CFLAGS = -O2
LD = gcc-cris -mlinux -march=v32 -nostdlib
OBJCOPY = objcopy-cris
OBJCOPYFLAGS = -O binary --remove-section=.bss
-OBJECTS = $(target)/head.o $(target)/misc.o
+OBJECTS = $(target)/head.o $(target)/misc.o $(target)/inflate.o

# files to compress
SYSTEM = $(objtree)/vmlinux.bin
@@ -28,6 +28,9 @@ $(objtree)/vmlinuz: $(target) piggy.img
rm -f piggy.img
cp $(objtree)/vmlinuz $(src)

+$(target)/inflate.o: lib/inflate.c
+ $(call cmd,cc_o_c)
+
$(target)/head.o: $(src)/head.S
$(CC) -D__ASSEMBLY__ -c $< -o $@

Index: 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-30 13:07:25.000000000 -0800
@@ -16,6 +16,7 @@

#include <linux/config.h>
#include <linux/types.h>
+#include <linux/inflate.h>
#include <asm/arch/hwregs/reg_rdwr.h>
#include <asm/arch/hwregs/reg_map.h>
#include <asm/arch/hwregs/ser_defs.h>
@@ -26,11 +27,8 @@ static u8 *output_data;

static void puts(const char *);

-/* gzip declarations */
-static long free_mem_ptr = (long)&_end;
-static long free_mem_end_ptr = 0xffffffff;
-
-#include "../../../../../lib/inflate.c"
+/* for gunzip */
+long free_mem_ptr = (long)&_end, free_mem_end_ptr = 0xffffffff;

/* decompressor info and error messages to serial console */

Index: 2.6.14/arch/i386/boot/compressed/Makefile
===================================================================
--- 2.6.14.orig/arch/i386/boot/compressed/Makefile 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/arch/i386/boot/compressed/Makefile 2005-10-30 13:07:25.000000000 -0800
@@ -9,7 +9,11 @@ EXTRA_AFLAGS := -traditional

LDFLAGS_vmlinux := -Ttext $(IMAGE_OFFSET) -e startup_32

-$(obj)/vmlinux: $(obj)/head.o $(obj)/misc.o $(obj)/piggy.o FORCE
+$(obj)/inflate.o: lib/inflate.c
+ $(call cmd,cc_o_c)
+
+$(obj)/vmlinux: $(obj)/head.o $(obj)/misc.o $(obj)/piggy.o $(obj)/inflate.o \
+ FORCE
$(call if_changed,ld)
@:

Index: 2.6.14/arch/i386/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/i386/boot/compressed/misc.c 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/arch/i386/boot/compressed/misc.c 2005-10-30 13:07:25.000000000 -0800
@@ -8,6 +8,7 @@
#include <linux/linkage.h>
#include <linux/vmalloc.h>
#include <linux/tty.h>
+#include <linux/inflate.h>
#include <asm/io.h>
#include <asm/page.h>

@@ -46,11 +47,7 @@ static int lines, cols;
static void * xquad_portio = NULL;
#endif

-/* gzip declarations */
-static long free_mem_ptr = (long)&end;
-static long free_mem_end_ptr;
-
-#include "../../../../lib/inflate.c"
+long free_mem_ptr = (long)&end, free_mem_end_ptr; /* for gunzip */

static void scroll(void)
{
Index: 2.6.14/arch/m32r/boot/compressed/Makefile
===================================================================
--- 2.6.14.orig/arch/m32r/boot/compressed/Makefile 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/arch/m32r/boot/compressed/Makefile 2005-10-30 13:07:25.000000000 -0800
@@ -18,7 +18,11 @@ OBJECTS = $(obj)/head.o $(obj)/misc.o

LDFLAGS_vmlinux := -T

-$(obj)/vmlinux: $(obj)/vmlinux.lds $(OBJECTS) $(obj)/piggy.o FORCE
+$(obj)/inflate.o: lib/inflate.c
+ $(call cmd,cc_o_c)
+
+$(obj)/vmlinux: $(obj)/vmlinux.lds $(OBJECTS) $(obj)/piggy.o $(obj)/inflate.o \
+ FORCE
$(call if_changed,ld)
@:

Index: 2.6.14/arch/m32r/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/m32r/boot/compressed/misc.c 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/arch/m32r/boot/compressed/misc.c 2005-10-30 13:07:25.000000000 -0800
@@ -9,6 +9,7 @@

#include <linux/config.h>
#include <linux/string.h>
+#include <linux/inflate.h>

static unsigned char *input_data;
static int input_len;
@@ -18,11 +19,7 @@ static u8 *output_data;

#define HEAP_SIZE 0x10000

-/* gzip declarations */
-static unsigned long free_mem_ptr;
-static unsigned long free_mem_end_ptr;
-
-#include "../../../../lib/inflate.c"
+unsigned long free_mem_ptr, free_mem_end_ptr; /* for gunzip */

/* flush the gunzip output buffer */
static void flush_window(const u8 *buf, int len)
Index: 2.6.14/arch/sh/boot/compressed/Makefile
===================================================================
--- 2.6.14.orig/arch/sh/boot/compressed/Makefile 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/arch/sh/boot/compressed/Makefile 2005-10-30 13:07:25.000000000 -0800
@@ -24,7 +24,10 @@ IMAGE_OFFSET := $(shell printf "0x%8x" $

LDFLAGS_vmlinux := -Ttext $(IMAGE_OFFSET) -e startup -T $(obj)/../../kernel/vmlinux.lds

-$(obj)/vmlinux: $(OBJECTS) $(obj)/piggy.o FORCE
+$(obj)/inflate.o: lib/inflate.c
+ $(call cmd,cc_o_c)
+
+$(obj)/vmlinux: $(OBJECTS) $(obj)/piggy.o $(obj)/inflate.o FORCE
$(call if_changed,ld)
@:

Index: 2.6.14/arch/sh/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh/boot/compressed/misc.c 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/arch/sh/boot/compressed/misc.c 2005-10-30 13:07:59.000000000 -0800
@@ -7,6 +7,7 @@
*/

#include <linux/config.h>
+#include <linux/inflate.h>
#include <asm/uaccess.h>
#ifdef CONFIG_SH_STANDARD_BIOS
#include <asm/sh_bios.h>
@@ -22,11 +23,7 @@ int puts(const char *);

#define HEAP_SIZE 0x10000

-/* gzip declarations */
-static unsigned long free_mem_ptr;
-static unsigned long free_mem_end_ptr;
-
-#include "../../../../lib/inflate.c"
+unsigned long free_mem_ptr, free_mem_end_ptr; /* for gunzip */

#ifdef CONFIG_SH_STANDARD_BIOS
size_t strlen(const char *s)
Index: 2.6.14/arch/sh64/boot/compressed/Makefile
===================================================================
--- 2.6.14.orig/arch/sh64/boot/compressed/Makefile 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/arch/sh64/boot/compressed/Makefile 2005-10-30 13:07:25.000000000 -0800
@@ -28,7 +28,10 @@ LDFLAGS_vmlinux := -Ttext $(ZIMAGE_OFFSE
-T $(obj)/../../kernel/vmlinux.lds \
--no-warn-mismatch

-$(obj)/vmlinux: $(OBJECTS) $(obj)/piggy.o FORCE
+$(obj)/inflate.o: lib/inflate.c
+ $(call cmd,cc_o_c)
+
+$(obj)/vmlinux: $(OBJECTS) $(obj)/piggy.o $(obj)/inflate.o FORCE
$(call if_changed,ld)
@:

Index: 2.6.14/arch/sh64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh64/boot/compressed/misc.c 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/arch/sh64/boot/compressed/misc.c 2005-10-30 13:07:25.000000000 -0800
@@ -5,6 +5,7 @@
*/

#include <linux/config.h>
+#include <linux/inflate.h>
#include <asm/uaccess.h>

/* cache.c */
@@ -22,11 +23,7 @@ static void puts(const char *);

#define HEAP_SIZE 0x10000

-/* gzip declarations */
-static unsigned long free_mem_ptr;
-static unsigned long free_mem_end_ptr;
-
-#include "../../../../lib/inflate.c"
+unsigned long free_mem_ptr, free_mem_end_ptr; /* for gunzip */

void puts(const char *s)
{
Index: 2.6.14/arch/x86_64/boot/compressed/Makefile
===================================================================
--- 2.6.14.orig/arch/x86_64/boot/compressed/Makefile 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/arch/x86_64/boot/compressed/Makefile 2005-10-30 13:07:25.000000000 -0800
@@ -16,7 +16,11 @@ LDFLAGS := -m elf_i386

LDFLAGS_vmlinux := -Ttext $(IMAGE_OFFSET) -e startup_32 -m elf_i386

-$(obj)/vmlinux: $(obj)/head.o $(obj)/misc.o $(obj)/piggy.o FORCE
+$(obj)/inflate.o: lib/inflate.c
+ $(call cmd,cc_o_c)
+
+$(obj)/vmlinux: $(obj)/head.o $(obj)/misc.o $(obj)/piggy.o $(obj)/inflate.o \
+ FORCE
$(call if_changed,ld)
@:

Index: 2.6.14/arch/x86_64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/x86_64/boot/compressed/misc.c 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/arch/x86_64/boot/compressed/misc.c 2005-10-30 13:07:25.000000000 -0800
@@ -6,6 +6,7 @@
*/

#include "miscsetup.h"
+#include <linux/inflate.h>
#include <asm/io.h>
#include <asm/page.h>

@@ -39,11 +40,7 @@ static char *vidmem = (char *)0xb8000;
static int vidport;
static int lines, cols;

-/* gzip declarations */
-static long free_mem_ptr = (long)&end;
-static long free_mem_end_ptr;
-
-#include "../../../../lib/inflate.c"
+long free_mem_ptr = (long)&end, free_mem_end_ptr; /* for gunzip */

static void scroll(void)
{
Index: 2.6.14/include/linux/inflate.h
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ 2.6.14/include/linux/inflate.h 2005-10-30 13:07:25.000000000 -0800
@@ -0,0 +1,9 @@
+#ifndef _LINUX_INFLATE_H
+#define _LINUX_INFLATE_H
+
+int gunzip(u8 *ibuf, int isize, void (*fill)(u8 *buf, int size),
+ void (*flush)(const u8 *buf, int size),
+ void (*error)(const char *msg));
+
+#endif /* _LINUX_INFLATE_H */
+
Index: 2.6.14/init/do_mounts_rd.c
===================================================================
--- 2.6.14.orig/init/do_mounts_rd.c 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/init/do_mounts_rd.c 2005-10-30 13:07:25.000000000 -0800
@@ -1,4 +1,3 @@
-
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/minix_fs.h>
@@ -7,6 +6,7 @@
#include <linux/cramfs_fs.h>
#include <linux/initrd.h>
#include <linux/string.h>
+#include <linux/inflate.h>

#include "do_mounts.h"

@@ -269,13 +269,6 @@ int __init rd_load_disk(int n)

#ifdef BUILD_CRAMDISK

-/* gzip declarations */
-#define INIT __init
-#define INITDATA __initdata
-#define NO_INFLATE_MALLOC
-
-#include "../lib/inflate.c"
-
#define INBUFSIZ 4096
static u8 *inbuf;
static int exit_code;
Index: 2.6.14/init/initramfs.c
===================================================================
--- 2.6.14.orig/init/initramfs.c 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/init/initramfs.c 2005-10-30 13:07:25.000000000 -0800
@@ -6,6 +6,7 @@
#include <linux/delay.h>
#include <linux/string.h>
#include <linux/syscalls.h>
+#include <linux/inflate.h>

static __initdata const char *message;
static void __init error(const char *x)
@@ -329,14 +330,6 @@ static void __init flush_buffer(const u8
}
}

-/* gzip declarations */
-
-#define INIT __init
-#define INITDATA __initdata
-#define NO_INFLATE_MALLOC
-
-#include "../lib/inflate.c"
-
static const char * __init unpack_to_rootfs(char *buf, unsigned len,
int check_only)
{
Index: 2.6.14/lib/Makefile
===================================================================
--- 2.6.14.orig/lib/Makefile 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/lib/Makefile 2005-10-30 13:07:25.000000000 -0800
@@ -5,12 +5,14 @@
lib-y := errno.o ctype.o string.o vsprintf.o cmdline.o \
bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \
idr.o div64.o int_sqrt.o bitmap.o extable.o prio_tree.o \
- sha1.o
+ sha1.o inflate.o

lib-y += kobject.o kref.o kobject_uevent.o klist.o

obj-y += sort.o parser.o halfmd4.o

+CFLAGS_inflate.o += -DCORE
+
ifeq ($(CONFIG_DEBUG_KOBJECT),y)
CFLAGS_kobject.o += -DDEBUG
CFLAGS_kobject_uevent.o += -DDEBUG
Index: 2.6.14/lib/inflate.c
===================================================================
--- 2.6.14.orig/lib/inflate.c 2005-10-30 13:07:19.000000000 -0800
+++ 2.6.14/lib/inflate.c 2005-10-30 13:07:25.000000000 -0800
@@ -99,22 +99,19 @@
a repeat code (16, 17, or 18) to go across the boundary between
the two sets of lengths.
*/
+#include <linux/kernel.h>
#include <linux/compiler.h>
+#include <asm/types.h>

-#ifndef INIT
+#ifndef CORE
#define INIT
-#endif
-#ifndef INITDATA
#define INITDATA
-#endif
-
-#include <asm/types.h>

-#ifndef NO_INFLATE_MALLOC
/* A trivial malloc implementation, adapted from
* malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
*/

+extern long free_mem_ptr, free_mem_end_ptr;
static unsigned long malloc_ptr;
static int malloc_count;

@@ -148,10 +145,17 @@ static void free(void *where)
}

static u8 INITDATA window[0x8000]; /* use a statically allocated window */
+
#else
+
+#include <linux/module.h>
+
static u8 *window; /* dynamically allocate */
#define malloc(a) kmalloc(a, GFP_KERNEL)
#define free(a) kfree(a)
+#define INIT __init
+#define INITDATA __initdata
+
#endif

static u32 crc_32_tab[256];
@@ -937,9 +941,9 @@ static void INIT makecrc(void)
* @flush: function to flush the output pool
* @error: function to report an error
*/
-static int INIT gunzip(u8 *ibuf, int isize, void (*fill)(u8 *buf, int size),
- void (*flush)(const u8 *buf, int size),
- void (*error)(const char *msg))
+int INIT gunzip(u8 *ibuf, int isize, void (*fill)(u8 *buf, int size),
+ void (*flush)(const u8 *buf, int size),
+ void (*error)(const char *msg))
{
u8 flags;
unsigned char magic[2]; /* magic header */

2005-10-31 21:04:37

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 16/20] inflate: remove legacy DEBG macros

inflate: remove legacy DEBG macros

Signed-off-by: Matt Mackall <[email protected]>

Index: 2.6.14/lib/inflate.c
===================================================================
--- 2.6.14.orig/lib/inflate.c 2005-10-28 22:04:23.000000000 -0700
+++ 2.6.14/lib/inflate.c 2005-10-28 22:04:27.000000000 -0700
@@ -1,5 +1,3 @@
-#define DEBG(x)
-#define DEBG1(x)
/* inflate.c -- Not copyrighted 1992 by Mark Adler
* version c10p1, 10 January 1993
*
@@ -416,8 +414,6 @@ static int INIT huft_build(unsigned *b,
int y; /* number of dummy codes added */
unsigned z; /* number of entries in current table */

- DEBG("huft1 ");
-
for (i = 0; i < BMAX + 1; i++)
c[i] = 0;

@@ -435,8 +431,6 @@ static int INIT huft_build(unsigned *b,
return 2;
}

- DEBG("huft2 ");
-
/* Find minimum and maximum length, bound *m by those */
l = *m;
for (j = 1; j <= BMAX; j++)
@@ -455,8 +449,6 @@ static int INIT huft_build(unsigned *b,
l = i;
*m = l;

- DEBG("huft3 ");
-
/* Adjust last length count to fill out codes, if needed */
for (y = 1 << j; j < i; j++, y <<= 1) {
y -= c[j];
@@ -469,8 +461,6 @@ static int INIT huft_build(unsigned *b,
return 2;
c[i] += y;

- DEBG("huft4 ");
-
/* Generate starting offsets into the value table for each length */
x[1] = j = 0;
p = c + 1;
@@ -483,8 +473,6 @@ static int INIT huft_build(unsigned *b,
xp++;
}

- DEBG("huft5 ");
-
/* Make a table of values in order of bit lengths */
p = b;
i = 0;
@@ -496,8 +484,6 @@ static int INIT huft_build(unsigned *b,

n = x[g]; /* set n to length of v */

- DEBG("h6 ");
-
/* Generate the Huffman codes and for each, make the table entries */
x[0] = i = 0; /* first Huffman code is zero */
p = v; /* grab values in bit order */
@@ -506,18 +492,14 @@ static int INIT huft_build(unsigned *b,
u[0] = NULL; /* just to keep compilers happy */
q = NULL; /* ditto */
z = 0; /* ditto */
- DEBG("h6a ");

/* go through the bit lengths (k already is bits in shortest code) */
for (; k <= g; k++) {
- DEBG("h6b ");
a = c[k];
while (a--) {
- DEBG("h6b1 ");
/* i is the Huffman code of length k for value *p */
/* make tables up to required level */
while (k > w + l) {
- DEBG1("1 ");
h++;
w += l; /* previous table always l bits */

@@ -530,7 +512,6 @@ static int INIT huft_build(unsigned *b,
f = 1 << j;
if (f > a + 1) {
/* too few codes for k-w bit table */
- DEBG1("2 ");
/* deduct codes from patterns left */
f -= a + 1;
xp = c + k;
@@ -547,7 +528,6 @@ static int INIT huft_build(unsigned *b,
}
}

- DEBG1("3 ");
/* table entries for j-bit table */
z = 1 << j;

@@ -559,13 +539,11 @@ static int INIT huft_build(unsigned *b,
return 3; /* not enough memory */
}

- DEBG1("4 ");
*t = q + 1; /* link to list for huft_free */
t = &q->next;
*t = NULL;
u[h] = ++q; /* table starts after link */

- DEBG1("5 ");
/* connect to last table, if there is one */
if (h) {
/* save pattern for backing up */
@@ -581,9 +559,7 @@ static int INIT huft_build(unsigned *b,
/* connect to last table */
u[h - 1][j] = r;
}
- DEBG1("6 ");
}
- DEBG("h6c ");

/* set up table entry in r */
r.bits = (u8)(k - w);
@@ -601,7 +577,6 @@ static int INIT huft_build(unsigned *b,
r.extra = (u8)e[*p - s];
r.val = d[*p++ - s];
}
- DEBG("h6d ");

/* fill code-like entries with r */
f = 1 << (k - w);
@@ -618,13 +593,9 @@ static int INIT huft_build(unsigned *b,
h--; /* don't need to update q */
w -= l;
}
- DEBG("h6e ");
}
- DEBG("h6f ");
}

- DEBG("huft7 ");
-
/* Return true (1) if we were given an incomplete table */
return y && g != 1;
}
@@ -713,8 +684,6 @@ static int INIT inflate_stored(struct io
{
unsigned n; /* number of bytes in block */

- DEBG("<stor");
-
/* go to byte boundary */
dumpbits(io, io->bits & 7);

@@ -727,7 +696,6 @@ static int INIT inflate_stored(struct io
while (n--)
put_byte(io, readbyte(io));

- DEBG(">");
return 0;
}

@@ -750,8 +718,6 @@ static int noinline INIT inflate_fixed(s
int bd; /* lookup bits for td */
unsigned l[N_MAX]; /* length list for huft_build */

- DEBG("<fix");
-
/* set up literal table */
for (i = 0; i < 144; i++)
l[i] = 8;
@@ -772,7 +738,6 @@ static int noinline INIT inflate_fixed(s
if ((i = huft_build(l, 30, 0, cpdist, cpdext, &td, &bd)) > 1) {
huft_free(tl);

- DEBG(">");
return i;
}

@@ -806,8 +771,6 @@ static int noinline INIT inflate_dynamic
unsigned nd; /* number of distance codes */
unsigned ll[286 + 30]; /* literal/length and distance code lengths */

- DEBG("<dyn");
-
/* read in table lengths */
nl = 257 + pullbits(io, 5); /* number of literal/length codes */
nd = 1 + pullbits(io, 5); /* number of distance codes */
@@ -815,16 +778,12 @@ static int noinline INIT inflate_dynamic
if (nl > 286 || nd > 30)
return 1; /* bad lengths */

- DEBG("dyn1 ");
-
/* read in bit-length-code lengths */
for (j = 0; j < nb; j++)
ll[border[j]] = pullbits(io, 3);
for (; j < 19; j++)
ll[border[j]] = 0;

- DEBG("dyn2 ");
-
/* build decoding table for trees--single level, 7 bit lookup */
bl = 7;
if ((i = huft_build(ll, 19, 19, 0, 0, &tl, &bl))) {
@@ -833,8 +792,6 @@ static int noinline INIT inflate_dynamic
return i; /* incomplete code set */
}

- DEBG("dyn3 ");
-
/* read in literal and distance code lengths */
n = nl + nd;
i = l = 0;
@@ -867,29 +824,21 @@ static int noinline INIT inflate_dynamic
}
}

- DEBG("dyn4 ");
-
/* free decoding table for trees */
huft_free(tl);

- DEBG("dyn5 ");
-
- DEBG("dyn5a ");
-
/* build the decoding tables for literal/length and distance codes */
bl = lbits;
if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl))) {
- DEBG("dyn5b ");
if (i == 1) {
io->error("incomplete literal tree");
huft_free(tl);
}
return i; /* incomplete code set */
}
- DEBG("dyn5c ");
+
bd = dbits;
if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd))) {
- DEBG("dyn5d ");
if (i == 1) {
io->error("incomplete distance tree");
huft_free(td);
@@ -898,19 +847,14 @@ static int noinline INIT inflate_dynamic
return i; /* incomplete code set */
}

- DEBG("dyn6 ");
-
/* decompress until an end-of-block code */
if (inflate_codes(io, tl, td, bl, bd))
return 1;

- DEBG("dyn7 ");
-
/* free the decoding tables, return */
huft_free(tl);
huft_free(td);

- DEBG(">");
return 0;
}

@@ -922,8 +866,6 @@ static int INIT inflate_block(struct ios
{
unsigned t; /* block type */

- DEBG("<blk");
-
*e = pullbits(io, 1); /* read in last block bit */
t = pullbits(io, 2); /* read in block type */

@@ -935,8 +877,6 @@ static int INIT inflate_block(struct ios
if (t == 1)
return inflate_fixed(io);

- DEBG(">");
-
/* bad block type */
return 2;
}

2005-10-31 21:00:33

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 18/20] inflate: minor const changes

inflate: small constant tidy-up

Index: 2.6.14/lib/inflate.c
===================================================================
--- 2.6.14.orig/lib/inflate.c 2005-10-28 22:04:29.000000000 -0700
+++ 2.6.14/lib/inflate.c 2005-10-28 22:04:31.000000000 -0700
@@ -52,7 +52,7 @@
The Huffman codes themselves are decoded using a multi-level table
lookup, in order to maximize the speed of decoding plus the speed of
building the decoding tables. See the comments below that precede the
- lbits and dbits tuning parameters.
+ LBITS and dbits tuning parameters.
*/

/*
@@ -350,9 +350,9 @@ static inline void popbytes(struct iosta
the longer codes. The time it costs to decode the longer codes is
then traded against the time it takes to make longer tables.

- This results of this trade are in the variables lbits and dbits
- below. lbits is the number of bits the first level table for literal/
- length codes can decode in one step, and dbits is the same thing for
+ This results of this trade are in the variables LBITS and DBITS
+ below. LBITS is the number of bits the first level table for literal/
+ length codes can decode in one step, and DBITS is the same thing for
the distance codes. Subsequent tables are also less than or equal to
those sizes. These values may be adjusted either when all of the
codes are shorter than that, in which case the longest code length in
@@ -365,17 +365,15 @@ static inline void popbytes(struct iosta
codes 286 possible values, or in a flat code, a little over eight
bits. The distance table codes 30 possible values, or a little less
than five bits, flat. The optimum values for speed end up being
- about one bit more than those, so lbits is 8+1 and dbits is 5+1.
+ about one bit more than those, so LBITS is 8+1 and DBITS is 5+1.
The optimum values may differ though from machine to machine, and
possibly even between compilers. Your mileage may vary.
*/

-static const int lbits = 9; /* bits in base literal/length lookup table */
-static const int dbits = 6; /* bits in base distance lookup table */
-
-/* If BMAX needs to be larger than 16, then h and x[] should be u32. */
-#define BMAX 16 /* maximum bit length of any code (16 for explode) */
-#define N_MAX 288 /* maximum number of codes in any set */
+#define LBITS 9 /* bits in base literal/length lookup table */
+#define DBITS 6 /* bits in base distance lookup table */
+#define BMAX 16 /* maximum bit length of any code (16 for explode) */
+#define N_MAX 288 /* maximum number of codes in any set */

/*
* huft-build - build a huffman decoding table
@@ -831,7 +829,7 @@ static int noinline INIT inflate_dynamic
huft_free(tl);

/* build the decoding tables for literal/length and distance codes */
- bl = lbits;
+ bl = LBITS;
if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl))) {
if (i == 1) {
io->error("incomplete literal tree");
@@ -840,7 +838,7 @@ static int noinline INIT inflate_dynamic
return i; /* incomplete code set */
}

- bd = dbits;
+ bd = DBITS;
if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd))) {
if (i == 1) {
io->error("incomplete distance tree");

2005-10-31 21:05:24

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 15/20] inflate: (arch) tidy user declarations

inflate: tidy user declarations

Regroup the few remaining gzip-related declarations in users. As the
bulk of the users are now _not_ a collection of routines copied from
gzip, that comment is removed.

Signed-off-by: Matt Mackall <[email protected]>

Index: 2.6.14/arch/alpha/boot/misc.c
===================================================================
--- 2.6.14.orig/arch/alpha/boot/misc.c 2005-10-28 22:04:23.000000000 -0700
+++ 2.6.14/arch/alpha/boot/misc.c 2005-10-28 22:04:25.000000000 -0700
@@ -1,8 +1,5 @@
/*
* misc.c
- *
- * This is a collection of several routines from gzip-1.0.3
- * adapted for Linux.
*
* Modified for ARM Linux by Russell King
*
@@ -17,28 +14,23 @@
*/

#include <linux/kernel.h>
-
#include <asm/uaccess.h>

#define puts srm_printk
extern long srm_printk(const char *, ...)
__attribute__ ((format (printf, 1, 2)));

-/*
- * gzip delarations
- */
-
+extern int end;
static char *input_data;
static int input_data_size;
-
static u8 *output_data;

-extern int end;
+#define HEAP_SIZE 0x2000
+
+/* gzip delarations */
static u32 free_mem_ptr;
static u32 free_mem_ptr_end;

-#define HEAP_SIZE 0x2000
-
#include "../../../lib/inflate.c"

/* flush gunzip output window */
Index: 2.6.14/arch/arm/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm/boot/compressed/misc.c 2005-10-28 22:04:23.000000000 -0700
+++ 2.6.14/arch/arm/boot/compressed/misc.c 2005-10-28 22:04:25.000000000 -0700
@@ -1,8 +1,5 @@
/*
* misc.c
- *
- * This is a collection of several routines from gzip-1.0.3
- * adapted for Linux.
*
* Modified for ARM Linux by Russell King
*
@@ -17,7 +14,6 @@
unsigned int __machine_arch_type;

#include <linux/string.h>
-
#include <asm/arch/uncompress.h>

#ifdef STANDALONE_DEBUG
Index: 2.6.14/arch/arm26/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm26/boot/compressed/misc.c 2005-10-28 22:04:23.000000000 -0700
+++ 2.6.14/arch/arm26/boot/compressed/misc.c 2005-10-28 22:04:25.000000000 -0700
@@ -1,8 +1,5 @@
/*
* misc.c
- *
- * This is a collection of several routines from gzip-1.0.3
- * adapted for Linux.
*
* Modified for ARM Linux by Russell King
*
@@ -17,7 +14,6 @@
unsigned int __machine_arch_type;

#include <linux/kernel.h>
-
#include <asm/uaccess.h>
#include "uncompress.h"

@@ -25,24 +21,19 @@ unsigned int __machine_arch_type;
#define puts printf
#endif

-#define __ptr_t void *
-
-/*
- * gzip delarations
- */
-
+extern int end;
extern char input_data[];
extern char input_data_end[];
static u8 *output_data;

static void puts(const char *);

-extern int end;
+#define HEAP_SIZE 0x2000
+
+/* gzip delarations */
static u32 free_mem_ptr;
static u32 free_mem_ptr_end;

-#define HEAP_SIZE 0x2000
-
#include "../../../../lib/inflate.c"

#ifdef STANDALONE_DEBUG
Index: 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-28 22:04:23.000000000 -0700
+++ 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-28 22:04:25.000000000 -0700
@@ -1,14 +1,9 @@
/*
* misc.c
*
- * $Id: misc.c,v 1.6 2003/10/27 08:04:31 starvik Exp $
- *
- * This is a collection of several routines from gzip-1.0.3
- * adapted for Linux.
- *
* puts by Nick Holloway 1993, better puts by Martin Mares 1995
* adoptation for Linux/CRIS Axis Communications AB, 1999
- *
+ *
*/

/* where the piggybacked kernel image expects itself to live.
@@ -20,24 +15,17 @@
#define KERNEL_LOAD_ADR 0x40004000

#include <linux/config.h>
-
#include <linux/types.h>
#include <asm/arch/svinto.h>

-/*
- * gzip declarations
- */
-
-unsigned compsize; /* compressed size, used by head.S */
-
+extern int end; /* the "heap" is put directly after the BSS ends, at end */
+extern unsigned compsize; /* compressed size, used by head.S */
extern char *input_data; /* lives in head.S */
static u8 *output_data;

static void puts(const char *);

-/* the "heap" is put directly after the BSS ends, at end */
-
-extern int end;
+/* gzip declarations */
static long free_mem_ptr = (long)&end;
static long free_mem_end_ptr = 0xffffffff;

Index: 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-28 22:04:23.000000000 -0700
+++ 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-28 22:04:25.000000000 -0700
@@ -1,11 +1,6 @@
/*
* misc.c
*
- * $Id: misc.c,v 1.8 2005/04/24 18:34:29 starvik Exp $
- *
- * This is a collection of several routines from gzip-1.0.3
- * adapted for Linux.
- *
* puts by Nick Holloway 1993, better puts by Martin Mares 1995
* adoptation for Linux/CRIS Axis Communications AB, 1999
*
@@ -20,24 +15,18 @@
#define KERNEL_LOAD_ADR 0x40004000

#include <linux/config.h>
-
#include <linux/types.h>
#include <asm/arch/hwregs/reg_rdwr.h>
#include <asm/arch/hwregs/reg_map.h>
#include <asm/arch/hwregs/ser_defs.h>

-/*
- * gzip declarations
- */
-
+extern int _end; /* the "heap" is put directly after the BSS ends, at end */
extern char *input_data; /* lives in head.S */
static u8 *output_data;

static void puts(const char *);

-/* the "heap" is put directly after the BSS ends, at end */
-
-extern int _end;
+/* gzip declarations */
static long free_mem_ptr = (long)&_end;
static long free_mem_end_ptr = 0xffffffff;

Index: 2.6.14/arch/i386/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/i386/boot/compressed/misc.c 2005-10-28 22:04:23.000000000 -0700
+++ 2.6.14/arch/i386/boot/compressed/misc.c 2005-10-28 22:04:25.000000000 -0700
@@ -1,8 +1,5 @@
/*
* misc.c
- *
- * This is a collection of several routines from gzip-1.0.3
- * adapted for Linux.
*
* puts by Nick Holloway 1993, better puts by Martin Mares 1995
* High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
@@ -15,16 +12,6 @@
#include <asm/page.h>

/*
- * gzip declarations
- */
-
-/*
- * Why do we do this? Don't ask me..
- *
- * Incomprehensible are the ways of bootloaders.
- */
-
-/*
* This is set up by the setup-routine at boot-time
*/
static unsigned char *real_mode; /* Pointer to real-mode data */
@@ -35,6 +22,7 @@ static unsigned char *real_mode; /* Poin
#endif
#define RM_SCREEN_INFO (*(struct screen_info *)(real_mode+0))

+extern int end;
extern char input_data[];
extern int input_len;
static long bytes_out;
@@ -42,10 +30,6 @@ static u8 *output_data;

static void putstr(const char *);

-extern int end;
-static long free_mem_ptr = (long)&end;
-static long free_mem_end_ptr;
-
#define INPLACE_MOVE_ROUTINE 0x1000
#define LOW_BUFFER_START 0x2000
#define LOW_BUFFER_MAX 0x90000
@@ -62,6 +46,10 @@ static int lines, cols;
static void * xquad_portio = NULL;
#endif

+/* gzip declarations */
+static long free_mem_ptr = (long)&end;
+static long free_mem_end_ptr;
+
#include "../../../../lib/inflate.c"

static void scroll(void)
Index: 2.6.14/arch/m32r/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/m32r/boot/compressed/misc.c 2005-10-28 22:04:23.000000000 -0700
+++ 2.6.14/arch/m32r/boot/compressed/misc.c 2005-10-28 22:04:25.000000000 -0700
@@ -1,9 +1,6 @@
/*
* arch/m32r/boot/compressed/misc.c
*
- * This is a collection of several routines from gzip-1.0.3
- * adapted for Linux.
- *
* Adapted for SH by Stuart Menefy, Aug 1999
*
* 2003-02-12: Support M32R by Takeo Takahashi
@@ -13,21 +10,18 @@
#include <linux/config.h>
#include <linux/string.h>

-/*
- * gzip declarations
- */
-
static unsigned char *input_data;
static int input_len;
static u8 *output_data;

#include "m32r_sio.c"

+#define HEAP_SIZE 0x10000
+
+/* gzip declarations */
static unsigned long free_mem_ptr;
static unsigned long free_mem_end_ptr;

-#define HEAP_SIZE 0x10000
-
#include "../../../../lib/inflate.c"

/* flush the gunzip output buffer */
Index: 2.6.14/arch/sh/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh/boot/compressed/misc.c 2005-10-28 22:04:23.000000000 -0700
+++ 2.6.14/arch/sh/boot/compressed/misc.c 2005-10-28 22:04:25.000000000 -0700
@@ -1,9 +1,6 @@
/*
* arch/sh/boot/compressed/misc.c
*
- * This is a collection of several routines from gzip-1.0.3
- * adapted for Linux.
- *
* Adapted for SH by Stuart Menefy, Aug 1999
*
* Modified to use standard LinuxSH BIOS by Greg Banks 7Jul2000
@@ -15,23 +12,20 @@
#include <asm/sh_bios.h>
#endif

-/*
- * gzip declarations
- */
-
+extern int _text; /* Defined in vmlinux.lds.S */
+extern int _end;
extern char input_data[];
extern int input_len;
static u8 *output_data;

int puts(const char *);

-extern int _text; /* Defined in vmlinux.lds.S */
-extern int _end;
+#define HEAP_SIZE 0x10000
+
+/* gzip declarations */
static unsigned long free_mem_ptr;
static unsigned long free_mem_end_ptr;

-#define HEAP_SIZE 0x10000
-
#include "../../../../lib/inflate.c"

#ifdef CONFIG_SH_STANDARD_BIOS
Index: 2.6.14/arch/sh64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh64/boot/compressed/misc.c 2005-10-28 22:04:23.000000000 -0700
+++ 2.6.14/arch/sh64/boot/compressed/misc.c 2005-10-28 22:04:25.000000000 -0700
@@ -1,9 +1,6 @@
/*
* arch/shmedia/boot/compressed/misc.c
*
- * This is a collection of several routines from gzip-1.0.3
- * adapted for Linux.
- *
* Adapted for SHmedia from sh by Stuart Menefy, May 2002
*/

@@ -15,23 +12,20 @@
#define CACHE_DISABLE 1
int cache_control(unsigned int command);

-/*
- * gzip declarations
- */
-
+extern int _text; /* Defined in vmlinux.lds.S */
+extern int _end;
extern char input_data[];
extern int input_len;
static u8 *output_data;

static void puts(const char *);

-extern int _text; /* Defined in vmlinux.lds.S */
-extern int _end;
+#define HEAP_SIZE 0x10000
+
+/* gzip declarations */
static unsigned long free_mem_ptr;
static unsigned long free_mem_end_ptr;

-#define HEAP_SIZE 0x10000
-
#include "../../../../lib/inflate.c"

void puts(const char *s)
Index: 2.6.14/arch/x86_64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/x86_64/boot/compressed/misc.c 2005-10-28 22:04:23.000000000 -0700
+++ 2.6.14/arch/x86_64/boot/compressed/misc.c 2005-10-28 22:04:25.000000000 -0700
@@ -1,8 +1,5 @@
/*
* misc.c
- *
- * This is a collection of several routines from gzip-1.0.3
- * adapted for Linux.
*
* puts by Nick Holloway 1993, better puts by Martin Mares 1995
* High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
@@ -13,10 +10,6 @@
#include <asm/page.h>

/*
- * gzip declarations
- */
-
-/*
* This is set up by the setup-routine at boot-time
*/
static unsigned char *real_mode; /* Pointer to real-mode data */
@@ -29,16 +22,11 @@ static unsigned char *real_mode; /* Poin

extern unsigned char input_data[];
extern int input_len;
-
+extern int end;
static long bytes_out;
static u8 *output_data;
-
static void putstr(const char *);

-extern int end;
-static long free_mem_ptr = (long)&end;
-static long free_mem_end_ptr;
-
#define INPLACE_MOVE_ROUTINE 0x1000
#define LOW_BUFFER_START 0x2000
#define LOW_BUFFER_MAX 0x90000
@@ -51,6 +39,10 @@ static char *vidmem = (char *)0xb8000;
static int vidport;
static int lines, cols;

+/* gzip declarations */
+static long free_mem_ptr = (long)&end;
+static long free_mem_end_ptr;
+
#include "../../../../lib/inflate.c"

static void scroll(void)
Index: 2.6.14/init/do_mounts_rd.c
===================================================================
--- 2.6.14.orig/init/do_mounts_rd.c 2005-10-28 22:04:23.000000000 -0700
+++ 2.6.14/init/do_mounts_rd.c 2005-10-28 22:04:25.000000000 -0700
@@ -269,9 +269,11 @@ int __init rd_load_disk(int n)

#ifdef BUILD_CRAMDISK

-/*
- * gzip declarations
- */
+/* gzip declarations */
+#define INIT __init
+#define NO_INFLATE_MALLOC
+
+#include "../lib/inflate.c"

#define INBUFSIZ 4096
static u8 *inbuf;
@@ -279,12 +281,6 @@ static int exit_code;
static int unzip_error;
static int crd_infd, crd_outfd;

-#define INIT __init
-
-#define NO_INFLATE_MALLOC
-
-#include "../lib/inflate.c"
-
static void __init error(const char *x)
{
printk(KERN_ERR "%s\n", x);
Index: 2.6.14/init/initramfs.c
===================================================================
--- 2.6.14.orig/init/initramfs.c 2005-10-28 22:04:23.000000000 -0700
+++ 2.6.14/init/initramfs.c 2005-10-28 22:04:25.000000000 -0700
@@ -329,12 +329,9 @@ static void __init flush_buffer(const u8
}
}

-/*
- * gzip declarations
- */
+/* gzip declarations */

#define INIT __init
-
#define NO_INFLATE_MALLOC

#include "../lib/inflate.c"

2005-10-31 21:07:03

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 13/20] inflate: (arch) kill silly zlib typedefs

inflate: remove legacy type definitions from callers

This replaces the legacy zlib typedefs and usage with kernel types in
all the inflate users.

Signed-off-by: Matt Mackall <[email protected]>

Index: 2.6.14/arch/alpha/boot/misc.c
===================================================================
--- 2.6.14.orig/arch/alpha/boot/misc.c 2005-10-28 22:04:19.000000000 -0700
+++ 2.6.14/arch/alpha/boot/misc.c 2005-10-28 22:04:21.000000000 -0700
@@ -28,20 +28,16 @@ extern long srm_printk(const char *, ...
* gzip delarations
*/

-typedef unsigned char uch;
-typedef unsigned short ush;
-typedef unsigned long ulg;
-
static void error(char *m);

static char *input_data;
static int input_data_size;

-static uch *output_data;
+static u8 *output_data;

extern int end;
-static ulg free_mem_ptr;
-static ulg free_mem_ptr_end;
+static u32 free_mem_ptr;
+static u32 free_mem_ptr_end;

#define HEAP_SIZE 0x2000

@@ -70,13 +66,13 @@ decompress_kernel(void *output_start,
size_t kzsize)
{
int count;
- output_data = (uch *)output_start;
- input_data = (uch *)input_start;
+ output_data = (u8 *)output_start;
+ input_data = (u8 *)input_start;
input_data_size = kzsize; /* use compressed size */

/* FIXME FIXME FIXME */
- free_mem_ptr = (ulg)output_start + ksize;
- free_mem_ptr_end = (ulg)output_start + ksize + 0x200000;
+ free_mem_ptr = (u32)output_start + ksize;
+ free_mem_ptr_end = (u32)output_start + ksize + 0x200000;
/* FIXME FIXME FIXME */

/* puts("Uncompressing Linux..."); */
Index: 2.6.14/arch/arm/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm/boot/compressed/misc.c 2005-10-28 22:04:19.000000000 -0700
+++ 2.6.14/arch/arm/boot/compressed/misc.c 2005-10-28 22:04:21.000000000 -0700
@@ -46,22 +46,18 @@ icedcc_putstr(const char *ptr)
* gzip declarations
*/

-typedef unsigned char uch;
-typedef unsigned short ush;
-typedef unsigned long ulg;
-
static void error(char *m);

extern char input_data[];
extern char input_data_end[];

-static uch *output_data;
+static u8 *output_data;

static void putstr(const char *);

extern int end;
-static ulg free_mem_ptr;
-static ulg free_mem_ptr_end;
+static u32 free_mem_ptr;
+static u32 free_mem_ptr_end;

#define HEAP_SIZE 0x2000

@@ -90,11 +86,11 @@ static void error(char *x)

#ifndef STANDALONE_DEBUG

-ulg
-decompress_kernel(ulg output_start, ulg free_mem_ptr_p, ulg free_mem_ptr_end_p,
+u32
+decompress_kernel(u32 output_start, u32 free_mem_ptr_p, u32 free_mem_ptr_end_p,
int arch_id)
{
- output_data = (uch *)output_start; /* Points to kernel start */
+ output_data = (u8 *)output_start; /* Points to kernel start */
free_mem_ptr = free_mem_ptr_p;
free_mem_ptr_end = free_mem_ptr_end_p;
__machine_arch_type = arch_id;
Index: 2.6.14/arch/arm26/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm26/boot/compressed/misc.c 2005-10-28 22:04:19.000000000 -0700
+++ 2.6.14/arch/arm26/boot/compressed/misc.c 2005-10-28 22:04:21.000000000 -0700
@@ -31,21 +31,17 @@ unsigned int __machine_arch_type;
* gzip delarations
*/

-typedef unsigned char uch;
-typedef unsigned short ush;
-typedef unsigned long ulg;
-
static void error(char *m);

extern char input_data[];
extern char input_data_end[];
-static uch *output_data;
+static u8 *output_data;

static void puts(const char *);

extern int end;
-static ulg free_mem_ptr;
-static ulg free_mem_ptr_end;
+static u32 free_mem_ptr;
+static u32 free_mem_ptr_end;

#define HEAP_SIZE 0x2000

@@ -76,11 +72,11 @@ static void error(char *x)

#ifndef STANDALONE_DEBUG

-ulg
-decompress_kernel(ulg output_start, ulg free_mem_ptr_p, ulg free_mem_ptr_end_p,
+u32
+decompress_kernel(u32 output_start, u32 free_mem_ptr_p, u32 free_mem_ptr_end_p,
int arch_id)
{
- output_data = (uch *)output_start; /* Points to kernel start */
+ output_data = (u8 *)output_start; /* Points to kernel start */
free_mem_ptr = free_mem_ptr_p;
free_mem_ptr_end = free_mem_ptr_end_p;
__machine_arch_type = arch_id;
Index: 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-28 22:04:19.000000000 -0700
+++ 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-28 22:04:21.000000000 -0700
@@ -28,16 +28,12 @@
* gzip declarations
*/

-typedef unsigned char uch;
-typedef unsigned short ush;
-typedef unsigned long ulg;
-
unsigned compsize; /* compressed size, used by head.S */

static void error(char *m);

extern char *input_data; /* lives in head.S */
-static uch *output_data;
+static u8 *output_data;

static void puts(const char *);

Index: 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-28 22:04:19.000000000 -0700
+++ 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-28 22:04:21.000000000 -0700
@@ -30,14 +30,10 @@
* gzip declarations
*/

-typedef unsigned char uch;
-typedef unsigned short ush;
-typedef unsigned long ulg;
-
static void error(char *m);

extern char *input_data; /* lives in head.S */
-static uch *output_data;
+static u8 *output_data;

static void puts(const char *);

Index: 2.6.14/arch/i386/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/i386/boot/compressed/misc.c 2005-10-28 22:04:19.000000000 -0700
+++ 2.6.14/arch/i386/boot/compressed/misc.c 2005-10-28 22:04:21.000000000 -0700
@@ -23,9 +23,6 @@
*
* Incomprehensible are the ways of bootloaders.
*/
-typedef unsigned char uch;
-typedef unsigned short ush;
-typedef unsigned long ulg;

static void error(char *m);

@@ -43,7 +40,7 @@ static unsigned char *real_mode; /* Poin
extern char input_data[];
extern int input_len;
static long bytes_out;
-static uch *output_data;
+static u8 *output_data;

static void putstr(const char *);

@@ -57,7 +54,7 @@ static long free_mem_end_ptr;
#define HEAP_SIZE 0x3000
static unsigned int low_buffer_end, low_buffer_size;
static int high_loaded =0;
-static uch *high_buffer_start /* = (uch *)(((ulg)&end) + HEAP_SIZE)*/;
+static u8 *high_buffer_start /* = (u8 *)(((u32)&end) + HEAP_SIZE)*/;

static char *vidmem = (char *)0xb8000;
static int vidport;
@@ -158,13 +155,13 @@ static void setup_normal_output_buffer(v
}

struct moveparams {
- uch *low_buffer_start; int lcount;
- uch *high_buffer_start; int hcount;
+ u8 *low_buffer_start; int lcount;
+ u8 *high_buffer_start; int hcount;
};

static void setup_output_buffer_if_we_run_high(struct moveparams *mv)
{
- high_buffer_start = (uch *)(((ulg)&end) + HEAP_SIZE);
+ high_buffer_start = (u8 *)(((u32)&end) + HEAP_SIZE);
#ifdef STANDARD_MEMORY_BIOS_CALL
if (RM_EXT_MEM_K < (3*1024)) error("Less than 4MB of memory");
#else
@@ -178,8 +175,8 @@ static void setup_output_buffer_if_we_ru
low_buffer_size = low_buffer_end - LOW_BUFFER_START;
high_loaded = 1;
free_mem_end_ptr = (long)high_buffer_start;
- if ( (__PHYSICAL_START + low_buffer_size) > ((ulg)high_buffer_start)) {
- high_buffer_start = (uch *)(__PHYSICAL_START + low_buffer_size);
+ if ( (__PHYSICAL_START + low_buffer_size) > ((u32)high_buffer_start)) {
+ high_buffer_start = (u8 *)(__PHYSICAL_START + low_buffer_size);
mv->hcount = 0; /* say: we need not to move high_buffer */
}
else mv->hcount = -1;
Index: 2.6.14/arch/m32r/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/m32r/boot/compressed/misc.c 2005-10-28 22:04:19.000000000 -0700
+++ 2.6.14/arch/m32r/boot/compressed/misc.c 2005-10-28 22:04:21.000000000 -0700
@@ -17,15 +17,11 @@
* gzip declarations
*/

-typedef unsigned char uch;
-typedef unsigned short ush;
-typedef unsigned long ulg;
-
static void error(char *m);

static unsigned char *input_data;
static int input_len;
-static uch *output_data;
+static u8 *output_data;

#include "m32r_sio.c"

Index: 2.6.14/arch/sh/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh/boot/compressed/misc.c 2005-10-28 22:04:19.000000000 -0700
+++ 2.6.14/arch/sh/boot/compressed/misc.c 2005-10-28 22:04:21.000000000 -0700
@@ -19,15 +19,11 @@
* gzip declarations
*/

-typedef unsigned char uch;
-typedef unsigned short ush;
-typedef unsigned long ulg;
-
static void error(char *m);

extern char input_data[];
extern int input_len;
-static uch *output_data;
+static u8 *output_data;

int puts(const char *);

Index: 2.6.14/arch/sh64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh64/boot/compressed/misc.c 2005-10-28 22:04:19.000000000 -0700
+++ 2.6.14/arch/sh64/boot/compressed/misc.c 2005-10-28 22:04:21.000000000 -0700
@@ -19,15 +19,11 @@ int cache_control(unsigned int command);
* gzip declarations
*/

-typedef unsigned char uch;
-typedef unsigned short ush;
-typedef unsigned long ulg;
-
static void error(char *m);

extern char input_data[];
extern int input_len;
-static uch *output_data;
+static u8 *output_data;

static void puts(const char *);

@@ -68,7 +64,7 @@ long *stack_start = &user_stack[STACK_SI

void decompress_kernel(void)
{
- output_data = (uch *) (CONFIG_MEMORY_START + 0x2000);
+ output_data = (u8 *) (CONFIG_MEMORY_START + 0x2000);
free_mem_ptr = (unsigned long) &_end;
free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;

Index: 2.6.14/arch/x86_64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/x86_64/boot/compressed/misc.c 2005-10-28 22:04:19.000000000 -0700
+++ 2.6.14/arch/x86_64/boot/compressed/misc.c 2005-10-28 22:04:21.000000000 -0700
@@ -16,10 +16,6 @@
* gzip declarations
*/

-typedef unsigned char uch;
-typedef unsigned short ush;
-typedef unsigned long ulg;
-
static void error(char *m);

/*
@@ -37,7 +33,7 @@ extern unsigned char input_data[];
extern int input_len;

static long bytes_out;
-static uch *output_data;
+static u8 *output_data;

static void putstr(const char *);

@@ -51,7 +47,7 @@ static long free_mem_end_ptr;
#define HEAP_SIZE 0x3000
static unsigned int low_buffer_end, low_buffer_size;
static int high_loaded =0;
-static uch *high_buffer_start /* = (uch *)(((ulg)&end) + HEAP_SIZE)*/;
+static u8 *high_buffer_start /* = (u8 *)(((u32)&end) + HEAP_SIZE)*/;

static char *vidmem = (char *)0xb8000;
static int vidport;
@@ -139,13 +135,13 @@ void setup_normal_output_buffer(void)
}

struct moveparams {
- uch *low_buffer_start; int lcount;
- uch *high_buffer_start; int hcount;
+ u8 *low_buffer_start; int lcount;
+ u8 *high_buffer_start; int hcount;
};

void setup_output_buffer_if_we_run_high(struct moveparams *mv)
{
- high_buffer_start = (uch *)(((ulg)&end) + HEAP_SIZE);
+ high_buffer_start = (u8 *)(((u32)&end) + HEAP_SIZE);
#ifdef STANDARD_MEMORY_BIOS_CALL
if (EXT_MEM_K < (3*1024)) error("Less than 4MB of memory");
#else
@@ -157,8 +153,8 @@ void setup_output_buffer_if_we_run_high(
low_buffer_size = low_buffer_end - LOW_BUFFER_START;
high_loaded = 1;
free_mem_end_ptr = (long)high_buffer_start;
- if ( (__PHYSICAL_START + low_buffer_size) > ((ulg)high_buffer_start)) {
- high_buffer_start = (uch *)(__PHYSICAL_START + low_buffer_size);
+ if ( (__PHYSICAL_START + low_buffer_size) > ((u32)high_buffer_start)) {
+ high_buffer_start = (u8 *)(__PHYSICAL_START + low_buffer_size);
mv->hcount = 0; /* say: we need not to move high_buffer */
}
else mv->hcount = -1;
Index: 2.6.14/init/do_mounts_rd.c
===================================================================
--- 2.6.14.orig/init/do_mounts_rd.c 2005-10-28 22:04:19.000000000 -0700
+++ 2.6.14/init/do_mounts_rd.c 2005-10-28 22:04:21.000000000 -0700
@@ -273,12 +273,8 @@ int __init rd_load_disk(int n)
* gzip declarations
*/

-typedef unsigned char uch;
-typedef unsigned short ush;
-typedef unsigned long ulg;
-
#define INBUFSIZ 4096
-static uch *inbuf;
+static u8 *inbuf;
static int exit_code;
static int unzip_error;
static int crd_infd, crd_outfd;
Index: 2.6.14/init/initramfs.c
===================================================================
--- 2.6.14.orig/init/initramfs.c 2005-10-28 22:04:19.000000000 -0700
+++ 2.6.14/init/initramfs.c 2005-10-28 22:04:21.000000000 -0700
@@ -333,10 +333,6 @@ static void __init flush_buffer(const u8
* gzip declarations
*/

-typedef unsigned char uch;
-typedef unsigned short ush;
-typedef unsigned long ulg;
-
#define INIT __init

static void __init error(char *m);

2005-10-31 21:07:38

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 20/20] inflate: make in-core inflate share common CRC

inflate: make in-core inflate share common CRC code

Signed-off-by: Matt Mackall <[email protected]>

Index: 2.6.14/lib/inflate.c
===================================================================
--- 2.6.14.orig/lib/inflate.c 2005-10-28 22:04:32.000000000 -0700
+++ 2.6.14/lib/inflate.c 2005-10-28 22:04:35.000000000 -0700
@@ -144,23 +144,46 @@ static void free(void *where)
malloc_ptr = free_mem_ptr;
}

-static u8 INITDATA window[0x8000]; /* use a statically allocated window */
+static u8 window[0x8000]; /* use a statically allocated window */
+
+/* simple CRC calculation */
+static u32 crc_32_tab[256];
+#define CRCPOLY_LE 0xedb88320
+
+static void makecrc(void)
+{
+ unsigned i, j;
+ u32 c = 1;
+
+ for (i = 128; i; i >>= 1) {
+ c = (c >> 1) ^ ((c & 1) ? CRCPOLY_LE : 0);
+ for (j = 0; j < 256; j += 2 * i)
+ crc_32_tab[i + j] = c ^ crc_32_tab[j];
+ }
+}
+
+static u32 crc32_le(u32 crc, unsigned char const *p, size_t len)
+{
+ while (len--)
+ crc = crc_32_tab[(*p++ ^ crc) & 0xff] ^ (crc >> 8);
+
+ return crc;
+}

#else

#include <linux/module.h>
+#include <linux/crc32.h>

static u8 *window; /* dynamically allocate */
#define malloc(a) kmalloc(a, GFP_KERNEL)
#define free(a) kfree(a)
+#define makecrc()
#define INIT __init
#define INITDATA __initdata

#endif

-static u32 crc_32_tab[256];
-#define CRCPOLY_LE 0xedb88320
-
/* Huffman code lookup table entry--this entry is four bytes for machines
that have 16-bit pointers (e.g. PC's in the small or medium model).
Valid extra bits are 0..13. e == 15 is EOB (end of block), e == 16
@@ -205,12 +228,7 @@ static int INIT inflate(struct iostate *

static void flush_output(struct iostate *io)
{
- int i;
-
- for (i = 0; i < io->opos; i++)
- io->crc = crc_32_tab[(io->window[i] ^ (int)io->crc) & 0xff]
- ^ (io->crc >> 8);
-
+ io->crc = crc32_le(io->crc, io->window, io->opos);
io->flush(io->window, io->opos);
io->ototal += io->opos;
io->opos = 0;
@@ -906,24 +924,6 @@ static int INIT inflate(struct iostate *
return 0;
}

-/**********************************************************************
- *
- * The following are support routines for inflate.c
- *
- **********************************************************************/
-
-static void INIT makecrc(void)
-{
- unsigned i, j;
- u32 c = 1;
-
- for (i = 128; i; i >>= 1) {
- c = (c >> 1) ^ ((c & 1) ? CRCPOLY_LE : 0);
- for (j = 0; j < 256; j += 2 * i)
- crc_32_tab[i + j] = c ^ crc_32_tab[j];
- }
-}
-
/* gzip flag byte */
#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */

2005-10-31 21:07:59

by Matt Mackall

[permalink] [raw]
Subject: [PATCH 2/20] inflate: kill legacy bits

inflate: kill legacy bits

Kill RCSID
Kill old includes and defines
Kill screwy types
Kill unused memory usage tracking
Kill 'register' usage
Kill unused tracing calls

Signed-off-by: Matt Mackall <[email protected]>

Index: tiny/lib/inflate.c
===================================================================
--- tiny.orig/lib/inflate.c 2005-09-28 18:19:05.000000000 -0700
+++ tiny/lib/inflate.c 2005-09-28 18:25:25.000000000 -0700
@@ -103,26 +103,11 @@
*/
#include <linux/compiler.h>

-#ifdef RCSID
-static char rcsid[] = "#Id: inflate.c,v 0.14 1993/06/10 13:27:04 jloup Exp #";
-#endif
-
-#ifndef STATIC
-
-#if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
-# include <sys/types.h>
-# include <stdlib.h>
-#endif
-
-#include "gzip.h"
-#define STATIC
-#endif /* !STATIC */
-
#ifndef INIT
#define INIT
#endif

-#define slide window
+#include <asm/types.h>

/* Huffman code lookup table entry--this entry is four bytes for machines
that have 16-bit pointers (e.g. PC's in the small or medium model).
@@ -132,36 +117,35 @@ static char rcsid[] = "#Id: inflate.c,v
an unused code. If a code with e == 99 is looked up, this implies an
error in the data. */
struct huft {
- uch e; /* number of extra bits or operation */
- uch b; /* number of bits in this code or subcode */
+ u8 e; /* number of extra bits or operation */
+ u8 b; /* number of bits in this code or subcode */
union {
- ush n; /* literal, length base, or distance base */
+ u16 n; /* literal, length base, or distance base */
struct huft *t; /* pointer to next level of table */
} v;
};

/* Function prototypes */
-STATIC int INIT huft_build OF((unsigned *, unsigned, unsigned,
- const ush *, const ush *, struct huft **, int *));
-STATIC int INIT huft_free OF((struct huft *));
-STATIC int INIT inflate_codes OF((struct huft *, struct huft *, int, int));
-STATIC int INIT inflate_stored OF((void));
-STATIC int INIT inflate_fixed OF((void));
-STATIC int INIT inflate_dynamic OF((void));
-STATIC int INIT inflate_block OF((int *));
-STATIC int INIT inflate OF((void));
+static int INIT huft_build(unsigned *, unsigned, unsigned,
+ const u16 *, const u16 *, struct huft **, int *);
+static int INIT huft_free(struct huft *);
+static int INIT inflate_codes(struct huft *, struct huft *, int, int);
+static int INIT inflate_stored(void);
+static int INIT inflate_fixed(void);
+static int INIT inflate_dynamic(void);
+static int INIT inflate_block(int *);
+static int INIT inflate(void);

/* The inflate algorithm uses a sliding 32 K byte window on the uncompressed
stream to find repeated byte strings. This is implemented here as a
circular buffer. The index is updated simply by incrementing and then
ANDing with 0x7fff (32K-1). */
/* It is left to other modules to supply the 32 K area. It is assumed
- to be usable as if it were declared "uch slide[32768];" or as just
- "uch *slide;" and then malloc'ed in the latter case. The definition
+ to be usable as if it were declared "u8 window[32768];" or as just
+ "u8 *window;" and then malloc'ed in the latter case. The definition
must be in unzip.h, included above. */
-/* unsigned wp; current position in slide */
-#define wp outcnt
-#define flush_output(w) (wp=(w),flush_window())
+
+#define flush_output(w) (outcnt=(w),flush_window())

/* Tables for deflate from PKZIP's appnote.txt. */

@@ -171,7 +155,7 @@ static const unsigned border[] = {
};

/* Copy lengths for literal codes 257..285 */
-static const ush cplens[] = {
+static const u16 cplens[] = {
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
};
@@ -180,20 +164,20 @@ static const ush cplens[] = {
* note: see note #13 above about the 258 in this list.
* 99==invalid
*/
-static const ush cplext[] = {
+static const u16 cplext[] = {
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99
};

/* Copy offsets for distance codes 0..29 */
-static const ush cpdist[] = {
+static const u16 cpdist[] = {
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
8193, 12289, 16385, 24577
};

/* Extra bits for distance codes */
-static const ush cpdext[] = {
+static const u16 cpdext[] = {
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
12, 12, 13, 13
@@ -207,10 +191,10 @@ static const ush cpdext[] = {
DUMPBITS(j)

where NEEDBITS makes sure that b has at least j bits in it, and
- DUMPBITS removes the bits from b. The macros use the variable k
- for the number of bits in b. Normally, b and k are register
- variables for speed, and are initialized at the beginning of a
- routine that uses these macros from a global bit buffer and count.
+ DUMPBITS removes the bits from b. The macros use the variable k for
+ the number of bits in b. Normally, b and k are initialized at the
+ beginning of a routine that uses these macros from a global bit
+ buffer and count.

If we assume that EOB will be the longest code, then we will never
ask for bits with NEEDBITS that are beyond the end of the stream.
@@ -229,17 +213,17 @@ static const ush cpdext[] = {
the stream.
*/

-STATIC ulg bb; /* bit buffer */
-STATIC unsigned bk; /* bits in bit buffer */
+static u32 bb; /* bit buffer */
+static unsigned bk; /* bits in bit buffer */

-STATIC const ush mask_bits[] = {
+static const u16 mask_bits[] = {
0x0000,
0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
};

-#define NEXTBYTE() ({ int v = get_byte(); if (v < 0) goto underrun; (uch)v; })
-#define NEEDBITS(n) do {while(k<(n)){b|=((ulg)NEXTBYTE())<<k;k+=8;}} while(0)
+#define NEXTBYTE() ({ int v = get_byte(); if (v < 0) goto underrun; (u8)v; })
+#define NEEDBITS(n) do {while(k<(n)){b|=((u32)NEXTBYTE())<<k;k+=8;}} while(0)
#define DUMPBITS(n) do {b>>=(n);k-=(n);} while(0)

/*
@@ -274,15 +258,13 @@ STATIC const ush mask_bits[] = {
possibly even between compilers. Your mileage may vary.
*/

-STATIC const int lbits = 9; /* bits in base literal/length lookup table */
-STATIC const int dbits = 6; /* bits in base distance lookup table */
+static const int lbits = 9; /* bits in base literal/length lookup table */
+static const int dbits = 6; /* bits in base distance lookup table */

-/* If BMAX needs to be larger than 16, then h and x[] should be ulg. */
+/* If BMAX needs to be larger than 16, then h and x[] should be u32. */
#define BMAX 16 /* maximum bit length of any code (16 for explode) */
#define N_MAX 288 /* maximum number of codes in any set */

-STATIC unsigned hufts; /* track memory usage */
-
/*
* huft-build - build a huffman decoding table
* @b: code lengths in bits (all assumed <= BMAX)
@@ -300,24 +282,24 @@ STATIC unsigned hufts; /* track memory
* an oversubscribed set of lengths), and three if not enough
* memory.
*/
-STATIC int INIT huft_build(unsigned *b, unsigned n, unsigned s, const ush * d,
- const ush * e, struct huft **t, int *m)
+static int INIT huft_build(unsigned *b, unsigned n, unsigned s, const u16 * d,
+ const u16 * e, struct huft **t, int *m)
{
unsigned a; /* counter for codes of length k */
unsigned c[BMAX + 1]; /* bit length count table */
unsigned f; /* i repeats in table every f entries */
int g; /* maximum code length */
int h; /* table level */
- register unsigned i; /* counter, current code */
- register unsigned j; /* counter */
- register int k; /* number of bits in current code */
+ unsigned i; /* counter, current code */
+ unsigned j; /* counter */
+ int k; /* number of bits in current code */
int l; /* bits per table (returned in m) */
- register unsigned *p; /* pointer into c[], b[], or v[] */
- register struct huft *q; /* points to current table */
+ unsigned *p; /* pointer into c[], b[], or v[] */
+ struct huft *q; /* points to current table */
struct huft r; /* table entry for structure assignment */
struct huft *u[BMAX]; /* table stack */
unsigned v[N_MAX]; /* values in order of bit length */
- register int w; /* bits before this table == (l * h) */
+ int w; /* bits before this table == (l * h) */
unsigned x[BMAX + 1]; /* bit offsets, then code stack */
unsigned *xp; /* pointer into x */
int y; /* number of dummy codes added */
@@ -330,14 +312,12 @@ STATIC int INIT huft_build(unsigned *b,
p = b;
i = n;
do {
- Tracecv(*p, (stderr, (n - i >= ' ' && n - i <= '~' ?
- "%c %d\n" : "0x%x %d\n"), n - i, *p));
c[*p]++; /* assume all entries <= BMAX */
p++;
} while (--i);

if (c[0] == n) { /* null input--all zero length codes */
- *t = (struct huft *)NULL;
+ *t = 0;
*m = 0;
return 2;
}
@@ -389,7 +369,7 @@ STATIC int INIT huft_build(unsigned *b,
p = b;
i = 0;
do {
- if ((j = *p++) != 0)
+ if ((j = *p++))
v[x[j]++] = i;
} while (++i < n);

@@ -402,8 +382,8 @@ STATIC int INIT huft_build(unsigned *b,
p = v; /* grab values in bit order */
h = -1; /* no tables yet--level -1 */
w = -l; /* bits decoded == (l * h) */
- u[0] = (struct huft *)NULL; /* just to keep compilers happy */
- q = (struct huft *)NULL; /* ditto */
+ u[0] = NULL; /* just to keep compilers happy */
+ q = NULL; /* ditto */
z = 0; /* ditto */
DEBG("h6a ");

@@ -448,17 +428,15 @@ STATIC int INIT huft_build(unsigned *b,
z = 1 << j;

/* allocate and link in new table */
- if ((q = (struct huft *)malloc(
- (z + 1) * sizeof(struct huft)))
- == (struct huft *)NULL) {
+ if (!(q = (struct huft *)malloc(
+ (z + 1) * sizeof(struct huft)))) {
if (h)
huft_free(u[0]);
return 3; /* not enough memory */
}
DEBG1("4 ");
- hufts += z + 1; /* track memory usage */
*t = q + 1; /* link to list for huft_free */
- *(t = &(q->v.t)) = (struct huft *)NULL;
+ *(t = &(q->v.t)) = 0;
u[h] = ++q; /* table starts after link */

DEBG1("5 ");
@@ -467,9 +445,9 @@ STATIC int INIT huft_build(unsigned *b,
/* save pattern for backing up */
x[h] = i;
/* bits to dump before this table */
- r.b = (uch)l;
+ r.b = (u8)l;
/* bits in this table */
- r.e = (uch)(16 + j);
+ r.e = (u8)(16 + j);
/* pointer to this table */
r.v.t = q;
/* (get around Turbo C bug) */
@@ -482,19 +460,19 @@ STATIC int INIT huft_build(unsigned *b,
DEBG("h6c ");

/* set up table entry in r */
- r.b = (uch) (k - w);
+ r.b = (u8) (k - w);
if (p >= v + n)
r.e = 99; /* out of values--invalid code */
else if (*p < s) {
/* 256 is end-of-block code */
- r.e = (uch) (*p < 256 ? 16 : 15);
+ r.e = (u8)(*p < 256 ? 16 : 15);
/* simple code is just the value */
- r.v.n = (ush) (*p);
+ r.v.n = (u16)(*p);
/* one compiler does not like *p++ */
p++;
} else {
/* non-simple--look up in lists */
- r.e = (uch)e[*p - s];
+ r.e = (u8)e[*p - s];
r.v.n = d[*p++ - s];
}
DEBG("h6d ");
@@ -522,7 +500,7 @@ STATIC int INIT huft_build(unsigned *b,
DEBG("huft7 ");

/* Return true (1) if we were given an incomplete table */
- return y != 0 && g != 1;
+ return y && g != 1;
}

/*
@@ -535,11 +513,11 @@ STATIC int INIT huft_build(unsigned *b,
*/
STATIC int INIT huft_free(struct huft *t)
{
- register struct huft *p, *q;
+ struct huft *p, *q;

/* Go through list, freeing from the malloced (t[-1]) address. */
p = t;
- while (p != (struct huft *)NULL) {
+ while (p) {
q = (--p)->v.t;
free((char *)p);
p = q;
@@ -557,20 +535,20 @@ STATIC int INIT huft_free(struct huft *t
* inflate (decompress) the codes in a deflated (compressed) block.
* Return an error code or zero if it all goes ok.
*/
-STATIC int inflate_codes(struct huft *tl, struct huft *td, int bl, int bd)
+static int inflate_codes(struct huft *tl, struct huft *td, int bl, int bd)
{
- register unsigned e; /* table entry flag/number of extra bits */
+ unsigned e; /* table entry flag/number of extra bits */
unsigned n, d; /* length and index for copy */
unsigned w; /* current window position */
struct huft *t; /* pointer to table entry */
unsigned ml, md; /* masks for bl and bd bits */
- register ulg b; /* bit buffer */
- register unsigned k; /* number of bits in bit buffer */
+ u32 b; /* bit buffer */
+ unsigned k; /* number of bits in bit buffer */

/* make local copies of globals */
b = bb; /* initialize bit buffer */
k = bk;
- w = wp; /* initialize window position */
+ w = outcnt; /* initialize window position */

/* inflate the coded data */
ml = mask_bits[bl]; /* precompute masks for speed */
@@ -588,8 +566,7 @@ STATIC int inflate_codes(struct huft *tl
mask_bits[e]))->e) > 16);
DUMPBITS(t->b);
if (e == 16) { /* then it's a literal */
- slide[w++] = (uch)t->v.n;
- Tracevv((stderr, "%c", slide[w - 1]));
+ window[w++] = (u8)t->v.n;
if (w == WSIZE) {
flush_output(w);
w = 0;
@@ -619,7 +596,6 @@ STATIC int inflate_codes(struct huft *tl
NEEDBITS(e);
d = w - t->v.n - ((unsigned)b & mask_bits[e]);
DUMPBITS(e)
- Tracevv((stderr, "\\[%d,%d]", w - d, n));

/* do the copy */
do {
@@ -628,16 +604,14 @@ STATIC int inflate_codes(struct huft *tl
#if !defined(NOMEMCPY) && !defined(DEBUG)
/* (this test assumes unsigned comparison) */
if (w - d >= e) {
- memcpy(slide + w, slide + d, e);
+ memcpy(window + w, window + d, e);
w += e;
d += e;
} else
#endif /* !NOMEMCPY */
/* avoid memcpy() overlap */
do {
- slide[w++] = slide[d++];
- Tracevv((stderr, "%c",
- slide[w - 1]));
+ window[w++] = window[d++];
} while (--e);
if (w == WSIZE) {
flush_output(w);
@@ -648,7 +622,7 @@ STATIC int inflate_codes(struct huft *tl
}

/* restore the globals from the locals */
- wp = w; /* restore global window pointer */
+ outcnt = w; /* restore global window pointer */
bb = b; /* restore global bit buffer */
bk = k;

@@ -660,19 +634,19 @@ STATIC int inflate_codes(struct huft *tl
}

/* inflate_stored - "decompress" an inflated type 0 (stored) block. */
-STATIC int INIT inflate_stored(void)
+static int INIT inflate_stored(void)
{
unsigned n; /* number of bytes in block */
unsigned w; /* current window position */
- register ulg b; /* bit buffer */
- register unsigned k; /* number of bits in bit buffer */
+ u32 b; /* bit buffer */
+ unsigned k; /* number of bits in bit buffer */

DEBG("<stor");

/* make local copies of globals */
b = bb; /* initialize bit buffer */
k = bk;
- w = wp; /* initialize window position */
+ w = outcnt; /* initialize window position */

/* go to byte boundary */
n = k & 7;
@@ -690,7 +664,7 @@ STATIC int INIT inflate_stored(void)
/* read and output the compressed data */
while (n--) {
NEEDBITS(8);
- slide[w++] = (uch)b;
+ window[w++] = (u8)b;
if (w == WSIZE) {
flush_output(w);
w = 0;
@@ -699,7 +673,7 @@ STATIC int INIT inflate_stored(void)
}

/* restore the globals from the locals */
- wp = w; /* restore global window pointer */
+ outcnt = w; /* restore global window pointer */
bb = b; /* restore global bit buffer */
bk = k;

@@ -719,14 +693,14 @@ STATIC int INIT inflate_stored(void)
*
* We use `noinline' here to prevent gcc-3.5 from using too much stack space
*/
-STATIC int noinline INIT inflate_fixed(void)
+static int noinline INIT inflate_fixed(void)
{
int i; /* temporary variable */
struct huft *tl; /* literal/length code table */
struct huft *td; /* distance code table */
int bl; /* lookup bits for tl */
int bd; /* lookup bits for td */
- unsigned l[288]; /* length list for huft_build */
+ unsigned l[N_MAX]; /* length list for huft_build */

DEBG("<fix");

@@ -737,10 +711,10 @@ STATIC int noinline INIT inflate_fixed(v
l[i] = 9;
for (; i < 280; i++)
l[i] = 7;
- for (; i < 288; i++) /* make a complete, but wrong code set */
+ for (; i < N_MAX; i++) /* make a complete, but wrong code set */
l[i] = 8;
bl = 7;
- if ((i = huft_build(l, 288, 257, cplens, cplext, &tl, &bl)) != 0)
+ if ((i = huft_build(l, N_MAX, 257, cplens, cplext, &tl, &bl)))
return i;

/* set up distance table */
@@ -769,7 +743,7 @@ STATIC int noinline INIT inflate_fixed(v
*
* We use `noinline' here to prevent gcc-3.5 from using too much stack space
*/
-STATIC int noinline INIT inflate_dynamic(void)
+static int noinline INIT inflate_dynamic(void)
{
int i; /* temporary variables */
unsigned j;
@@ -783,13 +757,9 @@ STATIC int noinline INIT inflate_dynamic
unsigned nb; /* number of bit length codes */
unsigned nl; /* number of literal/length codes */
unsigned nd; /* number of distance codes */
-#ifdef PKZIP_BUG_WORKAROUND
- unsigned ll[288 + 32]; /* literal/length and distance code lengths */
-#else
unsigned ll[286 + 30]; /* literal/length and distance code lengths */
-#endif
- register ulg b; /* bit buffer */
- register unsigned k; /* number of bits in bit buffer */
+ u32 b; /* bit buffer */
+ unsigned k; /* number of bits in bit buffer */

DEBG("<dyn");

@@ -807,11 +777,7 @@ STATIC int noinline INIT inflate_dynamic
NEEDBITS(4);
nb = 4 + ((unsigned)b & 0xf); /* number of bit length codes */
DUMPBITS(4);
-#ifdef PKZIP_BUG_WORKAROUND
- if (nl > 288 || nd > 32)
-#else
if (nl > 286 || nd > 30)
-#endif
return 1; /* bad lengths */

DEBG("dyn1 ");
@@ -829,7 +795,7 @@ STATIC int noinline INIT inflate_dynamic

/* build decoding table for trees--single level, 7 bit lookup */
bl = 7;
- if ((i = huft_build(ll, 19, 19, NULL, NULL, &tl, &bl)) != 0) {
+ if ((i = huft_build(ll, 19, 19, 0, 0, &tl, &bl))) {
if (i == 1)
huft_free(tl);
return i; /* incomplete code set */
@@ -892,7 +858,7 @@ STATIC int noinline INIT inflate_dynamic

/* build the decoding tables for literal/length and distance codes */
bl = lbits;
- if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl)) != 0) {
+ if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl))) {
DEBG("dyn5b ");
if (i == 1) {
error("incomplete literal tree");
@@ -902,19 +868,14 @@ STATIC int noinline INIT inflate_dynamic
}
DEBG("dyn5c ");
bd = dbits;
- if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd)) != 0) {
+ if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd))) {
DEBG("dyn5d ");
if (i == 1) {
error("incomplete distance tree");
-#ifdef PKZIP_BUG_WORKAROUND
- i = 0;
- }
-#else
huft_free(td);
}
huft_free(tl);
return i; /* incomplete code set */
-#endif
}

DEBG("dyn6 ");
@@ -939,11 +900,11 @@ STATIC int noinline INIT inflate_dynamic
/* inflate_block - decompress a deflated block
* @e: last block flag
*/
-STATIC int INIT inflate_block(int *e)
+static int INIT inflate_block(int *e)
{
unsigned t; /* block type */
- register ulg b; /* bit buffer */
- register unsigned k; /* number of bits in bit buffer */
+ u32 b; /* bit buffer */
+ unsigned k; /* number of bits in bit buffer */

DEBG("<blk");

@@ -983,30 +944,25 @@ STATIC int INIT inflate_block(int *e)
}

/* inflate - decompress an inflated entry */
-STATIC int INIT inflate(void)
+static int INIT inflate(void)
{
int e; /* last block flag */
int r; /* result code */
- unsigned h; /* maximum struct huft's malloc'ed */
void *ptr;

/* initialize window, bit buffer */
- wp = 0;
+ outcnt = 0;
bk = 0;
bb = 0;

/* decompress until the last block */
- h = 0;
do {
- hufts = 0;
gzip_mark(&ptr);
- if ((r = inflate_block(&e)) != 0) {
+ if ((r = inflate_block(&e))) {
gzip_release(&ptr);
return r;
}
gzip_release(&ptr);
- if (hufts > h)
- h = hufts;
} while (!e);

/* Undo too much lookahead. The next read will be byte aligned so we
@@ -1017,13 +973,10 @@ STATIC int INIT inflate(void)
inptr--;
}

- /* flush out slide */
- flush_output(wp);
+ /* flush out window */
+ flush_output(outcnt);

/* return success */
-#ifdef DEBUG
- fprintf(stderr, "<%u> ", h);
-#endif /* DEBUG */
return 0;
}

@@ -1033,8 +986,8 @@ STATIC int INIT inflate(void)
*
**********************************************************************/

-static ulg crc_32_tab[256];
-static ulg crc; /* initialized in makecrc() so it'll reside in bss */
+static u32 crc_32_tab[256];
+static u32 crc; /* initialized in makecrc() so it'll reside in bss */
#define CRC_VALUE (crc ^ 0xffffffffUL)

/*
@@ -1073,7 +1026,7 @@ static void INIT makecrc(void)
}

/* this is initialized here so this code could reside in ROM */
- crc = (ulg)0xffffffffUL; /* shift register contents */
+ crc = 0xffffffffUL; /* shift register contents */
}

/* gzip flag byte */
@@ -1090,11 +1043,11 @@ static void INIT makecrc(void)
*/
static int INIT gunzip(void)
{
- uch flags;
+ u8 flags;
unsigned char magic[2]; /* magic header */
char method;
- ulg orig_crc = 0; /* original crc */
- ulg orig_len = 0; /* original uncompressed length */
+ u32 orig_crc = 0; /* original crc */
+ u32 orig_len = 0; /* original uncompressed length */
int res;

magic[0] = NEXTBYTE();
@@ -1112,16 +1065,16 @@ static int INIT gunzip(void)
return -1;
}

- flags = (uch)get_byte();
- if ((flags & ENCRYPTED) != 0) {
+ flags = (u8)get_byte();
+ if (flags & ENCRYPTED) {
error("Input is encrypted");
return -1;
}
- if ((flags & CONTINUATION) != 0) {
+ if (flags & CONTINUATION) {
error("Multi part input");
return -1;
}
- if ((flags & RESERVED) != 0) {
+ if (flags & RESERVED) {
error("Input has invalid flags");
return -1;
}
@@ -1133,25 +1086,22 @@ static int INIT gunzip(void)
(void)NEXTBYTE(); /* Ignore extra flags for the moment */
(void)NEXTBYTE(); /* Ignore OS type for the moment */

- if ((flags & EXTRA_FIELD) != 0) {
+ if (flags & EXTRA_FIELD) {
unsigned len = (unsigned)NEXTBYTE();
len |= ((unsigned)NEXTBYTE()) << 8;
while (len--)
(void)NEXTBYTE();
}

- /* Get original file name if it was truncated */
- if ((flags & ORIG_NAME) != 0) {
- /* Discard the old name */
- while (NEXTBYTE() != 0) /* null */
+ /* Discard original file name if it was truncated */
+ if (flags & ORIG_NAME)
+ while (NEXTBYTE())
;
- }

/* Discard file comment if any */
- if ((flags & COMMENT) != 0) {
- while (NEXTBYTE() != 0) /* null */
+ if (flags & COMMENT)
+ while (NEXTBYTE())
;
- }

/* Decompress */
if ((res = inflate())) {
@@ -1180,15 +1130,15 @@ static int INIT gunzip(void)
/* crc32 (see algorithm.doc)
* uncompressed input size modulo 2^32
*/
- orig_crc = (ulg)NEXTBYTE();
- orig_crc |= (ulg)NEXTBYTE() << 8;
- orig_crc |= (ulg)NEXTBYTE() << 16;
- orig_crc |= (ulg)NEXTBYTE() << 24;
-
- orig_len = (ulg)NEXTBYTE();
- orig_len |= (ulg)NEXTBYTE() << 8;
- orig_len |= (ulg)NEXTBYTE() << 16;
- orig_len |= (ulg)NEXTBYTE() << 24;
+ orig_crc = (u32)NEXTBYTE();
+ orig_crc |= (u32)NEXTBYTE() << 8;
+ orig_crc |= (u32)NEXTBYTE() << 16;
+ orig_crc |= (u32)NEXTBYTE() << 24;
+
+ orig_len = (u32)NEXTBYTE();
+ orig_len |= (u32)NEXTBYTE() << 8;
+ orig_len |= (u32)NEXTBYTE() << 16;
+ orig_len |= (u32)NEXTBYTE() << 24;

/* Validate decompression */
if (orig_crc != CRC_VALUE) {

2005-10-31 21:06:13

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH 13/20] inflate: (arch) kill silly zlib typedefs

On Mon, 31 Oct 2005, Matt Mackall wrote:
> inflate: remove legacy type definitions from callers
>
> This replaces the legacy zlib typedefs and usage with kernel types in
> all the inflate users.

> -static ulg free_mem_ptr;
> -static ulg free_mem_ptr_end;
> +static u32 free_mem_ptr;
> +static u32 free_mem_ptr_end;

Bang, on 64-bit platforms...

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2005-10-31 21:19:36

by Matt Mackall

[permalink] [raw]
Subject: Re: [PATCH 13/20] inflate: (arch) kill silly zlib typedefs

On Mon, Oct 31, 2005 at 10:05:15PM +0100, Geert Uytterhoeven wrote:
> On Mon, 31 Oct 2005, Matt Mackall wrote:
> > inflate: remove legacy type definitions from callers
> >
> > This replaces the legacy zlib typedefs and usage with kernel types in
> > all the inflate users.
>
> > -static ulg free_mem_ptr;
> > -static ulg free_mem_ptr_end;
> > +static u32 free_mem_ptr;
> > +static u32 free_mem_ptr_end;
>
> Bang, on 64-bit platforms...

That was quick.

Yes, this is broken on Alpha. The other 64-bit arches use proper pointers
here. But I need to change all the arches to use the same pointer
type, probably as patch 8.5 in the series.

--
Mathematics is the supreme nostalgia of our time.

2005-10-31 22:43:10

by Russell King

[permalink] [raw]
Subject: Re: [PATCH 17/20] inflate: mark some arrays as initdata

On Mon, Oct 31, 2005 at 02:54:51PM -0600, Matt Mackall wrote:
> inflate: mark some arrays as INITDATA and define it in in-core callers

This breaks ARM. Our decompressor has some rather odd requirements
due to the way we support PIC - it's PIC text with fixed data.

This means that all fixed initialised data must be "const" or initialised
by code. This patch breaks that assertion.

--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 Serial core

2005-10-31 22:45:09

by Russell King

[permalink] [raw]
Subject: Re: [PATCH 19/20] inflate: (arch) use proper linking

On Mon, Oct 31, 2005 at 02:54:52PM -0600, Matt Mackall wrote:
> inflate: remove include of lib/inflate.c and use proper linking
>
> - make free_mem_ptr vars nonstatic
> - make gunzip nonstatic
> - add gunzip prototype to new inflate.h
> - add per-arch Makefile bits
> - change inflate.c includes to inflate.h includes
> - change NO_INFLATE_MALLOC to CORE
> - compile core kernel version of inflate with -DCORE

We need to build inflate.c with -Dstatic= to disable static data,
and text so that we get the correct binary layout for ARM PIC
decompressors. This patch breaks that.

(Unfortunately there's no other way to get GCC to produce what we
require.)

--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 Serial core

2005-10-31 23:02:56

by Matt Mackall

[permalink] [raw]
Subject: Re: [PATCH 17/20] inflate: mark some arrays as initdata

On Mon, Oct 31, 2005 at 10:43:01PM +0000, Russell King wrote:
> On Mon, Oct 31, 2005 at 02:54:51PM -0600, Matt Mackall wrote:
> > inflate: mark some arrays as INITDATA and define it in in-core callers
>
> This breaks ARM. Our decompressor has some rather odd requirements
> due to the way we support PIC - it's PIC text with fixed data.
>
> This means that all fixed initialised data must be "const" or initialised
> by code. This patch breaks that assertion.

It would have been helpful if you quoted the patch.

+#ifndef INITDATA
+#define INITDATA
+#endif
...
-static const u16 cplens[] = {
+static INITDATA u16 cplens[] = {
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
};

etc..

I think for ARM, we can simply do -DINITDATA=const, yes?

--
Mathematics is the supreme nostalgia of our time.

2005-10-31 23:07:39

by Matt Mackall

[permalink] [raw]
Subject: Re: [PATCH 19/20] inflate: (arch) use proper linking

On Mon, Oct 31, 2005 at 10:45:01PM +0000, Russell King wrote:
> On Mon, Oct 31, 2005 at 02:54:52PM -0600, Matt Mackall wrote:
> > inflate: remove include of lib/inflate.c and use proper linking
> >
> > - make free_mem_ptr vars nonstatic
> > - make gunzip nonstatic
> > - add gunzip prototype to new inflate.h
> > - add per-arch Makefile bits
> > - change inflate.c includes to inflate.h includes
> > - change NO_INFLATE_MALLOC to CORE
> > - compile core kernel version of inflate with -DCORE
>
> We need to build inflate.c with -Dstatic= to disable static data,
> and text so that we get the correct binary layout for ARM PIC
> decompressors. This patch breaks that.

So.. we need to add CFLAGS_inflate.o := -Dstatic=? Or is more needed?

--
Mathematics is the supreme nostalgia of our time.

2005-10-31 23:10:58

by Russell King

[permalink] [raw]
Subject: Re: [PATCH 17/20] inflate: mark some arrays as initdata

On Mon, Oct 31, 2005 at 02:57:46PM -0800, Matt Mackall wrote:
> On Mon, Oct 31, 2005 at 10:43:01PM +0000, Russell King wrote:
> > On Mon, Oct 31, 2005 at 02:54:51PM -0600, Matt Mackall wrote:
> > > inflate: mark some arrays as INITDATA and define it in in-core callers
> >
> > This breaks ARM. Our decompressor has some rather odd requirements
> > due to the way we support PIC - it's PIC text with fixed data.
> >
> > This means that all fixed initialised data must be "const" or initialised
> > by code. This patch breaks that assertion.
>
> It would have been helpful if you quoted the patch.

That's what threading is for. 8)

> +#ifndef INITDATA
> +#define INITDATA
> +#endif
> ...
> -static const u16 cplens[] = {
> +static INITDATA u16 cplens[] = {
> 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
> 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
> };
>
> etc..
>
> I think for ARM, we can simply do -DINITDATA=const, yes?

No, unless you want to make this const:

-static u8 window[0x8000]; /* use a statically allocated window */
+static u8 INITDATA window[0x8000]; /* use a statically allocated window */

It shouldn't be marked INITDATA either anyway - it's uninitialised so
it'll end up in the BSS. There is no "discarded at runtime" BSS so
anything you want to place in a non-BSS section has to be initialised.

Of course, if you initialise it, you end up needlessly adding 32K to
the kernel image size...

--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 Serial core

2005-10-31 23:13:49

by Russell King

[permalink] [raw]
Subject: Re: [PATCH 19/20] inflate: (arch) use proper linking

On Mon, Oct 31, 2005 at 03:02:33PM -0800, Matt Mackall wrote:
> On Mon, Oct 31, 2005 at 10:45:01PM +0000, Russell King wrote:
> > On Mon, Oct 31, 2005 at 02:54:52PM -0600, Matt Mackall wrote:
> > > inflate: remove include of lib/inflate.c and use proper linking
> > >
> > > - make free_mem_ptr vars nonstatic
> > > - make gunzip nonstatic
> > > - add gunzip prototype to new inflate.h
> > > - add per-arch Makefile bits
> > > - change inflate.c includes to inflate.h includes
> > > - change NO_INFLATE_MALLOC to CORE
> > > - compile core kernel version of inflate with -DCORE
> >
> > We need to build inflate.c with -Dstatic= to disable static data,
> > and text so that we get the correct binary layout for ARM PIC
> > decompressors. This patch breaks that.
>
> So.. we need to add CFLAGS_inflate.o := -Dstatic=? Or is more needed?

I think that'll do. Trying it in practice will tell though.

--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 Serial core

2005-10-31 23:16:27

by Matt Mackall

[permalink] [raw]
Subject: Re: [PATCH 17/20] inflate: mark some arrays as initdata

On Mon, Oct 31, 2005 at 11:10:52PM +0000, Russell King wrote:
> That's what threading is for. 8)

What's what's threading is for?

> > I think for ARM, we can simply do -DINITDATA=const, yes?
>
> No, unless you want to make this const:
>
> -static u8 window[0x8000]; /* use a statically allocated window */
> +static u8 INITDATA window[0x8000]; /* use a statically allocated window */

Ok, that bit can just be dropped. It needn't be INITDATA anyway, as it
now gets kmalloc'ed for users in the kernel proper. Anything else?

--
Mathematics is the supreme nostalgia of our time.

2005-10-31 23:36:40

by Russell King

[permalink] [raw]
Subject: Re: [PATCH 17/20] inflate: mark some arrays as initdata

On Mon, Oct 31, 2005 at 03:11:21PM -0800, Matt Mackall wrote:
> On Mon, Oct 31, 2005 at 11:10:52PM +0000, Russell King wrote:
> > That's what threading is for. 8)
>
> What's what's threading is for?
>
> > > I think for ARM, we can simply do -DINITDATA=const, yes?
> >
> > No, unless you want to make this const:
> >
> > -static u8 window[0x8000]; /* use a statically allocated window */
> > +static u8 INITDATA window[0x8000]; /* use a statically allocated window */
>
> Ok, that bit can just be dropped. It needn't be INITDATA anyway, as it
> now gets kmalloc'ed for users in the kernel proper. Anything else?

I didn't notice anything else, but it will need testing on ARM in
this configuration.

Basically, for the decompressor to work in this mode, we have to
ensure:

1. no static data
2. no initialised non-const data

gets placed into the decompressor.

--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 Serial core

2005-11-01 00:24:40

by Paul Mackerras

[permalink] [raw]
Subject: Re: [PATCH 1/20] inflate: lindent and manual formatting changes

Matt,

My concern about this series of patches is that it will make it harder
to keep the kernel zlib in sync with the upstream zlib.

Are you signing up to track the upstream zlib and apply any changes
made there to the kernel version, for the forseeable future?

Paul.

2005-11-01 01:45:07

by Matt Mackall

[permalink] [raw]
Subject: Re: [PATCH 1/20] inflate: lindent and manual formatting changes

On Tue, Nov 01, 2005 at 11:24:27AM +1100, Paul Mackerras wrote:
> Matt,
>
> My concern about this series of patches is that it will make it harder
> to keep the kernel zlib in sync with the upstream zlib.

This code is very long out of sync with the existing upstream zlib in
terms of coding style and content, so I doubt my changes will make
much difference from that perspective.

As one of my eventual goals is to get us down to exactly one copy of
this in the kernel, I think it's a step forward. This set of patches
goes a long way towards that goal by making inflate support just a
couple lines for most of the kernel uses.

> Are you signing up to track the upstream zlib and apply any changes
> made there to the kernel version, for the forseeable future?

I will fix any security-relevant bugs, provided other folks don't beat
me to them.

--
Mathematics is the supreme nostalgia of our time.

2005-11-01 07:04:30

by Willy Tarreau

[permalink] [raw]
Subject: Re: [PATCH 13/20] inflate: (arch) kill silly zlib typedefs

On Mon, Oct 31, 2005 at 01:14:22PM -0800, Matt Mackall wrote:
> On Mon, Oct 31, 2005 at 10:05:15PM +0100, Geert Uytterhoeven wrote:
> > On Mon, 31 Oct 2005, Matt Mackall wrote:
> > > inflate: remove legacy type definitions from callers
> > >
> > > This replaces the legacy zlib typedefs and usage with kernel types in
> > > all the inflate users.
> >
> > > -static ulg free_mem_ptr;
> > > -static ulg free_mem_ptr_end;
> > > +static u32 free_mem_ptr;
> > > +static u32 free_mem_ptr_end;
> >
> > Bang, on 64-bit platforms...
>
> That was quick.
>
> Yes, this is broken on Alpha. The other 64-bit arches use proper pointers
> here. But I need to change all the arches to use the same pointer
> type, probably as patch 8.5 in the series.

But if it's a pointer why don't you declare them unsigned long then ?
C defines the long as the integer the right size to store a pointer.
u32 is just a 32 bits unsigned integer, which will not always do what
you're looking for. Having read the rest of the patch, I guess you can
also make the pointer (void *) and avoid a few casts later.

Regards,
Willy

2005-11-01 08:41:05

by Rob Landley

[permalink] [raw]
Subject: Re: [PATCH 1/20] inflate: lindent and manual formatting changes

On Monday 31 October 2005 19:39, Matt Mackall wrote:
> On Tue, Nov 01, 2005 at 11:24:27AM +1100, Paul Mackerras wrote:
> > Matt,
> >
> > My concern about this series of patches is that it will make it harder
> > to keep the kernel zlib in sync with the upstream zlib.
>
> This code is very long out of sync with the existing upstream zlib in
> terms of coding style and content, so I doubt my changes will make
> much difference from that perspective.
>
> As one of my eventual goals is to get us down to exactly one copy of
> this in the kernel, I think it's a step forward. This set of patches
> goes a long way towards that goal by making inflate support just a
> couple lines for most of the kernel uses.
>
> > Are you signing up to track the upstream zlib and apply any changes
> > made there to the kernel version, for the forseeable future?
>
> I will fix any security-relevant bugs, provided other folks don't beat
> me to them.

Something that may help:

The zlib developers take down old versions because they don't want people
using out of date stuff with known security bugs, but I asked the zlib
developers nicely if they could put the history up anyway, because busybox
also contains its own somewhat-shrunk fork of the gzip code, and we want to
make sure we don't miss any security fixes. They were nice enough to
populate "http://zlib.net/fossils/", which you might find useful too.

Rob

(Not that I've had time to go through and see what if any security fixes
relevant to busybox there might be in there yet. If you find anything
interesting, could you let me know? :)

2005-11-01 07:50:53

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH 13/20] inflate: (arch) kill silly zlib typedefs

On Tue, 1 Nov 2005, Willy Tarreau wrote:
> But if it's a pointer why don't you declare them unsigned long then ?
> C defines the long as the integer the right size to store a pointer.
^
Is it C?

Since on Wintendo P64 it's not true...

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2005-11-01 09:08:29

by Willy Tarreau

[permalink] [raw]
Subject: Re: [PATCH 13/20] inflate: (arch) kill silly zlib typedefs

On Tue, Nov 01, 2005 at 08:50:43AM +0100, Geert Uytterhoeven wrote:
> On Tue, 1 Nov 2005, Willy Tarreau wrote:
> > But if it's a pointer why don't you declare them unsigned long then ?
> > C defines the long as the integer the right size to store a pointer.
> ^
> Is it C?

Yes, that's what I read quite a time ago, and it appears that it was an
interpretation of the spec which is not true anymore with LLP64 models :-(

> Since on Wintendo P64 it's not true...

I don't know if x86_64 is LP64 or LLP64 on Linux, but at least my alpha
and sparc64 are LP64, so is another PPC64 I use for code validation.
LPC64 is the recommended model for easier 32 to 64 portability (where
ints are 32 ; long, longlong, ptrs are 64).

There's an interesting reading about this here :

http://www.usenix.org/publications/login/standards/10.data.html

So Matt, you have to use void* or char* in your types.

> Gr{oetje,eeting}s,
>
> Geert

Thanks Geert for the notification, it was an opportunity to refresh my
thoughts about portability practices. I think it will be time to buy
an x86_64 :-/

Willy

2005-11-01 11:27:46

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH 13/20] inflate: (arch) kill silly zlib typedefs

On Tue, 1 Nov 2005, Willy Tarreau wrote:
> On Tue, Nov 01, 2005 at 08:50:43AM +0100, Geert Uytterhoeven wrote:
> > On Tue, 1 Nov 2005, Willy Tarreau wrote:
> > > But if it's a pointer why don't you declare them unsigned long then ?
> > > C defines the long as the integer the right size to store a pointer.
> > ^
> > Is it C?
>
> Yes, that's what I read quite a time ago, and it appears that it was an
> interpretation of the spec which is not true anymore with LLP64 models :-(
>
> > Since on Wintendo P64 it's not true...
>
> I don't know if x86_64 is LP64 or LLP64 on Linux, but at least my alpha
> and sparc64 are LP64, so is another PPC64 I use for code validation.
> LPC64 is the recommended model for easier 32 to 64 portability (where
> ints are 32 ; long, longlong, ptrs are 64).

Linux on x86_64 uses LP64, like all other 64-bit platforms Linux runs on.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2005-11-01 18:33:25

by Matt Mackall

[permalink] [raw]
Subject: Oops! Forgot [PATCH 0/20] inflate cleanups

[Just realized that my 0/20 description didn't go out, so here it is.
I'll wait a bit more before respinning the set with feedback.]

This is a refactored version of the lib/inflate.c I posted about a
year ago. It has a few end goals:

- clean up some really ugly code
- clean up atrocities like '#include "../../../lib/inflate.c"'
- drop a ton of cut and paste code from the kernel boot
- move towards making the boot decompressor pluggable
- move towards unifying the multiple inflate implementations
- save space

This touches 11 architectures, which makes things slightly
interesting. Rather than break the patches out by arch, I've gone the
route of making a number of small incremental changes that sweep
across the tree. Patches that touch the per-arch code are marked
"(arch)".

I've been primarily testing this on x86, but various versions of this
code have gotten testing on a variety of architectures as part of my
linux-tiny tree.

--
Mathematics is the supreme nostalgia of our time.

2005-11-08 06:06:43

by Miles Bader

[permalink] [raw]
Subject: Re: [PATCH 13/20] inflate: (arch) kill silly zlib typedefs

Willy Tarreau <[email protected]> writes:
> I don't know if x86_64 is LP64 or LLP64 on Linux, but at least my alpha
> and sparc64 are LP64, so is another PPC64 I use for code validation.
> LPC64 is the recommended model for easier 32 to 64 portability (where
> ints are 32 ; long, longlong, ptrs are 64).

Are there _any_ (widespread) platforms except Windows that use LLP64?

LP64 seems to be by far the most common in the unix world.

-miles
--
"1971 pickup truck; will trade for guns"

2005-11-08 06:32:40

by Willy Tarreau

[permalink] [raw]
Subject: Re: [PATCH 13/20] inflate: (arch) kill silly zlib typedefs

On Tue, Nov 08, 2005 at 03:05:57PM +0900, Miles Bader wrote:
> Willy Tarreau <[email protected]> writes:
> > I don't know if x86_64 is LP64 or LLP64 on Linux, but at least my alpha
> > and sparc64 are LP64, so is another PPC64 I use for code validation.
> > LPC64 is the recommended model for easier 32 to 64 portability (where
> > ints are 32 ; long, longlong, ptrs are 64).
>
> Are there _any_ (widespread) platforms except Windows that use LLP64?

I don't think so, ask google for LLP64 and click the second link (blogs),
you will like it :-)

Basically, they choose LLP64 because they have declared some structures
as LONG (eg: in bitmaps) instead of making them int32 ! I didn't know
that they were losers to the point of not understanding a typedef !
This may explain why they stopped supporting alpha long ago...

> LP64 seems to be by far the most common in the unix world.

it seems so, but I'd be interested in counter-examples too.

> -miles
> --
> "1971 pickup truck; will trade for guns"

Willy