@@ -255,7 +255,19 @@ impl Command {
255
255
) {
256
256
self . proc_thread_attributes . insert (
257
257
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 } ) ,
259
271
) ;
260
272
}
261
273
@@ -889,11 +901,21 @@ impl Drop for ProcThreadAttributeList {
889
901
}
890
902
891
903
/// Wrapper around the value data to be used as a Process Thread Attribute.
892
- struct ProcThreadAttributeValue {
904
+ struct ProcThreadAttributeValueData {
893
905
data : Box < dyn Send + Sync > ,
894
906
size : usize ,
895
907
}
896
908
909
+ struct ProcThreadAttributeValuePointer {
910
+ pointer : * const c_void ,
911
+ size : usize ,
912
+ }
913
+
914
+ enum ProcThreadAttributeValue {
915
+ Data ( ProcThreadAttributeValueData ) ,
916
+ Pointer ( ProcThreadAttributeValuePointer ) ,
917
+ }
918
+
897
919
fn make_proc_thread_attribute_list (
898
920
attributes : & BTreeMap < usize , ProcThreadAttributeValue > ,
899
921
) -> io:: Result < ProcThreadAttributeList > {
@@ -935,18 +957,36 @@ fn make_proc_thread_attribute_list(
935
957
// It's theoretically possible for the attribute count to exceed a u32 value.
936
958
// Therefore, we ensure that we don't add more attributes than the buffer was initialized for.
937
959
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
+
950
990
}
951
991
952
992
Ok ( proc_thread_attribute_list)
0 commit comments