Jelajahi Sumber

配置网络相关的系统调用 & 修复由于DragonOS不支持TLS(thread local storage)导致errno变量无法正常工作的问题 (#8)

1.配置网络相关的系统调用
2.修复由于DragonOS不支持TLS(thread local storage)导致errno变量无法正常工作的问题.
login 2 tahun lalu
induk
melakukan
5ca4d0eae1
5 mengubah file dengan 67 tambahan dan 57 penghapusan
  1. 4 4
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 9 0
      src/header/errno/mod.rs
  4. 45 52
      src/platform/dragonos/socket.rs
  5. 8 0
      src/platform/mod.rs

+ 4 - 4
Cargo.lock

@@ -109,9 +109,9 @@ name = "crtn"
 version = "0.1.0"
 
 [[package]]
-name = "dsc"
-version = "0.1.0"
-source = "git+https://github.com/DragonOS-Community/dsc.git?rev=0f61350#0f61350272d93e1cbda1f5f565bdaf81cc942a9f"
+name = "dragonos-dsc"
+version = "0.0.1"
+source = "git+https://github.com/DragonOS-Community/dsc.git?rev=194f741#194f741bc36411c2ce1579b17ba010951312730d"
 
 [[package]]
 name = "errno"
@@ -411,7 +411,7 @@ dependencies = [
  "cbitset",
  "cc",
  "core_io",
- "dsc",
+ "dragonos-dsc",
  "goblin",
  "lazy_static",
  "memchr",

+ 1 - 1
Cargo.toml

@@ -43,7 +43,7 @@ sc = "0.2.3"
 [target.'cfg(target_os = "dragonos")'.dependencies]
 # Development
 #dsc = { path = "本地存放dsc的代码的路径" }
-dsc = { git = "https://github.com/DragonOS-Community/dsc.git", rev = "0f61350" }
+dragonos-dsc = { git = "https://github.com/DragonOS-Community/dsc.git", rev = "194f741" }
 
 [target.'cfg(target_os = "redox")'.dependencies]
 redox_syscall = "0.3"

+ 9 - 0
src/header/errno/mod.rs

@@ -63,7 +63,10 @@ pub const ENOLCK: c_int = 37; /* No record locks available */
 pub const ENOSYS: c_int = 38; /* Function not implemented */
 pub const ENOTEMPTY: c_int = 39; /* Directory not empty */
 pub const ELOOP: c_int = 40; /* Too many symbolic links encountered */
+#[cfg(not(target_os = "dragonos"))]
 pub const EWOULDBLOCK: c_int = 41; /* Operation would block */
+#[cfg(target_os = "dragonos")]
+pub const EWOULDBLOCK: c_int = EAGAIN; /* Operation would block */
 pub const ENOMSG: c_int = 42; /* No message of desired type */
 pub const EIDRM: c_int = 43; /* Identifier removed */
 pub const ECHRNG: c_int = 44; /* Channel number out of range */
@@ -167,7 +170,10 @@ pub static STR_ERROR: [&'static str; 132] = [
     "Exec format error",
     "Bad file number",
     "No child processes",
+    #[cfg(not(target_os = "dragonos"))]
     "Try again",
+    #[cfg(target_os = "dragonos")]
+    "Try again or operation would block",
     "Out of memory",
     "Permission denied",
     "Bad address",
@@ -197,6 +203,7 @@ pub static STR_ERROR: [&'static str; 132] = [
     "Function not implemented",
     "Directory not empty",
     "Too many symbolic links encountered",
+    #[cfg(not(target_os = "dragonos"))]
     "Operation would block",
     "No message of desired type",
     "Identifier removed",
@@ -288,4 +295,6 @@ pub static STR_ERROR: [&'static str; 132] = [
     "Key was rejected by service",
     "Owner died",
     "State not recoverable",
+    #[cfg(target_os = "dragonos")]
+    "Unknown"
 ];

+ 45 - 52
src/platform/dragonos/socket.rs

@@ -7,18 +7,20 @@ use crate::header::sys_socket::{sockaddr, socklen_t};
 
 impl PalSocket for Sys {
     unsafe fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int {
-        // e(syscall!(ACCEPT, socket, address, address_len)) as c_int
-        unimplemented!()
+        e(syscall!(
+            SYS_ACCEPT,
+            socket as usize,
+            address as usize,
+            address_len as usize
+        )) as c_int
     }
 
     unsafe fn bind(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int {
-        // e(syscall!(BIND, socket, address, address_len)) as c_int
-        unimplemented!()
+        e(syscall!(SYS_BIND, socket, address, address_len)) as c_int
     }
 
     unsafe fn connect(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int {
-        // e(syscall!(CONNECT, socket, address, address_len)) as c_int
-        unimplemented!()
+        e(syscall!(SYS_CONNECT, socket, address, address_len)) as c_int
     }
 
     unsafe fn getpeername(
@@ -26,8 +28,7 @@ impl PalSocket for Sys {
         address: *mut sockaddr,
         address_len: *mut socklen_t,
     ) -> c_int {
-        // e(syscall!(GETPEERNAME, socket, address, address_len)) as c_int
-        unimplemented!()
+        e(syscall!(SYS_GETPEERNAME, socket, address, address_len)) as c_int
     }
 
     unsafe fn getsockname(
@@ -35,8 +36,7 @@ impl PalSocket for Sys {
         address: *mut sockaddr,
         address_len: *mut socklen_t,
     ) -> c_int {
-        // e(syscall!(GETSOCKNAME, socket, address, address_len)) as c_int
-        unimplemented!()
+        e(syscall!(SYS_GETSOCKNAME, socket, address, address_len)) as c_int
     }
 
     fn getsockopt(
@@ -46,22 +46,20 @@ impl PalSocket for Sys {
         option_value: *mut c_void,
         option_len: *mut socklen_t,
     ) -> c_int {
-        unimplemented!()
-        // e(unsafe {
-        //     syscall!(
-        //         GETSOCKOPT,
-        //         socket,
-        //         level,
-        //         option_name,
-        //         option_value,
-        //         option_len
-        //     )
-        // }) as c_int
+        e(unsafe {
+            syscall!(
+                SYS_GETSOCKOPT,
+                socket,
+                level,
+                option_name,
+                option_value,
+                option_len
+            )
+        }) as c_int
     }
 
     fn listen(socket: c_int, backlog: c_int) -> c_int {
-        // e(unsafe { syscall!(LISTEN, socket, backlog) }) as c_int
-        unimplemented!()
+        e(unsafe { syscall!(SYS_LISTEN, socket, backlog) }) as c_int
     }
 
     unsafe fn recvfrom(
@@ -72,16 +70,15 @@ impl PalSocket for Sys {
         address: *mut sockaddr,
         address_len: *mut socklen_t,
     ) -> ssize_t {
-        // e(syscall!(
-        //     RECVFROM,
-        //     socket,
-        //     buf,
-        //     len,
-        //     flags,
-        //     address,
-        //     address_len
-        // )) as ssize_t
-        unimplemented!()
+        e(syscall!(
+            SYS_RECVFROM,
+            socket,
+            buf,
+            len,
+            flags,
+            address,
+            address_len
+        )) as ssize_t
     }
 
     unsafe fn sendto(
@@ -92,10 +89,9 @@ impl PalSocket for Sys {
         dest_addr: *const sockaddr,
         dest_len: socklen_t,
     ) -> ssize_t {
-        // e(syscall!(
-        //     SENDTO, socket, buf, len, flags, dest_addr, dest_len
-        // )) as ssize_t
-        unimplemented!()
+        e(syscall!(
+            SYS_SENDTO, socket, buf, len, flags, dest_addr, dest_len
+        )) as ssize_t
     }
 
     fn setsockopt(
@@ -105,27 +101,24 @@ impl PalSocket for Sys {
         option_value: *const c_void,
         option_len: socklen_t,
     ) -> c_int {
-        // e(unsafe {
-        //     syscall!(
-        //         SETSOCKOPT,
-        //         socket,
-        //         level,
-        //         option_name,
-        //         option_value,
-        //         option_len
-        //     )
-        // }) as c_int
-        unimplemented!()
+        e(unsafe {
+            syscall!(
+                SYS_SETSOCKOPT,
+                socket,
+                level,
+                option_name,
+                option_value,
+                option_len
+            )
+        }) as c_int
     }
 
     fn shutdown(socket: c_int, how: c_int) -> c_int {
-        // e(unsafe { syscall!(SHUTDOWN, socket, how) }) as c_int
-        unimplemented!()
+        e(unsafe { syscall!(SYS_SHUTDOWN, socket, how) }) as c_int
     }
 
     unsafe fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int {
-        // e(syscall!(SOCKET, domain, kind, protocol)) as c_int
-        unimplemented!()
+        e(syscall!(SYS_SOCKET, domain, kind, protocol)) as c_int
     }
 
     fn socketpair(domain: c_int, kind: c_int, protocol: c_int, sv: &mut [c_int; 2]) -> c_int {

+ 8 - 0
src/platform/mod.rs

@@ -54,11 +54,19 @@ pub use redox_exec::auxv_defs;
 use self::types::*;
 pub mod types;
 
+#[cfg(not(target_os = "dragonos"))]
 #[thread_local]
 #[allow(non_upper_case_globals)]
 #[no_mangle]
 pub static mut errno: c_int = 0;
 
+/// DragonOS doesn't have thread_local, so we use a global variable instead.
+/// TODO: This is a hack, and should be fixed.
+#[cfg(target_os = "dragonos")]
+#[allow(non_upper_case_globals)]
+#[no_mangle]
+pub static mut errno: c_int = 0;
+
 #[allow(non_upper_case_globals)]
 pub static mut argv: *mut *mut c_char = ptr::null_mut();
 #[allow(non_upper_case_globals)]