1 
2 /*--------------------------------------------------------------------*/
3 /*--- System call wrappers, etc.                pub_core_syswrap.h ---*/
4 /*--------------------------------------------------------------------*/
5 
6 /*
7    This file is part of Valgrind, a dynamic binary instrumentation
8    framework.
9 
10    Copyright (C) 2000-2013 Julian Seward
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 
31 #ifndef __PUB_CORE_SYSWRAP_H
32 #define __PUB_CORE_SYSWRAP_H
33 
34 #include "pub_core_basics.h"        // VG_ macro
35 #include "pub_core_threadstate.h"   // ThreadArchState
36 
37 //--------------------------------------------------------------------
38 // PURPOSE: This module contains all the syscall junk:  mostly PRE/POST
39 // wrappers, but also the main syscall jacketing code.
40 //--------------------------------------------------------------------
41 
42 // Allocates a stack for the first thread, then runs it,
43 // as if the thread had been set up by clone()
44 extern void VG_(main_thread_wrapper_NORETURN)(ThreadId tid);
45 
46 extern void VG_(client_syscall) ( ThreadId tid, UInt trc );
47 
48 extern void VG_(post_syscall)   ( ThreadId tid );
49 
50 /* Clear this module's private state for thread 'tid' */
51 extern void VG_(clear_syscallInfo) ( Int tid );
52 
53 // Returns True if the given thread is currently in a system call
54 extern Bool VG_(is_in_syscall) ( Int tid );
55 
56 // Fix up a thread's state when syscall is interrupted by a signal.
57 extern void VG_(fixup_guest_state_after_syscall_interrupted)(
58                ThreadId tid,
59                Addr     ip,
60                SysRes   sysret,
61                Bool     restart
62             );
63 
64 // Wait until all other threads are dead
65 extern void VG_(reap_threads)(ThreadId self);
66 
67 // Release resources held by this thread
68 extern void VG_(cleanup_thread) ( ThreadArchState* );
69 
70 /* fd leakage calls. */
71 extern void VG_(init_preopened_fds) ( void );
72 extern void VG_(show_open_fds) ( const HChar* when );
73 
74 // When the final thread is done, where shall I call to shutdown the
75 // system cleanly?  Is set once at startup (in m_main) and never
76 // changes after that.  Is basically a pointer to the exit
77 // continuation.  This is all just a nasty hack to avoid calling
78 // directly from m_syswrap to m_main at exit, since that would cause
79 // m_main to become part of a module cycle, which is silly.
80 extern void (* VG_(address_of_m_main_shutdown_actions_NORETURN) )
81             (ThreadId,VgSchedReturnCode);
82 
83 #endif   // __PUB_CORE_SYSWRAP_H
84 
85 /*--------------------------------------------------------------------*/
86 /*--- end                                                          ---*/
87 /*--------------------------------------------------------------------*/
88 
89