@@ -253,10 +253,27 @@ impl Command {
253
253
attribute : usize ,
254
254
value : T ,
255
255
) {
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
+ } ) ,
260
277
}
261
278
262
279
pub fn spawn (
@@ -907,11 +924,21 @@ impl Drop for ProcThreadAttributeList {
907
924
}
908
925
909
926
/// Wrapper around the value data to be used as a Process Thread Attribute.
910
- struct ProcThreadAttributeValue {
927
+ struct ProcThreadAttributeValueData {
911
928
data : Box < dyn Send + Sync > ,
912
929
size : usize ,
913
930
}
914
931
932
+ struct ProcThreadAttributeValuePointer {
933
+ pointer : isize , // using isize instead of *const c_void to have it sendable
934
+ size : usize ,
935
+ }
936
+
937
+ enum ProcThreadAttributeValue {
938
+ Data ( ProcThreadAttributeValueData ) ,
939
+ Pointer ( ProcThreadAttributeValuePointer ) ,
940
+ }
941
+
915
942
fn make_proc_thread_attribute_list (
916
943
attributes : & BTreeMap < usize , ProcThreadAttributeValue > ,
917
944
) -> io:: Result < ProcThreadAttributeList > {
@@ -953,18 +980,38 @@ fn make_proc_thread_attribute_list(
953
980
// It's theoretically possible for the attribute count to exceed a u32 value.
954
981
// Therefore, we ensure that we don't add more attributes than the buffer was initialized for.
955
982
for ( & attribute, value) in attributes. iter ( ) . take ( attribute_count as usize ) {
956
- let value_ptr = core:: ptr:: addr_of!( * 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
- } ) ?;
983
+ match value {
984
+ ProcThreadAttributeValue :: Data ( value) => {
985
+ let value_ptr = core:: ptr:: addr_of!( * value. data) as _ ;
986
+ cvt ( unsafe {
987
+ c:: UpdateProcThreadAttribute (
988
+ proc_thread_attribute_list. 0 . as_mut_ptr ( ) as _ ,
989
+ 0 ,
990
+ attribute,
991
+ value_ptr,
992
+ value. size ,
993
+ ptr:: null_mut ( ) ,
994
+ ptr:: null_mut ( ) ,
995
+ )
996
+ } ) ?;
997
+ }
998
+ ProcThreadAttributeValue :: Pointer ( value) => {
999
+ cvt (
1000
+ unsafe {
1001
+ #![ allow( fuzzy_provenance_casts) ]
1002
+ c:: UpdateProcThreadAttribute (
1003
+ proc_thread_attribute_list. 0 . as_mut_ptr ( ) as _ ,
1004
+ 0 ,
1005
+ attribute,
1006
+ value. pointer as * const c_void ,
1007
+ value. size ,
1008
+ ptr:: null_mut ( ) ,
1009
+ ptr:: null_mut ( ) ,
1010
+ )
1011
+ } ,
1012
+ ) ?;
1013
+ }
1014
+ }
968
1015
}
969
1016
970
1017
Ok ( proc_thread_attribute_list)
0 commit comments