pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS


workaround for wintar zero bytes in text files bug
Posted by Anonymous on Mon 16th Dec 2024 17:51
raw | new post
view followups (newest first): workaround for wintar zero bytes in text files bug by Anonymous
modification of post by Anonymous (view diff)

  1. diff --git a/sys/nfs41sys_driver.h b/sys/nfs41sys_driver.h
  2. index 1c39ab6..0e0107c 100644
  3. --- a/sys/nfs41sys_driver.h
  4. +++ b/sys/nfs41sys_driver.h
  5. @@ -48,8 +48,10 @@
  6.      (POOL_FLAG_UNINITIALIZED|POOL_FLAG_CACHE_ALIGNED)
  7.  
  8.  #define RxAllocatePoolWithTag(rxallocpool, numbytes, tag) \
  9. -    ExAllocatePool2(((((rxallocpool) == NonPagedPoolNx)? \
  10. -            POOL_FLAG_NON_PAGED:POOL_FLAG_NON_PAGED_EXECUTE) | \
  11. +    ExAllocatePool2((( \
  12. +            ((rxallocpool) == PagedPool)?POOL_FLAG_PAGED: \
  13. +                (((rxallocpool) == NonPagedPoolNx)? \
  14. +                    POOL_FLAG_NON_PAGED:POOL_FLAG_NON_PAGED_EXECUTE)) | \
  15.              RXALLOCATEPOOL_DEFAULT_ALLOCATEPOOL2FLAGS), \
  16.          (numbytes), (tag))
  17.  #endif /* EXALLOCATEPOOLWITHTAG_DEPRECATED */
  18. diff --git a/sys/nfs41sys_readwrite.c b/sys/nfs41sys_readwrite.c
  19. index 050819c..b34a4a3 100644
  20. --- a/sys/nfs41sys_readwrite.c
  21. +++ b/sys/nfs41sys_readwrite.c
  22. @@ -58,6 +58,7 @@
  23.  #include <winerror.h>
  24.  
  25.  #include <Ntstrsafe.h>
  26. +#include <stdbool.h>
  27.  
  28.  #include "nfs41sys_buildconfig.h"
  29.  
  30. @@ -333,7 +334,7 @@ NTSTATUS nfs41_Write(
  31.      IN OUT PRX_CONTEXT RxContext)
  32.  {
  33.      NTSTATUS status = STATUS_INSUFFICIENT_RESOURCES;
  34. -    nfs41_updowncall_entry *entry;
  35. +    nfs41_updowncall_entry *entry = NULL;
  36.      BOOLEAN async = FALSE;
  37.      PLOWIO_CONTEXT LowIoContext  = &RxContext->LowIoContext;
  38.      __notnull PMRX_SRV_OPEN SrvOpen = RxContext->pRelevantSrvOpen;
  39. @@ -344,6 +345,11 @@ NTSTATUS nfs41_Write(
  40.      __notnull PNFS41_FCB nfs41_fcb = NFS41GetFcbExtension(RxContext->pFcb);
  41.      __notnull PNFS41_FOBX nfs41_fobx = NFS41GetFobxExtension(RxContext->pFobx);
  42.      DWORD io_delay;
  43. +#if 1
  44. +    void *userbuffer_mem = NULL;
  45. +    PMDL userbuffer_mdl = NULL;
  46. +    PVOID UserBuffer = NULL;
  47. +#endif
  48.  #ifdef ENABLE_TIMINGS
  49.      LARGE_INTEGER t1, t2;
  50.      t1 = KeQueryPerformanceCounter(NULL);
  51. @@ -362,9 +368,43 @@ NTSTATUS nfs41_Write(
  52.          pNetRootContext->nfs41d_version, SrvOpen->pAlreadyPrefixedName, &entry);
  53.      if (status) goto out;
  54.  
  55. +#if 1
  56. +    userbuffer_mem = RxAllocatePoolWithTag(NonPagedPoolNx,
  57. +        LowIoContext->ParamsFor.ReadWrite.ByteCount,
  58. +        NFS41_MM_POOLTAG_DOWN);
  59. +    if (userbuffer_mem == NULL) {
  60. +        status = STATUS_NO_MEMORY;
  61. +        goto out;
  62. +    }
  63. +
  64. +    UserBuffer = RxLowIoGetBufferAddress(RxContext);
  65. +    if (UserBuffer == NULL) {
  66. +        status = STATUS_NO_MEMORY;
  67. +        goto out;
  68. +    }
  69. +
  70. +    userbuffer_mdl = IoAllocateMdl(userbuffer_mem,
  71. +        LowIoContext->ParamsFor.ReadWrite.ByteCount,
  72. +        FALSE, FALSE, NULL);
  73. +    if (userbuffer_mdl == NULL) {
  74. +        status = STATUS_NO_MEMORY;
  75. +        goto out;
  76. +    }
  77. +
  78. +    MmProbeAndLockPages(userbuffer_mdl, KernelMode, IoModifyAccess);
  79. +
  80. +    (void)RtlCopyMemory(userbuffer_mem,
  81. +        ((char *)UserBuffer)+LowIoContext->ParamsFor.ReadWrite.ByteOffset,
  82. +        LowIoContext->ParamsFor.ReadWrite.ByteCount);
  83. +
  84. +    entry->u.ReadWrite.MdlAddress = userbuffer_mdl;
  85. +    entry->buf_len = LowIoContext->ParamsFor.ReadWrite.ByteCount;
  86. +    entry->u.ReadWrite.offset = 0;
  87. +#else
  88.      entry->u.ReadWrite.MdlAddress = LowIoContext->ParamsFor.ReadWrite.Buffer;
  89.      entry->buf_len = LowIoContext->ParamsFor.ReadWrite.ByteCount;
  90.      entry->u.ReadWrite.offset = LowIoContext->ParamsFor.ReadWrite.ByteOffset;
  91. +#endif
  92.  
  93.      if (FlagOn(RxContext->CurrentIrpSp->FileObject->Flags,
  94.              FO_SYNCHRONOUS_IO) == FALSE) {
  95. @@ -420,6 +460,17 @@ NTSTATUS nfs41_Write(
  96.      }
  97.      nfs41_UpcallDestroy(entry);
  98.  out:
  99. +#if 1
  100. +    if (!async) {
  101. +        if (userbuffer_mdl) {
  102. +            IoFreeMdl(userbuffer_mdl);
  103. +        }
  104. +        if (userbuffer_mem) {
  105. +            RxFreePool(userbuffer_mem);
  106. +        }
  107. +    }
  108. +#endif
  109. +
  110.  #ifdef ENABLE_TIMINGS
  111.      t2 = KeQueryPerformanceCounter(NULL);
  112.      InterlockedIncrement(&write.tops);

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.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at