32 u8 junk = 0, *ssvm_filename;
34 uword page_size, requested_va = 0;
38 return SSVM_API_ERROR_NO_SIZE;
44 ssvm_filename =
format (0,
"/dev/shm/%s%c", ssvm->
name, 0);
45 unlink ((
char *) ssvm_filename);
48 ssvm_fd = shm_open ((
char *) ssvm->
name, O_RDWR | O_CREAT | O_EXCL, 0777);
52 return SSVM_API_ERROR_CREATE_FAILURE;
55 if (fchmod (ssvm_fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
61 if (fchown (ssvm_fd, smr->
uid, smr->
gid) < 0)
65 if (lseek (ssvm_fd, ssvm->
ssvm_size, SEEK_SET) < 0)
69 return SSVM_API_ERROR_SET_SIZE;
72 if (write (ssvm_fd, &junk, 1) != 1)
76 return SSVM_API_ERROR_SET_SIZE;
93 return SSVM_API_ERROR_MMAP;
105 1 ,
"ssvm server shm");
132 ssvm_fd = shm_open ((
char *) ssvm->
name, O_RDWR, 0777);
138 if (fstat (ssvm_fd, &stat) < 0)
144 if (stat.st_size > 0)
148 return SSVM_API_ERROR_CLIENT_TIMEOUT;
151 sh = (
void *) mmap (0,
MMAP_PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
153 if (sh == MAP_FAILED)
157 return SSVM_API_ERROR_MMAP;
168 return SSVM_API_ERROR_CLIENT_TIMEOUT;
176 PROT_READ | PROT_WRITE,
177 MAP_SHARED | MAP_FIXED, ssvm_fd, 0);
179 if (sh == MAP_FAILED)
183 return SSVM_API_ERROR_MMAP;
194 fn =
format (0,
"/dev/shm/%s%c", ssvm->
name, 0);
197 clib_warning (
"[%d] unlinking ssvm (%s) backing file '%s'", getpid (),
201 if (unlink ((
char *) fn) < 0)
219 uword page_size, n_pages;
225 return SSVM_API_ERROR_NO_SIZE;
230 (
char *) memfd->
name);
235 return SSVM_API_ERROR_CREATE_FAILURE;
239 if (log2_page_size == 0)
242 return SSVM_API_ERROR_CREATE_FAILURE;
245 n_pages = ((memfd->
ssvm_size - 1) >> log2_page_size) + 1;
247 if ((ftruncate (memfd->
fd, n_pages << log2_page_size)) == -1)
250 return SSVM_API_ERROR_CREATE_FAILURE;
255 (
char *) memfd->
name);
260 return SSVM_API_ERROR_CREATE_FAILURE;
264 memfd->
my_pid = getpid ();
272 page_size = 1ULL << log2_page_size;
275 1 ,
"ssvm server memfd");
294 int mmap_flags = MAP_SHARED;
304 return SSVM_API_ERROR_MMAP;
308 mmap_flags |= MAP_FIXED;
313 sh = (
void *) mmap (0, page_size, PROT_READ | PROT_WRITE, MAP_SHARED,
316 if (sh == MAP_FAILED)
320 return SSVM_API_ERROR_MMAP;
325 munmap (sh, page_size);
332 PROT_READ | PROT_WRITE, mmap_flags, memfd->
fd, 0);
334 if (sh == MAP_FAILED)
338 return SSVM_API_ERROR_MMAP;
363 uword page_size, log2_page_size, rnd_size = 0;
368 if (log2_page_size == 0)
371 return SSVM_API_ERROR_CREATE_FAILURE;
374 page_size = 1ULL << log2_page_size;
376 rnd_size &= ~(page_size - 1);
379 (
char *) ssvm->
name);
383 return SSVM_API_ERROR_CREATE_FAILURE;
387 1 ,
"ssvm server private");
__clib_export int clib_mem_vm_create_fd(clib_mem_page_sz_t log2_page_size, char *fmt,...)
#define CLIB_MEM_UNPOISON(a, s)
#define CLIB_MEM_VM_MAP_FAILED
svm_region_t * svm_get_root_rp(void)
#define vec_c_string_is_terminated(V)
Test whether a vector is a NULL terminated c-string.
__clib_export int clib_mem_vm_unmap(void *base)
__clib_export void clib_mem_vm_randomize_va(uword *requested_va, clib_mem_page_sz_t log2_page_size)
int ssvm_client_init_memfd(ssvm_private_t *memfd)
Initialize memfd segment client.
clib_mem_heap_t * clib_mem_create_heap(void *base, uword size, int is_locked, char *fmt,...)
__clib_export void * clib_mem_vm_map_shared(void *base, uword size, int fd, uword offset, char *fmt,...)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
void(* delete_fn)(ssvm_private_t *)
ssvm_shared_header_t * sh
static uword min_log2(uword x)
void ssvm_delete(ssvm_private_t *ssvm)
__clib_export void * clib_mem_vm_map(void *base, uword size, clib_mem_page_sz_t log2_page_sz, char *fmt,...)
u8 * ssvm_name(const ssvm_private_t *ssvm)
int ssvm_server_init(ssvm_private_t *ssvm, ssvm_segment_type_t type)
enum ssvm_segment_type_ ssvm_segment_type_t
static init_fn client_init_fns[SSVM_N_SEGMENT_TYPES]
int(* init_fn)(ssvm_private_t *)
description fragment has unexpected format
static void * ssvm_push_heap(ssvm_shared_header_t *sh)
int attach_timeout
shm segments attach timeout (sec)
static void ssvm_pop_heap(void *oldheap)
vl_api_fib_path_type_t type
void clib_mem_destroy_heap(clib_mem_heap_t *heap)
int ssvm_server_init_memfd(ssvm_private_t *memfd)
Initialize memfd segment server.
int ssvm_client_init_private(ssvm_private_t *ssvm)
uword clib_mem_get_heap_free_space(clib_mem_heap_t *heap)
#define vec_free(V)
Free vector's memory (no header).
#define clib_warning(format, args...)
static_always_inline clib_mem_page_sz_t clib_mem_get_log2_page_size(void)
int ssvm_server_init_private(ssvm_private_t *ssvm)
Initialize segment in a private heap.
#define uword_to_pointer(u, type)
int ssvm_client_init(ssvm_private_t *ssvm, ssvm_segment_type_t type)
__clib_export clib_mem_page_sz_t clib_mem_get_fd_log2_page_size(int fd)
static uword pointer_to_uword(const void *p)
__clib_export u64 clib_mem_get_fd_page_size(int fd)
static init_fn server_init_fns[SSVM_N_SEGMENT_TYPES]
static delete_fn delete_fns[SSVM_N_SEGMENT_TYPES]
#define clib_unix_warning(format, args...)
void ssvm_delete_memfd(ssvm_private_t *memfd)
int ssvm_client_init_shm(ssvm_private_t *ssvm)
void ssvm_delete_private(ssvm_private_t *ssvm)
void ssvm_delete_shm(ssvm_private_t *ssvm)
int ssvm_server_init_shm(ssvm_private_t *ssvm)
ssvm_segment_type_t ssvm_type(const ssvm_private_t *ssvm)