windows: get pid with win32 api (#8785)

While trying to get mouse/keyboard support in for Windows I ran into a
stack overflow issue related to the pid being `-1`. Getting the proper
process ID seems to fix it.

Release Notes:

- Fixed stack overflow on Windows
This commit is contained in:
Ezekiel Warren 2024-03-03 11:42:36 -08:00 committed by GitHub
parent a5eab29662
commit 36d9b3d483
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 1 deletions

1
Cargo.lock generated
View file

@ -9463,6 +9463,7 @@ dependencies = [
"theme", "theme",
"thiserror", "thiserror",
"util", "util",
"windows 0.53.0",
] ]
[[package]] [[package]]

View file

@ -30,5 +30,11 @@ theme.workspace = true
thiserror.workspace = true thiserror.workspace = true
util.workspace = true util.workspace = true
[target.'cfg(windows)'.dependencies.windows]
version = "0.53.0"
features = [
"Win32_System_Threading",
]
[dev-dependencies] [dev-dependencies]
rand.workspace = true rand.workspace = true

View file

@ -670,7 +670,7 @@ impl Terminal {
let mut pid = unsafe { libc::tcgetpgrp(self.shell_fd as i32) }; let mut pid = unsafe { libc::tcgetpgrp(self.shell_fd as i32) };
// todo("windows") // todo("windows")
#[cfg(windows)] #[cfg(windows)]
let mut pid = -1; let mut pid = unsafe { windows::Win32::System::Threading::GetCurrentProcessId() } as i32;
if pid < 0 { if pid < 0 {
pid = self.shell_pid as i32; pid = self.shell_pid as i32;
} }