1
0
Fork 0
mirror of https://gitlab.redox-os.org/CoffeeCode/redox-ssh.git synced 2025-12-28 15:22:18 +01:00

WIP: Replace redox_syscall with libredox

This commit is contained in:
Laurenz 2024-09-28 15:03:14 +02:00
parent d582aca73f
commit b30a46e568
Signed by: C0ffeeCode
SSH key fingerprint: SHA256:jnEltBNftC3wUZESLSMvM9zVPOkkevGRzqqoW2k2ORI
5 changed files with 48 additions and 16 deletions

31
Cargo.lock generated
View file

@ -31,6 +31,12 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
[[package]] [[package]]
name = "block-buffer" name = "block-buffer"
version = "0.10.4" version = "0.10.4"
@ -220,6 +226,17 @@ version = "0.2.159"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5"
[[package]]
name = "libredox"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [
"bitflags 2.6.0",
"libc",
"redox_syscall 0.5.6",
]
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.22" version = "0.4.22"
@ -332,10 +349,11 @@ dependencies = [
"ed25519-dalek", "ed25519-dalek",
"hmac", "hmac",
"libc", "libc",
"libredox",
"log", "log",
"num-bigint", "num-bigint",
"rand", "rand",
"redox_syscall", "redox_syscall 0.2.16",
"sha2", "sha2",
] ]
@ -345,7 +363,16 @@ version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [ dependencies = [
"bitflags", "bitflags 1.3.2",
]
[[package]]
name = "redox_syscall"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "355ae415ccd3a04315d3f8246e86d67689ea74d88d915576e1589a351062a13b"
dependencies = [
"bitflags 2.6.0",
] ]
[[package]] [[package]]

View file

@ -23,6 +23,9 @@ name = "ssh-keygen"
path = "src/bin/ssh-keygen.rs" path = "src/bin/ssh-keygen.rs"
doc = false doc = false
[features]
default = []
[dependencies] [dependencies]
byteorder = "^1.5.0" byteorder = "^1.5.0"
log = "^0.4.22" log = "^0.4.22"
@ -46,3 +49,4 @@ libc = "^0.2.159"
[target.'cfg(target_os = "redox")'.dependencies] [target.'cfg(target_os = "redox")'.dependencies]
redox_syscall = "0.2" redox_syscall = "0.2"
libredox = "~0.1.3" # Does not follow SemVer

View file

@ -88,14 +88,9 @@ impl Channel {
self.read_thread = Some(thread::spawn(move || { self.read_thread = Some(thread::spawn(move || {
#[cfg(target_os = "redox")] #[cfg(target_os = "redox")]
use syscall::dup; let master2 = unsafe { syscall::dup(master_fd as usize, &[]).unwrap_or(!0) };
#[cfg(target_os = "redox")]
let master2 = unsafe { dup(master_fd as usize, &[]).unwrap_or(!0) };
#[cfg(not(target_os = "redox"))] #[cfg(not(target_os = "redox"))]
use libc::dup; let master2 = unsafe { libc::dup(master_fd) };
#[cfg(not(target_os = "redox"))]
let master2 = unsafe { dup(master_fd) };
println!("dup result: {}", master2 as u32); println!("dup result: {}", master2 as u32);
let mut master = unsafe { File::from_raw_fd(master2 as i32) }; let mut master = unsafe { File::from_raw_fd(master2 as i32) };
@ -103,6 +98,9 @@ impl Channel {
use std::str::from_utf8_unchecked; use std::str::from_utf8_unchecked;
let mut buf = [0; 4096]; let mut buf = [0; 4096];
let count = master.read(&mut buf).unwrap(); let count = master.read(&mut buf).unwrap();
// This is weird.
// An error is thrown&unwrapped here (panic)
// but yet it continues to function properly
if count == 0 { if count == 0 {
break; break;
} }

View file

@ -4,8 +4,8 @@ extern crate rand;
extern crate num_bigint; extern crate num_bigint;
#[macro_use] #[macro_use]
extern crate log; extern crate log;
#[cfg(target_os = "redox")] // #[cfg(target_os = "redox")]
extern crate syscall; // extern crate syscall;
#[cfg(not(target_os = "redox"))] #[cfg(not(target_os = "redox"))]
extern crate libc; extern crate libc;

View file

@ -7,21 +7,24 @@ pub fn before_exec() -> Result<()> {
} }
pub fn fork() -> usize { pub fn fork() -> usize {
extern crate syscall; todo!("You must specify -f, the old forking for Redox doesn't work anyway.");
unsafe { syscall::clone(syscall::CloneFlags::empty()).unwrap() } // The following on't work anyway
// but will panic due to missing implementation
// extern crate syscall;
// unsafe { syscall::clone(syscall::CloneFlags::empty()).unwrap() }
} }
pub fn set_winsize(fd: RawFd, row: u16, col: u16, xpixel: u16, ypixel: u16) {} pub fn set_winsize(fd: RawFd, row: u16, col: u16, xpixel: u16, ypixel: u16) {}
pub fn getpty() -> (RawFd, PathBuf) { pub fn getpty() -> (RawFd, PathBuf) {
use syscall; use libredox::{call, flag};
let master = syscall::open("pty:", syscall::O_RDWR | syscall::O_CREAT) let master = call::open("pty:", flag::O_RDWR | flag::O_CREAT, 777)
.unwrap(); .unwrap();
let mut buf: [u8; 4096] = [0; 4096]; let mut buf: [u8; 4096] = [0; 4096];
let count = syscall::fpath(master, &mut buf).unwrap(); let count = call::fpath(master, &mut buf).unwrap();
( (
master as i32, master as i32,
PathBuf::from(unsafe { PathBuf::from(unsafe {