Prechádzať zdrojové kódy

Patch fix unix family (#13)

* 调整unix family下,dragonos的编译

* fix dlibc

* fix std

* 1

* 更改部分条件编译,使得其在DragonOS上行为正常

* undate

* update

* update

* pipe与spawn修改
GnoCiYeH 1 rok pred
rodič
commit
f46c81c7ce

+ 2 - 1
dlibc/src/unix/header/signal/mod.rs

@@ -192,7 +192,8 @@ extern "C" {
     fn __restore_rt();
 }
 
-#[no_mangle]
+//TODO: 该行为不一致,使用系统调用signal
+//#[no_mangle]
 pub extern "C" fn signal(
     sig: ::c_int,
     func: Option<extern "C" fn(::c_int)>,

+ 10 - 12
dlibc/src/unix/header/unistd/mod.rs

@@ -2,6 +2,8 @@
 
 use core::{convert::TryFrom, mem, ptr, slice};
 
+pub use self::{brk::*, getopt::*, pathconf::*, sysconf::*};
+use crate::unix::platform;
 use crate::unix::{
     c_str::CStr,
     header::{
@@ -9,16 +11,9 @@ use crate::unix::{
     },
 };
 use alloc::collections::LinkedList;
-use crate::unix::platform;
-pub use self::{brk::*, getopt::*, pathconf::*, sysconf::*};
-
 use ioctl;
-use TIOCSPGRP;
 use TIOCGPGRP;
 
-
-
-
 mod brk;
 mod getopt;
 mod pathconf;
@@ -478,7 +473,12 @@ pub unsafe extern "C" fn pipe(fildes: *mut ::c_int) -> ::c_int {
 // }
 
 #[no_mangle]
-pub unsafe extern "C" fn pread(fildes: ::c_int, buf: *mut ::c_void, nbyte: ::size_t, offset: ::off_t) -> ::ssize_t {
+pub unsafe extern "C" fn pread(
+    fildes: ::c_int,
+    buf: *mut ::c_void,
+    nbyte: ::size_t,
+    offset: ::off_t,
+) -> ::ssize_t {
     //TODO: better pread using system calls
 
     let previous = ::lseek(fildes, offset, SEEK_SET);
@@ -664,7 +664,7 @@ pub extern "C" fn truncate(path: *const ::c_char, length: ::off_t) -> ::c_int {
         return -1;
     }
 
-    let res = unsafe{::ftruncate(fd, length)};
+    let res = unsafe { ::ftruncate(fd, length) };
 
     platform::pal::close(fd);
 
@@ -688,9 +688,7 @@ pub extern "C" fn ttyname_r(fildes: ::c_int, name: *mut ::c_char, namesize: ::si
         return errno::ERANGE;
     }
 
-    let len = platform::pal::fpath(fildes, 
-        (&mut name[..namesize - 1]).as_ptr() as *const i8
-    );
+    let len = platform::pal::fpath(fildes, (&mut name[..namesize - 1]).as_ptr() as *const i8);
     if len < 0 {
         return unsafe { -platform::errno };
     }

+ 13 - 12
dlibc/src/unix/platform/dragonos/pal/mod.rs

@@ -782,10 +782,10 @@ pub extern "C" fn syscall(_num: ::c_long) -> ::c_long {
 // pub extern "C" fn setsid() -> ::pid_t{
 // 	unimplemented!()
 // }
-// #[no_mangle]
-// pub extern "C" fn setuid(uid: uid_t) -> ::c_int{
-// 	unimplemented!()
-// }
+#[no_mangle]
+pub extern "C" fn setuid(uid: ::uid_t) -> ::c_int{
+	0
+}
 
 // #[cfg_attr(
 //     all(target_os = "macos", target_arch = "x86"),
@@ -921,10 +921,11 @@ pub extern "C" fn syscall(_num: ::c_long) -> ::c_long {
 // 	unimplemented!()
 // }
 
-// #[no_mangle]
-// pub extern "C" fn signal(signum: ::c_int, handler: sighandler_t) -> sighandler_t{
-// 	unimplemented!()
-// }
+#[no_mangle]
+pub extern "C" fn signal(signum: ::c_int, handler: ::sighandler_t) -> ::sighandler_t{
+	0
+    //unimplemented!()
+}
 
 // #[cfg_attr(target_os = "netbsd", link_name = "__getrusage50")]
 // #[no_mangle]
@@ -1778,10 +1779,10 @@ pub extern "C" fn pthread_setspecific(_key: ::pthread_key_t, _value: *const ::c_
 // pub extern "C" fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void{
 // 	unimplemented!()
 // }
-// #[no_mangle]
-// pub extern "C" fn setgroups(ngroups: ::size_t, ptr: *const ::gid_t) -> ::c_int{
-// 	unimplemented!()
-// }
+#[no_mangle]
+pub extern "C" fn setgroups(ngroups: ::size_t, ptr: *const ::gid_t) -> ::c_int{
+	0
+}
 // #[no_mangle]
 // pub extern "C" fn pipe2(fds: *mut ::c_int, flags: ::c_int) -> ::c_int{
 // 	if flags == 0 {

+ 89 - 82
dlibc/src/unix/platform/dragonos/pal/relibc_adapter/pal.rs

@@ -1,32 +1,34 @@
 
 
+
 use crate::unix::platform::pal::{e};
 use crate::unix::c_str::CStr;
+use crate::unix::platform::pal::e;
 use crate::unix::*;
 use dsc::syscall;
 
 pub extern "C" fn utimens(_path: &CStr, _times: *const timespec) -> ::c_int {
-	// e(unsafe { syscall!(UTIMENSAT, AT_FDCWD, path.as_ptr(), times, 0) }) as ::c_int
-	unimplemented!()
+    // e(unsafe { syscall!(UTIMENSAT, AT_FDCWD, path.as_ptr(), times, 0) }) as ::c_int
+    unimplemented!()
 }
 
 #[no_mangle]
-pub extern "C" fn write(fd: ::c_int, buf: *const ::c_void, count: ::size_t) -> ::ssize_t{
-	e(unsafe { syscall!(SYS_WRITE, fd, buf, count) }) as ::ssize_t
+pub extern "C" fn write(fd: ::c_int, buf: *const ::c_void, count: ::size_t) -> ::ssize_t {
+    e(unsafe { syscall!(SYS_WRITE, fd, buf, count) }) as ::ssize_t
 }
 
 #[no_mangle]
-pub extern "C" fn access(_path: *const ::c_char, _amode: ::c_int) -> ::c_int{
-	unimplemented!()
+pub extern "C" fn access(_path: *const ::c_char, _amode: ::c_int) -> ::c_int {
+    unimplemented!()
 }
 
-pub extern "C" fn brk(addr: *mut ::c_void) -> *mut ::c_void{
-	unsafe { syscall!(SYS_BRK, addr) as *mut ::c_void }
+pub extern "C" fn brk(addr: *mut ::c_void) -> *mut ::c_void {
+    unsafe { syscall!(SYS_BRK, addr) as *mut ::c_void }
 }
 
 #[no_mangle]
-pub extern "C" fn chdir(dir: *const ::c_char) -> ::c_int{
-	e(unsafe { syscall!(SYS_CHDIR, dir) }) as ::c_int
+pub extern "C" fn chdir(dir: *const ::c_char) -> ::c_int {
+    e(unsafe { syscall!(SYS_CHDIR, dir) }) as ::c_int
 }
 
 #[no_mangle]
@@ -45,18 +47,18 @@ pub extern "C" fn clock_gettime(_clk_id: ::clockid_t, _tp: *mut ::timespec) -> :
 }
 
 #[no_mangle]
-pub extern "C" fn close(fd: ::c_int) -> ::c_int{
-	e(unsafe { syscall!(SYS_CLOSE, fd) }) as ::c_int
+pub extern "C" fn close(fd: ::c_int) -> ::c_int {
+    e(unsafe { syscall!(SYS_CLOSE, fd) }) as ::c_int
 }
 
 #[no_mangle]
-pub extern "C" fn dup(fd: ::c_int) -> ::c_int{
-	e(unsafe { syscall!(SYS_DUP, fd) }) as ::c_int
+pub extern "C" fn dup(fd: ::c_int) -> ::c_int {
+    e(unsafe { syscall!(SYS_DUP, fd) }) as ::c_int
 }
 
 #[no_mangle]
-pub extern "C" fn dup2(src: ::c_int, dst: ::c_int) -> ::c_int{
-	e(unsafe { syscall!(SYS_DUP2, src, dst) }) as ::c_int
+pub extern "C" fn dup2(src: ::c_int, dst: ::c_int) -> ::c_int {
+    e(unsafe { syscall!(SYS_DUP2, src, dst) }) as ::c_int
 }
 
 #[no_mangle]
@@ -64,21 +66,21 @@ pub extern "C" fn execve(
     prog: *const ::c_char,
     argv_: *const *const ::c_char,
     envp: *const *const ::c_char,
-) -> ::c_int{
-	e(unsafe{syscall!(SYS_EXECVE, prog, argv_, envp)}) as ::c_int
+) -> ::c_int {
+    e(unsafe { syscall!(SYS_EXECVE, prog, argv_, envp) }) as ::c_int
 }
 
 #[no_mangle]
-pub extern "C" fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int{
-	e(unsafe { syscall!(SYS_FSTAT, fildes, buf) }) as ::c_int
+pub extern "C" fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int {
+    e(unsafe { syscall!(SYS_FSTAT, fildes, buf) }) as ::c_int
 }
 
 //#[no_mangle]
-pub extern "C" fn exit(status: ::c_int) -> !{
-	unsafe {
-		syscall!(SYS_EXIT, status);
-	}
-	loop {}
+pub extern "C" fn exit(status: ::c_int) -> ! {
+    unsafe {
+        syscall!(SYS_EXIT, status);
+    }
+    loop {}
 }
 
 #[no_mangle]
@@ -107,13 +109,13 @@ pub extern "C" fn fstatvfs(_fd: ::c_int, _buf: *mut statvfs) -> ::c_int{
 }
 
 #[no_mangle]
-pub extern "C" fn fcntl(fd: ::c_int, cmd: ::c_int,arg: ::c_int) -> ::c_int{
-	e(unsafe { syscall!(SYS_FCNTL, fd, cmd, arg) }) as ::c_int
+pub extern "C" fn fcntl(fd: ::c_int, cmd: ::c_int, arg: ::c_int) -> ::c_int {
+    e(unsafe { syscall!(SYS_FCNTL, fd, cmd, arg) }) as ::c_int
 }
 
 //#[no_mangle]
-pub extern "C" fn fork() -> ::pid_t{
-	e(unsafe { syscall!(SYS_FORK) }) as ::pid_t
+pub extern "C" fn fork() -> ::pid_t {
+    e(unsafe { syscall!(SYS_FORK) }) as ::pid_t
 }
 
 #[no_mangle]
@@ -127,8 +129,8 @@ pub extern "C" fn fsync(_fd: ::c_int) -> ::c_int{
 }
 
 #[no_mangle]
-pub extern "C" fn ftruncate(fd: ::c_int, length: off_t) -> ::c_int{
-	e(unsafe { syscall!(SYS_FTRUNCATE, fd, length) }) as ::c_int
+pub extern "C" fn ftruncate(fd: ::c_int, length: off_t) -> ::c_int {
+    e(unsafe { syscall!(SYS_FTRUNCATE, fd, length) }) as ::c_int
 }
 
 pub extern "C" fn futex(_addr: *mut ::c_int, _op: ::c_int, _val: ::c_int, _val2: usize) -> ::c_int {
@@ -178,22 +180,27 @@ pub extern "C" fn getdents(
 }
 
 #[no_mangle]
-pub extern "C" fn getegid() -> gid_t{
-	0
+pub extern "C" fn getdents(fd: ::c_int, dirents: *mut dirent, bytes: usize) -> ::c_int {
+    unsafe { syscall!(SYS_GET_DENTS, dirents, bytes) as ::c_int }
 }
 
 #[no_mangle]
-pub extern "C" fn geteuid() -> uid_t{
-	0
+pub extern "C" fn getegid() -> gid_t {
+    0
 }
 
 #[no_mangle]
-pub extern "C" fn getgid() -> gid_t{
-	0
+pub extern "C" fn geteuid() -> uid_t {
+    0
+}
+
+#[no_mangle]
+pub extern "C" fn getgid() -> gid_t {
+    0
 }
 
 //#[no_mangle]
-pub extern "C" fn getpagesize() -> usize{
+pub extern "C" fn getpagesize() -> usize {
     unimplemented!()
 }
 
@@ -203,13 +210,13 @@ pub extern "C" fn getpgid(_pid: ::pid_t) -> ::pid_t{
 }
 
 #[no_mangle]
-pub extern "C" fn getpid() -> ::pid_t{
-	e(unsafe { syscall!(SYS_GETPID) }) as ::pid_t
+pub extern "C" fn getpid() -> ::pid_t {
+    e(unsafe { syscall!(SYS_GETPID) }) as ::pid_t
 }
 
 #[no_mangle]
-pub extern "C" fn getppid() -> ::pid_t{
-	0
+pub extern "C" fn getppid() -> ::pid_t {
+    0
 }
 
 #[no_mangle]
@@ -223,18 +230,18 @@ pub extern "C" fn getsid(_pid: ::pid_t) -> ::pid_t{
 }
 
 #[no_mangle]
-pub extern "C" fn gettid() -> ::pid_t{
-	unimplemented!()
+pub extern "C" fn gettid() -> ::pid_t {
+    unimplemented!()
 }
 
 //#[no_mangle]
-pub extern "C" fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int{
-	e(unsafe { syscall!(SYS_GETTIMEOFDAY, tp, tz) }) as ::c_int
+pub extern "C" fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int {
+    e(unsafe { syscall!(SYS_GETTIMEOFDAY, tp, tz) }) as ::c_int
 }
 
 #[no_mangle]
-pub extern "C" fn getuid() -> uid_t{
-	0
+pub extern "C" fn getuid() -> uid_t {
+    0
 }
 
 #[no_mangle]
@@ -248,13 +255,13 @@ pub extern "C" fn link(_src: *const ::c_char, _dst: *const ::c_char) -> ::c_int{
 }
 
 #[no_mangle]
-pub extern "C" fn lseek(fd: ::c_int, offset: off_t, whence: ::c_int) -> off_t{
-	e(unsafe { syscall!(SYS_LSEEK, fd, offset, whence) }) as off_t
+pub extern "C" fn lseek(fd: ::c_int, offset: off_t, whence: ::c_int) -> off_t {
+    e(unsafe { syscall!(SYS_LSEEK, fd, offset, whence) }) as off_t
 }
 
 #[no_mangle]
-pub extern "C" fn mkdir(path: *const ::c_char, mode: mode_t) -> ::c_int{
-	e(unsafe { syscall!(SYS_MKDIR, path, mode) }) as ::c_int
+pub extern "C" fn mkdir(path: *const ::c_char, mode: mode_t) -> ::c_int {
+    e(unsafe { syscall!(SYS_MKDIR, path, mode) }) as ::c_int
 }
 
 #[no_mangle]
@@ -280,13 +287,13 @@ pub extern "C" fn mmap(
     flags: ::c_int,
     fd: ::c_int,
     offset: off_t,
-) -> *mut ::c_void{
-	e(unsafe{syscall!(SYS_MMAP, addr, len, prot, flags, fd, offset)}) as *mut ::c_void
+) -> *mut ::c_void {
+    e(unsafe { syscall!(SYS_MMAP, addr, len, prot, flags, fd, offset) }) as *mut ::c_void
 }
 
 #[no_mangle]
-pub extern "C" fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int{
-	e(unsafe{syscall!(SYS_MPROTECT, addr, len, prot)}) as ::c_int
+pub extern "C" fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int {
+    e(unsafe { syscall!(SYS_MPROTECT, addr, len, prot) }) as ::c_int
 }
 
 #[no_mangle]
@@ -300,32 +307,32 @@ pub extern "C" fn munlock(_addr: *const ::c_void, _len: ::size_t) -> ::c_int{
 }
 
 #[no_mangle]
-pub extern "C" fn munlockall() -> ::c_int{
-	unimplemented!()
+pub extern "C" fn munlockall() -> ::c_int {
+    unimplemented!()
 }
 
 #[no_mangle]
-pub extern "C" fn munmap(addr: *mut ::c_void, len: ::size_t) -> ::c_int{
-	e(unsafe{syscall!(SYS_MUNMAP, addr, len)}) as ::c_int
+pub extern "C" fn munmap(addr: *mut ::c_void, len: ::size_t) -> ::c_int {
+    e(unsafe { syscall!(SYS_MUNMAP, addr, len) }) as ::c_int
 }
 
 #[no_mangle]
-pub extern "C" fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> ::c_int{
-	e(unsafe { syscall!(SYS_NANOSLEEP, rqtp, rmtp) }) as ::c_int
+pub extern "C" fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> ::c_int {
+    e(unsafe { syscall!(SYS_NANOSLEEP, rqtp, rmtp) }) as ::c_int
 }
 
 #[no_mangle]
-pub extern "C" fn open(path: *const ::c_char, oflag: ::c_int, mode: mode_t) -> ::c_int{
-	e(unsafe { syscall!(SYS_OPEN, path, oflag, mode) }) as ::c_int
+pub extern "C" fn open(path: *const ::c_char, oflag: ::c_int, mode: mode_t) -> ::c_int {
+    e(unsafe { syscall!(SYS_OPEN, path, oflag, mode) }) as ::c_int
 }
 
 #[no_mangle]
-pub extern "C" fn pipe2(fds: *mut ::c_int, flags: ::c_int) -> ::c_int{
-	if flags == 0 {
-		e(unsafe { syscall!(SYS_PIPE, fds) }) as ::c_int
-	} else {
-		unimplemented!()
-	}
+pub extern "C" fn pipe2(fds: *mut ::c_int, flags: ::c_int) -> ::c_int {
+    if flags == 0 {
+        e(unsafe { syscall!(SYS_PIPE, fds) }) as ::c_int
+    } else {
+        unimplemented!()
+    }
 }
 
 #[no_mangle]
@@ -334,8 +341,8 @@ pub unsafe extern "C" fn pte_clone(_stack: *mut usize) -> ::pid_t{
 }
 
 #[no_mangle]
-pub extern "C" fn read(fd: ::c_int, buf: *mut ::c_void, count: ::size_t) -> ::ssize_t{
-	e(unsafe { syscall!(SYS_READ, fd, buf, count) }) as ::ssize_t
+pub extern "C" fn read(fd: ::c_int, buf: *mut ::c_void, count: ::size_t) -> ::ssize_t {
+    e(unsafe { syscall!(SYS_READ, fd, buf, count) }) as ::ssize_t
 }
 
 pub extern "C" fn readlink(_path: *const c_char, _buf: *mut c_char, _bufsz: ::size_t) -> ::ssize_t{
@@ -348,13 +355,13 @@ pub extern "C" fn rename(_oldname: *const ::c_char, _newname: *const ::c_char) -
 }
 
 #[no_mangle]
-pub extern "C" fn rmdir(path: *const ::c_char) -> ::c_int{
-	e(unsafe { syscall!(SYS_UNLINK_AT, 0, path, AT_REMOVEDIR) }) as ::c_int
+pub extern "C" fn rmdir(path: *const ::c_char) -> ::c_int {
+    e(unsafe { syscall!(SYS_UNLINK_AT, 0, path, AT_REMOVEDIR) }) as ::c_int
 }
 
 #[no_mangle]
-pub extern "C" fn sched_yield() -> ::c_int{
-	unimplemented!()
+pub extern "C" fn sched_yield() -> ::c_int {
+    unimplemented!()
 }
 
 #[no_mangle]
@@ -388,16 +395,16 @@ pub extern "C" fn uname(_buf: *mut ::utsname) -> ::c_int{
 }
 
 #[no_mangle]
-pub extern "C" fn unlink(c: *const ::c_char) -> ::c_int{
-	e(unsafe { syscall!(SYS_UNLINK_AT, AT_FDCWD, c, 0) }) as ::c_int
+pub extern "C" fn unlink(c: *const ::c_char) -> ::c_int {
+    e(unsafe { syscall!(SYS_UNLINK_AT, AT_FDCWD, c, 0) }) as ::c_int
 }
 
 #[no_mangle]
-pub extern "C" fn waitpid(pid: ::pid_t, status: *mut ::c_int, options: ::c_int) -> ::pid_t{
-	e(unsafe { syscall!(SYS_WAIT4, pid, status, options, 0) }) as ::pid_t
+pub extern "C" fn waitpid(pid: ::pid_t, status: *mut ::c_int, options: ::c_int) -> ::pid_t {
+    e(unsafe { syscall!(SYS_WAIT4, pid, status, options, 0) }) as ::pid_t
 }
 
 #[no_mangle]
-pub extern "C" fn verify() -> bool{
+pub extern "C" fn verify() -> bool {
     return true;
-}
+}

+ 4 - 3
dlibc/src/unix/start.rs

@@ -136,15 +136,16 @@ extern "C" fn init_array() {
     //     init_complete = true
     // }
 }
+use stdio;
 
 fn io_init() {
     unsafe {
         // Initialize stdin/stdout/stderr,
         // see https://github.com/rust-lang/rust/issues/51718
         
-        // stdio::stdin = stdio::default_stdin.get();
-        // stdio::stdout = stdio::default_stdout.get();
-        // stdio::stderr = stdio::default_stderr.get();
+        stdio::stdin = stdio::default_stdin.get();
+        stdio::stdout = stdio::default_stdout.get();
+        stdio::stderr = stdio::default_stderr.get();
     }
 }
 

+ 0 - 1
src/std/os/linux/raw.rs

@@ -11,7 +11,6 @@
 
 use crate::std::os::raw::c_ulong;
 
-
 pub type dev_t = u64;
 pub type mode_t = u32;
 

+ 0 - 1
src/std/os/unix/process.rs

@@ -10,7 +10,6 @@ use crate::std::sealed::Sealed;
 use crate::std::sys;
 use crate::std::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
 
-
 use cfg_if::cfg_if;
 
 cfg_if! {

+ 0 - 4
src/std/panicking.rs

@@ -9,7 +9,6 @@
 
 #![deny(unsafe_op_in_unsafe_fn)]
 
-
 use core::panic::{BoxMeUp, Location, PanicInfo};
 
 use crate::std::any::Any;
@@ -20,11 +19,8 @@ use crate::std::process;
 
 use crate::std::sync::{PoisonError, RwLock};
 
-
-
 use crate::std::thread;
 
-
 // make sure to use the stderr output configured
 // by libtest in the real copy of std
 #[cfg(test)]

+ 0 - 1
src/std/sys/unix/args.rs

@@ -9,7 +9,6 @@ use crate::std::ffi::OsString;
 use crate::std::fmt;
 use crate::std::vec;
 
-
 /// One-time global initialization.
 pub unsafe fn init(argc: isize, argv: *const *const u8) {
     imp::init(argc, argv)

+ 2 - 0
src/std/sys/unix/fd.rs

@@ -407,6 +407,7 @@ impl FileDesc {
         target_os = "redox",
         target_os = "vxworks",
         target_os = "nto",
+        target_os = "dragonos"
     )))]
     pub fn set_cloexec(&self) -> io::Result<()> {
         unsafe {
@@ -429,6 +430,7 @@ impl FileDesc {
         target_os = "redox",
         target_os = "vxworks",
         target_os = "nto",
+        target_os = "dragonos"
     ))]
     pub fn set_cloexec(&self) -> io::Result<()> {
         unsafe {

+ 14 - 4
src/std/sys/unix/pipe.rs

@@ -11,7 +11,6 @@ use dlibc;
 ////////////////////////////////////////////////////////////////////////////////
 
 pub struct AnonPipe(FileDesc);
-
 pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
     let mut fds = [0; 2];
 
@@ -25,18 +24,29 @@ pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
             target_os = "linux",
             target_os = "netbsd",
             target_os = "openbsd",
-            target_os = "redox"
+            target_os = "redox",
         ))] {
             unsafe {
                 cvt(dlibc::pipe2(fds.as_mut_ptr(), dlibc::O_CLOEXEC))?;
                 Ok((AnonPipe(FileDesc::from_raw_fd(fds[0])), AnonPipe(FileDesc::from_raw_fd(fds[1]))))
             }
-        } else {
+        }
+        else if #[cfg(target_os = "dragonos")]{
+            unsafe{
+                cvt(dlibc::pipe(fds.as_mut_ptr()))?;
+                let fd0 = FileDesc::from_raw_fd(fds[0]);
+                let fd1 = FileDesc::from_raw_fd(fds[1]);
+                dlibc::fcntl(fd0.as_raw_fd(),dlibc::F_SETFD,dlibc::FD_CLOEXEC);
+                dlibc::fcntl(fd1.as_raw_fd(),dlibc::F_SETFD,dlibc::FD_CLOEXEC);
+                Ok((AnonPipe(fd0), AnonPipe(fd1)))
+            }
+        }
+        else {
             unsafe {
                 cvt(dlibc::pipe(fds.as_mut_ptr()))?;
-
                 let fd0 = FileDesc::from_raw_fd(fds[0]);
                 let fd1 = FileDesc::from_raw_fd(fds[1]);
+                //TODO: dragonos在此处返回错误
                 fd0.set_cloexec()?;
                 fd1.set_cloexec()?;
                 Ok((AnonPipe(fd0), AnonPipe(fd1)))

+ 124 - 108
src/std/sys/unix/process/process_unix.rs

@@ -1,10 +1,12 @@
 use crate::std::fmt;
-use crate::std::io::{self, ErrorKind};
+use crate::std::io::{self, Error, ErrorKind};
 
+use crate::mem;
 use crate::std::num::NonZeroI32;
 use crate::std::sys;
 use crate::std::sys::cvt;
 use crate::std::sys::process::process_common::*;
+use crate::{print, println};
 use core::ffi::NonZero_c_int;
 use dlibc;
 
@@ -73,113 +75,124 @@ impl Command {
         _default: Stdio,
         _needs_stdin: bool,
     ) -> io::Result<(Process, StdioPipes)> {
-        // const CLOEXEC_MSG_FOOTER: [u8; 4] = *b"NOEX";
-
-        // let envp = self.capture_env();
-
-        // if self.saw_nul() {
-        //     return Err(io::const_io_error!(
-        //         ErrorKind::InvalidInput,
-        //         "nul byte found in provided data",
-        //     ));
-        // }
-
-        // let (ours, theirs) = self.setup_io(default, needs_stdin)?;
-
-        // if let Some(ret) = self.posix_spawn(&theirs, envp.as_ref())? {
-        //     return Ok((ret, ours));
-        // }
-
-        // #[cfg(target_os = "linux")]
-        // let (input, output) = sys::net::Socket::new_pair(dlibc::AF_UNIX, dlibc::SOCK_SEQPACKET)?;
-
-        // #[cfg(not(target_os = "linux"))]
-        // let (input, output) = sys::pipe::anon_pipe()?;
-
-        // // Whatever happens after the fork is almost for sure going to touch or
-        // // look at the environment in one way or another (PATH in `execvp` or
-        // // accessing the `environ` pointer ourselves). Make sure no other thread
-        // // is accessing the environment when we do the fork itself.
-        // //
-        // // Note that as soon as we're done with the fork there's no need to hold
-        // // a lock any more because the parent won't do anything and the child is
-        // // in its own process. Thus the parent drops the lock guard immediately.
-        // // The child calls `mem::forget` to leak the lock, which is crucial because
-        // // releasing a lock is not async-signal-safe.
-        // let env_lock = sys::os::env_read_lock();
-        // let pid = unsafe { self.do_fork()? };
-
-        // if pid == 0 {
-        //     crate::std::panic::always_abort();
-        //     mem::forget(env_lock); // avoid non-async-signal-safe unlocking
-        //     drop(input);
-        //     #[cfg(target_os = "linux")]
-        //     if self.get_create_pidfd() {
-        //         self.send_pidfd(&output);
-        //     }
-        //     let Err(err) = unsafe { self.do_exec(theirs, envp.as_ref()) };
-        //     let errno = err.raw_os_error().unwrap_or(dlibc::EINVAL) as u32;
-        //     let errno = errno.to_be_bytes();
-        //     let bytes = [
-        //         errno[0],
-        //         errno[1],
-        //         errno[2],
-        //         errno[3],
-        //         CLOEXEC_MSG_FOOTER[0],
-        //         CLOEXEC_MSG_FOOTER[1],
-        //         CLOEXEC_MSG_FOOTER[2],
-        //         CLOEXEC_MSG_FOOTER[3],
-        //     ];
-        //     // pipe I/O up to PIPE_BUF bytes should be atomic, and then
-        //     // we want to be sure we *don't* run at_exit destructors as
-        //     // we're being torn down regardless
-        //     rtassert!(output.write(&bytes).is_ok());
-        //     unsafe { dlibc::_exit(1) }
-        // }
-
-        // drop(env_lock);
-        // drop(output);
-
-        // #[cfg(target_os = "linux")]
-        // let pidfd = if self.get_create_pidfd() { self.recv_pidfd(&input) } else { -1 };
-
-        // #[cfg(not(target_os = "linux"))]
-        // let pidfd = -1;
-
-        // // Safety: We obtained the pidfd from calling `clone3` with
-        // // `CLONE_PIDFD` so it's valid an otherwise unowned.
-        // let mut p = unsafe { Process::new(pid, pidfd) };
-        // let mut bytes = [0; 8];
-
-        // // loop to handle EINTR
-        // loop {
-        //     match input.read(&mut bytes) {
-        //         Ok(0) => return Ok((p, ours)),
-        //         Ok(8) => {
-        //             let (errno, footer) = bytes.split_at(4);
-        //             assert_eq!(
-        //                 CLOEXEC_MSG_FOOTER, footer,
-        //                 "Validation on the CLOEXEC pipe failed: {:?}",
-        //                 bytes
-        //             );
-        //             let errno = i32::from_be_bytes(errno.try_into().unwrap());
-        //             assert!(p.wait().is_ok(), "wait() should either return Ok or panic");
-        //             return Err(Error::from_raw_os_error(errno));
-        //         }
-        //         Err(ref e) if e.is_interrupted() => {}
-        //         Err(e) => {
-        //             assert!(p.wait().is_ok(), "wait() should either return Ok or panic");
-        //             panic!("the CLOEXEC pipe failed: {e:?}")
-        //         }
-        //         Ok(..) => {
-        //             // pipe I/O up to PIPE_BUF bytes should be atomic
-        //             // similarly SOCK_SEQPACKET messages should arrive whole
-        //             assert!(p.wait().is_ok(), "wait() should either return Ok or panic");
-        //             panic!("short read on the CLOEXEC pipe")
-        //         }
-        //     }
-        // }
-        unimplemented!();
+        const CLOEXEC_MSG_FOOTER: [u8; 4] = *b"NOEX";
+        let envp = self.capture_env();
+
+        if self.saw_nul() {
+            return Err(io::const_io_error!(
+                ErrorKind::InvalidInput,
+                "nul byte found in provided data",
+            ));
+        }
+
+        let (ours, theirs) = self.setup_io(default, needs_stdin)?;
+
+        if let Some(ret) = self.posix_spawn(&theirs, envp.as_ref())? {
+            return Ok((ret, ours));
+        }
+
+        #[cfg(target_os = "linux")]
+        let (input, output) = sys::net::Socket::new_pair(dlibc::AF_UNIX, dlibc::SOCK_SEQPACKET)?;
+
+        #[cfg(not(target_os = "linux"))]
+        let (input, output) = sys::pipe::anon_pipe()?;
+
+        // Whatever happens after the fork is almost for sure going to touch or
+        // look at the environment in one way or another (PATH in `execvp` or
+        // accessing the `environ` pointer ourselves). Make sure no other thread
+        // is accessing the environment when we do the fork itself.
+        //
+        // Note that as soon as we're done with the fork there's no need to hold
+        // a lock any more because the parent won't do anything and the child is
+        // in its own process. Thus the parent drops the lock guard immediately.
+        // The child calls `mem::forget` to leak the lock, which is crucial because
+        // releasing a lock is not async-signal-safe.
+
+        let env_lock = sys::os::env_read_lock();
+        let pid = unsafe { self.do_fork()? };
+        if pid == 0 {
+            crate::std::panic::always_abort();
+            mem::forget(env_lock); // avoid non-async-signal-safe unlocking
+            drop(input);
+            #[cfg(target_os = "linux")]
+            if self.get_create_pidfd() {
+                self.send_pidfd(&output);
+            }
+            //此处改动
+            if let Err(err) = unsafe { self.do_exec(theirs, envp.as_ref()) } {
+                let errno = err.raw_os_error().unwrap_or(dlibc::EINVAL) as u32;
+                let errno = errno.to_be_bytes();
+                let bytes = [
+                    errno[0],
+                    errno[1],
+                    errno[2],
+                    errno[3],
+                    CLOEXEC_MSG_FOOTER[0],
+                    CLOEXEC_MSG_FOOTER[1],
+                    CLOEXEC_MSG_FOOTER[2],
+                    CLOEXEC_MSG_FOOTER[3],
+                ];
+                // pipe I/O up to PIPE_BUF bytes should be atomic, and then
+                // we want to be sure we *don't* run at_exit destructors as
+                // we're being torn down regardless
+                rtassert!(output.write(&bytes).is_ok());
+                unsafe { dlibc::_exit(1) }
+            }
+        } else {
+            use crate::print;
+            use crate::println;
+
+            drop(env_lock);
+            drop(output);
+
+            #[cfg(target_os = "linux")]
+            let pidfd = if self.get_create_pidfd() {
+                self.recv_pidfd(&input)
+            } else {
+                -1
+            };
+
+            #[cfg(not(target_os = "linux"))]
+            let pidfd = -1;
+
+            // Safety: We obtained the pidfd from calling `clone3` with
+            // `CLONE_PIDFD` so it's valid an otherwise unowned.
+            let mut p = unsafe { Process::new(pid, pidfd) };
+            let mut bytes = [0; 8];
+
+            //test
+            //return Ok((p,ours));
+            // loop to handle EINTR
+            loop {
+                match input.read(&mut bytes) {
+                    Ok(0) => return Ok((p, ours)),
+                    Ok(8) => {
+                        let (errno, footer) = bytes.split_at(4);
+                        assert_eq!(
+                            CLOEXEC_MSG_FOOTER, footer,
+                            "Validation on the CLOEXEC pipe failed: {:?}",
+                            bytes
+                        );
+                        let errno = i32::from_be_bytes(errno.try_into().unwrap());
+                        assert!(p.wait().is_ok(), "wait() should either return Ok or panic");
+                        return Err(Error::from_raw_os_error(errno));
+                    }
+                    Err(ref e) if e.is_interrupted() => {}
+                    Err(e) => {
+                        assert!(p.wait().is_ok(), "wait() should either return Ok or panic");
+                        panic!("the CLOEXEC pipe failed: {e:?}")
+                    }
+                    Ok(..) => {
+                        // pipe I/O up to PIPE_BUF bytes should be atomic
+                        // similarly SOCK_SEQPACKET messages should arrive whole
+                        assert!(p.wait().is_ok(), "wait() should either return Ok or panic");
+                        panic!("short read on the CLOEXEC pipe")
+                    }
+                }
+            }
+        }
+        //TODO: 改动
+        return Err(Error::last_os_error());
     }
 
     pub fn output(&mut self) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> {
@@ -309,6 +322,7 @@ impl Command {
         stdio: ChildPipes,
         maybe_envp: Option<&CStringArray>,
     ) -> Result<!, io::Error> {
+
         use crate::std::sys::{self, cvt_r};
 
         if let Some(fd) = stdio.stdin.fd() {
@@ -431,6 +445,7 @@ impl Command {
         all(target_os = "linux", target_env = "gnu"),
         all(target_os = "linux", target_env = "musl"),
         target_os = "nto",
+        targte_os = "dragonos"
     )))]
     fn posix_spawn(
         &mut self,
@@ -451,6 +466,7 @@ impl Command {
         all(target_os = "linux", target_env = "gnu"),
         all(target_os = "linux", target_env = "musl"),
         target_os = "nto",
+        targte_os = "dragonos"
     ))]
     fn posix_spawn(
         &mut self,

+ 0 - 5
src/std/sys_common/backtrace.rs

@@ -1,10 +1,5 @@
 //use crate::std::backtrace_rs::{self, BacktraceFmt, BytesOrWideString, PrintFmt};
 
-
-
-
-
-
 use crate::std::sync::{Mutex, PoisonError};
 
 

+ 0 - 1
src/std/sys_common/thread_local_key.rs

@@ -53,7 +53,6 @@ mod tests;
 use crate::std::sync::atomic::{self, AtomicUsize, Ordering};
 use crate::std::sys::thread_local_key as imp;
 
-
 /// A type for TLS keys that are statically allocated.
 ///
 /// This type is entirely `unsafe` to use as it does not protect against

+ 34 - 0
target.json

@@ -0,0 +1,34 @@
+{
+    "arch": "x86_64",
+    "code-model": "kernel",
+    "cpu": "x86-64",
+    "os": "dragonos",
+    "target-endian": "little",
+    "target-pointer-width": "64",
+    "target-family": [
+        "unix"
+    ],
+    "target-c-int-width": "32",
+    "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
+    "disable-redzone": true,
+    "features": "-3dnow,-3dnowa,-avx,-avx2",
+    "linker": "rust-lld",
+    "linker-flavor": "ld.lld",
+    "llvm-target": "x86_64-unknown-none",
+    "max-atomic-width": 64,
+    "panic-strategy": "abort",
+    "position-independent-executables": true,
+    "relro-level": "full",
+    "stack-probes": {
+        "kind": "inline-or-call",
+        "min-llvm-version-for-inline": [
+            16,
+            0,
+            0
+        ]
+    },
+    "static-position-independent-executables": true,
+    "supported-sanitizers": [
+        "kcfi"
+    ]
+}