Skip to content

Commit c526632

Browse files
committed
std: add platform support for hexagon-unknown-qurt
QuRT provides POSIX-like APIs for basic operations, so this implementation reuses the unix platform abstraction layer with QuRT-specific customizations. Platform modules: - New os::qurt module with platform-specific extensions to ffi, fs, io, raw - QuRT-specific file handling for ino, dev, mode, nlink, etc. Unsupported: Networking, fork/exec, pipe, chown/fchown/lchown/chroot/mkfifo
1 parent a72e2a7 commit c526632

40 files changed

Lines changed: 570 additions & 67 deletions

File tree

library/std/src/os/fd/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ mod raw;
1313
mod owned;
1414

1515
// Implementations for `AsRawFd` etc. for network types.
16-
#[cfg(not(target_os = "trusty"))]
16+
#[cfg(not(any(target_os = "trusty", target_os = "qurt")))]
1717
mod net;
1818

1919
// Implementation of stdio file descriptor constants.
2020
mod stdio;
2121

22-
#[cfg(test)]
22+
#[cfg(all(test, not(target_os = "qurt")))]
2323
mod tests;
2424

2525
// Export the types and traits for the public API.

library/std/src/os/fd/owned.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl Drop for OwnedFd {
210210
// the latest POSIX wording: http://austingroupbugs.net/view.php?id=529
211211
#[cfg(not(target_os = "hermit"))]
212212
{
213-
#[cfg(unix)]
213+
#[cfg(all(unix, not(target_os = "qurt")))]
214214
crate::sys::fs::debug_assert_fd_is_open(self.fd.as_inner());
215215

216216
let _ = libc::close(self.fd.as_inner());
@@ -344,7 +344,7 @@ impl From<OwnedFd> for fs::File {
344344
}
345345

346346
#[stable(feature = "io_safety", since = "1.63.0")]
347-
#[cfg(not(target_os = "trusty"))]
347+
#[cfg(not(any(target_os = "trusty", target_os = "qurt")))]
348348
impl AsFd for crate::net::TcpStream {
349349
#[inline]
350350
fn as_fd(&self) -> BorrowedFd<'_> {
@@ -353,7 +353,7 @@ impl AsFd for crate::net::TcpStream {
353353
}
354354

355355
#[stable(feature = "io_safety", since = "1.63.0")]
356-
#[cfg(not(target_os = "trusty"))]
356+
#[cfg(not(any(target_os = "trusty", target_os = "qurt")))]
357357
impl From<crate::net::TcpStream> for OwnedFd {
358358
/// Takes ownership of a [`TcpStream`](crate::net::TcpStream)'s socket file descriptor.
359359
#[inline]
@@ -363,7 +363,7 @@ impl From<crate::net::TcpStream> for OwnedFd {
363363
}
364364

365365
#[stable(feature = "io_safety", since = "1.63.0")]
366-
#[cfg(not(target_os = "trusty"))]
366+
#[cfg(not(any(target_os = "trusty", target_os = "qurt")))]
367367
impl From<OwnedFd> for crate::net::TcpStream {
368368
#[inline]
369369
fn from(owned_fd: OwnedFd) -> Self {
@@ -374,7 +374,7 @@ impl From<OwnedFd> for crate::net::TcpStream {
374374
}
375375

376376
#[stable(feature = "io_safety", since = "1.63.0")]
377-
#[cfg(not(target_os = "trusty"))]
377+
#[cfg(not(any(target_os = "trusty", target_os = "qurt")))]
378378
impl AsFd for crate::net::TcpListener {
379379
#[inline]
380380
fn as_fd(&self) -> BorrowedFd<'_> {
@@ -383,7 +383,7 @@ impl AsFd for crate::net::TcpListener {
383383
}
384384

385385
#[stable(feature = "io_safety", since = "1.63.0")]
386-
#[cfg(not(target_os = "trusty"))]
386+
#[cfg(not(any(target_os = "trusty", target_os = "qurt")))]
387387
impl From<crate::net::TcpListener> for OwnedFd {
388388
/// Takes ownership of a [`TcpListener`](crate::net::TcpListener)'s socket file descriptor.
389389
#[inline]
@@ -393,7 +393,7 @@ impl From<crate::net::TcpListener> for OwnedFd {
393393
}
394394

395395
#[stable(feature = "io_safety", since = "1.63.0")]
396-
#[cfg(not(target_os = "trusty"))]
396+
#[cfg(not(any(target_os = "trusty", target_os = "qurt")))]
397397
impl From<OwnedFd> for crate::net::TcpListener {
398398
#[inline]
399399
fn from(owned_fd: OwnedFd) -> Self {
@@ -404,7 +404,7 @@ impl From<OwnedFd> for crate::net::TcpListener {
404404
}
405405

406406
#[stable(feature = "io_safety", since = "1.63.0")]
407-
#[cfg(not(target_os = "trusty"))]
407+
#[cfg(not(any(target_os = "trusty", target_os = "qurt")))]
408408
impl AsFd for crate::net::UdpSocket {
409409
#[inline]
410410
fn as_fd(&self) -> BorrowedFd<'_> {
@@ -413,7 +413,7 @@ impl AsFd for crate::net::UdpSocket {
413413
}
414414

415415
#[stable(feature = "io_safety", since = "1.63.0")]
416-
#[cfg(not(target_os = "trusty"))]
416+
#[cfg(not(any(target_os = "trusty", target_os = "qurt")))]
417417
impl From<crate::net::UdpSocket> for OwnedFd {
418418
/// Takes ownership of a [`UdpSocket`](crate::net::UdpSocket)'s file descriptor.
419419
#[inline]
@@ -423,7 +423,7 @@ impl From<crate::net::UdpSocket> for OwnedFd {
423423
}
424424

425425
#[stable(feature = "io_safety", since = "1.63.0")]
426-
#[cfg(not(target_os = "trusty"))]
426+
#[cfg(not(any(target_os = "trusty", target_os = "qurt")))]
427427
impl From<OwnedFd> for crate::net::UdpSocket {
428428
#[inline]
429429
fn from(owned_fd: OwnedFd) -> Self {
@@ -532,47 +532,47 @@ impl<'a> AsFd for io::StderrLock<'a> {
532532
}
533533

534534
#[stable(feature = "anonymous_pipe", since = "1.87.0")]
535-
#[cfg(not(target_os = "trusty"))]
535+
#[cfg(not(any(target_os = "trusty", target_os = "qurt")))]
536536
impl AsFd for io::PipeReader {
537537
fn as_fd(&self) -> BorrowedFd<'_> {
538538
self.0.as_fd()
539539
}
540540
}
541541

542542
#[stable(feature = "anonymous_pipe", since = "1.87.0")]
543-
#[cfg(not(target_os = "trusty"))]
543+
#[cfg(not(any(target_os = "trusty", target_os = "qurt")))]
544544
impl From<io::PipeReader> for OwnedFd {
545545
fn from(pipe: io::PipeReader) -> Self {
546546
pipe.0.into_inner()
547547
}
548548
}
549549

550550
#[stable(feature = "anonymous_pipe", since = "1.87.0")]
551-
#[cfg(not(target_os = "trusty"))]
551+
#[cfg(not(any(target_os = "trusty", target_os = "qurt")))]
552552
impl AsFd for io::PipeWriter {
553553
fn as_fd(&self) -> BorrowedFd<'_> {
554554
self.0.as_fd()
555555
}
556556
}
557557

558558
#[stable(feature = "anonymous_pipe", since = "1.87.0")]
559-
#[cfg(not(target_os = "trusty"))]
559+
#[cfg(not(any(target_os = "trusty", target_os = "qurt")))]
560560
impl From<io::PipeWriter> for OwnedFd {
561561
fn from(pipe: io::PipeWriter) -> Self {
562562
pipe.0.into_inner()
563563
}
564564
}
565565

566566
#[stable(feature = "anonymous_pipe", since = "1.87.0")]
567-
#[cfg(not(target_os = "trusty"))]
567+
#[cfg(not(any(target_os = "trusty", target_os = "qurt")))]
568568
impl From<OwnedFd> for io::PipeReader {
569569
fn from(owned_fd: OwnedFd) -> Self {
570570
Self(FromInner::from_inner(owned_fd))
571571
}
572572
}
573573

574574
#[stable(feature = "anonymous_pipe", since = "1.87.0")]
575-
#[cfg(not(target_os = "trusty"))]
575+
#[cfg(not(any(target_os = "trusty", target_os = "qurt")))]
576576
impl From<OwnedFd> for io::PipeWriter {
577577
fn from(owned_fd: OwnedFd) -> Self {
578578
Self(FromInner::from_inner(owned_fd))

library/std/src/os/fd/raw.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl IntoRawFd for fs::File {
193193
}
194194

195195
#[stable(feature = "asraw_stdio", since = "1.21.0")]
196-
#[cfg(not(target_os = "trusty"))]
196+
#[cfg(not(any(target_os = "trusty", target_os = "qurt")))]
197197
impl AsRawFd for io::Stdin {
198198
#[inline]
199199
fn as_raw_fd(&self) -> RawFd {
@@ -202,6 +202,7 @@ impl AsRawFd for io::Stdin {
202202
}
203203

204204
#[stable(feature = "asraw_stdio", since = "1.21.0")]
205+
#[cfg(not(target_os = "qurt"))]
205206
impl AsRawFd for io::Stdout {
206207
#[inline]
207208
fn as_raw_fd(&self) -> RawFd {
@@ -210,6 +211,7 @@ impl AsRawFd for io::Stdout {
210211
}
211212

212213
#[stable(feature = "asraw_stdio", since = "1.21.0")]
214+
#[cfg(not(target_os = "qurt"))]
213215
impl AsRawFd for io::Stderr {
214216
#[inline]
215217
fn as_raw_fd(&self) -> RawFd {
@@ -218,7 +220,7 @@ impl AsRawFd for io::Stderr {
218220
}
219221

220222
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")]
221-
#[cfg(not(target_os = "trusty"))]
223+
#[cfg(not(any(target_os = "trusty", target_os = "qurt")))]
222224
impl<'a> AsRawFd for io::StdinLock<'a> {
223225
#[inline]
224226
fn as_raw_fd(&self) -> RawFd {
@@ -227,6 +229,7 @@ impl<'a> AsRawFd for io::StdinLock<'a> {
227229
}
228230

229231
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")]
232+
#[cfg(not(target_os = "qurt"))]
230233
impl<'a> AsRawFd for io::StdoutLock<'a> {
231234
#[inline]
232235
fn as_raw_fd(&self) -> RawFd {
@@ -235,6 +238,7 @@ impl<'a> AsRawFd for io::StdoutLock<'a> {
235238
}
236239

237240
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")]
241+
#[cfg(not(target_os = "qurt"))]
238242
impl<'a> AsRawFd for io::StderrLock<'a> {
239243
#[inline]
240244
fn as_raw_fd(&self) -> RawFd {

library/std/src/os/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ pub mod nto;
165165
pub mod nuttx;
166166
#[cfg(target_os = "openbsd")]
167167
pub mod openbsd;
168+
#[cfg(target_os = "qurt")]
169+
pub mod qurt;
168170
#[cfg(target_os = "redox")]
169171
pub mod redox;
170172
#[cfg(target_os = "rtems")]

library/std/src/os/qurt/ffi.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//! QuRT-specific extension to the primitives in the [`std::ffi`] module.
2+
//!
3+
//! [`std::ffi`]: crate::ffi
4+
5+
#![stable(feature = "raw_ext", since = "1.1.0")]
6+
7+
use crate::ffi::{OsStr, OsString};
8+
use crate::mem;
9+
use crate::sealed::Sealed;
10+
use crate::sys::os_str::Buf;
11+
use crate::sys::{AsInner, FromInner, IntoInner};
12+
13+
/// QuRT-specific extensions to [`OsString`].
14+
///
15+
/// This trait is sealed: it cannot be implemented outside the standard library.
16+
#[stable(feature = "raw_ext", since = "1.1.0")]
17+
pub trait OsStringExt: Sealed {
18+
/// Creates an [`OsString`] from a byte vector.
19+
#[stable(feature = "raw_ext", since = "1.1.0")]
20+
fn from_vec(vec: Vec<u8>) -> Self;
21+
22+
/// Yields the underlying byte vector of this [`OsString`].
23+
#[stable(feature = "raw_ext", since = "1.1.0")]
24+
fn into_vec(self) -> Vec<u8>;
25+
}
26+
27+
#[stable(feature = "raw_ext", since = "1.1.0")]
28+
impl OsStringExt for OsString {
29+
#[inline]
30+
fn from_vec(vec: Vec<u8>) -> OsString {
31+
FromInner::from_inner(Buf { inner: vec })
32+
}
33+
34+
#[inline]
35+
fn into_vec(self) -> Vec<u8> {
36+
self.into_inner().inner
37+
}
38+
}
39+
40+
/// QuRT-specific extensions to [`OsStr`].
41+
///
42+
/// This trait is sealed: it cannot be implemented outside the standard library.
43+
#[stable(feature = "raw_ext", since = "1.1.0")]
44+
pub trait OsStrExt: Sealed {
45+
#[stable(feature = "raw_ext", since = "1.1.0")]
46+
/// Creates an [`OsStr`] from a byte slice.
47+
fn from_bytes(slice: &[u8]) -> &Self;
48+
49+
/// Gets the underlying byte view of the [`OsStr`] slice.
50+
#[stable(feature = "raw_ext", since = "1.1.0")]
51+
fn as_bytes(&self) -> &[u8];
52+
}
53+
54+
#[stable(feature = "raw_ext", since = "1.1.0")]
55+
impl OsStrExt for OsStr {
56+
#[inline]
57+
fn from_bytes(slice: &[u8]) -> &OsStr {
58+
unsafe { mem::transmute(slice) }
59+
}
60+
61+
#[inline]
62+
fn as_bytes(&self) -> &[u8] {
63+
&self.as_inner().inner
64+
}
65+
}

0 commit comments

Comments
 (0)