Skip to content

Commit d56c59e

Browse files
authored
Rollup merge of rust-lang#97060 - bdbai:fix/uwphandle, r=ChrisDenton
Fix use of SetHandleInformation on UWP The use of `SetHandleInformation` (introduced in rust-lang#96441 to make `HANDLE` inheritable) breaks UWP builds because it is not available for UWP targets. Proposed workaround: duplicate the `HANDLE` with `inherit = true` and immediately close the old one. Traditional Windows Desktop programs are not affected. cc `@ChrisDenton`
2 parents ede4f0e + 4f637ee commit d56c59e

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

library/std/src/os/windows/io/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ impl OwnedHandle {
206206
}
207207

208208
/// Allow child processes to inherit the handle.
209+
#[cfg(not(target_vendor = "uwp"))]
209210
pub(crate) fn set_inheritable(&self) -> io::Result<()> {
210211
cvt(unsafe {
211212
c::SetHandleInformation(

library/std/src/os/windows/io/socket.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::mem;
1010
use crate::mem::forget;
1111
use crate::sys;
1212
use crate::sys::c;
13+
#[cfg(not(target_vendor = "uwp"))]
1314
use crate::sys::cvt;
1415

1516
/// A borrowed socket.

library/std/src/sys/windows/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ impl Handle {
221221
Ok(Self(self.0.duplicate(access, inherit, options)?))
222222
}
223223

224+
#[cfg(not(target_vendor = "uwp"))]
224225
pub(crate) fn set_inheritable(&self) -> io::Result<()> {
225226
self.0.set_inheritable()
226227
}

library/std/src/sys/windows/pipe.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,21 @@ impl Pipes {
5757
} else {
5858
let (ours, theirs) = if ours_readable { (read, write) } else { (write, read) };
5959
let ours = Handle::from_raw_handle(ours);
60+
#[cfg(not(target_vendor = "uwp"))]
6061
let theirs = Handle::from_raw_handle(theirs);
62+
#[cfg(target_vendor = "uwp")]
63+
let mut theirs = Handle::from_raw_handle(theirs);
6164

6265
if their_handle_inheritable {
63-
theirs.set_inheritable()?;
66+
#[cfg(not(target_vendor = "uwp"))]
67+
{
68+
theirs.set_inheritable()?;
69+
}
70+
71+
#[cfg(target_vendor = "uwp")]
72+
{
73+
theirs = theirs.duplicate(0, true, c::DUPLICATE_SAME_ACCESS)?;
74+
}
6475
}
6576

6677
Ok(Pipes { ours: AnonPipe::Sync(ours), theirs: AnonPipe::Sync(theirs) })

0 commit comments

Comments
 (0)