OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
EventQueue.c
Go to the documentation of this file.
1
19#include <AppleMacEfi.h>
20
21#include <Library/BaseLib.h>
22#include <Library/BaseMemoryLib.h>
23#include <Library/DebugLib.h>
24#include <Library/MemoryAllocationLib.h>
25#include <Library/UefiBootServicesTableLib.h>
26#include <Library/UefiLib.h>
27#include <Library/UefiRuntimeServicesTableLib.h>
28
29#include "AppleEventInternal.h"
30
31// APPLE_EVENT_QUEUE_SIGNATURE
32#define APPLE_EVENT_QUEUE_SIGNATURE SIGNATURE_32 ('A', 'E', 'v', 'Q')
33
34// APPLE_EVENT_QUEUE_FROM_LIST_ENTRY
35#define APPLE_EVENT_QUEUE_FROM_LIST_ENTRY(ListEntry) \
36 CR ((ListEntry), APPLE_EVENT_QUEUE, Link, APPLE_EVENT_QUEUE_SIGNATURE)
37
38// APPLE_EVENT_QUEUE
44
45// mQueueEvent
46STATIC EFI_EVENT mQueueEvent = NULL;
47
48// mQueueEventCreated
49STATIC BOOLEAN mQueueEventCreated = FALSE;
50
51// mEventQueueList
52STATIC LIST_ENTRY mQueue = INITIALIZE_LIST_HEAD_VARIABLE (mQueue);
53
54// mQueueLock
55STATIC EFI_LOCK mQueueLock = {
56 0,
57 0,
58 FALSE
59};
60
61// InternalSignalAndCloseQueueEvent
62VOID
64 VOID
65 )
66{
67 DEBUG ((DEBUG_VERBOSE, "InternalSignalAndCloseQueueEvent\n"));
68
69 gBS->SignalEvent (mQueueEvent);
70
71 if (mQueueEventCreated && (mQueueEvent != NULL)) {
72 gBS->CloseEvent (mQueueEvent);
73 }
74}
75
76// InternalQueueEventNotifyFunction
77STATIC
78VOID
79EFIAPI
81 IN EFI_EVENT Event,
82 IN VOID *Context
83 )
84{
85 EFI_STATUS Status;
86 LIST_ENTRY *EventQueueEntry;
87 APPLE_EVENT_QUEUE *EventQueue;
88
89 DEBUG ((DEBUG_VERBOSE, "InternalQueueEventNotifyFunction\n"));
90
92 do {
93 Status = EfiAcquireLockOrFail (&mQueueLock);
94 } while (EFI_ERROR (Status));
95
97
98 EventQueueEntry = GetFirstNode (&mQueue);
99
100 while (!IsNull (&mQueue, EventQueueEntry)) {
101 EventQueue = APPLE_EVENT_QUEUE_FROM_LIST_ENTRY (EventQueueEntry);
102
103 InternalSignalEvents (EventQueue->Information);
104
105 if ( ((EventQueue->Information->EventType & APPLE_ALL_KEYBOARD_EVENTS) != 0)
106 && (EventQueue->Information->EventData.KeyData != NULL))
107 {
108 FreePool (
109 (VOID *)EventQueue->Information->EventData.KeyData
110 );
111 }
112
113 EventQueueEntry = RemoveEntryList (EventQueueEntry);
114 FreePool ((VOID *)EventQueue->Information);
115 FreePool ((VOID *)EventQueue);
116 }
117
119 EfiReleaseLock (&mQueueLock);
120 }
121}
122
123// InternalCreateQueueEvent
124VOID
126 VOID
127 )
128{
129 EFI_STATUS Status;
130
131 DEBUG ((DEBUG_VERBOSE, "InternalCreateQueueEvent\n"));
132
133 EfiInitializeLock (&mQueueLock, TPL_NOTIFY);
134
135 Status = gBS->CreateEvent (
136 EVT_NOTIFY_SIGNAL,
137 TPL_CALLBACK,
139 NULL,
141 );
142
143 if (!EFI_ERROR (Status)) {
144 mQueueEventCreated = TRUE;
145 }
146}
147
148// EventCreateAppleEventQueueInfo
151 IN APPLE_EVENT_DATA EventData,
152 IN APPLE_EVENT_TYPE EventType,
153 IN DIMENSION *PointerPosition,
154 IN APPLE_MODIFIER_MAP Modifiers
155 )
156{
157 APPLE_EVENT_INFORMATION *QueueInfo;
158 EFI_TIME CreationTime;
159
160 DEBUG ((DEBUG_VERBOSE, "EventCreateAppleEventQueueInfo\n"));
161
162 QueueInfo = AllocateZeroPool (sizeof (*QueueInfo));
163
164 if (QueueInfo != NULL) {
165 gRT->GetTime (&CreationTime, NULL);
166
167 QueueInfo->EventType = EventType;
168 QueueInfo->EventData = EventData;
169 QueueInfo->Modifiers = Modifiers;
170 QueueInfo->CreationTime.Year = CreationTime.Year;
171 QueueInfo->CreationTime.Month = CreationTime.Month;
172 QueueInfo->CreationTime.Day = CreationTime.Day;
173 QueueInfo->CreationTime.Hour = CreationTime.Hour;
174 QueueInfo->CreationTime.Minute = CreationTime.Minute;
175 QueueInfo->CreationTime.Second = CreationTime.Second;
176 QueueInfo->CreationTime.Pad1 = CreationTime.Pad1;
177
178 if (PointerPosition != NULL) {
179 CopyMem (
180 (VOID *)&QueueInfo->PointerPosition,
181 (VOID *)PointerPosition,
182 sizeof (*PointerPosition)
183 );
184 }
185 } else {
186 DEBUG ((DEBUG_VERBOSE, "EventCreateAppleEventQueueInfo alloc failure\n"));
187 }
188
189 return QueueInfo;
190}
191
192// EventAddEventToQueue
193VOID
195 IN APPLE_EVENT_INFORMATION *Information
196 )
197{
198 EFI_STATUS Status;
199 APPLE_EVENT_QUEUE *EventQueue;
200
201 DEBUG ((DEBUG_VERBOSE, "EventAddEventToQueue\n"));
202
203 if (mQueueEventCreated) {
204 do {
205 Status = EfiAcquireLockOrFail (&mQueueLock);
206 } while (EFI_ERROR (Status));
207
208 EventQueue = AllocateZeroPool (sizeof (*EventQueue));
209
210 if (EventQueue != NULL) {
212 EventQueue->Information = Information;
213
214 InsertTailList (&mQueue, &EventQueue->Link);
215 } else {
216 DEBUG ((DEBUG_VERBOSE, "EventAddEventToQueue alloc failure\n"));
217 }
218
219 EfiReleaseLock (&mQueueLock);
220 gBS->SignalEvent (mQueueEvent);
221 }
222}
223
224// EventCreateEventQueue
225EFI_STATUS
227 IN APPLE_EVENT_DATA EventData,
228 IN APPLE_EVENT_TYPE EventType,
229 IN APPLE_MODIFIER_MAP Modifiers
230 )
231{
232 EFI_STATUS Status;
233 APPLE_EVENT_INFORMATION *Information;
234
235 DEBUG ((DEBUG_VERBOSE, "EventCreateEventQueue\n"));
236
237 Status = EFI_INVALID_PARAMETER;
238
239 if ((EventData.Raw != 0) || (Modifiers != 0)) {
240 Information = EventCreateAppleEventQueueInfo (
241 EventData,
242 EventType,
243 NULL,
244 Modifiers
245 );
246
247 Status = EFI_OUT_OF_RESOURCES;
248
249 if (Information != NULL) {
250 EventAddEventToQueue (Information);
251
252 Status = EFI_SUCCESS;
253 } else {
254 DEBUG ((DEBUG_VERBOSE, "EventCreateEventQueue alloc failure\n"));
255 }
256 }
257
258 return Status;
259}
UINT32 APPLE_EVENT_TYPE
Definition AppleEvent.h:45
#define APPLE_ALL_KEYBOARD_EVENTS
Definition AppleEvent.h:42
VOID InternalFlagAllEventsReady(VOID)
VOID InternalSignalEvents(IN APPLE_EVENT_INFORMATION *Information)
VOID InternalRemoveUnregisteredEvents(VOID)
UINT16 APPLE_MODIFIER_MAP
Definition AppleHid.h:102
#define APPLE_EVENT_QUEUE_FROM_LIST_ENTRY(ListEntry)
Definition EventQueue.c:35
EFI_STATUS EventCreateEventQueue(IN APPLE_EVENT_DATA EventData, IN APPLE_EVENT_TYPE EventType, IN APPLE_MODIFIER_MAP Modifiers)
Definition EventQueue.c:226
STATIC EFI_LOCK mQueueLock
Definition EventQueue.c:55
APPLE_EVENT_INFORMATION * EventCreateAppleEventQueueInfo(IN APPLE_EVENT_DATA EventData, IN APPLE_EVENT_TYPE EventType, IN DIMENSION *PointerPosition, IN APPLE_MODIFIER_MAP Modifiers)
Definition EventQueue.c:150
STATIC LIST_ENTRY mQueue
Definition EventQueue.c:52
STATIC VOID EFIAPI InternalQueueEventNotifyFunction(IN EFI_EVENT Event, IN VOID *Context)
Definition EventQueue.c:80
#define APPLE_EVENT_QUEUE_SIGNATURE
Definition EventQueue.c:32
VOID InternalCreateQueueEvent(VOID)
Definition EventQueue.c:125
STATIC BOOLEAN mQueueEventCreated
Definition EventQueue.c:49
VOID InternalSignalAndCloseQueueEvent(VOID)
Definition EventQueue.c:63
STATIC EFI_EVENT mQueueEvent
Definition EventQueue.c:46
VOID EventAddEventToQueue(IN APPLE_EVENT_INFORMATION *Information)
Definition EventQueue.c:194
EFI_BOOT_SERVICES * gBS
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_RUNTIME_SERVICES * gRT
struct APPLE_EVENT_INFORMATION::@51 CreationTime
APPLE_EVENT_DATA EventData
Definition AppleEvent.h:81
APPLE_EVENT_TYPE EventType
Definition AppleEvent.h:80
APPLE_MODIFIER_MAP Modifiers
Definition AppleEvent.h:82
LIST_ENTRY Link
Definition EventQueue.c:41
APPLE_EVENT_INFORMATION * Information
Definition EventQueue.c:42
APPLE_KEY_EVENT_DATA * KeyData
Definition AppleEvent.h:58