/* Which thread is running on an LWP? Copyright (C) 2003-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, see . */ #include "pthread-infinity.h" #include "tls-infinity.h" #if I8_THREAD_SELF == I8_TS_CONST_THREAD_AREA # include "infinity_lookup_th_unique_cta.i8" #endif #if I8_THREAD_SELF == I8_TS_REGISTER # include "infinity_lookup_th_unique_reg.i8" #endif #if I8_THREAD_SELF == I8_TS_REGISTER_THREAD_AREA # include "infinity_lookup_th_unique_rta.i8" #endif /* Given an lwpid_t identifying an LWP, return the descriptor of the thread running on it and TD_OK, or NULL and a non-TD_OK td_err_e code indicating the reason for failure. Thread descriptors are opaque pointers and should not be dereferenced by calling code. */ int, addr libpthread::map_lwp2thr (int lwpid) { /* We cannot rely on thread registers and such information at all before __pthread_initialize_minimal has gotten far enough. They sometimes contain garbage that would confuse us, left by the kernel at exec. So if it looks like initialization is incomplete, we only fake a special descriptor for the initial thread. */ if (deref (__stack_user, LIST_T_NEXT_OFFSET) == NULL) { if (i8core::ps_getpid () != lwpid) return TD_ERR, undefined; return TD_OK, NULL; } return __lookup_th_unique (lwpid); }