1 /* 1 /* 2 * Private includes and definitions 2 * Private includes and definitions 3 * 3 * 4 * Author: Lasse Collin <lasse.collin@tukaani. 4 * Author: Lasse Collin <lasse.collin@tukaani.org> 5 * 5 * 6 * This file has been put into the public doma 6 * This file has been put into the public domain. 7 * You can do whatever you want with this file 7 * You can do whatever you want with this file. 8 */ 8 */ 9 9 10 #ifndef XZ_PRIVATE_H 10 #ifndef XZ_PRIVATE_H 11 #define XZ_PRIVATE_H 11 #define XZ_PRIVATE_H 12 12 13 #ifdef __KERNEL__ 13 #ifdef __KERNEL__ 14 # include <linux/xz.h> 14 # include <linux/xz.h> 15 # include <linux/kernel.h> 15 # include <linux/kernel.h> 16 # include <asm/unaligned.h> 16 # include <asm/unaligned.h> 17 /* XZ_PREBOOT may be defined only via 17 /* XZ_PREBOOT may be defined only via decompress_unxz.c. */ 18 # ifndef XZ_PREBOOT 18 # ifndef XZ_PREBOOT 19 # include <linux/slab.h> 19 # include <linux/slab.h> 20 # include <linux/vmalloc.h> 20 # include <linux/vmalloc.h> 21 # include <linux/string.h> 21 # include <linux/string.h> 22 # ifdef CONFIG_XZ_DEC_X86 22 # ifdef CONFIG_XZ_DEC_X86 23 # define XZ_DEC_X86 23 # define XZ_DEC_X86 24 # endif 24 # endif 25 # ifdef CONFIG_XZ_DEC_POWERPC 25 # ifdef CONFIG_XZ_DEC_POWERPC 26 # define XZ_DEC_POWERPC 26 # define XZ_DEC_POWERPC 27 # endif 27 # endif 28 # ifdef CONFIG_XZ_DEC_IA64 28 # ifdef CONFIG_XZ_DEC_IA64 29 # define XZ_DEC_IA64 29 # define XZ_DEC_IA64 30 # endif 30 # endif 31 # ifdef CONFIG_XZ_DEC_ARM 31 # ifdef CONFIG_XZ_DEC_ARM 32 # define XZ_DEC_ARM 32 # define XZ_DEC_ARM 33 # endif 33 # endif 34 # ifdef CONFIG_XZ_DEC_ARMTHUMB 34 # ifdef CONFIG_XZ_DEC_ARMTHUMB 35 # define XZ_DEC_ARMTHUMB 35 # define XZ_DEC_ARMTHUMB 36 # endif 36 # endif 37 # ifdef CONFIG_XZ_DEC_SPARC 37 # ifdef CONFIG_XZ_DEC_SPARC 38 # define XZ_DEC_SPARC 38 # define XZ_DEC_SPARC 39 # endif 39 # endif 40 # ifdef CONFIG_XZ_DEC_MICROLZMA 40 # ifdef CONFIG_XZ_DEC_MICROLZMA 41 # define XZ_DEC_MICROLZM 41 # define XZ_DEC_MICROLZMA 42 # endif 42 # endif 43 # define memeq(a, b, size) (memc 43 # define memeq(a, b, size) (memcmp(a, b, size) == 0) 44 # define memzero(buf, size) mems 44 # define memzero(buf, size) memset(buf, 0, size) 45 # endif 45 # endif 46 # define get_le32(p) le32_to_cpup((const 46 # define get_le32(p) le32_to_cpup((const uint32_t *)(p)) 47 #else 47 #else 48 /* 48 /* 49 * For userspace builds, use a separat 49 * For userspace builds, use a separate header to define the required 50 * macros and functions. This makes it 50 * macros and functions. This makes it easier to adapt the code into 51 * different environments and avoids c 51 * different environments and avoids clutter in the Linux kernel tree. 52 */ 52 */ 53 # include "xz_config.h" 53 # include "xz_config.h" 54 #endif 54 #endif 55 55 56 /* If no specific decoding mode is requested, 56 /* If no specific decoding mode is requested, enable support for all modes. */ 57 #if !defined(XZ_DEC_SINGLE) && !defined(XZ_DEC 57 #if !defined(XZ_DEC_SINGLE) && !defined(XZ_DEC_PREALLOC) \ 58 && !defined(XZ_DEC_DYNALLOC) 58 && !defined(XZ_DEC_DYNALLOC) 59 # define XZ_DEC_SINGLE 59 # define XZ_DEC_SINGLE 60 # define XZ_DEC_PREALLOC 60 # define XZ_DEC_PREALLOC 61 # define XZ_DEC_DYNALLOC 61 # define XZ_DEC_DYNALLOC 62 #endif 62 #endif 63 63 64 /* 64 /* 65 * The DEC_IS_foo(mode) macros are used in "if 65 * The DEC_IS_foo(mode) macros are used in "if" statements. If only some 66 * of the supported modes are enabled, these m 66 * of the supported modes are enabled, these macros will evaluate to true or 67 * false at compile time and thus allow the co 67 * false at compile time and thus allow the compiler to omit unneeded code. 68 */ 68 */ 69 #ifdef XZ_DEC_SINGLE 69 #ifdef XZ_DEC_SINGLE 70 # define DEC_IS_SINGLE(mode) ((mode) == 70 # define DEC_IS_SINGLE(mode) ((mode) == XZ_SINGLE) 71 #else 71 #else 72 # define DEC_IS_SINGLE(mode) (false) 72 # define DEC_IS_SINGLE(mode) (false) 73 #endif 73 #endif 74 74 75 #ifdef XZ_DEC_PREALLOC 75 #ifdef XZ_DEC_PREALLOC 76 # define DEC_IS_PREALLOC(mode) ((mode) = 76 # define DEC_IS_PREALLOC(mode) ((mode) == XZ_PREALLOC) 77 #else 77 #else 78 # define DEC_IS_PREALLOC(mode) (false) 78 # define DEC_IS_PREALLOC(mode) (false) 79 #endif 79 #endif 80 80 81 #ifdef XZ_DEC_DYNALLOC 81 #ifdef XZ_DEC_DYNALLOC 82 # define DEC_IS_DYNALLOC(mode) ((mode) = 82 # define DEC_IS_DYNALLOC(mode) ((mode) == XZ_DYNALLOC) 83 #else 83 #else 84 # define DEC_IS_DYNALLOC(mode) (false) 84 # define DEC_IS_DYNALLOC(mode) (false) 85 #endif 85 #endif 86 86 87 #if !defined(XZ_DEC_SINGLE) 87 #if !defined(XZ_DEC_SINGLE) 88 # define DEC_IS_MULTI(mode) (true) 88 # define DEC_IS_MULTI(mode) (true) 89 #elif defined(XZ_DEC_PREALLOC) || defined(XZ_D 89 #elif defined(XZ_DEC_PREALLOC) || defined(XZ_DEC_DYNALLOC) 90 # define DEC_IS_MULTI(mode) ((mode) != X 90 # define DEC_IS_MULTI(mode) ((mode) != XZ_SINGLE) 91 #else 91 #else 92 # define DEC_IS_MULTI(mode) (false) 92 # define DEC_IS_MULTI(mode) (false) 93 #endif 93 #endif 94 94 95 /* 95 /* 96 * If any of the BCJ filter decoders are wante 96 * If any of the BCJ filter decoders are wanted, define XZ_DEC_BCJ. 97 * XZ_DEC_BCJ is used to enable generic suppor 97 * XZ_DEC_BCJ is used to enable generic support for BCJ decoders. 98 */ 98 */ 99 #ifndef XZ_DEC_BCJ 99 #ifndef XZ_DEC_BCJ 100 # if defined(XZ_DEC_X86) || defined(XZ_D 100 # if defined(XZ_DEC_X86) || defined(XZ_DEC_POWERPC) \ 101 || defined(XZ_DEC_IA64 101 || defined(XZ_DEC_IA64) || defined(XZ_DEC_ARM) \ 102 || defined(XZ_DEC_ARM) 102 || defined(XZ_DEC_ARM) || defined(XZ_DEC_ARMTHUMB) \ 103 || defined(XZ_DEC_SPAR 103 || defined(XZ_DEC_SPARC) 104 # define XZ_DEC_BCJ 104 # define XZ_DEC_BCJ 105 # endif 105 # endif 106 #endif 106 #endif 107 107 >> 108 #ifndef CRC32_POLY_LE >> 109 #define CRC32_POLY_LE 0xedb88320 >> 110 #endif >> 111 108 /* 112 /* 109 * Allocate memory for LZMA2 decoder. xz_dec_l 113 * Allocate memory for LZMA2 decoder. xz_dec_lzma2_reset() must be used 110 * before calling xz_dec_lzma2_run(). 114 * before calling xz_dec_lzma2_run(). 111 */ 115 */ 112 XZ_EXTERN struct xz_dec_lzma2 *xz_dec_lzma2_cr 116 XZ_EXTERN struct xz_dec_lzma2 *xz_dec_lzma2_create(enum xz_mode mode, 113 117 uint32_t dict_max); 114 118 115 /* 119 /* 116 * Decode the LZMA2 properties (one byte) and 120 * Decode the LZMA2 properties (one byte) and reset the decoder. Return 117 * XZ_OK on success, XZ_MEMLIMIT_ERROR if the 121 * XZ_OK on success, XZ_MEMLIMIT_ERROR if the preallocated dictionary is not 118 * big enough, and XZ_OPTIONS_ERROR if props i 122 * big enough, and XZ_OPTIONS_ERROR if props indicates something that this 119 * decoder doesn't support. 123 * decoder doesn't support. 120 */ 124 */ 121 XZ_EXTERN enum xz_ret xz_dec_lzma2_reset(struc 125 XZ_EXTERN enum xz_ret xz_dec_lzma2_reset(struct xz_dec_lzma2 *s, 122 uint8 126 uint8_t props); 123 127 124 /* Decode raw LZMA2 stream from b->in to b->ou 128 /* Decode raw LZMA2 stream from b->in to b->out. */ 125 XZ_EXTERN enum xz_ret xz_dec_lzma2_run(struct 129 XZ_EXTERN enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s, 126 struct 130 struct xz_buf *b); 127 131 128 /* Free the memory allocated for the LZMA2 dec 132 /* Free the memory allocated for the LZMA2 decoder. */ 129 XZ_EXTERN void xz_dec_lzma2_end(struct xz_dec_ 133 XZ_EXTERN void xz_dec_lzma2_end(struct xz_dec_lzma2 *s); 130 134 131 #ifdef XZ_DEC_BCJ 135 #ifdef XZ_DEC_BCJ 132 /* 136 /* 133 * Allocate memory for BCJ decoders. xz_dec_bc 137 * Allocate memory for BCJ decoders. xz_dec_bcj_reset() must be used before 134 * calling xz_dec_bcj_run(). 138 * calling xz_dec_bcj_run(). 135 */ 139 */ 136 XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create 140 XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool single_call); 137 141 138 /* 142 /* 139 * Decode the Filter ID of a BCJ filter. This 143 * Decode the Filter ID of a BCJ filter. This implementation doesn't 140 * support custom start offsets, so no decodin 144 * support custom start offsets, so no decoding of Filter Properties 141 * is needed. Returns XZ_OK if the given Filte 145 * is needed. Returns XZ_OK if the given Filter ID is supported. 142 * Otherwise XZ_OPTIONS_ERROR is returned. 146 * Otherwise XZ_OPTIONS_ERROR is returned. 143 */ 147 */ 144 XZ_EXTERN enum xz_ret xz_dec_bcj_reset(struct 148 XZ_EXTERN enum xz_ret xz_dec_bcj_reset(struct xz_dec_bcj *s, uint8_t id); 145 149 146 /* 150 /* 147 * Decode raw BCJ + LZMA2 stream. This must be 151 * Decode raw BCJ + LZMA2 stream. This must be used only if there actually is 148 * a BCJ filter in the chain. If the chain has 152 * a BCJ filter in the chain. If the chain has only LZMA2, xz_dec_lzma2_run() 149 * must be called directly. 153 * must be called directly. 150 */ 154 */ 151 XZ_EXTERN enum xz_ret xz_dec_bcj_run(struct xz 155 XZ_EXTERN enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s, 152 struct xz 156 struct xz_dec_lzma2 *lzma2, 153 struct xz 157 struct xz_buf *b); 154 158 155 /* Free the memory allocated for the BCJ filte 159 /* Free the memory allocated for the BCJ filters. */ 156 #define xz_dec_bcj_end(s) kfree(s) 160 #define xz_dec_bcj_end(s) kfree(s) 157 #endif 161 #endif 158 162 159 #endif 163 #endif 160 164
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.