feat(compress): move static CCtx gating into Rust
Move public ZSTD_initStaticCCtx null, alignment, minimum-size, and callback dispatch into Rust. Keep private workspace reservations, block-state buffers, and CPU initialization in the C callback. Test Plan: - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/Cargo.toml --release init_static_cctx -- --nocapture - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/Cargo.toml --release - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --release --all-targets -- -D warnings - ulimit -v 41943040; make -B -C programs -j1 zstd - ulimit -v 41943040; make -C tests -j1 test-zstream ZSTREAM_TESTTIME=-T1s
This commit is contained in:
@@ -344,6 +344,27 @@ typedef char ZSTD_rust_create_cctx_state_layout[
|
||||
== 4 * sizeof(void*)
|
||||
&& sizeof(ZSTD_rust_createCCtxState) == 5 * sizeof(void*))
|
||||
? 1 : -1];
|
||||
typedef void* (*ZSTD_rust_initStaticCCtxInit_f)(void* context);
|
||||
typedef struct {
|
||||
void* callbackContext;
|
||||
void* workspace;
|
||||
size_t workspaceSize;
|
||||
size_t cctxSize;
|
||||
ZSTD_rust_initStaticCCtxInit_f init;
|
||||
} 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, init)
|
||||
== 4 * sizeof(void*)
|
||||
&& sizeof(ZSTD_rust_initStaticCCtxState) == 5 * sizeof(void*))
|
||||
? 1 : -1];
|
||||
typedef void* (*ZSTD_rust_createCDictCreate_f)(
|
||||
void* context, const void* dict, size_t dictSize,
|
||||
int dictLoadMethod, int dictContentType,
|
||||
@@ -2168,20 +2189,26 @@ ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem)
|
||||
return (ZSTD_CCtx*)ZSTD_rust_createCCtx(&state);
|
||||
}
|
||||
|
||||
ZSTD_CCtx* ZSTD_initStaticCCtx(void* workspace, size_t workspaceSize)
|
||||
typedef struct {
|
||||
void* workspace;
|
||||
size_t workspaceSize;
|
||||
} ZSTD_rust_initStaticCCtxContext;
|
||||
|
||||
static void* ZSTD_rust_initStaticCCtx_init(void* opaque)
|
||||
{
|
||||
ZSTD_rust_initStaticCCtxContext* const context =
|
||||
(ZSTD_rust_initStaticCCtxContext*)opaque;
|
||||
ZSTD_cwksp ws;
|
||||
ZSTD_CCtx* cctx;
|
||||
if (workspaceSize <= sizeof(ZSTD_CCtx)) return NULL; /* minimum size */
|
||||
if ((size_t)workspace & 7) return NULL; /* must be 8-aligned */
|
||||
ZSTD_cwksp_init(&ws, workspace, workspaceSize, ZSTD_cwksp_static_alloc);
|
||||
|
||||
ZSTD_cwksp_init(&ws, context->workspace, context->workspaceSize,
|
||||
ZSTD_cwksp_static_alloc);
|
||||
cctx = (ZSTD_CCtx*)ZSTD_cwksp_reserve_object(&ws, sizeof(ZSTD_CCtx));
|
||||
if (cctx == NULL) return NULL;
|
||||
|
||||
ZSTD_memset(cctx, 0, sizeof(ZSTD_CCtx));
|
||||
ZSTD_cwksp_move(&cctx->workspace, &ws);
|
||||
cctx->staticSize = workspaceSize;
|
||||
cctx->staticSize = context->workspaceSize;
|
||||
|
||||
/* statically sized space. tmpWorkspace never moves (but prev/next block swap places) */
|
||||
if (!ZSTD_cwksp_check_available(&cctx->workspace, TMP_WORKSPACE_SIZE + 2 * sizeof(ZSTD_compressedBlockState_t))) return NULL;
|
||||
@@ -2193,6 +2220,20 @@ ZSTD_CCtx* ZSTD_initStaticCCtx(void* workspace, size_t workspaceSize)
|
||||
return cctx;
|
||||
}
|
||||
|
||||
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.init = ZSTD_rust_initStaticCCtx_init;
|
||||
return (ZSTD_CCtx*)ZSTD_rust_initStaticCCtx(&state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears and frees all of the dictionaries in the CCtx.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user