From 23555a33d3e46edd7fb241a59cda80035ae42a92 Mon Sep 17 00:00:00 2001 From: Andrew Stitcher Date: Wed, 11 Jun 2014 17:47:37 +0000 Subject: QPID-3650: Avoid unaligned memory access git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1601969 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/qpid/sys/rdma/RdmaClient.cpp | 8 ++++---- qpid/cpp/src/qpid/sys/rdma/rdma_wrap.h | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'qpid/cpp') diff --git a/qpid/cpp/src/qpid/sys/rdma/RdmaClient.cpp b/qpid/cpp/src/qpid/sys/rdma/RdmaClient.cpp index 38e9b59541..504000af08 100644 --- a/qpid/cpp/src/qpid/sys/rdma/RdmaClient.cpp +++ b/qpid/cpp/src/qpid/sys/rdma/RdmaClient.cpp @@ -97,8 +97,8 @@ void write(Rdma::AsynchIO& aio) { Rdma::Buffer* b = aio.getSendBuffer(); if (!b) break; b->dataCount(msgsize); - uint32_t* ip = reinterpret_cast(b->bytes()); - uint32_t* lip = ip + b->dataCount() / sizeof(uint32_t); + uint32_t* ip = b->words(); + uint32_t* lip = ip + b->wordCount(); while (ip != lip) {*ip++ = *output; ++output;} aio.queueWrite(b); ++smsgs; @@ -116,8 +116,8 @@ void data(Poller::shared_ptr p, Rdma::AsynchIO& aio, Rdma::Buffer* b) { // Check message is unaltered bool match = true; - uint32_t* ip = reinterpret_cast(b->bytes()); - uint32_t* lip = ip + b->dataCount() / sizeof(uint32_t); + uint32_t* ip = b->words(); + uint32_t* lip = ip + b->wordCount(); while (ip != lip) { if (*ip++ != *input) {match = false; break;} ++input;} if (!match) { cout << "Data doesn't match: at msg " << rmsgs << " byte " << rbytes-b->dataCount() << " (ish)\n"; diff --git a/qpid/cpp/src/qpid/sys/rdma/rdma_wrap.h b/qpid/cpp/src/qpid/sys/rdma/rdma_wrap.h index 5f84793a5b..5d9b681da8 100644 --- a/qpid/cpp/src/qpid/sys/rdma/rdma_wrap.h +++ b/qpid/cpp/src/qpid/sys/rdma/rdma_wrap.h @@ -53,7 +53,9 @@ namespace Rdma { friend class QueuePairEvent; char* bytes() const; + uint32_t* words() const; int32_t byteCount() const; + int32_t wordCount() const; int32_t dataCount() const; void dataCount(int32_t); @@ -68,11 +70,20 @@ namespace Rdma { return (char*) sge.addr; } + inline uint32_t* Buffer::words() const { + return (uint32_t*) sge.addr; + } + /** return the number of bytes available for application data */ inline int32_t Buffer::byteCount() const { return bufferSize - reserved; } + /** return the number of words available for application data */ + inline int32_t Buffer::wordCount() const { + return (bufferSize - reserved) / sizeof(uint32_t); + } + inline int32_t Buffer::dataCount() const { return sge.length; } -- cgit v1.2.1