adenilson / rpms / zlib

Forked from rpms/zlib 8 months ago
Clone

Blame SOURCES/zlib-1.2.11-IBM-Z-hw-accelrated-deflate-compressBound-fix.patch

1df4e5
Source from https://gitlab.com/redhat/centos-stream/rpms/zlib/-/merge_requests/9
1df4e5
Author: Ilya Leoshkevich
1df4e5
1df4e5
--- a/compress.c
1df4e5
+++ b/compress.c
1df4e5
@@ -5,9 +5,15 @@
1df4e5
 
1df4e5
 /* @(#) $Id$ */
1df4e5
 
1df4e5
-#define ZLIB_INTERNAL
1df4e5
+#include "zutil.h"
1df4e5
 #include "zlib.h"
1df4e5
 
1df4e5
+#ifdef DFLTCC
1df4e5
+#  include "contrib/s390/dfltcc.h"
1df4e5
+#else
1df4e5
+#define DEFLATE_BOUND_COMPLEN(source_len) 0
1df4e5
+#endif
1df4e5
+
1df4e5
 /* ===========================================================================
1df4e5
      Compresses the source buffer into the destination buffer. The level
1df4e5
    parameter has the same meaning as in deflateInit.  sourceLen is the byte
1df4e5
@@ -81,6 +87,12 @@ int ZEXPORT compress (dest, destLen, source, sourceLen)
1df4e5
 uLong ZEXPORT compressBound (sourceLen)
1df4e5
     uLong sourceLen;
1df4e5
 {
1df4e5
+    uLong complen = DEFLATE_BOUND_COMPLEN(sourceLen);
1df4e5
+
1df4e5
+    if (complen > 0)
1df4e5
+	/* Architecture-specific code provided an upper bound. */
1df4e5
+	return complen + ZLIB_WRAPLEN;
1df4e5
+
1df4e5
     return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
1df4e5
            (sourceLen >> 25) + 13;
1df4e5
 }
1df4e5
--- a/contrib/s390/dfltcc.h
1df4e5
+++ b/contrib/s390/dfltcc.h
1df4e5
@@ -12,6 +12,28 @@ void ZLIB_INTERNAL dfltcc_reset OF((z_streamp strm, uInt size));
1df4e5
 voidpf ZLIB_INTERNAL dfltcc_alloc_window OF((z_streamp strm, uInt items,
1df4e5
                                              uInt size));
1df4e5
 void ZLIB_INTERNAL dfltcc_free_window OF((z_streamp strm, voidpf w));
1df4e5
+#define DFLTCC_BLOCK_HEADER_BITS 3
1df4e5
+#define DFLTCC_HLITS_COUNT_BITS 5
1df4e5
+#define DFLTCC_HDISTS_COUNT_BITS 5
1df4e5
+#define DFLTCC_HCLENS_COUNT_BITS 4
1df4e5
+#define DFLTCC_MAX_HCLENS 19
1df4e5
+#define DFLTCC_HCLEN_BITS 3
1df4e5
+#define DFLTCC_MAX_HLITS 286
1df4e5
+#define DFLTCC_MAX_HDISTS 30
1df4e5
+#define DFLTCC_MAX_HLIT_HDIST_BITS 7
1df4e5
+#define DFLTCC_MAX_SYMBOL_BITS 16
1df4e5
+#define DFLTCC_MAX_EOBS_BITS 15
1df4e5
+#define DFLTCC_MAX_PADDING_BITS 7
1df4e5
+#define DEFLATE_BOUND_COMPLEN(source_len) \
1df4e5
+    ((DFLTCC_BLOCK_HEADER_BITS + \
1df4e5
+      DFLTCC_HLITS_COUNT_BITS + \
1df4e5
+      DFLTCC_HDISTS_COUNT_BITS + \
1df4e5
+      DFLTCC_HCLENS_COUNT_BITS + \
1df4e5
+      DFLTCC_MAX_HCLENS * DFLTCC_HCLEN_BITS + \
1df4e5
+      (DFLTCC_MAX_HLITS + DFLTCC_MAX_HDISTS) * DFLTCC_MAX_HLIT_HDIST_BITS + \
1df4e5
+      (source_len) * DFLTCC_MAX_SYMBOL_BITS + \
1df4e5
+      DFLTCC_MAX_EOBS_BITS + \
1df4e5
+      DFLTCC_MAX_PADDING_BITS) >> 3)
1df4e5
 int ZLIB_INTERNAL dfltcc_can_inflate OF((z_streamp strm));
1df4e5
 typedef enum {
1df4e5
     DFLTCC_INFLATE_CONTINUE,
1df4e5
diff --git a/contrib/s390/dfltcc_deflate.h b/contrib/s390/dfltcc_deflate.h
1df4e5
index 03f7f53..46acfc5 100644
1df4e5
--- a/contrib/s390/dfltcc_deflate.h
1df4e5
+++ b/contrib/s390/dfltcc_deflate.h
1df4e5
@@ -46,8 +46,7 @@ int ZLIB_INTERNAL dfltcc_deflate_get_dictionary OF((z_streamp strm,
1df4e5
 #define DEFLATE_BOUND_ADJUST_COMPLEN(strm, complen, source_len) \
1df4e5
     do { \
1df4e5
         if (dfltcc_can_deflate((strm))) \
1df4e5
-            (complen) = (3 + 5 + 5 + 4 + 19 * 3 + (286 + 30) * 7 + \
1df4e5
-                         (source_len) * 16 + 15 + 7) >> 3; \
1df4e5
+            (complen) = DEFLATE_BOUND_COMPLEN(source_len); \
1df4e5
     } while (0)
1df4e5
 #define DEFLATE_NEED_CONSERVATIVE_BOUND(strm) (dfltcc_can_deflate((strm)))
1df4e5
 #define DEFLATE_HOOK dfltcc_deflate
1df4e5
diff --git a/zutil.h b/zutil.h
1df4e5
index 14277bc..cf90e49 100644
1df4e5
--- a/zutil.h
1df4e5
+++ b/zutil.h
1df4e5
@@ -87,6 +87,8 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
1df4e5
 
1df4e5
 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
1df4e5
 
1df4e5
+#define ZLIB_WRAPLEN 6 /* zlib format overhead */
1df4e5
+
1df4e5
         /* target dependencies */
1df4e5
 
1df4e5
 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))