@@ -53,23 +53,23 @@ impl WasiFd {
5353 }
5454
5555 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) }
5757 }
5858
5959 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) }
6161 }
6262
6363 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) }
6565 }
6666
6767 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) }
6969 }
7070
7171 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) }
7373 }
7474
7575 pub fn seek ( & self , pos : SeekFrom ) -> io:: Result < u64 > {
@@ -78,37 +78,37 @@ impl WasiFd {
7878 SeekFrom :: End ( pos) => ( wasi:: WHENCE_END , pos) ,
7979 SeekFrom :: Current ( pos) => ( wasi:: WHENCE_CUR , pos) ,
8080 } ;
81- wasi:: fd_seek ( self . fd , offset, whence) . map_err ( err2io)
81+ unsafe { wasi:: fd_seek ( self . fd , offset, whence) . map_err ( err2io) }
8282 }
8383
8484 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) }
8686 }
8787
8888 // FIXME: __wasi_fd_fdstat_get
8989
9090 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) }
9292 }
9393
9494 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) }
9696 }
9797
9898 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) }
100100 }
101101
102102 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) }
104104 }
105105
106106 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) }
108108 }
109109
110110 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) }
112112 }
113113
114114 pub fn link (
@@ -118,8 +118,10 @@ impl WasiFd {
118118 new_fd : & WasiFd ,
119119 new_path : & [ u8 ] ,
120120 ) -> 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+ }
123125 }
124126
125127 pub fn open (
@@ -131,32 +133,35 @@ impl WasiFd {
131133 fs_rights_inheriting : wasi:: Rights ,
132134 fs_flags : wasi:: FdFlags ,
133135 ) -> 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+ }
143147 }
144148
145149 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) }
147151 }
148152
149153 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) }
151155 }
152156
153157 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+ }
156161 }
157162
158163 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) }
160165 }
161166
162167 pub fn filestat_set_times (
@@ -165,20 +170,21 @@ impl WasiFd {
165170 mtim : wasi:: Timestamp ,
166171 fstflags : wasi:: FstFlags ,
167172 ) -> 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+ }
170176 }
171177
172178 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) }
174180 }
175181
176182 pub fn path_filestat_get (
177183 & self ,
178184 flags : wasi:: LookupFlags ,
179185 path : & [ u8 ] ,
180186 ) -> 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) }
182188 }
183189
184190 pub fn path_filestat_set_times (
@@ -189,38 +195,40 @@ impl WasiFd {
189195 mtim : wasi:: Timestamp ,
190196 fstflags : wasi:: FstFlags ,
191197 ) -> 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+ }
200208 }
201209
202210 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) }
204212 }
205213
206214 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) }
208216 }
209217
210218 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) }
212220 }
213221
214222 pub fn sock_recv (
215223 & self ,
216224 ri_data : & mut [ IoSliceMut < ' _ > ] ,
217225 ri_flags : wasi:: RiFlags ,
218226 ) -> 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) }
220228 }
221229
222230 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) }
224232 }
225233
226234 pub fn sock_shutdown ( & self , how : Shutdown ) -> io:: Result < ( ) > {
@@ -229,14 +237,14 @@ impl WasiFd {
229237 Shutdown :: Write => wasi:: SHUT_WR ,
230238 Shutdown :: Both => wasi:: SHUT_WR | wasi:: SHUT_RD ,
231239 } ;
232- wasi:: sock_shutdown ( self . fd , how) . map_err ( err2io)
240+ unsafe { wasi:: sock_shutdown ( self . fd , how) . map_err ( err2io) }
233241 }
234242}
235243
236244impl Drop for WasiFd {
237245 fn drop ( & mut self ) {
238246 // FIXME: can we handle the return code here even though we can't on
239247 // unix?
240- let _ = wasi:: fd_close ( self . fd ) ;
248+ let _ = unsafe { wasi:: fd_close ( self . fd ) } ;
241249 }
242250}
0 commit comments