<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <meta http-equiv="X-UA-Compatible" content="IE=9"/> <meta name="generator" content="Doxygen 1.8.5"/> <title>PolarSSL v1.3.8: memory_buffer_alloc.h File Reference</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="dynsections.js"></script> <link href="doxygen.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="top"><!-- do not remove this div, it is closed by doxygen! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">PolarSSL v1.3.8 </div> </td> </tr> </tbody> </table> </div> <!-- end header part --> <!-- Generated by Doxygen 1.8.5 --> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>Globals</span></a></li> </ul> </div> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="dir_6a9bbd12bf4e19a18c45e270f8fae3fd.html">include</a></li><li class="navelem"><a class="el" href="dir_04272d44da4745cf8b8bfc767d6c6523.html">polarssl</a></li> </ul> </div> </div><!-- top --> <div class="header"> <div class="summary"> <a href="#define-members">Macros</a> | <a href="#func-members">Functions</a> </div> <div class="headertitle"> <div class="title">memory_buffer_alloc.h File Reference</div> </div> </div><!--header--> <div class="contents"> <p>Buffer-based memory allocator. <a href="#details">More...</a></p> <div class="textblock"><code>#include "<a class="el" href="config_8h_source.html">config.h</a>"</code><br/> <code>#include <stdlib.h></code><br/> </div><div class="textblock"><div class="dynheader"> Include dependency graph for memory_buffer_alloc.h:</div> <div class="dyncontent"> <div class="center"><img src="memory__buffer__alloc_8h__incl.png" border="0" usemap="#memory__buffer__alloc_8h" alt=""/></div> <map name="memory__buffer__alloc_8h" id="memory__buffer__alloc_8h"> </map> </div> </div><div class="textblock"><div class="dynheader"> This graph shows which files directly or indirectly include this file:</div> <div class="dyncontent"> <div class="center"><img src="memory__buffer__alloc_8h__dep__incl.png" border="0" usemap="#memory__buffer__alloc_8hdep" alt=""/></div> <map name="memory__buffer__alloc_8hdep" id="memory__buffer__alloc_8hdep"> </map> </div> </div> <p><a href="memory__buffer__alloc_8h_source.html">Go to the source code of this file.</a></p> <table class="memberdecls"> <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="define-members"></a> Macros</h2></td></tr> <tr class="memitem:ae9b20acb59b74c83292f835ee94b2b42"><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="memory__buffer__alloc_8h.html#ae9b20acb59b74c83292f835ee94b2b42">MEMORY_VERIFY_NONE</a>   0</td></tr> <tr class="separator:ae9b20acb59b74c83292f835ee94b2b42"><td class="memSeparator" colspan="2"> </td></tr> <tr class="memitem:a129f05dbba09d85d2b880faeca2a6eff"><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="memory__buffer__alloc_8h.html#a129f05dbba09d85d2b880faeca2a6eff">MEMORY_VERIFY_ALLOC</a>   (1 << 0)</td></tr> <tr class="separator:a129f05dbba09d85d2b880faeca2a6eff"><td class="memSeparator" colspan="2"> </td></tr> <tr class="memitem:adc781138868927caa03bfe4b58c4e80d"><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="memory__buffer__alloc_8h.html#adc781138868927caa03bfe4b58c4e80d">MEMORY_VERIFY_FREE</a>   (1 << 1)</td></tr> <tr class="separator:adc781138868927caa03bfe4b58c4e80d"><td class="memSeparator" colspan="2"> </td></tr> <tr class="memitem:a8e4c201d28d750e49911028b8062bb8f"><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="memory__buffer__alloc_8h.html#a8e4c201d28d750e49911028b8062bb8f">MEMORY_VERIFY_ALWAYS</a>   (<a class="el" href="memory__buffer__alloc_8h.html#a129f05dbba09d85d2b880faeca2a6eff">MEMORY_VERIFY_ALLOC</a> | <a class="el" href="memory__buffer__alloc_8h.html#adc781138868927caa03bfe4b58c4e80d">MEMORY_VERIFY_FREE</a>)</td></tr> <tr class="separator:a8e4c201d28d750e49911028b8062bb8f"><td class="memSeparator" colspan="2"> </td></tr> <tr><td colspan="2"><div class="groupHeader">SECTION: Module settings</div></td></tr> <tr><td colspan="2"><div class="groupText"><p>The configuration options you can set for this module are in this section.</p> <p>Either change them in <a class="el" href="config_8h.html" title="Configuration options (set of defines) ">config.h</a> or define them on the compiler command line. </p> </div></td></tr> <tr class="memitem:a3207cb8b170cc1fe695783d1809c32a4"><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="memory__buffer__alloc_8h.html#a3207cb8b170cc1fe695783d1809c32a4">POLARSSL_MEMORY_ALIGN_MULTIPLE</a>   4</td></tr> <tr class="memdesc:a3207cb8b170cc1fe695783d1809c32a4"><td class="mdescLeft"> </td><td class="mdescRight">Align on multiples of this value. <a href="#a3207cb8b170cc1fe695783d1809c32a4">More...</a><br/></td></tr> <tr class="separator:a3207cb8b170cc1fe695783d1809c32a4"><td class="memSeparator" colspan="2"> </td></tr> </table><table class="memberdecls"> <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a> Functions</h2></td></tr> <tr class="memitem:af2745e4cbfe3339911913ed02dccce91"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="memory__buffer__alloc_8h.html#af2745e4cbfe3339911913ed02dccce91">memory_buffer_alloc_init</a> (unsigned char *buf, size_t len)</td></tr> <tr class="memdesc:af2745e4cbfe3339911913ed02dccce91"><td class="mdescLeft"> </td><td class="mdescRight">Initialize use of stack-based memory allocator. <a href="#af2745e4cbfe3339911913ed02dccce91">More...</a><br/></td></tr> <tr class="separator:af2745e4cbfe3339911913ed02dccce91"><td class="memSeparator" colspan="2"> </td></tr> <tr class="memitem:a422e29785ed0ae2e31ca9688a0f18267"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="memory__buffer__alloc_8h.html#a422e29785ed0ae2e31ca9688a0f18267">memory_buffer_alloc_free</a> (void)</td></tr> <tr class="memdesc:a422e29785ed0ae2e31ca9688a0f18267"><td class="mdescLeft"> </td><td class="mdescRight">Free the mutex for thread-safety and clear remaining memory. <a href="#a422e29785ed0ae2e31ca9688a0f18267">More...</a><br/></td></tr> <tr class="separator:a422e29785ed0ae2e31ca9688a0f18267"><td class="memSeparator" colspan="2"> </td></tr> <tr class="memitem:a0cfecc13142981464f1f746863542a86"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="memory__buffer__alloc_8h.html#a0cfecc13142981464f1f746863542a86">memory_buffer_set_verify</a> (int verify)</td></tr> <tr class="memdesc:a0cfecc13142981464f1f746863542a86"><td class="mdescLeft"> </td><td class="mdescRight">Determine when the allocator should automatically verify the state of the entire chain of headers / meta-data. <a href="#a0cfecc13142981464f1f746863542a86">More...</a><br/></td></tr> <tr class="separator:a0cfecc13142981464f1f746863542a86"><td class="memSeparator" colspan="2"> </td></tr> <tr class="memitem:a9bf18c3768a4c35d6df53bc781b18d1a"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="memory__buffer__alloc_8h.html#a9bf18c3768a4c35d6df53bc781b18d1a">memory_buffer_alloc_verify</a> (void)</td></tr> <tr class="memdesc:a9bf18c3768a4c35d6df53bc781b18d1a"><td class="mdescLeft"> </td><td class="mdescRight">Verifies that all headers in the memory buffer are correct and contain sane values. <a href="#a9bf18c3768a4c35d6df53bc781b18d1a">More...</a><br/></td></tr> <tr class="separator:a9bf18c3768a4c35d6df53bc781b18d1a"><td class="memSeparator" colspan="2"> </td></tr> </table> <a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2> <div class="textblock"><p>Buffer-based memory allocator. </p> <p>Copyright (C) 2006-2014, Brainspark B.V.</p> <p>This file is part of PolarSSL (<a href="http://www.polarssl.org">http://www.polarssl.org</a>) Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org></p> <p>All rights reserved.</p> <p>This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.</p> <p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.</p> <p>You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. </p> <p>Definition in file <a class="el" href="memory__buffer__alloc_8h_source.html">memory_buffer_alloc.h</a>.</p> </div><h2 class="groupheader">Macro Definition Documentation</h2> <a class="anchor" id="a129f05dbba09d85d2b880faeca2a6eff"></a> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">#define MEMORY_VERIFY_ALLOC   (1 << 0)</td> </tr> </table> </div><div class="memdoc"> <p>Definition at line <a class="el" href="memory__buffer__alloc_8h_source.html#l00053">53</a> of file <a class="el" href="memory__buffer__alloc_8h_source.html">memory_buffer_alloc.h</a>.</p> </div> </div> <a class="anchor" id="a8e4c201d28d750e49911028b8062bb8f"></a> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">#define MEMORY_VERIFY_ALWAYS   (<a class="el" href="memory__buffer__alloc_8h.html#a129f05dbba09d85d2b880faeca2a6eff">MEMORY_VERIFY_ALLOC</a> | <a class="el" href="memory__buffer__alloc_8h.html#adc781138868927caa03bfe4b58c4e80d">MEMORY_VERIFY_FREE</a>)</td> </tr> </table> </div><div class="memdoc"> <p>Definition at line <a class="el" href="memory__buffer__alloc_8h_source.html#l00055">55</a> of file <a class="el" href="memory__buffer__alloc_8h_source.html">memory_buffer_alloc.h</a>.</p> </div> </div> <a class="anchor" id="adc781138868927caa03bfe4b58c4e80d"></a> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">#define MEMORY_VERIFY_FREE   (1 << 1)</td> </tr> </table> </div><div class="memdoc"> <p>Definition at line <a class="el" href="memory__buffer__alloc_8h_source.html#l00054">54</a> of file <a class="el" href="memory__buffer__alloc_8h_source.html">memory_buffer_alloc.h</a>.</p> </div> </div> <a class="anchor" id="ae9b20acb59b74c83292f835ee94b2b42"></a> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">#define MEMORY_VERIFY_NONE   0</td> </tr> </table> </div><div class="memdoc"> <p>Definition at line <a class="el" href="memory__buffer__alloc_8h_source.html#l00052">52</a> of file <a class="el" href="memory__buffer__alloc_8h_source.html">memory_buffer_alloc.h</a>.</p> </div> </div> <a class="anchor" id="a3207cb8b170cc1fe695783d1809c32a4"></a> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">#define POLARSSL_MEMORY_ALIGN_MULTIPLE   4</td> </tr> </table> </div><div class="memdoc"> <p>Align on multiples of this value. </p> <p>Definition at line <a class="el" href="memory__buffer__alloc_8h_source.html#l00047">47</a> of file <a class="el" href="memory__buffer__alloc_8h_source.html">memory_buffer_alloc.h</a>.</p> </div> </div> <h2 class="groupheader">Function Documentation</h2> <a class="anchor" id="a422e29785ed0ae2e31ca9688a0f18267"></a> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">void memory_buffer_alloc_free </td> <td>(</td> <td class="paramtype">void </td> <td class="paramname"></td><td>)</td> <td></td> </tr> </table> </div><div class="memdoc"> <p>Free the mutex for thread-safety and clear remaining memory. </p> <p>Referenced by <a class="el" href="test__suite__aes_8cbc_8c_source.html#l01033">main()</a>.</p> </div> </div> <a class="anchor" id="af2745e4cbfe3339911913ed02dccce91"></a> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">int memory_buffer_alloc_init </td> <td>(</td> <td class="paramtype">unsigned char * </td> <td class="paramname"><em>buf</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">size_t </td> <td class="paramname"><em>len</em> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </div><div class="memdoc"> <p>Initialize use of stack-based memory allocator. </p> <pre class="fragment"> The stack-based allocator does memory management inside the presented buffer and does not call malloc() and free(). It sets the global polarssl_malloc() and polarssl_free() pointers to its own functions. (Provided polarssl_malloc() and polarssl_free() are thread-safe if POLARSSL_THREADING_C is defined) </pre><dl class="section note"><dt>Note</dt><dd>This code is not optimized and provides a straight-forward implementation of a stack-based memory allocator.</dd></dl> <dl class="params"><dt>Parameters</dt><dd> <table class="params"> <tr><td class="paramname">buf</td><td>buffer to use as heap </td></tr> <tr><td class="paramname">len</td><td>size of the buffer</td></tr> </table> </dd> </dl> <dl class="section return"><dt>Returns</dt><dd>0 if successful </dd></dl> <p>Referenced by <a class="el" href="test__suite__aes_8cbc_8c_source.html#l01033">main()</a>.</p> </div> </div> <a class="anchor" id="a9bf18c3768a4c35d6df53bc781b18d1a"></a> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">int memory_buffer_alloc_verify </td> <td>(</td> <td class="paramtype">void </td> <td class="paramname"></td><td>)</td> <td></td> </tr> </table> </div><div class="memdoc"> <p>Verifies that all headers in the memory buffer are correct and contain sane values. </p> <p>Helps debug buffer-overflow errors. </p> <pre class="fragment"> Prints out first failure if POLARSSL_MEMORY_DEBUG is defined. Prints out full header information if POLARSSL_MEMORY_DEBUG_HEADERS is defined. (Includes stack trace information for each block if POLARSSL_MEMORY_BACKTRACE is defined as well). </pre><dl class="section return"><dt>Returns</dt><dd>0 if verified, 1 otherwise </dd></dl> </div> </div> <a class="anchor" id="a0cfecc13142981464f1f746863542a86"></a> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">void memory_buffer_set_verify </td> <td>(</td> <td class="paramtype">int </td> <td class="paramname"><em>verify</em></td><td>)</td> <td></td> </tr> </table> </div><div class="memdoc"> <p>Determine when the allocator should automatically verify the state of the entire chain of headers / meta-data. </p> <pre class="fragment"> (Default: MEMORY_VERIFY_NONE) </pre><dl class="params"><dt>Parameters</dt><dd> <table class="params"> <tr><td class="paramname">verify</td><td>One of MEMORY_VERIFY_NONE, MEMORY_VERIFY_ALLOC, MEMORY_VERIFY_FREE or MEMORY_VERIFY_ALWAYS </td></tr> </table> </dd> </dl> </div> </div> </div><!-- contents --> <!-- start footer part --> <hr class="footer"/><address class="footer"><small> Generated on Thu Jul 31 2014 11:35:56 for PolarSSL v1.3.8 by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/> </a> 1.8.5 </small></address> </body> </html>