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