mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 19:08:55 -04:00
inside buffer, not outside
This commit is contained in:
parent
d37e8b0dbf
commit
e5aa103cd1
@ -257,7 +257,11 @@ setup_context_1(void) {
|
|||||||
/* Now we overwrite the stack pointer value in the saved
|
/* Now we overwrite the stack pointer value in the saved
|
||||||
register context. This doesn't work with all implementations
|
register context. This doesn't work with all implementations
|
||||||
of setjmp/longjmp. */
|
of setjmp/longjmp. */
|
||||||
(*(void **)&temp[CS_JB_SP]) = (st_stack + st_stack_size);
|
|
||||||
|
/* We give ourselves a small buffer of unused space at the top
|
||||||
|
of the stack, to allow for the stack frame and such that this
|
||||||
|
code might be assuming is there. */
|
||||||
|
(*(void **)&temp[CS_JB_SP]) = (st_stack + st_stack_size - 0x100);
|
||||||
|
|
||||||
/* And finally, we place ourselves on the new stack by using
|
/* And finally, we place ourselves on the new stack by using
|
||||||
longjmp() to reload the modified context. */
|
longjmp() to reload the modified context. */
|
||||||
|
@ -79,7 +79,7 @@ ThreadSimpleImpl::
|
|||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
VirtualFree(_stack, 0, MEM_RELEASE);
|
VirtualFree(_stack, 0, MEM_RELEASE);
|
||||||
#else
|
#else
|
||||||
munmap(_stack, _stack_alloc_size);
|
munmap(_stack, _stack_size);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,25 +115,13 @@ start(ThreadPriority priority, bool joinable) {
|
|||||||
nassertr(_stack == NULL, false);
|
nassertr(_stack == NULL, false);
|
||||||
_stack_size = (size_t)thread_stack_size;
|
_stack_size = (size_t)thread_stack_size;
|
||||||
|
|
||||||
// We allocate the requested stack size, plus an additional tiny
|
|
||||||
// buffer to allow room for the code to access values on the
|
|
||||||
// currently executing stack frame at the time we switch the stack.
|
|
||||||
_stack_alloc_size = _stack_size + 0x100;
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
// Windows case.
|
// Windows case.
|
||||||
SYSTEM_INFO sysinfo;
|
_stack = (unsigned char *)VirtualAlloc(NULL, _stack_size, MEM_COMMIT | MEM_RESERVE,
|
||||||
GetSystemInfo(&sysinfo);
|
|
||||||
|
|
||||||
size_t page_size = (size_t)sysinfo.dwPageSize;
|
|
||||||
_stack_alloc_size = ((_stack_alloc_size + page_size - 1) / page_size) * page_size;
|
|
||||||
_stack = (unsigned char *)VirtualAlloc(NULL, _stack_alloc_size, MEM_COMMIT | MEM_RESERVE,
|
|
||||||
PAGE_EXECUTE_READWRITE);
|
PAGE_EXECUTE_READWRITE);
|
||||||
#else
|
#else
|
||||||
// Posix case.
|
// Posix case.
|
||||||
size_t page_size = getpagesize();
|
_stack = (unsigned char *)mmap(NULL, _stack_size, PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||||
_stack_alloc_size = ((_stack_alloc_size + page_size - 1) / page_size) * page_size;
|
|
||||||
_stack = (unsigned char *)mmap(NULL, _stack_alloc_size, PROT_READ | PROT_WRITE | PROT_EXEC,
|
|
||||||
MAP_PRIVATE | MAP_ANON, -1, 0);
|
MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -115,7 +115,6 @@ private:
|
|||||||
ThreadContext _context;
|
ThreadContext _context;
|
||||||
unsigned char *_stack;
|
unsigned char *_stack;
|
||||||
size_t _stack_size;
|
size_t _stack_size;
|
||||||
size_t _stack_alloc_size;
|
|
||||||
|
|
||||||
#ifdef HAVE_PYTHON
|
#ifdef HAVE_PYTHON
|
||||||
// If we might be working with Python, we have to manage the Python
|
// If we might be working with Python, we have to manage the Python
|
||||||
|
Loading…
x
Reference in New Issue
Block a user