Преглед изворни кода

Fix a few GDB compilation issues

jD91mZM2 пре 5 година
родитељ
комит
aeab6a986d

+ 1 - 0
include/bits/errno.h

@@ -8,6 +8,7 @@ extern "C" {
 #define ENOTSUP EOPNOTSUPP
 
 #define errno (*__errno_location())
+#define program_invocation_name (__program_invocation_name())
 
 #ifdef __cplusplus
 } // extern "C"

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

@@ -13,6 +13,11 @@ pub unsafe extern "C" fn __errno_location() -> *mut c_int {
     &mut platform::errno
 }
 
+#[no_mangle]
+pub unsafe extern "C" fn __program_invocation_name() -> *mut c_char {
+    platform::inner_argv[0]
+}
+
 pub const EPERM: c_int = 1; /* Operation not permitted */
 pub const ENOENT: c_int = 2; /* No such file or directory */
 pub const ESRCH: c_int = 3; /* No such process */

+ 30 - 2
src/header/sys_ioctl/redox.rs

@@ -2,14 +2,19 @@ use core::{mem, slice};
 use syscall;
 
 use crate::{
-    header::{errno, termios},
+    header::{errno, fcntl, termios},
     platform::{self, e, types::*},
 };
 
 use super::winsize;
 
+pub const FIONBIO: c_ulong = 0x5421;
+
 pub const TCGETS: c_ulong = 0x5401;
 pub const TCSETS: c_ulong = 0x5402;
+pub const TCSBRK: c_ulong = 0x5409;
+
+pub const TCXONC: c_ulong = 0x540A;
 
 pub const TCFLSH: c_ulong = 0x540B;
 
@@ -50,6 +55,22 @@ fn dup_write<T>(fd: c_int, name: &str, t: &T) -> syscall::Result<usize> {
 #[no_mangle]
 pub unsafe extern "C" fn ioctl(fd: c_int, request: c_ulong, out: *mut c_void) -> c_int {
     match request {
+        FIONBIO => {
+            let mut flags = fcntl::sys_fcntl(fd, fcntl::F_GETFL, 0);
+            if flags < 0 {
+                return -1;
+            }
+            flags = if *(out as *mut c_int) == 0 {
+                flags & !fcntl::O_NONBLOCK
+            } else {
+                flags | fcntl::O_NONBLOCK
+            };
+            if fcntl::sys_fcntl(fd, fcntl::F_SETFL, flags) < 0 {
+                -1
+            } else {
+                0
+            }
+        }
         TCGETS => {
             let termios = &mut *(out as *mut termios::termios);
             if e(dup_read(fd, "termios", termios)) == !0 {
@@ -58,7 +79,6 @@ pub unsafe extern "C" fn ioctl(fd: c_int, request: c_ulong, out: *mut c_void) ->
                 0
             }
         }
-
         TCSETS => {
             let termios = &*(out as *const termios::termios);
             if e(dup_write(fd, "termios", termios)) == !0 {
@@ -107,6 +127,14 @@ pub unsafe extern "C" fn ioctl(fd: c_int, request: c_ulong, out: *mut c_void) ->
                 0
             }
         }
+        TCSBRK => {
+            // TODO
+            0
+        }
+        TCXONC => {
+            // TODO
+            0
+        }
         _ => {
             platform::errno = errno::EINVAL;
             -1

+ 4 - 0
src/header/sys_resource/cbindgen.toml

@@ -6,6 +6,10 @@ style = "Tag"
 no_includes = true
 cpp_compat = true
 
+[defines]
+"target_os=linux" = "__linux__"
+"target_os=redox" = "__redox__"
+
 [enum]
 prefix_with_name = true
 

+ 4 - 0
src/header/sys_resource/linux.rs

@@ -0,0 +1,4 @@
+#[no_mangle]
+pub unsafe extern "C" fn getrlimit(resource: c_int, rlp: *mut rlimit) -> c_int {
+    Sys::getrlimit(resource, rlp)
+}

+ 33 - 6
src/header/sys_resource/mod.rs

@@ -12,6 +12,37 @@ use platform::{Pal, Sys};
 // const RUSAGE_BOTH: c_int = -2;
 // const RUSAGE_THREAD: c_int = 1;
 
+pub const RLIM_INFINITY: u64 = 0xFFFF_FFFF_FFFF_FFFF;
+pub const RLIM_SAVED_CUR: u64 = RLIM_INFINITY;
+pub const RLIM_SAVED_MAX: u64 = RLIM_INFINITY;
+
+pub const RLIMIT_CPU: u64 = 0;
+pub const RLIMIT_FSIZE: u64 = 1;
+pub const RLIMIT_DATA: u64 = 2;
+pub const RLIMIT_STACK: u64 = 3;
+pub const RLIMIT_CORE: u64 = 4;
+pub const RLIMIT_RSS: u64 = 5;
+pub const RLIMIT_NPROC: u64 = 6;
+pub const RLIMIT_NOFILE: u64 = 7;
+pub const RLIMIT_MEMLOCK: u64 = 8;
+pub const RLIMIT_AS: u64 = 9;
+pub const RLIMIT_LOCKS: u64 = 10;
+pub const RLIMIT_SIGPENDING: u64 = 11;
+pub const RLIMIT_MSGQUEUE: u64 = 12;
+pub const RLIMIT_NICE: u64 = 13;
+pub const RLIMIT_RTPRIO: u64 = 14;
+pub const RLIMIT_NLIMITS: u64 = 15;
+
+#[cfg(target_os = "linux")]
+mod linux;
+#[cfg(target_os = "redox")]
+mod redox;
+
+#[cfg(target_os = "linux")]
+pub use linux::*;
+#[cfg(target_os = "redox")]
+pub use redox::*;
+
 type rlim_t = u64;
 
 #[repr(C)]
@@ -46,13 +77,9 @@ pub unsafe extern "C" fn getpriority(which: c_int, who: id_t) -> c_int {
 }
 
 // #[no_mangle]
-pub unsafe extern "C" fn getrlimit(resource: c_int, rlp: *mut rlimit) -> c_int {
-    unimplemented!();
-}
-
-#[no_mangle]
 pub unsafe extern "C" fn getrusage(who: c_int, r_usage: *mut rusage) -> c_int {
-    Sys::getrusage(who, r_usage)
+    // Sys::getrusage(who, r_usage)
+    unimplemented!();
 }
 
 // #[no_mangle]

+ 5 - 0
src/header/sys_resource/redox.rs

@@ -0,0 +1,5 @@
+#[no_mangle]
+pub unsafe extern "C" fn getrlimit(resource: c_int, rlp: *mut rlimit) -> c_int {
+    // TODO
+    RLIM_INFINITY
+}

+ 1 - 1
src/header/sys_socket/constants.rs

@@ -13,7 +13,7 @@ pub const SOL_SOCKET: c_int = 1;
 pub const SO_DEBUG: c_int = 1;
 pub const SO_REUSEADDR: c_int = 2;
 pub const SO_TYPE: c_int = 3;
-//pub const SO_ERROR: c_int = 4;
+pub const SO_ERROR: c_int = 4;
 pub const SO_DONTROUTE: c_int = 5;
 pub const SO_BROADCAST: c_int = 6;
 pub const SO_SNDBUF: c_int = 7;

+ 19 - 0
src/header/termios/mod.rs

@@ -196,3 +196,22 @@ pub unsafe extern "C" fn cfsetospeed(termios_p: *mut termios, speed: speed_t) ->
 pub unsafe extern "C" fn tcflush(fd: c_int, queue: c_int) -> c_int {
     sys_ioctl::ioctl(fd, sys_ioctl::TCFLSH, queue as *mut c_void)
 }
+
+#[no_mangle]
+pub unsafe extern "C" fn tcdrain(fd: c_int) -> c_int {
+    sys_ioctl::ioctl(fd, sys_ioctl::TCSBRK, 1 as *mut _)
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn tcsendbreak(fd: c_int, _dur: c_int) -> c_int {
+    // non-zero duration is ignored by musl due to it being
+    // implementation-defined. we do the same.
+    sys_ioctl::ioctl(fd, sys_ioctl::TCSBRK, 0 as *mut _)
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn tcflow(fd: c_int, action: c_int) -> c_int {
+    // non-zero duration is ignored by musl due to it being
+    // implementation-defined. we do the same.
+    sys_ioctl::ioctl(fd, sys_ioctl::TCXONC, action as *mut _)
+}