Add some syscalls

This commit is contained in:
Steve Akinyemi
2018-11-19 01:04:08 +01:00
parent ab570e8be6
commit cb77e89c45
5 changed files with 36 additions and 2 deletions

View File

@ -150,7 +150,7 @@
```
- <a name="exit"></a>exit - _[__syscall1](#__syscall1)_ &nbsp;&nbsp;&nbsp;&nbsp;[:top:](#emscripten-syscalls)
```rust
fn exit(error_code: usize)
fn exit(status: c_int)
```
- <a name="faccessat"></a>faccessat - _[__syscall307](#__syscall307)_ &nbsp;&nbsp;&nbsp;&nbsp;[:top:](#emscripten-syscalls)
```rust
@ -289,7 +289,7 @@ fn exit(error_code: usize)
```
- <a name="open"></a>open - _[__syscall5](#__syscall5)_ &nbsp;&nbsp;&nbsp;&nbsp;[:top:](#emscripten-syscalls)
```rust
fn open(pathname: *const char, flags: usize, mode: usize) -> usize
fn open(path: *const c_char, oflag: c_int, ...) -> c_int
```
- <a name="openat"></a>openat - _[__syscall295](#__syscall295)_ &nbsp;&nbsp;&nbsp;&nbsp;[:top:](#emscripten-syscalls)
```rust

View File

@ -3,6 +3,7 @@ use crate::webassembly::{ImportObject, ImportValue};
mod abort;
mod printf;
mod putchar;
mod syscalls;
pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
let mut import_object = ImportObject::new();
@ -10,6 +11,10 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
import_object.set("env", "putchar", ImportValue::Func(putchar::putchar as *const u8));
import_object.set("env", "abort", ImportValue::Func(abort::abort as *const u8));
import_object.set("env", "_abort", ImportValue::Func(abort::abort as *const u8));
// SYSCALLS
import_object.set("env", "__syscall1", ImportValue::Func(syscalls::__syscall1 as *const u8));
import_object.set("env", "__syscall3", ImportValue::Func(syscalls::__syscall3 as *const u8));
import_object.set("env", "__syscall5", ImportValue::Func(syscalls::__syscall5 as *const u8));
import_object
}

View File

@ -0,0 +1 @@
pub mod syscalls;

View File

@ -0,0 +1,25 @@
use libc::{
c_int,
c_void,
c_char,
size_t,
ssize_t,
open,
exit,
read,
};
/// exit
pub extern "C" fn __syscall1(status: c_int) {
unsafe { exit(status); }
}
/// read
pub extern "C" fn __syscall3(fd: c_int, buf: *mut c_void, count: size_t) -> ssize_t {
unsafe { read(fd, buf, count) }
}
/// open
pub extern "C" fn __syscall5(path: *const c_char, oflag: c_int) -> c_int {
unsafe { open(path, oflag) }
}

View File

@ -0,0 +1,3 @@
mod darwin;
pub use self::darwin::syscalls::*;