2
0
Эх сурвалжийг харах

Merge branch 'master' into 'master'

Workaround compilation errors

See merge request redox-os/relibc!149
jD91mZM2 6 жил өмнө
parent
commit
0567f699a2

+ 7 - 0
include/bits/unistd.h

@@ -0,0 +1,7 @@
+#ifndef _BITS_UNISTD_H
+#define _BITS_UNISTD_H
+
+int execl(const char *path, const char* argv0, ...);
+int execle(const char *path, const char* argv0, ...);
+
+#endif

+ 6 - 2
include/bits/exec.h → src/c/unistd.c

@@ -1,5 +1,7 @@
-#ifndef _BITS_EXEC_H
-#define _BITS_EXEC_H
+#include <stdarg.h>
+#include <stddef.h>
+
+int execv(const char *path, char *const *argv);
 
 int execl(const char *path, const char* argv0, ...)
 {
@@ -22,6 +24,8 @@ int execl(const char *path, const char* argv0, ...)
 	}
 }
 
+int execve(const char *path, char *const *argv, char *const *envp);
+
 int execle(const char *path, const char* argv0, ...)
 {
 	int argc;

+ 0 - 3
src/platform/Cargo.toml

@@ -8,6 +8,3 @@ sc = "0.2"
 
 [target.'cfg(target_os = "redox")'.dependencies]
 redox_syscall = "0.1"
-
-[dependencies]
-ralloc = { path = "../../ralloc" }

+ 0 - 7
src/platform/src/lib.rs

@@ -2,8 +2,6 @@
 
 #![no_std]
 #![allow(non_camel_case_types)]
-#![feature(alloc)]
-#![feature(global_allocator)]
 //TODO #![feature(thread_local)]
 
 #[cfg(all(not(feature = "no_std"), target_os = "linux"))]
@@ -24,17 +22,12 @@ mod sys;
 #[path = "redox/mod.rs"]
 mod sys;
 
-extern crate alloc;
-extern crate ralloc;
-
 pub mod types;
 
 use core::fmt;
 
 use types::*;
 
-#[global_allocator]
-static ALLOCATOR: ralloc::Allocator = ralloc::Allocator;
 //TODO #[thread_local]
 #[allow(non_upper_case_globals)]
 #[no_mangle]

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

@@ -1,7 +1,6 @@
 use core::ptr;
 use core::slice;
 use core::mem;
-use alloc::Vec;
 use syscall;
 use syscall::flag::*;
 use syscall::data::TimeSpec as redox_timespec;
@@ -68,58 +67,6 @@ pub fn dup2(fd1: c_int, fd2: c_int) -> c_int {
     e(syscall::dup2(fd1 as usize, fd2 as usize, &[])) as c_int
 }
 
-pub fn execve(path: *const c_char, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int {
-    unsafe {
-        let mut env = envp;
-        while !(*env).is_null() {
-            let slice = c_str(*env);
-            // Should always contain a =, but worth checking
-            if let Some(sep) = slice.iter().position(|&c| c == b'=') {
-                // If the environment variable has no name, do not attempt
-                // to add it to the env.
-                if sep > 0 {
-                    let mut path = b"env:".to_vec();
-                    path.extend_from_slice(&slice[..sep]);
-                    match syscall::open(&path, O_WRONLY | O_CREAT) {
-                        Ok(fd) => {
-                            // If the environment variable has no value, there
-                            // is no need to write anything to the env scheme.
-                            if sep + 1 < slice.len() {
-                                let n = match syscall::write(fd, &slice[sep + 1..]) {
-                                    Ok(n) => n,
-                                    err => {
-                                        return e(err) as c_int;
-                                    }
-                                };
-                            }
-                            // Cleanup after adding the variable.
-                            match syscall::close(fd) {
-                                Ok(_) => (),
-                                err => {
-                                    return e(err) as c_int;
-                                }
-                            }
-                        }
-                        err => {
-                            return e(err) as c_int;
-                        }
-                    }
-                }
-            }
-            env = env.offset(1);
-        }
-
-        let mut args: Vec<[usize; 2]> = Vec::new();
-        let mut arg = argv;
-        while !(*arg).is_null() {
-            args.push([*arg as usize, c_str(*arg).len()]);
-            arg = arg.offset(1);
-        }
-
-        e(syscall::execve(c_str(path), &args)) as c_int
-    }
-}
-
 pub fn exit(status: c_int) -> ! {
     let _ = syscall::exit(status as usize);
     loop {}

+ 2 - 2
src/unistd/cbindgen.toml

@@ -1,6 +1,6 @@
-sys_includes = ["stddef.h", "stdint.h", "sys/types.h", "stdarg.h", "bits/exec.h"]
+sys_includes = ["stddef.h", "stdint.h", "sys/types.h"]
 include_guard = "_UNISTD_H"
-trailer = "#include <bits/fcntl.h>"
+trailer = "#include <bits/fcntl.h>\n#include <bits/unistd.h>"
 language = "C"
 
 [enum]

+ 64 - 5
src/unistd/src/lib.rs

@@ -33,7 +33,7 @@ pub const STDOUT_FILENO: c_int = 1;
 pub const STDERR_FILENO: c_int = 2;
 
 #[no_mangle]
-pub static mut environ: *const *mut c_char = 0 as *const *mut c_char;
+pub static mut environ: *const *mut c_char = ptr::null();
 
 #[no_mangle]
 pub extern "C" fn _exit(status: c_int) {
@@ -120,17 +120,76 @@ pub extern "C" fn encrypt(block: [c_char; 64], edflag: c_int) {
 // }
 
 #[no_mangle]
-pub extern "C" fn execv(path: *const c_char, argv: *const *mut c_char) -> c_int {
-    unsafe { execve(path, argv, environ) }
+pub unsafe extern "C" fn execv(path: *const c_char, argv: *const *mut c_char) -> c_int {
+    execve(path, argv, environ)
 }
 
 #[no_mangle]
-pub extern "C" fn execve(
+pub unsafe extern "C" fn execve(
     path: *const c_char,
     argv: *const *mut c_char,
     envp: *const *mut c_char,
 ) -> c_int {
-    platform::execve(path, argv, envp)
+    #[cfg(target_os = "linux")] {
+        platform::execve(path, argv, envp)
+    }
+    #[cfg(target_os = "redox")] {
+        let mut env = envp;
+        while !(*env).is_null() {
+            let slice = c_str(*env);
+            // Should always contain a =, but worth checking
+            if let Some(sep) = slice.iter().position(|&c| c == b'=') {
+                // If the environment variable has no name, do not attempt
+                // to add it to the env.
+                if sep > 0 {
+                    let mut path = b"env:".to_vec();
+                    path.extend_from_slice(&slice[..sep]);
+                    match platform::syscall::open(&path, O_WRONLY | O_CREAT) {
+                        Ok(fd) => {
+                            // If the environment variable has no value, there
+                            // is no need to write anything to the env scheme.
+                            if sep + 1 < slice.len() {
+                                let n = match syscall::write(fd, &slice[sep + 1..]) {
+                                    Ok(n) => n,
+                                    err => {
+                                        return e(err) as c_int;
+                                    }
+                                };
+                            }
+                            // Cleanup after adding the variable.
+                            match platform::syscall::close(fd) {
+                                Ok(_) => (),
+                                err => {
+                                    return e(err) as c_int;
+                                }
+                            }
+                        }
+                        err => {
+                            return e(err) as c_int;
+                        }
+                    }
+                }
+            }
+            env = env.offset(1);
+        }
+
+        let mut len = 0;
+        for i in 0.. {
+            if (*arg.offset(i)).is_null() {
+                len = i;
+                break;
+            }
+        }
+
+        let mut args: Vec<[usize; 2]> = Vec::with_capacity(len);
+        let mut arg = argv;
+        while !(*arg).is_null() {
+            args.push([*arg as usize, c_str(*arg).len()]);
+            arg = arg.offset(1);
+        }
+
+        e(platform::syscall::execve(c_str(path), &args)) as c_int
+    }
 }
 
 #[no_mangle]

+ 1 - 0
tests/exec.c

@@ -1,4 +1,5 @@
 #include <unistd.h>
+#include <stdio.h>
 
 int main(int argc, char** argv) {
     char *const args[1] = {"arg"};

+ 0 - 0
tests/expected/exec.stderr


+ 1 - 0
tests/expected/exec.stdout

@@ -0,0 +1 @@
+Hello World!