2N/A/* mm.h - prototypes and declarations for memory manager */
2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2002,2007 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#ifndef GRUB_MM_H
2N/A#define GRUB_MM_H 1
2N/A
2N/A#include <grub/types.h>
2N/A#include <grub/symbol.h>
2N/A#include <config.h>
2N/A
2N/A#ifndef NULL
2N/A# define NULL ((void *) 0)
2N/A#endif
2N/A
2N/Avoid grub_mm_init_region (void *addr, grub_size_t size);
2N/Avoid *EXPORT_FUNC(grub_malloc) (grub_size_t size);
2N/Avoid *EXPORT_FUNC(grub_zalloc) (grub_size_t size);
2N/Avoid EXPORT_FUNC(grub_free) (void *ptr);
2N/Avoid *EXPORT_FUNC(grub_realloc) (void *ptr, grub_size_t size);
2N/Avoid *EXPORT_FUNC(grub_memalign) (grub_size_t align, grub_size_t size);
2N/A
2N/Avoid grub_mm_check_real (char *file, int line);
2N/A#define grub_mm_check() grub_mm_check_real (GRUB_FILE, __LINE__);
2N/A
2N/A/* For debugging. */
2N/A#if defined(MM_DEBUG) && !defined(GRUB_UTIL) && !defined (GRUB_MACHINE_EMU)
2N/A/* Set this variable to 1 when you want to trace all memory function calls. */
2N/Aextern int EXPORT_VAR(grub_mm_debug);
2N/A
2N/Avoid grub_mm_dump_free (void);
2N/Avoid grub_mm_dump (unsigned lineno);
2N/A
2N/A#define grub_malloc(size) \
2N/A grub_debug_malloc (GRUB_FILE, __LINE__, size)
2N/A
2N/A#define grub_zalloc(size) \
2N/A grub_debug_zalloc (GRUB_FILE, __LINE__, size)
2N/A
2N/A#define grub_realloc(ptr,size) \
2N/A grub_debug_realloc (GRUB_FILE, __LINE__, ptr, size)
2N/A
2N/A#define grub_memalign(align,size) \
2N/A grub_debug_memalign (GRUB_FILE, __LINE__, align, size)
2N/A
2N/A#define grub_free(ptr) \
2N/A grub_debug_free (GRUB_FILE, __LINE__, ptr)
2N/A
2N/Avoid *EXPORT_FUNC(grub_debug_malloc) (const char *file, int line,
2N/A grub_size_t size);
2N/Avoid *EXPORT_FUNC(grub_debug_zalloc) (const char *file, int line,
2N/A grub_size_t size);
2N/Avoid EXPORT_FUNC(grub_debug_free) (const char *file, int line, void *ptr);
2N/Avoid *EXPORT_FUNC(grub_debug_realloc) (const char *file, int line, void *ptr,
2N/A grub_size_t size);
2N/Avoid *EXPORT_FUNC(grub_debug_memalign) (const char *file, int line,
2N/A grub_size_t align, grub_size_t size);
2N/A#endif /* MM_DEBUG && ! GRUB_UTIL */
2N/A
2N/A#include <grub/err.h>
2N/A
2N/Astatic inline grub_err_t
2N/Agrub_extend_alloc (grub_size_t sz, grub_size_t *allocated, void **ptr)
2N/A{
2N/A void *n;
2N/A if (sz < *allocated)
2N/A return GRUB_ERR_NONE;
2N/A
2N/A *allocated = 2 * sz;
2N/A n = grub_realloc (*ptr, *allocated);
2N/A if (!n)
2N/A return grub_errno;
2N/A *ptr = n;
2N/A return GRUB_ERR_NONE;
2N/A}
2N/A
2N/Astatic inline grub_size_t
2N/Agrub_page_align (grub_size_t size)
2N/A{
2N/A return (size + (1 << 12) - 1) & (~((1 << 12) - 1));
2N/A}
2N/A
2N/A#endif /* ! GRUB_MM_H */