C part of decompressor
This commit is contained in:
parent
c5b4cd370e
commit
f8926c32b4
9 changed files with 272 additions and 20 deletions
|
@ -1100,10 +1100,17 @@ enum xz_ret xz_dec_lzma2_run(
|
|||
return XZ_OK;
|
||||
}
|
||||
|
||||
#ifdef GRUB_EMBED_DECOMPRESSOR
|
||||
#include <grub/decompressor.h>
|
||||
static struct xz_dec_lzma2 lzma2;
|
||||
static char dict[GRUB_DECOMPRESSOR_DICT_SIZE];
|
||||
#endif
|
||||
|
||||
struct xz_dec_lzma2 * xz_dec_lzma2_create(uint32_t dict_max)
|
||||
{
|
||||
struct xz_dec_lzma2 *s;
|
||||
|
||||
#ifndef GRUB_EMBED_DECOMPRESSOR
|
||||
/* Maximum supported dictionary by this implementation is 3 GiB. */
|
||||
if (dict_max > ((uint32_t)3 << 30))
|
||||
return NULL;
|
||||
|
@ -1120,6 +1127,17 @@ struct xz_dec_lzma2 * xz_dec_lzma2_create(uint32_t dict_max)
|
|||
}
|
||||
}
|
||||
|
||||
#else
|
||||
if (dict_max > GRUB_DECOMPRESSOR_DICT_SIZE)
|
||||
return NULL;
|
||||
|
||||
s = &lzma2;
|
||||
|
||||
if (dict_max > 0) {
|
||||
s->dict.buf = (void *) &dict;
|
||||
}
|
||||
#endif
|
||||
|
||||
s->dict.allocated = dict_max;
|
||||
|
||||
return s;
|
||||
|
@ -1135,6 +1153,7 @@ enum xz_ret xz_dec_lzma2_reset(
|
|||
s->dict.size = 2 + (props & 1);
|
||||
s->dict.size <<= (props >> 1) + 11;
|
||||
|
||||
#ifndef GRUB_EMBED_DECOMPRESSOR
|
||||
if (s->dict.allocated > 0 && s->dict.allocated < s->dict.size)
|
||||
{
|
||||
/* enlarge dictionary buffer */
|
||||
|
@ -1146,7 +1165,10 @@ enum xz_ret xz_dec_lzma2_reset(
|
|||
s->dict.buf = newdict;
|
||||
s->dict.allocated = s->dict.size;
|
||||
}
|
||||
|
||||
#else
|
||||
if (s->dict.allocated > 0 && s->dict.allocated < s->dict.size)
|
||||
return XZ_MEMLIMIT_ERROR;
|
||||
#endif
|
||||
s->dict.end = s->dict.size;
|
||||
|
||||
s->lzma.len = 0;
|
||||
|
@ -1159,10 +1181,12 @@ enum xz_ret xz_dec_lzma2_reset(
|
|||
return XZ_OK;
|
||||
}
|
||||
|
||||
void xz_dec_lzma2_end(struct xz_dec_lzma2 *s)
|
||||
void xz_dec_lzma2_end(struct xz_dec_lzma2 *s __attribute__ ((unused)))
|
||||
{
|
||||
#ifndef GRUB_EMBED_DECOMPRESSOR
|
||||
if (s->dict.allocated > 0)
|
||||
vfree(s->dict.buf);
|
||||
|
||||
kfree(s);
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue