ReactOS 0.4.17-dev-1281-g065abb3
ucxutil.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS USB Host Controller Extension
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE: Driver wide state, object creation and verifier fault injection
5 * COPYRIGHT: Copyright 2026 Justin Miller <justin.miller@reactos.org>
6 */
7
8#include "ucx01000.h"
9
10#define NDEBUG
11#include <debug.h>
12
14
15/* The parent and execution constraints always come from UCX */
23{
25 WDFOBJECT Created;
27
28 *Object = NULL;
29
30 Status = WdfObjectCreate(Primary, &Created);
31 if (!NT_SUCCESS(Status))
32 {
33 DPRINT1("Object create failed 0x%lx\n", Status);
34 return Status;
35 }
36
37 if (Secondary != NULL && Secondary->ContextTypeInfo != NULL)
38 {
39 Extra = *Secondary;
40 Extra.ParentObject = NULL;
43
44 Status = WdfObjectAllocateContext(Created, &Extra, NULL);
45 if (!NT_SUCCESS(Status))
46 {
47 DPRINT1("Client context on object %p failed 0x%lx\n", Created, Status);
48 WdfObjectDelete(Created);
49 return Status;
50 }
51 }
52
53 *Object = Created;
54 return STATUS_SUCCESS;
55}
56
57/* Verifier fault injection; races on the seed only make it more random */
58
62{
63 UcxDriver.RandomSeed = UcxDriver.RandomSeed * 1103515245 + 12345;
64
65 return (UcxDriver.RandomSeed / 65536) % 32768;
66}
67
72 _In_ ULONG Setting)
73{
74 if (Setting == 0)
75 return FALSE;
76
77 if (Setting == 1)
78 return TRUE;
79
80 return (32768 / Setting) > UcxRandom();
81}
82
87{
88 return (UcxRandom() % Max) + 1;
89}
90
94{
95 return (NTSTATUS)(0xC0000000 | UcxRandom());
96}
unsigned char BOOLEAN
Definition: actypes.h:127
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define Max(a, b)
Definition: cdprocs.h:78
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:24
#define _Must_inspect_result_
Definition: no_sal2.h:62
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define _In_opt_
Definition: no_sal2.h:212
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG RandomSeed
Definition: ucxutil.h:159
WDFOBJECT ParentObject
Definition: wdfobject.h:130
WDF_EXECUTION_LEVEL ExecutionLevel
Definition: wdfobject.h:120
WDF_SYNCHRONIZATION_SCOPE SynchronizationScope
Definition: wdfobject.h:125
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG
Definition: typedefs.h:59
ULONG NTAPI UcxRandom(VOID)
Definition: ucxutil.cpp:61
UcxDriverState UcxDriver
Definition: ucxutil.cpp:13
BOOLEAN NTAPI UcxVerifierWantsFailure(_In_ ULONG Setting)
Definition: ucxutil.cpp:71
_Must_inspect_result_ NTSTATUS NTAPI UcxCreateObjectWithTwoContexts(_In_ PWDF_OBJECT_ATTRIBUTES Primary, _In_opt_ PWDF_OBJECT_ATTRIBUTES Secondary, _Out_ WDFOBJECT *Object)
Definition: ucxutil.cpp:19
NTSTATUS NTAPI UcxRandomErrorStatus(VOID)
Definition: ucxutil.cpp:93
ULONG NTAPI UcxRandomInRange(_In_ ULONG Max)
Definition: ucxutil.cpp:85
WdfObjectDelete(String)
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
@ WdfSynchronizationScopeInheritFromParent
Definition: wdfobject.h:63
@ WdfExecutionLevelInheritFromParent
Definition: wdfobject.h:53
FORCEINLINE NTSTATUS WdfObjectAllocateContext(_In_ WDFOBJECT Handle, _In_ PWDF_OBJECT_ATTRIBUTES ContextAttributes, _Outptr_opt_ PVOID *Context)
Definition: wdfobject.h:587