fix signess, optimize codes

Signed-off-by: Sergey Isakov <isakov-sl@bk.ru>
This commit is contained in:
Sergey Isakov 2020-02-23 08:53:21 +03:00
parent 3933f80eb2
commit c35f9aa052
6 changed files with 48 additions and 137 deletions

View File

@ -15,7 +15,6 @@
12AAF3A51DB75DC800A52B12 /* FirmwareVolume.c in Sources */ = {isa = PBXBuildFile; fileRef = 12AAF3A41DB75DC800A52B12 /* FirmwareVolume.c */; };
2C794E3F1A0AA85900D845B0 /* FSInject.c in Sources */ = {isa = PBXBuildFile; fileRef = 2C794CEA1A0AA85900D845B0 /* FSInject.c */; };
2C794E401A0AA85900D845B0 /* Test.c in Sources */ = {isa = PBXBuildFile; fileRef = 2C794CF11A0AA85900D845B0 /* Test.c */; };
A5456CD723FC5A88000BF18C /* uefibootoption.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5456CC523FC5A81000BF18C /* uefibootoption.cpp */; };
A5456CD823FC5A88000BF18C /* securemenu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5456CC623FC5A81000BF18C /* securemenu.cpp */; };
A5456CD923FC5A88000BF18C /* securehash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5456CC723FC5A82000BF18C /* securehash.cpp */; };
A5456CDA23FC5A88000BF18C /* securevars.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5456CC823FC5A82000BF18C /* securevars.cpp */; };
@ -2272,7 +2271,6 @@
A51F63CB22DFB86F00086DB7 /* ApplePartitionInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ApplePartitionInfo.h; sourceTree = "<group>"; };
A5429219233538250001F42A /* Clover */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Clover; sourceTree = BUILT_PRODUCTS_DIR; };
A5456CC423FC5A81000BF18C /* CanonicalDB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CanonicalDB.h; sourceTree = "<group>"; };
A5456CC523FC5A81000BF18C /* uefibootoption.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = uefibootoption.cpp; sourceTree = "<group>"; };
A5456CC623FC5A81000BF18C /* securemenu.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = securemenu.cpp; sourceTree = "<group>"; };
A5456CC723FC5A82000BF18C /* securehash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = securehash.cpp; sourceTree = "<group>"; };
A5456CC823FC5A82000BF18C /* securevars.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = securevars.cpp; sourceTree = "<group>"; };
@ -6058,7 +6056,6 @@
A5456CC623FC5A81000BF18C /* securemenu.cpp */,
A5456CC823FC5A82000BF18C /* securevars.cpp */,
A5456CCE23FC5A84000BF18C /* tool.cpp */,
A5456CC523FC5A81000BF18C /* uefibootoption.cpp */,
);
path = entry_scan;
sourceTree = "<group>";
@ -16553,7 +16550,6 @@
A5AAFC0B237F13B3009CD413 /* NullMemoryTest.c in Sources */,
A5AA06E3237F13C2009CD413 /* DevicePathToText.c in Sources */,
A5AAFBF7237F13B3009CD413 /* DiskIo.c in Sources */,
A5456CD723FC5A88000BF18C /* uefibootoption.cpp in Sources */,
A5AAFCC3237F13B4009CD413 /* UsbHub.c in Sources */,
A5AAFC7D237F13B4009CD413 /* NvmExpressPeiStorageSecurity.c in Sources */,
A5AAFCE9237F13B4009CD413 /* DxeCapsuleProcessLib.c in Sources */,

View File

@ -214,6 +214,7 @@ static struct FIX_CONFIG { const CHAR8* oldName; const CHAR8* newName; UINT32 bi
while (AsmReadMsr64(MSR_IA32_PERF_STATUS) & (1 << 21)) { if (!inline_timeout--) break; }
}
*/
#if 0
UINT32
GetCrc32 (
UINT8 *Buffer,
@ -239,6 +240,21 @@ GetCrc32 (
return x;
}
#else //nice programming
UINT32
GetCrc32 (
UINT8 *Buffer,
UINTN Size
)
{
UINT32 x = 0;
UINT32 *Fake = (UINT32*)Buffer;
if (!Fake) return 0;
Size >>= 2;
while (Size--) x+= *Fake++;
return x;
}
#endif
/*
return TRUE if the property present && value = TRUE
@ -270,6 +286,13 @@ IsPropertyFalse (
((Prop->string[0] == 'N') || (Prop->string[0] == 'n'))));
}
/*
Possible values
<integer>1234</integer>
<integer>+1234</integer>
<integer>-1234</integer>
<string>0x12abd</string>
*/
INTN
GetPropertyInteger (
TagPtr Prop,
@ -281,7 +304,7 @@ GetPropertyInteger (
}
if (Prop->type == kTagTypeInteger) {
return (INTN)Prop->string;
return (INTN)Prop->string; //this is union char* or size_t
} else if ((Prop->type == kTagTypeString) && Prop->string) {
if ((Prop->string[1] == 'x') || (Prop->string[1] == 'X')) {
return (INTN)AsciiStrHexToUintn (Prop->string);

View File

@ -1,110 +0,0 @@
/*
* refit/scan/uefibootoption.c
*
* Copyright (c) 2006-2010 Christoph Pfisterer
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Christoph Pfisterer nor the names of the
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
VOID AddUEFIBootOption(BO_BOOT_OPTION *bootOption)
{
UINTN volumeIndex;
REFIT_VOLUME *volume;
EFI_DEVICE_PATH_PROTOCOL *devPathNode;
LOADER_ENTRY *loaderEntry;
FILEPATH_DEVICE_PATH *loaderDevicePath;
CHAR16 *loaderPath;
CHAR16 *bootParams;
CHAR16 *title;
EFI_GUID *volumeGUID;
EFI_GUID *bootGUID;
for (volumeIndex = 0; volumeIndex < VolumesCount; volumeIndex++) {
volume = Volumes[volumeIndex];
volumeGUID = FindGPTPartitionGuidInDevicePath(volume->DevicePath);
bootGUID = FindGPTPartitionGuidInDevicePath(bootOption->FilePathList);
if (!volumeGUID || !bootGUID || !CompareGuid(volumeGUID, bootGUID)) continue;
devPathNode = bootOption->FilePathList;
loaderDevicePath = (FILEPATH_DEVICE_PATH *) FindDevicePathNodeWithType(devPathNode, MEDIA_DEVICE_PATH,
MEDIA_FILEPATH_DP);
if (!loaderDevicePath) continue;
loaderPath = loaderDevicePath->PathName;
bootParams = (CHAR16 *) bootOption->OptionalData;
title = bootOption->Description;
volume->OSIconName = L"unknown";
volume->BootType = BOOTING_BY_EFI;
loaderEntry = AddLoaderEntry(loaderPath, title, volume, OSTYPE_EFI);
loaderEntry->LoadOptions = EfiStrDuplicate(bootParams);
}
}
VOID ScanUEFIBootOptions(BOOLEAN allBootOptions)
{
EFI_STATUS status;
UINT16 *bootOrder;
UINTN bootOrderCnt;
UINT16 i;
BO_BOOT_OPTION bootOption;
DBG("Scanning boot options from UEFI ...\n");
if (allBootOptions) {
for (i = 0; i <= 0xFFFF; i++) {
status = GetBootOption(i, &bootOption);
if (EFI_ERROR(status)) continue;
AddUEFIBootOption(&bootOption);
FreePool(bootOption.Variable);
}
} else {
status = GetBootOrder(&bootOrder, &bootOrderCnt);
if (EFI_ERROR(status)) return;
for (i = 0; i < bootOrderCnt; i++) {
status = GetBootOption(bootOrder[i], &bootOption);
if (EFI_ERROR(status)) continue;
AddUEFIBootOption(&bootOption);
FreePool(bootOption.Variable);
}
FreePool(bootOrder);
}
}
// */

View File

@ -293,11 +293,11 @@ static unsigned uivector_resize(uivector* p, size_t size)
/*resize and give all new elements the value*/
static unsigned uivector_resizev(uivector* p, size_t size, unsigned value)
{
size_t oldsize = p->size, i;
size_t oldsize = p->size;
// Prevent memset from being emitted by making this volatile
volatile uivector *tmp = p;
if(!uivector_resize(p, size)) return 0;
for(i = oldsize; i < size; ++i) tmp->data[i] = value;
for(size_t i = oldsize; i < size; ++i) tmp->data[i] = value;
return 1;
}
@ -372,9 +372,9 @@ static void ucvector_init(ucvector* p)
/*resize and give all new elements the value*/
static unsigned ucvector_resizev(ucvector* p, size_t size, unsigned char value)
{
size_t oldsize = p->size, i;
size_t oldsize = p->size;
if(!ucvector_resize(p, size)) return 0;
for(i = oldsize; i < size; ++i) p->data[i] = value;
for(size_t i = oldsize; i < size; ++i) p->data[i] = value;
return 1;
}
#endif /*LODEPNG_COMPILE_DECODER*/
@ -433,10 +433,10 @@ static void string_cleanup(char** out)
static void string_set(char** out, const char* in)
{
size_t insize = AsciiStrLen(in), i;
size_t insize = AsciiStrLen(in);
if(string_resize(out, insize))
{
for(i = 0; i != insize; ++i)
for(size_t i = 0; i != insize; ++i)
{
(*out)[i] = in[i];
}
@ -537,14 +537,12 @@ unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const
static void addBitsToStream(size_t* bitpointer, ucvector* bitstream, unsigned value, size_t nbits)
{
size_t i;
for(i = 0; i != nbits; ++i) addBitToStream(bitpointer, bitstream, (unsigned char)((value >> i) & 1));
for(size_t i = 0; i != nbits; ++i) addBitToStream(bitpointer, bitstream, (unsigned char)((value >> i) & 1));
}
static void addBitsToStreamReversed(size_t* bitpointer, ucvector* bitstream, unsigned value, size_t nbits)
{
size_t i;
for(i = 0; i != nbits; ++i) addBitToStream(bitpointer, bitstream, (unsigned char)((value >> (nbits - 1 - i)) & 1));
for(size_t i = 0; i != nbits; ++i) addBitToStream(bitpointer, bitstream, (unsigned char)((value >> (nbits - 1 - i)) & 1));
}
#endif /*LODEPNG_COMPILE_ENCODER*/
@ -561,8 +559,8 @@ static unsigned char readBitFromStream(size_t* bitpointer, const unsigned char*
static unsigned readBitsFromStream(size_t* bitpointer, const unsigned char* bitstream, size_t nbits)
{
unsigned result = 0, i;
for(i = 0; i != nbits; ++i)
unsigned result = 0;
for(size_t i = 0; i != nbits; ++i)
{
result += ((unsigned)READBIT(*bitpointer, bitstream)) << i;
++(*bitpointer);
@ -918,12 +916,12 @@ unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequen
leaves = (BPMNode*)lodepng_malloc(numcodes * sizeof(*leaves));
if(!leaves) return 83; /*alloc fail*/
for(int i = 0; i != numcodes; ++i)
for(size_t i = 0; i != numcodes; ++i)
{
if(frequencies[i] > 0)
{
leaves[numpresent].weight = (int)frequencies[i];
leaves[numpresent].index = i;
leaves[numpresent].index = (unsigned)i;
++numpresent;
}
}
@ -963,19 +961,19 @@ unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequen
if(!error)
{
for(int i = 0; i != lists.memsize; ++i) lists.freelist[i] = &lists.memory[i];
for(unsigned i = 0; i != lists.memsize; ++i) lists.freelist[i] = &lists.memory[i];
bpmnode_create(&lists, leaves[0].weight, 1, 0);
bpmnode_create(&lists, leaves[1].weight, 2, 0);
for(int i = 0; i != lists.listsize; ++i)
for(unsigned i = 0; i != lists.listsize; ++i)
{
lists.chains0[i] = &lists.memory[0];
lists.chains1[i] = &lists.memory[1];
}
/*each boundaryPM call adds one chain to the last list, and we need 2 * numpresent - 2 chains.*/
for(int i = 2; i != 2 * numpresent - 2; ++i) boundaryPM(&lists, leaves, numpresent, (int)maxbitlen - 1, i);
for(unsigned i = 2; i != 2 * numpresent - 2; ++i) boundaryPM(&lists, leaves, numpresent, (int)maxbitlen - 1, (int)i);
for(node = lists.chains1[maxbitlen - 1]; node; node = node->tail)
{
for(int i = 0; i != node->index; ++i) ++lengths[leaves[i].index];
for(unsigned i = 0; i != node->index; ++i) ++lengths[leaves[i].index];
}
}

View File

@ -221,9 +221,12 @@ VOID PrepareFont()
static inline BOOLEAN EmptyPix(EG_PIXEL *Ptr, EG_PIXEL *FirstPixel)
{
//compare with first pixel of the array top-left point [0][0]
return ((Ptr->r >= FirstPixel->r - (FirstPixel->r >> 2)) && (Ptr->r <= FirstPixel->r + (FirstPixel->r >> 2)) &&
(Ptr->g >= FirstPixel->g - (FirstPixel->g >> 2)) && (Ptr->g <= FirstPixel->g + (FirstPixel->g >> 2)) &&
(Ptr->b >= FirstPixel->b - (FirstPixel->b >> 2)) && (Ptr->b <= FirstPixel->b + (FirstPixel->b >> 2)) &&
return ((Ptr->r >= FirstPixel->r - (FirstPixel->r >> 2)) &&
(Ptr->r <= FirstPixel->r + (FirstPixel->r >> 2)) &&
(Ptr->g >= FirstPixel->g - (FirstPixel->g >> 2)) &&
(Ptr->g <= FirstPixel->g + (FirstPixel->g >> 2)) &&
(Ptr->b >= FirstPixel->b - (FirstPixel->b >> 2)) &&
(Ptr->b <= FirstPixel->b + (FirstPixel->b >> 2)) &&
(Ptr->a == FirstPixel->a)); //hack for transparent fonts
}

View File

@ -62,7 +62,8 @@
#endif
//#define PREBOOT_LOG L"EFI\\CLOVER\\misc\\preboot.log"
#define VBIOS_BIN L"EFI\\CLOVER\\misc\\c0000.bin"
//#define VBIOS_BIN L"EFI\\CLOVER\\misc\\c0000.bin"
CONST CHAR16 *VBIOS_BIN = L"EFI\\CLOVER\\misc\\c0000.bin";
//#define LSTR(s) L##s