Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
btwise
OpenCorePKG_MOD
提交
f323be45
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,发现更多精彩内容 >>
提交
f323be45
编写于
4月 03, 2020
作者:
V
vit9696
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MmapDump: Initial version of MMAP dumping utility
上级
67ab1cfd
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
254 addition
and
40 deletion
+254
-40
Application/MmapDump/MmapDump.c
Application/MmapDump/MmapDump.c
+101
-0
Application/MmapDump/MmapDump.inf
Application/MmapDump/MmapDump.inf
+52
-0
Include/Library/OcMemoryLib.h
Include/Library/OcMemoryLib.h
+26
-8
Library/OcAppleRamDiskLib/OcAppleRamDiskLib.c
Library/OcAppleRamDiskLib/OcAppleRamDiskLib.c
+1
-1
Library/OcMemoryLib/MemoryMap.c
Library/OcMemoryLib/MemoryMap.c
+72
-31
OpenCorePkg.dsc
OpenCorePkg.dsc
+1
-0
macbuild.tool
macbuild.tool
+1
-0
未找到文件。
Application/MmapDump/MmapDump.c
0 → 100644
浏览文件 @
f323be45
/** @file
Dump memory map and memory attributes.
Copyright (c) 2020, vit9696. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/OcMemoryLib.h>
#include <Library/OcMiscLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiApplicationEntryPoint.h>
#include <Protocol/OcFirmwareRuntime.h>
EFI_STATUS
EFIAPI
UefiMain
(
IN
EFI_HANDLE
ImageHandle
,
IN
EFI_SYSTEM_TABLE
*
SystemTable
)
{
EFI_STATUS
Status
;
OC_FIRMWARE_RUNTIME_PROTOCOL
*
FwRuntime
;
EFI_PHYSICAL_ADDRESS
Address
;
UINTN
Pages
;
UINTN
MemoryMapSize
;
UINTN
OriginalSize
;
UINTN
DescriptorSize
;
EFI_MEMORY_DESCRIPTOR
*
MemoryMap
;
Address
=
0
;
Status
=
gBS
->
LocateProtocol
(
&
gOcFirmwareRuntimeProtocolGuid
,
NULL
,
(
VOID
**
)
&
FwRuntime
);
if
(
!
EFI_ERROR
(
Status
)
&&
FwRuntime
->
Revision
==
OC_FIRMWARE_RUNTIME_REVISION
)
{
Status
=
FwRuntime
->
GetExecArea
(
&
Address
,
&
Pages
);
DEBUG
((
DEBUG_WARN
,
"MMDD: OpenRuntime r%u resides at %X - %r
\n
"
,
(
UINT32
)
FwRuntime
->
Revision
,
(
UINT32
)
Address
,
Status
));
}
else
if
(
FwRuntime
->
Revision
!=
OC_FIRMWARE_RUNTIME_REVISION
)
{
DEBUG
((
DEBUG_WARN
,
"MMDD: OpenRuntime has unexpected revision r%u instead of r%u
\n
"
,
(
UINT32
)
FwRuntime
->
Revision
,
(
UINT32
)
OC_FIRMWARE_RUNTIME_REVISION
));
}
else
{
DEBUG
((
DEBUG_WARN
,
"MMDD: OpenRuntime is missing - %r
\n
"
,
Status
));
}
DEBUG
((
DEBUG_WARN
,
"MMDD: Note, that DEBUG version of the tool prints more
\n
"
));
OcPrintMemoryAttributesTable
();
MemoryMap
=
OcGetCurrentMemoryMap
(
&
MemoryMapSize
,
&
DescriptorSize
,
NULL
,
NULL
,
&
OriginalSize
,
TRUE
);
if
(
MemoryMap
!=
NULL
)
{
DEBUG
((
DEBUG_INFO
,
"MMDD: Dumping the original memory map
\n
"
));
OcPrintMemoryMap
(
MemoryMapSize
,
MemoryMap
,
DescriptorSize
);
DEBUG
((
DEBUG_INFO
,
"MMDD: Dumping patched memory map
\n
"
));
OcUpdateAttributes
(
Address
,
EfiRuntimeServicesCode
,
EFI_MEMORY_RO
,
EFI_MEMORY_XP
);
Status
=
OcSplitMemoryMapByAttributes
(
OriginalSize
,
&
MemoryMapSize
,
MemoryMap
,
DescriptorSize
);
if
(
!
EFI_ERROR
(
Status
))
{
OcPrintMemoryMap
(
MemoryMapSize
,
MemoryMap
,
DescriptorSize
);
}
else
{
DEBUG
((
DEBUG_INFO
,
"MMDD: Cannot patch memory map - %r
\n
"
,
Status
));
}
}
else
{
DEBUG
((
DEBUG_INFO
,
"MMDD: Unable to obtain memory map
\n
"
));
}
gBS
->
Stall
(
SECONDS_TO_MICROSECONDS
(
3
));
return
EFI_SUCCESS
;
}
Application/MmapDump/MmapDump.inf
0 → 100644
浏览文件 @
f323be45
## @file
# Dump memory map and memory attributes.
#
# Copyright (c) 2018, vit9696. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = MmapDump
FILE_GUID = 932C885D-D6CA-408E-B482-90A582212F30
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
ENTRY_POINT = UefiMain
#
# This flag specifies whether HII resource section is generated into PE image.
#
UEFI_HII_RESOURCE_SECTION = TRUE
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
MmapDump.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
OpenCorePkg/OpenCorePkg.dec
UefiCpuPkg/UefiCpuPkg.dec
[Protocols]
gOcFirmwareRuntimeProtocolGuid ## CONSUMES
[LibraryClasses]
OcConsoleControlEntryModeGenericLib
OcMemoryLib
UefiApplicationEntryPoint
UefiLib
PcdLib
IoLib
Include/Library/OcMemoryLib.h
浏览文件 @
f323be45
...
...
@@ -73,21 +73,25 @@ LegacyRegionUnlock (
);
/**
Get current memory map allocated on pool.
Get current memory map allocated on pool
with reserved entries
.
@param[out] MemoryMapSize Resulting memory map size in bytes.
@param[out] DescriptorSize Resulting memory map descriptor size in bytes.
@param[out] MapKey Memory map key, optional.
@param[out] DescriptorVersion Memory map descriptor version, optional.
@param[out] MemoryMapSize Resulting memory map size in bytes.
@param[out] DescriptorSize Resulting memory map descriptor size in bytes.
@param[out] MapKey Memory map key, optional.
@param[out] DescriptorVersion Memory map descriptor version, optional.
@param[out] OriginalMemoryMapSize Actual pool allocation memory, optional.
@param[out] IncludeSplitSpace Allocate memory to permit splitting memory map.
@retval current memory map or NULL.
**/
EFI_MEMORY_DESCRIPTOR
*
GetCurrentMemoryMap
(
Oc
GetCurrentMemoryMap
(
OUT
UINTN
*
MemoryMapSize
,
OUT
UINTN
*
DescriptorSize
,
OUT
UINTN
*
MapKey
OPTIONAL
,
OUT
UINT32
*
DescriptorVersion
OPTIONAL
OUT
UINTN
*
MapKey
OPTIONAL
,
OUT
UINT32
*
DescriptorVersion
OPTIONAL
,
OUT
UINTN
*
OriginalMemoryMapSize
OPTIONAL
,
IN
BOOLEAN
IncludeSplitSpace
);
/**
...
...
@@ -220,6 +224,20 @@ OcPrintMemoryAttributesTable (
VOID
);
/**
Print memory map.
@param[in] MemoryMapSize Memory map size in bytes.
@param[in] MemoryMap Memory map to print.
@param[in] DescriptorSize Memory map descriptor size in bytes.
**/
VOID
OcPrintMemoryMap
(
IN
UINTN
MemoryMapSize
,
IN
EFI_MEMORY_DESCRIPTOR
*
MemoryMap
,
IN
UINTN
DescriptorSize
);
/**
Refresh memory descriptor containing the specified address.
...
...
Library/OcAppleRamDiskLib/OcAppleRamDiskLib.c
浏览文件 @
f323be45
...
...
@@ -246,7 +246,7 @@ InternalAppleRamDiskAllocate (
UINTN
RemainingSize
;
APPLE_RAM_DISK_EXTENT_TABLE
*
ExtentTable
;
MemoryMap
=
GetCurrentMemoryMap
(
&
MemoryMapSize
,
&
DescriptorSize
,
NULL
,
NULL
);
MemoryMap
=
OcGetCurrentMemoryMap
(
&
MemoryMapSize
,
&
DescriptorSize
,
NULL
,
NULL
,
NULL
,
FALSE
);
if
(
MemoryMap
==
NULL
)
{
return
NULL
;
}
...
...
Library/OcMemoryLib/MemoryMap.c
浏览文件 @
f323be45
...
...
@@ -24,16 +24,20 @@
#include <Library/UefiLib.h>
EFI_MEMORY_DESCRIPTOR
*
GetCurrentMemoryMap
(
Oc
GetCurrentMemoryMap
(
OUT
UINTN
*
MemoryMapSize
,
OUT
UINTN
*
DescriptorSize
,
OUT
UINTN
*
MapKey
OPTIONAL
,
OUT
UINT32
*
DescriptorVersion
OPTIONAL
OUT
UINTN
*
MapKey
OPTIONAL
,
OUT
UINT32
*
DescriptorVersion
OPTIONAL
,
OUT
UINTN
*
OriginalMemoryMapSize
OPTIONAL
,
IN
BOOLEAN
IncludeSplitSpace
)
{
EFI_MEMORY_DESCRIPTOR
*
MemoryMap
;
EFI_STATUS
Status
;
UINTN
MapKeyValue
;
UINTN
OriginalSize
;
UINTN
ExtraSize
;
UINT32
DescriptorVersionValue
;
BOOLEAN
Result
;
...
...
@@ -50,13 +54,19 @@ GetCurrentMemoryMap (
return
NULL
;
}
if
(
IncludeSplitSpace
)
{
ExtraSize
=
OcCountSplitDescritptors
()
*
*
DescriptorSize
;
}
else
{
ExtraSize
=
0
;
}
//
// Apple uses 1024 as constant, however it will grow by at least
// DescriptorSize.
//
Result
=
OcOverflowAddUN
(
*
MemoryMapSize
,
MAX
(
*
DescriptorSize
,
1024
),
MAX
(
*
DescriptorSize
+
ExtraSize
,
1024
+
ExtraSize
),
MemoryMapSize
);
...
...
@@ -64,7 +74,8 @@ GetCurrentMemoryMap (
return
NULL
;
}
MemoryMap
=
AllocatePool
(
*
MemoryMapSize
);
OriginalSize
=
*
MemoryMapSize
;
MemoryMap
=
AllocatePool
(
OriginalSize
);
if
(
MemoryMap
==
NULL
)
{
return
NULL
;
}
...
...
@@ -90,6 +101,10 @@ GetCurrentMemoryMap (
*
DescriptorVersion
=
DescriptorVersionValue
;
}
if
(
OriginalMemoryMapSize
!=
NULL
)
{
*
OriginalMemoryMapSize
=
OriginalSize
;
}
return
MemoryMap
;
}
...
...
@@ -398,7 +413,7 @@ CountFreePages (
*
LowerMemory
=
0
;
}
MemoryMap
=
GetCurrentMemoryMap
(
&
MemoryMapSize
,
&
DescriptorSize
,
NULL
,
NULL
);
MemoryMap
=
OcGetCurrentMemoryMap
(
&
MemoryMapSize
,
&
DescriptorSize
,
NULL
,
NULL
,
NULL
,
FALSE
);
if
(
MemoryMap
==
NULL
)
{
return
0
;
}
...
...
@@ -443,38 +458,64 @@ OcPrintMemoryAttributesTable (
{
UINTN
Index
;
CONST
EFI_MEMORY_ATTRIBUTES_TABLE
*
MemoryAttributesTable
;
CONST
EFI_MEMORY_DESCRIPTOR
*
MemoryAttributesEntry
;
EFI_MEMORY_DESCRIPTOR
*
MemoryAttributesEntry
;
for
(
Index
=
0
;
Index
<
gST
->
NumberOfTableEntries
;
++
Index
)
{
if
(
CompareGuid
(
&
gST
->
ConfigurationTable
[
Index
].
VendorGuid
,
&
gEfiMemoryAttributesTableGuid
))
{
MemoryAttributesTable
=
(
CONST
EFI_MEMORY_ATTRIBUTES_TABLE
*
)
gST
->
ConfigurationTable
[
Index
].
VendorTable
;
MemoryAttributesTable
=
OcGetMemoryAttributes
(
&
MemoryAttributesEntry
);
if
(
MemoryAttributesTable
==
NULL
)
{
DEBUG
((
DEBUG_INFO
,
"OCMM: MemoryAttributesTable is not present!
\n
"
));
return
;
}
DEBUG
((
DEBUG_INFO
,
"OCMM: MemoryAttributesTable:
\n
"
));
DEBUG
((
DEBUG_INFO
,
"OCMM: Version - 0x%08x
\n
"
,
MemoryAttributesTable
->
Version
));
DEBUG
((
DEBUG_INFO
,
"OCMM: NumberOfEntries - 0x%08x
\n
"
,
MemoryAttributesTable
->
NumberOfEntries
));
DEBUG
((
DEBUG_INFO
,
"OCMM: DescriptorSize - 0x%08x
\n
"
,
MemoryAttributesTable
->
DescriptorSize
));
DEBUG
((
DEBUG_INFO
,
"OCMM: MemoryAttributesTable:
\n
"
));
DEBUG
((
DEBUG_INFO
,
"OCMM: Version - 0x%08x
\n
"
,
MemoryAttributesTable
->
Version
));
DEBUG
((
DEBUG_INFO
,
"OCMM: NumberOfEntries - 0x%08x
\n
"
,
MemoryAttributesTable
->
NumberOfEntries
));
DEBUG
((
DEBUG_INFO
,
"OCMM: DescriptorSize - 0x%08x
\n
"
,
MemoryAttributesTable
->
DescriptorSize
));
MemoryAttributesEntry
=
(
CONST
EFI_MEMORY_DESCRIPTOR
*
)
(
MemoryAttributesTable
+
1
);
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
));
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
));
MemoryAttributesEntry
=
NEXT_MEMORY_DESCRIPTOR
(
MemoryAttributesEntry
,
MemoryAttributesTable
->
DescriptorSize
);
}
}
MemoryAttributesEntry
=
NEXT_MEMORY_DESCRIPTOR
(
MemoryAttributesEntry
,
MemoryAttributesTable
->
DescriptorSize
);
}
VOID
OcPrintMemoryMap
(
IN
UINTN
MemoryMapSize
,
IN
EFI_MEMORY_DESCRIPTOR
*
MemoryMap
,
IN
UINTN
DescriptorSize
)
{
UINTN
Index
;
UINT32
NumberOfEntries
;
return
;
}
}
NumberOfEntries
=
(
UINT32
)
(
MemoryMapSize
/
DescriptorSize
);
DEBUG
((
DEBUG_INFO
,
"OCMM: MemoryMap:
\n
"
));
DEBUG
((
DEBUG_INFO
,
"OCMM: Size - 0x%08x
\n
"
,
MemoryMapSize
));
DEBUG
((
DEBUG_INFO
,
"OCMM: NumberOfEntries - 0x%08x
\n
"
,
NumberOfEntries
));
DEBUG
((
DEBUG_INFO
,
"OCMM: DescriptorSize - 0x%08x
\n
"
,
DescriptorSize
));
DEBUG
((
DEBUG_INFO
,
"OCMM: MemoryAttributesTable is not present!
\n
"
));
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
));
MemoryMap
=
NEXT_MEMORY_DESCRIPTOR
(
MemoryMap
,
DescriptorSize
);
}
}
EFI_STATUS
...
...
OpenCorePkg.dsc
浏览文件 @
f323be45
...
...
@@ -145,6 +145,7 @@
OpenCorePkg/Application/GopStop/GopStop.inf
OpenCorePkg/Application/HdaCodecDump/HdaCodecDump.inf
OpenCorePkg/Application/KeyTester/KeyTester.inf
OpenCorePkg/Application/MmapDump/MmapDump.inf
OpenCorePkg/Application/OpenControl/OpenControl.inf
OpenCorePkg/Application/PavpProvision/PavpProvision.inf
OpenCorePkg/Application/VerifyMsrE2/VerifyMsrE2.inf
...
...
macbuild.tool
浏览文件 @
f323be45
...
...
@@ -31,6 +31,7 @@ package() {
cp
HdaCodecDump.efi tmp/EFI/OC/Tools/
||
exit
1
cp
HiiDatabase.efi tmp/EFI/OC/Drivers/
||
exit
1
cp
KeyTester.efi tmp/EFI/OC/Tools/
||
exit
1
cp
MmapDump.efi tmp/EFI/OC/Tools/
||
exit
1
cp
NvmExpressDxe.efi tmp/EFI/OC/Drivers/
||
exit
1
cp
OpenCanopy.efi tmp/EFI/OC/Drivers/
||
exit
1
cp
OpenControl.efi tmp/EFI/OC/Tools/
||
exit
1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录