-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set of offset-based APIs for thread-safe file IO #53669
Merged
Merged
Changes from 40 commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
d37d1ee
move logic related to opening and initializing handle from FileStream…
adamsitnik 539393d
move the arguments validation logic common for FileStream ctor and Fi…
adamsitnik b60e876
introduce File.OpenHandle
adamsitnik c61d639
fix the new tests
adamsitnik ad252de
FileStream created from a handle should allow for bufferSize == 0
adamsitnik 1540dba
File.OpenHandle should always use full path
adamsitnik d8a3113
fix a bug in NtCreateFile mapping logic
adamsitnik 02cd564
always use NtCreateFile for SafeFileHandle.Open
adamsitnik 1430dd6
move the ThreadPoolBinding initialization logic to one place
adamsitnik ebaa92a
IsAsync: use syscall when not provided and validate it early
adamsitnik fbbcd4d
read all FileOptions, not just FileOptions.Asynchronous
adamsitnik 7f94f85
move IsPipe CanSeek to SafeFileHandle as well (the new APIs like Rand…
adamsitnik 33ecb8d
disable the Append test as it's currently not supported by design
adamsitnik f1af8f6
expose SafeFileHandle.IsAsync and write a test for it
adamsitnik a46da91
fix compilation errors on Linux
adamsitnik 9ef23eb
don't try to test DeleteOnClose for FileStreams created from handle a…
adamsitnik 485eb93
take advantage of knowing the file type and avoid one syscall for Can…
adamsitnik c8818aa
revert some ordering changes to make the code easier to review
adamsitnik dc13de0
Apply suggestions from code review
adamsitnik 6c58252
add missing ;
adamsitnik fb24f5c
simplify Windows implementation:
adamsitnik 8baf0bd
unify CanSeek and IsPipe for the .NET 5 Windows strategy as well
adamsitnik 50aba1f
move the !MS_IO_REDIST methods from `File.cs` to `File.netcoreapp.cs`…
adamsitnik 143d31c
RandomAccess: GetLength, Read and Write single buffer
adamsitnik 1d41d65
fix Unix build
adamsitnik 2d8ac90
refactor the tests
adamsitnik bbbd267
ReadAsync and WriteAsync
adamsitnik 46d9b6f
move AsyncWindowsFileStreamStrategy.ValueTaskSource to SafeFileHandle
adamsitnik a946c5d
ReadScatter and WriteGather
adamsitnik 4f807ef
some polishing
adamsitnik 638e67a
ReadScatterAsync and WriteGatherAsync
adamsitnik fe8fbd1
use ReadFileScatter and WriteFileGather when possible
adamsitnik 381776b
complete Unix implementation
adamsitnik 1febba1
add tests for handling already cancelled tokens
adamsitnik 8db3f7a
add tests for unauthorized access
adamsitnik f33d4ca
some polishing before sending PR
adamsitnik f8c8423
always treat EOF as success with 0 bytes read (read at end of file)
adamsitnik 2126f15
simplify the NoBuffering tests logic
adamsitnik e613e72
handle lack of preadv pwritev on OSX
adamsitnik 73f0751
fix the Linux build
adamsitnik 940609c
Apply suggestions from code review
adamsitnik 891c2b3
code review fixes and suggestions
adamsitnik e462d49
Unix fixes
adamsitnik 253faa1
skip the test that uses System.IO.Pipes for Browser (it's not supported)
adamsitnik fd86735
remove the invalid assumption that every file file opened from path m…
adamsitnik 6241b08
support ReadFileScatter and WriteFileGather on 32-bit systems as we d…
adamsitnik 648ab9b
move the unpinning to finally block
adamsitnik e075441
update the comment
adamsitnik b1d3006
move the call to Dispose to the catch block
adamsitnik 98eaf24
InitThreadPoolBindingIfNeeded can dispose the handle only if we own it
adamsitnik 76a4326
when 0 is allowed, the exception message should ask for non-negative …
adamsitnik dcd9e12
fix the casting compilation error
adamsitnik 2b6a555
don't make ownsHandle a protected field as it would become a part of …
adamsitnik 4a6bb62
move IOVector from pal_networking.h to pal_io.h and use it in pal_io.…
adamsitnik 5ec9e1f
don't use nullable field to store canSeek information. Store the file…
adamsitnik 4d002b2
update outdated debug assert
adamsitnik d5c9229
Revert "don't use nullable field to store canSeek information. Store …
adamsitnik 994b112
CanSeek should be thread-safe
adamsitnik 9405abe
add more debug asserts to try to see why two CI legs have failed with…
adamsitnik 752ff9d
fix invalid link (it was pointing to a closed duplicate)
adamsitnik e609c06
async File IO is not supported on Windows for Mono
adamsitnik 5ae1dfb
async file IO is not supported on browser
adamsitnik d4e5b09
fix WASM build
adamsitnik abc4b14
don't use preadv and pwritev on WASM as WASM implementation has bugs
adamsitnik 043a926
Merge remote-tracking branch 'upstream/main' into randomAcess
adamsitnik fc76167
fix a typo
adamsitnik 93db089
Merge remote-tracking branch 'upstream/main' into randomAcess
adamsitnik 1014688
add missing CreateFileW default flags
adamsitnik fde8c34
Merge remote-tracking branch 'upstream/main' into randomAcess
adamsitnik 05327b1
reduce code duplication
adamsitnik 05e65eb
Apply suggestions from code review
adamsitnik c87354c
address code review feedback
adamsitnik f80bbb7
Apply suggestions from code review
adamsitnik 07051fa
address code review feedback
adamsitnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/libraries/Common/src/Interop/Unix/System.Native/Interop.IOVector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Sys | ||
{ | ||
internal unsafe struct IOVector | ||
{ | ||
public byte* Base; | ||
public UIntPtr Count; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/libraries/Common/src/Interop/Unix/System.Native/Interop.PRead.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Sys | ||
{ | ||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_PRead", SetLastError = true)] | ||
internal static extern unsafe int PRead(SafeHandle fd, byte* buffer, int count, long fileOffset); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/libraries/Common/src/Interop/Unix/System.Native/Interop.PReadV.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Sys | ||
{ | ||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_PReadV", SetLastError = true)] | ||
internal static extern unsafe long PReadV(SafeHandle fd, IOVector* vectors, int vectorCount, long fileOffset); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/libraries/Common/src/Interop/Unix/System.Native/Interop.PWrite.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Sys | ||
{ | ||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_PWrite", SetLastError = true)] | ||
internal static extern unsafe int PWrite(SafeHandle fd, byte* buffer, int bufferSize, long fileOffset); | ||
adamsitnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/libraries/Common/src/Interop/Unix/System.Native/Interop.PWriteV.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Sys | ||
{ | ||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_PWriteV", SetLastError = true)] | ||
internal static extern unsafe long PWriteV(SafeHandle fd, IOVector* vectors, int vectorCount, long fileOffset); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FileScatterGather.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Kernel32 | ||
{ | ||
[StructLayout(LayoutKind.Explicit, Size = 8)] | ||
internal unsafe struct FILE_SEGMENT_ELEMENT | ||
{ | ||
[FieldOffset(0)] | ||
public IntPtr Buffer; | ||
adamsitnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[FieldOffset(0)] | ||
public ulong Alignment; | ||
} | ||
|
||
[DllImport(Libraries.Kernel32, SetLastError = true)] | ||
internal static extern unsafe int ReadFileScatter( | ||
SafeHandle handle, | ||
FILE_SEGMENT_ELEMENT* segments, | ||
int numBytesToRead, | ||
IntPtr reserved_mustBeZero, | ||
NativeOverlapped* overlapped); | ||
|
||
[DllImport(Libraries.Kernel32, SetLastError = true)] | ||
internal static extern unsafe int WriteFileGather( | ||
SafeHandle handle, | ||
FILE_SEGMENT_ELEMENT* segments, | ||
int numBytesToWrite, | ||
IntPtr reserved_mustBeZero, | ||
NativeOverlapped* overlapped); | ||
adamsitnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: nuint