Browse Source

Patch fix unix family (#14)

* 调整unix family下,dragonos的编译

* fix dlibc

* fix std

* 1

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

* undate

* update

* update

* pipe与spawn修改

* update
GnoCiYeH 1 year ago
parent
commit
68e95534b2

+ 5 - 2
dlibc/src/unix/header/dirent/mod.rs

@@ -88,7 +88,7 @@ pub unsafe extern "C" fn readdir(dir: *mut DIR) -> *mut ::dirent {
     (*dir).index += (*ptr).d_reclen as usize;
     ptr
 }
-// #[no_mangle]
+#[no_mangle]
 pub extern "C" fn readdir_r(
     _dir: *mut DIR,
     _entry: *mut ::dirent,
@@ -114,7 +114,10 @@ pub unsafe extern "C" fn rewinddir(dir: *mut DIR) {
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn alphasort(first: *mut *const ::dirent, second: *mut *const ::dirent) -> ::c_int {
+pub unsafe extern "C" fn alphasort(
+    first: *mut *const ::dirent,
+    second: *mut *const ::dirent,
+) -> ::c_int {
     string::strcoll((**first).d_name.as_ptr(), (**second).d_name.as_ptr())
 }
 

+ 4 - 0
dlibc/src/unix/platform/dragonos/musl/lfs64.rs

@@ -88,11 +88,13 @@ pub unsafe extern "C" fn getrlimit64(resource: ::c_int, rlim: *mut ::rlimit64) -
 }
 
 #[inline]
+#[no_mangle]
 pub unsafe extern "C" fn lseek64(fd: ::c_int, offset: ::off64_t, whence: ::c_int) -> ::off64_t {
     ::lseek(fd, offset, whence)
 }
 
 #[inline]
+#[no_mangle]
 pub unsafe extern "C" fn lstat64(path: *const ::c_char, buf: *mut ::stat64) -> ::c_int {
     ::lstat(path, buf as *mut _)
 }
@@ -188,6 +190,7 @@ pub unsafe extern "C" fn pwritev64(
 }
 
 #[inline]
+#[no_mangle]
 pub unsafe extern "C" fn readdir64(dirp: *mut ::DIR) -> *mut ::dirent64 {
     ::readdir(dirp) as *mut _
 }
@@ -217,6 +220,7 @@ pub unsafe extern "C" fn setrlimit64(resource: ::c_int, rlim: *const ::rlimit64)
 }
 
 #[inline]
+#[no_mangle]
 pub unsafe extern "C" fn stat64(pathname: *const ::c_char, statbuf: *mut ::stat64) -> ::c_int {
     ::stat(pathname, statbuf as *mut _)
 }

+ 83 - 93
dlibc/src/unix/platform/dragonos/pal/relibc_adapter/pal.rs

@@ -1,6 +1,4 @@
 
-
-
 use crate::unix::platform::pal::{e};
 use crate::unix::c_str::CStr;
 use crate::unix::platform::pal::e;
@@ -32,18 +30,18 @@ pub extern "C" fn chdir(dir: *const ::c_char) -> ::c_int {
 }
 
 #[no_mangle]
-pub extern "C" fn chmod(_path: *const c_char, _mode: mode_t) -> ::c_int{
-	0
+pub extern "C" fn chmod(_path: *const c_char, _mode: mode_t) -> ::c_int {
+    0
 }
 
 #[no_mangle]
-pub extern "C" fn chown(_path: *const ::c_char, _uid: uid_t, _gid: gid_t) -> ::c_int{
-	0
+pub extern "C" fn chown(_path: *const ::c_char, _uid: uid_t, _gid: gid_t) -> ::c_int {
+    0
 }
 
 #[no_mangle]
-pub extern "C" fn clock_gettime(_clk_id: ::clockid_t, _tp: *mut ::timespec) -> ::c_int{
-	-ENOSYS
+pub extern "C" fn clock_gettime(_clk_id: ::clockid_t, _tp: *mut ::timespec) -> ::c_int {
+    -ENOSYS
 }
 
 #[no_mangle]
@@ -84,28 +82,28 @@ pub extern "C" fn exit(status: ::c_int) -> ! {
 }
 
 #[no_mangle]
-pub extern "C" fn fchdir(_dirfd: ::c_int) -> ::c_int{
-	unimplemented!()
+pub extern "C" fn fchdir(_dirfd: ::c_int) -> ::c_int {
+    unimplemented!()
 }
 
 #[no_mangle]
-pub extern "C" fn fchmod(_fd: ::c_int, _mode: mode_t) -> ::c_int{
-	0
+pub extern "C" fn fchmod(_fd: ::c_int, _mode: mode_t) -> ::c_int {
+    0
 }
 
 #[no_mangle]
-pub extern "C" fn fchown(_fd: ::c_int, _owner: ::uid_t, _group: ::gid_t) -> ::c_int{
-	0
+pub extern "C" fn fchown(_fd: ::c_int, _owner: ::uid_t, _group: ::gid_t) -> ::c_int {
+    0
 }
 
 #[no_mangle]
-pub extern "C" fn flock(_fd: ::c_int, _operation: ::c_int) -> ::c_int{
-	0
+pub extern "C" fn flock(_fd: ::c_int, _operation: ::c_int) -> ::c_int {
+    0
 }
 
 #[no_mangle]
-pub extern "C" fn fstatvfs(_fd: ::c_int, _buf: *mut statvfs) -> ::c_int{
-	unimplemented!()
+pub extern "C" fn fstatvfs(_fd: ::c_int, _buf: *mut statvfs) -> ::c_int {
+    unimplemented!()
 }
 
 #[no_mangle]
@@ -119,13 +117,13 @@ pub extern "C" fn fork() -> ::pid_t {
 }
 
 #[no_mangle]
-pub extern "C" fn fpath(_filedes: ::c_int, _name:*const ::c_char) -> c_long{
-	unimplemented!()
+pub extern "C" fn fpath(_filedes: ::c_int, _name: *const ::c_char) -> c_long {
+    unimplemented!()
 }
 
 #[no_mangle]
-pub extern "C" fn fsync(_fd: ::c_int) -> ::c_int{
-	0
+pub extern "C" fn fsync(_fd: ::c_int) -> ::c_int {
+    0
 }
 
 #[no_mangle]
@@ -134,54 +132,46 @@ pub extern "C" fn ftruncate(fd: ::c_int, length: off_t) -> ::c_int {
 }
 
 pub extern "C" fn futex(_addr: *mut ::c_int, _op: ::c_int, _val: ::c_int, _val2: usize) -> ::c_int {
-	// unsafe { syscall!(FUTEX, addr, op, val, val2, 0, 0) as ::c_int }
-	unimplemented!()
+    // unsafe { syscall!(FUTEX, addr, op, val, val2, 0, 0) as ::c_int }
+    unimplemented!()
 }
 
 #[no_mangle]
-pub extern "C" fn futimens(_fd: ::c_int, _times: *const ::timespec) -> ::c_int{
-	unimplemented!()
+pub extern "C" fn futimens(_fd: ::c_int, _times: *const ::timespec) -> ::c_int {
+    unimplemented!()
 }
 
 #[no_mangle]
 pub extern "C" fn utimensat(
-	_dirfd: ::c_int,
-	_path: *const ::c_char,
-	_times: *const ::timespec,
-	_flag: ::c_int,
-) -> ::c_int{
-	unimplemented!()
+    _dirfd: ::c_int,
+    _path: *const ::c_char,
+    _times: *const ::timespec,
+    _flag: ::c_int,
+) -> ::c_int {
+    unimplemented!()
 }
 
 //#[no_mangle]
-pub extern "C" fn getcwd(buf: *mut ::c_char, size: ::size_t) -> *mut ::c_char{
-	// if e(unsafe { syscall!(GETCWD, buf, size) }) == !0 {
-	//     ptr::null_mut()
-	// } else {
-	//     buf
-	// }
-	// 临时实现,设置所有的cwd为根目录
-	if size > 2 {
-		unsafe {
-			*buf = b'/' as ::c_char;
-			*buf.add(1) = b'\0' as ::c_char;
-		}
-	}
-
-	buf
-}
-
-#[no_mangle]
-pub extern "C" fn getdents(
-    _fd: ::c_int, 
-    _dirents: *mut dirent, 
-    _bytes: usize) -> ::c_int{
-        unimplemented!()
+pub extern "C" fn getcwd(buf: *mut ::c_char, size: ::size_t) -> *mut ::c_char {
+    // if e(unsafe { syscall!(GETCWD, buf, size) }) == !0 {
+    //     ptr::null_mut()
+    // } else {
+    //     buf
+    // }
+    // 临时实现,设置所有的cwd为根目录
+    if size > 2 {
+        unsafe {
+            *buf = b'/' as ::c_char;
+            *buf.add(1) = b'\0' as ::c_char;
+        }
+    }
+
+    buf
 }
 
 #[no_mangle]
 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 }
+    unsafe { syscall!(SYS_GET_DENTS, fd, dirents, bytes) as ::c_int }
 }
 
 #[no_mangle]
@@ -205,8 +195,8 @@ pub extern "C" fn getpagesize() -> usize {
 }
 
 #[no_mangle]
-pub extern "C" fn getpgid(_pid: ::pid_t) -> ::pid_t{
-	0
+pub extern "C" fn getpgid(_pid: ::pid_t) -> ::pid_t {
+    0
 }
 
 #[no_mangle]
@@ -220,13 +210,13 @@ pub extern "C" fn getppid() -> ::pid_t {
 }
 
 #[no_mangle]
-pub extern "C" fn getrlimit(_resource: ::c_int, _rlim: *mut ::rlimit) -> ::c_int{
-	unimplemented!()
+pub extern "C" fn getrlimit(_resource: ::c_int, _rlim: *mut ::rlimit) -> ::c_int {
+    unimplemented!()
 }
 
 #[no_mangle]
-pub extern "C" fn getsid(_pid: ::pid_t) -> ::pid_t{
-	0
+pub extern "C" fn getsid(_pid: ::pid_t) -> ::pid_t {
+    0
 }
 
 #[no_mangle]
@@ -245,13 +235,13 @@ pub extern "C" fn getuid() -> uid_t {
 }
 
 #[no_mangle]
-pub extern "C" fn lchown(_path: *const ::c_char, _uid: uid_t, _gid: gid_t) -> ::c_int{
-	0
+pub extern "C" fn lchown(_path: *const ::c_char, _uid: uid_t, _gid: gid_t) -> ::c_int {
+    0
 }
 
 #[no_mangle]
-pub extern "C" fn link(_src: *const ::c_char, _dst: *const ::c_char) -> ::c_int{
-	unimplemented!()
+pub extern "C" fn link(_src: *const ::c_char, _dst: *const ::c_char) -> ::c_int {
+    unimplemented!()
 }
 
 #[no_mangle]
@@ -265,18 +255,18 @@ pub extern "C" fn mkdir(path: *const ::c_char, mode: mode_t) -> ::c_int {
 }
 
 #[no_mangle]
-pub extern "C" fn mkfifo(_path: *const ::c_char, _mode: mode_t) -> ::c_int{
-	unimplemented!()
+pub extern "C" fn mkfifo(_path: *const ::c_char, _mode: mode_t) -> ::c_int {
+    unimplemented!()
 }
 
 #[no_mangle]
-pub extern "C" fn mlock(_addr: *const ::c_void, _len: ::size_t) -> ::c_int{
-	unimplemented!()
+pub extern "C" fn mlock(_addr: *const ::c_void, _len: ::size_t) -> ::c_int {
+    unimplemented!()
 }
 
 #[no_mangle]
-pub extern "C" fn mlockall(_flags: ::c_int) -> ::c_int{
-	unimplemented!()
+pub extern "C" fn mlockall(_flags: ::c_int) -> ::c_int {
+    unimplemented!()
 }
 
 #[no_mangle]
@@ -297,13 +287,13 @@ pub extern "C" fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) ->
 }
 
 #[no_mangle]
-pub extern "C" fn msync(_addr: *mut ::c_void, _len: ::size_t, _flags: ::c_int) -> ::c_int{
-	unimplemented!()
+pub extern "C" fn msync(_addr: *mut ::c_void, _len: ::size_t, _flags: ::c_int) -> ::c_int {
+    unimplemented!()
 }
 
 #[no_mangle]
-pub extern "C" fn munlock(_addr: *const ::c_void, _len: ::size_t) -> ::c_int{
-	unimplemented!()
+pub extern "C" fn munlock(_addr: *const ::c_void, _len: ::size_t) -> ::c_int {
+    unimplemented!()
 }
 
 #[no_mangle]
@@ -336,8 +326,8 @@ pub extern "C" fn pipe2(fds: *mut ::c_int, flags: ::c_int) -> ::c_int {
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn pte_clone(_stack: *mut usize) -> ::pid_t{
-    unimplemented!()    
+pub unsafe extern "C" fn pte_clone(_stack: *mut usize) -> ::pid_t {
+    unimplemented!()
 }
 
 #[no_mangle]
@@ -345,13 +335,13 @@ pub extern "C" fn read(fd: ::c_int, buf: *mut ::c_void, count: ::size_t) -> ::ss
     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{
+pub extern "C" fn readlink(_path: *const c_char, _buf: *mut c_char, _bufsz: ::size_t) -> ::ssize_t {
     unimplemented!()
 }
 
 #[no_mangle]
-pub extern "C" fn rename(_oldname: *const ::c_char, _newname: *const ::c_char) -> ::c_int{
-	unimplemented!()
+pub extern "C" fn rename(_oldname: *const ::c_char, _newname: *const ::c_char) -> ::c_int {
+    unimplemented!()
 }
 
 #[no_mangle]
@@ -365,33 +355,33 @@ pub extern "C" fn sched_yield() -> ::c_int {
 }
 
 #[no_mangle]
-pub extern "C" fn setpgid(_pid: ::pid_t, _pgid: ::pid_t) -> ::c_int{
-	unimplemented!()
+pub extern "C" fn setpgid(_pid: ::pid_t, _pgid: ::pid_t) -> ::c_int {
+    unimplemented!()
 }
 
 #[no_mangle]
-pub extern "C" fn setregid(_rgid: gid_t, _egid: gid_t) -> ::c_int{
-	unimplemented!()
+pub extern "C" fn setregid(_rgid: gid_t, _egid: gid_t) -> ::c_int {
+    unimplemented!()
 }
 
 #[no_mangle]
-pub extern "C" fn setreuid(_ruid: uid_t, _euid: uid_t) -> ::c_int{
-	unimplemented!()
+pub extern "C" fn setreuid(_ruid: uid_t, _euid: uid_t) -> ::c_int {
+    unimplemented!()
 }
 
 #[no_mangle]
-pub extern "C" fn symlink(_path1: *const ::c_char, _path2: *const ::c_char) -> ::c_int{
-	unimplemented!()
+pub extern "C" fn symlink(_path1: *const ::c_char, _path2: *const ::c_char) -> ::c_int {
+    unimplemented!()
 }
 
 #[no_mangle]
-pub extern "C" fn umask(_mask: mode_t) -> mode_t{
-	unimplemented!()
+pub extern "C" fn umask(_mask: mode_t) -> mode_t {
+    unimplemented!()
 }
 
 #[no_mangle]
-pub extern "C" fn uname(_buf: *mut ::utsname) -> ::c_int{
-	unimplemented!()
+pub extern "C" fn uname(_buf: *mut ::utsname) -> ::c_int {
+    unimplemented!()
 }
 
 #[no_mangle]

+ 1 - 1
src/std/os/linux/fs.rs

@@ -312,7 +312,7 @@ pub trait MetadataExt {
 impl MetadataExt for Metadata {
     #[allow(deprecated)]
     fn as_raw_stat(&self) -> &raw::stat {
-        unsafe { &*(self.as_inner().as_inner() as *const dlibc::stat as *const raw::stat) }
+        unsafe { &*(self.as_inner().as_inner() as *const dlibc::stat64 as *const raw::stat) }
     }
     fn st_dev(&self) -> u64 {
         self.as_inner().as_inner().st_dev as u64

+ 6 - 3
src/std/sys/unix/fs.rs

@@ -58,10 +58,9 @@ use dlibc::fstatat64;
     target_os = "illumos",
     target_os = "nto",
     target_os = "vita",
-    target_os = "dragonos",
 ))]
 use dlibc::readdir as readdir64;
-#[cfg(target_os = "linux")]
+#[cfg(any(target_os = "linux",target_os = "dragonos",))]
 use dlibc::readdir64;
 #[cfg(any(target_os = "emscripten", target_os = "l4re"))]
 use dlibc::readdir64_r;
@@ -88,7 +87,8 @@ use dlibc::{
     target_os = "linux",
     target_os = "emscripten",
     target_os = "l4re",
-    target_os = "android"
+    target_os = "android",
+    target_os = "dragonos"
 )))]
 use dlibc::{
     dirent as dirent64, fstat as fstat64, ftruncate as ftruncate64, lseek as lseek64,
@@ -97,6 +97,9 @@ use dlibc::{
 #[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "l4re"))]
 use dlibc::{dirent64, fstat64, ftruncate64, lseek64, lstat64, off64_t, open64, stat64};
 
+#[cfg(any(target_os = "dragonos"))]
+use dlibc::{dirent64, fstat64, ftruncate64, lseek64, lstat64, off64_t, open as open64, stat64};
+
 pub use crate::std::sys_common::fs::try_exists;
 
 pub struct File(FileDesc);

+ 2 - 5
src/std/sys/unix/process/process_unix.rs

@@ -139,9 +139,6 @@ impl Command {
                 unsafe { dlibc::_exit(1) }
             }
         } else {
-            use crate::print;
-            use crate::println;
-
             drop(env_lock);
             drop(output);
 
@@ -160,8 +157,8 @@ impl Command {
             let mut p = unsafe { Process::new(pid, pidfd) };
             let mut bytes = [0; 8];
 
-            //test
-            //return Ok((p,ours));
+            //TODO: 这里直接返回,没有从管道读取子进程状态,后续需更改
+            return Ok((p,ours));
             // loop to handle EINTR
             loop {
                 match input.read(&mut bytes) {

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

@@ -2,7 +2,6 @@
 
 use crate::std::sync::{Mutex, PoisonError};
 
-
 /// Max number of frames to print.
 const MAX_NB_FRAMES: usize = 100;