diff options
author | Christian Duerr <contact@christianduerr.com> | 2021-01-01 05:07:39 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-01 05:07:39 +0000 |
commit | 8ed72cc065255007a7f0687e3b8a540e8c6202c6 (patch) | |
tree | 97be52ae4c288fcfeb849d1f97f7a5efc9c2dab1 /alacritty_terminal/src/tty/windows/conpty.rs | |
parent | 1723e30d25f0c6068f9532448b016a89aa491a95 (diff) | |
download | alacritty-8ed72cc065255007a7f0687e3b8a540e8c6202c6.tar.gz alacritty-8ed72cc065255007a7f0687e3b8a540e8c6202c6.zip |
Remove Windows WinPTY backend
Diffstat (limited to 'alacritty_terminal/src/tty/windows/conpty.rs')
-rw-r--r-- | alacritty_terminal/src/tty/windows/conpty.rs | 65 |
1 files changed, 8 insertions, 57 deletions
diff --git a/alacritty_terminal/src/tty/windows/conpty.rs b/alacritty_terminal/src/tty/windows/conpty.rs index 5469c7fe..de3d8d4e 100644 --- a/alacritty_terminal/src/tty/windows/conpty.rs +++ b/alacritty_terminal/src/tty/windows/conpty.rs @@ -6,10 +6,10 @@ use std::ptr; use mio_anonymous_pipes::{EventedAnonRead, EventedAnonWrite}; use winapi::shared::basetsd::{PSIZE_T, SIZE_T}; -use winapi::shared::minwindef::{BYTE, DWORD}; -use winapi::shared::ntdef::{HANDLE, HRESULT, LPWSTR}; +use winapi::shared::minwindef::BYTE; +use winapi::shared::ntdef::LPWSTR; use winapi::shared::winerror::S_OK; -use winapi::um::libloaderapi::{GetModuleHandleA, GetProcAddress}; +use winapi::um::consoleapi::{ClosePseudoConsole, CreatePseudoConsole, ResizePseudoConsole}; use winapi::um::processthreadsapi::{ CreateProcessW, InitializeProcThreadAttributeList, UpdateProcThreadAttribute, PROCESS_INFORMATION, STARTUPINFOW, @@ -23,52 +23,9 @@ use crate::term::SizeInfo; use crate::tty::windows::child::ChildExitWatcher; use crate::tty::windows::{cmdline, win32_string, Pty}; -// TODO: Replace with winapi's implementation. This cannot be -// done until a safety net is in place for versions of Windows -// that do not support the ConPTY api, as such versions will -// pass unit testing - but fail to actually function. -/// Dynamically-loaded Pseudoconsole API from kernel32.dll. -/// -/// The field names are deliberately PascalCase as this matches -/// the defined symbols in kernel32 and also is the convention -/// that the `winapi` crate follows. -#[allow(non_snake_case)] -struct ConptyApi { - CreatePseudoConsole: - unsafe extern "system" fn(COORD, HANDLE, HANDLE, DWORD, *mut HPCON) -> HRESULT, - ResizePseudoConsole: unsafe extern "system" fn(HPCON, COORD) -> HRESULT, - ClosePseudoConsole: unsafe extern "system" fn(HPCON), -} - -impl ConptyApi { - /// Load the API or None if it cannot be found. - pub fn new() -> Option<Self> { - // Unsafe because windows API calls. - unsafe { - let hmodule = GetModuleHandleA("kernel32\0".as_ptr() as _); - assert!(!hmodule.is_null()); - - let cpc = GetProcAddress(hmodule, "CreatePseudoConsole\0".as_ptr() as _); - let rpc = GetProcAddress(hmodule, "ResizePseudoConsole\0".as_ptr() as _); - let clpc = GetProcAddress(hmodule, "ClosePseudoConsole\0".as_ptr() as _); - - if cpc.is_null() || rpc.is_null() || clpc.is_null() { - None - } else { - Some(Self { - CreatePseudoConsole: mem::transmute(cpc), - ResizePseudoConsole: mem::transmute(rpc), - ClosePseudoConsole: mem::transmute(clpc), - }) - } - } - } -} - /// RAII Pseudoconsole. pub struct Conpty { pub handle: HPCON, - api: ConptyApi, } impl Drop for Conpty { @@ -77,20 +34,14 @@ impl Drop for Conpty { // conout pipe has already been dropped by this point. // // See PR #3084 and https://docs.microsoft.com/en-us/windows/console/closepseudoconsole. - unsafe { (self.api.ClosePseudoConsole)(self.handle) } + unsafe { ClosePseudoConsole(self.handle) } } } // The ConPTY handle can be sent between threads. unsafe impl Send for Conpty {} -pub fn new<C>(config: &Config<C>, size: &SizeInfo, _window_id: Option<usize>) -> Option<Pty> { - if config.winpty_backend { - return None; - } - - let api = ConptyApi::new()?; - +pub fn new<C>(config: &Config<C>, size: &SizeInfo) -> Option<Pty> { let mut pty_handle = 0 as HPCON; // Passing 0 as the size parameter allows the "system default" buffer @@ -105,7 +56,7 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo, _window_id: Option<usize>) -> // Create the Pseudo Console, using the pipes. let result = unsafe { - (api.CreatePseudoConsole)( + CreatePseudoConsole( coord, conin_pty_handle.into_raw_handle(), conout_pty_handle.into_raw_handle(), @@ -213,7 +164,7 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo, _window_id: Option<usize>) -> let conout = EventedAnonRead::new(conout); let child_watcher = ChildExitWatcher::new(proc_info.hProcess).unwrap(); - let conpty = Conpty { handle: pty_handle, api }; + let conpty = Conpty { handle: pty_handle }; Some(Pty::new(conpty, conout, conin, child_watcher)) } @@ -226,7 +177,7 @@ fn panic_shell_spawn() { impl OnResize for Conpty { fn on_resize(&mut self, sizeinfo: &SizeInfo) { if let Some(coord) = coord_from_sizeinfo(sizeinfo) { - let result = unsafe { (self.api.ResizePseudoConsole)(self.handle, coord) }; + let result = unsafe { ResizePseudoConsole(self.handle, coord) }; assert_eq!(result, S_OK); } } |