ZwCreateEnlistment

ZwCreateEnlistment routine

The ZwCreateEnlistment routine creates a new enlistment object for a transaction.

Syntax


NTSTATUS ZwCreateEnlistment(
  _Out_    PHANDLE            EnlistmentHandle,
  _In_     ACCESS_MASK        DesiredAccess,
  _In_     HANDLE             ResourceManagerHandle,
  _In_     HANDLE             TransactionHandle,
  _In_opt_ POBJECT_ATTRIBUTES ObjectAttributes,
  _In_opt_ ULONG              CreateOptions,
  _In_     NOTIFICATION_MASK  NotificationMask,
  _In_opt_ PVOID              EnlistmentKey
);

Parameters

EnlistmentHandle [out]

A pointer to a caller-allocated variable that receives a handle to the new enlistment object if the call to ZwCreateEnlistment succeeds.

DesiredAccess [in]

An ACCESS_MASK value that specifies the caller's requested access to the enlistment object. In addition to the access rights that are defined for all kinds of objects (see ACCESS_MASK), the caller can specify any of the following access right flags for enlistment objects:

ACCESS_MASK flagAllows the caller to

ENLISTMENT_QUERY_INFORMATION

Query information about the enlistment (see ZwQueryInformationEnlistment).

ENLISTMENT_SET_INFORMATION

Set information for the enlistment (see ZwSetInformationEnlistment).

ENLISTMENT_RECOVER

Recover the enlistment (see ZwRecoverEnlistment).

ENLISTMENT_SUBORDINATE_RIGHTS

Perform operations that a resource manager that is not superior performs (see ZwRollbackEnlistment, ZwPrePrepareComplete, ZwPrepareComplete, ZwCommitComplete, ZwRollbackComplete, ZwSinglePhaseReject, ZwReadOnlyEnlistment).

ENLISTMENT_SUPERIOR_RIGHTS

Perform operations that a superior transaction manager must perform (see ZwPrepareEnlistment, ZwPrePrepareEnlistment, ZwCommitEnlistment).

 

Alternatively, you can specify one or more of the following ACCESS_MASK bitmaps. These bitmaps combine the flags from the previous table with the STANDARD_RIGHTS_XXX flags that are described on the ACCESS_MASK reference page. You can also combine these bitmaps together with additional flags from the previous table. The following table shows how the bitmaps correspond to specific access rights.

Generic access rightSet of specific access rights

ENLISTMENT_GENERIC_READ

STANDARD_RIGHTS_READ and ENLISTMENT_QUERY_INFORMATION

ENLISTMENT_GENERIC_WRITE

STANDARD_RIGHTS_WRITE, ENLISTMENT_SET_INFORMATION, ENLISTMENT_RECOVER, ENLISTMENT_REFERENCE, ENLISTMENT_SUBORDINATE_RIGHTS, and ENLISTMENT_SUPERIOR_RIGHTS

ENLISTMENT_GENERIC_EXECUTE

STANDARD_RIGHTS_EXECUTE, ENLISTMENT_RECOVER, ENLISTMENT_SUBORDINATE_RIGHTS, and ENLISTMENT_SUPERIOR_RIGHTS

ENLISTMENT_ALL_ACCESS

STANDARD_RIGHTS_REQUIRED, ENLISTMENT_GENERIC_READ, ENLISTMENT_GENERIC_WRITE, and ENLISTMENT_GENERIC_EXECUTE

 

ResourceManagerHandle [in]

A handle to the caller's resource manager object that was obtained by a previous call to ZwCreateResourceManager or ZwOpenResourceManager.

TransactionHandle [in]

A handle to a transaction object that was obtained by a previous call to ZwCreateTransaction or ZwOpenTransaction. KTM adds this transaction to the list of transactions that the calling resource manager is handling.

ObjectAttributes [in, optional]

A pointer to an OBJECT_ATTRIBUTES structure that specifies the object name and other attributes. Use the InitializeObjectAttributes routine to initialize this structure. If the caller is not running in a system thread context, it must set the OBJ_KERNEL_HANDLE attribute when it calls InitializeObjectAttributes. This parameter is optional and can be NULL.

CreateOptions [in, optional]

Enlistment option flags. The following table contains the only available flag.

CreateOptions flagMeaning

ENLISTMENT_SUPERIOR

The caller is enlisting as a superior transaction manager for the specified transaction.

 

This parameter is optional and can be zero.

NotificationMask [in]

A bitwise OR of TRANSACTION_NOTIFY_XXX values that are defined in Ktmtypes.h. This mask specifies the types of transaction notifications that KTM sends to the caller.

EnlistmentKey [in, optional]

A pointer to caller-defined information that uniquely identifies the enlistment. The resource manager receives this pointer when it calls ZwGetNotificationResourceManager or when KTM calls the ResourceManagerNotification callback routine. The resource manager can maintain a reference count for this key by calling TmReferenceEnlistmentKey and TmDereferenceEnlistmentKey. This parameter is optional and can be NULL.

Return value

ZwCreateEnlistment returns STATUS_SUCCESS if the operation succeeds. Otherwise, this routine might return one of the following values:

Return codeDescription
STATUS_INVALID_HANDLE

An object handle is invalid.

STATUS_INVALID_PARAMETER

The CreateOptions or NotificationMask parameter's value is invalid, or KTM could not find the transaction that the TransactionHandle parameter specifies.

STATUS_INSUFFICIENT_RESOURCES

A memory allocation failed.

STATUS_TRANSACTIONMANAGER_NOT_ONLINE

The enlistment failed because KTM or the resource manager is not in an operational state.

STATUS_TRANSACTION_NOT_ACTIVE

The enlistment failed because the transaction that the TransactionHandle parameter specifies is not active.

STATUS_TRANSACTION_SUPERIOR_EXISTS

The caller tried to register as a superior transaction manager but a superior transaction manager already exists.

STATUS_TM_VOLATILE

The caller is trying to register as a superior transaction manager, but the caller's resource manager object is volatile while the associated transaction manager object is not volatile.

STATUS_ACCESS_DENIED

The value of the DesiredAccess parameter is invalid.

 

The routine might return other NTSTATUS values.

Remarks

A resource manager calls ZwCreateEnlistment to enlist in a transaction.

Resource managers that are not superior must include the ENLISTMENT_SUBORDINATE_RIGHTS flag in their access mask.

Superior transaction managers must include the ENLISTMENT_SUPERIOR_RIGHTS flag in their access masks. Typically, a superior transaction manager includes code that calls ZwRollbackEnlistment, so it must also include the ENLISTMENT_SUBORDINATE_RIGHTS flag.

A resource manager that calls ZwCreateEnlistment must eventually call ZwClose to close the object handle.

Your resource manager can use the EnlistmentKey parameter to assign a unique value to each enlistment, such as a pointer to a data structure that contains information about the enlistment. For example, if the resource manager stores the enlistment object's handle in the structure, the resource manager can do the following:

  1. Call ZwGetNotificationResourceManager to obtain a notification.

  2. Obtain the enlistment key value from the TRANSACTION_NOTIFICATION structure.

  3. Use the enlistment key to find the stored enlistment object handle.

  4. Call routines that require the enlistment handle as input, such as ZwCommitComplete or ZwRollbackComplete.

For more information about ZwCreateEnlistment, see Creating a Resource Manager and Creating a Superior Transaction Manager.

Requirements

Target platform

Universal

Version

Available in Windows Vista and later operating system versions.

Header

Wdm.h (include Wdm.h, Ntddk.h, or Ntifs.h)

Library

NtosKrnl.lib

DLL

NtosKrnl.exe

IRQL

PASSIVE_LEVEL

DDI compliance rules

PowerIrpDDis, HwStorPortProhibitedDDIs

See also

ACCESS_MASK
InitializeObjectAttributes
OBJECT_ATTRIBUTES
TRANSACTION_NOTIFICATION
ZwClose
ZwCommitComplete
ZwCommitEnlistment
ZwCreateResourceManager
ZwCreateTransaction
ZwGetNotificationResourceManager
ZwOpenEnlistment
ZwOpenResourceManager
ZwOpenTransaction
ZwPrepareComplete
ZwPrepareEnlistment
ZwPrePrepareComplete
ZwPrePrepareEnlistment
ZwQueryInformationEnlistment
ZwReadOnlyEnlistment
ZwRecoverEnlistment
ZwRollbackComplete
ZwRollbackEnlistment
ZwSetInformationEnlistment
ZwSinglePhaseReject

 

 

Send comments about this topic to Microsoft

Show:
© 2016 Microsoft