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,9 @@ __KLD_SHARED=no .endif +ZLIB_CFLAGS+= -DZ_SOLO +ZLIB_CFLAGS+= -DMY_CALLOC + .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/gzguts.h =================================================================== --- sys/contrib/zlib/gzguts.h +++ sys/contrib/zlib/gzguts.h @@ -22,14 +22,18 @@ #include "zlib.h" #ifdef STDC # include -# include +# if !defined(NO_GZIP) +# include +# endif # include #endif #ifndef _POSIX_SOURCE # define _POSIX_SOURCE #endif -#include +#if !defined(NO_GZIP) +# include +#endif #ifdef _WIN32 # include @@ -124,15 +128,17 @@ #endif /* get errno and strerror definition */ -#if defined UNDER_CE -# include -# define zstrerror() gz_strwinerror((DWORD)GetLastError()) -#else -# ifndef NO_STRERROR -# include -# define zstrerror() strerror(errno) +#if !defined(NO_GZIP) +# if defined UNDER_CE +# include +# define zstrerror() gz_strwinerror((DWORD)GetLastError()) # else -# define zstrerror() "stdio error (consult errno)" +# ifndef NO_STRERROR +# include +# define zstrerror() strerror(errno) +# else +# define zstrerror() "stdio error (consult errno)" +# endif # endif #endif Index: sys/contrib/zlib/zconf.h =================================================================== --- sys/contrib/zlib/zconf.h +++ sys/contrib/zlib/zconf.h @@ -440,13 +440,11 @@ #endif #ifdef STDC -# ifndef Z_SOLO # include /* for off_t */ -# endif #endif #if defined(STDC) || defined(Z_HAVE_STDARG_H) -# ifndef Z_SOLO +# if !defined(Z_SOLO) && !defined(NO_GZIP) # include /* for va_list */ # endif #endif Index: sys/contrib/zlib/zlib.h =================================================================== --- sys/contrib/zlib/zlib.h +++ sys/contrib/zlib/zlib.h @@ -1898,7 +1898,7 @@ ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, const char *mode)); #endif -#if defined(STDC) || defined(Z_HAVE_STDARG_H) +#if !defined(NO_GZIP) && (defined(STDC) || defined(Z_HAVE_STDARG_H)) # ifndef Z_SOLO ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file, const char *format, Index: sys/contrib/zlib/zutil.h =================================================================== --- sys/contrib/zlib/zutil.h +++ sys/contrib/zlib/zutil.h @@ -253,7 +253,7 @@ # define Tracecv(c,x) #endif -#ifndef Z_SOLO +#if !defined(Z_SOLO) || defined(MY_ZCALLOC) voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, unsigned size)); void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); Index: sys/dev/zlib/zlib_mod.c =================================================================== --- /dev/null +++ sys/dev/zlib/zlib_mod.c @@ -0,0 +1,24 @@ +#include +#include +#include +#include + +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 #include #include -#include -#include # define HAVE_MEMCPY #else @@ -5390,25 +5388,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,27 @@ # $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+= 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 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 @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include #include @@ -60,6 +60,12 @@ int window_inflate = -1 * MAX_WBITS; int window_deflate = -12; +static void * +crypto_zalloc(void *nil, u_int type, u_int size); + +static void +crypto_zfree(void *nil, void *ptr); + /* * This function takes a block of data and (de)compress it using the deflate * algorithm @@ -113,8 +119,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 +173,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; } @@ -228,9 +234,7 @@ } void * -z_alloc(nil, type, size) - void *nil; - u_int type, size; +crypto_zalloc(void *nil, u_int type, u_int size) { void *ptr; @@ -239,8 +243,8 @@ } void -z_free(nil, ptr) - void *nil, *ptr; +crypto_zfree(void *nil, void *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 - #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,42 @@ * 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 deflate_copyright zlib104_deflate_copyright +# define inflate_copyright zlib104_inflate_copyright -# 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 +515,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));