1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2 /*
3 * Copyright (c) 2004-2007 High Performance Computing Center Stuttgart,
4 * University of Stuttgart. All rights reserved.
5 * Copyright (c) 2004-2008 The Trustees of Indiana University.
6 * All rights reserved.
7 * Copyright (c) 2015 Los Alamos National Security, LLC. All rights
8 * reserved.
9 *
10 * $COPYRIGHT$
11 *
12 * Additional copyrights may follow
13 *
14 * $HEADER$
15 */
16
17 /**
18 * @file
19 *
20 * memchecker (memory checker) framework component interface.
21 *
22 * Intent
23 *
24 * This is a very thin framework to abstract memory checking tools,
25 * such as valgrind and possibly Sun rtc (memory checking available
26 * possibly only under Solaris/Sparc).
27 *
28 * Currently, only functionality for hiding and unhiding of memory
29 * is added; further functions provided by the memory checker/api
30 * checker could be added, however, this comes (at least for valgrind)
31 * with considerable overhead.
32 * One possible option would be to have error_print_callbacks, that
33 * output different error messages, depending on the memory location
34 * being hit by certain error.
35 */
36
37 #ifndef OPAL_MCA_MEMCHECKER_MEMCHECKER_H
38 #define OPAL_MCA_MEMCHECKER_MEMCHECKER_H
39
40 #include "opal_config.h"
41
42 #include "opal/mca/mca.h"
43 #include "opal/mca/base/base.h"
44
45 /**
46 * Module initialization function. Should return OPAL_SUCCESS.
47 */
48 typedef int (*opal_memchecker_base_module_init_1_0_0_fn_t)(void);
49
50 /**
51 * Module function to query, whether we're under the memory
52 * checking program, like valgrind
53 */
54 typedef int (*opal_memchecker_base_module_runindebugger_fn_t)(void);
55
56 /**
57 * Module function to check, whether memory region is addressable
58 */
59 typedef int (*opal_memchecker_base_module_isaddressable_fn_t)(void * p, size_t len);
60
61 /**
62 * Module function to check, whether memory region is defined
63 */
64 typedef int (*opal_memchecker_base_module_isdefined_fn_t)(void * p, size_t len);
65
66 /**
67 * Module function to set memory region to not accessible
68 */
69 typedef int (*opal_memchecker_base_module_mem_noaccess_fn_t)(void * p, size_t len);
70
71 /**
72 * Module function to set memory region to undefined
73 */
74 typedef int (*opal_memchecker_base_module_mem_undefined_fn_t)(void * p, size_t len);
75
76 /**
77 * Module function to set memory region to defined
78 */
79 typedef int (*opal_memchecker_base_module_mem_defined_fn_t)(void * p, size_t len);
80
81 /**
82 * Module function to set memory region to defined, but only if addressable
83 */
84 typedef int (*opal_memchecker_base_module_mem_defined_if_addressable_fn_t)(void * p, size_t len);
85
86 /**
87 * Module function name a specific memory region
88 */
89 typedef int (*opal_memchecker_base_module_create_block_fn_t)(void * p, size_t len, char * description);
90
91 /**
92 * Module function to discard a named memory region
93 */
94 typedef int (*opal_memchecker_base_module_discard_block_fn_t)(void * p); /* Here, we need to do some mapping for valgrind */
95
96 /**
97 * Module function to check for any leaks
98 */
99 typedef int (*opal_memchecker_base_module_leakcheck_fn_t)(void);
100
101 /**
102 * Module function to get vbits
103 */
104 typedef int (*opal_memchecker_base_module_get_vbits_fn_t)(void * p, char * vbits, size_t len);
105
106 /**
107 * Module function to set vbits
108 */
109 typedef int (*opal_memchecker_base_module_set_vbits_fn_t)(void * p, char * vbits, size_t len);
110
111
112
113 /**
114 * Structure for memchecker components.
115 */
116 struct opal_memchecker_base_component_2_0_0_t {
117 /** MCA base component */
118 mca_base_component_t base_version;
119 /** MCA base data */
120 mca_base_component_data_t base_data;
121 };
122
123 /**
124 * Convenience typedef
125 */
126 typedef struct opal_memchecker_base_component_2_0_0_t opal_memchecker_base_component_2_0_0_t;
127 typedef struct opal_memchecker_base_component_2_0_0_t opal_memchecker_base_component_t;
128
129 /**
130 * Structure for memchecker modules
131 */
132 struct opal_memchecker_base_module_1_0_0_t {
133 /** Module initialization function */
134 opal_memchecker_base_module_init_1_0_0_fn_t init;
135
136 /** Module function to check, whether we are executed by memory debugger */
137 opal_memchecker_base_module_runindebugger_fn_t runindebugger;
138
139 /** Module function to check, whether memory region is addressable */
140 opal_memchecker_base_module_isaddressable_fn_t isaddressable;
141
142 /** Module function to check, whether memory region is defined */
143 opal_memchecker_base_module_isdefined_fn_t isdefined;
144
145 /** Module function to set memory region to not accessible */
146 opal_memchecker_base_module_mem_noaccess_fn_t mem_noaccess;
147
148 /** Module function to set memory region to undefined */
149 opal_memchecker_base_module_mem_undefined_fn_t mem_undefined;
150
151 /** Module function to set memory region to defined */
152 opal_memchecker_base_module_mem_defined_fn_t mem_defined;
153
154 /** Module function to set memory region to defined, but only if addressable */
155 opal_memchecker_base_module_mem_defined_if_addressable_fn_t mem_defined_if_addressable;
156
157 /** Module function name a specific memory region */
158 opal_memchecker_base_module_create_block_fn_t create_block;
159
160 /** Module function to discard a named memory region */
161 opal_memchecker_base_module_discard_block_fn_t discard_block;
162
163 /** Module function to check for any leaks */
164 opal_memchecker_base_module_leakcheck_fn_t leakcheck;
165
166 /** Module function to get vbits */
167 opal_memchecker_base_module_get_vbits_fn_t get_vbits;
168
169 /** Module function to set vbits */
170 opal_memchecker_base_module_set_vbits_fn_t set_vbits;
171 };
172
173 /**
174 * Convenience typedef
175 */
176 typedef struct opal_memchecker_base_module_1_0_0_t opal_memchecker_base_module_1_0_0_t;
177 typedef struct opal_memchecker_base_module_1_0_0_t opal_memchecker_base_module_t;
178
179
180 /**
181 * Macro for use in components that are of type memchecker
182 */
183 #define OPAL_MEMCHECKER_BASE_VERSION_2_0_0 \
184 OPAL_MCA_BASE_VERSION_2_1_0("memchecker", 2, 0, 0)
185
186 #endif /* OPAL_MCA_MEMCHECKER_MEMCHECKER_H */