Skip to content

Haiku: Process/thread management functions#121883

Open
trungnt2910 wants to merge 4 commits intodotnet:mainfrom
trungnt2910:dev/trungnt2910/haiku-lib-diagnostics
Open

Haiku: Process/thread management functions#121883
trungnt2910 wants to merge 4 commits intodotnet:mainfrom
trungnt2910:dev/trungnt2910/haiku-lib-diagnostics

Conversation

@trungnt2910
Copy link
Copy Markdown
Contributor

Add support for process/thread management functions in System.Diagnostics.Process for Haiku.

This is required to build managed runtime libraries for Haiku as well as running a simple "Hello, World!" application.

Part of #55803.

Copilot AI review requested due to automatic review settings November 21, 2025 15:01
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 21, 2025
@trungnt2910
Copy link
Copy Markdown
Contributor Author

C/c @am11

I just added the relevant parts of the common files to both, then we can rebase stuff later.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds Haiku operating system support to the System.Diagnostics.Process library, enabling process and thread management functionality for Haiku. This is part of the broader effort to support Haiku as a platform (#55803).

  • Implements Haiku-specific process/thread management APIs using native Haiku system calls
  • Adds proper platform attribute annotations for API surface compatibility
  • Integrates Haiku interop layer for process, thread, and image information

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
ProcessThread.cs Adds [SupportedOSPlatform("haiku")] attributes to PriorityLevel property getter and setter
ProcessThread.Haiku.cs Implements Haiku-specific thread priority management and processor time tracking using native BeOS-style priority values
ProcessManager.Haiku.cs Implements process enumeration, module collection, and process information retrieval for Haiku using team and thread APIs
Process.cs Adds [UnsupportedOSPlatform("haiku")] attributes to working set limit properties
Process.Haiku.cs Implements Haiku-specific process properties including boot time caching, start time, processor time tracking, and platform-specific helper methods
System.Diagnostics.Process.csproj Adds Haiku target framework and includes Haiku-specific source files and interop definitions
Interop.OS.cs Defines Haiku native interop for OS-level APIs including team/thread/area/system information structures and P/Invoke declarations
Interop.Libraries.cs Defines the libroot library constant for Haiku native library imports
Interop.Image.cs Defines Haiku native interop for image (module) information APIs

@@ -100,6 +101,7 @@ public ThreadPriorityLevel PriorityLevel
return _priorityLevel.Value;
}
[SupportedOSPlatform("windows")]
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

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

The setter is missing [SupportedOSPlatform("linux")] and [SupportedOSPlatform("freebsd")] attributes. While these platforms throw PlatformNotSupportedException in their implementations, the attributes on the public API should match the getter's attributes to maintain consistency and accuracy in the API surface declarations. The presence of the getter attribute for these platforms indicates the API should be callable, even if it throws at runtime.

Suggested change
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("linux")]
[SupportedOSPlatform("freebsd")]

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ignoring since it's not related to Haiku.

Comment thread src/libraries/Common/src/Interop/Haiku/Interop.OS.cs Outdated
Comment thread src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Haiku.cs Outdated
@trungnt2910 trungnt2910 force-pushed the dev/trungnt2910/haiku-lib-diagnostics branch from 3db3a8c to 822ecd1 Compare November 21, 2025 15:28
Comment thread src/libraries/Common/src/Interop/Haiku/Interop.Image.cs Outdated
Comment thread src/libraries/Common/src/Interop/Haiku/Interop.Image.cs Outdated
@trungnt2910 trungnt2910 force-pushed the dev/trungnt2910/haiku-lib-diagnostics branch from 822ecd1 to 7863bab Compare November 21, 2025 15:51
@trungnt2910 trungnt2910 force-pushed the dev/trungnt2910/haiku-lib-diagnostics branch 2 times, most recently from b7ee79c to f458cbd Compare November 22, 2025 02:53
@jeffhandley jeffhandley added the needs-author-action An issue or pull request that requires more info or actions from the author. label Feb 1, 2026
@trungnt2910
Copy link
Copy Markdown
Contributor Author

Still tracking, will take action soon.

@dotnet-policy-service dotnet-policy-service Bot removed needs-author-action An issue or pull request that requires more info or actions from the author. no-recent-activity labels Feb 16, 2026
@jeffhandley
Copy link
Copy Markdown
Member

@trungnt2910 I pushed 0ee9ed3 to my fork; it merges main into your branch and resolves the conflict. Feel free to cherry-pick that commit if it's helpful.

@trungnt2910 trungnt2910 force-pushed the dev/trungnt2910/haiku-lib-diagnostics branch from f458cbd to 5ed9cf0 Compare April 11, 2026 10:08
Copilot AI review requested due to automatic review settings April 11, 2026 10:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.

Comment thread src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Haiku.cs Outdated
Comment thread src/native/libs/configure.cmake
Comment thread src/native/libs/System.Native/pal_getosinfo.c
Comment thread src/libraries/Common/src/Interop/Haiku/Interop.OS.cs
Copilot AI review requested due to automatic review settings April 11, 2026 11:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 7 comments.

Comment thread src/native/libs/System.Native/pal_getosinfo.c
Comment thread src/native/libs/configure.cmake
Comment on lines +14 to +21
public static void GetProcessInfos(ref ArrayBuilder<ProcessInfo> builder, string? processNameFilter)
{
int cookie = 0;
Interop.OS.TeamInfo info;

while ((Interop.OS.GetNextTeamInfo(ref cookie, out info)) == 0)
{
ProcessInfo? pi = GetProcessInfoFromTeamInfo(ref info, processNameFilter);
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

Interop.OS.TeamInfo is declared as an unsafe struct (due to the fixed buffer). Declaring/using it here (and calling GetNextTeamInfo) requires an unsafe context; as written this method will fail to compile for the Haiku TFM. Mark the method as unsafe (or refactor the interop type to avoid requiring unsafe at call sites).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Haven't seen any build errors so far.

Comment on lines +73 to +81
internal static ProcessInfo? CreateProcessInfo(int pid, string? processNameFilter = null)
{
// Negative PIDs aren't valid
ArgumentOutOfRangeException.ThrowIfNegative(pid);

Interop.OS.TeamInfo info;
int status = Interop.OS.GetTeamInfo(pid, out info);

if (status != 0)
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

CreateProcessInfo uses Interop.OS.TeamInfo (an unsafe struct because of the fixed buffer). This method needs to be in an unsafe context (e.g., mark it unsafe) or the interop needs to be reshaped so callers don't need unsafe; otherwise the Haiku build will fail to compile.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Haven't seen any build errors so far.

Comment on lines +45 to +53
internal DateTime StartTimeCore
{
get
{
EnsureState(State.HaveNonExitedId);

Interop.OS.TeamInfo info;
int status = Interop.OS.GetTeamInfo(_processId, out info);

Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

StartTimeCore uses Interop.OS.TeamInfo (an unsafe struct because of the fixed buffer). This getter must be in an unsafe context (e.g., mark the property/getter as unsafe) or the interop needs to be reshaped; otherwise the Haiku TFM will not compile.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Haven't seen any build errors so far.

Copilot AI review requested due to automatic review settings April 11, 2026 11:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

@trungnt2910
Copy link
Copy Markdown
Contributor Author

trungnt2910 commented Apr 11, 2026

Local builds are succeeding in both Release and Debug mode (with all my other open PRs on native components applied).

@jkotas jkotas requested a review from adamsitnik April 11, 2026 14:29
Copilot AI review requested due to automatic review settings April 11, 2026 14:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings April 26, 2026 03:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

@am11
Copy link
Copy Markdown
Member

am11 commented Apr 26, 2026

LGTM!
cc @adamsitnik, PTAL.

trungnt2910 and others added 3 commits April 26, 2026 22:46
Add support for process/thread management functions in
`System.Diagnostics.Process` for Haiku.

This is required to build managed runtime libraries for Haiku as well as
running a simple "Hello, World!" application.

Co-authored-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>
Declare Haiku as a supported platform to MSBuild for all
`System.Diagnostics.Process` builds.

This prevents `CA1418` when using the `SupportedOSPlatform` attribute
with `haiku`.
@trungnt2910 trungnt2910 force-pushed the dev/trungnt2910/haiku-lib-diagnostics branch from 50691e9 to d460910 Compare April 26, 2026 12:47
Otherwise `clang`-based builds will complain.

`clang` treats the `enum`s as unsigned `int`, triggering a sign conversion warning.
Copilot AI review requested due to automatic review settings April 26, 2026 13:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Diagnostics.Process community-contribution Indicates that the PR has been added by a community member os-haiku

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants