sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- A home for miscellaneous bits of information which pertain ---*/ |
| 4 | /*--- to the client's state. ---*/ |
| 5 | /*--- m_clientstate.c ---*/ |
| 6 | /*--------------------------------------------------------------------*/ |
| 7 | |
| 8 | /* |
| 9 | This file is part of Valgrind, a dynamic binary instrumentation |
| 10 | framework. |
| 11 | |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame^] | 12 | Copyright (C) 2000-2017 Julian Seward |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 13 | jseward@acm.org |
| 14 | |
| 15 | This program is free software; you can redistribute it and/or |
| 16 | modify it under the terms of the GNU General Public License as |
| 17 | published by the Free Software Foundation; either version 2 of the |
| 18 | License, or (at your option) any later version. |
| 19 | |
| 20 | This program is distributed in the hope that it will be useful, but |
| 21 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 23 | General Public License for more details. |
| 24 | |
| 25 | You should have received a copy of the GNU General Public License |
| 26 | along with this program; if not, write to the Free Software |
| 27 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 28 | 02111-1307, USA. |
| 29 | |
| 30 | The GNU General Public License is contained in the file COPYING. |
| 31 | */ |
| 32 | |
| 33 | #include "pub_core_basics.h" |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame^] | 34 | #include "pub_core_threadstate.h" |
sewardj | 4cfea4f | 2006-10-14 19:26:10 +0000 | [diff] [blame] | 35 | #include "pub_core_vki.h" |
sewardj | 14c7cc5 | 2007-02-25 15:08:24 +0000 | [diff] [blame] | 36 | #include "pub_core_xarray.h" |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 37 | #include "pub_core_clientstate.h" |
| 38 | |
| 39 | /*-----------------------------------------------------------------*/ |
| 40 | /*--- ---*/ |
| 41 | /*--- Basic globals about the address space. ---*/ |
| 42 | /*--- ---*/ |
| 43 | /*-----------------------------------------------------------------*/ |
| 44 | |
| 45 | /* Client address space, lowest to highest (see top of ume.c) */ |
| 46 | // TODO: get rid of as many of these as possible. |
| 47 | |
philippe | 4fa3d37 | 2013-07-21 16:04:05 +0000 | [diff] [blame] | 48 | /* ***Initial*** lowest address of the stack segment of the main thread. |
philippe | 38a74d2 | 2014-08-29 22:53:19 +0000 | [diff] [blame] | 49 | The main stack will grow if needed but VG_(clstk_start_base) will |
philippe | 4fa3d37 | 2013-07-21 16:04:05 +0000 | [diff] [blame] | 50 | not be changed according to the growth. */ |
philippe | 38a74d2 | 2014-08-29 22:53:19 +0000 | [diff] [blame] | 51 | Addr VG_(clstk_start_base) = 0; |
philippe | 4fa3d37 | 2013-07-21 16:04:05 +0000 | [diff] [blame] | 52 | /* Initial highest address of the stack segment of the main thread. */ |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 53 | Addr VG_(clstk_end) = 0; |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame^] | 54 | UWord VG_(clstk_id) = NULL_STK_ID; |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 55 | /* Maximum size of the main thread's client stack. */ |
| 56 | SizeT VG_(clstk_max_size) = 0; |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 57 | |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 58 | /* Solaris and Linux only, specifies where the client auxv is. |
| 59 | |
| 60 | This is set up as part of setup_client_stack() in |
| 61 | initimg-{linux,solaris}.c. */ |
sewardj | 2a31239 | 2011-06-26 09:26:48 +0000 | [diff] [blame] | 62 | UWord* VG_(client_auxv) = NULL; |
| 63 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 64 | Addr VG_(brk_base) = 0; /* start of brk */ |
| 65 | Addr VG_(brk_limit) = 0; /* current brk */ |
| 66 | |
| 67 | /* A fd which refers to the client executable. */ |
| 68 | Int VG_(cl_exec_fd) = -1; |
| 69 | |
| 70 | /* A fd which refers to the fake /proc/<pid>/cmdline in /tmp. */ |
| 71 | Int VG_(cl_cmdline_fd) = -1; |
| 72 | |
tom | 41ad7e7 | 2012-10-04 20:27:38 +0000 | [diff] [blame] | 73 | /* A fd which refers to the fake /proc/<pid>/auxv in /tmp. */ |
| 74 | Int VG_(cl_auxv_fd) = -1; |
| 75 | |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 76 | #if defined(VGO_solaris) |
| 77 | /* A fd which refers to the fake /proc/<pid>/psinfo in /tmp. */ |
| 78 | Int VG_(cl_psinfo_fd) = -1; |
| 79 | #endif /* VGO_solaris */ |
| 80 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 81 | // Command line pieces, after they have been extracted from argv in |
florian | a2968cc | 2013-09-20 21:34:40 +0000 | [diff] [blame] | 82 | // m_main.main(). The payload vectors are allocated in VG_AR_CORE |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 83 | // (the default arena). They are never freed. |
| 84 | |
| 85 | /* Args for the client. */ |
sewardj | 14c7cc5 | 2007-02-25 15:08:24 +0000 | [diff] [blame] | 86 | XArray* /* of HChar* */ VG_(args_for_client) = NULL; |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 87 | |
| 88 | /* Args for V (augments, then those from the launcher). */ |
sewardj | 14c7cc5 | 2007-02-25 15:08:24 +0000 | [diff] [blame] | 89 | XArray* /* of HChar* */ VG_(args_for_valgrind) = NULL; |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 90 | |
| 91 | /* How many of the above not to pass on at execve time? */ |
| 92 | Int VG_(args_for_valgrind_noexecpass) = 0; |
| 93 | |
| 94 | /* The name of the client executable, as specified on the command |
| 95 | line. */ |
bart | a3054f5 | 2010-06-14 18:12:56 +0000 | [diff] [blame] | 96 | const HChar* VG_(args_the_exename) = NULL; |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 97 | |
| 98 | // Client's original rlimit data and rlimit stack |
| 99 | struct vki_rlimit VG_(client_rlimit_data); |
| 100 | struct vki_rlimit VG_(client_rlimit_stack); |
| 101 | |
| 102 | // Name of the launcher, as extracted from VALGRIND_LAUNCHER at |
| 103 | // startup. |
| 104 | HChar* VG_(name_of_launcher) = NULL; |
| 105 | |
sewardj | fdf91b4 | 2005-09-28 00:53:09 +0000 | [diff] [blame] | 106 | /* Application-visible file descriptor limits */ |
| 107 | Int VG_(fd_soft_limit) = -1; |
| 108 | Int VG_(fd_hard_limit) = -1; |
| 109 | |
Elliott Hughes | a0664b9 | 2017-04-18 17:46:52 -0700 | [diff] [blame] | 110 | /* Useful addresses extracted from the client. */ |
| 111 | /* Where is the freeres_wrapper routine we made? */ |
| 112 | Addr VG_(client_freeres_wrapper) = 0; |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 113 | |
sewardj | a672ea3 | 2006-04-29 18:03:14 +0000 | [diff] [blame] | 114 | /* x86-linux only: where is glibc's _dl_sysinfo_int80 function? |
| 115 | Finding it isn't essential, but knowing where it is does sometimes |
| 116 | help produce better back traces. See big comment in |
| 117 | VG_(get_StackTrace) in m_stacktrace.c for further info. */ |
| 118 | Addr VG_(client__dl_sysinfo_int80) = 0; |
| 119 | |
philippe | 9848690 | 2014-08-19 22:46:44 +0000 | [diff] [blame] | 120 | /* Address of the (internal) glibc nptl pthread stack cache size, |
| 121 | declared as: |
| 122 | static size_t stack_cache_actsize; |
| 123 | in nptl/allocatestack.c */ |
| 124 | SizeT* VG_(client__stack_cache_actsize__addr) = 0; |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 125 | |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 126 | #if defined(VGO_solaris) |
| 127 | /* Address of variable vg_vfork_fildes in vgpreload_core.so.0 |
| 128 | (vg_preloaded.c). */ |
| 129 | Int* VG_(vfork_fildes_addr) = 0; |
| 130 | #endif |
| 131 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 132 | /*--------------------------------------------------------------------*/ |
| 133 | /*--- end ---*/ |
| 134 | /*--------------------------------------------------------------------*/ |