Struct ProcThreadAttributeListBuilder
pub struct ProcThreadAttributeListBuilder<'a> { pub(in ::os::windows::process) attributes: BTreeMap<usize, ProcThreadAttributeValue>, pub(in ::os::windows::process) _lifetime_marker: PhantomData<&'a ()> }
Builder for constructing a ProcThreadAttributeList.
Fields
attributes: BTreeMap<usize, ProcThreadAttributeValue>_lifetime_marker: PhantomData<&'a ()>
Implementations
impl<'a> ProcThreadAttributeListBuilder<'a>
fn new() -> Selffn attribute<T>(self, attribute: usize, value: &'a T) -> SelfSets an attribute on the attribute list.
The
attributeparameter specifies the raw attribute to be set, while thevalueparameter holds the value associated with that attribute. Please refer to the [Windows documentation][1] for a list of valid attributes.Note
The maximum number of attributes is the value of
u32::MAX. If this limit is exceeded, the call toSelf::finishwill return anErrorindicating that the maximum number of attributes has been exceeded.Safety Note
Remember that improper use of attributes can lead to undefined behavior or security vulnerabilities. Always consult the documentation and ensure proper attribute values are used.
unsafe fn raw_attribute<T>(self, attribute: usize, value_ptr: *const T, value_size: usize) -> SelfSets a raw attribute on the attribute list.
This function is useful for setting attributes with pointers or sizes that cannot be derived directly from their values.
Safety
This function is marked as
unsafebecause it deals with raw pointers and sizes. It is the responsibility of the caller to ensure the value lives longer than the resultingProcThreadAttributeListas well as the validity of the size parameter.Example
#![feature(windows_process_extensions_raw_attribute)] use std::ffi::c_void; use std::os::windows::process::{CommandExt, ProcThreadAttributeList}; use std::os::windows::raw::HANDLE; use std::process::Command; #[repr(C)] pub struct COORD { pub X: i16, pub Y: i16, } unsafe extern "system" { fn CreatePipe( hreadpipe: *mut HANDLE, hwritepipe: *mut HANDLE, lppipeattributes: *const c_void, nsize: u32, ) -> i32; fn CreatePseudoConsole( size: COORD, hinput: HANDLE, houtput: HANDLE, dwflags: u32, phpc: *mut isize, ) -> i32; fn CloseHandle(hobject: HANDLE) -> i32; } let [mut input_read_side, mut output_write_side, mut output_read_side, mut input_write_side] = [unsafe { std::mem::zeroed::<HANDLE>() }; 4]; unsafe { CreatePipe(&mut input_read_side, &mut input_write_side, std::ptr::null(), 0); CreatePipe(&mut output_read_side, &mut output_write_side, std::ptr::null(), 0); } let size = COORD { X: 60, Y: 40 }; let mut h_pc = unsafe { std::mem::zeroed() }; unsafe { CreatePseudoConsole(size, input_read_side, output_write_side, 0, &mut h_pc) }; unsafe { CloseHandle(input_read_side) }; unsafe { CloseHandle(output_write_side) }; const PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE: usize = 131094; let attribute_list = unsafe { ProcThreadAttributeList::build() .raw_attribute( PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE, h_pc as *const c_void, size_of::<isize>(), ) .finish()? }; let mut child = Command::new("cmd").spawn_with_attributes(&attribute_list)?; # # child.kill()?; # Ok::<(), std::io::Error>(())fn finish(&self) -> Result<ProcThreadAttributeList<'a>>Finalizes the construction of the
ProcThreadAttributeList.Errors
Returns an error if the maximum number of attributes is exceeded or if there is an I/O error during initialization.
Trait Implementations
impl<'a> Clone for ProcThreadAttributeListBuilder<'a>
fn clone(&self) -> ProcThreadAttributeListBuilder<'a>
impl<'a> Debug for ProcThreadAttributeListBuilder<'a>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Auto Trait Implementations
impl<'a> !Send for ProcThreadAttributeListBuilder<'a>
impl<'a> !Sync for ProcThreadAttributeListBuilder<'a>
impl<'a> Freeze for ProcThreadAttributeListBuilder<'a>
impl<'a> RefUnwindSafe for ProcThreadAttributeListBuilder<'a>
impl<'a> Unpin for ProcThreadAttributeListBuilder<'a>
impl<'a> UnsafeUnpin for ProcThreadAttributeListBuilder<'a>
impl<'a> UnwindSafe for ProcThreadAttributeListBuilder<'a>
Blanket Implementations
impl<T> Any for ProcThreadAttributeListBuilder<'a>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for ProcThreadAttributeListBuilder<'a>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for ProcThreadAttributeListBuilder<'a>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for ProcThreadAttributeListBuilder<'a>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for ProcThreadAttributeListBuilder<'a>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> SizeHint for ProcThreadAttributeListBuilder<'a>
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for ProcThreadAttributeListBuilder<'a>
impl<T> ToOwned for ProcThreadAttributeListBuilder<'a>
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for ProcThreadAttributeListBuilder<'a>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for ProcThreadAttributeListBuilder<'a>
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for ProcThreadAttributeListBuilder<'a>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>