From 36d9b3d48364e7423a3c660ba5dc00633c33cfa6 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Sun, 3 Mar 2024 11:42:36 -0800 Subject: [PATCH] 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 --- Cargo.lock | 1 + crates/terminal/Cargo.toml | 6 ++++++ crates/terminal/src/terminal.rs | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 34c59338446558f086dd6e22aa24069f12423e6d..5e1eff04a840f30fc163946dc694f7d2e5b1e05e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9463,6 +9463,7 @@ dependencies = [ "theme", "thiserror", "util", + "windows 0.53.0", ] [[package]] diff --git a/crates/terminal/Cargo.toml b/crates/terminal/Cargo.toml index 7123264948225481e6c3f27622e15d3d6dd99a63..c41168d639f163eeec84e01c8b3565f0532d3938 100644 --- a/crates/terminal/Cargo.toml +++ b/crates/terminal/Cargo.toml @@ -30,5 +30,11 @@ theme.workspace = true thiserror.workspace = true util.workspace = true +[target.'cfg(windows)'.dependencies.windows] +version = "0.53.0" +features = [ + "Win32_System_Threading", +] + [dev-dependencies] rand.workspace = true diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 2ae53d40d2260e01db54b9e67c869f43d9381444..342d4c6cc20868885c0a9f27ff0561dfa4116088 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -670,7 +670,7 @@ impl Terminal { let mut pid = unsafe { libc::tcgetpgrp(self.shell_fd as i32) }; // todo("windows") #[cfg(windows)] - let mut pid = -1; + let mut pid = unsafe { windows::Win32::System::Threading::GetCurrentProcessId() } as i32; if pid < 0 { pid = self.shell_pid as i32; }