6.55. Pointer Bounds Checker Built-in Functions

6.55 Pointer Bounds Checker Built-in Functions

GCC provides a set of built-in functions to control Pointer Bounds Checker instrumentation. Note that all Pointer Bounds Checker builtins can be used even if you compile with Pointer Bounds Checker off (-fno-check-pointer-bounds). The behavior may differ in such case as documented below.

— Built-in Function: void * __builtin___bnd_set_ptr_bounds (const void *q, size_t size)

This built-in function returns a new pointer with the value of q, and associate it with the bounds [q, q+size-1]. With Pointer Bounds Checker off, the built-in function just returns the first argument.

extern void *__wrap_malloc (size_t n)
{
  void *p = (void *)__real_malloc (n);
  if (!p) return __builtin___bnd_null_ptr_bounds (p);
  return __builtin___bnd_set