Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Implement open #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ crate-type = ["staticlib", "dylib"]

[dependencies]
lazy_static = { version = "0.2.2", features = ["spin_no_std"] }
libc = { version = "0.2", default-features = false }
rlibc = "1.0.0"
spin = "0.4.5"
sc = "0.1.5"
Expand Down
1 change: 1 addition & 0 deletions ported_objects
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ mlockall.o
mmap.o
mremap.o
munmap.o
open.o
quick_exit.o
stpcpy.o
strcmp.o
Expand Down
16 changes: 16 additions & 0 deletions src/fcntl/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use libc::c_int;

// These constants don't appear in rust-lang/libc, so we define them here
// because musl defines them. Maybe we should add them to libc...
pub const O_LARGEFILE: c_int = 0100000;
pub const O_NOATIME: c_int = 01000000;
pub const O_PATH: c_int = 010000000;
pub const O_TMPFILE: c_int = 020200000;

pub const F_SETSIG: c_int = 10;
pub const F_GETSIG: c_int = 11;

pub const F_SETOWN_EX: c_int = 15;
pub const F_GETOWN_EX: c_int = 16;

pub const F_GETOWNER_UIDS: c_int = 17;
3 changes: 3 additions & 0 deletions src/fcntl/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod constants;

pub mod open;
20 changes: 20 additions & 0 deletions src/fcntl/open.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use super::constants::{O_TMPFILE};
use libc::*;
use syscall_mgt::syscall_return;
use va_list::VaList;

#[no_mangle]
pub unsafe extern "C" fn open(filename: *const c_char, flags: c_int, mut args: VaList) -> c_int {
let mut mode: mode_t = 0;

if (flags & O_CREAT) != 0 || ((flags & O_TMPFILE) == O_TMPFILE) {
mode = args.get::<mode_t>();
}

let fd = syscall!(OPEN, filename, flags, mode);
if fd >= 0 && (flags & O_CLOEXEC) != 0 {
syscall!(FCNTL, fd, F_SETFD, FD_CLOEXEC);
}

syscall_return(fd) as c_int
}
10 changes: 7 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#![no_std]
#![feature(asm, const_fn, lang_items, linkage, compiler_builtins_lib)]
#![feature(asm, const_fn, lang_items, linkage, compiler_builtins_lib, core_intrinsics)]

#![allow(non_camel_case_types)]

extern crate compiler_builtins;
#[macro_use]
extern crate lazy_static;
extern crate libc;
extern crate rlibc;
extern crate spin;
extern crate sc as syscall;
Expand All @@ -17,6 +18,7 @@ pub use rlibc::*;
pub mod syscall_mgt;

pub mod exit;
pub mod fcntl;
pub mod malloc;
pub mod mmap;
pub mod string;
Expand All @@ -36,7 +38,9 @@ pub use platform::mman;
pub use platform::pthread;
pub use platform::signal;

use core::intrinsics;
#[cfg(not(test))]
#[lang = "panic_fmt"]
#[no_mangle]
extern "C" fn panic_fmt() {}
extern "C" fn rust_begin_panic(_msg: core::fmt::Arguments, _file: &'static str, _line: u32) -> ! {
unsafe { intrinsics::abort() }
}