Commit df10293
Fix NativeUnixDirectory direct I/O open on macOS and ARM64 Linux (#1342)
Two platform bugs caused TestNativeUnixDirectory* to fail (5 on macOS, all
on ARM64 Linux):
- macOS EACCES: the write path opened with open(path, O_RDWR|O_CREAT, 0666)
through a fixed-signature P/Invoke, but C's open() is variadic so the mode
argument rides the varargs ABI; on macOS (incl. Apple Silicon) the callee
read garbage and created files without owner-read permission, so the
subsequent O_RDONLY open failed with EACCES. Now pre-create the file with
the BCL (applying the normal mode + umask) and open with the two-argument
open() (no O_CREAT, no varargs). Dropped the broken 3-arg open and the
O_CREAT/S_RW constants.
- ARM64 Linux ENOTDIR: O_DIRECT was hardcoded to 0x4000, which is correct on
x86/x86-64 but is O_DIRECTORY on Arm/Arm64 (the two are swapped; O_DIRECT
there is 0x10000), so open() of a regular file failed with ENOTDIR. Now
select O_DIRECT by RuntimeInformation.OSArchitecture.
Also tighten the input refill EOF check from n < 0 to n <= 0: upstream used
FileChannel.read() (returns -1 at EOF) but the port wraps libc pread()
(returns 0 at EOF), so read-past-EOF would otherwise silently return zeros.
Verified: TestNativeUnixDirectory* 23/23 pass on macOS arm64, Linux aarch64,
and Linux x86-64 (the latter two in mcr.microsoft.com/dotnet/sdk:10.0 with an
O_DIRECT-capable TMPDIR).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 2bfbf0e commit df10293
2 files changed
Lines changed: 30 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
69 | 83 | | |
70 | 84 | | |
71 | 85 | | |
72 | 86 | | |
73 | 87 | | |
74 | | - | |
| 88 | + | |
75 | 89 | | |
76 | 90 | | |
77 | 91 | | |
| |||
89 | 103 | | |
90 | 104 | | |
91 | 105 | | |
92 | | - | |
| 106 | + | |
93 | 107 | | |
94 | 108 | | |
95 | 109 | | |
| |||
194 | 208 | | |
195 | 209 | | |
196 | 210 | | |
197 | | - | |
| 211 | + | |
198 | 212 | | |
199 | 213 | | |
200 | | - | |
201 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
202 | 223 | | |
203 | 224 | | |
204 | | - | |
205 | 225 | | |
206 | 226 | | |
207 | 227 | | |
208 | 228 | | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | 229 | | |
213 | 230 | | |
214 | 231 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
526 | 526 | | |
527 | 527 | | |
528 | 528 | | |
529 | | - | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
530 | 533 | | |
531 | 534 | | |
532 | 535 | | |
| |||
0 commit comments