6
6
7
7
package runtime
8
8
9
- import "unsafe"
9
+ import (
10
+ "structs"
11
+ "unsafe"
12
+ )
10
13
11
14
// GOARCH=wasm currently has 64 bits pointers, but the WebAssembly host expects
12
15
// pointers to be 32 bits so we use this type alias to represent pointers in
@@ -48,31 +51,31 @@ func exit(code int32)
48
51
49
52
//go:wasmimport wasi_snapshot_preview1 args_get
50
53
//go:noescape
51
- func args_get (argv , argvBuf unsafe. Pointer ) errno
54
+ func args_get (argv * uintptr32 , argvBuf * byte ) errno
52
55
53
56
//go:wasmimport wasi_snapshot_preview1 args_sizes_get
54
57
//go:noescape
55
- func args_sizes_get (argc , argvBufLen unsafe. Pointer ) errno
58
+ func args_sizes_get (argc , argvBufLen * size ) errno
56
59
57
60
//go:wasmimport wasi_snapshot_preview1 clock_time_get
58
61
//go:noescape
59
- func clock_time_get (clock_id clockid , precision timestamp , time unsafe. Pointer ) errno
62
+ func clock_time_get (clock_id clockid , precision timestamp , time * timestamp ) errno
60
63
61
64
//go:wasmimport wasi_snapshot_preview1 environ_get
62
65
//go:noescape
63
- func environ_get (environ , environBuf unsafe. Pointer ) errno
66
+ func environ_get (environ * uintptr32 , environBuf * byte ) errno
64
67
65
68
//go:wasmimport wasi_snapshot_preview1 environ_sizes_get
66
69
//go:noescape
67
- func environ_sizes_get (environCount , environBufLen unsafe. Pointer ) errno
70
+ func environ_sizes_get (environCount , environBufLen * size ) errno
68
71
69
72
//go:wasmimport wasi_snapshot_preview1 fd_write
70
73
//go:noescape
71
- func fd_write (fd int32 , iovs unsafe.Pointer , iovsLen size , nwritten unsafe. Pointer ) errno
74
+ func fd_write (fd int32 , iovs unsafe.Pointer , iovsLen size , nwritten * size ) errno
72
75
73
76
//go:wasmimport wasi_snapshot_preview1 random_get
74
77
//go:noescape
75
- func random_get (buf unsafe. Pointer , bufLen size ) errno
78
+ func random_get (buf * byte , bufLen size ) errno
76
79
77
80
type eventtype = uint8
78
81
@@ -99,13 +102,15 @@ type userdata = uint64
99
102
// struct size because errno is declared as a 32 bits type, so we declare the
100
103
// error field as a plain uint16.
101
104
type event struct {
105
+ _ structs.HostLayout
102
106
userdata userdata
103
107
error uint16
104
108
typ eventtype
105
109
fdReadwrite eventFdReadwrite
106
110
}
107
111
108
112
type eventFdReadwrite struct {
113
+ _ structs.HostLayout
109
114
nbytes filesize
110
115
flags eventrwflags
111
116
}
@@ -117,17 +122,20 @@ const (
117
122
)
118
123
119
124
type subscriptionClock struct {
125
+ _ structs.HostLayout
120
126
id clockid
121
127
timeout timestamp
122
128
precision timestamp
123
129
flags subclockflags
124
130
}
125
131
126
132
type subscriptionFdReadwrite struct {
133
+ _ structs.HostLayout
127
134
fd int32
128
135
}
129
136
130
137
type subscription struct {
138
+ _ structs.HostLayout
131
139
userdata userdata
132
140
u subscriptionUnion
133
141
}
@@ -148,15 +156,15 @@ func (u *subscriptionUnion) subscriptionFdReadwrite() *subscriptionFdReadwrite {
148
156
149
157
//go:wasmimport wasi_snapshot_preview1 poll_oneoff
150
158
//go:noescape
151
- func poll_oneoff (in , out unsafe. Pointer , nsubscriptions size , nevents unsafe. Pointer ) errno
159
+ func poll_oneoff (in * subscription , out * event , nsubscriptions size , nevents * size ) errno
152
160
153
161
func write1 (fd uintptr , p unsafe.Pointer , n int32 ) int32 {
154
162
iov := iovec {
155
163
buf : uintptr32 (uintptr (p )),
156
164
bufLen : size (n ),
157
165
}
158
166
var nwritten size
159
- if fd_write (int32 (fd ), unsafe .Pointer (& iov ), 1 , unsafe . Pointer ( & nwritten ) ) != 0 {
167
+ if fd_write (int32 (fd ), unsafe .Pointer (& iov ), 1 , & nwritten ) != 0 {
160
168
throw ("fd_write failed" )
161
169
}
162
170
return int32 (nwritten )
@@ -175,13 +183,13 @@ func usleep(usec uint32) {
175
183
subscription .timeout = timestamp (usec ) * 1e3
176
184
subscription .precision = 1e3
177
185
178
- if poll_oneoff (unsafe . Pointer ( & in ), unsafe . Pointer ( & out ) , 1 , unsafe . Pointer ( & nevents ) ) != 0 {
186
+ if poll_oneoff (& in , & out , 1 , & nevents ) != 0 {
179
187
throw ("wasi_snapshot_preview1.poll_oneoff" )
180
188
}
181
189
}
182
190
183
191
func readRandom (r []byte ) int {
184
- if random_get (unsafe . Pointer ( & r [0 ]) , size (len (r ))) != 0 {
192
+ if random_get (& r [0 ], size (len (r ))) != 0 {
185
193
return 0
186
194
}
187
195
return len (r )
@@ -191,15 +199,15 @@ func goenvs() {
191
199
// arguments
192
200
var argc size
193
201
var argvBufLen size
194
- if args_sizes_get (unsafe . Pointer ( & argc ), unsafe . Pointer ( & argvBufLen ) ) != 0 {
202
+ if args_sizes_get (& argc , & argvBufLen ) != 0 {
195
203
throw ("args_sizes_get failed" )
196
204
}
197
205
198
206
argslice = make ([]string , argc )
199
207
if argc > 0 {
200
208
argv := make ([]uintptr32 , argc )
201
209
argvBuf := make ([]byte , argvBufLen )
202
- if args_get (unsafe . Pointer ( & argv [0 ]), unsafe . Pointer ( & argvBuf [0 ]) ) != 0 {
210
+ if args_get (& argv [0 ], & argvBuf [0 ]) != 0 {
203
211
throw ("args_get failed" )
204
212
}
205
213
@@ -216,15 +224,15 @@ func goenvs() {
216
224
// environment
217
225
var environCount size
218
226
var environBufLen size
219
- if environ_sizes_get (unsafe . Pointer ( & environCount ), unsafe . Pointer ( & environBufLen ) ) != 0 {
227
+ if environ_sizes_get (& environCount , & environBufLen ) != 0 {
220
228
throw ("environ_sizes_get failed" )
221
229
}
222
230
223
231
envs = make ([]string , environCount )
224
232
if environCount > 0 {
225
233
environ := make ([]uintptr32 , environCount )
226
234
environBuf := make ([]byte , environBufLen )
227
- if environ_get (unsafe . Pointer ( & environ [0 ]), unsafe . Pointer ( & environBuf [0 ]) ) != 0 {
235
+ if environ_get (& environ [0 ], & environBuf [0 ]) != 0 {
228
236
throw ("environ_get failed" )
229
237
}
230
238
@@ -245,15 +253,15 @@ func walltime() (sec int64, nsec int32) {
245
253
246
254
func walltime1 () (sec int64 , nsec int32 ) {
247
255
var time timestamp
248
- if clock_time_get (clockRealtime , 0 , unsafe . Pointer ( & time ) ) != 0 {
256
+ if clock_time_get (clockRealtime , 0 , & time ) != 0 {
249
257
throw ("clock_time_get failed" )
250
258
}
251
259
return int64 (time / 1000000000 ), int32 (time % 1000000000 )
252
260
}
253
261
254
262
func nanotime1 () int64 {
255
263
var time timestamp
256
- if clock_time_get (clockMonotonic , 0 , unsafe . Pointer ( & time ) ) != 0 {
264
+ if clock_time_get (clockMonotonic , 0 , & time ) != 0 {
257
265
throw ("clock_time_get failed" )
258
266
}
259
267
return int64 (time )
0 commit comments