-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking Issue for windows_process_extensions_raw_attribute
#114854
Comments
Now that there's an initial implementation on nightly people can start experimenting with it. One thing worth exploring is if there's a better API here. Notably attribute lists can potentially be reused between calls. They are also optionally used for thread creation as well as creating a process (though this is not yet implemented). This suggests it might be helpful to have a The simplest thing would be something that just wraps How ever it is implemented, it would also still be very unsafe. An attribute value can contain a struct which itself contains pointer to other data. It would be necessary for the user (or a library) to ensure that data outlives the attribute list. The same goes for other resources, e.g. ensuring |
I currently see an issue with the new With the current interface, it is not possible to pass a pointer value as an attribute, or at least it seems so. This is required, for example, when trying to start a process attached to a pseudo-console, which is weird since this was the original intent of #88193. Does anyone see any way the interface could be used to, for example, pass a pseudo-console handle to it? |
Any news on this topic? |
I was experimenting with working with pseudo consoles in Windows and tried to use this feature, but found that it was not available for this reason. Since However, it is not possible to handle cases where pub trait CommandExt {
unsafe fn raw_attribute_ptr(
&mut self,
attribute: usize,
ptr: PointerLikeType,
) -> &mut process::Command;
} Of course, this is a more dangerous function than There are several points of question.
|
@kazatsuyu do you know of any place where a raw pointer is used in a std function that interfaces with a system API? |
This also triped me up. |
For example, the Windows expects a thin pointer, so using We would have to accept a separate Optimally for me, we would have something like this: pub trait CommandExt {
unsafe fn raw_attribute<T: Sized, *const T: Repr<*const c_void>>(
&mut self,
attribute: usize,
ptr: *const T,
) -> &mut process::Command {
// record size_of::<T>() and the ptr as *const c_void
}
} |
Sorry for the newbie question, I just want to understand the problem a little more, why is it a problem that cmd.raw_attribute(PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE, hpc.0); Why is it not a problem in this other scenario that is in the documentation? child_cmd.raw_attribute(PROC_THREAD_ATTRIBUTE_PARENT_PROCESS, parent.as_raw_handle() as isize); |
@Ivan-Sanchez-Diaz windows api is a bit weird here since it treats some values as literal pointers. The Basically windows expects us to pass Similar how it would be wrong to pass a In case of the parent process, what we are passing to |
Technically HPCOM is not a direct pointer but a HANDLE which is an index into a table which holds the actual address. |
thanks for the good explanation! now I understand that the problem is that we are passing the reference of the reference to |
Sorry, I am not very familiar with the dependencies on the system API inside the std library. But it seems to me that a system function that requires passing a pointer of a different type and size, and where the size may be non-trivial, is a rather unique case. |
@michaelvanstraten To state that the pointer is a thin pointer, it is sufficient to know that |
I did not know that transmute checks for the size, that would be very useful here if the error message is understandable for the user. |
@kazatsuyu I am trying to think of a |
@michaelvanstraten Of course it works, but |
You would have to cast |
I understand that. So we use |
Why is For example if we had something like the following API: pub trait CommandExt {
unsafe fn raw_attribute<T: Sized + 'static>(
&mut self,
attribute: usize,
ptr: *const T,
) -> &mut process::Command {
// record size_of::<T>() and std::men::transmute::<_, *const c_void>(ptr)
}
} We could do the following: let g = GROUP_AFFINITY {
Mask: 0,
Group: 6,
Reserved: [0,0,0],
}
let mut cmd = Cmd::new("foo");
unsafe { cmd.raw_attribute(PROC_THREAD_ATTRIBUTE_GROUP_AFFINITY, addr_of!(g))} ; If necessary, you can just cask your |
Oh, |
Passing the slice pointer to would be false here, so the interface is correct to assume that To do this correctly you would need an unstable API, namely It would look something like this: #![feature(raw)]
use std::raw::{self, Repr};
let handles = &[0, 1, 2];
let repr: raw::Slice<usize> = handles.repr();
let mut cmd = Cmd::new("foo");
cmd.raw_attribute(PROC_THREAD_ATTRIBUTE_HANDLE_LIST, repr.data, repr.len); Here |
This can also be done in stable rust using the |
On second thought, unsafe fn raw_attribute<'a, 'b: 'a, T: Sized>(
&'a mut self,
attribute: usize,
&'b value: [T],
) -> &mut process::Command {
let lpvalue = value.as_ptr();
let cbsize = size_of::<T>() * value.len();
} seems to work fine in most cases. However, this will not address the let hpc: HPCON;
cmd.raw_attribute(PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE, std::slice::from_raw_parts(hpc.0 as *const HPCON, 1)); Doing the above will have the same effect as passing |
enum Attribute<'a, T> {
Value(T),
Slice(&'a [T]),
UnsafeImmediatePtrDontUseUntillUnderstandWhenYouShouldUseThis {
lpvalue: *const T,
cbsize: usize,
},
} Perhaps we should allow values to be passed through such a type? |
Maybe, but that is probably too specific for a raw interface. pub trait CommandExt {
unsafe fn raw_attribute<T: Sized + 'static>(
&mut self,
attribute: usize,
ptr: *const T,
size: usize,
) -> &mut process::Command {
// record size and std::men::transmute::<_, *const c_void>(ptr)
}
} It still does not allow for any pointers other than thin ones, and you can pass a slice using it. |
In the end, that is the most straightforward implementation. Note that |
It is an unsafe interface, so yes. |
Hello, Please tell me what you think. best regards. |
…ute_list, r=<try> Abstract `ProcThreadAttributeList` into its own struct As extensively discussed in issue rust-lang#114854, the current implementation of the unstable `windows_process_extensions_raw_attribute` features lacks support for passing a raw pointer. This PR wants to explore the opportunity to abstract away the `ProcThreadAttributeList` into its own struct to for one improve safety and usability and secondly make it possible to maybe also use it to spawn new threads. try-job: x86_64-msvc
…ute_list, r=<try> Abstract `ProcThreadAttributeList` into its own struct As extensively discussed in issue rust-lang#114854, the current implementation of the unstable `windows_process_extensions_raw_attribute` features lacks support for passing a raw pointer. This PR wants to explore the opportunity to abstract away the `ProcThreadAttributeList` into its own struct to for one improve safety and usability and secondly make it possible to maybe also use it to spawn new threads. try-job: x86_64-mingw
…ute_list, r=<try> Abstract `ProcThreadAttributeList` into its own struct As extensively discussed in issue rust-lang#114854, the current implementation of the unstable `windows_process_extensions_raw_attribute` features lacks support for passing a raw pointer. This PR wants to explore the opportunity to abstract away the `ProcThreadAttributeList` into its own struct to for one improve safety and usability and secondly make it possible to maybe also use it to spawn new threads. try-job: x86_64-mingw
…ute_list, r=<try> Abstract `ProcThreadAttributeList` into its own struct As extensively discussed in issue rust-lang#114854, the current implementation of the unstable `windows_process_extensions_raw_attribute` features lacks support for passing a raw pointer. This PR wants to explore the opportunity to abstract away the `ProcThreadAttributeList` into its own struct to for one improve safety and usability and secondly make it possible to maybe also use it to spawn new threads. try-job: x86_64-mingw
…ute_list, r=<try> Abstract `ProcThreadAttributeList` into its own struct As extensively discussed in issue rust-lang#114854, the current implementation of the unstable `windows_process_extensions_raw_attribute` features lacks support for passing a raw pointer. This PR wants to explore the opportunity to abstract away the `ProcThreadAttributeList` into its own struct to for one improve safety and usability and secondly make it possible to maybe also use it to spawn new threads. try-job: x86_64-mingw
Feature Gate:
#![feature(windows_process_extensions_raw_attribute)]
This is a tracking issue for adding support to attach raw attributes for process creation on Windows using the
raw_attribute()
method.Public API
Steps / History
ProcThreadAttributeList
into its own struct #123604Unresolved Questions
The text was updated successfully, but these errors were encountered: