Skip to content

Commit c52e059

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 3ea711f commit c52e059

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
@@ -18,6 +18,7 @@ pub mod net;
1818
pub mod os_str;
1919
pub mod path;
2020
pub mod random;
21+
pub mod stdio;
2122
pub mod sync;
2223
pub mod thread_local;
2324

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

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

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
@@ -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
pub mod thread_parking;
2423
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
@@ -27,7 +27,6 @@ pub mod os;
2727
pub mod pipe;
2828
#[path = "../unsupported/process.rs"]
2929
pub mod process;
30-
pub mod stdio;
3130
pub use self::itron::{thread, thread_parking};
3231
pub mod time;
3332

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub mod os;
1616
pub mod pipe;
1717
#[path = "../unsupported/process.rs"]
1818
pub mod process;
19-
pub mod stdio;
2019
pub mod thread;
2120
#[allow(non_upper_case_globals)]
2221
#[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
@@ -20,7 +20,6 @@ pub mod os;
2020
#[path = "../unsupported/pipe.rs"]
2121
pub mod pipe;
2222
pub mod process;
23-
pub mod stdio;
2423
pub mod thread;
2524
pub mod time;
2625

library/std/src/sys/pal/unix/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
pub mod process;
2020
pub mod stack_overflow;
21-
pub mod stdio;
2221
pub mod sync;
2322
pub mod thread;
2423
pub mod thread_parking;

0 commit comments

Comments
 (0)