xref: /openbsd-src/gnu/llvm/compiler-rt/include/sanitizer/common_interface_defs.h (revision 810390e339a5425391477d5d41c78d7cab2424ac)
13cab2bb3Spatrick //===-- sanitizer/common_interface_defs.h -----------------------*- C++ -*-===//
23cab2bb3Spatrick //
33cab2bb3Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
43cab2bb3Spatrick // See https://llvm.org/LICENSE.txt for license information.
53cab2bb3Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
63cab2bb3Spatrick //
73cab2bb3Spatrick //===----------------------------------------------------------------------===//
83cab2bb3Spatrick //
93cab2bb3Spatrick // Common part of the public sanitizer interface.
103cab2bb3Spatrick //===----------------------------------------------------------------------===//
113cab2bb3Spatrick 
123cab2bb3Spatrick #ifndef SANITIZER_COMMON_INTERFACE_DEFS_H
133cab2bb3Spatrick #define SANITIZER_COMMON_INTERFACE_DEFS_H
143cab2bb3Spatrick 
153cab2bb3Spatrick #include <stddef.h>
163cab2bb3Spatrick #include <stdint.h>
173cab2bb3Spatrick 
183cab2bb3Spatrick // GCC does not understand __has_feature.
193cab2bb3Spatrick #if !defined(__has_feature)
203cab2bb3Spatrick #define __has_feature(x) 0
213cab2bb3Spatrick #endif
223cab2bb3Spatrick 
233cab2bb3Spatrick #ifdef __cplusplus
243cab2bb3Spatrick extern "C" {
253cab2bb3Spatrick #endif
263cab2bb3Spatrick // Arguments for __sanitizer_sandbox_on_notify() below.
273cab2bb3Spatrick typedef struct {
283cab2bb3Spatrick   // Enable sandbox support in sanitizer coverage.
293cab2bb3Spatrick   int coverage_sandboxed;
303cab2bb3Spatrick   // File descriptor to write coverage data to. If -1 is passed, a file will
31*810390e3Srobert   // be pre-opened by __sanitizer_sandbox_on_notify(). This field has no
323cab2bb3Spatrick   // effect if coverage_sandboxed == 0.
333cab2bb3Spatrick   intptr_t coverage_fd;
343cab2bb3Spatrick   // If non-zero, split the coverage data into well-formed blocks. This is
353cab2bb3Spatrick   // useful when coverage_fd is a socket descriptor. Each block will contain
363cab2bb3Spatrick   // a header, allowing data from multiple processes to be sent over the same
373cab2bb3Spatrick   // socket.
383cab2bb3Spatrick   unsigned int coverage_max_block_size;
393cab2bb3Spatrick } __sanitizer_sandbox_arguments;
403cab2bb3Spatrick 
413cab2bb3Spatrick // Tell the tools to write their reports to "path.<pid>" instead of stderr.
423cab2bb3Spatrick void __sanitizer_set_report_path(const char *path);
433cab2bb3Spatrick // Tell the tools to write their reports to the provided file descriptor
443cab2bb3Spatrick // (casted to void *).
453cab2bb3Spatrick void __sanitizer_set_report_fd(void *fd);
46d89ec533Spatrick // Get the current full report file path, if a path was specified by
47d89ec533Spatrick // an earlier call to __sanitizer_set_report_path. Returns null otherwise.
48d89ec533Spatrick const char *__sanitizer_get_report_path();
493cab2bb3Spatrick 
503cab2bb3Spatrick // Notify the tools that the sandbox is going to be turned on. The reserved
513cab2bb3Spatrick // parameter will be used in the future to hold a structure with functions
523cab2bb3Spatrick // that the tools may call to bypass the sandbox.
533cab2bb3Spatrick void __sanitizer_sandbox_on_notify(__sanitizer_sandbox_arguments *args);
543cab2bb3Spatrick 
553cab2bb3Spatrick // This function is called by the tool when it has just finished reporting
563cab2bb3Spatrick // an error. 'error_summary' is a one-line string that summarizes
573cab2bb3Spatrick // the error message. This function can be overridden by the client.
583cab2bb3Spatrick void __sanitizer_report_error_summary(const char *error_summary);
593cab2bb3Spatrick 
603cab2bb3Spatrick // Some of the sanitizers (for example ASan/TSan) could miss bugs that happen
613cab2bb3Spatrick // in unaligned loads/stores. To find such bugs reliably, you need to replace
623cab2bb3Spatrick // plain unaligned loads/stores with these calls.
633cab2bb3Spatrick 
643cab2bb3Spatrick /// Loads a 16-bit unaligned value.
653cab2bb3Spatrick ///
663cab2bb3Spatrick /// \param p Pointer to unaligned memory.
673cab2bb3Spatrick ///
683cab2bb3Spatrick /// \returns Loaded value.
693cab2bb3Spatrick uint16_t __sanitizer_unaligned_load16(const void *p);
703cab2bb3Spatrick 
713cab2bb3Spatrick /// Loads a 32-bit unaligned value.
723cab2bb3Spatrick ///
733cab2bb3Spatrick /// \param p Pointer to unaligned memory.
743cab2bb3Spatrick ///
753cab2bb3Spatrick /// \returns Loaded value.
763cab2bb3Spatrick uint32_t __sanitizer_unaligned_load32(const void *p);
773cab2bb3Spatrick 
783cab2bb3Spatrick /// Loads a 64-bit unaligned value.
793cab2bb3Spatrick ///
803cab2bb3Spatrick /// \param p Pointer to unaligned memory.
813cab2bb3Spatrick ///
823cab2bb3Spatrick /// \returns Loaded value.
833cab2bb3Spatrick uint64_t __sanitizer_unaligned_load64(const void *p);
843cab2bb3Spatrick 
853cab2bb3Spatrick /// Stores a 16-bit unaligned value.
863cab2bb3Spatrick ///
873cab2bb3Spatrick /// \param p Pointer to unaligned memory.
883cab2bb3Spatrick /// \param x 16-bit value to store.
893cab2bb3Spatrick void __sanitizer_unaligned_store16(void *p, uint16_t x);
903cab2bb3Spatrick 
913cab2bb3Spatrick /// Stores a 32-bit unaligned value.
923cab2bb3Spatrick ///
933cab2bb3Spatrick /// \param p Pointer to unaligned memory.
943cab2bb3Spatrick /// \param x 32-bit value to store.
953cab2bb3Spatrick void __sanitizer_unaligned_store32(void *p, uint32_t x);
963cab2bb3Spatrick 
973cab2bb3Spatrick /// Stores a 64-bit unaligned value.
983cab2bb3Spatrick ///
993cab2bb3Spatrick /// \param p Pointer to unaligned memory.
1003cab2bb3Spatrick /// \param x 64-bit value to store.
1013cab2bb3Spatrick void __sanitizer_unaligned_store64(void *p, uint64_t x);
1023cab2bb3Spatrick 
1033cab2bb3Spatrick // Returns 1 on the first call, then returns 0 thereafter.  Called by the tool
1043cab2bb3Spatrick // to ensure only one report is printed when multiple errors occur
1053cab2bb3Spatrick // simultaneously.
1063cab2bb3Spatrick int __sanitizer_acquire_crash_state();
1073cab2bb3Spatrick 
1083cab2bb3Spatrick /// Annotates the current state of a contiguous container, such as
1093cab2bb3Spatrick /// <c>std::vector</c>, <c>std::string</c>, or similar.
1103cab2bb3Spatrick ///
1113cab2bb3Spatrick /// A contiguous container is a container that keeps all of its elements
1123cab2bb3Spatrick /// in a contiguous region of memory. The container owns the region of memory
1133cab2bb3Spatrick /// <c>[beg, end)</c>; the memory <c>[beg, mid)</c> is used to store the
1143cab2bb3Spatrick /// current elements, and the memory <c>[mid, end)</c> is reserved for future
1153cab2bb3Spatrick /// elements (<c>beg <= mid <= end</c>). For example, in
1163cab2bb3Spatrick /// <c>std::vector<> v</c>:
1173cab2bb3Spatrick ///
1183cab2bb3Spatrick /// \code
1193cab2bb3Spatrick ///   beg = &v[0];
1203cab2bb3Spatrick ///   end = beg + v.capacity() * sizeof(v[0]);
1213cab2bb3Spatrick ///   mid = beg + v.size()     * sizeof(v[0]);
1223cab2bb3Spatrick /// \endcode
1233cab2bb3Spatrick ///
1243cab2bb3Spatrick /// This annotation tells the Sanitizer tool about the current state of the
1253cab2bb3Spatrick /// container so that the tool can report errors when memory from
1263cab2bb3Spatrick /// <c>[mid, end)</c> is accessed. Insert this annotation into methods like
1273cab2bb3Spatrick /// <c>push_back()</c> or <c>pop_back()</c>. Supply the old and new values of
1283cab2bb3Spatrick /// <c>mid</c>(<c><i>old_mid</i></c> and <c><i>new_mid</i></c>). In the initial
1293cab2bb3Spatrick /// state <c>mid == end</c>, so that should be the final state when the
1303cab2bb3Spatrick /// container is destroyed or when the container reallocates the storage.
1313cab2bb3Spatrick ///
1323cab2bb3Spatrick /// For ASan, <c><i>beg</i></c> should be 8-aligned and <c><i>end</i></c>
1333cab2bb3Spatrick /// should be either 8-aligned or it should point to the end of a separate
1343cab2bb3Spatrick /// heap-, stack-, or global-allocated buffer. So the following example will
1353cab2bb3Spatrick /// not work:
1363cab2bb3Spatrick ///
1373cab2bb3Spatrick /// \code
1383cab2bb3Spatrick ///   int64_t x[2]; // 16 bytes, 8-aligned
1393cab2bb3Spatrick ///   char *beg = (char *)&x[0];
1403cab2bb3Spatrick ///   char *end = beg + 12; // Not 8-aligned, not the end of the buffer
1413cab2bb3Spatrick /// \endcode
1423cab2bb3Spatrick ///
1433cab2bb3Spatrick /// The following, however, will work:
1443cab2bb3Spatrick /// \code
1453cab2bb3Spatrick ///   int32_t x[3]; // 12 bytes, but 8-aligned under ASan.
1463cab2bb3Spatrick ///   char *beg = (char*)&x[0];
1473cab2bb3Spatrick ///   char *end = beg + 12; // Not 8-aligned, but is the end of the buffer
1483cab2bb3Spatrick /// \endcode
1493cab2bb3Spatrick ///
1503cab2bb3Spatrick /// \note  Use this function with caution and do not use for anything other
1513cab2bb3Spatrick /// than vector-like classes.
1523cab2bb3Spatrick ///
1533cab2bb3Spatrick /// \param beg Beginning of memory region.
1543cab2bb3Spatrick /// \param end End of memory region.
1553cab2bb3Spatrick /// \param old_mid Old middle of memory region.
1563cab2bb3Spatrick /// \param new_mid New middle of memory region.
1573cab2bb3Spatrick void __sanitizer_annotate_contiguous_container(const void *beg,
1583cab2bb3Spatrick                                                const void *end,
1593cab2bb3Spatrick                                                const void *old_mid,
1603cab2bb3Spatrick                                                const void *new_mid);
1613cab2bb3Spatrick 
162*810390e3Srobert /// Similar to <c>__sanitizer_annotate_contiguous_container</c>.
163*810390e3Srobert ///
164*810390e3Srobert /// Annotates the current state of a contiguous container memory,
165*810390e3Srobert /// such as <c>std::deque</c>'s single chunk, when the boundries are moved.
166*810390e3Srobert ///
167*810390e3Srobert /// A contiguous chunk is a chunk that keeps all of its elements
168*810390e3Srobert /// in a contiguous region of memory. The container owns the region of memory
169*810390e3Srobert /// <c>[storage_beg, storage_end)</c>; the memory <c>[container_beg,
170*810390e3Srobert /// container_end)</c> is used to store the current elements, and the memory
171*810390e3Srobert /// <c>[storage_beg, container_beg), [container_end, storage_end)</c> is
172*810390e3Srobert /// reserved for future elements (<c>storage_beg <= container_beg <=
173*810390e3Srobert /// container_end <= storage_end</c>). For example, in <c> std::deque </c>:
174*810390e3Srobert /// - chunk with a frist deques element will have container_beg equal to address
175*810390e3Srobert ///  of the first element.
176*810390e3Srobert /// - in every next chunk with elements, true is  <c> container_beg ==
177*810390e3Srobert /// storage_beg </c>.
178*810390e3Srobert ///
179*810390e3Srobert /// Argument requirements:
180*810390e3Srobert /// During unpoisoning memory of empty container (before first element is
181*810390e3Srobert /// added):
182*810390e3Srobert /// - old_container_beg_p == old_container_end_p
183*810390e3Srobert /// During poisoning after last element was removed:
184*810390e3Srobert /// - new_container_beg_p == new_container_end_p
185*810390e3Srobert /// \param storage_beg Beginning of memory region.
186*810390e3Srobert /// \param storage_end End of memory region.
187*810390e3Srobert /// \param old_container_beg Old beginning of used region.
188*810390e3Srobert /// \param old_container_end End of used region.
189*810390e3Srobert /// \param new_container_beg New beginning of used region.
190*810390e3Srobert /// \param new_container_end New end of used region.
191*810390e3Srobert void __sanitizer_annotate_double_ended_contiguous_container(
192*810390e3Srobert     const void *storage_beg, const void *storage_end,
193*810390e3Srobert     const void *old_container_beg, const void *old_container_end,
194*810390e3Srobert     const void *new_container_beg, const void *new_container_end);
195*810390e3Srobert 
1963cab2bb3Spatrick /// Returns true if the contiguous container <c>[beg, end)</c> is properly
1973cab2bb3Spatrick /// poisoned.
1983cab2bb3Spatrick ///
1993cab2bb3Spatrick /// Proper poisoning could occur, for example, with
2003cab2bb3Spatrick /// <c>__sanitizer_annotate_contiguous_container</c>), that is, if
2013cab2bb3Spatrick /// <c>[beg, mid)</c> is addressable and <c>[mid, end)</c> is unaddressable.
2023cab2bb3Spatrick /// Full verification requires O (<c>end - beg</c>) time; this function tries
2033cab2bb3Spatrick /// to avoid such complexity by touching only parts of the container around
2043cab2bb3Spatrick /// <c><i>beg</i></c>, <c><i>mid</i></c>, and <c><i>end</i></c>.
2053cab2bb3Spatrick ///
2063cab2bb3Spatrick /// \param beg Beginning of memory region.
2073cab2bb3Spatrick /// \param mid Middle of memory region.
2083cab2bb3Spatrick /// \param end Old end of memory region.
2093cab2bb3Spatrick ///
2103cab2bb3Spatrick /// \returns True if the contiguous container <c>[beg, end)</c> is properly
2113cab2bb3Spatrick ///  poisoned.
2123cab2bb3Spatrick int __sanitizer_verify_contiguous_container(const void *beg, const void *mid,
2133cab2bb3Spatrick                                             const void *end);
2143cab2bb3Spatrick 
215*810390e3Srobert /// Returns true if the double ended contiguous
216*810390e3Srobert /// container <c>[storage_beg, storage_end)</c> is properly poisoned.
217*810390e3Srobert ///
218*810390e3Srobert /// Proper poisoning could occur, for example, with
219*810390e3Srobert /// <c>__sanitizer_annotate_double_ended_contiguous_container</c>), that is, if
220*810390e3Srobert /// <c>[storage_beg, container_beg)</c> is not addressable, <c>[container_beg,
221*810390e3Srobert /// container_end)</c> is addressable and <c>[container_end, end)</c> is
222*810390e3Srobert /// unaddressable. Full verification requires O (<c>storage_end -
223*810390e3Srobert /// storage_beg</c>) time; this function tries to avoid such complexity by
224*810390e3Srobert /// touching only parts of the container around <c><i>storage_beg</i></c>,
225*810390e3Srobert /// <c><i>container_beg</i></c>, <c><i>container_end</i></c>, and
226*810390e3Srobert /// <c><i>storage_end</i></c>.
227*810390e3Srobert ///
228*810390e3Srobert /// \param storage_beg Beginning of memory region.
229*810390e3Srobert /// \param container_beg Beginning of used region.
230*810390e3Srobert /// \param container_end End of used region.
231*810390e3Srobert /// \param storage_end End of memory region.
232*810390e3Srobert ///
233*810390e3Srobert /// \returns True if the double-ended contiguous container <c>[storage_beg,
234*810390e3Srobert /// container_beg, container_end, end)</c> is properly poisoned - only
235*810390e3Srobert /// [container_beg; container_end) is addressable.
236*810390e3Srobert int __sanitizer_verify_double_ended_contiguous_container(
237*810390e3Srobert     const void *storage_beg, const void *container_beg,
238*810390e3Srobert     const void *container_end, const void *storage_end);
239*810390e3Srobert 
2403cab2bb3Spatrick /// Similar to <c>__sanitizer_verify_contiguous_container()</c> but also
2413cab2bb3Spatrick /// returns the address of the first improperly poisoned byte.
2423cab2bb3Spatrick ///
2433cab2bb3Spatrick /// Returns NULL if the area is poisoned properly.
2443cab2bb3Spatrick ///
2453cab2bb3Spatrick /// \param beg Beginning of memory region.
2463cab2bb3Spatrick /// \param mid Middle of memory region.
2473cab2bb3Spatrick /// \param end Old end of memory region.
2483cab2bb3Spatrick ///
2493cab2bb3Spatrick /// \returns The bad address or NULL.
2503cab2bb3Spatrick const void *__sanitizer_contiguous_container_find_bad_address(const void *beg,
2513cab2bb3Spatrick                                                               const void *mid,
2523cab2bb3Spatrick                                                               const void *end);
2533cab2bb3Spatrick 
254*810390e3Srobert /// returns the address of the first improperly poisoned byte.
255*810390e3Srobert ///
256*810390e3Srobert /// Returns NULL if the area is poisoned properly.
257*810390e3Srobert ///
258*810390e3Srobert /// \param storage_beg Beginning of memory region.
259*810390e3Srobert /// \param container_beg Beginning of used region.
260*810390e3Srobert /// \param container_end End of used region.
261*810390e3Srobert /// \param storage_end End of memory region.
262*810390e3Srobert ///
263*810390e3Srobert /// \returns The bad address or NULL.
264*810390e3Srobert const void *__sanitizer_double_ended_contiguous_container_find_bad_address(
265*810390e3Srobert     const void *storage_beg, const void *container_beg,
266*810390e3Srobert     const void *container_end, const void *storage_end);
267*810390e3Srobert 
2683cab2bb3Spatrick /// Prints the stack trace leading to this call (useful for calling from the
2693cab2bb3Spatrick /// debugger).
2703cab2bb3Spatrick void __sanitizer_print_stack_trace(void);
2713cab2bb3Spatrick 
2723cab2bb3Spatrick // Symbolizes the supplied 'pc' using the format string 'fmt'.
2733cab2bb3Spatrick // Outputs at most 'out_buf_size' bytes into 'out_buf'.
2743cab2bb3Spatrick // If 'out_buf' is not empty then output is zero or more non empty C strings
2753cab2bb3Spatrick // followed by single empty C string. Multiple strings can be returned if PC
2763cab2bb3Spatrick // corresponds to inlined function. Inlined frames are printed in the order
2773cab2bb3Spatrick // from "most-inlined" to the "least-inlined", so the last frame should be the
2783cab2bb3Spatrick // not inlined function.
2793cab2bb3Spatrick // Inlined frames can be removed with 'symbolize_inline_frames=0'.
2803cab2bb3Spatrick // The format syntax is described in
2813cab2bb3Spatrick // lib/sanitizer_common/sanitizer_stacktrace_printer.h.
2823cab2bb3Spatrick void __sanitizer_symbolize_pc(void *pc, const char *fmt, char *out_buf,
2833cab2bb3Spatrick                               size_t out_buf_size);
2843cab2bb3Spatrick // Same as __sanitizer_symbolize_pc, but for data section (i.e. globals).
2853cab2bb3Spatrick void __sanitizer_symbolize_global(void *data_ptr, const char *fmt,
2863cab2bb3Spatrick                                   char *out_buf, size_t out_buf_size);
287*810390e3Srobert // Determine the return address.
288*810390e3Srobert #if !defined(_MSC_VER) || defined(__clang__)
289*810390e3Srobert #define __sanitizer_return_address()                                           \
290*810390e3Srobert   __builtin_extract_return_addr(__builtin_return_address(0))
291*810390e3Srobert #else
292*810390e3Srobert extern "C" void *_ReturnAddress(void);
293*810390e3Srobert #pragma intrinsic(_ReturnAddress)
294*810390e3Srobert #define __sanitizer_return_address() _ReturnAddress()
295*810390e3Srobert #endif
2963cab2bb3Spatrick 
2973cab2bb3Spatrick /// Sets the callback to be called immediately before death on error.
2983cab2bb3Spatrick ///
2993cab2bb3Spatrick /// Passing 0 will unset the callback.
3003cab2bb3Spatrick ///
3013cab2bb3Spatrick /// \param callback User-provided callback.
3023cab2bb3Spatrick void __sanitizer_set_death_callback(void (*callback)(void));
3033cab2bb3Spatrick 
3043cab2bb3Spatrick 
3053cab2bb3Spatrick // Interceptor hooks.
3063cab2bb3Spatrick // Whenever a libc function interceptor is called, it checks if the
3073cab2bb3Spatrick // corresponding weak hook is defined, and calls it if it is indeed defined.
3083cab2bb3Spatrick // The primary use-case is data-flow-guided fuzzing, where the fuzzer needs
3093cab2bb3Spatrick // to know what is being passed to libc functions (for example memcmp).
3103cab2bb3Spatrick // FIXME: implement more hooks.
3113cab2bb3Spatrick 
3123cab2bb3Spatrick /// Interceptor hook for <c>memcmp()</c>.
3133cab2bb3Spatrick ///
3143cab2bb3Spatrick /// \param called_pc PC (program counter) address of the original call.
3153cab2bb3Spatrick /// \param s1 Pointer to block of memory.
3163cab2bb3Spatrick /// \param s2 Pointer to block of memory.
3173cab2bb3Spatrick /// \param n Number of bytes to compare.
3183cab2bb3Spatrick /// \param result Value returned by the intercepted function.
3193cab2bb3Spatrick void __sanitizer_weak_hook_memcmp(void *called_pc, const void *s1,
3203cab2bb3Spatrick                                   const void *s2, size_t n, int result);
3213cab2bb3Spatrick 
3223cab2bb3Spatrick /// Interceptor hook for <c>strncmp()</c>.
3233cab2bb3Spatrick ///
3243cab2bb3Spatrick /// \param called_pc PC (program counter) address of the original call.
3253cab2bb3Spatrick /// \param s1 Pointer to block of memory.
3263cab2bb3Spatrick /// \param s2 Pointer to block of memory.
3273cab2bb3Spatrick /// \param n Number of bytes to compare.
3283cab2bb3Spatrick /// \param result Value returned by the intercepted function.
3293cab2bb3Spatrick void __sanitizer_weak_hook_strncmp(void *called_pc, const char *s1,
3303cab2bb3Spatrick                                   const char *s2, size_t n, int result);
3313cab2bb3Spatrick 
3323cab2bb3Spatrick /// Interceptor hook for <c>strncasecmp()</c>.
3333cab2bb3Spatrick ///
3343cab2bb3Spatrick /// \param called_pc PC (program counter) address of the original call.
3353cab2bb3Spatrick /// \param s1 Pointer to block of memory.
3363cab2bb3Spatrick /// \param s2 Pointer to block of memory.
3373cab2bb3Spatrick /// \param n Number of bytes to compare.
3383cab2bb3Spatrick /// \param result Value returned by the intercepted function.
3393cab2bb3Spatrick void __sanitizer_weak_hook_strncasecmp(void *called_pc, const char *s1,
3403cab2bb3Spatrick                                        const char *s2, size_t n, int result);
3413cab2bb3Spatrick 
3423cab2bb3Spatrick /// Interceptor hook for <c>strcmp()</c>.
3433cab2bb3Spatrick ///
3443cab2bb3Spatrick /// \param called_pc PC (program counter) address of the original call.
3453cab2bb3Spatrick /// \param s1 Pointer to block of memory.
3463cab2bb3Spatrick /// \param s2 Pointer to block of memory.
3473cab2bb3Spatrick /// \param result Value returned by the intercepted function.
3483cab2bb3Spatrick void __sanitizer_weak_hook_strcmp(void *called_pc, const char *s1,
3493cab2bb3Spatrick                                   const char *s2, int result);
3503cab2bb3Spatrick 
3513cab2bb3Spatrick /// Interceptor hook for <c>strcasecmp()</c>.
3523cab2bb3Spatrick ///
3533cab2bb3Spatrick /// \param called_pc PC (program counter) address of the original call.
3543cab2bb3Spatrick /// \param s1 Pointer to block of memory.
3553cab2bb3Spatrick /// \param s2 Pointer to block of memory.
3563cab2bb3Spatrick /// \param result Value returned by the intercepted function.
3573cab2bb3Spatrick void __sanitizer_weak_hook_strcasecmp(void *called_pc, const char *s1,
3583cab2bb3Spatrick                                       const char *s2, int result);
3593cab2bb3Spatrick 
3603cab2bb3Spatrick /// Interceptor hook for <c>strstr()</c>.
3613cab2bb3Spatrick ///
3623cab2bb3Spatrick /// \param called_pc PC (program counter) address of the original call.
3633cab2bb3Spatrick /// \param s1 Pointer to block of memory.
3643cab2bb3Spatrick /// \param s2 Pointer to block of memory.
3653cab2bb3Spatrick /// \param result Value returned by the intercepted function.
3663cab2bb3Spatrick void __sanitizer_weak_hook_strstr(void *called_pc, const char *s1,
3673cab2bb3Spatrick                                   const char *s2, char *result);
3683cab2bb3Spatrick 
3693cab2bb3Spatrick void __sanitizer_weak_hook_strcasestr(void *called_pc, const char *s1,
3703cab2bb3Spatrick                                       const char *s2, char *result);
3713cab2bb3Spatrick 
3723cab2bb3Spatrick void __sanitizer_weak_hook_memmem(void *called_pc,
3733cab2bb3Spatrick                                   const void *s1, size_t len1,
3743cab2bb3Spatrick                                   const void *s2, size_t len2, void *result);
3753cab2bb3Spatrick 
3763cab2bb3Spatrick // Prints stack traces for all live heap allocations ordered by total
3773cab2bb3Spatrick // allocation size until top_percent of total live heap is shown. top_percent
3783cab2bb3Spatrick // should be between 1 and 100. At most max_number_of_contexts contexts
3793cab2bb3Spatrick // (stack traces) are printed.
3803cab2bb3Spatrick // Experimental feature currently available only with ASan on Linux/x86_64.
3813cab2bb3Spatrick void __sanitizer_print_memory_profile(size_t top_percent,
3823cab2bb3Spatrick                                       size_t max_number_of_contexts);
3833cab2bb3Spatrick 
3843cab2bb3Spatrick /// Notify ASan that a fiber switch has started (required only if implementing
3853cab2bb3Spatrick /// your own fiber library).
3863cab2bb3Spatrick ///
3873cab2bb3Spatrick /// Before switching to a different stack, you must call
3883cab2bb3Spatrick /// <c>__sanitizer_start_switch_fiber()</c> with a pointer to the bottom of the
3893cab2bb3Spatrick /// destination stack and with its size. When code starts running on the new
3903cab2bb3Spatrick /// stack, it must call <c>__sanitizer_finish_switch_fiber()</c> to finalize
3913cab2bb3Spatrick /// the switch. The <c>__sanitizer_start_switch_fiber()</c> function takes a
3923cab2bb3Spatrick /// <c>void**</c> pointer argument to store the current fake stack if there is
3933cab2bb3Spatrick /// one (it is necessary when the runtime option
3943cab2bb3Spatrick /// <c>detect_stack_use_after_return</c> is enabled).
3953cab2bb3Spatrick ///
3963cab2bb3Spatrick /// When restoring a stack, this <c>void**</c> pointer must be given to the
3973cab2bb3Spatrick /// <c>__sanitizer_finish_switch_fiber()</c> function. In most cases, this
3983cab2bb3Spatrick /// pointer can be stored on the stack immediately before switching. When
3993cab2bb3Spatrick /// leaving a fiber definitely, NULL must be passed as the first argument to
4003cab2bb3Spatrick /// the <c>__sanitizer_start_switch_fiber()</c> function so that the fake stack
4013cab2bb3Spatrick /// is destroyed. If your program does not need stack use-after-return
4023cab2bb3Spatrick /// detection, you can always pass NULL to these two functions.
4033cab2bb3Spatrick ///
4043cab2bb3Spatrick /// \note The fake stack mechanism is disabled during fiber switch, so if a
4053cab2bb3Spatrick /// signal callback runs during the switch, it will not benefit from stack
4063cab2bb3Spatrick /// use-after-return detection.
4073cab2bb3Spatrick ///
408d89ec533Spatrick /// \param[out] fake_stack_save Fake stack save location.
4093cab2bb3Spatrick /// \param bottom Bottom address of stack.
4103cab2bb3Spatrick /// \param size Size of stack in bytes.
4113cab2bb3Spatrick void __sanitizer_start_switch_fiber(void **fake_stack_save,
4123cab2bb3Spatrick                                     const void *bottom, size_t size);
4133cab2bb3Spatrick 
4143cab2bb3Spatrick /// Notify ASan that a fiber switch has completed (required only if
4153cab2bb3Spatrick /// implementing your own fiber library).
4163cab2bb3Spatrick ///
4173cab2bb3Spatrick /// When code starts running on the new stack, it must call
4183cab2bb3Spatrick /// <c>__sanitizer_finish_switch_fiber()</c> to finalize
4193cab2bb3Spatrick /// the switch. For usage details, see the description of
4203cab2bb3Spatrick /// <c>__sanitizer_start_switch_fiber()</c>.
4213cab2bb3Spatrick ///
4223cab2bb3Spatrick /// \param fake_stack_save Fake stack save location.
423d89ec533Spatrick /// \param[out] bottom_old Bottom address of old stack.
424d89ec533Spatrick /// \param[out] size_old Size of old stack in bytes.
4253cab2bb3Spatrick void __sanitizer_finish_switch_fiber(void *fake_stack_save,
4263cab2bb3Spatrick                                      const void **bottom_old,
4273cab2bb3Spatrick                                      size_t *size_old);
4283cab2bb3Spatrick 
4293cab2bb3Spatrick // Get full module name and calculate pc offset within it.
4303cab2bb3Spatrick // Returns 1 if pc belongs to some module, 0 if module was not found.
4313cab2bb3Spatrick int __sanitizer_get_module_and_offset_for_pc(void *pc, char *module_path,
4323cab2bb3Spatrick                                              size_t module_path_len,
4333cab2bb3Spatrick                                              void **pc_offset);
4343cab2bb3Spatrick 
4353cab2bb3Spatrick #ifdef __cplusplus
4363cab2bb3Spatrick }  // extern "C"
4373cab2bb3Spatrick #endif
4383cab2bb3Spatrick 
4393cab2bb3Spatrick #endif  // SANITIZER_COMMON_INTERFACE_DEFS_H
440