1 /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2 
3 /*
4  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification,
8  * are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  *    this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  *    this list of conditions and the following disclaimer in the documentation
14  *    and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27  * OF SUCH DAMAGE.
28  *
29  * This file is part of the lwIP TCP/IP stack.
30  *
31  * Author: Adam Dunkels <adam@sics.se>
32  *
33  */
34 #ifndef __LWIP_MEM_H__
35 #define __LWIP_MEM_H__
36 
37 #include "lwip/opt.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 #if MEM_LIBC_MALLOC
44 
45 #include <stddef.h> /* for size_t */
46 
47 typedef size_t mem_size_t;
48 
49 /* aliases for C library malloc() */
50 #define mem_init()
51 /* in case C library malloc() needs extra protection,
52  * allow these defines to be overridden.
53  */
54 #ifndef mem_free
55 #define mem_free free
56 #endif
57 #ifndef mem_malloc
58 #define mem_malloc malloc
59 #endif
60 #ifndef mem_calloc
61 #define mem_calloc calloc
62 #endif
63 #ifndef mem_realloc
mem_realloc(void * mem,mem_size_t size)64 static void *mem_realloc(void *mem, mem_size_t size)
65 {
66   LWIP_UNUSED_ARG(size);
67   return mem;
68 }
69 #endif
70 #else /* MEM_LIBC_MALLOC */
71 
72 /* MEM_SIZE would have to be aligned, but using 64000 here instead of
73  * 65535 leaves some room for alignment...
74  */
75 #if MEM_SIZE > 64000l
76 typedef u32_t mem_size_t;
77 #else
78 typedef u16_t mem_size_t;
79 #endif /* MEM_SIZE > 64000 */
80 
81 #if MEM_USE_POOLS
82 /** mem_init is not used when using pools instead of a heap */
83 #define mem_init()
84 /** mem_realloc is not used when using pools instead of a heap:
85     we can't free part of a pool element and don't want to copy the rest */
86 #define mem_realloc(mem, size) (mem)
87 #else /* MEM_USE_POOLS */
88 /* lwIP alternative malloc */
89 void  mem_init(void);
90 void *mem_realloc(void *mem, mem_size_t size);
91 #endif /* MEM_USE_POOLS */
92 void *mem_malloc(mem_size_t size);
93 void *mem_calloc(mem_size_t count, mem_size_t size);
94 void  mem_free(void *mem);
95 #endif /* MEM_LIBC_MALLOC */
96 
97 #ifndef LWIP_MEM_ALIGN_SIZE
98 #define LWIP_MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1) & ~(MEM_ALIGNMENT-1))
99 #endif
100 
101 #ifndef LWIP_MEM_ALIGN
102 #define LWIP_MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1)))
103 #endif
104 
105 #ifdef __cplusplus
106 }
107 #endif
108 
109 #endif /* __LWIP_MEM_H__ */
110