1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/* $Id: vq_malloc.h,v 1.1.1.1 2005/06/13 16:47:31 bogdan_iancu Exp $
*
* Copyright (C) 2001-2003 FhG Fokus
*
* This file is part of openser, a free SIP server.
*
* openser 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
*
* openser 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.
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#if !defined(VQ_MALLOC_H) && defined(VQ_MALLOC)
#define VQ_MALLOC_H
#include "../config.h"
/* indicates this fragment is not in use (must not be offset of valid
aligned fragment beginning
*/
#define FR_USED 0xef
/*useful macros*/
#define FRAG_END(f) \
((struct vqm_frag_end*)((char*)(f)-sizeof(struct vqm_frag_end)+ \
(f)->size))
#define FRAG_NEXT(f) \
((struct vqm_frag*)((char*)(f)+(f)->size))
#define PREV_FRAG_END(f) \
((struct vqm_frag_end*)((char*)(f)-sizeof(struct vqm_frag_end)))
#define FRAG_PREV(f) \
( (struct vqm_frag*) ( (char*)(f) - PREV_FRAG_END(f)->size ))
#define FRAG_ISUSED(f) \
((f)->u.inuse.magic==FR_USED)
/* just a bumper for the step function */
#define EO_STEP -1
#ifdef DBG_QM_MALLOC
# define ST_CHECK_PATTERN 0xf0f0f0f0
# define END_CHECK_PATTERN "sExP"
# define END_CHECK_PATTERN_LEN 4
# define VQM_OVERHEAD (sizeof(struct vqm_frag)+ \
sizeof(struct vqm_frag_end)+END_CHECK_PATTERN_LEN)
# define VQM_DEBUG_FRAG(qm, f) vqm_debug_frag( (qm), (f))
#else
# define VQM_DEBUG_FRAG(qm, f)
# define VQM_OVERHEAD (sizeof(struct vqm_frag)+ sizeof(struct vqm_frag_end))
#endif
struct vqm_frag {
/* XXX */
/* total chunk size including all overhead/bellowfoot/roundings/etc */
/* useless as otherwise size implied by bucket (if I really want to save
bytes, I'll remove it from here */
unsigned long size;
union{
/* pointer to next chunk in a bucket if free */
struct vqm_frag* nxt_free;
struct { /* or bucket number if busy */
unsigned char magic;
unsigned char bucket;
} inuse;
} u;
#ifdef DBG_QM_MALLOC
/* source code info */
char* file;
char* func;
unsigned long line;
/* your safety is important to us! safety signatures */
unsigned long check;
char *end_check;
/* the size user was originally asking for */
unsigned long demanded_size;
#endif
};
struct vqm_frag_end{
/* total chunk size including all overhead/bellowfoot/roundings/etc */
unsigned long size;
/* XXX */
/* used only for variable-size chunks; might have different
data structures for variable/fixed length chunks */
struct vqm_frag* prv_free;
};
struct vqm_block{
/* size to bucket table */
unsigned char s2b[ MAX_FIXED_BLOCK ];
/* size to rounded size */
unsigned short s2s[ MAX_FIXED_BLOCK ];
unsigned char max_small_bucket;
/* core gained on init ... */
char *core, *init_core, *core_end;
/* ... and its available net amount; note that there's lot of
free memory in buckets too -- this just tells about memory
which has not been assigned to chunks */
unsigned long free_core;
/* we allocate huge chunks from the end on; this is the
pointer to big chunks
*/
char *big_chunks;
struct vqm_frag* next_free[ MAX_BUCKET +1];
#ifdef DBG_QM_MALLOC
unsigned long usage[ MAX_BUCKET +1];
#endif
};
struct vqm_block* vqm_malloc_init(char* address, unsigned int size);
#ifdef DBG_QM_MALLOC
void vqm_debug_frag(struct vqm_block* qm, struct vqm_frag* f);
void* vqm_malloc(struct vqm_block*, unsigned int size, char* file, char* func,
unsigned int line);
void vqm_free(struct vqm_block*, void* p, char* file, char* func,
unsigned int line);
#else
void* vqm_malloc(struct vqm_block*, unsigned int size);
void vqm_free(struct vqm_block*, void* p);
#endif
void vqm_status(struct vqm_block*);
#endif
|