1 --- linux-2.6.19.old/lib/Makefile 2007-04-18 17:41:22.679403384 +0200
2 +++ linux-2.6.19.dev/lib/Makefile 2007-04-18 17:41:43.303268080 +0200
4 obj-$(CONFIG_AUDIT_GENERIC) += audit.o
6 obj-$(CONFIG_SWIOTLB) += swiotlb.o
9 hostprogs-y := gen_crc32table
10 clean-files := crc32table.h
11 --- linux-2.6.19.old/lib/LzmaDecode.c 1970-01-01 01:00:00.000000000 +0100
12 +++ linux-2.6.19.dev/lib/LzmaDecode.c 2006-12-14 03:13:20.000000000 +0100
18 + LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25)
19 + http://www.7-zip.org/
21 + LZMA SDK is licensed under two licenses:
22 + 1) GNU Lesser General Public License (GNU LGPL)
23 + 2) Common Public License (CPL)
24 + It means that you can select one of these two licenses and
25 + follow rules of that license.
28 + Igor Pavlov, as the author of this code, expressly permits you to
29 + statically or dynamically link your code (or bind by name) to the
30 + interfaces of this file without subjecting your linked code to the
31 + terms of the CPL or GNU LGPL. Any modifications or additions
32 + to this file, however, are subject to the LGPL or CPL terms.
35 +#include <linux/LzmaDecode.h>
38 +#define Byte unsigned char
41 +#define kNumTopBits 24
42 +#define kTopValue ((UInt32)1 << kNumTopBits)
44 +#define kNumBitModelTotalBits 11
45 +#define kBitModelTotal (1 << kNumBitModelTotalBits)
46 +#define kNumMoveBits 5
48 +typedef struct _CRangeDecoder
55 + ILzmaInCallback *InCallback;
61 +Byte RangeDecoderReadByte(CRangeDecoder *rd)
63 + if (rd->Buffer == rd->BufferLim)
67 + rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size);
68 + rd->BufferLim = rd->Buffer + size;
76 + return (*rd->Buffer++);
79 +/* #define ReadByte (*rd->Buffer++) */
80 +#define ReadByte (RangeDecoderReadByte(rd))
82 +void RangeDecoderInit(CRangeDecoder *rd,
84 + ILzmaInCallback *inCallback
86 + Byte *stream, UInt32 bufferSize
92 + rd->InCallback = inCallback;
93 + rd->Buffer = rd->BufferLim = 0;
95 + rd->Buffer = stream;
96 + rd->BufferLim = stream + bufferSize;
100 + rd->Range = (0xFFFFFFFF);
101 + for(i = 0; i < 5; i++)
102 + rd->Code = (rd->Code << 8) | ReadByte;
105 +#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code;
106 +#define RC_FLUSH_VAR rd->Range = range; rd->Code = code;
107 +#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; }
109 +UInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits)
114 + for (i = numTotalBits; i > 0; i--)
126 + t = (code - range) >> 31;
128 + code -= range & (t - 1);
129 + result = (result + result) | (1 - t);
137 +int RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd)
139 + UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob;
140 + if (rd->Code < bound)
143 + *prob += (kBitModelTotal - *prob) >> kNumMoveBits;
144 + if (rd->Range < kTopValue)
146 + rd->Code = (rd->Code << 8) | ReadByte;
153 + rd->Range -= bound;
155 + *prob -= (*prob) >> kNumMoveBits;
156 + if (rd->Range < kTopValue)
158 + rd->Code = (rd->Code << 8) | ReadByte;
165 +#define RC_GET_BIT2(prob, mi, A0, A1) \
166 + UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \
167 + if (code < bound) \
168 + { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \
170 + { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \
173 +#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;)
175 +int RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)
179 + #ifdef _LZMA_LOC_OPT
182 + for(i = numLevels; i > 0; i--)
184 + #ifdef _LZMA_LOC_OPT
185 + CProb *prob = probs + mi;
186 + RC_GET_BIT(prob, mi)
188 + mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd);
191 + #ifdef _LZMA_LOC_OPT
194 + return mi - (1 << numLevels);
197 +int RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)
202 + #ifdef _LZMA_LOC_OPT
205 + for(i = 0; i < numLevels; i++)
207 + #ifdef _LZMA_LOC_OPT
208 + CProb *prob = probs + mi;
209 + RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i))
211 + int bit = RangeDecoderBitDecode(probs + mi, rd);
212 + mi = mi + mi + bit;
213 + symbol |= (bit << i);
216 + #ifdef _LZMA_LOC_OPT
222 +Byte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd)
225 + #ifdef _LZMA_LOC_OPT
230 + #ifdef _LZMA_LOC_OPT
231 + CProb *prob = probs + symbol;
232 + RC_GET_BIT(prob, symbol)
234 + symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);
237 + while (symbol < 0x100);
238 + #ifdef _LZMA_LOC_OPT
244 +Byte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte)
247 + #ifdef _LZMA_LOC_OPT
253 + int matchBit = (matchByte >> 7) & 1;
255 + #ifdef _LZMA_LOC_OPT
257 + CProb *prob = probs + ((1 + matchBit) << 8) + symbol;
258 + RC_GET_BIT2(prob, symbol, bit = 0, bit = 1)
261 + bit = RangeDecoderBitDecode(probs + ((1 + matchBit) << 8) + symbol, rd);
262 + symbol = (symbol << 1) | bit;
264 + if (matchBit != bit)
266 + while (symbol < 0x100)
268 + #ifdef _LZMA_LOC_OPT
269 + CProb *prob = probs + symbol;
270 + RC_GET_BIT(prob, symbol)
272 + symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);
278 + while (symbol < 0x100);
279 + #ifdef _LZMA_LOC_OPT
285 +#define kNumPosBitsMax 4
286 +#define kNumPosStatesMax (1 << kNumPosBitsMax)
288 +#define kLenNumLowBits 3
289 +#define kLenNumLowSymbols (1 << kLenNumLowBits)
290 +#define kLenNumMidBits 3
291 +#define kLenNumMidSymbols (1 << kLenNumMidBits)
292 +#define kLenNumHighBits 8
293 +#define kLenNumHighSymbols (1 << kLenNumHighBits)
296 +#define LenChoice2 (LenChoice + 1)
297 +#define LenLow (LenChoice2 + 1)
298 +#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
299 +#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
300 +#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
302 +int LzmaLenDecode(CProb *p, CRangeDecoder *rd, int posState)
304 + if(RangeDecoderBitDecode(p + LenChoice, rd) == 0)
305 + return RangeDecoderBitTreeDecode(p + LenLow +
306 + (posState << kLenNumLowBits), kLenNumLowBits, rd);
307 + if(RangeDecoderBitDecode(p + LenChoice2, rd) == 0)
308 + return kLenNumLowSymbols + RangeDecoderBitTreeDecode(p + LenMid +
309 + (posState << kLenNumMidBits), kLenNumMidBits, rd);
310 + return kLenNumLowSymbols + kLenNumMidSymbols +
311 + RangeDecoderBitTreeDecode(p + LenHigh, kLenNumHighBits, rd);
314 +#define kNumStates 12
316 +#define kStartPosModelIndex 4
317 +#define kEndPosModelIndex 14
318 +#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
320 +#define kNumPosSlotBits 6
321 +#define kNumLenToPosStates 4
323 +#define kNumAlignBits 4
324 +#define kAlignTableSize (1 << kNumAlignBits)
326 +#define kMatchMinLen 2
329 +#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
330 +#define IsRepG0 (IsRep + kNumStates)
331 +#define IsRepG1 (IsRepG0 + kNumStates)
332 +#define IsRepG2 (IsRepG1 + kNumStates)
333 +#define IsRep0Long (IsRepG2 + kNumStates)
334 +#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
335 +#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
336 +#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
337 +#define LenCoder (Align + kAlignTableSize)
338 +#define RepLenCoder (LenCoder + kNumLenProbs)
339 +#define Literal (RepLenCoder + kNumLenProbs)
341 +#if Literal != LZMA_BASE_SIZE
345 +#ifdef _LZMA_OUT_READ
347 +typedef struct _LzmaVarState
349 + CRangeDecoder RangeDecoder;
351 + UInt32 DictionarySize;
352 + UInt32 DictionaryPos;
359 + int PreviousIsMatch;
363 +int LzmaDecoderInit(
364 + unsigned char *buffer, UInt32 bufferSize,
365 + int lc, int lp, int pb,
366 + unsigned char *dictionary, UInt32 dictionarySize,
368 + ILzmaInCallback *inCallback
370 + unsigned char *inStream, UInt32 inSize
374 + LzmaVarState *vs = (LzmaVarState *)buffer;
375 + CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
376 + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
378 + if (bufferSize < numProbs * sizeof(CProb) + sizeof(LzmaVarState))
379 + return LZMA_RESULT_NOT_ENOUGH_MEM;
380 + vs->Dictionary = dictionary;
381 + vs->DictionarySize = dictionarySize;
382 + vs->DictionaryPos = 0;
384 + vs->Reps[0] = vs->Reps[1] = vs->Reps[2] = vs->Reps[3] = 1;
389 + vs->PreviousIsMatch = 0;
391 + dictionary[dictionarySize - 1] = 0;
392 + for (i = 0; i < numProbs; i++)
393 + p[i] = kBitModelTotal >> 1;
394 + RangeDecoderInit(&vs->RangeDecoder,
401 + return LZMA_RESULT_OK;
404 +int LzmaDecode(unsigned char *buffer,
405 + unsigned char *outStream, UInt32 outSize,
406 + UInt32 *outSizeProcessed)
408 + LzmaVarState *vs = (LzmaVarState *)buffer;
409 + CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
410 + CRangeDecoder rd = vs->RangeDecoder;
411 + int state = vs->State;
412 + int previousIsMatch = vs->PreviousIsMatch;
414 + UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];
416 + UInt32 posStateMask = (1 << (vs->pb)) - 1;
417 + UInt32 literalPosMask = (1 << (vs->lp)) - 1;
419 + int len = vs->RemainLen;
420 + UInt32 globalPos = vs->GlobalPos;
422 + Byte *dictionary = vs->Dictionary;
423 + UInt32 dictionarySize = vs->DictionarySize;
424 + UInt32 dictionaryPos = vs->DictionaryPos;
428 + *outSizeProcessed = 0;
429 + return LZMA_RESULT_OK;
432 + while(len > 0 && nowPos < outSize)
434 + UInt32 pos = dictionaryPos - rep0;
435 + if (pos >= dictionarySize)
436 + pos += dictionarySize;
437 + outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];
438 + if (++dictionaryPos == dictionarySize)
442 + if (dictionaryPos == 0)
443 + previousByte = dictionary[dictionarySize - 1];
445 + previousByte = dictionary[dictionaryPos - 1];
449 + Byte *buffer, UInt32 bufferSize,
450 + int lc, int lp, int pb,
452 + ILzmaInCallback *inCallback,
454 + unsigned char *inStream, UInt32 inSize,
456 + unsigned char *outStream, UInt32 outSize,
457 + UInt32 *outSizeProcessed)
459 + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
460 + CProb *p = (CProb *)buffer;
464 + int previousIsMatch = 0;
465 + Byte previousByte = 0;
466 + UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
468 + UInt32 posStateMask = (1 << pb) - 1;
469 + UInt32 literalPosMask = (1 << lp) - 1;
471 + if (bufferSize < numProbs * sizeof(CProb))
472 + return LZMA_RESULT_NOT_ENOUGH_MEM;
473 + for (i = 0; i < numProbs; i++)
474 + p[i] = kBitModelTotal >> 1;
475 + RangeDecoderInit(&rd,
484 + *outSizeProcessed = 0;
485 + while(nowPos < outSize)
487 + int posState = (int)(
489 + #ifdef _LZMA_OUT_READ
495 + if (rd.Result != LZMA_RESULT_OK)
498 + if (rd.ExtraBytes != 0)
499 + return LZMA_RESULT_DATA_ERROR;
500 + if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0)
502 + CProb *probs = p + Literal + (LZMA_LIT_SIZE *
505 + #ifdef _LZMA_OUT_READ
509 + & literalPosMask) << lc) + (previousByte >> (8 - lc))));
511 + if (state < 4) state = 0;
512 + else if (state < 10) state -= 3;
514 + if (previousIsMatch)
517 + #ifdef _LZMA_OUT_READ
518 + UInt32 pos = dictionaryPos - rep0;
519 + if (pos >= dictionarySize)
520 + pos += dictionarySize;
521 + matchByte = dictionary[pos];
523 + matchByte = outStream[nowPos - rep0];
525 + previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte);
526 + previousIsMatch = 0;
529 + previousByte = LzmaLiteralDecode(probs, &rd);
530 + outStream[nowPos++] = previousByte;
531 + #ifdef _LZMA_OUT_READ
532 + dictionary[dictionaryPos] = previousByte;
533 + if (++dictionaryPos == dictionarySize)
539 + previousIsMatch = 1;
540 + if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1)
542 + if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0)
544 + if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0)
546 + #ifdef _LZMA_OUT_READ
551 + #ifdef _LZMA_OUT_READ
556 + return LZMA_RESULT_DATA_ERROR;
557 + state = state < 7 ? 9 : 11;
558 + #ifdef _LZMA_OUT_READ
559 + pos = dictionaryPos - rep0;
560 + if (pos >= dictionarySize)
561 + pos += dictionarySize;
562 + previousByte = dictionary[pos];
563 + dictionary[dictionaryPos] = previousByte;
564 + if (++dictionaryPos == dictionarySize)
567 + previousByte = outStream[nowPos - rep0];
569 + outStream[nowPos++] = previousByte;
576 + if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0)
580 + if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0)
592 + len = LzmaLenDecode(p + RepLenCoder, &rd, posState);
593 + state = state < 7 ? 8 : 11;
601 + state = state < 7 ? 7 : 10;
602 + len = LzmaLenDecode(p + LenCoder, &rd, posState);
603 + posSlot = RangeDecoderBitTreeDecode(p + PosSlot +
604 + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
605 + kNumPosSlotBits), kNumPosSlotBits, &rd);
606 + if (posSlot >= kStartPosModelIndex)
608 + int numDirectBits = ((posSlot >> 1) - 1);
609 + rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits);
610 + if (posSlot < kEndPosModelIndex)
612 + rep0 += RangeDecoderReverseBitTreeDecode(
613 + p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd);
617 + rep0 += RangeDecoderDecodeDirectBits(&rd,
618 + numDirectBits - kNumAlignBits) << kNumAlignBits;
619 + rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd);
626 + if (rep0 == (UInt32)(0))
628 + /* it's for stream version */
633 + #ifdef _LZMA_OUT_READ
638 + return LZMA_RESULT_DATA_ERROR;
640 + len += kMatchMinLen;
643 + #ifdef _LZMA_OUT_READ
644 + UInt32 pos = dictionaryPos - rep0;
645 + if (pos >= dictionarySize)
646 + pos += dictionarySize;
647 + previousByte = dictionary[pos];
648 + dictionary[dictionaryPos] = previousByte;
649 + if (++dictionaryPos == dictionarySize)
652 + previousByte = outStream[nowPos - rep0];
654 + outStream[nowPos++] = previousByte;
657 + while(len > 0 && nowPos < outSize);
661 + #ifdef _LZMA_OUT_READ
662 + vs->RangeDecoder = rd;
663 + vs->DictionaryPos = dictionaryPos;
664 + vs->GlobalPos = globalPos + nowPos;
665 + vs->Reps[0] = rep0;
666 + vs->Reps[1] = rep1;
667 + vs->Reps[2] = rep2;
668 + vs->Reps[3] = rep3;
670 + vs->PreviousIsMatch = previousIsMatch;
671 + vs->RemainLen = len;
674 + *outSizeProcessed = nowPos;
675 + return LZMA_RESULT_OK;
677 --- linux-2.6.19.old/include/linux/LzmaDecode.h 1970-01-01 01:00:00.000000000 +0100
678 +++ linux-2.6.19.dev/include/linux/LzmaDecode.h 2006-12-14 03:13:20.000000000 +0100
682 + LZMA Decoder interface
684 + LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25)
685 + http://www.7-zip.org/
687 + LZMA SDK is licensed under two licenses:
688 + 1) GNU Lesser General Public License (GNU LGPL)
689 + 2) Common Public License (CPL)
690 + It means that you can select one of these two licenses and
691 + follow rules of that license.
694 + Igor Pavlov, as the author of this code, expressly permits you to
695 + statically or dynamically link your code (or bind by name) to the
696 + interfaces of this file without subjecting your linked code to the
697 + terms of the CPL or GNU LGPL. Any modifications or additions
698 + to this file, however, are subject to the LGPL or CPL terms.
701 +#ifndef __LZMADECODE_H
702 +#define __LZMADECODE_H
704 +/* #define _LZMA_IN_CB */
705 +/* Use callback for input data */
707 +/* #define _LZMA_OUT_READ */
708 +/* Use read function for output data */
710 +/* #define _LZMA_PROB32 */
711 +/* It can increase speed on some 32-bit CPUs,
712 + but memory usage will be doubled in that case */
714 +/* #define _LZMA_LOC_OPT */
715 +/* Enable local speed optimizations inside code */
718 +#ifdef _LZMA_UINT32_IS_ULONG
719 +#define UInt32 unsigned long
721 +#define UInt32 unsigned int
726 +#define CProb UInt32
728 +#define CProb unsigned short
731 +#define LZMA_RESULT_OK 0
732 +#define LZMA_RESULT_DATA_ERROR 1
733 +#define LZMA_RESULT_NOT_ENOUGH_MEM 2
736 +typedef struct _ILzmaInCallback
738 + int (*Read)(void *object, unsigned char **buffer, UInt32 *bufferSize);
742 +#define LZMA_BASE_SIZE 1846
743 +#define LZMA_LIT_SIZE 768
746 +bufferSize = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb)
747 +bufferSize += 100 in case of _LZMA_OUT_READ
748 +by default CProb is unsigned short,
749 +but if specify _LZMA_PROB_32, CProb will be UInt32(unsigned int)
752 +#ifdef _LZMA_OUT_READ
753 +int LzmaDecoderInit(
754 + unsigned char *buffer, UInt32 bufferSize,
755 + int lc, int lp, int pb,
756 + unsigned char *dictionary, UInt32 dictionarySize,
758 + ILzmaInCallback *inCallback
760 + unsigned char *inStream, UInt32 inSize
766 + unsigned char *buffer,
767 + #ifndef _LZMA_OUT_READ
769 + int lc, int lp, int pb,
771 + ILzmaInCallback *inCallback,
773 + unsigned char *inStream, UInt32 inSize,
776 + unsigned char *outStream, UInt32 outSize,
777 + UInt32 *outSizeProcessed);