L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
mem_alloc_impl.h
Go to the documentation of this file.
1
5/*
6 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
7 * Alexander Warg <warg@os.inf.tu-dresden.de>
8 * economic rights: Technische Universität Dresden (Germany)
9 *
10 * License: see LICENSE.spdx (in this directory or the directories above)
11 */
12#include <l4/re/mem_alloc>
13#include <l4/re/dataspace>
14#include <l4/re/error_helper>
15
16#include <l4/sys/factory>
17
18
19namespace L4Re
20{
21
23Mem_alloc::alloc(long size, L4::Cap<Dataspace> mem, unsigned long flags,
24 unsigned long align, l4_addr_t paddr,
25 char const *type) const noexcept
26{
28 auto call = f->create(mem, L4Re::Dataspace::Protocol);
29 call << l4_mword_t(size)
30 << l4_umword_t(flags)
31 << l4_umword_t(align);
32 if (flags & Fixed_paddr)
33 call << l4_umword_t(paddr);
34 if (type)
35 {
36 // We have to prepend 'type='.
37 static constexpr unsigned Prefix_len = 5;
38 char type_buf[32]; // assuming that type length is limited
39 auto len = __builtin_strlen(type);
40 if (len > sizeof(type_buf) - Prefix_len - 1)
41 return -L4_EINVAL; // name too long
42 __builtin_memcpy(type_buf, "type=", Prefix_len);
43 __builtin_memcpy(&type_buf[Prefix_len], type, len);
44 type_buf[Prefix_len + len] = '\0';
45
46 call << type_buf;
47 }
48
49 return l4_error(call);
50}
51
52};
@ Fixed_paddr
Allocate at fixed physical address.
Definition mem_alloc:67
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.
C++ interface for capabilities.
Definition capability.h:249
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition kobject:69
Dataspace interface.
Error helper.
Common factory related definitions.
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
unsigned long l4_addr_t
Address type.
Definition l4int.h:34
signed long l4_mword_t
Signed machine word.
Definition l4int.h:37
@ L4_EINVAL
Invalid argument.
Definition err.h:47
l4_ret_t l4_error(l4_msgtag_t tag) L4_NOTHROW
Get IPC error code if any or message tag label otherwise for an IPC call.
Definition ipc.h:730
l4_int16_t l4_ret_t
Return value of an IPC call as well as an RPC call.
Definition types.h:29
Memory allocator interface.
L4Re C++ Interfaces.
Definition cmd_control:14