Path: blob/main/sys/contrib/xz-embedded/linux/lib/xz/xz_private.h
48521 views
/*1* Private includes and definitions2*3* Author: Lasse Collin <[email protected]>4*5* This file has been put into the public domain.6* You can do whatever you want with this file.7*/89#ifndef XZ_PRIVATE_H10#define XZ_PRIVATE_H1112#ifdef __KERNEL__13# include <linux/xz.h>14# include <linux/kernel.h>15# include <asm/unaligned.h>16/* XZ_PREBOOT may be defined only via decompress_unxz.c. */17# ifndef XZ_PREBOOT18# include <linux/slab.h>19# include <linux/vmalloc.h>20# include <linux/string.h>21# ifdef CONFIG_XZ_DEC_X8622# define XZ_DEC_X8623# endif24# ifdef CONFIG_XZ_DEC_POWERPC25# define XZ_DEC_POWERPC26# endif27# ifdef CONFIG_XZ_DEC_IA6428# define XZ_DEC_IA6429# endif30# ifdef CONFIG_XZ_DEC_ARM31# define XZ_DEC_ARM32# endif33# ifdef CONFIG_XZ_DEC_ARMTHUMB34# define XZ_DEC_ARMTHUMB35# endif36# ifdef CONFIG_XZ_DEC_SPARC37# define XZ_DEC_SPARC38# endif39# ifdef CONFIG_XZ_DEC_MICROLZMA40# define XZ_DEC_MICROLZMA41# endif42# define memeq(a, b, size) (memcmp(a, b, size) == 0)43# define memzero(buf, size) memset(buf, 0, size)44# endif45# define get_le32(p) le32_to_cpup((const uint32_t *)(p))46#else47/*48* For userspace builds, use a separate header to define the required49* macros and functions. This makes it easier to adapt the code into50* different environments and avoids clutter in the Linux kernel tree.51*/52# include <contrib/xz-embedded/freebsd/xz_config.h>53#endif5455/* If no specific decoding mode is requested, enable support for all modes. */56#if !defined(XZ_DEC_SINGLE) && !defined(XZ_DEC_PREALLOC) \57&& !defined(XZ_DEC_DYNALLOC)58# define XZ_DEC_SINGLE59# define XZ_DEC_PREALLOC60# define XZ_DEC_DYNALLOC61#endif6263/*64* The DEC_IS_foo(mode) macros are used in "if" statements. If only some65* of the supported modes are enabled, these macros will evaluate to true or66* false at compile time and thus allow the compiler to omit unneeded code.67*/68#ifdef XZ_DEC_SINGLE69# define DEC_IS_SINGLE(mode) ((mode) == XZ_SINGLE)70#else71# define DEC_IS_SINGLE(mode) (false)72#endif7374#ifdef XZ_DEC_PREALLOC75# define DEC_IS_PREALLOC(mode) ((mode) == XZ_PREALLOC)76#else77# define DEC_IS_PREALLOC(mode) (false)78#endif7980#ifdef XZ_DEC_DYNALLOC81# define DEC_IS_DYNALLOC(mode) ((mode) == XZ_DYNALLOC)82#else83# define DEC_IS_DYNALLOC(mode) (false)84#endif8586#if !defined(XZ_DEC_SINGLE)87# define DEC_IS_MULTI(mode) (true)88#elif defined(XZ_DEC_PREALLOC) || defined(XZ_DEC_DYNALLOC)89# define DEC_IS_MULTI(mode) ((mode) != XZ_SINGLE)90#else91# define DEC_IS_MULTI(mode) (false)92#endif9394/*95* If any of the BCJ filter decoders are wanted, define XZ_DEC_BCJ.96* XZ_DEC_BCJ is used to enable generic support for BCJ decoders.97*/98#ifndef XZ_DEC_BCJ99# if defined(XZ_DEC_X86) || defined(XZ_DEC_POWERPC) \100|| defined(XZ_DEC_IA64) || defined(XZ_DEC_ARM) \101|| defined(XZ_DEC_ARM) || defined(XZ_DEC_ARMTHUMB) \102|| defined(XZ_DEC_SPARC)103# define XZ_DEC_BCJ104# endif105#endif106107/*108* Allocate memory for LZMA2 decoder. xz_dec_lzma2_reset() must be used109* before calling xz_dec_lzma2_run().110*/111XZ_EXTERN struct xz_dec_lzma2 *xz_dec_lzma2_create(enum xz_mode mode,112uint32_t dict_max);113114/*115* Decode the LZMA2 properties (one byte) and reset the decoder. Return116* XZ_OK on success, XZ_MEMLIMIT_ERROR if the preallocated dictionary is not117* big enough, and XZ_OPTIONS_ERROR if props indicates something that this118* decoder doesn't support.119*/120XZ_EXTERN enum xz_ret xz_dec_lzma2_reset(struct xz_dec_lzma2 *s,121uint8_t props);122123/* Decode raw LZMA2 stream from b->in to b->out. */124XZ_EXTERN enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s,125struct xz_buf *b);126127/* Free the memory allocated for the LZMA2 decoder. */128XZ_EXTERN void xz_dec_lzma2_end(struct xz_dec_lzma2 *s);129130#ifdef XZ_DEC_BCJ131/*132* Allocate memory for BCJ decoders. xz_dec_bcj_reset() must be used before133* calling xz_dec_bcj_run().134*/135XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool single_call);136137/*138* Decode the Filter ID of a BCJ filter. This implementation doesn't139* support custom start offsets, so no decoding of Filter Properties140* is needed. Returns XZ_OK if the given Filter ID is supported.141* Otherwise XZ_OPTIONS_ERROR is returned.142*/143XZ_EXTERN enum xz_ret xz_dec_bcj_reset(struct xz_dec_bcj *s, uint8_t id);144145/*146* Decode raw BCJ + LZMA2 stream. This must be used only if there actually is147* a BCJ filter in the chain. If the chain has only LZMA2, xz_dec_lzma2_run()148* must be called directly.149*/150XZ_EXTERN enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s,151struct xz_dec_lzma2 *lzma2,152struct xz_buf *b);153154/* Free the memory allocated for the BCJ filters. */155#define xz_dec_bcj_end(s) kfree(s)156#endif157158#endif159160161