summaryrefslogtreecommitdiff
path: root/viengoos/zalloc.h
blob: 6dd5d945214cfb8ffeb2180c8cc1003e1a9ada47 (plain)
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
/* Fast memory allocator.
   Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc.
   Written by Neal H Walfield.

   This file is part of the GNU Hurd.

   The GNU Hurd 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.

   The GNU Hurd 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 this program.  If not, see
   <http://www.gnu.org/licenses/>.  */

#ifndef __ZALLOC_H__
#define __ZALLOC_H__

#include <stdint.h>
#include <hurd/stddef.h>

/* The amount of memory available (in PAGESIZE units).  */
extern uintptr_t zalloc_memory;

/* Add to the pool the block BLOCK of size SIZE.  BLOCK must be
   aligned to the system's minimum page size.  SIZE must be a multiple
   of the system's minimum page size.  */
void zfree (uintptr_t block, uintptr_t size);

/* Allocate a block of memory of size SIZE.  SIZE must be a multiple
   of the system's minimum page size. */
uintptr_t zalloc_internal (uintptr_t size);

static inline uintptr_t
zalloc (uintptr_t size)
{
  if (size / PAGESIZE > zalloc_memory)
    return 0;

  return zalloc_internal (size);
}

/* Dump some internal data structures.  Only defined if zalloc was
   compiled without NDEBUG defined.  */
void zalloc_dump_zones (const char *prefix);

#endif	/* __ZALLOC_H__ */