PipeWire  0.2.7
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 
37 };
38 
39 #define PW_MEMBLOCK_FLAG_MAP_READWRITE (PW_MEMBLOCK_FLAG_MAP_READ | PW_MEMBLOCK_FLAG_MAP_WRITE)
40 
43 struct pw_memblock {
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
56  int fd, off_t offset, size_t size,
57  struct pw_memblock **mem);
58 
59 int
61 
62 void
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 
75 #define PW_MAP_RANGE_INIT (struct pw_map_range){ 0, }
76 
79 static inline void pw_map_range_init(struct pw_map_range *range,
80  uint32_t offset, uint32_t size,
81  uint32_t page_size)
82 {
83  range->offset = SPA_ROUND_DOWN_N(offset, page_size);
84  range->start = offset - range->offset;
85  range->size = offset + size - range->offset;
86 }
87 
88 
89 #ifdef __cplusplus
90 }
91 #endif
92 
93 #endif /* __PIPEWIRE_MEM_H__ */
pw_map_range
parameters to map a memory range
Definition: mem.h:69
pw_memblock_import
SPA_EXPORT int pw_memblock_import(enum pw_memblock_flags flags, int fd, off_t offset, size_t size, struct pw_memblock **mem)
Definition: mem.c:231
memblock
Definition: mem.c:82
memblock::link
struct spa_list link
Definition: mem.c:84
MFD_CLOEXEC
#define MFD_CLOEXEC
Definition: mem.c:59
pw_memblock::pw_memblock_map
SPA_EXPORT int pw_memblock_map(struct pw_memblock *mem)
Map a memblock.
Definition: mem.c:97
PW_MEMBLOCK_FLAG_MAP_READWRITE
#define PW_MEMBLOCK_FLAG_MAP_READWRITE
Definition: mem.h:39
pw_map_range::start
uint32_t start
Definition: mem.h:70
MFD_ALLOW_SEALING
#define MFD_ALLOW_SEALING
Definition: mem.c:63
pw_memblock_find
struct pw_memblock * pw_memblock_find(const void *ptr)
Find memblock for given ptr.
Definition: mem.c:276
pw_memblock::pw_memblock_alloc
SPA_EXPORT int pw_memblock_alloc(enum pw_memblock_flags flags, size_t size, struct pw_memblock **mem)
Create a new memblock.
Definition: mem.c:154
pw_memblock::pw_memblock_flags
pw_memblock_flags
Flags passed to pw_memblock_alloc()
Definition: mem.h:30
pw_memblock::size
size_t size
size of mapped memory
Definition: mem.h:48
pw_memblock::flags
enum pw_memblock_flags flags
flags used when allocating
Definition: mem.h:44
pw_map_range::offset
uint32_t offset
offset in first page with start of data
Definition: mem.h:71
PW_MEMBLOCK_FLAG_MAP_READ
@ PW_MEMBLOCK_FLAG_MAP_READ
Definition: mem.h:34
memblock::mem
struct pw_memblock mem
Definition: mem.c:83
PW_MEMBLOCK_FLAG_SEAL
@ PW_MEMBLOCK_FLAG_SEAL
Definition: mem.h:33
F_SEAL_GROW
#define F_SEAL_GROW
Definition: mem.c:78
pw_memblock::offset
off_t offset
offset of mappable memory
Definition: mem.h:46
pw_memblock::fd
int fd
memfd if any
Definition: mem.h:45
pw_map_range::size
uint32_t size
page aligned offset to map
Definition: mem.h:72
PW_MEMBLOCK_FLAG_MAP_WRITE
@ PW_MEMBLOCK_FLAG_MAP_WRITE
Definition: mem.h:35
pw_memblock::ptr
void * ptr
ptr to mapped memory
Definition: mem.h:47
F_ADD_SEALS
#define F_ADD_SEALS
Definition: mem.c:73
pw_memblock::pw_memblock_free
SPA_EXPORT void pw_memblock_free(struct pw_memblock *mem)
Free a memblock.
Definition: mem.c:255
F_SEAL_SEAL
#define F_SEAL_SEAL
Definition: mem.c:76
PW_MEMBLOCK_FLAG_NONE
@ PW_MEMBLOCK_FLAG_NONE
Definition: mem.h:31
F_SEAL_SHRINK
#define F_SEAL_SHRINK
Definition: mem.c:77
pw_memblock
Memory block structure.
Definition: mem.h:43
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:231
log.h
PW_MEMBLOCK_FLAG_MAP_TWICE
@ PW_MEMBLOCK_FLAG_MAP_TWICE
Definition: mem.h:36
PW_MEMBLOCK_FLAG_WITH_FD
@ PW_MEMBLOCK_FLAG_WITH_FD
Definition: mem.h:32
pw_log::pw_log_error
void pw_log_error(const char *format,...)
Log an error message.
mem.h
pw_memblock_find
SPA_EXPORT struct pw_memblock * pw_memblock_find(const void *ptr)
Find memblock for given ptr.
Definition: mem.c:276
pw_log::pw_log_warn
void pw_log_warn(const char *format,...)
Log a warning message.
pw_log::pw_log_debug
void pw_log_debug(const char *format,...)
Log a debug message.