-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addresses part of #70 Signed-off-by: Dave Thaler <[email protected]>
- Loading branch information
Showing
12 changed files
with
147 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// SPDX-License-Identifier: MIT | ||
#pragma once | ||
#include "usersim/ke.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
typedef _IRQL_requires_max_(PASSIVE_LEVEL) _IRQL_requires_same_ VOID NTAPI ETWENABLECALLBACK( | ||
_In_ LPCGUID SourceId, | ||
_In_ ULONG ControlCode, | ||
_In_ UCHAR Level, | ||
_In_ ULONGLONG MatchAnyKeyword, | ||
_In_ ULONGLONG MatchAllKeyword, | ||
_In_opt_ PEVENT_FILTER_DESCRIPTOR FilterData, | ||
_Inout_opt_ PVOID CallbackContext); | ||
|
||
typedef ETWENABLECALLBACK* PETWENABLECALLBACK; | ||
|
||
_IRQL_requires_max_(PASSIVE_LEVEL) USERSIM_API NTSTATUS EtwRegister( | ||
_In_ LPCGUID provider_id, | ||
_In_opt_ PETWENABLECALLBACK enable_callback, | ||
_In_opt_ PVOID callback_context, | ||
_Out_ PREGHANDLE reg_handle); | ||
|
||
_IRQL_requires_max_(PASSIVE_LEVEL) USERSIM_API NTSTATUS EtwUnregister(_In_ REGHANDLE reg_handle); | ||
|
||
_IRQL_requires_max_(HIGH_LEVEL) USERSIM_API NTSTATUS EtwWriteTransfer( | ||
REGHANDLE reg_handle, | ||
_In_ EVENT_DESCRIPTOR const* descriptor, | ||
_In_opt_ LPCGUID activity_id, | ||
_In_opt_ LPCGUID related_activity_id, | ||
_In_range_(2, 128) UINT32 data_size, | ||
_Inout_cap_(cData) EVENT_DATA_DESCRIPTOR* data); | ||
|
||
USERSIM_API NTSTATUS | ||
EtwSetInformation( | ||
REGHANDLE reg_handle, | ||
EVENT_INFO_CLASS information_class, | ||
_In_opt_ PVOID information, | ||
UINT16 const information_size); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
add_library(usersim SHARED | ||
dllmain.cpp | ||
etw.cpp | ||
ex.cpp | ||
fault_injection.cpp | ||
fault_injection.h | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include "platform.h" | ||
#include "usersim/etw.h" | ||
|
||
typedef struct | ||
{ | ||
GUID provider_id; | ||
PETWENABLECALLBACK enable_callback; | ||
PVOID callback_context; | ||
} usersim_etw_provider_t; | ||
|
||
_IRQL_requires_max_(PASSIVE_LEVEL) NTSTATUS EtwRegister( | ||
_In_ LPCGUID provider_id, | ||
_In_opt_ PETWENABLECALLBACK enable_callback, | ||
_In_opt_ PVOID callback_context, | ||
_Out_ PREGHANDLE reg_handle) | ||
{ | ||
usersim_etw_provider_t* provider = (usersim_etw_provider_t*)usersim_allocate(sizeof(*provider)); | ||
if (provider == nullptr) { | ||
return STATUS_NO_MEMORY; | ||
} | ||
provider->provider_id = *provider_id; | ||
provider->enable_callback = enable_callback; | ||
provider->callback_context = callback_context; | ||
*reg_handle = (uintptr_t)provider; | ||
return STATUS_SUCCESS; | ||
} | ||
|
||
_IRQL_requires_max_(PASSIVE_LEVEL) NTSTATUS EtwUnregister(_In_ REGHANDLE reg_handle) | ||
{ | ||
usersim_free((void*)(uintptr_t)reg_handle); | ||
return STATUS_SUCCESS; | ||
} | ||
|
||
NTSTATUS | ||
EtwWriteTransfer( | ||
REGHANDLE reg_handle, | ||
_In_ EVENT_DESCRIPTOR const* desc, | ||
_In_opt_ LPCGUID activity_id, | ||
_In_opt_ LPCGUID related_activity_id, | ||
_In_range_(2, 128) UINT32 data_size, | ||
_Inout_cap_(cData) EVENT_DATA_DESCRIPTOR* data) | ||
{ | ||
usersim_etw_provider_t* provider = (usersim_etw_provider_t*)reg_handle; | ||
|
||
// TODO(#70): implement similar to usersim_trace_logging_write(). | ||
UNREFERENCED_PARAMETER(provider); | ||
UNREFERENCED_PARAMETER(desc); | ||
UNREFERENCED_PARAMETER(activity_id); | ||
UNREFERENCED_PARAMETER(related_activity_id); | ||
UNREFERENCED_PARAMETER(data_size); | ||
UNREFERENCED_PARAMETER(data); | ||
return STATUS_SUCCESS; | ||
} | ||
|
||
NTSTATUS | ||
EtwSetInformation( | ||
REGHANDLE reg_handle, EVENT_INFO_CLASS information_class, _In_opt_ PVOID information, UINT16 const information_size) | ||
{ | ||
UNREFERENCED_PARAMETER(reg_handle); | ||
UNREFERENCED_PARAMETER(information_class); | ||
UNREFERENCED_PARAMETER(information); | ||
UNREFERENCED_PARAMETER(information_size); | ||
return STATUS_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// SPDX-License-Identifier: MIT | ||
|
||
#if !defined(CMAKE_NUGET) | ||
#include <catch2/catch_all.hpp> | ||
#else | ||
#include <catch2/catch.hpp> | ||
#endif | ||
#include "usersim/etw.h" | ||
|
||
TEST_CASE("EtwRegister", "[etw]") | ||
{ | ||
GUID guid = {}; | ||
REGHANDLE reg_handle; | ||
REQUIRE(EtwRegister(&guid, nullptr, nullptr, ®_handle) == STATUS_SUCCESS); | ||
REQUIRE(EtwUnregister(reg_handle) == STATUS_SUCCESS); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters