Skip to content

Commit 15c7907

Browse files
committed
[sanitizer_common] Move container overflow declarations into new file
Currently the ASan container overflow function declarations live in the common_interface_defs.h file. In order to allow libcxx to directly use these declarations, rather than forward declaring them, we need to prefix all identifiers with '__'. To minimize the impact of that we can break the effected functions out into a separate file, and alter only these. This patch does the above.
1 parent 0e8222b commit 15c7907

File tree

2 files changed

+280
-244
lines changed

2 files changed

+280
-244
lines changed

compiler-rt/include/sanitizer/common_interface_defs.h

Lines changed: 5 additions & 244 deletions
Original file line numberDiff line numberDiff line change
@@ -110,250 +110,11 @@ void SANITIZER_CDECL __sanitizer_unaligned_store64(void *p, uint64_t x);
110110
// simultaneously.
111111
int SANITIZER_CDECL __sanitizer_acquire_crash_state();
112112

113-
/// Annotates the current state of a contiguous container, such as
114-
/// <c>std::vector</c>, <c>std::string</c>, or similar.
115-
///
116-
/// A contiguous container is a container that keeps all of its elements
117-
/// in a contiguous region of memory. The container owns the region of memory
118-
/// <c>[beg, end)</c>; the memory <c>[beg, mid)</c> is used to store the
119-
/// current elements, and the memory <c>[mid, end)</c> is reserved for future
120-
/// elements (<c>beg <= mid <= end</c>). For example, in
121-
/// <c>std::vector<> v</c>:
122-
///
123-
/// \code
124-
/// beg = &v[0];
125-
/// end = beg + v.capacity() * sizeof(v[0]);
126-
/// mid = beg + v.size() * sizeof(v[0]);
127-
/// \endcode
128-
///
129-
/// This annotation tells the Sanitizer tool about the current state of the
130-
/// container so that the tool can report errors when memory from
131-
/// <c>[mid, end)</c> is accessed. Insert this annotation into methods like
132-
/// <c>push_back()</c> or <c>pop_back()</c>. Supply the old and new values of
133-
/// <c>mid</c>(<c><i>old_mid</i></c> and <c><i>new_mid</i></c>). In the initial
134-
/// state <c>mid == end</c>, so that should be the final state when the
135-
/// container is destroyed or when the container reallocates the storage.
136-
///
137-
/// For ASan, <c><i>beg</i></c> no longer needs to be 8-aligned,
138-
/// first and last granule may be shared with other objects
139-
/// and therefore the function can be used for any allocator.
140-
///
141-
/// The following example shows how to use the function:
142-
///
143-
/// \code
144-
/// int32_t x[3]; // 12 bytes
145-
/// char *beg = (char*)&x[0];
146-
/// char *end = beg + 12;
147-
/// __sanitizer_annotate_contiguous_container(beg, end, beg, end);
148-
/// \endcode
149-
///
150-
/// \note Use this function with caution and do not use for anything other
151-
/// than vector-like classes.
152-
/// \note Unaligned <c><i>beg</i></c> or <c><i>end</i></c> may miss bugs in
153-
/// these granules.
154-
///
155-
/// \param beg Beginning of memory region.
156-
/// \param end End of memory region.
157-
/// \param old_mid Old middle of memory region.
158-
/// \param new_mid New middle of memory region.
159-
#ifdef __SANITIZER_DISABLE_CONTAINER_OVERFLOW__
160-
__attribute__((__internal_linkage__)) inline void SANITIZER_CDECL
161-
__sanitizer_annotate_contiguous_container(const void *beg, const void *end,
162-
const void *old_mid,
163-
const void *new_mid) {}
164-
#else
165-
void SANITIZER_CDECL __sanitizer_annotate_contiguous_container(
166-
const void *beg, const void *end, const void *old_mid, const void *new_mid);
167-
#endif
168-
169-
/// Similar to <c>__sanitizer_annotate_contiguous_container</c>.
170-
///
171-
/// Annotates the current state of a contiguous container memory,
172-
/// such as <c>std::deque</c>'s single chunk, when the boundries are moved.
173-
///
174-
/// A contiguous chunk is a chunk that keeps all of its elements
175-
/// in a contiguous region of memory. The container owns the region of memory
176-
/// <c>[storage_beg, storage_end)</c>; the memory <c>[container_beg,
177-
/// container_end)</c> is used to store the current elements, and the memory
178-
/// <c>[storage_beg, container_beg), [container_end, storage_end)</c> is
179-
/// reserved for future elements (<c>storage_beg <= container_beg <=
180-
/// container_end <= storage_end</c>). For example, in <c> std::deque </c>:
181-
/// - chunk with a frist deques element will have container_beg equal to address
182-
/// of the first element.
183-
/// - in every next chunk with elements, true is <c> container_beg ==
184-
/// storage_beg </c>.
185-
///
186-
/// Argument requirements:
187-
/// During unpoisoning memory of empty container (before first element is
188-
/// added):
189-
/// - old_container_beg_p == old_container_end_p
190-
/// During poisoning after last element was removed:
191-
/// - new_container_beg_p == new_container_end_p
192-
/// \param storage_beg Beginning of memory region.
193-
/// \param storage_end End of memory region.
194-
/// \param old_container_beg Old beginning of used region.
195-
/// \param old_container_end End of used region.
196-
/// \param new_container_beg New beginning of used region.
197-
/// \param new_container_end New end of used region.
198-
#ifdef __SANITIZER_DISABLE_CONTAINER_OVERFLOW__
199-
__attribute__((__internal_linkage__)) inline void
200-
SANITIZER_CDECL __sanitizer_annotate_double_ended_contiguous_container(
201-
const void *storage_beg, const void *storage_end,
202-
const void *old_container_beg, const void *old_container_end,
203-
const void *new_container_beg, const void *new_container_end) {}
204-
#else
205-
void SANITIZER_CDECL __sanitizer_annotate_double_ended_contiguous_container(
206-
const void *storage_beg, const void *storage_end,
207-
const void *old_container_beg, const void *old_container_end,
208-
const void *new_container_beg, const void *new_container_end);
209-
#endif
210-
211-
/// Copies memory annotations from a source storage region to a destination
212-
/// storage region. After the operation, the destination region has the same
213-
/// memory annotations as the source region, as long as sanitizer limitations
214-
/// allow it (more bytes may be unpoisoned than in the source region, resulting
215-
/// in more false negatives, but never false positives). If the source and
216-
/// destination regions overlap, only the minimal required changes are made to
217-
/// preserve the correct annotations. Old storage bytes that are not in the new
218-
/// storage should have the same annotations, as long as sanitizer limitations
219-
/// allow it.
220-
///
221-
/// This function is primarily designed to be used when moving trivially
222-
/// relocatable objects that may have poisoned memory, making direct copying
223-
/// problematic under sanitizer. However, this function does not move memory
224-
/// content itself, only annotations.
225-
///
226-
/// A contiguous container is a container that keeps all of its elements in a
227-
/// contiguous region of memory. The container owns the region of memory
228-
/// <c>[src_begin, src_end)</c> and <c>[dst_begin, dst_end)</c>. The memory
229-
/// within these regions may be alternately poisoned and non-poisoned, with
230-
/// possibly smaller poisoned and unpoisoned regions.
231-
///
232-
/// If this function fully poisons a granule, it is marked as "container
233-
/// overflow".
234-
///
235-
/// Argument requirements: The destination container must have the same size as
236-
/// the source container, which is inferred from the beginning and end of the
237-
/// source region. Addresses may be granule-unaligned, but this may affect
238-
/// performance.
239-
///
240-
/// \param src_begin Begin of the source container region.
241-
/// \param src_end End of the source container region.
242-
/// \param dst_begin Begin of the destination container region.
243-
/// \param dst_end End of the destination container region.
244-
#ifdef __SANITIZER_DISABLE_CONTAINER_OVERFLOW__
245-
__attribute__((__internal_linkage__)) inline void SANITIZER_CDECL
246-
__sanitizer_copy_contiguous_container_annotations(const void *src_begin,
247-
const void *src_end,
248-
const void *dst_begin,
249-
const void *dst_end) {}
250-
#else
251-
void SANITIZER_CDECL __sanitizer_copy_contiguous_container_annotations(
252-
const void *src_begin, const void *src_end, const void *dst_begin,
253-
const void *dst_end);
254-
#endif
255-
256-
/// Returns true if the contiguous container <c>[beg, end)</c> is properly
257-
/// poisoned.
258-
///
259-
/// Proper poisoning could occur, for example, with
260-
/// <c>__sanitizer_annotate_contiguous_container</c>), that is, if
261-
/// <c>[beg, mid)</c> is addressable and <c>[mid, end)</c> is unaddressable.
262-
/// Full verification requires O (<c>end - beg</c>) time; this function tries
263-
/// to avoid such complexity by touching only parts of the container around
264-
/// <c><i>beg</i></c>, <c><i>mid</i></c>, and <c><i>end</i></c>.
265-
///
266-
/// \param beg Beginning of memory region.
267-
/// \param mid Middle of memory region.
268-
/// \param end Old end of memory region.
269-
///
270-
/// \returns True if the contiguous container <c>[beg, end)</c> is properly
271-
/// poisoned.
272-
#ifdef __SANITIZER_DISABLE_CONTAINER_OVERFLOW__
273-
__attribute__((__internal_linkage__)) inline int
274-
SANITIZER_CDECL __sanitizer_verify_contiguous_container(const void *beg,
275-
const void *mid,
276-
const void *end) {}
277-
#else
278-
int SANITIZER_CDECL __sanitizer_verify_contiguous_container(const void *beg,
279-
const void *mid,
280-
const void *end);
281-
#endif
282-
283-
/// Returns true if the double ended contiguous
284-
/// container <c>[storage_beg, storage_end)</c> is properly poisoned.
285-
///
286-
/// Proper poisoning could occur, for example, with
287-
/// <c>__sanitizer_annotate_double_ended_contiguous_container</c>), that is, if
288-
/// <c>[storage_beg, container_beg)</c> is not addressable, <c>[container_beg,
289-
/// container_end)</c> is addressable and <c>[container_end, end)</c> is
290-
/// unaddressable. Full verification requires O (<c>storage_end -
291-
/// storage_beg</c>) time; this function tries to avoid such complexity by
292-
/// touching only parts of the container around <c><i>storage_beg</i></c>,
293-
/// <c><i>container_beg</i></c>, <c><i>container_end</i></c>, and
294-
/// <c><i>storage_end</i></c>.
295-
///
296-
/// \param storage_beg Beginning of memory region.
297-
/// \param container_beg Beginning of used region.
298-
/// \param container_end End of used region.
299-
/// \param storage_end End of memory region.
300-
///
301-
/// \returns True if the double-ended contiguous container <c>[storage_beg,
302-
/// container_beg, container_end, end)</c> is properly poisoned - only
303-
/// [container_beg; container_end) is addressable.
304-
#ifdef __SANITIZER_DISABLE_CONTAINER_OVERFLOW__
305-
__attribute__((__internal_linkage__)) inline int SANITIZER_CDECL
306-
__sanitizer_verify_double_ended_contiguous_container(const void *storage_beg,
307-
const void *container_beg,
308-
const void *container_end,
309-
const void *storage_end) {}
310-
#else
311-
int SANITIZER_CDECL __sanitizer_verify_double_ended_contiguous_container(
312-
const void *storage_beg, const void *container_beg,
313-
const void *container_end, const void *storage_end);
314-
#endif
315-
316-
/// Similar to <c>__sanitizer_verify_contiguous_container()</c> but also
317-
/// returns the address of the first improperly poisoned byte.
318-
///
319-
/// Returns NULL if the area is poisoned properly.
320-
///
321-
/// \param beg Beginning of memory region.
322-
/// \param mid Middle of memory region.
323-
/// \param end Old end of memory region.
324-
///
325-
/// \returns The bad address or NULL.
326-
#ifdef __SANITIZER_DISABLE_CONTAINER_OVERFLOW__
327-
__attribute__((__internal_linkage__)) inline const void *SANITIZER_CDECL
328-
__sanitizer_contiguous_container_find_bad_address(const void *beg,
329-
const void *mid,
330-
const void *end) {}
331-
#else
332-
const void *SANITIZER_CDECL __sanitizer_contiguous_container_find_bad_address(
333-
const void *beg, const void *mid, const void *end);
334-
#endif
335-
336-
/// returns the address of the first improperly poisoned byte.
337-
///
338-
/// Returns NULL if the area is poisoned properly.
339-
///
340-
/// \param storage_beg Beginning of memory region.
341-
/// \param container_beg Beginning of used region.
342-
/// \param container_end End of used region.
343-
/// \param storage_end End of memory region.
344-
///
345-
/// \returns The bad address or NULL.
346-
#ifdef __SANITIZER_DISABLE_CONTAINER_OVERFLOW__
347-
__attribute__((__internal_linkage__)) inline const void *SANITIZER_CDECL
348-
__sanitizer_double_ended_contiguous_container_find_bad_address(
349-
const void *storage_beg, const void *container_beg,
350-
const void *container_end, const void *storage_end) {}
351-
#else
352-
const void *SANITIZER_CDECL
353-
__sanitizer_double_ended_contiguous_container_find_bad_address(
354-
const void *storage_beg, const void *container_beg,
355-
const void *container_end, const void *storage_end);
356-
#endif
113+
// The container overflow function declarations used to be inline here, but in
114+
// order to allow libcxx to directly use the header they are now in a separate
115+
// file. This file is included here to avoid breaking anyone reliant on
116+
// the definitions appearing in the current file.
117+
#include "container_overflow_defs.h"
357118

358119
/// Prints the stack trace leading to this call (useful for calling from the
359120
/// debugger).

0 commit comments

Comments
 (0)