-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement kevent #96
Implement kevent #96
Conversation
Signed-off-by: Alan Jowett <[email protected]>
SynchronizationEvent | ||
} EVENT_TYPE; | ||
|
||
typedef struct _kevent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this not an abstraction for a HANDLE
for a simple event in usermode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because kernel mode events aren't handles that require a call to CloseHandle on. Valid kernel mode code can initialize events without calling any close API on them.
As an example, this is valid, but it we use a simple Win32 event via a handle it leaks handles.
/**
* @brief Send a message to the specified CPU and wait for it to complete.
*
* @param[in] message Message to send.
* @param[in] cpu_id CPU to send the message to.
*/
_IRQL_requires_max_(APC_LEVEL) static void _ebpf_epoch_send_message_and_wait(
_In_ ebpf_epoch_cpu_message_t* message, uint32_t cpu_id)
{
KDPC dpc;
// Initialize the completion event.
KeInitializeEvent(&message->completion_event, NotificationEvent, FALSE);
// Initialize the dpc
KeInitializeDpc(&dpc, _ebpf_epoch_messenger_worker, NULL);
KeSetTargetProcessorDpc(&dpc, (uint8_t)cpu_id);
// Send the message.
KeInsertQueueDpc(&dpc, message, NULL);
// Wait for the message to complete.
KeWaitForSingleObject(&message->completion_event, Executive, KernelMode, FALSE, NULL);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Alan-Jowett semaphores have the same difference between user and kernel mode and the usersim implementation of semaphores does use handles. See usersim_free_semaphores()
which is called by usersim_platform_terminate()
.
Signed-off-by: Alan Jowett <[email protected]>
Note:
This implementation permits using KEVENT as a local stack variable without leaking large numbers of Win32 handles.
It is a prerequisite to fixing microsoft/ebpf-for-windows#2787.