ReactOS  0.4.14-dev-98-gb0d4763
memp.h File Reference
#include "lwip/opt.h"
#include "lwip/memp_std.h"
Include dependency graph for memp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LWIP_MEMPOOL(name, num, size, desc)   MEMP_##name,
 

Enumerations

enum  memp_t { MEMP_MAX }
 

Functions

void memp_init (void)
 
voidmemp_malloc (memp_t type)
 
void memp_free (memp_t type, void *mem)
 

Macro Definition Documentation

◆ LWIP_MEMPOOL

#define LWIP_MEMPOOL (   name,
  num,
  size,
  desc 
)    MEMP_##name,

Definition at line 44 of file memp.h.

Enumeration Type Documentation

◆ memp_t

Enumerator
MEMP_MAX 

Definition at line 43 of file memp.h.

43  {
44 #define LWIP_MEMPOOL(name,num,size,desc) MEMP_##name,
45 #include "lwip/memp_std.h"
46  MEMP_MAX
47 } memp_t;
Definition: memp.h:46
memp_t
Definition: memp.h:43

Function Documentation

◆ memp_free()

void memp_free ( memp_t  type,
void mem 
)

Put an element back into its pool.

Parameters
typethe pool where to put mem
memthe memp element to free

Definition at line 435 of file memp.c.

436 {
437  struct memp *memp;
438  SYS_ARCH_DECL_PROTECT(old_level);
439 
440  if (mem == NULL) {
441  return;
442  }
443  LWIP_ASSERT("memp_free: mem properly aligned",
444  ((mem_ptr_t)mem % MEM_ALIGNMENT) == 0);
445 
446  memp = (struct memp *)(void *)((u8_t*)mem - MEMP_SIZE);
447 
448  SYS_ARCH_PROTECT(old_level);
449 #if MEMP_OVERFLOW_CHECK
450 #if MEMP_OVERFLOW_CHECK >= 2
451  memp_overflow_check_all();
452 #else
453  memp_overflow_check_element_overflow(memp, type);
454  memp_overflow_check_element_underflow(memp, type);
455 #endif /* MEMP_OVERFLOW_CHECK >= 2 */
456 #endif /* MEMP_OVERFLOW_CHECK */
457 
459 
460  memp->next = memp_tab[type];
461  memp_tab[type] = memp;
462 
463 #if MEMP_SANITY_CHECK
464  LWIP_ASSERT("memp sanity", memp_sanity());
465 #endif /* MEMP_SANITY_CHECK */
466 
467  SYS_ARCH_UNPROTECT(old_level);
468 }
#define MEM_ALIGNMENT
Definition: d3d9_helpers.c:15
#define MEMP_SIZE
Definition: memp.c:110
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:66
smooth NULL
Definition: ftsmooth.c:416
c used
Definition: write.c:2877
struct memp * next
Definition: memp.c:67
#define SYS_ARCH_PROTECT(lev)
Definition: cc.h:55
Definition: memp.c:66
ULONG_PTR mem_ptr_t
Definition: cc.h:33
static struct memp * memp_tab[MEMP_MAX]
Definition: memp.c:117
unsigned char u8_t
Definition: cc.h:23
#define SYS_ARCH_DECL_PROTECT(lev)
Definition: cc.h:54
Definition: mem.c:156
#define SYS_ARCH_UNPROTECT(lev)
Definition: cc.h:56
#define MEMP_STATS_DEC(x, i)
Definition: stats.h:254

Referenced by pbuf_free(), tcpip_callback_with_block(), tcpip_callbackmsg_delete(), tcpip_input(), and tcpip_thread().

◆ memp_init()

void memp_init ( void  )

Initialize this module.

Carves out memp_memory into linked lists for each pool-type.

Definition at line 338 of file memp.c.

339 {
340  struct memp *memp;
341  u16_t i, j;
342 
343  for (i = 0; i < MEMP_MAX; ++i) {
344  MEMP_STATS_AVAIL(used, i, 0);
345  MEMP_STATS_AVAIL(max, i, 0);
346  MEMP_STATS_AVAIL(err, i, 0);
348  }
349 
350 #if !MEMP_SEPARATE_POOLS
351  memp = (struct memp *)LWIP_MEM_ALIGN(memp_memory);
352 #endif /* !MEMP_SEPARATE_POOLS */
353  /* for every pool: */
354  for (i = 0; i < MEMP_MAX; ++i) {
355  memp_tab[i] = NULL;
356 #if MEMP_SEPARATE_POOLS
357  memp = (struct memp*)memp_bases[i];
358 #endif /* MEMP_SEPARATE_POOLS */
359  /* create a linked list of memp elements */
360  for (j = 0; j < memp_num[i]; ++j) {
361  memp->next = memp_tab[i];
362  memp_tab[i] = memp;
363  memp = (struct memp *)(void *)((u8_t *)memp + MEMP_SIZE + memp_sizes[i]
365  + MEMP_SANITY_REGION_AFTER_ALIGNED
366 #endif
367  );
368  }
369  }
370 #if MEMP_OVERFLOW_CHECK
371  memp_overflow_init();
372  /* check everything a first time to see if it worked */
373  memp_overflow_check_all();
374 #endif /* MEMP_OVERFLOW_CHECK */
375 }
static const u16_t memp_sizes[MEMP_MAX]
Definition: memp.c:129
#define max(a, b)
Definition: svc.c:63
Definition: memp.h:46
#define MEMP_STATS_AVAIL(x, i, y)
Definition: stats.h:252
#define MEMP_SIZE
Definition: memp.c:110
static const u16_t memp_num[MEMP_MAX]
Definition: memp.c:137
static int avail
Definition: adh-main.c:39
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
c used
Definition: write.c:2877
#define MEMP_OVERFLOW_CHECK
Definition: opt.h:154
struct memp * next
Definition: memp.c:67
Definition: memp.c:66
#define err(...)
static struct memp * memp_tab[MEMP_MAX]
Definition: memp.c:117
static u8_t memp_memory[MEM_ALIGNMENT - 1 #define LWIP_MEMPOOL(name, num, size, desc)]
Definition: memp.c:173
unsigned char u8_t
Definition: cc.h:23
#define LWIP_MEM_ALIGN(addr)
Definition: mem.h:116
unsigned short u16_t
Definition: cc.h:24

Referenced by lwip_init().

◆ memp_malloc()

void* memp_malloc ( memp_t  type)

Get an element from a specific pool.

Parameters
typethe pool to get an element from

the debug version has two more parameters:

Parameters
filefile name calling this function
linenumber of line where this function is called
Returns
a pointer to the allocated memory or a NULL pointer on error

Definition at line 390 of file memp.c.

394 {
395  struct memp *memp;
396  SYS_ARCH_DECL_PROTECT(old_level);
397 
398  LWIP_ERROR("memp_malloc: type < MEMP_MAX", (type < MEMP_MAX), return NULL;);
399 
400  SYS_ARCH_PROTECT(old_level);
401 #if MEMP_OVERFLOW_CHECK >= 2
402  memp_overflow_check_all();
403 #endif /* MEMP_OVERFLOW_CHECK >= 2 */
404 
405  memp = memp_tab[type];
406 
407  if (memp != NULL) {
408  memp_tab[type] = memp->next;
409 #if MEMP_OVERFLOW_CHECK
410  memp->next = NULL;
411  memp->file = file;
412  memp->line = line;
413 #endif /* MEMP_OVERFLOW_CHECK */
415  LWIP_ASSERT("memp_malloc: memp properly aligned",
416  ((mem_ptr_t)memp % MEM_ALIGNMENT) == 0);
417  memp = (struct memp*)(void *)((u8_t*)memp + MEMP_SIZE);
418  } else {
419  LWIP_DEBUGF(MEMP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("memp_malloc: out of memory in pool %s\n", memp_desc[type]));
421  }
422 
423  SYS_ARCH_UNPROTECT(old_level);
424 
425  return memp;
426 }
Definition: memp.h:46
#define MEM_ALIGNMENT
Definition: d3d9_helpers.c:15
#define MEMP_SIZE
Definition: memp.c:110
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:66
#define MEMP_DEBUG
Definition: opt.h:1989
smooth NULL
Definition: ftsmooth.c:416
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:95
c used
Definition: write.c:2877
#define MEMP_STATS_INC_USED(x, i)
Definition: stats.h:255
struct memp * next
Definition: memp.c:67
const char file[]
Definition: icontest.c:11
#define SYS_ARCH_PROTECT(lev)
Definition: cc.h:55
char line[200]
Definition: main.c:97
Definition: memp.c:66
#define err(...)
ULONG_PTR mem_ptr_t
Definition: cc.h:33
static struct memp * memp_tab[MEMP_MAX]
Definition: memp.c:117
#define LWIP_ERROR(message, expression, handler)
Definition: debug.h:74
#define LWIP_DBG_LEVEL_SERIOUS
Definition: debug.h:47
unsigned char u8_t
Definition: cc.h:23
#define SYS_ARCH_DECL_PROTECT(lev)
Definition: cc.h:54
#define SYS_ARCH_UNPROTECT(lev)
Definition: cc.h:56
#define MEMP_STATS_INC(x, i)
Definition: stats.h:253

Referenced by pbuf_alloc(), tcpip_callback_with_block(), tcpip_callbackmsg_new(), and tcpip_input().