xref: /dflybsd-src/contrib/cvs-1.12/lib/pagealign_alloc.h (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
1*86d7f5d3SJohn Marino /* Memory allocation aligned to system page boundaries.
2*86d7f5d3SJohn Marino 
3*86d7f5d3SJohn Marino    Copyright (C) 2005 Free Software Foundation, Inc.
4*86d7f5d3SJohn Marino 
5*86d7f5d3SJohn Marino    This program is free software; you can redistribute it and/or modify it
6*86d7f5d3SJohn Marino    under the terms of the GNU General Public License as published
7*86d7f5d3SJohn Marino    by the Free Software Foundation; either version 2, or (at your option)
8*86d7f5d3SJohn Marino    any later version.
9*86d7f5d3SJohn Marino 
10*86d7f5d3SJohn Marino    This program is distributed in the hope that it will be useful,
11*86d7f5d3SJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
12*86d7f5d3SJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13*86d7f5d3SJohn Marino    General Public License for more details.
14*86d7f5d3SJohn Marino 
15*86d7f5d3SJohn Marino    You should have received a copy of the GNU General Public
16*86d7f5d3SJohn Marino    License along with this program; if not, write to the Free Software
17*86d7f5d3SJohn Marino    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18*86d7f5d3SJohn Marino    USA.  */
19*86d7f5d3SJohn Marino 
20*86d7f5d3SJohn Marino #ifndef _PAGEALIGN_ALLOC_H
21*86d7f5d3SJohn Marino # define _PAGEALIGN_ALLOC_H
22*86d7f5d3SJohn Marino 
23*86d7f5d3SJohn Marino # include <stddef.h>
24*86d7f5d3SJohn Marino 
25*86d7f5d3SJohn Marino /* Allocate a block of memory of SIZE bytes, aligned on a system page
26*86d7f5d3SJohn Marino    boundary.
27*86d7f5d3SJohn Marino    If SIZE is not a multiple of the system page size, it will be rounded up
28*86d7f5d3SJohn Marino    to the next multiple.
29*86d7f5d3SJohn Marino    Return a pointer to the start of the memory block. Upon allocation failure,
30*86d7f5d3SJohn Marino    return NULL and set errno.  */
31*86d7f5d3SJohn Marino extern void *pagealign_alloc (size_t size);
32*86d7f5d3SJohn Marino 
33*86d7f5d3SJohn Marino /* Like pagealign_alloc, except it exits the program if the allocation
34*86d7f5d3SJohn Marino    fails.  */
35*86d7f5d3SJohn Marino extern void *pagealign_xalloc (size_t size);
36*86d7f5d3SJohn Marino 
37*86d7f5d3SJohn Marino /* Free a memory block.
38*86d7f5d3SJohn Marino    PTR must be a non-NULL pointer returned by pagealign_alloc or
39*86d7f5d3SJohn Marino    pagealign_xalloc.  */
40*86d7f5d3SJohn Marino extern void pagealign_free (void *ptr);
41*86d7f5d3SJohn Marino 
42*86d7f5d3SJohn Marino #endif /* _PAGEALIGN_ALLOC_H */
43