mem.h
Go to the documentation of this file.
/* PipeWire
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __PIPEWIRE_MEM_H__
#define __PIPEWIRE_MEM_H__
#include <spa/utils/defs.h>
#ifdef __cplusplus
extern "C" {
#endif
enum pw_memblock_flags {
PW_MEMBLOCK_FLAG_NONE = 0,
PW_MEMBLOCK_FLAG_WITH_FD = (1 << 0),
PW_MEMBLOCK_FLAG_SEAL = (1 << 1),
PW_MEMBLOCK_FLAG_MAP_READ = (1 << 2),
PW_MEMBLOCK_FLAG_MAP_WRITE = (1 << 3),
PW_MEMBLOCK_FLAG_MAP_TWICE = (1 << 4),
};
#define PW_MEMBLOCK_FLAG_MAP_READWRITE (PW_MEMBLOCK_FLAG_MAP_READ | PW_MEMBLOCK_FLAG_MAP_WRITE)
struct pw_memblock {
enum pw_memblock_flags flags;
int fd;
off_t offset;
void *ptr;
size_t size;
};
int
pw_memblock_alloc(enum pw_memblock_flags flags, size_t size, struct pw_memblock **mem);
int
pw_memblock_import(enum pw_memblock_flags flags,
int fd, off_t offset, size_t size,
struct pw_memblock **mem);
int
pw_memblock_map(struct pw_memblock *mem);
void
pw_memblock_free(struct pw_memblock *mem);
struct pw_memblock * pw_memblock_find(const void *ptr);
struct pw_map_range {
uint32_t start;
uint32_t offset;
uint32_t size;
};
#define PW_MAP_RANGE_INIT (struct pw_map_range){ 0, }
static inline void pw_map_range_init(struct pw_map_range *range,
uint32_t offset, uint32_t size,
uint32_t page_size)
{
range->offset = SPA_ROUND_DOWN_N(offset, page_size);
range->start = offset - range->offset;
range->size = offset + size - range->offset;
}
#ifdef __cplusplus
}
#endif
#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:231
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_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::fd
int fd
memfd if any
Definition: mem.h:45
pw_memblock::pw_memblock_map
SPA_EXPORT int pw_memblock_map(struct pw_memblock *mem)
Map a memblock.
Definition: mem.c:97
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::pw_memblock_free
SPA_EXPORT void pw_memblock_free(struct pw_memblock *mem)
Free a memblock.
Definition: mem.c:255
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:276
PW_MEMBLOCK_FLAG_MAP_READ
Definition: mem.h:34