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 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
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 @@ -274,7 +274,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
@@ -0,0 +1,36 @@
// 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 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)]
private static extern unsafe bool TryReadProcessStatusInfo(int pid, ProcessStatusInfo* processStatus);

internal struct ProcessStatusInfo
{
internal nuint ResidentSetSize;
// 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
{
statusInfo = default;
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 @@ -1296,3 +1305,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));
close(fd);
if (result >= 0)
{
processStatus->ResidentSetSize = status.pr_rssize * 1024; // pr_rssize is in Kbytes
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
@@ -1,10 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Threading;

namespace System.Net.NetworkInformation
{
public partial class NetworkChange
{
static NetworkChange()
{
// fake usage of static readonly fields to avoid getting CA1823 warning when we are compiling this partial.
var addressChangedSubscribers = new Dictionary<NetworkAddressChangedEventHandler, ExecutionContext?>(s_addressChangedSubscribers);
var availabilityChangedSubscribers = new Dictionary<NetworkAvailabilityChangedEventHandler, ExecutionContext?>(s_availabilityChangedSubscribers);
NetworkAvailabilityEventArgs args = addressChangedSubscribers.Count > 0 ? s_availableEventArgs : s_notAvailableEventArgs;
ContextCallback callbackContext = s_runAddressChangedHandler != null ? s_runHandlerAvailable : s_runHandlerNotAvailable;
}

public static event NetworkAddressChangedEventHandler? NetworkAddressChanged
{
add { throw new PlatformNotSupportedException(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1851,11 +1851,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);
}
}
4 changes: 2 additions & 2 deletions src/mono/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<!-- Set up common target properties that we use to conditionally include sources -->
<PropertyGroup>
<TargetsFreeBSD Condition="'$(TargetOS)' == 'FreeBSD'">true</TargetsFreeBSD>
<TargetsIllumos Condition="'$(TargetOS)' == 'illumos'">true</TargetsIllumos>
<Targetsillumos Condition="'$(TargetOS)' == 'illumos'">true</Targetsillumos>
<TargetsSolaris Condition="'$(TargetOS)' == 'Solaris'">true</TargetsSolaris>
<TargetsLinux Condition="'$(TargetOS)' == 'Linux' or '$(TargetOS)' == 'Android'">true</TargetsLinux>
<TargetsNetBSD Condition="'$(TargetOS)' == 'NetBSD'">true</TargetsNetBSD>
Expand All @@ -46,7 +46,7 @@
<TargetsAndroid Condition="'$(TargetOS)' == 'Android'">true</TargetsAndroid>
<TargetsBrowser Condition="'$(TargetOS)' == 'Browser'">true</TargetsBrowser>
<TargetsWindows Condition="'$(TargetOS)' == 'windows'">true</TargetsWindows>
<TargetsUnix Condition="'$(TargetsFreeBSD)' == 'true' or '$(TargetsIllumos)' == 'true' or '$(TargetsSolaris)' == 'true' or '$(TargetsLinux)' == 'true' or '$(TargetsNetBSD)' == 'true' or '$(TargetsOSX)' == 'true' or '$(TargetstvOS)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetsAndroid)' == 'true'">true</TargetsUnix>
<TargetsUnix Condition="'$(TargetsFreeBSD)' == 'true' or '$(Targetsillumos)' == 'true' or '$(TargetsSolaris)' == 'true' or '$(TargetsLinux)' == 'true' or '$(TargetsNetBSD)' == 'true' or '$(TargetsOSX)' == 'true' or '$(TargetstvOS)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetsAndroid)' == 'true'">true</TargetsUnix>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
<When Condition="'$(TargetOS)'=='illumos'">
<PropertyGroup>
<TargetsUnix>true</TargetsUnix>
<TargetsIllumos>true</TargetsIllumos>
<Targetsillumos>true</Targetsillumos>
<TestNugetRuntimeId>ubuntu.14.04-$(TargetArchitecture)</TestNugetRuntimeId>
</PropertyGroup>
</When>
Expand Down