mm.h 2.63 KB
Newer Older
okuji's avatar
okuji committed
1 2
/* mm.h - prototypes and declarations for memory manager */
/*
3
 *  GRUB  --  GRand Unified Bootloader
4
 *  Copyright (C) 2002,2007  Free Software Foundation, Inc.
okuji's avatar
okuji committed
5
 *
6
 *  GRUB is free software: you can redistribute it and/or modify
okuji's avatar
okuji committed
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation, either version 3 of the License, or
okuji's avatar
okuji committed
9 10
 *  (at your option) any later version.
 *
11
 *  GRUB is distributed in the hope that it will be useful,
okuji's avatar
okuji committed
12 13 14 15 16
 *  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
17
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
okuji's avatar
okuji committed
18 19
 */

20 21
#ifndef GRUB_MM_H
#define GRUB_MM_H	1
okuji's avatar
okuji committed
22

23 24
#include <grub/types.h>
#include <grub/symbol.h>
25
#include <config.h>
okuji's avatar
okuji committed
26

27 28 29 30
#ifndef NULL
# define NULL	((void *) 0)
#endif

31 32
void grub_mm_init_region (void *addr, grub_size_t size);
void *EXPORT_FUNC(grub_malloc) (grub_size_t size);
33
void *EXPORT_FUNC(grub_zalloc) (grub_size_t size);
34
void EXPORT_FUNC(grub_free) (void *ptr);
35
void *EXPORT_FUNC(grub_realloc) (void *ptr, grub_size_t size);
36
#ifndef GRUB_MACHINE_EMU
37
void *EXPORT_FUNC(grub_memalign) (grub_size_t align, grub_size_t size);
38
#endif
okuji's avatar
okuji committed
39

40
void grub_mm_check_real (const char *file, int line);
41
#define grub_mm_check() grub_mm_check_real (GRUB_FILE, __LINE__);
42

okuji's avatar
okuji committed
43
/* For debugging.  */
44
#if defined(MM_DEBUG) && !defined(GRUB_UTIL) && !defined (GRUB_MACHINE_EMU)
45 46 47
/* Set this variable to 1 when you want to trace all memory function calls.  */
extern int EXPORT_VAR(grub_mm_debug);

48
void grub_mm_dump_free (void);
49
void grub_mm_dump (unsigned lineno);
50 51

#define grub_malloc(size)	\
52
  grub_debug_malloc (GRUB_FILE, __LINE__, size)
53

54
#define grub_zalloc(size)	\
55
  grub_debug_zalloc (GRUB_FILE, __LINE__, size)
56

57
#define grub_realloc(ptr,size)	\
58
  grub_debug_realloc (GRUB_FILE, __LINE__, ptr, size)
59 60

#define grub_memalign(align,size)	\
61
  grub_debug_memalign (GRUB_FILE, __LINE__, align, size)
62 63

#define grub_free(ptr)	\
64
  grub_debug_free (GRUB_FILE, __LINE__, ptr)
65 66 67

void *EXPORT_FUNC(grub_debug_malloc) (const char *file, int line,
				      grub_size_t size);
68 69
void *EXPORT_FUNC(grub_debug_zalloc) (const char *file, int line,
				       grub_size_t size);
70 71 72 73 74 75
void EXPORT_FUNC(grub_debug_free) (const char *file, int line, void *ptr);
void *EXPORT_FUNC(grub_debug_realloc) (const char *file, int line, void *ptr,
				       grub_size_t size);
void *EXPORT_FUNC(grub_debug_memalign) (const char *file, int line,
					grub_size_t align, grub_size_t size);
#endif /* MM_DEBUG && ! GRUB_UTIL */
okuji's avatar
okuji committed
76

77
#endif /* ! GRUB_MM_H */