Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F136786385
D19706.id58858.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
14 KB
Referenced Files
None
Subscribers
None
D19706.id58858.diff
View Options
Index: sys/conf/NOTES
===================================================================
--- sys/conf/NOTES
+++ sys/conf/NOTES
@@ -2963,4 +2963,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
@@ -4032,6 +4032,42 @@
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/compress.c optional crypto | geom_uzip | ipsec | \
+ ipsec_support | mxge | ddb_ctf | gzio | zlib \
+ compile-with "${ZLIB_C} -Wno-cast-qual"
+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/uncompr.c optional crypto | geom_uzip | ipsec | \
+ ipsec_support | mxge | ddb_ctf | gzio | zlib \
+ compile-with "${ZLIB_C} -Wno-cast-qual"
+contrib/zlib/zutil.c optional crypto | geom_uzip | ipsec | \
+ ipsec_support | mxge | ddb_ctf | gzio | zlib \
+ compile-with "${ZLIB_C} -DHAVE_MEMCPY -DMY_ZCALLOC"
+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
Index: sys/conf/kern.pre.mk
===================================================================
--- sys/conf/kern.pre.mk
+++ sys/conf/kern.pre.mk
@@ -173,6 +173,12 @@
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+= -I$S/dev/zlib
+ZLIB_CFLAGS+= -DMY_ZCALLOC
+ZLIB_CFLAGS+= -DHAVE_MEMCPY
+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+= -I${SRCTOP}/sys/dev/zlib
+
.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/dev/zlib/errno.h
===================================================================
--- /dev/null
+++ sys/dev/zlib/errno.h
@@ -0,0 +1,3 @@
+/* This file is in the public domain */
+/* $FreeBSD$ */
+#include <sys/errno.h>
Index: sys/dev/zlib/fcntl.h
===================================================================
--- /dev/null
+++ sys/dev/zlib/fcntl.h
@@ -0,0 +1,3 @@
+/* This file is in the public domain */
+/* $FreeBSD$ */
+#include <sys/fcntl.h>
Index: sys/dev/zlib/limits.h
===================================================================
--- /dev/null
+++ sys/dev/zlib/limits.h
@@ -0,0 +1,3 @@
+/* This file is in the public domain */
+/* $FreeBSD$ */
+#include <sys/limits.h>
Index: sys/dev/zlib/stdarg.h
===================================================================
--- /dev/null
+++ sys/dev/zlib/stdarg.h
@@ -0,0 +1,3 @@
+/* This file is in the public domain */
+/* $FreeBSD$ */
+#include <sys/_stdarg.h>
Index: sys/dev/zlib/stddef.h
===================================================================
--- /dev/null
+++ sys/dev/zlib/stddef.h
@@ -0,0 +1,4 @@
+/* This file is in the public domain */
+/* $FreeBSD$ */
+#include <sys/param.h> /* size_t */
+#include <sys/stddef.h>
Index: sys/dev/zlib/stdio.h
===================================================================
--- /dev/null
+++ sys/dev/zlib/stdio.h
@@ -0,0 +1,2 @@
+/* This file is in the public domain */
+/* $FreeBSD$ */
Index: sys/dev/zlib/stdlib.h
===================================================================
--- /dev/null
+++ sys/dev/zlib/stdlib.h
@@ -0,0 +1,16 @@
+#ifndef _DEV_ZLIB_STDLIB_
+#define _DEV_ZLIB_STDLIB_
+
+/* This file is in the public domain */
+/* $FreeBSD$ */
+
+#define malloc kernz_malloc
+#define free kernz_free
+
+void
+*kernz_malloc(size_t size);
+
+void
+kernz_free(void *ptr);
+
+#endif
Index: sys/dev/zlib/string.h
===================================================================
--- /dev/null
+++ sys/dev/zlib/string.h
@@ -0,0 +1,3 @@
+/* This file is in the public domain */
+/* $FreeBSD$ */
+#include <sys/systm.h> /* memcpy, memset */
Index: sys/dev/zlib/zcalloc.h
===================================================================
--- /dev/null
+++ sys/dev/zlib/zcalloc.h
@@ -0,0 +1,7 @@
+#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);
+
+#endif
Index: sys/dev/zlib/zcalloc.c
===================================================================
--- /dev/null
+++ sys/dev/zlib/zcalloc.c
@@ -0,0 +1,53 @@
+#include <contrib/zlib/zutil.h>
+#include <dev/zlib/zcalloc.h>
+/* zlib expects std malloc/free and replaced to call kernz_malloc/free */
+#undef malloc
+#undef free
+#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 *
+zcalloc(void *nil, u_int items, u_int size)
+{
+
+ return zcalloc_waitok(nil, items, size);
+}
+
+void
+zcfree(void *nil, void *ptr)
+{
+
+ free(ptr, M_ZLIB);
+}
+
+void *
+kernz_malloc(size_t size)
+{
+ void *ptr;
+
+ ptr = malloc(size, M_ZLIB, M_WAITOK);
+ return ptr;
+}
+
+void
+kernz_free(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
@@ -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
@@ -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/zlib/Makefile
===================================================================
--- sys/modules/zlib/Makefile
+++ sys/modules/zlib/Makefile
@@ -1,8 +1,31 @@
# $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+= zcalloc.c
+SRCS+= adler32.c
+SRCS+= compress.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}
+CFLAGS.zutil.c+=-DMY_ZCALLOC
+CFLAGS.zutil.c+=-DHAVE_MEMCPY
+
+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
@@ -105,7 +105,7 @@
bufh = bufp = malloc(sizeof(*bufp) + (size_t)(size * i),
M_CRYPTO_DATA, M_NOWAIT);
if (bufp == NULL) {
- SDT_PROBE6(opencrypto, deflate, deflate_global, bad,
+ SDT_PROBE6(opencrypto, _zlib104_deflate, deflate_global, bad,
decomp, 0, __LINE__, 0, 0, 0);
goto bad2;
}
@@ -125,7 +125,7 @@
deflateInit2(&zbuf, Z_DEFAULT_COMPRESSION, Z_METHOD,
window_deflate, Z_MEMLEVEL, Z_DEFAULT_STRATEGY);
if (error != Z_OK) {
- SDT_PROBE6(opencrypto, deflate, deflate_global, bad,
+ SDT_PROBE6(opencrypto, _zlib104_deflate, deflate_global, bad,
decomp, error, __LINE__, 0, 0, 0);
goto bad;
}
@@ -134,12 +134,12 @@
error = decomp ? inflate(&zbuf, Z_SYNC_FLUSH) :
deflate(&zbuf, Z_FINISH);
if (error != Z_OK && error != Z_STREAM_END) {
- SDT_PROBE6(opencrypto, deflate, deflate_global, bad,
+ SDT_PROBE6(opencrypto, _zlib104_deflate, deflate_global, bad,
decomp, error, __LINE__,
zbuf.avail_in, zbuf.avail_out, zbuf.total_out);
goto bad;
}
- SDT_PROBE6(opencrypto, deflate, deflate_global, iter,
+ SDT_PROBE6(opencrypto, _zlib104_deflate, deflate_global, iter,
decomp, error, __LINE__,
zbuf.avail_in, zbuf.avail_out, zbuf.total_out);
if (decomp && zbuf.avail_in == 0 && error == Z_STREAM_END) {
@@ -155,7 +155,7 @@
p = malloc(sizeof(*p) + (size_t)(size * i),
M_CRYPTO_DATA, M_NOWAIT);
if (p == NULL) {
- SDT_PROBE6(opencrypto, deflate, deflate_global,
+ SDT_PROBE6(opencrypto, _zlib104_deflate, deflate_global,
bad, decomp, 0, __LINE__, 0, 0, 0);
goto bad;
}
@@ -167,7 +167,7 @@
zbuf.avail_out = bufp->size;
} else {
/* Unexpect result. */
- SDT_PROBE6(opencrypto, deflate, deflate_global, bad,
+ SDT_PROBE6(opencrypto, _zlib104_deflate, deflate_global, bad,
decomp, error, __LINE__,
zbuf.avail_in, zbuf.avail_out, zbuf.total_out);
goto bad;
@@ -178,7 +178,7 @@
*out = malloc(result, M_CRYPTO_DATA, M_NOWAIT);
if (*out == NULL) {
- SDT_PROBE6(opencrypto, deflate, deflate_global, bad,
+ SDT_PROBE6(opencrypto, _zlib104_deflate, deflate_global, bad,
decomp, 0, __LINE__, 0, 0, 0);
goto bad;
}
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)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 20, 1:16 PM (2 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
25727369
Default Alt Text
D19706.id58858.diff (14 KB)
Attached To
Mode
D19706: Allow Kernel to link in both legacy libkern/zlib and new sys/contrib/zlib.
Attached
Detach File
Event Timeline
Log In to Comment