@@ -253,10 +253,28 @@ impl Command {
253253 attribute : usize ,
254254 value : T ,
255255 ) {
256- self . proc_thread_attributes . insert ( attribute, ProcThreadAttributeValue {
257- size : mem:: size_of :: < T > ( ) ,
258- data : Box :: new ( value) ,
259- } ) ;
256+ self . proc_thread_attributes . insert (
257+ attribute,
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 as isize ,
276+ } ) ,
277+ ) ;
260278 }
261279
262280 pub fn spawn (
@@ -907,11 +925,21 @@ impl Drop for ProcThreadAttributeList {
907925}
908926
909927/// Wrapper around the value data to be used as a Process Thread Attribute.
910- struct ProcThreadAttributeValue {
928+ struct ProcThreadAttributeValueData {
911929 data : Box < dyn Send + Sync > ,
912930 size : usize ,
913931}
914932
933+ struct ProcThreadAttributeValuePointer {
934+ pointer : isize , // using isize instead of *const c_void to have it sendable
935+ size : usize ,
936+ }
937+
938+ enum ProcThreadAttributeValue {
939+ Data ( ProcThreadAttributeValueData ) ,
940+ Pointer ( ProcThreadAttributeValuePointer ) ,
941+ }
942+
915943fn make_proc_thread_attribute_list (
916944 attributes : & BTreeMap < usize , ProcThreadAttributeValue > ,
917945) -> io:: Result < ProcThreadAttributeList > {
@@ -953,18 +981,38 @@ fn make_proc_thread_attribute_list(
953981 // It's theoretically possible for the attribute count to exceed a u32 value.
954982 // Therefore, we ensure that we don't add more attributes than the buffer was initialized for.
955983 for ( & attribute, value) in attributes. iter ( ) . take ( attribute_count as usize ) {
956- let value_ptr = ( & raw const * value. data ) as _ ;
957- cvt ( unsafe {
958- c:: UpdateProcThreadAttribute (
959- proc_thread_attribute_list. 0 . as_mut_ptr ( ) as _ ,
960- 0 ,
961- attribute,
962- value_ptr,
963- value. size ,
964- ptr:: null_mut ( ) ,
965- ptr:: null_mut ( ) ,
966- )
967- } ) ?;
984+ match value {
985+ ProcThreadAttributeValue :: Data ( value) => {
986+ let value_ptr = ( & raw const * value. data ) as _ ;
987+ cvt ( unsafe {
988+ c:: UpdateProcThreadAttribute (
989+ proc_thread_attribute_list. 0 . as_mut_ptr ( ) as _ ,
990+ 0 ,
991+ attribute,
992+ value_ptr,
993+ value. size ,
994+ ptr:: null_mut ( ) ,
995+ ptr:: null_mut ( ) ,
996+ )
997+ } ) ?;
998+ }
999+ ProcThreadAttributeValue :: Pointer ( value) => {
1000+ cvt (
1001+ unsafe {
1002+ #![ allow( fuzzy_provenance_casts) ]
1003+ c:: UpdateProcThreadAttribute (
1004+ proc_thread_attribute_list. 0 . as_mut_ptr ( ) as _ ,
1005+ 0 ,
1006+ attribute,
1007+ value. pointer as * const c_void ,
1008+ value. size ,
1009+ ptr:: null_mut ( ) ,
1010+ ptr:: null_mut ( ) ,
1011+ )
1012+ } ,
1013+ ) ?;
1014+ }
1015+ }
9681016 }
9691017
9701018 Ok ( proc_thread_attribute_list)
0 commit comments