Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:10

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 #       define memeq(a, b, size) (memcmp(a, b, size) == 0)
0041 #       define memzero(buf, size) memset(buf, 0, size)
0042 #   endif
0043 #   define get_le32(p) le32_to_cpup((const uint32_t *)(p))
0044 #else
0045     /*
0046      * For userspace builds, use a separate header to define the required
0047      * macros and functions. This makes it easier to adapt the code into
0048      * different environments and avoids clutter in the Linux kernel tree.
0049      */
0050 #   include "xz_config.h"
0051 #endif
0052 
0053 /* If no specific decoding mode is requested, enable support for all modes. */
0054 #if !defined(XZ_DEC_SINGLE) && !defined(XZ_DEC_PREALLOC) \
0055         && !defined(XZ_DEC_DYNALLOC)
0056 #   define XZ_DEC_SINGLE
0057 #   define XZ_DEC_PREALLOC
0058 #   define XZ_DEC_DYNALLOC
0059 #endif
0060 
0061 /*
0062  * The DEC_IS_foo(mode) macros are used in "if" statements. If only some
0063  * of the supported modes are enabled, these macros will evaluate to true or
0064  * false at compile time and thus allow the compiler to omit unneeded code.
0065  */
0066 #ifdef XZ_DEC_SINGLE
0067 #   define DEC_IS_SINGLE(mode) ((mode) == XZ_SINGLE)
0068 #else
0069 #   define DEC_IS_SINGLE(mode) (false)
0070 #endif
0071 
0072 #ifdef XZ_DEC_PREALLOC
0073 #   define DEC_IS_PREALLOC(mode) ((mode) == XZ_PREALLOC)
0074 #else
0075 #   define DEC_IS_PREALLOC(mode) (false)
0076 #endif
0077 
0078 #ifdef XZ_DEC_DYNALLOC
0079 #   define DEC_IS_DYNALLOC(mode) ((mode) == XZ_DYNALLOC)
0080 #else
0081 #   define DEC_IS_DYNALLOC(mode) (false)
0082 #endif
0083 
0084 #if !defined(XZ_DEC_SINGLE)
0085 #   define DEC_IS_MULTI(mode) (true)
0086 #elif defined(XZ_DEC_PREALLOC) || defined(XZ_DEC_DYNALLOC)
0087 #   define DEC_IS_MULTI(mode) ((mode) != XZ_SINGLE)
0088 #else
0089 #   define DEC_IS_MULTI(mode) (false)
0090 #endif
0091 
0092 /*
0093  * If any of the BCJ filter decoders are wanted, define XZ_DEC_BCJ.
0094  * XZ_DEC_BCJ is used to enable generic support for BCJ decoders.
0095  */
0096 #ifndef XZ_DEC_BCJ
0097 #   if defined(XZ_DEC_X86) || defined(XZ_DEC_POWERPC) \
0098             || defined(XZ_DEC_IA64) || defined(XZ_DEC_ARM) \
0099             || defined(XZ_DEC_ARM) || defined(XZ_DEC_ARMTHUMB) \
0100             || defined(XZ_DEC_SPARC)
0101 #       define XZ_DEC_BCJ
0102 #   endif
0103 #endif
0104 
0105 /*
0106  * Allocate memory for LZMA2 decoder. xz_dec_lzma2_reset() must be used
0107  * before calling xz_dec_lzma2_run().
0108  */
0109 XZ_EXTERN struct xz_dec_lzma2 *xz_dec_lzma2_create(enum xz_mode mode,
0110                            uint32_t dict_max);
0111 
0112 /*
0113  * Decode the LZMA2 properties (one byte) and reset the decoder. Return
0114  * XZ_OK on success, XZ_MEMLIMIT_ERROR if the preallocated dictionary is not
0115  * big enough, and XZ_OPTIONS_ERROR if props indicates something that this
0116  * decoder doesn't support.
0117  */
0118 XZ_EXTERN enum xz_ret xz_dec_lzma2_reset(struct xz_dec_lzma2 *s,
0119                      uint8_t props);
0120 
0121 /* Decode raw LZMA2 stream from b->in to b->out. */
0122 XZ_EXTERN enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s,
0123                        struct xz_buf *b);
0124 
0125 /* Free the memory allocated for the LZMA2 decoder. */
0126 XZ_EXTERN void xz_dec_lzma2_end(struct xz_dec_lzma2 *s);
0127 
0128 #ifdef XZ_DEC_BCJ
0129 /*
0130  * Allocate memory for BCJ decoders. xz_dec_bcj_reset() must be used before
0131  * calling xz_dec_bcj_run().
0132  */
0133 XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool single_call);
0134 
0135 /*
0136  * Decode the Filter ID of a BCJ filter. This implementation doesn't
0137  * support custom start offsets, so no decoding of Filter Properties
0138  * is needed. Returns XZ_OK if the given Filter ID is supported.
0139  * Otherwise XZ_OPTIONS_ERROR is returned.
0140  */
0141 XZ_EXTERN enum xz_ret xz_dec_bcj_reset(struct xz_dec_bcj *s, uint8_t id);
0142 
0143 /*
0144  * Decode raw BCJ + LZMA2 stream. This must be used only if there actually is
0145  * a BCJ filter in the chain. If the chain has only LZMA2, xz_dec_lzma2_run()
0146  * must be called directly.
0147  */
0148 XZ_EXTERN enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s,
0149                      struct xz_dec_lzma2 *lzma2,
0150                      struct xz_buf *b);
0151 
0152 /* Free the memory allocated for the BCJ filters. */
0153 #define xz_dec_bcj_end(s) kfree(s)
0154 #endif
0155 
0156 #endif