2 * Private includes and definitions
4 * Author: Lasse Collin <lasse.collin@tukaani.org>
6 * This file has been put into the public domain.
7 * You can do whatever you want with this file.
14 # include <linux/xz.h>
15 # include <linux/kernel.h>
16 # include <asm/unaligned.h>
17 /* XZ_PREBOOT may be defined only via decompress_unxz.c. */
19 # include <linux/slab.h>
20 # include <linux/vmalloc.h>
21 # include <linux/string.h>
22 # ifdef CONFIG_XZ_DEC_X86
25 # ifdef CONFIG_XZ_DEC_POWERPC
26 # define XZ_DEC_POWERPC
28 # ifdef CONFIG_XZ_DEC_IA64
31 # ifdef CONFIG_XZ_DEC_ARM
34 # ifdef CONFIG_XZ_DEC_ARMTHUMB
35 # define XZ_DEC_ARMTHUMB
37 # ifdef CONFIG_XZ_DEC_SPARC
40 # ifdef CONFIG_XZ_DEC_MICROLZMA
41 # define XZ_DEC_MICROLZMA
43 # define memeq(a, b, size) (memcmp(a, b, size) == 0)
44 # define memzero(buf, size) memset(buf, 0, size)
46 # define get_le32(p) le32_to_cpup((const uint32_t *)(p))
49 * For userspace builds, use a separate header to define the required
50 * macros and functions. This makes it easier to adapt the code into
51 * different environments and avoids clutter in the Linux kernel tree.
53 # include "xz_config.h"
56 /* If no specific decoding mode is requested, enable support for all modes. */
57 #if !defined(XZ_DEC_SINGLE) && !defined(XZ_DEC_PREALLOC) \
58 && !defined(XZ_DEC_DYNALLOC)
59 # define XZ_DEC_SINGLE
60 # define XZ_DEC_PREALLOC
61 # define XZ_DEC_DYNALLOC
65 * The DEC_IS_foo(mode) macros are used in "if" statements. If only some
66 * of the supported modes are enabled, these macros will evaluate to true or
67 * false at compile time and thus allow the compiler to omit unneeded code.
70 # define DEC_IS_SINGLE(mode) ((mode) == XZ_SINGLE)
72 # define DEC_IS_SINGLE(mode) (false)
75 #ifdef XZ_DEC_PREALLOC
76 # define DEC_IS_PREALLOC(mode) ((mode) == XZ_PREALLOC)
78 # define DEC_IS_PREALLOC(mode) (false)
81 #ifdef XZ_DEC_DYNALLOC
82 # define DEC_IS_DYNALLOC(mode) ((mode) == XZ_DYNALLOC)
84 # define DEC_IS_DYNALLOC(mode) (false)
87 #if !defined(XZ_DEC_SINGLE)
88 # define DEC_IS_MULTI(mode) (true)
89 #elif defined(XZ_DEC_PREALLOC) || defined(XZ_DEC_DYNALLOC)
90 # define DEC_IS_MULTI(mode) ((mode) != XZ_SINGLE)
92 # define DEC_IS_MULTI(mode) (false)
96 * If any of the BCJ filter decoders are wanted, define XZ_DEC_BCJ.
97 * XZ_DEC_BCJ is used to enable generic support for BCJ decoders.
100 # if defined(XZ_DEC_X86) || defined(XZ_DEC_POWERPC) \
101 || defined(XZ_DEC_IA64) || defined(XZ_DEC_ARM) \
102 || defined(XZ_DEC_ARM) || defined(XZ_DEC_ARMTHUMB) \
103 || defined(XZ_DEC_SPARC)
108 #ifndef CRC32_POLY_LE
109 #define CRC32_POLY_LE 0xedb88320
113 * Allocate memory for LZMA2 decoder. xz_dec_lzma2_reset() must be used
114 * before calling xz_dec_lzma2_run().
116 XZ_EXTERN struct xz_dec_lzma2 *xz_dec_lzma2_create(enum xz_mode mode,
120 * Decode the LZMA2 properties (one byte) and reset the decoder. Return
121 * XZ_OK on success, XZ_MEMLIMIT_ERROR if the preallocated dictionary is not
122 * big enough, and XZ_OPTIONS_ERROR if props indicates something that this
123 * decoder doesn't support.
125 XZ_EXTERN enum xz_ret xz_dec_lzma2_reset(struct xz_dec_lzma2 *s,
128 /* Decode raw LZMA2 stream from b->in to b->out. */
129 XZ_EXTERN enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s,
132 /* Free the memory allocated for the LZMA2 decoder. */
133 XZ_EXTERN void xz_dec_lzma2_end(struct xz_dec_lzma2 *s);
137 * Allocate memory for BCJ decoders. xz_dec_bcj_reset() must be used before
138 * calling xz_dec_bcj_run().
140 XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool single_call);
143 * Decode the Filter ID of a BCJ filter. This implementation doesn't
144 * support custom start offsets, so no decoding of Filter Properties
145 * is needed. Returns XZ_OK if the given Filter ID is supported.
146 * Otherwise XZ_OPTIONS_ERROR is returned.
148 XZ_EXTERN enum xz_ret xz_dec_bcj_reset(struct xz_dec_bcj *s, uint8_t id);
151 * Decode raw BCJ + LZMA2 stream. This must be used only if there actually is
152 * a BCJ filter in the chain. If the chain has only LZMA2, xz_dec_lzma2_run()
153 * must be called directly.
155 XZ_EXTERN enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s,
156 struct xz_dec_lzma2 *lzma2,
159 /* Free the memory allocated for the BCJ filters. */
160 #define xz_dec_bcj_end(s) kfree(s)