Skip to content

Migrate libpsl-native to managed/libc P/Invoke#27668

Draft
adityapatwardhan wants to merge 1 commit into
PowerShell:masterfrom
adityapatwardhan:ReplaceLibPSLNative
Draft

Migrate libpsl-native to managed/libc P/Invoke#27668
adityapatwardhan wants to merge 1 commit into
PowerShell:masterfrom
adityapatwardhan:ReplaceLibPSLNative

Conversation

@adityapatwardhan

Copy link
Copy Markdown
Member

Replace the low-risk libpsl-native functions (those not requiring stat/passwd struct marshalling) with pure managed code and direct LibraryImport("libc") calls, following the engine/Interop/Windows convention with a parallel engine/Interop/Unix folder.

Migrated:

  • GetErrorCategory -> managed errno->ErrorCategory table
  • CreateSymLink/CreateHardLink -> libc symlink/link
  • IsExecutable -> libc access(path, X_OK)
  • KillProcess -> libc kill(pid, SIGKILL)
  • WaitPid -> libc waitpid
  • GetCurrentThreadId -> libc gettid (Linux) / pthread_threadid_np (macOS)
  • SetDate -> libc settimeofday (via DateTimeOffset; drops UnixTm struct)
  • Syslog Open/SysLog/Close -> libc openlog/syslog/closelog

Interop.Unix is compiled only on non-Windows (per csproj), so the consuming bodies in CorePsPlatform are guarded with #if UNIX. The remaining libpsl-native imports (stat, passwd/group, GetUserFromPid, ForkAndExecProcess) are deferred to later phases.

Verified: Windows build and cross-compiled linux-x64 build both pass.

PR Summary

PR Context

PR Checklist

Replace the low-risk libpsl-native functions (those not requiring
stat/passwd struct marshalling) with pure managed code and direct
LibraryImport("libc") calls, following the engine/Interop/Windows
convention with a parallel engine/Interop/Unix folder.

Migrated:
- GetErrorCategory -> managed errno->ErrorCategory table
- CreateSymLink/CreateHardLink -> libc symlink/link
- IsExecutable -> libc access(path, X_OK)
- KillProcess -> libc kill(pid, SIGKILL)
- WaitPid -> libc waitpid
- GetCurrentThreadId -> libc gettid (Linux) / pthread_threadid_np (macOS)
- SetDate -> libc settimeofday (via DateTimeOffset; drops UnixTm struct)
- Syslog Open/SysLog/Close -> libc openlog/syslog/closelog

Interop.Unix is compiled only on non-Windows (per csproj), so the
consuming bodies in CorePsPlatform are guarded with #if UNIX. The
remaining libpsl-native imports (stat, passwd/group, GetUserFromPid,
ForkAndExecProcess) are deferred to later phases.

Verified: Windows build and cross-compiled linux-x64 build both pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant