IHANDLE, PROTOCOL_INTERFACE, PROTOCOL_ENTRY, PROTOCOL_NOTIFY and IEVENT

2024.05.03
一边阅读源码,一边借助NDB观察,以弄清楚三者之间的关系:

mProtocolDatabase与gHandleList是总纲:

上NDB:
DxeCore!gHanleList->IHANDLE->PROTOCOL_INTERFACE->PROTOCOL_ENTRY
DxeCore!mProtocolDatabase->PROTOCOL_ENTRY->PROTOCOL_INTERFACE->IHANDLE
PROTOCOL_INTERFACE中的interface 到底指向什么?具体的某个PROTOCOL结构体。

这样用NDB操作过一遍,再来看源代码,就清清楚楚了:

x DxeCore!gHandleList
00000000`3ec53488  DxeCore!gHandleList 
dt -b IHANDLE 00000000`3ec53488-8
   +0x000 Signature        : 0x1`201246dc
   +0x008 AllHandles       :  [ 00000000`efdfffa0 - eeb43920 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x018 Protocols        :  [ 00000000`44505049 - a ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x028 LocateRequest    : 1
   +0x030 Key              : 0xef325ca0
dq 00000000`3ec53488 l1
00000000`3ec53488  00000000`efdfffa0
dt -b IHANDLE 00000000`efdfffa0-8
   +0x000 Signature        : 0x6c646e68
   +0x008 AllHandles       :  [ 00000000`efdff1a0 - 3ec53488 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x018 Protocols        :  [ 00000000`efdfff20 - efdfff20 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x028 LocateRequest    : 0x18d
   +0x030 Key              : 1
da 00000000`efdfffa0-8
00000000`efdfff98  "hndl"
x DxeCore!gHandleList
00000000`3ec53488  DxeCore!gHandleList 
dq 00000000`3ec53488 l1
00000000`3ec53488  00000000`efdfffa0
dt -b IHANDLE 00000000`efdfffa0-8
   +0x000 Signature        : 0x6c646e68
   +0x008 AllHandles       :  [ 00000000`efdff1a0 - 3ec53488 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x018 Protocols        :  [ 00000000`efdfff20 - efdfff20 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x028 LocateRequest    : 0x18d
   +0x030 Key              : 1
da 00000000`efdfffa0-8
00000000`efdfff98  "hndl"
[ndb]!echo "All IHANDLEs can be accessed through AllHandles list."
All IHANDLEs can be accessed through AllHandles list.
[ndb]!echo "PROTOCOL_INTERFACE's for this handle can be accessed through Protocols list."
PROTOCOL_INTERFACE's for this handle can be accessed through Protocols list.
dt -b PROTOCOL_INTERFACE 00000000`efdfff20-8
   +0x000 Signature        : 0x63666970
   +0x008 Link             :  [ 00000000`efdfffb0 - efdfffb0 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x018 Handle           : (null) 
   +0x020 ByProtocol       :  [ 00000000`ef358238 - efdff040 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x030 Protocol         : (null) 
   +0x038 Interface        : 0x00000000`3ec53900 
   +0x040 OpenList         :  [ 00000000`ef358b20 - ef358b20 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x050 OpenListCount    : 1
da 00000000`efdfff20-8
00000000`efdfff18  "pifc"
[ndb]!echo " PROTOCOL_ENTRY    *Protocol;"
 PROTOCOL_ENTRY    *Protocol;
dqs 00000000`efdfff20-8+30 l1
00000000`efdfff48  00000000`efdff018
dt -b PROTOCOL_ENTRY 00000000`efdff018
   +0x000 Signature        : 0x65747270
   +0x008 AllEntries       :  [ 00000000`efdffea0 - 3ec53380 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x018 ProtocolID       : 
      +0x000 Data1            : 0x5b1b31a1
      +0x004 Data2            : 0x9562
      +0x006 Data3            : 0x11d2
      +0x008 Data4            : 
       [00] 0x8e ''
       [01] 0x3f '?'
       [02] 0 ''
       [03] 0xa0 ''
       [04] 0xc9 ''
       [05] 0x69 'i'
       [06] 0x72 'r'
       [07] 0x3b ';'
   +0x028 Protocols        :  [ 00000000`efdfff38 - eeb430b8 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x038 Notify           :  [ 00000000`efdff050 - efdff050 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
da 00000000`efdff018
00000000`efdff018  "prte"
[ndb]!echo "/// Link Entry inserted to mProtocolDatabase -> AllEntries"
/// Link Entry inserted to mProtocolDatabase -> AllEntries
x DxeCore!mProtocolDatabase
00000000`3ec53380  DxeCore!mProtocolDatabase 
dq 00000000`3ec53380
00000000`3ec53380  00000000`efdff020 00000000`eeb38e20
00000000`3ec53390  00000000`00000010 00000000`00000004
00000000`3ec533a0  00000000`00000001 4a828a15`3bc1b285
00000000`3ec533b0  6532fb13`7d4dbfaa 4181da36`b1ee129e
00000000`3ec533c0  a7663792`a404f891 11d4a391`6b30c738
00000000`3ec533d0  4dc13f27`90003b9a 4d1ab443`18a031ab
00000000`3ec533e0  719f1e26`090cc0a5 11d26d3f`09576e91
00000000`3ec533f0  3b7269c9`a000398e 00000001`00000000
dt -b PROTOCOL_ENTRY 00000000`efdff020-8
   +0x000 Signature        : 0x65747270
   +0x008 AllEntries       :  [ 00000000`efdffea0 - 3ec53380 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x018 ProtocolID       : 
      +0x000 Data1            : 0x5b1b31a1
      +0x004 Data2            : 0x9562
      +0x006 Data3            : 0x11d2
      +0x008 Data4            : 
       [00] 0x8e ''
       [01] 0x3f '?'
       [02] 0 ''
       [03] 0xa0 ''
       [04] 0xc9 ''
       [05] 0x69 'i'
       [06] 0x72 'r'
       [07] 0x3b ';'
   +0x028 Protocols        :  [ 00000000`efdfff38 - eeb430b8 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x038 Notify           :  [ 00000000`efdff050 - efdff050 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
da 00000000`efdff020-8
00000000`efdff018  "prte"
[ndb]!echo "Protocols -> All protocol interfaces"
Protocols -> All protocol interfaces
[ndb]!echo "Different offset:    +0x020 ByProtocol       :  [ 00000000`ef358238 - efdff040 ]"
invalid command name "00000000`ef358238"
!echo "Different offset:    +0x020 ByProtocol       :  [ 00000000`ef358238 - efdff040 ]"
No command echo found
dt -b PROTOCOL_INTERFACE 00000000`efdfff38-20
   +0x000 Signature        : 0x63666970
   +0x008 Link             :  [ 00000000`efdfffb0 - efdfffb0 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x018 Handle           : (null) 
   +0x020 ByProtocol       :  [ 00000000`ef358238 - efdff040 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x030 Protocol         : (null) 
   +0x038 Interface        : 0x00000000`3ec53900 
   +0x040 OpenList         :  [ 00000000`ef358b20 - ef358b20 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x050 OpenListCount    : 1
da 00000000`efdfff38-20
00000000`efdfff18  "pifc"
dq 00000000`efdfff38-20+18 l1
00000000`efdfff30  00000000`efdfff98
da 00000000`efdfff98
00000000`efdfff98  "hndl"
dt -b IHANDLE 00000000`efdfff98
   +0x000 Signature        : 0x6c646e68
   +0x008 AllHandles       :  [ 00000000`efdff1a0 - 3ec53488 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x018 Protocols        :  [ 00000000`efdfff20 - efdfff20 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x028 LocateRequest    : 0x18d
   +0x030 Key              : 1
[ndb]!echo "To see what interface it is:dq 00000000`efdfff38-20+18 l1 00000000`efdfff30  00000000`efdfff98 da 00000000`efdfff98 00000000`efdfff98  "hndl" dt -b IHANDLE 00000000`efdfff98    +0x000 Signature        : 0x6c646e68    +0x008 AllHandles       :  [ 00000000`efdff1a0 - 3ec53488 ]       +0x000 ForwardLink      : (null)        +0x008 BackLink         : (null)     +0x018 Protocols        :  [ 00000000`efdfff20 - efdfff20 ]       +0x000 ForwardLink      : (null)        +0x008 BackLink         : (null)     +0x028 LocateRequest    : 0x18d    +0x030 Key              : 1"
invalid command name "00000000`efdff1a0"
!echo "To see what interface it is:dq 00000000`efdfff38-20+18 l1 00000000`efdfff30  00000000`efdfff98 da 00000000`efdfff98 00000000`efdfff98  "hndl" dt -b IHANDLE 00000000`efdfff98    +0x000 Signature        : 0x6c646e68    +0x008 AllHandles       :  [ 00000000`efdff1a0 - 3ec53488 ]       +0x000 ForwardLink      : (null)        +0x008 BackLink         : (null)     +0x018 Protocols        :  [ 00000000`efdfff20 - efdfff20 ]       +0x000 ForwardLink      : (null)        +0x008 BackLink         : (null)     +0x028 LocateRequest    : 0x18d    +0x030 Key              : 1"
Syntax error in extension cmd

dqs 0x00000000`3ec53900
00000000`3ec53900  00000000`00001000
00000000`3ec53908  00000000`00000000
00000000`3ec53910  00000000`effd0018
00000000`3ec53918  00000000`efde8998
00000000`3ec53920  00000000`ef358f18
00000000`3ec53928  00000000`00000000
00000000`3ec53930  00000000`00000000
00000000`3ec53938  00000000`00000000
00000000`3ec53940  00000000`3ec27000 DxeCore!SwitchStack.obj+0x3ec27000
00000000`3ec53948  00000000`0004a000
00000000`3ec53950  00000004`00000003
00000000`3ec53958  00000000`00000000
00000000`3ec53960  00000000`3ec27000 DxeCore!SwitchStack.obj+0x3ec27000
00000000`3ec53968  00000000`0000004a
00000000`3ec53970  00000000`00000000
00000000`3ec53978  00000000`00000004

da 00000000`effd0018
00000000`effd0018  "IBI SYSTF"
dqs 00000000`effd0018
00000000`effd0018  54535953`20494249
00000000`effd0020  00000078`00020046
00000000`effd0028  00000000`3b765e4a
00000000`effd0030  00000000`effde318
00000000`effd0038  00000000`00010000
00000000`effd0040  00000000`ef22a918
00000000`effd0048  00000000`eaa0e400 ConSplitterDxe!mConIn+0x10
00000000`effd0050  00000000`eeb43918
00000000`effd0058  00000000`eeb3b020
00000000`effd0060  00000000`ef228e98
00000000`effd0068  00000000`eaa0e190 ConSplitterDxe!mStdErr+0x10
00000000`effd0070  00000000`effdff18
00000000`effd0078  00000000`3ec531d8 DxeCore!mBootServices
00000000`effd0080  00000000`0000000d
00000000`effd0088  00000000`effdfb18
00000000`effd0090  afafafaf`6c617470

interface 就是指向此EFI_LOADED_IMAGE_PROTOCOL:

2024.05.04
继续,串上PROTOCOL_NOTIFY与IEVENT

dt -b PROTOCOL_ENTRY 00000000`efdffea0-8
   +0x000 Signature        : 0x65747270
   +0x008 AllEntries       :  [ 00000000`efdff9a0 - efdff020 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x018 ProtocolID       : 
      +0x000 Data1            : 0x96f46153
      +0x004 Data2            : 0x97a7
      +0x006 Data3            : 0x4793
      +0x008 Data4            : 
       [00] 0xac ''
       [01] 0xc1 ''
       [02] 0xfa ''
       [03] 0x19 ''
       [04] 0xbf ''
       [05] 0x78 'x'
       [06] 0xea ''
       [07] 0x97 ''
   +0x028 Protocols        :  [ 00000000`efdffec0 - efdffec0 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x038 Notify           :  [ 00000000`efdffc28 - efdffc28 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
dt -b PROTOCOL_NOTIFY 00000000`efdffc28-10
   +0x000 Signature        : 0x6e747270
   +0x008 Protocol         : (null) 
   +0x010 Link             :  [ 00000000`efdffed0 - efdffed0 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x020 Event            : 0x00000000`efdffb18 
   +0x028 Position         : (null) 
da 00000000`efdffc28-10
00000000`efdffc18  "prtn"
dt -b IEVENT 00000000`efdffb18
   +0x000 Signature        : 0x746e7665
   +0x008 Type             : 0x200
   +0x00c SignalCount      : 0
   +0x010 SignalLink       :  [ 00000000`3ec540e0 - efdfe028 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x020 NotifyTpl        : 8
   +0x028 NotifyFunction   : (null) 
   +0x030 NotifyContext    : (null) 
   +0x038 EventGroup       : 
      +0x000 Data1            : 0
      +0x004 Data2            : 0
      +0x006 Data3            : 0
      +0x008 Data4            : 
       [00] 0 ''
       [01] 0 ''
       [02] 0 ''
       [03] 0 ''
       [04] 0 ''
       [05] 0 ''
       [06] 0 ''
       [07] 0 ''
   +0x048 NotifyLink       :  [ 00000000`00000000 - 0 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x058 ExFlag           : 0x2 ''
   +0x060 RuntimeData      : 
      +0x000 Type             : 0
      +0x008 NotifyTpl        : 0
      +0x010 NotifyFunction   : (null) 
      +0x018 NotifyContext 
   : (null) 
      +0x020 Event            : (null) 
      +0x028 Link             :  [ 00000000`00000000 - 0 ]
         +0x000 ForwardLink      : (null) 
         +0x008 BackLink         : (null) 
   +0x098 Timer            : 
      +0x000 Link             :  [ 00000000`00000000 - 0 ]
         +0x000 ForwardLink      : (null) 
         +0x008 BackLink         : (null) 
      +0x010 TriggerTime      : 0
      +0x018 Period           : 0
da 00000000`efdffb18
00000000`efdffb18  "evnt"

DxeCore!gIdleLoopEvent

X DxeCore!gIdleLoopEvent
00000000`3ec55610  DxeCore!gIdleLoopEvent 
dqs 00000000`3ec55610 l1
00000000`3ec55610  00000000`efdfed98
dt -b IEVENT 00000000`efdfed98
   +0x000 Signature        : 0x746e7665
   +0x008 Type             : 0x200
   +0x00c SignalCount      : 1
   +0x010 SignalLink       :  [ 00000000`efdfeca8 - efdfe128 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x020 NotifyTpl        : 0x10
   +0x028 NotifyFunction   : (null) 
   +0x030 NotifyContext    : (null) 
   +0x038 EventGroup       : 
      +0x000 Data1            : 0x3c8d294c
      +0x004 Data2            : 0x5fc3
      +0x006 Data3            : 0x4451
      +0x008 Data4            : 
       [00] 0xbb ''
       [01] 0x31 '1'
       [02] 0xc4 ''
       [03] 0xc0 ''
       [04] 0x32 '2'
       [05] 0x29 ')'
       [06] 0x5e '^'
       [07] 0x6c 'l'
   +0x048 NotifyLink       :  [ 00000000`3ec55718 - 3ec55718 ]
      +0x000 ForwardLink      : (null) 
      +0x008 BackLink         : (null) 
   +0x058 ExFlag           : 0x1 ''
   +0x060 RuntimeData      : 
      +0x000 Type             : 0
      +0x008 NotifyTpl        : 0

+0x010 NotifyFunction   : (null) 
      +0x018 NotifyContext    : (null) 
      +0x020 Event            : (null) 
      +0x028 Link             :  [ 00000000`00000000 - 0 ]
         +0x000 ForwardLink      : (null) 
         +0x008 BackLink         : (null) 
   +0x098 Timer            : 
      +0x000 Link             :  [ 00000000`00000000 - 0 ]
         +0x000 ForwardLink      : (null) 
         +0x008 BackLink         : (null) 
      +0x010 TriggerTime      : 0
      +0x018 Period           : 0
da 00000000`efdfed98
00000000`efdfed98  "evnt"
?? sizeof(IEVENT)
unsigned int64 0xb8
dqs 00000000`efdfed98 lb8/8
00000000`efdfed98  00000000`746e7665
00000000`efdfeda0  00000001`00000200
00000000`efdfeda8  00000000`efdfeca8
00000000`efdfedb0  00000000`efdfe128
00000000`efdfedb8  00000000`00000010
00000000`efdfedc0  00000000`3ec3e9a4 DxeCore!EfiEventEmptyFunction
00000000`efdfedc8  00000000`00000000
00000000`efdfedd0  44515fc3`3c8d294c
00000000`efdfedd8  6c5e2932`c0c431bb
00000000`efdfede0  00000000`3ec55718 DxeCore!gEventQueue+0x100
00000000`efdfede8  00000000`3ec55718 DxeCore!gEventQueue+0x100
00000000`efdfedf0  00000000`00000001
00000000`efdfedf8  00000000`00000000
00000000`efdfee00  00000000`00000000
00000000`efdfee08  00000000`00000000
00000000`efdfee10  00000000`00000000
00000000`efdfee18  00000000`00000000
00000000`efdfee20  00000000`00000000
00000000`efdfee28  00000000`00000000
00000000`efdfee30  00000000`00000000
00000000`efdfee38  00000000`00000000
00000000`efdfee40  00000000`00000000
00000000`efdfee48  00000000`00000000
u DxeCore!EfiEventEmptyFunction
DxeCore!EfiEventEmptyFunction:
3ec3e9a4 d65f03c0 ret    
DxeCore!PeCoffLoaderGetImageInfo:
3ec3e9a8 a9ba7bfd stp    x29, x30, [sp, #-0x60]!
3ec3e9ac 910003fd mov    x29, sp
3ec3e9b0 a90153f3 stp    x19, x20, [sp, #0x10]
3ec3e9b4 aa0003f3 mov    x19, x0
3ec3e9b8 d00000a0 adrp    x0, #0x3ec54000
3ec3e9bc a9025bf5 stp    x21, x22, [sp, #0x20]
3ec3e9c0 a90363f7 stp    x23, x24, [sp, #0x30]
作者:朱博渊  创建时间:2024-05-03 22:37
最后编辑:朱博渊  更新时间:2024-11-15 17:44