Date: Sat, 2 Nov 2019 21:02:54 +0000 (UTC) From: Toomas Soome <tsoome@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r354265 - in head: cddl/lib/libzpool sys/cddl/contrib/opensolaris/common/lz4 Message-ID: <201911022102.xA2L2sQq098040@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: tsoome Date: Sat Nov 2 21:02:54 2019 New Revision: 354265 URL: https://svnweb.freebsd.org/changeset/base/354265 Log: r354253 did miss the fact that libzpool is built as fake kernel We build libzpool as kernel like, use _FAKE_KERNEL check to include kernel api in libzpool. Added: head/sys/cddl/contrib/opensolaris/common/lz4/lz4.c - copied, changed from r354249, head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lz4.c head/sys/cddl/contrib/opensolaris/common/lz4/lz4.h (contents, props changed) Replaced: head/sys/cddl/contrib/opensolaris/common/lz4/ Modified: head/cddl/lib/libzpool/Makefile Modified: head/cddl/lib/libzpool/Makefile ============================================================================== --- head/cddl/lib/libzpool/Makefile Sat Nov 2 20:46:45 2019 (r354264) +++ head/cddl/lib/libzpool/Makefile Sat Nov 2 21:02:54 2019 (r354265) @@ -65,6 +65,8 @@ CFLAGS+= -DWANTS_MUTEX_OWNED CFLAGS+= -I${SRCTOP}/lib/libpthread/thread CFLAGS+= -I${SRCTOP}/lib/libpthread/sys CFLAGS+= -I${SRCTOP}/lib/libthr/arch/${MACHINE_CPUARCH}/include +CFLAGS.lz4.o+= -D_FAKE_KERNEL +CFLAGS.lz4.pico+= -D_FAKE_KERNEL CFLAGS.gcc+= -fms-extensions LIBADD= md pthread z nvpair avl umem Copied and modified: head/sys/cddl/contrib/opensolaris/common/lz4/lz4.c (from r354249, head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lz4.c) ============================================================================== --- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lz4.c Sat Nov 2 09:50:36 2019 (r354249, copy source) +++ head/sys/cddl/contrib/opensolaris/common/lz4/lz4.c Sat Nov 2 21:02:54 2019 (r354265) @@ -35,11 +35,29 @@ * Copyright (c) 2016 by Delphix. All rights reserved. */ +#if defined(_KERNEL) || defined(_FAKE_KERNEL) #include <sys/zfs_context.h> +#elif defined(_STANDALONE) +#include <sys/cdefs.h> +#include <stand.h> +#include <sys/types.h> +#include <sys/endian.h> +#include <assert.h> +#define ASSERT assert +#else +#include <string.h> +#include <stdlib.h> +#include <sys/types.h> +#include <netinet/in.h> +#include <assert.h> + +#define ASSERT assert +#endif +#include <lz4.h> + static int real_LZ4_compress(const char *source, char *dest, int isize, int osize); -static int LZ4_compressBound(int isize); static int LZ4_uncompress_unknownOutputSize(const char *source, char *dest, int isize, int maxOutputSize); static int LZ4_compressCtx(void *ctx, const char *source, char *dest, @@ -47,11 +65,13 @@ static int LZ4_compressCtx(void *ctx, const char *sour static int LZ4_compress64kCtx(void *ctx, const char *source, char *dest, int isize, int osize); +#if defined(_KERNEL) || defined(_FAKE_KERNEL) static kmem_cache_t *lz4_ctx_cache; +#endif -/*ARGSUSED*/ size_t -lz4_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n) +lz4_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, + int n __unused) { uint32_t bufsiz; char *dest = d_start; @@ -71,17 +91,25 @@ lz4_compress(void *s_start, void *d_start, size_t s_le * added to the compressed buffer and which, if unhandled, would * confuse the hell out of our decompression function. */ - *(uint32_t *)dest = BE_32(bufsiz); +#if defined(_KERNEL) || defined(_FAKE_KERNEL) + *(uint32_t *)(void *)dest = BE_32(bufsiz); +#else + *(uint32_t *)(void *)dest = htonl(bufsiz); +#endif return (bufsiz + sizeof (bufsiz)); } -/*ARGSUSED*/ int -lz4_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n) +lz4_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len, + int n __unused) { const char *src = s_start; - uint32_t bufsiz = BE_IN32(src); +#if defined(_KERNEL) || defined(_FAKE_KERNEL) + uint32_t bufsiz = BE_IN32(s_start); +#else + uint32_t bufsiz = htonl(*(uint32_t *)s_start); +#endif /* invalid compressed buffer size encoded at start */ if (bufsiz + sizeof (bufsiz) > s_len) @@ -105,20 +133,10 @@ lz4_decompress(void *s_start, void *d_start, size_t s_ * or 0 if the compression fails (if LZ4_COMPRESSMIN is set). * note : destination buffer must be already allocated. * destination buffer must be sized to handle worst cases - * situations (input data not compressible) worst case size - * evaluation is provided by function LZ4_compressBound(). + * situations (input data not compressible). * * Advanced Functions * - * LZ4_compressBound() : - * Provides the maximum size that LZ4 may output in a "worst case" - * scenario (input data not compressible) primarily useful for memory - * allocation of output buffer. - * - * isize : is the input size. Max supported value is ~1.9GB - * return : maximum output size in a "worst case" scenario - * note : this function is limited by "int" range (2^31-1) - * * LZ4_uncompress_unknownOutputSize() : * isize : is the input size, therefore the compressed size * maxOutputSize : is the size of the destination buffer (which must be @@ -292,9 +310,9 @@ typedef struct _U64_S { #pragma pack() #endif -#define A64(x) (((U64_S *)(x))->v) -#define A32(x) (((U32_S *)(x))->v) -#define A16(x) (((U16_S *)(x))->v) +#define A64(x) (((U64_S *)(__DECONST(void *, x)))->v) +#define A32(x) (((U32_S *)(__DECONST(void *, x)))->v) +#define A16(x) (((U16_S *)(__DECONST(void *, x)))->v) /* * Constants @@ -456,14 +474,6 @@ LZ4_NbCommonBytes(register U32 val) #endif -/* Public functions */ - -static int -LZ4_compressBound(int isize) -{ - return (isize + (isize / 255) + 16); -} - /* Compression functions */ /*ARGSUSED*/ @@ -478,7 +488,7 @@ LZ4_compressCtx(void *ctx, const char *source, char *d HTYPE HashTable[HASHTABLESIZE] = { 0 }; #endif - const BYTE *ip = (BYTE *) source; + const BYTE *ip = (const BYTE *) source; INITBASE(base); const BYTE *anchor = ip; const BYTE *const iend = ip + isize; @@ -527,7 +537,7 @@ LZ4_compressCtx(void *ctx, const char *source, char *d } while ((ref < ip - MAX_DISTANCE) || (A32(ref) != A32(ip))); /* Catch up */ - while ((ip > anchor) && (ref > (BYTE *) source) && + while ((ip > anchor) && (ref > (const BYTE *) source) && unlikely(ip[-1] == ref[-1])) { ip--; ref--; @@ -673,7 +683,7 @@ LZ4_compress64kCtx(void *ctx, const char *source, char U16 HashTable[HASH64KTABLESIZE] = { 0 }; #endif - const BYTE *ip = (BYTE *) source; + const BYTE *ip = (const BYTE *) source; const BYTE *anchor = ip; const BYTE *const base = ip; const BYTE *const iend = ip + isize; @@ -720,7 +730,7 @@ LZ4_compress64kCtx(void *ctx, const char *source, char } while (A32(ref) != A32(ip)); /* Catch up */ - while ((ip > anchor) && (ref > (BYTE *) source) && + while ((ip > anchor) && (ref > (const BYTE *) source) && (ip[-1] == ref[-1])) { ip--; ref--; @@ -847,7 +857,11 @@ static int real_LZ4_compress(const char *source, char *dest, int isize, int osize) { #if HEAPMODE +#if defined(_KERNEL) || defined(_FAKE_KERNEL) void *ctx = kmem_cache_alloc(lz4_ctx_cache, KM_NOSLEEP); +#else + void *ctx = malloc(sizeof(struct refTables)); +#endif int result; /* @@ -863,7 +877,11 @@ real_LZ4_compress(const char *source, char *dest, int else result = LZ4_compressCtx(ctx, source, dest, isize, osize); +#if defined(_KERNEL) || defined(_FAKE_KERNEL) kmem_cache_free(lz4_ctx_cache, ctx); +#else + free(ctx); +#endif return (result); #else if (isize < (int)LZ4_64KLIMIT) @@ -876,7 +894,7 @@ real_LZ4_compress(const char *source, char *dest, int /* * Note: The decoding function LZ4_uncompress_unknownOutputSize() is safe - * against "buffer overflow" attack type. They will never write nor + * against "buffer overflow" attack type. It will never write nor * read outside of the provided output buffers. * LZ4_uncompress_unknownOutputSize() also insures that it will never * read outside of the input buffer. A corrupted input will produce @@ -1010,9 +1028,10 @@ LZ4_uncompress_unknownOutputSize(const char *source, c /* write overflow error detected */ _output_error: - return (int)(-(((char *)ip) - source)); + return (int)(-(((const char *)ip) - source)); } +#if defined(_KERNEL) || defined(_FAKE_KERNEL) extern void lz4_init(void) { @@ -1031,3 +1050,4 @@ lz4_fini(void) kmem_cache_destroy(lz4_ctx_cache); #endif } +#endif /* _KERNEL || _FAKE_KERNEL */ Added: head/sys/cddl/contrib/opensolaris/common/lz4/lz4.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/cddl/contrib/opensolaris/common/lz4/lz4.h Sat Nov 2 21:02:54 2019 (r354265) @@ -0,0 +1,50 @@ +/* + * LZ4 - Fast LZ compression algorithm + * Header File + * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * You can contact the author at : + * - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html + * - LZ4 source repository : http://code.google.com/p/lz4/ + */ + +#ifndef _LZ4_H +#define _LZ4_H + +#include <sys/types.h> + +#ifdef __cplusplus +extern "C" { +#endif + +extern size_t lz4_compress(void *, void *, size_t, size_t, int); +extern int lz4_decompress(void *, void *, size_t, size_t, int); + +#ifdef __cplusplus +} +#endif + +#endif /* _LZ4_H */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201911022102.xA2L2sQq098040>