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
42 changes: 42 additions & 0 deletions src/libraries/Common/src/Interop/Haiku/Interop.Image.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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;

#pragma warning disable CA1823 // analyzer incorrectly flags fixed buffer length const (https://github.com/dotnet/roslyn/issues/37593)

internal static partial class Interop
{
internal static partial class Image
{
internal const int MAXPATHLEN = 1024;

internal enum ImageType : int
{
B_APP_IMAGE = 1,
B_LIBRARY_IMAGE,
B_ADD_ON_IMAGE,
B_SYSTEM_IMAGE,
}

[StructLayout(LayoutKind.Sequential)]
internal unsafe struct ImageInfo
{
public ImageType type;
public fixed byte name[MAXPATHLEN];
public void* text;
public int text_size;
public int data_size;
}

/// <summary>
/// Gets information about images owned by a team.
/// </summary>
/// <param name="team">The team ID to iterate.</param>
/// <param name="cookie">A cookie to track the iteration.</param>
/// <param name="info">The <see cref="ImageInfo"/> structure to fill in.</param>
/// <returns>Returns 0 on success. Returns an error code on failure or when there are no more images to iterate.</returns>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetNextImageInfo")]
internal static partial int GetNextImageInfo(int team, ref int cookie, out ImageInfo info);
}
}
146 changes: 142 additions & 4 deletions src/libraries/Common/src/Interop/Haiku/Interop.OS.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,166 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.InteropServices;

#pragma warning disable CA1823 // analyzer incorrectly flags fixed buffer length const (https://github.com/dotnet/roslyn/issues/37593)
internal static partial class Interop
{
internal static partial class OS
{
internal const int B_OS_NAME_LENGTH = 32;

[StructLayout(LayoutKind.Sequential)]
internal unsafe struct AreaInfo
internal struct AreaInfo
{
public nuint size;
public uint ram_size;
}

[StructLayout(LayoutKind.Sequential)]
internal unsafe struct TeamInfo
{
public int team;
public int session_id;
public int parent;
public fixed byte name[B_OS_NAME_LENGTH];
public long start_time;
}

internal enum BTeamUsage : int
{
B_TEAM_USAGE_SELF = 0,
B_TEAM_USAGE_CHILDREN = -1,
}

[StructLayout(LayoutKind.Sequential)]
internal struct TeamUsageInfo
{
public long user_time;
public long kernel_time;
}

internal enum ThreadState : int
{
B_THREAD_RUNNING = 1,
B_THREAD_READY,
B_THREAD_RECEIVING,
B_THREAD_ASLEEP,
B_THREAD_SUSPENDED,
B_THREAD_WAITING,
}

[StructLayout(LayoutKind.Sequential)]
internal struct ThreadInfo
{
public int thread;
public int team;
public ThreadState state;
public int priority;
public long user_time;
public long kernel_time;
}

internal enum BPriority : int
{
B_IDLE_PRIORITY = 0,
B_LOWEST_ACTIVE_PRIORITY = 1,
B_LOW_PRIORITY = 5,
B_NORMAL_PRIORITY = 10,
B_DISPLAY_PRIORITY = 15,
B_URGENT_DISPLAY_PRIORITY = 20,
B_REAL_TIME_DISPLAY_PRIORITY = 100,
B_URGENT_PRIORITY = 110,
B_REAL_TIME_PRIORITY = 120,
}

[StructLayout(LayoutKind.Sequential)]
internal struct SystemInfo
{
public long boot_time;
}

/// <summary>
/// Gets information about areas owned by a team.
/// </summary>
/// <param name="team">The team ID of the areas to iterate.</param>
/// <param name="cookie">A cookie to track the iteration.</param>
/// <param name="areaInfo">The <see cref="AreaInfo"/> structure to fill in.</param>
/// <param name="info">The <see cref="AreaInfo"/> structure to fill in.</param>
/// <returns>Returns 0 on success. Returns an error code on failure or when there are no more areas to iterate.</returns>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetNextAreaInfo")]
internal static unsafe partial int GetNextAreaInfo(int team, ref nint cookie, out AreaInfo areaInfo);
internal static partial int GetNextAreaInfo(int team, ref nint cookie, out AreaInfo info);

/// <summary>
/// Gets information about a team.
/// </summary>
/// <param name="team">The team ID.</param>
/// <param name="info">The <see cref="TeamInfo"/> structure to fill in.</param>
/// <returns>Returns 0 on success or an error code on failure.</returns>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetTeamInfo")]
internal static partial int GetTeamInfo(int team, out TeamInfo info);

/// <summary>
/// Gets information about teams.
/// </summary>
/// <param name="cookie">A cookie to track the iteration.</param>
/// <param name="info">The <see cref="TeamInfo"/> structure to fill in.</param>
/// <returns>Returns 0 on success. Returns an error code on failure or when there are no more teams to iterate.</returns>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetNextTeamInfo")]
internal static partial int GetNextTeamInfo(ref int cookie, out TeamInfo info);

/// <summary>
/// Gets team IDs.
/// </summary>
/// <param name="cookie">A cookie to track the iteration.</param>
/// <param name="team">The integer to store the retrieved team ID.</param>
/// <returns>Returns 0 on success. Returns an error code on failure or when there are no more teams to iterate.</returns>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetNextTeamId")]
internal static partial int GetNextTeamId(ref int cookie, out int team);

/// <summary>
/// Gets information about a team's usage.
/// </summary>
/// <param name="team">The team ID.</param>
/// <param name="who">Specifies whether to get usage information for the team or its children.</param>
/// <param name="info">The <see cref="TeamUsageInfo"/> structure to fill in.</param>
/// <returns>Returns 0 on success or an error code on failure.</returns>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetTeamUsageInfo")]
internal static partial int GetTeamUsageInfo(int team, BTeamUsage who, out TeamUsageInfo info);

/// <summary>
/// Sets the priority of a thread.
/// </summary>
/// <param name="thread">The thread ID.</param>
/// <param name="newPriority">The new priority.</param>
/// <returns>The previous priority if successful or an error code on failure.</returns>
Comment thread
trungnt2910 marked this conversation as resolved.
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetThreadPriority")]
internal static partial int SetThreadPriority(int thread, int newPriority);

/// <summary>
/// Gets information about a thread.
/// </summary>
/// <param name="thread">The thread ID.</param>
/// <param name="info">The <see cref="ThreadInfo"/> structure to fill in.</param>
/// <returns>Returns 0 on success or an error code on failure.</returns>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetThreadInfo")]
internal static partial int GetThreadInfo(int thread, out ThreadInfo info);

/// <summary>
/// Gets information about threads owned by a team.
/// </summary>
/// <param name="team">The team ID of the threads to iterate.</param>
/// <param name="cookie">A cookie to track the iteration.</param>
/// <param name="info">The <see cref="ThreadInfo"/> structure to fill in.</param>
/// <returns>Returns 0 on success. Returns an error code on failure or when there are no more threads to iterate.</returns>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetNextThreadInfo")]
internal static partial int GetNextThreadInfo(int team, ref int cookie, out ThreadInfo info);

/// <summary>
/// Gets information about the system.
/// </summary>
/// <param name="info">The system info to store retrieved information.</param>
/// <returns>0 if successful.</returns>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetSystemInfo")]
internal static partial int GetSystemInfo(out SystemInfo info);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ internal ProcessThread() { }
public int Id { get { throw null; } }
public int IdealProcessor { set { } }
public bool PriorityBoostEnabled { get { throw null; } set { } }
public System.Diagnostics.ThreadPriorityLevel PriorityLevel { [System.Runtime.Versioning.SupportedOSPlatform("windows")] [System.Runtime.Versioning.SupportedOSPlatform("linux")] [System.Runtime.Versioning.SupportedOSPlatform("freebsd")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } }
public System.Diagnostics.ThreadPriorityLevel PriorityLevel { [System.Runtime.Versioning.SupportedOSPlatform("windows")] [System.Runtime.Versioning.SupportedOSPlatform("linux")] [System.Runtime.Versioning.SupportedOSPlatform("freebsd")] [System.Runtime.Versioning.SupportedOSPlatform("haiku")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] [System.Runtime.Versioning.SupportedOSPlatformAttribute("haiku")] set { } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
[System.Runtime.Versioning.SupportedOSPlatformAttribute("maccatalyst")] // this needs to come after the ios attribute due to limitations in the platform analyzer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-freebsd;$(NetCoreAppCurrent)-linux;$(NetCoreAppCurrent)-osx;$(NetCoreAppCurrent)-maccatalyst;$(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)-illumos;$(NetCoreAppCurrent)-solaris;$(NetCoreAppCurrent)</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-freebsd;$(NetCoreAppCurrent)-linux;$(NetCoreAppCurrent)-osx;$(NetCoreAppCurrent)-maccatalyst;$(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)-illumos;$(NetCoreAppCurrent)-solaris;$(NetCoreAppCurrent)-haiku;$(NetCoreAppCurrent)</TargetFrameworks>
<DefineConstants>$(DefineConstants);FEATURE_REGISTRY</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
Expand Down Expand Up @@ -403,12 +403,26 @@
Link="Common\Interop\SunOS\procfs\Interop.ProcFs.GetThreadInfoById.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'haiku'">
<Compile Include="System\Diagnostics\Process.Haiku.cs" />
<Compile Include="System\Diagnostics\ProcessManager.Haiku.cs" />
<Compile Include="System\Diagnostics\ProcessThread.Haiku.cs" />
<Compile Include="$(CommonPath)Interop\Haiku\Interop.Image.cs"
Link="Common\Interop\Haiku\Interop.Image.cs" />
<Compile Include="$(CommonPath)Interop\Haiku\Interop.OS.cs"
Link="Common\Interop\Haiku\Interop.OS.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'ios' or '$(TargetPlatformIdentifier)' == 'tvos'">
<Compile Include="System\Diagnostics\Process.iOS.cs" />
<Compile Include="System\Diagnostics\ProcessManager.iOS.cs" />
<Compile Include="System\Diagnostics\ProcessThread.iOS.cs" />
</ItemGroup>

<ItemGroup>
<SupportedPlatform Include="Haiku"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Win32.Primitives\src\Microsoft.Win32.Primitives.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Win32.Registry\src\Microsoft.Win32.Registry.csproj" />
Expand Down
Loading
Loading