Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions common_service/ruxfdtab/src/as_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ extern crate alloc;
use std::path::PathBuf;

use alloc::vec;
use ms_std::{libos::libos, sync::UPSafeCell};
use spin::Mutex;
use ms_std::{libos::libos};

use crate::{
fd_ops::{close_file_like, get_file_like},
Expand All @@ -21,6 +20,8 @@ use ruxdriver::init_drivers;
use ruxfs::init_blkfs;

use ruxfdtable::{FileLike, RuxStat};

#[allow(unused_imports)]
use ruxfs::{fops::OpenOptions, init_filesystems, init_tempfs, prepare_commonfs};

fn convert(ruxstat: RuxStat) -> Stat {
Expand Down
1 change: 1 addition & 0 deletions libmsvisor/src/isolation/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{collections::BTreeMap, fs, io::BufReader, path::PathBuf};
use anyhow;
use log::{debug, warn};
use ms_hostcall::types::ServiceName;
#[allow(unused_imports)]
use serde::{Deserialize, Serialize};

use std::io;
Expand Down
13 changes: 6 additions & 7 deletions ms_std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use ms_hostcall::{
use crate::{
io::{Read, Write},
libos::libos,
println,
};

pub struct File {
Expand Down Expand Up @@ -47,15 +46,15 @@ impl File {
pub fn metadata(&self) -> FdtabResult<Stat> {
libos!(stat(self.raw_fd))
}

pub fn write_str(&mut self, s: &str) -> core::fmt::Result {
self.write_all(s.as_bytes()).map_err(|_| core::fmt::Error)
}
}

impl Write for File {
fn write_str(&mut self, s: &str) -> core::fmt::Result {
if libos!(write(self.raw_fd, s.as_bytes())).is_err() {
Err(core::fmt::Error)?
}

Ok(())
fn write(&mut self, buf: &[u8]) -> Result<usize, FdtabError> {
libos!(write(self.raw_fd, buf))
}
}

Expand Down
19 changes: 17 additions & 2 deletions ms_std/src/io.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
pub use core::fmt::Write;

use alloc::{
string::{String, ToString},
vec::Vec,
Expand Down Expand Up @@ -34,3 +32,20 @@ pub trait Read {
Ok(buf.len())
}
}

pub trait Write {
fn write(&mut self, buf: &[u8]) -> Result<usize, FdtabError>;

fn write_all(&mut self, mut buf: &[u8]) -> Result<(), FdtabError> {
while !buf.is_empty() {
match self.write(buf) {
Ok(0) => {
panic!("write data failed")
}
Ok(n) => buf = &buf[n..],
Err(e) => return Err(e),
}
}
Ok(())
}
}
47 changes: 27 additions & 20 deletions ms_std/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ use core::{
};

use alloc::vec::Vec;
use ms_hostcall::{fdtab::FdtabError, types::Fd};
use ms_hostcall::{fdtab::FdtabError, socket::SmoltcpError, types::Fd};

use crate::{io::Write, libos::libos};
use crate::{
io::{Read, Write},
libos::libos,
};

pub struct TcpStream {
raw_fd: Fd,
}

impl TcpStream {
pub fn connect(addr: SocketAddr) -> Result<Self, FdtabError> {
pub fn connect<A: ToSocketAddrs>(addr: A) -> Result<Self, FdtabError> {
// println!("connect to {}", addr);

let sockaddrv4 = match addr.inner {
let sockaddrv4 = match addr.to_socket_addrs()?.inner {
core::net::SocketAddr::V4(addr) => addr,
core::net::SocketAddr::V6(_) => todo!(),
};
Expand All @@ -26,20 +29,20 @@ impl TcpStream {
Ok(stream)
}

pub fn write_all(&mut self, data: &[u8]) -> Result<(), FdtabError> {
let _ = libos!(write(self.raw_fd, data))?;
// println!("TcpStream write {} bytes.", data.len());
Ok(())
}
// fn write_str(&mut self, s: &str) -> core::fmt::Result {
// self.write_all(s.as_bytes()).map_err(|_| core::fmt::Error)
// }
}

pub fn read(&mut self, buf: &mut [u8]) -> Result<usize, FdtabError> {
libos!(read(self.raw_fd, buf))
impl Write for TcpStream {
fn write(&mut self, buf: &[u8]) -> Result<usize, FdtabError> {
libos!(write(self.raw_fd, buf))
}
}

impl Write for TcpStream {
fn write_str(&mut self, s: &str) -> core::fmt::Result {
self.write_all(s.as_bytes()).map_err(|_| core::fmt::Error)
impl Read for TcpStream {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, FdtabError> {
libos!(read(self.raw_fd, buf))
}
}

Expand Down Expand Up @@ -68,8 +71,8 @@ pub struct TcpListener {
}

impl TcpListener {
pub fn bind(url: &str) -> Result<Self, FdtabError> {
let addr: SocketAddr = url.into();
pub fn bind<A: ToSocketAddrs>(url: A) -> Result<Self, FdtabError> {
let addr: SocketAddr = url.to_socket_addrs().unwrap();
let sockaddrv4 = match addr.inner {
core::net::SocketAddr::V4(addr) => addr,
core::net::SocketAddr::V6(_) => todo!(),
Expand Down Expand Up @@ -106,12 +109,16 @@ impl Display for SocketAddr {
}
}

impl From<&str> for SocketAddr {
fn from(value: &str) -> Self {
pub trait ToSocketAddrs {
fn to_socket_addrs(&self) -> Result<SocketAddr, SmoltcpError>;
}

impl ToSocketAddrs for &str {
fn to_socket_addrs(&self) -> Result<SocketAddr, SmoltcpError> {
let mut sockaddr = SocketAddr::default();

let (ip, port) = {
let target_tuple: Vec<&str> = value.split(':').collect();
let target_tuple: Vec<&str> = self.split(':').collect();
let host_str = target_tuple[0];
let addr = if let Ok(addr) = host_str.parse() {
addr
Expand All @@ -129,6 +136,6 @@ impl From<&str> for SocketAddr {

sockaddr.inner = core::net::SocketAddr::from(SocketAddrV4::new(ip, port));

sockaddr
Ok(sockaddr)
}
}
2 changes: 2 additions & 0 deletions ms_std/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub extern crate alloc;
pub use crate::agent::{DataBuffer, FaaSFuncResult as Result};
pub use crate::println;

pub use alloc::string::String;
1 change: 1 addition & 0 deletions scripts/build_user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ for file in $(find user -name 'Cargo.toml' \
-not -path 'user/never_stop/Cargo.toml' \
-not -path 'user/tinywasm*/Cargo.toml' \
-not -path 'user/wasmtime*/Cargo.toml'); do
echo "Build $file".
if ! bash -c "cargo build $feature_arg --manifest-path $file $release_flag"; then
echo "Build $file failed!"
exit 1
Expand Down
1 change: 1 addition & 0 deletions user/file_reader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use ms_std::{
time::{SystemTime, UNIX_EPOCH},
};
use ms_std_proc_macro::FaasData;
#[allow(unused_imports)]
use serde::{Deserialize, Serialize};
// use ms_std_proc_macro::FaasData;

Expand Down
2 changes: 2 additions & 0 deletions user/func_a/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
extern crate alloc;

use alloc::{borrow::ToOwned, vec::Vec};

#[allow(unused_imports)]
use ms_std::{
agent::{DataBuffer, FaaSFuncResult as Result},
println,
Expand Down
2 changes: 1 addition & 1 deletion user/load_all/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ms_std::args;

cfg_if::cfg_if! {
if #[cfg(feature = "with_libos")] {
use ms_std::{agent::FaaSFuncResult as Result, println, libos::libos, fs::File};
use ms_std::{agent::FaaSFuncResult as Result, println, libos::libos};
extern crate alloc;
} else {
type Result<T> = core::result::Result<T, String>;
Expand Down
5 changes: 4 additions & 1 deletion user/mapper/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![no_std]

#[allow(unused_imports)]
use core::str::FromStr;

use alloc::{
Expand All @@ -20,9 +21,11 @@ use ms_std::{
fs::File,
io::Read,
println,
time::{SystemTime, UNIX_EPOCH},
time::{SystemTime},
};
use ms_std_proc_macro::FaasData;

#[allow(unused_imports)]
use serde::{Deserialize, Serialize};

extern crate alloc;
Expand Down
3 changes: 3 additions & 0 deletions user/merger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use ms_std::{
time::{SystemTime, UNIX_EPOCH},
};
use ms_std_proc_macro::FaasData;

#[allow(unused_imports)]
use serde::{Deserialize, Serialize};

#[cfg(feature = "pkey_per_func")]
Expand Down Expand Up @@ -74,6 +76,7 @@ fn merge_partitions(partitions: Vec<&NumberArray>, dst: &mut NumberArray) {

match min_partition {
Some(partition_idx) => {
#[allow(unused_variables)]
let ret = dst.push(min_value);
#[cfg(feature = "pkey_per_func")]
{
Expand Down
4 changes: 4 additions & 0 deletions user/reducer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![no_std]

#[allow(unused_imports)]
use core::str::FromStr;

use alloc::{
Expand All @@ -14,6 +16,8 @@ use ms_std::{
time::{SystemTime, UNIX_EPOCH},
};
use ms_std_proc_macro::FaasData;

#[allow(unused_imports)]
use serde::{Deserialize, Serialize};

extern crate alloc;
Expand Down
6 changes: 4 additions & 2 deletions user/simple_file/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use alloc::{
string::{String, ToString},
vec::Vec,
};

#[allow(unused_imports)]
use ms_std::{
agent::FaaSFuncResult as Result,
fs::File,
Expand Down Expand Up @@ -85,13 +87,13 @@ use ms_std::{

#[no_mangle]
pub fn main() -> Result<()> {
let start_time = SystemTime::now();
// let start_time = SystemTime::now();
let path = "lines.txt";

/////////////////// test create/write/read. ///////////////////
let data = "Rust LibOS Cool.";
let mut output = File::create(path)?;
write!(output, "{}", data).expect("");
output.write_str(data).expect("");
// drop(output);

let mut input_file = File::open(path)?;
Expand Down
12 changes: 6 additions & 6 deletions user/simple_http/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#![no_std]
#![allow(clippy::result_unit_err)]

extern crate alloc;

use alloc::string::String;

use ms_std::{agent::FaaSFuncResult as Result, net::TcpStream, println};
use ms_std::{
io::{Read, Write},
net::TcpStream,
prelude::*,
};

#[no_mangle]
pub fn main() -> Result<()> {
let mut stream = TcpStream::connect("www.baidu.com".into())?;
let mut stream = TcpStream::connect("example.com")?;
println!("tcp connection created.");
stream.write_all(b"GET / HTTP/1.0\r\n\r\n")?;
let mut buffer = [0; 4096];
Expand Down
4 changes: 4 additions & 0 deletions user/sorter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use alloc::{format, string::String, vec::Vec};


#[allow(unused_imports)]
use ms_std::{
args,
fs::File,
Expand All @@ -10,6 +12,8 @@ use ms_std::{
time::{SystemTime, UNIX_EPOCH},
};
use ms_std_proc_macro::FaasData;

#[allow(unused_imports)]
use serde::{Deserialize, Serialize};

#[cfg_attr(feature = "file-based", derive(Serialize, Deserialize))]
Expand Down
2 changes: 2 additions & 0 deletions user/splitter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use ms_std::{
time::{SystemTime, UNIX_EPOCH},
};
use ms_std_proc_macro::FaasData;

#[allow(unused_imports)]
use serde::{Deserialize, Serialize};

#[cfg_attr(feature = "file-based", derive(Serialize, Deserialize))]
Expand Down
Loading