forked from vlang/v
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
builtin,coroutines,cgen: fix using coroutines with boehm GC, by using…
… a stack pointer corrector (vlang#20771)
- Loading branch information
1 parent
215ab13
commit 212adfa
Showing
4 changed files
with
95 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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 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 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,32 @@ | ||
// TODO: convert this to v code? handle all platforms | ||
// currently if it's not macos or win it defaults to the linux impl | ||
|
||
static void sp_corrector(void** sp_ptr, void* tid) { | ||
size_t stack_size; | ||
char* stack_addr; | ||
#ifdef __APPLE__ | ||
stack_size = pthread_get_stacksize_np((pthread_t)tid); | ||
stack_addr = (char*) pthread_get_stackaddr_np((pthread_t)tid); | ||
#elif defined(_WIN64) | ||
ULONG_PTR stack_low, stack_high; | ||
GetCurrentThreadStackLimits(&stack_low, &stack_high); | ||
stack_size = stack_high - stack_low; | ||
stack_addr = (char*)stack_low; | ||
// #elif defined(__linux__) | ||
// pthread_attr_t gattr; | ||
// pthread_getattr_np((pthread_t)tid, &gattr); | ||
// pthread_attr_getstack(&gattr, (void**)&stack_addr, &stack_size); | ||
// pthread_attr_destroy(&gattr); | ||
// #else | ||
// assert("unsupported platform"); | ||
#else | ||
pthread_attr_t gattr; | ||
pthread_getattr_np((pthread_t)tid, &gattr); | ||
pthread_attr_getstack(&gattr, (void**)&stack_addr, &stack_size); | ||
pthread_attr_destroy(&gattr); | ||
#endif | ||
char sp = (char)*sp_ptr; | ||
if(sp <= stack_addr || sp >= stack_addr+stack_size) { | ||
*sp_ptr = (void*)stack_addr; | ||
} | ||
} |
This file contains 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