ReactOS 0.4.17-dev-1281-g065abb3
errreport.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS SuperSpeed USB Hub Driver
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE: Live kernel dump requests and their per boot throttle
5 * COPYRIGHT: Copyright 2026 Justin Miller <justin.miller@reactos.org>
6 */
7
8#include "usbhub3.h"
9
10#define NDEBUG
11#include <debug.h>
12
13/* Work item context for a request made at DISPATCH_LEVEL */
15{
18};
19
21
22/*
23 * The throttle lives in a volatile subkey of the device's hardware key,
24 * so it resets every boot. Any failure reads as "not throttled".
25 */
27static
30HubOpenThrottleKey(
31 _In_ WDFDEVICE Device,
32 _Out_ WDFKEY* WerKey)
33{
34 DECLARE_CONST_UNICODE_STRING(WerName, L"Wer");
37
38 *WerKey = NULL;
39
46 {
47 DPRINT1("Hub %p hardware key open failed 0x%lx\n", Device, Status);
48 return Status;
49 }
50
52 &WerName,
55 NULL,
57 WerKey);
58 if (!NT_SUCCESS(Status))
59 DPRINT1("Hub %p WER throttle key create failed 0x%lx\n", Device, Status);
60
62 return Status;
63}
64
66static
69HubReadThrottleMask(
70 _In_ WDFDEVICE Device)
71{
72 DECLARE_CONST_UNICODE_STRING(MaskName, L"ThrottleMask");
73 WDFKEY Key;
74 ULONG Mask = 0;
76
77 if (!NT_SUCCESS(HubOpenThrottleKey(Device, &Key)))
78 return 0;
79
80 Status = WdfRegistryQueryULong(Key, &MaskName, &Mask);
81 if (!NT_SUCCESS(Status))
82 {
84 DPRINT1("Reading the WER throttle failed 0x%lx\n", Status);
85 Mask = 0;
86 }
87
89 return Mask;
90}
91
92/* No live dump API exists, so the throttle is honored but nothing is captured and no bit is ever added */
96HubSubmitLiveDump(
97 _In_ WDFDEVICE Device,
100{
101 PAGED_CODE();
102
103 if (HubReadThrottleMask(Device) & (1UL << (Code & 0x1F)))
104 {
105 DPRINT("Hub %p live dump 0x%lx throttled\n", Device, Code);
106 return STATUS_UNSUCCESSFUL;
107 }
108
109 DPRINT1("USBHUB3 live dump 0x%lx, reason 0x%lx, not supported\n", Code, SubReason);
110
112}
113
114static
115ULONG
116NTAPI
119{
120 switch (Type)
121 {
124
127
130
131 default:
132 return 0;
133 }
134}
135
136static
137VOID
138NTAPI
140 _In_ WDFWORKITEM WorkItem)
141{
142 HubReportWork* Work = HubGetReportWork(WorkItem);
143
144 HubCreateReport((WDFDEVICE)WdfWorkItemGetParentObject(WorkItem), Work->Type, Work->SubReason);
146}
147
150NTAPI
152 _In_ WDFDEVICE HubFdo,
155{
158 WDFWORKITEM WorkItem;
160
162 return HubSubmitLiveDump(HubFdo, HubReportCode(Type), SubReason);
163
166 Attributes.ParentObject = HubFdo;
167
168 Status = WdfWorkItemCreate(&Config, &Attributes, &WorkItem);
169 if (!NT_SUCCESS(Status))
170 {
171 DPRINT1("Hub %p report work item create failed 0x%lx\n", HubFdo, Status);
172 return Status;
173 }
174
175 HubGetReportWork(WorkItem)->Type = Type;
176 HubGetReportWork(WorkItem)->SubReason = SubReason;
178
179 return STATUS_SUCCESS;
180}
#define PAGED_CODE()
Type
Definition: Type.h:7
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
Definition: fdo.h:132
_In_ ULONG Attributes
Definition: dispmprt.h:1077
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define L(x)
Definition: resources.c:13
#define _IRQL_requires_(irql)
Definition: driverspecs.h:229
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
_Out_ WDFKEY * WerKey
Definition: errreport.cpp:33
NTSTATUS NTAPI HubCreateReport(_In_ WDFDEVICE HubFdo, _In_ HubReport Type, _In_ ULONG SubReason)
Definition: errreport.cpp:151
static VOID NTAPI HubEvtReportWorkItem(_In_ WDFWORKITEM WorkItem)
Definition: errreport.cpp:139
WDFKEY HardwareKey
Definition: errreport.cpp:35
_In_ ULONG _In_ ULONG SubReason
Definition: errreport.cpp:100
return STATUS_NOT_SUPPORTED
Definition: errreport.cpp:111
static ULONG NTAPI HubReportCode(_In_ HubReport Type)
Definition: errreport.cpp:117
WdfRegistryClose(HardwareKey)
NTSTATUS Status
Definition: errreport.cpp:36
unsigned int Mask
Definition: fpcontrol.c:82
Status
Definition: gdiplustypes.h:24
HubReport
Definition: hubdriver.h:144
@ DeviceEnumerationFailed
@ HubResetSucceeded
#define HUB_LIVEDUMP_HUB_RESET_FAILED
Definition: hubdriver.h:152
#define HUB_LIVEDUMP_ENUMERATION_FAILED
Definition: hubdriver.h:154
#define HUB_LIVEDUMP_HUB_RESET_OK
Definition: hubdriver.h:151
return WdfDeviceOpenRegistryKey(Child->m_Pdo->m_Device, PLUGPLAY_REGKEY_DEVICE, Access, WDF_NO_OBJECT_ATTRIBUTES, Key)
return WdfRegistryCreateKey(Parent, Name, CreateAccess, REG_OPTION_NON_VOLATILE, NULL, WDF_NO_OBJECT_ATTRIBUTES, Key)
WdfWorkItemEnqueue(WorkItem)
_Must_inspect_result_ _In_ PUCXHUB_DEVICE_CREATE_INFO _Out_ UCXUSBDEVICE * Device
Definition: hubucx.h:258
_In_opt_ PVOID _In_ PUCXHUB_WORKITEM WorkItem
Definition: hubucx.h:227
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define KEY_READ
Definition: nt_native.h:1026
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1021
#define KEY_WRITE
Definition: nt_native.h:1034
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1063
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
ULONG SubReason
Definition: errreport.cpp:17
HubReport Type
Definition: errreport.cpp:16
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PUCX_CONTROLLER_CONFIG Config
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
WdfObjectDelete(String)
#define DECLARE_CONST_UNICODE_STRING(_variablename, _string)
Definition: wdfcore.h:161
_In_ UCHAR _In_ UCHAR _In_ ULONG Code
Definition: wdfdevice.h:1707
#define WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(_attributes, _contexttype)
Definition: wdfobject.h:170
#define WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(_contexttype, _castingfunction)
Definition: wdfobject.h:350
#define WDF_NO_OBJECT_ATTRIBUTES
Definition: wdftypes.h:105
FORCEINLINE VOID WDF_WORKITEM_CONFIG_INIT(_Out_ PWDF_WORKITEM_CONFIG Config, _In_ PFN_WDF_WORKITEM EvtWorkItemFunc)
Definition: wdfworkitem.h:85
#define PLUGPLAY_REGKEY_DEVICE
Definition: iofuncs.h:2812