31 #include <sys/types.h> 40 #ifndef XD3_DEFAULT_WINSIZE 41 #define XD3_DEFAULT_WINSIZE (1U << 23) 45 #ifndef XD3_DEFAULT_SRCWINSZ 46 #define XD3_DEFAULT_SRCWINSZ (1U << 26) 53 #define XD3_ALLOCSIZE (1U<<14) 62 #ifndef XD3_HARDMAXWINSIZE 63 #define XD3_HARDMAXWINSIZE (1U<<24) 70 #ifndef XD3_DEFAULT_IOPT_SIZE 71 #define XD3_DEFAULT_IOPT_SIZE (1U<<15) 75 #ifndef XD3_DEFAULT_SPREVSZ 76 #define XD3_DEFAULT_SPREVSZ (1U<<18) 81 #ifndef XD3_DEFAULT_LEVEL 82 #define XD3_DEFAULT_LEVEL 3 85 #ifndef XD3_DEFAULT_SECONDARY_LEVEL 86 #define XD3_DEFAULT_SECONDARY_LEVEL 6 89 #ifndef XD3_USE_LARGEFILE64 90 #define XD3_USE_LARGEFILE64 1 104 #define WIN32_LEAN_AND_MEAN 105 #if XD3_USE_LARGEFILE64 108 #define WINVER 0x0500 109 #define _WIN32_WINNT 0x0500 113 #define WINVER 0x0400 114 #define _WIN32_WINNT 0x0400 120 typedef signed int ssize_t;
121 typedef unsigned char uint8_t;
122 typedef unsigned short uint16_t;
123 typedef unsigned long uint32_t;
124 typedef ULONGLONG uint64_t;
134 #if XD3_USE_LARGEFILE64 135 #define __USE_FILE_OFFSET64 1 136 #ifndef _LARGEFILE_SOURCE 137 #define _LARGEFILE_SOURCE 139 #ifndef _FILE_OFFSET_BITS 140 #define _FILE_OFFSET_BITS 64 144 #define SIZEOF_XOFF_T 8 145 #define SIZEOF_USIZE_T 4 153 #define SIZEOF_XOFF_T 4 154 #define SIZEOF_USIZE_T 4 158 #define USE_UINT32 (SIZEOF_USIZE_T == 4 || \ 159 SIZEOF_XOFF_T == 4 || REGRESSION_TEST) 160 #define USE_UINT64 (SIZEOF_USIZE_T == 8 || \ 161 SIZEOF_XOFF_T == 8 || REGRESSION_TEST) 165 #if defined(__i386__) || defined(__i486__) || defined(__i586__) || \ 166 defined(__i686__) || defined(_X86_) || defined(__x86_64__) 167 #define UNALIGNED_OK 1 169 #define UNALIGNED_OK 0 177 #define XD3_ENCODER 1 183 #define EXIT_FAILURE 1 188 #ifndef REGRESSION_TEST 189 #define REGRESSION_TEST 0 199 #ifndef PYTHON_MODULE 200 #define PYTHON_MODULE 0 204 #define SWIG_MODULE 0 210 #ifndef XD3_BUILD_SLOW 211 #define XD3_BUILD_SLOW 1 213 #ifndef XD3_BUILD_FAST 214 #define XD3_BUILD_FAST 1 216 #ifndef XD3_BUILD_FASTER 217 #define XD3_BUILD_FASTER 1 219 #ifndef XD3_BUILD_FASTEST 220 #define XD3_BUILD_FASTEST 1 222 #ifndef XD3_BUILD_SOFT 223 #define XD3_BUILD_SOFT 1 225 #ifndef XD3_BUILD_DEFAULT 226 #define XD3_BUILD_DEFAULT 1 283 const uint8_t **data,
289 #define XD3_ASSERT(x) \ 290 do { if (! (x)) { DP(RINT "%s:%d: XD3 assertion failed: %s\n", __FILE__, __LINE__, #x); \ 291 abort (); } } while (0) 293 #define XD3_ASSERT(x) (void)0 298 #define max(x,y) ({ \ 299 const typeof(x) _x = (x); \ 300 const typeof(y) _y = (y); \ 301 (void) (&_x == &_y); \ 302 _x > _y ? _x : _y; }) 306 #define min(x,y) ({ \ 307 const typeof(x) _x = (x); \ 308 const typeof(y) _y = (y); \ 309 (void) (&_x == &_y); \ 310 _x < _y ? _x : _y; }) 314 #define max(x,y) ((x) < (y) ? (y) : (x)) 317 #define min(x,y) ((x) < (y) ? (x) : (y)) 904 uint8_t dec_magic[4];
923 uint8_t dec_cksum[4];
1030 const uint8_t *source,
1032 uint8_t *output_buffer,
1040 const uint8_t *source,
1042 uint8_t *output_buf,
1089 const uint8_t *input,
1097 const uint8_t *input,
1206 const uint8_t *data,
1230 xoff_t addr,
int is_source);
1242 memset (config, 0,
sizeof (*config));
1243 config->
flags = flags;
1264 const uint8_t *idata,
1308 stream->
flags = flags;
1316 return stream->
msg ? stream->
msg :
"";
1343 blkdiff = *blkoff >> source->
shiftby;
1348 *blkoff &= source->
maskby;
static const char * xd3_errstring(xd3_stream *stream)
void xd3_abort_stream(xd3_stream *stream)
int( xd3_getblk_func)(xd3_stream *stream, xd3_source *source, xoff_t blkno)
void xd3_free_stream(xd3_stream *stream)
static void xd3_init_config(xd3_config *config, int flags)
static void xd3_avail_input(xd3_stream *stream, const uint8_t *idata, usize_t isize)
const uint8_t * enc_appheader
int xd3_encode_init_partial(xd3_stream *stream)
xd3_whole_state whole_target
void xd3_set_appheader(xd3_stream *stream, const uint8_t *data, usize_t size)
const uint8_t * dec_tgtaddrbase
const xd3_sec_type * sec_type
int xd3_config_stream(xd3_stream *stream, xd3_config *config)
xd3_sec_stream * sec_stream_d
struct _xd3_rpage xd3_rpage
struct _xd3_sec_stream xd3_sec_stream
xd3_comp_table_func * comp_table_func
void *( xd3_alloc_func)(void *opaque, usize_t items, usize_t size)
xd3_smatcher smatcher_soft
xd3_dinst * code_table_alloc
void xd3_init_cache(xd3_addr_cache *acache)
int( xd3_comp_table_func)(xd3_stream *stream, const uint8_t **data, usize_t *size)
xd3_decode_state dec_state
int xd3_found_match(xd3_stream *stream, usize_t pos, usize_t size, xoff_t addr, int is_source)
int xd3_close_stream(xd3_stream *stream)
int xd3_set_source_and_size(xd3_stream *stream, xd3_source *source, xoff_t source_size)
int xd3_decode_memory(const uint8_t *input, usize_t input_size, const uint8_t *source, usize_t source_size, uint8_t *output_buf, usize_t *output_size, usize_t avail_output, int flags)
static void xd3_consume_output(xd3_stream *stream)
const xd3_dinst * code_table
struct _xd3_sec_type xd3_sec_type
const xd3_code_table_desc * code_table_desc
const xd3_dinst *( xd3_code_table_func)(void)
int xd3_decode_stream(xd3_stream *stream, const uint8_t *input, usize_t input_size, uint8_t *output, usize_t *output_size, usize_t avail_size)
xd3_sec_stream * sec_stream_i
static void xd3_blksize_div(const xoff_t offset, const xd3_source *source, xoff_t *blkno, usize_t *blkoff)
xd3_iopt_buflist * iopt_alloc
static void xd3_blksize_add(xoff_t *blkno, usize_t *blkoff, const xd3_source *source, const usize_t add)
xd3_encode_state enc_state
struct _xd3_code_table_sizes xd3_code_table_sizes
int xd3_encode_stream(xd3_stream *stream, const uint8_t *input, usize_t input_size, uint8_t *output, usize_t *output_size, usize_t avail_output)
struct _xd3_code_table_desc xd3_code_table_desc
static usize_t xd3_encoder_srclen(xd3_stream *stream)
int xd3_get_appheader(xd3_stream *stream, uint8_t **data, usize_t *size)
static xoff_t xd3_encoder_srcbase(xd3_stream *stream)
int xd3_set_source(xd3_stream *stream, xd3_source *source)
void( xd3_free_func)(void *opaque, void *address)
const char * xd3_strerror(int ret)
int xd3_decode_input(xd3_stream *stream)
xd3_match_state match_state
xd3_sec_stream * sec_stream_a
xd3_smatch_cfg smatch_cfg
const uint8_t * dec_cpyaddrbase
xd3_code_table_func * code_table_func
const uint8_t * buf_leftover
int xd3_encode_memory(const uint8_t *input, usize_t input_size, const uint8_t *source, usize_t source_size, uint8_t *output_buffer, usize_t *output_size, usize_t avail_output, int flags)
static int xd3_encoder_used_source(xd3_stream *stream)
int xd3_encode_input(xd3_stream *stream)
static void xd3_set_flags(xd3_stream *stream, int flags)