Skip to content

Commit 7da05b6

Browse files
xNombrecyberknight777
authored andcommitted
lib: Update LZ4 module to v1.9.3+
Update lz4 module using official repository from revision [1]. Keep in mind lz4hc wasn't updated thus it is not used. It may not compile anymore. [1]: https://github.com/lz4/lz4/tree/4ebe313e00aa52c837ee029ede39a0503a8a39c9 Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
1 parent ec43d85 commit 7da05b6

4 files changed

Lines changed: 1749 additions & 1133 deletions

File tree

include/linux/lz4.h

Lines changed: 84 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#define __LZ4_H__
4343

4444
#include <linux/types.h>
45-
#include <linux/string.h> /* memset, memcpy */
45+
#include <linux/string.h> /* memset, memcpy */
4646

4747
/*-************************************************************************
4848
* CONSTANTS
@@ -57,23 +57,24 @@
5757
*/
5858
#define LZ4_MEMORY_USAGE 14
5959

60-
#define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
61-
#define LZ4_COMPRESSBOUND(isize) (\
62-
(unsigned int)(isize) > (unsigned int)LZ4_MAX_INPUT_SIZE \
63-
? 0 \
64-
: (isize) + ((isize)/255) + 16)
60+
#define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
61+
#define LZ4_COMPRESSBOUND(isize) \
62+
((unsigned int)(isize) > (unsigned int)LZ4_MAX_INPUT_SIZE ? \
63+
0 : \
64+
(isize) + ((isize) / 255) + 16)
6565

6666
#define LZ4_ACCELERATION_DEFAULT 1
67-
#define LZ4_HASHLOG (LZ4_MEMORY_USAGE-2)
67+
#define LZ4_ACCELERATION_MAX 65537
68+
#define LZ4_HASHLOG (LZ4_MEMORY_USAGE - 2)
6869
#define LZ4_HASHTABLESIZE (1 << LZ4_MEMORY_USAGE)
6970
#define LZ4_HASH_SIZE_U32 (1 << LZ4_HASHLOG)
7071

71-
#define LZ4HC_MIN_CLEVEL 3
72-
#define LZ4HC_DEFAULT_CLEVEL 9
73-
#define LZ4HC_MAX_CLEVEL 16
72+
#define LZ4HC_MIN_CLEVEL 3
73+
#define LZ4HC_DEFAULT_CLEVEL 9
74+
#define LZ4HC_MAX_CLEVEL 16
7475

7576
#define LZ4HC_DICTIONARY_LOGSIZE 16
76-
#define LZ4HC_MAXD (1<<LZ4HC_DICTIONARY_LOGSIZE)
77+
#define LZ4HC_MAXD (1 << LZ4HC_DICTIONARY_LOGSIZE)
7778
#define LZ4HC_MAXD_MASK (LZ4HC_MAXD - 1)
7879
#define LZ4HC_HASH_LOG (LZ4HC_DICTIONARY_LOGSIZE - 1)
7980
#define LZ4HC_HASHTABLESIZE (1 << LZ4HC_HASH_LOG)
@@ -82,51 +83,54 @@
8283
/*-************************************************************************
8384
* STREAMING CONSTANTS AND STRUCTURES
8485
**************************************************************************/
85-
#define LZ4_STREAMSIZE_U64 ((1 << (LZ4_MEMORY_USAGE - 3)) + 4)
86-
#define LZ4_STREAMSIZE (LZ4_STREAMSIZE_U64 * sizeof(unsigned long long))
86+
#define LZ4_STREAMSIZE \
87+
((1UL << LZ4_MEMORY_USAGE) + \
88+
32) /* static size, for inter-version compatibility */
89+
#define LZ4_STREAMSIZE_VOIDP (LZ4_STREAMSIZE / sizeof(void *))
8790

88-
#define LZ4_STREAMHCSIZE 262192
89-
#define LZ4_STREAMHCSIZE_SIZET (262192 / sizeof(size_t))
91+
#define LZ4_STREAMDECODESIZE_U64 \
92+
(4 + ((sizeof(void *) == 16) ? 2 : 0) /*AS-400*/)
93+
#define LZ4_STREAMDECODESIZE \
94+
(LZ4_STREAMDECODESIZE_U64 * sizeof(unsigned long long))
9095

91-
#define LZ4_STREAMDECODESIZE_U64 4
92-
#define LZ4_STREAMDECODESIZE (LZ4_STREAMDECODESIZE_U64 * \
93-
sizeof(unsigned long long))
96+
#define LZ4_STREAMHCSIZE_SIZET (262192 / sizeof(size_t))
9497

9598
/*
9699
* LZ4_stream_t - information structure to track an LZ4 stream.
97100
*/
98-
typedef struct {
101+
typedef struct LZ4_stream_t_internal LZ4_stream_t_internal;
102+
struct LZ4_stream_t_internal {
99103
uint32_t hashTable[LZ4_HASH_SIZE_U32];
100104
uint32_t currentOffset;
101-
uint32_t initCheck;
105+
uint32_t tableType;
102106
const uint8_t *dictionary;
103-
uint8_t *bufferStart;
107+
const LZ4_stream_t_internal *dictCtx;
104108
uint32_t dictSize;
105-
} LZ4_stream_t_internal;
109+
};
106110
typedef union {
107-
unsigned long long table[LZ4_STREAMSIZE_U64];
111+
void *table[LZ4_STREAMSIZE_VOIDP];
108112
LZ4_stream_t_internal internal_donotuse;
109113
} LZ4_stream_t;
110114

111115
/*
112116
* LZ4_streamHC_t - information structure to track an LZ4HC stream.
113117
*/
114118
typedef struct {
115-
unsigned int hashTable[LZ4HC_HASHTABLESIZE];
116-
unsigned short chainTable[LZ4HC_MAXD];
119+
unsigned int hashTable[LZ4HC_HASHTABLESIZE];
120+
unsigned short chainTable[LZ4HC_MAXD];
117121
/* next block to continue on current prefix */
118122
const unsigned char *end;
119123
/* All index relative to this position */
120124
const unsigned char *base;
121125
/* alternate base for extDict */
122126
const unsigned char *dictBase;
123127
/* below that point, need extDict */
124-
unsigned int dictLimit;
128+
unsigned int dictLimit;
125129
/* below that point, no more dict */
126-
unsigned int lowLimit;
130+
unsigned int lowLimit;
127131
/* index from which to continue dict update */
128-
unsigned int nextToUpdate;
129-
unsigned int compressionLevel;
132+
unsigned int nextToUpdate;
133+
unsigned int compressionLevel;
130134
} LZ4HC_CCtx_internal;
131135
typedef union {
132136
size_t table[LZ4_STREAMHCSIZE_SIZET];
@@ -153,8 +157,8 @@ typedef union {
153157
/*-************************************************************************
154158
* SIZE OF STATE
155159
**************************************************************************/
156-
#define LZ4_MEM_COMPRESS LZ4_STREAMSIZE
157-
#define LZ4HC_MEM_COMPRESS LZ4_STREAMHCSIZE
160+
#define LZ4_MEM_COMPRESS LZ4_STREAMSIZE
161+
#define LZ4HC_MEM_COMPRESS LZ4_STREAMHCSIZE
158162

159163
/*-************************************************************************
160164
* Compression Functions
@@ -195,7 +199,7 @@ static inline int LZ4_compressBound(size_t isize)
195199
* (necessarily <= maxOutputSize) or 0 if compression fails
196200
*/
197201
int LZ4_compress_default(const char *source, char *dest, int inputSize,
198-
int maxOutputSize, void *wrkmem);
202+
int maxOutputSize, void *wrkmem);
199203

200204
/**
201205
* LZ4_compress_fast() - As LZ4_compress_default providing an acceleration param
@@ -219,7 +223,7 @@ int LZ4_compress_default(const char *source, char *dest, int inputSize,
219223
* (necessarily <= maxOutputSize) or 0 if compression fails
220224
*/
221225
int LZ4_compress_fast(const char *source, char *dest, int inputSize,
222-
int maxOutputSize, int acceleration, void *wrkmem);
226+
int maxOutputSize, int acceleration, void *wrkmem);
223227

224228
/**
225229
* LZ4_compress_destSize() - Compress as much data as possible
@@ -243,33 +247,12 @@ int LZ4_compress_fast(const char *source, char *dest, int inputSize,
243247
* or 0 if compression fails
244248
*/
245249
int LZ4_compress_destSize(const char *source, char *dest, int *sourceSizePtr,
246-
int targetDestSize, void *wrkmem);
250+
int targetDestSize, void *wrkmem);
247251

248252
/*-************************************************************************
249253
* Decompression Functions
250254
**************************************************************************/
251255

252-
/**
253-
* LZ4_decompress_fast() - Decompresses data from 'source' into 'dest'
254-
* @source: source address of the compressed data
255-
* @dest: output buffer address of the uncompressed data
256-
* which must be already allocated with 'originalSize' bytes
257-
* @originalSize: is the original and therefore uncompressed size
258-
*
259-
* Decompresses data from 'source' into 'dest'.
260-
* This function fully respect memory boundaries for properly formed
261-
* compressed data.
262-
* It is a bit faster than LZ4_decompress_safe().
263-
* However, it does not provide any protection against intentionally
264-
* modified data stream (malicious input).
265-
* Use this function in trusted environment only
266-
* (data to decode comes from a trusted source).
267-
*
268-
* Return: number of bytes read from the source buffer
269-
* or a negative result if decompression fails.
270-
*/
271-
int LZ4_decompress_fast(const char *source, char *dest, int originalSize);
272-
273256
/**
274257
* LZ4_decompress_safe() - Decompression protected against buffer overflow
275258
* @source: source address of the compressed data
@@ -290,7 +273,7 @@ int LZ4_decompress_fast(const char *source, char *dest, int originalSize);
290273
* or a negative result in case of error
291274
*/
292275
int LZ4_decompress_safe(const char *source, char *dest, int compressedSize,
293-
int maxDecompressedSize);
276+
int maxDecompressedSize);
294277

295278
/**
296279
* LZ4_decompress_safe_partial() - Decompress a block of size 'compressedSize'
@@ -318,7 +301,8 @@ int LZ4_decompress_safe(const char *source, char *dest, int compressedSize,
318301
*
319302
*/
320303
int LZ4_decompress_safe_partial(const char *source, char *dest,
321-
int compressedSize, int targetOutputSize, int maxDecompressedSize);
304+
int compressedSize, int targetOutputSize,
305+
int maxDecompressedSize);
322306

323307
/*-************************************************************************
324308
* LZ4 HC Compression
@@ -344,7 +328,7 @@ int LZ4_decompress_safe_partial(const char *source, char *dest,
344328
* Return : the number of bytes written into 'dst' or 0 if compression fails.
345329
*/
346330
int LZ4_compress_HC(const char *src, char *dst, int srcSize, int dstCapacity,
347-
int compressionLevel, void *wrkmem);
331+
int compressionLevel, void *wrkmem);
348332

349333
/**
350334
* LZ4_resetStreamHC() - Init an allocated 'LZ4_streamHC_t' structure
@@ -373,8 +357,8 @@ void LZ4_resetStreamHC(LZ4_streamHC_t *streamHCPtr, int compressionLevel);
373357
*
374358
* Return : dictionary size, in bytes (necessarily <= 64 KB)
375359
*/
376-
int LZ4_loadDictHC(LZ4_streamHC_t *streamHCPtr, const char *dictionary,
377-
int dictSize);
360+
int LZ4_loadDictHC(LZ4_streamHC_t *streamHCPtr, const char *dictionary,
361+
int dictSize);
378362

379363
/**
380364
* LZ4_compress_HC_continue() - Compress 'src' using data from previously
@@ -413,7 +397,7 @@ int LZ4_loadDictHC(LZ4_streamHC_t *streamHCPtr, const char *dictionary,
413397
* Return: Number of bytes written into buffer 'dst' or 0 if compression fails
414398
*/
415399
int LZ4_compress_HC_continue(LZ4_streamHC_t *streamHCPtr, const char *src,
416-
char *dst, int srcSize, int maxDstSize);
400+
char *dst, int srcSize, int maxDstSize);
417401

418402
/**
419403
* LZ4_saveDictHC() - Save static dictionary from LZ4HC_stream
@@ -432,7 +416,7 @@ int LZ4_compress_HC_continue(LZ4_streamHC_t *streamHCPtr, const char *src,
432416
* or 0 if error.
433417
*/
434418
int LZ4_saveDictHC(LZ4_streamHC_t *streamHCPtr, char *safeBuffer,
435-
int maxDictSize);
419+
int maxDictSize);
436420

437421
/*-*********************************************
438422
* Streaming Compression Functions
@@ -462,8 +446,7 @@ void LZ4_resetStream(LZ4_stream_t *LZ4_stream);
462446
*
463447
* Return : dictionary size, in bytes (necessarily <= 64 KB)
464448
*/
465-
int LZ4_loadDict(LZ4_stream_t *streamPtr, const char *dictionary,
466-
int dictSize);
449+
int LZ4_loadDict(LZ4_stream_t *streamPtr, const char *dictionary, int dictSize);
467450

468451
/**
469452
* LZ4_saveDict() - Save static dictionary from LZ4_stream
@@ -505,7 +488,8 @@ int LZ4_saveDict(LZ4_stream_t *streamPtr, char *safeBuffer, int dictSize);
505488
* Return: Number of bytes written into buffer 'dst' or 0 if compression fails
506489
*/
507490
int LZ4_compress_fast_continue(LZ4_stream_t *streamPtr, const char *src,
508-
char *dst, int srcSize, int maxDstSize, int acceleration);
491+
char *dst, int srcSize, int maxDstSize,
492+
int acceleration);
509493

510494
/**
511495
* LZ4_setStreamDecode() - Instruct where to find dictionary
@@ -519,7 +503,7 @@ int LZ4_compress_fast_continue(LZ4_stream_t *streamPtr, const char *src,
519503
* Return: 1 if OK, 0 if error
520504
*/
521505
int LZ4_setStreamDecode(LZ4_streamDecode_t *LZ4_streamDecode,
522-
const char *dictionary, int dictSize);
506+
const char *dictionary, int dictSize);
523507

524508
/**
525509
* LZ4_decompress_fast_continue() - Decompress blocks in streaming mode
@@ -558,8 +542,32 @@ int LZ4_setStreamDecode(LZ4_streamDecode_t *LZ4_streamDecode,
558542
* or a negative result in case of error
559543
*/
560544
int LZ4_decompress_safe_continue(LZ4_streamDecode_t *LZ4_streamDecode,
561-
const char *source, char *dest, int compressedSize,
562-
int maxDecompressedSize);
545+
const char *source, char *dest,
546+
int compressedSize, int maxDecompressedSize);
547+
548+
/* \/ Following methods are disabled because they are deprecated \/ */
549+
550+
/**
551+
* LZ4_decompress_fast() - Decompresses data from 'source' into 'dest'
552+
* @source: source address of the compressed data
553+
* @dest: output buffer address of the uncompressed data
554+
* which must be already allocated with 'originalSize' bytes
555+
* @originalSize: is the original and therefore uncompressed size
556+
*
557+
* Decompresses data from 'source' into 'dest'.
558+
* This function fully respect memory boundaries for properly formed
559+
* compressed data.
560+
* It is a bit faster than LZ4_decompress_safe().
561+
* However, it does not provide any protection against intentionally
562+
* modified data stream (malicious input).
563+
* Use this function in trusted environment only
564+
* (data to decode comes from a trusted source).
565+
*
566+
* Return: number of bytes read from the source buffer
567+
* or a negative result if decompression fails.
568+
*/
569+
570+
//int LZ4_decompress_fast(const char *source, char *dest, int originalSize);
563571

564572
/**
565573
* LZ4_decompress_fast_continue() - Decompress blocks in streaming mode
@@ -596,8 +604,9 @@ int LZ4_decompress_safe_continue(LZ4_streamDecode_t *LZ4_streamDecode,
596604
* (necessarily <= maxDecompressedSize)
597605
* or a negative result in case of error
598606
*/
599-
int LZ4_decompress_fast_continue(LZ4_streamDecode_t *LZ4_streamDecode,
600-
const char *source, char *dest, int originalSize);
607+
608+
//int LZ4_decompress_fast_continue(LZ4_streamDecode_t *LZ4_streamDecode,
609+
// const char *source, char *dest, int originalSize);
601610

602611
/**
603612
* LZ4_decompress_safe_usingDict() - Same as LZ4_setStreamDecode()
@@ -619,9 +628,9 @@ int LZ4_decompress_fast_continue(LZ4_streamDecode_t *LZ4_streamDecode,
619628
* (necessarily <= maxDecompressedSize)
620629
* or a negative result in case of error
621630
*/
622-
int LZ4_decompress_safe_usingDict(const char *source, char *dest,
623-
int compressedSize, int maxDecompressedSize, const char *dictStart,
624-
int dictSize);
631+
//int LZ4_decompress_safe_usingDict(const char *source, char *dest,
632+
// int compressedSize, int maxDecompressedSize, const char *dictStart,
633+
// int dictSize);
625634

626635
/**
627636
* LZ4_decompress_fast_usingDict() - Same as LZ4_setStreamDecode()
@@ -642,7 +651,7 @@ int LZ4_decompress_safe_usingDict(const char *source, char *dest,
642651
* (necessarily <= maxDecompressedSize)
643652
* or a negative result in case of error
644653
*/
645-
int LZ4_decompress_fast_usingDict(const char *source, char *dest,
646-
int originalSize, const char *dictStart, int dictSize);
654+
//int LZ4_decompress_fast_usingDict(const char *source, char *dest,
655+
// int originalSize, const char *dictStart, int dictSize);
647656

648657
#endif

0 commit comments

Comments
 (0)