mirror of https://github.com/acidanthera/audk.git
MdeModulePkg/Core: fix bits operation error on a boundary condition
If given address is on 64K boundary and the requested bit number is 64, all SetBits(), ClearBits() and GetBits() will encounter ASSERT problem in trying to do a 64 bits of shift, which is not allowed by LShift() and RShift(). This patch tries to fix this issue by turning bits operation into whole integer operation in such situation. Cc: Star Zeng <star.zeng@intel.com> Cc: Eric Dong <eric.dong@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Ruiyu Ni <ruiyu.ni@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
This commit is contained in:
parent
883787a2c6
commit
36f2f049a8
|
@ -70,7 +70,7 @@ SetBits (
|
||||||
StartBit = (UINTN)GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address);
|
StartBit = (UINTN)GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address);
|
||||||
EndBit = (StartBit + BitNumber - 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
|
EndBit = (StartBit + BitNumber - 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
|
||||||
|
|
||||||
if ((StartBit + BitNumber) > GUARDED_HEAP_MAP_ENTRY_BITS) {
|
if ((StartBit + BitNumber) >= GUARDED_HEAP_MAP_ENTRY_BITS) {
|
||||||
Msbs = (GUARDED_HEAP_MAP_ENTRY_BITS - StartBit) %
|
Msbs = (GUARDED_HEAP_MAP_ENTRY_BITS - StartBit) %
|
||||||
GUARDED_HEAP_MAP_ENTRY_BITS;
|
GUARDED_HEAP_MAP_ENTRY_BITS;
|
||||||
Lsbs = (EndBit + 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
|
Lsbs = (EndBit + 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
|
||||||
|
@ -123,7 +123,7 @@ ClearBits (
|
||||||
StartBit = (UINTN)GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address);
|
StartBit = (UINTN)GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address);
|
||||||
EndBit = (StartBit + BitNumber - 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
|
EndBit = (StartBit + BitNumber - 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
|
||||||
|
|
||||||
if ((StartBit + BitNumber) > GUARDED_HEAP_MAP_ENTRY_BITS) {
|
if ((StartBit + BitNumber) >= GUARDED_HEAP_MAP_ENTRY_BITS) {
|
||||||
Msbs = (GUARDED_HEAP_MAP_ENTRY_BITS - StartBit) %
|
Msbs = (GUARDED_HEAP_MAP_ENTRY_BITS - StartBit) %
|
||||||
GUARDED_HEAP_MAP_ENTRY_BITS;
|
GUARDED_HEAP_MAP_ENTRY_BITS;
|
||||||
Lsbs = (EndBit + 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
|
Lsbs = (EndBit + 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
|
||||||
|
@ -188,11 +188,15 @@ GetBits (
|
||||||
Lsbs = 0;
|
Lsbs = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (StartBit == 0 && BitNumber == GUARDED_HEAP_MAP_ENTRY_BITS) {
|
||||||
|
Result = *BitMap;
|
||||||
|
} else {
|
||||||
Result = RShiftU64((*BitMap), StartBit) & (LShiftU64(1, Msbs) - 1);
|
Result = RShiftU64((*BitMap), StartBit) & (LShiftU64(1, Msbs) - 1);
|
||||||
if (Lsbs > 0) {
|
if (Lsbs > 0) {
|
||||||
BitMap += 1;
|
BitMap += 1;
|
||||||
Result |= LShiftU64 ((*BitMap) & (LShiftU64 (1, Lsbs) - 1), Msbs);
|
Result |= LShiftU64 ((*BitMap) & (LShiftU64 (1, Lsbs) - 1), Msbs);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue