diff --git a/.gitmodules b/.gitmodules index fe424c0..6127e03 100644 --- a/.gitmodules +++ b/.gitmodules @@ -8,5 +8,5 @@ path = ralloc url = https://github.com/redox-os/ralloc [submodule "ion"] - path = ion + path = programs/ion url = https://github.com/redox-os/ion.git diff --git a/Makefile b/Makefile index 09fff8a..24a5cf8 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,7 @@ clean: cargo clean --manifest-path libstd/Cargo.toml cargo clean --manifest-path init/Cargo.toml cargo clean --manifest-path ion/Cargo.toml + cargo clean --manifest-path login/Cargo.toml cargo clean --manifest-path drivers/ps2d/Cargo.toml cargo clean --manifest-path drivers/pcid/Cargo.toml cargo clean --manifest-path drivers/vesad/Cargo.toml @@ -125,13 +126,13 @@ $(BUILD)/libstd.rlib: libstd/Cargo.toml libstd/src/** $(BUILD)/libcore.rlib $(BU $(CARGO) rustc --verbose --manifest-path $< $(CARGOFLAGS) -o $@ cp libstd/target/$(TARGET)/debug/deps/*.rlib $(BUILD) -initfs/bin/init: init/Cargo.toml init/src/*.rs $(BUILD)/libstd.rlib +initfs/bin/%: drivers/%/Cargo.toml drivers/%/src/** $(BUILD)/libstd.rlib mkdir -p initfs/bin $(CARGO) rustc --manifest-path $< $(CARGOFLAGS) -o $@ strip $@ rm $@.d -initfs/bin/%: drivers/%/Cargo.toml drivers/%/src/** $(BUILD)/libstd.rlib +initfs/bin/%: programs/%/Cargo.toml programs/%/src/** $(BUILD)/libstd.rlib mkdir -p initfs/bin $(CARGO) rustc --manifest-path $< $(CARGOFLAGS) -o $@ strip $@ @@ -143,19 +144,14 @@ initfs/bin/%: schemes/%/Cargo.toml schemes/%/src/** $(BUILD)/libstd.rlib strip $@ rm $@.d -initfs/bin/ion: ion/Cargo.toml ion/src/*.rs $(BUILD)/libstd.rlib - mkdir -p initfs/bin - $(CARGO) rustc --manifest-path $< $(CARGOFLAGS) -o $@ - strip $@ - rm $@.d - $(BUILD)/initfs.rs: \ - initfs/bin/init \ initfs/bin/pcid \ initfs/bin/ps2d \ initfs/bin/vesad \ - initfs/bin/example \ - initfs/bin/ion + initfs/bin/init \ + initfs/bin/ion \ + initfs/bin/login \ + initfs/bin/example echo 'use collections::BTreeMap;' > $@ echo 'pub fn gen() -> BTreeMap<&'"'"'static [u8], &'"'"'static [u8]> {' >> $@ echo ' let mut files: BTreeMap<&'"'"'static [u8], &'"'"'static [u8]> = BTreeMap::new();' >> $@ diff --git a/drivers/vesad/src/main.rs b/drivers/vesad/src/main.rs index a0022d5..7cbed6e 100644 --- a/drivers/vesad/src/main.rs +++ b/drivers/vesad/src/main.rs @@ -8,17 +8,15 @@ extern crate ransid; extern crate syscall; use std::cell::RefCell; -use std::collections::BTreeMap; use std::fs::File; use std::io::{Read, Write}; -use std::sync::atomic::{AtomicUsize, Ordering}; -use std::{cmp, slice, thread}; +use std::{slice, thread}; use ransid::{Console, Event}; -use syscall::{physmap, physunmap, Error, EINVAL, EBADF, Packet, Result, Scheme, SEEK_SET, SEEK_CUR, SEEK_END, MAP_WRITE, MAP_WRITE_COMBINE}; +use syscall::{physmap, physunmap, Packet, Result, Scheme, MAP_WRITE, MAP_WRITE_COMBINE}; use display::Display; use mode_info::VBEModeInfo; -use primitive::{fast_copy, fast_set64}; +use primitive::fast_set64; pub mod display; pub mod mode_info; @@ -26,9 +24,7 @@ pub mod primitive; struct DisplayScheme { console: RefCell, - display: RefCell, - next_id: AtomicUsize, - handles: RefCell> + display: RefCell } impl Scheme for DisplayScheme { @@ -40,6 +36,10 @@ impl Scheme for DisplayScheme { Ok(0) } + fn fsync(&self, _id: usize) -> Result { + Ok(0) + } + fn write(&self, _id: usize, buf: &[u8]) -> Result { let mut display = self.display.borrow_mut(); self.console.borrow_mut().write(buf, |event| { @@ -52,57 +52,11 @@ impl Scheme for DisplayScheme { Ok(buf.len()) } - fn close(&self, id: usize) -> Result { + fn close(&self, _id: usize) -> Result { Ok(0) } } -/* -struct DisplayScheme { - display: RefCell, - next_id: AtomicUsize, - handles: RefCell> -} - -impl Scheme for DisplayScheme { - fn open(&self, _path: &[u8], _flags: usize) -> Result { - let id = self.next_id.fetch_add(1, Ordering::SeqCst); - self.handles.borrow_mut().insert(id, 0); - Ok(id) - } - - fn write(&self, id: usize, buf: &[u8]) -> Result { - let mut handles = self.handles.borrow_mut(); - let mut seek = handles.get_mut(&id).ok_or(Error::new(EBADF))?; - let mut display = self.display.borrow_mut(); - let len = cmp::min(buf.len(), display.offscreen.len() * 4 - *seek); - unsafe { - fast_copy((display.offscreen.as_mut_ptr() as usize + *seek) as *mut u8, buf.as_ptr(), len); - fast_copy((display.onscreen.as_mut_ptr() as usize + *seek) as *mut u8, buf.as_ptr(), len); - } - *seek += len; - Ok(len) - } - - fn seek(&self, id: usize, pos: usize, whence: usize) -> Result { - let mut handles = self.handles.borrow_mut(); - let mut seek = handles.get_mut(&id).ok_or(Error::new(EBADF))?; - let len = self.display.borrow().offscreen.len() * 4; - *seek = match whence { - SEEK_SET => cmp::min(len, pos), - SEEK_CUR => cmp::max(0, cmp::min(len as isize, *seek as isize + pos as isize)) as usize, - SEEK_END => cmp::max(0, cmp::min(len as isize, len as isize + pos as isize)) as usize, - _ => return Err(Error::new(EINVAL)) - }; - Ok(*seek) - } - - fn close(&self, id: usize) -> Result { - self.handles.borrow_mut().remove(&id).ok_or(Error::new(EBADF)).and(Ok(0)) - } -} -*/ - fn main() { let width; let height; @@ -135,17 +89,15 @@ fn main() { display: RefCell::new(Display::new(width, height, unsafe { slice::from_raw_parts_mut(onscreen as *mut u32, size) }, unsafe { slice::from_raw_parts_mut(offscreen as *mut u32, size) } - )), - next_id: AtomicUsize::new(0), - handles: RefCell::new(BTreeMap::new()) + )) }; loop { let mut packet = Packet::default(); - socket.read(&mut packet); + socket.read(&mut packet).expect("vesad: failed to read display scheme"); //println!("vesad: {:?}", packet); scheme.handle(&mut packet); - socket.write(&packet); + socket.write(&packet).expect("vesad: failed to write display scheme"); } }); } diff --git a/initfs/etc/init.rc b/initfs/etc/init.rc index c66bf29..374b4ab 100644 --- a/initfs/etc/init.rc +++ b/initfs/etc/init.rc @@ -1,5 +1,5 @@ initfs:bin/vesad -#initfs:bin/ps2d +initfs:bin/ps2d #initfs:bin/pcid -initfs:bin/example -#initfs:bin/ion +#initfs:bin/example +initfs:bin/login display: initfs:bin/ion diff --git a/kernel/syscall/process.rs b/kernel/syscall/process.rs index 6ffd8c5..34d5751 100644 --- a/kernel/syscall/process.rs +++ b/kernel/syscall/process.rs @@ -452,7 +452,7 @@ pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result { )); let mut arg_size = 0; - for arg in args.iter() { + for arg in args.iter().rev() { sp -= mem::size_of::(); unsafe { *(sp as *mut usize) = arch::USER_ARG_OFFSET + arg_size; } sp -= mem::size_of::(); @@ -474,7 +474,7 @@ pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result { ); let mut arg_offset = 0; - for arg in args.iter() { + for arg in args.iter().rev() { unsafe { memcpy((arch::USER_ARG_OFFSET + arg_offset) as *mut u8, arg.as_ptr(), diff --git a/init/Cargo.toml b/programs/init/Cargo.toml similarity index 100% rename from init/Cargo.toml rename to programs/init/Cargo.toml diff --git a/init/src/main.rs b/programs/init/src/main.rs similarity index 91% rename from init/src/main.rs rename to programs/init/src/main.rs index 7d649ba..bae77fa 100644 --- a/init/src/main.rs +++ b/programs/init/src/main.rs @@ -36,10 +36,9 @@ pub fn main() { command.arg(arg); } - println!("init: spawning {}", line); match command.spawn() { Ok(mut child) => match child.wait() { - Ok(status) => println!("init: waited for {}: {:?}", line, status.code()), + Ok(_status) => (), //println!("init: waited for {}: {:?}", line, status.code()), Err(err) => println!("init: failed to wait for '{}': {}", line, err) }, Err(err) => println!("init: failed to execute '{}': {}", line, err) diff --git a/ion b/programs/ion similarity index 100% rename from ion rename to programs/ion diff --git a/programs/login/Cargo.toml b/programs/login/Cargo.toml new file mode 100644 index 0000000..23bc463 --- /dev/null +++ b/programs/login/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "login" +version = "0.1.0" + +[dependencies] +syscall = { path = "../../syscall/" } diff --git a/programs/login/src/main.rs b/programs/login/src/main.rs new file mode 100644 index 0000000..043c0af --- /dev/null +++ b/programs/login/src/main.rs @@ -0,0 +1,38 @@ +extern crate syscall; + +use std::env; +use std::process::Command; +use std::thread; + +pub fn main() { + let mut args = env::args().skip(1); + + let tty = args.next().expect("login: no tty provided"); + let sh = args.next().expect("login: no sh provided"); + let sh_args: Vec = args.collect(); + + syscall::close(2); + syscall::close(1); + syscall::close(0); + + syscall::open(&tty, syscall::flag::O_RDWR); + syscall::open(&tty, syscall::flag::O_RDWR); + syscall::open(&tty, syscall::flag::O_RDWR); + + thread::spawn(move || { + loop { + let mut command = Command::new(&sh); + for arg in sh_args.iter() { + command.arg(arg); + } + + match command.spawn() { + Ok(mut child) => match child.wait() { + Ok(_status) => (), //println!("login: waited for {}: {:?}", sh, status.code()), + Err(err) => panic!("login: failed to wait for '{}': {}", sh, err) + }, + Err(err) => panic!("login: failed to execute '{}': {}", sh, err) + } + } + }); +} diff --git a/schemes/example/src/main.rs b/schemes/example/src/main.rs index ffe5ae9..84fb345 100644 --- a/schemes/example/src/main.rs +++ b/schemes/example/src/main.rs @@ -25,24 +25,6 @@ impl Scheme for ExampleScheme { } fn main(){ - { - let fd = syscall::open("display:", 0).expect("example: failed to open display"); - let mut buf = *b" \n"; - let mut i: usize = 0; - while i < 10000000000 { - i += 1; - let mut n = i; - let mut e = 10; - while e > 0 && n > 0 { - e -= 1; - buf[e] = (n % 10) as u8 + b'0'; - n = n / 10; - } - syscall::write(fd, &buf[e..]); - } - syscall::close(fd); - } - thread::spawn(move || { let mut socket = File::create(":example").expect("example: failed to create example scheme"); let scheme = ExampleScheme;