@@ -255,7 +255,25 @@ impl Command {
255255 ) {
256256 self . proc_thread_attributes . insert (
257257 attribute,
258- ProcThreadAttributeValue { size : mem:: size_of :: < T > ( ) , data : Box :: new ( value) } ,
258+ ProcThreadAttributeValue :: Data ( ProcThreadAttributeValueData {
259+ size : mem:: size_of :: < T > ( ) ,
260+ data : Box :: new ( value) ,
261+ } ) ,
262+ ) ;
263+ }
264+
265+ pub unsafe fn raw_attribute_ptr (
266+ & mut self ,
267+ attribute : usize ,
268+ value_ptr : * const c_void ,
269+ value_size : usize ,
270+ ) {
271+ self . proc_thread_attributes . insert (
272+ attribute,
273+ ProcThreadAttributeValue :: Pointer ( ProcThreadAttributeValuePointer {
274+ size : value_size,
275+ pointer : value_ptr,
276+ } ) ,
259277 ) ;
260278 }
261279
@@ -889,11 +907,21 @@ impl Drop for ProcThreadAttributeList {
889907}
890908
891909/// Wrapper around the value data to be used as a Process Thread Attribute.
892- struct ProcThreadAttributeValue {
910+ struct ProcThreadAttributeValueData {
893911 data : Box < dyn Send + Sync > ,
894912 size : usize ,
895913}
896914
915+ struct ProcThreadAttributeValuePointer {
916+ pointer : * const c_void ,
917+ size : usize ,
918+ }
919+
920+ enum ProcThreadAttributeValue {
921+ Data ( ProcThreadAttributeValueData ) ,
922+ Pointer ( ProcThreadAttributeValuePointer ) ,
923+ }
924+
897925fn make_proc_thread_attribute_list (
898926 attributes : & BTreeMap < usize , ProcThreadAttributeValue > ,
899927) -> io:: Result < ProcThreadAttributeList > {
@@ -935,18 +963,35 @@ fn make_proc_thread_attribute_list(
935963 // It's theoretically possible for the attribute count to exceed a u32 value.
936964 // Therefore, we ensure that we don't add more attributes than the buffer was initialized for.
937965 for ( & attribute, value) in attributes. iter ( ) . take ( attribute_count as usize ) {
938- let value_ptr = core:: ptr:: addr_of!( * value. data) as _ ;
939- cvt ( unsafe {
940- c:: UpdateProcThreadAttribute (
941- proc_thread_attribute_list. 0 . as_mut_ptr ( ) as _ ,
942- 0 ,
943- attribute,
944- value_ptr,
945- value. size ,
946- ptr:: null_mut ( ) ,
947- ptr:: null_mut ( ) ,
948- )
949- } ) ?;
966+ match value {
967+ ProcThreadAttributeValue :: Data ( value) => {
968+ let value_ptr = core:: ptr:: addr_of!( * value. data) as _ ;
969+ cvt ( unsafe {
970+ c:: UpdateProcThreadAttribute (
971+ proc_thread_attribute_list. 0 . as_mut_ptr ( ) as _ ,
972+ 0 ,
973+ attribute,
974+ value_ptr,
975+ value. size ,
976+ ptr:: null_mut ( ) ,
977+ ptr:: null_mut ( ) ,
978+ )
979+ } ) ?;
980+ }
981+ ProcThreadAttributeValue :: Pointer ( value) => {
982+ cvt ( unsafe {
983+ c:: UpdateProcThreadAttribute (
984+ proc_thread_attribute_list. 0 . as_mut_ptr ( ) as _ ,
985+ 0 ,
986+ attribute,
987+ value. pointer ,
988+ value. size ,
989+ ptr:: null_mut ( ) ,
990+ ptr:: null_mut ( ) ,
991+ )
992+ } ) ?;
993+ }
994+ }
950995 }
951996
952997 Ok ( proc_thread_attribute_list)
0 commit comments