Skip to content
Snippets Groups Projects
Commit 2096b851 authored by Dan Robertson's avatar Dan Robertson Committed by Dan Robertson
Browse files

Fix platform

 - Add cfg to extern crate sc. It is not used by redox.
 - Fix bad syntax in brk implementation for redox
 - nits
   - style: update brk implementation for linux
   - style: no space between not operator and ptr.is_null
   - style: should be a space around = in module path
parent a808dfe3
No related branches found
No related tags found
1 merge request!16Fix platform
......@@ -3,6 +3,7 @@
#![no_std]
#![allow(non_camel_case_types)]
#[cfg(all(not(feature="no_std"), target_os = "linux"))]
#[macro_use]
extern crate sc;
......
......@@ -6,40 +6,31 @@ pub fn brk(addr: *const c_void) -> c_int {
unsafe {
let newbrk = syscall!(BRK, addr);
if newbrk < addr as usize {
return -1
-1
} else {
0
}
0
}
}
pub fn chdir(path: *const c_char) -> c_int {
unsafe {
syscall!(CHDIR, path) as c_int
}
unsafe { syscall!(CHDIR, path) as c_int }
}
pub fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int {
unsafe {
syscall!(CHOWN, owner as u32, group as u32) as c_int
}
unsafe { syscall!(CHOWN, owner as u32, group as u32) as c_int }
}
pub fn close(fildes: c_int) -> c_int {
unsafe {
syscall!(CLOSE, fildes) as c_int
}
unsafe { syscall!(CLOSE, fildes) as c_int }
}
pub fn dup(fildes: c_int) -> c_int {
unsafe {
syscall!(DUP, fildes) as c_int
}
unsafe { syscall!(DUP, fildes) as c_int }
}
pub fn dup2(fildes: c_int, fildes2:c_int) -> c_int {
unsafe {
syscall!(DUP2, fildes, fildes2) as c_int
}
pub fn dup2(fildes: c_int, fildes2: c_int) -> c_int {
unsafe { syscall!(DUP2, fildes, fildes2) as c_int }
}
pub fn exit(status: c_int) -> ! {
......@@ -50,27 +41,19 @@ pub fn exit(status: c_int) -> ! {
}
pub fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int {
unsafe {
syscall!(FCHOWN, owner, group) as c_int
}
unsafe { syscall!(FCHOWN, fildes, owner, group) as c_int }
}
pub fn fchdir(fildes: c_int) -> c_int {
unsafe {
syscall!(FCHDIR, fildes) as c_int
}
unsafe { syscall!(FCHDIR, fildes) as c_int }
}
pub fn fsync(fildes: c_int) -> c_int {
unsafe {
syscall!(FSYNC, fildes) as c_int
}
unsafe { syscall!(FSYNC, fildes) as c_int }
}
pub fn ftruncate(fildes: c_int, length: off_t) -> c_int {
unsafe {
syscall!(FTRUNCATE, fildes, length) as c_int
}
unsafe { syscall!(FTRUNCATE, fildes, length) as c_int }
}
pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char {
......@@ -81,70 +64,47 @@ pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char {
}
pub fn getegid() -> gid_t {
unsafe {
syscall!(GETEGID)
}
unsafe { syscall!(GETEGID) }
}
pub fn geteuid() -> uid_t {
unsafe {
syscall!(GETEUID)
}
unsafe { syscall!(GETEUID) }
}
pub fn getgid() -> gid_t {
unsafe {
syscall!(GETGID)
}
unsafe { syscall!(GETGID) }
}
pub fn getpgid(pid: pid_t) -> pid_t {
unsafe {
syscall!(GETPGID, pid)
}
unsafe { syscall!(GETPGID, pid) }
}
pub fn getpid() -> pid_t {
unsafe {
syscall!(GETPID)
}
unsafe { syscall!(GETPID) }
}
pub fn getppid() -> pid_t {
unsafe {
syscall!(GETPPID)
}
unsafe { syscall!(GETPPID) }
}
pub fn getuid() -> uid_t {
unsafe {
syscall!(GETUID)
}
unsafe { syscall!(GETUID) }
}
pub fn link(path1: *const c_char, path2: *const c_char) -> c_int {
unsafe {
syscall!(LINK, path1, path2) as c_int
}
unsafe { syscall!(LINK, path1, path2) as c_int }
}
#[cfg(target_arch = "x86_64")]
pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
unsafe {
syscall!(OPEN, path, oflag, mode) as c_int
}
unsafe { syscall!(OPEN, path, oflag, mode) as c_int }
}
#[cfg(target_arch = "aarch64")]
pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
unsafe {
syscall!(OPENAT, AT_FDCWD, path, oflag, mode) as c_int
}
unsafe { syscall!(OPENAT, AT_FDCWD, path, oflag, mode) as c_int }
}
pub fn write(fildes: c_int, buf: &[u8]) -> ssize_t {
unsafe {
syscall!(WRITE, fildes, buf.as_ptr(), buf.len()) as ssize_t
}
unsafe { syscall!(WRITE, fildes, buf.as_ptr(), buf.len()) as ssize_t }
}
......@@ -3,18 +3,19 @@ use syscall;
use c_str;
use types::*;
pub fn brk(addr: *const c_void) -> {
pub fn brk(addr: *const c_void) -> c_int {
syscall::brk(addr as usize).unwrap_or(-1) as c_int
}
pub fn chdir(path: *const c_char) -> c_int {
pub fn chdir(path: *const c_char) -> c_int {
let path = unsafe { c_str(path) };
syscall::chdir(path).unwrap_or(-1) as c_int
}
}
pub fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int {
let fd = syscall::open(cstr_to_slice(path));
syscall::fchown(fd as usize, owner as usize, group as usize).unwrap_or(-1) as c_int
}
pub fn close(fd: c_int) -> c_int {
syscall::close(fd as usize);
......@@ -25,7 +26,7 @@ pub fn dup(fd: c_int) -> c_int {
syscall::dup(fd as usize, &[]).unwrap_or(-1) as c_int
}
pub fn dup2(fd1: c_int, fd2) -> c_int {
pub fn dup2(fd1: c_int, fd2: c_int) -> c_int {
syscall::dup2(fd1 as usize, fd2 as usize, &[]).unwrap_or(-1) as c_int
}
......@@ -51,17 +52,15 @@ pub fn fsync(fd: c_int) -> c_int {
syscall::fsync(fd as usize).unwrap_or(-1) as c_int
}
pub fn ftruncate(fd: c_int, len: off_t) -> {
pub fn ftruncate(fd: c_int, len: off_t) -> c_int {
syscall::ftruncate(fd as usize, len as usize).unwrap_or(-1) as c_int
}
pub fn getcwd(buf: *mut c_char, size: size_t) -> {
pub fn getcwd(buf: *mut c_char, size: size_t) -> c_int {
// XXX: do something with size maybe
let rbuf = unsafe { c_str(buf) };
syscall::getcwd(rbuf);
unsafe {
&*(rbuf as *mut [c_char])
}
unsafe { &*(rbuf as *mut [c_char]) }
}
pub fn getegid() -> gid_t {
......@@ -92,7 +91,7 @@ pub fn getuid() -> uid_t {
syscall::getuid().unwrap_or(-1) as pid_t
}
pub fn link(path1: const c_char, path2: const c_char) -> c_int {
pub fn link(path1: *const c_char, path2: *const c_char) -> c_int {
let path1 = unsafe { c_str(path1) };
let path2 = unsafe { c_str(path2) };
syscall::link(path1, path2).unwrap_or(-1) as c_int
......
......@@ -9,11 +9,11 @@ use platform::types::*;
pub use sys::*;
#[cfg(target_os = "linux")]
#[path="linux.rs"]
#[path = "linux.rs"]
pub mod sys;
#[cfg(target_os = "redox")]
#[path="redox.rs"]
#[path = "redox.rs"]
pub mod sys;
pub const F_DUPFD: c_int = 0;
......
......@@ -76,7 +76,7 @@ pub unsafe extern "C" fn calloc(nelem: size_t, elsize: size_t) -> *mut c_void {
let size = nelem * elsize;
let ptr = malloc(size);
if ! ptr.is_null() {
if !ptr.is_null() {
intrinsics::write_bytes(ptr as *mut u8, 0, size);
}
ptr
......@@ -209,7 +209,7 @@ pub extern "C" fn lrand48() -> c_long {
pub unsafe extern "C" fn malloc(size: size_t) -> *mut c_void {
let align = 8;
let ptr = ralloc::alloc(size + 16, align);
if ! ptr.is_null() {
if !ptr.is_null() {
*(ptr as *mut u64) = (size + 16) as u64;
*(ptr as *mut u64).offset(1) = align as u64;
ptr.offset(16) as *mut c_void
......@@ -289,7 +289,7 @@ pub unsafe extern "C" fn realloc(ptr: *mut c_void, size: size_t) -> *mut c_void
let old_size = *(old_ptr as *mut u64);
let align = *(old_ptr as *mut u64).offset(1);
let ptr = ralloc::realloc(old_ptr, old_size as usize, size + 16, align as usize);
if ! ptr.is_null() {
if !ptr.is_null() {
*(ptr as *mut u64) = (size + 16) as u64;
*(ptr as *mut u64).offset(1) = align;
ptr.offset(16) as *mut c_void
......@@ -367,7 +367,7 @@ pub extern "C" fn unlockpt(fildes: c_int) -> c_int {
pub unsafe extern "C" fn valloc(size: size_t) -> *mut c_void {
let align = 4096;
let ptr = ralloc::alloc(size + 16, align);
if ! ptr.is_null() {
if !ptr.is_null() {
*(ptr as *mut u64) = (size + 16) as u64;
*(ptr as *mut u64).offset(1) = align as u64;
ptr.offset(16) as *mut c_void
......
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