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

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: Code review feedback 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
« no previous file with comments | « pydir/wasm-run-torture-tests.py ('k') | src/IceCfg.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/runtime/wasm-runtime.c - Subzero WASM runtime source -------===// 1 //===- subzero/runtime/wasm-runtime.c - Subzero WASM runtime source -------===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This file implements the system calls required by the libc that is included 10 // This file implements the system calls required by the libc that is included
11 // in WebAssembly programs. 11 // in WebAssembly programs.
12 // 12 //
13 //===----------------------------------------------------------------------===// 13 //===----------------------------------------------------------------------===//
14 14
15 #include <errno.h> 15 #include <errno.h>
16 #include <fcntl.h>
16 #include <stdio.h> 17 #include <stdio.h>
17 #include <stdlib.h> 18 #include <stdlib.h>
18 #include <string.h> 19 #include <string.h>
20 #include <sys/types.h>
21 #include <sys/stat.h>
19 #include <unistd.h> 22 #include <unistd.h>
20 23
21 extern char WASM_MEMORY[]; 24 extern char WASM_MEMORY[];
22 25
23 void env$$abort() { 26 void env$$abort() {
24 fprintf(stderr, "Aborting...\n"); 27 fprintf(stderr, "Aborting...\n");
25 abort(); 28 abort();
26 } 29 }
27 30
28 void env$$_abort() { env$$abort(); } 31 void env$$_abort() { env$$abort(); }
29 32
33 void env$$exit(int Status) {
34 exit(Status);
35 }
36 void env$$_exit(int Status) { env$$exit(Status); }
37
30 #define UNIMPLEMENTED(f) \ 38 #define UNIMPLEMENTED(f) \
31 void env$$##f() { \ 39 void env$$##f() { \
32 fprintf(stderr, "Unimplemented: " #f "\n"); \ 40 fprintf(stderr, "Unimplemented: " #f "\n"); \
33 abort(); \ 41 abort(); \
34 } 42 }
35 43
36 UNIMPLEMENTED(sbrk) 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)
37 UNIMPLEMENTED(pthread_cleanup_push) 51 UNIMPLEMENTED(pthread_cleanup_push)
38 UNIMPLEMENTED(pthread_cleanup_pop) 52 UNIMPLEMENTED(pthread_cleanup_pop)
39 UNIMPLEMENTED(pthread_self) 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)
40 UNIMPLEMENTED(__lock) 69 UNIMPLEMENTED(__lock)
41 UNIMPLEMENTED(__unlock) 70 UNIMPLEMENTED(__unlock)
42 UNIMPLEMENTED(__syscall6) 71 UNIMPLEMENTED(__syscall6)
72 UNIMPLEMENTED(__syscall20)
43 UNIMPLEMENTED(__syscall140) 73 UNIMPLEMENTED(__syscall140)
74 UNIMPLEMENTED(__syscall192)
44 75
45 void *wasmPtr(int Index) { 76 void *wasmPtr(int Index) {
46 // TODO (eholk): get the mask from the WASM file. 77 // TODO (eholk): get the mask from the WASM file.
47 const int MASK = 0x3fffff; 78 const int MASK = 0x3fffff;
48 Index &= MASK; 79 Index &= MASK;
49 80
50 return WASM_MEMORY + Index; 81 return WASM_MEMORY + Index;
51 } 82 }
52 83
53 extern int __szwasm_main(int, char **); 84 extern int __szwasm_main(int, const char **);
54 85
55 #define WASM_REF(Type, Index) ((Type *)wasmPtr(Index)) 86 #define WASM_REF(Type, Index) ((Type *)wasmPtr(Index))
56 #define WASM_DEREF(Type, Index) (*WASM_REF(Type, Index)) 87 #define WASM_DEREF(Type, Index) (*WASM_REF(Type, Index))
57 88
58 int main(int argc, char **argv) { return __szwasm_main(argc, argv); } 89 int main(int argc, const char **argv) { return __szwasm_main(argc, argv); }
59 90
60 /// sys_write 91 /// sys_write
61 int env$$__syscall4(int Which, int VarArgs) { 92 int env$$__syscall4(int Which, int VarArgs) {
62 int Fd = WASM_DEREF(int, VarArgs + 0 * sizeof(int)); 93 int Fd = WASM_DEREF(int, VarArgs + 0 * sizeof(int));
63 int Buffer = WASM_DEREF(int, VarArgs + 1 * sizeof(int)); 94 int Buffer = WASM_DEREF(int, VarArgs + 1 * sizeof(int));
64 int Length = WASM_DEREF(int, VarArgs + 2 * sizeof(int)); 95 int Length = WASM_DEREF(int, VarArgs + 2 * sizeof(int));
65 96
66 return write(Fd, WASM_REF(char *, Buffer), Length); 97 return write(Fd, WASM_REF(char *, Buffer), Length);
67 } 98 }
68 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
69 /// sys_ioctl 112 /// sys_ioctl
70 int env$$__syscall54(int A, int B) { 113 int env$$__syscall54(int A, int B) {
71 int Fd = WASM_DEREF(int, B + 0 * sizeof(int)); 114 int Fd = WASM_DEREF(int, B + 0 * sizeof(int));
72 int Op = WASM_DEREF(int, B + 1 * sizeof(int)); 115 int Op = WASM_DEREF(int, B + 1 * sizeof(int));
73 int ArgP = WASM_DEREF(int, B + 2 * sizeof(int)); 116 int ArgP = WASM_DEREF(int, B + 2 * sizeof(int));
74 // TODO (eholk): implement sys_ioctl 117 // TODO (eholk): implement sys_ioctl
75 return -ENOTTY; 118 return -ENOTTY;
76 } 119 }
77 120
78 int env$$__syscall146(int Which, int VarArgs) { 121 int env$$__syscall146(int Which, int VarArgs) {
(...skipping 18 matching lines...) Expand all
97 fprintf(stderr, "%d\n", Curr); 140 fprintf(stderr, "%d\n", Curr);
98 141
99 if (Curr < 0) { 142 if (Curr < 0) {
100 return -1; 143 return -1;
101 } 144 }
102 Count += Curr; 145 Count += Curr;
103 } 146 }
104 fprintf(stderr, " Count = %d\n", Count); 147 fprintf(stderr, " Count = %d\n", Count);
105 return Count; 148 return Count;
106 } 149 }
OLDNEW
« no previous file with comments | « 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