Expose zlib's utility functions in Z_SOLO library when building kernel.

This allows kernel code to reuse zlib's implementation.

PR:		229763
Reviewed by:	Yoshihiro Ota <ota j email ne jp>
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D21156
This commit is contained in:
Xin LI 2019-08-07 01:41:17 +00:00
parent 67b3fe8ecf
commit a15cb219c6
15 changed files with 50 additions and 48 deletions

View File

@ -273,7 +273,7 @@ cddl/contrib/opensolaris/uts/common/os/callb.c optional zfs compile-with "${Z
cddl/contrib/opensolaris/uts/common/os/fm.c optional zfs compile-with "${ZFS_C}"
cddl/contrib/opensolaris/uts/common/os/list.c optional zfs compile-with "${ZFS_C}"
cddl/contrib/opensolaris/uts/common/os/nvpair_alloc_system.c optional zfs compile-with "${ZFS_C}"
cddl/contrib/opensolaris/uts/common/zmod/zmod.c optional zfs compile-with "${ZFS_C} ${ZLIB_CFLAGS}"
cddl/contrib/opensolaris/uts/common/zmod/zmod.c optional zfs compile-with "${ZFS_C}"
# zfs lua support
cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lapi.c optional zfs compile-with "${ZFS_C}"
cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lauxlib.c optional zfs compile-with "${ZFS_C}"
@ -2443,8 +2443,7 @@ mwlboot.fw optional mwlfw \
compile-with "${NORMAL_FW}" \
no-obj no-implicit-rule \
clean "mwlboot.fw"
dev/mxge/if_mxge.c optional mxge pci \
compile-with "${ZLIB_C}"
dev/mxge/if_mxge.c optional mxge pci
dev/mxge/mxge_eth_z8e.c optional mxge pci
dev/mxge/mxge_ethp_z8e.c optional mxge pci
dev/mxge/mxge_rss_eth_z8e.c optional mxge pci
@ -3999,35 +3998,32 @@ 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 | zfs | zlib
contrib/zlib/compress.c optional crypto | geom_uzip | ipsec | \
ipsec_support | mxge | ddb_ctf | gzio | zfs | zlib \
compile-with "${ZLIB_C}"
compile-with "${NORMAL_C} -Wno-cast-qual"
contrib/zlib/crc32.c optional crypto | geom_uzip | ipsec | \
ipsec_support | mxge | ddb_ctf | gzio | zfs | zlib \
compile-with "${ZLIB_C} -Wno-cast-qual"
ipsec_support | mxge | ddb_ctf | gzio | zfs | zlib
contrib/zlib/deflate.c optional crypto | geom_uzip | ipsec | \
ipsec_support | mxge | ddb_ctf | gzio | zfs | zlib \
compile-with "${ZLIB_C} -Wno-cast-qual"
compile-with "${NORMAL_C} -Wno-cast-qual"
contrib/zlib/inffast.c optional crypto | geom_uzip | ipsec | \
ipsec_support | mxge | ddb_ctf | gzio | zfs | zlib \
compile-with "${ZLIB_C}"
ipsec_support | mxge | ddb_ctf | gzio | zfs | zlib
contrib/zlib/inflate.c optional crypto | geom_uzip | ipsec | \
ipsec_support | mxge | ddb_ctf | gzio | zfs | zlib \
compile-with "${ZLIB_C}"
ipsec_support | mxge | ddb_ctf | gzio | zfs | zlib
contrib/zlib/inftrees.c optional crypto | geom_uzip | ipsec | \
ipsec_support | mxge | ddb_ctf | gzio | zfs | zlib \
compile-with "${ZLIB_C}"
ipsec_support | mxge | ddb_ctf | gzio | zfs | zlib
contrib/zlib/trees.c optional crypto | geom_uzip | ipsec | \
ipsec_support | mxge | ddb_ctf | gzio | zfs | zlib
contrib/zlib/uncompr.c optional crypto | geom_uzip | ipsec | \
ipsec_support | mxge | ddb_ctf | gzio | zfs | zlib \
compile-with "${ZLIB_C}"
compile-with "${NORMAL_C} -Wno-cast-qual"
contrib/zlib/zutil.c optional crypto | geom_uzip | ipsec | \
ipsec_support | mxge | ddb_ctf | gzio | zfs | zlib \
compile-with "${ZLIB_C}"
ipsec_support | mxge | ddb_ctf | gzio | zfs | zlib
dev/zlib/zlib_mod.c optional crypto | geom_uzip | ipsec | \
ipsec_support | mxge | ddb_ctf | gzio | zfs | zlib \
compile-with "${ZLIB_C}"
ipsec_support | mxge | ddb_ctf | gzio | zfs | zlib
dev/zlib/zcalloc.c optional crypto | geom_uzip | ipsec | \
ipsec_support | mxge | ddb_ctf | gzio | zfs | zlib \
compile-with "${ZLIB_C}"
ipsec_support | mxge | ddb_ctf | gzio | zfs | zlib
net/altq/altq_cbq.c optional altq
net/altq/altq_codel.c optional altq
net/altq/altq_hfsc.c optional altq
@ -4780,8 +4776,7 @@ opencrypto/crypto.c optional crypto | ipsec | ipsec_support
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 \
compile-with "${ZLIB_C}"
opencrypto/cryptodeflate.c optional crypto | ipsec | ipsec_support
opencrypto/gmac.c optional crypto | ipsec | ipsec_support
opencrypto/gfmult.c optional crypto | ipsec | ipsec_support
opencrypto/rmd160.c optional crypto | ipsec | ipsec_support

View File

@ -173,10 +173,6 @@ NORMAL_FW= uudecode -o ${.TARGET} ${.ALLSRC}
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}

View File

@ -104,8 +104,6 @@ __KLD_SHARED=yes
__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

View File

@ -266,7 +266,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
strm->msg = Z_NULL;
if (strm->zalloc == (alloc_func)0) {
#ifdef Z_SOLO
#if defined(Z_SOLO) && !defined(_KERNEL)
return Z_STREAM_ERROR;
#else
strm->zalloc = zcalloc;
@ -274,7 +274,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
#endif
}
if (strm->zfree == (free_func)0)
#ifdef Z_SOLO
#if defined(Z_SOLO) && !defined(_KERNEL)
return Z_STREAM_ERROR;
#else
strm->zfree = zcfree;

View File

@ -42,7 +42,7 @@ int stream_size;
return Z_STREAM_ERROR;
strm->msg = Z_NULL; /* in case we return an error */
if (strm->zalloc == (alloc_func)0) {
#ifdef Z_SOLO
#if defined(Z_SOLO) && !defined(_KERNEL)
return Z_STREAM_ERROR;
#else
strm->zalloc = zcalloc;
@ -50,7 +50,7 @@ int stream_size;
#endif
}
if (strm->zfree == (free_func)0)
#ifdef Z_SOLO
#if defined(Z_SOLO) && !defined(_KERNEL)
return Z_STREAM_ERROR;
#else
strm->zfree = zcfree;

View File

@ -207,7 +207,7 @@ int stream_size;
if (strm == Z_NULL) return Z_STREAM_ERROR;
strm->msg = Z_NULL; /* in case we return an error */
if (strm->zalloc == (alloc_func)0) {
#ifdef Z_SOLO
#if defined(Z_SOLO) && !defined(_KERNEL)
return Z_STREAM_ERROR;
#else
strm->zalloc = zcalloc;
@ -215,7 +215,7 @@ int stream_size;
#endif
}
if (strm->zfree == (free_func)0)
#ifdef Z_SOLO
#if defined(Z_SOLO) && !defined(_KERNEL)
return Z_STREAM_ERROR;
#else
strm->zfree = zcfree;

View File

@ -8,6 +8,12 @@
#ifndef ZCONF_H
#define ZCONF_H
#ifdef __FreeBSD__
#ifdef _KERNEL
#define Z_SOLO
#endif
#endif
/*
* 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.
@ -30,7 +36,7 @@
# define adler32_combine z_adler32_combine
# define adler32_combine64 z_adler32_combine64
# define adler32_z z_adler32_z
# ifndef Z_SOLO
# if !defined(Z_SOLO) && !defined(_KERNEL)
# define compress z_compress
# define compress2 z_compress2
# define compressBound z_compressBound
@ -125,12 +131,12 @@
# define inflate_copyright z_inflate_copyright
# define inflate_fast z_inflate_fast
# define inflate_table z_inflate_table
# ifndef Z_SOLO
# if !defined(Z_SOLO) && !defined(_KERNEL)
# define uncompress z_uncompress
# define uncompress2 z_uncompress2
# endif
# define zError z_zError
# ifndef Z_SOLO
# if !defined(Z_SOLO) && !defined(_KERNEL)
# define zcalloc z_zcalloc
# define zcfree z_zcfree
# endif

View File

@ -1213,7 +1213,7 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
27-31: 0 (reserved)
*/
#ifndef Z_SOLO
#if !defined(Z_SOLO) || defined(_KERNEL)
/* utility functions */
@ -1288,6 +1288,9 @@ ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen,
length of the source is *sourceLen. On return, *sourceLen is the number of
source bytes consumed.
*/
#endif /* !Z_SOLO || _KERNEL */
#ifndef Z_SOLO
/* gzip file access functions */

View File

@ -256,7 +256,7 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# define Tracecv(c,x)
#endif
#ifndef Z_SOLO
#if !defined(Z_SOLO) || defined(_KERNEL)
voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
unsigned size));
void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));

View File

@ -24,6 +24,13 @@ zcalloc_nowait(void *nil, u_int items, u_int size)
return mallocarray(items, size, M_ZLIB, M_NOWAIT);
}
void *
zcalloc(void *nil, u_int items, u_int size)
{
return zcalloc_nowait(nil, items, size);
}
void
zcfree(void *nil, void *ptr)
{

View File

@ -6,8 +6,9 @@
#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);
#include <contrib/zlib/zutil.h>
#undef local
void *zcalloc_waitok(void *, u_int, u_int);
void *zcalloc_nowait(void *, u_int, u_int);
#endif

View File

@ -23,7 +23,6 @@ KMOD = crypto
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

View File

@ -5,6 +5,4 @@
KMOD= if_mxge
SRCS= if_mxge.c device_if.h bus_if.h pci_if.h opt_inet.h opt_inet6.h
CFLAGS.if_mxge.c+= ${ZLIB_CFLAGS}
.include <bsd.kmod.mk>

View File

@ -56,7 +56,6 @@ SRCS+= nvpair_alloc_system.c
.PATH: ${SUNW}/uts/common/zmod
SRCS+= zmod.c
CFLAGS.zmod.c+= ${ZLIB_CFLAGS}
.PATH: ${SYSDIR}/crypto/sha2
SRCS+= sha256c.c sha512c.c

View File

@ -11,16 +11,16 @@ SRCS= zlib.c
SRCS+= zcalloc.c
SRCS+= zlib_mod.c
SRCS+= adler32.c
SRCS+= compress.c
SRCS+= crc32.c
SRCS+= deflate.c
SRCS+= inffast.c
SRCS+= inflate.c
SRCS+= inftrees.c
SRCS+= trees.c
SRCS+= uncompr.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