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

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

Issue 1900213002: Subzero - WASM: Codegen fixes, better test infrastructure (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Copyright notice and TODO 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
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 <fcntl.h>
17 #include <math.h>
17 #include <stdio.h> 18 #include <stdio.h>
18 #include <stdlib.h> 19 #include <stdlib.h>
19 #include <string.h> 20 #include <string.h>
20 #include <sys/types.h> 21 #include <sys/types.h>
21 #include <sys/stat.h> 22 #include <sys/stat.h>
22 #include <unistd.h> 23 #include <unistd.h>
23 24
24 extern char WASM_MEMORY[]; 25 extern char WASM_MEMORY[];
25 26
26 void env$$abort() { 27 void env$$abort() {
(...skipping 10 matching lines...) Expand all
37 void env$$##f() { \ 38 void env$$##f() { \
38 fprintf(stderr, "Unimplemented: " #f "\n"); \ 39 fprintf(stderr, "Unimplemented: " #f "\n"); \
39 abort(); \ 40 abort(); \
40 } 41 }
41 42
42 UNIMPLEMENTED(sbrk) 43 UNIMPLEMENTED(sbrk)
43 UNIMPLEMENTED(setjmp) 44 UNIMPLEMENTED(setjmp)
44 UNIMPLEMENTED(longjmp) 45 UNIMPLEMENTED(longjmp)
45 UNIMPLEMENTED(__assert_fail) 46 UNIMPLEMENTED(__assert_fail)
46 UNIMPLEMENTED(__builtin_malloc) 47 UNIMPLEMENTED(__builtin_malloc)
48 UNIMPLEMENTED(__builtin_isinff)
49 UNIMPLEMENTED(__builtin_isinfl)
47 UNIMPLEMENTED(__builtin_apply) 50 UNIMPLEMENTED(__builtin_apply)
48 UNIMPLEMENTED(__builtin_apply_args) 51 UNIMPLEMENTED(__builtin_apply_args)
49 UNIMPLEMENTED(pthread_cleanup_push) 52 UNIMPLEMENTED(pthread_cleanup_push)
50 UNIMPLEMENTED(pthread_cleanup_pop) 53 UNIMPLEMENTED(pthread_cleanup_pop)
51 UNIMPLEMENTED(pthread_self) 54 UNIMPLEMENTED(pthread_self)
52 UNIMPLEMENTED(abs)
53 UNIMPLEMENTED(__floatditf) 55 UNIMPLEMENTED(__floatditf)
54 UNIMPLEMENTED(__floatsitf) 56 UNIMPLEMENTED(__floatsitf)
55 UNIMPLEMENTED(__fixtfdi) 57 UNIMPLEMENTED(__fixtfdi)
56 UNIMPLEMENTED(__fixtfsi) 58 UNIMPLEMENTED(__fixtfsi)
57 UNIMPLEMENTED(__fixsfti) 59 UNIMPLEMENTED(__fixsfti)
58 UNIMPLEMENTED(__netf2) 60 UNIMPLEMENTED(__netf2)
59 UNIMPLEMENTED(__getf2) 61 UNIMPLEMENTED(__getf2)
60 UNIMPLEMENTED(__eqtf2) 62 UNIMPLEMENTED(__eqtf2)
61 UNIMPLEMENTED(__lttf2) 63 UNIMPLEMENTED(__lttf2)
62 UNIMPLEMENTED(__addtf3) 64 UNIMPLEMENTED(__addtf3)
63 UNIMPLEMENTED(__subtf3) 65 UNIMPLEMENTED(__subtf3)
64 UNIMPLEMENTED(__divtf3) 66 UNIMPLEMENTED(__divtf3)
65 UNIMPLEMENTED(__multf3) 67 UNIMPLEMENTED(__multf3)
66 UNIMPLEMENTED(__multi3) 68 UNIMPLEMENTED(__multi3)
67 UNIMPLEMENTED(__lock) 69 UNIMPLEMENTED(__lock)
68 UNIMPLEMENTED(__unlock) 70 UNIMPLEMENTED(__unlock)
69 UNIMPLEMENTED(__syscall6) 71 UNIMPLEMENTED(__syscall6) // sys_close
70 UNIMPLEMENTED(__syscall20) 72 UNIMPLEMENTED(__syscall140) // sys_llseek
71 UNIMPLEMENTED(__syscall140) 73 UNIMPLEMENTED(__syscall192) // sys_mmap?
72 UNIMPLEMENTED(__syscall192) 74 UNIMPLEMENTED(__unordtf2)
75 UNIMPLEMENTED(__fixunstfsi)
76 UNIMPLEMENTED(__floatunsitf)
77 UNIMPLEMENTED(__extenddftf2)
73 78
74 void *wasmPtr(int Index) { 79 void *wasmPtr(int Index) {
75 // TODO (eholk): get the mask from the WASM file. 80 // TODO (eholk): get the mask from the WASM file.
76 const int MASK = 0x3fffff; 81 const int MASK = 0xffffff;
77 Index &= MASK; 82 Index &= MASK;
78 83
79 return WASM_MEMORY + Index; 84 return WASM_MEMORY + Index;
80 } 85 }
81 86
82 extern int __szwasm_main(int, const char **); 87 extern int __szwasm_main(int, const char **);
83 88
84 #define WASM_REF(Type, Index) ((Type *)wasmPtr(Index)) 89 #define WASM_REF(Type, Index) ((Type *)wasmPtr(Index))
85 #define WASM_DEREF(Type, Index) (*WASM_REF(Type, Index)) 90 #define WASM_DEREF(Type, Index) (*WASM_REF(Type, Index))
86 91
87 int main(int argc, const char **argv) { return __szwasm_main(argc, argv); } 92 int main(int argc, const char **argv) { return __szwasm_main(argc, argv); }
88 93
94 int env$$abs(int a) { return abs(a); }
95
96 double env$$pow(double x, double y) { return pow(x, y); }
97
89 /// sys_write 98 /// sys_write
90 int env$$__syscall4(int Which, int VarArgs) { 99 int env$$__syscall4(int Which, int VarArgs) {
91 int Fd = WASM_DEREF(int, VarArgs + 0 * sizeof(int)); 100 int Fd = WASM_DEREF(int, VarArgs + 0 * sizeof(int));
92 int Buffer = WASM_DEREF(int, VarArgs + 1 * sizeof(int)); 101 int Buffer = WASM_DEREF(int, VarArgs + 1 * sizeof(int));
93 int Length = WASM_DEREF(int, VarArgs + 2 * sizeof(int)); 102 int Length = WASM_DEREF(int, VarArgs + 2 * sizeof(int));
94 103
95 return write(Fd, WASM_REF(char *, Buffer), Length); 104 return write(Fd, WASM_REF(char *, Buffer), Length);
96 } 105 }
97 106
98 /// sys_open 107 /// sys_open
99 int env$$__syscall5(int Which, int VarArgs) { 108 int env$$__syscall5(int Which, int VarArgs) {
100 int WasmPath = WASM_DEREF(int, VarArgs); 109 int WasmPath = WASM_DEREF(int, VarArgs);
101 int Flags = WASM_DEREF(int, VarArgs + 4); 110 int Flags = WASM_DEREF(int, VarArgs + 4);
102 int Mode = WASM_DEREF(int, VarArgs + 8); 111 int Mode = WASM_DEREF(int, VarArgs + 8);
103 const char *Path = WASM_REF(char, WasmPath); 112 const char *Path = WASM_REF(char, WasmPath);
104 113
105 fprintf(stderr, "sys_open(%s, %d, %d)\n", Path, Flags, Mode); 114 fprintf(stderr, "sys_open(%s, %d, %d)\n", Path, Flags, Mode);
106 115
107 return open(Path, Flags, Mode); 116 return open(Path, Flags, Mode);
108 } 117 }
109 118
119 /// sys_getpid
120 int env$$__syscall20(int Which, int VarArgs) {
121 (void)Which;
122 (void)VarArgs;
123
124 return getpid();
125 }
126
110 /// sys_ioctl 127 /// sys_ioctl
111 int env$$__syscall54(int A, int B) { 128 int env$$__syscall54(int A, int B) {
112 int Fd = WASM_DEREF(int, B + 0 * sizeof(int)); 129 int Fd = WASM_DEREF(int, B + 0 * sizeof(int));
113 int Op = WASM_DEREF(int, B + 1 * sizeof(int)); 130 int Op = WASM_DEREF(int, B + 1 * sizeof(int));
114 int ArgP = WASM_DEREF(int, B + 2 * sizeof(int)); 131 int ArgP = WASM_DEREF(int, B + 2 * sizeof(int));
115 // TODO (eholk): implement sys_ioctl 132 // TODO (eholk): implement sys_ioctl
116 return -ENOTTY; 133 return -ENOTTY;
117 } 134 }
118 135
136 /// sys_write
119 int env$$__syscall146(int Which, int VarArgs) { 137 int env$$__syscall146(int Which, int VarArgs) {
120 fprintf(stderr, "syscall146\n");
121 138
122 int Fd = WASM_DEREF(int, VarArgs); 139 int Fd = WASM_DEREF(int, VarArgs);
123 int Iov = WASM_DEREF(int, VarArgs + sizeof(int)); 140 int Iov = WASM_DEREF(int, VarArgs + sizeof(int));
124 int Iovcnt = WASM_DEREF(int, VarArgs + 2 * sizeof(int)); 141 int Iovcnt = WASM_DEREF(int, VarArgs + 2 * sizeof(int));
125 142
126 fprintf(stderr, " Fd=%d, Iov=%d (%p), Iovcnt=%d\n", Fd, Iov, wasmPtr(Iov),
127 Iovcnt);
128
129 int Count = 0; 143 int Count = 0;
130 144
131 for (int I = 0; I < Iovcnt; ++I) { 145 for (int I = 0; I < Iovcnt; ++I) {
132 void *Ptr = WASM_REF(void, WASM_DEREF(int, Iov + I * 8)); 146 void *Ptr = WASM_REF(void, WASM_DEREF(int, Iov + I * 8));
133 int Length = WASM_DEREF(int, Iov + I * 8 + 4); 147 int Length = WASM_DEREF(int, Iov + I * 8 + 4);
134 148
135 fprintf(stderr, " [%d] write(%d, %p, %d) = ", I, Fd, Ptr, Length);
136 int Curr = write(Fd, Ptr, Length); 149 int Curr = write(Fd, Ptr, Length);
137 150
138 fprintf(stderr, "%d\n", Curr);
139
140 if (Curr < 0) { 151 if (Curr < 0) {
141 return -1; 152 return -1;
142 } 153 }
143 Count += Curr; 154 Count += Curr;
144 } 155 }
145 fprintf(stderr, " Count = %d\n", Count);
146 return Count; 156 return Count;
147 } 157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698