Linux Audio

Check our new training course

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