@@ -33,12 +33,13 @@ use crate::stackswitch::*;
3333use crate :: { RunResult , RuntimeFiberStack } ;
3434use std:: boxed:: Box ;
3535use std:: cell:: Cell ;
36- use std:: io;
3736use std:: ops:: Range ;
3837use std:: ptr;
3938use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
39+ use wasmtime_environ:: error:: { OutOfMemory , Result } ;
40+ use wasmtime_environ:: prelude:: * ;
4041
41- pub type Error = io :: Error ;
42+ pub type Error = wasmtime_environ :: error :: Error ;
4243
4344pub struct FiberStack {
4445 base : BasePtr ,
@@ -78,7 +79,7 @@ fn host_page_size() -> usize {
7879}
7980
8081impl FiberStack {
81- pub fn new ( size : usize , zeroed : bool ) -> io :: Result < Self > {
82+ pub fn new ( size : usize , zeroed : bool ) -> Result < Self > {
8283 let page_size = host_page_size ( ) ;
8384 // The anonymous `mmap`s we use for `FiberStackStorage` are always
8485 // zeroed.
@@ -101,7 +102,7 @@ impl FiberStack {
101102 } )
102103 }
103104
104- pub unsafe fn from_raw_parts ( base : * mut u8 , guard_size : usize , len : usize ) -> io :: Result < Self > {
105+ pub unsafe fn from_raw_parts ( base : * mut u8 , guard_size : usize , len : usize ) -> Result < Self > {
105106 // See comments in `mod asan` below for why asan has a different stack
106107 // allocation strategy.
107108 if cfg ! ( asan) {
@@ -118,7 +119,7 @@ impl FiberStack {
118119 matches ! ( self . storage, FiberStackStorage :: Unmanaged ( _) )
119120 }
120121
121- pub fn from_custom ( custom : Box < dyn RuntimeFiberStack > ) -> io :: Result < Self > {
122+ pub fn from_custom ( custom : Box < dyn RuntimeFiberStack > ) -> Result < Self > {
122123 let range = custom. range ( ) ;
123124 let page_size = host_page_size ( ) ;
124125 let start_ptr = range. start as * mut u8 ;
@@ -168,7 +169,7 @@ unsafe impl Send for MmapFiberStack {}
168169unsafe impl Sync for MmapFiberStack { }
169170
170171impl MmapFiberStack {
171- fn new ( size : usize ) -> io :: Result < Self > {
172+ fn new ( size : usize ) -> Result < Self > {
172173 // Round up our stack size request to the nearest multiple of the
173174 // page size.
174175 let page_size = host_page_size ( ) ;
@@ -177,7 +178,7 @@ impl MmapFiberStack {
177178 } else {
178179 let with_extra = size
179180 . checked_add ( page_size - 1 )
180- . ok_or ( io :: ErrorKind :: OutOfMemory ) ?;
181+ . ok_or_else ( || OutOfMemory :: new ( usize :: MAX ) ) ?;
181182 with_extra & ( !( page_size - 1 ) )
182183 } ;
183184
@@ -243,20 +244,17 @@ where
243244}
244245
245246impl Fiber {
246- pub fn new < F , A , B , C > ( stack : & FiberStack , func : F ) -> io :: Result < Self >
247+ pub fn new < F , A , B , C > ( stack : & FiberStack , func : F ) -> Result < Self >
247248 where
248249 F : FnOnce ( A , & mut super :: Suspend < A , B , C > ) -> C ,
249250 {
250251 // On unsupported platforms `wasmtime_fiber_init` is a panicking shim so
251252 // return an error saying the host architecture isn't supported instead.
252253 if !SUPPORTED_ARCH {
253- return Err ( io:: Error :: new (
254- io:: ErrorKind :: Other ,
255- "fibers not supported on this host architecture" ,
256- ) ) ;
254+ bail ! ( "fibers not supported on this host architecture" ) ;
257255 }
258256 unsafe {
259- let data = Box :: into_raw ( Box :: new ( func) ) . cast ( ) ;
257+ let data = Box :: into_raw ( try_new :: < Box < _ > > ( func) ? ) . cast ( ) ;
260258 wasmtime_fiber_init ( stack. top ( ) . unwrap ( ) , fiber_start :: < F , A , B , C > , data) ;
261259 }
262260
@@ -330,7 +328,7 @@ impl Suspend {
330328/// called around every stack switch with some other fiddly bits as well.
331329#[ cfg( asan) ]
332330mod asan {
333- use super :: { FiberStack , MmapFiberStack , RuntimeFiberStack , host_page_size } ;
331+ use super :: * ;
334332 use alloc:: boxed:: Box ;
335333 use alloc:: vec:: Vec ;
336334 use std:: mem:: ManuallyDrop ;
@@ -442,11 +440,11 @@ mod asan {
442440 /// meaning that this should only ever be a relatively small set of stacks.
443441 static FIBER_STACKS : Mutex < Vec < MmapFiberStack > > = Mutex :: new ( Vec :: new ( ) ) ;
444442
445- pub fn new_fiber_stack ( size : usize ) -> std :: io :: Result < Box < dyn RuntimeFiberStack > > {
443+ pub fn new_fiber_stack ( size : usize ) -> Result < Box < dyn RuntimeFiberStack > > {
446444 let page_size = host_page_size ( ) ;
447445 let needed_size = size
448446 . checked_add ( page_size)
449- . ok_or ( std :: io :: ErrorKind :: OutOfMemory ) ?;
447+ . ok_or_else ( || OutOfMemory :: new ( usize :: MAX ) ) ?;
450448 let mut stacks = FIBER_STACKS . lock ( ) . unwrap ( ) ;
451449
452450 let stack = match stacks. iter ( ) . position ( |i| needed_size <= i. mapping_len ) {
@@ -500,7 +498,7 @@ mod asan {
500498// Shim module that's the same as above but only has stubs.
501499#[ cfg( not( asan) ) ]
502500mod asan_disabled {
503- use super :: { FiberStack , RuntimeFiberStack } ;
501+ use super :: * ;
504502 use std:: boxed:: Box ;
505503
506504 #[ derive( Default ) ]
@@ -527,7 +525,7 @@ mod asan_disabled {
527525 PreviousStack
528526 }
529527
530- pub fn new_fiber_stack ( _size : usize ) -> std :: io :: Result < Box < dyn RuntimeFiberStack > > {
528+ pub fn new_fiber_stack ( _size : usize ) -> Result < Box < dyn RuntimeFiberStack > > {
531529 unimplemented ! ( )
532530 }
533531}
0 commit comments