aboutsummaryrefslogtreecommitdiffstats
path: root/lib/lzo
diff options
context:
space:
mode:
authorWe-unite <3205135446@qq.com>2025-03-08 22:04:20 +0800
committerWe-unite <3205135446@qq.com>2025-03-08 22:04:20 +0800
commita07bb8fd1299070229f0e8f3dcb57ffd5ef9870a (patch)
tree84f21bd0bf7071bc5fc7dd989e77d7ceb5476682 /lib/lzo
downloadohosKernel-a07bb8fd1299070229f0e8f3dcb57ffd5ef9870a.tar.gz
ohosKernel-a07bb8fd1299070229f0e8f3dcb57ffd5ef9870a.zip
Initial commit: OpenHarmony-v4.0-ReleaseOpenHarmony-v4.0-Release
Diffstat (limited to 'lib/lzo')
-rw-r--r--lib/lzo/Makefile6
-rw-r--r--lib/lzo/lzo1x_compress.c400
-rw-r--r--lib/lzo/lzo1x_decompress_safe.c296
-rw-r--r--lib/lzo/lzodefs.h71
4 files changed, 773 insertions, 0 deletions
diff --git a/lib/lzo/Makefile b/lib/lzo/Makefile
new file mode 100644
index 000000000..2f58fafbb
--- /dev/null
+++ b/lib/lzo/Makefile
@@ -0,0 +1,6 @@
1# SPDX-License-Identifier: GPL-2.0-only
2lzo_compress-objs := lzo1x_compress.o
3lzo_decompress-objs := lzo1x_decompress_safe.o
4
5obj-$(CONFIG_LZO_COMPRESS) += lzo_compress.o
6obj-$(CONFIG_LZO_DECOMPRESS) += lzo_decompress.o
diff --git a/lib/lzo/lzo1x_compress.c b/lib/lzo/lzo1x_compress.c
new file mode 100644
index 000000000..8ad5ba2b8
--- /dev/null
+++ b/lib/lzo/lzo1x_compress.c
@@ -0,0 +1,400 @@
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * LZO1X Compressor from LZO
4 *
5 * Copyright (C) 1996-2012 Markus F.X.J. Oberhumer <markus@oberhumer.com>
6 *
7 * The full LZO package can be found at:
8 * http://www.oberhumer.com/opensource/lzo/
9 *
10 * Changed for Linux kernel use by:
11 * Nitin Gupta <nitingupta910@gmail.com>
12 * Richard Purdie <rpurdie@openedhand.com>
13 */
14
15#include <linux/module.h>
16#include <linux/kernel.h>
17#include <asm/unaligned.h>
18#include <linux/lzo.h>
19#include "lzodefs.h"
20
21static noinline size_t
22lzo1x_1_do_compress(const unsigned char *in, size_t in_len,
23 unsigned char *out, size_t *out_len,
24 size_t ti, void *wrkmem, signed char *state_offset,
25 const unsigned char bitstream_version)
26{
27 const unsigned char *ip;
28 unsigned char *op;
29 const unsigned char * const in_end = in + in_len;
30 const unsigned char * const ip_end = in + in_len - 20;
31 const unsigned char *ii;
32 lzo_dict_t * const dict = (lzo_dict_t *) wrkmem;
33
34 op = out;
35 ip = in;
36 ii = ip;
37 ip += ti < 4 ? 4 - ti : 0;
38
39 for (;;) {
40 const unsigned char *m_pos = NULL;
41 size_t t, m_len, m_off;
42 u32 dv;
43 u32 run_length = 0;
44literal:
45 ip += 1 + ((ip - ii) >> 5);
46next:
47 if (unlikely(ip >= ip_end))
48 break;
49 dv = get_unaligned_le32(ip);
50
51 if (dv == 0 && bitstream_version) {
52 const unsigned char *ir = ip + 4;
53 const unsigned char *limit = ip_end
54 < (ip + MAX_ZERO_RUN_LENGTH + 1)
55 ? ip_end : ip + MAX_ZERO_RUN_LENGTH + 1;
56#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && \
57 defined(LZO_FAST_64BIT_MEMORY_ACCESS)
58 u64 dv64;
59
60 for (; (ir + 32) <= limit; ir += 32) {
61 dv64 = get_unaligned((u64 *)ir);
62 dv64 |= get_unaligned((u64 *)ir + 1);
63 dv64 |= get_unaligned((u64 *)ir + 2);
64 dv64 |= get_unaligned((u64 *)ir + 3);
65 if (dv64)
66 break;
67 }
68 for (; (ir + 8) <= limit; ir += 8) {
69 dv64 = get_unaligned((u64 *)ir);
70 if (dv64) {
71# if defined(__LITTLE_ENDIAN)
72 ir += __builtin_ctzll(dv64) >> 3;
73# elif defined(__BIG_ENDIAN)
74 ir += __builtin_clzll(dv64) >> 3;
75# else
76# error "missing endian definition"
77# endif
78 break;
79 }
80 }
81#else
82 while ((ir < (const unsigned char *)
83 ALIGN((uintptr_t)ir, 4)) &&
84 (ir < limit) && (*ir == 0))
85 ir++;
86 if (IS_ALIGNED((uintptr_t)ir, 4)) {
87 for (; (ir + 4) <= limit; ir += 4) {
88 dv = *((u32 *)ir);
89 if (dv) {
90# if defined(__LITTLE_ENDIAN)
91 ir += __builtin_ctz(dv) >> 3;
92# elif defined(__BIG_ENDIAN)
93 ir += __builtin_clz(dv) >> 3;
94# else
95# error "missing endian definition"
96# endif
97 break;
98 }
99 }
100 }
101#endif
102 while (likely(ir < limit) && unlikely(*ir == 0))
103 ir++;
104 run_length = ir - ip;
105 if (run_length > MAX_ZERO_RUN_LENGTH)
106 run_length = MAX_ZERO_RUN_LENGTH;
107 } else {
108 t = ((dv * 0x1824429d) >> (32 - D_BITS)) & D_MASK;
109 m_pos = in + dict[t];
110 dict[t] = (lzo_dict_t) (ip - in);
111 if (unlikely(dv != get_unaligned_le32(m_pos)))
112 goto literal;
113 }
114
115 ii -= ti;
116 ti = 0;
117 t = ip - ii;
118 if (t != 0) {
119 if (t <= 3) {
120 op[*state_offset] |= t;
121 COPY4(op, ii);
122 op += t;
123 } else if (t <= 16) {
124 *op++ = (t - 3);
125 COPY8(op, ii);
126 COPY8(op + 8, ii + 8);
127 op += t;
128 } else {
129 if (t <= 18) {
130 *op++ = (t - 3);
131 } else {
132 size_t tt = t - 18;
133 *op++ = 0;
134 while (unlikely(tt > 255)) {
135 tt -= 255;
136 *op++ = 0;
137 }
138 *op++ = tt;
139 }
140 do {
141 COPY8(op, ii);
142 COPY8(op + 8, ii + 8);
143 op += 16;
144 ii += 16;
145 t -= 16;
146 } while (t >= 16);
147 if (t > 0) do {
148 *op++ = *ii++;
149 } while (--t > 0);
150 }
151 }
152
153 if (unlikely(run_length)) {
154 ip += run_length;
155 run_length -= MIN_ZERO_RUN_LENGTH;
156 put_unaligned_le32((run_length << 21) | 0xfffc18
157 | (run_length & 0x7), op);
158 op += 4;
159 run_length = 0;
160 *state_offset = -3;
161 goto finished_writing_instruction;
162 }
163
164 m_len = 4;
165 {
166#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && defined(LZO_USE_CTZ64)
167 u64 v;
168 v = get_unaligned((const u64 *) (ip + m_len)) ^
169 get_unaligned((const u64 *) (m_pos + m_len));
170 if (unlikely(v == 0)) {
171 do {
172 m_len += 8;
173 v = get_unaligned((const u64 *) (ip + m_len)) ^
174 get_unaligned((const u64 *) (m_pos + m_len));
175 if (unlikely(ip + m_len >= ip_end))
176 goto m_len_done;
177 } while (v == 0);
178 }
179# if defined(__LITTLE_ENDIAN)
180 m_len += (unsigned) __builtin_ctzll(v) / 8;
181# elif defined(__BIG_ENDIAN)
182 m_len += (unsigned) __builtin_clzll(v) / 8;
183# else
184# error "missing endian definition"
185# endif
186#elif defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && defined(LZO_USE_CTZ32)
187 u32 v;
188 v = get_unaligned((const u32 *) (ip + m_len)) ^
189 get_unaligned((const u32 *) (m_pos + m_len));
190 if (unlikely(v == 0)) {
191 do {
192 m_len += 4;
193 v = get_unaligned((const u32 *) (ip + m_len)) ^
194 get_unaligned((const u32 *) (m_pos + m_len));
195 if (v != 0)
196 break;
197 m_len += 4;
198 v = get_unaligned((const u32 *) (ip + m_len)) ^
199 get_unaligned((const u32 *) (m_pos + m_len));
200 if (unlikely(ip + m_len >= ip_end))
201 goto m_len_done;
202 } while (v == 0);
203 }
204# if defined(__LITTLE_ENDIAN)
205 m_len += (unsigned) __builtin_ctz(v) / 8;
206# elif defined(__BIG_ENDIAN)
207 m_len += (unsigned) __builtin_clz(v) / 8;
208# else
209# error "missing endian definition"
210# endif
211#else
212 if (unlikely(ip[m_len] == m_pos[m_len])) {
213 do {
214 m_len += 1;
215 if (ip[m_len] != m_pos[m_len])
216 break;
217 m_len += 1;
218 if (ip[m_len] != m_pos[m_len])
219 break;
220 m_len += 1;
221 if (ip[m_len] != m_pos[m_len])
222 break;
223 m_len += 1;
224 if (ip[m_len] != m_pos[m_len])
225 break;
226 m_len += 1;
227 if (ip[m_len] != m_pos[m_len])
228 break;
229 m_len += 1;
230 if (ip[m_len] != m_pos[m_len])
231 break;
232 m_len += 1;
233 if (ip[m_len] != m_pos[m_len])
234 break;
235 m_len += 1;
236 if (unlikely(ip + m_len >= ip_end))
237 goto m_len_done;
238 } while (ip[m_len] == m_pos[m_len]);
239 }
240#endif
241 }
242m_len_done:
243
244 m_off = ip - m_pos;
245 ip += m_len;
246 if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET) {
247 m_off -= 1;
248 *op++ = (((m_len - 1) << 5) | ((m_off & 7) << 2));
249 *op++ = (m_off >> 3);
250 } else if (m_off <= M3_MAX_OFFSET) {
251 m_off -= 1;
252 if (m_len <= M3_MAX_LEN)
253 *op++ = (M3_MARKER | (m_len - 2));
254 else {
255 m_len -= M3_MAX_LEN;
256 *op++ = M3_MARKER | 0;
257 while (unlikely(m_len > 255)) {
258 m_len -= 255;
259 *op++ = 0;
260 }
261 *op++ = (m_len);
262 }
263 *op++ = (m_off << 2);
264 *op++ = (m_off >> 6);
265 } else {
266 m_off -= 0x4000;
267 if (m_len <= M4_MAX_LEN)
268 *op++ = (M4_MARKER | ((m_off >> 11) & 8)
269 | (m_len - 2));
270 else {
271 if (unlikely(((m_off & 0x403f) == 0x403f)
272 && (m_len >= 261)
273 && (m_len <= 264))
274 && likely(bitstream_version)) {
275 // Under lzo-rle, block copies
276 // for 261 <= length <= 264 and
277 // (distance & 0x80f3) == 0x80f3
278 // can result in ambiguous
279 // output. Adjust length
280 // to 260 to prevent ambiguity.
281 ip -= m_len - 260;
282 m_len = 260;
283 }
284 m_len -= M4_MAX_LEN;
285 *op++ = (M4_MARKER | ((m_off >> 11) & 8));
286 while (unlikely(m_len > 255)) {
287 m_len -= 255;
288 *op++ = 0;
289 }
290 *op++ = (m_len);
291 }
292 *op++ = (m_off << 2);
293 *op++ = (m_off >> 6);
294 }
295 *state_offset = -2;
296finished_writing_instruction:
297 ii = ip;
298 goto next;
299 }
300 *out_len = op - out;
301 return in_end - (ii - ti);
302}
303
304int lzogeneric1x_1_compress(const unsigned char *in, size_t in_len,
305 unsigned char *out, size_t *out_len,
306 void *wrkmem, const unsigned char bitstream_version)
307{
308 const unsigned char *ip = in;
309 unsigned char *op = out;
310 unsigned char *data_start;
311 size_t l = in_len;
312 size_t t = 0;
313 signed char state_offset = -2;
314 unsigned int m4_max_offset;
315
316 // LZO v0 will never write 17 as first byte (except for zero-length
317 // input), so this is used to version the bitstream
318 if (bitstream_version > 0) {
319 *op++ = 17;
320 *op++ = bitstream_version;
321 m4_max_offset = M4_MAX_OFFSET_V1;
322 } else {
323 m4_max_offset = M4_MAX_OFFSET_V0;
324 }
325
326 data_start = op;
327
328 while (l > 20) {
329 size_t ll = l <= (m4_max_offset + 1) ? l : (m4_max_offset + 1);
330 uintptr_t ll_end = (uintptr_t) ip + ll;
331 if ((ll_end + ((t + ll) >> 5)) <= ll_end)
332 break;
333 BUILD_BUG_ON(D_SIZE * sizeof(lzo_dict_t) > LZO1X_1_MEM_COMPRESS);
334 memset(wrkmem, 0, D_SIZE * sizeof(lzo_dict_t));
335 t = lzo1x_1_do_compress(ip, ll, op, out_len, t, wrkmem,
336 &state_offset, bitstream_version);
337 ip += ll;
338 op += *out_len;
339 l -= ll;
340 }
341 t += l;
342
343 if (t > 0) {
344 const unsigned char *ii = in + in_len - t;
345
346 if (op == data_start && t <= 238) {
347 *op++ = (17 + t);
348 } else if (t <= 3) {
349 op[state_offset] |= t;
350 } else if (t <= 18) {
351 *op++ = (t - 3);
352 } else {
353 size_t tt = t - 18;
354 *op++ = 0;
355 while (tt > 255) {
356 tt -= 255;
357 *op++ = 0;
358 }
359 *op++ = tt;
360 }
361 if (t >= 16) do {
362 COPY8(op, ii);
363 COPY8(op + 8, ii + 8);
364 op += 16;
365 ii += 16;
366 t -= 16;
367 } while (t >= 16);
368 if (t > 0) do {
369 *op++ = *ii++;
370 } while (--t > 0);
371 }
372
373 *op++ = M4_MARKER | 1;
374 *op++ = 0;
375 *op++ = 0;
376
377 *out_len = op - out;
378 return LZO_E_OK;
379}
380
381int lzo1x_1_compress(const unsigned char *in, size_t in_len,
382 unsigned char *out, size_t *out_len,
383 void *wrkmem)
384{
385 return lzogeneric1x_1_compress(in, in_len, out, out_len, wrkmem, 0);
386}
387
388int lzorle1x_1_compress(const unsigned char *in, size_t in_len,
389 unsigned char *out, size_t *out_len,
390 void *wrkmem)
391{
392 return lzogeneric1x_1_compress(in, in_len, out, out_len,
393 wrkmem, LZO_VERSION);
394}
395
396EXPORT_SYMBOL_GPL(lzo1x_1_compress);
397EXPORT_SYMBOL_GPL(lzorle1x_1_compress);
398
399MODULE_LICENSE("GPL");
400MODULE_DESCRIPTION("LZO1X-1 Compressor");
diff --git a/lib/lzo/lzo1x_decompress_safe.c b/lib/lzo/lzo1x_decompress_safe.c
new file mode 100644
index 000000000..7892a40cf
--- /dev/null
+++ b/lib/lzo/lzo1x_decompress_safe.c
@@ -0,0 +1,296 @@
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * LZO1X Decompressor from LZO
4 *
5 * Copyright (C) 1996-2012 Markus F.X.J. Oberhumer <markus@oberhumer.com>
6 *
7 * The full LZO package can be found at:
8 * http://www.oberhumer.com/opensource/lzo/
9 *
10 * Changed for Linux kernel use by:
11 * Nitin Gupta <nitingupta910@gmail.com>
12 * Richard Purdie <rpurdie@openedhand.com>
13 */
14
15#ifndef STATIC
16#include <linux/module.h>
17#include <linux/kernel.h>
18#endif
19#include <asm/unaligned.h>
20#include <linux/lzo.h>
21#include "lzodefs.h"
22
23#define HAVE_IP(x) ((size_t)(ip_end - ip) >= (size_t)(x))
24#define HAVE_OP(x) ((size_t)(op_end - op) >= (size_t)(x))
25#define NEED_IP(x) if (!HAVE_IP(x)) goto input_overrun
26#define NEED_OP(x) if (!HAVE_OP(x)) goto output_overrun
27#define TEST_LB(m_pos) if ((m_pos) < out) goto lookbehind_overrun
28
29/* This MAX_255_COUNT is the maximum number of times we can add 255 to a base
30 * count without overflowing an integer. The multiply will overflow when
31 * multiplying 255 by more than MAXINT/255. The sum will overflow earlier
32 * depending on the base count. Since the base count is taken from a u8
33 * and a few bits, it is safe to assume that it will always be lower than
34 * or equal to 2*255, thus we can always prevent any overflow by accepting
35 * two less 255 steps. See Documentation/staging/lzo.rst for more information.
36 */
37#define MAX_255_COUNT ((((size_t)~0) / 255) - 2)
38
39int lzo1x_decompress_safe(const unsigned char *in, size_t in_len,
40 unsigned char *out, size_t *out_len)
41{
42 unsigned char *op;
43 const unsigned char *ip;
44 size_t t, next;
45 size_t state = 0;
46 const unsigned char *m_pos;
47 const unsigned char * const ip_end = in + in_len;
48 unsigned char * const op_end = out + *out_len;
49
50 unsigned char bitstream_version;
51
52 op = out;
53 ip = in;
54
55 if (unlikely(in_len < 3))
56 goto input_overrun;
57
58 if (likely(in_len >= 5) && likely(*ip == 17)) {
59 bitstream_version = ip[1];
60 ip += 2;
61 } else {
62 bitstream_version = 0;
63 }
64
65 if (*ip > 17) {
66 t = *ip++ - 17;
67 if (t < 4) {
68 next = t;
69 goto match_next;
70 }
71 goto copy_literal_run;
72 }
73
74 for (;;) {
75 t = *ip++;
76 if (t < 16) {
77 if (likely(state == 0)) {
78 if (unlikely(t == 0)) {
79 size_t offset;
80 const unsigned char *ip_last = ip;
81
82 while (unlikely(*ip == 0)) {
83 ip++;
84 NEED_IP(1);
85 }
86 offset = ip - ip_last;
87 if (unlikely(offset > MAX_255_COUNT))
88 return LZO_E_ERROR;
89
90 offset = (offset << 8) - offset;
91 t += offset + 15 + *ip++;
92 }
93 t += 3;
94copy_literal_run:
95#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
96 if (likely(HAVE_IP(t + 15) && HAVE_OP(t + 15))) {
97 const unsigned char *ie = ip + t;
98 unsigned char *oe = op + t;
99 do {
100 COPY8(op, ip);
101 op += 8;
102 ip += 8;
103 COPY8(op, ip);
104 op += 8;
105 ip += 8;
106 } while (ip < ie);
107 ip = ie;
108 op = oe;
109 } else
110#endif
111 {
112 NEED_OP(t);
113 NEED_IP(t + 3);
114 do {
115 *op++ = *ip++;
116 } while (--t > 0);
117 }
118 state = 4;
119 continue;
120 } else if (state != 4) {
121 next = t & 3;
122 m_pos = op - 1;
123 m_pos -= t >> 2;
124 m_pos -= *ip++ << 2;
125 TEST_LB(m_pos);
126 NEED_OP(2);
127 op[0] = m_pos[0];
128 op[1] = m_pos[1];
129 op += 2;
130 goto match_next;
131 } else {
132 next = t & 3;
133 m_pos = op - (1 + M2_MAX_OFFSET);
134 m_pos -= t >> 2;
135 m_pos -= *ip++ << 2;
136 t = 3;
137 }
138 } else if (t >= 64) {
139 next = t & 3;
140 m_pos = op - 1;
141 m_pos -= (t >> 2) & 7;
142 m_pos -= *ip++ << 3;
143 t = (t >> 5) - 1 + (3 - 1);
144 } else if (t >= 32) {
145 t = (t & 31) + (3 - 1);
146 if (unlikely(t == 2)) {
147 size_t offset;
148 const unsigned char *ip_last = ip;
149
150 while (unlikely(*ip == 0)) {
151 ip++;
152 NEED_IP(1);
153 }
154 offset = ip - ip_last;
155 if (unlikely(offset > MAX_255_COUNT))
156 return LZO_E_ERROR;
157
158 offset = (offset << 8) - offset;
159 t += offset + 31 + *ip++;
160 NEED_IP(2);
161 }
162 m_pos = op - 1;
163 next = get_unaligned_le16(ip);
164 ip += 2;
165 m_pos -= next >> 2;
166 next &= 3;
167 } else {
168 NEED_IP(2);
169 next = get_unaligned_le16(ip);
170 if (((next & 0xfffc) == 0xfffc) &&
171 ((t & 0xf8) == 0x18) &&
172 likely(bitstream_version)) {
173 NEED_IP(3);
174 t &= 7;
175 t |= ip[2] << 3;
176 t += MIN_ZERO_RUN_LENGTH;
177 NEED_OP(t);
178 memset(op, 0, t);
179 op += t;
180 next &= 3;
181 ip += 3;
182 goto match_next;
183 } else {
184 m_pos = op;
185 m_pos -= (t & 8) << 11;
186 t = (t & 7) + (3 - 1);
187 if (unlikely(t == 2)) {
188 size_t offset;
189 const unsigned char *ip_last = ip;
190
191 while (unlikely(*ip == 0)) {
192 ip++;
193 NEED_IP(1);
194 }
195 offset = ip - ip_last;
196 if (unlikely(offset > MAX_255_COUNT))
197 return LZO_E_ERROR;
198
199 offset = (offset << 8) - offset;
200 t += offset + 7 + *ip++;
201 NEED_IP(2);
202 next = get_unaligned_le16(ip);
203 }
204 ip += 2;
205 m_pos -= next >> 2;
206 next &= 3;
207 if (m_pos == op)
208 goto eof_found;
209 m_pos -= 0x4000;
210 }
211 }
212 TEST_LB(m_pos);
213#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
214 if (op - m_pos >= 8) {
215 unsigned char *oe = op + t;
216 if (likely(HAVE_OP(t + 15))) {
217 do {
218 COPY8(op, m_pos);
219 op += 8;
220 m_pos += 8;
221 COPY8(op, m_pos);
222 op += 8;
223 m_pos += 8;
224 } while (op < oe);
225 op = oe;
226 if (HAVE_IP(6)) {
227 state = next;
228 COPY4(op, ip);
229 op += next;
230 ip += next;
231 continue;
232 }
233 } else {
234 NEED_OP(t);
235 do {
236 *op++ = *m_pos++;
237 } while (op < oe);
238 }
239 } else
240#endif
241 {
242 unsigned char *oe = op + t;
243 NEED_OP(t);
244 op[0] = m_pos[0];
245 op[1] = m_pos[1];
246 op += 2;
247 m_pos += 2;
248 do {
249 *op++ = *m_pos++;
250 } while (op < oe);
251 }
252match_next:
253 state = next;
254 t = next;
255#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
256 if (likely(HAVE_IP(6) && HAVE_OP(4))) {
257 COPY4(op, ip);
258 op += t;
259 ip += t;
260 } else
261#endif
262 {
263 NEED_IP(t + 3);
264 NEED_OP(t);
265 while (t > 0) {
266 *op++ = *ip++;
267 t--;
268 }
269 }
270 }
271
272eof_found:
273 *out_len = op - out;
274 return (t != 3 ? LZO_E_ERROR :
275 ip == ip_end ? LZO_E_OK :
276 ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN);
277
278input_overrun:
279 *out_len = op - out;
280 return LZO_E_INPUT_OVERRUN;
281
282output_overrun:
283 *out_len = op - out;
284 return LZO_E_OUTPUT_OVERRUN;
285
286lookbehind_overrun:
287 *out_len = op - out;
288 return LZO_E_LOOKBEHIND_OVERRUN;
289}
290#ifndef STATIC
291EXPORT_SYMBOL_GPL(lzo1x_decompress_safe);
292
293MODULE_LICENSE("GPL");
294MODULE_DESCRIPTION("LZO1X Decompressor");
295
296#endif
diff --git a/lib/lzo/lzodefs.h b/lib/lzo/lzodefs.h
new file mode 100644
index 000000000..b60851fcf
--- /dev/null
+++ b/lib/lzo/lzodefs.h
@@ -0,0 +1,71 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * lzodefs.h -- architecture, OS and compiler specific defines
4 *
5 * Copyright (C) 1996-2012 Markus F.X.J. Oberhumer <markus@oberhumer.com>
6 *
7 * The full LZO package can be found at:
8 * http://www.oberhumer.com/opensource/lzo/
9 *
10 * Changed for Linux kernel use by:
11 * Nitin Gupta <nitingupta910@gmail.com>
12 * Richard Purdie <rpurdie@openedhand.com>
13 */
14
15
16/* Version
17 * 0: original lzo version
18 * 1: lzo with support for RLE
19 */
20#define LZO_VERSION 1
21
22#define COPY4(dst, src) \
23 put_unaligned(get_unaligned((const u32 *)(src)), (u32 *)(dst))
24#if defined(CONFIG_X86_64) || defined(CONFIG_ARM64)
25#define COPY8(dst, src) \
26 put_unaligned(get_unaligned((const u64 *)(src)), (u64 *)(dst))
27#else
28#define COPY8(dst, src) \
29 COPY4(dst, src); COPY4((dst) + 4, (src) + 4)
30#endif
31
32#if defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN)
33#error "conflicting endian definitions"
34#elif defined(CONFIG_X86_64) || defined(CONFIG_ARM64)
35#define LZO_USE_CTZ64 1
36#define LZO_USE_CTZ32 1
37#define LZO_FAST_64BIT_MEMORY_ACCESS
38#elif defined(CONFIG_X86) || defined(CONFIG_PPC)
39#define LZO_USE_CTZ32 1
40#elif defined(CONFIG_ARM) && (__LINUX_ARM_ARCH__ >= 5)
41#define LZO_USE_CTZ32 1
42#endif
43
44#define M1_MAX_OFFSET 0x0400
45#define M2_MAX_OFFSET 0x0800
46#define M3_MAX_OFFSET 0x4000
47#define M4_MAX_OFFSET_V0 0xbfff
48#define M4_MAX_OFFSET_V1 0xbffe
49
50#define M1_MIN_LEN 2
51#define M1_MAX_LEN 2
52#define M2_MIN_LEN 3
53#define M2_MAX_LEN 8
54#define M3_MIN_LEN 3
55#define M3_MAX_LEN 33
56#define M4_MIN_LEN 3
57#define M4_MAX_LEN 9
58
59#define M1_MARKER 0
60#define M2_MARKER 64
61#define M3_MARKER 32
62#define M4_MARKER 16
63
64#define MIN_ZERO_RUN_LENGTH 4
65#define MAX_ZERO_RUN_LENGTH (2047 + MIN_ZERO_RUN_LENGTH)
66
67#define lzo_dict_t unsigned short
68#define D_BITS 13
69#define D_SIZE (1u << D_BITS)
70#define D_MASK (D_SIZE - 1)
71#define D_HIGH ((D_MASK >> 1) + 1)