[syslinux:corezlib] core: corified zlib to support compressed btrfs
syslinux-bot for H. Peter Anvin
hpa at linux.intel.com
Thu Jul 8 08:06:06 PDT 2010
Commit-ID: 3ea40011903b1357f71e959eb3aa86df6e63bd33
Gitweb: http://syslinux.zytor.com/commit/3ea40011903b1357f71e959eb3aa86df6e63bd33
Author: H. Peter Anvin <hpa at linux.intel.com>
AuthorDate: Tue, 6 Jul 2010 15:34:02 -0700
Committer: H. Peter Anvin <hpa at linux.intel.com>
CommitDate: Tue, 6 Jul 2010 15:34:02 -0700
core: corified zlib to support compressed btrfs
Add a corified zlib, decompression support only.
Signed-off-by: H. Peter Anvin <hpa at linux.intel.com>
---
core/Makefile | 3 +-
{com32/lib => core}/zlib/adler32.c | 0
{com32/lib => core}/zlib/crc32.c | 96 ++++++++++++++---------------------
{com32/lib => core}/zlib/crc32.h | 0
{com32/lib => core}/zlib/inffast.c | 0
{com32/lib => core}/zlib/inffast.h | 0
{com32/lib => core}/zlib/inffixed.h | 0
{com32/lib => core}/zlib/inflate.c | 0
{com32/lib => core}/zlib/inflate.h | 0
{com32/lib => core}/zlib/inftrees.c | 0
{com32/lib => core}/zlib/inftrees.h | 0
{com32/lib => core}/zlib/uncompr.c | 0
{com32/lib => core}/zlib/zutil.h | 15 ++++--
13 files changed, 52 insertions(+), 62 deletions(-)
diff --git a/core/Makefile b/core/Makefile
index 1330fb9..ef98c30 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -57,7 +57,8 @@ NASMOPT += $(NASMDEBUG)
PREPCORE = ../lzo/prepcore
-# CFLAGS += -DDEBUG=1
+# Make zlib take less space
+CFLAGS += -DDYNAMIC_CRC_TABLE -DBUILDFIXED -DHAVE_MEMCPY
# The DATE is set on the make command line when building binaries for
# official release. Otherwise, substitute a hex string that is pretty much
diff --git a/com32/lib/zlib/adler32.c b/core/zlib/adler32.c
similarity index 100%
copy from com32/lib/zlib/adler32.c
copy to core/zlib/adler32.c
diff --git a/com32/lib/zlib/crc32.c b/core/zlib/crc32.c
similarity index 85%
copy from com32/lib/zlib/crc32.c
copy to core/zlib/crc32.c
index 07265c6..22450ed 100644
--- a/com32/lib/zlib/crc32.c
+++ b/core/zlib/crc32.c
@@ -18,6 +18,8 @@
first call get_crc_table() to initialize the tables before allowing more than
one thread to use crc32().
*/
+#include <endian.h>
+#include <stdbool.h>
#ifdef MAKECRCH
# include <stdio.h>
@@ -55,9 +57,7 @@
#ifdef BYFOUR
# define REV(w) ((((w)>>24)&0xff)+(((w)>>8)&0xff00)+ \
(((w)&0xff00)<<8)+(((w)&0xff)<<24))
- local unsigned long crc32_little OF((unsigned long,
- const unsigned char FAR *, unsigned));
- local unsigned long crc32_big OF((unsigned long,
+ local unsigned long crc32_byfour OF((unsigned long,
const unsigned char FAR *, unsigned));
# define TBLS 8
#else
@@ -73,7 +73,7 @@ local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2);
#ifdef DYNAMIC_CRC_TABLE
-local volatile int crc_table_empty = 1;
+local bool crc_table_empty = true;
local unsigned long FAR crc_table[TBLS][256];
local void make_crc_table OF((void));
#ifdef MAKECRCH
@@ -105,55 +105,41 @@ local void make_crc_table OF((void));
allow for word-at-a-time CRC calculation for both big-endian and little-
endian machines, where a word is four bytes.
*/
-local void make_crc_table()
+local void make_crc_table(void)
{
unsigned long c;
int n, k;
unsigned long poly; /* polynomial exclusive-or pattern */
/* terms of polynomial defining this crc (except x^32): */
- static volatile int first = 1; /* flag to limit concurrent making */
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
- /* See if another task is already doing this (not thread-safe, but better
- than nothing -- significantly reduces duration of vulnerability in
- case the advice about DYNAMIC_CRC_TABLE is ignored) */
- if (first) {
- first = 0;
-
- /* make exclusive-or pattern from polynomial (0xedb88320UL) */
- poly = 0UL;
- for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++)
- poly |= 1UL << (31 - p[n]);
-
- /* generate a crc for every 8-bit value */
- for (n = 0; n < 256; n++) {
- c = (unsigned long)n;
- for (k = 0; k < 8; k++)
- c = c & 1 ? poly ^ (c >> 1) : c >> 1;
- crc_table[0][n] = c;
- }
-
-#ifdef BYFOUR
- /* generate crc for each value followed by one, two, and three zeros,
- and then the byte reversal of those as well as the first table */
- for (n = 0; n < 256; n++) {
- c = crc_table[0][n];
- crc_table[4][n] = REV(c);
- for (k = 1; k < 4; k++) {
- c = crc_table[0][c & 0xff] ^ (c >> 8);
- crc_table[k][n] = c;
- crc_table[k + 4][n] = REV(c);
- }
- }
-#endif /* BYFOUR */
-
- crc_table_empty = 0;
+ /* make exclusive-or pattern from polynomial (0xedb88320UL) */
+ poly = 0UL;
+ for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++)
+ poly |= 1UL << (31 - p[n]);
+
+ /* generate a crc for every 8-bit value */
+ for (n = 0; n < 256; n++) {
+ c = (unsigned long)n;
+ for (k = 0; k < 8; k++)
+ c = c & 1 ? poly ^ (c >> 1) : c >> 1;
+ crc_table[0][n] = c;
}
- else { /* not first */
- /* wait for the other guy to finish (not efficient, but rare) */
- while (crc_table_empty)
- ;
+
+#ifdef BYFOUR
+ /* generate crc for each value followed by one, two, and three zeros,
+ and then the byte reversal of those as well as the first table */
+ for (n = 0; n < 256; n++) {
+ c = crc_table[0][n];
+ crc_table[4][n] = REV(c);
+ for (k = 1; k < 4; k++) {
+ c = crc_table[0][c & 0xff] ^ (c >> 8);
+ crc_table[k][n] = c;
+ crc_table[k + 4][n] = REV(c);
+ }
}
+#endif /* BYFOUR */
+ crc_table_empty = 0;
#ifdef MAKECRCH
/* write out CRC tables to crc32.h */
@@ -226,21 +212,13 @@ unsigned long ZEXPORT crc32(crc, buf, len)
if (buf == Z_NULL) return 0UL;
#ifdef DYNAMIC_CRC_TABLE
- if (crc_table_empty)
+ if (__unlikely(crc_table_empty))
make_crc_table();
#endif /* DYNAMIC_CRC_TABLE */
#ifdef BYFOUR
- if (sizeof(void *) == sizeof(ptrdiff_t)) {
- u4 endian;
-
- endian = 1;
- if (*((unsigned char *)(&endian)))
- return crc32_little(crc, buf, len);
- else
- return crc32_big(crc, buf, len);
- }
-#endif /* BYFOUR */
+ return crc32_byfour(crc, buf, len);
+#else /* BYFOUR */
crc = crc ^ 0xffffffffUL;
while (len >= 8) {
DO8;
@@ -250,10 +228,12 @@ unsigned long ZEXPORT crc32(crc, buf, len)
DO1;
} while (--len);
return crc ^ 0xffffffffUL;
+#endif
}
#ifdef BYFOUR
+#if BYTE_ORDER == LITTLE_ENDIAN
/* ========================================================================= */
#define DOLIT4 c ^= *buf4++; \
c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
@@ -261,7 +241,7 @@ unsigned long ZEXPORT crc32(crc, buf, len)
#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
/* ========================================================================= */
-local unsigned long crc32_little(crc, buf, len)
+local unsigned long crc32_byfour(crc, buf, len)
unsigned long crc;
const unsigned char FAR *buf;
unsigned len;
@@ -294,6 +274,7 @@ local unsigned long crc32_little(crc, buf, len)
return (unsigned long)c;
}
+#else /* BIG_ENDIAN */
/* ========================================================================= */
#define DOBIG4 c ^= *++buf4; \
c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
@@ -301,7 +282,7 @@ local unsigned long crc32_little(crc, buf, len)
#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
/* ========================================================================= */
-local unsigned long crc32_big(crc, buf, len)
+local unsigned long crc32_byfour(crc, buf, len)
unsigned long crc;
const unsigned char FAR *buf;
unsigned len;
@@ -336,6 +317,7 @@ local unsigned long crc32_big(crc, buf, len)
return (unsigned long)(REV(c));
}
+#endif
#endif /* BYFOUR */
#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
diff --git a/com32/lib/zlib/crc32.h b/core/zlib/crc32.h
similarity index 100%
copy from com32/lib/zlib/crc32.h
copy to core/zlib/crc32.h
diff --git a/com32/lib/zlib/inffast.c b/core/zlib/inffast.c
similarity index 100%
copy from com32/lib/zlib/inffast.c
copy to core/zlib/inffast.c
diff --git a/com32/lib/zlib/inffast.h b/core/zlib/inffast.h
similarity index 100%
copy from com32/lib/zlib/inffast.h
copy to core/zlib/inffast.h
diff --git a/com32/lib/zlib/inffixed.h b/core/zlib/inffixed.h
similarity index 100%
copy from com32/lib/zlib/inffixed.h
copy to core/zlib/inffixed.h
diff --git a/com32/lib/zlib/inflate.c b/core/zlib/inflate.c
similarity index 100%
copy from com32/lib/zlib/inflate.c
copy to core/zlib/inflate.c
diff --git a/com32/lib/zlib/inflate.h b/core/zlib/inflate.h
similarity index 100%
copy from com32/lib/zlib/inflate.h
copy to core/zlib/inflate.h
diff --git a/com32/lib/zlib/inftrees.c b/core/zlib/inftrees.c
similarity index 100%
copy from com32/lib/zlib/inftrees.c
copy to core/zlib/inftrees.c
diff --git a/com32/lib/zlib/inftrees.h b/core/zlib/inftrees.h
similarity index 100%
copy from com32/lib/zlib/inftrees.h
copy to core/zlib/inftrees.h
diff --git a/com32/lib/zlib/uncompr.c b/core/zlib/uncompr.c
similarity index 100%
copy from com32/lib/zlib/uncompr.c
copy to core/zlib/uncompr.c
diff --git a/com32/lib/zlib/zutil.h b/core/zlib/zutil.h
similarity index 97%
copy from com32/lib/zlib/zutil.h
copy to core/zlib/zutil.h
index ac2d73e..a6d7f27 100644
--- a/com32/lib/zlib/zutil.h
+++ b/core/zlib/zutil.h
@@ -261,10 +261,17 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# define Tracecv(c,x)
#endif
-
-voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
- unsigned size));
-void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
+static inline void *zcalloc(void *opaque, unsigned items, unsigned size)
+{
+ (void)opaque;
+ return zalloc(items*size);
+}
+
+static inline void zcfree(void *opaque, void *ptr)
+{
+ (void)opaque;
+ free(ptr);
+}
#define ZALLOC(strm, items, size) \
(*((strm)->zalloc))((strm)->opaque, (items), (size))
More information about the Syslinux-commits
mailing list