merge mainline into gdb
This commit is contained in:
commit
515e8007fc
465 changed files with 26882 additions and 11400 deletions
|
@ -69,9 +69,9 @@ static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *a
|
|||
}
|
||||
|
||||
Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
|
||||
Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }
|
||||
static Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 curindex) { return p->buffer[curindex]; }
|
||||
|
||||
UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
|
||||
static UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
|
||||
|
||||
void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
|
||||
{
|
||||
|
|
|
@ -120,7 +120,7 @@ UInt32 GetPosSlot1(UInt32 pos)
|
|||
#define kNumLogBits (9 + (int)sizeof(size_t) / 2)
|
||||
#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)
|
||||
|
||||
void LzmaEnc_FastPosInit(Byte *g_FastPos)
|
||||
static void LzmaEnc_FastPosInit(Byte *g_FastPos)
|
||||
{
|
||||
int c = 2, slotFast;
|
||||
g_FastPos[0] = 0;
|
||||
|
@ -374,58 +374,6 @@ typedef struct _CLzmaEnc
|
|||
CSaveState saveState;
|
||||
} CLzmaEnc;
|
||||
|
||||
void LzmaEnc_SaveState(CLzmaEncHandle pp)
|
||||
{
|
||||
CLzmaEnc *p = (CLzmaEnc *)pp;
|
||||
CSaveState *dest = &p->saveState;
|
||||
int i;
|
||||
dest->lenEnc = p->lenEnc;
|
||||
dest->repLenEnc = p->repLenEnc;
|
||||
dest->state = p->state;
|
||||
|
||||
for (i = 0; i < kNumStates; i++)
|
||||
{
|
||||
memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
|
||||
memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
|
||||
}
|
||||
for (i = 0; i < kNumLenToPosStates; i++)
|
||||
memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
|
||||
memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
|
||||
memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
|
||||
memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
|
||||
memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
|
||||
memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
|
||||
memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
|
||||
memcpy(dest->reps, p->reps, sizeof(p->reps));
|
||||
memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb));
|
||||
}
|
||||
|
||||
void LzmaEnc_RestoreState(CLzmaEncHandle pp)
|
||||
{
|
||||
CLzmaEnc *dest = (CLzmaEnc *)pp;
|
||||
const CSaveState *p = &dest->saveState;
|
||||
int i;
|
||||
dest->lenEnc = p->lenEnc;
|
||||
dest->repLenEnc = p->repLenEnc;
|
||||
dest->state = p->state;
|
||||
|
||||
for (i = 0; i < kNumStates; i++)
|
||||
{
|
||||
memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
|
||||
memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
|
||||
}
|
||||
for (i = 0; i < kNumLenToPosStates; i++)
|
||||
memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
|
||||
memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
|
||||
memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
|
||||
memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
|
||||
memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
|
||||
memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
|
||||
memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
|
||||
memcpy(dest->reps, p->reps, sizeof(p->reps));
|
||||
memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb));
|
||||
}
|
||||
|
||||
SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
|
||||
{
|
||||
CLzmaEnc *p = (CLzmaEnc *)pp;
|
||||
|
@ -643,7 +591,7 @@ static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol,
|
|||
while (symbol < 0x10000);
|
||||
}
|
||||
|
||||
void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
|
||||
static void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
|
||||
{
|
||||
UInt32 i;
|
||||
for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))
|
||||
|
@ -975,6 +923,8 @@ static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur)
|
|||
|
||||
#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * 0x300)
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wshadow"
|
||||
|
||||
static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
|
||||
{
|
||||
UInt32 numAvailableBytes, lenMain, numDistancePairs;
|
||||
|
@ -1769,7 +1719,7 @@ static void FillDistancesPrices(CLzmaEnc *p)
|
|||
p->matchPriceCount = 0;
|
||||
}
|
||||
|
||||
void LzmaEnc_Construct(CLzmaEnc *p)
|
||||
static void LzmaEnc_Construct(CLzmaEnc *p)
|
||||
{
|
||||
RangeEnc_Construct(&p->rc);
|
||||
MatchFinder_Construct(&p->matchFinderBase);
|
||||
|
@ -1802,7 +1752,7 @@ CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc)
|
|||
return p;
|
||||
}
|
||||
|
||||
void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
|
||||
static void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
|
||||
{
|
||||
alloc->Free(alloc, p->litProbs);
|
||||
alloc->Free(alloc, p->saveState.litProbs);
|
||||
|
@ -1810,7 +1760,7 @@ void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
|
|||
p->saveState.litProbs = 0;
|
||||
}
|
||||
|
||||
void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
|
||||
static void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
|
||||
{
|
||||
#ifdef COMPRESS_MF_MT
|
||||
MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);
|
||||
|
@ -2043,7 +1993,7 @@ static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, I
|
|||
return SZ_OK;
|
||||
}
|
||||
|
||||
void LzmaEnc_Init(CLzmaEnc *p)
|
||||
static void LzmaEnc_Init(CLzmaEnc *p)
|
||||
{
|
||||
UInt32 i;
|
||||
p->state = 0;
|
||||
|
@ -2102,7 +2052,7 @@ void LzmaEnc_Init(CLzmaEnc *p)
|
|||
p->lpMask = (1 << p->lp) - 1;
|
||||
}
|
||||
|
||||
void LzmaEnc_InitPrices(CLzmaEnc *p)
|
||||
static void LzmaEnc_InitPrices(CLzmaEnc *p)
|
||||
{
|
||||
if (!p->fastMode)
|
||||
{
|
||||
|
@ -2143,15 +2093,6 @@ static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqInStream *inStream, ISeqOutSt
|
|||
return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);
|
||||
}
|
||||
|
||||
SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
|
||||
ISeqInStream *inStream, UInt32 keepWindowSize,
|
||||
ISzAlloc *alloc, ISzAlloc *allocBig)
|
||||
{
|
||||
CLzmaEnc *p = (CLzmaEnc *)pp;
|
||||
p->inStream = inStream;
|
||||
return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
|
||||
}
|
||||
|
||||
static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)
|
||||
{
|
||||
p->seqBufInStream.funcTable.Read = MyRead;
|
||||
|
@ -2159,16 +2100,7 @@ static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)
|
|||
p->seqBufInStream.rem = srcLen;
|
||||
}
|
||||
|
||||
SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
|
||||
UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
|
||||
{
|
||||
CLzmaEnc *p = (CLzmaEnc *)pp;
|
||||
LzmaEnc_SetInputBuf(p, src, srcLen);
|
||||
p->inStream = &p->seqBufInStream.funcTable;
|
||||
return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
|
||||
}
|
||||
|
||||
void LzmaEnc_Finish(CLzmaEncHandle pp)
|
||||
static void LzmaEnc_Finish(CLzmaEncHandle pp)
|
||||
{
|
||||
#ifdef COMPRESS_MF_MT
|
||||
CLzmaEnc *p = (CLzmaEnc *)pp;
|
||||
|
@ -2201,53 +2133,6 @@ static size_t MyWrite(void *pp, const void *data, size_t size)
|
|||
return size;
|
||||
}
|
||||
|
||||
|
||||
UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)
|
||||
{
|
||||
const CLzmaEnc *p = (CLzmaEnc *)pp;
|
||||
return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
|
||||
}
|
||||
|
||||
const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
|
||||
{
|
||||
const CLzmaEnc *p = (CLzmaEnc *)pp;
|
||||
return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
|
||||
}
|
||||
|
||||
SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
|
||||
Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)
|
||||
{
|
||||
CLzmaEnc *p = (CLzmaEnc *)pp;
|
||||
UInt64 nowPos64;
|
||||
SRes res;
|
||||
CSeqOutStreamBuf outStream;
|
||||
|
||||
outStream.funcTable.Write = MyWrite;
|
||||
outStream.data = dest;
|
||||
outStream.rem = *destLen;
|
||||
outStream.overflow = False;
|
||||
|
||||
p->writeEndMark = False;
|
||||
p->finished = False;
|
||||
p->result = SZ_OK;
|
||||
|
||||
if (reInit)
|
||||
LzmaEnc_Init(p);
|
||||
LzmaEnc_InitPrices(p);
|
||||
nowPos64 = p->nowPos64;
|
||||
RangeEnc_Init(&p->rc);
|
||||
p->rc.outStream = &outStream.funcTable;
|
||||
|
||||
res = LzmaEnc_CodeOneBlock(pp, True, desiredPackSize, *unpackSize);
|
||||
|
||||
*unpackSize = (UInt32)(p->nowPos64 - nowPos64);
|
||||
*destLen -= outStream.rem;
|
||||
if (outStream.overflow)
|
||||
return SZ_ERROR_OUTPUT_EOF;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,
|
||||
ISzAlloc *alloc, ISzAlloc *allocBig)
|
||||
{
|
||||
|
|
|
@ -25,14 +25,11 @@
|
|||
#include <grub/i18n.h>
|
||||
|
||||
/* Built-in parser for default options. */
|
||||
#define SHORT_ARG_HELP -100
|
||||
#define SHORT_ARG_USAGE -101
|
||||
|
||||
static const struct grub_arg_option help_options[] =
|
||||
{
|
||||
{"help", SHORT_ARG_HELP, 0,
|
||||
{"help", 0, 0,
|
||||
N_("Display this help and exit."), 0, ARG_TYPE_NONE},
|
||||
{"usage", SHORT_ARG_USAGE, 0,
|
||||
{"usage", 0, 0,
|
||||
N_("Display the usage of this command and exit."), 0, ARG_TYPE_NONE},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
@ -125,9 +122,9 @@ grub_arg_show_help (grub_extcmd_t cmd)
|
|||
|
||||
if (opt->shortarg && grub_isgraph (opt->shortarg))
|
||||
grub_printf ("-%c%c ", opt->shortarg, opt->longarg ? ',':' ');
|
||||
else if (opt->shortarg == SHORT_ARG_HELP && ! h_is_used)
|
||||
else if (opt == help_options && ! h_is_used)
|
||||
grub_printf ("-h, ");
|
||||
else if (opt->shortarg == SHORT_ARG_USAGE && ! u_is_used)
|
||||
else if (opt == help_options + 1 && ! u_is_used)
|
||||
grub_printf ("-u, ");
|
||||
else
|
||||
grub_printf (" ");
|
||||
|
@ -180,50 +177,34 @@ grub_arg_show_help (grub_extcmd_t cmd)
|
|||
|
||||
|
||||
static int
|
||||
parse_option (grub_extcmd_t cmd, int key, char *arg, struct grub_arg_list *usr)
|
||||
parse_option (grub_extcmd_t cmd, const struct grub_arg_option *opt,
|
||||
char *arg, struct grub_arg_list *usr)
|
||||
{
|
||||
switch (key)
|
||||
if (opt == help_options)
|
||||
{
|
||||
case SHORT_ARG_HELP:
|
||||
grub_arg_show_help (cmd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
case SHORT_ARG_USAGE:
|
||||
if (opt == help_options + 1)
|
||||
{
|
||||
show_usage (cmd);
|
||||
return -1;
|
||||
|
||||
default:
|
||||
{
|
||||
int found = -1;
|
||||
int i = 0;
|
||||
const struct grub_arg_option *opt = cmd->options;
|
||||
|
||||
while (opt->doc)
|
||||
{
|
||||
if (opt->shortarg && key == opt->shortarg)
|
||||
{
|
||||
found = i;
|
||||
break;
|
||||
}
|
||||
opt++;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (found == -1)
|
||||
return -1;
|
||||
|
||||
if (opt->flags & GRUB_ARG_OPTION_REPEATABLE)
|
||||
{
|
||||
usr[found].args[usr[found].set++] = arg;
|
||||
usr[found].args[usr[found].set] = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
usr[found].set = 1;
|
||||
usr[found].arg = arg;
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
int found = opt - cmd->options;
|
||||
|
||||
if (opt->flags & GRUB_ARG_OPTION_REPEATABLE)
|
||||
{
|
||||
usr[found].args[usr[found].set++] = arg;
|
||||
usr[found].args[usr[found].set] = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
usr[found].set = 1;
|
||||
usr[found].arg = arg;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -296,8 +277,9 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
|
|||
|
||||
if (! opt)
|
||||
{
|
||||
char tmp[3] = { '-', *curshort, 0 };
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
"unknown argument `-%c'", *curshort);
|
||||
N_("unknown argument `%s'"), tmp);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
@ -307,7 +289,7 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
|
|||
it can have an argument value. */
|
||||
if (*curshort)
|
||||
{
|
||||
if (parse_option (cmd, opt->shortarg, 0, usr) || grub_errno)
|
||||
if (parse_option (cmd, opt, 0, usr) || grub_errno)
|
||||
goto fail;
|
||||
}
|
||||
else
|
||||
|
@ -351,7 +333,7 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
|
|||
opt = find_long (cmd->options, arg + 2, arglen);
|
||||
|
||||
if (!option && argv[curarg + 1] && argv[curarg + 1][0] != '-'
|
||||
&& opt->type != ARG_TYPE_NONE)
|
||||
&& opt && opt->type != ARG_TYPE_NONE)
|
||||
option = argv[++curarg];
|
||||
|
||||
if (!opt && (cmd->cmd->flags & GRUB_COMMAND_ACCEPT_DASH))
|
||||
|
@ -363,7 +345,7 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
|
|||
|
||||
if (! opt)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown argument `%s'", arg);
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, N_("unknown argument `%s'"), arg);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
@ -374,7 +356,7 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
|
|||
if (! option)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
"missing mandatory option for `%s'", opt->longarg);
|
||||
N_("missing mandatory option for `%s'"), opt->longarg);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
@ -396,7 +378,7 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
|
|||
if (tail == 0 || tail == option || *tail != '\0' || grub_errno)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
"the argument `%s' requires an integer",
|
||||
N_("the argument `%s' requires an integer"),
|
||||
arg);
|
||||
|
||||
goto fail;
|
||||
|
@ -411,7 +393,7 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
|
|||
/* XXX: Not implemented. */
|
||||
break;
|
||||
}
|
||||
if (parse_option (cmd, opt->shortarg, option, usr) || grub_errno)
|
||||
if (parse_option (cmd, opt, option, usr) || grub_errno)
|
||||
goto fail;
|
||||
}
|
||||
else
|
||||
|
@ -419,12 +401,12 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
|
|||
if (option)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
"a value was assigned to the argument `%s' while it "
|
||||
"doesn't require an argument", arg);
|
||||
N_("a value was assigned to the argument `%s' while it "
|
||||
"doesn't require an argument"), arg);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (parse_option (cmd, opt->shortarg, 0, usr) || grub_errno)
|
||||
if (parse_option (cmd, opt, 0, usr) || grub_errno)
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <grub/mm.h>
|
||||
#include <grub/term.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
#include <termios.h>
|
||||
|
@ -169,20 +170,6 @@ grub_crypto_cipher_set_key (grub_crypto_cipher_handle_t cipher,
|
|||
return cipher->cipher->setkey (cipher->ctx, key, keylen);
|
||||
}
|
||||
|
||||
void
|
||||
grub_crypto_xor (void *out, const void *in1, const void *in2, grub_size_t size)
|
||||
{
|
||||
const grub_uint8_t *in1ptr = in1, *in2ptr = in2;
|
||||
grub_uint8_t *outptr = out;
|
||||
while (size--)
|
||||
{
|
||||
*outptr = *in1ptr ^ *in2ptr;
|
||||
in1ptr++;
|
||||
in2ptr++;
|
||||
outptr++;
|
||||
}
|
||||
}
|
||||
|
||||
gcry_err_code_t
|
||||
grub_crypto_ecb_decrypt (grub_crypto_cipher_handle_t cipher,
|
||||
void *out, const void *in, grub_size_t size)
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include <grub/i386/relocator.h>
|
||||
#include <grub/relocator_private.h>
|
||||
#include <grub/i386/relocator_private.h>
|
||||
|
||||
extern grub_uint8_t grub_relocator_forward_start;
|
||||
extern grub_uint8_t grub_relocator_forward_end;
|
||||
|
@ -200,8 +201,10 @@ grub_relocator16_boot (struct grub_relocator *rel,
|
|||
|
||||
/* Put it higher than the byte it checks for A20 check. */
|
||||
err = grub_relocator_alloc_chunk_align (rel, &ch, 0x8010,
|
||||
0xa0000 - RELOCATOR_SIZEOF (16),
|
||||
RELOCATOR_SIZEOF (16), 16,
|
||||
0xa0000 - RELOCATOR_SIZEOF (16)
|
||||
- GRUB_RELOCATOR16_STACK_SIZE,
|
||||
RELOCATOR_SIZEOF (16)
|
||||
+ GRUB_RELOCATOR16_STACK_SIZE, 16,
|
||||
GRUB_RELOCATOR_PREFERENCE_NONE);
|
||||
if (err)
|
||||
return err;
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
#define PSEUDO_REAL_DSEG 0x20
|
||||
|
||||
#include <grub/i386/relocator_private.h>
|
||||
|
||||
#include "relocator_common.S"
|
||||
|
||||
.p2align 4 /* force 16-byte alignment */
|
||||
|
@ -101,10 +103,9 @@ VARIABLE(grub_relocator16_keep_a20_enabled)
|
|||
test %ax, %ax
|
||||
jnz LOCAL(gate_a20_done)
|
||||
|
||||
/* first of all, test if already in a good state */
|
||||
call LOCAL(gate_a20_check_state)
|
||||
testb %al, %al
|
||||
jz LOCAL(gate_a20_done)
|
||||
movw %cs, %ax
|
||||
movw %ax, %ss
|
||||
leaw EXT_C(grub_relocator16_end) - LOCAL(base) + GRUB_RELOCATOR16_STACK_SIZE, %sp
|
||||
|
||||
/* second, try a BIOS call */
|
||||
movw $0x2400, %ax
|
||||
|
@ -132,14 +133,6 @@ LOCAL(gate_a20_check_state):
|
|||
/* iterate the checking for a while */
|
||||
movw $100, %cx
|
||||
1:
|
||||
call 3f
|
||||
testb %al, %al
|
||||
jz 2f
|
||||
loop 1b
|
||||
2:
|
||||
ret
|
||||
|
||||
3:
|
||||
xorw %ax, %ax
|
||||
movw %ax, %ds
|
||||
decw %ax
|
||||
|
@ -168,7 +161,12 @@ LOCAL(gate_a20_check_state):
|
|||
subb %dh, %al
|
||||
xorb $1, %al
|
||||
/* restore the original */
|
||||
movb %dl, %es:(%di)
|
||||
movb %dl, %ds:(%si)
|
||||
|
||||
testb %al, %al
|
||||
jz LOCAL(gate_a20_done)
|
||||
loop 1b
|
||||
2:
|
||||
ret
|
||||
|
||||
LOCAL(gate_a20_done):
|
||||
|
|
|
@ -85,7 +85,10 @@ grub_relocator_firmware_fill_events (struct grub_relocator_mmap_event *events)
|
|||
int
|
||||
grub_relocator_firmware_alloc_region (grub_addr_t start, grub_size_t size)
|
||||
{
|
||||
return (grub_claimmap (start, size) >= 0);
|
||||
grub_err_t err;
|
||||
err = grub_claimmap (start, size);
|
||||
grub_errno = 0;
|
||||
return (err == 0);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <grub/err.h>
|
||||
#include <grub/legacy_parse.h>
|
||||
#include <grub/i386/pc/vesa_modes_table.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
struct legacy_command
|
||||
{
|
||||
|
@ -42,7 +43,8 @@ struct legacy_command
|
|||
TYPE_BOOL,
|
||||
TYPE_INT,
|
||||
TYPE_REST_VERBATIM,
|
||||
TYPE_VBE_MODE
|
||||
TYPE_VBE_MODE,
|
||||
TYPE_WITH_CONFIGFILE_OPTION
|
||||
} argt[4];
|
||||
enum {
|
||||
FLAG_IGNORE_REST = 0x001,
|
||||
|
@ -67,7 +69,13 @@ static struct legacy_command legacy_commands[] =
|
|||
"Print the blocklist notation of the file FILE."},
|
||||
{"boot", "boot\n", NULL, 0, 0, {}, 0, 0,
|
||||
"Boot the OS/chain-loader which has been loaded."},
|
||||
/* FIXME: bootp unsupported. */
|
||||
{"bootp", "net_bootp; net_ls_addr; if [ x%s = x--with-configfile ]; then "
|
||||
"if net_get_dhcp_option configfile_name pxe 150 string; then "
|
||||
"configfile $configfile_name; fi; fi\n", NULL, 0, 1,
|
||||
{TYPE_WITH_CONFIGFILE_OPTION}, FLAG_IGNORE_REST, "[--with-configfile]",
|
||||
"Initialize a network device via BOOTP. If the option `--with-configfile'"
|
||||
" is given, try to load a configuration file specified by the 150 vendor"
|
||||
" tag."},
|
||||
{"cat", "cat '%s'\n", NULL, 0, 1, {TYPE_FILE}, 0, "FILE",
|
||||
"Print the contents of the file FILE."},
|
||||
{"chainloader", "chainloader %s '%s'\n", NULL, 0,
|
||||
|
@ -105,7 +113,13 @@ static struct legacy_command legacy_commands[] =
|
|||
"[NUM | `saved']",
|
||||
"Set the default entry to entry number NUM (if not specified, it is"
|
||||
" 0, the first entry) or the entry number saved by savedefault."},
|
||||
/* FIXME: dhcp unsupported. */
|
||||
{"dhcp", "net_bootp; net_ls_addr; if [ x%s = x--with-configfile ]; then "
|
||||
"if net_get_dhcp_option configfile_name pxe 150 string; then "
|
||||
"configfile $configfile_name; fi; fi\n", NULL, 0, 1,
|
||||
{TYPE_WITH_CONFIGFILE_OPTION}, FLAG_IGNORE_REST, "[--with-configfile]",
|
||||
"Initialize a network device via BOOTP. If the option `--with-configfile'"
|
||||
" is given, try to load a configuration file specified by the 150 vendor"
|
||||
" tag."},
|
||||
{"displayapm", "lsapm\n", NULL, 0, 0, {}, 0, 0,
|
||||
"Display APM BIOS information."},
|
||||
{"displaymem", "lsmmap\n", NULL, 0, 0, {}, 0, 0,
|
||||
|
@ -402,7 +416,7 @@ adjust_file (const char *in, grub_size_t len)
|
|||
}
|
||||
|
||||
static int
|
||||
check_option (const char *a, char *b, grub_size_t len)
|
||||
check_option (const char *a, const char *b, grub_size_t len)
|
||||
{
|
||||
if (grub_strlen (b) != len)
|
||||
return 0;
|
||||
|
@ -414,6 +428,8 @@ is_option (enum arg_type opt, const char *curarg, grub_size_t len)
|
|||
{
|
||||
switch (opt)
|
||||
{
|
||||
case TYPE_WITH_CONFIGFILE_OPTION:
|
||||
return check_option (curarg, "--with-configfile", len);
|
||||
case TYPE_NOAPM_OPTION:
|
||||
return check_option (curarg, "--no-apm", len);
|
||||
case TYPE_FORCE_OPTION:
|
||||
|
@ -665,6 +681,7 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix)
|
|||
case TYPE_VERBATIM:
|
||||
args[i] = grub_legacy_escape (curarg, curarglen);
|
||||
break;
|
||||
case TYPE_WITH_CONFIGFILE_OPTION:
|
||||
case TYPE_FORCE_OPTION:
|
||||
case TYPE_NOAPM_OPTION:
|
||||
case TYPE_TYPE_OR_NOMEM_OPTION:
|
||||
|
@ -759,6 +776,7 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix)
|
|||
case TYPE_FILE:
|
||||
case TYPE_REST_VERBATIM:
|
||||
case TYPE_VERBATIM:
|
||||
case TYPE_WITH_CONFIGFILE_OPTION:
|
||||
case TYPE_FORCE_OPTION:
|
||||
case TYPE_NOAPM_OPTION:
|
||||
case TYPE_TYPE_OR_NOMEM_OPTION:
|
||||
|
@ -784,7 +802,7 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix)
|
|||
len = grub_strlen (corig);
|
||||
if (!slash)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "bad color specification %s",
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid color specification `%s'"),
|
||||
args[0]);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -101,7 +101,8 @@ transform ( MD4_CONTEXT *ctx, const unsigned char *data )
|
|||
#ifdef WORDS_BIGENDIAN
|
||||
{
|
||||
int i;
|
||||
byte *p2, *p1;
|
||||
byte *p2;
|
||||
const byte *p1;
|
||||
for(i=0, p1=data, p2=(byte*)in; i < 16; i++, p2 += 4 )
|
||||
{
|
||||
p2[3] = *p1++;
|
||||
|
|
|
@ -92,7 +92,8 @@ transform ( MD5_CONTEXT *ctx, const unsigned char *data )
|
|||
#ifdef WORDS_BIGENDIAN
|
||||
{
|
||||
int i;
|
||||
byte *p2, *p1;
|
||||
byte *p2;
|
||||
const byte *p1;
|
||||
for(i=0, p1=data, p2=(byte*)correct_words; i < 16; i++, p2 += 4 )
|
||||
{
|
||||
p2[3] = *p1++;
|
||||
|
|
|
@ -169,7 +169,8 @@ transform ( RMD160_CONTEXT *hd, const unsigned char *data )
|
|||
u32 x[16];
|
||||
{
|
||||
int i;
|
||||
byte *p2, *p1;
|
||||
byte *p2;
|
||||
const byte *p1;
|
||||
for (i=0, p1=data, p2=(byte*)x; i < 16; i++, p2 += 4 )
|
||||
{
|
||||
p2[3] = *p1++;
|
||||
|
|
|
@ -585,22 +585,19 @@ serpent_key_prepare (const byte *key, unsigned int key_length,
|
|||
int i;
|
||||
|
||||
/* Copy key. */
|
||||
for (i = 0; i < key_length / 4; i++)
|
||||
{
|
||||
memcpy (key_prepared, key, key_length);
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
key_prepared[i] = byte_swap_32 (((u32 *) key)[i]);
|
||||
#else
|
||||
key_prepared[i] = ((u32 *) key)[i];
|
||||
for (i = 0; i < key_length / 4; i++)
|
||||
key_prepared[i] = byte_swap_32 (key_prepared[i]);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (i < 8)
|
||||
if (key_length < 32)
|
||||
{
|
||||
/* Key must be padded according to the Serpent
|
||||
specification. */
|
||||
key_prepared[i] = 0x00000001;
|
||||
key_prepared[key_length / 4] = 0x00000001;
|
||||
|
||||
for (i++; i < 8; i++)
|
||||
for (i = key_length / 4 + 1; i < 8; i++)
|
||||
key_prepared[i] = 0;
|
||||
}
|
||||
}
|
||||
|
@ -707,21 +704,17 @@ serpent_setkey (void *ctx,
|
|||
|
||||
static void
|
||||
serpent_encrypt_internal (serpent_context_t *context,
|
||||
const serpent_block_t input, serpent_block_t output)
|
||||
const byte *input, byte *output)
|
||||
{
|
||||
serpent_block_t b, b_next;
|
||||
int round = 0;
|
||||
|
||||
memcpy (b, input, sizeof (b));
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
b[0] = byte_swap_32 (input[0]);
|
||||
b[1] = byte_swap_32 (input[1]);
|
||||
b[2] = byte_swap_32 (input[2]);
|
||||
b[3] = byte_swap_32 (input[3]);
|
||||
#else
|
||||
b[0] = input[0];
|
||||
b[1] = input[1];
|
||||
b[2] = input[2];
|
||||
b[3] = input[3];
|
||||
b[0] = byte_swap_32 (b[0]);
|
||||
b[1] = byte_swap_32 (b[1]);
|
||||
b[2] = byte_swap_32 (b[2]);
|
||||
b[3] = byte_swap_32 (b[3]);
|
||||
#endif
|
||||
|
||||
ROUND (0, context->keys, b, b_next);
|
||||
|
@ -759,35 +752,27 @@ serpent_encrypt_internal (serpent_context_t *context,
|
|||
ROUND_LAST (7, context->keys, b, b_next);
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
output[0] = byte_swap_32 (b_next[0]);
|
||||
output[1] = byte_swap_32 (b_next[1]);
|
||||
output[2] = byte_swap_32 (b_next[2]);
|
||||
output[3] = byte_swap_32 (b_next[3]);
|
||||
#else
|
||||
output[0] = b_next[0];
|
||||
output[1] = b_next[1];
|
||||
output[2] = b_next[2];
|
||||
output[3] = b_next[3];
|
||||
b_next[0] = byte_swap_32 (b_next[0]);
|
||||
b_next[1] = byte_swap_32 (b_next[1]);
|
||||
b_next[2] = byte_swap_32 (b_next[2]);
|
||||
b_next[3] = byte_swap_32 (b_next[3]);
|
||||
#endif
|
||||
memcpy (output, b_next, sizeof (b_next));
|
||||
}
|
||||
|
||||
static void
|
||||
serpent_decrypt_internal (serpent_context_t *context,
|
||||
const serpent_block_t input, serpent_block_t output)
|
||||
const byte *input, byte *output)
|
||||
{
|
||||
serpent_block_t b, b_next;
|
||||
int round = ROUNDS;
|
||||
|
||||
memcpy (b, input, sizeof (b));
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
b_next[0] = byte_swap_32 (input[0]);
|
||||
b_next[1] = byte_swap_32 (input[1]);
|
||||
b_next[2] = byte_swap_32 (input[2]);
|
||||
b_next[3] = byte_swap_32 (input[3]);
|
||||
#else
|
||||
b_next[0] = input[0];
|
||||
b_next[1] = input[1];
|
||||
b_next[2] = input[2];
|
||||
b_next[3] = input[3];
|
||||
b[0] = byte_swap_32 (b[0]);
|
||||
b[1] = byte_swap_32 (b[1]);
|
||||
b[2] = byte_swap_32 (b[2]);
|
||||
b[3] = byte_swap_32 (b[3]);
|
||||
#endif
|
||||
|
||||
ROUND_FIRST_INVERSE (7, context->keys, b_next, b);
|
||||
|
@ -824,18 +809,13 @@ serpent_decrypt_internal (serpent_context_t *context,
|
|||
ROUND_INVERSE (1, context->keys, b, b_next);
|
||||
ROUND_INVERSE (0, context->keys, b, b_next);
|
||||
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
output[0] = byte_swap_32 (b_next[0]);
|
||||
output[1] = byte_swap_32 (b_next[1]);
|
||||
output[2] = byte_swap_32 (b_next[2]);
|
||||
output[3] = byte_swap_32 (b_next[3]);
|
||||
#else
|
||||
output[0] = b_next[0];
|
||||
output[1] = b_next[1];
|
||||
output[2] = b_next[2];
|
||||
output[3] = b_next[3];
|
||||
b_next[0] = byte_swap_32 (b_next[0]);
|
||||
b_next[1] = byte_swap_32 (b_next[1]);
|
||||
b_next[2] = byte_swap_32 (b_next[2]);
|
||||
b_next[3] = byte_swap_32 (b_next[3]);
|
||||
#endif
|
||||
memcpy (output, b_next, sizeof (b_next));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -843,8 +823,7 @@ serpent_encrypt (void *ctx, byte *buffer_out, const byte *buffer_in)
|
|||
{
|
||||
serpent_context_t *context = ctx;
|
||||
|
||||
serpent_encrypt_internal (context,
|
||||
(const u32 *) buffer_in, (u32 *) buffer_out);
|
||||
serpent_encrypt_internal (context, buffer_in, buffer_out);
|
||||
_gcry_burn_stack (2 * sizeof (serpent_block_t));
|
||||
}
|
||||
|
||||
|
@ -853,9 +832,7 @@ serpent_decrypt (void *ctx, byte *buffer_out, const byte *buffer_in)
|
|||
{
|
||||
serpent_context_t *context = ctx;
|
||||
|
||||
serpent_decrypt_internal (context,
|
||||
(const u32 *) buffer_in,
|
||||
(u32 *) buffer_out);
|
||||
serpent_decrypt_internal (context, buffer_in, buffer_out);
|
||||
_gcry_burn_stack (2 * sizeof (serpent_block_t));
|
||||
}
|
||||
|
||||
|
@ -915,8 +892,8 @@ serpent_test (void)
|
|||
serpent_setkey_internal (&context, test_data[i].key,
|
||||
test_data[i].key_length);
|
||||
serpent_encrypt_internal (&context,
|
||||
(const u32 *) test_data[i].text_plain,
|
||||
(u32 *) scratch);
|
||||
test_data[i].text_plain,
|
||||
scratch);
|
||||
|
||||
if (memcmp (scratch, test_data[i].text_cipher, sizeof (serpent_block_t)))
|
||||
switch (test_data[i].key_length)
|
||||
|
@ -930,8 +907,8 @@ serpent_test (void)
|
|||
}
|
||||
|
||||
serpent_decrypt_internal (&context,
|
||||
(const u32 *) test_data[i].text_cipher,
|
||||
(u32 *) scratch);
|
||||
test_data[i].text_cipher,
|
||||
scratch);
|
||||
if (memcmp (scratch, test_data[i].text_plain, sizeof (serpent_block_t)))
|
||||
switch (test_data[i].key_length)
|
||||
{
|
||||
|
|
|
@ -25,13 +25,14 @@
|
|||
#include <grub/dl.h>
|
||||
#include <grub/crypto.h>
|
||||
|
||||
#ifdef GRUB_CPU_WORDS_BIGENDIAN
|
||||
#define WORDS_BIGENDIAN
|
||||
#else
|
||||
#undef WORDS_BIGENDIAN
|
||||
|
||||
#ifdef GRUB_CPU_WORDS_BIGENDIAN
|
||||
#define WORDS_BIGENDIAN 1
|
||||
#endif
|
||||
|
||||
#define __GNU_LIBRARY__
|
||||
#undef __GNU_LIBRARY__
|
||||
#define __GNU_LIBRARY__ 1
|
||||
|
||||
#define DIM ARRAY_SIZE
|
||||
|
||||
|
@ -88,6 +89,7 @@ fips_mode (void)
|
|||
}
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
#pragma GCC diagnostic ignored "-Wshadow"
|
||||
static inline void *
|
||||
memcpy (void *dest, const void *src, grub_size_t n)
|
||||
{
|
||||
|
@ -105,6 +107,7 @@ memcmp (const void *s1, const void *s2, grub_size_t n)
|
|||
{
|
||||
return grub_memcmp (s1, s2, n);
|
||||
}
|
||||
#pragma GCC diagnostic error "-Wshadow"
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -31,6 +31,8 @@ GRUB_MOD_LICENSE ("GPLv2+");
|
|||
desired derived output length DKLEN. Output buffer is DK which
|
||||
must have room for at least DKLEN octets. The output buffer will
|
||||
be filled with the derived data. */
|
||||
#pragma GCC diagnostic ignored "-Wunreachable-code"
|
||||
|
||||
gcry_err_code_t
|
||||
grub_crypto_pbkdf2 (const struct gcry_md_spec *md,
|
||||
const grub_uint8_t *P, grub_size_t Plen,
|
||||
|
|
|
@ -27,7 +27,7 @@ static inline void
|
|||
assert_real (const char *file, int line, int cond)
|
||||
{
|
||||
if (!cond)
|
||||
grub_fatal ("Assertion failed at %s:%d\n", file, line);
|
||||
grub_printf ("Assertion failed at %s:%d\n", file, line);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -42,13 +42,19 @@ isdigit (int c)
|
|||
static inline int
|
||||
islower (int c)
|
||||
{
|
||||
return (c >= 'a' && c <= 'z');
|
||||
return grub_islower (c);
|
||||
}
|
||||
|
||||
static inline int
|
||||
isascii (int c)
|
||||
{
|
||||
return !(c & ~0x7f);
|
||||
}
|
||||
|
||||
static inline int
|
||||
isupper (int c)
|
||||
{
|
||||
return (c >= 'A' && c <= 'Z');
|
||||
return grub_isupper (c);
|
||||
}
|
||||
|
||||
static inline int
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
typedef enum { CODESET } nl_item;
|
||||
|
||||
static inline char *
|
||||
static inline const char *
|
||||
nl_langinfo (nl_item item)
|
||||
{
|
||||
switch (item)
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
#define UINT_MAX GRUB_UINT_MAX
|
||||
#define ULONG_MAX GRUB_ULONG_MAX
|
||||
|
||||
#define SHRT_MAX GRUB_SHRT_MAX
|
||||
#define INT_MAX GRUB_INT_MAX
|
||||
|
||||
#define CHAR_BIT 8
|
||||
|
||||
#endif
|
||||
|
|
|
@ -26,4 +26,17 @@ typedef struct grub_file FILE;
|
|||
|
||||
#define EOF -1
|
||||
|
||||
static inline int
|
||||
snprintf (char *str, size_t n, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
va_start (ap, fmt);
|
||||
ret = grub_vsnprintf (str, n, fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -46,12 +46,10 @@ realloc (void *ptr, grub_size_t size)
|
|||
return grub_realloc (ptr, size);
|
||||
}
|
||||
|
||||
static inline void
|
||||
abort (void)
|
||||
static inline int
|
||||
abs (int c)
|
||||
{
|
||||
grub_abort ();
|
||||
return (c >= 0) ? c : -c;
|
||||
}
|
||||
|
||||
#define MB_CUR_MAX 6
|
||||
|
||||
#endif
|
||||
|
|
|
@ -45,6 +45,61 @@ memcpy (void *dest, const void *src, grub_size_t n)
|
|||
{
|
||||
return grub_memcpy (dest, src, n);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline int
|
||||
memcmp (const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
return grub_memcmp (s1, s2, n);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static inline char *
|
||||
strcpy (char *dest, const char *src)
|
||||
{
|
||||
return grub_strcpy (dest, src);
|
||||
}
|
||||
|
||||
static inline char *
|
||||
strstr (const char *haystack, const char *needle)
|
||||
{
|
||||
return grub_strstr (haystack, needle);
|
||||
}
|
||||
|
||||
static inline char *
|
||||
strchr (const char *s, int c)
|
||||
{
|
||||
return grub_strchr (s, c);
|
||||
}
|
||||
|
||||
static inline char *
|
||||
strncpy (char *dest, const char *src, size_t n)
|
||||
{
|
||||
return grub_strncpy (dest, src, n);
|
||||
}
|
||||
|
||||
static inline char *
|
||||
strcat (char *dest, const char *src)
|
||||
{
|
||||
return grub_strcat (dest, src);
|
||||
}
|
||||
|
||||
static inline char *
|
||||
strncat (char *dest, const char *src, size_t n)
|
||||
{
|
||||
return grub_strncat (dest, src, n);
|
||||
}
|
||||
|
||||
static inline int
|
||||
strcoll (const char *s1, const char *s2)
|
||||
{
|
||||
return grub_strcmp (s1, s2);
|
||||
}
|
||||
|
||||
static inline void *
|
||||
memchr (const void *s, int c, size_t n)
|
||||
{
|
||||
return grub_memchr (s, c, n);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -22,7 +22,11 @@
|
|||
#include <grub/misc.h>
|
||||
|
||||
typedef grub_size_t size_t;
|
||||
typedef grub_ssize_t ssize_t;
|
||||
#ifndef GRUB_POSIX_BOOL_DEFINED
|
||||
typedef enum { false = 0, true = 1 } bool;
|
||||
#define GRUB_POSIX_BOOL_DEFINED 1
|
||||
#endif
|
||||
|
||||
typedef grub_uint8_t uint8_t;
|
||||
typedef grub_uint16_t uint16_t;
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
#include <sys/types.h>
|
|
@ -19,7 +19,97 @@
|
|||
#ifndef GRUB_POSIX_WCHAR_H
|
||||
#define GRUB_POSIX_WCHAR_H 1
|
||||
|
||||
#include <grub/charset.h>
|
||||
|
||||
/* UCS-4. */
|
||||
typedef grub_uint32_t wchar_t;
|
||||
typedef grub_int32_t wint_t;
|
||||
enum
|
||||
{
|
||||
WEOF = -1
|
||||
};
|
||||
|
||||
/* UCS-4. */
|
||||
typedef grub_int32_t wchar_t;
|
||||
|
||||
typedef struct mbstate {
|
||||
grub_uint32_t code;
|
||||
int count;
|
||||
} mbstate_t;
|
||||
|
||||
/* UTF-8. */
|
||||
#define MB_CUR_MAX 4
|
||||
#define MB_LEN_MAX 4
|
||||
|
||||
static inline size_t
|
||||
mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
|
||||
{
|
||||
const char *ptr;
|
||||
if (!s)
|
||||
{
|
||||
pwc = 0;
|
||||
s = "";
|
||||
n = 1;
|
||||
}
|
||||
|
||||
if (pwc)
|
||||
*pwc = 0;
|
||||
|
||||
for (ptr = s; ptr < s + n; ptr++)
|
||||
{
|
||||
if (!grub_utf8_process (*ptr, &ps->code, &ps->count))
|
||||
return -1;
|
||||
if (ps->count)
|
||||
continue;
|
||||
if (pwc)
|
||||
*pwc = ps->code;
|
||||
if (ps->code == 0)
|
||||
return 0;
|
||||
return ptr - s + 1;
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
|
||||
static inline int
|
||||
mbsinit(const mbstate_t *ps)
|
||||
{
|
||||
return ps->count == 0;
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
wcrtomb (char *s, wchar_t wc, mbstate_t *ps __attribute__ ((unused)))
|
||||
{
|
||||
if (s == 0)
|
||||
return 1;
|
||||
return grub_encode_utf8_character ((grub_uint8_t *) s,
|
||||
(grub_uint8_t *) s + MB_LEN_MAX,
|
||||
wc);
|
||||
}
|
||||
|
||||
static inline wint_t btowc (int c)
|
||||
{
|
||||
if (c & ~0x7f)
|
||||
return WEOF;
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
static inline int
|
||||
wcscoll (const wchar_t *s1, const wchar_t *s2)
|
||||
{
|
||||
while (*s1 && *s2)
|
||||
{
|
||||
if (*s1 != *s2)
|
||||
break;
|
||||
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
if (*s1 < *s2)
|
||||
return -1;
|
||||
if (*s1 > *s2)
|
||||
return +1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_POSIX_WCTYPE_H
|
||||
#define GRUB_POSIX_WCTYPE_H 1
|
||||
|
||||
#include <grub/misc.h>
|
||||
#include <wchar.h>
|
||||
|
||||
typedef enum { GRUB_CTYPE_INVALID,
|
||||
GRUB_CTYPE_ALNUM, GRUB_CTYPE_CNTRL, GRUB_CTYPE_LOWER,
|
||||
GRUB_CTYPE_SPACE, GRUB_CTYPE_ALPHA, GRUB_CTYPE_DIGIT,
|
||||
GRUB_CTYPE_PRINT, GRUB_CTYPE_UPPER, GRUB_CTYPE_BLANK,
|
||||
GRUB_CTYPE_GRAPH, GRUB_CTYPE_PUNCT, GRUB_CTYPE_XDIGIT,
|
||||
GRUB_CTYPE_MAX} wctype_t;
|
||||
|
||||
#define CHARCLASS_NAME_MAX (sizeof ("xdigit") - 1)
|
||||
|
||||
static inline wctype_t
|
||||
wctype (const char *name)
|
||||
{
|
||||
wctype_t i;
|
||||
static const char names[][10] = { "",
|
||||
"alnum", "cntrl", "lower",
|
||||
"space", "alpha", "digit",
|
||||
"print", "upper", "blank",
|
||||
"graph", "punct", "xdigit" };
|
||||
for (i = GRUB_CTYPE_INVALID; i < GRUB_CTYPE_MAX; i++)
|
||||
if (grub_strcmp (names[i], name) == 0)
|
||||
return i;
|
||||
return GRUB_CTYPE_INVALID;
|
||||
}
|
||||
|
||||
/* FIXME: take into account international lowercase characters. */
|
||||
static inline int
|
||||
iswlower (wint_t wc)
|
||||
{
|
||||
return grub_islower (wc);
|
||||
}
|
||||
|
||||
static inline wint_t
|
||||
towlower (wint_t c)
|
||||
{
|
||||
return grub_tolower (c);
|
||||
}
|
||||
|
||||
static inline wint_t
|
||||
towupper (wint_t c)
|
||||
{
|
||||
return grub_toupper (c);
|
||||
}
|
||||
|
||||
static inline int
|
||||
iswalnum (wint_t c)
|
||||
{
|
||||
return grub_isalpha (c) || grub_isdigit (c);
|
||||
}
|
||||
|
||||
static inline int
|
||||
iswctype (wint_t wc, wctype_t desc)
|
||||
{
|
||||
switch (desc)
|
||||
{
|
||||
case GRUB_CTYPE_ALNUM:
|
||||
return iswalnum (wc);
|
||||
case GRUB_CTYPE_CNTRL:
|
||||
return grub_iscntrl (wc);
|
||||
case GRUB_CTYPE_LOWER:
|
||||
return iswlower (wc);
|
||||
case GRUB_CTYPE_SPACE:
|
||||
return grub_isspace (wc);
|
||||
case GRUB_CTYPE_ALPHA:
|
||||
return grub_isalpha (wc);
|
||||
case GRUB_CTYPE_DIGIT:
|
||||
return grub_isdigit (wc);
|
||||
case GRUB_CTYPE_PRINT:
|
||||
return grub_isprint (wc);
|
||||
case GRUB_CTYPE_UPPER:
|
||||
return grub_isupper (wc);
|
||||
case GRUB_CTYPE_BLANK:
|
||||
return wc == ' ' || wc == '\t';
|
||||
case GRUB_CTYPE_GRAPH:
|
||||
return grub_isgraph (wc);
|
||||
case GRUB_CTYPE_PUNCT:
|
||||
return grub_isprint (wc) && !grub_isspace (wc) && !iswalnum (wc);
|
||||
case GRUB_CTYPE_XDIGIT:
|
||||
return grub_isxdigit (wc);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
257
grub-core/lib/priority_queue.c
Normal file
257
grub-core/lib/priority_queue.c
Normal file
|
@ -0,0 +1,257 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2011 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TEST
|
||||
#include <grub/priority_queue.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/dl.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <queue>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef size_t grub_size_t;
|
||||
typedef int (*grub_comparator_t) (const void *a, const void *b);
|
||||
typedef unsigned char grub_uint8_t;
|
||||
#define grub_malloc malloc
|
||||
#define grub_memcpy memcpy
|
||||
#define grub_realloc realloc
|
||||
#define grub_free free
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GRUB_ERR_NONE,
|
||||
grub_errno
|
||||
} grub_err_t;
|
||||
#endif
|
||||
|
||||
struct grub_priority_queue
|
||||
{
|
||||
grub_size_t elsize;
|
||||
grub_size_t allocated;
|
||||
grub_size_t used;
|
||||
grub_comparator_t cmp;
|
||||
void *els;
|
||||
};
|
||||
|
||||
#ifdef TEST
|
||||
typedef struct grub_priority_queue *grub_priority_queue_t;
|
||||
#endif
|
||||
|
||||
static inline void *
|
||||
element (struct grub_priority_queue *pq, grub_size_t k)
|
||||
{
|
||||
return ((grub_uint8_t *) pq->els) + k * pq->elsize;
|
||||
}
|
||||
|
||||
static inline void
|
||||
swap (struct grub_priority_queue *pq, grub_size_t m, grub_size_t n)
|
||||
{
|
||||
grub_uint8_t *p1, *p2;
|
||||
grub_size_t l;
|
||||
p1 = (grub_uint8_t *) element (pq, m);
|
||||
p2 = (grub_uint8_t *) element (pq, n);
|
||||
for (l = pq->elsize; l; l--, p1++, p2++)
|
||||
{
|
||||
grub_uint8_t t;
|
||||
t = *p1;
|
||||
*p1 = *p2;
|
||||
*p2 = t;
|
||||
}
|
||||
}
|
||||
|
||||
static inline grub_size_t
|
||||
parent (grub_size_t v)
|
||||
{
|
||||
return (v - 1) / 2;
|
||||
}
|
||||
|
||||
static inline grub_size_t
|
||||
left_child (grub_size_t v)
|
||||
{
|
||||
return 2 * v + 1;
|
||||
}
|
||||
|
||||
static inline grub_size_t
|
||||
right_child (grub_size_t v)
|
||||
{
|
||||
return 2 * v + 2;
|
||||
}
|
||||
|
||||
void *
|
||||
grub_priority_queue_top (grub_priority_queue_t pq)
|
||||
{
|
||||
if (!pq->used)
|
||||
return 0;
|
||||
return element (pq, 0);
|
||||
}
|
||||
|
||||
void
|
||||
grub_priority_queue_destroy (grub_priority_queue_t pq)
|
||||
{
|
||||
grub_free (pq->els);
|
||||
grub_free (pq);
|
||||
}
|
||||
|
||||
grub_priority_queue_t
|
||||
grub_priority_queue_new (grub_size_t elsize,
|
||||
grub_comparator_t cmp)
|
||||
{
|
||||
struct grub_priority_queue *ret;
|
||||
void *els;
|
||||
els = grub_malloc (elsize * 8);
|
||||
if (!els)
|
||||
return 0;
|
||||
ret = (struct grub_priority_queue *) grub_malloc (sizeof (*ret));
|
||||
if (!ret)
|
||||
{
|
||||
grub_free (els);
|
||||
return 0;
|
||||
}
|
||||
ret->elsize = elsize;
|
||||
ret->allocated = 8;
|
||||
ret->used = 0;
|
||||
ret->cmp = cmp;
|
||||
ret->els = els;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Heap property: pq->cmp (element (pq, p), element (pq, parent (p))) <= 0. */
|
||||
grub_err_t
|
||||
grub_priority_queue_push (grub_priority_queue_t pq, const void *el)
|
||||
{
|
||||
grub_size_t p;
|
||||
if (pq->used == pq->allocated)
|
||||
{
|
||||
void *els;
|
||||
els = grub_realloc (pq->els, pq->elsize * 2 * pq->allocated);
|
||||
if (!els)
|
||||
return grub_errno;
|
||||
pq->allocated *= 2;
|
||||
pq->els = els;
|
||||
}
|
||||
pq->used++;
|
||||
grub_memcpy (element (pq, pq->used - 1), el, pq->elsize);
|
||||
for (p = pq->used - 1; p; p = parent (p))
|
||||
{
|
||||
if (pq->cmp (element (pq, p), element (pq, parent (p))) <= 0)
|
||||
break;
|
||||
swap (pq, p, parent (p));
|
||||
}
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
void
|
||||
grub_priority_queue_pop (grub_priority_queue_t pq)
|
||||
{
|
||||
grub_size_t p;
|
||||
|
||||
swap (pq, 0, pq->used - 1);
|
||||
pq->used--;
|
||||
for (p = 0; left_child (p) < pq->used; )
|
||||
{
|
||||
grub_size_t c;
|
||||
if (pq->cmp (element (pq, left_child (p)), element (pq, p)) <= 0
|
||||
&& (right_child (p) >= pq->used
|
||||
|| pq->cmp (element (pq, right_child (p)), element (pq, p)) <= 0))
|
||||
break;
|
||||
if (right_child (p) >= pq->used
|
||||
|| pq->cmp (element (pq, left_child (p)),
|
||||
element (pq, right_child (p))) > 0)
|
||||
c = left_child (p);
|
||||
else
|
||||
c = right_child (p);
|
||||
swap (pq, p, c);
|
||||
p = c;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
static int
|
||||
compar (const void *a_, const void *b_)
|
||||
{
|
||||
int a = *(int *) a_;
|
||||
int b = *(int *) b_;
|
||||
if (a < b)
|
||||
return -1;
|
||||
if (a > b)
|
||||
return +1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
priority_queue <int> pq;
|
||||
grub_priority_queue_t pq2;
|
||||
int counter;
|
||||
int s = 0;
|
||||
pq2 = grub_priority_queue_new (sizeof (int), compar);
|
||||
if (!pq2)
|
||||
return 1;
|
||||
srand (1);
|
||||
|
||||
for (counter = 0; counter < 1000000; counter++)
|
||||
{
|
||||
int op = rand () % 10;
|
||||
if (s && *(int *) grub_priority_queue_top (pq2) != pq.top ())
|
||||
{
|
||||
printf ("Error at %d\n", counter);
|
||||
return 2;
|
||||
}
|
||||
if (op < 3 && s)
|
||||
{
|
||||
grub_priority_queue_pop (pq2);
|
||||
pq.pop ();
|
||||
s--;
|
||||
}
|
||||
else
|
||||
{
|
||||
int v = rand ();
|
||||
int e;
|
||||
pq.push (v);
|
||||
e = grub_priority_queue_push (pq2, &v);
|
||||
if (e)
|
||||
return 3;
|
||||
s++;
|
||||
}
|
||||
}
|
||||
while (s)
|
||||
{
|
||||
if (*(int *) grub_priority_queue_top (pq2) != pq.top ())
|
||||
{
|
||||
printf ("Error at the end. %d elements remaining.\n", s);
|
||||
return 4;
|
||||
}
|
||||
grub_priority_queue_pop (pq2);
|
||||
pq.pop ();
|
||||
s--;
|
||||
}
|
||||
printf ("All tests passed successfully\n");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
|
@ -25,6 +25,10 @@
|
|||
#define grub_memcpy memcpy
|
||||
#endif
|
||||
|
||||
#ifndef STANDALONE
|
||||
#include <assert.h>
|
||||
#endif
|
||||
|
||||
#ifndef STANDALONE
|
||||
#ifdef TEST
|
||||
typedef unsigned int grub_size_t;
|
||||
|
@ -37,6 +41,9 @@ typedef unsigned char grub_uint8_t;
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#define SECTOR_SIZE 512
|
||||
#define MAX_BLOCK_SIZE (200 * SECTOR_SIZE)
|
||||
|
||||
#ifdef STANDALONE
|
||||
#ifdef TEST
|
||||
typedef unsigned int grub_size_t;
|
||||
|
@ -56,19 +63,29 @@ typedef grub_uint8_t gf_single_t;
|
|||
#if defined (STANDALONE) && !defined (TEST)
|
||||
static gf_single_t * const gf_powx __attribute__ ((section(".text"))) = (void *) 0x100000;
|
||||
static gf_single_t * const gf_powx_inv __attribute__ ((section(".text"))) = (void *) 0x100200;
|
||||
|
||||
static char *scratch __attribute__ ((section(".text"))) = (void *) 0x100300;
|
||||
static int *const chosenstat __attribute__ ((section(".text"))) = (void *) 0x100300;
|
||||
static gf_single_t *const sigma __attribute__ ((section(".text"))) = (void *) 0x100700;
|
||||
static gf_single_t *const errpot __attribute__ ((section(".text"))) = (void *) 0x100800;
|
||||
static int *const errpos __attribute__ ((section(".text"))) = (void *) 0x100900;
|
||||
static gf_single_t *const sy __attribute__ ((section(".text"))) = (void *) 0x100d00;
|
||||
static gf_single_t *const mstat __attribute__ ((section(".text"))) = (void *) 0x100e00;
|
||||
static gf_single_t *const errvals __attribute__ ((section(".text"))) = (void *) 0x100f00;
|
||||
static gf_single_t *const eqstat __attribute__ ((section(".text"))) = (void *) 0x101000;
|
||||
/* Next available address: (void *) 0x112000. */
|
||||
#else
|
||||
#if defined (STANDALONE)
|
||||
static char *scratch;
|
||||
#endif
|
||||
|
||||
static gf_single_t gf_powx[255 * 2];
|
||||
static gf_single_t gf_powx_inv[256];
|
||||
static int chosenstat[256];
|
||||
static gf_single_t sigma[256];
|
||||
static gf_single_t errpot[256];
|
||||
static int errpos[256];
|
||||
static gf_single_t sy[256];
|
||||
static gf_single_t mstat[256];
|
||||
static gf_single_t errvals[256];
|
||||
static gf_single_t eqstat[65536 + 256];
|
||||
#endif
|
||||
|
||||
#define SECTOR_SIZE 512
|
||||
#define MAX_BLOCK_SIZE (200 * SECTOR_SIZE)
|
||||
|
||||
static gf_single_t
|
||||
gf_mul (gf_single_t a, gf_single_t b)
|
||||
{
|
||||
|
@ -89,6 +106,7 @@ init_powx (void)
|
|||
int i;
|
||||
grub_uint8_t cur = 1;
|
||||
|
||||
gf_powx_inv[0] = 0;
|
||||
for (i = 0; i < 255; i++)
|
||||
{
|
||||
gf_powx[i] = cur;
|
||||
|
@ -102,14 +120,11 @@ init_powx (void)
|
|||
}
|
||||
|
||||
static gf_single_t
|
||||
pol_evaluate (gf_single_t *pol, grub_size_t degree, gf_single_t x)
|
||||
pol_evaluate (gf_single_t *pol, grub_size_t degree, int log_x)
|
||||
{
|
||||
int i;
|
||||
gf_single_t s = 0;
|
||||
int log_xn = 0, log_x;
|
||||
if (x == 0)
|
||||
return pol[0];
|
||||
log_x = gf_powx_inv[x];
|
||||
int log_xn = 0;
|
||||
for (i = degree; i >= 0; i--)
|
||||
{
|
||||
if (pol[i])
|
||||
|
@ -159,25 +174,6 @@ rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs)
|
|||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
syndroms (gf_single_t *m, grub_size_t s, grub_size_t rs,
|
||||
gf_single_t *sy)
|
||||
{
|
||||
gf_single_t xn = 1;
|
||||
unsigned i;
|
||||
for (i = 0; i < rs; i++)
|
||||
{
|
||||
if (xn & (1 << (GF_SIZE - 1)))
|
||||
{
|
||||
xn <<= 1;
|
||||
xn ^= GF_POLYNOMIAL;
|
||||
}
|
||||
else
|
||||
xn <<= 1;
|
||||
sy[i] = pol_evaluate (m, s + rs - 1, xn);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gauss_eliminate (gf_single_t *eq, int n, int m, int *chosen)
|
||||
{
|
||||
|
@ -208,65 +204,34 @@ gauss_eliminate (gf_single_t *eq, int n, int m, int *chosen)
|
|||
static void
|
||||
gauss_solve (gf_single_t *eq, int n, int m, gf_single_t *sol)
|
||||
{
|
||||
int *chosen;
|
||||
int i, j;
|
||||
|
||||
#ifndef STANDALONE
|
||||
chosen = xmalloc (n * sizeof (int));
|
||||
#else
|
||||
chosen = (void *) scratch;
|
||||
scratch += n * sizeof (int);
|
||||
#endif
|
||||
for (i = 0; i < n; i++)
|
||||
chosen[i] = -1;
|
||||
chosenstat[i] = -1;
|
||||
for (i = 0; i < m; i++)
|
||||
sol[i] = 0;
|
||||
gauss_eliminate (eq, n, m, chosen);
|
||||
gauss_eliminate (eq, n, m, chosenstat);
|
||||
for (i = n - 1; i >= 0; i--)
|
||||
{
|
||||
gf_single_t s = 0;
|
||||
if (chosen[i] == -1)
|
||||
if (chosenstat[i] == -1)
|
||||
continue;
|
||||
for (j = 0; j < m; j++)
|
||||
s ^= gf_mul (eq[i * (m + 1) + j], sol[j]);
|
||||
s ^= eq[i * (m + 1) + m];
|
||||
sol[chosen[i]] = s;
|
||||
sol[chosenstat[i]] = s;
|
||||
}
|
||||
#ifndef STANDALONE
|
||||
free (chosen);
|
||||
#else
|
||||
scratch -= n * sizeof (int);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
rs_recover (gf_single_t *m, grub_size_t s, grub_size_t rs)
|
||||
rs_recover (gf_single_t *mm, grub_size_t s, grub_size_t rs)
|
||||
{
|
||||
grub_size_t rs2 = rs / 2;
|
||||
gf_single_t *sigma;
|
||||
gf_single_t *errpot;
|
||||
int *errpos;
|
||||
gf_single_t *sy;
|
||||
int errnum = 0;
|
||||
int i, j;
|
||||
|
||||
#ifndef STANDALONE
|
||||
sigma = xmalloc (rs2 * sizeof (gf_single_t));
|
||||
errpot = xmalloc (rs2 * sizeof (gf_single_t));
|
||||
errpos = xmalloc (rs2 * sizeof (int));
|
||||
sy = xmalloc (rs * sizeof (gf_single_t));
|
||||
#else
|
||||
sigma = (void *) scratch;
|
||||
scratch += rs2 * sizeof (gf_single_t);
|
||||
errpot = (void *) scratch;
|
||||
scratch += rs2 * sizeof (gf_single_t);
|
||||
errpos = (void *) scratch;
|
||||
scratch += rs2 * sizeof (int);
|
||||
sy = (void *) scratch;
|
||||
scratch += rs * sizeof (gf_single_t);
|
||||
#endif
|
||||
|
||||
syndroms (m, s, rs, sy);
|
||||
for (i = 0; i < (int) rs; i++)
|
||||
sy[i] = pol_evaluate (mm, s + rs - 1, i);
|
||||
|
||||
for (i = 0; i < (int) rs; i++)
|
||||
if (sy[i] != 0)
|
||||
|
@ -274,109 +239,44 @@ rs_recover (gf_single_t *m, grub_size_t s, grub_size_t rs)
|
|||
|
||||
/* No error detected. */
|
||||
if (i == (int) rs)
|
||||
{
|
||||
#ifndef STANDALONE
|
||||
free (sigma);
|
||||
free (errpot);
|
||||
free (errpos);
|
||||
free (sy);
|
||||
#else
|
||||
scratch -= rs2 * sizeof (gf_single_t);
|
||||
scratch -= rs2 * sizeof (gf_single_t);
|
||||
scratch -= rs2 * sizeof (int);
|
||||
scratch -= rs * sizeof (gf_single_t);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
return;
|
||||
|
||||
{
|
||||
gf_single_t *eq;
|
||||
|
||||
#ifndef STANDALONE
|
||||
eq = xmalloc (rs2 * (rs2 + 1) * sizeof (gf_single_t));
|
||||
#else
|
||||
eq = (void *) scratch;
|
||||
scratch += rs2 * (rs2 + 1) * sizeof (gf_single_t);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < (int) rs2; i++)
|
||||
for (j = 0; j < (int) rs2 + 1; j++)
|
||||
eq[i * (rs2 + 1) + j] = sy[i+j];
|
||||
eqstat[i * (rs2 + 1) + j] = sy[i+j];
|
||||
|
||||
for (i = 0; i < (int) rs2; i++)
|
||||
sigma[i] = 0;
|
||||
|
||||
gauss_solve (eq, rs2, rs2, sigma);
|
||||
|
||||
#ifndef STANDALONE
|
||||
free (eq);
|
||||
#else
|
||||
scratch -= rs2 * (rs2 + 1) * sizeof (gf_single_t);
|
||||
#endif
|
||||
gauss_solve (eqstat, rs2, rs2, sigma);
|
||||
}
|
||||
|
||||
{
|
||||
gf_single_t xn = 1, yn = 1;
|
||||
for (i = 0; i < (int) (rs + s); i++)
|
||||
for (i = 0; i < (int) (rs + s); i++)
|
||||
if (pol_evaluate (sigma, rs2 - 1, 255 - i) == gf_powx[i])
|
||||
{
|
||||
gf_single_t ev = (gf_mul (pol_evaluate (sigma, rs2 - 1, xn), xn) ^ 1);
|
||||
if (ev == 0)
|
||||
{
|
||||
errpot[errnum] = yn;
|
||||
errpos[errnum++] = s + rs - i - 1;
|
||||
}
|
||||
yn = gf_mul (yn, 2);
|
||||
xn = gf_mul (xn, GF_INVERT2);
|
||||
errpot[errnum] = gf_powx[i];
|
||||
errpos[errnum++] = s + rs - i - 1;
|
||||
}
|
||||
}
|
||||
{
|
||||
gf_single_t *errvals;
|
||||
gf_single_t *eq;
|
||||
|
||||
#ifndef STANDALONE
|
||||
eq = xmalloc (rs * (errnum + 1) * sizeof (gf_single_t));
|
||||
errvals = xmalloc (errnum * sizeof (int));
|
||||
#else
|
||||
eq = (void *) scratch;
|
||||
scratch += rs * (errnum + 1) * sizeof (gf_single_t);
|
||||
errvals = (void *) scratch;
|
||||
scratch += errnum * sizeof (int);
|
||||
#endif
|
||||
|
||||
for (j = 0; j < errnum; j++)
|
||||
eq[j] = errpot[j];
|
||||
eq[errnum] = sy[0];
|
||||
eqstat[j] = 1;
|
||||
eqstat[errnum] = sy[0];
|
||||
for (i = 1; i < (int) rs; i++)
|
||||
{
|
||||
for (j = 0; j < (int) errnum; j++)
|
||||
eq[(errnum + 1) * i + j] = gf_mul (errpot[j],
|
||||
eq[(errnum + 1) * (i - 1) + j]);
|
||||
eq[(errnum + 1) * i + errnum] = sy[i];
|
||||
eqstat[(errnum + 1) * i + j] = gf_mul (errpot[j],
|
||||
eqstat[(errnum + 1) * (i - 1)
|
||||
+ j]);
|
||||
eqstat[(errnum + 1) * i + errnum] = sy[i];
|
||||
}
|
||||
|
||||
gauss_solve (eq, rs, errnum, errvals);
|
||||
gauss_solve (eqstat, rs, errnum, errvals);
|
||||
|
||||
for (i = 0; i < (int) errnum; i++)
|
||||
m[errpos[i]] ^= errvals[i];
|
||||
#ifndef STANDALONE
|
||||
free (eq);
|
||||
free (errvals);
|
||||
#else
|
||||
scratch -= rs * (errnum + 1) * sizeof (gf_single_t);
|
||||
scratch -= errnum * sizeof (int);
|
||||
#endif
|
||||
mm[errpos[i]] ^= errvals[i];
|
||||
}
|
||||
#ifndef STANDALONE
|
||||
free (sigma);
|
||||
free (errpot);
|
||||
free (errpos);
|
||||
free (sy);
|
||||
#else
|
||||
scratch -= rs2 * sizeof (gf_single_t);
|
||||
scratch -= rs2 * sizeof (gf_single_t);
|
||||
scratch -= rs2 * sizeof (int);
|
||||
scratch -= rs * sizeof (gf_single_t);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -388,21 +288,20 @@ decode_block (gf_single_t *ptr, grub_size_t s,
|
|||
{
|
||||
grub_size_t ds = (s + SECTOR_SIZE - 1 - i) / SECTOR_SIZE;
|
||||
grub_size_t rr = (rs + SECTOR_SIZE - 1 - i) / SECTOR_SIZE;
|
||||
gf_single_t m[ds + rr];
|
||||
|
||||
/* Nothing to do. */
|
||||
if (!ds || !rr)
|
||||
continue;
|
||||
|
||||
for (j = 0; j < (int) ds; j++)
|
||||
m[j] = ptr[SECTOR_SIZE * j + i];
|
||||
mstat[j] = ptr[SECTOR_SIZE * j + i];
|
||||
for (j = 0; j < (int) rr; j++)
|
||||
m[j + ds] = rptr[SECTOR_SIZE * j + i];
|
||||
mstat[j + ds] = rptr[SECTOR_SIZE * j + i];
|
||||
|
||||
rs_recover (m, ds, rr);
|
||||
rs_recover (mstat, ds, rr);
|
||||
|
||||
for (j = 0; j < (int) ds; j++)
|
||||
ptr[SECTOR_SIZE * j + i] = m[j];
|
||||
ptr[SECTOR_SIZE * j + i] = mstat[j];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -416,12 +315,18 @@ encode_block (gf_single_t *ptr, grub_size_t s,
|
|||
{
|
||||
grub_size_t ds = (s + SECTOR_SIZE - 1 - i) / SECTOR_SIZE;
|
||||
grub_size_t rr = (rs + SECTOR_SIZE - 1 - i) / SECTOR_SIZE;
|
||||
gf_single_t m[ds + rr];
|
||||
gf_single_t *m;
|
||||
|
||||
if (!ds || !rr)
|
||||
continue;
|
||||
|
||||
m = xmalloc (ds + rr);
|
||||
for (j = 0; j < ds; j++)
|
||||
m[j] = ptr[SECTOR_SIZE * j + i];
|
||||
rs_encode (m, ds, rr);
|
||||
for (j = 0; j < rr; j++)
|
||||
rptr[SECTOR_SIZE * j + i] = m[j + ds];
|
||||
free (m);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -435,6 +340,10 @@ grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size,
|
|||
grub_size_t rs = redundancy;
|
||||
gf_single_t *ptr = buffer;
|
||||
gf_single_t *rptr = ptr + s;
|
||||
void *tmp;
|
||||
|
||||
tmp = xmalloc (data_size);
|
||||
grub_memcpy (tmp, buffer, data_size);
|
||||
|
||||
/* Nothing to do. */
|
||||
if (!rs)
|
||||
|
@ -460,6 +369,11 @@ grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size,
|
|||
s -= cs;
|
||||
rs -= crs;
|
||||
}
|
||||
|
||||
#ifndef TEST
|
||||
assert (grub_memcmp (tmp, buffer, data_size) == 0);
|
||||
#endif
|
||||
free (tmp);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -506,14 +420,11 @@ main (int argc, char **argv)
|
|||
grub_memset (gf_powx, 0xee, sizeof (gf_powx));
|
||||
grub_memset (gf_powx_inv, 0xdd, sizeof (gf_powx_inv));
|
||||
|
||||
#ifdef STANDALONE
|
||||
scratch = xmalloc (1048576);
|
||||
#endif
|
||||
|
||||
#ifndef STANDALONE
|
||||
init_powx ();
|
||||
#endif
|
||||
|
||||
#ifndef STANDALONE
|
||||
in = fopen ("tst.bin", "rb");
|
||||
if (!in)
|
||||
return 1;
|
||||
|
@ -530,7 +441,19 @@ main (int argc, char **argv)
|
|||
out = fopen ("tst_rs.bin", "wb");
|
||||
fwrite (buf, 1, s + rs, out);
|
||||
fclose (out);
|
||||
#if 0
|
||||
#else
|
||||
out = fopen ("tst_rs.bin", "rb");
|
||||
fseek (out, 0, SEEK_END);
|
||||
s = ftell (out);
|
||||
fseek (out, 0, SEEK_SET);
|
||||
rs = 0x7007;
|
||||
s -= rs;
|
||||
|
||||
buf = xmalloc (s + rs + SECTOR_SIZE);
|
||||
fread (buf, 1, s + rs, out);
|
||||
fclose (out);
|
||||
#endif
|
||||
#if 1
|
||||
grub_memset (buf + 512 * 15, 0, 512);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <grub/cache.h>
|
||||
#include <grub/memory.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
|
@ -524,9 +525,11 @@ malloc_in_range (struct grub_relocator *rel,
|
|||
#if GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS
|
||||
for (r = grub_mm_base; r; r = r->next)
|
||||
{
|
||||
#ifdef DEBUG_RELOCATOR_NOMEM_DPRINTF
|
||||
grub_dprintf ("relocator", "Blocking at 0x%lx-0x%lx\n",
|
||||
(unsigned long) r - r->pre_size,
|
||||
(unsigned long) (r + 1) + r->size);
|
||||
#endif
|
||||
events[N].type = FIRMWARE_BLOCK_START;
|
||||
events[N].pos = (grub_addr_t) r - r->pre_size;
|
||||
N++;
|
||||
|
@ -538,8 +541,10 @@ malloc_in_range (struct grub_relocator *rel,
|
|||
struct grub_relocator_extra_block *cur;
|
||||
for (cur = extra_blocks; cur; cur = cur->next)
|
||||
{
|
||||
#ifdef DEBUG_RELOCATOR_NOMEM_DPRINTF
|
||||
grub_dprintf ("relocator", "Blocking at 0x%lx-0x%lx\n",
|
||||
(unsigned long) cur->start, (unsigned long) cur->end);
|
||||
#endif
|
||||
events[N].type = FIRMWARE_BLOCK_START;
|
||||
events[N].pos = cur->start;
|
||||
N++;
|
||||
|
@ -1204,14 +1209,14 @@ grub_relocator_alloc_chunk_addr (struct grub_relocator *rel,
|
|||
grub_phys_addr_t min_addr = 0, max_addr;
|
||||
|
||||
if (target > ~size)
|
||||
return grub_error (GRUB_ERR_OUT_OF_RANGE, "address is out of range");
|
||||
return grub_error (GRUB_ERR_BUG, "address is out of range");
|
||||
|
||||
adjust_limits (rel, &min_addr, &max_addr, target, target);
|
||||
|
||||
for (chunk = rel->chunks; chunk; chunk = chunk->next)
|
||||
if ((chunk->target <= target && target < chunk->target + chunk->size)
|
||||
|| (target <= chunk->target && chunk->target < target + size))
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "overlap detected");
|
||||
return grub_error (GRUB_ERR_BUG, "overlap detected");
|
||||
|
||||
chunk = grub_malloc (sizeof (struct grub_relocator_chunk));
|
||||
if (!chunk)
|
||||
|
@ -1251,7 +1256,7 @@ grub_relocator_alloc_chunk_addr (struct grub_relocator *rel,
|
|||
|
||||
grub_dprintf ("relocator", "not allocated\n");
|
||||
grub_free (chunk);
|
||||
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
|
||||
return grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
||||
}
|
||||
while (0);
|
||||
|
||||
|
@ -1361,7 +1366,7 @@ grub_relocator_alloc_chunk_align (struct grub_relocator *rel,
|
|||
break;
|
||||
}
|
||||
|
||||
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
|
||||
return grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
||||
}
|
||||
while (0);
|
||||
|
||||
|
@ -1481,7 +1486,7 @@ grub_relocator_prepare_relocs (struct grub_relocator *rel, grub_addr_t addr,
|
|||
if (!malloc_in_range (rel, 0, ~(grub_addr_t)0 - rel->relocators_size + 1,
|
||||
grub_relocator_align,
|
||||
rel->relocators_size, &movers_chunk, 1, 1))
|
||||
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
|
||||
return grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
||||
movers_chunk.srcv = rels = rels0
|
||||
= grub_map_memory (movers_chunk.src, movers_chunk.size);
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include "./sparc64/setjmp.S"
|
||||
#elif defined(__mips__)
|
||||
#include "./mips/setjmp.S"
|
||||
#elif defined(__powerpc__)
|
||||
#elif defined(__powerpc__) || defined(__PPC__)
|
||||
#include "./powerpc/setjmp.S"
|
||||
#elif defined(__ia64__)
|
||||
#include "./ia64/setjmp.S"
|
||||
|
|
|
@ -25,6 +25,13 @@
|
|||
#define XZ_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <grub/misc.h>
|
||||
|
||||
#ifndef GRUB_POSIX_BOOL_DEFINED
|
||||
typedef enum { false = 0, true = 1 } bool;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* enum xz_ret - Return codes
|
||||
|
|
|
@ -26,27 +26,27 @@
|
|||
|
||||
/* Enable BCJ filter decoders. */
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
#if defined(GRUB_TARGET_CPU_I386) || defined(GRUB_TARGET_CPU_X86_64)
|
||||
#define XZ_DEC_X86
|
||||
#endif
|
||||
|
||||
#ifdef __powerpc__
|
||||
#ifdef GRUB_TARGET_CPU_POWERPC
|
||||
#define XZ_DEC_POWERPC
|
||||
#endif
|
||||
|
||||
#ifdef __ia64__
|
||||
#ifdef GRUB_TARGET_CPU_IA64
|
||||
#define XZ_DEC_IA64
|
||||
#endif
|
||||
|
||||
#ifdef __arm__
|
||||
#ifdef GRUB_TARGET_CPU_ARM
|
||||
#define XZ_DEC_ARM
|
||||
#endif
|
||||
|
||||
#ifdef __thumb__
|
||||
#if 0
|
||||
#define XZ_DEC_ARMTHUMB
|
||||
#endif
|
||||
|
||||
#ifdef __sparc__
|
||||
#ifdef GRUB_TARGET_CPU_SPARC
|
||||
#define XZ_DEC_SPARC
|
||||
#endif
|
||||
|
||||
|
|
|
@ -445,6 +445,8 @@ static enum xz_ret dec_stream_header(struct xz_dec *s)
|
|||
return XZ_FORMAT_ERROR;
|
||||
|
||||
#ifndef GRUB_EMBED_DECOMPRESSOR
|
||||
s->crc32 = grub_crypto_lookup_md_by_name ("CRC32");
|
||||
|
||||
if (s->crc32)
|
||||
{
|
||||
uint64_t hash_context[(s->crc32->contextsize + 7) / 8];
|
||||
|
@ -958,10 +960,6 @@ struct xz_dec * xz_dec_init(uint32_t dict_max)
|
|||
|
||||
memset (s, 0, sizeof (*s));
|
||||
|
||||
#ifndef GRUB_EMBED_DECOMPRESSOR
|
||||
s->crc32 = grub_crypto_lookup_md_by_name ("CRC32");
|
||||
#endif
|
||||
|
||||
s->single_call = dict_max == 0;
|
||||
|
||||
#ifdef XZ_DEC_BCJ
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue