ReactOS 0.4.15-dev-8096-ga0eec98
cmwraprs.c File Reference
#include "ntoskrnl.h"
#include "debug.h"
Include dependency graph for cmwraprs.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI CmpCreateEvent (IN EVENT_TYPE EventType, OUT PHANDLE EventHandle, OUT PKEVENT *Event)
 
PVOID NTAPI CmpAllocate (IN SIZE_T Size, IN BOOLEAN Paged, IN ULONG Tag)
 
VOID NTAPI CmpFree (IN PVOID Ptr, IN ULONG Quota)
 
BOOLEAN NTAPI CmpFileRead (IN PHHIVE RegistryHive, IN ULONG FileType, IN PULONG FileOffset, OUT PVOID Buffer, IN SIZE_T BufferLength)
 
BOOLEAN NTAPI CmpFileWrite (IN PHHIVE RegistryHive, IN ULONG FileType, IN PULONG FileOffset, IN PVOID Buffer, IN SIZE_T BufferLength)
 
BOOLEAN NTAPI CmpFileSetSize (_In_ PHHIVE RegistryHive, _In_ ULONG FileType, _In_ ULONG FileSize, _In_ ULONG OldFileSize)
 
BOOLEAN NTAPI CmpFileFlush (IN PHHIVE RegistryHive, IN ULONG FileType, IN OUT PLARGE_INTEGER FileOffset, IN ULONG Length)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file cmwraprs.c.

Function Documentation

◆ CmpAllocate()

PVOID NTAPI CmpAllocate ( IN SIZE_T  Size,
IN BOOLEAN  Paged,
IN ULONG  Tag 
)

Definition at line 54 of file cmwraprs.c.

57{
59 Size,
60 Tag);
61}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
#define PagedPool
Definition: env_spec_w32.h:308
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4065
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

◆ CmpCreateEvent()

NTSTATUS NTAPI CmpCreateEvent ( IN EVENT_TYPE  EventType,
OUT PHANDLE  EventHandle,
OUT PKEVENT Event 
)

Definition at line 19 of file cmwraprs.c.

22{
25
26 /* Create the event */
28 NULL,
30 NULL,
31 NULL);
32 Status = ZwCreateEvent(EventHandle,
36 FALSE);
37 if (!NT_SUCCESS(Status)) return Status;
38
39 /* Get a pointer to the object itself */
42 NULL,
44 (PVOID*)Event,
45 NULL);
47
48 /* Return status */
49 return Status;
50}
LONG NTSTATUS
Definition: precomp.h:26
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define KernelMode
Definition: asm.h:34
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_ EVENT_TYPE EventType
Definition: exfuncs.h:167
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:857

Referenced by CmpOpenHiveFiles().

◆ CmpFileFlush()

BOOLEAN NTAPI CmpFileFlush ( IN PHHIVE  RegistryHive,
IN ULONG  FileType,
IN OUT PLARGE_INTEGER  FileOffset,
IN ULONG  Length 
)

Definition at line 192 of file cmwraprs.c.

196{
197 PCMHIVE CmHive = (PCMHIVE)RegistryHive;
198 HANDLE HiveHandle = CmHive->FileHandles[FileType];
201
202 /* Just return success if no file is associated with this hive */
203 if (HiveHandle == NULL)
204 return TRUE;
205
206 /* Don't do anything if we're not supposed to */
207 if (CmpNoWrite)
208 return TRUE;
209
211
212 /* This operation is always synchronous */
215
216 return NT_SUCCESS(Status) ? TRUE : FALSE;
217}
struct _CMHIVE * PCMHIVE
BOOLEAN CmpNoWrite
Definition: cmsysini.c:30
#define TRUE
Definition: types.h:120
#define ASSERT(a)
Definition: mode.c:44
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define STATUS_PENDING
Definition: ntstatus.h:82
Definition: cmlib.h:316
HANDLE FileHandles[HFILE_TYPE_MAX]
Definition: cmlib.h:318
_In_ WDFDEVICE _In_ WDF_SPECIAL_FILE_TYPE FileType
Definition: wdfdevice.h:2741
NTSYSAPI NTSTATUS NTAPI ZwFlushBuffersFile(_In_ HANDLE FileHandle, _Out_ PIO_STATUS_BLOCK IoStatusBlock)

Referenced by CmpInitializeHive().

◆ CmpFileRead()

BOOLEAN NTAPI CmpFileRead ( IN PHHIVE  RegistryHive,
IN ULONG  FileType,
IN PULONG  FileOffset,
OUT PVOID  Buffer,
IN SIZE_T  BufferLength 
)

Definition at line 73 of file cmwraprs.c.

78{
79 PCMHIVE CmHive = (PCMHIVE)RegistryHive;
80 HANDLE HiveHandle = CmHive->FileHandles[FileType];
81 LARGE_INTEGER _FileOffset;
84
85 /* Just return success if no file is associated with this hive */
86 if (HiveHandle == NULL)
87 return TRUE;
88
89 _FileOffset.QuadPart = *FileOffset;
90 Status = ZwReadFile(HiveHandle, NULL, NULL, NULL, &IoStatusBlock,
91 Buffer, (ULONG)BufferLength, &_FileOffset, NULL);
92 /* We do synchronous I/O for simplicity - see CmpOpenHiveFiles. */
94 return NT_SUCCESS(Status) ? TRUE : FALSE;
95}
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:160
Definition: bufpool.h:45
uint32_t ULONG
Definition: typedefs.h:59
LONGLONG QuadPart
Definition: typedefs.h:114
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771

Referenced by CmpInitializeHive().

◆ CmpFileSetSize()

BOOLEAN NTAPI CmpFileSetSize ( _In_ PHHIVE  RegistryHive,
_In_ ULONG  FileType,
_In_ ULONG  FileSize,
_In_ ULONG  OldFileSize 
)

Definition at line 132 of file cmwraprs.c.

137{
138 PCMHIVE CmHive = (PCMHIVE)RegistryHive;
139 HANDLE HiveHandle = CmHive->FileHandles[FileType];
140 FILE_END_OF_FILE_INFORMATION EndOfFileInfo;
141 FILE_ALLOCATION_INFORMATION FileAllocationInfo;
143 BOOLEAN HardErrors;
145
146 /* Just return success if no file is associated with this hive */
147 if (HiveHandle == NULL)
148 {
149 DPRINT1("No hive handle associated with the given hive\n");
150 return TRUE;
151 }
152
153 /*
154 * Disable hard errors so that we don't deadlock
155 * when touching with the hive files.
156 */
157 HardErrors = IoSetThreadHardErrorMode(FALSE);
158
159 EndOfFileInfo.EndOfFile.QuadPart = FileSize;
160 Status = ZwSetInformationFile(HiveHandle,
162 &EndOfFileInfo,
165 if (!NT_SUCCESS(Status))
166 {
167 DPRINT1("ZwSetInformationFile failed to set new size of end of file (Status 0x%lx)\n", Status);
168 IoSetThreadHardErrorMode(HardErrors);
169 return FALSE;
170 }
171
172 FileAllocationInfo.AllocationSize.QuadPart = FileSize;
173 Status = ZwSetInformationFile(HiveHandle,
175 &FileAllocationInfo,
178 if (!NT_SUCCESS(Status))
179 {
180 DPRINT1("ZwSetInformationFile failed to set new of allocation file (Status 0x%lx)\n", Status);
181 IoSetThreadHardErrorMode(HardErrors);
182 return FALSE;
183 }
184
185 /* Reset the hard errors back */
186 IoSetThreadHardErrorMode(HardErrors);
187 return TRUE;
188}
unsigned char BOOLEAN
#define DPRINT1
Definition: precomp.h:8
@ FileEndOfFileInformation
Definition: from_kernel.h:81
@ FileAllocationInformation
Definition: from_kernel.h:80
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
BOOLEAN NTAPI IoSetThreadHardErrorMode(IN BOOLEAN HardErrorEnabled)
Definition: error.c:726
LARGE_INTEGER AllocationSize
Definition: winternl.h:688

Referenced by CmpInitializeHive().

◆ CmpFileWrite()

BOOLEAN NTAPI CmpFileWrite ( IN PHHIVE  RegistryHive,
IN ULONG  FileType,
IN PULONG  FileOffset,
IN PVOID  Buffer,
IN SIZE_T  BufferLength 
)

Definition at line 99 of file cmwraprs.c.

104{
105 PCMHIVE CmHive = (PCMHIVE)RegistryHive;
106 HANDLE HiveHandle = CmHive->FileHandles[FileType];
107 LARGE_INTEGER _FileOffset;
110
111 /* Just return success if no file is associated with this hive */
112 if (HiveHandle == NULL)
113 return TRUE;
114
115 /* Don't do anything if we're not supposed to */
116 if (CmpNoWrite)
117 return TRUE;
118
119 _FileOffset.QuadPart = *FileOffset;
120 Status = ZwWriteFile(HiveHandle, NULL, NULL, NULL, &IoStatusBlock,
121 Buffer, (ULONG)BufferLength, &_FileOffset, NULL);
122 /* We do synchronous I/O for simplicity - see CmpOpenHiveFiles.
123 * Windows optimizes here by starting an async write for each 64k chunk,
124 * then waiting for all writes to complete at once.
125 */
127 return NT_SUCCESS(Status) ? TRUE : FALSE;
128}

Referenced by CmpInitializeHive().

◆ CmpFree()

VOID NTAPI CmpFree ( IN PVOID  Ptr,
IN ULONG  Quota 
)

Definition at line 65 of file cmwraprs.c.

67{
69}
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898