File: mm_private.h

package info (click to toggle)
grub2 2.14~git20250718.0e36779-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 60,688 kB
  • sloc: ansic: 541,811; asm: 68,074; sh: 9,803; cpp: 2,095; makefile: 1,895; python: 1,518; sed: 446; lex: 393; yacc: 268; awk: 85; lisp: 54; perl: 31
file content (115 lines) | stat: -rw-r--r-- 3,328 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 *  GRUB  --  GRand Unified Bootloader
 *  Copyright (C) 2010  Free Software Foundation, Inc.
 *
 *  GRUB is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  GRUB is distributed in the hope that it will be useful,
 *  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
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef GRUB_MM_PRIVATE_H
#define GRUB_MM_PRIVATE_H	1

#include <grub/mm.h>
#include <grub/misc.h>

/* For context, see kern/mm.c */

/* Magic words.  */
#define GRUB_MM_FREE_MAGIC	0x2d3c2808
#define GRUB_MM_ALLOC_MAGIC	0x6db08fa4

/* A header describing a block of memory - either allocated or free */
typedef struct grub_mm_header
{
  /*
   * The 'next' free block in this region's circular free list.
   * Only meaningful if the block is free.
   */
  struct grub_mm_header *next;
  /* The block size, not in bytes but the number of cells of
   * GRUB_MM_ALIGN bytes. Includes the header cell.
   */
  grub_size_t size;
  /* either free or alloc magic, depending on the block type. */
  grub_size_t magic;
  /* pad to cell size: see the top of kern/mm.c. */
#if GRUB_CPU_SIZEOF_VOID_P == 4
  char padding[4];
#elif GRUB_CPU_SIZEOF_VOID_P == 8
  char padding[8];
#else
# error "unknown word size"
#endif
}
*grub_mm_header_t;

#if GRUB_CPU_SIZEOF_VOID_P == 4
# define GRUB_MM_ALIGN_LOG2	4
#elif GRUB_CPU_SIZEOF_VOID_P == 8
# define GRUB_MM_ALIGN_LOG2	5
#endif

#define GRUB_MM_ALIGN	(1 << GRUB_MM_ALIGN_LOG2)

/* A region from which we can make allocations. */
typedef struct grub_mm_region
{
  /* The first free block in this region. */
  struct grub_mm_header *first;

  /*
   * The next region in the linked list of regions. Regions are initially
   * sorted in order of increasing size, but can grow, in which case the
   * ordering may not be preserved.
   */
  struct grub_mm_region *next;

  /*
   * A grub_mm_region will always be aligned to cell size. The pre-size is
   * the number of bytes we were given but had to skip in order to get that
   * alignment.
   */
  grub_size_t pre_size;

  /*
   * Likewise, the post-size is the number of bytes we wasted at the end
   * of the allocation because it wasn't a multiple of GRUB_MM_ALIGN
   */
  grub_size_t post_size;

  /* How many bytes are in this region? (free and allocated) */
  grub_size_t size;

  /* pad to a multiple of cell size */
  char padding[3 * GRUB_CPU_SIZEOF_VOID_P];
}
*grub_mm_region_t;

#ifndef GRUB_MACHINE_EMU
extern grub_mm_region_t EXPORT_VAR (grub_mm_base);
#endif

static inline void
grub_mm_size_sanity_check (void) {
  /* Ensure we preserve alignment when doing h = (grub_mm_header_t) (r + 1). */
  COMPILE_TIME_ASSERT ((sizeof (struct grub_mm_region) %
		        sizeof (struct grub_mm_header)) == 0);

  /*
   * GRUB_MM_ALIGN is supposed to represent cell size, and a mm_header is
   * supposed to be 1 cell.
   */
  COMPILE_TIME_ASSERT (sizeof (struct grub_mm_header) == GRUB_MM_ALIGN);
}

#endif