- diff --git a/build.vc19/nfs41_driver/nfs41_driver.vcxproj b/build.vc19/nfs41_driver/nfs41_driver.vcxproj
- index 0affe23..9c55630 100644
- --- a/build.vc19/nfs41_driver/nfs41_driver.vcxproj
- +++ b/build.vc19/nfs41_driver/nfs41_driver.vcxproj
- @@ -144,7 +144,7 @@
- <AdditionalOptions>/std:c17 /Zc:preprocessor- /kernel /wd4100 /wd4201 /wd5104</AdditionalOptions>
- </ClCompile>
- <Link>
- - <AdditionalDependencies>$(DDK_LIB_PATH)\ntoskrnl.lib;$(DDK_LIB_PATH)\hal.lib;$(DDK_LIB_PATH)\BufferOverflowfastfailK.lib;$(DDK_LIB_PATH)\ksecdd.lib;$(DDK_LIB_PATH)\rxce.lib;$(DDK_LIB_PATH)\rdbsslib.lib</AdditionalDependencies>
- + <AdditionalDependencies>$(DDK_LIB_PATH)\ntoskrnl.lib;$(DDK_LIB_PATH)\hal.lib;$(DDK_LIB_PATH)\BufferOverflowfastfailK.lib;$(DDK_LIB_PATH)\ksecdd.lib;$(DDK_LIB_PATH)\rxce.lib;$(DDK_LIB_PATH)\rdbsslib.lib;$(DDK_LIB_PATH)\tdi.lib</AdditionalDependencies>
- </Link>
- </ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
- @@ -158,7 +158,7 @@
- <AdditionalOptions>/std:c17 /Zc:preprocessor- /kernel /wd4100 /wd4201 /wd5104</AdditionalOptions>
- </ClCompile>
- <Link>
- - <AdditionalDependencies>$(DDK_LIB_PATH)\ntoskrnl.lib;$(DDK_LIB_PATH)\hal.lib;$(DDK_LIB_PATH)\BufferOverflowfastfailK.lib;$(DDK_LIB_PATH)\ksecdd.lib;$(DDK_LIB_PATH)\rxce.lib;$(DDK_LIB_PATH)\rdbsslib.lib</AdditionalDependencies>
- + <AdditionalDependencies>$(DDK_LIB_PATH)\ntoskrnl.lib;$(DDK_LIB_PATH)\hal.lib;$(DDK_LIB_PATH)\BufferOverflowfastfailK.lib;$(DDK_LIB_PATH)\ksecdd.lib;$(DDK_LIB_PATH)\rxce.lib;$(DDK_LIB_PATH)\rdbsslib.lib;$(DDK_LIB_PATH)\tdi.lib</AdditionalDependencies>
- </Link>
- </ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- @@ -172,7 +172,7 @@
- <AdditionalOptions>/std:c17 /Zc:preprocessor- /kernel /wd4100 /wd4201 /wd5104</AdditionalOptions>
- </ClCompile>
- <Link>
- - <AdditionalDependencies>$(DDK_LIB_PATH)\ntoskrnl.lib;$(DDK_LIB_PATH)\hal.lib;$(DDK_LIB_PATH)\BufferOverflowfastfailK.lib;$(DDK_LIB_PATH)\ksecdd.lib;$(DDK_LIB_PATH)\rxce.lib;$(DDK_LIB_PATH)\rdbsslib.lib</AdditionalDependencies>
- + <AdditionalDependencies>$(DDK_LIB_PATH)\ntoskrnl.lib;$(DDK_LIB_PATH)\hal.lib;$(DDK_LIB_PATH)\BufferOverflowfastfailK.lib;$(DDK_LIB_PATH)\ksecdd.lib;$(DDK_LIB_PATH)\rxce.lib;$(DDK_LIB_PATH)\rdbsslib.lib;$(DDK_LIB_PATH)\tdi.lib</AdditionalDependencies>
- </Link>
- <DriverSign>
- <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
- @@ -189,7 +189,7 @@
- <AdditionalOptions>/std:c17 /Zc:preprocessor- /kernel /wd4100 /wd4201 /wd5104</AdditionalOptions>
- </ClCompile>
- <Link>
- - <AdditionalDependencies>$(DDK_LIB_PATH)\ntoskrnl.lib;$(DDK_LIB_PATH)\hal.lib;$(DDK_LIB_PATH)\BufferOverflowfastfailK.lib;$(DDK_LIB_PATH)\ksecdd.lib;$(DDK_LIB_PATH)\rxce.lib;$(DDK_LIB_PATH)\rdbsslib.lib</AdditionalDependencies>
- + <AdditionalDependencies>$(DDK_LIB_PATH)\ntoskrnl.lib;$(DDK_LIB_PATH)\hal.lib;$(DDK_LIB_PATH)\BufferOverflowfastfailK.lib;$(DDK_LIB_PATH)\ksecdd.lib;$(DDK_LIB_PATH)\rxce.lib;$(DDK_LIB_PATH)\rdbsslib.lib;$(DDK_LIB_PATH)\tdi.lib</AdditionalDependencies>
- </Link>
- <DriverSign>
- <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
- @@ -206,7 +206,7 @@
- <AdditionalOptions>/std:c17 /Zc:preprocessor- /kernel /wd4100 /wd4201 /wd5104</AdditionalOptions>
- </ClCompile>
- <Link>
- - <AdditionalDependencies>$(DDK_LIB_PATH)\ntoskrnl.lib;$(DDK_LIB_PATH)\hal.lib;$(DDK_LIB_PATH)\BufferOverflowfastfailK.lib;$(DDK_LIB_PATH)\ksecdd.lib;$(DDK_LIB_PATH)\rxce.lib;$(DDK_LIB_PATH)\rdbsslib.lib</AdditionalDependencies>
- + <AdditionalDependencies>$(DDK_LIB_PATH)\ntoskrnl.lib;$(DDK_LIB_PATH)\hal.lib;$(DDK_LIB_PATH)\BufferOverflowfastfailK.lib;$(DDK_LIB_PATH)\ksecdd.lib;$(DDK_LIB_PATH)\rxce.lib;$(DDK_LIB_PATH)\rdbsslib.lib;$(DDK_LIB_PATH)\tdi.lib</AdditionalDependencies>
- </Link>
- </ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
- @@ -220,7 +220,7 @@
- <AdditionalOptions>/std:c17 /Zc:preprocessor- /kernel /wd4100 /wd4201 /wd5104</AdditionalOptions>
- </ClCompile>
- <Link>
- - <AdditionalDependencies>$(DDK_LIB_PATH)\ntoskrnl.lib;$(DDK_LIB_PATH)\hal.lib;$(DDK_LIB_PATH)\BufferOverflowfastfailK.lib;$(DDK_LIB_PATH)\ksecdd.lib;$(DDK_LIB_PATH)\rxce.lib;$(DDK_LIB_PATH)\rdbsslib.lib</AdditionalDependencies>
- + <AdditionalDependencies>$(DDK_LIB_PATH)\ntoskrnl.lib;$(DDK_LIB_PATH)\hal.lib;$(DDK_LIB_PATH)\BufferOverflowfastfailK.lib;$(DDK_LIB_PATH)\ksecdd.lib;$(DDK_LIB_PATH)\rxce.lib;$(DDK_LIB_PATH)\rdbsslib.lib;$(DDK_LIB_PATH)\tdi.lib</AdditionalDependencies>
- </Link>
- </ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
- @@ -234,7 +234,7 @@
- <AdditionalOptions>/std:c17 /Zc:preprocessor- /kernel /wd4100 /wd4201 /wd5104</AdditionalOptions>
- </ClCompile>
- <Link>
- - <AdditionalDependencies>$(DDK_LIB_PATH)\ntoskrnl.lib;$(DDK_LIB_PATH)\hal.lib;$(DDK_LIB_PATH)\BufferOverflowfastfailK.lib;$(DDK_LIB_PATH)\ksecdd.lib;$(DDK_LIB_PATH)\rxce.lib;$(DDK_LIB_PATH)\rdbsslib.lib</AdditionalDependencies>
- + <AdditionalDependencies>$(DDK_LIB_PATH)\ntoskrnl.lib;$(DDK_LIB_PATH)\hal.lib;$(DDK_LIB_PATH)\BufferOverflowfastfailK.lib;$(DDK_LIB_PATH)\ksecdd.lib;$(DDK_LIB_PATH)\rxce.lib;$(DDK_LIB_PATH)\rdbsslib.lib;$(DDK_LIB_PATH)\tdi.lib</AdditionalDependencies>
- </Link>
- <DriverSign>
- <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
- @@ -251,7 +251,7 @@
- <AdditionalOptions>/std:c17 /Zc:preprocessor- /kernel /wd4100 /wd4201 /wd5104</AdditionalOptions>
- </ClCompile>
- <Link>
- - <AdditionalDependencies>$(DDK_LIB_PATH)\ntoskrnl.lib;$(DDK_LIB_PATH)\hal.lib;$(DDK_LIB_PATH)\BufferOverflowfastfailK.lib;$(DDK_LIB_PATH)\ksecdd.lib;$(DDK_LIB_PATH)\rxce.lib;$(DDK_LIB_PATH)\rdbsslib.lib</AdditionalDependencies>
- + <AdditionalDependencies>$(DDK_LIB_PATH)\ntoskrnl.lib;$(DDK_LIB_PATH)\hal.lib;$(DDK_LIB_PATH)\BufferOverflowfastfailK.lib;$(DDK_LIB_PATH)\ksecdd.lib;$(DDK_LIB_PATH)\rxce.lib;$(DDK_LIB_PATH)\rdbsslib.lib;$(DDK_LIB_PATH)\tdi.lib</AdditionalDependencies>
- </Link>
- <DriverSign>
- <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
- diff --git a/sys/nfs41sys_driver.h b/sys/nfs41sys_driver.h
- index 1c39ab6..0e0107c 100644
- --- a/sys/nfs41sys_driver.h
- +++ b/sys/nfs41sys_driver.h
- @@ -48,8 +48,10 @@
- (POOL_FLAG_UNINITIALIZED|POOL_FLAG_CACHE_ALIGNED)
- #define RxAllocatePoolWithTag(rxallocpool, numbytes, tag) \
- - ExAllocatePool2(((((rxallocpool) == NonPagedPoolNx)? \
- - POOL_FLAG_NON_PAGED:POOL_FLAG_NON_PAGED_EXECUTE) | \
- + ExAllocatePool2((( \
- + ((rxallocpool) == PagedPool)?POOL_FLAG_PAGED: \
- + (((rxallocpool) == NonPagedPoolNx)? \
- + POOL_FLAG_NON_PAGED:POOL_FLAG_NON_PAGED_EXECUTE)) | \
- RXALLOCATEPOOL_DEFAULT_ALLOCATEPOOL2FLAGS), \
- (numbytes), (tag))
- #endif /* EXALLOCATEPOOLWITHTAG_DEPRECATED */
- diff --git a/sys/nfs41sys_readwrite.c b/sys/nfs41sys_readwrite.c
- index 050819c..a70ead2 100644
- --- a/sys/nfs41sys_readwrite.c
- +++ b/sys/nfs41sys_readwrite.c
- @@ -58,6 +58,8 @@
- #include <winerror.h>
- #include <Ntstrsafe.h>
- +#include <stdbool.h>
- +#include <tdikrnl.h>
- #include "nfs41sys_buildconfig.h"
- @@ -333,7 +335,7 @@ NTSTATUS nfs41_Write(
- IN OUT PRX_CONTEXT RxContext)
- {
- NTSTATUS status = STATUS_INSUFFICIENT_RESOURCES;
- - nfs41_updowncall_entry *entry;
- + nfs41_updowncall_entry *entry = NULL;
- BOOLEAN async = FALSE;
- PLOWIO_CONTEXT LowIoContext = &RxContext->LowIoContext;
- __notnull PMRX_SRV_OPEN SrvOpen = RxContext->pRelevantSrvOpen;
- @@ -344,6 +346,11 @@ NTSTATUS nfs41_Write(
- __notnull PNFS41_FCB nfs41_fcb = NFS41GetFcbExtension(RxContext->pFcb);
- __notnull PNFS41_FOBX nfs41_fobx = NFS41GetFobxExtension(RxContext->pFobx);
- DWORD io_delay;
- +#if 1
- + void *userbuffer_mem = NULL;
- + PMDL userbuffer_mdl = NULL;
- +// PVOID UserBuffer = NULL;
- +#endif
- #ifdef ENABLE_TIMINGS
- LARGE_INTEGER t1, t2;
- t1 = KeQueryPerformanceCounter(NULL);
- @@ -362,9 +369,151 @@ NTSTATUS nfs41_Write(
- pNetRootContext->nfs41d_version, SrvOpen->pAlreadyPrefixedName, &entry);
- if (status) goto out;
- +#if 1
- + ULONG padded_readwrite_bytecount = LowIoContext->ParamsFor.ReadWrite.ByteCount + (8192) /* fixme */;
- +
- +#if 1
- + userbuffer_mem = ExAllocatePool2(POOL_FLAG_PAGED, padded_readwrite_bytecount, NFS41_MM_POOLTAG_DOWN);
- +#else
- + userbuffer_mem = RxAllocatePoolWithTag(NonPagedPoolNx,
- + padded_readwrite_bytecount,
- + NFS41_MM_POOLTAG_DOWN);
- +#endif
- + if (userbuffer_mem == NULL) {
- + status = STATUS_NO_MEMORY;
- + goto out;
- + }
- +
- + RtlZeroMemory(userbuffer_mem, padded_readwrite_bytecount);
- +#if 0
- + UserBuffer = RxLowIoGetBufferAddress(RxContext);
- + if (UserBuffer == NULL) {
- + status = STATUS_NO_MEMORY;
- + goto out;
- + }
- +#endif
- + userbuffer_mdl = IoAllocateMdl(userbuffer_mem,
- + padded_readwrite_bytecount,
- + FALSE, FALSE, NULL);
- + if (userbuffer_mdl == NULL) {
- + status = STATUS_NO_MEMORY;
- + goto out;
- + }
- +
- +#if 1
- +#pragma warning( push )
- +/*
- + * C28145: "The opaque MDL structure should not be modified by a
- + * driver.", |MDL_MAPPING_CAN_FAIL| is the exception
- + */
- +#pragma warning (disable : 28145)
- + userbuffer_mdl->MdlFlags |= MDL_MAPPING_CAN_FAIL;
- +#pragma warning( pop )
- +#endif
- +
- + MmProbeAndLockPages(userbuffer_mdl, KernelMode, IoModifyAccess);
- +
- +#if 1
- +
- +#if 1
- + PVOID Src;
- +
- + if ((Src = MmGetSystemAddressForMdlSafe(LowIoContext->ParamsFor.ReadWrite.Buffer, NormalPagePriority)) == NULL) {
- + return STATUS_INSUFFICIENT_RESOURCES;
- + }
- +
- + ULONG mdl_bytecount = MmGetMdlByteCount(LowIoContext->ParamsFor.ReadWrite.Buffer);
- +
- + if (mdl_bytecount < LowIoContext->ParamsFor.ReadWrite.ByteCount) {
- + DbgP("#### ERROR: mdl_bytecount(=%lld) < LowIoContext->ParamsFor.ReadWrite.ByteCount(=%lld)\n",
- + (long long)mdl_bytecount,
- + (long long)LowIoContext->ParamsFor.ReadWrite.ByteCount);
- + DbgP("ReadWrite.Buffer=(Next=0x%p, Size=%ld, MdlFlags=0x%lx, "
- + "Process=0x%p, MappedSystemVa=0x%p, StartVa=0x%p, "
- + "ByteCount=%ld, ByteOffset=%ld)\n",
- + (void *)LowIoContext->ParamsFor.ReadWrite.Buffer->Next,
- + (long)LowIoContext->ParamsFor.ReadWrite.Buffer->Size,
- + (long)LowIoContext->ParamsFor.ReadWrite.Buffer->MdlFlags,
- + (void *)LowIoContext->ParamsFor.ReadWrite.Buffer->Process,
- + (void *)LowIoContext->ParamsFor.ReadWrite.Buffer->MappedSystemVa,
- + (void *)LowIoContext->ParamsFor.ReadWrite.Buffer->StartVa,
- + (long)LowIoContext->ParamsFor.ReadWrite.Buffer->ByteCount,
- + (long)LowIoContext->ParamsFor.ReadWrite.Buffer->ByteOffset);
- + return STATUS_INTERNAL_ERROR;
- + }
- +
- +#if 1
- + volatile char *cp_dest = userbuffer_mem;
- + volatile char *cp_src = ((char *)Src)+LowIoContext->ParamsFor.ReadWrite.ByteOffset;
- + volatile char tmpbyte;
- +
- + long long cp_i;
- +
- + long long cp_max = LowIoContext->ParamsFor.ReadWrite.ByteCount;
- +
- + if (LowIoContext->ParamsFor.ReadWrite.ByteOffset)
- + cp_max--;
- +
- + for (cp_i = 0 ; cp_i < cp_max ; cp_i++) {
- + tmpbyte = *cp_src++;
- +
- + *cp_dest++ = tmpbyte;
- + }
- +#else
- + (void)RtlCopyMemory(userbuffer_mem,
- + ((char *)Src)+LowIoContext->ParamsFor.ReadWrite.ByteOffset,
- + LowIoContext->ParamsFor.ReadWrite.ByteCount);
- +#endif
- +#else
- + ULONG bytescopied = 0UL;
- + NTSTATUS tdi_status;
- +
- + tdi_status = TdiCopyMdlToBuffer(LowIoContext->ParamsFor.ReadWrite.Buffer,
- + (ULONG)LowIoContext->ParamsFor.ReadWrite.ByteOffset /* fixme: Add assert LONGLONG2ULONG cast */,
- + userbuffer_mem,
- + 0,
- + LowIoContext->ParamsFor.ReadWrite.ByteCount+1,
- + &bytescopied);
- +
- + if (((tdi_status != STATUS_SUCCESS) && (tdi_status != STATUS_BUFFER_OVERFLOW)) ||
- + (bytescopied != LowIoContext->ParamsFor.ReadWrite.ByteCount)) {
- + DbgP("#### ERROR: tdi_status=0x%lx || (bytescopied(=%lld) != ReadWrite.ByteCount(=%lld))\n",
- + (long)tdi_status,
- + (long long)bytescopied,
- + (long long)LowIoContext->ParamsFor.ReadWrite.ByteCount);
- + DbgP("ReadWrite.Buffer=(Next=0x%p, Size=%ld, MdlFlags=0x%lx, "
- + "Process=0x%p, MappedSystemVa=0x%p, StartVa=0x%p, "
- + "ByteCount=%ld, ByteOffset=%ld)\n",
- + (void *)LowIoContext->ParamsFor.ReadWrite.Buffer->Next,
- + (long)LowIoContext->ParamsFor.ReadWrite.Buffer->Size,
- + (long)LowIoContext->ParamsFor.ReadWrite.Buffer->MdlFlags,
- + (void *)LowIoContext->ParamsFor.ReadWrite.Buffer->Process,
- + (void *)LowIoContext->ParamsFor.ReadWrite.Buffer->MappedSystemVa,
- + (void *)LowIoContext->ParamsFor.ReadWrite.Buffer->StartVa,
- + (long)LowIoContext->ParamsFor.ReadWrite.Buffer->ByteCount,
- + (long)LowIoContext->ParamsFor.ReadWrite.Buffer->ByteOffset);
- + }
- + if ((bytescopied == 0) && (LowIoContext->ParamsFor.ReadWrite.ByteCount > 0)) {
- + DbgP("requesting STATUS_RETRY\n");
- +// status = STATUS_RETRY;
- +// goto out;
- + }
- +
- +#endif
- +#else
- + (void)RtlCopyMemory(userbuffer_mem,
- + ((char *)UserBuffer)+LowIoContext->ParamsFor.ReadWrite.ByteOffset,
- + LowIoContext->ParamsFor.ReadWrite.ByteCount);
- +#endif
- +
- + entry->u.ReadWrite.MdlAddress = userbuffer_mdl;
- + entry->buf_len = LowIoContext->ParamsFor.ReadWrite.ByteCount;
- + entry->u.ReadWrite.offset = 0;
- +#else
- entry->u.ReadWrite.MdlAddress = LowIoContext->ParamsFor.ReadWrite.Buffer;
- entry->buf_len = LowIoContext->ParamsFor.ReadWrite.ByteCount;
- entry->u.ReadWrite.offset = LowIoContext->ParamsFor.ReadWrite.ByteOffset;
- +#endif
- if (FlagOn(RxContext->CurrentIrpSp->FileObject->Flags,
- FO_SYNCHRONOUS_IO) == FALSE) {
- @@ -420,6 +569,17 @@ NTSTATUS nfs41_Write(
- }
- nfs41_UpcallDestroy(entry);
- out:
- +#if 1
- + if (!async) {
- + if (userbuffer_mdl) {
- + IoFreeMdl(userbuffer_mdl);
- + }
- + if (userbuffer_mem) {
- + RxFreePool(userbuffer_mem);
- + }
- + }
- +#endif
- +
- #ifdef ENABLE_TIMINGS
- t2 = KeQueryPerformanceCounter(NULL);
- InterlockedIncrement(&write.tops);
workaround for wintar zero bytes in text files bug
Posted by Anonymous on Wed 18th Dec 2024 10:13
raw | new post
modification of post by Anonymous (view diff)
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.