Rizin
unix-like reverse engineering framework and cli tools
common.h
Go to the documentation of this file.
1 //
5 //
6 // Author: Lasse Collin
7 //
8 // This file has been put into the public domain.
9 // You can do whatever you want with this file.
10 //
12 
13 #ifndef LZMA_COMMON_H
14 #define LZMA_COMMON_H
15 
16 #include "sysdefs.h"
17 #include "mythread.h"
18 #include "tuklib_integer.h"
19 
20 #if defined(_WIN32) || defined(__CYGWIN__)
21 # ifdef DLL_EXPORT
22 # define LZMA_API_EXPORT __declspec(dllexport)
23 # else
24 # define LZMA_API_EXPORT
25 # endif
26 // Don't use ifdef or defined() below.
27 #elif HAVE_VISIBILITY
28 # define LZMA_API_EXPORT __attribute__((__visibility__("default")))
29 #else
30 # define LZMA_API_EXPORT
31 #endif
32 
33 #define LZMA_API(type) LZMA_API_EXPORT type LZMA_API_CALL
34 
35 #include "lzma.h"
36 
37 // These allow helping the compiler in some often-executed branches, whose
38 // result is almost always the same.
39 #ifdef __GNUC__
40 # define likely(expr) __builtin_expect(expr, true)
41 # define unlikely(expr) __builtin_expect(expr, false)
42 #else
43 # define likely(expr) (expr)
44 # define unlikely(expr) (expr)
45 #endif
46 
47 
49 #define LZMA_BUFFER_SIZE 4096
50 
51 
56 #define LZMA_THREADS_MAX 16384
57 
58 
63 #define LZMA_MEMUSAGE_BASE (UINT64_C(1) << 15)
64 
67 #define LZMA_FILTER_RESERVED_START (LZMA_VLI_C(1) << 62)
68 
69 
72 #define LZMA_SUPPORTED_FLAGS \
73  ( LZMA_TELL_NO_CHECK \
74  | LZMA_TELL_UNSUPPORTED_CHECK \
75  | LZMA_TELL_ANY_CHECK \
76  | LZMA_IGNORE_CHECK \
77  | LZMA_CONCATENATED )
78 
79 
81 #define LZMA_ACTION_MAX ((unsigned int)(LZMA_FULL_BARRIER))
82 
83 
88 #define LZMA_TIMED_OUT 32
89 
90 
91 typedef struct lzma_next_coder_s lzma_next_coder;
92 
94 
95 
99  const lzma_filter_info *filters);
100 
106  void *coder, const lzma_allocator *allocator,
107  const uint8_t *restrict in, size_t *restrict in_pos,
108  size_t in_size, uint8_t *restrict out,
109  size_t *restrict out_pos, size_t out_size,
111 
113 typedef void (*lzma_end_function)(
114  void *coder, const lzma_allocator *allocator);
115 
116 
124 
128 
130  void *options;
131 };
132 
133 
137  void *coder;
138 
142 
148 
151 
156 
159  void (*get_progress)(void *coder,
160  uint64_t *progress_in, uint64_t *progress_out);
161 
164  lzma_check (*get_check)(const void *coder);
165 
168  lzma_ret (*memconfig)(void *coder, uint64_t *memusage,
169  uint64_t *old_memlimit, uint64_t new_memlimit);
170 
174  const lzma_filter *filters,
175  const lzma_filter *reversed_filters);
176 };
177 
178 
180 #define LZMA_NEXT_CODER_INIT \
181  (lzma_next_coder){ \
182  .coder = NULL, \
183  .init = (uintptr_t)(NULL), \
184  .id = LZMA_VLI_UNKNOWN, \
185  .code = NULL, \
186  .end = NULL, \
187  .get_progress = NULL, \
188  .get_check = NULL, \
189  .memconfig = NULL, \
190  .update = NULL, \
191  }
192 
193 
199 
204  enum {
213 
217  size_t avail_in;
218 
221 
225 };
226 
227 
229 extern void *lzma_alloc(size_t size, const lzma_allocator *allocator)
230  lzma_attribute((__malloc__)) lzma_attr_alloc_size(1);
231 
235 extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
236  lzma_alloc_zero(size_t size, const lzma_allocator *allocator);
237 
239 extern void lzma_free(void *ptr, const lzma_allocator *allocator);
240 
241 
245 
253 
258  const lzma_filter *reversed_filters);
259 
262 extern void lzma_next_end(lzma_next_coder *next,
264 
265 
268 extern size_t lzma_bufcpy(const uint8_t *restrict in, size_t *restrict in_pos,
269  size_t in_size, uint8_t *restrict out,
270  size_t *restrict out_pos, size_t out_size);
271 
272 
278 #define return_if_error(expr) \
279 do { \
280  const lzma_ret ret_ = (expr); \
281  if (ret_ != LZMA_OK) \
282  return ret_; \
283 } while (0)
284 
285 
291 #define lzma_next_coder_init(func, next, allocator) \
292 do { \
293  if ((uintptr_t)(func) != (next)->init) \
294  lzma_next_end(next, allocator); \
295  (next)->init = (uintptr_t)(func); \
296 } while (0)
297 
298 
303 #define lzma_next_strm_init(func, strm, ...) \
304 do { \
305  return_if_error(lzma_strm_init(strm)); \
306  const lzma_ret ret_ = func(&(strm)->internal->next, \
307  (strm)->allocator, __VA_ARGS__); \
308  if (ret_ != LZMA_OK) { \
309  lzma_end(strm); \
310  return ret_; \
311  } \
312 } while (0)
313 
314 #endif
lzma_check
Type of the integrity check (Check ID)
Definition: check.h:27
const lzma_allocator const uint8_t size_t uint8_t size_t * out_pos
Definition: block.h:528
const lzma_allocator const uint8_t size_t * in_pos
Definition: block.h:579
const lzma_allocator const uint8_t size_t in_size
Definition: block.h:527
const lzma_allocator const uint8_t * in
Definition: block.h:527
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
const lzma_filter * filters
Definition: container.h:315
static lzma_stream strm
Definition: full_flush.c:20
voidpf void uLong size
Definition: ioapi.h:138
#define restrict
#define const
Definition: ansidecl.h:240
The public API of liblzma data compression library.
Some threading related helper macros and functions.
unsigned long uint64_t
Definition: sftypes.h:28
unsigned char uint8_t
Definition: sftypes.h:31
_W64 unsigned int uintptr_t
Custom functions for memory handling.
Definition: base.h:372
void * options
Pointer to filter's options structure.
Definition: common.h:130
lzma_vli id
Definition: common.h:123
lzma_init_function init
Definition: common.h:127
Filter options.
Definition: filter.h:43
lzma_next_coder next
The actual coder that should do something useful.
Definition: common.h:198
bool supported_actions[LZMA_ACTION_MAX+1]
Indicates which lzma_action values are allowed by next.code.
Definition: common.h:220
@ ISEQ_FULL_BARRIER
Definition: common.h:209
bool allow_buf_error
Definition: common.h:224
enum lzma_internal_s::@645 sequence
size_t avail_in
Definition: common.h:217
Hold data and function pointers of the next filter in the chain.
Definition: common.h:135
void(* get_progress)(void *coder, uint64_t *progress_in, uint64_t *progress_out)
Definition: common.h:159
lzma_code_function code
Pointer to function to do the actual coding.
Definition: common.h:150
void * coder
Pointer to coder-specific data.
Definition: common.h:137
lzma_vli id
Definition: common.h:141
lzma_check(* get_check)(const void *coder)
Definition: common.h:164
uintptr_t init
Definition: common.h:147
lzma_end_function end
Definition: common.h:155
lzma_ret(* update)(void *coder, const lzma_allocator *allocator, const lzma_filter *filters, const lzma_filter *reversed_filters)
Definition: common.h:173
lzma_ret(* memconfig)(void *coder, uint64_t *memusage, uint64_t *old_memlimit, uint64_t new_memlimit)
Definition: common.h:168
Passing data to and from liblzma.
Definition: base.h:485
lzma_ret lzma_next_filter_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
Definition: common.c:116
void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1) lzma_alloc_zero(size_t size
void lzma_free(void *ptr, const lzma_allocator *allocator)
Frees memory.
Definition: common.c:78
#define LZMA_ACTION_MAX
Largest valid lzma_action value as unsigned integer.
Definition: common.h:81
lzma_ret(* lzma_code_function)(void *coder, const lzma_allocator *allocator, const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size, lzma_action action)
Definition: common.h:105
lzma_ret lzma_strm_init(lzma_stream *strm)
Definition: common.c:170
lzma_ret(* lzma_init_function)(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
Type of a function used to initialize a filter encoder or decoder.
Definition: common.h:97
void * lzma_alloc(size_t size, const lzma_allocator *allocator) lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
Allocates memory.
size_t lzma_bufcpy(const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size)
Definition: common.c:94
lzma_ret lzma_next_filter_update(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter *reversed_filters)
Definition: common.c:127
void(* lzma_end_function)(void *coder, const lzma_allocator *allocator)
Type of a function to free the memory allocated for the coder.
Definition: common.h:113
void lzma_next_end(lzma_next_coder *next, const lzma_allocator *allocator)
Definition: common.c:145
void const lzma_allocator * allocator
Definition: common.h:236
Common includes, definitions, system-specific things etc.
#define lzma_attr_alloc_size(x)
Definition: sysdefs.h:196
Various integer and bit operations.
uint64_t lzma_vli
Variable-length integer type.
Definition: vli.h:63
lzma_ret
Return values used by several functions in liblzma.
Definition: base.h:57
lzma_action
The ‘action’ argument for lzma_code()
Definition: base.h:250
uint64_t * progress_in
Definition: base.h:599