mem_block.c 21.1 KB
Newer Older
gauthier's avatar
gauthier committed
1
/*******************************************************************************
nikaeinn's avatar
nikaeinn committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom

    OpenAirInterface 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 3 of the License, or
    (at your option) any later version.


    OpenAirInterface 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 OpenAirInterface.The full GNU General Public License is
    included in this distribution in the file called "COPYING". If not,
    see <http://www.gnu.org/licenses/>.

  Contact Information
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@eurecom.fr

ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
nikaeinn's avatar
nikaeinn committed
27

gauthier's avatar
gauthier committed
28
*******************************************************************************/
nikaeinn's avatar
nikaeinn committed
29 30


31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
/***************************************************************************
                          mem_block.c  -  description
                             -------------------
  AUTHOR  : Lionel GAUTHIER
  COMPANY : EURECOM
  EMAIL   : Lionel.Gauthier@eurecom.fr


 ***************************************************************************/
#define MEM_BLOCK_C
//#include "rtos_header.h"
#include "mem_block.h"
#include "mem_pool.h"
#include "list.h"
#include "LAYER2/MAC/extern.h"

//-----------------------------------------------------------------------------
//#define DEBUG_MEM_MNGT_FREE
//#define DEBUG_MEM_MNGT_ALLOC_SIZE
//#define DEBUG_MEM_MNGT_ALLOC
//-----------------------------------------------------------------------------
Cedric Roux's avatar
Cedric Roux committed
52
#if defined(USER_MODE) && defined(DEBUG_MEM_MNGT_ALLOC)
53
uint32_t             counters[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
54 55 56 57 58 59 60 61
#endif
//-----------------------------------------------------------------------------
/*
 * initialize all ures
 */
void           *
pool_buffer_init ()
{
62
  //-----------------------------------------------------------------------------
63

64
  uint32_t             index, mb_index, pool_index;
65 66
  mem_pool       *memory = (mem_pool *) &mem_block_var;
  int             pool_sizes[14] = { MEM_MNGT_MB0_NB_BLOCKS, MEM_MNGT_MB1_NB_BLOCKS,
67 68 69 70 71 72 73
                                     MEM_MNGT_MB2_NB_BLOCKS, MEM_MNGT_MB3_NB_BLOCKS,
                                     MEM_MNGT_MB4_NB_BLOCKS, MEM_MNGT_MB5_NB_BLOCKS,
                                     MEM_MNGT_MB6_NB_BLOCKS, MEM_MNGT_MB7_NB_BLOCKS,
                                     MEM_MNGT_MB8_NB_BLOCKS, MEM_MNGT_MB9_NB_BLOCKS,
                                     MEM_MNGT_MB10_NB_BLOCKS, MEM_MNGT_MB11_NB_BLOCKS,
                                     MEM_MNGT_MB12_NB_BLOCKS, MEM_MNGT_MBCOPY_NB_BLOCKS
                                   };
74 75 76

  memset (memory, 0, sizeof (mem_pool));
  mb_index = 0;
77

78 79 80
  // LG_TEST
  for (pool_index = 0; pool_index <= MEM_MNGT_POOL_ID_COPY; pool_index++) {
    list_init (&memory->mem_lists[pool_index], "POOL");
81

82 83 84 85
    for (index = 0; index < pool_sizes[pool_index]; index++) {
      //memory->mem_blocks[mb_index + index].previous = NULL; -> done in memset 0
      //memory->mem_blocks[mb_index + index].next     = NULL; -> done in memset 0
      switch (pool_index) {
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
      case 0:
        memory->mem_blocks[mb_index + index].data = (unsigned char*)&(memory->mem_pool0[index][0]);
        break;

      case 1:
        memory->mem_blocks[mb_index + index].data = (unsigned char*)&(memory->mem_pool1[index][0]);
        break;

      case 2:
        memory->mem_blocks[mb_index + index].data = (unsigned char*)&(memory->mem_pool2[index][0]);
        break;

      case 3:
        memory->mem_blocks[mb_index + index].data = (unsigned char*)&(memory->mem_pool3[index][0]);
        break;

      case 4:
        memory->mem_blocks[mb_index + index].data = (unsigned char*)&(memory->mem_pool4[index][0]);
        break;

      case 5:
        memory->mem_blocks[mb_index + index].data = (unsigned char*)&(memory->mem_pool5[index][0]);
        break;

      case 6:
        memory->mem_blocks[mb_index + index].data = (unsigned char*)&(memory->mem_pool6[index][0]);
        break;

      case 7:
        memory->mem_blocks[mb_index + index].data = (unsigned char*)&(memory->mem_pool7[index][0]);
        break;

      case 8:
        memory->mem_blocks[mb_index + index].data = (unsigned char*)&(memory->mem_pool8[index][0]);
        break;

      case 9:
        memory->mem_blocks[mb_index + index].data = (unsigned char*)&(memory->mem_pool9[index][0]);
        break;

      case 10:
        memory->mem_blocks[mb_index + index].data = (unsigned char*)&(memory->mem_pool10[index][0]);
        break;

      case 11:
        memory->mem_blocks[mb_index + index].data = (unsigned char*)&(memory->mem_pool11[index][0]);
        break;

      case 12:
        memory->mem_blocks[mb_index + index].data = (unsigned char*)&(memory->mem_pool12[index][0]);
        break;

      default:
        ;
        memory->mem_blocks[mb_index + index].data = NULL;   // pool copy
141 142

      }
143

144 145 146
      memory->mem_blocks[mb_index + index].pool_id = pool_index;
      list_add_tail_eurecom (&memory->mem_blocks[mb_index + index], &memory->mem_lists[pool_index]);
    }
147

148 149
    mb_index += pool_sizes[pool_index];
  }
150

151 152 153 154 155 156 157
  return 0;
}

//-----------------------------------------------------------------------------
void           *
pool_buffer_clean (void *arg)
{
158
  //-----------------------------------------------------------------------------
159 160 161 162 163 164
  return 0;
}
//-----------------------------------------------------------------------------
void
free_mem_block (mem_block_t * leP)
{
165
  //-----------------------------------------------------------------------------
166 167 168 169 170

  if (!(leP)) {
    msg ("[MEM_MNGT][FREE] WARNING FREE NULL MEM_BLOCK\n");
    return;
  }
171 172

#ifdef DEBUG_MEM_MNGT_FREE
173
  msg ("[MEM_MNGT][FREE] free_mem_block() %p pool: %d\n", leP, leP->pool_id);
174 175
#endif
#ifdef DEBUG_MEM_MNGT_ALLOC
176
  check_free_mem_block (leP);
177
#endif
178 179 180

  if (leP->pool_id <= MEM_MNGT_POOL_ID_COPY) {
    list_add_tail_eurecom (leP, &mem_block_var.mem_lists[leP->pool_id]);
181
#ifdef DEBUG_MEM_MNGT_ALLOC
182
    counters[leP->pool_id] -= 1;
183
#endif
184 185 186 187 188 189 190 191
    leP = NULL;                 // this prevent from freeing the block twice
  } else {
    msg ("[MEM_MNGT][FREE] ERROR free_mem_block() unknown pool_id : %d\n", leP->pool_id);
  }
}

//-----------------------------------------------------------------------------
mem_block_t      *
192
get_free_mem_block (uint16_t sizeP)
193
{
194
  //-----------------------------------------------------------------------------
195 196 197 198
  mem_block_t      *le = NULL;
  int             pool_selected;
  int             size;

199 200 201 202 203 204 205
  // next block commented, because sizeP > MEM_MNGT_MB12_BLOCK_SIZE can never be true.
  //  if (sizeP > MEM_MNGT_MB12_BLOCK_SIZE) {
  //    msg ("[MEM_MNGT][ERROR][FATAL] size requested %d out of bounds\n", sizeP);
  //    display_mem_load ();
  //    mac_xface->macphy_exit("[MEM_MNGT][ERROR][FATAL] get_free_mem_block size requested out of bounds");
  //    return NULL;
  //  }
206 207 208 209 210 211 212 213 214 215 216 217
  size = sizeP >> 6;
  pool_selected = 0;

  while ((size)) {
    pool_selected += 1;
    size = size >> 1;
  }

  // pool is selected according to the size requested, now get a block
  // if no block is available pick one in an other pool
  do {
    if ((le = list_remove_head (&mem_block_var.mem_lists[pool_selected]))) {
218
#ifdef DEBUG_MEM_MNGT_ALLOC
219
      counters[pool_selected] += 1;
220 221
#endif
#ifdef DEBUG_MEM_MNGT_ALLOC_SIZE
222
      msg ("[MEM_MNGT][INFO] ALLOC MEM_BLOCK SIZE %d bytes pool %d (%p)\n", sizeP, pool_selected,le);
223
#endif
224 225
      return le;
    }
226 227

#ifdef DEBUG_MEM_MNGT_ALLOC
228
    msg ("[MEM_MNGT][ERROR][MINOR] memory pool %d is empty trying next pool alloc count = %d\n", pool_selected, counters[pool_selected]);
229
#ifdef USER_MODE
230 231
    //    display_mem_load ();
    //    check_mem_area ((void *)&mem_block_var);
232 233
#endif
#endif
234 235
  } while (pool_selected++ < 12);

236
  display_mem_load();
gauthier's avatar
gauthier committed
237
  mac_xface->macphy_exit("[MEM_MNGT][ERROR][FATAL] get_free_mem_block failed");
238 239 240 241 242 243 244
  return NULL;
};

//-----------------------------------------------------------------------------
mem_block_t      *
get_free_copy_mem_block (void)
{
245
  //-----------------------------------------------------------------------------
246 247 248 249
  mem_block_t      *le;

  if ((le = list_remove_head (&mem_block_var.mem_lists[MEM_MNGT_POOL_ID_COPY]))) {
#ifdef DEBUG_MEM_MNGT_ALLOC_SIZE
250
    msg ("[MEM_MNGT][INFO] ALLOC COPY MEM BLOCK (%p)\n",le);
251 252 253 254 255 256 257 258 259
#endif
    return le;
  } else {
    msg ("[MEM_MNGT][ERROR] POOL COPY IS EMPTY\n");
    //#ifdef DEBUG_MEM_MNGT_ALLOC
    check_mem_area ();
    //    break_point ();
    //#endif

gauthier's avatar
gauthier committed
260
    mac_xface->macphy_exit("[MEM_MNGT][ERROR][FATAL] get_free_copy_mem_block failed");
261 262 263 264 265 266 267 268
    return NULL;
  }
}

//-----------------------------------------------------------------------------
mem_block_t      *
copy_mem_block (mem_block_t * leP, mem_block_t * destP)
{
269
  //-----------------------------------------------------------------------------
270 271 272 273 274 275

  if ((destP != NULL) && (leP != NULL) && (destP->pool_id == MEM_MNGT_POOL_ID_COPY)) {
    destP->data = leP->data;
  } else {
    msg ("[MEM_MNGT][COPY] copy_mem_block() pool dest src or dest is NULL\n");
  }
276

277 278 279 280 281 282 283
  return destP;
}

//-----------------------------------------------------------------------------
void
display_mem_load (void)
{
284
  //-----------------------------------------------------------------------------
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321

  mem_pool       *memory = (mem_pool *) &mem_block_var;

  msg ("POOL 0 (%d elements of %d Bytes): ", MEM_MNGT_MB0_NB_BLOCKS, MEM_MNGT_MB0_BLOCK_SIZE);
  list_display (&memory->mem_lists[MEM_MNGT_POOL_ID0]);
  msg ("POOL 1 (%d elements of %d Bytes): ", MEM_MNGT_MB1_NB_BLOCKS, MEM_MNGT_MB1_BLOCK_SIZE);
  list_display (&memory->mem_lists[MEM_MNGT_POOL_ID1]);
  msg ("POOL 2 (%d elements of %d Bytes): ", MEM_MNGT_MB2_NB_BLOCKS, MEM_MNGT_MB2_BLOCK_SIZE);
  list_display (&memory->mem_lists[MEM_MNGT_POOL_ID2]);
  msg ("POOL 3 (%d elements of %d Bytes): ", MEM_MNGT_MB3_NB_BLOCKS, MEM_MNGT_MB3_BLOCK_SIZE);
  list_display (&memory->mem_lists[MEM_MNGT_POOL_ID3]);
  msg ("POOL 4 (%d elements of %d Bytes): ", MEM_MNGT_MB4_NB_BLOCKS, MEM_MNGT_MB4_BLOCK_SIZE);
  list_display (&memory->mem_lists[MEM_MNGT_POOL_ID4]);
  msg ("POOL 5 (%d elements of %d Bytes): ", MEM_MNGT_MB5_NB_BLOCKS, MEM_MNGT_MB5_BLOCK_SIZE);
  list_display (&memory->mem_lists[MEM_MNGT_POOL_ID5]);
  msg ("POOL 6 (%d elements of %d Bytes): ", MEM_MNGT_MB6_NB_BLOCKS, MEM_MNGT_MB6_BLOCK_SIZE);
  list_display (&memory->mem_lists[MEM_MNGT_POOL_ID6]);
  msg ("POOL 7 (%d elements of %d Bytes): ", MEM_MNGT_MB7_NB_BLOCKS, MEM_MNGT_MB7_BLOCK_SIZE);
  list_display (&memory->mem_lists[MEM_MNGT_POOL_ID7]);
  msg ("POOL 8 (%d elements of %d Bytes): ", MEM_MNGT_MB8_NB_BLOCKS, MEM_MNGT_MB8_BLOCK_SIZE);
  list_display (&memory->mem_lists[MEM_MNGT_POOL_ID8]);
  msg ("POOL 9 (%d elements of %d Bytes): ", MEM_MNGT_MB9_NB_BLOCKS, MEM_MNGT_MB9_BLOCK_SIZE);
  list_display (&memory->mem_lists[MEM_MNGT_POOL_ID9]);
  msg ("POOL 10 (%d elements of %d Bytes): ", MEM_MNGT_MB10_NB_BLOCKS, MEM_MNGT_MB10_BLOCK_SIZE);
  list_display (&memory->mem_lists[MEM_MNGT_POOL_ID10]);
  msg ("POOL 11 (%d elements of %d Bytes): ", MEM_MNGT_MB11_NB_BLOCKS, MEM_MNGT_MB11_BLOCK_SIZE);
  list_display (&memory->mem_lists[MEM_MNGT_POOL_ID11]);
  msg ("POOL 12 (%d elements of %d Bytes): ", MEM_MNGT_MB12_NB_BLOCKS, MEM_MNGT_MB12_BLOCK_SIZE);
  list_display (&memory->mem_lists[MEM_MNGT_POOL_ID12]);
  msg ("POOL C (%d elements): ", MEM_MNGT_MBCOPY_NB_BLOCKS);
  list_display (&memory->mem_lists[MEM_MNGT_POOL_ID_COPY]);
}

//-----------------------------------------------------------------------------
void
check_mem_area (void)
{
322
  //-----------------------------------------------------------------------------
323 324 325 326
  int             index, mb_index;
  mem_pool       *memory = (mem_pool *) &mem_block_var;

  for (index = 0; index < MEM_MNGT_MB0_NB_BLOCKS; index++) {
327
    if ((memory->mem_blocks[index].data != (unsigned char*)&(memory->mem_pool0[index][0])) && (memory->mem_blocks[index].pool_id != MEM_MNGT_POOL_ID0)) {
328 329 330
      msg ("[MEM] ERROR POOL0 block index %d\n", index);
    }
  }
331

332
  mb_index = MEM_MNGT_MB0_NB_BLOCKS;
333

334
  for (index = 0; index < MEM_MNGT_MB1_NB_BLOCKS; index++) {
335
    if ((memory->mem_blocks[mb_index + index].data != (unsigned char*)&(memory->mem_pool1[index][0])) && (memory->mem_blocks[mb_index + index].pool_id != MEM_MNGT_POOL_ID1)) {
336 337 338
      msg ("[MEM] ERROR POOL1 block index %d\n", index);
    }
  }
339

340
  mb_index += MEM_MNGT_MB1_NB_BLOCKS;
341

342
  for (index = 0; index < MEM_MNGT_MB2_NB_BLOCKS; index++) {
343
    if ((memory->mem_blocks[mb_index + index].data != (unsigned char*)&(memory->mem_pool2[index][0])) && (memory->mem_blocks[mb_index + index].pool_id != MEM_MNGT_POOL_ID2)) {
344 345 346
      msg ("[MEM] ERROR POOL2 block index %d\n", index);
    }
  }
347

348
  mb_index += MEM_MNGT_MB2_NB_BLOCKS;
349

350
  for (index = 0; index < MEM_MNGT_MB3_NB_BLOCKS; index++) {
351
    if ((memory->mem_blocks[mb_index + index].data != (unsigned char*)&(memory->mem_pool3[index][0])) && (memory->mem_blocks[mb_index + index].pool_id != MEM_MNGT_POOL_ID3)) {
352 353 354
      msg ("[MEM] ERROR POOL3 block index %d\n", index);
    }
  }
355

356
  mb_index += MEM_MNGT_MB3_NB_BLOCKS;
357

358
  for (index = 0; index < MEM_MNGT_MB4_NB_BLOCKS; index++) {
359
    if ((memory->mem_blocks[mb_index + index].data != (unsigned char*)&(memory->mem_pool4[index][0])) && (memory->mem_blocks[mb_index + index].pool_id != MEM_MNGT_POOL_ID4)) {
360 361 362
      msg ("[MEM] ERROR POOL4 block index %d\n", index);
    }
  }
363

364
  mb_index += MEM_MNGT_MB4_NB_BLOCKS;
365

366
  for (index = 0; index < MEM_MNGT_MB5_NB_BLOCKS; index++) {
367
    if ((memory->mem_blocks[mb_index + index].data != (unsigned char*)&(memory->mem_pool5[index][0])) && (memory->mem_blocks[mb_index + index].pool_id != MEM_MNGT_POOL_ID5)) {
368 369 370
      msg ("[MEM] ERROR POOL5 block index %d\n", index);
    }
  }
371

372
  mb_index += MEM_MNGT_MB5_NB_BLOCKS;
373

374
  for (index = 0; index < MEM_MNGT_MB6_NB_BLOCKS; index++) {
375
    if ((memory->mem_blocks[mb_index + index].data != (unsigned char*)&(memory->mem_pool6[index][0])) && (memory->mem_blocks[mb_index + index].pool_id != MEM_MNGT_POOL_ID6)) {
376 377 378
      msg ("[MEM] ERROR POOL6 block index %d\n", index);
    }
  }
379

380
  mb_index += MEM_MNGT_MB6_NB_BLOCKS;
381

382
  for (index = 0; index < MEM_MNGT_MB7_NB_BLOCKS; index++) {
383
    if ((memory->mem_blocks[mb_index + index].data != (unsigned char*)&(memory->mem_pool7[index][0])) && (memory->mem_blocks[mb_index + index].pool_id != MEM_MNGT_POOL_ID7)) {
384 385 386
      msg ("[MEM] ERROR POOL7 block index %d\n", index);
    }
  }
387

388
  mb_index += MEM_MNGT_MB7_NB_BLOCKS;
389

390
  for (index = 0; index < MEM_MNGT_MB8_NB_BLOCKS; index++) {
391
    if ((memory->mem_blocks[mb_index + index].data != (unsigned char*)&(memory->mem_pool8[index][0])) && (memory->mem_blocks[mb_index + index].pool_id != MEM_MNGT_POOL_ID8)) {
392 393 394
      msg ("[MEM] ERROR POOL8 block index %d\n", index);
    }
  }
395

396
  mb_index += MEM_MNGT_MB8_NB_BLOCKS;
397

398
  for (index = 0; index < MEM_MNGT_MB9_NB_BLOCKS; index++) {
399
    if ((memory->mem_blocks[mb_index + index].data != (unsigned char*)&(memory->mem_pool9[index][0])) && (memory->mem_blocks[mb_index + index].pool_id != MEM_MNGT_POOL_ID9)) {
400 401 402
      msg ("[MEM] ERROR POOL9 block index %d\n", index);
    }
  }
403

404
  mb_index += MEM_MNGT_MB9_NB_BLOCKS;
405

406
  for (index = mb_index; index < MEM_MNGT_MB10_NB_BLOCKS; index++) {
407 408 409
    if ((memory->mem_blocks[mb_index + index].data != (unsigned char*)&(memory->mem_pool10[index][0])) && (memory->mem_blocks[mb_index + index].pool_id != MEM_MNGT_POOL_ID10)) {
      msg ("[MEM] ERROR POOL10 block index %d\n", index);
    }
410
  }
411

412
  mb_index += MEM_MNGT_MB10_NB_BLOCKS;
413

414
  for (index = mb_index; index < MEM_MNGT_MB11_NB_BLOCKS; index++) {
415 416 417
    if ((memory->mem_blocks[mb_index + index].data != (unsigned char*)&(memory->mem_pool11[index][0])) && (memory->mem_blocks[mb_index + index].pool_id != MEM_MNGT_POOL_ID11)) {
      msg ("[MEM] ERROR POOL11 block index %d\n", index);
    }
418
  }
419

420
  mb_index += MEM_MNGT_MB11_NB_BLOCKS;
421

422
  for (index = mb_index; index < MEM_MNGT_MB12_NB_BLOCKS; index++) {
423 424 425
    if ((memory->mem_blocks[mb_index + index].data != (unsigned char*)&(memory->mem_pool12[index][0])) && (memory->mem_blocks[mb_index + index].pool_id != MEM_MNGT_POOL_ID12)) {
      msg ("[MEM] ERROR POOL12 block index %d\n", index);
    }
426
  }
427

428
  mb_index += MEM_MNGT_MB12_NB_BLOCKS;
429

430
  for (index = mb_index; index < MEM_MNGT_NB_ELEMENTS; index++) {
431 432 433
    if ((memory->mem_blocks[index].data != NULL) && (memory->mem_blocks[index].pool_id != MEM_MNGT_POOL_ID_COPY)) {
      msg ("[MEM] ERROR POOL COPY block index %d\n", index);
    }
434 435 436 437 438 439 440
  }
}

//-----------------------------------------------------------------------------
void
check_free_mem_block (mem_block_t * leP)
{
441
  //-----------------------------------------------------------------------------
Cedric Roux's avatar
Cedric Roux committed
442
  ptrdiff_t             block_index;
443

444 445 446 447 448
  if ((leP >= mem_block_var.mem_blocks) && (leP <= &mem_block_var.mem_blocks[MEM_MNGT_NB_ELEMENTS-1])) {
    // the pointer is inside the memory region
    block_index = leP - mem_block_var.mem_blocks;
    // block_index is now: 0 <= block_index < MEM_MNGT_NB_ELEMENTS

449
    if (block_index < MEM_MNGT_MB0_NB_BLOCKS) {
450
      if ((leP->data != (unsigned char*)mem_block_var.mem_pool0[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID0)) {
451 452
        msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
      }
453

454 455
      return;
    }
456

457 458 459 460
    block_index -= MEM_MNGT_MB0_NB_BLOCKS;

    if (block_index < MEM_MNGT_MB1_NB_BLOCKS) {
      if ((leP->data != (unsigned char*)mem_block_var.mem_pool1[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID1)) {
461 462
        msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
      }
463

464 465
      return;
    }
466

467 468 469 470
    block_index -= MEM_MNGT_MB1_NB_BLOCKS;

    if (block_index < MEM_MNGT_MB2_NB_BLOCKS) {
      if ((leP->data != (unsigned char*)mem_block_var.mem_pool2[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID2)) {
471 472
        msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
      }
473

474 475
      return;
    }
476

477 478 479 480
    block_index -= MEM_MNGT_MB2_NB_BLOCKS;

    if (block_index < MEM_MNGT_MB3_NB_BLOCKS) {
      if ((leP->data != (unsigned char*)mem_block_var.mem_pool3[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID3)) {
481 482
        msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
      }
483

484 485
      return;
    }
486

487 488 489 490
    block_index -= MEM_MNGT_MB3_NB_BLOCKS;

    if (block_index < MEM_MNGT_MB4_NB_BLOCKS) {
      if ((leP->data != (unsigned char*)mem_block_var.mem_pool4[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID4)) {
491 492
        msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
      }
493

494 495
      return;
    }
496

497 498 499 500
    block_index -= MEM_MNGT_MB4_NB_BLOCKS;

    if (block_index < MEM_MNGT_MB5_NB_BLOCKS) {
      if ((leP->data != (unsigned char*)mem_block_var.mem_pool5[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID5)) {
501 502
        msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
      }
503

504 505
      return;
    }
506

507 508 509 510
    block_index -= MEM_MNGT_MB5_NB_BLOCKS;

    if (block_index < MEM_MNGT_MB6_NB_BLOCKS) {
      if ((leP->data != (unsigned char*)mem_block_var.mem_pool6[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID6)) {
511 512
        msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
      }
513

514 515
      return;
    }
516

517 518 519 520
    block_index -= MEM_MNGT_MB6_NB_BLOCKS;

    if (block_index < MEM_MNGT_MB7_NB_BLOCKS) {
      if ((leP->data != (unsigned char*)mem_block_var.mem_pool7[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID7)) {
521 522
        msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
      }
523

524 525
      return;
    }
526

527 528 529 530
    block_index -= MEM_MNGT_MB7_NB_BLOCKS;

    if (block_index < MEM_MNGT_MB8_NB_BLOCKS) {
      if ((leP->data != (unsigned char*)mem_block_var.mem_pool8[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID8)) {
531 532
        msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
      }
533

534 535
      return;
    }
536

537 538 539 540
    block_index -= MEM_MNGT_MB8_NB_BLOCKS;

    if (block_index < MEM_MNGT_MB9_NB_BLOCKS) {
      if ((leP->data != (unsigned char*)mem_block_var.mem_pool9[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID9)) {
541 542
        msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
      }
543

544 545
      return;
    }
546

547 548 549 550
    block_index -= MEM_MNGT_MB9_NB_BLOCKS;

    if (block_index < MEM_MNGT_MB10_NB_BLOCKS) {
      if ((leP->data != (unsigned char*)mem_block_var.mem_pool10[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID10)) {
Cedric Roux's avatar
Cedric Roux committed
551 552
        msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
      }
553

554 555
      return;
    }
556

557 558 559 560
    block_index -= MEM_MNGT_MB10_NB_BLOCKS;

    if (block_index < MEM_MNGT_MB11_NB_BLOCKS) {
      if ((leP->data != (unsigned char*)mem_block_var.mem_pool11[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID11)) {
Cedric Roux's avatar
Cedric Roux committed
561 562
        msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
      }
563

564 565
      return;
    }
566

567 568 569 570
    block_index -= MEM_MNGT_MB11_NB_BLOCKS;

    if (block_index < MEM_MNGT_MB12_NB_BLOCKS) {
      if ((leP->data != (unsigned char*)mem_block_var.mem_pool12[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID12)) {
Cedric Roux's avatar
Cedric Roux committed
571 572
        msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
      }
573

574
      return;
Cedric Roux's avatar
Cedric Roux committed
575
    }
576 577 578
  } else {
    msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
  }
579 580

  // the block is ok
581
}