Skip to content

Commit 489e9c4

Browse files
committed
std: move stdio to sys
As per #117276, this moves the platform definitions of `Stdout` and friends into `sys`. This PR also unifies the UNIX and Hermit implementations and moves the `__rust_print_err` function needed by libunwind on SGX into the dedicated module for such helper functions.
1 parent 4559163 commit 489e9c4

File tree

29 files changed

+77
-150
lines changed

29 files changed

+77
-150
lines changed

library/std/src/sys/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub mod net;
1717
pub mod os_str;
1818
pub mod path;
1919
pub mod random;
20+
pub mod stdio;
2021
pub mod sync;
2122
pub mod thread_local;
2223

library/std/src/sys/pal/hermit/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ pub mod os;
2828
pub mod pipe;
2929
#[path = "../unsupported/process.rs"]
3030
pub mod process;
31-
pub mod stdio;
3231
pub mod thread;
3332
pub mod time;
3433

library/std/src/sys/pal/hermit/stdio.rs

Lines changed: 0 additions & 97 deletions
This file was deleted.

library/std/src/sys/pal/sgx/abi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use core::sync::atomic::{AtomicUsize, Ordering};
66
use crate::io::Write;
77

88
// runtime features
9-
pub(super) mod panic;
9+
pub mod panic;
1010
mod reloc;
1111

1212
// library features

library/std/src/sys/pal/sgx/libunwind_integration.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![cfg(not(test))]
55

66
use crate::sys::sync::RwLock;
7+
use crate::{slice, str};
78

89
// Verify that the byte pattern libunwind uses to initialize an RwLock is
910
// equivalent to the value of RwLock::new(). If the value changes,
@@ -44,3 +45,14 @@ pub unsafe extern "C" fn __rust_rwlock_unlock(p: *mut RwLock) -> i32 {
4445
unsafe { (*p).write_unlock() };
4546
return 0;
4647
}
48+
49+
#[unsafe(no_mangle)]
50+
pub unsafe extern "C" fn __rust_print_err(m: *mut u8, s: i32) {
51+
if s < 0 {
52+
return;
53+
}
54+
let buf = unsafe { slice::from_raw_parts(m as *const u8, s as _) };
55+
if let Ok(s) = str::from_utf8(&buf[..buf.iter().position(|&b| b == 0).unwrap_or(buf.len())]) {
56+
eprint!("{s}");
57+
}
58+
}

library/std/src/sys/pal/sgx/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub mod os;
2020
pub mod pipe;
2121
#[path = "../unsupported/process.rs"]
2222
pub mod process;
23-
pub mod stdio;
2423
pub mod thread;
2524
pub mod thread_parking;
2625
pub mod time;

library/std/src/sys/pal/solid/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ pub mod os;
2828
pub mod pipe;
2929
#[path = "../unsupported/process.rs"]
3030
pub mod process;
31-
pub mod stdio;
3231
pub use self::itron::{thread, thread_parking};
3332
pub mod time;
3433

library/std/src/sys/pal/teeos/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ pub mod os;
1818
pub mod pipe;
1919
#[path = "../unsupported/process.rs"]
2020
pub mod process;
21-
pub mod stdio;
2221
pub mod thread;
2322
#[allow(non_upper_case_globals)]
2423
#[path = "../unix/time.rs"]

library/std/src/sys/pal/uefi/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub mod os;
2121
#[path = "../unsupported/pipe.rs"]
2222
pub mod pipe;
2323
pub mod process;
24-
pub mod stdio;
2524
pub mod thread;
2625
pub mod time;
2726

library/std/src/sys/pal/unix/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub mod os;
1919
pub mod pipe;
2020
pub mod process;
2121
pub mod stack_overflow;
22-
pub mod stdio;
2322
pub mod sync;
2423
pub mod thread;
2524
pub mod thread_parking;

0 commit comments

Comments
 (0)