libc icon indicating copy to clipboard operation
libc copied to clipboard

Missing kill function in libc on Windows

Open chuacw opened this issue 1 year ago • 7 comments

The kill function is missing in libc on Windows

chuacw avatar Jul 02 '24 15:07 chuacw

I did not find it in MSDN.

devnexen avatar Jul 03 '24 22:07 devnexen

The implementation is missing in libc's implementation on Windows.

chuacw avatar Jul 04 '24 00:07 chuacw

libc crate is a thin wrapper around platform's C libc, like glibc, msvcrt, musl, BSD libc. There is no corresponding kill functions on Windows MSVC libc. What #3764 does is adding a wrong abstraction. Take a look at the kill function signature:

int kill(pid_t pid, int sig);

What does pid_t mean on Windows? Windows only uses HANDLE.

If you want to kill a process on Windows, you should use either:

  • std::process::Child::kill if you spawn a std::Command
  • or #[cfg(windows)] your code and use specific lower level windows APIs that crates like winapi or windows-sys exposed.

ptrca avatar Jul 04 '24 01:07 ptrca

The initial PR used a different signature than expected because of styling issues that causes a ci failure when I used the same signature. It has now been fixed.

The added kill function is to provide parity with the existing kill function and usage on other platforms.

Thanks.

chuacw avatar Jul 04 '24 03:07 chuacw

Scope of libc states that this crate wraps "VS CRT libraries" and is "distinct from the winapi crate as well as bindings to common system DLLs found on Windows".

Therefore we should not be depending on winapi nor duplicating their bindings.

ChrisDenton avatar Jul 04 '24 03:07 ChrisDenton

See also point 3 Unresolved questions

chuacw avatar Jul 04 '24 05:07 chuacw

Even if it is a yes, then only bare Win32 APIs will be exposed, not compositions/emulations of them.

ptrca avatar Jul 04 '24 07:07 ptrca

Thank you for the enthusiasm here. However, as pointed out, this crate only provides bindings to system libraries (and some very minimal functions that reimplement C macros). It is even a bit lower level than windows, which makes use of Rust features to provide a much more user-friendly API.

A crate that provides a POSIX API for Windows is a very interesting idea; this just isn't the place for it (something like a fork of nix that supports Windows would be cool).

tgross35 avatar Aug 29 '24 09:08 tgross35