PipeWire: mem.h Source File

PipeWire 0.1.8

mem.h
Go to the documentation of this file.
1 /* PipeWire
2 * Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #ifndef __PIPEWIRE_MEM_H__
21 #define __PIPEWIRE_MEM_H__
22
23 #include <spa/utils/defs.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
30 enum pw_memblock_flags {
31 PW_MEMBLOCK_FLAG_NONE = 0,
32 PW_MEMBLOCK_FLAG_WITH_FD = (1 << 0),
33 PW_MEMBLOCK_FLAG_SEAL = (1 << 1),
34 PW_MEMBLOCK_FLAG_MAP_READ = (1 << 2),
35 PW_MEMBLOCK_FLAG_MAP_WRITE = (1 << 3),
36 PW_MEMBLOCK_FLAG_MAP_TWICE = (1 << 4),
37 };
38
39 #define PW_MEMBLOCK_FLAG_MAP_READWRITE (PW_MEMBLOCK_FLAG_MAP_READ | PW_MEMBLOCK_FLAG_MAP_WRITE)
40
43 struct pw_memblock {
44 enum pw_memblock_flags flags;
45 int fd;
46 off_t offset;
47 void *ptr;
48 size_t size;
49 };
50
51 int
52 pw_memblock_alloc(enum pw_memblock_flags flags, size_t size, struct pw_memblock **mem);
53
54 int
55 pw_memblock_import(enum pw_memblock_flags flags,
56 int fd, off_t offset, size_t size,
57 struct pw_memblock **mem);
58
59 int
60 pw_memblock_map(struct pw_memblock *mem);
61
62 void
63 pw_memblock_free(struct pw_memblock *mem);
64
66 struct pw_memblock * pw_memblock_find(const void *ptr);
67
69 struct pw_map_range {
70 uint32_t start;
71 uint32_t offset;
72 uint32_t size;
73 };
74
77 static inline void pw_map_range_init(struct pw_map_range *range,
78 uint32_t offset, uint32_t size,
79 uint32_t page_size)
80 {
81 range->offset = SPA_ROUND_DOWN_N(offset, page_size);
82 range->start = offset - range->offset;
83 range->size = offset + size - range->offset;
84 }
85
86
87 #ifdef __cplusplus
88 }
89 #endif
90
91 #endif /* __PIPEWIRE_MEM_H__ */
pw_map_range
parameters to map a memory range
Definition: mem.h:69
pw_map_range::offset
uint32_t offset
offset in first page with start of data
Definition: mem.h:71
pw_memblock::flags
enum pw_memblock_flags flags
flags used when allocating
Definition: mem.h:44
PW_MEMBLOCK_FLAG_WITH_FD
Definition: mem.h:32
pw_memblock_import
int pw_memblock_import(enum pw_memblock_flags flags, int fd, off_t offset, size_t size, struct pw_memblock **mem)
Definition: mem.c:226
PW_MEMBLOCK_FLAG_NONE
Definition: mem.h:31
PW_MEMBLOCK_FLAG_MAP_WRITE
Definition: mem.h:35
pw_memblock::pw_memblock_flags
pw_memblock_flags
Flags passed to pw_memblock_alloc()
Definition: mem.h:30
pw_memblock::pw_memblock_free
void pw_memblock_free(struct pw_memblock *mem)
Free a memblock.
Definition: mem.c:247
pw_memblock::fd
int fd
memfd if any
Definition: mem.h:45
pw_memblock::pw_memblock_alloc
int pw_memblock_alloc(enum pw_memblock_flags flags, size_t size, struct pw_memblock **mem)
Create a new memblock.
Definition: mem.c:151
pw_memblock::pw_memblock_map
int pw_memblock_map(struct pw_memblock *mem)
Map a memblock.
Definition: mem.c:96
pw_memblock::offset
off_t offset
offset of mappable memory
Definition: mem.h:46
pw_map_range::start
uint32_t start
Definition: mem.h:70
pw_memblock::ptr
void * ptr
ptr to mapped memory
Definition: mem.h:47
pw_memblock
Memory block structure.
Definition: mem.h:43
pw_memblock::size
size_t size
size of mapped memory
Definition: mem.h:48
PW_MEMBLOCK_FLAG_MAP_TWICE
Definition: mem.h:36
PW_MEMBLOCK_FLAG_SEAL
Definition: mem.h:33
pw_map_range::size
uint32_t size
page aligned offset to map
Definition: mem.h:72
pw_memblock_find
struct pw_memblock * pw_memblock_find(const void *ptr)
Find memblock for given ptr.
Definition: mem.c:266
PW_MEMBLOCK_FLAG_MAP_READ
Definition: mem.h:34