Merge recent updates from ch7.
This commit is contained in:
parent
b535f5ba98
commit
f6ebd1ac68
4 changed files with 5 additions and 69 deletions
|
@ -1,62 +0,0 @@
|
||||||
use alloc::vec::Vec;
|
|
||||||
use lazy_static::*;
|
|
||||||
|
|
||||||
pub fn get_num_app() -> usize {
|
|
||||||
extern "C" { fn _num_app(); }
|
|
||||||
unsafe { (_num_app as usize as *const usize).read_volatile() }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_app_data(app_id: usize) -> &'static [u8] {
|
|
||||||
extern "C" { fn _num_app(); }
|
|
||||||
let num_app_ptr = _num_app as usize as *const usize;
|
|
||||||
let num_app = get_num_app();
|
|
||||||
let app_start = unsafe {
|
|
||||||
core::slice::from_raw_parts(num_app_ptr.add(1), num_app + 1)
|
|
||||||
};
|
|
||||||
assert!(app_id < num_app);
|
|
||||||
unsafe {
|
|
||||||
core::slice::from_raw_parts(
|
|
||||||
app_start[app_id] as *const u8,
|
|
||||||
app_start[app_id + 1] - app_start[app_id]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
static ref APP_NAMES: Vec<&'static str> = {
|
|
||||||
let num_app = get_num_app();
|
|
||||||
extern "C" { fn _app_names(); }
|
|
||||||
let mut start = _app_names as usize as *const u8;
|
|
||||||
let mut v = Vec::new();
|
|
||||||
unsafe {
|
|
||||||
for _ in 0..num_app {
|
|
||||||
let mut end = start;
|
|
||||||
while end.read_volatile() != '\0' as u8 {
|
|
||||||
end = end.add(1);
|
|
||||||
}
|
|
||||||
let slice = core::slice::from_raw_parts(start, end as usize - start as usize);
|
|
||||||
let str = core::str::from_utf8(slice).unwrap();
|
|
||||||
v.push(str);
|
|
||||||
start = end.add(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
v
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[allow(unused)]
|
|
||||||
pub fn get_app_data_by_name(name: &str) -> Option<&'static [u8]> {
|
|
||||||
let num_app = get_num_app();
|
|
||||||
(0..num_app)
|
|
||||||
.find(|&i| APP_NAMES[i] == name)
|
|
||||||
.map(|i| get_app_data(i))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn list_apps() {
|
|
||||||
println!("/**** APPS ****");
|
|
||||||
for app in APP_NAMES.iter() {
|
|
||||||
println!("{}", app);
|
|
||||||
}
|
|
||||||
println!("**************/");
|
|
||||||
}
|
|
|
@ -11,7 +11,6 @@ use user_lib::{
|
||||||
close,
|
close,
|
||||||
read,
|
read,
|
||||||
};
|
};
|
||||||
use alloc::string::String;
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn main(argc: usize, argv: &[&str]) -> i32 {
|
pub fn main(argc: usize, argv: &[&str]) -> i32 {
|
||||||
|
@ -22,13 +21,11 @@ pub fn main(argc: usize, argv: &[&str]) -> i32 {
|
||||||
}
|
}
|
||||||
let fd = fd as usize;
|
let fd = fd as usize;
|
||||||
let mut buf = [0u8; 16];
|
let mut buf = [0u8; 16];
|
||||||
let mut s = String::new();
|
|
||||||
loop {
|
loop {
|
||||||
let size = read(fd, &mut buf) as usize;
|
let size = read(fd, &mut buf) as usize;
|
||||||
if size == 0 { break; }
|
if size == 0 { break; }
|
||||||
s.push_str(core::str::from_utf8(&buf[..size]).unwrap());
|
println!("{}", core::str::from_utf8(&buf[..size]).unwrap());
|
||||||
}
|
}
|
||||||
println!("{}", s);
|
|
||||||
close(fd);
|
close(fd);
|
||||||
0
|
0
|
||||||
}
|
}
|
|
@ -18,7 +18,7 @@ pub fn main() -> i32 {
|
||||||
for i in 0..buffer.len() {
|
for i in 0..buffer.len() {
|
||||||
buffer[i] = i as u8;
|
buffer[i] = i as u8;
|
||||||
}
|
}
|
||||||
let f = open("testf", OpenFlags::CREATE | OpenFlags::WRONLY);
|
let f = open("testf\0", OpenFlags::CREATE | OpenFlags::WRONLY);
|
||||||
if f < 0 {
|
if f < 0 {
|
||||||
panic!("Open test file failed!");
|
panic!("Open test file failed!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ unsafe fn f(count:usize) -> ! {
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn main(argc: usize, argv: &[&str]) -> i32 {
|
pub fn main(argc: usize, argv: &[&str]) -> i32 {
|
||||||
|
let mut count = 0;
|
||||||
if argc == 1 {
|
if argc == 1 {
|
||||||
count = THREAD_COUNT;
|
count = THREAD_COUNT;
|
||||||
} else if argc == 2 {
|
} else if argc == 2 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue