mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Use VirtualAlloc/VirtualProtect/VirtualFree for windows stack allocation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65909 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e7d919d265
commit
38f7bb481e
1 changed files with 63 additions and 53 deletions
24
cont.c
24
cont.c
|
@ -416,10 +416,11 @@ cont_free(void *ptr)
|
|||
rb_bug("Illegal root fiber parameter");
|
||||
}
|
||||
#ifdef _WIN32
|
||||
free((void*)fib->ss_sp);
|
||||
VirtualFree((void*)fib->ss_sp, 0, MEM_RELEASE);
|
||||
#else
|
||||
munmap((void*)fib->ss_sp, fib->ss_size);
|
||||
#endif
|
||||
fib->ss_sp = NULL;
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
if (!fiber_is_root_p(fib)) {
|
||||
|
@ -870,6 +871,9 @@ static char*
|
|||
fiber_machine_stack_alloc(size_t size)
|
||||
{
|
||||
char *ptr;
|
||||
#ifdef _WIN32
|
||||
DWORD old_protect;
|
||||
#endif
|
||||
|
||||
if (machine_stack_cache_index > 0) {
|
||||
if (machine_stack_cache[machine_stack_cache_index - 1].size == (size / sizeof(VALUE))) {
|
||||
|
@ -877,15 +881,21 @@ fiber_machine_stack_alloc(size_t size)
|
|||
machine_stack_cache_index--;
|
||||
machine_stack_cache[machine_stack_cache_index].ptr = NULL;
|
||||
machine_stack_cache[machine_stack_cache_index].size = 0;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
/* TODO handle multiple machine stack size */
|
||||
rb_bug("machine_stack_cache size is not canonicalized");
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
#ifdef _WIN32
|
||||
return malloc(size);
|
||||
ptr = VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
|
||||
|
||||
if (!ptr) {
|
||||
rb_raise(rb_eFiberError, "can't allocate machine stack to fiber: %s", ERRNOMSG);
|
||||
}
|
||||
|
||||
if (!VirtualProtect(ptr, RB_PAGE_SIZE, PAGE_READWRITE | PAGE_GUARD, &old_protect)) {
|
||||
rb_raise(rb_eFiberError, "can't set a guard page: %s", ERRNOMSG);
|
||||
}
|
||||
#else
|
||||
void *page;
|
||||
STACK_GROW_DIR_DETECTION;
|
||||
|
@ -1725,7 +1735,7 @@ fiber_store(rb_fiber_t *next_fib, rb_thread_t *th)
|
|||
else {
|
||||
if (terminated_machine_stack.ptr != fib->cont.machine.stack) {
|
||||
#ifdef _WIN32
|
||||
free((void*)terminated_machine_stack.ptr);
|
||||
VirtualFree(terminated_machine_stack.ptr, 0, MEM_RELEASE);
|
||||
#else
|
||||
munmap((void*)terminated_machine_stack.ptr, terminated_machine_stack.size * sizeof(VALUE));
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue