Add login process. Remove debugging. Fix order of arguments

This commit is contained in:
Jeremy Soller 2016-09-22 08:43:22 -06:00
parent afe7a99700
commit 046236c10f
11 changed files with 70 additions and 97 deletions

2
.gitmodules vendored
View file

@ -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

View file

@ -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();' >> $@

View file

@ -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<Console>,
display: RefCell<Display>,
next_id: AtomicUsize,
handles: RefCell<BTreeMap<usize, usize>>
display: RefCell<Display>
}
impl Scheme for DisplayScheme {
@ -40,6 +36,10 @@ impl Scheme for DisplayScheme {
Ok(0)
}
fn fsync(&self, _id: usize) -> Result<usize> {
Ok(0)
}
fn write(&self, _id: usize, buf: &[u8]) -> Result<usize> {
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<usize> {
fn close(&self, _id: usize) -> Result<usize> {
Ok(0)
}
}
/*
struct DisplayScheme {
display: RefCell<Display>,
next_id: AtomicUsize,
handles: RefCell<BTreeMap<usize, usize>>
}
impl Scheme for DisplayScheme {
fn open(&self, _path: &[u8], _flags: usize) -> Result<usize> {
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<usize> {
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<usize> {
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<usize> {
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");
}
});
}

View file

@ -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

View file

@ -452,7 +452,7 @@ pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result<usize> {
));
let mut arg_size = 0;
for arg in args.iter() {
for arg in args.iter().rev() {
sp -= mem::size_of::<usize>();
unsafe { *(sp as *mut usize) = arch::USER_ARG_OFFSET + arg_size; }
sp -= mem::size_of::<usize>();
@ -474,7 +474,7 @@ pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result<usize> {
);
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(),

View file

@ -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)

View file

View file

@ -0,0 +1,6 @@
[package]
name = "login"
version = "0.1.0"
[dependencies]
syscall = { path = "../../syscall/" }

View file

@ -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<String> = 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)
}
}
});
}

View file

@ -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;