File: priv_aspacemgr.h

package info (click to toggle)
valgrind 1:3.12.0~svn20160714-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 120,428 kB
  • ctags: 70,855
  • sloc: ansic: 674,645; exp: 26,134; xml: 21,574; asm: 7,570; cpp: 7,567; makefile: 7,380; sh: 6,188; perl: 5,855; haskell: 195
file content (161 lines) | stat: -rw-r--r-- 6,144 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

/*--------------------------------------------------------------------*/
/*--- Module-local header file for m_aspacemgr.                    ---*/
/*---                                             priv_aspacemgr.h ---*/
/*--------------------------------------------------------------------*/

/*
   This file is part of Valgrind, a dynamic binary instrumentation
   framework.

   Copyright (C) 2006-2015 OpenWorks LLP
      info@open-works.co.uk

   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, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307, USA.

   The GNU General Public License is contained in the file COPYING.
*/

#ifndef __PRIV_ASPACEMGR_H
#define __PRIV_ASPACEMGR_H

/* One of the important design goals of the address space manager is
   to minimise dependence on other modules.  Hence the following
   minimal set of imports. */

#include "pub_core_basics.h"     // types
#include "pub_core_vkiscnums.h"  // system call numbers
#include "pub_core_vki.h"        // VKI_PAGE_SIZE, VKI_MREMAP_MAYMOVE,
                                 // VKI_MREMAP_FIXED, vki_stat64

#include "pub_core_debuglog.h"   // VG_(debugLog)

#include "pub_core_libcbase.h"   // VG_(strlen), VG_(strcmp), VG_(strncpy)
                                 // VG_IS_PAGE_ALIGNED
                                 // VG_PGROUNDDN, VG_PGROUNDUP

#include "pub_core_libcassert.h" // VG_(exit_now)

#include "pub_core_syscall.h"    // VG_(do_syscallN)
                                 // VG_(mk_SysRes_Error)
                                 // VG_(mk_SysRes_Success)

#include "pub_core_options.h"    // VG_(clo_sanity_level)

#include "pub_core_aspacemgr.h"  // self


/* --------------- Implemented in aspacemgr-common.c ---------------*/

/* Simple assert-like, file I/O and syscall facilities, which avoid
   dependence on m_libcassert, and hence on the entire module graph.
   This is important since most of the system itself depends on
   aspacem, so we have to do this to avoid a circular dependency. */

__attribute__ ((noreturn))
extern void   ML_(am_exit) ( Int status );
__attribute__ ((noreturn))
extern void   ML_(am_barf) ( const HChar* what );
__attribute__ ((noreturn))
extern void   ML_(am_barf_toolow) ( const HChar* what );

__attribute__ ((noreturn))
extern void   ML_(am_assert_fail) ( const HChar* expr,
                                    const HChar* file,
                                    Int line, 
                                    const HChar* fn );

#define aspacem_assert(expr)                              \
  ((void) (LIKELY(expr) ? 0 :                             \
           (ML_(am_assert_fail)(#expr,                    \
                                __FILE__, __LINE__,       \
                                __PRETTY_FUNCTION__))))

/* Dude, what's my process ID ? */
extern Int    ML_(am_getpid)( void );

/* A simple, self-contained sprintf implementation. */
extern UInt   ML_(am_sprintf) ( HChar* buf, const HChar *format, ... );

/* mmap et al wrappers */
/* wrapper for munmap */
extern SysRes ML_(am_do_munmap_NO_NOTIFY)(Addr start, SizeT length);

/* wrapper for the ghastly 'mremap' syscall */
extern SysRes ML_(am_do_extend_mapping_NO_NOTIFY)( 
                 Addr  old_addr, 
                 SizeT old_len,
                 SizeT new_len 
              );
/* ditto */
extern SysRes ML_(am_do_relocate_nooverlap_mapping_NO_NOTIFY)( 
                 Addr old_addr, Addr old_len, 
                 Addr new_addr, Addr new_len 
              );

/* There is also VG_(do_mmap_NO_NOTIFY), but that's not declared
   here (obviously). */

extern SysRes ML_(am_open)  ( const HChar* pathname, Int flags, Int mode );
extern void   ML_(am_close) ( Int fd );
extern Int    ML_(am_read)  ( Int fd, void* buf, Int count);
extern Int    ML_(am_readlink) ( const HChar* path, HChar* buf, UInt bufsiz );
extern Int    ML_(am_fcntl) ( Int fd, Int cmd, Addr arg );

/* Get the dev, inode and mode info for a file descriptor, if
   possible.  Returns True on success. */
extern
Bool ML_(am_get_fd_d_i_m)( Int fd, 
                           /*OUT*/ULong* dev, 
                           /*OUT*/ULong* ino, /*OUT*/UInt* mode );

extern
Bool ML_(am_resolve_filename) ( Int fd, /*OUT*/HChar* buf, Int nbuf );

/* ------ Implemented separately in aspacemgr-linux.c ------ */

/* Do a sanity check (/proc/self/maps sync check) */
extern void ML_(am_do_sanity_check)( void );


/* ------ Implemented in aspacemgr-segnames.c ------ */
void ML_(am_segnames_init)(void);
void ML_(am_show_segnames)(Int logLevel, const HChar *prefix);

/* Put NAME into the string table of segment names. Return index for
   future reference. A return value of -1 indicates that the segment name
   could not be stored. Basically an out-of-memory situation. */
Int ML_(am_allocate_segname)(const HChar *name);

/* Increment / decrement the reference counter for this segment name. */
void ML_(am_inc_refcount)(Int);
void ML_(am_dec_refcount)(Int);

/* Check whether the segname index is sane. */
Bool ML_(am_sane_segname)(Int fnIdx);

/* Return the segment name for the given index. Maybe return NULL, if the
   segment does not have a name. */
const HChar *ML_(am_get_segname)(Int fnIdx);

/* Return the sequence number of the segment name */
Int ML_(am_segname_get_seqnr)(Int fnIdx);

#endif   // __PRIV_ASPACEMGR_H

/*--------------------------------------------------------------------*/
/*--- end                                                          ---*/
/*--------------------------------------------------------------------*/