@@ -44,7 +44,8 @@ namespace bi = boost::interprocess;
4444
4545// / Struct holding the representation of a message queue inside the shared
4646// / memory.
47- // / \param size Total size of the message queue.
47+ // / \param size Total size of the message queue. Considered invalid after
48+ // / MessageQueue::LoadFromSharedMemory. Check DLIS-8378 for additional details.
4849// / \param mutex Handle of the mutex variable protecting index.
4950// / \param index Used element index.
5051// / \param sem_empty Semaphore object counting the number of empty buffer slots.
@@ -118,13 +119,15 @@ class MessageQueue {
118119 int head_idx = Head ();
119120 // Additional check to avoid out of bounds read/write. Check DLIS-8378 for
120121 // additional details.
121- if (head_idx < 0 || static_cast <size_t >(head_idx) >= Size ()) {
122- constexpr const char * error_msg =
123- " Message queue head index out of bounds" ;
122+ if (head_idx < 0 || static_cast <uint32_t >(head_idx) >= Size ()) {
123+ std::string error_msg =
124+ " internal error: message queue head index out of bounds. Expects "
125+ " positive integer less than the size of message queue " +
126+ std::to_string (Size ()) + " but got " + std::to_string (head_idx);
124127#ifdef TRITON_PB_STUB
125128 LOG_ERROR << error_msg;
126129#else
127- LOG_MESSAGE (TRITONSERVER_LOG_ERROR, error_msg);
130+ LOG_MESSAGE (TRITONSERVER_LOG_ERROR, error_msg. c_str () );
128131#endif
129132 return ;
130133 }
@@ -166,13 +169,15 @@ class MessageQueue {
166169 int head_idx = Head ();
167170 // Additional check to avoid out of bounds read/write. Check DLIS-8378 for
168171 // additional details.
169- if (head_idx < 0 || static_cast <size_t >(head_idx) >= Size ()) {
170- constexpr const char * error_msg =
171- " Message queue head index out of bounds" ;
172+ if (head_idx < 0 || static_cast <uint32_t >(head_idx) >= Size ()) {
173+ std::string error_msg =
174+ " internal error: message queue head index out of bounds. Expects "
175+ " positive integer less than the size of message queue " +
176+ std::to_string (Size ()) + " but got " + std::to_string (head_idx);
172177#ifdef TRITON_PB_STUB
173178 LOG_ERROR << error_msg;
174179#else
175- LOG_MESSAGE (TRITONSERVER_LOG_ERROR, error_msg);
180+ LOG_MESSAGE (TRITONSERVER_LOG_ERROR, error_msg. c_str () );
176181#endif
177182 return ;
178183 }
@@ -275,7 +280,7 @@ class MessageQueue {
275280 }
276281
277282 private:
278- std:: size_t & Size () { return mq_shm_ptr_-> size ; }
283+ uint32_t Size () { return size_ ; }
279284 const bi::interprocess_mutex& Mutex () { return mq_shm_ptr_->mutex ; }
280285 bi::interprocess_mutex* MutexMutable () { return &(mq_shm_ptr_->mutex ); }
281286 int & Head () { return mq_shm_ptr_->head ; }
@@ -304,6 +309,7 @@ class MessageQueue {
304309 MessageQueueShm* mq_shm_ptr_;
305310 T* mq_buffer_shm_ptr_;
306311 bi::managed_external_buffer::handle_t mq_handle_;
312+ uint32_t size_;
307313
308314 // / Create/load a Message queue.
309315 // / \param mq_shm Message queue representation in shared memory.
@@ -315,6 +321,7 @@ class MessageQueue {
315321 mq_buffer_shm_ptr_ = mq_buffer_shm_.data_ .get ();
316322 mq_shm_ptr_ = mq_shm_.data_ .get ();
317323 mq_handle_ = mq_shm_.handle_ ;
324+ size_ = mq_shm_ptr_->size ;
318325 }
319326};
320327}}} // namespace triton::backend::python
0 commit comments