Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setjmp support #490

Closed
calvin2021y opened this issue Jul 21, 2022 · 4 comments
Closed

setjmp support #490

calvin2021y opened this issue Jul 21, 2022 · 4 comments

Comments

@calvin2021y
Copy link

calvin2021y commented Jul 21, 2022

current sdk ./share/wasi-sysroot/include/c++/v1/setjmp.h is not working.

please share the roadmap for this sdk to support setjmp, I want use it in https://github.com/protocolbuffers/upb

@sunfishcode
Copy link
Member

The current plan is to wait for the exception-handling proposal to be standardized and implemented in wasm engines, and then to implement setjmp and longjmp using that feature. Exception-handling is currently in phase 3.

Another option would be to define a host API which performs stack unwinding. We've so far not pursued this approach, because that would be a lot of complex work for non-JS host API implementors, for what would ultimately be a temporary workaround. And, such an API would not be virtualizable, and would raise complex questions about non-C-language unwinding which the exception-handling proposal already has answers for.

adamziel added a commit to WordPress/wordpress-playground that referenced this issue Jan 14, 2023
This commit explores using the wasmenv toolkit to compile PHP.
The configure phase works, but the make fails because setjmp is
unsupported yet, see the error message below and the relevant
GitHub issue at WebAssembly/WASI#490

There's a chance "make" would work if we tried a dedicated libc build:

   https://github.com/WebAssembly/wasi-libc/blob/main/libc-top-half/musl/include/setjmp.h

I'm not sure if the final PHP build would be functional, though.

Either way, building using wasi-sdk which has libc and set_jmp.h baked
in would be a sensible next step:

https://github.com/WebAssembly/wasi-sdk/releases

31 69.49 /root/php-src/main/setjmp.h:44:2: warning: setjmp is not yet implemented for WASI [-W#warnings]
31 69.49 #warning setjmp is not yet implemented for WASI
31 69.49  ^
31 69.56 In file included from /root/php-src/ext/bcmath/libbcmath/src/div.c:32:
31 69.56 In file included from /root/php-src/ext/bcmath/libbcmath/src/config.h:7:
31 69.56 In file included from /root/php-src/main/php.h:35:
31 69.56 In file included from /root/php-src/Zend/zend_API.h:25:
31 69.56 In file included from /root/php-src/Zend/zend_modules.h:24:
31 69.56 In file included from /root/php-src/Zend/zend_compile.h:724:
31 69.56 /root/php-src/Zend/zend_globals.h:151:2: error: unknown type name 'jmp_buf'
31 69.56         JMP_BUF *bailout;
31 69.56         ^
31 69.56 /root/php-src/Zend/zend_portability.h:361:18: note: expanded from macro 'JMP_BUF'
31 69.56 # define JMP_BUF jmp_buf
@sunfishcode
Copy link
Member

The original question is answered; please file new issues for any further questions!

@namse
Copy link

namse commented May 27, 2024

@sunfishcode According to WebAssembly/exception-handling#179, it seems that most browsers have completed the implementation. It's in Phase 3, but since the implementation has been completed, would it be okay to provide support for it?

@sunfishcode
Copy link
Member

Yes, an implementation is now merged into wasi-libc in WebAssembly/wasi-libc#483.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants