`dr_get_process_id` doesn't return the expected result in `thread_exit_event` callbacks
Created by: petrochenkov
Citing the documentation of void dr_register_thread_exit_event ( void(*)(void *drcontext) func )
:
The passed-in drcontext should be used instead of calling dr_get_current_drcontext(), as the thread exit event may be invoked from other threads, and using dr_get_current_drcontext() can result in failure to clean up the right resources, and at process exit time it may return NULL.
The dr_get_process_id
API doesn't take a drcontext
parameter, so it's effectively using "the current context" when being called from thread exit callbacks, which is not recommended.
This can lead to pretty confusing results when DynamoRIO reports different process IDs for the same thread ID at different points.
Possible solution: introduce a version of dr_get_process_id
taking a void* drcontext
parameter that would work exactly like thread_id_t dr_get_thread_id ( void * drcontext )
, but would return dcontext->owning_process
rather than dcontext->owning_thread
.