Changeset View
Changeset View
Standalone View
Standalone View
sys/modules/zlib/README
- This file was added.
Property | Old Value | New Value |
---|---|---|
svn:eol-style | null | native \ No newline at end of property |
svn:keywords | null | FreeBSD=%H \ No newline at end of property |
svn:mime-type | null | text/plain \ No newline at end of property |
Brief implementations/configuration of zlib in FreeBSD kernel | |||||
zlib 1.0.4 1996 was imported into FreeBSD kernel. | |||||
- All C files were combined into a single C file in kernel. | |||||
- Equivalent to -DNO_GZIP (not yet existed). | |||||
- zlib's crc32 implementation was excluded to avoid collision. | |||||
- FreeBSD special implementation was added for netgraph. | |||||
- Mostly with native zlib API except inflate being _zlib104_inflate. | |||||
- zcalloc/zcfree were not used at all; all callers provided its own | |||||
zcalloc/zcfree and did not let zlib use one in zlib. | |||||
zfs had zfs 1.2.3 2005 in zmod module. | |||||
- -DZ_PREFIX was enabled with special treatment of compress, compress2 | |||||
and uncompress functions prefixed with zz_. | |||||
- Did not have -DNO_GZIP. | |||||
- zmod implemented zcalloc/zcfree from zfs kernel memory. | |||||
All of zlib calls in ZFS calls its default allocator. | |||||
zlib 1.2.11 in user-land was integrated into kernel. | |||||
- Enabled -DNO_GZIP as kernel does not read nor write gz file. | |||||
- Enabled -DZ_PREFIX to avoid symbol collisions in kernel. | |||||
- ZLIB_CFLAGS and ZLIB_C options are added in kern.pre.mk and kmod.mk. | |||||
unzip 5.12 1994 is in sys/inflate.h | |||||
- used by kern/imgact_gzip.c which is for gzipped a.out. Best if we can remove. | |||||
- used by subr_inflate.c by sys/onf/Makefile.arm | |||||
- used by arm/arm/elf_trampoline.c which is converted to use ZLIB. | |||||
- included by mips/mips/elf_trampoline.c which is removed. | |||||
- kgzip and kgzldr are removed. | |||||
inflate | |||||
not defined KZIP | |||||
inflate_kernel() | |||||
% grep -R kzipmalloc sys | |||||
sys/arm/arm/elf_trampoline.c:kzipmalloc(int size) | |||||
sys/kern/subr_inflate.c:extern unsigned char *kzipmalloc (int); | |||||
sys/kern/subr_inflate.c:#define malloc(x, y, z) kzipmalloc((x)) | |||||
sys/conf/Makefile.arm: echo "#define KERNCOMPSIZE $$st_size" >>opt_kernname.h | |||||
sys/arm/arm/elf_trampoline.c: if ((size_t)(i_input - orig_input) >= KERNCOMPSIZE) { | |||||
sys/arm/arm/elf_trampoline.c: KERNCOMPSIZE - 1; /* input size */ | |||||
Questions | |||||
1 - Should we use new z_zcalloc to allocate from M_ZLIB for the ones allocates | |||||
with M_WAITOK | M_ZERO? | |||||
One benefit of each caller providing zcalloc is to allocate memory from | |||||
its own namespace. However, is it worth the cost of code duplication? | |||||
2 - Does zcalloc needs M_ZERO? calloc() does but zlib's usage don't seem to | |||||
depend on being zeros. | |||||
3 - Is mallocarray better than malloc for z_zcalloc? | |||||
Progress Notes | |||||
0 - legacy zlib in kernel was NO_GZIP. | |||||
- Few #include adjustments are made to compile ZLIB in kernel | |||||
with -DNO_GZIP option and few other tweaks. | |||||
- Adjusted Z_SOLO to include compress(), compress2(), and uncompress(). | |||||
1 - sys/crc32.h is split out of sys/libkern.h to avoid conflicts | |||||
between zlib's crc32 and system crc32. | |||||
2 - ZLIB_C is created con/kern.pre.mk to share compile paths. | |||||
-I sys/contrib/zlib | |||||
-I sys/contrib/zlib/contrib/freebsd | |||||
-DZ_PREIFX - this conflicts with zfs z_compress. However, zlib's zconf.h | |||||
-DHAVE_MEMCPY for zlib so that it uses libkern mem* functions. | |||||
-DMY_ZCALLOC is better to avoid stdlib.h. | |||||
zstd/lib/freebsd/stdlib.h helps zlib to use kernel | |||||
malloc/free/callc in zcalloc/zcfree in zutil.c. | |||||
2.1 - Added compress.c and uncompr.c for kernel to use z_compress, z_compress2, | |||||
z_uncompress, z_uncompress2, and z_compressBound. | |||||
2.2 - usr.bin/minigzip | |||||
3 - NO_GZIP compile condition has been adjusted in zlib. | |||||
This hasn't been as much as useful as zfs requires GZIP. | |||||
4 - opencryptodeflate.c | |||||
zfs.state->dummy is an address and doesn't seem to be useful. | |||||
Its DTRACE probe is removed. | |||||
5 - ZFS had had its own copy of zlib, too. | |||||
sys/cddl/contrib/opensolaris/uts/common/zmod has zlib | |||||
version 1.2.3 in 2005. | |||||
- ZFS had attached its own zcalloc/zcfree to zmod's zlib. | |||||
- ZFS had been #define'ing compress to zz_compress, compress2 to | |||||
zz_compress2, and uncompress to zz_uncompress . | |||||
- ZFS had had own implementation of z_compress and z_uncompress and | |||||
had its own API called z_compress_level(). | |||||
- ZFS uses gzip and zlib cannot be compiled with NO_GZIP. | |||||
ZFS cannot be compiled with -DZ_PREFIX of zlib. | |||||
Solaris ctf uses z_strerror() but not anyone else. | |||||
8 - Zalloc/zfrees are renamed for ease of distinguishing these functions. | |||||
Each of these is passed for zlib to allocate and free memory. | |||||
Each zalloc/zfree pair allocates differently and that is reasonable. | |||||
They are in if_mxge.c, g_unzip_zlib.c, kern_ctf.c, subr_compressor.c, | |||||
ng_deflate.c(okay), cryptodeflate.c, and zmod.c in zfs. | |||||
9 - netgraph/deflate.c needs and uses FreeBSD enhancements to zlib. | |||||
Moved sys/zlib.h to netgraph/ng_zlib.h, sys/libkern/zlib.c to | |||||
netgraph/ng_zlib.c, and netgraph/deflate.c includes netgraph/ng_zlib.c | |||||
to compile as a part of deflate.c. | |||||
Prefixed with ng_ for inflate() and deflate() to emphasize that | |||||
these are the FreeBSD specific implementations. | |||||
All of ng_zlib.h functions are marked static. | |||||
10 - sys/inflate.h | |||||
unzip 5.12 1994 | |||||
used by imgact_gzip.c | |||||
used by subr_inflate.c | |||||
used by elf_trampoline.c | |||||
11 - stand/i386/kgzldr/boot.c uses sys/inflate.h | |||||
kgzip & kgzldr has been broken and nearly dead. | |||||
kgzldr has been disconnected since 2015. | |||||
https://lists.freebsd.org/pipermail/freebsd-current/2016-January/059182.html | |||||
kgzip has been broken since 2013. | |||||
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=183666 | |||||
Bugzilla | |||||
zlib | |||||
- Consolidate multiple zlib instances in kernel | |||||
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=229763 | |||||
- Namespace conflicts between kern/inflate.c and net/zlib.c | |||||
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=191935 | |||||
kgzip + bxe | |||||
- Compiled-in bxe(4) breaks kgzip(1) kernel | |||||
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=183666 | |||||
zfs | |||||
- booting from a gzip-compressed dataset doesn't work | |||||
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=153173 |