├── LibreELEC ├── LibreELEC10-zlib-ng.patch └── README.md ├── README.md └── nginx ├── 1.18.0-zlib-ng.patch ├── 1.25.3-zlib-ng.patch ├── 1.26.2-zlib-ng.patch ├── 1.26.3-zlib-ng.patch └── README.md /LibreELEC/LibreELEC10-zlib-ng.patch: -------------------------------------------------------------------------------- 1 | diff --git a/packages/compress/zlib/package.mk b/packages/compress/zlib/package.mk 2 | index f39e64dee8..5dd78604a8 100644 3 | --- a/packages/compress/zlib/package.mk 4 | +++ b/packages/compress/zlib/package.mk 5 | @@ -1,13 +1,18 @@ 6 | # SPDX-License-Identifier: GPL-2.0-or-later 7 | # Copyright (C) 2009-2016 Stephan Raue (stephan@openelec.tv) 8 | +# Copyright (C) 2021-present Team LibreELEC (https://libreelec.tv) 9 | 10 | PKG_NAME="zlib" 11 | -PKG_VERSION="1.2.11" 12 | -PKG_SHA256="4ff941449631ace0d4d203e3483be9dbc9da454084111f97ea0a2114e19bf066" 13 | +PKG_VERSION="2.0.2" 14 | +PKG_SHA256="dd37886f22ca6890e403ea6c1d60f36eab1d08d2f232a35f5b02126621149d28" 15 | PKG_LICENSE="OSS" 16 | -PKG_SITE="http://www.zlib.net" 17 | -PKG_URL="http://zlib.net/${PKG_NAME}-${PKG_VERSION}.tar.xz" 18 | +PKG_SITE="https://github.com/zlib-ng/zlib-ng" 19 | +PKG_URL="https://github.com/zlib-ng/zlib-ng/archive/refs/tags/${PKG_VERSION}.tar.gz" 20 | PKG_DEPENDS_HOST="cmake:host" 21 | PKG_DEPENDS_TARGET="toolchain" 22 | -PKG_LONGDESC="A general purpose (ZIP) data compression library." 23 | +PKG_LONGDESC="zlib data compression library for the next generation systems" 24 | PKG_TOOLCHAIN="cmake-make" 25 | + 26 | +PKG_CMAKE_OPTS_HOST="-DZLIB_COMPAT=ON" 27 | + 28 | +PKG_CMAKE_OPTS_TARGET="-DZLIB_COMPAT=ON" 29 | -------------------------------------------------------------------------------- /LibreELEC/README.md: -------------------------------------------------------------------------------- 1 | ## LibreELEC10-zlib-ng.patch 2 | * Patch created against LibreELEC (LE10) 3 | * Link full distro against zlib-ng instead of zlib 4 | * Apply patch against https://github.com/LibreELEC/LibreELEC.tv 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### About 2 | 3 | This repository is here to allow sharing patches that allow compiling an application against zlib-ng. 4 | The patches should generally be safe to use in prod. 5 | The patches might not be implemented in a clean way, they might short-circuit zlib detection or otherwise 6 | hard-code zlib-ng usage, therefore these patches might not be of a quality where they are ready to upstream. 7 | 8 | ### Contribution guidelines 9 | 10 | * Look at the nginx patch folder for an example of how things should look. 11 | * Add a folder for the application name, with a README.md file describing its contents. 12 | * Add a short description to the README.md, detailing the changes per patch file. 13 | * Optionally add a longer description to the top of the patch file. 14 | * Add information about what version the patch applies cleanly to, preferably also as part of the patch name. 15 | 16 | -------------------------------------------------------------------------------- /nginx/1.18.0-zlib-ng.patch: -------------------------------------------------------------------------------- 1 | diff -ru nginx-1.18.0/auto/lib/zlib/conf nginx-1.18.0-zlib-ng/auto/lib/zlib/conf 2 | --- nginx-1.18.0/auto/lib/zlib/conf 2020-04-21 16:09:01.000000000 +0200 3 | +++ nginx-1.18.0-zlib-ng/auto/lib/zlib/conf 2020-04-28 13:12:15.301291321 +0200 4 | @@ -33,8 +33,8 @@ 5 | 6 | *) 7 | have=NGX_ZLIB . auto/have 8 | - LINK_DEPS="$LINK_DEPS $ZLIB/libz.a" 9 | - CORE_LIBS="$CORE_LIBS $ZLIB/libz.a" 10 | + LINK_DEPS="$LINK_DEPS $ZLIB/libz-ng.a" 11 | + CORE_LIBS="$CORE_LIBS $ZLIB/libz-ng.a" 12 | #CORE_LIBS="$CORE_LIBS -L $ZLIB -lz" 13 | ;; 14 | 15 | @@ -50,10 +50,10 @@ 16 | ngx_feature="zlib library" 17 | ngx_feature_name="NGX_ZLIB" 18 | ngx_feature_run=no 19 | - ngx_feature_incs="#include " 20 | + ngx_feature_incs="#include " 21 | ngx_feature_path= 22 | - ngx_feature_libs="-lz" 23 | - ngx_feature_test="z_stream z; deflate(&z, Z_NO_FLUSH)" 24 | + ngx_feature_libs="-lz-ng" 25 | + ngx_feature_test="zng_stream z; zng_deflate(&z, Z_NO_FLUSH)" 26 | . auto/feature 27 | 28 | 29 | diff -ru nginx-1.18.0/src/http/modules/ngx_http_gunzip_filter_module.c nginx-1.18.0-zlib-ng/src/http/modules/ngx_http_gunzip_filter_module.c 30 | --- nginx-1.18.0/src/http/modules/ngx_http_gunzip_filter_module.c 2020-04-21 16:09:01.000000000 +0200 31 | +++ nginx-1.18.0-zlib-ng/src/http/modules/ngx_http_gunzip_filter_module.c 2020-04-28 13:12:15.317291487 +0200 32 | @@ -10,7 +10,14 @@ 33 | #include 34 | #include 35 | 36 | -#include 37 | +#if defined(NGX_ZLIB_NG) 38 | +# include 39 | +# define ZPREFIX(x) zng_ ## x 40 | +# define z_stream zng_stream 41 | +#elif defined(NGX_ZLIB) 42 | +# include 43 | +# define ZPREFIX(x) x 44 | +#endif 45 | 46 | 47 | typedef struct { 48 | @@ -312,7 +319,7 @@ 49 | ctx->zstream.opaque = ctx; 50 | 51 | /* windowBits +16 to decode gzip, zlib 1.2.0.4+ */ 52 | - rc = inflateInit2(&ctx->zstream, MAX_WBITS + 16); 53 | + rc = ZPREFIX(inflateInit2)(&ctx->zstream, MAX_WBITS + 16); 54 | 55 | if (rc != Z_OK) { 56 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 57 | @@ -425,7 +432,7 @@ 58 | ctx->zstream.avail_in, ctx->zstream.avail_out, 59 | ctx->flush, ctx->redo); 60 | 61 | - rc = inflate(&ctx->zstream, ctx->flush); 62 | + rc = ZPREFIX(inflate)(&ctx->zstream, ctx->flush); 63 | 64 | if (rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) { 65 | ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 66 | @@ -523,7 +530,7 @@ 67 | 68 | if (rc == Z_STREAM_END && ctx->zstream.avail_in > 0) { 69 | 70 | - rc = inflateReset(&ctx->zstream); 71 | + rc = ZPREFIX(inflateReset)(&ctx->zstream); 72 | 73 | if (rc != Z_OK) { 74 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 75 | @@ -574,7 +581,7 @@ 76 | ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 77 | "gunzip inflate end"); 78 | 79 | - rc = inflateEnd(&ctx->zstream); 80 | + rc = ZPREFIX(inflateEnd)(&ctx->zstream); 81 | 82 | if (rc != Z_OK) { 83 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 84 | diff -ru nginx-1.18.0/src/http/modules/ngx_http_gzip_filter_module.c nginx-1.18.0-zlib-ng/src/http/modules/ngx_http_gzip_filter_module.c 85 | --- nginx-1.18.0/src/http/modules/ngx_http_gzip_filter_module.c 2020-04-21 16:09:01.000000000 +0200 86 | +++ nginx-1.18.0-zlib-ng/src/http/modules/ngx_http_gzip_filter_module.c 2021-02-25 13:46:43.120677662 +0100 87 | @@ -9,7 +9,14 @@ 88 | #include 89 | #include 90 | 91 | -#include 92 | +#if defined(NGX_ZLIB_NG) 93 | +# include 94 | +# define ZPREFIX(x) zng_ ## x 95 | +# define z_stream zng_stream 96 | +#elif defined(NGX_ZLIB) 97 | +# include 98 | +# define ZPREFIX(x) x 99 | +#endif 100 | 101 | 102 | typedef struct { 103 | @@ -452,7 +459,7 @@ 104 | ctx->done = 1; 105 | 106 | if (ctx->preallocated) { 107 | - deflateEnd(&ctx->zstream); 108 | + ZPREFIX(deflateEnd)(&ctx->zstream); 109 | 110 | ngx_pfree(r->pool, ctx->preallocated); 111 | } 112 | @@ -519,9 +526,13 @@ 113 | wbits = ngx_max(wbits, 13); 114 | } 115 | 116 | - ctx->allocated = 8192 + 16 + (1 << (wbits + 2)) 117 | - + (1 << (ngx_max(memlevel, 8) + 8)) 118 | - + (1 << (memlevel + 8)); 119 | + // zlib-ng 120 | + ctx->allocated = 8192 /* deflate_state + padding + extra? */ 121 | + + (1 << (wbits + 1)) + 8 /* s->window + s->prev + padding */ 122 | + + (1 << (17)) + 8 /* s->head */ 123 | + + (1 << (ngx_max(memlevel, 8) + 8)) /* s->pending_buf */ 124 | + + (1 << (memlevel + 8)); /* not sure */ 125 | + 126 | ctx->intel = 1; 127 | } 128 | } 129 | @@ -615,7 +626,7 @@ 130 | ctx->zstream.zfree = ngx_http_gzip_filter_free; 131 | ctx->zstream.opaque = ctx; 132 | 133 | - rc = deflateInit2(&ctx->zstream, (int) conf->level, Z_DEFLATED, 134 | + rc = ZPREFIX(deflateInit2)(&ctx->zstream, (int) conf->level, Z_DEFLATED, 135 | ctx->wbits + 16, ctx->memlevel, Z_DEFAULT_STRATEGY); 136 | 137 | if (rc != Z_OK) { 138 | @@ -750,7 +761,7 @@ 139 | ctx->zstream.avail_in, ctx->zstream.avail_out, 140 | ctx->flush, ctx->redo); 141 | 142 | - rc = deflate(&ctx->zstream, ctx->flush); 143 | + rc = ZPREFIX(deflate)(&ctx->zstream, ctx->flush); 144 | 145 | if (rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) { 146 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 147 | @@ -874,7 +885,7 @@ 148 | ctx->zin = ctx->zstream.total_in; 149 | ctx->zout = ctx->zstream.total_out; 150 | 151 | - rc = deflateEnd(&ctx->zstream); 152 | + rc = ZPREFIX(deflateEnd)(&ctx->zstream); 153 | 154 | if (rc != Z_OK) { 155 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 156 | diff -ru nginx-1.18.0/src/http/modules/ngx_http_log_module.c nginx-1.18.0-zlib-ng/src/http/modules/ngx_http_log_module.c 157 | --- nginx-1.18.0/src/http/modules/ngx_http_log_module.c 2020-04-21 16:09:01.000000000 +0200 158 | +++ nginx-1.18.0-zlib-ng/src/http/modules/ngx_http_log_module.c 2020-04-28 13:12:15.319291508 +0200 159 | @@ -9,8 +9,13 @@ 160 | #include 161 | #include 162 | 163 | -#if (NGX_ZLIB) 164 | -#include 165 | +#if defined(NGX_ZLIB_NG) 166 | +# include 167 | +# define ZPREFIX(x) zng_ ## x 168 | +# define z_stream zng_stream 169 | +#elif defined(NGX_ZLIB) 170 | +# include 171 | +# define ZPREFIX(x) x 172 | #endif 173 | 174 | 175 | @@ -634,7 +639,7 @@ 176 | zstream.next_out = out; 177 | zstream.avail_out = size; 178 | 179 | - rc = deflateInit2(&zstream, (int) level, Z_DEFLATED, wbits + 16, memlevel, 180 | + rc = ZPREFIX(deflateInit2)(&zstream, (int) level, Z_DEFLATED, wbits + 16, memlevel, 181 | Z_DEFAULT_STRATEGY); 182 | 183 | if (rc != Z_OK) { 184 | @@ -647,7 +652,7 @@ 185 | zstream.next_in, zstream.next_out, 186 | zstream.avail_in, zstream.avail_out); 187 | 188 | - rc = deflate(&zstream, Z_FINISH); 189 | + rc = ZPREFIX(deflate)(&zstream, Z_FINISH); 190 | 191 | if (rc != Z_STREAM_END) { 192 | ngx_log_error(NGX_LOG_ALERT, log, 0, 193 | @@ -663,7 +668,7 @@ 194 | 195 | size -= zstream.avail_out; 196 | 197 | - rc = deflateEnd(&zstream); 198 | + rc = ZPREFIX(deflateEnd)(&zstream); 199 | 200 | if (rc != Z_OK) { 201 | ngx_log_error(NGX_LOG_ALERT, log, 0, "deflateEnd() failed: %d", rc); 202 | diff -ru nginx-1.18.0/src/stream/ngx_stream_log_module.c nginx-1.18.0-zlib-ng/src/stream/ngx_stream_log_module.c 203 | --- nginx-1.18.0/src/stream/ngx_stream_log_module.c 2020-04-21 16:09:01.000000000 +0200 204 | +++ nginx-1.18.0-zlib-ng/src/stream/ngx_stream_log_module.c 2020-04-28 13:12:15.319291508 +0200 205 | @@ -9,8 +9,13 @@ 206 | #include 207 | #include 208 | 209 | -#if (NGX_ZLIB) 210 | -#include 211 | +#if defined(NGX_ZLIB_NG) 212 | +# include 213 | +# define ZPREFIX(x) zng_ ## x 214 | +# define z_stream zng_stream 215 | +#elif defined(NGX_ZLIB) 216 | +# include 217 | +# define ZPREFIX(x) x 218 | #endif 219 | 220 | 221 | @@ -482,7 +487,7 @@ 222 | u_char *out; 223 | size_t size; 224 | ssize_t n; 225 | - z_stream zstream; 226 | + z_stream zstream; 227 | ngx_err_t err; 228 | ngx_pool_t *pool; 229 | 230 | @@ -525,7 +530,7 @@ 231 | zstream.next_out = out; 232 | zstream.avail_out = size; 233 | 234 | - rc = deflateInit2(&zstream, (int) level, Z_DEFLATED, wbits + 16, memlevel, 235 | + rc = ZPREFIX(deflateInit2)(&zstream, (int) level, Z_DEFLATED, wbits + 16, memlevel, 236 | Z_DEFAULT_STRATEGY); 237 | 238 | if (rc != Z_OK) { 239 | @@ -538,7 +543,7 @@ 240 | zstream.next_in, zstream.next_out, 241 | zstream.avail_in, zstream.avail_out); 242 | 243 | - rc = deflate(&zstream, Z_FINISH); 244 | + rc = ZPREFIX(deflate)(&zstream, Z_FINISH); 245 | 246 | if (rc != Z_STREAM_END) { 247 | ngx_log_error(NGX_LOG_ALERT, log, 0, 248 | @@ -554,7 +559,7 @@ 249 | 250 | size -= zstream.avail_out; 251 | 252 | - rc = deflateEnd(&zstream); 253 | + rc = ZPREFIX(deflateEnd)(&zstream); 254 | 255 | if (rc != Z_OK) { 256 | ngx_log_error(NGX_LOG_ALERT, log, 0, "deflateEnd() failed: %d", rc); 257 | -------------------------------------------------------------------------------- /nginx/1.25.3-zlib-ng.patch: -------------------------------------------------------------------------------- 1 | diff -urN nginx-1.25.3.orig/auto/lib/zlib/conf nginx-1.25.3/auto/lib/zlib/conf 2 | --- nginx-1.25.3.orig/auto/lib/zlib/conf 2023-10-24 15:46:47.000000000 +0200 3 | +++ nginx-1.25.3/auto/lib/zlib/conf 2023-11-25 16:50:20.103591053 +0100 4 | @@ -33,8 +33,8 @@ 5 | 6 | *) 7 | have=NGX_ZLIB . auto/have 8 | - LINK_DEPS="$LINK_DEPS $ZLIB/libz.a" 9 | - CORE_LIBS="$CORE_LIBS $ZLIB/libz.a" 10 | + LINK_DEPS="$LINK_DEPS $ZLIB/libz-ng.a" 11 | + CORE_LIBS="$CORE_LIBS $ZLIB/libz-ng.a" 12 | #CORE_LIBS="$CORE_LIBS -L $ZLIB -lz" 13 | ;; 14 | 15 | @@ -50,10 +50,10 @@ 16 | ngx_feature="zlib library" 17 | ngx_feature_name="NGX_ZLIB" 18 | ngx_feature_run=no 19 | - ngx_feature_incs="#include " 20 | + ngx_feature_incs="#include " 21 | ngx_feature_path= 22 | - ngx_feature_libs="-lz" 23 | - ngx_feature_test="z_stream z; deflate(&z, Z_NO_FLUSH)" 24 | + ngx_feature_libs="-lz-ng" 25 | + ngx_feature_test="zng_stream z; zng_deflate(&z, Z_NO_FLUSH)" 26 | . auto/feature 27 | 28 | 29 | diff -urN nginx-1.25.3.orig/src/http/modules/ngx_http_gunzip_filter_module.c nginx-1.25.3/src/http/modules/ngx_http_gunzip_filter_module.c 30 | --- nginx-1.25.3.orig/src/http/modules/ngx_http_gunzip_filter_module.c 2023-10-24 15:46:47.000000000 +0200 31 | +++ nginx-1.25.3/src/http/modules/ngx_http_gunzip_filter_module.c 2023-11-25 16:50:20.103591053 +0100 32 | @@ -10,7 +10,14 @@ 33 | #include 34 | #include 35 | 36 | -#include 37 | +#if defined(NGX_ZLIB_NG) 38 | +# include 39 | +# define ZPREFIX(x) zng_ ## x 40 | +# define z_stream zng_stream 41 | +#elif defined(NGX_ZLIB) 42 | +# include 43 | +# define ZPREFIX(x) x 44 | +#endif 45 | 46 | 47 | typedef struct { 48 | @@ -312,7 +319,7 @@ 49 | ctx->zstream.opaque = ctx; 50 | 51 | /* windowBits +16 to decode gzip, zlib 1.2.0.4+ */ 52 | - rc = inflateInit2(&ctx->zstream, MAX_WBITS + 16); 53 | + rc = ZPREFIX(inflateInit2)(&ctx->zstream, MAX_WBITS + 16); 54 | 55 | if (rc != Z_OK) { 56 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 57 | @@ -425,7 +432,7 @@ 58 | ctx->zstream.avail_in, ctx->zstream.avail_out, 59 | ctx->flush, ctx->redo); 60 | 61 | - rc = inflate(&ctx->zstream, ctx->flush); 62 | + rc = ZPREFIX(inflate)(&ctx->zstream, ctx->flush); 63 | 64 | if (rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) { 65 | ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 66 | @@ -523,7 +530,7 @@ 67 | 68 | if (rc == Z_STREAM_END && ctx->zstream.avail_in > 0) { 69 | 70 | - rc = inflateReset(&ctx->zstream); 71 | + rc = ZPREFIX(inflateReset)(&ctx->zstream); 72 | 73 | if (rc != Z_OK) { 74 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 75 | @@ -574,7 +581,7 @@ 76 | ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 77 | "gunzip inflate end"); 78 | 79 | - rc = inflateEnd(&ctx->zstream); 80 | + rc = ZPREFIX(inflateEnd)(&ctx->zstream); 81 | 82 | if (rc != Z_OK) { 83 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 84 | diff -urN nginx-1.25.3.orig/src/http/modules/ngx_http_gzip_filter_module.c nginx-1.25.3/src/http/modules/ngx_http_gzip_filter_module.c 85 | --- nginx-1.25.3.orig/src/http/modules/ngx_http_gzip_filter_module.c 2023-10-24 15:46:47.000000000 +0200 86 | +++ nginx-1.25.3/src/http/modules/ngx_http_gzip_filter_module.c 2023-11-25 16:50:20.103591053 +0100 87 | @@ -9,7 +9,14 @@ 88 | #include 89 | #include 90 | 91 | -#include 92 | +#if defined(NGX_ZLIB_NG) 93 | +# include 94 | +# define ZPREFIX(x) zng_ ## x 95 | +# define z_stream zng_stream 96 | +#elif defined(NGX_ZLIB) 97 | +# include 98 | +# define ZPREFIX(x) x 99 | +#endif 100 | 101 | 102 | typedef struct { 103 | @@ -454,7 +461,7 @@ 104 | ctx->done = 1; 105 | 106 | if (ctx->preallocated) { 107 | - deflateEnd(&ctx->zstream); 108 | + ZPREFIX(deflateEnd)(&ctx->zstream); 109 | 110 | ngx_pfree(r->pool, ctx->preallocated); 111 | } 112 | @@ -621,7 +628,7 @@ 113 | ctx->zstream.zfree = ngx_http_gzip_filter_free; 114 | ctx->zstream.opaque = ctx; 115 | 116 | - rc = deflateInit2(&ctx->zstream, (int) conf->level, Z_DEFLATED, 117 | + rc = ZPREFIX(deflateInit2)(&ctx->zstream, (int) conf->level, Z_DEFLATED, 118 | ctx->wbits + 16, ctx->memlevel, Z_DEFAULT_STRATEGY); 119 | 120 | if (rc != Z_OK) { 121 | @@ -756,7 +763,7 @@ 122 | ctx->zstream.avail_in, ctx->zstream.avail_out, 123 | ctx->flush, ctx->redo); 124 | 125 | - rc = deflate(&ctx->zstream, ctx->flush); 126 | + rc = ZPREFIX(deflate)(&ctx->zstream, ctx->flush); 127 | 128 | if (rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) { 129 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 130 | @@ -880,7 +887,7 @@ 131 | ctx->zin = ctx->zstream.total_in; 132 | ctx->zout = ctx->zstream.total_out; 133 | 134 | - rc = deflateEnd(&ctx->zstream); 135 | + rc = ZPREFIX(deflateEnd)(&ctx->zstream); 136 | 137 | if (rc != Z_OK) { 138 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 139 | diff -urN nginx-1.25.3.orig/src/http/modules/ngx_http_log_module.c nginx-1.25.3/src/http/modules/ngx_http_log_module.c 140 | --- nginx-1.25.3.orig/src/http/modules/ngx_http_log_module.c 2023-10-24 15:46:47.000000000 +0200 141 | +++ nginx-1.25.3/src/http/modules/ngx_http_log_module.c 2023-11-25 16:50:20.103591053 +0100 142 | @@ -9,8 +9,13 @@ 143 | #include 144 | #include 145 | 146 | -#if (NGX_ZLIB) 147 | -#include 148 | +#if defined(NGX_ZLIB_NG) 149 | +# include 150 | +# define ZPREFIX(x) zng_ ## x 151 | +# define z_stream zng_stream 152 | +#elif defined(NGX_ZLIB) 153 | +# include 154 | +# define ZPREFIX(x) x 155 | #endif 156 | 157 | 158 | @@ -634,7 +639,7 @@ 159 | zstream.next_out = out; 160 | zstream.avail_out = size; 161 | 162 | - rc = deflateInit2(&zstream, (int) level, Z_DEFLATED, wbits + 16, memlevel, 163 | + rc = ZPREFIX(deflateInit2)(&zstream, (int) level, Z_DEFLATED, wbits + 16, memlevel, 164 | Z_DEFAULT_STRATEGY); 165 | 166 | if (rc != Z_OK) { 167 | @@ -647,7 +652,7 @@ 168 | zstream.next_in, zstream.next_out, 169 | zstream.avail_in, zstream.avail_out); 170 | 171 | - rc = deflate(&zstream, Z_FINISH); 172 | + rc = ZPREFIX(deflate)(&zstream, Z_FINISH); 173 | 174 | if (rc != Z_STREAM_END) { 175 | ngx_log_error(NGX_LOG_ALERT, log, 0, 176 | @@ -663,7 +668,7 @@ 177 | 178 | size -= zstream.avail_out; 179 | 180 | - rc = deflateEnd(&zstream); 181 | + rc = ZPREFIX(deflateEnd)(&zstream); 182 | 183 | if (rc != Z_OK) { 184 | ngx_log_error(NGX_LOG_ALERT, log, 0, "deflateEnd() failed: %d", rc); 185 | diff -urN nginx-1.25.3.orig/src/stream/ngx_stream_log_module.c nginx-1.25.3/src/stream/ngx_stream_log_module.c 186 | --- nginx-1.25.3.orig/src/stream/ngx_stream_log_module.c 2023-10-24 15:46:47.000000000 +0200 187 | +++ nginx-1.25.3/src/stream/ngx_stream_log_module.c 2023-11-25 16:50:20.103591053 +0100 188 | @@ -9,8 +9,13 @@ 189 | #include 190 | #include 191 | 192 | -#if (NGX_ZLIB) 193 | -#include 194 | +#if defined(NGX_ZLIB_NG) 195 | +# include 196 | +# define ZPREFIX(x) zng_ ## x 197 | +# define z_stream zng_stream 198 | +#elif defined(NGX_ZLIB) 199 | +# include 200 | +# define ZPREFIX(x) x 201 | #endif 202 | 203 | 204 | @@ -525,7 +530,7 @@ 205 | zstream.next_out = out; 206 | zstream.avail_out = size; 207 | 208 | - rc = deflateInit2(&zstream, (int) level, Z_DEFLATED, wbits + 16, memlevel, 209 | + rc = ZPREFIX(deflateInit2)(&zstream, (int) level, Z_DEFLATED, wbits + 16, memlevel, 210 | Z_DEFAULT_STRATEGY); 211 | 212 | if (rc != Z_OK) { 213 | @@ -538,7 +543,7 @@ 214 | zstream.next_in, zstream.next_out, 215 | zstream.avail_in, zstream.avail_out); 216 | 217 | - rc = deflate(&zstream, Z_FINISH); 218 | + rc = ZPREFIX(deflate)(&zstream, Z_FINISH); 219 | 220 | if (rc != Z_STREAM_END) { 221 | ngx_log_error(NGX_LOG_ALERT, log, 0, 222 | @@ -554,7 +559,7 @@ 223 | 224 | size -= zstream.avail_out; 225 | 226 | - rc = deflateEnd(&zstream); 227 | + rc = ZPREFIX(deflateEnd)(&zstream); 228 | 229 | if (rc != Z_OK) { 230 | ngx_log_error(NGX_LOG_ALERT, log, 0, "deflateEnd() failed: %d", rc); 231 | -------------------------------------------------------------------------------- /nginx/1.26.2-zlib-ng.patch: -------------------------------------------------------------------------------- 1 | diff -ru nginx-1.26.2/auto/lib/zlib/conf nginx-1.26.2-zlib-ng/auto/lib/zlib/conf 2 | --- nginx-1.26.2/auto/lib/zlib/conf 2024-08-12 16:28:31.000000000 +0200 3 | +++ nginx-1.26.2-zlib-ng/auto/lib/zlib/conf 2024-10-18 13:59:33.218699818 +0200 4 | @@ -33,8 +33,8 @@ 5 | 6 | *) 7 | have=NGX_ZLIB . auto/have 8 | - LINK_DEPS="$LINK_DEPS $ZLIB/libz.a" 9 | - CORE_LIBS="$CORE_LIBS $ZLIB/libz.a" 10 | + LINK_DEPS="$LINK_DEPS $ZLIB/libz-ng.a" 11 | + CORE_LIBS="$CORE_LIBS $ZLIB/libz-ng.a" 12 | #CORE_LIBS="$CORE_LIBS -L $ZLIB -lz" 13 | ;; 14 | 15 | @@ -50,10 +50,10 @@ 16 | ngx_feature="zlib library" 17 | ngx_feature_name="NGX_ZLIB" 18 | ngx_feature_run=no 19 | - ngx_feature_incs="#include " 20 | + ngx_feature_incs="#include " 21 | ngx_feature_path= 22 | - ngx_feature_libs="-lz" 23 | - ngx_feature_test="z_stream z; deflate(&z, Z_NO_FLUSH)" 24 | + ngx_feature_libs="-lz-ng" 25 | + ngx_feature_test="zng_stream z; zng_deflate(&z, Z_NO_FLUSH)" 26 | . auto/feature 27 | 28 | 29 | diff -ru nginx-1.26.2/src/core/ngx_config.h nginx-1.26.2-zlib-ng/src/core/ngx_config.h 30 | --- nginx-1.26.2/src/core/ngx_config.h 2024-08-12 16:28:31.000000000 +0200 31 | +++ nginx-1.26.2-zlib-ng/src/core/ngx_config.h 2024-10-18 14:26:37.446504000 +0200 32 | @@ -141,5 +141,9 @@ 33 | 34 | #endif 35 | 36 | +/* Force enable ZLIB-NG */ 37 | +#ifndef NGX_ZLIB_NG 38 | +#define NGX_ZLIB_NG 1 39 | +#endif 40 | 41 | #endif /* _NGX_CONFIG_H_INCLUDED_ */ 42 | diff -ru nginx-1.26.2/src/http/modules/ngx_http_gunzip_filter_module.c nginx-1.26.2-zlib-ng/src/http/modules/ngx_http_gunzip_filter_module.c 43 | --- nginx-1.26.2/src/http/modules/ngx_http_gunzip_filter_module.c 2024-08-12 16:28:31.000000000 +0200 44 | +++ nginx-1.26.2-zlib-ng/src/http/modules/ngx_http_gunzip_filter_module.c 2024-10-18 13:59:33.218699818 +0200 45 | @@ -10,7 +10,14 @@ 46 | #include 47 | #include 48 | 49 | -#include 50 | +#if defined(NGX_ZLIB_NG) 51 | +# include 52 | +# define ZPREFIX(x) zng_ ## x 53 | +# define z_stream zng_stream 54 | +#elif defined(NGX_ZLIB) 55 | +# include 56 | +# define ZPREFIX(x) x 57 | +#endif 58 | 59 | 60 | typedef struct { 61 | @@ -312,7 +319,7 @@ 62 | ctx->zstream.opaque = ctx; 63 | 64 | /* windowBits +16 to decode gzip, zlib 1.2.0.4+ */ 65 | - rc = inflateInit2(&ctx->zstream, MAX_WBITS + 16); 66 | + rc = ZPREFIX(inflateInit2)(&ctx->zstream, MAX_WBITS + 16); 67 | 68 | if (rc != Z_OK) { 69 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 70 | @@ -435,7 +442,7 @@ 71 | ctx->zstream.avail_in, ctx->zstream.avail_out, 72 | ctx->flush, ctx->redo); 73 | 74 | - rc = inflate(&ctx->zstream, ctx->flush); 75 | + rc = ZPREFIX(inflate)(&ctx->zstream, ctx->flush); 76 | 77 | if (rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) { 78 | ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 79 | @@ -533,7 +540,7 @@ 80 | 81 | if (rc == Z_STREAM_END && ctx->zstream.avail_in > 0) { 82 | 83 | - rc = inflateReset(&ctx->zstream); 84 | + rc = ZPREFIX(inflateReset)(&ctx->zstream); 85 | 86 | if (rc != Z_OK) { 87 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 88 | @@ -584,7 +591,7 @@ 89 | ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 90 | "gunzip inflate end"); 91 | 92 | - rc = inflateEnd(&ctx->zstream); 93 | + rc = ZPREFIX(inflateEnd)(&ctx->zstream); 94 | 95 | if (rc != Z_OK) { 96 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 97 | diff -ru nginx-1.26.2/src/http/modules/ngx_http_gzip_filter_module.c nginx-1.26.2-zlib-ng/src/http/modules/ngx_http_gzip_filter_module.c 98 | --- nginx-1.26.2/src/http/modules/ngx_http_gzip_filter_module.c 2024-08-12 16:28:31.000000000 +0200 99 | +++ nginx-1.26.2-zlib-ng/src/http/modules/ngx_http_gzip_filter_module.c 2024-10-18 14:55:07.499545547 +0200 100 | @@ -9,7 +9,14 @@ 101 | #include 102 | #include 103 | 104 | -#include 105 | +#if defined(NGX_ZLIB_NG) 106 | +# include 107 | +# define ZPREFIX(x) zng_ ## x 108 | +# define z_stream zng_stream 109 | +#elif defined(NGX_ZLIB) 110 | +# include 111 | +# define ZPREFIX(x) x 112 | +#endif 113 | 114 | 115 | typedef struct { 116 | @@ -454,7 +461,7 @@ 117 | ctx->done = 1; 118 | 119 | if (ctx->preallocated) { 120 | - deflateEnd(&ctx->zstream); 121 | + ZPREFIX(deflateEnd)(&ctx->zstream); 122 | 123 | ngx_pfree(r->pool, ctx->preallocated); 124 | } 125 | @@ -515,20 +522,20 @@ 126 | } else { 127 | /* 128 | * Another zlib variant, https://github.com/zlib-ng/zlib-ng. 129 | - * It used to force window bits to 13 for fast compression level, 130 | - * uses (64 + sizeof(void*)) additional space on all allocations 131 | - * for alignment, 16-byte padding in one of window-sized buffers, 132 | - * and 128K hash. 133 | */ 134 | - 135 | - if (conf->level == 1) { 136 | - wbits = ngx_max(wbits, 13); 137 | - } 138 | - 139 | - ctx->allocated = 8192 + 16 + (1 << (wbits + 2)) 140 | - + 131072 + (1 << (memlevel + 8)) 141 | - + 4 * (64 + sizeof(void*)); 142 | ctx->zlib_ng = 1; 143 | + ctx->allocated = 6144 // State 144 | + + 65536 // Window 145 | + + 65536 // Prev 146 | + + 131072 // Head 147 | + + 163840 // Pending 148 | + + 56 + 8 // Alloc struct + padding 149 | +#if (defined(__s390__) || defined(__s390x__) || defined(__zarch__)) 150 | + + 4096 // Required to fix allocation alignment 151 | +#else 152 | + + 64 // Required to fix allocation alignment 153 | +#endif 154 | + + 256; // Extra to allow for future changes 155 | } 156 | } 157 | 158 | @@ -621,7 +628,7 @@ 159 | ctx->zstream.zfree = ngx_http_gzip_filter_free; 160 | ctx->zstream.opaque = ctx; 161 | 162 | - rc = deflateInit2(&ctx->zstream, (int) conf->level, Z_DEFLATED, 163 | + rc = ZPREFIX(deflateInit2)(&ctx->zstream, (int) conf->level, Z_DEFLATED, 164 | ctx->wbits + 16, ctx->memlevel, Z_DEFAULT_STRATEGY); 165 | 166 | if (rc != Z_OK) { 167 | @@ -756,7 +763,7 @@ 168 | ctx->zstream.avail_in, ctx->zstream.avail_out, 169 | ctx->flush, ctx->redo); 170 | 171 | - rc = deflate(&ctx->zstream, ctx->flush); 172 | + rc = ZPREFIX(deflate)(&ctx->zstream, ctx->flush); 173 | 174 | if (rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) { 175 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 176 | @@ -880,7 +887,7 @@ 177 | ctx->zin = ctx->zstream.total_in; 178 | ctx->zout = ctx->zstream.total_out; 179 | 180 | - rc = deflateEnd(&ctx->zstream); 181 | + rc = ZPREFIX(deflateEnd)(&ctx->zstream); 182 | 183 | if (rc != Z_OK) { 184 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 185 | diff -ru nginx-1.26.2/src/http/modules/ngx_http_log_module.c nginx-1.26.2-zlib-ng/src/http/modules/ngx_http_log_module.c 186 | --- nginx-1.26.2/src/http/modules/ngx_http_log_module.c 2024-08-12 16:28:31.000000000 +0200 187 | +++ nginx-1.26.2-zlib-ng/src/http/modules/ngx_http_log_module.c 2024-10-18 13:59:33.219699787 +0200 188 | @@ -9,8 +9,13 @@ 189 | #include 190 | #include 191 | 192 | -#if (NGX_ZLIB) 193 | -#include 194 | +#if defined(NGX_ZLIB_NG) 195 | +# include 196 | +# define ZPREFIX(x) zng_ ## x 197 | +# define z_stream zng_stream 198 | +#elif defined(NGX_ZLIB) 199 | +# include 200 | +# define ZPREFIX(x) x 201 | #endif 202 | 203 | 204 | @@ -634,7 +639,7 @@ 205 | zstream.next_out = out; 206 | zstream.avail_out = size; 207 | 208 | - rc = deflateInit2(&zstream, (int) level, Z_DEFLATED, wbits + 16, memlevel, 209 | + rc = ZPREFIX(deflateInit2)(&zstream, (int) level, Z_DEFLATED, wbits + 16, memlevel, 210 | Z_DEFAULT_STRATEGY); 211 | 212 | if (rc != Z_OK) { 213 | @@ -647,7 +652,7 @@ 214 | zstream.next_in, zstream.next_out, 215 | zstream.avail_in, zstream.avail_out); 216 | 217 | - rc = deflate(&zstream, Z_FINISH); 218 | + rc = ZPREFIX(deflate)(&zstream, Z_FINISH); 219 | 220 | if (rc != Z_STREAM_END) { 221 | ngx_log_error(NGX_LOG_ALERT, log, 0, 222 | @@ -663,7 +668,7 @@ 223 | 224 | size -= zstream.avail_out; 225 | 226 | - rc = deflateEnd(&zstream); 227 | + rc = ZPREFIX(deflateEnd)(&zstream); 228 | 229 | if (rc != Z_OK) { 230 | ngx_log_error(NGX_LOG_ALERT, log, 0, "deflateEnd() failed: %d", rc); 231 | diff -ru nginx-1.26.2/src/stream/ngx_stream_log_module.c nginx-1.26.2-zlib-ng/src/stream/ngx_stream_log_module.c 232 | --- nginx-1.26.2/src/stream/ngx_stream_log_module.c 2024-08-12 16:28:31.000000000 +0200 233 | +++ nginx-1.26.2-zlib-ng/src/stream/ngx_stream_log_module.c 2024-10-18 13:59:33.219699787 +0200 234 | @@ -9,8 +9,13 @@ 235 | #include 236 | #include 237 | 238 | -#if (NGX_ZLIB) 239 | -#include 240 | +#if defined(NGX_ZLIB_NG) 241 | +# include 242 | +# define ZPREFIX(x) zng_ ## x 243 | +# define z_stream zng_stream 244 | +#elif defined(NGX_ZLIB) 245 | +# include 246 | +# define ZPREFIX(x) x 247 | #endif 248 | 249 | 250 | @@ -525,7 +530,7 @@ 251 | zstream.next_out = out; 252 | zstream.avail_out = size; 253 | 254 | - rc = deflateInit2(&zstream, (int) level, Z_DEFLATED, wbits + 16, memlevel, 255 | + rc = ZPREFIX(deflateInit2)(&zstream, (int) level, Z_DEFLATED, wbits + 16, memlevel, 256 | Z_DEFAULT_STRATEGY); 257 | 258 | if (rc != Z_OK) { 259 | @@ -538,7 +543,7 @@ 260 | zstream.next_in, zstream.next_out, 261 | zstream.avail_in, zstream.avail_out); 262 | 263 | - rc = deflate(&zstream, Z_FINISH); 264 | + rc = ZPREFIX(deflate)(&zstream, Z_FINISH); 265 | 266 | if (rc != Z_STREAM_END) { 267 | ngx_log_error(NGX_LOG_ALERT, log, 0, 268 | @@ -554,7 +559,7 @@ 269 | 270 | size -= zstream.avail_out; 271 | 272 | - rc = deflateEnd(&zstream); 273 | + rc = ZPREFIX(deflateEnd)(&zstream); 274 | 275 | if (rc != Z_OK) { 276 | ngx_log_error(NGX_LOG_ALERT, log, 0, "deflateEnd() failed: %d", rc); 277 | -------------------------------------------------------------------------------- /nginx/1.26.3-zlib-ng.patch: -------------------------------------------------------------------------------- 1 | diff -ur nginx-1.26.3/auto/lib/zlib/conf nginx-1.26.3-zlib-ng/auto/lib/zlib/conf 2 | --- nginx-1.26.3/auto/lib/zlib/conf 2025-02-05 12:07:30.000000000 +0100 3 | +++ nginx-1.26.3-zlib-ng/auto/lib/zlib/conf 2025-03-19 21:26:49.564791340 +0100 4 | @@ -33,8 +33,8 @@ 5 | 6 | *) 7 | have=NGX_ZLIB . auto/have 8 | - LINK_DEPS="$LINK_DEPS $ZLIB/libz.a" 9 | - CORE_LIBS="$CORE_LIBS $ZLIB/libz.a" 10 | + LINK_DEPS="$LINK_DEPS $ZLIB/libz-ng.a" 11 | + CORE_LIBS="$CORE_LIBS $ZLIB/libz-ng.a" 12 | #CORE_LIBS="$CORE_LIBS -L $ZLIB -lz" 13 | ;; 14 | 15 | @@ -50,10 +50,10 @@ 16 | ngx_feature="zlib library" 17 | ngx_feature_name="NGX_ZLIB" 18 | ngx_feature_run=no 19 | - ngx_feature_incs="#include " 20 | + ngx_feature_incs="#include " 21 | ngx_feature_path= 22 | - ngx_feature_libs="-lz" 23 | - ngx_feature_test="z_stream z; deflate(&z, Z_NO_FLUSH)" 24 | + ngx_feature_libs="-lz-ng" 25 | + ngx_feature_test="zng_stream z; zng_deflate(&z, Z_NO_FLUSH)" 26 | . auto/feature 27 | 28 | 29 | diff -ur nginx-1.26.3/src/core/ngx_config.h nginx-1.26.3-zlib-ng/src/core/ngx_config.h 30 | --- nginx-1.26.3/src/core/ngx_config.h 2025-02-05 12:07:30.000000000 +0100 31 | +++ nginx-1.26.3-zlib-ng/src/core/ngx_config.h 2025-03-19 21:26:49.564791340 +0100 32 | @@ -141,5 +141,9 @@ 33 | 34 | #endif 35 | 36 | +/* Force enable ZLIB-NG */ 37 | +#ifndef NGX_ZLIB_NG 38 | +#define NGX_ZLIB_NG 1 39 | +#endif 40 | 41 | #endif /* _NGX_CONFIG_H_INCLUDED_ */ 42 | diff -ur nginx-1.26.3/src/http/modules/ngx_http_gunzip_filter_module.c nginx-1.26.3-zlib-ng/src/http/modules/ngx_http_gunzip_filter_module.c 43 | --- nginx-1.26.3/src/http/modules/ngx_http_gunzip_filter_module.c 2025-02-05 12:07:30.000000000 +0100 44 | +++ nginx-1.26.3-zlib-ng/src/http/modules/ngx_http_gunzip_filter_module.c 2025-03-19 21:26:49.667786357 +0100 45 | @@ -10,7 +10,14 @@ 46 | #include 47 | #include 48 | 49 | -#include 50 | +#if defined(NGX_ZLIB_NG) 51 | +# include 52 | +# define ZPREFIX(x) zng_ ## x 53 | +# define z_stream zng_stream 54 | +#elif defined(NGX_ZLIB) 55 | +# include 56 | +# define ZPREFIX(x) x 57 | +#endif 58 | 59 | 60 | typedef struct { 61 | @@ -312,7 +319,7 @@ 62 | ctx->zstream.opaque = ctx; 63 | 64 | /* windowBits +16 to decode gzip, zlib 1.2.0.4+ */ 65 | - rc = inflateInit2(&ctx->zstream, MAX_WBITS + 16); 66 | + rc = ZPREFIX(inflateInit2)(&ctx->zstream, MAX_WBITS + 16); 67 | 68 | if (rc != Z_OK) { 69 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 70 | @@ -435,7 +442,7 @@ 71 | ctx->zstream.avail_in, ctx->zstream.avail_out, 72 | ctx->flush, ctx->redo); 73 | 74 | - rc = inflate(&ctx->zstream, ctx->flush); 75 | + rc = ZPREFIX(inflate)(&ctx->zstream, ctx->flush); 76 | 77 | if (rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) { 78 | ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 79 | @@ -533,7 +540,7 @@ 80 | 81 | if (rc == Z_STREAM_END && ctx->zstream.avail_in > 0) { 82 | 83 | - rc = inflateReset(&ctx->zstream); 84 | + rc = ZPREFIX(inflateReset)(&ctx->zstream); 85 | 86 | if (rc != Z_OK) { 87 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 88 | @@ -584,7 +591,7 @@ 89 | ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 90 | "gunzip inflate end"); 91 | 92 | - rc = inflateEnd(&ctx->zstream); 93 | + rc = ZPREFIX(inflateEnd)(&ctx->zstream); 94 | 95 | if (rc != Z_OK) { 96 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 97 | diff -ur nginx-1.26.3/src/http/modules/ngx_http_gzip_filter_module.c nginx-1.26.3-zlib-ng/src/http/modules/ngx_http_gzip_filter_module.c 98 | --- nginx-1.26.3/src/http/modules/ngx_http_gzip_filter_module.c 2025-02-05 12:07:30.000000000 +0100 99 | +++ nginx-1.26.3-zlib-ng/src/http/modules/ngx_http_gzip_filter_module.c 2025-03-19 21:46:51.435543453 +0100 100 | @@ -9,7 +9,14 @@ 101 | #include 102 | #include 103 | 104 | -#include 105 | +#if defined(NGX_ZLIB_NG) 106 | +# include 107 | +# define ZPREFIX(x) zng_ ## x 108 | +# define z_stream zng_stream 109 | +#elif defined(NGX_ZLIB) 110 | +# include 111 | +# define ZPREFIX(x) x 112 | +#endif 113 | 114 | 115 | typedef struct { 116 | @@ -454,7 +461,7 @@ 117 | ctx->done = 1; 118 | 119 | if (ctx->preallocated) { 120 | - deflateEnd(&ctx->zstream); 121 | + ZPREFIX(deflateEnd)(&ctx->zstream); 122 | 123 | ngx_pfree(r->pool, ctx->preallocated); 124 | } 125 | @@ -515,21 +522,20 @@ 126 | } else { 127 | /* 128 | * Another zlib variant, https://github.com/zlib-ng/zlib-ng. 129 | - * It used to force window bits to 13 for fast compression level, 130 | - * used (64 + sizeof(void*)) additional space on all allocations 131 | - * for alignment and 16-byte padding in one of window-sized buffers, 132 | - * uses a single allocation with up to 200 bytes for alignment and 133 | - * internal pointers, 5/4 times more memory for the pending buffer, 134 | - * and 128K hash. 135 | */ 136 | 137 | - if (conf->level == 1) { 138 | - wbits = ngx_max(wbits, 13); 139 | - } 140 | - 141 | - ctx->allocated = 8192 + 16 + (1 << (wbits + 2)) 142 | - + 131072 + (5 << (memlevel + 6)) 143 | - + 4 * (64 + sizeof(void*)); 144 | + ctx->allocated = 6144 // State 145 | + + 65536 // Window 146 | + + 65536 // Prev 147 | + + 131072 // Head 148 | + + 163840 // Pending 149 | + + 56 + 8 // Alloc struct + padding 150 | +#if (defined(__s390__) || defined(__s390x__) || defined(__zarch__)) 151 | + + 4096 // Required to fix allocation alignment 152 | +#else 153 | + + 64 // Required to fix allocation alignment 154 | +#endif 155 | + + 256; // Extra to allow for future changes 156 | ctx->zlib_ng = 1; 157 | } 158 | } 159 | @@ -623,7 +629,7 @@ 160 | ctx->zstream.zfree = ngx_http_gzip_filter_free; 161 | ctx->zstream.opaque = ctx; 162 | 163 | - rc = deflateInit2(&ctx->zstream, (int) conf->level, Z_DEFLATED, 164 | + rc = ZPREFIX(deflateInit2)(&ctx->zstream, (int) conf->level, Z_DEFLATED, 165 | ctx->wbits + 16, ctx->memlevel, Z_DEFAULT_STRATEGY); 166 | 167 | if (rc != Z_OK) { 168 | @@ -758,7 +764,7 @@ 169 | ctx->zstream.avail_in, ctx->zstream.avail_out, 170 | ctx->flush, ctx->redo); 171 | 172 | - rc = deflate(&ctx->zstream, ctx->flush); 173 | + rc = ZPREFIX(deflate)(&ctx->zstream, ctx->flush); 174 | 175 | if (rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) { 176 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 177 | @@ -882,7 +888,7 @@ 178 | ctx->zin = ctx->zstream.total_in; 179 | ctx->zout = ctx->zstream.total_out; 180 | 181 | - rc = deflateEnd(&ctx->zstream); 182 | + rc = ZPREFIX(deflateEnd)(&ctx->zstream); 183 | 184 | if (rc != Z_OK) { 185 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 186 | Only in nginx-1.26.3-zlib-ng/src/http/modules: ngx_http_gzip_filter_module.c.orig 187 | diff -ur nginx-1.26.3/src/http/modules/ngx_http_log_module.c nginx-1.26.3-zlib-ng/src/http/modules/ngx_http_log_module.c 188 | --- nginx-1.26.3/src/http/modules/ngx_http_log_module.c 2025-02-05 12:07:30.000000000 +0100 189 | +++ nginx-1.26.3-zlib-ng/src/http/modules/ngx_http_log_module.c 2025-03-19 21:26:49.669786260 +0100 190 | @@ -9,8 +9,13 @@ 191 | #include 192 | #include 193 | 194 | -#if (NGX_ZLIB) 195 | -#include 196 | +#if defined(NGX_ZLIB_NG) 197 | +# include 198 | +# define ZPREFIX(x) zng_ ## x 199 | +# define z_stream zng_stream 200 | +#elif defined(NGX_ZLIB) 201 | +# include 202 | +# define ZPREFIX(x) x 203 | #endif 204 | 205 | 206 | @@ -634,7 +639,7 @@ 207 | zstream.next_out = out; 208 | zstream.avail_out = size; 209 | 210 | - rc = deflateInit2(&zstream, (int) level, Z_DEFLATED, wbits + 16, memlevel, 211 | + rc = ZPREFIX(deflateInit2)(&zstream, (int) level, Z_DEFLATED, wbits + 16, memlevel, 212 | Z_DEFAULT_STRATEGY); 213 | 214 | if (rc != Z_OK) { 215 | @@ -647,7 +652,7 @@ 216 | zstream.next_in, zstream.next_out, 217 | zstream.avail_in, zstream.avail_out); 218 | 219 | - rc = deflate(&zstream, Z_FINISH); 220 | + rc = ZPREFIX(deflate)(&zstream, Z_FINISH); 221 | 222 | if (rc != Z_STREAM_END) { 223 | ngx_log_error(NGX_LOG_ALERT, log, 0, 224 | @@ -663,7 +668,7 @@ 225 | 226 | size -= zstream.avail_out; 227 | 228 | - rc = deflateEnd(&zstream); 229 | + rc = ZPREFIX(deflateEnd)(&zstream); 230 | 231 | if (rc != Z_OK) { 232 | ngx_log_error(NGX_LOG_ALERT, log, 0, "deflateEnd() failed: %d", rc); 233 | diff -ur nginx-1.26.3/src/stream/ngx_stream_log_module.c nginx-1.26.3-zlib-ng/src/stream/ngx_stream_log_module.c 234 | --- nginx-1.26.3/src/stream/ngx_stream_log_module.c 2025-02-05 12:07:30.000000000 +0100 235 | +++ nginx-1.26.3-zlib-ng/src/stream/ngx_stream_log_module.c 2025-03-19 21:26:49.669786260 +0100 236 | @@ -9,8 +9,13 @@ 237 | #include 238 | #include 239 | 240 | -#if (NGX_ZLIB) 241 | -#include 242 | +#if defined(NGX_ZLIB_NG) 243 | +# include 244 | +# define ZPREFIX(x) zng_ ## x 245 | +# define z_stream zng_stream 246 | +#elif defined(NGX_ZLIB) 247 | +# include 248 | +# define ZPREFIX(x) x 249 | #endif 250 | 251 | 252 | @@ -525,7 +530,7 @@ 253 | zstream.next_out = out; 254 | zstream.avail_out = size; 255 | 256 | - rc = deflateInit2(&zstream, (int) level, Z_DEFLATED, wbits + 16, memlevel, 257 | + rc = ZPREFIX(deflateInit2)(&zstream, (int) level, Z_DEFLATED, wbits + 16, memlevel, 258 | Z_DEFAULT_STRATEGY); 259 | 260 | if (rc != Z_OK) { 261 | @@ -538,7 +543,7 @@ 262 | zstream.next_in, zstream.next_out, 263 | zstream.avail_in, zstream.avail_out); 264 | 265 | - rc = deflate(&zstream, Z_FINISH); 266 | + rc = ZPREFIX(deflate)(&zstream, Z_FINISH); 267 | 268 | if (rc != Z_STREAM_END) { 269 | ngx_log_error(NGX_LOG_ALERT, log, 0, 270 | @@ -554,7 +559,7 @@ 271 | 272 | size -= zstream.avail_out; 273 | 274 | - rc = deflateEnd(&zstream); 275 | + rc = ZPREFIX(deflateEnd)(&zstream); 276 | 277 | if (rc != Z_OK) { 278 | ngx_log_error(NGX_LOG_ALERT, log, 0, "deflateEnd() failed: %d", rc); 279 | -------------------------------------------------------------------------------- /nginx/README.md: -------------------------------------------------------------------------------- 1 | ## 1.18.0-zlib-ng.patch 2 | * Patch created against Nginx 1.18.0 3 | * Link to native zlib-ng instead of zlib 4 | * Prefix all zlib calls 5 | * Increase the size of pre-allocated memory to fit with zlib-ng requirements 6 | 7 | ## 1.26.2-zlib-ng.patch 8 | * Patch created against Nginx 1.26.2 9 | * Supports zlib-ng 2.2.x 10 | * Links to native zlib-ng instead of zlib 11 | * Prefixes all zlib calls 12 | * Increases the size of pre-allocated memory to fit with zlib-ng requirements 13 | * New: No longer requires you to define NGX_ZLIB_NG to enable overrides 14 | 15 | ## 1.26.3-zlib-ng.patch 16 | * Patch created against Nginx 1.26.3 17 | * Supports zlib-ng 2.2.x 18 | * Links to native zlib-ng instead of zlib 19 | * Prefixes all zlib calls 20 | * Increases the size of pre-allocated memory to fit with zlib-ng requirements 21 | 22 | PS: due to an oversight in the Nginx code, it assumes zlib is not compiled with 23 | const support enabled, but zlib-ng always uses const. 24 | So to avoid errors, please compile Nginx with this CFlag: `-Werror=discarded-qualifiers` 25 | Ex: `./configure --with-cc-opt="-O2 -Werror=discarded-qualifiers"` 26 | --------------------------------------------------------------------------------