From 0c32ad42372aabf19206068fd00e1fbd6e089bc2 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Sat, 16 Dec 2023 18:00:45 +0500 Subject: [PATCH] Add force initialization functable, because deflate captures function pointers from functable Signed-off-by: Vladislav Shchapov --- deflate.c | 3 +++ functable.c | 11 +++++++++++ functable.h | 1 + 3 files changed, 15 insertions(+) diff --git a/deflate.c b/deflate.c index 73501451..2a0a20e5 100644 --- a/deflate.c +++ b/deflate.c @@ -194,6 +194,9 @@ int32_t ZNG_CONDEXPORT PREFIX(deflateInit2)(PREFIX3(stream) *strm, int32_t level deflate_state *s; int wrap = 1; + /* Force initialization functable, because deflate captures function pointers from functable. */ + functable.force_init(); + if (strm == NULL) return Z_STREAM_ERROR; diff --git a/functable.c b/functable.c index f664d280..99fe735e 100644 --- a/functable.c +++ b/functable.c @@ -11,6 +11,10 @@ #include "functable.h" #include "cpu_features.h" +static void force_init_empty(void) { + // empty +} + static void init_functable(void) { struct functable_s ft; struct cpu_features cf; @@ -18,6 +22,7 @@ static void init_functable(void) { cpu_check_features(&cf); // Generic code + ft.force_init = &force_init_empty; ft.adler32 = &adler32_c; ft.adler32_fold_copy = &adler32_fold_copy_c; ft.chunkmemset_safe = &chunkmemset_safe_c; @@ -234,6 +239,7 @@ static void init_functable(void) { #endif // Assign function pointers individually for atomic operation + functable.force_init = ft.force_init; functable.adler32 = ft.adler32; functable.adler32_fold_copy = ft.adler32_fold_copy; functable.chunkmemset_safe = ft.chunkmemset_safe; @@ -254,6 +260,10 @@ static void init_functable(void) { } /* stub functions */ +static void force_init_stub(void) { + init_functable(); +} + static uint32_t adler32_stub(uint32_t adler, const uint8_t* buf, size_t len) { init_functable(); return functable.adler32(adler, buf, len); @@ -341,6 +351,7 @@ static uint32_t update_hash_stub(deflate_state* const s, uint32_t h, uint32_t va /* functable init */ Z_INTERNAL Z_TLS struct functable_s functable = { + force_init_stub, adler32_stub, adler32_fold_copy_stub, chunkmemset_safe_stub, diff --git a/functable.h b/functable.h index 1cdfd4df..b1742bad 100644 --- a/functable.h +++ b/functable.h @@ -17,6 +17,7 @@ typedef struct zng_stream_s zng_stream; #endif struct functable_s { + void (* force_init) (void); uint32_t (* adler32) (uint32_t adler, const uint8_t *buf, size_t len); uint32_t (* adler32_fold_copy) (uint32_t adler, uint8_t *dst, const uint8_t *src, size_t len); uint8_t* (* chunkmemset_safe) (uint8_t *out, unsigned dist, unsigned len, unsigned left); -- 2.47.2