Skip to content

Commit

Permalink
packer: sync xz sources from Swiss
Browse files Browse the repository at this point in the history
  • Loading branch information
9ary committed Aug 12, 2024
1 parent fa6b5d6 commit d363ae4
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 79 deletions.
50 changes: 25 additions & 25 deletions packer/xz/xz.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/* SPDX-License-Identifier: 0BSD */

/*
* XZ decompressor
*
* Authors: Lasse Collin <[email protected]>
* Igor Pavlov <https://7-zip.org/>
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*/

#ifndef XZ_H
Expand Down Expand Up @@ -147,7 +146,7 @@ struct xz_buf {
size_t out_size;
};

/**
/*
* struct xz_dec - Opaque type to hold the XZ decoder state
*/
struct xz_dec;
Expand Down Expand Up @@ -216,7 +215,7 @@ XZ_EXTERN struct xz_dec *xz_dec_init(enum xz_mode mode, uint32_t dict_max);
* the multi-call decoder if you don't want to uncompress the whole stream.
*
* Use xz_dec_run() when XZ data is stored inside some other file format.
* The decoding will stop after one XZ stream has been decompresed. To
* The decoding will stop after one XZ stream has been decompressed. To
* decompress regular .xz files which might have multiple concatenated
* streams, use xz_dec_catrun() instead.
*/
Expand Down Expand Up @@ -279,23 +278,33 @@ XZ_EXTERN void xz_dec_reset(struct xz_dec *s);
*/
XZ_EXTERN void xz_dec_end(struct xz_dec *s);

/*
* Decompressor for MicroLZMA, an LZMA variant with a very minimal header.
* See xz_dec_microlzma_alloc() below for details.
/**
* DOC: MicroLZMA decompressor
*
* This MicroLZMA header format was created for use in EROFS but may be used
* by others too. **In most cases one needs the XZ APIs above instead.**
*
* The compressed format supported by this decoder is a raw LZMA stream
* whose first byte (always 0x00) has been replaced with bitwise-negation
* of the LZMA properties (lc/lp/pb) byte. For example, if lc/lp/pb is
* 3/0/2, the first byte is 0xA2. This way the first byte can never be 0x00.
* Just like with LZMA2, lc + lp <= 4 must be true. The LZMA end-of-stream
* marker must not be used. The unused values are reserved for future use.
*
* These functions aren't used or available in preboot code and thus aren't
* marked with XZ_EXTERN. This avoids warnings about static functions that
* are never defined.
*/
/**

/*
* struct xz_dec_microlzma - Opaque type to hold the MicroLZMA decoder state
*/
struct xz_dec_microlzma;

/**
* xz_dec_microlzma_alloc() - Allocate memory for the MicroLZMA decoder
* @mode XZ_SINGLE or XZ_PREALLOC
* @dict_size LZMA dictionary size. This must be at least 4 KiB and
* @mode: XZ_SINGLE or XZ_PREALLOC
* @dict_size: LZMA dictionary size. This must be at least 4 KiB and
* at most 3 GiB.
*
* In contrast to xz_dec_init(), this function only allocates the memory
Expand All @@ -308,30 +317,21 @@ struct xz_dec_microlzma;
* On success, xz_dec_microlzma_alloc() returns a pointer to
* struct xz_dec_microlzma. If memory allocation fails or
* dict_size is invalid, NULL is returned.
*
* The compressed format supported by this decoder is a raw LZMA stream
* whose first byte (always 0x00) has been replaced with bitwise-negation
* of the LZMA properties (lc/lp/pb) byte. For example, if lc/lp/pb is
* 3/0/2, the first byte is 0xA2. This way the first byte can never be 0x00.
* Just like with LZMA2, lc + lp <= 4 must be true. The LZMA end-of-stream
* marker must not be used. The unused values are reserved for future use.
* This MicroLZMA header format was created for use in EROFS but may be used
* by others too.
*/
extern struct xz_dec_microlzma *xz_dec_microlzma_alloc(enum xz_mode mode,
uint32_t dict_size);

/**
* xz_dec_microlzma_reset() - Reset the MicroLZMA decoder state
* @s Decoder state allocated using xz_dec_microlzma_alloc()
* @comp_size Compressed size of the input stream
* @uncomp_size Uncompressed size of the input stream. A value smaller
* @s: Decoder state allocated using xz_dec_microlzma_alloc()
* @comp_size: Compressed size of the input stream
* @uncomp_size: Uncompressed size of the input stream. A value smaller
* than the real uncompressed size of the input stream can
* be specified if uncomp_size_is_exact is set to false.
* uncomp_size can never be set to a value larger than the
* expected real uncompressed size because it would eventually
* result in XZ_DATA_ERROR.
* @uncomp_size_is_exact This is an int instead of bool to avoid
* @uncomp_size_is_exact: This is an int instead of bool to avoid
* requiring stdbool.h. This should normally be set to true.
* When this is set to false, error detection is weaker.
*/
Expand All @@ -341,7 +341,7 @@ extern void xz_dec_microlzma_reset(struct xz_dec_microlzma *s,

/**
* xz_dec_microlzma_run() - Run the MicroLZMA decoder
* @s Decoder state initialized using xz_dec_microlzma_reset()
* @s: Decoder state initialized using xz_dec_microlzma_reset()
* @b: Input and output buffers
*
* This works similarly to xz_dec_run() with a few important differences.
Expand Down
28 changes: 17 additions & 11 deletions packer/xz/xz_config.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* SPDX-License-Identifier: 0BSD */

/*
* Private includes and definitions for userspace use of XZ Embedded
*
* Author: Lasse Collin <[email protected]>
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*/

#ifndef XZ_CONFIG_H
Expand All @@ -25,23 +24,20 @@
/* #define XZ_DEC_ARM */
/* #define XZ_DEC_ARMTHUMB */
/* #define XZ_DEC_ARM64 */
/* #define XZ_DEC_RISCV */
#define XZ_DEC_POWERPC
/* #define XZ_DEC_IA64 */
/* #define XZ_DEC_SPARC */

/*
* MSVC doesn't support modern C but XZ Embedded is mostly C89
* so these are enough.
* Visual Studio 2013 update 2 supports only __inline, not inline.
* MSVC v19.0 / VS 2015 and newer support both.
*/
#ifdef _MSC_VER
typedef unsigned char bool;
# define true 1
# define false 0
#if defined(_MSC_VER) && _MSC_VER < 1900 && !defined(inline)
# define inline __inline
#else
# include <stdbool.h>
#endif

#include <stdbool.h>
#include <stdlib.h>
#include <string.h>

Expand All @@ -61,6 +57,16 @@ void memzero(void *buf, size_t size);
#endif
#define min_t(type, x, y) min(x, y)

#ifndef fallthrough
# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000
# define fallthrough [[fallthrough]]
# elif defined(__GNUC__) && __GNUC__ >= 7
# define fallthrough __attribute__((__fallthrough__))
# else
# define fallthrough do {} while (0)
# endif
#endif

/*
* Some functions have been marked with __always_inline to keep the
* performance reasonable even when the compiler is optimizing for
Expand Down
5 changes: 2 additions & 3 deletions packer/xz/xz_crc32.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// SPDX-License-Identifier: 0BSD

/*
* CRC32 using the polynomial from IEEE-802.3
*
* Authors: Lasse Collin <[email protected]>
* Igor Pavlov <https://7-zip.org/>
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*/

/*
Expand Down
5 changes: 2 additions & 3 deletions packer/xz/xz_crc64.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// SPDX-License-Identifier: 0BSD

/*
* CRC64 using the polynomial from ECMA-182
*
* This file is similar to xz_crc32.c. See the comments there.
*
* Authors: Lasse Collin <[email protected]>
* Igor Pavlov <https://7-zip.org/>
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*/

#include "xz_private.h"
Expand Down
Loading

0 comments on commit d363ae4

Please sign in to comment.