Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/coreclr/gc/unix/numasupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <limits.h>
#include <minipal/utils.h>

#if defined(TARGET_LINUX) && !defined(TARGET_ANDROID)
#if defined(TARGET_LINUX) && !defined(TARGET_ANDROID) && !defined(TARGET_OPENHARMONY)
#include <sys/syscall.h>
#endif

Expand All @@ -21,7 +21,7 @@ int g_highestNumaNode = 0;
// Is numa available
bool g_numaAvailable = false;

#if defined(TARGET_LINUX) && !defined(TARGET_ANDROID)
#if defined(TARGET_LINUX) && !defined(TARGET_ANDROID) && !defined(TARGET_OPENHARMONY)
static int GetNodeNum(const char* path, bool firstOnly)
{
DIR *dir;
Expand Down Expand Up @@ -56,7 +56,7 @@ static int GetNodeNum(const char* path, bool firstOnly)

void NUMASupportInitialize()
{
#if defined(TARGET_LINUX) && !defined(TARGET_ANDROID)
#if defined(TARGET_LINUX) && !defined(TARGET_ANDROID) && !defined(TARGET_OPENHARMONY)
if (syscall(__NR_get_mempolicy, NULL, NULL, 0, 0, 0) < 0)
return;

Expand All @@ -72,7 +72,7 @@ void NUMASupportInitialize()

int GetNumaNodeNumByCpu(int cpu)
{
#if defined(TARGET_LINUX) && !defined(TARGET_ANDROID)
#if defined(TARGET_LINUX) && !defined(TARGET_ANDROID) && !defined(TARGET_OPENHARMONY)
char path[64];
if (snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d", cpu) < 0)
return -1;
Expand All @@ -85,7 +85,7 @@ int GetNumaNodeNumByCpu(int cpu)

long BindMemoryPolicy(void* start, unsigned long len, const unsigned long* nodemask, unsigned long maxnode)
{
#if defined(TARGET_LINUX) && !defined(TARGET_ANDROID)
#if defined(TARGET_LINUX) && !defined(TARGET_ANDROID) && !defined(TARGET_OPENHARMONY)
return syscall(__NR_mbind, (long)start, len, 1, (long)nodemask, maxnode, 0);
#else
return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<DefineConstants Condition="'$(Targetsillumos)' == 'true'">$(DefineConstants);TARGET_ILLUMOS</DefineConstants>
<DefineConstants Condition="'$(TargetsSolaris)' == 'true'">$(DefineConstants);TARGET_SOLARIS</DefineConstants>
<DefineConstants Condition="'$(TargetsHaiku)' == 'true'">$(DefineConstants);TARGET_HAIKU</DefineConstants>
<DefineConstants Condition="'$(TargetOpenHarmony)' == 'true'">$(DefineConstants);TARGET_OPENHARMONY</DefineConstants>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TargetOpenHarmony -> TargetsOpenHarmony to match the naming pattern

</PropertyGroup>
<PropertyGroup>
<DefineConstants Condition="'$(FeatureCrossProcessMutex)' == 'true'">$(DefineConstants);FEATURE_CROSS_PROCESS_MUTEX</DefineConstants>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,15 @@ private static string InitalizeSharedFilesPath()
}
}

// On non-Apple platforms, shared memory files live under the process temp directory.
#if TARGET_OPENHARMONY
// HarmonyOS (OpenHarmony) app sandboxes mount /tmp read-only, so use the process temp
// directory (which honors TMPDIR on Unix and falls back to /tmp) for the .NET shared
// memory files (named mutexes, etc.).
return Path.GetTempPath();
#else
return "/tmp/";
#endif
}

internal static SafeFileHandle CreateOrOpenFile(string sharedMemoryFilePath, SharedMemoryId id, bool createIfNotExist, out bool createdFile)
Expand Down
11 changes: 11 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/OperatingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,17 @@ internal static bool IsHaiku() =>
false;
#endif

/// <summary>
/// Indicates whether the current application is running on HarmonyOS (OpenHarmony).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HarmonyOS is not the same as OpenHarmony. Should all comments like this talk just about OpenHarmony?

/// </summary>
[NonVersionable]
internal static bool IsOpenHarmony() =>
#if TARGET_OPENHARMONY
true;
#else
false;
#endif

/// <summary>
/// Indicates whether the current application is running on Android.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ internal abstract class NamedMutexProcessDataBase(SharedMemoryProcessDataHeader<
// independently by the processes involved. See https://github.com/dotnet/runtime/issues/10519.
// On OpenBSD, cross process mutexes are not supported in the pthread implementation. See https://github.com/dotnet/runtime/pull/125089.
// On Haiku, robust mutexes are WIP. See https://github.com/dotnet/runtime/pull/126701#issuecomment-4334338213.
private static bool UsePThreadMutexes => !OperatingSystem.IsApplePlatform() && !OperatingSystem.IsFreeBSD() && !OperatingSystem.IsOpenBSD() && !OperatingSystem.IsHaiku();
private static bool UsePThreadMutexes => !OperatingSystem.IsApplePlatform() && !OperatingSystem.IsFreeBSD() && !OperatingSystem.IsOpenBSD() && !OperatingSystem.IsHaiku() && !OperatingSystem.IsOpenHarmony();

private readonly SharedMemoryProcessDataHeader<NamedMutexProcessDataBase> _processDataHeader = header;
protected nuint _lockCount;
Expand Down
11 changes: 10 additions & 1 deletion src/libraries/System.Threading/tests/MutexTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,16 @@ public void NamedMutex_OtherEvent_NotCompatible()
Assert.Throws<PlatformNotSupportedException>(() => WaitHandle.WaitAny(new WaitHandle[] { m, mre }, 0));
}

private const string GlobalSharedMemoryDirectory = $"/tmp/.dotnet/shm/global";
// The runtime places global shared memory files under {SharedFilesPath}/.dotnet/shm/global
// (see SharedMemoryManager.Unix.cs). SharedFilesPath is /tmp/ on non-Apple platforms except
// on HarmonyOS, where it honors TMPDIR. Mirror the runtime's derivation so these tests
// always target the same directory the runtime uses.
private static string GlobalSharedMemoryDirectory =>
#if TARGET_OPENHARMONY
Path.Combine(Path.GetTempPath(), ".dotnet", "shm", "global");
#else
"/tmp/.dotnet/shm/global";
#endif
private const UnixFileMode AllUsersRwx =
UnixFileMode.UserRead
| UnixFileMode.UserWrite
Expand Down
Loading