.. | .. |
---|
15 | 15 | #include "inffast.h" |
---|
16 | 16 | #include "infutil.h" |
---|
17 | 17 | |
---|
| 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 | + |
---|
18 | 28 | int zlib_inflate_workspacesize(void) |
---|
19 | 29 | { |
---|
20 | 30 | return sizeof(struct inflate_workspace); |
---|
.. | .. |
---|
42 | 52 | state->write = 0; |
---|
43 | 53 | state->whave = 0; |
---|
44 | 54 | |
---|
| 55 | + INFLATE_RESET_HOOK(strm); |
---|
45 | 56 | return Z_OK; |
---|
46 | 57 | } |
---|
47 | 58 | |
---|
.. | .. |
---|
66 | 77 | return Z_STREAM_ERROR; |
---|
67 | 78 | } |
---|
68 | 79 | 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 |
---|
69 | 87 | state->window = &WS(strm)->working_window[0]; |
---|
| 88 | +#endif |
---|
70 | 89 | |
---|
71 | 90 | return zlib_inflateReset(strm); |
---|
72 | 91 | } |
---|
.. | .. |
---|
227 | 246 | bits -= bits & 7; \ |
---|
228 | 247 | } while (0) |
---|
229 | 248 | |
---|
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 | | - |
---|
235 | 249 | /* |
---|
236 | 250 | inflate() uses a state machine to process as much input data and generate as |
---|
237 | 251 | much output data as possible before returning. The state machine is |
---|
.. | .. |
---|
382 | 396 | strm->adler = state->check = REVERSE(hold); |
---|
383 | 397 | INITBITS(); |
---|
384 | 398 | state->mode = DICT; |
---|
| 399 | + /* fall through */ |
---|
385 | 400 | case DICT: |
---|
386 | 401 | if (state->havedict == 0) { |
---|
387 | 402 | RESTORE(); |
---|
.. | .. |
---|
389 | 404 | } |
---|
390 | 405 | strm->adler = state->check = zlib_adler32(0L, NULL, 0); |
---|
391 | 406 | state->mode = TYPE; |
---|
| 407 | + /* fall through */ |
---|
392 | 408 | case TYPE: |
---|
393 | 409 | if (flush == Z_BLOCK) goto inf_leave; |
---|
| 410 | + /* fall through */ |
---|
394 | 411 | case TYPEDO: |
---|
| 412 | + INFLATE_TYPEDO_HOOK(strm, flush); |
---|
395 | 413 | if (state->last) { |
---|
396 | 414 | BYTEBITS(); |
---|
397 | 415 | state->mode = CHECK; |
---|
.. | .. |
---|
428 | 446 | state->length = (unsigned)hold & 0xffff; |
---|
429 | 447 | INITBITS(); |
---|
430 | 448 | state->mode = COPY; |
---|
| 449 | + /* fall through */ |
---|
431 | 450 | case COPY: |
---|
432 | 451 | copy = state->length; |
---|
433 | 452 | if (copy) { |
---|
.. | .. |
---|
461 | 480 | #endif |
---|
462 | 481 | state->have = 0; |
---|
463 | 482 | state->mode = LENLENS; |
---|
| 483 | + /* fall through */ |
---|
464 | 484 | case LENLENS: |
---|
465 | 485 | while (state->have < state->ncode) { |
---|
466 | 486 | NEEDBITS(3); |
---|
.. | .. |
---|
481 | 501 | } |
---|
482 | 502 | state->have = 0; |
---|
483 | 503 | state->mode = CODELENS; |
---|
| 504 | + /* fall through */ |
---|
484 | 505 | case CODELENS: |
---|
485 | 506 | while (state->have < state->nlen + state->ndist) { |
---|
486 | 507 | for (;;) { |
---|
.. | .. |
---|
554 | 575 | break; |
---|
555 | 576 | } |
---|
556 | 577 | state->mode = LEN; |
---|
| 578 | + /* fall through */ |
---|
557 | 579 | case LEN: |
---|
558 | 580 | if (have >= 6 && left >= 258) { |
---|
559 | 581 | RESTORE(); |
---|
.. | .. |
---|
593 | 615 | } |
---|
594 | 616 | state->extra = (unsigned)(this.op) & 15; |
---|
595 | 617 | state->mode = LENEXT; |
---|
| 618 | + /* fall through */ |
---|
596 | 619 | case LENEXT: |
---|
597 | 620 | if (state->extra) { |
---|
598 | 621 | NEEDBITS(state->extra); |
---|
.. | .. |
---|
600 | 623 | DROPBITS(state->extra); |
---|
601 | 624 | } |
---|
602 | 625 | state->mode = DIST; |
---|
| 626 | + /* fall through */ |
---|
603 | 627 | case DIST: |
---|
604 | 628 | for (;;) { |
---|
605 | 629 | this = state->distcode[BITS(state->distbits)]; |
---|
.. | .. |
---|
625 | 649 | state->offset = (unsigned)this.val; |
---|
626 | 650 | state->extra = (unsigned)(this.op) & 15; |
---|
627 | 651 | state->mode = DISTEXT; |
---|
| 652 | + /* fall through */ |
---|
628 | 653 | case DISTEXT: |
---|
629 | 654 | if (state->extra) { |
---|
630 | 655 | NEEDBITS(state->extra); |
---|
.. | .. |
---|
644 | 669 | break; |
---|
645 | 670 | } |
---|
646 | 671 | state->mode = MATCH; |
---|
| 672 | + /* fall through */ |
---|
647 | 673 | case MATCH: |
---|
648 | 674 | if (left == 0) goto inf_leave; |
---|
649 | 675 | copy = out - left; |
---|
.. | .. |
---|
681 | 707 | out -= left; |
---|
682 | 708 | strm->total_out += out; |
---|
683 | 709 | state->total += out; |
---|
684 | | - if (out) |
---|
| 710 | + if (INFLATE_NEED_CHECKSUM(strm) && out) |
---|
685 | 711 | strm->adler = state->check = |
---|
686 | 712 | UPDATE(state->check, put - out, out); |
---|
687 | 713 | out = left; |
---|
.. | .. |
---|
694 | 720 | INITBITS(); |
---|
695 | 721 | } |
---|
696 | 722 | state->mode = DONE; |
---|
| 723 | + /* fall through */ |
---|
697 | 724 | case DONE: |
---|
698 | 725 | ret = Z_STREAM_END; |
---|
699 | 726 | goto inf_leave; |
---|
.. | .. |
---|
714 | 741 | */ |
---|
715 | 742 | inf_leave: |
---|
716 | 743 | 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))) |
---|
718 | 746 | zlib_updatewindow(strm, out); |
---|
719 | 747 | |
---|
720 | 748 | in -= strm->avail_in; |
---|
.. | .. |
---|
722 | 750 | strm->total_in += in; |
---|
723 | 751 | strm->total_out += out; |
---|
724 | 752 | state->total += out; |
---|
725 | | - if (state->wrap && out) |
---|
| 753 | + if (INFLATE_NEED_CHECKSUM(strm) && state->wrap && out) |
---|
726 | 754 | strm->adler = state->check = |
---|
727 | 755 | UPDATE(state->check, strm->next_out - out, out); |
---|
728 | 756 | |
---|