Browse Source

修改spawn和pipe2等一系列问题 (#15)

* 调整unix family下,dragonos的编译

* fix dlibc

* fix std

* 1

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

* undate

* update

* update

* pipe与spawn修改

* update

* 修改pipe2问题,以及临时解决spawn时内核报错问题
GnoCiYeH 1 year ago
parent
commit
a84e10c84b

+ 3 - 4
dlibc/src/unix/header/unistd/mod.rs

@@ -6,13 +6,12 @@ pub use self::{brk::*, getopt::*, pathconf::*, sysconf::*};
 use crate::unix::platform;
 use crate::unix::{
     c_str::CStr,
-    header::{
-        errno, limits, stdlib::getenv, sys_time, termios,
-    },
+    header::{errno, limits, stdlib::getenv, sys_time, termios},
 };
 use alloc::collections::LinkedList;
 use ioctl;
 use TIOCGPGRP;
+use TIOCSPGRP;
 
 mod brk;
 mod getopt;
@@ -462,7 +461,7 @@ pub extern "C" fn pause() -> ::c_int {
     unimplemented!();
 }
 
-#[no_mangle]
+//#[no_mangle]
 pub unsafe extern "C" fn pipe(fildes: *mut ::c_int) -> ::c_int {
     ::pipe2(fildes, 0)
 }

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

@@ -752,10 +752,10 @@ pub extern "C" fn syscall(_num: ::c_long) -> ::c_long {
 // pub extern "C" fn pathconf(path: *const ::c_char, name: ::c_int) -> c_long{
 // 	unimplemented!()
 // }
-// #[no_mangle]
-// pub extern "C" fn pipe(fds: *mut ::c_int) -> ::c_int{
-// 	unimplemented!()
-// }
+#[no_mangle]
+pub extern "C" fn pipe(fds: *mut ::c_int) -> ::c_int{
+	e(unsafe { syscall!(SYS_PIPE, fds) }) as ::c_int
+}
 // #[no_mangle]
 // pub extern "C" fn posix_memalign(memptr: *mut *mut ::c_void, align: ::size_t, size: ::size_t) -> ::c_int{
 // 	unimplemented!()

+ 1 - 5
dlibc/src/unix/platform/dragonos/pal/relibc_adapter/pal.rs

@@ -318,11 +318,7 @@ pub extern "C" fn open(path: *const ::c_char, oflag: ::c_int, mode: mode_t) -> :
 
 #[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!()
-    }
+    e(unsafe { syscall!(SYS_PIPE, fds, flags )}) as ::c_int
 }
 
 #[no_mangle]

+ 1 - 1
src/std/sys/unix/fs.rs

@@ -60,7 +60,7 @@ use dlibc::fstatat64;
     target_os = "vita",
 ))]
 use dlibc::readdir as readdir64;
-#[cfg(any(target_os = "linux",target_os = "dragonos",))]
+#[cfg(any(target_os = "linux", target_os = "dragonos",))]
 use dlibc::readdir64;
 #[cfg(any(target_os = "emscripten", target_os = "l4re"))]
 use dlibc::readdir64_r;

+ 2 - 12
src/std/sys/unix/pipe.rs

@@ -25,23 +25,13 @@ pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
             target_os = "netbsd",
             target_os = "openbsd",
             target_os = "redox",
+            target_os = "dragonos"
         ))] {
             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 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 {
+        }else {
             unsafe {
                 cvt(dlibc::pipe(fds.as_mut_ptr()))?;
                 let fd0 = FileDesc::from_raw_fd(fds[0]);

+ 1 - 1
src/std/sys/unix/process/process_unix.rs

@@ -158,7 +158,7 @@ impl Command {
             let mut bytes = [0; 8];
 
             //TODO: 这里直接返回,没有从管道读取子进程状态,后续需更改
-            return Ok((p,ours));
+            return Ok((p, ours));
             // loop to handle EINTR
             loop {
                 match input.read(&mut bytes) {