Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: runtime/wasm-runtime.c

Issue 1890283002: Subzero, Wasm: Link and run torture tests; bug fixes. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 //===- subzero/runtime/wasm-runtime.c - Subzero WASM runtime source -------===//
2 //
3 // The Subzero Code Generator
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the system calls required by the libc that is included
11 // in WebAssembly programs.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include <errno.h>
16 #include <fcntl.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <unistd.h>
23
24 extern char WASM_MEMORY[];
25
26 void env$$abort() {
27 fprintf(stderr, "Aborting...\n");
28 abort();
29 }
30
31 void env$$_abort() { env$$abort(); }
32
33 void env$$exit(int Status) {
34 exit(Status);
35 }
36 void env$$_exit(int Status) { env$$exit(Status); }
37
38 #define UNIMPLEMENTED(f) \
39 void env$$##f() { \
40 fprintf(stderr, "Unimplemented: " #f "\n"); \
41 abort(); \
42 }
43
44 UNIMPLEMENTED(sbrk)
45 UNIMPLEMENTED(setjmp)
46 UNIMPLEMENTED(longjmp)
47 UNIMPLEMENTED(__assert_fail)
48 UNIMPLEMENTED(__builtin_malloc)
49 UNIMPLEMENTED(__builtin_apply)
50 UNIMPLEMENTED(__builtin_apply_args)
51 UNIMPLEMENTED(pthread_cleanup_push)
52 UNIMPLEMENTED(pthread_cleanup_pop)
53 UNIMPLEMENTED(pthread_self)
54 UNIMPLEMENTED(abs)
55 UNIMPLEMENTED(__floatditf)
56 UNIMPLEMENTED(__floatsitf)
57 UNIMPLEMENTED(__fixtfdi)
58 UNIMPLEMENTED(__fixtfsi)
59 UNIMPLEMENTED(__fixsfti)
60 UNIMPLEMENTED(__netf2)
61 UNIMPLEMENTED(__getf2)
62 UNIMPLEMENTED(__eqtf2)
63 UNIMPLEMENTED(__lttf2)
64 UNIMPLEMENTED(__addtf3)
65 UNIMPLEMENTED(__subtf3)
66 UNIMPLEMENTED(__divtf3)
67 UNIMPLEMENTED(__multf3)
68 UNIMPLEMENTED(__multi3)
69 UNIMPLEMENTED(__lock)
70 UNIMPLEMENTED(__unlock)
71 UNIMPLEMENTED(__syscall6)
72 UNIMPLEMENTED(__syscall20)
73 UNIMPLEMENTED(__syscall140)
74 UNIMPLEMENTED(__syscall192)
75
76 void *wasmPtr(int Index) {
77 // TODO (eholk): get the mask from the WASM file.
78 const int MASK = 0x3fffff;
79 Index &= MASK;
80
81 return WASM_MEMORY + Index;
82 }
83
84 extern int __szwasm_main(int, const char **);
85
86 #define WASM_REF(Type, Index) ((Type *)wasmPtr(Index))
87 #define WASM_DEREF(Type, Index) (*WASM_REF(Type, Index))
88
89 int main(int argc, const char **argv) { return __szwasm_main(argc, argv); }
90
91 /// sys_write
92 int env$$__syscall4(int Which, int VarArgs) {
93 int Fd = WASM_DEREF(int, VarArgs + 0 * sizeof(int));
94 int Buffer = WASM_DEREF(int, VarArgs + 1 * sizeof(int));
95 int Length = WASM_DEREF(int, VarArgs + 2 * sizeof(int));
96
97 return write(Fd, WASM_REF(char *, Buffer), Length);
98 }
99
100 /// sys_open
101 int env$$__syscall5(int Which, int VarArgs) {
102 int WasmPath = WASM_DEREF(int, VarArgs);
103 int Flags = WASM_DEREF(int, VarArgs + 4);
104 int Mode = WASM_DEREF(int, VarArgs + 8);
105 const char *Path = WASM_REF(char, WasmPath);
106
107 fprintf(stderr, "sys_open(%s, %d, %d)\n", Path, Flags, Mode);
108
109 return open(Path, Flags, Mode);
110 }
111
112 /// sys_ioctl
113 int env$$__syscall54(int A, int B) {
114 int Fd = WASM_DEREF(int, B + 0 * sizeof(int));
115 int Op = WASM_DEREF(int, B + 1 * sizeof(int));
116 int ArgP = WASM_DEREF(int, B + 2 * sizeof(int));
117 // TODO (eholk): implement sys_ioctl
118 return -ENOTTY;
119 }
120
121 int env$$__syscall146(int Which, int VarArgs) {
122 fprintf(stderr, "syscall146\n");
123
124 int Fd = WASM_DEREF(int, VarArgs);
125 int Iov = WASM_DEREF(int, VarArgs + sizeof(int));
126 int Iovcnt = WASM_DEREF(int, VarArgs + 2 * sizeof(int));
127
128 fprintf(stderr, " Fd=%d, Iov=%d (%p), Iovcnt=%d\n", Fd, Iov, wasmPtr(Iov),
129 Iovcnt);
130
131 int Count = 0;
132
133 for (int I = 0; I < Iovcnt; ++I) {
134 void *Ptr = WASM_REF(void, WASM_DEREF(int, Iov + I * 8));
135 int Length = WASM_DEREF(int, Iov + I * 8 + 4);
136
137 fprintf(stderr, " [%d] write(%d, %p, %d) = ", I, Fd, Ptr, Length);
138 int Curr = write(Fd, Ptr, Length);
139
140 fprintf(stderr, "%d\n", Curr);
141
142 if (Curr < 0) {
143 return -1;
144 }
145 Count += Curr;
146 }
147 fprintf(stderr, " Count = %d\n", Count);
148 return Count;
149 }
OLDNEW
« fetch-torture-tests.sh ('K') | « pydir/wasm-run-torture-tests.py ('k') | src/IceCfg.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698