Blame lib/memory.h

Packit c22fc9
/*
Packit c22fc9
 * Soft:        Keepalived is a failover program for the LVS project
Packit c22fc9
 *              <www.linuxvirtualserver.org>. It monitor & manipulate
Packit c22fc9
 *              a loadbalanced server pool using multi-layer checks.
Packit c22fc9
 *
Packit c22fc9
 * Part:        memory.c include file.
Packit c22fc9
 *
Packit c22fc9
 * Authors:     Alexandre Cassen, <acassen@linux-vs.org>
Packit c22fc9
 *              Jan Holmberg, <jan@artech.net>
Packit c22fc9
 *
Packit c22fc9
 *              This program is distributed in the hope that it will be useful,
Packit c22fc9
 *              but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit c22fc9
 *              MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Packit c22fc9
 *              See the GNU General Public License for more details.
Packit c22fc9
 *
Packit c22fc9
 *              This program is free software; you can redistribute it and/or
Packit c22fc9
 *              modify it under the terms of the GNU General Public License
Packit c22fc9
 *              as published by the Free Software Foundation; either version
Packit c22fc9
 *              2 of the License, or (at your option) any later version.
Packit c22fc9
 *
Packit c22fc9
 * Copyright (C) 2001-2017 Alexandre Cassen, <acassen@gmail.com>
Packit c22fc9
 */
Packit c22fc9
Packit c22fc9
#ifndef _MEMORY_H
Packit c22fc9
#define _MEMORY_H
Packit c22fc9
Packit c22fc9
#include "config.h"
Packit c22fc9
Packit c22fc9
/* system includes */
Packit c22fc9
#include <stddef.h>
Packit c22fc9
#ifdef _MEM_CHECK_
Packit c22fc9
#include <sys/types.h>
Packit c22fc9
#else
Packit c22fc9
#include <stdlib.h>
Packit c22fc9
#endif
Packit c22fc9
Packit c22fc9
/* Local defines */
Packit c22fc9
#ifdef _MEM_CHECK_
Packit c22fc9
Packit c22fc9
#define MALLOC(n)    ( keepalived_malloc((n), \
Packit c22fc9
		      (__FILE__), (char *)(__FUNCTION__), (__LINE__)) )
Packit c22fc9
#define FREE(b)      ( keepalived_free((b), \
Packit c22fc9
		      (__FILE__), (char *)(__FUNCTION__), (__LINE__)), \
Packit c22fc9
		       (b) = NULL )
Packit c22fc9
#define REALLOC(b,n) ( keepalived_realloc((b), (n), \
Packit c22fc9
		      (__FILE__), (char *)(__FUNCTION__), (__LINE__)) )
Packit c22fc9
Packit c22fc9
extern size_t mem_allocated;
Packit c22fc9
Packit c22fc9
/* Memory debug prototypes defs */
Packit c22fc9
extern void memcheck_log(const char *, const char *, const char *, const char *, int);
Packit c22fc9
extern void *keepalived_malloc(size_t, const char *, const char *, int)
Packit c22fc9
		__attribute__((alloc_size(1))) __attribute__((malloc));
Packit c22fc9
extern void keepalived_free(void *, const char *, const char *, int);
Packit c22fc9
extern void *keepalived_realloc(void *, size_t, const char *, const char *, int)
Packit c22fc9
		__attribute__((alloc_size(2)));
Packit c22fc9
Packit c22fc9
extern void keepalived_alloc_dump(void);
Packit c22fc9
extern void mem_log_init(const char *, const char *);
Packit c22fc9
extern void skip_mem_dump(void);
Packit c22fc9
extern void enable_mem_log_termination(void);
Packit c22fc9
Packit c22fc9
#else
Packit c22fc9
Packit c22fc9
extern void *zalloc(unsigned long size);
Packit c22fc9
Packit c22fc9
#define MALLOC(n)    (zalloc(n))
Packit c22fc9
#define FREE(p)      (free(p), (p) = NULL)
Packit c22fc9
#define REALLOC(p,n) (realloc((p),(n)))
Packit c22fc9
Packit c22fc9
#endif
Packit c22fc9
Packit c22fc9
/* Common defines */
Packit c22fc9
#define PMALLOC(p)	{ p = MALLOC(sizeof(*p)); }
Packit c22fc9
#define FREE_PTR(p)	{ if (p) { FREE(p);} }
Packit c22fc9
#endif