소스 검색

Merged master with branch

Tom Almeida 7 년 전
부모
커밋
d8139238e7
9개의 변경된 파일44개의 추가작업 그리고 9개의 파일을 삭제
  1. 1 0
      src/lib.rs
  2. 4 0
      src/platform/src/linux/mod.rs
  3. 11 0
      src/platform/src/redox/mod.rs
  4. 2 2
      src/resource/cbindgen.toml
  5. 5 5
      src/string/src/lib.rs
  6. 2 2
      src/wait/src/lib.rs
  7. 1 0
      tests/.gitignore
  8. 1 0
      tests/Makefile
  9. 17 0
      tests/waitpid.c

+ 1 - 0
src/lib.rs

@@ -20,6 +20,7 @@ extern crate string;
 extern crate sys_time;
 extern crate time;
 extern crate unistd;
+extern crate wait;
 extern crate wctype;
 
 #[lang = "eh_personality"]

+ 4 - 0
src/platform/src/linux/mod.rs

@@ -163,6 +163,10 @@ pub fn unlink(path: *const c_char) -> c_int {
     e(unsafe { syscall!(UNLINKAT, AT_FDCWD, path, 0) }) as c_int
 }
 
+pub fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t {
+    e(unsafe { syscall!(WAIT4, pid, stat_loc, options, 0) }) as pid_t
+}
+
 pub fn write(fildes: c_int, buf: &[u8]) -> ssize_t {
     e(unsafe { syscall!(WRITE, fildes, buf.as_ptr(), buf.len()) }) as ssize_t
 }

+ 11 - 0
src/platform/src/redox/mod.rs

@@ -210,6 +210,17 @@ pub fn unlink(path: *const c_char) -> c_int {
     e(syscall::unlink(path)) as c_int
 }
 
+pub fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t {
+    unsafe {
+        let mut temp: usize = 0;
+        let res = e(syscall::waitpid(pid as usize, &mut temp, options as usize));
+        if !stat_loc.is_null() {
+            *stat_loc = temp as c_int;
+        }
+        res
+    }
+}
+
 pub fn write(fd: c_int, buf: &[u8]) -> ssize_t {
     e(syscall::write(fd as usize, buf)) as ssize_t
 }

+ 2 - 2
src/resource/cbindgen.toml

@@ -1,7 +1,7 @@
-sys_includes = ["sys/types.h", "sys/time.h"]
+sys_includes = ["sys/types.h", "stdint.h", "sys/time.h"]
 include_guard = "_SYS_RESOURCE_H"
 language = "C"
-style = "Tag"
+style = "Both"
 
 [enum]
 prefix_with_name = true

+ 5 - 5
src/string/src/lib.rs

@@ -117,7 +117,7 @@ pub unsafe extern "C" fn strcpy(s1: *mut c_char, s2: *const c_char) -> *mut c_ch
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn strcspn(s1: *const c_char, s2: *const c_char) -> c_ulong {
+pub unsafe extern "C" fn strcspn(s1: *const c_char, s2: *const c_char) -> size_t {
     use core::mem;
 
     let s1 = s1 as *const u8;
@@ -143,7 +143,7 @@ pub unsafe extern "C" fn strcspn(s1: *const c_char, s2: *const c_char) -> c_ulon
         }
         i += 1;
     }
-    i as u64
+    i as size_t
 }
 
 #[no_mangle]
@@ -274,7 +274,7 @@ pub unsafe extern "C" fn strrchr(s: *const c_char, c: c_int) -> *mut c_char {
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn strspn(s1: *const c_char, s2: *const c_char) -> c_ulong {
+pub unsafe extern "C" fn strspn(s1: *const c_char, s2: *const c_char) -> size_t {
     use core::mem;
 
     let s1 = s1 as *const u8;
@@ -300,7 +300,7 @@ pub unsafe extern "C" fn strspn(s1: *const c_char, s2: *const c_char) -> c_ulong
         }
         i += 1;
     }
-    i as u64
+    i as size_t
 }
 
 #[no_mangle]
@@ -337,7 +337,7 @@ pub extern "C" fn strtok_r(
 }
 
 #[no_mangle]
-pub extern "C" fn strxfrm(s1: *mut c_char, s2: *const c_char, n: usize) -> c_ulong {
+pub extern "C" fn strxfrm(s1: *mut c_char, s2: *const c_char, n: usize) -> size_t {
     unimplemented!();
 }
 

+ 2 - 2
src/wait/src/lib.rs

@@ -11,7 +11,7 @@ use resource::rusage;
 
 #[no_mangle]
 pub unsafe extern "C" fn wait(stat_loc: *mut c_int) -> pid_t {
-    unimplemented!();
+    waitpid(!0, stat_loc, 0)
 }
 
 #[no_mangle]
@@ -39,5 +39,5 @@ pub unsafe extern "C" fn wait3(
 
 #[no_mangle]
 pub unsafe extern "C" fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t {
-    unimplemented!();
+    platform::waitpid(pid, stat_loc, options)
 }

+ 1 - 0
tests/.gitignore

@@ -37,5 +37,6 @@
 /string/strrchr
 /string/strspn
 /unlink
+/waitpid
 /write
 

+ 1 - 0
tests/Makefile

@@ -35,6 +35,7 @@ EXPECT_BINS=\
 	string/strstr \
 	string/strpbrk \
 	unlink \
+	waitpid \
 	write
 
 # Binaries that may generate varied output

+ 17 - 0
tests/waitpid.c

@@ -0,0 +1,17 @@
+#include <sys/wait.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+int main(int argc, char** argv) {
+    pid_t pid = fork();
+    if (pid == 0) {
+        // child
+        sleep(1);
+        exit(0);
+    } else {
+        // parent
+        int stat_loc;
+        waitpid(pid, &stat_loc, 0);
+    }
+    return 0;
+}