Commit aa2150c2 authored by Martin Sustrik's avatar Martin Sustrik

VSM data are aligned to 32/64 bit boundary

Till now the VSM buffer was aligned to 16 bit boundary
which could possibly cause problems on RISC architectures
when accessing the message data in unsafe manner.
Signed-off-by: 's avatarMartin Sustrik <sustrik@250bpm.com>
parent 1526ff63
...@@ -39,10 +39,6 @@ namespace zmq ...@@ -39,10 +39,6 @@ namespace zmq
// Commands in pipe per allocation event. // Commands in pipe per allocation event.
command_pipe_granularity = 16, command_pipe_granularity = 16,
// Size in bytes of the largest message that is still copied around
// rather than being reference-counted.
max_vsm_size = 29,
// Determines how often does socket poll for new commands when it // Determines how often does socket poll for new commands when it
// still has unprocessed messages to handle. Thus, if it is set to 100, // still has unprocessed messages to handle. Thus, if it is set to 100,
// socket will process 100 inbound messages before doing the poll. // socket will process 100 inbound messages before doing the poll.
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
*/ */
#include "msg.hpp" #include "msg.hpp"
#include "../include/zmq.h"
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
...@@ -29,6 +30,11 @@ ...@@ -29,6 +30,11 @@
#include "likely.hpp" #include "likely.hpp"
#include "err.hpp" #include "err.hpp"
// Check whether the sizes of public representation of the message (zmq_msg_t)
// and private represenation of the message (zmq::msg_t) match.
typedef char zmq_msg_size_check
[2 * ((sizeof (zmq::msg_t) == sizeof (zmq_msg_t)) != 0) - 1];
bool zmq::msg_t::check () bool zmq::msg_t::check ()
{ {
return u.base.type >= type_min && u.base.type <= type_max; return u.base.type >= type_min && u.base.type <= type_max;
......
...@@ -77,6 +77,10 @@ namespace zmq ...@@ -77,6 +77,10 @@ namespace zmq
private: private:
// Size in bytes of the largest message that is still copied around
// rather than being reference-counted.
enum {max_vsm_size = 29};
// Shared message buffer. Message data are either allocated in one // Shared message buffer. Message data are either allocated in one
// continuous block along with this structure - thus avoiding one // continuous block along with this structure - thus avoiding one
// malloc/free pair or they are stored in used-supplied memory. // malloc/free pair or they are stored in used-supplied memory.
...@@ -109,21 +113,24 @@ namespace zmq ...@@ -109,21 +113,24 @@ namespace zmq
// the union. // the union.
union { union {
struct { struct {
unsigned char unused [max_vsm_size + 1];
unsigned char type; unsigned char type;
unsigned char flags; unsigned char flags;
} base; } base;
struct { struct {
unsigned char data [max_vsm_size];
unsigned char size;
unsigned char type; unsigned char type;
unsigned char flags; unsigned char flags;
unsigned char size;
unsigned char data [max_vsm_size];
} vsm; } vsm;
struct { struct {
content_t *content;
unsigned char unused [max_vsm_size + 1 - sizeof (content_t*)];
unsigned char type; unsigned char type;
unsigned char flags; unsigned char flags;
content_t *content;
} lmsg; } lmsg;
struct { struct {
unsigned char unused [max_vsm_size + 1];
unsigned char type; unsigned char type;
unsigned char flags; unsigned char flags;
} delimiter; } delimiter;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment