Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 52542ca

Browse files
committedJun 29, 2019
Auto merge of #62237 - Centril:rollup-nsrgek8, r=Centril
Rollup of 4 pull requests Successful merges: - #60260 (Add support for UWP targets) - #62128 (Adjust warning of -C extra-filename with -o.) - #62153 (Update the `rust-installer` submodule) - #62224 (rustdoc: remove unused derives and variants) Failed merges: r? @ghost
2 parents 9a90d03 + b30f62f commit 52542ca

File tree

29 files changed

+590
-187
lines changed

29 files changed

+590
-187
lines changed
 

‎Cargo.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,9 +1272,10 @@ name = "installer"
12721272
version = "0.0.0"
12731273
dependencies = [
12741274
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
1275-
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
1275+
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
12761276
"flate2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
12771277
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
1278+
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
12781279
"rayon 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
12791280
"tar 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
12801281
"walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",

‎src/bootstrap/compile.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl Step for StartupObjects {
326326
fn run(self, builder: &Builder<'_>) {
327327
let for_compiler = self.compiler;
328328
let target = self.target;
329-
if !target.contains("pc-windows-gnu") {
329+
if !target.contains("windows-gnu") {
330330
return
331331
}
332332

@@ -1130,6 +1130,7 @@ pub fn run_cargo(builder: &Builder<'_>,
11301130
// Skip files like executables
11311131
if !filename.ends_with(".rlib") &&
11321132
!filename.ends_with(".lib") &&
1133+
!filename.ends_with(".a") &&
11331134
!is_dylib(&filename) &&
11341135
!(is_check && filename.ends_with(".rmeta")) {
11351136
continue;

‎src/librustc_codegen_ssa/back/linker.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,26 @@ impl<'a> Linker for GccLinker<'a> {
368368
}
369369
} else {
370370
self.cmd.arg("-shared");
371+
if self.sess.target.target.options.is_like_windows {
372+
// The output filename already contains `dll_suffix` so
373+
// the resulting import library will have a name in the
374+
// form of libfoo.dll.a
375+
let implib_name = out_filename
376+
.file_name()
377+
.and_then(|file| file.to_str())
378+
.map(|file| format!("{}{}{}",
379+
self.sess.target.target.options.staticlib_prefix,
380+
file,
381+
self.sess.target.target.options.staticlib_suffix));
382+
if let Some(implib_name) = implib_name {
383+
let implib = out_filename
384+
.parent()
385+
.map(|dir| dir.join(&implib_name));
386+
if let Some(implib) = implib {
387+
self.linker_arg(&format!("--out-implib,{}", (*implib).to_str().unwrap()));
388+
}
389+
}
390+
}
371391
}
372392
}
373393

‎src/librustc_interface/util.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,14 +642,14 @@ pub fn build_output_filenames(
642642
);
643643
None
644644
} else {
645+
if !sess.opts.cg.extra_filename.is_empty() {
646+
sess.warn("ignoring -C extra-filename flag due to -o flag");
647+
}
645648
Some(out_file.clone())
646649
};
647650
if *odir != None {
648651
sess.warn("ignoring --out-dir flag due to -o flag");
649652
}
650-
if !sess.opts.cg.extra_filename.is_empty() {
651-
sess.warn("ignoring -C extra-filename flag due to -o flag");
652-
}
653653

654654
OutputFilenames {
655655
out_directory: out_file.parent().unwrap_or_else(|| Path::new("")).to_path_buf(),
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use crate::spec::{LinkerFlavor, Target, TargetResult};
2+
3+
pub fn target() -> TargetResult {
4+
let mut base = super::windows_uwp_base::opts();
5+
base.cpu = "pentium4".to_string();
6+
base.max_atomic_width = Some(64);
7+
base.eliminate_frame_pointer = false; // Required for backtraces
8+
9+
// Mark all dynamic libraries and executables as compatible with the larger 4GiB address
10+
// space available to x86 Windows binaries on x86_64.
11+
base.pre_link_args
12+
.get_mut(&LinkerFlavor::Gcc).unwrap().push("-Wl,--large-address-aware".to_string());
13+
14+
Ok(Target {
15+
llvm_target: "i686-pc-windows-gnu".to_string(),
16+
target_endian: "little".to_string(),
17+
target_pointer_width: "32".to_string(),
18+
target_c_int_width: "32".to_string(),
19+
data_layout: "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32".to_string(),
20+
arch: "x86".to_string(),
21+
target_os: "windows".to_string(),
22+
target_env: "gnu".to_string(),
23+
target_vendor: "uwp".to_string(),
24+
linker_flavor: LinkerFlavor::Gcc,
25+
options: base,
26+
})
27+
}

‎src/librustc_target/spec/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ mod solaris_base;
6060
mod uefi_base;
6161
mod windows_base;
6262
mod windows_msvc_base;
63+
mod windows_uwp_base;
6364
mod thumb_base;
6465
mod l4re_base;
6566
mod fuchsia_base;
@@ -433,6 +434,8 @@ supported_targets! {
433434

434435
("x86_64-pc-windows-gnu", x86_64_pc_windows_gnu),
435436
("i686-pc-windows-gnu", i686_pc_windows_gnu),
437+
("i686-uwp-windows-gnu", i686_uwp_windows_gnu),
438+
("x86_64-uwp-windows-gnu", x86_64_uwp_windows_gnu),
436439

437440
("aarch64-pc-windows-msvc", aarch64_pc_windows_msvc),
438441
("x86_64-pc-windows-msvc", x86_64_pc_windows_msvc),
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
use crate::spec::{LinkArgs, LinkerFlavor, TargetOptions};
2+
use std::default::Default;
3+
4+
pub fn opts() -> TargetOptions {
5+
let mut pre_link_args = LinkArgs::new();
6+
pre_link_args.insert(LinkerFlavor::Gcc, vec![
7+
// Tell GCC to avoid linker plugins, because we are not bundling
8+
// them with Windows installer, and Rust does its own LTO anyways.
9+
"-fno-use-linker-plugin".to_string(),
10+
11+
// Always enable DEP (NX bit) when it is available
12+
"-Wl,--nxcompat".to_string(),
13+
]);
14+
15+
let mut late_link_args = LinkArgs::new();
16+
late_link_args.insert(LinkerFlavor::Gcc, vec![
17+
//"-lwinstorecompat".to_string(),
18+
//"-lmingwex".to_string(),
19+
//"-lwinstorecompat".to_string(),
20+
"-lwinstorecompat".to_string(),
21+
"-lruntimeobject".to_string(),
22+
"-lsynchronization".to_string(),
23+
"-lvcruntime140_app".to_string(),
24+
"-lucrt".to_string(),
25+
"-lwindowsapp".to_string(),
26+
"-lmingwex".to_string(),
27+
"-lmingw32".to_string(),
28+
]);
29+
30+
TargetOptions {
31+
// FIXME(#13846) this should be enabled for windows
32+
function_sections: false,
33+
linker: Some("gcc".to_string()),
34+
dynamic_linking: true,
35+
executables: false,
36+
dll_prefix: String::new(),
37+
dll_suffix: ".dll".to_string(),
38+
exe_suffix: ".exe".to_string(),
39+
staticlib_prefix: "lib".to_string(),
40+
staticlib_suffix: ".a".to_string(),
41+
no_default_libraries: true,
42+
target_family: Some("windows".to_string()),
43+
is_like_windows: true,
44+
allows_weak_linkage: false,
45+
pre_link_args,
46+
pre_link_objects_exe: vec![
47+
"rsbegin.o".to_string(), // Rust compiler runtime initialization, see rsbegin.rs
48+
],
49+
pre_link_objects_dll: vec![
50+
"rsbegin.o".to_string(),
51+
],
52+
late_link_args,
53+
post_link_objects: vec![
54+
"rsend.o".to_string(),
55+
],
56+
custom_unwind_resume: true,
57+
abi_return_struct_as_int: true,
58+
emit_debug_gdb_scripts: false,
59+
requires_uwtable: true,
60+
limit_rdylib_exports: false,
61+
62+
.. Default::default()
63+
}
64+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use crate::spec::{LinkerFlavor, Target, TargetResult};
2+
3+
pub fn target() -> TargetResult {
4+
let mut base = super::windows_uwp_base::opts();
5+
base.cpu = "x86-64".to_string();
6+
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m64".to_string());
7+
base.max_atomic_width = Some(64);
8+
9+
Ok(Target {
10+
llvm_target: "x86_64-pc-windows-gnu".to_string(),
11+
target_endian: "little".to_string(),
12+
target_pointer_width: "64".to_string(),
13+
target_c_int_width: "32".to_string(),
14+
data_layout: "e-m:w-i64:64-f80:128-n8:16:32:64-S128".to_string(),
15+
arch: "x86_64".to_string(),
16+
target_os: "windows".to_string(),
17+
target_env: "gnu".to_string(),
18+
target_vendor: "uwp".to_string(),
19+
linker_flavor: LinkerFlavor::Gcc,
20+
options: base,
21+
})
22+
}

‎src/librustdoc/clean/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use syntax_pos::Span;
1616

1717
use crate::html::escape::Escape;
1818

19-
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, PartialEq, Eq, Hash)]
19+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
2020
pub enum Cfg {
2121
/// Accepts all configurations.
2222
True,

‎src/librustdoc/clean/mod.rs

Lines changed: 54 additions & 57 deletions
Large diffs are not rendered by default.

‎src/librustdoc/doctree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl Module<'hir> {
7878
}
7979
}
8080

81-
#[derive(Debug, Clone, RustcEncodable, RustcDecodable, Copy)]
81+
#[derive(Debug, Clone, Copy)]
8282
pub enum StructType {
8383
/// A braced struct
8484
Plain,

‎src/librustdoc/html/format.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -737,9 +737,6 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter<'_>, use_absolute: bool) ->
737737
}
738738
}
739739
}
740-
clean::Unique(..) => {
741-
panic!("should have been cleaned")
742-
}
743740
}
744741
}
745742

‎src/librustdoc/html/item_type.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ impl From<clean::TypeKind> for ItemType {
110110
clean::TypeKind::Module => ItemType::Module,
111111
clean::TypeKind::Static => ItemType::Static,
112112
clean::TypeKind::Const => ItemType::Constant,
113-
clean::TypeKind::Variant => ItemType::Variant,
114113
clean::TypeKind::Typedef => ItemType::Typedef,
115114
clean::TypeKind::Foreign => ItemType::ForeignType,
116115
clean::TypeKind::Macro => ItemType::Macro,

‎src/librustdoc/html/render.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5188,9 +5188,6 @@ fn collect_paths_for_type(first_ty: clean::Type) -> Vec<String> {
51885188
clean::Type::Array(ty, _) => {
51895189
work.push_back(*ty);
51905190
},
5191-
clean::Type::Unique(ty) => {
5192-
work.push_back(*ty);
5193-
},
51945191
clean::Type::RawPointer(_, ty) => {
51955192
work.push_back(*ty);
51965193
},

‎src/librustdoc/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ extern crate test as testing;
4242
#[macro_use] extern crate log;
4343
extern crate rustc_errors as errors;
4444

45-
extern crate serialize as rustc_serialize; // used by deriving
46-
4745
use std::default::Default;
4846
use std::env;
4947
use std::panic;

‎src/libstd/build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ fn main() {
3939
println!("cargo:rustc-link-lib=framework=Security");
4040
println!("cargo:rustc-link-lib=framework=Foundation");
4141
println!("cargo:rustc-link-lib=resolv");
42+
} else if target.contains("uwp") {
43+
println!("cargo:rustc-link-lib=ws2_32");
44+
// For BCryptGenRandom
45+
println!("cargo:rustc-link-lib=bcrypt");
4246
} else if target.contains("windows") {
4347
println!("cargo:rustc-link-lib=advapi32");
4448
println!("cargo:rustc-link-lib=ws2_32");

‎src/libstd/sys/windows/c.rs

Lines changed: 133 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#![cfg_attr(test, allow(dead_code))]
55
#![unstable(issue = "0", feature = "windows_c")]
66

7+
macro_rules! ifdef {
8+
($($t:tt)*) => ($($t)*)
9+
}
10+
711
use crate::os::raw::{c_int, c_uint, c_ulong, c_long, c_longlong, c_ushort, c_char};
812
use crate::ptr;
913

@@ -34,9 +38,7 @@ pub type ULONG = c_ulong;
3438

3539
pub type LPBOOL = *mut BOOL;
3640
pub type LPBYTE = *mut BYTE;
37-
pub type LPBY_HANDLE_FILE_INFORMATION = *mut BY_HANDLE_FILE_INFORMATION;
3841
pub type LPCSTR = *const CHAR;
39-
pub type LPCVOID = *const c_void;
4042
pub type LPCWSTR = *const WCHAR;
4143
pub type LPDWORD = *mut DWORD;
4244
pub type LPHANDLE = *mut HANDLE;
@@ -121,6 +123,7 @@ impl Clone for WIN32_FIND_DATAW {
121123
}
122124

123125
pub const WSA_FLAG_OVERLAPPED: DWORD = 0x01;
126+
pub const WSA_FLAG_NO_HANDLE_INHERIT: DWORD = 0x80;
124127

125128
pub const WSADESCRIPTION_LEN: usize = 256;
126129
pub const WSASYS_STATUS_LEN: usize = 128;
@@ -130,6 +133,7 @@ pub const INVALID_SOCKET: SOCKET = !0;
130133
pub const WSAEACCES: c_int = 10013;
131134
pub const WSAEINVAL: c_int = 10022;
132135
pub const WSAEWOULDBLOCK: c_int = 10035;
136+
pub const WSAEPROTOTYPE: c_int = 10041;
133137
pub const WSAEADDRINUSE: c_int = 10048;
134138
pub const WSAEADDRNOTAVAIL: c_int = 10049;
135139
pub const WSAECONNABORTED: c_int = 10053;
@@ -141,7 +145,6 @@ pub const WSAECONNREFUSED: c_int = 10061;
141145

142146
pub const MAX_PROTOCOL_CHAIN: DWORD = 7;
143147

144-
pub const TOKEN_READ: DWORD = 0x20008;
145148
pub const MAXIMUM_REPARSE_DATA_BUFFER_SIZE: usize = 16 * 1024;
146149
pub const FSCTL_GET_REPARSE_POINT: DWORD = 0x900a8;
147150
pub const IO_REPARSE_TAG_SYMLINK: DWORD = 0xa000000c;
@@ -157,8 +160,6 @@ pub const STD_INPUT_HANDLE: DWORD = -10i32 as DWORD;
157160
pub const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
158161
pub const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD;
159162

160-
pub const HANDLE_FLAG_INHERIT: DWORD = 0x00000001;
161-
162163
pub const PROGRESS_CONTINUE: DWORD = 0;
163164

164165
pub const ERROR_FILE_NOT_FOUND: DWORD = 2;
@@ -259,10 +260,6 @@ pub const WAIT_OBJECT_0: DWORD = 0x00000000;
259260
pub const WAIT_TIMEOUT: DWORD = 258;
260261
pub const WAIT_FAILED: DWORD = 0xFFFFFFFF;
261262

262-
pub const EXCEPTION_CONTINUE_SEARCH: LONG = 0;
263-
pub const EXCEPTION_STACK_OVERFLOW: DWORD = 0xc00000fd;
264-
pub const EXCEPTION_MAXIMUM_PARAMETERS: usize = 15;
265-
266263
pub const PIPE_ACCESS_INBOUND: DWORD = 0x00000001;
267264
pub const PIPE_ACCESS_OUTBOUND: DWORD = 0x00000002;
268265
pub const FILE_FLAG_FIRST_PIPE_INSTANCE: DWORD = 0x00080000;
@@ -342,20 +339,6 @@ pub struct WIN32_FILE_ATTRIBUTE_DATA {
342339
pub nFileSizeLow: DWORD,
343340
}
344341

345-
#[repr(C)]
346-
pub struct BY_HANDLE_FILE_INFORMATION {
347-
pub dwFileAttributes: DWORD,
348-
pub ftCreationTime: FILETIME,
349-
pub ftLastAccessTime: FILETIME,
350-
pub ftLastWriteTime: FILETIME,
351-
pub dwVolumeSerialNumber: DWORD,
352-
pub nFileSizeHigh: DWORD,
353-
pub nFileSizeLow: DWORD,
354-
pub nNumberOfLinks: DWORD,
355-
pub nFileIndexHigh: DWORD,
356-
pub nFileIndexLow: DWORD,
357-
}
358-
359342
#[repr(C)]
360343
#[allow(dead_code)] // we only use some variants
361344
pub enum FILE_INFO_BY_HANDLE_CLASS {
@@ -461,25 +444,6 @@ pub struct REPARSE_MOUNTPOINT_DATA_BUFFER {
461444
pub ReparseTarget: WCHAR,
462445
}
463446

464-
#[repr(C)]
465-
pub struct EXCEPTION_RECORD {
466-
pub ExceptionCode: DWORD,
467-
pub ExceptionFlags: DWORD,
468-
pub ExceptionRecord: *mut EXCEPTION_RECORD,
469-
pub ExceptionAddress: LPVOID,
470-
pub NumberParameters: DWORD,
471-
pub ExceptionInformation: [LPVOID; EXCEPTION_MAXIMUM_PARAMETERS]
472-
}
473-
474-
#[repr(C)]
475-
pub struct EXCEPTION_POINTERS {
476-
pub ExceptionRecord: *mut EXCEPTION_RECORD,
477-
pub ContextRecord: *mut CONTEXT,
478-
}
479-
480-
pub type PVECTORED_EXCEPTION_HANDLER = extern "system"
481-
fn(ExceptionInfo: *mut EXCEPTION_POINTERS) -> LONG;
482-
483447
#[repr(C)]
484448
pub struct GUID {
485449
pub Data1: DWORD,
@@ -562,8 +526,6 @@ pub enum ADDRESS_MODE {
562526
AddrModeFlat,
563527
}
564528

565-
pub enum CONTEXT {}
566-
567529
#[repr(C)]
568530
pub struct SOCKADDR_STORAGE_LH {
569531
pub ss_family: ADDRESS_FAMILY,
@@ -625,16 +587,6 @@ pub enum EXCEPTION_DISPOSITION {
625587
ExceptionCollidedUnwind
626588
}
627589

628-
#[repr(C)]
629-
#[derive(Copy, Clone)]
630-
pub struct CONSOLE_READCONSOLE_CONTROL {
631-
pub nLength: ULONG,
632-
pub nInitialChars: ULONG,
633-
pub dwCtrlWakeupMask: ULONG,
634-
pub dwControlKeyState: ULONG,
635-
}
636-
pub type PCONSOLE_READCONSOLE_CONTROL = *mut CONSOLE_READCONSOLE_CONTROL;
637-
638590
#[repr(C)]
639591
#[derive(Copy)]
640592
pub struct fd_set {
@@ -655,6 +607,132 @@ pub struct timeval {
655607
pub tv_usec: c_long,
656608
}
657609

610+
// Functions forbidden when targeting UWP
611+
#[cfg(not(target_vendor = "uwp"))]
612+
ifdef! {
613+
pub const EXCEPTION_CONTINUE_SEARCH: LONG = 0;
614+
pub const EXCEPTION_STACK_OVERFLOW: DWORD = 0xc00000fd;
615+
pub const EXCEPTION_MAXIMUM_PARAMETERS: usize = 15;
616+
617+
#[repr(C)]
618+
pub struct EXCEPTION_RECORD {
619+
pub ExceptionCode: DWORD,
620+
pub ExceptionFlags: DWORD,
621+
pub ExceptionRecord: *mut EXCEPTION_RECORD,
622+
pub ExceptionAddress: LPVOID,
623+
pub NumberParameters: DWORD,
624+
pub ExceptionInformation: [LPVOID; EXCEPTION_MAXIMUM_PARAMETERS]
625+
}
626+
627+
pub enum CONTEXT {}
628+
629+
#[repr(C)]
630+
pub struct EXCEPTION_POINTERS {
631+
pub ExceptionRecord: *mut EXCEPTION_RECORD,
632+
pub ContextRecord: *mut CONTEXT,
633+
}
634+
635+
pub type PVECTORED_EXCEPTION_HANDLER = extern "system"
636+
fn(ExceptionInfo: *mut EXCEPTION_POINTERS) -> LONG;
637+
638+
#[repr(C)]
639+
#[derive(Copy, Clone)]
640+
pub struct CONSOLE_READCONSOLE_CONTROL {
641+
pub nLength: ULONG,
642+
pub nInitialChars: ULONG,
643+
pub dwCtrlWakeupMask: ULONG,
644+
pub dwControlKeyState: ULONG,
645+
}
646+
647+
pub type PCONSOLE_READCONSOLE_CONTROL = *mut CONSOLE_READCONSOLE_CONTROL;
648+
649+
#[repr(C)]
650+
pub struct BY_HANDLE_FILE_INFORMATION {
651+
pub dwFileAttributes: DWORD,
652+
pub ftCreationTime: FILETIME,
653+
pub ftLastAccessTime: FILETIME,
654+
pub ftLastWriteTime: FILETIME,
655+
pub dwVolumeSerialNumber: DWORD,
656+
pub nFileSizeHigh: DWORD,
657+
pub nFileSizeLow: DWORD,
658+
pub nNumberOfLinks: DWORD,
659+
pub nFileIndexHigh: DWORD,
660+
pub nFileIndexLow: DWORD,
661+
}
662+
663+
pub type LPBY_HANDLE_FILE_INFORMATION = *mut BY_HANDLE_FILE_INFORMATION;
664+
pub type LPCVOID = *const c_void;
665+
666+
pub const HANDLE_FLAG_INHERIT: DWORD = 0x00000001;
667+
668+
pub const TOKEN_READ: DWORD = 0x20008;
669+
670+
extern "system" {
671+
#[link_name = "SystemFunction036"]
672+
pub fn RtlGenRandom(RandomBuffer: *mut u8, RandomBufferLength: ULONG) -> BOOLEAN;
673+
674+
pub fn ReadConsoleW(hConsoleInput: HANDLE,
675+
lpBuffer: LPVOID,
676+
nNumberOfCharsToRead: DWORD,
677+
lpNumberOfCharsRead: LPDWORD,
678+
pInputControl: PCONSOLE_READCONSOLE_CONTROL) -> BOOL;
679+
680+
pub fn WriteConsoleW(hConsoleOutput: HANDLE,
681+
lpBuffer: LPCVOID,
682+
nNumberOfCharsToWrite: DWORD,
683+
lpNumberOfCharsWritten: LPDWORD,
684+
lpReserved: LPVOID) -> BOOL;
685+
686+
pub fn GetConsoleMode(hConsoleHandle: HANDLE,
687+
lpMode: LPDWORD) -> BOOL;
688+
// Allowed but unused by UWP
689+
pub fn OpenProcessToken(ProcessHandle: HANDLE,
690+
DesiredAccess: DWORD,
691+
TokenHandle: *mut HANDLE) -> BOOL;
692+
pub fn GetUserProfileDirectoryW(hToken: HANDLE,
693+
lpProfileDir: LPWSTR,
694+
lpcchSize: *mut DWORD) -> BOOL;
695+
pub fn GetFileInformationByHandle(hFile: HANDLE,
696+
lpFileInformation: LPBY_HANDLE_FILE_INFORMATION)
697+
-> BOOL;
698+
pub fn SetHandleInformation(hObject: HANDLE,
699+
dwMask: DWORD,
700+
dwFlags: DWORD) -> BOOL;
701+
pub fn AddVectoredExceptionHandler(FirstHandler: ULONG,
702+
VectoredHandler: PVECTORED_EXCEPTION_HANDLER)
703+
-> LPVOID;
704+
pub fn CreateHardLinkW(lpSymlinkFileName: LPCWSTR,
705+
lpTargetFileName: LPCWSTR,
706+
lpSecurityAttributes: LPSECURITY_ATTRIBUTES)
707+
-> BOOL;
708+
}
709+
}
710+
711+
// UWP specific functions & types
712+
#[cfg(target_vendor = "uwp")]
713+
ifdef! {
714+
pub const BCRYPT_USE_SYSTEM_PREFERRED_RNG: DWORD = 0x00000002;
715+
716+
#[repr(C)]
717+
pub struct FILE_STANDARD_INFO {
718+
pub AllocationSize: LARGE_INTEGER,
719+
pub EndOfFile: LARGE_INTEGER,
720+
pub NumberOfLink: DWORD,
721+
pub DeletePending: BOOLEAN,
722+
pub Directory: BOOLEAN,
723+
}
724+
725+
extern "system" {
726+
pub fn GetFileInformationByHandleEx(hFile: HANDLE,
727+
fileInfoClass: FILE_INFO_BY_HANDLE_CLASS,
728+
lpFileInformation: LPVOID,
729+
dwBufferSize: DWORD) -> BOOL;
730+
pub fn BCryptGenRandom(hAlgorithm: LPVOID, pBuffer: *mut u8,
731+
cbBuffer: ULONG, dwFlags: ULONG) -> LONG;
732+
}
733+
}
734+
735+
// Shared between Desktop & UWP
658736
extern "system" {
659737
pub fn WSAStartup(wVersionRequested: WORD,
660738
lpWSAData: LPWSADATA) -> c_int;
@@ -694,34 +772,13 @@ extern "system" {
694772
pub fn LeaveCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
695773
pub fn DeleteCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
696774

697-
pub fn ReadConsoleW(hConsoleInput: HANDLE,
698-
lpBuffer: LPVOID,
699-
nNumberOfCharsToRead: DWORD,
700-
lpNumberOfCharsRead: LPDWORD,
701-
pInputControl: PCONSOLE_READCONSOLE_CONTROL) -> BOOL;
702-
703-
pub fn WriteConsoleW(hConsoleOutput: HANDLE,
704-
lpBuffer: LPCVOID,
705-
nNumberOfCharsToWrite: DWORD,
706-
lpNumberOfCharsWritten: LPDWORD,
707-
lpReserved: LPVOID) -> BOOL;
708-
709-
pub fn GetConsoleMode(hConsoleHandle: HANDLE,
710-
lpMode: LPDWORD) -> BOOL;
711775
pub fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
712776
pub fn SetFileAttributesW(lpFileName: LPCWSTR,
713777
dwFileAttributes: DWORD) -> BOOL;
714-
pub fn GetFileInformationByHandle(hFile: HANDLE,
715-
lpFileInformation: LPBY_HANDLE_FILE_INFORMATION)
716-
-> BOOL;
717-
718778
pub fn SetLastError(dwErrCode: DWORD);
719779
pub fn GetCommandLineW() -> *mut LPCWSTR;
720780
pub fn GetTempPathW(nBufferLength: DWORD,
721781
lpBuffer: LPCWSTR) -> DWORD;
722-
pub fn OpenProcessToken(ProcessHandle: HANDLE,
723-
DesiredAccess: DWORD,
724-
TokenHandle: *mut HANDLE) -> BOOL;
725782
pub fn GetCurrentProcess() -> HANDLE;
726783
pub fn GetCurrentThread() -> HANDLE;
727784
pub fn GetStdHandle(which: DWORD) -> HANDLE;
@@ -746,21 +803,12 @@ extern "system" {
746803
pub fn SwitchToThread() -> BOOL;
747804
pub fn Sleep(dwMilliseconds: DWORD);
748805
pub fn GetProcessId(handle: HANDLE) -> DWORD;
749-
pub fn GetUserProfileDirectoryW(hToken: HANDLE,
750-
lpProfileDir: LPWSTR,
751-
lpcchSize: *mut DWORD) -> BOOL;
752-
pub fn SetHandleInformation(hObject: HANDLE,
753-
dwMask: DWORD,
754-
dwFlags: DWORD) -> BOOL;
755806
pub fn CopyFileExW(lpExistingFileName: LPCWSTR,
756807
lpNewFileName: LPCWSTR,
757808
lpProgressRoutine: LPPROGRESS_ROUTINE,
758809
lpData: LPVOID,
759810
pbCancel: LPBOOL,
760811
dwCopyFlags: DWORD) -> BOOL;
761-
pub fn AddVectoredExceptionHandler(FirstHandler: ULONG,
762-
VectoredHandler: PVECTORED_EXCEPTION_HANDLER)
763-
-> LPVOID;
764812
pub fn FormatMessageW(flags: DWORD,
765813
lpSrc: LPVOID,
766814
msgId: DWORD,
@@ -857,10 +905,6 @@ extern "system" {
857905
lpOverlapped: LPOVERLAPPED)
858906
-> BOOL;
859907
pub fn CloseHandle(hObject: HANDLE) -> BOOL;
860-
pub fn CreateHardLinkW(lpSymlinkFileName: LPCWSTR,
861-
lpTargetFileName: LPCWSTR,
862-
lpSecurityAttributes: LPSECURITY_ATTRIBUTES)
863-
-> BOOL;
864908
pub fn MoveFileExW(lpExistingFileName: LPCWSTR,
865909
lpNewFileName: LPCWSTR,
866910
dwFlags: DWORD)
@@ -950,8 +994,6 @@ extern "system" {
950994
exceptfds: *mut fd_set,
951995
timeout: *const timeval) -> c_int;
952996

953-
#[link_name = "SystemFunction036"]
954-
pub fn RtlGenRandom(RandomBuffer: *mut u8, RandomBufferLength: ULONG) -> BOOLEAN;
955997

956998
pub fn GetProcessHeap() -> HANDLE;
957999
pub fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) -> LPVOID;
@@ -975,6 +1017,7 @@ compat_fn! {
9751017
_dwFlags: DWORD) -> DWORD {
9761018
SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
9771019
}
1020+
#[cfg(not(target_vendor = "uwp"))]
9781021
pub fn SetThreadStackGuarantee(_size: *mut c_ulong) -> BOOL {
9791022
SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
9801023
}

‎src/libstd/sys/windows/compat.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ pub fn store_func(ptr: &AtomicUsize, module: &str, symbol: &str,
3737

3838
macro_rules! compat_fn {
3939
($module:ident: $(
40+
$(#[$meta:meta])*
4041
pub fn $symbol:ident($($argname:ident: $argtype:ty),*)
4142
-> $rettype:ty {
4243
$($body:expr);*
4344
}
4445
)*) => ($(
4546
#[allow(unused_variables)]
47+
$(#[$meta])*
4648
pub unsafe fn $symbol($($argname: $argtype),*) -> $rettype {
4749
use crate::sync::atomic::{AtomicUsize, Ordering};
4850
use crate::mem;

‎src/libstd/sys/windows/fs.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ impl File {
287287
Ok(())
288288
}
289289

290+
#[cfg(not(target_vendor = "uwp"))]
290291
pub fn file_attr(&self) -> io::Result<FileAttr> {
291292
unsafe {
292293
let mut info: c::BY_HANDLE_FILE_INFORMATION = mem::zeroed();
@@ -310,6 +311,49 @@ impl File {
310311
}
311312
}
312313

314+
#[cfg(target_vendor = "uwp")]
315+
pub fn file_attr(&self) -> io::Result<FileAttr> {
316+
unsafe {
317+
let mut info: c::FILE_BASIC_INFO = mem::zeroed();
318+
let size = mem::size_of_val(&info);
319+
cvt(c::GetFileInformationByHandleEx(self.handle.raw(),
320+
c::FileBasicInfo,
321+
&mut info as *mut _ as *mut libc::c_void,
322+
size as c::DWORD))?;
323+
let mut attr = FileAttr {
324+
attributes: info.FileAttributes,
325+
creation_time: c::FILETIME {
326+
dwLowDateTime: info.CreationTime as c::DWORD,
327+
dwHighDateTime: (info.CreationTime >> 32) as c::DWORD,
328+
},
329+
last_access_time: c::FILETIME {
330+
dwLowDateTime: info.LastAccessTime as c::DWORD,
331+
dwHighDateTime: (info.LastAccessTime >> 32) as c::DWORD,
332+
},
333+
last_write_time: c::FILETIME {
334+
dwLowDateTime: info.LastWriteTime as c::DWORD,
335+
dwHighDateTime: (info.LastWriteTime >> 32) as c::DWORD,
336+
},
337+
file_size: 0,
338+
reparse_tag: 0,
339+
};
340+
let mut info: c::FILE_STANDARD_INFO = mem::zeroed();
341+
let size = mem::size_of_val(&info);
342+
cvt(c::GetFileInformationByHandleEx(self.handle.raw(),
343+
c::FileStandardInfo,
344+
&mut info as *mut _ as *mut libc::c_void,
345+
size as c::DWORD))?;
346+
attr.file_size = info.AllocationSize as u64;
347+
if attr.is_reparse_point() {
348+
let mut b = [0; c::MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
349+
if let Ok((_, buf)) = self.reparse_point(&mut b) {
350+
attr.reparse_tag = buf.ReparseTag;
351+
}
352+
}
353+
Ok(attr)
354+
}
355+
}
356+
313357
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
314358
self.handle.read(buf)
315359
}
@@ -670,6 +714,7 @@ pub fn symlink_inner(src: &Path, dst: &Path, dir: bool) -> io::Result<()> {
670714
Ok(())
671715
}
672716

717+
#[cfg(not(target_vendor = "uwp"))]
673718
pub fn link(src: &Path, dst: &Path) -> io::Result<()> {
674719
let src = to_u16s(src)?;
675720
let dst = to_u16s(dst)?;
@@ -679,6 +724,12 @@ pub fn link(src: &Path, dst: &Path) -> io::Result<()> {
679724
Ok(())
680725
}
681726

727+
#[cfg(target_vendor = "uwp")]
728+
pub fn link(_src: &Path, _dst: &Path) -> io::Result<()> {
729+
return Err(io::Error::new(io::ErrorKind::Other,
730+
"hard link are not supported on UWP"));
731+
}
732+
682733
pub fn stat(path: &Path) -> io::Result<FileAttr> {
683734
let mut opts = OpenOptions::new();
684735
// No read or write permissions are necessary

‎src/libstd/sys/windows/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,20 @@ pub mod pipe;
3333
pub mod process;
3434
pub mod rand;
3535
pub mod rwlock;
36-
pub mod stack_overflow;
3736
pub mod thread;
3837
pub mod thread_local;
3938
pub mod time;
40-
pub mod stdio;
39+
cfg_if! {
40+
if #[cfg(not(target_vendor = "uwp"))] {
41+
pub mod stdio;
42+
pub mod stack_overflow;
43+
} else {
44+
pub mod stdio_uwp;
45+
pub mod stack_overflow_uwp;
46+
pub use self::stdio_uwp as stdio;
47+
pub use self::stack_overflow_uwp as stack_overflow;
48+
}
49+
}
4150

4251
#[cfg(not(test))]
4352
pub fn init() {

‎src/libstd/sys/windows/net.rs

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,26 @@ impl Socket {
9797
};
9898
let socket = unsafe {
9999
match c::WSASocketW(fam, ty, 0, ptr::null_mut(), 0,
100-
c::WSA_FLAG_OVERLAPPED) {
101-
c::INVALID_SOCKET => Err(last_error()),
100+
c::WSA_FLAG_OVERLAPPED | c::WSA_FLAG_NO_HANDLE_INHERIT) {
101+
c::INVALID_SOCKET => {
102+
match c::WSAGetLastError() {
103+
c::WSAEPROTOTYPE => {
104+
match c::WSASocketW(fam, ty, 0, ptr::null_mut(), 0,
105+
c::WSA_FLAG_OVERLAPPED) {
106+
c::INVALID_SOCKET => Err(last_error()),
107+
n => {
108+
let s = Socket(n);
109+
s.set_no_inherit()?;
110+
Ok(s)
111+
},
112+
}
113+
},
114+
n => Err(io::Error::from_raw_os_error(n)),
115+
}
116+
},
102117
n => Ok(Socket(n)),
103118
}
104119
}?;
105-
socket.set_no_inherit()?;
106120
Ok(socket)
107121
}
108122

@@ -168,7 +182,6 @@ impl Socket {
168182
n => Ok(Socket(n)),
169183
}
170184
}?;
171-
socket.set_no_inherit()?;
172185
Ok(socket)
173186
}
174187

@@ -178,16 +191,34 @@ impl Socket {
178191
cvt(c::WSADuplicateSocketW(self.0,
179192
c::GetCurrentProcessId(),
180193
&mut info))?;
194+
181195
match c::WSASocketW(info.iAddressFamily,
182196
info.iSocketType,
183197
info.iProtocol,
184198
&mut info, 0,
185-
c::WSA_FLAG_OVERLAPPED) {
186-
c::INVALID_SOCKET => Err(last_error()),
199+
c::WSA_FLAG_OVERLAPPED | c::WSA_FLAG_NO_HANDLE_INHERIT) {
200+
c::INVALID_SOCKET => {
201+
match c::WSAGetLastError() {
202+
c::WSAEPROTOTYPE => {
203+
match c::WSASocketW(info.iAddressFamily,
204+
info.iSocketType,
205+
info.iProtocol,
206+
&mut info, 0,
207+
c::WSA_FLAG_OVERLAPPED) {
208+
c::INVALID_SOCKET => Err(last_error()),
209+
n => {
210+
let s = Socket(n);
211+
s.set_no_inherit()?;
212+
Ok(s)
213+
},
214+
}
215+
},
216+
n => Err(io::Error::from_raw_os_error(n)),
217+
}
218+
},
187219
n => Ok(Socket(n)),
188220
}
189221
}?;
190-
socket.set_no_inherit()?;
191222
Ok(socket)
192223
}
193224

@@ -312,13 +343,19 @@ impl Socket {
312343
}
313344
}
314345

346+
#[cfg(not(target_vendor = "uwp"))]
315347
fn set_no_inherit(&self) -> io::Result<()> {
316348
sys::cvt(unsafe {
317349
c::SetHandleInformation(self.0 as c::HANDLE,
318350
c::HANDLE_FLAG_INHERIT, 0)
319351
}).map(|_| ())
320352
}
321353

354+
#[cfg(target_vendor = "uwp")]
355+
fn set_no_inherit(&self) -> io::Result<()> {
356+
Err(io::Error::new(io::ErrorKind::Other, "Unavailable on UWP"))
357+
}
358+
322359
pub fn shutdown(&self, how: Shutdown) -> io::Result<()> {
323360
let how = match how {
324361
Shutdown::Write => c::SD_SEND,

‎src/libstd/sys/windows/os.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use crate::path::{self, PathBuf};
1313
use crate::ptr;
1414
use crate::slice;
1515
use crate::sys::{c, cvt};
16-
use crate::sys::handle::Handle;
1716

1817
use super::to_u16s;
1918

@@ -284,10 +283,11 @@ pub fn temp_dir() -> PathBuf {
284283
}, super::os2path).unwrap()
285284
}
286285

287-
pub fn home_dir() -> Option<PathBuf> {
288-
crate::env::var_os("HOME").or_else(|| {
289-
crate::env::var_os("USERPROFILE")
290-
}).map(PathBuf::from).or_else(|| unsafe {
286+
#[cfg(not(target_vendor = "uwp"))]
287+
fn home_dir_crt() -> Option<PathBuf> {
288+
unsafe {
289+
use crate::sys::handle::Handle;
290+
291291
let me = c::GetCurrentProcess();
292292
let mut token = ptr::null_mut();
293293
if c::OpenProcessToken(me, c::TOKEN_READ, &mut token) == 0 {
@@ -301,7 +301,18 @@ pub fn home_dir() -> Option<PathBuf> {
301301
_ => sz - 1, // sz includes the null terminator
302302
}
303303
}, super::os2path).ok()
304-
})
304+
}
305+
}
306+
307+
#[cfg(target_vendor = "uwp")]
308+
fn home_dir_crt() -> Option<PathBuf> {
309+
None
310+
}
311+
312+
pub fn home_dir() -> Option<PathBuf> {
313+
crate::env::var_os("HOME").or_else(|| {
314+
crate::env::var_os("USERPROFILE")
315+
}).map(PathBuf::from).or_else(|| home_dir_crt())
305316
}
306317

307318
pub fn exit(code: i32) -> ! {

‎src/libstd/sys/windows/pipe.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct Pipes {
4545
/// mode. This means that technically speaking it should only ever be used
4646
/// with `OVERLAPPED` instances, but also works out ok if it's only ever used
4747
/// once at a time (which we do indeed guarantee).
48-
pub fn anon_pipe(ours_readable: bool) -> io::Result<Pipes> {
48+
pub fn anon_pipe(ours_readable: bool, their_handle_inheritable: bool) -> io::Result<Pipes> {
4949
// Note that we specifically do *not* use `CreatePipe` here because
5050
// unfortunately the anonymous pipes returned do not support overlapped
5151
// operations. Instead, we create a "hopefully unique" name and create a
@@ -137,6 +137,13 @@ pub fn anon_pipe(ours_readable: bool) -> io::Result<Pipes> {
137137
opts.write(ours_readable);
138138
opts.read(!ours_readable);
139139
opts.share_mode(0);
140+
let size = mem::size_of::<c::SECURITY_ATTRIBUTES>();
141+
let mut sa = c::SECURITY_ATTRIBUTES {
142+
nLength: size as c::DWORD,
143+
lpSecurityDescriptor: ptr::null_mut(),
144+
bInheritHandle: their_handle_inheritable as i32,
145+
};
146+
opts.security_attributes(&mut sa);
140147
let theirs = File::open(Path::new(&name), &opts)?;
141148
let theirs = AnonPipe { inner: theirs.into_handle() };
142149

‎src/libstd/sys/windows/process.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,8 @@ impl Stdio {
267267

268268
Stdio::MakePipe => {
269269
let ours_readable = stdio_id != c::STD_INPUT_HANDLE;
270-
let pipes = pipe::anon_pipe(ours_readable)?;
270+
let pipes = pipe::anon_pipe(ours_readable, true)?;
271271
*pipe = Some(pipes.ours);
272-
cvt(unsafe {
273-
c::SetHandleInformation(pipes.theirs.handle().raw(),
274-
c::HANDLE_FLAG_INHERIT,
275-
c::HANDLE_FLAG_INHERIT)
276-
})?;
277272
Ok(pipes.theirs.into_handle())
278273
}
279274

‎src/libstd/sys/windows/rand.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::io;
22
use crate::mem;
33
use crate::sys::c;
44

5+
#[cfg(not(target_vendor = "uwp"))]
56
pub fn hashmap_random_keys() -> (u64, u64) {
67
let mut v = (0, 0);
78
let ret = unsafe {
@@ -14,3 +15,20 @@ pub fn hashmap_random_keys() -> (u64, u64) {
1415
}
1516
return v
1617
}
18+
19+
#[cfg(target_vendor = "uwp")]
20+
pub fn hashmap_random_keys() -> (u64, u64) {
21+
use crate::ptr;
22+
23+
let mut v = (0, 0);
24+
let ret = unsafe {
25+
c::BCryptGenRandom(ptr::null_mut(), &mut v as *mut _ as *mut u8,
26+
mem::size_of_val(&v) as c::ULONG,
27+
c::BCRYPT_USE_SYSTEM_PREFERRED_RNG)
28+
};
29+
if ret != 0 {
30+
panic!("couldn't generate random bytes: {}",
31+
io::Error::last_os_error());
32+
}
33+
return v
34+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![cfg_attr(test, allow(dead_code))]
2+
3+
pub struct Handler;
4+
5+
impl Handler {
6+
pub fn new() -> Handler {
7+
Handler
8+
}
9+
}
10+
11+
pub unsafe fn init() {}
12+
13+
pub unsafe fn cleanup() {}

‎src/libstd/sys/windows/stdio_uwp.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#![unstable(issue = "0", feature = "windows_stdio")]
2+
3+
use crate::io;
4+
use crate::sys::c;
5+
use crate::sys::handle::Handle;
6+
use crate::mem::ManuallyDrop;
7+
8+
pub struct Stdin {
9+
}
10+
pub struct Stdout;
11+
pub struct Stderr;
12+
13+
const MAX_BUFFER_SIZE: usize = 8192;
14+
pub const STDIN_BUF_SIZE: usize = MAX_BUFFER_SIZE / 2 * 3;
15+
16+
pub fn get_handle(handle_id: c::DWORD) -> io::Result<c::HANDLE> {
17+
let handle = unsafe { c::GetStdHandle(handle_id) };
18+
if handle == c::INVALID_HANDLE_VALUE {
19+
Err(io::Error::last_os_error())
20+
} else if handle.is_null() {
21+
Err(io::Error::from_raw_os_error(c::ERROR_INVALID_HANDLE as i32))
22+
} else {
23+
Ok(handle)
24+
}
25+
}
26+
27+
fn write(handle_id: c::DWORD, data: &[u8]) -> io::Result<usize> {
28+
let handle = get_handle(handle_id)?;
29+
let handle = Handle::new(handle);
30+
ManuallyDrop::new(handle).write(data)
31+
}
32+
33+
impl Stdin {
34+
pub fn new() -> io::Result<Stdin> {
35+
Ok(Stdin { })
36+
}
37+
}
38+
39+
impl io::Read for Stdin {
40+
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
41+
let handle = get_handle(c::STD_INPUT_HANDLE)?;
42+
let handle = Handle::new(handle);
43+
ManuallyDrop::new(handle).read(buf)
44+
}
45+
}
46+
47+
impl Stdout {
48+
pub fn new() -> io::Result<Stdout> {
49+
Ok(Stdout)
50+
}
51+
}
52+
53+
impl io::Write for Stdout {
54+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
55+
write(c::STD_OUTPUT_HANDLE, buf)
56+
}
57+
58+
fn flush(&mut self) -> io::Result<()> {
59+
Ok(())
60+
}
61+
}
62+
63+
impl Stderr {
64+
pub fn new() -> io::Result<Stderr> {
65+
Ok(Stderr)
66+
}
67+
}
68+
69+
impl io::Write for Stderr {
70+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
71+
write(c::STD_ERROR_HANDLE, buf)
72+
}
73+
74+
fn flush(&mut self) -> io::Result<()> {
75+
Ok(())
76+
}
77+
}
78+
79+
pub fn is_ebadf(err: &io::Error) -> bool {
80+
err.raw_os_error() == Some(c::ERROR_INVALID_HANDLE as i32)
81+
}
82+
83+
pub fn panic_output() -> Option<impl io::Write> {
84+
Stderr::new().ok()
85+
}

‎src/libunwind/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ fn main() {
2828
println!("cargo:rustc-link-lib=gcc_s");
2929
} else if target.contains("dragonfly") {
3030
println!("cargo:rustc-link-lib=gcc_pic");
31-
} else if target.contains("windows-gnu") {
31+
} else if target.contains("pc-windows-gnu") {
3232
println!("cargo:rustc-link-lib=static-nobundle=gcc_eh");
3333
println!("cargo:rustc-link-lib=static-nobundle=pthread");
34+
} else if target.contains("uwp-windows-gnu") {
35+
println!("cargo:rustc-link-lib=unwind");
3436
} else if target.contains("fuchsia") {
3537
println!("cargo:rustc-link-lib=unwind");
3638
} else if target.contains("haiku") {

0 commit comments

Comments
 (0)
Please sign in to comment.