njn | 2521d32 | 2005-05-08 14:45:13 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
njn | c1b0181 | 2005-06-17 22:19:06 +0000 | [diff] [blame] | 3 | /*--- System call wrappers, etc. pub_core_syswrap.h ---*/ |
njn | 2521d32 | 2005-05-08 14:45:13 +0000 | [diff] [blame] | 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
| 9 | |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame] | 10 | Copyright (C) 2000-2017 Julian Seward |
njn | 2521d32 | 2005-05-08 14:45:13 +0000 | [diff] [blame] | 11 | jseward@acm.org |
| 12 | |
| 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
| 28 | The GNU General Public License is contained in the file COPYING. |
| 29 | */ |
| 30 | |
njn | c1b0181 | 2005-06-17 22:19:06 +0000 | [diff] [blame] | 31 | #ifndef __PUB_CORE_SYSWRAP_H |
| 32 | #define __PUB_CORE_SYSWRAP_H |
njn | 2521d32 | 2005-05-08 14:45:13 +0000 | [diff] [blame] | 33 | |
florian | 535fb1b | 2013-09-15 13:54:34 +0000 | [diff] [blame] | 34 | #include "pub_core_basics.h" // VG_ macro |
| 35 | #include "pub_core_threadstate.h" // ThreadArchState |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 36 | #include "pub_core_tooliface.h" // CorePart |
florian | 535fb1b | 2013-09-15 13:54:34 +0000 | [diff] [blame] | 37 | |
njn | 2521d32 | 2005-05-08 14:45:13 +0000 | [diff] [blame] | 38 | //-------------------------------------------------------------------- |
njn | 899ce73 | 2005-06-21 00:28:11 +0000 | [diff] [blame] | 39 | // PURPOSE: This module contains all the syscall junk: mostly PRE/POST |
| 40 | // wrappers, but also the main syscall jacketing code. |
njn | 2521d32 | 2005-05-08 14:45:13 +0000 | [diff] [blame] | 41 | //-------------------------------------------------------------------- |
| 42 | |
njn | 8c2e153 | 2005-06-10 23:16:13 +0000 | [diff] [blame] | 43 | // Allocates a stack for the first thread, then runs it, |
| 44 | // as if the thread had been set up by clone() |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 45 | extern void VG_(main_thread_wrapper_NORETURN)(ThreadId tid); |
njn | 8c2e153 | 2005-06-10 23:16:13 +0000 | [diff] [blame] | 46 | |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 47 | extern void VG_(client_syscall) ( ThreadId tid, UInt trc ); |
njn | 2521d32 | 2005-05-08 14:45:13 +0000 | [diff] [blame] | 48 | |
| 49 | extern void VG_(post_syscall) ( ThreadId tid ); |
| 50 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 51 | /* Clear this module's private state for thread 'tid' */ |
| 52 | extern void VG_(clear_syscallInfo) ( Int tid ); |
| 53 | |
rhyskidd | bc3770e | 2015-03-07 05:22:12 +0000 | [diff] [blame] | 54 | // Returns True if the given thread is currently in a system call |
| 55 | extern Bool VG_(is_in_syscall) ( Int tid ); |
| 56 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 57 | // Fix up a thread's state when syscall is interrupted by a signal. |
| 58 | extern void VG_(fixup_guest_state_after_syscall_interrupted)( |
| 59 | ThreadId tid, |
| 60 | Addr ip, |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 61 | SysRes sysret, |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 62 | Bool restart, |
| 63 | struct vki_ucontext *uc |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 64 | ); |
njn | 2521d32 | 2005-05-08 14:45:13 +0000 | [diff] [blame] | 65 | |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 66 | #if defined(VGO_solaris) |
| 67 | // Determine if in a blocking syscall. |
| 68 | extern Bool VG_(is_ip_in_blocking_syscall)(ThreadId tid, Addr ip); |
| 69 | #endif |
| 70 | |
njn | 7b85dd5 | 2005-06-12 17:26:29 +0000 | [diff] [blame] | 71 | // Wait until all other threads are dead |
| 72 | extern void VG_(reap_threads)(ThreadId self); |
| 73 | |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 74 | // Release resources held by this thread |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 75 | extern void VG_(cleanup_thread) ( ThreadArchState* ); |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 76 | |
njn | 2521d32 | 2005-05-08 14:45:13 +0000 | [diff] [blame] | 77 | /* fd leakage calls. */ |
| 78 | extern void VG_(init_preopened_fds) ( void ); |
florian | e543f30 | 2012-10-21 19:43:43 +0000 | [diff] [blame] | 79 | extern void VG_(show_open_fds) ( const HChar* when ); |
njn | 2521d32 | 2005-05-08 14:45:13 +0000 | [diff] [blame] | 80 | |
sewardj | 1ae3f3a | 2005-09-28 10:47:38 +0000 | [diff] [blame] | 81 | // When the final thread is done, where shall I call to shutdown the |
| 82 | // system cleanly? Is set once at startup (in m_main) and never |
| 83 | // changes after that. Is basically a pointer to the exit |
| 84 | // continuation. This is all just a nasty hack to avoid calling |
| 85 | // directly from m_syswrap to m_main at exit, since that would cause |
| 86 | // m_main to become part of a module cycle, which is silly. |
| 87 | extern void (* VG_(address_of_m_main_shutdown_actions_NORETURN) ) |
| 88 | (ThreadId,VgSchedReturnCode); |
| 89 | |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 90 | #if defined(VGO_solaris) |
| 91 | extern void VG_(save_context)(ThreadId tid, vki_ucontext_t *uc, |
| 92 | CorePart part); |
| 93 | extern void VG_(restore_context)(ThreadId tid, vki_ucontext_t *uc, |
| 94 | CorePart part, Bool esp_is_thrptr); |
| 95 | extern void VG_(syswrap_init)(void); |
iraisr | e036540 | 2015-09-25 20:12:26 +0000 | [diff] [blame] | 96 | extern void VG_(change_mapping_ownership)(Addr addr, Bool once_only); |
iraisr | bcfaeed | 2015-08-22 22:08:43 +0000 | [diff] [blame] | 97 | extern Bool VG_(setup_client_dataseg)(void); |
| 98 | extern void VG_(track_client_dataseg)(ThreadId tid); |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 99 | #endif |
| 100 | |
njn | c1b0181 | 2005-06-17 22:19:06 +0000 | [diff] [blame] | 101 | #endif // __PUB_CORE_SYSWRAP_H |
njn | 2521d32 | 2005-05-08 14:45:13 +0000 | [diff] [blame] | 102 | |
| 103 | /*--------------------------------------------------------------------*/ |
| 104 | /*--- end ---*/ |
| 105 | /*--------------------------------------------------------------------*/ |
| 106 | |