ReactOS  0.4.14-dev-317-g96040ec
rxact.c File Reference
#include <rtl.h>
#include <ndk/cmfuncs.h>
#include <debug.h>
Include dependency graph for rxact.c:

Go to the source code of this file.

Classes

struct  _RXACT_INFO
 
struct  _RXACT_DATA
 
struct  _RXACT_CONTEXT
 
struct  _RXACT_ACTION
 

Macros

#define NDEBUG
 
#define RXACT_DEFAULT_BUFFER_SIZE   (4 * PAGE_SIZE)
 

Typedefs

typedef struct _RXACT_INFO RXACT_INFO
 
typedef struct _RXACT_INFOPRXACT_INFO
 
typedef struct _RXACT_DATA RXACT_DATA
 
typedef struct _RXACT_DATAPRXACT_DATA
 
typedef struct _RXACT_CONTEXT RXACT_CONTEXT
 
typedef struct _RXACT_CONTEXTPRXACT_CONTEXT
 
typedef struct _RXACT_ACTION RXACT_ACTION
 
typedef struct _RXACT_ACTIONPRXACT_ACTION
 

Enumerations

enum  { RXactDeleteKey = 1, RXactSetValueKey = 2 }
 

Functions

static VOID NTAPI RXactInitializeContext (PRXACT_CONTEXT Context, HANDLE RootDirectory, HANDLE KeyHandle)
 
static NTSTATUS NTAPI RXactpOpenTargetKey (HANDLE RootDirectory, ULONG ActionType, PUNICODE_STRING KeyName, PHANDLE KeyHandle)
 
static NTSTATUS NTAPI RXactpCommit (PRXACT_CONTEXT Context)
 
NTSTATUS NTAPI RtlStartRXact (PRXACT_CONTEXT Context)
 
NTSTATUS NTAPI RtlAbortRXact (PRXACT_CONTEXT Context)
 
NTSTATUS NTAPI RtlInitializeRXact (HANDLE RootDirectory, BOOLEAN Commit, PRXACT_CONTEXT *OutContext)
 
NTSTATUS NTAPI RtlAddAttributeActionToRXact (PRXACT_CONTEXT Context, ULONG ActionType, PUNICODE_STRING KeyName, HANDLE KeyHandle, PUNICODE_STRING ValueName, ULONG ValueType, PVOID ValueData, ULONG ValueDataSize)
 
NTSTATUS NTAPI RtlAddActionToRXact (PRXACT_CONTEXT Context, ULONG ActionType, PUNICODE_STRING KeyName, ULONG ValueType, PVOID ValueData, ULONG ValueDataSize)
 
NTSTATUS NTAPI RtlApplyRXactNoFlush (PRXACT_CONTEXT Context)
 
NTSTATUS NTAPI RtlApplyRXact (PRXACT_CONTEXT Context)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file rxact.c.

◆ RXACT_DEFAULT_BUFFER_SIZE

#define RXACT_DEFAULT_BUFFER_SIZE   (4 * PAGE_SIZE)

Definition at line 17 of file rxact.c.

Typedef Documentation

◆ PRXACT_ACTION

◆ PRXACT_CONTEXT

◆ PRXACT_DATA

◆ PRXACT_INFO

◆ RXACT_ACTION

◆ RXACT_CONTEXT

◆ RXACT_DATA

◆ RXACT_INFO

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
RXactDeleteKey 
RXactSetValueKey 

Definition at line 53 of file rxact.c.

54 {
55  RXactDeleteKey = 1,
56  RXactSetValueKey = 2,
57 };

Function Documentation

◆ RtlAbortRXact()

NTSTATUS NTAPI RtlAbortRXact ( PRXACT_CONTEXT  Context)

Definition at line 276 of file rxact.c.

278 {
279  /* We must have a data buffer */
280  if (Context->Data == NULL)
281  {
283  }
284 
285  /* Free the buffer */
286  RtlFreeHeap(RtlGetProcessHeap(), 0, Context->Data);
287 
288  /* Reinitialize the context */
289  RXactInitializeContext(Context, Context->RootDirectory, Context->KeyHandle);
290 
291  return STATUS_SUCCESS;
292 }
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
static VOID NTAPI RXactInitializeContext(PRXACT_CONTEXT Context, HANDLE RootDirectory, HANDLE KeyHandle)
Definition: rxact.c:64
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_RXACT_INVALID_STATE
Definition: ntstatus.h:506
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by RtlApplyRXact(), RtlApplyRXactNoFlush(), and RtlInitializeRXact().

◆ RtlAddActionToRXact()

NTSTATUS NTAPI RtlAddActionToRXact ( PRXACT_CONTEXT  Context,
ULONG  ActionType,
PUNICODE_STRING  KeyName,
ULONG  ValueType,
PVOID  ValueData,
ULONG  ValueDataSize 
)

Definition at line 604 of file rxact.c.

611 {
613 
614  /* Create a key and set the default key value or delete a key. */
617  ActionType,
618  KeyName,
620  &ValueName,
621  ValueType,
622  ValueData,
623  ValueDataSize);
624 }
NTSTATUS NTAPI RtlAddAttributeActionToRXact(PRXACT_CONTEXT Context, ULONG ActionType, PUNICODE_STRING KeyName, HANDLE KeyHandle, PUNICODE_STRING ValueName, ULONG ValueType, PVOID ValueData, ULONG ValueDataSize)
Definition: rxact.c:491
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
_In_ PCWSTR _In_z_ PCWSTR _In_ ULONG ValueType
Definition: rtlfuncs.h:4016
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
smooth NULL
Definition: ftsmooth.c:416
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:311
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)

◆ RtlAddAttributeActionToRXact()

NTSTATUS NTAPI RtlAddAttributeActionToRXact ( PRXACT_CONTEXT  Context,
ULONG  ActionType,
PUNICODE_STRING  KeyName,
HANDLE  KeyHandle,
PUNICODE_STRING  ValueName,
ULONG  ValueType,
PVOID  ValueData,
ULONG  ValueDataSize 
)

Definition at line 491 of file rxact.c.

500 {
501  ULONG ActionSize;
504  ULONG CurrentOffset;
505  PRXACT_DATA NewData;
507 
508  /* Validate ActionType parameter */
509  if ((ActionType != RXactDeleteKey) && (ActionType != RXactSetValueKey))
510  {
512  }
513 
514  /* Calculate the size of the new action record */
515  ActionSize = ALIGN_UP_BY(ValueName->Length, sizeof(ULONG)) +
516  ALIGN_UP_BY(ValueDataSize, sizeof(ULONG)) +
517  ALIGN_UP_BY(KeyName->Length, sizeof(ULONG)) +
518  ALIGN_UP_BY(sizeof(RXACT_ACTION), sizeof(ULONG));
519 
520  /* Calculate the new buffer size we need */
521  RequiredSize = ActionSize + Context->Data->CurrentSize;
522 
523  /* Check for integer overflow */
524  if (RequiredSize < ActionSize)
525  {
526  return STATUS_NO_MEMORY;
527  }
528 
529  /* Check if the buffer is large enough */
530  BufferSize = Context->Data->BufferSize;
531  if (RequiredSize > BufferSize)
532  {
533  /* Increase by a factor of 2, until it is large enough */
534  while (BufferSize < RequiredSize)
535  {
536  BufferSize *= 2;
537  }
538 
539  /* Allocate a new buffer from the heap */
540  NewData = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferSize);
541  if (NewData == NULL)
542  {
543  return STATUS_NO_MEMORY;
544  }
545 
546  /* Copy the old buffer to the new one */
547  RtlCopyMemory(NewData, Context->Data, Context->Data->CurrentSize);
548 
549  /* Free the old buffer and use the new one */
550  RtlFreeHeap(RtlGetProcessHeap(), 0, Context->Data);
551  Context->Data = NewData;
552  NewData->BufferSize = BufferSize;
553  }
554 
555  /* Get the next action record */
556  Action = (RXACT_ACTION *)((PUCHAR)Context->Data + Context->Data->CurrentSize);
557 
558  /* Fill in the fields */
559  Action->Size = ActionSize;
560  Action->Type = ActionType;
561  Action->KeyName = *KeyName;
562  Action->ValueName = *ValueName;
563  Action->ValueType = ValueType;
564  Action->ValueDataSize = ValueDataSize;
565  Action->KeyHandle = KeyHandle;
566 
567  /* Copy the key name (and convert the pointer to a buffer offset) */
568  CurrentOffset = Context->Data->CurrentSize + sizeof(RXACT_ACTION);
569  Action->KeyName.Buffer = UlongToPtr(CurrentOffset);
570  RtlCopyMemory((PUCHAR)Context->Data + CurrentOffset,
571  KeyName->Buffer,
572  KeyName->Length);
573 
574  /* Copy the value name (and convert the pointer to a buffer offset) */
575  CurrentOffset += ALIGN_UP_BY(KeyName->Length, sizeof(ULONG));
576  Action->ValueName.Buffer = UlongToPtr(CurrentOffset);
577  RtlCopyMemory((PUCHAR)Context->Data + CurrentOffset,
578  ValueName->Buffer,
579  ValueName->Length);
580 
581  /* Update the offset */
582  CurrentOffset += ALIGN_UP_BY(ValueName->Length, sizeof(ULONG));
583 
584  /* Is this a set action? */
585  if (ActionType == RXactSetValueKey)
586  {
587  /* Copy the key value data as well */
588  Action->ValueData = UlongToPtr(CurrentOffset);
589  RtlCopyMemory((PUCHAR)Context->Data + CurrentOffset,
590  ValueData,
591  ValueDataSize);
592  CurrentOffset += ALIGN_UP_BY(ValueDataSize, sizeof(ULONG));
593  }
594 
595  /* Update data site and action count */
596  Context->Data->CurrentSize = CurrentOffset;
597  Context->Data->ActionCount++;
598 
599  return STATUS_SUCCESS;
600 }
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
unsigned char * PUCHAR
Definition: retypes.h:3
_In_ PCWSTR _In_z_ PCWSTR _In_ ULONG ValueType
Definition: rtlfuncs.h:4016
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
ULONG BufferSize
Definition: rxact.c:29
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
smooth NULL
Definition: ftsmooth.c:416
struct _RXACT_ACTION RXACT_ACTION
_Inout_ PRTL_BUFFER _In_ SIZE_T RequiredSize
#define UlongToPtr(u)
Definition: config.h:106
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
_In_ PLIST_ENTRY _In_ PSTRING _In_ USHORT _In_opt_ PSTRING _In_opt_ PSTRING _In_ ULONG _In_ ULONG Action
Definition: fsrtlfuncs.h:738
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:311
#define BufferSize
Definition: classpnp.h:419
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
unsigned int ULONG
Definition: retypes.h:1
#define ALIGN_UP_BY(size, align)
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by RtlAddActionToRXact().

◆ RtlApplyRXact()

NTSTATUS NTAPI RtlApplyRXact ( PRXACT_CONTEXT  Context)

Definition at line 649 of file rxact.c.

651 {
654 
655  /* Temporarily safe the current transaction in the 'Log' key value */
657  Status = ZwSetValueKey(Context->KeyHandle,
658  &ValueName,
659  0,
660  REG_BINARY,
661  Context->Data,
662  Context->Data->CurrentSize);
663  if (!NT_SUCCESS(Status))
664  {
665  return Status;
666  }
667 
668  /* Flush the key */
669  Status = NtFlushKey(Context->KeyHandle);
670  if (!NT_SUCCESS(Status))
671  {
672  NtDeleteValueKey(Context->KeyHandle, &ValueName);
673  return Status;
674  }
675 
676  /* Now commit the transaction */
678  if (!NT_SUCCESS(Status))
679  {
680  NtDeleteValueKey(Context->KeyHandle, &ValueName);
681  return Status;
682  }
683 
684  /* Delete the 'Log' key value */
685  Status = NtDeleteValueKey(Context->KeyHandle, &ValueName);
687 
688  /* Reset the transaction */
691 
692  return STATUS_SUCCESS;
693 }
#define REG_BINARY
Definition: nt_native.h:1496
LONG NTSTATUS
Definition: precomp.h:26
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
NTSYSAPI NTSTATUS NTAPI NtDeleteValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName)
Definition: ntapi.c:994
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
static NTSTATUS NTAPI RXactpCommit(PRXACT_CONTEXT Context)
Definition: rxact.c:126
NTSTATUS NTAPI NtFlushKey(IN HANDLE KeyHandle)
Definition: ntapi.c:1065
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
return STATUS_SUCCESS
Definition: btrfs.c:2938
NTSTATUS NTAPI RtlAbortRXact(PRXACT_CONTEXT Context)
Definition: rxact.c:276

◆ RtlApplyRXactNoFlush()

NTSTATUS NTAPI RtlApplyRXactNoFlush ( PRXACT_CONTEXT  Context)

Definition at line 628 of file rxact.c.

630 {
632 
633  /* Commit the transaction */
635  if (!NT_SUCCESS(Status))
636  {
637  return Status;
638  }
639 
640  /* Reset the transaction */
643 
644  return Status;
645 }
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
static NTSTATUS NTAPI RXactpCommit(PRXACT_CONTEXT Context)
Definition: rxact.c:126
NTSTATUS NTAPI RtlAbortRXact(PRXACT_CONTEXT Context)
Definition: rxact.c:276

◆ RtlInitializeRXact()

NTSTATUS NTAPI RtlInitializeRXact ( HANDLE  RootDirectory,
BOOLEAN  Commit,
PRXACT_CONTEXT OutContext 
)

Definition at line 296 of file rxact.c.

300 {
301  NTSTATUS Status, TmpStatus;
303  PKEY_VALUE_FULL_INFORMATION KeyValueInformation;
304  KEY_VALUE_BASIC_INFORMATION KeyValueBasicInfo;
308  RXACT_INFO TransactionInfo;
311  ULONG ValueDataLength;
312  ULONG Length;
314 
315  /* Open or create the 'RXACT' key in the root directory */
316  RtlInitUnicodeString(&KeyName, L"RXACT");
318  &KeyName,
321  NULL);
322  Status = ZwCreateKey(&KeyHandle,
325  0,
326  NULL,
327  0,
328  &Disposition);
329  if (!NT_SUCCESS(Status))
330  {
331  return Status;
332  }
333 
334  /* Allocate a new context */
335  Context = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(*Context));
336  *OutContext = Context;
337  if (Context == NULL)
338  {
339  TmpStatus = ZwDeleteKey(KeyHandle);
340  ASSERT(NT_SUCCESS(TmpStatus));
341 
342  TmpStatus = NtClose(KeyHandle);
343  ASSERT(NT_SUCCESS(TmpStatus));
344 
345  return STATUS_NO_MEMORY;
346  }
347 
348  /* Initialize the context */
350 
351  /* Check if we created a new key */
353  {
354  /* The key is new, set the default value */
355  TransactionInfo.Revision = 1;
357  Status = ZwSetValueKey(KeyHandle,
358  &ValueName,
359  0,
360  REG_NONE,
361  &TransactionInfo,
362  sizeof(TransactionInfo));
363  if (!NT_SUCCESS(Status))
364  {
365  TmpStatus = ZwDeleteKey(KeyHandle);
366  ASSERT(NT_SUCCESS(TmpStatus));
367 
368  TmpStatus = NtClose(KeyHandle);
369  ASSERT(NT_SUCCESS(TmpStatus));
370 
371  RtlFreeHeap(RtlGetProcessHeap(), 0, *OutContext);
372  return Status;
373  }
374 
376  }
377  else
378  {
379  /* The key exited, get the default key value */
380  ValueDataLength = sizeof(TransactionInfo);
382  &ValueType,
383  &TransactionInfo,
384  &ValueDataLength,
385  0);
386  if (!NT_SUCCESS(Status))
387  {
388  TmpStatus = NtClose(KeyHandle);
389  ASSERT(NT_SUCCESS(TmpStatus));
390  RtlFreeHeap(RtlGetProcessHeap(), 0, Context);
391  return Status;
392  }
393 
394  /* Check if the value date is valid */
395  if ((ValueDataLength != sizeof(TransactionInfo)) ||
396  (TransactionInfo.Revision != 1))
397  {
398  TmpStatus = NtClose(KeyHandle);
399  ASSERT(NT_SUCCESS(TmpStatus));
400  RtlFreeHeap(RtlGetProcessHeap(), 0, Context);
402  }
403 
404  /* Query the 'Log' key value */
406  Status = ZwQueryValueKey(KeyHandle,
407  &ValueName,
409  &KeyValueBasicInfo,
410  sizeof(KeyValueBasicInfo),
411  &Length);
412  if (!NT_SUCCESS(Status))
413  {
414  /* There is no 'Log', so we are done */
415  return STATUS_SUCCESS;
416  }
417 
418  /* Check if the caller asked to commit the current state */
419  if (!Commit)
420  {
421  /* We have a log, that must be committed first! */
423  }
424 
425  /* Query the size of the 'Log' key value */
426  Status = ZwQueryValueKey(KeyHandle,
427  &ValueName,
429  NULL,
430  0,
431  &Length);
433  {
434  return Status;
435  }
436 
437  /* Allocate a buffer for the key value information */
438  KeyValueInformation = RtlAllocateHeap(RtlGetProcessHeap(), 0, Length);
439  if (KeyValueInformation == NULL)
440  {
441  return STATUS_NO_MEMORY;
442  }
443 
444  /* Query the 'Log' key value */
445  Status = ZwQueryValueKey(KeyHandle,
446  &ValueName,
448  KeyValueInformation,
449  Length,
450  &Length);
451  if (!NT_SUCCESS(Status))
452  {
453  RtlFreeHeap(RtlGetProcessHeap(), 0, KeyValueInformation);
454  RtlFreeHeap(RtlGetProcessHeap(), 0, Context);
455  return Status;
456  }
457 
458  /* Set the Data pointer to the key value data */
459  Context->Data = (PRXACT_DATA)((PUCHAR)KeyValueInformation +
460  KeyValueInformation->DataOffset);
461 
462  /* This is an old log, don't use handles when committing! */
463  Context->CanUseHandles = FALSE;
464 
465  /* Commit the data */
467  if (!NT_SUCCESS(Status))
468  {
469  RtlFreeHeap(RtlGetProcessHeap(), 0, KeyValueInformation);
470  RtlFreeHeap(RtlGetProcessHeap(), 0, Context);
471  return Status;
472  }
473 
474  /* Delete the old key */
477 
478  /* Set the data member to the allocated buffer, so it will get freed */
479  Context->Data = (PRXACT_DATA)KeyValueInformation;
480 
481  /* Abort the old transaction */
484 
485  return Status;
486  }
487 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
WCHAR RootDirectory[MAX_PATH]
Definition: format.c:74
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define KEY_READ
Definition: nt_native.h:1023
unsigned char * PUCHAR
Definition: retypes.h:3
_In_ PCWSTR _In_z_ PCWSTR _In_ ULONG ValueType
Definition: rtlfuncs.h:4016
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
static VOID NTAPI RXactInitializeContext(PRXACT_CONTEXT Context, HANDLE RootDirectory, HANDLE KeyHandle)
Definition: rxact.c:64
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:50
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define OBJ_OPENIF
Definition: winternl.h:229
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
smooth NULL
Definition: ftsmooth.c:416
#define REG_CREATED_NEW_KEY
Definition: nt_native.h:1084
#define STATUS_RXACT_STATE_CREATED
Definition: ntstatus.h:118
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
NTSYSAPI NTSTATUS NTAPI NtDeleteValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName)
Definition: ntapi.c:994
#define KEY_WRITE
Definition: nt_native.h:1031
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSTATUS NTAPI RtlpNtQueryValueKey(IN HANDLE KeyHandle, OUT PULONG Type OPTIONAL, OUT PVOID Data OPTIONAL, IN OUT PULONG DataLength OPTIONAL, IN ULONG Unused)
Definition: registry.c:933
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
static NTSTATUS NTAPI RXactpCommit(PRXACT_CONTEXT Context)
Definition: rxact.c:126
struct _RXACT_DATA * PRXACT_DATA
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
struct tagContext Context
Definition: acpixf.h:1024
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_RXACT_COMMIT_NECESSARY
Definition: ntstatus.h:192
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define REG_NONE
Definition: nt_native.h:1492
ULONG Revision
Definition: rxact.c:21
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define STATUS_UNKNOWN_REVISION
Definition: ntstatus.h:310
#define DELETE
Definition: nt_native.h:57
NTSTATUS NTAPI RtlAbortRXact(PRXACT_CONTEXT Context)
Definition: rxact.c:276

◆ RtlStartRXact()

NTSTATUS NTAPI RtlStartRXact ( PRXACT_CONTEXT  Context)

Definition at line 247 of file rxact.c.

249 {
251 
252  /* We must not have a buffer yet */
253  if (Context->Data != NULL)
254  {
256  }
257 
258  /* Allocate a buffer */
259  Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, RXACT_DEFAULT_BUFFER_SIZE);
260  if (Buffer == NULL)
261  {
262  return STATUS_NO_MEMORY;
263  }
264 
265  /* Initialize the buffer */
266  Buffer->ActionCount = 0;
267  Buffer->BufferSize = RXACT_DEFAULT_BUFFER_SIZE;
268  Buffer->CurrentSize = sizeof(RXACT_DATA);
269  Context->Data = Buffer;
270 
271  return STATUS_SUCCESS;
272 }
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define STATUS_RXACT_INVALID_STATE
Definition: ntstatus.h:506
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define RXACT_DEFAULT_BUFFER_SIZE
Definition: rxact.c:17
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2938
struct _RXACT_DATA RXACT_DATA

◆ RXactInitializeContext()

static VOID NTAPI RXactInitializeContext ( PRXACT_CONTEXT  Context,
HANDLE  RootDirectory,
HANDLE  KeyHandle 
)
static

Definition at line 64 of file rxact.c.

68 {
69  Context->Data = NULL;
70  Context->RootDirectory = RootDirectory;
71  Context->CanUseHandles = TRUE;
72  Context->KeyHandle = KeyHandle;
73 }
#define TRUE
Definition: types.h:120
WCHAR RootDirectory[MAX_PATH]
Definition: format.c:74
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
smooth NULL
Definition: ftsmooth.c:416

Referenced by RtlAbortRXact(), and RtlInitializeRXact().

◆ RXactpCommit()

static NTSTATUS NTAPI RXactpCommit ( PRXACT_CONTEXT  Context)
static

Definition at line 126 of file rxact.c.

128 {
131  NTSTATUS Status, TmpStatus;
133  ULONG i;
134 
135  Data = Context->Data;
136 
137  /* The first action record starts after the data header */
138  Action = (PRXACT_ACTION)(Data + 1);
139 
140  /* Loop all recorded actions */
141  for (i = 0; i < Data->ActionCount; i++)
142  {
143  /* Translate relative offsets to actual pointers */
144  Action->KeyName.Buffer = (PWSTR)((PUCHAR)Data + (ULONG_PTR)Action->KeyName.Buffer);
145  Action->ValueName.Buffer = (PWSTR)((PUCHAR)Data + (ULONG_PTR)Action->ValueName.Buffer);
146  Action->ValueData = (PUCHAR)Data + (ULONG_PTR)Action->ValueData;
147 
148  /* Check what kind of action this is */
149  if (Action->Type == RXactDeleteKey)
150  {
151  /* This is a delete action. Check if we can use a handle */
152  if ((Action->KeyHandle != INVALID_HANDLE_VALUE) && Context->CanUseHandles)
153  {
154  /* Delete the key by the given handle */
155  Status = ZwDeleteKey(Action->KeyHandle);
156  if (!NT_SUCCESS(Status))
157  {
158  return Status;
159  }
160  }
161  else
162  {
163  /* We cannot use a handle, open the key first by it's name */
164  Status = RXactpOpenTargetKey(Context->RootDirectory,
166  &Action->KeyName,
167  &KeyHandle);
168  if (NT_SUCCESS(Status))
169  {
170  Status = ZwDeleteKey(KeyHandle);
171  TmpStatus = NtClose(KeyHandle);
172  ASSERT(NT_SUCCESS(TmpStatus));
173  if (!NT_SUCCESS(Status))
174  {
175  return Status;
176  }
177  }
178  else
179  {
180  /* Failed to open the key, it's ok, if it was not found */
182  return Status;
183  }
184  }
185  }
186  else if (Action->Type == RXactSetValueKey)
187  {
188  /* This is a set action. Check if we can use a handle */
189  if ((Action->KeyHandle != INVALID_HANDLE_VALUE) && Context->CanUseHandles)
190  {
191  /* Set the key value using the given key handle */
192  Status = ZwSetValueKey(Action->KeyHandle,
193  &Action->ValueName,
194  0,
195  Action->ValueType,
196  Action->ValueData,
197  Action->ValueDataSize);
198  if (!NT_SUCCESS(Status))
199  {
200  return Status;
201  }
202  }
203  else
204  {
205  /* We cannot use a handle, open the key first by it's name */
206  Status = RXactpOpenTargetKey(Context->RootDirectory,
208  &Action->KeyName,
209  &KeyHandle);
210  if (!NT_SUCCESS(Status))
211  {
212  return Status;
213  }
214 
215  /* Set the key value */
216  Status = ZwSetValueKey(KeyHandle,
217  &Action->ValueName,
218  0,
219  Action->ValueType,
220  Action->ValueData,
221  Action->ValueDataSize);
222 
223  TmpStatus = NtClose(KeyHandle);
224  ASSERT(NT_SUCCESS(TmpStatus));
225 
226  if (!NT_SUCCESS(Status))
227  {
228  return Status;
229  }
230  }
231  }
232  else
233  {
234  ASSERT(FALSE);
236  }
237 
238  /* Go to the next action record */
239  Action = (PRXACT_ACTION)((PUCHAR)Action + Action->Size);
240  }
241 
242  return STATUS_SUCCESS;
243 }
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
uint16_t * PWSTR
Definition: typedefs.h:54
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
uint32_t ULONG_PTR
Definition: typedefs.h:63
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ PLIST_ENTRY _In_ PSTRING _In_ USHORT _In_opt_ PSTRING _In_opt_ PSTRING _In_ ULONG _In_ ULONG Action
Definition: fsrtlfuncs.h:738
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
struct _RXACT_ACTION * PRXACT_ACTION
static NTSTATUS NTAPI RXactpOpenTargetKey(HANDLE RootDirectory, ULONG ActionType, PUNICODE_STRING KeyName, PHANDLE KeyHandle)
Definition: rxact.c:78
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by RtlApplyRXact(), RtlApplyRXactNoFlush(), and RtlInitializeRXact().

◆ RXactpOpenTargetKey()

static NTSTATUS NTAPI RXactpOpenTargetKey ( HANDLE  RootDirectory,
ULONG  ActionType,
PUNICODE_STRING  KeyName,
PHANDLE  KeyHandle 
)
static

Definition at line 78 of file rxact.c.

83 {
87 
88  /* Check what kind of action this is */
89  if (ActionType == RXactDeleteKey)
90  {
91  /* This is a delete, so open the key for delete */
93  KeyName,
96  NULL);
97  Status = ZwOpenKey(KeyHandle, DELETE, &ObjectAttributes);
98  }
99  else if (ActionType == RXactSetValueKey)
100  {
101  /* This is a create, so open or create with write access */
103  KeyName,
106  NULL);
107  Status = ZwCreateKey(KeyHandle,
108  KEY_WRITE,
110  0,
111  NULL,
112  0,
113  &Disposition);
114  }
115  else
116  {
118  }
119 
120  return Status;
121 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
WCHAR RootDirectory[MAX_PATH]
Definition: format.c:74
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:50
#define OBJ_OPENIF
Definition: winternl.h:229
smooth NULL
Definition: ftsmooth.c:416
#define KEY_WRITE
Definition: nt_native.h:1031
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
Status
Definition: gdiplustypes.h:24
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define DELETE
Definition: nt_native.h:57

Referenced by RXactpCommit().