Commit a1d931c3 authored by Dmitry Safonov's avatar Dmitry Safonov Committed by Andrei Vagin

compel: plugins -- Add shmem plugin

The shmem pluging allows creation of shared memory segment between
parasite code and the caller.
Signed-off-by: 's avatarDmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 5cf76474
#ifndef __COMPEL_PLUGIN_SHMEM_PRIV_H__
#define __COMPEL_PLUGIN_SHMEM_PRIV_H__
struct shmem_plugin_msg {
unsigned long start;
unsigned long len;
};
#endif /* __COMPEL_PLUGIN_SHMEM_PRIV_H__ */
......@@ -2,6 +2,9 @@
ARCH_DIR := compel/arch/$(ARCH)/plugins
#
# CFLAGS, ASFLAGS, LDFLAGS
# General compel includes
ccflags-y += -iquote $(SRC_DIR)/compel/include
......@@ -20,6 +23,10 @@ asflags-y += -iquote $(SRC_DIR)/$(ARCH_DIR)
asflags-y += -Wstrict-prototypes -Wa,--noexecstack
asflags-y += -D__ASSEMBLY__ -nostdlib -fomit-frame-pointer
#
# Shmem plugin
target += shmem
shmem-obj-y += shmem/shmem.o
#
# STD plugin
......
#ifndef __COMPEL_PLUGIN_STD_PRIV_H__
#define __COMPEL_PLUGIN_STD_PRIV_H__
extern int std_ctl_sock(void);
#endif /* __COMPEL_PLUGIN_STD_PRIV_H__ */
#ifndef __COMPEL_PLUGIN_SHMEM_H__
#define __COMPEL_PLUGIN_SHMEM_H__
/*
* Creates local shmem mapping and announces it
* to the peer. Peer can later "receive" one. The
* local area should be munmap()-ed at the end.
*/
extern void *shmem_create(unsigned long size);
/*
* "Receives" shmem from peer and maps it. The
* locally mapped area should be munmap()-ed at
* the end
*/
extern void *shmem_receive(unsigned long *size);
#endif /* __COMPEL_PLUGIN_SHMEM_H__ */
#include <sys/mman.h>
#include "uapi/plugins.h"
#include "uapi/plugin-shmem.h"
#include "uapi/std/syscall.h"
#include "shmem.h"
#include "std-priv.h"
void *shmem_create(unsigned long size)
{
int ret;
void *mem;
struct shmem_plugin_msg spi;
mem = (void *)sys_mmap(NULL, size, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANON, 0, 0);
if (mem == MAP_FAILED)
return NULL;
spi.start = (unsigned long)mem;
spi.len = size;
ret = sys_write(std_ctl_sock(), &spi, sizeof(spi));
if (ret != sizeof(spi)) {
sys_munmap(mem, size);
return NULL;
}
return mem;
}
void *shmem_receive(unsigned long *size)
{
/* master -> parasite not implemented yet */
return NULL;
}
PLUGIN_REGISTER_DUMMY(shmem)
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