1 #include <lwip/mem.h> 2 3 #ifndef LWIP_TAG 4 #define LWIP_TAG 'PIwl' 5 #endif 6 7 void * 8 malloc(mem_size_t size) 9 { 10 return ExAllocatePoolWithTag(NonPagedPool, size, LWIP_TAG); 11 } 12 13 void * 14 calloc(mem_size_t count, mem_size_t size) 15 { 16 void *mem = malloc(count * size); 17 18 if (!mem) return NULL; 19 20 RtlZeroMemory(mem, count * size); 21 22 return mem; 23 } 24 25 void 26 free(void *mem) 27 { 28 ExFreePoolWithTag(mem, LWIP_TAG); 29 } 30 31 /* This is only used to trim in lwIP */ 32 void * 33 realloc(void *mem, size_t size) 34 { 35 void* new_mem; 36 37 /* realloc() with a NULL mem pointer acts like a call to malloc() */ 38 if (mem == NULL) { 39 return malloc(size); 40 } 41 42 /* realloc() with a size 0 acts like a call to free() */ 43 if (size == 0) { 44 free(mem); 45 return NULL; 46 } 47 48 /* Allocate the new buffer first */ 49 new_mem = malloc(size); 50 if (new_mem == NULL) { 51 /* The old buffer is still intact */ 52 return NULL; 53 } 54 55 /* Copy the data over */ 56 RtlCopyMemory(new_mem, mem, size); 57 58 /* Deallocate the old buffer */ 59 free(mem); 60 61 /* Return the newly allocated block */ 62 return new_mem; 63 } 64