PipeWire  0.2.0
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
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 
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__ */
parameters to map a memory range
Definition: mem.h:69
uint32_t offset
offset in first page with start of data
Definition: mem.h:71
enum pw_memblock_flags flags
flags used when allocating
Definition: mem.h:44
Definition: mem.h:32
int pw_memblock_import(enum pw_memblock_flags flags, int fd, off_t offset, size_t size, struct pw_memblock **mem)
Definition: mem.c:228
Definition: mem.h:31
Definition: mem.h:35
pw_memblock_flags
Flags passed to pw_memblock_alloc()
Definition: mem.h:30
void pw_memblock_free(struct pw_memblock *mem)
Free a memblock.
Definition: mem.c:251
int fd
memfd if any
Definition: mem.h:45
int pw_memblock_alloc(enum pw_memblock_flags flags, size_t size, struct pw_memblock **mem)
Create a new memblock.
Definition: mem.c:152
int pw_memblock_map(struct pw_memblock *mem)
Map a memblock.
Definition: mem.c:96
off_t offset
offset of mappable memory
Definition: mem.h:46
uint32_t start
Definition: mem.h:70
void * ptr
ptr to mapped memory
Definition: mem.h:47
Memory block structure.
Definition: mem.h:43
size_t size
size of mapped memory
Definition: mem.h:48
Definition: mem.h:36
Definition: mem.h:33
uint32_t size
page aligned offset to map
Definition: mem.h:72
struct pw_memblock * pw_memblock_find(const void *ptr)
Find memblock for given ptr.
Definition: mem.c:271
Definition: mem.h:34