Skip to content

Commit 9ea39cf

Browse files
committed
Merge branch 'theseus_main' into update_rust_toolchain
Signed-off-by: Klimenty Tsoutsman <[email protected]>
2 parents 2cda740 + c025bd1 commit 9ea39cf

File tree

34 files changed

+1034
-353
lines changed

34 files changed

+1034
-353
lines changed

.github/workflows/test.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ name: QEMU Test
22
on:
33
pull_request:
44
types: [synchronize, opened, reopened]
5+
paths-ignore:
6+
- 'book/**'
7+
- 'c_test/**'
8+
- 'docker/**'
9+
- 'github_pages/**'
10+
- 'old_crates/**'
11+
- 'scripts/**'
12+
- '.gitignore'
13+
- 'LICENSE-MIT'
14+
- 'README.md'
15+
- 'bochsrc.txt'
16+
- 'rustfmt.toml'
17+
- 'slirp.conf'
518
jobs:
619
run-tests:
720
runs-on: ubuntu-latest

Cargo.lock

-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

applications/bm/src/lib.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use alloc::string::{String, ToString};
3535
use alloc::sync::Arc;
3636
use hpet::get_hpet;
3737
use heapfile::HeapFile;
38-
use path::Path;
38+
use path::{Path, PathBuf};
3939
use fs_node::{DirRef, FileOrDir, FileRef};
4040
use libtest::*;
4141
use memory::{create_mapping, PteFlags};
@@ -324,9 +324,9 @@ fn do_spawn_inner(overhead_ct: u64, th: usize, nr: usize, on_cpu: CpuId) -> Resu
324324
.map_err(|_| "could not find the application namespace")?;
325325
let namespace_dir = namespace.dir();
326326
let app_path = namespace_dir.get_file_starting_with("hello-")
327-
.map(|f| Path::new(f.lock().get_absolute_path()))
327+
.map(|f| PathBuf::from(f.lock().get_absolute_path()))
328328
.ok_or("Could not find the application 'hello'")?;
329-
let crate_name = crate_name_from_path(&app_path).to_string();
329+
let crate_name = crate_name_from_path(&app_path).ok_or("invalid app path")?.to_string();
330330

331331
// here we are taking the time at every iteration.
332332
// otherwise the crate is not fully unloaded from the namespace before the next iteration starts
@@ -336,7 +336,7 @@ fn do_spawn_inner(overhead_ct: u64, th: usize, nr: usize, on_cpu: CpuId) -> Resu
336336
while namespace.get_crate(&crate_name).is_some() { }
337337

338338
start_hpet = hpet.get_counter();
339-
let child = spawn::new_application_task_builder(app_path.clone(), None)?
339+
let child = spawn::new_application_task_builder(&app_path, None)?
340340
.pin_on_cpu(on_cpu)
341341
.spawn()?;
342342

@@ -1237,7 +1237,7 @@ fn do_fs_read_with_open_inner(filename: &str, overhead_ct: u64, th: usize, nr: u
12371237
let hpet = get_hpet().ok_or("Could not retrieve hpet counter")?;
12381238

12391239

1240-
let path = Path::new(filename.to_string());
1240+
let path = PathBuf::from(filename.to_string());
12411241
let mut _dummy_sum: u64 = 0;
12421242
let mut buf = vec![0; READ_BUF_SIZE];
12431243
let size = match get_file(filename) {
@@ -1302,7 +1302,7 @@ fn do_fs_read_only_inner(filename: &str, overhead_ct: u64, th: usize, nr: usize)
13021302
let hpet = get_hpet().ok_or("Could not retrieve hpet counter")?;
13031303

13041304

1305-
let path = Path::new(filename.to_string());
1305+
let path = PathBuf::from(filename.to_string());
13061306
let _dummy_sum: u64 = 0;
13071307
let mut buf = vec![0; READ_BUF_SIZE];
13081308
let size = match get_file(filename) {
@@ -1640,7 +1640,7 @@ fn test_file_inner(fileref: FileRef) {
16401640
/// Wrapper function to get a file provided a string.
16411641
/// Not used in measurements
16421642
fn get_file(filename: &str) -> Option<FileRef> {
1643-
let path = Path::new(filename.to_string());
1643+
let path: &Path = filename.as_ref();
16441644
match path.get(&get_cwd().unwrap()) {
16451645
Some(file_dir_enum) => {
16461646
match file_dir_enum {

applications/cat/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern crate core2;
1111

1212
use core::str;
1313
use alloc::{
14-
string::{String, ToString},
14+
string::String,
1515
vec::Vec,
1616
};
1717
use getopts::Options;
@@ -47,7 +47,7 @@ pub fn main(args: Vec<String>) -> isize {
4747
println!("failed to get current task");
4848
return -1;
4949
};
50-
let path = Path::new(matches.free[0].to_string());
50+
let path: &Path = matches.free[0].as_ref();
5151

5252
// navigate to the filepath specified by first argument
5353
match path.get(&cwd) {

applications/cd/src/lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ extern crate root;
1010
extern crate task;
1111

1212
use alloc::string::String;
13-
use alloc::string::ToString;
1413
use alloc::sync::Arc;
1514
use alloc::vec::Vec;
1615
use getopts::Options;
17-
use path::Path;
1816

1917
pub fn main(args: Vec<String>) -> isize {
2018
let mut opts = Options::new();
@@ -38,8 +36,8 @@ pub fn main(args: Vec<String>) -> isize {
3836
if matches.free.is_empty() {
3937
curr_env.lock().working_dir = Arc::clone(root::get_root());
4038
} else {
41-
let path = Path::new(matches.free[0].to_string());
42-
match curr_env.lock().chdir(&path) {
39+
let path = matches.free[0].as_ref();
40+
match curr_env.lock().chdir(path) {
4341
Err(environment::Error::NotADirectory) => {
4442
println!("not a directory: {}", path);
4543
return -1;

applications/hull/src/builtin.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//! Builtin shell commands.
22
33
use crate::{Error, Result, Shell};
4-
use alloc::{borrow::ToOwned, string::ToString};
4+
use alloc::string::ToString;
55
use app_io::println;
6-
use path::Path;
76

87
// TODO: Decide which builtins we don't need.
98

@@ -64,15 +63,16 @@ impl Shell {
6463
return Err(Error::Command(1));
6564
}
6665

67-
let path = Path::new(if let Some(arg) = args.first() {
68-
(*arg).to_owned()
66+
let path = if let Some(arg) = args.first() {
67+
*arg
6968
} else {
70-
"/".to_owned()
71-
});
69+
"/"
70+
}
71+
.as_ref();
7272

7373
let task = task::get_my_current_task().ok_or(Error::CurrentTaskUnavailable)?;
7474

75-
match task.get_env().lock().chdir(&path) {
75+
match task.get_env().lock().chdir(path) {
7676
Ok(()) => Ok(()),
7777
Err(_) => {
7878
println!("no such file or directory: {path}");

applications/hull/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use hashbrown::HashMap;
3939
use job::Job;
4040
use log::{error, warn};
4141
use noline::{builder::EditorBuilder, sync::embedded::IO as Io};
42-
use path::Path;
42+
use path::PathBuf;
4343
use stdio::Stdio;
4444
use sync_block::Mutex;
4545
use task::{ExitValue, KillReason};
@@ -306,15 +306,15 @@ impl Shell {
306306
.into_iter();
307307

308308
let app_path = match matching_files.next() {
309-
Some(f) => Path::new(f.lock().get_absolute_path()),
309+
Some(f) => PathBuf::from(f.lock().get_absolute_path()),
310310
None => return Err(Error::CommandNotFound(cmd.to_owned())),
311311
};
312312

313313
if matching_files.next().is_some() {
314314
println!("multiple matching files found, running: {app_path}");
315315
}
316316

317-
let task = spawn::new_application_task_builder(app_path, None)
317+
let task = spawn::new_application_task_builder(&app_path, None)
318318
.map_err(Error::SpawnFailed)?
319319
.argument(args.into_iter().map(ToOwned::to_owned).collect::<Vec<_>>())
320320
.block()

applications/loadc/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ use alloc::{collections::BTreeSet, string::{String, ToString}, sync::Arc, vec::V
2626
use getopts::{Matches, Options};
2727
use memory::{Page, MappedPages, VirtualAddress, PteFlagsArch, PteFlags};
2828
use mod_mgmt::{CrateNamespace, StrongDependency, find_symbol_table, RelocationEntry, write_relocation};
29-
use rustc_demangle::demangle;
3029
use path::Path;
30+
use rustc_demangle::demangle;
3131
use xmas_elf::{
3232
ElfFile,
3333
program::SegmentData,
@@ -72,8 +72,7 @@ fn rmain(matches: Matches) -> Result<c_int, String> {
7272
).map_err(|_| String::from("failed to get current task"))?;
7373

7474
let path = matches.free.first().ok_or_else(|| "Missing path to ELF executable".to_string())?;
75-
let path = Path::new(path.clone());
76-
let file_ref = path.get_file(&curr_wd)
75+
let file_ref = Path::new(path).get_file(&curr_wd)
7776
.ok_or_else(|| format!("Failed to access file at {path:?}"))?;
7877
let file = file_ref.lock();
7978

applications/ls/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ extern crate path;
99

1010
use alloc::{
1111
string::String,
12-
string::ToString,
1312
vec::Vec,
1413
};
1514
use core::fmt::Write;
@@ -45,7 +44,7 @@ pub fn main(args: Vec<String>) -> isize {
4544
return 0;
4645
}
4746

48-
let path = Path::new(matches.free[0].to_string());
47+
let path: &Path = matches.free[0].as_ref();
4948

5049
// Navigate to the path specified by first argument
5150
match path.get(&curr_wd) {

applications/ns/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use alloc::{
2525
use getopts::{Options, Matches};
2626
use mod_mgmt::CrateNamespace;
2727
use fs_node::FileRef;
28-
use path::Path;
28+
use path::PathBuf;
2929

3030

3131
pub fn main(args: Vec<String>) -> isize {
@@ -68,7 +68,7 @@ fn rmain(matches: Matches) -> Result<(), String> {
6868
let mut output = String::new();
6969

7070
if let Some(crate_obj_file_path) = matches.opt_str("load") {
71-
let path = Path::new(crate_obj_file_path);
71+
let path = PathBuf::from(crate_obj_file_path);
7272
let file = path.get_file(&curr_wd).ok_or_else(||
7373
format!("Couldn't resolve path to crate object file at {path:?}")
7474
)?;

applications/qemu_test/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
use alloc::{boxed::Box, string::String, vec::Vec};
1010

1111
use app_io::{print, println};
12-
use path::Path;
1312
use qemu_exit::{QEMUExit, X86};
1413
use task::{ExitValue, KillReason};
14+
use path::{Path, PathBuf};
1515

1616
extern crate alloc;
1717

@@ -37,7 +37,7 @@ pub fn main(_: Vec<String>) -> isize {
3737
// deadlock.
3838
let file = dir.lock().get_file(file_name.as_ref()).unwrap();
3939
let path = file.lock().get_absolute_path();
40-
Some((file_name, Path::new(path)))
40+
Some((file_name, PathBuf::from(path)))
4141
} else {
4242
None
4343
}
@@ -56,7 +56,7 @@ pub fn main(_: Vec<String>) -> isize {
5656
num_ignored += 1;
5757
println!("ignored");
5858
} else {
59-
match run_test(path) {
59+
match run_test(&path) {
6060
Ok(_) => println!("ok"),
6161
Err(_) => {
6262
num_failed += 1;
@@ -81,7 +81,7 @@ pub fn main(_: Vec<String>) -> isize {
8181
}
8282

8383
#[allow(clippy::result_unit_err)]
84-
pub fn run_test(path: Path) -> Result<(), ()> {
84+
pub fn run_test(path: &Path) -> Result<(), ()> {
8585
match spawn::new_application_task_builder(path, None)
8686
.unwrap()
8787
.argument(Vec::new())

applications/rm/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use alloc::vec::Vec;
1313
use alloc::string::String;
1414
use alloc::string::ToString;
1515
use getopts::Options;
16-
use path::Path;
16+
use path::PathBuf;
1717
use fs_node::{FsNode, FileOrDir};
1818

1919

@@ -56,7 +56,7 @@ pub fn remove_node(args: Vec<String>) -> Result<(), String> {
5656
}
5757

5858
for path_string in &matches.free {
59-
let path = Path::new(path_string.clone());
59+
let path = PathBuf::from(path_string.clone());
6060
let node_to_delete = match path.get(&working_dir) {
6161
Some(node) => node,
6262
_ => return Err(format!("Couldn't find path {path}")),

applications/shell/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -638,10 +638,10 @@ impl Shell {
638638
let app_file = matching_apps.next();
639639
let second_match = matching_apps.next(); // return an error if there are multiple matching apps
640640
let app_path = app_file.xor(second_match)
641-
.map(|f| Path::new(f.lock().get_absolute_path()))
641+
.map(|f| f.lock().get_absolute_path())
642642
.ok_or(AppErr::NotFound(cmd))?;
643643

644-
let taskref = spawn::new_application_task_builder(app_path, None)
644+
let taskref = spawn::new_application_task_builder(app_path.as_ref(), None)
645645
.map_err(|e| AppErr::SpawnErr(e.to_string()))?
646646
.argument(args)
647647
.block()
@@ -860,7 +860,7 @@ impl Shell {
860860

861861
// Walk through nodes existing in the command.
862862
for node in &nodes {
863-
let path = Path::new(node.to_string());
863+
let path: &Path = node.as_ref();
864864
match path.get(&curr_wd) {
865865
Some(file_dir_enum) => {
866866
match file_dir_enum {

applications/swap/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn rmain(matches: Matches) -> Result<(), String> {
7272
return Err("failed to get current task".to_string());
7373
};
7474
let override_namespace_crate_dir = if let Some(path) = matches.opt_str("d") {
75-
let path = Path::new(path);
75+
let path: &Path = path.as_ref();
7676
let dir = match path.get(&curr_dir) {
7777
Some(FileOrDir::Dir(dir)) => dir,
7878
_ => return Err(format!("Error: could not find specified namespace crate directory: {path}.")),
@@ -166,7 +166,7 @@ fn do_swap(
166166
let (into_new_crate_file, new_namespace) = {
167167
if let Some(f) = override_namespace_crate_dir.as_ref().and_then(|ns_dir| ns_dir.get_file_starting_with(new_crate_str)) {
168168
(IntoCrateObjectFile::File(f), None)
169-
} else if let Some(FileOrDir::File(f)) = Path::new(String::from(new_crate_str)).get(curr_dir) {
169+
} else if let Some(FileOrDir::File(f)) = Path::new(new_crate_str).get(curr_dir) {
170170
(IntoCrateObjectFile::File(f), None)
171171
} else {
172172
(IntoCrateObjectFile::Prefix(String::from(new_crate_str)), None)

applications/test_wasmtime/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn main(args: Vec<String>) -> isize {
2929

3030

3131
fn rmain(args: Vec<String>) -> Result<(), String> {
32-
let path_to_hello_cwasm = Path::new(args.get(0).cloned().unwrap_or("/extra_files/wasm/hello.cwasm".to_string()));
32+
let path_to_hello_cwasm: &Path = args.get(0).map(|arg| &arg[..]).unwrap_or("/extra_files/wasm/hello.cwasm").as_ref();
3333
let Ok(curr_wd) = task::with_current_task(|t| t.get_env().lock().working_dir.clone()) else {
3434
return Err("failed to get current task".to_string());
3535
};

applications/upd/src/lib.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn rmain(matches: Matches) -> Result<(), String> {
123123
}
124124
"apply" | "ap" => {
125125
let base_dir_path = matches.free.get(1).ok_or_else(|| String::from("missing BASE_DIR path argument"))?;
126-
apply(&Path::new(base_dir_path.clone()))
126+
apply(base_dir_path.as_ref())
127127
}
128128
other => {
129129
Err(format!("unrecognized command {other:?}"))
@@ -197,8 +197,8 @@ fn download(remote_endpoint: IpEndpoint, update_build: &str, crate_list: Option<
197197
let size = content.len();
198198
// The name of the crate file that we downloaded is something like: "/keyboard_log/k#keyboard-36be916209949cef.o".
199199
// We need to get just the basename of the file, then remove the crate type prefix ("k#").
200-
let df_path = Path::new(df.name);
201-
let cfile = new_namespace_dir.write_crate_object_file(df_path.basename(), content)?;
200+
let file_name = Path::new(&df.name).file_name().ok_or("crate file path did not have file name")?;
201+
let cfile = new_namespace_dir.write_crate_object_file(file_name, content)?;
202202
println!("Downloaded crate: {:?}, size {}", cfile.lock().get_absolute_path(), size);
203203
}
204204

@@ -257,7 +257,9 @@ fn apply(base_dir_path: &Path) -> Result<(), String> {
257257
// An empty old_crate_name indicates that there is no old crate or object file to remove, we are just loading a new crate (or inserting its object file)
258258
None
259259
} else {
260-
let old_crate_name = mod_mgmt::crate_name_from_path(&Path::new(old_crate_module_file_name)).to_string();
260+
let old_crate_name = mod_mgmt::crate_name_from_path(old_crate_module_file_name.as_ref())
261+
.ok_or("invalid old crate module file name")?
262+
.to_string();
261263
if curr_namespace.get_crate(&old_crate_name).is_none() {
262264
println!("\t Note: old crate {:?} was not currently loaded into namespace {:?}.", old_crate_name, curr_namespace.name());
263265
}

applications/wasm/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn main(args: Vec<String>) -> isize {
6666

6767
// Verify passed preopened directories are real directories.
6868
for dir in preopened_dirs.iter() {
69-
let dir_path = Path::new(dir.clone());
69+
let dir_path: &Path = dir.as_ref();
7070

7171
match dir_path.get(&curr_wd) {
7272
Some(file_dir_enum) => match file_dir_enum {
@@ -92,7 +92,7 @@ pub fn main(args: Vec<String>) -> isize {
9292
return -1;
9393
}
9494

95-
let wasm_binary_path = Path::new(args[0].clone());
95+
let wasm_binary_path: &Path = args[0].as_ref();
9696

9797
// Parse inputted WebAssembly binary path into byte array.
9898
let wasm_binary: Vec<u8> = match wasm_binary_path.get(&curr_wd) {

0 commit comments

Comments
 (0)