-
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
Abstract ProcThreadAttributeList
into its own struct
#123604
base: master
Are you sure you want to change the base?
Abstract ProcThreadAttributeList
into its own struct
#123604
Conversation
r? @ChrisDenton rustbot has assigned @ChrisDenton. Use |
This comment has been minimized.
This comment has been minimized.
4134d3e
to
3e6c21a
Compare
This comment has been minimized.
This comment has been minimized.
#[unstable(feature = "windows_process_extensions_raw_attribute", issue = "114854")] | ||
pub use sys::process::{ProcThreadAttributeList, ProcThreadAttributeListBuilder}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't exactly know the right way to export this here. @Dylan-DPC can you guide me on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As with the imports above, you need to start the import with crate::
. But see my review comment.
r? @Dylan-DPC |
Assigning it back to Chris giving them more time to review it :) (and well i am not the right person to review it :P) r? @ChrisDenton |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The public struct should be defined and documented in std/src/os
. Internally it can just be a simple wrapper around the std/src/sys
types but nothing in sys
should be directly exposed to users.
#[unstable(feature = "windows_process_extensions_raw_attribute", issue = "114854")] | ||
pub use sys::process::{ProcThreadAttributeList, ProcThreadAttributeListBuilder}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As with the imports above, you need to start the import with crate::
. But see my review comment.
/// # Safety | ||
/// | ||
/// This function is marked as `unsafe` because it deals with raw pointers and sizes. | ||
/// It is the responsibility of the caller to ensure the value lives longer than the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// It is the responsibility of the caller to ensure the value lives longer than the | |
/// It is the responsibility of the caller to ensure the value pointed to by the `value_ptr` lives longer than the |
/// | ||
/// This function is marked as `unsafe` because it deals with raw pointers and sizes. | ||
/// It is the responsibility of the caller to ensure the value lives longer than the | ||
/// [`ProcThreadAttributeListBuilder`] as well as the validity of the size parameter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// [`ProcThreadAttributeListBuilder`] as well as the validity of the size parameter. | |
/// [`ProcThreadAttributeList`] as well as the validity of the size parameter. |
si_ex = c::STARTUPINFOEXW { | ||
StartupInfo: si, | ||
lpAttributeList: proc_thread_attribute_list.0.as_mut_ptr() as _, | ||
lpAttributeList: proc_thread_attribute_list.as_mut_ptr().cast::<c_void>(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand why the win API require a *mut
to the attribute list here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the C headers do not distinguish. between const and mut so, when automatically generating the bindings, mut
is the most reasonable option. You can open an issue on the win32metadata repo if you'd like them to manually add some metadata so the Rust bindings know which one to use.
Though it doesn't matter too much. In rust, const and mut on pointers is just a lint. You can do, e.g. proc_thread_attribute_list.as_ptr().cast::<c_void>().cast_mut()
to go from a reference to a pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that was highly illegal because of some llvm
attributes that rustc sets when dealing with shared references.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pointers and references are different. You cannot turn a &
into an &mut
. You can turn an &
into a *mut
so long as you don't ever write to the memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, my concern was that with the win api having an interface that explicitly expects a *mut
I thought it might be the case that they actually write to it, but good to know. I will add a safety comment and open an issue over at the win32 crate repo.
☔ The latest upstream changes (presumably #125280) made this pull request unmergeable. Please resolve the merge conflicts. |
@rustbot label +S-waiting-on-author -S-waiting-on-review |
Would https://github.com/rust-lang/rust/blob/master/library/std/src/os/windows/process.rs, even be the right location for it considering it can be used to create a thread? Maybe |
What I don't understand is that there exists a Is it possible to create a thread for the current process with |
Yes. Indeed, the OS doesn't expose a special function to create a thread in the current process. |
@ChrisDenton fourth time is the charm. |
@bors try |
…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
If this should fail, I will set up a Windows machine to run the doc-tests locally. |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
Okay, let me fix this locally before I waste more CI time. |
d9e74ac
to
47927bd
Compare
@ChrisDenton, looks good on my local win11 build. I think you can push to try again once more. |
@bors try |
…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
☀️ Try build successful - checks-actions |
@ChrisDenton is there something I should do? |
47927bd
to
15a9f45
Compare
@ChrisDenton, I've resolved the two comments I made my self, from my perspective this should be ready to be merged. |
15a9f45
to
51590a8
Compare
This comment has been minimized.
This comment has been minimized.
51590a8
to
0f24485
Compare
@rustbot label -S-waiting-on-author +S-waiting-on-review |
As extensively discussed in issue #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