safec 3.8.0
Safe C Library - ISO TR24731 Bounds Checking Interface
Loading...
Searching...
No Matches
safe_mem_constraint.c File Reference
+ Include dependency graph for safe_mem_constraint.c:

Functions

EXPORT constraint_handler_t set_mem_constraint_handler_s (constraint_handler_t handler)
 The set_mem_constraint_handler_s function sets the runtime-constraint handler to be handler.
 
EXPORT constraint_handler_t thrd_set_mem_constraint_handler_s (constraint_handler_t handler)
 The thrd_set_mem_constraint_handler_s function sets the runtime-constraint handler to a thread-local handler.
 
EXPORT void invoke_safe_mem_constraint_handler (const char *msg, void *ptr, errno_t error)
 Invokes the currently set thread-safe or not constraint handler or the default.
 
void handle_mem_bos_chk_warn (const char *restrict func, void *restrict dest, const rsize_t dmax, const size_t destbos)
 

Variables

static constraint_handler_t mem_handler
 
static constraint_handler_t thrd_mem_handler
 

Function Documentation

◆ set_mem_constraint_handler_s()

EXPORT constraint_handler_t set_mem_constraint_handler_s ( constraint_handler_t  handler)

The set_mem_constraint_handler_s function sets the runtime-constraint handler to be handler.

The runtime-constraint handler is the function to be called when a library function detects a runtime-constraint order:

  1. A pointer to a character string describing the runtime-constraint violation.
  2. A null pointer or a pointer to an implementation defined object.
  3. If the function calling the handler has a return type declared as errno_t, the return value of the function is passed. Otherwise, a positive value of type errno_t is passed. The implementation has a default constraint handler that is used if no calls to the set_constraint_handler_s function have been made. The behavior of the default handler is implementation-defined, and it may cause the program to exit or abort. If the handler argument to set_constraint_handler_s is a null pointer, the implementation default handler becomes the current constraint handler.
Remarks
SPECIFIED IN ISO/IEC JTC1 SC22 WG14 N1172, Programming languages, environments and system software interfaces, Extensions to the C Library, Part I: Bounds-checking interfaces
See also
set_str_constraint_handler_s()

◆ thrd_set_mem_constraint_handler_s()

EXPORT constraint_handler_t thrd_set_mem_constraint_handler_s ( constraint_handler_t  handler)

The thrd_set_mem_constraint_handler_s function sets the runtime-constraint handler to a thread-local handler.

The thrd_set_mem_constraint_handler_s function behaves the same way as the set_mem_constraint_handler_s function except that it sets the runtime-constraint handler to the handler only for the calling thread and for any threads that are yet to be created by the calling thread. The function has no effect on other threads in the program. The remaining effects of the two functions are identical, as are their return values.

Remarks
SPECIFIED IN ISO/IEC JTC1 SC22 WG14 N2809 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2809.pdf
See also
thrd_set_str_constraint_handler_s()

◆ invoke_safe_mem_constraint_handler()

EXPORT void invoke_safe_mem_constraint_handler ( const char *  msg,
void *  ptr,
errno_t  error 
)

Invokes the currently set thread-safe or not constraint handler or the default.

Can be disabled via --disable-constraint-handler

Parameters
*msgPointer to the message describing the error.
*ptrPointer to associated data. Can be NULL.
errorThe error code encountered.

◆ handle_mem_bos_chk_warn()

void handle_mem_bos_chk_warn ( const char *restrict  func,
void *restrict  dest,
const rsize_t  dmax,
const size_t  destbos 
)

Variable Documentation

◆ mem_handler

constraint_handler_t mem_handler
static
Initial value:
=
NULL

◆ thrd_mem_handler

constraint_handler_t thrd_mem_handler
static
Initial value:
=
NULL