| Index: runtime/wasm-runtime.c
|
| diff --git a/runtime/wasm-runtime.c b/runtime/wasm-runtime.c
|
| index 0ffb6ca9d013ddb361a92dbc42c6444a0ea18537..a7ce49b6d6227c42a3e9863116acf6f5f947031c 100644
|
| --- a/runtime/wasm-runtime.c
|
| +++ b/runtime/wasm-runtime.c
|
| @@ -13,9 +13,12 @@
|
| //===----------------------------------------------------------------------===//
|
|
|
| #include <errno.h>
|
| +#include <fcntl.h>
|
| #include <stdio.h>
|
| #include <stdlib.h>
|
| #include <string.h>
|
| +#include <sys/types.h>
|
| +#include <sys/stat.h>
|
| #include <unistd.h>
|
|
|
| extern char WASM_MEMORY[];
|
| @@ -27,6 +30,11 @@ void env$$abort() {
|
|
|
| void env$$_abort() { env$$abort(); }
|
|
|
| +void env$$exit(int Status) {
|
| + exit(Status);
|
| +}
|
| +void env$$_exit(int Status) { env$$exit(Status); }
|
| +
|
| #define UNIMPLEMENTED(f) \
|
| void env$$##f() { \
|
| fprintf(stderr, "Unimplemented: " #f "\n"); \
|
| @@ -34,13 +42,36 @@ void env$$_abort() { env$$abort(); }
|
| }
|
|
|
| UNIMPLEMENTED(sbrk)
|
| +UNIMPLEMENTED(setjmp)
|
| +UNIMPLEMENTED(longjmp)
|
| +UNIMPLEMENTED(__assert_fail)
|
| +UNIMPLEMENTED(__builtin_malloc)
|
| +UNIMPLEMENTED(__builtin_apply)
|
| +UNIMPLEMENTED(__builtin_apply_args)
|
| UNIMPLEMENTED(pthread_cleanup_push)
|
| UNIMPLEMENTED(pthread_cleanup_pop)
|
| UNIMPLEMENTED(pthread_self)
|
| +UNIMPLEMENTED(abs)
|
| +UNIMPLEMENTED(__floatditf)
|
| +UNIMPLEMENTED(__floatsitf)
|
| +UNIMPLEMENTED(__fixtfdi)
|
| +UNIMPLEMENTED(__fixtfsi)
|
| +UNIMPLEMENTED(__fixsfti)
|
| +UNIMPLEMENTED(__netf2)
|
| +UNIMPLEMENTED(__getf2)
|
| +UNIMPLEMENTED(__eqtf2)
|
| +UNIMPLEMENTED(__lttf2)
|
| +UNIMPLEMENTED(__addtf3)
|
| +UNIMPLEMENTED(__subtf3)
|
| +UNIMPLEMENTED(__divtf3)
|
| +UNIMPLEMENTED(__multf3)
|
| +UNIMPLEMENTED(__multi3)
|
| UNIMPLEMENTED(__lock)
|
| UNIMPLEMENTED(__unlock)
|
| UNIMPLEMENTED(__syscall6)
|
| +UNIMPLEMENTED(__syscall20)
|
| UNIMPLEMENTED(__syscall140)
|
| +UNIMPLEMENTED(__syscall192)
|
|
|
| void *wasmPtr(int Index) {
|
| // TODO (eholk): get the mask from the WASM file.
|
| @@ -50,12 +81,12 @@ void *wasmPtr(int Index) {
|
| return WASM_MEMORY + Index;
|
| }
|
|
|
| -extern int __szwasm_main(int, char **);
|
| +extern int __szwasm_main(int, const char **);
|
|
|
| #define WASM_REF(Type, Index) ((Type *)wasmPtr(Index))
|
| #define WASM_DEREF(Type, Index) (*WASM_REF(Type, Index))
|
|
|
| -int main(int argc, char **argv) { return __szwasm_main(argc, argv); }
|
| +int main(int argc, const char **argv) { return __szwasm_main(argc, argv); }
|
|
|
| /// sys_write
|
| int env$$__syscall4(int Which, int VarArgs) {
|
| @@ -66,6 +97,18 @@ int env$$__syscall4(int Which, int VarArgs) {
|
| return write(Fd, WASM_REF(char *, Buffer), Length);
|
| }
|
|
|
| +/// sys_open
|
| +int env$$__syscall5(int Which, int VarArgs) {
|
| + int WasmPath = WASM_DEREF(int, VarArgs);
|
| + int Flags = WASM_DEREF(int, VarArgs + 4);
|
| + int Mode = WASM_DEREF(int, VarArgs + 8);
|
| + const char *Path = WASM_REF(char, WasmPath);
|
| +
|
| + fprintf(stderr, "sys_open(%s, %d, %d)\n", Path, Flags, Mode);
|
| +
|
| + return open(Path, Flags, Mode);
|
| +}
|
| +
|
| /// sys_ioctl
|
| int env$$__syscall54(int A, int B) {
|
| int Fd = WASM_DEREF(int, B + 0 * sizeof(int));
|
|
|