34 u8 junk = 0, *ssvm_filename;
36 uword page_size, requested_va = 0;
40 return SSVM_API_ERROR_NO_SIZE;
46 ssvm_filename =
format (0,
"/dev/shm/%s%c", ssvm->
name, 0);
47 unlink ((
char *) ssvm_filename);
50 ssvm_fd = shm_open ((
char *) ssvm->
name, O_RDWR | O_CREAT | O_EXCL, 0777);
54 return SSVM_API_ERROR_CREATE_FAILURE;
57 if (fchmod (ssvm_fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
59 if (fchown (ssvm_fd, smr->
uid, smr->
gid) < 0)
62 if (lseek (ssvm_fd, ssvm->
ssvm_size, SEEK_SET) < 0)
66 return SSVM_API_ERROR_SET_SIZE;
69 if (write (ssvm_fd, &junk, 1) != 1)
73 return SSVM_API_ERROR_SET_SIZE;
90 return SSVM_API_ERROR_MMAP;
127 ssvm_fd = shm_open ((
char *) ssvm->
name, O_RDWR, 0777);
133 if (fstat (ssvm_fd, &stat) < 0)
139 if (stat.st_size > 0)
143 return SSVM_API_ERROR_SLAVE_TIMEOUT;
146 sh = (
void *) mmap (0,
MMAP_PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
148 if (sh == MAP_FAILED)
152 return SSVM_API_ERROR_MMAP;
163 return SSVM_API_ERROR_SLAVE_TIMEOUT;
171 PROT_READ | PROT_WRITE,
172 MAP_SHARED | MAP_FIXED, ssvm_fd, 0);
174 if (sh == MAP_FAILED)
178 return SSVM_API_ERROR_MMAP;
189 fn =
format (0,
"/dev/shm/%s%c", ssvm->
name, 0);
192 clib_warning (
"[%d] unlinking ssvm (%s) backing file '%s'", getpid (),
196 if (unlink ((
char *) fn) < 0)
218 return SSVM_API_ERROR_NO_SIZE;
229 return SSVM_API_ERROR_CREATE_FAILURE;
232 memfd->
fd = alloc.
fd;
234 memfd->
my_pid = getpid ();
274 return SSVM_API_ERROR_MMAP;
281 mapa.
size = page_size;
287 return SSVM_API_ERROR_MMAP;
304 return SSVM_API_ERROR_MMAP;
333 rnd_size = (ssvm->
ssvm_size + (pagesize - 1)) & ~pagesize;
352 memset (sh, 0,
sizeof (*sh));
svm_region_t * svm_get_root_rp(void)
static init_fn slave_init_fns[SSVM_N_SEGMENT_TYPES]
static init_fn master_init_fns[SSVM_N_SEGMENT_TYPES]
#define vec_c_string_is_terminated(V)
Test whether a vector is a NULL terminated c-string.
void * mheap_alloc(void *memory, uword size)
void * addr
Pointer to allocated memory, set on successful allocation.
uword requested_va
Request fixed position mapping.
void(* delete_fn)(ssvm_private_t *)
static mheap_t * mheap_header(u8 *v)
int ssvm_slave_init_shm(ssvm_private_t *ssvm)
ssvm_shared_header_t * sh
#define MHEAP_FLAG_THREAD_SAFE
int ssvm_master_init_shm(ssvm_private_t *ssvm)
static uword min_log2(uword x)
void ssvm_delete(ssvm_private_t *ssvm)
int ssvm_slave_init_private(ssvm_private_t *ssvm)
u8 * ssvm_name(const ssvm_private_t *ssvm)
enum ssvm_segment_type_ ssvm_segment_type_t
clib_error_t * clib_mem_vm_ext_map(clib_mem_vm_map_t *a)
clib_error_t * clib_mem_vm_ext_alloc(clib_mem_vm_alloc_t *a)
uword requested_va
Request fixed position mapping.
int(* init_fn)(ssvm_private_t *)
#define MHEAP_FLAG_DISABLE_VM
int ssvm_master_init_memfd(ssvm_private_t *memfd)
Initialize memfd segment master.
char * name
Name for memory allocation, set by caller.
static void * ssvm_push_heap(ssvm_shared_header_t *sh)
uword size
Allocation size, set by caller.
int attach_timeout
shm segments attach timeout (sec)
int ssvm_master_init(ssvm_private_t *ssvm, ssvm_segment_type_t type)
static void ssvm_pop_heap(void *oldheap)
#define CLIB_MEM_VM_F_SHARED
int fd
File descriptor, set on successful allocation if CLIB_MEM_VM_F_SHARED is set.
uword clib_mem_vm_get_page_size(int fd)
#define vec_free(V)
Free vector's memory (no header).
#define clib_warning(format, args...)
int ssvm_slave_init(ssvm_private_t *ssvm, ssvm_segment_type_t type)
u32 flags
vm allocation flags: CLIB_MEM_VM_F_SHARED: request shared memory, file descriptor will be provided ...
void * mheap_alloc_with_flags(void *memory, uword memory_size, uword flags)
static void clib_mem_free(void *p)
#define clib_error_report(e)
static heap_header_t * heap_header(void *v)
static uword pointer_to_uword(const void *p)
static void clib_mem_vm_free(void *addr, uword size)
static delete_fn delete_fns[SSVM_N_SEGMENT_TYPES]
#define clib_unix_warning(format, args...)
void ssvm_delete_memfd(ssvm_private_t *memfd)
void clib_mem_vm_randomize_va(uword *requested_va, u32 log2_page_size)
int ssvm_master_init_private(ssvm_private_t *ssvm)
Initialize segment in a private heap.
static void * clib_mem_alloc_aligned(uword size, uword align)
int fd
File descriptor to be mapped.
void ssvm_delete_private(ssvm_private_t *ssvm)
void ssvm_delete_shm(ssvm_private_t *ssvm)
#define CLIB_CACHE_LINE_BYTES
uword clib_mem_get_page_size(void)
int ssvm_slave_init_memfd(ssvm_private_t *memfd)
Initialize memfd segment slave.
void * addr
Pointer to mapped memory, if successful.
ssvm_segment_type_t ssvm_type(const ssvm_private_t *ssvm)