/* * Copyright (c) Meta Platforms, Inc. and affiliates. * All rights reserved. * * This source code is licensed under both the BSD-style license (found in the * LICENSE file in the root directory of this source tree) and the GPLv2 (found * in the COPYING file in the root directory of this source tree). * You may select, at your option, one of the above-listed licenses. */ /*-************************************* * Dependencies ***************************************/ #include "../common/allocations.h" /* ZSTD_customMalloc, ZSTD_customCalloc, ZSTD_customFree */ #include "../common/zstd_deps.h" /* INT_MAX, ZSTD_memset, ZSTD_memcpy */ #include "../common/mem.h" #include "../common/error_private.h" #include "hist.h" /* HIST_countFast_wksp */ #define FSE_STATIC_LINKING_ONLY /* FSE_encodeSymbol */ #include "../common/fse.h" #include "../common/huf.h" #include "zstd_compress_internal.h" #include "zstd_compress_sequences.h" #include "zstd_compress_literals.h" #include "zstd_fast.h" #include "zstd_double_fast.h" #include "zstd_lazy.h" #include "zstd_opt.h" #include "zstd_ldm.h" #include "zstd_compress_superblock.h" #include "../common/bits.h" /* ZSTD_highbit32 */ /* Frame serialization lives in Rust. Keep its interface scalar so the * large, configuration-sensitive CCtx parameter structure stays in C. */ size_t ZSTD_rust_writeFrameHeader(void* dst, size_t dstCapacity, int noDictIDFlag, int checksumFlag, int contentSizeFlag, int format, U32 windowLog, U64 pledgedSrcSize, U32 dictID); void ZSTD_rust_writeBlockHeader(void* op, size_t cSize, size_t blockSize, U32 lastBlock); int ZSTD_rust_updateFrameProgression(unsigned long long* consumedSrcSize, unsigned long long* producedCSize, unsigned long long pledgedSrcSizePlusOne, size_t srcSize, size_t cSize, size_t fhSize); size_t ZSTD_rust_setPledgedSrcSize(int streamStage, unsigned long long pledgedSrcSize, unsigned long long* pledgedSrcSizePlusOne); typedef size_t (*ZSTD_rust_resetCStreamReset_f)(void* context); typedef size_t (*ZSTD_rust_resetCStreamSetPledgedSrcSize_f)( void* context, unsigned long long pledgedSrcSize); typedef struct { void* callbackContext; ZSTD_rust_resetCStreamReset_f resetSession; ZSTD_rust_resetCStreamSetPledgedSrcSize_f setPledgedSrcSize; } ZSTD_rust_resetCStreamState; size_t ZSTD_rust_resetCStream(const ZSTD_rust_resetCStreamState* state, unsigned long long pss); typedef char ZSTD_rust_reset_cstream_state_layout[ (offsetof(ZSTD_rust_resetCStreamState, callbackContext) == 0 && offsetof(ZSTD_rust_resetCStreamState, resetSession) == sizeof(void*) && offsetof(ZSTD_rust_resetCStreamState, setPledgedSrcSize) == 2 * sizeof(void*) && sizeof(ZSTD_rust_resetCStreamState) == 3 * sizeof(void*)) ? 1 : -1]; typedef size_t (*ZSTD_rust_initCStreamUsingCDictAdvancedReset_f)(void* context); typedef size_t (*ZSTD_rust_initCStreamUsingCDictAdvancedSetPledgedSrcSize_f)( void* context, unsigned long long pledgedSrcSize); typedef void (*ZSTD_rust_initCStreamUsingCDictAdvancedSetFrameParams_f)( void* context, unsigned contentSizeFlag, unsigned checksumFlag, unsigned noDictIDFlag); typedef size_t (*ZSTD_rust_initCStreamUsingCDictAdvancedRefCDict_f)( void* context, const void* cdict); typedef struct { void* callbackContext; ZSTD_rust_initCStreamUsingCDictAdvancedReset_f resetSession; ZSTD_rust_initCStreamUsingCDictAdvancedSetPledgedSrcSize_f setPledgedSrcSize; ZSTD_rust_initCStreamUsingCDictAdvancedSetFrameParams_f setFrameParams; ZSTD_rust_initCStreamUsingCDictAdvancedRefCDict_f refCDict; } ZSTD_rust_initCStreamUsingCDictAdvancedState; size_t ZSTD_rust_initCStreamUsingCDictAdvanced( const ZSTD_rust_initCStreamUsingCDictAdvancedState* state, unsigned long long pledgedSrcSize, unsigned contentSizeFlag, unsigned checksumFlag, unsigned noDictIDFlag, const void* cdict); typedef char ZSTD_rust_init_cstream_using_cdict_advanced_state_layout[ (offsetof(ZSTD_rust_initCStreamUsingCDictAdvancedState, callbackContext) == 0 && offsetof(ZSTD_rust_initCStreamUsingCDictAdvancedState, resetSession) == sizeof(void*) && offsetof(ZSTD_rust_initCStreamUsingCDictAdvancedState, setPledgedSrcSize) == 2 * sizeof(void*) && offsetof(ZSTD_rust_initCStreamUsingCDictAdvancedState, setFrameParams) == 3 * sizeof(void*) && offsetof(ZSTD_rust_initCStreamUsingCDictAdvancedState, refCDict) == 4 * sizeof(void*) && sizeof(ZSTD_rust_initCStreamUsingCDictAdvancedState) == 5 * sizeof(void*)) ? 1 : -1]; typedef struct { void* callbackContext; ZSTD_rust_initCStreamUsingCDictAdvancedReset_f resetSession; ZSTD_rust_initCStreamUsingCDictAdvancedRefCDict_f refCDict; } ZSTD_rust_initCStreamUsingCDictState; size_t ZSTD_rust_initCStreamUsingCDict( const ZSTD_rust_initCStreamUsingCDictState* state, const void* cdict); typedef char ZSTD_rust_init_cstream_using_cdict_state_layout[ (offsetof(ZSTD_rust_initCStreamUsingCDictState, callbackContext) == 0 && offsetof(ZSTD_rust_initCStreamUsingCDictState, resetSession) == sizeof(void*) && offsetof(ZSTD_rust_initCStreamUsingCDictState, refCDict) == 2 * sizeof(void*) && sizeof(ZSTD_rust_initCStreamUsingCDictState) == 3 * sizeof(void*)) ? 1 : -1]; typedef size_t (*ZSTD_rust_initCStreamSrcSizeSetLevel_f)( void* context, int compressionLevel); typedef struct { void* callbackContext; ZSTD_rust_initCStreamUsingCDictAdvancedReset_f resetSession; ZSTD_rust_initCStreamUsingCDictAdvancedRefCDict_f refCDict; ZSTD_rust_initCStreamSrcSizeSetLevel_f setLevel; ZSTD_rust_initCStreamUsingCDictAdvancedSetPledgedSrcSize_f setPledgedSrcSize; } ZSTD_rust_initCStreamSrcSizeState; size_t ZSTD_rust_initCStreamSrcSize( const ZSTD_rust_initCStreamSrcSizeState* state, unsigned long long pss, int compressionLevel); typedef char ZSTD_rust_init_cstream_src_size_state_layout[ (offsetof(ZSTD_rust_initCStreamSrcSizeState, callbackContext) == 0 && offsetof(ZSTD_rust_initCStreamSrcSizeState, resetSession) == sizeof(void*) && offsetof(ZSTD_rust_initCStreamSrcSizeState, refCDict) == 2 * sizeof(void*) && offsetof(ZSTD_rust_initCStreamSrcSizeState, setLevel) == 3 * sizeof(void*) && offsetof(ZSTD_rust_initCStreamSrcSizeState, setPledgedSrcSize) == 4 * sizeof(void*) && sizeof(ZSTD_rust_initCStreamSrcSizeState) == 5 * sizeof(void*)) ? 1 : -1]; typedef struct { void* callbackContext; ZSTD_rust_initCStreamUsingCDictAdvancedReset_f resetSession; ZSTD_rust_initCStreamUsingCDictAdvancedRefCDict_f refCDict; ZSTD_rust_initCStreamSrcSizeSetLevel_f setLevel; } ZSTD_rust_initCStreamState; size_t ZSTD_rust_initCStream(const ZSTD_rust_initCStreamState* state, int compressionLevel); typedef char ZSTD_rust_init_cstream_state_layout[ (offsetof(ZSTD_rust_initCStreamState, callbackContext) == 0 && offsetof(ZSTD_rust_initCStreamState, resetSession) == sizeof(void*) && offsetof(ZSTD_rust_initCStreamState, refCDict) == 2 * sizeof(void*) && offsetof(ZSTD_rust_initCStreamState, setLevel) == 3 * sizeof(void*) && sizeof(ZSTD_rust_initCStreamState) == 4 * sizeof(void*)) ? 1 : -1]; typedef size_t (*ZSTD_rust_initCStreamUsingDictLoadDictionary_f)( void* context, const void* dict, size_t dictSize); typedef struct { void* callbackContext; ZSTD_rust_initCStreamUsingCDictAdvancedReset_f resetSession; ZSTD_rust_initCStreamSrcSizeSetLevel_f setLevel; ZSTD_rust_initCStreamUsingDictLoadDictionary_f loadDictionary; } ZSTD_rust_initCStreamUsingDictState; size_t ZSTD_rust_initCStreamUsingDict( const ZSTD_rust_initCStreamUsingDictState* state, const void* dict, size_t dictSize, int compressionLevel); typedef char ZSTD_rust_init_cstream_using_dict_state_layout[ (offsetof(ZSTD_rust_initCStreamUsingDictState, callbackContext) == 0 && offsetof(ZSTD_rust_initCStreamUsingDictState, resetSession) == sizeof(void*) && offsetof(ZSTD_rust_initCStreamUsingDictState, setLevel) == 2 * sizeof(void*) && offsetof(ZSTD_rust_initCStreamUsingDictState, loadDictionary) == 3 * sizeof(void*) && sizeof(ZSTD_rust_initCStreamUsingDictState) == 4 * sizeof(void*)) ? 1 : -1]; typedef size_t (*ZSTD_rust_initCStreamAdvancedCheckCParams_f)( void* context, ZSTD_compressionParameters cParams); typedef void (*ZSTD_rust_initCStreamAdvancedSetZstdParams_f)( void* context, const ZSTD_parameters* params); typedef struct { void* callbackContext; ZSTD_rust_initCStreamUsingCDictAdvancedReset_f resetSession; ZSTD_rust_initCStreamUsingCDictAdvancedSetPledgedSrcSize_f setPledgedSrcSize; ZSTD_rust_initCStreamAdvancedCheckCParams_f checkCParams; ZSTD_rust_initCStreamAdvancedSetZstdParams_f setZstdParams; ZSTD_rust_initCStreamUsingDictLoadDictionary_f loadDictionary; } ZSTD_rust_initCStreamAdvancedState; size_t ZSTD_rust_initCStreamAdvanced( const ZSTD_rust_initCStreamAdvancedState* state, const ZSTD_parameters* params, unsigned long long pss, const void* dict, size_t dictSize); typedef char ZSTD_rust_init_cstream_advanced_state_layout[ (offsetof(ZSTD_rust_initCStreamAdvancedState, callbackContext) == 0 && offsetof(ZSTD_rust_initCStreamAdvancedState, resetSession) == sizeof(void*) && offsetof(ZSTD_rust_initCStreamAdvancedState, setPledgedSrcSize) == 2 * sizeof(void*) && offsetof(ZSTD_rust_initCStreamAdvancedState, checkCParams) == 3 * sizeof(void*) && offsetof(ZSTD_rust_initCStreamAdvancedState, setZstdParams) == 4 * sizeof(void*) && offsetof(ZSTD_rust_initCStreamAdvancedState, loadDictionary) == 5 * sizeof(void*) && sizeof(ZSTD_rust_initCStreamAdvancedState) == 6 * sizeof(void*)) ? 1 : -1]; typedef size_t (*ZSTD_rust_setCParamsCheckCParams_f)( void* context, ZSTD_compressionParameters cParams); typedef size_t (*ZSTD_rust_setCParamsSetParameter_f)( void* context, int param, int value); typedef struct { void* callbackContext; ZSTD_rust_setCParamsCheckCParams_f checkCParams; ZSTD_rust_setCParamsSetParameter_f setParameter; } ZSTD_rust_setCParamsState; size_t ZSTD_rust_setCParams(const ZSTD_rust_setCParamsState* state, ZSTD_compressionParameters cParams); typedef char ZSTD_rust_set_cparams_state_layout[ (offsetof(ZSTD_rust_setCParamsState, callbackContext) == 0 && offsetof(ZSTD_rust_setCParamsState, checkCParams) == sizeof(void*) && offsetof(ZSTD_rust_setCParamsState, setParameter) == 2 * sizeof(void*) && sizeof(ZSTD_rust_setCParamsState) == 3 * sizeof(void*)) ? 1 : -1]; typedef size_t (*ZSTD_rust_setFParamsSetParameter_f)( void* context, int param, int value); typedef struct { void* callbackContext; ZSTD_rust_setFParamsSetParameter_f setParameter; } ZSTD_rust_setFParamsState; size_t ZSTD_rust_setFParams(const ZSTD_rust_setFParamsState* state, ZSTD_frameParameters fParams); typedef char ZSTD_rust_set_fparams_state_layout[ (offsetof(ZSTD_rust_setFParamsState, callbackContext) == 0 && offsetof(ZSTD_rust_setFParamsState, setParameter) == sizeof(void*) && sizeof(ZSTD_rust_setFParamsState) == 2 * sizeof(void*)) ? 1 : -1]; typedef size_t (*ZSTD_rust_setParamsCheckCParams_f)( void* context, ZSTD_compressionParameters cParams); typedef size_t (*ZSTD_rust_setParamsSetFParams_f)( void* context, ZSTD_frameParameters fParams); typedef size_t (*ZSTD_rust_setParamsSetCParams_f)( void* context, ZSTD_compressionParameters cParams); typedef struct { void* callbackContext; ZSTD_rust_setParamsCheckCParams_f checkCParams; ZSTD_rust_setParamsSetFParams_f setFParams; ZSTD_rust_setParamsSetCParams_f setCParams; } ZSTD_rust_setParamsState; size_t ZSTD_rust_setParams(const ZSTD_rust_setParamsState* state, ZSTD_parameters params); typedef char ZSTD_rust_set_params_state_layout[ (offsetof(ZSTD_rust_setParamsState, callbackContext) == 0 && offsetof(ZSTD_rust_setParamsState, checkCParams) == sizeof(void*) && offsetof(ZSTD_rust_setParamsState, setFParams) == 2 * sizeof(void*) && offsetof(ZSTD_rust_setParamsState, setCParams) == 3 * sizeof(void*) && sizeof(ZSTD_rust_setParamsState) == 4 * sizeof(void*)) ? 1 : -1]; typedef struct { ZSTD_CCtx_params* requestedParams; const ZSTD_CCtx_params* sourceParams; int streamStage; const void* cdict; } ZSTD_rust_setParametersUsingCCtxParamsState; size_t ZSTD_rust_setParametersUsingCCtxParams( const ZSTD_rust_setParametersUsingCCtxParamsState* state); typedef char ZSTD_rust_set_parameters_using_cctx_params_state_layout[ (offsetof(ZSTD_rust_setParametersUsingCCtxParamsState, requestedParams) == 0 && offsetof(ZSTD_rust_setParametersUsingCCtxParamsState, sourceParams) == sizeof(void*) && offsetof(ZSTD_rust_setParametersUsingCCtxParamsState, streamStage) == 2 * sizeof(void*) && offsetof(ZSTD_rust_setParametersUsingCCtxParamsState, cdict) == 3 * sizeof(void*) && sizeof(ZSTD_rust_setParametersUsingCCtxParamsState) == 4 * sizeof(void*)) ? 1 : -1]; typedef struct { ZSTD_CCtx_params* requestedParams; int streamStage; int* cParamsChanged; size_t staticSize; unsigned* rustSimpleCompress2MaxBlockSizeSet; } ZSTD_rust_setParameterState; size_t ZSTD_rust_setParameter(const ZSTD_rust_setParameterState* state, int param, int value); typedef char ZSTD_rust_set_parameter_state_layout[ (offsetof(ZSTD_rust_setParameterState, requestedParams) == 0 && offsetof(ZSTD_rust_setParameterState, streamStage) == sizeof(void*) && offsetof(ZSTD_rust_setParameterState, cParamsChanged) == 2 * sizeof(void*) && offsetof(ZSTD_rust_setParameterState, staticSize) == 3 * sizeof(void*) && offsetof(ZSTD_rust_setParameterState, rustSimpleCompress2MaxBlockSizeSet) == 4 * sizeof(void*) && sizeof(ZSTD_rust_setParameterState) == 5 * sizeof(void*)) ? 1 : -1]; /* Thread-pool attachment policy lives in Rust. The pool slot remains * C-owned; this projection passes its storage location and opaque value. */ typedef struct { void** pool; void* requestedPool; int streamStage; } ZSTD_rust_refThreadPoolState; size_t ZSTD_rust_refThreadPool(const ZSTD_rust_refThreadPoolState* state); typedef char ZSTD_rust_ref_thread_pool_state_layout[ (offsetof(ZSTD_rust_refThreadPoolState, pool) == 0 && offsetof(ZSTD_rust_refThreadPoolState, requestedPool) == sizeof(void*) && offsetof(ZSTD_rust_refThreadPoolState, streamStage) == 2 * sizeof(void*) && sizeof(ZSTD_rust_refThreadPoolState) == 3 * sizeof(void*)) ? 1 : -1]; typedef void (*ZSTD_rust_freeCCtxCallback_f)(void* context); typedef struct { void* callbackContext; size_t staticSize; int cctxInWorkspace; ZSTD_rust_freeCCtxCallback_f freeDictionaries; ZSTD_rust_freeCCtxCallback_f freeMTContext; ZSTD_rust_freeCCtxCallback_f freeWorkspace; ZSTD_rust_freeCCtxCallback_f freeObject; } ZSTD_rust_freeCCtxState; size_t ZSTD_rust_freeCCtx(const ZSTD_rust_freeCCtxState* state); typedef char ZSTD_rust_free_cctx_state_layout[ (offsetof(ZSTD_rust_freeCCtxState, callbackContext) == 0 && offsetof(ZSTD_rust_freeCCtxState, staticSize) == sizeof(void*) && offsetof(ZSTD_rust_freeCCtxState, cctxInWorkspace) == 2 * sizeof(void*) && offsetof(ZSTD_rust_freeCCtxState, freeDictionaries) == 3 * sizeof(void*) && offsetof(ZSTD_rust_freeCCtxState, freeMTContext) == 4 * sizeof(void*) && offsetof(ZSTD_rust_freeCCtxState, freeWorkspace) == 5 * sizeof(void*) && offsetof(ZSTD_rust_freeCCtxState, freeObject) == 6 * sizeof(void*) && sizeof(ZSTD_rust_freeCCtxState) == 7 * sizeof(void*)) ? 1 : -1]; typedef int (*ZSTD_rust_createCCtxValidateCustomMem_f)(void* context); typedef void* (*ZSTD_rust_createCCtxAllocate_f)(void* context, size_t size); typedef void (*ZSTD_rust_createCCtxInit_f)(void* context, void* cctx); typedef struct { void* callbackContext; size_t cctxSize; ZSTD_rust_createCCtxValidateCustomMem_f validateCustomMem; ZSTD_rust_createCCtxAllocate_f allocate; ZSTD_rust_createCCtxInit_f init; } ZSTD_rust_createCCtxState; void* ZSTD_rust_createCCtx(const ZSTD_rust_createCCtxState* state); typedef char ZSTD_rust_create_cctx_state_layout[ (offsetof(ZSTD_rust_createCCtxState, callbackContext) == 0 && offsetof(ZSTD_rust_createCCtxState, cctxSize) == sizeof(void*) && offsetof(ZSTD_rust_createCCtxState, validateCustomMem) == 2 * sizeof(void*) && offsetof(ZSTD_rust_createCCtxState, allocate) == 3 * sizeof(void*) && offsetof(ZSTD_rust_createCCtxState, init) == 4 * sizeof(void*) && sizeof(ZSTD_rust_createCCtxState) == 5 * sizeof(void*)) ? 1 : -1]; typedef void (*ZSTD_rust_initCCtxCallback_f)(void* context); typedef void (*ZSTD_rust_initCCtxSetCustomMem_f)( void* context, const void* customMem); typedef size_t (*ZSTD_rust_initCCtxReset_f)(void* context); typedef struct { void* callbackContext; const void* customMem; ZSTD_rust_initCCtxCallback_f zero; ZSTD_rust_initCCtxSetCustomMem_f setCustomMem; ZSTD_rust_initCCtxCallback_f setBmi2; ZSTD_rust_initCCtxReset_f reset; } ZSTD_rust_initCCtxState; size_t ZSTD_rust_initCCtx(const ZSTD_rust_initCCtxState* state); typedef char ZSTD_rust_init_cctx_state_layout[ (offsetof(ZSTD_rust_initCCtxState, callbackContext) == 0 && offsetof(ZSTD_rust_initCCtxState, customMem) == sizeof(void*) && offsetof(ZSTD_rust_initCCtxState, zero) == 2 * sizeof(void*) && offsetof(ZSTD_rust_initCCtxState, setCustomMem) == 3 * sizeof(void*) && offsetof(ZSTD_rust_initCCtxState, setBmi2) == 4 * sizeof(void*) && offsetof(ZSTD_rust_initCCtxState, reset) == 5 * sizeof(void*) && sizeof(ZSTD_rust_initCCtxState) == 6 * sizeof(void*)) ? 1 : -1]; typedef void (*ZSTD_rust_initStaticCCtxCreateWorkspace_f)(void* context); typedef void* (*ZSTD_rust_initStaticCCtxReserveObject_f)(void* context); typedef void (*ZSTD_rust_initStaticCCtxZero_f)(void* context, void* cctx); typedef void (*ZSTD_rust_initStaticCCtxMoveWorkspace_f)( void* context, void* cctx); typedef int (*ZSTD_rust_initStaticCCtxCheckAvailable_f)(void* context); typedef void* (*ZSTD_rust_initStaticCCtxReserveBlockState_f)( void* context, int blockState); typedef void* (*ZSTD_rust_initStaticCCtxReserveTmpWorkspace_f)(void* context); typedef void (*ZSTD_rust_initStaticCCtxSetBmi2_f)(void* context); typedef struct { void* callbackContext; void* workspace; size_t workspaceSize; size_t cctxSize; ZSTD_rust_initStaticCCtxCreateWorkspace_f createWorkspace; ZSTD_rust_initStaticCCtxReserveObject_f reserveObject; ZSTD_rust_initStaticCCtxZero_f zero; ZSTD_rust_initStaticCCtxMoveWorkspace_f moveWorkspace; ZSTD_rust_initStaticCCtxCheckAvailable_f checkAvailable; ZSTD_rust_initStaticCCtxReserveBlockState_f reserveBlockState; ZSTD_rust_initStaticCCtxReserveTmpWorkspace_f reserveTmpWorkspace; ZSTD_rust_initStaticCCtxSetBmi2_f setBmi2; } ZSTD_rust_initStaticCCtxState; void* ZSTD_rust_initStaticCCtx(const ZSTD_rust_initStaticCCtxState* state); typedef char ZSTD_rust_init_static_cctx_state_layout[ (offsetof(ZSTD_rust_initStaticCCtxState, callbackContext) == 0 && offsetof(ZSTD_rust_initStaticCCtxState, workspace) == sizeof(void*) && offsetof(ZSTD_rust_initStaticCCtxState, workspaceSize) == 2 * sizeof(void*) && offsetof(ZSTD_rust_initStaticCCtxState, cctxSize) == 3 * sizeof(void*) && offsetof(ZSTD_rust_initStaticCCtxState, createWorkspace) == 4 * sizeof(void*) && offsetof(ZSTD_rust_initStaticCCtxState, reserveObject) == 5 * sizeof(void*) && offsetof(ZSTD_rust_initStaticCCtxState, zero) == 6 * sizeof(void*) && offsetof(ZSTD_rust_initStaticCCtxState, moveWorkspace) == 7 * sizeof(void*) && offsetof(ZSTD_rust_initStaticCCtxState, checkAvailable) == 8 * sizeof(void*) && offsetof(ZSTD_rust_initStaticCCtxState, reserveBlockState) == 9 * sizeof(void*) && offsetof(ZSTD_rust_initStaticCCtxState, reserveTmpWorkspace) == 10 * sizeof(void*) && offsetof(ZSTD_rust_initStaticCCtxState, setBmi2) == 11 * sizeof(void*) && sizeof(ZSTD_rust_initStaticCCtxState) == 12 * sizeof(void*)) ? 1 : -1]; typedef void* (*ZSTD_rust_createCDictCreate_f)( void* context, const void* dict, size_t dictSize, int dictLoadMethod, int dictContentType, const ZSTD_compressionParameters* cParams); typedef void (*ZSTD_rust_createCDictSetCompressionLevel_f)( void* context, void* cdict, int compressionLevel); typedef struct { void* callbackContext; const U32* exclusionMask; ZSTD_rust_createCDictCreate_f create; ZSTD_rust_createCDictSetCompressionLevel_f setCompressionLevel; } ZSTD_rust_createCDictState; void* ZSTD_rust_createCDict( const ZSTD_rust_createCDictState* state, const void* dict, size_t dictSize, int compressionLevel, int dictLoadMethod); typedef char ZSTD_rust_create_cdict_state_layout[ (offsetof(ZSTD_rust_createCDictState, callbackContext) == 0 && offsetof(ZSTD_rust_createCDictState, exclusionMask) == sizeof(void*) && offsetof(ZSTD_rust_createCDictState, create) == 2 * sizeof(void*) && offsetof(ZSTD_rust_createCDictState, setCompressionLevel) == 3 * sizeof(void*) && sizeof(ZSTD_rust_createCDictState) == 4 * sizeof(void*)) ? 1 : -1]; typedef void (*ZSTD_rust_freeCDictWorkspace_f)(void* context); typedef void (*ZSTD_rust_freeCDictObject_f)(void* context); typedef struct { void* callbackContext; int cdictInWorkspace; ZSTD_rust_freeCDictWorkspace_f freeWorkspace; ZSTD_rust_freeCDictObject_f freeObject; } ZSTD_rust_freeCDictState; size_t ZSTD_rust_freeCDict(const ZSTD_rust_freeCDictState* state); typedef char ZSTD_rust_free_cdict_state_layout[ (offsetof(ZSTD_rust_freeCDictState, callbackContext) == 0 && offsetof(ZSTD_rust_freeCDictState, cdictInWorkspace) == sizeof(void*) && offsetof(ZSTD_rust_freeCDictState, freeWorkspace) == 2 * sizeof(void*) && offsetof(ZSTD_rust_freeCDictState, freeObject) == 3 * sizeof(void*) && sizeof(ZSTD_rust_freeCDictState) == 4 * sizeof(void*)) ? 1 : -1]; typedef void (*ZSTD_rust_initStaticCDictCreateWorkspace_f)(void* context); typedef void* (*ZSTD_rust_initStaticCDictReserveObject_f)(void* context); typedef void (*ZSTD_rust_initStaticCDictMoveWorkspace_f)( void* context, void* cdict); typedef void (*ZSTD_rust_initStaticCDictInitialize_f)( void* context, void* cdict, int useRowMatchFinder); typedef size_t (*ZSTD_rust_initStaticCDictInit_f)( void* context, void* cdict); typedef struct { void* callbackContext; void* workspace; size_t workspaceSize; size_t dictSize; size_t dictLoadMethod; const ZSTD_compressionParameters* cParams; const void* sizing; ZSTD_rust_initStaticCDictCreateWorkspace_f createWorkspace; ZSTD_rust_initStaticCDictReserveObject_f reserveObject; ZSTD_rust_initStaticCDictMoveWorkspace_f moveWorkspace; ZSTD_rust_initStaticCDictInitialize_f initialize; ZSTD_rust_initStaticCDictInit_f init; } ZSTD_rust_initStaticCDictState; void* ZSTD_rust_initStaticCDict(const ZSTD_rust_initStaticCDictState* state); typedef char ZSTD_rust_init_static_cdict_state_layout[ (offsetof(ZSTD_rust_initStaticCDictState, callbackContext) == 0 && offsetof(ZSTD_rust_initStaticCDictState, workspace) == sizeof(void*) && offsetof(ZSTD_rust_initStaticCDictState, workspaceSize) == 2 * sizeof(void*) && offsetof(ZSTD_rust_initStaticCDictState, dictSize) == 3 * sizeof(void*) && offsetof(ZSTD_rust_initStaticCDictState, dictLoadMethod) == 4 * sizeof(void*) && offsetof(ZSTD_rust_initStaticCDictState, cParams) == 5 * sizeof(void*) && offsetof(ZSTD_rust_initStaticCDictState, sizing) == 6 * sizeof(void*) && offsetof(ZSTD_rust_initStaticCDictState, createWorkspace) == 7 * sizeof(void*) && offsetof(ZSTD_rust_initStaticCDictState, reserveObject) == 8 * sizeof(void*) && offsetof(ZSTD_rust_initStaticCDictState, moveWorkspace) == 9 * sizeof(void*) && offsetof(ZSTD_rust_initStaticCDictState, initialize) == 10 * sizeof(void*) && offsetof(ZSTD_rust_initStaticCDictState, init) == 11 * sizeof(void*) && sizeof(ZSTD_rust_initStaticCDictState) == 12 * sizeof(void*)) ? 1 : -1]; typedef void (*ZSTD_rust_clearAllDictsCallback_f)(void* context); typedef struct { void* callbackContext; ZSTD_rust_clearAllDictsCallback_f freeLocalDictBuffer; ZSTD_rust_clearAllDictsCallback_f freeLocalCDict; ZSTD_rust_clearAllDictsCallback_f clearLocalDict; ZSTD_rust_clearAllDictsCallback_f clearPrefixDict; ZSTD_rust_clearAllDictsCallback_f clearCDict; } ZSTD_rust_clearAllDictsState; void ZSTD_rust_clearAllDicts(const ZSTD_rust_clearAllDictsState* state); typedef char ZSTD_rust_clear_all_dicts_state_layout[ (offsetof(ZSTD_rust_clearAllDictsState, callbackContext) == 0 && offsetof(ZSTD_rust_clearAllDictsState, freeLocalDictBuffer) == sizeof(void*) && offsetof(ZSTD_rust_clearAllDictsState, freeLocalCDict) == 2 * sizeof(void*) && offsetof(ZSTD_rust_clearAllDictsState, clearLocalDict) == 3 * sizeof(void*) && offsetof(ZSTD_rust_clearAllDictsState, clearPrefixDict) == 4 * sizeof(void*) && offsetof(ZSTD_rust_clearAllDictsState, clearCDict) == 5 * sizeof(void*) && sizeof(ZSTD_rust_clearAllDictsState) == 6 * sizeof(void*)) ? 1 : -1]; typedef void (*ZSTD_rust_resetCCtxClearAllDicts_f)(void* context); typedef size_t (*ZSTD_rust_resetCCtxResetParams_f)(void* context); typedef struct { void* callbackContext; unsigned* rustSimpleCompress2Completed; ZSTD_cStreamStage* streamStage; unsigned long long* pledgedSrcSizePlusOne; unsigned* rustSimpleCompress2MaxBlockSizeSet; ZSTD_rust_resetCCtxClearAllDicts_f clearAllDicts; ZSTD_rust_resetCCtxResetParams_f resetParams; } ZSTD_rust_resetCCtxState; size_t ZSTD_rust_resetCCtx(const ZSTD_rust_resetCCtxState* state, int reset); typedef char ZSTD_rust_reset_cctx_state_layout[ (offsetof(ZSTD_rust_resetCCtxState, callbackContext) == 0 && offsetof(ZSTD_rust_resetCCtxState, rustSimpleCompress2Completed) == sizeof(void*) && offsetof(ZSTD_rust_resetCCtxState, streamStage) == 2 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxState, pledgedSrcSizePlusOne) == 3 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxState, rustSimpleCompress2MaxBlockSizeSet) == 4 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxState, clearAllDicts) == 5 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxState, resetParams) == 6 * sizeof(void*) && sizeof(ZSTD_rust_resetCCtxState) == 7 * sizeof(void*)) ? 1 : -1]; typedef size_t (*ZSTD_rust_copyCCtxReset_f)( void* context, const void* srcCCtx, const ZSTD_frameParameters* fParams, U64 pledgedSrcSize, int zbuff); typedef void (*ZSTD_rust_copyCCtxMarkTables_f)(void* context); typedef struct { void* callbackContext; const void* srcCCtx; const ZSTD_frameParameters* fParams; U64 pledgedSrcSize; const int* sourceStage; void* destinationCustomMem; const void* sourceCustomMem; ZSTD_rust_copyCCtxReset_f reset; ZSTD_rust_copyCCtxMarkTables_f markTablesDirty; ZSTD_rust_copyCCtxMarkTables_f markTablesClean; U32** destinationHashTable; const U32* sourceHashTable; const U32* sourceHashLog; U32** destinationChainTable; const U32* sourceChainTable; const U32* sourceChainLog; U32** destinationHashTable3; const U32* sourceHashTable3; const U32* sourceHashLog3; const int* sourceStrategy; const int* sourceUseRowMatchFinder; void* destinationWindow; const void* sourceWindow; U32* destinationNextToUpdate; const U32* sourceNextToUpdate; U32* destinationLoadedDictEnd; const U32* sourceLoadedDictEnd; U32* destinationDictID; const U32* sourceDictID; size_t* destinationDictContentSize; const size_t* sourceDictContentSize; ZSTD_compressedBlockState_t** destinationBlockState; const ZSTD_compressedBlockState_t* sourceBlockState; int zbuff; } ZSTD_rust_copyCCtxInternalState; typedef char ZSTD_rust_copy_window_state_layout[ sizeof(ZSTD_window_t) == ((3 * sizeof(void*) + 3 * sizeof(U32) + sizeof(void*) - 1) / sizeof(void*)) * sizeof(void*) ? 1 : -1]; size_t ZSTD_rust_copyCCtxInternal( const ZSTD_rust_copyCCtxInternalState* state); typedef size_t (*ZSTD_rust_copyCCtxInternal_f)( void* context, const void* srcCCtx, const ZSTD_frameParameters* fParams, U64 pledgedSrcSize, int zbuff); typedef struct { void* callbackContext; const void* srcCCtx; const ZSTD_frameParameters* fParams; const U64* pledgedSrcSize; const int* zbuff; ZSTD_rust_copyCCtxInternal_f copyInternal; } ZSTD_rust_copyCCtxState; size_t ZSTD_rust_copyCCtx(const ZSTD_rust_copyCCtxState* state); typedef char ZSTD_rust_copy_cctx_state_layout[ (offsetof(ZSTD_rust_copyCCtxState, callbackContext) == 0 && offsetof(ZSTD_rust_copyCCtxState, srcCCtx) == sizeof(void*) && offsetof(ZSTD_rust_copyCCtxState, fParams) == 2 * sizeof(void*) && offsetof(ZSTD_rust_copyCCtxState, pledgedSrcSize) == 3 * sizeof(void*) && offsetof(ZSTD_rust_copyCCtxState, zbuff) == 4 * sizeof(void*) && offsetof(ZSTD_rust_copyCCtxState, copyInternal) == 5 * sizeof(void*) && sizeof(ZSTD_rust_copyCCtxState) == 6 * sizeof(void*)) ? 1 : -1]; typedef char ZSTD_rust_copy_cctx_internal_state_layout[ (offsetof(ZSTD_rust_copyCCtxInternalState, callbackContext) == 0 && offsetof(ZSTD_rust_copyCCtxInternalState, srcCCtx) == sizeof(void*) && offsetof(ZSTD_rust_copyCCtxInternalState, fParams) == 2 * sizeof(void*) && offsetof(ZSTD_rust_copyCCtxInternalState, pledgedSrcSize) == 3 * sizeof(void*) && offsetof(ZSTD_rust_copyCCtxInternalState, sourceStage) == 3 * sizeof(void*) + sizeof(U64) && offsetof(ZSTD_rust_copyCCtxInternalState, zbuff) == 3 * sizeof(void*) + sizeof(U64) + 29 * sizeof(void*) && sizeof(ZSTD_rust_copyCCtxInternalState) == ((offsetof(ZSTD_rust_copyCCtxInternalState, zbuff) + sizeof(int) + sizeof(void*) - 1) / sizeof(void*)) * sizeof(void*)) ? 1 : -1]; typedef void (*ZSTD_rust_compressAdvancedInitParams_f)( void* context, const ZSTD_parameters* params); typedef size_t (*ZSTD_rust_compressAdvancedInternal_f)( void* context, void* dst, size_t dstCapacity, const void* src, size_t srcSize, const void* dict, size_t dictSize); typedef struct { void* callbackContext; ZSTD_rust_compressAdvancedInitParams_f initParams; ZSTD_rust_compressAdvancedInternal_f compressInternal; } ZSTD_rust_compressAdvancedState; size_t ZSTD_rust_compressAdvanced( const ZSTD_rust_compressAdvancedState* state, void* dst, size_t dstCapacity, const void* src, size_t srcSize, const void* dict, size_t dictSize, const ZSTD_parameters* params); typedef char ZSTD_rust_compress_advanced_state_layout[ (offsetof(ZSTD_rust_compressAdvancedState, callbackContext) == 0 && offsetof(ZSTD_rust_compressAdvancedState, initParams) == sizeof(void*) && offsetof(ZSTD_rust_compressAdvancedState, compressInternal) == 2 * sizeof(void*) && sizeof(ZSTD_rust_compressAdvancedState) == 3 * sizeof(void*)) ? 1 : -1]; typedef size_t (*ZSTD_rust_compressAdvancedInternalBegin_f)( void* context, const void* dict, size_t dictSize, const void* params, U64 pledgedSrcSize); typedef size_t (*ZSTD_rust_compressAdvancedInternalEnd_f)( void* context, void* dst, size_t dstCapacity, const void* src, size_t srcSize); typedef struct { void* callbackContext; ZSTD_rust_compressAdvancedInternalBegin_f begin; ZSTD_rust_compressAdvancedInternalEnd_f end; } ZSTD_rust_compressAdvancedInternalState; size_t ZSTD_rust_compressAdvancedInternal( const ZSTD_rust_compressAdvancedInternalState* state, void* dst, size_t dstCapacity, const void* src, size_t srcSize, const void* dict, size_t dictSize, const void* params); typedef char ZSTD_rust_compress_advanced_internal_state_layout[ (offsetof(ZSTD_rust_compressAdvancedInternalState, callbackContext) == 0 && offsetof(ZSTD_rust_compressAdvancedInternalState, begin) == sizeof(void*) && offsetof(ZSTD_rust_compressAdvancedInternalState, end) == 2 * sizeof(void*) && sizeof(ZSTD_rust_compressAdvancedInternalState) == 3 * sizeof(void*)) ? 1 : -1]; typedef void (*ZSTD_rust_compressUsingDictInitParams_f)( void* context, const ZSTD_parameters* params, int compressionLevel); typedef struct { void* callbackContext; const U32* exclusionMask; ZSTD_rust_compressUsingDictInitParams_f initParams; ZSTD_rust_compressAdvancedInternal_f compressInternal; } ZSTD_rust_compressUsingDictState; size_t ZSTD_rust_compressUsingDict( const ZSTD_rust_compressUsingDictState* state, void* dst, size_t dstCapacity, const void* src, size_t srcSize, const void* dict, size_t dictSize, int compressionLevel); typedef char ZSTD_rust_compress_using_dict_state_layout[ (offsetof(ZSTD_rust_compressUsingDictState, callbackContext) == 0 && offsetof(ZSTD_rust_compressUsingDictState, exclusionMask) == sizeof(void*) && offsetof(ZSTD_rust_compressUsingDictState, initParams) == 2 * sizeof(void*) && offsetof(ZSTD_rust_compressUsingDictState, compressInternal) == 3 * sizeof(void*) && sizeof(ZSTD_rust_compressUsingDictState) == 4 * sizeof(void*)) ? 1 : -1]; typedef void (*ZSTD_rust_compressBeginAdvancedInitParams_f)( void* cctxParams, const ZSTD_parameters* params); typedef size_t (*ZSTD_rust_compressBeginAdvancedBegin_f)( void* context, const void* dict, size_t dictSize, const void* cctxParams, U64 pledgedSrcSize); typedef struct { void* cctx; void* cctxParams; ZSTD_rust_compressBeginAdvancedInitParams_f initParams; ZSTD_rust_compressBeginAdvancedBegin_f begin; } ZSTD_rust_compressBeginAdvancedState; size_t ZSTD_rust_compressBeginAdvanced( const ZSTD_rust_compressBeginAdvancedState* state, const void* dict, size_t dictSize, const ZSTD_parameters* params, U64 pledgedSrcSize); typedef char ZSTD_rust_compress_begin_advanced_state_layout[ (offsetof(ZSTD_rust_compressBeginAdvancedState, cctx) == 0 && offsetof(ZSTD_rust_compressBeginAdvancedState, cctxParams) == sizeof(void*) && offsetof(ZSTD_rust_compressBeginAdvancedState, initParams) == 2 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginAdvancedState, begin) == 3 * sizeof(void*) && sizeof(ZSTD_rust_compressBeginAdvancedState) == 4 * sizeof(void*)) ? 1 : -1]; ZSTD_frameProgression ZSTD_rust_frameProgression(U64 consumedSrcSize, size_t buffered, U64 producedCSize); typedef ZSTD_frameProgression (*ZSTD_rust_frameProgressionMTorST_f)( void* context); typedef struct { const void* inBuff; size_t inBuffPos; size_t inToCompress; } ZSTD_rust_frameProgressionInputState; typedef char ZSTD_rust_frame_progression_input_state_layout[ (offsetof(ZSTD_rust_frameProgressionInputState, inBuff) == 0 && offsetof(ZSTD_rust_frameProgressionInputState, inBuffPos) == sizeof(void*) && offsetof(ZSTD_rust_frameProgressionInputState, inToCompress) == sizeof(void*) + sizeof(size_t) && sizeof(ZSTD_rust_frameProgressionInputState) == sizeof(void*) + 2 * sizeof(size_t)) ? 1 : -1]; typedef struct { U64 consumedSrcSize; U64 producedCSize; ZSTD_rust_frameProgressionInputState input; void* mtContext; ZSTD_rust_frameProgressionMTorST_f mtFrameProgression; int nbWorkers; } ZSTD_rust_frameProgressionMTorSTState; typedef char ZSTD_rust_frame_progression_mt_or_st_state_layout[ (sizeof(ZSTD_rust_frameProgressionMTorST_f) == sizeof(void*) && offsetof(ZSTD_rust_frameProgressionMTorSTState, consumedSrcSize) == 0 && offsetof(ZSTD_rust_frameProgressionMTorSTState, producedCSize) == sizeof(U64) && offsetof(ZSTD_rust_frameProgressionMTorSTState, input) == 2 * sizeof(U64) && offsetof(ZSTD_rust_frameProgressionMTorSTState, mtContext) == 2 * sizeof(U64) + sizeof(void*) + 2 * sizeof(size_t) && offsetof(ZSTD_rust_frameProgressionMTorSTState, mtFrameProgression) == 2 * sizeof(U64) + 2 * sizeof(void*) + 2 * sizeof(size_t) && offsetof(ZSTD_rust_frameProgressionMTorSTState, nbWorkers) == 2 * sizeof(U64) + 3 * sizeof(void*) + 2 * sizeof(size_t) && sizeof(ZSTD_rust_frameProgressionMTorSTState) == (sizeof(void*) == 8 ? 64 : 40)) ? 1 : -1]; ZSTD_frameProgression ZSTD_rust_frameProgressionMTorST( const ZSTD_rust_frameProgressionMTorSTState* state); size_t ZSTD_rust_resetCCtxForSimpleCompression(void* cctx); size_t ZSTD_rust_prepareCCtxForSimpleCompression(void* cctx, size_t srcSize, int compressionLevel); int ZSTD_rust_compressCCtxStrategy(size_t srcSize, int compressionLevel); size_t ZSTD_rust_resetCCtxForSimpleCompressionSession(void* cctx); void ZSTD_rust_markSimpleCompression2Complete(void* cctx); typedef size_t (*ZSTD_rust_compress2Reset_f)(void* context); typedef void (*ZSTD_rust_compress2SetBufferModes_f)( void* context, int inBufferMode, int outBufferMode); typedef size_t (*ZSTD_rust_compress2StreamEnd_f)( void* context, void* dst, size_t dstCapacity, size_t* dstPos, const void* src, size_t srcSize, size_t* srcPos); typedef struct { void* callbackContext; ZSTD_rust_compress2Reset_f resetSession; ZSTD_rust_compress2SetBufferModes_f setBufferModes; ZSTD_rust_compress2StreamEnd_f compressStreamEnd; int originalInBufferMode; int originalOutBufferMode; } ZSTD_rust_compress2State; size_t ZSTD_rust_compress2(const ZSTD_rust_compress2State* state, void* dst, size_t dstCapacity, const void* src, size_t srcSize); typedef char ZSTD_rust_compress2_state_layout[ (offsetof(ZSTD_rust_compress2State, callbackContext) == 0 && offsetof(ZSTD_rust_compress2State, resetSession) == sizeof(void*) && offsetof(ZSTD_rust_compress2State, setBufferModes) == 2 * sizeof(void*) && offsetof(ZSTD_rust_compress2State, compressStreamEnd) == 3 * sizeof(void*) && offsetof(ZSTD_rust_compress2State, originalInBufferMode) == 4 * sizeof(void*) && offsetof(ZSTD_rust_compress2State, originalOutBufferMode) == 4 * sizeof(void*) + sizeof(int) && sizeof(ZSTD_rust_compress2State) == 4 * sizeof(void*) + 2 * sizeof(int)) ? 1 : -1]; size_t ZSTD_compress2_c(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); size_t ZSTD_compressStream2_c(ZSTD_CCtx* cctx, ZSTD_outBuffer* output, ZSTD_inBuffer* input, ZSTD_EndDirective endOp); typedef void (*ZSTD_rust_compressStream2SetBufferExpectations_f)( void* context, const void* output, const void* input); typedef struct { void* callbackContext; ZSTD_rust_compressStream2SetBufferExpectations_f setBufferExpectations; const void* output; const void* input; size_t compressResult; size_t outBuffContentSize; size_t outBuffFlushedSize; } ZSTD_rust_compressStream2ResultPolicyState; size_t ZSTD_rust_compressStream2ResultPolicy( const ZSTD_rust_compressStream2ResultPolicyState* state); typedef char ZSTD_rust_compress_stream2_result_policy_state_layout[ (offsetof(ZSTD_rust_compressStream2ResultPolicyState, callbackContext) == 0 && offsetof(ZSTD_rust_compressStream2ResultPolicyState, setBufferExpectations) == sizeof(void*) && offsetof(ZSTD_rust_compressStream2ResultPolicyState, output) == 2 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2ResultPolicyState, input) == 3 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2ResultPolicyState, compressResult) == 4 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2ResultPolicyState, outBuffContentSize) == 5 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2ResultPolicyState, outBuffFlushedSize) == 6 * sizeof(void*) && sizeof(ZSTD_rust_compressStream2SetBufferExpectations_f) == sizeof(void*) && sizeof(ZSTD_rust_compressStream2ResultPolicyState) == 7 * sizeof(void*)) ? 1 : -1]; typedef struct { size_t outputPos; size_t outputSize; size_t inputPos; size_t inputSize; } ZSTD_rust_compressStream2BufferPolicyState; enum { ZSTD_RUST_COMPRESS_STREAM2_BUFFER_VALID = 0, ZSTD_RUST_COMPRESS_STREAM2_BUFFER_OUTPUT_INVALID = 1, ZSTD_RUST_COMPRESS_STREAM2_BUFFER_INPUT_INVALID = 2 }; int ZSTD_rust_compressStream2BufferPolicy( const ZSTD_rust_compressStream2BufferPolicyState* state); typedef char ZSTD_rust_compress_stream2_buffer_policy_state_layout[ (offsetof(ZSTD_rust_compressStream2BufferPolicyState, outputPos) == 0 && offsetof(ZSTD_rust_compressStream2BufferPolicyState, outputSize) == sizeof(size_t) && offsetof(ZSTD_rust_compressStream2BufferPolicyState, inputPos) == 2 * sizeof(size_t) && offsetof(ZSTD_rust_compressStream2BufferPolicyState, inputSize) == 3 * sizeof(size_t) && sizeof(ZSTD_rust_compressStream2BufferPolicyState) == 4 * sizeof(size_t)) ? 1 : -1]; typedef struct { int endOp; } ZSTD_rust_compressStream2PolicyState; int ZSTD_rust_compressStream2Policy( const ZSTD_rust_compressStream2PolicyState* state); typedef char ZSTD_rust_compress_stream2_policy_state_layout[ (offsetof(ZSTD_rust_compressStream2PolicyState, endOp) == 0 && sizeof(ZSTD_rust_compressStream2PolicyState) == sizeof(int)) ? 1 : -1]; typedef struct { int inBufferMode; int endOp; size_t inputSize; size_t stableInNotConsumed; const void* inputSrc; size_t inputPos; const void* expectedInputSrc; size_t expectedInputSize; int format; } ZSTD_rust_compressStream2InitPolicyState; enum { ZSTD_RUST_COMPRESS_STREAM2_INIT_POLICY_INITIALIZE = 0, /* These values are the exact progress hints returned by the C API. */ ZSTD_RUST_COMPRESS_STREAM2_INIT_POLICY_DEFER_MAGICLESS = 2, ZSTD_RUST_COMPRESS_STREAM2_INIT_POLICY_DEFER_ZSTD = 6, ZSTD_RUST_COMPRESS_STREAM2_INIT_POLICY_STABLE_SRC_INVALID = -1, ZSTD_RUST_COMPRESS_STREAM2_INIT_POLICY_STABLE_POS_INVALID = -2 }; int ZSTD_rust_compressStream2InitPolicy( const ZSTD_rust_compressStream2InitPolicyState* state); typedef char ZSTD_rust_compress_stream2_init_policy_state_layout[ (offsetof(ZSTD_rust_compressStream2InitPolicyState, inBufferMode) == 0 && offsetof(ZSTD_rust_compressStream2InitPolicyState, endOp) == sizeof(int) && offsetof(ZSTD_rust_compressStream2InitPolicyState, inputSize) == 2 * sizeof(int) && offsetof(ZSTD_rust_compressStream2InitPolicyState, stableInNotConsumed) == 2 * sizeof(int) + sizeof(size_t) && offsetof(ZSTD_rust_compressStream2InitPolicyState, inputSrc) == 2 * sizeof(int) + 2 * sizeof(size_t) && offsetof(ZSTD_rust_compressStream2InitPolicyState, inputPos) == 2 * sizeof(int) + 3 * sizeof(size_t) && offsetof(ZSTD_rust_compressStream2InitPolicyState, expectedInputSrc) == 2 * sizeof(int) + 4 * sizeof(size_t) && offsetof(ZSTD_rust_compressStream2InitPolicyState, expectedInputSize) == 2 * sizeof(int) + 5 * sizeof(size_t) && offsetof(ZSTD_rust_compressStream2InitPolicyState, format) == 2 * sizeof(int) + 6 * sizeof(size_t) && sizeof(ZSTD_rust_compressStream2InitPolicyState) == 2 * sizeof(int) + 7 * sizeof(size_t)) ? 1 : -1]; typedef struct { int endOp; size_t flushMin; size_t inputPos; size_t inputSize; size_t inputPosBefore; size_t outputPos; size_t outputSize; size_t outputPosBefore; } ZSTD_rust_compressStream2MTLoopPolicyState; enum { ZSTD_RUST_COMPRESS_STREAM2_MT_LOOP_POLICY_CONTINUE = 0, ZSTD_RUST_COMPRESS_STREAM2_MT_LOOP_POLICY_BREAK = 1, ZSTD_RUST_COMPRESS_STREAM2_MT_LOOP_POLICY_ERROR = 2, ZSTD_RUST_COMPRESS_STREAM2_MT_LOOP_POLICY_END_COMPLETE = 3 }; int ZSTD_rust_compressStream2MTLoopPolicy( const ZSTD_rust_compressStream2MTLoopPolicyState* state); typedef char ZSTD_rust_compress_stream2_mt_loop_policy_state_layout[ (offsetof(ZSTD_rust_compressStream2MTLoopPolicyState, endOp) == 0 && offsetof(ZSTD_rust_compressStream2MTLoopPolicyState, flushMin) == sizeof(size_t) && offsetof(ZSTD_rust_compressStream2MTLoopPolicyState, inputPos) == 2 * sizeof(size_t) && offsetof(ZSTD_rust_compressStream2MTLoopPolicyState, inputSize) == 3 * sizeof(size_t) && offsetof(ZSTD_rust_compressStream2MTLoopPolicyState, inputPosBefore) == 4 * sizeof(size_t) && offsetof(ZSTD_rust_compressStream2MTLoopPolicyState, outputPos) == 5 * sizeof(size_t) && offsetof(ZSTD_rust_compressStream2MTLoopPolicyState, outputSize) == 6 * sizeof(size_t) && offsetof(ZSTD_rust_compressStream2MTLoopPolicyState, outputPosBefore) == 7 * sizeof(size_t) && sizeof(ZSTD_rust_compressStream2MTLoopPolicyState) == 8 * sizeof(size_t)) ? 1 : -1]; typedef void (*ZSTD_rust_compressStream2MTTrace_f)(void* context); typedef size_t (*ZSTD_rust_compressStream2MTReset_f)(void* context); typedef struct { void* callbackContext; ZSTD_rust_compressStream2MTTrace_f trace; ZSTD_rust_compressStream2MTReset_f reset; } ZSTD_rust_compressStream2MTCompletionCallbacks; typedef struct { int loopPolicy; const ZSTD_rust_compressStream2MTCompletionCallbacks* callbacks; } ZSTD_rust_compressStream2MTCompletionState; void ZSTD_rust_compressStream2MTCompletion( const ZSTD_rust_compressStream2MTCompletionState* state); typedef char ZSTD_rust_compress_stream2_mt_completion_callbacks_layout[ (offsetof(ZSTD_rust_compressStream2MTCompletionCallbacks, callbackContext) == 0 && offsetof(ZSTD_rust_compressStream2MTCompletionCallbacks, trace) == sizeof(void*) && offsetof(ZSTD_rust_compressStream2MTCompletionCallbacks, reset) == 2 * sizeof(void*) && sizeof(ZSTD_rust_compressStream2MTTrace_f) == sizeof(void*) && sizeof(ZSTD_rust_compressStream2MTReset_f) == sizeof(void*) && sizeof(ZSTD_rust_compressStream2MTCompletionCallbacks) == 3 * sizeof(void*)) ? 1 : -1]; typedef char ZSTD_rust_compress_stream2_mt_completion_state_layout[ (offsetof(ZSTD_rust_compressStream2MTCompletionState, loopPolicy) == 0 && offsetof(ZSTD_rust_compressStream2MTCompletionState, callbacks) == sizeof(void*) && sizeof(ZSTD_rust_compressStream2MTCompletionState) == 2 * sizeof(void*)) ? 1 : -1]; typedef size_t (*ZSTD_rust_compressStream2MTStep_f)( void* context, ZSTD_outBuffer* output, ZSTD_inBuffer* input, int endOp); typedef struct { void* callbackContext; ZSTD_rust_compressStream2MTStep_f step; ZSTD_outBuffer* output; ZSTD_inBuffer* input; const ZSTD_rust_compressStream2MTCompletionCallbacks* completionCallbacks; int endOp; } ZSTD_rust_compressStream2MTCoordinatorState; size_t ZSTD_rust_compressStream2MTCoordinator( const ZSTD_rust_compressStream2MTCoordinatorState* state); typedef char ZSTD_rust_compress_stream2_mt_coordinator_state_layout[ (offsetof(ZSTD_rust_compressStream2MTCoordinatorState, callbackContext) == 0 && offsetof(ZSTD_rust_compressStream2MTCoordinatorState, step) == sizeof(void*) && offsetof(ZSTD_rust_compressStream2MTCoordinatorState, output) == 2 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2MTCoordinatorState, input) == 3 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2MTCoordinatorState, completionCallbacks) == 4 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2MTCoordinatorState, endOp) == 5 * sizeof(void*) && sizeof(ZSTD_rust_compressStream2MTStep_f) == sizeof(void*) && sizeof(ZSTD_rust_compressStream2MTCoordinatorState) == 6 * sizeof(void*)) ? 1 : -1]; typedef size_t (*ZSTD_rust_compressStream2Init_f)( void* context, int endOp, size_t inputSize); typedef size_t (*ZSTD_rust_compressStream2CheckBuffer_f)( void* context, const void* output, const void* input); typedef size_t (*ZSTD_rust_compressStream2Stream_f)( void* context, ZSTD_outBuffer* output, ZSTD_inBuffer* input, int endOp); typedef void (*ZSTD_rust_compressStream2UpdateMT_f)(void* context); typedef struct { void* callbackContext; ZSTD_outBuffer* output; ZSTD_inBuffer* input; int* streamStage; size_t* stableInNotConsumed; ZSTD_inBuffer* expectedInBuffer; unsigned* simpleCompress2Completed; int* cParamsChanged; const size_t* outBuffContentSize; const size_t* outBuffFlushedSize; unsigned long long pledgedSrcSizePlusOne; int inBufferMode; int outBufferMode; int format; /* Transparent init may resolve a different worker mode for unknown sizes. */ const int* nbWorkers; } ZSTD_rust_compressStream2Fields; typedef struct { ZSTD_rust_compressStream2Init_f initCompressStream2; ZSTD_rust_compressStream2CheckBuffer_f checkBufferStability; ZSTD_rust_compressStream2SetBufferExpectations_f setBufferExpectations; ZSTD_rust_compressStream2Stream_f compressStream; ZSTD_rust_compressStream2UpdateMT_f updateMTCParams; ZSTD_rust_compressStream2MTStep_f mtStep; ZSTD_rust_compressStream2MTTrace_f mtTrace; ZSTD_rust_compressStream2MTReset_f mtReset; } ZSTD_rust_compressStream2Callbacks; typedef struct { const ZSTD_rust_compressStream2Fields* fields; const ZSTD_rust_compressStream2Callbacks* callbacks; int endOp; } ZSTD_rust_compressStream2State; size_t ZSTD_rust_compressStream2( const ZSTD_rust_compressStream2State* state); typedef char ZSTD_rust_compress_stream2_fields_layout[ (offsetof(ZSTD_rust_compressStream2Fields, callbackContext) == 0 && offsetof(ZSTD_rust_compressStream2Fields, output) == sizeof(void*) && offsetof(ZSTD_rust_compressStream2Fields, input) == 2 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2Fields, streamStage) == 3 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2Fields, stableInNotConsumed) == 4 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2Fields, expectedInBuffer) == 5 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2Fields, simpleCompress2Completed) == 6 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2Fields, cParamsChanged) == 7 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2Fields, outBuffContentSize) == 8 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2Fields, outBuffFlushedSize) == 9 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2Fields, pledgedSrcSizePlusOne) == 10 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2Fields, inBufferMode) == 10 * sizeof(void*) + sizeof(unsigned long long) && offsetof(ZSTD_rust_compressStream2Fields, outBufferMode) == 10 * sizeof(void*) + sizeof(unsigned long long) + sizeof(int) && offsetof(ZSTD_rust_compressStream2Fields, format) == 10 * sizeof(void*) + sizeof(unsigned long long) + 2 * sizeof(int) && offsetof(ZSTD_rust_compressStream2Fields, nbWorkers) == ((10 * sizeof(void*) + sizeof(unsigned long long) + 3 * sizeof(int) + sizeof(void*) - 1) / sizeof(void*)) * sizeof(void*) && sizeof(ZSTD_rust_compressStream2Fields) == offsetof(ZSTD_rust_compressStream2Fields, nbWorkers) + sizeof(const int*)) ? 1 : -1]; typedef char ZSTD_rust_compress_stream2_callbacks_layout[ (offsetof(ZSTD_rust_compressStream2Callbacks, initCompressStream2) == 0 && offsetof(ZSTD_rust_compressStream2Callbacks, checkBufferStability) == sizeof(void*) && offsetof(ZSTD_rust_compressStream2Callbacks, setBufferExpectations) == 2 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2Callbacks, compressStream) == 3 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2Callbacks, updateMTCParams) == 4 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2Callbacks, mtStep) == 5 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2Callbacks, mtTrace) == 6 * sizeof(void*) && offsetof(ZSTD_rust_compressStream2Callbacks, mtReset) == 7 * sizeof(void*) && sizeof(ZSTD_rust_compressStream2Callbacks) == 8 * sizeof(void*)) ? 1 : -1]; typedef char ZSTD_rust_compress_stream2_state_layout[ (offsetof(ZSTD_rust_compressStream2State, fields) == 0 && offsetof(ZSTD_rust_compressStream2State, callbacks) == sizeof(void*) && offsetof(ZSTD_rust_compressStream2State, endOp) == 2 * sizeof(void*) && sizeof(ZSTD_rust_compressStream2State) == ((2 * sizeof(void*) + sizeof(int) + sizeof(void*) - 1) / sizeof(void*)) * sizeof(void*)) ? 1 : -1]; int ZSTD_rust_simpleCompress2Level(const void* cctx, size_t srcSize); typedef struct { int format; int contentSizeFlag; int checksumFlag; int cParamsWindowLog; int cParamsChainLog; int cParamsHashLog; int cParamsSearchLog; int cParamsMinMatch; int cParamsTargetLength; int requestedStrategy; int forceWindow; int targetCBlockSizeSet; int srcSizeHintSet; int attachDictPref; int literalCompressionMode; int nbWorkersSet; int jobSizeSet; int overlapLogSet; int rsyncable; int ldmEnable; int ldmHashLogSet; int ldmBucketSizeLog; int ldmMinMatchLengthSet; int ldmHashRateLog; int ldmWindowLogSet; int dedicatedDictSearch; int inBufferMode; int outBufferMode; int blockDelimiters; int validateSequences; int postBlockSplitter; int preBlockSplitterLevelSet; int maxBlockSizeSet; int maxBlockSizeSetByApi; int useRowMatchFinder; int deterministicRefPrefix; int prefetchCDictTables; int matchFinderFallback; int extSeqProdFuncSet; int searchForExternalRepcodes; int poolSet; int collectSequences; int cdictSet; int prefixDictSet; int localDictSet; int compressionLevel; int selectedStrategy; } ZSTD_rust_simpleCompress2LevelState; int ZSTD_rust_simpleCompress2LevelPolicy( const ZSTD_rust_simpleCompress2LevelState* state); typedef char ZSTD_rust_simple_compress2_level_state_layout[ (offsetof(ZSTD_rust_simpleCompress2LevelState, format) == 0 && offsetof(ZSTD_rust_simpleCompress2LevelState, selectedStrategy) == 46 * sizeof(int) && sizeof(ZSTD_rust_simpleCompress2LevelState) == 47 * sizeof(int)) ? 1 : -1]; typedef int (*ZSTD_rust_simpleCompress2Level_f)(const void* cctx, size_t srcSize); typedef struct { int streamStage; unsigned long long pledgedSrcSizePlusOne; unsigned rustSimpleCompress2Completed; } ZSTD_rust_simpleCompressStream2Projection; typedef char ZSTD_rust_simple_compress_stream2_projection_layout[ (offsetof(ZSTD_rust_simpleCompressStream2Projection, streamStage) == 0 && offsetof(ZSTD_rust_simpleCompressStream2Projection, pledgedSrcSizePlusOne) == (sizeof(void*) == 8 ? 8 : 4) && offsetof(ZSTD_rust_simpleCompressStream2Projection, rustSimpleCompress2Completed) == (sizeof(void*) == 8 ? 16 : 12) && sizeof(ZSTD_rust_simpleCompressStream2Projection) == (sizeof(void*) == 8 ? 24 : 16)) ? 1 : -1]; int ZSTD_rust_simpleCompressStream2Policy( const ZSTD_rust_simpleCompressStream2Projection* projection, const void* cctx, size_t srcSize, ZSTD_rust_simpleCompress2Level_f simpleCompress2Level); int ZSTD_rust_simpleCompressStream2Level(const void* cctx, size_t srcSize); U32 ZSTD_rust_limitNextToUpdate(U32 curr, U32 nextToUpdate); void ZSTD_rust_reduceIndex(U32* hashTable, U32 hashSize, U32* chainTable, U32 chainSize, U32* hashTable3, U32 hashSize3, U32 reducerValue, int preserveChainMark); void ZSTD_rust_reduceIndexForMatchState( U32* hashTable, U32 hashLog, U32* chainTable, U32 chainLog, U32* hashTable3, U32 hashLog3, int strategy, int useRowMatchFinder, int dedicatedDictSearch, U32 reducerValue); typedef int (*ZSTD_rust_overflowNeedCorrection_f)( void* context, const void* src, const void* srcEnd); typedef U32 (*ZSTD_rust_overflowCorrect_f)( void* context, const void* src); typedef void (*ZSTD_rust_overflowCallback_f)(void* context); typedef void (*ZSTD_rust_overflowReduceIndex_f)(void* context, U32 correction); typedef struct { void* callbackContext; U32* nextToUpdate; ZSTD_rust_overflowNeedCorrection_f needCorrection; ZSTD_rust_overflowCorrect_f correctOverflow; ZSTD_rust_overflowCallback_f markTablesDirty; ZSTD_rust_overflowReduceIndex_f reduceIndex; ZSTD_rust_overflowCallback_f markTablesClean; U32* loadedDictEnd; const ZSTD_MatchState_t** dictMatchState; } ZSTD_rust_overflowCorrectState; void ZSTD_rust_overflowCorrectIfNeeded( const ZSTD_rust_overflowCorrectState* state, const void* src, const void* srcEnd); typedef char ZSTD_rust_overflow_correct_state_layout[ (offsetof(ZSTD_rust_overflowCorrectState, callbackContext) == 0 && offsetof(ZSTD_rust_overflowCorrectState, nextToUpdate) == sizeof(void*) && offsetof(ZSTD_rust_overflowCorrectState, needCorrection) == 2 * sizeof(void*) && offsetof(ZSTD_rust_overflowCorrectState, correctOverflow) == 3 * sizeof(void*) && offsetof(ZSTD_rust_overflowCorrectState, markTablesDirty) == 4 * sizeof(void*) && offsetof(ZSTD_rust_overflowCorrectState, reduceIndex) == 5 * sizeof(void*) && offsetof(ZSTD_rust_overflowCorrectState, markTablesClean) == 6 * sizeof(void*) && offsetof(ZSTD_rust_overflowCorrectState, loadedDictEnd) == 7 * sizeof(void*) && offsetof(ZSTD_rust_overflowCorrectState, dictMatchState) == 8 * sizeof(void*) && sizeof(ZSTD_rust_overflowCorrectState) == 9 * sizeof(void*)) ? 1 : -1]; void ZSTD_rust_copyCDictTableIntoCCtx(U32* dst, U32 const* src, size_t tableSize, int tagged); int ZSTD_indexTooCloseToMax(size_t nextSrcBaseOffset); int ZSTD_dictTooBig(size_t loadedDictSize); /* Match-state reset orchestration lives in Rust. The callbacks keep the * workspace implementation, window representation, and private pointer * fields in C. */ typedef void (*ZSTD_rust_resetMatchStateCallback_f)(void* context); typedef void (*ZSTD_rust_resetMatchStateSetPointer_f)( void* context, int pointerKind, void* pointer); typedef void* (*ZSTD_rust_resetMatchStateReserve_f)( void* context, int reserveKind, size_t size); typedef int (*ZSTD_rust_resetMatchStateReserveFailed_f)(void* context); typedef void (*ZSTD_rust_resetMatchStateZero_f)( void* context, void* pointer, size_t size); typedef struct { void* callbackContext; ZSTD_compressionParameters cParams; int dedicatedDictSearch; int useRowMatchFinder; int compResetPolicy; int indexResetPolicy; int resetTarget; unsigned hashLog3Max; size_t litFreqSize; size_t litLengthFreqSize; size_t matchLengthFreqSize; size_t offCodeFreqSize; size_t matchSize; size_t optimalSize; void* hashLog3; void* rowHashLog; void* hashSalt; void* lazySkipping; void* cParamsOut; ZSTD_rust_resetMatchStateSetPointer_f setPointer; ZSTD_rust_resetMatchStateCallback_f windowInit; ZSTD_rust_resetMatchStateCallback_f markTablesDirty; ZSTD_rust_resetMatchStateCallback_f invalidateMatchState; ZSTD_rust_resetMatchStateCallback_f clearTables; ZSTD_rust_resetMatchStateCallback_f cleanTables; unsigned hashSaltEntropy; ZSTD_rust_resetMatchStateReserve_f reserve; ZSTD_rust_resetMatchStateReserveFailed_f reserveFailed; ZSTD_rust_resetMatchStateZero_f zero; } ZSTD_rust_resetMatchStateState; size_t ZSTD_rust_resetMatchState(const ZSTD_rust_resetMatchStateState* state); typedef char ZSTD_rust_reset_match_state_layout[ (offsetof(ZSTD_rust_resetMatchStateState, callbackContext) == 0 && offsetof(ZSTD_rust_resetMatchStateState, cParams) == sizeof(void*) && offsetof(ZSTD_rust_resetMatchStateState, litFreqSize) > offsetof(ZSTD_rust_resetMatchStateState, hashLog3Max) && offsetof(ZSTD_rust_resetMatchStateState, hashLog3) == offsetof(ZSTD_rust_resetMatchStateState, optimalSize) + sizeof(size_t) && offsetof(ZSTD_rust_resetMatchStateState, hashSaltEntropy) == offsetof(ZSTD_rust_resetMatchStateState, cleanTables) + sizeof(void*) && offsetof(ZSTD_rust_resetMatchStateState, reserve) == offsetof(ZSTD_rust_resetMatchStateState, hashSaltEntropy) + sizeof(void*) && offsetof(ZSTD_rust_resetMatchStateState, setPointer) == offsetof(ZSTD_rust_resetMatchStateState, cParamsOut) + sizeof(void*) && sizeof(ZSTD_rust_resetMatchStateState) == offsetof(ZSTD_rust_resetMatchStateState, zero) + sizeof(void*)) ? 1 : -1]; /* The frame-chunk loop and preparation ordering are Rust-owned. These * callbacks keep the private ZSTD_CCtx and match-state layout in C: Rust * passes the context back to the narrow window/workspace operations. */ typedef void (*ZSTD_rust_frameChunkPrepareOverflow_f)(void* context, const void* src, size_t blockSize); typedef void (*ZSTD_rust_frameChunkPrepareWindow_f)(void* context, const void* src, size_t blockSize, U32 maxDist); typedef struct { U32* nextToUpdate; const U32* lowLimit; } ZSTD_rust_frameChunkClampState; typedef struct { void* callbackContext; U32 maxDist; ZSTD_rust_frameChunkPrepareOverflow_f correctOverflow; ZSTD_rust_frameChunkPrepareWindow_f checkDictValidity; ZSTD_rust_frameChunkPrepareWindow_f enforceMaxDist; const ZSTD_rust_frameChunkClampState* clampState; } ZSTD_rust_frameChunkPrepareState; typedef char ZSTD_rust_frame_chunk_clamp_state_layout[ (offsetof(ZSTD_rust_frameChunkClampState, nextToUpdate) == 0 && offsetof(ZSTD_rust_frameChunkClampState, lowLimit) == sizeof(void*) && sizeof(ZSTD_rust_frameChunkClampState) == 2 * sizeof(void*)) ? 1 : -1]; typedef char ZSTD_rust_frame_chunk_prepare_state_layout[ (offsetof(ZSTD_rust_frameChunkPrepareState, callbackContext) == 0 && offsetof(ZSTD_rust_frameChunkPrepareState, maxDist) == sizeof(void*) && offsetof(ZSTD_rust_frameChunkPrepareState, correctOverflow) == 2 * sizeof(void*) && offsetof(ZSTD_rust_frameChunkPrepareState, checkDictValidity) == 3 * sizeof(void*) && offsetof(ZSTD_rust_frameChunkPrepareState, enforceMaxDist) == 4 * sizeof(void*) && offsetof(ZSTD_rust_frameChunkPrepareState, clampState) == 5 * sizeof(void*) && sizeof(ZSTD_rust_frameChunkPrepareState) == 6 * sizeof(void*)) ? 1 : -1]; typedef struct ZSTD_rust_compressContinueBlockState_s ZSTD_rust_compressContinueBlockState; typedef struct ZSTD_rust_targetCBlockSizeState_s ZSTD_rust_targetCBlockSizeState; typedef struct ZSTD_rust_splitBlockState_s ZSTD_rust_splitBlockState; typedef struct ZSTD_rust_deriveBlockSplitsState_s ZSTD_rust_deriveBlockSplitsState; typedef size_t (*ZSTD_rust_frameChunkCompress_f)(void* context, void* dst, size_t dstCapacity, const void* src, size_t srcSize, U32 lastBlock); typedef struct { void* callbackContext; void* tmpWorkspace; XXH64_state_t* checksumState; int* isFirstBlock; ZSTD_compressionStage_e* stage; size_t tmpWkspSize; size_t blockSizeMax; S64 savings; int preBlockSplitterLevel; int strategy; int useTargetCBlockSize; int blockSplitterEnabled; int checksumFlag; int endingStage; const ZSTD_rust_frameChunkPrepareState* prepareState; ZSTD_rust_frameChunkCompress_f compressTarget; ZSTD_rust_frameChunkCompress_f compressSplit; ZSTD_rust_frameChunkCompress_f compressInternal; const ZSTD_rust_compressContinueBlockState* compressInternalState; const ZSTD_rust_targetCBlockSizeState* compressTargetState; const ZSTD_rust_splitBlockState* compressSplitState; const ZSTD_rust_deriveBlockSplitsState* deriveBlockSplitsState; } ZSTD_rust_frameChunkState; size_t ZSTD_rust_compressFrameChunk( const ZSTD_rust_frameChunkState* state, void* dst, size_t dstCapacity, const void* src, size_t srcSize, U32 lastFrameChunk); typedef char ZSTD_rust_frame_chunk_state_layout[ (offsetof(ZSTD_rust_frameChunkState, callbackContext) == 0 && offsetof(ZSTD_rust_frameChunkState, tmpWorkspace) == sizeof(void*) && offsetof(ZSTD_rust_frameChunkState, checksumState) == 2 * sizeof(void*) && offsetof(ZSTD_rust_frameChunkState, isFirstBlock) == 3 * sizeof(void*) && offsetof(ZSTD_rust_frameChunkState, stage) == 4 * sizeof(void*) && offsetof(ZSTD_rust_frameChunkState, tmpWkspSize) == 5 * sizeof(void*) && offsetof(ZSTD_rust_frameChunkState, blockSizeMax) == 6 * sizeof(void*) && offsetof(ZSTD_rust_frameChunkState, savings) == 7 * sizeof(void*) && offsetof(ZSTD_rust_frameChunkState, preBlockSplitterLevel) == 7 * sizeof(void*) + sizeof(S64) && offsetof(ZSTD_rust_frameChunkState, strategy) == 7 * sizeof(void*) + sizeof(S64) + sizeof(int) && offsetof(ZSTD_rust_frameChunkState, useTargetCBlockSize) == 7 * sizeof(void*) + sizeof(S64) + 2 * sizeof(int) && offsetof(ZSTD_rust_frameChunkState, blockSplitterEnabled) == 7 * sizeof(void*) + sizeof(S64) + 3 * sizeof(int) && offsetof(ZSTD_rust_frameChunkState, checksumFlag) == 7 * sizeof(void*) + sizeof(S64) + 4 * sizeof(int) && offsetof(ZSTD_rust_frameChunkState, endingStage) == 7 * sizeof(void*) + sizeof(S64) + 5 * sizeof(int) && offsetof(ZSTD_rust_frameChunkState, prepareState) == 7 * sizeof(void*) + sizeof(S64) + 6 * sizeof(int) && offsetof(ZSTD_rust_frameChunkState, compressInternalState) == 11 * sizeof(void*) + sizeof(S64) + 6 * sizeof(int) && offsetof(ZSTD_rust_frameChunkState, compressTargetState) == 12 * sizeof(void*) + sizeof(S64) + 6 * sizeof(int) && offsetof(ZSTD_rust_frameChunkState, compressSplitState) == 13 * sizeof(void*) + sizeof(S64) + 6 * sizeof(int) && offsetof(ZSTD_rust_frameChunkState, deriveBlockSplitsState) == 14 * sizeof(void*) + sizeof(S64) + 6 * sizeof(int) && sizeof(ZSTD_rust_frameChunkState) == 15 * sizeof(void*) + sizeof(S64) + 6 * sizeof(int)) ? 1 : -1]; /* The high-level continue/block entry points are Rust-owned. This projection * carries frame-header scalars, the already-projected frame-chunk state, and * the remaining C callback for context-sensitive block compression. Window * advancement uses direct pointers to the C-owned fields; the private CCtx * and match-state layout never crosses the ABI. */ typedef struct { void* nextSrc; void* base; void* dictBase; void* dictLimit; void* lowLimit; void* forceNonContiguous; void* nextToUpdate; } ZSTD_rust_compressContinueWindowState; typedef char ZSTD_rust_compress_continue_window_state_layout[ (sizeof(ZSTD_rust_compressContinueWindowState) == 7 * sizeof(void*)) ? 1 : -1]; typedef size_t (*ZSTD_rust_compressContinueBlock_f)(void* context, void* dst, size_t dstCapacity, const void* src, size_t srcSize, U32 lastFrameChunk); typedef struct { void* callbackContext; ZSTD_rust_compressContinueWindowState* windowState; ZSTD_rust_compressContinueWindowState* ldmWindowState; const ZSTD_rust_overflowCorrectState* overflowState; const ZSTD_rust_frameChunkState* frameChunkState; ZSTD_rust_compressContinueBlock_f compressBlock; ZSTD_compressionStage_e* stage; unsigned long long* consumedSrcSize; unsigned long long* producedCSize; U64 pledgedSrcSizePlusOne; size_t blockSizeMax; int checkBlockSize; int noDictIDFlag; int checksumFlag; int contentSizeFlag; int format; U32 windowLog; U32 dictID; int ldmEnabled; } ZSTD_rust_compressContinueState; size_t ZSTD_rust_compressContinue( const ZSTD_rust_compressContinueState* state, void* dst, size_t dstCapacity, const void* src, size_t srcSize, U32 frame, U32 lastFrameChunk); size_t ZSTD_rust_compressContinueBlock( void* context, void* dst, size_t dstCapacity, const void* src, size_t srcSize, U32 lastFrameChunk); typedef char ZSTD_rust_compress_continue_state_layout[ (offsetof(ZSTD_rust_compressContinueState, callbackContext) == 0 && offsetof(ZSTD_rust_compressContinueState, windowState) == sizeof(void*) && offsetof(ZSTD_rust_compressContinueState, ldmWindowState) == 2 * sizeof(void*) && offsetof(ZSTD_rust_compressContinueState, overflowState) == 3 * sizeof(void*) && offsetof(ZSTD_rust_compressContinueState, frameChunkState) == 4 * sizeof(void*) && offsetof(ZSTD_rust_compressContinueState, compressBlock) == 5 * sizeof(void*) && offsetof(ZSTD_rust_compressContinueState, stage) == 6 * sizeof(void*) && offsetof(ZSTD_rust_compressContinueState, consumedSrcSize) == 7 * sizeof(void*) && offsetof(ZSTD_rust_compressContinueState, producedCSize) == 8 * sizeof(void*) && offsetof(ZSTD_rust_compressContinueState, pledgedSrcSizePlusOne) == 9 * sizeof(void*) && offsetof(ZSTD_rust_compressContinueState, blockSizeMax) == 9 * sizeof(void*) + sizeof(U64) && offsetof(ZSTD_rust_compressContinueState, checkBlockSize) == 9 * sizeof(void*) + sizeof(U64) + sizeof(size_t) && offsetof(ZSTD_rust_compressContinueState, noDictIDFlag) == 9 * sizeof(void*) + sizeof(U64) + sizeof(size_t) + sizeof(int) && offsetof(ZSTD_rust_compressContinueState, checksumFlag) == 9 * sizeof(void*) + sizeof(U64) + sizeof(size_t) + 2 * sizeof(int) && offsetof(ZSTD_rust_compressContinueState, contentSizeFlag) == 9 * sizeof(void*) + sizeof(U64) + sizeof(size_t) + 3 * sizeof(int) && offsetof(ZSTD_rust_compressContinueState, format) == 9 * sizeof(void*) + sizeof(U64) + sizeof(size_t) + 4 * sizeof(int) && offsetof(ZSTD_rust_compressContinueState, windowLog) == 9 * sizeof(void*) + sizeof(U64) + sizeof(size_t) + 5 * sizeof(int) && offsetof(ZSTD_rust_compressContinueState, dictID) == 9 * sizeof(void*) + sizeof(U64) + sizeof(size_t) + 5 * sizeof(int) + sizeof(U32) && offsetof(ZSTD_rust_compressContinueState, ldmEnabled) == 9 * sizeof(void*) + sizeof(U64) + sizeof(size_t) + 5 * sizeof(int) + 2 * sizeof(U32) && sizeof(ZSTD_rust_compressContinueState) == (sizeof(void*) == 8 ? 120 : 80)) ? 1 : -1]; /* Rust owns the end-of-frame orchestration. Only the trace operation still * needs a callback; checksum and frame-epilogue fields are projected * explicitly, and continue uses the shared direct state projection. */ typedef void (*ZSTD_rust_compressEndTrace_f)(void* context, size_t extraCSize); typedef struct { void* callbackContext; const ZSTD_rust_compressContinueState* compressContinueState; ZSTD_rust_compressEndTrace_f trace; unsigned long long* consumedSrcSize; U64 pledgedSrcSizePlusOne; int contentSizeFlag; int* stage; int noDictIDFlag; int checksumFlag; int format; U32 windowLog; const XXH64_state_t* checksumState; } ZSTD_rust_compressEndState; size_t ZSTD_rust_compressEnd(const ZSTD_rust_compressEndState* state, void* dst, size_t dstCapacity, const void* src, size_t srcSize); typedef char ZSTD_rust_compress_end_state_layout[ (offsetof(ZSTD_rust_compressEndState, callbackContext) == 0 && offsetof(ZSTD_rust_compressEndState, compressContinueState) == sizeof(void*) && offsetof(ZSTD_rust_compressEndState, trace) == 2 * sizeof(void*) && offsetof(ZSTD_rust_compressEndState, consumedSrcSize) == 3 * sizeof(void*) && offsetof(ZSTD_rust_compressEndState, pledgedSrcSizePlusOne) == 4 * sizeof(void*) && offsetof(ZSTD_rust_compressEndState, contentSizeFlag) == 4 * sizeof(void*) + sizeof(U64) && offsetof(ZSTD_rust_compressEndState, stage) == 5 * sizeof(void*) + sizeof(U64) && offsetof(ZSTD_rust_compressEndState, noDictIDFlag) == 6 * sizeof(void*) + sizeof(U64) && offsetof(ZSTD_rust_compressEndState, checksumFlag) == 6 * sizeof(void*) + sizeof(U64) + sizeof(int) && offsetof(ZSTD_rust_compressEndState, format) == 6 * sizeof(void*) + sizeof(U64) + 2 * sizeof(int) && offsetof(ZSTD_rust_compressEndState, windowLog) == 6 * sizeof(void*) + sizeof(U64) + 3 * sizeof(int) && offsetof(ZSTD_rust_compressEndState, checksumState) == 6 * sizeof(void*) + sizeof(U64) + 3 * sizeof(int) + sizeof(U32) && sizeof(ZSTD_rust_compressEndState) == (sizeof(void*) == 8 ? 80 : 48)) ? 1 : -1]; /* Rust owns the single-threaded buffered/stable stream state machine. The * projection contains only stream bookkeeping and callback slots; operations * which still need the private CCtx layout remain C callbacks. */ typedef size_t (*ZSTD_rust_compressStreamReset_f)(void* context); typedef struct { void* callbackContext; int inBufferMode; int outBufferMode; ZSTD_cStreamStage* streamStage; size_t blockSizeMax; size_t* stableInNotConsumed; void* inBuff; size_t inBuffSize; size_t* inToCompress; size_t* inBuffPos; size_t* inBuffTarget; void* outBuff; size_t outBuffSize; size_t* outBuffContentSize; size_t* outBuffFlushedSize; U32* frameEnded; const ZSTD_rust_compressContinueState* compressContinueState; const ZSTD_rust_compressEndState* compressEndState; ZSTD_rust_compressStreamReset_f resetSession; } ZSTD_rust_compressStreamState; size_t ZSTD_rust_compressStreamGeneric( const ZSTD_rust_compressStreamState* state, ZSTD_outBuffer* output, ZSTD_inBuffer* input, int flushMode); typedef char ZSTD_rust_compress_stream_state_layout[ (offsetof(ZSTD_rust_compressStreamState, callbackContext) == 0 && offsetof(ZSTD_rust_compressStreamState, inBufferMode) == sizeof(void*) && offsetof(ZSTD_rust_compressStreamState, outBufferMode) == sizeof(void*) + sizeof(int) && offsetof(ZSTD_rust_compressStreamState, streamStage) == sizeof(void*) + 2 * sizeof(int) && offsetof(ZSTD_rust_compressStreamState, blockSizeMax) == 2 * sizeof(void*) + 2 * sizeof(int) && offsetof(ZSTD_rust_compressStreamState, stableInNotConsumed) == 3 * sizeof(void*) + 2 * sizeof(int) && offsetof(ZSTD_rust_compressStreamState, inBuff) == 4 * sizeof(void*) + 2 * sizeof(int) && offsetof(ZSTD_rust_compressStreamState, inBuffSize) == 5 * sizeof(void*) + 2 * sizeof(int) && offsetof(ZSTD_rust_compressStreamState, inToCompress) == 5 * sizeof(void*) + 2 * sizeof(int) + sizeof(size_t) && offsetof(ZSTD_rust_compressStreamState, inBuffPos) == 6 * sizeof(void*) + 2 * sizeof(int) + sizeof(size_t) && offsetof(ZSTD_rust_compressStreamState, inBuffTarget) == 7 * sizeof(void*) + 2 * sizeof(int) + sizeof(size_t) && offsetof(ZSTD_rust_compressStreamState, outBuff) == 8 * sizeof(void*) + 2 * sizeof(int) + sizeof(size_t) && offsetof(ZSTD_rust_compressStreamState, outBuffSize) == 9 * sizeof(void*) + 2 * sizeof(int) + sizeof(size_t) && offsetof(ZSTD_rust_compressStreamState, outBuffContentSize) == 9 * sizeof(void*) + 2 * sizeof(int) + 2 * sizeof(size_t) && offsetof(ZSTD_rust_compressStreamState, outBuffFlushedSize) == 10 * sizeof(void*) + 2 * sizeof(int) + 2 * sizeof(size_t) && offsetof(ZSTD_rust_compressStreamState, frameEnded) == 11 * sizeof(void*) + 2 * sizeof(int) + 2 * sizeof(size_t) && offsetof(ZSTD_rust_compressStreamState, compressContinueState) == 12 * sizeof(void*) + 2 * sizeof(int) + 2 * sizeof(size_t) && offsetof(ZSTD_rust_compressStreamState, compressEndState) == 13 * sizeof(void*) + 2 * sizeof(int) + 2 * sizeof(size_t) && offsetof(ZSTD_rust_compressStreamState, resetSession) == 14 * sizeof(void*) + 2 * sizeof(int) + 2 * sizeof(size_t) && sizeof(ZSTD_rust_compressStreamState) == 15 * sizeof(void*) + 2 * sizeof(int) + 2 * sizeof(size_t)) ? 1 : -1]; /* Rust owns only the high-level transparent initialization policy. The * parameter object, dictionary/context layouts, allocator, trace state, and * codec entry points stay behind these scalar/opaque callbacks. */ typedef struct { const void* prefixDict; size_t prefixDictSize; int prefixDictContentType; const void* cdict; int cdictIsLocal; int cdictCompressionLevel; size_t cdictDictContentSize; } ZSTD_rust_compressStreamInitDictionaryState; typedef struct { const void* dict; void* dictBuffer; size_t dictSize; int dictContentType; void* localCDict; const void* cdict; const void* prefixDict; void* createdCDict; } ZSTD_rust_compressStreamInitLocalDictState; typedef void (*ZSTD_rust_compressStreamInitGetLocalDict_f)( void* context, ZSTD_rust_compressStreamInitLocalDictState* state); typedef size_t (*ZSTD_rust_compressStreamInitCreateLocalDict_f)( void* context, ZSTD_rust_compressStreamInitLocalDictState* state); typedef void (*ZSTD_rust_compressStreamInitPublishLocalDict_f)( void* context, const ZSTD_rust_compressStreamInitLocalDictState* state); typedef void (*ZSTD_rust_compressStreamInitRefreshCDict_f)( void* context, ZSTD_rust_compressStreamInitDictionaryState* state); typedef void (*ZSTD_rust_compressStreamInitClearPrefix_f)(void* context); typedef void (*ZSTD_rust_compressStreamInitAssertDictionaries_f)( void* context, const void* prefixDict); typedef void (*ZSTD_rust_compressStreamInitSetLevel_f)(void* params, int level); typedef void (*ZSTD_rust_compressStreamInitDebug_f)(void* context); typedef U64 (*ZSTD_rust_compressStreamInitGetPledged_f)(void* context); typedef void (*ZSTD_rust_compressStreamInitSetPledged_f)(void* context, size_t inSize); typedef int (*ZSTD_rust_compressStreamInitGetCParamMode_f)( void* params, const void* cdict, U64 pledgedSrcSize); typedef void (*ZSTD_rust_compressStreamInitBuildCParams_f)( void* params, U64 pledgedSrcSize, size_t dictSize, int mode); typedef void (*ZSTD_rust_compressStreamInitResolveParams_f)( void* params, int operation); typedef unsigned (*ZSTD_rust_compressStreamInitGetNbWorkers_f)(void* params); typedef void (*ZSTD_rust_compressStreamInitSetNbWorkers_f)( void* params, unsigned nbWorkers); typedef int (*ZSTD_rust_compressStreamInitHasExtSeqProd_f)(void* params); typedef void (*ZSTD_rust_compressStreamInitTrace_f)(void* context); typedef void* (*ZSTD_rust_compressStreamInitGetMTContext_f)(void* context); typedef size_t (*ZSTD_rust_compressStreamInitCreateMTContext_f)( void* context, unsigned nbWorkers); typedef size_t (*ZSTD_rust_compressStreamInitMT_f)( void* context, void* mtctx, const ZSTD_rust_compressStreamInitDictionaryState* dictionaries, void* params, U64 pledgedSrcSize); typedef void (*ZSTD_rust_compressStreamInitCommitMT_f)( void* context, const ZSTD_rust_compressStreamInitDictionaryState* dictionaries, void* params); typedef void (*ZSTD_rust_compressStreamInitCheckCParams_f)(void* params); typedef size_t (*ZSTD_rust_compressStreamInitBegin_f)( void* context, const ZSTD_rust_compressStreamInitDictionaryState* dictionaries, void* params, U64 pledgedSrcSize); typedef void (*ZSTD_rust_compressStreamInitAssertOrdinary_f)(void* context); typedef int (*ZSTD_rust_compressStreamInitGetBufferMode_f)(void* context); typedef size_t (*ZSTD_rust_compressStreamInitGetBlockSize_f)(void* context); typedef void (*ZSTD_rust_compressStreamInitCommitOrdinary_f)( void* context, size_t inBuffTarget); typedef struct { void* callbackContext; void* params; ZSTD_rust_compressStreamInitDictionaryState* dictionaries; int endOp; size_t inSize; int multithreaded; size_t mtJobSizeMin; ZSTD_rust_compressStreamInitGetLocalDict_f getLocalDict; ZSTD_rust_compressStreamInitCreateLocalDict_f createLocalDict; ZSTD_rust_compressStreamInitPublishLocalDict_f publishLocalDict; ZSTD_rust_compressStreamInitRefreshCDict_f refreshCDict; ZSTD_rust_compressStreamInitClearPrefix_f clearPrefix; ZSTD_rust_compressStreamInitAssertDictionaries_f assertDictionaries; ZSTD_rust_compressStreamInitSetLevel_f setCompressionLevel; ZSTD_rust_compressStreamInitDebug_f debugInit; ZSTD_rust_compressStreamInitGetPledged_f getPledgedSrcSizePlusOne; ZSTD_rust_compressStreamInitSetPledged_f setPledgedSrcSize; ZSTD_rust_compressStreamInitGetCParamMode_f getCParamMode; ZSTD_rust_compressStreamInitBuildCParams_f buildCParams; ZSTD_rust_compressStreamInitResolveParams_f resolveParams; ZSTD_rust_compressStreamInitGetNbWorkers_f getNbWorkers; ZSTD_rust_compressStreamInitSetNbWorkers_f setNbWorkers; ZSTD_rust_compressStreamInitHasExtSeqProd_f hasExtSeqProd; ZSTD_rust_compressStreamInitTrace_f traceBegin; ZSTD_rust_compressStreamInitGetMTContext_f getMTContext; ZSTD_rust_compressStreamInitCreateMTContext_f createMTContext; ZSTD_rust_compressStreamInitMT_f initMT; ZSTD_rust_compressStreamInitCommitMT_f commitMT; ZSTD_rust_compressStreamInitCheckCParams_f checkCParams; ZSTD_rust_compressStreamInitBegin_f compressBegin; ZSTD_rust_compressStreamInitAssertOrdinary_f assertOrdinary; ZSTD_rust_compressStreamInitGetBufferMode_f getBufferMode; ZSTD_rust_compressStreamInitGetBlockSize_f getBlockSize; ZSTD_rust_compressStreamInitCommitOrdinary_f commitOrdinary; } ZSTD_rust_compressStreamInitState; typedef char ZSTD_rust_compress_stream_init_local_dict_layout[ (offsetof(ZSTD_rust_compressStreamInitLocalDictState, dict) == 0 && offsetof(ZSTD_rust_compressStreamInitLocalDictState, dictBuffer) == sizeof(void*) && offsetof(ZSTD_rust_compressStreamInitLocalDictState, dictSize) == 2 * sizeof(void*) && offsetof(ZSTD_rust_compressStreamInitLocalDictState, dictContentType) == 3 * sizeof(void*) && offsetof(ZSTD_rust_compressStreamInitLocalDictState, localCDict) == 4 * sizeof(void*) && offsetof(ZSTD_rust_compressStreamInitLocalDictState, cdict) == 5 * sizeof(void*) && offsetof(ZSTD_rust_compressStreamInitLocalDictState, prefixDict) == 6 * sizeof(void*) && offsetof(ZSTD_rust_compressStreamInitLocalDictState, createdCDict) == 7 * sizeof(void*) && sizeof(ZSTD_rust_compressStreamInitLocalDictState) == 8 * sizeof(void*)) ? 1 : -1]; typedef char ZSTD_rust_compress_stream_init_dictionary_layout[ (offsetof(ZSTD_rust_compressStreamInitDictionaryState, prefixDict) == 0 && offsetof(ZSTD_rust_compressStreamInitDictionaryState, prefixDictSize) == sizeof(void*) && offsetof(ZSTD_rust_compressStreamInitDictionaryState, prefixDictContentType) == 2 * sizeof(void*) && offsetof(ZSTD_rust_compressStreamInitDictionaryState, cdict) == 3 * sizeof(void*) && offsetof(ZSTD_rust_compressStreamInitDictionaryState, cdictIsLocal) == 4 * sizeof(void*) && offsetof(ZSTD_rust_compressStreamInitDictionaryState, cdictCompressionLevel) == 4 * sizeof(void*) + sizeof(int) && offsetof(ZSTD_rust_compressStreamInitDictionaryState, cdictDictContentSize) == 4 * sizeof(void*) + 2 * sizeof(int) && sizeof(ZSTD_rust_compressStreamInitDictionaryState) == (sizeof(void*) == 8 ? 48 : 28)) ? 1 : -1]; typedef char ZSTD_rust_compress_stream_init_state_layout[ (offsetof(ZSTD_rust_compressStreamInitState, callbackContext) == 0 && offsetof(ZSTD_rust_compressStreamInitState, params) == sizeof(void*) && offsetof(ZSTD_rust_compressStreamInitState, dictionaries) == 2 * sizeof(void*) && offsetof(ZSTD_rust_compressStreamInitState, endOp) == 3 * sizeof(void*) && offsetof(ZSTD_rust_compressStreamInitState, inSize) == 4 * sizeof(void*) && offsetof(ZSTD_rust_compressStreamInitState, multithreaded) == 4 * sizeof(void*) + sizeof(size_t) && offsetof(ZSTD_rust_compressStreamInitState, mtJobSizeMin) == 5 * sizeof(void*) + sizeof(size_t) && sizeof(ZSTD_rust_compressStreamInitState) == (sizeof(void*) == 8 ? 272 : 144)) ? 1 : -1]; size_t ZSTD_rust_compressStreamInit( const ZSTD_rust_compressStreamInitState* state); /* The target-sized block body only needs this narrow projection of ZSTD_CCtx. * Matchfinder/window state, sequence-store construction, and outer repeat-mode * cleanup remain in C. */ struct ZSTD_rust_targetCBlockSizeState_s { const SeqStore_t* seqStore; ZSTD_compressedBlockState_t** prevCBlock; ZSTD_compressedBlockState_t** nextCBlock; void* tmpWorkspace; size_t tmpWkspSize; int strategy; int disableLiteralCompression; int bmi2; U32 windowLog; size_t targetCBlockSize; int isFirstBlock; }; size_t ZSTD_rust_compressBlockTargetCBlockSize( const ZSTD_rust_targetCBlockSizeState* state, void* dst, size_t dstCapacity, const void* src, size_t srcSize, int bss, U32 lastBlock); size_t ZSTD_rust_compressBlockTargetCBlockSizeAfterBuild( const ZSTD_rust_targetCBlockSizeState* state, void* dst, size_t dstCapacity, const void* src, size_t srcSize, int bss, U32 lastBlock); typedef char ZSTD_rust_target_cblock_state_layout[ (offsetof(ZSTD_rust_targetCBlockSizeState, seqStore) == 0 && offsetof(ZSTD_rust_targetCBlockSizeState, prevCBlock) == sizeof(void*) && offsetof(ZSTD_rust_targetCBlockSizeState, nextCBlock) == 2 * sizeof(void*) && offsetof(ZSTD_rust_targetCBlockSizeState, tmpWorkspace) == 3 * sizeof(void*) && offsetof(ZSTD_rust_targetCBlockSizeState, tmpWkspSize) == 4 * sizeof(void*) && offsetof(ZSTD_rust_targetCBlockSizeState, strategy) == 5 * sizeof(void*) && offsetof(ZSTD_rust_targetCBlockSizeState, disableLiteralCompression) == 5 * sizeof(void*) + sizeof(int) && offsetof(ZSTD_rust_targetCBlockSizeState, bmi2) == 5 * sizeof(void*) + 2 * sizeof(int) && offsetof(ZSTD_rust_targetCBlockSizeState, windowLog) == 5 * sizeof(void*) + 3 * sizeof(int) && offsetof(ZSTD_rust_targetCBlockSizeState, targetCBlockSize) == 5 * sizeof(void*) + 4 * sizeof(int) && offsetof(ZSTD_rust_targetCBlockSizeState, isFirstBlock) == 5 * sizeof(void*) + 4 * sizeof(int) + sizeof(size_t) && sizeof(ZSTD_rust_targetCBlockSizeState) == (sizeof(void*) == 8 ? 72 : 44)) ? 1 : -1]; /* Split discovery and the post-split partition loop use narrow projections of * ZSTD_CCtx. The private block-split context remains in C; Rust owns the * estimator call, partition accounting, repcode simulation, and emission. */ struct ZSTD_rust_deriveBlockSplitsState_s { const SeqStore_t* originalSeqStore; SeqStore_t* fullSeqStoreChunk; SeqStore_t* firstHalfSeqStore; SeqStore_t* secondHalfSeqStore; ZSTD_compressedBlockState_t** prevCBlock; ZSTD_compressedBlockState_t** nextCBlock; ZSTD_entropyCTablesMetadata_t* entropyMetadata; void* workspace; size_t workspaceSize; int strategy; int disableLiteralCompression; }; typedef char ZSTD_rust_derive_block_splits_state_layout[ (offsetof(ZSTD_rust_deriveBlockSplitsState, originalSeqStore) == 0 && offsetof(ZSTD_rust_deriveBlockSplitsState, fullSeqStoreChunk) == sizeof(void*) && offsetof(ZSTD_rust_deriveBlockSplitsState, firstHalfSeqStore) == 2 * sizeof(void*) && offsetof(ZSTD_rust_deriveBlockSplitsState, secondHalfSeqStore) == 3 * sizeof(void*) && offsetof(ZSTD_rust_deriveBlockSplitsState, prevCBlock) == 4 * sizeof(void*) && offsetof(ZSTD_rust_deriveBlockSplitsState, nextCBlock) == 5 * sizeof(void*) && offsetof(ZSTD_rust_deriveBlockSplitsState, entropyMetadata) == 6 * sizeof(void*) && offsetof(ZSTD_rust_deriveBlockSplitsState, workspace) == 7 * sizeof(void*) && offsetof(ZSTD_rust_deriveBlockSplitsState, workspaceSize) == 8 * sizeof(void*) && offsetof(ZSTD_rust_deriveBlockSplitsState, strategy) == 8 * sizeof(void*) + sizeof(size_t) && offsetof(ZSTD_rust_deriveBlockSplitsState, disableLiteralCompression) == 8 * sizeof(void*) + sizeof(size_t) + sizeof(int) && sizeof(ZSTD_rust_deriveBlockSplitsState) == 8 * sizeof(void*) + sizeof(size_t) + 2 * sizeof(int)) ? 1 : -1]; struct ZSTD_rust_splitBlockState_s { const SeqStore_t* seqStore; const U32* partitions; SeqStore_t* nextSeqStore; SeqStore_t* currSeqStore; ZSTD_compressedBlockState_t** prevCBlock; ZSTD_compressedBlockState_t** nextCBlock; void* tmpWorkspace; size_t tmpWkspSize; SeqCollector* seqCollector; size_t blockSizeMax; int strategy; int disableLiteralCompression; int bmi2; int isFirstBlock; }; size_t ZSTD_rust_compressBlockSplit( const ZSTD_rust_splitBlockState* state, void* dst, size_t dstCapacity, const void* src, size_t blockSize, U32 lastBlock, size_t numSplits); size_t ZSTD_rust_compressBlockSplitAfterBuild( const ZSTD_rust_splitBlockState* state, void* dst, size_t dstCapacity, const void* src, size_t blockSize, U32 lastBlock, size_t numSplits, int bss); typedef char ZSTD_rust_split_block_state_layout[ (offsetof(ZSTD_rust_splitBlockState, seqStore) == 0 && offsetof(ZSTD_rust_splitBlockState, partitions) == sizeof(void*) && offsetof(ZSTD_rust_splitBlockState, nextSeqStore) == 2 * sizeof(void*) && offsetof(ZSTD_rust_splitBlockState, currSeqStore) == 3 * sizeof(void*) && offsetof(ZSTD_rust_splitBlockState, prevCBlock) == 4 * sizeof(void*) && offsetof(ZSTD_rust_splitBlockState, nextCBlock) == 5 * sizeof(void*) && offsetof(ZSTD_rust_splitBlockState, tmpWorkspace) == 6 * sizeof(void*) && offsetof(ZSTD_rust_splitBlockState, tmpWkspSize) == 7 * sizeof(void*) && offsetof(ZSTD_rust_splitBlockState, seqCollector) == 8 * sizeof(void*) && offsetof(ZSTD_rust_splitBlockState, blockSizeMax) == 9 * sizeof(void*) && offsetof(ZSTD_rust_splitBlockState, strategy) == 10 * sizeof(void*) && offsetof(ZSTD_rust_splitBlockState, disableLiteralCompression) == 10 * sizeof(void*) + sizeof(int) && offsetof(ZSTD_rust_splitBlockState, bmi2) == 10 * sizeof(void*) + 2 * sizeof(int) && offsetof(ZSTD_rust_splitBlockState, isFirstBlock) == 10 * sizeof(void*) + 3 * sizeof(int) && sizeof(ZSTD_rust_splitBlockState) == 10 * sizeof(void*) + 4 * sizeof(int)) ? 1 : -1]; /* The ordinary sequence-block body only needs this projection of ZSTD_CCtx. * Sequence-store construction and the no-compress fallback remain in C. */ typedef struct { const SeqStore_t* seqStore; ZSTD_compressedBlockState_t** prevCBlock; ZSTD_compressedBlockState_t** nextCBlock; void* tmpWorkspace; size_t tmpWkspSize; SeqCollector* seqCollector; int strategy; int disableLiteralCompression; int bmi2; int isFirstBlock; } ZSTD_rust_blockInternalState; size_t ZSTD_rust_compressBlockInternal( const ZSTD_rust_blockInternalState* state, void* dst, size_t dstCapacity, const void* src, size_t srcSize, U32 frame); size_t ZSTD_rust_compressBlockInternalAfterBuild( const ZSTD_rust_blockInternalState* state, void* dst, size_t dstCapacity, const void* src, size_t srcSize, U32 frame, int bss); typedef char ZSTD_rust_block_internal_state_layout[ (offsetof(ZSTD_rust_blockInternalState, seqStore) == 0 && offsetof(ZSTD_rust_blockInternalState, prevCBlock) == sizeof(void*) && offsetof(ZSTD_rust_blockInternalState, nextCBlock) == 2 * sizeof(void*) && offsetof(ZSTD_rust_blockInternalState, tmpWorkspace) == 3 * sizeof(void*) && offsetof(ZSTD_rust_blockInternalState, tmpWkspSize) == 4 * sizeof(void*) && offsetof(ZSTD_rust_blockInternalState, seqCollector) == 5 * sizeof(void*) && offsetof(ZSTD_rust_blockInternalState, strategy) == 6 * sizeof(void*) && offsetof(ZSTD_rust_blockInternalState, disableLiteralCompression) == 6 * sizeof(void*) + sizeof(int) && offsetof(ZSTD_rust_blockInternalState, bmi2) == 6 * sizeof(void*) + 2 * sizeof(int) && offsetof(ZSTD_rust_blockInternalState, isFirstBlock) == 6 * sizeof(void*) + 3 * sizeof(int) && sizeof(ZSTD_rust_blockInternalState) == 6 * sizeof(void*) + 4 * sizeof(int)) ? 1 : -1]; size_t ZSTD_rust_nextInputSizeHint(int inBufferMode, size_t blockSizeMax, size_t stableInNotConsumed, size_t inBuffTarget, size_t inBuffPos); typedef size_t (*ZSTD_rust_nextInputSizeHintMTorST_f)(void* context); typedef struct { size_t blockSizeMax; size_t stableInNotConsumed; size_t inBuffTarget; size_t inBuffPos; int nbWorkers; int inBufferMode; void* mtContext; ZSTD_rust_nextInputSizeHintMTorST_f mtNextInputSizeHint; } ZSTD_rust_nextInputSizeHintMTorSTState; typedef char ZSTD_rust_next_input_size_hint_mt_or_st_state_layout[ (sizeof(ZSTD_rust_nextInputSizeHintMTorST_f) == sizeof(void*) && offsetof(ZSTD_rust_nextInputSizeHintMTorSTState, blockSizeMax) == 0 && offsetof(ZSTD_rust_nextInputSizeHintMTorSTState, stableInNotConsumed) == sizeof(size_t) && offsetof(ZSTD_rust_nextInputSizeHintMTorSTState, inBuffTarget) == 2 * sizeof(size_t) && offsetof(ZSTD_rust_nextInputSizeHintMTorSTState, inBuffPos) == 3 * sizeof(size_t) && offsetof(ZSTD_rust_nextInputSizeHintMTorSTState, nbWorkers) == 4 * sizeof(size_t) && offsetof(ZSTD_rust_nextInputSizeHintMTorSTState, inBufferMode) == 4 * sizeof(size_t) + sizeof(int) && offsetof(ZSTD_rust_nextInputSizeHintMTorSTState, mtContext) == 4 * sizeof(size_t) + 2 * sizeof(int) && offsetof(ZSTD_rust_nextInputSizeHintMTorSTState, mtNextInputSizeHint) == 4 * sizeof(size_t) + 2 * sizeof(int) + sizeof(void*) && sizeof(ZSTD_rust_nextInputSizeHintMTorSTState) == 4 * sizeof(size_t) + 2 * sizeof(int) + 2 * sizeof(void*)) ? 1 : -1]; size_t ZSTD_rust_nextInputSizeHintMTorST( const ZSTD_rust_nextInputSizeHintMTorSTState* state); typedef size_t (*ZSTD_rust_estimateCDictSizeAdvanced_f)( void* context, size_t dictSize, ZSTD_compressionParameters cParams, int dictLoadMethod); typedef struct { void* callbackContext; const U32* exclusionMask; ZSTD_rust_estimateCDictSizeAdvanced_f estimateAdvanced; } ZSTD_rust_estimateCDictSizeState; typedef char zstd_rust_estimate_cdict_size_state_layout[ (offsetof(ZSTD_rust_estimateCDictSizeState, callbackContext) == 0 && offsetof(ZSTD_rust_estimateCDictSizeState, exclusionMask) == sizeof(void*) && offsetof(ZSTD_rust_estimateCDictSizeState, estimateAdvanced) == 2 * sizeof(void*) && sizeof(ZSTD_rust_estimateCDictSizeState) == 3 * sizeof(void*)) ? 1 : -1]; size_t ZSTD_rust_estimateCDictSize( const ZSTD_rust_estimateCDictSizeState* state, size_t dictSize, int compressionLevel); size_t ZSTD_rust_sizeofCDict(size_t objectSize, size_t workspaceSize); size_t ZSTD_rust_sizeofLocalDict(int dictBufferPresent, size_t dictSize, size_t cdictSize); size_t ZSTD_rust_sizeofCCtx(size_t objectSize, size_t workspaceSize, size_t localDictSize, size_t mtctxSize); typedef struct { size_t cctxSize; size_t compressedBlockStateSize; size_t seqDefSize; size_t rawSeqSize; size_t externalSequenceSize; size_t tmpWorkspaceSize; size_t wildcopyOverlength; size_t matchTSize; size_t optimalTSize; size_t asanRedzoneSize; } ZSTD_rustCCtxWorkspaceSizing; typedef struct { size_t windowSize; size_t blockSize; size_t maxNbSeq; size_t buffInSize; size_t buffOutSize; size_t maxNbLdmSeq; size_t maxNbExternalSeq; size_t neededSpace; int needsIndexReset; } ZSTD_rustCCtxResetPlan; typedef char ZSTD_rust_cctx_workspace_sizing_layout[ (offsetof(ZSTD_rustCCtxWorkspaceSizing, cctxSize) == 0 && offsetof(ZSTD_rustCCtxWorkspaceSizing, compressedBlockStateSize) == sizeof(size_t) && offsetof(ZSTD_rustCCtxWorkspaceSizing, seqDefSize) == 2 * sizeof(size_t) && offsetof(ZSTD_rustCCtxWorkspaceSizing, rawSeqSize) == 3 * sizeof(size_t) && offsetof(ZSTD_rustCCtxWorkspaceSizing, externalSequenceSize) == 4 * sizeof(size_t) && offsetof(ZSTD_rustCCtxWorkspaceSizing, tmpWorkspaceSize) == 5 * sizeof(size_t) && offsetof(ZSTD_rustCCtxWorkspaceSizing, wildcopyOverlength) == 6 * sizeof(size_t) && offsetof(ZSTD_rustCCtxWorkspaceSizing, matchTSize) == 7 * sizeof(size_t) && offsetof(ZSTD_rustCCtxWorkspaceSizing, optimalTSize) == 8 * sizeof(size_t) && offsetof(ZSTD_rustCCtxWorkspaceSizing, asanRedzoneSize) == 9 * sizeof(size_t) && sizeof(ZSTD_rustCCtxWorkspaceSizing) == 10 * sizeof(size_t)) ? 1 : -1]; typedef struct { ZSTD_compressionParameters cParams; int ldmEnable; U32 ldmHashLog; U32 ldmBucketSizeLog; U32 ldmMinMatchLength; int isStatic; int useRowMatchFinder; int inBufferBuffered; int outBufferBuffered; int useSequenceProducer; int initialized; int indexTooClose; int dictTooBig; U64 pledgedSrcSize; size_t maxBlockSize; const ZSTD_rustCCtxWorkspaceSizing* sizing; ZSTD_rustCCtxResetPlan* plan; } ZSTD_rustCCtxResetState; typedef char ZSTD_rust_cctx_reset_state_layout[ (offsetof(ZSTD_rustCCtxResetState, cParams) == 0 && offsetof(ZSTD_rustCCtxResetState, ldmEnable) == sizeof(ZSTD_compressionParameters) && offsetof(ZSTD_rustCCtxResetState, pledgedSrcSize) > offsetof(ZSTD_rustCCtxResetState, dictTooBig) && offsetof(ZSTD_rustCCtxResetState, maxBlockSize) == offsetof(ZSTD_rustCCtxResetState, pledgedSrcSize) + sizeof(U64) && offsetof(ZSTD_rustCCtxResetState, sizing) == offsetof(ZSTD_rustCCtxResetState, maxBlockSize) + sizeof(size_t) && offsetof(ZSTD_rustCCtxResetState, plan) == offsetof(ZSTD_rustCCtxResetState, sizing) + sizeof(void*) && sizeof(ZSTD_rustCCtxResetState) == offsetof(ZSTD_rustCCtxResetState, plan) + sizeof(void*)) ? 1 : -1]; typedef char ZSTD_rust_cctx_reset_plan_layout[ (offsetof(ZSTD_rustCCtxResetPlan, windowSize) == 0 && offsetof(ZSTD_rustCCtxResetPlan, blockSize) == sizeof(size_t) && offsetof(ZSTD_rustCCtxResetPlan, maxNbSeq) == 2 * sizeof(size_t) && offsetof(ZSTD_rustCCtxResetPlan, buffInSize) == 3 * sizeof(size_t) && offsetof(ZSTD_rustCCtxResetPlan, buffOutSize) == 4 * sizeof(size_t) && offsetof(ZSTD_rustCCtxResetPlan, maxNbLdmSeq) == 5 * sizeof(size_t) && offsetof(ZSTD_rustCCtxResetPlan, maxNbExternalSeq) == 6 * sizeof(size_t) && offsetof(ZSTD_rustCCtxResetPlan, neededSpace) == 7 * sizeof(size_t) && offsetof(ZSTD_rustCCtxResetPlan, needsIndexReset) == 8 * sizeof(size_t) && sizeof(ZSTD_rustCCtxResetPlan) == 9 * sizeof(size_t)) ? 1 : -1]; typedef void (*ZSTD_rust_resetCCtxStorageSetPointer_f)( void* context, int pointerKind, void* pointer); typedef void (*ZSTD_rust_resetCCtxStorageSetSize_f)( void* context, int sizeKind, size_t value); typedef void (*ZSTD_rust_resetCCtxStorageSetInt_f)( void* context, int intKind, int value); typedef void* (*ZSTD_rust_resetCCtxStorageReserve_f)( void* context, int reserveKind, size_t size); typedef int (*ZSTD_rust_resetCCtxStorageReserveFailed_f)(void* context); typedef void (*ZSTD_rust_resetCCtxStorageZero_f)( void* context, void* pointer, size_t size); typedef void (*ZSTD_rust_resetCCtxStorageCallback_f)(void* context); typedef size_t (*ZSTD_rust_resetCCtxWorkspaceCreate_f)( void* context, size_t neededSpace); typedef void* (*ZSTD_rust_resetCCtxWorkspaceReserveObject_f)( void* context, size_t size); typedef size_t (*ZSTD_rust_resetCCtxTailCallback_f)(void* context); typedef void (*ZSTD_rust_resetCCtxWorkspacePrepare_f)( void* context, size_t neededSpace, size_t windowSize, size_t blockSize, int* workspaceTooSmall, int* workspaceWasteful); typedef void (*ZSTD_rust_resetCCtxTailPrepare_f)( void* context, size_t blockSize, int indexResetPolicy); void ZSTD_rust_workspaceResizeFlags( size_t workspaceSize, size_t availableSpace, int workspaceOversizedDuration, size_t neededSpace, int* workspaceTooSmall, int* workspaceWasteful); void ZSTD_rust_workspaceBumpOversizedDuration( size_t availableSpace, size_t additionalNeededSpace, int* workspaceOversizedDuration); typedef struct { void* callbackContext; int ldmEnable; int hasExtSeqProd; U32 hashLog; U32 bucketSizeLog; size_t blockSize; size_t maxNbSeq; size_t maxNbLdmSeq; size_t maxNbExternalSeq; size_t buffInSize; size_t buffOutSize; size_t seqDefSize; size_t ldmEntrySize; size_t rawSeqSize; size_t externalSequenceSize; size_t byteSize; size_t wildcopyOverlength; int bufferedPolicy; ZSTD_rust_resetCCtxStorageSetPointer_f setPointer; ZSTD_rust_resetCCtxStorageSetSize_f setSize; ZSTD_rust_resetCCtxStorageSetInt_f setInt; ZSTD_rust_resetCCtxStorageReserve_f reserve; ZSTD_rust_resetCCtxStorageReserveFailed_f reserveFailed; ZSTD_rust_resetCCtxStorageZero_f zero; ZSTD_rust_resetCCtxStorageCallback_f windowInit; ZSTD_rust_resetCCtxStorageCallback_f resetExternalSequences; } ZSTD_rust_resetCCtxStorageState; typedef char ZSTD_rust_reset_cctx_storage_state_layout[ (offsetof(ZSTD_rust_resetCCtxStorageState, callbackContext) == 0 && offsetof(ZSTD_rust_resetCCtxStorageState, ldmEnable) == sizeof(void*) && offsetof(ZSTD_rust_resetCCtxStorageState, hasExtSeqProd) == sizeof(void*) + sizeof(int) && offsetof(ZSTD_rust_resetCCtxStorageState, hashLog) > offsetof(ZSTD_rust_resetCCtxStorageState, hasExtSeqProd) && offsetof(ZSTD_rust_resetCCtxStorageState, bucketSizeLog) == offsetof(ZSTD_rust_resetCCtxStorageState, hashLog) + sizeof(U32) && offsetof(ZSTD_rust_resetCCtxStorageState, blockSize) > offsetof(ZSTD_rust_resetCCtxStorageState, bucketSizeLog) && offsetof(ZSTD_rust_resetCCtxStorageState, maxNbSeq) == offsetof(ZSTD_rust_resetCCtxStorageState, blockSize) + sizeof(size_t) && offsetof(ZSTD_rust_resetCCtxStorageState, maxNbLdmSeq) == offsetof(ZSTD_rust_resetCCtxStorageState, maxNbSeq) + sizeof(size_t) && offsetof(ZSTD_rust_resetCCtxStorageState, maxNbExternalSeq) == offsetof(ZSTD_rust_resetCCtxStorageState, maxNbLdmSeq) + sizeof(size_t) && offsetof(ZSTD_rust_resetCCtxStorageState, buffInSize) == offsetof(ZSTD_rust_resetCCtxStorageState, maxNbExternalSeq) + sizeof(size_t) && offsetof(ZSTD_rust_resetCCtxStorageState, buffOutSize) == offsetof(ZSTD_rust_resetCCtxStorageState, buffInSize) + sizeof(size_t) && offsetof(ZSTD_rust_resetCCtxStorageState, seqDefSize) == offsetof(ZSTD_rust_resetCCtxStorageState, buffOutSize) + sizeof(size_t) && offsetof(ZSTD_rust_resetCCtxStorageState, ldmEntrySize) == offsetof(ZSTD_rust_resetCCtxStorageState, seqDefSize) + sizeof(size_t) && offsetof(ZSTD_rust_resetCCtxStorageState, rawSeqSize) == offsetof(ZSTD_rust_resetCCtxStorageState, ldmEntrySize) + sizeof(size_t) && offsetof(ZSTD_rust_resetCCtxStorageState, externalSequenceSize) == offsetof(ZSTD_rust_resetCCtxStorageState, rawSeqSize) + sizeof(size_t) && offsetof(ZSTD_rust_resetCCtxStorageState, byteSize) == offsetof(ZSTD_rust_resetCCtxStorageState, externalSequenceSize) + sizeof(size_t) && offsetof(ZSTD_rust_resetCCtxStorageState, wildcopyOverlength) == offsetof(ZSTD_rust_resetCCtxStorageState, byteSize) + sizeof(size_t) && offsetof(ZSTD_rust_resetCCtxStorageState, bufferedPolicy) > offsetof(ZSTD_rust_resetCCtxStorageState, wildcopyOverlength) && offsetof(ZSTD_rust_resetCCtxStorageState, setSize) == offsetof(ZSTD_rust_resetCCtxStorageState, setPointer) + sizeof(void*) && offsetof(ZSTD_rust_resetCCtxStorageState, setInt) == offsetof(ZSTD_rust_resetCCtxStorageState, setSize) + sizeof(void*) && offsetof(ZSTD_rust_resetCCtxStorageState, reserve) == offsetof(ZSTD_rust_resetCCtxStorageState, setInt) + sizeof(void*) && sizeof(ZSTD_rust_resetCCtxStorageState) == offsetof(ZSTD_rust_resetCCtxStorageState, resetExternalSequences) + sizeof(void*)) ? 1 : -1]; typedef struct { void* callbackContext; int isStatic; int workspaceTooSmall; int workspaceWasteful; size_t neededSpace; size_t compressedBlockStateSize; size_t tmpWorkspaceSize; int* needsIndexReset; ZSTD_rust_resetCCtxStorageCallback_f bumpOversizedDuration; ZSTD_rust_resetCCtxStorageCallback_f freeWorkspace; ZSTD_rust_resetCCtxWorkspaceCreate_f createWorkspace; ZSTD_rust_resetCCtxWorkspaceReserveObject_f reserveObject; ZSTD_rust_resetCCtxStorageSetPointer_f setPointer; ZSTD_rust_resetCCtxStorageSetSize_f setSize; ZSTD_rust_resetCCtxStorageCallback_f clearWorkspace; } ZSTD_rust_resetCCtxWorkspaceState; typedef char ZSTD_rust_reset_cctx_workspace_state_layout[ (offsetof(ZSTD_rust_resetCCtxWorkspaceState, callbackContext) == 0 && offsetof(ZSTD_rust_resetCCtxWorkspaceState, isStatic) == sizeof(void*) && offsetof(ZSTD_rust_resetCCtxWorkspaceState, workspaceTooSmall) == sizeof(void*) + sizeof(int) && offsetof(ZSTD_rust_resetCCtxWorkspaceState, workspaceWasteful) == sizeof(void*) + 2 * sizeof(int) && offsetof(ZSTD_rust_resetCCtxWorkspaceState, neededSpace) > offsetof(ZSTD_rust_resetCCtxWorkspaceState, workspaceWasteful) && offsetof(ZSTD_rust_resetCCtxWorkspaceState, compressedBlockStateSize) == offsetof(ZSTD_rust_resetCCtxWorkspaceState, neededSpace) + sizeof(size_t) && offsetof(ZSTD_rust_resetCCtxWorkspaceState, tmpWorkspaceSize) == offsetof(ZSTD_rust_resetCCtxWorkspaceState, compressedBlockStateSize) + sizeof(size_t) && offsetof(ZSTD_rust_resetCCtxWorkspaceState, needsIndexReset) == offsetof(ZSTD_rust_resetCCtxWorkspaceState, tmpWorkspaceSize) + sizeof(size_t) && sizeof(ZSTD_rust_resetCCtxWorkspaceState) == offsetof(ZSTD_rust_resetCCtxWorkspaceState, clearWorkspace) + sizeof(void*)) ? 1 : -1]; typedef struct { void* callbackContext; ZSTD_rust_resetCCtxStorageCallback_f resetHash; void* compressedBlockState; ZSTD_rust_resetCCtxTailCallback_f resetMatchState; const ZSTD_rust_resetCCtxStorageState* storageState; ZSTD_compressionParameters* matchStateCParams; int* matchStatePrefetchCDictTables; unsigned long long* pledgedSrcSizePlusOne; unsigned long long* consumedSrcSize; unsigned long long* producedCSize; int* contentSizeFlag; size_t* blockSizeMax; int* stage; U32* dictID; size_t* dictContentSize; ZSTD_compressionParameters cParams; int prefetchCDictTables; U64 pledgedSrcSize; size_t blockSize; } ZSTD_rust_resetCCtxTailState; typedef char ZSTD_rust_reset_cctx_tail_state_layout[ (offsetof(ZSTD_rust_resetCCtxTailState, callbackContext) == 0 && offsetof(ZSTD_rust_resetCCtxTailState, resetHash) == sizeof(void*) && offsetof(ZSTD_rust_resetCCtxTailState, compressedBlockState) == 2 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxTailState, resetMatchState) == 3 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxTailState, storageState) == 4 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxTailState, matchStateCParams) == 5 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxTailState, matchStatePrefetchCDictTables) == 6 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxTailState, pledgedSrcSizePlusOne) == 7 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxTailState, consumedSrcSize) == 8 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxTailState, producedCSize) == 9 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxTailState, contentSizeFlag) == 10 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxTailState, blockSizeMax) == 11 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxTailState, stage) == 12 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxTailState, dictID) == 13 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxTailState, dictContentSize) == 14 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxTailState, cParams) == 15 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxTailState, prefetchCDictTables) == offsetof(ZSTD_rust_resetCCtxTailState, cParams) + sizeof(ZSTD_compressionParameters) && offsetof(ZSTD_rust_resetCCtxTailState, pledgedSrcSize) > offsetof(ZSTD_rust_resetCCtxTailState, prefetchCDictTables) && offsetof(ZSTD_rust_resetCCtxTailState, blockSize) == offsetof(ZSTD_rust_resetCCtxTailState, pledgedSrcSize) + sizeof(U64) && sizeof(ZSTD_rust_resetCCtxTailState) == offsetof(ZSTD_rust_resetCCtxTailState, blockSize) + sizeof(size_t)) ? 1 : -1]; typedef struct { void* callbackContext; const ZSTD_rustCCtxResetState* resetState; ZSTD_rust_resetCCtxStorageState* storageState; ZSTD_rust_resetCCtxWorkspaceState* workspaceState; ZSTD_rust_resetCCtxTailState* tailState; ZSTD_rust_resetCCtxWorkspacePrepare_f prepareWorkspace; ZSTD_rust_resetCCtxTailPrepare_f prepareTail; } ZSTD_rust_resetCCtxInternalState; typedef char ZSTD_rust_reset_cctx_internal_state_layout[ (offsetof(ZSTD_rust_resetCCtxInternalState, callbackContext) == 0 && offsetof(ZSTD_rust_resetCCtxInternalState, resetState) == sizeof(void*) && offsetof(ZSTD_rust_resetCCtxInternalState, storageState) == 2 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxInternalState, workspaceState) == 3 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxInternalState, tailState) == 4 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxInternalState, prepareWorkspace) == 5 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxInternalState, prepareTail) == 6 * sizeof(void*) && sizeof(ZSTD_rust_resetCCtxInternalState) == 7 * sizeof(void*)) ? 1 : -1]; enum { ZSTD_RUST_RESET_CCTX_RESERVE_ALIGNED64 = 0, ZSTD_RUST_RESET_CCTX_RESERVE_BUFFER = 1 }; enum { ZSTD_RUST_RESET_CCTX_POINTER_SEQ_START = 0, ZSTD_RUST_RESET_CCTX_POINTER_LDM_HASH = 1, ZSTD_RUST_RESET_CCTX_POINTER_LDM_SEQUENCES = 2, ZSTD_RUST_RESET_CCTX_POINTER_EXTERNAL_SEQUENCES = 3, ZSTD_RUST_RESET_CCTX_POINTER_LITERALS = 4, ZSTD_RUST_RESET_CCTX_POINTER_INPUT_BUFFER = 5, ZSTD_RUST_RESET_CCTX_POINTER_OUTPUT_BUFFER = 6, ZSTD_RUST_RESET_CCTX_POINTER_LL_CODE = 7, ZSTD_RUST_RESET_CCTX_POINTER_ML_CODE = 8, ZSTD_RUST_RESET_CCTX_POINTER_OF_CODE = 9, ZSTD_RUST_RESET_CCTX_POINTER_LDM_BUCKETS = 10, ZSTD_RUST_RESET_CCTX_POINTER_PREV_CBLOCK = 11, ZSTD_RUST_RESET_CCTX_POINTER_NEXT_CBLOCK = 12, ZSTD_RUST_RESET_CCTX_POINTER_TMP_WORKSPACE = 13 }; enum { ZSTD_RUST_RESET_CCTX_SIZE_MAX_NB_SEQ = 0, ZSTD_RUST_RESET_CCTX_SIZE_MAX_NB_LIT = 1, ZSTD_RUST_RESET_CCTX_SIZE_MAX_NB_LDM_SEQ = 2, ZSTD_RUST_RESET_CCTX_SIZE_EXTERNAL_SEQ_CAPACITY = 3, ZSTD_RUST_RESET_CCTX_SIZE_INPUT_BUFFER = 4, ZSTD_RUST_RESET_CCTX_SIZE_OUTPUT_BUFFER = 5, ZSTD_RUST_RESET_CCTX_SIZE_TMP_WORKSPACE = 6 }; enum { ZSTD_RUST_RESET_CCTX_INT_BUFFERED_POLICY = 0, ZSTD_RUST_RESET_CCTX_INT_INITIALIZED = 1 }; size_t ZSTD_rust_resetCCtxStorage(const ZSTD_rust_resetCCtxStorageState* state); size_t ZSTD_rust_resetCCtxWorkspace( const ZSTD_rust_resetCCtxWorkspaceState* state); size_t ZSTD_rust_resetCCtxTail(const ZSTD_rust_resetCCtxTailState* state); size_t ZSTD_rust_resetCCtxInternal( const ZSTD_rust_resetCCtxInternalState* state); size_t ZSTD_rust_estimateCCtxWorkspaceSize( ZSTD_compressionParameters cParams, int ldmEnable, U32 ldmHashLog, U32 ldmBucketSizeLog, U32 ldmMinMatchLength, int isStatic, int useRowMatchFinder, size_t buffInSize, size_t buffOutSize, U64 pledgedSrcSize, int useSequenceProducer, size_t maxBlockSize, const ZSTD_rustCCtxWorkspaceSizing* sizing); size_t ZSTD_rust_planCCtxReset(const ZSTD_rustCCtxResetState* state); size_t ZSTD_rust_maxEstimateCCtxSize(size_t estimate0, size_t estimate1, size_t estimate2, size_t estimate3); typedef size_t (*ZSTD_rust_estimateCSizeUsingCParams_f)( void* context, int useRowMatchFinder); typedef struct { void* callbackContext; int strategy; ZSTD_rust_estimateCSizeUsingCParams_f estimate; } ZSTD_rust_estimateCSizeUsingCParamsState; size_t ZSTD_rust_estimateCSizeUsingCParams( const ZSTD_rust_estimateCSizeUsingCParamsState* state); typedef char ZSTD_rust_estimate_csize_using_cparams_state_layout[ (offsetof(ZSTD_rust_estimateCSizeUsingCParamsState, callbackContext) == 0 && offsetof(ZSTD_rust_estimateCSizeUsingCParamsState, strategy) == sizeof(void*) && offsetof(ZSTD_rust_estimateCSizeUsingCParamsState, estimate) == 2 * sizeof(void*) && sizeof(ZSTD_rust_estimateCSizeUsingCParamsState) == 3 * sizeof(void*)) ? 1 : -1]; typedef size_t (*ZSTD_rust_estimateCSize_f)(void* context, int compressionLevel); typedef struct { void* callbackContext; int compressionLevel; ZSTD_rust_estimateCSize_f estimate; } ZSTD_rust_estimateCSizeState; size_t ZSTD_rust_estimateCSizeMonotonic( const ZSTD_rust_estimateCSizeState* state); typedef char ZSTD_rust_estimate_csize_state_layout[ (offsetof(ZSTD_rust_estimateCSizeState, callbackContext) == 0 && offsetof(ZSTD_rust_estimateCSizeState, compressionLevel) == sizeof(void*) && offsetof(ZSTD_rust_estimateCSizeState, estimate) == 2 * sizeof(void*) && sizeof(ZSTD_rust_estimateCSizeState) == 3 * sizeof(void*)) ? 1 : -1]; typedef ZSTD_compressionParameters (*ZSTD_rust_estimateCCtxSizeGetCParams_f)( void* context, int compressionLevel, U64 srcSizeHint); typedef size_t (*ZSTD_rust_estimateCCtxSizeEstimate_f)( void* context, ZSTD_compressionParameters cParams); typedef struct { void* callbackContext; int compressionLevel; ZSTD_rust_estimateCCtxSizeGetCParams_f getCParams; ZSTD_rust_estimateCCtxSizeEstimate_f estimate; } ZSTD_rust_estimateCCtxSizeState; typedef char ZSTD_rust_estimate_cctx_size_state_layout[ (offsetof(ZSTD_rust_estimateCCtxSizeState, callbackContext) == 0 && offsetof(ZSTD_rust_estimateCCtxSizeState, compressionLevel) == sizeof(void*) && offsetof(ZSTD_rust_estimateCCtxSizeState, getCParams) == 2 * sizeof(void*) && offsetof(ZSTD_rust_estimateCCtxSizeState, estimate) == 3 * sizeof(void*) && sizeof(ZSTD_rust_estimateCCtxSizeState) == 4 * sizeof(void*)) ? 1 : -1]; size_t ZSTD_rust_estimateCCtxSizeInternal( const ZSTD_rust_estimateCCtxSizeState* state); ZSTD_inBuffer ZSTD_rust_inBufferForEndFlush(int inBufferMode, const void* expectedSrc, size_t expectedSize, size_t expectedPos); size_t ZSTD_rust_endStreamRemaining(size_t remainingToFlush, int frameEnded, int checksumFlag); size_t ZSTD_rust_endStreamRemainingPolicy(size_t remainingToFlush, int nbWorkers, int frameEnded, int checksumFlag); size_t ZSTD_rust_checkBufferStability( int inBufferMode, int outBufferMode, const void* expectedInSrc, size_t expectedInPos, const void* inputSrc, size_t inputPos, size_t expectedOutBufferSize, size_t outputSize, size_t outputPos); void ZSTD_rust_setBufferExpectations( int inBufferMode, int outBufferMode, ZSTD_inBuffer* expectedInBuffer, size_t* expectedOutBufferSize, const ZSTD_outBuffer* output, const ZSTD_inBuffer* input); /* Context-free compression-parameter selection and sizing leaves live in * Rust (rust/src/zstd_compress_params.rs). This file retains * configuration-sensitive policy: the C-preprocessor construction of the * excluded-block-compressor mask, private ZSTD_CCtx_params handling, and * sanitizer workspace policy, which it feeds to the leaves as explicit * scalar inputs. The ZSTD_CParamMode_e and ZSTD_ParamSwitch_e enums are * passed as int; the Rust side mirrors their values. */ ZSTD_bounds ZSTD_rust_params_getBounds(int param); void ZSTD_rust_params_assertEqualCParams(ZSTD_compressionParameters cParams1, ZSTD_compressionParameters cParams2); ZSTD_compressionParameters ZSTD_clampCParams(ZSTD_compressionParameters cParams); ZSTD_compressionParameters ZSTD_rust_params_selectCParams(int compressionLevel, U64 srcSizeHint, size_t dictSize, int mode); ZSTD_compressionParameters ZSTD_rust_params_adjustCParams(ZSTD_compressionParameters cParams, U64 srcSize, size_t dictSize, int mode, int useRowMatchFinder); ZSTD_compressionParameters ZSTD_rust_params_getCParamsInternal( int compressionLevel, U64 srcSizeHint, size_t dictSize, int mode, U32 exclusionMask); ZSTD_parameters ZSTD_rust_params_getParamsInternal( int compressionLevel, U64 srcSizeHint, size_t dictSize, int mode, U32 exclusionMask); ZSTD_compressionParameters ZSTD_rust_params_getCParams( int compressionLevel, U64 srcSizeHint, size_t dictSize, U32 exclusionMask); ZSTD_parameters ZSTD_rust_params_getParams( int compressionLevel, U64 srcSizeHint, size_t dictSize, U32 exclusionMask); ZSTD_compressionParameters ZSTD_rust_params_applyStrategyExclusions( ZSTD_compressionParameters cParams, U32 exclusionMask); ZSTD_compressionParameters ZSTD_rust_params_getCParamsFromCCtxParams( int compressionLevel, int cctxSrcSizeHint, U64 srcSizeHint, size_t dictSize, int mode, int enableLdm, U32 ldmDefaultWindowLog, ZSTD_compressionParameters overrides, int useRowMatchFinder, U32 exclusionMask); ZSTD_parameters ZSTD_rust_params_makeParams(ZSTD_compressionParameters cParams); size_t ZSTD_rust_params_maxNbSeq(size_t blockSize, U32 minMatch, int useSequenceProducer); size_t ZSTD_resolveMaxBlockSize(size_t maxBlockSize); size_t ZSTD_rust_params_getBlockSize(size_t maxBlockSize, U32 windowLog); int ZSTD_resolveExternalSequenceValidation(int mode); int ZSTD_rowMatchFinderSupported(int strategy); int ZSTD_rust_params_rowMatchFinderUsed(int strategy, int mode); int ZSTD_resolveRowMatchFinderMode( int mode, ZSTD_compressionParameters cParams); int ZSTD_resolveBlockSplitterMode( int mode, ZSTD_compressionParameters cParams); int ZSTD_rust_params_allocateChainTable(int strategy, int mode, int forDDSDict); int ZSTD_resolveEnableLdm( int mode, ZSTD_compressionParameters cParams); int ZSTD_resolveExternalRepcodeSearch(int mode, int cLevel); int ZSTD_CDictIndicesAreTagged(ZSTD_compressionParameters cParams); ZSTD_compressionParameters ZSTD_rust_params_dedicatedDictSearch_revertCParams(ZSTD_compressionParameters cParams); int ZSTD_rust_params_getCParamMode(int cdict_present, int cdict_strategy, int cdict_dedicated_search, U64 pledgedSrcSize, int params_attachDictPref, int params_forceWindow); typedef struct { const ZSTD_BlockCompressor_f* blockCompressors; const ZSTD_BlockCompressor_f* rowBlockCompressors; ZSTD_BlockCompressor_f* selectedCompressor; } ZSTD_rust_selectBlockCompressorState; size_t ZSTD_rust_selectBlockCompressor( const ZSTD_rust_selectBlockCompressorState* state, int strategy, int useRowMatchFinder, int dictMode); typedef char ZSTD_rust_select_block_compressor_state_layout[ (offsetof(ZSTD_rust_selectBlockCompressorState, blockCompressors) == 0 && offsetof(ZSTD_rust_selectBlockCompressorState, rowBlockCompressors) == sizeof(void*) && offsetof(ZSTD_rust_selectBlockCompressorState, selectedCompressor) == 2 * sizeof(void*) && sizeof(ZSTD_rust_selectBlockCompressorState) == 3 * sizeof(void*)) ? 1 : -1]; /* CCtx parameter state is mirrored by rust/src/zstd_compress_params_api.rs. * Rust owns parameter bounds and clamping; C exposes only the * build-configuration values required by that narrow ABI. */ size_t ZSTD_rust_cctx_params_clamp_bounds(int param, int* value); int ZSTD_rust_cctx_params_within_bounds(int param, int value); int ZSTD_rust_cctx_params_is_multithreaded(void); int ZSTD_rust_cctx_params_nb_workers_max(void); int ZSTD_rust_cctx_params_job_size_min(void); int ZSTD_rust_cctx_params_job_size_max(void); ZSTD_CCtx_params* ZSTD_rust_createCCtxParams(ZSTD_customMem customMem); void ZSTD_rust_makeCCtxParamsFromCParams( ZSTD_CCtx_params* cctxParams, const ZSTD_compressionParameters* cParams); void ZSTD_rust_CCtxParams_init_internal( ZSTD_CCtx_params* cctxParams, const ZSTD_parameters* params, int compressionLevel); void ZSTD_rust_CCtxParams_setZstdParams(ZSTD_CCtx_params* cctxParams, const ZSTD_parameters* params); int ZSTD_useTargetCBlockSize(const ZSTD_CCtx_params* cctxParams); int ZSTD_blockSplitterEnabled(ZSTD_CCtx_params* cctxParams); #define ZSTD_RUST_CCTX_PARAMS_ASSERT(name, condition) \ typedef char name[(condition) ? 1 : -1] ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_ldm_size, sizeof(ldmParams_t) == 24); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_custom_mem_size, sizeof(ZSTD_customMem) == (sizeof(void*) == 8 ? 24 : 12)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_size, sizeof(ZSTD_CCtx_params) == (sizeof(void*) == 8 ? 224 : 180)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_format_offset, offsetof(ZSTD_CCtx_params, format) == 0); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_cparams_offset, offsetof(ZSTD_CCtx_params, cParams) == 4); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_fparams_offset, offsetof(ZSTD_CCtx_params, fParams) == 32); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_level_offset, offsetof(ZSTD_CCtx_params, compressionLevel) == 44); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_force_window_offset, offsetof(ZSTD_CCtx_params, forceWindow) == 48); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_target_block_offset, offsetof(ZSTD_CCtx_params, targetCBlockSize) == (sizeof(void*) == 8 ? 56 : 52)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_src_hint_offset, offsetof(ZSTD_CCtx_params, srcSizeHint) == (sizeof(void*) == 8 ? 64 : 56)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_attach_offset, offsetof(ZSTD_CCtx_params, attachDictPref) == (sizeof(void*) == 8 ? 68 : 60)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_literal_mode_offset, offsetof(ZSTD_CCtx_params, literalCompressionMode) == (sizeof(void*) == 8 ? 72 : 64)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_workers_offset, offsetof(ZSTD_CCtx_params, nbWorkers) == (sizeof(void*) == 8 ? 76 : 68)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_job_size_offset, offsetof(ZSTD_CCtx_params, jobSize) == (sizeof(void*) == 8 ? 80 : 72)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_overlap_offset, offsetof(ZSTD_CCtx_params, overlapLog) == (sizeof(void*) == 8 ? 88 : 76)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_rsyncable_offset, offsetof(ZSTD_CCtx_params, rsyncable) == (sizeof(void*) == 8 ? 92 : 80)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_ldm_offset, offsetof(ZSTD_CCtx_params, ldmParams) == (sizeof(void*) == 8 ? 96 : 84)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_dedicated_dict_offset, offsetof(ZSTD_CCtx_params, enableDedicatedDictSearch) == (sizeof(void*) == 8 ? 120 : 108)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_in_buffer_offset, offsetof(ZSTD_CCtx_params, inBufferMode) == (sizeof(void*) == 8 ? 124 : 112)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_out_buffer_offset, offsetof(ZSTD_CCtx_params, outBufferMode) == (sizeof(void*) == 8 ? 128 : 116)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_delimiters_offset, offsetof(ZSTD_CCtx_params, blockDelimiters) == (sizeof(void*) == 8 ? 132 : 120)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_validate_offset, offsetof(ZSTD_CCtx_params, validateSequences) == (sizeof(void*) == 8 ? 136 : 124)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_post_splitter_offset, offsetof(ZSTD_CCtx_params, postBlockSplitter) == (sizeof(void*) == 8 ? 140 : 128)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_pre_splitter_offset, offsetof(ZSTD_CCtx_params, preBlockSplitter_level) == (sizeof(void*) == 8 ? 144 : 132)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_max_block_offset, offsetof(ZSTD_CCtx_params, maxBlockSize) == (sizeof(void*) == 8 ? 152 : 136)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_row_matcher_offset, offsetof(ZSTD_CCtx_params, useRowMatchFinder) == (sizeof(void*) == 8 ? 160 : 140)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_deterministic_prefix_offset, offsetof(ZSTD_CCtx_params, deterministicRefPrefix) == (sizeof(void*) == 8 ? 164 : 144)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_custom_mem_offset, offsetof(ZSTD_CCtx_params, customMem) == (sizeof(void*) == 8 ? 168 : 148)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_prefetch_offset, offsetof(ZSTD_CCtx_params, prefetchCDictTables) == (sizeof(void*) == 8 ? 192 : 160)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_fallback_offset, offsetof(ZSTD_CCtx_params, enableMatchFinderFallback) == (sizeof(void*) == 8 ? 196 : 164)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_state_offset, offsetof(ZSTD_CCtx_params, extSeqProdState) == (sizeof(void*) == 8 ? 200 : 168)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_function_offset, offsetof(ZSTD_CCtx_params, extSeqProdFunc) == (sizeof(void*) == 8 ? 208 : 172)); ZSTD_RUST_CCTX_PARAMS_ASSERT(ZSTD_rust_cctx_params_repcode_offset, offsetof(ZSTD_CCtx_params, searchForExternalRepcodes) == (sizeof(void*) == 8 ? 216 : 176)); #undef ZSTD_RUST_CCTX_PARAMS_ASSERT typedef struct { size_t cdictSize; size_t hufWorkspaceSize; U32 hashLog3Max; size_t matchTSize; size_t optimalTSize; size_t asanRedzoneSize; } ZSTD_rustCDictSizing; typedef char zstd_rust_cdict_sizing_layout[ (offsetof(ZSTD_rustCDictSizing, cdictSize) == 0 && offsetof(ZSTD_rustCDictSizing, hufWorkspaceSize) == sizeof(size_t) && offsetof(ZSTD_rustCDictSizing, hashLog3Max) == 2 * sizeof(size_t) && offsetof(ZSTD_rustCDictSizing, matchTSize) == 3 * sizeof(size_t) && offsetof(ZSTD_rustCDictSizing, optimalTSize) == 4 * sizeof(size_t) && offsetof(ZSTD_rustCDictSizing, asanRedzoneSize) == 5 * sizeof(size_t) && sizeof(ZSTD_rustCDictSizing) == 6 * sizeof(size_t)) ? 1 : -1]; size_t ZSTD_rust_params_estimateCDictSizeFromCParams( size_t dictSize, ZSTD_compressionParameters cParams, int dictLoadMethod, const ZSTD_rustCDictSizing* sizing); size_t ZSTD_rust_params_estimateCDictWorkspaceSize( size_t dictSize, ZSTD_compressionParameters cParams, int dictLoadMethod, int useRowMatchFinder, int enableDedicatedDictSearch, const ZSTD_rustCDictSizing* sizing); /* Sequence statistics and seqStore entropy compression live in Rust * (rust/src/zstd_compress_stats.rs), which also exports ZSTD_seqToCodes() * under its original name. The shims below extract the sequence store, the * entropy-table leaves, and the only two ZSTD_CCtx_params fields these paths * read (the strategy and the literals-compression switch), so the private * parameter structure layout never crosses the language boundary. The * shared leaf layouts are pinned by the compile-time asserts that follow. */ size_t ZSTD_rust_entropyCompressSeqStore_internal( void* dst, size_t dstCapacity, const void* literals, size_t litSize, const SeqStore_t* seqStorePtr, const ZSTD_entropyCTables_t* prevEntropy, ZSTD_entropyCTables_t* nextEntropy, int strategy, int disableLiteralCompression, void* entropyWorkspace, size_t entropyWkspSize, int bmi2); size_t ZSTD_rust_buildBlockEntropyStats( const SeqStore_t* seqStorePtr, const ZSTD_entropyCTables_t* prevEntropy, ZSTD_entropyCTables_t* nextEntropy, int strategy, int disableLiteralCompression, ZSTD_entropyCTablesMetadata_t* entropyMetadata, void* workspace, size_t wkspSize); void ZSTD_rust_invalidateRepCodes(U32 rep[ZSTD_REP_NUM]); void ZSTD_rust_invalidateMatchState( size_t endT, U32* lowLimit, U32* dictLimit, U32* nextToUpdate, U32* loadedDictEnd, U32* litLengthSum, const ZSTD_MatchState_t** dictMatchState); typedef char ZSTD_rust_invalidate_rep_count[(ZSTD_REP_NUM == 3) ? 1 : -1]; void ZSTD_rust_confirmRepcodesAndEntropyTables( ZSTD_compressedBlockState_t** prevCBlock, ZSTD_compressedBlockState_t** nextCBlock); void ZSTD_rust_storeLastLiterals(SeqStore_t* seqStorePtr, const BYTE* anchor, size_t lastLLSize); void ZSTD_rust_validateSeqStore(const SeqStore_t* seqStore, U32 minMatch); U32 ZSTD_rust_resolveRepcodeToRawOffset(const U32 rep[ZSTD_REP_NUM], U32 offBase, U32 ll0); /* Rust owns dictionary-content orchestration and policy. The callbacks below * keep configuration-sensitive match-state, LDM, workspace, and matchfinder * operations private to C. */ typedef size_t (*ZSTD_rust_loadDictionaryContent_f)( void* matchState, void* ldmState, void* workspaceState, const void* params, const void* src, size_t srcSize, int dtlm, int tfp); typedef void (*ZSTD_rust_loadDictionaryContent_assert_f)(void* context); typedef void (*ZSTD_rust_loadDictionaryContent_assertWindowEmpty_f)( void* context, int ldm); typedef void (*ZSTD_rust_loadDictionaryContent_windowUpdate_f)( void* context, int ldm, const void* src, size_t srcSize); typedef void (*ZSTD_rust_loadDictionaryContent_fillLdm_f)( void* context, const void* ip, const void* iend); typedef void (*ZSTD_rust_loadDictionaryContent_overflowCorrect_f)( void* context, const void* ip, const void* iend); typedef struct { const BYTE** base; U32* loadedDictEnd; } ZSTD_rust_loadDictionaryContentLdmPublicationState; typedef char ZSTD_rust_load_dictionary_ldm_publication_layout[ (offsetof(ZSTD_rust_loadDictionaryContentLdmPublicationState, base) == 0 && offsetof(ZSTD_rust_loadDictionaryContentLdmPublicationState, loadedDictEnd) == sizeof(void*) && sizeof(ZSTD_rust_loadDictionaryContentLdmPublicationState) == 2 * sizeof(void*)) ? 1 : -1]; typedef struct { const BYTE** base; U32* nextToUpdate; U32* loadedDictEnd; int* forceNonContiguous; } ZSTD_rust_loadDictionaryContentMatchStatePublicationState; typedef char ZSTD_rust_load_dictionary_match_state_publication_layout[ (offsetof(ZSTD_rust_loadDictionaryContentMatchStatePublicationState, base) == 0 && offsetof(ZSTD_rust_loadDictionaryContentMatchStatePublicationState, nextToUpdate) == sizeof(void*) && offsetof(ZSTD_rust_loadDictionaryContentMatchStatePublicationState, loadedDictEnd) == 2 * sizeof(void*) && offsetof(ZSTD_rust_loadDictionaryContentMatchStatePublicationState, forceNonContiguous) == 3 * sizeof(void*) && sizeof(ZSTD_rust_loadDictionaryContentMatchStatePublicationState) == 4 * sizeof(void*)) ? 1 : -1]; /* The Fast dictionary-table leaf is implemented in Rust. Keep only the * fields needed by that leaf in the ABI projection; the complete * ZSTD_MatchState_t layout remains private to C. */ typedef struct { U32** hashTable; const BYTE** base; const U32* nextToUpdate; const U32* hashLog; const U32* minMatch; int fullTableLoad; int forCDict; } ZSTD_rust_loadDictionaryContentFastTableState; typedef char ZSTD_rust_load_dictionary_fast_table_layout[ (offsetof(ZSTD_rust_loadDictionaryContentFastTableState, hashTable) == 0 && offsetof(ZSTD_rust_loadDictionaryContentFastTableState, base) == sizeof(void*) && offsetof(ZSTD_rust_loadDictionaryContentFastTableState, nextToUpdate) == 2 * sizeof(void*) && offsetof(ZSTD_rust_loadDictionaryContentFastTableState, hashLog) == 3 * sizeof(void*) && offsetof(ZSTD_rust_loadDictionaryContentFastTableState, minMatch) == 4 * sizeof(void*) && offsetof(ZSTD_rust_loadDictionaryContentFastTableState, fullTableLoad) == 5 * sizeof(void*) && offsetof(ZSTD_rust_loadDictionaryContentFastTableState, forCDict) == 5 * sizeof(void*) + sizeof(int) && sizeof(ZSTD_rust_loadDictionaryContentFastTableState) == 5 * sizeof(void*) + 2 * sizeof(int)) ? 1 : -1]; /* The Double-Fast dictionary-table leaf is also implemented in Rust. Keep * pointers to the live match-state fields because window/publish callbacks * run before the Rust orchestrator selects this branch. */ typedef struct { U32** hashLong; U32** hashSmall; const BYTE** base; const U32* nextToUpdate; const U32* hashLog; const U32* chainLog; const U32* minMatch; int fullTableLoad; int forCDict; int available; } ZSTD_rust_loadDictionaryContentDoubleFastTableState; typedef char ZSTD_rust_load_dictionary_double_fast_table_layout[ (offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, hashLong) == 0 && offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, hashSmall) == sizeof(void*) && offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, base) == 2 * sizeof(void*) && offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, nextToUpdate) == 3 * sizeof(void*) && offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, hashLog) == 4 * sizeof(void*) && offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, chainLog) == 5 * sizeof(void*) && offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, minMatch) == 6 * sizeof(void*) && offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, fullTableLoad) == 7 * sizeof(void*) && offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, forCDict) == 7 * sizeof(void*) + sizeof(int) && offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, available) == 7 * sizeof(void*) + 2 * sizeof(int) && sizeof(ZSTD_rust_loadDictionaryContentDoubleFastTableState) == ((7 * sizeof(void*) + 3 * sizeof(int) + sizeof(void*) - 1) / sizeof(void*) * sizeof(void*))) ? 1 : -1]; typedef void (*ZSTD_rust_loadDictionaryContent_loadMatch_f)( void* context, const void* ip); typedef void (*ZSTD_rust_loadDictionaryContent_loadTree_f)( void* context, const void* ip, const void* iend); typedef struct { void* callbackContext; size_t currentMax; size_t windowStartIndex; size_t shortCacheTagBits; size_t chunkSizeMax; size_t hashReadSize; size_t hashLog; size_t chainLog; size_t cdictIndicesTagged; size_t ldmEnabled; size_t hasLdmState; size_t forceWindow; size_t deterministicRefPrefix; size_t strategy; size_t useRowMatchFinder; size_t dedicatedDictSearch; size_t dtlm; size_t tfp; ZSTD_rust_loadDictionaryContent_assert_f assertCParams; ZSTD_rust_loadDictionaryContent_assertWindowEmpty_f assertWindowEmpty; ZSTD_rust_loadDictionaryContent_windowUpdate_f windowUpdate; const ZSTD_rust_loadDictionaryContentLdmPublicationState* setLdmLoadedDictEnd; const ZSTD_rust_loadDictionaryContentMatchStatePublicationState* publishMatchState; ZSTD_rust_loadDictionaryContent_fillLdm_f fillLdm; ZSTD_rust_loadDictionaryContent_overflowCorrect_f overflowCorrect; const ZSTD_rust_loadDictionaryContentFastTableState* fastTable; const ZSTD_rust_loadDictionaryContentDoubleFastTableState* doubleFastTable; ZSTD_rust_loadDictionaryContent_loadMatch_f loadDedicated; ZSTD_rust_loadDictionaryContent_loadMatch_f loadRow; ZSTD_rust_loadDictionaryContent_loadMatch_f loadChain; ZSTD_rust_loadDictionaryContent_loadTree_f loadTree; const ZSTD_rust_loadDictionaryContentMatchStatePublicationState* publishFinalIndex; ZSTD_rust_loadDictionaryContent_assert_f assertLazyConfiguration; ZSTD_rust_loadDictionaryContent_assert_f assertInvalidStrategy; } ZSTD_rust_loadDictionaryContentState; #define ZSTD_RUST_LOAD_DICT_ASSERT(name, condition) \ typedef char name[(condition) ? 1 : -1] ZSTD_RUST_LOAD_DICT_ASSERT(ZSTD_rust_load_dict_context_offset, offsetof(ZSTD_rust_loadDictionaryContentState, callbackContext) == 0); ZSTD_RUST_LOAD_DICT_ASSERT(ZSTD_rust_load_dict_scalar_offset, offsetof(ZSTD_rust_loadDictionaryContentState, currentMax) == sizeof(void*)); ZSTD_RUST_LOAD_DICT_ASSERT(ZSTD_rust_load_dict_callback_offset, offsetof(ZSTD_rust_loadDictionaryContentState, assertCParams) == 18 * sizeof(void*)); ZSTD_RUST_LOAD_DICT_ASSERT(ZSTD_rust_load_dict_ldm_publication_offset, offsetof(ZSTD_rust_loadDictionaryContentState, setLdmLoadedDictEnd) == 21 * sizeof(void*)); ZSTD_RUST_LOAD_DICT_ASSERT(ZSTD_rust_load_dict_match_publication_offset, offsetof(ZSTD_rust_loadDictionaryContentState, publishMatchState) == 22 * sizeof(void*)); ZSTD_RUST_LOAD_DICT_ASSERT(ZSTD_rust_load_dict_fast_table_offset, offsetof(ZSTD_rust_loadDictionaryContentState, fastTable) == 25 * sizeof(void*)); ZSTD_RUST_LOAD_DICT_ASSERT(ZSTD_rust_load_dict_double_fast_table_offset, offsetof(ZSTD_rust_loadDictionaryContentState, doubleFastTable) == 26 * sizeof(void*)); ZSTD_RUST_LOAD_DICT_ASSERT(ZSTD_rust_load_dict_final_callback_offset, offsetof(ZSTD_rust_loadDictionaryContentState, publishFinalIndex) == 31 * sizeof(void*)); ZSTD_RUST_LOAD_DICT_ASSERT(ZSTD_rust_load_dict_lazy_callback_offset, offsetof(ZSTD_rust_loadDictionaryContentState, assertLazyConfiguration) == 32 * sizeof(void*)); ZSTD_RUST_LOAD_DICT_ASSERT(ZSTD_rust_load_dict_invalid_callback_offset, offsetof(ZSTD_rust_loadDictionaryContentState, assertInvalidStrategy) == 33 * sizeof(void*)); ZSTD_RUST_LOAD_DICT_ASSERT(ZSTD_rust_load_dict_state_size, sizeof(ZSTD_rust_loadDictionaryContentState) == 34 * sizeof(void*)); #undef ZSTD_RUST_LOAD_DICT_ASSERT size_t ZSTD_rust_loadDictionaryContent( const ZSTD_rust_loadDictionaryContentState* state, const void* src, size_t srcSize); size_t ZSTD_rust_compressInsertDictionary( ZSTD_compressedBlockState_t* bs, void* matchState, void* ldmState, void* workspaceState, const void* params, const void* dict, size_t dictSize, int dictContentType, int dtlm, int tfp, void* workspace, int noDictIDFlag, ZSTD_rust_loadDictionaryContent_f loadDictionaryContent); /* CCtx dictionary attachment policy lives in Rust. These callbacks keep * the private CCtx, local/prefix dictionary layouts, allocator, and CDict * lifetime operations in C. */ typedef void (*ZSTD_rust_CCtxDictionaryClear_f)(void* context); typedef size_t (*ZSTD_rust_CCtxAssignLocalDict_f)( void* context, const void* dict, size_t dictSize, int dictLoadMethod, int dictContentType); typedef void* (*ZSTD_rust_assignLocalDictAllocate_f)( void* context, size_t size); typedef struct { void* callbackContext; size_t staticSize; const void** dict; void** dictBuffer; size_t* dictSize; int* dictContentType; ZSTD_rust_assignLocalDictAllocate_f allocate; } ZSTD_rust_assignLocalDictState; typedef char ZSTD_rust_assign_local_dict_state_layout[ (offsetof(ZSTD_rust_assignLocalDictState, callbackContext) == 0 && offsetof(ZSTD_rust_assignLocalDictState, staticSize) == sizeof(void*) && offsetof(ZSTD_rust_assignLocalDictState, dict) == 2 * sizeof(void*) && offsetof(ZSTD_rust_assignLocalDictState, dictBuffer) == 3 * sizeof(void*) && offsetof(ZSTD_rust_assignLocalDictState, dictSize) == 4 * sizeof(void*) && offsetof(ZSTD_rust_assignLocalDictState, dictContentType) == 5 * sizeof(void*) && sizeof(ZSTD_rust_assignLocalDictAllocate_f) == sizeof(void*) && offsetof(ZSTD_rust_assignLocalDictState, allocate) == 6 * sizeof(void*) && sizeof(ZSTD_rust_assignLocalDictState) == 7 * sizeof(void*)) ? 1 : -1]; size_t ZSTD_rust_assignLocalDict( const ZSTD_rust_assignLocalDictState* state, const void* dict, size_t dictSize, int dictLoadMethod, int dictContentType); typedef void (*ZSTD_rust_CCtxAssignCDict_f)( void* context, const void* cdict); typedef void (*ZSTD_rust_CCtxAssignPrefixDict_f)( void* context, const void* prefix, size_t prefixSize, int dictContentType); size_t ZSTD_rust_CCtx_loadDictionaryAdvanced( void* context, int streamStage, const void* dict, size_t dictSize, int dictLoadMethod, int dictContentType, ZSTD_rust_CCtxDictionaryClear_f clearDictionaries, ZSTD_rust_CCtxAssignLocalDict_f assignLocalDict); size_t ZSTD_rust_CCtx_refCDict( void* context, int streamStage, const void* cdict, ZSTD_rust_CCtxDictionaryClear_f clearDictionaries, ZSTD_rust_CCtxAssignCDict_f assignCDict); size_t ZSTD_rust_CCtx_refPrefixAdvanced( void* context, int streamStage, const void* prefix, size_t prefixSize, int dictContentType, ZSTD_rust_CCtxDictionaryClear_f clearDictionaries, ZSTD_rust_CCtxAssignPrefixDict_f assignPrefixDict); typedef void (*ZSTD_rust_compressBeginUsingCDictInitParams_f)( void* cctxParams, const ZSTD_parameters* params, int compressionLevel); typedef void (*ZSTD_rust_compressBeginUsingCDictAdjustWindow_f)( void* cctxParams, U32 minWindowLog); typedef size_t (*ZSTD_rust_compressBeginUsingCDictBegin_f)( void* context, const void* cdict, const void* cctxParams, U64 pledgedSrcSize); typedef struct { void* cctx; const void* cdict; void* cctxParams; const ZSTD_compressionParameters* cdictCParams; const size_t* cdictContentSize; const int* cdictCompressionLevel; const ZSTD_frameParameters* fParams; const unsigned long long* pledgedSrcSize; const U32* exclusionMask; ZSTD_rust_compressBeginUsingCDictInitParams_f initParams; ZSTD_rust_compressBeginUsingCDictAdjustWindow_f adjustWindow; ZSTD_rust_compressBeginUsingCDictBegin_f begin; } ZSTD_rust_compressBeginUsingCDictState; size_t ZSTD_rust_compressBeginUsingCDict( const ZSTD_rust_compressBeginUsingCDictState* state); typedef char ZSTD_rust_compress_begin_using_cdict_state_layout[ (offsetof(ZSTD_rust_compressBeginUsingCDictState, cctx) == 0 && offsetof(ZSTD_rust_compressBeginUsingCDictState, cdict) == sizeof(void*) && offsetof(ZSTD_rust_compressBeginUsingCDictState, cctxParams) == 2 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginUsingCDictState, cdictCParams) == 3 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginUsingCDictState, cdictContentSize) == 4 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginUsingCDictState, cdictCompressionLevel) == 5 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginUsingCDictState, fParams) == 6 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginUsingCDictState, pledgedSrcSize) == 7 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginUsingCDictState, exclusionMask) == 8 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginUsingCDictState, initParams) == 9 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginUsingCDictState, adjustWindow) == 10 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginUsingCDictState, begin) == 11 * sizeof(void*) && sizeof(ZSTD_rust_compressBeginUsingCDictState) == 12 * sizeof(void*)) ? 1 : -1]; typedef size_t (*ZSTD_rust_compressUsingCDictBegin_f)( void* context, const void* cdict, const ZSTD_frameParameters* fParams, U64 pledgedSrcSize); typedef size_t (*ZSTD_rust_compressUsingCDictEnd_f)( void* context, void* dst, size_t dstCapacity, const void* src, size_t srcSize); typedef struct { void* callbackContext; const void* cdict; ZSTD_rust_compressUsingCDictBegin_f begin; ZSTD_rust_compressUsingCDictEnd_f end; } ZSTD_rust_compressUsingCDictState; size_t ZSTD_rust_compressUsingCDict( const ZSTD_rust_compressUsingCDictState* state, void* dst, size_t dstCapacity, const void* src, size_t srcSize); typedef char ZSTD_rust_compress_using_cdict_state_layout[ (offsetof(ZSTD_rust_compressUsingCDictState, callbackContext) == 0 && offsetof(ZSTD_rust_compressUsingCDictState, cdict) == sizeof(void*) && offsetof(ZSTD_rust_compressUsingCDictState, begin) == 2 * sizeof(void*) && offsetof(ZSTD_rust_compressUsingCDictState, end) == 3 * sizeof(void*) && sizeof(ZSTD_rust_compressUsingCDictState) == 4 * sizeof(void*)) ? 1 : -1]; typedef struct { void* callbackContext; const void* cdict; const ZSTD_frameParameters* fParams; ZSTD_rust_compressUsingCDictBegin_f begin; ZSTD_rust_compressUsingCDictEnd_f end; } ZSTD_rust_compressUsingCDictAdvancedState; size_t ZSTD_rust_compressUsingCDictAdvanced( const ZSTD_rust_compressUsingCDictAdvancedState* state, void* dst, size_t dstCapacity, const void* src, size_t srcSize); typedef char ZSTD_rust_compress_using_cdict_advanced_state_layout[ (offsetof(ZSTD_rust_compressUsingCDictAdvancedState, callbackContext) == 0 && offsetof(ZSTD_rust_compressUsingCDictAdvancedState, cdict) == sizeof(void*) && offsetof(ZSTD_rust_compressUsingCDictAdvancedState, fParams) == 2 * sizeof(void*) && offsetof(ZSTD_rust_compressUsingCDictAdvancedState, begin) == 3 * sizeof(void*) && offsetof(ZSTD_rust_compressUsingCDictAdvancedState, end) == 4 * sizeof(void*) && sizeof(ZSTD_rust_compressUsingCDictAdvancedState) == 5 * sizeof(void*)) ? 1 : -1]; typedef size_t (*ZSTD_rust_compressBeginUsingCDictPublicBegin_f)( void* context, const void* cdict, const ZSTD_frameParameters* fParams, U64 pledgedSrcSize); typedef struct { void* callbackContext; const void* cdict; ZSTD_rust_compressBeginUsingCDictPublicBegin_f begin; } ZSTD_rust_compressBeginUsingCDictPublicState; size_t ZSTD_rust_compressBeginUsingCDictPublic( const ZSTD_rust_compressBeginUsingCDictPublicState* state); typedef char ZSTD_rust_compress_begin_using_cdict_public_state_layout[ (offsetof(ZSTD_rust_compressBeginUsingCDictPublicState, callbackContext) == 0 && offsetof(ZSTD_rust_compressBeginUsingCDictPublicState, cdict) == sizeof(void*) && offsetof(ZSTD_rust_compressBeginUsingCDictPublicState, begin) == 2 * sizeof(void*) && sizeof(ZSTD_rust_compressBeginUsingCDictPublicState) == 3 * sizeof(void*)) ? 1 : -1]; typedef void (*ZSTD_rust_compressBeginUsingDictInitParams_f)( void* cctxParams, const ZSTD_parameters* params, int compressionLevel); typedef size_t (*ZSTD_rust_compressBeginUsingDictBegin_f)( void* context, const void* dict, size_t dictSize, const void* cctxParams, U64 pledgedSrcSize); typedef struct { void* cctx; void* cctxParams; const U32* exclusionMask; ZSTD_rust_compressBeginUsingDictInitParams_f initParams; ZSTD_rust_compressBeginUsingDictBegin_f begin; } ZSTD_rust_compressBeginUsingDictState; size_t ZSTD_rust_compressBeginUsingDict( const ZSTD_rust_compressBeginUsingDictState* state, const void* dict, size_t dictSize, int compressionLevel); typedef char ZSTD_rust_compress_begin_using_dict_state_layout[ (offsetof(ZSTD_rust_compressBeginUsingDictState, cctx) == 0 && offsetof(ZSTD_rust_compressBeginUsingDictState, cctxParams) == sizeof(void*) && offsetof(ZSTD_rust_compressBeginUsingDictState, exclusionMask) == 2 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginUsingDictState, initParams) == 3 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginUsingDictState, begin) == 4 * sizeof(void*) && sizeof(ZSTD_rust_compressBeginUsingDictState) == 5 * sizeof(void*)) ? 1 : -1]; typedef struct { const ZSTD_compressionParameters* cParams; const unsigned* dictID; } ZSTD_rust_cdictQueryState; ZSTD_compressionParameters ZSTD_rust_getCParamsFromCDict( const ZSTD_rust_cdictQueryState* state); unsigned ZSTD_rust_getDictIDFromCDict( const ZSTD_rust_cdictQueryState* state); typedef char ZSTD_rust_cdict_query_state_layout[ (offsetof(ZSTD_rust_cdictQueryState, cParams) == 0 && offsetof(ZSTD_rust_cdictQueryState, dictID) == sizeof(void*) && sizeof(ZSTD_rust_cdictQueryState) == 2 * sizeof(void*)) ? 1 : -1]; size_t ZSTD_rust_transferSequencesWBlockDelim( SeqStore_t* seqStore, ZSTD_SequencePosition* seqPos, const ZSTD_Sequence* inSeqs, size_t inSeqsSize, const BYTE* src, size_t blockSize, int externalRepSearch, const U32 prevRepcodes[ZSTD_REP_NUM], U32 nextRepcodes[ZSTD_REP_NUM], U32 dictSize, int validateSequences, U32 minMatch, U32 windowLog, int useSequenceProducer); size_t ZSTD_rust_optimalBlockSize(const void* src, size_t srcSize, size_t blockSizeMax, int splitLevel, int strategy, S64 savings, void* workspace, size_t workspaceSize); /* Sequence-store construction is Rust-owned at the orchestration boundary. * Matchfinder, LDM, and external sequence-producer operations retain access * to the private CCtx through these narrow C callbacks. */ typedef void (*ZSTD_rust_buildSeqStoreSkip_f)(void* context, size_t srcSize); typedef void (*ZSTD_rust_buildSeqStorePrepare_f)(void* context, const void* src, size_t srcSize); typedef size_t (*ZSTD_rust_buildSeqStoreCompress_f)( void* context, SeqStore_t* seqStore, U32 nextRep[ZSTD_REP_NUM], const void* src, size_t srcSize); typedef size_t (*ZSTD_rust_buildSeqStoreTryExternalProducer_f)( void* context, const void* src, size_t srcSize, int* seqStoreComplete, int* allowFallback); typedef void (*ZSTD_rust_buildSeqStoreClearLdm_f)(void* context); typedef struct { SeqStore_t* seqStore; ZSTD_compressedBlockState_t** prevCBlock; ZSTD_compressedBlockState_t** nextCBlock; void* callbackContext; U32 minMatch; int validateSeqStore; ZSTD_rust_buildSeqStoreSkip_f skipSmallBlock; ZSTD_rust_buildSeqStorePrepare_f prepareMatchState; int hasExternalSequences; int ldmEnabled; int hasExternalSequenceProducer; int enableMatchFinderFallback; ZSTD_rust_buildSeqStoreCompress_f compressExternalSequences; ZSTD_rust_buildSeqStoreCompress_f compressLdm; ZSTD_rust_buildSeqStoreTryExternalProducer_f tryExternalSequenceProducer; ZSTD_rust_buildSeqStoreCompress_f compressInternal; ZSTD_rust_buildSeqStoreClearLdm_f clearLdmSeqStore; } ZSTD_rust_buildSeqStoreState; size_t ZSTD_rust_buildSeqStore(const ZSTD_rust_buildSeqStoreState* state, const void* src, size_t srcSize); typedef char ZSTD_rust_build_seq_store_state_layout[ (offsetof(ZSTD_rust_buildSeqStoreState, seqStore) == 0 && offsetof(ZSTD_rust_buildSeqStoreState, prevCBlock) == sizeof(void*) && offsetof(ZSTD_rust_buildSeqStoreState, nextCBlock) == 2 * sizeof(void*) && offsetof(ZSTD_rust_buildSeqStoreState, callbackContext) == 3 * sizeof(void*) && offsetof(ZSTD_rust_buildSeqStoreState, minMatch) == 4 * sizeof(void*) && offsetof(ZSTD_rust_buildSeqStoreState, validateSeqStore) == 4 * sizeof(void*) + sizeof(U32) && offsetof(ZSTD_rust_buildSeqStoreState, skipSmallBlock) == 4 * sizeof(void*) + sizeof(U32) + sizeof(int) && offsetof(ZSTD_rust_buildSeqStoreState, prepareMatchState) == 5 * sizeof(void*) + sizeof(U32) + sizeof(int) && offsetof(ZSTD_rust_buildSeqStoreState, hasExternalSequences) == 6 * sizeof(void*) + sizeof(U32) + sizeof(int) && offsetof(ZSTD_rust_buildSeqStoreState, ldmEnabled) == 6 * sizeof(void*) + sizeof(U32) + 2 * sizeof(int) && offsetof(ZSTD_rust_buildSeqStoreState, hasExternalSequenceProducer) == 6 * sizeof(void*) + sizeof(U32) + 3 * sizeof(int) && offsetof(ZSTD_rust_buildSeqStoreState, enableMatchFinderFallback) == 6 * sizeof(void*) + sizeof(U32) + 4 * sizeof(int) && offsetof(ZSTD_rust_buildSeqStoreState, compressExternalSequences) == 6 * sizeof(void*) + sizeof(U32) + 5 * sizeof(int) && offsetof(ZSTD_rust_buildSeqStoreState, compressLdm) == 7 * sizeof(void*) + sizeof(U32) + 5 * sizeof(int) && offsetof(ZSTD_rust_buildSeqStoreState, tryExternalSequenceProducer) == 8 * sizeof(void*) + sizeof(U32) + 5 * sizeof(int) && offsetof(ZSTD_rust_buildSeqStoreState, compressInternal) == 9 * sizeof(void*) + sizeof(U32) + 5 * sizeof(int) && offsetof(ZSTD_rust_buildSeqStoreState, clearLdmSeqStore) == 10 * sizeof(void*) + sizeof(U32) + 5 * sizeof(int) && sizeof(ZSTD_rust_buildSeqStoreState) == 11 * sizeof(void*) + sizeof(U32) + 5 * sizeof(int)) ? 1 : -1]; typedef size_t (*ZSTD_rust_externalSequenceTransfer_f)( void* context, ZSTD_SequencePosition* seqPos, const ZSTD_Sequence* inSeqs, size_t inSeqsSize, const void* src, size_t blockSize); typedef struct { void* callbackContext; void* producerState; ZSTD_sequenceProducer_F producer; ZSTD_Sequence* extSeqBuf; const size_t* extSeqBufCapacity; const void* src; const size_t* srcSize; const int* compressionLevel; const size_t* windowSize; ZSTD_rust_externalSequenceTransfer_f transfer; size_t* externalSeqCount; int* seqStoreComplete; int* allowFallback; } ZSTD_rust_externalSequenceProducerState; size_t ZSTD_rust_tryExternalSequenceProducer( const ZSTD_rust_externalSequenceProducerState* state); typedef char ZSTD_rust_external_sequence_producer_state_layout[ (offsetof(ZSTD_rust_externalSequenceProducerState, callbackContext) == 0 && offsetof(ZSTD_rust_externalSequenceProducerState, producerState) == sizeof(void*) && offsetof(ZSTD_rust_externalSequenceProducerState, producer) == 2 * sizeof(void*) && offsetof(ZSTD_rust_externalSequenceProducerState, extSeqBuf) == 3 * sizeof(void*) && offsetof(ZSTD_rust_externalSequenceProducerState, extSeqBufCapacity) == 4 * sizeof(void*) && offsetof(ZSTD_rust_externalSequenceProducerState, src) == 5 * sizeof(void*) && offsetof(ZSTD_rust_externalSequenceProducerState, srcSize) == 6 * sizeof(void*) && offsetof(ZSTD_rust_externalSequenceProducerState, compressionLevel) == 7 * sizeof(void*) && offsetof(ZSTD_rust_externalSequenceProducerState, windowSize) == 8 * sizeof(void*) && offsetof(ZSTD_rust_externalSequenceProducerState, transfer) == 9 * sizeof(void*) && offsetof(ZSTD_rust_externalSequenceProducerState, externalSeqCount) == 10 * sizeof(void*) && offsetof(ZSTD_rust_externalSequenceProducerState, seqStoreComplete) == 11 * sizeof(void*) && offsetof(ZSTD_rust_externalSequenceProducerState, allowFallback) == 12 * sizeof(void*) && sizeof(ZSTD_rust_externalSequenceProducerState) == 13 * sizeof(void*)) ? 1 : -1]; typedef struct { rawSeq** seq; size_t* pos; size_t* posInSequence; size_t* size; size_t* capacity; } ZSTD_rust_externalSequenceStoreState; void ZSTD_rust_referenceExternalSequences( const ZSTD_rust_externalSequenceStoreState* state, rawSeq* seq, size_t nbSeq); typedef char ZSTD_rust_external_sequence_store_state_layout[ (offsetof(ZSTD_rust_externalSequenceStoreState, seq) == 0 && offsetof(ZSTD_rust_externalSequenceStoreState, pos) == sizeof(void*) && offsetof(ZSTD_rust_externalSequenceStoreState, posInSequence) == 2 * sizeof(void*) && offsetof(ZSTD_rust_externalSequenceStoreState, size) == 3 * sizeof(void*) && offsetof(ZSTD_rust_externalSequenceStoreState, capacity) == 4 * sizeof(void*) && sizeof(ZSTD_rust_externalSequenceStoreState) == 5 * sizeof(void*)) ? 1 : -1]; typedef void* (*ZSTD_rust_initCDictReserveContent_f)( void* context, size_t dictSize); typedef void* (*ZSTD_rust_initCDictReserveEntropy_f)( void* context, size_t workspaceSize); typedef size_t (*ZSTD_rust_initCDictResetMatchState_f)( void* context, const ZSTD_compressionParameters* cParams, int useRowMatchFinder, int compResetPolicy, int indexResetPolicy, int resetTarget); typedef size_t (*ZSTD_rust_initCDictInsertDictionary_f)( void* context, const void* params, const void* dict, size_t dictSize, int dictContentType, int dtlm, int tfp); typedef struct { void* callbackContext; void* params; const ZSTD_compressionParameters* cParams; ZSTD_compressionParameters* matchStateCParams; int* dedicatedDictSearch; const int* enableDedicatedDictSearch; const ZSTD_ParamSwitch_e* useRowMatchFinder; const void** dictContent; size_t* dictContentSize; int* dictContentType; U32** entropyWorkspace; U32* dictID; int* compressionLevel; int* contentSizeFlag; ZSTD_rust_initCDictReserveContent_f reserveContent; ZSTD_rust_initCDictReserveEntropy_f reserveEntropy; void* blockState; ZSTD_rust_initCDictResetMatchState_f resetMatchState; ZSTD_rust_initCDictInsertDictionary_f insertDictionary; } ZSTD_rust_initCDictState; size_t ZSTD_rust_initCDict( const ZSTD_rust_initCDictState* state, const void* dict, size_t dictSize, int dictLoadMethod, int dictContentType); typedef char ZSTD_rust_init_cdict_state_layout[ (offsetof(ZSTD_rust_initCDictState, callbackContext) == 0 && offsetof(ZSTD_rust_initCDictState, params) == sizeof(void*) && offsetof(ZSTD_rust_initCDictState, cParams) == 2 * sizeof(void*) && offsetof(ZSTD_rust_initCDictState, matchStateCParams) == 3 * sizeof(void*) && offsetof(ZSTD_rust_initCDictState, dedicatedDictSearch) == 4 * sizeof(void*) && offsetof(ZSTD_rust_initCDictState, enableDedicatedDictSearch) == 5 * sizeof(void*) && offsetof(ZSTD_rust_initCDictState, useRowMatchFinder) == 6 * sizeof(void*) && offsetof(ZSTD_rust_initCDictState, dictContent) == 7 * sizeof(void*) && offsetof(ZSTD_rust_initCDictState, dictContentSize) == 8 * sizeof(void*) && offsetof(ZSTD_rust_initCDictState, dictContentType) == 9 * sizeof(void*) && offsetof(ZSTD_rust_initCDictState, entropyWorkspace) == 10 * sizeof(void*) && offsetof(ZSTD_rust_initCDictState, dictID) == 11 * sizeof(void*) && offsetof(ZSTD_rust_initCDictState, compressionLevel) == 12 * sizeof(void*) && offsetof(ZSTD_rust_initCDictState, contentSizeFlag) == 13 * sizeof(void*) && offsetof(ZSTD_rust_initCDictState, reserveContent) == 14 * sizeof(void*) && offsetof(ZSTD_rust_initCDictState, reserveEntropy) == 15 * sizeof(void*) && offsetof(ZSTD_rust_initCDictState, blockState) == 16 * sizeof(void*) && offsetof(ZSTD_rust_initCDictState, resetMatchState) == 17 * sizeof(void*) && offsetof(ZSTD_rust_initCDictState, insertDictionary) == 18 * sizeof(void*) && sizeof(ZSTD_rust_initCDictState) == 19 * sizeof(void*)) ? 1 : -1]; typedef int (*ZSTD_rust_createCDictAdvancedValidateCustomMem_f)(void* context); typedef void* (*ZSTD_rust_createCDictAdvancedAllocate_f)( void* context, size_t workspaceSize); typedef void (*ZSTD_rust_createCDictAdvancedCreateWorkspace_f)( void* context, void* workspace, size_t workspaceSize); typedef void* (*ZSTD_rust_createCDictAdvancedReserveObject_f)( void* context); typedef void (*ZSTD_rust_createCDictAdvancedMoveWorkspace_f)( void* context, void* cdict); typedef void (*ZSTD_rust_createCDictAdvancedInitialize_f)( void* context, void* cdict, int useRowMatchFinder); typedef size_t (*ZSTD_rust_createCDictAdvancedInit_f)( void* context, void* cdict, const void* dict, size_t dictSize, int dictLoadMethod, int dictContentType, const ZSTD_CCtx_params* cctxParams); typedef void (*ZSTD_rust_createCDictAdvancedFreeWorkspace_f)( void* context, void* workspace); typedef void (*ZSTD_rust_createCDictAdvancedFree_f)( void* context, void* cdict); typedef void (*ZSTD_rust_createCDictAdvancedCopyParams_f)( void* context, void* destination, const void* source); typedef struct { void* callbackContext; ZSTD_CCtx_params* cctxParams; const ZSTD_compressionParameters* cParams; const int* enableDedicatedDictSearch; const int* useRowMatchFinder; U32 exclusionMask; U32 ldmDefaultWindowLog; ZSTD_rust_createCDictAdvancedValidateCustomMem_f validateCustomMem; const ZSTD_rustCDictSizing* sizing; ZSTD_rust_createCDictAdvancedAllocate_f allocate; ZSTD_rust_createCDictAdvancedCreateWorkspace_f createWorkspace; ZSTD_rust_createCDictAdvancedReserveObject_f reserveObject; ZSTD_rust_createCDictAdvancedMoveWorkspace_f moveWorkspace; ZSTD_rust_createCDictAdvancedInitialize_f initialize; ZSTD_rust_createCDictAdvancedInit_f init; ZSTD_rust_createCDictAdvancedFreeWorkspace_f freeWorkspace; ZSTD_rust_createCDictAdvancedFree_f free; const void* originalCctxParams; ZSTD_rust_createCDictAdvancedCopyParams_f copyParams; } ZSTD_rust_createCDictAdvancedState; void* ZSTD_rust_createCDictAdvanced( const ZSTD_rust_createCDictAdvancedState* state, const void* dict, size_t dictSize, int dictLoadMethod, int dictContentType); typedef char ZSTD_rust_create_cdict_advanced_state_layout[ (offsetof(ZSTD_rust_createCDictAdvancedState, callbackContext) == 0 && offsetof(ZSTD_rust_createCDictAdvancedState, cctxParams) == sizeof(void*) && offsetof(ZSTD_rust_createCDictAdvancedState, cParams) == 2 * sizeof(void*) && offsetof(ZSTD_rust_createCDictAdvancedState, enableDedicatedDictSearch) == 3 * sizeof(void*) && offsetof(ZSTD_rust_createCDictAdvancedState, useRowMatchFinder) == 4 * sizeof(void*) && offsetof(ZSTD_rust_createCDictAdvancedState, exclusionMask) == 5 * sizeof(void*) && offsetof(ZSTD_rust_createCDictAdvancedState, ldmDefaultWindowLog) == 5 * sizeof(void*) + sizeof(U32) && offsetof(ZSTD_rust_createCDictAdvancedState, validateCustomMem) == 5 * sizeof(void*) + 2 * sizeof(U32) && offsetof(ZSTD_rust_createCDictAdvancedState, sizing) == 6 * sizeof(void*) + 2 * sizeof(U32) && offsetof(ZSTD_rust_createCDictAdvancedState, allocate) == 7 * sizeof(void*) + 2 * sizeof(U32) && offsetof(ZSTD_rust_createCDictAdvancedState, createWorkspace) == 8 * sizeof(void*) + 2 * sizeof(U32) && offsetof(ZSTD_rust_createCDictAdvancedState, reserveObject) == 9 * sizeof(void*) + 2 * sizeof(U32) && offsetof(ZSTD_rust_createCDictAdvancedState, moveWorkspace) == 10 * sizeof(void*) + 2 * sizeof(U32) && offsetof(ZSTD_rust_createCDictAdvancedState, initialize) == 11 * sizeof(void*) + 2 * sizeof(U32) && offsetof(ZSTD_rust_createCDictAdvancedState, init) == 12 * sizeof(void*) + 2 * sizeof(U32) && offsetof(ZSTD_rust_createCDictAdvancedState, freeWorkspace) == 13 * sizeof(void*) + 2 * sizeof(U32) && offsetof(ZSTD_rust_createCDictAdvancedState, free) == 14 * sizeof(void*) + 2 * sizeof(U32) && offsetof(ZSTD_rust_createCDictAdvancedState, originalCctxParams) == 15 * sizeof(void*) + 2 * sizeof(U32) && offsetof(ZSTD_rust_createCDictAdvancedState, copyParams) == 16 * sizeof(void*) + 2 * sizeof(U32) && sizeof(ZSTD_rust_createCDictAdvancedState) == 17 * sizeof(void*) + 2 * sizeof(U32)) ? 1 : -1]; typedef void (*ZSTD_rust_createCDictAdvancedWrapperInitParams_f)( void* context, void* cctxParams, const ZSTD_compressionParameters* cParams, const void* customMem, size_t dictSize, int dictContentType); typedef void* (*ZSTD_rust_createCDictAdvancedWrapperCreate_f)( void* context, const void* dict, size_t dictSize, int dictLoadMethod, int dictContentType, const void* cctxParams, const void* customMem); typedef struct { void* callbackContext; void* cctxParams; const ZSTD_compressionParameters* cParams; const void* customMem; ZSTD_rust_createCDictAdvancedWrapperInitParams_f initParams; ZSTD_rust_createCDictAdvancedWrapperCreate_f create; } ZSTD_rust_createCDictAdvancedWrapperState; void* ZSTD_rust_createCDictAdvancedWrapper( const ZSTD_rust_createCDictAdvancedWrapperState* state, const void* dict, size_t dictSize, int dictLoadMethod, int dictContentType); typedef char ZSTD_rust_create_cdict_advanced_wrapper_state_layout[ (offsetof(ZSTD_rust_createCDictAdvancedWrapperState, callbackContext) == 0 && offsetof(ZSTD_rust_createCDictAdvancedWrapperState, cctxParams) == sizeof(void*) && offsetof(ZSTD_rust_createCDictAdvancedWrapperState, cParams) == 2 * sizeof(void*) && offsetof(ZSTD_rust_createCDictAdvancedWrapperState, customMem) == 3 * sizeof(void*) && offsetof(ZSTD_rust_createCDictAdvancedWrapperState, initParams) == 4 * sizeof(void*) && offsetof(ZSTD_rust_createCDictAdvancedWrapperState, create) == 5 * sizeof(void*) && sizeof(ZSTD_rust_createCDictAdvancedWrapperState) == 6 * sizeof(void*)) ? 1 : -1]; typedef size_t (*ZSTD_rust_compressBeginResetInternal_f)( void* context, const void* params, U64 pledgedSrcSize, size_t loadedDictSize, int zbuff); typedef size_t (*ZSTD_rust_compressBeginResetUsingCDict_f)( void* context, const void* cdict, const void* params, U64 pledgedSrcSize, int zbuff); typedef size_t (*ZSTD_rust_compressBeginInsertDictionary_f)( void* context, const void* dict, size_t dictSize, int dictContentType, int dtlm); typedef struct { void* callbackContext; const void* params; const void* cdict; const void* cdictDictContent; size_t cdictDictContentSize; int cdictDictContentType; const size_t* cdictContentSize; const int* cdictCompressionLevel; const ZSTD_dictAttachPref_e* attachDictPref; const void* dict; const size_t* dictSize; const int* dictContentType; const int* dtlm; const U64* pledgedSrcSize; const int* zbuff; const int* forceLoad; U32* dictID; size_t* dictContentSize; ZSTD_rust_compressBeginResetInternal_f resetInternal; ZSTD_rust_compressBeginResetUsingCDict_f resetUsingCDict; ZSTD_rust_compressBeginInsertDictionary_f insertDictionary; } ZSTD_rust_compressBeginState; size_t ZSTD_rust_compressBegin(const ZSTD_rust_compressBeginState* state); typedef char ZSTD_rust_compress_begin_state_layout[ (offsetof(ZSTD_rust_compressBeginState, callbackContext) == 0 && offsetof(ZSTD_rust_compressBeginState, params) == sizeof(void*) && offsetof(ZSTD_rust_compressBeginState, cdict) == 2 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginState, cdictDictContent) == 3 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginState, cdictDictContentSize) == 4 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginState, cdictDictContentType) == 4 * sizeof(void*) + sizeof(size_t) && offsetof(ZSTD_rust_compressBeginState, cdictContentSize) == 6 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginState, cdictCompressionLevel) == 7 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginState, attachDictPref) == 8 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginState, dict) == 9 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginState, dictSize) == 10 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginState, dictContentType) == 11 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginState, dtlm) == 12 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginState, pledgedSrcSize) == 13 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginState, zbuff) == 14 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginState, forceLoad) == 15 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginState, dictID) == 16 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginState, dictContentSize) == 17 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginState, resetInternal) == 18 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginState, resetUsingCDict) == 19 * sizeof(void*) && offsetof(ZSTD_rust_compressBeginState, insertDictionary) == 20 * sizeof(void*) && sizeof(ZSTD_rust_compressBeginState) == 21 * sizeof(void*)) ? 1 : -1]; typedef size_t (*ZSTD_rust_resetCCtxUsingCDictAttach_f)( void* context, const void* cdict, const void* params, U64 pledgedSrcSize, int zbuff); typedef size_t (*ZSTD_rust_resetCCtxUsingCDictCopy_f)( void* context, const void* cdict, const void* params, U64 pledgedSrcSize, int zbuff); typedef struct { void* callbackContext; const void* cdict; const void* params; const int* cdictStrategy; const int* dedicatedDictSearch; const int* attachDictPref; const int* forceWindow; const U64* pledgedSrcSize; const int* zbuff; ZSTD_rust_resetCCtxUsingCDictAttach_f attach; ZSTD_rust_resetCCtxUsingCDictCopy_f copy; } ZSTD_rust_resetCCtxUsingCDictState; size_t ZSTD_rust_resetCCtxUsingCDict( const ZSTD_rust_resetCCtxUsingCDictState* state); typedef char ZSTD_rust_reset_cctx_using_cdict_state_layout[ (offsetof(ZSTD_rust_resetCCtxUsingCDictState, callbackContext) == 0 && offsetof(ZSTD_rust_resetCCtxUsingCDictState, cdict) == sizeof(void*) && offsetof(ZSTD_rust_resetCCtxUsingCDictState, params) == 2 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxUsingCDictState, cdictStrategy) == 3 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxUsingCDictState, dedicatedDictSearch) == 4 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxUsingCDictState, attachDictPref) == 5 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxUsingCDictState, forceWindow) == 6 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxUsingCDictState, pledgedSrcSize) == 7 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxUsingCDictState, zbuff) == 8 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxUsingCDictState, attach) == 9 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxUsingCDictState, copy) == 10 * sizeof(void*) && sizeof(ZSTD_rust_resetCCtxUsingCDictState) == 11 * sizeof(void*)) ? 1 : -1]; typedef size_t (*ZSTD_rust_resetCCtxByCopyingCDictReset_f)( void* context, const void* cdict, const void* params, U64 pledgedSrcSize, int zbuff); typedef void (*ZSTD_rust_resetCCtxByCopyingCDictMarkTables_f)(void* context); typedef struct { void* callbackContext; const void* cdict; const void* params; U64 pledgedSrcSize; ZSTD_rust_resetCCtxByCopyingCDictReset_f reset; ZSTD_rust_resetCCtxByCopyingCDictMarkTables_f markTablesDirty; ZSTD_rust_resetCCtxByCopyingCDictMarkTables_f markTablesClean; U32** destinationHashTable; const U32* sourceHashTable; const U32* sourceHashLog; U32** destinationChainTable; const U32* sourceChainTable; const U32* sourceChainLog; const int* sourceStrategy; const int* sourceUseRowMatchFinder; const int* sourceIndicesTagged; const int* destinationStrategy; const int* destinationUseRowMatchFinder; BYTE** destinationTagTable; const BYTE* sourceTagTable; U64* destinationHashSalt; const U64* sourceHashSalt; U32** destinationHashTable3; const U32* destinationHashLog3; void* destinationWindow; const void* sourceWindow; U32* destinationNextToUpdate; const U32* sourceNextToUpdate; U32* destinationLoadedDictEnd; const U32* sourceLoadedDictEnd; U32* destinationDictID; const U32* sourceDictID; size_t* destinationDictContentSize; const size_t* sourceDictContentSize; ZSTD_compressedBlockState_t** destinationBlockState; const ZSTD_compressedBlockState_t* sourceBlockState; int zbuff; } ZSTD_rust_resetCCtxByCopyingCDictState; size_t ZSTD_rust_resetCCtxByCopyingCDict( const ZSTD_rust_resetCCtxByCopyingCDictState* state); typedef char ZSTD_rust_reset_cctx_by_copying_cdict_state_layout[ (offsetof(ZSTD_rust_resetCCtxByCopyingCDictState, callbackContext) == 0 && offsetof(ZSTD_rust_resetCCtxByCopyingCDictState, cdict) == sizeof(void*) && offsetof(ZSTD_rust_resetCCtxByCopyingCDictState, params) == 2 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxByCopyingCDictState, pledgedSrcSize) == 3 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxByCopyingCDictState, reset) == 3 * sizeof(void*) + sizeof(U64) && offsetof(ZSTD_rust_resetCCtxByCopyingCDictState, zbuff) == 3 * sizeof(void*) + sizeof(U64) + 32 * sizeof(void*) && sizeof(ZSTD_rust_resetCCtxByCopyingCDictState) == ((offsetof(ZSTD_rust_resetCCtxByCopyingCDictState, zbuff) + sizeof(int) + sizeof(void*) - 1) / sizeof(void*)) * sizeof(void*)) ? 1 : -1]; typedef size_t (*ZSTD_rust_resetCCtxByAttachingCDictReset_f)( void* context, const void* cdict, const void* params, U64 pledgedSrcSize, int zbuff); typedef struct { void* callbackContext; const void* cdict; const void* params; U64 pledgedSrcSize; ZSTD_rust_resetCCtxByAttachingCDictReset_f reset; const ZSTD_MatchState_t* sourceMatchState; const U32* sourceCDictEnd; const U32* sourceCDictLen; const ZSTD_MatchState_t** destinationDictMatchState; const BYTE** destinationWindowNextSrc; const BYTE* const* destinationWindowBase; U32* destinationWindowLowLimit; U32* destinationWindowDictLimit; U32* destinationLoadedDictEnd; U32* destinationDictID; const U32* sourceDictID; size_t* destinationDictContentSize; const size_t* sourceDictContentSize; ZSTD_compressedBlockState_t** destinationBlockState; const ZSTD_compressedBlockState_t* sourceBlockState; int zbuff; } ZSTD_rust_resetCCtxByAttachingCDictState; size_t ZSTD_rust_resetCCtxByAttachingCDict( const ZSTD_rust_resetCCtxByAttachingCDictState* state); typedef char ZSTD_rust_reset_cctx_by_attaching_cdict_state_layout[ (offsetof(ZSTD_rust_resetCCtxByAttachingCDictState, callbackContext) == 0 && offsetof(ZSTD_rust_resetCCtxByAttachingCDictState, cdict) == sizeof(void*) && offsetof(ZSTD_rust_resetCCtxByAttachingCDictState, params) == 2 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxByAttachingCDictState, pledgedSrcSize) == 3 * sizeof(void*) && offsetof(ZSTD_rust_resetCCtxByAttachingCDictState, reset) == 3 * sizeof(void*) + sizeof(U64) && offsetof(ZSTD_rust_resetCCtxByAttachingCDictState, zbuff) == 3 * sizeof(void*) + sizeof(U64) + 16 * sizeof(void*) && sizeof(ZSTD_rust_resetCCtxByAttachingCDictState) == ((offsetof(ZSTD_rust_resetCCtxByAttachingCDictState, zbuff) + sizeof(int) + sizeof(void*) - 1) / sizeof(void*)) * sizeof(void*)) ? 1 : -1]; /* The sequence-compression loop receives only the state it actually reads or * updates. In particular, neither ZSTD_CCtx nor a C function pointer crosses * the Rust ABI. */ typedef struct { SeqStore_t* seqStore; ZSTD_compressedBlockState_t** prevCBlock; ZSTD_compressedBlockState_t** nextCBlock; void* tmpWorkspace; size_t tmpWkspSize; size_t blockSizeMax; int bmi2; int blockDelimiters; int strategy; int disableLiteralCompression; int searchForExternalRepcodes; int validateSequences; U32 minMatch; U32 windowLog; U32 dictSize; int useSequenceProducer; int* isFirstBlock; } ZSTD_rust_sequenceCompressionState; size_t ZSTD_rust_compressSequencesInternal( const ZSTD_rust_sequenceCompressionState* state, void* dst, size_t dstCapacity, const ZSTD_Sequence* inSeqs, size_t inSeqsSize, const void* src, size_t srcSize); typedef char ZSTD_rust_sequence_state_layout[ (offsetof(ZSTD_rust_sequenceCompressionState, seqStore) == 0 && offsetof(ZSTD_rust_sequenceCompressionState, prevCBlock) == sizeof(void*) && offsetof(ZSTD_rust_sequenceCompressionState, nextCBlock) == 2 * sizeof(void*) && offsetof(ZSTD_rust_sequenceCompressionState, tmpWorkspace) == 3 * sizeof(void*) && offsetof(ZSTD_rust_sequenceCompressionState, tmpWkspSize) == 4 * sizeof(void*) && offsetof(ZSTD_rust_sequenceCompressionState, blockSizeMax) == 5 * sizeof(void*) && offsetof(ZSTD_rust_sequenceCompressionState, bmi2) == 6 * sizeof(void*) && offsetof(ZSTD_rust_sequenceCompressionState, minMatch) == 6 * sizeof(void*) + 6 * sizeof(int) && offsetof(ZSTD_rust_sequenceCompressionState, useSequenceProducer) == 6 * sizeof(void*) + 3 * sizeof(U32) + 6 * sizeof(int) && offsetof(ZSTD_rust_sequenceCompressionState, isFirstBlock) == 6 * sizeof(void*) + 3 * sizeof(U32) + 7 * sizeof(int) && sizeof(ZSTD_rust_sequenceCompressionState) == offsetof(ZSTD_rust_sequenceCompressionState, isFirstBlock) + sizeof(void*)) ? 1 : -1]; /* The external-sequence/literals block loop keeps sequence conversion as a * C-private callback because it still reads the opaque CCtx. Everything * else it mutates is passed through this explicit projection. */ typedef size_t (*ZSTD_rust_sequenceLiteralsConvert_f)( void* context, const ZSTD_Sequence* inSeqs, size_t nbSequences, int repcodeResolution); typedef struct { SeqStore_t* seqStore; ZSTD_compressedBlockState_t** prevCBlock; ZSTD_compressedBlockState_t** nextCBlock; void* tmpWorkspace; size_t tmpWkspSize; size_t blockSizeMax; int bmi2; int strategy; int disableLiteralCompression; int repcodeResolution; int* isFirstBlock; void* callbackContext; ZSTD_rust_sequenceLiteralsConvert_f convertBlockSequences; } ZSTD_rust_sequenceLiteralsState; size_t ZSTD_rust_compressSequencesAndLiteralsInternal( const ZSTD_rust_sequenceLiteralsState* state, void* dst, size_t dstCapacity, const ZSTD_Sequence* inSeqs, size_t nbSequences, const void* literals, size_t litSize, size_t srcSize); /* Public sequence conversion uses only the sequence store and the two * compressed-block state slots. Keep the C entry point for existing callers, * but move its conversion logic behind this explicit Rust projection. */ typedef struct { SeqStore_t* seqStore; ZSTD_compressedBlockState_t** prevCBlock; ZSTD_compressedBlockState_t** nextCBlock; } ZSTD_rust_convertBlockSequencesState; size_t ZSTD_rust_convertBlockSequences( const ZSTD_rust_convertBlockSequencesState* state, const ZSTD_Sequence* inSeqs, size_t nbSequences, int repcodeResolution); typedef char ZSTD_rust_convert_block_sequences_state_layout[ (offsetof(ZSTD_rust_convertBlockSequencesState, seqStore) == 0 && offsetof(ZSTD_rust_convertBlockSequencesState, prevCBlock) == sizeof(void*) && offsetof(ZSTD_rust_convertBlockSequencesState, nextCBlock) == 2 * sizeof(void*) && sizeof(ZSTD_rust_convertBlockSequencesState) == 3 * sizeof(void*)) ? 1 : -1]; typedef char ZSTD_rust_sequence_literals_state_layout[ (offsetof(ZSTD_rust_sequenceLiteralsState, seqStore) == 0 && offsetof(ZSTD_rust_sequenceLiteralsState, prevCBlock) == sizeof(void*) && offsetof(ZSTD_rust_sequenceLiteralsState, nextCBlock) == 2 * sizeof(void*) && offsetof(ZSTD_rust_sequenceLiteralsState, tmpWorkspace) == 3 * sizeof(void*) && offsetof(ZSTD_rust_sequenceLiteralsState, tmpWkspSize) == 4 * sizeof(void*) && offsetof(ZSTD_rust_sequenceLiteralsState, blockSizeMax) == 5 * sizeof(void*) && offsetof(ZSTD_rust_sequenceLiteralsState, bmi2) == 6 * sizeof(void*) && offsetof(ZSTD_rust_sequenceLiteralsState, strategy) == 6 * sizeof(void*) + sizeof(int) && offsetof(ZSTD_rust_sequenceLiteralsState, disableLiteralCompression) == 6 * sizeof(void*) + 2 * sizeof(int) && offsetof(ZSTD_rust_sequenceLiteralsState, repcodeResolution) == 6 * sizeof(void*) + 3 * sizeof(int) && offsetof(ZSTD_rust_sequenceLiteralsState, isFirstBlock) == 6 * sizeof(void*) + 4 * sizeof(int) && offsetof(ZSTD_rust_sequenceLiteralsState, callbackContext) == 6 * sizeof(void*) + 4 * sizeof(int) + sizeof(void*) && offsetof(ZSTD_rust_sequenceLiteralsState, convertBlockSequences) == 6 * sizeof(void*) + 4 * sizeof(int) + 2 * sizeof(void*) && sizeof(ZSTD_rust_sequenceLiteralsState) == 6 * sizeof(void*) + 4 * sizeof(int) + 3 * sizeof(void*)) ? 1 : -1]; /* The public sequence APIs keep their CCtx initialization in C, while Rust * owns frame-header/checksum serialization, ordering, and output accounting. * The checksum state and two block-loop projections are populated by the * initialization callback after the private CCtx has been initialized. */ typedef struct ZSTD_rust_sequenceApiState_s ZSTD_rust_sequenceApiState; typedef size_t (*ZSTD_rust_sequenceApiInit_f)( void* context, size_t pledgedSrcSize, ZSTD_rust_sequenceApiState* state); struct ZSTD_rust_sequenceApiState_s { void* callbackContext; ZSTD_rust_sequenceCompressionState* sequenceState; ZSTD_rust_sequenceLiteralsState* sequenceLiteralsState; ZSTD_rust_sequenceApiInit_f init; XXH64_state_t* checksumState; int checksumFlag; int blockDelimiters; int validateSequences; int noDictIDFlag; int contentSizeFlag; int format; U32 windowLog; U32 dictID; }; size_t ZSTD_rust_compressSequences( ZSTD_rust_sequenceApiState* state, void* dst, size_t dstCapacity, const ZSTD_Sequence* inSeqs, size_t inSeqsSize, const void* src, size_t srcSize); size_t ZSTD_rust_compressSequencesAndLiterals( ZSTD_rust_sequenceApiState* state, void* dst, size_t dstCapacity, const ZSTD_Sequence* inSeqs, size_t inSeqsSize, const void* literals, size_t litSize, size_t litCapacity, size_t decompressedSize); typedef char ZSTD_rust_sequence_api_state_layout[ (offsetof(ZSTD_rust_sequenceApiState, callbackContext) == 0 && offsetof(ZSTD_rust_sequenceApiState, sequenceState) == sizeof(void*) && offsetof(ZSTD_rust_sequenceApiState, sequenceLiteralsState) == 2 * sizeof(void*) && offsetof(ZSTD_rust_sequenceApiState, init) == 3 * sizeof(void*) && offsetof(ZSTD_rust_sequenceApiState, checksumState) == 4 * sizeof(void*) && offsetof(ZSTD_rust_sequenceApiState, checksumFlag) == 5 * sizeof(void*) && offsetof(ZSTD_rust_sequenceApiState, blockDelimiters) == 5 * sizeof(void*) + sizeof(int) && offsetof(ZSTD_rust_sequenceApiState, validateSequences) == 5 * sizeof(void*) + 2 * sizeof(int) && offsetof(ZSTD_rust_sequenceApiState, noDictIDFlag) == 5 * sizeof(void*) + 3 * sizeof(int) && offsetof(ZSTD_rust_sequenceApiState, contentSizeFlag) == 5 * sizeof(void*) + 4 * sizeof(int) && offsetof(ZSTD_rust_sequenceApiState, format) == 5 * sizeof(void*) + 5 * sizeof(int) && offsetof(ZSTD_rust_sequenceApiState, windowLog) == 5 * sizeof(void*) + 6 * sizeof(int) && offsetof(ZSTD_rust_sequenceApiState, dictID) == 5 * sizeof(void*) + 6 * sizeof(int) + sizeof(U32) && sizeof(ZSTD_rust_sequenceApiState) == (sizeof(void*) == 8 ? 72 : 52)) ? 1 : -1]; typedef char ZSTD_rust_stats_seqdef_layout[(sizeof(SeqDef) == 8) ? 1 : -1]; typedef char ZSTD_rust_stats_block_summary_layout[ (sizeof(BlockSummary) == 3 * sizeof(size_t)) ? 1 : -1]; typedef char ZSTD_rust_stats_seqstore_long_length_pos[ (offsetof(SeqStore_t, longLengthPos) == 9 * sizeof(size_t) + 4) ? 1 : -1]; typedef char ZSTD_rust_stats_seqstore_layout[ (sizeof(SeqStore_t) == 9 * sizeof(size_t) + 8) ? 1 : -1]; typedef char ZSTD_rust_stats_huf_layout[ (sizeof(ZSTD_hufCTables_t) == 258 * sizeof(size_t)) ? 1 : -1]; typedef char ZSTD_rust_stats_fse_layout[(sizeof(ZSTD_fseCTables_t) == 3552) ? 1 : -1]; typedef char ZSTD_rust_stats_entropy_fse_offset[ (offsetof(ZSTD_entropyCTables_t, fse) == sizeof(ZSTD_hufCTables_t)) ? 1 : -1]; typedef char ZSTD_rust_stats_huf_metadata_buffer[ (offsetof(ZSTD_hufCTablesMetadata_t, hufDesBuffer) == 4 && ZSTD_MAX_HUF_HEADER_SIZE == 128) ? 1 : -1]; typedef char ZSTD_rust_stats_fse_metadata_buffer[ (offsetof(ZSTD_fseCTablesMetadata_t, fseTablesBuffer) == 12 && ZSTD_MAX_FSE_HEADERS_SIZE == 133) ? 1 : -1]; typedef char ZSTD_rust_stats_entropy_metadata_layout[ (offsetof(ZSTD_entropyCTablesMetadata_t, fseMetadata) == sizeof(ZSTD_hufCTablesMetadata_t)) ? 1 : -1]; typedef char ZSTD_rust_stats_sequence_layout[(sizeof(ZSTD_Sequence) == 16) ? 1 : -1]; typedef char ZSTD_rust_stats_sequence_position_layout[ (sizeof(ZSTD_SequencePosition) == 2 * sizeof(U32) + sizeof(size_t) && offsetof(ZSTD_SequencePosition, posInSrc) == 2 * sizeof(U32)) ? 1 : -1]; typedef char ZSTD_rust_stats_seqcollector_layout[ (offsetof(SeqCollector, seqStart) == sizeof(size_t) && offsetof(SeqCollector, seqIndex) == 2 * sizeof(size_t) && sizeof(SeqCollector) == 4 * sizeof(size_t)) ? 1 : -1]; #if ZSTD_ADDRESS_SANITIZER && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE) # define ZSTD_RUST_ASAN_REDZONE_SIZE ((size_t)ZSTD_CWKSP_ASAN_REDZONE_SIZE) #else # define ZSTD_RUST_ASAN_REDZONE_SIZE ((size_t)0) #endif /* *************************************************************** * Tuning parameters *****************************************************************/ /*! * COMPRESS_HEAPMODE : * Select how default decompression function ZSTD_compress() allocates its context, * on stack (0, default), or into heap (1). * Note that functions with explicit context such as ZSTD_compressCCtx() are unaffected. */ #ifndef ZSTD_COMPRESS_HEAPMODE # define ZSTD_COMPRESS_HEAPMODE 0 #endif /*! * ZSTD_HASHLOG3_MAX : * Maximum size of the hash table dedicated to find 3-bytes matches, * in log format, aka 17 => 1 << 17 == 128Ki positions. * This structure is only used in zstd_opt. * Since allocation is centralized for all strategies, it has to be known here. * The actual (selected) size of the hash table is then stored in ZSTD_MatchState_t.hashLog3, * so that zstd_opt.c doesn't need to know about this constant. */ #ifndef ZSTD_HASHLOG3_MAX # define ZSTD_HASHLOG3_MAX 17 #endif /*-************************************* * Helper functions ***************************************/ /* ZSTD_compressBound() lives in rust/src/zstd_compress_api.rs. Keep this * translation unit for the context implementation, which still calls the * exported ABI symbol. */ /*-************************************* * Context memory management ***************************************/ struct ZSTD_CDict_s { const void* dictContent; size_t dictContentSize; ZSTD_dictContentType_e dictContentType; /* The dictContentType the CDict was created with */ U32* entropyWorkspace; /* entropy workspace of HUF_WORKSPACE_SIZE bytes */ ZSTD_cwksp workspace; ZSTD_MatchState_t matchState; ZSTD_compressedBlockState_t cBlockState; ZSTD_customMem customMem; U32 dictID; int compressionLevel; /* 0 indicates that advanced API was used to select CDict params */ ZSTD_ParamSwitch_e useRowMatchFinder; /* Indicates whether the CDict was created with params that would use * row-based matchfinder. Unless the cdict is reloaded, we will use * the same greedy/lazy matchfinder at compression time. */ }; /* typedef'd to ZSTD_CDict within "zstd.h" */ ZSTD_CCtx* ZSTD_createCCtx(void) { return ZSTD_createCCtx_advanced(ZSTD_defaultCMem); } static void ZSTD_initCCtx_zero(void* context) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; assert(cctx != NULL); ZSTD_memset(cctx, 0, sizeof(*cctx)); } static void ZSTD_initCCtx_setCustomMem(void* context, const void* customMem) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; cctx->customMem = *(const ZSTD_customMem*)customMem; } static void ZSTD_initCCtx_setBmi2(void* context) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; cctx->bmi2 = ZSTD_cpuSupportsBmi2(); } static size_t ZSTD_initCCtx_reset(void* context) { return ZSTD_CCtx_reset((ZSTD_CCtx*)context, ZSTD_reset_parameters); } static int ZSTD_rust_createCCtx_validateCustomMem(void* context) { ZSTD_customMem const* const customMem = (const ZSTD_customMem*)context; return ((!customMem->customAlloc) ^ (!customMem->customFree)) == 0; } static void* ZSTD_rust_createCCtx_allocate(void* context, size_t size) { return ZSTD_customMalloc(size, *(const ZSTD_customMem*)context); } static void ZSTD_rust_createCCtx_init(void* context, void* cctx) { ZSTD_rust_initCCtxState state; state.callbackContext = cctx; state.customMem = context; state.zero = ZSTD_initCCtx_zero; state.setCustomMem = ZSTD_initCCtx_setCustomMem; state.setBmi2 = ZSTD_initCCtx_setBmi2; state.reset = ZSTD_initCCtx_reset; { size_t const err = ZSTD_rust_initCCtx(&state); assert(!ZSTD_isError(err)); (void)err; } } ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem) { ZSTD_rust_createCCtxState state; ZSTD_STATIC_ASSERT(zcss_init==0); ZSTD_STATIC_ASSERT(ZSTD_CONTENTSIZE_UNKNOWN==(0ULL - 1)); state.callbackContext = &customMem; state.cctxSize = sizeof(ZSTD_CCtx); state.validateCustomMem = ZSTD_rust_createCCtx_validateCustomMem; state.allocate = ZSTD_rust_createCCtx_allocate; state.init = ZSTD_rust_createCCtx_init; return (ZSTD_CCtx*)ZSTD_rust_createCCtx(&state); } typedef struct { void* workspace; size_t workspaceSize; ZSTD_cwksp workspaceState; ZSTD_CCtx* cctx; } ZSTD_rust_initStaticCCtxContext; static void ZSTD_rust_initStaticCCtx_createWorkspace(void* opaque) { ZSTD_rust_initStaticCCtxContext* const context = (ZSTD_rust_initStaticCCtxContext*)opaque; ZSTD_cwksp_init(&context->workspaceState, context->workspace, context->workspaceSize, ZSTD_cwksp_static_alloc); } static void* ZSTD_rust_initStaticCCtx_reserveObject(void* opaque) { ZSTD_rust_initStaticCCtxContext* const context = (ZSTD_rust_initStaticCCtxContext*)opaque; context->cctx = (ZSTD_CCtx*)ZSTD_cwksp_reserve_object( &context->workspaceState, sizeof(ZSTD_CCtx)); return context->cctx; } static void ZSTD_rust_initStaticCCtx_zero(void* opaque, void* cctx) { (void)opaque; ZSTD_memset(cctx, 0, sizeof(ZSTD_CCtx)); } static void ZSTD_rust_initStaticCCtx_moveWorkspace(void* opaque, void* cctx) { ZSTD_rust_initStaticCCtxContext* const context = (ZSTD_rust_initStaticCCtxContext*)opaque; ZSTD_CCtx* const contextCCtx = (ZSTD_CCtx*)cctx; ZSTD_cwksp_move(&contextCCtx->workspace, &context->workspaceState); contextCCtx->staticSize = context->workspaceSize; } static int ZSTD_rust_initStaticCCtx_checkAvailable(void* opaque) { ZSTD_rust_initStaticCCtxContext const* const context = (const ZSTD_rust_initStaticCCtxContext*)opaque; return ZSTD_cwksp_check_available( &context->cctx->workspace, TMP_WORKSPACE_SIZE + 2 * sizeof(ZSTD_compressedBlockState_t)); } enum { ZSTD_RUST_INIT_STATIC_CCTX_PREV_CBLOCK = 0, ZSTD_RUST_INIT_STATIC_CCTX_NEXT_CBLOCK = 1 }; static void* ZSTD_rust_initStaticCCtx_reserveBlockState( void* opaque, int blockState) { ZSTD_rust_initStaticCCtxContext* const context = (ZSTD_rust_initStaticCCtxContext*)opaque; void* const block = ZSTD_cwksp_reserve_object( &context->cctx->workspace, sizeof(ZSTD_compressedBlockState_t)); if (blockState == ZSTD_RUST_INIT_STATIC_CCTX_PREV_CBLOCK) { context->cctx->blockState.prevCBlock = (ZSTD_compressedBlockState_t*)block; } else if (blockState == ZSTD_RUST_INIT_STATIC_CCTX_NEXT_CBLOCK) { context->cctx->blockState.nextCBlock = (ZSTD_compressedBlockState_t*)block; } else { assert(0); return NULL; } return block; } static void* ZSTD_rust_initStaticCCtx_reserveTmpWorkspace(void* opaque) { ZSTD_rust_initStaticCCtxContext* const context = (ZSTD_rust_initStaticCCtxContext*)opaque; context->cctx->tmpWorkspace = ZSTD_cwksp_reserve_object( &context->cctx->workspace, TMP_WORKSPACE_SIZE); context->cctx->tmpWkspSize = TMP_WORKSPACE_SIZE; return context->cctx->tmpWorkspace; } static void ZSTD_rust_initStaticCCtx_setBmi2(void* opaque) { ZSTD_rust_initStaticCCtxContext const* const context = (const ZSTD_rust_initStaticCCtxContext*)opaque; context->cctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid()); } ZSTD_CCtx* ZSTD_initStaticCCtx(void* workspace, size_t workspaceSize) { ZSTD_rust_initStaticCCtxContext context; ZSTD_rust_initStaticCCtxState state; context.workspace = workspace; context.workspaceSize = workspaceSize; state.callbackContext = &context; state.workspace = workspace; state.workspaceSize = workspaceSize; state.cctxSize = sizeof(ZSTD_CCtx); state.createWorkspace = ZSTD_rust_initStaticCCtx_createWorkspace; state.reserveObject = ZSTD_rust_initStaticCCtx_reserveObject; state.zero = ZSTD_rust_initStaticCCtx_zero; state.moveWorkspace = ZSTD_rust_initStaticCCtx_moveWorkspace; state.checkAvailable = ZSTD_rust_initStaticCCtx_checkAvailable; state.reserveBlockState = ZSTD_rust_initStaticCCtx_reserveBlockState; state.reserveTmpWorkspace = ZSTD_rust_initStaticCCtx_reserveTmpWorkspace; state.setBmi2 = ZSTD_rust_initStaticCCtx_setBmi2; return (ZSTD_CCtx*)ZSTD_rust_initStaticCCtx(&state); } /* Keep the private workspace and CCtx layout operations above in C. Rust * owns only the public checks, construction order, and failure policy. */ /** * Clears and frees all of the dictionaries in the CCtx. */ static void ZSTD_clearAllDicts_freeLocalDictBuffer(void* context) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; ZSTD_customFree(cctx->localDict.dictBuffer, cctx->customMem); } static void ZSTD_clearAllDicts_freeLocalCDict(void* context) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; ZSTD_freeCDict(cctx->localDict.cdict); } static void ZSTD_clearAllDicts_clearLocalDict(void* context) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; ZSTD_memset(&cctx->localDict, 0, sizeof(cctx->localDict)); } static void ZSTD_clearAllDicts_clearPrefixDict(void* context) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; ZSTD_memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict)); } static void ZSTD_clearAllDicts_clearCDict(void* context) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; cctx->cdict = NULL; } static void ZSTD_clearAllDicts(ZSTD_CCtx* cctx) { ZSTD_rust_clearAllDictsState state; state.callbackContext = cctx; state.freeLocalDictBuffer = ZSTD_clearAllDicts_freeLocalDictBuffer; state.freeLocalCDict = ZSTD_clearAllDicts_freeLocalCDict; state.clearLocalDict = ZSTD_clearAllDicts_clearLocalDict; state.clearPrefixDict = ZSTD_clearAllDicts_clearPrefixDict; state.clearCDict = ZSTD_clearAllDicts_clearCDict; ZSTD_rust_clearAllDicts(&state); } static void ZSTD_clearAllDicts_callback(void* context) { ZSTD_clearAllDicts((ZSTD_CCtx*)context); } static void* ZSTD_rust_assignLocalDict_allocate(void* context, size_t size) { ZSTD_CCtx const* const cctx = (const ZSTD_CCtx*)context; return ZSTD_customMalloc(size, cctx->customMem); } static size_t ZSTD_assignLocalDict_callback( void* context, const void* dict, size_t dictSize, int dictLoadMethod, int dictContentType) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; ZSTD_localDict* const localDict = &cctx->localDict; ZSTD_rust_assignLocalDictState state; state.callbackContext = cctx; state.staticSize = cctx->staticSize; state.dict = &localDict->dict; state.dictBuffer = &localDict->dictBuffer; state.dictSize = &localDict->dictSize; state.dictContentType = (int*)&localDict->dictContentType; state.allocate = ZSTD_rust_assignLocalDict_allocate; return ZSTD_rust_assignLocalDict( &state, dict, dictSize, dictLoadMethod, dictContentType); } static void ZSTD_assignCDict_callback(void* context, const void* cdict) { ((ZSTD_CCtx*)context)->cdict = (const ZSTD_CDict*)cdict; } static void ZSTD_assignPrefixDict_callback( void* context, const void* prefix, size_t prefixSize, int dictContentType) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; if (prefix != NULL && prefixSize > 0) { cctx->prefixDict.dict = prefix; cctx->prefixDict.dictSize = prefixSize; cctx->prefixDict.dictContentType = (ZSTD_dictContentType_e)dictContentType; } } static size_t ZSTD_sizeof_localDict(ZSTD_localDict dict) { size_t const cdictSize = ZSTD_sizeof_CDict(dict.cdict); return ZSTD_rust_sizeofLocalDict(dict.dictBuffer != NULL, dict.dictSize, cdictSize); } static void ZSTD_rust_freeCCtx_freeMTContext(void* context) { #ifdef ZSTD_MULTITHREAD ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; ZSTDMT_freeCCtx(cctx->mtctx); cctx->mtctx = NULL; #else (void)context; #endif } static void ZSTD_rust_freeCCtx_freeWorkspace(void* context) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; ZSTD_cwksp_free(&cctx->workspace, cctx->customMem); } static void ZSTD_rust_freeCCtx_freeObject(void* context) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; ZSTD_customFree(cctx, cctx->customMem); } size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx) { ZSTD_rust_freeCCtxState state; DEBUGLOG(3, "ZSTD_freeCCtx (address: %p)", (void*)cctx); state.callbackContext = cctx; state.staticSize = cctx == NULL ? 0 : cctx->staticSize; state.cctxInWorkspace = cctx != NULL && cctx->staticSize == 0 ? ZSTD_cwksp_owns_buffer(&cctx->workspace, cctx) : 0; /* Rust owns the release order; these callbacks retain only private C * dictionary, MT-context, workspace, and object operations. */ state.freeDictionaries = ZSTD_clearAllDicts_callback; state.freeMTContext = ZSTD_rust_freeCCtx_freeMTContext; state.freeWorkspace = ZSTD_rust_freeCCtx_freeWorkspace; state.freeObject = ZSTD_rust_freeCCtx_freeObject; return ZSTD_rust_freeCCtx(&state); } static size_t ZSTD_sizeof_mtctx(const ZSTD_CCtx* cctx) { #ifdef ZSTD_MULTITHREAD return ZSTDMT_sizeof_CCtx(cctx->mtctx); #else (void)cctx; return 0; #endif } size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx) { if (cctx==NULL) return 0; /* support sizeof on NULL */ { /* cctx may be in the workspace */ size_t const objectSize = cctx->workspace.workspace == cctx ? 0 : sizeof(*cctx); size_t const workspaceSize = ZSTD_cwksp_sizeof(&cctx->workspace); size_t const localDictSize = ZSTD_sizeof_localDict(cctx->localDict); size_t const mtctxSize = ZSTD_sizeof_mtctx(cctx); return ZSTD_rust_sizeofCCtx(objectSize, workspaceSize, localDictSize, mtctxSize); } } size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs) { return ZSTD_sizeof_CCtx(zcs); /* same object */ } /* private API call, for dictBuilder only */ const SeqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx) { return &(ctx->seqStore); } /* These pure policy leaves are implemented in Rust under their caller symbols. * C retains the surrounding private-state and configuration-sensitive logic. */ static ZSTD_CCtx_params ZSTD_makeCCtxParamsFromCParams( ZSTD_compressionParameters cParams) { ZSTD_CCtx_params cctxParams; /* Rust owns reset, copy, and default policy. Keep the C LDM adapter and * assertions here because they depend on the private C parameter type. */ ZSTD_rust_makeCCtxParamsFromCParams(&cctxParams, &cParams); if (cctxParams.ldmParams.enableLdm == ZSTD_ps_enable) { ZSTD_ldm_adjustParameters(&cctxParams.ldmParams, &cParams); assert(cctxParams.ldmParams.hashLog >= cctxParams.ldmParams.bucketSizeLog); assert(cctxParams.ldmParams.hashRateLog < 32); } assert(!ZSTD_checkCParams(cParams)); return cctxParams; } ZSTD_CCtx_params* ZSTD_createCCtxParams(void) { return ZSTD_rust_createCCtxParams(ZSTD_defaultCMem); } #define ZSTD_NO_CLEVEL 0 /** * Initializes `cctxParams` from `params` and `compressionLevel`. * @param compressionLevel If params are derived from a compression level then that compression level, otherwise ZSTD_NO_CLEVEL. */ static void ZSTD_CCtxParams_init_internal(ZSTD_CCtx_params* cctxParams, const ZSTD_parameters* params, int compressionLevel) { assert(!ZSTD_checkCParams(params->cParams)); ZSTD_rust_CCtxParams_init_internal(cctxParams, params, compressionLevel); DEBUGLOG(4, "ZSTD_CCtxParams_init_internal: useRowMatchFinder=%d, useBlockSplitter=%d ldm=%d", cctxParams->useRowMatchFinder, cctxParams->postBlockSplitter, cctxParams->ldmParams.enableLdm); } /** * Sets cctxParams' cParams and fParams from params, but otherwise leaves them alone. * @param params Validated zstd parameters. */ static void ZSTD_CCtxParams_setZstdParams( ZSTD_CCtx_params* cctxParams, const ZSTD_parameters* params) { assert(!ZSTD_checkCParams(params->cParams)); ZSTD_rust_CCtxParams_setZstdParams(cctxParams, params); } int ZSTD_rust_cctx_params_is_multithreaded(void) { #ifdef ZSTD_MULTITHREAD return 1; #else return 0; #endif } int ZSTD_rust_cctx_params_nb_workers_max(void) { #ifdef ZSTD_MULTITHREAD return ZSTDMT_NBWORKERS_MAX; #else return 0; #endif } int ZSTD_rust_cctx_params_job_size_min(void) { #ifdef ZSTD_MULTITHREAD return ZSTDMT_JOBSIZE_MIN; #else return 0; #endif } int ZSTD_rust_cctx_params_job_size_max(void) { #ifdef ZSTD_MULTITHREAD return ZSTDMT_JOBSIZE_MAX; #else return 0; #endif } #define BOUNDCHECK(cParam, val) \ do { \ RETURN_ERROR_IF(!ZSTD_cParam_withinBounds(cParam,val), \ parameter_outOfBound, "Param out of bounds"); \ } while (0) size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value) { ZSTD_rust_setParameterState state; DEBUGLOG(4, "ZSTD_CCtx_setParameter (%i, %i)", (int)param, value); state.requestedParams = &cctx->requestedParams; state.streamStage = (int)cctx->streamStage; state.cParamsChanged = &cctx->cParamsChanged; state.staticSize = cctx->staticSize; state.rustSimpleCompress2MaxBlockSizeSet = &cctx->rustSimpleCompress2MaxBlockSizeSet; return ZSTD_rust_setParameter(&state, (int)param, value); } size_t ZSTD_CCtx_getParameter(ZSTD_CCtx const* cctx, ZSTD_cParameter param, int* value) { return ZSTD_CCtxParams_getParameter(&cctx->requestedParams, param, value); } /** ZSTD_CCtx_setParametersUsingCCtxParams() : * just applies `params` into `cctx` * no action is performed, parameters are merely stored. * If ZSTDMT is enabled, parameters are pushed to cctx->mtctx. * This is possible even if a compression is ongoing. * In which case, new parameters will be applied on the fly, starting with next compression job. */ size_t ZSTD_CCtx_setParametersUsingCCtxParams( ZSTD_CCtx* cctx, const ZSTD_CCtx_params* params) { DEBUGLOG(4, "ZSTD_CCtx_setParametersUsingCCtxParams"); { ZSTD_rust_setParametersUsingCCtxParamsState const state = { &cctx->requestedParams, params, (int)cctx->streamStage, cctx->cdict }; return ZSTD_rust_setParametersUsingCCtxParams(&state); } } static size_t ZSTD_rust_setCParams_checkCParams( void* context, ZSTD_compressionParameters cParams) { (void)context; return ZSTD_checkCParams(cParams); } static size_t ZSTD_rust_setCParams_setParameter( void* context, int param, int value) { return ZSTD_CCtx_setParameter((ZSTD_CCtx*)context, (ZSTD_cParameter)param, value); } static size_t ZSTD_rust_setFParams_setParameter( void* context, int param, int value) { return ZSTD_CCtx_setParameter((ZSTD_CCtx*)context, (ZSTD_cParameter)param, value); } static size_t ZSTD_rust_setParams_checkCParams( void* context, ZSTD_compressionParameters cParams) { (void)context; return ZSTD_checkCParams(cParams); } static size_t ZSTD_rust_setParams_setFParams( void* context, ZSTD_frameParameters fParams) { return ZSTD_CCtx_setFParams((ZSTD_CCtx*)context, fParams); } static size_t ZSTD_rust_setParams_setCParams( void* context, ZSTD_compressionParameters cParams) { return ZSTD_CCtx_setCParams((ZSTD_CCtx*)context, cParams); } size_t ZSTD_CCtx_setCParams(ZSTD_CCtx* cctx, ZSTD_compressionParameters cparams) { ZSTD_rust_setCParamsState state; ZSTD_STATIC_ASSERT(sizeof(cparams) == 7 * 4 /* all params are listed below */); DEBUGLOG(4, "ZSTD_CCtx_setCParams"); state.callbackContext = cctx; state.checkCParams = ZSTD_rust_setCParams_checkCParams; state.setParameter = ZSTD_rust_setCParams_setParameter; return ZSTD_rust_setCParams(&state, cparams); } size_t ZSTD_CCtx_setFParams(ZSTD_CCtx* cctx, ZSTD_frameParameters fparams) { ZSTD_rust_setFParamsState state; ZSTD_STATIC_ASSERT(sizeof(fparams) == 3 * 4 /* all params are listed below */); DEBUGLOG(4, "ZSTD_CCtx_setFParams"); state.callbackContext = cctx; state.setParameter = ZSTD_rust_setFParams_setParameter; return ZSTD_rust_setFParams(&state, fparams); } size_t ZSTD_CCtx_setParams(ZSTD_CCtx* cctx, ZSTD_parameters params) { ZSTD_rust_setParamsState state; DEBUGLOG(4, "ZSTD_CCtx_setParams"); state.callbackContext = cctx; state.checkCParams = ZSTD_rust_setParams_checkCParams; state.setFParams = ZSTD_rust_setParams_setFParams; state.setCParams = ZSTD_rust_setParams_setCParams; return ZSTD_rust_setParams(&state, params); } size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize) { DEBUGLOG(4, "ZSTD_CCtx_setPledgedSrcSize to %llu bytes", pledgedSrcSize); return ZSTD_rust_setPledgedSrcSize((int)cctx->streamStage, pledgedSrcSize, &cctx->pledgedSrcSizePlusOne); } size_t ZSTD_CCtx_loadDictionary_advanced( ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType) { DEBUGLOG(4, "ZSTD_CCtx_loadDictionary_advanced (size: %u)", (U32)dictSize); return ZSTD_rust_CCtx_loadDictionaryAdvanced( cctx, (int)cctx->streamStage, dict, dictSize, (int)dictLoadMethod, (int)dictContentType, ZSTD_clearAllDicts_callback, ZSTD_assignLocalDict_callback); } size_t ZSTD_CCtx_loadDictionary_byReference( ZSTD_CCtx* cctx, const void* dict, size_t dictSize) { return ZSTD_CCtx_loadDictionary_advanced( cctx, dict, dictSize, ZSTD_dlm_byRef, ZSTD_dct_auto); } size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, size_t dictSize) { return ZSTD_CCtx_loadDictionary_advanced( cctx, dict, dictSize, ZSTD_dlm_byCopy, ZSTD_dct_auto); } size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict) { return ZSTD_rust_CCtx_refCDict( cctx, (int)cctx->streamStage, cdict, ZSTD_clearAllDicts_callback, ZSTD_assignCDict_callback); } size_t ZSTD_CCtx_refThreadPool(ZSTD_CCtx* cctx, ZSTD_threadPool* pool) { ZSTD_rust_refThreadPoolState state; state.pool = (void**)&cctx->pool; state.requestedPool = pool; state.streamStage = (int)cctx->streamStage; return ZSTD_rust_refThreadPool(&state); } size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize) { return ZSTD_CCtx_refPrefix_advanced(cctx, prefix, prefixSize, ZSTD_dct_rawContent); } size_t ZSTD_CCtx_refPrefix_advanced( ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType) { return ZSTD_rust_CCtx_refPrefixAdvanced( cctx, (int)cctx->streamStage, prefix, prefixSize, (int)dictContentType, ZSTD_clearAllDicts_callback, ZSTD_assignPrefixDict_callback); } static void ZSTD_rust_resetCCtx_clearAllDicts(void* context) { ZSTD_clearAllDicts((ZSTD_CCtx*)context); } static size_t ZSTD_rust_resetCCtx_resetParams(void* context) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; return ZSTD_CCtxParams_reset(&cctx->requestedParams); } /*! ZSTD_CCtx_reset() : * Also dumps dictionary */ size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_ResetDirective reset) { ZSTD_rust_resetCCtxState state; state.callbackContext = cctx; state.rustSimpleCompress2Completed = &cctx->rustSimpleCompress2Completed; state.streamStage = &cctx->streamStage; state.pledgedSrcSizePlusOne = &cctx->pledgedSrcSizePlusOne; state.rustSimpleCompress2MaxBlockSizeSet = &cctx->rustSimpleCompress2MaxBlockSizeSet; state.clearAllDicts = ZSTD_rust_resetCCtx_clearAllDicts; state.resetParams = ZSTD_rust_resetCCtx_resetParams; return ZSTD_rust_resetCCtx(&state, (int)reset); } U32 ZSTD_getCParamsExclusionMask(void); /** ZSTD_adjustCParams_internal() : * optimize `cPar` for a specified input (`srcSize` and `dictSize`). * mostly downsize to reduce memory consumption and initialization latency. * `srcSize` can be ZSTD_CONTENTSIZE_UNKNOWN when not known. * `mode` is the mode for parameter adjustment. See docs for `ZSTD_CParamMode_e`. * note : `srcSize==0` means 0! * condition : cPar is presumed validated (can be checked using ZSTD_checkCParams()). */ static ZSTD_compressionParameters ZSTD_adjustCParams_internal(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize, ZSTD_CParamMode_e mode, ZSTD_ParamSwitch_e useRowMatchFinder) { assert(ZSTD_checkCParams(cPar)==0); /* Cascade the selected strategy down to the next-highest one built into * this binary. The C preprocessor constructs the mask so Rust does not * need to mirror this build's active ZSTD_EXCLUDE_* definitions. */ cPar = ZSTD_rust_params_applyStrategyExclusions( cPar, ZSTD_getCParamsExclusionMask()); /* The remaining adjustment logic is context-free and lives in Rust. The * short-cache and row-hash tag widths the leaf assumes are fixed * private-header constants; keep them checked here. */ ZSTD_STATIC_ASSERT(ZSTD_SHORT_CACHE_TAG_BITS == 8); ZSTD_STATIC_ASSERT(ZSTD_ROW_HASH_TAG_BITS == 8); return ZSTD_rust_params_adjustCParams(cPar, (U64)srcSize, dictSize, (int)mode, (int)useRowMatchFinder); } ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize) { cPar = ZSTD_clampCParams(cPar); /* resulting cPar is necessarily valid (all parameters within range) */ if (srcSize == 0) srcSize = ZSTD_CONTENTSIZE_UNKNOWN; return ZSTD_adjustCParams_internal(cPar, srcSize, dictSize, ZSTD_cpm_unknown, ZSTD_ps_auto); } static ZSTD_compressionParameters ZSTD_getCParams_internal(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize, ZSTD_CParamMode_e mode); static ZSTD_parameters ZSTD_getParams_internal(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize, ZSTD_CParamMode_e mode); enum { ZSTD_RUST_PARAMS_EXCLUDE_BTULTRA = 1u << 0, ZSTD_RUST_PARAMS_EXCLUDE_BTOPT = 1u << 1, ZSTD_RUST_PARAMS_EXCLUDE_BTLAZY2 = 1u << 2, ZSTD_RUST_PARAMS_EXCLUDE_LAZY2 = 1u << 3, ZSTD_RUST_PARAMS_EXCLUDE_LAZY = 1u << 4, ZSTD_RUST_PARAMS_EXCLUDE_GREEDY = 1u << 5, ZSTD_RUST_PARAMS_EXCLUDE_DFAST = 1u << 6 }; U32 ZSTD_getCParamsExclusionMask(void) { U32 mask = 0; #ifdef ZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR mask |= ZSTD_RUST_PARAMS_EXCLUDE_BTULTRA; #endif #ifdef ZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR mask |= ZSTD_RUST_PARAMS_EXCLUDE_BTOPT; #endif #ifdef ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR mask |= ZSTD_RUST_PARAMS_EXCLUDE_BTLAZY2; #endif #ifdef ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR mask |= ZSTD_RUST_PARAMS_EXCLUDE_LAZY2; #endif #ifdef ZSTD_EXCLUDE_LAZY_BLOCK_COMPRESSOR mask |= ZSTD_RUST_PARAMS_EXCLUDE_LAZY; #endif #ifdef ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR mask |= ZSTD_RUST_PARAMS_EXCLUDE_GREEDY; #endif #ifdef ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR mask |= ZSTD_RUST_PARAMS_EXCLUDE_DFAST; #endif return mask; } /* ZSTD_getCParamsFromCCtxParams() is implemented directly by Rust. */ static size_t ZSTD_estimateCCtxSize_usingCCtxParams_internal( const ZSTD_compressionParameters* cParams, const ldmParams_t* ldmParams, const int isStatic, const ZSTD_ParamSwitch_e useRowMatchFinder, const size_t buffInSize, const size_t buffOutSize, const U64 pledgedSrcSize, int useSequenceProducer, size_t maxBlockSize) { ZSTD_rustCCtxWorkspaceSizing const sizing = { sizeof(ZSTD_CCtx), sizeof(ZSTD_compressedBlockState_t), sizeof(SeqDef), sizeof(rawSeq), sizeof(ZSTD_Sequence), TMP_WORKSPACE_SIZE, WILDCOPY_OVERLENGTH, sizeof(ZSTD_match_t), sizeof(ZSTD_optimal_t), ZSTD_RUST_ASAN_REDZONE_SIZE }; size_t const neededSpace = ZSTD_rust_estimateCCtxWorkspaceSize( *cParams, (int)ldmParams->enableLdm, ldmParams->hashLog, ldmParams->bucketSizeLog, ldmParams->minMatchLength, isStatic, (int)useRowMatchFinder, buffInSize, buffOutSize, pledgedSrcSize, useSequenceProducer, maxBlockSize, &sizing); DEBUGLOG(5, "estimate workspace : %u", (U32)neededSpace); return neededSpace; } size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params) { ZSTD_compressionParameters const cParams = ZSTD_getCParamsFromCCtxParams(params, ZSTD_CONTENTSIZE_UNKNOWN, 0, ZSTD_cpm_noAttachDict); ZSTD_ParamSwitch_e const useRowMatchFinder = (ZSTD_ParamSwitch_e) ZSTD_resolveRowMatchFinderMode((int)params->useRowMatchFinder, cParams); RETURN_ERROR_IF(params->nbWorkers > 0, GENERIC, "Estimate CCtx size is supported for single-threaded compression only."); /* estimateCCtxSize is for one-shot compression. So no buffers should * be needed. However, we still allocate two 0-sized buffers, which can * take space under ASAN. */ return ZSTD_estimateCCtxSize_usingCCtxParams_internal( &cParams, ¶ms->ldmParams, 1, useRowMatchFinder, 0, 0, ZSTD_CONTENTSIZE_UNKNOWN, ZSTD_hasExtSeqProd(params), params->maxBlockSize); } static size_t ZSTD_rust_estimateCCtxSize_usingCParams_estimate( void* context, int useRowMatchFinder) { ZSTD_compressionParameters const* const cParams = (const ZSTD_compressionParameters*)context; ZSTD_CCtx_params initialParams = ZSTD_makeCCtxParamsFromCParams(*cParams); initialParams.useRowMatchFinder = (ZSTD_ParamSwitch_e)useRowMatchFinder; return ZSTD_estimateCCtxSize_usingCCtxParams(&initialParams); } size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams) { ZSTD_rust_estimateCSizeUsingCParamsState const state = { &cParams, (int)cParams.strategy, ZSTD_rust_estimateCCtxSize_usingCParams_estimate }; return ZSTD_rust_estimateCSizeUsingCParams(&state); } static ZSTD_compressionParameters ZSTD_rust_estimateCCtxSize_getCParams( void* context, int compressionLevel, U64 srcSizeHint) { (void)context; return ZSTD_getCParams_internal( compressionLevel, srcSizeHint, 0, ZSTD_cpm_noAttachDict); } static size_t ZSTD_rust_estimateCCtxSize_estimate( void* context, ZSTD_compressionParameters cParams) { (void)context; return ZSTD_estimateCCtxSize_usingCParams(cParams); } static size_t ZSTD_estimateCCtxSize_internal(int compressionLevel) { ZSTD_rust_estimateCCtxSizeState const state = { NULL, compressionLevel, ZSTD_rust_estimateCCtxSize_getCParams, ZSTD_rust_estimateCCtxSize_estimate }; return ZSTD_rust_estimateCCtxSizeInternal(&state); } static size_t ZSTD_rust_estimateCCtxSize_estimateLevel( void* context, int compressionLevel) { (void)context; return ZSTD_estimateCCtxSize_internal(compressionLevel); } size_t ZSTD_estimateCCtxSize(int compressionLevel) { ZSTD_rust_estimateCSizeState const state = { NULL, compressionLevel, ZSTD_rust_estimateCCtxSize_estimateLevel }; return ZSTD_rust_estimateCSizeMonotonic(&state); } size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params) { RETURN_ERROR_IF(params->nbWorkers > 0, GENERIC, "Estimate CCtx size is supported for single-threaded compression only."); { ZSTD_compressionParameters const cParams = ZSTD_getCParamsFromCCtxParams(params, ZSTD_CONTENTSIZE_UNKNOWN, 0, ZSTD_cpm_noAttachDict); size_t const blockSize = MIN(ZSTD_resolveMaxBlockSize(params->maxBlockSize), (size_t)1 << cParams.windowLog); size_t const inBuffSize = (params->inBufferMode == ZSTD_bm_buffered) ? ((size_t)1 << cParams.windowLog) + blockSize : 0; size_t const outBuffSize = (params->outBufferMode == ZSTD_bm_buffered) ? ZSTD_compressBound(blockSize) + 1 : 0; ZSTD_ParamSwitch_e const useRowMatchFinder = (ZSTD_ParamSwitch_e) ZSTD_resolveRowMatchFinderMode( (int)params->useRowMatchFinder, params->cParams); return ZSTD_estimateCCtxSize_usingCCtxParams_internal( &cParams, ¶ms->ldmParams, 1, useRowMatchFinder, inBuffSize, outBuffSize, ZSTD_CONTENTSIZE_UNKNOWN, ZSTD_hasExtSeqProd(params), params->maxBlockSize); } } static size_t ZSTD_rust_estimateCStreamSize_usingCParams_estimate( void* context, int useRowMatchFinder) { ZSTD_compressionParameters const* const cParams = (const ZSTD_compressionParameters*)context; ZSTD_CCtx_params initialParams = ZSTD_makeCCtxParamsFromCParams(*cParams); initialParams.useRowMatchFinder = (ZSTD_ParamSwitch_e)useRowMatchFinder; return ZSTD_estimateCStreamSize_usingCCtxParams(&initialParams); } size_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams) { ZSTD_rust_estimateCSizeUsingCParamsState const state = { &cParams, (int)cParams.strategy, ZSTD_rust_estimateCStreamSize_usingCParams_estimate }; return ZSTD_rust_estimateCSizeUsingCParams(&state); } static size_t ZSTD_estimateCStreamSize_internal(int compressionLevel) { ZSTD_compressionParameters const cParams = ZSTD_getCParams_internal(compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN, 0, ZSTD_cpm_noAttachDict); return ZSTD_estimateCStreamSize_usingCParams(cParams); } static size_t ZSTD_rust_estimateCStreamSize_estimateLevel( void* context, int compressionLevel) { (void)context; return ZSTD_estimateCStreamSize_internal(compressionLevel); } size_t ZSTD_estimateCStreamSize(int compressionLevel) { ZSTD_rust_estimateCSizeState const state = { NULL, compressionLevel, ZSTD_rust_estimateCStreamSize_estimateLevel }; return ZSTD_rust_estimateCSizeMonotonic(&state); } /* ZSTD_getFrameProgression(): * tells how much data has been consumed (input) and produced (output) for current frame. * able to count progression inside worker threads (non-blocking mode). */ #ifdef ZSTD_MULTITHREAD static ZSTD_frameProgression ZSTD_rust_frameProgression_MT(void* context) { return ZSTDMT_getFrameProgression((ZSTDMT_CCtx*)context); } #endif ZSTD_frameProgression ZSTD_getFrameProgression(const ZSTD_CCtx* cctx) { ZSTD_rust_frameProgressionMTorSTState state = { cctx->consumedSrcSize, cctx->producedCSize, { cctx->inBuff, cctx->inBuffPos, cctx->inToCompress }, NULL, NULL, 0 }; #ifdef ZSTD_MULTITHREAD state.mtContext = cctx->mtctx; state.mtFrameProgression = ZSTD_rust_frameProgression_MT; state.nbWorkers = (int)cctx->appliedParams.nbWorkers; #endif return ZSTD_rust_frameProgressionMTorST(&state); } typedef size_t (*ZSTD_rust_toFlushNow_f)(void* context); typedef struct { void* callbackContext; int nbWorkers; ZSTD_rust_toFlushNow_f toFlushNow; } ZSTD_rust_toFlushNowState; typedef char ZSTD_rust_to_flush_now_state_layout[ (offsetof(ZSTD_rust_toFlushNowState, callbackContext) == 0 && offsetof(ZSTD_rust_toFlushNowState, nbWorkers) == sizeof(void*) && offsetof(ZSTD_rust_toFlushNowState, toFlushNow) == 2 * sizeof(void*) && sizeof(ZSTD_rust_toFlushNowState) == 3 * sizeof(void*)) ? 1 : -1]; size_t ZSTD_rust_toFlushNow(const ZSTD_rust_toFlushNowState* state); static size_t ZSTD_rust_toFlushNow_callback(void* context) { #ifdef ZSTD_MULTITHREAD return ZSTDMT_toFlushNow(((ZSTD_CCtx*)context)->mtctx); #else (void)context; return 0; #endif } /*! ZSTD_toFlushNow() * Only useful for multithreading scenarios currently (nbWorkers >= 1). */ size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx) { ZSTD_rust_toFlushNowState state; state.callbackContext = cctx; state.nbWorkers = (int)cctx->appliedParams.nbWorkers; state.toFlushNow = ZSTD_rust_toFlushNow_callback; return ZSTD_rust_toFlushNow(&state); } /** * Controls, for this matchState reset, whether the tables need to be cleared / * prepared for the coming compression (ZSTDcrp_makeClean), or whether the * tables can be left unclean (ZSTDcrp_leaveDirty), because we know that a * subsequent operation will overwrite the table space anyways (e.g., copying * the matchState contents in from a CDict). */ typedef enum { ZSTDcrp_makeClean, ZSTDcrp_leaveDirty } ZSTD_compResetPolicy_e; /** * Controls, for this matchState reset, whether indexing can continue where it * left off (ZSTDirp_continue), or whether it needs to be restarted from zero * (ZSTDirp_reset). */ typedef enum { ZSTDirp_continue, ZSTDirp_reset } ZSTD_indexResetPolicy_e; typedef enum { ZSTD_resetTarget_CDict, ZSTD_resetTarget_CCtx } ZSTD_resetTarget_e; /* Mixes in the hashSalt and hashSaltEntropy to create a new hashSalt */ typedef struct { ZSTD_MatchState_t* ms; ZSTD_cwksp* ws; } ZSTD_rust_resetMatchStateContext; enum { ZSTD_RUST_RESET_MATCH_RESERVE_TABLE = 0, ZSTD_RUST_RESET_MATCH_RESERVE_ALIGNED_INIT_ONCE = 1, ZSTD_RUST_RESET_MATCH_RESERVE_ALIGNED64 = 2 }; enum { ZSTD_RUST_RESET_MATCH_POINTER_HASH_TABLE = 0, ZSTD_RUST_RESET_MATCH_POINTER_CHAIN_TABLE = 1, ZSTD_RUST_RESET_MATCH_POINTER_HASH_TABLE3 = 2, ZSTD_RUST_RESET_MATCH_POINTER_TAG_TABLE = 3, ZSTD_RUST_RESET_MATCH_POINTER_LIT_FREQ = 4, ZSTD_RUST_RESET_MATCH_POINTER_LIT_LENGTH_FREQ = 5, ZSTD_RUST_RESET_MATCH_POINTER_MATCH_LENGTH_FREQ = 6, ZSTD_RUST_RESET_MATCH_POINTER_OFF_CODE_FREQ = 7, ZSTD_RUST_RESET_MATCH_POINTER_MATCH_TABLE = 8, ZSTD_RUST_RESET_MATCH_POINTER_PRICE_TABLE = 9 }; static void ZSTD_rust_resetMatchState_windowInit(void* opaque) { ZSTD_rust_resetMatchStateContext* const context = (ZSTD_rust_resetMatchStateContext*)opaque; ZSTD_window_init(&context->ms->window); } static void ZSTD_rust_resetMatchState_markTablesDirty(void* opaque) { ZSTD_rust_resetMatchStateContext* const context = (ZSTD_rust_resetMatchStateContext*)opaque; ZSTD_cwksp_mark_tables_dirty(context->ws); } static void ZSTD_rust_resetMatchState_invalidate(void* opaque) { ZSTD_rust_resetMatchStateContext* const context = (ZSTD_rust_resetMatchStateContext*)opaque; ZSTD_MatchState_t* const ms = context->ms; ZSTD_rust_invalidateMatchState( (size_t)(ms->window.nextSrc - ms->window.base), &ms->window.lowLimit, &ms->window.dictLimit, &ms->nextToUpdate, &ms->loadedDictEnd, &ms->opt.litLengthSum, &ms->dictMatchState); } static void ZSTD_rust_resetMatchState_clearTables(void* opaque) { ZSTD_rust_resetMatchStateContext* const context = (ZSTD_rust_resetMatchStateContext*)opaque; ZSTD_cwksp_clear_tables(context->ws); } static void ZSTD_rust_resetMatchState_cleanTables(void* opaque) { ZSTD_rust_resetMatchStateContext* const context = (ZSTD_rust_resetMatchStateContext*)opaque; ZSTD_cwksp_clean_tables(context->ws); } static void* ZSTD_rust_resetMatchState_reserve( void* opaque, int reserveKind, size_t size) { ZSTD_rust_resetMatchStateContext* const context = (ZSTD_rust_resetMatchStateContext*)opaque; switch (reserveKind) { case ZSTD_RUST_RESET_MATCH_RESERVE_TABLE: return ZSTD_cwksp_reserve_table(context->ws, size); case ZSTD_RUST_RESET_MATCH_RESERVE_ALIGNED_INIT_ONCE: return ZSTD_cwksp_reserve_aligned_init_once(context->ws, size); case ZSTD_RUST_RESET_MATCH_RESERVE_ALIGNED64: return ZSTD_cwksp_reserve_aligned64(context->ws, size); default: assert(0); return NULL; } } static int ZSTD_rust_resetMatchState_reserveFailed(void* opaque) { ZSTD_rust_resetMatchStateContext* const context = (ZSTD_rust_resetMatchStateContext*)opaque; return ZSTD_cwksp_reserve_failed(context->ws); } static void ZSTD_rust_resetMatchState_setPointer( void* opaque, int pointerKind, void* pointer) { ZSTD_rust_resetMatchStateContext* const context = (ZSTD_rust_resetMatchStateContext*)opaque; ZSTD_MatchState_t* const ms = context->ms; switch (pointerKind) { case ZSTD_RUST_RESET_MATCH_POINTER_HASH_TABLE: ms->hashTable = (U32*)pointer; break; case ZSTD_RUST_RESET_MATCH_POINTER_CHAIN_TABLE: ms->chainTable = (U32*)pointer; break; case ZSTD_RUST_RESET_MATCH_POINTER_HASH_TABLE3: ms->hashTable3 = (U32*)pointer; break; case ZSTD_RUST_RESET_MATCH_POINTER_TAG_TABLE: ms->tagTable = (BYTE*)pointer; break; case ZSTD_RUST_RESET_MATCH_POINTER_LIT_FREQ: ms->opt.litFreq = (unsigned*)pointer; break; case ZSTD_RUST_RESET_MATCH_POINTER_LIT_LENGTH_FREQ: ms->opt.litLengthFreq = (unsigned*)pointer; break; case ZSTD_RUST_RESET_MATCH_POINTER_MATCH_LENGTH_FREQ: ms->opt.matchLengthFreq = (unsigned*)pointer; break; case ZSTD_RUST_RESET_MATCH_POINTER_OFF_CODE_FREQ: ms->opt.offCodeFreq = (unsigned*)pointer; break; case ZSTD_RUST_RESET_MATCH_POINTER_MATCH_TABLE: ms->opt.matchTable = (ZSTD_match_t*)pointer; break; case ZSTD_RUST_RESET_MATCH_POINTER_PRICE_TABLE: ms->opt.priceTable = (ZSTD_optimal_t*)pointer; break; default: assert(0); break; } } static void ZSTD_rust_resetMatchState_zero( void* opaque, void* pointer, size_t size) { (void)opaque; ZSTD_memset(pointer, 0, size); } static size_t ZSTD_reset_matchState(ZSTD_MatchState_t* ms, ZSTD_cwksp* ws, const ZSTD_compressionParameters* cParams, const ZSTD_ParamSwitch_e useRowMatchFinder, const ZSTD_compResetPolicy_e crp, const ZSTD_indexResetPolicy_e forceResetIndex, const ZSTD_resetTarget_e forWho) { ZSTD_rust_resetMatchStateContext context; ZSTD_rust_resetMatchStateState state; context.ms = ms; context.ws = ws; state.callbackContext = &context; state.cParams = *cParams; state.dedicatedDictSearch = ms->dedicatedDictSearch; state.useRowMatchFinder = (int)useRowMatchFinder; state.compResetPolicy = (int)crp; state.indexResetPolicy = (int)forceResetIndex; state.resetTarget = (int)forWho; state.hashLog3Max = ZSTD_HASHLOG3_MAX; state.litFreqSize = (1 << Litbits) * sizeof(unsigned); state.litLengthFreqSize = (MaxLL + 1) * sizeof(unsigned); state.matchLengthFreqSize = (MaxML + 1) * sizeof(unsigned); state.offCodeFreqSize = (MaxOff + 1) * sizeof(unsigned); state.matchSize = ZSTD_OPT_SIZE * sizeof(ZSTD_match_t); state.optimalSize = ZSTD_OPT_SIZE * sizeof(ZSTD_optimal_t); state.hashLog3 = &ms->hashLog3; state.rowHashLog = &ms->rowHashLog; state.hashSalt = &ms->hashSalt; state.lazySkipping = &ms->lazySkipping; state.cParamsOut = &ms->cParams; state.setPointer = ZSTD_rust_resetMatchState_setPointer; state.windowInit = ZSTD_rust_resetMatchState_windowInit; state.markTablesDirty = ZSTD_rust_resetMatchState_markTablesDirty; state.invalidateMatchState = ZSTD_rust_resetMatchState_invalidate; state.clearTables = ZSTD_rust_resetMatchState_clearTables; state.cleanTables = ZSTD_rust_resetMatchState_cleanTables; state.hashSaltEntropy = ms->hashSaltEntropy; state.reserve = ZSTD_rust_resetMatchState_reserve; state.reserveFailed = ZSTD_rust_resetMatchState_reserveFailed; state.zero = ZSTD_rust_resetMatchState_zero; return ZSTD_rust_resetMatchState(&state); } /* ZSTD_indexTooCloseToMax() and ZSTD_dictTooBig() are Rust-owned scalar policy * leaves. C retains the window and dictionary state used to supply inputs. */ typedef struct { ZSTD_CCtx* cctx; ZSTD_cwksp* ws; } ZSTD_rust_resetCCtxStorageContext; static void ZSTD_rust_resetCCtxStorage_setPointer( void* opaque, int pointerKind, void* pointer) { ZSTD_rust_resetCCtxStorageContext* const context = (ZSTD_rust_resetCCtxStorageContext*)opaque; ZSTD_CCtx* const cctx = context->cctx; switch (pointerKind) { case ZSTD_RUST_RESET_CCTX_POINTER_SEQ_START: cctx->seqStore.sequencesStart = (SeqDef*)pointer; break; case ZSTD_RUST_RESET_CCTX_POINTER_LDM_HASH: cctx->ldmState.hashTable = (ldmEntry_t*)pointer; break; case ZSTD_RUST_RESET_CCTX_POINTER_LDM_SEQUENCES: cctx->ldmSequences = (rawSeq*)pointer; break; case ZSTD_RUST_RESET_CCTX_POINTER_EXTERNAL_SEQUENCES: cctx->extSeqBuf = (ZSTD_Sequence*)pointer; break; case ZSTD_RUST_RESET_CCTX_POINTER_LITERALS: cctx->seqStore.litStart = (BYTE*)pointer; break; case ZSTD_RUST_RESET_CCTX_POINTER_INPUT_BUFFER: cctx->inBuff = (char*)pointer; break; case ZSTD_RUST_RESET_CCTX_POINTER_OUTPUT_BUFFER: cctx->outBuff = (char*)pointer; break; case ZSTD_RUST_RESET_CCTX_POINTER_LL_CODE: cctx->seqStore.llCode = (BYTE*)pointer; break; case ZSTD_RUST_RESET_CCTX_POINTER_ML_CODE: cctx->seqStore.mlCode = (BYTE*)pointer; break; case ZSTD_RUST_RESET_CCTX_POINTER_OF_CODE: cctx->seqStore.ofCode = (BYTE*)pointer; break; case ZSTD_RUST_RESET_CCTX_POINTER_LDM_BUCKETS: cctx->ldmState.bucketOffsets = (BYTE*)pointer; break; case ZSTD_RUST_RESET_CCTX_POINTER_PREV_CBLOCK: cctx->blockState.prevCBlock = (ZSTD_compressedBlockState_t*)pointer; break; case ZSTD_RUST_RESET_CCTX_POINTER_NEXT_CBLOCK: cctx->blockState.nextCBlock = (ZSTD_compressedBlockState_t*)pointer; break; case ZSTD_RUST_RESET_CCTX_POINTER_TMP_WORKSPACE: cctx->tmpWorkspace = pointer; break; default: assert(0); break; } } static void ZSTD_rust_resetCCtxStorage_setSize( void* opaque, int sizeKind, size_t value) { ZSTD_rust_resetCCtxStorageContext* const context = (ZSTD_rust_resetCCtxStorageContext*)opaque; ZSTD_CCtx* const cctx = context->cctx; switch (sizeKind) { case ZSTD_RUST_RESET_CCTX_SIZE_MAX_NB_SEQ: cctx->seqStore.maxNbSeq = value; break; case ZSTD_RUST_RESET_CCTX_SIZE_MAX_NB_LIT: cctx->seqStore.maxNbLit = value; break; case ZSTD_RUST_RESET_CCTX_SIZE_MAX_NB_LDM_SEQ: cctx->maxNbLdmSequences = value; break; case ZSTD_RUST_RESET_CCTX_SIZE_EXTERNAL_SEQ_CAPACITY: cctx->extSeqBufCapacity = value; break; case ZSTD_RUST_RESET_CCTX_SIZE_INPUT_BUFFER: cctx->inBuffSize = value; break; case ZSTD_RUST_RESET_CCTX_SIZE_OUTPUT_BUFFER: cctx->outBuffSize = value; break; case ZSTD_RUST_RESET_CCTX_SIZE_TMP_WORKSPACE: cctx->tmpWkspSize = value; break; default: assert(0); break; } } static void ZSTD_rust_resetCCtxStorage_setInt( void* opaque, int intKind, int value) { ZSTD_rust_resetCCtxStorageContext* const context = (ZSTD_rust_resetCCtxStorageContext*)opaque; ZSTD_CCtx* const cctx = context->cctx; switch (intKind) { case ZSTD_RUST_RESET_CCTX_INT_BUFFERED_POLICY: cctx->bufferedPolicy = (ZSTD_buffered_policy_e)value; break; case ZSTD_RUST_RESET_CCTX_INT_INITIALIZED: cctx->initialized = value; break; default: assert(0); break; } } static void* ZSTD_rust_resetCCtxStorage_reserve( void* opaque, int reserveKind, size_t size) { ZSTD_rust_resetCCtxStorageContext* const context = (ZSTD_rust_resetCCtxStorageContext*)opaque; switch (reserveKind) { case ZSTD_RUST_RESET_CCTX_RESERVE_ALIGNED64: return ZSTD_cwksp_reserve_aligned64(context->ws, size); case ZSTD_RUST_RESET_CCTX_RESERVE_BUFFER: return ZSTD_cwksp_reserve_buffer(context->ws, size); default: assert(0); return NULL; } } static int ZSTD_rust_resetCCtxStorage_reserveFailed(void* opaque) { ZSTD_rust_resetCCtxStorageContext* const context = (ZSTD_rust_resetCCtxStorageContext*)opaque; return ZSTD_cwksp_reserve_failed(context->ws); } static void ZSTD_rust_resetCCtxStorage_zero( void* opaque, void* pointer, size_t size) { (void)opaque; ZSTD_memset(pointer, 0, size); } static void ZSTD_rust_resetCCtxStorage_windowInit(void* opaque) { ZSTD_rust_resetCCtxStorageContext* const context = (ZSTD_rust_resetCCtxStorageContext*)opaque; ZSTD_window_init(&context->cctx->ldmState.window); context->cctx->ldmState.loadedDictEnd = 0; } static void ZSTD_rust_resetCCtxStorage_resetExternalSequences(void* opaque) { ZSTD_rust_resetCCtxStorageContext* const context = (ZSTD_rust_resetCCtxStorageContext*)opaque; ZSTD_referenceExternalSequences(context->cctx, NULL, 0); } static void ZSTD_rust_resetCCtxWorkspace_bumpOversizedDuration(void* opaque) { ZSTD_rust_resetCCtxStorageContext* const context = (ZSTD_rust_resetCCtxStorageContext*)opaque; ZSTD_rust_workspaceBumpOversizedDuration( ZSTD_cwksp_available_space(context->ws), 0, &context->ws->workspaceOversizedDuration); } static void ZSTD_rust_resetCCtxWorkspace_free(void* opaque) { ZSTD_rust_resetCCtxStorageContext* const context = (ZSTD_rust_resetCCtxStorageContext*)opaque; ZSTD_cwksp_free(context->ws, context->cctx->customMem); } static size_t ZSTD_rust_resetCCtxWorkspace_create( void* opaque, size_t neededSpace) { ZSTD_rust_resetCCtxStorageContext* const context = (ZSTD_rust_resetCCtxStorageContext*)opaque; return ZSTD_cwksp_create( context->ws, neededSpace, context->cctx->customMem); } static void* ZSTD_rust_resetCCtxWorkspace_reserveObject( void* opaque, size_t size) { ZSTD_rust_resetCCtxStorageContext* const context = (ZSTD_rust_resetCCtxStorageContext*)opaque; return ZSTD_cwksp_reserve_object(context->ws, size); } static void ZSTD_rust_resetCCtxWorkspace_clear(void* opaque) { ZSTD_rust_resetCCtxStorageContext* const context = (ZSTD_rust_resetCCtxStorageContext*)opaque; ZSTD_cwksp_clear(context->ws); } typedef struct { ZSTD_CCtx* cctx; const ZSTD_CCtx_params* params; ZSTD_cwksp* ws; ZSTD_compResetPolicy_e compResetPolicy; ZSTD_indexResetPolicy_e indexResetPolicy; ZSTD_rust_resetCCtxStorageState* storageState; ZSTD_rust_resetCCtxTailState* tailState; } ZSTD_rust_resetCCtxTailContext; static void ZSTD_rust_resetCCtxWorkspace_prepare( void* opaque, size_t neededSpace, size_t windowSize, size_t blockSize, int* workspaceTooSmall, int* workspaceWasteful) { ZSTD_rust_resetCCtxTailContext* const context = (ZSTD_rust_resetCCtxTailContext*)opaque; ZSTD_cwksp* const ws = context->ws; ZSTD_rust_workspaceResizeFlags( ZSTD_cwksp_sizeof(ws), ZSTD_cwksp_available_space(ws), ws->workspaceOversizedDuration, neededSpace, workspaceTooSmall, workspaceWasteful); DEBUGLOG(4, "Need %zu B workspace", neededSpace); DEBUGLOG(4, "windowSize: %zu - blockSize: %zu", windowSize, blockSize); if (*workspaceTooSmall || *workspaceWasteful) { DEBUGLOG(4, "Resize workspaceSize from %zuKB to %zuKB", ZSTD_cwksp_sizeof(ws) >> 10, neededSpace >> 10); } } static void ZSTD_rust_resetCCtxTail_prepare( void* opaque, size_t blockSize, int indexResetPolicy) { ZSTD_rust_resetCCtxTailContext* const context = (ZSTD_rust_resetCCtxTailContext*)opaque; context->indexResetPolicy = (ZSTD_indexResetPolicy_e)indexResetPolicy; context->tailState->blockSize = blockSize; context->tailState->compressedBlockState = context->cctx->blockState.prevCBlock; } static void ZSTD_rust_resetCCtxTail_resetHash(void* opaque) { ZSTD_rust_resetCCtxTailContext* const context = (ZSTD_rust_resetCCtxTailContext*)opaque; ZSTD_CCtx* const cctx = context->cctx; DEBUGLOG(4, "pledged content size : %u ; flag : %u", (unsigned)cctx->pledgedSrcSizePlusOne - 1, cctx->appliedParams.fParams.contentSizeFlag); XXH64_reset(&cctx->xxhState, 0); } static size_t ZSTD_rust_resetCCtxTail_resetMatchState(void* opaque) { ZSTD_rust_resetCCtxTailContext* const context = (ZSTD_rust_resetCCtxTailContext*)opaque; return ZSTD_reset_matchState( &context->cctx->blockState.matchState, context->ws, &context->params->cParams, context->params->useRowMatchFinder, context->compResetPolicy, context->indexResetPolicy, ZSTD_resetTarget_CCtx); } /*! ZSTD_resetCCtx_internal() : * @param loadedDictSize The size of the dictionary to be loaded * into the context, if any. If no dictionary is used, or the * dictionary is being attached / copied, then pass 0. * note : `params` are assumed fully validated at this stage. */ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc, ZSTD_CCtx_params const* params, U64 const pledgedSrcSize, size_t const loadedDictSize, ZSTD_compResetPolicy_e const crp, ZSTD_buffered_policy_e const zbuff) { ZSTD_cwksp* const ws = &zc->workspace; DEBUGLOG(4, "ZSTD_resetCCtx_internal: pledgedSrcSize=%u, wlog=%u, useRowMatchFinder=%d useBlockSplitter=%d", (U32)pledgedSrcSize, params->cParams.windowLog, (int)params->useRowMatchFinder, (int)params->postBlockSplitter); assert(!ZSTD_isError(ZSTD_checkCParams(params->cParams))); zc->isFirstBlock = 1; /* Set applied params early so we can modify them for LDM, * and point params at the applied params. */ zc->appliedParams = *params; params = &zc->appliedParams; assert(params->useRowMatchFinder != ZSTD_ps_auto); assert(params->postBlockSplitter != ZSTD_ps_auto); assert(params->ldmParams.enableLdm != ZSTD_ps_auto); assert(params->maxBlockSize != 0); if (params->ldmParams.enableLdm == ZSTD_ps_enable) { /* Adjust long distance matching parameters */ ZSTD_ldm_adjustParameters(&zc->appliedParams.ldmParams, ¶ms->cParams); assert(params->ldmParams.hashLog >= params->ldmParams.bucketSizeLog); assert(params->ldmParams.hashRateLog < 32); } { ZSTD_rustCCtxWorkspaceSizing const sizing = { sizeof(ZSTD_CCtx), sizeof(ZSTD_compressedBlockState_t), sizeof(SeqDef), sizeof(rawSeq), sizeof(ZSTD_Sequence), TMP_WORKSPACE_SIZE, WILDCOPY_OVERLENGTH, sizeof(ZSTD_match_t), sizeof(ZSTD_optimal_t), ZSTD_RUST_ASAN_REDZONE_SIZE }; ZSTD_rustCCtxResetPlan resetPlan; ZSTD_rustCCtxResetState resetState; ZSTD_indexResetPolicy_e needsIndexReset = ZSTDirp_continue; ZSTD_rust_resetCCtxStorageContext storageContext; ZSTD_rust_resetCCtxStorageState storageState; ZSTD_rust_resetCCtxWorkspaceState workspaceState; ZSTD_rust_resetCCtxTailContext tailContext; ZSTD_rust_resetCCtxTailState tailState; ZSTD_rust_resetCCtxInternalState internalState; resetState.cParams = params->cParams; resetState.ldmEnable = (int)params->ldmParams.enableLdm; resetState.ldmHashLog = params->ldmParams.hashLog; resetState.ldmBucketSizeLog = params->ldmParams.bucketSizeLog; resetState.ldmMinMatchLength = params->ldmParams.minMatchLength; resetState.isStatic = zc->staticSize != 0; resetState.useRowMatchFinder = (int)params->useRowMatchFinder; resetState.inBufferBuffered = zbuff == ZSTDb_buffered && params->inBufferMode == ZSTD_bm_buffered; resetState.outBufferBuffered = zbuff == ZSTDb_buffered && params->outBufferMode == ZSTD_bm_buffered; resetState.useSequenceProducer = ZSTD_hasExtSeqProd(params); resetState.initialized = zc->initialized != 0; resetState.indexTooClose = ZSTD_indexTooCloseToMax((size_t)( zc->blockState.matchState.window.nextSrc - zc->blockState.matchState.window.base)); resetState.dictTooBig = ZSTD_dictTooBig(loadedDictSize); resetState.pledgedSrcSize = pledgedSrcSize; resetState.maxBlockSize = params->maxBlockSize; resetState.sizing = &sizing; resetState.plan = &resetPlan; storageContext.cctx = zc; storageContext.ws = ws; storageState.callbackContext = &storageContext; storageState.ldmEnable = (int)params->ldmParams.enableLdm; storageState.hasExtSeqProd = ZSTD_hasExtSeqProd(params); storageState.hashLog = params->ldmParams.hashLog; storageState.bucketSizeLog = params->ldmParams.bucketSizeLog; storageState.blockSize = 0; storageState.maxNbSeq = 0; storageState.maxNbLdmSeq = 0; storageState.maxNbExternalSeq = 0; storageState.buffInSize = 0; storageState.buffOutSize = 0; storageState.seqDefSize = sizeof(SeqDef); storageState.ldmEntrySize = sizeof(ldmEntry_t); storageState.rawSeqSize = sizeof(rawSeq); storageState.externalSequenceSize = sizeof(ZSTD_Sequence); storageState.byteSize = sizeof(BYTE); storageState.wildcopyOverlength = WILDCOPY_OVERLENGTH; storageState.bufferedPolicy = (int)zbuff; storageState.setPointer = ZSTD_rust_resetCCtxStorage_setPointer; storageState.setSize = ZSTD_rust_resetCCtxStorage_setSize; storageState.setInt = ZSTD_rust_resetCCtxStorage_setInt; storageState.reserve = ZSTD_rust_resetCCtxStorage_reserve; storageState.reserveFailed = ZSTD_rust_resetCCtxStorage_reserveFailed; storageState.zero = ZSTD_rust_resetCCtxStorage_zero; storageState.windowInit = ZSTD_rust_resetCCtxStorage_windowInit; storageState.resetExternalSequences = ZSTD_rust_resetCCtxStorage_resetExternalSequences; workspaceState.callbackContext = &storageContext; workspaceState.isStatic = zc->staticSize != 0; workspaceState.workspaceTooSmall = 0; workspaceState.workspaceWasteful = 0; workspaceState.neededSpace = 0; workspaceState.compressedBlockStateSize = sizeof(ZSTD_compressedBlockState_t); workspaceState.tmpWorkspaceSize = TMP_WORKSPACE_SIZE; workspaceState.needsIndexReset = (int*)&needsIndexReset; workspaceState.bumpOversizedDuration = ZSTD_rust_resetCCtxWorkspace_bumpOversizedDuration; workspaceState.freeWorkspace = ZSTD_rust_resetCCtxWorkspace_free; workspaceState.createWorkspace = ZSTD_rust_resetCCtxWorkspace_create; workspaceState.reserveObject = ZSTD_rust_resetCCtxWorkspace_reserveObject; workspaceState.setPointer = ZSTD_rust_resetCCtxStorage_setPointer; workspaceState.setSize = ZSTD_rust_resetCCtxStorage_setSize; workspaceState.clearWorkspace = ZSTD_rust_resetCCtxWorkspace_clear; tailContext.cctx = zc; tailContext.params = params; tailContext.ws = ws; tailContext.compResetPolicy = crp; tailContext.indexResetPolicy = needsIndexReset; tailContext.storageState = &storageState; tailContext.tailState = &tailState; tailState.callbackContext = &tailContext; tailState.resetHash = ZSTD_rust_resetCCtxTail_resetHash; tailState.compressedBlockState = NULL; tailState.resetMatchState = ZSTD_rust_resetCCtxTail_resetMatchState; tailState.storageState = &storageState; tailState.matchStateCParams = &zc->blockState.matchState.cParams; tailState.matchStatePrefetchCDictTables = &zc->blockState.matchState.prefetchCDictTables; tailState.pledgedSrcSizePlusOne = &zc->pledgedSrcSizePlusOne; tailState.consumedSrcSize = &zc->consumedSrcSize; tailState.producedCSize = &zc->producedCSize; tailState.contentSizeFlag = &zc->appliedParams.fParams.contentSizeFlag; tailState.blockSizeMax = &zc->blockSizeMax; tailState.stage = (int*)&zc->stage; tailState.dictID = &zc->dictID; tailState.dictContentSize = &zc->dictContentSize; tailState.cParams = params->cParams; tailState.prefetchCDictTables = (int)params->prefetchCDictTables; tailState.pledgedSrcSize = pledgedSrcSize; tailState.blockSize = 0; internalState.callbackContext = &tailContext; internalState.resetState = &resetState; internalState.storageState = &storageState; internalState.workspaceState = &workspaceState; internalState.tailState = &tailState; internalState.prepareWorkspace = ZSTD_rust_resetCCtxWorkspace_prepare; internalState.prepareTail = ZSTD_rust_resetCCtxTail_prepare; FORWARD_IF_ERROR(ZSTD_rust_resetCCtxInternal(&internalState), ""); DEBUGLOG(3, "wksp: finished allocating, %zd bytes remain available", ZSTD_cwksp_available_space(ws)); assert(ZSTD_cwksp_estimated_space_within_bounds(ws, resetPlan.neededSpace)); return 0; } } /* ZSTD_invalidateRepCodes() : * ensures next compression will not use repcodes from previous block. * Note : only works with regular variant; * do not use with extDict variant ! */ void ZSTD_invalidateRepCodes(ZSTD_CCtx* cctx) { ZSTD_compressedBlockState_t* const prevCBlock = cctx->blockState.prevCBlock; ZSTD_rust_invalidateRepCodes(prevCBlock->rep); assert(!ZSTD_window_hasExtDict(cctx->blockState.matchState.window)); } static size_t ZSTD_rust_resetCCtx_byAttachingCDict_reset( void* context, const void* cdictOpaque, const void* paramsOpaque, U64 pledgedSrcSize, int zbuff) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; const ZSTD_CDict* const cdict = (const ZSTD_CDict*)cdictOpaque; ZSTD_CCtx_params params = *(const ZSTD_CCtx_params*)paramsOpaque; ZSTD_compressionParameters adjusted_cdict_cParams = cdict->matchState.cParams; unsigned const windowLog = params.cParams.windowLog; DEBUGLOG(4, "ZSTD_resetCCtx_byAttachingCDict() pledgedSrcSize=%llu", (unsigned long long)pledgedSrcSize); assert(windowLog != 0); /* Resize working context table params for input only, since the dict * has its own tables. */ if (cdict->matchState.dedicatedDictSearch) { adjusted_cdict_cParams = ZSTD_rust_params_dedicatedDictSearch_revertCParams( adjusted_cdict_cParams); } params.cParams = ZSTD_adjustCParams_internal( adjusted_cdict_cParams, pledgedSrcSize, cdict->dictContentSize, ZSTD_cpm_attachDict, params.useRowMatchFinder); params.cParams.windowLog = windowLog; params.useRowMatchFinder = cdict->useRowMatchFinder; { size_t const resetError = ZSTD_resetCCtx_internal( cctx, ¶ms, pledgedSrcSize, /* loadedDictSize */ 0, ZSTDcrp_makeClean, (ZSTD_buffered_policy_e)zbuff); if (ZSTD_isError(resetError)) return resetError; } assert(cctx->appliedParams.cParams.strategy == adjusted_cdict_cParams.strategy); return 0; } static size_t ZSTD_resetCCtx_byAttachingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict, ZSTD_CCtx_params params, U64 pledgedSrcSize, ZSTD_buffered_policy_e zbuff) { U32 const cdictEnd = (U32)(cdict->matchState.window.nextSrc - cdict->matchState.window.base); U32 const cdictLen = cdictEnd - cdict->matchState.window.dictLimit; ZSTD_rust_resetCCtxByAttachingCDictState state; state.callbackContext = cctx; state.cdict = cdict; state.params = ¶ms; state.pledgedSrcSize = pledgedSrcSize; state.reset = ZSTD_rust_resetCCtx_byAttachingCDict_reset; state.sourceMatchState = &cdict->matchState; state.sourceCDictEnd = &cdictEnd; state.sourceCDictLen = &cdictLen; state.destinationDictMatchState = &cctx->blockState.matchState.dictMatchState; state.destinationWindowNextSrc = &cctx->blockState.matchState.window.nextSrc; state.destinationWindowBase = &cctx->blockState.matchState.window.base; state.destinationWindowLowLimit = &cctx->blockState.matchState.window.lowLimit; state.destinationWindowDictLimit = &cctx->blockState.matchState.window.dictLimit; state.destinationLoadedDictEnd = &cctx->blockState.matchState.loadedDictEnd; state.destinationDictID = &cctx->dictID; state.sourceDictID = &cdict->dictID; state.destinationDictContentSize = &cctx->dictContentSize; state.sourceDictContentSize = &cdict->dictContentSize; state.destinationBlockState = &cctx->blockState.prevCBlock; state.sourceBlockState = &cdict->cBlockState; state.zbuff = (int)zbuff; return ZSTD_rust_resetCCtxByAttachingCDict(&state); } static size_t ZSTD_rust_resetCCtx_byCopyingCDict_reset( void* context, const void* cdictOpaque, const void* paramsOpaque, U64 pledgedSrcSize, int zbuff) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; const ZSTD_CDict* const cdict = (const ZSTD_CDict*)cdictOpaque; ZSTD_CCtx_params params = *(const ZSTD_CCtx_params*)paramsOpaque; const ZSTD_compressionParameters* const cdict_cParams = &cdict->matchState.cParams; assert(!cdict->matchState.dedicatedDictSearch); DEBUGLOG(4, "ZSTD_resetCCtx_byCopyingCDict() pledgedSrcSize=%llu", (unsigned long long)pledgedSrcSize); { unsigned const windowLog = params.cParams.windowLog; assert(windowLog != 0); /* Copy only compression parameters related to tables. */ params.cParams = *cdict_cParams; params.cParams.windowLog = windowLog; params.useRowMatchFinder = cdict->useRowMatchFinder; { size_t const resetError = ZSTD_resetCCtx_internal( cctx, ¶ms, pledgedSrcSize, /* loadedDictSize */ 0, ZSTDcrp_leaveDirty, (ZSTD_buffered_policy_e)zbuff); if (ZSTD_isError(resetError)) return resetError; } assert(cctx->appliedParams.cParams.strategy == cdict_cParams->strategy); assert(cctx->appliedParams.cParams.hashLog == cdict_cParams->hashLog); assert(cctx->appliedParams.cParams.chainLog == cdict_cParams->chainLog); } return 0; } static void ZSTD_rust_resetCCtx_byCopyingCDict_mark_tables_dirty(void* context) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; ZSTD_cwksp_mark_tables_dirty(&cctx->workspace); } static void ZSTD_rust_resetCCtx_byCopyingCDict_mark_tables_clean(void* context) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; ZSTD_cwksp_mark_tables_clean(&cctx->workspace); } static size_t ZSTD_resetCCtx_byCopyingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict, ZSTD_CCtx_params params, U64 pledgedSrcSize, ZSTD_buffered_policy_e zbuff) { const ZSTD_compressionParameters* const cdict_cParams = &cdict->matchState.cParams; U32 const sourceHashLog = cdict_cParams->hashLog; U32 const sourceChainLog = cdict_cParams->chainLog; int const sourceStrategy = (int)cdict_cParams->strategy; int const sourceUseRowMatchFinder = (int)cdict->useRowMatchFinder; int const sourceIndicesTagged = ZSTD_CDictIndicesAreTagged(*cdict_cParams); ZSTD_rust_resetCCtxByCopyingCDictState state; state.callbackContext = cctx; state.cdict = cdict; state.params = ¶ms; state.pledgedSrcSize = pledgedSrcSize; state.reset = ZSTD_rust_resetCCtx_byCopyingCDict_reset; state.markTablesDirty = ZSTD_rust_resetCCtx_byCopyingCDict_mark_tables_dirty; state.markTablesClean = ZSTD_rust_resetCCtx_byCopyingCDict_mark_tables_clean; assert(cdict->matchState.hashLog3 == 0); state.destinationHashTable = &cctx->blockState.matchState.hashTable; state.sourceHashTable = cdict->matchState.hashTable; state.sourceHashLog = &sourceHashLog; state.destinationChainTable = &cctx->blockState.matchState.chainTable; state.sourceChainTable = cdict->matchState.chainTable; state.sourceChainLog = &sourceChainLog; state.sourceStrategy = &sourceStrategy; state.sourceUseRowMatchFinder = &sourceUseRowMatchFinder; state.sourceIndicesTagged = &sourceIndicesTagged; state.destinationStrategy = (const int*)&cctx->appliedParams.cParams.strategy; state.destinationUseRowMatchFinder = (const int*)&cctx->appliedParams.useRowMatchFinder; state.destinationTagTable = &cctx->blockState.matchState.tagTable; state.sourceTagTable = cdict->matchState.tagTable; state.destinationHashSalt = &cctx->blockState.matchState.hashSalt; state.sourceHashSalt = &cdict->matchState.hashSalt; state.destinationHashTable3 = &cctx->blockState.matchState.hashTable3; state.destinationHashLog3 = &cctx->blockState.matchState.hashLog3; state.destinationWindow = &cctx->blockState.matchState.window; state.sourceWindow = &cdict->matchState.window; state.destinationNextToUpdate = &cctx->blockState.matchState.nextToUpdate; state.sourceNextToUpdate = &cdict->matchState.nextToUpdate; state.destinationLoadedDictEnd = &cctx->blockState.matchState.loadedDictEnd; state.sourceLoadedDictEnd = &cdict->matchState.loadedDictEnd; state.destinationDictID = &cctx->dictID; state.sourceDictID = &cdict->dictID; state.destinationDictContentSize = &cctx->dictContentSize; state.sourceDictContentSize = &cdict->dictContentSize; state.destinationBlockState = &cctx->blockState.prevCBlock; state.sourceBlockState = &cdict->cBlockState; state.zbuff = (int)zbuff; return ZSTD_rust_resetCCtxByCopyingCDict(&state); } static size_t ZSTD_rust_resetCCtxUsingCDict_attach( void* context, const void* cdict, const void* params, U64 pledgedSrcSize, int zbuff) { return ZSTD_resetCCtx_byAttachingCDict( (ZSTD_CCtx*)context, (const ZSTD_CDict*)cdict, *(const ZSTD_CCtx_params*)params, pledgedSrcSize, (ZSTD_buffered_policy_e)zbuff); } static size_t ZSTD_rust_resetCCtxUsingCDict_copy( void* context, const void* cdict, const void* params, U64 pledgedSrcSize, int zbuff) { return ZSTD_resetCCtx_byCopyingCDict( (ZSTD_CCtx*)context, (const ZSTD_CDict*)cdict, *(const ZSTD_CCtx_params*)params, pledgedSrcSize, (ZSTD_buffered_policy_e)zbuff); } /* We have a choice between copying the dictionary context into the working * context, or referencing the dictionary context from the working context * in-place. We decide here which strategy to use. */ static size_t ZSTD_resetCCtx_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict, const ZSTD_CCtx_params* params, U64 pledgedSrcSize, ZSTD_buffered_policy_e zbuff) { ZSTD_rust_resetCCtxUsingCDictState state; int const cdictStrategy = (int)cdict->matchState.cParams.strategy; int const dedicatedDictSearch = (int)cdict->matchState.dedicatedDictSearch; int const attachDictPref = (int)params->attachDictPref; int const forceWindow = (int)params->forceWindow; int const zbuffValue = (int)zbuff; DEBUGLOG(4, "ZSTD_resetCCtx_usingCDict (pledgedSrcSize=%u)", (unsigned)pledgedSrcSize); state.callbackContext = cctx; state.cdict = cdict; state.params = params; state.cdictStrategy = &cdictStrategy; state.dedicatedDictSearch = &dedicatedDictSearch; state.attachDictPref = &attachDictPref; state.forceWindow = &forceWindow; state.pledgedSrcSize = &pledgedSrcSize; state.zbuff = &zbuffValue; state.attach = ZSTD_rust_resetCCtxUsingCDict_attach; state.copy = ZSTD_rust_resetCCtxUsingCDict_copy; return ZSTD_rust_resetCCtxUsingCDict(&state); } static size_t ZSTD_rust_copyCCtx_reset( void* context, const void* srcCCtx, const ZSTD_frameParameters* fParams, U64 pledgedSrcSize, int zbuff) { ZSTD_CCtx* const dst = (ZSTD_CCtx*)context; const ZSTD_CCtx* const src = (const ZSTD_CCtx*)srcCCtx; ZSTD_CCtx_params params = dst->requestedParams; /* Copy only compression parameters related to tables. */ params.cParams = src->appliedParams.cParams; assert(src->appliedParams.useRowMatchFinder != ZSTD_ps_auto); assert(src->appliedParams.postBlockSplitter != ZSTD_ps_auto); assert(src->appliedParams.ldmParams.enableLdm != ZSTD_ps_auto); params.useRowMatchFinder = src->appliedParams.useRowMatchFinder; params.postBlockSplitter = src->appliedParams.postBlockSplitter; params.ldmParams = src->appliedParams.ldmParams; params.fParams = *fParams; params.maxBlockSize = src->appliedParams.maxBlockSize; { size_t const resetError = ZSTD_resetCCtx_internal( dst, ¶ms, pledgedSrcSize, /* loadedDictSize */ 0, ZSTDcrp_leaveDirty, (ZSTD_buffered_policy_e)zbuff); if (ZSTD_isError(resetError)) return resetError; } assert(dst->appliedParams.cParams.windowLog == src->appliedParams.cParams.windowLog); assert(dst->appliedParams.cParams.strategy == src->appliedParams.cParams.strategy); assert(dst->appliedParams.cParams.hashLog == src->appliedParams.cParams.hashLog); assert(dst->appliedParams.cParams.chainLog == src->appliedParams.cParams.chainLog); assert(dst->blockState.matchState.hashLog3 == src->blockState.matchState.hashLog3); return 0; } static void ZSTD_rust_copyCCtx_mark_tables_dirty(void* context) { ZSTD_CCtx* const dst = (ZSTD_CCtx*)context; ZSTD_cwksp_mark_tables_dirty(&dst->workspace); } static void ZSTD_rust_copyCCtx_mark_tables_clean(void* context) { ZSTD_CCtx* const dst = (ZSTD_CCtx*)context; ZSTD_cwksp_mark_tables_clean(&dst->workspace); } static size_t ZSTD_rust_copyCCtx_internal_callback( void* context, const void* srcCCtx, const ZSTD_frameParameters* fParams, U64 pledgedSrcSize, int zbuff) { ZSTD_rust_copyCCtxInternalState state; ZSTD_CCtx* const dst = (ZSTD_CCtx*)context; const ZSTD_CCtx* const src = (const ZSTD_CCtx*)srcCCtx; int const sourceStage = (int)((const ZSTD_CCtx*)srcCCtx)->stage; U32 const sourceHashLog = src->appliedParams.cParams.hashLog; U32 const sourceChainLog = src->appliedParams.cParams.chainLog; U32 const sourceHashLog3 = src->blockState.matchState.hashLog3; int const sourceStrategy = (int)src->appliedParams.cParams.strategy; int const sourceUseRowMatchFinder = (int)src->appliedParams.useRowMatchFinder; state.callbackContext = context; state.srcCCtx = srcCCtx; state.fParams = fParams; state.pledgedSrcSize = pledgedSrcSize; state.sourceStage = &sourceStage; state.destinationCustomMem = &((ZSTD_CCtx*)context)->customMem; state.sourceCustomMem = &((const ZSTD_CCtx*)srcCCtx)->customMem; state.reset = ZSTD_rust_copyCCtx_reset; state.markTablesDirty = ZSTD_rust_copyCCtx_mark_tables_dirty; state.markTablesClean = ZSTD_rust_copyCCtx_mark_tables_clean; state.destinationHashTable = &dst->blockState.matchState.hashTable; state.sourceHashTable = src->blockState.matchState.hashTable; state.sourceHashLog = &sourceHashLog; state.destinationChainTable = &dst->blockState.matchState.chainTable; state.sourceChainTable = src->blockState.matchState.chainTable; state.sourceChainLog = &sourceChainLog; state.destinationHashTable3 = &dst->blockState.matchState.hashTable3; state.sourceHashTable3 = src->blockState.matchState.hashTable3; state.sourceHashLog3 = &sourceHashLog3; state.sourceStrategy = &sourceStrategy; state.sourceUseRowMatchFinder = &sourceUseRowMatchFinder; state.destinationWindow = &((ZSTD_CCtx*)context)->blockState.matchState.window; state.sourceWindow = &((const ZSTD_CCtx*)srcCCtx)->blockState.matchState.window; state.destinationNextToUpdate = &((ZSTD_CCtx*)context)->blockState.matchState.nextToUpdate; state.sourceNextToUpdate = &((const ZSTD_CCtx*)srcCCtx)->blockState.matchState.nextToUpdate; state.destinationLoadedDictEnd = &((ZSTD_CCtx*)context)->blockState.matchState.loadedDictEnd; state.sourceLoadedDictEnd = &((const ZSTD_CCtx*)srcCCtx)->blockState.matchState.loadedDictEnd; state.destinationDictID = &((ZSTD_CCtx*)context)->dictID; state.sourceDictID = &((const ZSTD_CCtx*)srcCCtx)->dictID; state.destinationDictContentSize = &((ZSTD_CCtx*)context)->dictContentSize; state.sourceDictContentSize = &((const ZSTD_CCtx*)srcCCtx)->dictContentSize; state.destinationBlockState = &((ZSTD_CCtx*)context)->blockState.prevCBlock; state.sourceBlockState = ((const ZSTD_CCtx*)srcCCtx)->blockState.prevCBlock; state.zbuff = zbuff; return ZSTD_rust_copyCCtxInternal(&state); } /*! ZSTD_copyCCtx() : * Duplicate an existing context `srcCCtx` into another one `dstCCtx`. * Only works during stage ZSTDcs_init (i.e. after creation, but before first call to ZSTD_compressContinue()). * pledgedSrcSize==0 means "unknown". * @return : 0, or an error code */ size_t ZSTD_copyCCtx(ZSTD_CCtx* dstCCtx, const ZSTD_CCtx* srcCCtx, unsigned long long pledgedSrcSize) { ZSTD_rust_copyCCtxState state; ZSTD_frameParameters const fParams = { 1 /*content*/, 0 /*checksum*/, 0 /*noDictID*/ }; U64 const pledgedSrcSizeValue = pledgedSrcSize; int const zbuffValue = (int)srcCCtx->bufferedPolicy; ZSTD_STATIC_ASSERT((U32)ZSTDb_buffered==1); state.callbackContext = dstCCtx; state.srcCCtx = srcCCtx; state.fParams = &fParams; state.pledgedSrcSize = &pledgedSrcSizeValue; state.zbuff = &zbuffValue; state.copyInternal = ZSTD_rust_copyCCtx_internal_callback; return ZSTD_rust_copyCCtx(&state); } /*! ZSTD_reduceIndex() : * rescale all indexes to avoid future overflow (indexes are U32) */ static void ZSTD_reduceIndex (ZSTD_MatchState_t* ms, ZSTD_CCtx_params const* params, const U32 reducerValue) { ZSTD_rust_reduceIndexForMatchState( ms->hashTable, params->cParams.hashLog, ms->chainTable, params->cParams.chainLog, ms->hashTable3, ms->hashLog3, params->cParams.strategy, params->useRowMatchFinder, ms->dedicatedDictSearch, reducerValue); } /*-******************************************************* * Block entropic compression *********************************************************/ /* See doc/zstd_compression_format.md for detailed format description */ /* ZSTD_seqToCodes() lives in rust/src/zstd_compress_stats.rs. */ /* ZSTD_useTargetCBlockSize() and ZSTD_blockSplitterEnabled() are Rust-owned * ABI leaves. Their diagnostics remain at the call boundary below. */ /* ZSTD_buildSequencesStatistics() and the ZSTD_entropyCompressSeqStore*() * implementations live in rust/src/zstd_compress_stats.rs. The wrappers * below keep the original signatures and extract the only two * ZSTD_CCtx_params fields those paths read. */ MEM_STATIC size_t ZSTD_entropyCompressSeqStore_internal( void* dst, size_t dstCapacity, const void* literals, size_t litSize, const SeqStore_t* seqStorePtr, const ZSTD_entropyCTables_t* prevEntropy, ZSTD_entropyCTables_t* nextEntropy, const ZSTD_CCtx_params* cctxParams, void* entropyWorkspace, size_t entropyWkspSize, const int bmi2) { return ZSTD_rust_entropyCompressSeqStore_internal( dst, dstCapacity, literals, litSize, seqStorePtr, prevEntropy, nextEntropy, (int)cctxParams->cParams.strategy, ZSTD_literalsCompressionIsDisabled(cctxParams), entropyWorkspace, entropyWkspSize, bmi2); } /* ZSTD_selectBlockCompressor() : * Not static, but internal use only (used by long distance matcher) * assumption : strat is a valid strategy */ ZSTD_BlockCompressor_f ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_ParamSwitch_e useRowMatchFinder, ZSTD_dictMode_e dictMode) { static const ZSTD_BlockCompressor_f blockCompressor[4][ZSTD_STRATEGY_MAX+1] = { { ZSTD_compressBlock_fast /* default for 0 */, ZSTD_compressBlock_fast, ZSTD_COMPRESSBLOCK_DOUBLEFAST, ZSTD_COMPRESSBLOCK_GREEDY, ZSTD_COMPRESSBLOCK_LAZY, ZSTD_COMPRESSBLOCK_LAZY2, ZSTD_COMPRESSBLOCK_BTLAZY2, ZSTD_COMPRESSBLOCK_BTOPT, ZSTD_COMPRESSBLOCK_BTULTRA, ZSTD_COMPRESSBLOCK_BTULTRA2 }, { ZSTD_compressBlock_fast_extDict /* default for 0 */, ZSTD_compressBlock_fast_extDict, ZSTD_COMPRESSBLOCK_DOUBLEFAST_EXTDICT, ZSTD_COMPRESSBLOCK_GREEDY_EXTDICT, ZSTD_COMPRESSBLOCK_LAZY_EXTDICT, ZSTD_COMPRESSBLOCK_LAZY2_EXTDICT, ZSTD_COMPRESSBLOCK_BTLAZY2_EXTDICT, ZSTD_COMPRESSBLOCK_BTOPT_EXTDICT, ZSTD_COMPRESSBLOCK_BTULTRA_EXTDICT, ZSTD_COMPRESSBLOCK_BTULTRA_EXTDICT }, { ZSTD_compressBlock_fast_dictMatchState /* default for 0 */, ZSTD_compressBlock_fast_dictMatchState, ZSTD_COMPRESSBLOCK_DOUBLEFAST_DICTMATCHSTATE, ZSTD_COMPRESSBLOCK_GREEDY_DICTMATCHSTATE, ZSTD_COMPRESSBLOCK_LAZY_DICTMATCHSTATE, ZSTD_COMPRESSBLOCK_LAZY2_DICTMATCHSTATE, ZSTD_COMPRESSBLOCK_BTLAZY2_DICTMATCHSTATE, ZSTD_COMPRESSBLOCK_BTOPT_DICTMATCHSTATE, ZSTD_COMPRESSBLOCK_BTULTRA_DICTMATCHSTATE, ZSTD_COMPRESSBLOCK_BTULTRA_DICTMATCHSTATE }, { NULL /* default for 0 */, NULL, NULL, ZSTD_COMPRESSBLOCK_GREEDY_DEDICATEDDICTSEARCH, ZSTD_COMPRESSBLOCK_LAZY_DEDICATEDDICTSEARCH, ZSTD_COMPRESSBLOCK_LAZY2_DEDICATEDDICTSEARCH, NULL, NULL, NULL, NULL } }; static const ZSTD_BlockCompressor_f rowBasedBlockCompressors[4][3] = { { ZSTD_COMPRESSBLOCK_GREEDY_ROW, ZSTD_COMPRESSBLOCK_LAZY_ROW, ZSTD_COMPRESSBLOCK_LAZY2_ROW }, { ZSTD_COMPRESSBLOCK_GREEDY_EXTDICT_ROW, ZSTD_COMPRESSBLOCK_LAZY_EXTDICT_ROW, ZSTD_COMPRESSBLOCK_LAZY2_EXTDICT_ROW }, { ZSTD_COMPRESSBLOCK_GREEDY_DICTMATCHSTATE_ROW, ZSTD_COMPRESSBLOCK_LAZY_DICTMATCHSTATE_ROW, ZSTD_COMPRESSBLOCK_LAZY2_DICTMATCHSTATE_ROW }, { ZSTD_COMPRESSBLOCK_GREEDY_DEDICATEDDICTSEARCH_ROW, ZSTD_COMPRESSBLOCK_LAZY_DEDICATEDDICTSEARCH_ROW, ZSTD_COMPRESSBLOCK_LAZY2_DEDICATEDDICTSEARCH_ROW } }; ZSTD_rust_selectBlockCompressorState state; ZSTD_BlockCompressor_f selectedCompressor = NULL; size_t selectionResult; ZSTD_STATIC_ASSERT((unsigned)ZSTD_fast == 1); assert(ZSTD_cParam_withinBounds(ZSTD_c_strategy, (int)strat)); DEBUGLOG(5, "Selected block compressor: dictMode=%d strat=%d rowMatchfinder=%d", (int)dictMode, (int)strat, (int)useRowMatchFinder); state.blockCompressors = &blockCompressor[0][0]; state.rowBlockCompressors = &rowBasedBlockCompressors[0][0]; state.selectedCompressor = &selectedCompressor; selectionResult = ZSTD_rust_selectBlockCompressor( &state, (int)strat, (int)useRowMatchFinder, (int)dictMode); assert(!ERR_isError(selectionResult)); assert(selectedCompressor != NULL); return selectedCompressor; } static size_t ZSTD_rust_externalSequenceProducer_transfer( void* context, ZSTD_SequencePosition* seqPos, const ZSTD_Sequence* inSeqs, size_t inSeqsSize, const void* src, size_t blockSize) { ZSTD_CCtx* const zc = (ZSTD_CCtx*)context; U32 dictSize; if (zc->cdict) { dictSize = (U32)zc->cdict->dictContentSize; } else if (zc->prefixDict.dict) { dictSize = (U32)zc->prefixDict.dictSize; } else { dictSize = 0; } return ZSTD_rust_transferSequencesWBlockDelim( &zc->seqStore, seqPos, inSeqs, inSeqsSize, (const BYTE*)src, blockSize, (int)zc->appliedParams.searchForExternalRepcodes, zc->blockState.prevCBlock->rep, zc->blockState.nextCBlock->rep, dictSize, zc->appliedParams.validateSequences, zc->appliedParams.cParams.minMatch, zc->appliedParams.cParams.windowLog, ZSTD_hasExtSeqProd(&zc->appliedParams)); } static void ZSTD_rust_buildSeqStore_skipSmallBlock(void* context, size_t srcSize) { ZSTD_CCtx* const zc = (ZSTD_CCtx*)context; if (zc->appliedParams.cParams.strategy >= ZSTD_btopt) { ZSTD_ldm_skipRawSeqStoreBytes(&zc->externSeqStore, srcSize); } else { ZSTD_ldm_skipSequences(&zc->externSeqStore, srcSize, zc->appliedParams.cParams.minMatch); } } static void ZSTD_rust_buildSeqStore_prepareMatchState(void* context, const void* src, size_t srcSize) { ZSTD_CCtx* const zc = (ZSTD_CCtx*)context; ZSTD_MatchState_t* const ms = &zc->blockState.matchState; DEBUGLOG(5, "ZSTD_buildSeqStore (srcSize=%zu)", srcSize); (void)srcSize; /* Assert that we have correctly flushed the ctx params into the ms's copy. */ ZSTD_rust_params_assertEqualCParams(zc->appliedParams.cParams, ms->cParams); /* required for optimal parser to read stats from dictionary */ ms->opt.symbolCosts = &zc->blockState.prevCBlock->entropy; /* tell the optimal parser how we expect to compress literals */ ms->opt.literalCompressionMode = zc->appliedParams.literalCompressionMode; /* a gap between an attached dict and the current window is not safe, * they must remain adjacent, and when that stops being the case, the * dict must be unset */ assert(ms->dictMatchState == NULL || ms->loadedDictEnd == ms->window.dictLimit); /* limited update after a very long match */ { const BYTE* const base = ms->window.base; const BYTE* const istart = (const BYTE*)src; const U32 curr = (U32)(istart-base); if (sizeof(ptrdiff_t)==8) assert(istart - base < (ptrdiff_t)(U32)(-1)); ms->nextToUpdate = ZSTD_rust_limitNextToUpdate(curr, ms->nextToUpdate); } } static size_t ZSTD_rust_buildSeqStore_compressExternalSequences( void* context, SeqStore_t* seqStore, U32 nextRep[ZSTD_REP_NUM], const void* src, size_t srcSize) { ZSTD_CCtx* const zc = (ZSTD_CCtx*)context; ZSTD_MatchState_t* const ms = &zc->blockState.matchState; size_t lastLLSize; assert(zc->appliedParams.ldmParams.enableLdm == ZSTD_ps_disable); lastLLSize = ZSTD_ldm_blockCompress( &zc->externSeqStore, ms, seqStore, nextRep, zc->appliedParams.useRowMatchFinder, src, srcSize); assert(zc->externSeqStore.pos <= zc->externSeqStore.size); return lastLLSize; } static size_t ZSTD_rust_buildSeqStore_compressLdm( void* context, SeqStore_t* seqStore, U32 nextRep[ZSTD_REP_NUM], const void* src, size_t srcSize) { ZSTD_CCtx* const zc = (ZSTD_CCtx*)context; ZSTD_MatchState_t* const ms = &zc->blockState.matchState; RawSeqStore_t ldmSeqStore = kNullRawSeqStore; size_t result; ldmSeqStore.seq = zc->ldmSequences; ldmSeqStore.capacity = zc->maxNbLdmSequences; result = ZSTD_ldm_generateSequences( &zc->ldmState, &ldmSeqStore, &zc->appliedParams.ldmParams, src, srcSize); if (ERR_isError(result)) return result; result = ZSTD_ldm_blockCompress( &ldmSeqStore, ms, seqStore, nextRep, zc->appliedParams.useRowMatchFinder, src, srcSize); assert(ldmSeqStore.pos == ldmSeqStore.size); return result; } static size_t ZSTD_rust_buildSeqStore_tryExternalSequenceProducer( void* context, const void* src, size_t srcSize, int* seqStoreComplete, int* allowFallback) { ZSTD_CCtx* const zc = (ZSTD_CCtx*)context; size_t nbExternalSeqs = 0; ZSTD_rust_externalSequenceProducerState state; size_t const windowSize = (size_t)1 << zc->appliedParams.cParams.windowLog; assert(zc->extSeqBufCapacity >= ZSTD_sequenceBound(srcSize)); assert(zc->appliedParams.extSeqProdFunc != NULL); state.callbackContext = zc; state.producerState = zc->appliedParams.extSeqProdState; state.producer = zc->appliedParams.extSeqProdFunc; state.extSeqBuf = zc->extSeqBuf; state.extSeqBufCapacity = &zc->extSeqBufCapacity; state.src = src; state.srcSize = &srcSize; state.compressionLevel = &zc->appliedParams.compressionLevel; state.windowSize = &windowSize; state.transfer = ZSTD_rust_externalSequenceProducer_transfer; state.externalSeqCount = &nbExternalSeqs; state.seqStoreComplete = seqStoreComplete; state.allowFallback = allowFallback; { size_t const producerResult = ZSTD_rust_tryExternalSequenceProducer(&state); if (*seqStoreComplete) { DEBUGLOG(5, "Copied %lu sequences from external sequence producer to internal seqStore.", (unsigned long)nbExternalSeqs); } return producerResult; } } static size_t ZSTD_rust_buildSeqStore_compressInternal( void* context, SeqStore_t* seqStore, U32 nextRep[ZSTD_REP_NUM], const void* src, size_t srcSize) { ZSTD_CCtx* const zc = (ZSTD_CCtx*)context; ZSTD_MatchState_t* const ms = &zc->blockState.matchState; ZSTD_BlockCompressor_f const blockCompressor = ZSTD_selectBlockCompressor( zc->appliedParams.cParams.strategy, zc->appliedParams.useRowMatchFinder, ZSTD_matchState_dictMode(ms)); return blockCompressor(ms, seqStore, nextRep, src, srcSize); } static void ZSTD_rust_buildSeqStore_clearLdmSeqStore(void* context) { ZSTD_CCtx* const zc = (ZSTD_CCtx*)context; zc->blockState.matchState.ldmSeqStore = NULL; } static void ZSTD_initBuildSeqStoreState( ZSTD_CCtx* zc, ZSTD_rust_buildSeqStoreState* state) { state->seqStore = &zc->seqStore; state->prevCBlock = &zc->blockState.prevCBlock; state->nextCBlock = &zc->blockState.nextCBlock; state->callbackContext = zc; state->minMatch = zc->appliedParams.cParams.minMatch; #if DEBUGLEVEL >= 1 state->validateSeqStore = 1; #else state->validateSeqStore = 0; #endif state->skipSmallBlock = ZSTD_rust_buildSeqStore_skipSmallBlock; state->prepareMatchState = ZSTD_rust_buildSeqStore_prepareMatchState; state->hasExternalSequences = zc->externSeqStore.pos < zc->externSeqStore.size; state->ldmEnabled = zc->appliedParams.ldmParams.enableLdm == ZSTD_ps_enable; state->hasExternalSequenceProducer = ZSTD_hasExtSeqProd(&zc->appliedParams); state->enableMatchFinderFallback = zc->appliedParams.enableMatchFinderFallback; state->compressExternalSequences = ZSTD_rust_buildSeqStore_compressExternalSequences; state->compressLdm = ZSTD_rust_buildSeqStore_compressLdm; state->tryExternalSequenceProducer = ZSTD_rust_buildSeqStore_tryExternalSequenceProducer; state->compressInternal = ZSTD_rust_buildSeqStore_compressInternal; state->clearLdmSeqStore = ZSTD_rust_buildSeqStore_clearLdmSeqStore; } /* ZSTD_sequenceBound() lives in rust/src/zstd_compress_api.rs. */ typedef size_t (*ZSTD_rust_generateSequencesGetParameter_f)( void* context, int param, int* value); typedef void* (*ZSTD_rust_generateSequencesAllocate_f)( void* context, size_t size); typedef void (*ZSTD_rust_generateSequencesFree_f)( void* context, void* pointer); typedef size_t (*ZSTD_rust_generateSequencesSetCollector_f)( void* context, ZSTD_Sequence* outSeqs, size_t outSeqsSize); typedef size_t (*ZSTD_rust_generateSequencesCompress2_f)( void* context, void* dst, size_t dstCapacity, const void* src, size_t srcSize); typedef size_t (*ZSTD_rust_generateSequencesGetCount_f)(void* context); typedef struct { void* callbackContext; ZSTD_rust_generateSequencesGetParameter_f getParameter; ZSTD_rust_generateSequencesAllocate_f allocate; ZSTD_rust_generateSequencesFree_f free; ZSTD_rust_generateSequencesSetCollector_f setCollector; ZSTD_rust_generateSequencesCompress2_f compress2; ZSTD_rust_generateSequencesGetCount_f getCount; } ZSTD_rust_generateSequencesState; typedef char ZSTD_rust_generate_sequences_state_layout[ (offsetof(ZSTD_rust_generateSequencesState, callbackContext) == 0 && offsetof(ZSTD_rust_generateSequencesState, getParameter) == sizeof(void*) && offsetof(ZSTD_rust_generateSequencesState, allocate) == 2 * sizeof(void*) && offsetof(ZSTD_rust_generateSequencesState, free) == 3 * sizeof(void*) && offsetof(ZSTD_rust_generateSequencesState, setCollector) == 4 * sizeof(void*) && offsetof(ZSTD_rust_generateSequencesState, compress2) == 5 * sizeof(void*) && offsetof(ZSTD_rust_generateSequencesState, getCount) == 6 * sizeof(void*) && sizeof(ZSTD_rust_generateSequencesState) == 7 * sizeof(void*)) ? 1 : -1]; size_t ZSTD_rust_generateSequences( const ZSTD_rust_generateSequencesState* state, ZSTD_Sequence* outSeqs, size_t outSeqsSize, const void* src, size_t srcSize); static size_t ZSTD_rust_generateSequences_getParameter( void* context, int param, int* value) { return ZSTD_CCtx_getParameter( (const ZSTD_CCtx*)context, (ZSTD_cParameter)param, value); } static void* ZSTD_rust_generateSequences_allocate(void* context, size_t size) { (void)context; return ZSTD_customMalloc(size, ZSTD_defaultCMem); } static void ZSTD_rust_generateSequences_free(void* context, void* pointer) { (void)context; ZSTD_customFree(pointer, ZSTD_defaultCMem); } static size_t ZSTD_rust_generateSequences_setCollector( void* context, ZSTD_Sequence* outSeqs, size_t outSeqsSize) { ZSTD_CCtx* const zc = (ZSTD_CCtx*)context; zc->seqCollector.collectSequences = 1; zc->seqCollector.seqStart = outSeqs; zc->seqCollector.seqIndex = 0; zc->seqCollector.maxSequences = outSeqsSize; return 0; } static size_t ZSTD_rust_generateSequences_compress2( void* context, void* dst, size_t dstCapacity, const void* src, size_t srcSize) { return ZSTD_compress2((ZSTD_CCtx*)context, dst, dstCapacity, src, srcSize); } static size_t ZSTD_rust_generateSequences_getCount(void* context) { return ((const ZSTD_CCtx*)context)->seqCollector.seqIndex; } size_t ZSTD_generateSequences(ZSTD_CCtx* zc, ZSTD_Sequence* outSeqs, size_t outSeqsSize, const void* src, size_t srcSize) { ZSTD_rust_generateSequencesState const state = { zc, ZSTD_rust_generateSequences_getParameter, ZSTD_rust_generateSequences_allocate, ZSTD_rust_generateSequences_free, ZSTD_rust_generateSequences_setCollector, ZSTD_rust_generateSequences_compress2, ZSTD_rust_generateSequences_getCount }; return ZSTD_rust_generateSequences( &state, outSeqs, outSeqsSize, src, srcSize); } /* ZSTD_mergeBlockDelimiters() lives in rust/src/zstd_compress_api.rs. */ /** ZSTD_buildBlockEntropyStats() : * Builds entropy for the block. * Requires workspace size ENTROPY_WORKSPACE_SIZE * @return : 0 on success, or an error code * Note : also employed in superblock * * The implementation, together with its literals/sequences/dummy helpers, * lives in rust/src/zstd_compress_stats.rs. */ size_t ZSTD_buildBlockEntropyStats( const SeqStore_t* seqStorePtr, const ZSTD_entropyCTables_t* prevEntropy, ZSTD_entropyCTables_t* nextEntropy, const ZSTD_CCtx_params* cctxParams, ZSTD_entropyCTablesMetadata_t* entropyMetadata, void* workspace, size_t wkspSize) { return ZSTD_rust_buildBlockEntropyStats( seqStorePtr, prevEntropy, nextEntropy, (int)cctxParams->cParams.strategy, ZSTD_literalsCompressionIsDisabled(cctxParams), entropyMetadata, workspace, wkspSize); } typedef struct { ZSTD_MatchState_t* matchState; ZSTD_cwksp* workspace; const ZSTD_CCtx_params* params; } ZSTD_rust_overflowCorrectContext; struct ZSTD_rust_compressContinueBlockState_s { const ZSTD_rust_buildSeqStoreState* buildSeqStoreState; const ZSTD_rust_blockInternalState* blockInternalState; }; typedef char ZSTD_rust_compress_continue_block_state_layout[ (sizeof(ZSTD_rust_compressContinueBlockState) == 2 * sizeof(void*)) ? 1 : -1]; /* All continue entry points use this synchronous stack projection. The * private CCtx and match-state layouts remain behind the direct field * projections and context-sensitive leaf callbacks. */ typedef struct { ZSTD_rust_compressContinueState state; ZSTD_rust_compressContinueWindowState windowState; ZSTD_rust_compressContinueWindowState ldmWindowState; ZSTD_rust_frameChunkState frameChunkState; ZSTD_rust_frameChunkPrepareState frameChunkPrepareState; ZSTD_rust_frameChunkClampState frameChunkClampState; ZSTD_rust_overflowCorrectContext overflowContext; ZSTD_rust_overflowCorrectState overflowState; ZSTD_rust_buildSeqStoreState buildSeqStoreState; ZSTD_rust_blockInternalState blockInternalState; ZSTD_rust_compressContinueBlockState blockState; ZSTD_rust_targetCBlockSizeState targetBlockState; ZSTD_rust_deriveBlockSplitsState deriveBlockSplitsState; ZSTD_rust_splitBlockState splitBlockState; } ZSTD_rust_compressContinueContext; static int ZSTD_rust_overflowCorrect_need( void* context, const void* src, const void* srcEnd) { ZSTD_rust_overflowCorrectContext const* const state = (const ZSTD_rust_overflowCorrectContext*)context; U32 const cycleLog = ZSTD_cycleLog( state->params->cParams.chainLog, state->params->cParams.strategy); U32 const maxDist = (U32)1 << state->params->cParams.windowLog; return (int)ZSTD_window_needOverflowCorrection( state->matchState->window, cycleLog, maxDist, state->matchState->loadedDictEnd, src, srcEnd); } static U32 ZSTD_rust_overflowCorrect_correct(void* context, const void* src) { ZSTD_rust_overflowCorrectContext const* const state = (const ZSTD_rust_overflowCorrectContext*)context; U32 const cycleLog = ZSTD_cycleLog( state->params->cParams.chainLog, state->params->cParams.strategy); U32 const maxDist = (U32)1 << state->params->cParams.windowLog; ZSTD_rust_windowOverflowState windowState = { &state->matchState->window.base, &state->matchState->window.dictBase, &state->matchState->window.dictLimit, &state->matchState->window.lowLimit, &state->matchState->window.nbOverflowCorrections, }; U32 const curr = (U32)((BYTE const*)src - state->matchState->window.base); return ZSTD_rust_windowCorrectOverflowState( &windowState, curr, cycleLog, maxDist, ZSTD_WINDOW_OVERFLOW_CORRECT_FREQUENTLY); } static void ZSTD_rust_overflowCorrect_markTablesDirty(void* context) { ZSTD_rust_overflowCorrectContext const* const state = (const ZSTD_rust_overflowCorrectContext*)context; ZSTD_cwksp_mark_tables_dirty(state->workspace); } static void ZSTD_rust_overflowCorrect_reduceIndex(void* context, U32 correction) { ZSTD_rust_overflowCorrectContext const* const state = (const ZSTD_rust_overflowCorrectContext*)context; ZSTD_reduceIndex(state->matchState, state->params, correction); } static void ZSTD_rust_overflowCorrect_markTablesClean(void* context) { ZSTD_rust_overflowCorrectContext const* const state = (const ZSTD_rust_overflowCorrectContext*)context; ZSTD_cwksp_mark_tables_clean(state->workspace); } static void ZSTD_overflowCorrectIfNeeded(ZSTD_MatchState_t* ms, ZSTD_cwksp* ws, ZSTD_CCtx_params const* params, void const* ip, void const* iend) { ZSTD_rust_overflowCorrectContext context; ZSTD_rust_overflowCorrectState state; ZSTD_STATIC_ASSERT(ZSTD_CHAINLOG_MAX <= 30); ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX_32 <= 30); ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX <= 31); context.matchState = ms; context.workspace = ws; context.params = params; state.callbackContext = &context; state.nextToUpdate = &ms->nextToUpdate; state.needCorrection = ZSTD_rust_overflowCorrect_need; state.correctOverflow = ZSTD_rust_overflowCorrect_correct; state.markTablesDirty = ZSTD_rust_overflowCorrect_markTablesDirty; state.reduceIndex = ZSTD_rust_overflowCorrect_reduceIndex; state.markTablesClean = ZSTD_rust_overflowCorrect_markTablesClean; state.loadedDictEnd = &ms->loadedDictEnd; state.dictMatchState = &ms->dictMatchState; ZSTD_rust_overflowCorrectIfNeeded(&state, ip, iend); } #include "zstd_preSplit.h" static void ZSTD_rust_frameChunk_correctOverflow(void* context, const void* src, size_t blockSize) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; ZSTD_MatchState_t* const ms = &cctx->blockState.matchState; ZSTD_overflowCorrectIfNeeded( ms, &cctx->workspace, &cctx->appliedParams, src, (const BYTE*)src + blockSize); } static void ZSTD_rust_frameChunk_checkDictValidity(void* context, const void* src, size_t blockSize, U32 maxDist) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; ZSTD_MatchState_t* const ms = &cctx->blockState.matchState; ZSTD_checkDictValidity( &ms->window, (const BYTE*)src + blockSize, maxDist, &ms->loadedDictEnd, &ms->dictMatchState); } static void ZSTD_rust_frameChunk_enforceMaxDist(void* context, const void* src, size_t blockSize, U32 maxDist) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; ZSTD_MatchState_t* const ms = &cctx->blockState.matchState; ZSTD_window_enforceMaxDist( &ms->window, src, maxDist, &ms->loadedDictEnd, &ms->dictMatchState); (void)blockSize; } static void ZSTD_compressContinue_prepare( ZSTD_CCtx* cctx, size_t blockSizeMax, int checkBlockSize, ZSTD_rust_compressContinueContext* context) { ZSTD_MatchState_t* const ms = &cctx->blockState.matchState; ZSTD_window_t* const window = &ms->window; ZSTD_window_t* const ldmWindow = &cctx->ldmState.window; context->windowState.nextSrc = &window->nextSrc; context->windowState.base = &window->base; context->windowState.dictBase = &window->dictBase; context->windowState.dictLimit = &window->dictLimit; context->windowState.lowLimit = &window->lowLimit; context->windowState.forceNonContiguous = &ms->forceNonContiguous; context->windowState.nextToUpdate = &ms->nextToUpdate; context->ldmWindowState.nextSrc = &ldmWindow->nextSrc; context->ldmWindowState.base = &ldmWindow->base; context->ldmWindowState.dictBase = &ldmWindow->dictBase; context->ldmWindowState.dictLimit = &ldmWindow->dictLimit; context->ldmWindowState.lowLimit = &ldmWindow->lowLimit; context->ldmWindowState.forceNonContiguous = NULL; context->ldmWindowState.nextToUpdate = NULL; context->frameChunkPrepareState.callbackContext = cctx; context->frameChunkPrepareState.maxDist = (U32)1 << cctx->appliedParams.cParams.windowLog; context->frameChunkPrepareState.correctOverflow = ZSTD_rust_frameChunk_correctOverflow; context->frameChunkPrepareState.checkDictValidity = ZSTD_rust_frameChunk_checkDictValidity; context->frameChunkPrepareState.enforceMaxDist = ZSTD_rust_frameChunk_enforceMaxDist; context->frameChunkClampState.nextToUpdate = &ms->nextToUpdate; context->frameChunkClampState.lowLimit = &ms->window.lowLimit; context->frameChunkPrepareState.clampState = &context->frameChunkClampState; context->frameChunkState.callbackContext = cctx; context->frameChunkState.tmpWorkspace = cctx->tmpWorkspace; context->frameChunkState.checksumState = &cctx->xxhState; context->frameChunkState.isFirstBlock = &cctx->isFirstBlock; context->frameChunkState.stage = &cctx->stage; context->frameChunkState.tmpWkspSize = cctx->tmpWkspSize; context->frameChunkState.blockSizeMax = cctx->blockSizeMax; context->frameChunkState.savings = (S64)cctx->consumedSrcSize - (S64)cctx->producedCSize; context->frameChunkState.preBlockSplitterLevel = cctx->appliedParams.preBlockSplitter_level; context->frameChunkState.strategy = (int)cctx->appliedParams.cParams.strategy; DEBUGLOG(5, "ZSTD_useTargetCBlockSize (targetCBlockSize=%zu)", cctx->appliedParams.targetCBlockSize); context->frameChunkState.useTargetCBlockSize = ZSTD_useTargetCBlockSize(&cctx->appliedParams); DEBUGLOG(5, "ZSTD_blockSplitterEnabled (postBlockSplitter=%d)", cctx->appliedParams.postBlockSplitter); context->frameChunkState.blockSplitterEnabled = ZSTD_blockSplitterEnabled(&cctx->appliedParams); context->frameChunkState.checksumFlag = cctx->appliedParams.fParams.checksumFlag; context->frameChunkState.endingStage = (int)ZSTDcs_ending; context->frameChunkState.prepareState = &context->frameChunkPrepareState; context->frameChunkState.compressTarget = NULL; context->frameChunkState.compressSplit = NULL; context->frameChunkState.compressInternal = NULL; context->frameChunkState.compressTargetState = &context->targetBlockState; context->frameChunkState.compressSplitState = &context->splitBlockState; context->frameChunkState.deriveBlockSplitsState = &context->deriveBlockSplitsState; ZSTD_initBuildSeqStoreState(cctx, &context->buildSeqStoreState); context->blockInternalState.seqStore = &cctx->seqStore; context->blockInternalState.prevCBlock = &cctx->blockState.prevCBlock; context->blockInternalState.nextCBlock = &cctx->blockState.nextCBlock; context->blockInternalState.tmpWorkspace = cctx->tmpWorkspace; context->blockInternalState.tmpWkspSize = cctx->tmpWkspSize; context->blockInternalState.seqCollector = &cctx->seqCollector; context->blockInternalState.strategy = (int)cctx->appliedParams.cParams.strategy; context->blockInternalState.disableLiteralCompression = ZSTD_literalsCompressionIsDisabled(&cctx->appliedParams); context->blockInternalState.bmi2 = cctx->bmi2; context->blockInternalState.isFirstBlock = cctx->isFirstBlock; context->blockState.buildSeqStoreState = &context->buildSeqStoreState; context->blockState.blockInternalState = &context->blockInternalState; context->frameChunkState.compressInternalState = &context->blockState; context->targetBlockState.seqStore = &cctx->seqStore; context->targetBlockState.prevCBlock = &cctx->blockState.prevCBlock; context->targetBlockState.nextCBlock = &cctx->blockState.nextCBlock; context->targetBlockState.tmpWorkspace = cctx->tmpWorkspace; context->targetBlockState.tmpWkspSize = cctx->tmpWkspSize; context->targetBlockState.strategy = (int)cctx->appliedParams.cParams.strategy; context->targetBlockState.disableLiteralCompression = ZSTD_literalsCompressionIsDisabled(&cctx->appliedParams); context->targetBlockState.bmi2 = cctx->bmi2; context->targetBlockState.windowLog = cctx->appliedParams.cParams.windowLog; context->targetBlockState.targetCBlockSize = cctx->appliedParams.targetCBlockSize; context->targetBlockState.isFirstBlock = cctx->isFirstBlock; context->deriveBlockSplitsState.originalSeqStore = &cctx->seqStore; context->deriveBlockSplitsState.fullSeqStoreChunk = &cctx->blockSplitCtx.fullSeqStoreChunk; context->deriveBlockSplitsState.firstHalfSeqStore = &cctx->blockSplitCtx.firstHalfSeqStore; context->deriveBlockSplitsState.secondHalfSeqStore = &cctx->blockSplitCtx.secondHalfSeqStore; context->deriveBlockSplitsState.prevCBlock = &cctx->blockState.prevCBlock; context->deriveBlockSplitsState.nextCBlock = &cctx->blockState.nextCBlock; context->deriveBlockSplitsState.entropyMetadata = &cctx->blockSplitCtx.entropyMetadata; context->deriveBlockSplitsState.workspace = cctx->tmpWorkspace; context->deriveBlockSplitsState.workspaceSize = cctx->tmpWkspSize; context->deriveBlockSplitsState.strategy = (int)cctx->appliedParams.cParams.strategy; context->deriveBlockSplitsState.disableLiteralCompression = ZSTD_literalsCompressionIsDisabled(&cctx->appliedParams); context->splitBlockState.seqStore = &cctx->seqStore; context->splitBlockState.partitions = cctx->blockSplitCtx.partitions; context->splitBlockState.nextSeqStore = &cctx->blockSplitCtx.nextSeqStore; context->splitBlockState.currSeqStore = &cctx->blockSplitCtx.currSeqStore; context->splitBlockState.prevCBlock = &cctx->blockState.prevCBlock; context->splitBlockState.nextCBlock = &cctx->blockState.nextCBlock; context->splitBlockState.tmpWorkspace = cctx->tmpWorkspace; context->splitBlockState.tmpWkspSize = cctx->tmpWkspSize; context->splitBlockState.seqCollector = &cctx->seqCollector; context->splitBlockState.blockSizeMax = cctx->blockSizeMax; context->splitBlockState.strategy = (int)cctx->appliedParams.cParams.strategy; context->splitBlockState.disableLiteralCompression = ZSTD_literalsCompressionIsDisabled(&cctx->appliedParams); context->splitBlockState.bmi2 = cctx->bmi2; context->splitBlockState.isFirstBlock = cctx->isFirstBlock; context->overflowContext.matchState = ms; context->overflowContext.workspace = &cctx->workspace; context->overflowContext.params = &cctx->appliedParams; context->overflowState.callbackContext = &context->overflowContext; context->overflowState.nextToUpdate = &ms->nextToUpdate; context->overflowState.needCorrection = ZSTD_rust_overflowCorrect_need; context->overflowState.correctOverflow = ZSTD_rust_overflowCorrect_correct; context->overflowState.markTablesDirty = ZSTD_rust_overflowCorrect_markTablesDirty; context->overflowState.reduceIndex = ZSTD_rust_overflowCorrect_reduceIndex; context->overflowState.markTablesClean = ZSTD_rust_overflowCorrect_markTablesClean; context->overflowState.loadedDictEnd = &ms->loadedDictEnd; context->overflowState.dictMatchState = &ms->dictMatchState; context->state.callbackContext = &context->blockState; context->state.windowState = &context->windowState; context->state.ldmWindowState = &context->ldmWindowState; context->state.overflowState = &context->overflowState; context->state.frameChunkState = &context->frameChunkState; context->state.compressBlock = ZSTD_rust_compressContinueBlock; context->state.stage = &cctx->stage; context->state.consumedSrcSize = &cctx->consumedSrcSize; context->state.producedCSize = &cctx->producedCSize; context->state.pledgedSrcSizePlusOne = cctx->pledgedSrcSizePlusOne; context->state.blockSizeMax = blockSizeMax; context->state.checkBlockSize = checkBlockSize; context->state.noDictIDFlag = cctx->appliedParams.fParams.noDictIDFlag; context->state.checksumFlag = cctx->appliedParams.fParams.checksumFlag; context->state.contentSizeFlag = cctx->appliedParams.fParams.contentSizeFlag; context->state.format = (int)cctx->appliedParams.format; context->state.windowLog = cctx->appliedParams.cParams.windowLog; context->state.dictID = cctx->dictID; context->state.ldmEnabled = cctx->appliedParams.ldmParams.enableLdm == ZSTD_ps_enable; } static size_t ZSTD_compressContinue_dispatch( ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, U32 frame, U32 lastFrameChunk, size_t blockSizeMax, int checkBlockSize) { ZSTD_rust_compressContinueContext context; ZSTD_compressContinue_prepare(cctx, blockSizeMax, checkBlockSize, &context); return ZSTD_rust_compressContinue( &context.state, dst, dstCapacity, src, srcSize, frame, lastFrameChunk); } void ZSTD_referenceExternalSequences(ZSTD_CCtx* cctx, rawSeq* seq, size_t nbSeq) { assert(cctx->stage == ZSTDcs_init); assert(nbSeq == 0 || cctx->appliedParams.ldmParams.enableLdm != ZSTD_ps_enable); { ZSTD_rust_externalSequenceStoreState state; state.seq = &cctx->externSeqStore.seq; state.pos = &cctx->externSeqStore.pos; state.posInSequence = &cctx->externSeqStore.posInSequence; state.size = &cctx->externSeqStore.size; state.capacity = &cctx->externSeqStore.capacity; ZSTD_rust_referenceExternalSequences(&state, seq, nbSeq); } } size_t ZSTD_compressContinue_public(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize) { DEBUGLOG(5, "ZSTD_compressContinue (srcSize=%u)", (unsigned)srcSize); return ZSTD_compressContinue_dispatch( cctx, dst, dstCapacity, src, srcSize, 1 /* frame mode */, 0 /* last chunk */, cctx->blockSizeMax, 0 /* block size already selected */); } /* NOTE: Must just wrap ZSTD_compressContinue_public() */ size_t ZSTD_compressContinue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize) { return ZSTD_compressContinue_public(cctx, dst, dstCapacity, src, srcSize); } static size_t ZSTD_getBlockSize_deprecated(const ZSTD_CCtx* cctx) { ZSTD_compressionParameters const cParams = cctx->appliedParams.cParams; assert(!ZSTD_checkCParams(cParams)); return ZSTD_rust_params_getBlockSize(cctx->appliedParams.maxBlockSize, cParams.windowLog); } /* NOTE: Must just wrap ZSTD_getBlockSize_deprecated() */ size_t ZSTD_getBlockSize(const ZSTD_CCtx* cctx) { return ZSTD_getBlockSize_deprecated(cctx); } /* NOTE: Must just wrap ZSTD_compressBlock_deprecated() */ size_t ZSTD_compressBlock_deprecated(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize) { DEBUGLOG(5, "ZSTD_compressBlock: srcSize = %u", (unsigned)srcSize); return ZSTD_compressContinue_dispatch( cctx, dst, dstCapacity, src, srcSize, 0 /* block mode */, 0 /* last chunk */, ZSTD_getBlockSize_deprecated(cctx), 1 /* validate block size */); } /* NOTE: Must just wrap ZSTD_compressBlock_deprecated() */ size_t ZSTD_compressBlock(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize) { return ZSTD_compressBlock_deprecated(cctx, dst, dstCapacity, src, srcSize); } typedef struct { ZSTD_MatchState_t* matchState; ldmState_t* ldmState; ZSTD_cwksp* workspace; const ZSTD_CCtx_params* params; } ZSTD_loadDictionaryContent_context; static void ZSTD_loadDictionaryContent_assertCParams(void* opaque) { ZSTD_loadDictionaryContent_context const* const context = (const ZSTD_loadDictionaryContent_context*)opaque; ZSTD_rust_params_assertEqualCParams(context->params->cParams, context->matchState->cParams); } static void ZSTD_loadDictionaryContent_assertWindowEmpty(void* opaque, int ldm) { ZSTD_loadDictionaryContent_context const* const context = (const ZSTD_loadDictionaryContent_context*)opaque; if (ldm) { assert(context->ldmState != NULL); assert(ZSTD_window_isEmpty(context->ldmState->window)); } else { assert(ZSTD_window_isEmpty(context->matchState->window)); } } static void ZSTD_loadDictionaryContent_windowUpdate( void* opaque, int ldm, const void* src, size_t srcSize) { ZSTD_loadDictionaryContent_context const* const context = (const ZSTD_loadDictionaryContent_context*)opaque; if (ldm) { assert(context->ldmState != NULL); ZSTD_window_update(&context->ldmState->window, src, srcSize, /* forceNonContiguous */ 0); } else { ZSTD_window_update(&context->matchState->window, src, srcSize, /* forceNonContiguous */ 0); } } static void ZSTD_loadDictionaryContent_fillLdm( void* opaque, const void* ip, const void* iend) { ZSTD_loadDictionaryContent_context const* const context = (const ZSTD_loadDictionaryContent_context*)opaque; assert(context->ldmState != NULL); ZSTD_ldm_fillHashTable(context->ldmState, (const BYTE*)ip, (const BYTE*)iend, &context->params->ldmParams); DEBUGLOG(4, "ZSTD_loadDictionaryContent: ZSTD_ldm_fillHashTable completes"); } static void ZSTD_loadDictionaryContent_overflowCorrect( void* opaque, const void* ip, const void* iend) { ZSTD_loadDictionaryContent_context const* const context = (const ZSTD_loadDictionaryContent_context*)opaque; ZSTD_overflowCorrectIfNeeded(context->matchState, context->workspace, context->params, ip, iend); } static void ZSTD_loadDictionaryContent_loadDedicated(void* opaque, const void* ip) { ZSTD_loadDictionaryContent_context const* const context = (const ZSTD_loadDictionaryContent_context*)opaque; #if !defined(ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR) \ || !defined(ZSTD_EXCLUDE_LAZY_BLOCK_COMPRESSOR) \ || !defined(ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR) assert(context->matchState->chainTable != NULL); ZSTD_dedicatedDictSearch_lazy_loadDictionary(context->matchState, (const BYTE*)ip); #else (void)context; (void)ip; assert(0); /* shouldn't be called: cparams should've been adjusted. */ #endif } static void ZSTD_loadDictionaryContent_loadRow(void* opaque, const void* ip) { ZSTD_loadDictionaryContent_context const* const context = (const ZSTD_loadDictionaryContent_context*)opaque; #if !defined(ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR) \ || !defined(ZSTD_EXCLUDE_LAZY_BLOCK_COMPRESSOR) \ || !defined(ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR) size_t const tagTableSize = ((size_t)1 << context->params->cParams.hashLog); ZSTD_memset(context->matchState->tagTable, 0, tagTableSize); ZSTD_row_update(context->matchState, (const BYTE*)ip); DEBUGLOG(4, "Using row-based hash table for lazy dict"); #else (void)context; (void)ip; assert(0); /* shouldn't be called: cparams should've been adjusted. */ #endif } static void ZSTD_loadDictionaryContent_loadChain(void* opaque, const void* ip) { ZSTD_loadDictionaryContent_context const* const context = (const ZSTD_loadDictionaryContent_context*)opaque; #if !defined(ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR) \ || !defined(ZSTD_EXCLUDE_LAZY_BLOCK_COMPRESSOR) \ || !defined(ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR) ZSTD_insertAndFindFirstIndex(context->matchState, (const BYTE*)ip); DEBUGLOG(4, "Using chain-based hash table for lazy dict"); #else (void)context; (void)ip; assert(0); /* shouldn't be called: cparams should've been adjusted. */ #endif } static void ZSTD_loadDictionaryContent_loadTree( void* opaque, const void* ip, const void* iend) { ZSTD_loadDictionaryContent_context const* const context = (const ZSTD_loadDictionaryContent_context*)opaque; #if !defined(ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR) \ || !defined(ZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR) \ || !defined(ZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR) DEBUGLOG(4, "Fill %u bytes into the Binary Tree", (unsigned)((const BYTE*)iend - (const BYTE*)ip)); ZSTD_updateTree(context->matchState, (const BYTE*)ip, (const BYTE*)iend); #else (void)context; (void)ip; (void)iend; assert(0); /* shouldn't be called: cparams should've been adjusted. */ #endif } static void ZSTD_loadDictionaryContent_assertLazyConfiguration(void* opaque) { ZSTD_loadDictionaryContent_context const* const context = (const ZSTD_loadDictionaryContent_context*)opaque; assert(context->params->useRowMatchFinder != ZSTD_ps_auto); } static void ZSTD_loadDictionaryContent_assertInvalidStrategy(void* opaque) { (void)opaque; assert(0); /* not possible: not a valid strategy id */ } /* Package only scalar policy inputs and opaque private-operation callbacks for * the Rust dictionary-content orchestrator. */ static size_t ZSTD_loadDictionaryContent_callback( void* matchState, void* ldmState, void* workspaceState, const void* params, const void* src, size_t srcSize, int dtlm, int tfp) { ZSTD_loadDictionaryContent_context context; ZSTD_rust_loadDictionaryContentLdmPublicationState ldmPublication; ZSTD_rust_loadDictionaryContentMatchStatePublicationState matchStatePublication; ZSTD_rust_loadDictionaryContentFastTableState fastTable; ZSTD_rust_loadDictionaryContentDoubleFastTableState doubleFastTable; ZSTD_rust_loadDictionaryContentState state; ZSTD_MatchState_t* const ms = (ZSTD_MatchState_t*)matchState; ldmState_t* const ls = (ldmState_t*)ldmState; ZSTD_cwksp* const ws = (ZSTD_cwksp*)workspaceState; ZSTD_CCtx_params const* const cctxParams = (const ZSTD_CCtx_params*)params; context.matchState = ms; context.ldmState = ls; context.workspace = ws; context.params = cctxParams; matchStatePublication.base = &ms->window.base; matchStatePublication.nextToUpdate = &ms->nextToUpdate; matchStatePublication.loadedDictEnd = &ms->loadedDictEnd; matchStatePublication.forceNonContiguous = &ms->forceNonContiguous; ldmPublication.base = ls == NULL ? NULL : &ls->window.base; ldmPublication.loadedDictEnd = ls == NULL ? NULL : &ls->loadedDictEnd; assert((tfp == ZSTD_tfp_forCDict && dtlm == ZSTD_dtlm_full) || (tfp != ZSTD_tfp_forCDict && dtlm == ZSTD_dtlm_fast)); /* These fields are mutated by the window/publish callbacks before the * Fast branch runs. Keep pointers to the live match-state fields rather * than a stale snapshot taken before the Rust orchestrator starts. */ fastTable.hashTable = &ms->hashTable; fastTable.base = &ms->window.base; fastTable.nextToUpdate = &ms->nextToUpdate; fastTable.hashLog = &ms->cParams.hashLog; fastTable.minMatch = &ms->cParams.minMatch; fastTable.fullTableLoad = dtlm == ZSTD_dtlm_full; fastTable.forCDict = tfp == ZSTD_tfp_forCDict; doubleFastTable.hashLong = &ms->hashTable; doubleFastTable.hashSmall = &ms->chainTable; doubleFastTable.base = &ms->window.base; doubleFastTable.nextToUpdate = &ms->nextToUpdate; doubleFastTable.hashLog = &ms->cParams.hashLog; doubleFastTable.chainLog = &ms->cParams.chainLog; doubleFastTable.minMatch = &ms->cParams.minMatch; doubleFastTable.fullTableLoad = dtlm == ZSTD_dtlm_full; doubleFastTable.forCDict = tfp == ZSTD_tfp_forCDict; #ifndef ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR doubleFastTable.available = 1; #else doubleFastTable.available = 0; #endif state.callbackContext = &context; state.currentMax = ZSTD_CURRENT_MAX; state.windowStartIndex = ZSTD_WINDOW_START_INDEX; state.shortCacheTagBits = ZSTD_SHORT_CACHE_TAG_BITS; state.chunkSizeMax = ZSTD_CHUNKSIZE_MAX; state.hashReadSize = HASH_READ_SIZE; state.hashLog = cctxParams->cParams.hashLog; state.chainLog = cctxParams->cParams.chainLog; state.cdictIndicesTagged = ZSTD_CDictIndicesAreTagged(cctxParams->cParams); state.ldmEnabled = cctxParams->ldmParams.enableLdm == ZSTD_ps_enable; state.hasLdmState = ls != NULL; state.forceWindow = cctxParams->forceWindow; state.deterministicRefPrefix = cctxParams->deterministicRefPrefix; state.strategy = cctxParams->cParams.strategy; state.useRowMatchFinder = cctxParams->useRowMatchFinder; state.dedicatedDictSearch = ms->dedicatedDictSearch; state.dtlm = (size_t)dtlm; state.tfp = (size_t)tfp; state.assertCParams = ZSTD_loadDictionaryContent_assertCParams; state.assertWindowEmpty = ZSTD_loadDictionaryContent_assertWindowEmpty; state.windowUpdate = ZSTD_loadDictionaryContent_windowUpdate; state.setLdmLoadedDictEnd = &ldmPublication; state.publishMatchState = &matchStatePublication; state.fillLdm = ZSTD_loadDictionaryContent_fillLdm; state.overflowCorrect = ZSTD_loadDictionaryContent_overflowCorrect; state.fastTable = &fastTable; state.doubleFastTable = &doubleFastTable; state.loadDedicated = ZSTD_loadDictionaryContent_loadDedicated; state.loadRow = ZSTD_loadDictionaryContent_loadRow; state.loadChain = ZSTD_loadDictionaryContent_loadChain; state.loadTree = ZSTD_loadDictionaryContent_loadTree; state.publishFinalIndex = &matchStatePublication; state.assertLazyConfiguration = ZSTD_loadDictionaryContent_assertLazyConfiguration; state.assertInvalidStrategy = ZSTD_loadDictionaryContent_assertInvalidStrategy; return ZSTD_rust_loadDictionaryContent(&state, src, srcSize); } /** ZSTD_compress_insertDictionary() : * @return : dictID, or an error code */ static size_t ZSTD_compress_insertDictionary(ZSTD_compressedBlockState_t* bs, ZSTD_MatchState_t* ms, ldmState_t* ls, ZSTD_cwksp* ws, const ZSTD_CCtx_params* params, const void* dict, size_t dictSize, ZSTD_dictContentType_e dictContentType, ZSTD_dictTableLoadMethod_e dtlm, ZSTD_tableFillPurpose_e tfp, void* workspace) { int const noDictIDFlag = (params != NULL && dict != NULL && dictSize >= 8) ? params->fParams.noDictIDFlag : 0; DEBUGLOG(4, "ZSTD_compress_insertDictionary (dictSize=%u)", (U32)dictSize); return ZSTD_rust_compressInsertDictionary( bs, ms, ls, ws, params, dict, dictSize, (int)dictContentType, (int)dtlm, (int)tfp, workspace, noDictIDFlag, ZSTD_loadDictionaryContent_callback); } static void* ZSTD_rust_initCDict_reserveContent( void* context, size_t reservedSize) { ZSTD_CDict* const cdict = (ZSTD_CDict*)context; return ZSTD_cwksp_reserve_object(&cdict->workspace, reservedSize); } static void* ZSTD_rust_initCDict_reserveEntropy( void* context, size_t workspaceSize) { ZSTD_CDict* const cdict = (ZSTD_CDict*)context; return ZSTD_cwksp_reserve_object(&cdict->workspace, workspaceSize); } static size_t ZSTD_rust_initCDict_resetMatchState( void* context, const ZSTD_compressionParameters* cParams, int useRowMatchFinder, int compResetPolicy, int indexResetPolicy, int resetTarget) { ZSTD_CDict* const cdict = (ZSTD_CDict*)context; return ZSTD_reset_matchState( &cdict->matchState, &cdict->workspace, cParams, (ZSTD_ParamSwitch_e)useRowMatchFinder, (ZSTD_compResetPolicy_e)compResetPolicy, (ZSTD_indexResetPolicy_e)indexResetPolicy, (ZSTD_resetTarget_e)resetTarget); } static size_t ZSTD_rust_initCDict_insertDictionary( void* context, const void* params, const void* dict, size_t dictSize, int dictContentType, int dtlm, int tfp) { ZSTD_CDict* const cdict = (ZSTD_CDict*)context; return ZSTD_compress_insertDictionary( &cdict->cBlockState, &cdict->matchState, NULL, &cdict->workspace, (const ZSTD_CCtx_params*)params, dict, dictSize, (ZSTD_dictContentType_e)dictContentType, (ZSTD_dictTableLoadMethod_e)dtlm, (ZSTD_tableFillPurpose_e)tfp, cdict->entropyWorkspace); } static size_t ZSTD_rust_compressBegin_resetInternal( void* context, const void* params, U64 pledgedSrcSize, size_t loadedDictSize, int zbuff) { return ZSTD_resetCCtx_internal( (ZSTD_CCtx*)context, (const ZSTD_CCtx_params*)params, pledgedSrcSize, loadedDictSize, ZSTDcrp_makeClean, (ZSTD_buffered_policy_e)zbuff); } static size_t ZSTD_rust_compressBegin_resetUsingCDict( void* context, const void* cdict, const void* params, U64 pledgedSrcSize, int zbuff) { return ZSTD_resetCCtx_usingCDict( (ZSTD_CCtx*)context, (const ZSTD_CDict*)cdict, (const ZSTD_CCtx_params*)params, pledgedSrcSize, (ZSTD_buffered_policy_e)zbuff); } static size_t ZSTD_rust_compressBegin_insertDictionary( void* context, const void* dict, size_t dictSize, int dictContentType, int dtlm) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; return ZSTD_compress_insertDictionary( cctx->blockState.prevCBlock, &cctx->blockState.matchState, &cctx->ldmState, &cctx->workspace, &cctx->appliedParams, dict, dictSize, (ZSTD_dictContentType_e)dictContentType, (ZSTD_dictTableLoadMethod_e)dtlm, ZSTD_tfp_forCCtx, cctx->tmpWorkspace); } #define ZSTD_USE_CDICT_PARAMS_SRCSIZE_CUTOFF (128 KB) #define ZSTD_USE_CDICT_PARAMS_DICTSIZE_MULTIPLIER (6ULL) /*! ZSTD_compressBegin_internal() : * Assumption : either @dict OR @cdict (or none) is non-NULL, never both * @return : 0, or an error code */ static size_t ZSTD_compressBegin_internal(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_dictContentType_e dictContentType, ZSTD_dictTableLoadMethod_e dtlm, const ZSTD_CDict* cdict, const ZSTD_CCtx_params* params, U64 pledgedSrcSize, ZSTD_buffered_policy_e zbuff) { ZSTD_rust_compressBeginState state; int const dictContentTypeValue = (int)dictContentType; int const dtlmValue = (int)dtlm; int const zbuffValue = (int)zbuff; int const forceLoadValue = (int)ZSTD_dictForceLoad; #if ZSTD_TRACE cctx->traceCtx = (ZSTD_trace_compress_begin != NULL) ? ZSTD_trace_compress_begin(cctx) : 0; #endif DEBUGLOG(4, "ZSTD_compressBegin_internal: wlog=%u", params->cParams.windowLog); /* params are supposed to be fully validated at this point */ assert(!ZSTD_isError(ZSTD_checkCParams(params->cParams))); assert(!((dict) && (cdict))); /* either dict or cdict, not both */ state.callbackContext = cctx; state.params = params; state.cdict = cdict; state.cdictDictContent = cdict == NULL ? NULL : cdict->dictContent; state.cdictDictContentSize = cdict == NULL ? 0 : cdict->dictContentSize; state.cdictDictContentType = cdict == NULL ? 0 : (int)cdict->dictContentType; state.cdictContentSize = cdict == NULL ? NULL : &cdict->dictContentSize; state.cdictCompressionLevel = cdict == NULL ? NULL : &cdict->compressionLevel; state.attachDictPref = ¶ms->attachDictPref; state.dict = dict; state.dictSize = &dictSize; state.dictContentType = &dictContentTypeValue; state.dtlm = &dtlmValue; state.pledgedSrcSize = &pledgedSrcSize; state.zbuff = &zbuffValue; state.forceLoad = &forceLoadValue; state.dictID = &cctx->dictID; state.dictContentSize = &cctx->dictContentSize; state.resetInternal = ZSTD_rust_compressBegin_resetInternal; state.resetUsingCDict = ZSTD_rust_compressBegin_resetUsingCDict; state.insertDictionary = ZSTD_rust_compressBegin_insertDictionary; return ZSTD_rust_compressBegin(&state); } static void ZSTD_rust_compressBeginUsingDict_initParams( void* cctxParams, const ZSTD_parameters* params, int compressionLevel) { ZSTD_CCtxParams_init_internal( (ZSTD_CCtx_params*)cctxParams, params, compressionLevel); } static size_t ZSTD_rust_compressBeginUsingDict_begin( void* context, const void* dict, size_t dictSize, const void* cctxParams, U64 pledgedSrcSize) { return ZSTD_compressBegin_internal( (ZSTD_CCtx*)context, dict, dictSize, ZSTD_dct_auto, ZSTD_dtlm_fast, NULL, (const ZSTD_CCtx_params*)cctxParams, pledgedSrcSize, ZSTDb_not_buffered); } static void ZSTD_rust_compressBeginAdvanced_initParams( void* cctxParams, const ZSTD_parameters* params) { ZSTD_CCtxParams_init_internal( (ZSTD_CCtx_params*)cctxParams, params, ZSTD_NO_CLEVEL); } static size_t ZSTD_rust_compressBeginAdvanced_begin( void* context, const void* dict, size_t dictSize, const void* cctxParams, U64 pledgedSrcSize) { return ZSTD_compressBegin_internal( (ZSTD_CCtx*)context, dict, dictSize, ZSTD_dct_auto, ZSTD_dtlm_fast, NULL, (const ZSTD_CCtx_params*)cctxParams, pledgedSrcSize, ZSTDb_not_buffered); } size_t ZSTD_compressBegin_advanced_internal(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_dictContentType_e dictContentType, ZSTD_dictTableLoadMethod_e dtlm, const ZSTD_CDict* cdict, const ZSTD_CCtx_params* params, unsigned long long pledgedSrcSize) { DEBUGLOG(4, "ZSTD_compressBegin_advanced_internal: wlog=%u", params->cParams.windowLog); /* compression parameters verification and optimization */ FORWARD_IF_ERROR( ZSTD_checkCParams(params->cParams) , ""); return ZSTD_compressBegin_internal(cctx, dict, dictSize, dictContentType, dtlm, cdict, params, pledgedSrcSize, ZSTDb_not_buffered); } /*! ZSTD_compressBegin_advanced() : * @return : 0, or an error code */ size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize) { ZSTD_rust_compressBeginAdvancedState state; ZSTD_CCtx_params cctxParams; state.cctx = cctx; state.cctxParams = &cctxParams; state.initParams = ZSTD_rust_compressBeginAdvanced_initParams; state.begin = ZSTD_rust_compressBeginAdvanced_begin; return ZSTD_rust_compressBeginAdvanced( &state, dict, dictSize, ¶ms, pledgedSrcSize); } static size_t ZSTD_compressBegin_usingDict_deprecated(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel) { ZSTD_rust_compressBeginUsingDictState state; ZSTD_CCtx_params cctxParams; U32 const exclusionMask = ZSTD_getCParamsExclusionMask(); DEBUGLOG(4, "ZSTD_compressBegin_usingDict (dictSize=%u)", (unsigned)dictSize); state.cctx = cctx; state.cctxParams = &cctxParams; state.exclusionMask = &exclusionMask; state.initParams = ZSTD_rust_compressBeginUsingDict_initParams; state.begin = ZSTD_rust_compressBeginUsingDict_begin; return ZSTD_rust_compressBeginUsingDict( &state, dict, dictSize, compressionLevel); } size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel) { return ZSTD_compressBegin_usingDict_deprecated(cctx, dict, dictSize, compressionLevel); } size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel) { return ZSTD_compressBegin_usingDict_deprecated(cctx, NULL, 0, compressionLevel); } typedef void (*ZSTD_rust_traceEnd_f)( void* context, unsigned long long traceCtx, const void* trace); typedef struct { void* callbackContext; unsigned long long* traceCtx; int streaming; unsigned dictionaryID; size_t dictionarySize; size_t uncompressedSize; size_t compressedSize; const void* params; const void* cctx; ZSTD_rust_traceEnd_f traceEnd; } ZSTD_rust_traceEndState; typedef char ZSTD_rust_trace_end_state_layout[ (offsetof(ZSTD_rust_traceEndState, callbackContext) == 0 && offsetof(ZSTD_rust_traceEndState, traceCtx) == sizeof(void*) && offsetof(ZSTD_rust_traceEndState, streaming) == sizeof(void*) + sizeof(unsigned long long) && offsetof(ZSTD_rust_traceEndState, dictionaryID) == sizeof(void*) + sizeof(unsigned long long) + sizeof(int) && offsetof(ZSTD_rust_traceEndState, dictionarySize) == sizeof(void*) + sizeof(unsigned long long) + 2 * sizeof(int) && offsetof(ZSTD_rust_traceEndState, uncompressedSize) == offsetof(ZSTD_rust_traceEndState, dictionarySize) + sizeof(size_t) && offsetof(ZSTD_rust_traceEndState, compressedSize) == offsetof(ZSTD_rust_traceEndState, dictionarySize) + 2 * sizeof(size_t) && offsetof(ZSTD_rust_traceEndState, params) == offsetof(ZSTD_rust_traceEndState, dictionarySize) + 3 * sizeof(size_t) && offsetof(ZSTD_rust_traceEndState, cctx) == offsetof(ZSTD_rust_traceEndState, dictionarySize) + 4 * sizeof(size_t) && offsetof(ZSTD_rust_traceEndState, traceEnd) == offsetof(ZSTD_rust_traceEndState, dictionarySize) + 5 * sizeof(size_t) && sizeof(ZSTD_rust_traceEndState) == offsetof(ZSTD_rust_traceEndState, dictionarySize) + 6 * sizeof(size_t)) ? 1 : -1]; void ZSTD_rust_traceEnd(const ZSTD_rust_traceEndState* state); #if ZSTD_TRACE static void ZSTD_rust_traceEnd_callback(void* context, unsigned long long traceCtx, const void* trace) { (void)context; if (ZSTD_trace_compress_end != NULL) { ZSTD_trace_compress_end((ZSTD_TraceCtx)traceCtx, (ZSTD_Trace const*)trace); } } #endif void ZSTD_CCtx_trace(ZSTD_CCtx* cctx, size_t extraCSize) { #if ZSTD_TRACE ZSTD_rust_traceEndState state; state.callbackContext = cctx; state.traceCtx = &cctx->traceCtx; state.streaming = cctx->inBuffSize > 0 || cctx->outBuffSize > 0 || cctx->appliedParams.nbWorkers > 0; state.dictionaryID = cctx->dictID; state.dictionarySize = cctx->dictContentSize; state.uncompressedSize = cctx->consumedSrcSize; state.compressedSize = cctx->producedCSize + extraCSize; state.params = &cctx->appliedParams; state.cctx = cctx; state.traceEnd = ZSTD_rust_traceEnd_callback; ZSTD_rust_traceEnd(&state); #else (void)cctx; (void)extraCSize; #endif } static void ZSTD_rust_compressEnd_trace(void* context, size_t extraCSize) { ZSTD_CCtx_trace((ZSTD_CCtx*)context, extraCSize); } static size_t ZSTD_compressEnd_dispatch(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize) { ZSTD_rust_compressContinueContext continueContext; ZSTD_rust_compressEndState state; ZSTD_compressContinue_prepare(cctx, cctx->blockSizeMax, 0 /* block size already selected */, &continueContext); state.callbackContext = cctx; state.compressContinueState = &continueContext.state; state.trace = ZSTD_rust_compressEnd_trace; state.consumedSrcSize = &cctx->consumedSrcSize; state.pledgedSrcSizePlusOne = cctx->pledgedSrcSizePlusOne; state.contentSizeFlag = cctx->appliedParams.fParams.contentSizeFlag; state.stage = (int*)&cctx->stage; state.noDictIDFlag = cctx->appliedParams.fParams.noDictIDFlag; state.checksumFlag = cctx->appliedParams.fParams.checksumFlag; state.format = (int)cctx->appliedParams.format; state.windowLog = cctx->appliedParams.cParams.windowLog; state.checksumState = &cctx->xxhState; return ZSTD_rust_compressEnd( &state, dst, dstCapacity, src, srcSize); } size_t ZSTD_compressEnd_public(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize) { return ZSTD_compressEnd_dispatch(cctx, dst, dstCapacity, src, srcSize); } /* NOTE: Must just wrap ZSTD_compressEnd_public() */ size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize) { return ZSTD_compressEnd_public(cctx, dst, dstCapacity, src, srcSize); } static void ZSTD_rust_compressAdvanced_initParams( void* context, const ZSTD_parameters* params); static size_t ZSTD_rust_compressAdvanced_compressInternal( void* context, void* dst, size_t dstCapacity, const void* src, size_t srcSize, const void* dict, size_t dictSize); static size_t ZSTD_rust_compressAdvancedInternal_begin( void* context, const void* dict, size_t dictSize, const void* params, U64 pledgedSrcSize); static size_t ZSTD_rust_compressAdvancedInternal_end( void* context, void* dst, size_t dstCapacity, const void* src, size_t srcSize); size_t ZSTD_compress_advanced (ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, const void* dict,size_t dictSize, ZSTD_parameters params) { ZSTD_rust_compressAdvancedState state; DEBUGLOG(4, "ZSTD_compress_advanced"); state.callbackContext = cctx; state.initParams = ZSTD_rust_compressAdvanced_initParams; state.compressInternal = ZSTD_rust_compressAdvanced_compressInternal; return ZSTD_rust_compressAdvanced( &state, dst, dstCapacity, src, srcSize, dict, dictSize, ¶ms); } /* Internal */ size_t ZSTD_compress_advanced_internal( ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, const void* dict,size_t dictSize, const ZSTD_CCtx_params* params) { ZSTD_rust_compressAdvancedInternalState state; DEBUGLOG(4, "ZSTD_compress_advanced_internal (srcSize:%u)", (unsigned)srcSize); state.callbackContext = cctx; state.begin = ZSTD_rust_compressAdvancedInternal_begin; state.end = ZSTD_rust_compressAdvancedInternal_end; return ZSTD_rust_compressAdvancedInternal( &state, dst, dstCapacity, src, srcSize, dict, dictSize, params); } static size_t ZSTD_rust_compressAdvancedInternal_begin( void* context, const void* dict, size_t dictSize, const void* params, U64 pledgedSrcSize) { return ZSTD_compressBegin_internal( (ZSTD_CCtx*)context, dict, dictSize, ZSTD_dct_auto, ZSTD_dtlm_fast, NULL, (const ZSTD_CCtx_params*)params, pledgedSrcSize, ZSTDb_not_buffered); } static size_t ZSTD_rust_compressAdvancedInternal_end( void* context, void* dst, size_t dstCapacity, const void* src, size_t srcSize) { return ZSTD_compressEnd_public( (ZSTD_CCtx*)context, dst, dstCapacity, src, srcSize); } static void ZSTD_rust_compressAdvanced_initParams( void* context, const ZSTD_parameters* params) { ZSTD_CCtxParams_init_internal( &((ZSTD_CCtx*)context)->simpleApiParams, params, ZSTD_NO_CLEVEL); } static size_t ZSTD_rust_compressAdvanced_compressInternal( void* context, void* dst, size_t dstCapacity, const void* src, size_t srcSize, const void* dict, size_t dictSize) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; return ZSTD_compress_advanced_internal( cctx, dst, dstCapacity, src, srcSize, dict, dictSize, &cctx->simpleApiParams); } static void ZSTD_rust_compressUsingDict_initParams( void* context, const ZSTD_parameters* params, int compressionLevel) { ZSTD_CCtxParams_init_internal( &((ZSTD_CCtx*)context)->simpleApiParams, params, compressionLevel); } size_t ZSTD_compress_usingDict(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, const void* dict, size_t dictSize, int compressionLevel) { ZSTD_rust_compressUsingDictState state; U32 const exclusionMask = ZSTD_getCParamsExclusionMask(); DEBUGLOG(4, "ZSTD_compress_usingDict (srcSize=%u)", (unsigned)srcSize); state.callbackContext = cctx; state.exclusionMask = &exclusionMask; state.initParams = ZSTD_rust_compressUsingDict_initParams; state.compressInternal = ZSTD_rust_compressAdvanced_compressInternal; return ZSTD_rust_compressUsingDict( &state, dst, dstCapacity, src, srcSize, dict, dictSize, compressionLevel); } /* ZSTD_compressCCtx() is implemented by rust/src/zstd_compress.rs. */ /* The Rust simple API still needs the C-owned context reset, but does not * cross the private context layout. */ size_t ZSTD_rust_resetCCtxForSimpleCompression(void* cctx) { return ZSTD_CCtx_reset((ZSTD_CCtx*)cctx, ZSTD_reset_session_and_parameters); } size_t ZSTD_rust_prepareCCtxForSimpleCompression(void* opaqueCctx, size_t srcSize, int compressionLevel) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)opaqueCctx; ZSTD_CCtx_params params; ZSTD_parameters const zstdParams = ZSTD_getParams_internal( compressionLevel, srcSize, 0, ZSTD_cpm_noAttachDict); ZSTD_CCtxParams_init_internal( ¶ms, &zstdParams, compressionLevel == 0 ? ZSTD_CLEVEL_DEFAULT : compressionLevel); FORWARD_IF_ERROR(ZSTD_compressBegin_internal( cctx, NULL, 0, ZSTD_dct_auto, ZSTD_dtlm_fast, NULL, ¶ms, srcSize, ZSTDb_not_buffered), ""); return ZSTD_CCtx_reset(cctx, ZSTD_reset_session_only); } size_t ZSTD_rust_resetCCtxForSimpleCompressionSession(void* cctx) { return ZSTD_CCtx_reset((ZSTD_CCtx*)cctx, ZSTD_reset_session_only); } void ZSTD_rust_markSimpleCompression2Complete(void* cctx) { ((ZSTD_CCtx*)cctx)->rustSimpleCompress2Completed = 1; } /* Project private context state before Rust evaluates the simple-path policy. * The parameter-selection leaf remains C-owned because it depends on the * private compression-parameter tables and implementation details. */ int ZSTD_rust_simpleCompress2Level(const void* opaqueCctx, size_t srcSize) { ZSTD_CCtx const* const cctx = (ZSTD_CCtx const*)opaqueCctx; if (cctx == NULL) return (-2147483647 - 1); { ZSTD_CCtx_params const* const params = &cctx->requestedParams; ZSTD_compressionParameters const cParams = ZSTD_getCParams_internal( params->compressionLevel, srcSize, 0, ZSTD_cpm_noAttachDict); ZSTD_rust_simpleCompress2LevelState const state = { (int)params->format, (int)params->fParams.contentSizeFlag, (int)params->fParams.checksumFlag, (int)params->cParams.windowLog, (int)params->cParams.chainLog, (int)params->cParams.hashLog, (int)params->cParams.searchLog, (int)params->cParams.minMatch, (int)params->cParams.targetLength, (int)params->cParams.strategy, params->forceWindow != 0, (int)(params->targetCBlockSize != 0), (int)(params->srcSizeHint != 0), (int)params->attachDictPref, (int)params->literalCompressionMode, (int)(params->nbWorkers != 0), (int)(params->jobSize != 0), (int)(params->overlapLog != 0), params->rsyncable != 0, (int)params->ldmParams.enableLdm, (int)(params->ldmParams.hashLog != 0), (int)params->ldmParams.bucketSizeLog, (int)(params->ldmParams.minMatchLength != 0), (int)params->ldmParams.hashRateLog, (int)(params->ldmParams.windowLog != 0), params->enableDedicatedDictSearch != 0, (int)params->inBufferMode, (int)params->outBufferMode, (int)params->blockDelimiters, params->validateSequences != 0, (int)params->postBlockSplitter, (int)(params->preBlockSplitter_level != 0), (int)(params->maxBlockSize != 0), (int)(cctx->rustSimpleCompress2MaxBlockSizeSet != 0), (int)params->useRowMatchFinder, params->deterministicRefPrefix != 0, (int)params->prefetchCDictTables, params->enableMatchFinderFallback != 0, (int)(params->extSeqProdFunc != NULL), (int)params->searchForExternalRepcodes, (int)(cctx->pool != NULL), cctx->seqCollector.collectSequences != 0, (int)(cctx->cdict != NULL), (int)(cctx->prefixDict.dict != NULL), (int)(cctx->localDict.dict != NULL || cctx->localDict.dictBuffer != NULL || cctx->localDict.cdict != NULL), params->compressionLevel, (int)cParams.strategy }; return ZSTD_rust_simpleCompress2LevelPolicy(&state); } } /* Return the simple level only while a new stream frame can be initialized. * Rust handles this complete-input case; all other stream states stay on the * original implementation so partial output and advanced buffering remain * governed by the C state machine. */ int ZSTD_rust_simpleCompressStream2Level(const void* opaqueCctx, size_t srcSize) { ZSTD_CCtx const* const cctx = (ZSTD_CCtx const*)opaqueCctx; ZSTD_rust_simpleCompressStream2Projection const projection = { cctx == NULL ? 0 : (int)cctx->streamStage, cctx == NULL ? 0 : cctx->pledgedSrcSizePlusOne, cctx == NULL ? 0 : cctx->rustSimpleCompress2Completed }; return ZSTD_rust_simpleCompressStream2Policy( &projection, opaqueCctx, srcSize, ZSTD_rust_simpleCompress2Level); } /* ZSTD_compress() is implemented by rust/src/zstd_compress.rs. */ /* ===== Dictionary API ===== */ /*! ZSTD_estimateCDictSize_advanced() : * Estimate amount of memory that will be needed to create a dictionary with following arguments */ size_t ZSTD_estimateCDictSize_advanced( size_t dictSize, ZSTD_compressionParameters cParams, ZSTD_dictLoadMethod_e dictLoadMethod) { ZSTD_rustCDictSizing sizing; sizing.cdictSize = sizeof(ZSTD_CDict); sizing.hufWorkspaceSize = HUF_WORKSPACE_SIZE; sizing.hashLog3Max = ZSTD_HASHLOG3_MAX; sizing.matchTSize = sizeof(ZSTD_match_t); sizing.optimalTSize = sizeof(ZSTD_optimal_t); sizing.asanRedzoneSize = ZSTD_RUST_ASAN_REDZONE_SIZE; return ZSTD_rust_params_estimateCDictSizeFromCParams( dictSize, cParams, (int)dictLoadMethod, &sizing); } static size_t ZSTD_rust_estimateCDictSize_advanced( void* context, size_t dictSize, ZSTD_compressionParameters cParams, int dictLoadMethod) { (void)context; return ZSTD_estimateCDictSize_advanced( dictSize, cParams, (ZSTD_dictLoadMethod_e)dictLoadMethod); } size_t ZSTD_estimateCDictSize(size_t dictSize, int compressionLevel) { ZSTD_rust_estimateCDictSizeState state; U32 const exclusionMask = ZSTD_getCParamsExclusionMask(); state.callbackContext = NULL; state.exclusionMask = &exclusionMask; state.estimateAdvanced = ZSTD_rust_estimateCDictSize_advanced; return ZSTD_rust_estimateCDictSize(&state, dictSize, compressionLevel); } size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict) { size_t objectSize, workspaceSize; if (cdict==NULL) return 0; /* support sizeof on NULL */ DEBUGLOG(5, "sizeof(*cdict) : %u", (unsigned)sizeof(*cdict)); /* cdict may be in the workspace */ objectSize = cdict->workspace.workspace == cdict ? 0 : sizeof(*cdict); workspaceSize = ZSTD_cwksp_sizeof(&cdict->workspace); return ZSTD_rust_sizeofCDict(objectSize, workspaceSize); } static size_t ZSTD_initCDict_internal( ZSTD_CDict* cdict, const void* dictBuffer, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_CCtx_params params) { ZSTD_rust_initCDictState state; DEBUGLOG(3, "ZSTD_initCDict_internal (dictContentType:%u)", (unsigned)dictContentType); assert(!ZSTD_checkCParams(params.cParams)); state.callbackContext = cdict; state.params = ¶ms; state.cParams = ¶ms.cParams; state.matchStateCParams = &cdict->matchState.cParams; state.dedicatedDictSearch = &cdict->matchState.dedicatedDictSearch; state.enableDedicatedDictSearch = ¶ms.enableDedicatedDictSearch; state.useRowMatchFinder = ¶ms.useRowMatchFinder; state.dictContent = &cdict->dictContent; state.dictContentSize = &cdict->dictContentSize; state.dictContentType = (int*)&cdict->dictContentType; state.entropyWorkspace = &cdict->entropyWorkspace; state.dictID = &cdict->dictID; state.compressionLevel = ¶ms.compressionLevel; state.contentSizeFlag = ¶ms.fParams.contentSizeFlag; state.reserveContent = ZSTD_rust_initCDict_reserveContent; state.reserveEntropy = ZSTD_rust_initCDict_reserveEntropy; state.blockState = &cdict->cBlockState; state.resetMatchState = ZSTD_rust_initCDict_resetMatchState; state.insertDictionary = ZSTD_rust_initCDict_insertDictionary; return ZSTD_rust_initCDict( &state, dictBuffer, dictSize, (int)dictLoadMethod, (int)dictContentType); } typedef struct { ZSTD_customMem customMem; ZSTD_cwksp workspace; } ZSTD_rust_createCDictAdvancedContext; static int ZSTD_rust_createCDictAdvanced_validateCustomMem(void* context) { ZSTD_rust_createCDictAdvancedContext const* const createContext = (const ZSTD_rust_createCDictAdvancedContext*)context; ZSTD_customMem const* const customMem = &createContext->customMem; return ((!customMem->customAlloc) ^ (!customMem->customFree)) == 0; } static void ZSTD_rust_createCDictAdvanced_copyParams( void* context, void* destination, const void* source) { (void)context; *(ZSTD_CCtx_params*)destination = *(const ZSTD_CCtx_params*)source; } static void* ZSTD_rust_createCDictAdvanced_allocate( void* context, size_t workspaceSize) { ZSTD_rust_createCDictAdvancedContext const* const createContext = (const ZSTD_rust_createCDictAdvancedContext*)context; return ZSTD_customMalloc(workspaceSize, createContext->customMem); } static void ZSTD_rust_createCDictAdvanced_createWorkspace( void* context, void* workspace, size_t workspaceSize) { ZSTD_rust_createCDictAdvancedContext* const createContext = (ZSTD_rust_createCDictAdvancedContext*)context; DEBUGLOG(3, "ZSTD_createCDict_advanced_internal (workspaceSize=%u)", (unsigned)workspaceSize); ZSTD_cwksp_init(&createContext->workspace, workspace, workspaceSize, ZSTD_cwksp_dynamic_alloc); } static void* ZSTD_rust_createCDictAdvanced_reserveObject(void* context) { ZSTD_rust_createCDictAdvancedContext* const createContext = (ZSTD_rust_createCDictAdvancedContext*)context; return ZSTD_cwksp_reserve_object(&createContext->workspace, sizeof(ZSTD_CDict)); } static void ZSTD_rust_createCDictAdvanced_moveWorkspace( void* context, void* cdict) { ZSTD_rust_createCDictAdvancedContext* const createContext = (ZSTD_rust_createCDictAdvancedContext*)context; ZSTD_cwksp_move(&((ZSTD_CDict*)cdict)->workspace, &createContext->workspace); } static void ZSTD_rust_createCDictAdvanced_initialize( void* context, void* cdict, int useRowMatchFinder) { ZSTD_rust_createCDictAdvancedContext const* const createContext = (const ZSTD_rust_createCDictAdvancedContext*)context; ZSTD_CDict* const dictionary = (ZSTD_CDict*)cdict; dictionary->customMem = createContext->customMem; dictionary->compressionLevel = ZSTD_NO_CLEVEL; /* signals advanced API usage */ dictionary->useRowMatchFinder = (ZSTD_ParamSwitch_e)useRowMatchFinder; } static void ZSTD_rust_createCDictAdvanced_freeWorkspace( void* context, void* workspace) { ZSTD_rust_createCDictAdvancedContext const* const createContext = (const ZSTD_rust_createCDictAdvancedContext*)context; ZSTD_customFree(workspace, createContext->customMem); } static size_t ZSTD_rust_createCDictAdvanced_init( void* context, void* cdict, const void* dict, size_t dictSize, int dictLoadMethod, int dictContentType, const ZSTD_CCtx_params* cctxParams) { (void)context; return ZSTD_initCDict_internal( (ZSTD_CDict*)cdict, dict, dictSize, (ZSTD_dictLoadMethod_e)dictLoadMethod, (ZSTD_dictContentType_e)dictContentType, *cctxParams); } static void ZSTD_rust_createCDictAdvanced_free(void* context, void* cdict) { (void)context; ZSTD_freeCDict((ZSTD_CDict*)cdict); } static void ZSTD_rust_createCDictAdvancedWrapper_initParams( void* context, void* opaqueCctxParams, const ZSTD_compressionParameters* cParams, const void* opaqueCustomMem, size_t dictSize, int dictContentType) { ZSTD_CCtx_params* const cctxParams = (ZSTD_CCtx_params*)opaqueCctxParams; ZSTD_customMem const* const customMem = (const ZSTD_customMem*)opaqueCustomMem; (void)context; ZSTD_memset(cctxParams, 0, sizeof(*cctxParams)); DEBUGLOG(3, "ZSTD_createCDict_advanced, dictSize=%u, mode=%u", (unsigned)dictSize, (unsigned)dictContentType); ZSTD_CCtxParams_init(cctxParams, 0); cctxParams->cParams = *cParams; cctxParams->customMem = *customMem; } static void* ZSTD_rust_createCDictAdvancedWrapper_create( void* context, const void* dict, size_t dictSize, int dictLoadMethod, int dictContentType, const void* opaqueCctxParams, const void* opaqueCustomMem) { ZSTD_customMem const* const customMem = (const ZSTD_customMem*)opaqueCustomMem; (void)context; return ZSTD_createCDict_advanced2( dict, dictSize, (ZSTD_dictLoadMethod_e)dictLoadMethod, (ZSTD_dictContentType_e)dictContentType, (const ZSTD_CCtx_params*)opaqueCctxParams, *customMem); } ZSTD_CDict* ZSTD_createCDict_advanced(const void* dictBuffer, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_compressionParameters cParams, ZSTD_customMem customMem) { ZSTD_CCtx_params cctxParams; ZSTD_rust_createCDictAdvancedWrapperState state; state.callbackContext = NULL; state.cctxParams = &cctxParams; state.cParams = &cParams; state.customMem = &customMem; state.initParams = ZSTD_rust_createCDictAdvancedWrapper_initParams; state.create = ZSTD_rust_createCDictAdvancedWrapper_create; return (ZSTD_CDict*)ZSTD_rust_createCDictAdvancedWrapper( &state, dictBuffer, dictSize, (int)dictLoadMethod, (int)dictContentType); } ZSTD_CDict* ZSTD_createCDict_advanced2( const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, const ZSTD_CCtx_params* originalCctxParams, ZSTD_customMem customMem) { ZSTD_CCtx_params cctxParams; ZSTD_rust_createCDictAdvancedContext context; ZSTD_rust_createCDictAdvancedState state; ZSTD_rustCDictSizing const sizing = { sizeof(ZSTD_CDict), HUF_WORKSPACE_SIZE, ZSTD_HASHLOG3_MAX, sizeof(ZSTD_match_t), sizeof(ZSTD_optimal_t), ZSTD_RUST_ASAN_REDZONE_SIZE }; DEBUGLOG(3, "ZSTD_createCDict_advanced2, dictSize=%u, mode=%u", (unsigned)dictSize, (unsigned)dictContentType); context.customMem = customMem; state.callbackContext = &context; state.cctxParams = &cctxParams; state.cParams = &cctxParams.cParams; state.enableDedicatedDictSearch = &cctxParams.enableDedicatedDictSearch; state.useRowMatchFinder = (const int*)&cctxParams.useRowMatchFinder; state.exclusionMask = ZSTD_getCParamsExclusionMask(); state.ldmDefaultWindowLog = ZSTD_LDM_DEFAULT_WINDOW_LOG; state.validateCustomMem = ZSTD_rust_createCDictAdvanced_validateCustomMem; state.sizing = &sizing; state.allocate = ZSTD_rust_createCDictAdvanced_allocate; state.createWorkspace = ZSTD_rust_createCDictAdvanced_createWorkspace; state.reserveObject = ZSTD_rust_createCDictAdvanced_reserveObject; state.moveWorkspace = ZSTD_rust_createCDictAdvanced_moveWorkspace; state.initialize = ZSTD_rust_createCDictAdvanced_initialize; state.init = ZSTD_rust_createCDictAdvanced_init; state.freeWorkspace = ZSTD_rust_createCDictAdvanced_freeWorkspace; state.free = ZSTD_rust_createCDictAdvanced_free; state.originalCctxParams = originalCctxParams; state.copyParams = ZSTD_rust_createCDictAdvanced_copyParams; return (ZSTD_CDict*)ZSTD_rust_createCDictAdvanced( &state, dict, dictSize, (int)dictLoadMethod, (int)dictContentType); } /* The implementation above intentionally keeps the private workspace and * object operations in C. Rust only sequences those operations and handles * the public construction policy. */ static void* ZSTD_rust_createCDict_create( void* context, const void* dict, size_t dictSize, int dictLoadMethod, int dictContentType, const ZSTD_compressionParameters* cParams) { (void)context; return ZSTD_createCDict_advanced( dict, dictSize, (ZSTD_dictLoadMethod_e)dictLoadMethod, (ZSTD_dictContentType_e)dictContentType, *cParams, ZSTD_defaultCMem); } static void ZSTD_rust_createCDict_setCompressionLevel( void* context, void* cdict, int compressionLevel) { (void)context; ((ZSTD_CDict*)cdict)->compressionLevel = compressionLevel; } ZSTD_CDict* ZSTD_createCDict(const void* dict, size_t dictSize, int compressionLevel) { ZSTD_rust_createCDictState state; U32 const exclusionMask = ZSTD_getCParamsExclusionMask(); state.callbackContext = NULL; state.exclusionMask = &exclusionMask; state.create = ZSTD_rust_createCDict_create; state.setCompressionLevel = ZSTD_rust_createCDict_setCompressionLevel; return (ZSTD_CDict*)ZSTD_rust_createCDict( &state, dict, dictSize, compressionLevel, ZSTD_dlm_byCopy); } ZSTD_CDict* ZSTD_createCDict_byReference(const void* dict, size_t dictSize, int compressionLevel) { ZSTD_rust_createCDictState state; U32 const exclusionMask = ZSTD_getCParamsExclusionMask(); state.callbackContext = NULL; state.exclusionMask = &exclusionMask; state.create = ZSTD_rust_createCDict_create; state.setCompressionLevel = ZSTD_rust_createCDict_setCompressionLevel; return (ZSTD_CDict*)ZSTD_rust_createCDict( &state, dict, dictSize, compressionLevel, ZSTD_dlm_byRef); } static void ZSTD_rust_freeCDict_freeWorkspace(void* context) { ZSTD_CDict* const cdict = (ZSTD_CDict*)context; ZSTD_cwksp_free(&cdict->workspace, cdict->customMem); } static void ZSTD_rust_freeCDict_freeObject(void* context) { ZSTD_CDict* const cdict = (ZSTD_CDict*)context; ZSTD_customFree(cdict, cdict->customMem); } size_t ZSTD_freeCDict(ZSTD_CDict* cdict) { ZSTD_rust_freeCDictState state; state.callbackContext = cdict; state.cdictInWorkspace = cdict == NULL ? 0 : ZSTD_cwksp_owns_buffer(&cdict->workspace, cdict); state.freeWorkspace = ZSTD_rust_freeCDict_freeWorkspace; state.freeObject = ZSTD_rust_freeCDict_freeObject; return ZSTD_rust_freeCDict(&state); } /*! ZSTD_initStaticCDict_advanced() : * Generate a digested dictionary in provided memory area. * workspace: The memory area to emplace the dictionary into. * Provided pointer must 8-bytes aligned. * It must outlive dictionary usage. * workspaceSize: Use ZSTD_estimateCDictSize() * to determine how large workspace must be. * cParams : use ZSTD_getCParams() to transform a compression level * into its relevant cParams. * @return : pointer to ZSTD_CDict*, or NULL if error (size too small) * Note : there is no corresponding "free" function. * Since workspace was allocated externally, it must be freed externally. */ typedef struct { void* workspace; size_t workspaceSize; const void* dict; size_t dictSize; ZSTD_dictLoadMethod_e dictLoadMethod; ZSTD_dictContentType_e dictContentType; ZSTD_compressionParameters cParams; ZSTD_cwksp workspaceState; ZSTD_CCtx_params params; } ZSTD_rust_initStaticCDictContext; static void ZSTD_rust_initStaticCDict_createWorkspace(void* opaque) { ZSTD_rust_initStaticCDictContext* const context = (ZSTD_rust_initStaticCDictContext*)opaque; ZSTD_cwksp_init(&context->workspaceState, context->workspace, context->workspaceSize, ZSTD_cwksp_static_alloc); } static void* ZSTD_rust_initStaticCDict_reserveObject(void* opaque) { ZSTD_rust_initStaticCDictContext* const context = (ZSTD_rust_initStaticCDictContext*)opaque; return ZSTD_cwksp_reserve_object(&context->workspaceState, sizeof(ZSTD_CDict)); } static void ZSTD_rust_initStaticCDict_moveWorkspace( void* opaque, void* cdict) { ZSTD_rust_initStaticCDictContext* const context = (ZSTD_rust_initStaticCDictContext*)opaque; ZSTD_cwksp_move(&((ZSTD_CDict*)cdict)->workspace, &context->workspaceState); } static void ZSTD_rust_initStaticCDict_initialize( void* opaque, void* cdict, int useRowMatchFinder) { ZSTD_rust_initStaticCDictContext* const context = (ZSTD_rust_initStaticCDictContext*)opaque; ZSTD_CDict* const dictionary = (ZSTD_CDict*)cdict; ZSTD_CCtx_params* const params = &context->params; ZSTD_CCtxParams_init(params, 0); params->cParams = context->cParams; params->useRowMatchFinder = (ZSTD_ParamSwitch_e)useRowMatchFinder; dictionary->useRowMatchFinder = (ZSTD_ParamSwitch_e)useRowMatchFinder; dictionary->compressionLevel = ZSTD_NO_CLEVEL; } static size_t ZSTD_rust_initStaticCDict_init(void* opaque, void* cdict) { ZSTD_rust_initStaticCDictContext const* const context = (const ZSTD_rust_initStaticCDictContext*)opaque; return ZSTD_initCDict_internal( (ZSTD_CDict*)cdict, context->dict, context->dictSize, context->dictLoadMethod, context->dictContentType, context->params); } const ZSTD_CDict* ZSTD_initStaticCDict( void* workspace, size_t workspaceSize, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_compressionParameters cParams) { ZSTD_rustCDictSizing const sizing = { sizeof(ZSTD_CDict), HUF_WORKSPACE_SIZE, ZSTD_HASHLOG3_MAX, sizeof(ZSTD_match_t), sizeof(ZSTD_optimal_t), ZSTD_RUST_ASAN_REDZONE_SIZE }; ZSTD_rust_initStaticCDictContext context; ZSTD_rust_initStaticCDictState state; DEBUGLOG(4, "ZSTD_initStaticCDict (dictSize==%u)", (unsigned)dictSize); /* Rust resolves row matching and computes the required workspace size; * these callbacks retain only private workspace and CDict operations. */ context.workspace = workspace; context.workspaceSize = workspaceSize; context.dict = dict; context.dictSize = dictSize; context.dictLoadMethod = dictLoadMethod; context.dictContentType = dictContentType; context.cParams = cParams; state.callbackContext = &context; state.workspace = workspace; state.workspaceSize = workspaceSize; state.dictSize = dictSize; state.dictLoadMethod = (size_t)dictLoadMethod; state.cParams = &cParams; state.sizing = &sizing; state.createWorkspace = ZSTD_rust_initStaticCDict_createWorkspace; state.reserveObject = ZSTD_rust_initStaticCDict_reserveObject; state.moveWorkspace = ZSTD_rust_initStaticCDict_moveWorkspace; state.initialize = ZSTD_rust_initStaticCDict_initialize; state.init = ZSTD_rust_initStaticCDict_init; return (const ZSTD_CDict*)ZSTD_rust_initStaticCDict(&state); } ZSTD_compressionParameters ZSTD_getCParamsFromCDict(const ZSTD_CDict* cdict) { ZSTD_rust_cdictQueryState state; assert(cdict != NULL); state.cParams = &cdict->matchState.cParams; state.dictID = NULL; return ZSTD_rust_getCParamsFromCDict(&state); } /*! ZSTD_getDictID_fromCDict() : * Provides the dictID of the dictionary loaded into `cdict`. * If @return == 0, the dictionary is not conformant to Zstandard specification, or empty. * Non-conformant dictionaries can still be loaded, but as content-only dictionaries. */ unsigned ZSTD_getDictID_fromCDict(const ZSTD_CDict* cdict) { ZSTD_rust_cdictQueryState state; state.cParams = NULL; state.dictID = cdict == NULL ? NULL : &cdict->dictID; return ZSTD_rust_getDictIDFromCDict(&state); } static void ZSTD_rust_compressBeginUsingCDict_initParams( void* cctxParams, const ZSTD_parameters* params, int compressionLevel) { ZSTD_CCtxParams_init_internal( (ZSTD_CCtx_params*)cctxParams, params, compressionLevel); } static void ZSTD_rust_compressBeginUsingCDict_adjustWindow( void* cctxParams, U32 minWindowLog) { ZSTD_CCtx_params* const params = (ZSTD_CCtx_params*)cctxParams; if (params->cParams.windowLog < minWindowLog) { params->cParams.windowLog = minWindowLog; } } static size_t ZSTD_rust_compressBeginUsingCDict_begin( void* context, const void* cdict, const void* cctxParams, U64 pledgedSrcSize) { return ZSTD_compressBegin_internal( (ZSTD_CCtx*)context, NULL, 0, ZSTD_dct_auto, ZSTD_dtlm_fast, (const ZSTD_CDict*)cdict, (const ZSTD_CCtx_params*)cctxParams, pledgedSrcSize, ZSTDb_not_buffered); } /* ZSTD_compressBegin_usingCDict_internal() : * Implementation of various ZSTD_compressBegin_usingCDict* functions. */ static size_t ZSTD_compressBegin_usingCDict_internal( ZSTD_CCtx* const cctx, const ZSTD_CDict* const cdict, ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize) { ZSTD_CCtx_params cctxParams; U32 const exclusionMask = ZSTD_getCParamsExclusionMask(); ZSTD_rust_compressBeginUsingCDictState state; DEBUGLOG(4, "ZSTD_compressBegin_usingCDict_internal"); state.cctx = cctx; state.cdict = cdict; state.cctxParams = &cctxParams; state.cdictCParams = cdict == NULL ? NULL : &cdict->matchState.cParams; state.cdictContentSize = cdict == NULL ? NULL : &cdict->dictContentSize; state.cdictCompressionLevel = cdict == NULL ? NULL : &cdict->compressionLevel; state.fParams = &fParams; state.pledgedSrcSize = &pledgedSrcSize; state.exclusionMask = &exclusionMask; state.initParams = ZSTD_rust_compressBeginUsingCDict_initParams; state.adjustWindow = ZSTD_rust_compressBeginUsingCDict_adjustWindow; state.begin = ZSTD_rust_compressBeginUsingCDict_begin; return ZSTD_rust_compressBeginUsingCDict(&state); } static size_t ZSTD_rust_compressBeginUsingCDictPublic_begin( void* context, const void* cdict, const ZSTD_frameParameters* fParams, U64 pledgedSrcSize) { return ZSTD_compressBegin_usingCDict_internal( (ZSTD_CCtx*)context, (const ZSTD_CDict*)cdict, *fParams, pledgedSrcSize); } /* ZSTD_compressBegin_usingCDict_advanced() : * This function is DEPRECATED. * cdict must be != NULL */ size_t ZSTD_compressBegin_usingCDict_advanced( ZSTD_CCtx* const cctx, const ZSTD_CDict* const cdict, ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize) { return ZSTD_compressBegin_usingCDict_internal(cctx, cdict, fParams, pledgedSrcSize); } /* ZSTD_compressBegin_usingCDict() : * cdict must be != NULL */ size_t ZSTD_compressBegin_usingCDict_deprecated(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict) { ZSTD_rust_compressBeginUsingCDictPublicState state; state.callbackContext = cctx; state.cdict = cdict; state.begin = ZSTD_rust_compressBeginUsingCDictPublic_begin; return ZSTD_rust_compressBeginUsingCDictPublic(&state); } size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict) { return ZSTD_compressBegin_usingCDict_deprecated(cctx, cdict); } static size_t ZSTD_rust_compressUsingCDict_begin( void* context, const void* cdict, const ZSTD_frameParameters* fParams, U64 pledgedSrcSize) { return ZSTD_compressBegin_usingCDict_internal( (ZSTD_CCtx*)context, (const ZSTD_CDict*)cdict, *fParams, pledgedSrcSize); } static size_t ZSTD_rust_compressUsingCDict_end( void* context, void* dst, size_t dstCapacity, const void* src, size_t srcSize) { return ZSTD_compressEnd_dispatch( (ZSTD_CCtx*)context, dst, dstCapacity, src, srcSize); } /*! ZSTD_compress_usingCDict_advanced(): * This function is DEPRECATED. */ size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, const ZSTD_CDict* cdict, ZSTD_frameParameters fParams) { ZSTD_rust_compressUsingCDictAdvancedState state; state.callbackContext = cctx; state.cdict = cdict; state.fParams = &fParams; state.begin = ZSTD_rust_compressUsingCDict_begin; state.end = ZSTD_rust_compressUsingCDict_end; return ZSTD_rust_compressUsingCDictAdvanced( &state, dst, dstCapacity, src, srcSize); } /*! ZSTD_compress_usingCDict() : * Compression using a digested Dictionary. * Faster startup than ZSTD_compress_usingDict(), recommended when same dictionary is used multiple times. * Note that compression parameters are decided at CDict creation time * while frame parameters are hardcoded */ size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, const ZSTD_CDict* cdict) { ZSTD_rust_compressUsingCDictState state; state.callbackContext = cctx; state.cdict = cdict; state.begin = ZSTD_rust_compressUsingCDict_begin; state.end = ZSTD_rust_compressUsingCDict_end; return ZSTD_rust_compressUsingCDict( &state, dst, dstCapacity, src, srcSize); } /* ****************************************************************** * Streaming ********************************************************************/ ZSTD_CStream* ZSTD_createCStream(void) { DEBUGLOG(3, "ZSTD_createCStream"); return ZSTD_createCStream_advanced(ZSTD_defaultCMem); } ZSTD_CStream* ZSTD_initStaticCStream(void *workspace, size_t workspaceSize) { return ZSTD_initStaticCCtx(workspace, workspaceSize); } ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem) { /* CStream and CCtx are now same object */ return ZSTD_createCCtx_advanced(customMem); } size_t ZSTD_freeCStream(ZSTD_CStream* zcs) { return ZSTD_freeCCtx(zcs); /* same object */ } /*====== Initialization ======*/ static ZSTD_CParamMode_e ZSTD_getCParamMode(ZSTD_CDict const* cdict, ZSTD_CCtx_params const* params, U64 pledgedSrcSize) { int const cdict_present = cdict != NULL; int const cdict_strategy = cdict_present ? cdict->matchState.cParams.strategy : 0; int const cdict_dedicated_search = cdict_present ? cdict->matchState.dedicatedDictSearch : 0; return (ZSTD_CParamMode_e)ZSTD_rust_params_getCParamMode( cdict_present, cdict_strategy, cdict_dedicated_search, pledgedSrcSize, (int)params->attachDictPref, params->forceWindow); } /* ZSTD_resetCStream(): * pledgedSrcSize == 0 means "unknown" */ static size_t ZSTD_rust_resetCStream_resetSession(void* context) { return ZSTD_CCtx_reset((ZSTD_CCtx*)context, ZSTD_reset_session_only); } static size_t ZSTD_rust_resetCStream_setPledgedSrcSize( void* context, unsigned long long pledgedSrcSize) { return ZSTD_CCtx_setPledgedSrcSize((ZSTD_CCtx*)context, pledgedSrcSize); } size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pss) { ZSTD_rust_resetCStreamState state; state.callbackContext = zcs; state.resetSession = ZSTD_rust_resetCStream_resetSession; state.setPledgedSrcSize = ZSTD_rust_resetCStream_setPledgedSrcSize; return ZSTD_rust_resetCStream(&state, pss); } /*! ZSTD_initCStream_internal() : * Note : for lib/compress only. Used by zstdmt_compress.c. * Assumption 1 : params are valid * Assumption 2 : either dict, or cdict, is defined, not both */ size_t ZSTD_initCStream_internal(ZSTD_CStream* zcs, const void* dict, size_t dictSize, const ZSTD_CDict* cdict, const ZSTD_CCtx_params* params, unsigned long long pledgedSrcSize) { DEBUGLOG(4, "ZSTD_initCStream_internal"); FORWARD_IF_ERROR( ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only) , ""); FORWARD_IF_ERROR( ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize) , ""); assert(!ZSTD_isError(ZSTD_checkCParams(params->cParams))); zcs->requestedParams = *params; assert(!((dict) && (cdict))); /* either dict or cdict, not both */ if (dict) { FORWARD_IF_ERROR( ZSTD_CCtx_loadDictionary(zcs, dict, dictSize) , ""); } else { /* Dictionary is cleared if !cdict */ FORWARD_IF_ERROR( ZSTD_CCtx_refCDict(zcs, cdict) , ""); } return 0; } /* ZSTD_initCStream_usingCDict_advanced() : * same as ZSTD_initCStream_usingCDict(), with control over frame parameters */ static size_t ZSTD_rust_initCStreamUsingCDictAdvanced_resetSession(void* context) { return ZSTD_CCtx_reset((ZSTD_CCtx*)context, ZSTD_reset_session_only); } static size_t ZSTD_rust_initCStreamUsingCDictAdvanced_setPledgedSrcSize( void* context, unsigned long long pledgedSrcSize) { return ZSTD_CCtx_setPledgedSrcSize((ZSTD_CCtx*)context, pledgedSrcSize); } static void ZSTD_rust_initCStreamUsingCDictAdvanced_setFrameParams( void* context, unsigned contentSizeFlag, unsigned checksumFlag, unsigned noDictIDFlag) { ZSTD_CCtx* const zcs = (ZSTD_CCtx*)context; zcs->requestedParams.fParams.contentSizeFlag = contentSizeFlag; zcs->requestedParams.fParams.checksumFlag = checksumFlag; zcs->requestedParams.fParams.noDictIDFlag = noDictIDFlag; } static size_t ZSTD_rust_initCStreamUsingCDictAdvanced_refCDict( void* context, const void* cdict) { return ZSTD_CCtx_refCDict((ZSTD_CCtx*)context, (const ZSTD_CDict*)cdict); } size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const ZSTD_CDict* cdict, ZSTD_frameParameters fParams, unsigned long long pledgedSrcSize) { ZSTD_rust_initCStreamUsingCDictAdvancedState state; DEBUGLOG(4, "ZSTD_initCStream_usingCDict_advanced"); state.callbackContext = zcs; state.resetSession = ZSTD_rust_initCStreamUsingCDictAdvanced_resetSession; state.setPledgedSrcSize = ZSTD_rust_initCStreamUsingCDictAdvanced_setPledgedSrcSize; state.setFrameParams = ZSTD_rust_initCStreamUsingCDictAdvanced_setFrameParams; state.refCDict = ZSTD_rust_initCStreamUsingCDictAdvanced_refCDict; return ZSTD_rust_initCStreamUsingCDictAdvanced( &state, pledgedSrcSize, fParams.contentSizeFlag, fParams.checksumFlag, fParams.noDictIDFlag, cdict); } /* note : cdict must outlive compression session */ size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict) { ZSTD_rust_initCStreamUsingCDictState state; DEBUGLOG(4, "ZSTD_initCStream_usingCDict"); state.callbackContext = zcs; state.resetSession = ZSTD_rust_initCStreamUsingCDictAdvanced_resetSession; state.refCDict = ZSTD_rust_initCStreamUsingCDictAdvanced_refCDict; return ZSTD_rust_initCStreamUsingCDict(&state, cdict); } /* ZSTD_initCStream_advanced() : * pledgedSrcSize must be exact. * if srcSize is not known at init time, use value ZSTD_CONTENTSIZE_UNKNOWN. * dict is loaded with default parameters ZSTD_dct_auto and ZSTD_dlm_byCopy. */ static size_t ZSTD_rust_initCStreamAdvanced_checkCParams( void* context, ZSTD_compressionParameters cParams) { (void)context; return ZSTD_checkCParams(cParams); } static void ZSTD_rust_initCStreamAdvanced_setZstdParams( void* context, const ZSTD_parameters* params) { ZSTD_CCtx* const zcs = (ZSTD_CCtx*)context; ZSTD_CCtxParams_setZstdParams(&zcs->requestedParams, params); } static size_t ZSTD_rust_initCStreamUsingDict_loadDictionary( void* context, const void* dict, size_t dictSize) { return ZSTD_CCtx_loadDictionary((ZSTD_CCtx*)context, dict, dictSize); } size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize, ZSTD_parameters params, unsigned long long pss) { ZSTD_rust_initCStreamAdvancedState state; /* for compatibility with older programs relying on this behavior. * Users should now specify ZSTD_CONTENTSIZE_UNKNOWN. * This line will be removed in the future. */ DEBUGLOG(4, "ZSTD_initCStream_advanced"); state.callbackContext = zcs; state.resetSession = ZSTD_rust_initCStreamUsingCDictAdvanced_resetSession; state.setPledgedSrcSize = ZSTD_rust_initCStreamUsingCDictAdvanced_setPledgedSrcSize; state.checkCParams = ZSTD_rust_initCStreamAdvanced_checkCParams; state.setZstdParams = ZSTD_rust_initCStreamAdvanced_setZstdParams; state.loadDictionary = ZSTD_rust_initCStreamUsingDict_loadDictionary; return ZSTD_rust_initCStreamAdvanced(&state, ¶ms, pss, dict, dictSize); } static size_t ZSTD_rust_initCStreamSrcSize_setLevel( void* context, int compressionLevel) { return ZSTD_CCtx_setParameter( (ZSTD_CCtx*)context, ZSTD_c_compressionLevel, compressionLevel); } size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel) { ZSTD_rust_initCStreamUsingDictState state; DEBUGLOG(4, "ZSTD_initCStream_usingDict"); state.callbackContext = zcs; state.resetSession = ZSTD_rust_initCStreamUsingCDictAdvanced_resetSession; state.setLevel = ZSTD_rust_initCStreamSrcSize_setLevel; state.loadDictionary = ZSTD_rust_initCStreamUsingDict_loadDictionary; return ZSTD_rust_initCStreamUsingDict( &state, dict, dictSize, compressionLevel); } size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pss) { ZSTD_rust_initCStreamSrcSizeState state; /* temporary : 0 interpreted as "unknown" during transition period. * Users willing to specify "unknown" **must** use ZSTD_CONTENTSIZE_UNKNOWN. * 0 will be interpreted as "empty" in the future. */ DEBUGLOG(4, "ZSTD_initCStream_srcSize"); state.callbackContext = zcs; state.resetSession = ZSTD_rust_initCStreamUsingCDictAdvanced_resetSession; state.refCDict = ZSTD_rust_initCStreamUsingCDictAdvanced_refCDict; state.setLevel = ZSTD_rust_initCStreamSrcSize_setLevel; state.setPledgedSrcSize = ZSTD_rust_initCStreamUsingCDictAdvanced_setPledgedSrcSize; return ZSTD_rust_initCStreamSrcSize(&state, pss, compressionLevel); } size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel) { ZSTD_rust_initCStreamState state; DEBUGLOG(4, "ZSTD_initCStream"); state.callbackContext = zcs; state.resetSession = ZSTD_rust_initCStreamUsingCDictAdvanced_resetSession; state.refCDict = ZSTD_rust_initCStreamUsingCDictAdvanced_refCDict; state.setLevel = ZSTD_rust_initCStreamSrcSize_setLevel; return ZSTD_rust_initCStream(&state, compressionLevel); } /*====== Compression ======*/ /** ZSTD_compressStream_generic(): * internal function for all *compressStream*() variants * @return : hint size for next input to complete ongoing block */ static size_t ZSTD_rust_compressStream_reset(void* context) { return ZSTD_CCtx_reset((ZSTD_CCtx*)context, ZSTD_reset_session_only); } static size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input, ZSTD_EndDirective const flushMode) { ZSTD_rust_compressContinueContext continueContext; ZSTD_rust_compressEndState endState; ZSTD_rust_compressStreamState state; ZSTD_CCtx* const cctx = (ZSTD_CCtx*)zcs; ZSTD_compressContinue_prepare(cctx, cctx->blockSizeMax, 0 /* block size already selected */, &continueContext); endState.callbackContext = zcs; endState.compressContinueState = &continueContext.state; endState.trace = ZSTD_rust_compressEnd_trace; endState.consumedSrcSize = &cctx->consumedSrcSize; endState.pledgedSrcSizePlusOne = cctx->pledgedSrcSizePlusOne; endState.contentSizeFlag = cctx->appliedParams.fParams.contentSizeFlag; endState.stage = (int*)&cctx->stage; endState.noDictIDFlag = cctx->appliedParams.fParams.noDictIDFlag; endState.checksumFlag = cctx->appliedParams.fParams.checksumFlag; endState.format = (int)cctx->appliedParams.format; endState.windowLog = cctx->appliedParams.cParams.windowLog; endState.checksumState = &cctx->xxhState; state.callbackContext = zcs; state.inBufferMode = (int)zcs->appliedParams.inBufferMode; state.outBufferMode = (int)zcs->appliedParams.outBufferMode; state.streamStage = &zcs->streamStage; state.blockSizeMax = zcs->blockSizeMax; state.stableInNotConsumed = &zcs->stableIn_notConsumed; state.inBuff = zcs->inBuff; state.inBuffSize = zcs->inBuffSize; state.inToCompress = &zcs->inToCompress; state.inBuffPos = &zcs->inBuffPos; state.inBuffTarget = &zcs->inBuffTarget; state.outBuff = zcs->outBuff; state.outBuffSize = zcs->outBuffSize; state.outBuffContentSize = &zcs->outBuffContentSize; state.outBuffFlushedSize = &zcs->outBuffFlushedSize; state.frameEnded = &zcs->frameEnded; state.compressContinueState = &continueContext.state; state.compressEndState = &endState; state.resetSession = ZSTD_rust_compressStream_reset; return ZSTD_rust_compressStreamGeneric( &state, output, input, (int)flushMode); } /* Keep the MT context opaque to Rust; only its existing C hint leaf crosses * this callback boundary. */ #ifdef ZSTD_MULTITHREAD static size_t ZSTD_nextInputSizeHint_MT(void* context) { return ZSTDMT_nextInputSizeHint((const ZSTDMT_CCtx*)context); } #endif static size_t ZSTD_nextInputSizeHint_MTorST(const ZSTD_CCtx* cctx) { int const inBufferMode = (int)cctx->appliedParams.inBufferMode; ZSTD_rust_nextInputSizeHintMTorSTState state = { cctx->blockSizeMax, cctx->stableIn_notConsumed, cctx->inBuffTarget, cctx->inBuffPos, 0, inBufferMode, NULL, NULL }; if (inBufferMode != ZSTD_bm_stable) { assert(inBufferMode == ZSTD_bm_buffered); } #ifdef ZSTD_MULTITHREAD state.nbWorkers = cctx->appliedParams.nbWorkers; state.mtContext = cctx->mtctx; state.mtNextInputSizeHint = ZSTD_nextInputSizeHint_MT; if (state.nbWorkers >= 1) { assert(state.mtContext != NULL); } #endif return ZSTD_rust_nextInputSizeHintMTorST(&state); } size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input) { FORWARD_IF_ERROR( ZSTD_compressStream2(zcs, output, input, ZSTD_e_continue) , ""); return ZSTD_nextInputSizeHint_MTorST(zcs); } /* After a compression call set the expected input/output buffer. * This is validated at the start of the next compression call. */ static void ZSTD_setBufferExpectations(ZSTD_CCtx* cctx, const ZSTD_outBuffer* output, const ZSTD_inBuffer* input) { DEBUGLOG(5, "ZSTD_setBufferExpectations (for advanced stable in/out modes)"); ZSTD_rust_setBufferExpectations( (int)cctx->appliedParams.inBufferMode, (int)cctx->appliedParams.outBufferMode, &cctx->expectedInBuffer, &cctx->expectedOutBufferSize, output, input); } static void ZSTD_rust_compressStream2_setBufferExpectations( void* context, const void* output, const void* input) { ZSTD_setBufferExpectations( (ZSTD_CCtx*)context, (const ZSTD_outBuffer*)output, (const ZSTD_inBuffer*)input); } /* Validate that the input/output buffers match the expectations set by * ZSTD_setBufferExpectations. */ static size_t ZSTD_checkBufferStability(ZSTD_CCtx const* cctx, ZSTD_outBuffer const* output, ZSTD_inBuffer const* input) { return ZSTD_rust_checkBufferStability( (int)cctx->appliedParams.inBufferMode, (int)cctx->appliedParams.outBufferMode, cctx->expectedInBuffer.src, cctx->expectedInBuffer.pos, input->src, input->pos, cctx->expectedOutBufferSize, output->size, output->pos); } /* * If @endOp == ZSTD_e_end, @inSize becomes pledgedSrcSize. * Otherwise, it's ignored. * @return: 0 on success, or a ZSTD_error code otherwise. */ enum { ZSTD_RUST_INIT_RESOLVE_BLOCK_SPLITTER = 0, ZSTD_RUST_INIT_RESOLVE_LDM = 1, ZSTD_RUST_INIT_RESOLVE_ROW_MATCH_FINDER = 2, ZSTD_RUST_INIT_RESOLVE_VALIDATE_SEQUENCES = 3, ZSTD_RUST_INIT_RESOLVE_MAX_BLOCK_SIZE = 4, ZSTD_RUST_INIT_RESOLVE_EXTERNAL_REPCODE_SEARCH = 5 }; static void ZSTD_rust_compressStreamInit_getLocalDict( void* context, ZSTD_rust_compressStreamInitLocalDictState* state) { ZSTD_CCtx const* const cctx = (ZSTD_CCtx const*)context; ZSTD_localDict const* const localDict = &cctx->localDict; state->dict = localDict->dict; state->dictBuffer = localDict->dictBuffer; state->dictSize = localDict->dictSize; state->dictContentType = (int)localDict->dictContentType; state->localCDict = (void*)localDict->cdict; state->cdict = cctx->cdict; state->prefixDict = cctx->prefixDict.dict; state->createdCDict = NULL; } static size_t ZSTD_rust_compressStreamInit_createLocalDict( void* context, ZSTD_rust_compressStreamInitLocalDictState* state) { ZSTD_CCtx const* const cctx = (ZSTD_CCtx const*)context; ZSTD_CDict* const cdict = ZSTD_createCDict_advanced2( state->dict, state->dictSize, ZSTD_dlm_byRef, (ZSTD_dictContentType_e)state->dictContentType, &cctx->requestedParams, cctx->customMem); RETURN_ERROR_IF(!cdict, memory_allocation, "ZSTD_createCDict_advanced failed"); state->createdCDict = cdict; return 0; } static void ZSTD_rust_compressStreamInit_publishLocalDict( void* context, const ZSTD_rust_compressStreamInitLocalDictState* state) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; cctx->localDict.cdict = (ZSTD_CDict*)state->createdCDict; cctx->cdict = cctx->localDict.cdict; } static void ZSTD_rust_compressStreamInit_refreshCDict( void* context, ZSTD_rust_compressStreamInitDictionaryState* state) { ZSTD_CCtx const* const cctx = (ZSTD_CCtx const*)context; state->cdict = cctx->cdict; state->cdictIsLocal = cctx->localDict.cdict != NULL; state->cdictCompressionLevel = cctx->cdict ? cctx->cdict->compressionLevel : 0; state->cdictDictContentSize = cctx->cdict ? cctx->cdict->dictContentSize : 0; } static void ZSTD_rust_compressStreamInit_clearPrefix(void* context) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; ZSTD_memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict)); } static void ZSTD_rust_compressStreamInit_assertDictionaries( void* context, const void* prefixDict) { ZSTD_CCtx const* const cctx = (ZSTD_CCtx const*)context; (void)cctx; (void)prefixDict; assert(prefixDict == NULL || cctx->cdict == NULL); } static void ZSTD_rust_compressStreamInit_setLevel(void* params, int level) { ((ZSTD_CCtx_params*)params)->compressionLevel = level; } static void ZSTD_rust_compressStreamInit_debug(void* context) { (void)context; DEBUGLOG(4, "ZSTD_CCtx_init_compressStream2 : transparent init stage"); } static U64 ZSTD_rust_compressStreamInit_getPledged(void* context) { return ((ZSTD_CCtx const*)context)->pledgedSrcSizePlusOne; } static void ZSTD_rust_compressStreamInit_setPledged(void* context, size_t inSize) { ((ZSTD_CCtx*)context)->pledgedSrcSizePlusOne = inSize + 1; } static int ZSTD_rust_compressStreamInit_getCParamMode( void* params, const void* cdict, U64 pledgedSrcSize) { return (int)ZSTD_getCParamMode( (const ZSTD_CDict*)cdict, (const ZSTD_CCtx_params*)params, pledgedSrcSize); } static void ZSTD_rust_compressStreamInit_buildCParams( void* params, U64 pledgedSrcSize, size_t dictSize, int mode) { ZSTD_CCtx_params* const cctxParams = (ZSTD_CCtx_params*)params; cctxParams->cParams = ZSTD_getCParamsFromCCtxParams( cctxParams, pledgedSrcSize, dictSize, (ZSTD_CParamMode_e)mode); } static void ZSTD_rust_compressStreamInit_resolveParams(void* params, int operation) { ZSTD_CCtx_params* const cctxParams = (ZSTD_CCtx_params*)params; switch (operation) { case ZSTD_RUST_INIT_RESOLVE_BLOCK_SPLITTER: cctxParams->postBlockSplitter = (ZSTD_ParamSwitch_e) ZSTD_resolveBlockSplitterMode( (int)cctxParams->postBlockSplitter, cctxParams->cParams); break; case ZSTD_RUST_INIT_RESOLVE_LDM: cctxParams->ldmParams.enableLdm = (ZSTD_ParamSwitch_e) ZSTD_resolveEnableLdm( (int)cctxParams->ldmParams.enableLdm, cctxParams->cParams); break; case ZSTD_RUST_INIT_RESOLVE_ROW_MATCH_FINDER: cctxParams->useRowMatchFinder = (ZSTD_ParamSwitch_e) ZSTD_resolveRowMatchFinderMode( (int)cctxParams->useRowMatchFinder, cctxParams->cParams); break; case ZSTD_RUST_INIT_RESOLVE_VALIDATE_SEQUENCES: cctxParams->validateSequences = ZSTD_resolveExternalSequenceValidation( cctxParams->validateSequences); break; case ZSTD_RUST_INIT_RESOLVE_MAX_BLOCK_SIZE: cctxParams->maxBlockSize = ZSTD_resolveMaxBlockSize(cctxParams->maxBlockSize); break; case ZSTD_RUST_INIT_RESOLVE_EXTERNAL_REPCODE_SEARCH: cctxParams->searchForExternalRepcodes = (ZSTD_ParamSwitch_e) ZSTD_resolveExternalRepcodeSearch( (int)cctxParams->searchForExternalRepcodes, cctxParams->compressionLevel); break; default: assert(0); break; } } static unsigned ZSTD_rust_compressStreamInit_getNbWorkers(void* params) { return ((ZSTD_CCtx_params const*)params)->nbWorkers; } static void ZSTD_rust_compressStreamInit_setNbWorkers(void* params, unsigned nbWorkers) { ((ZSTD_CCtx_params*)params)->nbWorkers = nbWorkers; } static int ZSTD_rust_compressStreamInit_hasExtSeqProd(void* params) { return ZSTD_hasExtSeqProd((ZSTD_CCtx_params const*)params); } static void ZSTD_rust_compressStreamInit_trace(void* context) { #if ZSTD_TRACE ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; cctx->traceCtx = (ZSTD_trace_compress_begin != NULL) ? ZSTD_trace_compress_begin(cctx) : 0; #else (void)context; #endif } static void* ZSTD_rust_compressStreamInit_getMTContext(void* context) { #ifdef ZSTD_MULTITHREAD return ((ZSTD_CCtx*)context)->mtctx; #else (void)context; return NULL; #endif } static size_t ZSTD_rust_compressStreamInit_createMTContext( void* context, unsigned nbWorkers) { #ifdef ZSTD_MULTITHREAD ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; DEBUGLOG(4, "ZSTD_compressStream2: creating new mtctx for nbWorkers=%u", nbWorkers); cctx->mtctx = ZSTDMT_createCCtx_advanced( (U32)nbWorkers, cctx->customMem, cctx->pool); RETURN_ERROR_IF(cctx->mtctx == NULL, memory_allocation, "NULL pointer!"); return 0; #else (void)context; (void)nbWorkers; return ERROR(memory_allocation); #endif } static size_t ZSTD_rust_compressStreamInit_mt( void* context, void* mtctx, const ZSTD_rust_compressStreamInitDictionaryState* dictionaries, void* params, U64 pledgedSrcSize) { #ifdef ZSTD_MULTITHREAD (void)context; DEBUGLOG(4, "call ZSTDMT_initCStream_internal as nbWorkers=%u", ((ZSTD_CCtx_params const*)params)->nbWorkers); return ZSTDMT_initCStream_internal( (ZSTDMT_CCtx*)mtctx, dictionaries->prefixDict, dictionaries->prefixDictSize, (ZSTD_dictContentType_e)dictionaries->prefixDictContentType, (const ZSTD_CDict*)dictionaries->cdict, *(const ZSTD_CCtx_params*)params, pledgedSrcSize); #else (void)context; (void)mtctx; (void)dictionaries; (void)params; (void)pledgedSrcSize; return ERROR(memory_allocation); #endif } static void ZSTD_rust_compressStreamInit_commitMT( void* context, const ZSTD_rust_compressStreamInitDictionaryState* dictionaries, void* params) { #ifdef ZSTD_MULTITHREAD ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; cctx->dictID = cctx->cdict ? cctx->cdict->dictID : 0; cctx->dictContentSize = cctx->cdict ? cctx->cdict->dictContentSize : dictionaries->prefixDictSize; cctx->consumedSrcSize = 0; cctx->producedCSize = 0; cctx->streamStage = zcss_load; cctx->appliedParams = *(const ZSTD_CCtx_params*)params; #else (void)context; (void)dictionaries; (void)params; #endif } static void ZSTD_rust_compressStreamInit_checkCParams(void* params) { (void)params; assert(!ZSTD_isError(ZSTD_checkCParams( ((ZSTD_CCtx_params const*)params)->cParams))); } static size_t ZSTD_rust_compressStreamInit_begin( void* context, const ZSTD_rust_compressStreamInitDictionaryState* dictionaries, void* params, U64 pledgedSrcSize) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; return ZSTD_compressBegin_internal( cctx, dictionaries->prefixDict, dictionaries->prefixDictSize, (ZSTD_dictContentType_e)dictionaries->prefixDictContentType, ZSTD_dtlm_fast, (const ZSTD_CDict*)dictionaries->cdict, (const ZSTD_CCtx_params*)params, pledgedSrcSize, ZSTDb_buffered); } static void ZSTD_rust_compressStreamInit_assertOrdinary(void* context) { (void)context; assert(((ZSTD_CCtx const*)context)->appliedParams.nbWorkers == 0); } static int ZSTD_rust_compressStreamInit_getBufferMode(void* context) { return (int)((ZSTD_CCtx const*)context)->appliedParams.inBufferMode; } static size_t ZSTD_rust_compressStreamInit_getBlockSize(void* context) { return ((ZSTD_CCtx const*)context)->blockSizeMax; } static void ZSTD_rust_compressStreamInit_commitOrdinary( void* context, size_t inBuffTarget) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; cctx->inToCompress = 0; cctx->inBuffPos = 0; cctx->inBuffTarget = inBuffTarget; cctx->outBuffContentSize = cctx->outBuffFlushedSize = 0; cctx->streamStage = zcss_load; cctx->frameEnded = 0; } static size_t ZSTD_CCtx_init_compressStream2(ZSTD_CCtx* cctx, ZSTD_EndDirective endOp, size_t inSize) { ZSTD_CCtx_params params = cctx->requestedParams; ZSTD_prefixDict const prefixDict = cctx->prefixDict; ZSTD_rust_compressStreamInitDictionaryState dictionaries = { prefixDict.dict, prefixDict.dictSize, (int)prefixDict.dictContentType, NULL, 0, 0, 0 }; ZSTD_rust_compressStreamInitState state = { cctx, ¶ms, &dictionaries, (int)endOp, inSize, #ifdef ZSTD_MULTITHREAD 1, ZSTDMT_JOBSIZE_MIN, #else 0, 0, #endif ZSTD_rust_compressStreamInit_getLocalDict, ZSTD_rust_compressStreamInit_createLocalDict, ZSTD_rust_compressStreamInit_publishLocalDict, ZSTD_rust_compressStreamInit_refreshCDict, ZSTD_rust_compressStreamInit_clearPrefix, ZSTD_rust_compressStreamInit_assertDictionaries, ZSTD_rust_compressStreamInit_setLevel, ZSTD_rust_compressStreamInit_debug, ZSTD_rust_compressStreamInit_getPledged, ZSTD_rust_compressStreamInit_setPledged, ZSTD_rust_compressStreamInit_getCParamMode, ZSTD_rust_compressStreamInit_buildCParams, ZSTD_rust_compressStreamInit_resolveParams, ZSTD_rust_compressStreamInit_getNbWorkers, ZSTD_rust_compressStreamInit_setNbWorkers, ZSTD_rust_compressStreamInit_hasExtSeqProd, ZSTD_rust_compressStreamInit_trace, ZSTD_rust_compressStreamInit_getMTContext, ZSTD_rust_compressStreamInit_createMTContext, ZSTD_rust_compressStreamInit_mt, ZSTD_rust_compressStreamInit_commitMT, ZSTD_rust_compressStreamInit_checkCParams, ZSTD_rust_compressStreamInit_begin, ZSTD_rust_compressStreamInit_assertOrdinary, ZSTD_rust_compressStreamInit_getBufferMode, ZSTD_rust_compressStreamInit_getBlockSize, ZSTD_rust_compressStreamInit_commitOrdinary }; return ZSTD_rust_compressStreamInit(&state); } /* @return provides a minimum amount of data remaining to be flushed from internal buffers */ #ifdef ZSTD_MULTITHREAD static void ZSTD_rust_compressStream2MT_trace(void* context) { ZSTD_CCtx_trace((ZSTD_CCtx*)context, 0); } static size_t ZSTD_rust_compressStream2MT_reset(void* context) { return ZSTD_CCtx_reset((ZSTD_CCtx*)context, ZSTD_reset_session_only); } static size_t ZSTD_rust_compressStream2MT_step( void* context, ZSTD_outBuffer* output, ZSTD_inBuffer* input, int endOp) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; size_t const ipos = input->pos; size_t const opos = output->pos; size_t const flushMin = ZSTDMT_compressStream_generic( cctx->mtctx, output, input, (ZSTD_EndDirective)endOp); cctx->consumedSrcSize += (U64)(input->pos - ipos); cctx->producedCSize += (U64)(output->pos - opos); return flushMin; } #endif /* ZSTD_MULTITHREAD */ static size_t ZSTD_rust_compressStream2_init(void* context, int endOp, size_t inputSize) { return ZSTD_CCtx_init_compressStream2( (ZSTD_CCtx*)context, (ZSTD_EndDirective)endOp, inputSize); } static size_t ZSTD_rust_compressStream2_checkBuffer( void* context, const void* output, const void* input) { return ZSTD_checkBufferStability( (const ZSTD_CCtx*)context, (const ZSTD_outBuffer*)output, (const ZSTD_inBuffer*)input); } static size_t ZSTD_rust_compressStream2_compressStream( void* context, ZSTD_outBuffer* output, ZSTD_inBuffer* input, int endOp) { return ZSTD_compressStream_generic( (ZSTD_CStream*)context, output, input, (ZSTD_EndDirective)endOp); } #ifdef ZSTD_MULTITHREAD static void ZSTD_rust_compressStream2_updateMTCParams(void* context) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; ZSTDMT_updateCParams_whileCompressing(cctx->mtctx, &cctx->requestedParams); } #endif size_t ZSTD_compressStream2_c( ZSTD_CCtx* cctx, ZSTD_outBuffer* output, ZSTD_inBuffer* input, ZSTD_EndDirective endOp) { ZSTD_rust_compressStream2Fields const fields = { cctx, output, input, (int*)&cctx->streamStage, &cctx->stableIn_notConsumed, &cctx->expectedInBuffer, &cctx->rustSimpleCompress2Completed, &cctx->cParamsChanged, &cctx->outBuffContentSize, &cctx->outBuffFlushedSize, cctx->pledgedSrcSizePlusOne, (int)cctx->requestedParams.inBufferMode, (int)cctx->requestedParams.outBufferMode, (int)cctx->requestedParams.format, &cctx->appliedParams.nbWorkers, }; ZSTD_rust_compressStream2Callbacks const callbacks = { ZSTD_rust_compressStream2_init, ZSTD_rust_compressStream2_checkBuffer, ZSTD_rust_compressStream2_setBufferExpectations, ZSTD_rust_compressStream2_compressStream, #ifdef ZSTD_MULTITHREAD ZSTD_rust_compressStream2_updateMTCParams, ZSTD_rust_compressStream2MT_step, ZSTD_rust_compressStream2MT_trace, ZSTD_rust_compressStream2MT_reset, #else NULL, NULL, NULL, NULL, #endif }; ZSTD_rust_compressStream2State const state = { &fields, &callbacks, (int)endOp, }; return ZSTD_rust_compressStream2(&state); } size_t ZSTD_compressStream2_simpleArgs ( ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, size_t* dstPos, const void* src, size_t srcSize, size_t* srcPos, ZSTD_EndDirective endOp) { ZSTD_outBuffer output; ZSTD_inBuffer input; output.dst = dst; output.size = dstCapacity; output.pos = *dstPos; input.src = src; input.size = srcSize; input.pos = *srcPos; /* ZSTD_compressStream2() will check validity of dstPos and srcPos */ { size_t const cErr = ZSTD_compressStream2(cctx, &output, &input, endOp); *dstPos = output.pos; *srcPos = input.pos; return cErr; } } static size_t ZSTD_rust_compress2_resetSession(void* context) { return ZSTD_CCtx_reset((ZSTD_CCtx*)context, ZSTD_reset_session_only); } static void ZSTD_rust_compress2_setBufferModes( void* context, int inBufferMode, int outBufferMode) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; cctx->requestedParams.inBufferMode = (ZSTD_bufferMode_e)inBufferMode; cctx->requestedParams.outBufferMode = (ZSTD_bufferMode_e)outBufferMode; } static size_t ZSTD_rust_compress2_streamEnd( void* context, void* dst, size_t dstCapacity, size_t* dstPos, const void* src, size_t srcSize, size_t* srcPos) { return ZSTD_compressStream2_simpleArgs( (ZSTD_CCtx*)context, dst, dstCapacity, dstPos, src, srcSize, srcPos, ZSTD_e_end); } size_t ZSTD_compress2_c(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize) { ZSTD_rust_compress2State state; state.callbackContext = cctx; state.resetSession = ZSTD_rust_compress2_resetSession; state.setBufferModes = ZSTD_rust_compress2_setBufferModes; state.compressStreamEnd = ZSTD_rust_compress2_streamEnd; state.originalInBufferMode = (int)cctx->requestedParams.inBufferMode; state.originalOutBufferMode = (int)cctx->requestedParams.outBufferMode; DEBUGLOG(4, "ZSTD_compress2 (srcSize=%u)", (unsigned)srcSize); return ZSTD_rust_compress2(&state, dst, dstCapacity, src, srcSize); } /* The public symbol remains C-facing for fullbench and the sequence API, but * the sequence-store conversion itself is Rust-owned. */ size_t ZSTD_convertBlockSequences(ZSTD_CCtx* cctx, const ZSTD_Sequence* const inSeqs, size_t nbSequences, int repcodeResolution) { ZSTD_rust_convertBlockSequencesState state; DEBUGLOG(5, "ZSTD_convertBlockSequences (nbSequences = %zu)", nbSequences); state.seqStore = &cctx->seqStore; state.prevCBlock = &cctx->blockState.prevCBlock; state.nextCBlock = &cctx->blockState.nextCBlock; return ZSTD_rust_convertBlockSequences( &state, inSeqs, nbSequences, repcodeResolution); } static size_t ZSTD_convertBlockSequencesForRust( void* context, const ZSTD_Sequence* inSeqs, size_t nbSequences, int repcodeResolution) { return ZSTD_convertBlockSequences((ZSTD_CCtx*)context, inSeqs, nbSequences, repcodeResolution); } static void ZSTD_rust_sequenceApi_prepareStates( ZSTD_CCtx* cctx, ZSTD_rust_sequenceCompressionState* sequenceState, ZSTD_rust_sequenceLiteralsState* sequenceLiteralsState) { U32 dictSize; if (cctx->cdict) { dictSize = (U32)cctx->cdict->dictContentSize; } else if (cctx->prefixDict.dict) { dictSize = (U32)cctx->prefixDict.dictSize; } else { dictSize = 0; } sequenceState->seqStore = &cctx->seqStore; sequenceState->prevCBlock = &cctx->blockState.prevCBlock; sequenceState->nextCBlock = &cctx->blockState.nextCBlock; sequenceState->tmpWorkspace = cctx->tmpWorkspace; sequenceState->tmpWkspSize = cctx->tmpWkspSize; sequenceState->blockSizeMax = cctx->blockSizeMax; sequenceState->bmi2 = cctx->bmi2; sequenceState->blockDelimiters = (int)cctx->appliedParams.blockDelimiters; sequenceState->strategy = (int)cctx->appliedParams.cParams.strategy; sequenceState->disableLiteralCompression = ZSTD_literalsCompressionIsDisabled(&cctx->appliedParams); sequenceState->searchForExternalRepcodes = (int)cctx->appliedParams.searchForExternalRepcodes; sequenceState->validateSequences = cctx->appliedParams.validateSequences; sequenceState->minMatch = cctx->appliedParams.cParams.minMatch; sequenceState->windowLog = cctx->appliedParams.cParams.windowLog; sequenceState->dictSize = dictSize; sequenceState->useSequenceProducer = ZSTD_hasExtSeqProd(&cctx->appliedParams); sequenceState->isFirstBlock = &cctx->isFirstBlock; assert(cctx->appliedParams.searchForExternalRepcodes != ZSTD_ps_auto); sequenceLiteralsState->seqStore = &cctx->seqStore; sequenceLiteralsState->prevCBlock = &cctx->blockState.prevCBlock; sequenceLiteralsState->nextCBlock = &cctx->blockState.nextCBlock; sequenceLiteralsState->tmpWorkspace = cctx->tmpWorkspace; sequenceLiteralsState->tmpWkspSize = cctx->tmpWkspSize; sequenceLiteralsState->blockSizeMax = cctx->blockSizeMax; sequenceLiteralsState->bmi2 = cctx->bmi2; sequenceLiteralsState->strategy = (int)cctx->appliedParams.cParams.strategy; sequenceLiteralsState->disableLiteralCompression = ZSTD_literalsCompressionIsDisabled(&cctx->appliedParams); sequenceLiteralsState->repcodeResolution = (cctx->appliedParams.searchForExternalRepcodes == ZSTD_ps_enable); sequenceLiteralsState->isFirstBlock = &cctx->isFirstBlock; sequenceLiteralsState->callbackContext = cctx; sequenceLiteralsState->convertBlockSequences = ZSTD_convertBlockSequencesForRust; } static size_t ZSTD_rust_sequenceApi_init( void* context, size_t pledgedSrcSize, ZSTD_rust_sequenceApiState* state) { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context; size_t initResult; if (cctx == NULL || state == NULL || state->sequenceState == NULL || state->sequenceLiteralsState == NULL) { return ERROR(GENERIC); } initResult = ZSTD_CCtx_init_compressStream2( cctx, ZSTD_e_end, pledgedSrcSize); if (ERR_isError(initResult)) { return initResult; } ZSTD_rust_sequenceApi_prepareStates( cctx, state->sequenceState, state->sequenceLiteralsState); state->checksumFlag = cctx->appliedParams.fParams.checksumFlag; state->blockDelimiters = (int)cctx->appliedParams.blockDelimiters; state->validateSequences = cctx->appliedParams.validateSequences; state->noDictIDFlag = cctx->appliedParams.fParams.noDictIDFlag; state->contentSizeFlag = cctx->appliedParams.fParams.contentSizeFlag; state->format = (int)cctx->appliedParams.format; state->windowLog = cctx->appliedParams.cParams.windowLog; state->dictID = cctx->dictID; return 0; } static void ZSTD_rust_sequenceApi_initState( ZSTD_rust_sequenceApiState* state, ZSTD_CCtx* cctx, ZSTD_rust_sequenceCompressionState* sequenceState, ZSTD_rust_sequenceLiteralsState* sequenceLiteralsState) { state->callbackContext = cctx; state->sequenceState = sequenceState; state->sequenceLiteralsState = sequenceLiteralsState; state->init = ZSTD_rust_sequenceApi_init; state->checksumState = &cctx->xxhState; state->checksumFlag = 0; state->blockDelimiters = 0; state->validateSequences = 0; state->noDictIDFlag = 0; state->contentSizeFlag = 0; state->format = 0; state->windowLog = 0; state->dictID = 0; } size_t ZSTD_compressSequences(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const ZSTD_Sequence* inSeqs, size_t inSeqsSize, const void* src, size_t srcSize) { ZSTD_rust_sequenceCompressionState sequenceState; ZSTD_rust_sequenceLiteralsState sequenceLiteralsState; ZSTD_rust_sequenceApiState state; DEBUGLOG(4, "ZSTD_compressSequences (nbSeqs=%zu,dstCapacity=%zu)", inSeqsSize, dstCapacity); assert(cctx != NULL); ZSTD_rust_sequenceApi_initState( &state, cctx, &sequenceState, &sequenceLiteralsState); return ZSTD_rust_compressSequences( &state, dst, dstCapacity, inSeqs, inSeqsSize, src, srcSize); } size_t ZSTD_compressSequencesAndLiterals(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const ZSTD_Sequence* inSeqs, size_t inSeqsSize, const void* literals, size_t litSize, size_t litCapacity, size_t decompressedSize) { ZSTD_rust_sequenceCompressionState sequenceState; ZSTD_rust_sequenceLiteralsState sequenceLiteralsState; ZSTD_rust_sequenceApiState state; DEBUGLOG(4, "ZSTD_compressSequencesAndLiterals (dstCapacity=%zu)", dstCapacity); assert(cctx != NULL); ZSTD_rust_sequenceApi_initState( &state, cctx, &sequenceState, &sequenceLiteralsState); return ZSTD_rust_compressSequencesAndLiterals( &state, dst, dstCapacity, inSeqs, inSeqsSize, literals, litSize, litCapacity, decompressedSize); } /*====== Finalize ======*/ static ZSTD_inBuffer inBuffer_forEndFlush(const ZSTD_CStream* zcs) { return ZSTD_rust_inBufferForEndFlush(zcs->appliedParams.inBufferMode, zcs->expectedInBuffer.src, zcs->expectedInBuffer.size, zcs->expectedInBuffer.pos); } /*! ZSTD_flushStream() : * @return : amount of data remaining to flush */ size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output) { ZSTD_inBuffer input = inBuffer_forEndFlush(zcs); input.size = input.pos; /* do not ingest more input during flush */ return ZSTD_compressStream2(zcs, output, &input, ZSTD_e_flush); } size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output) { ZSTD_inBuffer input = inBuffer_forEndFlush(zcs); size_t const remainingToFlush = ZSTD_compressStream2(zcs, output, &input, ZSTD_e_end); FORWARD_IF_ERROR(remainingToFlush , "ZSTD_compressStream2(,,ZSTD_e_end) failed"); { size_t const toFlush = ZSTD_rust_endStreamRemainingPolicy( remainingToFlush, zcs->appliedParams.nbWorkers, zcs->frameEnded, zcs->appliedParams.fParams.checksumFlag); if (zcs->appliedParams.nbWorkers <= 0) { DEBUGLOG(4, "ZSTD_endStream : remaining to flush : %u", (unsigned)toFlush); } return toFlush; } } /*-===== Pre-defined compression levels =====-*/ /* The compression-level tables (formerly included from clevels.h) live in * rust/src/zstd_compress_params.rs. */ /*! ZSTD_getCParams_internal() : * @return ZSTD_compressionParameters structure for a selected compression level, srcSize and dictSize. * Note: srcSizeHint 0 means 0, use ZSTD_CONTENTSIZE_UNKNOWN for unknown. * Use dictSize == 0 for unknown or unused. * Note: `mode` controls how we treat the `dictSize`. See docs for `ZSTD_CParamMode_e`. */ static ZSTD_compressionParameters ZSTD_getCParams_internal(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize, ZSTD_CParamMode_e mode) { return ZSTD_rust_params_getCParamsInternal( compressionLevel, srcSizeHint, dictSize, (int)mode, ZSTD_getCParamsExclusionMask()); } /*! ZSTD_getCParams() : * @return ZSTD_compressionParameters structure for a selected compression level, srcSize and dictSize. * Size values are optional, provide 0 if not known or unused */ ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize) { return ZSTD_rust_params_getCParams( compressionLevel, srcSizeHint, dictSize, ZSTD_getCParamsExclusionMask()); } /*! ZSTD_getParams() : * same idea as ZSTD_getCParams() * @return a `ZSTD_parameters` structure (instead of `ZSTD_compressionParameters`). * Fields of `ZSTD_frameParameters` are set to default values */ static ZSTD_parameters ZSTD_getParams_internal(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize, ZSTD_CParamMode_e mode) { DEBUGLOG(5, "ZSTD_getParams (cLevel=%i)", compressionLevel); return ZSTD_rust_params_getParamsInternal( compressionLevel, srcSizeHint, dictSize, (int)mode, ZSTD_getCParamsExclusionMask()); } /*! ZSTD_getParams() : * same idea as ZSTD_getCParams() * @return a `ZSTD_parameters` structure (instead of `ZSTD_compressionParameters`). * Fields of `ZSTD_frameParameters` are set to default values */ ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize) { return ZSTD_rust_params_getParams( compressionLevel, srcSizeHint, dictSize, ZSTD_getCParamsExclusionMask()); } void ZSTD_registerSequenceProducer( ZSTD_CCtx* zc, void* extSeqProdState, ZSTD_sequenceProducer_F extSeqProdFunc) { assert(zc != NULL); ZSTD_CCtxParams_registerSequenceProducer( &zc->requestedParams, extSeqProdState, extSeqProdFunc ); }