lib/zstd/decompress/zstd_decompress_block.c
Source file repositories/reference/linux-study-clean/lib/zstd/decompress/zstd_decompress_block.c
File Facts
- System
- Linux kernel
- Corpus path
lib/zstd/decompress/zstd_decompress_block.c- Extension
.c- Size
- 101454 bytes
- Lines
- 2211
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: implementation source
- Status
- source implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
Dependency Surface
../common/zstd_deps.h../common/compiler.h../common/cpu.h../common/mem.h../common/fse.h../common/huf.h../common/zstd_internal.hzstd_decompress_internal.hzstd_ddict.hzstd_decompress_block.h../common/bits.h
Detected Declarations
function Copyrightfunction ZSTD_blockSizeMaxfunction ZSTD_getcBlockSizefunction ZSTD_allocateLiteralsBufferfunction ZSTD_decodeLiteralsBlockfunction ZSTD_decodeLiteralsBlock_wrapperfunction ZSTD_buildSeqTable_rlefunction symbolfunction probabilityfunction ZSTD_buildFSETable_body_defaultfunction ZSTD_buildFSETable_body_bmi2function ZSTD_buildFSETablefunction ZSTD_buildSeqTablefunction ZSTD_decodeSeqHeadersfunction ZSTD_overlapCopy8function memcpyfunction ZSTD_safecopyDstBeforeSrcfunction ZSTD_execSequenceEndfunction ZSTD_execSequenceEndSplitLitBufferfunction ZSTD_execSequencefunction ZSTD_execSequenceSplitLitBufferfunction ZSTD_initFseStatefunction ZSTD_updateFseStateWithDInfofunction ZSTD_decodeSequencefunction ZSTD_dictionaryIsActivefunction ZSTD_assertValidSequencefunction ZSTD_decompressSequences_bodySplitLitBufferfunction ZSTD_decompressSequences_bodyfunction ZSTD_decompressSequences_defaultfunction ZSTD_decompressSequencesSplitLitBuffer_defaultfunction ZSTD_prefetchMatchfunction ZSTD_decompressSequencesLong_bodyfunction ZSTD_decompressSequencesLong_defaultfunction ZSTD_decompressSequences_bmi2function ZSTD_decompressSequencesSplitLitBuffer_bmi2function ZSTD_decompressSequencesLong_bmi2function ZSTD_decompressSequencesfunction ZSTD_decompressSequencesSplitLitBufferfunction ZSTD_decompressSequencesLongfunction ZSTD_totalHistorySizefunction offunction ZSTD_maxShortOffsetfunction ZSTD_decompressBlock_internalfunction ZSTD_checkContinuityfunction ZSTD_decompressBlock_deprecatedfunction ZSTD_decompressBlock
Annotated Snippet
static void ZSTD_copy4(void* dst, const void* src) { ZSTD_memcpy(dst, src, 4); }
/*-*************************************************************
* Block decoding
***************************************************************/
static size_t ZSTD_blockSizeMax(ZSTD_DCtx const* dctx)
{
size_t const blockSizeMax = dctx->isFrameDecompression ? dctx->fParams.blockSizeMax : ZSTD_BLOCKSIZE_MAX;
assert(blockSizeMax <= ZSTD_BLOCKSIZE_MAX);
return blockSizeMax;
}
/*! ZSTD_getcBlockSize() :
* Provides the size of compressed block from block header `src` */
size_t ZSTD_getcBlockSize(const void* src, size_t srcSize,
blockProperties_t* bpPtr)
{
RETURN_ERROR_IF(srcSize < ZSTD_blockHeaderSize, srcSize_wrong, "");
{ U32 const cBlockHeader = MEM_readLE24(src);
U32 const cSize = cBlockHeader >> 3;
bpPtr->lastBlock = cBlockHeader & 1;
bpPtr->blockType = (blockType_e)((cBlockHeader >> 1) & 3);
bpPtr->origSize = cSize; /* only useful for RLE */
if (bpPtr->blockType == bt_rle) return 1;
RETURN_ERROR_IF(bpPtr->blockType == bt_reserved, corruption_detected, "");
return cSize;
}
}
/* Allocate buffer for literals, either overlapping current dst, or split between dst and litExtraBuffer, or stored entirely within litExtraBuffer */
static void ZSTD_allocateLiteralsBuffer(ZSTD_DCtx* dctx, void* const dst, const size_t dstCapacity, const size_t litSize,
const streaming_operation streaming, const size_t expectedWriteSize, const unsigned splitImmediately)
{
size_t const blockSizeMax = ZSTD_blockSizeMax(dctx);
assert(litSize <= blockSizeMax);
assert(dctx->isFrameDecompression || streaming == not_streaming);
assert(expectedWriteSize <= blockSizeMax);
if (streaming == not_streaming && dstCapacity > blockSizeMax + WILDCOPY_OVERLENGTH + litSize + WILDCOPY_OVERLENGTH) {
/* If we aren't streaming, we can just put the literals after the output
* of the current block. We don't need to worry about overwriting the
* extDict of our window, because it doesn't exist.
* So if we have space after the end of the block, just put it there.
*/
dctx->litBuffer = (BYTE*)dst + blockSizeMax + WILDCOPY_OVERLENGTH;
dctx->litBufferEnd = dctx->litBuffer + litSize;
dctx->litBufferLocation = ZSTD_in_dst;
} else if (litSize <= ZSTD_LITBUFFEREXTRASIZE) {
/* Literals fit entirely within the extra buffer, put them there to avoid
* having to split the literals.
*/
dctx->litBuffer = dctx->litExtraBuffer;
dctx->litBufferEnd = dctx->litBuffer + litSize;
dctx->litBufferLocation = ZSTD_not_in_dst;
} else {
assert(blockSizeMax > ZSTD_LITBUFFEREXTRASIZE);
/* Literals must be split between the output block and the extra lit
* buffer. We fill the extra lit buffer with the tail of the literals,
* and put the rest of the literals at the end of the block, with
* WILDCOPY_OVERLENGTH of buffer room to allow for overreads.
* This MUST not write more than our maxBlockSize beyond dst, because in
* streaming mode, that could overwrite part of our extDict window.
*/
if (splitImmediately) {
/* won't fit in litExtraBuffer, so it will be split between end of dst and extra buffer */
dctx->litBuffer = (BYTE*)dst + expectedWriteSize - litSize + ZSTD_LITBUFFEREXTRASIZE - WILDCOPY_OVERLENGTH;
dctx->litBufferEnd = dctx->litBuffer + litSize - ZSTD_LITBUFFEREXTRASIZE;
} else {
/* initially this will be stored entirely in dst during huffman decoding, it will partially be shifted to litExtraBuffer after */
dctx->litBuffer = (BYTE*)dst + expectedWriteSize - litSize;
dctx->litBufferEnd = (BYTE*)dst + expectedWriteSize;
}
dctx->litBufferLocation = ZSTD_split;
assert(dctx->litBufferEnd <= (BYTE*)dst + expectedWriteSize);
}
}
/*! ZSTD_decodeLiteralsBlock() :
* Where it is possible to do so without being stomped by the output during decompression, the literals block will be stored
* in the dstBuffer. If there is room to do so, it will be stored in full in the excess dst space after where the current
* block will be output. Otherwise it will be stored at the end of the current dst blockspace, with a small portion being
* stored in dctx->litExtraBuffer to help keep it "ahead" of the current output write.
*
* @return : nb of bytes read from src (< srcSize )
* note : symbol not declared but exposed for fullbench */
static size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx,
const void* src, size_t srcSize, /* note : srcSize < BLOCKSIZE */
void* dst, size_t dstCapacity, const streaming_operation streaming)
Annotation
- Immediate include surface: `../common/zstd_deps.h`, `../common/compiler.h`, `../common/cpu.h`, `../common/mem.h`, `../common/fse.h`, `../common/huf.h`, `../common/zstd_internal.h`, `zstd_decompress_internal.h`.
- Detected declarations: `function Copyright`, `function ZSTD_blockSizeMax`, `function ZSTD_getcBlockSize`, `function ZSTD_allocateLiteralsBuffer`, `function ZSTD_decodeLiteralsBlock`, `function ZSTD_decodeLiteralsBlock_wrapper`, `function ZSTD_buildSeqTable_rle`, `function symbol`, `function probability`, `function ZSTD_buildFSETable_body_default`.
- Atlas domain: Kernel Services / lib.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.