mirror of
https://github.com/openai/codex.git
synced 2026-11-10 16:44:38 +00:00
## Why `codex-utils-pty` and `codex-windows-sandbox` were the remaining crates in `codex-rs` that still overrode the workspace's Rust 2024 edition. Moving them forward in a separate PR keeps the baseline edition update isolated from the follow-on Bazel clippy workflow in #15955, while making linting and formatting behavior consistent with the rest of the workspace. This PR also needs Cargo and Bazel to agree on the edition for `codex-windows-sandbox`. Without the Bazel-side sync, the experimental Bazel app-server builds fail once they compile `windows-sandbox-rs`. ## What changed - switch `codex-rs/utils/pty` and `codex-rs/windows-sandbox-rs` to `edition = "2024"` - update `codex-utils-pty` callsites and tests to use the collapsed `if let` form that Clippy expects under the new edition - fix the Rust 2024 fallout in `windows-sandbox-rs`, including the reserved `gen` identifier, `unsafe extern` requirements, and new Clippy findings that surfaced under the edition bump - keep the edition bump separate from a larger unsafe cleanup by temporarily allowing `unsafe_op_in_unsafe_fn` in the Windows entrypoint modules that now report it under Rust 2024 - update `codex-rs/windows-sandbox-rs/BUILD.bazel` to `crate_edition = "2024"` so Bazel compiles the crate with the same edition as Cargo --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/openai/codex/pull/15954). * #15976 * #15955 * __->__ #15954
80 lines
2.7 KiB
Rust
80 lines
2.7 KiB
Rust
//! Low-level Windows thread attribute helpers used by ConPTY spawn.
|
||
//!
|
||
//! This module wraps the Win32 `PROC_THREAD_ATTRIBUTE_LIST` APIs so ConPTY handles can
|
||
//! be attached to a child process. It is ConPTY‑specific and used in both legacy and
|
||
//! elevated unified_exec paths when spawning a PTY‑backed process.
|
||
|
||
use std::io;
|
||
use windows_sys::Win32::Foundation::GetLastError;
|
||
use windows_sys::Win32::System::Threading::DeleteProcThreadAttributeList;
|
||
use windows_sys::Win32::System::Threading::InitializeProcThreadAttributeList;
|
||
use windows_sys::Win32::System::Threading::LPPROC_THREAD_ATTRIBUTE_LIST;
|
||
use windows_sys::Win32::System::Threading::UpdateProcThreadAttribute;
|
||
|
||
const PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE: usize = 0x00020016;
|
||
|
||
/// RAII wrapper for Windows PROC_THREAD_ATTRIBUTE_LIST.
|
||
pub struct ProcThreadAttributeList {
|
||
buffer: Vec<u8>,
|
||
}
|
||
|
||
impl ProcThreadAttributeList {
|
||
/// Allocate and initialize a thread attribute list.
|
||
pub fn new(attr_count: u32) -> io::Result<Self> {
|
||
let mut size: usize = 0;
|
||
unsafe {
|
||
InitializeProcThreadAttributeList(std::ptr::null_mut(), attr_count, 0, &mut size);
|
||
}
|
||
if size == 0 {
|
||
return Err(io::Error::from_raw_os_error(unsafe {
|
||
GetLastError() as i32
|
||
}));
|
||
}
|
||
let mut buffer = vec![0u8; size];
|
||
let list = buffer.as_mut_ptr() as LPPROC_THREAD_ATTRIBUTE_LIST;
|
||
let ok = unsafe { InitializeProcThreadAttributeList(list, attr_count, 0, &mut size) };
|
||
if ok == 0 {
|
||
return Err(io::Error::from_raw_os_error(unsafe {
|
||
GetLastError() as i32
|
||
}));
|
||
}
|
||
Ok(Self { buffer })
|
||
}
|
||
|
||
/// Return a mutable pointer to the attribute list for Win32 APIs.
|
||
pub fn as_mut_ptr(&mut self) -> LPPROC_THREAD_ATTRIBUTE_LIST {
|
||
self.buffer.as_mut_ptr() as LPPROC_THREAD_ATTRIBUTE_LIST
|
||
}
|
||
|
||
/// Attach a ConPTY handle to the attribute list.
|
||
pub fn set_pseudoconsole(&mut self, hpc: isize) -> io::Result<()> {
|
||
let list = self.as_mut_ptr();
|
||
let mut hpc_value = hpc;
|
||
let ok = unsafe {
|
||
UpdateProcThreadAttribute(
|
||
list,
|
||
0,
|
||
PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE,
|
||
(&mut hpc_value as *mut isize).cast(),
|
||
std::mem::size_of::<isize>(),
|
||
std::ptr::null_mut(),
|
||
std::ptr::null_mut(),
|
||
)
|
||
};
|
||
if ok == 0 {
|
||
return Err(io::Error::from_raw_os_error(unsafe {
|
||
GetLastError() as i32
|
||
}));
|
||
}
|
||
Ok(())
|
||
}
|
||
}
|
||
|
||
impl Drop for ProcThreadAttributeList {
|
||
fn drop(&mut self) {
|
||
unsafe {
|
||
DeleteProcThreadAttributeList(self.as_mut_ptr());
|
||
}
|
||
}
|
||
}
|