#include <stdio.h>
#include <stdlib.h>
+#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#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;
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);
}
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
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