Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Transactions;
using System.Transactions.DtcProxyShim.DtcInterfaces;

internal static partial class Interop
{
internal static partial class Xolehlp
{
// https://learn.microsoft.com/previous-versions/windows/desktop/ms678898(v=vs.85)
[LibraryImport(Libraries.Xolehlp, StringMarshalling = StringMarshalling.Utf16)]
[RequiresUnreferencedCode(TransactionManager.DistributedTransactionTrimmingWarning)]
internal static unsafe partial int DtcGetTransactionManagerExW(
[MarshalAs(UnmanagedType.LPWStr)] string? pszHost,
[MarshalAs(UnmanagedType.LPWStr)] string? pszTmName,
in Guid riid,
int grfOptions,
void* pvConfigPararms,
[MarshalAs(UnmanagedType.Interface)] out ITransactionDispenser ppvObject);
}
}
149 changes: 149 additions & 0 deletions src/libraries/Common/src/Interop/Windows/Xolehlp/Interop.Enums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

internal static partial class Interop
{
internal static partial class Xolehlp
{
internal enum ShimNotificationType
{
None = 0,
Phase0RequestNotify = 1,
VoteRequestNotify = 2,
PrepareRequestNotify = 3,
CommitRequestNotify = 4,
AbortRequestNotify = 5,
CommittedNotify = 6,
AbortedNotify = 7,
InDoubtNotify = 8,
EnlistmentTmDownNotify = 9,
ResourceManagerTmDownNotify = 10
}

internal enum OletxPrepareVoteType
{
ReadOnly = 0,
SinglePhase = 1,
Prepared = 2,
Failed = 3,
InDoubt = 4
}

internal enum OletxTransactionOutcome
{
NotKnownYet = 0,
Committed = 1,
Aborted = 2
}

internal enum OletxTransactionIsolationLevel
{
ISOLATIONLEVEL_UNSPECIFIED = -1,
ISOLATIONLEVEL_CHAOS = 0x10,
ISOLATIONLEVEL_READUNCOMMITTED = 0x100,
ISOLATIONLEVEL_BROWSE = 0x100,
ISOLATIONLEVEL_CURSORSTABILITY = 0x1000,
ISOLATIONLEVEL_READCOMMITTED = 0x1000,
ISOLATIONLEVEL_REPEATABLEREAD = 0x10000,
ISOLATIONLEVEL_SERIALIZABLE = 0x100000,
ISOLATIONLEVEL_ISOLATED = 0x100000
}

[Flags]
internal enum OletxTransactionIsoFlags
{
ISOFLAG_NONE = 0,
ISOFLAG_RETAIN_COMMIT_DC = 1,
ISOFLAG_RETAIN_COMMIT = 2,
ISOFLAG_RETAIN_COMMIT_NO = 3,
ISOFLAG_RETAIN_ABORT_DC = 4,
ISOFLAG_RETAIN_ABORT = 8,
ISOFLAG_RETAIN_ABORT_NO = 12,
ISOFLAG_RETAIN_DONTCARE = ISOFLAG_RETAIN_COMMIT_DC | ISOFLAG_RETAIN_ABORT_DC,
ISOFLAG_RETAIN_BOTH = ISOFLAG_RETAIN_COMMIT | ISOFLAG_RETAIN_ABORT,
ISOFLAG_RETAIN_NONE = ISOFLAG_RETAIN_COMMIT_NO | ISOFLAG_RETAIN_ABORT_NO,
ISOFLAG_OPTIMISTIC = 16,
ISOFLAG_READONLY = 32
}

internal enum OletxXacttc : uint
{
XACTTC_NONE = 0,
XACTTC_SYNC_PHASEONE = 1,
XACTTC_SYNC_PHASETWO = 2,
XACTTC_SYNC = 2,
XACTTC_ASYNC_PHASEONE = 4,
XACTTC_ASYNC = 4
}

internal enum OletxXactRm : uint
{
XACTRM_OPTIMISTICLASTWINS = 1,
XACTRM_NOREADONLYPREPARES = 2
}

internal enum OletxTransactionStatus
{
OLETX_TRANSACTION_STATUS_NONE = 0,
OLETX_TRANSACTION_STATUS_OPENNORMAL = 0x1,
OLETX_TRANSACTION_STATUS_OPENREFUSED = 0x2,
OLETX_TRANSACTION_STATUS_PREPARING = 0x4,
OLETX_TRANSACTION_STATUS_PREPARED = 0x8,
OLETX_TRANSACTION_STATUS_PREPARERETAINING = 0x10,
OLETX_TRANSACTION_STATUS_PREPARERETAINED = 0x20,
OLETX_TRANSACTION_STATUS_COMMITTING = 0x40,
OLETX_TRANSACTION_STATUS_COMMITRETAINING = 0x80,
OLETX_TRANSACTION_STATUS_ABORTING = 0x100,
OLETX_TRANSACTION_STATUS_ABORTED = 0x200,
OLETX_TRANSACTION_STATUS_COMMITTED = 0x400,
OLETX_TRANSACTION_STATUS_HEURISTIC_ABORT = 0x800,
OLETX_TRANSACTION_STATUS_HEURISTIC_COMMIT = 0x1000,
OLETX_TRANSACTION_STATUS_HEURISTIC_DAMAGE = 0x2000,
OLETX_TRANSACTION_STATUS_HEURISTIC_DANGER = 0x4000,
OLETX_TRANSACTION_STATUS_FORCED_ABORT = 0x8000,
OLETX_TRANSACTION_STATUS_FORCED_COMMIT = 0x10000,
OLETX_TRANSACTION_STATUS_INDOUBT = 0x20000,
OLETX_TRANSACTION_STATUS_CLOSED = 0x40000,
OLETX_TRANSACTION_STATUS_OPEN = 0x3,
OLETX_TRANSACTION_STATUS_NOTPREPARED = 0x7ffc3,
OLETX_TRANSACTION_STATUS_ALL = 0x7ffff
}

internal enum OletxTransactionHeuristic : uint
{
XACTHEURISTIC_ABORT = 1,
XACTHEURISTIC_COMMIT = 2,
XACTHEURISTIC_DAMAGE = 3,
XACTHEURISTIC_DANGER = 4
}

internal enum OletxXactStat : int
{
XACTSTAT_NONE = 0,
XACTSTAT_OPENNORMAL = 0x1,
XACTSTAT_OPENREFUSED = 0x2,
XACTSTAT_PREPARING = 0x4,
XACTSTAT_PREPARED = 0x8,
XACTSTAT_PREPARERETAINING = 0x10,
XACTSTAT_PREPARERETAINED = 0x20,
XACTSTAT_COMMITTING = 0x40,
XACTSTAT_COMMITRETAINING = 0x80,
XACTSTAT_ABORTING = 0x100,
XACTSTAT_ABORTED = 0x200,
XACTSTAT_COMMITTED = 0x400,
XACTSTAT_HEURISTIC_ABORT = 0x800,
XACTSTAT_HEURISTIC_COMMIT = 0x1000,
XACTSTAT_HEURISTIC_DAMAGE = 0x2000,
XACTSTAT_HEURISTIC_DANGER = 0x4000,
XACTSTAT_FORCED_ABORT = 0x8000,
XACTSTAT_FORCED_COMMIT = 0x10000,
XACTSTAT_INDOUBT = 0x20000,
XACTSTAT_CLOSED = 0x40000,
XACTSTAT_OPEN = 0x3,
XACTSTAT_NOTPREPARED = 0x7ffc3,
XACTSTAT_ALL = 0x7ffff
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
<Compile Include="System\Transactions\DtcProxyShim\EnlistmentNotifyShim.cs" />
<Compile Include="System\Transactions\DtcProxyShim\EnlistmentShim.cs" />
<Compile Include="System\Transactions\DtcProxyShim\Guids.cs" />
<Compile Include="System\Transactions\DtcProxyShim\NativeEnums.cs" />
<Compile Include="System\Transactions\DtcProxyShim\NotificationShimBase.cs" />
<Compile Include="System\Transactions\DtcProxyShim\OletxHelper.cs" />
<Compile Include="System\Transactions\DtcProxyShim\OletxXactTransInfo.cs" />
Expand All @@ -101,6 +100,8 @@
<Compile Include="System\Transactions\Oletx\OletxTransactionManager.cs" />
<Compile Include="System\Transactions\Oletx\OletxVolatileEnlistment.cs" />
<Compile Include="System\Transactions\TransactionInterop.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Xolehlp\Interop.DtcGetTransactionManagerEx.cs" Link="Common\Interop\Windows\Xolehlp\Interop.DtcGetTransactionManagerEx.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Xolehlp\Interop.Enums.cs" Link="Common\Interop\Windows\Xolehlp\Interop.Enums.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' != 'windows'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ internal void Enlist(
[MarshalAs(UnmanagedType.Interface)] ITransaction pTransaction,
[MarshalAs(UnmanagedType.Interface)] ITransactionResourceAsync pRes,
out Guid pUOW,
out OletxTransactionIsolationLevel pisoLevel,
out Interop.Xolehlp.OletxTransactionIsolationLevel pisoLevel,
[MarshalAs(UnmanagedType.Interface)] out ITransactionEnlistmentAsync ppEnlist);

internal void Reenlist(
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] byte[] pPrepInfo,
uint cbPrepInfom,
uint lTimeout,
out OletxXactStat pXactStat);
out Interop.Xolehlp.OletxXactStat pXactStat);

void ReenlistmentComplete();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal partial interface ITransaction
{
void Commit(
[MarshalAs(UnmanagedType.Bool)] bool fRetaining,
OletxXacttc grfTC,
Interop.Xolehlp.OletxXacttc grfTC,
uint grfRM);

void Abort(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal partial interface ITransactionCloner
{
void Commit(
[MarshalAs(UnmanagedType.Bool)] bool fRetainingt,
OletxXacttc grfTC,
Interop.Xolehlp.OletxXacttc grfTC,
uint grfRM);

void Abort(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ internal partial interface ITransactionDispenser

void BeginTransaction(
IntPtr punkOuter,
OletxTransactionIsolationLevel isoLevel,
OletxTransactionIsoFlags isoFlags,
Interop.Xolehlp.OletxTransactionIsolationLevel isoLevel,
Interop.Xolehlp.OletxTransactionIsoFlags isoFlags,
[MarshalAs(UnmanagedType.Interface)] ITransactionOptions pOptions,
[MarshalAs(UnmanagedType.Interface)] out ITransaction ppTransaction);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void Aborted(
int hresult);

void HeuristicDecision(
OletxTransactionHeuristic dwDecision,
Interop.Xolehlp.OletxTransactionHeuristic dwDecision,
IntPtr pboidReason,
int hresult);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ internal partial interface ITransactionResourceAsync
{
void PrepareRequest(
[MarshalAs(UnmanagedType.Bool)] bool fRetaining,
OletxXactRm grfRM,
Interop.Xolehlp.OletxXactRm grfRM,
[MarshalAs(UnmanagedType.Bool)] bool fWantMoniker,
[MarshalAs(UnmanagedType.Bool)] bool fSinglePhase);

void CommitRequest(OletxXactRm grfRM, IntPtr pNewUOW);
void CommitRequest(Interop.Xolehlp.OletxXactRm grfRM, IntPtr pNewUOW);

void AbortRequest(
IntPtr pboidReason,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void Aborted(
uint hresult);

void HeuristicDecision(
OletxTransactionHeuristic dwDecision,
Interop.Xolehlp.OletxTransactionHeuristic dwDecision,
IntPtr pboidReason,
uint hresult);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ private static unsafe partial int DtcGetTransactionManagerExW(
[MarshalAs(UnmanagedType.Interface)] out ITransactionDispenser ppvObject);

[RequiresUnreferencedCode(TransactionManager.DistributedTransactionTrimmingWarning)]
private static unsafe void DtcGetTransactionManager(string? nodeName, out ITransactionDispenser localDispenser) => Marshal.ThrowExceptionForHR(DtcGetTransactionManagerExW(nodeName, null, Guids.IID_ITransactionDispenser_Guid, 0, null, out localDispenser));
private static unsafe void DtcGetTransactionManager(string? nodeName, out ITransactionDispenser localDispenser)
=> Marshal.ThrowExceptionForHR(Interop.Xolehlp.DtcGetTransactionManagerExW(nodeName, null, Guids.IID_ITransactionDispenser_Guid, 0, null, out localDispenser));

public void ConnectToProxy(
string? nodeName,
Expand Down Expand Up @@ -169,7 +170,7 @@ public void ReleaseNotificationLock()

public void BeginTransaction(
uint timeout,
OletxTransactionIsolationLevel isolationLevel,
Interop.Xolehlp.OletxTransactionIsolationLevel isolationLevel,
object? managedIdentifier,
out Guid transactionIdentifier,
out TransactionShim transactionShim)
Expand All @@ -181,9 +182,9 @@ public void BeginTransaction(
var xactopt = new Xactopt(timeout, string.Empty);
options.SetOptions(xactopt);

_transactionDispenser.BeginTransaction(IntPtr.Zero, isolationLevel, OletxTransactionIsoFlags.ISOFLAG_NONE, options, out ITransaction? pTx);
_transactionDispenser.BeginTransaction(IntPtr.Zero, isolationLevel, Interop.Xolehlp.OletxTransactionIsoFlags.ISOFLAG_NONE, options, out ITransaction? pTx);

SetupTransaction(pTx, managedIdentifier, out transactionIdentifier, out OletxTransactionIsolationLevel localIsoLevel, out transactionShim);
SetupTransaction(pTx, managedIdentifier, out transactionIdentifier, out Interop.Xolehlp.OletxTransactionIsolationLevel localIsoLevel, out transactionShim);
}
finally
{
Expand Down Expand Up @@ -220,7 +221,7 @@ public void Import(
byte[] cookie,
OutcomeEnlistment managedIdentifier,
out Guid transactionIdentifier,
out OletxTransactionIsolationLevel isolationLevel,
out Interop.Xolehlp.OletxTransactionIsolationLevel isolationLevel,
out TransactionShim transactionShim)
{
var txImport = (ITransactionImport)_transactionDispenser;
Expand All @@ -233,7 +234,7 @@ public void ReceiveTransaction(
byte[] propagationToken,
OutcomeEnlistment managedIdentifier,
out Guid transactionIdentifier,
out OletxTransactionIsolationLevel isolationLevel,
out Interop.Xolehlp.OletxTransactionIsolationLevel isolationLevel,
out TransactionShim transactionShim)
{
ITransactionReceiver receiver = GetCachedReceiver();
Expand All @@ -257,7 +258,7 @@ public void CreateTransactionShim(
IDtcTransaction transactionNative,
OutcomeEnlistment managedIdentifier,
out Guid transactionIdentifier,
out OletxTransactionIsolationLevel isolationLevel,
out Interop.Xolehlp.OletxTransactionIsolationLevel isolationLevel,
out TransactionShim transactionShim)
{
var cloner = (ITransactionCloner)TransactionInterop.GetITransactionFromIDtcTransaction(transactionNative);
Expand All @@ -274,14 +275,14 @@ internal ITransactionVoterFactory2 VoterFactory

public void GetNotification(
out object? managedIdentifier,
out ShimNotificationType shimNotificationType,
out Interop.Xolehlp.ShimNotificationType shimNotificationType,
out bool isSinglePhase,
out bool abortingHint,
out bool releaseLock,
out byte[]? prepareInfo)
{
managedIdentifier = null;
shimNotificationType = ShimNotificationType.None;
shimNotificationType = Interop.Xolehlp.ShimNotificationType.None;
isSinglePhase = false;
abortingHint = false;
releaseLock = false;
Expand All @@ -305,7 +306,7 @@ public void GetNotification(
// other notifications from being processed while we are processing TMDown. But we don't want
// to force 3 roundtrips to this NotificationShimFactory for all notifications ( 1 to grab the lock,
// one to get the notification, and one to release the lock).
if (!entryRemoved || shimNotificationType != ShimNotificationType.ResourceManagerTmDownNotify)
if (!entryRemoved || shimNotificationType != Interop.Xolehlp.ShimNotificationType.ResourceManagerTmDownNotify)
{
Monitor.Exit(_notificationLock);
}
Expand All @@ -319,7 +320,7 @@ private void SetupTransaction(
ITransaction transaction,
object? managedIdentifier,
out Guid pTransactionIdentifier,
out OletxTransactionIsolationLevel pIsolationLevel,
out Interop.Xolehlp.OletxTransactionIsolationLevel pIsolationLevel,
out TransactionShim ppTransactionShim)
{
var transactionNotifyShim = new TransactionNotifyShim(this, managedIdentifier);
Expand Down
Loading