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 b9ef35a

Browse files
committedSep 25, 2024
Auto merge of rust-lang#130816 - matthiaskrgr:rollup-jy25phv, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#130549 (Add RISC-V vxworks targets) - rust-lang#130595 (Initial std library support for NuttX) - rust-lang#130734 (Fix: ices on virtual-function-elimination about principal trait) - rust-lang#130787 (Ban combination of GCE and new solver) - rust-lang#130809 (Update llvm triple for OpenHarmony targets) - rust-lang#130810 (Don't trap into the debugger on panics under Linux) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4a7aeff + bcb9d23 commit b9ef35a

File tree

22 files changed

+227
-100
lines changed

22 files changed

+227
-100
lines changed
 

‎panic_unwind/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ cfg_if::cfg_if! {
4848
target_os = "psp",
4949
target_os = "xous",
5050
target_os = "solid_asp3",
51-
all(target_family = "unix", not(any(target_os = "espidf", target_os = "rtems"))),
51+
all(target_family = "unix", not(any(target_os = "espidf", target_os = "rtems", target_os = "nuttx"))),
5252
all(target_vendor = "fortanix", target_env = "sgx"),
5353
target_family = "wasm",
5454
))] {

‎std/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ fn main() {
5454
|| target_os == "teeos"
5555
|| target_os == "zkvm"
5656
|| target_os == "rtems"
57+
|| target_os == "nuttx"
5758

5859
// See src/bootstrap/src/core/build_steps/synthetic_targets.rs
5960
|| env::var("RUSTC_BOOTSTRAP_SYNTHETIC_TARGET").is_ok()

‎std/src/os/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ pub mod macos;
139139
pub mod netbsd;
140140
#[cfg(target_os = "nto")]
141141
pub mod nto;
142+
#[cfg(target_os = "nuttx")]
143+
pub mod nuttx;
142144
#[cfg(target_os = "openbsd")]
143145
pub mod openbsd;
144146
#[cfg(target_os = "redox")]

‎std/src/os/nuttx/fs.rs

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#![stable(feature = "metadata_ext", since = "1.1.0")]
2+
3+
use crate::fs::Metadata;
4+
use crate::sys_common::AsInner;
5+
6+
#[stable(feature = "metadata_ext", since = "1.1.0")]
7+
pub trait MetadataExt {
8+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
9+
fn st_dev(&self) -> u64;
10+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
11+
fn st_ino(&self) -> u64;
12+
#[stable(feature = "metadata_ext", since = "1.1.0")]
13+
fn st_mode(&self) -> u32;
14+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
15+
fn st_nlink(&self) -> u64;
16+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
17+
fn st_uid(&self) -> u32;
18+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
19+
fn st_gid(&self) -> u32;
20+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
21+
fn st_rdev(&self) -> u64;
22+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
23+
fn st_size(&self) -> u64;
24+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
25+
fn st_atime(&self) -> i64;
26+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
27+
fn st_atime_nsec(&self) -> i64;
28+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
29+
fn st_mtime(&self) -> i64;
30+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
31+
fn st_mtime_nsec(&self) -> i64;
32+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
33+
fn st_ctime(&self) -> i64;
34+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
35+
fn st_ctime_nsec(&self) -> i64;
36+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
37+
fn st_blksize(&self) -> u64;
38+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
39+
fn st_blocks(&self) -> u64;
40+
}
41+
42+
#[stable(feature = "metadata_ext", since = "1.1.0")]
43+
impl MetadataExt for Metadata {
44+
fn st_dev(&self) -> u64 {
45+
self.as_inner().as_inner().st_dev as u64
46+
}
47+
fn st_ino(&self) -> u64 {
48+
self.as_inner().as_inner().st_ino as u64
49+
}
50+
fn st_mode(&self) -> u32 {
51+
self.as_inner().as_inner().st_mode as u32
52+
}
53+
fn st_nlink(&self) -> u64 {
54+
self.as_inner().as_inner().st_nlink as u64
55+
}
56+
fn st_uid(&self) -> u32 {
57+
self.as_inner().as_inner().st_uid as u32
58+
}
59+
fn st_gid(&self) -> u32 {
60+
self.as_inner().as_inner().st_gid as u32
61+
}
62+
fn st_rdev(&self) -> u64 {
63+
self.as_inner().as_inner().st_rdev as u64
64+
}
65+
fn st_size(&self) -> u64 {
66+
self.as_inner().as_inner().st_size as u64
67+
}
68+
fn st_atime(&self) -> i64 {
69+
self.as_inner().as_inner().st_atim.tv_sec as i64
70+
}
71+
fn st_atime_nsec(&self) -> i64 {
72+
self.as_inner().as_inner().st_atim.tv_nsec as i64
73+
}
74+
fn st_mtime(&self) -> i64 {
75+
self.as_inner().as_inner().st_mtim.tv_sec as i64
76+
}
77+
fn st_mtime_nsec(&self) -> i64 {
78+
self.as_inner().as_inner().st_mtim.tv_nsec as i64
79+
}
80+
fn st_ctime(&self) -> i64 {
81+
self.as_inner().as_inner().st_ctim.tv_sec as i64
82+
}
83+
fn st_ctime_nsec(&self) -> i64 {
84+
self.as_inner().as_inner().st_ctim.tv_nsec as i64
85+
}
86+
fn st_blksize(&self) -> u64 {
87+
self.as_inner().as_inner().st_blksize as u64
88+
}
89+
fn st_blocks(&self) -> u64 {
90+
self.as_inner().as_inner().st_blocks as u64
91+
}
92+
}

‎std/src/os/nuttx/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![stable(feature = "raw_ext", since = "1.1.0")]
2+
#![forbid(unsafe_op_in_unsafe_fn)]
3+
pub mod fs;
4+
pub(crate) mod raw;

‎std/src/os/nuttx/raw.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//! rtems raw type definitions
2+
3+
#![stable(feature = "raw_ext", since = "1.1.0")]
4+
#![deprecated(
5+
since = "1.8.0",
6+
note = "these type aliases are no longer supported by \
7+
the standard library, the `libc` crate on \
8+
crates.io should be used instead for the correct \
9+
definitions"
10+
)]
11+
#![allow(deprecated)]
12+
13+
#[stable(feature = "pthread_t", since = "1.8.0")]
14+
pub type pthread_t = libc::pthread_t;
15+
16+
#[stable(feature = "raw_ext", since = "1.1.0")]
17+
pub type blkcnt_t = libc::blkcnt_t;
18+
19+
#[stable(feature = "raw_ext", since = "1.1.0")]
20+
pub type blksize_t = libc::blksize_t;
21+
#[stable(feature = "raw_ext", since = "1.1.0")]
22+
pub type dev_t = libc::dev_t;
23+
#[stable(feature = "raw_ext", since = "1.1.0")]
24+
pub type ino_t = libc::ino_t;
25+
#[stable(feature = "raw_ext", since = "1.1.0")]
26+
pub type mode_t = libc::mode_t;
27+
#[stable(feature = "raw_ext", since = "1.1.0")]
28+
pub type nlink_t = libc::nlink_t;
29+
#[stable(feature = "raw_ext", since = "1.1.0")]
30+
pub type off_t = libc::off_t;
31+
32+
#[stable(feature = "raw_ext", since = "1.1.0")]
33+
pub type time_t = libc::time_t;

‎std/src/os/unix/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ mod platform {
6969
pub use crate::os::netbsd::*;
7070
#[cfg(target_os = "nto")]
7171
pub use crate::os::nto::*;
72+
#[cfg(target_os = "nuttx")]
73+
pub use crate::os::nuttx::*;
7274
#[cfg(target_os = "openbsd")]
7375
pub use crate::os::openbsd::*;
7476
#[cfg(target_os = "redox")]

‎std/src/sys/alloc/unix.rs

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ cfg_if::cfg_if! {
7171
}
7272
} else {
7373
#[inline]
74+
#[cfg_attr(target_os = "vxworks", allow(unused_unsafe))]
7475
unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 {
7576
let mut out = ptr::null_mut();
7677
// We prefer posix_memalign over aligned_alloc since it is more widely available, and

‎std/src/sys/dbg.rs

+1-78
Original file line numberDiff line numberDiff line change
@@ -105,84 +105,7 @@ mod os {
105105
}
106106
}
107107

108-
#[cfg(target_os = "linux")]
109-
mod os {
110-
use super::DebuggerPresence;
111-
use crate::fs::File;
112-
use crate::io::Read;
113-
114-
pub(super) fn is_debugger_present() -> Option<DebuggerPresence> {
115-
// This function is crafted with the following goals:
116-
// * Memory efficiency: It avoids crashing the panicking process due to
117-
// out-of-memory (OOM) conditions by not using large heap buffers or
118-
// allocating significant stack space, which could lead to stack overflow.
119-
// * Minimal binary size: The function uses a minimal set of facilities
120-
// from the standard library to avoid increasing the resulting binary size.
121-
//
122-
// To achieve these goals, the function does not use `[std::io::BufReader]`
123-
// and instead reads the file byte by byte using a sliding window approach.
124-
// It's important to note that the "/proc/self/status" pseudo-file is synthesized
125-
// by the Virtual File System (VFS), meaning it is not read from a slow or
126-
// non-volatile storage medium so buffering might not be as beneficial because
127-
// all data is read from memory, though this approach does incur a syscall for
128-
// each byte read.
129-
//
130-
// We cannot make assumptions about the file size or the position of the
131-
// target prefix ("TracerPid:"), so the function does not use
132-
// `[std::fs::read_to_string]` thus not employing UTF-8 to ASCII checking,
133-
// conversion, or parsing as we're looking for an ASCII prefix.
134-
//
135-
// These condiderations make the function deviate from the familiar concise pattern
136-
// of searching for a string in a text file.
137-
138-
fn read_byte(file: &mut File) -> Option<u8> {
139-
let mut buffer = [0];
140-
file.read_exact(&mut buffer).ok()?;
141-
Some(buffer[0])
142-
}
143-
144-
// The ASCII prefix of the datum we're interested in.
145-
const TRACER_PID: &[u8] = b"TracerPid:\t";
146-
147-
let mut file = File::open("/proc/self/status").ok()?;
148-
let mut matched = 0;
149-
150-
// Look for the `TRACER_PID` prefix.
151-
while let Some(byte) = read_byte(&mut file) {
152-
if byte == TRACER_PID[matched] {
153-
matched += 1;
154-
if matched == TRACER_PID.len() {
155-
break;
156-
}
157-
} else {
158-
matched = 0;
159-
}
160-
}
161-
162-
// Was the prefix found?
163-
if matched != TRACER_PID.len() {
164-
return None;
165-
}
166-
167-
// It was; get the ASCII representation of the first digit
168-
// of the PID. That is enough to see if there is a debugger
169-
// attached as the kernel does not pad the PID on the left
170-
// with the leading zeroes.
171-
let byte = read_byte(&mut file)?;
172-
if byte.is_ascii_digit() && byte != b'0' {
173-
Some(DebuggerPresence::Detected)
174-
} else {
175-
Some(DebuggerPresence::NotDetected)
176-
}
177-
}
178-
}
179-
180-
#[cfg(not(any(
181-
target_os = "windows",
182-
target_vendor = "apple",
183-
target_os = "freebsd",
184-
target_os = "linux"
185-
)))]
108+
#[cfg(not(any(target_os = "windows", target_vendor = "apple", target_os = "freebsd")))]
186109
mod os {
187110
pub(super) fn is_debugger_present() -> Option<super::DebuggerPresence> {
188111
None

‎std/src/sys/pal/unix/args.rs

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ impl DoubleEndedIterator for Args {
113113
target_os = "nto",
114114
target_os = "hurd",
115115
target_os = "rtems",
116+
target_os = "nuttx",
116117
))]
117118
mod imp {
118119
use crate::ffi::c_char;

‎std/src/sys/pal/unix/env.rs

+11
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,14 @@ pub mod os {
283283
pub const EXE_SUFFIX: &str = "";
284284
pub const EXE_EXTENSION: &str = "";
285285
}
286+
287+
#[cfg(target_os = "nuttx")]
288+
pub mod os {
289+
pub const FAMILY: &str = "unix";
290+
pub const OS: &str = "nuttx";
291+
pub const DLL_PREFIX: &str = "lib";
292+
pub const DLL_SUFFIX: &str = ".so";
293+
pub const DLL_EXTENSION: &str = "so";
294+
pub const EXE_SUFFIX: &str = "";
295+
pub const EXE_EXTENSION: &str = "";
296+
}

‎std/src/sys/pal/unix/fd.rs

+36-6
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ impl FileDesc {
9898
Ok(ret as usize)
9999
}
100100

101-
#[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "vita")))]
101+
#[cfg(not(any(
102+
target_os = "espidf",
103+
target_os = "horizon",
104+
target_os = "vita",
105+
target_os = "nuttx"
106+
)))]
102107
pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
103108
let ret = cvt(unsafe {
104109
libc::readv(
@@ -110,14 +115,24 @@ impl FileDesc {
110115
Ok(ret as usize)
111116
}
112117

113-
#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita"))]
118+
#[cfg(any(
119+
target_os = "espidf",
120+
target_os = "horizon",
121+
target_os = "vita",
122+
target_os = "nuttx"
123+
))]
114124
pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
115125
io::default_read_vectored(|b| self.read(b), bufs)
116126
}
117127

118128
#[inline]
119129
pub fn is_read_vectored(&self) -> bool {
120-
cfg!(not(any(target_os = "espidf", target_os = "horizon", target_os = "vita")))
130+
cfg!(not(any(
131+
target_os = "espidf",
132+
target_os = "horizon",
133+
target_os = "vita",
134+
target_os = "nuttx"
135+
)))
121136
}
122137

123138
pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> {
@@ -297,7 +312,12 @@ impl FileDesc {
297312
Ok(ret as usize)
298313
}
299314

300-
#[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "vita")))]
315+
#[cfg(not(any(
316+
target_os = "espidf",
317+
target_os = "horizon",
318+
target_os = "vita",
319+
target_os = "nuttx"
320+
)))]
301321
pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
302322
let ret = cvt(unsafe {
303323
libc::writev(
@@ -309,14 +329,24 @@ impl FileDesc {
309329
Ok(ret as usize)
310330
}
311331

312-
#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita"))]
332+
#[cfg(any(
333+
target_os = "espidf",
334+
target_os = "horizon",
335+
target_os = "vita",
336+
target_os = "nuttx"
337+
))]
313338
pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
314339
io::default_write_vectored(|b| self.write(b), bufs)
315340
}
316341

317342
#[inline]
318343
pub fn is_write_vectored(&self) -> bool {
319-
cfg!(not(any(target_os = "espidf", target_os = "horizon", target_os = "vita")))
344+
cfg!(not(any(
345+
target_os = "espidf",
346+
target_os = "horizon",
347+
target_os = "vita",
348+
target_os = "nuttx"
349+
)))
320350
}
321351

322352
#[cfg_attr(target_os = "vxworks", allow(unused_unsafe))]

0 commit comments

Comments
 (0)