Page MenuHomeFreeBSD

D19706.id59565.diff
No OneTemporary

D19706.id59565.diff

Index: sys/conf/NOTES
===================================================================
--- sys/conf/NOTES
+++ sys/conf/NOTES
@@ -2981,4 +2981,6 @@
# Enable legacy /dev/spigenN name aliases for /dev/spigenX.Y devices.
options SPIGEN_LEGACY_CDEVNAME # legacy device names for spigen
+# Compression supports.
+device zlib # gzip/zlib compression/decompression library
device xz # xz_embedded LZMA de-compression library
Index: sys/conf/files
===================================================================
--- sys/conf/files
+++ sys/conf/files
@@ -4005,6 +4005,36 @@
libkern/timingsafe_bcmp.c standard
libkern/zlib.c optional crypto | geom_uzip | ipsec | \
ipsec_support | mxge | netgraph_deflate | ddb_ctf | gzio
+contrib/zlib/adler32.c optional crypto | geom_uzip | ipsec | \
+ ipsec_support | mxge | ddb_ctf | gzio | zlib \
+ compile-with "${ZLIB_C}"
+contrib/zlib/crc32.c optional crypto | geom_uzip | ipsec | \
+ ipsec_support | mxge | ddb_ctf | gzio | zlib \
+ compile-with "${ZLIB_C} -Wno-cast-qual"
+contrib/zlib/deflate.c optional crypto | geom_uzip | ipsec | \
+ ipsec_support | mxge | ddb_ctf | gzio | zlib \
+ compile-with "${ZLIB_C} -Wno-cast-qual"
+contrib/zlib/inffast.c optional crypto | geom_uzip | ipsec | \
+ ipsec_support | mxge | ddb_ctf | gzio | zlib \
+ compile-with "${ZLIB_C}"
+contrib/zlib/inflate.c optional crypto | geom_uzip | ipsec | \
+ ipsec_support | mxge | ddb_ctf | gzio | zlib \
+ compile-with "${ZLIB_C}"
+contrib/zlib/inftrees.c optional crypto | geom_uzip | ipsec | \
+ ipsec_support | mxge | ddb_ctf | gzio | zlib \
+ compile-with "${ZLIB_C}"
+contrib/zlib/trees.c optional crypto | geom_uzip | ipsec | \
+ ipsec_support | mxge | ddb_ctf | gzio | zlib \
+ compile-with "${ZLIB_C}"
+contrib/zlib/zutil.c optional crypto | geom_uzip | ipsec | \
+ ipsec_support | mxge | ddb_ctf | gzio | zlib \
+ compile-with "${ZLIB_C}"
+dev/zlib/zlib_mod.c optional crypto | geom_uzip | ipsec | \
+ ipsec_support | mxge | ddb_ctf | gzio | zlib \
+ compile-with "${ZLIB_C}"
+dev/zlib/zcalloc.c optional crypto | geom_uzip | ipsec | \
+ ipsec_support | mxge | ddb_ctf | gzio | zlib \
+ compile-with "${ZLIB_C}"
net/altq/altq_cbq.c optional altq
net/altq/altq_codel.c optional altq
net/altq/altq_hfsc.c optional altq
@@ -4756,7 +4786,8 @@
opencrypto/cryptodev.c optional cryptodev
opencrypto/cryptodev_if.m optional crypto | ipsec | ipsec_support
opencrypto/cryptosoft.c optional crypto | ipsec | ipsec_support
-opencrypto/cryptodeflate.c optional crypto | ipsec | ipsec_support
+opencrypto/cryptodeflate.c optional crypto | ipsec | ipsec_support \
+ compile-with "${ZLIB_C}"
opencrypto/gmac.c optional crypto | ipsec | ipsec_support
opencrypto/gfmult.c optional crypto | ipsec | ipsec_support
opencrypto/rmd160.c optional crypto | ipsec | ipsec_support
Index: sys/conf/kern.pre.mk
===================================================================
--- sys/conf/kern.pre.mk
+++ sys/conf/kern.pre.mk
@@ -173,6 +173,10 @@
NORMAL_FWO= ${LD} -b binary --no-warn-mismatch -d -warn-common -r \
-m ${LD_EMULATION} -o ${.TARGET} ${.ALLSRC:M*.fw}
+# for zlib in the kernel
+ZLIB_CFLAGS+= -DZ_SOLO
+ZLIB_C= ${CC} -c ${ZLIB_CFLAGS} ${CFLAGS} ${.IMPSRC}
+
# for ZSTD in the kernel (include zstd/lib/freebsd before other CFLAGS)
ZSTD_C= ${CC} -c -DZSTD_HEAPMODE=1 -I$S/contrib/zstd/lib/freebsd ${CFLAGS} -I$S/contrib/zstd/lib -I$S/contrib/zstd/lib/common ${WERROR} -Wno-inline -Wno-missing-prototypes ${PROF} -U__BMI__ ${.IMPSRC}
Index: sys/conf/kmod.mk
===================================================================
--- sys/conf/kmod.mk
+++ sys/conf/kmod.mk
@@ -104,6 +104,8 @@
__KLD_SHARED=no
.endif
+ZLIB_CFLAGS+= -DZ_SOLO
+
.if !empty(CFLAGS:M-O[23s]) && empty(CFLAGS:M-fno-strict-aliasing)
CFLAGS+= -fno-strict-aliasing
.endif
Index: sys/contrib/zlib/deflate.c
===================================================================
--- sys/contrib/zlib/deflate.c
+++ sys/contrib/zlib/deflate.c
@@ -1622,8 +1622,10 @@
/* Maximum stored block length in deflate format (not including header). */
#define MAX_STORED 65535
+#if !defined(MIN)
/* Minimum of a and b. */
#define MIN(a, b) ((a) > (b) ? (b) : (a))
+#endif
/* ===========================================================================
* Copy without compression as much as possible from the input stream, return
Index: sys/contrib/zlib/zconf.h
===================================================================
--- sys/contrib/zlib/zconf.h
+++ sys/contrib/zlib/zconf.h
@@ -503,6 +503,10 @@
/*
* This is hard-configured for FreeBSD.
*/
+#ifdef Z_SOLO
+# include <sys/types.h> /* for off_t */
+#endif
+
#define z_off_t off_t
#ifndef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 64
Index: sys/dev/zlib/zcalloc.h
===================================================================
--- /dev/null
+++ sys/dev/zlib/zcalloc.h
@@ -0,0 +1,8 @@
+#ifndef _DEV_ZLIB_ZCALLOC_
+#define _DEV_ZLIB_ZCALLOC_
+
+void * zcalloc_waitok(void *nil, u_int items, u_int size);
+void * zcalloc_nowait(void *nil, u_int items, u_int size);
+void zcfree(void *nil, void *ptr);
+
+#endif
Index: sys/dev/zlib/zcalloc.c
===================================================================
--- /dev/null
+++ sys/dev/zlib/zcalloc.c
@@ -0,0 +1,27 @@
+#include <sys/param.h>
+#include <dev/zlib/zcalloc.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+
+MALLOC_DEFINE(M_ZLIB, "zlib", "ZLIB Compressor");
+
+void *
+zcalloc_waitok(void *nil, u_int items, u_int size)
+{
+
+ return mallocarray(items, size, M_ZLIB, M_WAITOK);
+}
+
+void *
+zcalloc_nowait(void *nil, u_int items, u_int size)
+{
+
+ return mallocarray(items, size, M_ZLIB, M_NOWAIT);
+}
+
+void
+zcfree(void *nil, void *ptr)
+{
+
+ free(ptr, M_ZLIB);
+}
Index: sys/dev/zlib/zlib_mod.c
===================================================================
--- /dev/null
+++ sys/dev/zlib/zlib_mod.c
@@ -0,0 +1,24 @@
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+
+static int
+zlib_modevent(module_t mod, int type, void *unused)
+{
+ switch (type) {
+ case MOD_LOAD:
+ return 0;
+ case MOD_UNLOAD:
+ return 0;
+ }
+ return EINVAL;
+}
+
+static moduledata_t zlib_mod = {
+ "zlib",
+ zlib_modevent,
+ 0
+};
+DECLARE_MODULE(zlib, zlib_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
+MODULE_VERSION(zlib, 1);
Index: sys/libkern/zlib.c
===================================================================
--- sys/libkern/zlib.c
+++ sys/libkern/zlib.c
@@ -25,14 +25,14 @@
#define MY_ZCALLOC
#if defined(__FreeBSD__) && defined(_KERNEL)
-#define _tr_init _zlib104_tr_init
-#define _tr_align _zlib104_tr_align
-#define _tr_tally _zlib104_tr_tally
-#define _tr_flush_block _zlib104_tr_flush_block
-#define _tr_stored_block _zlib104_tr_stored_block
-#define inflate_fast _zlib104_inflate_fast
-#define inflate _zlib104_inflate
-#define zlibVersion _zlib104_Version
+#define _tr_init zlib104_tr_init
+#define _tr_align zlib104_tr_align
+#define _tr_tally zlib104_tr_tally
+#define _tr_flush_block zlib104_tr_flush_block
+#define _tr_stored_block zlib104_tr_stored_block
+#define inflate_fast zlib104_inflate_fast
+#define inflate zlib104_inflate
+#define zlibVersion zlib104_Version
#endif
@@ -65,8 +65,6 @@
#include <sys/time.h>
#include <sys/systm.h>
#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/module.h>
# define HAVE_MEMCPY
#else
@@ -602,7 +600,6 @@
/* #include "deflate.h" */
-char deflate_copyright[] = " deflate 1.0.4 Copyright 1995-1996 Jean-loup Gailly ";
/*
If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot
@@ -4109,7 +4106,6 @@
/* #include "zutil.h" */
/* #include "inftrees.h" */
-char inflate_copyright[] = " inflate 1.0.4 Copyright 1995-1996 Mark Adler ";
/*
If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot
@@ -5390,25 +5386,3 @@
return (s2 << 16) | s1;
}
/* --- adler32.c */
-
-#ifdef _KERNEL
-static int
-zlib_modevent(module_t mod, int type, void *unused)
-{
- switch (type) {
- case MOD_LOAD:
- return 0;
- case MOD_UNLOAD:
- return 0;
- }
- return EINVAL;
-}
-
-static moduledata_t zlib_mod = {
- "zlib",
- zlib_modevent,
- 0
-};
-DECLARE_MODULE(zlib, zlib_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
-MODULE_VERSION(zlib, 1);
-#endif /* _KERNEL */
Index: sys/modules/crypto/Makefile
===================================================================
--- sys/modules/crypto/Makefile
+++ sys/modules/crypto/Makefile
@@ -23,6 +23,7 @@
SRCS = crypto.c cryptodev_if.c
SRCS += criov.c cryptosoft.c xform.c
SRCS += cast.c cryptodeflate.c rmd160.c rijndael-alg-fst.c rijndael-api.c rijndael-api-fst.c
+CFLAGS.cryptodeflate.c += ${ZLIB_CFLAGS}
SRCS += skipjack.c bf_enc.c bf_ecb.c bf_skey.c
SRCS += camellia.c camellia-api.c
SRCS += des_ecb.c des_enc.c des_setkey.c
Index: sys/modules/zlib/Makefile
===================================================================
--- sys/modules/zlib/Makefile
+++ sys/modules/zlib/Makefile
@@ -1,8 +1,28 @@
# $FreeBSD$
.PATH: ${SRCTOP}/sys/libkern
+.PATH: ${SRCTOP}/sys/dev/zlib
+.PATH: ${SRCTOP}/sys/contrib/zlib
KMOD= zlib
+# legacy zlib - 1.0.4
SRCS= zlib.c
+# newer zlib - 1.2.11
+SRCS+= zcalloc.c
+SRCS+= zlib_mod.c
+SRCS+= adler32.c
+SRCS+= crc32.c
+SRCS+= deflate.c
+SRCS+= inffast.c
+SRCS+= inflate.c
+SRCS+= inftrees.c
+SRCS+= trees.c
+SRCS+= zutil.c
+
+CFLAGS+=${ZLIB_CFLAGS}
+
+CWARNFLAGS.compress.c+=-Wno-cast-qual # compress:49
+CWARNFLAGS.deflate.c+=-Wno-cast-qual # deflate.c:415
+CWARNFLAGS.uncompr.c+=-Wno-cast-qual # uncompr:49
.include <bsd.kmod.mk>
Index: sys/opencrypto/cryptodeflate.c
===================================================================
--- sys/opencrypto/cryptodeflate.c
+++ sys/opencrypto/cryptodeflate.c
@@ -29,7 +29,7 @@
/*
* This file contains a wrapper around the deflate algo compression
- * functions using the zlib library (see libkern/zlib.c and sys/zlib.h})
+ * functions using the zlib library (see sys/contrib/zlib)
*/
#include <sys/cdefs.h>
@@ -42,7 +42,7 @@
#include <sys/kernel.h>
#include <sys/sdt.h>
#include <sys/systm.h>
-#include <sys/zlib.h>
+#include <contrib/zlib/zlib.h>
#include <opencrypto/cryptodev.h>
#include <opencrypto/deflate.h>
@@ -60,6 +60,22 @@
int window_inflate = -1 * MAX_WBITS;
int window_deflate = -12;
+static void *
+crypto_zalloc(void *nil, u_int type, u_int size)
+{
+ void *ptr;
+
+ ptr = malloc(type *size, M_CRYPTO_DATA, M_NOWAIT);
+ return ptr;
+}
+
+static void
+crypto_zfree(void *nil, void *ptr)
+{
+
+ free(ptr, M_CRYPTO_DATA);
+}
+
/*
* This function takes a block of data and (de)compress it using the deflate
* algorithm
@@ -113,8 +129,8 @@
bufp->size = size * i;
bzero(&zbuf, sizeof(z_stream));
- zbuf.zalloc = z_alloc;
- zbuf.zfree = z_free;
+ zbuf.zalloc = crypto_zalloc;
+ zbuf.zfree = crypto_zfree;
zbuf.opaque = Z_NULL;
zbuf.next_in = data; /* Data that is going to be processed. */
zbuf.avail_in = size; /* Total length of data to be processed. */
@@ -167,8 +183,8 @@
zbuf.avail_out = bufp->size;
} else {
/* Unexpect result. */
- SDT_PROBE6(opencrypto, deflate, deflate_global, bad,
- decomp, error, __LINE__,
+ SDT_PROBE6(opencrypto, deflate, deflate_global,
+ bad, decomp, error, __LINE__,
zbuf.avail_in, zbuf.avail_out, zbuf.total_out);
goto bad;
}
@@ -225,22 +241,4 @@
bad2:
*out = NULL;
return 0;
-}
-
-void *
-z_alloc(nil, type, size)
- void *nil;
- u_int type, size;
-{
- void *ptr;
-
- ptr = malloc(type *size, M_CRYPTO_DATA, M_NOWAIT);
- return ptr;
-}
-
-void
-z_free(nil, ptr)
- void *nil, *ptr;
-{
- free(ptr, M_CRYPTO_DATA);
}
Index: sys/opencrypto/deflate.h
===================================================================
--- sys/opencrypto/deflate.h
+++ sys/opencrypto/deflate.h
@@ -36,16 +36,12 @@
#ifndef _CRYPTO_DEFLATE_H_
#define _CRYPTO_DEFLATE_H_
-#include <sys/zlib.h>
-
#define Z_METHOD 8
#define Z_MEMLEVEL 8
#define MINCOMP 2 /* won't be used, but must be defined */
#define ZBUF 10
u_int32_t deflate_global(u_int8_t *, u_int32_t, int, u_int8_t **);
-void *z_alloc(void *, u_int, u_int);
-void z_free(void *, void *);
/*
* We are going to use a combined allocation to hold the metadata
Index: sys/sys/zlib.h
===================================================================
--- sys/sys/zlib.h
+++ sys/sys/zlib.h
@@ -72,40 +72,40 @@
* If you *really* need a unique prefix for all types and library functions,
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
*/
-#ifdef Z_PREFIX
-# define deflateInit_ z_deflateInit_
-# define deflate z_deflate
-# define deflateEnd z_deflateEnd
-# define inflateInit_ z_inflateInit_
-# define inflate z_inflate
-# define inflateEnd z_inflateEnd
-# define deflateInit2_ z_deflateInit2_
-# define deflateSetDictionary z_deflateSetDictionary
-# define deflateCopy z_deflateCopy
-# define deflateReset z_deflateReset
-# define deflateParams z_deflateParams
-# define inflateInit2_ z_inflateInit2_
-# define inflateSetDictionary z_inflateSetDictionary
-# define inflateSync z_inflateSync
-# define inflateReset z_inflateReset
-# define compress z_compress
-# define uncompress z_uncompress
-# define adler32 z_adler32
+#ifdef _KERNEL
+# define deflateInit_ zlib104_deflateInit_
+# define deflate zlib104_deflate
+# define deflateEnd zlib104_deflateEnd
+# define inflateInit_ zlib104_inflateInit_
+# define inflate zlib104_inflate
+# define inflateEnd zlib104_inflateEnd
+# define deflateInit2_ zlib104_deflateInit2_
+# define deflateSetDictionary zlib104_deflateSetDictionary
+# define deflateCopy zlib104_deflateCopy
+# define deflateReset zlib104_deflateReset
+# define deflateParams zlib104_deflateParams
+# define inflateInit2_ zlib104_inflateInit2_
+# define inflateSetDictionary zlib104_inflateSetDictionary
+# define inflateSync zlib104_inflateSync
+# define inflateReset zlib104_inflateReset
+# define compress zlib104_compress
+# define uncompress zlib104_uncompress
+# define adler32 zlib104_adler32
#if 0
-# define crc32 z_crc32
-# define get_crc_table z_get_crc_table
+# define crc32 zlib104_crc32
+# define get_crc_table zlib104_get_crc_table
#endif
-# define Byte z_Byte
-# define uInt z_uInt
-# define uLong z_uLong
-# define Bytef z_Bytef
-# define charf z_charf
-# define intf z_intf
-# define uIntf z_uIntf
-# define uLongf z_uLongf
-# define voidpf z_voidpf
-# define voidp z_voidp
+# define Byte zlib104_Byte
+# define uInt zlib104_uInt
+# define uLong zlib104_uLong
+# define Bytef zlib104_Bytef
+# define charf zlib104_charf
+# define intf zlib104_intf
+# define uIntf zlib104_uIntf
+# define uLongf zlib104_uLongf
+# define voidpf zlib104_voidpf
+# define voidp zlib104_voidp
#endif
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
@@ -513,7 +513,7 @@
*/
#if defined(__FreeBSD__) && defined(_KERNEL)
-#define inflate _zlib104_inflate /* FreeBSD already has an inflate :-( */
+#define inflate zlib104_inflate /* FreeBSD already has an inflate :-( */
#endif
extern int EXPORT inflate OF((z_streamp strm, int flush));

File Metadata

Mime Type
text/plain
Expires
Sat, Oct 25, 10:25 AM (7 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
24169888
Default Alt Text
D19706.id59565.diff (14 KB)

Event Timeline