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 16:30
raw | new post
view followups (newest first): workaround for wintar zero bytes in text files bug by Anonymous

  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..a1f5cc1 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. +    PVOID UserBuffer = NULL;
  46. +    bool mdl_locked = false;
  47. +#endif
  48.  #ifdef ENABLE_TIMINGS
  49.      LARGE_INTEGER t1, t2;
  50.      t1 = KeQueryPerformanceCounter(NULL);
  51. @@ -362,9 +368,66 @@ 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. +#if 1
  65. +    if (!RxLowIoIsMdlLocked(LowIoContext->ParamsFor.ReadWrite.Buffer)) {
  66. +        MmProbeAndLockPages(LowIoContext->ParamsFor.ReadWrite.Buffer, KernelMode, IoModifyAccess);
  67. +        mdl_locked = true;
  68. +    }
  69. +#endif
  70. +
  71. +#if 1
  72. +    __try {    
  73. +        UserBuffer = MmMapLockedPagesSpecifyCache(
  74. +            LowIoContext->ParamsFor.ReadWrite.Buffer,
  75. +            KernelMode, MmCached, NULL, FALSE,
  76. +            NormalPagePriority);
  77. +    } __except(EXCEPTION_EXECUTE_HANDLER) {
  78. +        NTSTATUS code;
  79. +        code = GetExceptionCode();
  80. +        print_error("nfs41_Write: Call to "
  81. +            "MmMapLockedPagesSpecifyCache() failed due to "
  82. +            "exception 0x%lx\n", (long)code);
  83. +        status = STATUS_ACCESS_VIOLATION;
  84. +        goto out;
  85. +    }
  86. +#else
  87. +    UserBuffer = RxLowIoGetBufferAddress(RxContext);
  88. +#endif
  89. +    if (UserBuffer == NULL) {
  90. +        status = STATUS_NO_MEMORY;
  91. +        goto out;
  92. +    }
  93. +
  94. +    entry->u.ReadWrite.MdlAddress = IoAllocateMdl(userbuffer_mem,
  95. +        LowIoContext->ParamsFor.ReadWrite.ByteCount,
  96. +        FALSE, FALSE, NULL);
  97. +    if (entry->u.ReadWrite.MdlAddress == NULL) {
  98. +        status = STATUS_NO_MEMORY;
  99. +        goto out;
  100. +    }
  101. +
  102. +    MmProbeAndLockPages(entry->u.ReadWrite.MdlAddress, KernelMode, IoModifyAccess);
  103. +
  104. +    (void)RtlCopyMemory(userbuffer_mem,
  105. +        ((char *)UserBuffer)+LowIoContext->ParamsFor.ReadWrite.ByteOffset,
  106. +        LowIoContext->ParamsFor.ReadWrite.ByteCount);
  107. +
  108. +    entry->buf_len = LowIoContext->ParamsFor.ReadWrite.ByteCount;
  109. +    entry->u.ReadWrite.offset = 0;
  110. +#else
  111.      entry->u.ReadWrite.MdlAddress = LowIoContext->ParamsFor.ReadWrite.Buffer;
  112.      entry->buf_len = LowIoContext->ParamsFor.ReadWrite.ByteCount;
  113.      entry->u.ReadWrite.offset = LowIoContext->ParamsFor.ReadWrite.ByteOffset;
  114. +#endif
  115.  
  116.      if (FlagOn(RxContext->CurrentIrpSp->FileObject->Flags,
  117.              FO_SYNCHRONOUS_IO) == FALSE) {
  118. @@ -420,6 +483,20 @@ NTSTATUS nfs41_Write(
  119.      }
  120.      nfs41_UpcallDestroy(entry);
  121.  out:
  122. +#if 1
  123. +    if (UserBuffer) {
  124. +        MmUnmapLockedPages(UserBuffer, LowIoContext->ParamsFor.ReadWrite.Buffer);
  125. +    }
  126. +
  127. +    if (entry && entry->u.ReadWrite.MdlAddress) {
  128. +        IoFreeMdl(entry->u.ReadWrite.MdlAddress);
  129. +        entry->u.ReadWrite.MdlAddress = NULL;
  130. +    }
  131. +    if (userbuffer_mem) {
  132. +        RxFreePool(userbuffer_mem);
  133. +    }
  134. +#endif
  135. +
  136.  #ifdef ENABLE_TIMINGS
  137.      t2 = KeQueryPerformanceCounter(NULL);
  138.      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