87 DPRINT(
"Starting to compare element %x to element %x\n", PtrA, PtrB);
90 if (((
A->Exclusive.FileLock.StartingByte.QuadPart <
91 B->Exclusive.FileLock.EndingByte.QuadPart) &&
92 (
A->Exclusive.FileLock.StartingByte.QuadPart >=
93 B->Exclusive.FileLock.StartingByte.QuadPart)) ||
94 ((
B->Exclusive.FileLock.StartingByte.QuadPart <
95 A->Exclusive.FileLock.EndingByte.QuadPart) &&
96 (
B->Exclusive.FileLock.StartingByte.QuadPart >=
97 A->Exclusive.FileLock.StartingByte.QuadPart)))
101 (
A->Exclusive.FileLock.StartingByte.QuadPart <
103 (
A->Exclusive.FileLock.StartingByte.QuadPart >
107 DPRINT(
"Compare(%x:%x) %x-%x to %x-%x => %d\n",
109 A->Exclusive.FileLock.StartingByte.LowPart,
110 A->Exclusive.FileLock.EndingByte.LowPart,
111 B->Exclusive.FileLock.StartingByte.LowPart,
112 B->Exclusive.FileLock.EndingByte.LowPart,
150 Following =
Irp->Tail.Overlay.ListEntry.
Flink;
152 DPRINT(
"ListEntry %p Head %p\n", Following, &LockInfo->
CsqList);
154 Following != &LockInfo->
CsqList;
155 Following = Following->
Flink)
228 Irp->IoStatus.Information = 0;
259 if (!FileLock->LockInformation)
return NULL;
262 else return &
Entry->Exclusive.FileLock;
346 DPRINT(
"FsRtlPrivateLock(%wZ, Offset %08x%08x (%d), Length %08x%08x (%d), Key %x, FailImmediately %u, Exclusive %u)\n",
363 DPRINT(
"File offset out of range\n");
369 (FileLock->CompleteLockIrpRoutine,
380 if (!FileLock->LockInformation)
388 FileLock->LockInformation = LockInfo;
413 LockInfo = FileLock->LockInformation;
422 (FileLock->LockInformation,
427 if (Conflict && !InsertedNew)
431 DPRINT(
"Conflict %08x%08x:%08x%08x Exc %u (Want Exc %u)\n",
440 DPRINT(
"STATUS_FILE_LOCK_CONFLICT\n");
444 DPRINT(
"STATUS_FILE_LOCK_CONFLICT: Complete\n");
446 (FileLock->CompleteLockIrpRoutine,
489 DPRINT(
"STATUS_FILE_LOCK_CONFLICT\n");
492 DPRINT(
"STATUS_FILE_LOCK_CONFLICT: Complete\n");
494 (FileLock->CompleteLockIrpRoutine,
520 DPRINT(
"Overlapping shared lock %wZ %08x%08x %08x%08x\n",
535 (FileLock->CompleteLockIrpRoutine,
557 (FileLock->CompleteLockIrpRoutine,
569 NewSharedRange->
Key =
Key;
573 DPRINT(
"Acquired shared lock %wZ %08x%08x %08x%08x\n",
583 (FileLock->CompleteLockIrpRoutine,
601 (FileLock->CompleteLockIrpRoutine,
612 DPRINT(
"Inserted new lock %wZ %08x%08x %08x%08x exclusive %u\n",
629 (FileLock->CompleteLockIrpRoutine,
641 NewSharedRange->
Key =
Key;
679 DPRINT(
"CheckLockForReadAccess(%wZ, Offset %08x%08x, Length %x)\n",
684 if (!FileLock->LockInformation) {
685 DPRINT(
"CheckLockForReadAccess(%wZ) => TRUE\n", &IoStack->
FileObject->FileName);
693 (FileLock->LockInformation,
696 DPRINT(
"CheckLockForReadAccess(%wZ) => TRUE\n", &IoStack->
FileObject->FileName);
699 Result = !
Found->Exclusive.FileLock.ExclusiveLock ||
718 DPRINT(
"CheckLockForWriteAccess(%wZ, Offset %08x%08x, Length %x)\n",
723 if (!FileLock->LockInformation) {
724 DPRINT(
"CheckLockForWriteAccess(%wZ) => TRUE\n", &IoStack->
FileObject->FileName);
732 (FileLock->LockInformation,
735 DPRINT(
"CheckLockForWriteAccess(%wZ) => TRUE\n", &IoStack->
FileObject->FileName);
739 DPRINT(
"CheckLockForWriteAccess(%wZ) => %s\n", &IoStack->
FileObject->FileName,
Result ?
"TRUE" :
"FALSE");
758 DPRINT(
"FsRtlFastCheckLockForRead(%wZ, Offset %08x%08x, Length %08x%08x, Key %x)\n",
768 if (!FileLock->LockInformation)
return TRUE;
770 (FileLock->LockInformation,
772 if (!
Found || !
Found->Exclusive.FileLock.ExclusiveLock)
return TRUE;
773 return Found->Exclusive.FileLock.Key ==
Key &&
774 Found->Exclusive.FileLock.ProcessId == EProcess;
793 DPRINT(
"FsRtlFastCheckLockForWrite(%wZ, Offset %08x%08x, Length %08x%08x, Key %x)\n",
803 if (!FileLock->LockInformation) {
808 (FileLock->LockInformation,
815 Found->Exclusive.FileLock.ProcessId == EProcess;
839 PIRP NextMatchingLockIrp;
841 DPRINT(
"FsRtlFastUnlockSingle(%wZ, Offset %08x%08x (%d), Length %08x%08x (%d), Key %x)\n",
858 DPRINT(
"File not previously locked (ever)\n");
867 DPRINT(
"Found lock entry: Exclusive %u %08x%08x:%08x%08x %wZ\n",
868 Entry->Exclusive.FileLock.ExclusiveLock,
869 Entry->Exclusive.FileLock.StartingByte.HighPart,
870 Entry->Exclusive.FileLock.StartingByte.LowPart,
871 Entry->Exclusive.FileLock.EndingByte.HighPart,
872 Entry->Exclusive.FileLock.EndingByte.LowPart,
875 if (
Entry->Exclusive.FileLock.ExclusiveLock)
877 if (
Entry->Exclusive.FileLock.Key !=
Key ||
879 Entry->Exclusive.FileLock.StartingByte.QuadPart !=
FileOffset->QuadPart ||
880 Entry->Exclusive.FileLock.EndingByte.QuadPart !=
892 DPRINT(
"Shared lock %wZ Start %08x%08x End %08x%08x\n",
894 Entry->Exclusive.FileLock.StartingByte.HighPart,
895 Entry->Exclusive.FileLock.StartingByte.LowPart,
896 Entry->Exclusive.FileLock.EndingByte.HighPart,
897 Entry->Exclusive.FileLock.EndingByte.LowPart);
900 SharedEntry = SharedEntry->
Flink)
905 SharedRange->
Key ==
Key &&
909 DPRINT(
"Found shared element to delete %wZ Start %08x%08x End %08x%08x Key %x\n",
925 DPRINT(
"Removing the lock entry %wZ (%08x%08x:%08x%08x)\n",
927 Entry->Exclusive.FileLock.StartingByte.HighPart,
928 Entry->Exclusive.FileLock.StartingByte.LowPart,
929 Entry->Exclusive.FileLock.EndingByte.HighPart,
930 Entry->Exclusive.FileLock.EndingByte.LowPart);
938 SharedEntry = SharedEntry->
Flink)
951 DPRINT(
"Skipping range %08x%08x:%08x%08x\n",
958 DPRINT(
"Re-creating range %08x%08x:%08x%08x\n",
973 DPRINT(
"Lock still has:\n");
976 SharedEntry = SharedEntry->
Flink)
979 DPRINT(
"Shared element %wZ Offset %08x%08x Length %08x%08x Key %x\n",
1000 NextMatchingLockIrp,
1009 DPRINT(
"Locking another IRP %p for %p %wZ\n",
1010 NextMatchingLockIrp, FileLock, &
FileObject->FileName);
1035 if (!FileLock->LockInformation) {
1045 ListEntry = ListEntry->
Flink;
1065 Entry->Exclusive.FileLock.EndingByte.QuadPart -
1066 Entry->Exclusive.FileLock.StartingByte.QuadPart;
1069 Entry->Exclusive.FileLock.FileObject,
1070 &
Entry->Exclusive.FileLock.StartingByte,
1072 Entry->Exclusive.FileLock.ProcessId,
1073 Entry->Exclusive.FileLock.Key,
1106 ListEntry = ListEntry->
Flink;
1127 Entry->Exclusive.FileLock.EndingByte.QuadPart -
1128 Entry->Exclusive.FileLock.StartingByte.QuadPart;
1129 if (
Entry->Exclusive.FileLock.Key ==
Key &&
1134 Entry->Exclusive.FileLock.FileObject,
1135 &
Entry->Exclusive.FileLock.StartingByte,
1137 Entry->Exclusive.FileLock.ProcessId,
1138 Entry->Exclusive.FileLock.Key,
1167 DPRINT(
"FsRtlProcessFileLock(%wZ, MinorFunction %x)\n",
1248 (FileLock->CompleteLockIrpRoutine,
1268 FileLock->FastIoIsQuestionable =
FALSE;
1271 FileLock->LockInformation =
NULL;
1281 if (FileLock->LockInformation)
1293 SharedEntry = SharedEntry->
Flink;
1309 FileLock->LockInformation =
NULL;
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
_In_ PFCB _In_ LONGLONG FileOffset
_In_ PIRP _In_ PVOID InsertContext
_In_opt_ PIRP _In_opt_ PVOID PeekContext
NTKERNELAPI NTSTATUS NTAPI IoCsqInitializeEx(_Out_ PIO_CSQ Csq, _In_ PIO_CSQ_INSERT_IRP_EX CsqInsertIrpEx, _In_ PIO_CSQ_REMOVE_IRP CsqRemoveIrp, _In_ PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp, _In_ PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock, _In_ PIO_CSQ_RELEASE_LOCK CsqReleaseLock, _In_ PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp)
Set up a CSQ struct to initialize the queue (extended version)
NTKERNELAPI NTSTATUS NTAPI IoCsqInsertIrpEx(_Inout_ PIO_CSQ Csq, _Inout_ PIRP Irp, _Out_opt_ PIO_CSQ_IRP_CONTEXT Context, _In_opt_ PVOID InsertContext)
Insert an IRP into the CSQ, with additional tracking context.
NTKERNELAPI PIRP NTAPI IoCsqRemoveNextIrp(_Inout_ PIO_CSQ Csq, _In_opt_ PVOID PeekContext)
IoCsqRemoveNextIrp - Removes the next IRP from the queue.
#define NT_SUCCESS(StatCode)
#define RemoveEntryList(Entry)
#define InsertTailList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
#define KeReleaseSpinLock(sl, irql)
#define KeAcquireSpinLock(sl, irql)
#define InitializeListHead(ListHead)
#define KeInitializeSpinLock(sl)
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG BOOLEAN BOOLEAN ExclusiveLock
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG BOOLEAN FailImmediately
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
VOID NTAPI FsRtlpExpandLockElement(PCOMBINED_LOCK_ELEMENT ToExpand, PCOMBINED_LOCK_ELEMENT Conflict)
PFILE_LOCK_INFO NTAPI FsRtlGetNextFileLock(IN PFILE_LOCK FileLock, IN BOOLEAN Restart)
BOOLEAN NTAPI FsRtlFastCheckLockForWrite(IN PFILE_LOCK FileLock, IN PLARGE_INTEGER FileOffset, IN PLARGE_INTEGER Length, IN ULONG Key, IN PFILE_OBJECT FileObject, IN PVOID Process)
struct _LOCK_INFORMATION LOCK_INFORMATION
static VOID NTAPI LockCompleteCanceledIrp(PIO_CSQ Csq, PIRP Irp)
static VOID NTAPI LockAcquireQueueLock(PIO_CSQ Csq, PKIRQL Irql)
union _COMBINED_LOCK_ELEMENT COMBINED_LOCK_ELEMENT
union _COMBINED_LOCK_ELEMENT * PCOMBINED_LOCK_ELEMENT
VOID NTAPI FsRtlInitializeFileLock(IN PFILE_LOCK FileLock, IN PCOMPLETE_LOCK_IRP_ROUTINE CompleteLockIrpRoutine OPTIONAL, IN PUNLOCK_ROUTINE UnlockRoutine OPTIONAL)
static PVOID NTAPI LockAllocate(PRTL_GENERIC_TABLE Table, CLONG Bytes)
BOOLEAN NTAPI FsRtlCheckLockForWriteAccess(IN PFILE_LOCK FileLock, IN PIRP Irp)
PCOMBINED_LOCK_ELEMENT NTAPI FsRtlpRebuildSharedLockRange(PFILE_LOCK FileLock, PLOCK_INFORMATION LockInfo, PCOMBINED_LOCK_ELEMENT Conflict)
PAGED_LOOKASIDE_LIST FsRtlFileLockLookasideList
VOID NTAPI FsRtlUninitializeFileLock(IN PFILE_LOCK FileLock)
NTSTATUS NTAPI FsRtlFastUnlockSingle(IN PFILE_LOCK FileLock, IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN PLARGE_INTEGER Length, IN PEPROCESS Process, IN ULONG Key, IN PVOID Context OPTIONAL, IN BOOLEAN AlreadySynchronized)
struct _LOCK_SHARED_RANGE LOCK_SHARED_RANGE
BOOLEAN NTAPI FsRtlPrivateLock(IN PFILE_LOCK FileLock, IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN PLARGE_INTEGER Length, IN PEPROCESS Process, IN ULONG Key, IN BOOLEAN FailImmediately, IN BOOLEAN ExclusiveLock, OUT PIO_STATUS_BLOCK IoStatus, IN PIRP Irp OPTIONAL, IN PVOID Context OPTIONAL, IN BOOLEAN AlreadySynchronized)
static VOID NTAPI LockReleaseQueueLock(PIO_CSQ Csq, KIRQL Irql)
NTSTATUS NTAPI FsRtlProcessFileLock(IN PFILE_LOCK FileLock, IN PIRP Irp, IN PVOID Context OPTIONAL)
PFILE_LOCK NTAPI FsRtlAllocateFileLock(IN PCOMPLETE_LOCK_IRP_ROUTINE CompleteLockIrpRoutine OPTIONAL, IN PUNLOCK_ROUTINE UnlockRoutine OPTIONAL)
NTSTATUS NTAPI FsRtlFastUnlockAll(IN PFILE_LOCK FileLock, IN PFILE_OBJECT FileObject, IN PEPROCESS Process, IN PVOID Context OPTIONAL)
static VOID NTAPI LockRemoveIrp(PIO_CSQ Csq, PIRP Irp)
static PIRP NTAPI LockPeekNextIrp(PIO_CSQ Csq, PIRP Irp, PVOID PeekContext)
BOOLEAN NTAPI FsRtlFastCheckLockForRead(IN PFILE_LOCK FileLock, IN PLARGE_INTEGER FileOffset, IN PLARGE_INTEGER Length, IN ULONG Key, IN PFILE_OBJECT FileObject, IN PVOID Process)
BOOLEAN NTAPI FsRtlCheckLockForReadAccess(IN PFILE_LOCK FileLock, IN PIRP Irp)
struct _LOCK_INFORMATION * PLOCK_INFORMATION
VOID NTAPI FsRtlCompleteLockIrpReal(IN PCOMPLETE_LOCK_IRP_ROUTINE CompleteRoutine, IN PVOID Context, IN PIRP Irp, IN NTSTATUS Status, OUT PNTSTATUS NewStatus, IN PFILE_OBJECT FileObject OPTIONAL)
static RTL_GENERIC_COMPARE_RESULTS NTAPI LockCompare(PRTL_GENERIC_TABLE Table, PVOID PtrA, PVOID PtrB)
VOID NTAPI FsRtlFreeFileLock(IN PFILE_LOCK FileLock)
NTSTATUS NTAPI FsRtlFastUnlockAllByKey(IN PFILE_LOCK FileLock, IN PFILE_OBJECT FileObject, IN PEPROCESS Process, IN ULONG Key, IN PVOID Context OPTIONAL)
struct _LOCK_SHARED_RANGE * PLOCK_SHARED_RANGE
static NTSTATUS NTAPI LockInsertIrpEx(PIO_CSQ Csq, PIRP Irp, PVOID InsertContext)
static VOID NTAPI LockFree(PRTL_GENERIC_TABLE Table, PVOID Buffer)
_Must_inspect_result_ _In_opt_ PUNLOCK_ROUTINE UnlockRoutine
_In_ PFILE_OBJECT _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ PEPROCESS _In_ ULONG _In_opt_ PVOID _In_ BOOLEAN AlreadySynchronized
_In_opt_ PCOMPLETE_LOCK_IRP_ROUTINE CompleteLockIrpRoutine
#define FsRtlCompleteRequest(IRP, STATUS)
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
NTSTATUS(NTAPI * PCOMPLETE_LOCK_IRP_ROUTINE)(_In_ PVOID Context, _In_ PIRP Irp)
VOID(NTAPI * PUNLOCK_ROUTINE)(_In_ PVOID Context, _In_ PFILE_LOCK_INFO FileLockInfo)
VOID NTAPI RtlInitializeGenericTable(IN PRTL_GENERIC_TABLE Table, IN PRTL_GENERIC_COMPARE_ROUTINE CompareRoutine, IN PRTL_GENERIC_ALLOCATE_ROUTINE AllocateRoutine, IN PRTL_GENERIC_FREE_ROUTINE FreeRoutine, IN PVOID TableContext)
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
#define ExFreePoolWithTag(_P, _T)
static OUT PIO_STATUS_BLOCK IoStatusBlock
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
_In_ ULONG _In_ ULONG _In_ ULONG Length
PEPROCESS NTAPI IoGetRequestorProcess(IN PIRP Irp)
#define STATUS_FILE_LOCK_CONFLICT
#define STATUS_RANGE_NOT_LOCKED
#define IRP_MJ_LOCK_CONTROL
PULONG MinorVersion OPTIONAL
base of all file and directory entries
LARGE_INTEGER StartingByte
PCOMPLETE_LOCK_IRP_ROUTINE CompleteLockIrpRoutine
struct _IO_STACK_LOCATION::@3979::@3984 Write
struct _IO_STACK_LOCATION::@3979::@3995 LockControl
struct _IO_STACK_LOCATION::@3979::@3983 Read
union _IO_STACK_LOCATION::@1580 Parameters
ULONG POINTER_ALIGNMENT Key
struct _LIST_ENTRY * Flink
#define RtlCopyMemory(Destination, Source, Length)
#define RtlZeroMemory(Destination, Length)
#define CONTAINING_RECORD(address, type, field)
#define STATUS_INVALID_DEVICE_REQUEST
#define STATUS_INVALID_PARAMETER
FILE_SHARED_LOCK_ENTRY Shared
FILE_EXCLUSIVE_LOCK_ENTRY Exclusive
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
struct LOOKASIDE_ALIGN _PAGED_LOOKASIDE_LIST PAGED_LOOKASIDE_LIST
#define IRP_MN_UNLOCK_ALL
#define IRP_MN_UNLOCK_ALL_BY_KEY
#define SL_FAIL_IMMEDIATELY
#define IRP_MN_UNLOCK_SINGLE
#define SL_EXCLUSIVE_LOCK
NTSYSAPI BOOLEAN NTAPI RtlDeleteElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ PVOID Buffer)
NTSYSAPI PVOID NTAPI RtlInsertElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_reads_bytes_(BufferSize) PVOID Buffer, _In_ CLONG BufferSize, _Out_opt_ PBOOLEAN NewElement)
_Must_inspect_result_ NTSYSAPI PVOID NTAPI RtlEnumerateGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ BOOLEAN Restart)
_Must_inspect_result_ NTSYSAPI PVOID NTAPI RtlGetElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ ULONG I)
NTSYSAPI ULONG NTAPI RtlNumberGenericTableElements(_In_ PRTL_GENERIC_TABLE Table)
_Must_inspect_result_ NTSYSAPI PVOID NTAPI RtlLookupElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ PVOID Buffer)
enum _RTL_GENERIC_COMPARE_RESULTS RTL_GENERIC_COMPARE_RESULTS