pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Kernel support for ARM64+misc, 2024-09-16
Posted by Anonymous on Mon 16th Sep 2024 18:20
raw | new post

  1. From 590e18bf7b46671b0f764ff851138e92bd96e7cf Mon Sep 17 00:00:00 2001
  2. From: Dan Shelton <dan.f.shelton@gmail.com>
  3. Date: Mon, 16 Sep 2024 15:54:13 +0200
  4. Subject: [PATCH 1/2] build.vc19,cygwin,sys: Implement FsRtlCopyRead2(),
  5.  FsRtlCopyWrite2() for ARM64
  6.  
  7. Implement FsRtlCopyRead2(), FsRtlCopyWrite2() for ARM64.
  8.  
  9. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  10. ---
  11. build.vc19/nfs41_driver/nfs41_driver.vcxproj  |  17 +-
  12.  .../nfs41_driver/nfs41_driver.vcxproj.filters |   3 +
  13.  cygwin/Makefile                               |   2 +-
  14.  sys/copysup.c                                 | 584 ++++++++++++++++++
  15.  4 files changed, 597 insertions(+), 9 deletions(-)
  16.  create mode 100644 sys/copysup.c
  17.  
  18. diff --git a/build.vc19/nfs41_driver/nfs41_driver.vcxproj b/build.vc19/nfs41_driver/nfs41_driver.vcxproj
  19. index 51a72f5..589eef1 100644
  20. --- a/build.vc19/nfs41_driver/nfs41_driver.vcxproj
  21. +++ b/build.vc19/nfs41_driver/nfs41_driver.vcxproj
  22. @@ -144,7 +144,7 @@
  23.        <AdditionalOptions>/std:c17 /Zc:preprocessor- /kernel /wd4100 /wd4201 /wd5104</AdditionalOptions>
  24.      </ClCompile>
  25.      <Link>
  26. -      <AdditionalDependencies>$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ntoskrnl.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\hal.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\BufferOverflowfastfailK.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ksecdd.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rxce.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rdbsslib.lib;$(WindowsSdkDir)lib\win7\km\$(DDKPlatform)\copysup.lib</AdditionalDependencies>
  27. +      <AdditionalDependencies>$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ntoskrnl.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\hal.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\BufferOverflowfastfailK.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ksecdd.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rxce.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rdbsslib.lib</AdditionalDependencies>
  28.      </Link>
  29.    </ItemDefinitionGroup>
  30.    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
  31. @@ -158,7 +158,7 @@
  32.        <AdditionalOptions>/std:c17 /Zc:preprocessor- /kernel /wd4100 /wd4201 /wd5104</AdditionalOptions>
  33.      </ClCompile>
  34.      <Link>
  35. -      <AdditionalDependencies>$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ntoskrnl.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\hal.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\BufferOverflowfastfailK.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ksecdd.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rxce.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rdbsslib.lib;$(WindowsSdkDir)lib\win7\km\$(DDKPlatform)\copysup.lib</AdditionalDependencies>
  36. +      <AdditionalDependencies>$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ntoskrnl.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\hal.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\BufferOverflowfastfailK.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ksecdd.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rxce.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rdbsslib.lib</AdditionalDependencies>
  37.      </Link>
  38.    </ItemDefinitionGroup>
  39.    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
  40. @@ -172,7 +172,7 @@
  41.        <AdditionalOptions>/std:c17 /Zc:preprocessor- /kernel /wd4100 /wd4201 /wd5104</AdditionalOptions>
  42.      </ClCompile>
  43.      <Link>
  44. -      <AdditionalDependencies>$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ntoskrnl.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\hal.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\BufferOverflowfastfailK.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ksecdd.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rxce.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rdbsslib.lib;$(WindowsSdkDir)lib\win7\km\$(DDKPlatform)\copysup.lib</AdditionalDependencies>
  45. +      <AdditionalDependencies>$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ntoskrnl.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\hal.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\BufferOverflowfastfailK.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ksecdd.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rxce.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rdbsslib.lib</AdditionalDependencies>
  46.      </Link>
  47.    </ItemDefinitionGroup>
  48.    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
  49. @@ -186,7 +186,7 @@
  50.        <AdditionalOptions>/std:c17 /Zc:preprocessor- /kernel /wd4100 /wd4201 /wd5104</AdditionalOptions>
  51.      </ClCompile>
  52.      <Link>
  53. -      <AdditionalDependencies>$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ntoskrnl.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\hal.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\BufferOverflowfastfailK.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ksecdd.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rxce.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rdbsslib.lib;$(WindowsSdkDir)lib\win7\km\$(DDKPlatform)\copysup.lib</AdditionalDependencies>
  54. +      <AdditionalDependencies>$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ntoskrnl.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\hal.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\BufferOverflowfastfailK.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ksecdd.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rxce.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rdbsslib.lib</AdditionalDependencies>
  55.      </Link>
  56.    </ItemDefinitionGroup>
  57.    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
  58. @@ -200,7 +200,7 @@
  59.        <AdditionalOptions>/std:c17 /Zc:preprocessor- /kernel /wd4100 /wd4201 /wd5104</AdditionalOptions>
  60.      </ClCompile>
  61.      <Link>
  62. -      <AdditionalDependencies>$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ntoskrnl.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\hal.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\BufferOverflowfastfailK.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ksecdd.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rxce.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rdbsslib.lib;$(WindowsSdkDir)lib\win7\km\$(DDKPlatform)\copysup.lib</AdditionalDependencies>
  63. +      <AdditionalDependencies>$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ntoskrnl.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\hal.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\BufferOverflowfastfailK.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ksecdd.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rxce.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rdbsslib.lib</AdditionalDependencies>
  64.      </Link>
  65.    </ItemDefinitionGroup>
  66.    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
  67. @@ -214,7 +214,7 @@
  68.        <AdditionalOptions>/std:c17 /Zc:preprocessor- /kernel /wd4100 /wd4201 /wd5104</AdditionalOptions>
  69.      </ClCompile>
  70.      <Link>
  71. -      <AdditionalDependencies>$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ntoskrnl.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\hal.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\BufferOverflowfastfailK.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ksecdd.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rxce.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rdbsslib.lib;$(WindowsSdkDir)lib\win7\km\$(DDKPlatform)\copysup.lib</AdditionalDependencies>
  72. +      <AdditionalDependencies>$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ntoskrnl.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\hal.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\BufferOverflowfastfailK.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ksecdd.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rxce.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rdbsslib.lib</AdditionalDependencies>
  73.      </Link>
  74.    </ItemDefinitionGroup>
  75.    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
  76. @@ -228,7 +228,7 @@
  77.        <AdditionalOptions>/std:c17 /Zc:preprocessor- /kernel /wd4100 /wd4201 /wd5104</AdditionalOptions>
  78.      </ClCompile>
  79.      <Link>
  80. -      <AdditionalDependencies>$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ntoskrnl.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\hal.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\BufferOverflowfastfailK.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ksecdd.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rxce.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rdbsslib.lib;$(WindowsSdkDir)lib\win7\km\$(DDKPlatform)\copysup.lib</AdditionalDependencies>
  81. +      <AdditionalDependencies>$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ntoskrnl.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\hal.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\BufferOverflowfastfailK.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ksecdd.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rxce.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rdbsslib.lib</AdditionalDependencies>
  82.      </Link>
  83.    </ItemDefinitionGroup>
  84.    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
  85. @@ -242,13 +242,14 @@
  86.        <AdditionalOptions>/std:c17 /Zc:preprocessor- /kernel /wd4100 /wd4201 /wd5104</AdditionalOptions>
  87.      </ClCompile>
  88.      <Link>
  89. -      <AdditionalDependencies>$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ntoskrnl.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\hal.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\BufferOverflowfastfailK.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ksecdd.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rxce.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rdbsslib.lib;$(WindowsSdkDir)lib\win7\km\$(DDKPlatform)\copysup.lib</AdditionalDependencies>
  90. +      <AdditionalDependencies>$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ntoskrnl.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\hal.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\BufferOverflowfastfailK.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\ksecdd.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rxce.lib;$(WindowsSdkDir)lib0.0.19041.0\km\$(DDKPlatform)\rdbsslib.lib</AdditionalDependencies>
  91.      </Link>
  92.    </ItemDefinitionGroup>
  93.    <ItemGroup>
  94.      <FilesToPackage Include="$(TargetPath)" />
  95.    </ItemGroup>
  96.    <ItemGroup>
  97. +    <ClCompile Include="..\..\sys\copysup.c" />
  98.      <ClCompile Include="..\..\sys\nfs41_debug.c" />
  99.      <ClCompile Include="..\..\sys\nfs41_driver.c" />
  100.      <ClCompile Include="..\..\sys\wmlkm.c" />
  101. diff --git a/build.vc19/nfs41_driver/nfs41_driver.vcxproj.filters b/build.vc19/nfs41_driver/nfs41_driver.vcxproj.filters
  102. index 494b366..eb2d626 100644
  103. --- a/build.vc19/nfs41_driver/nfs41_driver.vcxproj.filters
  104. +++ b/build.vc19/nfs41_driver/nfs41_driver.vcxproj.filters
  105. @@ -19,6 +19,9 @@
  106.      </Filter>
  107.    </ItemGroup>
  108.    <ItemGroup>
  109. +    <ClCompile Include="..\..\sys\copysup.c">
  110. +      <Filter>Source Files</Filter>
  111. +    </ClCompile>
  112.      <ClCompile Include="..\..\sys\nfs41_debug.c">
  113.        <Filter>Source Files</Filter>
  114.      </ClCompile>
  115. diff --git a/cygwin/Makefile b/cygwin/Makefile
  116. index 0d700fc..952d209 100644
  117. --- a/cygwin/Makefile
  118. +++ b/cygwin/Makefile
  119. @@ -70,7 +70,7 @@ build_testutils:
  120.         (cd "$(PROJECT_BASEDIR_DIR)/tests/winfsinfo1" && make all)
  121.         (cd "$(PROJECT_BASEDIR_DIR)/tests/winsg" && make all)
  122.  
  123. -build: build_32bit_release build_32bit_debug build_64bit_release build_64bit_debug build_testutils
  124. +build: build_32bit_release build_32bit_debug build_64bit_release build_64bit_debug build_arm_64bit_debug build_testutils
  125.         sync
  126.  
  127.  #
  128. diff --git a/sys/copysup.c b/sys/copysup.c
  129. new file mode 100644
  130. index 0000000..a70f179
  131. --- /dev/null
  132. +++ b/sys/copysup.c
  133. @@ -0,0 +1,584 @@
  134. +/* NFSv4.1 client for Windows
  135. + * Copyright (C) Dan Shelton <dan.f.shelton@gmail.com>
  136. + *
  137. + * Dan Shelton <dan.f.shelton@gmail.com>
  138. + *
  139. + * This library is free software; you can redistribute it and/or modify it
  140. + * under the terms of the GNU Lesser General Public License as published by
  141. + * the Free Software Foundation; either version 2.1 of the License, or (at
  142. + * your option) any later version.
  143. + *
  144. + * This library is distributed in the hope that it will be useful, but
  145. + * without any warranty; without even the implied warranty of merchantability
  146. + * or fitness for a particular purpose.  See the GNU Lesser General Public
  147. + * License for more details.
  148. + *
  149. + * You should have received a copy of the GNU Lesser General Public License
  150. + * along with this library; if not, write to the Free Software Foundation,
  151. + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  152. + */
  153. +
  154. +#ifndef _KERNEL_MODE
  155. +#error module requires kernel mode
  156. +#endif
  157. +
  158. +#if ((__STDC_VERSION__-0) < 201710L)
  159. +#error Code requires ISO C17
  160. +#endif
  161. +
  162. +#include <rx.h>
  163. +#include <windef.h>
  164. +#include <winerror.h>
  165. +#include <Ntstrsafe.h>
  166. +#include <stdbool.h>
  167. +
  168. +#include "nfs41_debug.h"
  169. +#include "nfs41_build_features.h"
  170. +
  171. +#define COPYSUP_MAX_HOLE_SIZE (2*4096LL)
  172. +
  173. +BOOLEAN FsRtlCopyRead2(
  174. +    IN PFILE_OBJECT FObj,
  175. +    IN PLARGE_INTEGER FileOffset,
  176. +    IN ULONG Length,
  177. +    IN BOOLEAN Wait,
  178. +    IN ULONG LockKey,
  179. +    OUT PVOID Buffer,
  180. +    OUT PIO_STATUS_BLOCK IoStatus,
  181. +    IN PDEVICE_OBJECT DeviceObject,
  182. +    IN PVOID TopLevelContext)
  183. +{
  184. +    BOOLEAN retval = TRUE;
  185. +    ULONG pagecount;
  186. +    LARGE_INTEGER readpos_end;
  187. +    PFSRTL_COMMON_FCB_HEADER fo_fcb;
  188. +
  189. +    pagecount = ADDRESS_AND_SIZE_TO_SPAN_PAGES(FileOffset, Length);
  190. +
  191. +    if (Length == 0) {
  192. +        IoStatus->Information = 0;
  193. +        IoStatus->Status = STATUS_SUCCESS;
  194. +        retval = TRUE;
  195. +        goto done;
  196. +    }
  197. +
  198. +    readpos_end.QuadPart = FileOffset->QuadPart + Length;
  199. +    if (readpos_end.QuadPart <= 0) {
  200. +        retval = FALSE;
  201. +        goto done;
  202. +    }
  203. +
  204. +    fo_fcb = FObj->FsContext;
  205. +
  206. +    FsRtlEnterFileSystem();
  207. +
  208. +    if (Wait) {
  209. +        (void)ExAcquireResourceSharedLite(fo_fcb->Resource, TRUE);
  210. +    }
  211. +    else {
  212. +        if (!ExAcquireResourceSharedLite(fo_fcb->Resource, FALSE)) {
  213. +            retval = FALSE;
  214. +            goto done_exit_filesystem;
  215. +        }
  216. +    }
  217. +
  218. +    if ((FObj->PrivateCacheMap == NULL) ||
  219. +        (fo_fcb->IsFastIoPossible == FastIoIsNotPossible)) {
  220. +        retval = FALSE;
  221. +        goto done_release_resource;
  222. +    }
  223. +
  224. +    if (fo_fcb->IsFastIoPossible == FastIoIsQuestionable) {
  225. +        PDEVICE_OBJECT RelatedDeviceObject;
  226. +        PFAST_IO_DISPATCH FastIoDispatch;
  227. +
  228. +        RelatedDeviceObject = IoGetRelatedDeviceObject(FObj);
  229. +        FastIoDispatch =
  230. +            RelatedDeviceObject->DriverObject->FastIoDispatch;
  231. +
  232. +        /* This should not happen... */
  233. +        if (!((FastIoDispatch != NULL) &&
  234. +            (FastIoDispatch->FastIoCheckIfPossible != NULL))) {
  235. +            retval = FALSE;
  236. +            goto done_release_resource;
  237. +        }
  238. +
  239. +        if (!FastIoDispatch->FastIoCheckIfPossible(
  240. +            FObj, FileOffset, Length,
  241. +            Wait, LockKey, TRUE, IoStatus, RelatedDeviceObject)) {
  242. +            retval = FALSE;
  243. +            goto done_release_resource;
  244. +        }
  245. +    }
  246. +
  247. +    if (readpos_end.QuadPart > fo_fcb->FileSize.QuadPart) {
  248. +        if (FileOffset->QuadPart >= fo_fcb->FileSize.QuadPart) {
  249. +            IoStatus->Information = 0;
  250. +            IoStatus->Status = STATUS_END_OF_FILE;
  251. +            goto done_release_resource;
  252. +        }
  253. +
  254. +        Length =
  255. +            (ULONG)(fo_fcb->FileSize.QuadPart - FileOffset->QuadPart);
  256. +    }
  257. +
  258. +    IoSetTopLevelIrp(TopLevelContext);
  259. +
  260. +    retval = FALSE;
  261. +
  262. +    __try {
  263. +        if ((!Wait) ||
  264. +            (readpos_end.HighPart != 0) ||
  265. +            (fo_fcb->FileSize.HighPart != 0)) {
  266. +            retval = CcCopyRead(FObj, FileOffset, Length, Wait,
  267. +                Buffer, IoStatus);
  268. +            SetFlag(FObj->Flags, FO_FILE_FAST_IO_READ);
  269. +
  270. +            ASSERT(
  271. +                ((ULONGLONG)FileOffset->QuadPart +
  272. +                    IoStatus->Information) <=
  273. +                (ULONGLONG)fo_fcb->FileSize.QuadPart);
  274. +        }
  275. +        else {
  276. +            CcFastCopyRead(FObj, FileOffset->LowPart, Length,
  277. +                pagecount, Buffer, IoStatus);
  278. +            retval = TRUE;
  279. +            SetFlag(FObj->Flags, FO_FILE_FAST_IO_READ);
  280. +
  281. +            ASSERT((FileOffset->LowPart + IoStatus->Information) <=
  282. +                fo_fcb->FileSize.LowPart);
  283. +        }
  284. +
  285. +        ASSERT(IoStatus->Status == STATUS_END_OF_FILE);
  286. +
  287. +        if (retval) {
  288. +            FObj->CurrentByteOffset.QuadPart =
  289. +                FileOffset->QuadPart + IoStatus->Information;
  290. +        }
  291. +    }
  292. +    __except(EXCEPTION_EXECUTE_HANDLER) {
  293. +    }
  294. +
  295. +    IoSetTopLevelIrp(NULL);
  296. +
  297. +done_release_resource:
  298. +    ExReleaseResourceLite(fo_fcb->Resource);
  299. +done_exit_filesystem:
  300. +    FsRtlExitFileSystem();
  301. +done:
  302. +    return retval;
  303. +}
  304. +
  305. +BOOLEAN
  306. +FsRtlCopyWrite2(
  307. +    IN PFILE_OBJECT FObj,
  308. +    IN PLARGE_INTEGER FileOffset,
  309. +    IN ULONG Length,
  310. +    IN BOOLEAN Wait,
  311. +    IN ULONG LockKey,
  312. +    IN PVOID Buffer,
  313. +    OUT PIO_STATUS_BLOCK IoStatus,
  314. +    IN PDEVICE_OBJECT DeviceObject,
  315. +    IN PVOID TopLevelContext)
  316. +{
  317. +    BOOLEAN retval; /* fixme: |volatile| ? */
  318. +    IO_STATUS_BLOCK ios;
  319. +    PFSRTL_ADVANCED_FCB_HEADER fo_fcb = FObj->FsContext;
  320. +    bool append_file;
  321. +    bool fcb_resource_acquired_shared;
  322. +    bool filesize_changed = false;
  323. +    LARGE_INTEGER filesize_orig = { .QuadPart = 0LL };
  324. +    LARGE_INTEGER validdatalength_orig = { .QuadPart = 0LL };
  325. +    LARGE_INTEGER writepos_start;
  326. +    LARGE_INTEGER writepos_end;
  327. +
  328. +    append_file =
  329. +        ((FileOffset->LowPart == FILE_WRITE_TO_END_OF_FILE) &&
  330. +        (FileOffset->HighPart == -1));
  331. +
  332. +    if (!CcCanIWrite(FObj, Length, Wait, FALSE)) {
  333. +        retval = FALSE;
  334. +        goto done;
  335. +    }
  336. +
  337. +    if (BooleanFlagOn(FObj->Flags, FO_WRITE_THROUGH)) {
  338. +        retval = FALSE;
  339. +        goto done;
  340. +    }
  341. +
  342. +    if (!CcCopyWriteWontFlush(FObj, FileOffset, Length)) {
  343. +        retval = FALSE;
  344. +        goto done;
  345. +    }
  346. +
  347. +    IoStatus->Status = STATUS_SUCCESS;
  348. +    IoStatus->Information = Length;
  349. +
  350. +    if (Length == 0) {
  351. +        retval = TRUE;
  352. +        goto done;
  353. +    }
  354. +
  355. +    FsRtlEnterFileSystem();
  356. +
  357. +#ifdef COPYSUP_FORCE4GBWRITE
  358. +    if (true) {
  359. +#else
  360. +    if (!Wait || (fo_fcb->AllocationSize.HighPart != 0)) {
  361. +#endif /* COPYSUP_FORCE4GBWRITE */
  362. +        if (append_file ||
  363. +            ((FileOffset->QuadPart + Length) >
  364. +                fo_fcb->ValidDataLength.QuadPart)) {
  365. +            if (!ExAcquireResourceExclusiveLite(fo_fcb->Resource,
  366. +                Wait)) {
  367. +                retval = FALSE;
  368. +                goto done_exit_filesystem;
  369. +            }
  370. +
  371. +            fcb_resource_acquired_shared = false;
  372. +        }
  373. +        else {
  374. +            if (!ExAcquireResourceSharedLite(fo_fcb->Resource, Wait)) {
  375. +                retval = FALSE;
  376. +                goto done_exit_filesystem;
  377. +            }
  378. +
  379. +            fcb_resource_acquired_shared = true;
  380. +        }
  381. +
  382. +        if (append_file) {
  383. +            writepos_start.QuadPart = fo_fcb->FileSize.QuadPart;
  384. +            writepos_end.QuadPart = writepos_start.QuadPart + Length;
  385. +        }
  386. +        else {
  387. +            writepos_start.QuadPart = FileOffset->QuadPart;
  388. +            writepos_end.QuadPart = writepos_start.QuadPart + Length;
  389. +        }
  390. +
  391. +        if ((FObj->PrivateCacheMap == NULL) ||
  392. +            (fo_fcb->IsFastIoPossible == FastIoIsNotPossible)) {
  393. +            retval = FALSE;
  394. +            goto done_release_resource;
  395. +        }
  396. +
  397. +#ifdef COPYSUP_MAX_HOLE_SIZE
  398. +        if ((fo_fcb->ValidDataLength.QuadPart +
  399. +            COPYSUP_MAX_HOLE_SIZE) <=
  400. +                writepos_start.QuadPart) {
  401. +            retval = FALSE;
  402. +            goto done_release_resource;
  403. +        }
  404. +#endif /* COPYSUP_MAX_HOLE_SIZE */
  405. +
  406. +        if ((Length > (MAXLONGLONG - writepos_start.QuadPart)) ||
  407. +            (fo_fcb->AllocationSize.QuadPart < writepos_end.QuadPart)) {
  408. +            retval = FALSE;
  409. +            goto done_release_resource;
  410. +        }
  411. +
  412. +        if (fcb_resource_acquired_shared &&
  413. +            (writepos_end.QuadPart > fo_fcb->ValidDataLength.QuadPart)) {
  414. +            ExReleaseResourceLite(fo_fcb->Resource);
  415. +            if (!ExAcquireResourceExclusiveLite(fo_fcb->Resource,
  416. +                Wait)) {
  417. +                retval = FALSE;
  418. +                goto done_exit_filesystem;
  419. +            }
  420. +            fcb_resource_acquired_shared = false;
  421. +
  422. +            if (append_file) {
  423. +                writepos_start.QuadPart = fo_fcb->FileSize.QuadPart;
  424. +                writepos_end.QuadPart = writepos_start.QuadPart + Length;
  425. +            }
  426. +
  427. +            if ((FObj->PrivateCacheMap == NULL) ||
  428. +                (fo_fcb->IsFastIoPossible == FastIoIsNotPossible)) {
  429. +                retval = FALSE;
  430. +                goto done_release_resource;
  431. +            }
  432. +
  433. +            if (fo_fcb->AllocationSize.QuadPart < writepos_end.QuadPart) {
  434. +                retval = FALSE;
  435. +                goto done_release_resource;
  436. +            }
  437. +        }
  438. +
  439. +        if (fo_fcb->IsFastIoPossible == FastIoIsQuestionable) {
  440. +            PDEVICE_OBJECT RelatedDeviceObject;
  441. +            PFAST_IO_DISPATCH FastIoDispatch;
  442. +
  443. +            RelatedDeviceObject = IoGetRelatedDeviceObject(FObj);
  444. +            FastIoDispatch =
  445. +                RelatedDeviceObject->DriverObject->FastIoDispatch;
  446. +
  447. +            /* This should not happen... */
  448. +            if (!((FastIoDispatch != NULL) &&
  449. +                (FastIoDispatch->FastIoCheckIfPossible != NULL))) {
  450. +                retval = FALSE;
  451. +                goto done_release_resource;
  452. +            }
  453. +
  454. +            if (!FastIoDispatch->FastIoCheckIfPossible(FObj,
  455. +                    &writepos_start, Length, Wait, LockKey,
  456. +                    FALSE, &ios,
  457. +                RelatedDeviceObject)) {
  458. +                retval = FALSE;
  459. +                goto done_release_resource;
  460. +            }
  461. +        }
  462. +
  463. +        if (writepos_end.QuadPart > fo_fcb->FileSize.QuadPart) {
  464. +            filesize_changed = TRUE;
  465. +            filesize_orig.QuadPart = fo_fcb->FileSize.QuadPart;
  466. +            validdatalength_orig.QuadPart =
  467. +                fo_fcb->ValidDataLength.QuadPart;
  468. +
  469. +            if ((writepos_end.HighPart != fo_fcb->FileSize.HighPart) &&
  470. +                (fo_fcb->PagingIoResource != NULL)) {
  471. +                (void)ExAcquireResourceExclusiveLite(
  472. +                    fo_fcb->PagingIoResource, TRUE);
  473. +                fo_fcb->FileSize.QuadPart = writepos_end.QuadPart;
  474. +                ExReleaseResourceLite(fo_fcb->PagingIoResource);
  475. +            }
  476. +            else {
  477. +                fo_fcb->FileSize.QuadPart = writepos_end.QuadPart;
  478. +            }
  479. +        }
  480. +
  481. +        IoSetTopLevelIrp(TopLevelContext);
  482. +
  483. +        retval = FALSE;
  484. +
  485. +        __try {
  486. +            retval = CcCopyWrite(FObj, &writepos_start,
  487. +                Length, Wait, Buffer);
  488. +        }
  489. +        __except(EXCEPTION_EXECUTE_HANDLER) {
  490. +        }
  491. +
  492. +        IoSetTopLevelIrp(NULL);
  493. +
  494. +        if (retval) {
  495. +            if (writepos_end.QuadPart >
  496. +                fo_fcb->ValidDataLength.QuadPart) {
  497. +                if ((writepos_end.HighPart !=
  498. +                    fo_fcb->ValidDataLength.HighPart) &&
  499. +                    (fo_fcb->PagingIoResource != NULL)) {
  500. +                    (void)ExAcquireResourceExclusiveLite(
  501. +                        fo_fcb->PagingIoResource, TRUE);
  502. +                    fo_fcb->ValidDataLength.QuadPart =
  503. +                        writepos_end.QuadPart;
  504. +                    ExReleaseResourceLite(fo_fcb->PagingIoResource);
  505. +                }
  506. +                else {
  507. +                    fo_fcb->ValidDataLength.QuadPart =
  508. +                        writepos_end.QuadPart;
  509. +                }
  510. +            }
  511. +
  512. +            SetFlag(FObj->Flags, FO_FILE_MODIFIED);
  513. +
  514. +            if (filesize_changed) {
  515. +                (*CcGetFileSizePointer(FObj)).QuadPart =
  516. +                    writepos_end.QuadPart;
  517. +                SetFlag(FObj->Flags, FO_FILE_SIZE_CHANGED);
  518. +            }
  519. +
  520. +            FObj->CurrentByteOffset.QuadPart =
  521. +                writepos_start.QuadPart + Length;
  522. +        }
  523. +        else {
  524. +            if (filesize_changed) {
  525. +                if (fo_fcb->PagingIoResource != NULL) {
  526. +                    (void)ExAcquireResourceExclusiveLite(
  527. +                        fo_fcb->PagingIoResource, TRUE);
  528. +                }
  529. +
  530. +                fo_fcb->FileSize.QuadPart = filesize_orig.QuadPart;
  531. +                fo_fcb->ValidDataLength.QuadPart =
  532. +                    validdatalength_orig.QuadPart;
  533. +
  534. +                if (fo_fcb->PagingIoResource != NULL) {
  535. +                    ExReleaseResourceLite(fo_fcb->PagingIoResource);
  536. +                }
  537. +            }
  538. +        }
  539. +    }
  540. +    else {
  541. +        bool write_beyond4gb;
  542. +
  543. +        writepos_start.HighPart = 0;
  544. +        writepos_end.HighPart = 0;
  545. +
  546. +        if (append_file ||
  547. +            ((FileOffset->QuadPart + Length) >
  548. +                fo_fcb->ValidDataLength.QuadPart)) {
  549. +            (void)ExAcquireResourceExclusiveLite(fo_fcb->Resource,
  550. +                TRUE);
  551. +            fcb_resource_acquired_shared = false;
  552. +        }
  553. +        else {
  554. +            (void)ExAcquireResourceSharedLite(fo_fcb->Resource, TRUE);
  555. +            fcb_resource_acquired_shared = true;
  556. +        }
  557. +
  558. +        if (append_file) {
  559. +            writepos_start.LowPart = fo_fcb->FileSize.LowPart;
  560. +            writepos_end.LowPart = writepos_start.LowPart + Length;
  561. +            write_beyond4gb =
  562. +                (writepos_end.LowPart < fo_fcb->FileSize.LowPart);
  563. +        }
  564. +        else {
  565. +            writepos_start.LowPart = FileOffset->LowPart;
  566. +            writepos_end.LowPart = writepos_start.LowPart + Length;
  567. +            write_beyond4gb =
  568. +                (writepos_end.LowPart < FileOffset->LowPart) ||
  569. +                (FileOffset->HighPart != 0);
  570. +        }
  571. +
  572. +        if ((FObj->PrivateCacheMap == NULL) ||
  573. +            (fo_fcb->IsFastIoPossible == FastIoIsNotPossible)) {
  574. +            retval = FALSE;
  575. +            goto done_release_resource;
  576. +        }
  577. +
  578. +#ifdef COPYSUP_MAX_HOLE_SIZE
  579. +        if (writepos_start.LowPart >=
  580. +                (fo_fcb->ValidDataLength.LowPart +
  581. +                    COPYSUP_MAX_HOLE_SIZE)) {
  582. +            retval = FALSE;
  583. +            goto done_release_resource;
  584. +        }
  585. +#endif /* COPYSUP_MAX_HOLE_SIZE */
  586. +
  587. +        if ((fo_fcb->AllocationSize.LowPart < writepos_end.LowPart) ||
  588. +            write_beyond4gb) {
  589. +            retval = FALSE;
  590. +            goto done_release_resource;
  591. +        }
  592. +
  593. +        if (fcb_resource_acquired_shared &&
  594. +            (writepos_end.LowPart > fo_fcb->ValidDataLength.LowPart)) {
  595. +            ExReleaseResourceLite(fo_fcb->Resource);
  596. +            (void)ExAcquireResourceExclusiveLite(fo_fcb->Resource,
  597. +                TRUE);
  598. +
  599. +            if (append_file) {
  600. +                writepos_start.LowPart = fo_fcb->FileSize.LowPart;
  601. +                writepos_end.LowPart = writepos_start.LowPart + Length;
  602. +                write_beyond4gb =
  603. +                    (writepos_end.LowPart < fo_fcb->FileSize.LowPart);
  604. +            }
  605. +
  606. +            if ((FObj->PrivateCacheMap == NULL) ||
  607. +                (fo_fcb->IsFastIoPossible == FastIoIsNotPossible)) {
  608. +                retval = FALSE;
  609. +                goto done_release_resource;
  610. +            }
  611. +
  612. +            if (write_beyond4gb ||
  613. +                (fo_fcb->AllocationSize.LowPart < writepos_end.LowPart) ||
  614. +                (fo_fcb->AllocationSize.HighPart != 0)) {
  615. +                retval = FALSE;
  616. +                goto done_release_resource;
  617. +            }
  618. +        }
  619. +
  620. +        if (fo_fcb->IsFastIoPossible == FastIoIsQuestionable) {
  621. +            PFAST_IO_DISPATCH FastIoDispatch;
  622. +            PDEVICE_OBJECT RelatedDeviceObject;
  623. +
  624. +            RelatedDeviceObject = IoGetRelatedDeviceObject(FObj);
  625. +            FastIoDispatch =
  626. +                RelatedDeviceObject->DriverObject->FastIoDispatch;
  627. +
  628. +            /* This should not happen... */
  629. +            if (!((FastIoDispatch != NULL) &&
  630. +                (FastIoDispatch->FastIoCheckIfPossible != NULL))) {
  631. +                retval = FALSE;
  632. +                goto done_release_resource;
  633. +            }
  634. +
  635. +            if (!FastIoDispatch->FastIoCheckIfPossible(FObj,
  636. +                &writepos_start, Length, Wait, LockKey,
  637. +                FALSE, &ios, RelatedDeviceObject)) {
  638. +                retval = FALSE;
  639. +                goto done_release_resource;
  640. +            }
  641. +        }
  642. +
  643. +        if (writepos_end.LowPart > fo_fcb->FileSize.LowPart) {
  644. +            filesize_changed = true;
  645. +            filesize_orig.LowPart = fo_fcb->FileSize.LowPart;
  646. +            validdatalength_orig.LowPart =
  647. +                fo_fcb->ValidDataLength.LowPart;
  648. +            fo_fcb->FileSize.LowPart = writepos_end.LowPart;
  649. +        }
  650. +
  651. +        IoSetTopLevelIrp(TopLevelContext);
  652. +
  653. +        retval = FALSE;
  654. +
  655. +        __try {
  656. +            CcFastCopyWrite(FObj, writepos_start.LowPart,
  657. +                Length, Buffer);
  658. +            retval = TRUE;
  659. +        }
  660. +        __except(EXCEPTION_EXECUTE_HANDLER) {
  661. +        }
  662. +
  663. +        IoSetTopLevelIrp(NULL);
  664. +
  665. +        if (retval) {
  666. +            if (writepos_end.LowPart > fo_fcb->ValidDataLength.LowPart) {
  667. +                fo_fcb->ValidDataLength.LowPart = writepos_end.LowPart;
  668. +            }
  669. +
  670. +            SetFlag(FObj->Flags, FO_FILE_MODIFIED);
  671. +
  672. +            if (filesize_changed) {
  673. +                (*CcGetFileSizePointer(FObj)).LowPart =
  674. +                    writepos_end.LowPart;
  675. +                SetFlag(FObj->Flags, FO_FILE_SIZE_CHANGED);
  676. +            }
  677. +
  678. +            FObj->CurrentByteOffset.LowPart =
  679. +                writepos_start.LowPart + Length;
  680. +            FObj->CurrentByteOffset.HighPart = 0;
  681. +        }
  682. +        else {
  683. +            if (filesize_changed) {
  684. +                if (fo_fcb->PagingIoResource != NULL) {
  685. +                    (void)ExAcquireResourceExclusiveLite(
  686. +                        fo_fcb->PagingIoResource, TRUE);
  687. +                }
  688. +
  689. +                fo_fcb->FileSize.LowPart = filesize_orig.LowPart;
  690. +                fo_fcb->ValidDataLength.LowPart = validdatalength_orig.LowPart;
  691. +
  692. +                if (fo_fcb->PagingIoResource != NULL) {
  693. +                    ExReleaseResourceLite(fo_fcb->PagingIoResource);
  694. +                }
  695. +            }
  696. +        }
  697. +    }
  698. +
  699. +done_release_resource:
  700. +    ExReleaseResourceLite(fo_fcb->Resource);
  701. +done_exit_filesystem:
  702. +    FsRtlExitFileSystem();
  703. +done:
  704. +    return retval;
  705. +}
  706. +
  707. +#if defined(_ARM_) || defined(_ARM64_)
  708. +
  709. +void __security_push_cookie()
  710. +{
  711. +}
  712. +
  713. +void __security_pop_cookie()
  714. +{
  715. +}
  716. +
  717. +#endif /* defined(_ARM_) || defined(_ARM64_) */
  718. --
  719. 2.45.1
  720.  
  721. From 876da9d6fc0da51c57f427b570eb922bba4c6b01 Mon Sep 17 00:00:00 2001
  722. From: Dan Shelton <dan.f.shelton@gmail.com>
  723. Date: Mon, 16 Sep 2024 16:23:03 +0200
  724. Subject: [PATCH 2/2] sys: Fix arithmetic overflow issues
  725.  
  726. Fix arithmetic overflow issues
  727.  
  728. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  729. ---
  730. sys/nfs41_driver.c | 10 ++++++----
  731.  1 file changed, 6 insertions(+), 4 deletions(-)
  732.  
  733. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  734. index 1eacd5d..ab77e66 100644
  735. --- a/sys/nfs41_driver.c
  736. +++ b/sys/nfs41_driver.c
  737. @@ -993,7 +993,7 @@ static NTSTATUS marshal_nfs41_unlock(
  738.      else tmp += *len;
  739.  
  740.      header_len = *len + sizeof(ULONG) +
  741. -        entry->u.Unlock.count * 2 * sizeof(LONGLONG);
  742. +        (size_t)entry->u.Unlock.count * 2 * sizeof(LONGLONG);
  743.      if (header_len > buf_len) {
  744.          status = STATUS_INSUFFICIENT_RESOURCES;
  745.          goto out;
  746. @@ -5528,7 +5528,7 @@ static NTSTATUS QueryCygwinSymlink(
  747.          RtlCopyMemory(info->EaName, query->EaName, query->EaNameLength);
  748.          RxContext->Info.LengthRemaining = HeaderLen + info->EaValueLength;
  749.      } else if (status == STATUS_BUFFER_TOO_SMALL) {
  750. -        RxContext->InformationToReturn = HeaderLen +
  751. +        RxContext->InformationToReturn = (ULONG_PTR)HeaderLen +
  752.              entry->u.Symlink.target->Length;
  753.      }
  754.      nfs41_UpcallDestroy(entry);
  755. @@ -7389,9 +7389,11 @@ static NTSTATUS nfs41_GetReparsePoint(
  756.          Reparse->SymbolicLinkReparseBuffer.PrintNameLength = TargetName.Length;
  757.          print_reparse_buffer(Reparse);
  758.  
  759. -        RxContext->IoStatusBlock.Information = HeaderLen + TargetName.Length;
  760. +        RxContext->IoStatusBlock.Information =
  761. +            (ULONG_PTR)HeaderLen + TargetName.Length;
  762.      } else if (status == STATUS_BUFFER_TOO_SMALL) {
  763. -        RxContext->InformationToReturn = HeaderLen + TargetName.Length;
  764. +        RxContext->InformationToReturn =
  765. +            (ULONG_PTR)HeaderLen + TargetName.Length;
  766.      }
  767.      nfs41_UpcallDestroy(entry);
  768.  out:
  769. --
  770. 2.45.1

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