Skip to content
Snippets Groups Projects
Verified Commit 234632d3 authored by jD91mZM2's avatar jD91mZM2
Browse files

Workaround compilation errors

parent 29a626cd
No related branches found
No related tags found
1 merge request!149Workaround compilation errors
#ifndef _BITS_EXEC_H
#define _BITS_EXEC_H
extern int execv(const char *path, char *const *argv);
int execl(const char *path, const char* argv0, ...)
{
int argc;
......@@ -22,6 +24,8 @@ int execl(const char *path, const char* argv0, ...)
}
}
extern int execve(const char *path, char *const *argv, char *const *envp);
int execle(const char *path, const char* argv0, ...)
{
int argc;
......
......@@ -8,6 +8,3 @@ sc = "0.2"
[target.'cfg(target_os = "redox")'.dependencies]
redox_syscall = "0.1"
[dependencies]
ralloc = { path = "../../ralloc" }
......@@ -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]
......
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 {}
......
......@@ -120,17 +120,68 @@ 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 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(platform::syscall::execve(c_str(path), &args)) as c_int
}
}
#[no_mangle]
......
Hello World!
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment