4 KERNEL_BUILD_PATH ?= "/lib/modules/$(shell uname -r)/build"
6 XVM = sub-projects/allocators/xvmalloc-kmod
7 +LZO = sub-projects/compression/lzo-kmod
8 EXTRA_CFLAGS := -DCONFIG_RAMZSWAP_STATS \
12 +obj-m += ramzswap.o $(LZO)/lzo1x.o
13 ramzswap-objs := ramzswap_drv.o $(XVM)/xvmalloc.o
17 make -C $(KERNEL_BUILD_PATH) M=$(PWD) modules
18 + make -C $(KERNEL_BUILD_PATH) M=$(PWD)/$(LZO) modules
19 make -C sub-projects/rzscontrol
22 @@ -16,5 +19,6 @@ doc:
25 make -C $(KERNEL_BUILD_PATH) M=$(PWD) clean
26 + make -C $(KERNEL_BUILD_PATH) M=$(PWD)/$(LZO) clean
27 make -C sub-projects/rzscontrol clean
32 #include <linux/device.h>
33 #include <linux/genhd.h>
34 #include <linux/highmem.h>
35 -#include <linux/lzo.h>
36 #include <linux/string.h>
37 #include <linux/swap.h>
38 #include <linux/swapops.h>
39 #include <linux/vmalloc.h>
40 #include <linux/version.h>
44 #include "ramzswap_drv.h"
47 +++ b/sub-projects/compression/lzo-kmod/lzo1x.c
49 +#include <linux/module.h>
51 +#include "lzo1x_compress.c"
52 +#include "lzo1x_decompress.c"
54 +MODULE_LICENSE("GPL");
55 +MODULE_DESCRIPTION("LZO1X Lib");
57 +++ b/sub-projects/compression/lzo-kmod/lzo1x_compress.c
60 + * LZO1X Compressor from MiniLZO
62 + * Copyright (C) 1996-2005 Markus F.X.J. Oberhumer <markus@oberhumer.com>
64 + * The full LZO package can be found at:
65 + * http://www.oberhumer.com/opensource/lzo/
67 + * Changed for kernel use by:
68 + * Nitin Gupta <nitingupta910@gmail.com>
69 + * Richard Purdie <rpurdie@openedhand.com>
72 +#include <linux/module.h>
73 +#include <linux/kernel.h>
74 +#include <asm/unaligned.h>
79 +static noinline size_t
80 +_lzo1x_1_do_compress(const unsigned char *in, size_t in_len,
81 + unsigned char *out, size_t *out_len, void *wrkmem)
83 + const unsigned char * const in_end = in + in_len;
84 + const unsigned char * const ip_end = in + in_len - M2_MAX_LEN - 5;
85 + const unsigned char ** const dict = wrkmem;
86 + const unsigned char *ip = in, *ii = ip;
87 + const unsigned char *end, *m, *m_pos;
88 + size_t m_off, m_len, dindex;
89 + unsigned char *op = out;
94 + dindex = ((size_t)(0x21 * DX3(ip, 5, 5, 6)) >> 5) & D_MASK;
95 + m_pos = dict[dindex];
100 + if (ip == m_pos || ((size_t)(ip - m_pos) > M4_MAX_OFFSET))
103 + m_off = ip - m_pos;
104 + if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
107 + dindex = (dindex & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f);
108 + m_pos = dict[dindex];
113 + if (ip == m_pos || ((size_t)(ip - m_pos) > M4_MAX_OFFSET))
116 + m_off = ip - m_pos;
117 + if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
123 + if (get_unaligned((const unsigned short *)m_pos)
124 + == get_unaligned((const unsigned short *)ip)) {
125 + if (likely(m_pos[2] == ip[2]))
132 + if (unlikely(ip >= ip_end))
139 + size_t t = ip - ii;
143 + } else if (t <= 18) {
146 + size_t tt = t - 18;
161 + if (m_pos[3] != *ip++ || m_pos[4] != *ip++
162 + || m_pos[5] != *ip++ || m_pos[6] != *ip++
163 + || m_pos[7] != *ip++ || m_pos[8] != *ip++) {
167 + if (m_off <= M2_MAX_OFFSET) {
169 + *op++ = (((m_len - 1) << 5)
170 + | ((m_off & 7) << 2));
171 + *op++ = (m_off >> 3);
172 + } else if (m_off <= M3_MAX_OFFSET) {
174 + *op++ = (M3_MARKER | (m_len - 2));
179 + *op++ = (M4_MARKER | ((m_off & 0x4000) >> 11)
185 + m = m_pos + M2_MAX_LEN + 1;
187 + while (ip < end && *m == *ip) {
193 + if (m_off <= M3_MAX_OFFSET) {
196 + *op++ = (M3_MARKER | (m_len - 2));
199 + *op++ = M3_MARKER | 0;
204 + if (m_len <= M4_MAX_LEN) {
206 + | ((m_off & 0x4000) >> 11)
209 + m_len -= M4_MAX_LEN;
211 + | ((m_off & 0x4000) >> 11));
213 + while (m_len > 255) {
222 + *op++ = ((m_off & 63) << 2);
223 + *op++ = (m_off >> 6);
227 + if (unlikely(ip >= ip_end))
231 + *out_len = op - out;
232 + return in_end - ii;
235 +int lzo1x_1_compress(const unsigned char *in, size_t in_len, unsigned char *out,
236 + size_t *out_len, void *wrkmem)
238 + const unsigned char *ii;
239 + unsigned char *op = out;
242 + if (unlikely(in_len <= M2_MAX_LEN + 5)) {
245 + t = _lzo1x_1_do_compress(in, in_len, op, out_len, wrkmem);
250 + ii = in + in_len - t;
252 + if (op == out && t <= 238) {
254 + } else if (t <= 3) {
256 + } else if (t <= 18) {
259 + size_t tt = t - 18;
274 + *op++ = M4_MARKER | 1;
278 + *out_len = op - out;
281 +EXPORT_SYMBOL_GPL(lzo1x_1_compress);
283 +MODULE_LICENSE("GPL");
284 +MODULE_DESCRIPTION("LZO1X-1 Compressor");
287 +++ b/sub-projects/compression/lzo-kmod/lzo1x_decompress.c
290 + * LZO1X Decompressor from MiniLZO
292 + * Copyright (C) 1996-2005 Markus F.X.J. Oberhumer <markus@oberhumer.com>
294 + * The full LZO package can be found at:
295 + * http://www.oberhumer.com/opensource/lzo/
297 + * Changed for kernel use by:
298 + * Nitin Gupta <nitingupta910@gmail.com>
299 + * Richard Purdie <rpurdie@openedhand.com>
302 +#include <linux/module.h>
303 +#include <linux/kernel.h>
304 +#include <asm/byteorder.h>
305 +#include <asm/unaligned.h>
307 +#include "lzodefs.h"
310 +#define HAVE_IP(x, ip_end, ip) ((size_t)(ip_end - ip) < (x))
311 +#define HAVE_OP(x, op_end, op) ((size_t)(op_end - op) < (x))
312 +#define HAVE_LB(m_pos, out, op) (m_pos < out || m_pos >= op)
314 +#define COPY4(dst, src) \
315 + put_unaligned(get_unaligned((const u32 *)(src)), (u32 *)(dst))
317 +int lzo1x_decompress_safe(const unsigned char *in, size_t in_len,
318 + unsigned char *out, size_t *out_len)
320 + const unsigned char * const ip_end = in + in_len;
321 + unsigned char * const op_end = out + *out_len;
322 + const unsigned char *ip = in, *m_pos;
323 + unsigned char *op = out;
332 + if (HAVE_OP(t, op_end, op))
333 + goto output_overrun;
334 + if (HAVE_IP(t + 1, ip_end, ip))
335 + goto input_overrun;
339 + goto first_literal_run;
342 + while ((ip < ip_end)) {
347 + if (HAVE_IP(1, ip_end, ip))
348 + goto input_overrun;
352 + if (HAVE_IP(1, ip_end, ip))
353 + goto input_overrun;
357 + if (HAVE_OP(t + 3, op_end, op))
358 + goto output_overrun;
359 + if (HAVE_IP(t + 4, ip_end, ip))
360 + goto input_overrun;
389 + m_pos = op - (1 + M2_MAX_OFFSET);
391 + m_pos -= *ip++ << 2;
393 + if (HAVE_LB(m_pos, out, op))
394 + goto lookbehind_overrun;
396 + if (HAVE_OP(3, op_end, op))
397 + goto output_overrun;
408 + m_pos -= (t >> 2) & 7;
409 + m_pos -= *ip++ << 3;
411 + if (HAVE_LB(m_pos, out, op))
412 + goto lookbehind_overrun;
413 + if (HAVE_OP(t + 3 - 1, op_end, op))
414 + goto output_overrun;
416 + } else if (t >= 32) {
419 + if (HAVE_IP(1, ip_end, ip))
420 + goto input_overrun;
424 + if (HAVE_IP(1, ip_end, ip))
425 + goto input_overrun;
430 + m_pos -= le16_to_cpu(get_unaligned(
431 + (const unsigned short *)ip)) >> 2;
433 + } else if (t >= 16) {
435 + m_pos -= (t & 8) << 11;
439 + if (HAVE_IP(1, ip_end, ip))
440 + goto input_overrun;
444 + if (HAVE_IP(1, ip_end, ip))
445 + goto input_overrun;
449 + m_pos -= le16_to_cpu(get_unaligned(
450 + (const unsigned short *)ip)) >> 2;
458 + m_pos -= *ip++ << 2;
460 + if (HAVE_LB(m_pos, out, op))
461 + goto lookbehind_overrun;
462 + if (HAVE_OP(2, op_end, op))
463 + goto output_overrun;
470 + if (HAVE_LB(m_pos, out, op))
471 + goto lookbehind_overrun;
472 + if (HAVE_OP(t + 3 - 1, op_end, op))
473 + goto output_overrun;
475 + if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) {
503 + if (HAVE_OP(t, op_end, op))
504 + goto output_overrun;
505 + if (HAVE_IP(t + 1, ip_end, ip))
506 + goto input_overrun;
516 + } while (ip < ip_end);
519 + *out_len = op - out;
520 + return LZO_E_EOF_NOT_FOUND;
523 + *out_len = op - out;
524 + return (ip == ip_end ? LZO_E_OK :
525 + (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
527 + *out_len = op - out;
528 + return LZO_E_INPUT_OVERRUN;
531 + *out_len = op - out;
532 + return LZO_E_OUTPUT_OVERRUN;
535 + *out_len = op - out;
536 + return LZO_E_LOOKBEHIND_OVERRUN;
539 +EXPORT_SYMBOL_GPL(lzo1x_decompress_safe);
541 +MODULE_LICENSE("GPL");
542 +MODULE_DESCRIPTION("LZO1X Decompressor");
545 +++ b/sub-projects/compression/lzo-kmod/lzodefs.h
548 + * lzodefs.h -- architecture, OS and compiler specific defines
550 + * Copyright (C) 1996-2005 Markus F.X.J. Oberhumer <markus@oberhumer.com>
552 + * The full LZO package can be found at:
553 + * http://www.oberhumer.com/opensource/lzo/
555 + * Changed for kernel use by:
556 + * Nitin Gupta <nitingupta910@gmail.com>
557 + * Richard Purdie <rpurdie@openedhand.com>
560 +#define LZO_VERSION 0x2020
561 +#define LZO_VERSION_STRING "2.02"
562 +#define LZO_VERSION_DATE "Oct 17 2005"
564 +#define M1_MAX_OFFSET 0x0400
565 +#define M2_MAX_OFFSET 0x0800
566 +#define M3_MAX_OFFSET 0x4000
567 +#define M4_MAX_OFFSET 0xbfff
569 +#define M1_MIN_LEN 2
570 +#define M1_MAX_LEN 2
571 +#define M2_MIN_LEN 3
572 +#define M2_MAX_LEN 8
573 +#define M3_MIN_LEN 3
574 +#define M3_MAX_LEN 33
575 +#define M4_MIN_LEN 3
576 +#define M4_MAX_LEN 9
579 +#define M2_MARKER 64
580 +#define M3_MARKER 32
581 +#define M4_MARKER 16
584 +#define D_MASK ((1u << D_BITS) - 1)
585 +#define D_HIGH ((D_MASK >> 1) + 1)
587 +#define DX2(p, s1, s2) (((((size_t)((p)[2]) << (s2)) ^ (p)[1]) \
589 +#define DX3(p, s1, s2, s3) ((DX2((p)+1, s2, s3) << (s1)) ^ (p)[0])
591 +++ b/sub-projects/compression/lzo-kmod/lzo.h
596 + * LZO Public Kernel Interface
597 + * A mini subset of the LZO real-time data compression library
599 + * Copyright (C) 1996-2005 Markus F.X.J. Oberhumer <markus@oberhumer.com>
601 + * The full LZO package can be found at:
602 + * http://www.oberhumer.com/opensource/lzo/
604 + * Changed for kernel use by:
605 + * Nitin Gupta <nitingupta910@gmail.com>
606 + * Richard Purdie <rpurdie@openedhand.com>
609 +#define LZO1X_MEM_COMPRESS (16384 * sizeof(unsigned char *))
610 +#define LZO1X_1_MEM_COMPRESS LZO1X_MEM_COMPRESS
612 +#define lzo1x_worst_compress(x) ((x) + ((x) / 16) + 64 + 3)
614 +/* This requires 'workmem' of size LZO1X_1_MEM_COMPRESS */
615 +int lzo1x_1_compress(const unsigned char *src, size_t src_len,
616 + unsigned char *dst, size_t *dst_len, void *wrkmem);
618 +/* safe decompression with overrun testing */
619 +int lzo1x_decompress_safe(const unsigned char *src, size_t src_len,
620 + unsigned char *dst, size_t *dst_len);
623 + * Return values (< 0 = Error)
626 +#define LZO_E_ERROR (-1)
627 +#define LZO_E_OUT_OF_MEMORY (-2)
628 +#define LZO_E_NOT_COMPRESSIBLE (-3)
629 +#define LZO_E_INPUT_OVERRUN (-4)
630 +#define LZO_E_OUTPUT_OVERRUN (-5)
631 +#define LZO_E_LOOKBEHIND_OVERRUN (-6)
632 +#define LZO_E_EOF_NOT_FOUND (-7)
633 +#define LZO_E_INPUT_NOT_CONSUMED (-8)
634 +#define LZO_E_NOT_YET_IMPLEMENTED (-9)
638 +++ b/sub-projects/compression/lzo-kmod/Makefile
640 +obj-m += lzo1x_compress.o lzo1x_decompress.o
643 + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
646 + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean