@@ -53,23 +53,23 @@ impl WasiFd {
53
53
}
54
54
55
55
pub fn datasync ( & self ) -> io:: Result < ( ) > {
56
- wasi:: fd_datasync ( self . fd ) . map_err ( err2io)
56
+ unsafe { wasi:: fd_datasync ( self . fd ) . map_err ( err2io) }
57
57
}
58
58
59
59
pub fn pread ( & self , bufs : & mut [ IoSliceMut < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
60
- wasi:: fd_pread ( self . fd , iovec ( bufs) , offset) . map_err ( err2io)
60
+ unsafe { wasi:: fd_pread ( self . fd , iovec ( bufs) , offset) . map_err ( err2io) }
61
61
}
62
62
63
63
pub fn pwrite ( & self , bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
64
- wasi:: fd_pwrite ( self . fd , ciovec ( bufs) , offset) . map_err ( err2io)
64
+ unsafe { wasi:: fd_pwrite ( self . fd , ciovec ( bufs) , offset) . map_err ( err2io) }
65
65
}
66
66
67
67
pub fn read ( & self , bufs : & mut [ IoSliceMut < ' _ > ] ) -> io:: Result < usize > {
68
- wasi:: fd_read ( self . fd , iovec ( bufs) ) . map_err ( err2io)
68
+ unsafe { wasi:: fd_read ( self . fd , iovec ( bufs) ) . map_err ( err2io) }
69
69
}
70
70
71
71
pub fn write ( & self , bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
72
- wasi:: fd_write ( self . fd , ciovec ( bufs) ) . map_err ( err2io)
72
+ unsafe { wasi:: fd_write ( self . fd , ciovec ( bufs) ) . map_err ( err2io) }
73
73
}
74
74
75
75
pub fn seek ( & self , pos : SeekFrom ) -> io:: Result < u64 > {
@@ -78,37 +78,37 @@ impl WasiFd {
78
78
SeekFrom :: End ( pos) => ( wasi:: WHENCE_END , pos) ,
79
79
SeekFrom :: Current ( pos) => ( wasi:: WHENCE_CUR , pos) ,
80
80
} ;
81
- wasi:: fd_seek ( self . fd , offset, whence) . map_err ( err2io)
81
+ unsafe { wasi:: fd_seek ( self . fd , offset, whence) . map_err ( err2io) }
82
82
}
83
83
84
84
pub fn tell ( & self ) -> io:: Result < u64 > {
85
- wasi:: fd_tell ( self . fd ) . map_err ( err2io)
85
+ unsafe { wasi:: fd_tell ( self . fd ) . map_err ( err2io) }
86
86
}
87
87
88
88
// FIXME: __wasi_fd_fdstat_get
89
89
90
90
pub fn set_flags ( & self , flags : wasi:: FdFlags ) -> io:: Result < ( ) > {
91
- wasi:: fd_fdstat_set_flags ( self . fd , flags) . map_err ( err2io)
91
+ unsafe { wasi:: fd_fdstat_set_flags ( self . fd , flags) . map_err ( err2io) }
92
92
}
93
93
94
94
pub fn set_rights ( & self , base : wasi:: Rights , inheriting : wasi:: Rights ) -> io:: Result < ( ) > {
95
- wasi:: fd_fdstat_set_rights ( self . fd , base, inheriting) . map_err ( err2io)
95
+ unsafe { wasi:: fd_fdstat_set_rights ( self . fd , base, inheriting) . map_err ( err2io) }
96
96
}
97
97
98
98
pub fn sync ( & self ) -> io:: Result < ( ) > {
99
- wasi:: fd_sync ( self . fd ) . map_err ( err2io)
99
+ unsafe { wasi:: fd_sync ( self . fd ) . map_err ( err2io) }
100
100
}
101
101
102
102
pub fn advise ( & self , offset : u64 , len : u64 , advice : wasi:: Advice ) -> io:: Result < ( ) > {
103
- wasi:: fd_advise ( self . fd , offset, len, advice) . map_err ( err2io)
103
+ unsafe { wasi:: fd_advise ( self . fd , offset, len, advice) . map_err ( err2io) }
104
104
}
105
105
106
106
pub fn allocate ( & self , offset : u64 , len : u64 ) -> io:: Result < ( ) > {
107
- wasi:: fd_allocate ( self . fd , offset, len) . map_err ( err2io)
107
+ unsafe { wasi:: fd_allocate ( self . fd , offset, len) . map_err ( err2io) }
108
108
}
109
109
110
110
pub fn create_directory ( & self , path : & [ u8 ] ) -> io:: Result < ( ) > {
111
- wasi:: path_create_directory ( self . fd , path) . map_err ( err2io)
111
+ unsafe { wasi:: path_create_directory ( self . fd , path) . map_err ( err2io) }
112
112
}
113
113
114
114
pub fn link (
@@ -118,8 +118,10 @@ impl WasiFd {
118
118
new_fd : & WasiFd ,
119
119
new_path : & [ u8 ] ,
120
120
) -> io:: Result < ( ) > {
121
- wasi:: path_link ( self . fd , old_flags, old_path, new_fd. fd , new_path)
122
- . map_err ( err2io)
121
+ unsafe {
122
+ wasi:: path_link ( self . fd , old_flags, old_path, new_fd. fd , new_path)
123
+ . map_err ( err2io)
124
+ }
123
125
}
124
126
125
127
pub fn open (
@@ -131,32 +133,35 @@ impl WasiFd {
131
133
fs_rights_inheriting : wasi:: Rights ,
132
134
fs_flags : wasi:: FdFlags ,
133
135
) -> io:: Result < WasiFd > {
134
- wasi:: path_open (
135
- self . fd ,
136
- dirflags,
137
- path,
138
- oflags,
139
- fs_rights_base,
140
- fs_rights_inheriting,
141
- fs_flags,
142
- ) . map ( |fd| unsafe { WasiFd :: from_raw ( fd) } ) . map_err ( err2io)
136
+ unsafe {
137
+ wasi:: path_open (
138
+ self . fd ,
139
+ dirflags,
140
+ path,
141
+ oflags,
142
+ fs_rights_base,
143
+ fs_rights_inheriting,
144
+ fs_flags,
145
+ ) . map ( |fd| WasiFd :: from_raw ( fd) ) . map_err ( err2io)
146
+ }
143
147
}
144
148
145
149
pub fn readdir ( & self , buf : & mut [ u8 ] , cookie : wasi:: DirCookie ) -> io:: Result < usize > {
146
- wasi:: fd_readdir ( self . fd , buf, cookie) . map_err ( err2io)
150
+ unsafe { wasi:: fd_readdir ( self . fd , buf, cookie) . map_err ( err2io) }
147
151
}
148
152
149
153
pub fn readlink ( & self , path : & [ u8 ] , buf : & mut [ u8 ] ) -> io:: Result < usize > {
150
- wasi:: path_readlink ( self . fd , path, buf) . map_err ( err2io)
154
+ unsafe { wasi:: path_readlink ( self . fd , path, buf) . map_err ( err2io) }
151
155
}
152
156
153
157
pub fn rename ( & self , old_path : & [ u8 ] , new_fd : & WasiFd , new_path : & [ u8 ] ) -> io:: Result < ( ) > {
154
- wasi:: path_rename ( self . fd , old_path, new_fd. fd , new_path)
155
- . map_err ( err2io)
158
+ unsafe {
159
+ wasi:: path_rename ( self . fd , old_path, new_fd. fd , new_path) . map_err ( err2io)
160
+ }
156
161
}
157
162
158
163
pub fn filestat_get ( & self ) -> io:: Result < wasi:: FileStat > {
159
- wasi:: fd_filestat_get ( self . fd ) . map_err ( err2io)
164
+ unsafe { wasi:: fd_filestat_get ( self . fd ) . map_err ( err2io) }
160
165
}
161
166
162
167
pub fn filestat_set_times (
@@ -165,20 +170,21 @@ impl WasiFd {
165
170
mtim : wasi:: Timestamp ,
166
171
fstflags : wasi:: FstFlags ,
167
172
) -> io:: Result < ( ) > {
168
- wasi:: fd_filestat_set_times ( self . fd , atim, mtim, fstflags)
169
- . map_err ( err2io)
173
+ unsafe {
174
+ wasi:: fd_filestat_set_times ( self . fd , atim, mtim, fstflags) . map_err ( err2io)
175
+ }
170
176
}
171
177
172
178
pub fn filestat_set_size ( & self , size : u64 ) -> io:: Result < ( ) > {
173
- wasi:: fd_filestat_set_size ( self . fd , size) . map_err ( err2io)
179
+ unsafe { wasi:: fd_filestat_set_size ( self . fd , size) . map_err ( err2io) }
174
180
}
175
181
176
182
pub fn path_filestat_get (
177
183
& self ,
178
184
flags : wasi:: LookupFlags ,
179
185
path : & [ u8 ] ,
180
186
) -> io:: Result < wasi:: FileStat > {
181
- wasi:: path_filestat_get ( self . fd , flags, path) . map_err ( err2io)
187
+ unsafe { wasi:: path_filestat_get ( self . fd , flags, path) . map_err ( err2io) }
182
188
}
183
189
184
190
pub fn path_filestat_set_times (
@@ -189,38 +195,40 @@ impl WasiFd {
189
195
mtim : wasi:: Timestamp ,
190
196
fstflags : wasi:: FstFlags ,
191
197
) -> io:: Result < ( ) > {
192
- wasi:: path_filestat_set_times (
193
- self . fd ,
194
- flags,
195
- path,
196
- atim,
197
- mtim,
198
- fstflags,
199
- ) . map_err ( err2io)
198
+ unsafe {
199
+ wasi:: path_filestat_set_times (
200
+ self . fd ,
201
+ flags,
202
+ path,
203
+ atim,
204
+ mtim,
205
+ fstflags,
206
+ ) . map_err ( err2io)
207
+ }
200
208
}
201
209
202
210
pub fn symlink ( & self , old_path : & [ u8 ] , new_path : & [ u8 ] ) -> io:: Result < ( ) > {
203
- wasi:: path_symlink ( old_path, self . fd , new_path) . map_err ( err2io)
211
+ unsafe { wasi:: path_symlink ( old_path, self . fd , new_path) . map_err ( err2io) }
204
212
}
205
213
206
214
pub fn unlink_file ( & self , path : & [ u8 ] ) -> io:: Result < ( ) > {
207
- wasi:: path_unlink_file ( self . fd , path) . map_err ( err2io)
215
+ unsafe { wasi:: path_unlink_file ( self . fd , path) . map_err ( err2io) }
208
216
}
209
217
210
218
pub fn remove_directory ( & self , path : & [ u8 ] ) -> io:: Result < ( ) > {
211
- wasi:: path_remove_directory ( self . fd , path) . map_err ( err2io)
219
+ unsafe { wasi:: path_remove_directory ( self . fd , path) . map_err ( err2io) }
212
220
}
213
221
214
222
pub fn sock_recv (
215
223
& self ,
216
224
ri_data : & mut [ IoSliceMut < ' _ > ] ,
217
225
ri_flags : wasi:: RiFlags ,
218
226
) -> io:: Result < ( usize , wasi:: RoFlags ) > {
219
- wasi:: sock_recv ( self . fd , iovec ( ri_data) , ri_flags) . map_err ( err2io)
227
+ unsafe { wasi:: sock_recv ( self . fd , iovec ( ri_data) , ri_flags) . map_err ( err2io) }
220
228
}
221
229
222
230
pub fn sock_send ( & self , si_data : & [ IoSlice < ' _ > ] , si_flags : wasi:: SiFlags ) -> io:: Result < usize > {
223
- wasi:: sock_send ( self . fd , ciovec ( si_data) , si_flags) . map_err ( err2io)
231
+ unsafe { wasi:: sock_send ( self . fd , ciovec ( si_data) , si_flags) . map_err ( err2io) }
224
232
}
225
233
226
234
pub fn sock_shutdown ( & self , how : Shutdown ) -> io:: Result < ( ) > {
@@ -229,14 +237,14 @@ impl WasiFd {
229
237
Shutdown :: Write => wasi:: SHUT_WR ,
230
238
Shutdown :: Both => wasi:: SHUT_WR | wasi:: SHUT_RD ,
231
239
} ;
232
- wasi:: sock_shutdown ( self . fd , how) . map_err ( err2io)
240
+ unsafe { wasi:: sock_shutdown ( self . fd , how) . map_err ( err2io) }
233
241
}
234
242
}
235
243
236
244
impl Drop for WasiFd {
237
245
fn drop ( & mut self ) {
238
246
// FIXME: can we handle the return code here even though we can't on
239
247
// unix?
240
- let _ = wasi:: fd_close ( self . fd ) ;
248
+ let _ = unsafe { wasi:: fd_close ( self . fd ) } ;
241
249
}
242
250
}
0 commit comments