Skip to content

Commit 1625cb6

Browse files
committed
CoreLib: use the process temp directory for shared memory on OpenHarmony
The OpenHarmony /tmp mount denies file locks (fcntl(F_SETLK) returns EACCES even on uncontended files), and the shared memory files rely on those locks through the file-lock-backed named mutex path. Use the process temp directory (which honors TMPDIR and falls back to /tmp) for the shared memory files instead, and mirror the derivation in the mutex tests.
1 parent 1d7bc42 commit 1625cb6

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎src/libraries/System.Private.CoreLib/src/System/IO/SharedMemoryManager.Unix.cs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,14 @@ private static string InitalizeSharedFilesPath()
403403
return ApplicationContainerPath ?? "/tmp/";
404404
}
405405

406+
#if TARGET_OPENHARMONY
407+
// The OpenHarmony /tmp mount denies file locks (fcntl(F_SETLK) returns EACCES),
408+
// which the shared memory lock files rely on, so use the process temp directory
409+
// (which honors TMPDIR and falls back to /tmp) for the shared memory files.
410+
return Path.GetTempPath();
411+
#else
406412
return "/tmp/";
413+
#endif
407414
}
408415

409416
private static string? GetApplicationContainerPath()

‎src/libraries/System.Threading/tests/MutexTests.cs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,14 @@ public void NamedMutex_OtherEvent_NotCompatible()
10841084
Assert.Throws<PlatformNotSupportedException>(() => WaitHandle.WaitAny(new WaitHandle[] { m, mre }, 0));
10851085
}
10861086

1087-
private const string GlobalSharedMemoryDirectory = $"/tmp/.dotnet/shm/global";
1087+
// The runtime places global shared memory files under {SharedFilesPath}/.dotnet/shm/global
1088+
// (see SharedMemoryManager.Unix.cs). SharedFilesPath is /tmp/ on non-Apple platforms except
1089+
// on OpenHarmony, where it honors TMPDIR. Mirror the runtime's derivation so these tests
1090+
// always target the same directory the runtime uses.
1091+
private static string GlobalSharedMemoryDirectory =>
1092+
OperatingSystem.IsOSPlatform("openharmony")
1093+
? Path.Combine(Path.GetTempPath(), ".dotnet", "shm", "global")
1094+
: "/tmp/.dotnet/shm/global";
10881095
private const UnixFileMode AllUsersRwx =
10891096
UnixFileMode.UserRead
10901097
| UnixFileMode.UserWrite

0 commit comments

Comments
 (0)