Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
btwise
OpenCorePKG_MOD
提交
8c95b246
O
OpenCorePKG_MOD
项目概览
btwise
/
OpenCorePKG_MOD
通知
26
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
OpenCorePKG_MOD
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8c95b246
编写于
4月 03, 2020
作者:
V
vit9696
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
OcMemoryLib: Add memory sorting and improve memory printing
上级
e673e7b6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
130 addition
and
23 deletion
+130
-23
Application/MmapDump/MmapDump.c
Application/MmapDump/MmapDump.c
+1
-0
Include/Library/OcMemoryLib.h
Include/Library/OcMemoryLib.h
+20
-3
Library/OcAppleBootCompatLib/ServiceOverrides.c
Library/OcAppleBootCompatLib/ServiceOverrides.c
+3
-1
Library/OcMemoryLib/MemoryMap.c
Library/OcMemoryLib/MemoryMap.c
+106
-19
未找到文件。
Application/MmapDump/MmapDump.c
浏览文件 @
8c95b246
...
...
@@ -81,6 +81,7 @@ UefiMain (
);
if
(
MemoryMap
!=
NULL
)
{
OcSortMemoryMap
(
MemoryMapSize
,
MemoryMap
,
DescriptorSize
);
DEBUG
((
DEBUG_INFO
,
"MMDD: Dumping the original memory map
\n
"
));
OcPrintMemoryMap
(
MemoryMapSize
,
MemoryMap
,
DescriptorSize
);
DEBUG
((
DEBUG_INFO
,
"MMDD: Dumping patched memory map
\n
"
));
...
...
Include/Library/OcMemoryLib.h
浏览文件 @
8c95b246
...
...
@@ -118,15 +118,31 @@ GetCurrentMemoryMapAlloc (
IN
OUT
EFI_PHYSICAL_ADDRESS
*
TopMemory
OPTIONAL
);
/**
Sort memory map entries based upon PhysicalStart, from low to high.
@param MemoryMapSize Size, in bytes, of the MemoryMap buffer.
@param MemoryMap A pointer to the buffer in which firmware places
the current memory map.
@param DescriptorSize Size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR.
**/
VOID
OcSortMemoryMap
(
IN
UINTN
MemoryMapSize
,
IN
OUT
EFI_MEMORY_DESCRIPTOR
*
MemoryMap
,
IN
UINTN
DescriptorSize
);
/**
Shrink memory map by joining non-runtime records.
Requires sorted memory map.
@param[in,out] MemoryMapSize Memory map size in bytes, updated on shrink.
@param[in,out] MemoryMap Memory map to shrink.
@param[in] DescriptorSize Memory map descriptor size in bytes.
**/
VOID
ShrinkMemoryMap
(
Oc
ShrinkMemoryMap
(
IN
OUT
UINTN
*
MemoryMapSize
,
IN
OUT
EFI_MEMORY_DESCRIPTOR
*
MemoryMap
,
IN
UINTN
DescriptorSize
...
...
@@ -309,8 +325,9 @@ OcCountSplitDescritptors (
/**
Split memory map by memory attributes if available.
Requires sorted memory map!
@param[in]
OriginalMemoryMapSize
Upper memory map size bound for growth.
@param[in]
MaxMemoryMapSize
Upper memory map size bound for growth.
@param[in,out] MemoryMapSize Current memory map size, updated on return.
@param[in,out] MemoryMap Memory map to split.
@param[in] DescriptorSize Memory map descriptor size.
...
...
@@ -323,7 +340,7 @@ OcCountSplitDescritptors (
**/
EFI_STATUS
OcSplitMemoryMapByAttributes
(
IN
UINTN
Original
MemoryMapSize
,
IN
UINTN
Max
MemoryMapSize
,
IN
OUT
UINTN
*
MemoryMapSize
,
IN
OUT
EFI_MEMORY_DESCRIPTOR
*
MemoryMap
,
IN
UINTN
DescriptorSize
...
...
Library/OcAppleBootCompatLib/ServiceOverrides.c
浏览文件 @
8c95b246
...
...
@@ -465,6 +465,8 @@ OcGetMemoryMap (
}
if
(
BootCompat
->
Settings
.
RebuildAppleMemoryMap
)
{
OcSortMemoryMap
(
*
MemoryMapSize
,
MemoryMap
,
*
DescriptorSize
);
Status2
=
OcSplitMemoryMapByAttributes
(
OriginalSize
,
MemoryMapSize
,
...
...
@@ -475,7 +477,7 @@ OcGetMemoryMap (
DEBUG
((
DEBUG_INFO
,
"OCABC: Cannot rebuild memory map - %r
\n
"
,
Status
));
}
ShrinkMemoryMap
(
Oc
ShrinkMemoryMap
(
MemoryMapSize
,
MemoryMap
,
*
DescriptorSize
...
...
Library/OcMemoryLib/MemoryMap.c
浏览文件 @
8c95b246
...
...
@@ -23,6 +23,24 @@
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
STATIC
CONST
CHAR8
*
mEfiMemoryTypeDesc
[
EfiMaxMemoryType
]
=
{
"Reserved "
,
"LDR Code "
,
"LDR Data "
,
"BS Code "
,
"BS Data "
,
"RT Code "
,
"RT Data "
,
"Available"
,
"Unusable "
,
"ACPI RECL"
,
"ACPI NVS "
,
"MemMapIO "
,
"MemPortIO"
,
"PAL Code "
,
"Persist "
};
EFI_MEMORY_DESCRIPTOR
*
OcGetCurrentMemoryMap
(
OUT
UINTN
*
MemoryMapSize
,
...
...
@@ -209,7 +227,38 @@ GetCurrentMemoryMapAlloc (
}
VOID
ShrinkMemoryMap
(
OcSortMemoryMap
(
IN
UINTN
MemoryMapSize
,
IN
OUT
EFI_MEMORY_DESCRIPTOR
*
MemoryMap
,
IN
UINTN
DescriptorSize
)
{
EFI_MEMORY_DESCRIPTOR
*
MemoryMapEntry
;
EFI_MEMORY_DESCRIPTOR
*
NextMemoryMapEntry
;
EFI_MEMORY_DESCRIPTOR
*
MemoryMapEnd
;
EFI_MEMORY_DESCRIPTOR
TempMemoryMap
;
MemoryMapEntry
=
MemoryMap
;
NextMemoryMapEntry
=
NEXT_MEMORY_DESCRIPTOR
(
MemoryMapEntry
,
DescriptorSize
);
MemoryMapEnd
=
(
EFI_MEMORY_DESCRIPTOR
*
)
((
UINT8
*
)
MemoryMap
+
MemoryMapSize
);
while
(
MemoryMapEntry
<
MemoryMapEnd
)
{
while
(
NextMemoryMapEntry
<
MemoryMapEnd
)
{
if
(
MemoryMapEntry
->
PhysicalStart
>
NextMemoryMapEntry
->
PhysicalStart
)
{
CopyMem
(
&
TempMemoryMap
,
MemoryMapEntry
,
sizeof
(
EFI_MEMORY_DESCRIPTOR
));
CopyMem
(
MemoryMapEntry
,
NextMemoryMapEntry
,
sizeof
(
EFI_MEMORY_DESCRIPTOR
));
CopyMem
(
NextMemoryMapEntry
,
&
TempMemoryMap
,
sizeof
(
EFI_MEMORY_DESCRIPTOR
));
}
NextMemoryMapEntry
=
NEXT_MEMORY_DESCRIPTOR
(
NextMemoryMapEntry
,
DescriptorSize
);
}
MemoryMapEntry
=
NEXT_MEMORY_DESCRIPTOR
(
MemoryMapEntry
,
DescriptorSize
);
NextMemoryMapEntry
=
NEXT_MEMORY_DESCRIPTOR
(
MemoryMapEntry
,
DescriptorSize
);
}
}
VOID
OcShrinkMemoryMap
(
IN
OUT
UINTN
*
MemoryMapSize
,
IN
OUT
EFI_MEMORY_DESCRIPTOR
*
MemoryMap
,
IN
UINTN
DescriptorSize
...
...
@@ -451,6 +500,57 @@ CountFreePages (
return
FreePages
;
}
STATIC
VOID
OcPrintMemoryDescritptor
(
IN
EFI_MEMORY_DESCRIPTOR
*
Desc
)
{
CONST
CHAR8
*
Type
;
CONST
CHAR8
*
SizeType
;
UINT64
SizeValue
;
if
(
Desc
->
Type
<
ARRAY_SIZE
(
mEfiMemoryTypeDesc
))
{
Type
=
mEfiMemoryTypeDesc
[
Desc
->
Type
];
}
else
{
Type
=
"Invalid"
;
}
SizeValue
=
EFI_PAGES_TO_SIZE
(
Desc
->
NumberOfPages
);
if
(
SizeValue
>=
BASE_1MB
)
{
SizeValue
/=
BASE_1MB
;
SizeType
=
"MB"
;
}
else
{
SizeValue
/=
BASE_1KB
;
SizeType
=
"KB"
;
}
DEBUG
((
DEBUG_INFO
,
"%a [%a|%a|%a|%a|%a|%a|%a|%a|%a|%a|%a|%a|%a|%a] 0x%016LX-0x%016LX -> 0x%016X (%Lu %a)
\n
"
,
Type
,
(
Desc
->
Attribute
&
EFI_MEMORY_RUNTIME
)
!=
0
?
"RUN"
:
" "
,
(
Desc
->
Attribute
&
EFI_MEMORY_CPU_CRYPTO
)
!=
0
?
"CRY"
:
" "
,
(
Desc
->
Attribute
&
EFI_MEMORY_SP
)
!=
0
?
"SP"
:
" "
,
(
Desc
->
Attribute
&
EFI_MEMORY_RO
)
!=
0
?
"RO"
:
" "
,
(
Desc
->
Attribute
&
EFI_MEMORY_MORE_RELIABLE
)
!=
0
?
"MR"
:
" "
,
(
Desc
->
Attribute
&
EFI_MEMORY_NV
)
!=
0
?
"NV"
:
" "
,
(
Desc
->
Attribute
&
EFI_MEMORY_RP
)
!=
0
?
"RP"
:
" "
,
(
Desc
->
Attribute
&
EFI_MEMORY_XP
)
!=
0
?
"XP"
:
" "
,
(
Desc
->
Attribute
&
EFI_MEMORY_RO
)
!=
0
?
"RO"
:
" "
,
(
Desc
->
Attribute
&
EFI_MEMORY_UCE
)
!=
0
?
"UCE"
:
" "
,
(
Desc
->
Attribute
&
EFI_MEMORY_WB
)
!=
0
?
"WB"
:
" "
,
(
Desc
->
Attribute
&
EFI_MEMORY_WT
)
!=
0
?
"WT"
:
" "
,
(
Desc
->
Attribute
&
EFI_MEMORY_WC
)
!=
0
?
"WC"
:
" "
,
(
Desc
->
Attribute
&
EFI_MEMORY_UC
)
!=
0
?
"UC"
:
" "
,
Desc
->
PhysicalStart
,
Desc
->
PhysicalStart
+
(
EFI_PAGES_TO_SIZE
(
Desc
->
NumberOfPages
)
-
1
),
Desc
->
VirtualStart
,
SizeValue
,
SizeType
));
}
VOID
OcPrintMemoryAttributesTable
(
VOID
...
...
@@ -472,13 +572,7 @@ OcPrintMemoryAttributesTable (
DEBUG
((
DEBUG_INFO
,
"OCMM: DescriptorSize - 0x%08x
\n
"
,
MemoryAttributesTable
->
DescriptorSize
));
for
(
Index
=
0
;
Index
<
MemoryAttributesTable
->
NumberOfEntries
;
++
Index
)
{
DEBUG
((
DEBUG_INFO
,
"OCMM: Entry (0x%x)
\n
"
,
MemoryAttributesEntry
));
DEBUG
((
DEBUG_INFO
,
"OCMM: Type - 0x%x
\n
"
,
MemoryAttributesEntry
->
Type
));
DEBUG
((
DEBUG_INFO
,
"OCMM: PhysicalStart - 0x%016lx
\n
"
,
MemoryAttributesEntry
->
PhysicalStart
));
DEBUG
((
DEBUG_INFO
,
"OCMM: VirtualStart - 0x%016lx
\n
"
,
MemoryAttributesEntry
->
VirtualStart
));
DEBUG
((
DEBUG_INFO
,
"OCMM: NumberOfPages - 0x%016lx
\n
"
,
MemoryAttributesEntry
->
NumberOfPages
));
DEBUG
((
DEBUG_INFO
,
"OCMM: Attribute - 0x%016lx
\n
"
,
MemoryAttributesEntry
->
Attribute
));
OcPrintMemoryDescritptor
(
MemoryAttributesEntry
);
MemoryAttributesEntry
=
NEXT_MEMORY_DESCRIPTOR
(
MemoryAttributesEntry
,
MemoryAttributesTable
->
DescriptorSize
...
...
@@ -504,13 +598,7 @@ OcPrintMemoryMap (
DEBUG
((
DEBUG_INFO
,
"OCMM: DescriptorSize - 0x%08x
\n
"
,
DescriptorSize
));
for
(
Index
=
0
;
Index
<
NumberOfEntries
;
++
Index
)
{
DEBUG
((
DEBUG_INFO
,
"OCMM: Entry (0x%x)
\n
"
,
MemoryMap
));
DEBUG
((
DEBUG_INFO
,
"OCMM: Type - 0x%x
\n
"
,
MemoryMap
->
Type
));
DEBUG
((
DEBUG_INFO
,
"OCMM: PhysicalStart - 0x%016lx
\n
"
,
MemoryMap
->
PhysicalStart
));
DEBUG
((
DEBUG_INFO
,
"OCMM: VirtualStart - 0x%016lx
\n
"
,
MemoryMap
->
VirtualStart
));
DEBUG
((
DEBUG_INFO
,
"OCMM: NumberOfPages - 0x%016lx
\n
"
,
MemoryMap
->
NumberOfPages
));
DEBUG
((
DEBUG_INFO
,
"OCMM: Attribute - 0x%016lx
\n
"
,
MemoryMap
->
Attribute
));
OcPrintMemoryDescritptor
(
MemoryMap
);
MemoryMap
=
NEXT_MEMORY_DESCRIPTOR
(
MemoryMap
,
DescriptorSize
...
...
@@ -772,7 +860,7 @@ OcSplitMemoryEntryByAttribute (
EFI_STATUS
OcSplitMemoryMapByAttributes
(
IN
UINTN
Original
MemoryMapSize
,
IN
UINTN
Max
MemoryMapSize
,
IN
OUT
UINTN
*
MemoryMapSize
,
IN
OUT
EFI_MEMORY_DESCRIPTOR
*
MemoryMap
,
IN
UINTN
DescriptorSize
...
...
@@ -792,7 +880,7 @@ OcSplitMemoryMapByAttributes (
BOOLEAN
CanSplit
;
BOOLEAN
InDescAttrs
;
ASSERT
(
Original
MemoryMapSize
>=
*
MemoryMapSize
);
ASSERT
(
Max
MemoryMapSize
>=
*
MemoryMapSize
);
MemoryAttributesTable
=
OcGetMemoryAttributes
(
&
MemoryAttributesEntry
);
if
(
MemoryAttributesTable
==
NULL
)
{
...
...
@@ -803,12 +891,11 @@ OcSplitMemoryMapByAttributes (
LastAttributeIndex
=
0
;
MemoryMapEntry
=
MemoryMap
;
CurrentEntryCount
=
*
MemoryMapSize
/
DescriptorSize
;
TotalEntryCount
=
Original
MemoryMapSize
/
DescriptorSize
;
TotalEntryCount
=
Max
MemoryMapSize
/
DescriptorSize
;
AttributeCount
=
MemoryAttributesTable
->
NumberOfEntries
;
//
// We assume that the memory map and attribute table are sorted.
// If this is not the case we can add a sort call here.
//
for
(
Index
=
0
;
Index
<
CurrentEntryCount
;
++
Index
)
{
//
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录