drd: Fix fork() handling
[valgrind.git] / include / pub_tool_libcproc.h
blob96b6d6838ef8464147e24019b4f660dc9f2bf23a
2 /*--------------------------------------------------------------------*/
3 /*--- Process-related libc stuff pub_tool_libcproc.h ---*/
4 /*--------------------------------------------------------------------*/
6 /*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
10 Copyright (C) 2000-2017 Julian Seward
11 jseward@acm.org
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.
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.
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.
28 The GNU General Public License is contained in the file COPYING.
31 #ifndef __PUB_TOOL_LIBCPROC_H
32 #define __PUB_TOOL_LIBCPROC_H
34 #include "pub_tool_basics.h" // VG_ macro
35 #include "pub_tool_vki.h" // vki_rlimit
37 /* ---------------------------------------------------------------------
38 Command-line and environment stuff
39 ------------------------------------------------------------------ */
41 /* Client environment. */
42 extern HChar** VG_(client_envp);
44 /* Looks up VG_(client_envp) */
45 extern HChar* VG_(getenv) ( const HChar* name );
47 /* Path to all our library/aux files */
48 extern const HChar *VG_(libdir);
50 // The name of the LD_PRELOAD-equivalent variable. It varies across
51 // platforms.
52 extern const HChar* VG_(LD_PRELOAD_var_name);
54 /* Resolves filename of VG_(cl_exec_fd) and copies it to the buffer.
55 Buffer must not be NULL and buf_size must be at least 1.
56 If buffer is not large enough it is terminated with '\0' only
57 when 'terminate_with_NUL == True'. */
58 extern void VG_(client_fname)(HChar *buffer, SizeT buf_size,
59 Bool terminate_with_NUL);
61 /* Concatenates client exename and command line arguments into
62 the buffer. Buffer must not be NULL and buf_size must be
63 at least 1. Buffer is always terminated with '\0'. */
64 extern void VG_(client_cmd_and_args)(HChar *buffer, SizeT buf_size);
66 /* ---------------------------------------------------------------------
67 Important syscalls
68 ------------------------------------------------------------------ */
70 extern Int VG_(waitpid)( Int pid, Int *status, Int options );
71 extern Int VG_(system) ( const HChar* cmd );
72 extern Int VG_(spawn) ( const HChar *filename, const HChar **argv );
73 extern Int VG_(fork) ( void);
74 extern void VG_(execv) ( const HChar* filename, const HChar** argv );
75 extern Int VG_(sysctl) ( Int *name, UInt namelen, void *oldp, SizeT *oldlenp, void *newp, SizeT newlen );
77 /* ---------------------------------------------------------------------
78 Resource limits and capabilities
79 ------------------------------------------------------------------ */
81 extern Int VG_(getrlimit) ( Int resource, struct vki_rlimit *rlim );
82 extern Int VG_(setrlimit) ( Int resource, const struct vki_rlimit *rlim );
83 extern Int VG_(prctl) (Int option,
84 ULong arg2, ULong arg3, ULong arg4, ULong arg5);
86 /* ---------------------------------------------------------------------
87 pids, etc
88 ------------------------------------------------------------------ */
90 extern Int VG_(gettid) ( void );
91 extern Int VG_(getpid) ( void );
92 extern Int VG_(getppid) ( void );
93 extern Int VG_(getpgrp) ( void );
94 extern Int VG_(geteuid) ( void );
95 extern Int VG_(getegid) ( void );
97 /* ---------------------------------------------------------------------
98 Timing
99 ------------------------------------------------------------------ */
101 // Returns the number of milliseconds passed since the program started
102 // (roughly; it gets initialised partway through Valgrind's initialisation
103 // steps). This is wallclock time.
104 extern UInt VG_(read_millisecond_timer) ( void );
106 extern Int VG_(gettimeofday)(struct vki_timeval *tv, struct vki_timezone *tz);
108 // Returns the number of milliseconds of user cpu time we have used,
109 // as reported by 'getrusage'.
110 extern UInt VG_(get_user_milliseconds)(void);
112 /* ---------------------------------------------------------------------
113 atfork
114 ------------------------------------------------------------------ */
116 typedef void (*vg_atfork_t)(ThreadId);
117 extern void VG_(atfork)(vg_atfork_t pre, vg_atfork_t parent, vg_atfork_t child);
120 #endif // __PUB_TOOL_LIBCPROC_H
122 /*--------------------------------------------------------------------*/
123 /*--- end ---*/
124 /*--------------------------------------------------------------------*/