Skip to content
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

Fix illumos managed build #44386

Merged
merged 4 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion eng/targetframeworksuffix.props
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<When Condition="'$(TargetFrameworkSuffix)' == 'illumos'">
<PropertyGroup>
<TargetsUnix>true</TargetsUnix>
<TargetsIllumos>true</TargetsIllumos>
<Targetsillumos>true</Targetsillumos>
<PackageTargetRuntime>illumos</PackageTargetRuntime>
</PropertyGroup>
</When>
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/dir.common.props
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@
<TargetsFreeBSD Condition="'$(TargetOS)' == 'FreeBSD'">true</TargetsFreeBSD>
<TargetsLinux Condition="'$(TargetOS)' == 'Linux'">true</TargetsLinux>
<TargetsNetBSD Condition="'$(TargetOS)' == 'NetBSD'">true</TargetsNetBSD>
<TargetsIllumos Condition="'$(TargetOS)' == 'illumos'">true</TargetsIllumos>
<Targetsillumos Condition="'$(TargetOS)' == 'illumos'">true</Targetsillumos>
<TargetsSolaris Condition="'$(TargetOS)' == 'Solaris'">true</TargetsSolaris>
<TargetsOSX Condition="'$(TargetOS)' == 'OSX'">true</TargetsOSX>
<TargetsWindows Condition="'$(TargetOS)' == 'windows'">true</TargetsWindows>

<TargetsUnix Condition="'$(TargetsFreeBSD)' == 'true' or '$(TargetsLinux)' == 'true' or '$(TargetsNetBSD)' == 'true' or '$(TargetsOSX)' == 'true' or '$(TargetsIllumos)' == 'true' or '$(TargetsSolaris)' == 'true'">true</TargetsUnix>
<TargetsUnix Condition="'$(TargetsFreeBSD)' == 'true' or '$(TargetsLinux)' == 'true' or '$(TargetsNetBSD)' == 'true' or '$(TargetsOSX)' == 'true' or '$(Targetsillumos)' == 'true' or '$(TargetsSolaris)' == 'true'">true</TargetsUnix>

<!-- We are only tracking Linux Distributions for Nuget RID mapping -->
<DistroRid Condition="'$(TargetsLinux)' == 'true'">$(__DistroRid)</DistroRid>
Expand Down
2 changes: 1 addition & 1 deletion src/installer/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
</When>
<When Condition="$(OutputRid.StartsWith('illumos'))">
<PropertyGroup>
<TargetsIllumos>true</TargetsIllumos>
<Targetsillumos>true</Targetsillumos>
<TargetsUnix>true</TargetsUnix>
</PropertyGroup>
</When>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<CoreCLRTargetOS Condition="'$(TargetsBrowser)' == 'true'">Browser</CoreCLRTargetOS>
<CoreCLRTargetOS Condition="'$(TargetsFreeBSD)' == 'true'">FreeBSD</CoreCLRTargetOS>
<CoreCLRTargetOS Condition="'$(TargetsNetBSD)' == 'true'">NetBSD</CoreCLRTargetOS>
<CoreCLRTargetOS Condition="'$(TargetsIllumos)' == 'true'">illumos</CoreCLRTargetOS>
<CoreCLRTargetOS Condition="'$(Targetsillumos)' == 'true'">illumos</CoreCLRTargetOS>
<CoreCLRTargetOS Condition="'$(TargetsSolaris)' == 'true'">Solaris</CoreCLRTargetOS>
<LibrariesTargetOS>$(CoreCLRTargetOS)</LibrariesTargetOS>
</PropertyGroup>
Expand Down
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.

#nullable enable
am11 marked this conversation as resolved.
Show resolved Hide resolved
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class procfs
{
/// <summary>
/// Attempts to get status info for the specified process ID.
/// </summary>
/// <param name="pid">PID of the process to read status info for.</param>
/// <param name="processStatus">The pointer to processStatus instance.</param>
/// <returns>
/// true if the process status was read; otherwise, false.
/// </returns>
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ReadProcessStatusInfo", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
am11 marked this conversation as resolved.
Show resolved Hide resolved
private static extern unsafe bool TryReadProcessStatusInfo(int pid, ProcessStatusInfo* processStatus);

internal struct ProcessStatusInfo
{
internal ulong ResidentSetSize;
am11 marked this conversation as resolved.
Show resolved Hide resolved
// add more fields when needed.
}

internal static unsafe bool TryReadProcessStatusInfo(int pid, out ProcessStatusInfo statusInfo)
am11 marked this conversation as resolved.
Show resolved Hide resolved
{
fixed (ProcessStatusInfo* pStatusInfo = &statusInfo)
{
return TryReadProcessStatusInfo(pid, pStatusInfo);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private static DistroInfo GetDistroInfo()
// What we want is major release as minor releases should be compatible.
result.VersionId = ToVersion(RuntimeInformation.OSDescription.Split()[1].Split('.')[0]);
}
else if (IsIllumos)
else if (Isillumos)
{
// examples:
// on OmniOS
Expand Down Expand Up @@ -195,7 +195,8 @@ private static DistroInfo GetDistroInfo()
// example:
// SunOS 5.11 11.3
result.Id = "Solaris";
result.VersionId = ToVersion(RuntimeInformation.OSDescription.Split(' ')[2]); // e.g. 11.3
// we only need the major version; 11
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
result.VersionId = ToVersion(RuntimeInformation.OSDescription.Split(' ')[2].Split('.')[0]); // e.g. 11
}
else if (File.Exists("/etc/os-release"))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static partial class PlatformDetection
public static bool IsNetBSD => RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD"));
public static bool IsiOS => RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS"));
public static bool IstvOS => RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS"));
public static bool IsIllumos => RuntimeInformation.IsOSPlatform(OSPlatform.Create("ILLUMOS"));
public static bool Isillumos => RuntimeInformation.IsOSPlatform(OSPlatform.Create("ILLUMOS"));
public static bool IsSolaris => RuntimeInformation.IsOSPlatform(OSPlatform.Create("SOLARIS"));
public static bool IsBrowser => RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER"));
public static bool IsNotBrowser => !IsBrowser;
Expand Down Expand Up @@ -124,7 +124,7 @@ public static bool IsNonZeroLowerBoundArraySupported
// Windows - Schannel supports alpn from win8.1/2012 R2 and higher.
// Linux - OpenSsl supports alpn from openssl 1.0.2 and higher.
// OSX - SecureTransport doesn't expose alpn APIs. TODO https://github.com/dotnet/runtime/issues/27727
public static bool IsOpenSslSupported => IsLinux || IsFreeBSD || IsIllumos || IsSolaris;
public static bool IsOpenSslSupported => IsLinux || IsFreeBSD || Isillumos || IsSolaris;

public static bool SupportsAlpn => (IsWindows && !IsWindows7) ||
(IsOpenSslSupported &&
Expand Down
37 changes: 37 additions & 0 deletions src/libraries/Native/Unix/System.Native/pal_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@
// Somehow, AIX mangles the definition for this behind a C++ def
// Redeclare it here
extern int getpeereid(int, uid_t *__restrict__, gid_t *__restrict__);
#elif defined(__sun)
#ifndef _KERNEL
#define _KERNEL
#define UNDEF_KERNEL
#endif
#include <sys/procfs.h>
#ifdef UNDEF_KERNEL
#undef _KERNEL
#endif
#endif

#if HAVE_STAT64
Expand Down Expand Up @@ -1288,3 +1297,31 @@ int32_t SystemNative_LChflagsCanSetHiddenFlag(void)
return false;
#endif
}

#ifdef __sun

int32_t SystemNative_ReadProcessStatusInfo(pid_t pid, ProcessStatus* processStatus)
{
char statusFilename[64];
snprintf(statusFilename, sizeof(statusFilename), "/proc/%d/psinfo", pid);

intptr_t fd;
while ((fd = open(statusFilename, O_RDONLY)) < 0 && errno == EINTR);
if (fd < 0)
{
return 0;
}

psinfo_t status;
int result = Common_Read(fd, &status, sizeof(psinfo_t));
while (close(fd) < 0 && errno == EINTR);
am11 marked this conversation as resolved.
Show resolved Hide resolved
if (result >= 0)
{
processStatus->ResidentSetSize = status.pr_rssize * 100; // pr_rssize is in Kbytes
am11 marked this conversation as resolved.
Show resolved Hide resolved
return 1;
}

return 0;
}

#endif // __sun
17 changes: 17 additions & 0 deletions src/libraries/Native/Unix/System.Native/pal_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ typedef struct
uint32_t UserFlags; // user defined flags
} FileStatus;

#ifdef __sun
typedef struct
{
size_t ResidentSetSize;
// add more fields when needed.
} ProcessStatus;
#endif

/* Provide consistent access to nanosecond fields, if they exist. */
/* Seconds are always available through st_atime, st_mtime, st_ctime. */

Expand Down Expand Up @@ -710,3 +718,12 @@ PALEXPORT int32_t SystemNative_LChflags(const char* path, uint32_t flags);
* Returns true (non-zero) if supported, false (zero) if not.
*/
PALEXPORT int32_t SystemNative_LChflagsCanSetHiddenFlag(void);

#ifdef __sun
/**
* Reads the psinfo_t struct and converts into ProcessStatus.
*
* Returns 1 if the process status was read; otherwise, 0.
*/
PALEXPORT int32_t SystemNative_ReadProcessStatusInfo(pid_t pid, ProcessStatus* processStatus);
#endif
2 changes: 1 addition & 1 deletion src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<Compile Include="$(CommonPath)Interop\Interop.Odbc.cs"
Link="Common\Interop\Interop.Odbc.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsLinux)' == 'true' or '$(TargetsFreeBSD)' == 'true' or '$(TargetsIllumos)' == 'true' or '$(TargetsSolaris)' == 'true'">
<ItemGroup Condition="'$(TargetsLinux)' == 'true' or '$(TargetsFreeBSD)' == 'true' or '$(Targetsillumos)' == 'true' or '$(TargetsSolaris)' == 'true'">
<Compile Include="$(CommonPath)Interop\Linux\Interop.Libraries.cs"
Link="Common\Interop\Linux\Interop.Libraries.cs" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Net.Http/src/System.Net.Http.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<WindowsRID>win</WindowsRID>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>$(DefineConstants);HTTP_DLL</DefineConstants>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-FreeBSD;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-FreeBSD;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-illumos;$(NetCoreAppCurrent)-Solaris</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetsOSX)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true'">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-FreeBSD</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-FreeBSD;$(NetCoreAppCurrent)-illumos;$(NetCoreAppCurrent)-Solaris</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
Expand Down Expand Up @@ -181,7 +181,7 @@
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.NetworkChange.cs" Link="Common\Interop\Unix\System.Native\Interop.NetworkChange.cs" />
</ItemGroup>
<!-- Unknown Unix -->
<ItemGroup Condition=" '$(TargetsUnknownUnix)' == 'true' ">
<ItemGroup Condition=" '$(TargetsUnknownUnix)' == 'true' or '$(Targetsillumos)' == 'true' or '$(TargetsSolaris)' == 'true' ">
<Compile Include="System\Net\NetworkInformation\IPGlobalPropertiesPal.UnknownUnix.cs" />
<Compile Include="System\Net\NetworkInformation\NetworkInterfacePal.UnknownUnix.cs" />
<Compile Include="System\Net\NetworkInformation\NetworkAddressChange.UnknownUnix.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ public partial class NetworkChange
// The listener thread's CFRunLoop.
private static CFRunLoopRef s_runLoop;

// The list of current address-changed subscribers.
private static readonly Dictionary<NetworkAddressChangedEventHandler, ExecutionContext?> s_addressChangedSubscribers =
new Dictionary<NetworkAddressChangedEventHandler, ExecutionContext?>();

// The list of current availability-changed subscribers.
private static readonly Dictionary<NetworkAvailabilityChangedEventHandler, ExecutionContext?> s_availabilityChangedSubscribers =
new Dictionary<NetworkAvailabilityChangedEventHandler, ExecutionContext?>();

private static readonly ContextCallback s_runHandlerAvailable = new ContextCallback(RunAvailabilityHandlerAvailable!);
private static readonly ContextCallback s_runHandlerNotAvailable = new ContextCallback(RunAvailabilityHandlerNotAvailable!);
private static readonly ContextCallback s_runAddressChangedHandler = new ContextCallback(RunAddressChangedHandler!);

// Use an event to try to prevent StartRaisingEvents from returning before the
// RunLoop actually begins. This will mitigate a race condition where the watcher
// thread hasn't completed initialization and stop is called before the RunLoop has even started.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ public partial class NetworkChange
private static readonly object s_gate = new object();
private static readonly Interop.Sys.NetworkChangeEvent s_networkChangeCallback = ProcessEvent;

// The list of current address-changed subscribers.
private static readonly Dictionary<NetworkAddressChangedEventHandler, ExecutionContext?> s_addressChangedSubscribers =
new Dictionary<NetworkAddressChangedEventHandler, ExecutionContext?>();

// The list of current availability-changed subscribers.
private static readonly Dictionary<NetworkAvailabilityChangedEventHandler, ExecutionContext?> s_availabilityChangedSubscribers =
new Dictionary<NetworkAvailabilityChangedEventHandler, ExecutionContext?>();

private static readonly ContextCallback s_runHandlerAvailable = new ContextCallback(RunAvailabilityHandlerAvailable!);
private static readonly ContextCallback s_runHandlerNotAvailable = new ContextCallback(RunAvailabilityHandlerNotAvailable!);
private static readonly ContextCallback s_runAddressChangedHandler = new ContextCallback(RunAddressChangedHandler!);

// The "leniency" window for NetworkAvailabilityChanged socket events.
// All socket events received within this duration will be coalesced into a
// single event. Generally, many route changed events are fired in succession,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ public partial class NetworkChange
{
private static readonly object s_globalLock = new object();

// The list of current address-changed subscribers.
private static readonly Dictionary<NetworkAddressChangedEventHandler, ExecutionContext?> s_addressChangedSubscribers =
new Dictionary<NetworkAddressChangedEventHandler, ExecutionContext?>();

// The list of current availability-changed subscribers.
private static readonly Dictionary<NetworkAvailabilityChangedEventHandler, ExecutionContext?> s_availabilityChangedSubscribers =
new Dictionary<NetworkAvailabilityChangedEventHandler, ExecutionContext?>();

private static readonly ContextCallback s_runHandlerAvailable = new ContextCallback(RunAvailabilityHandlerAvailable!);
private static readonly ContextCallback s_runHandlerNotAvailable = new ContextCallback(RunAvailabilityHandlerNotAvailable!);
private static readonly ContextCallback s_runAddressChangedHandler = new ContextCallback(RunAddressChangedHandler!);

public static event NetworkAvailabilityChangedEventHandler? NetworkAvailabilityChanged
{
add
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,8 @@ namespace System.Net.NetworkInformation
{
public partial class NetworkChange
{
// The list of current address-changed subscribers.
private static readonly Dictionary<NetworkAddressChangedEventHandler, ExecutionContext?> s_addressChangedSubscribers =
new Dictionary<NetworkAddressChangedEventHandler, ExecutionContext?>();

// The list of current availability-changed subscribers.
private static readonly Dictionary<NetworkAvailabilityChangedEventHandler, ExecutionContext?> s_availabilityChangedSubscribers =
new Dictionary<NetworkAvailabilityChangedEventHandler, ExecutionContext?>();

private static readonly NetworkAvailabilityEventArgs s_availableEventArgs = new NetworkAvailabilityEventArgs(isAvailable: true);
private static readonly NetworkAvailabilityEventArgs s_notAvailableEventArgs = new NetworkAvailabilityEventArgs(isAvailable: false);
private static readonly ContextCallback s_runHandlerAvailable = new ContextCallback(RunAvailabilityHandlerAvailable!);
private static readonly ContextCallback s_runHandlerNotAvailable = new ContextCallback(RunAvailabilityHandlerNotAvailable!);
private static readonly ContextCallback s_runAddressChangedHandler = new ContextCallback(RunAddressChangedHandler!);
am11 marked this conversation as resolved.
Show resolved Hide resolved

// Introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1853,11 +1853,14 @@
Link="Common\System\IO\StringParser.cs" />
<Compile Include="$(CommonPath)Interop\OSX\Interop.libproc.GetProcessInfoById.cs" Condition="'$(IsOSXLike)' == 'true'"
Link="Common\Interop\OSX\Interop.libproc.GetProcessInfoById.cs" />
<Compile Include="$(CommonPath)Interop\SunOS\procfs\Interop.ProcFsStat.TryReadProcessStatusInfo.cs" Condition="'$(Targetsillumos)' == 'true' or '$(TargetsSolaris)' == 'true'"
Link="Common\Interop\SunOS\Interop.ProcFsStat.TryReadProcessStatusInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.FreeBSD.cs" Condition="'$(TargetsFreeBSD)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.Linux.cs" Condition="'$(TargetsLinux)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.OSX.cs" Condition="'$(IsOSXLike)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.OSVersion.Unix.cs" Condition="'$(IsOSXLike)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.SunOS.cs" Condition="'$(Targetsillumos)' == 'true' or '$(TargetsSolaris)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.GetDisplayName.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\DriveInfoInternal.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\PersistedFiles.Unix.cs" />
Expand Down
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;

namespace System
{
public static partial class Environment
{
public static long WorkingSet =>
(long)(Interop.procfs.TryReadProcessStatusInfo(ProcessId, out Interop.procfs.ProcessStatusInfo status) ? status.ResidentSetSize : 0);
}
}
Loading