5 * \brief Memory allocator interface
8 * (c) 2008-2009 Technische Universität Dresden
9 * This file is part of TUD:OS and distributed under the terms of the
10 * GNU General Public License 2.
11 * Please see the COPYING-GPL-2 file for details.
13 * As a special exception, you may use this file as part of a free software
14 * library without restriction. Specifically, if other files instantiate
15 * templates or use macros or inline functions from this file, or you compile
16 * this file and link it with other files to produce an executable, this
17 * file does not by itself cause the resulting executable to be covered by
18 * the GNU General Public License. This exception does not however
19 * invalidate any other reasons why the executable file might be covered by
20 * the GNU General Public License.
24 #include <l4/sys/capability>
25 #include <l4/re/protocols>
31 // * alignment constraints
32 // * shall we support superpages in noncont memory?
35 * \defgroup api_l4re_mem_alloc Memory allocator API
37 * \brief Memory-allocator interface.
39 * The memory-allocator API is the basic API to allocate memory from the
40 * L4Re subsystem. The memory is allocated in terms of data spaces (see
41 * L4Re::Dataspace). The provided data spaces have at least the
42 * property that data written to such a data space is available as long
43 * as the data space is not freed or the data is not overwritten. In particular,
44 * the memory backing a data space from an allocator need not be allocated
45 * instantly, but may be allocated lazily on demand.
47 * A memory allocator can provide data spaces with a additional properties,
48 * such as physically contiguous memory, pre-allocated memory, or pinned
49 * memory. To request memory with an additional property the
50 * L4Re::Mem_alloc::alloc() method provides a flags parameter. If the
51 * concrete implementation of a memory allocator does not support or allow
52 * allocation of memory with a certain property, the allocation may be
55 * The main interface is defined by the class L4Re::Mem_alloc.
59 * \brief Memory allocator.
60 * \ingroup api_l4re_mem_alloc
62 * Memory-allocator interface, for more information see
63 * \link api_l4re_mem_alloc Memory-allocator API \endlink.
65 class L4_EXPORT Mem_alloc :
66 public L4::Kobject_t<Mem_alloc, L4::Kobject, L4Re::Protocol::Mem_alloc>
72 * \brief Flags for the allocator
76 Continuous = 0x01, ///< Allocate physically contiguous data space, if supported by the allocator
77 Pinned = 0x02, ///< Allocate pinned data space, if supported by the allocator
78 Super_pages = 0x04, ///< Allocate super pages, if supported by the allocator
81 * \brief Allocate anonymous memory.
83 * \param size Size to be requested in bytes (granularity
84 * is (super)pages and the size is rounded up to this
86 * \param mem Object capability for the data space to be allocated.
87 * \param flags Flags, see #Mem_alloc_flags, default none
89 * \return 0 on success, <0 on error
93 long alloc(unsigned long size, L4::Cap<Dataspace> mem,
94 unsigned long flags = 0) const throw();
96 * \brief Free data space.
98 * \param mem Data space that contains the memory.
100 * \return 0 on success, <0 on error
104 long free(L4::Cap<Dataspace> mem) const throw();