mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-03 18:13:01 +00:00
Sync VEX/LICENSE.GPL with top-level COPYING file. We used 3 different addresses for writing to the FSF to receive a copy of the GPL. Replace all different variants with an URL <http://www.gnu.org/licenses/>. The following files might still have some slightly different (L)GPL copyright notice because they were derived from other programs: - files under coregrind/m_demangle which come from libiberty: cplus-dem.c, d-demangle.c, demangle.h, rust-demangle.c, safe-ctype.c and safe-ctype.h - coregrind/m_demangle/dyn-string.[hc] derived from GCC. - coregrind/m_demangle/ansidecl.h derived from glibc. - VEX files for FMA detived from glibc: host_generic_maddf.h and host_generic_maddf.c - files under coregrin/m_debuginfo derived from LZO: lzoconf.h, lzodefs.h, minilzo-inl.c and minilzo.h - files under coregrind/m_gdbserver detived from GDB: gdb/signals.h, inferiors.c, regcache.c, regcache.h, regdef.h, remote-utils.c, server.c, server.h, signals.c, target.c, target.h and utils.c Plus the following test files: - none/tests/ppc32/testVMX.c derived from testVMX. - ppc tests derived from QEMU: jm-insns.c, ppc64_helpers.h and test_isa_3_0.c - tests derived from bzip2 (with embedded GPL text in code): hackedbz2.c, origin5-bz2.c, varinfo6.c - tests detived from glibc: str_tester.c, pth_atfork1.c - test detived from GCC libgomp: tc17_sembar.c - performance tests derived from bzip2 or tinycc (with embedded GPL text in code): bz2.c, test_input_for_tinycc.c and tinycc.c
195 lines
5.7 KiB
C
195 lines
5.7 KiB
C
|
|
/*--------------------------------------------------------------------*/
|
|
/*--- The thread state. m_threadstate.c ---*/
|
|
/*--------------------------------------------------------------------*/
|
|
|
|
/*
|
|
This file is part of Valgrind, a dynamic binary instrumentation
|
|
framework.
|
|
|
|
Copyright (C) 2000-2017 Julian Seward
|
|
jseward@acm.org
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public License as
|
|
published by the Free Software Foundation; either version 2 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program 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
|
|
General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
The GNU General Public License is contained in the file COPYING.
|
|
*/
|
|
|
|
#include "pub_core_basics.h"
|
|
#include "pub_core_vki.h"
|
|
#include "pub_core_threadstate.h"
|
|
#include "pub_core_mallocfree.h" // VG_(malloc)
|
|
#include "pub_core_libcassert.h"
|
|
#include "pub_core_inner.h"
|
|
#if defined(ENABLE_INNER_CLIENT_REQUEST)
|
|
#include "helgrind/helgrind.h"
|
|
#endif
|
|
|
|
/*------------------------------------------------------------*/
|
|
/*--- Data structures. ---*/
|
|
/*------------------------------------------------------------*/
|
|
|
|
ThreadId VG_(running_tid) = VG_INVALID_THREADID;
|
|
|
|
ThreadState *VG_(threads);
|
|
UInt VG_N_THREADS;
|
|
|
|
ThreadState *VG_(inner_threads);
|
|
|
|
/*------------------------------------------------------------*/
|
|
/*--- Operations. ---*/
|
|
/*------------------------------------------------------------*/
|
|
|
|
void VG_(init_Threads)(void)
|
|
{
|
|
ThreadId tid;
|
|
|
|
VG_(threads) = VG_(arena_memalign) (VG_AR_CORE, "init_Threads",
|
|
LibVEX_GUEST_STATE_ALIGN,
|
|
VG_N_THREADS * sizeof VG_(threads)[0]);
|
|
|
|
for (tid = 1; tid < VG_N_THREADS; tid++) {
|
|
INNER_REQUEST(
|
|
ANNOTATE_BENIGN_RACE_SIZED(&VG_(threads)[tid].status,
|
|
sizeof(VG_(threads)[tid].status), ""));
|
|
INNER_REQUEST(
|
|
ANNOTATE_BENIGN_RACE_SIZED(&VG_(threads)[tid].os_state.exitcode,
|
|
sizeof(VG_(threads)[tid].os_state.exitcode),
|
|
""));
|
|
}
|
|
INNER_REQUEST(VALGRIND_INNER_THREADS(VG_(threads)));
|
|
}
|
|
|
|
const HChar* VG_(name_of_ThreadStatus) ( ThreadStatus status )
|
|
{
|
|
switch (status) {
|
|
case VgTs_Empty: return "VgTs_Empty";
|
|
case VgTs_Init: return "VgTs_Init";
|
|
case VgTs_Runnable: return "VgTs_Runnable";
|
|
case VgTs_WaitSys: return "VgTs_WaitSys";
|
|
case VgTs_Yielding: return "VgTs_Yielding";
|
|
case VgTs_Zombie: return "VgTs_Zombie";
|
|
default: return "VgTs_???";
|
|
}
|
|
}
|
|
|
|
const HChar* VG_(name_of_VgSchedReturnCode) ( VgSchedReturnCode retcode )
|
|
{
|
|
switch (retcode) {
|
|
case VgSrc_None: return "VgSrc_None";
|
|
case VgSrc_ExitThread: return "VgSrc_ExitThread";
|
|
case VgSrc_ExitProcess: return "VgSrc_ExitProcess";
|
|
case VgSrc_FatalSig: return "VgSrc_FatalSig";
|
|
default: return "VgSrc_???";
|
|
}
|
|
}
|
|
|
|
ThreadState *VG_(get_ThreadState)(ThreadId tid)
|
|
{
|
|
vg_assert(tid >= 0 && tid < VG_N_THREADS);
|
|
vg_assert(VG_(threads)[tid].tid == tid);
|
|
return &VG_(threads)[tid];
|
|
}
|
|
|
|
Bool VG_(is_valid_tid) ( ThreadId tid )
|
|
{
|
|
/* tid is unsigned, hence no < 0 test. */
|
|
if (tid == 0) return False;
|
|
if (tid >= VG_N_THREADS) return False;
|
|
if (VG_(threads)[tid].status == VgTs_Empty) return False;
|
|
return True;
|
|
}
|
|
|
|
// This function is for tools to call.
|
|
ThreadId VG_(get_running_tid)(void)
|
|
{
|
|
return VG_(running_tid);
|
|
}
|
|
|
|
Bool VG_(is_running_thread)(ThreadId tid)
|
|
{
|
|
ThreadState *tst = VG_(get_ThreadState)(tid);
|
|
|
|
return
|
|
// tst->os_state.lwpid == VG_(gettid)() && // check we're this tid
|
|
VG_(running_tid) == tid && // and that we've got the lock
|
|
tst->status == VgTs_Runnable; // and we're runnable
|
|
}
|
|
|
|
/* Return true if the thread is still alive but in the process of exiting. */
|
|
inline Bool VG_(is_exiting)(ThreadId tid)
|
|
{
|
|
vg_assert(VG_(is_valid_tid)(tid));
|
|
return VG_(threads)[tid].exitreason != VgSrc_None;
|
|
}
|
|
|
|
/* Return the number of non-dead Threads */
|
|
Int VG_(count_living_threads)(void)
|
|
{
|
|
Int count = 0;
|
|
ThreadId tid;
|
|
|
|
for(tid = 1; tid < VG_N_THREADS; tid++)
|
|
if (VG_(threads)[tid].status != VgTs_Empty &&
|
|
VG_(threads)[tid].status != VgTs_Zombie)
|
|
count++;
|
|
|
|
return count;
|
|
}
|
|
|
|
/* Return the number of threads in VgTs_Runnable state */
|
|
Int VG_(count_runnable_threads)(void)
|
|
{
|
|
Int count = 0;
|
|
ThreadId tid;
|
|
|
|
for(tid = 1; tid < VG_N_THREADS; tid++)
|
|
if (VG_(threads)[tid].status == VgTs_Runnable)
|
|
count++;
|
|
|
|
return count;
|
|
}
|
|
|
|
/* Given an LWP id (ie, real kernel thread id), find the corresponding
|
|
ThreadId */
|
|
ThreadId VG_(lwpid_to_vgtid)(Int lwp)
|
|
{
|
|
ThreadId tid;
|
|
|
|
for(tid = 1; tid < VG_N_THREADS; tid++)
|
|
if (VG_(threads)[tid].status != VgTs_Empty
|
|
&& VG_(threads)[tid].os_state.lwpid == lwp)
|
|
return tid;
|
|
|
|
return VG_INVALID_THREADID;
|
|
}
|
|
|
|
ThreadId VG_(lwpid_to_vgtid_dead_ok)(Int lwp)
|
|
{
|
|
ThreadId tid = VG_(lwpid_to_vgtid)(lwp);
|
|
|
|
if (tid != VG_INVALID_THREADID)
|
|
return tid;
|
|
|
|
for(tid = 1; tid < VG_N_THREADS; tid++)
|
|
if (VG_(threads)[tid].os_state.lwpid == lwp)
|
|
return tid;
|
|
|
|
return VG_INVALID_THREADID;
|
|
}
|
|
|
|
/*--------------------------------------------------------------------*/
|
|
/*--- end ---*/
|
|
/*--------------------------------------------------------------------*/
|