Add login process. Remove debugging. Fix order of arguments
This commit is contained in:
parent
afe7a99700
commit
046236c10f
2
.gitmodules
vendored
2
.gitmodules
vendored
|
@ -8,5 +8,5 @@
|
||||||
path = ralloc
|
path = ralloc
|
||||||
url = https://github.com/redox-os/ralloc
|
url = https://github.com/redox-os/ralloc
|
||||||
[submodule "ion"]
|
[submodule "ion"]
|
||||||
path = ion
|
path = programs/ion
|
||||||
url = https://github.com/redox-os/ion.git
|
url = https://github.com/redox-os/ion.git
|
||||||
|
|
18
Makefile
18
Makefile
|
@ -26,6 +26,7 @@ clean:
|
||||||
cargo clean --manifest-path libstd/Cargo.toml
|
cargo clean --manifest-path libstd/Cargo.toml
|
||||||
cargo clean --manifest-path init/Cargo.toml
|
cargo clean --manifest-path init/Cargo.toml
|
||||||
cargo clean --manifest-path ion/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/ps2d/Cargo.toml
|
||||||
cargo clean --manifest-path drivers/pcid/Cargo.toml
|
cargo clean --manifest-path drivers/pcid/Cargo.toml
|
||||||
cargo clean --manifest-path drivers/vesad/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 $@
|
$(CARGO) rustc --verbose --manifest-path $< $(CARGOFLAGS) -o $@
|
||||||
cp libstd/target/$(TARGET)/debug/deps/*.rlib $(BUILD)
|
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
|
mkdir -p initfs/bin
|
||||||
$(CARGO) rustc --manifest-path $< $(CARGOFLAGS) -o $@
|
$(CARGO) rustc --manifest-path $< $(CARGOFLAGS) -o $@
|
||||||
strip $@
|
strip $@
|
||||||
rm $@.d
|
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
|
mkdir -p initfs/bin
|
||||||
$(CARGO) rustc --manifest-path $< $(CARGOFLAGS) -o $@
|
$(CARGO) rustc --manifest-path $< $(CARGOFLAGS) -o $@
|
||||||
strip $@
|
strip $@
|
||||||
|
@ -143,19 +144,14 @@ initfs/bin/%: schemes/%/Cargo.toml schemes/%/src/** $(BUILD)/libstd.rlib
|
||||||
strip $@
|
strip $@
|
||||||
rm $@.d
|
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: \
|
$(BUILD)/initfs.rs: \
|
||||||
initfs/bin/init \
|
|
||||||
initfs/bin/pcid \
|
initfs/bin/pcid \
|
||||||
initfs/bin/ps2d \
|
initfs/bin/ps2d \
|
||||||
initfs/bin/vesad \
|
initfs/bin/vesad \
|
||||||
initfs/bin/example \
|
initfs/bin/init \
|
||||||
initfs/bin/ion
|
initfs/bin/ion \
|
||||||
|
initfs/bin/login \
|
||||||
|
initfs/bin/example
|
||||||
echo 'use collections::BTreeMap;' > $@
|
echo 'use collections::BTreeMap;' > $@
|
||||||
echo 'pub fn gen() -> BTreeMap<&'"'"'static [u8], &'"'"'static [u8]> {' >> $@
|
echo 'pub fn gen() -> BTreeMap<&'"'"'static [u8], &'"'"'static [u8]> {' >> $@
|
||||||
echo ' let mut files: BTreeMap<&'"'"'static [u8], &'"'"'static [u8]> = BTreeMap::new();' >> $@
|
echo ' let mut files: BTreeMap<&'"'"'static [u8], &'"'"'static [u8]> = BTreeMap::new();' >> $@
|
||||||
|
|
|
@ -8,17 +8,15 @@ extern crate ransid;
|
||||||
extern crate syscall;
|
extern crate syscall;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::BTreeMap;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::{slice, thread};
|
||||||
use std::{cmp, slice, thread};
|
|
||||||
use ransid::{Console, Event};
|
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 display::Display;
|
||||||
use mode_info::VBEModeInfo;
|
use mode_info::VBEModeInfo;
|
||||||
use primitive::{fast_copy, fast_set64};
|
use primitive::fast_set64;
|
||||||
|
|
||||||
pub mod display;
|
pub mod display;
|
||||||
pub mod mode_info;
|
pub mod mode_info;
|
||||||
|
@ -26,9 +24,7 @@ pub mod primitive;
|
||||||
|
|
||||||
struct DisplayScheme {
|
struct DisplayScheme {
|
||||||
console: RefCell<Console>,
|
console: RefCell<Console>,
|
||||||
display: RefCell<Display>,
|
display: RefCell<Display>
|
||||||
next_id: AtomicUsize,
|
|
||||||
handles: RefCell<BTreeMap<usize, usize>>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scheme for DisplayScheme {
|
impl Scheme for DisplayScheme {
|
||||||
|
@ -40,6 +36,10 @@ impl Scheme for DisplayScheme {
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn fsync(&self, _id: usize) -> Result<usize> {
|
||||||
|
Ok(0)
|
||||||
|
}
|
||||||
|
|
||||||
fn write(&self, _id: usize, buf: &[u8]) -> Result<usize> {
|
fn write(&self, _id: usize, buf: &[u8]) -> Result<usize> {
|
||||||
let mut display = self.display.borrow_mut();
|
let mut display = self.display.borrow_mut();
|
||||||
self.console.borrow_mut().write(buf, |event| {
|
self.console.borrow_mut().write(buf, |event| {
|
||||||
|
@ -52,57 +52,11 @@ impl Scheme for DisplayScheme {
|
||||||
Ok(buf.len())
|
Ok(buf.len())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn close(&self, id: usize) -> Result<usize> {
|
fn close(&self, _id: usize) -> Result<usize> {
|
||||||
Ok(0)
|
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() {
|
fn main() {
|
||||||
let width;
|
let width;
|
||||||
let height;
|
let height;
|
||||||
|
@ -135,17 +89,15 @@ fn main() {
|
||||||
display: RefCell::new(Display::new(width, height,
|
display: RefCell::new(Display::new(width, height,
|
||||||
unsafe { slice::from_raw_parts_mut(onscreen as *mut u32, size) },
|
unsafe { slice::from_raw_parts_mut(onscreen as *mut u32, size) },
|
||||||
unsafe { slice::from_raw_parts_mut(offscreen 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 {
|
loop {
|
||||||
let mut packet = Packet::default();
|
let mut packet = Packet::default();
|
||||||
socket.read(&mut packet);
|
socket.read(&mut packet).expect("vesad: failed to read display scheme");
|
||||||
//println!("vesad: {:?}", packet);
|
//println!("vesad: {:?}", packet);
|
||||||
scheme.handle(&mut packet);
|
scheme.handle(&mut packet);
|
||||||
socket.write(&packet);
|
socket.write(&packet).expect("vesad: failed to write display scheme");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
initfs:bin/vesad
|
initfs:bin/vesad
|
||||||
#initfs:bin/ps2d
|
initfs:bin/ps2d
|
||||||
#initfs:bin/pcid
|
#initfs:bin/pcid
|
||||||
initfs:bin/example
|
#initfs:bin/example
|
||||||
#initfs:bin/ion
|
initfs:bin/login display: initfs:bin/ion
|
||||||
|
|
|
@ -452,7 +452,7 @@ pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result<usize> {
|
||||||
));
|
));
|
||||||
|
|
||||||
let mut arg_size = 0;
|
let mut arg_size = 0;
|
||||||
for arg in args.iter() {
|
for arg in args.iter().rev() {
|
||||||
sp -= mem::size_of::<usize>();
|
sp -= mem::size_of::<usize>();
|
||||||
unsafe { *(sp as *mut usize) = arch::USER_ARG_OFFSET + arg_size; }
|
unsafe { *(sp as *mut usize) = arch::USER_ARG_OFFSET + arg_size; }
|
||||||
sp -= mem::size_of::<usize>();
|
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;
|
let mut arg_offset = 0;
|
||||||
for arg in args.iter() {
|
for arg in args.iter().rev() {
|
||||||
unsafe {
|
unsafe {
|
||||||
memcpy((arch::USER_ARG_OFFSET + arg_offset) as *mut u8,
|
memcpy((arch::USER_ARG_OFFSET + arg_offset) as *mut u8,
|
||||||
arg.as_ptr(),
|
arg.as_ptr(),
|
||||||
|
|
|
@ -36,10 +36,9 @@ pub fn main() {
|
||||||
command.arg(arg);
|
command.arg(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("init: spawning {}", line);
|
|
||||||
match command.spawn() {
|
match command.spawn() {
|
||||||
Ok(mut child) => match child.wait() {
|
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 wait for '{}': {}", line, err)
|
||||||
},
|
},
|
||||||
Err(err) => println!("init: failed to execute '{}': {}", line, err)
|
Err(err) => println!("init: failed to execute '{}': {}", line, err)
|
6
programs/login/Cargo.toml
Normal file
6
programs/login/Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[package]
|
||||||
|
name = "login"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
syscall = { path = "../../syscall/" }
|
38
programs/login/src/main.rs
Normal file
38
programs/login/src/main.rs
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
|
@ -25,24 +25,6 @@ impl Scheme for ExampleScheme {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main(){
|
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 || {
|
thread::spawn(move || {
|
||||||
let mut socket = File::create(":example").expect("example: failed to create example scheme");
|
let mut socket = File::create(":example").expect("example: failed to create example scheme");
|
||||||
let scheme = ExampleScheme;
|
let scheme = ExampleScheme;
|
||||||
|
|
Loading…
Reference in a new issue