example-greenthreads icon indicating copy to clipboard operation
example-greenthreads copied to clipboard

fixbug

Open PeterWrighten opened this issue 1 year ago • 3 comments

  • The asm code call switch doesn't work in macOS, it should be call _switch
  • Add rust-toochain

PeterWrighten avatar Jul 12 '22 17:07 PeterWrighten

Ah, tanks.

I forgot that macos prepend subroutines with "_" even when no_mangle is specified.

However, I think for the code to work on both linux and macos we need conditional compilation since I believe the suggestion will not work on linux anymore (it will try to call _shwitch which will not exist since linux doesn't prepend the function name with "_").

I don't have access to a mac at the moment, but if you have the opporunity to try the code on linux and confirm (I guess the playground could work)? If I'm correct then I think we need to do something like this:

#[cfg(not(target_os = "macos"))]
asm!("call switch", in("rdi") old, in("rsi") new, clobber_abi("C"));
#[cfg(target_os = "macos")]
asm!("call _switch", in("rdi") old, in("rsi") new, clobber_abi("C"));

cfsamson avatar Jul 14 '22 23:07 cfsamson

Ah, tanks.

I forgot that macos prepend subroutines with "_" even when no_mangle is specified.

However, I think for the code to work on both linux and macos we need conditional compilation since I believe the suggestion will not work on linux anymore (it will try to call _shwitch which will not exist since linux doesn't prepend the function name with "_").

I don't have access to a mac at the moment, but if you have the opporunity to try the code on linux and confirm (I guess the playground could work)? If I'm correct then I think we need to do something like this:

#[cfg(not(target_os = "macos"))]
asm!("call switch", in("rdi") old, in("rsi") new, clobber_abi("C"));
#[cfg(target_os = "macos")]
asm!("call _switch", in("rdi") old, in("rsi") new, clobber_abi("C"));

OK, I would try it later. (Sorry for my late reply...)

PeterWrighten avatar Jul 20 '22 03:07 PeterWrighten

@cfsamson Hi, Sir, I have modified and add #[cfg] flag, I also try it on both macOS and Ubuntu, and it works so well.

PeterWrighten avatar Jul 21 '22 11:07 PeterWrighten

Sorry for the delay. Thanks 👍

cfsamson avatar Aug 11 '22 08:08 cfsamson