@@ -255,7 +255,19 @@ 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 { size : mem:: size_of :: < T > ( ) , data : Box :: new ( value) } ) ,
259+ ) ;
260+ }
261+
262+ pub unsafe fn raw_attribute_ptr (
263+ & mut self ,
264+ attribute : usize ,
265+ value_ptr : * const c_void ,
266+ value_size : usize ,
267+ ) {
268+ self . proc_thread_attributes . insert (
269+ attribute,
270+ ProcThreadAttributeValue :: Pointer ( ProcThreadAttributeValuePointer { size : value_size, pointer : value_ptr } ) ,
259271 ) ;
260272 }
261273
@@ -889,11 +901,21 @@ impl Drop for ProcThreadAttributeList {
889901}
890902
891903/// Wrapper around the value data to be used as a Process Thread Attribute.
892- struct ProcThreadAttributeValue {
904+ struct ProcThreadAttributeValueData {
893905 data : Box < dyn Send + Sync > ,
894906 size : usize ,
895907}
896908
909+ struct ProcThreadAttributeValuePointer {
910+ pointer : * const c_void ,
911+ size : usize ,
912+ }
913+
914+ enum ProcThreadAttributeValue {
915+ Data ( ProcThreadAttributeValueData ) ,
916+ Pointer ( ProcThreadAttributeValuePointer ) ,
917+ }
918+
897919fn make_proc_thread_attribute_list (
898920 attributes : & BTreeMap < usize , ProcThreadAttributeValue > ,
899921) -> io:: Result < ProcThreadAttributeList > {
@@ -935,18 +957,36 @@ fn make_proc_thread_attribute_list(
935957 // It's theoretically possible for the attribute count to exceed a u32 value.
936958 // Therefore, we ensure that we don't add more attributes than the buffer was initialized for.
937959 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- } ) ?;
960+ match value {
961+ ProcThreadAttributeValue :: Data ( value) => {
962+ let value_ptr = core:: ptr:: addr_of!( * value. data) as _ ;
963+ cvt ( unsafe {
964+ c:: UpdateProcThreadAttribute (
965+ proc_thread_attribute_list. 0 . as_mut_ptr ( ) as _ ,
966+ 0 ,
967+ attribute,
968+ value_ptr,
969+ value. size ,
970+ ptr:: null_mut ( ) ,
971+ ptr:: null_mut ( ) ,
972+ )
973+ } ) ?;
974+ }
975+ ProcThreadAttributeValue :: Pointer ( value) => {
976+ cvt ( unsafe {
977+ c:: UpdateProcThreadAttribute (
978+ proc_thread_attribute_list. 0 . as_mut_ptr ( ) as _ ,
979+ 0 ,
980+ attribute,
981+ value. pointer ,
982+ value. size ,
983+ ptr:: null_mut ( ) ,
984+ ptr:: null_mut ( ) ,
985+ )
986+ } ) ?;
987+ }
988+ }
989+
950990 }
951991
952992 Ok ( proc_thread_attribute_list)
0 commit comments