Skip to content

Commit

Permalink
get SYS_gettid value specific to given architecture (and hopefully fi…
Browse files Browse the repository at this point in the history
…x the build for arm64)
  • Loading branch information
adamsitnik committed Jul 19, 2024
1 parent 0de6947 commit c126dd5
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,23 @@ public void TestPriorityLevelProperty_Unix()
Assert.Throws<PlatformNotSupportedException>(() => thread.PriorityLevel = level);
}

private static int GetCurrentThreadId() => syscall(186); // SYS_gettid
private static int GetCurrentThreadId()
{
// The magic values come from https://github.com/torvalds/linux.
int SYS_gettid = RuntimeInformation.ProcessArchitecture switch
{
Architecture.Arm => 224,
Architecture.Arm64 => 178,
Architecture.X86 => 224,
Architecture.X64 => 186,
Architecture.S390x => 236,
Architecture.Ppc64le => 207,
Architecture.RiscV64 => 178,
_ => 178,
};

syscall(SYS_gettid);
}

[DllImport("libc")]
private static extern int syscall(int nr);
Expand Down

0 comments on commit c126dd5

Please sign in to comment.