Commit bce10e76 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Add block_shm_Alloc()

parent a02360f2
......@@ -168,6 +168,7 @@ static inline void block_Release( block_t *p_block )
VLC_API block_t *block_heap_Alloc(void *, size_t) VLC_USED VLC_MALLOC;
VLC_API block_t *block_mmap_Alloc(void *addr, size_t length) VLC_USED VLC_MALLOC;
VLC_API block_t * block_shm_Alloc(void *addr, size_t length) VLC_USED VLC_MALLOC;
VLC_API block_t *block_File(int fd) VLC_USED VLC_MALLOC;
VLC_API block_t *block_FilePath(const char *) VLC_USED VLC_MALLOC;
......
......@@ -32,6 +32,7 @@ block_FilePath
block_heap_Alloc
block_Init
block_mmap_Alloc
block_shm_Alloc
block_Realloc
config_AddIntf
config_ChainCreate
......
......@@ -335,6 +335,55 @@ block_t *block_mmap_Alloc (void *addr, size_t length)
}
#endif
#ifdef HAVE_SYS_SHM_H
# include <sys/shm.h>
typedef struct block_shm_t
{
block_t self;
void *base_addr;
} block_shm_t;
static void block_shm_Release (block_t *block)
{
block_shm_t *p_sys = (block_shm_t *)block;
shmdt (p_sys->base_addr);
free (p_sys);
}
/**
* Creates a block from a System V shared memory segment (shmget()).
* This is provided by LibVLC so that segments can safely be deallocated
* even after the allocating plugin has been unloaded from memory.
*
* @param addr base address of the segment (as returned by shmat())
* @param length length (bytes) of the segment (as passed to shmget())
* @return NULL if an error occurred (in that case, shmdt(addr) is invoked
* before returning NULL).
*/
block_t *block_shm_Alloc (void *addr, size_t length)
{
block_shm_t *block = malloc (sizeof (*block));
if (unlikely(block == NULL))
{
shmdt (addr);
return NULL;
}
block_Init (&block->self, (uint8_t *)addr, length);
block->self.pf_release = block_shm_Release;
block->base_addr = addr;
return &block->self;
}
#else
block_t *block_shm_Alloc (void *addr, size_t length)
{
(void) addr; (void) length;
abort ();
}
#endif
#ifdef WIN32
# include <io.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment