summaryrefslogtreecommitdiffstats
path: root/vlib-api/vlibmemory
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2016-04-09 03:16:30 +0200
committerDave Wallace <dwallacelf@gmail.com>2016-04-20 16:50:29 +0000
commit6855f6cdfee8c479f1e0ae440ce87a91ff41a708 (patch)
treee438e21c8107a675dc3a3141c6af6ba0ab458992 /vlib-api/vlibmemory
parent633951c3d8dc1640813b4778f3e35463d08f3795 (diff)
Python-API: Inital commit of Python bindings for the VPP API.
See: https://wiki.fd.io/view/VPP/Python_API Change-Id: If135fc32208c7031787e1935b399d930e0e1ea1f Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'vlib-api/vlibmemory')
-rw-r--r--vlib-api/vlibmemory/api.h7
-rw-r--r--vlib-api/vlibmemory/memory_shared.c14
2 files changed, 13 insertions, 8 deletions
diff --git a/vlib-api/vlibmemory/api.h b/vlib-api/vlibmemory/api.h
index 117bf433651..516d321ff53 100644
--- a/vlib-api/vlibmemory/api.h
+++ b/vlib-api/vlibmemory/api.h
@@ -86,6 +86,13 @@ typedef struct vl_shmem_hdr_ {
} vl_shmem_hdr_t;
+/* Note that the size of the structure is 16 bytes, with 4 bytes of padding after data[0]. */
+typedef struct msgbuf_ {
+ unix_shared_memory_queue_t *q;
+ u32 data_len;
+ u8 data[0];
+} msgbuf_t;
+
#define VL_SHM_VERSION 2
#define VL_API_EPOCH_MASK 0xFF
diff --git a/vlib-api/vlibmemory/memory_shared.c b/vlib-api/vlibmemory/memory_shared.c
index ecd5cff7339..a32194310a4 100644
--- a/vlib-api/vlibmemory/memory_shared.c
+++ b/vlib-api/vlibmemory/memory_shared.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
@@ -38,11 +39,6 @@
#include <vlibmemory/vl_memory_api_h.h>
#undef vl_typedefs
-typedef struct msgbuf_ {
- unix_shared_memory_queue_t *q;
- u8 data[0];
-} msgbuf_t;
-
static inline void *vl_msg_api_alloc_internal(int nbytes, int pool)
{
int i;
@@ -119,12 +115,13 @@ static inline void *vl_msg_api_alloc_internal(int nbytes, int pool)
pthread_mutex_lock (&am->vlib_rp->mutex);
oldheap = svm_push_data_heap (am->vlib_rp);
- rv = clib_mem_alloc(nbytes + sizeof(msgbuf_t));
+ rv = clib_mem_alloc(nbytes);
rv->q = 0;
svm_pop_heap (oldheap);
pthread_mutex_unlock (&am->vlib_rp->mutex);
out:
+ rv->data_len = htonl(nbytes - sizeof(msgbuf_t));
return(rv->data);
}
@@ -152,7 +149,8 @@ void vl_msg_api_free(void *a)
void *oldheap;
api_main_t *am = &api_main;
- rv = (msgbuf_t *)(((u8 *)a) - sizeof(*rv));
+ rv = (msgbuf_t *)(((u8 *)a) - offsetof(msgbuf_t, data));
+
/*
* Here's the beauty of the scheme. Only one proc/thread has
* control of a given message buffer. To free a buffer, we just clear the
@@ -176,7 +174,7 @@ static void vl_msg_api_free_nolock (void *a)
void *oldheap;
api_main_t *am = &api_main;
- rv = (msgbuf_t *)(((u8 *)a) - sizeof(*rv));
+ rv = (msgbuf_t *)(((u8 *)a) - offsetof(msgbuf_t, data));
/*
* Here's the beauty of the scheme. Only one proc/thread has
* control of a given message buffer. To free a buffer, we just clear the