hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/lib/zlib_inflate/inflate.c
....@@ -15,6 +15,16 @@
1515 #include "inffast.h"
1616 #include "infutil.h"
1717
18
+/* architecture-specific bits */
19
+#ifdef CONFIG_ZLIB_DFLTCC
20
+# include "../zlib_dfltcc/dfltcc.h"
21
+#else
22
+#define INFLATE_RESET_HOOK(strm) do {} while (0)
23
+#define INFLATE_TYPEDO_HOOK(strm, flush) do {} while (0)
24
+#define INFLATE_NEED_UPDATEWINDOW(strm) 1
25
+#define INFLATE_NEED_CHECKSUM(strm) 1
26
+#endif
27
+
1828 int zlib_inflate_workspacesize(void)
1929 {
2030 return sizeof(struct inflate_workspace);
....@@ -42,6 +52,7 @@
4252 state->write = 0;
4353 state->whave = 0;
4454
55
+ INFLATE_RESET_HOOK(strm);
4556 return Z_OK;
4657 }
4758
....@@ -66,7 +77,15 @@
6677 return Z_STREAM_ERROR;
6778 }
6879 state->wbits = (unsigned)windowBits;
80
+#ifdef CONFIG_ZLIB_DFLTCC
81
+ /*
82
+ * DFLTCC requires the window to be page aligned.
83
+ * Thus, we overallocate and take the aligned portion of the buffer.
84
+ */
85
+ state->window = PTR_ALIGN(&WS(strm)->working_window[0], PAGE_SIZE);
86
+#else
6987 state->window = &WS(strm)->working_window[0];
88
+#endif
7089
7190 return zlib_inflateReset(strm);
7291 }
....@@ -227,11 +246,6 @@
227246 bits -= bits & 7; \
228247 } while (0)
229248
230
-/* Reverse the bytes in a 32-bit value */
231
-#define REVERSE(q) \
232
- ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
233
- (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
234
-
235249 /*
236250 inflate() uses a state machine to process as much input data and generate as
237251 much output data as possible before returning. The state machine is
....@@ -382,6 +396,7 @@
382396 strm->adler = state->check = REVERSE(hold);
383397 INITBITS();
384398 state->mode = DICT;
399
+ /* fall through */
385400 case DICT:
386401 if (state->havedict == 0) {
387402 RESTORE();
....@@ -389,9 +404,12 @@
389404 }
390405 strm->adler = state->check = zlib_adler32(0L, NULL, 0);
391406 state->mode = TYPE;
407
+ /* fall through */
392408 case TYPE:
393409 if (flush == Z_BLOCK) goto inf_leave;
410
+ /* fall through */
394411 case TYPEDO:
412
+ INFLATE_TYPEDO_HOOK(strm, flush);
395413 if (state->last) {
396414 BYTEBITS();
397415 state->mode = CHECK;
....@@ -428,6 +446,7 @@
428446 state->length = (unsigned)hold & 0xffff;
429447 INITBITS();
430448 state->mode = COPY;
449
+ /* fall through */
431450 case COPY:
432451 copy = state->length;
433452 if (copy) {
....@@ -461,6 +480,7 @@
461480 #endif
462481 state->have = 0;
463482 state->mode = LENLENS;
483
+ /* fall through */
464484 case LENLENS:
465485 while (state->have < state->ncode) {
466486 NEEDBITS(3);
....@@ -481,6 +501,7 @@
481501 }
482502 state->have = 0;
483503 state->mode = CODELENS;
504
+ /* fall through */
484505 case CODELENS:
485506 while (state->have < state->nlen + state->ndist) {
486507 for (;;) {
....@@ -554,6 +575,7 @@
554575 break;
555576 }
556577 state->mode = LEN;
578
+ /* fall through */
557579 case LEN:
558580 if (have >= 6 && left >= 258) {
559581 RESTORE();
....@@ -593,6 +615,7 @@
593615 }
594616 state->extra = (unsigned)(this.op) & 15;
595617 state->mode = LENEXT;
618
+ /* fall through */
596619 case LENEXT:
597620 if (state->extra) {
598621 NEEDBITS(state->extra);
....@@ -600,6 +623,7 @@
600623 DROPBITS(state->extra);
601624 }
602625 state->mode = DIST;
626
+ /* fall through */
603627 case DIST:
604628 for (;;) {
605629 this = state->distcode[BITS(state->distbits)];
....@@ -625,6 +649,7 @@
625649 state->offset = (unsigned)this.val;
626650 state->extra = (unsigned)(this.op) & 15;
627651 state->mode = DISTEXT;
652
+ /* fall through */
628653 case DISTEXT:
629654 if (state->extra) {
630655 NEEDBITS(state->extra);
....@@ -644,6 +669,7 @@
644669 break;
645670 }
646671 state->mode = MATCH;
672
+ /* fall through */
647673 case MATCH:
648674 if (left == 0) goto inf_leave;
649675 copy = out - left;
....@@ -681,7 +707,7 @@
681707 out -= left;
682708 strm->total_out += out;
683709 state->total += out;
684
- if (out)
710
+ if (INFLATE_NEED_CHECKSUM(strm) && out)
685711 strm->adler = state->check =
686712 UPDATE(state->check, put - out, out);
687713 out = left;
....@@ -694,6 +720,7 @@
694720 INITBITS();
695721 }
696722 state->mode = DONE;
723
+ /* fall through */
697724 case DONE:
698725 ret = Z_STREAM_END;
699726 goto inf_leave;
....@@ -714,7 +741,8 @@
714741 */
715742 inf_leave:
716743 RESTORE();
717
- if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
744
+ if (INFLATE_NEED_UPDATEWINDOW(strm) &&
745
+ (state->wsize || (state->mode < CHECK && out != strm->avail_out)))
718746 zlib_updatewindow(strm, out);
719747
720748 in -= strm->avail_in;
....@@ -722,7 +750,7 @@
722750 strm->total_in += in;
723751 strm->total_out += out;
724752 state->total += out;
725
- if (state->wrap && out)
753
+ if (INFLATE_NEED_CHECKSUM(strm) && state->wrap && out)
726754 strm->adler = state->check =
727755 UPDATE(state->check, strm->next_out - out, out);
728756