L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
mem_alloc
Go to the documentation of this file.
1// -*- Mode: C++ -*-
2// vim:ft=cpp
7/*
8 * Copyright (C) 2014-2016, 2019, 2021, 2024-2025 Kernkonzept GmbH.
9 * Author(s): Alexander Warg <alexander.warg@kernkonzept.com>
10 */
11/*
12 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
13 * Alexander Warg <warg@os.inf.tu-dresden.de>,
14 * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
15 * economic rights: Technische Universität Dresden (Germany)
16 *
17 * License: see LICENSE.spdx (in this directory or the directories above)
18 */
19#pragma once
20
21#include <l4/re/protocols.h>
22#include <l4/sys/capability>
23#include <l4/sys/cxx/ipc_iface>
24#include <l4/sys/factory>
25
26namespace L4Re {
27class Dataspace;
28
29// MISSING:
30// * alignment constraints
31// * shall we support superpages in noncont memory?
32
53 public L4::Kobject_t<Mem_alloc, L4::Factory, L4RE_PROTO_MEM_ALLOC>
54{
55public:
62 enum Mem_alloc_flags : unsigned long
63 {
64 Continuous = 0x01,
65 Pinned = 0x02,
66 Super_pages = 0x04,
67 Fixed_paddr = 0x08,
69
70 Dma_mask_bits = 0x3f0,
72 };
73
80 static L4_INLINE L4_CONSTEXPR unsigned Dma_mask(unsigned bits)
81 {
82 if (L4_UNLIKELY(bits > 64))
83 return 0;
84
85 if (L4_UNLIKELY(bits == 0))
86 bits = 1; // prevent overflow below
87
88 // Implemented as (64 - bits) << 4 for backwards compatibility.
89 return (64 - bits) << 4;
90 }
91
149
184 l4_ret_t alloc(long size, L4::Cap<Dataspace> mem, unsigned long flags = 0,
185 unsigned long align = 0, l4_addr_t paddr = 0,
186 char const *type = nullptr) const noexcept;
187
196 L4_INLINE_RPC(long, info, (Stats &stats));
197
198 typedef L4::Typeid::Rpcs<info_t> Rpcs;
199};
200
201};
L4::Cap related definitions.
Interface for memory-like objects.
Definition dataspace:53
Memory allocation interface.
Definition mem_alloc:54
Mem_alloc_flags
Flags for the allocator.
Definition mem_alloc:63
@ Super_pages
Allocate super pages.
Definition mem_alloc:66
@ Invert_dma_mask
Effectively says to allocate above the Dma_mask().
Definition mem_alloc:71
@ Fixed_paddr
Allocate at fixed physical address.
Definition mem_alloc:67
@ Continuous
Allocate physically contiguous memory.
Definition mem_alloc:64
@ Dma_mask_bits
See Dma_mask().
Definition mem_alloc:70
@ Pinned
Deprecated, use L4Re::Dma_space instead.
Definition mem_alloc:65
l4_ret_t alloc(long size, L4::Cap< Dataspace > mem, unsigned long flags=0, unsigned long align=0, l4_addr_t paddr=0, char const *type=nullptr) const noexcept
Allocate anonymous memory.
long info(Stats &stats)
Get allocator information.
static L4_CONSTEXPR unsigned Dma_mask(unsigned bits)
Constrain allocations to physical addresses below given bits.
Definition mem_alloc:80
C++ interface for capabilities.
Definition capability.h:249
Helper class to create an L4Re interface class that is derived from a single base class.
Definition __typeinfo.h:750
Common factory related definitions.
unsigned int l4_size_t
Unsigned size type.
Definition l4int.h:22
unsigned long l4_addr_t
Address type.
Definition l4int.h:34
#define L4_UNLIKELY(x)
Expression is unlikely to execute.
Definition compiler.h:295
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
#define L4_EXPORT
Attribute to mark functions, variables, and data types as being exported from a library.
Definition compiler.h:220
#define L4_CONSTEXPR
Constexpr function attribute.
Definition compiler.h:200
Interface Definition Language.
#define L4_INLINE_RPC(res, name, args, attr...)
Define an inline RPC call (type and callable).
Definition ipc_iface:483
l4_int16_t l4_ret_t
Return value of an IPC call as well as an RPC call.
Definition types.h:29
L4Re C++ Interfaces.
Definition cmd_control:14
L4 low-level kernel interface.
L4Re Protocol Constants (C version).
Statistics about memory-allocator.
Definition mem_alloc:96
l4_size_t quota
Memory quota of this allocator.
Definition mem_alloc:104
l4_size_t mem_limit
Maximum amount of memory that can be allocated by this allocator.
Definition mem_alloc:123
l4_size_t quota_used
Amount of currently used quota of this allocator.
Definition mem_alloc:115
l4_size_t mem_used
Amount of currently allocated memory.
Definition mem_alloc:137
l4_size_t mem_free
Amount of memory that is still available for allocation.
Definition mem_alloc:147