-
Notifications
You must be signed in to change notification settings - Fork 217
Add libsetjmp.a/so #483
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
Merged
Merged
Add libsetjmp.a/so #483
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
typedef unsigned long __jmp_buf[8]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* a runtime implementation for | ||
* https://github.com/llvm/llvm-project/pull/84137 | ||
* https://docs.google.com/document/d/1ZvTPT36K5jjiedF8MCXbEmYjULJjI723aOAks1IdLLg/edit | ||
*/ | ||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
|
||
/* | ||
* function prototypes | ||
*/ | ||
void __wasm_setjmp(void *env, uint32_t label, void *func_invocation_id); | ||
uint32_t __wasm_setjmp_test(void *env, void *func_invocation_id); | ||
void __wasm_longjmp(void *env, int val); | ||
|
||
/* | ||
* jmp_buf should have large enough size and alignment to contain | ||
* this structure. | ||
*/ | ||
struct jmp_buf_impl { | ||
void *func_invocation_id; | ||
uint32_t label; | ||
|
||
/* | ||
* this is a temorary storage used by the communication between | ||
* __wasm_sjlj_longjmp and WebAssemblyLowerEmscriptenEHSjL-generated | ||
* logic. | ||
* ideally, this can be replaced with multivalue. | ||
*/ | ||
struct arg { | ||
void *env; | ||
int val; | ||
} arg; | ||
}; | ||
|
||
void | ||
__wasm_setjmp(void *env, uint32_t label, void *func_invocation_id) | ||
{ | ||
struct jmp_buf_impl *jb = env; | ||
if (label == 0) { /* ABI contract */ | ||
__builtin_trap(); | ||
} | ||
if (func_invocation_id == NULL) { /* sanity check */ | ||
__builtin_trap(); | ||
} | ||
jb->func_invocation_id = func_invocation_id; | ||
jb->label = label; | ||
} | ||
|
||
uint32_t | ||
__wasm_setjmp_test(void *env, void *func_invocation_id) | ||
{ | ||
struct jmp_buf_impl *jb = env; | ||
if (jb->label == 0) { /* ABI contract */ | ||
__builtin_trap(); | ||
} | ||
if (func_invocation_id == NULL) { /* sanity check */ | ||
__builtin_trap(); | ||
} | ||
if (jb->func_invocation_id == func_invocation_id) { | ||
return jb->label; | ||
} | ||
return 0; | ||
} | ||
|
||
void | ||
__wasm_longjmp(void *env, int val) | ||
{ | ||
struct jmp_buf_impl *jb = env; | ||
struct arg *arg = &jb->arg; | ||
/* | ||
* C standard says: | ||
* The longjmp function cannot cause the setjmp macro to return | ||
* the value 0; if val is 0, the setjmp macro returns the value 1. | ||
*/ | ||
if (val == 0) { | ||
val = 1; | ||
} | ||
arg->env = env; | ||
arg->val = val; | ||
__builtin_wasm_throw(1, arg); /* 1 == C_LONGJMP */ | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we should copy the content of this into the tool-conventions repo. Would you be interested in doing this, or would you mind if I did it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree we should document in the tool-conventions repo.
i think i can write something next month.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wrote something. WebAssembly/tool-conventions#225