Lines Matching full:s
158 /* If 1, it's a match. Otherwise it's a single 8-bit literal. */
161 /* If 1, it's a repeated match. The distance is one of rep0 .. rep3. */
572 static uint16_t *lzma_literal_probs(struct xz_dec_lzma2 *s) in lzma_literal_probs() argument
574 uint32_t prev_byte = dict_get(&s->dict, 0); in lzma_literal_probs()
575 uint32_t low = prev_byte >> (8 - s->lzma.lc); in lzma_literal_probs()
576 uint32_t high = (s->dict.pos & s->lzma.literal_pos_mask) << s->lzma.lc; in lzma_literal_probs()
577 return s->lzma.literal[low + high]; in lzma_literal_probs()
581 static void lzma_literal(struct xz_dec_lzma2 *s) in lzma_literal() argument
590 probs = lzma_literal_probs(s); in lzma_literal()
592 if (lzma_state_is_literal(s->lzma.state)) { in lzma_literal()
593 symbol = rc_bittree(&s->rc, probs, 0x100); in lzma_literal()
596 match_byte = dict_get(&s->dict, s->lzma.rep0) << 1; in lzma_literal()
604 if (rc_bit(&s->rc, &probs[i])) { in lzma_literal()
614 dict_put(&s->dict, (uint8_t)symbol); in lzma_literal()
615 lzma_state_literal(&s->lzma.state); in lzma_literal()
618 /* Decode the length of the match into s->lzma.len. */
619 static void lzma_len(struct xz_dec_lzma2 *s, struct lzma_len_dec *l, in lzma_len() argument
625 if (!rc_bit(&s->rc, &l->choice)) { in lzma_len()
628 s->lzma.len = MATCH_LEN_MIN; in lzma_len()
630 if (!rc_bit(&s->rc, &l->choice2)) { in lzma_len()
633 s->lzma.len = MATCH_LEN_MIN + LEN_LOW_SYMBOLS; in lzma_len()
637 s->lzma.len = MATCH_LEN_MIN + LEN_LOW_SYMBOLS in lzma_len()
642 s->lzma.len += rc_bittree(&s->rc, probs, limit) - limit; in lzma_len()
645 /* Decode a match. The distance will be stored in s->lzma.rep0. */
646 static void lzma_match(struct xz_dec_lzma2 *s, uint32_t pos_state) in lzma_match() argument
652 lzma_state_match(&s->lzma.state); in lzma_match()
654 s->lzma.rep3 = s->lzma.rep2; in lzma_match()
655 s->lzma.rep2 = s->lzma.rep1; in lzma_match()
656 s->lzma.rep1 = s->lzma.rep0; in lzma_match()
658 lzma_len(s, &s->lzma.match_len_dec, pos_state); in lzma_match()
660 probs = s->lzma.dist_slot[lzma_get_dist_state(s->lzma.len)]; in lzma_match()
661 dist_slot = rc_bittree(&s->rc, probs, DIST_SLOTS) - DIST_SLOTS; in lzma_match()
664 s->lzma.rep0 = dist_slot; in lzma_match()
667 s->lzma.rep0 = 2 + (dist_slot & 1); in lzma_match()
670 s->lzma.rep0 <<= limit; in lzma_match()
671 probs = s->lzma.dist_special + s->lzma.rep0 in lzma_match()
673 rc_bittree_reverse(&s->rc, probs, in lzma_match()
674 &s->lzma.rep0, limit); in lzma_match()
676 rc_direct(&s->rc, &s->lzma.rep0, limit - ALIGN_BITS); in lzma_match()
677 s->lzma.rep0 <<= ALIGN_BITS; in lzma_match()
678 rc_bittree_reverse(&s->rc, s->lzma.dist_align, in lzma_match()
679 &s->lzma.rep0, ALIGN_BITS); in lzma_match()
686 * seen matches. The distance will be stored in s->lzma.rep0.
688 static void lzma_rep_match(struct xz_dec_lzma2 *s, uint32_t pos_state) in lzma_rep_match() argument
692 if (!rc_bit(&s->rc, &s->lzma.is_rep0[s->lzma.state])) { in lzma_rep_match()
693 if (!rc_bit(&s->rc, &s->lzma.is_rep0_long[ in lzma_rep_match()
694 s->lzma.state][pos_state])) { in lzma_rep_match()
695 lzma_state_short_rep(&s->lzma.state); in lzma_rep_match()
696 s->lzma.len = 1; in lzma_rep_match()
700 if (!rc_bit(&s->rc, &s->lzma.is_rep1[s->lzma.state])) { in lzma_rep_match()
701 tmp = s->lzma.rep1; in lzma_rep_match()
703 if (!rc_bit(&s->rc, &s->lzma.is_rep2[s->lzma.state])) { in lzma_rep_match()
704 tmp = s->lzma.rep2; in lzma_rep_match()
706 tmp = s->lzma.rep3; in lzma_rep_match()
707 s->lzma.rep3 = s->lzma.rep2; in lzma_rep_match()
710 s->lzma.rep2 = s->lzma.rep1; in lzma_rep_match()
713 s->lzma.rep1 = s->lzma.rep0; in lzma_rep_match()
714 s->lzma.rep0 = tmp; in lzma_rep_match()
717 lzma_state_long_rep(&s->lzma.state); in lzma_rep_match()
718 lzma_len(s, &s->lzma.rep_len_dec, pos_state); in lzma_rep_match()
722 static bool lzma_main(struct xz_dec_lzma2 *s) in lzma_main() argument
730 if (dict_has_space(&s->dict) && s->lzma.len > 0) in lzma_main()
731 dict_repeat(&s->dict, &s->lzma.len, s->lzma.rep0); in lzma_main()
737 while (dict_has_space(&s->dict) && !rc_limit_exceeded(&s->rc)) { in lzma_main()
738 pos_state = s->dict.pos & s->lzma.pos_mask; in lzma_main()
740 if (!rc_bit(&s->rc, &s->lzma.is_match[ in lzma_main()
741 s->lzma.state][pos_state])) { in lzma_main()
742 lzma_literal(s); in lzma_main()
744 if (rc_bit(&s->rc, &s->lzma.is_rep[s->lzma.state])) in lzma_main()
745 lzma_rep_match(s, pos_state); in lzma_main()
747 lzma_match(s, pos_state); in lzma_main()
749 if (!dict_repeat(&s->dict, &s->lzma.len, s->lzma.rep0)) in lzma_main()
758 rc_normalize(&s->rc); in lzma_main()
767 static void lzma_reset(struct xz_dec_lzma2 *s) in lzma_reset() argument
772 s->lzma.state = STATE_LIT_LIT; in lzma_reset()
773 s->lzma.rep0 = 0; in lzma_reset()
774 s->lzma.rep1 = 0; in lzma_reset()
775 s->lzma.rep2 = 0; in lzma_reset()
776 s->lzma.rep3 = 0; in lzma_reset()
787 probs = s->lzma.is_match[0]; in lzma_reset()
791 rc_reset(&s->rc); in lzma_reset()
799 static bool lzma_props(struct xz_dec_lzma2 *s, uint8_t props) in lzma_props() argument
804 s->lzma.pos_mask = 0; in lzma_props()
807 ++s->lzma.pos_mask; in lzma_props()
810 s->lzma.pos_mask = (1 << s->lzma.pos_mask) - 1; in lzma_props()
812 s->lzma.literal_pos_mask = 0; in lzma_props()
815 ++s->lzma.literal_pos_mask; in lzma_props()
818 s->lzma.lc = props; in lzma_props()
820 if (s->lzma.lc + s->lzma.literal_pos_mask > 4) in lzma_props()
823 s->lzma.literal_pos_mask = (1 << s->lzma.literal_pos_mask) - 1; in lzma_props()
825 lzma_reset(s); in lzma_props()
835 * The LZMA decoder assumes that if the input limit (s->rc.in_limit) hasn't
837 * wrapper function takes care of making the LZMA decoder's assumption safe.
841 * there's LZMA_IN_REQUIRED bytes left. Those remaining bytes are copied into
842 * s->temp.buf, which (hopefully) gets filled on the next call to this
846 static bool lzma2_lzma(struct xz_dec_lzma2 *s, struct xz_buf *b) in lzma2_lzma() argument
852 if (s->temp.size > 0 || s->lzma2.compressed == 0) { in lzma2_lzma()
853 tmp = 2 * LZMA_IN_REQUIRED - s->temp.size; in lzma2_lzma()
854 if (tmp > s->lzma2.compressed - s->temp.size) in lzma2_lzma()
855 tmp = s->lzma2.compressed - s->temp.size; in lzma2_lzma()
859 memcpy(s->temp.buf + s->temp.size, b->in + b->in_pos, tmp); in lzma2_lzma()
861 if (s->temp.size + tmp == s->lzma2.compressed) { in lzma2_lzma()
862 memzero(s->temp.buf + s->temp.size + tmp, in lzma2_lzma()
863 sizeof(s->temp.buf) in lzma2_lzma()
864 - s->temp.size - tmp); in lzma2_lzma()
865 s->rc.in_limit = s->temp.size + tmp; in lzma2_lzma()
866 } else if (s->temp.size + tmp < LZMA_IN_REQUIRED) { in lzma2_lzma()
867 s->temp.size += tmp; in lzma2_lzma()
871 s->rc.in_limit = s->temp.size + tmp - LZMA_IN_REQUIRED; in lzma2_lzma()
874 s->rc.in = s->temp.buf; in lzma2_lzma()
875 s->rc.in_pos = 0; in lzma2_lzma()
877 if (!lzma_main(s) || s->rc.in_pos > s->temp.size + tmp) in lzma2_lzma()
880 s->lzma2.compressed -= s->rc.in_pos; in lzma2_lzma()
882 if (s->rc.in_pos < s->temp.size) { in lzma2_lzma()
883 s->temp.size -= s->rc.in_pos; in lzma2_lzma()
884 memmove(s->temp.buf, s->temp.buf + s->rc.in_pos, in lzma2_lzma()
885 s->temp.size); in lzma2_lzma()
889 b->in_pos += s->rc.in_pos - s->temp.size; in lzma2_lzma()
890 s->temp.size = 0; in lzma2_lzma()
895 s->rc.in = b->in; in lzma2_lzma()
896 s->rc.in_pos = b->in_pos; in lzma2_lzma()
898 if (in_avail >= s->lzma2.compressed + LZMA_IN_REQUIRED) in lzma2_lzma()
899 s->rc.in_limit = b->in_pos + s->lzma2.compressed; in lzma2_lzma()
901 s->rc.in_limit = b->in_size - LZMA_IN_REQUIRED; in lzma2_lzma()
903 if (!lzma_main(s)) in lzma2_lzma()
906 in_avail = s->rc.in_pos - b->in_pos; in lzma2_lzma()
907 if (in_avail > s->lzma2.compressed) in lzma2_lzma()
910 s->lzma2.compressed -= in_avail; in lzma2_lzma()
911 b->in_pos = s->rc.in_pos; in lzma2_lzma()
916 if (in_avail > s->lzma2.compressed) in lzma2_lzma()
917 in_avail = s->lzma2.compressed; in lzma2_lzma()
919 memcpy(s->temp.buf, b->in + b->in_pos, in_avail); in lzma2_lzma()
920 s->temp.size = in_avail; in lzma2_lzma()
931 XZ_EXTERN enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s, in xz_dec_lzma2_run() argument
936 while (b->in_pos < b->in_size || s->lzma2.sequence == SEQ_LZMA_RUN) { in xz_dec_lzma2_run()
937 switch (s->lzma2.sequence) { in xz_dec_lzma2_run()
948 * Highest three bits (s->control & 0xE0): in xz_dec_lzma2_run()
960 * (s->control & 1F) are the highest bits of the in xz_dec_lzma2_run()
976 s->lzma2.need_props = true; in xz_dec_lzma2_run()
977 s->lzma2.need_dict_reset = false; in xz_dec_lzma2_run()
978 dict_reset(&s->dict, b); in xz_dec_lzma2_run()
979 } else if (s->lzma2.need_dict_reset) { in xz_dec_lzma2_run()
984 s->lzma2.uncompressed = (tmp & 0x1F) << 16; in xz_dec_lzma2_run()
985 s->lzma2.sequence = SEQ_UNCOMPRESSED_1; in xz_dec_lzma2_run()
993 s->lzma2.need_props = false; in xz_dec_lzma2_run()
994 s->lzma2.next_sequence in xz_dec_lzma2_run()
997 } else if (s->lzma2.need_props) { in xz_dec_lzma2_run()
1001 s->lzma2.next_sequence in xz_dec_lzma2_run()
1004 lzma_reset(s); in xz_dec_lzma2_run()
1010 s->lzma2.sequence = SEQ_COMPRESSED_0; in xz_dec_lzma2_run()
1011 s->lzma2.next_sequence = SEQ_COPY; in xz_dec_lzma2_run()
1017 s->lzma2.uncompressed in xz_dec_lzma2_run()
1019 s->lzma2.sequence = SEQ_UNCOMPRESSED_2; in xz_dec_lzma2_run()
1023 s->lzma2.uncompressed in xz_dec_lzma2_run()
1025 s->lzma2.sequence = SEQ_COMPRESSED_0; in xz_dec_lzma2_run()
1029 s->lzma2.compressed in xz_dec_lzma2_run()
1031 s->lzma2.sequence = SEQ_COMPRESSED_1; in xz_dec_lzma2_run()
1035 s->lzma2.compressed in xz_dec_lzma2_run()
1037 s->lzma2.sequence = s->lzma2.next_sequence; in xz_dec_lzma2_run()
1041 if (!lzma_props(s, b->in[b->in_pos++])) in xz_dec_lzma2_run()
1044 s->lzma2.sequence = SEQ_LZMA_PREPARE; in xz_dec_lzma2_run()
1049 if (s->lzma2.compressed < RC_INIT_BYTES) in xz_dec_lzma2_run()
1052 if (!rc_read_init(&s->rc, b)) in xz_dec_lzma2_run()
1055 s->lzma2.compressed -= RC_INIT_BYTES; in xz_dec_lzma2_run()
1056 s->lzma2.sequence = SEQ_LZMA_RUN; in xz_dec_lzma2_run()
1068 * multiple times without changing s->lzma2.sequence. in xz_dec_lzma2_run()
1070 dict_limit(&s->dict, min_t(size_t, in xz_dec_lzma2_run()
1072 s->lzma2.uncompressed)); in xz_dec_lzma2_run()
1073 if (!lzma2_lzma(s, b)) in xz_dec_lzma2_run()
1076 s->lzma2.uncompressed -= dict_flush(&s->dict, b); in xz_dec_lzma2_run()
1078 if (s->lzma2.uncompressed == 0) { in xz_dec_lzma2_run()
1079 if (s->lzma2.compressed > 0 || s->lzma.len > 0 in xz_dec_lzma2_run()
1080 || !rc_is_finished(&s->rc)) in xz_dec_lzma2_run()
1083 rc_reset(&s->rc); in xz_dec_lzma2_run()
1084 s->lzma2.sequence = SEQ_CONTROL; in xz_dec_lzma2_run()
1088 && s->temp.size in xz_dec_lzma2_run()
1089 < s->lzma2.compressed)) { in xz_dec_lzma2_run()
1096 dict_uncompressed(&s->dict, b, &s->lzma2.compressed); in xz_dec_lzma2_run()
1097 if (s->lzma2.compressed > 0) in xz_dec_lzma2_run()
1100 s->lzma2.sequence = SEQ_CONTROL; in xz_dec_lzma2_run()
1111 struct xz_dec_lzma2 *s = kmalloc(sizeof(*s), GFP_KERNEL); in xz_dec_lzma2_create() local
1112 if (s == NULL) in xz_dec_lzma2_create()
1115 s->dict.mode = mode; in xz_dec_lzma2_create()
1116 s->dict.size_max = dict_max; in xz_dec_lzma2_create()
1119 s->dict.buf = vmalloc(dict_max); in xz_dec_lzma2_create()
1120 if (s->dict.buf == NULL) { in xz_dec_lzma2_create()
1121 kfree(s); in xz_dec_lzma2_create()
1125 s->dict.buf = NULL; in xz_dec_lzma2_create()
1126 s->dict.allocated = 0; in xz_dec_lzma2_create()
1129 return s; in xz_dec_lzma2_create()
1132 XZ_EXTERN enum xz_ret xz_dec_lzma2_reset(struct xz_dec_lzma2 *s, uint8_t props) in xz_dec_lzma2_reset() argument
1138 s->dict.size = 2 + (props & 1); in xz_dec_lzma2_reset()
1139 s->dict.size <<= (props >> 1) + 11; in xz_dec_lzma2_reset()
1141 if (DEC_IS_MULTI(s->dict.mode)) { in xz_dec_lzma2_reset()
1142 if (s->dict.size > s->dict.size_max) in xz_dec_lzma2_reset()
1145 s->dict.end = s->dict.size; in xz_dec_lzma2_reset()
1147 if (DEC_IS_DYNALLOC(s->dict.mode)) { in xz_dec_lzma2_reset()
1148 if (s->dict.allocated < s->dict.size) { in xz_dec_lzma2_reset()
1149 s->dict.allocated = s->dict.size; in xz_dec_lzma2_reset()
1150 vfree(s->dict.buf); in xz_dec_lzma2_reset()
1151 s->dict.buf = vmalloc(s->dict.size); in xz_dec_lzma2_reset()
1152 if (s->dict.buf == NULL) { in xz_dec_lzma2_reset()
1153 s->dict.allocated = 0; in xz_dec_lzma2_reset()
1160 s->lzma.len = 0; in xz_dec_lzma2_reset()
1162 s->lzma2.sequence = SEQ_CONTROL; in xz_dec_lzma2_reset()
1163 s->lzma2.need_dict_reset = true; in xz_dec_lzma2_reset()
1165 s->temp.size = 0; in xz_dec_lzma2_reset()
1170 XZ_EXTERN void xz_dec_lzma2_end(struct xz_dec_lzma2 *s) in xz_dec_lzma2_end() argument
1172 if (DEC_IS_MULTI(s->dict.mode)) in xz_dec_lzma2_end()
1173 vfree(s->dict.buf); in xz_dec_lzma2_end()
1175 kfree(s); in xz_dec_lzma2_end()