Skip to content

Commit 52032c8

Browse files
authored
Unrolled build for rust-lang#119408
Rollup merge of rust-lang#119408 - betrusted-io:xous-fixes-add-network, r=Mark-Simulacrum xous: misc fixes + add network support This patchset makes several fixes to Xous support. Additionally, this patch adds networking support. Many of these fixes are the result of the recent patch to get `unwinding` support merged. As a result of this patch, we can now run rust tests. As a result of these tests, we now have 729 tests passing: ``` failures: env::tests::test env::tests::test_self_exe_path env::tests::vars_debug env::tests::vars_os_debug os::raw::tests::same path::tests::test_push path::tests::test_set_file_name time::tests::since_epoch test result: FAILED. 729 passed; 8 failed; 1 ignored; 0 measured; 0 filtered out; finished in 214.54s ``` In the course of fixing several tests and getting the test sequence to reliably run, several issues were found. This patchset fixes those issues.
2 parents 3066253 + 50e4fed commit 52032c8

File tree

20 files changed

+1770
-176
lines changed

20 files changed

+1770
-176
lines changed

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

+12-10
Original file line numberDiff line numberDiff line change
@@ -88,29 +88,31 @@ fn lend_impl(
8888
let a3 = opcode;
8989
let a4 = data.as_ptr() as usize;
9090
let a5 = data.len();
91-
let mut a6 = arg1;
92-
let mut a7 = arg2;
91+
let a6 = arg1;
92+
let a7 = arg2;
93+
let mut ret1;
94+
let mut ret2;
9395

9496
unsafe {
9597
core::arch::asm!(
9698
"ecall",
9799
inlateout("a0") a0,
98-
inlateout("a1") a1 => _,
99-
inlateout("a2") a2 => _,
100+
inlateout("a1") a1 => ret1,
101+
inlateout("a2") a2 => ret2,
100102
inlateout("a3") a3 => _,
101103
inlateout("a4") a4 => _,
102104
inlateout("a5") a5 => _,
103-
inlateout("a6") a6,
104-
inlateout("a7") a7,
105+
inlateout("a6") a6 => _,
106+
inlateout("a7") a7 => _,
105107
)
106108
};
107109

108110
let result = a0;
109111

110112
if result == SyscallResult::MemoryReturned as usize {
111-
Ok((a6, a7))
113+
Ok((ret1, ret2))
112114
} else if result == SyscallResult::Error as usize {
113-
Err(a1.into())
115+
Err(ret1.into())
114116
} else {
115117
Err(Error::InternalError)
116118
}
@@ -405,7 +407,7 @@ pub(crate) unsafe fn map_memory<T>(
405407
pub(crate) unsafe fn unmap_memory<T>(range: *mut [T]) -> Result<(), Error> {
406408
let mut a0 = Syscall::UnmapMemory as usize;
407409
let mut a1 = range.as_mut_ptr() as usize;
408-
let a2 = range.len();
410+
let a2 = range.len() * core::mem::size_of::<T>();
409411
let a3 = 0;
410412
let a4 = 0;
411413
let a5 = 0;
@@ -450,7 +452,7 @@ pub(crate) unsafe fn update_memory_flags<T>(
450452
) -> Result<(), Error> {
451453
let mut a0 = Syscall::UpdateMemoryFlags as usize;
452454
let mut a1 = range.as_mut_ptr() as usize;
453-
let a2 = range.len();
455+
let a2 = range.len() * core::mem::size_of::<T>();
454456
let a3 = new_flags.bits();
455457
let a4 = 0; // Process ID is currently None
456458
let a5 = 0;

library/std/src/os/xous/services.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
use crate::os::xous::ffi::Connection;
22
use core::sync::atomic::{AtomicU32, Ordering};
33

4+
mod dns;
5+
pub(crate) use dns::*;
6+
47
mod log;
58
pub(crate) use log::*;
69

10+
mod net;
11+
pub(crate) use net::*;
12+
713
mod systime;
814
pub(crate) use systime::*;
915

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use crate::os::xous::ffi::Connection;
2+
use crate::os::xous::services::connect;
3+
use core::sync::atomic::{AtomicU32, Ordering};
4+
5+
#[repr(usize)]
6+
pub(crate) enum DnsLendMut {
7+
RawLookup = 6,
8+
}
9+
10+
impl Into<usize> for DnsLendMut {
11+
fn into(self) -> usize {
12+
self as usize
13+
}
14+
}
15+
16+
/// Return a `Connection` to the DNS lookup server. This server is used for
17+
/// querying domain name values.
18+
pub(crate) fn dns_server() -> Connection {
19+
static DNS_CONNECTION: AtomicU32 = AtomicU32::new(0);
20+
let cid = DNS_CONNECTION.load(Ordering::Relaxed);
21+
if cid != 0 {
22+
return cid.into();
23+
}
24+
25+
let cid = connect("_DNS Resolver Middleware_").unwrap();
26+
DNS_CONNECTION.store(cid.into(), Ordering::Relaxed);
27+
cid
28+
}

library/std/src/os/xous/services/log.rs

+11
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ impl<'a> Into<[usize; 5]> for LogScalar<'a> {
4545
}
4646
}
4747

48+
pub(crate) enum LogLend {
49+
StandardOutput = 1,
50+
StandardError = 2,
51+
}
52+
53+
impl Into<usize> for LogLend {
54+
fn into(self) -> usize {
55+
self as usize
56+
}
57+
}
58+
4859
/// Return a `Connection` to the log server, which is used for printing messages to
4960
/// the console and reporting panics. If the log server has not yet started, this
5061
/// will block until the server is running. It is safe to call this multiple times,
+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
use crate::os::xous::ffi::Connection;
2+
use crate::os::xous::services::connect;
3+
use core::sync::atomic::{AtomicU32, Ordering};
4+
5+
pub(crate) enum NetBlockingScalar {
6+
StdGetTtlUdp(u16 /* fd */), /* 36 */
7+
StdSetTtlUdp(u16 /* fd */, u32 /* ttl */), /* 37 */
8+
StdGetTtlTcp(u16 /* fd */), /* 36 */
9+
StdSetTtlTcp(u16 /* fd */, u32 /* ttl */), /* 37 */
10+
StdGetNodelay(u16 /* fd */), /* 38 */
11+
StdSetNodelay(u16 /* fd */, bool), /* 39 */
12+
StdTcpClose(u16 /* fd */), /* 34 */
13+
StdUdpClose(u16 /* fd */), /* 41 */
14+
StdTcpStreamShutdown(u16 /* fd */, crate::net::Shutdown /* how */), /* 46 */
15+
}
16+
17+
pub(crate) enum NetLendMut {
18+
StdTcpConnect, /* 30 */
19+
StdTcpTx(u16 /* fd */), /* 31 */
20+
StdTcpPeek(u16 /* fd */, bool /* nonblocking */), /* 32 */
21+
StdTcpRx(u16 /* fd */, bool /* nonblocking */), /* 33 */
22+
StdGetAddress(u16 /* fd */), /* 35 */
23+
StdUdpBind, /* 40 */
24+
StdUdpRx(u16 /* fd */), /* 42 */
25+
StdUdpTx(u16 /* fd */), /* 43 */
26+
StdTcpListen, /* 44 */
27+
StdTcpAccept(u16 /* fd */), /* 45 */
28+
}
29+
30+
impl Into<usize> for NetLendMut {
31+
fn into(self) -> usize {
32+
match self {
33+
NetLendMut::StdTcpConnect => 30,
34+
NetLendMut::StdTcpTx(fd) => 31 | ((fd as usize) << 16),
35+
NetLendMut::StdTcpPeek(fd, blocking) => {
36+
32 | ((fd as usize) << 16) | if blocking { 0x8000 } else { 0 }
37+
}
38+
NetLendMut::StdTcpRx(fd, blocking) => {
39+
33 | ((fd as usize) << 16) | if blocking { 0x8000 } else { 0 }
40+
}
41+
NetLendMut::StdGetAddress(fd) => 35 | ((fd as usize) << 16),
42+
NetLendMut::StdUdpBind => 40,
43+
NetLendMut::StdUdpRx(fd) => 42 | ((fd as usize) << 16),
44+
NetLendMut::StdUdpTx(fd) => 43 | ((fd as usize) << 16),
45+
NetLendMut::StdTcpListen => 44,
46+
NetLendMut::StdTcpAccept(fd) => 45 | ((fd as usize) << 16),
47+
}
48+
}
49+
}
50+
51+
impl<'a> Into<[usize; 5]> for NetBlockingScalar {
52+
fn into(self) -> [usize; 5] {
53+
match self {
54+
NetBlockingScalar::StdGetTtlTcp(fd) => [36 | ((fd as usize) << 16), 0, 0, 0, 0],
55+
NetBlockingScalar::StdGetTtlUdp(fd) => [36 | ((fd as usize) << 16), 0, 0, 0, 1],
56+
NetBlockingScalar::StdSetTtlTcp(fd, ttl) => {
57+
[37 | ((fd as usize) << 16), ttl as _, 0, 0, 0]
58+
}
59+
NetBlockingScalar::StdSetTtlUdp(fd, ttl) => {
60+
[37 | ((fd as usize) << 16), ttl as _, 0, 0, 1]
61+
}
62+
NetBlockingScalar::StdGetNodelay(fd) => [38 | ((fd as usize) << 16), 0, 0, 0, 0],
63+
NetBlockingScalar::StdSetNodelay(fd, enabled) => {
64+
[39 | ((fd as usize) << 16), if enabled { 1 } else { 0 }, 0, 0, 1]
65+
}
66+
NetBlockingScalar::StdTcpClose(fd) => [34 | ((fd as usize) << 16), 0, 0, 0, 0],
67+
NetBlockingScalar::StdUdpClose(fd) => [41 | ((fd as usize) << 16), 0, 0, 0, 0],
68+
NetBlockingScalar::StdTcpStreamShutdown(fd, how) => [
69+
46 | ((fd as usize) << 16),
70+
match how {
71+
crate::net::Shutdown::Read => 1,
72+
crate::net::Shutdown::Write => 2,
73+
crate::net::Shutdown::Both => 3,
74+
},
75+
0,
76+
0,
77+
0,
78+
],
79+
}
80+
}
81+
}
82+
83+
/// Return a `Connection` to the Network server. This server provides all
84+
/// OS-level networking functions.
85+
pub(crate) fn net_server() -> Connection {
86+
static NET_CONNECTION: AtomicU32 = AtomicU32::new(0);
87+
let cid = NET_CONNECTION.load(Ordering::Relaxed);
88+
if cid != 0 {
89+
return cid.into();
90+
}
91+
92+
let cid = connect("_Middleware Network Server_").unwrap();
93+
NET_CONNECTION.store(cid.into(), Ordering::Relaxed);
94+
cid
95+
}

library/std/src/sys/pal/xous/alloc.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
use crate::alloc::{GlobalAlloc, Layout, System};
22

3+
#[cfg(not(test))]
4+
#[export_name = "_ZN16__rust_internals3std3sys4xous5alloc8DLMALLOCE"]
35
static mut DLMALLOC: dlmalloc::Dlmalloc = dlmalloc::Dlmalloc::new();
46

7+
#[cfg(test)]
8+
extern "Rust" {
9+
#[link_name = "_ZN16__rust_internals3std3sys4xous5alloc8DLMALLOCE"]
10+
static mut DLMALLOC: dlmalloc::Dlmalloc;
11+
}
12+
513
#[stable(feature = "alloc_system_type", since = "1.28.0")]
614
unsafe impl GlobalAlloc for System {
715
#[inline]

0 commit comments

Comments
 (0)