Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Private includes and definitions
0003  *
0004  * Author: Lasse Collin <lasse.collin@tukaani.org>
0005  *
0006  * This file has been put into the public domain.
0007  * You can do whatever you want with this file.
0008  */
0009 
0010 #ifndef XZ_PRIVATE_H
0011 #define XZ_PRIVATE_H
0012 
0013 #ifdef __KERNEL__
0014 #   include <linux/xz.h>
0015 #   include <linux/kernel.h>
0016 #   include <asm/unaligned.h>
0017     /* XZ_PREBOOT may be defined only via decompress_unxz.c. */
0018 #   ifndef XZ_PREBOOT
0019 #       include <linux/slab.h>
0020 #       include <linux/vmalloc.h>
0021 #       include <linux/string.h>
0022 #       ifdef CONFIG_XZ_DEC_X86
0023 #           define XZ_DEC_X86
0024 #       endif
0025 #       ifdef CONFIG_XZ_DEC_POWERPC
0026 #           define XZ_DEC_POWERPC
0027 #       endif
0028 #       ifdef CONFIG_XZ_DEC_IA64
0029 #           define XZ_DEC_IA64
0030 #       endif
0031 #       ifdef CONFIG_XZ_DEC_ARM
0032 #           define XZ_DEC_ARM
0033 #       endif
0034 #       ifdef CONFIG_XZ_DEC_ARMTHUMB
0035 #           define XZ_DEC_ARMTHUMB
0036 #       endif
0037 #       ifdef CONFIG_XZ_DEC_SPARC
0038 #           define XZ_DEC_SPARC
0039 #       endif
0040 #       ifdef CONFIG_XZ_DEC_MICROLZMA
0041 #           define XZ_DEC_MICROLZMA
0042 #       endif
0043 #       define memeq(a, b, size) (memcmp(a, b, size) == 0)
0044 #       define memzero(buf, size) memset(buf, 0, size)
0045 #   endif
0046 #   define get_le32(p) le32_to_cpup((const uint32_t *)(p))
0047 #else
0048     /*
0049      * For userspace builds, use a separate header to define the required
0050      * macros and functions. This makes it easier to adapt the code into
0051      * different environments and avoids clutter in the Linux kernel tree.
0052      */
0053 #   include "xz_config.h"
0054 #endif
0055 
0056 /* If no specific decoding mode is requested, enable support for all modes. */
0057 #if !defined(XZ_DEC_SINGLE) && !defined(XZ_DEC_PREALLOC) \
0058         && !defined(XZ_DEC_DYNALLOC)
0059 #   define XZ_DEC_SINGLE
0060 #   define XZ_DEC_PREALLOC
0061 #   define XZ_DEC_DYNALLOC
0062 #endif
0063 
0064 /*
0065  * The DEC_IS_foo(mode) macros are used in "if" statements. If only some
0066  * of the supported modes are enabled, these macros will evaluate to true or
0067  * false at compile time and thus allow the compiler to omit unneeded code.
0068  */
0069 #ifdef XZ_DEC_SINGLE
0070 #   define DEC_IS_SINGLE(mode) ((mode) == XZ_SINGLE)
0071 #else
0072 #   define DEC_IS_SINGLE(mode) (false)
0073 #endif
0074 
0075 #ifdef XZ_DEC_PREALLOC
0076 #   define DEC_IS_PREALLOC(mode) ((mode) == XZ_PREALLOC)
0077 #else
0078 #   define DEC_IS_PREALLOC(mode) (false)
0079 #endif
0080 
0081 #ifdef XZ_DEC_DYNALLOC
0082 #   define DEC_IS_DYNALLOC(mode) ((mode) == XZ_DYNALLOC)
0083 #else
0084 #   define DEC_IS_DYNALLOC(mode) (false)
0085 #endif
0086 
0087 #if !defined(XZ_DEC_SINGLE)
0088 #   define DEC_IS_MULTI(mode) (true)
0089 #elif defined(XZ_DEC_PREALLOC) || defined(XZ_DEC_DYNALLOC)
0090 #   define DEC_IS_MULTI(mode) ((mode) != XZ_SINGLE)
0091 #else
0092 #   define DEC_IS_MULTI(mode) (false)
0093 #endif
0094 
0095 /*
0096  * If any of the BCJ filter decoders are wanted, define XZ_DEC_BCJ.
0097  * XZ_DEC_BCJ is used to enable generic support for BCJ decoders.
0098  */
0099 #ifndef XZ_DEC_BCJ
0100 #   if defined(XZ_DEC_X86) || defined(XZ_DEC_POWERPC) \
0101             || defined(XZ_DEC_IA64) || defined(XZ_DEC_ARM) \
0102             || defined(XZ_DEC_ARM) || defined(XZ_DEC_ARMTHUMB) \
0103             || defined(XZ_DEC_SPARC)
0104 #       define XZ_DEC_BCJ
0105 #   endif
0106 #endif
0107 
0108 #ifndef CRC32_POLY_LE
0109 #define CRC32_POLY_LE 0xedb88320
0110 #endif
0111 
0112 /*
0113  * Allocate memory for LZMA2 decoder. xz_dec_lzma2_reset() must be used
0114  * before calling xz_dec_lzma2_run().
0115  */
0116 XZ_EXTERN struct xz_dec_lzma2 *xz_dec_lzma2_create(enum xz_mode mode,
0117                            uint32_t dict_max);
0118 
0119 /*
0120  * Decode the LZMA2 properties (one byte) and reset the decoder. Return
0121  * XZ_OK on success, XZ_MEMLIMIT_ERROR if the preallocated dictionary is not
0122  * big enough, and XZ_OPTIONS_ERROR if props indicates something that this
0123  * decoder doesn't support.
0124  */
0125 XZ_EXTERN enum xz_ret xz_dec_lzma2_reset(struct xz_dec_lzma2 *s,
0126                      uint8_t props);
0127 
0128 /* Decode raw LZMA2 stream from b->in to b->out. */
0129 XZ_EXTERN enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s,
0130                        struct xz_buf *b);
0131 
0132 /* Free the memory allocated for the LZMA2 decoder. */
0133 XZ_EXTERN void xz_dec_lzma2_end(struct xz_dec_lzma2 *s);
0134 
0135 #ifdef XZ_DEC_BCJ
0136 /*
0137  * Allocate memory for BCJ decoders. xz_dec_bcj_reset() must be used before
0138  * calling xz_dec_bcj_run().
0139  */
0140 XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool single_call);
0141 
0142 /*
0143  * Decode the Filter ID of a BCJ filter. This implementation doesn't
0144  * support custom start offsets, so no decoding of Filter Properties
0145  * is needed. Returns XZ_OK if the given Filter ID is supported.
0146  * Otherwise XZ_OPTIONS_ERROR is returned.
0147  */
0148 XZ_EXTERN enum xz_ret xz_dec_bcj_reset(struct xz_dec_bcj *s, uint8_t id);
0149 
0150 /*
0151  * Decode raw BCJ + LZMA2 stream. This must be used only if there actually is
0152  * a BCJ filter in the chain. If the chain has only LZMA2, xz_dec_lzma2_run()
0153  * must be called directly.
0154  */
0155 XZ_EXTERN enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s,
0156                      struct xz_dec_lzma2 *lzma2,
0157                      struct xz_buf *b);
0158 
0159 /* Free the memory allocated for the BCJ filters. */
0160 #define xz_dec_bcj_end(s) kfree(s)
0161 #endif
0162 
0163 #endif