pty: Replace winapi with windows-sys (#8073)
This commit is contained in:
1 parent
cdb6bf7790
commit
568f4ffadc
8 files changed
+43
-47
No files matched your search
Generated
+1
-1
@@ -4422,7 +4422,7 @@ dependencies = [
|
||||
"shared_library",
|
||||
"shell-words",
|
||||
"smol",
|
||||
"winapi",
|
||||
"windows-sys 0.61.2",
|
||||
"winreg",
|
||||
]
|
||||
|
||||
|
||||
+6
-9
@@ -27,15 +27,12 @@ serde_support = ["serde"]
|
||||
bitflags.workspace = true
|
||||
lazy_static.workspace = true
|
||||
shared_library.workspace = true
|
||||
winapi = { workspace=true, features = [
|
||||
"winuser",
|
||||
"consoleapi",
|
||||
"handleapi",
|
||||
"fileapi",
|
||||
"namedpipeapi",
|
||||
"processenv",
|
||||
"synchapi",
|
||||
]}
|
||||
windows-sys = { workspace = true, features = [
|
||||
"Win32_Foundation",
|
||||
"Win32_System_Console",
|
||||
"Win32_System_Environment",
|
||||
"Win32_System_Threading",
|
||||
] }
|
||||
winreg.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -104,7 +104,7 @@ fn get_base_env() -> BTreeMap<OsString, EnvEntry> {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
use std::os::windows::ffi::OsStringExt;
|
||||
use winapi::um::processenv::ExpandEnvironmentStringsW;
|
||||
use windows_sys::Win32::System::Environment::ExpandEnvironmentStringsW;
|
||||
use winreg::enums::{RegType, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE};
|
||||
use winreg::types::FromRegValue;
|
||||
use winreg::{RegKey, RegValue};
|
||||
|
||||
+3
-3
@@ -46,6 +46,8 @@ use serde::{Deserialize, Serialize};
|
||||
use std::io::Result as IoResult;
|
||||
#[cfg(windows)]
|
||||
use std::os::windows::prelude::{AsRawHandle, RawHandle};
|
||||
#[cfg(windows)]
|
||||
use windows_sys::Win32::System::Threading::TerminateProcess;
|
||||
|
||||
pub mod cmdbuilder;
|
||||
pub use cmdbuilder::CommandBuilder;
|
||||
@@ -303,9 +305,7 @@ impl ChildKiller for ProcessSignaller {
|
||||
fn kill(&mut self) -> IoResult<()> {
|
||||
if let Some(handle) = &self.handle {
|
||||
unsafe {
|
||||
if winapi::um::processthreadsapi::TerminateProcess(handle.as_raw_handle() as _, 127)
|
||||
== 0
|
||||
{
|
||||
if TerminateProcess(handle.as_raw_handle(), 127) == 0 {
|
||||
return Err(std::io::Error::last_os_error());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::{Child, MasterPty, PtyPair, PtySize, PtySystem, SlavePty};
|
||||
use anyhow::Error;
|
||||
use filedescriptor::{FileDescriptor, Pipe};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use winapi::um::wincon::COORD;
|
||||
use windows_sys::Win32::System::Console::COORD;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ConPtySystem {}
|
||||
|
||||
+13
-14
@@ -5,11 +5,10 @@ use std::os::windows::io::{AsRawHandle, RawHandle};
|
||||
use std::pin::Pin;
|
||||
use std::sync::Mutex;
|
||||
use std::task::{Context, Poll};
|
||||
use winapi::shared::minwindef::DWORD;
|
||||
use winapi::um::minwinbase::STILL_ACTIVE;
|
||||
use winapi::um::processthreadsapi::*;
|
||||
use winapi::um::synchapi::WaitForSingleObject;
|
||||
use winapi::um::winbase::INFINITE;
|
||||
use windows_sys::Win32::Foundation::STILL_ACTIVE;
|
||||
use windows_sys::Win32::System::Threading::{
|
||||
GetExitCodeProcess, GetProcessId, TerminateProcess, WaitForSingleObject, INFINITE,
|
||||
};
|
||||
|
||||
pub mod conpty;
|
||||
mod procthreadattr;
|
||||
@@ -24,11 +23,11 @@ pub struct WinChild {
|
||||
|
||||
impl WinChild {
|
||||
fn is_complete(&mut self) -> IoResult<Option<ExitStatus>> {
|
||||
let mut status: DWORD = 0;
|
||||
let mut status: u32 = 0;
|
||||
let proc = self.proc.lock().unwrap().try_clone().unwrap();
|
||||
let res = unsafe { GetExitCodeProcess(proc.as_raw_handle() as _, &mut status) };
|
||||
let res = unsafe { GetExitCodeProcess(proc.as_raw_handle(), &mut status) };
|
||||
if res != 0 {
|
||||
if status == STILL_ACTIVE {
|
||||
if status == STILL_ACTIVE as u32 {
|
||||
Ok(None)
|
||||
} else {
|
||||
Ok(Some(ExitStatus::with_exit_code(status)))
|
||||
@@ -40,7 +39,7 @@ impl WinChild {
|
||||
|
||||
fn do_kill(&mut self) -> IoResult<()> {
|
||||
let proc = self.proc.lock().unwrap().try_clone().unwrap();
|
||||
let res = unsafe { TerminateProcess(proc.as_raw_handle() as _, 1) };
|
||||
let res = unsafe { TerminateProcess(proc.as_raw_handle(), 1) };
|
||||
let err = IoError::last_os_error();
|
||||
if res == 0 {
|
||||
Err(err)
|
||||
@@ -69,7 +68,7 @@ pub struct WinChildKiller {
|
||||
|
||||
impl ChildKiller for WinChildKiller {
|
||||
fn kill(&mut self) -> IoResult<()> {
|
||||
let res = unsafe { TerminateProcess(self.proc.as_raw_handle() as _, 1) };
|
||||
let res = unsafe { TerminateProcess(self.proc.as_raw_handle(), 1) };
|
||||
let err = IoError::last_os_error();
|
||||
if res == 0 {
|
||||
Err(err)
|
||||
@@ -95,10 +94,10 @@ impl Child for WinChild {
|
||||
}
|
||||
let proc = self.proc.lock().unwrap().try_clone().unwrap();
|
||||
unsafe {
|
||||
WaitForSingleObject(proc.as_raw_handle() as _, INFINITE);
|
||||
WaitForSingleObject(proc.as_raw_handle(), INFINITE);
|
||||
}
|
||||
let mut status: DWORD = 0;
|
||||
let res = unsafe { GetExitCodeProcess(proc.as_raw_handle() as _, &mut status) };
|
||||
let mut status: u32 = 0;
|
||||
let res = unsafe { GetExitCodeProcess(proc.as_raw_handle(), &mut status) };
|
||||
if res != 0 {
|
||||
Ok(ExitStatus::with_exit_code(status))
|
||||
} else {
|
||||
@@ -107,7 +106,7 @@ impl Child for WinChild {
|
||||
}
|
||||
|
||||
fn process_id(&self) -> Option<u32> {
|
||||
let res = unsafe { GetProcessId(self.proc.lock().unwrap().as_raw_handle() as _) };
|
||||
let res = unsafe { GetProcessId(self.proc.lock().unwrap().as_raw_handle()) };
|
||||
if res == 0 {
|
||||
None
|
||||
} else {
|
||||
|
||||
@@ -2,8 +2,10 @@ use crate::win::psuedocon::HPCON;
|
||||
use anyhow::{ensure, Error};
|
||||
use std::io::Error as IoError;
|
||||
use std::{mem, ptr};
|
||||
use winapi::shared::minwindef::DWORD;
|
||||
use winapi::um::processthreadsapi::*;
|
||||
use windows_sys::Win32::System::Threading::{
|
||||
DeleteProcThreadAttributeList, InitializeProcThreadAttributeList, UpdateProcThreadAttribute,
|
||||
LPPROC_THREAD_ATTRIBUTE_LIST,
|
||||
};
|
||||
|
||||
const PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE: usize = 0x00020016;
|
||||
|
||||
@@ -12,7 +14,7 @@ pub struct ProcThreadAttributeList {
|
||||
}
|
||||
|
||||
impl ProcThreadAttributeList {
|
||||
pub fn with_capacity(num_attributes: DWORD) -> Result<Self, Error> {
|
||||
pub fn with_capacity(num_attributes: u32) -> Result<Self, Error> {
|
||||
let mut bytes_required: usize = 0;
|
||||
unsafe {
|
||||
InitializeProcThreadAttributeList(
|
||||
|
||||
+13
-15
@@ -12,30 +12,28 @@ use std::os::windows::io::{AsRawHandle, FromRawHandle};
|
||||
use std::path::Path;
|
||||
use std::sync::Mutex;
|
||||
use std::{mem, ptr};
|
||||
use winapi::shared::minwindef::DWORD;
|
||||
use winapi::shared::winerror::{HRESULT, S_OK};
|
||||
use winapi::um::handleapi::*;
|
||||
use winapi::um::processthreadsapi::*;
|
||||
use winapi::um::winbase::{
|
||||
CREATE_UNICODE_ENVIRONMENT, EXTENDED_STARTUPINFO_PRESENT, STARTF_USESTDHANDLES, STARTUPINFOEXW,
|
||||
use windows_sys::core::HRESULT;
|
||||
use windows_sys::Win32::Foundation::{HANDLE, INVALID_HANDLE_VALUE, S_OK};
|
||||
use windows_sys::Win32::System::Console::COORD;
|
||||
use windows_sys::Win32::System::Threading::{
|
||||
CreateProcessW, CREATE_UNICODE_ENVIRONMENT, EXTENDED_STARTUPINFO_PRESENT, PROCESS_INFORMATION,
|
||||
STARTF_USESTDHANDLES, STARTUPINFOEXW,
|
||||
};
|
||||
use winapi::um::wincon::COORD;
|
||||
use winapi::um::winnt::HANDLE;
|
||||
|
||||
pub type HPCON = HANDLE;
|
||||
|
||||
pub const PSUEDOCONSOLE_INHERIT_CURSOR: DWORD = 0x1;
|
||||
pub const PSEUDOCONSOLE_RESIZE_QUIRK: DWORD = 0x2;
|
||||
pub const PSEUDOCONSOLE_WIN32_INPUT_MODE: DWORD = 0x4;
|
||||
pub const PSUEDOCONSOLE_INHERIT_CURSOR: u32 = 0x1;
|
||||
pub const PSEUDOCONSOLE_RESIZE_QUIRK: u32 = 0x2;
|
||||
pub const PSEUDOCONSOLE_WIN32_INPUT_MODE: u32 = 0x4;
|
||||
#[allow(dead_code)]
|
||||
pub const PSEUDOCONSOLE_PASSTHROUGH_MODE: DWORD = 0x8;
|
||||
pub const PSEUDOCONSOLE_PASSTHROUGH_MODE: u32 = 0x8;
|
||||
|
||||
shared_library!(ConPtyFuncs,
|
||||
pub fn CreatePseudoConsole(
|
||||
size: COORD,
|
||||
hInput: HANDLE,
|
||||
hOutput: HANDLE,
|
||||
flags: DWORD,
|
||||
flags: u32,
|
||||
hpc: *mut HPCON
|
||||
) -> HRESULT,
|
||||
pub fn ResizePseudoConsole(hpc: HPCON, size: COORD) -> HRESULT,
|
||||
@@ -82,8 +80,8 @@ impl PsuedoCon {
|
||||
let result = unsafe {
|
||||
(CONPTY.CreatePseudoConsole)(
|
||||
size,
|
||||
input.as_raw_handle() as _,
|
||||
output.as_raw_handle() as _,
|
||||
input.as_raw_handle(),
|
||||
output.as_raw_handle(),
|
||||
PSUEDOCONSOLE_INHERIT_CURSOR
|
||||
| PSEUDOCONSOLE_RESIZE_QUIRK
|
||||
| PSEUDOCONSOLE_WIN32_INPUT_MODE,
|
||||
|
||||
Reference in new issue
Block a user