aboutsummaryrefslogtreecommitdiffstats
path: root/src/svm
diff options
context:
space:
mode:
Diffstat (limited to 'src/svm')
-rw-r--r--src/svm/fifo_segment.c27
-rw-r--r--src/svm/fifo_segment.h17
2 files changed, 34 insertions, 10 deletions
diff --git a/src/svm/fifo_segment.c b/src/svm/fifo_segment.c
index 0c3a79a613b..4ffec7c86d0 100644
--- a/src/svm/fifo_segment.c
+++ b/src/svm/fifo_segment.c
@@ -278,7 +278,11 @@ fifo_segment_init (fifo_segment_t * fs)
ASSERT (fsh->max_byte_index <= sh->ssvm_size - offset);
fs->max_byte_index = fsh->max_byte_index;
- fs->h = sh->opaque[0] = fsh;
+ fs->h = fsh;
+ sh->opaque[0] = (void *) ((u8 *) fsh - (u8 *) fs->ssvm.sh);
+
+ /* Allow random offsets */
+ fs->ssvm.sh->ssvm_va = 0;
vec_validate (fs->slices, fs->n_slices - 1);
for (i = 0; i < fs->n_slices; i++)
@@ -338,7 +342,7 @@ fifo_segment_attach (fifo_segment_main_t * sm, fifo_segment_create_args_t * a)
fs->ssvm.ssvm_size = a->segment_size;
fs->ssvm.my_pid = getpid ();
fs->ssvm.name = format (0, "%s%c", a->segment_name, 0);
- fs->ssvm.requested_va = sm->next_baseva;
+ fs->ssvm.requested_va = 0;
if (a->segment_type == SSVM_SEGMENT_MEMFD)
fs->ssvm.fd = a->memfd_fd;
else
@@ -346,17 +350,15 @@ fifo_segment_attach (fifo_segment_main_t * sm, fifo_segment_create_args_t * a)
if ((rv = ssvm_client_init (&fs->ssvm, a->segment_type)))
{
- _vec_len (fs) = vec_len (fs) - 1;
+ pool_put (sm->segments, fs);
return (rv);
}
- /* Fish the segment header */
- fsh = fs->h = fs->ssvm.sh->opaque[0];
-
/* Probably a segment without fifos */
- if (!fsh)
+ if (!fs->ssvm.sh->opaque[0])
goto done;
+ fsh = fs->h = (void *) fs->ssvm.sh + (uword) fs->ssvm.sh->opaque[0];
fs->max_byte_index = fsh->max_byte_index;
vec_validate (fs->slices, 0);
fs->slices[0].fifos =
@@ -824,9 +826,12 @@ done:
}
svm_fifo_t *
-fifo_segment_alloc_fifo_w_shared (fifo_segment_t *fs, svm_fifo_shared_t *sf)
+fifo_segment_alloc_fifo_w_offset (fifo_segment_t *fs, uword offset)
{
svm_fifo_t *f = fs_fifo_alloc (fs, 0);
+ svm_fifo_shared_t *sf;
+
+ sf = (svm_fifo_shared_t *) ((u8 *) fs->h + offset);
f->fs_hdr = fs->h;
f->shr = sf;
@@ -950,6 +955,12 @@ fifo_segment_attach_fifo (fifo_segment_t * fs, svm_fifo_t * f,
}
}
+uword
+fifo_segment_fifo_offset (svm_fifo_t *f)
+{
+ return (u8 *) f->shr - (u8 *) f->fs_hdr;
+}
+
svm_msg_q_t *
fifo_segment_msg_q_alloc (fifo_segment_t *fs, u32 mq_index,
svm_msg_q_cfg_t *cfg)
diff --git a/src/svm/fifo_segment.h b/src/svm/fifo_segment.h
index 195869a25dd..8266690d4ed 100644
--- a/src/svm/fifo_segment.h
+++ b/src/svm/fifo_segment.h
@@ -104,6 +104,18 @@ fifo_segment_t *fifo_segment_get_segment (fifo_segment_main_t * sm,
u32 fifo_segment_index (fifo_segment_main_t * sm, fifo_segment_t * fs);
void fifo_segment_info (fifo_segment_t * seg, char **address, size_t * size);
+always_inline void *
+fifo_segment_ptr (fifo_segment_t *fs, uword offset)
+{
+ return (void *) ((u8 *) fs->h + offset);
+}
+
+always_inline uword
+fifo_segment_offset (fifo_segment_t *fs, void *p)
+{
+ return (uword) ((u8 *) p - (u8 *) fs->h);
+}
+
/**
* Allocate fifo in fifo segment
*
@@ -116,8 +128,8 @@ svm_fifo_t *fifo_segment_alloc_fifo_w_slice (fifo_segment_t * fs,
u32 slice_index,
u32 data_bytes,
fifo_segment_ftype_t ftype);
-svm_fifo_t *fifo_segment_alloc_fifo_w_shared (fifo_segment_t *fs,
- svm_fifo_shared_t *sf);
+svm_fifo_t *fifo_segment_alloc_fifo_w_offset (fifo_segment_t *fs,
+ uword offset);
/**
* Free fifo allocated in fifo segment
@@ -130,6 +142,7 @@ void fifo_segment_free_fifo (fifo_segment_t * fs, svm_fifo_t * f);
void fifo_segment_detach_fifo (fifo_segment_t * fs, svm_fifo_t * f);
void fifo_segment_attach_fifo (fifo_segment_t * fs, svm_fifo_t * f,
u32 slice_index);
+uword fifo_segment_fifo_offset (svm_fifo_t *f);
/**
* Allocate message queue on segment