+#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
+