[pypy-issue] Issue #2285: Segfault in vmprof sigprof_handler on OS X in release-5.1 (pypy/pypy)
issues-reply at bitbucket.org
Tue Apr 26 19:13:40 EDT 2016
New issue 2285: Segfault in vmprof sigprof_handler on OS X in release-5.1
While evaluating PyPy for use on an existing project, I ran into a segfault. It appears to be the use of thread-locals in `sigprof_handler`. Specifically, on line 158 as a parameter to `get_stack_trace`, `get_vmprof_stack()` is called, which is just a wrapper around `RPY_THREADLOCALREF_GET(vmprof_tl_stack)`. This macro (at least on my machine) unwraps to this:
((struct pypy_threadlocal_s *)pthread_getspecific(pypy_threadlocal_key))->vmprof_tl_stack
According to the manual for `pthread_getspecific`, this function can return `NULL`. This concern is noted on line 118 within this file under the header "TERRIBLE HACK AHEAD". The calls to threadlocals on lines 130 (`pthread_self()`) and 131 (`get_current_thread_id()`) are guarded, but this one later on is not.
My C is a little rusty, but I think this could be solved by returning `NULL` in `get_vmprof_stack()` if `_RPy_ThreadLocals_Get()` returns `NULL` and checking for that case in `sigprof_handler`. `get_vmprof_stack` doesn't appear to be used anywhere else.
More information about the pypy-issue