@@ -7,6 +7,8 @@ use crate::{catch, warn};
77use corosensei:: stack:: { DefaultStack , Stack } ;
88use corosensei:: trap:: TrapHandlerRegs ;
99use corosensei:: CoroutineResult ;
10+ #[ cfg( all( any( target_os = "linux" , target_os = "android" ) , target_arch = "x86" ) ) ]
11+ use num_conv:: CastUnsigned ;
1012use std:: cell:: { Cell , RefCell , UnsafeCell } ;
1113use std:: collections:: VecDeque ;
1214use std:: ffi:: c_longlong;
@@ -57,7 +59,7 @@ impl<'c, Param, Yield, Return> Coroutine<'c, Param, Yield, Return> {
5759 any( target_os = "linux" , target_os = "android" ) ,
5860 target_arch = "x86" ,
5961 ) ) ] {
60- let sp = u64 :: from ( std :: mem :: transmute :: <_ , std :: ffi :: c_uint> ( context. uc_mcontext. gregs[ usize :: try_from( libc:: REG_ESP ) . expect( "overflow" ) ] ) ) ;
62+ let sp = u64 :: cast_unsigned ( context. uc_mcontext. gregs[ usize :: try_from( libc:: REG_ESP ) . expect( "overflow" ) ] . try_into ( ) . unwrap ( ) ) ;
6163 } else if #[ cfg( all( target_vendor = "apple" , target_arch = "x86_64" ) ) ] {
6264 let sp = u64 :: try_from( ( * context. uc_mcontext) . __ss. __rsp) . expect( "overflow" ) ;
6365 } else if #[ cfg( all(
@@ -108,11 +110,11 @@ impl<'c, Param, Yield, Return> Coroutine<'c, Param, Yield, Return> {
108110 target_arch = "x86" ,
109111 ) ) ] {
110112 let TrapHandlerRegs { eip, esp, ebp, ecx, edx } = regs;
111- context. uc_mcontext. gregs[ usize :: try_from( libc:: REG_EIP ) . expect( "overflow" ) ] = std :: mem :: transmute ( eip) ;
112- context. uc_mcontext. gregs[ usize :: try_from( libc:: REG_ESP ) . expect( "overflow" ) ] = std :: mem :: transmute ( esp) ;
113- context. uc_mcontext. gregs[ usize :: try_from( libc:: REG_EBP ) . expect( "overflow" ) ] = std :: mem :: transmute ( ebp) ;
114- context. uc_mcontext. gregs[ usize :: try_from( libc:: REG_ECX ) . expect( "overflow" ) ] = std :: mem :: transmute ( ecx) ;
115- context. uc_mcontext. gregs[ usize :: try_from( libc:: REG_EDX ) . expect( "overflow" ) ] = std :: mem :: transmute ( edx) ;
113+ context. uc_mcontext. gregs[ usize :: try_from( libc:: REG_EIP ) . expect( "overflow" ) ] = u32 :: cast_signed ( eip) ;
114+ context. uc_mcontext. gregs[ usize :: try_from( libc:: REG_ESP ) . expect( "overflow" ) ] = u32 :: cast_signed ( esp) ;
115+ context. uc_mcontext. gregs[ usize :: try_from( libc:: REG_EBP ) . expect( "overflow" ) ] = u32 :: cast_signed ( ebp) ;
116+ context. uc_mcontext. gregs[ usize :: try_from( libc:: REG_ECX ) . expect( "overflow" ) ] = u32 :: cast_signed ( ecx) ;
117+ context. uc_mcontext. gregs[ usize :: try_from( libc:: REG_EDX ) . expect( "overflow" ) ] = u32 :: cast_signed ( edx) ;
116118 } else if #[ cfg( all( target_vendor = "apple" , target_arch = "x86_64" ) ) ] {
117119 let TrapHandlerRegs { rip, rsp, rbp, rdi, rsi } = regs;
118120 ( * context. uc_mcontext) . __ss. __rip = rip;
0 commit comments