safec  2.1
Safe C Library - ISO TR24731 Bounds Checking Interface
All Files Functions Variables Macros Pages
safe_mem_constraint.c
Go to the documentation of this file.
1 /*------------------------------------------------------------------
2  * safe_mem_constraint.c
3  *
4  * October 2008, Bo Berry
5  * 2012, Jonathan Toppins <jtoppins@users.sourceforge.net>
6  *
7  * Copyright (c) 2008-2012 Cisco Systems
8  * All rights reserved.
9  *
10  * Permission is hereby granted, free of charge, to any person
11  * obtaining a copy of this software and associated documentation
12  * files (the "Software"), to deal in the Software without
13  * restriction, including without limitation the rights to use,
14  * copy, modify, merge, publish, distribute, sublicense, and/or
15  * sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following
17  * conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29  * OTHER DEALINGS IN THE SOFTWARE.
30  *------------------------------------------------------------------
31  */
32 
33 #include "safeclib_private.h"
34 #include "safe_mem_constraint.h"
35 #include "safe_mem_lib.h"
36 
37 
38 static constraint_handler_t mem_handler = NULL;
39 
40 
71 constraint_handler_t
72 set_mem_constraint_handler_s (constraint_handler_t handler)
73 {
74  constraint_handler_t prev_handler = mem_handler;
75  if (NULL == handler) {
76  mem_handler = sl_default_handler;
77  } else {
78  mem_handler = handler;
79  }
80  return prev_handler;
81 }
82 EXPORT_SYMBOL(set_mem_constraint_handler_s)
83 
84 
85 
94 void
96  void *ptr,
97  errno_t error)
98 {
99  if (NULL != mem_handler) {
100  mem_handler(msg, ptr, error);
101  } else {
102  sl_default_handler(msg, ptr, error);
103  }
104 }
static constraint_handler_t mem_handler
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...
void invoke_safe_mem_constraint_handler(const char *msg, void *ptr, errno_t error)
Invokes the currently set constraint handler or the default.